mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-25 17:52:02 +02:00
Drop the dependency on libnotify for notifications on Linux
This commit is contained in:
@@ -1010,3 +1010,10 @@ class Boss:
|
|||||||
if identifier == 'new-version':
|
if identifier == 'new-version':
|
||||||
from .update_check import notification_activated
|
from .update_check import notification_activated
|
||||||
notification_activated()
|
notification_activated()
|
||||||
|
|
||||||
|
def dbus_notification_callback(self, activated, *args):
|
||||||
|
from .notify import dbus_notification_created
|
||||||
|
if activated:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
dbus_notification_created(*args)
|
||||||
|
|||||||
23
kitty/glfw.c
23
kitty/glfw.c
@@ -1027,6 +1027,28 @@ wayland_request_frame_render(OSWindow *w) {
|
|||||||
w->wayland_render_state = RENDER_FRAME_REQUESTED;
|
w->wayland_render_state = RENDER_FRAME_REQUESTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __APPLE__
|
||||||
|
|
||||||
|
void
|
||||||
|
dbus_notification_created_callback(unsigned long long notification_id, uint32_t new_notification_id, void* data UNUSED) {
|
||||||
|
unsigned long new_id = new_notification_id;
|
||||||
|
call_boss(dbus_notification_callback, "OKk", Py_False, notification_id, new_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject*
|
||||||
|
dbus_send_notification(PyObject *self UNUSED, PyObject *args) {
|
||||||
|
char *app_name, *icon, *summary, *body;
|
||||||
|
int timeout = -1;
|
||||||
|
if (!PyArg_ParseTuple(args, "ssss|i", &app_name, &icon, &summary, &body, &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);
|
||||||
|
return PyLong_FromUnsignedLongLong(notification_id);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Boilerplate {{{
|
// Boilerplate {{{
|
||||||
|
|
||||||
static PyMethodDef module_methods[] = {
|
static PyMethodDef module_methods[] = {
|
||||||
@@ -1048,6 +1070,7 @@ static PyMethodDef module_methods[] = {
|
|||||||
METHODB(x11_window_id, METH_O),
|
METHODB(x11_window_id, METH_O),
|
||||||
METHODB(set_primary_selection, METH_VARARGS),
|
METHODB(set_primary_selection, METH_VARARGS),
|
||||||
METHODB(glfw_poll_events, METH_NOARGS),
|
METHODB(glfw_poll_events, METH_NOARGS),
|
||||||
|
METHODB(dbus_send_notification, METH_VARARGS),
|
||||||
{"glfw_init", (PyCFunction)glfw_init, METH_VARARGS, ""},
|
{"glfw_init", (PyCFunction)glfw_init, METH_VARARGS, ""},
|
||||||
{"glfw_terminate", (PyCFunction)glfw_terminate, METH_NOARGS, ""},
|
{"glfw_terminate", (PyCFunction)glfw_terminate, METH_NOARGS, ""},
|
||||||
{"glfw_post_empty_event", (PyCFunction)glfw_post_empty_event, METH_NOARGS, ""},
|
{"glfw_post_empty_event", (PyCFunction)glfw_post_empty_event, METH_NOARGS, ""},
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
# License: GPLv3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPLv3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
import subprocess
|
|
||||||
|
|
||||||
from .constants import is_macos, logo_png_file
|
from .constants import is_macos, logo_png_file
|
||||||
|
|
||||||
@@ -23,9 +22,15 @@ if is_macos:
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
# libnotify depends on GTK, so we are not using it, instead
|
from .fast_data_types import dbus_send_notification
|
||||||
# use the command line notify-send wrapper it provides
|
|
||||||
# May want to just implement this in glfw using DBUS
|
alloc_map = {}
|
||||||
|
identifier_map = {}
|
||||||
|
|
||||||
|
def dbus_notification_created(alloc_id, notification_id):
|
||||||
|
identifier = alloc_map.get(alloc_id)
|
||||||
|
if identifier is not None:
|
||||||
|
identifier_map[identifier] = notification_id
|
||||||
|
|
||||||
def notify(
|
def notify(
|
||||||
title,
|
title,
|
||||||
@@ -35,16 +40,8 @@ else:
|
|||||||
icon=True,
|
icon=True,
|
||||||
identifier=None
|
identifier=None
|
||||||
):
|
):
|
||||||
cmd = ['notify-send', '-a', application]
|
|
||||||
if timeout > -1:
|
|
||||||
cmd.append('-t'), cmd.append(str(timeout))
|
|
||||||
if icon is True:
|
if icon is True:
|
||||||
icon = logo_png_file
|
icon = logo_png_file
|
||||||
if icon:
|
alloc_id = dbus_send_notification(application, icon, title, body, timeout)
|
||||||
cmd.extend(['-i', icon])
|
if alloc_id and identifier is not None:
|
||||||
subprocess.Popen(
|
alloc_map[alloc_id] = identifier
|
||||||
cmd + [title, body],
|
|
||||||
stdout=subprocess.DEVNULL,
|
|
||||||
stderr=subprocess.DEVNULL,
|
|
||||||
stdin=subprocess.DEVNULL,
|
|
||||||
)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user