Skip to content

Commit 9b30564

Browse files
author
Manuel Bachmann
committed
Implement initial Wayland support
This commit creates a new "wayland" backend, which can be activated at configure time with "-DFREEGLUT_WAYLAND=ON". If done so, it will be used instead of X11 (building both and doing runtime detection may become possible later). Please note that if you choose to use GL instead of GLES (by not specifying "-DFREEGLUT_GLES=ON"), then libX11 will still be pulled as an indirect dependency. Following features are still WIP : - menus (not implemented, TODO) ; - client-side decorations (not implemented, required because Wayland shells do not draw title bars nor resize grips, TODO) ; - game mode (code is commented out, depends on WIP protocols tested upstream, WAIT FOR UPSTREAM) ; - window visibility states (code is commented out, depends on xdg-shell protocol, TODO). Signed-off-by: Manuel Bachmann <tarnyko@tarnyko.net>
1 parent 27d5d26 commit 9b30564

13 files changed

+1825
-37
lines changed

freeglut/freeglut/CMakeLists.txt

Lines changed: 67 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ ENDIF()
5252
# OpenGL ES support
5353
OPTION(FREEGLUT_GLES "Use OpenGL ES (requires EGL)" OFF)
5454

55-
# option to build either as "glut" (ON) or "freeglut" (OFF)
5655
IF(NOT WIN32)
56+
# Wayland support
57+
OPTION(FREEGLUT_WAYLAND "Use Wayland (no X11)" OFF)
58+
# option to build either as "glut" (ON) or "freeglut" (OFF)
5759
OPTION(FREEGLUT_REPLACE_GLUT "Be a replacement for GLUT" ON)
5860
ENDIF()
5961

