Skip to content

Commit a268e6f

Browse files
committed
WorkspaceClone: cleanup
1 parent cbec7b3 commit a268e6f

File tree

1 file changed

+34
-58
lines changed

1 file changed

+34
-58
lines changed

src/Widgets/MultitaskingView/WorkspaceClone.vala

Lines changed: 34 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
//
2-
// Copyright (C) 2014 Tom Beckmann
3-
//
4-
// This program is free software: you can redistribute it and/or modify
5-
// it under the terms of the GNU General Public License as published by
6-
// the Free Software Foundation, either version 3 of the License, or
7-
// (at your option) any later version.
8-
//
9-
// This program is distributed in the hope that it will be useful,
10-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
// GNU General Public License for more details.
13-
//
14-
// You should have received a copy of the GNU General Public License
15-
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
//
1+
/*
2+
* SPDX-License-Identifier: GPL-3.0-or-later
3+
* SPDX-FileCopyrightText: 2014 Tom Beckmann
4+
* 2025 elementary, Inc. (https://elementary.io)
5+
*/
176

187
/**
198
* Utility class which adds a border and a shadow to a Background
@@ -83,16 +72,15 @@ private class Gala.FramedBackground : BackgroundManager {
8372
cached_texture = texture;
8473
}
8574
} catch (Error e) {
86-
debug (e.message);
75+
critical ("FramedBackground: Couldn't create texture: %s", e.message);
8776
}
8877

8978
var color = Cogl.Color.from_4f (1.0f, 1.0f, 1.0f, 25.0f / 255.0f);
9079
color.premultiply ();
9180

9281
pipeline.set_color (color);
9382

94-
unowned var fb = context.get_framebuffer ();
95-
fb.draw_rectangle (pipeline, 0, 0, width, height);
83+
context.get_framebuffer ().draw_rectangle (pipeline, 0, 0, width, height);
9684
}
9785
}
9886

@@ -133,20 +121,15 @@ public class Gala.WorkspaceClone : ActorTarget {
133121
public WindowCloneContainer window_container { get; private set; }
134122

135123
private BackgroundManager background;
136-
private bool opened;
137-
138124
private uint hover_activate_timeout = 0;
139125

140126
public WorkspaceClone (WindowManager wm, Meta.Workspace workspace, float monitor_scale) {
141127
Object (wm: wm, workspace: workspace, monitor_scale: monitor_scale);
142128
}
143129

144130
construct {
145-
opened = false;
146-
147-
unowned Meta.Display display = workspace.get_display ();
148-
var primary_monitor = display.get_primary_monitor ();
149-
var monitor_geometry = display.get_monitor_geometry (primary_monitor);
131+
unowned var display = workspace.get_display ();
132+
var monitor_geometry = display.get_monitor_geometry (display.get_primary_monitor ());
150133

151134
var background_click_action = new Clutter.ClickAction ();
152135
background_click_action.clicked.connect (() => activate (true));
@@ -157,7 +140,7 @@ public class Gala.WorkspaceClone : ActorTarget {
157140
width = monitor_geometry.width,
158141
height = monitor_geometry.height,
159142
};
160-
window_container.window_selected.connect ((w) => { window_selected (w); });
143+
window_container.window_selected.connect ((w) => window_selected (w));
161144
window_container.requested_close.connect (() => activate (true));
162145
bind_property ("monitor-scale", window_container, "monitor-scale");
163146

@@ -167,34 +150,31 @@ public class Gala.WorkspaceClone : ActorTarget {
167150
if (!hovered && hover_activate_timeout != 0) {
168151
Source.remove (hover_activate_timeout);
169152
hover_activate_timeout = 0;
153+
170154
return;
171155
}
172156

173157
if (hovered && hover_activate_timeout == 0) {
174158
hover_activate_timeout = Timeout.add (HOVER_ACTIVATE_DELAY, () => {
175159
activate (false);
176160
hover_activate_timeout = 0;
177-
return false;
161+
162+
return Source.REMOVE;
178163
});
179164
}
180165
});
181166

182167
display.window_entered_monitor.connect (window_entered_monitor);
183168
display.window_left_monitor.connect (window_left_monitor);
184169
workspace.window_added.connect (add_window);
185-
workspace.window_removed.connect (remove_window);
170+
workspace.window_removed.connect (window_container.remove_window);
186171

187172
add_child (background);
188173
add_child (window_container);
189174

190175
// add existing windows
191-
var windows = workspace.list_windows ();
192-
foreach (var window in windows) {
193-
if (window.window_type == Meta.WindowType.NORMAL
194-
&& !window.on_all_workspaces
195-
&& window.is_on_primary_monitor ()) {
196-
window_container.add_window (window);
197-
}
176+
foreach (var window in workspace.list_windows ()) {
177+
add_window (window);
198178
}
199179

200180
var static_windows = StaticWindowContainer.get_instance (display);
@@ -207,54 +187,51 @@ public class Gala.WorkspaceClone : ActorTarget {
207187
}
208188

209189
~WorkspaceClone () {
210-
unowned Meta.Display display = workspace.get_display ();
190+
unowned var display = workspace.get_display ();
211191

212192
display.window_entered_monitor.disconnect (window_entered_monitor);
213193
display.window_left_monitor.disconnect (window_left_monitor);
214194
workspace.window_added.disconnect (add_window);
215-
workspace.window_removed.disconnect (remove_window);
195+
workspace.window_removed.disconnect (window_container.remove_window);
216196

217197
background.destroy ();
218198
window_container.destroy ();
219199
}
220200

221201
/**
222-
* Add a window to the WindowCloneContainer and the IconGroup if it really
223-
* belongs to this workspace and this monitor.
202+
* Add a window to the WindowCloneContainer if it belongs to this workspace and this monitor.
224203
*/
225204
private void add_window (Meta.Window window) {
226-
if (window.window_type != Meta.WindowType.NORMAL
227-
|| window.get_workspace () != workspace
228-
|| StaticWindowContainer.get_instance (workspace.get_display ()).is_static (window)
229-
|| !window.is_on_primary_monitor ())
205+
if (window.window_type != NORMAL ||
206+
window.get_workspace () != workspace ||
207+
StaticWindowContainer.get_instance (workspace.get_display ()).is_static (window) ||
208+
!window.is_on_primary_monitor ()
209+
) {
230210
return;
211+
}
231212

232-
foreach (var child in window_container.get_children ())
233-
if (((WindowClone) child).window == window)
213+
foreach (var child in (GLib.List<weak WindowClone>) window_container.get_children ()) {
214+
if (child.window == window) {
234215
return;
216+
}
217+
}
235218

236219
window_container.add_window (window);
237220
}
238221

