linux-windowing/wayland_egl.h

168 lines
4.3 KiB
C

#ifndef WAYLAND_EGL_EXAMPLE_H
#define WAYLAND_EGL_EXAMPLE_H
#define HAS_DBUS
#define HAVE_MEMFD_CREATE
#define HAVE_POSIX_FALLOCATE
#define Min(a, b) ((a)>(b)?(b):(a))
#define Max(a, b) ((a)<(b)?(b):(a))
#define ClampTop(x, a) Min(x, a)
#define ClampBot(x, a) Max(x, a)
typedef enum ColorScheme{
ColorScheme_Default,
ColorScheme_Dark,
ColorScheme_Light
} ColorScheme;
typedef struct CursorTheme{
char *name;
int size;
} CursorTheme;
typedef uint32_t CursorShape;
enum{
CursorShape_Hidden,
CursorShape_Pointer,
CursorShape_Resize_Top,
CursorShape_Resize_Bottom,
CursorShape_Resize_Left,
CursorShape_Resize_Right,
CursorShape_Resize_TopLeft,
CursorShape_Resize_TopRight,
CursorShape_Resize_BottomLeft,
CursorShape_Resize_BottomRight,
CursorShape_COUNT
};
typedef uint32_t WindowFlags;
enum{
WindowFlag_IsFullscreen = (1 << 0),
WindowFlag_IsMax = (1 << 1),
WindowFlag_IsActivated = (1 << 2),
WindowFlag_IsTiledLeft = (1 << 3),
WindowFlag_IsTiledRight = (1 << 4),
WindowFlag_IsTiledTop = (1 << 5),
WindowFlag_IsTiledBottom = (1 << 6),
WindowFlag_IsResizing = (1 << 7),
WindowFlag_IsSuspended = (1 << 8),
WindowFlag_IsConstrainedLeft = (1 << 9),
WindowFlag_IsConstrainedRight = (1 << 10),
WindowFlag_IsConstrainedTop = (1 << 11),
WindowFlag_IsConstrainedBottom = (1 << 12),
};
typedef uint32_t WindowControlFlags;
enum{
WindowControlFlag_Move = (1 << 0),
WindowControlFlag_Resize = (1 << 1),
WindowControlFlag_Min = (1 << 2),
WindowControlFlag_Max = (1 << 3),
WindowControlFlag_Close = (1 << 4),
};
typedef struct Config{
uint32_t serial;
int32_t dim[2];
uint32_t flags;
uint32_t decoration_mode;
} Config;
typedef struct CSD_Frame{
int32_t border[2][2]; // [0][]:x [1][]:y [][0]:min [][1]:max
int32_t minbox[2];
} CSD_Frame;
typedef struct Ctx{
/* "application variables" */
int close_signal;
/* globals: desktop settings */
ColorScheme color_scheme;
CursorTheme cursor_theme;
/* globals: wayland */
struct wl_display *wl_display;
struct wl_registry *wl_registry;
struct wl_compositor *wl_compositor;
struct wl_subcompositor *wl_subcompositor;
struct wl_shm *wl_shm;
struct xdg_wm_base *xdg_wm_base;
struct zxdg_decoration_manager_v1 *zxdg_decoration_manager;
struct wl_cursor_theme *wl_cursor_theme;
struct wl_cursor *wl_cursors[CursorShape_COUNT];
/* globals: egl */
EGLDisplay egl_display;
EGLContext egl_context;
/* per-seat: wayland */
struct wl_seat *wl_seat;
struct wl_pointer *wl_pointer;
struct wl_surface *cursor_surface;
/* per-window: wayland */
struct wl_surface *main_wl_surface;
struct xdg_surface *main_xdg_surface;
struct xdg_toplevel *main_xdg_toplevel;
struct zxdg_toplevel_decoration_v1 *main_zxdg_toplevel_decoration;
struct wl_surface *shadow_wl_surface;
struct wl_subsurface *shadow_wl_subsurface;
struct wl_buffer *shadow_wl_buffer;
void *shadow_data;
uint64_t shadow_size;
int32_t shadow_dim[2];
/* per-window: egl */
struct wl_egl_window *main_wl_egl_window;
EGLSurface main_egl_surface;
/* per-window */
WindowControlFlags control_flags;
Config config;
Config config_staged;
int32_t mmbox[2][2]; // [0][]:x [1][]:y [][0]:min [][1]:max
int32_t dim[2];
uint32_t hover_serial;
uint32_t button_serial;
struct wl_surface *hover;
int32_t p[2];
uint32_t button;
int handled_first_size;
} Ctx;
/* csd implementation */
static CSD_Frame csd_impl_calculate_frame(void);
/* wayland helpers */
static WindowFlags csd_window_flags_from_states_array(struct wl_array *states);
/* os */
static int os_resize_anonymous_file(int fd, off_t size);
static int os_create_anonymous_file(off_t size);
/* desktop settings */
static CursorTheme ds_get_cursor_theme(void);
static ColorScheme ds_get_color_scheme(void);
static CursorTheme ds__get_cursor_theme_from_env(void);
#if defined(HAS_DBUS)
#include <dbus/dbus.h>
static DBusMessage* ds__get_setting_sync(DBusConnection *const connection, const char *k, const char *v);
static int ds__parse_type(DBusMessage *const reply, const int type, void *value);
#endif /* defined(HAS_DBUS) */
#endif /* WAYLAND_EGL_EXAMPLE_H */