| //======================================================================== |
| // GLFW 3.1 Wayland - www.glfw.org |
| //------------------------------------------------------------------------ |
| // Copyright (c) 2014 Jonas Ã…dahl <jadahl@gmail.com> |
| // |
| // This software is provided 'as-is', without any express or implied |
| // warranty. In no event will the authors be held liable for any damages |
| // arising from the use of this software. |
| // |
| // Permission is granted to anyone to use this software for any purpose, |
| // including commercial applications, and to alter it and redistribute it |
| // freely, subject to the following restrictions: |
| // |
| // 1. The origin of this software must not be misrepresented; you must not |
| // claim that you wrote the original software. If you use this software |
| // in a product, an acknowledgment in the product documentation would |
| // be appreciated but is not required. |
| // |
| // 2. Altered source versions must be plainly marked as such, and must not |
| // be misrepresented as being the original software. |
| // |
| // 3. This notice may not be removed or altered from any source |
| // distribution. |
| // |
| //======================================================================== |
| |
| #include "internal.h" |
| |
| #include <stdio.h> |
| #include <stdlib.h> |
| #include <string.h> |
| #include <wayland-client.h> |
| #include <wayland-client-protocol.h> |
| #include <wayland-cursor.h> |
| |
| |
| static void handlePing(void* data, |
| struct wl_shell_surface* shellSurface, |
| uint32_t serial) |
| { |
| wl_shell_surface_pong(shellSurface, serial); |
| } |
| |
| static void handleConfigure(void* data, |
| struct wl_shell_surface* shellSurface, |
| uint32_t edges, |
| int32_t width, |
| int32_t height) |
| { |
| } |
| |
| static void handlePopupDone(void *data, struct wl_shell_surface *shell_surface) |
| { |
| } |
| |
| static const struct wl_shell_surface_listener shellSurfaceListener = { |
| handlePing, |
| handleConfigure, |
| handlePopupDone |
| }; |
| |
| static void registryHandleGlobal(void* data, |
| struct wl_registry* registry, |
| uint32_t name, |
| const char* interface, |
| uint32_t version) |
| { |
| if (strcmp(interface, "wl_compositor") == 0) |
| { |
| _glfw.wl.compositor = |
| wl_registry_bind(registry, name, &wl_compositor_interface, 1); |
| } |
| else if (strcmp(interface, "wl_shell") == 0) |
| { |
| _glfw.wl.shell = |
| wl_registry_bind(registry, name, &wl_shell_interface, 1); |
| } |
| else if (strcmp(interface, "wl_output") == 0) |
| { |
| _glfwAddOutput(name, version); |
| } |
| } |
| |
| static void registryHandleGlobalRemove(void *data, |
| struct wl_registry *registry, |
| uint32_t name) |
| { |
| } |
| |
| |
| static const struct wl_registry_listener registryListener = { |
| registryHandleGlobal, |
| registryHandleGlobalRemove |
| }; |
| |
| |
| ////////////////////////////////////////////////////////////////////////// |
| ////// GLFW platform API ////// |
| ////////////////////////////////////////////////////////////////////////// |
| |
| int _glfwPlatformInit(void) |
| { |
| _glfw.wl.display = wl_display_connect(NULL); |
| if (!_glfw.wl.display) |
| { |
| _glfwInputError(GLFW_PLATFORM_ERROR, |
| "Wayland: Failed to connect to display"); |
| return GL_FALSE; |
| } |
| |
| _glfw.wl.registry = wl_display_get_registry(_glfw.wl.display); |
| wl_registry_add_listener(_glfw.wl.registry, ®istryListener, NULL); |
| |
| _glfw.wl.monitors = calloc(4, sizeof(_GLFWmonitor*)); |
| _glfw.wl.monitorsSize = 4; |
| |
| // Sync so we got all registry objects |
| wl_display_roundtrip(_glfw.wl.display); |
| |
| // Sync so we got all initial output events |
| wl_display_roundtrip(_glfw.wl.display); |
| |
| if (!_glfwInitContextAPI()) |
| return GL_FALSE; |
| |
| _glfwInitTimer(); |
| _glfwInitJoysticks(); |
| |
| return GL_TRUE; |
| } |
| |
| void _glfwPlatformTerminate(void) |
| { |
| _glfwTerminateContextAPI(); |
| |
| if (_glfw.wl.registry) |
| wl_registry_destroy(_glfw.wl.registry); |
| if (_glfw.wl.display) |
| wl_display_flush(_glfw.wl.display); |
| if (_glfw.wl.display) |
| wl_display_disconnect(_glfw.wl.display); |
| } |
| |
| const char* _glfwPlatformGetVersionString(void) |
| { |
| const char* version = _GLFW_VERSION_NUMBER " Wayland EGL " |
| #if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK) |
| " clock_gettime" |
| #endif |
| #if defined(_GLFW_BUILD_DLL) |
| " shared" |
| #endif |
| ; |
| |
| return version; |
| } |
| |