Respond to clicks on user notifications via DBus
This commit is contained in:
parent
27887ada45
commit
5da123c632
@ -1012,8 +1012,8 @@ class Boss:
|
||||
notification_activated()
|
||||
|
||||
def dbus_notification_callback(self, activated, *args):
|
||||
from .notify import dbus_notification_created
|
||||
from .notify import dbus_notification_created, dbus_notification_activated
|
||||
if activated:
|
||||
pass
|
||||
dbus_notification_activated(*args)
|
||||
else:
|
||||
dbus_notification_created(*args)
|
||||
|
||||
10
kitty/glfw.c
10
kitty/glfw.c
@ -669,6 +669,12 @@ error_callback(int error, const char* description) {
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
dbus_user_notification_activated(uint32_t notification_id, const char* action) {
|
||||
unsigned long nid = notification_id;
|
||||
call_boss(dbus_notification_callback, "Oks", Py_True, nid, action);
|
||||
}
|
||||
|
||||
PyObject*
|
||||
glfw_init(PyObject UNUSED *self, PyObject *args) {
|
||||
const char* path;
|
||||
@ -685,6 +691,10 @@ glfw_init(PyObject UNUSED *self, PyObject *args) {
|
||||
#ifdef __APPLE__
|
||||
glfwInitHint(GLFW_COCOA_CHDIR_RESOURCES, 0);
|
||||
glfwInitHint(GLFW_COCOA_MENUBAR, 0);
|
||||
#else
|
||||
if (glfwDBusSetUserNotificationHandler) {
|
||||
glfwDBusSetUserNotificationHandler(dbus_user_notification_activated);
|
||||
}
|
||||
#endif
|
||||
PyObject *ans = glfwInit() ? Py_True: Py_False;
|
||||
if (ans == Py_True) {
|
||||
|
||||
@ -23,15 +23,22 @@ if is_macos:
|
||||
else:
|
||||
|
||||
from .fast_data_types import dbus_send_notification
|
||||
from .constants import get_boss
|
||||
|
||||
alloc_map = {}
|
||||
identifier_map = {}
|
||||
|
||||
def dbus_notification_created(alloc_id, notification_id):
|
||||
identifier = alloc_map.get(alloc_id)
|
||||
identifier = alloc_map.pop(alloc_id, None)
|
||||
if identifier is not None:
|
||||
identifier_map[identifier] = notification_id
|
||||
|
||||
def dbus_notification_activated(notification_id, action):
|
||||
rmap = {v: k for k, v in identifier_map.items()}
|
||||
identifier = rmap.get(notification_id)
|
||||
if identifier is not None:
|
||||
get_boss().notification_activated(identifier)
|
||||
|
||||
def notify(
|
||||
title,
|
||||
body,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user