From 54bf615d2711692d879f3d7bb537ef08de4e54a6 Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Tue, 24 Jun 2014 14:42:46 +0200 Subject: [PATCH] Unify API of TiledWindowContainer Provide open/close methodes like we do in other places --- .../MultitaskingView/MonitorClone.vala | 4 +- .../TiledWindowContainer.vala | 111 +++++++++--------- .../MultitaskingView/WorkspaceClone.vala | 16 ++- 3 files changed, 69 insertions(+), 62 deletions(-) diff --git a/src/Widgets/MultitaskingView/MonitorClone.vala b/src/Widgets/MultitaskingView/MonitorClone.vala index 5b8db474..65cf0565 100644 --- a/src/Widgets/MultitaskingView/MonitorClone.vala +++ b/src/Widgets/MultitaskingView/MonitorClone.vala @@ -83,13 +83,13 @@ namespace Gala public void open () { - window_container.opened = true; + window_container.open (); // background.opacity = 0; TODO consider this option } public void close () { - window_container.opened = false; + window_container.close (); background.opacity = 255; } diff --git a/src/Widgets/MultitaskingView/TiledWindowContainer.vala b/src/Widgets/MultitaskingView/TiledWindowContainer.vala index 39869416..9ba2e932 100644 --- a/src/Widgets/MultitaskingView/TiledWindowContainer.vala +++ b/src/Widgets/MultitaskingView/TiledWindowContainer.vala @@ -29,56 +29,19 @@ namespace Gala public int padding_right { get; set; default = 12; } public int padding_bottom { get; set; default = 12; } - bool _opened; - public bool opened { - get { - return _opened; - } - set { - if (value == _opened) - return; - - _opened = value; - - if (_opened) { - // hide the highlight when opened - if (_current_window != null) - _current_window.active = false; - - // make sure our windows are where they belong in case they were moved - // while were closed. - foreach (var window in get_children ()) { - ((TiledWindow) window).transition_to_original_state (false); - } - - reflow (); - } else { - foreach (var window in get_children ()) - ((TiledWindow) window).transition_to_original_state (true); - } - } - } - - TiledWindow? _current_window = null; - public Window? current_window { - get { - return _current_window != null ? _current_window.window : null; - } - set { - foreach (var child in get_children ()) { - unowned TiledWindow tiled_window = (TiledWindow) child; - if (tiled_window.window == value) { - _current_window = tiled_window; - break; - } - } - } - } + bool opened; + TiledWindow? current_window; public TiledWindowContainer () { } + construct + { + opened = false; + current_window = null; + } + public void add_window (Window window) { unowned Meta.Display display = window.get_display (); @@ -221,16 +184,16 @@ namespace Gala if (get_n_children () < 1) return; - if (_current_window == null) { - _current_window = (TiledWindow) get_child_at_index (0); + if (current_window == null) { + current_window = (TiledWindow) get_child_at_index (0); return; } - var current_rect = _current_window.slot; + var current_rect = current_window.slot; TiledWindow? closest = null; foreach (var window in get_children ()) { - if (window == _current_window) + if (window == current_window) continue; var window_rect = ((TiledWindow) window).slot; @@ -294,17 +257,57 @@ namespace Gala if (closest == null) return; - if (_current_window != null) - _current_window.active = false; + if (current_window != null) + current_window.active = false; closest.active = true; - _current_window = closest; + current_window = closest; } public void activate_selected_window () { - if (_current_window != null) - _current_window.selected (); + if (current_window != null) + current_window.selected (); + } + + public void open (Window? selected_window = null) + { + if (opened) + return; + + opened = true; + + // hide the highlight when opened + if (selected_window != null) { + foreach (var child in get_children ()) { + unowned TiledWindow tiled_window = (TiledWindow) child; + if (tiled_window.window == selected_window) { + current_window = tiled_window; + break; + } + } + current_window.active = false; + } else { + current_window = null; + } + + // make sure our windows are where they belong in case they were moved + // while were closed. + foreach (var window in get_children ()) + ((TiledWindow) window).transition_to_original_state (false); + + reflow (); + } + + public void close () + { + if (!opened) + return; + + opened = false; + + foreach (var window in get_children ()) + ((TiledWindow) window).transition_to_original_state (true); } } } diff --git a/src/Widgets/MultitaskingView/WorkspaceClone.vala b/src/Widgets/MultitaskingView/WorkspaceClone.vala index 57e21aae..dce46b65 100644 --- a/src/Widgets/MultitaskingView/WorkspaceClone.vala +++ b/src/Widgets/MultitaskingView/WorkspaceClone.vala @@ -205,6 +205,11 @@ namespace Gala public void open () { + if (opened) + return; + + opened = true; + var screen = workspace.get_screen (); var display = screen.get_display (); @@ -227,8 +232,6 @@ namespace Gala }; shrink_rectangle (ref area, 32); - opened = true; - window_container.padding_top = TOP_OFFSET; window_container.padding_left = window_container.padding_right = (int)(monitor.width - monitor.width * scale) / 2; @@ -236,13 +239,14 @@ namespace Gala icon_group.redraw (); - window_container.opened = true; - if (screen.get_active_workspace () == workspace) - window_container.current_window = display.get_focus_window (); + window_container.open (screen.get_active_workspace () == workspace ? display.get_focus_window () : null); } public void close () { + if (!opened) + return; + opened = false; background.save_easing_state (); @@ -251,7 +255,7 @@ namespace Gala background.set_scale (1, 1); background.restore_easing_state (); - window_container.opened = false; + window_container.close (); } } }