Set Cocoa window number
This commit is contained in:
parent
1bb6242020
commit
1fd338cc6c
3 changed files with 36 additions and 2 deletions
|
|
@ -390,6 +390,12 @@ - (void)openFilesFromPasteboard:(NSPasteboard *)pasteboard type:(int)type {
|
|||
[window makeKeyWindow];
|
||||
}
|
||||
|
||||
long
|
||||
cocoa_window_number(void *w) {
|
||||
NSWindow *window = (NSWindow*)w;
|
||||
return [window windowNumber];
|
||||
}
|
||||
|
||||
size_t
|
||||
cocoa_get_workspace_ids(void *w, size_t *workspace_ids, size_t array_sz) {
|
||||
NSWindow *window = (NSWindow*)w;
|
||||
|
|
|
|||
22
kitty/glfw.c
22
kitty/glfw.c
|
|
@ -11,6 +11,7 @@
|
|||
#include "glfw-wrapper.h"
|
||||
extern bool cocoa_make_window_resizable(void *w, bool);
|
||||
extern void cocoa_focus_window(void *w);
|
||||
extern long cocoa_window_number(void *w);
|
||||
extern void cocoa_create_global_menu(void);
|
||||
extern void cocoa_hide_window_title(void *w);
|
||||
extern void cocoa_hide_titlebar(void *w);
|
||||
|
|
@ -1040,6 +1041,24 @@ x11_window_id(PyObject UNUSED *self, PyObject *os_wid) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
static PyObject*
|
||||
cocoa_window_id(PyObject UNUSED *self, PyObject *os_wid) {
|
||||
if (glfwGetCocoaWindow) {
|
||||
id_type os_window_id = PyLong_AsUnsignedLongLong(os_wid);
|
||||
for (size_t i = 0; i < global_state.num_os_windows; i++) {
|
||||
OSWindow *w = global_state.os_windows + i;
|
||||
if (w->id == os_window_id) {
|
||||
return Py_BuildValue("l", (long)cocoa_window_number(glfwGetCocoaWindow(w->handle)));
|
||||
}
|
||||
}
|
||||
}
|
||||
else { PyErr_SetString(PyExc_RuntimeError, "Failed to load glfwGetCocoaWindow"); return NULL; }
|
||||
PyErr_SetString(PyExc_ValueError, "No OSWindow with the specified id found");
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
static PyObject*
|
||||
get_primary_selection(PYNOARG) {
|
||||
if (glfwGetPrimarySelectionString) {
|
||||
|
|
@ -1220,6 +1239,9 @@ static PyMethodDef module_methods[] = {
|
|||
METHODB(set_primary_selection, METH_VARARGS),
|
||||
#ifndef __APPLE__
|
||||
METHODB(dbus_send_notification, METH_VARARGS),
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
METHODB(cocoa_window_id, METH_O),
|
||||
#endif
|
||||
{"glfw_init", (PyCFunction)glfw_init, METH_VARARGS, ""},
|
||||
{"glfw_terminate", (PyCFunction)glfw_terminate, METH_NOARGS, ""},
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
from .cli_stub import CLIOptions
|
||||
from .constants import appname, is_macos, is_wayland
|
||||
from .fast_data_types import (
|
||||
add_tab, attach_window, detach_window, get_boss, mark_tab_bar_dirty,
|
||||
add_tab, attach_window, cocoa_window_id, detach_window, get_boss, mark_tab_bar_dirty,
|
||||
next_window_id, remove_tab, remove_window, ring_bell, set_active_tab,
|
||||
set_active_window, swap_tabs, sync_os_window_title, x11_window_id
|
||||
)
|
||||
|
|
@ -283,7 +283,13 @@ def launch_child(
|
|||
if env:
|
||||
fenv.update(env)
|
||||
fenv['KITTY_WINDOW_ID'] = str(next_window_id())
|
||||
if not is_macos and not is_wayland():
|
||||
if is_macos:
|
||||
try:
|
||||
fenv['WINDOWID'] = str(cocoa_window_id(self.os_window_id))
|
||||
except Exception:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
elif not is_wayland():
|
||||
try:
|
||||
fenv['WINDOWID'] = str(x11_window_id(self.os_window_id))
|
||||
except Exception:
|
||||
|
|
|
|||
Loading…
Reference in a new issue