* Get ready for mir 1.0 by moving away from deprecations.

This commit is contained in:
Brandon Schaefer 2017-03-28 19:03:29 -07:00
parent 7a8516d296
commit 0cc231d23b
5 changed files with 144 additions and 153 deletions

View File

@ -394,9 +394,9 @@ GLFWAPI MirConnection* glfwGetMirDisplay(void);
*/ */
GLFWAPI int glfwGetMirMonitor(GLFWmonitor* monitor); GLFWAPI int glfwGetMirMonitor(GLFWmonitor* monitor);
/*! @brief Returns the `MirSurface*` of the specified window. /*! @brief Returns the `MirWindow*` of the specified window.
* *
* @return The `MirSurface*` of the specified window, or `NULL` if an * @return The `MirWindow*` of the specified window, or `NULL` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
@ -406,7 +406,7 @@ GLFWAPI int glfwGetMirMonitor(GLFWmonitor* monitor);
* *
* @ingroup native * @ingroup native
*/ */
GLFWAPI MirSurface* glfwGetMirWindow(GLFWwindow* window); GLFWAPI MirWindow* glfwGetMirWindow(GLFWwindow* window);
#endif #endif
#if defined(GLFW_EXPOSE_NATIVE_EGL) #if defined(GLFW_EXPOSE_NATIVE_EGL)

View File

@ -1,7 +1,7 @@
//======================================================================== //========================================================================
// GLFW 3.3 Mir - www.glfw.org // GLFW 3.3 Mir - www.glfw.org
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Copyright (c) 2014-2015 Brandon Schaefer <brandon.schaefer@canonical.com> // Copyright (c) 2014-2017 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
@ -198,10 +198,6 @@ int _glfwPlatformInit(void)
_glfwInitTimerPOSIX(); _glfwInitTimerPOSIX();
// Need the default conf for when we set a NULL cursor
_glfw.mir.defaultConf = mir_cursor_configuration_from_name(mir_default_cursor_name);
_glfw.mir.disabledConf = mir_cursor_configuration_from_name(mir_disabled_cursor_name);
_glfw.mir.eventQueue = calloc(1, sizeof(EventQueue)); _glfw.mir.eventQueue = calloc(1, sizeof(EventQueue));
_glfwInitEventQueueMir(_glfw.mir.eventQueue); _glfwInitEventQueueMir(_glfw.mir.eventQueue);

View File

@ -1,7 +1,7 @@
//======================================================================== //========================================================================
// GLFW 3.3 Mir - www.glfw.org // GLFW 3.3 Mir - www.glfw.org
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Copyright (c) 2014-2015 Brandon Schaefer <brandon.schaefer@canonical.com> // Copyright (c) 2014-2017 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

View File

