aboutsummaryrefslogtreecommitdiff
path: root/src/window
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2025-01-17 12:44:14 +0100
committerdec05eba <dec05eba@protonmail.com>2025-01-17 12:44:14 +0100
commit97d24e6a1b1fe8d2a4e217f9ee3f82a1accf468a (patch)
treebdd6b9263d8e9ddfc96ab24a2a41b67a352f5398 /src/window
parentfc6457d7596bcf7956767a34a2f3cd32db1bda70 (diff)
Expose mgl_for_each_active_monitor_output
Diffstat (limited to 'src/window')
-rw-r--r--src/window/window.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/window/window.c b/src/window/window.c
index d931a9f..485e400 100644
--- a/src/window/window.c
+++ b/src/window/window.c
@@ -711,8 +711,7 @@ static const XRRModeInfo* get_mode_info(const XRRScreenResources *sr, RRMode id)
return NULL;
}
-typedef void (*active_monitor_callback)(const mgl_monitor *monitor, void *userdata);
-static void for_each_active_monitor_output(Display *display, active_monitor_callback callback, void *userdata) {
+void mgl_for_each_active_monitor_output(void *display, mgl_active_monitor_callback callback, void *userdata) {
XRRScreenResources *screen_res = XRRGetScreenResources(display, DefaultRootWindow(display));
if(!screen_res)
return;
@@ -724,10 +723,8 @@ static void for_each_active_monitor_output(Display *display, active_monitor_call
XRRCrtcInfo *crt_info = XRRGetCrtcInfo(display, screen_res, out_info->crtc);
if(crt_info && crt_info->mode) {
const XRRModeInfo *mode_info = get_mode_info(screen_res, crt_info->mode);
- if(mode_info && out_info->nameLen < (int)sizeof(display_name)) {
- memcpy(display_name, out_info->name, out_info->nameLen);
- display_name[out_info->nameLen] = '\0';
-
+ if(mode_info) {
+ snprintf(display_name, sizeof(display_name), "%s", out_info->name);
mgl_monitor monitor = {
.id = screen_res->outputs[i],
.crtc_id = out_info->crtc,
@@ -1044,7 +1041,7 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window
// TODO: This should be done once and monitor events should be done once, no matter how many windows you have
x11_context_clear_monitors(x11_context);
- for_each_active_monitor_output(context->connection, monitor_callback_add_to_x11_context, x11_context);
+ mgl_for_each_active_monitor_output(context->connection, monitor_callback_add_to_x11_context, x11_context);
self->num_monitors = x11_context->num_monitors;
mgl_window_on_resize(self, self->size.x, self->size.y);