static X11Window activeWindow;
static X11Cursor systemCursors[SystemCursor];
+static Window acquiredInputWindow;
+static Point acquireStart;
+static Point lastMouse;
+static MouseButtons buttonsState;
+
+static bool keyStates[KeyCode];
+
static enum NETWMStateAction { remove = 0, add = 1, toggle = 2 };
static enum AtomIdents
_net_wm_window_type_menu, _net_wm_window_type_normal, _net_wm_window_type_popup_menu, _net_wm_window_type_splash,
_net_wm_window_type_toolbar, _net_wm_window_type_utility, _net_workarea, _net_frame_extents, _net_request_frame_extents,
_net_wm_state_maximized_vert, _net_wm_state_maximized_horz, _net_wm_state_modal, app_selection, _net_supported,
- _net_wm_state_skip_taskbar, _net_wm_state_fullscreen, _net_wm_state_above
+ _net_wm_state_skip_taskbar, _net_wm_state_fullscreen, _net_wm_state_above, capsLock, numLock, scrollLock
};
static Atom atoms[AtomIdents];
"_NET_SUPPORTED",
"_NET_WM_STATE_SKIP_TASKBAR",
"_NET_WM_STATE_FULLSCREEN",
- "_NET_WM_STATE_ABOVE"
+ "_NET_WM_STATE_ABOVE",
+ "Caps Lock",
+ "Num Lock",
+ "Scroll Lock",
};
/*
_NET_WM_STATE_STICKY, ATOM
guiApp.SetAppFocus(false);
SetNETWMState((X11Window)window.windowHandle, true, remove, atoms[_net_wm_state_fullscreen], 0);
XIconifyWindow(xGlobalDisplay, (X11Window)window.windowHandle, DefaultScreen(xGlobalDisplay));
+ if(acquiredInputWindow)
+ XInterface::SetMousePosition(guiApp.acquiredMouseX, guiApp.acquiredMouseY);
}
code.alt = true;
}
if(release == 1)
{
int numBytes;
+
+ if(code < KeyCode::enumSize) keyStates[code] = false;
if(windowData && windowData.ic) ch = buflength ? UTF8GetChar(buf, &numBytes) : 0;
if(ch == 127) ch = 0;
// printf("Release! %d %d %d\n", keysym, code, ch);
int c;
if(release == 0)
{
+ if(code < KeyCode::enumSize) keyStates[code] = true;
+
if(windowData.ic && buflength)
{
for(c = 0; c<buflength;)
return (!data || (event->window == (X11Window) data)) && event->type == ConfigureNotify;
}
+static X11Bool FocusInChecker(void *display, XFocusChangeEvent *event, char * data)
+{
+ X11Bool result = False;
+ if(event->type == FocusIn)
+ {
+ Window window = null;
+ XFindContext(xGlobalDisplay, event->window, windowContext, (XPointer *) &window);
+ if(window)
+ result = True;
+ }
+ return result;
+}
+
static enum FrameExtentSupport { unknown, working, broken };
static FrameExtentSupport frameExtentSupported;
return result;
}
-static bool WaitForFrameExtents(Window window)
+static bool WaitForFrameExtents(Window window, bool update)
{
int attempts = 0;
//XFlush(xGlobalDisplay);
- while(attempts++ < 10)
+ while(attempts++ < 40)
{
- if(GetFrameExtents(window, false)) return true;
+ if(GetFrameExtents(window, update)) return true;
Sleep(1.0 / RESOLUTION);
}
return false;
guiApp.desktop.Destroy(0);*/
}
+static void X11UpdateState(Window window, bool * unmaximized)
+{
+ if(atomsSupported[_net_wm_state]) //window.nativeDecorations)
+ {
+ int format;
+ unsigned long len, fill;
+ Atom type;
+ char * data = null;
+ if(XGetWindowProperty(xGlobalDisplay, (X11Window)window.systemHandle, atoms[_net_wm_state], 0, 32, False,
+ XA_ATOM, &type, &format, &len, &fill, &data) == Success)
+ {
+ bool maxVert = false, maxHorz = false, isMinimized = false;
+ Atom * hints = (Atom *)data;
+ int c;
+ for(c = 0; c < len && hints[c]; c++)
+ {
+ if(hints[c] == atoms[_net_wm_state_maximized_vert])
+ maxVert = true;
+ else if(hints[c] == atoms[_net_wm_state_maximized_horz])
+ maxHorz = true;
+ else if(hints[c] == atoms[_net_wm_state_hidden])
+ isMinimized = true;
+ }
+ XFree(data);
+
+ if(maxVert && maxHorz)
+ {
+ if(window.state != maximized)
+ {
+ *&window.state = maximized;
+ if(!window.nativeDecorations)
+ window.CreateSystemChildren();
+ }
+ }
+ else if(isMinimized)
+ {
+ if(window.state != minimized)
+ {
+ *&window.state = minimized;
+ if(!window.nativeDecorations)
+ window.CreateSystemChildren();
+ }
+ }
+ else if(window.state != normal)
+ {
+ if(unmaximized && window.state == maximized)
+ *unmaximized = true;
+ *&window.state = normal;
+ if(!window.nativeDecorations)
+ window.CreateSystemChildren();
+ }
+ }
+ }
+}
+
class XInterface : Interface
{
class_property(name) = "X";
bool Initialize()
{
setlocale(LC_ALL, "en_US.UTF-8");
- XInitThreads();
+ // XInitThreads();
XSupportsLocale();
XSetLocaleModifiers("");
XSetErrorHandler(MyXErrorHandler);
whichButton = 0;
buttonMask = Button1Mask;
keyFlags.left = true;
+ buttonsState.left = true;
}
else if(event->button == Button3)
{
whichButton = 2;
buttonMask = Button3Mask;
keyFlags.right = true;
+ buttonsState.right = true;
}
else
{
whichButton = 1;
buttonMask = Button2Mask;
keyFlags.middle = true;
+ buttonsState.middle = true;
}
if(event->state & buttonMask)
break;
{
button = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp;
buttonMask = Button1Mask;
+ buttonsState.left = false;
}
else if(event->button == Button3)
{
button = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp;
buttonMask = Button3Mask;
+ buttonsState.right = false;
}
else
{
button = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp;
buttonMask = Button2Mask;
+ buttonsState.middle = false;
}
timeStamp = event->time;
if(!(event->state & buttonMask)) break;
if(event->state & Button3Mask) keyFlags.right = true;
//*XUnlockDisplay(xGlobalDisplay);
incref window;
+ if(window == acquiredInputWindow)
+ {
+ lastMouse.x = event->x_root;
+ lastMouse.y = event->y_root;
+ }
window.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove,
event->x_root, event->y_root, &keyFlags, false, false);
delete window;
}
case FocusIn:
{
+ lastMouse = acquireStart;
+
guiApp.SetAppFocus(true);
+ X11UpdateState(window, null);
+
if(fullScreenMode)
{
+ if(acquiredInputWindow)
+ {
+ GetMousePosition(&guiApp.acquiredMouseX, &guiApp.acquiredMouseY);
+ lastMouse = { window.size.w/2, window.size.h/2 };
+ SetMousePosition(lastMouse.x, lastMouse.y);
+ }
XRaiseWindow(xGlobalDisplay, (X11Window)window.windowHandle);
SetNETWMState((X11Window)window.windowHandle, true, add, atoms[_net_wm_state_fullscreen], 0);
XGrabKeyboard(xGlobalDisplay, (X11Window)window.windowHandle, False, GrabModeAsync, GrabModeAsync, CurrentTime);
}
case FocusOut:
{
- if((X11Window)window.windowHandle == activeWindow)
- guiApp.SetAppFocus(false);
+#ifdef _DEBUG
+ //printf("Processing a FocusOut Event for %s (%x)\n", window._class.name, window);
+#endif
- if(fullScreenMode)
+ /*
+ if(XCheckTypedWindowEvent(xGlobalDisplay, thisEvent->window, FocusIn, (XEvent *)thisEvent))
{
- SetNETWMState((X11Window)window.windowHandle, true, remove, atoms[_net_wm_state_fullscreen], 0);
- XUngrabKeyboard(xGlobalDisplay, CurrentTime);
- // -- This XIconifyWindow causes trouble on Gnome Classic
- XIconifyWindow(xGlobalDisplay, (X11Window)window.windowHandle, DefaultScreen(xGlobalDisplay));
break;
}
+ */
-#ifdef _DEBUG
- //printf("Processing a FocusOut Event for %s (%x)\n", window._class.name, window);
-#endif
+ if(XCheckIfEvent(xGlobalDisplay, (XEvent *)thisEvent, (void *)FocusInChecker, null))
+ {
+ if(!fullScreenMode)
+ XPutBackEvent(xGlobalDisplay, (XEvent *)thisEvent);
+ break;
+ }
- if(XCheckTypedWindowEvent(xGlobalDisplay, thisEvent->window, FocusIn, (XEvent *)thisEvent))
+
+ if(fullScreenMode || (X11Window)window.windowHandle == activeWindow)
+ guiApp.SetAppFocus(false);
+
+ if(fullScreenMode)
{
+ //XUngrabKeyboard(xGlobalDisplay, CurrentTime);
+ //SetNETWMState((X11Window)window.windowHandle, true, remove, atoms[_net_wm_state_fullscreen], 0);
+ //XIconifyWindow(xGlobalDisplay, (X11Window)window.windowHandle, DefaultScreen(xGlobalDisplay));
break;
}
+
if(thisEvent->window == activeWindow)
activeWindow = (X11Window)null;
#if 0
while(XCheckIfEvent(xGlobalDisplay, (XEvent *)thisEvent, (void *)ConfigureNotifyChecker, (void *)window.windowHandle));
//if(event->x - desktopX != window.position.x || event->y - desktopY != window.position.y || event->width != window.size.w || event->height != window.size.h)
- if(atomsSupported[_net_wm_state]) //window.nativeDecorations)
- {
- int format;
- unsigned long len, fill;
- Atom type;
- char * data = null;
- if(XGetWindowProperty(xGlobalDisplay, (X11Window)window.systemHandle, atoms[_net_wm_state], 0, 32, False,
- XA_ATOM, &type, &format, &len, &fill, &data) == Success)
- {
- bool maxVert = false, maxHorz = false, isMinimized = false;
- Atom * hints = (Atom *)data;
- int c;
- for(c = 0; c < len && hints[c]; c++)
- {
- if(hints[c] == atoms[_net_wm_state_maximized_vert])
- maxVert = true;
- else if(hints[c] == atoms[_net_wm_state_maximized_horz])
- maxHorz = true;
- else if(hints[c] == atoms[_net_wm_state_hidden])
- isMinimized = true;
- }
- XFree(data);
-
- if(maxVert && maxHorz)
- {
- if(window.state != maximized)
- {
- *&window.state = maximized;
- if(!window.nativeDecorations)
- window.CreateSystemChildren();
- }
- }
- else if(isMinimized)
- {
- if(window.state != minimized)
- {
- *&window.state = minimized;
- if(!window.nativeDecorations)
- window.CreateSystemChildren();
- }
- }
- else if(window.state != normal)
- {
- if(window.state == maximized)
- unmaximized = true;
- *&window.state = normal;
- if(!window.nativeDecorations)
- window.CreateSystemChildren();
- }
- }
- }
+ X11UpdateState(window, &unmaximized);
{
bool offset = false;
int x, y, w, h;
if(unmaximized && window.nativeDecorations)
{
if(window.nativeDecorations && RequestFrameExtents((X11Window)window.windowHandle))
- WaitForFrameExtents(window);
+ WaitForFrameExtents(window, false);
// Ensure we set the normal size anchor when un-maximizing
window.ComputeAnchors(window.normalAnchor, window.normalSizeAnchor, &x, &y, &w, &h);
y -= windowData.decor.top;
w += windowData.decor.left + windowData.decor.right;
h += windowData.decor.top + windowData.decor.bottom;
-
- /*
- x -= window.clientStart.x;
- y -= window.clientStart.y - (window.hasMenuBar ? skinMenuHeight : 0);
- w += window.size.w - window.clientSize.w;
- h += window.size.h - window.clientSize.h;
- */
}
}
- window.Position(x, y, w, h, true, true, true, true, false, unmaximized);
+ window.Position(x, y, w, h, false /*true*/, true, true, true, false, unmaximized);
// Break the anchors for moveable/resizable windows
// Avoid doing this if the translation wasn't in sync as it will cause the window to move around
}
}
+ lastMouse = acquireStart;
modalRoot = window.FindModal();
windowData = modalRoot ? modalRoot.windowData : window.windowData;
if(windowData)
XUngrabPointer(xGlobalDisplay, CurrentTime);
}
- if(!fullScreenMode && !window.nativeDecorations || !RequestFrameExtents(windowHandle))
+ if(fullScreenMode || !window.nativeDecorations || !RequestFrameExtents(windowHandle))
((XWindowData)window.windowData).gotFrameExtents = true;
+
+ window.windowHandle = (void *)windowHandle;
+ if(window.state != maximized)
+ WaitForFrameExtents(window, true);
+
+ //GetFrameExtents(window, true);
+
if(fullScreenMode)
{
XMapWindow(xGlobalDisplay, windowHandle);
void DestroyRootWindow(Window window)
{
XEvent event;
+ if(window == acquiredInputWindow)
+ delete acquiredInputWindow;
XDeleteContext(xGlobalDisplay, (XID)window, windowContext);
XSaveContext(xGlobalDisplay, (X11Window)window.windowHandle, windowContext, null);
// && window.state != maximized -- required for Cinnamon on Mint 14/15
if(!windowData.gotFrameExtents && window.state != maximized)
{
- if(WaitForFrameExtents(window))
+ if(WaitForFrameExtents(window, false))
{
x += windowData.decor.left;
y += windowData.decor.top ;
void SetMousePosition(int x, int y)
{
-
+ XWarpPointer(xGlobalDisplay, None, DefaultRootWindow(xGlobalDisplay), 0, 0, 0, 0, x, y);
+ XFlush(xGlobalDisplay);
}
void SetMouseRange(Window window, Box box)
{
if(window.rootWindow.windowHandle)
XDefineCursor(xGlobalDisplay, (X11Window) window.rootWindow.windowHandle,
- cursor == -1 ? nullCursor : systemCursors[(SystemCursor)cursor]);
+ (acquiredInputWindow || cursor == -1) ? nullCursor : systemCursors[(SystemCursor)cursor]);
}
// --- Caret ---
bool AcquireInput(Window window, bool state)
{
- return false;
+ if(state && window)
+ {
+ GetMousePosition(&acquireStart.x, &acquireStart.y);
+ lastMouse = acquireStart;
+ acquiredInputWindow = window;
+ incref acquiredInputWindow;
+ }
+ else if(acquiredInputWindow)
+ delete acquiredInputWindow;
+ return true;
}
bool GetMouseState(MouseButtons * buttons, int * x, int * y)
{
bool result = false;
- if(x) *x = 0;
- if(y) *y = 0;
+ if(acquiredInputWindow && guiApp.desktop.active)
+ {
+ if(x) *x = lastMouse.x - acquireStart.x;
+ if(y) *y = lastMouse.y - acquireStart.y;
+ *buttons = buttonsState;
+ SetMousePosition(acquireStart.x, acquireStart.y);
+ lastMouse = acquireStart;
+ result = true;
+ }
+ else
+ {
+ if(x) *x = 0;
+ if(y) *y = 0;
+ if(buttons) *buttons = 0;
+ }
return result;
}
bool GetKeyState(Key key)
{
- int keyState = 0;
- return keyState;
+ if(key == capsState || key == numState || key == scrollState)
+ {
+ Atom atom = None;
+ X11Bool state = 0;
+ int idx = 0;
+ switch(key)
+ {
+ case capsState: atom = atoms[capsLock]; idx = 0; break;
+ case numState: atom = atoms[numLock]; idx = 1; break;
+ case scrollState: atom = atoms[scrollLock]; idx = 2; break;
+ }
+ /*XkbGetIndicatorState(xGlobalDisplay, XkbUseCoreKbd, &state);
+ state = (state & (1 << idx)) ? 1 : 0;*/
+ XkbGetNamedIndicator(xGlobalDisplay, /*XkbUseCoreKbd,*/ atom, &idx, &state, NULL, NULL);
+ return (bool)state;
+ }
+ else
+ return keyStates[key.code];
}
void SetTimerResolution(uint hertz)