Formatting.

This commit is contained in:
Camilla Berglund 2014-11-06 23:52:38 +01:00
parent e059f012d7
commit 916371e04c
4 changed files with 167 additions and 149 deletions

View File

@ -26,6 +26,7 @@
#include "internal.h"
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
@ -37,11 +38,12 @@ int _glfwPlatformInit(void)
if (!mir_connection_is_valid(_glfw.mir.connection))
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unable to connect to Server\n");
"Mir: Unable to connect to Server");
return GL_FALSE;
}
_glfw.mir.native_display = mir_connection_get_egl_native_display(_glfw.mir.connection);
_glfw.mir.display =
mir_connection_get_egl_native_display(_glfw.mir.connection);
if (!_glfwInitContextAPI())
return GL_FALSE;
@ -56,6 +58,7 @@ void _glfwPlatformTerminate(void)
{
_glfwTerminateContextAPI();
_glfwTerminateJoysticks();
mir_connection_release(_glfw.mir.connection);
}

View File

@ -35,15 +35,16 @@
_GLFWmonitor** _glfwPlatformGetMonitors(int* count)
{
int d, found = 0;
MirDisplayConfiguration* display_config = mir_connection_create_display_config(_glfw.mir.connection);
int i, found = 0;
_GLFWmonitor** monitors = NULL;
_GLFWmonitor* monitor = NULL;
MirDisplayConfiguration* displayConfig =
mir_connection_create_display_config(_glfw.mir.connection);
for (d = 0; d < display_config->num_outputs; d++)
*count = 0;
for (i = 0; i < displayConfig->num_outputs; i++)
{
MirDisplayOutput const* out = display_config->outputs + d;
const MirDisplayOutput* out = displayConfig->outputs + i;
if (out->used &&
out->connected &&
@ -51,23 +52,22 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
out->current_mode < out->num_modes)
{
found++;
monitors = realloc(monitors, sizeof(_GLFWmonitor*) * found);
monitor = _glfwAllocMonitor("Unknown",
out->physical_width_mm,
out->physical_height_mm);
monitor->mir.x = out->position_x;
monitor->mir.y = out->position_y;
monitor->mir.output_id = out->output_id;
monitor->mir.cur_mode = out->current_mode;
monitors[found] = realloc(monitors, sizeof(_GLFWmonitor*) * found);
monitors[found] = _glfwAllocMonitor("Unknown",
out->physical_width_mm,
out->physical_height_mm);
monitors[d] = monitor;
monitors[found]->mir.x = out->position_x;
monitors[found]->mir.y = out->position_y;
monitors[found]->mir.output_id = out->output_id;
monitors[found]->mir.cur_mode = out->current_mode;
}
}
*count = found;
mir_display_config_destroy(display_config);
mir_display_config_destroy(displayConfig);
*count = found;
return monitors;
}
@ -88,12 +88,12 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
{
int i;
GLFWvidmode* modes = NULL;
MirDisplayConfiguration* display_config =
MirDisplayConfiguration* displayConfig =
mir_connection_create_display_config(_glfw.mir.connection);
for (i = 0; i < display_config->num_outputs; i++)
for (i = 0; i < displayConfig->num_outputs; i++)
{
const MirDisplayOutput* out = display_config->outputs + i;
const MirDisplayOutput* out = displayConfig->outputs + i;
if (out->output_id != monitor->mir.output_id)
continue;
@ -112,24 +112,25 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
break;
}
mir_display_config_destroy(display_config);
mir_display_config_destroy(displayConfig);
return modes;
}
void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
{
*mode = monitor->modes[monitor->mir.cur_mode];
*mode = monitor->modes[monitor->mir.cur_mode];
}
void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
"Mir: Unsupported Function %s!", __PRETTY_FUNCTION__);
}
void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
"Mir: Unsupported Function %s!", __PRETTY_FUNCTION__);
}

View File

