Xinerama.c0100664000413400041340000002213107327056334011751 0ustar jakubjakub/* $Xorg: XPanoramiX.c,v 1.4 2000/08/17 19:45:51 cpqbld Exp $ */ /***************************************************************** Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Except as contained in this notice, the name of Digital Equipment Corporation shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Digital Equipment Corporation. ******************************************************************/ /* $XFree86: xc/lib/Xinerama/Xinerama.c,v 1.1 2000/02/27 23:10:04 mvojkovi Exp $ */ #define NEED_EVENTS #define NEED_REPLIES #include #include #include "Xext.h" /* in ../include */ #include "extutil.h" /* in ../include */ #include "panoramiXext.h" #include "panoramiXproto.h" /* in ../include */ #include "Xinerama.h" static XExtensionInfo _panoramiX_ext_info_data; static XExtensionInfo *panoramiX_ext_info = &_panoramiX_ext_info_data; static /* const */ char *panoramiX_extension_name = PANORAMIX_PROTOCOL_NAME; #define PanoramiXCheckExtension(dpy,i,val) \ XextCheckExtension (dpy, i, panoramiX_extension_name, val) #define PanoramiXSimpleCheckExtension(dpy,i) \ XextSimpleCheckExtension (dpy, i, panoramiX_extension_name) static int close_display(); static /* const */ XExtensionHooks panoramiX_extension_hooks = { NULL, /* create_gc */ NULL, /* copy_gc */ NULL, /* flush_gc */ NULL, /* free_gc */ NULL, /* create_font */ NULL, /* free_font */ close_display, /* close_display */ NULL, /* wire_to_event */ NULL, /* event_to_wire */ NULL, /* error */ NULL, /* error_string */ }; static XEXT_GENERATE_FIND_DISPLAY (find_display, panoramiX_ext_info, panoramiX_extension_name, &panoramiX_extension_hooks, 0, NULL) static XEXT_GENERATE_CLOSE_DISPLAY (close_display, panoramiX_ext_info) /**************************************************************************** * * * PanoramiX public interfaces * * * ****************************************************************************/ Bool XPanoramiXQueryExtension ( Display *dpy, int *event_basep, int *error_basep ) { XExtDisplayInfo *info = find_display (dpy); if (XextHasExtension(info)) { *event_basep = info->codes->first_event; *error_basep = info->codes->first_error; return True; } else { return False; } } Status XPanoramiXQueryVersion( Display *dpy, int *major_versionp, int *minor_versionp ) { XExtDisplayInfo *info = find_display (dpy); xPanoramiXQueryVersionReply rep; register xPanoramiXQueryVersionReq *req; PanoramiXCheckExtension (dpy, info, 0); LockDisplay (dpy); GetReq (PanoramiXQueryVersion, req); req->reqType = info->codes->major_opcode; req->panoramiXReqType = X_PanoramiXQueryVersion; req->clientMajor = PANORAMIX_MAJOR_VERSION; req->clientMinor = PANORAMIX_MINOR_VERSION; if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { UnlockDisplay (dpy); SyncHandle (); return 0; } *major_versionp = rep.majorVersion; *minor_versionp = rep.minorVersion; UnlockDisplay (dpy); SyncHandle (); return 1; } XPanoramiXInfo *XPanoramiXAllocInfo(void) { return (XPanoramiXInfo *) Xmalloc (sizeof (XPanoramiXInfo)); } Status XPanoramiXGetState ( Display *dpy, Drawable drawable, XPanoramiXInfo *panoramiX_info ) { XExtDisplayInfo *info = find_display (dpy); xPanoramiXGetStateReply rep; register xPanoramiXGetStateReq *req; PanoramiXCheckExtension (dpy, info, 0); LockDisplay (dpy); GetReq (PanoramiXGetState, req); req->reqType = info->codes->major_opcode; req->panoramiXReqType = X_PanoramiXGetState; req->window = drawable; if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { UnlockDisplay (dpy); SyncHandle (); return 0; } UnlockDisplay (dpy); SyncHandle (); panoramiX_info->window = rep.window; panoramiX_info->State = rep.state; return 1; } Status XPanoramiXGetScreenCount ( Display *dpy, Drawable drawable, XPanoramiXInfo *panoramiX_info ) { XExtDisplayInfo *info = find_display (dpy); xPanoramiXGetScreenCountReply rep; register xPanoramiXGetScreenCountReq *req; PanoramiXCheckExtension (dpy, info, 0); LockDisplay (dpy); GetReq (PanoramiXGetScreenCount, req); req->reqType = info->codes->major_opcode; req->panoramiXReqType = X_PanoramiXGetScreenCount; req->window = drawable; if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { UnlockDisplay (dpy); SyncHandle (); return 0; } UnlockDisplay (dpy); SyncHandle (); panoramiX_info->window = rep.window; panoramiX_info->ScreenCount = rep.ScreenCount; return 1; } Status XPanoramiXGetScreenSize ( Display *dpy, Drawable drawable, int screen_num, XPanoramiXInfo *panoramiX_info ) { XExtDisplayInfo *info = find_display (dpy); xPanoramiXGetScreenSizeReply rep; register xPanoramiXGetScreenSizeReq *req; PanoramiXCheckExtension (dpy, info, 0); LockDisplay (dpy); GetReq (PanoramiXGetScreenSize, req); req->reqType = info->codes->major_opcode; req->panoramiXReqType = X_PanoramiXGetScreenSize; req->window = drawable; req->screen = screen_num; /* need to define */ if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { UnlockDisplay (dpy); SyncHandle (); return 0; } UnlockDisplay (dpy); SyncHandle (); panoramiX_info->window = rep.window; panoramiX_info->screen = rep.screen; panoramiX_info->width = rep.width; panoramiX_info->height = rep.height; return 1; } /*******************************************************************\ Alternate interface to make up for shortcomings in the original, namely, the omission of the screen origin. The new interface is in the "Xinerama" namespace instead of "PanoramiX". \*******************************************************************/ Bool XineramaQueryExtension ( Display *dpy, int *event_base, int *error_base ) { return XPanoramiXQueryExtension(dpy, event_base, error_base); } Status XineramaQueryVersion( Display *dpy, int *major, int *minor ) { return XPanoramiXQueryVersion(dpy, major, minor); } Bool XineramaIsActive(Display *dpy) { xXineramaIsActiveReply rep; xXineramaIsActiveReq *req; XExtDisplayInfo *info = find_display (dpy); if(!XextHasExtension(info)) return False; /* server doesn't even have the extension */ LockDisplay (dpy); GetReq (XineramaIsActive, req); req->reqType = info->codes->major_opcode; req->panoramiXReqType = X_XineramaIsActive; if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { UnlockDisplay (dpy); SyncHandle (); return False; } UnlockDisplay (dpy); SyncHandle (); return rep.state; } #include XineramaScreenInfo * XineramaQueryScreens( Display *dpy, int *number ) { XExtDisplayInfo *info = find_display (dpy); xXineramaQueryScreensReply rep; xXineramaQueryScreensReq *req; XineramaScreenInfo *scrnInfo = NULL; PanoramiXCheckExtension (dpy, info, 0); LockDisplay (dpy); GetReq (XineramaQueryScreens, req); req->reqType = info->codes->major_opcode; req->panoramiXReqType = X_XineramaQueryScreens; if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) { UnlockDisplay (dpy); SyncHandle (); return NULL; } if(rep.number) { if((scrnInfo = Xmalloc(sizeof(XineramaScreenInfo) * rep.number))) { xXineramaScreenInfo scratch; int i; for(i = 0; i < rep.number; i++) { _XRead(dpy, (char*)(&scratch), sz_XineramaScreenInfo); scrnInfo[i].screen_number = i; scrnInfo[i].x_org = scratch.x_org; scrnInfo[i].y_org = scratch.y_org; scrnInfo[i].width = scratch.width; scrnInfo[i].height = scratch.height; } *number = rep.number; } else _XEatData(dpy, rep.length << 2); } UnlockDisplay (dpy); SyncHandle (); return scrnInfo; } extutil.h0100664000413400041340000001511407406454270011712 0ustar jakubjakub/* * $Xorg: extutil.h,v 1.4 2001/02/09 02:03:24 xorgcvs Exp $ * Copyright 1989, 1998 The Open Group Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. * * Author: Jim Fulton, MIT The Open Group * * Xlib Extension-Writing Utilities * * This package contains utilities for writing the client API for various * protocol extensions. THESE INTERFACES ARE NOT PART OF THE X STANDARD AND * ARE SUBJECT TO CHANGE! */ /* $XFree86: xc/include/extensions/extutil.h,v 1.8 2001/08/19 02:47:49 tsi Exp $ */ #ifndef _EXTUTIL_H_ #define _EXTUTIL_H_ #include /* * We need to keep a list of open displays since the Xlib display list isn't * public. We also have to per-display info in a separate block since it isn't * stored directly in the Display structure. */ typedef struct _XExtDisplayInfo { struct _XExtDisplayInfo *next; /* keep a linked list */ Display *display; /* which display this is */ XExtCodes *codes; /* the extension protocol codes */ XPointer data; /* extra data for extension to use */ } XExtDisplayInfo; typedef struct _XExtensionInfo { XExtDisplayInfo *head; /* start of list */ XExtDisplayInfo *cur; /* most recently used */ int ndisplays; /* number of displays */ } XExtensionInfo; typedef struct _XExtensionHooks { int (*create_gc)( #if NeedNestedPrototypes Display* /* display */, GC /* gc */, XExtCodes* /* codes */ #endif ); int (*copy_gc)( #if NeedNestedPrototypes Display* /* display */, GC /* gc */, XExtCodes* /* codes */ #endif ); int (*flush_gc)( #if NeedNestedPrototypes Display* /* display */, GC /* gc */, XExtCodes* /* codes */ #endif ); int (*free_gc)( #if NeedNestedPrototypes Display* /* display */, GC /* gc */, XExtCodes* /* codes */ #endif ); int (*create_font)( #if NeedNestedPrototypes Display* /* display */, XFontStruct* /* fs */, XExtCodes* /* codes */ #endif ); int (*free_font)( #if NeedNestedPrototypes Display* /* display */, XFontStruct* /* fs */, XExtCodes* /* codes */ #endif ); int (*close_display)( #if NeedNestedPrototypes Display* /* display */, XExtCodes* /* codes */ #endif ); Bool (*wire_to_event)( #if NeedNestedPrototypes Display* /* display */, XEvent* /* re */, xEvent* /* event */ #endif ); Status (*event_to_wire)( #if NeedNestedPrototypes Display* /* display */, XEvent* /* re */, xEvent* /* event */ #endif ); int (*error)( #if NeedNestedPrototypes Display* /* display */, xError* /* err */, XExtCodes* /* codes */, int* /* ret_code */ #endif ); char *(*error_string)( #if NeedNestedPrototypes Display* /* display */, int /* code */, XExtCodes* /* codes */, char* /* buffer */, int /* nbytes */ #endif ); } XExtensionHooks; extern XExtensionInfo *XextCreateExtension( #if NeedFunctionPrototypes void #endif ); extern void XextDestroyExtension( #if NeedFunctionPrototypes XExtensionInfo* /* info */ #endif ); extern XExtDisplayInfo *XextAddDisplay( #if NeedFunctionPrototypes XExtensionInfo* /* extinfo */, Display* /* dpy */, char* /* ext_name */, XExtensionHooks* /* hooks */, int /* nevents */, XPointer /* data */ #endif ); extern int XextRemoveDisplay( #if NeedFunctionPrototypes XExtensionInfo* /* extinfo */, Display* /* dpy */ #endif ); extern XExtDisplayInfo *XextFindDisplay( #if NeedFunctionPrototypes XExtensionInfo* /* extinfo */, Display* /* dpy */ #endif ); #define XextHasExtension(i) ((i) && ((i)->codes)) #define XextCheckExtension(dpy,i,name,val) \ if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return val; } #define XextSimpleCheckExtension(dpy,i,name) \ if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return; } /* * helper macros to generate code that is common to all extensions; caller * should prefix it with static if extension source is in one file; this * could be a utility function, but have to stack 6 unused arguments for * something that is called many, many times would be bad. */ #define XEXT_GENERATE_FIND_DISPLAY(proc,extinfo,extname,hooks,nev,data) \ XExtDisplayInfo *proc (Display *dpy) \ { \ XExtDisplayInfo *dpyinfo; \ if (!extinfo) { if (!(extinfo = XextCreateExtension())) return NULL; } \ if (!(dpyinfo = XextFindDisplay (extinfo, dpy))) \ dpyinfo = XextAddDisplay (extinfo,dpy,extname,hooks,nev,data); \ return dpyinfo; \ } #define XEXT_FIND_DISPLAY_PROTO(proc) \ XExtDisplayInfo *proc(Display *dpy) #define XEXT_GENERATE_CLOSE_DISPLAY(proc,extinfo) \ int proc (Display *dpy, XExtCodes *codes) \ { \ return XextRemoveDisplay (extinfo, dpy); \ } #define XEXT_CLOSE_DISPLAY_PROTO(proc) \ int proc(Display *dpy, XExtCodes *codes) #define XEXT_GENERATE_ERROR_STRING(proc,extname,nerr,errl) \ char *proc (Display *dpy, int code, XExtCodes *codes, char *buf, int n) \ { \ code -= codes->first_error; \ if (code >= 0 && code < nerr) { \ char tmp[256]; \ sprintf (tmp, "%s.%d", extname, code); \ XGetErrorDatabaseText (dpy, "XProtoError", tmp, errl[code], buf, n); \ return buf; \ } \ return (char *)0; \ } #define XEXT_ERROR_STRING_PROTO(proc) \ char *proc(Display *dpy, int code, XExtCodes *codes, char *buf, int n) #endif