UI: remove window dragging functionality and add manual settings

Signed-off-by: Vasiliy Doylov <nekocwd@mainlining.org>
This commit is contained in:
Vasiliy Doylov 2025-03-18 00:35:39 +03:00
parent c698966a03
commit 149689d7ca
Signed by: NekoCWD
GPG key ID: B7BE22D44474A582
7 changed files with 110 additions and 124 deletions

View file

@ -1,25 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="pipetap">
<schema id="io.gitlab.nekocwd.pipetap.adjustments">
<key name='start-x' type='d'>
<key name='orientation' type='i'>
<default>0</default>
</key>
<key name='start-y' type='d'>
<default>0</default>
<key name='margin-right' type='i'>
<default>-1</default>
</key>
<key name='end-x' type='d'>
<default>0</default>
<key name='margin-left' type='i'>
<default>10</default>
</key>
<key name='end-y' type='d'>
<default>0</default>
<key name='margin-top' type='i'>
<default>80</default>
</key>
<key name='orientation' type='b'>
<default>false</default>
<key name='margin-bottom' type='i'>
<default>110</default>
</key>
</schema>
<schema id="io.gitlab.nekocwd.pipetap" path="/io/gitlab/nekocwd/pipetap/">
<child name="main-controls-pos" schema="io.gitlab.nekocwd.pipetap.adjustments"></child>
<child name="exp-pos" schema="io.gitlab.nekocwd.pipetap.adjustments"></child>
<child name="focus-pos" schema="io.gitlab.nekocwd.pipetap.adjustments"></child>
<key name='is-uninitialised' type='b'>
<default>true</default>
</key>
</schema>
</schemalist>

View file

@ -20,7 +20,6 @@
public class PipeTap.Application : Adw.Application {
public Settings settings;
public bool adjust_overlay_visible { get; set; }
public Ui.SliderOverlay exposure;
public Ui.SliderOverlay focus;
public Ui.MainBar main_bar;
@ -38,11 +37,12 @@ public class PipeTap.Application : Adw.Application {
{ "about", this.on_about_action },
{ "preferences", this.on_preferences_action },
{ "quit", this.quit },
{ "adjust-overlays", () => { adjust_overlay_visible = !adjust_overlay_visible; } }
};
this.add_action_entries (action_entries, this);
this.set_accels_for_action ("app.quit", { "<primary>q" });
settings = new Settings ("io.gitlab.nekocwd.pipetap");
if (settings.get_boolean ("is-uninitialised"))
reset_settings ();
}
public override void activate () {
@ -84,6 +84,32 @@ public class PipeTap.Application : Adw.Application {
}
private void on_preferences_action () {
message ("app.preferences action activated");
new Ui.Settings ().present (null);
}
public void reset_settings () {
settings.set_boolean ("is-uninitialised", false);
var settings = this.settings.get_child ("main-controls-pos");
settings.set_int ("orientation", 1);
settings.set_int ("margin-right", 80);
settings.set_int ("margin-left", 80);
settings.set_int ("margin-top", 65);
settings.set_int ("margin-bottom", -1);
settings.apply ();
settings = this.settings.get_child ("exp-pos");
settings.set_int ("orientation", 0);
settings.set_int ("margin-right", -1);
settings.set_int ("margin-left", 10);
settings.set_int ("margin-top", 65);
settings.set_int ("margin-bottom", 110);
settings.apply ();
settings = this.settings.get_child ("focus-pos");
settings.set_int ("orientation", 0);
settings.set_int ("margin-right", 10);
settings.set_int ("margin-left", -1);
settings.set_int ("margin-top", 65);
settings.set_int ("margin-bottom", 110);
settings.apply ();
this.settings.apply ();
}
}

View file

