diff options
author | Jon TURNEY <jon.turney@dronecode.org.uk> | 2012-11-23 00:03:32 +0000 |
---|---|---|
committer | Jon TURNEY <jon.turney@dronecode.org.uk> | 2012-12-17 22:30:32 +0000 |
commit | 1e1379861f78299f577537b8e5ade4372be9c9c0 (patch) | |
tree | ea22c0544fb147bebad5ff6e6316c5b9895a6ef8 | |
parent | c405792a776ef10ebeaee7e9255a092a64a9081b (diff) |
Add cursor conversion using libXWinWMUtil
-rw-r--r-- | TODO | 18 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/main.c | 13 | ||||
-rw-r--r-- | src/wincursor.c | 67 | ||||
-rw-r--r-- | src/wincursor.h | 27 | ||||
-rw-r--r-- | src/wndproc.c | 3 |
6 files changed, 123 insertions, 7 deletions
@@ -69,11 +69,17 @@ native compostion notes (08/11/11): libXwinWMUtil * should contain at least: -- Icon conversion -- Cursor conversion -- mouse event conversion -- keyboard event conversion -- taskbar interface -- X region to HRGN conversion (maybe...) +- [x] Icon conversion +- [x] Cursor conversion +- [ ] mouse event conversion +- [ ] keyboard event conversion +- [ ] keyboard layout mapping +- [ ] taskbar interface +- [ ] X region to HRGN conversion (appears to be not worthwhile) WM_ICON_NAME should be used for minimized windows? + +XQueryBestCursor() +- only the DDX gets to decide the the answer given to this +- we'd like to tell things that GetSystemMetrics(SM_C(X|Y)CURSOR) is the best size to use +- It's not clear that anything actually uses this, though... diff --git a/src/Makefile.am b/src/Makefile.am index a536286..0d24084 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,6 +15,8 @@ xtow_SOURCES = \ scancodes.h \ winicons.c \ winicons.h \ + wincursor.c \ + wincursor.h \ resource.rc .rc.o: @@ -27,9 +27,11 @@ #include "debug.h" #include "global.h" #include "wndproc.h" +#include "wincursor.h" #define WM_XCWM_CREATE WM_USER #define WM_XCWM_DESTROY (WM_USER+1) +#define WM_XCWM_CURSOR (WM_USER+2) #define XCWM_EVENT_WINDOW_ICON 100 @@ -92,6 +94,13 @@ eventHandler(const xcwm_event_t *event) case XCWM_EVENT_WINDOW_ICON: UpdateIcon(window); break; + + case XCWM_EVENT_CURSOR: + /* + Only the 'GUI thread' is allowed to SetCursor() + */ + PostThreadMessage(msgPumpThread, WM_XCWM_CURSOR, 0, 0); + break; } } @@ -182,6 +191,8 @@ int main(int argc, char **argv) // spawn the event loop thread, and set the callback function xcwm_event_start_loop(context, eventHandler); + InitCursor(); + // pump windows message queue while (GetMessage(&msg, NULL, 0, 0) > 0) { @@ -195,6 +206,8 @@ int main(int argc, char **argv) winDestroyWindowsWindow((xcwm_window_t *)msg.lParam); sem_post(&semaphore); } + else if (msg.message == WM_XCWM_CURSOR) + UpdateCursor(); else DispatchMessage(&msg); } diff --git a/src/wincursor.c b/src/wincursor.c new file mode 100644 index 0000000..3a86366 --- /dev/null +++ b/src/wincursor.c @@ -0,0 +1,67 @@ +// +// Copyright © Jon TURNEY 2012 +// +// This file is part of XtoW. +// +// XtoW 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. +// +// XtoW 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 XtoW. If not, see <http://www.gnu.org/licenses/>. +// + +#include <windows.h> +#include <XWinWMUtil/cursor_convert.h> +#include <xcb/xfixes.h> +#include "global.h" +#include "debug.h" +#include "wincursor.h" + +// we keep a handle to the current cursor around, so we can set it again on WM_SETCURSOR +static HCURSOR hCursor; + +void InitCursor(void) +{ + UpdateCursor(); +} + +void +UpdateCursor(void) +{ + xcb_xfixes_get_cursor_image_cookie_t cookie = xcb_xfixes_get_cursor_image(xcwm_context_get_connection(context)); + xcb_xfixes_get_cursor_image_reply_t* reply = xcb_xfixes_get_cursor_image_reply(xcwm_context_get_connection(context), cookie, NULL); + + DEBUG("Got cursor image, serial %d\n", reply->cursor_serial); + + WMUTIL_CURSOR cursor; + memset(&cursor, 0, sizeof(cursor)); + cursor.width = reply->width; + cursor.height = reply->height; + cursor.xhot = reply->xhot; + cursor.yhot = reply->yhot; + cursor.argb = xcb_xfixes_get_cursor_image_cursor_image(reply); + + hCursor = winXCursorToHCURSOR(&cursor); + + // XXX: We should only change the cursor if the cursor is within one of our windows... + // it's hard to notice this as a problem, as windows don't normally try to change the cursor except in response to something being clicked... + HCURSOR hPreviousCursor = SetCursor(hCursor); + + DEBUG("cursor 0x%08x, previous cursor 0x%08x\n", hCursor, hPreviousCursor); + + DestroyCursor(hPreviousCursor); + + free(reply); +} + +HCURSOR winGetCursor(void) +{ + return hCursor; +} diff --git a/src/wincursor.h b/src/wincursor.h new file mode 100644 index 0000000..88782c7 --- /dev/null +++ b/src/wincursor.h @@ -0,0 +1,27 @@ +// +// Copyright © Jon TURNEY 2012 +// +// This file is part of XtoW. +// +// XtoW 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. +// +// XtoW 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 XtoW. If not, see <http://www.gnu.org/licenses/>. +// + +#ifndef WINCURSOR_H +#define WINCURSOR_H + +void InitCursor(void); +void UpdateCursor(void); +HCURSOR winGetCursor(void); + +#endif /* WINCURSOR_H */ diff --git a/src/wndproc.c b/src/wndproc.c index c3e2d37..e01a558 100644 --- a/src/wndproc.c +++ b/src/wndproc.c @@ -38,6 +38,7 @@ #include "winicons.h" #include "wndproc.h" #include "global.h" +#include "wincursor.h" #define WINDOW_CLASS_X "xtow" #define WINDOW_TITLE_X "X" @@ -1271,7 +1272,7 @@ winTopLevelWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_SETCURSOR: if (LOWORD(lParam) == HTCLIENT) { - SetCursor(LoadCursor(NULL, IDC_ARROW)); + SetCursor(winGetCursor()); return TRUE; } break; |