async initialization of the candy and displays

This commit is contained in:
Vivianne 2022-03-18 02:28:49 -07:00
parent 8028525007
commit 00995b6d4c
7 changed files with 75 additions and 25 deletions

View file

@ -1,8 +1,13 @@
using Deskcandy.Candy;
namespace Deskcandy { namespace Deskcandy {
public class Application : Gtk.Application { 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 bool enabled { get; set; }
public Application() { public Application() {
@ -11,10 +16,14 @@ namespace Deskcandy {
var toggle_enabled = new PropertyAction("toggle-enabled", this, "enabled"); var toggle_enabled = new PropertyAction("toggle-enabled", this, "enabled");
toggle_enabled.notify.connect(this.on_toggle_enabled); toggle_enabled.notify.connect(this.on_toggle_enabled);
this.add_action(toggle_enabled); this.add_action(toggle_enabled);
this.set_up_actions(); 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() { private void on_toggle_enabled() {
@ -41,10 +50,10 @@ namespace Deskcandy {
this.window = new Window(this); this.window = new Window(this);
} }
this.desktop_window = new DesktopWindow(this);
this.window.present(); this.window.present();
var desktop_win = new DesktopWindow(this); this.initialize_async.begin();
desktop_win.present();
} }
} }
} }

10
src/candy/base.vala Normal file
View file

@ -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;
}
}

View file

