non-resizable window and always floating window

This commit is contained in:
2023-11-26 01:29:17 +02:00
parent 10f727cd28
commit 9fc316583f
6 changed files with 39 additions and 5 deletions
+2 -1
View File
@@ -122,11 +122,12 @@ int main(int argc, char *argv[]) {
}
Color clear_color = {0.2f, 0.15f, 0.5f, 1.f};
int res = init_zephr(font_path, title, (Size){800, 600}, &clear_color);
int res = init_zephr(font_path, title, (Size){900, 900}, &clear_color);
if (res != 0) {
printf("[ERROR]: could not initialize zephr\n");
return 1;
}
make_window_non_resizable();
srand(time(NULL));
-2
View File
@@ -1,8 +1,6 @@
- "premade" (but also customizable) ui elements (buttons, text boxes, etc) with instanced rendering
- maybe force the window to be a specific resolution (for cudoku only? or all games?)
- border decorations for shapes (maybe. or maybe only for ui elements)
- remove the hardcoded 1920 and 1080 values when applying relative pixel constraints
and replace them with the screen's currently active resolution
text rendering improvements
- [ ] unicode support (allows for non-ascii characters)
+8 -2
View File
@@ -241,6 +241,11 @@ int init_ui(const char* font_path, Size window_size) {
return 0;
}
// Has to be called after calling init_zephr()
void make_window_non_resizable() {
x11_make_window_non_resizable(display, window, zephr_context.window_size.width, zephr_context.window_size.height);
}
int init_zephr(const char* font_path, const char* window_title, Size window_size, Color *clear_color) {
int res = audio_init();
if (res != 0) {
@@ -263,6 +268,7 @@ int init_zephr(const char* font_path, const char* window_title, Size window_size
zephr_context.clear_color = (Color){0.0, 0.0, 0.0, 1.0};
}
get_screen_size(display, &zephr_context.screen_size.width, &zephr_context.screen_size.height);
start_internal_timer();
return 0;
@@ -421,7 +427,7 @@ void set_width_constraint(UIConstraints *constraints, float value, UIConstraint
constraints->width = (value * zephr_context.window_size.width);
break;
case UI_CONSTRAINT_RELATIVE_PIXELS:
constraints->width = zephr_context.window_size.width / 1920.f * value;
constraints->width = zephr_context.window_size.width / (float)zephr_context.screen_size.width * value;
break;
case UI_CONSTRAINT_ASPECT_RATIO:
constraints->width = constraints->height * value;
@@ -438,7 +444,7 @@ void set_height_constraint(UIConstraints *constraints, float value, UIConstraint
constraints->height = (value * zephr_context.window_size.height);
break;
case UI_CONSTRAINT_RELATIVE_PIXELS:
constraints->height = zephr_context.window_size.height / 1080.f * value;
constraints->height = zephr_context.window_size.height / (float)zephr_context.screen_size.height * value;
break;
case UI_CONSTRAINT_ASPECT_RATIO:
constraints->height = constraints->width * value;
+2
View File
@@ -32,6 +32,7 @@ typedef struct Text {
typedef struct Context {
bool should_quit;
Color clear_color;
Size screen_size;
Size window_size;
ZephFont font;
Text texts;
@@ -68,6 +69,7 @@ typedef struct UIConstraints {
int init_zephr(const char* font_path, const char* window_title, Size window_size, Color *clear_color);
void deinit_zephr();
void make_window_non_resizable();
bool zephr_should_quit();
void zephr_swap_buffers();
Size zephr_get_window_size();
+25
View File
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <string.h>
#include <X11/Xatom.h>
#include <glad/glx.h>
static bool fullscreen = false;
@@ -38,6 +39,12 @@ int init_x11(Display **display, Window *window, const char* title, int window_wi
DefaultDepth(*display, screen), InputOutput, visual,
CWColormap | CWEventMask, &attributes);
// hints to the WM that the window is a dialog window which makes it a floating
// window in titling WMs (only tested on DWM though)
Atom net_wm_window_type = XInternAtom(*display, "_NET_WM_WINDOW_TYPE", False);
Atom net_wm_window_type_dialog = XInternAtom(*display, "_NET_WM_WINDOW_TYPE_DIALOG", False);
XChangeProperty(*display, *window, net_wm_window_type, XA_ATOM, 32, PropModeReplace, (unsigned char*)&net_wm_window_type_dialog, 1);
XMapWindow(*display, *window);
XStoreName(*display, *window, title);
@@ -160,3 +167,21 @@ void toggle_fullscreen(Display *display, Window window) {
fullscreen = !fullscreen;
}
void get_screen_size(Display *display, int *width, int *height) {
Screen *screen = DefaultScreenOfDisplay(display);
*width = screen->width;
*height = screen->height;
}
void x11_make_window_non_resizable(Display *display, Window window, int width, int height) {
XSizeHints *size_hints = XAllocSizeHints();
size_hints->flags = PMinSize | PMaxSize;
size_hints->min_width = width;
size_hints->min_height = height;
size_hints->max_width = width;
size_hints->max_height = height;
XSetWMNormalHints(display, window, size_hints);
XFree(size_hints);
}
+2
View File
@@ -6,3 +6,5 @@ int init_x11(Display **display, Window *window, const char* title, int window_wi
void close_x11(Display **display, Window *window);
void resize_x11_window(Display *display, Window window);
void toggle_fullscreen(Display *display, Window window);
void get_screen_size(Display *display, int *width, int *height);
void x11_make_window_non_resizable(Display *display, Window window, int width, int height);