Skip to content

Commit aa6606d

Browse files
authored
Add D-Bus activation to book (#2229)
1 parent e29e5a0 commit aa6606d

7 files changed

Lines changed: 70 additions & 29 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
1-
subdir('icons')
21
subdir('resources')
32

4-
desktop_conf = configuration_data()
5-
desktop_conf.set('APP_ID', application_id)
6-
configure_file(
7-
input: '@0@.desktop.in'.format(base_id),
8-
output: '@0@.desktop'.format(application_id),
9-
configuration: desktop_conf,
10-
install: true,
11-
install_dir: datadir / 'applications',
12-
)
3+
# Linux-specific: desktop file, GSettings schema, and icons
4+
if host_machine.system() == 'linux'
5+
subdir('icons')
136

14-
gschema_conf = configuration_data()
15-
gschema_conf.set('APP_ID', application_id)
16-
configure_file(
17-
input: '@0@.gschema.xml.in'.format(base_id),
18-
output: '@0@.gschema.xml'.format(application_id),
19-
configuration: gschema_conf,
20-
install: true,
21-
install_dir: datadir / 'glib-2.0' / 'schemas',
22-
)
7+
desktop_conf = configuration_data()
8+
desktop_conf.set('APP_ID', application_id)
9+
configure_file(
10+
input: '@0@.desktop.in'.format(base_id),
11+
output: '@0@.desktop'.format(application_id),
12+
configuration: desktop_conf,
13+
install: true,
14+
install_dir: datadir / 'applications',
15+
)
16+
17+
gschema_conf = configuration_data()
18+
gschema_conf.set('APP_ID', application_id)
19+
configure_file(
20+
input: '@0@.gschema.xml.in'.format(base_id),
21+
output: '@0@.gschema.xml'.format(application_id),
22+
configuration: gschema_conf,
23+
install: true,
24+
install_dir: datadir / 'glib-2.0' / 'schemas',
25+
)
26+
27+
service_conf = configuration_data()
28+
service_conf.set('APP_ID', application_id)
29+
service_conf.set('BINDIR', bindir)
30+
configure_file(
31+
input: '@0@.service.in'.format(base_id),
32+
output: '@0@.service'.format(application_id),
33+
configuration: service_conf,
34+
install: true,
35+
install_dir: datadir / 'dbus-1' / 'services',
36+
)
37+
endif
2338

book/listings/todo/9/data/org.gtk_rs.Todo9.desktop.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ Exec=todo
44
Icon=@APP_ID@
55
Terminal=false
66
Type=Application
7+
DBusActivatable=true
78
Categories=GNOME;GTK;Utility;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[D-BUS Service]
2+
Name=@APP_ID@
3+
Exec=@BINDIR@/todo --gapplication-service

book/listings/xtask/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn print_help() {
2626
eprintln!(
2727
"Tasks:
2828
install install everything needed to run the listings
29-
configure configure meson projects (generates config.rs, for CI)
29+
configure configure meson projects
3030
"
3131
)
3232
}

book/src/installation_linux.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ To do this, execute the command belonging to the distribution you are using.
99
Fedora and derivatives:
1010

1111
```
12-
sudo dnf install gtk4-devel libadwaita-devel meson desktop-file-utils gcc
12+
sudo dnf install gtk4-devel libadwaita-devel meson desktop-file-utils gcc glib-compile-resources gtk4-update-icon-cache update-desktop-database
1313
```
1414

1515
Debian and derivatives:
1616

1717
```
18-
sudo apt install libgtk-4-dev libadwaita-1-dev meson desktop-file-utils build-essential
18+
sudo apt install libgtk-4-dev libadwaita-1-dev meson desktop-file-utils gcc gtk-update-icon-cache
1919
```
2020

2121
Arch and derivatives:
2222

2323
```
24-
sudo pacman -S gtk4 libadwaita meson desktop-file-utils base-devel
24+
sudo pacman -S gtk4 libadwaita meson desktop-file-utils gcc
2525
```

book/src/meson.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,15 @@ That means that we can change images and `.ui` files without triggering Rust com
107107

108108
We also use `config::app_id()` instead of a hardcoded constant.
109109

110-
## System Integration
110+
## Linux/GNOME Integration
111+
112+
The following sections cover integration with Linux desktop environments, particularly GNOME.
113+
These are optional if you're targeting other platforms, but essential for a polished Linux experience.
111114

112115
### Data meson.build
113116

114-
This file sets subdirs where `meson.build` files will be executed, and declares that a desktop and GSettings schema file will be templated and installed.
117+
This file compiles GResources (cross-platform) and handles Linux-specific installation.
118+
The desktop file, GSettings schema, and icon installation are wrapped in a `host_machine.system() == 'linux'` check, so they're skipped on other platforms.
115119

116120
Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/main/book/listings/todo/9/data/meson.build">listings/todo/9/data/meson.build</a>
117121

@@ -130,7 +134,24 @@ Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/main/b
130134
```
131135

132136
The `@APP_ID@` placeholder is substituted during the build.
133-
This way, we can install the app in default and development, without the two installations clashing with each other.
137+
This way, we can install the app in default and development, without the two installations clashing with each other.
138+
139+
The `DBusActivatable=true` entry enables [D-Bus activation](https://developer.gnome.org/documentation/guidelines/maintainer/integrating.html#d-bus-activation).
140+
Instead of launching your app directly, GNOME can send a D-Bus message to your application's well-known name.
141+
If the app is already running, it can respond by raising its existing window instead of spawning a duplicate instance.
142+
D-Bus activation is also a prerequisite for persistent notifications.
143+
144+
### D-Bus Service File
145+
146+
For D-Bus activation to work, we also need a service file that tells D-Bus how to start our application:
147+
148+
Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/main/book/listings/todo/9/data/org.gtk_rs.Todo9.service.in">listings/todo/9/data/org.gtk_rs.Todo9.service.in</a>
149+
150+
```ini
151+
{{#include ../listings/todo/9/data/org.gtk_rs.Todo9.service.in}}
152+
```
153+
154+
The `--gapplication-service` flag tells GApplication to run as a D-Bus service rather than a standalone application.
134155

135156

136157
### GSettings Schema

0 commit comments

Comments
 (0)