@ -1,15 +1,24 @@
namespace Deskcandy.Candy { namespace Deskcandy.Candy {
class XScreensaver : Object { class XScreensaver : BaseCandy {
public string config_dir { get; private set; } public string config_dir { get; private set; }
public string path_dir { get; private set; } public string path_dir { get; private set; }
public XScreensaver() { 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() { private async void hacky_determine_directories() {
warning("HACK: launching xscreensaver-settings to figure out the configuration"); warning("HACK: launching xscreensaver-settings to figure out the configuration");
try { try {
SourceFunc callback = this.hacky_determine_directories.callback;
var proc = new Subprocess(SubprocessFlags.STDERR_PIPE, "xscreensaver-settings", "--debug"); var proc = new Subprocess(SubprocessFlags.STDERR_PIPE, "xscreensaver-settings", "--debug");
GLib.Timeout.add(250, () => { GLib.Timeout.add(250, () => {
proc.send_signal(15); proc.send_signal(15);
@ -19,11 +28,12 @@ namespace Deskcandy.Candy {
this.interpret_output(dis); this.interpret_output(dis);
} catch (Error e) { } catch (Error e) {
warning(e.message); warning(e.message);
return false;
} }
callback();
return false; return false;
}); });
yield;
} catch (Error e) { } catch (Error e) {
error("failed to initialize xscreensaver settings."); error("failed to initialize xscreensaver settings.");

View file

@ -1,27 +1,41 @@
using Deskcandy.Candy;
namespace Deskcandy { namespace Deskcandy {
[GtkTemplate(ui = "/moe/solarpunk/Deskcandy/desktop_window.ui")] [GtkTemplate(ui = "/moe/solarpunk/Deskcandy/desktop_window.ui")]
public class DesktopWindow : Gtk.Window { public class DesktopWindow : Gtk.Window {
public DesktopWindow(Gtk.Application app) { private Gtk.Socket socket;
private Subprocess proc;
public DesktopWindow(Application app) {
Object(application: app); Object(application: app);
Gdk.Rectangle rect = this.get_display().get_primary_monitor().get_geometry(); Gdk.Rectangle rect = this.get_display().get_primary_monitor().get_geometry();
this.set_default_size(rect.width, rect.height); this.set_default_size(rect.width, rect.height);
this.set_keep_below(true); this.set_keep_below(true);
this.refresh_socket(); app.initialized.connect(this.on_initialized);
} }
public void refresh_socket() { public void refresh_socket(BaseCandy candy) {
Gtk.Socket socket = new Gtk.Socket(); if (this.socket != null) {
socket.set_visible(true); this.remove(this.socket);
this.add(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 { try {
Subprocess proc = new Subprocess(SubprocessFlags.NONE, "/usr/lib64/misc/xscreensaver/unknownpleasures", "-window-id", id.to_string()); this.proc = candy.launch((uint)this.socket.get_id());
} catch (GLib.Error e) { } catch (Error e) {
error(e.message); error(e.message);
} }
} }
private void on_initialized(BaseCandy candy) {
this.present();
this.refresh_socket(candy);
}
} }
} }

View file

@ -3,6 +3,7 @@ deskcandy_sources = [
'window.vala', 'window.vala',
'desktop_window.vala', 'desktop_window.vala',
'application.vala', 'application.vala',
'candy/base.vala',
'candy/xscreensaver.vala' 'candy/xscreensaver.vala'
] ]

View file

@ -231,7 +231,7 @@
</mime-types> </mime-types>
</object> </object>
<template class="DeskcandyWindow" parent="GtkApplicationWindow"> <template class="DeskcandyWindow" parent="GtkApplicationWindow">
<property name="visible">True</property> <property name="visible">False</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="border-width">5</property> <property name="border-width">5</property>
<property name="window-position">center</property> <property name="window-position">center</property>

View file

@ -1,12 +1,11 @@
using GLib; using GLib;
using Deskcandy.Candy;
namespace Deskcandy { namespace Deskcandy {
[GtkTemplate (ui = "/moe/solarpunk/Deskcandy/window.ui")] [GtkTemplate (ui = "/moe/solarpunk/Deskcandy/window.ui")]
public class Window : Gtk.ApplicationWindow { public class Window : Gtk.ApplicationWindow {
private Gtk.Socket socket; private Gtk.Socket socket;
[GtkChild]
private unowned Gtk.Switch enabler_toggle;
[GtkChild] [GtkChild]
private unowned Gtk.MenuButton open_menu_button; private unowned Gtk.MenuButton open_menu_button;
[GtkChild] [GtkChild]
@ -16,7 +15,9 @@ namespace Deskcandy {
[GtkChild] [GtkChild]
private unowned Gtk.Stack main_stack; private unowned Gtk.Stack main_stack;
public Window (Gtk.Application app) { private Subprocess proc;
public Window (Application app) {
Object (application: app); Object (application: app);
var preset_action_group = new SimpleActionGroup(); var preset_action_group = new SimpleActionGroup();
@ -34,23 +35,28 @@ namespace Deskcandy {
var menu = (GLib.MenuModel)builder.get_object("main_menu"); var menu = (GLib.MenuModel)builder.get_object("main_menu");
this.open_menu_button.menu_model = menu; this.open_menu_button.menu_model = menu;
app.initialized.connect(this.on_initialized);
app.notify["enabled"].connect(this.on_notify_enabled); app.notify["enabled"].connect(this.on_notify_enabled);
this.refresh_socket();
} }
private void refresh_socket() { public void on_initialized(BaseCandy candy) {
this.refresh_socket(candy);
}
private void refresh_socket(BaseCandy candy) {
if (this.socket != null) { if (this.socket != null) {
this.preview.remove(this.socket); this.preview.remove(this.socket);
this.proc.send_signal(15);
} }
this.socket = new Gtk.Socket(); this.socket = new Gtk.Socket();
this.socket.realize();
this.socket.expand = true; this.socket.expand = true;
this.socket.visible = true; this.socket.visible = true;
this.preview.add(this.socket); this.preview.add(this.socket);
try { try {
var subprocess = new Subprocess(SubprocessFlags.NONE, "/usr/lib64/misc/xscreensaver/abstractile", "-window-id", ((uint)this.socket.get_id()).to_string()); this.proc = candy.launch((uint)this.socket.get_id());
} catch (Error e) { } catch (Error e) {
error(e.message); error(e.message);
} }