PageRenderTime 40ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/nx-3.5.0/nx-X11/lib/Xinerama/Xinerama.c

#
C | 319 lines | 240 code | 43 blank | 36 comment | 12 complexity | e911a307dc8e08b63dfee6d099d7ab09 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.0
  1. /* $Xorg: XPanoramiX.c,v 1.4 2000/08/17 19:45:51 cpqbld Exp $ */
  2. /*****************************************************************
  3. Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software.
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  14. DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
  15. BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
  16. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
  17. IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  18. Except as contained in this notice, the name of Digital Equipment Corporation
  19. shall not be used in advertising or otherwise to promote the sale, use or other
  20. dealings in this Software without prior written authorization from Digital
  21. Equipment Corporation.
  22. ******************************************************************/
  23. /* $XFree86: xc/lib/Xinerama/Xinerama.c,v 1.2 2001/07/23 17:20:28 dawes Exp $ */
  24. #define NEED_EVENTS
  25. #define NEED_REPLIES
  26. #include <X11/Xlibint.h>
  27. #include <X11/Xutil.h>
  28. #include <X11/extensions/Xext.h>
  29. #include <X11/extensions/extutil.h>
  30. #include <X11/extensions/panoramiXext.h>
  31. #include <X11/extensions/panoramiXproto.h>
  32. #include <X11/extensions/Xinerama.h>
  33. static XExtensionInfo _panoramiX_ext_info_data;
  34. static XExtensionInfo *panoramiX_ext_info = &_panoramiX_ext_info_data;
  35. static /* const */ char *panoramiX_extension_name = PANORAMIX_PROTOCOL_NAME;
  36. #define PanoramiXCheckExtension(dpy,i,val) \
  37. XextCheckExtension (dpy, i, panoramiX_extension_name, val)
  38. #define PanoramiXSimpleCheckExtension(dpy,i) \
  39. XextSimpleCheckExtension (dpy, i, panoramiX_extension_name)
  40. static int close_display();
  41. static /* const */ XExtensionHooks panoramiX_extension_hooks = {
  42. NULL, /* create_gc */
  43. NULL, /* copy_gc */
  44. NULL, /* flush_gc */
  45. NULL, /* free_gc */
  46. NULL, /* create_font */
  47. NULL, /* free_font */
  48. close_display, /* close_display */
  49. NULL, /* wire_to_event */
  50. NULL, /* event_to_wire */
  51. NULL, /* error */
  52. NULL, /* error_string */
  53. };
  54. static XEXT_GENERATE_FIND_DISPLAY (find_display, panoramiX_ext_info,
  55. panoramiX_extension_name,
  56. &panoramiX_extension_hooks,
  57. 0, NULL)
  58. static XEXT_GENERATE_CLOSE_DISPLAY (close_display, panoramiX_ext_info)
  59. /****************************************************************************
  60. * *
  61. * PanoramiX public interfaces *
  62. * *
  63. ****************************************************************************/
  64. Bool XPanoramiXQueryExtension (
  65. Display *dpy,
  66. int *event_basep,
  67. int *error_basep
  68. )
  69. {
  70. XExtDisplayInfo *info = find_display (dpy);
  71. if (XextHasExtension(info)) {
  72. *event_basep = info->codes->first_event;
  73. *error_basep = info->codes->first_error;
  74. return True;
  75. } else {
  76. return False;
  77. }
  78. }
  79. Status XPanoramiXQueryVersion(
  80. Display *dpy,
  81. int *major_versionp,
  82. int *minor_versionp
  83. )
  84. {
  85. XExtDisplayInfo *info = find_display (dpy);
  86. xPanoramiXQueryVersionReply rep;
  87. register xPanoramiXQueryVersionReq *req;
  88. PanoramiXCheckExtension (dpy, info, 0);
  89. LockDisplay (dpy);
  90. GetReq (PanoramiXQueryVersion, req);
  91. req->reqType = info->codes->major_opcode;
  92. req->panoramiXReqType = X_PanoramiXQueryVersion;
  93. req->clientMajor = PANORAMIX_MAJOR_VERSION;
  94. req->clientMinor = PANORAMIX_MINOR_VERSION;
  95. if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
  96. UnlockDisplay (dpy);
  97. SyncHandle ();
  98. return 0;
  99. }
  100. *major_versionp = rep.majorVersion;
  101. *minor_versionp = rep.minorVersion;
  102. UnlockDisplay (dpy);
  103. SyncHandle ();
  104. return 1;
  105. }
  106. XPanoramiXInfo *XPanoramiXAllocInfo(void)
  107. {
  108. return (XPanoramiXInfo *) Xmalloc (sizeof (XPanoramiXInfo));
  109. }
  110. Status XPanoramiXGetState (
  111. Display *dpy,
  112. Drawable drawable,
  113. XPanoramiXInfo *panoramiX_info
  114. )
  115. {
  116. XExtDisplayInfo *info = find_display (dpy);
  117. xPanoramiXGetStateReply rep;
  118. register xPanoramiXGetStateReq *req;
  119. PanoramiXCheckExtension (dpy, info, 0);
  120. LockDisplay (dpy);
  121. GetReq (PanoramiXGetState, req);
  122. req->reqType = info->codes->major_opcode;
  123. req->panoramiXReqType = X_PanoramiXGetState;
  124. req->window = drawable;
  125. if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
  126. UnlockDisplay (dpy);
  127. SyncHandle ();
  128. return 0;
  129. }
  130. UnlockDisplay (dpy);
  131. SyncHandle ();
  132. panoramiX_info->window = rep.window;
  133. panoramiX_info->State = rep.state;
  134. return 1;
  135. }
  136. Status XPanoramiXGetScreenCount (
  137. Display *dpy,
  138. Drawable drawable,
  139. XPanoramiXInfo *panoramiX_info
  140. )
  141. {
  142. XExtDisplayInfo *info = find_display (dpy);
  143. xPanoramiXGetScreenCountReply rep;
  144. register xPanoramiXGetScreenCountReq *req;
  145. PanoramiXCheckExtension (dpy, info, 0);
  146. LockDisplay (dpy);
  147. GetReq (PanoramiXGetScreenCount, req);
  148. req->reqType = info->codes->major_opcode;
  149. req->panoramiXReqType = X_PanoramiXGetScreenCount;
  150. req->window = drawable;
  151. if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
  152. UnlockDisplay (dpy);
  153. SyncHandle ();
  154. return 0;
  155. }
  156. UnlockDisplay (dpy);
  157. SyncHandle ();
  158. panoramiX_info->window = rep.window;
  159. panoramiX_info->ScreenCount = rep.ScreenCount;
  160. return 1;
  161. }
  162. Status XPanoramiXGetScreenSize (
  163. Display *dpy,
  164. Drawable drawable,
  165. int screen_num,
  166. XPanoramiXInfo *panoramiX_info
  167. )
  168. {
  169. XExtDisplayInfo *info = find_display (dpy);
  170. xPanoramiXGetScreenSizeReply rep;
  171. register xPanoramiXGetScreenSizeReq *req;
  172. PanoramiXCheckExtension (dpy, info, 0);
  173. LockDisplay (dpy);
  174. GetReq (PanoramiXGetScreenSize, req);
  175. req->reqType = info->codes->major_opcode;
  176. req->panoramiXReqType = X_PanoramiXGetScreenSize;
  177. req->window = drawable;
  178. req->screen = screen_num; /* need to define */
  179. if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
  180. UnlockDisplay (dpy);
  181. SyncHandle ();
  182. return 0;
  183. }
  184. UnlockDisplay (dpy);
  185. SyncHandle ();
  186. panoramiX_info->window = rep.window;
  187. panoramiX_info->screen = rep.screen;
  188. panoramiX_info->width = rep.width;
  189. panoramiX_info->height = rep.height;
  190. return 1;
  191. }
  192. /*******************************************************************\
  193. Alternate interface to make up for shortcomings in the original,
  194. namely, the omission of the screen origin. The new interface is
  195. in the "Xinerama" namespace instead of "PanoramiX".
  196. \*******************************************************************/
  197. Bool XineramaQueryExtension (
  198. Display *dpy,
  199. int *event_base,
  200. int *error_base
  201. )
  202. {
  203. return XPanoramiXQueryExtension(dpy, event_base, error_base);
  204. }
  205. Status XineramaQueryVersion(
  206. Display *dpy,
  207. int *major,
  208. int *minor
  209. )
  210. {
  211. return XPanoramiXQueryVersion(dpy, major, minor);
  212. }
  213. Bool XineramaIsActive(Display *dpy)
  214. {
  215. xXineramaIsActiveReply rep;
  216. xXineramaIsActiveReq *req;
  217. XExtDisplayInfo *info = find_display (dpy);
  218. if(!XextHasExtension(info))
  219. return False; /* server doesn't even have the extension */
  220. LockDisplay (dpy);
  221. GetReq (XineramaIsActive, req);
  222. req->reqType = info->codes->major_opcode;
  223. req->panoramiXReqType = X_XineramaIsActive;
  224. if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
  225. UnlockDisplay (dpy);
  226. SyncHandle ();
  227. return False;
  228. }
  229. UnlockDisplay (dpy);
  230. SyncHandle ();
  231. return rep.state;
  232. }
  233. #include <stdio.h>
  234. XineramaScreenInfo *
  235. XineramaQueryScreens(
  236. Display *dpy,
  237. int *number
  238. )
  239. {
  240. XExtDisplayInfo *info = find_display (dpy);
  241. xXineramaQueryScreensReply rep;
  242. xXineramaQueryScreensReq *req;
  243. XineramaScreenInfo *scrnInfo = NULL;
  244. PanoramiXCheckExtension (dpy, info, 0);
  245. LockDisplay (dpy);
  246. GetReq (XineramaQueryScreens, req);
  247. req->reqType = info->codes->major_opcode;
  248. req->panoramiXReqType = X_XineramaQueryScreens;
  249. if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
  250. UnlockDisplay (dpy);
  251. SyncHandle ();
  252. return NULL;
  253. }
  254. if(rep.number) {
  255. if((scrnInfo = Xmalloc(sizeof(XineramaScreenInfo) * rep.number))) {
  256. xXineramaScreenInfo scratch;
  257. int i;
  258. for(i = 0; i < rep.number; i++) {
  259. _XRead(dpy, (char*)(&scratch), sz_XineramaScreenInfo);
  260. scrnInfo[i].screen_number = i;
  261. scrnInfo[i].x_org = scratch.x_org;
  262. scrnInfo[i].y_org = scratch.y_org;
  263. scrnInfo[i].width = scratch.width;
  264. scrnInfo[i].height = scratch.height;
  265. }
  266. *number = rep.number;
  267. } else
  268. _XEatData(dpy, rep.length << 2);
  269. }
  270. UnlockDisplay (dpy);
  271. SyncHandle ();
  272. return scrnInfo;
  273. }