From 7d4d978d9746e328e587f7f97a9b2eb4e3f94da8 Mon Sep 17 00:00:00 2001 From: Alex Lau Date: Mon, 23 Apr 2018 21:55:05 -0700 Subject: [PATCH] Add macos_hide_from_tasks option --- kitty/cocoa_window.m | 7 +++++++ kitty/config.py | 1 + kitty/kitty.conf | 3 +++ kitty/main.py | 4 ++++ 4 files changed, 15 insertions(+) diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index e9bcd56fb..f4165e4ed 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -228,6 +228,12 @@ macos_change_titlebar_color(PyObject *self UNUSED, PyObject *val) { Py_RETURN_NONE; } +static PyObject* +macos_set_hide_from_tasks(PyObject *self UNUSED, PyObject *val UNUSED) { + [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory]; + Py_RETURN_NONE; +} + void cocoa_set_titlebar_color(void *w) { @@ -260,6 +266,7 @@ static PyMethodDef module_methods[] = { {"cocoa_get_lang", (PyCFunction)cocoa_get_lang, METH_NOARGS, ""}, {"cwd_of_process", (PyCFunction)cwd_of_process, METH_O, ""}, {"macos_change_titlebar_color", (PyCFunction)macos_change_titlebar_color, METH_O, ""}, + {"macos_set_hide_from_tasks", (PyCFunction)macos_set_hide_from_tasks, METH_NOARGS, ""}, {NULL, NULL, 0, NULL} /* Sentinel */ }; diff --git a/kitty/config.py b/kitty/config.py index b56e4e25f..1bf2e39c5 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -318,6 +318,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/kitty.conf b/kitty/kitty.conf index bc2af1da5..fc35b15f4 100644 --- a/kitty/kitty.conf +++ b/kitty/kitty.conf @@ -499,4 +499,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 yes # }}} diff --git a/kitty/main.py b/kitty/main.py index 85128b55b..009cc4a4d 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -45,6 +45,10 @@ def run_app(opts, args): with cached_values_for('main') as cached_values: w, h = initial_window_size(opts, cached_values) window_id = create_os_window(w, h, appname, args.name or args.cls or appname, args.cls or appname, load_all_shaders) + if is_macos and opts.macos_hide_from_tasks: + from .fast_data_types import macos_set_hide_from_tasks + # This needs to be done after creating the OS window as glfw sets the activation policy as well. + macos_set_hide_from_tasks() startup_ctx = init_startup_notification(window_id) show_window(window_id) if not is_wayland and not is_macos: # no window icons on wayland