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.
This commit is contained in:
Pieter van der Heijden 2026-03-11 21:41:06 +01:00
parent a1e02c8858
commit e9de88221f
No known key found for this signature in database
GPG key ID: 995311A374B2E1E6
3 changed files with 15 additions and 0 deletions

View file

@ -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);

View file

@ -1341,15 +1341,23 @@ cocoa_show_progress_bar_on_dock_icon(PyObject *self UNUSED, PyObject *args) {
// 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[] = {

View file

@ -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;