Cleanup change_os_window_state
This commit is contained in:
+1
-4
@@ -387,10 +387,7 @@ class Boss:
|
||||
focused_os_window = wid
|
||||
os_window_id = None
|
||||
if self.args.start_as != 'normal':
|
||||
if self.args.start_as == 'fullscreen':
|
||||
self.toggle_fullscreen()
|
||||
else:
|
||||
change_os_window_state(self.args.start_as)
|
||||
change_os_window_state(self.args.start_as, wid)
|
||||
if focused_os_window > 0:
|
||||
focus_os_window(focused_os_window, True, token)
|
||||
elif token and is_wayland() and wid:
|
||||
|
||||
@@ -818,7 +818,7 @@ def cocoa_set_menubar_title(title: str) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def change_os_window_state(state: str) -> None:
|
||||
def change_os_window_state(state: str, os_window_id: int = 0) -> None:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
+14
-17
@@ -1333,15 +1333,6 @@ get_content_scale_for_window(PYNOARG) {
|
||||
return Py_BuildValue("ff", xscale, yscale);
|
||||
}
|
||||
|
||||
static OSWindow*
|
||||
find_os_window(id_type os_window_id) {
|
||||
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 w;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
activation_token_callback(GLFWwindow *window UNUSED, const char *token, void *data) {
|
||||
if (!token || !token[0]) {
|
||||
@@ -1366,7 +1357,7 @@ static PyObject*
|
||||
toggle_fullscreen(PyObject UNUSED *self, PyObject *args) {
|
||||
id_type os_window_id = 0;
|
||||
if (!PyArg_ParseTuple(args, "|K", &os_window_id)) return NULL;
|
||||
OSWindow *w = os_window_id ? find_os_window(os_window_id) : current_os_window();
|
||||
OSWindow *w = os_window_id ? os_window_for_id(os_window_id) : current_os_window();
|
||||
if (!w) Py_RETURN_NONE;
|
||||
if (toggle_fullscreen_for_os_window(w)) { Py_RETURN_TRUE; }
|
||||
Py_RETURN_FALSE;
|
||||
@@ -1376,7 +1367,7 @@ static PyObject*
|
||||
toggle_maximized(PyObject UNUSED *self, PyObject *args) {
|
||||
id_type os_window_id = 0;
|
||||
if (!PyArg_ParseTuple(args, "|K", &os_window_id)) return NULL;
|
||||
OSWindow *w = os_window_id ? find_os_window(os_window_id) : current_os_window();
|
||||
OSWindow *w = os_window_id ? os_window_for_id(os_window_id) : current_os_window();
|
||||
if (!w) Py_RETURN_NONE;
|
||||
if (toggle_maximized_for_os_window(w)) { Py_RETURN_TRUE; }
|
||||
Py_RETURN_FALSE;
|
||||
@@ -1387,7 +1378,7 @@ cocoa_minimize_os_window(PyObject UNUSED *self, PyObject *args) {
|
||||
id_type os_window_id = 0;
|
||||
if (!PyArg_ParseTuple(args, "|K", &os_window_id)) return NULL;
|
||||
#ifdef __APPLE__
|
||||
OSWindow *w = os_window_id ? find_os_window(os_window_id) : current_os_window();
|
||||
OSWindow *w = os_window_id ? os_window_for_id(os_window_id) : current_os_window();
|
||||
if (!w || !w->handle) Py_RETURN_NONE;
|
||||
if (!glfwGetCocoaWindow) { PyErr_SetString(PyExc_RuntimeError, "Failed to load glfwGetCocoaWindow"); return NULL; }
|
||||
void *window = glfwGetCocoaWindow(w->handle);
|
||||
@@ -1403,12 +1394,18 @@ cocoa_minimize_os_window(PyObject UNUSED *self, PyObject *args) {
|
||||
static PyObject*
|
||||
change_os_window_state(PyObject *self UNUSED, PyObject *args) {
|
||||
char *state;
|
||||
if (!PyArg_ParseTuple(args, "s", &state)) return NULL;
|
||||
OSWindow *w = current_os_window();
|
||||
id_type wid = 0;
|
||||
if (!PyArg_ParseTuple(args, "s|K", &state, &wid)) return NULL;
|
||||
OSWindow *w = wid ? os_window_for_id(wid) : current_os_window();
|
||||
if (!w || !w->handle) Py_RETURN_NONE;
|
||||
if (strcmp(state, "maximized") == 0) glfwMaximizeWindow(w->handle);
|
||||
else if (strcmp(state, "minimized") == 0) glfwIconifyWindow(w->handle);
|
||||
else { PyErr_SetString(PyExc_ValueError, "Unknown window state"); return NULL; }
|
||||
else if (strcmp(state, "fullscreen") == 0 || strcmp(state, "fullscreened") == 0) {
|
||||
if (!is_os_window_fullscreen(w)) toggle_fullscreen_for_os_window(w);
|
||||
} else if (strcmp(state, "normal") == 0) {
|
||||
if (is_os_window_fullscreen(w)) toggle_fullscreen_for_os_window(w);
|
||||
else glfwRestoreWindow(w->handle);
|
||||
} else { PyErr_SetString(PyExc_ValueError, "Unknown window state"); return NULL; }
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
@@ -1485,7 +1482,7 @@ x11_display(PYNOARG) {
|
||||
|
||||
static PyObject*
|
||||
x11_window_id(PyObject UNUSED *self, PyObject *os_wid) {
|
||||
OSWindow *w = find_os_window(PyLong_AsUnsignedLongLong(os_wid));
|
||||
OSWindow *w = os_window_for_id(PyLong_AsUnsignedLongLong(os_wid));
|
||||
if (!w) { PyErr_SetString(PyExc_ValueError, "No OSWindow with the specified id found"); return NULL; }
|
||||
if (!glfwGetX11Window) { PyErr_SetString(PyExc_RuntimeError, "Failed to load glfwGetX11Window"); return NULL; }
|
||||
return Py_BuildValue("l", (long)glfwGetX11Window(w->handle));
|
||||
@@ -1493,7 +1490,7 @@ x11_window_id(PyObject UNUSED *self, PyObject *os_wid) {
|
||||
|
||||
static PyObject*
|
||||
cocoa_window_id(PyObject UNUSED *self, PyObject *os_wid) {
|
||||
OSWindow *w = find_os_window(PyLong_AsUnsignedLongLong(os_wid));
|
||||
OSWindow *w = os_window_for_id(PyLong_AsUnsignedLongLong(os_wid));
|
||||
if (!w) { PyErr_SetString(PyExc_ValueError, "No OSWindow with the specified id found"); return NULL; }
|
||||
if (!glfwGetCocoaWindow) { PyErr_SetString(PyExc_RuntimeError, "Failed to load glfwGetCocoaWindow"); return NULL; }
|
||||
#ifdef __APPLE__
|
||||
|
||||
@@ -127,6 +127,15 @@ current_focused_os_window_id(void) {
|
||||
}
|
||||
|
||||
|
||||
OSWindow*
|
||||
os_window_for_id(id_type os_window_id) {
|
||||
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 w;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OSWindow*
|
||||
os_window_for_kitty_window(id_type kitty_window_id) {
|
||||
for (size_t i = 0; i < global_state.num_os_windows; i++) {
|
||||
|
||||
@@ -284,6 +284,7 @@ void focus_os_window(OSWindow *w, bool also_raise, const char *activation_token)
|
||||
void run_with_activation_token_in_os_window(OSWindow *w, PyObject *callback);
|
||||
void set_os_window_title(OSWindow *w, const char *title);
|
||||
OSWindow* os_window_for_kitty_window(id_type);
|
||||
OSWindow* os_window_for_id(id_type);
|
||||
OSWindow* add_os_window(void);
|
||||
OSWindow* current_os_window(void);
|
||||
void os_window_regions(OSWindow*, Region *main, Region *tab_bar);
|
||||
|
||||
Reference in New Issue
Block a user