diff options
Diffstat (limited to 'src/common/input.c')
| -rw-r--r-- | src/common/input.c | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/src/common/input.c b/src/common/input.c index 511cd0a..338ed2d 100644 --- a/src/common/input.c +++ b/src/common/input.c @@ -1,29 +1,29 @@ #include "input.h" -#include "yasl/loop.h" +#include "common/private_loop.h" #include <stdlib.h> #include <string.h> -static bool has_text(const struct yasl_event *ev) +static bool has_text(const struct yasl_private_event *ev) { - return ev->type == YASL_EVENT_TEXT || ev->type == YASL_EVENT_PASTE || - ev->type == YASL_EVENT_DROP; + return ev->type == YASL_PRIVATE_EVENT_TEXT || ev->type == YASL_PRIVATE_EVENT_PASTE || + ev->type == YASL_PRIVATE_EVENT_DROP || ev->type == YASL_PRIVATE_EVENT_TEXT_EDIT; } static void discard_pending(struct input_queue *q) { for (size_t i = 0; i < q->count; i++) { - struct yasl_event *ev = &q->events[(q->head + i) & (q->capacity - 1)]; + struct yasl_private_event *ev = &q->events[(q->head + i) & (q->capacity - 1)]; if (has_text(ev)) free((void *)ev->text.data); } q->head = q->count = 0; } -bool input_queue_push(struct input_queue *q, const struct yasl_event *ev) +bool input_queue_push(struct input_queue *q, const struct yasl_private_event *ev) { - struct yasl_event copy = *ev; + struct yasl_private_event copy = *ev; char *owned = NULL; - if (!copy.time_ns) copy.time_ns = yasl_loop_now_ns(); + if (!copy.time_ns) copy.time_ns = yasl_private_loop_now_ns(); if (has_text(ev) && !q->publish) { size_t len = ev->text.len; if ((!ev->text.data && len) || len == SIZE_MAX) goto failed; @@ -31,42 +31,43 @@ bool input_queue_push(struct input_queue *q, const struct yasl_event *ev) if (!owned) goto failed; if (len) memcpy(owned, ev->text.data, len); owned[len] = '\0'; - if (ev->type == YASL_EVENT_PASTE) copy.paste.data = owned; + if (ev->type == YASL_PRIVATE_EVENT_PASTE) copy.paste.data = owned; + else if (ev->type == YASL_PRIVATE_EVENT_TEXT_EDIT) copy.text_edit.data = owned; else copy.text.data = owned; } uint32_t buttons = q->buttons; switch (ev->type) { - case YASL_EVENT_POINTER_MOTION: + case YASL_PRIVATE_EVENT_POINTER_MOTION: if (!q->relative) { copy.pointer.delta = q->has_last_pos - ? (struct yasl_vector2d){ev->pointer.pos.x - q->last_pos.x, + ? (struct yasl_private_vector2d){ev->pointer.pos.x - q->last_pos.x, ev->pointer.pos.y - q->last_pos.y} - : (struct yasl_vector2d){0, 0}; + : (struct yasl_private_vector2d){0, 0}; } q->last_pos = ev->pointer.pos; q->has_last_pos = true; break; - case YASL_EVENT_POINTER_DOWN: - case YASL_EVENT_POINTER_UP: + case YASL_PRIVATE_EVENT_POINTER_DOWN: + case YASL_PRIVATE_EVENT_POINTER_UP: if ((unsigned)ev->pointer.button < 32) { - uint32_t bit = YASL_BUTTON_BIT(ev->pointer.button); - buttons = ev->type == YASL_EVENT_POINTER_DOWN ? buttons | bit : buttons & ~bit; + uint32_t bit = YASL_PRIVATE_BUTTON_BIT(ev->pointer.button); + buttons = ev->type == YASL_PRIVATE_EVENT_POINTER_DOWN ? buttons | bit : buttons & ~bit; } q->last_pos = ev->pointer.pos; q->has_last_pos = true; break; - case YASL_EVENT_POINTER_LEAVE: + case YASL_PRIVATE_EVENT_POINTER_LEAVE: if (q->leave_ends_press) buttons = 0; q->has_last_pos = false; break; - case YASL_EVENT_INPUT_RESET: + case YASL_PRIVATE_EVENT_INPUT_RESET: buttons = 0; q->has_last_pos = false; break; default: break; } - if (ev->type >= YASL_EVENT_POINTER_DOWN && ev->type <= YASL_EVENT_POINTER_LEAVE) + if (ev->type >= YASL_PRIVATE_EVENT_POINTER_DOWN && ev->type <= YASL_PRIVATE_EVENT_POINTER_LEAVE) copy.pointer.buttons = buttons; if (q->publish) { q->buttons = buttons; @@ -76,7 +77,7 @@ bool input_queue_push(struct input_queue *q, const struct yasl_event *ev) size_t capacity = q->capacity ? q->capacity * 2 : 32; if (capacity < q->capacity || capacity > SIZE_MAX / sizeof(*q->events)) goto failed; - struct yasl_event *events = malloc(capacity * sizeof(*events)); + struct yasl_private_event *events = malloc(capacity * sizeof(*events)); if (!events) goto failed; if (q->events && q->count > 0) { size_t first = q->capacity - q->head; @@ -107,7 +108,7 @@ failed: return false; } -bool input_queue_pop(struct input_queue *q, struct yasl_event *ev) +bool input_queue_pop(struct input_queue *q, struct yasl_private_event *ev) { if (!ev || (!q->count && !q->reset_pending)) return false; if (q->last_text) { @@ -115,9 +116,9 @@ bool input_queue_pop(struct input_queue *q, struct yasl_event *ev) q->last_text = NULL; } if (q->reset_pending) { - *ev = (struct yasl_event){ - .type = YASL_EVENT_INPUT_RESET, .surface = q->reset_surface, - .time_ns = yasl_loop_now_ns(), + *ev = (struct yasl_private_event){ + .type = YASL_PRIVATE_EVENT_INPUT_RESET, .surface = q->reset_surface, + .time_ns = yasl_private_loop_now_ns(), }; q->reset_pending = false; return true; @@ -132,7 +133,7 @@ bool input_queue_pop(struct input_queue *q, struct yasl_event *ev) void input_queue_clear(struct input_queue *q) { - bool (*publish)(const struct yasl_event *, void *) = q->publish; + bool (*publish)(const struct yasl_private_event *, void *) = q->publish; void *publish_ud = q->publish_ud; discard_pending(q); free(q->last_text); |
