84 lines
2.9 KiB
Vala
84 lines
2.9 KiB
Vala
namespace Deskcandy.Candy {
|
|
public class XScreensaver : BaseCandy {
|
|
public string config_path { get; private set; }
|
|
public string saver_path { get; private set; }
|
|
|
|
public List<XScreensaverConfig> configs;
|
|
|
|
public XScreensaver() {
|
|
this.configs = new List<XScreensaverConfig>();
|
|
}
|
|
|
|
public override async void initialize() throws Error {
|
|
yield this.hacky_determine_directories();
|
|
|
|
var config_dir = File.new_for_path(this.config_path);
|
|
var enumerator = yield config_dir.enumerate_children_async("standard::*", FileQueryInfoFlags.NOFOLLOW_SYMLINKS);
|
|
FileInfo info;
|
|
message(@"Parsing configs in $(this.config_path)");
|
|
while ((info = enumerator.next_file()) != null) {
|
|
var name = info.get_name();
|
|
if (!name.has_suffix(".xml")) {
|
|
continue;
|
|
}
|
|
|
|
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 {
|
|
message("Launching XScreensaver...");
|
|
return new Subprocess(SubprocessFlags.NONE, @"$(this.saver_path)/$(this.name)", "-window-id", socket_id.to_string());
|
|
}
|
|
|
|
private async void hacky_determine_directories() {
|
|
// TODO: Make this a first-time thing and save to config
|
|
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);
|
|
try {
|
|
proc.wait();
|
|
var dis = new DataInputStream(proc.get_stderr_pipe());
|
|
this.interpret_output(dis);
|
|
} catch (Error e) {
|
|
warning(e.message);
|
|
}
|
|
|
|
callback();
|
|
return false;
|
|
});
|
|
yield;
|
|
|
|
} 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_path = info.fetch(1);
|
|
message(@"Found xscreensaver config dir: $(this.config_path)");
|
|
} else if (path_dir_regex.match(line, 0, out info)) {
|
|
this.saver_path = info.fetch(1);
|
|
message(@"Found xscreensaver path dir: $(this.saver_path)");
|
|
}
|
|
}
|
|
} catch (IOError e) {
|
|
error(e.message);
|
|
}
|
|
}
|
|
}
|
|
}
|