Qt5: use Nitpicker instead of liquid_fb

Fixes #1072.
This commit is contained in:
Christian Prochaska 2014-02-20 16:32:58 +01:00 committed by Christian Helmuth
parent 4c45f3451c
commit 66957c8113
8 changed files with 699 additions and 504 deletions

View File

@ -1,3 +1,11 @@
IMPORT_QT5_INC=$(call select_from_repositories,lib/import/import-qt5.inc)
include $(IMPORT_QT5_INC)
# include dirs needed for 'qnitpickerplatformwindow.h', which is used by
# the qt5_qnitpickerviewwidget library
INC_DIR += $(REP_DIR)/src/lib/qt5/qtbase/src/plugins/platforms/nitpicker \
$(REP_DIR)/contrib/$(QT5)/qtbase/src/platformsupport/input/evdevkeyboard \
$(REP_DIR)/contrib/$(QT5)/qtbase/include/QtGui/$(QT_VERSION)/QtGui \

View File

@ -7,4 +7,5 @@ HEADERS += qnitpickerviewwidget.h
vpath %.h $(REP_DIR)/include/qt5/qnitpickerviewwidget
vpath %.cpp $(REP_DIR)/src/lib/qt5/qnitpickerviewwidget
LIBS += qt5_gui qt5_widgets qt5_core libc
LIBS += qt5_gui qt5_widgets qt5_core libc qt5_qpa_nitpicker

View File

@ -12,6 +12,7 @@ SRC_CC = qgenericunixeventdispatcher.cpp \
SRC_CC += main.cpp \
qnitpickerglcontext.cpp \
qnitpickerintegration.cpp \
qnitpickerplatformwindow.cpp \
qnitpickerwindowsurface.cpp \
moc_qnitpickerplatformwindow.cpp \
moc_qnitpickerwindowsurface.cpp \
@ -21,13 +22,10 @@ SRC_CC += main.cpp \
moc_qevdevkeyboardhandler_p.cpp
INC_DIR += $(REP_DIR)/contrib/$(QT5)/qtbase/src/platformsupport/eventdispatchers \
$(REP_DIR)/contrib/$(QT5)/qtbase/src/platformsupport/input/evdevkeyboard \
$(REP_DIR)/contrib/$(QT5)/qtbase/src/platformsupport/fontdatabases/basic \
$(REP_DIR)/contrib/$(QT5)/qtbase/src/3rdparty/harfbuzz/src \
$(REP_DIR)/src/lib/qt5/qtbase/src/plugins/platforms/nitpicker \
$(REP_DIR)/contrib/$(QT5)/qtbase/include/QtPlatformSupport/$(QT_VERSION) \
$(REP_DIR)/contrib/$(QT5)/qtbase/include/QtGui/$(QT_VERSION) \
$(REP_DIR)/contrib/$(QT5)/qtbase/include/QtGui/$(QT_VERSION)/QtGui \
$(REP_DIR)/contrib/$(QT5)/qtbase/include/QtCore/$(QT_VERSION) \
$(REP_DIR)/contrib/$(QT5)/qtbase/include/QtCore/$(QT_VERSION)/QtCore

View File

