src/video/x11/SDL_x11video.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 26 Jul 2006 06:34:54 +0000
changeset 1950 a344e42bce3b
child 1951 7177581dc9fa
permissions -rw-r--r--
Started work on the new X11 driver.
slouken@1950
     1
/*
slouken@1950
     2
    SDL - Simple DirectMedia Layer
slouken@1950
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@1950
     4
slouken@1950
     5
    This library is free software; you can redistribute it and/or
slouken@1950
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1950
     7
    License as published by the Free Software Foundation; either
slouken@1950
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1950
     9
slouken@1950
    10
    This library is distributed in the hope that it will be useful,
slouken@1950
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1950
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1950
    13
    Lesser General Public License for more details.
slouken@1950
    14
slouken@1950
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1950
    16
    License along with this library; if not, write to the Free Software
slouken@1950
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1950
    18
slouken@1950
    19
    Sam Lantinga
slouken@1950
    20
    slouken@libsdl.org
slouken@1950
    21
*/
slouken@1950
    22
#include "SDL_config.h"
slouken@1950
    23
slouken@1950
    24
#include "SDL_video.h"
slouken@1950
    25
#include "SDL_mouse.h"
slouken@1950
    26
#include "../SDL_sysvideo.h"
slouken@1950
    27
#include "../SDL_pixels_c.h"
slouken@1950
    28
slouken@1950
    29
#include "SDL_x11video.h"
slouken@1950
    30
//#include "SDL_d3drender.h"
slouken@1950
    31
//#include "SDL_gdirender.h"
slouken@1950
    32
slouken@1950
    33
/* Initialization/Query functions */
slouken@1950
    34
static int X11_VideoInit(_THIS);
slouken@1950
    35
static void X11_VideoQuit(_THIS);
slouken@1950
    36
slouken@1950
    37
/* X11 driver bootstrap functions */
slouken@1950
    38
slouken@1950
    39
static int
slouken@1950
    40
X11_Available(void)
slouken@1950
    41
{
slouken@1950
    42
    Display *display = NULL;
slouken@1950
    43
    if (SDL_X11_LoadSymbols()) {
slouken@1950
    44
        display = XOpenDisplay(NULL);
slouken@1950
    45
        if (display != NULL) {
slouken@1950
    46
            XCloseDisplay(display);
slouken@1950
    47
        }
slouken@1950
    48
        SDL_X11_UnloadSymbols();
slouken@1950
    49
    }
slouken@1950
    50
    return (display != NULL);
slouken@1950
    51
}
slouken@1950
    52
slouken@1950
    53
static void
slouken@1950
    54
X11_DeleteDevice(SDL_VideoDevice * device)
slouken@1950
    55
{
slouken@1950
    56
    SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
slouken@1950
    57
slouken@1950
    58
    if (data->display) {
slouken@1950
    59
        XCloseDisplay(data->display);
slouken@1950
    60
    }
slouken@1950
    61
    SDL_free(device->driverdata);
slouken@1950
    62
    SDL_free(device);
slouken@1950
    63
slouken@1950
    64
    SDL_X11_UnloadSymbols();
slouken@1950
    65
}
slouken@1950
    66
slouken@1950
    67
static SDL_VideoDevice *
slouken@1950
    68
