summaryrefslogtreecommitdiff
path: root/lib
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
parentd6f4e86f63082271c9a68f5ce2864b6c78d9a5f9 (diff)
parentc8e705a7999e2d36e137771e38aa443c3ed5416d (diff)
Merge pull request #186 from Aylur/feat/wayland-glib
wayland glib
Diffstat (limited to 'lib')
-rw-r--r--lib/river/default.nix6
-rw-r--r--lib/river/include/wayland-source.h16
-rw-r--r--lib/river/meson.build3
-rw-r--r--lib/river/src/meson.build4
-rw-r--r--lib/river/src/river.c12
-rw-r--r--lib/river/src/wayland-source.c104
l---------lib/river/subprojects/wayland-glib1
-rw-r--r--lib/wayland-glib/meson.build40
-rw-r--r--lib/wayland-glib/version1
-rw-r--r--lib/wayland-glib/wl-source.vala44
10 files changed, 104 insertions, 127 deletions
diff --git a/lib/river/default.nix b/lib/river/default.nix
index 99f09dd..15c6eb4 100644
--- a/lib/river/default.nix
+++ b/lib/river/default.nix
@@ -12,4 +12,10 @@ mkAstalPkg {
authors = "kotontrion";
gir-suffix = "River";
description = "IPC client for River";
+
+ postUnpack = ''
+ rm -rf $sourceRoot/subprojects
+ mkdir -p $sourceRoot/subprojects
+ cp -r --remove-destination ${../wayland-glib} $sourceRoot/subprojects/wayland-glib
+ '';
}
diff --git a/lib/river/include/wayland-source.h b/lib/river/include/wayland-source.h
deleted file mode 100644
index b219589..0000000
--- a/lib/river/include/wayland-source.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef __WAYLAND_SOURCE_H__
-#define __WAYLAND_SOURCE_H__
-
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-typedef struct _WLSource WLSource;
-
-WLSource* wl_source_new();
-void wl_source_free(WLSource* self);
-struct wl_display* wl_source_get_display(WLSource* source);
-
-G_END_DECLS
-
-#endif /* __WAYLAND_SOURCE_H__ */
diff --git a/lib/river/meson.build b/lib/river/meson.build
index aa5e23b..2f98315 100644
--- a/lib/river/meson.build
+++ b/lib/river/meson.build
@@ -13,6 +13,9 @@ lib_so_version = version_split[0] + '.' + version_split[1]
pkg_config = import('pkgconfig')
gnome = import('gnome')
+wayland_glib = subproject('wayland-glib')
+wayland_glib_dep = wayland_glib.get_variable('wayland_glib')
+
subdir('protocols')
subdir('include')
subdir('src')
diff --git a/lib/river/src/meson.build b/lib/river/src/meson.build
index b7ce20d..9c58e41 100644
--- a/lib/river/src/meson.build
+++ b/lib/river/src/meson.build
@@ -1,7 +1,6 @@
srcs = files(
'river-output.c',
- 'river.c',
- 'wayland-source.c',
+ 'river.c'
)
deps = [
@@ -9,6 +8,7 @@ deps = [
dependency('gio-2.0'),
dependency('wayland-client'),
dependency('json-glib-1.0'),
+ wayland_glib_dep
]
astal_river_lib = library(
diff --git a/lib/river/src/river.c b/lib/river/src/river.c
index 124cb20..6f94c9c 100644
--- a/lib/river/src/river.c
+++ b/lib/river/src/river.c
@@ -6,7 +6,8 @@
#include "river-control-unstable-v1-client.h"
#include "river-private.h"
#include "river-status-unstable-v1-client.h"
-#include "wayland-source.h"
+// #include "wayland-source.h"
+#include <wayland-glib.h>
struct _AstalRiverRiver {
GObject parent_instance;
@@ -22,7 +23,7 @@ typedef struct {
struct wl_registry* wl_registry;
struct wl_seat* seat;
struct wl_display* display;
- WLSource* wl_source;
+ WlGlibWlSource* wl_source;
struct zriver_status_manager_v1* river_status_manager;
struct zriver_control_v1* river_control;
struct zriver_seat_status_v1* river_seat_status;
@@ -340,7 +341,7 @@ static gboolean astal_river_river_initable_init(GInitable* initable, GCancellabl
if (priv->init) return TRUE;
- priv->wl_source = wl_source_new(NULL, NULL);
+ priv->wl_source = wl_glib_wl_source_new();
if (priv->wl_source == NULL) {
g_set_error_literal(error, G_IO_ERROR, G_IO_ERROR_FAILED,
@@ -348,7 +349,7 @@ static gboolean astal_river_river_initable_init(GInitable* initable, GCancellabl
return FALSE;
}
- priv->display = wl_source_get_display(priv->wl_source);
+ priv->display = priv->wl_source->display;
priv->wl_registry = wl_display_get_registry(priv->display);
wl_registry_add_listener(priv->wl_registry, &registry_listener, self);
@@ -449,7 +450,8 @@ static void astal_river_river_finalize(GObject* object) {
if (priv->seat != NULL) wl_seat_destroy(priv->seat);
if (priv->display != NULL) wl_display_flush(priv->display);
- if (priv->wl_source != NULL) wl_source_free(priv->wl_source);
+ // if (priv->wl_source != NULL) wl_source_free(priv->wl_source);
+ if (priv->wl_source != NULL) g_source_unref((GSource*)(priv->wl_source));
g_free(self->focused_view);
g_free(self->focused_output);
diff --git a/lib/river/src/wayland-source.c b/lib/river/src/wayland-source.c
deleted file mode 100644
index 875c32c..0000000
--- a/lib/river/src/wayland-source.c
+++ /dev/null
@@ -1,104 +0,0 @@
-
-#include "wayland-source.h"
-
-#include <errno.h>
-#include <glib.h>
-#include <wayland-client.h>
-
-struct _WLSource {
- GSource source;
- struct wl_display *display;
- gpointer fd;
- int error;
-};
-
-static gboolean wl_source_prepare(GSource *source, gint *timeout) {
- WLSource *self = (WLSource *)source;
-
- *timeout = 0;
- if (wl_display_prepare_read(self->display) != 0)
- return TRUE;
- else if (wl_display_flush(self->display) < 0) {
- self->error = errno;
- return TRUE;
- }
- *timeout = -1;
- return FALSE;
-}
-
-static gboolean wl_source_check(GSource *source) {
- WLSource *self = (WLSource *)source;
-
- if (self->error > 0) return TRUE;
-
- GIOCondition revents;
- revents = g_source_query_unix_fd(source, self->fd);
-
- if (revents & G_IO_IN) {
- if (wl_display_read_events(self->display) < 0) self->error = errno;
- } else
- wl_display_cancel_read(self->display);
-
- return revents > 0;
-}
-
-static gboolean wl_source_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) {
- WLSource *self = (WLSource *)source;
- GIOCondition revents;
-
- revents = g_source_query_unix_fd(source, self->fd);
- if ((self->error > 0) || (revents & (G_IO_ERR | G_IO_HUP))) {
- errno = self->error;
- self->error = 0;
- if (callback != NULL) return callback(user_data);
- return G_SOURCE_REMOVE;
- }
-
- if (wl_display_dispatch_pending(self->display) < 0) {
- if (callback != NULL) return callback(user_data);
- return G_SOURCE_REMOVE;
- }
-
- return G_SOURCE_CONTINUE;
-}
-
-static void wl_source_finalize(GSource *source) {
- WLSource *self = (WLSource *)source;
- wl_display_disconnect(self->display);
-}
-
-static GSourceFuncs wl_source_funcs = {
- .prepare = wl_source_prepare,
- .check = wl_source_check,
- .dispatch = wl_source_dispatch,
- .finalize = wl_source_finalize,
-};
-
-WLSource *wl_source_new() {
- struct wl_display *display;
- WLSource *self;
- GSource *source;
-
- display = wl_display_connect(NULL);
- if (display == NULL) return NULL;
-
- source = g_source_new(&wl_source_funcs, sizeof(WLSource));
- self = (WLSource *)source;
- self->display = display;
-
- self->fd = g_source_add_unix_fd(source, wl_display_get_fd(self->display),
- G_IO_IN | G_IO_ERR | G_IO_HUP);
-
- g_source_attach(source, NULL);
-
- return self;
-}
-
-void wl_source_free(WLSource *self) {
- GSource *source = (GSource *)self;
- g_return_if_fail(source != NULL);
- g_source_destroy(source);
- g_source_unref(source);
-}
-
-struct wl_display *wl_source_get_display(WLSource *self) { return self->display; }
diff --git a/lib/river/subprojects/wayland-glib b/lib/river/subprojects/wayland-glib
new file mode 120000
index 0000000..41372cf
--- /dev/null
+++ b/lib/river/subprojects/wayland-glib
@@ -0,0 +1 @@
+../../wayland-glib \ No newline at end of file
diff --git a/lib/wayland-glib/meson.build b/lib/wayland-glib/meson.build
new file mode 100644
index 0000000..3d93ac0
--- /dev/null
+++ b/lib/wayland-glib/meson.build
@@ -0,0 +1,40 @@
+project(
+ 'wayland-glib',
+ 'vala',
+ 'c',
+ version: run_command('cat', join_paths(meson.project_source_root(), 'version')).stdout().strip(),
+ meson_version: '>= 0.62.0',
+ default_options: [
+ 'warning_level=2',
+ 'werror=false',
+ 'c_std=gnu11',
+ ],
+)
+
+version_split = meson.project_version().split('.')
+
+deps = [
+ dependency('glib-2.0'),
+ dependency('gio-2.0'),
+ dependency('gobject-2.0'),
+ dependency('wayland-client'),
+]
+
+sources = [
+ 'wl-source.vala',
+]
+
+lib = static_library(
+ meson.project_name(),
+ sources,
+ dependencies: deps,
+ vala_header: meson.project_name() + '.h',
+ vala_vapi: meson.project_name() + '.vapi',
+)
+
+wayland_glib = declare_dependency(
+ link_with: lib,
+ include_directories: include_directories('.')
+ )
+
+
diff --git a/lib/wayland-glib/version b/lib/wayland-glib/version
new file mode 100644
index 0000000..6e8bf73
--- /dev/null
+++ b/lib/wayland-glib/version
@@ -0,0 +1 @@
+0.1.0
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);
+ }
+}
+}
+