@ -1,7 +1,7 @@
//======================================================================== //========================================================================
// GLFW 3.3 Mir - www.glfw.org // GLFW 3.3 Mir - www.glfw.org
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Copyright (c) 2014-2015 Brandon Schaefer <brandon.schaefer@canonical.com> // Copyright (c) 2014-2017 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
@ -33,18 +33,18 @@
#include <mir_toolkit/mir_client_library.h> #include <mir_toolkit/mir_client_library.h>
typedef VkFlags VkMirSurfaceCreateFlagsKHR; typedef VkFlags VkMirWindowCreateFlagsKHR;
typedef struct VkMirSurfaceCreateInfoKHR typedef struct VkMirWindowCreateInfoKHR
{ {
VkStructureType sType; VkStructureType sType;
const void* pNext; const void* pNext;
VkMirSurfaceCreateFlagsKHR flags; VkMirWindowCreateFlagsKHR flags;
MirConnection* connection; MirConnection* connection;
MirSurface* mirSurface; MirWindow* mirWindow;
} VkMirSurfaceCreateInfoKHR; } VkMirWindowCreateInfoKHR;
typedef VkResult (APIENTRY *PFN_vkCreateMirSurfaceKHR)(VkInstance,const VkMirSurfaceCreateInfoKHR*,const VkAllocationCallbacks*,VkSurfaceKHR*); typedef VkResult (APIENTRY *PFN_vkCreateMirWindowKHR)(VkInstance,const VkMirWindowCreateInfoKHR*,const VkAllocationCallbacks*,VkSurfaceKHR*);
typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceMirPresentationSupportKHR)(VkPhysicalDevice,uint32_t,MirConnection*); typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceMirPresentationSupportKHR)(VkPhysicalDevice,uint32_t,MirConnection*);
#include "posix_tls.h" #include "posix_tls.h"
@ -52,12 +52,13 @@ typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceMirPresentationSupportKHR)(Vk
#include "linux_joystick.h" #include "linux_joystick.h"
#include "xkb_unicode.h" #include "xkb_unicode.h"
#include "egl_context.h" #include "egl_context.h"
#include "osmesa_context.h"
#define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL)
#define _glfw_dlclose(handle) dlclose(handle) #define _glfw_dlclose(handle) dlclose(handle)
#define _glfw_dlsym(handle, name) dlsym(handle, name) #define _glfw_dlsym(handle, name) dlsym(handle, name)
#define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->mir.window) #define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->mir.nativeWindow)
#define _GLFW_EGL_NATIVE_DISPLAY ((EGLNativeDisplayType) _glfw.mir.display) #define _GLFW_EGL_NATIVE_DISPLAY ((EGLNativeDisplayType) _glfw.mir.display)
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowMir mir #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowMir mir
@ -80,10 +81,10 @@ typedef struct EventQueue
// //
typedef struct _GLFWwindowMir typedef struct _GLFWwindowMir
{ {
MirSurface* surface; MirWindow* window;
int width; int width;
int height; int height;
MirEGLNativeWindowType window; MirEGLNativeWindowType nativeWindow;
_GLFWcursor* currentCursor; _GLFWcursor* currentCursor;
} _GLFWwindowMir; } _GLFWwindowMir;
@ -105,18 +106,16 @@ typedef struct _GLFWlibraryMir
{ {
MirConnection* connection; MirConnection* connection;
MirEGLNativeDisplayType display; MirEGLNativeDisplayType display;
MirCursorConfiguration* defaultConf;
MirCursorConfiguration* disabledConf;
EventQueue* eventQueue; EventQueue* eventQueue;
short int keycodes[256]; short int keycodes[256];
short int scancodes[GLFW_KEY_LAST + 1]; short int scancodes[GLFW_KEY_LAST + 1];
pthread_mutex_t eventMutex; pthread_mutex_t eventMutex;
pthread_cond_t eventCond; pthread_cond_t eventCond;
// The window whose disabled cursor mode is active // The window whose disabled cursor mode is active
_GLFWwindow* disabledCursorWindow; _GLFWwindow* disabledCursorWindow;
} _GLFWlibraryMir; } _GLFWlibraryMir;
@ -127,6 +126,7 @@ typedef struct _GLFWcursorMir
{ {
MirCursorConfiguration* conf; MirCursorConfiguration* conf;
MirBufferStream* customCursor; MirBufferStream* customCursor;
char const* cursorName; // only needed for system cursors
} _GLFWcursorMir; } _GLFWcursorMir;

View File

@ -1,7 +1,7 @@
//======================================================================== //========================================================================
// GLFW 3.3 Mir - www.glfw.org // GLFW 3.3 Mir - www.glfw.org
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Copyright (c) 2014-2015 Brandon Schaefer <brandon.schaefer@canonical.com> // Copyright (c) 2014-2017 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,9 +89,6 @@ 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;
@ -283,14 +280,14 @@ static void handleEvent(const MirEvent* event, _GLFWwindow* window)
} }
} }
static void addNewEvent(MirSurface* surface, const MirEvent* event, void* context) static void addNewEvent(MirWindow* window, const MirEvent* event, void* context)
{ {
enqueueEvent(event, context); enqueueEvent(event, context);
} }
static GLFWbool createSurface(_GLFWwindow* window) static GLFWbool createWindow(_GLFWwindow* window)
{ {
MirSurfaceSpec* spec; MirWindowSpec* spec;
MirBufferUsage buffer_usage = mir_buffer_usage_hardware; MirBufferUsage buffer_usage = mir_buffer_usage_hardware;
MirPixelFormat pixel_format = findValidPixelFormat(); MirPixelFormat pixel_format = findValidPixelFormat();
@ -301,40 +298,39 @@ static GLFWbool createSurface(_GLFWwindow* window)
return GLFW_FALSE; return GLFW_FALSE;
} }
spec = mir_connection_create_spec_for_normal_surface(_glfw.mir.connection, spec = mir_create_normal_window_spec(_glfw.mir.connection,
window->mir.width, window->mir.width,
window->mir.height, window->mir.height);
pixel_format);
mir_surface_spec_set_buffer_usage(spec, buffer_usage); mir_window_spec_set_pixel_format(spec, pixel_format);
mir_surface_spec_set_name(spec, "MirSurface"); mir_window_spec_set_buffer_usage(spec, buffer_usage);
window->mir.surface = mir_surface_create_sync(spec); window->mir.window = mir_create_window_sync(spec);
mir_surface_spec_release(spec); mir_window_spec_release(spec);
if (!mir_surface_is_valid(window->mir.surface)) if (!mir_window_is_valid(window->mir.window))
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unable to create surface: %s", "Mir: Unable to create window: %s",
mir_surface_get_error_message(window->mir.surface)); mir_window_get_error_message(window->mir.window));
return GLFW_FALSE; return GLFW_FALSE;
} }
mir_surface_set_event_handler(window->mir.surface, addNewEvent, window); mir_window_set_event_handler(window->mir.window, addNewEvent, window);
return GLFW_TRUE; return GLFW_TRUE;
} }
static void setSurfaceConfinement(_GLFWwindow* window, MirPointerConfinementState state) static void setWindowConfinement(_GLFWwindow* window, MirPointerConfinementState state)
{ {
MirSurfaceSpec* spec; MirWindowSpec* spec;
spec = mir_connection_create_spec_for_changes(_glfw.mir.connection); spec = mir_create_window_spec(_glfw.mir.connection);
mir_surface_spec_set_pointer_confinement(spec, state); mir_window_spec_set_pointer_confinement(spec, state);
mir_surface_apply_spec(window->mir.surface, spec); mir_window_apply_spec(window->mir.window, spec);
mir_surface_spec_release(spec); mir_window_spec_release(spec);
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -381,12 +377,12 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
GLFWvidmode mode; GLFWvidmode mode;
_glfwPlatformGetVideoMode(window->monitor, &mode); _glfwPlatformGetVideoMode(window->monitor, &mode);
mir_surface_set_state(window->mir.surface, mir_surface_state_fullscreen); mir_window_set_state(window->mir.window, mir_window_state_fullscreen);
if (wndconfig->width > mode.width || wndconfig->height > mode.height) if (wndconfig->width > mode.width || wndconfig->height > mode.height)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Requested surface size too large: %ix%i", "Mir: Requested window size too large: %ix%i",
wndconfig->width, wndconfig->height); wndconfig->width, wndconfig->height);
return GLFW_FALSE; return GLFW_FALSE;
@ -397,11 +393,11 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
window->mir.height = wndconfig->height; window->mir.height = wndconfig->height;
window->mir.currentCursor = NULL; window->mir.currentCursor = NULL;
if (!createSurface(window)) if (!createWindow(window))
return GLFW_FALSE; return GLFW_FALSE;
window->mir.window = mir_buffer_stream_get_egl_native_window( window->mir.nativeWindow = mir_buffer_stream_get_egl_native_window(
mir_surface_get_buffer_stream(window->mir.surface)); mir_window_get_buffer_stream(window->mir.window));
if (ctxconfig->client != GLFW_NO_API) if (ctxconfig->client != GLFW_NO_API)
{ {
@ -419,10 +415,10 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
if (_glfw.mir.disabledCursorWindow == window) if (_glfw.mir.disabledCursorWindow == window)
_glfw.mir.disabledCursorWindow = NULL; _glfw.mir.disabledCursorWindow = NULL;
if (mir_surface_is_valid(window->mir.surface)) if (mir_window_is_valid(window->mir.window))
{ {
mir_surface_release_sync(window->mir.surface); mir_window_release_sync(window->mir.window);
window->mir.surface = NULL; window->mir.window= NULL;
} }
if (window->context.destroy) if (window->context.destroy)
@ -431,14 +427,14 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
{ {
MirSurfaceSpec* spec; MirWindowSpec* spec;
const char* e_title = title ? title : ""; const char* e_title = title ? title : "";
spec = mir_connection_create_spec_for_changes(_glfw.mir.connection); spec = mir_create_window_spec(_glfw.mir.connection);
mir_surface_spec_set_name(spec, e_title); mir_window_spec_set_name(spec, e_title);
mir_surface_apply_spec(window->mir.surface, spec); mir_window_apply_spec(window->mir.window, spec);
mir_surface_spec_release(spec); mir_window_spec_release(spec);
} }
void _glfwPlatformSetWindowIcon(_GLFWwindow* window, void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
@ -450,22 +446,30 @@ void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
{ {
MirSurfaceSpec* spec; MirWindowSpec* spec;
spec = mir_connection_create_spec_for_changes(_glfw.mir.connection); spec = mir_create_window_spec(_glfw.mir.connection);
mir_surface_spec_set_width (spec, width); mir_window_spec_set_width (spec, width);
mir_surface_spec_set_height(spec, height); mir_window_spec_set_height(spec, height);
mir_surface_apply_spec(window->mir.surface, spec); mir_window_apply_spec(window->mir.window, spec);
mir_surface_spec_release(spec); mir_window_spec_release(spec);
} }
void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window, void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window,
int minwidth, int minheight, int minwidth, int minheight,
int maxwidth, int maxheight) int maxwidth, int maxheight)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, MirWindowSpec* spec;
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
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);
} }
void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom) void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom)
@ -504,57 +508,57 @@ void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
void _glfwPlatformIconifyWindow(_GLFWwindow* window) void _glfwPlatformIconifyWindow(_GLFWwindow* window)
{ {
MirSurfaceSpec* spec; MirWindowSpec* spec;
spec = mir_connection_create_spec_for_changes(_glfw.mir.connection); spec = mir_create_window_spec(_glfw.mir.connection);
mir_surface_spec_set_state(spec, mir_surface_state_minimized); mir_window_spec_set_state(spec, mir_window_state_minimized);
mir_surface_apply_spec(window->mir.surface, spec); mir_window_apply_spec(window->mir.window, spec);
mir_surface_spec_release(spec); mir_window_spec_release(spec);
} }
void _glfwPlatformRestoreWindow(_GLFWwindow* window) void _glfwPlatformRestoreWindow(_GLFWwindow* window)
{ {
MirSurfaceSpec* spec; MirWindowSpec* spec;
spec = mir_connection_create_spec_for_changes(_glfw.mir.connection); spec = mir_create_window_spec(_glfw.mir.connection);
mir_surface_spec_set_state(spec, mir_surface_state_restored); mir_window_spec_set_state(spec, mir_window_state_restored);
mir_surface_apply_spec(window->mir.surface, spec); mir_window_apply_spec(window->mir.window, spec);
mir_surface_spec_release(spec); mir_window_spec_release(spec);
} }
void _glfwPlatformMaximizeWindow(_GLFWwindow* window) void _glfwPlatformMaximizeWindow(_GLFWwindow* window)
{ {
MirSurfaceSpec* spec; MirWindowSpec* spec;
spec = mir_connection_create_spec_for_changes(_glfw.mir.connection); spec = mir_create_window_spec(_glfw.mir.connection);
mir_surface_spec_set_state(spec, mir_surface_state_maximized); mir_window_spec_set_state(spec, mir_window_state_maximized);
mir_surface_apply_spec(window->mir.surface, spec); mir_window_apply_spec(window->mir.window, spec);
mir_surface_spec_release(spec); mir_window_spec_release(spec);
} }
void _glfwPlatformHideWindow(_GLFWwindow* window) void _glfwPlatformHideWindow(_GLFWwindow* window)
{ {
MirSurfaceSpec* spec; MirWindowSpec* spec;
spec = mir_connection_create_spec_for_changes(_glfw.mir.connection); spec = mir_create_window_spec(_glfw.mir.connection);
mir_surface_spec_set_state(spec, mir_surface_state_hidden); mir_window_spec_set_state(spec, mir_window_state_hidden);
mir_surface_apply_spec(window->mir.surface, spec); mir_window_apply_spec(window->mir.window, spec);
mir_surface_spec_release(spec); mir_window_spec_release(spec);
} }
void _glfwPlatformShowWindow(_GLFWwindow* window) void _glfwPlatformShowWindow(_GLFWwindow* window)
{ {
MirSurfaceSpec* spec; MirWindowSpec* spec;
spec = mir_connection_create_spec_for_changes(_glfw.mir.connection); spec = mir_create_window_spec(_glfw.mir.connection);
mir_surface_spec_set_state(spec, mir_surface_state_restored); mir_window_spec_set_state(spec, mir_window_state_restored);
mir_surface_apply_spec(window->mir.surface, spec); mir_window_apply_spec(window->mir.window, spec);
mir_surface_spec_release(spec); mir_window_spec_release(spec);
} }
void _glfwPlatformFocusWindow(_GLFWwindow* window) void _glfwPlatformFocusWindow(_GLFWwindow* window)
@ -575,7 +579,7 @@ void _glfwPlatformSetWindowMonitor(_GLFWwindow* window,
int _glfwPlatformWindowFocused(_GLFWwindow* window) int _glfwPlatformWindowFocused(_GLFWwindow* window)
{ {
return mir_surface_get_focus(window->mir.surface) == mir_surface_focused; return mir_window_get_focus_state(window->mir.window) == mir_window_focus_state_focused;
} }
int _glfwPlatformWindowIconified(_GLFWwindow* window) int _glfwPlatformWindowIconified(_GLFWwindow* window)
@ -587,12 +591,12 @@ int _glfwPlatformWindowIconified(_GLFWwindow* window)
int _glfwPlatformWindowVisible(_GLFWwindow* window) int _glfwPlatformWindowVisible(_GLFWwindow* window)
{ {
return mir_surface_get_visibility(window->mir.surface) == mir_surface_visibility_exposed; return mir_window_get_visibility(window->mir.window) == mir_window_visibility_exposed;
} }
int _glfwPlatformWindowMaximized(_GLFWwindow* window) int _glfwPlatformWindowMaximized(_GLFWwindow* window)
{ {
return mir_surface_get_state(window->mir.surface) == mir_surface_state_maximized; return mir_window_get_state(window->mir.window) == mir_window_state_maximized;
} }
void _glfwPlatformSetWindowResizable(_GLFWwindow* window, GLFWbool enabled) void _glfwPlatformSetWindowResizable(_GLFWwindow* window, GLFWbool enabled)
@ -628,7 +632,7 @@ void _glfwPlatformWaitEvents(void)
{ {
pthread_mutex_lock(&_glfw.mir.eventMutex); pthread_mutex_lock(&_glfw.mir.eventMutex);
if (emptyEventQueue(_glfw.mir.eventQueue)) while (emptyEventQueue(_glfw.mir.eventQueue))
pthread_cond_wait(&_glfw.mir.eventCond, &_glfw.mir.eventMutex); pthread_cond_wait(&_glfw.mir.eventCond, &_glfw.mir.eventMutex);
pthread_mutex_unlock(&_glfw.mir.eventMutex); pthread_mutex_unlock(&_glfw.mir.eventMutex);
@ -671,54 +675,40 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
int xhot, int yhot) int xhot, int yhot)
{ {
MirBufferStream* stream; MirBufferStream* stream;
MirPixelFormat pixel_format = findValidPixelFormat();
int i_w = image->width; int i_w = image->width;
int i_h = image->height; 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 GLFW_FALSE;
}
stream = mir_connection_create_buffer_stream_sync(_glfw.mir.connection, stream = mir_connection_create_buffer_stream_sync(_glfw.mir.connection,
i_w, i_h, i_w, i_h,
pixel_format, mir_pixel_format_argb_8888,
mir_buffer_usage_software); mir_buffer_usage_software);
cursor->mir.conf = mir_cursor_configuration_from_buffer_stream(stream, xhot, yhot); 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; MirGraphicsRegion region;
mir_buffer_stream_get_graphics_region(stream, &region); mir_buffer_stream_get_graphics_region(stream, &region);
// FIXME Figure this out based on the current_pf unsigned char* pixels = image->pixels;
bytes_per_pixel = 4; char* dest = region.vaddr;
bytes_per_row = bytes_per_pixel * i_w; int i;
dest = region.vaddr; for (i = 0; i < i_w * i_h; i++, pixels += 4)
pixels = image->pixels;
r_stride = region.stride;
for (i = 0; i < i_h; i++)
{ {
memcpy(dest, pixels, bytes_per_row); unsigned int alpha = pixels[3];
dest += r_stride; *dest++ = (char)(pixels[2] * alpha / 255);
pixels += r_stride; *dest++ = (char)(pixels[1] * alpha / 255);
*dest++ = (char)(pixels[0] * alpha / 255);
*dest++ = (char)alpha;
} }
mir_buffer_stream_swap_buffers_sync(stream);
cursor->mir.customCursor = stream; cursor->mir.customCursor = stream;
return GLFW_TRUE; return GLFW_TRUE;
} }
const char* getSystemCursorName(int shape) static const char* getSystemCursorName(int shape)
{ {
switch (shape) switch (shape)
{ {
@ -741,17 +731,11 @@ const char* getSystemCursorName(int shape)
int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape) int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
{ {
const char* cursor_name = getSystemCursorName(shape); cursor->mir.conf = NULL;
cursor->mir.customCursor = NULL;
cursor->mir.cursorName = getSystemCursorName(shape);
if (cursor_name) return cursor->mir.cursorName != NULL;
{
cursor->mir.conf = mir_cursor_configuration_from_name(cursor_name);
cursor->mir.customCursor = NULL;
return GLFW_TRUE;
}
return GLFW_FALSE;
} }
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor) void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
@ -762,21 +746,32 @@ void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
mir_buffer_stream_release_sync(cursor->mir.customCursor); mir_buffer_stream_release_sync(cursor->mir.customCursor);
} }
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);
}
void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
{ {
if (cursor && cursor->mir.conf) if (cursor)
{ {
window->mir.currentCursor = cursor; window->mir.currentCursor = cursor;
mir_wait_for(mir_surface_configure_cursor(window->mir.surface, cursor->mir.conf)); if (cursor->mir.cursorName)
if (cursor->mir.customCursor)
{ {
mir_buffer_stream_swap_buffers_sync(cursor->mir.customCursor); setCursorNameForWindow(window->mir.window, cursor->mir.cursorName);
}
else if (cursor->mir.conf)
{
mir_window_configure_cursor(window->mir.window, cursor->mir.conf);
} }
} }
else else
{ {
mir_wait_for(mir_surface_configure_cursor(window->mir.surface, _glfw.mir.defaultConf)); setCursorNameForWindow(window->mir.window, mir_default_cursor_name);
} }
} }
@ -797,8 +792,8 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
if (mode == GLFW_CURSOR_DISABLED) if (mode == GLFW_CURSOR_DISABLED)
{ {
_glfw.mir.disabledCursorWindow = window; _glfw.mir.disabledCursorWindow = window;
setSurfaceConfinement(window, mir_pointer_confined_to_surface); setWindowConfinement(window, mir_pointer_confined_to_window);
mir_wait_for(mir_surface_configure_cursor(window->mir.surface, _glfw.mir.disabledConf)); setCursorNameForWindow(window->mir.window, mir_disabled_cursor_name);
} }
else else
{ {
@ -806,7 +801,7 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
if (_glfw.mir.disabledCursorWindow == window) if (_glfw.mir.disabledCursorWindow == window)
{ {
_glfw.mir.disabledCursorWindow = NULL; _glfw.mir.disabledCursorWindow = NULL;
setSurfaceConfinement(window, mir_pointer_unconfined); setWindowConfinement(window, mir_pointer_unconfined);
} }
if (window->cursorMode == GLFW_CURSOR_NORMAL) if (window->cursorMode == GLFW_CURSOR_NORMAL)
@ -815,7 +810,7 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
} }
else if (window->cursorMode == GLFW_CURSOR_HIDDEN) else if (window->cursorMode == GLFW_CURSOR_HIDDEN)
{ {
mir_wait_for(mir_surface_configure_cursor(window->mir.surface, _glfw.mir.disabledConf)); setCursorNameForWindow(window->mir.window, mir_disabled_cursor_name);
} }
} }
} }
@ -880,12 +875,12 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
VkSurfaceKHR* surface) VkSurfaceKHR* surface)
{ {
VkResult err; VkResult err;
VkMirSurfaceCreateInfoKHR sci; VkMirWindowCreateInfoKHR sci;
PFN_vkCreateMirSurfaceKHR vkCreateMirSurfaceKHR; PFN_vkCreateMirWindowKHR vkCreateMirWindowKHR;
vkCreateMirSurfaceKHR = (PFN_vkCreateMirSurfaceKHR) vkCreateMirWindowKHR = (PFN_vkCreateMirWindowKHR)
vkGetInstanceProcAddr(instance, "vkCreateMirSurfaceKHR"); vkGetInstanceProcAddr(instance, "vkCreateMirWindowKHR");
if (!vkCreateMirSurfaceKHR) if (!vkCreateMirWindowKHR)
{ {
_glfwInputError(GLFW_API_UNAVAILABLE, _glfwInputError(GLFW_API_UNAVAILABLE,
"Mir: Vulkan instance missing VK_KHR_mir_surface extension"); "Mir: Vulkan instance missing VK_KHR_mir_surface extension");
@ -895,9 +890,9 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
memset(&sci, 0, sizeof(sci)); memset(&sci, 0, sizeof(sci));
sci.sType = VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR; sci.sType = VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR;
sci.connection = _glfw.mir.connection; sci.connection = _glfw.mir.connection;
sci.mirSurface = window->mir.surface; sci.mirWindow = window->mir.window;
err = vkCreateMirSurfaceKHR(instance, &sci, allocator, surface); err = vkCreateMirWindowKHR(instance, &sci, allocator, surface);
if (err) if (err)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
@ -919,10 +914,10 @@ GLFWAPI MirConnection* glfwGetMirDisplay(void)
return _glfw.mir.connection; return _glfw.mir.connection;
} }
GLFWAPI MirSurface* glfwGetMirWindow(GLFWwindow* handle) GLFWAPI MirWindow* glfwGetMirWindow(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return window->mir.surface; return window->mir.window;
} }