Skip to content
Closed
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
23 changes: 23 additions & 0 deletions src/animation/icon_motion.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Singularity.Animation {
public const uint DOCK_LIMIT = 500;

private const string PLAYING = "singularity-icon-motion";
private const string ANIMATED_KEY = "animated-icons";
internal const string SOURCE = "singularity-icon-source";

public static void set_source(Gtk.Image image, GLib.File? file) {
Expand All @@ -28,6 +29,7 @@ namespace Singularity.Animation {

public static bool animated(Gtk.Image image) {
#if IRIDE
if (!animated_icons_enabled()) return false;
int size = image.pixel_size > 0 ? image.pixel_size : int.min(image.get_width(), image.get_height());
return size > 0 && IconPlayback.sibling_of(image, size, image.get_scale_factor()) != null;
#else
Expand Down Expand Up @@ -69,9 +71,30 @@ namespace Singularity.Animation {

private static bool allowed() {
if (Singularity.Motion.reduced()) return false;
if (!animated_icons_enabled()) return false;
return !GLib.PowerProfileMonitor.dup_default().power_saver_enabled;
}
#endif

// The "animated-icons" switch in the desktop settings. Read once and cached,
// like Motion reads reduce-motion: a missing schema or key means ON.
private static GLib.Settings? _animated_settings = null;

private static bool animated_icons_enabled() {
if (_animated_settings == null) {
var source = GLib.SettingsSchemaSource.get_default();
string schema_id = Singularity.Runtime.desktop_settings_schema;
var schema = source != null ? source.lookup(schema_id, true) : null;
if (schema != null && schema.has_key(ANIMATED_KEY)) {
_animated_settings = new GLib.Settings(schema_id);
}
}
return _animated_settings == null || _animated_settings.get_boolean(ANIMATED_KEY);
}

internal static bool animated_icons_enabled_for_test() {
return animated_icons_enabled();
}
}

#if IRIDE
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/motion/dev.sinty.motiontest.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@
<default>1.0</default>
<summary>Animation duration multiplier</summary>
</key>
<key name="animated-icons" type="b">
<default>true</default>
<summary>Animated Icons</summary>
</key>
</schema>
</schemalist>
13 changes: 13 additions & 0 deletions tests/motion_test.vala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Gtk;
using Singularity;
using Singularity.Animation;

Expand Down Expand Up @@ -354,6 +355,17 @@ void test_reduce_motion() {
assert("--motion-duration-scene: 600ms;" in motion.css());
}

void test_animated_icons_gate() {
fresh_clock();
var settings = new GLib.Settings("dev.sinty.motiontest");
assert(settings.get_boolean("animated-icons") == true);
assert(IconMotion.animated_icons_enabled_for_test());
settings.set_boolean("animated-icons", false);
assert(!IconMotion.animated_icons_enabled_for_test());
settings.set_boolean("animated-icons", true);
assert(IconMotion.animated_icons_enabled_for_test());
}

void test_reduce_motion_setting() {
fresh_clock();
var settings = new GLib.Settings("dev.sinty.motiontest");
Expand Down Expand Up @@ -526,6 +538,7 @@ int main(string[] args) {
Test.add_func("/motion/stagger", test_stagger);
Test.add_func("/motion/groups", test_groups);
Test.add_func("/motion/reduce-motion", test_reduce_motion);
Test.add_func("/motion/animated-icons-gate", test_animated_icons_gate);
Test.add_func("/motion/reduce-motion-setting", test_reduce_motion_setting);
Test.add_func("/motion/skip-all", test_skip_all);
Test.add_func("/motion/morph-math", test_morph_math);
Expand Down