Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions data/gala.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@
<summary>What action should be performed on Super + Scroll</summary>
<description></description>
</key>
<key type="i" name="permanent-workspaces">
<default>0</default>
<summary>How many workspaces should be permanent</summary>
<description></description>
</key>
</schema>

<schema path="/io/elementary/desktop/wm/keybindings/" id="io.elementary.desktop.wm.keybindings">
Expand Down
20 changes: 20 additions & 0 deletions src/DesktopIntegration.vala
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,24 @@ public class Gala.DesktopIntegration : GLib.Object {

wm.window_overview.open (hints);
}

public void set_workspace_permanent (int index, bool permanent) throws DBusError, IOError {
unowned var manager = wm.get_display ().get_workspace_manager ();

if (index < 0 || index >= manager.n_workspaces) {
throw new IOError.FAILED ("Invalid workspace index");
}

WorkspaceManager.get_default ().set_permanent (manager.get_workspace_by_index (index), permanent);
}

public bool is_workspace_permanent (int index) throws DBusError, IOError {
unowned var manager = wm.get_display ().get_workspace_manager ();

if (index < 0 || index >= manager.n_workspaces) {
throw new IOError.FAILED ("Invalid workspace index");
}

return WorkspaceManager.get_default ().is_permanent (manager.get_workspace_by_index (index));
}
}
20 changes: 4 additions & 16 deletions src/InternalUtils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,14 @@ namespace Gala {
* @param new_window A window that should be moved to the new workspace
*/
public static void insert_workspace_with_window (int index, Meta.Window new_window) {
unowned var manager = new_window.get_display ().get_workspace_manager ();
unowned WorkspaceManager workspace_manager = WorkspaceManager.get_default ();
workspace_manager.freeze_remove ();

new_window.change_workspace_by_index (index, false);

unowned List<Meta.WindowActor> actors = new_window.get_display ().get_window_actors ();
foreach (unowned Meta.WindowActor actor in actors) {
if (actor.is_destroyed ())
continue;

unowned Meta.Window window = actor.get_meta_window ();
if (window == new_window)
continue;
var new_workspace = manager.append_new_workspace (false, Meta.CURRENT_TIME);
manager.reorder_workspace (new_workspace, index);

var current_index = window.get_workspace ().index ();
if (current_index >= index
&& !window.on_all_workspaces) {
window.change_workspace_by_index (current_index + 1, true);
}
}
new_window.change_workspace_by_index (index, false);

workspace_manager.thaw_remove ();
}
Expand Down
53 changes: 41 additions & 12 deletions src/WorkspaceManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class Gala.WorkspaceManager : Object {

public WindowManager wm { get; construct; }

private Settings behavior_settings;

private Gee.LinkedList<Meta.Workspace> workspaces_marked_removed;
private int remove_freeze_count = 0;

Expand All @@ -37,9 +39,23 @@ public class Gala.WorkspaceManager : Object {

construct {
workspaces_marked_removed = new Gee.LinkedList<Meta.Workspace> ();
behavior_settings = new GLib.Settings ("io.elementary.desktop.wm.behavior");

unowned Meta.Display display = wm.get_display ();
unowned Meta.WorkspaceManager manager = display.get_workspace_manager ();

for (int i = 0; i < behavior_settings.get_int ("permanent-workspaces"); i++) {
Meta.Workspace workspace;
if (i < manager.get_n_workspaces ()) {
workspace = manager.get_workspace_by_index (i);
} else {
workspace = manager.append_new_workspace (false, display.get_current_time ());
}
workspace.set_data<bool> ("permanent", true);
}

append_workspace ();

// There are some empty workspace at startup
cleanup ();

Expand All @@ -58,13 +74,6 @@ public class Gala.WorkspaceManager : Object {
manager.workspace_removed.connect_after (workspace_removed);
display.window_entered_monitor.connect (window_entered_monitor);
display.window_left_monitor.connect (window_left_monitor);

// make sure the last workspace has no windows on it
if (Meta.Prefs.get_dynamic_workspaces ()
&& Utils.get_n_windows (manager.get_workspace_by_index (manager.get_n_workspaces () - 1)) > 0
) {
append_workspace ();
}
}

~WorkspaceManager () {
Expand Down Expand Up @@ -114,6 +123,7 @@ public class Gala.WorkspaceManager : Object {
var prev_workspace = manager.get_workspace_by_index (from);
if (Utils.get_n_windows (prev_workspace) < 1
&& from != manager.get_n_workspaces () - 1
&& !is_permanent (prev_workspace)
) {

// If we're about to remove a workspace, cancel any DnD going on in the multitasking view
Expand Down Expand Up @@ -177,15 +187,14 @@ public class Gala.WorkspaceManager : Object {
&& remove_freeze_count < 1
&& Utils.get_n_windows (workspace, true, window) == 0
&& workspace != last_workspace
&& !is_permanent (workspace)
) {
queue_remove_workspace (workspace);
}

// if window is the second last and empty, make it the last workspace
if (is_active_workspace
} else if (is_active_workspace // if window is the second last and empty, make it the last workspace
&& remove_freeze_count < 1
&& Utils.get_n_windows (workspace, true, window) == 0
&& workspace.index () == last_workspace_index - 1
&& !is_permanent (workspace)
) {
queue_remove_workspace (last_workspace);
}
Expand Down Expand Up @@ -301,9 +310,29 @@ public class Gala.WorkspaceManager : Object {

foreach (var workspace in manager.get_workspaces ()) {
var last_index = manager.get_n_workspaces () - 1;
if (Utils.get_n_windows (workspace) == 0 && workspace.index () != last_index) {
if (Utils.get_n_windows (workspace) == 0 && workspace.index () != last_index && !is_permanent (workspace)) {
queue_remove_workspace (workspace);
}
}
}

public void set_permanent (Meta.Workspace workspace, bool permanent) {
workspace.set_data<bool> ("permanent", permanent);

unowned var manager = wm.get_display ().get_workspace_manager ();
int n_permanent = 0;
foreach (var ws in manager.get_workspaces ()) {
if (ws.get_data<bool> ("permanent")) {
n_permanent++;
}
}

behavior_settings.set_int ("permanent-workspaces", n_permanent);

cleanup ();
}

public bool is_permanent (Meta.Workspace workspace) {
return workspace.get_data<bool> ("permanent");
}
}