diff options
author | kotontrion <[email protected]> | 2024-06-16 18:37:04 +0200 |
---|---|---|
committer | kotontrion <[email protected]> | 2024-06-16 18:37:04 +0200 |
commit | 36ce3262ac1f137866bf7f94a2ffea8c6c6fcee6 (patch) | |
tree | a842210653b6b64796daf41b488fb4b61a1cf351 | |
parent | 637875607f230ab7bd45d05db685323f568900f9 (diff) |
fix code style
-rw-r--r-- | include/river-private.h | 14 | ||||
-rw-r--r-- | include/river.h | 37 | ||||
-rw-r--r-- | include/wayland-source.h | 4 | ||||
-rw-r--r-- | meson.build | 2 | ||||
-rw-r--r-- | src/astal-river.c | 37 | ||||
-rw-r--r-- | src/river-output.c | 282 | ||||
-rw-r--r-- | src/river.c | 415 | ||||
-rw-r--r-- | src/wayland-source.c | 43 |
8 files changed, 341 insertions, 493 deletions
diff --git a/include/river-private.h b/include/river-private.h index 1b94495..d32e074 100644 --- a/include/river-private.h +++ b/include/river-private.h @@ -1,20 +1,20 @@ #ifndef ASTAL_RIVER_OUTPUT_PRIVATE_H #define ASTAL_RIVER_OUTPUT_PRIVATE_H -#include "river.h" -#include "river-status-unstable-v1-client.h" #include <wayland-client.h> +#include "river-status-unstable-v1-client.h" +#include "river.h" + G_BEGIN_DECLS -AstalRiverOutput *astal_river_output_new(guint id, - struct wl_output *wl_output, +AstalRiverOutput *astal_river_output_new(guint id, struct wl_output *wl_output, struct zriver_status_manager_v1 *status_manager, struct wl_display *wl_display); -struct wl_output* astal_river_output_get_wl_output(AstalRiverOutput *self); -void astal_river_output_set_focused_view(AstalRiverOutput *self, gchar* focused_view); +struct wl_output *astal_river_output_get_wl_output(AstalRiverOutput *self); +void astal_river_output_set_focused_view(AstalRiverOutput *self, gchar *focused_view); G_END_DECLS -#endif // !ASTAL_RIVER_OUTPUT_PRIVATE_H +#endif // !ASTAL_RIVER_OUTPUT_PRIVATE_H diff --git a/include/river.h b/include/river.h index 7e2bd59..e8576a3 100644 --- a/include/river.h +++ b/include/river.h @@ -7,7 +7,7 @@ G_BEGIN_DECLS #define ASTAL_RIVER_TYPE_OUTPUT (astal_river_output_get_type()) -G_DECLARE_FINAL_TYPE (AstalRiverOutput, astal_river_output, ASTAL_RIVER, OUTPUT, GObject) +G_DECLARE_FINAL_TYPE(AstalRiverOutput, astal_river_output, ASTAL_RIVER, OUTPUT, GObject) /** * astal_river_output_get_nid @@ -23,7 +23,7 @@ guint astal_river_output_get_id(AstalRiverOutput *self); * * Returns: (transfer none) (nullable): the name of the output */ -gchar* astal_river_output_get_name(AstalRiverOutput *self); +gchar *astal_river_output_get_name(AstalRiverOutput *self); /** * astal_river_output_get_layout_name @@ -31,7 +31,7 @@ gchar* astal_river_output_get_name(AstalRiverOutput *self); * * Returns: (transfer none) (nullable): the currently used layout name of the output */ -gchar* astal_river_output_get_layout_name(AstalRiverOutput *self); +gchar *astal_river_output_get_layout_name(AstalRiverOutput *self); /** * astal_river_output_get_focused_view @@ -39,7 +39,7 @@ gchar* astal_river_output_get_layout_name(AstalRiverOutput *self); * * Returns: (transfer none) (nullable): the focused view on the output */ -gchar* astal_river_output_get_focused_view(AstalRiverOutput *self); +gchar *astal_river_output_get_focused_view(AstalRiverOutput *self); /** * astal_river_output_get_focused_tags @@ -57,7 +57,6 @@ guint astal_river_output_get_focused_tags(AstalRiverOutput *self); */ guint astal_river_output_get_urgent_tags(AstalRiverOutput *self); - /** * astal_river_output_get_occupied_tags * @self: the AstalRiverOutput object @@ -66,13 +65,9 @@ guint astal_river_output_get_urgent_tags(AstalRiverOutput *self); */ guint astal_river_output_get_occupied_tags(AstalRiverOutput *self); - - #define ASTAL_RIVER_TYPE_RIVER (astal_river_river_get_type()) -G_DECLARE_FINAL_TYPE (AstalRiverRiver, astal_river_river, ASTAL_RIVER, RIVER, GObject) - - +G_DECLARE_FINAL_TYPE(AstalRiverRiver, astal_river_river, ASTAL_RIVER, RIVER, GObject) /** * astal_river_river_new @@ -86,7 +81,7 @@ AstalRiverRiver *astal_river_river_new(); * * Returns: (nullable) (transfer none): gets the default River object. */ -AstalRiverRiver* astal_river_river_get_default(); +AstalRiverRiver *astal_river_river_get_default(); /** * astal_river_river_get_outputs * @self: the AstalRiverRiver object @@ -94,7 +89,7 @@ AstalRiverRiver* astal_river_river_get_default(); * Returns: (transfer none) (element-type AstalRiver.Output): a list of all outputs * */ -GList* astal_river_river_get_outputs(AstalRiverRiver *self); +GList *astal_river_river_get_outputs(AstalRiverRiver *self); /** * astal_river_river_get_output @@ -103,8 +98,7 @@ GList* astal_river_river_get_outputs(AstalRiverRiver *self); * * Returns: (transfer none) (nullable): the output with the given name or null */ -AstalRiverOutput* astal_river_river_get_output(AstalRiverRiver *self, gchar* name); - +AstalRiverOutput *astal_river_river_get_output(AstalRiverRiver *self, gchar *name); /** * astal_river_river_get_focused_view @@ -112,7 +106,7 @@ AstalRiverOutput* astal_river_river_get_output(AstalRiverRiver *self, gchar* nam * * Returns: (transfer none) (nullable): the currently focused view */ -gchar* astal_river_river_get_focused_view(AstalRiverRiver *self); +gchar *astal_river_river_get_focused_view(AstalRiverRiver *self); /** * astal_river_river_get_focused_output @@ -120,8 +114,7 @@ gchar* astal_river_river_get_focused_view(AstalRiverRiver *self); * * Returns: (transfer none) (nullable): the name of the currently focused output */ -gchar* astal_river_river_get_focused_output(AstalRiverRiver *self); - +gchar *astal_river_river_get_focused_output(AstalRiverRiver *self); /** * astal_river_river_get_mode @@ -129,8 +122,7 @@ gchar* astal_river_river_get_focused_output(AstalRiverRiver *self); * * Returns: (transfer none) (nullable): the currently active mode */ -gchar* astal_river_river_get_mode(AstalRiverRiver *self); - +gchar *astal_river_river_get_mode(AstalRiverRiver *self); /** * AstalRiverCommandCallback: @@ -150,10 +142,9 @@ typedef void (*AstalRiverCommandCallback)(gboolean success, const gchar *msg); * * Calls the given callback with the provided parameters. */ -void astal_river_river_run_command_async(AstalRiverRiver *self, gint length, const gchar **cmd, AstalRiverCommandCallback callback); - - +void astal_river_river_run_command_async(AstalRiverRiver *self, gint length, const gchar **cmd, + AstalRiverCommandCallback callback); G_END_DECLS -#endif // !ASTAL_RIVER_H +#endif // !ASTAL_RIVER_H diff --git a/include/wayland-source.h b/include/wayland-source.h index ad6ed8c..342d82b 100644 --- a/include/wayland-source.h +++ b/include/wayland-source.h @@ -6,8 +6,8 @@ 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); +void wl_source_free(WLSource* self); +struct wl_display* wl_source_get_display(WLSource* source); G_END_DECLS diff --git a/meson.build b/meson.build index 923d06c..0cee54d 100644 --- a/meson.build +++ b/meson.build @@ -9,7 +9,7 @@ project('astal_river', ) add_project_arguments( - ['-Wno-pedantic'], + ['-Wno-pedantic', '-Wno-unused-parameter'], language : 'c') version_split = meson.project_version().split('.') diff --git a/src/astal-river.c b/src/astal-river.c index 6596eb4..cb04d45 100644 --- a/src/astal-river.c +++ b/src/astal-river.c @@ -1,29 +1,26 @@ -#include "river.h" -#include "gio/gio.h" #include <getopt.h> #include <json-glib/json-glib.h> -GMainLoop *loop; +#include "gio/gio.h" +#include "river.h" + +GMainLoop* loop; -void print_json(AstalRiverRiver *river) { - JsonNode *json = json_gobject_serialize (G_OBJECT(river)); +void print_json(AstalRiverRiver* river) { + JsonNode* json = json_gobject_serialize(G_OBJECT(river)); - gchar* json_str = json_to_string (json, FALSE); + gchar* json_str = json_to_string(json, FALSE); g_print("%s\n", json_str); g_free(json); } -int main(int argc, char **argv) { - +int main(int argc, char** argv) { gboolean daemon = FALSE; int opt; - const char *optstring = "d"; + const char* optstring = "d"; - static struct option long_options[] = { - {"daemon", no_argument, NULL, 'd'}, - {NULL, 0, NULL, 0} - }; + 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) { @@ -36,15 +33,13 @@ int main(int argc, char **argv) { } } - AstalRiverRiver *river = astal_river_river_new (); - if(daemon) { - loop = g_main_loop_new (NULL, FALSE); + AstalRiverRiver* river = astal_river_river_new(); + 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_main_loop_run(loop); + } else { + print_json(river); g_object_unref(river); } - } diff --git a/src/river-output.c b/src/river-output.c index 297a290..a431cf4 100644 --- a/src/river-output.c +++ b/src/river-output.c @@ -1,6 +1,6 @@ +#include <gio/gio.h> #include "river-private.h" -#include <gio/gio.h> #include "river-status-unstable-v1-client.h" struct _AstalRiverOutput { @@ -8,17 +8,17 @@ struct _AstalRiverOutput { guint focused_tags; guint occupied_tags; guint urgent_tags; - gchar *layout_name; - gchar *focused_view; + gchar* layout_name; + gchar* focused_view; guint id; gchar* name; }; typedef struct { - struct zriver_status_manager_v1 *river_status_manager; - struct zriver_output_status_v1 *river_output_status; - struct wl_display *wl_display; - struct wl_output *wl_output; + struct zriver_status_manager_v1* river_status_manager; + struct zriver_output_status_v1* river_output_status; + struct wl_display* wl_display; + struct wl_output* wl_output; } AstalRiverOutputPrivate; G_DEFINE_FINAL_TYPE_WITH_PRIVATE(AstalRiverOutput, astal_river_output, G_TYPE_OBJECT); @@ -39,158 +39,143 @@ typedef enum { ASTAL_RIVER_OUTPUT_N_SIGNALS } AstalRiverOutputSignals; -static guint astal_river_output_signals[ASTAL_RIVER_OUTPUT_N_SIGNALS] = {0,}; -static GParamSpec *astal_river_output_properties[ASTAL_RIVER_OUTPUT_N_PROPERTIES] = {NULL,}; +static guint astal_river_output_signals[ASTAL_RIVER_OUTPUT_N_SIGNALS] = { + 0, +}; -guint astal_river_output_get_id(AstalRiverOutput *self) { - return self->id; -} +static GParamSpec* astal_river_output_properties[ASTAL_RIVER_OUTPUT_N_PROPERTIES] = { + NULL, +}; -gchar* astal_river_output_get_name(AstalRiverOutput *self) { - return self->name; -} +guint astal_river_output_get_id(AstalRiverOutput* self) { return self->id; } -gchar* astal_river_output_get_layout_name(AstalRiverOutput *self) { - return self->layout_name; -} +gchar* astal_river_output_get_name(AstalRiverOutput* self) { return self->name; } -gchar* astal_river_output_get_focused_view(AstalRiverOutput *self) { - return self->focused_view; -} +gchar* astal_river_output_get_layout_name(AstalRiverOutput* self) { return self->layout_name; } + +gchar* astal_river_output_get_focused_view(AstalRiverOutput* self) { return self->focused_view; } -void astal_river_output_set_focused_view(AstalRiverOutput *self, gchar* focused_view) { +void astal_river_output_set_focused_view(AstalRiverOutput* self, gchar* focused_view) { g_free(self->focused_view); self->focused_view = g_strdup(focused_view); - g_object_notify (G_OBJECT(self), "focused-view"); - g_signal_emit (self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0); + g_object_notify(G_OBJECT(self), "focused-view"); + g_signal_emit(self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0); } -guint astal_river_output_get_focused_tags(AstalRiverOutput *self) { - return self->focused_tags; -} +guint astal_river_output_get_focused_tags(AstalRiverOutput* self) { return self->focused_tags; } -guint astal_river_output_get_urgent_tags(AstalRiverOutput *self) { - return self->urgent_tags; -} - -guint astal_river_output_get_occupied_tags(AstalRiverOutput *self) { - return self->occupied_tags; -} +guint astal_river_output_get_urgent_tags(AstalRiverOutput* self) { return self->urgent_tags; } +guint astal_river_output_get_occupied_tags(AstalRiverOutput* self) { return self->occupied_tags; } -struct wl_output* astal_river_output_get_wl_output(AstalRiverOutput *self) { - AstalRiverOutputPrivate *priv = astal_river_output_get_instance_private(self); - return priv->wl_output; +struct wl_output* astal_river_output_get_wl_output(AstalRiverOutput* self) { + AstalRiverOutputPrivate* priv = astal_river_output_get_instance_private(self); + return priv->wl_output; } -static void astal_river_output_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { - AstalRiverOutput *self = ASTAL_RIVER_OUTPUT(object); +static void astal_river_output_get_property(GObject* object, guint property_id, GValue* value, + GParamSpec* pspec) { + AstalRiverOutput* self = ASTAL_RIVER_OUTPUT(object); switch (property_id) { case ASTAL_RIVER_OUTPUT_PROP_FOCUSED_TAGS: - g_value_set_uint (value, self->focused_tags); + g_value_set_uint(value, self->focused_tags); break; case ASTAL_RIVER_OUTPUT_PROP_OCCUPIED_TAGS: - g_value_set_uint (value, self->occupied_tags); + g_value_set_uint(value, self->occupied_tags); break; case ASTAL_RIVER_OUTPUT_PROP_URGENT_TAGS: - g_value_set_uint (value, self->urgent_tags); + g_value_set_uint(value, self->urgent_tags); break; case ASTAL_RIVER_OUTPUT_PROP_ID: - g_value_set_uint (value, self->id); + g_value_set_uint(value, self->id); break; case ASTAL_RIVER_OUTPUT_PROP_NAME: - g_value_set_string (value, self->name); + g_value_set_string(value, self->name); break; case ASTAL_RIVER_OUTPUT_PROP_LAYOUT_NAME: - g_value_set_string (value, self->layout_name); + g_value_set_string(value, self->layout_name); break; case ASTAL_RIVER_OUTPUT_PROP_FOCUSED_VIEW: - g_value_set_string (value, self->focused_view); + g_value_set_string(value, self->focused_view); break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); break; } } -static void astal_river_output_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { - AstalRiverOutput *self = ASTAL_RIVER_OUTPUT(object); +static void astal_river_output_set_property(GObject* object, guint property_id, const GValue* value, + GParamSpec* pspec) { + AstalRiverOutput* self = ASTAL_RIVER_OUTPUT(object); switch (property_id) { case ASTAL_RIVER_OUTPUT_PROP_ID: - self->id = g_value_get_uint (value); + self->id = g_value_get_uint(value); g_object_notify(G_OBJECT(self), "id"); break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); break; } - g_signal_emit (self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0); + g_signal_emit(self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0); } static void noop() {} -static void astal_river_handle_focused_tags(void *data, - struct zriver_output_status_v1 *status, +static void astal_river_handle_focused_tags(void* data, struct zriver_output_status_v1* status, uint32_t tags) { - AstalRiverOutput *self = ASTAL_RIVER_OUTPUT (data); + AstalRiverOutput* self = ASTAL_RIVER_OUTPUT(data); self->focused_tags = tags; - g_object_notify (G_OBJECT(self), "focused-tags"); - g_signal_emit (self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0); + g_object_notify(G_OBJECT(self), "focused-tags"); + g_signal_emit(self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0); } -static void astal_river_handle_urgent_tags(void *data, - struct zriver_output_status_v1 *status, +static void astal_river_handle_urgent_tags(void* data, struct zriver_output_status_v1* status, uint32_t tags) { - AstalRiverOutput *self = ASTAL_RIVER_OUTPUT (data); + AstalRiverOutput* self = ASTAL_RIVER_OUTPUT(data); self->urgent_tags = tags; - g_object_notify (G_OBJECT(self), "urgent-tags"); - g_signal_emit (self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0); + g_object_notify(G_OBJECT(self), "urgent-tags"); + g_signal_emit(self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0); } -static void astal_river_handle_occupied_tags(void *data, - struct zriver_output_status_v1 *status, - struct wl_array *view_tags) { - AstalRiverOutput *self = ASTAL_RIVER_OUTPUT (data); +static void astal_river_handle_occupied_tags(void* data, struct zriver_output_status_v1* status, + struct wl_array* view_tags) { + AstalRiverOutput* self = ASTAL_RIVER_OUTPUT(data); guint tags = 0; - guint *view; - wl_array_for_each (view, view_tags) { - tags |= *view; - } + guint* view; + wl_array_for_each(view, view_tags) { tags |= *view; } self->occupied_tags = tags; - g_object_notify (G_OBJECT(self), "occupied-tags"); - g_signal_emit (self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0); + g_object_notify(G_OBJECT(self), "occupied-tags"); + g_signal_emit(self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0); } -static void astal_river_handle_layout_name(void *data, - struct zriver_output_status_v1 *status, +static void astal_river_handle_layout_name(void* data, struct zriver_output_status_v1* status, const char* name) { - AstalRiverOutput *self = ASTAL_RIVER_OUTPUT (data); + AstalRiverOutput* self = ASTAL_RIVER_OUTPUT(data); g_free(self->layout_name); - self->layout_name = g_strdup (name); - g_object_notify (G_OBJECT(self), "layout-name"); - g_signal_emit (self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0); + self->layout_name = g_strdup(name); + g_object_notify(G_OBJECT(self), "layout-name"); + g_signal_emit(self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0); } -static void astal_river_handle_layout_name_clear(void *data, - struct zriver_output_status_v1 *status) { - AstalRiverOutput *self = ASTAL_RIVER_OUTPUT (data); +static void astal_river_handle_layout_name_clear(void* data, + struct zriver_output_status_v1* status) { + AstalRiverOutput* self = ASTAL_RIVER_OUTPUT(data); g_free(self->layout_name); - self->layout_name = NULL; - g_object_notify (G_OBJECT(self), "layout-name"); - g_signal_emit (self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0); + self->layout_name = NULL; + g_object_notify(G_OBJECT(self), "layout-name"); + g_signal_emit(self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0); } -static void astal_river_wl_output_handle_name(void *data, - struct wl_output *output, +static void astal_river_wl_output_handle_name(void* data, struct wl_output* output, const char* name) { - AstalRiverOutput *self = ASTAL_RIVER_OUTPUT (data); + AstalRiverOutput* self = ASTAL_RIVER_OUTPUT(data); g_free(self->name); self->name = g_strdup(name); - g_object_notify (G_OBJECT(self), "name"); - g_signal_emit (self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0); + g_object_notify(G_OBJECT(self), "name"); + g_signal_emit(self, astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED], 0); } static const struct zriver_output_status_v1_listener output_status_listener = { @@ -210,121 +195,72 @@ static const struct wl_output_listener wl_output_listener = { .done = noop, }; -static void astal_river_output_finalize(GObject *object) { +static void astal_river_output_finalize(GObject* object) { + AstalRiverOutput* self = ASTAL_RIVER_OUTPUT(object); + AstalRiverOutputPrivate* priv = astal_river_output_get_instance_private(self); - AstalRiverOutput *self = ASTAL_RIVER_OUTPUT(object); - AstalRiverOutputPrivate *priv = astal_river_output_get_instance_private (self); + zriver_output_status_v1_destroy(priv->river_output_status); + wl_output_destroy(priv->wl_output); - zriver_output_status_v1_destroy (priv->river_output_status); - wl_output_destroy (priv->wl_output); - - wl_display_roundtrip (priv->wl_display); + wl_display_roundtrip(priv->wl_display); g_free(self->layout_name); g_free(self->name); - G_OBJECT_CLASS (astal_river_output_parent_class)->finalize(object); + G_OBJECT_CLASS(astal_river_output_parent_class)->finalize(object); } -static void astal_river_output_init(AstalRiverOutput *self) { -} - -AstalRiverOutput *astal_river_output_new(guint id, - struct wl_output *wl_output, - struct zriver_status_manager_v1 *status_manager, - struct wl_display *wl_display) { +static void astal_river_output_init(AstalRiverOutput* self) {} - AstalRiverOutput *self = g_object_new (ASTAL_RIVER_TYPE_OUTPUT, NULL); - AstalRiverOutputPrivate *priv = astal_river_output_get_instance_private (self); +AstalRiverOutput* astal_river_output_new(guint id, struct wl_output* wl_output, + struct zriver_status_manager_v1* status_manager, + struct wl_display* wl_display) { + AstalRiverOutput* self = g_object_new(ASTAL_RIVER_TYPE_OUTPUT, NULL); + AstalRiverOutputPrivate* priv = astal_river_output_get_instance_private(self); self->id = id; priv->wl_display = wl_display; priv->wl_output = wl_output; priv->river_status_manager = status_manager; - priv->river_output_status = zriver_status_manager_v1_get_river_output_status( - priv->river_status_manager, wl_output); + priv->river_output_status = + zriver_status_manager_v1_get_river_output_status(priv->river_status_manager, wl_output); - zriver_output_status_v1_add_listener( - priv->river_output_status, &output_status_listener, self); + zriver_output_status_v1_add_listener(priv->river_output_status, &output_status_listener, self); - wl_output_add_listener (wl_output, &wl_output_listener, self); + wl_output_add_listener(wl_output, &wl_output_listener, self); wl_display_roundtrip(priv->wl_display); return self; } -static void astal_river_output_class_init(AstalRiverOutputClass *class) { - - GObjectClass *object_class = G_OBJECT_CLASS (class); +static void astal_river_output_class_init(AstalRiverOutputClass* class) { + GObjectClass* object_class = G_OBJECT_CLASS(class); object_class->get_property = astal_river_output_get_property; object_class->set_property = astal_river_output_set_property; object_class->finalize = astal_river_output_finalize; - - astal_river_output_properties[ASTAL_RIVER_OUTPUT_PROP_FOCUSED_TAGS] = - g_param_spec_uint("focused-tags", - "focused-tags", - "currently focused tags", - 0, - INT_MAX, - 0, - G_PARAM_READABLE); + astal_river_output_properties[ASTAL_RIVER_OUTPUT_PROP_FOCUSED_TAGS] = g_param_spec_uint( + "focused-tags", "focused-tags", "currently focused tags", 0, INT_MAX, 0, G_PARAM_READABLE); astal_river_output_properties[ASTAL_RIVER_OUTPUT_PROP_OCCUPIED_TAGS] = - g_param_spec_uint("occupied-tags", - "occupied-tags", - "currently occupied tags", - 0, - INT_MAX, - 0, - G_PARAM_READABLE); - astal_river_output_properties[ASTAL_RIVER_OUTPUT_PROP_URGENT_TAGS] = - g_param_spec_uint("urgent-tags", - "urgent-tags", - "currently urgent tags", - 0, - INT_MAX, - 0, - G_PARAM_READABLE); + g_param_spec_uint("occupied-tags", "occupied-tags", "currently occupied tags", 0, INT_MAX, + 0, G_PARAM_READABLE); + astal_river_output_properties[ASTAL_RIVER_OUTPUT_PROP_URGENT_TAGS] = g_param_spec_uint( + "urgent-tags", "urgent-tags", "currently urgent tags", 0, INT_MAX, 0, G_PARAM_READABLE); astal_river_output_properties[ASTAL_RIVER_OUTPUT_PROP_ID] = - g_param_spec_uint("id", - "id", - "id of the output object", - 0, - INT_MAX, - 0, - G_PARAM_READABLE); - astal_river_output_properties[ASTAL_RIVER_OUTPUT_PROP_LAYOUT_NAME] = - g_param_spec_string("layout-name", - "layout-name", - "name of the current layout", - NULL, - G_PARAM_READABLE); + g_param_spec_uint("id", "id", "id of the output object", 0, INT_MAX, 0, G_PARAM_READABLE); + astal_river_output_properties[ASTAL_RIVER_OUTPUT_PROP_LAYOUT_NAME] = g_param_spec_string( + "layout-name", "layout-name", "name of the current layout", NULL, G_PARAM_READABLE); astal_river_output_properties[ASTAL_RIVER_OUTPUT_PROP_NAME] = - g_param_spec_string("name", - "name", - "name of the output", - NULL, - G_PARAM_READABLE); + g_param_spec_string("name", "name", "name of the output", NULL, G_PARAM_READABLE); astal_river_output_properties[ASTAL_RIVER_OUTPUT_PROP_FOCUSED_VIEW] = - g_param_spec_string("focused-view", - "focused-view", - "name of last focused view on this output", - NULL, - G_PARAM_READABLE); - - g_object_class_install_properties(object_class, - ASTAL_RIVER_OUTPUT_N_PROPERTIES, + g_param_spec_string("focused-view", "focused-view", + "name of last focused view on this output", NULL, G_PARAM_READABLE); + + g_object_class_install_properties(object_class, ASTAL_RIVER_OUTPUT_N_PROPERTIES, astal_river_output_properties); astal_river_output_signals[ASTAL_RIVER_OUTPUT_SIGNAL_CHANGED] = - g_signal_new("changed", - G_TYPE_FROM_CLASS(class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, - NULL, - NULL, - G_TYPE_NONE, - 0); + g_signal_new("changed", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, + G_TYPE_NONE, 0); } diff --git a/src/river.c b/src/river.c index e6fc26c..16e9e05 100644 --- a/src/river.c +++ b/src/river.c @@ -1,44 +1,42 @@ - - -#include "river.h" -#include "river-private.h" #include <gio/gio.h> +#include <json-glib/json-glib.h> #include <wayland-client-protocol.h> #include <wayland-client.h> -#include "river-status-unstable-v1-client.h" + #include "river-control-unstable-v1-client.h" +#include "river-private.h" +#include "river-status-unstable-v1-client.h" #include "wayland-source.h" -#include <json-glib/json-glib.h> - struct _AstalRiverRiver { GObject parent_instance; - GList *outputs; - gchar *focused_output; - gchar *focused_view; - gchar *mode; + GList* outputs; + gchar* focused_output; + gchar* focused_view; + gchar* mode; }; typedef struct { - GHashTable *signal_ids; - - struct wl_registry *wl_registry; - struct wl_seat *seat; - struct wl_display *display; - WLSource *wl_source; - struct zriver_status_manager_v1 *river_status_manager; - struct zriver_control_v1 *river_control;; - struct zriver_seat_status_v1 *river_seat_status; + GHashTable* signal_ids; + + struct wl_registry* wl_registry; + struct wl_seat* seat; + struct wl_display* display; + WLSource* wl_source; + struct zriver_status_manager_v1* river_status_manager; + struct zriver_control_v1* river_control; + struct zriver_seat_status_v1* river_seat_status; } AstalRiverRiverPrivate; -static JsonSerializableIface *serializable_iface = NULL; -static void astal_river_river_initable_iface_init (GInitableIface *iface); -static void astal_river_river_json_serializable_iface_init(JsonSerializableIface *g_iface); +static JsonSerializableIface* serializable_iface = NULL; +static void astal_river_river_initable_iface_init(GInitableIface* iface); +static void astal_river_river_json_serializable_iface_init(JsonSerializableIface* g_iface); -G_DEFINE_TYPE_WITH_CODE (AstalRiverRiver, astal_river_river, G_TYPE_OBJECT, - G_ADD_PRIVATE (AstalRiverRiver) - G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, astal_river_river_initable_iface_init) - G_IMPLEMENT_INTERFACE (JSON_TYPE_SERIALIZABLE, astal_river_river_json_serializable_iface_init)) +G_DEFINE_TYPE_WITH_CODE(AstalRiverRiver, astal_river_river, G_TYPE_OBJECT, + G_ADD_PRIVATE(AstalRiverRiver) G_IMPLEMENT_INTERFACE( + G_TYPE_INITABLE, astal_river_river_initable_iface_init) + G_IMPLEMENT_INTERFACE(JSON_TYPE_SERIALIZABLE, + astal_river_river_json_serializable_iface_init)) typedef enum { ASTAL_RIVER_RIVER_PROP_FOCUSED_OUTPUT = 1, @@ -55,144 +53,135 @@ typedef enum { ASTAL_RIVER_RIVER_N_SIGNALS } AstalRiverOutputSignals; -static guint astal_river_river_signals[ASTAL_RIVER_RIVER_N_SIGNALS] = {0,}; -static GParamSpec *astal_river_river_properties[ASTAL_RIVER_RIVER_N_PROPERTIES] = {NULL,}; +static guint astal_river_river_signals[ASTAL_RIVER_RIVER_N_SIGNALS] = { + 0, +}; +static GParamSpec* astal_river_river_properties[ASTAL_RIVER_RIVER_N_PROPERTIES] = { + NULL, +}; -static void reemit_changed(AstalRiverOutput *output, AstalRiverRiver *self) { - g_signal_emit (self, astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_CHANGED], 0); +static void reemit_changed(AstalRiverOutput* output, AstalRiverRiver* self) { + g_signal_emit(self, astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_CHANGED], 0); } -static AstalRiverOutput *find_output_by_id (AstalRiverRiver *self, uint32_t id) { - GList *output = self->outputs; - while(output != NULL) { - AstalRiverOutput *river_output = output->data; - if(astal_river_output_get_id (river_output) == id) return river_output; +static AstalRiverOutput* find_output_by_id(AstalRiverRiver* self, uint32_t id) { + GList* output = self->outputs; + while (output != NULL) { + AstalRiverOutput* river_output = output->data; + if (astal_river_output_get_id(river_output) == id) return river_output; output = output->next; } return NULL; } -static AstalRiverOutput *find_output_by_output (AstalRiverRiver *self, struct wl_output *wl_output) { - GList *output = self->outputs; - while(output != NULL) { - AstalRiverOutput *river_output = output->data; - if(astal_river_output_get_wl_output (river_output) == wl_output) return river_output; +static AstalRiverOutput* find_output_by_output(AstalRiverRiver* self, struct wl_output* wl_output) { + GList* output = self->outputs; + while (output != NULL) { + AstalRiverOutput* river_output = output->data; + if (astal_river_output_get_wl_output(river_output) == wl_output) return river_output; output = output->next; } return NULL; } -static AstalRiverOutput *find_output_by_name (AstalRiverRiver *self, gchar* name) { - GList *output = self->outputs; - while(output != NULL) { - AstalRiverOutput *river_output = output->data; - if(strcmp(astal_river_output_get_name (river_output), name) == 0) return river_output; +static AstalRiverOutput* find_output_by_name(AstalRiverRiver* self, gchar* name) { + GList* output = self->outputs; + while (output != NULL) { + AstalRiverOutput* river_output = output->data; + if (strcmp(astal_river_output_get_name(river_output), name) == 0) return river_output; output = output->next; } return NULL; } -GList* astal_river_river_get_outputs(AstalRiverRiver *self){ - return self->outputs; -} +GList* astal_river_river_get_outputs(AstalRiverRiver* self) { return self->outputs; } -AstalRiverOutput* astal_river_river_get_output(AstalRiverRiver *self, gchar* name) { - return find_output_by_name(self, name); +AstalRiverOutput* astal_river_river_get_output(AstalRiverRiver* self, gchar* name) { + return find_output_by_name(self, name); } -gchar* astal_river_river_get_focused_view(AstalRiverRiver *self) { - return self->focused_view; -} +gchar* astal_river_river_get_focused_view(AstalRiverRiver* self) { return self->focused_view; } -gchar* astal_river_river_get_focused_output(AstalRiverRiver *self) { - return self->focused_output; -} +gchar* astal_river_river_get_focused_output(AstalRiverRiver* self) { return self->focused_output; } -gchar* astal_river_river_get_mode(AstalRiverRiver *self) { - return self->mode; -} +gchar* astal_river_river_get_mode(AstalRiverRiver* self) { return self->mode; } -static void astal_river_river_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { - AstalRiverRiver *self = ASTAL_RIVER_RIVER(object); +static void astal_river_river_get_property(GObject* object, guint property_id, GValue* value, + GParamSpec* pspec) { + AstalRiverRiver* self = ASTAL_RIVER_RIVER(object); switch (property_id) { case ASTAL_RIVER_RIVER_PROP_MODE: - g_value_set_string (value, self->mode); + g_value_set_string(value, self->mode); break; case ASTAL_RIVER_RIVER_PROP_FOCUSED_VIEW: - g_value_set_string (value, self->focused_view); + g_value_set_string(value, self->focused_view); break; case ASTAL_RIVER_RIVER_PROP_FOCUSED_OUTPUT: - g_value_set_string (value, self->focused_output); + g_value_set_string(value, self->focused_output); break; case ASTAL_RIVER_RIVER_PROP_OUTPUTS: g_value_set_pointer(value, self->outputs); break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); break; } } -static JsonNode* astal_river_river_serialize_property(JsonSerializable *serializable, - const gchar *name, - const GValue *value, - GParamSpec *pspec) { - JsonNode *retval = NULL; - if (strcmp (name, "outputs") == 0) { - JsonArray *outputs = json_array_new (); - retval = json_node_new (JSON_NODE_ARRAY); - GList *output = g_value_get_pointer (value); - while(output != NULL) { - AstalRiverOutput *river_output = output->data; - json_array_add_element (outputs, json_gobject_serialize (G_OBJECT(river_output))); +static JsonNode* astal_river_river_serialize_property(JsonSerializable* serializable, + const gchar* name, const GValue* value, + GParamSpec* pspec) { + JsonNode* retval = NULL; + if (strcmp(name, "outputs") == 0) { + JsonArray* outputs = json_array_new(); + retval = json_node_new(JSON_NODE_ARRAY); + GList* output = g_value_get_pointer(value); + while (output != NULL) { + AstalRiverOutput* river_output = output->data; + json_array_add_element(outputs, json_gobject_serialize(G_OBJECT(river_output))); output = output->next; } - json_node_take_array (retval, outputs); - } - else + json_node_take_array(retval, outputs); + } else retval = serializable_iface->serialize_property(serializable, name, value, pspec); return retval; } -static void noop(){} +static void noop() {} static void river_seat_status_handle_focused_output(void* data, struct zriver_seat_status_v1* seat_status, struct wl_output* focused_output) { - - AstalRiverRiver *self = ASTAL_RIVER_RIVER(data); + AstalRiverRiver* self = ASTAL_RIVER_RIVER(data); g_free(self->focused_output); - AstalRiverOutput *output = find_output_by_output(self, focused_output); - if(output == NULL) return; + AstalRiverOutput* output = find_output_by_output(self, focused_output); + if (output == NULL) return; self->focused_output = g_strdup(astal_river_output_get_name(output)); g_object_notify(G_OBJECT(self), "focused-output"); - g_signal_emit (self, astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_CHANGED], 0); + g_signal_emit(self, astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_CHANGED], 0); } static void river_seat_status_handle_focused_view(void* data, struct zriver_seat_status_v1* seat_status, const char* focused_view) { - - AstalRiverRiver *self = ASTAL_RIVER_RIVER(data); + AstalRiverRiver* self = ASTAL_RIVER_RIVER(data); g_free(self->focused_view); self->focused_view = g_strdup(focused_view); - AstalRiverOutput *output = find_output_by_name(self, self->focused_output); - astal_river_output_set_focused_view (output, focused_view); + AstalRiverOutput* output = find_output_by_name(self, self->focused_output); + astal_river_output_set_focused_view(output, focused_view); g_object_notify(G_OBJECT(self), "focused-view"); - g_signal_emit (self, astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_CHANGED], 0); + g_signal_emit(self, astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_CHANGED], 0); } -static void river_seat_status_handle_mode(void* data, - struct zriver_seat_status_v1* seat_status, +static void river_seat_status_handle_mode(void* data, struct zriver_seat_status_v1* seat_status, const char* mode) { - - AstalRiverRiver *self = ASTAL_RIVER_RIVER(data); + AstalRiverRiver* self = ASTAL_RIVER_RIVER(data); g_free(self->mode); self->mode = g_strdup(mode); g_object_notify(G_OBJECT(self), "mode"); - g_signal_emit (self, astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_CHANGED], 0); + g_signal_emit(self, astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_CHANGED], 0); } static const struct zriver_seat_status_v1_listener river_seat_status_listener = { @@ -202,110 +191,105 @@ static const struct zriver_seat_status_v1_listener river_seat_status_listener = .mode = river_seat_status_handle_mode, }; -static void global_registry_handler(void* data, - struct wl_registry* registry, - uint32_t id, - const char* interface, - uint32_t version) { - AstalRiverRiver *self = ASTAL_RIVER_RIVER(data); - AstalRiverRiverPrivate *priv = astal_river_river_get_instance_private (self); +static void global_registry_handler(void* data, struct wl_registry* registry, uint32_t id, + const char* interface, uint32_t version) { + AstalRiverRiver* self = ASTAL_RIVER_RIVER(data); + AstalRiverRiverPrivate* priv = astal_river_river_get_instance_private(self); if (strcmp(interface, wl_output_interface.name) == 0) { - struct wl_output *wl_out = wl_registry_bind(registry, id, &wl_output_interface, 4); - AstalRiverOutput *output = astal_river_output_new(id, wl_out, priv->river_status_manager, priv->display); + struct wl_output* wl_out = wl_registry_bind(registry, id, &wl_output_interface, 4); + AstalRiverOutput* output = + astal_river_output_new(id, wl_out, priv->river_status_manager, priv->display); - self->outputs = g_list_append (self->outputs, output); - g_object_notify (G_OBJECT(self), "outputs"); + self->outputs = g_list_append(self->outputs, output); + g_object_notify(G_OBJECT(self), "outputs"); g_signal_emit(G_OBJECT(self), astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_OUTPUT_ADDED], 0, astal_river_output_get_name(output)); - g_signal_emit (self, astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_CHANGED], 0); + g_signal_emit(self, astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_CHANGED], 0); + guint signal_id = g_signal_connect(output, "changed", G_CALLBACK(reemit_changed), self); - g_hash_table_insert (priv->signal_ids, GUINT_TO_POINTER (id), GUINT_TO_POINTER (signal_id)); + g_hash_table_insert(priv->signal_ids, GUINT_TO_POINTER(id), GUINT_TO_POINTER(signal_id)); } else if (strcmp(interface, wl_seat_interface.name) == 0) { priv->seat = wl_registry_bind(registry, id, &wl_seat_interface, 4); } else if (strcmp(interface, zriver_status_manager_v1_interface.name) == 0) { - priv->river_status_manager = wl_registry_bind( - registry, id, &zriver_status_manager_v1_interface, 4); + priv->river_status_manager = + wl_registry_bind(registry, id, &zriver_status_manager_v1_interface, 4); } else if (strcmp(interface, zriver_control_v1_interface.name) == 0) { - priv->river_control = wl_registry_bind( - registry, id, &zriver_control_v1_interface, 1); + priv->river_control = wl_registry_bind(registry, id, &zriver_control_v1_interface, 1); } } -static void astal_river_river_callback_success(void *data, - struct zriver_command_callback_v1 *cb, - const char *msg) { +static void astal_river_river_callback_success(void* data, struct zriver_command_callback_v1* cb, + const char* msg) { AstalRiverCommandCallback callback = (AstalRiverCommandCallback)(data); callback(TRUE, msg); } -static void astal_river_river_callback_failure(void *data, - struct zriver_command_callback_v1 *cb, - const char *msg) { +static void astal_river_river_callback_failure(void* data, struct zriver_command_callback_v1* cb, + const char* msg) { AstalRiverCommandCallback callback = (AstalRiverCommandCallback)(data); callback(FALSE, msg); } const struct zriver_command_callback_v1_listener cb_listener = { - .success = astal_river_river_callback_success, - .failure = astal_river_river_callback_failure -}; + .success = astal_river_river_callback_success, .failure = astal_river_river_callback_failure}; -void astal_river_river_run_command_async(AstalRiverRiver *self, gint length, const gchar **cmd, AstalRiverCommandCallback callback) { - AstalRiverRiverPrivate *priv = astal_river_river_get_instance_private(self); - - for(gint i = 0; i < length; ++i) { +void astal_river_river_run_command_async(AstalRiverRiver* self, gint length, const gchar** cmd, + AstalRiverCommandCallback callback) { + AstalRiverRiverPrivate* priv = astal_river_river_get_instance_private(self); + + for (gint i = 0; i < length; ++i) { zriver_control_v1_add_argument(priv->river_control, cmd[i]); } - - struct zriver_command_callback_v1 *cb = zriver_control_v1_run_command(priv->river_control, priv->seat); - if(callback != NULL) - zriver_command_callback_v1_add_listener(cb, &cb_listener, callback); + + struct zriver_command_callback_v1* cb = + zriver_control_v1_run_command(priv->river_control, priv->seat); + if (callback != NULL) zriver_command_callback_v1_add_listener(cb, &cb_listener, callback); } static void global_registry_remover(void* data, struct wl_registry* registry, uint32_t id) { - AstalRiverRiver *self = ASTAL_RIVER_RIVER (data); - AstalRiverRiverPrivate *priv = astal_river_river_get_instance_private (self); - AstalRiverOutput *output = find_output_by_id(self, id); - if ( output != NULL ) { - guint signal_id = GPOINTER_TO_UINT (g_hash_table_lookup (priv->signal_ids, GUINT_TO_POINTER (id))); - g_hash_table_remove (priv->signal_ids, GUINT_TO_POINTER(id)); - g_signal_handler_disconnect (output, signal_id); + AstalRiverRiver* self = ASTAL_RIVER_RIVER(data); + AstalRiverRiverPrivate* priv = astal_river_river_get_instance_private(self); + AstalRiverOutput* output = find_output_by_id(self, id); + if (output != NULL) { + guint signal_id = + GPOINTER_TO_UINT(g_hash_table_lookup(priv->signal_ids, GUINT_TO_POINTER(id))); + g_hash_table_remove(priv->signal_ids, GUINT_TO_POINTER(id)); + g_signal_handler_disconnect(output, signal_id); g_signal_emit(G_OBJECT(self), astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_OUTPUT_ADDED], 0, astal_river_output_get_name(output)); - self->outputs = g_list_remove (self->outputs, output); - g_object_notify (G_OBJECT(self), "outputs"); + self->outputs = g_list_remove(self->outputs, output); + g_object_notify(G_OBJECT(self), "outputs"); g_object_unref(output); - return; - } - g_signal_emit (self, astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_CHANGED], 0); + return; + } + g_signal_emit(self, astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_CHANGED], 0); } +static const struct wl_registry_listener registry_listener = {global_registry_handler, + global_registry_remover}; -static const struct wl_registry_listener registry_listener = { - global_registry_handler, - global_registry_remover -}; - -static void astal_river_river_json_serializable_iface_init(JsonSerializableIface *iface){ +static void astal_river_river_json_serializable_iface_init(JsonSerializableIface* iface) { iface->serialize_property = astal_river_river_serialize_property; - serializable_iface = g_type_default_interface_peek (JSON_TYPE_SERIALIZABLE); + serializable_iface = g_type_default_interface_peek(JSON_TYPE_SERIALIZABLE); } -static gboolean astal_river_river_initable_init (GInitable *initable, GCancellable *cancellable, GError **error) { - AstalRiverRiver *self = ASTAL_RIVER_RIVER (initable); - AstalRiverRiverPrivate *priv = astal_river_river_get_instance_private (self); +static gboolean astal_river_river_initable_init(GInitable* initable, GCancellable* cancellable, + GError** error) { + AstalRiverRiver* self = ASTAL_RIVER_RIVER(initable); + AstalRiverRiverPrivate* priv = astal_river_river_get_instance_private(self); priv->seat = NULL; priv->display = NULL; priv->river_status_manager = NULL; - priv->signal_ids = g_hash_table_new (g_direct_hash, g_direct_equal); + priv->signal_ids = g_hash_table_new(g_direct_hash, g_direct_equal); priv->wl_source = wl_source_new(NULL, NULL); if (priv->wl_source == NULL) { - g_set_error_literal(error, G_IO_ERROR, G_IO_ERROR_FAILED, "Can not connect to wayland display"); + g_set_error_literal(error, G_IO_ERROR, G_IO_ERROR_FAILED, + "Can not connect to wayland display"); return FALSE; } @@ -317,58 +301,53 @@ static gboolean astal_river_river_initable_init (GInitable *initable, GCancellab wl_display_roundtrip(priv->display); if (priv->river_status_manager == NULL) { - g_set_error_literal(error, G_IO_ERROR, G_IO_ERROR_FAILED, "Can not connect river status protocol"); + g_set_error_literal(error, G_IO_ERROR, G_IO_ERROR_FAILED, + "Can not connect river status protocol"); return FALSE; } - priv->river_seat_status = zriver_status_manager_v1_get_river_seat_status( - priv->river_status_manager, priv->seat); - zriver_seat_status_v1_add_listener( - priv->river_seat_status, &river_seat_status_listener, self); + priv->river_seat_status = + zriver_status_manager_v1_get_river_seat_status(priv->river_status_manager, priv->seat); + zriver_seat_status_v1_add_listener(priv->river_seat_status, &river_seat_status_listener, self); wl_display_roundtrip(priv->display); return TRUE; } -static void astal_river_river_initable_iface_init (GInitableIface *iface) { +static void astal_river_river_initable_iface_init(GInitableIface* iface) { iface->init = astal_river_river_initable_init; } -static void astal_river_river_init(AstalRiverRiver *self) { - self->outputs = NULL; -} +static void astal_river_river_init(AstalRiverRiver* self) { self->outputs = NULL; } -AstalRiverRiver *astal_river_river_new() { +AstalRiverRiver* astal_river_river_new() { return g_initable_new(ASTAL_RIVER_TYPE_RIVER, NULL, NULL, NULL); } -static void disconnect_signal (gpointer key, gpointer value, gpointer user_data) { - AstalRiverRiver *self = ASTAL_RIVER_RIVER(user_data); - AstalRiverRiverPrivate *priv = astal_river_river_get_instance_private (self); +static void disconnect_signal(gpointer key, gpointer value, gpointer user_data) { + AstalRiverRiver* self = ASTAL_RIVER_RIVER(user_data); - AstalRiverOutput *output = find_output_by_id (self, GPOINTER_TO_UINT(key)); - g_signal_handler_disconnect (output, GPOINTER_TO_UINT(value)); + AstalRiverOutput* output = find_output_by_id(self, GPOINTER_TO_UINT(key)); + g_signal_handler_disconnect(output, GPOINTER_TO_UINT(value)); } AstalRiverRiver* astal_river_river_get_default() { - static AstalRiverRiver *self = NULL; + static AstalRiverRiver* self = NULL; - if (self == NULL) - self = astal_river_river_new(); + if (self == NULL) self = astal_river_river_new(); - return self; + return self; } -static void astal_river_river_finalize(GObject *object) { - - AstalRiverRiver *self = ASTAL_RIVER_RIVER(object); - AstalRiverRiverPrivate *priv = astal_river_river_get_instance_private(self); +static void astal_river_river_finalize(GObject* object) { + AstalRiverRiver* self = ASTAL_RIVER_RIVER(object); + AstalRiverRiverPrivate* priv = astal_river_river_get_instance_private(self); - g_hash_table_foreach (priv->signal_ids, disconnect_signal, self); - g_hash_table_destroy (priv->signal_ids); + g_hash_table_foreach(priv->signal_ids, disconnect_signal, self); + g_hash_table_destroy(priv->signal_ids); - wl_display_roundtrip (priv->display); + wl_display_roundtrip(priv->display); g_clear_list(&self->outputs, g_object_unref); self->outputs = NULL; @@ -385,76 +364,34 @@ static void astal_river_river_finalize(GObject *object) { g_free(self->focused_output); g_free(self->mode); - - G_OBJECT_CLASS (astal_river_river_parent_class)->finalize(object); + G_OBJECT_CLASS(astal_river_river_parent_class)->finalize(object); } -static void astal_river_river_class_init(AstalRiverRiverClass *class) { - - GObjectClass *object_class = G_OBJECT_CLASS (class); +static void astal_river_river_class_init(AstalRiverRiverClass* class) { + GObjectClass* object_class = G_OBJECT_CLASS(class); object_class->get_property = astal_river_river_get_property; object_class->finalize = astal_river_river_finalize; astal_river_river_properties[ASTAL_RIVER_RIVER_PROP_MODE] = - g_param_spec_string("mode", - "mode", - "currently active mode", - NULL, - G_PARAM_READABLE); - astal_river_river_properties[ASTAL_RIVER_RIVER_PROP_FOCUSED_VIEW] = - g_param_spec_string("focused-view", - "focused-view", - "currently focused view", - NULL, - G_PARAM_READABLE); - astal_river_river_properties[ASTAL_RIVER_RIVER_PROP_FOCUSED_OUTPUT] = - g_param_spec_string("focused-output", - "focused-output", - "currently focused-output", - NULL, - G_PARAM_READABLE); + g_param_spec_string("mode", "mode", "currently active mode", NULL, G_PARAM_READABLE); + astal_river_river_properties[ASTAL_RIVER_RIVER_PROP_FOCUSED_VIEW] = g_param_spec_string( + "focused-view", "focused-view", "currently focused view", NULL, G_PARAM_READABLE); + astal_river_river_properties[ASTAL_RIVER_RIVER_PROP_FOCUSED_OUTPUT] = g_param_spec_string( + "focused-output", "focused-output", "currently focused-output", NULL, G_PARAM_READABLE); astal_river_river_properties[ASTAL_RIVER_RIVER_PROP_OUTPUTS] = - g_param_spec_pointer("outputs", - "outputs", - "a list of all outputs", - G_PARAM_READABLE); + g_param_spec_pointer("outputs", "outputs", "a list of all outputs", G_PARAM_READABLE); - g_object_class_install_properties(object_class, - ASTAL_RIVER_RIVER_N_PROPERTIES, + g_object_class_install_properties(object_class, ASTAL_RIVER_RIVER_N_PROPERTIES, astal_river_river_properties); - astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_OUTPUT_ADDED] = - g_signal_new("output-added", - G_TYPE_FROM_CLASS(class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, - NULL, - NULL, - G_TYPE_NONE, - 1, - G_TYPE_STRING); + g_signal_new("output-added", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL, + NULL, G_TYPE_NONE, 1, G_TYPE_STRING); astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_OUTPUT_REMOVED] = - g_signal_new("output-removed", - G_TYPE_FROM_CLASS(class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, - NULL, - NULL, - G_TYPE_NONE, - 1, - G_TYPE_STRING); + g_signal_new("output-removed", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL, + NULL, G_TYPE_NONE, 1, G_TYPE_STRING); astal_river_river_signals[ASTAL_RIVER_RIVER_SIGNAL_CHANGED] = - g_signal_new("changed", - G_TYPE_FROM_CLASS(class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, - NULL, - NULL, - G_TYPE_NONE, - 0); + g_signal_new("changed", G_TYPE_FROM_CLASS(class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, + G_TYPE_NONE, 0); } diff --git a/src/wayland-source.c b/src/wayland-source.c index d984c2e..516fc0c 100644 --- a/src/wayland-source.c +++ b/src/wayland-source.c @@ -1,8 +1,9 @@ +#include "wayland-source.h" + #include <errno.h> #include <glib.h> #include <wayland-client.h> -#include "wayland-source.h" struct _WLSource { GSource source; @@ -11,8 +12,7 @@ struct _WLSource { int error; }; -static gboolean wl_source_prepare(GSource *source, - gint *timeout) { +static gboolean wl_source_prepare(GSource *source, gint *timeout) { WLSource *self = (WLSource *)source; *timeout = 0; @@ -29,25 +29,20 @@ static gboolean wl_source_prepare(GSource *source, static gboolean wl_source_check(GSource *source) { WLSource *self = (WLSource *)source; - if (self->error > 0) - return TRUE; + 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 + 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) { +static gboolean wl_source_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) { WLSource *self = (WLSource *)source; GIOCondition revents; @@ -55,14 +50,12 @@ static gboolean wl_source_dispatch(GSource *source, if ((self->error > 0) || (revents & (G_IO_ERR | G_IO_HUP))) { errno = self->error; self->error = 0; - if ( callback != NULL ) - return callback(user_data); + 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); + if (callback != NULL) return callback(user_data); return G_SOURCE_REMOVE; } @@ -75,27 +68,25 @@ static void wl_source_finalize(GSource *source) { } static GSourceFuncs wl_source_funcs = { - .prepare = wl_source_prepare, - .check = wl_source_check, + .prepare = wl_source_prepare, + .check = wl_source_check, .dispatch = wl_source_dispatch, .finalize = wl_source_finalize, }; -WLSource* wl_source_new() { +WLSource *wl_source_new() { struct wl_display *display; WLSource *self; GSource *source; display = wl_display_connect(NULL); - if (display == NULL) - return 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), + 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); @@ -104,11 +95,9 @@ WLSource* wl_source_new() { } void wl_source_free(WLSource *self) { - GSource * source = (GSource *)self; + GSource *source = (GSource *)self; g_source_destroy(source); g_source_unref(source); } -struct wl_display* wl_source_get_display(WLSource *self) { - return self->display; -} +struct wl_display *wl_source_get_display(WLSource *self) { return self->display; } |