Fix crash resulting from missing removal of workspaces when their number changes

This commit is contained in:
Tom Beckmann 2012-12-24 17:43:00 +01:00
parent 813ab28e25
commit 374a254a00
2 changed files with 31 additions and 9 deletions

View File

@ -451,14 +451,14 @@ namespace Gala
if (workspace == null) if (workspace == null)
return true; return true;
if (!Prefs.get_dynamic_workspaces ())
return false;
if (workspace.index () == screen.n_workspaces - 1) { if (workspace.index () == screen.n_workspaces - 1) {
wallpaper.animate (AnimationMode.EASE_OUT_QUAD, 300, opacity : 210); wallpaper.animate (AnimationMode.EASE_OUT_QUAD, 300, opacity : 210);
return true; return true;
} }
if (!Prefs.get_dynamic_workspaces ())
return false;
//dont allow closing the tab if it's the last one used //dont allow closing the tab if it's the last one used
if (workspace.index () == 0 && screen.n_workspaces == 2) if (workspace.index () == 0 && screen.n_workspaces == 2)
return false; return false;

View File

@ -86,6 +86,23 @@ namespace Gala
int swidth, sheight; int swidth, sheight;
screen.get_size (out swidth, out sheight); screen.get_size (out swidth, out sheight);
y = sheight; y = sheight;
screen.workspace_added.connect ((obj) => {
create_workspace_thumb (screen.get_workspace_by_index (obj));
});
Prefs.add_listener ((pref) => {
if (!Prefs.get_dynamic_workspaces () && pref == Preference.NUM_WORKSPACES) {
// 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_num_workspaces () < thumbnails.get_n_children ()) {
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 //method that waits for the workspaces to be configured on first run
@ -172,17 +189,21 @@ namespace Gala
void add_workspace () void add_workspace ()
{ {
var screen = plugin.get_screen ();
var wp = screen.append_new_workspace (false, screen.get_display ().get_current_time ()); var wp = screen.append_new_workspace (false, screen.get_display ().get_current_time ());
if (wp == null) if (wp == null)
return; return;
}
var thumb = new WorkspaceThumb (wp); void create_workspace_thumb (Meta.Workspace workspace)
{
var screen = plugin.get_screen ();
var thumb = new WorkspaceThumb (workspace);
thumb.clicked.connect (hide); thumb.clicked.connect (hide);
thumb.closed.connect (remove_workspace); thumb.closed.connect (remove_workspace);
thumb.window_on_last.connect (add_workspace); thumb.window_on_last.connect (add_workspace);
thumbnails.add_child (thumb); thumbnails.insert_child_at_index (thumb, workspace.index ());
thumb.show (); thumb.show ();
@ -202,7 +223,8 @@ namespace Gala
var workspace = thumb.workspace; 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 (); var screen = workspace.get_screen ();
screen.remove_workspace (workspace, screen.get_display ().get_current_time ()); screen.remove_workspace (workspace, screen.get_display ().get_current_time ());
} }