static gboolean manager_maybe_grab_window (GSManager *manager, GSWindow *window) { GdkDisplay *display; GdkScreen *screen; int monitor; int x, y; gboolean grabbed; display = gdk_display_get_default (); gdk_display_get_pointer (display, &screen, &x, &y, NULL); monitor = gdk_screen_get_monitor_at_point (screen, x, y); gdk_flush (); grabbed = FALSE; if (gs_window_get_screen (window) == screen && gs_window_get_monitor (window) == monitor) { gs_debug ("Moving grab to %p", window); gs_grab_move_to_window (manager->priv->grab, gs_window_get_gdk_window (window), gs_window_get_screen (window), FALSE); grabbed = TRUE; } return grabbed; }
static gboolean manager_maybe_grab_window (GSManager *manager, GSWindow *window) { GdkDisplay *display; GdkScreen *screen; int monitor; int x, y; gboolean grabbed; display = gdk_display_get_default (); #if GTK_CHECK_VERSION(3, 0, 0) GdkDeviceManager *device_manager = gdk_display_get_device_manager (display); GdkDevice *pointer = gdk_device_manager_get_client_pointer (device_manager); gdk_device_get_position (pointer, &screen, &x, &y); #else gdk_display_get_pointer (display, &screen, &x, &y, NULL); #endif monitor = gdk_screen_get_monitor_at_point (screen, x, y); gdk_flush (); grabbed = FALSE; if (gs_window_get_screen (window) == screen && gs_window_get_monitor (window) == monitor) { gs_debug ("Moving grab to %p", window); gs_grab_move_to_window (manager->priv->grab, gs_window_get_gdk_window (window), gs_window_get_screen (window), TRUE); grabbed = TRUE; } return grabbed; }
static gboolean manager_maybe_grab_window (GSManager *manager, GSWindow *window) { GdkDisplay *display; GdkDevice *device; GdkMonitor *monitor; int x, y; gboolean grabbed; display = gdk_display_get_default (); device = gdk_seat_get_pointer (gdk_display_get_default_seat (display)); gdk_device_get_position (device, NULL, &x, &y); monitor = gdk_display_get_monitor_at_point (display, x, y); gdk_display_flush (display); grabbed = FALSE; if (gs_window_get_display (window) == display && gs_window_get_monitor (window) == monitor) { gs_debug ("Initiate grab move to %p", window); gs_grab_move_to_window (manager->priv->grab, gs_window_get_gdk_window (window), gs_window_get_display (window), FALSE, FALSE); grabbed = TRUE; } return grabbed; }
static void on_screen_monitors_changed (GdkScreen *screen, GSManager *manager) { GSList *l; int n_monitors; int n_windows; int i; n_monitors = gdk_screen_get_n_monitors (screen); n_windows = g_slist_length (manager->priv->windows); gs_debug ("Monitors changed for screen %d: num=%d", gdk_screen_get_number (screen), n_monitors); if (n_monitors > n_windows) { /* add more windows */ for (i = n_windows; i < n_monitors; i++) { gs_manager_create_window_for_monitor (manager, screen, i); } } else { gdk_x11_grab_server (); /* remove the extra windows */ l = manager->priv->windows; while (l != NULL) { GdkScreen *this_screen; int this_monitor; GSList *next = l->next; this_screen = gs_window_get_screen (GS_WINDOW (l->data)); this_monitor = gs_window_get_monitor (GS_WINDOW (l->data)); if (this_screen == screen && this_monitor >= n_monitors) { gs_window_destroy (GS_WINDOW (l->data)); manager->priv->windows = g_slist_delete_link (manager->priv->windows, l); } l = next; } gdk_flush (); gdk_x11_ungrab_server (); } for (l = manager->priv->windows; l != NULL; l = l->next) { GdkScreen *this_screen; this_screen = gs_window_get_screen (GS_WINDOW (l->data)); if (this_screen == screen) { gtk_widget_queue_resize (GTK_WIDGET (l->data)); } } }
static GSWindow * find_window_at_pointer (GSManager *manager) { GdkDisplay *display; GdkDevice *device; GdkMonitor *monitor; int x, y; GSWindow *window; GSList *l; display = gdk_display_get_default (); device = gdk_seat_get_pointer (gdk_display_get_default_seat (display)); gdk_device_get_position (device, NULL, &x, &y); monitor = gdk_display_get_monitor_at_point (display, x, y); /* Find the gs-window that is on that monitor */ window = NULL; for (l = manager->priv->windows; l; l = l->next) { GSWindow *win = GS_WINDOW (l->data); if (gs_window_get_display (win) == display && gs_window_get_monitor (win) == monitor) { window = win; } } if (window == NULL) { gs_debug ("WARNING: Could not find the GSWindow for display %s", gdk_display_get_name (display)); /* take the first one */ window = manager->priv->windows->data; } else { gs_debug ("Requesting unlock for display %s", gdk_display_get_name (display)); } return window; }
static GSWindow * find_window_at_pointer (GSManager *manager) { GdkDisplay *display; GdkScreen *screen; int monitor; int x, y; GSWindow *window; int screen_num; GSList *l; display = gdk_display_get_default (); gdk_display_get_pointer (display, &screen, &x, &y, NULL); monitor = gdk_screen_get_monitor_at_point (screen, x, y); screen_num = gdk_screen_get_number (screen); /* Find the gs-window that is on that screen */ window = NULL; for (l = manager->priv->windows; l; l = l->next) { GSWindow *win = GS_WINDOW (l->data); if (gs_window_get_screen (win) == screen && gs_window_get_monitor (win) == monitor) { window = win; } } if (window == NULL) { gs_debug ("WARNING: Could not find the GSWindow for screen %d", screen_num); /* take the first one */ window = manager->priv->windows->data; } else { gs_debug ("Requesting unlock for screen %d", screen_num); } return window; }
static void on_display_monitor_removed (GdkDisplay *display, GdkMonitor *monitor, GSManager *manager) { GSList *l; int n_monitors; n_monitors = gdk_display_get_n_monitors (display); gs_debug ("Monitor removed on display %s, now there are %d", gdk_display_get_name (display), n_monitors); gdk_x11_grab_server (); /* 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) { 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 (); }
static void on_screen_monitors_changed (GdkScreen *screen, GSManager *manager) { GSList *l; int n_monitors; int n_windows; int i; n_monitors = gdk_screen_get_n_monitors (screen); n_windows = g_slist_length (manager->priv->windows); gs_debug ("Monitors changed for screen %d: num=%d", gdk_screen_get_number (screen), n_monitors); if (n_monitors > n_windows) { /* 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 more windows */ for (i = n_windows; i < n_monitors; i++) { gs_manager_create_window_for_monitor (manager, screen, i); } /* And put unlock dialog up where ever it's supposed to be */ gs_manager_request_unlock (manager); } else { gdk_x11_grab_server (); /* remove the extra windows */ l = manager->priv->windows; while (l != NULL) { GdkScreen *this_screen; int this_monitor; GSList *next = l->next; this_screen = gs_window_get_screen (GS_WINDOW (l->data)); this_monitor = gs_window_get_monitor (GS_WINDOW (l->data)); if (this_screen == screen && this_monitor >= n_monitors) { 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, * and that the keyboard is still properly grabbed after all * the windows above got destroyed*/ if (n_windows > n_monitors) { gs_manager_request_unlock (manager); } gdk_flush (); gdk_x11_ungrab_server (); } }