@ -39,24 +39,29 @@
#error "The Mir backend depends on EGL platform support"
#endif
#define _GLFW_EGL_NATIVE_WINDOW window->mir.native_window
#define _GLFW_EGL_NATIVE_DISPLAY _glfw.mir.native_display
#define _GLFW_EGL_NATIVE_WINDOW window->mir.window
#define _GLFW_EGL_NATIVE_DISPLAY _glfw.mir.display
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowMir mir;
#define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorMir mir;
#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryMir mir;
#define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorMir mir;
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowMir mir
#define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorMir mir
#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryMir mir
#define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorMir mir
// Mir-specific per-window data
//
typedef struct _GLFWwindowMir
{
MirSurface* surface;
int width;
int height;
MirEGLNativeWindowType native_window;
MirSurface* surface;
int width;
int height;
MirEGLNativeWindowType window;
} _GLFWwindowMir;
// Mir-specific per-monitor data
//
typedef struct _GLFWmonitorMir
{
int cur_mode;
@ -66,14 +71,20 @@ typedef struct _GLFWmonitorMir
} _GLFWmonitorMir;
// Mir-specific global data
//
typedef struct _GLFWlibraryMir
{
MirConnection* connection;
MirEGLNativeDisplayType native_display;
MirConnection* connection;
MirEGLNativeDisplayType display;
} _GLFWlibraryMir;
// TODO Only system cursors are implemented in mir atm. Need to wait for support.
// Mir-specific per-cursor data
// TODO: Only system cursors are implemented in mir atm. Need to wait for support.
//
typedef struct _GLFWcursorMir
{
} _GLFWcursorMir;

View File

