summaryrefslogtreecommitdiff
path: root/src/platform
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform')
-rw-r--r--src/platform/cocoa/api.h2
-rw-r--r--src/platform/cocoa/keymap.h2
-rw-r--r--src/platform/cocoa/window.m21
-rw-r--r--src/platform/sync.h2
-rw-r--r--src/platform/wayland/api.h4
-rw-r--r--src/platform/wayland/backend.c6
-rw-r--r--src/platform/wayland/buffer.c17
-rw-r--r--src/platform/wayland/clipboard.c2
-rw-r--r--src/platform/wayland/internal.h9
-rw-r--r--src/platform/wayland/keyboard.c1
-rw-r--r--src/platform/wayland/keymap.h2
-rw-r--r--src/platform/wayland/popup.c1
-rw-r--r--src/platform/wayland/shell.c56
-rw-r--r--src/platform/wayland/surface.c2
-rw-r--r--src/platform/x11/keymap.h2
-rw-r--r--src/platform/x11/window.c17
16 files changed, 59 insertions, 87 deletions
diff --git a/src/platform/cocoa/api.h b/src/platform/cocoa/api.h
index 89b71f3..0f705dd 100644
--- a/src/platform/cocoa/api.h
+++ b/src/platform/cocoa/api.h
@@ -1,7 +1,7 @@
#ifndef YASL_COCOA_API_H
#define YASL_COCOA_API_H
-#include "common/backend.h"
+#include "yasl/yasl.h"
struct cocoa_display;
struct cocoa_surface;
diff --git a/src/platform/cocoa/keymap.h b/src/platform/cocoa/keymap.h
index 1aba70b..a5394e2 100644
--- a/src/platform/cocoa/keymap.h
+++ b/src/platform/cocoa/keymap.h
@@ -1,7 +1,7 @@
#ifndef YASL_COCOA_KEYMAP_H
#define YASL_COCOA_KEYMAP_H
-#include "yasl/yasl.h"
+#include "yasl/keycodes.h"
enum yasl_key yasl_key_from_cocoa(uint32_t code);
diff --git a/src/platform/cocoa/window.m b/src/platform/cocoa/window.m
index dc6175d..aa9fa48 100644
--- a/src/platform/cocoa/window.m
+++ b/src/platform/cocoa/window.m
@@ -3,6 +3,7 @@
#import <QuartzCore/QuartzCore.h>
#include "platform/cocoa/api.h"
+#include "common/backend.h"
#include "yasl/native/cocoa.h"
#include "common/timing.h"
#include "common/loop.h"
@@ -93,7 +94,6 @@ struct cocoa_surface {
struct input_queue input;
struct yasl_vector2i pointer;
double scroll_x;
- uint32_t state;
uint32_t mods;
uint32_t buttons;
enum yasl_cursor cursor;
@@ -180,13 +180,13 @@ static void set_state(struct cocoa_surface *w, uint32_t bit, bool on)
{
if (!w || w->closed)
return;
- uint32_t next = on ? (w->state | bit) : (w->state & ~bit);
- if (next == w->state)
+ uint32_t next = on ? (w->base.state | bit) : (w->base.state & ~bit);
+ if (next == w->base.state)
return;
- w->state = next;
+ w->base.state = next;
darwin_ctx.depth++;
if (w->cbs->state)
- w->cbs->state(&w->base, w->state, w->ud);
+ w->cbs->state(&w->base, next, w->ud);
darwin_ctx.depth--;
}
@@ -713,7 +713,7 @@ static struct yasl_vector2i dragging_pos(YaslView *view, id<NSDraggingInfo> send
if (period > 0.0 && period < 0.25)
w->clock.refresh_ns = period * 1e9;
w->frame_due = true;
- if (!w->want_draw || (w->state & YASL_STATE_SUSPENDED)) {
+ if (!w->want_draw || (w->base.state & YASL_STATE_SUSPENDED)) {
if (++w->idle_frames >= LINK_IDLE_FRAMES)
link.paused = YES;
return;
@@ -1069,7 +1069,7 @@ bool cocoa_surface_present(struct cocoa_surface *w, const struct yasl_framebuffe
static void render_and_commit(struct cocoa_surface *w)
{
if (w->closed || !w->cbs->draw || w->rendering || w->size.x <= 0 || w->size.y <= 0 ||
- (w->state & YASL_STATE_SUSPENDED))
+ (w->base.state & YASL_STATE_SUSPENDED))
return;
size_t count = (size_t)w->size.x * (size_t)w->size.y;
@@ -2042,12 +2042,6 @@ static struct yasl_geometry impl_surface_geometry(const struct yasl_surface *s)
return cocoa_surface_geometry((const struct cocoa_surface *)s);
}
-static uint32_t impl_surface_state(const struct yasl_surface *s)
-{
- const struct cocoa_surface *w = (const struct cocoa_surface *)s;
- return w ? w->state : 0;
-}
-
static struct yasl_timing impl_surface_timing(const struct yasl_surface *s)
{
return cocoa_surface_timing((const struct cocoa_surface *)s);
@@ -2156,7 +2150,6 @@ const struct yasl_backend_ops yasl_cocoa_backend = {
.surface_present = impl_surface_present,
.surface_input_poll = impl_surface_input_poll,
.surface_geometry = impl_surface_geometry,
- .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,
diff --git a/src/platform/sync.h b/src/platform/sync.h
index 1dcf28f..43b4a34 100644
--- a/src/platform/sync.h
+++ b/src/platform/sync.h
@@ -5,6 +5,6 @@
* yasl_mutex_init/destroy/lock/unlock operations. Init returns zero on success
* or an errno value on failure. The other operations require an initialized
* mutex. Native types and calls stay in the selected implementation header. */
-#include "yasl_platform_sync.h"
+#include "yasl_platform_sync.h" // IWYU pragma: export
#endif
diff --git a/src/platform/wayland/api.h b/src/platform/wayland/api.h
index 04a6bf1..bbd20df 100644
--- a/src/platform/wayland/api.h
+++ b/src/platform/wayland/api.h
@@ -1,8 +1,7 @@
#ifndef YASL_WAYLAND_API_H
#define YASL_WAYLAND_API_H
-#include "common/backend.h"
-#include "yasl/native/wayland.h"
+#include "yasl/yasl.h"
struct wayland_display;
struct wayland_surface;
@@ -28,7 +27,6 @@ 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_geometry wayland_surface_geometry(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);
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);
diff --git a/src/platform/wayland/backend.c b/src/platform/wayland/backend.c
index 3eada38..cc96934 100644
--- a/src/platform/wayland/backend.c
+++ b/src/platform/wayland/backend.c
@@ -111,11 +111,6 @@ static struct yasl_geometry impl_surface_geometry(const struct yasl_surface *s)
return wayland_surface_geometry((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);
@@ -212,7 +207,6 @@ const struct yasl_backend_ops yasl_wayland_backend = {
.surface_present = impl_surface_present,
.surface_input_poll = impl_surface_input_poll,
.surface_geometry = impl_surface_geometry,
- .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,
diff --git a/src/platform/wayland/buffer.c b/src/platform/wayland/buffer.c
index f4243d1..f5a2c0f 100644
--- a/src/platform/wayland/buffer.c
+++ b/src/platform/wayland/buffer.c
@@ -1,4 +1,6 @@
#include "internal.h"
+#include "common/utf8.h"
+#include <errno.h>
#include <sys/resource.h>
static long minor_faults(void)
@@ -134,7 +136,8 @@ int apply_pending_geometry(struct wayland_surface *w)
w->size_pending = false;
return 0;
}
- bool floating = !w->parent && !w->maximized && !w->fullscreen && !w->tiled;
+ bool floating = !w->parent && !(w->base.state &
+ (YASL_STATE_MAXIMIZED | YASL_STATE_FULLSCREEN | YASL_STATE_TILED));
int free_w = floating && w->floating_width > 0 ? w->floating_width : w->logical_width;
int free_h = floating && w->floating_height > 0 ? w->floating_height : w->logical_height;
int logical_w = !w->parent && w->req_width > 0 ? w->req_width : free_w;
@@ -143,7 +146,7 @@ int apply_pending_geometry(struct wayland_surface *w)
if (logical_w < YASL_MIN_LOGICAL_PX) logical_w = YASL_MIN_LOGICAL_PX;
if (logical_h < YASL_MIN_LOGICAL_PX) logical_h = YASL_MIN_LOGICAL_PX;
}
- if (!w->fullscreen) {
+ if (!(w->base.state & YASL_STATE_FULLSCREEN)) {
if (w->bound_width > 0 && logical_w > w->bound_width)
logical_w = w->bound_width;
if (w->bound_height > 0 && logical_h > w->bound_height)
@@ -539,16 +542,6 @@ void wayland_surface_set_title(struct wayland_surface *w, const char *title)
free(copy);
}
-uint32_t wayland_surface_state(const struct wayland_surface *w)
-{
- if (unlikely(!w)) return 0;
- return ((uint32_t)w->fullscreen * YASL_STATE_FULLSCREEN) |
- ((uint32_t)w->maximized * YASL_STATE_MAXIMIZED) |
- ((uint32_t)w->activated * YASL_STATE_ACTIVATED) |
- ((uint32_t)w->suspended * YASL_STATE_SUSPENDED) |
- ((uint32_t)!w->server_decorated * YASL_STATE_CSD);
-}
-
struct yasl_timing wayland_surface_timing(const struct wayland_surface *w)
{
struct yasl_timing t = {
diff --git a/src/platform/wayland/clipboard.c b/src/platform/wayland/clipboard.c
index 24dee97..353e993 100644
--- a/src/platform/wayland/clipboard.c
+++ b/src/platform/wayland/clipboard.c
@@ -1,6 +1,8 @@
#define _GNU_SOURCE
#include "internal.h"
#include "clipboard.h"
+#include "common/utf8.h"
+#include <errno.h>
#define CLIPBOARD_TEXT_MAX (256u * 1024)
diff --git a/src/platform/wayland/internal.h b/src/platform/wayland/internal.h
index f777674..d619dba 100644
--- a/src/platform/wayland/internal.h
+++ b/src/platform/wayland/internal.h
@@ -4,8 +4,8 @@
#define _GNU_SOURCE
#include "api.h"
+#include "common/backend.h"
#include "common/timing.h"
-#include "common/utf8.h"
#include "clipboard.h"
#include <wayland-client.h>
@@ -24,7 +24,6 @@
#include "protocols/xdg-toplevel-drag-v1-client-protocol.h"
#include "protocols/primary-selection-unstable-v1-client-protocol.h"
-#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <poll.h>
@@ -307,10 +306,8 @@ struct wayland_surface {
uint32_t pending_serial;
/* 1-byte booleans packed tightly */
- bool server_decorated;
bool frame_active;
bool frame_presented;
- bool tiled;
bool size_pending;
bool sample_refresh;
bool has_pending_serial;
@@ -318,10 +315,6 @@ struct wayland_surface {
bool closed;
bool destroyed;
bool opaque;
- bool fullscreen;
- bool maximized;
- bool activated;
- bool suspended;
bool want_draw;
};
diff --git a/src/platform/wayland/keyboard.c b/src/platform/wayland/keyboard.c
index 0913079..ebd0fc7 100644
--- a/src/platform/wayland/keyboard.c
+++ b/src/platform/wayland/keyboard.c
@@ -1,6 +1,7 @@
#include "internal.h"
#include "common/keyboard.h"
#include "keymap.h"
+#include <errno.h>
#define XKB_EVDEV_OFFSET 8
#define KEYMAP_MAX_BYTES (8u * 1024 * 1024)
diff --git a/src/platform/wayland/keymap.h b/src/platform/wayland/keymap.h
index 26a5cd6..c0ff81e 100644
--- a/src/platform/wayland/keymap.h
+++ b/src/platform/wayland/keymap.h
@@ -1,7 +1,7 @@
#ifndef YASL_WAYLAND_KEYMAP_H
#define YASL_WAYLAND_KEYMAP_H
-#include "yasl/yasl.h"
+#include "yasl/keycodes.h"
enum yasl_key yasl_key_from_evdev(uint32_t code);
diff --git a/src/platform/wayland/popup.c b/src/platform/wayland/popup.c
index fd415c9..cb578d5 100644
--- a/src/platform/wayland/popup.c
+++ b/src/platform/wayland/popup.c
@@ -137,6 +137,7 @@ struct wayland_surface *wayland_surface_create_popup(struct wayland_surface *par
if (!w)
return NULL;
w->base.display = &c->base;
+ w->base.state = YASL_STATE_CSD;
w->conn = c;
w->conn_next = c->surfaces;
c->surfaces = w;
diff --git a/src/platform/wayland/shell.c b/src/platform/wayland/shell.c
index 4c1caad..92c89d1 100644
--- a/src/platform/wayland/shell.c
+++ b/src/platform/wayland/shell.c
@@ -265,10 +265,12 @@ static const struct xdg_wm_base_listener wm_base_listener = {
.ping = wm_base_ping,
};
-static void notify_state(struct wayland_surface *w)
+static void set_state(struct wayland_surface *w, uint32_t state)
{
+ if (state == w->base.state) return;
+ w->base.state = state;
if (w->cbs && w->cbs->state)
- w->cbs->state(&w->base, wayland_surface_state(w), w->ud);
+ w->cbs->state(&w->base, state, w->ud);
}
static void toplevel_configure(void *data, struct xdg_toplevel *toplevel,
@@ -277,35 +279,29 @@ static void toplevel_configure(void *data, struct xdg_toplevel *toplevel,
(void)toplevel;
struct wayland_surface *w = data;
- uint32_t state_mask = 0;
+ uint32_t state = w->base.state & ~(YASL_STATE_FULLSCREEN |
+ YASL_STATE_MAXIMIZED | YASL_STATE_ACTIVATED |
+ YASL_STATE_SUSPENDED | YASL_STATE_TILED);
uint32_t *s;
wl_array_for_each(s, states) {
- if (*s < 32)
- state_mask |= (1u << *s);
+ switch (*s) {
+ case XDG_TOPLEVEL_STATE_FULLSCREEN: state |= YASL_STATE_FULLSCREEN; break;
+ case XDG_TOPLEVEL_STATE_MAXIMIZED: state |= YASL_STATE_MAXIMIZED; break;
+ case XDG_TOPLEVEL_STATE_ACTIVATED: state |= YASL_STATE_ACTIVATED; break;
+ case XDG_TOPLEVEL_STATE_SUSPENDED: state |= YASL_STATE_SUSPENDED; break;
+ case XDG_TOPLEVEL_STATE_TILED_LEFT:
+ case XDG_TOPLEVEL_STATE_TILED_RIGHT:
+ case XDG_TOPLEVEL_STATE_TILED_TOP:
+ case XDG_TOPLEVEL_STATE_TILED_BOTTOM:
+ state |= YASL_STATE_TILED;
+ break;
+ default: break;
+ }
}
- bool max = (state_mask & (1u << XDG_TOPLEVEL_STATE_MAXIMIZED)) != 0;
- bool fs = (state_mask & (1u << XDG_TOPLEVEL_STATE_FULLSCREEN)) != 0;
- bool act = (state_mask & (1u << XDG_TOPLEVEL_STATE_ACTIVATED)) != 0;
- bool susp = (state_mask & (1u << XDG_TOPLEVEL_STATE_SUSPENDED)) != 0;
- bool tiled = (state_mask & (
- (1u << XDG_TOPLEVEL_STATE_TILED_LEFT) |
- (1u << XDG_TOPLEVEL_STATE_TILED_RIGHT) |
- (1u << XDG_TOPLEVEL_STATE_TILED_TOP) |
- (1u << XDG_TOPLEVEL_STATE_TILED_BOTTOM))) != 0;
-
- if ((fs ^ w->fullscreen) | (max ^ w->maximized) |
- (act ^ w->activated) | (susp ^ w->suspended)) {
- w->fullscreen = fs;
- w->maximized = max;
- w->activated = act;
- w->suspended = susp;
- notify_state(w);
- }
-
- w->tiled = tiled;
w->req_width = width;
w->req_height = height;
+ set_state(w, state);
}
static void toplevel_close(void *data, struct xdg_toplevel *toplevel)
@@ -363,10 +359,12 @@ static void toplevel_decoration_configure(void *data,
{
(void)toplevel_decor;
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)
- notify_state(w);
+ uint32_t state = w->base.state;
+ if (mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE)
+ state &= ~YASL_STATE_CSD;
+ else
+ state |= YASL_STATE_CSD;
+ set_state(w, state);
}
static const struct zxdg_toplevel_decoration_v1_listener toplevel_decoration_listener = {
diff --git a/src/platform/wayland/surface.c b/src/platform/wayland/surface.c
index 7daa679..ad3a24c 100644
--- a/src/platform/wayland/surface.c
+++ b/src/platform/wayland/surface.c
@@ -1,5 +1,6 @@
#include "internal.h"
#include <assert.h>
+#include <errno.h>
static void display_free(struct wayland_display *c);
@@ -335,6 +336,7 @@ struct wayland_surface *wayland_surface_create_toplevel(struct wayland_display *
if (!w) return NULL;
c->depth++;
conn_link(c, w);
+ w->base.state = YASL_STATE_CSD;
wayland_surface_set_callbacks(w, NULL, NULL);
w->cursor = YASL_CURSOR_TEXT;
w->req_width = width;
diff --git a/src/platform/x11/keymap.h b/src/platform/x11/keymap.h
index 2ec4295..8114fb5 100644
--- a/src/platform/x11/keymap.h
+++ b/src/platform/x11/keymap.h
@@ -1,7 +1,7 @@
#ifndef YASL_X11_KEYMAP_H
#define YASL_X11_KEYMAP_H
-#include "yasl/yasl.h"
+#include "yasl/keycodes.h"
enum yasl_key yasl_key_from_xkb_name(const char name[4]);
diff --git a/src/platform/x11/window.c b/src/platform/x11/window.c
index 347b4c2..3bab6e2 100644
--- a/src/platform/x11/window.c
+++ b/src/platform/x11/window.c
@@ -58,7 +58,6 @@ struct x11_surface {
struct yasl_frame frame;
struct yasl_damage_list damage;
struct yasl_frame_clock clock;
- uint32_t state;
bool want_draw, drawing, presented, destroyed;
struct x11_surface *parent;
bool is_popup;
@@ -700,7 +699,7 @@ static struct yasl_surface *create_toplevel(struct yasl_display *base,
if (spec->fullscreen) {
XChangeProperty(d->native, s->window, d->net_state, XA_ATOM, 32,
PropModeReplace, (unsigned char *)&d->fullscreen, 1);
- s->state |= YASL_STATE_FULLSCREEN;
+ s->base.state |= YASL_STATE_FULLSCREEN;
}
XMapWindow(d->native, s->window);
XFlush(d->native);
@@ -893,7 +892,7 @@ static void update_state(struct x11_surface *s)
int format;
unsigned long count, left;
unsigned char *data = NULL;
- uint32_t state = s->state & YASL_STATE_ACTIVATED;
+ uint32_t state = s->base.state & ~(YASL_STATE_FULLSCREEN | YASL_STATE_MAXIMIZED);
if (XGetWindowProperty(d->native, s->window, d->net_state, 0, 64, False,
XA_ATOM, &actual, &format, &count, &left, &data) == Success && format == 32) {
Atom *atoms = (Atom *)data;
@@ -906,8 +905,8 @@ static void update_state(struct x11_surface *s)
if (h && v) state |= YASL_STATE_MAXIMIZED;
}
if (data) XFree(data);
- if (state == s->state) return;
- s->state = state;
+ if (state == s->base.state) return;
+ s->base.state = state;
if (s->cbs && s->cbs->state) s->cbs->state(&s->base, state, s->ud);
}
@@ -1335,11 +1334,11 @@ static void dispatch(struct yasl_display *base)
case FocusIn: case FocusOut: {
bool focused = event.type == FocusIn;
if (s->ic) { if (focused) XSetICFocus(s->ic); else XUnsetICFocus(s->ic); }
- if (focused) s->state |= YASL_STATE_ACTIVATED;
- else s->state &= ~YASL_STATE_ACTIVATED;
+ if (focused) s->base.state |= YASL_STATE_ACTIVATED;
+ else s->base.state &= ~YASL_STATE_ACTIVATED;
push(s, (struct yasl_input_event){
.kind = YASL_INPUT_FOCUS, .focus.focused = focused}, NULL, 0);
- if (s->cbs && s->cbs->state) s->cbs->state(&s->base, s->state, s->ud);
+ if (s->cbs && s->cbs->state) s->cbs->state(&s->base, s->base.state, s->ud);
break;
}
case PropertyNotify:
@@ -1746,7 +1745,6 @@ static struct yasl_geometry geometry(const struct yasl_surface *s)
{
return (struct yasl_geometry){((const struct x11_surface *)s)->size, YASL_SCALE_UNIT};
}
-static uint32_t state(const struct yasl_surface *s) { return ((const struct x11_surface *)s)->state; }
static int mods(const struct yasl_display *d) { return (int)((const struct x11_display *)d)->mods; }
static void *native_display(struct yasl_display *d) { return ((struct x11_display *)d)->native; }
static void *native_surface(struct yasl_surface *s) { return (void *)(uintptr_t)((struct x11_surface *)s)->window; }
@@ -2042,7 +2040,6 @@ const struct yasl_backend_ops yasl_x11_backend = {
.surface_present = present,
.surface_input_poll = input_poll,
.surface_geometry = geometry,
- .surface_state = state,
.surface_timing = timing,
.surface_frame_time_ns = frame_time,
.surface_set_cursor = cursor,