Skip to content

Commit fc47e20

Browse files
committed
feat: global shortcuts support through dbus (my behated)
1 parent 9b513c3 commit fc47e20

8 files changed

Lines changed: 822 additions & 1 deletion

File tree

arch/PKGBUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ depends=(
1111
'libevdev.so'
1212
'libinput'
1313
'libpixman-1.so'
14+
'libsystemd.so'
1415
'libudev.so'
1516
'libwayland-server.so'
1617
'libxcb'

arch/doors-portals.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[preferred]
22
default=wlr;*
33
org.freedesktop.impl.portal.Inhibit=none
4+
org.freedesktop.impl.portal.GlobalShortcuts=doors;wlr;*

include/global_shortcuts.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#pragma once
2+
3+
#include <stdbool.h>
4+
#include <stdint.h>
5+
#include <wayland-server-core.h>
6+
#include <xkbcommon/xkbcommon.h>
7+
8+
struct sd_bus;
9+
struct sd_bus_slot;
10+
11+
// D-Bus interface / bus names
12+
#define GS_IMPL_IFACE "org.freedesktop.impl.portal.GlobalShortcuts"
13+
#define GS_SESSION_IFACE "org.freedesktop.portal.Session"
14+
#define GS_REQUEST_IFACE "org.freedesktop.portal.Request"
15+
#define GS_BUS_NAME "org.freedesktop.impl.portal.desktop.doors"
16+
#define GS_OBJECT_PATH "/org/freedesktop/portal/desktop"
17+
#define GS_VERSION 2
18+
19+
// Portal response codes
20+
#define GS_RESPONSE_SUCCESS 0
21+
#define GS_RESPONSE_CANCELLED 1
22+
#define GS_RESPONSE_ERROR 2
23+
24+
typedef struct gs_shortcut {
25+
char *id;
26+
char *description;
27+
char *trigger_description; // human-readable, e.g. "Super+K"
28+
uint32_t modifiers; // XKB modifier mask (WLR_MODIFIER_*)
29+
xkb_keysym_t keysym;
30+
bool has_trigger;
31+
32+
struct gs_session *session;
33+
struct wl_list link; // gs_session.shortcuts
34+
} gs_shortcut_t;
35+
36+
typedef struct gs_session {
37+
char *app_id;
38+
char *session_path;
39+
char *request_path;
40+
bool destroyed;
41+
struct wl_list shortcuts; // gs_shortcut.link
42+
struct wl_list link; // gs_state.sessions
43+
struct sd_bus_slot *session_slot;
44+
struct sd_bus_slot *request_slot;
45+
} gs_session_t;
46+
47+
typedef struct gs_state {
48+
struct sd_bus *bus;
49+
struct sd_bus_slot *main_slot;
50+
struct sd_bus_slot *session_fallback_slot;
51+
struct sd_bus_slot *request_fallback_slot;
52+
struct wl_event_source *bus_event_source;
53+
struct wl_list sessions; // gs_session.link
54+
bool initialized;
55+
} gs_state_t;
56+
57+
void global_shortcuts_init(void);
58+
void global_shortcuts_fini(void);
59+
bool global_shortcuts_handle_key(uint32_t modifiers, uint32_t keycode, const xkb_keysym_t *syms,
60+
int nsyms, uint32_t state, uint32_t time_msec);

meson.build

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ libs = [
3434
wayland_protos,
3535
]
3636

37+
libsystemd = dependency('libsystemd', required: false)
38+
if libsystemd.found()
39+
libs += libsystemd
40+
add_project_arguments('-DHAVE_SYSTEMD=1', language: 'c')
41+
endif
42+
3743
if host_machine.system() == 'freebsd'
3844
libs += declare_dependency(link_args: ['/usr/local/lib/libinotify.so', '-lpthread'])
3945
endif
@@ -96,6 +102,7 @@ executable(
96102
'src' / 'effects_gles2.c',
97103
'src' / 'effects_vk.c',
98104
'src' / 'gesture.c',
105+
'src' / 'global_shortcuts.c',
99106
'src' / 'idle.c',
100107
'src' / 'idle_power.c',
101108
'src' / 'ipc.c',

src/cursor.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,12 @@ static void apply_leaf_positions(desktop_t *d) {
198198

199199
unsigned int bw = effective_border_width(d);
200200
if (bw != 0) {
201-
struct wlr_box geo = {0, 0, r.width, r.height};
201+
struct wlr_box geo = {
202+
0,
203+
0,
204+
r.width,
205+
r.height
206+
};
202207
update_borders(client_border_tree(n->client), client_border_rects(n->client), geo, bw);
203208
update_border_colors(n->client);
204209
if (n->client->border_radius > 0.0f) {

0 commit comments

Comments
 (0)