summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-02-04 21:00:14 -0500
committerAndrew Opalach <andrew@akon.city> 2025-02-04 21:03:32 -0500
commitdda9ba19bb94947cf7d2f176f0d6760078598b69 (patch)
tree8e9392e4a2999ad37741401a4b29e0ec953c01e1 /src
parenta55bfe4c21858eef0eb1bddf4085fcfde1b7e07d (diff)
downloadstela-dda9ba19bb94947cf7d2f176f0d6760078598b69.tar.gz
stela-dda9ba19bb94947cf7d2f176f0d6760078598b69.tar.bz2
stela-dda9ba19bb94947cf7d2f176f0d6760078598b69.zip
Unsigned width and height
- Slight build cleanup Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src')
-rw-r--r--src/egl_common.c2
-rw-r--r--src/poll_common.c5
-rw-r--r--src/window.c6
-rw-r--r--src/window.h23
-rw-r--r--src/window_glfm.c17
-rw-r--r--src/window_glfw.c32
-rw-r--r--src/window_kms.c11
-rw-r--r--src/window_wayland.c56
-rw-r--r--src/window_x11.c26
9 files changed, 95 insertions, 83 deletions
diff --git a/src/egl_common.c b/src/egl_common.c
index 818873f..7bbcba9 100644
--- a/src/egl_common.c
+++ b/src/egl_common.c
@@ -137,7 +137,7 @@ bool stl_init_egl_context(struct stl_egl *egl, struct stl_egl_global *global, EG
if (!egl_choose_config(egl->display, window_attr, visual_id, config)) {
al_log_error("egl", "Failed to get config.");
- return false;
+ continue;
}
al_log_info("egl", "Trying to create a %s context of version %i.%i (GLSL %i).",
diff --git a/src/poll_common.c b/src/poll_common.c
index 5e7f38a..a592b55 100644
--- a/src/poll_common.c
+++ b/src/poll_common.c
@@ -20,8 +20,9 @@ bool stl_poll_common(struct nn_pollfd *fds, bool block)
return false;
}
- // This happens consistantly if a program is lagging too much.
- // TODO: Recovery.
+ // This will happen consistantly if a program is lagging too hard.
+ // https://github.com/swaywm/sway/commit/e3f0ba4cd9ca709cac115ade54958885614d889c
+ // @TODO: Recovery.
if (fds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) { // Fatal error.
al_log_error("poll_common", "poll() returned error in revents (%d).", fds[0].revents);
al_assert(false);
diff --git a/src/window.c b/src/window.c
index 762adce..9afe285 100644
--- a/src/window.c
+++ b/src/window.c
@@ -100,7 +100,7 @@ void stl_window_send_key_event(struct stl_window *window, u8 state, u8 button)
#endif
}
-void stl_window_send_resize_event(struct stl_window *window, s32 width, s32 height)
+void stl_window_send_resize_event(struct stl_window *window, u32 width, u32 height)
{
#ifdef STELA_EVENT_BUFFER
(void)width;
@@ -147,8 +147,8 @@ bool stl_window_read_events(struct stl_window *window)
u8 op = STELA_EVENT_NONE;
if (window->pending_resize) {
- s32 width = window->width;
- s32 height = window->height;
+ u32 width = window->width;
+ u32 height = window->height;
window->resize_internal(window, width, height);
if (window->resize_callback) {
window->resize_callback(window->userdata, width, height);
diff --git a/src/window.h b/src/window.h
index afe797e..11ba00f 100644
--- a/src/window.h
+++ b/src/window.h
@@ -40,17 +40,17 @@ enum {
#define STELA_MAX_MONITOR_NAME 255u
struct stl_monitor {
- s32 width;
- s32 height;
- s32 scale;
+ u32 width;
+ u32 height;
+ u32 scale;
bool vertical;
char name[STELA_MAX_MONITOR_NAME];
};
struct stl_window {
- s32 width;
- s32 height;
- s32 scale;
+ u32 width;
+ u32 height;
+ u32 scale;
bool fullscreen;
#ifdef STELA_EVENT_BUFFER
u8 *data;
@@ -62,10 +62,9 @@ struct stl_window {
bool pending_refresh;
#endif
// Methods.
- bool (*create_context)(struct stl_window *, s32);
- bool (*create_window)(struct stl_window *, s32, s32, const char *, const char *, s32);
- void (*resize_internal)(struct stl_window *, s32, s32);
- void (*resize)(struct stl_window *, s32, s32);
+ bool (*create_window)(struct stl_window *, u32, u32, const char *, const char *, u32);
+ void (*resize_internal)(struct stl_window *, u32, u32);
+ void (*resize)(struct stl_window *, u32, u32);
void (*toggle_fullscreen)(struct stl_window *);
#ifdef STELA_POLL_INLINE
bool (*poll)(struct stl_window *, bool);
@@ -103,7 +102,7 @@ struct stl_window {
bool (*key_callback)(void *, u8, u8);
// Always runs on the thread that's processing events.
void (*key_immediate_callback)(void *, u8, u8);
- void (*resize_callback)(void *, s32, s32);
+ void (*resize_callback)(void *, u32, u32);
void (*refresh_callback)(void *);
void (*should_close_callback)(void *);
void *userdata;
@@ -147,7 +146,7 @@ void stl_window_send_pointer_pos_event(struct stl_window *window, f64 x, f64 y);
void stl_window_send_scroll_event(struct stl_window *window, f64 y);
void stl_window_send_mouse_button_event(struct stl_window *window, u8 state, u8 button);
void stl_window_send_key_event(struct stl_window *window, u8 state, u8 button);
-void stl_window_send_resize_event(struct stl_window *window, s32 width, s32 height);
+void stl_window_send_resize_event(struct stl_window *window, u32 width, u32 height);
#ifdef STELA_POLL_INLINE
void stl_window_send_refresh_event(struct stl_window *window);
#endif
diff --git a/src/window_glfm.c b/src/window_glfm.c
index 4e4f034..29ab44b 100644
--- a/src/window_glfm.c
+++ b/src/window_glfm.c
@@ -27,16 +27,18 @@ void stl_global_close(void)
{
}
-static bool window_glfm_create_window(struct stl_window *window, s32 width, s32 height,
- const char *monitor, const char *name, s32 flags)
+static bool window_glfm_create_window(struct stl_window *window, u32 width, u32 height,
+ const char *monitor, const char *name, u32 flags)
{
struct stl_window_glfm *glfm = (struct stl_window_glfm *)window;
(void)monitor;
(void)name;
(void)flags;
- glfmGetDisplaySize(glfm->display, &width, &height);
- glfm->w.width = width;
- glfm->w.height = height;
+ s32 display_width, display_height;
+ glfmGetDisplaySize(glfm->display, &display_width, &display_height);
+ al_assert(display_width > 0 && display_height > 0);
+ glfm->w.width = (u32)display_width;
+ glfm->w.height = (u32)display_height;
#ifdef STELA_USE_EGL
glfm->w.egl_display = (EGLDisplay)glfmGetEglDisplay(glfm->display);
glfm->w.egl_context = (EGLContext)glfmGetEglContext(glfm->display);
@@ -44,14 +46,14 @@ static bool window_glfm_create_window(struct stl_window *window, s32 width, s32
return true;
}
-static void window_glfm_resize_internal(struct stl_window *window, s32 width, s32 height)
+static void window_glfm_resize_internal(struct stl_window *window, u32 width, u32 height)
{
(void)window;
(void)width;
(void)height;
}
-static void window_glfm_resize(struct stl_window *window, s32 width, s32 height)
+static void window_glfm_resize(struct stl_window *window, u32 width, u32 height)
{
(void)window;
(void)width;
@@ -130,7 +132,6 @@ struct stl_window *stl_window_create(void *context)
glfm->display = (GLFMDisplay *)context;
stl_window_common_init(&glfm->w);
glfm->w.fullscreen = false;
- glfm->w.create_context = NULL;
glfm->w.create_window = window_glfm_create_window;
glfm->w.resize_internal = window_glfm_resize_internal;
glfm->w.resize = window_glfm_resize;
diff --git a/src/window_glfw.c b/src/window_glfw.c
index dbf6a70..fc7b020 100644
--- a/src/window_glfw.c
+++ b/src/window_glfw.c
@@ -101,12 +101,21 @@ static void scroll_callback(GLFWwindow *window, f64 xoffset, f64 yoffset)
stl_window_send_scroll_event(&glfw->w, -yoffset);
}
-static void resize_callback(GLFWwindow *window, s32 width, s32 height)
+static void resize_callback(GLFWwindow *window, s32 event_width, s32 event_height)
{
struct stl_window_glfw *glfw = glfwGetWindowUserPointer(window);
- glfw->w.width = width;
- glfw->w.height = height;
- stl_window_send_resize_event(&glfw->w, width, height);
+ al_assert(event_width > 0 && event_height > 0);
+
+ u32 width = (u32)event_width;
+ u32 height = (u32)event_height;
+ if (width == glfw->w.width && height == glfw->w.height) {
+ return;
+ }
+
+ glfw->w.width = (u32)width;
+ glfw->w.height = (u32)height;
+
+ stl_window_send_resize_event(&glfw->w, glfw->w.width, glfw->w.height);
}
#ifdef STELA_POLL_INLINE
@@ -123,8 +132,8 @@ static void close_callback(GLFWwindow *window)
stl_window_send_should_close_event(&glfw->w);
}
-static bool window_glfw_create_window(struct stl_window *window, s32 width, s32 height,
- const char *monitor, const char *name, s32 flags)
+static bool window_glfw_create_window(struct stl_window *window, u32 width, u32 height,
+ const char *monitor, const char *name, u32 flags)
{
struct stl_window_glfw *glfw = (struct stl_window_glfw *)window;
(void)monitor;
@@ -183,7 +192,11 @@ static bool window_glfw_create_window(struct stl_window *window, s32 width, s32
(void)flags;
#endif
- glfwGetFramebufferSize(glfw->window, &glfw->w.width, &glfw->w.height);
+ s32 buffer_width, buffer_height;
+ glfwGetFramebufferSize(glfw->window, &buffer_width, &buffer_height);
+ al_assert(buffer_width > 0 && buffer_height > 0);
+ glfw->w.width = (u32)buffer_width;
+ glfw->w.height = (u32)buffer_height;
glfwSetWindowSizeLimits(glfw->window, STELA_MIN_WIDTH, STELA_MIN_HEIGHT, GLFW_DONT_CARE, GLFW_DONT_CARE);
glfw->prev.x = 0;
@@ -207,14 +220,14 @@ static bool window_glfw_create_window(struct stl_window *window, s32 width, s32
return true;
}
-static void window_glfw_resize_internal(struct stl_window *window, s32 width, s32 height)
+static void window_glfw_resize_internal(struct stl_window *window, u32 width, u32 height)
{
(void)window;
(void)width;
(void)height;
}
-static void window_glfw_resize(struct stl_window *window, s32 width, s32 height)
+static void window_glfw_resize(struct stl_window *window, u32 width, u32 height)
{
struct stl_window_glfw *glfw = (struct stl_window_glfw *)window;
glfwSetWindowAspectRatio(glfw->window, width, height);
@@ -388,7 +401,6 @@ struct stl_window *stl_window_create(void *context)
struct stl_window_glfw *glfw = al_alloc_object(struct stl_window_glfw);
stl_window_common_init(&glfw->w);
glfw->w.fullscreen = false;
- glfw->w.create_context = NULL;
glfw->w.create_window = window_glfw_create_window;
glfw->w.resize_internal = window_glfw_resize_internal;
glfw->w.resize = window_glfw_resize;
diff --git a/src/window_kms.c b/src/window_kms.c
index cc35213..58d68eb 100644
--- a/src/window_kms.c
+++ b/src/window_kms.c
@@ -27,8 +27,8 @@ void stl_global_close(void)
{
}
-static bool window_kms_create_window(struct stl_window *window, s32 width, s32 height,
- const char *monitor, const char *name, s32 flags)
+static bool window_kms_create_window(struct stl_window *window, u32 width, u32 height,
+ const char *monitor, const char *name, u32 flags)
{
struct stl_window_kms *kms = (struct stl_window_kms *)window;
(void)kms;
@@ -40,14 +40,14 @@ static bool window_kms_create_window(struct stl_window *window, s32 width, s32 h
return true;
}
-static void window_kms_resize_internal(struct stl_window *window, s32 width, s32 height)
+static void window_kms_resize_internal(struct stl_window *window, u32 width, u32 height)
{
(void)window;
(void)width;
(void)height;
}
-static void window_kms_resize(struct stl_window *window, s32 width, s32 height)
+static void window_kms_resize(struct stl_window *window, u32 width, u32 height)
{
(void)window;
(void)width;
@@ -125,7 +125,6 @@ struct stl_window *stl_window_create(void *context)
struct stl_window_kms *kms = al_alloc_object(struct stl_window_kms);
stl_window_common_init(&kms->w);
kms->w.fullscreen = true;
- kms->w.create_context = NULL;
kms->w.create_window = window_kms_create_window;
kms->w.resize_internal = window_kms_resize_internal;
kms->w.resize = window_kms_resize;
@@ -143,7 +142,7 @@ struct stl_window *stl_window_create(void *context)
kms->w.free = window_kms_free;
#if defined STELA_API_VULKAN
#elif defined STELA_API_OPENGL
- kms->w.get_gl_proc_address = kmsGetProcAddress;
+ kms->w.get_gl_proc_address = NULL;
kms->w.gl_loader_load = window_kms_gl_loader_load;
kms->w.gl_make_current = window_kms_gl_make_current;
kms->w.gl_release_current = window_kms_gl_release_current;
diff --git a/src/window_wayland.c b/src/window_wayland.c
index 40886c2..31d1e13 100644
--- a/src/window_wayland.c
+++ b/src/window_wayland.c
@@ -40,12 +40,13 @@ static void handle_output_mode(void *data, struct wl_output *output,
(void)output;
(void)flags;
(void)refresh;
+ al_assert(width > 0 && height > 0);
if (monitor->m.vertical) {
- monitor->m.width = height;
- monitor->m.height = width;
+ monitor->m.width = (u32)height;
+ monitor->m.height = (u32)width;
} else {
- monitor->m.width = width;
- monitor->m.height = height;
+ monitor->m.width = (u32)width;
+ monitor->m.height = (u32)height;
}
}
@@ -53,7 +54,7 @@ static void handle_output_done(void *data, struct wl_output *output)
{
struct stl_monitor_wayland *monitor = (struct stl_monitor_wayland *)data;
(void)output;
- al_log_info("window_wayland", "Output discovered: %s (%dx%d) (vertical: %s).",
+ al_log_info("window_wayland", "Output discovered: %s (%ux%u) (vertical: %s).",
monitor->m.name, monitor->m.width, monitor->m.height, BOOLSTR(monitor->m.vertical));
if (global.output_discovered) {
global.output_discovered(global.userdata, (struct stl_monitor *)monitor);
@@ -64,7 +65,8 @@ static void handle_output_scale(void *data, struct wl_output *output, s32 factor
{
struct stl_monitor_wayland *monitor = (struct stl_monitor_wayland *)data;
(void)output;
- monitor->m.scale = factor;
+ al_assert(factor > 0);
+ monitor->m.scale = (u32)factor;
}
static void handle_output_description(void *data, struct wl_output *output, const char *description)
@@ -577,15 +579,22 @@ static const struct wl_surface_listener surface_listener = {
.preferred_buffer_transform = preferred_buffer_transform
};
-static bool check_and_set_dimensions(struct stl_window_wayland *wl, s32 width, s32 height)
+static bool check_and_set_dimensions(struct stl_window_wayland *wl, s32 event_width, s32 event_height)
{
- width *= wl->w.scale;
- height *= wl->w.scale;
- if (!width || !height || (width == wl->w.width && height == wl->w.height)) {
+ if (event_width <= 0 || event_height <= 0) {
return false;
}
+
+ u32 scale = wl->w.scale;
+ u32 width = event_width * scale;
+ u32 height = event_height * scale;
+ if (width == wl->w.width && height == wl->w.height) {
+ return false;
+ }
+
wl->w.width = width;
wl->w.height = height;
+
return true;
}
@@ -714,17 +723,6 @@ static bool create_context_internal(struct stl_window_wayland *wl)
return true;
}
-static bool window_wayland_create_context(struct stl_window *window, s32 flags)
-{
- struct stl_window_wayland *wl = (struct stl_window_wayland *)window;
- (void)flags;
- if (!create_context_internal(wl)) {
- wl->w.free((struct stl_window **)&wl);
- return false;
- }
- return true;
-}
-
static struct stl_monitor_wayland *monitor_from_name(const char *name)
{
for (u32 i = 0; i < global.monitors.count; i++) {
@@ -759,6 +757,7 @@ static bool create_toplevel(struct stl_window_wayland *wl, s32 scale, const char
xdg_toplevel_set_title(wl->xdg_toplevel, name);
xdg_toplevel_set_app_id(wl->xdg_toplevel, name);
xdg_toplevel_set_min_size(wl->xdg_toplevel, STELA_MIN_WIDTH, STELA_MIN_HEIGHT);
+ //xdg_surface_set_window_geometry(wl->xdg_surface, 0, 0, wl->w.width, wl->w.height);
u32 decor = ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE;
wl->zxdg_toplevel_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration(
@@ -789,8 +788,8 @@ static bool create_layer_shell(struct stl_window_wayland *wl, struct stl_monitor
return true;
}
-static bool window_wayland_create_window(struct stl_window *window, s32 width, s32 height,
- const char *monitor, const char *name, s32 flags)
+static bool window_wayland_create_window(struct stl_window *window, u32 width, u32 height,
+ const char *monitor, const char *name, u32 flags)
{
struct stl_window_wayland *wl = (struct stl_window_wayland *)window;
@@ -809,7 +808,7 @@ static bool window_wayland_create_window(struct stl_window *window, s32 width, s
wl_surface_add_listener(wl->surface, &surface_listener, wl);
if (!(flags & STELA_WINDOW_WALLPAPER)) {
- // TODO: Scale selection for toplevels.
+ // @TODO: Scale selection for toplevels.
selected = (struct stl_monitor_wayland *)al_array_at(global.monitors, 0);
if (!create_toplevel(wl, selected ? selected->m.scale : 1, name)) goto err;
} else {
@@ -826,7 +825,7 @@ static bool window_wayland_create_window(struct stl_window *window, s32 width, s
#ifdef STELA_API_OPENGL
stl_egl_make_current(&wl->egl);
- stl_egl_swap_interval(&wl->egl, (flags & STELA_WINDOW_VSYNC) ? 1 : 0);
+ stl_egl_swap_interval(&wl->egl, flags & STELA_WINDOW_VSYNC ? 1 : 0);
stl_egl_release_current(&wl->egl);
#endif
@@ -842,7 +841,7 @@ err:
return false;
}
-static void window_wayland_resize(struct stl_window *window, s32 width, s32 height)
+static void window_wayland_resize(struct stl_window *window, u32 width, u32 height)
{
struct stl_window_wayland *wl = (struct stl_window_wayland *)window;
(void)wl;
@@ -850,11 +849,11 @@ static void window_wayland_resize(struct stl_window *window, s32 width, s32 heig
(void)height;
}
-static void window_wayland_resize_internal(struct stl_window *window, s32 width, s32 height)
+static void window_wayland_resize_internal(struct stl_window *window, u32 width, u32 height)
{
struct stl_window_wayland *wl = (struct stl_window_wayland *)window;
#ifdef STELA_API_OPENGL
- //xdg_surface_set_window_geometry(wl->xdg_surface, 0, 0, wl->w.width, wl->w.height);
+ //xdg_surface_set_window_geometry(wl->xdg_surface, 0, 0, width, height);
if (stl_egl_is_ready(&wl->egl)) {
wl_egl_window_resize(wl->egl_window, width, height, 0, 0);
}
@@ -993,7 +992,6 @@ struct stl_window *stl_window_create(void *context)
struct stl_window_wayland *wl = al_alloc_object(struct stl_window_wayland);
stl_window_common_init(&wl->w);
wl->w.fullscreen = false;
- wl->w.create_context = window_wayland_create_context;
wl->w.create_window = window_wayland_create_window;
wl->w.resize = window_wayland_resize;
wl->w.resize_internal = window_wayland_resize_internal;
diff --git a/src/window_x11.c b/src/window_x11.c
index b02d639..c1425ee 100644
--- a/src/window_x11.c
+++ b/src/window_x11.c
@@ -60,8 +60,9 @@ bool stl_global_init(bool skip_graphics)
al_memcpy(monitor->name, name, length);
free(name);
monitor->scale = 1;
- monitor->width = info[i].width;
- monitor->height = info[i].height;
+ al_assert(info[i].width > 0 && info[i].height > 0);
+ monitor->width = (u32)info[i].width;
+ monitor->height = (u32)info[i].height;
al_array_push(global.monitors, monitor);
if (global.output_discovered) {
global.output_discovered(global.userdata, monitor);
@@ -112,8 +113,8 @@ static bool x11_egl_init(struct stl_window_x11 *xw)
}
#endif
-static bool window_x11_create_window(struct stl_window *window, s32 width, s32 height,
- const char *monitor, const char *name, s32 flags)
+static bool window_x11_create_window(struct stl_window *window, u32 width, u32 height,
+ const char *monitor, const char *name, u32 flags)
{
struct stl_window_x11 *xw = (struct stl_window_x11 *)window;
(void)monitor;
@@ -140,8 +141,9 @@ static bool window_x11_create_window(struct stl_window *window, s32 width, s32 h
XWindowAttributes gwa;
XGetWindowAttributes(global.x11_d, xw->window, &gwa);
- xw->w.width = gwa.width;
- xw->w.height = gwa.height;
+ al_assert(gwa.width > 0 && gwa.height > 0);
+ xw->w.width = (u32)gwa.width;
+ xw->w.height = (u32)gwa.height;
if (flags & STELA_WINDOW_WALLPAPER) {
Atom net_wm_type = XInternAtom(global.x11_d, "_NET_WM_WINDOW_TYPE", False);
@@ -185,14 +187,14 @@ static bool window_x11_create_window(struct stl_window *window, s32 width, s32 h
return true;
}
-static void window_x11_resize_internal(struct stl_window *window, s32 width, s32 height)
+static void window_x11_resize_internal(struct stl_window *window, u32 width, u32 height)
{
(void)window;
(void)width;
(void)height;
}
-static void window_x11_resize(struct stl_window *window, s32 width, s32 height)
+static void window_x11_resize(struct stl_window *window, u32 width, u32 height)
{
struct stl_window_x11 *xw = (struct stl_window_x11 *)window;
XMoveResizeWindow(global.x11_d, xw->window, 0, 0, width, height);
@@ -234,8 +236,9 @@ static void handle_next_xevent(struct stl_window_x11 *xw)
}
break;
case ConfigureNotify:
- xw->w.width = xev.xconfigure.width;
- xw->w.height = xev.xconfigure.height;
+ al_assert(xev.xconfigure.width > 0 && xev.xconfigure.height > 0);
+ xw->w.width = (u32)xev.xconfigure.width;
+ xw->w.height = (u32)xev.xconfigure.height;
stl_window_send_resize_event(&xw->w, xw->w.width, xw->w.height);
break;
case KeyPress:
@@ -291,7 +294,7 @@ static bool window_x11_should_refresh(struct stl_window *window)
static void window_x11_free(struct stl_window **window)
{
struct stl_window_x11 *xw = (struct stl_window_x11 *)*window;
- // TODO: Cleanup x11 stuff.
+ // @TODO: Cleanup x11 stuff.
#ifdef STELA_EVENT_BUFFER
al_free(xw->w.data);
#endif
@@ -352,7 +355,6 @@ struct stl_window *stl_window_create(void *context)
struct stl_window_x11 *xw = al_alloc_object(struct stl_window_x11);
stl_window_common_init(&xw->w);
xw->w.fullscreen = false;
- xw->w.create_context = NULL;
xw->w.create_window = window_x11_create_window;
xw->w.resize_internal = window_x11_resize_internal;
xw->w.resize = window_x11_resize;