|
| 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); |
0 commit comments