diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 13:44:13 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 13:44:13 +0300 |
| commit | c059e3aa7f93da470f052a5cd8ee0d8dc969e679 (patch) | |
| tree | 63ffa378287ed2c606eda2e940501b9edc3d2b8b /src/common | |
| parent | 87d0bc50d53dc216efb2b04495f090616318bc5c (diff) | |
rename and simplification
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/app.c | 28 | ||||
| -rw-r--r-- | src/common/backend.c | 17 | ||||
| -rw-r--r-- | src/common/backend.h | 10 | ||||
| -rw-r--r-- | src/common/keyboard.c | 399 | ||||
| -rw-r--r-- | src/common/keyboard.h | 4 | ||||
| -rw-r--r-- | src/common/loop.c | 429 | ||||
| -rw-r--r-- | src/common/meson.build | 2 | ||||
| -rw-r--r-- | src/common/native.c | 38 |
8 files changed, 36 insertions, 891 deletions
diff --git a/src/common/app.c b/src/common/app.c index 1916c5b..da9747d 100644 --- a/src/common/app.c +++ b/src/common/app.c @@ -1,8 +1,9 @@ #include "yasl/app.h" #include "common/app_internal.h" #include "common/backend.h" +#include "platform/sync.h" -#include <pthread.h> +#include <errno.h> #include <stdlib.h> #include <string.h> @@ -38,7 +39,7 @@ struct app_runner { int surface_count; struct app_surface *surfaces; - pthread_mutex_t user_event_mutex; + yasl_mutex user_event_mutex; struct user_event_node *user_event_head; struct user_event_node *user_event_tail; }; @@ -158,7 +159,7 @@ void app_runner_register_surface(void *runner, struct yasl_surface *s) ar->surface_count++; ar->had_surfaces = true; - struct yasl_surface_cbs cbs = { + struct yasl_window_cbs cbs = { .draw = app_runner_surface_draw, .configure = app_runner_surface_configure, .close = app_runner_surface_close, @@ -264,7 +265,7 @@ bool yasl_post_event(struct yasl_display *d, struct yasl_surface *s, node->size = size; node->next = NULL; - pthread_mutex_lock(&ar->user_event_mutex); + yasl_mutex_lock(&ar->user_event_mutex); if (ar->user_event_tail) { ar->user_event_tail->next = node; ar->user_event_tail = node; @@ -272,7 +273,7 @@ bool yasl_post_event(struct yasl_display *d, struct yasl_surface *s, ar->user_event_head = node; ar->user_event_tail = node; } - pthread_mutex_unlock(&ar->user_event_mutex); + yasl_mutex_unlock(&ar->user_event_mutex); if (d->loop) { yasl_loop_kick(d->loop); @@ -312,11 +313,11 @@ void yasl_app_del_timer(struct yasl_display *d, yasl_timer_id id) static void app_runner_dispatch_user_events(struct app_runner *ar) { - pthread_mutex_lock(&ar->user_event_mutex); + yasl_mutex_lock(&ar->user_event_mutex); struct user_event_node *node = ar->user_event_head; ar->user_event_head = NULL; ar->user_event_tail = NULL; - pthread_mutex_unlock(&ar->user_event_mutex); + yasl_mutex_unlock(&ar->user_event_mutex); while (node && ar->running) { struct user_event_node *next = node->next; @@ -467,7 +468,12 @@ int yasl_run(const struct yasl_app_desc *desc) .surface_count = 0, .surfaces = NULL, }; - pthread_mutex_init(&runner.user_event_mutex, NULL); + int sync_error = yasl_mutex_init(&runner.user_event_mutex); + if (sync_error) { + yasl_display_close(d); + errno = sync_error; + return -1; + } d->app_runner = &runner; if (desc->init(desc->userdata, d) == YASL_APP_QUIT) { @@ -529,15 +535,15 @@ int yasl_run(const struct yasl_app_desc *desc) d->app_runner = NULL; - pthread_mutex_lock(&runner.user_event_mutex); + yasl_mutex_lock(&runner.user_event_mutex); struct user_event_node *node = runner.user_event_head; while (node) { struct user_event_node *next = node->next; free(node); node = next; } - pthread_mutex_unlock(&runner.user_event_mutex); - pthread_mutex_destroy(&runner.user_event_mutex); + yasl_mutex_unlock(&runner.user_event_mutex); + yasl_mutex_destroy(&runner.user_event_mutex); yasl_display_close(d); return 0; diff --git a/src/common/backend.c b/src/common/backend.c index e690697..be06136 100644 --- a/src/common/backend.c +++ b/src/common/backend.c @@ -152,7 +152,7 @@ void yasl_display_drag_cancel(struct yasl_display *d) } struct yasl_surface *yasl_create_toplevel(struct yasl_display *d, - const struct yasl_surface_spec *spec, void *graphics_device) + const struct yasl_window_spec *spec, void *graphics_device) { if (!d || !d->ops->surface_create_toplevel || !spec || spec->size.x <= 0 || spec->size.y <= 0 || @@ -168,14 +168,19 @@ struct yasl_surface *yasl_create_toplevel(struct yasl_display *d, errno = 0; struct yasl_surface *s = d->ops->surface_create_toplevel(d, spec, graphics_device); if (!s && !errno) errno = ENODEV; - if (s && d->app_runner) { - app_runner_register_surface(d->app_runner, s); + if (s) { + /* Native creation may dispatch events. Attach this window's callbacks + * only after it finishes, so callers can store the returned surface. */ + if (d->app_runner) + app_runner_register_surface(d->app_runner, s); + else + yasl_surface_set_callbacks(s, spec->cbs, spec->ud); } return s; } struct yasl_surface *yasl_surface_create_toplevel(struct yasl_display *d, - const struct yasl_surface_spec *spec) + const struct yasl_window_spec *spec) { return yasl_create_toplevel(d, spec, NULL); } @@ -246,11 +251,11 @@ struct yasl_display *yasl_surface_display(const struct yasl_surface *s) return s ? s->display : NULL; } -void yasl_surface_set_callbacks(struct yasl_surface *s, const struct yasl_surface_cbs *cbs, void *ud) +void yasl_surface_set_callbacks(struct yasl_surface *s, const struct yasl_window_cbs *cbs, void *ud) { if (!s) return; - s->callbacks = cbs ? *cbs : (struct yasl_surface_cbs){0}; + s->callbacks = cbs ? *cbs : (struct yasl_window_cbs){0}; s->ud = ud; if (s->display && s->display->ops && s->display->ops->surface_set_callbacks) s->display->ops->surface_set_callbacks(s, cbs, ud); diff --git a/src/common/backend.h b/src/common/backend.h index b93547a..37fa167 100644 --- a/src/common/backend.h +++ b/src/common/backend.h @@ -24,7 +24,7 @@ struct yasl_surface { uint32_t scale_120; uint32_t state; uint32_t bg_color; - struct yasl_surface_cbs callbacks; + struct yasl_window_cbs callbacks; void *ud; uint64_t frame_generation; struct input_queue input; @@ -38,7 +38,7 @@ struct yasl_surface { void yasl_surface_clear_timers(struct yasl_surface *s); struct yasl_surface *yasl_create_toplevel(struct yasl_display *d, - const struct yasl_surface_spec *spec, void *graphics_device); + const struct yasl_window_spec *spec, void *graphics_device); static inline uint64_t yasl_frame_begin(struct yasl_surface *s) { @@ -58,13 +58,15 @@ struct yasl_backend_ops { void (*display_paste)(struct yasl_display *d, enum yasl_selection sel, struct yasl_surface *target); bool (*display_drag_start)(struct yasl_display *d, struct yasl_surface *origin, const struct yasl_drag_image *image, const struct yasl_drag_listener *l, void *ud); void (*display_drag_cancel)(struct yasl_display *d); + /* Create with callbacks disabled; common code installs them after return. */ struct yasl_surface *(*surface_create_toplevel)(struct yasl_display *d, - const struct yasl_surface_spec *spec, void *graphics_device); + const struct yasl_window_spec *spec, void *graphics_device); struct yasl_surface *(*surface_create_popup)(struct yasl_surface *parent, const struct yasl_popup_spec *spec); bool (*surface_popup_reposition)(struct yasl_surface *popup, const struct yasl_popup_spec *spec); void (*surface_destroy)(struct yasl_surface *s); struct yasl_display *(*surface_display)(const struct yasl_surface *s); - void (*surface_set_callbacks)(struct yasl_surface *s, const struct yasl_surface_cbs *cbs, void *ud); + /* Copy only; must not invoke application callbacks. */ + void (*surface_set_callbacks)(struct yasl_surface *s, const struct yasl_window_cbs *cbs, void *ud); void (*surface_set_title)(struct yasl_surface *s, const char *title); void (*surface_schedule_redraw)(struct yasl_surface *s); bool (*surface_present)(struct yasl_surface *s, const struct yasl_framebuffer *fb, const struct yasl_damage_list *damage); diff --git a/src/common/keyboard.c b/src/common/keyboard.c deleted file mode 100644 index 80c6702..0000000 --- a/src/common/keyboard.c +++ /dev/null @@ -1,399 +0,0 @@ -#include "keyboard.h" -#include "cocoa/keycodes.h" -#include <string.h> - -/* Numeric Linux evdev codes; no platform headers are needed by this table. */ -enum yasl_key yasl_key_from_evdev(uint32_t code) -{ - switch (code) { - case 1: return YASL_KEY_ESCAPE; /* KEY_ESC */ - case 2: return YASL_KEY_1; /* KEY_1 */ - case 3: return YASL_KEY_2; /* KEY_2 */ - case 4: return YASL_KEY_3; /* KEY_3 */ - case 5: return YASL_KEY_4; /* KEY_4 */ - case 6: return YASL_KEY_5; /* KEY_5 */ - case 7: return YASL_KEY_6; /* KEY_6 */ - case 8: return YASL_KEY_7; /* KEY_7 */ - case 9: return YASL_KEY_8; /* KEY_8 */ - case 10: return YASL_KEY_9; /* KEY_9 */ - case 11: return YASL_KEY_0; /* KEY_0 */ - case 12: return YASL_KEY_MINUS; /* KEY_MINUS */ - case 13: return YASL_KEY_EQUAL; /* KEY_EQUAL */ - case 14: return YASL_KEY_BACKSPACE; /* KEY_BACKSPACE */ - case 15: return YASL_KEY_TAB; /* KEY_TAB */ - case 16: return YASL_KEY_Q; /* KEY_Q */ - case 17: return YASL_KEY_W; /* KEY_W */ - case 18: return YASL_KEY_E; /* KEY_E */ - case 19: return YASL_KEY_R; /* KEY_R */ - case 20: return YASL_KEY_T; /* KEY_T */ - case 21: return YASL_KEY_Y; /* KEY_Y */ - case 22: return YASL_KEY_U; /* KEY_U */ - case 23: return YASL_KEY_I; /* KEY_I */ - case 24: return YASL_KEY_O; /* KEY_O */ - case 25: return YASL_KEY_P; /* KEY_P */ - case 26: return YASL_KEY_LEFT_BRACKET; /* KEY_LEFTBRACE */ - case 27: return YASL_KEY_RIGHT_BRACKET; /* KEY_RIGHTBRACE */ - case 28: return YASL_KEY_ENTER; /* KEY_ENTER */ - case 29: return YASL_KEY_LEFT_CONTROL; /* KEY_LEFTCTRL */ - case 30: return YASL_KEY_A; /* KEY_A */ - case 31: return YASL_KEY_S; /* KEY_S */ - case 32: return YASL_KEY_D; /* KEY_D */ - case 33: return YASL_KEY_F; /* KEY_F */ - case 34: return YASL_KEY_G; /* KEY_G */ - case 35: return YASL_KEY_H; /* KEY_H */ - case 36: return YASL_KEY_J; /* KEY_J */ - case 37: return YASL_KEY_K; /* KEY_K */ - case 38: return YASL_KEY_L; /* KEY_L */ - case 39: return YASL_KEY_SEMICOLON; /* KEY_SEMICOLON */ - case 40: return YASL_KEY_APOSTROPHE; /* KEY_APOSTROPHE */ - case 41: return YASL_KEY_GRAVE; /* KEY_GRAVE */ - case 42: return YASL_KEY_LEFT_SHIFT; /* KEY_LEFTSHIFT */ - case 43: return YASL_KEY_BACKSLASH; /* KEY_BACKSLASH */ - case 44: return YASL_KEY_Z; /* KEY_Z */ - case 45: return YASL_KEY_X; /* KEY_X */ - case 46: return YASL_KEY_C; /* KEY_C */ - case 47: return YASL_KEY_V; /* KEY_V */ - case 48: return YASL_KEY_B; /* KEY_B */ - case 49: return YASL_KEY_N; /* KEY_N */ - case 50: return YASL_KEY_M; /* KEY_M */ - case 51: return YASL_KEY_COMMA; /* KEY_COMMA */ - case 52: return YASL_KEY_PERIOD; /* KEY_DOT */ - case 53: return YASL_KEY_SLASH; /* KEY_SLASH */ - case 54: return YASL_KEY_RIGHT_SHIFT; /* KEY_RIGHTSHIFT */ - case 55: return YASL_KEY_KP_MULTIPLY; /* KEY_KPASTERISK */ - case 56: return YASL_KEY_LEFT_ALT; /* KEY_LEFTALT */ - case 57: return YASL_KEY_SPACE; /* KEY_SPACE */ - case 58: return YASL_KEY_CAPS_LOCK; /* KEY_CAPSLOCK */ - case 59: return YASL_KEY_F1; /* KEY_F1 */ - case 60: return YASL_KEY_F2; /* KEY_F2 */ - case 61: return YASL_KEY_F3; /* KEY_F3 */ - case 62: return YASL_KEY_F4; /* KEY_F4 */ - case 63: return YASL_KEY_F5; /* KEY_F5 */ - case 64: return YASL_KEY_F6; /* KEY_F6 */ - case 65: return YASL_KEY_F7; /* KEY_F7 */ - case 66: return YASL_KEY_F8; /* KEY_F8 */ - case 67: return YASL_KEY_F9; /* KEY_F9 */ - case 68: return YASL_KEY_F10; /* KEY_F10 */ - case 69: return YASL_KEY_NUM_LOCK; /* KEY_NUMLOCK */ - case 70: return YASL_KEY_SCROLL_LOCK; /* KEY_SCROLLLOCK */ - case 71: return YASL_KEY_KP_7; /* KEY_KP7 */ - case 72: return YASL_KEY_KP_8; /* KEY_KP8 */ - case 73: return YASL_KEY_KP_9; /* KEY_KP9 */ - case 74: return YASL_KEY_KP_SUBTRACT; /* KEY_KPMINUS */ - case 75: return YASL_KEY_KP_4; /* KEY_KP4 */ - case 76: return YASL_KEY_KP_5; /* KEY_KP5 */ - case 77: return YASL_KEY_KP_6; /* KEY_KP6 */ - case 78: return YASL_KEY_KP_ADD; /* KEY_KPPLUS */ - case 79: return YASL_KEY_KP_1; /* KEY_KP1 */ - case 80: return YASL_KEY_KP_2; /* KEY_KP2 */ - case 81: return YASL_KEY_KP_3; /* KEY_KP3 */ - case 82: return YASL_KEY_KP_0; /* KEY_KP0 */ - case 83: return YASL_KEY_KP_DECIMAL; /* KEY_KPDOT */ - case 86: return YASL_KEY_ISO_BACKSLASH; /* KEY_102ND */ - case 87: return YASL_KEY_F11; /* KEY_F11 */ - case 88: return YASL_KEY_F12; /* KEY_F12 */ - case 89: return YASL_KEY_RO; /* KEY_RO */ - case 92: return YASL_KEY_CONVERT; /* KEY_HENKAN */ - case 93: return YASL_KEY_KANA; /* KEY_KATAKANAHIRAGANA */ - case 94: return YASL_KEY_NONCONVERT; /* KEY_MUHENKAN */ - case 96: return YASL_KEY_KP_ENTER; /* KEY_KPENTER */ - case 97: return YASL_KEY_RIGHT_CONTROL; /* KEY_RIGHTCTRL */ - case 98: return YASL_KEY_KP_DIVIDE; /* KEY_KPSLASH */ - case 99: return YASL_KEY_PRINT_SCREEN; /* KEY_SYSRQ */ - case 100: return YASL_KEY_RIGHT_ALT; /* KEY_RIGHTALT */ - case 102: return YASL_KEY_HOME; /* KEY_HOME */ - case 103: return YASL_KEY_UP; /* KEY_UP */ - case 104: return YASL_KEY_PAGE_UP; /* KEY_PAGEUP */ - case 105: return YASL_KEY_LEFT; /* KEY_LEFT */ - case 106: return YASL_KEY_RIGHT; /* KEY_RIGHT */ - case 107: return YASL_KEY_END; /* KEY_END */ - case 108: return YASL_KEY_DOWN; /* KEY_DOWN */ - case 109: return YASL_KEY_PAGE_DOWN; /* KEY_PAGEDOWN */ - case 110: return YASL_KEY_INSERT; /* KEY_INSERT */ - case 111: return YASL_KEY_DELETE; /* KEY_DELETE */ - case 113: return YASL_KEY_MUTE; /* KEY_MUTE */ - case 114: return YASL_KEY_VOLUME_DOWN; /* KEY_VOLUMEDOWN */ - case 115: return YASL_KEY_VOLUME_UP; /* KEY_VOLUMEUP */ - case 117: return YASL_KEY_KP_EQUAL; /* KEY_KPEQUAL */ - case 119: return YASL_KEY_PAUSE; /* KEY_PAUSE */ - case 121: return YASL_KEY_KP_COMMA; /* KEY_KPCOMMA */ - case 124: return YASL_KEY_YEN; /* KEY_YEN */ - case 125: return YASL_KEY_LEFT_SUPER; /* KEY_LEFTMETA */ - case 126: return YASL_KEY_RIGHT_SUPER; /* KEY_RIGHTMETA */ - case 127: return YASL_KEY_MENU; /* KEY_COMPOSE */ - case 183: return YASL_KEY_F13; /* KEY_F13 */ - case 184: return YASL_KEY_F14; /* KEY_F14 */ - case 185: return YASL_KEY_F15; /* KEY_F15 */ - case 186: return YASL_KEY_F16; /* KEY_F16 */ - case 187: return YASL_KEY_F17; /* KEY_F17 */ - case 188: return YASL_KEY_F18; /* KEY_F18 */ - case 189: return YASL_KEY_F19; /* KEY_F19 */ - case 190: return YASL_KEY_F20; /* KEY_F20 */ - case 191: return YASL_KEY_F21; /* KEY_F21 */ - case 192: return YASL_KEY_F22; /* KEY_F22 */ - case 193: return YASL_KEY_F23; /* KEY_F23 */ - case 194: return YASL_KEY_F24; /* KEY_F24 */ - default: return YASL_KEY_UNKNOWN; - } -} - -enum yasl_key yasl_key_from_cocoa(uint32_t code) -{ - switch (code) { - case kVK_ANSI_A: return YASL_KEY_A; - case kVK_ANSI_B: return YASL_KEY_B; - case kVK_ANSI_C: return YASL_KEY_C; - case kVK_ANSI_D: return YASL_KEY_D; - case kVK_ANSI_E: return YASL_KEY_E; - case kVK_ANSI_F: return YASL_KEY_F; - case kVK_ANSI_G: return YASL_KEY_G; - case kVK_ANSI_H: return YASL_KEY_H; - case kVK_ANSI_I: return YASL_KEY_I; - case kVK_ANSI_J: return YASL_KEY_J; - case kVK_ANSI_K: return YASL_KEY_K; - case kVK_ANSI_L: return YASL_KEY_L; - case kVK_ANSI_M: return YASL_KEY_M; - case kVK_ANSI_N: return YASL_KEY_N; - case kVK_ANSI_O: return YASL_KEY_O; - case kVK_ANSI_P: return YASL_KEY_P; - case kVK_ANSI_Q: return YASL_KEY_Q; - case kVK_ANSI_R: return YASL_KEY_R; - case kVK_ANSI_S: return YASL_KEY_S; - case kVK_ANSI_T: return YASL_KEY_T; - case kVK_ANSI_U: return YASL_KEY_U; - case kVK_ANSI_V: return YASL_KEY_V; - case kVK_ANSI_W: return YASL_KEY_W; - case kVK_ANSI_X: return YASL_KEY_X; - case kVK_ANSI_Y: return YASL_KEY_Y; - case kVK_ANSI_Z: return YASL_KEY_Z; - case kVK_ANSI_0: return YASL_KEY_0; - case kVK_ANSI_1: return YASL_KEY_1; - case kVK_ANSI_2: return YASL_KEY_2; - case kVK_ANSI_3: return YASL_KEY_3; - case kVK_ANSI_4: return YASL_KEY_4; - case kVK_ANSI_5: return YASL_KEY_5; - case kVK_ANSI_6: return YASL_KEY_6; - case kVK_ANSI_7: return YASL_KEY_7; - case kVK_ANSI_8: return YASL_KEY_8; - case kVK_ANSI_9: return YASL_KEY_9; - case kVK_Return: return YASL_KEY_ENTER; - case kVK_Tab: return YASL_KEY_TAB; - case kVK_Space: return YASL_KEY_SPACE; - case kVK_Escape: return YASL_KEY_ESCAPE; - case kVK_Home: return YASL_KEY_HOME; - case kVK_End: return YASL_KEY_END; - case kVK_Delete: return YASL_KEY_BACKSPACE; - case kVK_ForwardDelete: return YASL_KEY_DELETE; - case kVK_PageUp: return YASL_KEY_PAGE_UP; - case kVK_PageDown: return YASL_KEY_PAGE_DOWN; - case kVK_Help: return YASL_KEY_INSERT; - case kVK_LeftArrow: return YASL_KEY_LEFT; - case kVK_RightArrow: return YASL_KEY_RIGHT; - case kVK_DownArrow: return YASL_KEY_DOWN; - case kVK_UpArrow: return YASL_KEY_UP; - case kVK_Command: return YASL_KEY_LEFT_SUPER; - case kVK_Shift: return YASL_KEY_LEFT_SHIFT; - case kVK_CapsLock: return YASL_KEY_CAPS_LOCK; - case kVK_Option: return YASL_KEY_LEFT_ALT; - case kVK_Control: return YASL_KEY_LEFT_CONTROL; - case kVK_RightCommand: return YASL_KEY_RIGHT_SUPER; - case kVK_RightShift: return YASL_KEY_RIGHT_SHIFT; - case kVK_RightOption: return YASL_KEY_RIGHT_ALT; - case kVK_RightControl: return YASL_KEY_RIGHT_CONTROL; - case kVK_ContextualMenu: return YASL_KEY_MENU; - case kVK_VolumeUp: return YASL_KEY_VOLUME_UP; - case kVK_VolumeDown: return YASL_KEY_VOLUME_DOWN; - case kVK_Mute: return YASL_KEY_MUTE; - case kVK_ISO_Section: return YASL_KEY_ISO_BACKSLASH; - case kVK_JIS_Yen: return YASL_KEY_YEN; - case kVK_JIS_Underscore: return YASL_KEY_RO; - case kVK_JIS_Eisu: return YASL_KEY_EISU; - case kVK_JIS_Kana: return YASL_KEY_KANA; - case kVK_JIS_KeypadComma: return YASL_KEY_KP_COMMA; - case kVK_ANSI_Equal: return YASL_KEY_EQUAL; - case kVK_ANSI_Minus: return YASL_KEY_MINUS; - case kVK_ANSI_LeftBracket: return YASL_KEY_LEFT_BRACKET; - case kVK_ANSI_RightBracket: return YASL_KEY_RIGHT_BRACKET; - case kVK_ANSI_Quote: return YASL_KEY_APOSTROPHE; - case kVK_ANSI_Semicolon: return YASL_KEY_SEMICOLON; - case kVK_ANSI_Backslash: return YASL_KEY_BACKSLASH; - case kVK_ANSI_Comma: return YASL_KEY_COMMA; - case kVK_ANSI_Slash: return YASL_KEY_SLASH; - case kVK_ANSI_Period: return YASL_KEY_PERIOD; - case kVK_ANSI_Grave: return YASL_KEY_GRAVE; - case kVK_F1: return YASL_KEY_F1; - case kVK_F2: return YASL_KEY_F2; - case kVK_F3: return YASL_KEY_F3; - case kVK_F4: return YASL_KEY_F4; - case kVK_F5: return YASL_KEY_F5; - case kVK_F6: return YASL_KEY_F6; - case kVK_F7: return YASL_KEY_F7; - case kVK_F8: return YASL_KEY_F8; - case kVK_F9: return YASL_KEY_F9; - case kVK_F10: return YASL_KEY_F10; - case kVK_F11: return YASL_KEY_F11; - case kVK_F12: return YASL_KEY_F12; - case kVK_F13: return YASL_KEY_F13; - case kVK_F14: return YASL_KEY_F14; - case kVK_F15: return YASL_KEY_F15; - case kVK_F16: return YASL_KEY_F16; - case kVK_F17: return YASL_KEY_F17; - case kVK_F18: return YASL_KEY_F18; - case kVK_F19: return YASL_KEY_F19; - case kVK_F20: return YASL_KEY_F20; - case kVK_ANSI_Keypad0: return YASL_KEY_KP_0; - case kVK_ANSI_Keypad1: return YASL_KEY_KP_1; - case kVK_ANSI_Keypad2: return YASL_KEY_KP_2; - case kVK_ANSI_Keypad3: return YASL_KEY_KP_3; - case kVK_ANSI_Keypad4: return YASL_KEY_KP_4; - case kVK_ANSI_Keypad5: return YASL_KEY_KP_5; - case kVK_ANSI_Keypad6: return YASL_KEY_KP_6; - case kVK_ANSI_Keypad7: return YASL_KEY_KP_7; - case kVK_ANSI_Keypad8: return YASL_KEY_KP_8; - case kVK_ANSI_Keypad9: return YASL_KEY_KP_9; - case kVK_ANSI_KeypadDecimal: return YASL_KEY_KP_DECIMAL; - case kVK_ANSI_KeypadMultiply: return YASL_KEY_KP_MULTIPLY; - case kVK_ANSI_KeypadPlus: return YASL_KEY_KP_ADD; - case kVK_ANSI_KeypadClear: return YASL_KEY_KP_CLEAR; - case kVK_ANSI_KeypadDivide: return YASL_KEY_KP_DIVIDE; - case kVK_ANSI_KeypadEnter: return YASL_KEY_KP_ENTER; - case kVK_ANSI_KeypadMinus: return YASL_KEY_KP_SUBTRACT; - case kVK_ANSI_KeypadEquals: return YASL_KEY_KP_EQUAL; - default: return YASL_KEY_UNKNOWN; - } -} - -/* XKB standard physical key names, independent of server numeric keycodes. */ -enum yasl_key yasl_key_from_xkb_name(const char name[4]) -{ - static const struct { char name[4]; enum yasl_key key; } keys[] = { - {{'T', 'L', 'D', 'E'}, YASL_KEY_GRAVE}, - {{'A', 'E', '0', '1'}, YASL_KEY_1}, - {{'A', 'E', '0', '2'}, YASL_KEY_2}, - {{'A', 'E', '0', '3'}, YASL_KEY_3}, - {{'A', 'E', '0', '4'}, YASL_KEY_4}, - {{'A', 'E', '0', '5'}, YASL_KEY_5}, - {{'A', 'E', '0', '6'}, YASL_KEY_6}, - {{'A', 'E', '0', '7'}, YASL_KEY_7}, - {{'A', 'E', '0', '8'}, YASL_KEY_8}, - {{'A', 'E', '0', '9'}, YASL_KEY_9}, - {{'A', 'E', '1', '0'}, YASL_KEY_0}, - {{'A', 'E', '1', '1'}, YASL_KEY_MINUS}, - {{'A', 'E', '1', '2'}, YASL_KEY_EQUAL}, - {{'B', 'K', 'S', 'P'}, YASL_KEY_BACKSPACE}, - {{'T', 'A', 'B', 0}, YASL_KEY_TAB}, - {{'A', 'D', '0', '1'}, YASL_KEY_Q}, - {{'A', 'D', '0', '2'}, YASL_KEY_W}, - {{'A', 'D', '0', '3'}, YASL_KEY_E}, - {{'A', 'D', '0', '4'}, YASL_KEY_R}, - {{'A', 'D', '0', '5'}, YASL_KEY_T}, - {{'A', 'D', '0', '6'}, YASL_KEY_Y}, - {{'A', 'D', '0', '7'}, YASL_KEY_U}, - {{'A', 'D', '0', '8'}, YASL_KEY_I}, - {{'A', 'D', '0', '9'}, YASL_KEY_O}, - {{'A', 'D', '1', '0'}, YASL_KEY_P}, - {{'A', 'D', '1', '1'}, YASL_KEY_LEFT_BRACKET}, - {{'A', 'D', '1', '2'}, YASL_KEY_RIGHT_BRACKET}, - {{'B', 'K', 'S', 'L'}, YASL_KEY_BACKSLASH}, - {{'R', 'T', 'R', 'N'}, YASL_KEY_ENTER}, - {{'C', 'A', 'P', 'S'}, YASL_KEY_CAPS_LOCK}, - {{'A', 'C', '0', '1'}, YASL_KEY_A}, - {{'A', 'C', '0', '2'}, YASL_KEY_S}, - {{'A', 'C', '0', '3'}, YASL_KEY_D}, - {{'A', 'C', '0', '4'}, YASL_KEY_F}, - {{'A', 'C', '0', '5'}, YASL_KEY_G}, - {{'A', 'C', '0', '6'}, YASL_KEY_H}, - {{'A', 'C', '0', '7'}, YASL_KEY_J}, - {{'A', 'C', '0', '8'}, YASL_KEY_K}, - {{'A', 'C', '0', '9'}, YASL_KEY_L}, - {{'A', 'C', '1', '0'}, YASL_KEY_SEMICOLON}, - {{'A', 'C', '1', '1'}, YASL_KEY_APOSTROPHE}, - {{'L', 'F', 'S', 'H'}, YASL_KEY_LEFT_SHIFT}, - {{'L', 'S', 'G', 'T'}, YASL_KEY_ISO_BACKSLASH}, - {{'A', 'B', '0', '1'}, YASL_KEY_Z}, - {{'A', 'B', '0', '2'}, YASL_KEY_X}, - {{'A', 'B', '0', '3'}, YASL_KEY_C}, - {{'A', 'B', '0', '4'}, YASL_KEY_V}, - {{'A', 'B', '0', '5'}, YASL_KEY_B}, - {{'A', 'B', '0', '6'}, YASL_KEY_N}, - {{'A', 'B', '0', '7'}, YASL_KEY_M}, - {{'A', 'B', '0', '8'}, YASL_KEY_COMMA}, - {{'A', 'B', '0', '9'}, YASL_KEY_PERIOD}, - {{'A', 'B', '1', '0'}, YASL_KEY_SLASH}, - {{'R', 'T', 'S', 'H'}, YASL_KEY_RIGHT_SHIFT}, - {{'L', 'C', 'T', 'L'}, YASL_KEY_LEFT_CONTROL}, - {{'L', 'W', 'I', 'N'}, YASL_KEY_LEFT_SUPER}, - {{'L', 'A', 'L', 'T'}, YASL_KEY_LEFT_ALT}, - {{'S', 'P', 'C', 'E'}, YASL_KEY_SPACE}, - {{'R', 'A', 'L', 'T'}, YASL_KEY_RIGHT_ALT}, - {{'R', 'W', 'I', 'N'}, YASL_KEY_RIGHT_SUPER}, - {{'C', 'O', 'M', 'P'}, YASL_KEY_MENU}, - {{'R', 'C', 'T', 'L'}, YASL_KEY_RIGHT_CONTROL}, - {{'E', 'S', 'C', 0}, YASL_KEY_ESCAPE}, - {{'F', 'K', '0', '1'}, YASL_KEY_F1}, - {{'F', 'K', '0', '2'}, YASL_KEY_F2}, - {{'F', 'K', '0', '3'}, YASL_KEY_F3}, - {{'F', 'K', '0', '4'}, YASL_KEY_F4}, - {{'F', 'K', '0', '5'}, YASL_KEY_F5}, - {{'F', 'K', '0', '6'}, YASL_KEY_F6}, - {{'F', 'K', '0', '7'}, YASL_KEY_F7}, - {{'F', 'K', '0', '8'}, YASL_KEY_F8}, - {{'F', 'K', '0', '9'}, YASL_KEY_F9}, - {{'F', 'K', '1', '0'}, YASL_KEY_F10}, - {{'F', 'K', '1', '1'}, YASL_KEY_F11}, - {{'F', 'K', '1', '2'}, YASL_KEY_F12}, - {{'P', 'R', 'S', 'C'}, YASL_KEY_PRINT_SCREEN}, - {{'S', 'C', 'L', 'K'}, YASL_KEY_SCROLL_LOCK}, - {{'P', 'A', 'U', 'S'}, YASL_KEY_PAUSE}, - {{'I', 'N', 'S', 0}, YASL_KEY_INSERT}, - {{'H', 'O', 'M', 'E'}, YASL_KEY_HOME}, - {{'P', 'G', 'U', 'P'}, YASL_KEY_PAGE_UP}, - {{'D', 'E', 'L', 'E'}, YASL_KEY_DELETE}, - {{'E', 'N', 'D', 0}, YASL_KEY_END}, - {{'P', 'G', 'D', 'N'}, YASL_KEY_PAGE_DOWN}, - {{'U', 'P', 0, 0}, YASL_KEY_UP}, - {{'L', 'E', 'F', 'T'}, YASL_KEY_LEFT}, - {{'D', 'O', 'W', 'N'}, YASL_KEY_DOWN}, - {{'R', 'G', 'H', 'T'}, YASL_KEY_RIGHT}, - {{'N', 'M', 'L', 'K'}, YASL_KEY_NUM_LOCK}, - {{'K', 'P', 'D', 'V'}, YASL_KEY_KP_DIVIDE}, - {{'K', 'P', 'M', 'U'}, YASL_KEY_KP_MULTIPLY}, - {{'K', 'P', 'S', 'U'}, YASL_KEY_KP_SUBTRACT}, - {{'K', 'P', '7', 0}, YASL_KEY_KP_7}, - {{'K', 'P', '8', 0}, YASL_KEY_KP_8}, - {{'K', 'P', '9', 0}, YASL_KEY_KP_9}, - {{'K', 'P', 'A', 'D'}, YASL_KEY_KP_ADD}, - {{'K', 'P', '4', 0}, YASL_KEY_KP_4}, - {{'K', 'P', '5', 0}, YASL_KEY_KP_5}, - {{'K', 'P', '6', 0}, YASL_KEY_KP_6}, - {{'K', 'P', '1', 0}, YASL_KEY_KP_1}, - {{'K', 'P', '2', 0}, YASL_KEY_KP_2}, - {{'K', 'P', '3', 0}, YASL_KEY_KP_3}, - {{'K', 'P', 'E', 'N'}, YASL_KEY_KP_ENTER}, - {{'K', 'P', '0', 0}, YASL_KEY_KP_0}, - {{'K', 'P', 'D', 'L'}, YASL_KEY_KP_DECIMAL}, - {{'K', 'P', 'E', 'Q'}, YASL_KEY_KP_EQUAL}, - {{'F', 'K', '1', '3'}, YASL_KEY_F13}, - {{'F', 'K', '1', '4'}, YASL_KEY_F14}, - {{'F', 'K', '1', '5'}, YASL_KEY_F15}, - {{'F', 'K', '1', '6'}, YASL_KEY_F16}, - {{'F', 'K', '1', '7'}, YASL_KEY_F17}, - {{'F', 'K', '1', '8'}, YASL_KEY_F18}, - {{'F', 'K', '1', '9'}, YASL_KEY_F19}, - {{'F', 'K', '2', '0'}, YASL_KEY_F20}, - {{'F', 'K', '2', '1'}, YASL_KEY_F21}, - {{'F', 'K', '2', '2'}, YASL_KEY_F22}, - {{'F', 'K', '2', '3'}, YASL_KEY_F23}, - {{'F', 'K', '2', '4'}, YASL_KEY_F24}, - {{'H', 'K', 'T', 'G'}, YASL_KEY_KANA}, - {{'A', 'B', '1', '1'}, YASL_KEY_RO}, - {{'H', 'E', 'N', 'K'}, YASL_KEY_CONVERT}, - {{'M', 'U', 'H', 'E'}, YASL_KEY_NONCONVERT}, - {{'A', 'E', '1', '3'}, YASL_KEY_YEN}, - {{'M', 'U', 'T', 'E'}, YASL_KEY_MUTE}, - {{'I', '1', '2', '9'}, YASL_KEY_KP_COMMA}, - }; - for (size_t i = 0; i < sizeof(keys) / sizeof(keys[0]); i++) - if (memcmp(keys[i].name, name, 4) == 0) return keys[i].key; - return YASL_KEY_UNKNOWN; -} diff --git a/src/common/keyboard.h b/src/common/keyboard.h index 50ddbb3..77c6380 100644 --- a/src/common/keyboard.h +++ b/src/common/keyboard.h @@ -3,10 +3,6 @@ #include "yasl/yasl.h" -enum yasl_key yasl_key_from_evdev(uint32_t code); -enum yasl_key yasl_key_from_xkb_name(const char name[4]); -enum yasl_key yasl_key_from_cocoa(uint32_t code); - /* Layout labels omit controls, invalid Unicode, and Cocoa function-key PUA. */ static inline uint32_t yasl_key_label(uint32_t cp) { diff --git a/src/common/loop.c b/src/common/loop.c deleted file mode 100644 index 1c6a612..0000000 --- a/src/common/loop.c +++ /dev/null @@ -1,429 +0,0 @@ -#define _GNU_SOURCE -#define _POSIX_C_SOURCE 200809L -#include "loop.h" - -#include <errno.h> -#include <fcntl.h> -#include <poll.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include <unistd.h> - -#define YASL_LOOP_INIT_CAP 32 - -typedef int (*yasl_loop_fd_fn)(int fd, short revents, void *ud); - -struct yasl_fd_source { - yasl_loop_fd_fn fn; - void *ud; - int id; - int fd; - short events; -}; - -struct yasl_timer_source { - yasl_timer_cb fn; - void *ud; - uint64_t interval_ns; - uint64_t deadline_ns; - yasl_timer_id id; - bool deleted; -}; - -struct yasl_loop { - struct yasl_fd_source *fds; - struct pollfd *pollfds; - int count; - int capacity; - int next_id; - bool running; - int wake_rfd; - int wake_wfd; - int wake_watch; - - struct yasl_timer_source *timers; - int timer_count; - int timer_capacity; - uint32_t next_timer_id; - int timer_firing_depth; -}; - -uint64_t yasl_loop_now_ns(void) -{ - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - return (uint64_t)ts.tv_sec * 1000000000ull + (uint64_t)ts.tv_nsec; -} - -static int loop_wake_cb(int fd, short revents, void *ud) -{ - (void)revents; - (void)ud; - char buf[128]; - ssize_t n; - while ((n = read(fd, buf, sizeof(buf))) > 0 || (n < 0 && errno == EINTR)) {} - return 0; -} - -struct yasl_loop *yasl_loop_create(void) -{ - struct yasl_loop *l = calloc(1, sizeof(*l)); - if (!l) return NULL; - - l->capacity = YASL_LOOP_INIT_CAP; - l->fds = malloc((size_t)l->capacity * sizeof(*l->fds)); - l->pollfds = malloc((size_t)l->capacity * sizeof(*l->pollfds)); - if (!l->fds || !l->pollfds) { - free(l->fds); - free(l->pollfds); - free(l); - return NULL; - } - - l->next_id = 1; - l->next_timer_id = 1; - l->wake_rfd = -1; - l->wake_wfd = -1; - - int p[2]; -#if defined(__linux__) && defined(O_CLOEXEC) - if (pipe2(p, O_CLOEXEC | O_NONBLOCK) == 0) { - l->wake_rfd = p[0]; - l->wake_wfd = p[1]; - } -#else - if (pipe(p) == 0) { - int f0 = fcntl(p[0], F_GETFL, 0); - int f1 = fcntl(p[1], F_GETFL, 0); - if (f0 >= 0) fcntl(p[0], F_SETFL, f0 | O_NONBLOCK); - if (f1 >= 0) fcntl(p[1], F_SETFL, f1 | O_NONBLOCK); - fcntl(p[0], F_SETFD, FD_CLOEXEC); - fcntl(p[1], F_SETFD, FD_CLOEXEC); - l->wake_rfd = p[0]; - l->wake_wfd = p[1]; - } -#endif - - if (l->wake_rfd >= 0) { - l->wake_watch = yasl_loop_add_fd(l, l->wake_rfd, POLLIN, loop_wake_cb, l); - } - return l; -} - -void yasl_loop_destroy(struct yasl_loop *l) -{ - if (!l) return; - if (l->wake_watch > 0) - yasl_loop_del_fd(l, l->wake_watch); - if (l->wake_rfd >= 0) - close(l->wake_rfd); - if (l->wake_wfd >= 0) - close(l->wake_wfd); - free(l->fds); - free(l->pollfds); - free(l->timers); - free(l); -} - -int yasl_loop_add_fd(struct yasl_loop *l, int fd, short events, - int (*fn)(int fd, short revents, void *ud), void *ud) -{ - if (!l || fd < 0) - return -1; - - if (l->count >= l->capacity) { - int new_cap = l->capacity ? l->capacity * 2 : YASL_LOOP_INIT_CAP; - struct yasl_fd_source *new_fds = realloc(l->fds, (size_t)new_cap * sizeof(*new_fds)); - if (!new_fds) return -1; - l->fds = new_fds; - - struct pollfd *new_pollfds = realloc(l->pollfds, (size_t)new_cap * sizeof(*new_pollfds)); - if (!new_pollfds) return -1; - l->pollfds = new_pollfds; - l->capacity = new_cap; - } - - int id = l->next_id++; - if (l->next_id <= 0) l->next_id = 1; - - l->fds[l->count] = (struct yasl_fd_source){ - .fn = fn, .ud = ud, .id = id, .fd = fd, .events = events, - }; - l->pollfds[l->count] = (struct pollfd){ - .fd = fd, .events = events, .revents = 0, - }; - l->count++; - return id; -} - -int yasl_loop_del_fd(struct yasl_loop *l, int id) -{ - if (!l || id <= 0) return -1; - for (int i = 0; i < l->count; i++) { - if (l->fds[i].id == id) { - l->count--; - l->fds[i] = l->fds[l->count]; - l->pollfds[i] = l->pollfds[l->count]; - return 0; - } - } - return -1; -} - -int yasl_loop_set_fd_events(struct yasl_loop *l, int id, short events) -{ - if (!l || id <= 0) return -1; - for (int i = 0; i < l->count; i++) { - if (l->fds[i].id == id) { - l->fds[i].events = events; - l->pollfds[i].events = events; - return 0; - } - } - return -1; -} - -void yasl_loop_kick(struct yasl_loop *l) -{ - if (!l || l->wake_wfd < 0) return; - char b = 1; - ssize_t n; - do { - n = write(l->wake_wfd, &b, 1); - } while (n < 0 && errno == EINTR); -} - -static void timer_cleanup_deleted(struct yasl_loop *l) -{ - if (!l || l->timer_firing_depth > 0) return; - int dest = 0; - for (int src = 0; src < l->timer_count; src++) { - struct yasl_timer_source t = l->timers[src]; - l->timers[dest] = t; - dest += !t.deleted; - } - l->timer_count = dest; -} - -bool yasl_loop_timer_armed(const struct yasl_loop *l, yasl_timer_id id) -{ - if (!l || id == 0) return false; - for (int i = 0; i < l->timer_count; i++) - if (l->timers[i].id == id) - return !l->timers[i].deleted; - return false; -} - -int yasl_loop_next_timeout_ms(const struct yasl_loop *l) -{ - if (!l || l->timer_count <= 0) return -1; - uint64_t now = yasl_loop_now_ns(); - uint64_t min_deadline = UINT64_MAX; - bool has_active = false; - for (int i = 0; i < l->timer_count; i++) { - if (!l->timers[i].deleted) { - has_active = true; - if (l->timers[i].deadline_ns < min_deadline) - min_deadline = l->timers[i].deadline_ns; - } - } - if (!has_active) return -1; - if (min_deadline <= now) return 0; - uint64_t diff = min_deadline - now; - uint64_t ms = (diff + 999999ull) / 1000000ull; - return (ms > (uint64_t)INT_MAX) ? INT_MAX : (int)ms; -} - -yasl_timer_id yasl_loop_add_timer(struct yasl_loop *l, uint64_t interval_ns, - yasl_timer_cb cb, void *ud) -{ - if (!l || !cb || interval_ns == 0) return 0; - - if (l->timer_count >= l->timer_capacity) { - int new_cap = l->timer_capacity ? l->timer_capacity * 2 : 16; - struct yasl_timer_source *new_timers = realloc(l->timers, (size_t)new_cap * sizeof(*new_timers)); - if (!new_timers) return 0; - l->timers = new_timers; - l->timer_capacity = new_cap; - } - - uint32_t id = l->next_timer_id++; - if (l->next_timer_id == 0) l->next_timer_id = 1; - - uint64_t now = yasl_loop_now_ns(); - l->timers[l->timer_count++] = (struct yasl_timer_source){ - .fn = cb, - .ud = ud, - .id = id, - .interval_ns = interval_ns, - .deadline_ns = now + interval_ns, - .deleted = false, - }; - - yasl_loop_kick(l); - return id; -} - -bool yasl_loop_del_timer(struct yasl_loop *l, yasl_timer_id id) -{ - if (!l || id == 0) return false; - for (int i = l->timer_count - 1; i >= 0; i--) { - if (l->timers[i].id == id && !l->timers[i].deleted) { - l->timers[i].deleted = true; - if (l->timer_firing_depth == 0) { - if (i == l->timer_count - 1) { - while (l->timer_count > 0 && l->timers[l->timer_count - 1].deleted) - l->timer_count--; - } else { - timer_cleanup_deleted(l); - } - } - return true; - } - } - return false; -} - -int yasl_loop_step(struct yasl_loop *l, int timeout_ms) -{ - if (!l) return -1; - - int timer_to = yasl_loop_next_timeout_ms(l); - int effective_timeout = timeout_ms; - if (timer_to >= 0) { - if (effective_timeout < 0 || timer_to < effective_timeout) - effective_timeout = timer_to; - } - - if (l->count <= 0) { - if (effective_timeout > 0) { - struct timespec req = { - .tv_sec = effective_timeout / 1000, - .tv_nsec = (long)(effective_timeout % 1000) * 1000000L, - }; - nanosleep(&req, NULL); - } - } else { - int n; - do { - n = poll(l->pollfds, (nfds_t)l->count, effective_timeout); - } while (n < 0 && errno == EINTR); - - if (n < 0) return -1; - } - - int handled = 0; - - if (l->count > 0) { - int count = l->count; - struct yasl_fd_source sstack[32]; - struct pollfd pstack[32]; - struct yasl_fd_source *scopy = (count <= 32) ? sstack : malloc((size_t)count * sizeof(*scopy)); - struct pollfd *pcopy = (count <= 32) ? pstack : malloc((size_t)count * sizeof(*pcopy)); - if (!scopy || !pcopy) { - if (scopy && scopy != sstack) free(scopy); - if (pcopy && pcopy != pstack) free(pcopy); - return -1; - } - - memcpy(scopy, l->fds, (size_t)count * sizeof(*scopy)); - memcpy(pcopy, l->pollfds, (size_t)count * sizeof(*pcopy)); - - for (int i = 0; i < count; i++) { - if (pcopy[i].revents) { - short revents = pcopy[i].revents; - // Fast-path: check if source is still at index i before linear scan - bool valid = false; - if (i < l->count && l->fds[i].id == scopy[i].id) { - l->pollfds[i].revents = 0; - valid = true; - } else { - for (int j = 0; j < l->count; j++) { - if (l->fds[j].id == scopy[i].id) { - l->pollfds[j].revents = 0; - valid = true; - break; - } - } - } - if (valid && scopy[i].fn) { - scopy[i].fn(scopy[i].fd, revents, scopy[i].ud); - handled++; - } - } - } - - if (scopy != sstack) free(scopy); - if (pcopy != pstack) free(pcopy); - } - - if (l->timer_count > 0) { - uint64_t now = yasl_loop_now_ns(); - l->timer_firing_depth++; - int initial_count = l->timer_count; - for (int i = 0; i < initial_count; i++) { - if (i >= l->timer_count) break; - if (l->timers[i].deleted || l->timers[i].deadline_ns > now) - continue; - - yasl_timer_id tid = l->timers[i].id; - uint64_t interval = l->timers[i].interval_ns; - void *ud = l->timers[i].ud; - struct yasl_timer_source timer_src = l->timers[i]; - - uint64_t next_interval = timer_src.fn(ud, tid, interval); - handled++; - - // Fast-path: timer is usually still at index i unless an earlier timer was deleted - if (i < l->timer_count && l->timers[i].id == tid) { - if (next_interval == 0 || l->timers[i].deleted) { - l->timers[i].deleted = true; - } else { - l->timers[i].interval_ns = next_interval; - if (l->timers[i].deadline_ns + next_interval > now) - l->timers[i].deadline_ns += next_interval; - else - l->timers[i].deadline_ns = now + next_interval; - } - } else { - for (int j = 0; j < l->timer_count; j++) { - if (l->timers[j].id == tid) { - if (next_interval == 0 || l->timers[j].deleted) { - l->timers[j].deleted = true; - } else { - l->timers[j].interval_ns = next_interval; - if (l->timers[j].deadline_ns + next_interval > now) - l->timers[j].deadline_ns += next_interval; - else - l->timers[j].deadline_ns = now + next_interval; - } - break; - } - } - } - } - l->timer_firing_depth--; - if (l->timer_firing_depth == 0) { - timer_cleanup_deleted(l); - } - } - - return handled; -} - -int yasl_loop_run(struct yasl_loop *l) -{ - if (!l) return -1; - l->running = true; - while (l->running) { - if (yasl_loop_step(l, -1) < 0) - return -1; - } - return 0; -} - -void yasl_loop_quit(struct yasl_loop *l) -{ - if (l) l->running = false; -} diff --git a/src/common/meson.build b/src/common/meson.build index e3986cd..015c61c 100644 --- a/src/common/meson.build +++ b/src/common/meson.build @@ -1 +1 @@ -sources += files('app.c', 'backend.c', 'input.c', 'keyboard.c', 'loop.c', 'native.c', 'timing.c', 'utf8.c') +sources += files('app.c', 'backend.c', 'input.c', 'native.c', 'timing.c', 'utf8.c') diff --git a/src/common/native.c b/src/common/native.c index 33837e4..42b065c 100644 --- a/src/common/native.c +++ b/src/common/native.c @@ -1,13 +1,5 @@ #include "backend.h" -#if YASL_HAS_WAYLAND -#include "yasl/native/wayland.h" -#endif - -#if YASL_HAS_X11 -#include "yasl/native/x11.h" -#endif - #include <errno.h> void *yasl_display_get_native_handle(struct yasl_display *d) @@ -26,36 +18,8 @@ void *yasl_surface_get_native_handle(struct yasl_surface *s) s->display->ops->surface_get_native_handle(s) : NULL; } -#if YASL_HAS_WAYLAND -struct wl_display *yasl_wayland_display_get_wl_display(struct yasl_display *d) -{ - return (d && yasl_display_backend(d) == YASL_BACKEND_WAYLAND) ? - (struct wl_display *)yasl_display_get_native_handle(d) : NULL; -} - -struct wl_surface *yasl_wayland_surface_get_wl_surface(struct yasl_surface *s) -{ - return (s && s->display && yasl_display_backend(s->display) == YASL_BACKEND_WAYLAND) ? - (struct wl_surface *)yasl_surface_get_native_handle(s) : NULL; -} -#endif - -#if YASL_HAS_X11 -Display *yasl_x11_display_get_display(struct yasl_display *d) -{ - return (d && yasl_display_backend(d) == YASL_BACKEND_X11) ? - (Display *)yasl_display_get_native_handle(d) : NULL; -} - -uintptr_t yasl_x11_surface_get_window(struct yasl_surface *s) -{ - return (s && s->display && yasl_display_backend(s->display) == YASL_BACKEND_X11) ? - (uintptr_t)yasl_surface_get_native_handle(s) : 0; -} -#endif - struct yasl_surface *yasl_surface_create_native(struct yasl_display *d, - const struct yasl_surface_spec *spec, void *graphics_device) + const struct yasl_window_spec *spec, void *graphics_device) { if (!graphics_device) { errno = EINVAL; |