X11_CreateDevice(int devindex)
slouken@1950
    69
{
slouken@1950
    70
    SDL_VideoDevice *device;
slouken@1950
    71
    SDL_VideoData *data;
slouken@1950
    72
    const char *display = NULL; /* Use the DISPLAY environment variable */
slouken@1950
    73
slouken@1950
    74
    if (!SDL_X11_LoadSymbols()) {
slouken@1950
    75
        return NULL;
slouken@1950
    76
    }
slouken@1950
    77
slouken@1950
    78
    /* Initialize all variables that we clean on shutdown */
slouken@1950
    79
    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
slouken@1950
    80
    if (device) {
slouken@1950
    81
        data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
slouken@1950
    82
    }
slouken@1950
    83
    if (!device || !data) {
slouken@1950
    84
        SDL_OutOfMemory();
slouken@1950
    85
        if (device) {
slouken@1950
    86
            SDL_free(device);
slouken@1950
    87
        }
slouken@1950
    88
        return NULL;
slouken@1950
    89
    }
slouken@1950
    90
    device->driverdata = data;
slouken@1950
    91
slouken@1950
    92
    /* FIXME: Do we need this?
slouken@1950
    93
       if ( (SDL_strncmp(XDisplayName(display), ":", 1) == 0) ||
slouken@1950
    94
       (SDL_strncmp(XDisplayName(display), "unix:", 5) == 0) ) {
slouken@1950
    95
       local_X11 = 1;
slouken@1950
    96
       } else {
slouken@1950
    97
       local_X11 = 0;
slouken@1950
    98
       }
slouken@1950
    99
     */
slouken@1950
   100
    data->display = XOpenDisplay(display);
slouken@1950
   101
#if defined(__osf__) && defined(SDL_VIDEO_DRIVER_X11_DYNAMIC)
slouken@1950
   102
    /* On Tru64 if linking without -lX11, it fails and you get following message.
slouken@1950
   103
     * Xlib: connection to ":0.0" refused by server
slouken@1950
   104
     * Xlib: XDM authorization key matches an existing client!
slouken@1950
   105
     *
slouken@1950
   106
     * It succeeds if retrying 1 second later
slouken@1950
   107
     * or if running xhost +localhost on shell.
slouken@1950
   108
     */
slouken@1950
   109
    if (data->display == NULL) {
slouken@1950
   110
        SDL_Delay(1000);
slouken@1950
   111
        data->display = XOpenDisplay(display);
slouken@1950
   112
    }
slouken@1950
   113
#endif
slouken@1950
   114
    if (data->display == NULL) {
slouken@1950
   115
        SDL_free(device);
slouken@1950
   116
        SDL_SetError("Couldn't open X11 display");
slouken@1950
   117
        return NULL;
slouken@1950
   118
    }
slouken@1950
   119
#ifdef X11_DEBUG
slouken@1950
   120
    XSynchronize(data->display, True);
slouken@1950
   121
#endif
slouken@1950
   122
slouken@1950
   123
    /* Set the function pointers */
slouken@1950
   124
    device->VideoInit = X11_VideoInit;
slouken@1950
   125
    device->VideoQuit = X11_VideoQuit;
slouken@1950
   126
    device->GetDisplayModes = X11_GetDisplayModes;
slouken@1950
   127
    device->SetDisplayMode = X11_SetDisplayMode;
slouken@1950
   128
//    device->SetDisplayGammaRamp = X11_SetDisplayGammaRamp;
slouken@1950
   129
//    device->GetDisplayGammaRamp = X11_GetDisplayGammaRamp;
slouken@1950
   130
//    device->PumpEvents = X11_PumpEvents;
slouken@1950
   131
slouken@1950
   132
/*
slouken@1950
   133
    device->CreateWindow = X11_CreateWindow;
slouken@1950
   134
    device->CreateWindowFrom = X11_CreateWindowFrom;
slouken@1950
   135
    device->SetWindowTitle = X11_SetWindowTitle;
slouken@1950
   136
    device->SetWindowPosition = X11_SetWindowPosition;
slouken@1950
   137
    device->SetWindowSize = X11_SetWindowSize;
slouken@1950
   138
    device->ShowWindow = X11_ShowWindow;
slouken@1950
   139
    device->HideWindow = X11_HideWindow;
slouken@1950
   140
    device->RaiseWindow = X11_RaiseWindow;
slouken@1950
   141
    device->MaximizeWindow = X11_MaximizeWindow;
slouken@1950
   142
    device->MinimizeWindow = X11_MinimizeWindow;
slouken@1950
   143
    device->RestoreWindow = X11_RestoreWindow;
slouken@1950
   144
    device->SetWindowGrab = X11_SetWindowGrab;
slouken@1950
   145
    device->DestroyWindow = X11_DestroyWindow;
slouken@1950
   146
    device->GetWindowWMInfo = X11_GetWindowWMInfo;
slouken@1950
   147
#ifdef SDL_VIDEO_OPENGL
slouken@1950
   148
    device->GL_LoadLibrary = X11_GL_LoadLibrary;
slouken@1950
   149
    device->GL_GetProcAddress = X11_GL_GetProcAddress;
slouken@1950
   150
    device->GL_CreateContext = X11_GL_CreateContext;
slouken@1950
   151
    device->GL_MakeCurrent = X11_GL_MakeCurrent;
slouken@1950
   152
    device->GL_SetSwapInterval = X11_GL_SetSwapInterval;
slouken@1950
   153
    device->GL_GetSwapInterval = X11_GL_GetSwapInterval;
slouken@1950
   154
    device->GL_SwapWindow = X11_GL_SwapWindow;
slouken@1950
   155
    device->GL_DeleteContext = X11_GL_DeleteContext;
slouken@1950
   156
#endif
slouken@1950
   157
*/
slouken@1950
   158
slouken@1950
   159
    device->free = X11_DeleteDevice;
slouken@1950
   160
slouken@1950
   161
    return device;
slouken@1950
   162
}
slouken@1950
   163
slouken@1950
   164
VideoBootStrap X11_bootstrap = {
slouken@1950
   165
    "x11", "SDL X11 video driver",
slouken@1950
   166
    X11_Available, X11_CreateDevice
slouken@1950
   167
};
slouken@1950
   168
slouken@1950
   169
slouken@1950
   170
int
slouken@1950
   171
X11_VideoInit(_THIS)
slouken@1950
   172
{
slouken@1950
   173
    X11_InitModes(_this);
slouken@1950
   174
slouken@1950
   175
//#if SDL_VIDEO_RENDER_D3D
slouken@1950
   176
//    D3D_AddRenderDriver(_this);
slouken@1950
   177
//#endif
slouken@1950
   178
//#if SDL_VIDEO_RENDER_GDI
slouken@1950
   179
//    GDI_AddRenderDriver(_this);
slouken@1950
   180
//#endif
slouken@1950
   181
slouken@1950
   182
    X11_InitKeyboard(_this);
slouken@1950
   183
    X11_InitMouse(_this);
slouken@1950
   184
slouken@1950
   185
    return 0;
slouken@1950
   186
}
slouken@1950
   187
slouken@1950
   188
void
slouken@1950
   189
X11_VideoQuit(_THIS)
slouken@1950
   190
{
slouken@1950
   191
    X11_QuitModes(_this);
slouken@1950
   192
    X11_QuitKeyboard(_this);
slouken@1950
   193
    X11_QuitMouse(_this);
slouken@1950
   194
}
slouken@1950
   195
slouken@1950
   196
/* vim: set ts=4 sw=4 expandtab: */