@ -29,54 +29,43 @@
#include <linux/input.h>
static MirPixelFormat findValidPixelFormat()
static MirPixelFormat findValidPixelFormat(void)
{
unsigned int pf_size = 32;
unsigned int valid_formats;
unsigned int f;
unsigned int i, validFormats, size = 32;
MirPixelFormat formats[size];
MirPixelFormat formats[pf_size];
mir_connection_get_available_surface_formats(_glfw.mir.connection, formats,
pf_size, &valid_formats);
size, &validFormats);
for (f = 0; f < valid_formats; f++)
for (i = 0; i < validFormats; i++)
{
MirPixelFormat cur_pf = formats[f];
if (cur_pf == mir_pixel_format_abgr_8888 ||
cur_pf == mir_pixel_format_xbgr_8888 ||
cur_pf == mir_pixel_format_argb_8888 ||
cur_pf == mir_pixel_format_xrgb_8888)
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)
{
return cur_pf;
return formats[i];
}
}
return mir_pixel_format_invalid;
}
static int mirModToGLFWMod(uint32_t mod)
static int mirModToGLFWMod(uint32_t mods)
{
int glfw_mod = 0x0;
int publicMods = 0x0;
if (mod & mir_key_modifier_alt)
{
glfw_mod |= GLFW_MOD_ALT;
}
else if (mod & mir_key_modifier_shift)
{
glfw_mod |= GLFW_MOD_SHIFT;
}
else if (mod & mir_key_modifier_ctrl)
{
glfw_mod |= GLFW_MOD_CONTROL;
}
else if (mod & mir_key_modifier_meta)
{
glfw_mod |= GLFW_MOD_SUPER;
}
if (mods & mir_key_modifier_alt)
publicMods |= GLFW_MOD_ALT;
else if (mods & mir_key_modifier_shift)
publicMods |= GLFW_MOD_SHIFT;
else if (mods & mir_key_modifier_ctrl)
publicMods |= GLFW_MOD_CONTROL;
else if (mods & mir_key_modifier_meta)
publicMods |= GLFW_MOD_SUPER;
return glfw_mod;
return publicMods;
}
// Taken from wl_init.c
@ -204,13 +193,12 @@ static int toGLFWKeyCode(uint32_t key)
}
}
static void handleKeyEvent(MirKeyEvent const key, _GLFWwindow* window)
static void handleKeyEvent(const MirKeyEvent key, _GLFWwindow* window)
{
int pressed = key.action == mir_key_action_up ? GLFW_RELEASE : GLFW_PRESS;
int mods = mirModToGLFWMod(key.modifiers);
long text = _glfwKeySym2Unicode(key.key_code);
int plain = !(mods & (GLFW_MOD_CONTROL | GLFW_MOD_ALT));
const int pressed = key.action == mir_key_action_up ? GLFW_RELEASE : GLFW_PRESS;
const int mods = mirModToGLFWMod(key.modifiers);
const long text = _glfwKeySym2Unicode(key.key_code);
const int plain = !(mods & (GLFW_MOD_CONTROL | GLFW_MOD_ALT));
_glfwInputKey(window, toGLFWKeyCode(key.scan_code), key.scan_code, pressed, mods);
@ -218,39 +206,40 @@ static void handleKeyEvent(MirKeyEvent const key, _GLFWwindow* window)
_glfwInputChar(window, text, mods, plain);
}
static void handleMouseButton(_GLFWwindow* window, int pressed, int mir_mods, MirMotionButton button)
static void handleMouseButton(_GLFWwindow* window,
int pressed, int mods, MirMotionButton button)
{
static int last_button;
int glfw_button;
int mods = mirModToGLFWMod(mir_mods);
static int lastButton;
int publicButton;
const int publicMods = mirModToGLFWMod(mods);
switch (button)
{
case mir_motion_button_primary:
glfw_button = GLFW_MOUSE_BUTTON_LEFT;
publicButton = GLFW_MOUSE_BUTTON_LEFT;
break;
case mir_motion_button_secondary:
glfw_button = GLFW_MOUSE_BUTTON_RIGHT;
publicButton = GLFW_MOUSE_BUTTON_RIGHT;
break;
case mir_motion_button_tertiary:
glfw_button = GLFW_MOUSE_BUTTON_MIDDLE;
publicButton = GLFW_MOUSE_BUTTON_MIDDLE;
break;
case mir_motion_button_forward:
// FIXME What is the forward button?
glfw_button = GLFW_MOUSE_BUTTON_4;
publicButton = GLFW_MOUSE_BUTTON_4;
break;
case mir_motion_button_back:
// FIXME What is the back button?
glfw_button = GLFW_MOUSE_BUTTON_5;
publicButton = GLFW_MOUSE_BUTTON_5;
break;
default:
glfw_button = last_button;
publicButton = lastButton;
break;
}
last_button = glfw_button;
lastButton = publicButton;
_glfwInputMouseClick(window, glfw_button, pressed, mods);
_glfwInputMouseClick(window, publicButton, pressed, publicMods);
}
static void handleMouseMotion(_GLFWwindow* window, int x, int y)
@ -263,17 +252,21 @@ static void handleMouseScroll(_GLFWwindow* window, int dx, int dy)
_glfwInputScroll(window, dx, dy);
}
static void handleMouseEvent(MirMotionEvent const motion, int cord_index, _GLFWwindow* window)
static void handleMouseEvent(const MirMotionEvent motion,
int cord_index,
_GLFWwindow* window)
{
switch (motion.action)
{
case mir_motion_action_down:
case mir_motion_action_pointer_down:
handleMouseButton(window, GLFW_PRESS, motion.modifiers, motion.button_state);
handleMouseButton(window, GLFW_PRESS,
motion.modifiers, motion.button_state);
break;
case mir_motion_action_up:
case mir_motion_action_pointer_up:
handleMouseButton(window, GLFW_RELEASE, motion.modifiers, motion.button_state);
handleMouseButton(window, GLFW_RELEASE,
motion.modifiers, motion.button_state);
break;
case mir_motion_action_hover_move:
case mir_motion_action_move:
@ -298,31 +291,31 @@ static void handleMouseEvent(MirMotionEvent const motion, int cord_index, _GLFWw
}
}
static void handleMotionEvent(MirMotionEvent const motion, _GLFWwindow* window)
static void handleMotionEvent(const MirMotionEvent motion, _GLFWwindow* window)
{
int cord_index;
for (cord_index = 0; cord_index < motion.pointer_count; cord_index++)
handleMouseEvent(motion, cord_index, window);
int i;
for (i = 0; i < motion.pointer_count; i++)
handleMouseEvent(motion, i, window);
}
static void handleInput(MirSurface* surface, MirEvent const* event, void* context)
static void handleInput(MirSurface* surface, const MirEvent* event, void* context)
{
switch (event->type)
{
case(mir_event_type_key):
handleKeyEvent(event->key, (_GLFWwindow*)context);
break;
case(mir_event_type_motion):
handleMotionEvent(event->motion, (_GLFWwindow*)context);
break;
default:
break;
}
switch (event->type)
{
case mir_event_type_key:
handleKeyEvent(event->key, (_GLFWwindow*) context);
break;
case mir_event_type_motion:
handleMotionEvent(event->motion, (_GLFWwindow*) context);
break;
default:
break;
}
}
static int createSurface(_GLFWwindow* window)
{
MirSurfaceParameters params =
MirSurfaceParameters params =
{
.name = "MirSurface",
.width = window->mir.width,
@ -342,15 +335,16 @@ static int createSurface(_GLFWwindow* window)
if (params.pixel_format == mir_pixel_format_invalid)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unable to find a correct pixel format!\n");
"Mir: Unable to find a correct pixel format");
return GL_FALSE;
}
window->mir.surface = mir_connection_create_surface_sync(_glfw.mir.connection, &params);
window->mir.surface =
mir_connection_create_surface_sync(_glfw.mir.connection, &params);
if (!mir_surface_is_valid(window->mir.surface))
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unable to create surface!\n");
"Mir: Unable to create surface");
return GL_FALSE;
}
@ -359,6 +353,7 @@ static int createSurface(_GLFWwindow* window)
return GL_TRUE;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
@ -381,7 +376,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
if (wndconfig->width > mode.width || wndconfig->height > mode.height)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Requested surface size is to large (%i %i)\n",
"Mir: Requested surface size is to large (%i %i)",
wndconfig->width, wndconfig->height);
return GL_FALSE;
@ -394,58 +389,60 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
if (!createSurface(window))
return GL_FALSE;
window->mir.native_window = mir_surface_get_egl_native_window(window->mir.surface);
window->mir.window = mir_surface_get_egl_native_window(window->mir.surface);
return GL_TRUE;
}
void _glfwPlatformDestroyWindow(_GLFWwindow* window)
{
if (mir_surface_is_valid(window->mir.surface))
{
mir_surface_release_sync(window->mir.surface);
window->mir.surface = NULL;
}
if (mir_surface_is_valid(window->mir.surface))
{
mir_surface_release_sync(window->mir.surface);
window->mir.surface = NULL;
}
_glfwDestroyContext(window);
_glfwDestroyContext(window);
}
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
"Mir: Unsupported Function %s!", __PRETTY_FUNCTION__);
}
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
"Mir: Unsupported Function %s!", __PRETTY_FUNCTION__);
}
void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window, int* left, int* top, int* right, int* bottom)
void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
int* left, int* top,
int* right, int* bottom)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
"Mir: Unsupported Function %s!", __PRETTY_FUNCTION__);
}
void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
"Mir: Unsupported Function %s!", __PRETTY_FUNCTION__);
}
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
"Mir: Unsupported Function %s!", __PRETTY_FUNCTION__);
}
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
{
if (width)
*width = window->mir.width;
if (height)
*height = window->mir.height;
if (width)
*width = window->mir.width;
if (height)
*height = window->mir.height;
}
void _glfwPlatformIconifyWindow(_GLFWwindow* window)
@ -461,28 +458,31 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
void _glfwPlatformHideWindow(_GLFWwindow* window)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
"Mir: Unsupported Function %s!", __PRETTY_FUNCTION__);
}
void _glfwPlatformShowWindow(_GLFWwindow* window)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
"Mir: Unsupported Function %s!", __PRETTY_FUNCTION__);
}
void _glfwPlatformUnhideWindow(_GLFWwindow* window)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
"Mir: Unsupported Function %s!", __PRETTY_FUNCTION__);
}
// Mir does event handling in a different thread, so windows get events directly as they happen
void _glfwPlatformPollEvents(void)
{
// Mir does event handling in a different thread, so windows get events
// directly as they happen
}
void _glfwPlatformWaitEvents(void)
{
// Mir does event handling in a different thread, so windows get events
// directly as they happen
}
void _glfwPlatformPostEmptyEvent(void)
@ -491,54 +491,57 @@ void _glfwPlatformPostEmptyEvent(void)
void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height)
{
if (width)
*width = window->mir.width;
if (height)
*height = window->mir.height;
if (width)
*width = window->mir.width;
if (height)
*height = window->mir.height;
}
int _glfwPlatformCreateCursor(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot)
int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
const GLFWimage* image,
int xhot, int yhot)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
"Mir: Unsupported Function %s!", __PRETTY_FUNCTION__);
return 0;
return GL_FALSE;
}
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
"Mir: Unsupported Function %s!", __PRETTY_FUNCTION__);
}
void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
"Mir: Unsupported Function %s!", __PRETTY_FUNCTION__);
}
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
"Mir: Unsupported Function %s!", __PRETTY_FUNCTION__);
}
void _glfwPlatformApplyCursorMode(_GLFWwindow* window)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
"Mir: Unsupported Function %s!", __PRETTY_FUNCTION__);
}
void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
"Mir: Unsupported Function %s!", __PRETTY_FUNCTION__);
}
const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
"Mir: Unsupported Function %s!", __PRETTY_FUNCTION__);
return NULL;
}