Commit cc0b6550 authored by Sam Lantinga's avatar Sam Lantinga

Initial work on X11 window code in.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401997
parent 3ec5d40b
...@@ -66,7 +66,7 @@ struct SDL_WindowData ...@@ -66,7 +66,7 @@ struct SDL_WindowData
{ {
SDL_WindowID windowID; SDL_WindowID windowID;
NSWindow *window; NSWindow *window;
BOOL created; SDL_bool created;
Cocoa_WindowListener *listener; Cocoa_WindowListener *listener;
struct SDL_VideoData *videodata; struct SDL_VideoData *videodata;
}; };
......
...@@ -242,9 +242,10 @@ fprintf(stderr, "keyUp\n"); ...@@ -242,9 +242,10 @@ fprintf(stderr, "keyUp\n");
@end @end
static int static int
SetupWindowData(SDL_Window * window, NSWindow *nswindow, BOOL created) SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
{ {
NSAutoreleasePool *pool; NSAutoreleasePool *pool;
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
SDL_WindowData *data; SDL_WindowData *data;
/* Allocate the window data */ /* Allocate the window data */
...@@ -256,7 +257,7 @@ SetupWindowData(SDL_Window * window, NSWindow *nswindow, BOOL created) ...@@ -256,7 +257,7 @@ SetupWindowData(SDL_Window * window, NSWindow *nswindow, BOOL created)
data->windowID = window->id; data->windowID = window->id;
data->window = nswindow; data->window = nswindow;
data->created = created; data->created = created;
data->videodata = (SDL_VideoData *) SDL_GetVideoDevice()->driverdata; data->videodata = videodata;
pool = [[NSAutoreleasePool alloc] init]; pool = [[NSAutoreleasePool alloc] init];
...@@ -380,7 +381,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window) ...@@ -380,7 +381,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
[pool release]; [pool release];
if (SetupWindowData(window, nswindow, YES) < 0) { if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
[nswindow release]; [nswindow release];
return -1; return -1;
} }
...@@ -413,7 +414,7 @@ Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) ...@@ -413,7 +414,7 @@ Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
[pool release]; [pool release];
return SetupWindowData(window, nswindow, NO); return SetupWindowData(_this, window, nswindow, SDL_FALSE);
} }
void void
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include "SDL_config.h" #include "SDL_config.h"
#include "SDL_win32video.h" #include "SDL_win32video.h"
#include "SDL_version.h"
#include "SDL_syswm.h" #include "SDL_syswm.h"
#include "SDL_vkeys.h" #include "SDL_vkeys.h"
#include "../../events/SDL_events_c.h" #include "../../events/SDL_events_c.h"
...@@ -393,6 +392,18 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) ...@@ -393,6 +392,18 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
SDL_WindowData *data; SDL_WindowData *data;
/* Send a SDL_SYSWMEVENT if the application wants them */
if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) {
SDL_SysWMmsg wmmsg;
SDL_VERSION(&wmmsg.version);
wmmsg.hwnd = hwnd;
wmmsg.msg = msg;
wmmsg.wParam = wParam;
wmmsg.lParam = lParam;
SDL_SendSysWMEvent(&wmmsg);
}
/* Get the window data for the window */ /* Get the window data for the window */
data = (SDL_WindowData *) GetProp(hwnd, TEXT("SDL_WindowData")); data = (SDL_WindowData *) GetProp(hwnd, TEXT("SDL_WindowData"));
if (!data) { if (!data) {
...@@ -412,18 +423,6 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) ...@@ -412,18 +423,6 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
} }
#endif #endif
/* Send a SDL_SYSWMEVENT if the application wants them */
if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) {
SDL_SysWMmsg wmmsg;
SDL_VERSION(&wmmsg.version);
wmmsg.hwnd = hwnd;
wmmsg.msg = msg;
wmmsg.wParam = wParam;
wmmsg.lParam = lParam;
SDL_SendSysWMEvent(&wmmsg);
}
switch (msg) { switch (msg) {
case WM_SHOWWINDOW: case WM_SHOWWINDOW:
......
...@@ -31,8 +31,9 @@ ...@@ -31,8 +31,9 @@
static int static int
SetupWindowData(SDL_Window * window, HWND hwnd, BOOL created) SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
{ {
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
SDL_WindowData *data; SDL_WindowData *data;
/* Allocate the window data */ /* Allocate the window data */
...@@ -46,7 +47,7 @@ SetupWindowData(SDL_Window * window, HWND hwnd, BOOL created) ...@@ -46,7 +47,7 @@ SetupWindowData(SDL_Window * window, HWND hwnd, BOOL created)
data->hdc = GetDC(hwnd); data->hdc = GetDC(hwnd);
data->created = created; data->created = created;
data->mouse_pressed = SDL_FALSE; data->mouse_pressed = SDL_FALSE;
data->videodata = (SDL_VideoData *) SDL_GetVideoDevice()->driverdata; data->videodata = videodata;
/* Associate the data with the window */ /* Associate the data with the window */
if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) { if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) {
...@@ -208,7 +209,7 @@ WIN_CreateWindow(_THIS, SDL_Window * window) ...@@ -208,7 +209,7 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
return -1; return -1;
} }
if (SetupWindowData(window, hwnd, TRUE) < 0) { if (SetupWindowData(_this, window, hwnd, SDL_TRUE) < 0) {
DestroyWindow(hwnd); DestroyWindow(hwnd);
return -1; return -1;
} }
...@@ -245,7 +246,7 @@ WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) ...@@ -245,7 +246,7 @@ WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
SDL_stack_free(title); SDL_stack_free(title);
} }
if (SetupWindowData(window, hwnd, FALSE) < 0) { if (SetupWindowData(_this, window, hwnd, SDL_FALSE) < 0) {
return -1; return -1;
} }
return 0; return 0;
......
...@@ -30,7 +30,7 @@ typedef struct ...@@ -30,7 +30,7 @@ typedef struct
HWND hwnd; HWND hwnd;
HDC hdc; HDC hdc;
WNDPROC wndproc; WNDPROC wndproc;
BOOL created; SDL_bool created;
int mouse_pressed; int mouse_pressed;
struct SDL_VideoData *videodata; struct SDL_VideoData *videodata;
} SDL_WindowData; } SDL_WindowData;
......
This diff is collapsed.
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#ifndef _SDL_x11events_h
#define _SDL_x11events_h
extern void X11_PumpEvents(_THIS);
extern void X11_SaveScreenSaver(Display * display, int *saved_timeout,
BOOL * dpms);
extern void X11_DisableScreenSaver(Display * display);
extern void X11_RestoreScreenSaver(Display * display, int saved_timeout,
BOOL dpms);
#endif /* _SDL_x11events_h */
/* vi: set ts=4 sw=4 expandtab: */
...@@ -106,6 +106,7 @@ X11_InitModes(_THIS) ...@@ -106,6 +106,7 @@ X11_InitModes(_THIS)
} }
displaydata->screen = screen; displaydata->screen = screen;
displaydata->visual = vinfo.visual; displaydata->visual = vinfo.visual;
displaydata->depth = vinfo.depth;
SDL_zero(display); SDL_zero(display);
display.desktop_mode = mode; display.desktop_mode = mode;
......
...@@ -28,6 +28,7 @@ typedef struct ...@@ -28,6 +28,7 @@ typedef struct
{ {
int screen; int screen;
Visual *visual; Visual *visual;
int depth;
} SDL_DisplayData; } SDL_DisplayData;
//typedef struct //typedef struct
......
...@@ -34,6 +34,49 @@ ...@@ -34,6 +34,49 @@
static int X11_VideoInit(_THIS); static int X11_VideoInit(_THIS);
static void X11_VideoQuit(_THIS); static void X11_VideoQuit(_THIS);
/* 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");
}
/* X11 driver bootstrap functions */ /* X11 driver bootstrap functions */
static int static int
...@@ -127,9 +170,8 @@ X11_CreateDevice(int devindex) ...@@ -127,9 +170,8 @@ X11_CreateDevice(int devindex)
device->SetDisplayMode = X11_SetDisplayMode; device->SetDisplayMode = X11_SetDisplayMode;
// device->SetDisplayGammaRamp = X11_SetDisplayGammaRamp; // device->SetDisplayGammaRamp = X11_SetDisplayGammaRamp;
// device->GetDisplayGammaRamp = X11_GetDisplayGammaRamp; // device->GetDisplayGammaRamp = X11_GetDisplayGammaRamp;
// device->PumpEvents = X11_PumpEvents; device->PumpEvents = X11_PumpEvents;
/*
device->CreateWindow = X11_CreateWindow; device->CreateWindow = X11_CreateWindow;
device->CreateWindowFrom = X11_CreateWindowFrom; device->CreateWindowFrom = X11_CreateWindowFrom;
device->SetWindowTitle = X11_SetWindowTitle; device->SetWindowTitle = X11_SetWindowTitle;
...@@ -144,6 +186,7 @@ X11_CreateDevice(int devindex) ...@@ -144,6 +186,7 @@ X11_CreateDevice(int devindex)
device->SetWindowGrab = X11_SetWindowGrab; device->SetWindowGrab = X11_SetWindowGrab;
device->DestroyWindow = X11_DestroyWindow; device->DestroyWindow = X11_DestroyWindow;
device->GetWindowWMInfo = X11_GetWindowWMInfo; device->GetWindowWMInfo = X11_GetWindowWMInfo;
/*
#ifdef SDL_VIDEO_OPENGL #ifdef SDL_VIDEO_OPENGL
device->GL_LoadLibrary = X11_GL_LoadLibrary; device->GL_LoadLibrary = X11_GL_LoadLibrary;
device->GL_GetProcAddress = X11_GL_GetProcAddress; device->GL_GetProcAddress = X11_GL_GetProcAddress;
...@@ -170,6 +213,28 @@ VideoBootStrap X11_bootstrap = { ...@@ -170,6 +213,28 @@ VideoBootStrap X11_bootstrap = {
int int
X11_VideoInit(_THIS) X11_VideoInit(_THIS)
{ {
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
/* Get the window class name, usually the name of the application */
data->classname = get_classname();
/* Open a connection to the X input manager */
#ifdef X_HAVE_UTF8_STRING
if (SDL_X11_HAVE_UTF8) {
data->im =
XOpenIM(data->display, NULL, data->classname, data->classname);
}
#endif
/* Save DPMS and screensaver settings */
X11_SaveScreenSaver(data->display, &data->screensaver_timeout,
&data->dpms_enabled);
X11_DisableScreenSaver(data->display);
/* Look up some useful Atoms */
data->WM_DELETE_WINDOW =
XInternAtom(data->display, "WM_DELETE_WINDOW", False);
X11_InitModes(_this); X11_InitModes(_this);
//#if SDL_VIDEO_RENDER_D3D //#if SDL_VIDEO_RENDER_D3D
...@@ -188,6 +253,19 @@ X11_VideoInit(_THIS) ...@@ -188,6 +253,19 @@ X11_VideoInit(_THIS)
void void
X11_VideoQuit(_THIS) X11_VideoQuit(_THIS)
{ {
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
if (data->classname) {
SDL_free(data->classname);
}
#ifdef X_HAVE_UTF8_STRING
if (data->im) {
XCloseIM(data->im);
}
#endif
X11_RestoreScreenSaver(data->display, data->screensaver_timeout,
data->dpms_enabled);
X11_QuitModes(_this); X11_QuitModes(_this);
X11_QuitKeyboard(_this); X11_QuitKeyboard(_this);
X11_QuitMouse(_this); X11_QuitMouse(_this);
......
...@@ -30,14 +30,6 @@ ...@@ -30,14 +30,6 @@
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
//#include "SDL_x11events.h"
//#include "SDL_x11gamma.h"
#include "SDL_x11keyboard.h"
#include "SDL_x11modes.h"
#include "SDL_x11mouse.h"
//#include "SDL_x11opengl.h"
//#include "SDL_x11window.h"
#if SDL_VIDEO_DRIVER_X11_XINERAMA #if SDL_VIDEO_DRIVER_X11_XINERAMA
#include "../Xext/extensions/Xinerama.h" #include "../Xext/extensions/Xinerama.h"
#endif #endif
...@@ -56,13 +48,28 @@ ...@@ -56,13 +48,28 @@
#include "SDL_x11dyn.h" #include "SDL_x11dyn.h"
#include "SDL_x11events.h"
//#include "SDL_x11gamma.h"
#include "SDL_x11keyboard.h"
#include "SDL_x11modes.h"
#include "SDL_x11mouse.h"
//#include "SDL_x11opengl.h"
#include "SDL_x11window.h"
/* Private display data */ /* Private display data */
typedef struct SDL_VideoData typedef struct SDL_VideoData
{ {
Display *display; Display *display;
char *classname;
XIM im;
int screensaver_timeout;
BOOL dpms_enabled;
int numwindows;
SDL_WindowData **windowlist;
int mouse; int mouse;
int keyboard; int keyboard;
Atom WM_DELETE_WINDOW;
} SDL_VideoData; } SDL_VideoData;
#endif /* _SDL_x11video_h */ #endif /* _SDL_x11video_h */
......
This diff is collapsed.
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#ifndef _SDL_x11window_h
#define _SDL_x11window_h
typedef struct
{
SDL_WindowID windowID;
Window window;
XIC ic;
SDL_bool created;
struct SDL_VideoData *videodata;
} SDL_WindowData;
extern int X11_CreateWindow(_THIS, SDL_Window * window);
extern int X11_CreateWindowFrom(_THIS, SDL_Window * window, const void *data);
extern void X11_SetWindowTitle(_THIS, SDL_Window * window);
extern void X11_SetWindowPosition(_THIS, SDL_Window * window);
extern void X11_SetWindowSize(_THIS, SDL_Window * window);
extern void X11_ShowWindow(_THIS, SDL_Window * window);
extern void X11_HideWindow(_THIS, SDL_Window * window);
extern void X11_RaiseWindow(_THIS, SDL_Window * window);
extern void X11_MaximizeWindow(_THIS, SDL_Window * window);
extern void X11_MinimizeWindow(_THIS, SDL_Window * window);
extern void X11_RestoreWindow(_THIS, SDL_Window * window);
extern void X11_SetWindowGrab(_THIS, SDL_Window * window);
extern void X11_DestroyWindow(_THIS, SDL_Window * window);
extern SDL_bool X11_GetWindowWMInfo(_THIS, SDL_Window * window,
struct SDL_SysWMinfo *info);
#endif /* _SDL_x11window_h */
/* vi: set ts=4 sw=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment