~ci-train-bot/qtubuntu/qtubuntu-ubuntu-xenial-landing-057

« back to all changes in this revision

Viewing changes to src/ubuntumirclient/input.cpp

  • Committer: CI Train Bot
  • Author(s): Gerry Boland, Nick Dedekind
  • Date: 2016-02-05 11:55:35 UTC
  • mfrom: (310.1.4 qtubuntu-clean)
  • Revision ID: ci-train-bot@canonical.com-20160205115535-99xvn26a75cr399q
React to formFactor and window flag changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
176
176
        return "mir_event_type_close_surface";
177
177
    case mir_event_type_input:
178
178
        return "mir_event_type_input";
 
179
    case mir_event_type_surface_output:
 
180
        return "mir_event_type_surface_output";
179
181
    default:
180
182
        return "invalid";
181
183
    }
211
213
        break;
212
214
    case mir_event_type_resize:
213
215
    {
214
 
        Q_ASSERT(ubuntuEvent->window->screen() == mIntegration->screen());
215
 
 
216
216
        auto resizeEvent = mir_event_get_resize_event(nativeEvent);
217
217
 
218
 
        mIntegration->screen()->handleWindowSurfaceResize(
219
 
                mir_resize_event_get_width(resizeEvent),
220
 
                mir_resize_event_get_height(resizeEvent));
 
218
        // Enable workaround for Screen rotation
 
219
        auto screen = static_cast<UbuntuScreen*>(ubuntuEvent->window->screen());
 
220
        if (screen) {
 
221
            screen->handleWindowSurfaceResize(
 
222
                    mir_resize_event_get_width(resizeEvent),
 
223
                    mir_resize_event_get_height(resizeEvent));
 
224
        }
221
225
 
222
226
        ubuntuEvent->window->handleSurfaceResized(mir_resize_event_get_width(resizeEvent),
223
227
            mir_resize_event_get_height(resizeEvent));
224
228
        break;
225
229
    }
226
230
    case mir_event_type_surface:
227
 
    {
228
 
        auto surfaceEvent = mir_event_get_surface_event(nativeEvent);
229
 
        if (mir_surface_event_get_attribute(surfaceEvent) == mir_surface_attrib_focus) {
230
 
            const bool focused = mir_surface_event_get_attribute_value(surfaceEvent) == mir_surface_focused;
231
 
            // Mir may have sent a pair of focus lost/gained events, so we need to "peek" into the queue
232
 
            // so that we don't deactivate windows prematurely.
233
 
            if (focused) {
234
 
                mPendingFocusGainedEvents--;
235
 
                ubuntuEvent->window->handleSurfaceFocused();
236
 
                QWindowSystemInterface::handleWindowActivated(ubuntuEvent->window->window(), Qt::ActiveWindowFocusReason);
237
 
 
238
 
                // NB: Since processing of system events is queued, never check qGuiApp->applicationState()
239
 
                //     as it might be outdated. Always call handleApplicationStateChanged() with the latest
240
 
                //     state regardless.
241
 
                QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationActive);
242
 
 
243
 
            } else if(!mPendingFocusGainedEvents) {
244
 
                qCDebug(ubuntumirclient, "No windows have focus");
245
 
                QWindowSystemInterface::handleWindowActivated(nullptr, Qt::ActiveWindowFocusReason);
246
 
                QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationInactive);
247
 
            }
248
 
        }
249
 
        break;
250
 
    }
 
231
        handleSurfaceEvent(ubuntuEvent->window, mir_event_get_surface_event(nativeEvent));
 
232
        break;
 
233
    case mir_event_type_surface_output:
 
234
        handleSurfaceOutputEvent(ubuntuEvent->window, mir_event_get_surface_output_event(nativeEvent));
 
235
        break;
251
236
    case mir_event_type_orientation:
252
237
        dispatchOrientationEvent(ubuntuEvent->window->window(), mir_event_get_orientation_event(nativeEvent));
253
238
        break;
551
536
                                new OrientationChangeEvent(OrientationChangeEvent::mType, orientation));
552
537
}
553
538
 
 
539
void UbuntuInput::handleSurfaceEvent(const QPointer<UbuntuWindow> &window, const MirSurfaceEvent *event)
 
540
{
 
541
    auto surfaceEventAttribute = mir_surface_event_get_attribute(event);
 
542
 
 
543
    switch (surfaceEventAttribute) {
 
544
    case mir_surface_attrib_focus: {
 
545
        const bool focused = mir_surface_event_get_attribute_value(event) == mir_surface_focused;
 
546
        // Mir may have sent a pair of focus lost/gained events, so we need to "peek" into the queue
 
547
        // so that we don't deactivate windows prematurely.
 
548
        if (focused) {
 
549
            mPendingFocusGainedEvents--;
 
550
            window->handleSurfaceFocused();
 
551
            QWindowSystemInterface::handleWindowActivated(window->window(), Qt::ActiveWindowFocusReason);
 
552
            if (qGuiApp->applicationState() == Qt::ApplicationInactive) {
 
553
                QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationActive);
 
554
            }
 
555
        } else if(!mPendingFocusGainedEvents) {
 
556
            qCDebug(ubuntumirclient, "No windows have focus");
 
557
            QWindowSystemInterface::handleWindowActivated(nullptr, Qt::ActiveWindowFocusReason);
 
558
            if (qGuiApp->applicationState() == Qt::ApplicationActive) {
 
559
                QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationInactive);
 
560
            }
 
561
        }
 
562
        break;
 
563
    }
 
564
    case mir_surface_attrib_visibility:
 
565
    // Remaining attributes are ones client sets for server, and server should not override them
 
566
    case mir_surface_attrib_type:
 
567
    case mir_surface_attrib_state:
 
568
    case mir_surface_attrib_swapinterval:
 
569
    case mir_surface_attrib_dpi:
 
570
    case mir_surface_attrib_preferred_orientation:
 
571
    case mir_surface_attribs:
 
572
        break;
 
573
    }
 
574
}
 
575
 
 
576
void UbuntuInput::handleSurfaceOutputEvent(const QPointer<UbuntuWindow> &window, const MirSurfaceOutputEvent *event)
 
577
{
 
578
    const uint32_t outputId = mir_surface_output_event_get_output_id(event);
 
579
    const MirFormFactor formFactor = mir_surface_output_event_get_form_factor(event);
 
580
 
 
581
    const auto screenObserver = mIntegration->screenObserver();
 
582
    UbuntuScreen *screen = screenObserver->findScreenWithId(outputId);
 
583
    if (!screen) {
 
584
        qWarning() << "Mir notified window" << window->window() << "on an unknown screen with id" << outputId;
 
585
        return;
 
586
    }
 
587
 
 
588
    screenObserver->handleScreenPropertiesChange(screen, formFactor);
 
589
    window->handleScreenPropertiesChange(formFactor);
 
590
 
 
591
    if (window->screen() != screen) {
 
592
        QWindowSystemInterface::handleWindowScreenChanged(window->window(), screen->screen());
 
593
    }
 
594
}