summaryrefslogtreecommitdiff
path: root/lib/river/src/astal-river.c
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-09-01 14:17:36 +0200
committerAylur <[email protected]>2024-09-01 14:17:36 +0200
commit3e3f045d650a839d21f7b649da7aa5c19bd2e38b (patch)
tree9a974eb0d38932d474940288c662bd1f01ea3088 /lib/river/src/astal-river.c
parent408faee16911ccfaa3e7dad69f9938fd4a696704 (diff)
monorepo structuring
Diffstat (limited to 'lib/river/src/astal-river.c')
-rw-r--r--lib/river/src/astal-river.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/river/src/astal-river.c b/lib/river/src/astal-river.c
new file mode 100644
index 0000000..37f34d5
--- /dev/null
+++ b/lib/river/src/astal-river.c
@@ -0,0 +1,51 @@
+#include <getopt.h>
+#include <json-glib/json-glib.h>
+#include <stdlib.h>
+
+#include "gio/gio.h"
+#include "astal-river.h"
+
+GMainLoop* loop;
+
+void print_json(AstalRiverRiver* river) {
+ JsonNode* json = json_gobject_serialize(G_OBJECT(river));
+
+ gchar* json_str = json_to_string(json, FALSE);
+ g_print("%s\n", json_str);
+ g_free(json);
+}
+
+int main(int argc, char** argv) {
+ gboolean daemon = FALSE;
+
+ int opt;
+ const char* optstring = "d";
+
+ static struct option long_options[] = {{"daemon", no_argument, NULL, 'd'}, {NULL, 0, NULL, 0}};
+
+ while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
+ switch (opt) {
+ case 'd':
+ daemon = TRUE;
+ break;
+ default:
+ g_print("Usage: %s [-d]\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ GError* error = NULL;
+ AstalRiverRiver* river = g_initable_new(ASTAL_RIVER_TYPE_RIVER, NULL, &error, NULL);
+ if (error) {
+ g_critical("%s\n", error->message);
+ exit(EXIT_FAILURE);
+ }
+ if (daemon) {
+ loop = g_main_loop_new(NULL, FALSE);
+ g_signal_connect(river, "changed", G_CALLBACK(print_json), NULL);
+ g_main_loop_run(loop);
+ } else {
+ print_json(river);
+ g_object_unref(river);
+ }
+}