Functions to get and set OS Window size

This commit is contained in:
Kovid Goyal 2021-07-25 12:58:58 +05:30
parent 2e01c1f37e
commit 3d9b52fbc2
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 67 additions and 1 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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),

View File

@ -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);