@ -14,18 +14,18 @@ template $PipeTapUiMainBar: $PipeTapUiFloatingWindow {
"linked",
]
Gtk.ToggleButton exposure {
icon-name: "camera-iso-symbolic";
tooltip-text: _("Exposure");
Gtk.ToggleButton focus {
icon-name: "camera-focus-symbolic";
tooltip-text: _("Focus");
styles [
"flat",
]
}
Gtk.ToggleButton focus {
icon-name: "camera-focus-symbolic";
tooltip-text: _("Focus");
Gtk.ToggleButton exposure {
icon-name: "camera-iso-symbolic";
tooltip-text: _("Exposure");
styles [
"flat",
@ -47,11 +47,6 @@ template $PipeTapUiMainBar: $PipeTapUiFloatingWindow {
menu primary_menu {
section {
item {
label: _("_Adjust overlays");
action: "app.adjust-overlays";
}
item {
label: _("_Preferences");
action: "app.preferences";

44
src/gui/settings.vala Normal file
View file

@ -0,0 +1,44 @@
public class PipeTap.Ui.Settings : Adw.PreferencesDialog {
public Settings() {
var overlays = new Adw.PreferencesPage();
overlays.title = _("Overlays");
overlays.add(make_group_for("Main bar", "main-controls-pos"));
overlays.add(make_group_for("Exposure bar", "exp-pos"));
overlays.add(make_group_for("Focus bar", "focus-pos"));
add(overlays);
}
Adw.PreferencesGroup make_group_for(string name, string child_name) {
var group = new Adw.PreferencesGroup();
group.title = _(name);
group.description = _("Set -1 to not anchor to side");
var orientation = new Adw.ComboRow();
orientation.title = _("Orientation");
orientation.model = new Gtk.StringList({ _("Vertical"), _("Horizontal") });
var top = new Adw.SpinRow.with_range(-1, double.MAX, 1);
top.title = _("Top spacing");
var bottom = new Adw.SpinRow.with_range(-1, double.MAX, 1);
bottom.title = _("Bottom spacing");
var right = new Adw.SpinRow.with_range(-1, double.MAX, 1);
right.title = _("Right spacing");
var left = new Adw.SpinRow.with_range(-1, double.MAX, 1);
left.title = _("Left spacing");
group.add(orientation);
group.add(top);
group.add(bottom);
group.add(left);
group.add(right);
var settings = Logic.app.settings.get_child(child_name);
settings.bind("margin-top", top, "value", SettingsBindFlags.DEFAULT);
settings.bind("margin-bottom", bottom, "value", SettingsBindFlags.DEFAULT);
settings.bind("margin-right", right, "value", SettingsBindFlags.DEFAULT);
settings.bind("margin-left", left, "value", SettingsBindFlags.DEFAULT);
settings.bind("orientation", orientation, "selected", SettingsBindFlags.DEFAULT);
return group;
}
}

View file

@ -11,40 +11,10 @@ template $PipeTapUiFloatingWindow: Gtk.Window {
"osd",
]
Box {
orientation: bind template.orientation;
Button resize {
visible: bind template.resize-visible;
styles [
"flat",
]
}
Adw.Bin content_bin {
valign: fill;
halign: fill;
hexpand: true;
vexpand: true;
}
Button rotate {
visible: bind template.rotate-visible;
icon-name: "angled-arrows-symbolic";
styles [
"flat",
]
}
Button move {
visible: bind template.move-visible;
icon-name: "move-tool-symbolic";
styles [
"flat",
]
}
}
}

View file

@ -25,27 +25,13 @@
[GtkTemplate (ui = "/io/gitlab/nekocwd/pipetap/gui/window.ui")]
public class PipeTap.Ui.FloatingWindow : Gtk.Window, Gtk.Orientable {
[GtkChild]
private unowned Gtk.Button move;
[GtkChild]
private unowned Gtk.Button resize;
[GtkChild]
private unowned Gtk.Button rotate;
[GtkChild]
private unowned Adw.Bin content_bin;
public Gtk.Orientation orientation { get; set; default = Gtk.Orientation.HORIZONTAL; }
public bool resize_visible { get; set; }
public bool rotate_visible { get; set; }
public bool move_visible { get; set; }
public string window_name { get; set; default = ""; }
protected double pos_sy { get; set; }
protected double pos_sx { get; set; }
protected double pos_ex { get; set; }
protected double pos_ey { get; set; }
public Gtk.Widget content { get { return content_bin.get_child (); } set { content_bin.set_child (value); } }
@ -54,69 +40,30 @@ public class PipeTap.Ui.FloatingWindow : Gtk.Window, Gtk.Orientable {
_window_name = name;
GtkLayerShell.init_for_window (this);
var move_controller = new Gtk.GestureDrag ();
move_controller.drag_update.connect ((ox, oy) => {
pos_sy += (int) oy;
pos_sx -= (int) ox;
});
move_controller.end.connect (move_controller.reset);
move.add_controller (move_controller);
var resize_controller = new Gtk.GestureDrag ();
resize_controller.drag_update.connect ((ox, oy) => {
pos_ex += (int) ox;
pos_ey += (int) oy;
});
resize_controller.end.connect (resize_controller.reset);
resize.add_controller (resize_controller);
bind_property ("orientation", resize, "icon_name", GLib.BindingFlags.SYNC_CREATE, (binding, src, ref dst) => {
dst.set_string (orientation == Gtk.Orientation.VERTICAL ? "double-ended-arrows-vertical-symbolic" : "double-ended-arrows-horizontal-symbolic");
return true;
});
rotate.clicked.connect (() => {
orientation = orientation == Gtk.Orientation.HORIZONTAL ? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL;
});
var positions = ((PipeTap.Application) app).settings.get_child (window_name + "-pos");
positions.bind_with_mapping ("orientation", this, "orientation", GLib.SettingsBindFlags.DEFAULT,
(value, variant) =>
{ value = variant.get_boolean () ? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL; return true; },
{ message ("%s", variant.get_type_string ()); value = variant.get_int32 () == 0 ? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL; return true; },
(value) =>
{ return ((Gtk.Orientation) value) == Gtk.Orientation.VERTICAL; },
{ return ((Gtk.Orientation) value) == Gtk.Orientation.VERTICAL ? 1 : 0; },
null, null
);
positions.bind ("start-x", this, "pos-sx", GLib.SettingsBindFlags.DEFAULT);
positions.bind ("start-y", this, "pos-sy", GLib.SettingsBindFlags.DEFAULT);
positions.bind ("end-x", this, "pos-ex", GLib.SettingsBindFlags.DEFAULT);
positions.bind ("end-y", this, "pos-ey", GLib.SettingsBindFlags.DEFAULT);
notify["pos-sx"].connect (set_position);
notify["pos-sy"].connect (set_position);
notify["pos-ex"].connect (set_position);
notify["pos-ey"].connect (set_position);
notify["orientation"].connect (set_position);
positions.changed.connect (set_position);
set_position ();
app.bind_property ("adjust-overlay-visible", this, "move-visible", GLib.BindingFlags.SYNC_CREATE);
app.bind_property ("adjust-overlay-visible", this, "resize-visible", GLib.BindingFlags.SYNC_CREATE);
app.bind_property ("adjust-overlay-visible", this, "rotate-visible", GLib.BindingFlags.SYNC_CREATE);
}
void set_position () {
var vertical = orientation == Gtk.Orientation.VERTICAL;
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.TOP, true);
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.BOTTOM, vertical);
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.RIGHT, true);
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.LEFT, !vertical);
var y = pos_sy;
if (vertical)
y = pos_ey + pos_sy;
var settings = Logic.app.settings.get_child (window_name + "-pos");
GtkLayerShell.set_margin (this, GtkLayerShell.Edge.TOP, int.max ((int) y, 0));
GtkLayerShell.set_margin (this, GtkLayerShell.Edge.RIGHT, int.max ((int) pos_sx, 0));
GtkLayerShell.set_margin (this, GtkLayerShell.Edge.LEFT, int.max ((int) (pos_ex - pos_sx), 0));
GtkLayerShell.set_margin (this, GtkLayerShell.Edge.BOTTOM, int.max ((int) (-pos_sy), 0));
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.TOP, settings.get_int ("margin-top") != -1);
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.BOTTOM, settings.get_int ("margin-bottom") != -1);
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.LEFT, settings.get_int ("margin-left") != -1);
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.RIGHT, settings.get_int ("margin-right") != -1);
GtkLayerShell.set_margin (this, GtkLayerShell.Edge.TOP, settings.get_int ("margin-top"));
GtkLayerShell.set_margin (this, GtkLayerShell.Edge.BOTTOM, settings.get_int ("margin-bottom"));
GtkLayerShell.set_margin (this, GtkLayerShell.Edge.LEFT, settings.get_int ("margin-left"));
GtkLayerShell.set_margin (this, GtkLayerShell.Edge.RIGHT, settings.get_int ("margin-right"));
}
}

View file

@ -4,6 +4,7 @@ pipetap_sources = [
'gui/window.vala',
'gui/main_bar.vala',
'gui/slider_overlay.vala',
'gui/settings.vala',
'logic/ctrl.vala',
'logic/wireplumber.vala',
]