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 {
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();
}
}
}

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 {
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.");

View file

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

View file

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

View file

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

View file

@ -1,12 +1,11 @@
using GLib;
using Deskcandy.Candy;
namespace Deskcandy {
[GtkTemplate (ui = "/moe/solarpunk/Deskcandy/window.ui")]
public class Window : Gtk.ApplicationWindow {
private Gtk.Socket socket;
[GtkChild]
private unowned Gtk.Switch enabler_toggle;
[GtkChild]
private unowned Gtk.MenuButton open_menu_button;
[GtkChild]
@ -16,7 +15,9 @@ namespace Deskcandy {
[GtkChild]
private unowned Gtk.Stack main_stack;
public Window (Gtk.Application app) {
private Subprocess proc;
public Window (Application app) {
Object (application: app);
var preset_action_group = new SimpleActionGroup();
@ -34,23 +35,28 @@ namespace Deskcandy {
var menu = (GLib.MenuModel)builder.get_object("main_menu");
this.open_menu_button.menu_model = menu;
app.initialized.connect(this.on_initialized);
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) {
this.preview.remove(this.socket);
this.proc.send_signal(15);
}
this.socket = new Gtk.Socket();
this.socket.realize();
this.socket.expand = true;
this.socket.visible = true;
this.preview.add(this.socket);
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) {
error(e.message);
}