Skip to content

Commit

Permalink
MultitaskingView: code style (#1790)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenemter authored Oct 30, 2023
1 parent aa1dc31 commit 69db035
Showing 1 changed file with 48 additions and 33 deletions.
81 changes: 48 additions & 33 deletions src/Widgets/MultitaskingView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()));

Expand Down Expand Up @@ -107,17 +106,18 @@ 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<Meta.Workspace> existing_workspaces = null;
for (int i = 0; i < manager.get_n_workspaces (); i++) {
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);
Expand All @@ -131,7 +131,7 @@ namespace Gala {
update_monitors ();
update_positions (false);

return false;
return Source.REMOVE;
});
});
}
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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 ();
Expand Down Expand Up @@ -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 ();
Expand All @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -532,8 +540,9 @@ namespace Gala {

clone.workspace.activate (display.get_current_time ());

if (close_view)
if (close_view) {
toggle ();
}
}

/**
Expand All @@ -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:
Expand Down Expand Up @@ -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;
Expand All @@ -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 ();
}
Expand Down Expand Up @@ -696,26 +706,27 @@ 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 ();
}

if (!is_cancel_animation) {
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);
Expand Down Expand Up @@ -755,7 +766,7 @@ namespace Gala {
toggle (false, true);
}

return false;
return Source.REMOVE;
});
};

Expand All @@ -771,26 +782,30 @@ 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);

var window_geom = window.get_frame_rect ();
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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 69db035

Please sign in to comment.