forked from libsdl-org/SDL
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate the X11 WM_CLASS and Wayland app ID envvars
Consolidate the X11_WMCLASS and WAYLAND_WMCLASS envvars into one SDL_HINT_APP_ID hint. This hint serves the same purpose on both windowing systems to allow desktop compositors to identify and group windows together, as well as associate applications with their desktop settings and icons. The common code for retrieving the value is now consolidated under core/unix/SDL_appid.c as it's common to *nix platforms, and the value is now retrieved at window creation time instead of being cached by the video driver at startup so that changes to the hint after video initialization and before window creation will be seen, as well as to accommodate cases where applications want to use different values for different windows.
- Loading branch information
1 parent
85f33fe
commit 2f75596
Showing
12 changed files
with
167 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
Simple DirectMedia Layer | ||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org> | ||
This software is provided 'as-is', without any express or implied | ||
warranty. In no event will the authors be held liable for any damages | ||
arising from the use of this software. | ||
Permission is granted to anyone to use this software for any purpose, | ||
including commercial applications, and to alter it and redistribute it | ||
freely, subject to the following restrictions: | ||
1. The origin of this software must not be misrepresented; you must not | ||
claim that you wrote the original software. If you use this software | ||
in a product, an acknowledgment in the product documentation would be | ||
appreciated but is not required. | ||
2. Altered source versions must be plainly marked as such, and must not be | ||
misrepresented as being the original software. | ||
3. This notice may not be removed or altered from any source distribution. | ||
*/ | ||
|
||
#include "SDL_internal.h" | ||
|
||
#include "SDL_appid.h" | ||
#include <unistd.h> | ||
|
||
const char *SDL_GetExeName() | ||
{ | ||
static const char *proc_name = NULL; | ||
|
||
/* TODO: Use a fallback if BSD has no mounted procfs (OpenBSD has no procfs at all) */ | ||
if (!proc_name) { | ||
#if defined(__LINUX__) || defined(__FREEBSD__) || defined (__NETBSD__) | ||
static char linkfile[1024]; | ||
int linksize; | ||
|
||
#if defined(__LINUX__) | ||
const char *proc_path = "/proc/self/exe"; | ||
#elif defined(__FREEBSD__) | ||
const char *proc_path = "/proc/curproc/file"; | ||
#elif defined(__NETBSD__) | ||
const char *proc_path = "/proc/curproc/exe"; | ||
#endif | ||
linksize = readlink(proc_path, linkfile, sizeof(linkfile) - 1); | ||
if (linksize > 0) { | ||
linkfile[linksize] = '\0'; | ||
proc_name = SDL_strrchr(linkfile, '/'); | ||
if (proc_name) { | ||
++proc_name; | ||
} else { | ||
proc_name = linkfile; | ||
} | ||
} | ||
#endif | ||
} | ||
|
||
return proc_name; | ||
} | ||
|
||
const char *SDL_GetAppID() | ||
{ | ||
/* Always check the hint, as it may have changed */ | ||
const char *id_str = SDL_GetHint(SDL_HINT_APP_ID); | ||
|
||
if (!id_str) { | ||
/* If the hint isn't set, try to use the application's executable name */ | ||
id_str = SDL_GetExeName(); | ||
} | ||
|
||
if (!id_str) { | ||
/* Finally, use the default we've used forever */ | ||
id_str = "SDL_App"; | ||
} | ||
|
||
return id_str; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
Simple DirectMedia Layer | ||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org> | ||
This software is provided 'as-is', without any express or implied | ||
warranty. In no event will the authors be held liable for any damages | ||
arising from the use of this software. | ||
Permission is granted to anyone to use this software for any purpose, | ||
including commercial applications, and to alter it and redistribute it | ||
freely, subject to the following restrictions: | ||
1. The origin of this software must not be misrepresented; you must not | ||
claim that you wrote the original software. If you use this software | ||
in a product, an acknowledgment in the product documentation would be | ||
appreciated but is not required. | ||
2. Altered source versions must be plainly marked as such, and must not be | ||
misrepresented as being the original software. | ||
3. This notice may not be removed or altered from any source distribution. | ||
*/ | ||
|
||
#include "SDL_internal.h" | ||
|
||
#ifndef SDL_appid_h_ | ||
#define SDL_appid_h_ | ||
|
||
extern const char *SDL_GetExeName(); | ||
extern const char *SDL_GetAppID(); | ||
|
||
#endif /* SDL_appid_h_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.