Skip to content

Commit

Permalink
fix more GdkScreen related deprecations
Browse files Browse the repository at this point in the history
This is a follow-up to 5d4416a to fix #126
  • Loading branch information
XRevan86 authored and raveit65 committed Aug 24, 2018
1 parent deb9266 commit dbd37df
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 92 deletions.
140 changes: 63 additions & 77 deletions src/gs-manager.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1268,11 +1268,8 @@ apply_background_to_window (GSManager *manager,
GSWindow *window) GSWindow *window)
{ {
cairo_surface_t *surface; cairo_surface_t *surface;
GdkDisplay *display;
GdkScreen *screen;
int width; int width;
int height; int height;
gint scale;


mate_bg_load_from_preferences (manager->priv->bg); mate_bg_load_from_preferences (manager->priv->bg);


Expand All @@ -1282,11 +1279,8 @@ apply_background_to_window (GSManager *manager,
gs_window_set_background_surface (window, NULL); gs_window_set_background_surface (window, NULL);
} }


display = gs_window_get_display (window); gtk_widget_get_preferred_width (GTK_WIDGET (window), &width, NULL);
screen = gdk_display_get_default_screen (display); gtk_widget_get_preferred_height (GTK_WIDGET (window), &height, NULL);
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;
gs_debug ("Creating background w:%d h:%d", width, height); gs_debug ("Creating background w:%d h:%d", width, height);
surface = mate_bg_create_surface (manager->priv->bg, surface = mate_bg_create_surface (manager->priv->bg,
gs_window_get_gdk_window (window), gs_window_get_gdk_window (window),
Expand Down Expand Up @@ -1533,16 +1527,14 @@ gs_manager_create_window_for_monitor (GSManager *manager,
GdkMonitor *monitor) GdkMonitor *monitor)
{ {
GSWindow *window; GSWindow *window;
GdkDisplay *display;
GdkRectangle rect; GdkRectangle rect;


display = gdk_monitor_get_display (monitor);
gdk_monitor_get_geometry (monitor, &rect); gdk_monitor_get_geometry (monitor, &rect);


gs_debug ("Creating a window [%d,%d] (%dx%d)", gs_debug ("Creating a window [%d,%d] (%dx%d)",
rect.x, rect.y, rect.width, rect.height); 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_user_switch_enabled (window, manager->priv->user_switch_enabled);
gs_window_set_logout_enabled (window, manager->priv->logout_enabled); gs_window_set_logout_enabled (window, manager->priv->logout_enabled);
Expand All @@ -1563,84 +1555,73 @@ gs_manager_create_window_for_monitor (GSManager *manager,
} }


static void static void
on_screen_monitors_changed (GdkScreen *screen, on_display_monitor_added (GdkDisplay *display,
GSManager *manager) GdkMonitor *monitor,
GSManager *manager)
{ {
GSList *l; GSList *l;
GdkDisplay *display;
int n_monitors; int n_monitors;
int n_windows;
int i;


display = gdk_screen_get_display (screen);
n_monitors = gdk_display_get_n_monitors (display); 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", gs_debug ("Monitor added on display %s, now there are %d",
gdk_display_get_name (display), gdk_display_get_name (display), n_monitors);
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 /* add a new window */
* to a new monitor gs_manager_create_window_for_monitor (manager, monitor);
*/
l = manager->priv->windows;
while (l != NULL)
{
gs_window_cancel_unlock_request (GS_WINDOW (l->data));
l = l->next;
}


/* add more windows */ /* and put unlock dialog up whereever it's supposed to be */
for (i = n_windows; i < n_monitors; i++) gs_manager_request_unlock (manager);
{ }
GdkMonitor *mon = gdk_display_get_monitor (display, i);
gs_manager_create_window_for_monitor (manager, mon);
}


/* And put unlock dialog up where ever it's supposed to be static void
*/ on_display_monitor_removed (GdkDisplay *display,
gs_manager_request_unlock (manager); GdkMonitor *monitor,
} GSManager *manager)
else {
{ GSList *l;
int n_monitors;


gdk_x11_grab_server (); n_monitors = gdk_display_get_n_monitors (display);


/* remove the extra windows */ gs_debug ("Monitor removed on display %s, now there are %d",
l = manager->priv->windows; gdk_display_get_name (display), n_monitors);
while (l != NULL)
{ gdk_x11_grab_server ();
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;
}


/* make sure there is a lock dialog on a connected monitor, /* remove the now extra window */
* and that the keyboard is still properly grabbed after all l = manager->priv->windows;
* the windows above got destroyed*/ while (l != NULL)
if (n_windows > n_monitors) {
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);
} }

l = next;
gdk_display_flush (display);
gdk_x11_ungrab_server ();
} }

gdk_display_flush (display);
gdk_x11_ungrab_server ();
} }


static void static void
Expand All @@ -1659,8 +1640,11 @@ gs_manager_destroy_windows (GSManager *manager)


display = gdk_display_get_default (); display = gdk_display_get_default ();


