swc

(Pinephone) swc with touch and other mobile stuff
git clone git://git.nihaljere.xyz/swc
Log | Files | Refs | README | LICENSE

commit c3e378fdf0833b4cf6593937bdc4501f167a7626
parent df5b490ea100f19173d8e116a30b6a41d7c4bb1d
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Tue, 30 May 2023 21:06:33 -0500

sleep timeout

Diffstat:
Alibswc/input_timeout.c | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Alibswc/input_timeout.h | 7+++++++
Mlibswc/internal.h | 1+
Mlibswc/swc.c | 38+++++++++++++++++++++++---------------
Mlibswc/swc.h | 6++++++
5 files changed, 104 insertions(+), 15 deletions(-)

diff --git a/libswc/input_timeout.c b/libswc/input_timeout.c @@ -0,0 +1,67 @@ +#include "input_timeout.h" +#include "internal.h" +#include "seat.h" +#include "touch.h" +#include "util.h" + +#include <stdbool.h> +#include <stdlib.h> + +// we need handlers for all events that will reset the input_timeout +bool +touch_down_handler(struct touch_handler *handler, uint32_t time, int32_t slot, wl_fixed_t x, wl_fixed_t y) { + wl_event_source_timer_update(swc.input_timeout->source, swc.input_timeout->timeout); + return false; +} + +static struct touch_handler touch_handler = { + .down = touch_down_handler +}; + +EXPORT void +swc_input_timeout_set(int ms) +{ + swc.input_timeout->timeout = ms; + if (swc.input_timeout && swc.input_timeout->source) + wl_event_source_timer_update(swc.input_timeout->source, ms); +} + +EXPORT int +swc_input_timeout_set_handler(int (*handler)(void *data), void *data) +{ + if (swc.input_timeout->source) { + wl_event_source_remove(swc.input_timeout->source); + } + + swc.input_timeout->source = wl_event_loop_add_timer(swc.event_loop, handler, data); + return !!swc.input_timeout->source; +} + +int +default_handler(void *data) +{ + fprintf(stderr, "Got here\n"); + return 0; +} + +struct input_timeout * +input_timeout_initialize() +{ + swc.input_timeout = calloc(1, sizeof(*swc.input_timeout)); + if (!swc.input_timeout) + return NULL; + + if (!swc_input_timeout_set_handler(&default_handler, NULL)) { + free(swc.input_timeout); + return NULL; + } + + wl_list_insert(&swc.seat->touch->handlers, &touch_handler.link); + return swc.input_timeout; +} + +void +input_timeout_finalize() +{ + free(swc.input_timeout); +} diff --git a/libswc/input_timeout.h b/libswc/input_timeout.h @@ -0,0 +1,7 @@ +struct input_timeout { + int timeout; + struct wl_event_source *source; +}; + +struct input_timeout *input_timeout_initialize(); +void input_timeout_finalize(); diff --git a/libswc/internal.h b/libswc/internal.h @@ -41,6 +41,7 @@ struct swc { struct swc_seat *seat; const struct swc_bindings *const bindings; + struct input_timeout *input_timeout; struct wl_list screens; struct swc_compositor *const compositor; struct swc_shm *shm; diff --git a/libswc/swc.c b/libswc/swc.c @@ -28,6 +28,7 @@ #include "drm.h" #include "event.h" #include "input_method.h" +#include "input_timeout.h" #include "internal.h" #include "launch.h" #include "kde_decoration.h" @@ -171,52 +172,57 @@ swc_initialize(struct wl_display *display, struct wl_event_loop *event_loop, con goto error8; } + if (!input_timeout_initialize()) { + ERROR("Could not initialize input timeout\n"); + goto error9; + } + swc.input_method_manager = input_method_manager_create(display); if (!swc.input_method_manager) { ERROR("Could not initialize input method manager\n"); - goto error9; + goto error10; } swc.text_input_manager = text_input_manager_create(display); if (!swc.text_input_manager) { ERROR("Could not initialize text input manager\n"); - goto error10; + goto error11; } swc.shell = shell_create(display); if (!swc.shell) { ERROR("Could not initialize shell\n"); - goto error11; + goto error12; } swc.xdg_shell = xdg_shell_create(display); if (!swc.xdg_shell) { ERROR("Could not initialize XDG shell\n"); - goto error12; + goto error13; } swc.xdg_decoration_manager = xdg_decoration_manager_create(display); if (!swc.xdg_decoration_manager) { ERROR("Could not initialize XDG decoration manager\n"); - goto error13; + goto error14; } swc.kde_decoration_manager = kde_decoration_manager_create(display); if (!swc.kde_decoration_manager) { ERROR("Could not initialize KDE decoration manager\n"); - goto error14; + goto error15; } swc.panel_manager = panel_manager_create(display); if (!swc.panel_manager) { ERROR("Could not initialize panel manager\n"); - goto error15; + goto error16; } #ifdef ENABLE_XWAYLAND if (!xserver_initialize()) { ERROR("Could not initialize xwayland\n"); - goto error16; + goto error17; } #endif @@ -225,21 +231,23 @@ swc_initialize(struct wl_display *display, struct wl_event_loop *event_loop, con return true; #ifdef ENABLE_XWAYLAND -error16: +error17: wl_global_destroy(swc.panel_manager); #endif -error15: +error16: wl_global_destroy(swc.kde_decoration_manager); -error14: +error15: wl_global_destroy(swc.xdg_decoration_manager); -error13: +error14: wl_global_destroy(swc.xdg_shell); -error12: +error13: wl_global_destroy(swc.shell); -error11: +error12: wl_global_destroy(swc.text_input_manager); -error10: +error11: wl_global_destroy(swc.input_method_manager); +error10: + input_timeout_finalize(); error9: seat_destroy(swc.seat); error8: diff --git a/libswc/swc.h b/libswc/swc.h @@ -299,6 +299,12 @@ int swc_add_binding(enum swc_binding_type type, uint32_t modifiers, uint32_t val /* }}} */ +/* Input timeout {{{ */ +void swc_input_timeout_set(int ms); + +int swc_input_timeout_set_handler(int (*handler)(void *data), void *data); +/* }}} */ + /** * This is a user-provided structure that swc will use to notify the display * server of new windows, screens and input devices.