2010-07-10 08:20:50 +00:00
|
|
|
/* ZZ Open GL graphics plugin
|
|
|
|
* Copyright (c)2009-2010 zeydlitz@gmail.com, arcum42@gmail.com
|
|
|
|
* Based on Zerofrog's ZeroGS KOSMOS (c)2005-2008
|
2010-03-19 02:04:55 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-07-04 22:49:00 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2010-03-19 02:04:55 +00:00
|
|
|
*/
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-09-01 10:28:37 +00:00
|
|
|
#include "Util.h"
|
|
|
|
#include "GLWin.h"
|
2010-03-19 02:04:55 +00:00
|
|
|
|
|
|
|
#ifdef GL_X11_WINDOW
|
|
|
|
|
2010-06-11 11:48:07 +00:00
|
|
|
#include <X11/Xlib.h>
|
2010-09-08 11:16:27 +00:00
|
|
|
#include <stdlib.h>
|
2010-06-11 11:48:07 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
#ifdef USE_GSOPEN2
|
|
|
|
bool GLWindow::CreateWindow(void *pDisplay)
|
|
|
|
{
|
|
|
|
glWindow = (Window)*((u32*)(pDisplay)+1);
|
|
|
|
// Do not take the display which come from pcsx2 neither change it.
|
|
|
|
// You need a new one to do the operation in the GS thread
|
|
|
|
glDisplay = XOpenDisplay(NULL);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#else
|
2010-03-19 02:04:55 +00:00
|
|
|
bool GLWindow::CreateWindow(void *pDisplay)
|
2010-04-25 00:31:27 +00:00
|
|
|
{
|
2010-09-05 16:30:47 +00:00
|
|
|
// init support of multi thread
|
|
|
|
if (!XInitThreads())
|
|
|
|
ZZLog::Error_Log("Failed to init the xlib concurent threads");
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
glDisplay = XOpenDisplay(NULL);
|
2010-03-19 02:04:55 +00:00
|
|
|
|
2010-11-10 11:15:48 +00:00
|
|
|
if (pDisplay == NULL)
|
|
|
|
{
|
|
|
|
ZZLog::Error_Log("Failed to create window. Exiting...");
|
|
|
|
return false;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
// Allow pad to use the display
|
2010-05-01 20:33:53 +00:00
|
|
|
*(Display**)pDisplay = glDisplay;
|
2011-06-12 14:48:36 +00:00
|
|
|
// Pad can use the window to grab the input. For the moment just set to 0 to avoid
|
|
|
|
// to grab an unknow window... Anyway GSopen1 might be dropped in the future
|
|
|
|
*((u32*)(pDisplay)+1) = 0;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
return true;
|
2010-03-19 02:04:55 +00:00
|
|
|
}
|
2011-06-12 14:48:36 +00:00
|
|
|
#endif
|
2010-03-19 02:04:55 +00:00
|
|
|
|
2010-09-01 10:28:37 +00:00
|
|
|
bool GLWindow::ReleaseContext()
|
2010-04-25 00:31:27 +00:00
|
|
|
{
|
2010-09-06 22:21:07 +00:00
|
|
|
bool status = true;
|
|
|
|
if (!glDisplay) return status;
|
|
|
|
|
|
|
|
// free the context
|
|
|
|
if (context)
|
2010-03-19 06:38:44 +00:00
|
|
|
{
|
2010-09-06 22:21:07 +00:00
|
|
|
if (!glXMakeCurrent(glDisplay, None, NULL)) {
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Could not release drawing context.");
|
2010-09-06 22:21:07 +00:00
|
|
|
status = false;
|
|
|
|
}
|
2010-09-01 10:28:37 +00:00
|
|
|
|
2010-03-19 06:38:44 +00:00
|
|
|
glXDestroyContext(glDisplay, context);
|
|
|
|
context = NULL;
|
|
|
|
}
|
2010-09-01 10:28:37 +00:00
|
|
|
|
2010-09-06 22:21:07 +00:00
|
|
|
// free the visual
|
|
|
|
if (vi) {
|
|
|
|
XFree(vi);
|
|
|
|
vi = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
2010-09-01 10:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLWindow::CloseWindow()
|
|
|
|
{
|
|
|
|
SaveConfig();
|
2010-09-05 15:47:09 +00:00
|
|
|
if (!glDisplay) return;
|
2010-03-19 06:38:44 +00:00
|
|
|
|
2010-09-05 15:47:09 +00:00
|
|
|
XCloseDisplay(glDisplay);
|
|
|
|
glDisplay = NULL;
|
2010-03-19 02:04:55 +00:00
|
|
|
}
|
|
|
|
|
2010-09-01 10:28:37 +00:00
|
|
|
bool GLWindow::CreateVisual()
|
2010-03-19 02:04:55 +00:00
|
|
|
{
|
|
|
|
// attributes for a single buffered visual in RGBA format with at least
|
|
|
|
// 8 bits per color and a 24 bit depth buffer
|
2010-04-25 00:31:27 +00:00
|
|
|
int attrListSgl[] = {GLX_RGBA, GLX_RED_SIZE, 8,
|
|
|
|
GLX_GREEN_SIZE, 8,
|
|
|
|
GLX_BLUE_SIZE, 8,
|
2010-03-19 02:04:55 +00:00
|
|
|
GLX_DEPTH_SIZE, 24,
|
2010-05-01 20:33:53 +00:00
|
|
|
None
|
|
|
|
};
|
2010-03-19 02:04:55 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
// attributes for a double buffered visual in RGBA format with at least
|
2010-03-19 02:04:55 +00:00
|
|
|
// 8 bits per color and a 24 bit depth buffer
|
2010-04-25 00:31:27 +00:00
|
|
|
int attrListDbl[] = { GLX_RGBA, GLX_DOUBLEBUFFER,
|
|
|
|
GLX_RED_SIZE, 8,
|
|
|
|
GLX_GREEN_SIZE, 8,
|
|
|
|
GLX_BLUE_SIZE, 8,
|
2010-03-19 02:04:55 +00:00
|
|
|
GLX_DEPTH_SIZE, 24,
|
2010-05-01 20:33:53 +00:00
|
|
|
None
|
|
|
|
};
|
2010-03-19 02:04:55 +00:00
|
|
|
|
|
|
|
/* get an appropriate visual */
|
2011-06-12 14:48:36 +00:00
|
|
|
vi = glXChooseVisual(glDisplay, DefaultScreen(glDisplay), attrListDbl);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
if (vi == NULL)
|
2010-03-19 06:38:44 +00:00
|
|
|
{
|
2011-06-12 14:48:36 +00:00
|
|
|
vi = glXChooseVisual(glDisplay, DefaultScreen(glDisplay), attrListSgl);
|
2010-03-19 06:38:44 +00:00
|
|
|
doubleBuffered = false;
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Only Singlebuffered Visual!");
|
2010-03-19 02:04:55 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
else
|
2010-03-19 06:38:44 +00:00
|
|
|
{
|
|
|
|
doubleBuffered = true;
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Got Doublebuffered Visual!");
|
2010-03-19 02:04:55 +00:00
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
if (vi == NULL)
|
2010-04-08 21:58:14 +00:00
|
|
|
{
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Failed to get buffered Visual!");
|
2010-04-08 21:58:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-09-01 10:28:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLWindow::GetWindowSize()
|
|
|
|
{
|
2010-09-05 15:47:09 +00:00
|
|
|
if (!glDisplay or !glWindow) return;
|
|
|
|
|
2010-09-01 10:28:37 +00:00
|
|
|
unsigned int borderDummy;
|
|
|
|
Window winDummy;
|
2010-09-05 15:47:09 +00:00
|
|
|
s32 xDummy;
|
|
|
|
s32 yDummy;
|
2010-09-01 10:28:37 +00:00
|
|
|
|
2010-09-06 22:21:07 +00:00
|
|
|
XLockDisplay(glDisplay);
|
2010-09-05 15:47:09 +00:00
|
|
|
XGetGeometry(glDisplay, glWindow, &winDummy, &xDummy, &yDummy, &width, &height, &borderDummy, &depth);
|
2010-09-06 22:21:07 +00:00
|
|
|
XUnlockDisplay(glDisplay);
|
2010-09-08 11:16:27 +00:00
|
|
|
|
|
|
|
// update the gl buffer size
|
2010-11-14 01:38:10 +00:00
|
|
|
UpdateWindowSize(width, height);
|
2010-09-08 11:16:27 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
#ifndef USE_GSOPEN2
|
|
|
|
// too verbose!
|
2010-10-21 11:13:49 +00:00
|
|
|
ZZLog::Dev_Log("Resolution %dx%d. Depth %d bpp. Position (%d,%d)", width, height, depth, conf.x, conf.y);
|
2011-06-12 14:48:36 +00:00
|
|
|
#endif
|
2010-09-01 10:28:37 +00:00
|
|
|
}
|
2010-03-19 02:04:55 +00:00
|
|
|
|
2010-09-01 10:28:37 +00:00
|
|
|
void GLWindow::GetGLXVersion()
|
|
|
|
{
|
|
|
|
int glxMajorVersion, glxMinorVersion;
|
|
|
|
|
2010-03-19 06:38:44 +00:00
|
|
|
glXQueryVersion(glDisplay, &glxMajorVersion, &glxMinorVersion);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
if (glXIsDirect(glDisplay, context))
|
|
|
|
ZZLog::Error_Log("glX-Version %d.%d with Direct Rendering", glxMajorVersion, glxMinorVersion);
|
|
|
|
else
|
|
|
|
ZZLog::Error_Log("glX-Version %d.%d with Indirect Rendering !!! It will be slow", glxMajorVersion, glxMinorVersion);
|
|
|
|
|
2010-09-01 10:28:37 +00:00
|
|
|
}
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
void GLWindow::CreateContextGL()
|
2010-09-08 11:16:27 +00:00
|
|
|
{
|
2011-06-12 14:48:36 +00:00
|
|
|
if (!glDisplay) return;
|
|
|
|
|
|
|
|
// Create a 2.0 opengl context. My understanding, you need it to call the gl function to get the 3.0 context
|
|
|
|
context = glXCreateContext(glDisplay, vi, NULL, GL_TRUE);
|
|
|
|
|
2011-07-01 09:01:50 +00:00
|
|
|
// FIXME
|
|
|
|
// On Geforce7, the context 3.0 creation crashes with BadAlloc (insufficient resources for operation)
|
|
|
|
// So until a better solution is found, keep the 2.0 context -- Gregory
|
|
|
|
return;
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddress((GLubyte *) "glXCreateContextAttribsARB");
|
|
|
|
PFNGLXCHOOSEFBCONFIGPROC glXChooseFBConfig = (PFNGLXCHOOSEFBCONFIGPROC) glXGetProcAddress((GLubyte *) "glXChooseFBConfig");
|
|
|
|
if (!glXCreateContextAttribsARB or !glXChooseFBConfig) {
|
|
|
|
ZZLog::Error_Log("No support of OpenGL 3.0\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note this part seems linux specific
|
|
|
|
int fbcount = 0;
|
|
|
|
GLXFBConfig *framebuffer_config = glXChooseFBConfig(glDisplay, DefaultScreen(glDisplay), NULL, &fbcount);
|
|
|
|
if (!framebuffer_config or !fbcount) return;
|
|
|
|
|
|
|
|
// At least create a 3.0 context with compatibility profile
|
|
|
|
int attribs[] = {
|
|
|
|
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
|
|
|
|
GLX_CONTEXT_MINOR_VERSION_ARB, 0,
|
|
|
|
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
GLXContext context_temp = glXCreateContextAttribsARB(glDisplay, framebuffer_config[0], NULL, true, attribs);
|
|
|
|
if (context_temp) {
|
|
|
|
ZZLog::Error_Log("Create a 3.0 opengl context");
|
|
|
|
glXDestroyContext(glDisplay, context);
|
|
|
|
context = context_temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_GSOPEN2
|
|
|
|
bool GLWindow::DisplayWindow(int _width, int _height)
|
|
|
|
{
|
|
|
|
GetWindowSize();
|
|
|
|
|
|
|
|
if (!CreateVisual()) return false;
|
|
|
|
|
|
|
|
// connect the glx-context to the window
|
|
|
|
CreateContextGL();
|
|
|
|
glXMakeCurrent(glDisplay, glWindow, context);
|
|
|
|
|
|
|
|
GetGLXVersion();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
bool GLWindow::DisplayWindow(int _width, int _height)
|
|
|
|
{
|
|
|
|
backbuffer.w = _width;
|
|
|
|
backbuffer.h = _height;
|
|
|
|
|
|
|
|
if (!CreateVisual()) return false;
|
|
|
|
|
|
|
|
/* create a color map */
|
|
|
|
attr.colormap = XCreateColormap(glDisplay, RootWindow(glDisplay, vi->screen),
|
|
|
|
vi->visual, AllocNone);
|
|
|
|
attr.border_pixel = 0;
|
|
|
|
attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask |
|
|
|
|
StructureNotifyMask | SubstructureRedirectMask | SubstructureNotifyMask |
|
|
|
|
EnterWindowMask | LeaveWindowMask | FocusChangeMask ;
|
|
|
|
|
|
|
|
// Create a window at the last position/size
|
|
|
|
glWindow = XCreateWindow(glDisplay, RootWindow(glDisplay, vi->screen),
|
|
|
|
conf.x , conf.y , _width, _height, 0, vi->depth, InputOutput, vi->visual,
|
|
|
|
CWBorderPixel | CWColormap | CWEventMask,
|
|
|
|
&attr);
|
|
|
|
|
|
|
|
/* Allow to kill properly the window */
|
|
|
|
Atom wmDelete = XInternAtom(glDisplay, "WM_DELETE_WINDOW", True);
|
|
|
|
XSetWMProtocols(glDisplay, glWindow, &wmDelete, 1);
|
|
|
|
|
|
|
|
// Set icon name
|
|
|
|
XSetIconName(glDisplay, glWindow, "ZZogl-pg");
|
|
|
|
|
|
|
|
// Draw the window
|
|
|
|
XMapRaised(glDisplay, glWindow);
|
|
|
|
XSync(glDisplay, false);
|
|
|
|
|
|
|
|
// connect the glx-context to the window
|
|
|
|
CreateContextGL();
|
|
|
|
glXMakeCurrent(glDisplay, glWindow, context);
|
|
|
|
|
|
|
|
GetGLXVersion();
|
|
|
|
|
|
|
|
// Always start in window mode
|
|
|
|
fullScreen = 0;
|
|
|
|
GetWindowSize();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void GLWindow::SwapGLBuffers()
|
|
|
|
{
|
|
|
|
if (glGetError() != GL_NO_ERROR) ZZLog::Debug_Log("glError before swap!");
|
|
|
|
// FIXME I think we need to flush when there is only 1 visual buffer
|
|
|
|
glXSwapBuffers(glDisplay, glWindow);
|
|
|
|
// glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 THR_KeyEvent = 0; // Value for key event processing between threads
|
|
|
|
bool THR_bShift = false;
|
|
|
|
bool THR_bCtrl = false;
|
|
|
|
|
|
|
|
void GLWindow::ProcessEvents()
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
#ifdef USE_GSOPEN2
|
|
|
|
GetWindowSize();
|
|
|
|
#else
|
|
|
|
ResizeCheck();
|
2010-09-06 22:21:07 +00:00
|
|
|
#endif
|
2011-06-12 14:48:36 +00:00
|
|
|
|
|
|
|
if (THR_KeyEvent) // This value was passed from GSKeyEvents which could be in another thread
|
|
|
|
{
|
|
|
|
int my_KeyEvent = THR_KeyEvent;
|
|
|
|
bool my_bShift = THR_bShift;
|
|
|
|
bool my_bCtrl = THR_bCtrl;
|
|
|
|
THR_KeyEvent = 0;
|
|
|
|
|
|
|
|
switch (my_KeyEvent)
|
|
|
|
{
|
|
|
|
case XK_F5:
|
|
|
|
case XK_F6:
|
|
|
|
case XK_F7:
|
|
|
|
case XK_F9:
|
|
|
|
// Note: to avoid some clash with PCSX2 shortcut in GSOpen2.
|
|
|
|
// GS shortcut will only be activated when ctrl is press
|
|
|
|
if (my_bCtrl)
|
|
|
|
OnFKey(my_KeyEvent - XK_F1 + 1, my_bShift);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-05 15:47:09 +00:00
|
|
|
}
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
|
|
|
|
// ************************** Function that are either stub or useless in GSOPEN2
|
|
|
|
#define _NET_WM_STATE_REMOVE 0
|
|
|
|
#define _NET_WM_STATE_ADD 1
|
|
|
|
#define _NET_WM_STATE_TOGGLE 2
|
|
|
|
|
2010-09-08 11:16:27 +00:00
|
|
|
void GLWindow::Force43Ratio()
|
|
|
|
{
|
2011-06-12 14:48:36 +00:00
|
|
|
#ifndef USE_GSOPEN2
|
2010-09-08 11:16:27 +00:00
|
|
|
// avoid black border in fullscreen
|
|
|
|
if (fullScreen && conf.isWideScreen) {
|
|
|
|
conf.width = width;
|
|
|
|
conf.height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!fullScreen && !conf.isWideScreen) {
|
|
|
|
// Compute the width based on height
|
|
|
|
s32 new_width = (4*height)/3;
|
2011-06-12 14:48:36 +00:00
|
|
|
// do not bother to resize for 5 pixels. Avoid a loop
|
2010-09-08 11:16:27 +00:00
|
|
|
// due to round value
|
2012-04-07 21:23:01 +00:00
|
|
|
if ( ABS(new_width - width) > 5) {
|
2010-09-08 11:16:27 +00:00
|
|
|
width = new_width;
|
|
|
|
conf.width = new_width;
|
|
|
|
// resize the window
|
|
|
|
XLockDisplay(glDisplay);
|
|
|
|
XResizeWindow(glDisplay, glWindow, new_width, height);
|
|
|
|
XSync(glDisplay, False);
|
|
|
|
XUnlockDisplay(glDisplay);
|
|
|
|
}
|
|
|
|
}
|
2011-06-12 14:48:36 +00:00
|
|
|
#endif
|
2010-09-08 11:16:27 +00:00
|
|
|
}
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
void GLWindow::UpdateGrabKey()
|
|
|
|
{
|
|
|
|
// Do not stole the key in debug mode. It is not breakpoint friendly...
|
|
|
|
#ifndef _DEBUG
|
|
|
|
XLockDisplay(glDisplay);
|
|
|
|
if (fullScreen) {
|
|
|
|
XGrabPointer(glDisplay, glWindow, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, glWindow, None, CurrentTime);
|
|
|
|
XGrabKeyboard(glDisplay, glWindow, True, GrabModeAsync, GrabModeAsync, CurrentTime);
|
|
|
|
} else {
|
|
|
|
XUngrabPointer(glDisplay, CurrentTime);
|
|
|
|
XUngrabKeyboard(glDisplay, CurrentTime);
|
|
|
|
}
|
|
|
|
XUnlockDisplay(glDisplay);
|
|
|
|
#endif
|
|
|
|
}
|
2010-09-05 15:47:09 +00:00
|
|
|
|
|
|
|
void GLWindow::ToggleFullscreen()
|
2010-09-01 10:28:37 +00:00
|
|
|
{
|
2011-06-12 14:48:36 +00:00
|
|
|
#ifndef USE_GSOPEN2
|
2010-09-05 15:47:09 +00:00
|
|
|
if (!glDisplay or !glWindow) return;
|
|
|
|
|
2010-09-08 11:16:27 +00:00
|
|
|
Force43Ratio();
|
2010-09-06 22:21:07 +00:00
|
|
|
|
2010-09-05 15:47:09 +00:00
|
|
|
u32 mask = SubstructureRedirectMask | SubstructureNotifyMask;
|
|
|
|
// Setup a new event structure
|
|
|
|
XClientMessageEvent cme;
|
|
|
|
cme.type = ClientMessage;
|
|
|
|
cme.send_event = True;
|
|
|
|
cme.display = glDisplay;
|
|
|
|
cme.window = glWindow;
|
|
|
|
cme.message_type = XInternAtom(glDisplay, "_NET_WM_STATE", False);
|
|
|
|
cme.format = 32;
|
2010-09-08 11:16:27 +00:00
|
|
|
// Note: can not use _NET_WM_STATE_TOGGLE because the WM can change the fullscreen state
|
|
|
|
// and screw up the fullscreen variable... The test on fulscreen restore a sane configuration
|
|
|
|
cme.data.l[0] = fullScreen ? _NET_WM_STATE_REMOVE : _NET_WM_STATE_ADD;
|
2010-09-05 15:47:09 +00:00
|
|
|
cme.data.l[1] = (u32)XInternAtom(glDisplay, "_NET_WM_STATE_FULLSCREEN", False);
|
|
|
|
cme.data.l[2] = 0;
|
|
|
|
cme.data.l[3] = 0;
|
|
|
|
|
|
|
|
// send the event
|
2010-09-05 16:30:47 +00:00
|
|
|
XLockDisplay(glDisplay);
|
2010-09-05 15:47:09 +00:00
|
|
|
if (!XSendEvent(glDisplay, RootWindow(glDisplay, vi->screen), False, mask, (XEvent*)(&cme)))
|
|
|
|
ZZLog::Error_Log("Failed to send event: toggle fullscreen");
|
2010-09-05 22:08:55 +00:00
|
|
|
else {
|
2010-09-05 15:47:09 +00:00
|
|
|
fullScreen = (!fullScreen);
|
2010-09-05 22:08:55 +00:00
|
|
|
conf.setFullscreen(fullScreen);
|
|
|
|
}
|
2010-09-05 16:30:47 +00:00
|
|
|
XUnlockDisplay(glDisplay);
|
2010-09-05 15:47:09 +00:00
|
|
|
|
|
|
|
// Apply the change
|
2010-10-15 09:32:41 +00:00
|
|
|
XSync(glDisplay, false);
|
|
|
|
|
|
|
|
// Wait a little that the VM does his joes. Actually the best is to check some WM event
|
|
|
|
// but it not sure it will appear so a time out is necessary.
|
|
|
|
usleep(100*1000); // 100 us should be far enough for old computer and unnoticeable for users
|
2010-09-05 15:47:09 +00:00
|
|
|
|
|
|
|
// update info structure
|
|
|
|
GetWindowSize();
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
UpdateGrabKey();
|
2010-09-05 15:47:09 +00:00
|
|
|
|
2010-09-08 19:04:11 +00:00
|
|
|
// avoid black border in widescreen fullscreen
|
|
|
|
if (fullScreen && conf.isWideScreen) {
|
|
|
|
conf.width = width;
|
|
|
|
conf.height = height;
|
|
|
|
}
|
2010-09-08 11:16:27 +00:00
|
|
|
|
2010-09-05 15:47:09 +00:00
|
|
|
// Hide the cursor in the right bottom corner
|
|
|
|
if(fullScreen)
|
2010-10-15 09:32:41 +00:00
|
|
|
XWarpPointer(glDisplay, None, glWindow, 0, 0, 0, 0, 2*width, 2*height);
|
2010-09-05 15:47:09 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
#endif
|
2010-03-19 02:04:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLWindow::ResizeCheck()
|
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
XEvent event;
|
2010-09-06 22:21:07 +00:00
|
|
|
if (!glDisplay or !glWindow) return;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-09-06 22:21:07 +00:00
|
|
|
XLockDisplay(glDisplay);
|
|
|
|
while (XCheckTypedWindowEvent(glDisplay, glWindow, ConfigureNotify, &event))
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
|
|
|
if ((event.xconfigure.width != width) || (event.xconfigure.height != height))
|
|
|
|
{
|
|
|
|
width = event.xconfigure.width;
|
|
|
|
height = event.xconfigure.height;
|
2010-09-08 11:16:27 +00:00
|
|
|
Force43Ratio();
|
2010-11-14 01:38:10 +00:00
|
|
|
UpdateWindowSize(width, height);
|
2010-05-01 20:33:53 +00:00
|
|
|
}
|
|
|
|
|
2010-09-05 15:47:09 +00:00
|
|
|
if (!fullScreen) {
|
2010-09-06 09:46:33 +00:00
|
|
|
if ((event.xconfigure.x != conf.x) || (event.xconfigure.y != conf.y))
|
2010-09-05 15:47:09 +00:00
|
|
|
{
|
|
|
|
// Fixme; x&y occassionally gives values near the top left corner rather then the real values,
|
|
|
|
// causing the window to change positions when adjusting ZZOgl's settings.
|
2010-09-06 09:46:33 +00:00
|
|
|
conf.x = event.xconfigure.x;
|
|
|
|
conf.y = event.xconfigure.y;
|
2010-09-05 15:47:09 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
}
|
2010-09-06 22:21:07 +00:00
|
|
|
XUnlockDisplay(glDisplay);
|
2010-03-19 02:04:55 +00:00
|
|
|
}
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
void GLWindow::SetTitle(char *strtitle)
|
2010-11-09 12:04:07 +00:00
|
|
|
{
|
2011-06-12 14:48:36 +00:00
|
|
|
#ifndef USE_GSOPEN2
|
|
|
|
if (!glDisplay or !glWindow) return;
|
|
|
|
if (fullScreen) return;
|
2010-11-09 12:04:07 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
XTextProperty prop;
|
|
|
|
memset(&prop, 0, sizeof(prop));
|
2010-11-09 12:04:07 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
char* ptitle = strtitle;
|
|
|
|
if (XStringListToTextProperty(&ptitle, 1, &prop)) {
|
|
|
|
XLockDisplay(glDisplay);
|
|
|
|
XSetWMName(glDisplay, glWindow, &prop);
|
|
|
|
XUnlockDisplay(glDisplay);
|
|
|
|
}
|
2010-11-09 12:04:07 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
XFree(prop.value);
|
|
|
|
#endif
|
2010-11-09 12:04:07 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 02:04:55 +00:00
|
|
|
#endif
|