From e9de88221f10810b3d1b9bef0a908a2810002dd8 Mon Sep 17 00:00:00 2001 From: Pieter van der Heijden Date: Wed, 11 Mar 2026 21:41:06 +0100 Subject: [PATCH] Clear macOS dock badge on keypress and mouse click The dock badge set by macos_dock_badge_on_bell is currently only cleared when the app transitions from inactive to active via NSApplicationDidBecomeActiveNotification. This means if a bell occurs while kitty is already the active app (e.g. in a background tmux pane or non-focused kitty tab), the badge persists until the user switches away and back. Clear the badge on any user interaction (keypress or mouse click) so it is dismissed as soon as the user engages with kitty, regardless of whether kitty was already active. --- kitty/cocoa_window.h | 1 + kitty/cocoa_window.m | 8 ++++++++ kitty/glfw.c | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/kitty/cocoa_window.h b/kitty/cocoa_window.h index 1779de9e2..773d576c7 100644 --- a/kitty/cocoa_window.h +++ b/kitty/cocoa_window.h @@ -67,3 +67,4 @@ void get_cocoa_key_equivalent(uint32_t, int, char *key, size_t key_sz, int*); void set_cocoa_pending_action(CocoaPendingAction action, const char*); void cocoa_report_live_notifications(const char* ident); void cocoa_set_dock_badge(const char *label); +void cocoa_clear_dock_badge_if_set(void); diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index ce7a7c58c..50249f785 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -1341,15 +1341,23 @@ - (void)drawRect:(NSRect)dirtyRect { // Dock badge {{{ +static bool dock_badge_is_set = false; + void cocoa_set_dock_badge(const char *label) { @autoreleasepool { NSDockTile *dockTile = [NSApp dockTile]; [dockTile setBadgeLabel:label ? @(label) : nil]; [dockTile display]; + dock_badge_is_set = (label != NULL); } } +void +cocoa_clear_dock_badge_if_set(void) { + if (dock_badge_is_set) cocoa_set_dock_badge(NULL); +} + // }}} static PyMethodDef module_methods[] = { diff --git a/kitty/glfw.c b/kitty/glfw.c index 7daa39f3c..6e9924b5b 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -518,6 +518,9 @@ update_modifier_state_on_modifier_key_event(GLFWkeyevent *ev, int key_modifier, static void key_callback(GLFWwindow *w, GLFWkeyevent *ev) { if (!set_callback_window(w)) return; +#ifdef __APPLE__ + cocoa_clear_dock_badge_if_set(); +#endif #ifndef __APPLE__ bool is_left; int key_modifier = key_to_modifier(ev->key, &is_left); @@ -554,6 +557,9 @@ cursor_enter_callback(GLFWwindow *w, int entered) { static void mouse_button_callback(GLFWwindow *w, int button, int action, int mods) { if (!set_callback_window(w)) return; +#ifdef __APPLE__ + cocoa_clear_dock_badge_if_set(); +#endif monotonic_t now = monotonic(); cursor_active_callback(now); mods_at_last_key_or_button_event = mods;