Skip to content

Commit

Permalink
Centralize app_id handling
Browse files Browse the repository at this point in the history
On modern Linux it is preferred to use the fully qualified application ID for naming the desktop, icon, and metainfo files. Add a meson option to capture this variable and set it to `org.dosbox-staging.Dosbox-staging` which better matches that the homepage is dosbox-staging.org.

Then ensure that we're setting the X11 `resourceclass` and the Wayland app_id to this value. Those values need to match the name of the .desktop file in order for compositors/window managers to correctly associate windows to the appropriate .desktop file (see [here](zed-industries/zed#12707 (comment)) for an explanation I previously wrote on how that works). Now that we're ensuring that both X11 and Wayland should have correct window associations we can drop `StartupWMClass` from the desktop file as it is now unnecessary.

Also, since SDL3 changed how that is done I added some #if statements so that that's ready whenever dosbox-staging is ported to SDL3.

Signed-off-by: Reilly Brogan <reilly@reillybrogan.com>
  • Loading branch information
ReillyBrogan committed Jul 11, 2024
1 parent 445eb15 commit dce2e47
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
run: sudo apt-get install appstream-util

- name: Verify metainfo.xml
run: appstream-util validate-relax --nonet contrib/linux/dosbox-staging.metainfo.xml
run: appstream-util validate-relax --nonet contrib/linux/dosbox-staging.metainfo.xml.in
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,5 @@ tools/unlock_the_magic_mpeg_ps.exe
obj-*.-linux-gnu
debian

contrib/linux/*.desktop
contrib/linux/*.metainfo.xml
3 changes: 2 additions & 1 deletion contrib/icons/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ png_files = {
foreach name, size : png_files
install_data(
'png' / name,
rename: 'dosbox-staging.png',
rename: appid + '.png',
install_dir: icons_hicolor / size / 'apps',
)
endforeach
Expand All @@ -28,5 +28,6 @@ endforeach
#
install_data(
'svg' / 'dosbox-staging.svg',
rename: appid + '.svg',
install_dir: icons_hicolor / 'scalable' / 'apps',
)
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ GenericName[zh_CN]=DOS 模拟器
GenericName[zh_TW]=DOS 模擬器
Comment=DOS/x86 emulator focusing on ease of use
Exec=dosbox
Icon=dosbox-staging
Icon=@app_id@
Type=Application
Terminal=false
Keywords=dos;gaming;game;games;emulator;
Categories=Game;Emulator;
StartupWMClass=dosbox-staging
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (C) 2020-2024 The DOSBox Staging Team -->
<component type="desktop">
<id>io.github.dosbox-staging</id>
<id>@app_id@</id>
<metadata_license>CC0-1.0</metadata_license>
<project_license>GPL-2.0-or-later</project_license>
<name>DOSBox Staging</name>
Expand Down Expand Up @@ -65,7 +65,7 @@
<control>console</control>
<control>gamepad</control>
</recommends>
<launchable type="desktop-id">dosbox-staging.desktop</launchable>
<launchable type="desktop-id">@app_id@.desktop</launchable>
<developer_name>The DOSBox Staging Team</developer_name>
<update_contact>dreamer.tan@gmail.com</update_contact>
<url type="homepage">https://www.dosbox-staging.org/</url>
Expand Down
3 changes: 2 additions & 1 deletion contrib/linux/install-icons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ usage() {

install_icons() {
cp -r icons $DEST_PATH
cp desktop/dosbox-staging.desktop $DEST_PATH/applications
cp desktop/dosbox-staging.desktop.in $DEST_PATH/applications/dosbox-staging.desktop

## Replace executable location in the .desktop file
sed -i 's\Exec=dosbox\Exec='$(realpath dosbox)'\g' $DEST_PATH/applications/dosbox-staging.desktop
sed -i 's\@app_id@\dosbox-staging\g' $DEST_PATH/applications/dosbox-staging.desktop
}

remove_icons() {
Expand Down
17 changes: 15 additions & 2 deletions contrib/linux/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
install_data('dosbox-staging.desktop', install_dir: data_dir / 'applications')
resource_data = configuration_data()
resource_data.set('app_id', appid)

install_data('dosbox-staging.metainfo.xml', install_dir: data_dir / 'metainfo')
configure_file(
input: 'dosbox-staging.desktop.in',
output: appid + '.desktop',
configuration: resource_data,
install_dir: data_dir / 'applications',
)

configure_file(
input: 'dosbox-staging.metainfo.xml.in',
output: appid + '.metainfo.xml',
configuration: resource_data,
install_dir: data_dir / 'metainfo',
)
1 change: 0 additions & 1 deletion include/dosbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
// Copyright string
#define DOSBOX_COPYRIGHT "(C) " DOSBOX_TEAM


int sdl_main(int argc, char *argv[]);

// The shutdown_requested bool is a conditional break in the parse-loop and
Expand Down
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ install_data(
)
install_data('AUTHORS', 'README', 'THANKS', install_dir: doc_dir)

appid = get_option('app_id')
subdir('contrib/linux')
subdir('contrib/icons')
subdir('contrib/resources')
Expand Down Expand Up @@ -418,6 +419,7 @@ git_hash = run_command(
conf_data = configuration_data()
conf_data.set('version', meson.project_version())
conf_data.set('project_name', meson.project_name())
conf_data.set('app_id', appid)
conf_data.set('git_hash', git_hash)
conf_data.set_quoted(
'CUSTOM_DATADIR',
Expand Down
9 changes: 9 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# Fully qualified application ID for the emulator
# See https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names for details
option(
'app_id',
type: 'string',
value: 'org.dosbox-staging.Dosbox-staging',
description: 'Fully qualified application ID for dosbox-staging. This is primarily used on Linux',
)

option(
'use_sdl2_net',
type: 'boolean',
Expand Down
4 changes: 3 additions & 1 deletion scripts/create-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ pkg_linux()
ldd "${build_dir}/dosbox" || true
install -DT "${build_dir}/dosbox" "${pkg_dir}/dosbox"

install -DT contrib/linux/dosbox-staging.desktop "${pkg_dir}/desktop/dosbox-staging.desktop"
install -DT contrib/linux/dosbox-staging.desktop.in "${pkg_dir}/desktop/dosbox-staging.desktop"
sed -i 's\@app_id@\dosbox-staging\g' "${pkg_dir}/desktop/dosbox-staging.desktop"

install -DT contrib/linux/install-icons.sh "${pkg_dir}/install-icons.sh"

DESTDIR="$(realpath "$pkg_dir")" make -C contrib/icons/ install datadir=
Expand Down
4 changes: 4 additions & 0 deletions src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
// Git hash of the build
#define BUILD_GIT_HASH "@git_hash@"

// Fully qualified application ID for the emulator
// See https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names for details
#define DOSBOX_APP_ID "@app_id@"

/* Operating System
*/

