diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 97f45a577..d45eb54a1 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -1187,3 +1187,22 @@ def mouse_selection(os_window_id: int, tab_id: int, window_id: int, code: int, b def apply_options_update() -> None: pass + + +def set_os_window_size(os_window_id: int, x: int, y: int) -> bool: + pass + + +class OSWindowSize(TypedDict): + width: int + height: int + framebuffer_width: int + framebuffer_height: int + xscale: float + yscale: float + xdpi: float + ydpi: float + + +def get_os_window_size(os_window_id: int) -> Optional[OSWindowSize]: + pass diff --git a/kitty/glfw.c b/kitty/glfw.c index 177c3693c..850584aa7 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -481,6 +481,16 @@ make_os_window_context_current(OSWindow *w) { } } +void +get_os_window_size(OSWindow *os_window, int *w, int *h, int *fw, int *fh) { + if (w && h) glfwGetWindowSize(os_window->handle, w, h); + if (fw && fh) glfwGetFramebufferSize(os_window->handle, fw, fh); +} + +void +set_os_window_size(OSWindow *os_window, int x, int y) { + glfwSetWindowSize(os_window->handle, x, y); +} static inline void get_window_content_scale(GLFWwindow *w, float *xscale, float *yscale, double *xdpi, double *ydpi) { @@ -508,6 +518,11 @@ get_window_dpi(GLFWwindow *w, double *x, double *y) { get_window_content_scale(w, &xscale, &yscale, x, y); } +void +get_os_window_content_scale(OSWindow *os_window, double *xdpi, double *ydpi, float *xscale, float *yscale) { + get_window_content_scale(os_window->handle, xscale, yscale, xdpi, ydpi); +} + static void set_os_window_dpi(OSWindow *w) { get_window_dpi(w->handle, &w->logical_dpi_x, &w->logical_dpi_y); @@ -1253,7 +1268,6 @@ cocoa_window_id(PyObject UNUSED *self, PyObject *os_wid) { return NULL; #endif } - static PyObject* get_primary_selection(PYNOARG) { if (glfwGetPrimarySelectionString) { diff --git a/kitty/state.c b/kitty/state.c index ba0d6e56c..794ffd98f 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -871,6 +871,34 @@ PYWRAP1(os_window_font_size) { return Py_BuildValue("d", 0.0); } +PYWRAP1(set_os_window_size) { + id_type os_window_id; + int width, height; + PA("Kii", &os_window_id, &width, &height); + WITH_OS_WINDOW(os_window_id) + set_os_window_size(os_window, width, height); + Py_RETURN_TRUE; + END_WITH_OS_WINDOW + Py_RETURN_FALSE; +} + +PYWRAP1(get_os_window_size) { + id_type os_window_id; + PA("K", &os_window_id); + WITH_OS_WINDOW(os_window_id) + double xdpi, ydpi; + float xscale, yscale; + int width, height, fw, fh; + get_os_window_size(os_window, &width, &height, &fw, &fh); + get_os_window_content_scale(os_window, &xdpi, &ydpi, &xscale, &yscale); + return Py_BuildValue("{si si si si sf sf sd sd}", + "width", width, "height", height, "framebuffer_width", fw, "framebuffer_height", fh, + "xscale", xscale, "yscale", yscale, "xdpi", xdpi, "ydpi", ydpi); + END_WITH_OS_WINDOW + Py_RETURN_NONE; +} + + PYWRAP1(set_boss) { Py_CLEAR(global_state.boss); global_state.boss = args; @@ -1066,6 +1094,8 @@ static PyMethodDef module_methods[] = { MW(global_font_size, METH_VARARGS), MW(set_background_image, METH_VARARGS), MW(os_window_font_size, METH_VARARGS), + MW(set_os_window_size, METH_VARARGS), + MW(get_os_window_size, METH_VARARGS), MW(set_boss, METH_O), MW(get_boss, METH_NOARGS), MW(apply_options_update, METH_NOARGS), diff --git a/kitty/state.h b/kitty/state.h index 698695cc2..0b9af1ebf 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -227,6 +227,9 @@ void gl_init(void); void remove_vao(ssize_t vao_idx); bool remove_os_window(id_type os_window_id); void make_os_window_context_current(OSWindow *w); +void set_os_window_size(OSWindow *os_window, int x, int y); +void get_os_window_size(OSWindow *os_window, int *w, int *h, int *fw, int *fh); +void get_os_window_content_scale(OSWindow *os_window, double *xdpi, double *ydpi, float *xscale, float *yscale); void update_os_window_references(void); void mark_os_window_for_close(OSWindow* w, CloseRequest cr); void update_os_window_viewport(OSWindow *window, bool);