summaryrefslogtreecommitdiff
path: root/lib/wayland-glib/wl-source.vala
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-12-21 21:53:37 +0100
committerGitHub <[email protected]>2024-12-21 21:53:37 +0100
commit3468763d51d389c67ec7b1a390ffa8a5328bddb6 (patch)
treee7101963b4b3c83b74636cbcd0adb5b9583849d1 /lib/wayland-glib/wl-source.vala
parentd6f4e86f63082271c9a68f5ce2864b6c78d9a5f9 (diff)
parentc8e705a7999e2d36e137771e38aa443c3ed5416d (diff)
Merge pull request #186 from Aylur/feat/wayland-glib
wayland glib
Diffstat (limited to 'lib/wayland-glib/wl-source.vala')
-rw-r--r--lib/wayland-glib/wl-source.vala44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/wayland-glib/wl-source.vala b/lib/wayland-glib/wl-source.vala
new file mode 100644
index 0000000..f8472fb
--- /dev/null
+++ b/lib/wayland-glib/wl-source.vala
@@ -0,0 +1,44 @@
+namespace WlGlib {
+public class WlSource : Source {
+
+ public Wl.Display display;
+ public void* fd;
+ public int error;
+
+ public override bool dispatch(SourceFunc callback) {
+ IOCondition revents = this.query_unix_fd(this.fd);
+ if (this.error > 0 || (revents & (IOCondition.ERR | IOCondition.HUP)) != 0) {
+ errno = this.error;
+ if(callback != null) return callback();
+ return Source.REMOVE;
+ }
+ if (((revents & IOCondition.IN) != 0) && this.display.dispatch() < 0) {
+ if(callback != null) return callback();
+ return Source.REMOVE;
+ }
+ return Source.CONTINUE;
+ }
+
+ public override bool check() {
+ IOCondition revents = this.query_unix_fd(this.fd);
+ return revents > 0;
+ }
+
+ public override bool prepare(out int timeout) {
+ if(this.display.flush() < 0)
+ this.error = errno;
+ timeout = -1;
+ return false;
+ }
+
+ public WlSource() {
+ base();
+ this.display = new Wl.Display.connect(null);
+ if(this.display == null) return;
+ this.fd = this.add_unix_fd(this.display.get_fd(),
+ IOCondition.IN | IOCondition.ERR | IOCondition.HUP);
+ this.attach(null);
+ }
+}
+}
+