add xscreensaver 'candy' (sub process)

This commit is contained in:
Vivianne 2022-03-18 01:18:23 -07:00
parent 83ced714d7
commit 8028525007
3 changed files with 58 additions and 0 deletions

View File

@ -13,6 +13,8 @@ namespace Deskcandy {
this.add_action(toggle_enabled);
this.set_up_actions();
var xss = new Candy.XScreensaver();
}
private void on_toggle_enabled() {

View File

@ -0,0 +1,54 @@
namespace Deskcandy.Candy {
class XScreensaver : Object {
public string config_dir { get; private set; }
public string path_dir { get; private set; }
public XScreensaver() {
this.hacky_determine_directories.begin();
}
private async void hacky_determine_directories() {
warning("HACK: launching xscreensaver-settings to figure out the configuration");
try {
var proc = new Subprocess(SubprocessFlags.STDERR_PIPE, "xscreensaver-settings", "--debug");
GLib.Timeout.add(250, () => {
proc.send_signal(15);
try {
proc.wait();
var dis = new DataInputStream(proc.get_stderr_pipe());
this.interpret_output(dis);
} catch (Error e) {
warning(e.message);
return false;
}
return false;
});
} catch (Error e) {
error("failed to initialize xscreensaver settings.");
}
}
private void interpret_output(DataInputStream dis) {
Regex config_dir_regex = /xscreensaver-settings: using config directory "(.*)"/;
Regex path_dir_regex = /.*added "(.*)" to \$PATH/;
string line;
try {
while ((line = dis.read_line_utf8()) != null) {
MatchInfo info;
if (config_dir_regex.match(line, 0, out info)) {
this.config_dir = info.fetch(1);
message(@"Found xscreensaver config dir: $(this.config_dir)");
} else if (path_dir_regex.match(line, 0, out info)) {
this.path_dir = info.fetch(1);
message(@"Found xscreensaver path dir: $(this.path_dir)");
}
}
} catch (IOError e) {
error(e.message);
}
}
}
}

View File

@ -3,8 +3,10 @@ deskcandy_sources = [
'window.vala',
'desktop_window.vala',
'application.vala',
'candy/xscreensaver.vala'
]
deskcandy_deps = [
dependency('gio-2.0', version: '>= 2.50'),
dependency('gtk+-3.0', version: '>= 3.22'),