de15ee4b57af7547bc7246b3c207934235ca8af1
[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 #        include <sys/joystick.h>
109 #        define JS_DATA_TYPE joystick
110 #        define JS_RETURN (sizeof(struct JS_DATA_TYPE))
111 #    endif
112
113 #    if defined(__linux__)
114 #        include <linux/joystick.h>
115
116 /* check the joystick driver version */
117 #        if defined(JS_VERSION) && JS_VERSION >= 0x010000
118 #            define JS_NEW
119 #        endif
120 #    else  /* Not BSD or Linux */
121 #        ifndef JS_RETURN
122
123   /*
124    * We'll put these values in and that should
125    * allow the code to at least compile when there is
126    * no support. The JS open routine should error out
127    * and shut off all the code downstream anyway and if
128    * the application doesn't use a joystick we'll be fine.
129    */
130
131   struct JS_DATA_TYPE
132   {
133     int buttons;
134     int x;
135     int y;
136   };
137
138 #            define JS_RETURN (sizeof(struct JS_DATA_TYPE))
139 #        endif
140 #    endif
141
142 /* XXX It might be better to poll the operating system for the numbers of buttons and
143  * XXX axes and then dynamically allocate the arrays.
144  */
145 #    define _JS_MAX_AXES 16
146 typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick;
147 struct tagSFG_PlatformJoystick
148 {
149 #   if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
150        struct os_specific_s *os;
151 #   endif
152
153 #   ifdef JS_NEW
154        struct js_event     js;
155        int          tmp_buttons;
156        float        tmp_axes [ _JS_MAX_AXES ];
157 #   else
158        struct JS_DATA_TYPE js;
159 #   endif
160
161     char         fname [ 128 ];
162     int          fd;
163 };
164
165
166 /* Menu font and color definitions */
167 #define  FREEGLUT_MENU_FONT    GLUT_BITMAP_HELVETICA_18
168
169 #define  FREEGLUT_MENU_PEN_FORE_COLORS   {0.0f,  0.0f,  0.0f,  1.0f}
170 #define  FREEGLUT_MENU_PEN_BACK_COLORS   {0.70f, 0.70f, 0.70f, 1.0f}
171 #define  FREEGLUT_MENU_PEN_HFORE_COLORS  {0.0f,  0.0f,  0.0f,  1.0f}
172 #define  FREEGLUT_MENU_PEN_HBACK_COLORS  {1.0f,  1.0f,  1.0f,  1.0f}
173
174
175 #endif  /* FREEGLUT_INTERNAL_WL_H */