@@ -167,36 +169,60 @@ ELSEIF(ANDROID OR BLACKBERRY)
167169
src/blackberry/fg_window_blackberry.c
168170
)
169171
ENDIF()
172+
170173
ELSE()
171-
LIST(APPEND FREEGLUT_SRCS
172-
src/x11/fg_cursor_x11.c
173-
src/x11/fg_ext_x11.c
174-
src/x11/fg_gamemode_x11.c
175-
src/x11/fg_glutfont_definitions_x11.c
176-
src/x11/fg_init_x11.c
177-
src/x11/fg_internal_x11.h
178-
src/x11/fg_input_devices_x11.c
179-
src/x11/fg_joystick_x11.c
180-
src/x11/fg_main_x11.c
181-
src/x11/fg_menu_x11.c
182-
src/x11/fg_spaceball_x11.c
183-
src/x11/fg_state_x11.c
184-
src/x11/fg_structure_x11.c
185-
src/x11/fg_window_x11.c
186-
src/x11/fg_xinput_x11.c
187-
)
188-
IF(NOT(FREEGLUT_GLES))
174+
# UNIX (Wayland)
175+
IF(FREEGLUT_WAYLAND)
176+
LIST(APPEND FREEGLUT_SRCS
177+
src/wayland/fg_cursor_wl.c
178+
src/wayland/fg_ext_wl.c
179+
src/wayland/fg_gamemode_wl.c
180+
src/wayland/fg_init_wl.c
181+
src/wayland/fg_internal_wl.h
182+
src/wayland/fg_input_devices_wl.c
183+
src/wayland/fg_main_wl.c
184+
src/wayland/fg_state_wl.c
185+
src/wayland/fg_structure_wl.c
186+
src/wayland/fg_window_wl.c
187+
# font, serial port & joystick code are agnostic
188+
src/x11/fg_glutfont_definitions_x11.c
189+
src/x11/fg_input_devices_x11.c
190+
src/x11/fg_joystick_x11.c
191+
)
192+
# UNIX (X11)
193+
ELSE()
189194
LIST(APPEND FREEGLUT_SRCS
190-
src/x11/fg_internal_x11_glx.h
191-
src/x11/fg_display_x11_glx.c
192-
src/x11/fg_state_x11_glx.c
193-
src/x11/fg_state_x11_glx.h
194-
src/x11/fg_window_x11_glx.c
195-
src/x11/fg_window_x11_glx.h
195+
src/x11/fg_cursor_x11.c
196+
src/x11/fg_ext_x11.c
197+
src/x11/fg_gamemode_x11.c
198+
src/x11/fg_glutfont_definitions_x11.c
199+
src/x11/fg_init_x11.c
200+
src/x11/fg_internal_x11.h
201+
src/x11/fg_input_devices_x11.c
202+
src/x11/fg_joystick_x11.c
203+
src/x11/fg_main_x11.c
204+
src/x11/fg_menu_x11.c
205+
src/x11/fg_spaceball_x11.c
206+
src/x11/fg_state_x11.c
207+
src/x11/fg_structure_x11.c
208+
src/x11/fg_window_x11.c
209+
src/x11/fg_xinput_x11.c
196210
)
211+
IF(NOT(FREEGLUT_GLES))
212+
LIST(APPEND FREEGLUT_SRCS
213+
src/x11/fg_internal_x11_glx.h
214+
src/x11/fg_display_x11_glx.c
215+
src/x11/fg_state_x11_glx.c
216+
src/x11/fg_state_x11_glx.h
217+
src/x11/fg_window_x11_glx.c
218+
src/x11/fg_window_x11_glx.h
219+
)
220+
ENDIF()
197221
ENDIF()
198222
ENDIF()
199-
IF(FREEGLUT_GLES)
223+
224+
# OpenGL ES requires EGL, and so does Wayland
225+
IF(FREEGLUT_GLES OR FREEGLUT_WAYLAND)
200226
LIST(APPEND FREEGLUT_SRCS
201227
src/egl/fg_internal_egl.h
202228
src/egl/fg_display_egl.c
@@ -226,6 +252,12 @@ ELSE()
226252
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
227253
ENDIF()
228254

255+
# For Wayland: compile with -DFREEGLUT_WAYLAND and pull EGL
256+
IF(FREEGLUT_WAYLAND)
257+
ADD_DEFINITIONS(-DFREEGLUT_WAYLAND)
258+
LIST(APPEND LIBS wayland-client wayland-cursor wayland-egl EGL xkbcommon)
259+
ENDIF()
260+
229261
# lib m for math, not needed on windows
230262
IF (NOT WIN32)
231263
# For compilation:
@@ -248,14 +280,14 @@ ENDIF()
248280

249281
IF(CMAKE_COMPILER_IS_GNUCC)
250282
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
251-
IF(NOT(ANDROID OR BLACKBERRY))
283+
IF(NOT(ANDROID OR BLACKBERRY OR FREEGLUT_WAYLAND))
252284
# not setting -ansi as EGL/KHR headers doesn't support it
253285
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic")
254286
ENDIF()
255287
ENDIF(CMAKE_COMPILER_IS_GNUCC)
256288

257289
INCLUDE(CheckIncludeFiles)
258-
IF(UNIX AND NOT(ANDROID OR BLACKBERRY))
290+
IF(UNIX AND NOT(ANDROID OR BLACKBERRY OR FREEGLUT_WAYLAND))
259291
FIND_PACKAGE(X11 REQUIRED)
260292
INCLUDE_DIRECTORIES(${X11_INCLUDE_DIR})
261293
LIST(APPEND LIBS ${X11_LIBRARIES})
@@ -506,11 +538,17 @@ ELSEIF(FREEGLUT_GLES)
506538
ELSE()
507539
SET(PC_LIBS_PRIVATE "-lbps -lslog2 -lscreen -lGLESv2 -lGLESv1_CM -lEGL -lm")
508540
ENDIF()
541+
ELSEIF(FREEGLUT_WAYLAND)
542+
SET(PC_LIBS_PRIVATE "-lwayland-client -lwayland-cursor -lwayland-egl -lGLESv2 -lGLESv1_CM -lEGL -lxkbcommon -lm")
509543
ELSE()
510544
SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGLESv2 -lGLESv1_CM -lEGL -lm")
511545
ENDIF()
512546
ELSE()
513-
SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGL -lm")
547+
IF(FREEGLUT_WAYLAND)
548+
SET(PC_LIBS_PRIVATE "-lwayland-client -lwayland-cursor -lwayland-egl -lGL -lxkbcommon -lm")
549+
ELSE()
550+
SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGL -lm")
551+
ENDIF()
514552
ENDIF()
515553
# Client applications need to define FreeGLUT GLES version to
516554
# bootstrap headers inclusion in freeglut_std.h:

freeglut/freeglut/src/egl/fg_init_egl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ void fghPlatformInitializeEGL()
3434
{
3535
/* CreateDisplay */
3636
/* Using EGL_DEFAULT_DISPLAY, or a specific native display */
37+
#ifdef FREEGLUT_WAYLAND
38+
fgDisplay.pDisplay.egl.Display = eglGetDisplay(
39+
(EGLNativeDisplayType)fgDisplay.pDisplay.display);
40+
#else
3741
EGLNativeDisplayType nativeDisplay = EGL_DEFAULT_DISPLAY;
3842
fgDisplay.pDisplay.egl.Display = eglGetDisplay(nativeDisplay);
43+
#endif
3944

4045
FREEGLUT_INTERNAL_ERROR_EXIT(fgDisplay.pDisplay.egl.Display != EGL_NO_DISPLAY,
4146
"No display available", "fgPlatformInitialize");

freeglut/freeglut/src/fg_internal.h

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@
5151
# define TARGET_HOST_BLACKBERRY 1
5252

5353
#elif defined(__posix__) || defined(__unix__) || defined(__linux__) || defined(__sun)
54-
# define TARGET_HOST_POSIX_X11 1
54+
# if defined(FREEGLUT_WAYLAND)
55+
# define TARGET_HOST_POSIX_WAYLAND 1
56+
# else
57+
# define TARGET_HOST_POSIX_X11 1
58+
# endif
5559

5660
#elif defined(__APPLE__)
5761
/* This is a placeholder until we get native OSX support ironed out -- JFF 11/18/09 */
@@ -70,32 +74,36 @@
7074
#endif
7175

7276
#ifndef TARGET_HOST_MS_WINDOWS
73-
# define TARGET_HOST_MS_WINDOWS 0
77+
# define TARGET_HOST_MS_WINDOWS 0
7478
#endif
7579

7680
#ifndef TARGET_HOST_ANDROID
77-
# define TARGET_HOST_ANDROID 0
81+
# define TARGET_HOST_ANDROID 0
7882
#endif
7983

8084
#ifndef TARGET_HOST_BLACKBERRY
81-
# define TARGET_HOST_BLACKBERRY 0
85+
# define TARGET_HOST_BLACKBERRY 0
86+
#endif
87+
88+
#ifndef TARGET_HOST_POSIX_WAYLAND
89+
# define TARGET_HOST_POSIX_WAYLAND 0
8290
#endif
8391

8492
#ifndef TARGET_HOST_POSIX_X11
85-
# define TARGET_HOST_POSIX_X11 0
93+
# define TARGET_HOST_POSIX_X11 0
8694
#endif
8795

8896
#ifndef TARGET_HOST_MAC_OSX
89-
# define TARGET_HOST_MAC_OSX 0
97+
# define TARGET_HOST_MAC_OSX 0
9098
#endif
9199

92100
#ifndef TARGET_HOST_SOLARIS
93-
# define TARGET_HOST_SOLARIS 0
101+
# define TARGET_HOST_SOLARIS 0
94102
#endif
95103

96104
/* -- FIXED CONFIGURATION LIMITS ------------------------------------------- */
97105

98-
#define FREEGLUT_MAX_MENUS 3
106+
#define FREEGLUT_MAX_MENUS 3
99107

100108
/* These files should be available on every platform. */
101109
#include <stdio.h>
@@ -188,6 +196,9 @@
188196
#endif
189197

190198
/* Platform-specific includes */
199+
#if TARGET_HOST_POSIX_WAYLAND
200+
#include "wayland/fg_internal_wl.h"
201+
#endif
191202
#if TARGET_HOST_POSIX_X11
192203
#include "x11/fg_internal_x11.h"
193204
#endif
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* fg_cursor_wl.c
3+
*
4+
* The Wayland-specific mouse cursor related stuff.
5+
*
6+
* Copyright (c) 2015 Manuel Bachmann. All Rights Reserved.
7+
* Written by Manuel Bachmann, <tarnyko@tarnyko.net>
8+
* Creation date: Thur Mar 19, 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+
#include <string.h>
29+
#include <GL/freeglut.h>
30+
#include "../fg_internal.h"
31+
32+
/*
33+
* Note: The arrangement of the table below depends on the fact that
34+
* the "normal" GLUT_CURSOR_* values start a 0 and are consecutive.
35+
*/
36+
static char* cursorList[] = {
37+
"UNSUPPORTED", /* GLUT_CURSOR_RIGHT_ARROW */
38+
"left_ptr", /* GLUT_CURSOR_LEFT_ARROW */
39+
"hand1", /* GLUT_CURSOR_INFO */
40+
"UNSUPPORTED", /* GLUT_CURSOR_DESTROY */
41+
"UNSUPPORTED", /* GLUT_CURSOR_HELP */
42+
"UNSUPPORTED", /* GLUT_CURSOR_CYCLE */
43+
"UNSUPPORTED", /* GLUT_CURSOR_SPRAY */
44+
"watch", /* GLUT_CURSOR_WAIT */
45+
"xterm", /* GLUT_CURSOR_TEXT */
46+
"grabbing", /* GLUT_CURSOR_CROSSHAIR */
47+
"UNSUPPORTED", /* GLUT_CURSOR_UP_DOWN */
48+
"UNSUPPORTED", /* GLUT_CURSOR_LEFT_RIGHT */
49+
"top_side", /* GLUT_CURSOR_TOP_SIDE */
50+
"bottom_side", /* GLUT_CURSOR_BOTTOM_SIDE */
51+
"left_side", /* GLUT_CURSOR_LEFT_SIDE */
52+
"right_side", /* GLUT_CURSOR_RIGHT_SIDE */
53+
"top_left_corner", /* GLUT_CURSOR_TOP_LEFT_CORNER */
54+
"top_right_corner", /* GLUT_CURSOR_TOP_RIGHT_CORNER */
55+
"bottom_right_corner", /* GLUT_CURSOR_BOTTOM_RIGHT_CORNER */
56+
"bottom_left_corner" /* GLUT_CURSOR_BOTTOM_LEFT_CORNER */
57+
};
58+
59+
void fgPlatformSetCursor ( SFG_Window *window, int cursorID )
60+
{
61+
/*
62+
* XXX FULL_CROSSHAIR demotes to plain CROSSHAIR. Old GLUT allows
63+
* for this, but if there is a system that easily supports a full-
64+
* window (or full-screen) crosshair, we might consider it.
65+
*/
66+
int cursorIDToUse =
67+
( cursorID == GLUT_CURSOR_FULL_CROSSHAIR ) ? GLUT_CURSOR_CROSSHAIR : cursorID;
68+
69+
char* cursor;
70+
71+
if( ( cursorIDToUse >= 0 ) &&
72+
( cursorIDToUse < sizeof( cursorList ) / sizeof( cursorList[0] ) ) ) {
73+
74+
cursor = cursorList[cursorIDToUse];
75+
76+
/* if the type is UNSUPPORTED, fall back to GLUT_CURSOR_LEFT_ARROW */
77+
if ( ! strcmp( cursor, "UNSUPPORTED" ) )
78+
{
79+
fgWarning( "glutSetCursor(): cursor type unsupported under Wayland : %d",
80+
cursorIDToUse );
81+
cursor = "left_ptr";
82+
}
83+
} else {
84+
switch( cursorIDToUse )
85+
{
86+
case GLUT_CURSOR_NONE:
87+
case GLUT_CURSOR_INHERIT:
88+
cursor = NULL;
89+
break;
90+
91+
default:
92+
fgError( "Unknown cursor type: %d", cursorIDToUse );
93+
return;
94+
}
95+
}
96+
97+
if ( cursorIDToUse == GLUT_CURSOR_INHERIT ) {
98+
if( window->Parent )
99+
window->Window.pContext.cursor =
100+
window->Parent->Window.pContext.cursor;
101+
} else {
102+
window->Window.pContext.cursor = wl_cursor_theme_get_cursor(
103+
fgDisplay.pDisplay.cursor_theme,
104+
cursor );
105+
if ( ! window->Window.pContext.cursor )
106+
fgError( "Failed to create cursor" );
107+
}
108+
}
109+
110+
111+
void fgPlatformWarpPointer ( int x, int y )
112+
{
113+
/* unsupported under Wayland */
114+
fgWarning( "glutWarpPointer(): function unsupported under Wayland" );
115+
}
116+
117+
void fghPlatformGetCursorPos(const SFG_Window *window, GLboolean client, SFG_XYUse *mouse_pos)
118+
{
119+
/* Get current pointer location relative to top-left of client area of window (if client is true and window is not NULL)
120+
* We cannot get current pointer location in screen coordinates under Wayland, so inform the user and return -1 is this case
121+
*/
122+
123+
if (client && window)
124+
{
125+
mouse_pos->X = window->State.MouseX;
126+
mouse_pos->Y = window->State.MouseY;
127+
}
128+
else
129+
{
130+
fgWarning( "glutGetCursorPos(): cannot get screen position under Wayland" );
131+
mouse_pos->X = -1;
132+
mouse_pos->Y = -1;
133+
}
134+
135+
mouse_pos->Use = GL_TRUE;
136+
}
137+

0 commit comments

Comments
 (0)