Rework to get rid of get_monitor_by_output

This commit is contained in:
Michael Wyraz
2023-12-20 14:31:01 +01:00
parent d4ca79bb96
commit 57acc7142f
2 changed files with 27 additions and 14 deletions

View File

@ -32,6 +32,7 @@ struct _GdkX11Monitor
GdkMonitor parent; GdkMonitor parent;
XID output; XID output;
char* name;
guint add : 1; guint add : 1;
guint remove : 1; guint remove : 1;
}; };

View File

@ -469,14 +469,14 @@ check_is_composited (GdkDisplay *display,
} }
static GdkX11Monitor * static GdkX11Monitor *
find_monitor_by_output (GdkX11Display *x11_display, XID output) find_monitor_by_name (GdkX11Display *x11_display, char *name)
{ {
int i; int i;
for (i = 0; i < x11_display->monitors->len; i++) for (i = 0; i < x11_display->monitors->len; i++)
{ {
GdkX11Monitor *monitor = x11_display->monitors->pdata[i]; GdkX11Monitor *monitor = x11_display->monitors->pdata[i];
if (monitor->output == output) if (strcmp(monitor->name, name) == 0)
return monitor; return monitor;
} }
@ -644,14 +644,22 @@ init_randr15 (GdkScreen *screen, gboolean *changed)
#undef EDID_LENGTH #undef EDID_LENGTH
} }
monitor = g_object_new (GDK_TYPE_X11_MONITOR, name = gdk_x11_get_xatom_name_for_display(display, rr_monitors[i].name);
monitor = find_monitor_by_name (x11_display, name);
if (monitor)
monitor->remove = FALSE;
else
{
monitor = g_object_new (gdk_x11_monitor_get_type (),
"display", display, "display", display,
NULL); NULL);
monitor->output = output;
monitor->name = name;
monitor->add = TRUE; monitor->add = TRUE;
g_ptr_array_add (x11_display->monitors, monitor); g_ptr_array_add (x11_display->monitors, monitor);
}
gdk_monitor_get_geometry (GDK_MONITOR (monitor), &geometry); gdk_monitor_get_geometry (GDK_MONITOR (monitor), &geometry);
name = gdk_x11_get_xatom_name_for_display(display, rr_monitors[i].name);
newgeo.x = rr_monitors[i].x / x11_screen->window_scale; newgeo.x = rr_monitors[i].x / x11_screen->window_scale;
newgeo.y = rr_monitors[i].y / x11_screen->window_scale; newgeo.y = rr_monitors[i].y / x11_screen->window_scale;
@ -833,7 +841,8 @@ init_randr13 (GdkScreen *screen, gboolean *changed)
} }
} }
monitor = find_monitor_by_output (x11_display, output); name = g_strndup (output_info->name, output_info->nameLen);
monitor = find_monitor_by_name (x11_display, name);
if (monitor) if (monitor)
monitor->remove = FALSE; monitor->remove = FALSE;
else else
@ -841,13 +850,13 @@ init_randr13 (GdkScreen *screen, gboolean *changed)
monitor = g_object_new (gdk_x11_monitor_get_type (), monitor = g_object_new (gdk_x11_monitor_get_type (),
"display", display, "display", display,
NULL); NULL);
monitor->name = name;
monitor->output = output; monitor->output = output;
monitor->add = TRUE; monitor->add = TRUE;
g_ptr_array_add (x11_display->monitors, monitor); g_ptr_array_add (x11_display->monitors, monitor);
} }
gdk_monitor_get_geometry (GDK_MONITOR (monitor), &geometry); gdk_monitor_get_geometry (GDK_MONITOR (monitor), &geometry);
name = g_strndup (output_info->name, output_info->nameLen);
newgeo.x = crtc->x / x11_screen->window_scale; newgeo.x = crtc->x / x11_screen->window_scale;
newgeo.y = crtc->y / x11_screen->window_scale; newgeo.y = crtc->y / x11_screen->window_scale;
@ -974,15 +983,18 @@ init_no_multihead (GdkScreen *screen, gboolean *changed)
monitor->remove = TRUE; monitor->remove = TRUE;
} }
monitor = find_monitor_by_output (x11_display, 0); if (x11_display->monitors->len > 0)
if (monitor) {
monitor = x11_display->monitors->pdata[0];
monitor->remove = FALSE; monitor->remove = FALSE;
}
else else
{ {
monitor = g_object_new (gdk_x11_monitor_get_type (), monitor = g_object_new (gdk_x11_monitor_get_type (),
"display", x11_display, "display", display,
NULL); NULL);
monitor->output = 0; monitor->output = 0;
monitor->name = 0;
monitor->add = TRUE; monitor->add = TRUE;
g_ptr_array_add (x11_display->monitors, monitor); g_ptr_array_add (x11_display->monitors, monitor);
} }