1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 10:48:51 -05:00

Move to the new MirEvent 2.0 + 0.14/0.15 changes

Closes #568.
This commit is contained in:
Brandon Schaefer 2015-07-30 10:59:32 -07:00 committed by Camilla Berglund
parent 37e13361f5
commit 9527c93a1c
4 changed files with 281 additions and 128 deletions

View File

@ -1,7 +1,7 @@
//======================================================================== //========================================================================
// GLFW 3.1 Mir - www.glfw.org // GLFW 3.1 Mir - www.glfw.org
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Copyright (c) 2014 Brandon Schaefer <brandon.schaefer@canonical.com> // Copyright (c) 2014-2015 Brandon Schaefer <brandon.schaefer@canonical.com>
// //
// This software is provided 'as-is', without any express or implied // This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages // warranty. In no event will the authors be held liable for any damages
@ -55,6 +55,9 @@ int _glfwPlatformInit(void)
if (!_glfwInitContextAPI()) if (!_glfwInitContextAPI())
return GL_FALSE; return GL_FALSE;
// Need the default conf for when we set a NULL cursor
_glfw.mir.default_conf = mir_cursor_configuration_from_name(mir_arrow_cursor_name);
_glfwInitTimer(); _glfwInitTimer();
_glfwInitJoysticks(); _glfwInitJoysticks();

View File

@ -1,7 +1,7 @@
//======================================================================== //========================================================================
// GLFW 3.1 Mir - www.glfw.org // GLFW 3.1 Mir - www.glfw.org
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Copyright (c) 2014 Brandon Schaefer <brandon.schaefer@canonical.com> // Copyright (c) 2014-2015 Brandon Schaefer <brandon.schaefer@canonical.com>
// //
// This software is provided 'as-is', without any express or implied // This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages // warranty. In no event will the authors be held liable for any damages
@ -86,6 +86,39 @@ void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos)
*ypos = monitor->mir.y; *ypos = monitor->mir.y;
} }
void FillInRGBBitsFromPixelFormat(GLFWvidmode* mode, MirPixelFormat const pf)
{
switch (pf)
{
case mir_pixel_format_rgb_565:
mode->redBits = 5;
mode->greenBits = 6;
mode->blueBits = 5;
break;
case mir_pixel_format_rgba_5551:
mode->redBits = 5;
mode->greenBits = 5;
mode->blueBits = 5;
break;
case mir_pixel_format_rgba_4444:
mode->redBits = 4;
mode->greenBits = 4;
mode->blueBits = 4;
break;
case mir_pixel_format_abgr_8888:
case mir_pixel_format_xbgr_8888:
case mir_pixel_format_argb_8888:
case mir_pixel_format_xrgb_8888:
case mir_pixel_format_bgr_888:
case mir_pixel_format_rgb_888:
default:
mode->redBits = 8;
mode->greenBits = 8;
mode->blueBits = 8;
break;
}
}
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
{ {
int i; int i;
@ -106,9 +139,8 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
modes[*found].width = out->modes[*found].horizontal_resolution; modes[*found].width = out->modes[*found].horizontal_resolution;
modes[*found].height = out->modes[*found].vertical_resolution; modes[*found].height = out->modes[*found].vertical_resolution;
modes[*found].refreshRate = out->modes[*found].refresh_rate; modes[*found].refreshRate = out->modes[*found].refresh_rate;
modes[*found].redBits = 8;
modes[*found].greenBits = 8; FillInRGBBitsFromPixelFormat(&modes[*found], out->output_formats[*found]);
modes[*found].blueBits = 8;
} }
break; break;

View File

