Skip to content

Commit 475bcdd

Browse files
authored
IconGroupContainer: Inline namespace (#2248)
1 parent 8d97ddd commit 475bcdd

File tree

1 file changed

+127
-140
lines changed

1 file changed

+127
-140
lines changed

src/Widgets/IconGroupContainer.vala

Lines changed: 127 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,175 +1,162 @@
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-
//
17-
18-
namespace Gala {
19-
/**
20-
* This class contains the icon groups at the bottom and will take
21-
* care of displaying actors for inserting windows between the groups
22-
* once implemented
23-
*/
24-
public class IconGroupContainer : Clutter.Actor {
25-
public const int SPACING = 48;
26-
public const int GROUP_WIDTH = 64;
27-
28-
public signal void request_reposition (bool animate);
29-
30-
private float _scale_factor = 1.0f;
31-
public float scale_factor {
32-
get {
33-
return _scale_factor;
34-
}
35-
set {
36-
if (value != _scale_factor) {
37-
_scale_factor = value;
38-
reallocate ();
39-
}
1+
/*
2+
* SPDX-License-Identifier: GPL-3.0-or-later
3+
* SPDX-FileCopyrightText: 2014 Tom Beckmann
4+
* 2025 elementary, Inc. <https://elementary.io>
5+
*/
6+
7+
/**
8+
* This class contains the icon groups at the bottom and will take
9+
* care of displaying actors for inserting windows between the groups
10+
* once implemented
11+
*/
12+
public class Gala.IconGroupContainer : Clutter.Actor {
13+
public const int SPACING = 48;
14+
public const int GROUP_WIDTH = 64;
15+
16+
public signal void request_reposition (bool animate);
17+
18+
private float _scale_factor = 1.0f;
19+
public float scale_factor {
20+
get {
21+
return _scale_factor;
22+
}
23+
set {
24+
if (value != _scale_factor) {
25+
_scale_factor = value;
26+
reallocate ();
4027
}
4128
}
29+
}
4230

43-
public IconGroupContainer (float scale) {
44-
Object (scale_factor: scale);
31+
public IconGroupContainer (float scale) {
32+
Object (scale_factor: scale);
4533

46-
layout_manager = new Clutter.BoxLayout ();
47-
}
34+
layout_manager = new Clutter.BoxLayout ();
35+
}
4836

49-
private void reallocate () {
50-
foreach (var child in get_children ()) {
51-
unowned WorkspaceInsertThumb thumb = child as WorkspaceInsertThumb;
52-
if (thumb != null) {
53-
thumb.scale_factor = scale_factor;
54-
}
37+
private void reallocate () {
38+
foreach (var child in get_children ()) {
39+
unowned WorkspaceInsertThumb thumb = child as WorkspaceInsertThumb;
40+
if (thumb != null) {
41+
thumb.scale_factor = scale_factor;
5542
}
5643
}
44+
}
5745

58-
public void add_group (IconGroup group) {
59-
var index = group.workspace.index ();
46+
public void add_group (IconGroup group) {
47+
var index = group.workspace.index ();
6048

61-
insert_child_at_index (group, index * 2);
49+
insert_child_at_index (group, index * 2);
6250

63-
var thumb = new WorkspaceInsertThumb (index, scale_factor);
64-
thumb.notify["expanded"].connect_after (expanded_changed);
65-
insert_child_at_index (thumb, index * 2);
51+
var thumb = new WorkspaceInsertThumb (index, scale_factor);
52+
thumb.notify["expanded"].connect_after (expanded_changed);
53+
insert_child_at_index (thumb, index * 2);
6654

67-
update_inserter_indices ();
68-
}
55+
update_inserter_indices ();
56+
}
6957

70-
public void remove_group (IconGroup group) {
71-
var thumb = (WorkspaceInsertThumb) group.get_previous_sibling ();
72-
thumb.notify["expanded"].disconnect (expanded_changed);
73-
remove_child (thumb);
58+
public void remove_group (IconGroup group) {
59+
var thumb = (WorkspaceInsertThumb) group.get_previous_sibling ();
60+
thumb.notify["expanded"].disconnect (expanded_changed);
61+
remove_child (thumb);
7462

75-
remove_child (group);
63+
remove_child (group);
7664

77-
update_inserter_indices ();
78-
}
65+
update_inserter_indices ();
66+
}
67+
68+
/**
69+
* Removes an icon group "in place".
70+
* When initially dragging an icon group we remove
71+
* it and it's previous WorkspaceInsertThumb. This would make
72+
* the container immediately reallocate and fill the empty space
73+
* with right-most IconGroups.
74+
*
75+
* We don't want that until the IconGroup
76+
* leaves the expanded WorkspaceInsertThumb.
77+
*/
78+
public void remove_group_in_place (IconGroup group) {
79+
var deleted_thumb = (WorkspaceInsertThumb) group.get_previous_sibling ();
80+
var deleted_placeholder_thumb = (WorkspaceInsertThumb) group.get_next_sibling ();
81+
82+
remove_group (group);
7983

8084
/**
81-
* Removes an icon group "in place".
82-
* When initially dragging an icon group we remove
83-
* it and it's previous WorkspaceInsertThumb. This would make
84-
* the container immediately reallocate and fill the empty space
85-
* with right-most IconGroups.
86-
*
87-
* We don't want that until the IconGroup
88-
* leaves the expanded WorkspaceInsertThumb.
89-
*/
90-
public void remove_group_in_place (IconGroup group) {
91-
var deleted_thumb = (WorkspaceInsertThumb) group.get_previous_sibling ();
92-
var deleted_placeholder_thumb = (WorkspaceInsertThumb) group.get_next_sibling ();
93-
94-
remove_group (group);
95-
96-
/**
97-
* We will account for that empty space
98-
* by manually expanding the next WorkspaceInsertThumb with the
99-
* width we deleted. Because the IconGroup is still hovering over
100-
* the expanded thumb, we will also update the drag & drop action
101-
* of IconGroup on that.
102-
*/
103-
if (deleted_placeholder_thumb != null) {
104-
float deleted_width = deleted_thumb.get_width () + group.get_width ();
105-
deleted_placeholder_thumb.expanded = true;
106-
deleted_placeholder_thumb.width += deleted_width;
107-
group.set_hovered_actor (deleted_placeholder_thumb);
108-
}
85+
* We will account for that empty space
86+
* by manually expanding the next WorkspaceInsertThumb with the
87+
* width we deleted. Because the IconGroup is still hovering over
88+
* the expanded thumb, we will also update the drag & drop action
89+
* of IconGroup on that.
90+
*/
91+
if (deleted_placeholder_thumb != null) {
92+
float deleted_width = deleted_thumb.get_width () + group.get_width ();
93+
deleted_placeholder_thumb.expanded = true;
94+
deleted_placeholder_thumb.width += deleted_width;
95+
group.set_hovered_actor (deleted_placeholder_thumb);
10996
}
97+
}
11098

111-
public void reset_thumbs (int delay) {
112-
foreach (var child in get_children ()) {
113-
unowned WorkspaceInsertThumb thumb = child as WorkspaceInsertThumb;
114-
if (thumb != null) {
115-
thumb.delay = delay;
116-
thumb.destroy_all_children ();
117-
}
99+
public void reset_thumbs (int delay) {
100+
foreach (var child in get_children ()) {
101+
unowned WorkspaceInsertThumb thumb = child as WorkspaceInsertThumb;
102+
if (thumb != null) {
103+
thumb.delay = delay;
104+
thumb.destroy_all_children ();
118105
}
119106
}
107+
}
120108

121-
private void expanded_changed (ParamSpec param) {
122-
request_reposition (true);
123-
}
109+
private void expanded_changed (ParamSpec param) {
110+
request_reposition (true);
111+
}
124112

125-
/**
126-
* Calculates the width that will be occupied taking currently running animations
127-
* end states into account
128-
*/
129-
public float calculate_total_width () {
130-
var spacing = InternalUtils.scale_to_int (SPACING, scale_factor);
131-
var group_width = InternalUtils.scale_to_int (GROUP_WIDTH, scale_factor);
132-
133-
var width = 0.0f;
134-
foreach (var child in get_children ()) {
135-
if (child is WorkspaceInsertThumb) {
136-
if (((WorkspaceInsertThumb) child).expanded)
137-
width += group_width + spacing * 2;
138-
else
139-
width += spacing;
140-
} else
141-
width += group_width;
142-
}
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+
}
143131

144-
width += spacing;
132+
width += spacing;
145133

146-
return width;
147-
}
134+
return width;
135+
}
148136

149-
public void force_reposition () {
150-
var children = get_children ();
137+
public void force_reposition () {
138+
var children = get_children ();
151139

152-
foreach (var child in children) {
153-
if (child is IconGroup) {
154-
remove_group ((IconGroup) child);
155-
}
140+
foreach (var child in children) {
141+
if (child is IconGroup) {
142+
remove_group ((IconGroup) child);
156143
}
144+
}
157145

158-
foreach (var child in children) {
159-
if (child is IconGroup) {
160-
add_group ((IconGroup) child);
161-
}
146+
foreach (var child in children) {
147+
if (child is IconGroup) {
148+
add_group ((IconGroup) child);
162149
}
163150
}
151+
}
164152

165-
private void update_inserter_indices () {
166-
var current_index = 0;
153+
private void update_inserter_indices () {
154+
var current_index = 0;
167155

168-
foreach (var child in get_children ()) {
169-
unowned WorkspaceInsertThumb thumb = child as WorkspaceInsertThumb;
170-
if (thumb != null) {
171-
thumb.workspace_index = current_index++;
172-
}
156+
foreach (var child in get_children ()) {
157+
unowned WorkspaceInsertThumb thumb = child as WorkspaceInsertThumb;
158+
if (thumb != null) {
159+
thumb.workspace_index = current_index++;
173160
}
174161
}
175162
}

0 commit comments

Comments
 (0)