239-
/**
240-
* Remove a window from the WindowCloneContainer and the IconGroup
241-
*/
242-
private void remove_window (Meta.Window window) {
243-
window_container.remove_window (window);
244-
}
245-
246222
private void window_entered_monitor (Meta.Display display, int monitor, Meta.Window window) {
247223
add_window (window);
248224
}
249225

250226
private void window_left_monitor (Meta.Display display, int monitor, Meta.Window window) {
251-
if (monitor == display.get_primary_monitor ())
252-
remove_window (window);
227+
if (monitor == display.get_primary_monitor ()) {
228+
window_container.remove_window (window);
229+
}
253230
}
254231

255232
private void on_window_static_changed (Meta.Window window, bool is_static) {
256233
if (is_static) {
257-
remove_window (window);
234+
window_container.remove_window (window);
258235
} else {
259236
add_window (window);
260237
}
@@ -286,8 +263,7 @@ public class Gala.WorkspaceClone : ActorTarget {
286263
add_target (new PropertyTarget (MULTITASKING_VIEW, background, "scale-y", typeof (double), 1d, (double) scale));
287264

288265
window_container.padding_top = Utils.scale_to_int (TOP_OFFSET, monitor_scale);
289-
window_container.padding_left =
290-
window_container.padding_right = (int)(monitor.width - monitor.width * scale) / 2;
266+
window_container.padding_left = window_container.padding_right = (int)(monitor.width - monitor.width * scale) / 2;
291267
window_container.padding_bottom = Utils.scale_to_int (BOTTOM_OFFSET, monitor_scale);
292268
}
293269

0 commit comments

Comments
 (0)