From 00995b6d4cca089003e752508d06c8eeebec367b Mon Sep 17 00:00:00 2001 From: Vivianne Langdon Date: Fri, 18 Mar 2022 02:28:49 -0700 Subject: [PATCH] async initialization of the candy and displays --- src/application.vala | 19 ++++++++++++++----- src/candy/base.vala | 10 ++++++++++ src/candy/xscreensaver.vala | 16 +++++++++++++--- src/desktop_window.vala | 32 +++++++++++++++++++++++--------- src/meson.build | 1 + src/window.ui | 2 +- src/window.vala | 20 +++++++++++++------- 7 files changed, 75 insertions(+), 25 deletions(-) create mode 100644 src/candy/base.vala diff --git a/src/application.vala b/src/application.vala index 63753f3..6e26f15 100644 --- a/src/application.vala +++ b/src/application.vala @@ -1,8 +1,13 @@ +using Deskcandy.Candy; namespace Deskcandy { public class Application : Gtk.Application { - private Gtk.Window window; + public signal void initialized(BaseCandy candy); + private Gtk.Window window; + private Gtk.Window desktop_window; + + public BaseCandy candy { get; private set; } public bool enabled { get; set; } public Application() { @@ -11,10 +16,14 @@ namespace Deskcandy { var toggle_enabled = new PropertyAction("toggle-enabled", this, "enabled"); toggle_enabled.notify.connect(this.on_toggle_enabled); this.add_action(toggle_enabled); - this.set_up_actions(); - var xss = new Candy.XScreensaver(); + this.candy = new XScreensaver(); + } + + private async void initialize_async() { + yield this.candy.initialize(); + initialized(this.candy); } private void on_toggle_enabled() { @@ -41,10 +50,10 @@ namespace Deskcandy { this.window = new Window(this); } + this.desktop_window = new DesktopWindow(this); this.window.present(); - var desktop_win = new DesktopWindow(this); - desktop_win.present(); + this.initialize_async.begin(); } } } diff --git a/src/candy/base.vala b/src/candy/base.vala new file mode 100644 index 0000000..c532fc5 --- /dev/null +++ b/src/candy/base.vala @@ -0,0 +1,10 @@ +namespace Deskcandy.Candy { + public abstract class BaseCandy : Object { + protected BaseCandy() { + } + + public abstract async void initialize(); + + public abstract Subprocess launch(uint socket_id) throws Error; + } +} diff --git a/src/candy/xscreensaver.vala b/src/candy/xscreensaver.vala index 441cd60..94ec703 100644 --- a/src/candy/xscreensaver.vala +++ b/src/candy/xscreensaver.vala @@ -1,15 +1,24 @@ namespace Deskcandy.Candy { - class XScreensaver : Object { + class XScreensaver : BaseCandy { public string config_dir { get; private set; } public string path_dir { get; private set; } public XScreensaver() { - this.hacky_determine_directories.begin(); + } + + public override async void initialize() { + yield this.hacky_determine_directories(); + } + + public override Subprocess launch(uint socket_id) throws Error { + message("Launching..."); + return new Subprocess(SubprocessFlags.NONE, @"$(this.path_dir)/abstractile", "-window-id", socket_id.to_string()); } private async void hacky_determine_directories() { warning("HACK: launching xscreensaver-settings to figure out the configuration"); try { + SourceFunc callback = this.hacky_determine_directories.callback; var proc = new Subprocess(SubprocessFlags.STDERR_PIPE, "xscreensaver-settings", "--debug"); GLib.Timeout.add(250, () => { proc.send_signal(15); @@ -19,11 +28,12 @@ namespace Deskcandy.Candy { this.interpret_output(dis); } catch (Error e) { warning(e.message); - return false; } + callback(); return false; }); + yield; } catch (Error e) { error("failed to initialize xscreensaver settings."); diff --git a/src/desktop_window.vala b/src/desktop_window.vala index 08f6aed..b131dbb 100644 --- a/src/desktop_window.vala +++ b/src/desktop_window.vala @@ -1,27 +1,41 @@ +using Deskcandy.Candy; + namespace Deskcandy { + [GtkTemplate(ui = "/moe/solarpunk/Deskcandy/desktop_window.ui")] public class DesktopWindow : Gtk.Window { - public DesktopWindow(Gtk.Application app) { + private Gtk.Socket socket; + private Subprocess proc; + + public DesktopWindow(Application app) { Object(application: app); Gdk.Rectangle rect = this.get_display().get_primary_monitor().get_geometry(); this.set_default_size(rect.width, rect.height); this.set_keep_below(true); - this.refresh_socket(); + app.initialized.connect(this.on_initialized); } - public void refresh_socket() { - Gtk.Socket socket = new Gtk.Socket(); - socket.set_visible(true); - this.add(socket); + public void refresh_socket(BaseCandy candy) { + if (this.socket != null) { + this.remove(this.socket); + this.proc.send_signal(15); + } - var id = (uint)socket.get_id(); + this.socket = new Gtk.Socket(); + this.socket.set_visible(true); + this.add(this.socket); try { - Subprocess proc = new Subprocess(SubprocessFlags.NONE, "/usr/lib64/misc/xscreensaver/unknownpleasures", "-window-id", id.to_string()); - } catch (GLib.Error e) { + this.proc = candy.launch((uint)this.socket.get_id()); + } catch (Error e) { error(e.message); } } + + private void on_initialized(BaseCandy candy) { + this.present(); + this.refresh_socket(candy); + } } } diff --git a/src/meson.build b/src/meson.build index 491fd5b..5d7e27a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -3,6 +3,7 @@ deskcandy_sources = [ 'window.vala', 'desktop_window.vala', 'application.vala', + 'candy/base.vala', 'candy/xscreensaver.vala' ] diff --git a/src/window.ui b/src/window.ui index b5eb53f..0196d6f 100644 --- a/src/window.ui +++ b/src/window.ui @@ -231,7 +231,7 @@