Compare commits
4 Commits
d4c219bff6
...
64ba90c802
Author | SHA1 | Date |
---|---|---|
Vivianne | 64ba90c802 | |
Vivianne | 35b69747e8 | |
Vivianne | 2b8624f7f5 | |
Vivianne | b39b36d545 |
|
@ -2,7 +2,7 @@ using Deskcandy.Candy;
|
|||
|
||||
namespace Deskcandy {
|
||||
public class Application : Gtk.Application {
|
||||
public signal void initialized(BaseCandy candy);
|
||||
public signal void initialized(BaseCandy[] candies);
|
||||
|
||||
private Gtk.Window window;
|
||||
private Gtk.Window desktop_window;
|
||||
|
@ -18,15 +18,19 @@ namespace Deskcandy {
|
|||
this.add_action(toggle_enabled);
|
||||
this.set_up_actions();
|
||||
|
||||
this._candies = { new XScreensaver(), new Mpv() };
|
||||
this._candies = { new XScreensaver(), new Video() };
|
||||
}
|
||||
|
||||
private async void initialize_async() {
|
||||
foreach (var candy in this._candies) {
|
||||
yield candy.initialize();
|
||||
try {
|
||||
yield candy.initialize();
|
||||
} catch (Error e) {
|
||||
error(@"Failed to load candy: $(e.message)");
|
||||
}
|
||||
}
|
||||
|
||||
initialized(this._candies[1]);
|
||||
initialized(this._candies);
|
||||
}
|
||||
|
||||
private void on_toggle_enabled() {
|
||||
|
|
|
@ -3,8 +3,8 @@ namespace Deskcandy.Candy {
|
|||
protected BaseCandy() {
|
||||
}
|
||||
|
||||
public abstract async void initialize();
|
||||
public abstract async void initialize() throws Error;
|
||||
|
||||
public abstract Subprocess launch(uint socket_id) throws Error;
|
||||
public abstract Subprocess launch(uint socket_id, string path) throws Error;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
namespace Deskcandy.Candy {
|
||||
class Mpv : BaseCandy {
|
||||
public Mpv() {
|
||||
}
|
||||
|
||||
public override async void initialize() {
|
||||
}
|
||||
|
||||
public override Subprocess launch(uint socket_id) throws Error {
|
||||
message("Launching mpv video...");
|
||||
return new Subprocess(SubprocessFlags.NONE, "mpv", @"--wid=$socket_id", "--no-audio", "--video-unscaled=downscale-big", "--video-zoom=20", "/home/vv/Videos/Sprite_Fright_-_Open_Movie_by_Blender_Studio.webm");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
namespace Deskcandy.Candy {
|
||||
class Video : BaseCandy {
|
||||
public Video() {
|
||||
}
|
||||
|
||||
public override async void initialize() throws Error {
|
||||
}
|
||||
|
||||
public override Subprocess launch(uint socket_id, string path) throws Error {
|
||||
message("Launching mpv video...");
|
||||
return new Subprocess(SubprocessFlags.NONE, "mpv", @"--wid=$socket_id", "--no-audio", "--video-unscaled=downscale-big", "--video-zoom=20", path);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,21 +1,40 @@
|
|||
namespace Deskcandy.Candy {
|
||||
class XScreensaver : BaseCandy {
|
||||
public string config_dir { get; private set; }
|
||||
public string path_dir { get; private set; }
|
||||
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() {
|
||||
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 {
|
||||
public override Subprocess launch(uint socket_id, string saver) throws Error {
|
||||
message("Launching XScreensaver...");
|
||||
return new Subprocess(SubprocessFlags.NONE, @"$(this.path_dir)/abstractile", "-window-id", socket_id.to_string());
|
||||
return new Subprocess(SubprocessFlags.NONE, @"$(this.saver_path)/$saver", "-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;
|
||||
|
@ -49,11 +68,11 @@ namespace Deskcandy.Candy {
|
|||
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)");
|
||||
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.path_dir = info.fetch(1);
|
||||
message(@"Found xscreensaver path dir: $(this.path_dir)");
|
||||
this.saver_path = info.fetch(1);
|
||||
message(@"Found xscreensaver path dir: $(this.saver_path)");
|
||||
}
|
||||
}
|
||||
} catch (IOError e) {
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
namespace Deskcandy.Candy {
|
||||
public class XScreensaverConfig : GXml.Element {
|
||||
[Description(nick="::name")]
|
||||
public string name { get; set; }
|
||||
|
||||
[Description(nick="::_label")]
|
||||
public string label { get; set; }
|
||||
|
||||
[Description(nick="::gl")]
|
||||
public string gl { get; set; }
|
||||
|
||||
public string description { get; set; }
|
||||
public string arg { get; set;}
|
||||
|
||||
public async XScreensaverConfig(File file) throws Error {
|
||||
this.initialize("screensaver");
|
||||
|
||||
yield this.read_from_file_async(file);
|
||||
|
||||
var tag = this.get_child("command");
|
||||
this.arg = tag.get_attribute("arg");
|
||||
|
||||
tag = this.get_child("_description");
|
||||
this.description = tag.text_content.strip();
|
||||
message(@"Loaded $this");
|
||||
}
|
||||
|
||||
public string to_string() {
|
||||
return @"Screensaver: $(this.label) [$(this.name)]";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@
|
|||
<interface>
|
||||
<requires lib="gtk+" version="3.24"/>
|
||||
<template class="DeskcandyDesktopWindow" parent="GtkWindow">
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="resizable">False</property>
|
||||
|
|
|
@ -23,19 +23,21 @@ namespace Deskcandy {
|
|||
}
|
||||
|
||||
this.socket = new Gtk.Socket();
|
||||
this.socket.set_visible(true);
|
||||
this.add(this.socket);
|
||||
this.socket.visible = true;
|
||||
this.visible = true;
|
||||
|
||||
try {
|
||||
this.proc = candy.launch((uint)this.socket.get_id());
|
||||
this.proc = candy.launch((uint)this.socket.get_id(), "unknownpleasures");
|
||||
} catch (Error e) {
|
||||
error(e.message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void on_initialized(BaseCandy candy) {
|
||||
private void on_initialized(BaseCandy[] candies) {
|
||||
this.present();
|
||||
this.refresh_socket(candy);
|
||||
this.refresh_socket(candies[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,13 +5,15 @@ deskcandy_sources = [
|
|||
'application.vala',
|
||||
'candy/base.vala',
|
||||
'candy/xscreensaver.vala',
|
||||
'candy/mpv.vala'
|
||||
'candy/xscreensaver_config.vala',
|
||||
'candy/video.vala'
|
||||
]
|
||||
|
||||
|
||||
deskcandy_deps = [
|
||||
dependency('gio-2.0', version: '>= 2.50'),
|
||||
dependency('gtk+-3.0', version: '>= 3.22'),
|
||||
dependency('gxml-0.20', version: '>= 0.20'),
|
||||
]
|
||||
|
||||
gnome = import('gnome')
|
||||
|
|
1209
src/window.ui
1209
src/window.ui
File diff suppressed because it is too large
Load Diff
|
@ -9,13 +9,17 @@ namespace Deskcandy {
|
|||
[GtkChild]
|
||||
private unowned Gtk.MenuButton open_menu_button;
|
||||
[GtkChild]
|
||||
private unowned Gtk.Box preview;
|
||||
[GtkChild]
|
||||
private unowned Gtk.HeaderBar headerbar;
|
||||
private unowned Gtk.Bin preview;
|
||||
[GtkChild]
|
||||
private unowned Gtk.Stack main_stack;
|
||||
[GtkChild]
|
||||
private unowned Gtk.Label candy_status;
|
||||
|
||||
[GtkChild]
|
||||
private unowned Gtk.ListStore screensavers_liststore;
|
||||
|
||||
private Subprocess proc;
|
||||
private XScreensaver xss;
|
||||
|
||||
public Window (Application app) {
|
||||
Object (application: app);
|
||||
|
@ -39,24 +43,32 @@ namespace Deskcandy {
|
|||
app.notify["enabled"].connect(this.on_notify_enabled);
|
||||
}
|
||||
|
||||
public void on_initialized(BaseCandy candy) {
|
||||
this.refresh_socket(candy);
|
||||
public void on_initialized(BaseCandy[] candies) {
|
||||
foreach (BaseCandy candy in candies) {
|
||||
if (candy is XScreensaver) {
|
||||
this.xss = (XScreensaver)candy;
|
||||
Gtk.TreeIter iter;
|
||||
this.screensavers_liststore.clear();
|
||||
foreach (XScreensaverConfig config in this.xss.configs) {
|
||||
this.screensavers_liststore.append(out iter);
|
||||
this.screensavers_liststore.set(iter, 0, config.label, 1, config.description, 2, config.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void refresh_socket(BaseCandy candy) {
|
||||
private void refresh_socket(BaseCandy candy, string name) {
|
||||
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 {
|
||||
this.proc = candy.launch((uint)this.socket.get_id());
|
||||
this.proc = candy.launch((uint)this.socket.get_id(), name);
|
||||
} catch (Error e) {
|
||||
error(e.message);
|
||||
}
|
||||
|
@ -68,6 +80,16 @@ namespace Deskcandy {
|
|||
this.application.quit();
|
||||
}
|
||||
|
||||
[GtkCallback]
|
||||
private void on_screensaver_chooser_row_activated(Gtk.TreeView treeview, Gtk.TreePath path, Gtk.TreeViewColumn col) {
|
||||
Gtk.TreeIter iter;
|
||||
if (treeview.model.get_iter(out iter, path)) {
|
||||
string name;
|
||||
treeview.model.get(iter, 2, out name);
|
||||
this.refresh_socket(this.xss, name);
|
||||
}
|
||||
}
|
||||
|
||||
private void on_create_preset(SimpleAction a, Variant? v) {
|
||||
this.main_stack.visible_child_name = "editor_page";
|
||||
}
|
||||
|
@ -96,7 +118,7 @@ namespace Deskcandy {
|
|||
|
||||
private void on_notify_enabled(Object o, GLib.ParamSpec param) {
|
||||
var val = ((Application)o).enabled;
|
||||
this.headerbar.subtitle = val ? "started" : "stopped";
|
||||
this.candy_status.label = val ? "Candy started" : "Candy stopped";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue