summaryrefslogtreecommitdiff
path: root/lib/astal/gtk4
diff options
context:
space:
mode:
Diffstat (limited to 'lib/astal/gtk4')
-rw-r--r--lib/astal/gtk4/src/application.vala11
-rw-r--r--lib/astal/gtk4/src/meson.build2
-rw-r--r--lib/astal/gtk4/src/widget/box.vala50
-rw-r--r--lib/astal/gtk4/src/widget/slider.vala65
4 files changed, 121 insertions, 7 deletions
diff --git a/lib/astal/gtk4/src/application.vala b/lib/astal/gtk4/src/application.vala
index fadf705..fe5dd8d 100644
--- a/lib/astal/gtk4/src/application.vala
+++ b/lib/astal/gtk4/src/application.vala
@@ -146,13 +146,10 @@ public class Astal.Application : Gtk.Application, AstalIO.Application {
if (reset)
reset_css();
- try {
- if (FileUtils.test(style, FileTest.EXISTS))
- provider.load_from_path(style);
- else
- provider.load_from_string(style);
- } catch (Error err) {
- critical(err.message);
+ if (FileUtils.test(style, FileTest.EXISTS)) {
+ provider.load_from_path(style);
+ } else {
+ provider.load_from_string(style);
}
Gtk.StyleContext.add_provider_for_display(
diff --git a/lib/astal/gtk4/src/meson.build b/lib/astal/gtk4/src/meson.build
index 8aac969..7b9c1e0 100644
--- a/lib/astal/gtk4/src/meson.build
+++ b/lib/astal/gtk4/src/meson.build
@@ -25,6 +25,8 @@ deps = [
]
sources = [config] + files(
+ 'widget/box.vala',
+ 'widget/slider.vala',
'widget/window.vala',
'application.vala',
)
diff --git a/lib/astal/gtk4/src/widget/box.vala b/lib/astal/gtk4/src/widget/box.vala
new file mode 100644
index 0000000..28f2b00
--- /dev/null
+++ b/lib/astal/gtk4/src/widget/box.vala
@@ -0,0 +1,50 @@
+public class Astal.Box : Gtk.Box {
+ /**
+ * Corresponds to [[email protected] :orientation].
+ */
+ [CCode (notify = false)]
+ public bool vertical {
+ get { return orientation == Gtk.Orientation.VERTICAL; }
+ set { orientation = value ? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL; }
+ }
+
+ construct {
+ notify["orientation"].connect(() => {
+ notify_property("vertical");
+ });
+ }
+
+ public List<weak Gtk.Widget> children {
+ set {
+ foreach (var child in children) {
+ remove(child);
+ }
+ foreach (var child in value) {
+ append(child);
+ }
+ }
+ owned get {
+ var list = new List<weak Gtk.Widget>();
+ var child = get_first_child();
+ while (child != null) {
+ list.append(child);
+ child = child.get_next_sibling();
+ }
+ return list;
+ }
+ }
+
+ public Gtk.Widget? child {
+ owned get {
+ foreach (var child in children) {
+ return child;
+ }
+ return null;
+ }
+ set {
+ var list = new List<weak Gtk.Widget>();
+ list.append(child);
+ this.children = children;
+ }
+ }
+}
diff --git a/lib/astal/gtk4/src/widget/slider.vala b/lib/astal/gtk4/src/widget/slider.vala
new file mode 100644
index 0000000..ca026a2
--- /dev/null
+++ b/lib/astal/gtk4/src/widget/slider.vala
@@ -0,0 +1,65 @@
+public class Astal.Slider : Gtk.Scale {
+ private Gtk.EventControllerLegacy controller;
+ private bool dragging;
+
+ construct {
+ if (adjustment == null)
+ adjustment = new Gtk.Adjustment(0,0,0,0,0,0);
+
+ if (max == 0 && min == 0) {
+ max = 1;
+ }
+
+ if (step == 0) {
+ step = 0.05;
+ }
+
+ controller = new Gtk.EventControllerLegacy();
+ add_controller(controller);
+ controller.event.connect((event) => {
+ var type = event.get_event_type();
+ if (type == Gdk.EventType.BUTTON_PRESS ||
+ type == Gdk.EventType.KEY_PRESS ||
+ type == Gdk.EventType.TOUCH_BEGIN) {
+ dragging = true;
+ }
+ if (type == Gdk.EventType.BUTTON_RELEASE ||
+ type == Gdk.EventType.KEY_RELEASE ||
+ type == Gdk.EventType.TOUCH_END) {
+ dragging = false;
+ }
+ });
+ }
+
+ /**
+ * Value of this slider. Defaults to `0`.
+ */
+ public double value {
+ get { return adjustment.value; }
+ set { if (!dragging) adjustment.value = value; }
+ }
+
+ /**
+ * Minimum possible value of this slider. Defaults to `0`.
+ */
+ public double min {
+ get { return adjustment.lower; }
+ set { adjustment.lower = value; }
+ }
+
+ /**
+ * Maximum possible value of this slider. Defaults to `1`.
+ */
+ public double max {
+ get { return adjustment.upper; }
+ set { adjustment.upper = value; }
+ }
+
+ /**
+ * Size of step increments. Defaults to `0.05`.
+ */
+ public double step {
+ get { return adjustment.step_increment; }
+ set { adjustment.step_increment = value; }
+ }
+}