2025-11-29 17:56:33 -07:00
/*!
* @ file Mw / LowLevel / Wayland . h
* @ brief Wayland Backend
* @ warning This is used internally
*/
# ifndef __MW_LOWLEVEL_WAYLAND_H__
# define __MW_LOWLEVEL_WAYLAND_H__
# include <Mw/MachDep.h>
# include <Mw/TypeDefs.h>
# include <Mw/LowLevel.h>
2025-12-07 17:25:16 -07:00
# include <wayland-client-protocol.h>
2025-12-03 18:17:27 -07:00
# include <wayland-egl.h>
# include <EGL/egl.h>
# include <GL/gl.h>
# include <GL/glext.h>
2025-11-29 17:56:33 -07:00
# include <wayland-client.h>
# include <xkbcommon/xkbcommon.h>
MWDECL int MwLLWaylandCallInit ( void ) ;
# ifndef WL_PROTOCOLS_DEFINED
# define WL_PROTOCOLS_DEFINED
# include "Wayland/xdg-shell-client-protocol.h"
# include "Wayland/xdg-decoration-client-protocol.h"
# include "Wayland/cursor-shape-client-protocol.h"
# endif
2025-12-07 19:04:59 -07:00
struct _MwLLWayland ;
2025-11-29 17:56:33 -07:00
typedef struct wayland_protocol {
void * listener ;
void * context ;
} wayland_protocol_t ;
typedef wayland_protocol_t * ( wl_setup_func ) ( MwU32 , struct _MwLLWayland * ) ;
2025-11-29 20:52:56 -07:00
struct _MwLLWaylandTopLevel {
struct xdg_surface * xdg_surface ;
struct xdg_toplevel * xdg_top_level ;
struct xdg_toplevel_listener xdg_toplevel_listener ;
struct xdg_surface_listener xdg_surface_listener ;
2025-11-29 17:56:33 -07:00
2025-11-29 20:52:56 -07:00
struct xkb_context * xkb_context ;
2025-12-08 17:11:42 -07:00
struct xkb_keymap * xkb_keymap ;
struct xkb_state * xkb_state ;
2025-11-29 17:56:33 -07:00
2025-11-29 20:52:56 -07:00
MwBool compositor_created ;
MwBool xdg_wm_base_created ;
MwBool xdg_surface_created ;
} ;
2025-11-29 17:56:33 -07:00
2025-11-29 20:52:56 -07:00
struct _MwLLWayland {
struct _MwLLCommon common ;
2025-12-09 00:46:54 -07:00
/* Pointer for data that's only loaded if the widget is a toplevel */
2025-12-07 20:41:37 -07:00
struct _MwLLWaylandTopLevel * toplevel ;
2025-12-09 00:46:54 -07:00
2025-11-29 20:52:56 -07:00
enum {
2025-12-07 20:41:37 -07:00
MWLL_WAYLAND_TOPLEVEL = 0 ,
2025-12-09 00:46:54 -07:00
MWLL_WAYLAND_SUBLEVEL = 1 , /* Sublevels are surfaces that have the toplevel as a parent. They could be implemented as subsurfaces if we ever switch away from OpenGL. Some parts of the code also call them subwidgets. */
2025-11-29 20:52:56 -07:00
} type ;
2025-12-09 00:46:54 -07:00
/* Map of Wayland interfaces to their relevant setup functions. */
2025-11-29 17:56:33 -07:00
struct {
const char * key ;
wl_setup_func * value ;
} * wl_protocol_setup_map ;
2025-12-09 00:46:54 -07:00
/* Map of Wayland interfaces to any information we keep about them once we've registered them. */
2025-11-29 17:56:33 -07:00
struct {
const char * key ;
wayland_protocol_t * value ;
} * wl_protocol_map ;
2025-12-03 18:17:27 -07:00
struct wl_display * display ;
struct wl_registry * registry ;
struct wl_compositor * compositor ;
struct wl_subcompositor * subcompositor ;
struct wl_surface * surface ;
struct wl_registry_listener registry_listener ;
2025-12-08 15:28:20 -07:00
struct wl_event_queue * event_queue ;
2025-12-03 22:26:03 -07:00
2025-12-03 18:17:27 -07:00
EGLNativeWindowType egl_window_native ;
EGLDisplay egl_display ;
EGLContext egl_context ;
EGLSurface egl_surface ;
2025-12-05 14:50:04 -07:00
EGLConfig egl_config ;
2025-12-09 00:46:54 -07:00
MwLL * sublevels ; /* stb_ds managed array of any sublevels */
MwBool configured ; /* Whether or not xdg_toplevel_configure has run once */
MwBool egl_setup ; /* Whether or not EGL has been set up */
MwBool has_set_xy /* Whether or not MwSetXY has been called */ ;
int resize_counter ; /* Counter that's for a hack in event_loop */
MwU32 x , y , ww , wh ; /* Window position */
MwU32 lw , lh ; /* Last known window position */
MwPoint cur_mouse_pos ; /* Currently known mouse position */
struct timeval timer ;
MwU64 cooldown_timer ;
MwU64 cooldown_timer_epoch ;
MwLL parent ;
MwLL topmost_parent ; /* The parent at the top of all the other parents. Usually a toplevel. */
2025-11-29 17:56:33 -07:00
} ;
struct _MwLLWaylandColor {
struct _MwLLCommonColor common ;
} ;
struct _MwLLWaylandPixmap {
struct _MwLLCommonPixmap common ;
2025-12-05 15:18:21 -07:00
GLuint texture ;
2025-12-08 15:28:20 -07:00
MwBool texture_deleted ;
2025-11-29 17:56:33 -07:00
} ;
# endif