glfw/src/wayland_init.c

156 lines
4.5 KiB
C
Raw Normal View History

//========================================================================
// 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>
2014-03-19 15:11:19 +00:00
static void handlePing(void* data,
struct wl_shell_surface* shellSurface,
uint32_t serial)
{
wl_shell_surface_pong(shellSurface, serial);
}
2014-03-19 15:11:19 +00:00
static void handleConfigure(void* data,
struct wl_shell_surface* shellSurface,
uint32_t edges,
int32_t width,
int32_t height)
{
}
2014-03-19 15:11:19 +00:00
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)
{
_GLFWlibraryWayland* wayland = &_glfw.wayland;
if (strcmp(interface, "wl_compositor") == 0)
{
wayland->compositor =
wl_registry_bind(registry, name, &wl_compositor_interface, 1);
}
else if (strcmp(interface, "wl_shell") == 0)
{
wayland->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.wayland.display = wl_display_connect(NULL);
if (!_glfw.wayland.display)
return GL_FALSE;
_glfw.wayland.registry = wl_display_get_registry(_glfw.wayland.display);
wl_registry_add_listener(_glfw.wayland.registry, &registryListener, NULL);
_glfw.wayland.monitors = calloc(4, sizeof(_GLFWmonitor*));
_glfw.wayland.monitorsSize = 4;
2014-03-19 15:11:19 +00:00
// Sync so we got all registry objects
wl_display_roundtrip(_glfw.wayland.display);
2014-03-19 15:11:19 +00:00
// Sync so we got all initial output events
wl_display_roundtrip(_glfw.wayland.display);
if (!_glfwInitContextAPI())
return GL_FALSE;
_glfwInitTimer();
_glfwInitJoysticks();
return GL_TRUE;
}
void _glfwPlatformTerminate(void)
{
_glfwTerminateContextAPI();
if (_glfw.wayland.registry)
wl_registry_destroy(_glfw.wayland.registry);
if (_glfw.wayland.display)
wl_display_flush(_glfw.wayland.display);
if (_glfw.wayland.display)
wl_display_disconnect(_glfw.wayland.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;
}
2014-03-19 15:11:19 +00:00