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.
This commit is contained in:
Frank Praznik 2023-05-25 20:37:49 -04:00
parent 85f33fe866
commit 2f75596d5a
12 changed files with 167 additions and 114 deletions

View file

@ -158,6 +158,53 @@ extern "C" {
*/
#define SDL_HINT_ANDROID_ALLOW_RECREATE_ACTIVITY "SDL_ANDROID_ALLOW_RECREATE_ACTIVITY"
/**
* \brief A variable setting the app ID string.
* This string is used by desktop compositors to identify and group windows
* together, as well as match applications with associated desktop settings
* and icons.
*
* On Wayland this corresponds to the "app ID" window property and on X11 this
* corresponds to the WM_CLASS property. Windows inherit the value of this hint
* at creation time. Changing this hint after a window has been created will not
* change the app ID or class of existing windows.
*
* For *nix platforms, this string should be formatted in reverse-DNS notation
* and follow some basic rules to be valid:
*
* - The application ID must be composed of two or more elements separated by a
* period (.) character.
*
* - Each element must contain one or more of the alphanumeric characters
* (A-Z, a-z, 0-9) plus underscore (_) and hyphen (-) and must not start
* with a digit. Note that hyphens, while technically allowed, should not be
* used if possible, as they are not supported by all components that use the ID,
* such as D-Bus. For maximum compatability, replace hyphens with an underscore.
*
* - The empty string is not a valid element (ie: your application ID may not
* start or end with a period and it is not valid to have two periods in a row).
*
* - The entire ID must be less than 255 characters in length.
*
* Examples of valid app ID strings:
*
* - org.MyOrg.MyApp
* - com.your_company.your_app
*
* Desktops such as GNOME and KDE require that the app ID string matches your
* application's .desktop file name (e.g. if the app ID string is 'org.MyOrg.MyApp',
* your application's .desktop file should be named 'org.MyOrg.MyApp.desktop').
*
* If you plan to package your application in a container such as Flatpak, the
* app ID should match the name of your Flatpak container as well.
*
* If not set, SDL will attempt to use the application executable name.
* If the executable name cannot be retrieved, the generic string "SDL_App" will be used.
*
* On targets where this is not supported, this hint does nothing.
*/
#define SDL_HINT_APP_ID "SDL_APP_ID"
/**
* \brief Specify an application name.
*