DSCF

.co.uk

PC32

A ColorForth compiler and editor for x86-64
git clone https://dscf.co.uk/clone/PC32.git
Log | Files | Refs | README

wl_platform.h (15591B)


      1 //========================================================================
      2 // GLFW 3.3 Wayland - www.glfw.org
      3 //------------------------------------------------------------------------
      4 // Copyright (c) 2014 Jonas Ã…dahl <jadahl@gmail.com>
      5 //
      6 // This software is provided 'as-is', without any express or implied
      7 // warranty. In no event will the authors be held liable for any damages
      8 // arising from the use of this software.
      9 //
     10 // Permission is granted to anyone to use this software for any purpose,
     11 // including commercial applications, and to alter it and redistribute it
     12 // freely, subject to the following restrictions:
     13 //
     14 // 1. The origin of this software must not be misrepresented; you must not
     15 //    claim that you wrote the original software. If you use this software
     16 //    in a product, an acknowledgment in the product documentation would
     17 //    be appreciated but is not required.
     18 //
     19 // 2. Altered source versions must be plainly marked as such, and must not
     20 //    be misrepresented as being the original software.
     21 //
     22 // 3. This notice may not be removed or altered from any source
     23 //    distribution.
     24 //
     25 //========================================================================
     26 
     27 #include <wayland-client.h>
     28 #include <xkbcommon/xkbcommon.h>
     29 #include <xkbcommon/xkbcommon-compose.h>
     30 #include <dlfcn.h>
     31 
     32 typedef VkFlags VkWaylandSurfaceCreateFlagsKHR;
     33 
     34 typedef struct VkWaylandSurfaceCreateInfoKHR
     35 {
     36     VkStructureType                 sType;
     37     const void*                     pNext;
     38     VkWaylandSurfaceCreateFlagsKHR  flags;
     39     struct wl_display*              display;
     40     struct wl_surface*              surface;
     41 } VkWaylandSurfaceCreateInfoKHR;
     42 
     43 typedef VkResult (APIENTRY *PFN_vkCreateWaylandSurfaceKHR)(VkInstance,const VkWaylandSurfaceCreateInfoKHR*,const VkAllocationCallbacks*,VkSurfaceKHR*);
     44 typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR)(VkPhysicalDevice,uint32_t,struct wl_display*);
     45 
     46 #include "posix_thread.h"
     47 #include "posix_time.h"
     48 #ifdef __linux__
     49 #include "linux_joystick.h"
     50 #else
     51 #include "null_joystick.h"
     52 #endif
     53 #include "xkb_unicode.h"
     54 #include "egl_context.h"
     55 #include "osmesa_context.h"
     56 
     57 #include "wayland-xdg-shell-client-protocol.h"
     58 #include "wayland-xdg-decoration-client-protocol.h"
     59 #include "wayland-viewporter-client-protocol.h"
     60 #include "wayland-relative-pointer-unstable-v1-client-protocol.h"
     61 #include "wayland-pointer-constraints-unstable-v1-client-protocol.h"
     62 #include "wayland-idle-inhibit-unstable-v1-client-protocol.h"
     63 
     64 #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL)
     65 #define _glfw_dlclose(handle) dlclose(handle)
     66 #define _glfw_dlsym(handle, name) dlsym(handle, name)
     67 
     68 #define _GLFW_EGL_NATIVE_WINDOW         ((EGLNativeWindowType) window->wl.egl.window)
     69 #define _GLFW_EGL_NATIVE_DISPLAY        ((EGLNativeDisplayType) _glfw.wl.display)
     70 
     71 #define _GLFW_PLATFORM_WINDOW_STATE         _GLFWwindowWayland  wl
     72 #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWayland wl
     73 #define _GLFW_PLATFORM_MONITOR_STATE        _GLFWmonitorWayland wl
     74 #define _GLFW_PLATFORM_CURSOR_STATE         _GLFWcursorWayland  wl
     75 
     76 #define _GLFW_PLATFORM_CONTEXT_STATE         struct { int dummyContext; }
     77 #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE struct { int dummyLibraryContext; }
     78 
     79 struct wl_cursor_image {
     80     uint32_t width;
     81     uint32_t height;
     82     uint32_t hotspot_x;
     83     uint32_t hotspot_y;
     84     uint32_t delay;
     85 };
     86 struct wl_cursor {
     87     unsigned int image_count;
     88     struct wl_cursor_image** images;
     89     char* name;
     90 };
     91 typedef struct wl_cursor_theme* (* PFN_wl_cursor_theme_load)(const char*, int, struct wl_shm*);
     92 typedef void (* PFN_wl_cursor_theme_destroy)(struct wl_cursor_theme*);
     93 typedef struct wl_cursor* (* PFN_wl_cursor_theme_get_cursor)(struct wl_cursor_theme*, const char*);
     94 typedef struct wl_buffer* (* PFN_wl_cursor_image_get_buffer)(struct wl_cursor_image*);
     95 #define wl_cursor_theme_load _glfw.wl.cursor.theme_load
     96 #define wl_cursor_theme_destroy _glfw.wl.cursor.theme_destroy
     97 #define wl_cursor_theme_get_cursor _glfw.wl.cursor.theme_get_cursor
     98 #define wl_cursor_image_get_buffer _glfw.wl.cursor.image_get_buffer
     99 
    100 typedef struct wl_egl_window* (* PFN_wl_egl_window_create)(struct wl_surface*, int, int);
    101 typedef void (* PFN_wl_egl_window_destroy)(struct wl_egl_window*);
    102 typedef void (* PFN_wl_egl_window_resize)(struct wl_egl_window*, int, int, int, int);
    103 #define wl_egl_window_create _glfw.wl.egl.window_create
    104 #define wl_egl_window_destroy _glfw.wl.egl.window_destroy
    105 #define wl_egl_window_resize _glfw.wl.egl.window_resize
    106 
    107 typedef struct xkb_context* (* PFN_xkb_context_new)(enum xkb_context_flags);
    108 typedef void (* PFN_xkb_context_unref)(struct xkb_context*);
    109 typedef struct xkb_keymap* (* PFN_xkb_keymap_new_from_string)(struct xkb_context*, const char*, enum xkb_keymap_format, enum xkb_keymap_compile_flags);
    110 typedef void (* PFN_xkb_keymap_unref)(struct xkb_keymap*);
    111 typedef xkb_mod_index_t (* PFN_xkb_keymap_mod_get_index)(struct xkb_keymap*, const char*);
    112 typedef int (* PFN_xkb_keymap_key_repeats)(struct xkb_keymap*, xkb_keycode_t);
    113 typedef int (* PFN_xkb_keymap_key_get_syms_by_level)(struct xkb_keymap*,xkb_keycode_t,xkb_layout_index_t,xkb_level_index_t,const xkb_keysym_t**);
    114 typedef struct xkb_state* (* PFN_xkb_state_new)(struct xkb_keymap*);
    115 typedef void (* PFN_xkb_state_unref)(struct xkb_state*);
    116 typedef int (* PFN_xkb_state_key_get_syms)(struct xkb_state*, xkb_keycode_t, const xkb_keysym_t**);
    117 typedef enum xkb_state_component (* PFN_xkb_state_update_mask)(struct xkb_state*, xkb_mod_mask_t, xkb_mod_mask_t, xkb_mod_mask_t, xkb_layout_index_t, xkb_layout_index_t, xkb_layout_index_t);
    118 typedef xkb_layout_index_t (* PFN_xkb_state_key_get_layout)(struct xkb_state*,xkb_keycode_t);
    119 typedef int (* PFN_xkb_state_mod_index_is_active)(struct xkb_state*,xkb_mod_index_t,enum xkb_state_component);
    120 #define xkb_context_new _glfw.wl.xkb.context_new
    121 #define xkb_context_unref _glfw.wl.xkb.context_unref
    122 #define xkb_keymap_new_from_string _glfw.wl.xkb.keymap_new_from_string
    123 #define xkb_keymap_unref _glfw.wl.xkb.keymap_unref
    124 #define xkb_keymap_mod_get_index _glfw.wl.xkb.keymap_mod_get_index
    125 #define xkb_keymap_key_repeats _glfw.wl.xkb.keymap_key_repeats
    126 #define xkb_keymap_key_get_syms_by_level _glfw.wl.xkb.keymap_key_get_syms_by_level
    127 #define xkb_state_new _glfw.wl.xkb.state_new
    128 #define xkb_state_unref _glfw.wl.xkb.state_unref
    129 #define xkb_state_key_get_syms _glfw.wl.xkb.state_key_get_syms
    130 #define xkb_state_update_mask _glfw.wl.xkb.state_update_mask
    131 #define xkb_state_key_get_layout _glfw.wl.xkb.state_key_get_layout
    132 #define xkb_state_mod_index_is_active _glfw.wl.xkb.state_mod_index_is_active
    133 
    134 typedef struct xkb_compose_table* (* PFN_xkb_compose_table_new_from_locale)(struct xkb_context*, const char*, enum xkb_compose_compile_flags);
    135 typedef void (* PFN_xkb_compose_table_unref)(struct xkb_compose_table*);
    136 typedef struct xkb_compose_state* (* PFN_xkb_compose_state_new)(struct xkb_compose_table*, enum xkb_compose_state_flags);
    137 typedef void (* PFN_xkb_compose_state_unref)(struct xkb_compose_state*);
    138 typedef enum xkb_compose_feed_result (* PFN_xkb_compose_state_feed)(struct xkb_compose_state*, xkb_keysym_t);
    139 typedef enum xkb_compose_status (* PFN_xkb_compose_state_get_status)(struct xkb_compose_state*);
    140 typedef xkb_keysym_t (* PFN_xkb_compose_state_get_one_sym)(struct xkb_compose_state*);
    141 #define xkb_compose_table_new_from_locale _glfw.wl.xkb.compose_table_new_from_locale
    142 #define xkb_compose_table_unref _glfw.wl.xkb.compose_table_unref
    143 #define xkb_compose_state_new _glfw.wl.xkb.compose_state_new
    144 #define xkb_compose_state_unref _glfw.wl.xkb.compose_state_unref
    145 #define xkb_compose_state_feed _glfw.wl.xkb.compose_state_feed
    146 #define xkb_compose_state_get_status _glfw.wl.xkb.compose_state_get_status
    147 #define xkb_compose_state_get_one_sym _glfw.wl.xkb.compose_state_get_one_sym
    148 
    149 typedef enum _GLFWdecorationSideWayland
    150 {
    151     mainWindow,
    152     topDecoration,
    153     leftDecoration,
    154     rightDecoration,
    155     bottomDecoration,
    156 } _GLFWdecorationSideWayland;
    157 
    158 typedef struct _GLFWdecorationWayland
    159 {
    160     struct wl_surface*          surface;
    161     struct wl_subsurface*       subsurface;
    162     struct wp_viewport*         viewport;
    163 } _GLFWdecorationWayland;
    164 
    165 typedef struct _GLFWofferWayland
    166 {
    167     struct wl_data_offer*       offer;
    168     GLFWbool                    text_plain_utf8;
    169     GLFWbool                    text_uri_list;
    170 } _GLFWofferWayland;
    171 
    172 // Wayland-specific per-window data
    173 //
    174 typedef struct _GLFWwindowWayland
    175 {
    176     int                         width, height;
    177     GLFWbool                    visible;
    178     GLFWbool                    maximized;
    179     GLFWbool                    activated;
    180     GLFWbool                    fullscreen;
    181     GLFWbool                    hovered;
    182     GLFWbool                    transparent;
    183     struct wl_surface*          surface;
    184     struct wl_callback*         callback;
    185 
    186     struct {
    187         struct wl_egl_window*   window;
    188     } egl;
    189 
    190     struct {
    191         int                     width, height;
    192         GLFWbool                maximized;
    193         GLFWbool                iconified;
    194         GLFWbool                activated;
    195         GLFWbool                fullscreen;
    196     } pending;
    197 
    198     struct {
    199         struct xdg_surface*     surface;
    200         struct xdg_toplevel*    toplevel;
    201         struct zxdg_toplevel_decoration_v1* decoration;
    202         uint32_t                decorationMode;
    203     } xdg;
    204 
    205     _GLFWcursor*                currentCursor;
    206     double                      cursorPosX, cursorPosY;
    207 
    208     char*                       title;
    209 
    210     // We need to track the monitors the window spans on to calculate the
    211     // optimal scaling factor.
    212     int                         scale;
    213     _GLFWmonitor**              monitors;
    214     int                         monitorsCount;
    215     int                         monitorsSize;
    216 
    217     struct {
    218         struct zwp_relative_pointer_v1*    relativePointer;
    219         struct zwp_locked_pointer_v1*      lockedPointer;
    220     } pointerLock;
    221 
    222     struct zwp_idle_inhibitor_v1*          idleInhibitor;
    223 
    224     struct {
    225         struct wl_buffer*                  buffer;
    226         _GLFWdecorationWayland             top, left, right, bottom;
    227         _GLFWdecorationSideWayland         focus;
    228     } decorations;
    229 } _GLFWwindowWayland;
    230 
    231 // Wayland-specific global data
    232 //
    233 typedef struct _GLFWlibraryWayland
    234 {
    235     struct wl_display*          display;
    236     struct wl_registry*         registry;
    237     struct wl_compositor*       compositor;
    238     struct wl_subcompositor*    subcompositor;
    239     struct wl_shm*              shm;
    240     struct wl_seat*             seat;
    241     struct wl_pointer*          pointer;
    242     struct wl_keyboard*         keyboard;
    243     struct wl_data_device_manager*          dataDeviceManager;
    244     struct wl_data_device*      dataDevice;
    245     struct xdg_wm_base*         wmBase;
    246     struct zxdg_decoration_manager_v1*      decorationManager;
    247     struct wp_viewporter*       viewporter;
    248     struct zwp_relative_pointer_manager_v1* relativePointerManager;
    249     struct zwp_pointer_constraints_v1*      pointerConstraints;
    250     struct zwp_idle_inhibit_manager_v1*     idleInhibitManager;
    251 
    252     _GLFWofferWayland*          offers;
    253     unsigned int                offerCount;
    254 
    255     struct wl_data_offer*       selectionOffer;
    256     struct wl_data_source*      selectionSource;
    257 
    258     struct wl_data_offer*       dragOffer;
    259     _GLFWwindow*                dragFocus;
    260     uint32_t                    dragSerial;
    261 
    262     int                         compositorVersion;
    263     int                         seatVersion;
    264 
    265     struct wl_cursor_theme*     cursorTheme;
    266     struct wl_cursor_theme*     cursorThemeHiDPI;
    267     struct wl_surface*          cursorSurface;
    268     const char*                 cursorPreviousName;
    269     int                         cursorTimerfd;
    270     uint32_t                    serial;
    271     uint32_t                    pointerEnterSerial;
    272 
    273     int32_t                     keyboardRepeatRate;
    274     int32_t                     keyboardRepeatDelay;
    275     int                         keyboardLastKey;
    276     int                         keyboardLastScancode;
    277     char*                       clipboardString;
    278     int                         timerfd;
    279     short int                   keycodes[256];
    280     short int                   scancodes[GLFW_KEY_LAST + 1];
    281     char                        keynames[GLFW_KEY_LAST + 1][5];
    282 
    283     struct {
    284         void*                   handle;
    285         struct xkb_context*     context;
    286         struct xkb_keymap*      keymap;
    287         struct xkb_state*       state;
    288         struct xkb_compose_state* composeState;
    289 
    290         xkb_mod_index_t         controlIndex;
    291         xkb_mod_index_t         altIndex;
    292         xkb_mod_index_t         shiftIndex;
    293         xkb_mod_index_t         superIndex;
    294         xkb_mod_index_t         capsLockIndex;
    295         xkb_mod_index_t         numLockIndex;
    296         unsigned int            modifiers;
    297 
    298         PFN_xkb_context_new context_new;
    299         PFN_xkb_context_unref context_unref;
    300         PFN_xkb_keymap_new_from_string keymap_new_from_string;
    301         PFN_xkb_keymap_unref keymap_unref;
    302         PFN_xkb_keymap_mod_get_index keymap_mod_get_index;
    303         PFN_xkb_keymap_key_repeats keymap_key_repeats;
    304         PFN_xkb_keymap_key_get_syms_by_level keymap_key_get_syms_by_level;
    305         PFN_xkb_state_new state_new;
    306         PFN_xkb_state_unref state_unref;
    307         PFN_xkb_state_key_get_syms state_key_get_syms;
    308         PFN_xkb_state_update_mask state_update_mask;
    309         PFN_xkb_state_key_get_layout state_key_get_layout;
    310         PFN_xkb_state_mod_index_is_active state_mod_index_is_active;
    311 
    312         PFN_xkb_compose_table_new_from_locale compose_table_new_from_locale;
    313         PFN_xkb_compose_table_unref compose_table_unref;
    314         PFN_xkb_compose_state_new compose_state_new;
    315         PFN_xkb_compose_state_unref compose_state_unref;
    316         PFN_xkb_compose_state_feed compose_state_feed;
    317         PFN_xkb_compose_state_get_status compose_state_get_status;
    318         PFN_xkb_compose_state_get_one_sym compose_state_get_one_sym;
    319     } xkb;
    320 
    321     _GLFWwindow*                pointerFocus;
    322     _GLFWwindow*                keyboardFocus;
    323 
    324     struct {
    325         void*                   handle;
    326 
    327         PFN_wl_cursor_theme_load theme_load;
    328         PFN_wl_cursor_theme_destroy theme_destroy;
    329         PFN_wl_cursor_theme_get_cursor theme_get_cursor;
    330         PFN_wl_cursor_image_get_buffer image_get_buffer;
    331     } cursor;
    332 
    333     struct {
    334         void*                   handle;
    335 
    336         PFN_wl_egl_window_create window_create;
    337         PFN_wl_egl_window_destroy window_destroy;
    338         PFN_wl_egl_window_resize window_resize;
    339     } egl;
    340 } _GLFWlibraryWayland;
    341 
    342 // Wayland-specific per-monitor data
    343 //
    344 typedef struct _GLFWmonitorWayland
    345 {
    346     struct wl_output*           output;
    347     uint32_t                    name;
    348     int                         currentMode;
    349 
    350     int                         x;
    351     int                         y;
    352     int                         scale;
    353 } _GLFWmonitorWayland;
    354 
    355 // Wayland-specific per-cursor data
    356 //
    357 typedef struct _GLFWcursorWayland
    358 {
    359     struct wl_cursor*           cursor;
    360     struct wl_cursor*           cursorHiDPI;
    361     struct wl_buffer*           buffer;
    362     int                         width, height;
    363     int                         xhot, yhot;
    364     int                         currentImage;
    365 } _GLFWcursorWayland;
    366 
    367 void _glfwAddOutputWayland(uint32_t name, uint32_t version);
    368 void _glfwUpdateContentScaleWayland(_GLFWwindow* window);
    369 GLFWbool _glfwInputTextWayland(_GLFWwindow* window, uint32_t scancode);
    370 
    371 void _glfwAddSeatListenerWayland(struct wl_seat* seat);
    372 void _glfwAddDataDeviceListenerWayland(struct wl_data_device* device);
    373