allow setting videos/screensaver based on tab

This commit is contained in:
Vivianne 2022-03-23 00:29:22 -07:00
parent 568db5e8dd
commit 708caa431f
6 changed files with 59 additions and 20 deletions

View file

@ -1,10 +1,12 @@
namespace Deskcandy.Candy {
public abstract class BaseCandy : Object {
public string name { get; set; }
protected BaseCandy() {
}
public abstract async void initialize() throws Error;
public abstract Subprocess launch(uint socket_id, string path) throws Error;
public abstract Subprocess launch(uint socket_id) throws Error;
}
}

View file

@ -6,9 +6,9 @@ namespace Deskcandy.Candy {
public override async void initialize() throws Error {
}
public override Subprocess launch(uint socket_id, string path) throws Error {
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", path);
return new Subprocess(SubprocessFlags.NONE, "mpv", @"--wid=$socket_id", "--no-audio", "--video-unscaled=downscale-big", "--video-zoom=20", this.name);
}
}
}

View file

@ -28,9 +28,9 @@ namespace Deskcandy.Candy {
message(@"Found $(this.configs.length()) screensavers.");
}
public override Subprocess launch(uint socket_id, string saver) throws Error {
public override Subprocess launch(uint socket_id) throws Error {
message("Launching XScreensaver...");
return new Subprocess(SubprocessFlags.NONE, @"$(this.saver_path)/$saver", "-window-id", socket_id.to_string());
return new Subprocess(SubprocessFlags.NONE, @"$(this.saver_path)/$(this.name)", "-window-id", socket_id.to_string());
}
private async void hacky_determine_directories() {

View file

@ -28,7 +28,7 @@ namespace Deskcandy {
this.visible = true;
try {
this.proc = candy.launch((uint)this.socket.get_id(), "unknownpleasures");
//this.proc = candy.launch((uint)this.socket.get_id());
} catch (Error e) {
error(e.message);
}

View file

@ -314,7 +314,8 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-end">5</property>
<property name="transition-type">slide-left-right</property>
<property name="transition-type">over-up-down</property>
<signal name="notify::visible-child-name" handler="on_main_stack_visible_child_name_notify" swapped="no"/>
<child>
<object class="GtkBox" id="presets_page">
<property name="visible">True</property>
@ -579,6 +580,7 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="transition-type">slide-left-right</property>
<signal name="notify::visible-child-name" handler="on_preset_type_stack_visible_child_name_notify" swapped="no"/>
<child>
<object class="GtkBox">
<property name="visible">True</property>
@ -649,6 +651,7 @@
<property name="valign">start</property>
<property name="filter">video_file_filter</property>
<property name="title" translatable="yes">Select Video</property>
<signal name="file-set" handler="on_video_chooser_file_set" swapped="no"/>
</object>
<packing>
<property name="name">video_page</property>

View file

@ -13,12 +13,18 @@ namespace Deskcandy {
[GtkChild]
private unowned Gtk.Stack main_stack;
[GtkChild]
private unowned Gtk.Stack preset_type_stack;
[GtkChild]
private unowned Gtk.Label candy_status;
[GtkChild]
private unowned Gtk.ListStore screensavers_liststore;
[GtkChild]
private unowned Gtk.FileChooserButton video_chooser;
private BaseCandy active_candy;
private Subprocess proc;
private XScreensaver xss;
private Video video;
public Window (Application app) {
Object (application: app);
@ -43,20 +49,19 @@ namespace Deskcandy {
}
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);
}
}
this.xss = (XScreensaver)candies[0];
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);
}
this.video = (Video)candies[1];
this.active_candy = this.xss;
}
private void refresh_socket(BaseCandy candy, string name) {
private void refresh_socket() {
if (this.socket != null) {
this.preview.remove(this.socket);
this.proc.send_signal(15);
@ -67,7 +72,7 @@ namespace Deskcandy {
this.preview.add(this.socket);
try {
this.proc = candy.launch((uint)this.socket.get_id(), name);
this.proc = this.active_candy.launch((uint)this.socket.get_id());
} catch (Error e) {
error(e.message);
}
@ -85,10 +90,17 @@ namespace Deskcandy {
if (treeview.model.get_iter(out iter, path)) {
string name;
treeview.model.get(iter, 2, out name);
this.refresh_socket(this.xss, name);
this.xss.name = name;
this.refresh_socket();
}
}
[GtkCallback]
private void on_video_chooser_file_set() {
this.video.name = this.video_chooser.get_filename();
this.refresh_socket();
}
private void on_create_preset(SimpleAction a, Variant? v) {
this.main_stack.visible_child_name = "editor_page";
}
@ -111,6 +123,28 @@ namespace Deskcandy {
popover.popdown();
}
[GtkCallback]
private void on_main_stack_visible_child_name_notify(Object o, ParamSpec param) {
message(@"page: $(this.main_stack.visible_child_name)");
}
[GtkCallback]
private void on_preset_type_stack_visible_child_name_notify(Object o, ParamSpec param) {
message(@"preset type: $(this.preset_type_stack.visible_child_name)");
switch (this.preset_type_stack.visible_child_name) {
case "video_page":
this.active_candy = this.video;
break;
case "screensaver_page":
this.active_candy = this.xss;
break;
}
if (this.active_candy.name != null && this.active_candy.name != "") {
this.refresh_socket();
}
}
private void on_delete_preset(SimpleAction a, Variant? v) {
message("delete");
}