4 * Various freeglut Wayland initialization functions.
6 * Copyright (c) 2015 Manuel Bachmann. All Rights Reserved.
7 * Written by Manuel Bachmann, <tarnyko@tarnyko.net>
8 * Creation date: Tue Mar 17, 2015
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:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
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.
28 #define FREEGLUT_BUILDING_LIB
30 #include <GL/freeglut.h>
31 #include "fg_internal.h"
32 #include "egl/fg_init_egl.h"
34 void fgPlatformInitialiseInputDevices( void );
35 void fgPlatformCloseInputDevices( void );
38 static void fghRegistryGlobal( void* data,
39 struct wl_registry* registry,
41 const char* interface,
44 SFG_PlatformDisplay* pDisplay = data;
46 if ( ! strcmp( interface, "wl_compositor" ) )
47 pDisplay->compositor = wl_registry_bind ( registry, id,
48 &wl_compositor_interface, 1 );
49 else if ( ! strcmp( interface, "wl_shell" ) )
50 pDisplay->shell = wl_registry_bind ( registry, id,
51 &wl_shell_interface, 1 );
52 else if ( ! strcmp( interface, "wl_seat" ) )
53 pDisplay->seat = wl_registry_bind ( registry, id,
54 &wl_seat_interface, 1 );
55 else if ( ! strcmp( interface, "wl_shm" ) )
56 pDisplay->shm = wl_registry_bind ( registry, id,
57 &wl_shm_interface, 1 );
59 static void fghRegistryGlobalRemove( void* data,
60 struct wl_registry* registry,
64 static const struct wl_registry_listener fghRegistryListener =
67 fghRegistryGlobalRemove
71 static void fghInitialiseCursorTheme(void)
73 fgDisplay.pDisplay.cursor_theme = wl_cursor_theme_load (
75 fgDisplay.pDisplay.shm );
78 void fgPlatformInitialize( const char* displayName )
80 fgDisplay.pDisplay.display = wl_display_connect( NULL );
82 if( fgDisplay.pDisplay.display == NULL )
83 fgError( "failed to connect to a Wayland compositor" );
85 fgDisplay.pDisplay.registry = wl_display_get_registry(
86 fgDisplay.pDisplay.display );
87 wl_registry_add_listener( fgDisplay.pDisplay.registry,
89 &fgDisplay.pDisplay );
90 wl_display_roundtrip( fgDisplay.pDisplay.display );
92 if( fgDisplay.pDisplay.compositor == NULL ||
93 fgDisplay.pDisplay.shell == NULL ||
94 fgDisplay.pDisplay.seat == NULL ||
95 fgDisplay.pDisplay.shm == NULL )
96 fgError( "failed to discover all needed compositor interfaces" );
98 fghInitialiseCursorTheme();
100 fghPlatformInitializeEGL();
103 fgState.Time = fgSystemTime();
105 fgState.Initialised = GL_TRUE;
107 atexit(fgDeinitialize);
109 /* InputDevice uses GlutTimerFunc(), so fgState.Initialised must be TRUE */
110 fgPlatformInitialiseInputDevices();
114 void fgPlatformDeinitialiseInputDevices ( void )
116 fgPlatformCloseInputDevices();
118 fgState.InputDevsInitialised = GL_FALSE;
122 void fgPlatformCloseDisplay ( void )
124 wl_cursor_theme_destroy( fgDisplay.pDisplay.cursor_theme );
126 wl_shm_destroy( fgDisplay.pDisplay.shm );
127 wl_seat_destroy( fgDisplay.pDisplay.seat );
128 wl_shell_destroy( fgDisplay.pDisplay.shell );
129 wl_compositor_destroy( fgDisplay.pDisplay.compositor );
130 wl_registry_destroy( fgDisplay.pDisplay.registry );
132 wl_display_disconnect( fgDisplay.pDisplay.display );