mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-27 10:41:58 +02:00
Functions to get and set OS Window size
This commit is contained in:
@@ -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:
|
def apply_options_update() -> None:
|
||||||
pass
|
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
|
||||||
|
|||||||
16
kitty/glfw.c
16
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
|
static inline void
|
||||||
get_window_content_scale(GLFWwindow *w, float *xscale, float *yscale, double *xdpi, double *ydpi) {
|
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);
|
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
|
static void
|
||||||
set_os_window_dpi(OSWindow *w) {
|
set_os_window_dpi(OSWindow *w) {
|
||||||
get_window_dpi(w->handle, &w->logical_dpi_x, &w->logical_dpi_y);
|
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;
|
return NULL;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
get_primary_selection(PYNOARG) {
|
get_primary_selection(PYNOARG) {
|
||||||
if (glfwGetPrimarySelectionString) {
|
if (glfwGetPrimarySelectionString) {
|
||||||
|
|||||||
@@ -871,6 +871,34 @@ PYWRAP1(os_window_font_size) {
|
|||||||
return Py_BuildValue("d", 0.0);
|
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) {
|
PYWRAP1(set_boss) {
|
||||||
Py_CLEAR(global_state.boss);
|
Py_CLEAR(global_state.boss);
|
||||||
global_state.boss = args;
|
global_state.boss = args;
|
||||||
@@ -1066,6 +1094,8 @@ static PyMethodDef module_methods[] = {
|
|||||||
MW(global_font_size, METH_VARARGS),
|
MW(global_font_size, METH_VARARGS),
|
||||||
MW(set_background_image, METH_VARARGS),
|
MW(set_background_image, METH_VARARGS),
|
||||||
MW(os_window_font_size, 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(set_boss, METH_O),
|
||||||
MW(get_boss, METH_NOARGS),
|
MW(get_boss, METH_NOARGS),
|
||||||
MW(apply_options_update, METH_NOARGS),
|
MW(apply_options_update, METH_NOARGS),
|
||||||
|
|||||||
@@ -227,6 +227,9 @@ void gl_init(void);
|
|||||||
void remove_vao(ssize_t vao_idx);
|
void remove_vao(ssize_t vao_idx);
|
||||||
bool remove_os_window(id_type os_window_id);
|
bool remove_os_window(id_type os_window_id);
|
||||||
void make_os_window_context_current(OSWindow *w);
|
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 update_os_window_references(void);
|
||||||
void mark_os_window_for_close(OSWindow* w, CloseRequest cr);
|
void mark_os_window_for_close(OSWindow* w, CloseRequest cr);
|
||||||
void update_os_window_viewport(OSWindow *window, bool);
|
void update_os_window_viewport(OSWindow *window, bool);
|
||||||
|
|||||||
Reference in New Issue
Block a user