basic picking of screensavers. BUG: some don't work because of egl.

This commit is contained in:
Vivianne 2022-03-19 05:43:51 -07:00
parent b39b36d545
commit 2b8624f7f5
8 changed files with 134 additions and 105 deletions

View File

@ -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;
@ -23,10 +23,14 @@ namespace Deskcandy {
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() {

View File

@ -5,6 +5,6 @@ namespace Deskcandy.Candy {
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;
}
}

View File

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

View File

@ -17,20 +17,20 @@ namespace Deskcandy.Candy {
FileInfo info;
message(@"Parsing configs in $(this.config_path)");
while ((info = enumerator.next_file()) != null) {
if (!info.get_name().has_suffix(".xml")) {
var name = info.get_name();
if (!name.has_suffix(".xml")) {
continue;
}
var name = info.get_name();
var config = new XScreensaverConfig(config_dir.resolve_relative_path(info.get_name()));
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.saver_path)/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() {

View File

@ -9,22 +9,24 @@ namespace Deskcandy.Candy {
[Description(nick="::gl")]
public string gl { get; set; }
public string description { get; set; }
public string arg { get; set;}
[Description(nick="::_description")]
public string description { get; set; }
public XScreensaverConfig(File file) throws Error {
public async XScreensaverConfig(File file) throws Error {
this.initialize("screensaver");
this.read_from_file(file);
yield this.read_from_file_async(file);
var tag = this.get_child("command");
this.arg = tag.get_attribute("arg");
debug(@"Loaded $this");
tag = this.get_child("_description");
this.description = tag.text_content.strip();
message(@"Loaded $this");
}
public string to_string() {
return @"Screensaver: $(this.label) [$(this.name) $(this.arg)]";
return @"Screensaver: $(this.label) [$(this.name)]";
}
}
}

View File

@ -27,15 +27,15 @@ namespace Deskcandy {
this.add(this.socket);
try {
this.proc = candy.launch((uint)this.socket.get_id());
this.proc = candy.launch((uint)this.socket.get_id(), "abstractile");
} 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(candy);
}
}
}

View File

@ -214,15 +214,18 @@
</object>
<object class="GtkListStore" id="screensavers_liststore">
<columns>
<!-- column-name name -->
<!-- column-name label -->
<column type="gchararray"/>
<!-- column-name description -->
<column type="gchararray"/>
<!-- column-name name -->
<column type="gchararray"/>
</columns>
<data>
<row>
<col id="0" translatable="yes">Screen Saver 1</col>
<col id="1" translatable="yes">The alpha and the omega</col>
<col id="2" translatable="yes"/>
</row>
</data>
</object>
@ -271,55 +274,59 @@
</packing>
</child>
<child>
<object class="GtkTreeView" id="presets_list">
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="model">presets_liststore</property>
<property name="headers-clickable">False</property>
<property name="fixed-height-mode">True</property>
<property name="activate-on-single-click">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
<property name="shadow-type">in</property>
<child>
<object class="GtkTreeViewColumn">
<property name="sizing">fixed</property>
<property name="fixed-width">30</property>
<object class="GtkTreeView" id="presets_list">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="model">presets_liststore</property>
<property name="headers-clickable">False</property>
<property name="fixed-height-mode">True</property>
<property name="activate-on-single-click">True</property>
<child>
<object class="GtkCellRendererToggle" id="preset_enabled">
<property name="radio">True</property>
<object class="GtkTreeViewColumn">
<property name="sizing">fixed</property>
<property name="fixed-width">30</property>
<child>
<object class="GtkCellRendererToggle" id="preset_enabled">
<property name="radio">True</property>
</object>
<attributes>
<attribute name="active">3</attribute>
</attributes>
</child>
</object>
<attributes>
<attribute name="active">3</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Name</property>
<property name="sort-column-id">0</property>
<child>
<object class="GtkCellRendererText" id="preset_name"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
<object class="GtkTreeViewColumn">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Name</property>
<property name="sort-column-id">0</property>
<child>
<object class="GtkCellRendererText" id="preset_name"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Description</property>
<property name="sort-column-id">1</property>
<child>
<object class="GtkCellRendererText" id="preset_description"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
<object class="GtkTreeViewColumn">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Description</property>
<property name="sort-column-id">1</property>
<child>
<object class="GtkCellRendererText" id="preset_description"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
@ -513,51 +520,43 @@
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<child>
<object class="GtkSearchEntry">
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="primary-icon-name">edit-find-symbolic</property>
<property name="primary-icon-activatable">False</property>
<property name="primary-icon-sensitive">False</property>
<property name="placeholder-text" translatable="yes">Search for screen savers</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkTreeView" id="screensaver_chooser">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="model">screensavers_liststore</property>
<property name="headers-clickable">False</property>
<property name="activate-on-single-click">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
<property name="shadow-type">in</property>
<child>
<object class="GtkTreeViewColumn">
<property name="resizable">True</property>
<property name="title" translatable="yes">Name</property>
<object class="GtkTreeView" id="screensaver_chooser">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="model">screensavers_liststore</property>
<property name="headers-clickable">False</property>
<property name="activate-on-single-click">True</property>
<signal name="row-activated" handler="on_screensaver_chooser_row_activated" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="ss_name"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
<object class="GtkTreeViewColumn">
<property name="resizable">True</property>
<property name="title" translatable="yes">Name</property>
<child>
<object class="GtkCellRendererText" id="ss_name"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="resizable">True</property>
<property name="title" translatable="yes">Description</property>
<child>
<object class="GtkCellRendererText" id="ss_description"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
<object class="GtkTreeViewColumn">
<property name="resizable">True</property>
<property name="title" translatable="yes">Description</property>
<child>
<object class="GtkCellRendererText" id="ss_description">
<property name="single-paragraph-mode">True</property>
</object>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>

View File

@ -15,7 +15,11 @@ namespace Deskcandy {
[GtkChild]
private unowned Gtk.Stack main_stack;
[GtkChild]
private unowned Gtk.ListStore screensavers_liststore;
private Subprocess proc;
private XScreensaver xss;
public Window (Application app) {
Object (application: app);
@ -39,11 +43,21 @@ 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);
@ -56,7 +70,7 @@ namespace Deskcandy {
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 +82,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";
}