Expand Down
11 changes: 10 additions & 1 deletion src/gui/sdlmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
#define APIENTRYP APIENTRY *
#endif

#if SDL_VERSION_ATLEAST(3, 0, 0)
#define SDL_HINT_APP_ID DOSBOX_APP_ID
#endif

/* Don't guard these with GL_VERSION_2_0 - Apple defines it but not these typedefs.
* If they're already defined they should match these definitions, so no conflicts.
*/
Expand Down Expand Up @@ -4616,13 +4620,16 @@ static int erase_mapper_file()
return 0;
}

#if !(SDL_VERSION_ATLEAST(3, 0, 0))
static void override_wm_class()
{
#if !defined(WIN32)
constexpr int overwrite = 0; // don't overwrite
setenv("SDL_VIDEO_X11_WMCLASS", DOSBOX_PROJECT_NAME, overwrite);
setenv("SDL_VIDEO_X11_WMCLASS", DOSBOX_APP_ID, overwrite);
setenv("SDL_VIDEO_WAYLAND_WMCLASS", DOSBOX_APP_ID, overwrite);
#endif
}
#endif

int sdl_main(int argc, char* argv[])
{
Expand Down Expand Up @@ -4669,8 +4676,10 @@ int sdl_main(int argc, char* argv[])
}
}

#if !(SDL_VERSION_ATLEAST(3, 0, 0))
// Before SDL2 video subsystem is initialised
override_wm_class();
#endif

// Create or determine the location of the config directory
// (e.g., in portable mode, the config directory is the
Expand Down

0 comments on commit dce2e47

Please sign in to comment.