Skip to content

Commit 3cac729

Browse files
authored
Inline namespaces (#2252)
1 parent a8cb5cd commit 3cac729

12 files changed

+1573
-1728
lines changed

src/Background/Background.vala

Lines changed: 203 additions & 216 deletions
Large diffs are not rendered by default.
Lines changed: 63 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,53 @@
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-
public class BackgroundCache : Object {
20-
private static BackgroundCache? instance = null;
21-
22-
public static unowned BackgroundCache get_default () {
23-
if (instance == null)
24-
instance = new BackgroundCache ();
25-
26-
return instance;
27-
}
1+
/*
2+
* SPDX-License-Identifier: GPL-3.0-or-later
3+
* SPDX-FileCopyrightText: 2014 Tom Beckmann
4+
* 2025 elementary, Inc. (https://elementary.io)
5+
*/
286

29-
public signal void file_changed (string filename);
7+
public class Gala.BackgroundCache : Object {
8+
private static BackgroundCache? instance = null;
309

31-
private Gee.HashMap<string,FileMonitor> file_monitors;
32-
private BackgroundSource background_source;
10+
public static unowned BackgroundCache get_default () {
11+
if (instance == null)
12+
instance = new BackgroundCache ();
3313

34-
private Animation animation;
14+
return instance;
15+
}
3516

36-
public BackgroundCache () {
37-
Object ();
38-
}
17+
public signal void file_changed (string filename);
3918

40-
construct {
41-
file_monitors = new Gee.HashMap<string,FileMonitor> ();
42-
}
19+
private Gee.HashMap<string,FileMonitor> file_monitors;
20+
private BackgroundSource background_source;
4321

44-
public void monitor_file (string filename) {
45-
if (file_monitors.has_key (filename))
46-
return;
47-
48-
var file = File.new_for_path (filename);
49-
try {
50-
var monitor = file.monitor (FileMonitorFlags.NONE, null);
51-
monitor.changed.connect (() => {
52-
file_changed (filename);
53-
});
54-
55-
file_monitors[filename] = monitor;
56-
} catch (Error e) {
57-
warning ("Failed to monitor %s: %s", filename, e.message);
58-
}
59-
}
22+
private Animation animation;
6023

61-
public async Animation get_animation (string filename) {
62-
if (animation != null && animation.filename == filename) {
63-
Idle.add (() => {
64-
get_animation.callback ();
65-
return Source.REMOVE;
66-
});
67-
yield;
24+
public BackgroundCache () {
25+
Object ();
26+
}
27+
28+
construct {
29+
file_monitors = new Gee.HashMap<string,FileMonitor> ();
30+
}
6831

69-
return animation;
70-
}
32+
public void monitor_file (string filename) {
33+
if (file_monitors.has_key (filename))
34+
return;
7135

72-
var animation = new Animation (filename);
36+
var file = File.new_for_path (filename);
37+
try {
38+
var monitor = file.monitor (FileMonitorFlags.NONE, null);
39+
monitor.changed.connect (() => {
40+
file_changed (filename);
41+
});
7342

74-
yield animation.load ();
43+
file_monitors[filename] = monitor;
44+
} catch (Error e) {
45+
warning ("Failed to monitor %s: %s", filename, e.message);
46+
}
47+
}
7548

49+
public async Animation get_animation (string filename) {
50+
if (animation != null && animation.filename == filename) {
7651
Idle.add (() => {
7752
get_animation.callback ();
7853
return Source.REMOVE;
@@ -82,20 +57,32 @@ namespace Gala {
8257
return animation;
8358
}
8459

85-
public BackgroundSource get_background_source (Meta.Display display) {
86-
if (background_source == null) {
87-
background_source = new BackgroundSource (display);
88-
background_source.use_count = 1;
89-
} else
90-
background_source.use_count++;
60+
var animation = new Animation (filename);
9161

92-
return background_source;
93-
}
62+
yield animation.load ();
63+
64+
Idle.add (() => {
65+
get_animation.callback ();
66+
return Source.REMOVE;
67+
});
68+
yield;
69+
70+
return animation;
71+
}
72+
73+
public BackgroundSource get_background_source (Meta.Display display) {
74+
if (background_source == null) {
75+
background_source = new BackgroundSource (display);
76+
background_source.use_count = 1;
77+
} else
78+
background_source.use_count++;
79+
80+
return background_source;
81+
}
9482

95-
public void release_background_source () {
96-
if (--background_source.use_count == 0) {
97-
background_source.destroy ();
98-
}
83+
public void release_background_source () {
84+
if (--background_source.use_count == 0) {
85+
background_source.destroy ();
9986
}
10087
}
10188
}
Lines changed: 48 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,68 @@
1-
//
2-
// Copyright (C) 2013 Tom Beckmann, Rico Tzschichholz
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: 2013 Tom Beckmann
4+
* 2013 Rico Tzschichholz
5+
* 2025 elementary, Inc. (https://elementary.io)
6+
*/
177

18-
namespace Gala {
19-
public class BackgroundContainer : Meta.BackgroundGroup {
20-
public signal void changed ();
21-
public signal void show_background_menu (int x, int y);
8+
public class Gala.BackgroundContainer : Meta.BackgroundGroup {
9+
public signal void changed ();
10+
public signal void show_background_menu (int x, int y);
2211

23-
public Meta.Display display { get; construct; }
12+
public Meta.Display display { get; construct; }
2413

25-
public BackgroundContainer (Meta.Display display) {
26-
Object (display: display);
27-
}
14+
public BackgroundContainer (Meta.Display display) {
15+
Object (display: display);
16+
}
2817

29-
construct {
30-
unowned var monitor_manager = display.get_context ().get_backend ().get_monitor_manager ();
31-
monitor_manager.monitors_changed.connect (update);
18+
construct {
19+
unowned var monitor_manager = display.get_context ().get_backend ().get_monitor_manager ();
20+
monitor_manager.monitors_changed.connect (update);
3221

33-
reactive = true;
34-
button_release_event.connect ((event) => {
35-
float x, y;
36-
event.get_coords (out x, out y);
37-
if (event.get_button () == Clutter.Button.SECONDARY) {
38-
show_background_menu ((int)x, (int)y);
39-
}
40-
});
22+
reactive = true;
23+
button_release_event.connect ((event) => {
24+
float x, y;
25+
event.get_coords (out x, out y);
26+
if (event.get_button () == Clutter.Button.SECONDARY) {
27+
show_background_menu ((int)x, (int)y);
28+
}
29+
});
4130

42-
set_black_background (true);
43-
update ();
44-
}
31+
set_black_background (true);
32+
update ();
33+
}
4534

46-
~BackgroundContainer () {
47-
unowned var monitor_manager = display.get_context ().get_backend ().get_monitor_manager ();
48-
monitor_manager.monitors_changed.disconnect (update);
49-
}
35+
~BackgroundContainer () {
36+
unowned var monitor_manager = display.get_context ().get_backend ().get_monitor_manager ();
37+
monitor_manager.monitors_changed.disconnect (update);
38+
}
5039

51-
public void set_black_background (bool black) {
40+
public void set_black_background (bool black) {
5241
#if HAS_MUTTER47
53-
set_background_color (black ? Cogl.Color.from_string ("Black") : null);
42+
set_background_color (black ? Cogl.Color.from_string ("Black") : null);
5443
#else
55-
set_background_color (black ? Clutter.Color.from_string ("Black") : null);
44+
set_background_color (black ? Clutter.Color.from_string ("Black") : null);
5645
#endif
57-
}
46+
}
5847

59-
private void update () {
60-
var reference_child = (get_child_at_index (0) as BackgroundManager);
61-
if (reference_child != null)
62-
reference_child.changed.disconnect (background_changed);
48+
private void update () {
49+
var reference_child = (get_child_at_index (0) as BackgroundManager);
50+
if (reference_child != null)
51+
reference_child.changed.disconnect (background_changed);
6352

64-
destroy_all_children ();
53+
destroy_all_children ();
6554

66-
for (var i = 0; i < display.get_n_monitors (); i++) {
67-
var background = new BackgroundManager (display, i);
55+
for (var i = 0; i < display.get_n_monitors (); i++) {
56+
var background = new BackgroundManager (display, i);
6857

69-
add_child (background);
58+
add_child (background);
7059

71-
if (i == 0)
72-
background.changed.connect (background_changed);
73-
}
60+
if (i == 0)
61+
background.changed.connect (background_changed);
7462
}
63+
}
7564

76-
private void background_changed () {
77-
changed ();
78-
}
65+
private void background_changed () {
66+
changed ();
7967
}
8068
}

0 commit comments

Comments
 (0)