summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2020-05-13 04:44:06 +0200
committerBenjamin Otte <otte@redhat.com>2020-05-13 06:45:08 +0200
commitbc88f0116560d461b35eafff152fbdacfb461830 (patch)
treef6fdfff7c70ecd1f86bd002d97cca6c47d756353
parent7ff69e9356030470277f94ffbd6cf5da24e4565c (diff)
downloadgtk+-bc88f0116560d461b35eafff152fbdacfb461830.tar.gz
win32: Use a GListStore for the monitors
-rw-r--r--gdk/win32/gdkdisplay-win32.c70
-rw-r--r--gdk/win32/gdkdisplay-win32.h4
2 files changed, 36 insertions, 38 deletions
diff --git a/gdk/win32/gdkdisplay-win32.c b/gdk/win32/gdkdisplay-win32.c
index ec451426b0..8861f6928b 100644
--- a/gdk/win32/gdkdisplay-win32.c
+++ b/gdk/win32/gdkdisplay-win32.c
@@ -169,11 +169,12 @@ _gdk_win32_display_find_matching_monitor (GdkWin32Display *win32_display,
{
int i;
- for (i = 0; i < win32_display->monitors->len; i++)
+ for (i = 0; i < g_list_model_get_n_items (win32_display->monitors); i++)
{
GdkWin32Monitor *m;
- m = GDK_WIN32_MONITOR (g_ptr_array_index (win32_display->monitors, i));
+ m = g_list_model_get_item (win32_display->monitors, i);
+ g_object_unref (m);
if (_gdk_win32_monitor_compare (m, GDK_WIN32_MONITOR (needle)) == 0)
return GDK_MONITOR (m);
@@ -182,17 +183,22 @@ _gdk_win32_display_find_matching_monitor (GdkWin32Display *win32_display,
return NULL;
}
-gboolean
+void
_gdk_win32_display_init_monitors (GdkWin32Display *win32_display)
{
GdkDisplay *display = GDK_DISPLAY (win32_display);
GPtrArray *new_monitors;
gint i;
- gboolean changed = FALSE;
GdkWin32Monitor *primary_to_move = NULL;
- for (i = 0; i < win32_display->monitors->len; i++)
- GDK_WIN32_MONITOR (g_ptr_array_index (win32_display->monitors, i))->remove = TRUE;
+ for (i = 0; i < g_list_model_get_n_items (win32_display->monitors); i++)
+ {
+ GdkWin32Monitor *m;
+
+ m = g_list_model_get_item (win32_display->monitors, i);
+ m->remove = TRUE;
+ g_object_unref (m);
+ }
new_monitors = _gdk_win32_display_get_monitor_list (win32_display);
@@ -213,7 +219,6 @@ _gdk_win32_display_init_monitors (GdkWin32Display *win32_display)
if (ex_monitor == NULL)
{
w32_m->add = TRUE;
- changed = TRUE;
continue;
}
@@ -230,14 +235,12 @@ _gdk_win32_display_init_monitors (GdkWin32Display *win32_display)
if (memcmp (&workarea, &ex_workarea, sizeof (GdkRectangle)) != 0)
{
w32_ex_monitor->work_rect = workarea;
- changed = TRUE;
}
if (memcmp (&geometry, &ex_geometry, sizeof (GdkRectangle)) != 0)
{
gdk_monitor_set_size (ex_monitor, geometry.width, geometry.height);
gdk_monitor_set_position (ex_monitor, geometry.x, geometry.y);
- changed = TRUE;
}
if (gdk_monitor_get_width_mm (m) != gdk_monitor_get_width_mm (ex_monitor) ||
@@ -246,56 +249,50 @@ _gdk_win32_display_init_monitors (GdkWin32Display *win32_display)
gdk_monitor_set_physical_size (ex_monitor,
gdk_monitor_get_width_mm (m),
gdk_monitor_get_height_mm (m));
- changed = TRUE;
}
if (g_strcmp0 (gdk_monitor_get_model (m), gdk_monitor_get_model (ex_monitor)) != 0)
{
gdk_monitor_set_model (ex_monitor,
gdk_monitor_get_model (m));
- changed = TRUE;
}
if (g_strcmp0 (gdk_monitor_get_manufacturer (m), gdk_monitor_get_manufacturer (ex_monitor)) != 0)
{
gdk_monitor_set_manufacturer (ex_monitor,
gdk_monitor_get_manufacturer (m));
- changed = TRUE;
}
if (gdk_monitor_get_refresh_rate (m) != gdk_monitor_get_refresh_rate (ex_monitor))
{
gdk_monitor_set_refresh_rate (ex_monitor, gdk_monitor_get_refresh_rate (m));
- changed = TRUE;
}
if (gdk_monitor_get_scale_factor (m) != gdk_monitor_get_scale_factor (ex_monitor))
{
gdk_monitor_set_scale_factor (ex_monitor, gdk_monitor_get_scale_factor (m));
- changed = TRUE;
}
if (gdk_monitor_get_subpixel_layout (m) != gdk_monitor_get_subpixel_layout (ex_monitor))
{
gdk_monitor_set_subpixel_layout (ex_monitor, gdk_monitor_get_subpixel_layout (m));
- changed = TRUE;
}
}
- for (i = win32_display->monitors->len - 1; i >= 0; i--)
+ for (i = g_list_model_get_n_items (win32_display->monitors) - 1; i >= 0; i--)
{
GdkWin32Monitor *w32_ex_monitor;
GdkMonitor *ex_monitor;
- w32_ex_monitor = GDK_WIN32_MONITOR (g_ptr_array_index (win32_display->monitors, i));
+ w32_ex_monitor = GDK_WIN32_MONITOR (g_list_model_get_item (win32_display->monitors, i));
+ g_object_unref (w32_ex_monitor);
ex_monitor = GDK_MONITOR (w32_ex_monitor);
if (!w32_ex_monitor->remove)
continue;
- changed = TRUE;
gdk_display_monitor_removed (display, ex_monitor);
- g_ptr_array_remove_index (win32_display->monitors, i);
+ g_list_store_remove (G_LIST_STORE (win32_display->monitors), i);
}
for (i = 0; i < new_monitors->len; i++)
@@ -312,20 +309,22 @@ _gdk_win32_display_init_monitors (GdkWin32Display *win32_display)
gdk_display_monitor_added (display, m);
if (i == 0)
- g_ptr_array_insert (win32_display->monitors, 0, g_object_ref (w32_m));
+ g_list_store_insert (G_LIST_STORE (win32_display->monitors), 0, w32_m);
else
- g_ptr_array_add (win32_display->monitors, g_object_ref (w32_m));
+ g_list_store_append (G_LIST_STORE (win32_display->monitors), w32_m);
}
g_ptr_array_free (new_monitors, TRUE);
if (primary_to_move)
{
- g_ptr_array_remove (win32_display->monitors, g_object_ref (primary_to_move));
- g_ptr_array_insert (win32_display->monitors, 0, primary_to_move);
- changed = TRUE;
+ guint pos;
+ g_object_ref (primary_to_move);
+ if (g_list_store_find (G_LIST_STORE (win32_display->monitors), primary_to_move, &pos))
+ g_list_store_remove (G_LIST_STORE (win32_display->monitors), pos);
+ g_list_store_insert (G_LIST_STORE (win32_display->monitors), 0, primary_to_move);
+ g_object_unref (primary_to_move);
}
- return changed;
}
@@ -706,7 +705,8 @@ gdk_win32_display_finalize (GObject *object)
_gdk_win32_dnd_exit ();
_gdk_win32_lang_notification_exit ();
- g_ptr_array_free (display_win32->monitors, TRUE);
+ g_list_store_remove_all (G_LIST_STORE (display_win32->monitors));
+ g_object_unref (display_win32->monitors);
while (display_win32->filters)
_gdk_win32_message_filter_unref (display_win32, display_win32->filters->data);
@@ -911,7 +911,7 @@ gdk_win32_display_init (GdkWin32Display *display)
{
const gchar *scale_str = g_getenv ("GDK_SCALE");
- display->monitors = g_ptr_array_new_with_free_func (g_object_unref);
+ display->monitors = G_LIST_MODEL (g_list_store_new (GDK_TYPE_MONITOR));
_gdk_win32_enable_hidpi (display);
@@ -964,7 +964,7 @@ gdk_win32_display_get_n_monitors (GdkDisplay *display)
{
GdkWin32Display *win32_display = GDK_WIN32_DISPLAY (display);
- return win32_display->monitors->len;
+ return g_list_model_get_n_items (win32_display->monitors);
}
@@ -973,23 +973,21 @@ gdk_win32_display_get_monitor (GdkDisplay *display,
int monitor_num)
{
GdkWin32Display *win32_display = GDK_WIN32_DISPLAY (display);
+ GdkMonitor *monitor;
- if (monitor_num < 0 || monitor_num >= win32_display->monitors->len)
+ monitor = g_list_model_get_item (win32_display->monitors, monitor_num);
+ if (monitor == NULL)
return NULL;
- return (GdkMonitor *) g_ptr_array_index (win32_display->monitors, monitor_num);
+ g_object_unref (monitor);
+ return monitor;
}
GdkMonitor *
gdk_win32_display_get_primary_monitor (GdkDisplay *display)
{
- GdkWin32Display *win32_display = GDK_WIN32_DISPLAY (display);
-
/* We arrange for the first monitor in the array to also be the primiary monitor */
- if (win32_display->monitors->len > 0)
- return (GdkMonitor *) g_ptr_array_index (win32_display->monitors, 0);
-
- return NULL;
+ return gdk_win32_display_get_monitor (display, 0);
}
guint
diff --git a/gdk/win32/gdkdisplay-win32.h b/gdk/win32/gdkdisplay-win32.h
index a4d9cc7378..8fb5ec4cb5 100644
--- a/gdk/win32/gdkdisplay-win32.h
+++ b/gdk/win32/gdkdisplay-win32.h
@@ -82,7 +82,7 @@ struct _GdkWin32Display
guint gl_version;
HWND gl_hwnd;
- GPtrArray *monitors;
+ GListModel *monitors;
guint hasWglARBCreateContext : 1;
guint hasWglEXTSwapControl : 1;
@@ -120,7 +120,7 @@ struct _GdkWin32DisplayClass
GdkDisplayClass display_class;
};
-gboolean _gdk_win32_display_init_monitors (GdkWin32Display *display);
+void _gdk_win32_display_init_monitors (GdkWin32Display *display);
GPtrArray *_gdk_win32_display_get_monitor_list (GdkWin32Display *display);