@ -1,7 +1,7 @@
//======================================================================== //========================================================================
// GLFW 3.1 Mir - www.glfw.org // GLFW 3.1 Mir - www.glfw.org
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Copyright (c) 2014 Brandon Schaefer <brandon.schaefer@canonical.com> // Copyright (c) 2014-2015 Brandon Schaefer <brandon.schaefer@canonical.com>
// //
// This software is provided 'as-is', without any express or implied // This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages // warranty. In no event will the authors be held liable for any damages
@ -89,6 +89,7 @@ typedef struct _GLFWlibraryMir
{ {
MirConnection* connection; MirConnection* connection;
MirEGLNativeDisplayType display; MirEGLNativeDisplayType display;
MirCursorConfiguration* default_conf;
EventQueue* event_queue; EventQueue* event_queue;
pthread_mutex_t event_mutex; pthread_mutex_t event_mutex;
@ -102,6 +103,8 @@ typedef struct _GLFWlibraryMir
// //
typedef struct _GLFWcursorMir typedef struct _GLFWcursorMir
{ {
MirCursorConfiguration* conf;
MirBufferStream* custom_cursor;
} _GLFWcursorMir; } _GLFWcursorMir;

View File

@ -1,7 +1,7 @@
//======================================================================== //========================================================================
// GLFW 3.1 Mir - www.glfw.org // GLFW 3.1 Mir - www.glfw.org
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Copyright (c) 2014 Brandon Schaefer <brandon.schaefer@canonical.com> // Copyright (c) 2014-2015 Brandon Schaefer <brandon.schaefer@canonical.com>
// //
// This software is provided 'as-is', without any express or implied // This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages // warranty. In no event will the authors be held liable for any damages
@ -34,13 +34,13 @@
typedef struct EventNode typedef struct EventNode
{ {
TAILQ_ENTRY(EventNode) entries; TAILQ_ENTRY(EventNode) entries;
MirEvent* event; const MirEvent* event;
_GLFWwindow* window; _GLFWwindow* window;
} EventNode; } EventNode;
static void deleteNode(EventQueue* queue, EventNode* node) static void deleteNode(EventQueue* queue, EventNode* node)
{ {
free(node->event); mir_event_unref(node->event);
free(node); free(node);
} }
@ -49,17 +49,19 @@ static int emptyEventQueue(EventQueue* queue)
return queue->head.tqh_first == NULL ? GL_TRUE : GL_FALSE; return queue->head.tqh_first == NULL ? GL_TRUE : GL_FALSE;
} }
static EventNode* newEventNode(MirEvent const* event, _GLFWwindow* context) // 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)
{ {
EventNode* new_node = calloc(1, sizeof(EventNode)); EventNode* new_node = calloc(1, sizeof(EventNode));
new_node->event = calloc(1, sizeof(MirEvent)); new_node->event = mir_event_ref(event);
new_node->window = context; new_node->window = context;
memcpy(new_node->event, event, sizeof(MirEvent));
return new_node; return new_node;
} }
static void enqueueEvent(MirEvent const* event, _GLFWwindow* context) static void enqueueEvent(const MirEvent* event, _GLFWwindow* context)
{ {
pthread_mutex_lock(&_glfw.mir.event_mutex); pthread_mutex_lock(&_glfw.mir.event_mutex);
@ -87,6 +89,9 @@ static EventNode* dequeueEvent(EventQueue* queue)
return node; return node;
} }
/* FIXME Soon to be changed upstream mir! So we can use an egl config to figure out
the best pixel format!
*/
static MirPixelFormat findValidPixelFormat(void) static MirPixelFormat findValidPixelFormat(void)
{ {
unsigned int i, validFormats, mirPixelFormats = 32; unsigned int i, validFormats, mirPixelFormats = 32;
@ -113,13 +118,13 @@ static int mirModToGLFWMod(uint32_t mods)
{ {
int publicMods = 0x0; int publicMods = 0x0;
if (mods & mir_key_modifier_alt) if (mods & mir_input_event_modifier_alt)
publicMods |= GLFW_MOD_ALT; publicMods |= GLFW_MOD_ALT;
else if (mods & mir_key_modifier_shift) else if (mods & mir_input_event_modifier_shift)
publicMods |= GLFW_MOD_SHIFT; publicMods |= GLFW_MOD_SHIFT;
else if (mods & mir_key_modifier_ctrl) else if (mods & mir_input_event_modifier_ctrl)
publicMods |= GLFW_MOD_CONTROL; publicMods |= GLFW_MOD_CONTROL;
else if (mods & mir_key_modifier_meta) else if (mods & mir_input_event_modifier_meta)
publicMods |= GLFW_MOD_SUPER; publicMods |= GLFW_MOD_SUPER;
return publicMods; return publicMods;
@ -250,97 +255,93 @@ static int toGLFWKeyCode(uint32_t key)
} }
} }
static void handleKeyEvent(const MirKeyEvent key, _GLFWwindow* window) static void handleKeyEvent(const MirKeyboardEvent* key_event, _GLFWwindow* window)
{ {
const int pressed = key.action == mir_key_action_up ? GLFW_RELEASE : GLFW_PRESS; const int action = mir_keyboard_event_action (key_event);
const int mods = mirModToGLFWMod(key.modifiers); const int scan_code = mir_keyboard_event_scan_code(key_event);
const long text = _glfwKeySym2Unicode(key.key_code); const int key_code = mir_keyboard_event_key_code (key_event);
const int modifiers = mir_keyboard_event_modifiers(key_event);
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)); const int plain = !(mods & (GLFW_MOD_CONTROL | GLFW_MOD_ALT));
_glfwInputKey(window, toGLFWKeyCode(key.scan_code), key.scan_code, pressed, mods); _glfwInputKey(window, toGLFWKeyCode(scan_code), scan_code, pressed, mods);
if (text != -1) if (text != -1)
_glfwInputChar(window, text, mods, plain); _glfwInputChar(window, text, mods, plain);
} }
static void handleMouseButton(_GLFWwindow* window, static void handlePointerButton(_GLFWwindow* window,
int pressed, int mods, MirMotionButton button) int pressed,
const MirPointerEvent* pointer_event)
{ {
static int lastButton; MirPointerButton button = mir_pointer_event_buttons (pointer_event);
int publicButton; int mods = mir_pointer_event_modifiers(pointer_event);
const int publicMods = mirModToGLFWMod(mods); const int publicMods = mirModToGLFWMod(mods);
int publicButton;
switch (button) switch (button)
{ {
case mir_motion_button_primary: case mir_pointer_button_primary:
publicButton = GLFW_MOUSE_BUTTON_LEFT; publicButton = GLFW_MOUSE_BUTTON_LEFT;
break; break;
case mir_motion_button_secondary: case mir_pointer_button_secondary:
publicButton = GLFW_MOUSE_BUTTON_RIGHT; publicButton = GLFW_MOUSE_BUTTON_RIGHT;
break; break;
case mir_motion_button_tertiary: case mir_pointer_button_tertiary:
publicButton = GLFW_MOUSE_BUTTON_MIDDLE; publicButton = GLFW_MOUSE_BUTTON_MIDDLE;
break; break;
case mir_motion_button_forward: case mir_pointer_button_forward:
// FIXME What is the forward button? // FIXME What is the forward button?
publicButton = GLFW_MOUSE_BUTTON_4; publicButton = GLFW_MOUSE_BUTTON_4;
break; break;
case mir_motion_button_back: case mir_pointer_button_back:
// FIXME What is the back button? // FIXME What is the back button?
publicButton = GLFW_MOUSE_BUTTON_5; publicButton = GLFW_MOUSE_BUTTON_5;
break; break;
default: default:
publicButton = lastButton;
break; break;
} }
lastButton = publicButton;
_glfwInputMouseClick(window, publicButton, pressed, publicMods); _glfwInputMouseClick(window, publicButton, pressed, publicMods);
} }
static void handleMouseMotion(_GLFWwindow* window, int x, int y) static void handlePointerMotion(_GLFWwindow* window,
const MirPointerEvent* pointer_event)
{ {
_glfwInputCursorMotion(window, x, y); int current_x = window->cursorPosX;
} int current_y = window->cursorPosY;
int x = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_x);
int y = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_y);
int dx = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_hscroll);
int dy = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_vscroll);
static void handleMouseScroll(_GLFWwindow* window, int dx, int dy) if (current_x != x || current_y != y)
{ _glfwInputCursorMotion(window, x, y);
if (dx != 0 || dy != 0)
_glfwInputScroll(window, dx, dy); _glfwInputScroll(window, dx, dy);
} }
static void handleMouseEvent(const MirMotionEvent motion, static void handlePointerEvent(const MirPointerEvent* pointer_event,
int cord_index,
_GLFWwindow* window) _GLFWwindow* window)
{ {
switch (motion.action) int action = mir_pointer_event_action(pointer_event);
switch (action)
{ {
case mir_motion_action_down: case mir_pointer_action_button_down:
case mir_motion_action_pointer_down: handlePointerButton(window, GLFW_PRESS, pointer_event);
handleMouseButton(window, GLFW_PRESS,
motion.modifiers, motion.button_state);
break; break;
case mir_motion_action_up: case mir_pointer_action_button_up:
case mir_motion_action_pointer_up: handlePointerButton(window, GLFW_RELEASE, pointer_event);
handleMouseButton(window, GLFW_RELEASE,
motion.modifiers, motion.button_state);
break; break;
case mir_motion_action_hover_move: case mir_pointer_action_motion:
case mir_motion_action_move: handlePointerMotion(window, pointer_event);
handleMouseMotion(window,
motion.pointer_coordinates[cord_index].x,
motion.pointer_coordinates[cord_index].y);
break; break;
case mir_motion_action_outside: case mir_pointer_action_enter:
break; case mir_pointer_action_leave:
case mir_motion_action_scroll:
handleMouseScroll(window,
motion.pointer_coordinates[cord_index].hscroll,
motion.pointer_coordinates[cord_index].vscroll);
break;
case mir_motion_action_cancel:
case mir_motion_action_hover_enter:
case mir_motion_action_hover_exit:
break; break;
default: default:
break; break;
@ -348,61 +349,66 @@ static void handleMouseEvent(const MirMotionEvent motion,
} }
} }
static void handleMotionEvent(const MirMotionEvent motion, _GLFWwindow* window) static void handleInput(const MirInputEvent* input_event, _GLFWwindow* window)
{ {
int i; int type = mir_input_event_get_type(input_event);
for (i = 0; i < motion.pointer_count; i++)
handleMouseEvent(motion, i, window);
}
static void handleInput(MirEvent const* event, _GLFWwindow* window) switch (type)
{
switch (event->type)
{ {
case mir_event_type_key: case mir_input_event_type_key:
handleKeyEvent(event->key, window); handleKeyEvent(mir_input_event_get_keyboard_event(input_event), window);
break; break;
case mir_event_type_motion: case mir_input_event_type_pointer:
handleMotionEvent(event->motion, window); handlePointerEvent(mir_input_event_get_pointer_event(input_event), window);
break; break;
default: default:
break; break;
} }
} }
static void addNewEvent(MirSurface* surface, MirEvent const* event, void* context) static void handleEvent(const MirEvent* event, _GLFWwindow* window)
{
int type = mir_event_get_type(event);
switch (type)
{
case mir_event_type_input:
handleInput(mir_event_get_input_event(event), window);
break;
default:
break;
}
}
static void addNewEvent(MirSurface* surface, const MirEvent* event, void* context)
{ {
enqueueEvent(event, context); enqueueEvent(event, context);
} }
static int createSurface(_GLFWwindow* window) static int createSurface(_GLFWwindow* window)
{ {
MirSurfaceParameters params = MirSurfaceSpec* spec;
{ MirBufferUsage buffer_usage = mir_buffer_usage_hardware;
.name = "MirSurface", MirPixelFormat pixel_format = findValidPixelFormat();
.width = window->mir.width,
.height = window->mir.height,
.pixel_format = mir_pixel_format_invalid,
.buffer_usage = mir_buffer_usage_hardware,
.output_id = mir_display_output_id_invalid
};
MirEventDelegate delegate = if (pixel_format == mir_pixel_format_invalid)
{
addNewEvent,
window
};
params.pixel_format = findValidPixelFormat();
if (params.pixel_format == mir_pixel_format_invalid)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unable to find a correct pixel format"); "Mir: Unable to find a correct pixel format");
return GL_FALSE; return GL_FALSE;
} }
window->mir.surface = spec = mir_connection_create_spec_for_normal_surface(_glfw.mir.connection,
mir_connection_create_surface_sync(_glfw.mir.connection, &params); window->mir.width,
window->mir.height,
pixel_format);
mir_surface_spec_set_buffer_usage(spec, buffer_usage);
mir_surface_spec_set_name(spec, "MirSurface");
window->mir.surface = mir_surface_create_sync(spec);
mir_surface_spec_release(spec);
if (!mir_surface_is_valid(window->mir.surface)) if (!mir_surface_is_valid(window->mir.surface))
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
@ -412,7 +418,7 @@ static int createSurface(_GLFWwindow* window)
return GL_FALSE; return GL_FALSE;
} }
mir_surface_set_event_handler(window->mir.surface, &delegate); mir_surface_set_event_handler(window->mir.surface, addNewEvent, window);
return GL_TRUE; return GL_TRUE;
} }
@ -482,7 +488,8 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
if (!createSurface(window)) if (!createSurface(window))
return GL_FALSE; return GL_FALSE;
window->mir.window = mir_surface_get_egl_native_window(window->mir.surface); window->mir.window = mir_buffer_stream_get_egl_native_window(
mir_surface_get_buffer_stream(window->mir.surface));
return GL_TRUE; return GL_TRUE;
} }
@ -500,8 +507,26 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, MirSurfaceSpec* spec;
"Mir: Unsupported function %s", __PRETTY_FUNCTION__); const char* e_title = title ? title : "";
spec = mir_connection_create_spec_for_changes(_glfw.mir.connection);
mir_surface_spec_set_name(spec, e_title);
mir_surface_apply_spec(window->mir.surface, spec);
mir_surface_spec_release(spec);
}
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
{
MirSurfaceSpec* spec;
spec = mir_connection_create_spec_for_changes(_glfw.mir.connection);
mir_surface_spec_set_width (spec, width);
mir_surface_spec_set_height(spec, height);
mir_surface_apply_spec(window->mir.surface, spec);
mir_surface_spec_release(spec);
} }
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos) void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos)
@ -524,12 +549,6 @@ void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos)
"Mir: Unsupported function %s", __PRETTY_FUNCTION__); "Mir: Unsupported function %s", __PRETTY_FUNCTION__);
} }
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
}
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height) void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
{ {
if (width) if (width)
@ -550,14 +569,24 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
void _glfwPlatformHideWindow(_GLFWwindow* window) void _glfwPlatformHideWindow(_GLFWwindow* window)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, MirSurfaceSpec* spec;
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
spec = mir_connection_create_spec_for_changes(_glfw.mir.connection);
mir_surface_spec_set_state(spec, mir_surface_state_hidden);
mir_surface_apply_spec(window->mir.surface, spec);
mir_surface_spec_release(spec);
} }
void _glfwPlatformShowWindow(_GLFWwindow* window) void _glfwPlatformShowWindow(_GLFWwindow* window)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, MirSurfaceSpec* spec;
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
spec = mir_connection_create_spec_for_changes(_glfw.mir.connection);
mir_surface_spec_set_state(spec, mir_surface_state_restored);
mir_surface_apply_spec(window->mir.surface, spec);
mir_surface_spec_release(spec);
} }
void _glfwPlatformUnhideWindow(_GLFWwindow* window) void _glfwPlatformUnhideWindow(_GLFWwindow* window)
@ -582,9 +611,7 @@ int _glfwPlatformWindowIconified(_GLFWwindow* window)
int _glfwPlatformWindowVisible(_GLFWwindow* window) int _glfwPlatformWindowVisible(_GLFWwindow* window)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, return mir_surface_get_visibility(window->mir.surface) == mir_surface_visibility_exposed;
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
return GL_FALSE;
} }
void _glfwPlatformPollEvents(void) void _glfwPlatformPollEvents(void)
@ -593,7 +620,7 @@ void _glfwPlatformPollEvents(void)
while ((node = dequeueEvent(_glfw.mir.event_queue))) while ((node = dequeueEvent(_glfw.mir.event_queue)))
{ {
handleInput(node->event, node->window); handleEvent(node->event, node->window);
deleteNode(_glfw.mir.event_queue, node); deleteNode(_glfw.mir.event_queue, node);
} }
} }
@ -622,34 +649,122 @@ void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* heigh
*height = window->mir.height; *height = window->mir.height;
} }
// FIXME implement
int _glfwPlatformCreateCursor(_GLFWcursor* cursor, int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
const GLFWimage* image, const GLFWimage* image,
int xhot, int yhot) int xhot, int yhot)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, MirBufferStream* stream;
"Mir: Unsupported function %s", __PRETTY_FUNCTION__); MirPixelFormat pixel_format = findValidPixelFormat();
int i_w = image->width;
int i_h = image->height;
if (pixel_format == mir_pixel_format_invalid)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unable to find a correct pixel format");
return GL_FALSE; return GL_FALSE;
}
stream = mir_connection_create_buffer_stream_sync(_glfw.mir.connection,
i_w, i_h,
pixel_format,
mir_buffer_usage_software);
cursor->mir.conf = mir_cursor_configuration_from_buffer_stream(stream, xhot, yhot);
char* dest;
unsigned char *pixels;
int i, r_stride, bytes_per_pixel, bytes_per_row;
MirGraphicsRegion region;
mir_buffer_stream_get_graphics_region(stream, &region);
// FIXME Figure this out based on the current_pf
bytes_per_pixel = 4;
bytes_per_row = bytes_per_pixel * i_w;
dest = region.vaddr;
pixels = image->pixels;
r_stride = region.stride;
for (i = 0; i < i_h; i++)
{
memcpy(dest, pixels, bytes_per_row);
dest += r_stride;
pixels += r_stride;
}
cursor->mir.custom_cursor = stream;
return GL_TRUE;
}
char const* getSystemCursorName(int shape)
{
switch (shape)
{
case GLFW_ARROW_CURSOR:
return mir_arrow_cursor_name;
case GLFW_IBEAM_CURSOR:
return mir_caret_cursor_name;
case GLFW_CROSSHAIR_CURSOR:
return mir_crosshair_cursor_name;
case GLFW_HAND_CURSOR:
return mir_open_hand_cursor_name;
case GLFW_HRESIZE_CURSOR:
return mir_horizontal_resize_cursor_name;
case GLFW_VRESIZE_CURSOR:
return mir_vertical_resize_cursor_name;
}
return NULL;
} }
int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape) int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, char const* cursor_name = getSystemCursorName(shape);
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
if (cursor_name)
{
cursor->mir.conf = mir_cursor_configuration_from_name(cursor_name);
cursor->mir.custom_cursor = NULL;
return GL_TRUE;
}
return GL_FALSE; return GL_FALSE;
} }
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor) void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, if (cursor->mir.conf)
"Mir: Unsupported function %s", __PRETTY_FUNCTION__); mir_cursor_configuration_destroy(cursor->mir.conf);
if (cursor->mir.custom_cursor)
mir_buffer_stream_release_sync(cursor->mir.custom_cursor);
} }
void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, if (cursor && cursor->mir.conf)
"Mir: Unsupported function %s", __PRETTY_FUNCTION__); {
mir_wait_for(mir_surface_configure_cursor(window->mir.surface, cursor->mir.conf));
if (cursor->mir.custom_cursor)
{
/* FIXME Bug https://bugs.launchpad.net/mir/+bug/1477285
Requires a triple buffer swap to get the cursor buffer on top! (since mir is tripled buffered)
*/
mir_buffer_stream_swap_buffers_sync(cursor->mir.custom_cursor);
mir_buffer_stream_swap_buffers_sync(cursor->mir.custom_cursor);
mir_buffer_stream_swap_buffers_sync(cursor->mir.custom_cursor);
}
}
else
{
mir_wait_for(mir_surface_configure_cursor(window->mir.surface, _glfw.mir.default_conf));
}
} }
void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos) void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos)