Skip to content

Commit 2cebb04

Browse files
committed
Introduce PrimaryMonitorClone
1 parent 434b79a commit 2cebb04

File tree

6 files changed

+83
-122
lines changed

6 files changed

+83
-122
lines changed

src/Widgets/IconGroupContainer.vala

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -110,30 +110,6 @@ public class Gala.IconGroupContainer : Clutter.Actor {
110110
request_reposition (true);
111111
}
112112

113-
/**
114-
* Calculates the width that will be occupied taking currently running animations
115-
* end states into account
116-
*/
117-
public float calculate_total_width () {
118-
var spacing = InternalUtils.scale_to_int (SPACING, scale_factor);
119-
var group_width = InternalUtils.scale_to_int (GROUP_WIDTH, scale_factor);
120-
121-
var width = 0.0f;
122-
foreach (var child in get_children ()) {
123-
if (child is WorkspaceInsertThumb) {
124-
if (((WorkspaceInsertThumb) child).expanded)
125-
width += group_width + spacing * 2;
126-
else
127-
width += spacing;
128-
} else
129-
width += group_width;
130-
}
131-
132-
width += spacing;
133-
134-
return width;
135-
}
136-
137113
public void force_reposition () {
138114
var children = get_children ();
139115

src/Widgets/MultitaskingView.vala

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace Gala {
4040

4141
private IconGroupContainer icon_groups;
4242
private ActorTarget workspaces;
43-
private Clutter.Actor primary_monitor_container;
43+
private PrimaryMonitorClone primary_monitor_clone;
4444
private Clutter.BrightnessContrastEffect brightness_effect;
4545

4646
private GLib.Settings gala_behavior_settings;
@@ -66,17 +66,6 @@ namespace Gala {
6666

6767
add_target (ShellClientsManager.get_instance ()); // For hiding the panels
6868

69-
workspaces = new WorkspaceRow (display);
70-
71-
workspaces_gesture_controller = new GestureController (WorkspaceRow.GESTURE_ID, SWITCH_WORKSPACE, workspaces) {
72-
enabled = false,
73-
overshoot_upper_clamp = 0.1
74-
};
75-
workspaces_gesture_controller.enable_touchpad ();
76-
workspaces_gesture_controller.enable_scroll (this, HORIZONTAL);
77-
78-
icon_groups = new IconGroupContainer (display.get_monitor_scale (display.get_primary_monitor ()));
79-
8069
brightness_effect = new Clutter.BrightnessContrastEffect ();
8170
update_brightness_effect ();
8271

@@ -86,13 +75,24 @@ namespace Gala {
8675

8776
add_child (blurred_bg);
8877

78+
icon_groups = new IconGroupContainer (display.get_monitor_scale (display.get_primary_monitor ()));
79+
80+
workspaces = new ActorTarget () {
81+
layout_manager = new Clutter.BoxLayout ()
82+
};
83+
8984
// Create a child container that will be sized to fit the primary monitor, to contain the "main"
9085
// multitasking view UI. The Clutter.Actor of this class has to be allowed to grow to the size of the
9186
// stage as it contains MonitorClones for each monitor.
92-
primary_monitor_container = new ActorTarget ();
93-
primary_monitor_container.add_child (icon_groups);
94-
primary_monitor_container.add_child (workspaces);
95-
add_child (primary_monitor_container);
87+
primary_monitor_clone = new PrimaryMonitorClone (display, icon_groups, workspaces);
88+
add_child (primary_monitor_clone);
89+
90+
workspaces_gesture_controller = new GestureController (PrimaryMonitorClone.GESTURE_ID, SWITCH_WORKSPACE, primary_monitor_clone) {
91+
enabled = false,
92+
overshoot_upper_clamp = 0.1
93+
};
94+
workspaces_gesture_controller.enable_touchpad ();
95+
workspaces_gesture_controller.enable_scroll (this, HORIZONTAL);
9696

9797
unowned var manager = display.get_workspace_manager ();
9898
manager.workspace_added.connect (add_workspace);
@@ -186,8 +186,8 @@ namespace Gala {
186186
var scale = display.get_monitor_scale (primary);
187187
icon_groups.scale_factor = scale;
188188

189-
primary_monitor_container.set_position (primary_geometry.x, primary_geometry.y);
190-
primary_monitor_container.set_size (primary_geometry.width, primary_geometry.height);
189+
primary_monitor_clone.set_position (primary_geometry.x, primary_geometry.y);
190+
primary_monitor_clone.set_size (primary_geometry.width, primary_geometry.height);
191191

192192
foreach (unowned var child in workspaces.get_children ()) {
193193
unowned var workspace_clone = (WorkspaceClone) child;
@@ -288,9 +288,7 @@ namespace Gala {
288288
modal_proxy = wm.push_modal (this);
289289
modal_proxy.set_keybinding_filter (keybinding_filter);
290290

291-
var scale = display.get_monitor_scale (display.get_primary_monitor ());
292291
icon_groups.force_reposition ();
293-
icon_groups.y = primary_monitor_container.height - InternalUtils.scale_to_int (WorkspaceClone.BOTTOM_OFFSET - 20, scale);
294292
} else {
295293
DragDropAction.cancel_all_by_id ("multitaskingview-window");
296294
}
@@ -332,6 +330,11 @@ namespace Gala {
332330
* positions immediately.
333331
*/
334332
private void update_positions (bool animate) {
333+
for (var child = workspaces.get_first_child (); child != null; child = child.get_next_sibling ()) {
334+
unowned var workspace_clone = (WorkspaceClone) child;
335+
workspaces.set_child_at_index (workspace_clone, workspace_clone.workspace.index ());
336+
}
337+
335338
unowned var manager = display.get_workspace_manager ();
336339
workspaces_gesture_controller.overshoot_lower_clamp = -manager.n_workspaces - 0.1 + 1;
337340

@@ -340,32 +343,6 @@ namespace Gala {
340343
} else {
341344
workspaces_gesture_controller.progress = -manager.get_active_workspace_index ();
342345
}
343-
344-
reposition_icon_groups (animate);
345-
}
346-
347-
private void reposition_icon_groups (bool animate) {
348-
unowned Meta.WorkspaceManager manager = display.get_workspace_manager ();
349-
var active_index = manager.get_active_workspace ().index ();
350-
351-
if (animate) {
352-
icon_groups.save_easing_state ();
353-
icon_groups.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
354-
icon_groups.set_easing_duration (200);
355-
}
356-
357-
var scale = display.get_monitor_scale (display.get_primary_monitor ());
358-
// make sure the active workspace's icongroup is always visible
359-
var icon_groups_width = icon_groups.calculate_total_width ();
360-
if (icon_groups_width > primary_monitor_container.width) {
361-
icon_groups.x = (-active_index * InternalUtils.scale_to_int (IconGroupContainer.SPACING + IconGroup.SIZE, scale) + primary_monitor_container.width / 2)
362-
.clamp (primary_monitor_container.width - icon_groups_width - InternalUtils.scale_to_int (64, scale), InternalUtils.scale_to_int (64, scale));
363-
} else
364-
icon_groups.x = primary_monitor_container.width / 2 - icon_groups_width / 2;
365-
366-
if (animate) {
367-
icon_groups.restore_easing_state ();
368-
}
369346
}
370347

371348
private void add_workspace (int num) {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2025 elementary, Inc. (https://elementary.io)
3+
* SPDX-License-Identifier: GPL-3.0-or-later
4+
*
5+
* Authored by: Leonhard Kargl <[email protected]>
6+
*/
7+
8+
public class Gala.PrimaryMonitorClone : ActorTarget {
9+
public const string GESTURE_ID = "workspace-row";
10+
11+
public Meta.Display display { get; construct; }
12+
13+
public IconGroupContainer icon_groups { get; construct; }
14+
public ActorTarget workspaces { get; construct; }
15+
16+
public PrimaryMonitorClone (Meta.Display display, IconGroupContainer icon_groups, ActorTarget workspaces) {
17+
Object (display: display, icon_groups: icon_groups, workspaces: workspaces);
18+
}
19+
20+
construct {
21+
add_child (icon_groups);
22+
add_child (workspaces);
23+
}
24+
25+
public override void allocate (Clutter.ActorBox allocation) {
26+
set_allocation (allocation);
27+
28+
float workspaces_x = (float) (get_current_progress (GESTURE_ID) * workspaces.get_first_child ().width);
29+
workspaces.allocate_preferred_size (Math.roundf (workspaces_x), 0);
30+
31+
var scale = display.get_monitor_scale (display.get_primary_monitor ());
32+
float icon_groups_y = allocation.get_height () - InternalUtils.scale_to_int (WorkspaceClone.BOTTOM_OFFSET - 20, scale);
33+
34+
float icon_groups_x, icon_groups_width;
35+
icon_groups.get_preferred_width (-1, null, out icon_groups_width);
36+
if (icon_groups_width <= allocation.get_width ()) {
37+
icon_groups_x = allocation.get_width () / 2 - icon_groups_width / 2;
38+
} else {
39+
icon_groups_x = (float) (get_current_progress (GESTURE_ID) * InternalUtils.scale_to_int (IconGroupContainer.SPACING + IconGroup.SIZE, scale) + allocation.get_width () / 2)
40+
.clamp (allocation.get_width () - icon_groups_width - InternalUtils.scale_to_int (64, scale), InternalUtils.scale_to_int (64, scale));
41+
}
42+
43+
icon_groups.allocate_preferred_size (Math.roundf (icon_groups_x), Math.roundf (icon_groups_y));
44+
}
45+
46+
public override void update_progress (string id, double progress) {
47+
if (id == GESTURE_ID) {
48+
queue_relayout ();
49+
}
50+
}
51+
52+
public override void commit_progress (string id, double to) {
53+
if (id == GESTURE_ID) {
54+
unowned var workspace_manager = display.get_workspace_manager ();
55+
workspace_manager.get_workspace_by_index ((int) (-to)).activate (display.get_current_time ());
56+
}
57+
}
58+
}

src/Widgets/WorkspaceClone.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ namespace Gala {
331331
}
332332

333333
public override void update_progress (string id, double progress) {
334-
if (id == WorkspaceRow.GESTURE_ID) {
334+
if (id == PrimaryMonitorClone.GESTURE_ID) {
335335
icon_group.backdrop_opacity = 1 - (float) (workspace.index () + progress).abs ().clamp (0, 1);
336336
}
337337
}

src/Widgets/WorkspaceRow.vala

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ gala_bin_sources = files(
6363
'Widgets/MultitaskingView.vala',
6464
'Widgets/PixelPicker.vala',
6565
'Widgets/PointerLocator.vala',
66+
'Widgets/PrimaryMonitorClone.vala',
6667
'Widgets/ScreenShield.vala',
6768
'Widgets/SelectionArea.vala',
6869
'Widgets/Tooltip.vala',
@@ -74,7 +75,6 @@ gala_bin_sources = files(
7475
'Widgets/WindowSwitcher/WindowSwitcherIcon.vala',
7576
'Widgets/WorkspaceClone.vala',
7677
'Widgets/WorkspaceInsertThumb.vala',
77-
'Widgets/WorkspaceRow.vala',
7878
)
7979

8080
gala_bin = executable(

0 commit comments

Comments
 (0)