Better fix for kitty not getting key events when launched via a symlink on macOS
Avoids the overhead of checking for a symlink and re-execing. Apparently all that was needed was setting the correct activation policy, glfw is supposed to do this but does it only if the menubar hint is on, which we turn off as we create our own menubar.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) { \
|
||||
|
||||
23
launcher.c
23
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 <sys/sysctl.h>
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user