aboutsummaryrefslogtreecommitdiff
path: root/src/window
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-11-16 04:49:07 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-16 04:49:07 +0100
commitdb02fe3f85165b09954d01d44a497abf8155b326 (patch)
treec0c9f38d94486c7ad5e1e43fb43c15b8d248749a /src/window
parent8ea04000bfa98798a0283bcf80ea136ea8b4dd42 (diff)
Window: allow setting window minimum/max size and position
Diffstat (limited to 'src/window')
-rw-r--r--src/window/window.c40
1 files changed, 31 insertions, 9 deletions
diff --git a/src/window/window.c b/src/window/window.c
index 5cc7ba1..da163da 100644
--- a/src/window/window.c
+++ b/src/window/window.c
@@ -208,11 +208,7 @@ static void mgl_window_on_resize(mgl_window *self, int width, int height) {
mgl_window_set_view(self, &view);
}
-int mgl_window_create(mgl_window *self, const char *title, int width, int height) {
- return mgl_window_create_with_params(self, title, width, height, 0);
-}
-
-static int mgl_window_init(mgl_window *self, const char *title, int width, int height, mgl_window_handle parent_window, Window existing_window) {
+static int mgl_window_init(mgl_window *self, const char *title, const mgl_window_create_params *params, Window existing_window) {
self->window = 0;
self->context = NULL;
self->open = false;
@@ -235,6 +231,7 @@ static int mgl_window_init(mgl_window *self, const char *title, int width, int h
mgl_context *context = mgl_get_context();
+ Window parent_window = params ? params->parent_window : None;
if(parent_window == 0)
parent_window = DefaultRootWindow(context->connection);
@@ -272,7 +269,8 @@ static int mgl_window_init(mgl_window *self, const char *title, int width, int h
XFreeColormap(context->connection, color_map);
self->window = existing_window;
} else {
- self->window = XCreateWindow(context->connection, parent_window, 0, 0, width, height, 0,
+ self->window = XCreateWindow(context->connection, parent_window, params->position.x, params->position.y,
+ params->size.x, params->size.y, 0,
((XVisualInfo*)context->visual_info)->depth, InputOutput, ((XVisualInfo*)context->visual_info)->visual,
CWColormap | CWEventMask | CWBitGravity, &window_attr);
XFreeColormap(context->connection, color_map);
@@ -286,6 +284,30 @@ static int mgl_window_init(mgl_window *self, const char *title, int width, int h
XMapWindow(context->connection, self->window);
}
+ if(params) {
+ XSizeHints *size_hints = XAllocSizeHints();
+ if(size_hints) {
+ size_hints->width = params->size.x;
+ size_hints->min_width = params->min_size.x;
+ size_hints->max_width = params->max_size.x;
+
+ size_hints->height = params->size.y;
+ size_hints->min_height = params->min_size.y;
+ size_hints->max_height = params->max_size.y;
+
+ size_hints->flags = PSize;
+ if(size_hints->min_width || size_hints->min_height)
+ size_hints->flags |= PMinSize;
+ if(size_hints->max_width || size_hints->max_height)
+ size_hints->flags |= PMaxSize;
+
+ XSetWMNormalHints(context->connection, self->window, size_hints);
+ XFree(size_hints);
+ } else {
+ fprintf(stderr, "Warning: failed to set window size hints\n");
+ }
+ }
+
/* TODO: Call XGetWMProtocols and add wm_delete_window_atom on top, to not overwrite existing wm protocol atoms */
Atom wm_protocol_atoms[2] = {
context->wm_delete_window_atom,
@@ -337,12 +359,12 @@ static int mgl_window_init(mgl_window *self, const char *title, int width, int h
return 0;
}
-int mgl_window_create_with_params(mgl_window *self, const char *title, int width, int height, mgl_window_handle parent_window) {
- return mgl_window_init(self, title, width, height, parent_window, None);
+int mgl_window_create(mgl_window *self, const char *title, const mgl_window_create_params *params) {
+ return mgl_window_init(self, title, params, None);
}
int mgl_window_init_from_existing_window(mgl_window *self, mgl_window_handle existing_window) {
- return mgl_window_init(self, "", 0, 0, 0, existing_window);
+ return mgl_window_init(self, "", NULL, existing_window);
}
void mgl_window_deinit(mgl_window *self) {