[Merge] lp:~mir-team/qtubuntu/port-to-mirclient into lp:qtubuntu
Michał Sawicz
michal.sawicz at canonical.com
Mon Mar 2 15:11:14 UTC 2015
Diff comments:
> === modified file 'debian/control'
> --- debian/control 2014-10-09 05:22:34 +0000
> +++ debian/control 2015-02-23 19:57:37 +0000
> @@ -9,7 +9,7 @@
> libgles2-mesa-dev,
> libglib2.0-dev,
> libmtdev-dev,
> - libubuntu-application-api-dev (>= 2.5.0),
> + libubuntu-application-api-dev (>= 2.8.0),
Isn't it 2.9.0?
> libudev-dev,
> libxrender-dev,
> libxkbcommon-dev,
>
> === modified file 'src/ubuntumirclient/input.cpp'
> --- src/ubuntumirclient/input.cpp 2014-12-12 15:43:19 +0000
> +++ src/ubuntumirclient/input.cpp 2015-02-23 19:57:37 +0000
> @@ -1,5 +1,5 @@
> /*
> - * Copyright (C) 2014 Canonical, Ltd.
> + * Copyright (C) 2014-2015 Canonical, Ltd.
> *
> * This program is free software: you can redistribute it and/or modify it under
> * the terms of the GNU Lesser General Public License version 3, as published by
> @@ -36,9 +36,7 @@
> #include <xkbcommon/xkbcommon.h>
> #include <xkbcommon/xkbcommon-keysyms.h>
>
> -// Platform API
> -#include <ubuntu/application/ui/input/event.h>
> -#include <ubuntu/application/ui/window_orientation.h>
> +#include <mir_toolkit/mir_client_library.h>
>
> #define LOG_EVENTS 0
>
> @@ -122,23 +120,20 @@
> 0, 0
> };
>
> -// Lookup table for the key types.
> -// FIXME(loicm) Not sure what to do with that multiple thing.
> -static const QEvent::Type kEventType[] = {
> - QEvent::KeyPress, // U_KEY_ACTION_DOWN = 0
> - QEvent::KeyRelease, // U_KEY_ACTION_UP = 1
> - QEvent::KeyPress // U_KEY_ACTION_MULTIPLE = 2
> -};
> -
> class UbuntuEvent : public QEvent
> {
> public:
> - UbuntuEvent(UbuntuWindow* window, const WindowEvent* event, QEvent::Type type)
> + UbuntuEvent(UbuntuWindow* window, const MirEvent *event, QEvent::Type type)
> : QEvent(type), window(window) {
> - memcpy(&nativeEvent, event, sizeof(WindowEvent));
> - }
> - UbuntuWindow* window;
> - WindowEvent nativeEvent;
> + nativeEvent = mir_event_ref(event);
> + }
> + ~UbuntuEvent()
> + {
> + mir_event_unref(nativeEvent);
> + }
> +
> + QPointer<UbuntuWindow> window;
> + const MirEvent *nativeEvent;
> };
>
> UbuntuInput::UbuntuInput(UbuntuClientIntegration* integration)
> @@ -163,124 +158,124 @@
> }
>
> #ifndef QT_NO_DEBUG
> -/*
> -static const char* nativeEventTypeToStr(int eventType)
> +
> +
> +static const char* nativeEventTypeToStr(MirEventType t)
> {
> - switch (eventType) {
> - case MOTION_WEVENT_TYPE:
> - return "MOTION_WEVENT_TYPE";
> - break;
> - case KEY_WEVENT_TYPE:
> - return "KEY_WEVENT_TYPE";
> - break;
> - case RESIZE_WEVENT_TYPE:
> - return "RESIZE_WEVENT_TYPE";
> - break;
> - case SURFACE_WEVENT_TYPE:
> - return "SURFACE_WEVENT_TYPE";
> - break;
> - case ORIENTATION_WEVENT_TYPE:
> - return "ORIENTATION_WEVENT_TYPE";
> - break;
> + switch (t)
> + {
> + case mir_event_type_key:
> + return "mir_event_type_key";
> + case mir_event_type_motion:
> + return "mir_event_type_motion";
> + case mir_event_type_surface:
> + return "mir_event_type_surface";
> + case mir_event_type_resize:
> + return "mir_event_type_resize";
> + case mir_event_type_prompt_session_state_change:
> + return "mir_event_type_prompt_session_state_change";
> + case mir_event_type_orientation:
> + return "mir_event_type_orientation";
> + case mir_event_type_close_surface:
> + return "mir_event_type_close_surface";
> + case mir_event_type_input:
> + return "mir_event_type_input";
> default:
> - return "INVALID!";
> + DLOG("Invalid event type %d", t);
> + return "invalid";
> }
> }
> -*/
> +
> +
> #endif
>
> void UbuntuInput::customEvent(QEvent* event)
> {
> DASSERT(QThread::currentThread() == thread());
> UbuntuEvent* ubuntuEvent = static_cast<UbuntuEvent*>(event);
> - WindowEvent *nativeEvent = &ubuntuEvent->nativeEvent;
> + const MirEvent *nativeEvent = ubuntuEvent->nativeEvent;
>
> - if (ubuntuEvent->window->window() == nullptr) {
> - qWarning() << "Attempted to deliver an event to a non-existant QWindow, ignoring.";
> + if ((ubuntuEvent->window == nullptr) || (ubuntuEvent->window->window() == nullptr)) {
> + qWarning() << "Attempted to deliver an event to a non-existent window, ignoring.";
> return;
> }
>
> // Event filtering.
> long result;
> if (QWindowSystemInterface::handleNativeEvent(
> - ubuntuEvent->window->window(), mEventFilterType, nativeEvent, &result) == true) {
> + ubuntuEvent->window->window(), mEventFilterType,
> + const_cast<void *>(static_cast<const void *>(nativeEvent)), &result) == true) {
> DLOG("event filtered out by native interface");
> return;
> }
>
> - //DLOG("UbuntuInput::customEvent(type=%s)", nativeEventTypeToStr(nativeEvent->type));
> + //DLOG("UbuntuInput::customEvent(type=%s)", nativeEventTypeToStr(mir_event_get_type(nativeEvent)));
>
> // Event dispatching.
> - switch (nativeEvent->type) {
> - case MOTION_WEVENT_TYPE:
> - dispatchMotionEvent(ubuntuEvent->window->window(), nativeEvent);
> - break;
> - case KEY_WEVENT_TYPE:
> - dispatchKeyEvent(ubuntuEvent->window->window(), nativeEvent);
> - break;
> - case RESIZE_WEVENT_TYPE:
> - ubuntuEvent->window->handleSurfaceResize(nativeEvent->resize.width,
> - nativeEvent->resize.height);
> - break;
> - case SURFACE_WEVENT_TYPE:
> - if (nativeEvent->surface.attribute == SURFACE_ATTRIBUTE_FOCUS) {
> - ubuntuEvent->window->handleSurfaceFocusChange(nativeEvent->surface.value == 1);
> + switch (mir_event_get_type(nativeEvent))
> + {
> + case mir_event_type_input:
> + dispatchInputEvent(ubuntuEvent->window->window(), mir_event_get_input_event(nativeEvent));
> + break;
> + case mir_event_type_resize:
> + {
> + auto resizeEvent = mir_event_get_resize_event(nativeEvent);
> + ubuntuEvent->window->handleSurfaceResize(mir_resize_event_get_width(resizeEvent),
> + mir_resize_event_get_height(resizeEvent));
> + break;
> + }
> + case mir_event_type_surface:
> + {
> + auto surfaceEvent = mir_event_get_surface_event(nativeEvent);
> + if (mir_surface_event_get_attribute(surfaceEvent) == mir_surface_attrib_focus) {
> + ubuntuEvent->window->handleSurfaceFocusChange(mir_surface_event_get_attribute_value(surfaceEvent) ==
> + mir_surface_focused);
> }
> break;
> - case ORIENTATION_WEVENT_TYPE:
> - dispatchOrientationEvent(ubuntuEvent->window->window(), nativeEvent);
> + }
> + case mir_event_type_orientation:
> + dispatchOrientationEvent(ubuntuEvent->window->window(), mir_event_get_orientation_event(nativeEvent));
> break;
> default:
> - DLOG("unhandled event type %d", nativeEvent->type);
> + DLOG("unhandled event type: %d", static_cast<int>(mir_event_get_type(nativeEvent)));
> }
> }
>
> -void UbuntuInput::postEvent(UbuntuWindow* platformWindow, const void* event)
> +void UbuntuInput::postEvent(UbuntuWindow *platformWindow, const MirEvent *event)
> {
> QWindow *window = platformWindow->window();
>
> QCoreApplication::postEvent(this, new UbuntuEvent(
> - platformWindow, reinterpret_cast<const WindowEvent*>(event), mEventType));
> + platformWindow, event, mEventType));
>
> if ((window->flags() && Qt::WindowTransparentForInput) && window->parent()) {
> QCoreApplication::postEvent(this, new UbuntuEvent(
> static_cast<UbuntuWindow*>(platformWindow->QPlatformWindow::parent()),
> - reinterpret_cast<const WindowEvent*>(event), mEventType));
> - }
> -}
> -
> -void UbuntuInput::dispatchMotionEvent(QWindow* window, const void* ev)
> -{
> - const WindowEvent* event = reinterpret_cast<const WindowEvent*>(ev);
> -
> - #if (LOG_EVENTS != 0)
> - // Motion event logging.
> - LOG("MOTION device_id:%d source_id:%d action:%d flags:%d meta_state:%d edge_flags:%d "
> - "button_state:%d x_offset:%.2f y_offset:%.2f x_precision:%.2f y_precision:%.2f "
> - "down_time:%lld event_time:%lld pointer_count:%d {", event->motion.device_id,
> - event->motion.source_id, event->motion.action,
> - event->motion.flags, event->motion.meta_state,
> - event->motion.edge_flags, event->motion.button_state,
> - event->motion.x_offset, event->motion.y_offset,
> - event->motion.x_precision, event->motion.y_precision,
> - event->motion.down_time, event->motion.event_time,
> - event->motion.pointer_count);
> - for (size_t i = 0; i < event->motion.pointer_count; i++) {
> - LOG(" id:%d x:%.2f y:%.2f rx:%.2f ry:%.2f maj:%.2f min:%.2f sz:%.2f press:%.2f",
> - event->motion.pointer_coordinates[i].id,
> - event->motion.pointer_coordinates[i].x,
> - event->motion.pointer_coordinates[i].y,
> - event->motion.pointer_coordinates[i].raw_x,
> - event->motion.pointer_coordinates[i].raw_y,
> - event->motion.pointer_coordinates[i].touch_major,
> - event->motion.pointer_coordinates[i].touch_minor,
> - event->motion.pointer_coordinates[i].size,
> - event->motion.pointer_coordinates[i].pressure
> - // event->motion.pointer_coordinates[i].orientation -> Always 0.0.
> - );
> - }
> - LOG("}");
> - #endif
> + event, mEventType));
> + }
> +}
> +
> +void UbuntuInput::dispatchInputEvent(QWindow *window, const MirInputEvent *ev)
> +{
> + switch (mir_input_event_get_type(ev))
> + {
> + case mir_input_event_type_key:
> + dispatchKeyEvent(window, ev);
> + break;
> + case mir_input_event_type_touch:
> + dispatchTouchEvent(window, ev);
> + break;
> + case mir_input_event_type_pointer:
> + dispatchPointerEvent(window, ev);
> + break;
> + default:
> + break;
> + }
> +}
> +
> +void UbuntuInput::dispatchTouchEvent(QWindow *window, const MirInputEvent *ev)
> +{
> + const MirTouchInputEvent *tev = mir_input_event_get_touch_input_event(ev);
>
> // FIXME(loicm) Max pressure is device specific. That one is for the Samsung Galaxy Nexus. That
> // needs to be fixed as soon as the compat input lib adds query support.
> @@ -291,62 +286,39 @@
>
> // TODO: Is it worth setting the Qt::TouchPointStationary ones? Currently they are left
> // as Qt::TouchPointMoved
> - const int kPointerCount = event->motion.pointer_count;
> - for (int i = 0; i < kPointerCount; ++i) {
> + const unsigned int kPointerCount = mir_touch_input_event_get_touch_count(tev);
> + for (unsigned int i = 0; i < kPointerCount; ++i) {
> QWindowSystemInterface::TouchPoint touchPoint;
>
> - const float kX = event->motion.pointer_coordinates[i].raw_x + kWindowGeometry.x();
> - const float kY = event->motion.pointer_coordinates[i].raw_y + kWindowGeometry.y(); // see bug lp:1346633 workaround comments elsewhere
> - const float kW = event->motion.pointer_coordinates[i].touch_major;
> - const float kH = event->motion.pointer_coordinates[i].touch_minor;
> - const float kP = event->motion.pointer_coordinates[i].pressure;
> - touchPoint.id = event->motion.pointer_coordinates[i].id;
> + const float kX = mir_touch_input_event_get_touch_axis_value(tev, i, mir_touch_input_axis_x) + kWindowGeometry.x();
> + const float kY = mir_touch_input_event_get_touch_axis_value(tev, i, mir_touch_input_axis_y) + kWindowGeometry.y(); // see bug lp:1346633 workaround comments elsewhere
> + const float kW = mir_touch_input_event_get_touch_axis_value(tev, i, mir_touch_input_axis_touch_major);
> + const float kH = mir_touch_input_event_get_touch_axis_value(tev, i, mir_touch_input_axis_touch_minor);
> + const float kP = mir_touch_input_event_get_touch_axis_value(tev, i, mir_touch_input_axis_pressure);
> + touchPoint.id = mir_touch_input_event_get_touch_id(tev, i);
> touchPoint.normalPosition = QPointF(kX / kWindowGeometry.width(), kY / kWindowGeometry.height());
> touchPoint.area = QRectF(kX - (kW / 2.0), kY - (kH / 2.0), kW, kH);
> touchPoint.pressure = kP / kMaxPressure;
> - touchPoint.state = Qt::TouchPointMoved;
> +
> + MirTouchInputEventTouchAction touch_action = mir_touch_input_event_get_touch_action(tev, i);
> + switch (touch_action)
> + {
> + case mir_touch_input_event_action_down:
> + touchPoint.state = Qt::TouchPointPressed;
> + break;
> + case mir_touch_input_event_action_up:
> + touchPoint.state = Qt::TouchPointReleased;
> + break;
> + case mir_touch_input_event_action_change:
> + default:
> + touchPoint.state = Qt::TouchPointMoved;
> + }
>
> touchPoints.append(touchPoint);
> }
>
> - switch (event->motion.action & U_MOTION_ACTION_MASK) {
> - case U_MOTION_ACTION_MOVE:
> - // No extra work needed.
> - break;
> -
> - case U_MOTION_ACTION_DOWN:
> - touchPoints[0].state = Qt::TouchPointPressed;
> - break;
> -
> - case U_MOTION_ACTION_UP:
> - touchPoints[0].state = Qt::TouchPointReleased;
> - break;
> -
> - case U_MOTION_ACTION_POINTER_DOWN: {
> - const int index = (event->motion.action & U_MOTION_ACTION_POINTER_INDEX_MASK) >>
> - U_MOTION_ACTION_POINTER_INDEX_SHIFT;
> - touchPoints[index].state = Qt::TouchPointPressed;
> - break;
> - }
> -
> - case U_MOTION_ACTION_CANCEL:
> - case U_MOTION_ACTION_POINTER_UP: {
> - const int index = (event->motion.action & U_MOTION_ACTION_POINTER_INDEX_MASK) >>
> - U_MOTION_ACTION_POINTER_INDEX_SHIFT;
> - touchPoints[index].state = Qt::TouchPointReleased;
> - break;
> - }
> -
> - case U_MOTION_ACTION_OUTSIDE:
> - case U_MOTION_ACTION_HOVER_MOVE:
> - case U_MOTION_ACTION_SCROLL:
> - case U_MOTION_ACTION_HOVER_ENTER:
> - case U_MOTION_ACTION_HOVER_EXIT:
> - default:
> - DLOG("unhandled motion event action %d", event->motion.action & U_MOTION_ACTION_MASK);
> - }
> -
> - QWindowSystemInterface::handleTouchEvent(window, event->motion.event_time / 1000000,
> + ulong timestamp = mir_input_event_get_event_time(ev) / 1000000;
> + QWindowSystemInterface::handleTouchEvent(window, timestamp,
> mTouchDevice, touchPoints);
> }
>
> @@ -368,49 +340,48 @@
> return toupper(sym);
> }
>
> -void UbuntuInput::dispatchKeyEvent(QWindow* window, const void* ev)
> -{
> - const WindowEvent* event = reinterpret_cast<const WindowEvent*>(ev);
> -
> - #if (LOG_EVENTS != 0)
> - // Key event logging.
> - LOG("KEY device_id:%d source_id:%d action:%d flags:%d meta_state:%d key_code:%d "
> - "scan_code:%d repeat_count:%d down_time:%lld event_time:%lld is_system_key:%d",
> - event->key.device_id, event->key.source_id,
> - event->key.action, event->key.flags, event->key.meta_state,
> - event->key.key_code, event->key.scan_code,
> - event->key.repeat_count, event->key.down_time,
> - event->key.event_time, event->key.is_system_key);
> - #endif
> -
> - ulong timestamp = event->key.event_time / 1000000;
> - xkb_keysym_t xk_sym = (xkb_keysym_t)event->key.key_code;
> +namespace
> +{
> +Qt::KeyboardModifiers qt_modifiers_from_mir(MirInputEventModifiers modifiers)
> +{
> + Qt::KeyboardModifiers q_modifiers = Qt::NoModifier;
> + if (modifiers & mir_input_event_modifier_shift) {
> + q_modifiers |= Qt::ShiftModifier;
> + }
> + if (modifiers & mir_input_event_modifier_ctrl) {
> + q_modifiers |= Qt::ControlModifier;
> + }
> + if (modifiers & mir_input_event_modifier_alt) {
> + q_modifiers |= Qt::AltModifier;
> + }
> + if (modifiers & mir_input_event_modifier_meta) {
> + q_modifiers |= Qt::MetaModifier;
> + }
> + return q_modifiers;
> +}
> +}
> +
> +void UbuntuInput::dispatchKeyEvent(QWindow *window, const MirInputEvent *event)
> +{
> + const MirKeyInputEvent *key_event = mir_input_event_get_key_input_event(event);
> +
> + ulong timestamp = mir_input_event_get_event_time(event) / 1000000;
> + xkb_keysym_t xk_sym = mir_key_input_event_get_key_code(key_event);
>
> // Key modifier and unicode index mapping.
> - const int kMetaState = event->key.meta_state;
> - Qt::KeyboardModifiers modifiers = Qt::NoModifier;
> - if (kMetaState & U_KEY_MODIFIER_SHIFT) {
> - modifiers |= Qt::ShiftModifier;
> - }
> - if (kMetaState & U_KEY_MODIFIER_CTRL) {
> - modifiers |= Qt::ControlModifier;
> - }
> - if (kMetaState & U_KEY_MODIFIER_ALT) {
> - modifiers |= Qt::AltModifier;
> - }
> - if (kMetaState & U_KEY_MODIFIER_META) {
> - modifiers |= Qt::MetaModifier;
> - }
> + auto modifiers = qt_modifiers_from_mir(mir_key_input_event_get_modifiers(key_event));
>
> - QEvent::Type keyType = event->key.action == U_KEY_ACTION_DOWN ? QEvent::KeyPress : QEvent::KeyRelease;
> + MirKeyInputEventAction action = mir_key_input_event_get_action(key_event);
> + QEvent::Type keyType = action == mir_key_input_event_action_up
> + ? QEvent::KeyRelease : QEvent::KeyPress;
>
> char s[2];
> int sym = translateKeysym(xk_sym, s, sizeof(s));
> QString text = QString::fromLatin1(s);
>
> - bool is_auto_rep = event->key.repeat_count > 0;
> + bool is_auto_rep = action == mir_key_input_event_action_repeat;
>
> - QPlatformInputContext* context = QGuiApplicationPrivate::platformIntegration()->inputContext();
> + QPlatformInputContext *context = QGuiApplicationPrivate::platformIntegration()->inputContext();
> if (context) {
> QKeyEvent qKeyEvent(keyType, sym, modifiers, text, is_auto_rep);
> qKeyEvent.setTimestamp(timestamp);
> @@ -423,20 +394,53 @@
> QWindowSystemInterface::handleKeyEvent(window, timestamp, keyType, sym, modifiers, text, is_auto_rep);
> }
>
> +namespace
> +{
> +Qt::MouseButtons extract_buttons(const MirPointerInputEvent *pev)
> +{
> + Qt::MouseButtons buttons = Qt::NoButton;
> + if (mir_pointer_input_event_get_button_state(pev, mir_pointer_input_button_primary))
> + buttons |= Qt::LeftButton;
> + if (mir_pointer_input_event_get_button_state(pev, mir_pointer_input_button_secondary))
> + buttons |= Qt::RightButton;
> + if (mir_pointer_input_event_get_button_state(pev, mir_pointer_input_button_tertiary))
> + buttons |= Qt::MidButton;
> +
> + // TODO: Should mir back and forward buttons exist?
> + // should they be Qt::X button 1 and 2?
> + return buttons;
> +}
> +}
> +
> +void UbuntuInput::dispatchPointerEvent(QWindow *window, const MirInputEvent *ev)
> +{
> + auto timestamp = mir_input_event_get_event_time(ev) / 1000000;
> +
> + auto pev = mir_input_event_get_pointer_input_event(ev);
> + auto modifiers = qt_modifiers_from_mir(mir_pointer_input_event_get_modifiers(pev));
> + auto buttons = extract_buttons(pev);
> +
> + auto local_point = QPointF(mir_pointer_input_event_get_axis_value(pev, mir_pointer_input_axis_x),
> + mir_pointer_input_event_get_axis_value(pev, mir_pointer_input_axis_y));
> +
> + QWindowSystemInterface::handleMouseEvent(window, timestamp, local_point, local_point /* Should we omit global point instead? */,
> + buttons, modifiers);
> +}
> +
> #if (LOG_EVENTS != 0)
> -static const char* nativeOrientationDirectionToStr(const int orientation)
> +static const char* nativeOrientationDirectionToStr(MirOrientation orientation)
> {
> switch (orientation) {
> - case U_ORIENTATION_NORMAL:
> + case mir_orientation_normal:
> return "Normal";
> break;
> - case U_ORIENTATION_LEFT:
> + case mir_orientation_left:
> return "Left";
> break;
> - case U_ORIENTATION_INVERTED:
> + case mir_orientation_inverted:
> return "Inverted";
> break;
> - case U_ORIENTATION_RIGHT:
> + case mir_orientation_right:
> return "Right";
> break;
> default:
> @@ -445,13 +449,12 @@
> }
> #endif
>
> -void UbuntuInput::dispatchOrientationEvent(QWindow* window, const void* ev)
> +void UbuntuInput::dispatchOrientationEvent(QWindow *window, const MirOrientationEvent *event)
> {
> - const WindowEvent* event = reinterpret_cast<const WindowEvent*>(ev);
> -
> + MirOrientation mir_orientation = mir_orientation_event_get_direction(event);
> #if (LOG_EVENTS != 0)
> // Orientation event logging.
> - LOG("ORIENTATION direction: %s", nativeOrientationDirectionToStr(event->orientation.direction));
> + LOG("ORIENTATION direction: %s", nativeOrientationDirectionToStr(mir_orientation));
> #endif
>
> if (!window->screen()) {
> @@ -460,21 +463,21 @@
> }
>
> QOrientationReading::Orientation orientation;
> - switch (event->orientation.direction) {
> - case U_ORIENTATION_NORMAL:
> + switch (mir_orientation) {
> + case mir_orientation_normal:
> orientation = QOrientationReading::TopUp;
> break;
> - case U_ORIENTATION_LEFT:
> + case mir_orientation_left:
> orientation = QOrientationReading::LeftUp;
> break;
> - case U_ORIENTATION_INVERTED:
> + case mir_orientation_inverted:
> orientation = QOrientationReading::TopDown;
> break;
> - case U_ORIENTATION_RIGHT:
> + case mir_orientation_right:
> orientation = QOrientationReading::RightUp;
> break;
> default:
> - DLOG("No such orientation %d", event->orientation.direction);
> + DLOG("No such orientation %d", mir_orientation);
> return;
> }
>
>
> === modified file 'src/ubuntumirclient/input.h'
> --- src/ubuntumirclient/input.h 2014-08-25 15:24:02 +0000
> +++ src/ubuntumirclient/input.h 2015-02-23 19:57:37 +0000
> @@ -1,5 +1,5 @@
> /*
> - * Copyright (C) 2014 Canonical, Ltd.
> + * Copyright (C) 2014-2015 Canonical, Ltd.
> *
> * This program is free software: you can redistribute it and/or modify it under
> * the terms of the GNU Lesser General Public License version 3, as published by
> @@ -20,6 +20,8 @@
> // Qt
> #include <qpa/qwindowsysteminterface.h>
>
> +#include <mir_toolkit/mir_client_library.h>
> +
> class UbuntuClientIntegration;
> class UbuntuWindow;
>
> @@ -34,13 +36,16 @@
> // QObject methods.
> void customEvent(QEvent* event) override;
>
> - void postEvent(UbuntuWindow* window, const void* event);
> + void postEvent(UbuntuWindow* window, const MirEvent *event);
> UbuntuClientIntegration* integration() const { return mIntegration; }
>
> protected:
> - void dispatchKeyEvent(QWindow* window, const void* event);
> - void dispatchMotionEvent(QWindow* window, const void* event);
> - void dispatchOrientationEvent(QWindow* window, const void* event);
> + void dispatchKeyEvent(QWindow *window, const MirInputEvent *event);
> + void dispatchPointerEvent(QWindow *window, const MirInputEvent *event);
> + void dispatchTouchEvent(QWindow *window, const MirInputEvent *event);
> + void dispatchInputEvent(QWindow *window, const MirInputEvent *event);
> +
> + void dispatchOrientationEvent(QWindow* window, const MirOrientationEvent *event);
>
> private:
> UbuntuClientIntegration* mIntegration;
>
> === modified file 'src/ubuntumirclient/integration.cpp'
> --- src/ubuntumirclient/integration.cpp 2014-10-01 17:20:40 +0000
> +++ src/ubuntumirclient/integration.cpp 2015-02-23 19:57:37 +0000
> @@ -1,5 +1,5 @@
> /*
> - * Copyright (C) 2014 Canonical, Ltd.
> + * Copyright (C) 2014-2015 Canonical, Ltd.
> *
> * This program is free software: you can redistribute it and/or modify it under
> * the terms of the GNU Lesser General Public License version 3, as published by
> @@ -156,7 +156,7 @@
> QPlatformWindow* UbuntuClientIntegration::createPlatformWindow(QWindow* window)
> {
> QPlatformWindow* platformWindow = new UbuntuWindow(
> - window, mClipboard, static_cast<UbuntuScreen*>(mScreen), mInput, mInstance);
> + window, mClipboard, static_cast<UbuntuScreen*>(mScreen), mInput, u_application_instance_get_mir_connection(mInstance));
> platformWindow->requestActivateWindow();
> return platformWindow;
> }
>
> === modified file 'src/ubuntumirclient/ubuntumirclient.pro'
> --- src/ubuntumirclient/ubuntumirclient.pro 2014-10-01 17:20:40 +0000
> +++ src/ubuntumirclient/ubuntumirclient.pro 2015-02-23 19:57:37 +0000
> @@ -12,9 +12,7 @@
> QMAKE_LFLAGS += -std=c++11 -Wl,-no-undefined
>
> CONFIG += link_pkgconfig
> -PKGCONFIG += egl
> -
> -LIBS += -lubuntu_application_api
> +PKGCONFIG += egl mirclient ubuntu-platform-api
>
> SOURCES = \
> backingstore.cpp \
>
> === modified file 'src/ubuntumirclient/window.cpp'
> --- src/ubuntumirclient/window.cpp 2014-10-01 17:20:40 +0000
> +++ src/ubuntumirclient/window.cpp 2015-02-23 19:57:37 +0000
> @@ -1,5 +1,5 @@
> /*
> - * Copyright (C) 2014 Canonical, Ltd.
> + * Copyright (C) 2014-2015 Canonical, Ltd.
> *
> * This program is free software: you can redistribute it and/or modify it under
> * the terms of the GNU Lesser General Public License version 3, as published by
> @@ -37,6 +37,53 @@
>
> #define IS_OPAQUE_FLAG 1
>
> +namespace
> +{
> +MirSurfaceState qtWindowStateToMirSurfaceState(Qt::WindowState state)
> +{
> + switch (state) {
> + case Qt::WindowNoState:
> + return mir_surface_state_restored;
> +
> + case Qt::WindowFullScreen:
> + return mir_surface_state_fullscreen;
> +
> + case Qt::WindowMaximized:
> + return mir_surface_state_maximized;
> +
> + case Qt::WindowMinimized:
> + return mir_surface_state_minimized;
> +
> + default:
> + LOG("Unexpected Qt::WindowState: %d", state);
> + return mir_surface_state_restored;
> + }
> +}
> +
> +#if !defined(QT_NO_DEBUG)
> +const char *qtWindowStateToStr(Qt::WindowState state)
> +{
> + switch (state) {
> + case Qt::WindowNoState:
> + return "NoState";
> +
> + case Qt::WindowFullScreen:
> + return "FullScreen";
> +
> + case Qt::WindowMaximized:
> + return "Maximized";
> +
> + case Qt::WindowMinimized:
> + return "Minimized";
> +
> + default:
> + return "!?";
> + }
> +}
> +#endif
> +
> +} // anonymous namespace
> +
> class UbuntuWindowPrivate
> {
> public:
> @@ -48,26 +95,36 @@
> EGLSurface eglSurface;
> WId id;
> UbuntuInput* input;
> - UAUiWindow* window;
> Qt::WindowState state;
> QRect geometry;
> - UApplicationInstance* uaInstance;
> - UAUiWindowProperties* wProps;
> + MirConnection *connection;
> + MirSurface* surface;
> QSize bufferSize;
> QSize targetBufferSize;
> QMutex mutex;
> QSharedPointer<UbuntuClipboard> clipboard;
> };
>
> -static void eventCallback(void* context, const WindowEvent* event)
> +static void eventCallback(MirSurface* surface, const MirEvent *event, void* context)
> {
> + (void) surface;
> DASSERT(context != NULL);
> UbuntuWindow* platformWindow = static_cast<UbuntuWindow*>(context);
> platformWindow->priv()->input->postEvent(platformWindow, event);
> }
>
> +static void surfaceCreateCallback(MirSurface* surface, void* context)
> +{
> + DASSERT(context != NULL);
> + UbuntuWindow* platformWindow = static_cast<UbuntuWindow*>(context);
> + platformWindow->priv()->surface = surface;
> +
> + MirEventDelegate handler = {eventCallback, context};
> + mir_surface_set_event_handler(surface, &handler);
> +}
> +
> UbuntuWindow::UbuntuWindow(QWindow* w, QSharedPointer<UbuntuClipboard> clipboard, UbuntuScreen* screen,
> - UbuntuInput* input, UApplicationInstance* instance)
> + UbuntuInput* input, MirConnection* connection)
> : QObject(nullptr), QPlatformWindow(w)
> {
> DASSERT(screen != NULL);
> @@ -77,7 +134,7 @@
> d->eglSurface = EGL_NO_SURFACE;
> d->input = input;
> d->state = window()->windowState();
> - d->uaInstance = instance;
> + d->connection = connection;
> d->clipboard = clipboard;
>
> static int id = 1;
> @@ -94,7 +151,9 @@
> {
> DLOG("UbuntuWindow::~UbuntuWindow");
> d->destroyEGLSurface();
> - ua_ui_window_destroy(d->window);
> +
> + mir_surface_release_sync(d->surface);
> +
> delete d;
> }
>
> @@ -136,6 +195,21 @@
> return gridUnit * 3 + qFloor(densityPixelRatio) * 2;
> }
>
> +namespace
> +{
> +static MirPixelFormat
> +mir_choose_default_pixel_format(MirConnection *connection)
> +{
> + MirPixelFormat format[mir_pixel_formats];
> + unsigned int nformats;
> +
> + mir_connection_get_available_surface_formats(connection,
> + format, mir_pixel_formats, &nformats);
> +
> + return format[0];
> +}
> +}
> +
> void UbuntuWindow::createWindow()
> {
> DLOG("UbuntuWindow::createWindow (this=%p)", this);
> @@ -154,12 +228,12 @@
> const QByteArray title = (!window()->title().isNull()) ? window()->title().toUtf8() : "Window 1"; // legacy title
> const int panelHeight = d->panelHeight();
>
> - #if !defined(QT_NO_DEBUG)
> +#if !defined(QT_NO_DEBUG)
> LOG("panelHeight: '%d'", panelHeight);
> LOG("role: '%d'", role);
> LOG("flags: '%s'", (flags & static_cast<uint>(1)) ? "Opaque" : "NotOpaque");
> LOG("title: '%s'", title.constData());
> - #endif
> +#endif
>
> // Get surface geometry.
> QRect geometry;
> @@ -187,32 +261,39 @@
> DLOG("[ubuntumirclient QPA] creating surface at (%d, %d) with size (%d, %d) with title '%s'\n",
> geometry.x(), geometry.y(), geometry.width(), geometry.height(), title.data());
>
> - // Setup platform window creation properties
> - d->wProps = ua_ui_window_properties_new_for_normal_window();
> - ua_ui_window_properties_set_titlen(d->wProps, title.data(), title.size());
> - ua_ui_window_properties_set_role(d->wProps, static_cast<UAUiWindowRole>(role));
> - ua_ui_window_properties_set_event_cb_and_ctx(d->wProps, &eventCallback, this);
> - ua_ui_window_properties_set_dimensions(d->wProps, geometry.width(), geometry.height());
> + MirSurfaceSpec *spec;
> + if (role == U_ON_SCREEN_KEYBOARD_ROLE)
> + {
> + spec = mir_connection_create_spec_for_input_method(d->connection, geometry.width(),
> + geometry.height(), mir_choose_default_pixel_format(d->connection));
> + }
> + else
> + {
> + spec = mir_connection_create_spec_for_normal_surface(d->connection, geometry.width(),
> + geometry.height(), mir_choose_default_pixel_format(d->connection));
> + }
> + mir_surface_spec_set_name(spec, title.data());
>
> // Create platform window
> - d->window = ua_ui_window_new_for_application_with_properties(d->uaInstance, d->wProps);
> -
> - if (geometry.x() != 0 || geometry.y() != 0)
> - ua_ui_window_move(d->window, geometry.x(), geometry.y());
> -
> - DASSERT(d->window != NULL);
> - d->createEGLSurface(ua_ui_window_get_native_type(d->window));
> + mir_wait_for(mir_surface_create(spec, surfaceCreateCallback, this));
> + mir_surface_spec_release(spec);
> +
> + DASSERT(d->surface != NULL);
> + d->createEGLSurface((EGLNativeWindowType)mir_surface_get_egl_native_window(d->surface));
> +
> if (d->state == Qt::WindowFullScreen) {
> - ua_ui_window_request_fullscreen(d->window);
> + // TODO: We could set this on creation once surface spec supports it (mps already up)
> + mir_wait_for(mir_surface_set_state(d->surface, mir_surface_state_fullscreen));
> }
>
> // Window manager can give us a final size different from what we asked for
> // so let's check what we ended up getting
> {
> - uint32_t width, height;
> - ua_ui_window_get_size(d->window, &width, &height);
> - geometry.setWidth(width);
> - geometry.setHeight(height);
> + MirSurfaceParameters parameters;
> + mir_surface_get_parameters(d->surface, ¶meters);
> +
> + geometry.setWidth(parameters.width);
> + geometry.setHeight(parameters.height);
> }
>
> DLOG("[ubuntumirclient QPA] created surface has size (%d, %d)",
> @@ -228,13 +309,8 @@
>
> void UbuntuWindow::moveResize(const QRect& rect)
> {
> - fprintf(stderr, "\nQUbuntuWindow::moveResize (this=%p, x=%d, y=%d, w=%d, h=%d)\n", this,
> - rect.x(), rect.y(), rect.width(), rect.height());
> - LOG("UbuntuWindow::moveResize(width=%d, height=%d)", rect.width(), rect.height());
> - ua_ui_window_move(d->window, rect.x(), rect.y());
> - ua_ui_window_resize(d->window, rect.width(), rect.height());
> - QWindowSystemInterface::handleGeometryChange(window(), rect);
> - QPlatformWindow::setGeometry(rect);
> + (void) rect;
> + // TODO: Not yet supported by mir.
> }
>
> void UbuntuWindow::handleSurfaceResize(int width, int height)
> @@ -313,34 +389,14 @@
> void UbuntuWindow::setWindowState(Qt::WindowState state)
> {
> QMutexLocker(&d->mutex);
> + DLOG("UbuntuWindow::setWindowState (this=%p, %s)", this, qtWindowStateToStr(state));
> +
> if (state == d->state)
> return;
>
> - switch (state) {
> - case Qt::WindowNoState:
> - DLOG("setting window state: 'NoState'");
> - ua_ui_window_request_state(d->window, U_RESTORED_STATE);
> - d->state = Qt::WindowNoState;
> - break;
> - case Qt::WindowFullScreen:
> - DLOG("setting window state: 'FullScreen'");
> - ua_ui_window_request_state(d->window, U_FULLSCREEN_STATE);
> - d->state = Qt::WindowFullScreen;
> - break;
> - case Qt::WindowMaximized:
> - DLOG("setting window state: 'Maximized'");
> - ua_ui_window_request_state(d->window, U_MAXIMIZED_STATE);
> - d->state = Qt::WindowMaximized;
> - break;
> - case Qt::WindowMinimized:
> - DLOG("setting window state: 'Minimized'");
> - ua_ui_window_request_state(d->window, U_MINIMIZED_STATE);
> - d->state = Qt::WindowMinimized;
> - break;
> - default:
> - DLOG("Unexpected window state");
> - break;
> - }
> + // TODO: Perhaps we should check if the states are applied?
> + mir_wait_for(mir_surface_set_state(d->surface, qtWindowStateToMirSurfaceState(state)));
> + d->state = state;
> }
>
> void UbuntuWindow::setGeometry(const QRect& rect)
> @@ -362,15 +418,19 @@
>
> void UbuntuWindow::setVisible(bool visible)
> {
> - DLOG("UbuntuWindow::setVisible (this=%p, visible=%s)", this, visible ? "true" : "false");
> -
> - if (visible) {
> - ua_ui_window_show(d->window);
> - QWindowSystemInterface::handleExposeEvent(window(), QRect());
> - QWindowSystemInterface::flushWindowSystemEvents();
> - } else {
> - ua_ui_window_hide(d->window);
> - }
> + QMutexLocker(&d->mutex);
> + DLOG("UbuntuWindow::setVisible (this=%p, visible=%s)", this, visible ? "true" : "false");
> +
> + if (visible) {
> + mir_wait_for(mir_surface_set_state(d->surface, qtWindowStateToMirSurfaceState(d->state)));
> +
> + QWindowSystemInterface::handleExposeEvent(window(), QRect());
> + QWindowSystemInterface::flushWindowSystemEvents();
> + } else {
> + // TODO: Use the new mir_surface_state_hidden state instead of mir_surface_state_minimized.
> + // Will have to change qtmir and unity8 for that.
> + mir_wait_for(mir_surface_set_state(d->surface, mir_surface_state_minimized));
> + }
> }
>
> void* UbuntuWindow::eglSurface() const
>
> === modified file 'src/ubuntumirclient/window.h'
> --- src/ubuntumirclient/window.h 2014-09-22 17:29:40 +0000
> +++ src/ubuntumirclient/window.h 2015-02-23 19:57:37 +0000
> @@ -1,5 +1,5 @@
> /*
> - * Copyright (C) 2014 Canonical, Ltd.
> + * Copyright (C) 2014-2015 Canonical, Ltd.
> *
> * This program is free software: you can redistribute it and/or modify it under
> * the terms of the GNU Lesser General Public License version 3, as published by
> @@ -20,6 +20,8 @@
> #include <qpa/qplatformwindow.h>
> #include <QSharedPointer>
>
> +#include <mir_toolkit/mir_client_library.h>
> +
> class UbuntuClipboard;
> class UbuntuInput;
> class UbuntuScreen;
> @@ -29,8 +31,8 @@
> {
> Q_OBJECT
> public:
> - UbuntuWindow(QWindow* w, QSharedPointer<UbuntuClipboard> clipboard, UbuntuScreen* screen,
> - UbuntuInput* input, void* instance);
> + UbuntuWindow(QWindow *w, QSharedPointer<UbuntuClipboard> clipboard, UbuntuScreen *screen,
> + UbuntuInput *input, MirConnection *mir_connection);
> virtual ~UbuntuWindow();
>
> // QPlatformWindow methods.
>
--
https://code.launchpad.net/~mir-team/qtubuntu/port-to-mirclient/+merge/245164
Your team Ubuntu Phablet Team is subscribed to branch lp:qtubuntu.
More information about the Ubuntu-reviews
mailing list