ecere/gui/drivers/XInterface: Fixed re-clicking DropBox to hide pulldown
[sdk] / ecere / src / gui / drivers / XInterface.ec
index 7dda68d..1820ad3 100644 (file)
@@ -100,6 +100,13 @@ static int joystickFD[4];
 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
@@ -112,7 +119,7 @@ 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_skip_taskbar, _net_wm_state_fullscreen, _net_wm_state_above, capsLock, numLock, scrollLock
 };
 
 static Atom atoms[AtomIdents];
@@ -160,19 +167,18 @@ static const char *atomNames[AtomIdents] = {
    "_NET_WM_STATE_MODAL", // _net_wm_state_modal
    "APP_SELECTION",
    "_NET_SUPPORTED",
-   "_NET_WM_STATE_SKIP_TASKBAR"
+   "_NET_WM_STATE_SKIP_TASKBAR",
+   "_NET_WM_STATE_FULLSCREEN",
+   "_NET_WM_STATE_ABOVE",
+   "Caps Lock",
+   "Num Lock",
+   "Scroll Lock",
 };
 /*
 _NET_WM_STATE_STICKY, ATOM
-_NET_WM_STATE_MAXIMIZED_VERT, ATOM
-_NET_WM_STATE_MAXIMIZED_HORZ, ATOM
 _NET_WM_STATE_SHADED, ATOM
 _NET_WM_STATE_SKIP_PAGER, ATOM
-_NET_WM_STATE_HIDDEN, ATOM
-_NET_WM_STATE_FULLSCREEN, ATOM
-_NET_WM_STATE_ABOVE, ATOM
 _NET_WM_STATE_BELOW, ATOM
-_NET_WM_STATE_DEMANDS_ATTENTION, ATOM
 */
 
 static bool autoRepeatDetectable;
@@ -404,11 +410,39 @@ static void RepositionDesktop(bool updateChildren)
 
    if(desktopX != x || desktopY != y || desktopW != w || desktopH != h)
    {
-      guiApp.SetDesktopPosition(x, y, w, h, updateChildren);
-      desktopX = x;
-      desktopY = y;
-      desktopW = w;
-      desktopH = h;
+      bool skip = false;
+      // Don't change the desktop area if another fullscreen application is running
+      // (Attemps to solve the debugging IDE being re-activated while switching debugged app between fullscreen/windowed on Cinnamon)
+      if(XGetWindowProperty(xGlobalDisplay, x_root, atoms[_net_active_window], 0, 32,
+                            False, AnyPropertyType, &type, &format, &len,
+                            &fill, &data) == Success && data)
+      {
+         X11Window active = *(long *)data;
+         XFree(data);
+         if(XGetWindowProperty(xGlobalDisplay, active, atoms[_net_wm_state], 0, 32, False,
+             XA_ATOM, &type, &format, &len, &fill, &data) == Success)
+         {
+            Atom * values = (Atom *) data;
+            int i;
+            for (i = 0; i < len; i++)
+            {
+               if(values[i] == atoms[_net_wm_state_fullscreen])
+               {
+                  skip = true;
+                  break;
+               }
+            }
+            XFree(data);
+         }
+      }
+      if(w && h && !skip)
+      {
+         guiApp.SetDesktopPosition(x, y, w, h, updateChildren);
+         desktopX = x;
+         desktopY = y;
+         desktopW = w;
+         desktopH = h;
+      }
    }
 }
 
