Commit | Line | Data |
---|---|---|
a09e091a JB |
1 | /* |
2 | * Copyright (C) 2011 Tobias Häußler | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a | |
5 | * copy of this software and associated documentation files (the "Software"), | |
6 | * to deal in the Software without restriction, including without limitation | |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
8 | * and/or sell copies of the Software, and to permit persons to whom the | |
9 | * Software is furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice (including the next | |
12 | * paragraph) shall be included in all copies or substantial portions of the | |
13 | * Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | */ | |
23 | ||
24 | #ifdef HAVE_XWIN_CONFIG_H | |
25 | #include <xwin-config.h> | |
26 | #endif | |
27 | ||
28 | #include <X11/Xlib.h> | |
29 | #include <X11/Xproto.h> | |
30 | #include <X11/Xwindows.h> | |
31 | #include <pthread.h> | |
32 | #include "winwindow.h" | |
33 | #include "os.h" | |
34 | #include "winmsg.h" | |
35 | ||
36 | #include <shlwapi.h> | |
37 | ||
38 | #define INITGUID | |
39 | #include "initguid.h" | |
40 | #include "propertystore.h" | |
41 | #undef INITGUID | |
42 | ||
43 | static HMODULE g_hmodShell32Dll = NULL; | |
44 | static SHGETPROPERTYSTOREFORWINDOWPROC g_pSHGetPropertyStoreForWindow = NULL; | |
45 | ||
46 | void | |
47 | winPropertyStoreInit(void) | |
48 | { | |
49 | /* | |
50 | Load library and get function pointer to SHGetPropertyStoreForWindow() | |
51 | ||
52 | SHGetPropertyStoreForWindow is only supported since Windows 7. On previous | |
53 | versions the pointer will be NULL and taskbar grouping is not supported. | |
54 | winSetAppUserModelID() will do nothing in this case. | |
55 | */ | |
56 | g_hmodShell32Dll = LoadLibrary("shell32.dll"); | |
57 | if (g_hmodShell32Dll == NULL) { | |
58 | ErrorF("winPropertyStoreInit - Could not load shell32.dll\n"); | |
59 | return; | |
60 | } | |
61 | ||
62 | g_pSHGetPropertyStoreForWindow = | |
63 | (SHGETPROPERTYSTOREFORWINDOWPROC) GetProcAddress(g_hmodShell32Dll, | |
64 | "SHGetPropertyStoreForWindow"); | |
65 | if (g_pSHGetPropertyStoreForWindow == NULL) { | |
66 | ErrorF | |
67 | ("winPropertyStoreInit - Could not get SHGetPropertyStoreForWindow address\n"); | |
68 | return; | |
69 | } | |
70 | } | |
71 | ||
72 | void | |
73 | winPropertyStoreDestroy(void) | |
74 | { | |
75 | if (g_hmodShell32Dll != NULL) { | |
76 | FreeLibrary(g_hmodShell32Dll); | |
77 | g_hmodShell32Dll = NULL; | |
78 | g_pSHGetPropertyStoreForWindow = NULL; | |
79 | } | |
80 | } | |
81 | ||
82 | void | |
83 | winSetAppUserModelID(HWND hWnd, const char *AppID) | |
84 | { | |
85 | PROPVARIANT pv; | |
86 | IPropertyStore *pps = NULL; | |
87 | HRESULT hr; | |
88 | ||
89 | if (g_pSHGetPropertyStoreForWindow == NULL) { | |
90 | return; | |
91 | } | |
92 | ||
93 | winDebug("winSetAppUserMOdelID - hwnd 0x%08x appid '%s'\n", hWnd, AppID); | |
94 | ||
95 | hr = g_pSHGetPropertyStoreForWindow(hWnd, &IID_IPropertyStore, | |
96 | (void **) &pps); | |
97 | if (SUCCEEDED(hr) && pps) { | |
98 | memset(&pv, 0, sizeof(PROPVARIANT)); | |
99 | if (AppID) { | |
100 | pv.vt = VT_LPWSTR; | |
101 | hr = SHStrDupA(AppID, &pv.pwszVal); | |
102 | } | |
103 | ||
104 | if (SUCCEEDED(hr)) { | |
105 | pps->lpVtbl->SetValue(pps, &PKEY_AppUserModel_ID, &pv); | |
106 | PropVariantClear(&pv); | |
107 | } | |
108 | pps->lpVtbl->Release(pps); | |
109 | } | |
110 | } |