diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index d11404591..812d99727 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -425,8 +425,8 @@ cocoa_cursor_blink_interval(void) { } void -cocoa_set_hide_from_tasks(void) { - [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory]; +cocoa_set_activation_policy(bool hide_from_tasks) { + [NSApp setActivationPolicy:(hide_from_tasks ? NSApplicationActivationPolicyAccessory : NSApplicationActivationPolicyRegular)]; } void diff --git a/kitty/glfw.c b/kitty/glfw.c index 1944f1765..436701649 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -12,7 +12,7 @@ extern bool cocoa_make_window_resizable(void *w, bool); extern void cocoa_focus_window(void *w); extern void cocoa_create_global_menu(void); -extern void cocoa_set_hide_from_tasks(void); +extern void cocoa_set_activation_policy(bool); extern void cocoa_set_titlebar_color(void *w, color_type color); extern bool cocoa_alt_option_key_pressed(unsigned long); extern size_t cocoa_get_workspace_ids(void *w, size_t *workspace_ids, size_t array_sz); @@ -498,6 +498,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args) { glfwWindowHint(GLFW_DEPTH_BITS, 0); glfwWindowHint(GLFW_STENCIL_BITS, 0); #ifdef __APPLE__ + cocoa_set_activation_policy(OPT(macos_hide_from_tasks)); glfwWindowHint(GLFW_COCOA_GRAPHICS_SWITCHING, true); glfwSetApplicationShouldHandleReopen(on_application_reopen); if (OPT(hide_window_decorations)) glfwWindowHint(GLFW_DECORATED, false); @@ -575,8 +576,6 @@ create_os_window(PyObject UNUSED *self, PyObject *args) { Py_DECREF(ret); #ifdef __APPLE__ cocoa_create_global_menu(); - // 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 #define CC(dest, shape) {\ if (!dest##_cursor) { \ diff --git a/launcher.c b/launcher.c index 171d7555a..253bcc739 100644 --- a/launcher.c +++ b/launcher.c @@ -112,16 +112,11 @@ static int run_embedded(const char* exe_dir_, const char *libpath, int argc, wch // read_exe_path() {{{ #ifdef __APPLE__ static inline bool -read_exe_path(char *exe, size_t buf_sz, bool *is_symlink) { +read_exe_path(char *exe, size_t buf_sz) { (void)buf_sz; - *is_symlink = false; uint32_t size = PATH_MAX; char apple[PATH_MAX+1] = {0}; if (_NSGetExecutablePath(apple, &size) != 0) { fprintf(stderr, "Failed to get path to executable\n"); return false; } - struct stat buf; - if (lstat(apple, &buf) == 0) { - *is_symlink = S_ISLNK(buf.st_mode); - } if (!safe_realpath(apple, exe, buf_sz)) { fprintf(stderr, "realpath() failed on the executable's path\n"); return false; } return true; } @@ -130,8 +125,7 @@ read_exe_path(char *exe, size_t buf_sz, bool *is_symlink) { #include static inline bool -read_exe_path(char *exe, size_t buf_sz, bool *is_symlink) { - *is_symlink = false; +read_exe_path(char *exe, size_t buf_sz) { int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; size_t length = buf_sz; int error = sysctl(name, 4, exe, &length, NULL, 0); @@ -144,8 +138,7 @@ read_exe_path(char *exe, size_t buf_sz, bool *is_symlink) { #elif defined(__NetBSD__) static inline bool -read_exe_path(char *exe, size_t buf_sz, bool *is_symlink) { - *is_symlink = false; +read_exe_path(char *exe, size_t buf_sz) { if (!safe_realpath("/proc/curproc/exe", exe, buf_sz)) { fprintf(stderr, "Failed to read /proc/curproc/exe\n"); return false; } return true; } @@ -153,8 +146,7 @@ read_exe_path(char *exe, size_t buf_sz, bool *is_symlink) { #else static inline bool -read_exe_path(char *exe, size_t buf_sz, bool *is_symlink) { - *is_symlink = false; +read_exe_path(char *exe, size_t buf_sz) { if (!safe_realpath("/proc/self/exe", exe, buf_sz)) { fprintf(stderr, "Failed to read /proc/self/exe\n"); return false; } return true; } @@ -162,12 +154,7 @@ read_exe_path(char *exe, size_t buf_sz, bool *is_symlink) { int main(int argc, char *argv[]) { char exe[PATH_MAX+1] = {0}; - bool is_symlink = false; - if (!read_exe_path(exe, sizeof(exe), &is_symlink)) return 1; -#ifdef __APPLE__ - // Cocoa has issues with bundle executables launched via symlinks - if (is_symlink) execv(exe, argv); -#endif + if (!read_exe_path(exe, sizeof(exe))) return 1; char *exe_dir = dirname(exe); int num, num_args, i, ret=0;