summaryrefslogtreecommitdiff
path: root/src/common/input.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-13 23:41:31 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-13 23:41:31 +0300
commit76073fe5fad8799e5850805f2f090af2cb62c741 (patch)
tree9658019babe4760a3634bdab4da0731a10e42e68 /src/common/input.c
parentdd1775a9927922c14f8679ccbc4d3ca8d5917e20 (diff)
Simplify the public event and CPU API
Applications now need far less ceremony: hello.c is a 20-line loop that handles REFRESH, CLOSE and QUIT and draws into the surface's own pixels. - Fold GEOMETRY, STATE and FOCUS into one WINDOW event carrying size, scale and state; unchanged values send nothing. - Guarantee REFRESH once a window has a size and after every resize, never at size zero. - Merge DROP_HOVER into DROP with over/leave/data actions and give drag and drop actions enums. - Keep event strings valid until the next wait and drop yasl_event_release; empty or failed waits report NONE. - Replace copy-in presentation with a lent pixel buffer: yasl_cpu_pixels and yasl_cpu_present. - Remove yasl_poll_event, yasl_cpu_read_pixels, unused event fields and comments that restated names. - Wayland: resize floating windows in request_size instead of reporting it unsupported, and stop marking new GPU surfaces as Vulkan so yasl_vulkan_create_surface no longer fails with NATIVE_WINDOW_IN_USE. Also includes the in-progress public API refactor that was uncommitted in the tree (removal of the app/loop layer, new surface, GL and Vulkan entry points). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'src/common/input.c')
-rw-r--r--src/common/input.c51
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);