Skip to content

Commit 87e1297

Browse files
committed
git-wrapper: also allow setting the application ID
Windows 7 allows users to pin running applications to the task bar. By setting the application ID, multiple processes can share a single task bar entry, and this is exactly what we need for `git-bash.exe` which wants to share the task bar entry with the `mintty.exe` instance it launches. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 4ded373 commit 87e1297

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

compat/win32/git-wrapper.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,30 @@ static LPWSTR expand_variables(LPWSTR buffer, size_t alloc)
266266
return buf;
267267
}
268268

269+
static void set_app_id(LPWSTR app_id)
270+
{
271+
HMODULE shell32;
272+
HRESULT (*set_app_id)(LPWSTR app_id);
273+
274+
shell32 = LoadLibrary(L"shell32.dll");
275+
if (!shell32)
276+
return;
277+
set_app_id = (void *) GetProcAddress(shell32,
278+
"SetCurrentProcessExplicitAppUserModelID");
279+
if (!set_app_id)
280+
return;
281+
if (!SUCCEEDED(set_app_id(app_id)))
282+
print_error(L"warning: could not set app ID", GetLastError());
283+
}
284+
269285
static int configure_via_resource(LPWSTR basename, LPWSTR exepath, LPWSTR exep,
270286
LPWSTR *prefix_args, int *prefix_args_len,
271287
int *is_git_command, LPWSTR *working_directory, int *full_path,
272288
int *skip_arguments, int *allocate_console, int *show_console)
273289
{
274290
int i, id, minimal_search_path, needs_a_console, no_hide, wargc;
275291
LPWSTR *wargv;
292+
WCHAR *app_id;
276293

277294
#define BUFSIZE 65536
278295
static WCHAR buf[BUFSIZE];
@@ -283,6 +300,7 @@ static int configure_via_resource(LPWSTR basename, LPWSTR exepath, LPWSTR exep,
283300
minimal_search_path = 0;
284301
needs_a_console = 0;
285302
no_hide = 0;
303+
app_id = NULL;
286304
len = LoadString(NULL, id, buf, BUFSIZE);
287305

288306
if (!len) {
@@ -307,6 +325,21 @@ static int configure_via_resource(LPWSTR basename, LPWSTR exepath, LPWSTR exep,
307325
needs_a_console = 1;
308326
else if (strip_prefix(buf, &len, L"SHOW_CONSOLE=1 "))
309327
no_hide = 1;
328+
else if (strip_prefix(buf, &len, L"APP_ID=")) {
329+
LPWSTR space = wcschr(buf, L' ');
330+
size_t app_id_len = space - buf;
331+
if (!space) {
332+
len -= 7;
333+
memmove(buf, buf + 7,
334+
len * sizeof(WCHAR));
335+
break;
336+
}
337+
app_id = wcsdup(buf);
338+
app_id[app_id_len] = L'\0';
339+
len -= app_id_len + 1;
340+
memmove(buf, buf + app_id_len + 1,
341+
len * sizeof(WCHAR));
342+
}
310343
else
311344
break;
312345
}
@@ -325,6 +358,8 @@ static int configure_via_resource(LPWSTR basename, LPWSTR exepath, LPWSTR exep,
325358
fwprintf(stderr,
326359
L"Skipping command-line '%s'\n('%s' not found)\n",
327360
buf2, exep);
361+
if (app_id)
362+
free(app_id);
328363
}
329364

330365
*prefix_args = buf2;
@@ -366,6 +401,10 @@ static int configure_via_resource(LPWSTR basename, LPWSTR exepath, LPWSTR exep,
366401
*skip_arguments = i;
367402
break;
368403
}
404+
else if (!wcsncmp(L"--app-id=", wargv[i], 9)) {
405+
free(app_id);
406+
app_id = wcsdup(wargv[i] + 9);
407+
}
369408
else
370409
break;
371410
*skip_arguments = i;
@@ -376,6 +415,8 @@ static int configure_via_resource(LPWSTR basename, LPWSTR exepath, LPWSTR exep,
376415
*allocate_console = 1;
377416
if (no_hide)
378417
*show_console = 1;
418+
if (app_id)
419+
set_app_id(app_id);
379420
LocalFree(wargv);
380421

381422
return 1;

0 commit comments

Comments
 (0)