135c4bbdfSmrg/*
235c4bbdfSmrg * Copyright (C) 2011 Tobias Häußler
335c4bbdfSmrg *
435c4bbdfSmrg * Permission is hereby granted, free of charge, to any person obtaining a
535c4bbdfSmrg * copy of this software and associated documentation files (the "Software"),
635c4bbdfSmrg * to deal in the Software without restriction, including without limitation
735c4bbdfSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
835c4bbdfSmrg * and/or sell copies of the Software, and to permit persons to whom the
935c4bbdfSmrg * Software is furnished to do so, subject to the following conditions:
1035c4bbdfSmrg *
1135c4bbdfSmrg * The above copyright notice and this permission notice (including the next
1235c4bbdfSmrg * paragraph) shall be included in all copies or substantial portions of the
1335c4bbdfSmrg * Software.
1435c4bbdfSmrg *
1535c4bbdfSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1635c4bbdfSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1735c4bbdfSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1835c4bbdfSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1935c4bbdfSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2035c4bbdfSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2135c4bbdfSmrg * DEALINGS IN THE SOFTWARE.
2235c4bbdfSmrg */
2335c4bbdfSmrg
2435c4bbdfSmrg#ifdef HAVE_XWIN_CONFIG_H
2535c4bbdfSmrg#include <xwin-config.h>
2635c4bbdfSmrg#endif
2735c4bbdfSmrg
2835c4bbdfSmrg#include <X11/Xlib.h>
2935c4bbdfSmrg#include <X11/Xproto.h>
3035c4bbdfSmrg#include <X11/Xwindows.h>
3135c4bbdfSmrg#include <pthread.h>
3235c4bbdfSmrg#include "winwindow.h"
3335c4bbdfSmrg#include "os.h"
3435c4bbdfSmrg#include "winmsg.h"
3535c4bbdfSmrg
3635c4bbdfSmrg#include <shlwapi.h>
3735c4bbdfSmrg
3835c4bbdfSmrg#define INITGUID
3935c4bbdfSmrg#include "initguid.h"
4035c4bbdfSmrg#include "propertystore.h"
4135c4bbdfSmrg#undef INITGUID
4235c4bbdfSmrg
4335c4bbdfSmrgstatic HMODULE g_hmodShell32Dll = NULL;
4435c4bbdfSmrgstatic SHGETPROPERTYSTOREFORWINDOWPROC g_pSHGetPropertyStoreForWindow = NULL;
4535c4bbdfSmrg
4635c4bbdfSmrgvoid
4735c4bbdfSmrgwinPropertyStoreInit(void)
4835c4bbdfSmrg{
4935c4bbdfSmrg    /*
5035c4bbdfSmrg       Load library and get function pointer to SHGetPropertyStoreForWindow()
5135c4bbdfSmrg
5235c4bbdfSmrg       SHGetPropertyStoreForWindow is only supported since Windows 7. On previous
5335c4bbdfSmrg       versions the pointer will be NULL and taskbar grouping is not supported.
5435c4bbdfSmrg       winSetAppUserModelID() will do nothing in this case.
5535c4bbdfSmrg     */
5635c4bbdfSmrg    g_hmodShell32Dll = LoadLibrary("shell32.dll");
5735c4bbdfSmrg    if (g_hmodShell32Dll == NULL) {
5835c4bbdfSmrg        ErrorF("winPropertyStoreInit - Could not load shell32.dll\n");
5935c4bbdfSmrg        return;
6035c4bbdfSmrg    }
6135c4bbdfSmrg
6235c4bbdfSmrg    g_pSHGetPropertyStoreForWindow =
6335c4bbdfSmrg        (SHGETPROPERTYSTOREFORWINDOWPROC) GetProcAddress(g_hmodShell32Dll,
6435c4bbdfSmrg                                                         "SHGetPropertyStoreForWindow");
6535c4bbdfSmrg    if (g_pSHGetPropertyStoreForWindow == NULL) {
6635c4bbdfSmrg        ErrorF
6735c4bbdfSmrg            ("winPropertyStoreInit - Could not get SHGetPropertyStoreForWindow address\n");
6835c4bbdfSmrg        return;
6935c4bbdfSmrg    }
7035c4bbdfSmrg}
7135c4bbdfSmrg
7235c4bbdfSmrgvoid
7335c4bbdfSmrgwinPropertyStoreDestroy(void)
7435c4bbdfSmrg{
7535c4bbdfSmrg    if (g_hmodShell32Dll != NULL) {
7635c4bbdfSmrg        FreeLibrary(g_hmodShell32Dll);
7735c4bbdfSmrg        g_hmodShell32Dll = NULL;
7835c4bbdfSmrg        g_pSHGetPropertyStoreForWindow = NULL;
7935c4bbdfSmrg    }
8035c4bbdfSmrg}
8135c4bbdfSmrg
8235c4bbdfSmrgvoid
8335c4bbdfSmrgwinSetAppUserModelID(HWND hWnd, const char *AppID)
8435c4bbdfSmrg{
8535c4bbdfSmrg    PROPVARIANT pv;
8635c4bbdfSmrg    IPropertyStore *pps = NULL;
8735c4bbdfSmrg    HRESULT hr;
8835c4bbdfSmrg
8935c4bbdfSmrg    if (g_pSHGetPropertyStoreForWindow == NULL) {
9035c4bbdfSmrg        return;
9135c4bbdfSmrg    }
9235c4bbdfSmrg
9335c4bbdfSmrg    winDebug("winSetAppUserMOdelID - hwnd 0x%p appid '%s'\n", hWnd, AppID);
9435c4bbdfSmrg
9535c4bbdfSmrg    hr = g_pSHGetPropertyStoreForWindow(hWnd, &IID_IPropertyStore,
9635c4bbdfSmrg                                        (void **) &pps);
9735c4bbdfSmrg    if (SUCCEEDED(hr) && pps) {
9835c4bbdfSmrg        memset(&pv, 0, sizeof(PROPVARIANT));
9935c4bbdfSmrg        if (AppID) {
10035c4bbdfSmrg            pv.vt = VT_LPWSTR;
10135c4bbdfSmrg            hr = SHStrDupA(AppID, &pv.pwszVal);
10235c4bbdfSmrg        }
10335c4bbdfSmrg
10435c4bbdfSmrg        if (SUCCEEDED(hr)) {
10535c4bbdfSmrg            pps->lpVtbl->SetValue(pps, &PKEY_AppUserModel_ID, &pv);
10635c4bbdfSmrg            PropVariantClear(&pv);
10735c4bbdfSmrg        }
10835c4bbdfSmrg        pps->lpVtbl->Release(pps);
10935c4bbdfSmrg    }
11035c4bbdfSmrg}
111