diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index e9bcd56fb..713d228bb 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -228,6 +228,11 @@ macos_change_titlebar_color(PyObject *self UNUSED, PyObject *val) { Py_RETURN_NONE; } +void +cocoa_set_hide_from_tasks(void) { + [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory]; +} + void cocoa_set_titlebar_color(void *w) { diff --git a/kitty/config.py b/kitty/config.py index 1eb0c6307..31ab292db 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -321,6 +321,7 @@ type_map = { 'initial_window_width': positive_int, 'initial_window_height': positive_int, 'macos_hide_titlebar': to_bool, + 'macos_hide_from_tasks': to_bool, 'macos_option_as_alt': to_bool, 'macos_titlebar_color': macos_titlebar_color, 'box_drawing_scale': box_drawing_scale, diff --git a/kitty/glfw.c b/kitty/glfw.c index 1e6190bd4..0bca63004 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -9,6 +9,7 @@ #include "glfw-wrapper.h" extern bool cocoa_make_window_resizable(void *w); extern void cocoa_create_global_menu(void); +extern void cocoa_set_hide_from_tasks(void); extern void cocoa_set_titlebar_color(void *w); #if GLFW_KEY_LAST >= MAX_KEY_COUNT @@ -375,6 +376,8 @@ create_os_window(PyObject UNUSED *self, PyObject *args) { #ifdef __APPLE__ cocoa_create_global_menu(); if (OPT(macos_option_as_alt)) glfwSetCocoaTextInputFilter(glfw_window, filter_option); + // This needs to be done only after the first window has been created, because glfw only sets the activation policy once upon initialization. + if (OPT(macos_hide_from_tasks)) cocoa_set_hide_from_tasks(); #endif is_first_window = false; } diff --git a/kitty/kitty.conf b/kitty/kitty.conf index 7020217db..e54baa3bf 100644 --- a/kitty/kitty.conf +++ b/kitty/kitty.conf @@ -507,4 +507,7 @@ macos_hide_titlebar no # break any Alt+key keyboard shortcuts in your terminal programs, but you # can use the macOS unicode input technique. macos_option_as_alt yes + +# Hide the kitty window from running tasks (alt-tab) on macOS. +macos_hide_from_tasks no # }}} diff --git a/kitty/state.c b/kitty/state.c index ce8d15724..ca76723ef 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -372,6 +372,7 @@ PYWRAP1(set_options) { S(close_on_child_death, PyObject_IsTrue); S(macos_option_as_alt, PyObject_IsTrue); S(macos_hide_titlebar, PyObject_IsTrue); + S(macos_hide_from_tasks, PyObject_IsTrue); PyObject *chars = PyObject_GetAttrString(opts, "select_by_word_characters"); if (chars == NULL) return NULL; diff --git a/kitty/state.h b/kitty/state.h index 83feb12ea..710914af9 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -23,7 +23,7 @@ typedef struct { color_type url_color, background, active_border_color, inactive_border_color; double repaint_delay, input_delay; bool focus_follows_mouse; - bool macos_option_as_alt, macos_hide_titlebar; + bool macos_option_as_alt, macos_hide_titlebar, macos_hide_from_tasks; int adjust_line_height_px, adjust_column_width_px; float adjust_line_height_frac, adjust_column_width_frac; float background_opacity;