@ -14,6 +14,8 @@
#include <private/qwindowsurface_nitpicker_qws_p.h>
#endif
#include <qnitpickerplatformwindow.h>
#include <qnitpickerviewwidget/qnitpickerviewwidget.h>
@ -88,12 +90,17 @@ void QNitpickerViewWidget::paintEvent(QPaintEvent *event)
qDebug() << "global(x, y): " << mapToGlobal(QPoint(x(), y()));
qDebug() << "window =" << window();
// qDebug() << "window->geometry() =" << window()->geometry();
// qDebug() << "mapToGlobal(window->geometry().topLeft()) =" << mapToGlobal(window()->geometry().topLeft());
// qDebug() << "mapToGlobal(window->geometry().topLeft()) =" <<
mapToGlobal(window()->geometry().topLeft());
qDebug() << "window->rect().topLeft() =" << window()->rect().topLeft();
qDebug() << "mapToGlobal(window->rect().topLeft()) =" << mapToGlobal(window()->rect().topLeft());
qDebug() << "mapToGlobal(window->childrenRect().topLeft()) =" << mapToGlobal(window()->childrenRect().topLeft());
qDebug() << "mapToGlobal(window->contentsRect().topLeft()) =" << mapToGlobal(window()->contentsRect().topLeft());
qDebug() << "mapToGlobal(mask().boundingRect().bottomRight()) =" << mapToGlobal(mask().boundingRect().bottomRight());
qDebug() << "mapToGlobal(window->rect().topLeft()) =" <<
mapToGlobal(window()->rect().topLeft());
qDebug() << "mapToGlobal(window->childrenRect().topLeft()) =" <<
mapToGlobal(window()->childrenRect().topLeft());
qDebug() << "mapToGlobal(window->contentsRect().topLeft()) =" <<
mapToGlobal(window()->contentsRect().topLeft());
qDebug() << "mapToGlobal(mask().boundingRect().bottomRight()) =" <<
mapToGlobal(mask().boundingRect().bottomRight());
#endif
// QPainter painter(this);
@ -126,17 +133,27 @@ void QNitpickerViewWidget::paintEvent(QPaintEvent *event)
/* start of view = most right window start position */
// qDebug() << "parent->geometry() =" << parent->geometry();
// qDebug() << "parent->frameGeometry() =" << parent->frameGeometry();
// qDebug() << "mapToGlobal(parent->frameGeometry().topLeft()) =" << parent->mapToGlobal(parent->frameGeometry().topLeft());
qDebug() << "mapToGlobal(parent->geometry().bottomRight()) =" << parent->mapToGlobal(parent->geometry().bottomRight());
qDebug() << "mapToGlobal(parent->rect().topLeft()) =" << parent->mapToGlobal(parent->rect().topLeft());
qDebug() << "mapToGlobal(parent->rect().bottomRight()) =" << parent->mapToGlobal(parent->rect().bottomRight());
qDebug() << "mapToGlobal(parent->childrenRect().topLeft()) =" << parent->mapToGlobal(parent->childrenRect().topLeft());
qDebug() << "mapToGlobal(parent->childrenRect().bottomRight()) =" << parent->mapToGlobal(parent->childrenRect().bottomRight());
qDebug() << "mapToGlobal(parent->contentsRect().topLeft()) =" << parent->mapToGlobal(parent->contentsRect().topLeft());
qDebug() << "mapToGlobal(parent->contentsRect().bottomRight()) =" << parent->mapToGlobal(parent->contentsRect().bottomRight());
qDebug() << "parentWidget()->childAt(" << geometry().topRight() << ") = " << parentWidget()->childAt(geometry().topRight());
// qDebug() << "mapToGlobal(parent->frameGeometry().topLeft()) =" <<
parent->mapToGlobal(parent->frameGeometry().topLeft());
qDebug() << "mapToGlobal(parent->geometry().bottomRight()) =" <<
parent->mapToGlobal(parent->geometry().bottomRight());
qDebug() << "mapToGlobal(parent->rect().topLeft()) =" <<
parent->mapToGlobal(parent->rect().topLeft());
qDebug() << "mapToGlobal(parent->rect().bottomRight()) =" <<
parent->mapToGlobal(parent->rect().bottomRight());
qDebug() << "mapToGlobal(parent->childrenRect().topLeft()) =" <<
parent->mapToGlobal(parent->childrenRect().topLeft());
qDebug() << "mapToGlobal(parent->childrenRect().bottomRight()) =" <<
parent->mapToGlobal(parent->childrenRect().bottomRight());
qDebug() << "mapToGlobal(parent->contentsRect().topLeft()) =" <<
parent->mapToGlobal(parent->contentsRect().topLeft());
qDebug() << "mapToGlobal(parent->contentsRect().bottomRight()) =" <<
parent->mapToGlobal(parent->contentsRect().bottomRight());
qDebug() << "parentWidget()->childAt(" << geometry().topRight() << ") = " <<
parentWidget()->childAt(geometry().topRight());
qDebug() << "visibleRegion() = " << visibleRegion();
qDebug() << "geometry().contains(" << geometry().topRight() << ") = " << geometry().contains(geometry().topRight());
qDebug() << "geometry().contains(" << geometry().topRight() << ") = " <<
geometry().contains(geometry().topRight());
qDebug() << "mask() = " << mask();
#endif
@ -161,8 +178,10 @@ void QNitpickerViewWidget::paintEvent(QPaintEvent *event)
_scrollbars.insert(scrollbar, true);
// w = qMin(w, parent->contentsRect().width() + parent->childrenRect().x());
// qDebug() << "mapToGlobal(viewport->rect().topLeft()) =" << scrollarea->viewport()->mapToGlobal(scrollarea->viewport()->rect().topLeft());
// qDebug() << "mapToGlobal(viewport->rect().bottomRight()) =" << scrollarea->viewport()->mapToGlobal(scrollarea->viewport()->rect().bottomRight());
/* qDebug() << "mapToGlobal(viewport->rect().topLeft()) =" <<
scrollarea->viewport()->mapToGlobal(scrollarea->viewport()->rect().topLeft()); */
/* qDebug() << "mapToGlobal(viewport->rect().bottomRight()) =" <<
scrollarea->viewport()->mapToGlobal(scrollarea->viewport()->rect().bottomRight()); */
}
x0 = qMax(x0, parent->mapToGlobal(parent->contentsRect().topLeft()).x());
@ -206,29 +225,35 @@ void QNitpickerViewWidget::paintEvent(QPaintEvent *event)
* the plugin view starts at (0, 0)
*/
if (mask().isEmpty()) {
// PDBG("x0 = %d, y0 = %d, w = %d, h = %d, buf_x = %d, buf_y = %d", x0, y0, w, h, orig_buf_x + diff_x, orig_buf_y + diff_y);
/* PDBG("x0 = %d, y0 = %d, w = %d, h = %d, buf_x = %d, buf_y = %d",
x0, y0, w, h, orig_buf_x + diff_x, orig_buf_y + diff_y); */
vc->viewport(x0,
y0,
/*qMin(width(), w)*/w,
/*qMin(height(), h)*/h,
orig_buf_x + diff_x,
orig_buf_y + diff_y,
true);
false);
} else {
// PDBG("x = %d, y = %d, w = %d, h = %d, buf_x = %d, buf_y = %d", mapToGlobal(mask().boundingRect().topLeft()).x(), mapToGlobal(mask().boundingRect().topLeft()).y(), mask().boundingRect().width(), mask().boundingRect().height(), orig_buf_x + diff_x, orig_buf_y + diff_y);
/* PDBG("x = %d, y = %d, w = %d, h = %d, buf_x = %d, buf_y = %d",
mapToGlobal(mask().boundingRect().topLeft()).x(),
mapToGlobal(mask().boundingRect().topLeft()).y(),
mask().boundingRect().width(),
mask().boundingRect().height(),
orig_buf_x + diff_x, orig_buf_y + diff_y); */
vc->viewport(mapToGlobal(mask().boundingRect().topLeft()).x(),
mapToGlobal(mask().boundingRect().topLeft()).y(),
mask().boundingRect().width(),
mask().boundingRect().height(),
orig_buf_x + diff_x,
orig_buf_y + diff_y,
true);
false);
}
#if 0
/* bring the plugin view to the front of the Qt window */
QWSNitpickerWindowSurface *ws = static_cast<QWSNitpickerWindowSurface*>(windowSurface());
vc->stack(ws->view_cap(), false, true);
#endif
QNitpickerPlatformWindow *platform_window =
dynamic_cast<QNitpickerPlatformWindow*>(window()->windowHandle()->handle());
vc->stack(platform_window->view_cap(), false, true);
}
#if 0
void QNitpickerViewWidget::windowEvent(QWSWindow *window,

View File

@ -0,0 +1,571 @@
/*
* \brief QNitpickerPlatformWindow
* \author Christian Prochaska
* \date 2013-05-08
*/
/*
* Copyright (C) 2013 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
/* Genode includes */
#include <nitpicker_view/client.h>
/* Qt includes */
#include <qpa/qwindowsysteminterface.h>
#include <qpa/qplatformscreen.h>
#include <QDebug>
#include "qnitpickerplatformwindow.h"
QT_BEGIN_NAMESPACE
static const bool qnpw_verbose = false/*true*/;
void QNitpickerPlatformWindow::_process_mouse_event(Input::Event *ev)
{
#if 0
/* liquid_fb-specific calculation */
QPoint local_position(ev->ax(), ev->ay());
QPoint global_position (geometry().x() + local_position.x(),
geometry().y() + local_position.y());
#endif
QPoint global_position(ev->ax(), ev->ay());
QPoint local_position(global_position.x() - geometry().x(),
global_position.y() - geometry().y());
//qDebug() << "local_position =" << local_position;
//qDebug() << "global_position =" << global_position;
switch (ev->type()) {
case Input::Event::PRESS:
if (qnpw_verbose)
PDBG("PRESS");
/* make this window the focused window */
requestActivateWindow();
switch (ev->code()) {
case Input::BTN_LEFT:
_mouse_button_state |= Qt::LeftButton;
break;
case Input::BTN_RIGHT:
_mouse_button_state |= Qt::RightButton;
break;
case Input::BTN_MIDDLE:
_mouse_button_state |= Qt::MidButton;
break;
case Input::BTN_SIDE:
_mouse_button_state |= Qt::XButton1;
break;
case Input::BTN_EXTRA:
_mouse_button_state |= Qt::XButton2;
break;
}
break;
case Input::Event::RELEASE:
if (qnpw_verbose)
PDBG("RELEASE");
switch (ev->code()) {
case Input::BTN_LEFT:
_mouse_button_state &= ~Qt::LeftButton;
break;
case Input::BTN_RIGHT:
_mouse_button_state &= ~Qt::RightButton;
break;
case Input::BTN_MIDDLE:
_mouse_button_state &= ~Qt::MidButton;
break;
case Input::BTN_SIDE:
_mouse_button_state &= ~Qt::XButton1;
break;
case Input::BTN_EXTRA:
_mouse_button_state &= ~Qt::XButton2;
break;
}
break;
case Input::Event::WHEEL:
if (qnpw_verbose)
PDBG("WHEEL");
QWindowSystemInterface::handleWheelEvent(window(),
local_position,
local_position,
ev->ry() * 120,
Qt::Vertical);
return;
default:
break;
}
QWindowSystemInterface::handleMouseEvent(window(),
local_position,
global_position,
_mouse_button_state);
}
void QNitpickerPlatformWindow::_process_key_event(Input::Event *ev)
{
const bool pressed = (ev->type() == Input::Event::PRESS);
const int keycode = ev->code();
_keyboard_handler.processKeycode(keycode, pressed, false);
}
Nitpicker::View_capability QNitpickerPlatformWindow::_parent_view_cap()
{
if (window()->transientParent()) {
QNitpickerPlatformWindow *parent_platform_window =
static_cast<QNitpickerPlatformWindow*>(window()->transientParent()->handle());
return parent_platform_window->view_cap();
} else
return Nitpicker::View_capability();
}
void QNitpickerPlatformWindow::_adjust_and_set_geometry(const QRect &rect)
{
/* limit window size to screen size */
QRect adjusted_rect(rect.intersected(screen()->geometry()));
/* Currently, top level windows must start at (0,0) */
if (!window()->transientParent())
adjusted_rect.moveTo(0, 0);
QPlatformWindow::setGeometry(adjusted_rect);
Framebuffer::Mode mode(adjusted_rect.width(), adjusted_rect.height(),
Framebuffer::Mode::RGB565);
_nitpicker_session.buffer(mode, false);
emit framebuffer_changed();
}
QNitpickerPlatformWindow::QNitpickerPlatformWindow(QWindow *window, Genode::Rpc_entrypoint &ep,
int screen_width, int screen_height)
: QPlatformWindow(window),
_framebuffer_session(_nitpicker_session.framebuffer_session()),
_framebuffer(0),
_view_cap(_nitpicker_session.create_view(_parent_view_cap())),
_input_session(_nitpicker_session.input_session()),
_timer(this),
_keyboard_handler("", -1, false, false, ""),
_resize_handle(!window->flags().testFlag(Qt::Popup)),
_decoration(!window->flags().testFlag(Qt::Popup)),
_egl_surface(EGL_NO_SURFACE)
{
if (qnpw_verbose)
if (window->transientParent())
qDebug() << "QNitpickerPlatformWindow(): child window of" << window->transientParent();
_adjust_and_set_geometry(geometry());
_ev_buf = static_cast<Input::Event *>
(Genode::env()->rm_session()->attach(_input_session.dataspace()));
/* bring the view to the top */
Nitpicker::View_client(_view_cap).stack(Nitpicker::View_capability(),
true, false);
connect(_timer, SIGNAL(timeout()), this, SLOT(handle_events()));
_timer->start(10);
}
QWindow *QNitpickerPlatformWindow::window() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::window()";
return QPlatformWindow::window();
}
QPlatformWindow *QNitpickerPlatformWindow::parent() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::parent()";
return QPlatformWindow::parent();
}
QPlatformScreen *QNitpickerPlatformWindow::screen() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::screen()";
return QPlatformWindow::screen();
}
QSurfaceFormat QNitpickerPlatformWindow::format() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::format()";
return QPlatformWindow::format();
}
void QNitpickerPlatformWindow::setGeometry(const QRect &rect)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setGeometry(" << rect << ")";
_adjust_and_set_geometry(rect);
if (window()->isVisible()) {
QRect g(geometry());
Nitpicker::View_client(_view_cap).viewport(g.x(),
g.y(),
g.width(),
g.height(),
0, 0, true);
}
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setGeometry() finished";
}
QRect QNitpickerPlatformWindow::geometry() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::geometry(): returning" << QPlatformWindow::geometry();
return QPlatformWindow::geometry();
}
QMargins QNitpickerPlatformWindow::frameMargins() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::frameMargins()";
return QPlatformWindow::frameMargins();
}
void QNitpickerPlatformWindow::setVisible(bool visible)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setVisible(" << visible << ")";
if (visible) {
QRect g = geometry();
Nitpicker::View_client(_view_cap).viewport(g.x(), g.y(),
g.width(),
g.height(),
0, 0, true);
} else
Nitpicker::View_client(_view_cap).viewport(0, 0, 0, 0, 0, 0,
false);
QPlatformWindow::setVisible(visible);
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setVisible() finished";
}
void QNitpickerPlatformWindow::setWindowFlags(Qt::WindowFlags flags)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setWindowFlags(" << flags << ")";
#if 0
_resize_handle = true;
_decoration = true;
if (flags.testFlag(Qt::Popup)) {
_resize_handle = false;
_decoration = false;
}
#endif
QPlatformWindow::setWindowFlags(flags);
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setWindowFlags() finished";
}
void QNitpickerPlatformWindow::setWindowState(Qt::WindowState state)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setWindowState(" << state << ")";
QPlatformWindow::setWindowState(state);
}
WId QNitpickerPlatformWindow::winId() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::winId()";
return WId(this);
}
void QNitpickerPlatformWindow::setParent(const QPlatformWindow *window)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setParent()";
QPlatformWindow::setParent(window);
}
void QNitpickerPlatformWindow::setWindowTitle(const QString &title)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setWindowTitle(" << title << ")";
QPlatformWindow::setWindowTitle(title);
_title = title.toLocal8Bit();
Nitpicker::View_client(_view_cap).title(_title.constData());
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setWindowTitle() finished";
}
void QNitpickerPlatformWindow::setWindowFilePath(const QString &title)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setWindowFilePath(" << title << ")";
QPlatformWindow::setWindowFilePath(title);
}
void QNitpickerPlatformWindow::setWindowIcon(const QIcon &icon)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setWindowIcon()";
QPlatformWindow::setWindowIcon(icon);
}
void QNitpickerPlatformWindow::raise()
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::raise()";
QPlatformWindow::raise();
}
void QNitpickerPlatformWindow::lower()
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::lower()";
QPlatformWindow::lower();
}
bool QNitpickerPlatformWindow::isExposed() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::isExposed()";
return QPlatformWindow::isExposed();
}
bool QNitpickerPlatformWindow::isActive() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::isActive()";
return QPlatformWindow::isActive();
}
bool QNitpickerPlatformWindow::isEmbedded(const QPlatformWindow *parentWindow) const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::isEmbedded()";
return QPlatformWindow::isEmbedded(parentWindow);
}
QPoint QNitpickerPlatformWindow::mapToGlobal(const QPoint &pos) const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::mapToGlobal(" << pos << ")";
return QPlatformWindow::mapToGlobal(pos);
}
QPoint QNitpickerPlatformWindow::mapFromGlobal(const QPoint &pos) const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::mapFromGlobal(" << pos << ")";
return QPlatformWindow::mapFromGlobal(pos);
}
void QNitpickerPlatformWindow::propagateSizeHints()
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::propagateSizeHints()";
QPlatformWindow::propagateSizeHints();
}
void QNitpickerPlatformWindow::setOpacity(qreal level)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setOpacity(" << level << ")";
QPlatformWindow::setOpacity(level);
}
void QNitpickerPlatformWindow::setMask(const QRegion &region)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setMask(" << region << ")";
QPlatformWindow::setMask(region);
}
void QNitpickerPlatformWindow::requestActivateWindow()
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::requestActivateWindow()";
QPlatformWindow::requestActivateWindow();
}
void QNitpickerPlatformWindow::handleContentOrientationChange(Qt::ScreenOrientation orientation)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::handleContentOrientationChange()";
QPlatformWindow::handleContentOrientationChange(orientation);
}
qreal QNitpickerPlatformWindow::devicePixelRatio() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::devicePixelRatio()";
return QPlatformWindow::devicePixelRatio();
}
bool QNitpickerPlatformWindow::setKeyboardGrabEnabled(bool grab)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setKeyboardGrabEnabled()";
return QPlatformWindow::setKeyboardGrabEnabled(grab);
}
bool QNitpickerPlatformWindow::setMouseGrabEnabled(bool grab)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setMouseGrabEnabled()";
return QPlatformWindow::setMouseGrabEnabled(grab);
}
bool QNitpickerPlatformWindow::setWindowModified(bool modified)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setWindowModified()";
return QPlatformWindow::setWindowModified(modified);
}
void QNitpickerPlatformWindow::windowEvent(QEvent *event)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::windowEvent(" << event->type() << ")";
QPlatformWindow::windowEvent(event);
}
bool QNitpickerPlatformWindow::startSystemResize(const QPoint &pos, Qt::Corner corner)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::startSystemResize()";
return QPlatformWindow::startSystemResize(pos, corner);
}
void QNitpickerPlatformWindow::setFrameStrutEventsEnabled(bool enabled)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setFrameStrutEventsEnabled()";
QPlatformWindow::setFrameStrutEventsEnabled(enabled);
}
bool QNitpickerPlatformWindow::frameStrutEventsEnabled() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::frameStrutEventsEnabled()";
return QPlatformWindow::frameStrutEventsEnabled();
}
/* functions used by the window surface */
unsigned char *QNitpickerPlatformWindow::framebuffer()
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::framebuffer()";
if (_framebuffer)
Genode::env()->rm_session()->detach(_framebuffer);
_framebuffer = Genode::env()->rm_session()->attach(_framebuffer_session.dataspace());
return _framebuffer;
}
void QNitpickerPlatformWindow::refresh(int x, int y, int w, int h)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::refresh()";
_framebuffer_session.refresh(x, y, w, h);
}
EGLSurface QNitpickerPlatformWindow::egl_surface() const
{
return _egl_surface;
}
void QNitpickerPlatformWindow::egl_surface(EGLSurface egl_surface)
{
_egl_surface = egl_surface;
}
Nitpicker::View_capability QNitpickerPlatformWindow::view_cap() const
{
return _view_cap;
}
void QNitpickerPlatformWindow::handle_events()
{
#if 0
/* handle framebuffer mode change events */
if (_window_slave_policy.mode_changed()) {
int new_width;
int new_height;
_window_slave_policy.size(new_width, new_height);
if (qnpw_verbose)
PDBG("mode change detected: %d, %d", new_width, new_height);
QRect geo = geometry();
geo.setWidth(new_width);
geo.setHeight(new_height);
QPlatformWindow::setGeometry(geo);
if (qnpw_verbose)
qDebug() << "calling QWindowSystemInterface::handleGeometryChange(" << geo << ")";
QWindowSystemInterface::handleGeometryChange(window(), geo);
emit framebuffer_changed();
}
#endif
/* handle input events */
if (_input_session.is_pending()) {
for (int i = 0, num_ev = _input_session.flush(); i < num_ev; i++) {
Input::Event *ev = &_ev_buf[i];
bool const is_key_event = ev->type() == Input::Event::PRESS ||
ev->type() == Input::Event::RELEASE;
bool const is_mouse_button_event =
is_key_event && (ev->code() == Input::BTN_LEFT ||
ev->code() == Input::BTN_MIDDLE ||
ev->code() == Input::BTN_RIGHT);
if (ev->type() == Input::Event::MOTION ||
ev->type() == Input::Event::WHEEL ||
is_mouse_button_event) {
_process_mouse_event(ev);
} else if (is_key_event && (ev->code() < 128)) {
_process_key_event(ev);
}
}
}
}
QT_END_NAMESPACE

