diff options
author | Jon TURNEY <jon.turney@dronecode.org.uk> | 2012-11-10 18:06:37 +0000 |
---|---|---|
committer | Jon TURNEY <jon.turney@dronecode.org.uk> | 2012-12-17 22:30:13 +0000 |
commit | c405792a776ef10ebeaee7e9255a092a64a9081b (patch) | |
tree | 35f9eacaf2a4a12309bc68bbb6bbbcf55c571cdb | |
parent | 59dd0316d0deca2bfcae502baf18b0c005915779 (diff) |
Add icon conversion using libXWinWMUtil
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/debug.c | 13 | ||||
-rw-r--r-- | src/debug.h | 11 | ||||
-rw-r--r-- | src/main.c | 9 | ||||
-rw-r--r-- | src/winicons.c | 12 | ||||
-rw-r--r-- | src/winicons.h | 6 | ||||
-rw-r--r-- | src/wndproc.c | 51 | ||||
-rw-r--r-- | src/wndproc.h | 1 |
8 files changed, 89 insertions, 16 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index ebf66dd..a536286 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -20,4 +20,4 @@ xtow_SOURCES = \ .rc.o: $(AM_V_GEN)$(WINDRES) --use-temp-file -i $< --input-format=rc -o $@ -O coff -xtow_LDADD = $(XCWM_LIBS) -lgdi32 +xtow_LDADD = -lXWinWMUtil $(XCWM_LIBS) -lgdi32 diff --git a/src/debug.c b/src/debug.c index 2761405..5495cd8 100644 --- a/src/debug.c +++ b/src/debug.c @@ -24,7 +24,7 @@ #if 1 int -debug(const char *format, ...) +winDebug(const char *format, ...) { int count; va_list ap; @@ -35,3 +35,14 @@ debug(const char *format, ...) return count; } #endif + +int +winError(const char *format, ...) +{ + int count; + va_list ap; + va_start(ap, format); + count = vfprintf(stderr, format, ap); + va_end(ap); + return count; +} diff --git a/src/debug.h b/src/debug.h index 16f3604..dd4daf2 100644 --- a/src/debug.h +++ b/src/debug.h @@ -17,9 +17,16 @@ // along with XtoW. If not, see <http://www.gnu.org/licenses/>. // +#ifndef DEBUG_H +#define DEBUG_H + +int winError(const char *format, ...); + #if 1 -int debug(const char *format, ...); -#define DEBUG debug +int winDebug(const char *format, ...); +#define DEBUG winDebug #else #define DEBUG(Args...) #endif + +#endif /* DEBUG_H */ @@ -31,10 +31,13 @@ #define WM_XCWM_CREATE WM_USER #define WM_XCWM_DESTROY (WM_USER+1) +#define XCWM_EVENT_WINDOW_ICON 100 + xcwm_context_t *context; xcb_atom_t motif_wm_hints = 0; xcb_atom_t windowState = 0; DWORD msgPumpThread; +int serverGeneration = 1; static sem_t semaphore; @@ -85,6 +88,10 @@ eventHandler(const xcwm_event_t *event) case XCWM_EVENT_WINDOW_SHAPE: UpdateShape(window); break; + + case XCWM_EVENT_WINDOW_ICON: + UpdateIcon(window); + break; } } @@ -169,6 +176,8 @@ int main(int argc, char **argv) // register interest in some atoms motif_wm_hints = xcwm_atom_register(context, "_MOTIF_WM_HINTS", XCWM_EVENT_WINDOW_APPEARANCE); windowState = xcwm_atom_register(context, "_NET_WM_STATE", XCWM_EVENT_WINDOW_APPEARANCE); + xcwm_atom_register(context, " _NET_WM_ICON", XCWM_EVENT_WINDOW_ICON); + xcwm_atom_register(context, " WM_HINTS", XCWM_EVENT_WINDOW_ICON); // spawn the event loop thread, and set the callback function xcwm_event_start_loop(context, eventHandler); diff --git a/src/winicons.c b/src/winicons.c index 37928fe..3b453f1 100644 --- a/src/winicons.c +++ b/src/winicons.c @@ -24,8 +24,8 @@ #include "resource.h" #include "winicons.h" -HICON g_hIconX = NULL; -HICON g_hSmallIconX = NULL; +static HICON g_hIconX = NULL; +static HICON g_hSmallIconX = NULL; static void winInitGlobalIcons(void) @@ -64,3 +64,11 @@ winSelectIcons(HICON *pIcon, HICON *pSmallIcon) if (pSmallIcon) *pSmallIcon = hSmallIcon; } + +void +winDestroyIcon(HICON hIcon) +{ + /* Delete the icon if its not one of the application defaults */ + if (hIcon && (hIcon != g_hIconX) && (hIcon != g_hSmallIconX)) + DestroyIcon(hIcon); +} diff --git a/src/winicons.h b/src/winicons.h index d928e91..3663ec2 100644 --- a/src/winicons.h +++ b/src/winicons.h @@ -20,4 +20,10 @@ * SOFTWARE. */ +#ifndef WINICONS_H +#define WINICONS_H + void winSelectIcons(HICON *pIcon, HICON *pSmallIcon); +void winDestroyIcon(HICON hIcon); + +#endif /* WINICONS_H */ diff --git a/src/wndproc.c b/src/wndproc.c index ee95d77..c3e2d37 100644 --- a/src/wndproc.c +++ b/src/wndproc.c @@ -30,6 +30,7 @@ #include <assert.h> #include <limits.h> #include <xcwm/xcwm.h> +#include <XWinWMUtil/icon_convert.h> #include "debug.h" #include "winmessages.h" @@ -636,6 +637,38 @@ UpdateStyle(xcwm_window_t *window) SetLayeredWindowAttributes(hWnd, RGB(0,0,0), bAlpha, LWA_ALPHA); } +void +UpdateIcon(xcwm_window_t *window) +{ + HWND hWnd = xcwm_window_get_local_data(window); + HICON hIcon, hIconSmall, hIconOld; + + hIcon = winXIconToHICON(xcwm_context_get_connection(xcwm_window_get_context(window)), xcwm_window_get_window_id(window), GetSystemMetrics(SM_CXICON)); + hIconSmall = winXIconToHICON(xcwm_context_get_connection(xcwm_window_get_context(window)), xcwm_window_get_window_id(window), GetSystemMetrics(SM_CXSMICON)); + + /* If we got the small, but not the large one swap them */ + if (!hIcon && hIconSmall) { + hIcon = hIconSmall; + hIconSmall = NULL; + } + + if (hIcon) + { + /* Set the large icon */ + hIconOld = (HICON) SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM) hIcon); + /* Delete the old icon, if its not the default */ + winDestroyIcon(hIconOld); + } + + if (hIconSmall) + { + /* Same for the small icon */ + hIconOld = (HICON) SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM) hIconSmall); + /* Delete the old icon, if its not the default */ + winDestroyIcon(hIconOld); + } +} + #define WIN_POLLING_MOUSE_TIMER_ID 2 #define MOUSE_POLLING_INTERVAL 50 @@ -1388,8 +1421,8 @@ winCreateWindowsWindow(xcwm_window_t *window) /* save the HWND into the context */ xcwm_window_set_local_data(window, hWnd); - /* Set icons */ - HICON hIcon; + /* Set default icon */ + HICON hIcon; HICON hIconSmall; winSelectIcons(&hIcon, &hIconSmall); if (hIcon) SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) hIcon); @@ -1437,7 +1470,7 @@ winCreateWindowsWindow(xcwm_window_t *window) /* Apply all properties which effect the window appearance or behaviour */ UpdateName(window); - /* UpdateIcon(); */ + UpdateIcon(window); UpdateStyle(window); UpdateShape(window); @@ -1456,11 +1489,11 @@ winDestroyWindowsWindow(xcwm_window_t *window) if (hWnd == NULL) return; -#if 0 /* Store the info we need to destroy after this window is gone */ - hIcon = (HICON)SendMessage(pWin->hWnd, WM_GETICON, ICON_BIG, 0); - hIconSm = (HICON)SendMessage(pWin->hWnd, WM_GETICON, ICON_SMALL, 0); -#endif + HICON hIcon; + HICON hIconSmall; + hIcon = (HICON)SendMessage(hWnd, WM_GETICON, ICON_BIG, 0); + hIconSmall = (HICON)SendMessage(hWnd, WM_GETICON, ICON_SMALL, 0); /* Destroy the Windows window */ DestroyWindow(hWnd); @@ -1468,9 +1501,7 @@ winDestroyWindowsWindow(xcwm_window_t *window) /* Null our handle to the Window so referencing it will cause an error */ xcwm_window_set_local_data(window, NULL); -#if 0 /* Destroy any icons we created for this window */ winDestroyIcon(hIcon); - winDestroyIcon(hIconSm); -#endif + winDestroyIcon(hIconSmall); } diff --git a/src/wndproc.h b/src/wndproc.h index 5b11f89..d711cd9 100644 --- a/src/wndproc.h +++ b/src/wndproc.h @@ -26,6 +26,7 @@ void UpdateName(xcwm_window_t *window); void UpdateImage(xcwm_window_t *window); void UpdateStyle(xcwm_window_t *window); void UpdateShape(xcwm_window_t *window); +void UpdateIcon(xcwm_window_t *window); void winCreateWindowsWindow(xcwm_window_t *window); void winDestroyWindowsWindow(xcwm_window_t *window); |