summaryrefslogtreecommitdiff
path: root/src/wayland
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-11 23:40:57 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-11 23:40:57 +0300
commit6eac0a5f2c552728efca420b1129fae7d4fea773 (patch)
tree27fc9dc013de80787525696897771acec22c0f0c /src/wayland
parent8d9f7c7cb39359d62bf28ef1775b944a7dddd6fb (diff)
feat: backend selection (Wayland, X11, Cocoa)
Diffstat (limited to 'src/wayland')
-rw-r--r--src/wayland/api.h47
-rw-r--r--src/wayland/backend.c231
-rw-r--r--src/wayland/buffer.c62
-rw-r--r--src/wayland/drag.c42
-rw-r--r--src/wayland/ime.c26
-rw-r--r--src/wayland/internal.h114
-rw-r--r--src/wayland/keyboard.c32
-rw-r--r--src/wayland/meson.build13
-rw-r--r--src/wayland/pointer.c98
-rw-r--r--src/wayland/popup.c23
-rw-r--r--src/wayland/shell.c46
-rw-r--r--src/wayland/surface.c93
12 files changed, 562 insertions, 265 deletions
diff --git a/src/wayland/api.h b/src/wayland/api.h
new file mode 100644
index 0000000..e4473cb
--- /dev/null
+++ b/src/wayland/api.h
@@ -0,0 +1,47 @@
+#ifndef YASL_WAYLAND_API_H
+#define YASL_WAYLAND_API_H
+
+#include "common/backend.h"
+
+struct wayland_display;
+struct wayland_surface;
+
+struct wayland_display *wayland_display_open(struct yasl_loop *loop, const struct yasl_display_spec *spec);
+void wayland_display_close(struct wayland_display *d);
+uint32_t wayland_display_caps(const struct wayland_display *d);
+void wayland_display_dispatch(struct wayland_display *d);
+void wayland_display_flush(struct wayland_display *d);
+int wayland_display_modifiers(const struct wayland_display *d);
+void wayland_display_copy(struct wayland_display *d, enum yasl_selection sel, const char *text);
+void wayland_display_paste(struct wayland_display *d, enum yasl_selection sel, struct wayland_surface *target);
+bool wayland_display_drag_start(struct wayland_display *d, struct wayland_surface *origin, const struct yasl_drag_image *image, const struct yasl_drag_listener *l, void *ud);
+void wayland_display_drag_cancel(struct wayland_display *d);
+struct wayland_surface *wayland_surface_create_toplevel(struct wayland_display *d, const struct yasl_surface_spec *spec);
+struct wayland_surface *wayland_surface_create_popup(struct wayland_surface *parent, const struct yasl_popup_spec *spec);
+bool wayland_surface_popup_reposition(struct wayland_surface *popup, const struct yasl_popup_spec *spec);
+void wayland_surface_destroy(struct wayland_surface *s);
+struct wayland_display *wayland_surface_display(const struct wayland_surface *s);
+void wayland_surface_set_callbacks(struct wayland_surface *s, const struct yasl_surface_cbs *cbs, void *ud);
+void wayland_surface_set_title(struct wayland_surface *s, const char *title);
+void wayland_surface_schedule_redraw(struct wayland_surface *s);
+bool wayland_surface_present(struct wayland_surface *s, const struct yasl_framebuffer *fb, const struct yasl_damage_list *damage);
+bool wayland_surface_input_poll(struct wayland_surface *s, struct yasl_input_event *ev);
+struct yasl_vector2i wayland_surface_size(const struct wayland_surface *s);
+uint32_t wayland_surface_scale_120(const struct wayland_surface *s);
+uint32_t wayland_surface_state(const struct wayland_surface *s);
+struct yasl_timing wayland_surface_timing(const struct wayland_surface *s);
+uint64_t wayland_surface_frame_time_ns(struct wayland_surface *s, uint64_t now);
+void wayland_surface_set_cursor(struct wayland_surface *s, enum yasl_cursor cursor);
+void wayland_surface_set_background_color(struct wayland_surface *s, uint32_t bg);
+const char *wayland_surface_ime_preedit(const struct wayland_surface *s);
+bool wayland_surface_ime_preedit_cursor(const struct wayland_surface *s, int *begin, int *end);
+void wayland_surface_set_ime_caret(struct wayland_surface *s, struct yasl_rect2i caret);
+bool wayland_surface_start_interactive_move(struct wayland_surface *s);
+bool wayland_surface_start_interactive_resize(struct wayland_surface *s, enum yasl_resize_edge edge);
+bool wayland_surface_show_window_menu(struct wayland_surface *s, struct yasl_vector2i pos);
+bool wayland_surface_drag_carry(struct wayland_surface *s, struct yasl_vector2i offset);
+bool wayland_surface_place_under_pointer(struct wayland_surface *s, struct yasl_vector2i at);
+void *wayland_display_get_native_handle(struct wayland_display *d);
+void *wayland_surface_get_native_handle(struct wayland_surface *s);
+
+#endif
diff --git a/src/wayland/backend.c b/src/wayland/backend.c
new file mode 100644
index 0000000..da7f1a3
--- /dev/null
+++ b/src/wayland/backend.c
@@ -0,0 +1,231 @@
+#include "wayland/internal.h"
+
+static struct yasl_display *impl_display_open(struct yasl_loop *loop, const struct yasl_display_spec *spec)
+{
+ struct wayland_display *result = wayland_display_open(loop, spec);
+ return result ? &result->base : NULL;
+}
+
+static void impl_display_close(struct yasl_display *d)
+{
+ wayland_display_close((struct wayland_display *)d);
+}
+
+static uint32_t impl_display_caps(const struct yasl_display *d)
+{
+ return wayland_display_caps((const struct wayland_display *)d);
+}
+
+static void impl_display_dispatch(struct yasl_display *d)
+{
+ wayland_display_dispatch((struct wayland_display *)d);
+}
+
+static void impl_display_flush(struct yasl_display *d)
+{
+ wayland_display_flush((struct wayland_display *)d);
+}
+
+static int impl_display_modifiers(const struct yasl_display *d)
+{
+ return wayland_display_modifiers((const struct wayland_display *)d);
+}
+
+static void impl_display_copy(struct yasl_display *d, enum yasl_selection sel, const char *text)
+{
+ wayland_display_copy((struct wayland_display *)d, sel, text);
+}
+
+static void impl_display_paste(struct yasl_display *d, enum yasl_selection sel, struct yasl_surface *target)
+{
+ wayland_display_paste((struct wayland_display *)d, sel, (struct wayland_surface *)target);
+}
+
+static bool impl_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)
+{
+ return wayland_display_drag_start((struct wayland_display *)d, (struct wayland_surface *)origin, image, l, ud);
+}
+
+static void impl_display_drag_cancel(struct yasl_display *d)
+{
+ wayland_display_drag_cancel((struct wayland_display *)d);
+}
+
+static struct yasl_surface *impl_surface_create_toplevel(struct yasl_display *d, const struct yasl_surface_spec *spec)
+{
+ struct wayland_surface *result = wayland_surface_create_toplevel((struct wayland_display *)d, spec);
+ return result ? &result->base : NULL;
+}
+
+static struct yasl_surface *impl_surface_create_popup(struct yasl_surface *parent, const struct yasl_popup_spec *spec)
+{
+ struct wayland_surface *result = wayland_surface_create_popup((struct wayland_surface *)parent, spec);
+ return result ? &result->base : NULL;
+}
+
+static bool impl_surface_popup_reposition(struct yasl_surface *popup, const struct yasl_popup_spec *spec)
+{
+ return wayland_surface_popup_reposition((struct wayland_surface *)popup, spec);
+}
+
+static void impl_surface_destroy(struct yasl_surface *s)
+{
+ wayland_surface_destroy((struct wayland_surface *)s);
+}
+
+static struct yasl_display *impl_surface_display(const struct yasl_surface *s)
+{
+ struct wayland_display *result = wayland_surface_display((const struct wayland_surface *)s);
+ return result ? &result->base : NULL;
+}
+
+static void impl_surface_set_callbacks(struct yasl_surface *s, const struct yasl_surface_cbs *cbs, void *ud)
+{
+ wayland_surface_set_callbacks((struct wayland_surface *)s, cbs, ud);
+}
+
+static void impl_surface_set_title(struct yasl_surface *s, const char *title)
+{
+ wayland_surface_set_title((struct wayland_surface *)s, title);
+}
+
+static void impl_surface_schedule_redraw(struct yasl_surface *s)
+{
+ wayland_surface_schedule_redraw((struct wayland_surface *)s);
+}
+
+static bool impl_surface_present(struct yasl_surface *s, const struct yasl_framebuffer *fb, const struct yasl_damage_list *damage)
+{
+ return wayland_surface_present((struct wayland_surface *)s, fb, damage);
+}
+
+static bool impl_surface_input_poll(struct yasl_surface *s, struct yasl_input_event *ev)
+{
+ return wayland_surface_input_poll((struct wayland_surface *)s, ev);
+}
+
+static struct yasl_vector2i impl_surface_size(const struct yasl_surface *s)
+{
+ return wayland_surface_size((const struct wayland_surface *)s);
+}
+
+static uint32_t impl_surface_scale_120(const struct yasl_surface *s)
+{
+ return wayland_surface_scale_120((const struct wayland_surface *)s);
+}
+
+static uint32_t impl_surface_state(const struct yasl_surface *s)
+{
+ return wayland_surface_state((const struct wayland_surface *)s);
+}
+
+static struct yasl_timing impl_surface_timing(const struct yasl_surface *s)
+{
+ return wayland_surface_timing((const struct wayland_surface *)s);
+}
+
+static uint64_t impl_surface_frame_time_ns(struct yasl_surface *s, uint64_t now)
+{
+ return wayland_surface_frame_time_ns((struct wayland_surface *)s, now);
+}
+
+static void impl_surface_set_cursor(struct yasl_surface *s, enum yasl_cursor cursor)
+{
+ wayland_surface_set_cursor((struct wayland_surface *)s, cursor);
+}
+
+static void impl_surface_set_background_color(struct yasl_surface *s, uint32_t bg)
+{
+ wayland_surface_set_background_color((struct wayland_surface *)s, bg);
+}
+
+static const char *impl_surface_ime_preedit(const struct yasl_surface *s)
+{
+ return wayland_surface_ime_preedit((const struct wayland_surface *)s);
+}
+
+static bool impl_surface_ime_preedit_cursor(const struct yasl_surface *s, int *begin, int *end)
+{
+ return wayland_surface_ime_preedit_cursor((const struct wayland_surface *)s, begin, end);
+}
+
+static void impl_surface_set_ime_caret(struct yasl_surface *s, struct yasl_rect2i caret)
+{
+ wayland_surface_set_ime_caret((struct wayland_surface *)s, caret);
+}
+
+static bool impl_surface_start_interactive_move(struct yasl_surface *s)
+{
+ return wayland_surface_start_interactive_move((struct wayland_surface *)s);
+}
+
+static bool impl_surface_start_interactive_resize(struct yasl_surface *s, enum yasl_resize_edge edge)
+{
+ return wayland_surface_start_interactive_resize((struct wayland_surface *)s, edge);
+}
+
+static bool impl_surface_show_window_menu(struct yasl_surface *s, struct yasl_vector2i pos)
+{
+ return wayland_surface_show_window_menu((struct wayland_surface *)s, pos);
+}
+
+static bool impl_surface_drag_carry(struct yasl_surface *s, struct yasl_vector2i offset)
+{
+ return wayland_surface_drag_carry((struct wayland_surface *)s, offset);
+}
+
+static bool impl_surface_place_under_pointer(struct yasl_surface *s, struct yasl_vector2i at)
+{
+ return wayland_surface_place_under_pointer((struct wayland_surface *)s, at);
+}
+
+static void *impl_display_get_native_handle(struct yasl_display *d)
+{
+ return wayland_display_get_native_handle((struct wayland_display *)d);
+}
+
+static void *impl_surface_get_native_handle(struct yasl_surface *s)
+{
+ return wayland_surface_get_native_handle((struct wayland_surface *)s);
+}
+
+const struct yasl_backend_ops yasl_wayland_backend = {
+ .type = YASL_BACKEND_WAYLAND,
+ .display_open = impl_display_open,
+ .display_close = impl_display_close,
+ .display_caps = impl_display_caps,
+ .display_dispatch = impl_display_dispatch,
+ .display_flush = impl_display_flush,
+ .display_modifiers = impl_display_modifiers,
+ .display_copy = impl_display_copy,
+ .display_paste = impl_display_paste,
+ .display_drag_start = impl_display_drag_start,
+ .display_drag_cancel = impl_display_drag_cancel,
+ .surface_create_toplevel = impl_surface_create_toplevel,
+ .surface_create_popup = impl_surface_create_popup,
+ .surface_popup_reposition = impl_surface_popup_reposition,
+ .surface_destroy = impl_surface_destroy,
+ .surface_display = impl_surface_display,
+ .surface_set_callbacks = impl_surface_set_callbacks,
+ .surface_set_title = impl_surface_set_title,
+ .surface_schedule_redraw = impl_surface_schedule_redraw,
+ .surface_present = impl_surface_present,
+ .surface_input_poll = impl_surface_input_poll,
+ .surface_size = impl_surface_size,
+ .surface_scale_120 = impl_surface_scale_120,
+ .surface_state = impl_surface_state,
+ .surface_timing = impl_surface_timing,
+ .surface_frame_time_ns = impl_surface_frame_time_ns,
+ .surface_set_cursor = impl_surface_set_cursor,
+ .surface_set_background_color = impl_surface_set_background_color,
+ .surface_ime_preedit = impl_surface_ime_preedit,
+ .surface_ime_preedit_cursor = impl_surface_ime_preedit_cursor,
+ .surface_set_ime_caret = impl_surface_set_ime_caret,
+ .surface_start_interactive_move = impl_surface_start_interactive_move,
+ .surface_start_interactive_resize = impl_surface_start_interactive_resize,
+ .surface_show_window_menu = impl_surface_show_window_menu,
+ .surface_drag_carry = impl_surface_drag_carry,
+ .surface_place_under_pointer = impl_surface_place_under_pointer,
+ .display_get_native_handle = impl_display_get_native_handle,
+ .surface_get_native_handle = impl_surface_get_native_handle,
+};
diff --git a/src/wayland/buffer.c b/src/wayland/buffer.c
index 492cfde..9776f13 100644
--- a/src/wayland/buffer.c
+++ b/src/wayland/buffer.c
@@ -7,7 +7,7 @@ static long minor_faults(void)
return getrusage(RUSAGE_SELF, &usage) == 0 ? usage.ru_minflt : 0;
}
-void surface_update_opaque_region(struct yasl_surface *w)
+void surface_update_opaque_region(struct wayland_surface *w)
{
if (!w || !w->opaque || w->logical_width <= 0 || w->logical_height <= 0)
return;
@@ -55,7 +55,7 @@ static bool fd_truncate(int fd, size_t bytes)
return rc == 0;
}
-int buffer_reserve(struct yasl_surface *w, struct buffer *b, size_t needed)
+int buffer_reserve(struct wayland_surface *w, struct buffer *b, size_t needed)
{
if (needed <= b->capacity) return 0;
if (b->busy || needed > INT32_MAX) return -1;
@@ -87,7 +87,7 @@ int buffer_reserve(struct yasl_surface *w, struct buffer *b, size_t needed)
return 0;
}
-int buffer_prepare(struct yasl_surface *w, struct buffer *b, int width, int height,
+int buffer_prepare(struct wayland_surface *w, struct buffer *b, int width, int height,
const struct wl_buffer_listener *listener)
{
if (b->proxy && !b->busy && b->width == width && b->height == height) return 0;
@@ -113,7 +113,7 @@ int buffer_prepare(struct yasl_surface *w, struct buffer *b, int width, int heig
return 0;
}
-static void publish_surface_scale(struct yasl_surface *w)
+static void publish_surface_scale(struct wayland_surface *w)
{
if (w->viewport) {
wp_viewport_set_destination(w->viewport, w->logical_width, w->logical_height);
@@ -124,15 +124,15 @@ static void publish_surface_scale(struct yasl_surface *w)
}
}
-static void surface_request_scale(struct yasl_surface *w, uint32_t scale_120)
+static void surface_request_scale(struct wayland_surface *w, uint32_t scale_120)
{
if (!scale_120 || scale_120 == w->pending_scale_120) return;
w->pending_scale_120 = scale_120;
w->size_pending = true;
- yasl_surface_schedule_redraw(w);
+ wayland_surface_schedule_redraw(w);
}
-int apply_pending_geometry(struct yasl_surface *w)
+int apply_pending_geometry(struct wayland_surface *w)
{
if (!w->size_pending) return 0;
if (w->parent && w->pending_scale_120 == w->scale_120) {
@@ -183,7 +183,7 @@ int apply_pending_geometry(struct yasl_surface *w)
}
publish_surface_scale(w);
if (w->cbs->configure && (resized || rescaled))
- w->cbs->configure(w, (struct yasl_geometry){
+ w->cbs->configure(&w->base, (struct yasl_geometry){
.size = { .x = width, .y = height }, .scale_120 = w->scale_120,
}, w->ud);
return 0;
@@ -200,7 +200,7 @@ static const struct wp_fractional_scale_v1_listener frac_scale_listener = {
.preferred_scale = fractional_preferred_scale,
};
-static void surface_follow_refresh(struct yasl_surface *w)
+static void surface_follow_refresh(struct wayland_surface *w)
{
uint32_t refresh = 0;
for (const struct wl_conn_output *o = w->conn->outputs; o; o = o->next)
@@ -213,7 +213,7 @@ static void surface_follow_refresh(struct yasl_surface *w)
w->clock.refresh_ns = refresh;
}
-void surface_follow_outputs(struct yasl_surface *w)
+void surface_follow_outputs(struct wayland_surface *w)
{
surface_follow_refresh(w);
if (!w->frac_scale && !surface_gets_preferred_scale(w->surface))
@@ -223,7 +223,7 @@ void surface_follow_outputs(struct yasl_surface *w)
static void surface_enter(void *data, struct wl_surface *surface, struct wl_output *output)
{
(void)surface;
- struct yasl_surface *w = data;
+ struct wayland_surface *w = data;
w->outputs |= conn_output_mask(w->conn, output);
surface_follow_outputs(w);
}
@@ -231,7 +231,7 @@ static void surface_enter(void *data, struct wl_surface *surface, struct wl_outp
static void surface_leave(void *data, struct wl_surface *surface, struct wl_output *output)
{
(void)surface;
- struct yasl_surface *w = data;
+ struct wayland_surface *w = data;
w->outputs &= ~conn_output_mask(w->conn, output);
surface_follow_outputs(w);
}
@@ -239,7 +239,7 @@ static void surface_leave(void *data, struct wl_surface *surface, struct wl_outp
static void surface_preferred_scale(void *data, struct wl_surface *surface, int32_t factor)
{
(void)surface;
- struct yasl_surface *w = data;
+ struct wayland_surface *w = data;
if (w->frac_scale || w->parent || factor <= 0)
return;
surface_request_scale(w, (uint32_t)factor * YASL_SCALE_UNIT);
@@ -264,7 +264,7 @@ static void buffer_release(void *data, struct wl_buffer *buffer)
struct buffer *b = data;
b->busy = false;
if (b->owner && b->owner->want_draw)
- yasl_surface_schedule_redraw(b->owner);
+ wayland_surface_schedule_redraw(b->owner);
}
static const struct wl_buffer_listener buffer_listener = {
@@ -273,7 +273,7 @@ static const struct wl_buffer_listener buffer_listener = {
static void frame_done(void *data, struct wl_callback *cb, uint32_t ms)
{
- struct yasl_surface *w = data;
+ struct wayland_surface *w = data;
wl_callback_destroy(cb);
w->frame_cb = NULL;
@@ -282,14 +282,14 @@ static void frame_done(void *data, struct wl_callback *cb, uint32_t ms)
yasl_clock_presented(&w->clock, yasl_clock_extend_ms(ms, now), w->sample_refresh);
if (w->want_draw)
- yasl_surface_schedule_redraw(w);
+ wayland_surface_schedule_redraw(w);
}
static const struct wl_callback_listener frame_listener = {
.done = frame_done,
};
-static void arm_frame(struct yasl_surface *w)
+static void arm_frame(struct wayland_surface *w)
{
if (!w->configured || w->closed || w->frame_cb)
return;
@@ -315,7 +315,7 @@ int buffer_pick_free_index(const struct buffer *bufs, int cur)
}
struct latency_feedback {
- struct yasl_surface *window;
+ struct wayland_surface *window;
struct wp_presentation_feedback *proxy;
struct latency_feedback *next;
};
@@ -329,7 +329,7 @@ static void feedback_destroy(struct latency_feedback *feedback)
free(feedback);
}
-void surface_feedback_destroy(struct yasl_surface *w)
+void surface_feedback_destroy(struct wayland_surface *w)
{
while (w->latency_feedbacks) feedback_destroy(w->latency_feedbacks);
}
@@ -346,7 +346,7 @@ static void presented(void *data, struct wp_presentation_feedback *fb,
{
(void)seq_hi; (void)seq_lo; (void)flags;
struct latency_feedback *feedback = data;
- struct yasl_surface *w = feedback->window;
+ struct wayland_surface *w = feedback->window;
if (w->conn->pres_clock_known) {
uint64_t ns = conn_pres_to_mono(w->conn,
(((uint64_t)tv_sec_hi << 32) | tv_sec_lo) * 1000000000ull + tv_nsec);
@@ -371,7 +371,7 @@ static const struct wp_presentation_feedback_listener feedback_listener = {
.discarded = discarded,
};
-void surface_request_presentation_feedback(struct yasl_surface *w)
+void surface_request_presentation_feedback(struct wayland_surface *w)
{
if (!w || !w->conn->presentation)
return;
@@ -389,7 +389,7 @@ void surface_request_presentation_feedback(struct yasl_surface *w)
wp_presentation_feedback_add_listener(fb, &feedback_listener, feedback);
}
-static void commit_buffer(struct yasl_surface *w, int idx)
+static void commit_buffer(struct wayland_surface *w, int idx)
{
wl_surface_attach(w->surface, w->buffers[idx].proxy, 0, 0);
@@ -432,7 +432,7 @@ static void commit_buffer(struct yasl_surface *w, int idx)
w->buffers[idx].presented = true;
}
-bool yasl_surface_present(struct yasl_surface *w, const struct yasl_framebuffer *fb,
+bool wayland_surface_present(struct wayland_surface *w, const struct yasl_framebuffer *fb,
const struct yasl_damage_list *damage)
{
if (!w || w->closed || !w->frame_active || w->frame_presented || !fb ||
@@ -450,7 +450,7 @@ bool yasl_surface_present(struct yasl_surface *w, const struct yasl_framebuffer
return true;
}
-void surface_draw_frame(struct yasl_surface *w)
+void surface_draw_frame(struct wayland_surface *w)
{
if (w->closed || !w->configured)
return;
@@ -477,7 +477,7 @@ void surface_draw_frame(struct yasl_surface *w)
memset(w->buffers[idx].pixels, 0, (size_t)w->width * (size_t)w->height * sizeof(uint32_t));
w->damage = (struct yasl_damage_list){0};
w->frame = (struct yasl_frame){
- .surface = w,
+ .surface = &w->base,
.target = {
.pixels = w->buffers[idx].pixels,
.size = { .x = w->width, .y = w->height },
@@ -490,13 +490,13 @@ void surface_draw_frame(struct yasl_surface *w)
};
w->frame_active = true;
w->frame_presented = false;
- w->cbs->draw(w, &w->frame, w->ud);
+ w->cbs->draw(&w->base, &w->frame, w->ud);
w->frame_active = false;
if (!w->closed && !w->frame_presented)
w->frames_skipped++;
}
-int surface_init_scaling(struct yasl_surface *w)
+int surface_init_scaling(struct wayland_surface *w)
{
wl_surface_add_listener(w->surface, &surface_listener, w);
if (w->conn->viewporter) {
@@ -512,7 +512,7 @@ int surface_init_scaling(struct yasl_surface *w)
return 0;
}
-void yasl_surface_set_title(struct yasl_surface *w, const char *title)
+void wayland_surface_set_title(struct wayland_surface *w, const char *title)
{
if (!w || !w->toplevel || !title) return;
char *copy = yasl_utf8_sanitize_dup(title);
@@ -521,7 +521,7 @@ void yasl_surface_set_title(struct yasl_surface *w, const char *title)
free(copy);
}
-uint32_t yasl_surface_state(const struct yasl_surface *w)
+uint32_t wayland_surface_state(const struct wayland_surface *w)
{
if (!w) return 0;
uint32_t s = 0;
@@ -533,7 +533,7 @@ uint32_t yasl_surface_state(const struct yasl_surface *w)
return s;
}
-struct yasl_timing yasl_surface_timing(const struct yasl_surface *w)
+struct yasl_timing wayland_surface_timing(const struct wayland_surface *w)
{
struct yasl_timing t = {
.refresh_ns = w->clock.refresh_ns,
@@ -545,7 +545,7 @@ struct yasl_timing yasl_surface_timing(const struct yasl_surface *w)
return t;
}
-uint64_t yasl_surface_frame_time_ns(struct yasl_surface *w, uint64_t now)
+uint64_t wayland_surface_frame_time_ns(struct wayland_surface *w, uint64_t now)
{
return yasl_clock_frame_timestamp_ns(&w->clock, now);
}
diff --git a/src/wayland/drag.c b/src/wayland/drag.c
index 107ec52..7c15002 100644
--- a/src/wayland/drag.c
+++ b/src/wayland/drag.c
@@ -11,7 +11,7 @@ static void icon_clear(struct drag_icon *icon)
*icon = (struct drag_icon){0};
}
-static bool icon_create(struct yasl_display *c, const struct yasl_drag_image *image)
+static bool icon_create(struct wayland_display *c, const struct yasl_drag_image *image)
{
struct drag_icon *icon = &c->drag.icon;
size_t bytes;
@@ -48,7 +48,7 @@ static bool icon_create(struct yasl_display *c, const struct yasl_drag_image *im
return true;
}
-static void icon_show(struct yasl_display *c, const struct yasl_drag_image *image)
+static void icon_show(struct wayland_display *c, const struct yasl_drag_image *image)
{
struct drag_icon *icon = &c->drag.icon;
uint32_t scale = c->drag.scale_120;
@@ -73,7 +73,7 @@ static void icon_show(struct yasl_display *c, const struct yasl_drag_image *imag
wl_surface_commit(icon->surface);
}
-static void drag_clear(struct yasl_display *c, bool ended)
+static void drag_clear(struct wayland_display *c, bool ended)
{
struct conn_drag *d = &c->drag;
if (d->toplevel) {
@@ -88,7 +88,7 @@ static void drag_clear(struct yasl_display *c, bool ended)
*d = (struct conn_drag){0};
}
-static void drag_finish(struct yasl_display *c, enum yasl_drag_end how, bool ended)
+static void drag_finish(struct wayland_display *c, enum yasl_drag_end how, bool ended)
{
const struct yasl_drag_listener *l = c->drag.listener;
void *ud = c->drag.ud;
@@ -97,7 +97,7 @@ static void drag_finish(struct yasl_display *c, enum yasl_drag_end how, bool end
l->end(ud, how);
}
-void conn_drag_end(struct yasl_display *c)
+void conn_drag_end(struct wayland_display *c)
{
if (c && c->drag.source)
drag_finish(c, YASL_DRAG_CANCELLED, false);
@@ -110,7 +110,7 @@ static void source_action(void *ud, struct wl_data_source *s, uint32_t action) {
static void source_cancelled(void *ud, struct wl_data_source *s)
{
(void)s;
- struct yasl_display *c = ud;
+ struct wayland_display *c = ud;
bool released = c->drag.dropped || !c->drag.carrying;
drag_finish(c, released ? YASL_DRAG_DROPPED : YASL_DRAG_CANCELLED, true);
}
@@ -118,7 +118,7 @@ static void source_cancelled(void *ud, struct wl_data_source *s)
static void source_dropped(void *ud, struct wl_data_source *s)
{
(void)s;
- ((struct yasl_display *)ud)->drag.dropped = true;
+ ((struct wayland_display *)ud)->drag.dropped = true;
}
static void source_finished(void *ud, struct wl_data_source *s)
@@ -136,9 +136,9 @@ static const struct wl_data_source_listener source_listener = {
.action = source_action,
};
-static struct seat *drag_seat(struct yasl_display *c, struct yasl_surface *origin)
+static struct seat *drag_seat(struct wayland_display *c, struct wayland_surface *origin)
{
- struct yasl_surface *root = surface_root(origin);
+ struct wayland_surface *root = surface_root(origin);
struct seat *active = conn_active_seat(c);
if (active && active->press_serial &&
surface_root(active->press_surface) == root)
@@ -149,7 +149,7 @@ static struct seat *drag_seat(struct yasl_display *c, struct yasl_surface *origi
return NULL;
}
-bool yasl_display_drag_start(struct yasl_display *c, struct yasl_surface *origin,
+bool wayland_display_drag_start(struct wayland_display *c, struct wayland_surface *origin,
const struct yasl_drag_image *image,
const struct yasl_drag_listener *l, void *ud)
{
@@ -187,15 +187,15 @@ bool yasl_display_drag_start(struct yasl_display *c, struct yasl_surface *origin
return true;
}
-void yasl_display_drag_cancel(struct yasl_display *c)
+void wayland_display_drag_cancel(struct wayland_display *c)
{
if (c && c->drag.source)
drag_clear(c, false);
}
-bool yasl_surface_drag_carry(struct yasl_surface *w, struct yasl_vector2i offset)
+bool wayland_surface_drag_carry(struct wayland_surface *w, struct yasl_vector2i offset)
{
- struct yasl_display *c = w ? w->conn : NULL;
+ struct wayland_display *c = w ? w->conn : NULL;
if (!c || !c->drag.source || !c->drag.toplevel || !w->toplevel)
return false;
uint32_t scale = c->drag.scale_120;
@@ -206,14 +206,14 @@ bool yasl_surface_drag_carry(struct yasl_surface *w, struct yasl_vector2i offset
return true;
}
-bool yasl_surface_place_under_pointer(struct yasl_surface *w, struct yasl_vector2i at)
+bool wayland_surface_place_under_pointer(struct wayland_surface *w, struct yasl_vector2i at)
{
(void)w;
(void)at;
return false;
}
-static struct yasl_vector2i drag_device_pos(const struct yasl_surface *w, double x, double y)
+static struct yasl_vector2i drag_device_pos(const struct wayland_surface *w, double x, double y)
{
double dx = x * w->scale_factor, dy = y * w->scale_factor;
return (struct yasl_vector2i){
@@ -222,20 +222,20 @@ static struct yasl_vector2i drag_device_pos(const struct yasl_surface *w, double
};
}
-void conn_drop_target(struct yasl_display *c, enum yasl_drop_event ev,
+void conn_drop_target(struct wayland_display *c, enum yasl_drop_event ev,
struct wl_surface *on, double x, double y)
{
- struct yasl_surface *w = conn_surface_for(c, on);
+ struct wayland_surface *w = conn_surface_for(c, on);
if (!w || w->parent || !w->cbs->drop)
return;
- w->cbs->drop(w, ev, drag_device_pos(w, x, y), w->ud);
+ w->cbs->drop(&w->base, ev, drag_device_pos(w, x, y), w->ud);
}
-void conn_drag_target(struct yasl_display *c, enum yasl_drag_event ev,
+void conn_drag_target(struct wayland_display *c, enum yasl_drag_event ev,
struct wl_surface *on, double x, double y)
{
- struct yasl_surface *w = conn_surface_for(c, on);
+ struct wayland_surface *w = conn_surface_for(c, on);
if (!w || w->parent || !w->cbs->drag)
return;
- w->cbs->drag(w, ev, drag_device_pos(w, x, y), w->ud);
+ w->cbs->drag(&w->base, ev, drag_device_pos(w, x, y), w->ud);
}
diff --git a/src/wayland/ime.c b/src/wayland/ime.c
index 9da019c..74db53f 100644
--- a/src/wayland/ime.c
+++ b/src/wayland/ime.c
@@ -2,7 +2,7 @@
#define IME_TEXT_MAX (256u * 1024)
-static void show_preedit(struct yasl_surface *w, char *text, int begin, int end)
+static void show_preedit(struct wayland_surface *w, char *text, int begin, int end)
{
bool changed = (text || w->ime_shown) &&
(!text || !w->ime_shown || strcmp(text, w->ime_shown) ||
@@ -12,10 +12,10 @@ static void show_preedit(struct yasl_surface *w, char *text, int begin, int end)
w->ime_shown_begin = begin;
w->ime_shown_end = end;
if (changed)
- yasl_surface_schedule_redraw(w);
+ wayland_surface_schedule_redraw(w);
}
-void ime_reset(struct yasl_surface *w)
+void ime_reset(struct wayland_surface *w)
{
free(w->ime_preedit);
w->ime_preedit = NULL;
@@ -24,7 +24,7 @@ void ime_reset(struct yasl_surface *w)
show_preedit(w, NULL, -1, -1);
}
-void ime_send_caret(struct yasl_surface *w)
+void ime_send_caret(struct wayland_surface *w)
{
struct seat *seat = w->ime_seat;
if (!seat || !seat->text_input)
@@ -38,12 +38,12 @@ void ime_send_caret(struct yasl_surface *w)
zwp_text_input_v3_commit(seat->text_input);
}
-const char *yasl_surface_ime_preedit(const struct yasl_surface *w)
+const char *wayland_surface_ime_preedit(const struct wayland_surface *w)
{
return w ? w->ime_shown : NULL;
}
-bool yasl_surface_ime_preedit_cursor(const struct yasl_surface *w, int *begin, int *end)
+bool wayland_surface_ime_preedit_cursor(const struct wayland_surface *w, int *begin, int *end)
{
if (!w || !w->ime_shown || w->ime_shown_begin < 0)
return false;
@@ -52,7 +52,7 @@ bool yasl_surface_ime_preedit_cursor(const struct yasl_surface *w, int *begin, i
return true;
}
-void yasl_surface_set_ime_caret(struct yasl_surface *w, struct yasl_rect2i caret)
+void wayland_surface_set_ime_caret(struct wayland_surface *w, struct yasl_rect2i caret)
{
if (!w || (w->ime_caret.x == caret.x && w->ime_caret.y == caret.y &&
w->ime_caret.width == caret.width && w->ime_caret.height == caret.height))
@@ -65,7 +65,7 @@ static void text_input_enter(void *data, struct zwp_text_input_v3 *text_input,
struct wl_surface *surface)
{
struct seat *s = data;
- struct yasl_surface *w = surface_root(conn_surface_for(s->conn, surface));
+ struct wayland_surface *w = surface_root(conn_surface_for(s->conn, surface));
s->ime_focus = w;
if (!w) return;
zwp_text_input_v3_enable(text_input);
@@ -81,7 +81,7 @@ static void text_input_leave(void *data, struct zwp_text_input_v3 *text_input,
{
(void)surface;
struct seat *s = data;
- struct yasl_surface *w = s->ime_focus;
+ struct wayland_surface *w = s->ime_focus;
s->ime_focus = NULL;
if (!w) return;
zwp_text_input_v3_disable(text_input);
@@ -96,7 +96,7 @@ static void text_input_preedit_string(void *data,
int32_t cursor_begin, int32_t cursor_end)
{
(void)text_input;
- struct yasl_surface *w = ((struct seat *)data)->ime_focus;
+ struct wayland_surface *w = ((struct seat *)data)->ime_focus;
if (!w) return;
free(w->ime_preedit);
w->ime_preedit = text ? strndup(text, IME_TEXT_MAX) : NULL;
@@ -111,7 +111,7 @@ static void text_input_commit_string(void *data,
struct zwp_text_input_v3 *text_input, const char *text)
{
(void)text_input;
- struct yasl_surface *w = ((struct seat *)data)->ime_focus;
+ struct wayland_surface *w = ((struct seat *)data)->ime_focus;
if (!w) return;
free(w->ime_commit);
w->ime_commit = (text && text[0]) ? strndup(text, IME_TEXT_MAX) : NULL;
@@ -128,12 +128,12 @@ static void text_input_done(void *data, struct zwp_text_input_v3 *text_input,
uint32_t serial)
{
(void)text_input; (void)serial;
- struct yasl_surface *w = ((struct seat *)data)->ime_focus;
+ struct wayland_surface *w = ((struct seat *)data)->ime_focus;
if (!w) return;
if (w->ime_commit) {
struct yasl_input_event ev = {
.kind = YASL_INPUT_TEXT,
- .surface = w,
+ .surface = &w->base,
.text = { .text = w->ime_commit, .len = strlen(w->ime_commit) },
};
input_queue_push(&w->input, &ev);
diff --git a/src/wayland/internal.h b/src/wayland/internal.h
index dc85943..6b9001f 100644
--- a/src/wayland/internal.h
+++ b/src/wayland/internal.h
@@ -3,7 +3,7 @@
#define _GNU_SOURCE
-#include "yasl/yasl.h"
+#include "api.h"
#include "yasl/timing.h"
#include "clipboard.h"
@@ -41,13 +41,13 @@
#define NBUF 3
-struct yasl_surface;
+struct wayland_surface;
struct tablet_tool;
struct tablet_device;
struct tablet_pad;
struct buffer {
- struct yasl_surface *owner;
+ struct wayland_surface *owner;
struct wl_shm_pool *pool;
struct wl_buffer *proxy;
uint32_t *pixels;
@@ -58,7 +58,7 @@ struct buffer {
};
struct wl_conn_output {
- struct yasl_display *conn;
+ struct wayland_display *conn;
struct wl_output *proxy;
struct wl_conn_output *next;
uint64_t mask;
@@ -68,7 +68,7 @@ struct wl_conn_output {
};
struct pending_press {
- struct yasl_surface *surface;
+ struct wayland_surface *surface;
struct yasl_vector2i pos;
int button;
bool release;
@@ -104,7 +104,7 @@ struct conn_drag {
#define SEAT_TOUCH_POINTS 10
struct touch_point {
- struct yasl_surface *surface;
+ struct wayland_surface *surface;
int32_t id;
double x, y;
bool active;
@@ -112,7 +112,7 @@ struct touch_point {
};
struct seat {
- struct yasl_display *conn;
+ struct wayland_display *conn;
struct seat *next;
struct wl_seat *proxy;
uint32_t name;
@@ -140,14 +140,14 @@ struct seat {
uint32_t repeat_key;
bool repeat_held;
- struct yasl_surface *pointer_focus;
- struct yasl_surface *keyboard_focus;
- struct yasl_surface *tablet_focus;
- struct yasl_surface *ime_focus;
- struct yasl_surface *focus_leaving;
+ struct wayland_surface *pointer_focus;
+ struct wayland_surface *keyboard_focus;
+ struct wayland_surface *tablet_focus;
+ struct wayland_surface *ime_focus;
+ struct wayland_surface *focus_leaving;
uint32_t input_serial;
uint32_t press_serial;
- struct yasl_surface *press_surface;
+ struct wayland_surface *press_surface;
uint32_t pointer_serial;
int cursor_shape;
@@ -161,7 +161,7 @@ struct seat {
bool axis_smooth;
bool motion_pending;
struct press_queue ptr_presses;
- struct yasl_surface *ptr_left;
+ struct wayland_surface *ptr_left;
struct yasl_vector2i ptr_left_pos;
bool ptr_left_motion;
@@ -210,7 +210,8 @@ static inline void input_queue_clear(struct input_queue *q)
q->head = q->tail = q->count = 0;
}
-struct yasl_display {
+struct wayland_display {
+ struct yasl_display base;
struct wl_display *wl;
struct wl_registry *registry;
struct wl_compositor *compositor;
@@ -244,20 +245,21 @@ struct yasl_display {
bool pres_clock_known;
struct xdg_toplevel_drag_manager_v1 *toplevel_drag_mgr;
struct conn_drag drag;
- struct yasl_surface *surfaces;
- struct yasl_surface *paste_target;
+ struct wayland_surface *surfaces;
+ struct wayland_surface *paste_target;
int watch;
int depth;
- struct yasl_surface *dead;
+ struct wayland_surface *dead;
bool reading;
bool lost;
};
-struct yasl_surface {
- struct yasl_display *conn;
- struct yasl_surface *conn_next;
- struct yasl_surface *dead_next;
- struct yasl_surface *parent;
+struct wayland_surface {
+ struct yasl_surface base;
+ struct wayland_display *conn;
+ struct wayland_surface *conn_next;
+ struct wayland_surface *dead_next;
+ struct wayland_surface *parent;
struct wl_surface *surface;
struct xdg_surface *xdg_surface;
struct xdg_toplevel *toplevel;
@@ -325,12 +327,12 @@ bool yasl_utf8_validate(const char *str, size_t len);
int device_px(int logical, uint32_t scale_120);
bool buffer_size(int width, int height, size_t *bytes);
-int buffer_reserve(struct yasl_surface *w, struct buffer *b, size_t needed);
+int buffer_reserve(struct wayland_surface *w, struct buffer *b, size_t needed);
void buffer_destroy(struct buffer *b);
int buffer_pick_free_index(const struct buffer *bufs, int cur);
-int buffer_prepare(struct yasl_surface *w, struct buffer *b, int width, int height,
+int buffer_prepare(struct wayland_surface *w, struct buffer *b, int width, int height,
const struct wl_buffer_listener *listener);
-int apply_pending_geometry(struct yasl_surface *w);
+int apply_pending_geometry(struct wayland_surface *w);
int logical_px_ceil(int device, uint32_t scale_120);
static inline void wl_damage_list(struct wl_surface *s, const struct yasl_damage_list *d)
@@ -345,8 +347,8 @@ static inline void wl_damage_list(struct wl_surface *s, const struct yasl_damage
d->rects[i].width, d->rects[i].height);
}
-void surface_update_opaque_region(struct yasl_surface *w);
-int surface_init_scaling(struct yasl_surface *w);
+void surface_update_opaque_region(struct wayland_surface *w);
+int surface_init_scaling(struct wayland_surface *w);
static inline bool surface_gets_preferred_scale(struct wl_surface *s)
{
@@ -354,65 +356,65 @@ static inline bool surface_gets_preferred_scale(struct wl_surface *s)
WL_SURFACE_PREFERRED_BUFFER_SCALE_SINCE_VERSION;
}
-uint64_t conn_output_mask(const struct yasl_display *c, const struct wl_output *proxy);
-uint32_t conn_output_scale_120(const struct yasl_display *c, uint64_t outputs);
-void conn_destroy_outputs(struct yasl_display *c);
-void surface_follow_outputs(struct yasl_surface *w);
-uint64_t conn_pres_to_mono(const struct yasl_display *c, uint64_t ns);
-uint64_t conn_mono_to_pres(const struct yasl_display *c, uint64_t ns);
-void surface_draw_frame(struct yasl_surface *w);
-void surface_fail(struct yasl_surface *w);
-void display_enter(struct yasl_display *c);
-void display_leave(struct yasl_display *c);
+uint64_t conn_output_mask(const struct wayland_display *c, const struct wl_output *proxy);
+uint32_t conn_output_scale_120(const struct wayland_display *c, uint64_t outputs);
+void conn_destroy_outputs(struct wayland_display *c);
+void surface_follow_outputs(struct wayland_surface *w);
+uint64_t conn_pres_to_mono(const struct wayland_display *c, uint64_t ns);
+uint64_t conn_mono_to_pres(const struct wayland_display *c, uint64_t ns);
+void surface_draw_frame(struct wayland_surface *w);
+void surface_fail(struct wayland_surface *w);
+void display_enter(struct wayland_display *c);
+void display_leave(struct wayland_display *c);
-struct yasl_surface *conn_surface_for(struct yasl_display *c, struct wl_surface *s);
+struct wayland_surface *conn_surface_for(struct wayland_display *c, struct wl_surface *s);
-static inline struct yasl_surface *surface_root(struct yasl_surface *w)
+static inline struct wayland_surface *surface_root(struct wayland_surface *w)
{
while (w && w->parent)
w = w->parent;
return w;
}
-void conn_drag_end(struct yasl_display *c);
-void conn_drop_target(struct yasl_display *c, enum yasl_drop_event ev,
+void conn_drag_end(struct wayland_display *c);
+void conn_drop_target(struct wayland_display *c, enum yasl_drop_event ev,
struct wl_surface *on, double x, double y);
-void conn_drag_target(struct yasl_display *c, enum yasl_drag_event ev,
+void conn_drag_target(struct wayland_display *c, enum yasl_drag_event ev,
struct wl_surface *on, double x, double y);
-void seat_bind(struct yasl_display *c, struct wl_registry *registry,
+void seat_bind(struct wayland_display *c, struct wl_registry *registry,
uint32_t name, uint32_t version);
-bool seat_remove(struct yasl_display *c, uint32_t name);
+bool seat_remove(struct wayland_display *c, uint32_t name);
void seat_destroy(struct seat *s);
-struct seat *conn_active_seat(const struct yasl_display *c);
+struct seat *conn_active_seat(const struct wayland_display *c);
void seat_note_input(struct seat *s, uint32_t serial);
-void seat_forget_surface(struct seat *s, struct yasl_surface *w);
+void seat_forget_surface(struct seat *s, struct wayland_surface *w);
void seat_clipboard_ensure(struct seat *s);
-int display_input_init(struct yasl_display *c);
+int display_input_init(struct wayland_display *c);
extern const struct wl_seat_listener seat_listener;
void keyboard_repeat_stop(struct seat *s);
void keyboard_repeat_sync(struct seat *s);
int keyboard_repeat_init(struct seat *s);
-void keyboard_settle_focus(struct yasl_display *c);
-bool conn_keyboard_on(const struct yasl_display *c, const struct yasl_surface *w,
+void keyboard_settle_focus(struct wayland_display *c);
+bool conn_keyboard_on(const struct wayland_display *c, const struct wayland_surface *w,
const struct seat *except);
extern const struct wl_keyboard_listener keyboard_listener;
int seat_modifiers(const struct seat *s);
-void surface_init_cursor(struct yasl_display *c);
+void surface_init_cursor(struct wayland_display *c);
void seat_destroy_tablet(struct seat *s);
void seat_pointer_reset(struct seat *s);
extern const struct zwp_text_input_v3_listener text_input_listener;
-void ime_reset(struct yasl_surface *w);
-void ime_send_caret(struct yasl_surface *w);
+void ime_reset(struct wayland_surface *w);
+void ime_send_caret(struct wayland_surface *w);
-int surface_init_shell(struct yasl_surface *w, const char *title);
+int surface_init_shell(struct wayland_surface *w, const char *title);
extern const struct xdg_surface_listener shell_surface_listener;
extern const struct wl_registry_listener registry_listener;
-void surface_feedback_destroy(struct yasl_surface *w);
-void surface_request_presentation_feedback(struct yasl_surface *w);
+void surface_feedback_destroy(struct wayland_surface *w);
+void surface_request_presentation_feedback(struct wayland_surface *w);
#endif
diff --git a/src/wayland/keyboard.c b/src/wayland/keyboard.c
index 7283d58..1746ac6 100644
--- a/src/wayland/keyboard.c
+++ b/src/wayland/keyboard.c
@@ -112,13 +112,13 @@ static void keyboard_keymap(void *data, struct wl_keyboard *keyboard,
}
}
-static void keyboard_reset_keys(struct seat *s, struct yasl_surface *w)
+static void keyboard_reset_keys(struct seat *s, struct wayland_surface *w)
{
(void)w;
keyboard_repeat_stop(s);
}
-bool conn_keyboard_on(const struct yasl_display *c, const struct yasl_surface *w,
+bool conn_keyboard_on(const struct wayland_display *c, const struct wayland_surface *w,
const struct seat *except)
{
for (const struct seat *s = c->seats; s; s = s->next)
@@ -127,11 +127,11 @@ bool conn_keyboard_on(const struct yasl_display *c, const struct yasl_surface *w
return false;
}
-static void push_focus(struct yasl_surface *w, bool focused)
+static void push_focus(struct wayland_surface *w, bool focused)
{
struct yasl_input_event ev = {
.kind = YASL_INPUT_FOCUS,
- .surface = w,
+ .surface = &w->base,
.focus = { .focused = focused },
};
input_queue_push(&w->input, &ev);
@@ -142,7 +142,7 @@ static void keyboard_enter(void *data, struct wl_keyboard *keyboard,
{
(void)keyboard; (void)serial; (void)keys;
struct seat *s = data;
- struct yasl_surface *w = surface_root(conn_surface_for(s->conn, surface));
+ struct wayland_surface *w = surface_root(conn_surface_for(s->conn, surface));
bool same_window = w && w == s->focus_leaving;
if (same_window)
s->focus_leaving = NULL;
@@ -159,7 +159,7 @@ static void keyboard_enter(void *data, struct wl_keyboard *keyboard,
static void seat_settle_focus(struct seat *s)
{
- struct yasl_surface *w = s->focus_leaving;
+ struct wayland_surface *w = s->focus_leaving;
if (!w)
return;
s->focus_leaving = NULL;
@@ -167,7 +167,7 @@ static void seat_settle_focus(struct seat *s)
push_focus(w, false);
}
-void keyboard_settle_focus(struct yasl_display *c)
+void keyboard_settle_focus(struct wayland_display *c)
{
for (struct seat *s = c->seats; s; s = s->next)
seat_settle_focus(s);
@@ -178,7 +178,7 @@ static void keyboard_leave(void *data, struct wl_keyboard *keyboard,
{
(void)keyboard; (void)serial; (void)surface;
struct seat *s = data;
- struct yasl_surface *w = s->keyboard_focus;
+ struct wayland_surface *w = s->keyboard_focus;
s->keyboard_focus = NULL;
if (!w) return;
keyboard_reset_keys(s, w);
@@ -231,7 +231,7 @@ static struct yasl_key_event xkb_key_event(struct seat *s, uint32_t key,
return k;
}
-static bool keyboard_dispatch_key(struct seat *s, struct yasl_surface *w, uint32_t key,
+static bool keyboard_dispatch_key(struct seat *s, struct wayland_surface *w, uint32_t key,
enum yasl_key_action action)
{
if (!s->xkb_state || !w->cbs) return false;
@@ -239,7 +239,7 @@ static bool keyboard_dispatch_key(struct seat *s, struct yasl_surface *w, uint32
struct yasl_key_event k = xkb_key_event(s, key, action);
struct yasl_input_event ev = {
.kind = YASL_INPUT_KEY,
- .surface = w,
+ .surface = &w->base,
.key = k,
};
input_queue_push(&w->input, &ev);
@@ -251,7 +251,7 @@ static void keyboard_key(void *data, struct wl_keyboard *keyboard,
{
(void)keyboard; (void)time;
struct seat *s = data;
- struct yasl_surface *w = s->keyboard_focus;
+ struct wayland_surface *w = s->keyboard_focus;
if (!w) return;
seat_note_input(s, serial);
if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
@@ -276,7 +276,7 @@ static int keyboard_repeat_ready(int fd, short revents, void *data)
uint64_t count;
if (!(revents & POLLIN) || read(fd, &count, sizeof(count)) != sizeof(count)) return 0;
- struct yasl_surface *w = s->keyboard_focus;
+ struct wayland_surface *w = s->keyboard_focus;
if (!w) {
keyboard_repeat_stop(s);
return 0;
@@ -355,12 +355,12 @@ int seat_modifiers(const struct seat *s)
return mods;
}
-int yasl_display_modifiers(const struct yasl_display *c)
+int wayland_display_modifiers(const struct wayland_display *c)
{
return c ? seat_modifiers(conn_active_seat(c)) : 0;
}
-void yasl_display_copy(struct yasl_display *c, enum yasl_selection sel, const char *text)
+void wayland_display_copy(struct wayland_display *c, enum yasl_selection sel, const char *text)
{
struct seat *s = c ? conn_active_seat(c) : NULL;
if (!s || !s->clipboard)
@@ -371,7 +371,7 @@ void yasl_display_copy(struct yasl_display *c, enum yasl_selection sel, const ch
clipboard_copy(s->clipboard, text, s->input_serial);
}
-void yasl_display_paste(struct yasl_display *c, enum yasl_selection sel, struct yasl_surface *target)
+void wayland_display_paste(struct wayland_display *c, enum yasl_selection sel, struct wayland_surface *target)
{
struct seat *s = c ? conn_active_seat(c) : NULL;
if (!s || !s->clipboard)
@@ -383,7 +383,7 @@ void yasl_display_paste(struct yasl_display *c, enum yasl_selection sel, struct
clipboard_paste(s->clipboard);
}
-bool yasl_surface_input_poll(struct yasl_surface *w, struct yasl_input_event *ev)
+bool wayland_surface_input_poll(struct wayland_surface *w, struct yasl_input_event *ev)
{
return w && ev && input_queue_pop(&w->input, ev);
}
diff --git a/src/wayland/meson.build b/src/wayland/meson.build
new file mode 100644
index 0000000..ca83755
--- /dev/null
+++ b/src/wayland/meson.build
@@ -0,0 +1,13 @@
+subdir('protocols')
+sources += wl_protocol_src + files(
+ 'backend.c',
+ 'buffer.c',
+ 'clipboard.c',
+ 'drag.c',
+ 'ime.c',
+ 'keyboard.c',
+ 'pointer.c',
+ 'popup.c',
+ 'shell.c',
+ 'surface.c',
+)
diff --git a/src/wayland/pointer.c b/src/wayland/pointer.c
index 37e72f3..f2902b4 100644
--- a/src/wayland/pointer.c
+++ b/src/wayland/pointer.c
@@ -30,7 +30,7 @@ static int device_px_round(double v)
return (int)(v < 0 ? v - 0.5 : v + 0.5);
}
-static struct yasl_vector2i device_from_fixed(const struct yasl_surface *w,
+static struct yasl_vector2i device_from_fixed(const struct wayland_surface *w,
wl_fixed_t x, wl_fixed_t y)
{
return (struct yasl_vector2i){
@@ -53,23 +53,23 @@ void seat_note_input(struct seat *s, uint32_t serial)
s->conn->active_seat = s;
}
-struct seat *conn_active_seat(const struct yasl_display *c)
+struct seat *conn_active_seat(const struct wayland_display *c)
{
return c->active_seat ? c->active_seat : c->seats;
}
-static void push_mouse(struct seat *s, struct yasl_surface *w, struct yasl_mouse_event ev)
+static void push_mouse(struct seat *s, struct wayland_surface *w, struct yasl_mouse_event ev)
{
ev.mods = (unsigned)seat_modifiers(s);
struct yasl_input_event input_ev = {
.kind = YASL_INPUT_MOUSE,
- .surface = w,
+ .surface = &w->base,
.mouse = ev,
};
input_queue_push(&surface_root(w)->input, &input_ev);
}
-static void report_mouse(struct seat *s, struct yasl_surface *w, struct yasl_vector2i pos,
+static void report_mouse(struct seat *s, struct wayland_surface *w, struct yasl_vector2i pos,
int button, enum yasl_pointer_kind kind)
{
push_mouse(s, w, (struct yasl_mouse_event){
@@ -77,7 +77,7 @@ static void report_mouse(struct seat *s, struct yasl_surface *w, struct yasl_vec
});
}
-static void report_wheel(struct seat *s, struct yasl_surface *w, struct yasl_vector2i pos,
+static void report_wheel(struct seat *s, struct wayland_surface *w, struct yasl_vector2i pos,
int button, int lines, float delta)
{
push_mouse(s, w, (struct yasl_mouse_event){
@@ -86,7 +86,7 @@ static void report_wheel(struct seat *s, struct yasl_surface *w, struct yasl_vec
});
}
-static bool cursor_theme_for(struct yasl_display *c, int scale)
+static bool cursor_theme_for(struct wayland_display *c, int scale)
{
if (c->cursor_theme && c->cursor_theme_scale == scale)
return true;
@@ -103,7 +103,7 @@ static bool cursor_theme_for(struct yasl_display *c, int scale)
static bool seat_cursor_surface(struct seat *s)
{
- struct yasl_display *c = s->conn;
+ struct wayland_display *c = s->conn;
if (s->cursor_surface)
return true;
s->cursor_surface = wl_compositor_create_surface(c->compositor);
@@ -114,10 +114,10 @@ static bool seat_cursor_surface(struct seat *s)
return true;
}
-static void set_cursor_theme_fallback(struct seat *s, struct yasl_surface *w,
+static void set_cursor_theme_fallback(struct seat *s, struct wayland_surface *w,
enum yasl_cursor shape)
{
- struct yasl_display *c = s->conn;
+ struct wayland_display *c = s->conn;
int scale = (int)((w->scale_120 + YASL_SCALE_UNIT - 1) / YASL_SCALE_UNIT);
if (scale < 1) scale = 1;
if (!seat_cursor_surface(s) || !cursor_theme_for(c, scale)) return;
@@ -174,7 +174,7 @@ static uint32_t cursor_shape_of(enum yasl_cursor shape)
}
}
-static void seat_set_cursor(struct seat *s, struct yasl_surface *w, enum yasl_cursor shape)
+static void seat_set_cursor(struct seat *s, struct wayland_surface *w, enum yasl_cursor shape)
{
if (!s->pointer || !s->pointer_serial || s->pointer_focus != w ||
s->cursor_shape == (int)shape)
@@ -200,7 +200,7 @@ static void tool_set_cursor(struct tablet_tool *t, enum yasl_cursor shape)
cursor_shape_of(shape));
}
-void yasl_surface_set_cursor(struct yasl_surface *w, enum yasl_cursor shape)
+void wayland_surface_set_cursor(struct wayland_surface *w, enum yasl_cursor shape)
{
if (!w || !w->conn) return;
for (struct seat *s = w->conn->seats; s; s = s->next) {
@@ -211,7 +211,7 @@ void yasl_surface_set_cursor(struct yasl_surface *w, enum yasl_cursor shape)
}
static void press_queue_flush(struct seat *s, struct press_queue *q,
- struct yasl_surface *only, uint64_t *buttons,
+ struct wayland_surface *only, uint64_t *buttons,
struct yasl_mouse_event like)
{
int kept = 0;
@@ -233,7 +233,7 @@ static void press_queue_flush(struct seat *s, struct press_queue *q,
q->n = kept;
}
-static void press_queue_push(struct press_queue *q, struct yasl_surface *w,
+static void press_queue_push(struct press_queue *q, struct wayland_surface *w,
struct yasl_vector2i pos, int button, bool release)
{
if (q->n == (int)(sizeof(q->ev) / sizeof(q->ev[0]))) {
@@ -245,7 +245,7 @@ static void press_queue_push(struct press_queue *q, struct yasl_surface *w,
};
}
-static void press_queue_forget(struct press_queue *q, struct yasl_surface *w)
+static void press_queue_forget(struct press_queue *q, struct wayland_surface *w)
{
for (int i = 0; i < q->n; i++)
if (q->ev[i].surface == w)
@@ -274,7 +274,7 @@ static void pointer_event_done(struct seat *s)
pointer_frame(s, s->pointer);
}
-static void flush_pending_motion(struct seat *s, struct yasl_surface *w)
+static void flush_pending_motion(struct seat *s, struct wayland_surface *w)
{
if (!s->motion_pending) return;
s->motion_pending = false;
@@ -287,7 +287,7 @@ static void pointer_enter(void *data, struct wl_pointer *pointer,
{
(void)pointer;
struct seat *s = data;
- struct yasl_surface *w = conn_surface_for(s->conn, surface);
+ struct wayland_surface *w = conn_surface_for(s->conn, surface);
s->pointer_focus = w;
if (!w) return;
s->pointer_pos = device_from_fixed(w, surface_x, surface_y);
@@ -303,7 +303,7 @@ static void pointer_leave(void *data, struct wl_pointer *pointer,
{
(void)pointer; (void)serial; (void)surface;
struct seat *s = data;
- struct yasl_surface *w = s->pointer_focus;
+ struct wayland_surface *w = s->pointer_focus;
s->pointer_focus = NULL;
if (!w) return;
if (s->ptr_left)
@@ -320,7 +320,7 @@ static void pointer_motion(void *data, struct wl_pointer *pointer,
{
(void)pointer; (void)time;
struct seat *s = data;
- struct yasl_surface *w = s->pointer_focus;
+ struct wayland_surface *w = s->pointer_focus;
if (!w) return;
s->pointer_pos = device_from_fixed(w, surface_x, surface_y);
s->motion_pending = true;
@@ -332,7 +332,7 @@ static void pointer_button(void *data, struct wl_pointer *pointer,
{
(void)pointer; (void)time;
struct seat *s = data;
- struct yasl_surface *w = s->pointer_focus;
+ struct wayland_surface *w = s->pointer_focus;
if (!w) return;
int b;
switch (button) {
@@ -415,7 +415,7 @@ static void pointer_axis_value120(void *data, struct wl_pointer *pointer, uint32
}
}
-static void pointer_frame_vertical(struct seat *s, struct yasl_surface *w)
+static void pointer_frame_vertical(struct seat *s, struct wayland_surface *w)
{
if (s->axis_has_v120_v) {
int discrete = s->axis_value120_v / 120;
@@ -438,7 +438,7 @@ static void pointer_frame_vertical(struct seat *s, struct yasl_surface *w)
s->frame_v120 = 0;
}
-static void pointer_frame_horizontal(struct seat *s, struct yasl_surface *w)
+static void pointer_frame_horizontal(struct seat *s, struct wayland_surface *w)
{
if (s->axis_has_v120_h) {
int discrete = s->axis_value120_h / 120;
@@ -462,7 +462,7 @@ static void pointer_frame(void *data, struct wl_pointer *pointer)
{
(void)pointer;
struct seat *s = data;
- struct yasl_surface *left = s->ptr_left;
+ struct wayland_surface *left = s->ptr_left;
if (left) {
s->ptr_left = NULL;
if (s->ptr_left_motion)
@@ -479,7 +479,7 @@ static void pointer_frame(void *data, struct wl_pointer *pointer)
s->pointer_serial = serial;
s->cursor_shape = shape;
}
- struct yasl_surface *w = s->pointer_focus;
+ struct wayland_surface *w = s->pointer_focus;
if (!w) {
s->ptr_presses.n = 0;
return;
@@ -547,7 +547,7 @@ static int touch_count(const struct seat *s)
return n;
}
-static double touch_centroid_y(const struct seat *s, const struct yasl_surface *on)
+static double touch_centroid_y(const struct seat *s, const struct wayland_surface *on)
{
double sum = 0;
int n = 0;
@@ -576,7 +576,7 @@ static void touch_down(void *data, struct wl_touch *touch,
{
(void)touch; (void)time;
struct seat *s = data;
- struct yasl_surface *w = conn_surface_for(s->conn, surface);
+ struct wayland_surface *w = conn_surface_for(s->conn, surface);
if (!w || touch_find(s, id)) return;
struct touch_point *p = NULL;
for (int i = 0; i < SEAT_TOUCH_POINTS && !p; i++)
@@ -704,7 +704,7 @@ static void tablet_tool_proximity_in(void *data,
(void)tool; (void)tablet;
struct tablet_tool *t = data;
struct seat *s = t->seat;
- struct yasl_surface *w = conn_surface_for(s->conn, surface);
+ struct wayland_surface *w = conn_surface_for(s->conn, surface);
s->tablet_focus = w;
s->tool = t;
s->tool_buttons = 0;
@@ -723,7 +723,7 @@ static void tablet_tool_proximity_out(void *data, struct zwp_tablet_tool_v2 *too
(void)tool;
struct tablet_tool *t = data;
struct seat *s = t->seat;
- struct yasl_surface *w = s->tablet_focus;
+ struct wayland_surface *w = s->tablet_focus;
if (w) {
press_queue_flush(s, &s->tool_presses, NULL, &s->tool_buttons, tool_event(s));
struct yasl_mouse_event ev = tool_event(s);
@@ -743,7 +743,7 @@ static void tablet_tool_down(void *data, struct zwp_tablet_tool_v2 *tool, uint32
{
(void)tool;
struct seat *s = ((struct tablet_tool *)data)->seat;
- struct yasl_surface *w = s->tablet_focus;
+ struct wayland_surface *w = s->tablet_focus;
if (!w) return;
seat_note_input(s, serial);
s->press_serial = serial;
@@ -755,7 +755,7 @@ static void tablet_tool_up(void *data, struct zwp_tablet_tool_v2 *tool)
{
(void)tool;
struct seat *s = ((struct tablet_tool *)data)->seat;
- struct yasl_surface *w = s->tablet_focus;
+ struct wayland_surface *w = s->tablet_focus;
if (!w) return;
press_queue_push(&s->tool_presses, w, s->tool_pos, 0, true);
}
@@ -764,7 +764,7 @@ static void tablet_tool_motion(void *data, struct zwp_tablet_tool_v2 *tool, wl_f
{
(void)tool;
struct seat *s = ((struct tablet_tool *)data)->seat;
- struct yasl_surface *w = s->tablet_focus;
+ struct wayland_surface *w = s->tablet_focus;
if (!w) return;
s->tool_pos = device_from_fixed(w, x, y);
s->tool_motion = true;
@@ -775,7 +775,7 @@ static void tablet_tool_button(void *data, struct zwp_tablet_tool_v2 *tool,
{
(void)tool;
struct seat *s = ((struct tablet_tool *)data)->seat;
- struct yasl_surface *w = s->tablet_focus;
+ struct wayland_surface *w = s->tablet_focus;
if (!w) return;
seat_note_input(s, serial);
int b;
@@ -822,7 +822,7 @@ static void tool_frame(void *d, struct zwp_tablet_tool_v2 *t, uint32_t time)
{
(void)t; (void)time;
struct seat *s = ((struct tablet_tool *)d)->seat;
- struct yasl_surface *w = s->tablet_focus;
+ struct wayland_surface *w = s->tablet_focus;
if (!w) {
s->tool_presses.n = 0;
s->tool_wheel = 0;
@@ -1003,13 +1003,13 @@ static void clipboard_received(const char *text, size_t len, bool uri_list,
struct wl_surface *on, void *ud)
{
struct seat *s = ud;
- struct yasl_display *c = s->conn;
- struct yasl_surface *w = on ? surface_root(conn_surface_for(c, on)) : NULL;
+ struct wayland_display *c = s->conn;
+ struct wayland_surface *w = on ? surface_root(conn_surface_for(c, on)) : NULL;
if (!w)
w = c->paste_target ? c->paste_target : s->keyboard_focus;
if (!len || !w) return;
struct yasl_input_event ev = {
- .surface = w,
+ .surface = &w->base,
.kind = uri_list ? YASL_INPUT_DROP_FILES : YASL_INPUT_PASTE,
};
if (uri_list) {
@@ -1038,7 +1038,7 @@ static void clipboard_drop_hover(enum yasl_drop_event ev, struct wl_surface *on,
void seat_clipboard_ensure(struct seat *s)
{
- struct yasl_display *c = s->conn;
+ struct wayland_display *c = s->conn;
if (!c->data_manager || !s->proxy)
return;
if (!s->clipboard) {
@@ -1082,7 +1082,7 @@ static void seat_drop_keyboard(struct seat *s)
s->keyboard = NULL;
}
s->repeat_rate = 0;
- struct yasl_surface *w = s->keyboard_focus;
+ struct wayland_surface *w = s->keyboard_focus;
s->keyboard_focus = NULL;
if (w && !s->focus_leaving)
s->focus_leaving = w;
@@ -1103,7 +1103,7 @@ static void seat_drop_touch(struct seat *s)
static void seat_capabilities(void *data, struct wl_seat *proxy, uint32_t caps)
{
struct seat *s = data;
- struct yasl_display *c = s->conn;
+ struct wayland_display *c = s->conn;
if (caps & WL_SEAT_CAPABILITY_KEYBOARD) {
if (!s->keyboard) {
s->keyboard = wl_seat_get_keyboard(proxy);
@@ -1165,7 +1165,7 @@ const struct wl_seat_listener seat_listener = {
.name = seat_name,
};
-void seat_bind(struct yasl_display *c, struct wl_registry *registry,
+void seat_bind(struct wayland_display *c, struct wl_registry *registry,
uint32_t name, uint32_t version)
{
struct seat *s = calloc(1, sizeof(*s));
@@ -1186,9 +1186,9 @@ void seat_bind(struct yasl_display *c, struct wl_registry *registry,
keyboard_repeat_init(s);
}
-void seat_forget_surface(struct seat *s, struct yasl_surface *w)
+void seat_forget_surface(struct seat *s, struct wayland_surface *w)
{
- struct yasl_surface **refs[] = {
+ struct wayland_surface **refs[] = {
&s->pointer_focus, &s->keyboard_focus,
&s->tablet_focus, &s->ime_focus, &s->focus_leaving, &s->ptr_left,
&s->press_surface,
@@ -1211,7 +1211,7 @@ void seat_forget_surface(struct seat *s, struct yasl_surface *w)
void seat_destroy(struct seat *s)
{
- struct yasl_display *c = s->conn;
+ struct wayland_display *c = s->conn;
for (struct seat **link = &c->seats; *link; link = &(*link)->next) {
if (*link == s) {
*link = s->next;
@@ -1220,7 +1220,7 @@ void seat_destroy(struct seat *s)
}
if (c->active_seat == s)
c->active_seat = NULL;
- for (struct yasl_surface *w = c->surfaces; w; w = w->conn_next) {
+ for (struct wayland_surface *w = c->surfaces; w; w = w->conn_next) {
if (w->ime_seat == s) {
w->ime_seat = NULL;
ime_reset(w);
@@ -1233,11 +1233,11 @@ void seat_destroy(struct seat *s)
seat_destroy_tablet(s);
seat_drop_pointer(s);
seat_drop_keyboard(s);
- struct yasl_surface *left = s->focus_leaving;
+ struct wayland_surface *left = s->focus_leaving;
if (left && !conn_keyboard_on(c, left, NULL)) {
struct yasl_input_event ev = {
.kind = YASL_INPUT_FOCUS,
- .surface = left,
+ .surface = &left->base,
.focus = { .focused = false },
};
input_queue_push(&left->input, &ev);
@@ -1259,7 +1259,7 @@ void seat_destroy(struct seat *s)
free(s);
}
-bool seat_remove(struct yasl_display *c, uint32_t name)
+bool seat_remove(struct wayland_display *c, uint32_t name)
{
for (struct seat *s = c->seats; s; s = s->next) {
if (s->name == name) {
@@ -1270,7 +1270,7 @@ bool seat_remove(struct yasl_display *c, uint32_t name)
return false;
}
-int display_input_init(struct yasl_display *c)
+int display_input_init(struct wayland_display *c)
{
for (struct seat *s = c->seats; s; s = s->next) {
keyboard_repeat_init(s);
@@ -1279,7 +1279,7 @@ int display_input_init(struct yasl_display *c)
return 0;
}
-void surface_init_cursor(struct yasl_display *c)
+void surface_init_cursor(struct wayland_display *c)
{
if (c->cursor_shape_mgr)
return;
diff --git a/src/wayland/popup.c b/src/wayland/popup.c
index e809a43..f0ef305 100644
--- a/src/wayland/popup.c
+++ b/src/wayland/popup.c
@@ -32,7 +32,7 @@ static bool popup_spec_valid(const struct yasl_popup_spec *spec)
spec->content_offset.y + spec->content_size.y <= spec->size.y;
}
-static bool popup_apply_spec(struct yasl_surface *w, const struct yasl_popup_spec *spec)
+static bool popup_apply_spec(struct wayland_surface *w, const struct yasl_popup_spec *spec)
{
uint32_t scale = w->parent->scale_120;
struct yasl_vector2i logical = {
@@ -69,7 +69,7 @@ static bool popup_apply_spec(struct yasl_surface *w, const struct yasl_popup_spe
return true;
}
-static void popup_set_geometry(struct yasl_surface *w)
+static void popup_set_geometry(struct wayland_surface *w)
{
uint32_t scale = w->scale_120;
int gx = yasl_scale_to_logical(w->content.x, scale);
@@ -85,10 +85,10 @@ static void popup_set_geometry(struct yasl_surface *w)
xdg_surface_set_window_geometry(w->xdg_surface, gx, gy, gw, gh);
}
-static struct xdg_positioner *popup_positioner(struct yasl_surface *w,
+static struct xdg_positioner *popup_positioner(struct wayland_surface *w,
const struct yasl_popup_spec *spec)
{
- struct yasl_surface *parent = w->parent;
+ struct wayland_surface *parent = w->parent;
struct xdg_positioner *pos = xdg_wm_base_create_positioner(w->conn->wm_base);
if (!pos)
return NULL;
@@ -119,23 +119,24 @@ static struct xdg_positioner *popup_positioner(struct yasl_surface *w,
return pos;
}
-struct yasl_surface *yasl_surface_create_popup(struct yasl_surface *parent,
+struct wayland_surface *wayland_surface_create_popup(struct wayland_surface *parent,
const struct yasl_popup_spec *spec)
{
- struct yasl_display *c = parent ? parent->conn : NULL;
+ struct wayland_display *c = parent ? parent->conn : NULL;
struct seat *seat = c ? conn_active_seat(c) : NULL;
if (!c || c->lost || parent->closed || !parent->xdg_surface || !seat ||
!seat->input_serial || !popup_spec_valid(spec))
return NULL;
- struct yasl_surface *w = calloc(1, sizeof(*w));
+ struct wayland_surface *w = calloc(1, sizeof(*w));
if (!w)
return NULL;
+ w->base.display = &c->base;
w->conn = c;
w->conn_next = c->surfaces;
c->surfaces = w;
w->parent = parent;
- yasl_surface_set_callbacks(w, NULL, NULL);
+ wayland_surface_set_callbacks(w, NULL, NULL);
w->clock.refresh_ns = parent->clock.refresh_ns;
w->surface = wl_compositor_create_surface(c->compositor);
@@ -162,11 +163,11 @@ struct yasl_surface *yasl_surface_create_popup(struct yasl_surface *parent,
return w;
err:
- yasl_surface_destroy(w);
+ wayland_surface_destroy(w);
return NULL;
}
-bool yasl_surface_popup_reposition(struct yasl_surface *w, const struct yasl_popup_spec *spec)
+bool wayland_surface_popup_reposition(struct wayland_surface *w, const struct yasl_popup_spec *spec)
{
if (!w || !w->popup || w->closed || !w->conn || w->conn->lost ||
!popup_spec_valid(spec) ||
@@ -188,6 +189,6 @@ bool yasl_surface_popup_reposition(struct yasl_surface *w, const struct yasl_pop
static uint32_t token;
xdg_popup_reposition(w->popup, pos, ++token);
xdg_positioner_destroy(pos);
- yasl_surface_schedule_redraw(w);
+ wayland_surface_schedule_redraw(w);
return true;
}
diff --git a/src/wayland/shell.c b/src/wayland/shell.c
index ef72512..f068f48 100644
--- a/src/wayland/shell.c
+++ b/src/wayland/shell.c
@@ -7,7 +7,7 @@ static void presentation_clock_id(void *data, struct wp_presentation *presentati
uint32_t clk_id)
{
(void)presentation;
- struct yasl_display *c = data;
+ struct wayland_display *c = data;
struct timespec ts;
c->pres_clock = (clockid_t)clk_id;
c->pres_clock_known = clock_gettime(c->pres_clock, &ts) == 0;
@@ -21,7 +21,7 @@ static uint64_t clock_ns(clockid_t clock)
return (uint64_t)ts.tv_sec * 1000000000ull + (uint64_t)ts.tv_nsec;
}
-uint64_t conn_pres_to_mono(const struct yasl_display *c, uint64_t ns)
+uint64_t conn_pres_to_mono(const struct wayland_display *c, uint64_t ns)
{
if (c->pres_clock == CLOCK_MONOTONIC)
return ns;
@@ -30,7 +30,7 @@ uint64_t conn_pres_to_mono(const struct yasl_display *c, uint64_t ns)
return ns + mono - pres;
}
-uint64_t conn_mono_to_pres(const struct yasl_display *c, uint64_t ns)
+uint64_t conn_mono_to_pres(const struct wayland_display *c, uint64_t ns)
{
if (c->pres_clock == CLOCK_MONOTONIC)
return ns;
@@ -61,9 +61,9 @@ static void output_mode(void *data, struct wl_output *output, uint32_t flags,
o->pending_refresh_ns = (uint32_t)(1000000000000ull / (uint32_t)refresh);
}
-static void conn_follow_outputs(struct yasl_display *c)
+static void conn_follow_outputs(struct wayland_display *c)
{
- for (struct yasl_surface *w = c->surfaces; w; w = w->conn_next)
+ for (struct wayland_surface *w = c->surfaces; w; w = w->conn_next)
surface_follow_outputs(w);
}
@@ -101,7 +101,7 @@ static const struct wl_output_listener output_listener = {
.scale = output_scale,
};
-static void conn_bind_output(struct yasl_display *c, struct wl_registry *registry,
+static void conn_bind_output(struct wayland_display *c, struct wl_registry *registry,
uint32_t name, uint32_t version)
{
struct wl_conn_output *o = calloc(1, sizeof(*o));
@@ -134,7 +134,7 @@ static void output_destroy(struct wl_conn_output *o)
free(o);
}
-static bool conn_remove_output(struct yasl_display *c, uint32_t name)
+static bool conn_remove_output(struct wayland_display *c, uint32_t name)
{
struct wl_conn_output **link = &c->outputs;
while (*link && (*link)->name != name)
@@ -143,14 +143,14 @@ static bool conn_remove_output(struct yasl_display *c, uint32_t name)
if (!o)
return false;
*link = o->next;
- for (struct yasl_surface *w = c->surfaces; w; w = w->conn_next)
+ for (struct wayland_surface *w = c->surfaces; w; w = w->conn_next)
w->outputs &= ~o->mask;
output_destroy(o);
conn_follow_outputs(c);
return true;
}
-void conn_destroy_outputs(struct yasl_display *c)
+void conn_destroy_outputs(struct wayland_display *c)
{
while (c->outputs) {
struct wl_conn_output *o = c->outputs;
@@ -159,7 +159,7 @@ void conn_destroy_outputs(struct yasl_display *c)
}
}
-uint64_t conn_output_mask(const struct yasl_display *c, const struct wl_output *proxy)
+uint64_t conn_output_mask(const struct wayland_display *c, const struct wl_output *proxy)
{
for (const struct wl_conn_output *o = c->outputs; o; o = o->next)
if (o->proxy == proxy)
@@ -167,7 +167,7 @@ uint64_t conn_output_mask(const struct yasl_display *c, const struct wl_output *
return 0;
}
-uint32_t conn_output_scale_120(const struct yasl_display *c, uint64_t outputs)
+uint32_t conn_output_scale_120(const struct wayland_display *c, uint64_t outputs)
{
int32_t scale = 0;
for (const struct wl_conn_output *o = c->outputs; o; o = o->next)
@@ -179,7 +179,7 @@ uint32_t conn_output_scale_120(const struct yasl_display *c, uint64_t outputs)
static void registry_global(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version)
{
- struct yasl_display *c = data;
+ struct wayland_display *c = data;
if (strcmp(interface, wl_compositor_interface.name) == 0) {
c->compositor = wl_registry_bind(registry, name,
&wl_compositor_interface, version < 6 ? version : 6);
@@ -245,7 +245,7 @@ static void registry_global_remove(void *data, struct wl_registry *registry,
uint32_t name)
{
(void)registry;
- struct yasl_display *c = data;
+ struct wayland_display *c = data;
if (c && !conn_remove_output(c, name))
seat_remove(c, name);
}
@@ -265,17 +265,17 @@ static const struct xdg_wm_base_listener wm_base_listener = {
.ping = wm_base_ping,
};
-static void notify_state(struct yasl_surface *w)
+static void notify_state(struct wayland_surface *w)
{
if (w->cbs && w->cbs->state)
- w->cbs->state(w, yasl_surface_state(w), w->ud);
+ w->cbs->state(&w->base, wayland_surface_state(w), w->ud);
}
static void toplevel_configure(void *data, struct xdg_toplevel *toplevel,
int32_t width, int32_t height, struct wl_array *states)
{
(void)toplevel;
- struct yasl_surface *w = data;
+ struct wayland_surface *w = data;
bool fs = false, max = false, act = false, susp = false, tiled = false;
uint32_t *s;
@@ -317,13 +317,13 @@ static void toplevel_configure_bounds(void *data, struct xdg_toplevel *toplevel,
int32_t width, int32_t height)
{
(void)toplevel;
- struct yasl_surface *w = data;
+ struct wayland_surface *w = data;
w->bound_width = width;
w->bound_height = height;
if ((width > 0 && w->logical_width > width) ||
(height > 0 && w->logical_height > height)) {
w->size_pending = true;
- yasl_surface_schedule_redraw(w);
+ wayland_surface_schedule_redraw(w);
}
}
@@ -342,13 +342,13 @@ static const struct xdg_toplevel_listener toplevel_listener = {
static void xdg_surface_configure(void *data, struct xdg_surface *xdg_surface, uint32_t serial)
{
- struct yasl_surface *w = data;
+ struct wayland_surface *w = data;
(void)xdg_surface;
w->pending_serial = serial;
w->has_pending_serial = true;
w->size_pending = true;
w->configured = true;
- yasl_surface_schedule_redraw(w);
+ wayland_surface_schedule_redraw(w);
}
const struct xdg_surface_listener shell_surface_listener = {
@@ -359,7 +359,7 @@ static void toplevel_decoration_configure(void *data,
struct zxdg_toplevel_decoration_v1 *toplevel_decor, uint32_t mode)
{
(void)toplevel_decor;
- struct yasl_surface *w = data;
+ struct wayland_surface *w = data;
bool was_server = w->server_decorated;
w->server_decorated = (mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
if (was_server != w->server_decorated)
@@ -370,7 +370,7 @@ static const struct zxdg_toplevel_decoration_v1_listener toplevel_decoration_lis
.configure = toplevel_decoration_configure,
};
-int surface_init_shell(struct yasl_surface *w, const char *title)
+int surface_init_shell(struct wayland_surface *w, const char *title)
{
w->xdg_surface = xdg_wm_base_get_xdg_surface(w->conn->wm_base, w->surface);
if (!w->xdg_surface) return -1;
@@ -379,7 +379,7 @@ int surface_init_shell(struct yasl_surface *w, const char *title)
if (!w->toplevel) return -1;
xdg_toplevel_add_listener(w->toplevel, &toplevel_listener, w);
- yasl_surface_set_title(w, title ? title : "yasl_app");
+ wayland_surface_set_title(w, title ? title : "yasl_app");
const char *app_id = w->conn->app_id ? w->conn->app_id : "yasl_app";
xdg_toplevel_set_app_id(w->toplevel, app_id);
diff --git a/src/wayland/surface.c b/src/wayland/surface.c
index da334e4..ced7d89 100644
--- a/src/wayland/surface.c
+++ b/src/wayland/surface.c
@@ -1,9 +1,9 @@
#include "internal.h"
#include <assert.h>
-static void display_free(struct yasl_display *c);
+static void display_free(struct wayland_display *c);
-static void display_cancel_read(struct yasl_display *c)
+static void display_cancel_read(struct wayland_display *c)
{
if (!c->reading)
return;
@@ -11,7 +11,7 @@ static void display_cancel_read(struct yasl_display *c)
c->reading = false;
}
-static void report_display_error(struct yasl_display *c)
+static void report_display_error(struct wayland_display *c)
{
int err = wl_display_get_error(c->wl);
if (!err)
@@ -26,24 +26,24 @@ static void report_display_error(struct yasl_display *c)
fprintf(stderr, "[yasl] display error %d\n", err);
}
-void display_enter(struct yasl_display *c)
+void display_enter(struct wayland_display *c)
{
c->depth++;
}
-void display_leave(struct yasl_display *c)
+void display_leave(struct wayland_display *c)
{
if (--c->depth > 0)
return;
keyboard_settle_focus(c);
while (c->dead) {
- struct yasl_surface *w = c->dead;
+ struct wayland_surface *w = c->dead;
c->dead = w->dead_next;
free(w);
}
}
-static void display_lose(struct yasl_display *c)
+static void display_lose(struct wayland_display *c)
{
if (c->lost)
return;
@@ -51,7 +51,7 @@ static void display_lose(struct yasl_display *c)
report_display_error(c);
display_cancel_read(c);
display_enter(c);
- for (struct yasl_surface *w = c->surfaces, *next; w; w = next) {
+ for (struct wayland_surface *w = c->surfaces, *next; w; w = next) {
next = w->conn_next;
surface_fail(w);
}
@@ -60,19 +60,19 @@ static void display_lose(struct yasl_display *c)
c->cbs->lost(c->ud);
}
-void surface_fail(struct yasl_surface *w)
+void surface_fail(struct wayland_surface *w)
{
if (w->closed)
return;
w->closed = true;
if (w->cbs->close)
- w->cbs->close(w, w->ud);
+ w->cbs->close(&w->base, w->ud);
}
static int display_ready(int fd, short revents, void *ud)
{
(void)fd;
- struct yasl_display *c = ud;
+ struct wayland_display *c = ud;
if (c->lost)
return 0;
display_enter(c);
@@ -90,7 +90,7 @@ static int display_ready(int fd, short revents, void *ud)
return 0;
}
-void yasl_display_dispatch(struct yasl_display *c)
+void wayland_display_dispatch(struct wayland_display *c)
{
if (!c || c->lost || c->reading)
return;
@@ -100,7 +100,7 @@ void yasl_display_dispatch(struct yasl_display *c)
display_leave(c);
}
-static void display_arm(struct yasl_display *c)
+static void display_arm(struct wayland_display *c)
{
while (!c->reading && wl_display_prepare_read(c->wl) != 0) {
if (wl_display_dispatch_pending(c->wl) < 0) {
@@ -121,12 +121,12 @@ static void display_arm(struct yasl_display *c)
yasl_loop_set_fd_events(c->loop, c->watch, events);
}
-void yasl_display_flush(struct yasl_display *c)
+void wayland_display_flush(struct wayland_display *c)
{
if (!c || c->lost)
return;
display_enter(c);
- for (struct yasl_surface *w = c->surfaces, *next; w; w = next) {
+ for (struct wayland_surface *w = c->surfaces, *next; w; w = next) {
next = w->conn_next;
surface_draw_frame(w);
}
@@ -135,7 +135,7 @@ void yasl_display_flush(struct yasl_display *c)
display_leave(c);
}
-static void display_free(struct yasl_display *c)
+static void display_free(struct wayland_display *c)
{
conn_drag_end(c);
if (c->loop && c->watch > 0) yasl_loop_del_fd(c->loop, c->watch);
@@ -167,10 +167,11 @@ static void display_free(struct yasl_display *c)
free(c);
}
-struct yasl_display *yasl_display_open(struct yasl_loop *loop, const struct yasl_display_spec *spec)
+struct wayland_display *wayland_display_open(struct yasl_loop *loop, const struct yasl_display_spec *spec)
{
- struct yasl_display *c = calloc(1, sizeof(*c));
+ struct wayland_display *c = calloc(1, sizeof(*c));
if (!c) return NULL;
+ c->base.ops = &yasl_wayland_backend;
c->loop = loop;
if (spec) {
c->cbs = spec->cbs;
@@ -201,14 +202,14 @@ err:
return NULL;
}
-void yasl_display_close(struct yasl_display *c)
+void wayland_display_close(struct wayland_display *c)
{
if (!c) return;
assert(!c->surfaces && "destroy every surface before its display");
display_free(c);
}
-uint32_t yasl_display_caps(const struct yasl_display *c)
+uint32_t wayland_display_caps(const struct wayland_display *c)
{
if (!c) return 0;
uint32_t caps = YASL_CAP_POPUPS | YASL_CAP_CSD;
@@ -223,18 +224,19 @@ uint32_t yasl_display_caps(const struct yasl_display *c)
return caps;
}
-static void conn_link(struct yasl_display *c, struct yasl_surface *w)
+static void conn_link(struct wayland_display *c, struct wayland_surface *w)
{
+ w->base.display = &c->base;
w->conn = c;
w->conn_next = c->surfaces;
c->surfaces = w;
}
-static void conn_unlink(struct yasl_surface *w)
+static void conn_unlink(struct wayland_surface *w)
{
- struct yasl_display *c = w->conn;
+ struct wayland_display *c = w->conn;
if (!c) return;
- for (struct yasl_surface **p = &c->surfaces; *p; p = &(*p)->conn_next) {
+ for (struct wayland_surface **p = &c->surfaces; *p; p = &(*p)->conn_next) {
if (*p == w) {
*p = w->conn_next;
break;
@@ -247,9 +249,9 @@ static void conn_unlink(struct yasl_surface *w)
w->conn = NULL;
}
-struct yasl_surface *conn_surface_for(struct yasl_display *c, struct wl_surface *s)
+struct wayland_surface *conn_surface_for(struct wayland_display *c, struct wl_surface *s)
{
- for (struct yasl_surface *w = c->surfaces; w && s; w = w->conn_next)
+ for (struct wayland_surface *w = c->surfaces; w && s; w = w->conn_next)
if (w->surface == s)
return w;
return NULL;
@@ -262,18 +264,18 @@ static bool spec_valid(const struct yasl_surface_spec *spec)
buffer_size(spec->size.x, spec->size.y, &bytes);
}
-struct yasl_surface *yasl_surface_create_toplevel(struct yasl_display *c,
+struct wayland_surface *wayland_surface_create_toplevel(struct wayland_display *c,
const struct yasl_surface_spec *spec)
{
if (!c || c->lost || !spec_valid(spec))
return NULL;
int width = spec->size.x, height = spec->size.y;
display_cancel_read(c);
- struct yasl_surface *w = calloc(1, sizeof(*w));
+ struct wayland_surface *w = calloc(1, sizeof(*w));
if (!w) return NULL;
display_enter(c);
conn_link(c, w);
- yasl_surface_set_callbacks(w, NULL, NULL);
+ wayland_surface_set_callbacks(w, NULL, NULL);
w->req_width = width;
w->req_height = height;
w->logical_width = width;
@@ -311,12 +313,12 @@ struct yasl_surface *yasl_surface_create_toplevel(struct yasl_display *c,
return w;
err:
- yasl_surface_destroy(w);
+ wayland_surface_destroy(w);
display_leave(c);
return NULL;
}
-void yasl_surface_set_callbacks(struct yasl_surface *w, const struct yasl_surface_cbs *cbs, void *ud)
+void wayland_surface_set_callbacks(struct wayland_surface *w, const struct yasl_surface_cbs *cbs, void *ud)
{
if (w && !w->closed) {
static const struct yasl_surface_cbs no_callbacks = {0};
@@ -325,10 +327,10 @@ void yasl_surface_set_callbacks(struct yasl_surface *w, const struct yasl_surfac
}
}
-void yasl_surface_destroy(struct yasl_surface *w)
+void wayland_surface_destroy(struct wayland_surface *w)
{
if (!w || w->destroyed) return;
- for (struct yasl_surface *o = w->conn ? w->conn->surfaces : NULL; o; o = o->conn_next)
+ for (struct wayland_surface *o = w->conn ? w->conn->surfaces : NULL; o; o = o->conn_next)
assert(o->parent != w && "destroy a popup before its parent");
input_queue_clear(&w->input);
free(w->ime_preedit);
@@ -347,10 +349,11 @@ void yasl_surface_destroy(struct yasl_surface *w)
if (w->popup) xdg_popup_destroy(w->popup);
if (w->xdg_surface) xdg_surface_destroy(w->xdg_surface);
if (w->surface) wl_surface_destroy(w->surface);
- struct yasl_display *c = w->conn;
+ struct wayland_display *c = w->conn;
conn_unlink(w);
static const struct yasl_surface_cbs no_callbacks = {0};
- *w = (struct yasl_surface){
+ *w = (struct wayland_surface){
+ .base = w->base,
.conn_next = w->conn_next,
.cbs = &no_callbacks,
.closed = true,
@@ -364,32 +367,32 @@ void yasl_surface_destroy(struct yasl_surface *w)
}
}
-struct yasl_display *yasl_surface_display(const struct yasl_surface *w)
+struct wayland_display *wayland_surface_display(const struct wayland_surface *w)
{
return w ? w->conn : NULL;
}
-void yasl_surface_schedule_redraw(struct yasl_surface *w)
+void wayland_surface_schedule_redraw(struct wayland_surface *w)
{
if (w) w->want_draw = true;
}
-struct yasl_vector2i yasl_surface_size(const struct yasl_surface *w)
+struct yasl_vector2i wayland_surface_size(const struct wayland_surface *w)
{
return w ? (struct yasl_vector2i){ .x = w->width, .y = w->height } : (struct yasl_vector2i){0};
}
-uint32_t yasl_surface_scale_120(const struct yasl_surface *w)
+uint32_t wayland_surface_scale_120(const struct wayland_surface *w)
{
return w ? w->scale_120 : YASL_SCALE_UNIT;
}
-void yasl_surface_set_background_color(struct yasl_surface *w, uint32_t bg)
+void wayland_surface_set_background_color(struct wayland_surface *w, uint32_t bg)
{
(void)w; (void)bg;
}
-bool yasl_surface_start_interactive_move(struct yasl_surface *s)
+bool wayland_surface_start_interactive_move(struct wayland_surface *s)
{
if (!s || !s->toplevel || !s->conn) return false;
struct seat *seat = conn_active_seat(s->conn);
@@ -398,7 +401,7 @@ bool yasl_surface_start_interactive_move(struct yasl_surface *s)
return true;
}
-bool yasl_surface_start_interactive_resize(struct yasl_surface *s, enum yasl_resize_edge edge)
+bool wayland_surface_start_interactive_resize(struct wayland_surface *s, enum yasl_resize_edge edge)
{
if (!s || !s->toplevel || !s->conn || edge == YASL_EDGE_NONE) return false;
struct seat *seat = conn_active_seat(s->conn);
@@ -407,7 +410,7 @@ bool yasl_surface_start_interactive_resize(struct yasl_surface *s, enum yasl_res
return true;
}
-bool yasl_surface_show_window_menu(struct yasl_surface *s, struct yasl_vector2i pos)
+bool wayland_surface_show_window_menu(struct wayland_surface *s, struct yasl_vector2i pos)
{
if (!s || !s->toplevel || !s->conn) return false;
struct seat *seat = conn_active_seat(s->conn);
@@ -419,12 +422,12 @@ bool yasl_surface_show_window_menu(struct yasl_surface *s, struct yasl_vector2i
return true;
}
-void *yasl_display_get_native_handle(struct yasl_display *d)
+void *wayland_display_get_native_handle(struct wayland_display *d)
{
return d ? d->wl : NULL;
}
-void *yasl_surface_get_native_handle(struct yasl_surface *s)
+void *wayland_surface_get_native_handle(struct wayland_surface *s)
{
return s ? s->surface : NULL;
}