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