2006-07-26 06:34:54 +00:00
|
|
|
/*
|
2011-04-08 13:03:26 -07:00
|
|
|
Simple DirectMedia Layer
|
2016-01-02 10:10:34 -08:00
|
|
|
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
2011-04-08 13:03:26 -07:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
2006-07-26 06:34:54 +00:00
|
|
|
*/
|
2013-11-24 23:56:17 -05:00
|
|
|
#include "../../SDL_internal.h"
|
2006-07-26 06:34:54 +00:00
|
|
|
|
2011-03-12 13:21:57 -08:00
|
|
|
#if SDL_VIDEO_DRIVER_X11
|
|
|
|
|
2010-07-12 00:36:55 -07:00
|
|
|
#include <unistd.h> /* For getpid() and readlink() */
|
|
|
|
|
2006-07-26 06:34:54 +00:00
|
|
|
#include "SDL_video.h"
|
|
|
|
#include "SDL_mouse.h"
|
|
|
|
#include "../SDL_sysvideo.h"
|
|
|
|
#include "../SDL_pixels_c.h"
|
|
|
|
|
|
|
|
#include "SDL_x11video.h"
|
2011-02-04 18:05:20 -08:00
|
|
|
#include "SDL_x11framebuffer.h"
|
2010-06-30 16:19:44 -04:00
|
|
|
#include "SDL_x11shape.h"
|
2013-05-18 14:17:52 -07:00
|
|
|
#include "SDL_x11touch.h"
|
2012-05-31 13:37:02 +03:00
|
|
|
#include "SDL_x11xinput2.h"
|
2008-08-25 06:33:00 +00:00
|
|
|
|
2013-08-19 16:29:46 -03:00
|
|
|
#if SDL_VIDEO_OPENGL_EGL
|
2009-07-30 14:53:57 +00:00
|
|
|
#include "SDL_x11opengles.h"
|
|
|
|
#endif
|
2006-07-26 06:34:54 +00:00
|
|
|
|
|
|
|
/* Initialization/Query functions */
|
|
|
|
static int X11_VideoInit(_THIS);
|
|
|
|
static void X11_VideoQuit(_THIS);
|
|
|
|
|
2006-07-27 06:53:23 +00:00
|
|
|
/* Find out what class name we should use */
|
|
|
|
static char *
|
|
|
|
get_classname()
|
|
|
|
{
|
|
|
|
char *spot;
|
|
|
|
#if defined(__LINUX__) || defined(__FREEBSD__)
|
|
|
|
char procfile[1024];
|
|
|
|
char linkfile[1024];
|
|
|
|
int linksize;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* First allow environment variable override */
|
|
|
|
spot = SDL_getenv("SDL_VIDEO_X11_WMCLASS");
|
|
|
|
if (spot) {
|
|
|
|
return SDL_strdup(spot);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Next look at the application's executable name */
|
|
|
|
#if defined(__LINUX__) || defined(__FREEBSD__)
|
|
|
|
#if defined(__LINUX__)
|
|
|
|
SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/exe", getpid());
|
|
|
|
#elif defined(__FREEBSD__)
|
|
|
|
SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/file",
|
|
|
|
getpid());
|
|
|
|
#else
|
|
|
|
#error Where can we find the executable name?
|
|
|
|
#endif
|
|
|
|
linksize = readlink(procfile, linkfile, sizeof(linkfile) - 1);
|
|
|
|
if (linksize > 0) {
|
|
|
|
linkfile[linksize] = '\0';
|
|
|
|
spot = SDL_strrchr(linkfile, '/');
|
|
|
|
if (spot) {
|
|
|
|
return SDL_strdup(spot + 1);
|
|
|
|
} else {
|
|
|
|
return SDL_strdup(linkfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* __LINUX__ || __FREEBSD__ */
|
|
|
|
|
|
|
|
/* Finally use the default we've used forever */
|
|
|
|
return SDL_strdup("SDL_App");
|
|
|
|
}
|
|
|
|
|
2006-07-26 06:34:54 +00:00
|
|
|
/* X11 driver bootstrap functions */
|
|
|
|
|
|
|
|
static int
|
|
|
|
X11_Available(void)
|
|
|
|
{
|
|
|
|
Display *display = NULL;
|
|
|
|
if (SDL_X11_LoadSymbols()) {
|
2013-10-18 01:36:41 -04:00
|
|
|
display = X11_XOpenDisplay(NULL);
|
2006-07-26 06:34:54 +00:00
|
|
|
if (display != NULL) {
|
2013-10-18 01:36:41 -04:00
|
|
|
X11_XCloseDisplay(display);
|
2006-07-26 06:34:54 +00:00
|
|
|
}
|
|
|
|
SDL_X11_UnloadSymbols();
|
|
|
|
}
|
|
|
|
return (display != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
X11_DeleteDevice(SDL_VideoDevice * device)
|
|
|
|
{
|
|
|
|
SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
|
|
|
|
if (data->display) {
|
2013-10-18 01:36:41 -04:00
|
|
|
X11_XCloseDisplay(data->display);
|
2006-07-26 06:34:54 +00:00
|
|
|
}
|
2008-03-07 17:20:37 +00:00
|
|
|
SDL_free(data->windowlist);
|
2006-07-26 06:34:54 +00:00
|
|
|
SDL_free(device->driverdata);
|
|
|
|
SDL_free(device);
|
|
|
|
|
|
|
|
SDL_X11_UnloadSymbols();
|
|
|
|
}
|
|
|
|
|
2012-09-28 14:12:45 -04:00
|
|
|
/* An error handler to reset the vidmode and then call the default handler. */
|
|
|
|
static SDL_bool safety_net_triggered = SDL_FALSE;
|
|
|
|
static int (*orig_x11_errhandler) (Display *, XErrorEvent *) = NULL;
|
|
|
|
static int
|
|
|
|
X11_SafetyNetErrHandler(Display * d, XErrorEvent * e)
|
|
|
|
{
|
2013-08-21 10:12:16 -03:00
|
|
|
SDL_VideoDevice *device = NULL;
|
2012-09-28 14:12:45 -04:00
|
|
|
/* if we trigger an error in our error handler, don't try again. */
|
|
|
|
if (!safety_net_triggered) {
|
|
|
|
safety_net_triggered = SDL_TRUE;
|
2013-08-21 10:12:16 -03:00
|
|
|
device = SDL_GetVideoDevice();
|
2012-09-28 14:12:45 -04:00
|
|
|
if (device != NULL) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < device->num_displays; i++) {
|
|
|
|
SDL_VideoDisplay *display = &device->displays[i];
|
|
|
|
if (SDL_memcmp(&display->current_mode, &display->desktop_mode,
|
|
|
|
sizeof (SDL_DisplayMode)) != 0) {
|
|
|
|
X11_SetDisplayMode(device, display, &display->desktop_mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (orig_x11_errhandler != NULL) {
|
|
|
|
return orig_x11_errhandler(d, e); /* probably terminate. */
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-26 06:34:54 +00:00
|
|
|
static SDL_VideoDevice *
|
|
|
|
X11_CreateDevice(int devindex)
|
|
|
|
{
|
|
|
|
SDL_VideoDevice *device;
|
|
|
|
SDL_VideoData *data;
|
|
|
|
const char *display = NULL; /* Use the DISPLAY environment variable */
|
|
|
|
|
|
|
|
if (!SDL_X11_LoadSymbols()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-01-21 02:50:11 -05:00
|
|
|
/* Need for threading gl calls. This is also required for the proprietary
|
|
|
|
nVidia driver to be threaded. */
|
2013-10-18 01:36:41 -04:00
|
|
|
X11_XInitThreads();
|
2012-10-11 09:37:38 -07:00
|
|
|
|
2006-07-26 06:34:54 +00:00
|
|
|
/* Initialize all variables that we clean on shutdown */
|
|
|
|
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
|
2008-03-06 23:07:02 +00:00
|
|
|
if (!device) {
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
return NULL;
|
2006-07-26 06:34:54 +00:00
|
|
|
}
|
2008-03-06 23:07:02 +00:00
|
|
|
data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
|
|
|
|
if (!data) {
|
|
|
|
SDL_free(device);
|
2013-03-31 12:48:50 -04:00
|
|
|
SDL_OutOfMemory();
|
2006-07-26 06:34:54 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
device->driverdata = data;
|
|
|
|
|
2015-04-22 16:50:48 -04:00
|
|
|
data->global_mouse_changed = SDL_TRUE;
|
|
|
|
|
2006-07-26 06:34:54 +00:00
|
|
|
/* FIXME: Do we need this?
|
2013-10-18 01:36:41 -04:00
|
|
|
if ( (SDL_strncmp(X11_XDisplayName(display), ":", 1) == 0) ||
|
|
|
|
(SDL_strncmp(X11_XDisplayName(display), "unix:", 5) == 0) ) {
|
2006-07-26 06:34:54 +00:00
|
|
|
local_X11 = 1;
|
|
|
|
} else {
|
|
|
|
local_X11 = 0;
|
|
|
|
}
|
|
|
|
*/
|
2013-10-18 01:36:41 -04:00
|
|
|
data->display = X11_XOpenDisplay(display);
|
2006-07-26 06:34:54 +00:00
|
|
|
#if defined(__osf__) && defined(SDL_VIDEO_DRIVER_X11_DYNAMIC)
|
|
|
|
/* On Tru64 if linking without -lX11, it fails and you get following message.
|
|
|
|
* Xlib: connection to ":0.0" refused by server
|
|
|
|
* Xlib: XDM authorization key matches an existing client!
|
|
|
|
*
|
|
|
|
* It succeeds if retrying 1 second later
|
|
|
|
* or if running xhost +localhost on shell.
|
|
|
|
*/
|
|
|
|
if (data->display == NULL) {
|
|
|
|
SDL_Delay(1000);
|
2013-10-18 01:36:41 -04:00
|
|
|
data->display = X11_XOpenDisplay(display);
|
2006-07-26 06:34:54 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (data->display == NULL) {
|
2012-07-18 14:48:32 -07:00
|
|
|
SDL_free(device->driverdata);
|
2006-07-26 06:34:54 +00:00
|
|
|
SDL_free(device);
|
|
|
|
SDL_SetError("Couldn't open X11 display");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#ifdef X11_DEBUG
|
2013-10-18 01:36:41 -04:00
|
|
|
X11_XSynchronize(data->display, True);
|
2006-07-26 06:34:54 +00:00
|
|
|
#endif
|
|
|
|
|
2012-09-28 14:12:45 -04:00
|
|
|
/* Hook up an X11 error handler to recover the desktop resolution. */
|
|
|
|
safety_net_triggered = SDL_FALSE;
|
2013-10-18 01:36:41 -04:00
|
|
|
orig_x11_errhandler = X11_XSetErrorHandler(X11_SafetyNetErrHandler);
|
2012-09-28 14:12:45 -04:00
|
|
|
|
2006-07-26 06:34:54 +00:00
|
|
|
/* Set the function pointers */
|
|
|
|
device->VideoInit = X11_VideoInit;
|
|
|
|
device->VideoQuit = X11_VideoQuit;
|
|
|
|
device->GetDisplayModes = X11_GetDisplayModes;
|
2012-06-19 14:19:05 -03:00
|
|
|
device->GetDisplayBounds = X11_GetDisplayBounds;
|
2016-01-04 23:52:40 -05:00
|
|
|
device->GetDisplayUsableBounds = X11_GetDisplayUsableBounds;
|
2015-07-29 17:19:02 -07:00
|
|
|
device->GetDisplayDPI = X11_GetDisplayDPI;
|
2006-07-26 06:34:54 +00:00
|
|
|
device->SetDisplayMode = X11_SetDisplayMode;
|
2009-01-12 06:19:05 +00:00
|
|
|
device->SuspendScreenSaver = X11_SuspendScreenSaver;
|
2006-07-27 06:53:23 +00:00
|
|
|
device->PumpEvents = X11_PumpEvents;
|
2006-07-26 06:34:54 +00:00
|
|
|
|
|
|
|
device->CreateWindow = X11_CreateWindow;
|
|
|
|
device->CreateWindowFrom = X11_CreateWindowFrom;
|
|
|
|
device->SetWindowTitle = X11_SetWindowTitle;
|
2009-01-02 17:39:48 +00:00
|
|
|
device->SetWindowIcon = X11_SetWindowIcon;
|
2006-07-26 06:34:54 +00:00
|
|
|
device->SetWindowPosition = X11_SetWindowPosition;
|
|
|
|
device->SetWindowSize = X11_SetWindowSize;
|
2013-08-09 23:13:52 -07:00
|
|
|
device->SetWindowMinimumSize = X11_SetWindowMinimumSize;
|
|
|
|
device->SetWindowMaximumSize = X11_SetWindowMaximumSize;
|
2016-01-05 02:29:06 -05:00
|
|
|
device->GetWindowBordersSize = X11_GetWindowBordersSize;
|
2016-01-05 02:46:10 -05:00
|
|
|
device->SetWindowOpacity = X11_SetWindowOpacity;
|
2015-04-21 09:45:58 -04:00
|
|
|
device->SetWindowModalFor = X11_SetWindowModalFor;
|
2016-01-05 02:28:56 -05:00
|
|
|
device->SetWindowInputFocus = X11_SetWindowInputFocus;
|
2006-07-26 06:34:54 +00:00
|
|
|
device->ShowWindow = X11_ShowWindow;
|
|
|
|
device->HideWindow = X11_HideWindow;
|
|
|
|
device->RaiseWindow = X11_RaiseWindow;
|
|
|
|
device->MaximizeWindow = X11_MaximizeWindow;
|
|
|
|
device->MinimizeWindow = X11_MinimizeWindow;
|
|
|
|
device->RestoreWindow = X11_RestoreWindow;
|
2012-09-13 01:43:53 -04:00
|
|
|
device->SetWindowBordered = X11_SetWindowBordered;
|
2016-09-29 22:52:41 -04:00
|
|
|
device->SetWindowResizable = X11_SetWindowResizable;
|
2011-02-15 17:23:02 -08:00
|
|
|
device->SetWindowFullscreen = X11_SetWindowFullscreen;
|
2011-03-11 08:49:20 -08:00
|
|
|
device->SetWindowGammaRamp = X11_SetWindowGammaRamp;
|
2006-07-26 06:34:54 +00:00
|
|
|
device->SetWindowGrab = X11_SetWindowGrab;
|
|
|
|
device->DestroyWindow = X11_DestroyWindow;
|
2011-02-04 18:05:20 -08:00
|
|
|
device->CreateWindowFramebuffer = X11_CreateWindowFramebuffer;
|
|
|
|
device->UpdateWindowFramebuffer = X11_UpdateWindowFramebuffer;
|
|
|
|
device->DestroyWindowFramebuffer = X11_DestroyWindowFramebuffer;
|
2006-07-26 06:34:54 +00:00
|
|
|
device->GetWindowWMInfo = X11_GetWindowWMInfo;
|
2014-05-28 01:22:47 -04:00
|
|
|
device->SetWindowHitTest = X11_SetWindowHitTest;
|
2011-02-04 18:05:20 -08:00
|
|
|
|
2010-06-30 16:19:44 -04:00
|
|
|
device->shape_driver.CreateShaper = X11_CreateShaper;
|
|
|
|
device->shape_driver.SetWindowShape = X11_SetWindowShape;
|
|
|
|
device->shape_driver.ResizeWindowShape = X11_ResizeWindowShape;
|
2011-02-04 18:05:20 -08:00
|
|
|
|
2011-01-24 17:38:18 -08:00
|
|
|
#if SDL_VIDEO_OPENGL_GLX
|
Improved simultaneous support for OpenGL and OpenGL ES
From Scott Percival
Okay, I think I have something for this. Tested it on GL and GLES
machines, it seems to work okay.
- Add a new SDL GL attribute SDL_GL_CONTEXT_EGL:
- Only useful for the X11 video driver at the moment
- Set to 1 for an EGL context, 0 to use the default for the video driver
- Default is 0, unless library is built for EGL only
- Should be set after SDL init, but before window/context
creation (i.e. same place you'd specify attributes for major/minor GL
version)
- After a lot of agony pondering the least-terrible way to go about
it, made it so that X11_GL_LoadLibrary and X11_GLES_LoadLibrary check
SDL_GL_CONTEXT_EGL. If no GL context exists yet, and the attribute
choice doesn't match with the checking function, then it changes all
the function pointers in the video driver and passes control on to the
new LoadLibrary method.
- Likewise, make X11_CreateWindow check this attribute before firing
off a call to X11_GL_GetVisual/X11_GLES_GetVisual
- Added a sanity check to the start of X11_GL_LoadLibrary
- Tidied up SDL_x11opengles.h
- Moved ownership of the gles_data structure over to
X11_GLES_LoadLibrary/UnloadLibrary
- Should incorporate the 3 fixes posted by Andre Heider
This is obviously quite a bit to take in, but is (at least) a proof of
concept for the approach I think EGL/GLX mingling should take. Any
comments/criticism is much appreciated.
2012-07-18 15:17:27 -07:00
|
|
|
device->GL_LoadLibrary = X11_GL_LoadLibrary;
|
|
|
|
device->GL_GetProcAddress = X11_GL_GetProcAddress;
|
|
|
|
device->GL_UnloadLibrary = X11_GL_UnloadLibrary;
|
|
|
|
device->GL_CreateContext = X11_GL_CreateContext;
|
|
|
|
device->GL_MakeCurrent = X11_GL_MakeCurrent;
|
|
|
|
device->GL_SetSwapInterval = X11_GL_SetSwapInterval;
|
|
|
|
device->GL_GetSwapInterval = X11_GL_GetSwapInterval;
|
|
|
|
device->GL_SwapWindow = X11_GL_SwapWindow;
|
|
|
|
device->GL_DeleteContext = X11_GL_DeleteContext;
|
2013-08-19 16:29:46 -03:00
|
|
|
#elif SDL_VIDEO_OPENGL_EGL
|
Improved simultaneous support for OpenGL and OpenGL ES
From Scott Percival
Okay, I think I have something for this. Tested it on GL and GLES
machines, it seems to work okay.
- Add a new SDL GL attribute SDL_GL_CONTEXT_EGL:
- Only useful for the X11 video driver at the moment
- Set to 1 for an EGL context, 0 to use the default for the video driver
- Default is 0, unless library is built for EGL only
- Should be set after SDL init, but before window/context
creation (i.e. same place you'd specify attributes for major/minor GL
version)
- After a lot of agony pondering the least-terrible way to go about
it, made it so that X11_GL_LoadLibrary and X11_GLES_LoadLibrary check
SDL_GL_CONTEXT_EGL. If no GL context exists yet, and the attribute
choice doesn't match with the checking function, then it changes all
the function pointers in the video driver and passes control on to the
new LoadLibrary method.
- Likewise, make X11_CreateWindow check this attribute before firing
off a call to X11_GL_GetVisual/X11_GLES_GetVisual
- Added a sanity check to the start of X11_GL_LoadLibrary
- Tidied up SDL_x11opengles.h
- Moved ownership of the gles_data structure over to
X11_GLES_LoadLibrary/UnloadLibrary
- Should incorporate the 3 fixes posted by Andre Heider
This is obviously quite a bit to take in, but is (at least) a proof of
concept for the approach I think EGL/GLX mingling should take. Any
comments/criticism is much appreciated.
2012-07-18 15:17:27 -07:00
|
|
|
device->GL_LoadLibrary = X11_GLES_LoadLibrary;
|
|
|
|
device->GL_GetProcAddress = X11_GLES_GetProcAddress;
|
|
|
|
device->GL_UnloadLibrary = X11_GLES_UnloadLibrary;
|
|
|
|
device->GL_CreateContext = X11_GLES_CreateContext;
|
|
|
|
device->GL_MakeCurrent = X11_GLES_MakeCurrent;
|
|
|
|
device->GL_SetSwapInterval = X11_GLES_SetSwapInterval;
|
|
|
|
device->GL_GetSwapInterval = X11_GLES_GetSwapInterval;
|
|
|
|
device->GL_SwapWindow = X11_GLES_SwapWindow;
|
|
|
|
device->GL_DeleteContext = X11_GLES_DeleteContext;
|
2009-07-30 14:53:57 +00:00
|
|
|
#endif
|
2006-07-26 06:34:54 +00:00
|
|
|
|
2010-07-12 00:36:55 -07:00
|
|
|
device->SetClipboardText = X11_SetClipboardText;
|
|
|
|
device->GetClipboardText = X11_GetClipboardText;
|
|
|
|
device->HasClipboardText = X11_HasClipboardText;
|
2014-06-18 20:11:39 +01:00
|
|
|
device->StartTextInput = X11_StartTextInput;
|
|
|
|
device->StopTextInput = X11_StopTextInput;
|
|
|
|
device->SetTextInputRect = X11_SetTextInputRect;
|
|
|
|
|
2006-07-26 06:34:54 +00:00
|
|
|
device->free = X11_DeleteDevice;
|
|
|
|
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoBootStrap X11_bootstrap = {
|
|
|
|
"x11", "SDL X11 video driver",
|
|
|
|
X11_Available, X11_CreateDevice
|
|
|
|
};
|
|
|
|
|
2010-07-20 00:57:01 -07:00
|
|
|
static int (*handler) (Display *, XErrorEvent *) = NULL;
|
|
|
|
static int
|
|
|
|
X11_CheckWindowManagerErrorHandler(Display * d, XErrorEvent * e)
|
|
|
|
{
|
|
|
|
if (e->error_code == BadWindow) {
|
|
|
|
return (0);
|
|
|
|
} else {
|
|
|
|
return (handler(d, e));
|
|
|
|
}
|
|
|
|
}
|
2006-07-26 06:34:54 +00:00
|
|
|
|
2010-07-13 23:11:10 -07:00
|
|
|
static void
|
|
|
|
X11_CheckWindowManager(_THIS)
|
|
|
|
{
|
|
|
|
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
|
|
|
Display *display = data->display;
|
|
|
|
Atom _NET_SUPPORTING_WM_CHECK;
|
|
|
|
int status, real_format;
|
|
|
|
Atom real_type;
|
2013-11-27 10:29:27 -08:00
|
|
|
unsigned long items_read = 0, items_left = 0;
|
|
|
|
unsigned char *propdata = NULL;
|
2010-07-13 23:11:10 -07:00
|
|
|
Window wm_window = 0;
|
|
|
|
#ifdef DEBUG_WINDOW_MANAGER
|
|
|
|
char *wm_name;
|
|
|
|
#endif
|
|
|
|
|
2010-07-20 00:57:01 -07:00
|
|
|
/* Set up a handler to gracefully catch errors */
|
2013-10-18 01:36:41 -04:00
|
|
|
X11_XSync(display, False);
|
|
|
|
handler = X11_XSetErrorHandler(X11_CheckWindowManagerErrorHandler);
|
2010-07-20 00:57:01 -07:00
|
|
|
|
2013-10-18 01:36:41 -04:00
|
|
|
_NET_SUPPORTING_WM_CHECK = X11_XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", False);
|
|
|
|
status = X11_XGetWindowProperty(display, DefaultRootWindow(display), _NET_SUPPORTING_WM_CHECK, 0L, 1L, False, XA_WINDOW, &real_type, &real_format, &items_read, &items_left, &propdata);
|
2013-11-27 10:29:27 -08:00
|
|
|
if (status == Success) {
|
|
|
|
if (items_read) {
|
|
|
|
wm_window = ((Window*)propdata)[0];
|
|
|
|
}
|
|
|
|
if (propdata) {
|
|
|
|
X11_XFree(propdata);
|
|
|
|
propdata = NULL;
|
|
|
|
}
|
2010-07-20 00:57:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (wm_window) {
|
2013-10-18 01:36:41 -04:00
|
|
|
status = X11_XGetWindowProperty(display, wm_window, _NET_SUPPORTING_WM_CHECK, 0L, 1L, False, XA_WINDOW, &real_type, &real_format, &items_read, &items_left, &propdata);
|
2010-07-20 00:57:01 -07:00
|
|
|
if (status != Success || !items_read || wm_window != ((Window*)propdata)[0]) {
|
|
|
|
wm_window = None;
|
|
|
|
}
|
2013-11-27 10:29:27 -08:00
|
|
|
if (status == Success && propdata) {
|
2013-10-18 01:36:41 -04:00
|
|
|
X11_XFree(propdata);
|
2013-11-27 10:29:27 -08:00
|
|
|
propdata = NULL;
|
2010-07-20 00:57:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset the error handler, we're done checking */
|
2013-10-18 01:36:41 -04:00
|
|
|
X11_XSync(display, False);
|
|
|
|
X11_XSetErrorHandler(handler);
|
2010-07-13 23:11:10 -07:00
|
|
|
|
|
|
|
if (!wm_window) {
|
|
|
|
#ifdef DEBUG_WINDOW_MANAGER
|
|
|
|
printf("Couldn't get _NET_SUPPORTING_WM_CHECK property\n");
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
data->net_wm = SDL_TRUE;
|
|
|
|
|
|
|
|
#ifdef DEBUG_WINDOW_MANAGER
|
|
|
|
wm_name = X11_GetWindowTitle(_this, wm_window);
|
|
|
|
printf("Window manager: %s\n", wm_name);
|
|
|
|
SDL_free(wm_name);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-12-28 03:46:55 -05:00
|
|
|
|
2006-07-26 06:34:54 +00:00
|
|
|
int
|
|
|
|
X11_VideoInit(_THIS)
|
|
|
|
{
|
2006-07-27 06:53:23 +00:00
|
|
|
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
|
|
|
|
|
|
|
/* Get the window class name, usually the name of the application */
|
|
|
|
data->classname = get_classname();
|
|
|
|
|
2011-06-27 19:30:52 +02:00
|
|
|
/* Get the process PID to be associated to the window */
|
|
|
|
data->pid = getpid();
|
|
|
|
|
2016-01-05 02:27:26 -05:00
|
|
|
/* I have no idea how random this actually is, or has to be. */
|
|
|
|
data->window_group = (XID) (((size_t) data->pid) ^ ((size_t) _this));
|
|
|
|
|
2006-07-27 06:53:23 +00:00
|
|
|
/* Open a connection to the X input manager */
|
|
|
|
#ifdef X_HAVE_UTF8_STRING
|
|
|
|
if (SDL_X11_HAVE_UTF8) {
|
|
|
|
data->im =
|
2013-10-18 01:36:41 -04:00
|
|
|
X11_XOpenIM(data->display, NULL, data->classname, data->classname);
|
2006-07-27 06:53:23 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Look up some useful Atoms */
|
2013-10-18 01:36:41 -04:00
|
|
|
#define GET_ATOM(X) data->X = X11_XInternAtom(data->display, #X, False)
|
2012-11-02 14:15:21 -04:00
|
|
|
GET_ATOM(WM_PROTOCOLS);
|
2010-07-13 23:11:10 -07:00
|
|
|
GET_ATOM(WM_DELETE_WINDOW);
|
2016-01-05 02:27:50 -05:00
|
|
|
GET_ATOM(WM_TAKE_FOCUS);
|
2010-07-13 23:11:10 -07:00
|
|
|
GET_ATOM(_NET_WM_STATE);
|
|
|
|
GET_ATOM(_NET_WM_STATE_HIDDEN);
|
2012-09-27 23:55:38 -07:00
|
|
|
GET_ATOM(_NET_WM_STATE_FOCUSED);
|
2010-07-13 23:11:10 -07:00
|
|
|
GET_ATOM(_NET_WM_STATE_MAXIMIZED_VERT);
|
|
|
|
GET_ATOM(_NET_WM_STATE_MAXIMIZED_HORZ);
|
|
|
|
GET_ATOM(_NET_WM_STATE_FULLSCREEN);
|
2016-01-05 01:30:40 -05:00
|
|
|
GET_ATOM(_NET_WM_STATE_ABOVE);
|
|
|
|
GET_ATOM(_NET_WM_STATE_SKIP_TASKBAR);
|
|
|
|
GET_ATOM(_NET_WM_STATE_SKIP_PAGER);
|
2012-09-27 00:53:37 -04:00
|
|
|
GET_ATOM(_NET_WM_ALLOWED_ACTIONS);
|
|
|
|
GET_ATOM(_NET_WM_ACTION_FULLSCREEN);
|
2010-07-13 23:11:10 -07:00
|
|
|
GET_ATOM(_NET_WM_NAME);
|
|
|
|
GET_ATOM(_NET_WM_ICON_NAME);
|
|
|
|
GET_ATOM(_NET_WM_ICON);
|
2012-11-02 15:22:37 -04:00
|
|
|
GET_ATOM(_NET_WM_PING);
|
2016-01-05 02:46:10 -05:00
|
|
|
GET_ATOM(_NET_WM_WINDOW_OPACITY);
|
2016-01-04 16:25:27 -05:00
|
|
|
GET_ATOM(_NET_WM_USER_TIME);
|
2013-03-06 09:37:03 -08:00
|
|
|
GET_ATOM(_NET_ACTIVE_WINDOW);
|
2016-03-04 18:47:19 -05:00
|
|
|
GET_ATOM(_NET_FRAME_EXTENTS);
|
2010-07-13 23:11:10 -07:00
|
|
|
GET_ATOM(UTF8_STRING);
|
2013-03-13 21:41:43 -07:00
|
|
|
GET_ATOM(PRIMARY);
|
|
|
|
GET_ATOM(XdndEnter);
|
|
|
|
GET_ATOM(XdndPosition);
|
|
|
|
GET_ATOM(XdndStatus);
|
|
|
|
GET_ATOM(XdndTypeList);
|
|
|
|
GET_ATOM(XdndActionCopy);
|
|
|
|
GET_ATOM(XdndDrop);
|
|
|
|
GET_ATOM(XdndFinished);
|
|
|
|
GET_ATOM(XdndSelection);
|
2015-08-15 00:36:39 -04:00
|
|
|
GET_ATOM(XKLAVIER_STATE);
|
2010-07-13 23:11:10 -07:00
|
|
|
|
|
|
|
/* Detect the window manager */
|
|
|
|
X11_CheckWindowManager(_this);
|
2006-07-27 06:53:23 +00:00
|
|
|
|
2009-12-04 09:01:48 +00:00
|
|
|
if (X11_InitModes(_this) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2006-07-26 06:34:54 +00:00
|
|
|
|
2012-05-31 13:37:02 +03:00
|
|
|
X11_InitXinput2(_this);
|
2012-05-30 11:25:35 -04:00
|
|
|
|
2008-01-08 00:10:46 +00:00
|
|
|
if (X11_InitKeyboard(_this) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2006-07-26 06:34:54 +00:00
|
|
|
X11_InitMouse(_this);
|
|
|
|
|
2010-05-31 00:24:37 -04:00
|
|
|
X11_InitTouch(_this);
|
2012-12-28 03:46:55 -05:00
|
|
|
|
|
|
|
#if SDL_USE_LIBDBUS
|
2014-06-18 20:11:39 +01:00
|
|
|
SDL_DBus_Init();
|
2012-12-28 03:46:55 -05:00
|
|
|
#endif
|
|
|
|
|
2006-07-26 06:34:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
X11_VideoQuit(_THIS)
|
|
|
|
{
|
2006-07-27 06:53:23 +00:00
|
|
|
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
|
|
|
|
2013-08-29 08:29:21 -07:00
|
|
|
SDL_free(data->classname);
|
2006-07-27 06:53:23 +00:00
|
|
|
#ifdef X_HAVE_UTF8_STRING
|
|
|
|
if (data->im) {
|
2013-10-18 01:36:41 -04:00
|
|
|
X11_XCloseIM(data->im);
|
2006-07-27 06:53:23 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-07-26 06:34:54 +00:00
|
|
|
X11_QuitModes(_this);
|
|
|
|
X11_QuitKeyboard(_this);
|
|
|
|
X11_QuitMouse(_this);
|
2010-05-31 00:24:37 -04:00
|
|
|
X11_QuitTouch(_this);
|
2012-12-28 03:46:55 -05:00
|
|
|
|
|
|
|
#if SDL_USE_LIBDBUS
|
2014-06-18 20:11:39 +01:00
|
|
|
SDL_DBus_Quit();
|
2012-12-28 03:46:55 -05:00
|
|
|
#endif
|
2006-07-26 06:34:54 +00:00
|
|
|
}
|
|
|
|
|
2011-03-11 08:49:20 -08:00
|
|
|
SDL_bool
|
|
|
|
X11_UseDirectColorVisuals(void)
|
|
|
|
{
|
|
|
|
return SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ? SDL_FALSE : SDL_TRUE;
|
|
|
|
}
|
|
|
|
|
2011-03-12 13:21:57 -08:00
|
|
|
#endif /* SDL_VIDEO_DRIVER_X11 */
|
|
|
|
|
2006-07-26 06:34:54 +00:00
|
|
|
/* vim: set ts=4 sw=4 expandtab: */
|