Mir: Get ready for Mir 1.0

Clean up CMake finding and check version.  Change last remaining
deprecations.

Closes #979.
This commit is contained in:
Brandon Schaefer 2017-03-28 19:03:29 -07:00 committed by Camilla Löwy
parent 9f63a8abfa
commit c9003b5547
7 changed files with 228 additions and 212 deletions

View File

@ -1,37 +1,34 @@
# Try to find Mir on a Unix system
# FindMir
# -------
# Finds the Mir library
#
# This will define:
# This will will define the following variables::
#
# MIR_FOUND - System has Mir
# MIR_LIBRARIES - Link these to use Mir
# MIR_INCLUDE_DIR - Include directory for Mir
# MIR_DEFINITIONS - Compiler switches required for using Mir
# MIR_FOUND - the system has Mir
# MIR_INCLUDE_DIRS - the Mir include directory
# MIR_LIBRARIES - the Mir libraries
# MIR_DEFINITIONS - the Mir definitions
if (NOT WIN32)
find_package (PkgConfig)
pkg_check_modules (PKG_MIR QUIET mirclient)
set(MIR_DEFINITIONS ${PKG_MIR_CFLAGS_OTHER})
if(PKG_CONFIG_FOUND)
pkg_check_modules (PC_MIR mirclient>=0.26.2 QUIET)
find_path(MIR_INCLUDE_DIR
NAMES xkbcommon/xkbcommon.h
HINTS ${PC_XKBCOMMON_INCLUDE_DIR} ${PC_XKBCOMMON_INCLUDE_DIRS}
)
find_path(MIR_INCLUDE_DIR NAMES mir_toolkit/mir_client_library.h
PATHS ${PC_MIR_INCLUDE_DIRS})
find_library(MIR_LIBRARY
NAMES mirclient
HINTS ${PKG_MIR_LIBRARIES} ${MIR_LIBRARY_DIRS}
)
set (MIR_INCLUDE_DIR ${PKG_MIR_INCLUDE_DIRS})
set (MIR_LIBRARIES ${MIR_LIBRARY})
find_library(MIR_LIBRARY NAMES mirclient
PATHS ${PC_MIR_LIBRARIES} ${PC_MIR_LIBRARY_DIRS})
include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (MIR DEFAULT_MSG
MIR_LIBRARIES
MIR_INCLUDE_DIR
)
mark_as_advanced (MIR_LIBRARIES MIR_INCLUDE_DIR)
find_package_handle_standard_args (MIR
REQUIRED_VARS MIR_LIBRARY MIR_INCLUDE_DIR)
if (MIR_FOUND)
set(MIR_LIBRARIES ${MIR_LIBRARY})
set(MIR_INCLUDE_DIRS ${PC_MIR_INCLUDE_DIRS})
set(MIR_DEFINITIONS -DHAVE_MIR=1)
endif()
mark_as_advanced (MIR_LIBRARY MIR_INCLUDE_DIR)
endif()

View File

@ -308,7 +308,7 @@ if (_GLFW_MIR)
find_package(Mir REQUIRED)
list(APPEND glfw_PKG_DEPS "mirclient")
list(APPEND glfw_INCLUDE_DIRS "${MIR_INCLUDE_DIR}")
list(APPEND glfw_INCLUDE_DIRS "${MIR_INCLUDE_DIRS}")
list(APPEND glfw_LIBRARIES "${MIR_LIBRARIES}" "${CMAKE_THREAD_LIBS_INIT}")
find_package(XKBCommon REQUIRED)

View File

@ -394,9 +394,9 @@ GLFWAPI MirConnection* glfwGetMirDisplay(void);
*/
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.
*
* @thread_safety This function may be called from any thread. Access is not
@ -406,7 +406,7 @@ GLFWAPI int glfwGetMirMonitor(GLFWmonitor* monitor);
*
* @ingroup native
*/
GLFWAPI MirSurface* glfwGetMirWindow(GLFWwindow* window);
GLFWAPI MirWindow* glfwGetMirWindow(GLFWwindow* window);
#endif
#if defined(GLFW_EXPOSE_NATIVE_EGL)

View File

@ -1,7 +1,7 @@
//========================================================================
// 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
// warranty. In no event will the authors be held liable for any damages
@ -195,10 +195,6 @@ int _glfwPlatformInit(void)
_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));
_glfwInitEventQueueMir(_glfw.mir.eventQueue);

View File

@ -1,7 +1,7 @@
//========================================================================
// 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
// warranty. In no event will the authors be held liable for any damages
@ -38,33 +38,41 @@
void _glfwPollMonitorsMir(void)
{
int i;
MirDisplayConfiguration* displayConfig =
mir_connection_create_display_config(_glfw.mir.connection);
MirDisplayConfig* displayConfig =
mir_connection_create_display_configuration(_glfw.mir.connection);
for (i = 0; i < displayConfig->num_outputs; i++)
int numOutputs = mir_display_config_get_num_outputs(displayConfig);
for (i = 0; i < numOutputs; i++)
{
const MirDisplayOutput* out = displayConfig->outputs + i;
const MirOutput* output = mir_display_config_get_output(displayConfig, i);
MirOutputConnectionState state = mir_output_get_connection_state(output);
bool enabled = mir_output_is_enabled(output);
if (out->used &&
out->connected &&
out->num_modes &&
out->current_mode < out->num_modes)
if (enabled && state == mir_output_connection_state_connected)
{
_GLFWmonitor* monitor = _glfwAllocMonitor("Unknown",
out->physical_width_mm,
out->physical_height_mm);
int widthMM = mir_output_get_physical_width_mm(output);
int heightMM = mir_output_get_physical_height_mm(output);
int x = mir_output_get_position_x(output);
int y = mir_output_get_position_y(output);
int id = mir_output_get_id(output);
size_t currentMode = mir_output_get_current_mode_index(output);
const char* name = mir_output_type_name(mir_output_get_type(output));
monitor->mir.x = out->position_x;
monitor->mir.y = out->position_y;
monitor->mir.outputId = out->output_id;
monitor->mir.curMode = out->current_mode;
_GLFWmonitor* monitor = _glfwAllocMonitor(name,
widthMM,
heightMM);
monitor->mir.x = x;
monitor->mir.y = y;
monitor->mir.outputId = id;
monitor->mir.curMode = currentMode;
monitor->modes = _glfwPlatformGetVideoModes(monitor, &monitor->modeCount);
_glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_LAST);
}
}
mir_display_config_destroy(displayConfig);
mir_display_config_release(displayConfig);
}
@ -80,7 +88,7 @@ void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos)
*ypos = monitor->mir.y;
}
void FillInRGBBitsFromPixelFormat(GLFWvidmode* mode, const MirPixelFormat pf)
static void FillInRGBBitsFromPixelFormat(GLFWvidmode* mode, const MirPixelFormat pf)
{
switch (pf)
{
@ -117,30 +125,52 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
{
int i;
GLFWvidmode* modes = NULL;
MirDisplayConfiguration* displayConfig =
mir_connection_create_display_config(_glfw.mir.connection);
MirDisplayConfig* displayConfig =
mir_connection_create_display_configuration(_glfw.mir.connection);
for (i = 0; i < displayConfig->num_outputs; i++)
int numOutputs = mir_display_config_get_num_outputs(displayConfig);
for (i = 0; i < numOutputs; i++)
{
const MirDisplayOutput* out = displayConfig->outputs + i;
if (out->output_id != monitor->mir.outputId)
const MirOutput* output = mir_display_config_get_output(displayConfig, i);
int id = mir_output_get_id(output);
if (id != monitor->mir.outputId)
continue;
modes = calloc(out->num_modes, sizeof(GLFWvidmode));
MirOutputConnectionState state = mir_output_get_connection_state(output);
bool enabled = mir_output_is_enabled(output);
for (*found = 0; *found < out->num_modes; (*found)++)
// We must have been disconnected
if (!enabled || state != mir_output_connection_state_connected)
{
modes[*found].width = out->modes[*found].horizontal_resolution;
modes[*found].height = out->modes[*found].vertical_resolution;
modes[*found].refreshRate = out->modes[*found].refresh_rate;
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Monitor no longer connected");
return NULL;
}
FillInRGBBitsFromPixelFormat(&modes[*found], out->output_formats[*found]);
int numModes = mir_output_get_num_modes(output);
modes = calloc(numModes, sizeof(GLFWvidmode));
for (*found = 0; *found < numModes; (*found)++)
{
const MirOutputMode* mode = mir_output_get_mode(output, *found);
int width = mir_output_mode_get_width(mode);
int height = mir_output_mode_get_height(mode);
double refreshRate = mir_output_mode_get_refresh_rate(mode);
MirPixelFormat currentFormat = mir_output_get_current_pixel_format(output);
modes[*found].width = width;
modes[*found].height = height;
modes[*found].refreshRate = refreshRate;
FillInRGBBitsFromPixelFormat(&modes[*found], currentFormat);
}
break;
}
mir_display_config_destroy(displayConfig);
mir_display_config_release(displayConfig);
return modes;
}
@ -173,4 +203,3 @@ GLFWAPI int glfwGetMirMonitor(GLFWmonitor* handle)
_GLFW_REQUIRE_INIT_OR_RETURN(0);
return monitor->mir.outputId;
}

View File

@ -1,7 +1,7 @@
//========================================================================
// 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
// warranty. In no event will the authors be held liable for any damages
@ -33,18 +33,18 @@
#include <mir_toolkit/mir_client_library.h>
typedef VkFlags VkMirSurfaceCreateFlagsKHR;
typedef VkFlags VkMirWindowCreateFlagsKHR;
typedef struct VkMirSurfaceCreateInfoKHR
typedef struct VkMirWindowCreateInfoKHR
{
VkStructureType sType;
const void* pNext;
VkMirSurfaceCreateFlagsKHR flags;
VkMirWindowCreateFlagsKHR flags;
MirConnection* connection;
MirSurface* mirSurface;
} VkMirSurfaceCreateInfoKHR;
MirWindow* mirWindow;
} 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*);
#include "posix_tls.h"
@ -58,7 +58,7 @@ typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceMirPresentationSupportKHR)(Vk
#define _glfw_dlclose(handle) dlclose(handle)
#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_PLATFORM_WINDOW_STATE _GLFWwindowMir mir
@ -81,10 +81,10 @@ typedef struct EventQueue
//
typedef struct _GLFWwindowMir
{
MirSurface* surface;
MirWindow* window;
int width;
int height;
MirEGLNativeWindowType window;
MirEGLNativeWindowType nativeWindow;
_GLFWcursor* currentCursor;
} _GLFWwindowMir;
@ -106,8 +106,6 @@ typedef struct _GLFWlibraryMir
{
MirConnection* connection;
MirEGLNativeDisplayType display;
MirCursorConfiguration* defaultConf;
MirCursorConfiguration* disabledConf;
EventQueue* eventQueue;
short int keycodes[256];
@ -128,9 +126,11 @@ typedef struct _GLFWcursorMir
{
MirCursorConfiguration* conf;
MirBufferStream* customCursor;
char const* cursorName; // only needed for system cursors
} _GLFWcursorMir;
extern void _glfwPollMonitorsMir(void);
extern void _glfwInitEventQueueMir(EventQueue* queue);
extern void _glfwDeleteEventQueueMir(EventQueue* queue);

View File

@ -1,7 +1,7 @@
//========================================================================
// 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
// warranty. In no event will the authors be held liable for any damages
@ -89,9 +89,6 @@ static EventNode* dequeueEvent(EventQueue* queue)
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)
{
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);
}
static GLFWbool createSurface(_GLFWwindow* window)
static GLFWbool createWindow(_GLFWwindow* window)
{
MirSurfaceSpec* spec;
MirWindowSpec* spec;
MirBufferUsage buffer_usage = mir_buffer_usage_hardware;
MirPixelFormat pixel_format = findValidPixelFormat();
@ -301,40 +298,39 @@ static GLFWbool createSurface(_GLFWwindow* window)
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.height,
pixel_format);
window->mir.height);
mir_surface_spec_set_buffer_usage(spec, buffer_usage);
mir_surface_spec_set_name(spec, "MirSurface");
mir_window_spec_set_pixel_format(spec, pixel_format);
mir_window_spec_set_buffer_usage(spec, buffer_usage);
window->mir.surface = mir_surface_create_sync(spec);
mir_surface_spec_release(spec);
window->mir.window = mir_create_window_sync(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,
"Mir: Unable to create surface: %s",
mir_surface_get_error_message(window->mir.surface));
"Mir: Unable to create window: %s",
mir_window_get_error_message(window->mir.window));
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;
}
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);
mir_surface_spec_set_pointer_confinement(spec, state);
spec = mir_create_window_spec(_glfw.mir.connection);
mir_window_spec_set_pointer_confinement(spec, state);
mir_surface_apply_spec(window->mir.surface, spec);
mir_surface_spec_release(spec);
mir_window_apply_spec(window->mir.window, spec);
mir_window_spec_release(spec);
}
//////////////////////////////////////////////////////////////////////////
@ -381,12 +377,12 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
GLFWvidmode 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)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Requested surface size too large: %ix%i",
"Mir: Requested window size too large: %ix%i",
wndconfig->width, wndconfig->height);
return GLFW_FALSE;
@ -397,11 +393,11 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
window->mir.height = wndconfig->height;
window->mir.currentCursor = NULL;
if (!createSurface(window))
if (!createWindow(window))
return GLFW_FALSE;
window->mir.window = mir_buffer_stream_get_egl_native_window(
mir_surface_get_buffer_stream(window->mir.surface));
window->mir.nativeWindow = mir_buffer_stream_get_egl_native_window(
mir_window_get_buffer_stream(window->mir.window));
if (ctxconfig->client != GLFW_NO_API)
{
@ -430,10 +426,10 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
if (_glfw.mir.disabledCursorWindow == window)
_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);
window->mir.surface = NULL;
mir_window_release_sync(window->mir.window);
window->mir.window= NULL;
}
if (window->context.destroy)
@ -442,13 +438,12 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
{
MirSurfaceSpec* spec;
MirWindowSpec* spec;
spec = mir_connection_create_spec_for_changes(_glfw.mir.connection);
mir_surface_spec_set_name(spec, title);
mir_surface_apply_spec(window->mir.surface, spec);
mir_surface_spec_release(spec);
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);
}
void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
@ -460,22 +455,30 @@ void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
{
MirSurfaceSpec* spec;
MirWindowSpec* 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);
spec = mir_create_window_spec(_glfw.mir.connection);
mir_window_spec_set_width (spec, width);
mir_window_spec_set_height(spec, height);
mir_surface_apply_spec(window->mir.surface, spec);
mir_surface_spec_release(spec);
mir_window_apply_spec(window->mir.window, spec);
mir_window_spec_release(spec);
}
void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window,
int minwidth, int minheight,
int maxwidth, int maxheight)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
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);
}
void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom)
@ -514,57 +517,57 @@ void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
void _glfwPlatformIconifyWindow(_GLFWwindow* window)
{
MirSurfaceSpec* spec;
MirWindowSpec* spec;
spec = mir_connection_create_spec_for_changes(_glfw.mir.connection);
mir_surface_spec_set_state(spec, mir_surface_state_minimized);
spec = mir_create_window_spec(_glfw.mir.connection);
mir_window_spec_set_state(spec, mir_window_state_minimized);
mir_surface_apply_spec(window->mir.surface, spec);
mir_surface_spec_release(spec);
mir_window_apply_spec(window->mir.window, spec);
mir_window_spec_release(spec);
}
void _glfwPlatformRestoreWindow(_GLFWwindow* window)
{
MirSurfaceSpec* spec;
MirWindowSpec* spec;
spec = mir_connection_create_spec_for_changes(_glfw.mir.connection);
mir_surface_spec_set_state(spec, mir_surface_state_restored);
spec = mir_create_window_spec(_glfw.mir.connection);
mir_window_spec_set_state(spec, mir_window_state_restored);
mir_surface_apply_spec(window->mir.surface, spec);
mir_surface_spec_release(spec);
mir_window_apply_spec(window->mir.window, spec);
mir_window_spec_release(spec);
}
void _glfwPlatformMaximizeWindow(_GLFWwindow* window)
{
MirSurfaceSpec* spec;
MirWindowSpec* spec;
spec = mir_connection_create_spec_for_changes(_glfw.mir.connection);
mir_surface_spec_set_state(spec, mir_surface_state_maximized);
spec = mir_create_window_spec(_glfw.mir.connection);
mir_window_spec_set_state(spec, mir_window_state_maximized);
mir_surface_apply_spec(window->mir.surface, spec);
mir_surface_spec_release(spec);
mir_window_apply_spec(window->mir.window, spec);
mir_window_spec_release(spec);
}
void _glfwPlatformHideWindow(_GLFWwindow* window)
{
MirSurfaceSpec* spec;
MirWindowSpec* spec;
spec = mir_connection_create_spec_for_changes(_glfw.mir.connection);
mir_surface_spec_set_state(spec, mir_surface_state_hidden);
spec = mir_create_window_spec(_glfw.mir.connection);
mir_window_spec_set_state(spec, mir_window_state_hidden);
mir_surface_apply_spec(window->mir.surface, spec);
mir_surface_spec_release(spec);
mir_window_apply_spec(window->mir.window, spec);
mir_window_spec_release(spec);
}
void _glfwPlatformShowWindow(_GLFWwindow* window)
{
MirSurfaceSpec* spec;
MirWindowSpec* spec;
spec = mir_connection_create_spec_for_changes(_glfw.mir.connection);
mir_surface_spec_set_state(spec, mir_surface_state_restored);
spec = mir_create_window_spec(_glfw.mir.connection);
mir_window_spec_set_state(spec, mir_window_state_restored);
mir_surface_apply_spec(window->mir.surface, spec);
mir_surface_spec_release(spec);
mir_window_apply_spec(window->mir.window, spec);
mir_window_spec_release(spec);
}
void _glfwPlatformFocusWindow(_GLFWwindow* window)
@ -585,7 +588,7 @@ void _glfwPlatformSetWindowMonitor(_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)
@ -597,12 +600,12 @@ int _glfwPlatformWindowIconified(_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)
{
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)
@ -638,7 +641,7 @@ void _glfwPlatformWaitEvents(void)
{
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_mutex_unlock(&_glfw.mir.eventMutex);
@ -681,54 +684,40 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
int xhot, int yhot)
{
MirBufferStream* stream;
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 GLFW_FALSE;
}
stream = mir_connection_create_buffer_stream_sync(_glfw.mir.connection,
i_w, i_h,
pixel_format,
mir_pixel_format_argb_8888,
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;
unsigned char* pixels = image->pixels;
char* dest = region.vaddr;
int i;
dest = region.vaddr;
pixels = image->pixels;
r_stride = region.stride;
for (i = 0; i < i_h; i++)
for (i = 0; i < i_w * i_h; i++, pixels += 4)
{
memcpy(dest, pixels, bytes_per_row);
dest += r_stride;
pixels += r_stride;
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;
}
mir_buffer_stream_swap_buffers_sync(stream);
cursor->mir.customCursor = stream;
return GLFW_TRUE;
}
const char* getSystemCursorName(int shape)
static const char* getSystemCursorName(int shape)
{
switch (shape)
{
@ -751,17 +740,11 @@ const char* getSystemCursorName(int shape)
int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
{
const char* cursor_name = getSystemCursorName(shape);
if (cursor_name)
{
cursor->mir.conf = mir_cursor_configuration_from_name(cursor_name);
cursor->mir.conf = NULL;
cursor->mir.customCursor = NULL;
cursor->mir.cursorName = getSystemCursorName(shape);
return GLFW_TRUE;
}
return GLFW_FALSE;
return cursor->mir.cursorName != NULL;
}
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
@ -772,21 +755,32 @@ void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
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)
{
if (cursor && cursor->mir.conf)
if (cursor)
{
window->mir.currentCursor = cursor;
mir_wait_for(mir_surface_configure_cursor(window->mir.surface, cursor->mir.conf));
if (cursor->mir.customCursor)
if (cursor->mir.cursorName)
{
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
{
mir_wait_for(mir_surface_configure_cursor(window->mir.surface, _glfw.mir.defaultConf));
setCursorNameForWindow(window->mir.window, mir_default_cursor_name);
}
}
@ -807,8 +801,8 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
if (mode == GLFW_CURSOR_DISABLED)
{
_glfw.mir.disabledCursorWindow = window;
setSurfaceConfinement(window, mir_pointer_confined_to_surface);
mir_wait_for(mir_surface_configure_cursor(window->mir.surface, _glfw.mir.disabledConf));
setWindowConfinement(window, mir_pointer_confined_to_window);
setCursorNameForWindow(window->mir.window, mir_disabled_cursor_name);
}
else
{
@ -816,7 +810,7 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
if (_glfw.mir.disabledCursorWindow == window)
{
_glfw.mir.disabledCursorWindow = NULL;
setSurfaceConfinement(window, mir_pointer_unconfined);
setWindowConfinement(window, mir_pointer_unconfined);
}
if (window->cursorMode == GLFW_CURSOR_NORMAL)
@ -825,7 +819,7 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
}
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);
}
}
}
@ -890,12 +884,12 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
VkSurfaceKHR* surface)
{
VkResult err;
VkMirSurfaceCreateInfoKHR sci;
PFN_vkCreateMirSurfaceKHR vkCreateMirSurfaceKHR;
VkMirWindowCreateInfoKHR sci;
PFN_vkCreateMirWindowKHR vkCreateMirWindowKHR;
vkCreateMirSurfaceKHR = (PFN_vkCreateMirSurfaceKHR)
vkGetInstanceProcAddr(instance, "vkCreateMirSurfaceKHR");
if (!vkCreateMirSurfaceKHR)
vkCreateMirWindowKHR = (PFN_vkCreateMirWindowKHR)
vkGetInstanceProcAddr(instance, "vkCreateMirWindowKHR");
if (!vkCreateMirWindowKHR)
{
_glfwInputError(GLFW_API_UNAVAILABLE,
"Mir: Vulkan instance missing VK_KHR_mir_surface extension");
@ -905,9 +899,9 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
memset(&sci, 0, sizeof(sci));
sci.sType = VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR;
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)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
@ -929,10 +923,10 @@ GLFWAPI MirConnection* glfwGetMirDisplay(void)
return _glfw.mir.connection;
}
GLFWAPI MirSurface* glfwGetMirWindow(GLFWwindow* handle)
GLFWAPI MirWindow* glfwGetMirWindow(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return window->mir.surface;
return window->mir.window;
}