From 2b8624f7f5a9433e85b2d57d50f579ea992ab904 Mon Sep 17 00:00:00 2001 From: Vivianne Langdon Date: Sat, 19 Mar 2022 05:43:51 -0700 Subject: [PATCH] basic picking of screensavers. BUG: some don't work because of egl. --- src/application.vala | 10 +- src/candy/base.vala | 2 +- src/candy/video.vala | 4 +- src/candy/xscreensaver.vala | 10 +- src/candy/xscreensaver_config.vala | 16 +-- src/desktop_window.vala | 6 +- src/window.ui | 159 ++++++++++++++--------------- src/window.vala | 32 +++++- 8 files changed, 134 insertions(+), 105 deletions(-) diff --git a/src/application.vala b/src/application.vala index e8c9e40..98c6528 100644 --- a/src/application.vala +++ b/src/application.vala @@ -2,7 +2,7 @@ using Deskcandy.Candy; namespace Deskcandy { public class Application : Gtk.Application { - public signal void initialized(BaseCandy candy); + public signal void initialized(BaseCandy[] candies); private Gtk.Window window; private Gtk.Window desktop_window; @@ -23,10 +23,14 @@ namespace Deskcandy { private async void initialize_async() { foreach (var candy in this._candies) { - yield candy.initialize(); + try { + yield candy.initialize(); + } catch (Error e) { + error(@"Failed to load candy: $(e.message)"); + } } - initialized(this._candies[1]); + initialized(this._candies); } private void on_toggle_enabled() { diff --git a/src/candy/base.vala b/src/candy/base.vala index 37335c6..fa5ef46 100644 --- a/src/candy/base.vala +++ b/src/candy/base.vala @@ -5,6 +5,6 @@ namespace Deskcandy.Candy { public abstract async void initialize() throws Error; - public abstract Subprocess launch(uint socket_id) throws Error; + public abstract Subprocess launch(uint socket_id, string path) throws Error; } } diff --git a/src/candy/video.vala b/src/candy/video.vala index 28335f1..2c18f47 100644 --- a/src/candy/video.vala +++ b/src/candy/video.vala @@ -6,9 +6,9 @@ namespace Deskcandy.Candy { public override async void initialize() throws Error { } - public override Subprocess launch(uint socket_id) throws Error { + public override Subprocess launch(uint socket_id, string path) throws Error { message("Launching mpv video..."); - return new Subprocess(SubprocessFlags.NONE, "mpv", @"--wid=$socket_id", "--no-audio", "--video-unscaled=downscale-big", "--video-zoom=20", "/home/vv/Videos/Spring_-_Blender_Open_Movie.webm"); + return new Subprocess(SubprocessFlags.NONE, "mpv", @"--wid=$socket_id", "--no-audio", "--video-unscaled=downscale-big", "--video-zoom=20", path); } } } diff --git a/src/candy/xscreensaver.vala b/src/candy/xscreensaver.vala index 3491ee1..ccc62a7 100644 --- a/src/candy/xscreensaver.vala +++ b/src/candy/xscreensaver.vala @@ -17,20 +17,20 @@ namespace Deskcandy.Candy { FileInfo info; message(@"Parsing configs in $(this.config_path)"); while ((info = enumerator.next_file()) != null) { - if (!info.get_name().has_suffix(".xml")) { + var name = info.get_name(); + if (!name.has_suffix(".xml")) { continue; } - var name = info.get_name(); - var config = new XScreensaverConfig(config_dir.resolve_relative_path(info.get_name())); + var config = yield new XScreensaverConfig(config_dir.resolve_relative_path(name)); this.configs.append(config); } message(@"Found $(this.configs.length()) screensavers."); } - public override Subprocess launch(uint socket_id) throws Error { + public override Subprocess launch(uint socket_id, string saver) throws Error { message("Launching XScreensaver..."); - return new Subprocess(SubprocessFlags.NONE, @"$(this.saver_path)/abstractile", "-window-id", socket_id.to_string()); + return new Subprocess(SubprocessFlags.NONE, @"$(this.saver_path)/$saver", "-window-id", socket_id.to_string()); } private async void hacky_determine_directories() { diff --git a/src/candy/xscreensaver_config.vala b/src/candy/xscreensaver_config.vala index 39fe3ad..222802c 100644 --- a/src/candy/xscreensaver_config.vala +++ b/src/candy/xscreensaver_config.vala @@ -9,22 +9,24 @@ namespace Deskcandy.Candy { [Description(nick="::gl")] public string gl { get; set; } + public string description { get; set; } public string arg { get; set;} - [Description(nick="::_description")] - public string description { get; set; } - - public XScreensaverConfig(File file) throws Error { + public async XScreensaverConfig(File file) throws Error { this.initialize("screensaver"); - this.read_from_file(file); + + yield this.read_from_file_async(file); var tag = this.get_child("command"); this.arg = tag.get_attribute("arg"); - debug(@"Loaded $this"); + + tag = this.get_child("_description"); + this.description = tag.text_content.strip(); + message(@"Loaded $this"); } public string to_string() { - return @"Screensaver: $(this.label) [$(this.name) $(this.arg)]"; + return @"Screensaver: $(this.label) [$(this.name)]"; } } } diff --git a/src/desktop_window.vala b/src/desktop_window.vala index b131dbb..3f7151d 100644 --- a/src/desktop_window.vala +++ b/src/desktop_window.vala @@ -27,15 +27,15 @@ namespace Deskcandy { this.add(this.socket); try { - this.proc = candy.launch((uint)this.socket.get_id()); + this.proc = candy.launch((uint)this.socket.get_id(), "abstractile"); } catch (Error e) { error(e.message); } } - private void on_initialized(BaseCandy candy) { + private void on_initialized(BaseCandy[] candies) { this.present(); - this.refresh_socket(candy); + //this.refresh_socket(candy); } } } diff --git a/src/window.ui b/src/window.ui index cdf26bd..0b2e74d 100644 --- a/src/window.ui +++ b/src/window.ui @@ -214,15 +214,18 @@ - + + + Screen Saver 1 The alpha and the omega + @@ -271,55 +274,59 @@ - + True True - presets_liststore - False - True - True - - - + in - - fixed - 30 + + True + True + presets_liststore + False + True + True - - True + + fixed + 30 + + + True + + + 3 + + - - 3 - - - - - - True - fixed - Name - 0 - - - 0 - + + True + fixed + Name + 0 + + + + 0 + + + - - - - - True - fixed - Description - 1 - - - 1 - + + True + fixed + Description + 1 + + + + 1 + + + @@ -513,51 +520,43 @@ vertical 5 - + True True - edit-find-symbolic - False - False - Search for screen savers - - - False - True - 0 - - - - - True - True - screensavers_liststore - False - True - - - + in - - True - Name + + True + True + screensavers_liststore + False + True + - - - 0 - + + True + Name + + + + 0 + + + - - - - - True - Description - - - 1 - + + True + Description + + + True + + + 1 + + + diff --git a/src/window.vala b/src/window.vala index 0ba32d6..fa6baa6 100644 --- a/src/window.vala +++ b/src/window.vala @@ -15,7 +15,11 @@ namespace Deskcandy { [GtkChild] private unowned Gtk.Stack main_stack; + [GtkChild] + private unowned Gtk.ListStore screensavers_liststore; + private Subprocess proc; + private XScreensaver xss; public Window (Application app) { Object (application: app); @@ -39,11 +43,21 @@ namespace Deskcandy { app.notify["enabled"].connect(this.on_notify_enabled); } - public void on_initialized(BaseCandy candy) { - this.refresh_socket(candy); + public void on_initialized(BaseCandy[] candies) { + foreach (BaseCandy candy in candies) { + if (candy is XScreensaver) { + this.xss = (XScreensaver)candy; + Gtk.TreeIter iter; + this.screensavers_liststore.clear(); + foreach (XScreensaverConfig config in this.xss.configs) { + this.screensavers_liststore.append(out iter); + this.screensavers_liststore.set(iter, 0, config.label, 1, config.description, 2, config.name); + } + } + } } - private void refresh_socket(BaseCandy candy) { + private void refresh_socket(BaseCandy candy, string name) { if (this.socket != null) { this.preview.remove(this.socket); this.proc.send_signal(15); @@ -56,7 +70,7 @@ namespace Deskcandy { this.preview.add(this.socket); try { - this.proc = candy.launch((uint)this.socket.get_id()); + this.proc = candy.launch((uint)this.socket.get_id(), name); } catch (Error e) { error(e.message); } @@ -68,6 +82,16 @@ namespace Deskcandy { this.application.quit(); } + [GtkCallback] + private void on_screensaver_chooser_row_activated(Gtk.TreeView treeview, Gtk.TreePath path, Gtk.TreeViewColumn col) { + Gtk.TreeIter iter; + if (treeview.model.get_iter(out iter, path)) { + string name; + treeview.model.get(iter, 2, out name); + this.refresh_socket(this.xss, name); + } + } + private void on_create_preset(SimpleAction a, Variant? v) { this.main_stack.visible_child_name = "editor_page"; }