diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-08-16 19:37:00 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-08-16 19:37:00 +0200 |
commit | da4925b23e7ebd6df35cdb0ba39ac8cc1701a102 (patch) | |
tree | 60984aaf6353dd2f733f1ac8005e09a84ac66a29 /src/egl.c | |
parent | f297a92e05e3e57b1b9350b64c8407f4a1436f09 (diff) |
Allow capture of external monitors on a laptop with dedicated gpu (prime) on x11, fix cursor not visible on some wayland compositors (hyprland) with multiple monitors
Diffstat (limited to 'src/egl.c')
-rw-r--r-- | src/egl.c | 47 |
1 files changed, 44 insertions, 3 deletions
@@ -1,16 +1,17 @@ #include "../include/egl.h" #include "../include/library_loader.h" #include "../include/utils.h" + #include <string.h> #include <stdio.h> #include <stdlib.h> #include <dlfcn.h> #include <assert.h> +#include <unistd.h> +#include <sys/capability.h> #include <wayland-client.h> #include <wayland-egl.h> -#include <unistd.h> -#include <sys/capability.h> // TODO: rename gsr_egl to something else since this includes both egl and glx and in the future maybe vulkan too @@ -93,7 +94,7 @@ static void registry_add_object(void *data, struct wl_registry *registry, uint32 } if(egl->wayland.num_outputs == GSR_MAX_OUTPUTS) { - fprintf(stderr, "gsr warning: reached maximum outputs (32), ignoring output %u\n", name); + fprintf(stderr, "gsr warning: reached maximum outputs (%d), ignoring output %u\n", GSR_MAX_OUTPUTS, name); return; } @@ -134,6 +135,26 @@ static void reset_cap_nice(void) { cap_free(caps); } +static void store_x11_monitor(const gsr_monitor *monitor, void *userdata) { + gsr_egl *egl = userdata; + if(egl->x11.num_outputs == GSR_MAX_OUTPUTS) { + fprintf(stderr, "gsr warning: reached maximum outputs (%d), ignoring output %s\n", GSR_MAX_OUTPUTS, monitor->name); + return; + } + + char *monitor_name = strdup(monitor->name); + if(!monitor_name) + return; + + const int index = egl->x11.num_outputs; + egl->x11.outputs[index].name = monitor_name; + egl->x11.outputs[index].pos = monitor->pos; + egl->x11.outputs[index].size = monitor->size; + egl->x11.outputs[index].connector_id = monitor->connector_id; + egl->x11.outputs[index].rotation = monitor->rotation; + ++egl->x11.num_outputs; +} + #define GLX_DRAWABLE_TYPE 0x8010 #define GLX_RENDER_TYPE 0x8011 #define GLX_RGBA_BIT 0x00000001 @@ -271,6 +292,11 @@ static bool gsr_egl_create_window(gsr_egl *self, bool wayland) { goto fail; } + if(!wayland) { + self->x11.num_outputs = 0; + for_each_active_monitor_output_x11_not_cached(self->x11.dpy, store_x11_monitor, self); + } + reset_cap_nice(); return true; @@ -587,6 +613,14 @@ void gsr_egl_unload(gsr_egl *self) { self->x11.window = None; } + for(int i = 0; i < self->x11.num_outputs; ++i) { + if(self->x11.outputs[i].name) { + free(self->x11.outputs[i].name); + self->x11.outputs[i].name = NULL; + } + } + self->x11.num_outputs = 0; + if(self->wayland.window) { wl_egl_window_destroy(self->wayland.window); self->wayland.window = NULL; @@ -658,3 +692,10 @@ void gsr_egl_swap_buffers(gsr_egl *self) { self->glXSwapBuffers(self->x11.dpy, self->x11.window); } } + +gsr_display_server gsr_egl_get_display_server(const gsr_egl *egl) { + if(egl->wayland.dpy) + return GSR_DISPLAY_SERVER_WAYLAND; + else + return GSR_DISPLAY_SERVER_X11; +} |