Commit 81c1c70c authored by Armin Krezović's avatar Armin Krezović Committed by Jonas Ådahl

Move workspace related code from MetaDisplay to MetaWorkspaceManager

https://bugzilla.gnome.org/show_bug.cgi?id=759538
parent e05cd600
......@@ -24,6 +24,7 @@
#include <config.h>
#include "boxes-private.h"
#include "constraints.h"
#include "meta-workspace-manager-private.h"
#include "workspace-private.h"
#include "place.h"
#include <meta/prefs.h>
......@@ -412,7 +413,7 @@ setup_constraint_info (ConstraintInfo *info,
&info->entire_monitor);
}
cur_workspace = window->display->active_workspace;
cur_workspace = window->display->workspace_manager->active_workspace;
info->usable_screen_region =
meta_workspace_get_onscreen_region (cur_workspace);
info->usable_monitor_region =
......@@ -499,7 +500,7 @@ place_window_if_needed(MetaWindow *window,
meta_window_get_work_area_for_logical_monitor (window,
logical_monitor,
&info->work_area_monitor);
cur_workspace = window->display->active_workspace;
cur_workspace = window->display->workspace_manager->active_workspace;
info->usable_monitor_region =
meta_workspace_get_onmonitor_region (cur_workspace, logical_monitor);
......@@ -926,6 +927,7 @@ constrain_maximization (MetaWindow *window,
ConstraintPriority priority,
gboolean check_only)
{
MetaWorkspaceManager *workspace_manager = window->display->workspace_manager;
MetaRectangle target_size;
MetaRectangle min_size, max_size;
gboolean hminbad, vminbad;
......@@ -965,7 +967,7 @@ constrain_maximization (MetaWindow *window,
direction = META_DIRECTION_HORIZONTAL;
else
direction = META_DIRECTION_VERTICAL;
active_workspace_struts = window->display->active_workspace->all_struts;
active_workspace_struts = workspace_manager->active_workspace->all_struts;
target_size = info->current;
meta_rectangle_expand_to_avoiding_struts (&target_size,
......
......@@ -24,6 +24,7 @@
#include <config.h>
#include "core.h"
#include "frame.h"
#include "meta-workspace-manager-private.h"
#include "workspace-private.h"
#include <meta/prefs.h>
#include <meta/meta-x11-errors.h>
......@@ -77,6 +78,8 @@ static gboolean
lower_window_and_transients (MetaWindow *window,
gpointer data)
{
MetaWorkspaceManager *workspace_manager = window->display->workspace_manager;
meta_window_lower (window);
meta_window_foreach_transient (window, lower_window_and_transients, NULL);
......@@ -87,22 +90,22 @@ lower_window_and_transients (MetaWindow *window,
* Do extra sanity checks to avoid possible race conditions.
* (Borrowed from window.c.)
*/
if (window->display->active_workspace &&
if (workspace_manager->active_workspace &&
meta_window_located_on_workspace (window,
window->display->active_workspace))
workspace_manager->active_workspace))
{
GList* link;
link = g_list_find (window->display->active_workspace->mru_list,
link = g_list_find (workspace_manager->active_workspace->mru_list,
window);
g_assert (link);
window->display->active_workspace->mru_list =
g_list_remove_link (window->display->active_workspace->mru_list,
workspace_manager->active_workspace->mru_list =
g_list_remove_link (workspace_manager->active_workspace->mru_list,
link);
g_list_free (link);
window->display->active_workspace->mru_list =
g_list_append (window->display->active_workspace->mru_list,
workspace_manager->active_workspace->mru_list =
g_list_append (workspace_manager->active_workspace->mru_list,
window);
}
}
......@@ -116,6 +119,7 @@ meta_core_user_lower_and_unfocus (Display *xdisplay,
guint32 timestamp)
{
MetaWindow *window = get_window (xdisplay, frame_xwindow);
MetaWorkspaceManager *workspace_manager = window->display->workspace_manager;
lower_window_and_transients (window, NULL);
......@@ -123,7 +127,7 @@ meta_core_user_lower_and_unfocus (Display *xdisplay,
* the focus window, assume that's always the case. (Typically,
* this will be invoked via keyboard action or by a mouse action;
* in either case the window or a modal child will have been focused.) */
meta_workspace_focus_default_window (window->display->active_workspace,
meta_workspace_focus_default_window (workspace_manager->active_workspace,
NULL,
timestamp);
}
......
......@@ -242,16 +242,6 @@ struct _MetaDisplay
guint work_area_later;
guint check_fullscreen_later;
MetaWorkspace *active_workspace;
GList *workspaces;
int rows_of_workspaces;
int columns_of_workspaces;
MetaDisplayCorner starting_corner;
guint vertical_workspaces : 1;
guint workspace_layout_overridden : 1;
MetaBell *bell;
MetaWorkspaceManager *workspace_manager;
};
......@@ -442,46 +432,4 @@ void meta_display_queue_check_fullscreen (MetaDisplay *display);
MetaWindow *meta_display_get_pointer_window (MetaDisplay *display,
MetaWindow *not_this_one);
void meta_display_init_workspaces (MetaDisplay *display);
void meta_display_update_workspace_layout (MetaDisplay *display,
MetaDisplayCorner starting_corner,
gboolean vertical_layout,
int n_rows,
int n_columns);
typedef struct MetaWorkspaceLayout MetaWorkspaceLayout;
struct MetaWorkspaceLayout
{
int rows;
int cols;
int *grid;
int grid_area;
int current_row;
int current_col;
};
void meta_display_calc_workspace_layout (MetaDisplay *display,
int num_workspaces,
int current_space,
MetaWorkspaceLayout *layout);
void meta_display_free_workspace_layout (MetaWorkspaceLayout *layout);
void meta_display_minimize_all_on_active_workspace_except (MetaDisplay *display,
MetaWindow *keep);
/* Show/hide the desktop (temporarily hide all windows) */
void meta_display_show_desktop (MetaDisplay *display,
guint32 timestamp);
void meta_display_unshow_desktop (MetaDisplay *display);
void meta_display_workspace_switched (MetaDisplay *display,
int from,
int to,
MetaMotionDirection direction);
void meta_display_update_num_workspaces (MetaDisplay *display,
guint32 timestamp,
int new_num);
#endif
This diff is collapsed.
......@@ -23,6 +23,7 @@
#include "edge-resistance.h"
#include "boxes-private.h"
#include "display-private.h"
#include "meta-workspace-manager-private.h"
#include "workspace-private.h"
/* A simple macro for whether a given window's edges are potentially
......@@ -999,6 +1000,7 @@ compute_resistance_and_snapping_edges (MetaDisplay *display)
* in the layer that we are working on
*/
GSList *rem_windows, *rem_win_stacking;
MetaWorkspaceManager *workspace_manager = display->workspace_manager;
g_assert (display->grab_window != NULL);
meta_topic (META_DEBUG_WINDOW_OPS,
......@@ -1010,7 +1012,7 @@ compute_resistance_and_snapping_edges (MetaDisplay *display)
*/
stacked_windows =
meta_stack_list_windows (display->stack,
display->active_workspace);
workspace_manager->active_workspace);
/*
* 2nd: we need to separate that stacked list into a list of windows that
......@@ -1172,8 +1174,8 @@ compute_resistance_and_snapping_edges (MetaDisplay *display)
*/
cache_edges (display,
edges,
display->active_workspace->monitor_edges,
display->active_workspace->screen_edges);
workspace_manager->active_workspace->monitor_edges,
workspace_manager->active_workspace->screen_edges);
g_list_free (edges);
/*
......
......@@ -29,6 +29,7 @@
#include <config.h>
#include "keybindings-private.h"
#include "meta-workspace-manager-private.h"
#include "workspace-private.h"
#include <meta/compositor.h>
#include <meta/meta-x11-errors.h>
......@@ -2733,8 +2734,9 @@ handle_switch_to_last_workspace (MetaDisplay *display,
MetaKeyBinding *binding,
gpointer dummy)
{
gint target = meta_display_get_n_workspaces(display) - 1;
MetaWorkspace *workspace = meta_display_get_workspace_by_index (display, target);
MetaWorkspaceManager *workspace_manager = display->workspace_manager;
gint target = meta_workspace_manager_get_n_workspaces (workspace_manager) - 1;
MetaWorkspace *workspace = meta_workspace_manager_get_workspace_by_index (workspace_manager, target);
meta_workspace_activate (workspace, event->time);
}
......@@ -2746,6 +2748,7 @@ handle_switch_to_workspace (MetaDisplay *display,
gpointer dummy)
{
gint which = binding->handler->data;
MetaWorkspaceManager *workspace_manager = display->workspace_manager;
MetaWorkspace *workspace;
if (which < 0)
......@@ -2754,12 +2757,12 @@ handle_switch_to_workspace (MetaDisplay *display,
* current workspace.
*/
workspace = meta_workspace_get_neighbor (display->active_workspace,
workspace = meta_workspace_get_neighbor (workspace_manager->active_workspace,
which);
}
else
{
workspace = meta_display_get_workspace_by_index (display, which);
workspace = meta_workspace_manager_get_workspace_by_index (workspace_manager, which);
}
if (workspace)
......@@ -2982,15 +2985,17 @@ handle_show_desktop (MetaDisplay *display,
MetaKeyBinding *binding,
gpointer dummy)
{
if (display->active_workspace->showing_desktop)
MetaWorkspaceManager *workspace_manager = display->workspace_manager;
if (workspace_manager->active_workspace->showing_desktop)
{
meta_display_unshow_desktop (display);
meta_workspace_focus_default_window (display->active_workspace,
meta_workspace_manager_unshow_desktop (workspace_manager);
meta_workspace_focus_default_window (workspace_manager->active_workspace,
NULL,
event->time);
}
else
meta_display_show_desktop (display, event->time);
meta_workspace_manager_show_desktop (workspace_manager, event->time);
}
static void
......@@ -3077,6 +3082,7 @@ do_choose_window (MetaDisplay *display,
MetaKeyBinding *binding,
gboolean backward)
{
MetaWorkspaceManager *workspace_manager = display->workspace_manager;
MetaTabList type = binding->handler->data;
MetaWindow *window;
......@@ -3085,7 +3091,7 @@ do_choose_window (MetaDisplay *display,
window = meta_display_get_tab_next (display,
type,
display->active_workspace,
workspace_manager->active_workspace,
NULL,
backward);
......@@ -3299,14 +3305,15 @@ handle_move_to_workspace_last (MetaDisplay *display,
MetaKeyBinding *binding,
gpointer dummy)
{
MetaWorkspaceManager *workspace_manager = display->workspace_manager;
gint which;
MetaWorkspace *workspace;
if (window->always_sticky)
return;
which = meta_display_get_n_workspaces (display) - 1;
workspace = meta_display_get_workspace_by_index (display, which);
which = meta_workspace_manager_get_n_workspaces (workspace_manager) - 1;
workspace = meta_workspace_manager_get_workspace_by_index (workspace_manager, which);
meta_window_change_workspace (window, workspace);
}
......@@ -3318,6 +3325,7 @@ handle_move_to_workspace (MetaDisplay *display,
MetaKeyBinding *binding,
gpointer dummy)
{
MetaWorkspaceManager *workspace_manager = display->workspace_manager;
gint which = binding->handler->data;
gboolean flip = (which < 0);
MetaWorkspace *workspace;
......@@ -3336,12 +3344,12 @@ handle_move_to_workspace (MetaDisplay *display,
workspace = NULL;
if (flip)
{
workspace = meta_workspace_get_neighbor (display->active_workspace,
workspace = meta_workspace_get_neighbor (workspace_manager->active_workspace,
which);
}
else
{
workspace = meta_display_get_workspace_by_index (display, which);
workspace = meta_workspace_manager_get_workspace_by_index (workspace_manager, which);
}
if (workspace)
......
......@@ -48,4 +48,49 @@ struct _MetaWorkspaceManager
MetaWorkspaceManager *meta_workspace_manager_new (MetaDisplay *display);
void meta_workspace_manager_init_workspaces (MetaWorkspaceManager *workspace_manager);
void meta_workspace_manager_update_workspace_layout (MetaWorkspaceManager *workspace_manager,
MetaDisplayCorner starting_corner,
gboolean vertical_layout,
int n_rows,
int n_columns);
void meta_workspace_manager_reload_work_areas (MetaWorkspaceManager *workspace_manager);
typedef struct MetaWorkspaceLayout MetaWorkspaceLayout;
struct MetaWorkspaceLayout
{
int rows;
int cols;
int *grid;
int grid_area;
int current_row;
int current_col;
};
void meta_workspace_manager_calc_workspace_layout (MetaWorkspaceManager *workspace_manager,
int num_workspaces,
int current_space,
MetaWorkspaceLayout *layout);
void meta_workspace_manager_free_workspace_layout (MetaWorkspaceLayout *layout);
void meta_workspace_manager_minimize_all_on_active_workspace_except (MetaWorkspaceManager *workspace_manager,
MetaWindow *keep);
/* Show/hide the desktop (temporarily hide all windows) */
void meta_workspace_manager_show_desktop (MetaWorkspaceManager *workspace_manager,
guint32 timestamp);
void meta_workspace_manager_unshow_desktop (MetaWorkspaceManager *workspace_manager);
void meta_workspace_manager_workspace_switched (MetaWorkspaceManager *workspace_manager,
int from,
int to,
MetaMotionDirection direction);
void meta_workspace_manager_update_num_workspaces (MetaWorkspaceManager *workspace_manager,
guint32 timestamp,
int new_num);
#endif /* META_WORKSPACE_MANAGER_PRIVATE_H */
This diff is collapsed.
......@@ -27,6 +27,7 @@
#include <config.h>
#include "stack.h"
#include "meta-workspace-manager-private.h"
#include "window-private.h"
#include <meta/meta-x11-errors.h>
#include "frame.h"
......@@ -101,6 +102,8 @@ void
meta_stack_add (MetaStack *stack,
MetaWindow *window)
{
MetaWorkspaceManager *workspace_manager = window->display->workspace_manager;
g_return_if_fail (meta_window_is_stackable (window));
meta_topic (META_DEBUG_STACK, "Adding window %s to the stack\n", window->desc);
......@@ -117,13 +120,15 @@ meta_stack_add (MetaStack *stack,
window->desc, window->stack_position);
stack_sync_to_xserver (stack);
meta_stack_update_window_tile_matches (stack, window->display->active_workspace);
meta_stack_update_window_tile_matches (stack, workspace_manager->active_workspace);
}
void
meta_stack_remove (MetaStack *stack,
MetaWindow *window)
{
MetaWorkspaceManager *workspace_manager = window->display->workspace_manager;
meta_topic (META_DEBUG_STACK, "Removing window %s from the stack\n", window->desc);
/* Set window to top position, so removing it will not leave gaps
......@@ -153,27 +158,29 @@ meta_stack_remove (MetaStack *stack,
}
stack_sync_to_xserver (stack);
meta_stack_update_window_tile_matches (stack, window->display->active_workspace);
meta_stack_update_window_tile_matches (stack, workspace_manager->active_workspace);
}
void
meta_stack_update_layer (MetaStack *stack,
MetaWindow *window)
{
MetaWorkspaceManager *workspace_manager = window->display->workspace_manager;
stack->need_relayer = TRUE;
stack_sync_to_xserver (stack);
meta_stack_update_window_tile_matches (stack, window->display->active_workspace);
meta_stack_update_window_tile_matches (stack, workspace_manager->active_workspace);
}
void
meta_stack_update_transient (MetaStack *stack,
MetaWindow *window)
{
MetaWorkspaceManager *workspace_manager = window->display->workspace_manager;
stack->need_constrain = TRUE;
stack_sync_to_xserver (stack);
meta_stack_update_window_tile_matches (stack, window->display->active_workspace);
meta_stack_update_window_tile_matches (stack, workspace_manager->active_workspace);
}
/* raise/lower within a layer */
......@@ -181,6 +188,7 @@ void
meta_stack_raise (MetaStack *stack,
MetaWindow *window)
{
MetaWorkspaceManager *workspace_manager = window->display->workspace_manager;
GList *l;
int max_stack_position = window->stack_position;
MetaWorkspace *workspace;
......@@ -202,13 +210,14 @@ meta_stack_raise (MetaStack *stack,
meta_window_set_stack_position_no_sync (window, max_stack_position);
stack_sync_to_xserver (stack);
meta_stack_update_window_tile_matches (stack, window->display->active_workspace);
meta_stack_update_window_tile_matches (stack, workspace_manager->active_workspace);
}
void
meta_stack_lower (MetaStack *stack,
MetaWindow *window)
{
MetaWorkspaceManager *workspace_manager = window->display->workspace_manager;
GList *l;
int min_stack_position = window->stack_position;
MetaWorkspace *workspace;
......@@ -230,7 +239,7 @@ meta_stack_lower (MetaStack *stack,
meta_window_set_stack_position_no_sync (window, min_stack_position);
stack_sync_to_xserver (stack);
meta_stack_update_window_tile_matches (stack, window->display->active_workspace);
meta_stack_update_window_tile_matches (stack, workspace_manager->active_workspace);
}
void
......@@ -1457,8 +1466,10 @@ void
meta_window_set_stack_position (MetaWindow *window,
int position)
{
MetaWorkspaceManager *workspace_manager = window->display->workspace_manager;
meta_window_set_stack_position_no_sync (window, position);
stack_sync_to_xserver (window->display->stack);
meta_stack_update_window_tile_matches (window->display->stack,
window->display->active_workspace);
workspace_manager->active_workspace);
}
......@@ -33,6 +33,7 @@
#include "util-private.h"
#include "frame.h"
#include <meta/meta-x11-errors.h>
#include "meta-workspace-manager-private.h"
#include "workspace-private.h"
#include "stack.h"
#include "keybindings-private.h"
......@@ -687,9 +688,10 @@ is_desktop_or_dock_foreach (MetaWindow *window,
static void
maybe_leave_show_desktop_mode (MetaWindow *window)
{
MetaWorkspaceManager *workspace_manager = window->display->workspace_manager;
gboolean is_desktop_or_dock;
if (!window->display->active_workspace->showing_desktop)
if (!workspace_manager->active_workspace->showing_desktop)
return;
/* If the window is a transient for the dock or desktop, don't
......@@ -706,9 +708,9 @@ maybe_leave_show_desktop_mode (MetaWindow *window)
if (!is_desktop_or_dock)
{
meta_display_minimize_all_on_active_workspace_except (window->display,
window);
meta_display_unshow_desktop (window->display);
meta_workspace_manager_minimize_all_on_active_workspace_except (workspace_manager,
window);
meta_workspace_manager_unshow_desktop (workspace_manager);
}
}
......@@ -929,6 +931,7 @@ _meta_window_shared_new (MetaDisplay *display,
MetaCompEffect effect,
XWindowAttributes *attrs)
{
MetaWorkspaceManager *workspace_manager = display->workspace_manager;
MetaWindow *window;
g_assert (attrs != NULL);
......@@ -1238,8 +1241,8 @@ _meta_window_shared_new (MetaDisplay *display,
"Window %s is initially on space %d\n",
window->desc, window->initial_workspace);
workspace = meta_display_get_workspace_by_index (window->display,
window->initial_workspace);
workspace = meta_workspace_manager_get_workspace_by_index (workspace_manager,
window->initial_workspace);
}
set_workspace_state (window, on_all_workspaces, workspace);
......@@ -1278,7 +1281,7 @@ _meta_window_shared_new (MetaDisplay *display,
"Putting window %s on active workspace\n",
window->desc);
set_workspace_state (window, FALSE, window->display->active_workspace);
set_workspace_state (window, FALSE, workspace_manager->active_workspace);
}
meta_window_update_struts (window);
......@@ -1378,6 +1381,7 @@ void
meta_window_unmanage (MetaWindow *window,
guint32 timestamp)
{
MetaWorkspaceManager *workspace_manager = window->display->workspace_manager;
GList *tmp;
meta_verbose ("Unmanaging %s\n", window->desc);
......@@ -1464,7 +1468,7 @@ meta_window_unmanage (MetaWindow *window,
meta_topic (META_DEBUG_FOCUS,
"Focusing default window since we're unmanaging %s\n",
window->desc);
meta_workspace_focus_default_window (window->display->active_workspace, NULL, timestamp);
meta_workspace_focus_default_window (workspace_manager->active_workspace, NULL, timestamp);
}
else
{
......@@ -1510,7 +1514,7 @@ meta_window_unmanage (MetaWindow *window,
g_assert (window->workspace == NULL);
#ifndef G_DISABLE_CHECKS
tmp = window->display->workspaces;
tmp = workspace_manager->workspaces;
while (tmp != NULL)
{
MetaWorkspace *workspace = tmp->data;
......@@ -1622,6 +1626,7 @@ ancestor_is_minimized (MetaWindow *window)
gboolean
meta_window_showing_on_its_workspace (MetaWindow *window)
{
MetaWorkspaceManager *workspace_manager = window->display->workspace_manager;
gboolean showing;
gboolean is_desktop_or_dock;
MetaWorkspace* workspace_of_window;
......@@ -1641,7 +1646,7 @@ meta_window_showing_on_its_workspace (MetaWindow *window)
&is_desktop_or_dock);
if (window->on_all_workspaces)
workspace_of_window = window->display->active_workspace;
workspace_of_window = workspace_manager->active_workspace;
else if (window->workspace)
workspace_of_window = window->workspace;
else /* This only seems to be needed for startup */
......@@ -1673,6 +1678,8 @@ meta_window_showing_on_its_workspace (MetaWindow *window)
gboolean
meta_window_should_be_showing (MetaWindow *window)
{
MetaWorkspaceManager *workspace_manager = window->display->workspace_manager;
#ifdef HAVE_WAYLAND
if (window->client_type == META_WINDOW_CLIENT_TYPE_WAYLAND &&
!meta_wayland_surface_get_buffer (window->surface))
......@@ -1681,7 +1688,7 @@ meta_window_should_be_showing (MetaWindow *window)
/* Windows should be showing if they're located on the
* active workspace and they're showing on their own workspace. */
return (meta_window_located_on_workspace (window, window->display->active_workspace) &&
return (meta_window_located_on_workspace (window, workspace_manager->active_workspace) &&
meta_window_showing_on_its_workspace (window));
}
......@@ -2551,6 +2558,7 @@ meta_window_show (MetaWindow *window)
static void
meta_window_hide (MetaWindow *window)
{
MetaWorkspaceManager *workspace_manager = window->display->workspace_manager;
gboolean did_hide;
meta_topic (META_DEBUG_WINDOW_STATE,
......@@ -2621,11 +2629,11 @@ meta_window_hide (MetaWindow *window)
* We also pass in NULL if we are in the process of hiding all non-desktop
* windows to avoid unexpected changes to the stacking order.
*/
if (my_workspace == window->display->active_workspace &&
if (my_workspace == workspace_manager->active_workspace &&
!my_workspace->showing_desktop)
not_this_one = window;
meta_workspace_focus_default_window (window->display->active_workspace,
meta_workspace_focus_default_window (workspace_manager->active_workspace,
not_this_one,
timestamp);
}
......@@ -3602,6 +3610,7 @@ meta_window_activate_full (MetaWindow *window,
MetaClientType source_indication,
MetaWorkspace *workspace)
{
MetaWorkspaceManager *workspace_manager = window->display->workspace_manager;
gboolean allow_workspace_switch;
meta_topic (