Initial pass for multi-window support.

This commit is contained in:
Camilla Berglund
2010-09-09 18:15:32 +02:00
parent 8247a6b3eb
commit 135194a960
14 changed files with 986 additions and 1006 deletions
+33 -118
View File
@@ -161,6 +161,10 @@ typedef const GLubyte* (APIENTRY *PFNGLGETSTRINGIPROC)(GLenum, GLuint);
#endif /*GL_VERSION_3_0*/
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 X11
#define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryX11 X11
//========================================================================
// Global variables (GLFW internals)
@@ -169,59 +173,7 @@ typedef const GLubyte* (APIENTRY *PFNGLGETSTRINGIPROC)(GLenum, GLuint);
//------------------------------------------------------------------------
// Window structure
//------------------------------------------------------------------------
typedef struct _GLFWwin_struct _GLFWwin;
struct _GLFWwin_struct {
// ========= PLATFORM INDEPENDENT MANDATORY PART =========================
// User callback functions
GLFWwindowsizefun windowSizeCallback;
GLFWwindowclosefun windowCloseCallback;
GLFWwindowrefreshfun windowRefreshCallback;
GLFWmousebuttonfun mouseButtonCallback;
GLFWmouseposfun mousePosCallback;
GLFWmousewheelfun mouseWheelCallback;
GLFWkeyfun keyCallback;
GLFWcharfun charCallback;
// User selected window settings
int fullscreen; // Fullscreen flag
int mouseLock; // Mouse-lock flag
int sysKeysDisabled; // System keys disabled flag
int windowNoResize; // Resize- and maximize gadgets disabled flag
int refreshRate; // Vertical monitor refresh rate
// Window status & parameters
int opened; // Flag telling if window is opened or not
int active; // Application active flag
int iconified; // Window iconified flag
int width, height; // Window width and heigth
int accelerated; // GL_TRUE if window is HW accelerated
// Framebuffer attributes
int redBits;
int greenBits;
int blueBits;
int alphaBits;
int depthBits;
int stencilBits;
int accumRedBits;
int accumGreenBits;
int accumBlueBits;
int accumAlphaBits;
int auxBuffers;
int stereo;
int samples;
// OpenGL extensions and context attributes
int glMajor, glMinor, glRevision;
int glForward, glDebug, glProfile;
PFNGLGETSTRINGIPROC GetStringi;
// ========= PLATFORM SPECIFIC PART ======================================
typedef struct _GLFWwindowX11 {
// Platform specific window resources
Colormap colormap; // Window colormap
@@ -238,6 +190,8 @@ struct _GLFWwin_struct {
Atom wmActiveWindow; // _NET_ACTIVE_WINDOW atom
Cursor cursor; // Invisible cursor for hidden cursor
int mouseMoved, cursorPosX, cursorPosY;
// GLX extensions
PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI;
PFNGLXGETFBCONFIGATTRIBSGIXPROC GetFBConfigAttribSGIX;
@@ -258,6 +212,30 @@ struct _GLFWwin_struct {
GLboolean pointerGrabbed; // True if pointer is currently grabbed
GLboolean pointerHidden; // True if pointer is currently hidden
} _GLFWwindowX11;
//------------------------------------------------------------------------
// Platform-specific ibrary global data
//------------------------------------------------------------------------
typedef struct {
Display* display;
// Server-side GLX version
int glxMajor, glxMinor;
struct {
int available;
int eventBase;
int errorBase;
} XF86VidMode;
struct {
int available;
int eventBase;
int errorBase;
} XRandR;
// Screensaver data
struct {
int changed;
@@ -280,69 +258,6 @@ struct _GLFWwin_struct {
Rotation oldRotation;
#endif
} FS;
};
GLFWGLOBAL _GLFWwin _glfwWin;
//------------------------------------------------------------------------
// User input status (most of this should go in _GLFWwin)
//------------------------------------------------------------------------
GLFWGLOBAL struct {
// ========= PLATFORM INDEPENDENT MANDATORY PART =========================
// Mouse status
int MousePosX, MousePosY;
int WheelPos;
char MouseButton[ GLFW_MOUSE_BUTTON_LAST+1 ];
// Keyboard status
char Key[ GLFW_KEY_LAST+1 ];
int LastChar;
// User selected settings
int StickyKeys;
int StickyMouseButtons;
int KeyRepeat;
// ========= PLATFORM SPECIFIC PART ======================================
// Platform specific internal variables
int MouseMoved, CursorPosX, CursorPosY;
} _glfwInput;
//------------------------------------------------------------------------
// Library global data
//------------------------------------------------------------------------
GLFWGLOBAL struct {
// ========= PLATFORM INDEPENDENT MANDATORY PART =========================
// Window opening hints
_GLFWhints hints;
// ========= PLATFORM SPECIFIC PART ======================================
Display* display;
// Server-side GLX version
int glxMajor, glxMinor;
struct {
int available;
int eventBase;
int errorBase;
} XF86VidMode;
struct {
int available;
int eventBase;
int errorBase;
} XRandR;
// Timer data
struct {
@@ -355,7 +270,7 @@ GLFWGLOBAL struct {
void* libGL; // dlopen handle for libGL.so
} Libs;
#endif
} _glfwLibrary;
} _GLFWlibraryX11;
//------------------------------------------------------------------------
@@ -382,7 +297,7 @@ void _glfwInitTimer(void);
int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate);
void _glfwSetVideoModeMODE(int screen, int mode, int rate);
void _glfwSetVideoMode(int screen, int* width, int* height, int* rate);
void _glfwRestoreVideoMode(void);
void _glfwRestoreVideoMode(int screen);
// Joystick input
void _glfwInitJoysticks(void);
+7 -7
View File
@@ -39,12 +39,12 @@
// Enable system keys
//========================================================================
void _glfwPlatformEnableSystemKeys(void)
void _glfwPlatformEnableSystemKeys(_GLFWwindow* window)
{
if (_glfwWin.keyboardGrabbed)
if (window->X11.keyboardGrabbed)
{
XUngrabKeyboard(_glfwLibrary.display, CurrentTime);
_glfwWin.keyboardGrabbed = GL_FALSE;
XUngrabKeyboard(_glfwLibrary.X11.display, CurrentTime);
window->X11.keyboardGrabbed = GL_FALSE;
}
}
@@ -52,13 +52,13 @@ void _glfwPlatformEnableSystemKeys(void)
// Disable system keys
//========================================================================
void _glfwPlatformDisableSystemKeys(void)
void _glfwPlatformDisableSystemKeys(_GLFWwindow* window)
{
if (XGrabKeyboard(_glfwLibrary.display, _glfwWin.window,
if (XGrabKeyboard(_glfwLibrary.X11.display, window->X11.window,
True, GrabModeAsync, GrabModeAsync, CurrentTime)
== GrabSuccess)
{
_glfwWin.keyboardGrabbed = GL_TRUE;
window->X11.keyboardGrabbed = GL_TRUE;
}
}
+53 -51
View File
@@ -75,10 +75,10 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
XRRScreenConfiguration* sc;
XRRScreenSize* sizelist;
if (_glfwLibrary.XRandR.available)
if (_glfwLibrary.X11.XRandR.available)
{
sc = XRRGetScreenInfo(_glfwLibrary.display,
RootWindow(_glfwLibrary.display, screen));
sc = XRRGetScreenInfo(_glfwLibrary.X11.display,
RootWindow(_glfwLibrary.X11.display, screen));
sizelist = XRRConfigSizes(sc, &sizecount);
@@ -174,8 +174,8 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
#endif
// Default: Simply use the screen resolution
*width = DisplayWidth(_glfwLibrary.display, screen);
*height = DisplayHeight(_glfwLibrary.display, screen);
*width = DisplayWidth(_glfwLibrary.X11.display, screen);
*height = DisplayHeight(_glfwLibrary.X11.display, screen);
return 0;
}
@@ -191,25 +191,25 @@ void _glfwSetVideoModeMODE(int screen, int mode, int rate)
XRRScreenConfiguration* sc;
Window root;
if (_glfwLibrary.XRandR.available)
if (_glfwLibrary.X11.XRandR.available)
{
root = RootWindow(_glfwLibrary.display, screen);
sc = XRRGetScreenInfo(_glfwLibrary.display, root);
root = RootWindow(_glfwLibrary.X11.display, screen);
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, root);
// Remember old size and flag that we have changed the mode
if (!_glfwWin.FS.modeChanged)
if (!_glfwLibrary.X11.FS.modeChanged)
{
_glfwWin.FS.oldSizeID = XRRConfigCurrentConfiguration(sc, &_glfwWin.FS.oldRotation);
_glfwWin.FS.oldWidth = DisplayWidth(_glfwLibrary.display, screen);
_glfwWin.FS.oldHeight = DisplayHeight(_glfwLibrary.display, screen);
_glfwLibrary.X11.FS.oldSizeID = XRRConfigCurrentConfiguration(sc, &_glfwLibrary.X11.FS.oldRotation);
_glfwLibrary.X11.FS.oldWidth = DisplayWidth(_glfwLibrary.X11.display, screen);
_glfwLibrary.X11.FS.oldHeight = DisplayHeight(_glfwLibrary.X11.display, screen);
_glfwWin.FS.modeChanged = GL_TRUE;
_glfwLibrary.X11.FS.modeChanged = GL_TRUE;
}
if (rate > 0)
{
// Set desired configuration
XRRSetScreenConfigAndRate(_glfwLibrary.display,
XRRSetScreenConfigAndRate(_glfwLibrary.X11.display,
sc,
root,
mode,
@@ -220,7 +220,7 @@ void _glfwSetVideoModeMODE(int screen, int mode, int rate)
else
{
// Set desired configuration
XRRSetScreenConfig(_glfwLibrary.display,
XRRSetScreenConfig(_glfwLibrary.X11.display,
sc,
root,
mode,
@@ -235,31 +235,31 @@ void _glfwSetVideoModeMODE(int screen, int mode, int rate)
int modecount;
// Use the XF86VidMode extension to control video resolution
if (_glfwLibrary.XF86VidMode.available)
if (_glfwLibrary.X11.XF86VidMode.available)
{
// Get a list of all available display modes
XF86VidModeGetAllModeLines(_glfwLibrary.display, screen,
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen,
&modecount, &modelist);
// Unlock mode switch if necessary
if (_glfwWin.FS.modeChanged)
XF86VidModeLockModeSwitch(_glfwLibrary.display, screen, 0);
if (_glfwLibrary.X11.FS.modeChanged)
XF86VidModeLockModeSwitch(_glfwLibrary.X11.display, screen, 0);
// Change the video mode to the desired mode
XF86VidModeSwitchToMode(_glfwLibrary.display, screen,
XF86VidModeSwitchToMode(_glfwLibrary.X11.display, screen,
modelist[mode]);
// Set viewport to upper left corner (where our window will be)
XF86VidModeSetViewPort(_glfwLibrary.display, screen, 0, 0);
XF86VidModeSetViewPort(_glfwLibrary.X11.display, screen, 0, 0);
// Lock mode switch
XF86VidModeLockModeSwitch(_glfwLibrary.display, screen, 1);
XF86VidModeLockModeSwitch(_glfwLibrary.X11.display, screen, 1);
// Remember old mode and flag that we have changed the mode
if (!_glfwWin.FS.modeChanged)
if (!_glfwLibrary.X11.FS.modeChanged)
{
_glfwWin.FS.oldMode = *modelist[0];
_glfwWin.FS.modeChanged = GL_TRUE;
_glfwLibrary.X11.FS.oldMode = *modelist[0];
_glfwLibrary.X11.FS.modeChanged = GL_TRUE;
}
// Free mode list
@@ -289,42 +289,44 @@ void _glfwSetVideoMode(int screen, int* width, int* height, int* rate)
// Restore the previously saved (original) video mode
//========================================================================
void _glfwRestoreVideoMode(void)
void _glfwRestoreVideoMode(int screen)
{
if (_glfwWin.FS.modeChanged)
if (_glfwLibrary.X11.FS.modeChanged)
{
#if defined(_GLFW_HAS_XRANDR)
if (_glfwLibrary.XRandR.available)
Window root = RootWindow(_glfwLibrary.X11.display, screen);
if (_glfwLibrary.X11.XRandR.available)
{
XRRScreenConfiguration* sc;
if (_glfwLibrary.XRandR.available)
if (_glfwLibrary.X11.XRandR.available)
{
sc = XRRGetScreenInfo(_glfwLibrary.display, _glfwWin.root);
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, root);
XRRSetScreenConfig(_glfwLibrary.display,
XRRSetScreenConfig(_glfwLibrary.X11.display,
sc,
_glfwWin.root,
_glfwWin.FS.oldSizeID,
_glfwWin.FS.oldRotation,
root,
_glfwLibrary.X11.FS.oldSizeID,
_glfwLibrary.X11.FS.oldRotation,
CurrentTime);
XRRFreeScreenConfigInfo(sc);
}
}
#elif defined(_GLFW_HAS_XF86VIDMODE)
if (_glfwLibrary.XF86VidMode.available)
if (_glfwLibrary.X11.XF86VidMode.available)
{
// Unlock mode switch
XF86VidModeLockModeSwitch(_glfwLibrary.display, _glfwWin.screen, 0);
XF86VidModeLockModeSwitch(_glfwLibrary.X11.display, screen, 0);
// Change the video mode back to the old mode
XF86VidModeSwitchToMode(_glfwLibrary.display,
_glfwWin.screen,
&_glfwWin.FS.oldMode);
XF86VidModeSwitchToMode(_glfwLibrary.X11.display,
screen,
&_glfwLibrary.X11.FS.oldMode);
}
#endif
_glfwWin.FS.modeChanged = GL_FALSE;
_glfwLibrary.X11.FS.modeChanged = GL_FALSE;
}
}
@@ -364,7 +366,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
#endif
// Get display and screen
dpy = _glfwLibrary.display;
dpy = _glfwLibrary.X11.display;
screen = DefaultScreen(dpy);
// Get list of visuals
@@ -410,7 +412,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
// Build resolution array
#if defined(_GLFW_HAS_XRANDR)
if (_glfwLibrary.XRandR.available)
if (_glfwLibrary.X11.XRandR.available)
{
sc = XRRGetScreenInfo(dpy, RootWindow(dpy, screen));
sizelist = XRRConfigSizes(sc, &sizecount);
@@ -505,7 +507,7 @@ void _glfwPlatformGetDesktopMode(GLFWvidmode* mode)
#endif
// Get display and screen
dpy = _glfwLibrary.display;
dpy = _glfwLibrary.X11.display;
screen = DefaultScreen(dpy);
// Get display depth
@@ -515,23 +517,23 @@ void _glfwPlatformGetDesktopMode(GLFWvidmode* mode)
BPP2RGB(bpp, &mode->redBits, &mode->greenBits, &mode->blueBits);
#if defined(_GLFW_HAS_XRANDR)
if (_glfwLibrary.XRandR.available)
if (_glfwLibrary.X11.XRandR.available)
{
if (_glfwWin.FS.modeChanged)
if (_glfwLibrary.X11.FS.modeChanged)
{
mode->width = _glfwWin.FS.oldWidth;
mode->height = _glfwWin.FS.oldHeight;
mode->width = _glfwLibrary.X11.FS.oldWidth;
mode->height = _glfwLibrary.X11.FS.oldHeight;
return;
}
}
#elif defined(_GLFW_HAS_XF86VIDMODE)
if (_glfwLibrary.XF86VidMode.available)
if (_glfwLibrary.X11.XF86VidMode.available)
{
if (_glfwWin.FS.modeChanged)
if (_glfwLibrary.X11.FS.modeChanged)
{
// The old (desktop) mode is stored in _glfwWin.FS.oldMode
mode->width = _glfwWin.FS.oldMode.hdisplay;
mode->height = _glfwWin.FS.oldMode.vdisplay;
mode->width = _glfwLibrary.X11.FS.oldMode.hdisplay;
mode->height = _glfwLibrary.X11.FS.oldMode.vdisplay;
}
else
{
+3 -2
View File
@@ -65,8 +65,9 @@ int _glfwPlatformExtensionSupported(const char* extension)
const GLubyte* extensions;
// Get list of GLX extensions
extensions = (const GLubyte*) glXQueryExtensionsString(_glfwLibrary.display,
_glfwWin.screen);
// Yuck
extensions = (const GLubyte*) glXQueryExtensionsString(_glfwLibrary.X11.display,
_glfwLibrary.window->X11.screen);
if (extensions != NULL)
{
if (_glfwStringInExtensionString(extension, extensions))
+21 -21
View File
@@ -82,8 +82,8 @@ static void glfw_atexit(void)
static int initDisplay(void)
{
// Open display
_glfwLibrary.display = XOpenDisplay(0);
if (!_glfwLibrary.display)
_glfwLibrary.X11.display = XOpenDisplay(0);
if (!_glfwLibrary.X11.display)
{
fprintf(stderr, "Failed to open X display\n");
return GL_FALSE;
@@ -91,36 +91,36 @@ static int initDisplay(void)
// Check for XF86VidMode extension
#ifdef _GLFW_HAS_XF86VIDMODE
_glfwLibrary.XF86VidMode.available =
XF86VidModeQueryExtension(_glfwLibrary.display,
&_glfwLibrary.XF86VidMode.eventBase,
&_glfwLibrary.XF86VidMode.errorBase);
_glfwLibrary.X11.XF86VidMode.available =
XF86VidModeQueryExtension(_glfwLibrary.X11.display,
&_glfwLibrary.X11.XF86VidMode.eventBase,
&_glfwLibrary.X11.XF86VidMode.errorBase);
#else
_glfwLibrary.XF86VidMode.available = 0;
_glfwLibrary.X11.XF86VidMode.available = 0;
#endif
// Check for XRandR extension
#ifdef _GLFW_HAS_XRANDR
_glfwLibrary.XRandR.available =
XRRQueryExtension(_glfwLibrary.display,
&_glfwLibrary.XRandR.eventBase,
&_glfwLibrary.XRandR.errorBase);
_glfwLibrary.X11.XRandR.available =
XRRQueryExtension(_glfwLibrary.X11.display,
&_glfwLibrary.X11.XRandR.eventBase,
&_glfwLibrary.X11.XRandR.errorBase);
#else
_glfwLibrary.XRandR.available = 0;
_glfwLibrary.X11.XRandR.available = 0;
#endif
// Fullscreen & screen saver settings
// Check if GLX is supported on this display
if (!glXQueryExtension(_glfwLibrary.display, NULL, NULL))
if (!glXQueryExtension(_glfwLibrary.X11.display, NULL, NULL))
{
fprintf(stderr, "GLX not supported\n");
return GL_FALSE;
}
// Retrieve GLX version
if (!glXQueryVersion(_glfwLibrary.display,
&_glfwLibrary.glxMajor,
&_glfwLibrary.glxMinor))
if (!glXQueryVersion(_glfwLibrary.X11.display,
&_glfwLibrary.X11.glxMajor,
&_glfwLibrary.X11.glxMinor))
{
fprintf(stderr, "Unable to query GLX version\n");
return GL_FALSE;
@@ -137,10 +137,10 @@ static int initDisplay(void)
static void terminateDisplay(void)
{
// Open display
if (_glfwLibrary.display)
if (_glfwLibrary.X11.display)
{
XCloseDisplay(_glfwLibrary.display);
_glfwLibrary.display = NULL;
XCloseDisplay(_glfwLibrary.X11.display);
_glfwLibrary.X11.display = NULL;
}
}
@@ -180,8 +180,8 @@ int _glfwPlatformInit(void)
int _glfwPlatformTerminate(void)
{
// Close OpenGL window
glfwCloseWindow();
if (_glfwLibrary.window)
glfwCloseWindow(_glfwLibrary.window);
// Terminate display
terminateDisplay();
+5 -5
View File
@@ -40,12 +40,12 @@ void _glfwInitTimer(void)
struct timeval tv;
// "Resolution" is 1 us
_glfwLibrary.Timer.resolution = 1e-6;
_glfwLibrary.X11.Timer.resolution = 1e-6;
// Set start-time for timer
gettimeofday(&tv, NULL);
_glfwLibrary.Timer.t0 = (long long) tv.tv_sec * (long long) 1000000 +
(long long) tv.tv_usec;
_glfwLibrary.X11.Timer.t0 = (long long) tv.tv_sec * (long long) 1000000 +
(long long) tv.tv_usec;
}
@@ -66,7 +66,7 @@ double _glfwPlatformGetTime(void)
t = (long long) tv.tv_sec * (long long) 1000000 +
(long long) tv.tv_usec;
return (double)(t - _glfwLibrary.Timer.t0) * _glfwLibrary.Timer.resolution;
return (double)(t - _glfwLibrary.X11.Timer.t0) * _glfwLibrary.X11.Timer.resolution;
}
@@ -84,6 +84,6 @@ void _glfwPlatformSetTime(double t)
(long long) tv.tv_usec;
// Calulate new starting time
_glfwLibrary.Timer.t0 = t0 - (long long)(t / _glfwLibrary.Timer.resolution);
_glfwLibrary.X11.Timer.t0 = t0 - (long long)(t / _glfwLibrary.X11.Timer.resolution);
}
+409 -433
View File
File diff suppressed because it is too large Load Diff