aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-06-10 17:14:25 +0200
committerdec05eba <dec05eba@protonmail.com>2024-06-10 17:14:25 +0200
commit55266f2a689a17fc34e7f441a4b8f1f8f917a366 (patch)
tree07f1eb4f6aba4b3bdab138441d72c9f82c5b8157 /src/utils.c
parentf02f5a9d00e6255852c68b22b96709ef2941b5c0 (diff)
Wayland: match montitor by name before trying to match by place
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/utils.c b/src/utils.c
index 8d726ef..92abbb0 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -296,28 +296,57 @@ bool get_monitor_by_name(const gsr_egl *egl, gsr_connection_type connection_type
typedef struct {
const gsr_monitor *monitor;
gsr_monitor_rotation rotation;
+ bool match_found;
} get_monitor_by_connector_id_userdata;
+static bool vec2i_eql(vec2i a, vec2i b) {
+ return a.x == b.x && a.y == b.y;
+}
+
+static void get_monitor_by_name_and_size_callback(const gsr_monitor *monitor, void *userdata) {
+ get_monitor_by_connector_id_userdata *data = (get_monitor_by_connector_id_userdata*)userdata;
+ if(monitor->name && data->monitor->name && strcmp(monitor->name, data->monitor->name) == 0 && vec2i_eql(monitor->size, data->monitor->size)) {
+ data->rotation = monitor->rotation;
+ data->match_found = true;
+ }
+}
+
static void get_monitor_by_connector_id_callback(const gsr_monitor *monitor, void *userdata) {
get_monitor_by_connector_id_userdata *data = (get_monitor_by_connector_id_userdata*)userdata;
if(monitor->connector_id == data->monitor->connector_id ||
(!monitor->connector_id && monitor->monitor_identifier == data->monitor->monitor_identifier))
{
data->rotation = monitor->rotation;
+ data->match_found = true;
}
}
gsr_monitor_rotation drm_monitor_get_display_server_rotation(const gsr_egl *egl, const gsr_monitor *monitor) {
if(egl->wayland.dpy) {
- get_monitor_by_connector_id_userdata userdata;
- userdata.monitor = monitor;
- userdata.rotation = GSR_MONITOR_ROT_0;
- for_each_active_monitor_output_wayland(egl, get_monitor_by_connector_id_callback, &userdata);
- return userdata.rotation;
+ {
+ get_monitor_by_connector_id_userdata userdata;
+ userdata.monitor = monitor;
+ userdata.rotation = GSR_MONITOR_ROT_0;
+ userdata.match_found = false;
+ for_each_active_monitor_output_wayland(egl, get_monitor_by_name_and_size_callback, &userdata);
+ if(userdata.match_found) {
+ fprintf(stderr, "found!\n");
+ return userdata.rotation;
+ }
+ }
+ {
+ get_monitor_by_connector_id_userdata userdata;
+ userdata.monitor = monitor;
+ userdata.rotation = GSR_MONITOR_ROT_0;
+ userdata.match_found = false;
+ for_each_active_monitor_output_wayland(egl, get_monitor_by_connector_id_callback, &userdata);
+ return userdata.rotation;
+ }
} else {
get_monitor_by_connector_id_userdata userdata;
userdata.monitor = monitor;
userdata.rotation = GSR_MONITOR_ROT_0;
+ userdata.match_found = false;
for_each_active_monitor_output_x11(egl->x11.dpy, get_monitor_by_connector_id_callback, &userdata);
return userdata.rotation;
}