Fix multiple bindings

Signed-off-by: Vasiliy Doylov <nekocwd@mainlining.org>
This commit is contained in:
Vasiliy Doylov 2025-07-10 06:32:02 +03:00
parent 66bf073f94
commit 00c15ba185
5 changed files with 35 additions and 75 deletions

View file

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<gresources> <gresources>
<gresource prefix="/mobi/phosh/plugins/vala-quick-setting/"> <gresource prefix="/mobi/phosh/plugins/vala-quick-setting/">
<file preprocess="xml-stripblanks">qs.ui</file>
<file preprocess="xml-stripblanks">player.ui</file> <file preprocess="xml-stripblanks">player.ui</file>
<file>style.css</file> <file>style.css</file>
</gresource> </gresource>

View file

@ -4,7 +4,6 @@ blueprints = custom_target(
'blueprints', 'blueprints',
input: files( input: files(
'player.blp', 'player.blp',
'qs.blp',
), ),
output: '.', output: '.',
command: [ command: [

View file

@ -21,6 +21,7 @@ public class Extension.Player : Gtk.Box {
get_style_context ().add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER); get_style_context ().add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER);
get_style_context ().add_class (id); get_style_context ().add_class (id);
} }
~Player () { ~Player () {
Gtk.StyleContext.remove_provider_for_screen (Gdk.Screen.get_default (), css_provider); Gtk.StyleContext.remove_provider_for_screen (Gdk.Screen.get_default (), css_provider);
} }
@ -36,7 +37,11 @@ public class Extension.Player : Gtk.Box {
} }
var data = ".%s { background: radial-gradient(circle at left, %s); }" var data = ".%s { background: radial-gradient(circle at left, %s); }"
.printf (id, string.joinv (",", gradient_points)); .printf (id, string.joinv (",", gradient_points));
css_provider.load_from_data (data); try {
css_provider.load_from_data (data);
} catch (Error err) {
warning ("Something wrong with CSS generation: %s", err.message);
}
} }
private Gdk.RGBA max_color (ref Gee.HashMap<Gdk.RGBA?, int> histogram) { private Gdk.RGBA max_color (ref Gee.HashMap<Gdk.RGBA?, int> histogram) {
@ -102,7 +107,12 @@ public class Extension.Player : Gtk.Box {
pixbuff = (Gdk.Pixbuf) icon; pixbuff = (Gdk.Pixbuf) icon;
else if (icon is FileIcon) { else if (icon is FileIcon) {
var fi = (LoadableIcon) icon; var fi = (LoadableIcon) icon;
pixbuff = new Gdk.Pixbuf.from_stream (fi.load (1024, null, null)); try {
pixbuff = new Gdk.Pixbuf.from_stream (fi.load (1024, null, null));
} catch (Error err) {
warning ("Icon load failed %s", err.message);
return null;
}
} else { } else {
return icon; return icon;
} }

View file

@ -1,44 +0,0 @@
using Gtk 3.0; // This requires blueprint-compiller changes
using Phosh 0;
template $ExtensionQuickSetting: Phosh.QuickSetting {
status-icon: info;
status-page: status_page;
clicked => $on_clicked();
}
Phosh.StatusIcon info {
visible: true;
}
Phosh.StatusPage status_page {
visible: true;
title: _("Quick Setting Example");
content: content;
footer: footer;
}
// Idk why there are no that placeholder in typelib
$PhoshStatusPagePlaceholder content{
visible: true;
icon-name: "face-angel-symbolic";
extra-widget: label;
}
Label label{
visible: true;
label: _("Im' written in Vala!");
}
Button footer {
visible: true;
hexpand: true;
clicked => $on_footer_clicked();
Label {
visible: true;
ellipsize: end;
label: _("Open Plugin Settings");
}
}

View file

@ -10,34 +10,15 @@ using Phosh;
using GLib; using GLib;
[GtkTemplate (ui = "/mobi/phosh/plugins/vala-quick-setting/qs.ui")]
public class Extension.QuickSetting : Phosh.QuickSetting { public class Extension.QuickSetting : Phosh.QuickSetting {
[GtkChild] private Player player = new Player ();
private unowned StatusIcon info; private Gtk.Widget? hiden_player = null;
[GtkCallback]
private void on_clicked (Phosh.QuickSetting qs) {
bool active = get_active ();
if (active) {
info.set_icon_name ("face-shutmouth-symbolic");
info.set_info ("I'm Inactive");
} else {
info.set_icon_name ("face-smile-big-symbolic");
info.set_info ("I'm Active");
}
set_active (!active);
}
[GtkCallback]
private void on_footer_clicked (Gtk.Button btn) {
}
construct { construct {
info.set_icon_name ("face-shutmouth-symbolic");
info.set_info ("I'm Inactive");
parent_set.connect (() => replace_player (Stage.QickSettings_Box)); parent_set.connect (() => replace_player (Stage.QickSettings_Box));
visible = false;
} }
enum Stage { enum Stage {
QickSettings_Box = 0, QickSettings_Box = 0,
QickSettings, QickSettings,
@ -47,12 +28,16 @@ public class Extension.QuickSetting : Phosh.QuickSetting {
return ((EnumClass) typeof (Stage).class_ref ()).get_value (this).value_nick.up (); return ((EnumClass) typeof (Stage).class_ref ()).get_value (this).value_nick.up ();
} }
} }
void replace_player (Stage stage) { void replace_player (Stage stage) {
message ("Replace player: Stage %d %s", stage, stage.to_string ());
if (parent == null) { if (parent == null) {
message ("Parent is null"); if (stage == Stage.QickSettings_Box)
clean_up ();
return; return;
} }
if (hiden_player != null)
return;
message ("Replace player: Stage %d %s", stage, stage.to_string ());
if (stage != Stage.BoxSettings) { if (stage != Stage.BoxSettings) {
var _p = parent; var _p = parent;
for (uint i = 0; i < stage; i++) for (uint i = 0; i < stage; i++)
@ -69,6 +54,9 @@ public class Extension.QuickSetting : Phosh.QuickSetting {
} }
void on_something_added (Gtk.Widget widget) { void on_something_added (Gtk.Widget widget) {
if (hiden_player != null)
return;
if (widget.get_type ().is_a (typeof (Gtk.Container))) { if (widget.get_type ().is_a (typeof (Gtk.Container))) {
((Gtk.Container) widget).add.connect ((w) => on_something_added (w)); ((Gtk.Container) widget).add.connect ((w) => on_something_added (w));
} }
@ -78,16 +66,17 @@ public class Extension.QuickSetting : Phosh.QuickSetting {
} }
void find_player (Gtk.Container container) { void find_player (Gtk.Container container) {
if (hiden_player != null)
return;
var i = 0; var i = 0;
foreach (var child in container.get_children ()) { foreach (var child in container.get_children ()) {
if (child.name == "PhoshDefaultMediaPlayer") { if (child.name == "PhoshDefaultMediaPlayer") {
message ("Player found"); message ("Player found");
var player = new Player ();
player.bind_to_player ((Gtk.Box) child); player.bind_to_player ((Gtk.Box) child);
container.add (player); container.add (player);
var b = (Gtk.Box) container; var b = (Gtk.Box) container;
b.reorder_child (player, i); b.reorder_child (player, i);
// container.remove (child); hiden_player = child;
} }
if (child.get_type ().is_a (typeof (Gtk.Container))) { if (child.get_type ().is_a (typeof (Gtk.Container))) {
find_player ((Gtk.Container) child); find_player ((Gtk.Container) child);
@ -95,4 +84,11 @@ public class Extension.QuickSetting : Phosh.QuickSetting {
i++; i++;
} }
} }
void clean_up () {
player.dispose ();
if (player.parent != null)
player.parent.remove (player);
hiden_player = null;
}
} }