2014-11-06 09:26:16 +01:00
|
|
|
//========================================================================
|
2016-08-18 23:42:15 +02:00
|
|
|
// GLFW 3.3 Mir - www.glfw.org
|
2014-11-06 09:26:16 +01:00
|
|
|
//------------------------------------------------------------------------
|
2017-03-29 04:03:29 +02:00
|
|
|
// Copyright (c) 2014-2017 Brandon Schaefer <brandon.schaefer@canonical.com>
|
2014-11-06 09:26:16 +01:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
|
2014-11-06 09:21:12 +01:00
|
|
|
#include "internal.h"
|
2014-11-06 09:24:49 +01:00
|
|
|
|
|
|
|
#include <linux/input.h>
|
2014-11-10 18:42:41 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-11-06 09:24:49 +01:00
|
|
|
|
2014-11-06 23:52:38 +01:00
|
|
|
|
2014-11-10 18:42:41 +01:00
|
|
|
typedef struct EventNode
|
|
|
|
{
|
|
|
|
TAILQ_ENTRY(EventNode) entries;
|
2015-07-30 19:59:32 +02:00
|
|
|
const MirEvent* event;
|
2014-11-10 18:42:41 +01:00
|
|
|
_GLFWwindow* window;
|
|
|
|
} EventNode;
|
|
|
|
|
|
|
|
static void deleteNode(EventQueue* queue, EventNode* node)
|
|
|
|
{
|
2015-07-30 19:59:32 +02:00
|
|
|
mir_event_unref(node->event);
|
2014-11-10 18:42:41 +01:00
|
|
|
free(node);
|
|
|
|
}
|
|
|
|
|
2015-08-23 19:30:04 +02:00
|
|
|
static GLFWbool emptyEventQueue(EventQueue* queue)
|
2014-11-10 18:42:41 +01:00
|
|
|
{
|
2015-08-23 19:30:04 +02:00
|
|
|
return queue->head.tqh_first == NULL;
|
2014-11-10 18:42:41 +01:00
|
|
|
}
|
|
|
|
|
2015-07-30 19:59:32 +02:00
|
|
|
// TODO The mir_event_ref is not supposed to be used but ... its needed
|
|
|
|
// in this case. Need to wait until we can read from an FD set up by mir
|
|
|
|
// for single threaded event handling.
|
|
|
|
static EventNode* newEventNode(const MirEvent* event, _GLFWwindow* context)
|
2014-11-10 18:42:41 +01:00
|
|
|
{
|
2016-08-17 00:26:07 +02:00
|
|
|
EventNode* newNode = calloc(1, sizeof(EventNode));
|
|
|
|
newNode->event = mir_event_ref(event);
|
|
|
|
newNode->window = context;
|
2014-11-10 18:42:41 +01:00
|
|
|
|
2016-08-17 00:26:07 +02:00
|
|
|
return newNode;
|
2014-11-10 18:42:41 +01:00
|
|
|
}
|
|
|
|
|
2015-07-30 19:59:32 +02:00
|
|
|
static void enqueueEvent(const MirEvent* event, _GLFWwindow* context)
|
2014-11-10 18:42:41 +01:00
|
|
|
{
|
2016-08-17 00:26:07 +02:00
|
|
|
pthread_mutex_lock(&_glfw.mir.eventMutex);
|
2014-11-10 18:42:41 +01:00
|
|
|
|
2016-08-17 00:26:07 +02:00
|
|
|
EventNode* newNode = newEventNode(event, context);
|
|
|
|
TAILQ_INSERT_TAIL(&_glfw.mir.eventQueue->head, newNode, entries);
|
2014-11-10 18:42:41 +01:00
|
|
|
|
2016-08-17 00:26:07 +02:00
|
|
|
pthread_cond_signal(&_glfw.mir.eventCond);
|
2014-11-10 18:42:41 +01:00
|
|
|
|
2016-08-17 00:26:07 +02:00
|
|
|
pthread_mutex_unlock(&_glfw.mir.eventMutex);
|
2014-11-10 18:42:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static EventNode* dequeueEvent(EventQueue* queue)
|
|
|
|
{
|
|
|
|
EventNode* node = NULL;
|
|
|
|
|
2016-08-17 00:26:07 +02:00
|
|
|
pthread_mutex_lock(&_glfw.mir.eventMutex);
|
2014-11-10 18:42:41 +01:00
|
|
|
|
|
|
|
node = queue->head.tqh_first;
|
|
|
|
|
|
|
|
if (node)
|
|
|
|
TAILQ_REMOVE(&queue->head, node, entries);
|
|
|
|
|
2016-08-17 00:26:07 +02:00
|
|
|
pthread_mutex_unlock(&_glfw.mir.eventMutex);
|
2014-11-10 18:42:41 +01:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2014-11-06 23:52:38 +01:00
|
|
|
static MirPixelFormat findValidPixelFormat(void)
|
2014-11-06 09:23:02 +01:00
|
|
|
{
|
2015-01-05 23:11:11 +01:00
|
|
|
unsigned int i, validFormats, mirPixelFormats = 32;
|
|
|
|
MirPixelFormat formats[mir_pixel_formats];
|
2014-11-06 09:23:02 +01:00
|
|
|
|
|
|
|
mir_connection_get_available_surface_formats(_glfw.mir.connection, formats,
|
2015-01-05 23:11:11 +01:00
|
|
|
mirPixelFormats, &validFormats);
|
2014-11-06 09:23:02 +01:00
|
|
|
|
2014-11-06 23:52:38 +01:00
|
|
|
for (i = 0; i < validFormats; i++)
|
2014-11-06 09:23:02 +01:00
|
|
|
{
|
2014-11-06 23:52:38 +01:00
|
|
|
if (formats[i] == mir_pixel_format_abgr_8888 ||
|
|
|
|
formats[i] == mir_pixel_format_xbgr_8888 ||
|
|
|
|
formats[i] == mir_pixel_format_argb_8888 ||
|
|
|
|
formats[i] == mir_pixel_format_xrgb_8888)
|
2014-11-06 09:23:02 +01:00
|
|
|
{
|
2014-11-06 23:52:38 +01:00
|
|
|
return formats[i];
|
2014-11-06 09:23:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mir_pixel_format_invalid;
|
|
|
|
}
|
|
|
|
|
2014-11-06 23:52:38 +01:00
|
|
|
static int mirModToGLFWMod(uint32_t mods)
|
2014-11-06 09:27:54 +01:00
|
|
|
{
|
2014-11-06 23:52:38 +01:00
|
|
|
int publicMods = 0x0;
|
2014-11-06 09:27:54 +01:00
|
|
|
|
2015-07-30 19:59:32 +02:00
|
|
|
if (mods & mir_input_event_modifier_alt)
|
2014-11-06 23:52:38 +01:00
|
|
|
publicMods |= GLFW_MOD_ALT;
|
2015-07-30 19:59:32 +02:00
|
|
|
else if (mods & mir_input_event_modifier_shift)
|
2014-11-06 23:52:38 +01:00
|
|
|
publicMods |= GLFW_MOD_SHIFT;
|
2015-07-30 19:59:32 +02:00
|
|
|
else if (mods & mir_input_event_modifier_ctrl)
|
2014-11-06 23:52:38 +01:00
|
|
|
publicMods |= GLFW_MOD_CONTROL;
|
2015-07-30 19:59:32 +02:00
|
|
|
else if (mods & mir_input_event_modifier_meta)
|
2014-11-06 23:52:38 +01:00
|
|
|
publicMods |= GLFW_MOD_SUPER;
|
2014-11-06 09:27:54 +01:00
|
|
|
|
2014-11-06 23:52:38 +01:00
|
|
|
return publicMods;
|
2014-11-06 09:27:54 +01:00
|
|
|
}
|
|
|
|
|
2014-11-06 09:24:49 +01:00
|
|
|
static int toGLFWKeyCode(uint32_t key)
|
|
|
|
{
|
2016-09-07 15:43:39 +02:00
|
|
|
if (key < sizeof(_glfw.mir.keycodes) / sizeof(_glfw.mir.keycodes[0]))
|
|
|
|
return _glfw.mir.keycodes[key];
|
2015-11-12 15:06:46 +01:00
|
|
|
|
|
|
|
return GLFW_KEY_UNKNOWN;
|
2014-11-06 09:24:49 +01:00
|
|
|
}
|
|
|
|
|
2015-07-30 19:59:32 +02:00
|
|
|
static void handleKeyEvent(const MirKeyboardEvent* key_event, _GLFWwindow* window)
|
2014-11-06 09:24:49 +01:00
|
|
|
{
|
2015-07-30 19:59:32 +02:00
|
|
|
const int action = mir_keyboard_event_action (key_event);
|
|
|
|
const int scan_code = mir_keyboard_event_scan_code(key_event);
|
|
|
|
const int key_code = mir_keyboard_event_key_code (key_event);
|
|
|
|
const int modifiers = mir_keyboard_event_modifiers(key_event);
|
2014-11-06 09:24:49 +01:00
|
|
|
|
2015-07-30 19:59:32 +02:00
|
|
|
const int pressed = action == mir_keyboard_action_up ? GLFW_RELEASE : GLFW_PRESS;
|
|
|
|
const int mods = mirModToGLFWMod(modifiers);
|
|
|
|
const long text = _glfwKeySym2Unicode(key_code);
|
|
|
|
const int plain = !(mods & (GLFW_MOD_CONTROL | GLFW_MOD_ALT));
|
|
|
|
|
|
|
|
_glfwInputKey(window, toGLFWKeyCode(scan_code), scan_code, pressed, mods);
|
2014-11-06 09:24:49 +01:00
|
|
|
|
2014-11-06 09:27:54 +01:00
|
|
|
if (text != -1)
|
|
|
|
_glfwInputChar(window, text, mods, plain);
|
2014-11-06 09:24:49 +01:00
|
|
|
}
|
|
|
|
|
2015-07-30 19:59:32 +02:00
|
|
|
static void handlePointerButton(_GLFWwindow* window,
|
|
|
|
int pressed,
|
|
|
|
const MirPointerEvent* pointer_event)
|
2014-11-06 09:24:49 +01:00
|
|
|
{
|
2015-07-30 19:59:32 +02:00
|
|
|
int mods = mir_pointer_event_modifiers(pointer_event);
|
|
|
|
const int publicMods = mirModToGLFWMod(mods);
|
2016-04-17 22:48:10 +02:00
|
|
|
MirPointerButton button = mir_pointer_button_primary;
|
|
|
|
static uint32_t oldButtonStates = 0;
|
|
|
|
uint32_t newButtonStates = mir_pointer_event_buttons(pointer_event);
|
|
|
|
int publicButton = GLFW_MOUSE_BUTTON_LEFT;
|
|
|
|
|
|
|
|
// XOR our old button states our new states to figure out what was added or removed
|
|
|
|
button = newButtonStates ^ oldButtonStates;
|
2014-11-06 09:24:49 +01:00
|
|
|
|
|
|
|
switch (button)
|
|
|
|
{
|
2015-07-30 19:59:32 +02:00
|
|
|
case mir_pointer_button_primary:
|
2014-11-06 23:52:38 +01:00
|
|
|
publicButton = GLFW_MOUSE_BUTTON_LEFT;
|
2014-11-06 09:24:49 +01:00
|
|
|
break;
|
2015-07-30 19:59:32 +02:00
|
|
|
case mir_pointer_button_secondary:
|
2014-11-06 23:52:38 +01:00
|
|
|
publicButton = GLFW_MOUSE_BUTTON_RIGHT;
|
2014-11-06 09:24:49 +01:00
|
|
|
break;
|
2015-07-30 19:59:32 +02:00
|
|
|
case mir_pointer_button_tertiary:
|
2014-11-06 23:52:38 +01:00
|
|
|
publicButton = GLFW_MOUSE_BUTTON_MIDDLE;
|
2014-11-06 09:24:49 +01:00
|
|
|
break;
|
2015-07-30 19:59:32 +02:00
|
|
|
case mir_pointer_button_forward:
|
2014-11-06 09:24:49 +01:00
|
|
|
// FIXME What is the forward button?
|
2014-11-06 23:52:38 +01:00
|
|
|
publicButton = GLFW_MOUSE_BUTTON_4;
|
2014-11-06 09:24:49 +01:00
|
|
|
break;
|
2015-07-30 19:59:32 +02:00
|
|
|
case mir_pointer_button_back:
|
2014-11-06 09:24:49 +01:00
|
|
|
// FIXME What is the back button?
|
2014-11-06 23:52:38 +01:00
|
|
|
publicButton = GLFW_MOUSE_BUTTON_5;
|
2014-11-06 09:24:49 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-04-17 22:48:10 +02:00
|
|
|
oldButtonStates = newButtonStates;
|
|
|
|
|
2014-11-06 23:52:38 +01:00
|
|
|
_glfwInputMouseClick(window, publicButton, pressed, publicMods);
|
2014-11-06 09:24:49 +01:00
|
|
|
}
|
|
|
|
|
2015-07-30 19:59:32 +02:00
|
|
|
static void handlePointerMotion(_GLFWwindow* window,
|
|
|
|
const MirPointerEvent* pointer_event)
|
2014-11-06 09:24:49 +01:00
|
|
|
{
|
2016-08-17 00:26:07 +02:00
|
|
|
const int hscroll = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_hscroll);
|
|
|
|
const int vscroll = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_vscroll);
|
2014-11-06 09:24:49 +01:00
|
|
|
|
2016-08-17 00:26:07 +02:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
|
|
|
{
|
|
|
|
if (_glfw.mir.disabledCursorWindow != window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const int dx = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_relative_x);
|
|
|
|
const int dy = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_relative_y);
|
|
|
|
const int current_x = window->virtualCursorPosX;
|
|
|
|
const int current_y = window->virtualCursorPosY;
|
|
|
|
|
|
|
|
_glfwInputCursorPos(window, dx + current_x, dy + current_y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const int x = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_x);
|
|
|
|
const int y = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_y);
|
|
|
|
|
|
|
|
_glfwInputCursorPos(window, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hscroll != 0 || vscroll != 0)
|
|
|
|
_glfwInputScroll(window, hscroll, vscroll);
|
2014-11-06 09:24:49 +01:00
|
|
|
}
|
|
|
|
|
2015-07-30 19:59:32 +02:00
|
|
|
static void handlePointerEvent(const MirPointerEvent* pointer_event,
|
2014-11-06 23:52:38 +01:00
|
|
|
_GLFWwindow* window)
|
2014-11-06 09:24:49 +01:00
|
|
|
{
|
2015-07-30 19:59:32 +02:00
|
|
|
int action = mir_pointer_event_action(pointer_event);
|
|
|
|
|
|
|
|
switch (action)
|
2014-11-06 09:24:49 +01:00
|
|
|
{
|
2015-07-30 19:59:32 +02:00
|
|
|
case mir_pointer_action_button_down:
|
|
|
|
handlePointerButton(window, GLFW_PRESS, pointer_event);
|
2014-11-06 09:24:49 +01:00
|
|
|
break;
|
2015-07-30 19:59:32 +02:00
|
|
|
case mir_pointer_action_button_up:
|
|
|
|
handlePointerButton(window, GLFW_RELEASE, pointer_event);
|
2014-11-06 09:24:49 +01:00
|
|
|
break;
|
2015-07-30 19:59:32 +02:00
|
|
|
case mir_pointer_action_motion:
|
|
|
|
handlePointerMotion(window, pointer_event);
|
2014-11-06 09:24:49 +01:00
|
|
|
break;
|
2015-07-30 19:59:32 +02:00
|
|
|
case mir_pointer_action_enter:
|
|
|
|
case mir_pointer_action_leave:
|
2014-11-06 09:24:49 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-30 19:59:32 +02:00
|
|
|
static void handleInput(const MirInputEvent* input_event, _GLFWwindow* window)
|
2014-11-06 09:24:49 +01:00
|
|
|
{
|
2015-07-30 19:59:32 +02:00
|
|
|
int type = mir_input_event_get_type(input_event);
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case mir_input_event_type_key:
|
|
|
|
handleKeyEvent(mir_input_event_get_keyboard_event(input_event), window);
|
|
|
|
break;
|
|
|
|
case mir_input_event_type_pointer:
|
|
|
|
handlePointerEvent(mir_input_event_get_pointer_event(input_event), window);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-11-06 09:24:49 +01:00
|
|
|
}
|
|
|
|
|
2015-07-30 19:59:32 +02:00
|
|
|
static void handleEvent(const MirEvent* event, _GLFWwindow* window)
|
2014-11-06 09:24:49 +01:00
|
|
|
{
|
2015-07-30 19:59:32 +02:00
|
|
|
int type = mir_event_get_type(event);
|
|
|
|
|
|
|
|
switch (type)
|
2014-11-06 23:52:38 +01:00
|
|
|
{
|
2015-07-30 19:59:32 +02:00
|
|
|
case mir_event_type_input:
|
|
|
|
handleInput(mir_event_get_input_event(event), window);
|
2014-11-06 23:52:38 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-11-06 09:24:49 +01:00
|
|
|
}
|
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
static void addNewEvent(MirWindow* window, const MirEvent* event, void* context)
|
2014-11-10 18:42:41 +01:00
|
|
|
{
|
|
|
|
enqueueEvent(event, context);
|
|
|
|
}
|
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
static GLFWbool createWindow(_GLFWwindow* window)
|
2014-11-06 09:21:12 +01:00
|
|
|
{
|
2017-03-29 04:03:29 +02:00
|
|
|
MirWindowSpec* spec;
|
2015-07-30 19:59:32 +02:00
|
|
|
MirBufferUsage buffer_usage = mir_buffer_usage_hardware;
|
|
|
|
MirPixelFormat pixel_format = findValidPixelFormat();
|
2014-11-06 09:23:02 +01:00
|
|
|
|
2015-07-30 19:59:32 +02:00
|
|
|
if (pixel_format == mir_pixel_format_invalid)
|
2014-11-06 09:23:02 +01:00
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2014-11-06 23:52:38 +01:00
|
|
|
"Mir: Unable to find a correct pixel format");
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2014-11-06 09:23:02 +01:00
|
|
|
}
|
2016-08-17 00:26:07 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
spec = mir_create_normal_window_spec(_glfw.mir.connection,
|
|
|
|
window->mir.width,
|
|
|
|
window->mir.height);
|
2015-07-30 19:59:32 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
mir_window_spec_set_pixel_format(spec, pixel_format);
|
|
|
|
mir_window_spec_set_buffer_usage(spec, buffer_usage);
|
2015-07-30 19:59:32 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
window->mir.window = mir_create_window_sync(spec);
|
|
|
|
mir_window_spec_release(spec);
|
2014-11-06 09:23:02 +01:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
if (!mir_window_is_valid(window->mir.window))
|
2014-11-06 09:23:02 +01:00
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2017-03-29 04:03:29 +02:00
|
|
|
"Mir: Unable to create window: %s",
|
|
|
|
mir_window_get_error_message(window->mir.window));
|
2015-01-05 23:11:11 +01:00
|
|
|
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2014-11-06 09:23:02 +01:00
|
|
|
}
|
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
mir_window_set_event_handler(window->mir.window, addNewEvent, window);
|
2014-11-06 09:24:49 +01:00
|
|
|
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_TRUE;
|
2014-11-06 09:25:52 +01:00
|
|
|
}
|
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
static void setWindowConfinement(_GLFWwindow* window, MirPointerConfinementState state)
|
2016-08-17 00:26:07 +02:00
|
|
|
{
|
2017-03-29 04:03:29 +02:00
|
|
|
MirWindowSpec* spec;
|
2016-08-17 00:26:07 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
spec = mir_create_window_spec(_glfw.mir.connection);
|
|
|
|
mir_window_spec_set_pointer_confinement(spec, state);
|
2016-08-17 00:26:07 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
mir_window_apply_spec(window->mir.window, spec);
|
|
|
|
mir_window_spec_release(spec);
|
2016-08-17 00:26:07 +02:00
|
|
|
}
|
|
|
|
|
2014-11-10 18:42:41 +01:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW internal API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-12-03 18:16:46 +01:00
|
|
|
void _glfwInitEventQueueMir(EventQueue* queue)
|
2014-11-10 18:42:41 +01:00
|
|
|
{
|
|
|
|
TAILQ_INIT(&queue->head);
|
|
|
|
}
|
|
|
|
|
2015-12-03 18:16:46 +01:00
|
|
|
void _glfwDeleteEventQueueMir(EventQueue* queue)
|
2014-11-10 18:42:41 +01:00
|
|
|
{
|
2014-11-10 21:17:21 +01:00
|
|
|
if (queue)
|
2014-11-10 18:42:41 +01:00
|
|
|
{
|
2014-11-10 21:17:21 +01:00
|
|
|
EventNode* node, *node_next;
|
|
|
|
node = queue->head.tqh_first;
|
2014-11-10 18:42:41 +01:00
|
|
|
|
2014-11-10 21:17:21 +01:00
|
|
|
while (node != NULL)
|
|
|
|
{
|
|
|
|
node_next = node->entries.tqe_next;
|
2014-11-10 18:42:41 +01:00
|
|
|
|
2014-11-10 21:17:21 +01:00
|
|
|
TAILQ_REMOVE(&queue->head, node, entries);
|
|
|
|
deleteNode(queue, node);
|
|
|
|
|
|
|
|
node = node_next;
|
|
|
|
}
|
|
|
|
|
2014-11-12 18:41:12 +01:00
|
|
|
free(queue);
|
|
|
|
}
|
2014-11-10 18:42:41 +01:00
|
|
|
}
|
2014-11-06 23:52:38 +01:00
|
|
|
|
2014-11-06 09:25:52 +01:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
|
|
|
const _GLFWwndconfig* wndconfig,
|
|
|
|
const _GLFWctxconfig* ctxconfig,
|
|
|
|
const _GLFWfbconfig* fbconfig)
|
|
|
|
{
|
2016-03-14 15:17:28 +01:00
|
|
|
if (window->monitor)
|
2014-11-06 21:07:20 +01:00
|
|
|
{
|
2014-11-06 23:45:56 +01:00
|
|
|
GLFWvidmode mode;
|
2016-03-14 15:17:28 +01:00
|
|
|
_glfwPlatformGetVideoMode(window->monitor, &mode);
|
2014-11-06 23:45:56 +01:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
mir_window_set_state(window->mir.window, mir_window_state_fullscreen);
|
2014-11-06 21:07:20 +01:00
|
|
|
|
2014-11-06 23:45:56 +01:00
|
|
|
if (wndconfig->width > mode.width || wndconfig->height > mode.height)
|
2014-11-06 21:07:20 +01:00
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2017-03-29 04:03:29 +02:00
|
|
|
"Mir: Requested window size too large: %ix%i",
|
2015-07-30 19:59:32 +02:00
|
|
|
wndconfig->width, wndconfig->height);
|
2014-11-06 21:07:20 +01:00
|
|
|
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2014-11-06 21:07:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-06 09:25:52 +01:00
|
|
|
window->mir.width = wndconfig->width;
|
|
|
|
window->mir.height = wndconfig->height;
|
2016-08-17 00:26:07 +02:00
|
|
|
window->mir.currentCursor = NULL;
|
2014-11-06 09:25:52 +01:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
if (!createWindow(window))
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2014-11-06 09:25:52 +01:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
window->mir.nativeWindow = mir_buffer_stream_get_egl_native_window(
|
|
|
|
mir_window_get_buffer_stream(window->mir.window));
|
2014-11-06 09:25:52 +01:00
|
|
|
|
2016-03-28 13:19:31 +02:00
|
|
|
if (ctxconfig->client != GLFW_NO_API)
|
2016-04-17 01:27:42 +02:00
|
|
|
{
|
2017-03-02 17:52:32 +01:00
|
|
|
if (ctxconfig->source == GLFW_EGL_CONTEXT_API ||
|
|
|
|
ctxconfig->source == GLFW_NATIVE_CONTEXT_API)
|
|
|
|
{
|
|
|
|
if (!_glfwInitEGL())
|
|
|
|
return GLFW_FALSE;
|
|
|
|
if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig))
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
|
|
|
else if (ctxconfig->source == GLFW_OSMESA_CONTEXT_API)
|
|
|
|
{
|
|
|
|
if (!_glfwInitOSMesa())
|
|
|
|
return GLFW_FALSE;
|
|
|
|
if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig))
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
2016-04-17 01:27:42 +02:00
|
|
|
}
|
|
|
|
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_TRUE;
|
2014-11-06 09:21:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformDestroyWindow(_GLFWwindow* window)
|
|
|
|
{
|
2016-08-17 00:26:07 +02:00
|
|
|
if (_glfw.mir.disabledCursorWindow == window)
|
|
|
|
_glfw.mir.disabledCursorWindow = NULL;
|
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
if (mir_window_is_valid(window->mir.window))
|
2014-11-06 23:52:38 +01:00
|
|
|
{
|
2017-03-29 04:03:29 +02:00
|
|
|
mir_window_release_sync(window->mir.window);
|
|
|
|
window->mir.window= NULL;
|
2014-11-06 23:52:38 +01:00
|
|
|
}
|
2014-11-06 21:07:20 +01:00
|
|
|
|
2016-08-05 11:22:55 +02:00
|
|
|
if (window->context.destroy)
|
2016-05-25 14:43:51 +02:00
|
|
|
window->context.destroy(window);
|
2014-11-06 09:21:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
|
|
|
|
{
|
2017-03-29 04:03:29 +02:00
|
|
|
MirWindowSpec* spec;
|
2015-07-30 19:59:32 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
spec = mir_create_window_spec(_glfw.mir.connection);
|
|
|
|
mir_window_spec_set_name(spec, title);
|
|
|
|
mir_window_apply_spec(window->mir.window, spec);
|
|
|
|
mir_window_spec_release(spec);
|
2015-07-30 19:59:32 +02:00
|
|
|
}
|
|
|
|
|
2016-03-07 14:55:30 +01:00
|
|
|
void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
|
|
|
|
int count, const GLFWimage* images)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
|
|
|
|
}
|
|
|
|
|
2015-07-30 19:59:32 +02:00
|
|
|
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
|
|
|
|
{
|
2017-03-29 04:03:29 +02:00
|
|
|
MirWindowSpec* spec;
|
2015-07-30 19:59:32 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
spec = mir_create_window_spec(_glfw.mir.connection);
|
|
|
|
mir_window_spec_set_width (spec, width);
|
|
|
|
mir_window_spec_set_height(spec, height);
|
2015-07-30 19:59:32 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
mir_window_apply_spec(window->mir.window, spec);
|
|
|
|
mir_window_spec_release(spec);
|
2014-11-06 09:21:12 +01:00
|
|
|
}
|
|
|
|
|
2014-02-13 02:57:59 +01:00
|
|
|
void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window,
|
|
|
|
int minwidth, int minheight,
|
|
|
|
int maxwidth, int maxheight)
|
|
|
|
{
|
2017-03-29 04:03:29 +02:00
|
|
|
MirWindowSpec* spec;
|
|
|
|
|
|
|
|
spec = mir_create_window_spec(_glfw.mir.connection);
|
|
|
|
mir_window_spec_set_max_width (spec, maxwidth);
|
|
|
|
mir_window_spec_set_max_height(spec, maxheight);
|
|
|
|
mir_window_spec_set_min_width (spec, minwidth);
|
|
|
|
mir_window_spec_set_min_height(spec, minheight);
|
|
|
|
|
|
|
|
mir_window_apply_spec(window->mir.window, spec);
|
|
|
|
mir_window_spec_release(spec);
|
2014-02-13 02:57:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
|
|
|
|
}
|
|
|
|
|
2014-11-06 09:21:12 +01:00
|
|
|
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos)
|
|
|
|
{
|
2014-11-06 09:24:08 +01:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 19:51:14 +01:00
|
|
|
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
|
2014-11-06 09:21:12 +01:00
|
|
|
}
|
|
|
|
|
2014-11-06 23:52:38 +01:00
|
|
|
void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
|
|
|
|
int* left, int* top,
|
|
|
|
int* right, int* bottom)
|
2014-11-06 09:26:39 +01:00
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 19:51:14 +01:00
|
|
|
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
|
2014-11-06 09:26:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 19:51:14 +01:00
|
|
|
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
|
2014-11-06 09:26:39 +01:00
|
|
|
}
|
|
|
|
|
2014-11-06 09:21:12 +01:00
|
|
|
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
|
|
|
|
{
|
2014-11-06 23:52:38 +01:00
|
|
|
if (width)
|
|
|
|
*width = window->mir.width;
|
|
|
|
if (height)
|
|
|
|
*height = window->mir.height;
|
2014-11-06 09:21:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformIconifyWindow(_GLFWwindow* window)
|
|
|
|
{
|
2017-03-29 04:03:29 +02:00
|
|
|
MirWindowSpec* spec;
|
2016-08-17 00:26:07 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
spec = mir_create_window_spec(_glfw.mir.connection);
|
|
|
|
mir_window_spec_set_state(spec, mir_window_state_minimized);
|
2016-08-17 00:26:07 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
mir_window_apply_spec(window->mir.window, spec);
|
|
|
|
mir_window_spec_release(spec);
|
2014-11-06 09:21:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformRestoreWindow(_GLFWwindow* window)
|
|
|
|
{
|
2017-03-29 04:03:29 +02:00
|
|
|
MirWindowSpec* spec;
|
2016-08-17 00:26:07 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
spec = mir_create_window_spec(_glfw.mir.connection);
|
|
|
|
mir_window_spec_set_state(spec, mir_window_state_restored);
|
2016-08-17 00:26:07 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
mir_window_apply_spec(window->mir.window, spec);
|
|
|
|
mir_window_spec_release(spec);
|
2014-11-06 09:21:12 +01:00
|
|
|
}
|
|
|
|
|
2015-10-13 12:50:59 +02:00
|
|
|
void _glfwPlatformMaximizeWindow(_GLFWwindow* window)
|
|
|
|
{
|
2017-03-29 04:03:29 +02:00
|
|
|
MirWindowSpec* spec;
|
2016-08-17 00:26:07 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
spec = mir_create_window_spec(_glfw.mir.connection);
|
|
|
|
mir_window_spec_set_state(spec, mir_window_state_maximized);
|
2016-08-17 00:26:07 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
mir_window_apply_spec(window->mir.window, spec);
|
|
|
|
mir_window_spec_release(spec);
|
2015-10-13 12:50:59 +02:00
|
|
|
}
|
|
|
|
|
2014-11-06 09:21:12 +01:00
|
|
|
void _glfwPlatformHideWindow(_GLFWwindow* window)
|
2014-11-06 09:26:39 +01:00
|
|
|
{
|
2017-03-29 04:03:29 +02:00
|
|
|
MirWindowSpec* spec;
|
2015-07-30 19:59:32 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
spec = mir_create_window_spec(_glfw.mir.connection);
|
|
|
|
mir_window_spec_set_state(spec, mir_window_state_hidden);
|
2015-07-30 19:59:32 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
mir_window_apply_spec(window->mir.window, spec);
|
|
|
|
mir_window_spec_release(spec);
|
2014-11-06 09:26:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformShowWindow(_GLFWwindow* window)
|
|
|
|
{
|
2017-03-29 04:03:29 +02:00
|
|
|
MirWindowSpec* spec;
|
2015-07-30 19:59:32 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
spec = mir_create_window_spec(_glfw.mir.connection);
|
|
|
|
mir_window_spec_set_state(spec, mir_window_state_restored);
|
2015-07-30 19:59:32 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
mir_window_apply_spec(window->mir.window, spec);
|
|
|
|
mir_window_spec_release(spec);
|
2014-11-06 09:26:39 +01:00
|
|
|
}
|
|
|
|
|
2017-03-21 14:02:57 +01:00
|
|
|
void _glfwPlatformRequestWindowAttention(_GLFWwindow* window)
|
|
|
|
{
|
2017-05-11 14:36:56 +02:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
|
2017-03-21 14:02:57 +01:00
|
|
|
}
|
|
|
|
|
2016-02-21 15:42:49 +01:00
|
|
|
void _glfwPlatformFocusWindow(_GLFWwindow* window)
|
2014-11-06 09:21:12 +01:00
|
|
|
{
|
2014-11-06 21:07:20 +01:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 19:51:14 +01:00
|
|
|
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
|
2014-11-06 09:21:12 +01:00
|
|
|
}
|
|
|
|
|
2016-02-23 12:26:42 +01:00
|
|
|
void _glfwPlatformSetWindowMonitor(_GLFWwindow* window,
|
|
|
|
_GLFWmonitor* monitor,
|
|
|
|
int xpos, int ypos,
|
|
|
|
int width, int height,
|
|
|
|
int refreshRate)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
|
|
|
|
}
|
|
|
|
|
2014-12-26 12:25:48 +01:00
|
|
|
int _glfwPlatformWindowFocused(_GLFWwindow* window)
|
|
|
|
{
|
2017-03-29 04:03:29 +02:00
|
|
|
return mir_window_get_focus_state(window->mir.window) == mir_window_focus_state_focused;
|
2014-12-26 12:25:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int _glfwPlatformWindowIconified(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 19:51:14 +01:00
|
|
|
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2014-12-26 12:25:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int _glfwPlatformWindowVisible(_GLFWwindow* window)
|
|
|
|
{
|
2017-03-29 04:03:29 +02:00
|
|
|
return mir_window_get_visibility(window->mir.window) == mir_window_visibility_exposed;
|
2014-12-26 12:25:48 +01:00
|
|
|
}
|
|
|
|
|
2015-10-13 12:50:59 +02:00
|
|
|
int _glfwPlatformWindowMaximized(_GLFWwindow* window)
|
|
|
|
{
|
2017-03-29 04:03:29 +02:00
|
|
|
return mir_window_get_state(window->mir.window) == mir_window_state_maximized;
|
2015-10-13 12:50:59 +02:00
|
|
|
}
|
|
|
|
|
2016-09-30 01:52:22 +02:00
|
|
|
void _glfwPlatformSetWindowResizable(_GLFWwindow* window, GLFWbool enabled)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, GLFWbool enabled)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
|
|
|
|
}
|
|
|
|
|
2014-11-06 09:21:12 +01:00
|
|
|
void _glfwPlatformPollEvents(void)
|
|
|
|
{
|
2014-11-10 18:42:41 +01:00
|
|
|
EventNode* node = NULL;
|
|
|
|
|
2016-08-17 00:26:07 +02:00
|
|
|
while ((node = dequeueEvent(_glfw.mir.eventQueue)))
|
2014-11-10 18:42:41 +01:00
|
|
|
{
|
2015-07-30 19:59:32 +02:00
|
|
|
handleEvent(node->event, node->window);
|
2016-08-17 00:26:07 +02:00
|
|
|
deleteNode(_glfw.mir.eventQueue, node);
|
2014-11-10 18:42:41 +01:00
|
|
|
}
|
2014-11-06 09:21:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformWaitEvents(void)
|
|
|
|
{
|
2016-08-17 00:26:07 +02:00
|
|
|
pthread_mutex_lock(&_glfw.mir.eventMutex);
|
2014-11-10 18:42:41 +01:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
while (emptyEventQueue(_glfw.mir.eventQueue))
|
2016-08-17 00:26:07 +02:00
|
|
|
pthread_cond_wait(&_glfw.mir.eventCond, &_glfw.mir.eventMutex);
|
2014-11-10 18:42:41 +01:00
|
|
|
|
2016-08-17 00:26:07 +02:00
|
|
|
pthread_mutex_unlock(&_glfw.mir.eventMutex);
|
2014-11-10 18:42:41 +01:00
|
|
|
|
|
|
|
_glfwPlatformPollEvents();
|
2014-11-06 09:21:12 +01:00
|
|
|
}
|
|
|
|
|
2016-02-02 21:11:16 +01:00
|
|
|
void _glfwPlatformWaitEventsTimeout(double timeout)
|
|
|
|
{
|
2016-08-17 00:26:07 +02:00
|
|
|
pthread_mutex_lock(&_glfw.mir.eventMutex);
|
2016-02-02 21:11:16 +01:00
|
|
|
|
2016-08-17 00:26:07 +02:00
|
|
|
if (emptyEventQueue(_glfw.mir.eventQueue))
|
2016-02-02 21:11:16 +01:00
|
|
|
{
|
|
|
|
struct timespec time;
|
|
|
|
clock_gettime(CLOCK_REALTIME, &time);
|
|
|
|
time.tv_sec += (long) timeout;
|
|
|
|
time.tv_nsec += (long) ((timeout - (long) timeout) * 1e9);
|
2016-08-17 00:26:07 +02:00
|
|
|
pthread_cond_timedwait(&_glfw.mir.eventCond, &_glfw.mir.eventMutex, &time);
|
2016-02-02 21:11:16 +01:00
|
|
|
}
|
|
|
|
|
2016-08-17 00:26:07 +02:00
|
|
|
pthread_mutex_unlock(&_glfw.mir.eventMutex);
|
2016-02-02 21:11:16 +01:00
|
|
|
|
|
|
|
_glfwPlatformPollEvents();
|
|
|
|
}
|
|
|
|
|
2014-11-06 09:21:12 +01:00
|
|
|
void _glfwPlatformPostEmptyEvent(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height)
|
|
|
|
{
|
2014-11-06 23:52:38 +01:00
|
|
|
if (width)
|
|
|
|
*width = window->mir.width;
|
|
|
|
if (height)
|
|
|
|
*height = window->mir.height;
|
2014-11-06 09:21:12 +01:00
|
|
|
}
|
|
|
|
|
2014-11-06 23:52:38 +01:00
|
|
|
int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
|
|
|
|
const GLFWimage* image,
|
|
|
|
int xhot, int yhot)
|
2014-11-06 09:21:12 +01:00
|
|
|
{
|
2015-07-30 19:59:32 +02:00
|
|
|
MirBufferStream* stream;
|
2014-11-06 09:24:08 +01:00
|
|
|
|
2015-07-30 19:59:32 +02:00
|
|
|
int i_w = image->width;
|
|
|
|
int i_h = image->height;
|
|
|
|
|
|
|
|
stream = mir_connection_create_buffer_stream_sync(_glfw.mir.connection,
|
|
|
|
i_w, i_h,
|
2017-03-29 04:03:29 +02:00
|
|
|
mir_pixel_format_argb_8888,
|
2015-07-30 19:59:32 +02:00
|
|
|
mir_buffer_usage_software);
|
|
|
|
|
|
|
|
cursor->mir.conf = mir_cursor_configuration_from_buffer_stream(stream, xhot, yhot);
|
|
|
|
|
|
|
|
MirGraphicsRegion region;
|
|
|
|
mir_buffer_stream_get_graphics_region(stream, ®ion);
|
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
unsigned char* pixels = image->pixels;
|
|
|
|
char* dest = region.vaddr;
|
|
|
|
int i;
|
2015-07-30 19:59:32 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
for (i = 0; i < i_w * i_h; i++, pixels += 4)
|
2015-07-30 19:59:32 +02:00
|
|
|
{
|
2017-03-29 04:03:29 +02:00
|
|
|
unsigned int alpha = pixels[3];
|
|
|
|
*dest++ = (char)(pixels[2] * alpha / 255);
|
|
|
|
*dest++ = (char)(pixels[1] * alpha / 255);
|
|
|
|
*dest++ = (char)(pixels[0] * alpha / 255);
|
|
|
|
*dest++ = (char)alpha;
|
2015-07-30 19:59:32 +02:00
|
|
|
}
|
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
mir_buffer_stream_swap_buffers_sync(stream);
|
2016-08-17 00:26:07 +02:00
|
|
|
cursor->mir.customCursor = stream;
|
2015-07-30 19:59:32 +02:00
|
|
|
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_TRUE;
|
2015-07-30 19:59:32 +02:00
|
|
|
}
|
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
static const char* getSystemCursorName(int shape)
|
2015-07-30 19:59:32 +02:00
|
|
|
{
|
|
|
|
switch (shape)
|
|
|
|
{
|
|
|
|
case GLFW_ARROW_CURSOR:
|
2015-07-30 20:32:32 +02:00
|
|
|
return mir_arrow_cursor_name;
|
2015-07-30 19:59:32 +02:00
|
|
|
case GLFW_IBEAM_CURSOR:
|
2015-07-30 20:32:32 +02:00
|
|
|
return mir_caret_cursor_name;
|
2015-07-30 19:59:32 +02:00
|
|
|
case GLFW_CROSSHAIR_CURSOR:
|
2015-07-30 20:32:32 +02:00
|
|
|
return mir_crosshair_cursor_name;
|
2015-07-30 19:59:32 +02:00
|
|
|
case GLFW_HAND_CURSOR:
|
2015-07-30 20:32:32 +02:00
|
|
|
return mir_open_hand_cursor_name;
|
2015-07-30 19:59:32 +02:00
|
|
|
case GLFW_HRESIZE_CURSOR:
|
2015-07-30 20:32:32 +02:00
|
|
|
return mir_horizontal_resize_cursor_name;
|
2015-07-30 19:59:32 +02:00
|
|
|
case GLFW_VRESIZE_CURSOR:
|
|
|
|
return mir_vertical_resize_cursor_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2014-11-06 09:21:12 +01:00
|
|
|
}
|
|
|
|
|
2014-09-02 16:52:16 +02:00
|
|
|
int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
|
|
|
{
|
2017-03-29 04:03:29 +02:00
|
|
|
cursor->mir.conf = NULL;
|
|
|
|
cursor->mir.customCursor = NULL;
|
|
|
|
cursor->mir.cursorName = getSystemCursorName(shape);
|
2014-09-02 16:52:16 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
return cursor->mir.cursorName != NULL;
|
2014-09-02 16:52:16 +02:00
|
|
|
}
|
|
|
|
|
2014-11-06 09:21:12 +01:00
|
|
|
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
|
|
|
|
{
|
2015-07-30 19:59:32 +02:00
|
|
|
if (cursor->mir.conf)
|
|
|
|
mir_cursor_configuration_destroy(cursor->mir.conf);
|
2016-08-17 00:26:07 +02:00
|
|
|
if (cursor->mir.customCursor)
|
|
|
|
mir_buffer_stream_release_sync(cursor->mir.customCursor);
|
2014-11-06 09:21:12 +01:00
|
|
|
}
|
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
static void setCursorNameForWindow(MirWindow* window, char const* name)
|
|
|
|
{
|
|
|
|
MirWindowSpec* spec = mir_create_window_spec(_glfw.mir.connection);
|
|
|
|
mir_window_spec_set_cursor_name(spec, name);
|
|
|
|
mir_window_apply_spec(window, spec);
|
|
|
|
mir_window_spec_release(spec);
|
|
|
|
}
|
|
|
|
|
2014-11-06 09:21:12 +01:00
|
|
|
void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
|
|
|
|
{
|
2017-03-29 04:03:29 +02:00
|
|
|
if (cursor)
|
2015-07-30 19:59:32 +02:00
|
|
|
{
|
2016-08-17 00:26:07 +02:00
|
|
|
window->mir.currentCursor = cursor;
|
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
if (cursor->mir.cursorName)
|
|
|
|
{
|
|
|
|
setCursorNameForWindow(window->mir.window, cursor->mir.cursorName);
|
|
|
|
}
|
|
|
|
else if (cursor->mir.conf)
|
2015-07-30 19:59:32 +02:00
|
|
|
{
|
2017-03-29 04:03:29 +02:00
|
|
|
mir_window_configure_cursor(window->mir.window, cursor->mir.conf);
|
2015-07-30 19:59:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-29 04:03:29 +02:00
|
|
|
setCursorNameForWindow(window->mir.window, mir_default_cursor_name);
|
2015-07-30 19:59:32 +02:00
|
|
|
}
|
2014-11-06 09:21:12 +01:00
|
|
|
}
|
|
|
|
|
2015-01-06 01:23:10 +01:00
|
|
|
void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 19:51:14 +01:00
|
|
|
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
|
2015-01-06 01:23:10 +01:00
|
|
|
}
|
|
|
|
|
2014-11-06 09:21:12 +01:00
|
|
|
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos)
|
|
|
|
{
|
2014-11-06 09:24:08 +01:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 19:51:14 +01:00
|
|
|
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
|
2014-11-06 09:21:12 +01:00
|
|
|
}
|
|
|
|
|
2015-07-02 13:04:56 +02:00
|
|
|
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
2014-11-06 09:21:12 +01:00
|
|
|
{
|
2016-08-17 00:26:07 +02:00
|
|
|
if (mode == GLFW_CURSOR_DISABLED)
|
|
|
|
{
|
|
|
|
_glfw.mir.disabledCursorWindow = window;
|
2017-03-29 04:03:29 +02:00
|
|
|
setWindowConfinement(window, mir_pointer_confined_to_window);
|
|
|
|
setCursorNameForWindow(window->mir.window, mir_disabled_cursor_name);
|
2016-08-17 00:26:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If we were disabled before lets undo that!
|
|
|
|
if (_glfw.mir.disabledCursorWindow == window)
|
|
|
|
{
|
|
|
|
_glfw.mir.disabledCursorWindow = NULL;
|
2017-03-29 04:03:29 +02:00
|
|
|
setWindowConfinement(window, mir_pointer_unconfined);
|
2016-08-17 00:26:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (window->cursorMode == GLFW_CURSOR_NORMAL)
|
|
|
|
{
|
|
|
|
_glfwPlatformSetCursor(window, window->mir.currentCursor);
|
|
|
|
}
|
|
|
|
else if (window->cursorMode == GLFW_CURSOR_HIDDEN)
|
|
|
|
{
|
2017-03-29 04:03:29 +02:00
|
|
|
setCursorNameForWindow(window->mir.window, mir_disabled_cursor_name);
|
2016-08-17 00:26:07 +02:00
|
|
|
}
|
|
|
|
}
|
2014-11-06 09:21:12 +01:00
|
|
|
}
|
|
|
|
|
2017-07-11 23:00:17 +02:00
|
|
|
const char* _glfwPlatformGetScancodeName(int scancode)
|
2015-07-02 14:24:50 +02:00
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-09-06 15:40:31 +02:00
|
|
|
int _glfwPlatformGetKeyScancode(int key)
|
2016-08-11 19:11:40 +02:00
|
|
|
{
|
2016-09-07 15:43:39 +02:00
|
|
|
return _glfw.mir.scancodes[key];
|
2016-08-11 19:11:40 +02:00
|
|
|
}
|
|
|
|
|
2014-11-06 09:21:12 +01:00
|
|
|
void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
|
|
|
|
{
|
2014-11-06 09:24:08 +01:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 19:51:14 +01:00
|
|
|
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
|
2014-11-06 09:21:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
|
|
|
|
{
|
2014-11-06 09:24:08 +01:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 19:51:14 +01:00
|
|
|
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
|
2014-11-06 09:24:08 +01:00
|
|
|
|
|
|
|
return NULL;
|
2014-11-06 09:21:12 +01:00
|
|
|
}
|
2014-11-06 23:52:38 +01:00
|
|
|
|
2016-08-22 20:25:52 +02:00
|
|
|
void _glfwPlatformGetRequiredInstanceExtensions(char** extensions)
|
2015-08-10 20:19:04 +02:00
|
|
|
{
|
2016-08-22 20:25:52 +02:00
|
|
|
if (!_glfw.vk.KHR_surface || !_glfw.vk.KHR_mir_surface)
|
|
|
|
return;
|
2015-08-10 20:19:04 +02:00
|
|
|
|
2016-08-22 20:25:52 +02:00
|
|
|
extensions[0] = "VK_KHR_surface";
|
|
|
|
extensions[1] = "VK_KHR_mir_surface";
|
2015-08-10 20:19:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,
|
|
|
|
VkPhysicalDevice device,
|
2016-03-23 10:24:01 +01:00
|
|
|
uint32_t queuefamily)
|
2015-08-10 20:19:04 +02:00
|
|
|
{
|
2017-09-17 14:39:17 +02:00
|
|
|
PFN_vkGetPhysicalDeviceMirPresentationSupportKHR
|
|
|
|
vkGetPhysicalDeviceMirPresentationSupportKHR =
|
2015-08-10 20:19:04 +02:00
|
|
|
(PFN_vkGetPhysicalDeviceMirPresentationSupportKHR)
|
|
|
|
vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceMirPresentationSupportKHR");
|
|
|
|
if (!vkGetPhysicalDeviceMirPresentationSupportKHR)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_API_UNAVAILABLE,
|
|
|
|
"Mir: Vulkan instance missing VK_KHR_mir_surface extension");
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vkGetPhysicalDeviceMirPresentationSupportKHR(device,
|
|
|
|
queuefamily,
|
|
|
|
_glfw.mir.connection);
|
|
|
|
}
|
|
|
|
|
|
|
|
VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
|
|
|
|
_GLFWwindow* window,
|
|
|
|
const VkAllocationCallbacks* allocator,
|
|
|
|
VkSurfaceKHR* surface)
|
|
|
|
{
|
|
|
|
VkResult err;
|
2017-03-29 04:03:29 +02:00
|
|
|
VkMirWindowCreateInfoKHR sci;
|
|
|
|
PFN_vkCreateMirWindowKHR vkCreateMirWindowKHR;
|
2015-08-10 20:19:04 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
vkCreateMirWindowKHR = (PFN_vkCreateMirWindowKHR)
|
|
|
|
vkGetInstanceProcAddr(instance, "vkCreateMirWindowKHR");
|
|
|
|
if (!vkCreateMirWindowKHR)
|
2015-08-10 20:19:04 +02:00
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_API_UNAVAILABLE,
|
|
|
|
"Mir: Vulkan instance missing VK_KHR_mir_surface extension");
|
|
|
|
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&sci, 0, sizeof(sci));
|
|
|
|
sci.sType = VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR;
|
2016-02-18 14:48:33 +01:00
|
|
|
sci.connection = _glfw.mir.connection;
|
2017-03-29 04:03:29 +02:00
|
|
|
sci.mirWindow = window->mir.window;
|
2015-08-10 20:19:04 +02:00
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
err = vkCreateMirWindowKHR(instance, &sci, allocator, surface);
|
2015-08-10 20:19:04 +02:00
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Mir: Failed to create Vulkan surface: %s",
|
|
|
|
_glfwGetVulkanResultString(err));
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-08-16 22:02:31 +02:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW native API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
GLFWAPI MirConnection* glfwGetMirDisplay(void)
|
|
|
|
{
|
|
|
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
|
|
|
return _glfw.mir.connection;
|
|
|
|
}
|
|
|
|
|
2017-03-29 04:03:29 +02:00
|
|
|
GLFWAPI MirWindow* glfwGetMirWindow(GLFWwindow* handle)
|
2015-08-16 22:02:31 +02:00
|
|
|
{
|
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
|
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
2017-03-29 04:03:29 +02:00
|
|
|
return window->mir.window;
|
2015-08-16 22:02:31 +02:00
|
|
|
}
|
|
|
|
|