View File

@ -16,491 +16,140 @@
#define _QNITPICKERPLATFORMWINDOW_H_
/* Genode includes */
#include <input/keycodes.h>
#include <input/event.h>
#include <nitpicker_session/connection.h>
/* EGL includes */
#include <EGL/egl.h>
/* Qt includes */
#include <qpa/qplatformwindow.h>
#include <qpa/qplatformscreen.h>
#include <qpa/qwindowsysteminterface.h>
#include <QTimer>
#include <QDebug>
#include <qevdevkeyboardhandler_p.h>
/* Qoost includes */
#include <qoost/qmember.h>
#include "window_slave_policy.h"
QT_BEGIN_NAMESPACE
static const bool qnpw_verbose = false;
class QNitpickerPlatformWindow : public QObject, public QPlatformWindow
{
Q_OBJECT
private:
Window_slave_policy _window_slave_policy;
Genode::Slave _window_slave;
QMember<QTimer> _timer;
Qt::MouseButtons _mouse_button_state;
QEvdevKeyboardHandler _keyboard_handler;
QByteArray _title;
bool _resize_handle;
bool _decoration;
EGLSurface _egl_surface;
Nitpicker::Connection _nitpicker_session;
Framebuffer::Session_client _framebuffer_session;
unsigned char *_framebuffer;
Nitpicker::View_capability _view_cap;
Input::Session_client _input_session;
Input::Event *_ev_buf;
QMember<QTimer> _timer;
Qt::MouseButtons _mouse_button_state;
QEvdevKeyboardHandler _keyboard_handler;
QByteArray _title;
bool _resize_handle;
bool _decoration;
EGLSurface _egl_surface;
void _process_mouse_event(Input::Event *ev)
{
QPoint local_position(ev->ax(), ev->ay());
QPoint global_position (geometry().x() + local_position.x(),
geometry().y() + local_position.y());
void _process_mouse_event(Input::Event *ev);
void _process_key_event(Input::Event *ev);
//qDebug() << "local_position =" << local_position;
//qDebug() << "global_position =" << global_position;
switch (ev->type()) {
case Input::Event::PRESS:
if (qnpw_verbose)
PDBG("PRESS");
/* make this window the focused window */
requestActivateWindow();
switch (ev->code()) {
case Input::BTN_LEFT:
_mouse_button_state |= Qt::LeftButton;
break;
case Input::BTN_RIGHT:
_mouse_button_state |= Qt::RightButton;
break;
case Input::BTN_MIDDLE:
_mouse_button_state |= Qt::MidButton;
break;
case Input::BTN_SIDE:
_mouse_button_state |= Qt::XButton1;
break;
case Input::BTN_EXTRA:
_mouse_button_state |= Qt::XButton2;
break;
}
break;
case Input::Event::RELEASE:
if (qnpw_verbose)
PDBG("RELEASE");
switch (ev->code()) {
case Input::BTN_LEFT:
_mouse_button_state &= ~Qt::LeftButton;
break;
case Input::BTN_RIGHT:
_mouse_button_state &= ~Qt::RightButton;
break;
case Input::BTN_MIDDLE:
_mouse_button_state &= ~Qt::MidButton;
break;
case Input::BTN_SIDE:
_mouse_button_state &= ~Qt::XButton1;
break;
case Input::BTN_EXTRA:
_mouse_button_state &= ~Qt::XButton2;
break;
}
break;
case Input::Event::WHEEL:
if (qnpw_verbose)
PDBG("WHEEL");
QWindowSystemInterface::handleWheelEvent(window(),
local_position,
local_position,
ev->ry() * 120,
Qt::Vertical);
return;
default:
break;
}
QWindowSystemInterface::handleMouseEvent(window(),
local_position,
global_position,
_mouse_button_state);
}
void _process_key_event(Input::Event *ev)
{
const bool pressed = (ev->type() == Input::Event::PRESS);
const int keycode = ev->code();
_keyboard_handler.processKeycode(keycode, pressed, false);
}
Nitpicker::View_capability _parent_view_cap();
void _adjust_and_set_geometry(const QRect &rect);
public:
QNitpickerPlatformWindow(QWindow *window, Genode::Rpc_entrypoint &ep,
int screen_width, int screen_height)
: QPlatformWindow(window),
_window_slave_policy(ep, screen_width, screen_height),
_window_slave(ep, _window_slave_policy, 9*1024*1024),
_timer(this),
_keyboard_handler("", -1, false, false, ""),
_resize_handle(!window->flags().testFlag(Qt::Popup)),
_decoration(!window->flags().testFlag(Qt::Popup)),
_egl_surface(EGL_NO_SURFACE)
{
_window_slave_policy.wait_for_service_announcements();
int screen_width, int screen_height);
connect(_timer, SIGNAL(timeout()), this, SLOT(handle_events()));
_timer->start(10);
}
QWindow *window() const;
QWindow *window() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::window()";
return QPlatformWindow::window();
}
QPlatformWindow *parent() const;
QPlatformWindow *parent() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::parent()";
return QPlatformWindow::parent();
}
QPlatformScreen *screen() const;
QPlatformScreen *screen() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::screen()";
return QPlatformWindow::screen();
}
QSurfaceFormat format() const;
QSurfaceFormat format() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::format()";
return QPlatformWindow::format();
}
void setGeometry(const QRect &rect);
void setGeometry(const QRect &rect)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setGeometry(" << rect << ")";
QRect geometry() const;
/* limit window size to screen size */
QRect adjusted_rect(rect.intersected(screen()->geometry()));
QMargins frameMargins() const;
/* make invisible window invisible by moving it out of the screen */
if (!window()->isVisible())
adjusted_rect.moveRight(screen()->geometry().width());
void setVisible(bool visible);
_window_slave_policy.configure(adjusted_rect.x(),
adjusted_rect.y(),
adjusted_rect.width(),
adjusted_rect.height(),
_title.constData(),
_resize_handle, _decoration);
int final_width, final_height;
_window_slave_policy.size(final_width, final_height);
QRect final_geometry(rect.x(), rect.y(), final_width, final_height);
QPlatformWindow::setGeometry(final_geometry);
void setWindowFlags(Qt::WindowFlags flags);
emit framebuffer_changed();
void setWindowState(Qt::WindowState state);
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setGeometry() finished";
}
WId winId() const;
QRect geometry() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::geometry(): returning" << QPlatformWindow::geometry();
return QPlatformWindow::geometry();
}
void setParent(const QPlatformWindow *window);
QMargins frameMargins() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::frameMargins()";
return QPlatformWindow::frameMargins();
}
void setWindowTitle(const QString &title);
void setVisible(bool visible)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setVisible(" << visible << ")";
void setWindowFilePath(const QString &title);
QRect g = geometry();
int x = g.x();
if (!visible)
x += 100000;
_window_slave_policy.configure(x, g.y(),
g.width(), g.height(),
_title.constData(),
_resize_handle, _decoration);
void setWindowIcon(const QIcon &icon);
emit framebuffer_changed();
void raise();
QPlatformWindow::setVisible(visible);
void lower();
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setVisible() finished";
}
bool isExposed() const;
void setWindowFlags(Qt::WindowFlags flags)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setWindowFlags(" << flags << ")";
bool isActive() const;
_resize_handle = true;
_decoration = true;
bool isEmbedded(const QPlatformWindow *parentWindow) const;
if (flags.testFlag(Qt::Popup)) {
_resize_handle = false;
_decoration = false;
}
QPoint mapToGlobal(const QPoint &pos) const;
QRect g = geometry();
int x = g.x();
if (!window()->isVisible())
x += 100000;
_window_slave_policy.configure(x, g.y(), g.width(), g.height(),
_title.constData(), _resize_handle,
_decoration);
QPoint mapFromGlobal(const QPoint &pos) const;
QPlatformWindow::setWindowFlags(flags);
void propagateSizeHints();
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setWindowFlags() finished";
}
void setOpacity(qreal level);
void setWindowState(Qt::WindowState state)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setWindowState(" << state << ")";
QPlatformWindow::setWindowState(state);
}
void setMask(const QRegion &region);
WId winId() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::winId()";
return WId(this);
}
void requestActivateWindow();
void setParent(const QPlatformWindow *window)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setParent()";
QPlatformWindow::setParent(window);
}
void handleContentOrientationChange(Qt::ScreenOrientation orientation);
void setWindowTitle(const QString &title)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setWindowTitle(" << title << ")";
qreal devicePixelRatio() const;
QPlatformWindow::setWindowTitle(title);
_title = title.toUtf8();
QRect g = geometry();
int x = g.x();
if (!window()->isVisible())
x += 100000;
_window_slave_policy.configure(x, g.y(),
g.width(), g.height(),
_title.constData(),
_resize_handle, _decoration);
emit framebuffer_changed();
bool setKeyboardGrabEnabled(bool grab);
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setWindowTitle() finished";
}
bool setMouseGrabEnabled(bool grab);
void setWindowFilePath(const QString &title)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setWindowFilePath(" << title << ")";
QPlatformWindow::setWindowFilePath(title);
}
bool setWindowModified(bool modified);
void setWindowIcon(const QIcon &icon)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setWindowIcon()";
QPlatformWindow::setWindowIcon(icon);
}
void windowEvent(QEvent *event);
void raise()
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::raise()";
QPlatformWindow::raise();
}
bool startSystemResize(const QPoint &pos, Qt::Corner corner);
void lower()
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::lower()";
QPlatformWindow::lower();
}
void setFrameStrutEventsEnabled(bool enabled);
bool isExposed() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::isExposed()";
return QPlatformWindow::isExposed();
}
bool frameStrutEventsEnabled() const;
bool isActive() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::isActive()";
return QPlatformWindow::isActive();
}
bool isEmbedded(const QPlatformWindow *parentWindow) const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::isEmbedded()";
return QPlatformWindow::isEmbedded(parentWindow);
}
/* for QNitpickerWindowSurface */
QPoint mapToGlobal(const QPoint &pos) const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::mapToGlobal(" << pos << ")";
return QPlatformWindow::mapToGlobal(pos);
}
unsigned char *framebuffer();
QPoint mapFromGlobal(const QPoint &pos) const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::mapFromGlobal(" << pos << ")";
return QPlatformWindow::mapFromGlobal(pos);
}
void refresh(int x, int y, int w, int h);
void propagateSizeHints()
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::propagateSizeHints()";
QPlatformWindow::propagateSizeHints();
}
void setOpacity(qreal level)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setOpacity(" << level << ")";
QPlatformWindow::setOpacity(level);
}
/* for QNitpickerGLContext */
void setMask(const QRegion &region)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setMask(" << region << ")";
QPlatformWindow::setMask(region);
}
EGLSurface egl_surface() const;
void requestActivateWindow()
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::requestActivateWindow()";
QPlatformWindow::requestActivateWindow();
}
void egl_surface(EGLSurface egl_surface);
void handleContentOrientationChange(Qt::ScreenOrientation orientation)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::handleContentOrientationChange()";
QPlatformWindow::handleContentOrientationChange(orientation);
}
qreal devicePixelRatio() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::devicePixelRatio()";
return QPlatformWindow::devicePixelRatio();
}
/* for QNitpickerViewWidget */
bool setKeyboardGrabEnabled(bool grab)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setKeyboardGrabEnabled()";
return QPlatformWindow::setKeyboardGrabEnabled(grab);
}
bool setMouseGrabEnabled(bool grab)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setMouseGrabEnabled()";
return QPlatformWindow::setMouseGrabEnabled(grab);
}
bool setWindowModified(bool modified)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setWindowModified()";
return QPlatformWindow::setWindowModified(modified);
}
void windowEvent(QEvent *event)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::windowEvent(" << event->type() << ")";
QPlatformWindow::windowEvent(event);
}
bool startSystemResize(const QPoint &pos, Qt::Corner corner)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::startSystemResize()";
return QPlatformWindow::startSystemResize(pos, corner);
}
void setFrameStrutEventsEnabled(bool enabled)
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::setFrameStrutEventsEnabled()";
QPlatformWindow::setFrameStrutEventsEnabled(enabled);
}
bool frameStrutEventsEnabled() const
{
if (qnpw_verbose)
qDebug() << "QNitpickerPlatformWindow::frameStrutEventsEnabled()";
return QPlatformWindow::frameStrutEventsEnabled();
}
/* functions used by the window surface */
unsigned char *framebuffer()
{
return _window_slave_policy.framebuffer();
}
void refresh(int x, int y, int w, int h)
{
_window_slave_policy.refresh(x, y, w, h);
}
EGLSurface egl_surface() const
{
return _egl_surface;
}
void egl_surface(EGLSurface egl_surface)
{
_egl_surface = egl_surface;
}
Nitpicker::View_capability view_cap() const;
signals:
@ -508,62 +157,7 @@ class QNitpickerPlatformWindow : public QObject, public QPlatformWindow
private slots:
void handle_events()
{
/* handle framebuffer mode change events */
if (_window_slave_policy.mode_changed()) {
int new_width;
int new_height;
_window_slave_policy.size(new_width, new_height);
if (qnpw_verbose)
PDBG("mode change detected: %d, %d", new_width, new_height);
QRect geo = geometry();
geo.setWidth(new_width);
geo.setHeight(new_height);
QPlatformWindow::setGeometry(geo);
if (qnpw_verbose)
qDebug() << "calling QWindowSystemInterface::handleGeometryChange(" << geo << ")";
QWindowSystemInterface::handleGeometryChange(window(), geo);
emit framebuffer_changed();
}
/* handle input events */
Input::Session_client input(_window_slave_policy.input_session());
if (input.is_pending()) {
Input::Event *ev_buf = _window_slave_policy.ev_buf();
for (int i = 0, num_ev = input.flush(); i < num_ev; i++) {
Input::Event *ev = &ev_buf[i];
bool const is_key_event = ev->type() == Input::Event::PRESS ||
ev->type() == Input::Event::RELEASE;
bool const is_mouse_button_event =
is_key_event && (ev->code() == Input::BTN_LEFT ||
ev->code() == Input::BTN_MIDDLE ||
ev->code() == Input::BTN_RIGHT);
if (ev->type() == Input::Event::MOTION ||
ev->type() == Input::Event::WHEEL ||
is_mouse_button_event) {
_process_mouse_event(ev);
} else if (is_key_event && (ev->code() < 128)) {
_process_key_event(ev);
}
}
}
}
void handle_events();
};

View File

@ -21,7 +21,6 @@
/* Genode includes */
#include <nitpicker_session/connection.h>
#include <framebuffer_session/client.h>
/* local includes */
#include "window_slave_policy.h"
@ -32,14 +31,12 @@ class QNitpickerScreen : public QPlatformScreen
{
private:
Nitpicker::Connection _nitpicker;
Framebuffer::Session_client _framebuffer;
Nitpicker::Connection _nitpicker;
QRect _geometry;
public:
QNitpickerScreen()
: _framebuffer(_nitpicker.framebuffer_session())
{
Framebuffer::Mode const scr_mode = _nitpicker.mode();
_nitpicker.buffer(scr_mode, false);

View File

@ -11,7 +11,6 @@
* under the terms of the GNU General Public License version 2.
*/
#include <private/qguiapplication_p.h>
#include <qpa/qplatformscreen.h>
@ -20,6 +19,8 @@
#include "qnitpickerwindowsurface.h"
#include <QDebug>
static const bool verbose = false;
QT_BEGIN_NAMESPACE