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