Make sure we go through all the pointer_coords.

master
BrandonSchaefer ago%!(EXTRA string=11 years) committed by Camilla Berglund
parent 8712d84bcc
commit 9bd0fae684
  1. 11
      src/mir_init.c
  2. 92
      src/mir_window.c

@ -37,6 +37,15 @@ void _glfwPlatformTerminate(void)
const char* _glfwPlatformGetVersionString(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;
} }

@ -6,7 +6,7 @@
// FIXME Remove me when done debugging! // FIXME Remove me when done debugging!
#include <stdio.h> #include <stdio.h>
MirPixelFormat FindValidPixelFormat() MirPixelFormat findValidPixelFormat()
{ {
unsigned int pf_size = 32; unsigned int pf_size = 32;
unsigned int valid_formats; 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; 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); _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; static int last_button;
int glfw_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. // 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); _glfwInputCursorMotion(window, x, y);
} }
// TODO Confirm it really wants the dx/dy and that they are in the correct direction! // 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); _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) switch (motion.action)
{ {
case mir_motion_action_down: case mir_motion_action_down:
case mir_motion_action_pointer_down: case mir_motion_action_pointer_down:
HandleMouseButton(window, GLFW_PRESS, motion.button_state); handleMouseButton(window, GLFW_PRESS, motion.button_state);
break; break;
case mir_motion_action_up: case mir_motion_action_up:
case mir_motion_action_pointer_up: case mir_motion_action_pointer_up:
HandleMouseButton(window, GLFW_RELEASE, motion.button_state); handleMouseButton(window, GLFW_RELEASE, motion.button_state);
break; break;
case mir_motion_action_hover_move: case mir_motion_action_hover_move:
case mir_motion_action_move: case mir_motion_action_move:
HandleMouseMotion(window, handleMouseMotion(window,
motion.pointer_coordinates[cord_index].x, motion.pointer_coordinates[cord_index].x,
motion.pointer_coordinates[cord_index].y); motion.pointer_coordinates[cord_index].y);
break; break;
case mir_motion_action_outside: case mir_motion_action_outside:
break; break;
case mir_motion_action_scroll: case mir_motion_action_scroll:
HandleMouseScroll(window, handleMouseScroll(window,
motion.pointer_coordinates[cord_index].hscroll, motion.pointer_coordinates[cord_index].hscroll,
motion.pointer_coordinates[cord_index].vscroll); motion.pointer_coordinates[cord_index].vscroll);
break; 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; int cord_index;
for (cord_index = 0; cord_index < motion.pointer_count; cord_index++) { for (cord_index = 0; cord_index < motion.pointer_count; cord_index++)
HandleMouseEvent(motion, cord_index, window); 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);
}
*/
}
} }
void HandleInput(MirSurface* surface, MirEvent const* event, void* context) void handleInput(MirSurface* surface, MirEvent const* event, void* context)
{ {
switch (event->type) switch (event->type)
{ {
case(mir_event_type_key): case(mir_event_type_key):
HandleKeyEvent(event->key, (_GLFWwindow*)context); handleKeyEvent(event->key, (_GLFWwindow*)context);
break; break;
case(mir_event_type_motion): case(mir_event_type_motion):
HandleMotionEvent(event->motion, (_GLFWwindow*)context); handleMotionEvent(event->motion, (_GLFWwindow*)context);
break; break;
default: default:
break; break;
} }
} }
////////////////////////////////////////////////////////////////////////// int createSurface(_GLFWwindow* window)
////// 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;
MirSurfaceParameters params = MirSurfaceParameters params =
{ {
.name = "MirSurface", .name = "MirSurface",
.width = wndconfig->width, .width = window->mir.width,
.height = wndconfig->height, .height = window->mir.height,
.pixel_format = mir_pixel_format_invalid, .pixel_format = mir_pixel_format_invalid,
.buffer_usage = mir_buffer_usage_hardware, .buffer_usage = mir_buffer_usage_hardware,
.output_id = mir_display_output_id_invalid .output_id = mir_display_output_id_invalid
@ -312,11 +288,11 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
MirEventDelegate delegate = MirEventDelegate delegate =
{ {
HandleInput, handleInput,
window window
}; };
params.pixel_format = FindValidPixelFormat(); params.pixel_format = findValidPixelFormat();
if (params.pixel_format == mir_pixel_format_invalid) if (params.pixel_format == mir_pixel_format_invalid)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
@ -332,13 +308,35 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
return GL_FALSE; 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); mir_surface_set_event_handler(window->mir.surface, &delegate);
return GL_TRUE; 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) void _glfwPlatformDestroyWindow(_GLFWwindow* window)
{ {
if (mir_surface_is_valid(window->mir.surface)) if (mir_surface_is_valid(window->mir.surface))

Loading…
Cancel
Save