diff options
Diffstat (limited to 'src/wlstate.cc')
| -rw-r--r-- | src/wlstate.cc | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/src/wlstate.cc b/src/wlstate.cc index da5e555..5233868 100644 --- a/src/wlstate.cc +++ b/src/wlstate.cc @@ -1,13 +1,15 @@ #include "wlstate.h" -#include "utils.h" -#include "xdg-shell.h" + #include <poll.h> #include <string.h> #include <wayland-client-protocol.h> +#include "utils.h" +#include "xdg-shell.h" + #define WAYC_VERSION 1 -static void wayc_xdg_wm_base_pong(void *data, struct xdg_wm_base *wm_base, +static void wayc_xdg_wm_base_pong(void* data, struct xdg_wm_base* wm_base, u32 serial) { (void)data; xdg_wm_base_pong(wm_base, serial); @@ -17,15 +19,15 @@ static struct xdg_wm_base_listener WAYC_XDG_WM_BASE_LISTENER = { wayc_xdg_wm_base_pong, }; -static void wayc_registry_add(void *data, struct wl_registry *registry, - u32 name, const char *interface, u32 version) { +static void wayc_registry_add(void* data, struct wl_registry* registry, + u32 name, const char* interface, u32 version) { (void)version; wayc_notnull(data); wayc_notnull(registry); wayc_notnull(interface); - struct wlstate_s *state = (struct wlstate_s *)data; + struct wlstate_s* state = (struct wlstate_s*)data; if (!strcmp(interface, wl_compositor_interface.name)) { wl_compositor_t compositor = (wl_compositor_t)wl_registry_bind( @@ -45,7 +47,7 @@ static void wayc_registry_add(void *data, struct wl_registry *registry, } } -static void wayc_registry_remove(void *data, struct wl_registry *registry, +static void wayc_registry_remove(void* data, struct wl_registry* registry, u32 name) { wayc_notnull(data); wayc_notnull(registry); @@ -58,24 +60,23 @@ static struct wl_registry_listener WAYC_REGISTRY_LISTENER = { wayc_registry_remove, }; -bool wayc_wlstate_init(struct wlstate_s *state) { +enum wlstate_error_e wayc_wlstate_init(struct wlstate_s* state) { wayc_notnull(state); memset(state, 0, sizeof(*state)); wl_display_t display = wl_display_connect(NULL); - if (display == NULL) - return false; + if (display == NULL) return WLSTATE_ERROR_CONNECTION; i32 eventfd = wl_display_get_fd(display); if (eventfd == -1) { wl_display_disconnect(display); - return false; + return WLSTATE_ERROR_CONNECTION; } wl_registry_t registry = wl_display_get_registry(display); if (registry == NULL) { wl_display_disconnect(display); - return false; + return WLSTATE_ERROR_REGISTRY; } wl_registry_add_listener(registry, &WAYC_REGISTRY_LISTENER, state); @@ -85,14 +86,13 @@ bool wayc_wlstate_init(struct wlstate_s *state) { state->registry = registry; state->eventfd = eventfd; - return true; + return WLSTATE_ERROR_NONE; } -void wayc_wlstate_deinit(struct wlstate_s *state) { +void wayc_wlstate_deinit(struct wlstate_s* state) { wayc_notnull(state); - if (state->display == nullptr) - return; + if (state->display == nullptr) return; wl_display_disconnect(state->display); state->display = nullptr; @@ -102,7 +102,7 @@ void wayc_wlstate_deinit(struct wlstate_s *state) { state->eventfd = -1; } -void wayc_wlstate_update(struct wlstate_s *state) { +void wayc_wlstate_update(struct wlstate_s* state) { wayc_notnull(state); struct pollfd pfd = { @@ -112,13 +112,10 @@ void wayc_wlstate_update(struct wlstate_s *state) { }; i32 rc = poll(&pfd, 1, 0); - if (rc == -1) - wayc_panic("Failed to poll Wayland eventfd"); + if (rc == -1) wayc_panic("Failed to poll Wayland eventfd"); - if (!(pfd.revents & POLLIN)) - return; + if (!(pfd.revents & POLLIN)) return; rc = wl_display_dispatch(state->display); - if (rc == -1) - wayc_panic("Failed to dispatch Wayland events"); + if (rc == -1) wayc_panic("Failed to dispatch Wayland events"); } |
