mirror of
https://github.com/IllusionMan1212/cudoku.git
synced 2026-10-24 02:12:25 +00:00
non-resizable window and always floating window
This commit is contained in:
@@ -122,11 +122,12 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Color clear_color = {0.2f, 0.15f, 0.5f, 1.f};
|
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) {
|
if (res != 0) {
|
||||||
printf("[ERROR]: could not initialize zephr\n");
|
printf("[ERROR]: could not initialize zephr\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
make_window_non_resizable();
|
||||||
|
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
- "premade" (but also customizable) ui elements (buttons, text boxes, etc) with instanced rendering
|
- "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?)
|
- 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)
|
- 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
|
text rendering improvements
|
||||||
- [ ] unicode support (allows for non-ascii characters)
|
- [ ] unicode support (allows for non-ascii characters)
|
||||||
|
|||||||
@@ -241,6 +241,11 @@ int init_ui(const char* font_path, Size window_size) {
|
|||||||
return 0;
|
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 init_zephr(const char* font_path, const char* window_title, Size window_size, Color *clear_color) {
|
||||||
int res = audio_init();
|
int res = audio_init();
|
||||||
if (res != 0) {
|
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};
|
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();
|
start_internal_timer();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -421,7 +427,7 @@ void set_width_constraint(UIConstraints *constraints, float value, UIConstraint
|
|||||||
constraints->width = (value * zephr_context.window_size.width);
|
constraints->width = (value * zephr_context.window_size.width);
|
||||||
break;
|
break;
|
||||||
case UI_CONSTRAINT_RELATIVE_PIXELS:
|
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;
|
break;
|
||||||
case UI_CONSTRAINT_ASPECT_RATIO:
|
case UI_CONSTRAINT_ASPECT_RATIO:
|
||||||
constraints->width = constraints->height * value;
|
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);
|
constraints->height = (value * zephr_context.window_size.height);
|
||||||
break;
|
break;
|
||||||
case UI_CONSTRAINT_RELATIVE_PIXELS:
|
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;
|
break;
|
||||||
case UI_CONSTRAINT_ASPECT_RATIO:
|
case UI_CONSTRAINT_ASPECT_RATIO:
|
||||||
constraints->height = constraints->width * value;
|
constraints->height = constraints->width * value;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ typedef struct Text {
|
|||||||
typedef struct Context {
|
typedef struct Context {
|
||||||
bool should_quit;
|
bool should_quit;
|
||||||
Color clear_color;
|
Color clear_color;
|
||||||
|
Size screen_size;
|
||||||
Size window_size;
|
Size window_size;
|
||||||
ZephFont font;
|
ZephFont font;
|
||||||
Text texts;
|
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);
|
int init_zephr(const char* font_path, const char* window_title, Size window_size, Color *clear_color);
|
||||||
void deinit_zephr();
|
void deinit_zephr();
|
||||||
|
void make_window_non_resizable();
|
||||||
bool zephr_should_quit();
|
bool zephr_should_quit();
|
||||||
void zephr_swap_buffers();
|
void zephr_swap_buffers();
|
||||||
Size zephr_get_window_size();
|
Size zephr_get_window_size();
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <X11/Xatom.h>
|
||||||
#include <glad/glx.h>
|
#include <glad/glx.h>
|
||||||
|
|
||||||
static bool fullscreen = false;
|
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,
|
DefaultDepth(*display, screen), InputOutput, visual,
|
||||||
CWColormap | CWEventMask, &attributes);
|
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);
|
XMapWindow(*display, *window);
|
||||||
XStoreName(*display, *window, title);
|
XStoreName(*display, *window, title);
|
||||||
|
|
||||||
@@ -160,3 +167,21 @@ void toggle_fullscreen(Display *display, Window window) {
|
|||||||
|
|
||||||
fullscreen = !fullscreen;
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -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 close_x11(Display **display, Window *window);
|
||||||
void resize_x11_window(Display *display, Window window);
|
void resize_x11_window(Display *display, Window window);
|
||||||
void toggle_fullscreen(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);
|
||||||
|
|||||||
Reference in New Issue
Block a user