From 69db03560b09346714846eb8c85eeef7aacf2527 Mon Sep 17 00:00:00 2001 From: Leo Date: Mon, 30 Oct 2023 18:05:44 +0900 Subject: [PATCH] MultitaskingView: code style (#1790) --- src/Widgets/MultitaskingView.vala | 81 ++++++++++++++++++------------- 1 file changed, 48 insertions(+), 33 deletions(-) diff --git a/src/Widgets/MultitaskingView.vala b/src/Widgets/MultitaskingView.vala index 7604ef1c..81f99376 100644 --- a/src/Widgets/MultitaskingView.vala +++ b/src/Widgets/MultitaskingView.vala @@ -68,7 +68,6 @@ namespace Gala { workspace_gesture_tracker.on_gesture_detected.connect (on_workspace_gesture_detected); workspaces = new Clutter.Actor (); - workspaces.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD); icon_groups = new IconGroupContainer (wm, display.get_monitor_scale (display.get_primary_monitor ())); @@ -107,8 +106,9 @@ namespace Gala { } if (Meta.Prefs.get_dynamic_workspaces () || - (pref != Meta.Preference.DYNAMIC_WORKSPACES && pref != Meta.Preference.NUM_WORKSPACES)) + (pref != Meta.Preference.DYNAMIC_WORKSPACES && pref != Meta.Preference.NUM_WORKSPACES)) { return; + } Idle.add (() => { unowned List existing_workspaces = null; @@ -116,8 +116,8 @@ namespace Gala { existing_workspaces.append (manager.get_workspace_by_index (i)); } - foreach (var child in workspaces.get_children ()) { - unowned WorkspaceClone workspace_clone = (WorkspaceClone) child; + foreach (unowned var child in workspaces.get_children ()) { + unowned var workspace_clone = (WorkspaceClone) child; if (existing_workspaces.index (workspace_clone.workspace) < 0) { workspace_clone.window_selected.disconnect (window_selected); workspace_clone.selected.disconnect (activate_workspace); @@ -131,7 +131,7 @@ namespace Gala { update_monitors (); update_positions (false); - return false; + return Source.REMOVE; }); }); } @@ -141,15 +141,17 @@ namespace Gala { * MonitorClones at the right positions */ private void update_monitors () { - foreach (var monitor_clone in window_containers_monitors) + foreach (var monitor_clone in window_containers_monitors) { monitor_clone.destroy (); + } var primary = display.get_primary_monitor (); if (InternalUtils.workspaces_only_on_primary ()) { for (var monitor = 0; monitor < display.get_n_monitors (); monitor++) { - if (monitor == primary) + if (monitor == primary) { continue; + } var monitor_clone = new MonitorClone (wm, display, monitor, multitasking_gesture_tracker); monitor_clone.window_selected.connect (window_selected); @@ -167,8 +169,8 @@ namespace Gala { primary_monitor_container.set_position (primary_geometry.x, primary_geometry.y); primary_monitor_container.set_size (primary_geometry.width, primary_geometry.height); - foreach (var child in workspaces.get_children ()) { - unowned WorkspaceClone workspace_clone = (WorkspaceClone) child; + foreach (unowned var child in workspaces.get_children ()) { + unowned var workspace_clone = (WorkspaceClone) child; workspace_clone.scale_factor = scale; workspace_clone.update_size (primary_geometry); } @@ -353,6 +355,7 @@ namespace Gala { (uint) calculated_duration; workspaces.save_easing_state (); + workspaces.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD); workspaces.set_easing_duration (duration); workspaces.x = (is_nudge_animation || cancel_action) ? initial_x : target_x; workspaces.restore_easing_state (); @@ -439,6 +442,7 @@ namespace Gala { } workspaces.save_easing_state (); + workspaces.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD); workspaces.set_easing_duration ((animate && wm.enable_animations) ? AnimationDuration.WORKSPACE_SWITCH_MIN : 0); workspaces.x = -active_x; workspaces.restore_easing_state (); @@ -465,24 +469,27 @@ namespace Gala { } else icon_groups.x = primary_monitor_container.width / 2 - icon_groups_width / 2; - if (animate) + if (animate) { icon_groups.restore_easing_state (); + } } private void add_workspace (int num) { - unowned Meta.WorkspaceManager manager = display.get_workspace_manager (); + unowned var manager = display.get_workspace_manager (); var scale = display.get_monitor_scale (display.get_primary_monitor ()); - var workspace = new WorkspaceClone (wm, manager.get_workspace_by_index (num), multitasking_gesture_tracker, scale); - workspace.window_selected.connect (window_selected); - workspace.selected.connect (activate_workspace); + var workspace = new WorkspaceClone (wm, manager.get_workspace_by_index (num), multitasking_gesture_tracker, scale); workspaces.insert_child_at_index (workspace, num); icon_groups.add_group (workspace.icon_group); + workspace.window_selected.connect (window_selected); + workspace.selected.connect (activate_workspace); + update_positions (false); - if (opened) + if (opened) { workspace.open (); + } } private void remove_workspace (int num) { @@ -495,16 +502,17 @@ namespace Gala { existing_workspaces.append (manager.get_workspace_by_index (i)); } - foreach (var child in workspaces.get_children ()) { - unowned WorkspaceClone clone = (WorkspaceClone) child; + foreach (unowned var child in workspaces.get_children ()) { + unowned var clone = (WorkspaceClone) child; if (existing_workspaces.index (clone.workspace) < 0) { workspace = clone; break; } } - if (workspace == null) + if (workspace == null) { return; + } workspace.window_selected.disconnect (window_selected); workspace.selected.disconnect (activate_workspace); @@ -532,8 +540,9 @@ namespace Gala { clone.workspace.activate (display.get_current_time ()); - if (close_view) + if (close_view) { toggle (); + } } /** @@ -545,8 +554,9 @@ namespace Gala { #else public override bool key_press_event (Clutter.KeyEvent event) { #endif - if (!opened) + if (!opened) { return true; + } switch (event.get_key_symbol ()) { case Clutter.Key.Escape: @@ -593,7 +603,7 @@ namespace Gala { */ private WorkspaceClone get_active_workspace_clone () { unowned Meta.WorkspaceManager manager = display.get_workspace_manager (); - foreach (var child in workspaces.get_children ()) { + foreach (unowned var child in workspaces.get_children ()) { unowned WorkspaceClone workspace_clone = (WorkspaceClone) child; if (workspace_clone.workspace == manager.get_active_workspace ()) { return workspace_clone; @@ -608,9 +618,9 @@ namespace Gala { unowned Meta.WorkspaceManager manager = display.get_workspace_manager (); var workspace = window.get_workspace (); - if (workspace != manager.get_active_workspace ()) + if (workspace != manager.get_active_workspace ()) { workspace.activate (time); - else { + } else { window.activate (time); toggle (); } @@ -696,18 +706,19 @@ namespace Gala { WorkspaceClone? active_workspace = null; unowned Meta.WorkspaceManager manager = display.get_workspace_manager (); var active = manager.get_active_workspace (); - foreach (var child in workspaces.get_children ()) { + foreach (unowned var child in workspaces.get_children ()) { unowned WorkspaceClone workspace = (WorkspaceClone) child; if (workspace.workspace == active) { active_workspace = workspace; break; } } - if (active_workspace != null) + if (active_workspace != null) { workspaces.set_child_above_sibling (active_workspace, null); + } workspaces.remove_all_transitions (); - foreach (var child in workspaces.get_children ()) { + foreach (unowned var child in workspaces.get_children ()) { child.remove_all_transitions (); } @@ -715,7 +726,7 @@ namespace Gala { update_positions (false); } - foreach (var child in workspaces.get_children ()) { + foreach (unowned var child in workspaces.get_children ()) { unowned WorkspaceClone workspace = (WorkspaceClone) child; if (opening) { workspace.open (with_gesture, is_cancel_animation); @@ -755,7 +766,7 @@ namespace Gala { toggle (false, true); } - return false; + return Source.REMOVE; }); }; @@ -771,17 +782,20 @@ namespace Gala { foreach (unowned Meta.WindowActor actor in window_actors) { const int MAX_OFFSET = 85; - if (actor.is_destroyed ()) + if (actor.is_destroyed ()) { continue; + } unowned Meta.Window window = actor.get_meta_window (); var monitor = window.get_monitor (); - if (window.window_type != Meta.WindowType.DOCK) + if (window.window_type != Meta.WindowType.DOCK) { continue; + } - if (display.get_monitor_in_fullscreen (monitor)) + if (display.get_monitor_in_fullscreen (monitor)) { continue; + } var monitor_geom = display.get_monitor_geometry (monitor); @@ -789,8 +803,9 @@ namespace Gala { var top = monitor_geom.y + MAX_OFFSET > window_geom.y; var bottom = monitor_geom.y + monitor_geom.height - MAX_OFFSET > window_geom.y; - if (!top && !bottom) + if (!top && !bottom) { continue; + } var initial_x = actor.x; var initial_y = actor.y; @@ -829,7 +844,7 @@ namespace Gala { } private void hide_docks (bool with_gesture, bool is_cancel_animation) { - foreach (var child in dock_clones.get_children ()) { + foreach (unowned var child in dock_clones.get_children ()) { var dock = (Clutter.Clone) child; var initial_y = dock.y; var target_y = dock.source.y;