From 4c9a6ed56c8dbecc245740e89734b110d7077383 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 3 Feb 2019 13:53:26 +0530 Subject: [PATCH] Set a default action name on the dbus notification --- glfw/glfw.py | 2 +- glfw/linux_notify.c | 7 ++++++- glfw/linux_notify.h | 2 +- glfw/wl_window.c | 4 ++-- glfw/x11_window.c | 4 ++-- kitty/glfw-wrapper.h | 2 +- kitty/glfw.c | 6 +++--- kitty/notify.py | 2 +- 8 files changed, 17 insertions(+), 12 deletions(-) diff --git a/glfw/glfw.py b/glfw/glfw.py index e240c51ad..7dc31eb4c 100755 --- a/glfw/glfw.py +++ b/glfw/glfw.py @@ -179,7 +179,7 @@ def generate_wrappers(glfw_header): int glfwGetXKBScancode(const char* key_name, int case_sensitive) void glfwRequestWaylandFrameEvent(GLFWwindow *handle, unsigned long long id, GLFWwaylandframecallbackfunc callback) unsigned long long glfwDBusUserNotify(const char *app_name, const char* icon, const char *summary, const char *body, \ -int32_t timeout, GLFWDBusnotificationcreatedfun callback, void *data) +const char *action_text, int32_t timeout, GLFWDBusnotificationcreatedfun callback, void *data) void glfwDBusSetUserNotificationHandler(GLFWDBusnotificationactivatedfun handler) '''.splitlines(): if line: diff --git a/glfw/linux_notify.c b/glfw/linux_notify.c index ac43f1a34..ff2484420 100644 --- a/glfw/linux_notify.c +++ b/glfw/linux_notify.c @@ -64,7 +64,7 @@ message_handler(DBusConnection *conn, DBusMessage *msg, void *user_data) { } notification_id_type -glfw_dbus_send_user_notification(const char *app_name, const char* icon, const char *summary, const char *body, int32_t timeout, GLFWDBusnotificationcreatedfun callback, void *user_data) { +glfw_dbus_send_user_notification(const char *app_name, const char* icon, const char *summary, const char *body, const char* action_name, int32_t timeout, GLFWDBusnotificationcreatedfun callback, void *user_data) { DBusConnection *session_bus = glfw_dbus_session_bus(); static DBusConnection *added_signal_match = NULL; if (!session_bus) return 0; @@ -91,6 +91,11 @@ glfw_dbus_send_user_notification(const char *app_name, const char* icon, const c APPEND(DBUS_TYPE_STRING, &summary) APPEND(DBUS_TYPE_STRING, &body) if (!dbus_message_iter_open_container(&args, DBUS_TYPE_ARRAY, "s", &array)) OOMMSG; + if (action_name) { + static const char* default_action = "default"; + dbus_message_iter_append_basic(&array, DBUS_TYPE_STRING, &default_action); + dbus_message_iter_append_basic(&array, DBUS_TYPE_STRING, &action_name); + } if (!dbus_message_iter_close_container(&args, &array)) OOMMSG; if (!dbus_message_iter_open_container(&args, DBUS_TYPE_ARRAY, "{sv}", &array)) OOMMSG; if (!dbus_message_iter_close_container(&args, &array)) OOMMSG; diff --git a/glfw/linux_notify.h b/glfw/linux_notify.h index 03de5f94c..90d2f53a4 100644 --- a/glfw/linux_notify.h +++ b/glfw/linux_notify.h @@ -14,6 +14,6 @@ typedef unsigned long long notification_id_type; typedef void (*GLFWDBusnotificationcreatedfun)(notification_id_type, uint32_t, void*); typedef void (*GLFWDBusnotificationactivatedfun)(uint32_t, const char*); notification_id_type -glfw_dbus_send_user_notification(const char *app_name, const char* icon, const char *summary, const char *body, int32_t timeout, GLFWDBusnotificationcreatedfun, void*); +glfw_dbus_send_user_notification(const char *app_name, const char* icon, const char *summary, const char *body, const char *action_name, int32_t timeout, GLFWDBusnotificationcreatedfun, void*); void glfw_dbus_set_user_notification_activated_handler(GLFWDBusnotificationactivatedfun handler); diff --git a/glfw/wl_window.c b/glfw/wl_window.c index b38dc6cff..8d2613079 100644 --- a/glfw/wl_window.c +++ b/glfw/wl_window.c @@ -2132,8 +2132,8 @@ GLFWAPI void glfwRequestWaylandFrameEvent(GLFWwindow *handle, unsigned long long } } -GLFWAPI unsigned long long glfwDBusUserNotify(const char *app_name, const char* icon, const char *summary, const char *body, int32_t timeout, GLFWDBusnotificationcreatedfun callback, void *data) { - return glfw_dbus_send_user_notification(app_name, icon, summary, body, timeout, callback, data); +GLFWAPI unsigned long long glfwDBusUserNotify(const char *app_name, const char* icon, const char *summary, const char *body, const char *action_name, int32_t timeout, GLFWDBusnotificationcreatedfun callback, void *data) { + return glfw_dbus_send_user_notification(app_name, icon, summary, body, action_name, timeout, callback, data); } GLFWAPI void glfwDBusSetUserNotificationHandler(GLFWDBusnotificationactivatedfun handler) { diff --git a/glfw/x11_window.c b/glfw/x11_window.c index eac25c88b..8258fc608 100644 --- a/glfw/x11_window.c +++ b/glfw/x11_window.c @@ -2895,8 +2895,8 @@ GLFWAPI int glfwGetXKBScancode(const char* keyName, GLFWbool caseSensitive) { return glfw_xkb_keysym_from_name(keyName, caseSensitive); } -GLFWAPI unsigned long long glfwDBusUserNotify(const char *app_name, const char* icon, const char *summary, const char *body, int32_t timeout, GLFWDBusnotificationcreatedfun callback, void *data) { - return glfw_dbus_send_user_notification(app_name, icon, summary, body, timeout, callback, data); +GLFWAPI unsigned long long glfwDBusUserNotify(const char *app_name, const char* icon, const char *summary, const char *body, const char *action_name, int32_t timeout, GLFWDBusnotificationcreatedfun callback, void *data) { + return glfw_dbus_send_user_notification(app_name, icon, summary, body, action_name, timeout, callback, data); } GLFWAPI void glfwDBusSetUserNotificationHandler(GLFWDBusnotificationactivatedfun handler) { diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index f25415018..eaf03ab02 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -1909,7 +1909,7 @@ typedef void (*glfwRequestWaylandFrameEvent_func)(GLFWwindow*, unsigned long lon glfwRequestWaylandFrameEvent_func glfwRequestWaylandFrameEvent_impl; #define glfwRequestWaylandFrameEvent glfwRequestWaylandFrameEvent_impl -typedef unsigned long long (*glfwDBusUserNotify_func)(const char*, const char*, const char*, const char*, int32_t, GLFWDBusnotificationcreatedfun, void*); +typedef unsigned long long (*glfwDBusUserNotify_func)(const char*, const char*, const char*, const char*, const char*, int32_t, GLFWDBusnotificationcreatedfun, void*); glfwDBusUserNotify_func glfwDBusUserNotify_impl; #define glfwDBusUserNotify glfwDBusUserNotify_impl diff --git a/kitty/glfw.c b/kitty/glfw.c index db562a274..2fefd5468 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -1037,14 +1037,14 @@ dbus_notification_created_callback(unsigned long long notification_id, uint32_t static PyObject* dbus_send_notification(PyObject *self UNUSED, PyObject *args) { - char *app_name, *icon, *summary, *body; + char *app_name, *icon, *summary, *body, *action_name; int timeout = -1; - if (!PyArg_ParseTuple(args, "ssss|i", &app_name, &icon, &summary, &body, &timeout)) return NULL; + if (!PyArg_ParseTuple(args, "sssss|i", &app_name, &icon, &summary, &body, &action_name, &timeout)) return NULL; if (!glfwDBusUserNotify) { PyErr_SetString(PyExc_RuntimeError, "Failed to load glfwDBusUserNotify, did you call glfw_init?"); return NULL; } - unsigned long long notification_id = glfwDBusUserNotify(app_name, icon, summary, body, timeout, dbus_notification_created_callback, NULL); + unsigned long long notification_id = glfwDBusUserNotify(app_name, icon, summary, body, action_name, timeout, dbus_notification_created_callback, NULL); return PyLong_FromUnsignedLongLong(notification_id); } #endif diff --git a/kitty/notify.py b/kitty/notify.py index 8850df640..49cebd35b 100644 --- a/kitty/notify.py +++ b/kitty/notify.py @@ -42,6 +42,6 @@ else: ): if icon is True: icon = logo_png_file - alloc_id = dbus_send_notification(application, icon, title, body, timeout) + alloc_id = dbus_send_notification(application, icon, title, body, 'Click to see changes', timeout) if alloc_id and identifier is not None: alloc_map[alloc_id] = identifier