@@ -786,7 +820,18 @@ static bool ProcessKeyMessage(Window window, uint keyCode, int release, XKeyEven
    if(key != leftControl && key != rightControl && event->state & ControlMask)
       code.ctrl = true;
    if(key != leftAlt && key != rightAlt && event->state & Mod1Mask)
+   {
+      if(fullScreenMode && key == tab)
+      {
+         XUngrabKeyboard(xGlobalDisplay, CurrentTime);
+         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;
+   }
 
 #ifdef __APPLE__
    if(key != leftAlt && key != rightAlt && event->state & (1<<13))
@@ -803,6 +848,8 @@ static bool ProcessKeyMessage(Window window, uint keyCode, int release, XKeyEven
    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);
@@ -813,6 +860,8 @@ static bool ProcessKeyMessage(Window window, uint keyCode, int release, XKeyEven
       int c;
       if(release == 0)
       {
+         if(code < KeyCode::enumSize) keyStates[code] = true;
+
          if(windowData.ic && buflength)
          {
             for(c = 0; c<buflength;)
@@ -879,6 +928,19 @@ static X11Bool ConfigureNotifyChecker(void *display, XConfigureEvent *event, cha
    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;
@@ -1123,13 +1185,13 @@ static bool GetFrameExtents(Window window, bool update)
    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;
@@ -1229,6 +1291,61 @@ static void SigIntHandler(int value)
       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";
@@ -1237,7 +1354,7 @@ class XInterface : Interface
    bool Initialize()
    {
       setlocale(LC_ALL, "en_US.UTF-8");
-      XInitThreads();
+      // XInitThreads();
       XSupportsLocale();
       XSetLocaleModifiers("");
       XSetErrorHandler(MyXErrorHandler);
@@ -1615,14 +1732,18 @@ class XInterface : Interface
                   if(event->button == Button1)
                   {
                      // Force a raise on click here to deal with confused active state preventing to bring the window up
-                     if(!atomsSupported[_net_active_window] && !window.isRemote)
-                        XRaiseWindow(xGlobalDisplay, (X11Window)window.windowHandle);
-                     XSetInputFocus(xGlobalDisplay, (X11Window)window.windowHandle, RevertToParent, CurrentTime);
+                     if(!fullScreenMode)
+                     {
+                        if(!atomsSupported[_net_active_window] && !window.isRemote)
+                           XRaiseWindow(xGlobalDisplay, (X11Window)window.windowHandle);
+                        XSetInputFocus(xGlobalDisplay, (X11Window)window.windowHandle, RevertToParent, CurrentTime);
+                     }
                      button = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown;
                      buttonDouble = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick;
                      whichButton = 0;
                      buttonMask = Button1Mask;
                      keyFlags.left = true;
+                     buttonsState.left = true;
                   }
                   else if(event->button == Button3)
                   {
@@ -1631,6 +1752,7 @@ class XInterface : Interface
                      whichButton = 2;
                      buttonMask = Button3Mask;
                      keyFlags.right = true;
+                     buttonsState.right = true;
                   }
                   else
                   {
@@ -1639,6 +1761,7 @@ class XInterface : Interface
                      whichButton = 1;
                      buttonMask = Button2Mask;
                      keyFlags.middle = true;
+                     buttonsState.middle = true;
                   }
                   if(event->state & buttonMask)
                      break;
@@ -1693,16 +1816,19 @@ class XInterface : Interface
                   {
                      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;
@@ -1747,6 +1873,11 @@ class XInterface : Interface
                      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;
@@ -1808,8 +1939,28 @@ class XInterface : Interface
                }
                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);
+                        (xGlobalDisplay, (X11Window)window.windowHandle, RevertToParent, timeStamp);
+                     XInterface::UpdateRootWindow(window);
+                     break;
+                  }
+
                   if(activeWindow != (X11Window)window.windowHandle)
                   {
                      XFocusChangeEvent *event = (XFocusChangeEvent *) thisEvent;
@@ -1842,17 +1993,36 @@ class XInterface : Interface
                }
                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(XCheckTypedWindowEvent(xGlobalDisplay, thisEvent->window, FocusIn, (XEvent *)thisEvent))
                   {
                      break;
                   }
+                  */
+
+                  if(XCheckIfEvent(xGlobalDisplay, (XEvent *)thisEvent, (void *)FocusInChecker, null))
+                  {
+                     if(!fullScreenMode)
+                        XPutBackEvent(xGlobalDisplay, (XEvent *)thisEvent);
+                     break;
+                  }
+
+
+                  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
@@ -1924,7 +2094,7 @@ class XInterface : Interface
 #endif
                   {
                      XFocusChangeEvent *event = (XFocusChangeEvent *) thisEvent;
-                     if(window != window.parent.activeChild && window != guiApp.interimWindow) break;
+                     if(window.parent && window != window.parent.activeChild && window != guiApp.interimWindow) break;
                      incref window;
 
 #ifdef _DEBUG
@@ -1949,68 +2119,18 @@ class XInterface : Interface
                {
                   XConfigureEvent * event = (XConfigureEvent *) thisEvent;
                   bool unmaximized = false;
-                  if(!window.visible) break;
+                  if(!window.visible || fullScreenMode) break;
                   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);
@@ -2047,13 +2167,6 @@ class XInterface : Interface
                            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;
-                           */
                         }
                      }
 
@@ -2088,6 +2201,16 @@ class XInterface : Interface
                      Window modalRoot;
                      XWindowData windowData;
                      bool laterFocus;
+
+                     if(fullScreenMode)
+                     {
+                        XRaiseWindow(xGlobalDisplay, (X11Window)window.windowHandle);
+                        XSetInputFocus(xGlobalDisplay, (X11Window)window.windowHandle, RevertToParent, timeStamp);
+                        XGrabKeyboard(xGlobalDisplay, (X11Window)window.windowHandle, False,  GrabModeAsync, GrabModeAsync, CurrentTime);
+                        guiApp.SetAppFocus(true);
+                        break;
+                     }
+
                      //activeWindow = (X11Window)window.windowHandle;
 
                      timeStamp = (X11Time)event->data.l[1];
@@ -2111,7 +2234,7 @@ class XInterface : Interface
                            XFocusChangeEvent *event = (XFocusChangeEvent *) &checkEvent;
                            Window window;
                            XFindContext(xGlobalDisplay, event->window, windowContext, (XPointer *) &window);
-                           if(window != window.parent.activeChild) break;
+                           if(window.parent && window != window.parent.activeChild) break;
                            incref window;
 
       #ifdef _DEBUG
@@ -2127,6 +2250,7 @@ class XInterface : Interface
                         }
                      }
 
+                     lastMouse = acquireStart;
                      modalRoot = window.FindModal();
                      windowData = modalRoot ? modalRoot.windowData : window.windowData;
                      if(windowData)
@@ -2192,7 +2316,7 @@ class XInterface : Interface
                {
                   XWindowData windowData = window.windowData;
                   XPropertyEvent * event = (XPropertyEvent *) thisEvent;
-                  if(event->atom == atoms[_net_frame_extents] &&
+                  if(!fullScreenMode && event->atom == atoms[_net_frame_extents] &&
                     event->state == PropertyNewValue && windowData)
                   {
                      if(!GetFrameExtents(window, true))
@@ -2399,9 +2523,39 @@ class XInterface : Interface
 
       if(fullScreenMode)
       {
-         windowHandle = XCreateWindow(xGlobalDisplay, DefaultRootWindow(xGlobalDisplay),
-            0,0,guiApp.desktop.size.w,guiApp.desktop.size.h,0, depth, InputOutput, visual ? visual : CopyFromParent,
-            CWEventMask | (visual ? (CWColormap | CWBorderPixel) : 0)/*| CWOverrideRedirect*/, &attributes);
+         windowHandle = XCreateWindow(xGlobalDisplay,
+               DefaultRootWindow(xGlobalDisplay),
+               0,0,
+               XDisplayWidth(xGlobalDisplay, DefaultScreen(xGlobalDisplay)),
+               XDisplayHeight(xGlobalDisplay, DefaultScreen(xGlobalDisplay)),
+               0, depth, InputOutput, visual ? visual : CopyFromParent,
+               CWEventMask | (visual ? (CWColormap | CWBorderPixel) : 0) | CWOverrideRedirect,
+               &attributes);
+
+         {
+            XSizeHints hints = { 0 };
+            XSetWMNormalHints(xGlobalDisplay, windowHandle, &hints);
+         }
+
+         {
+            String caption = window.caption;
+            XChangeProperty(xGlobalDisplay, windowHandle, atoms[_net_wm_name],
+               atoms[utf8_string], 8, PropModeReplace, (byte *)window.caption, caption ? strlen(caption) : 0);
+            XChangeProperty(xGlobalDisplay, windowHandle, atoms[wm_name],
+               atoms[utf8_string], 8, PropModeReplace, (byte *)window.caption, caption ? strlen(caption) : 0);
+         }
+
+         SetNETWMState((X11Window)windowHandle, false, add, atoms[_net_wm_state_fullscreen], 0);
+         //SetNETWMState((X11Window)windowHandle, false, add, atoms[_net_wm_state_above], 0);
+         {
+            Atom hints[4];
+            int count;
+
+            hints[0] = atoms[_net_wm_window_type_normal];
+            count = 1;
+            XChangeProperty(xGlobalDisplay, windowHandle, atoms[_net_wm_window_type], XA_ATOM, 32,
+               PropModeReplace, (unsigned char*)&hints, count);
+         }
 
          {
             XWMHints xwmHints;
@@ -2600,10 +2754,10 @@ class XInterface : Interface
             {
                (window.nativeDecorations ? 0 : MWM_HINTS_DECORATIONS)|MWM_HINTS_FUNCTIONS,
                (window.hasClose ? MWM_FUNC_CLOSE : 0) |
-               (window.hasMaximize ? MWM_FUNC_MAXIMIZE : 0) |
-               (window.hasMinimize ? MWM_FUNC_MINIMIZE : 0) |
-               ((window.moveable || ((BorderBits)window.borderStyle).fixed) ? MWM_FUNC_MOVE : 0) |
-               (((BorderBits)window.borderStyle).sizable ? MWM_FUNC_RESIZE : 0),
+               (fullScreenMode || window.hasMaximize ? MWM_FUNC_MAXIMIZE : 0) |
+               (fullScreenMode || window.hasMinimize ? MWM_FUNC_MINIMIZE : 0) |
+               ((fullScreenMode || window.moveable || ((BorderBits)window.borderStyle).fixed) ? MWM_FUNC_MOVE : 0) |
+               (fullScreenMode || ((BorderBits)window.borderStyle).sizable ? MWM_FUNC_RESIZE : 0),
                 0, 0, 0
             };
             XChangeProperty(xGlobalDisplay, windowHandle, atoms[_motif_wm_hints], atoms[_motif_wm_hints], 32,
@@ -2640,15 +2794,28 @@ class XInterface : Interface
          XUngrabPointer(xGlobalDisplay, CurrentTime);
       }
 
-      if(!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);
+         XGrabKeyboard(xGlobalDisplay, windowHandle, False,  GrabModeAsync, GrabModeAsync, CurrentTime);
+      }
       return (void *)windowHandle;
    }
 
    void DestroyRootWindow(Window window)
    {
       XEvent event;
+      if(window == acquiredInputWindow)
+         delete acquiredInputWindow;
 
       XDeleteContext(xGlobalDisplay, (XID)window, windowContext);
       XSaveContext(xGlobalDisplay, (X11Window)window.windowHandle, windowContext, null);
@@ -2702,7 +2869,7 @@ class XInterface : Interface
                // && 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 ;
@@ -2729,7 +2896,7 @@ class XInterface : Interface
          x += desktopX;
          y += desktopY;
 
-         if(!atomsSupported[_net_wm_state] || window.state != maximized)
+         if(!fullScreenMode && (!atomsSupported[_net_wm_state] || window.state != maximized))
          {
             if(move && resize)
                XMoveResizeWindow(xGlobalDisplay, (X11Window)window.windowHandle, x, y, w, h);
@@ -2810,6 +2977,17 @@ class XInterface : Interface
                   ActivateRootWindow(window);
             }
 
+            if(fullScreenMode && state != minimized)
+            {
+               int w = XDisplayWidth(xGlobalDisplay, DefaultScreen(xGlobalDisplay));
+               int h = XDisplayHeight(xGlobalDisplay, DefaultScreen(xGlobalDisplay));
+               SetNETWMState((X11Window)window.windowHandle, true, add, atoms[_net_wm_state_fullscreen], 0);
+               XMoveResizeWindow(xGlobalDisplay, (X11Window)window.windowHandle, 0, 0, w, h);
+
+               guiApp.SetDesktopPosition(0, 0, w, h, true);
+               window.Position(0, 0, w, h, true, true, true, true, false, false);
+            }
+
             if(state == minimized && atomsSupported[_net_wm_state])
             {
                uint iconic = IconicState;
@@ -2833,9 +3011,10 @@ class XInterface : Interface
                */
 
                // printf("Attempting to minimize %s\n", window._class.name);
-               XIconifyWindow(xGlobalDisplay, (X11Window)window.windowHandle, DefaultScreen(xGlobalDisplay));
+               if(!fullScreenMode)
+                  XIconifyWindow(xGlobalDisplay, (X11Window)window.windowHandle, DefaultScreen(xGlobalDisplay));
             }
-            else
+            else if(!fullScreenMode)
             {
                //((XWindowData)window.windowData).gotFrameExtents && (!window.nativeDecorations || window.state == state))
                if(!atomsSupported[_net_wm_state] || (!((XWindowData)window.windowData).gotFrameExtents && window.state == maximized))
@@ -2869,7 +3048,7 @@ class XInterface : Interface
                if(atomsSupported[_net_wm_state])
                {
                   // Maximize / Restore the window
-                  SetNETWMState((X11Window)window.windowHandle, true, state == maximized ? add: remove,
+                  SetNETWMState((X11Window)window.windowHandle, true, state == maximized ? add : remove,
                      atoms[_net_wm_state_maximized_vert], atoms[_net_wm_state_maximized_horz]);
                   if(state == maximized)
                   {
@@ -2969,7 +3148,8 @@ class XInterface : Interface
 
    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)
@@ -3047,7 +3227,7 @@ class XInterface : Interface
    {
       if(window.rootWindow.windowHandle)
          XDefineCursor(xGlobalDisplay, (X11Window) window.rootWindow.windowHandle,
-            cursor == -1 ? nullCursor : systemCursors[(SystemCursor)cursor]);
+            (acquiredInputWindow || cursor == -1) ? nullCursor : systemCursors[(SystemCursor)cursor]);
    }
 
    // --- Caret ---
@@ -3196,14 +3376,36 @@ class XInterface : Interface
 
    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;
    }
 
@@ -3229,8 +3431,24 @@ class XInterface : Interface
 
    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)