Allow specifying which os window to toggle
This commit is contained in:
parent
630379651e
commit
a2f7aedd9c
@ -570,11 +570,11 @@ def free_font_data() -> None:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def toggle_maximized() -> bool:
|
def toggle_maximized(os_window_id: int = 0) -> bool:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def toggle_fullscreen() -> bool:
|
def toggle_fullscreen(os_window_id: int = 0) -> bool:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
40
kitty/glfw.c
40
kitty/glfw.c
@ -1142,17 +1142,30 @@ set_clipboard_string(PyObject UNUSED *self, PyObject *args) {
|
|||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 PyObject*
|
static PyObject*
|
||||||
toggle_fullscreen(PYNOARG) {
|
toggle_fullscreen(PyObject UNUSED *self, PyObject *args) {
|
||||||
OSWindow *w = current_os_window();
|
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();
|
||||||
if (!w) Py_RETURN_NONE;
|
if (!w) Py_RETURN_NONE;
|
||||||
if (toggle_fullscreen_for_os_window(w)) { Py_RETURN_TRUE; }
|
if (toggle_fullscreen_for_os_window(w)) { Py_RETURN_TRUE; }
|
||||||
Py_RETURN_FALSE;
|
Py_RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
toggle_maximized(PYNOARG) {
|
toggle_maximized(PyObject UNUSED *self, PyObject *args) {
|
||||||
OSWindow *w = current_os_window();
|
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();
|
||||||
if (!w) Py_RETURN_NONE;
|
if (!w) Py_RETURN_NONE;
|
||||||
if (toggle_maximized_for_os_window(w)) { Py_RETURN_TRUE; }
|
if (toggle_maximized_for_os_window(w)) { Py_RETURN_TRUE; }
|
||||||
Py_RETURN_FALSE;
|
Py_RETURN_FALSE;
|
||||||
@ -1238,19 +1251,9 @@ x11_display(PYNOARG) {
|
|||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static OSWindow*
|
|
||||||
find_os_window(PyObject *os_wid) {
|
|
||||||
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 w;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
x11_window_id(PyObject UNUSED *self, PyObject *os_wid) {
|
x11_window_id(PyObject UNUSED *self, PyObject *os_wid) {
|
||||||
OSWindow *w = find_os_window(os_wid);
|
OSWindow *w = find_os_window(PyLong_AsUnsignedLongLong(os_wid));
|
||||||
if (!w) { PyErr_SetString(PyExc_ValueError, "No OSWindow with the specified id found"); return NULL; }
|
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; }
|
if (!glfwGetX11Window) { PyErr_SetString(PyExc_RuntimeError, "Failed to load glfwGetX11Window"); return NULL; }
|
||||||
return Py_BuildValue("l", (long)glfwGetX11Window(w->handle));
|
return Py_BuildValue("l", (long)glfwGetX11Window(w->handle));
|
||||||
@ -1258,7 +1261,7 @@ x11_window_id(PyObject UNUSED *self, PyObject *os_wid) {
|
|||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
cocoa_window_id(PyObject UNUSED *self, PyObject *os_wid) {
|
cocoa_window_id(PyObject UNUSED *self, PyObject *os_wid) {
|
||||||
OSWindow *w = find_os_window(os_wid);
|
OSWindow *w = find_os_window(PyLong_AsUnsignedLongLong(os_wid));
|
||||||
if (!w) { PyErr_SetString(PyExc_ValueError, "No OSWindow with the specified id found"); return NULL; }
|
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; }
|
if (!glfwGetCocoaWindow) { PyErr_SetString(PyExc_RuntimeError, "Failed to load glfwGetCocoaWindow"); return NULL; }
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
@ -1268,6 +1271,7 @@ cocoa_window_id(PyObject UNUSED *self, PyObject *os_wid) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
get_primary_selection(PYNOARG) {
|
get_primary_selection(PYNOARG) {
|
||||||
if (glfwGetPrimarySelectionString) {
|
if (glfwGetPrimarySelectionString) {
|
||||||
@ -1433,8 +1437,8 @@ static PyMethodDef module_methods[] = {
|
|||||||
METHODB(get_content_scale_for_window, METH_NOARGS),
|
METHODB(get_content_scale_for_window, METH_NOARGS),
|
||||||
METHODB(ring_bell, METH_NOARGS),
|
METHODB(ring_bell, METH_NOARGS),
|
||||||
METHODB(set_clipboard_string, METH_VARARGS),
|
METHODB(set_clipboard_string, METH_VARARGS),
|
||||||
METHODB(toggle_fullscreen, METH_NOARGS),
|
METHODB(toggle_fullscreen, METH_VARARGS),
|
||||||
METHODB(toggle_maximized, METH_NOARGS),
|
METHODB(toggle_maximized, METH_VARARGS),
|
||||||
METHODB(change_os_window_state, METH_VARARGS),
|
METHODB(change_os_window_state, METH_VARARGS),
|
||||||
METHODB(glfw_window_hint, METH_VARARGS),
|
METHODB(glfw_window_hint, METH_VARARGS),
|
||||||
METHODB(get_primary_selection, METH_NOARGS),
|
METHODB(get_primary_selection, METH_NOARGS),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user