From 14b0a83f64134fd6669d580558e10b4a225cb1d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Thu, 9 Apr 2015 12:20:24 +0800 Subject: [PATCH] Don't calculate the main window monitor every time it`s needed The main monitor of a window is maintained as 'window->monitor' and is updated when the window is resized or moved. Lets avoid calculating it every time it`s needed. https://bugzilla.gnome.org/show_bug.cgi?id=744934 --- src/core/keybindings.c | 2 +- src/core/screen-private.h | 4 ++-- src/core/screen.c | 4 ++-- src/core/stack.c | 3 +-- src/core/window.c | 14 ++++++-------- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/core/keybindings.c b/src/core/keybindings.c index 981a012a1..08d77ae80 100644 --- a/src/core/keybindings.c +++ b/src/core/keybindings.c @@ -3186,7 +3186,7 @@ handle_move_to_monitor (MetaDisplay *display, gint which = binding->handler->data; const MetaMonitorInfo *current, *new; - current = meta_screen_get_monitor_for_window (screen, window); + current = window->monitor; new = meta_screen_get_monitor_neighbor (screen, current->number, which); if (new == NULL) diff --git a/src/core/screen-private.h b/src/core/screen-private.h index bc3b5ac2b..40eae6e1b 100644 --- a/src/core/screen-private.h +++ b/src/core/screen-private.h @@ -149,8 +149,8 @@ const MetaMonitorInfo* meta_screen_get_current_monitor_info_for_pos (MetaScree int y); const MetaMonitorInfo* meta_screen_get_monitor_for_rect (MetaScreen *screen, MetaRectangle *rect); -const MetaMonitorInfo* meta_screen_get_monitor_for_window (MetaScreen *screen, - MetaWindow *window); +const MetaMonitorInfo* meta_screen_calculate_monitor_for_window (MetaScreen *screen, + MetaWindow *window); const MetaMonitorInfo* meta_screen_get_monitor_neighbor (MetaScreen *screen, diff --git a/src/core/screen.c b/src/core/screen.c index bef429b9a..ca810d975 100644 --- a/src/core/screen.c +++ b/src/core/screen.c @@ -1439,8 +1439,8 @@ meta_screen_get_monitor_for_rect (MetaScreen *screen, } const MetaMonitorInfo* -meta_screen_get_monitor_for_window (MetaScreen *screen, - MetaWindow *window) +meta_screen_calculate_monitor_for_window (MetaScreen *screen, + MetaWindow *window) { MetaRectangle window_rect; diff --git a/src/core/stack.c b/src/core/stack.c index 8b4dc00cb..87dade1d8 100644 --- a/src/core/stack.c +++ b/src/core/stack.c @@ -288,8 +288,7 @@ windows_on_different_monitor (MetaWindow *a, if (a->screen != b->screen) return TRUE; - return meta_screen_get_monitor_for_window (a->screen, a) != - meta_screen_get_monitor_for_window (b->screen, b); + return a->monitor != b->monitor; } /* Get layer ignoring any transient or group relationships */ diff --git a/src/core/window.c b/src/core/window.c index 212ae1826..6b5836783 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -981,7 +981,8 @@ _meta_window_shared_new (MetaDisplay *display, window->compositor_private = NULL; - window->monitor = meta_screen_get_monitor_for_window (window->screen, window); + window->monitor = meta_screen_calculate_monitor_for_window (window->screen, + window); window->preferred_output_winsys_id = window->monitor->winsys_id; window->tile_match = NULL; @@ -3546,7 +3547,8 @@ meta_window_update_monitor (MetaWindow *window, const MetaMonitorInfo *old; old = window->monitor; - window->monitor = meta_screen_get_monitor_for_window (window->screen, window); + window->monitor = meta_screen_calculate_monitor_for_window (window->screen, + window); if (old != window->monitor) { meta_window_on_all_workspaces_changed (window); @@ -5638,7 +5640,7 @@ update_move (MetaWindow *window, int monitor; window->tile_mode = META_TILE_NONE; - wmonitor = meta_screen_get_monitor_for_window (window->screen, window); + wmonitor = window->monitor; for (monitor = 0; monitor < window->screen->n_monitor_infos; monitor++) { @@ -6047,12 +6049,8 @@ void meta_window_get_work_area_current_monitor (MetaWindow *window, MetaRectangle *area) { - const MetaMonitorInfo *monitor = NULL; - monitor = meta_screen_get_monitor_for_window (window->screen, - window); - meta_window_get_work_area_for_monitor (window, - monitor->number, + window->monitor->number, area); }