From 8b220079d0aef9d61a1f3ef052c52eb46c0c7501 Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Mon, 24 Jan 2011 15:40:30 -0500 Subject: [PATCH] Add ability to override workspace layout A plugin that does workspace management on its on may want to set the workspace layout without having to deal with putting a property on the root window to be read back and parsed. Add meta_screen_override_window_layout() that allows the same types of layouts as _NET_DESKTOP_LAYOUT but without setting a property. https://bugzilla.gnome.org/show_bug.cgi?id=640552 --- src/core/screen-private.h | 9 +-------- src/core/screen.c | 40 +++++++++++++++++++++++++++++++++++++++ src/include/screen.h | 13 +++++++++++++ 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/core/screen-private.h b/src/core/screen-private.h index f64f7458c..c7373e258 100644 --- a/src/core/screen-private.h +++ b/src/core/screen-private.h @@ -50,14 +50,6 @@ struct _MetaMonitorInfo typedef void (* MetaScreenWindowFunc) (MetaScreen *screen, MetaWindow *window, gpointer user_data); -typedef enum -{ - META_SCREEN_TOPLEFT, - META_SCREEN_TOPRIGHT, - META_SCREEN_BOTTOMLEFT, - META_SCREEN_BOTTOMRIGHT -} MetaScreenCorner; - typedef enum { META_SCREEN_UP, @@ -127,6 +119,7 @@ struct _MetaScreen int columns_of_workspaces; MetaScreenCorner starting_corner; guint vertical_workspaces : 1; + guint workspace_layout_overridden : 1; guint keys_grabbed : 1; guint all_keys_grabbed : 1; diff --git a/src/core/screen.c b/src/core/screen.c index 502d149c8..b656c25f0 100644 --- a/src/core/screen.c +++ b/src/core/screen.c @@ -2163,6 +2163,9 @@ meta_screen_update_workspace_layout (MetaScreen *screen) { gulong *list; int n_items; + + if (screen->workspace_layout_overridden) + return; list = NULL; n_items = 0; @@ -2249,6 +2252,43 @@ meta_screen_update_workspace_layout (MetaScreen *screen) screen->starting_corner); } +/** + * meta_screen_override_workspace_layout: + * @screen: a #MetaScreen + * @starting_corner: the corner at which the first workspace is found + * @vertical_layout: if %TRUE the workspaces are laid out in columns rather than rows + * @n_rows: number of rows of workspaces, or -1 to determine the number of rows from + * @n_columns and the total number of workspaces + * @n_columns: number of columns of workspaces, or -1 to determine the number of columns from + * @n_rows and the total number of workspaces + * + * Explicitly set the layout of workspaces. Once this has been called, the contents of the + * _NET_DESKTOP_LAYOUT property on the root window are completely ignored. + */ +void +meta_screen_override_workspace_layout (MetaScreen *screen, + MetaScreenCorner starting_corner, + gboolean vertical_layout, + int n_rows, + int n_columns) +{ + g_return_if_fail (META_IS_SCREEN (screen)); + g_return_if_fail (n_rows > 0 || n_columns > 0); + g_return_if_fail (n_rows != 0 && n_columns != 0); + + screen->workspace_layout_overridden = TRUE; + screen->vertical_workspaces = vertical_layout != FALSE; + screen->starting_corner = starting_corner; + screen->rows_of_workspaces = n_rows; + screen->columns_of_workspaces = n_columns; + + /* In theory we should remove _NET_DESKTOP_LAYOUT from _NET_SUPPORTED at this + * point, but it's unlikely that anybody checks that, and it's unlikely that + * anybody who checks that handles changes, so we'd probably just create + * a race condition. And it's hard to implement with the code in set_supported_hint() + */ +} + static void set_workspace_names (MetaScreen *screen) { diff --git a/src/include/screen.h b/src/include/screen.h index d3f816e81..9b5de83dc 100644 --- a/src/include/screen.h +++ b/src/include/screen.h @@ -80,4 +80,17 @@ void meta_screen_get_monitor_geometry (MetaScreen *screen, int monitor, MetaRectangle *geometry); +typedef enum +{ + META_SCREEN_TOPLEFT, + META_SCREEN_TOPRIGHT, + META_SCREEN_BOTTOMLEFT, + META_SCREEN_BOTTOMRIGHT +} MetaScreenCorner; + +void meta_screen_override_workspace_layout (MetaScreen *screen, + MetaScreenCorner starting_corner, + gboolean vertical_layout, + int n_rows, + int n_columns); #endif