summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-06-26 02:20:59 +0200
committerAylur <[email protected]>2024-06-26 02:20:59 +0200
commit710e419986b671dbe02021f19e9fe94e0d17ccb3 (patch)
tree0dedeeb4d7c9469e36fdeaf508fc97282b8aa0db
parent03228cdb160cff067e562a6ab7f8650af23358bd (diff)
feat: widget click through
-rw-r--r--gjs/src/astalify.ts11
-rw-r--r--lua/astal/widget.lua5
-rw-r--r--src/widget/widget.vala23
3 files changed, 39 insertions, 0 deletions
diff --git a/gjs/src/astalify.ts b/gjs/src/astalify.ts
index 6c74179..f198f68 100644
--- a/gjs/src/astalify.ts
+++ b/gjs/src/astalify.ts
@@ -67,6 +67,7 @@ export type Widget<C extends { new(...args: any): Gtk.Widget }> = InstanceType<C
className: string
css: string
cursor: Cursor
+ clickThrough: boolean
toggleClassName(name: string, on?: boolean): void
hook(
object: Connectable,
@@ -205,6 +206,15 @@ function proxify<
this.cursor = cursor
}
+ Object.defineProperty(klass.prototype, "clickThrough", {
+ get() { return Astal.widget_get_click_through(this) },
+ set(v) { Astal.widget_set_click_through(this, v) },
+ })
+
+ klass.prototype.set_click_through = function(clickThrough: boolean) {
+ this.clickThrough = clickThrough
+ }
+
const proxy = new Proxy(klass, {
construct(_, [conf, ...children]) {
const self = new klass
@@ -256,6 +266,7 @@ export type ConstructProps<
className?: string
css?: string
cursor?: string
+ clickThrough?: boolean
}> & {
onDestroy?: (self: Widget<Self>) => unknown
onDraw?: (self: Widget<Self>) => unknown
diff --git a/lua/astal/widget.lua b/lua/astal/widget.lua
index f38cdb9..d2dadc6 100644
--- a/lua/astal/widget.lua
+++ b/lua/astal/widget.lua
@@ -259,6 +259,11 @@ Gtk.Widget._attribute.cursor = {
set = Astal.widget_set_cursor,
}
+Gtk.Widget._attribute.click_through = {
+ get = Astal.widget_get_click_through,
+ set = Astal.widget_set_click_through,
+}
+
Astal.Box._attribute.children = {
get = Astal.Box.get_children,
set = Astal.Box.set_children,
diff --git a/src/widget/widget.vala b/src/widget/widget.vala
index de5ba00..2506bc8 100644
--- a/src/widget/widget.vala
+++ b/src/widget/widget.vala
@@ -131,4 +131,27 @@ public void widget_set_cursor(Gtk.Widget widget, string cursor) {
public string widget_get_cursor(Gtk.Widget widget) {
return Cursor.cursors.get(widget);
}
+
+private class ClickThrough {
+ private static HashTable<Gtk.Widget, bool> _click_through;
+ public static HashTable<Gtk.Widget, bool> click_through {
+ get {
+ if (_click_through == null) {
+ _click_through = new HashTable<Gtk.Widget, bool>(
+ (w) => (uint)w,
+ (a, b) => a == b);
+ }
+ return _click_through;
+ }
+ }
+}
+
+public void widget_set_click_through(Gtk.Widget widget, bool click_through) {
+ ClickThrough.click_through.set(widget, click_through);
+ widget.input_shape_combine_region(click_through ? new Cairo.Region() : null);
+}
+
+public bool widget_get_click_through(Gtk.Widget widget) {
+ return ClickThrough.click_through.get(widget);
+}
}