Skip to content

Commit e65e63e

Browse files
committed
ShellWindow: Only handle common code
Move things that only apply to PanelWindows there. Also rely on subclasses to provide a GestureTarget for property updates instead of trying to handle all cases. This cleans up a lot of code that was necessary to handle the stuff needed by all subclass. This makes sure we only update things when actually needed. For example ExtendedBehaviorWindows never need to update their target. This will also provide more flexibility in the future if we want to introduce other specialized windows. This also allows to change more stuff in subclasses without affecting other subclasses.
1 parent fa49edf commit e65e63e

File tree

5 files changed

+59
-87
lines changed

5 files changed

+59
-87
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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.ExtendedBehaviorWindow : ShellWindow {
9+
public ExtendedBehaviorWindow (Meta.Window window) {
10+
var target = new PropertyTarget (CUSTOM, window.get_compositor_private (), "opacity", typeof (uint), 255u, 0u);
11+
Object (window: window, position: Position.CENTER, hide_target: target);
12+
}
13+
}

src/ShellClients/PanelWindow.vala

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,26 @@ public class Gala.PanelWindow : ShellWindow, RootTarget {
7171
workspace_hide_tracker.switching_workspace_progress_updated.connect ((value) => workspace_gesture_controller.progress = value);
7272
workspace_hide_tracker.window_state_changed_progress_updated.connect (workspace_gesture_controller.goto);
7373

74+
window.size_changed.connect (update_target);
75+
notify["position"].connect (update_target);
76+
update_target ();
77+
7478
add_gesture_controller (user_gesture_controller);
7579
add_gesture_controller (workspace_gesture_controller);
80+
81+
var window_actor = (Meta.WindowActor) window.get_compositor_private ();
82+
83+
window_actor.notify["width"].connect (update_clip);
84+
window_actor.notify["height"].connect (update_clip);
85+
window_actor.notify["translation-y"].connect (update_clip);
86+
notify["position"].connect (update_clip);
7687
}
7788

7889
public void request_visible_in_multitasking_view () {
7990
visible_in_multitasking_view = true;
8091
actor.add_action (new DragDropAction (DESTINATION, "multitaskingview-window"));
8192
}
8293

83-
protected override void update_target () {
84-
base.update_target ();
85-
workspace_hide_tracker.recalculate_all_workspaces ();
86-
}
87-
8894
protected override double get_hidden_progress () {
8995
var user_workspace_hidden_progress = double.min (
9096
user_gesture_controller.progress,
@@ -214,4 +220,26 @@ public class Gala.PanelWindow : ShellWindow, RootTarget {
214220
return TOP;
215221
}
216222
}
223+
224+
private void update_target () {
225+
var to_value = anchor == TOP ? -get_custom_window_rect ().height : get_custom_window_rect ().height;
226+
hide_target = new PropertyTarget (CUSTOM, actor, "translation-y", typeof (float), 0f, (float) to_value);
227+
228+
workspace_hide_tracker.recalculate_all_workspaces ();
229+
}
230+
231+
private void update_clip () {
232+
var monitor_geom = window.display.get_monitor_geometry (window.get_monitor ());
233+
var window_actor = (Meta.WindowActor) window.get_compositor_private ();
234+
235+
var y = window_actor.y + window_actor.translation_y;
236+
237+
if (y + window_actor.height > monitor_geom.y + monitor_geom.height) {
238+
window_actor.set_clip (0, 0, window_actor.width, monitor_geom.y + monitor_geom.height - y);
239+
} else if (y < monitor_geom.y) {
240+
window_actor.set_clip (0, monitor_geom.y - y, window_actor.width, window_actor.height);
241+
} else {
242+
window_actor.remove_clip ();
243+
}
244+
}
217245
}

src/ShellClients/ShellClientsManager.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public class Gala.ShellClientsManager : Object, GestureTarget {
199199
}
200200

