From d15c1a4e14425f463f017abc3e2124b6e9f6718a Mon Sep 17 00:00:00 2001 From: Vasiliy Doylov Date: Wed, 9 Jul 2025 19:46:30 +0300 Subject: [PATCH] Add AutoFocus trigger Signed-off-by: Vasiliy Doylov --- src/application.vala | 2 +- src/gui/slider_overlay.blp | 82 +++++++++++++++++++++---------------- src/gui/slider_overlay.vala | 29 ++++++++----- src/logic/wireplumber.vala | 16 +++++++- 4 files changed, 82 insertions(+), 47 deletions(-) diff --git a/src/application.vala b/src/application.vala index a083bd5..e1b0645 100644 --- a/src/application.vala +++ b/src/application.vala @@ -64,7 +64,7 @@ public class PipeTap.Application : Adw.Application { if (exposure == null) exposure = new Ui.SliderOverlay (this, Logic.Ctrl.CtrlType.Exposure, Logic.Ctrl.CtrlType.ExposureEnable, "exp", "camera-iso-symbolic"); if (focus == null) - focus = new Ui.SliderOverlay (this, Logic.Ctrl.CtrlType.Focus, Logic.Ctrl.CtrlType.AutoFocusEnable, "focus", "camera-focus-symbolic"); + focus = new Ui.SliderOverlay (this, Logic.Ctrl.CtrlType.Focus, Logic.Ctrl.CtrlType.AutoFocusEnable, "focus", "camera-focus-symbolic", false); if (contrast == null) contrast = new Ui.SliderOverlay (this, Logic.Ctrl.CtrlType.Contrast, Logic.Ctrl.CtrlType.ContrastEnable, "contrast", "color-symbolic"); if (main_bar == null) diff --git a/src/gui/slider_overlay.blp b/src/gui/slider_overlay.blp index a9f8889..949e5fa 100644 --- a/src/gui/slider_overlay.blp +++ b/src/gui/slider_overlay.blp @@ -1,46 +1,58 @@ using Gtk 4.0; -using Adw 1; template $PipeTapUiSliderOverlay: $PipeTapUiFloatingWindow { - title: _("PipeTap Slider"); + title: _("PipeTap Slider"); - content: Gtk.Box content_box { - orientation: bind template.orientation; - halign: fill; - spacing: 10; + content: Gtk.Box content_box { + orientation: bind template.orientation; + halign: fill; + spacing: 10; - Separator spacer { - styles [ - "spacer", - ] - } + Separator spacer { + styles [ + "spacer", + ] + } - Scale scale { - orientation: bind template.orientation; - vexpand: true; - hexpand: true; - halign: fill; - valign: fill; + Scale scale { + orientation: bind template.orientation; + vexpand: true; + hexpand: true; + halign: fill; + valign: fill; - adjustment: Adjustment { - lower: 0; - upper: 1000; - step-increment: 1; - value: 500; - }; + adjustment: Adjustment { + lower: 0; + upper: 1000; + step-increment: 1; + value: 500; + }; - styles [ - "pt-slider", - ] - } + styles [ + "pt-slider", + ] + } - Gtk.ToggleButton lock_btn { - icon-name: "camera-iso-symbolic"; - tooltip-text: _("Lock"); + Gtk.ToggleButton toggle_btn { + icon-name: bind template.icon; + tooltip-text: _("Lock"); + visible: bind template.is_toggle; + sensitive: bind template.is_btn_available; - styles [ - "flat", - ] - } - }; + styles [ + "flat", + ] + } + + Gtk.ToggleButton press_btn { + icon-name: bind template.icon; + tooltip-text: _("Start"); + visible: bind template.is_toggle inverted; + sensitive: bind template.is_btn_available; + + styles [ + "flat", + ] + } + }; } diff --git a/src/gui/slider_overlay.vala b/src/gui/slider_overlay.vala index 5eb2745..ad29142 100644 --- a/src/gui/slider_overlay.vala +++ b/src/gui/slider_overlay.vala @@ -3,21 +3,27 @@ public class PipeTap.Ui.SliderOverlay : PipeTap.Ui.FloatingWindow { [GtkChild] private unowned Gtk.Scale scale; [GtkChild] - private unowned Gtk.ToggleButton lock_btn; - + private unowned Gtk.ToggleButton toggle_btn; + [GtkChild] + private unowned Gtk.Button press_btn; public Logic.Ctrl.CtrlType slider_type { get; set; } public Logic.Ctrl.CtrlType? toggle_type { get; set; } public bool is_available { get; protected set; } + public bool is_toggle { get; protected set; } + public string icon { get; set; } + public bool is_btn_available { get; protected set; } - public SliderOverlay(PipeTap.Application app, Logic.Ctrl.CtrlType slider_type, Logic.Ctrl.CtrlType toggle_type, string name, string icon_name) { + public SliderOverlay(PipeTap.Application app, Logic.Ctrl.CtrlType slider_type, Logic.Ctrl.CtrlType toggle_type, string name, string icon_name, bool is_toggle = true) { base(app, name); this.slider_type = slider_type; this.toggle_type = toggle_type; + this.is_toggle = is_toggle; scale.value_changed.connect(value_changed); - lock_btn.toggled.connect(lock_changed); + toggle_btn.toggled.connect(lock_changed); + press_btn.clicked.connect(lock_changed); app.notify["device"].connect(set_ctrls); - lock_btn.icon_name = icon_name; + this.icon = icon_name; set_ctrls(); } @@ -25,12 +31,12 @@ public class PipeTap.Ui.SliderOverlay : PipeTap.Ui.FloatingWindow { var slider_ctrl = Logic.find_ctrl(slider_type); var lock_ctrl = Logic.find_ctrl(toggle_type); scale.sensitive = slider_ctrl != null; - lock_btn.sensitive = lock_ctrl != null; + is_btn_available = lock_ctrl != null; is_available = slider_ctrl != null || lock_ctrl != null; if (slider_ctrl != null) scale.set_value(slider_ctrl.value); if (lock_ctrl != null) - lock_btn.active = lock_ctrl.value == 1; + toggle_btn.active = lock_ctrl.value == 1; } void value_changed() { @@ -44,12 +50,15 @@ public class PipeTap.Ui.SliderOverlay : PipeTap.Ui.FloatingWindow { } void lock_changed() { - message("Lock %s", lock_btn.active ? "on" : "off"); var ctrl = Logic.find_ctrl(toggle_type); if (ctrl == null) { message("Toggle ctrl not found"); return; } - ctrl.value = (int) lock_btn.active; + if (!is_toggle) { + ctrl.value = 1; + return; + } + ctrl.value = (int) toggle_btn.active; } -} \ No newline at end of file +} diff --git a/src/logic/wireplumber.vala b/src/logic/wireplumber.vala index 7967a0e..2b235d5 100644 --- a/src/logic/wireplumber.vala +++ b/src/logic/wireplumber.vala @@ -36,6 +36,11 @@ namespace PipeTap.Logic.WirePlumber { message("Sending bool %s", adjusted ? "true" : "false"); pb.add_boolean(adjusted); break; + case "int": + var adjusted = value; + message("Sending int %f", (int) adjusted); + pb.add_int((int) adjusted); + break; default: message("Unknown type %s", wp_type); break; @@ -154,6 +159,15 @@ namespace PipeTap.Logic.WirePlumber { var ctrl = new Ctrl(Logic.Ctrl.CtrlType.Contrast, node, id, type, 0, 2, 1); found_ctrls.append(ctrl); break; + case "AfTrigger": + if (type != "int") { + warning("Wrong type"); + break; + } + message("Found AF Trigger"); + var ctrl = new Ctrl(Logic.Ctrl.CtrlType.AutoFocusEnable, node, id, type, 0, 1, 0); + found_ctrls.append(ctrl); + break; default: message("Unknown ctrl %s of %s", description, type); break; @@ -177,4 +191,4 @@ namespace PipeTap.Logic.WirePlumber { core = new Wp.Core(null, null, null); core.activate.begin(Wp.CoreFeatures.CONNECTED, null, init_manager); } -} \ No newline at end of file +}