g_signal_handlers_disconnect_by_func (gdk_display_get_default_screen (display), g_signal_handlers_disconnect_by_func (display,
on_screen_monitors_changed, on_display_monitor_removed,
manager);
g_signal_handlers_disconnect_by_func (display,
on_display_monitor_added,
manager); manager);


for (l = manager->priv->windows; l; l = l->next) for (l = manager->priv->windows; l; l = l->next)
Expand Down Expand Up @@ -1753,9 +1737,11 @@ gs_manager_create_windows (GSManager *manager)
g_assert (manager->priv->windows == NULL); g_assert (manager->priv->windows == NULL);


display = gdk_display_get_default (); display = gdk_display_get_default ();
g_signal_connect (gdk_display_get_default_screen (display), g_signal_connect (display, "monitor-added",
"monitors-changed", G_CALLBACK (on_display_monitor_added),
G_CALLBACK (on_screen_monitors_changed), manager);
g_signal_connect (display, "monitor-removed",
G_CALLBACK (on_display_monitor_removed),
manager); manager);


gs_manager_create_windows_for_display (manager, display); gs_manager_create_windows_for_display (manager, display);
Expand Down
28 changes: 16 additions & 12 deletions src/gs-window-x11.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -366,10 +366,11 @@ update_geometry (GSWindow *window)
} }


static void static void
screen_size_changed (GdkScreen *screen, monitor_geometry_notify (GdkMonitor *monitor,
GSWindow *window) 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)); gtk_widget_queue_resize (GTK_WIDGET (window));
} }


Expand Down Expand Up @@ -418,8 +419,9 @@ gs_window_move_resize_window (GSWindow *window,
static void static void
gs_window_real_unrealize (GtkWidget *widget) gs_window_real_unrealize (GtkWidget *widget)
{ {
g_signal_handlers_disconnect_by_func (gtk_window_get_screen (GTK_WINDOW (widget)), GdkMonitor *monitor = GS_WINDOW (widget)->priv->monitor;
screen_size_changed,
g_signal_handlers_disconnect_by_func (monitor, monitor_geometry_notify,
widget); widget);


if (GTK_WIDGET_CLASS (gs_window_parent_class)->unrealize) if (GTK_WIDGET_CLASS (gs_window_parent_class)->unrealize)
Expand Down Expand Up @@ -575,6 +577,8 @@ widget_set_best_visual (GtkWidget *widget)
static void static void
gs_window_real_realize (GtkWidget *widget) gs_window_real_realize (GtkWidget *widget)
{ {
GdkMonitor *monitor = GS_WINDOW (widget)->priv->monitor;

widget_set_best_visual (widget); widget_set_best_visual (widget);


if (GTK_WIDGET_CLASS (gs_window_parent_class)->realize) if (GTK_WIDGET_CLASS (gs_window_parent_class)->realize)
Expand All @@ -586,9 +590,9 @@ gs_window_real_realize (GtkWidget *widget)


gs_window_move_resize_window (GS_WINDOW (widget), TRUE, TRUE); gs_window_move_resize_window (GS_WINDOW (widget), TRUE, TRUE);


g_signal_connect (gtk_window_get_screen (GTK_WINDOW (widget)), g_signal_connect (monitor,
"size_changed", "notify::geometry",
G_CALLBACK (screen_size_changed), G_CALLBACK (monitor_geometry_notify),
widget); widget);
} }


Expand Down Expand Up @@ -2557,12 +2561,12 @@ gs_window_finalize (GObject *object)
} }


GSWindow * GSWindow *
gs_window_new (GdkDisplay *display, gs_window_new (GdkMonitor *monitor,
GdkMonitor *monitor,
gboolean lock_enabled) gboolean lock_enabled)
{ {
GObject *result; GObject *result;
GdkScreen *screen = gdk_display_get_default_screen (display); GdkDisplay *display = gdk_monitor_get_display (monitor);
GdkScreen *screen = gdk_display_get_default_screen (display);


result = g_object_new (GS_TYPE_WINDOW, result = g_object_new (GS_TYPE_WINDOW,
"type", GTK_WINDOW_POPUP, "type", GTK_WINDOW_POPUP,
Expand Down
3 changes: 1 addition & 2 deletions src/gs-window.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ void gs_window_show_message (GSWindow *window,
void gs_window_request_unlock (GSWindow *window); void gs_window_request_unlock (GSWindow *window);
void gs_window_cancel_unlock_request (GSWindow *window); void gs_window_cancel_unlock_request (GSWindow *window);


GSWindow * gs_window_new (GdkDisplay *display, GSWindow * gs_window_new (GdkMonitor *monitor,
GdkMonitor *monitor,
gboolean lock_enabled); gboolean lock_enabled);
void gs_window_show (GSWindow *window); void gs_window_show (GSWindow *window);
void gs_window_destroy (GSWindow *window); void gs_window_destroy (GSWindow *window);
Expand Down
2 changes: 1 addition & 1 deletion src/test-window.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ test_window (void)
display = gdk_display_get_default (); display = gdk_display_get_default ();
monitor = gdk_display_get_primary_monitor (display); 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); gs_window_set_user_switch_enabled (window, user_switch_enabled);


Expand Down

0 comments on commit dbd37df

Please sign in to comment.