201201
public void make_centered (Meta.Window window) requires (!is_itself_positioned (window)) {
202-
positioned_windows[window] = new ShellWindow (window, CENTER);
202+
positioned_windows[window] = new ExtendedBehaviorWindow (window);
203203

204204
// connect_after so we make sure that any queued move is unqueued
205205
window.unmanaging.connect_after ((_window) => positioned_windows.remove (_window));

src/ShellClients/ShellWindow.vala

Lines changed: 11 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,19 @@
88
public class Gala.ShellWindow : PositionedWindow, GestureTarget {
99
public bool restore_previous_x11_region { private get; set; default = false; }
1010

11-
private Meta.WindowActor window_actor;
11+
/**
12+
* A gesture target that will receive a CUSTOM update every time a gesture
13+
* is propagated, with the progress gotten via {@link get_hidden_progress()}
14+
*/
15+
public GestureTarget hide_target { get; construct set; }
16+
1217
private double multitasking_view_progress = 0;
1318
private int animations_ongoing = 0;
1419

15-
private PropertyTarget property_target;
16-
1720
public ShellWindow (Meta.Window window, Position position, Variant? position_data = null) {
1821
base (window, position, position_data);
1922
}
2023

21-
construct {
22-
window_actor = (Meta.WindowActor) window.get_compositor_private ();
23-
24-
window_actor.notify["width"].connect (update_clip);
25-
window_actor.notify["height"].connect (update_clip);
26-
window_actor.notify["translation-y"].connect (update_clip);
27-
notify["position"].connect (update_clip);
28-
29-
window.size_changed.connect (update_target);
30-
notify["position"].connect (update_target);
31-
update_target ();
32-
}
33-
34-
protected virtual void update_target () {
35-
property_target = new PropertyTarget (
36-
CUSTOM, window_actor,
37-
get_animation_property (),
38-
get_property_type (),
39-
calculate_value (false),
40-
calculate_value (true)
41-
);
42-
}
43-
4424
public virtual void propagate (UpdateType update_type, GestureAction action, double progress) {
4525
switch (update_type) {
4626
case START:
@@ -53,7 +33,7 @@ public class Gala.ShellWindow : PositionedWindow, GestureTarget {
5333
multitasking_view_progress = progress;
5434
}
5535

56-
property_target.propagate (UPDATE, CUSTOM, get_hidden_progress ());
36+
hide_target.propagate (UPDATE, CUSTOM, get_hidden_progress ());
5737
break;
5838

5939
case END:
@@ -71,6 +51,8 @@ public class Gala.ShellWindow : PositionedWindow, GestureTarget {
7151
}
7252

7353
private void update_visibility () {
54+
unowned var window_actor = (Meta.WindowActor) window.get_compositor_private ();
55+
7456
var visible = get_hidden_progress () < 0.1;
7557
var animating = animations_ongoing > 0;
7658

@@ -104,63 +86,11 @@ public class Gala.ShellWindow : PositionedWindow, GestureTarget {
10486
return true;
10587
}
10688

107-
unowned var window_actor = (Meta.WindowActor) transient.get_compositor_private ();
89+
unowned var transient_window_actor = (Meta.WindowActor) transient.get_compositor_private ();
10890

109-
window_actor.visible = visible && !animating;
91+
transient_window_actor.visible = visible && !animating;
11092

11193
return true;
11294
});
11395
}
114-
115-
private string get_animation_property () {
116-
switch (position) {
117-
case TOP:
118-
case BOTTOM:
119-
return "translation-y";
120-
default:
121-
return "opacity";
122-
}
123-
}
124-
125-
private Type get_property_type () {
126-
switch (position) {
127-
case TOP:
128-
case BOTTOM:
129-
return typeof (float);
130-
default:
131-
return typeof (uint);
132-
}
133-
}
134-
135-
private Value calculate_value (bool hidden) {
136-
var custom_rect = get_custom_window_rect ();
137-
138-
switch (position) {
139-
case TOP:
140-
return hidden ? -custom_rect.height : 0f;
141-
case BOTTOM:
142-
return hidden ? custom_rect.height : 0f;
143-
default:
144-
return hidden ? 0u : 255u;
145-
}
146-
}
147-
148-
private void update_clip () {
149-
if (position != TOP && position != BOTTOM) {
150-
window_actor.remove_clip ();
151-
return;
152-
}
153-
154-
var monitor_geom = window.display.get_monitor_geometry (window.get_monitor ());
155-
156-
var y = window_actor.y + window_actor.translation_y;
157-
158-
if (y + window_actor.height > monitor_geom.y + monitor_geom.height) {
159-
window_actor.set_clip (0, 0, window_actor.width, monitor_geom.y + monitor_geom.height - y);
160-
} else if (y < monitor_geom.y) {
161-
window_actor.set_clip (0, monitor_geom.y - y, window_actor.width, window_actor.height);
162-
} else {
163-
window_actor.remove_clip ();
164-
}
165-
}
16696
}

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ gala_bin_sources = files(
4242
'HotCorners/Barrier.vala',
4343
'HotCorners/HotCorner.vala',
4444
'HotCorners/HotCornerManager.vala',
45+
'ShellClients/ExtendedBehaviorWindow.vala',
4546
'ShellClients/HideTracker.vala',
4647
'ShellClients/ManagedClient.vala',
4748
'ShellClients/NotificationsClient.vala',

0 commit comments

Comments
 (0)