Exit on click

This commit is contained in:
Midgard 2022-09-07 21:50:25 +02:00
parent 2610fb1cf2
commit ac272a754e
Signed by: midgard
GPG key ID: 511C112F1331BBB4

View file

@ -117,14 +117,17 @@ struct user_request {
struct client_state {
struct user_request user_request;
/* Globals */
struct wl_display *wl_display;
struct wl_registry *wl_registry;
struct wl_display *wl_display;
struct wl_shm *wl_shm;
struct wl_compositor *wl_compositor;
struct wl_seat *wl_seat;
/* Objects */
struct zwlr_layer_shell_v1 *layer_shell;
struct wl_surface *wl_surface;
struct zwlr_layer_surface_v1 *zwlr_surface;
bool stop;
};
static void
@ -235,6 +238,7 @@ draw_frame(struct client_state *state, const int width, const int height)
munmap(data, size);
wl_buffer_add_listener(buffer, &wl_buffer_listener, NULL);
return buffer;
}
@ -255,6 +259,46 @@ static const struct zwlr_layer_surface_v1_listener zwlr_layer_surface_listener =
.configure = zwlr_layer_surface_configure,
};
static void
wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
uint32_t serial, uint32_t time, uint32_t button, uint32_t button_state)
{
struct client_state *state = data;
state->stop = true;
}
void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y) {}
void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer,
uint32_t serial, struct wl_surface *surface) {}
void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {}
void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
uint32_t time, uint32_t axis, wl_fixed_t value) {}
void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) {}
void wl_pointer_axis_source(void *data, struct wl_pointer *wl_pointer,
uint32_t axis_source) {}
void wl_pointer_axis_stop(void *data, struct wl_pointer *wl_pointer,
uint32_t time, uint32_t axis) {}
void wl_pointer_axis_discrete(void *data, struct wl_pointer *wl_pointer,
uint32_t axis, int32_t discrete) {}
void wl_pointer_axis_value120(void *data, struct wl_pointer *wl_pointer,
uint32_t axis, int32_t value120) {}
static const struct wl_pointer_listener wl_pointer_listener = {
.button = wl_pointer_button,
.enter = wl_pointer_enter,
.leave = wl_pointer_leave,
.motion = wl_pointer_motion,
.axis = wl_pointer_axis,
.frame = wl_pointer_frame,
.axis_source = wl_pointer_axis_source,
.axis_stop = wl_pointer_axis_stop,
.axis_discrete = wl_pointer_axis_discrete,
.axis_value120 = wl_pointer_axis_value120,
};
static void
registry_global(void *data, struct wl_registry *wl_registry,
uint32_t name, const char *interface, uint32_t version)
@ -270,7 +314,11 @@ registry_global(void *data, struct wl_registry *wl_registry,
} else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == STR_EQUAL) {
state->layer_shell = wl_registry_bind(
wl_registry, name, &zwlr_layer_shell_v1_interface, 1);
wl_registry, name, &zwlr_layer_shell_v1_interface, 1);
} else if (strcmp(interface, wl_seat_interface.name) == STR_EQUAL) {
state->wl_seat = wl_registry_bind(
wl_registry, name, &wl_seat_interface, 7);
}
}
@ -287,6 +335,8 @@ static const struct wl_registry_listener wl_registry_listener = {
};
static void
parse_hex(char *hex, struct color_argb *result_color) {
if (strlen(hex) != 4 * 2) {
@ -417,12 +467,20 @@ main(int argc, char *argv[])
zwlr_layer_surface_v1_add_listener(state.zwlr_surface, &zwlr_layer_surface_listener, &state);
struct wl_pointer *pointer = wl_seat_get_pointer(state.wl_seat);
wl_pointer_add_listener(pointer, &wl_pointer_listener, &state);
wl_surface_commit(state.wl_surface);
while (wl_display_dispatch(state.wl_display)) {
while (wl_display_dispatch(state.wl_display) && !state.stop) {
/* This space deliberately left blank */
}
if (state.wl_surface != NULL) {
wl_surface_destroy(state.wl_surface);
state.wl_surface = NULL;
}
free(state.user_request.graphics_filename);
if (state.user_request.text != NULL) {
free(state.user_request.text);