make placement of icon groups more stable, prepare for window insert code

This commit is contained in:
Tom Beckmann 2014-06-22 18:17:16 +02:00
parent 7c190df02c
commit 1dd51b4ae4
4 changed files with 85 additions and 12 deletions

View File

@ -52,6 +52,7 @@ gala_VALASOURCES = \
Widgets/WindowSwitcher.vala \
Widgets/WindowThumb.vala \
Widgets/MultitaskingView/IconGroup.vala \
Widgets/MultitaskingView/IconGroupContainer.vala \
Widgets/MultitaskingView/MonitorClone.vala \
Widgets/MultitaskingView/MultitaskingView.vala \
Widgets/MultitaskingView/TiledWindow.vala \

View File

@ -0,0 +1,71 @@
//
// Copyright (C) 2014 Tom Beckmann
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
using Clutter;
using Meta;
namespace Gala
{
// TODO: allow DnD to insert new workspaces
public class IconGroupContainer : Actor
{
const int SPACING = 48;
public Screen screen { get; construct; }
public IconGroupContainer (Screen screen)
{
Object (screen: screen);
}
void update_positions ()
{
unowned List<Workspace> existing_workspaces = screen.get_workspaces ();
foreach (var child in get_children ()) {
var icon_group = child as IconGroup;
// we don't use meta_workspace_index() here because it crashes
// the wm if the workspace has already been removed. This could
// happen here if two workspaces are removed very shortly after
// each other and a transition is still playing. Also,
// meta_workspace_index() does the exact same thing.
var index = existing_workspaces.index (icon_group.workspace);
if (index < 0)
child.visible = false;
else
child.x = index * (child.width + SPACING);
}
}
public void add_group (IconGroup group)
{
add_child (group);
update_positions ();
}
public void remove_group (IconGroup group)
{
remove_child (group);
update_positions ();
}
}
}

View File

@ -30,7 +30,7 @@ namespace Gala
List<MonitorClone> window_containers_monitors;
Actor icon_groups;
IconGroupContainer icon_groups;
Actor workspaces;
public MultitaskingView (WindowManager wm)
@ -44,9 +44,7 @@ namespace Gala
workspaces = new Actor ();
workspaces.set_easing_mode (AnimationMode.EASE_OUT_QUAD);
icon_groups = new Actor ();
icon_groups.layout_manager = new BoxLayout ();
(icon_groups.layout_manager as BoxLayout).spacing = 48;
icon_groups = new IconGroupContainer (screen);
add_child (icon_groups);
add_child (workspaces);
@ -82,7 +80,9 @@ namespace Gala
if (existing_workspaces.index (workspace_clone.workspace) < 0) {
workspace_clone.window_selected.disconnect (window_selected);
workspace_clone.selected.disconnect (activate_workspace);
workspace_clone.icon_group.destroy ();
icon_groups.remove_group (workspace_clone.icon_group);
workspace_clone.destroy ();
}
}
@ -187,7 +187,7 @@ namespace Gala
workspace.selected.connect (activate_workspace);
workspaces.insert_child_at_index (workspace, num);
icon_groups.insert_child_at_index (workspace.icon_group, num);
icon_groups.add_group (workspace.icon_group);
update_positions (opened);
@ -223,10 +223,11 @@ namespace Gala
var transition = workspace.icon_group.get_transition ("opacity");
if (transition != null)
transition.completed.connect (() => {
workspace.icon_group.destroy ();
icon_groups.remove_group (workspace.icon_group);
});
else
workspace.icon_group.destroy ();
icon_groups.remove_group (workspace.icon_group);
workspace.destroy ();
update_positions (opened);

View File

@ -106,9 +106,9 @@ namespace Gala
}
}
void window_added (Workspace workspace, Window window)
void window_added (Workspace? workspace, Window window)
{
if (!Prefs.get_dynamic_workspaces ())
if (workspace == null || !Prefs.get_dynamic_workspaces ())
return;
if ((window.window_type == WindowType.NORMAL
@ -118,9 +118,9 @@ namespace Gala
append_workspace ();
}
void window_removed (Workspace workspace, Window window)
void window_removed (Workspace? workspace, Window window)
{
if (!Prefs.get_dynamic_workspaces ())
if (workspace == null || !Prefs.get_dynamic_workspaces ())
return;
if (window.window_type != WindowType.NORMAL