Add support for disabling dynamic workspaces

This commit is contained in:
Tom Beckmann 2012-12-26 01:05:42 +01:00
commit cf7c6fa378
5 changed files with 63 additions and 6 deletions

View File

@ -95,6 +95,11 @@
<summary>Shortcut to open the window overview for all windows</summary>
<description></description>
</key>
<key type="b" name="dynamic-workspaces">
<default>true</default>
<summary>Enable dynamic workspace instead of static ones</summary>
<description>Use a dynamically increasing or decreseasing number, as needed, of workspaces instead of a static, fixed number</description>
</key>
</schema>
<schema path="/org/pantheon/desktop/gala/appearance/" id="org.pantheon.desktop.gala.appearance" gettext-domain="gala">

View File

@ -57,6 +57,7 @@ namespace Gala
public Plugin ()
{
Prefs.set_ignore_request_hide_titlebar (true);
Prefs.override_preference_schema ("dynamic-workspaces", Config.SCHEMA + ".behavior");
Prefs.override_preference_schema ("attach-modal-dialogs", Config.SCHEMA + ".appearance");
Prefs.override_preference_schema ("button-layout", Config.SCHEMA + ".appearance");
Prefs.override_preference_schema ("edge-tiling", Config.SCHEMA + ".behavior");
@ -76,7 +77,8 @@ namespace Gala
stage.background_color = Clutter.Color.from_string (color);
stage.no_clear_hint = true;
screen.override_workspace_layout (ScreenCorner.TOPLEFT, false, 1, -1);
if (Prefs.get_dynamic_workspaces ())
screen.override_workspace_layout (ScreenCorner.TOPLEFT, false, 1, -1);
workspace_view = new WorkspaceView (this);
workspace_view.visible = false;

View File

@ -19,6 +19,7 @@ namespace Gala
{
public class BehaviorSettings : Granite.Services.Settings
{
public bool dynamic_workspaces { get; set; }
public bool edge_tiling { get; set; }
public string panel_main_menu_action { get; set; }
public string toggle_recording_action { get; set; }

View File

@ -327,6 +327,9 @@ namespace Gala
void check_last_workspace ()
{
if (!Prefs.get_dynamic_workspaces ())
return;
//last workspace, show plus button and so on
//give the last one a different style
@ -372,12 +375,15 @@ namespace Gala
});
return;
}
if (visible) {
update_windows ();
update_icons ();
}
if (!Prefs.get_dynamic_workspaces ())
return;
if (workspace != null && workspace.index () == screen.n_workspaces - 1 && Utils.get_n_windows (workspace) > 0)
window_on_last ();
}
@ -387,6 +393,9 @@ namespace Gala
if (visible)
update_windows ();
if (!Prefs.get_dynamic_workspaces ())
return;
//dont remove workspaces when for example slingshot was closed
if (window.window_type != WindowType.NORMAL &&
window.window_type != WindowType.DIALOG &&
@ -442,6 +451,9 @@ namespace Gala
if (workspace == null)
return true;
if (!Prefs.get_dynamic_workspaces ())
return false;
if (workspace.index () == screen.n_workspaces - 1) {
wallpaper.animate (AnimationMode.EASE_OUT_QUAD, 300, opacity : 210);
return true;

View File

@ -86,6 +86,24 @@ namespace Gala
int swidth, sheight;
screen.get_size (out swidth, out sheight);
y = sheight;
screen.workspace_added.connect ((index) => {
create_workspace_thumb (screen.get_workspace_by_index (index));
});
Prefs.add_listener ((pref) => {
// only need to listen for the case when workspaces were removed.
// Any other case will be caught by the workspace_added signal.
// For some reason workspace_removed is not emitted, when changing the workspace number
if (Prefs.get_dynamic_workspaces () ||
pref != Preference.NUM_WORKSPACES ||
Prefs.get_num_workspaces () > thumbnails.get_n_children ())
return;
for (int i = Prefs.get_num_workspaces () - 1; i < thumbnails.get_n_children (); i++) {
(thumbnails.get_child_at_index (i) as WorkspaceThumb).closed ();
}
});
}
//method that waits for the workspaces to be configured on first run
@ -95,6 +113,20 @@ namespace Gala
var workspaces = screen.get_workspaces ().copy ();
if (!Prefs.get_dynamic_workspaces ()) {
foreach (var workspace in workspaces) {
var thumb = new WorkspaceThumb (workspace);
thumb.clicked.connect (hide);
thumb.closed.connect (remove_workspace);
thumb.window_on_last.connect (add_workspace);
thumbnails.add_child (thumb);
}
//and we're done
return;
}
//remove everything except for the first
for (var i = 1; i < workspaces.length (); i++)
screen.remove_workspace (workspaces.nth_data (i), screen.get_display ().get_current_time ());
@ -158,17 +190,21 @@ namespace Gala
void add_workspace ()
{
var screen = plugin.get_screen ();
var wp = screen.append_new_workspace (false, screen.get_display ().get_current_time ());
if (wp == null)
return;
}
void create_workspace_thumb (Meta.Workspace workspace)
{
var screen = plugin.get_screen ();
var thumb = new WorkspaceThumb (wp);
var thumb = new WorkspaceThumb (workspace);
thumb.clicked.connect (hide);
thumb.closed.connect (remove_workspace);
thumb.window_on_last.connect (add_workspace);
thumbnails.add_child (thumb);
thumbnails.insert_child_at_index (thumb, workspace.index ());
thumb.show ();
@ -188,7 +224,8 @@ namespace Gala
var workspace = thumb.workspace;
if (workspace != null && workspace.index () > -1) { //dont remove non existing workspaces
//dont remove non existing workspaces
if (workspace != null && workspace.index () > -1) {
var screen = workspace.get_screen ();
screen.remove_workspace (workspace, screen.get_display ().get_current_time ());
}