81bd5bc2b2ec0267471c7ae3b168fc00dd01266c
[freeglut] / src / wayland / fg_internal_wl.h
1 /*
2  * fg_internal_wl.h
3  *
4  * The freeglut library private include file.
5  *
6  * Copyright (c) 2015 Manuel Bachmann. All Rights Reserved.
7  * Written by Manuel Bachmann, <tarnyko@tarnyko.net>
8  * Creation date: Tue Mar 17, 2015
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a
11  * copy of this software and associated documentation files (the "Software"),
12  * to deal in the Software without restriction, including without limitation
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  * and/or sell copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included
18  * in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23  * MANUEL BACHMANN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27
28 #ifndef  FREEGLUT_INTERNAL_WL_H
29 #define  FREEGLUT_INTERNAL_WL_H
30
31
32 /* -- PLATFORM-SPECIFIC INCLUDES ------------------------------------------- */
33 #include "egl/fg_internal_egl.h"
34 #include <wayland-egl.h>
35 #include <wayland-client.h>
36 #include <wayland-cursor.h>
37 #include <xkbcommon/xkbcommon.h>
38
39
40 /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */
41 /* The structure used by display initialization in fg_init.c */
42 typedef struct tagSFG_PlatformDisplay SFG_PlatformDisplay;
43 struct tagSFG_PlatformDisplay
44 {
45     struct tagSFG_PlatformDisplayEGL egl;
46
47     struct wl_display* display;        /* The display we are being run in    */
48     struct wl_registry* registry;      /* The global interface registry      */
49     struct wl_compositor* compositor;  /* The compositor                     */
50     struct wl_shell* shell;            /* The shell, AKA window manager      */
51     struct wl_seat* seat;              /* The seat, references input devices */
52
53     struct xkb_context* xkb_context;   /* The global XKB keyboard context    */
54     struct xkb_state* xkb_state;       /* The current XKB keyboard state     */
55     struct wl_keyboard* keyboard;      /* The keyboard input device          */
56     struct wl_pointer* pointer;        /* The pointer input device (mouse)   */
57     struct wl_touch* touch;            /* The touchscreen input device       */
58
59     struct wl_shm* shm;                    /* The software rendering engine  */
60     struct wl_cursor_theme* cursor_theme;  /* The pointer cursor theme       */
61 };
62
63
64 /* The structure used by window creation in fg_window.c */
65 typedef struct tagSFG_PlatformContext SFG_PlatformContext;
66 struct tagSFG_PlatformContext
67 {
68     struct tagSFG_PlatformContextEGL egl;
69     GLboolean pointer_button_pressed;
70
71     struct wl_surface* surface;            /* The drawing surface             */
72     struct wl_shell_surface* shsurface;    /* The shell surface, has states   */
73     struct wl_egl_window* egl_window;      /* Binding between WL/EGL surfaces */
74
75     struct wl_cursor* cursor;              /* The active cursor */
76     struct wl_surface* cursor_surface;     /* The active cursor surface */
77 };
78
79
80 /* The window state description. This structure should be kept portable. */
81 typedef struct tagSFG_PlatformWindowState SFG_PlatformWindowState;
82 struct tagSFG_PlatformWindowState
83 {
84     int OldWidth;                        /* Window width from before a resize */
85     int OldHeight;                       /*   "    height  "    "    "   "    */
86 };
87
88
89 /* -- JOYSTICK-SPECIFIC STRUCTURES AND TYPES ------------------------------- */
90 /*
91  * Initial defines from "js.h" starting around line 33 with the existing "fg_joystick.c"
92  * interspersed
93  */
94 #    ifdef HAVE_SYS_IOCTL_H
95 #        include <sys/ioctl.h>
96 #    endif
97 #    ifdef HAVE_FCNTL_H
98 #        include <fcntl.h>
99 #    endif
100
101 #include <errno.h>
102 #include <string.h>
103
104 #    if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
105 /* XXX The below hack is done until freeglut's autoconf is updated. */
106 #        define HAVE_USB_JS    1
107
108 #        if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
109 #            include <sys/joystick.h>
110 #        else
111 /*
112  * XXX NetBSD/amd64 systems may find that they have to steal the
113  * XXX /usr/include/machine/joystick.h from a NetBSD/i386 system.
114  * XXX I cannot comment whether that works for the interface, but
115  * XXX it lets you compile...(^&  I do not think that we can do away
116  * XXX with this header.
117  */
118 #            include <machine/joystick.h>         /* For analog joysticks */
119 #        endif
120 #        define JS_DATA_TYPE joystick
121 #        define JS_RETURN (sizeof(struct JS_DATA_TYPE))
122 #    endif
123
124 #    if defined(__linux__)
125 #        include <linux/joystick.h>
126
127 /* check the joystick driver version */
128 #        if defined(JS_VERSION) && JS_VERSION >= 0x010000
129 #            define JS_NEW
130 #        endif
131 #    else  /* Not BSD or Linux */
132 #        ifndef JS_RETURN
133
134   /*
135    * We'll put these values in and that should
136    * allow the code to at least compile when there is
137    * no support. The JS open routine should error out
138    * and shut off all the code downstream anyway and if
139    * the application doesn't use a joystick we'll be fine.
140    */
141
142   struct JS_DATA_TYPE
143   {
144     int buttons;
145     int x;
146     int y;
147   };
148
149 #            define JS_RETURN (sizeof(struct JS_DATA_TYPE))
150 #        endif
151 #    endif
152
153 /* XXX It might be better to poll the operating system for the numbers of buttons and
154  * XXX axes and then dynamically allocate the arrays.
155  */
156 #    define _JS_MAX_AXES 16
157 typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick;
158 struct tagSFG_PlatformJoystick
159 {
160 #   if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
161        struct os_specific_s *os;
162 #   endif
163
164 #   ifdef JS_NEW
165        struct js_event     js;
166        int          tmp_buttons;
167        float        tmp_axes [ _JS_MAX_AXES ];
168 #   else
169        struct JS_DATA_TYPE js;
170 #   endif
171
172     char         fname [ 128 ];
173     int          fd;
174 };
175
176
177 /* Menu font and color definitions */
178 #define  FREEGLUT_MENU_FONT    GLUT_BITMAP_HELVETICA_18
179
180 #define  FREEGLUT_MENU_PEN_FORE_COLORS   {0.0f,  0.0f,  0.0f,  1.0f}
181 #define  FREEGLUT_MENU_PEN_BACK_COLORS   {0.70f, 0.70f, 0.70f, 1.0f}
182 #define  FREEGLUT_MENU_PEN_HFORE_COLORS  {0.0f,  0.0f,  0.0f,  1.0f}
183 #define  FREEGLUT_MENU_PEN_HBACK_COLORS  {1.0f,  1.0f,  1.0f,  1.0f}
184
185
186 #endif  /* FREEGLUT_INTERNAL_WL_H */