summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gs-manager.c140
-rw-r--r--src/gs-window-x11.c28
-rw-r--r--src/gs-window.h3
-rw-r--r--src/test-window.c2
4 files changed, 81 insertions, 92 deletions
diff --git a/src/gs-manager.c b/src/gs-manager.c
index d8c9213..b9777d0 100644
--- a/src/gs-manager.c
+++ b/src/gs-manager.c
@@ -1268,11 +1268,8 @@ apply_background_to_window (GSManager *manager,
GSWindow *window)
{
cairo_surface_t *surface;
- GdkDisplay *display;
- GdkScreen *screen;
int width;
int height;
- gint scale;
mate_bg_load_from_preferences (manager->priv->bg);
@@ -1282,11 +1279,8 @@ apply_background_to_window (GSManager *manager,
gs_window_set_background_surface (window, NULL);
}
- display = gs_window_get_display (window);
- screen = gdk_display_get_default_screen (display);
- scale = gdk_window_get_scale_factor (gdk_screen_get_root_window (screen));
- width = WidthOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale;
- height = HeightOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale;
+ gtk_widget_get_preferred_width (GTK_WIDGET (window), &width, NULL);
+ gtk_widget_get_preferred_height (GTK_WIDGET (window), &height, NULL);
gs_debug ("Creating background w:%d h:%d", width, height);
surface = mate_bg_create_surface (manager->priv->bg,
gs_window_get_gdk_window (window),
@@ -1533,16 +1527,14 @@ gs_manager_create_window_for_monitor (GSManager *manager,
GdkMonitor *monitor)
{
GSWindow *window;
- GdkDisplay *display;
GdkRectangle rect;
- display = gdk_monitor_get_display (monitor);
gdk_monitor_get_geometry (monitor, &rect);
gs_debug ("Creating a window [%d,%d] (%dx%d)",
rect.x, rect.y, rect.width, rect.height);
- window = gs_window_new (display, monitor, manager->priv->lock_active);
+ window = gs_window_new (monitor, manager->priv->lock_active);
gs_window_set_user_switch_enabled (window, manager->priv->user_switch_enabled);
gs_window_set_logout_enabled (window, manager->priv->logout_enabled);
@@ -1563,84 +1555,73 @@ gs_manager_create_window_for_monitor (GSManager *manager,
}
static void
-on_screen_monitors_changed (GdkScreen *screen,
- GSManager *manager)
+on_display_monitor_added (GdkDisplay *display,
+ GdkMonitor *monitor,
+ GSManager *manager)
{
GSList *l;
- GdkDisplay *display;
int n_monitors;
- int n_windows;
- int i;
- display = gdk_screen_get_display (screen);
n_monitors = gdk_display_get_n_monitors (display);
- n_windows = g_slist_length (manager->priv->windows);
- gs_debug ("Monitors changed for display %s: num=%d",
- gdk_display_get_name (display),
- n_monitors);
+ gs_debug ("Monitor added on display %s, now there are %d",
+ gdk_display_get_name (display), n_monitors);
- if (n_monitors > n_windows)
+ /* Tear down the unlock dialog in case we want to move it
+ * to the new monitor
+ */
+ l = manager->priv->windows;
+ while (l != NULL)
{
+ gs_window_cancel_unlock_request (GS_WINDOW (l->data));
+ l = l->next;
+ }
- /* Tear down unlock dialog in case we want to move it
- * to a new monitor
- */
- l = manager->priv->windows;
- while (l != NULL)
- {
- gs_window_cancel_unlock_request (GS_WINDOW (l->data));
- l = l->next;
- }
+ /* add a new window */
+ gs_manager_create_window_for_monitor (manager, monitor);
- /* add more windows */
- for (i = n_windows; i < n_monitors; i++)
- {
- GdkMonitor *mon = gdk_display_get_monitor (display, i);
- gs_manager_create_window_for_monitor (manager, mon);
- }
+ /* and put unlock dialog up whereever it's supposed to be */
+ gs_manager_request_unlock (manager);
+}
- /* And put unlock dialog up where ever it's supposed to be
- */
- gs_manager_request_unlock (manager);
- }
- else
- {
+static void
+on_display_monitor_removed (GdkDisplay *display,
+ GdkMonitor *monitor,
+ GSManager *manager)
+{
+ GSList *l;
+ int n_monitors;
- gdk_x11_grab_server ();
+ n_monitors = gdk_display_get_n_monitors (display);
- /* remove the extra windows */
- l = manager->priv->windows;
- while (l != NULL)
- {
- GdkDisplay *this_display;
- GdkMonitor *this_monitor;
- GSList *next = l->next;
-
- this_display = gs_window_get_display (GS_WINDOW (l->data));
- this_monitor = gs_window_get_monitor (GS_WINDOW (l->data));
- if (this_display == display &&
- !GDK_IS_MONITOR (this_monitor))
- {
- manager_maybe_stop_job_for_window (manager, GS_WINDOW (l->data));
- g_hash_table_remove (manager->priv->jobs, l->data);
- gs_window_destroy (GS_WINDOW (l->data));
- manager->priv->windows = g_slist_delete_link (manager->priv->windows, l);
- }
- l = next;
- }
+ gs_debug ("Monitor removed on display %s, now there are %d",
+ gdk_display_get_name (display), n_monitors);
+
+ gdk_x11_grab_server ();
- /* make sure there is a lock dialog on a connected monitor,
- * and that the keyboard is still properly grabbed after all
- * the windows above got destroyed*/
- if (n_windows > n_monitors)
+ /* remove the now extra window */
+ l = manager->priv->windows;
+ while (l != NULL)
+ {
+ GdkDisplay *this_display;
+ GdkMonitor *this_monitor;
+ GSList *next = l->next;
+
+ this_display = gs_window_get_display (GS_WINDOW (l->data));
+ this_monitor = gs_window_get_monitor (GS_WINDOW (l->data));
+ if (this_display == display && this_monitor == monitor)
{
- gs_manager_request_unlock (manager);
+ manager_maybe_stop_job_for_window (manager,
+ GS_WINDOW (l->data));
+ g_hash_table_remove (manager->priv->jobs, l->data);
+ gs_window_destroy (GS_WINDOW (l->data));
+ manager->priv->windows = g_slist_delete_link (manager->priv->windows, l);
}
-
- gdk_display_flush (display);
- gdk_x11_ungrab_server ();
+ l = next;
}
+
+ gdk_display_flush (display);
+ gdk_x11_ungrab_server ();
}
static void
@@ -1659,8 +1640,11 @@ gs_manager_destroy_windows (GSManager *manager)
display = gdk_display_get_default ();
- g_signal_handlers_disconnect_by_func (gdk_display_get_default_screen (display),
- on_screen_monitors_changed,
+ g_signal_handlers_disconnect_by_func (display,
+ on_display_monitor_removed,
+ manager);
+ g_signal_handlers_disconnect_by_func (display,
+ on_display_monitor_added,
manager);
for (l = manager->priv->windows; l; l = l->next)
@@ -1753,9 +1737,11 @@ gs_manager_create_windows (GSManager *manager)
g_assert (manager->priv->windows == NULL);
display = gdk_display_get_default ();
- g_signal_connect (gdk_display_get_default_screen (display),
- "monitors-changed",
- G_CALLBACK (on_screen_monitors_changed),
+ g_signal_connect (display, "monitor-added",
+ G_CALLBACK (on_display_monitor_added),
+ manager);
+ g_signal_connect (display, "monitor-removed",
+ G_CALLBACK (on_display_monitor_removed),
manager);
gs_manager_create_windows_for_display (manager, display);
diff --git a/src/gs-window-x11.c b/src/gs-window-x11.c
index e36f113..4c4224d 100644
--- a/src/gs-window-x11.c
+++ b/src/gs-window-x11.c
@@ -366,10 +366,11 @@ update_geometry (GSWindow *window)
}
static void
-screen_size_changed (GdkScreen *screen,
- GSWindow *window)
+monitor_geometry_notify (GdkMonitor *monitor,
+ GParamSpec *pspec,
+ GSWindow *window)
{
- gs_debug ("Got screen size changed signal");
+ gs_debug ("Got monitor geometry notify signal");
gtk_widget_queue_resize (GTK_WIDGET (window));
}
@@ -418,8 +419,9 @@ gs_window_move_resize_window (GSWindow *window,
static void
gs_window_real_unrealize (GtkWidget *widget)
{
- g_signal_handlers_disconnect_by_func (gtk_window_get_screen (GTK_WINDOW (widget)),
- screen_size_changed,
+ GdkMonitor *monitor = GS_WINDOW (widget)->priv->monitor;
+
+ g_signal_handlers_disconnect_by_func (monitor, monitor_geometry_notify,
widget);
if (GTK_WIDGET_CLASS (gs_window_parent_class)->unrealize)
@@ -575,6 +577,8 @@ widget_set_best_visual (GtkWidget *widget)
static void
gs_window_real_realize (GtkWidget *widget)
{
+ GdkMonitor *monitor = GS_WINDOW (widget)->priv->monitor;
+
widget_set_best_visual (widget);
if (GTK_WIDGET_CLASS (gs_window_parent_class)->realize)
@@ -586,9 +590,9 @@ gs_window_real_realize (GtkWidget *widget)
gs_window_move_resize_window (GS_WINDOW (widget), TRUE, TRUE);
- g_signal_connect (gtk_window_get_screen (GTK_WINDOW (widget)),
- "size_changed",
- G_CALLBACK (screen_size_changed),
+ g_signal_connect (monitor,
+ "notify::geometry",
+ G_CALLBACK (monitor_geometry_notify),
widget);
}
@@ -2557,12 +2561,12 @@ gs_window_finalize (GObject *object)
}
GSWindow *
-gs_window_new (GdkDisplay *display,
- GdkMonitor *monitor,
+gs_window_new (GdkMonitor *monitor,
gboolean lock_enabled)
{
- GObject *result;
- GdkScreen *screen = gdk_display_get_default_screen (display);
+ GObject *result;
+ GdkDisplay *display = gdk_monitor_get_display (monitor);
+ GdkScreen *screen = gdk_display_get_default_screen (display);
result = g_object_new (GS_TYPE_WINDOW,
"type", GTK_WINDOW_POPUP,
diff --git a/src/gs-window.h b/src/gs-window.h
index 903beae..33bad7f 100644
--- a/src/gs-window.h
+++ b/src/gs-window.h
@@ -91,8 +91,7 @@ void gs_window_show_message (GSWindow *window,
void gs_window_request_unlock (GSWindow *window);
void gs_window_cancel_unlock_request (GSWindow *window);
-GSWindow * gs_window_new (GdkDisplay *display,
- GdkMonitor *monitor,
+GSWindow * gs_window_new (GdkMonitor *monitor,
gboolean lock_enabled);
void gs_window_show (GSWindow *window);
void gs_window_destroy (GSWindow *window);
diff --git a/src/test-window.c b/src/test-window.c
index 92166d1..3233c36 100644
--- a/src/test-window.c
+++ b/src/test-window.c
@@ -130,7 +130,7 @@ test_window (void)
display = gdk_display_get_default ();
monitor = gdk_display_get_primary_monitor (display);
- window = gs_window_new (display, monitor, lock_active);
+ window = gs_window_new (monitor, lock_active);
gs_window_set_user_switch_enabled (window, user_switch_enabled);