From 5d1ab45526eaf896be2822df966eb267e0e3b004 Mon Sep 17 00:00:00 2001 From: Jerome St-Louis Date: Sat, 8 Feb 2014 16:28:04 +0700 Subject: [PATCH] ecere/src/gui/XInterface: (#678) System cursors support on X --- ecere/src/gui/GuiApplication.ec | 6 ++--- ecere/src/gui/Interface.ec | 2 +- ecere/src/gui/Window.ec | 35 +++++++++++++------------- ecere/src/gui/drivers/AndroidInterface.ec | 2 +- ecere/src/gui/drivers/NCursesInterface.ec | 2 +- ecere/src/gui/drivers/Win32ConsoleInterface.ec | 2 +- ecere/src/gui/drivers/Win32Interface.ec | 2 +- ecere/src/gui/drivers/XInterface.ec | 32 +++++++++++++++++------ ecere/src/gui/drivers/cocoa/CocoaInterface.ec | 2 +- 9 files changed, 52 insertions(+), 33 deletions(-) diff --git a/ecere/src/gui/GuiApplication.ec b/ecere/src/gui/GuiApplication.ec index 0189419..8ebc5e8 100644 --- a/ecere/src/gui/GuiApplication.ec +++ b/ecere/src/gui/GuiApplication.ec @@ -303,16 +303,16 @@ public class GuiApplication : Application } // --- Mouse-based window movement --- - void SetCurrentCursor(Cursor cursor) + void SetCurrentCursor(Window window, Cursor cursor) { currentCursor = cursor; if(cursor) { if(fullScreenMode && cursor.bitmap) - interfaceDriver.SetMouseCursor((SystemCursor)-1); + interfaceDriver.SetMouseCursor(window ? window : desktop, (SystemCursor)-1); else { - interfaceDriver.SetMouseCursor(cursor.systemCursor); + interfaceDriver.SetMouseCursor(window ? window : desktop, cursor.systemCursor); cursorBackground.Free(); } } diff --git a/ecere/src/gui/Interface.ec b/ecere/src/gui/Interface.ec index 072c489..f662f97 100644 --- a/ecere/src/gui/Interface.ec +++ b/ecere/src/gui/Interface.ec @@ -87,7 +87,7 @@ public: virtual void ::SetMouseCapture(Window window); // --- Mouse cursor --- - virtual void ::SetMouseCursor(SystemCursor cursor); + virtual void ::SetMouseCursor(Window window, SystemCursor cursor); // --- Caret manipulation --- virtual void ::SetCaret(int caretX, int caretY, int size); diff --git a/ecere/src/gui/Window.ec b/ecere/src/gui/Window.ec index d34d8c7..336b21f 100644 --- a/ecere/src/gui/Window.ec +++ b/ecere/src/gui/Window.ec @@ -2233,7 +2233,7 @@ private: Window GetParentMenuBar() { Window menuBarParent; - for(menuBarParent = this; menuBarParent; menuBarParent = menuBarParent.parent) + for(menuBarParent = this ? parent : null; menuBarParent; menuBarParent = menuBarParent.parent) { if(menuBarParent.menuBar) return menuBarParent.menuBar; if(menuBarParent && !menuBarParent.isActiveClient) @@ -3357,7 +3357,7 @@ private: mouseWindow = rootWindow ? rootWindow.GetAtPosition(x,y, true, false, null) : null; if((guiApp.windowMoving && !guiApp.windowIsResizing) || guiApp.windowScrolling) - guiApp.SetCurrentCursor(guiApp.systemCursors[moving]); + guiApp.SetCurrentCursor(guiApp.windowMoving, guiApp.systemCursors[moving]); else if(mouseWindow) { modalWindow = mouseWindow.FindModal(); @@ -3370,30 +3370,31 @@ private: rx = guiApp.resizeX; ry = guiApp.resizeY; if((rex && rey) || (rx && ry)) - guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]); + guiApp.SetCurrentCursor(guiApp.windowMoving, guiApp.systemCursors[sizeNWSE]); else if((rex && ry) || (rx && rey)) - guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]); + guiApp.SetCurrentCursor(guiApp.windowMoving, guiApp.systemCursors[sizeNESW]); else if((ry || rey) && (!rx && !rex)) - guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]); + guiApp.SetCurrentCursor(guiApp.windowMoving, guiApp.systemCursors[sizeNS]); else if((rx || rex) && (!ry && !rey)) - guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]); + guiApp.SetCurrentCursor(guiApp.windowMoving, guiApp.systemCursors[sizeWE]); } else if(!modalWindow && !guiApp.windowCaptured && mouseWindow.IsMouseResizing(x, y, mouseWindow.size.w, mouseWindow.size.h, &rx, &ry, &rex, &rey)) { if((rex && rey) || (rx && ry)) - guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]); + guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNWSE]); else if((rex && ry) || (rx && rey)) - guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]); + guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNESW]); else if((ry || rey) && (!rx && !rex)) - guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]); + guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNS]); else if((rx || rex) && (!ry && !rey)) - guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]); + guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeWE]); } else if(!guiApp.windowCaptured && !modalWindow && !guiApp.interimWindow) { - if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y})) + if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y}) && + mouseWindow.rootWindow != mouseWindow) cursorWindow = mouseWindow.parent; else cursorWindow = mouseWindow; @@ -3402,19 +3403,19 @@ private: cursorWindow = guiApp.windowCaptured; if(cursorWindow) { - for(; !cursorWindow.cursor && !cursorWindow.style.nonClient; cursorWindow = cursorWindow.parent); - guiApp.SetCurrentCursor(cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]); + for(; !cursorWindow.cursor && !cursorWindow.style.nonClient && cursorWindow.rootWindow != cursorWindow; cursorWindow = cursorWindow.parent); + guiApp.SetCurrentCursor(cursorWindow, cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]); } else if(modalWindow) { - guiApp.SetCurrentCursor(guiApp.systemCursors[arrow]); + guiApp.SetCurrentCursor(null, guiApp.systemCursors[arrow]); } else if(guiApp.interimWindow) { if(guiApp.interimWindow.cursor) - guiApp.SetCurrentCursor(guiApp.interimWindow.cursor); + guiApp.SetCurrentCursor(guiApp.interimWindow, guiApp.interimWindow.cursor); else - guiApp.SetCurrentCursor(mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]); + guiApp.SetCurrentCursor(mouseWindow, mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]); } } } @@ -3434,7 +3435,7 @@ private: if(state && result) { SetMouseRangeToClient(); - guiApp.interfaceDriver.SetMouseCursor((SystemCursor)-1); + guiApp.interfaceDriver.SetMouseCursor(guiApp.acquiredWindow, (SystemCursor)-1); } else { diff --git a/ecere/src/gui/drivers/AndroidInterface.ec b/ecere/src/gui/drivers/AndroidInterface.ec index 3e400fa..29156e9 100644 --- a/ecere/src/gui/drivers/AndroidInterface.ec +++ b/ecere/src/gui/drivers/AndroidInterface.ec @@ -779,7 +779,7 @@ class AndroidInterface : Interface // -- Mouse cursor --- - void SetMouseCursor(int cursor) + void SetMouseCursor(Window window, int cursor) { if(cursor == -1) { diff --git a/ecere/src/gui/drivers/NCursesInterface.ec b/ecere/src/gui/drivers/NCursesInterface.ec index e78f6f4..08a12c1 100644 --- a/ecere/src/gui/drivers/NCursesInterface.ec +++ b/ecere/src/gui/drivers/NCursesInterface.ec @@ -580,7 +580,7 @@ class NCursesInterface : Interface // -- Mouse cursor --- - void SetMouseCursor(int cursor) + void SetMouseCursor(Window window, int cursor) { } diff --git a/ecere/src/gui/drivers/Win32ConsoleInterface.ec b/ecere/src/gui/drivers/Win32ConsoleInterface.ec index c2caa74..74a6c11 100644 --- a/ecere/src/gui/drivers/Win32ConsoleInterface.ec +++ b/ecere/src/gui/drivers/Win32ConsoleInterface.ec @@ -410,7 +410,7 @@ class Win32ConsoleInterface : Interface // -- Mouse cursor --- - void SetMouseCursor(int cursor) + void SetMouseCursor(Window window, int cursor) { } diff --git a/ecere/src/gui/drivers/Win32Interface.ec b/ecere/src/gui/drivers/Win32Interface.ec index c2e7821..1296f34 100644 --- a/ecere/src/gui/drivers/Win32Interface.ec +++ b/ecere/src/gui/drivers/Win32Interface.ec @@ -1625,7 +1625,7 @@ class Win32Interface : Interface // -- Mouse cursor --- - void SetMouseCursor(SystemCursor cursor) + void SetMouseCursor(Window window, SystemCursor cursor) { if(lastCursor != cursor) { diff --git a/ecere/src/gui/drivers/XInterface.ec b/ecere/src/gui/drivers/XInterface.ec index be5f0c6..252b984 100644 --- a/ecere/src/gui/drivers/XInterface.ec +++ b/ecere/src/gui/drivers/XInterface.ec @@ -40,6 +40,7 @@ default: #include #include #include +#include #include #if !defined(ECERE_NO3D) && !defined(ECERE_NOGL) #include @@ -92,6 +93,7 @@ static bool gotAnXEvent = false; static XEvent xEvent; static int joystickFD[4]; static X11Window activeWindow; +static X11Cursor systemCursors[SystemCursor]; static enum AtomIdents { @@ -1069,6 +1071,16 @@ class XInterface : Interface joystickFD[2] = open("/dev/js2", O_RDONLY); joystickFD[3] = open("/dev/js3", O_RDONLY); + systemCursors[iBeam] = XCreateFontCursor(xGlobalDisplay, XC_xterm); + systemCursors[cross] = XCreateFontCursor(xGlobalDisplay, XC_tcross); + systemCursors[moving] = XCreateFontCursor(xGlobalDisplay, XC_fleur); + systemCursors[sizeNESW] = XCreateFontCursor(xGlobalDisplay, XC_bottom_left_corner); + systemCursors[sizeNS] = XCreateFontCursor(xGlobalDisplay, XC_sb_v_double_arrow); + systemCursors[sizeNWSE] = XCreateFontCursor(xGlobalDisplay, XC_bottom_right_corner); + systemCursors[sizeWE] = XCreateFontCursor(xGlobalDisplay, XC_sb_h_double_arrow); + systemCursors[hand] = XCreateFontCursor(xGlobalDisplay, XC_hand2); + systemCursors[arrow] = XCreateFontCursor(xGlobalDisplay, XC_left_ptr); + if(xGlobalDisplay) { XWindowAttributes attributes = { 0 }; @@ -1253,6 +1265,16 @@ class XInterface : Interface delete timerThread; hiResTimer.Stop(); + XFreeCursor(xGlobalDisplay, systemCursors[iBeam]); + XFreeCursor(xGlobalDisplay, systemCursors[cross]); + XFreeCursor(xGlobalDisplay, systemCursors[moving]); + XFreeCursor(xGlobalDisplay, systemCursors[sizeNESW]); + XFreeCursor(xGlobalDisplay, systemCursors[sizeNS]); + XFreeCursor(xGlobalDisplay, systemCursors[sizeNWSE]); + XFreeCursor(xGlobalDisplay, systemCursors[sizeWE]); + XFreeCursor(xGlobalDisplay, systemCursors[hand]); + XFreeCursor(xGlobalDisplay, systemCursors[arrow]); + //XPutBackEvent(xGlobalDisplay, &e); // xThread.Wait(); // delete xThread; @@ -2757,14 +2779,10 @@ class XInterface : Interface // -- Mouse cursor --- - void SetMouseCursor(int cursor) + void SetMouseCursor(Window window, int cursor) { - //*XLockDisplay(xGlobalDisplay); - if(cursor == -1) - { - XDefineCursor(xGlobalDisplay, (X11Window) guiApp.desktop.windowHandle, nullCursor); - } - //*XUnlockDisplay(xGlobalDisplay); + XDefineCursor(xGlobalDisplay, (X11Window) window.rootWindow.windowHandle, + cursor == -1 ? (X11Cursor)0 : systemCursors[(SystemCursor)cursor]); } // --- Caret --- diff --git a/ecere/src/gui/drivers/cocoa/CocoaInterface.ec b/ecere/src/gui/drivers/cocoa/CocoaInterface.ec index 59eeeaf..dc08d3f 100644 --- a/ecere/src/gui/drivers/cocoa/CocoaInterface.ec +++ b/ecere/src/gui/drivers/cocoa/CocoaInterface.ec @@ -202,7 +202,7 @@ class CocoaInterface : Interface // -- Mouse cursor --- - void SetMouseCursor(int cursor) + void SetMouseCursor(Window window, int cursor) { // TODO: printf("STUB! %s:%i\n", __FILE__, __LINE__); -- 1.8.3.1