From 9bd0fae684ac506348b267dd7a4bbc44b580a6c5 Mon Sep 17 00:00:00 2001 From: BrandonSchaefer Date: Thu, 6 Nov 2014 00:25:52 -0800 Subject: [PATCH] Make sure we go through all the pointer_coords. --- src/mir_init.c | 11 +++++- src/mir_window.c | 92 +++++++++++++++++++++++------------------------- 2 files changed, 55 insertions(+), 48 deletions(-) diff --git a/src/mir_init.c b/src/mir_init.c index b37fa2c8..33923c4e 100644 --- a/src/mir_init.c +++ b/src/mir_init.c @@ -37,6 +37,15 @@ void _glfwPlatformTerminate(void) const char* _glfwPlatformGetVersionString(void) { - return "MIR // FIXME (<0_0>)"; + const char* version = _GLFW_VERSION_NUMBER " Mir EGL " +#if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK) + " clock_gettime" +#endif +#if defined(_GLFW_BUILD_DLL) + " shared" +#endif + ; + + return version; } diff --git a/src/mir_window.c b/src/mir_window.c index 0c40c668..2dc33c02 100644 --- a/src/mir_window.c +++ b/src/mir_window.c @@ -6,7 +6,7 @@ // FIXME Remove me when done debugging! #include -MirPixelFormat FindValidPixelFormat() +MirPixelFormat findValidPixelFormat() { unsigned int pf_size = 32; unsigned int valid_formats; @@ -157,7 +157,7 @@ static int toGLFWKeyCode(uint32_t key) } } -void HandleKeyEvent(MirKeyEvent const key, _GLFWwindow* window) +void handleKeyEvent(MirKeyEvent const key, _GLFWwindow* window) { int pressed = key.action == mir_key_action_up ? GLFW_RELEASE : GLFW_PRESS; @@ -170,7 +170,7 @@ void HandleKeyEvent(MirKeyEvent const key, _GLFWwindow* window) _glfwInputChar(window, text, 0, 0); } -void HandleMouseButton(_GLFWwindow* window, int pressed, MirMotionButton button) +void handleMouseButton(_GLFWwindow* window, int pressed, MirMotionButton button) { static int last_button; int glfw_button; @@ -206,39 +206,39 @@ void HandleMouseButton(_GLFWwindow* window, int pressed, MirMotionButton button) } // TODO Confirm the x/y is correct and no futher work needs to be done. -void HandleMouseMotion(_GLFWwindow* window, int x, int y) +void handleMouseMotion(_GLFWwindow* window, int x, int y) { _glfwInputCursorMotion(window, x, y); } // TODO Confirm it really wants the dx/dy and that they are in the correct direction! -void HandleMouseScroll(_GLFWwindow* window, int dx, int dy) +void handleMouseScroll(_GLFWwindow* window, int dx, int dy) { _glfwInputScroll(window, dx, dy); } -void HandleMouseEvent(MirMotionEvent const motion, int cord_index, _GLFWwindow* window) +void handleMouseEvent(MirMotionEvent const 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.button_state); + handleMouseButton(window, GLFW_PRESS, motion.button_state); break; case mir_motion_action_up: case mir_motion_action_pointer_up: - HandleMouseButton(window, GLFW_RELEASE, motion.button_state); + handleMouseButton(window, GLFW_RELEASE, motion.button_state); break; case mir_motion_action_hover_move: case mir_motion_action_move: - HandleMouseMotion(window, + handleMouseMotion(window, motion.pointer_coordinates[cord_index].x, motion.pointer_coordinates[cord_index].y); break; case mir_motion_action_outside: break; case mir_motion_action_scroll: - HandleMouseScroll(window, + handleMouseScroll(window, motion.pointer_coordinates[cord_index].hscroll, motion.pointer_coordinates[cord_index].vscroll); break; @@ -252,59 +252,35 @@ void HandleMouseEvent(MirMotionEvent const motion, int cord_index, _GLFWwindow* } } -static void HandleMotionEvent(MirMotionEvent const motion, _GLFWwindow* window) +static void handleMotionEvent(MirMotionEvent const motion, _GLFWwindow* window) { int cord_index; - for (cord_index = 0; cord_index < motion.pointer_count; cord_index++) { - HandleMouseEvent(motion, cord_index, window); - /* - // TODO Does GLFW handle touch events? - if (motion.pointer_coordinates[cord_index].tool_type == mir_motion_tool_type_finger) { - HandleTouchEvent(motion, cord_index, window); - } - else { - HandleMouseEvent(motion, cord_index, window); - } - */ - } + for (cord_index = 0; cord_index < motion.pointer_count; cord_index++) + handleMouseEvent(motion, cord_index, window); } -void HandleInput(MirSurface* surface, MirEvent const* event, void* context) +void handleInput(MirSurface* surface, MirEvent const* event, void* context) { switch (event->type) { case(mir_event_type_key): - HandleKeyEvent(event->key, (_GLFWwindow*)context); + handleKeyEvent(event->key, (_GLFWwindow*)context); break; case(mir_event_type_motion): - HandleMotionEvent(event->motion, (_GLFWwindow*)context); + handleMotionEvent(event->motion, (_GLFWwindow*)context); break; default: break; } } -////////////////////////////////////////////////////////////////////////// -////// GLFW platform API ////// -////////////////////////////////////////////////////////////////////////// - -int _glfwPlatformCreateWindow(_GLFWwindow* window, - const _GLFWwndconfig* wndconfig, - const _GLFWctxconfig* ctxconfig, - const _GLFWfbconfig* fbconfig) +int createSurface(_GLFWwindow* window) { - if (!_glfwCreateContext(window, ctxconfig, fbconfig)) - return GL_FALSE; - - // FIXME Add a check here to ensure we are within our max width/height - window->mir.width = wndconfig->width; - window->mir.height = wndconfig->height; - MirSurfaceParameters params = { .name = "MirSurface", - .width = wndconfig->width, - .height = wndconfig->height, + .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 @@ -312,11 +288,11 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, MirEventDelegate delegate = { - HandleInput, + handleInput, window }; - params.pixel_format = FindValidPixelFormat(); + params.pixel_format = findValidPixelFormat(); if (params.pixel_format == mir_pixel_format_invalid) { _glfwInputError(GLFW_PLATFORM_ERROR, @@ -332,13 +308,35 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, return GL_FALSE; } - window->mir.native_window = mir_surface_get_egl_native_window(window->mir.surface); - mir_surface_set_event_handler(window->mir.surface, &delegate); return GL_TRUE; } +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// + +int _glfwPlatformCreateWindow(_GLFWwindow* window, + const _GLFWwndconfig* wndconfig, + const _GLFWctxconfig* ctxconfig, + const _GLFWfbconfig* fbconfig) +{ + if (!_glfwCreateContext(window, ctxconfig, fbconfig)) + return GL_FALSE; + + // FIXME Add a check here to ensure we are within our max width/height + window->mir.width = wndconfig->width; + window->mir.height = wndconfig->height; + + if (!createSurface(window)) + return GL_FALSE; + + window->mir.native_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))