Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
419 changes: 203 additions & 216 deletions src/Background/Background.vala

Large diffs are not rendered by default.

139 changes: 63 additions & 76 deletions src/Background/BackgroundCache.vala
Original file line number Diff line number Diff line change
@@ -1,78 +1,53 @@
//
// Copyright (C) 2014 Tom Beckmann
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

namespace Gala {
public class BackgroundCache : Object {
private static BackgroundCache? instance = null;

public static unowned BackgroundCache get_default () {
if (instance == null)
instance = new BackgroundCache ();

return instance;
}
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2014 Tom Beckmann
* 2025 elementary, Inc. (https://elementary.io)
*/

public signal void file_changed (string filename);
public class Gala.BackgroundCache : Object {
private static BackgroundCache? instance = null;

private Gee.HashMap<string,FileMonitor> file_monitors;
private BackgroundSource background_source;
public static unowned BackgroundCache get_default () {
if (instance == null)
instance = new BackgroundCache ();

private Animation animation;
return instance;
}

public BackgroundCache () {
Object ();
}
public signal void file_changed (string filename);

construct {
file_monitors = new Gee.HashMap<string,FileMonitor> ();
}
private Gee.HashMap<string,FileMonitor> file_monitors;
private BackgroundSource background_source;

public void monitor_file (string filename) {
if (file_monitors.has_key (filename))
return;

var file = File.new_for_path (filename);
try {
var monitor = file.monitor (FileMonitorFlags.NONE, null);
monitor.changed.connect (() => {
file_changed (filename);
});

file_monitors[filename] = monitor;
} catch (Error e) {
warning ("Failed to monitor %s: %s", filename, e.message);
}
}
private Animation animation;

public async Animation get_animation (string filename) {
if (animation != null && animation.filename == filename) {
Idle.add (() => {
get_animation.callback ();
return Source.REMOVE;
});
yield;
public BackgroundCache () {
Object ();
}

construct {
file_monitors = new Gee.HashMap<string,FileMonitor> ();
}

return animation;
}
public void monitor_file (string filename) {
if (file_monitors.has_key (filename))
return;

var animation = new Animation (filename);
var file = File.new_for_path (filename);
try {
var monitor = file.monitor (FileMonitorFlags.NONE, null);
monitor.changed.connect (() => {
file_changed (filename);
});

yield animation.load ();
file_monitors[filename] = monitor;
} catch (Error e) {
warning ("Failed to monitor %s: %s", filename, e.message);
}
}

public async Animation get_animation (string filename) {
if (animation != null && animation.filename == filename) {
Idle.add (() => {
get_animation.callback ();
return Source.REMOVE;
Expand All @@ -82,20 +57,32 @@ namespace Gala {
return animation;
}

public BackgroundSource get_background_source (Meta.Display display) {
if (background_source == null) {
background_source = new BackgroundSource (display);
background_source.use_count = 1;
} else
background_source.use_count++;
var animation = new Animation (filename);

return background_source;
}
yield animation.load ();

Idle.add (() => {
get_animation.callback ();
return Source.REMOVE;
});
yield;

return animation;
}

public BackgroundSource get_background_source (Meta.Display display) {
if (background_source == null) {
background_source = new BackgroundSource (display);
background_source.use_count = 1;
} else
background_source.use_count++;

return background_source;
}

public void release_background_source () {
if (--background_source.use_count == 0) {
background_source.destroy ();
}
public void release_background_source () {
if (--background_source.use_count == 0) {
background_source.destroy ();
}
}
}
108 changes: 48 additions & 60 deletions src/Background/BackgroundContainer.vala
Original file line number Diff line number Diff line change
@@ -1,80 +1,68 @@
//
// Copyright (C) 2013 Tom Beckmann, Rico Tzschichholz
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2013 Tom Beckmann
* 2013 Rico Tzschichholz
* 2025 elementary, Inc. (https://elementary.io)
*/

namespace Gala {
public class BackgroundContainer : Meta.BackgroundGroup {
public signal void changed ();
public signal void show_background_menu (int x, int y);
public class Gala.BackgroundContainer : Meta.BackgroundGroup {
public signal void changed ();
public signal void show_background_menu (int x, int y);

public Meta.Display display { get; construct; }
public Meta.Display display { get; construct; }

public BackgroundContainer (Meta.Display display) {
Object (display: display);
}
public BackgroundContainer (Meta.Display display) {
Object (display: display);
}

construct {
unowned var monitor_manager = display.get_context ().get_backend ().get_monitor_manager ();
monitor_manager.monitors_changed.connect (update);
construct {
unowned var monitor_manager = display.get_context ().get_backend ().get_monitor_manager ();
monitor_manager.monitors_changed.connect (update);

reactive = true;
button_release_event.connect ((event) => {
float x, y;
event.get_coords (out x, out y);
if (event.get_button () == Clutter.Button.SECONDARY) {
show_background_menu ((int)x, (int)y);
}
});
reactive = true;
button_release_event.connect ((event) => {
float x, y;
event.get_coords (out x, out y);
if (event.get_button () == Clutter.Button.SECONDARY) {
show_background_menu ((int)x, (int)y);
}
});

set_black_background (true);
update ();
}
set_black_background (true);
update ();
}

~BackgroundContainer () {
unowned var monitor_manager = display.get_context ().get_backend ().get_monitor_manager ();
monitor_manager.monitors_changed.disconnect (update);
}
~BackgroundContainer () {
unowned var monitor_manager = display.get_context ().get_backend ().get_monitor_manager ();
monitor_manager.monitors_changed.disconnect (update);
}

public void set_black_background (bool black) {
public void set_black_background (bool black) {
#if HAS_MUTTER47
set_background_color (black ? Cogl.Color.from_string ("Black") : null);
set_background_color (black ? Cogl.Color.from_string ("Black") : null);
#else
set_background_color (black ? Clutter.Color.from_string ("Black") : null);
set_background_color (black ? Clutter.Color.from_string ("Black") : null);
#endif
}
}

private void update () {
var reference_child = (get_child_at_index (0) as BackgroundManager);
if (reference_child != null)
reference_child.changed.disconnect (background_changed);
private void update () {
var reference_child = (get_child_at_index (0) as BackgroundManager);
if (reference_child != null)
reference_child.changed.disconnect (background_changed);

destroy_all_children ();
destroy_all_children ();

for (var i = 0; i < display.get_n_monitors (); i++) {
var background = new BackgroundManager (display, i);
for (var i = 0; i < display.get_n_monitors (); i++) {
var background = new BackgroundManager (display, i);

add_child (background);
add_child (background);

if (i == 0)
background.changed.connect (background_changed);
}
if (i == 0)
background.changed.connect (background_changed);
}
}

private void background_changed () {
changed ();
}
private void background_changed () {
changed ();
}
}
Loading
Loading