2015-03-19 07:29:34 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#include "x11windowed_backend.h"
|
2019-06-13 09:27:01 +00:00
|
|
|
#include "x11windowed_output.h"
|
2015-05-05 13:23:53 +00:00
|
|
|
#include "scene_qpainter_x11_backend.h"
|
2015-05-05 15:27:03 +00:00
|
|
|
#include "logging.h"
|
2015-03-19 07:29:34 +00:00
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "xcbutils.h"
|
2015-11-25 12:33:40 +00:00
|
|
|
#include "egl_x11_backend.h"
|
2019-06-13 09:27:01 +00:00
|
|
|
#include "outputscreens.h"
|
2015-03-19 07:29:34 +00:00
|
|
|
#include <kwinxrenderutils.h>
|
2015-09-16 11:51:44 +00:00
|
|
|
// KDE
|
|
|
|
#include <KLocalizedString>
|
2015-03-19 07:29:34 +00:00
|
|
|
#include <QAbstractEventDispatcher>
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QSocketNotifier>
|
|
|
|
// kwayland
|
2015-09-16 11:51:44 +00:00
|
|
|
#include <KWayland/Server/display.h>
|
2015-03-19 07:29:34 +00:00
|
|
|
#include <KWayland/Server/seat_interface.h>
|
2015-09-17 07:47:45 +00:00
|
|
|
// xcb
|
|
|
|
#include <xcb/xcb_keysyms.h>
|
2018-12-05 17:46:35 +00:00
|
|
|
// X11
|
|
|
|
#if HAVE_X11_XINPUT
|
|
|
|
#include "ge_event_mem_mover.h"
|
|
|
|
#include <X11/extensions/XInput2.h>
|
|
|
|
#include <X11/extensions/XI2proto.h>
|
|
|
|
#endif
|
2015-03-19 07:29:34 +00:00
|
|
|
// system
|
|
|
|
#include <linux/input.h>
|
2015-03-19 10:07:49 +00:00
|
|
|
#include <X11/Xlib-xcb.h>
|
2015-03-19 07:29:34 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2015-05-06 07:37:25 +00:00
|
|
|
X11WindowedBackend::X11WindowedBackend(QObject *parent)
|
2016-04-07 07:18:10 +00:00
|
|
|
: Platform(parent)
|
2015-05-06 06:32:39 +00:00
|
|
|
{
|
2015-06-05 17:34:03 +00:00
|
|
|
setSupportsPointerWarping(true);
|
2015-11-17 09:40:17 +00:00
|
|
|
connect(this, &X11WindowedBackend::sizeChanged, this, &X11WindowedBackend::screenSizeChanged);
|
2015-05-06 06:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
X11WindowedBackend::~X11WindowedBackend()
|
|
|
|
{
|
|
|
|
if (m_connection) {
|
2015-09-17 07:47:45 +00:00
|
|
|
if (m_keySymbols) {
|
|
|
|
xcb_key_symbols_free(m_keySymbols);
|
|
|
|
}
|
2015-05-06 06:32:39 +00:00
|
|
|
if (m_cursor) {
|
|
|
|
xcb_free_cursor(m_connection, m_cursor);
|
|
|
|
}
|
|
|
|
xcb_disconnect(m_connection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11WindowedBackend::init()
|
2015-03-19 07:29:34 +00:00
|
|
|
{
|
|
|
|
int screen = 0;
|
2015-03-19 10:07:49 +00:00
|
|
|
xcb_connection_t *c = nullptr;
|
2015-05-06 07:37:25 +00:00
|
|
|
Display *xDisplay = XOpenDisplay(deviceIdentifier().constData());
|
2015-03-19 10:07:49 +00:00
|
|
|
if (xDisplay) {
|
|
|
|
c = XGetXCBConnection(xDisplay);
|
|
|
|
XSetEventQueueOwner(xDisplay, XCBOwnsEventQueue);
|
|
|
|
screen = XDefaultScreen(xDisplay);
|
|
|
|
}
|
|
|
|
if (c && !xcb_connection_has_error(c)) {
|
2015-03-19 07:29:34 +00:00
|
|
|
m_connection = c;
|
|
|
|
m_screenNumber = screen;
|
2015-03-19 10:07:49 +00:00
|
|
|
m_display = xDisplay;
|
2015-03-19 07:29:34 +00:00
|
|
|
for (xcb_screen_iterator_t it = xcb_setup_roots_iterator(xcb_get_setup(m_connection));
|
|
|
|
it.rem;
|
|
|
|
--screen, xcb_screen_next(&it)) {
|
|
|
|
if (screen == m_screenNumber) {
|
|
|
|
m_screen = it.data;
|
|
|
|
}
|
|
|
|
}
|
2018-12-05 17:46:35 +00:00
|
|
|
initXInput();
|
2015-03-19 07:29:34 +00:00
|
|
|
XRenderUtils::init(m_connection, m_screen->root);
|
2019-06-13 09:27:01 +00:00
|
|
|
createOutputs();
|
2016-08-03 15:24:37 +00:00
|
|
|
connect(kwinApp(), &Application::workspaceCreated, this, &X11WindowedBackend::startEventReading);
|
2016-02-23 11:29:05 +00:00
|
|
|
connect(this, &X11WindowedBackend::cursorChanged, this,
|
|
|
|
[this] {
|
|
|
|
createCursor(softwareCursor(), softwareCursorHotspot());
|
|
|
|
}
|
|
|
|
);
|
2015-05-05 17:02:52 +00:00
|
|
|
setReady(true);
|
2015-05-06 06:52:59 +00:00
|
|
|
waylandServer()->seat()->setHasPointer(true);
|
|
|
|
waylandServer()->seat()->setHasKeyboard(true);
|
2018-12-05 17:46:35 +00:00
|
|
|
if (m_hasXInput) {
|
|
|
|
waylandServer()->seat()->setHasTouch(true);
|
|
|
|
}
|
2015-05-06 07:03:54 +00:00
|
|
|
emit screensQueried();
|
2015-05-06 07:16:36 +00:00
|
|
|
} else {
|
|
|
|
emit initFailed();
|
2015-03-19 07:29:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 17:46:35 +00:00
|
|
|
void X11WindowedBackend::initXInput()
|
|
|
|
{
|
|
|
|
#if HAVE_X11_XINPUT
|
|
|
|
int xi_opcode, event, error;
|
|
|
|
// init XInput extension
|
|
|
|
if (!XQueryExtension(m_display, "XInputExtension", &xi_opcode, &event, &error)) {
|
|
|
|
qCDebug(KWIN_X11WINDOWED) << "XInputExtension not present";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// verify that the XInput extension is at at least version 2.0
|
|
|
|
int major = 2, minor = 2;
|
|
|
|
int result = XIQueryVersion(m_display, &major, &minor);
|
|
|
|
if (result != Success) {
|
|
|
|
qCDebug(KWIN_X11WINDOWED) << "Failed to init XInput 2.2, trying 2.0";
|
|
|
|
minor = 0;
|
|
|
|
if (XIQueryVersion(m_display, &major, &minor) != Success) {
|
|
|
|
qCDebug(KWIN_X11WINDOWED) << "Failed to init XInput";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_xiOpcode = xi_opcode;
|
|
|
|
m_majorVersion = major;
|
|
|
|
m_minorVersion = minor;
|
|
|
|
m_hasXInput = m_majorVersion >=2 && m_minorVersion >= 2;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-06-13 09:27:01 +00:00
|
|
|
void X11WindowedBackend::createOutputs()
|
2015-03-19 07:29:34 +00:00
|
|
|
{
|
|
|
|
Xcb::Atom protocolsAtom(QByteArrayLiteral("WM_PROTOCOLS"), false, m_connection);
|
|
|
|
Xcb::Atom deleteWindowAtom(QByteArrayLiteral("WM_DELETE_WINDOW"), false, m_connection);
|
2015-11-24 12:11:29 +00:00
|
|
|
|
2019-06-13 09:27:01 +00:00
|
|
|
// we need to multiply the initial window size with the scale in order to
|
|
|
|
// create an output window of this size in the end
|
|
|
|
const int pixelWidth = initialWindowSize().width() * initialOutputScale() + 0.5;
|
|
|
|
const int pixelHeight = initialWindowSize().height() * initialOutputScale() + 0.5;
|
|
|
|
const int logicalWidth = initialWindowSize().width();
|
|
|
|
|
|
|
|
int logicalWidthSum = 0;
|
|
|
|
for (int i = 0; i < initialOutputCount(); ++i) {
|
|
|
|
auto *output = new X11WindowedOutput(this);
|
|
|
|
output->setScale(initialOutputScale());
|
|
|
|
output->setGeometry(QPoint(logicalWidthSum, 0), QSize(pixelWidth, pixelHeight));
|
|
|
|
output->init();
|
2015-11-24 12:11:29 +00:00
|
|
|
|
|
|
|
m_protocols = protocolsAtom;
|
|
|
|
m_deleteWindowProtocol = deleteWindowAtom;
|
|
|
|
|
2019-06-13 09:27:01 +00:00
|
|
|
xcb_change_property(m_connection,
|
|
|
|
XCB_PROP_MODE_REPLACE,
|
|
|
|
output->window(),
|
|
|
|
m_protocols,
|
|
|
|
XCB_ATOM_ATOM,
|
|
|
|
32, 1,
|
|
|
|
&m_deleteWindowProtocol);
|
|
|
|
|
|
|
|
logicalWidthSum += logicalWidth;
|
|
|
|
m_outputs << output;
|
2015-11-24 12:11:29 +00:00
|
|
|
}
|
2015-11-24 09:47:52 +00:00
|
|
|
|
|
|
|
updateWindowTitle();
|
2015-03-19 07:29:34 +00:00
|
|
|
|
|
|
|
xcb_flush(m_connection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11WindowedBackend::startEventReading()
|
|
|
|
{
|
|
|
|
QSocketNotifier *notifier = new QSocketNotifier(xcb_get_file_descriptor(m_connection), QSocketNotifier::Read, this);
|
|
|
|
auto processXcbEvents = [this] {
|
|
|
|
while (auto event = xcb_poll_for_event(m_connection)) {
|
|
|
|
handleEvent(event);
|
|
|
|
free(event);
|
|
|
|
}
|
|
|
|
xcb_flush(m_connection);
|
|
|
|
};
|
|
|
|
connect(notifier, &QSocketNotifier::activated, this, processXcbEvents);
|
|
|
|
connect(QCoreApplication::eventDispatcher(), &QAbstractEventDispatcher::aboutToBlock, this, processXcbEvents);
|
|
|
|
connect(QCoreApplication::eventDispatcher(), &QAbstractEventDispatcher::awake, this, processXcbEvents);
|
|
|
|
}
|
|
|
|
|
2018-12-05 17:46:35 +00:00
|
|
|
#if HAVE_X11_XINPUT
|
|
|
|
|
|
|
|
static inline qreal fixed1616ToReal(FP1616 val)
|
|
|
|
{
|
|
|
|
return (val) * 1.0 / (1 << 16);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-19 07:29:34 +00:00
|
|
|
void X11WindowedBackend::handleEvent(xcb_generic_event_t *e)
|
|
|
|
{
|
|
|
|
const uint8_t eventType = e->response_type & ~0x80;
|
|
|
|
switch (eventType) {
|
|
|
|
case XCB_BUTTON_PRESS:
|
|
|
|
case XCB_BUTTON_RELEASE:
|
|
|
|
handleButtonPress(reinterpret_cast<xcb_button_press_event_t*>(e));
|
|
|
|
break;
|
2015-05-05 08:44:46 +00:00
|
|
|
case XCB_MOTION_NOTIFY: {
|
2015-03-19 07:29:34 +00:00
|
|
|
auto event = reinterpret_cast<xcb_motion_notify_event_t*>(e);
|
2019-06-13 09:27:01 +00:00
|
|
|
auto it = std::find_if(m_outputs.constBegin(), m_outputs.constEnd(),
|
|
|
|
[event] (X11WindowedOutput *output) { return output->window() == event->event; }
|
|
|
|
);
|
|
|
|
if (it == m_outputs.constEnd()) {
|
2015-11-24 09:47:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-11-04 21:48:29 +00:00
|
|
|
//generally we don't need to normalise input to the output scale; however because we're getting input
|
|
|
|
//from a host window that doesn't understand scaling, we need to apply it ourselves so the cursor matches
|
2019-06-13 09:27:01 +00:00
|
|
|
pointerMotion(QPointF(event->root_x - (*it)->hostPosition().x() + (*it)->internalPosition().x(),
|
|
|
|
event->root_y - (*it)->hostPosition().y() + (*it)->internalPosition().y()) / (*it)->scale(),
|
|
|
|
event->time);
|
2015-03-19 07:29:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XCB_KEY_PRESS:
|
2015-05-05 08:44:46 +00:00
|
|
|
case XCB_KEY_RELEASE: {
|
2015-03-19 07:29:34 +00:00
|
|
|
auto event = reinterpret_cast<xcb_key_press_event_t*>(e);
|
2015-05-05 08:44:46 +00:00
|
|
|
if (eventType == XCB_KEY_PRESS) {
|
2015-09-17 07:47:45 +00:00
|
|
|
if (!m_keySymbols) {
|
|
|
|
m_keySymbols = xcb_key_symbols_alloc(m_connection);
|
|
|
|
}
|
|
|
|
const xcb_keysym_t kc = xcb_key_symbols_get_keysym(m_keySymbols, event->detail, 0);
|
|
|
|
if (kc == XK_Control_R) {
|
|
|
|
grabKeyboard(event->time);
|
|
|
|
}
|
2015-05-05 08:44:46 +00:00
|
|
|
keyboardKeyPressed(event->detail - 8, event->time);
|
|
|
|
} else {
|
|
|
|
keyboardKeyReleased(event->detail - 8, event->time);
|
|
|
|
}
|
2015-03-19 07:29:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XCB_CONFIGURE_NOTIFY:
|
|
|
|
updateSize(reinterpret_cast<xcb_configure_notify_event_t*>(e));
|
|
|
|
break;
|
2015-05-05 08:44:46 +00:00
|
|
|
case XCB_ENTER_NOTIFY: {
|
2015-03-19 07:29:34 +00:00
|
|
|
auto event = reinterpret_cast<xcb_enter_notify_event_t*>(e);
|
2019-06-13 09:27:01 +00:00
|
|
|
auto it = std::find_if(m_outputs.constBegin(), m_outputs.constEnd(),
|
|
|
|
[event] (X11WindowedOutput *output) { return output->window() == event->event; }
|
|
|
|
);
|
|
|
|
if (it == m_outputs.constEnd()) {
|
2015-11-24 09:47:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-06-13 09:27:01 +00:00
|
|
|
pointerMotion(QPointF(event->root_x - (*it)->hostPosition().x() + (*it)->internalPosition().x(),
|
|
|
|
event->root_y - (*it)->hostPosition().y() + (*it)->internalPosition().y()) / (*it)->scale(),
|
|
|
|
event->time);
|
2015-03-19 07:29:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XCB_CLIENT_MESSAGE:
|
|
|
|
handleClientMessage(reinterpret_cast<xcb_client_message_event_t*>(e));
|
|
|
|
break;
|
|
|
|
case XCB_EXPOSE:
|
|
|
|
handleExpose(reinterpret_cast<xcb_expose_event_t*>(e));
|
|
|
|
break;
|
2015-09-17 07:47:45 +00:00
|
|
|
case XCB_MAPPING_NOTIFY:
|
|
|
|
if (m_keySymbols) {
|
|
|
|
xcb_refresh_keyboard_mapping(m_keySymbols, reinterpret_cast<xcb_mapping_notify_event_t*>(e));
|
|
|
|
}
|
|
|
|
break;
|
2018-12-05 17:46:35 +00:00
|
|
|
#if HAVE_X11_XINPUT
|
|
|
|
case XCB_GE_GENERIC: {
|
|
|
|
GeEventMemMover ge(e);
|
|
|
|
auto te = reinterpret_cast<xXIDeviceEvent*>(e);
|
2019-06-13 09:27:01 +00:00
|
|
|
auto it = std::find_if(m_outputs.constBegin(), m_outputs.constEnd(),
|
|
|
|
[te] (X11WindowedOutput *output) { return output->window() == te->event; }
|
|
|
|
);
|
|
|
|
if (it == m_outputs.constEnd()) {
|
2018-12-05 17:46:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
QPointF position{
|
2019-06-13 09:27:01 +00:00
|
|
|
fixed1616ToReal(te->root_x) - (*it)->hostPosition().x() + (*it)->internalPosition().x(),
|
|
|
|
fixed1616ToReal(te->root_y) - (*it)->hostPosition().y() + (*it)->internalPosition().y()
|
2018-12-05 17:46:35 +00:00
|
|
|
};
|
2019-06-13 09:27:01 +00:00
|
|
|
position /= (*it)->scale();
|
2018-12-05 17:46:35 +00:00
|
|
|
|
|
|
|
switch (ge->event_type) {
|
|
|
|
|
|
|
|
case XI_TouchBegin: {
|
|
|
|
touchDown(te->detail, position, te->time);
|
|
|
|
touchFrame();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case XI_TouchUpdate: {
|
|
|
|
touchMotion(te->detail, position, te->time);
|
|
|
|
touchFrame();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case XI_TouchEnd: {
|
|
|
|
touchUp(te->detail, te->time);
|
|
|
|
touchFrame();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case XI_TouchOwnership: {
|
|
|
|
auto te = reinterpret_cast<xXITouchOwnershipEvent*>(e);
|
|
|
|
XIAllowTouchEvents(m_display, te->deviceid, te->sourceid, te->touchid, XIAcceptTouch);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2015-03-19 07:29:34 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-17 07:47:45 +00:00
|
|
|
void X11WindowedBackend::grabKeyboard(xcb_timestamp_t time)
|
|
|
|
{
|
|
|
|
const bool oldState = m_keyboardGrabbed;
|
|
|
|
if (m_keyboardGrabbed) {
|
|
|
|
xcb_ungrab_keyboard(m_connection, time);
|
|
|
|
xcb_ungrab_pointer(m_connection, time);
|
|
|
|
m_keyboardGrabbed = false;
|
|
|
|
} else {
|
2015-11-24 09:47:52 +00:00
|
|
|
const auto c = xcb_grab_keyboard_unchecked(m_connection, false, window(), time,
|
2015-09-17 07:47:45 +00:00
|
|
|
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
|
|
|
|
ScopedCPointer<xcb_grab_keyboard_reply_t> grab(xcb_grab_keyboard_reply(m_connection, c, nullptr));
|
|
|
|
if (grab.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (grab->status == XCB_GRAB_STATUS_SUCCESS) {
|
2015-11-24 09:47:52 +00:00
|
|
|
const auto c = xcb_grab_pointer_unchecked(m_connection, false, window(),
|
2015-09-17 07:47:45 +00:00
|
|
|
XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE |
|
|
|
|
XCB_EVENT_MASK_POINTER_MOTION |
|
|
|
|
XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW,
|
|
|
|
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC,
|
2015-11-24 09:47:52 +00:00
|
|
|
window(), XCB_CURSOR_NONE, time);
|
2015-09-17 07:47:45 +00:00
|
|
|
ScopedCPointer<xcb_grab_pointer_reply_t> grab(xcb_grab_pointer_reply(m_connection, c, nullptr));
|
|
|
|
if (grab.isNull() || grab->status != XCB_GRAB_STATUS_SUCCESS) {
|
|
|
|
xcb_ungrab_keyboard(m_connection, time);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_keyboardGrabbed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (oldState != m_keyboardGrabbed) {
|
|
|
|
updateWindowTitle();
|
|
|
|
xcb_flush(m_connection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11WindowedBackend::updateWindowTitle()
|
|
|
|
{
|
|
|
|
const QString grab = m_keyboardGrabbed ? i18n("Press right control to ungrab input") : i18n("Press right control key to grab input");
|
|
|
|
const QString title = QStringLiteral("%1 (%2) - %3").arg(i18n("KDE Wayland Compositor"))
|
|
|
|
.arg(waylandServer()->display()->socketName())
|
|
|
|
.arg(grab);
|
2019-06-13 09:27:01 +00:00
|
|
|
for (auto it = m_outputs.constBegin(); it != m_outputs.constEnd(); ++it) {
|
|
|
|
(*it)->setWindowTitle(title);
|
2015-11-24 09:47:52 +00:00
|
|
|
}
|
2015-09-17 07:47:45 +00:00
|
|
|
}
|
|
|
|
|
2015-03-19 07:29:34 +00:00
|
|
|
void X11WindowedBackend::handleClientMessage(xcb_client_message_event_t *event)
|
|
|
|
{
|
2019-06-13 09:27:01 +00:00
|
|
|
auto it = std::find_if(m_outputs.begin(), m_outputs.end(),
|
|
|
|
[event] (X11WindowedOutput *output) { return output->window() == event->window; }
|
|
|
|
);
|
|
|
|
if (it == m_outputs.end()) {
|
2015-03-19 07:29:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (event->type == m_protocols && m_protocols != XCB_ATOM_NONE) {
|
|
|
|
if (event->data.data32[0] == m_deleteWindowProtocol && m_deleteWindowProtocol != XCB_ATOM_NONE) {
|
2019-06-13 09:27:01 +00:00
|
|
|
if (m_outputs.count() == 1) {
|
2016-07-20 11:33:54 +00:00
|
|
|
qCDebug(KWIN_X11WINDOWED) << "Backend window is going to be closed, shutting down.";
|
|
|
|
QCoreApplication::quit();
|
|
|
|
} else {
|
|
|
|
// remove the window
|
|
|
|
qCDebug(KWIN_X11WINDOWED) << "Removing one output window.";
|
2019-06-13 09:27:01 +00:00
|
|
|
|
|
|
|
auto removedOutput = *it;
|
|
|
|
it = m_outputs.erase(it);
|
2016-07-20 11:33:54 +00:00
|
|
|
|
|
|
|
// update the sizes
|
2019-06-13 09:27:01 +00:00
|
|
|
int x = removedOutput->internalPosition().x();
|
|
|
|
for (; it != m_outputs.end(); ++it) {
|
|
|
|
(*it)->setGeometry(QPoint(x, 0), (*it)->pixelSize());
|
|
|
|
x += (*it)->geometry().width();
|
2016-07-20 11:33:54 +00:00
|
|
|
}
|
2019-06-13 09:27:01 +00:00
|
|
|
|
|
|
|
delete removedOutput;
|
2016-07-20 11:33:54 +00:00
|
|
|
QMetaObject::invokeMethod(screens(), "updateCount");
|
|
|
|
}
|
2015-03-19 07:29:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11WindowedBackend::handleButtonPress(xcb_button_press_event_t *event)
|
|
|
|
{
|
2019-06-13 09:27:01 +00:00
|
|
|
auto it = std::find_if(m_outputs.constBegin(), m_outputs.constEnd(),
|
|
|
|
[event] (X11WindowedOutput *output) { return output->window() == event->event; }
|
|
|
|
);
|
|
|
|
if (it == m_outputs.constEnd()) {
|
2015-11-24 09:47:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-03-19 07:29:34 +00:00
|
|
|
bool const pressed = (event->response_type & ~0x80) == XCB_BUTTON_PRESS;
|
|
|
|
if (event->detail >= XCB_BUTTON_INDEX_4 && event->detail <= 7) {
|
|
|
|
// wheel
|
|
|
|
if (!pressed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const int delta = (event->detail == XCB_BUTTON_INDEX_4 || event->detail == 6) ? -1 : 1;
|
|
|
|
static const qreal s_defaultAxisStepDistance = 10.0;
|
2015-05-05 08:44:46 +00:00
|
|
|
if (event->detail > 5) {
|
Send axis_source, axis_discrete, and axis_stop
Summary:
So far KWin didn't send axis_source, axis_discrete, and axis_stop. Even
though most of those events are optional, clients need them to work as
expected. For example, one needs axis_source and axis_stop to implement
kinetic scrolling; Xwayland needs axis_discrete to prevent multiple
scroll events when the compositor sends axis deltas greater than 10, etc.
BUG: 404152
FIXED-IN: 5.17.0
Test Plan:
* Content of a webpage in Firefox is moved by one line per each mouse
wheel "click";
* Scrolled gedit using 2 fingers on GNOME Shell, sway, and KDE Plasma;
in all three cases wayland debug looked the same (except diagonal scroll
motions).
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D19000
2019-02-12 09:14:51 +00:00
|
|
|
pointerAxisHorizontal(delta * s_defaultAxisStepDistance, event->time, delta);
|
2015-05-05 08:44:46 +00:00
|
|
|
} else {
|
Send axis_source, axis_discrete, and axis_stop
Summary:
So far KWin didn't send axis_source, axis_discrete, and axis_stop. Even
though most of those events are optional, clients need them to work as
expected. For example, one needs axis_source and axis_stop to implement
kinetic scrolling; Xwayland needs axis_discrete to prevent multiple
scroll events when the compositor sends axis deltas greater than 10, etc.
BUG: 404152
FIXED-IN: 5.17.0
Test Plan:
* Content of a webpage in Firefox is moved by one line per each mouse
wheel "click";
* Scrolled gedit using 2 fingers on GNOME Shell, sway, and KDE Plasma;
in all three cases wayland debug looked the same (except diagonal scroll
motions).
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D19000
2019-02-12 09:14:51 +00:00
|
|
|
pointerAxisVertical(delta * s_defaultAxisStepDistance, event->time, delta);
|
2015-05-05 08:44:46 +00:00
|
|
|
}
|
2015-03-19 07:29:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint32_t button = 0;
|
|
|
|
switch (event->detail) {
|
|
|
|
case XCB_BUTTON_INDEX_1:
|
|
|
|
button = BTN_LEFT;
|
|
|
|
break;
|
|
|
|
case XCB_BUTTON_INDEX_2:
|
|
|
|
button = BTN_MIDDLE;
|
|
|
|
break;
|
|
|
|
case XCB_BUTTON_INDEX_3:
|
|
|
|
button = BTN_RIGHT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
button = event->detail + BTN_LEFT - 1;
|
|
|
|
return;
|
|
|
|
}
|
2016-11-04 21:48:29 +00:00
|
|
|
|
2019-06-13 09:27:01 +00:00
|
|
|
pointerMotion(QPointF(event->root_x - (*it)->hostPosition().x() + (*it)->internalPosition().x(),
|
|
|
|
event->root_y - (*it)->hostPosition().y() + (*it)->internalPosition().y()) / (*it)->scale(),
|
|
|
|
event->time);
|
2015-05-05 08:44:46 +00:00
|
|
|
if (pressed) {
|
|
|
|
pointerButtonPressed(button, event->time);
|
|
|
|
} else {
|
|
|
|
pointerButtonReleased(button, event->time);
|
|
|
|
}
|
2015-03-19 07:29:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void X11WindowedBackend::handleExpose(xcb_expose_event_t *event)
|
|
|
|
{
|
2015-05-05 08:54:13 +00:00
|
|
|
repaint(QRect(event->x, event->y, event->width, event->height));
|
2015-03-19 07:29:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void X11WindowedBackend::updateSize(xcb_configure_notify_event_t *event)
|
|
|
|
{
|
2019-06-13 09:27:01 +00:00
|
|
|
auto it = std::find_if(m_outputs.begin(), m_outputs.end(),
|
|
|
|
[event] (X11WindowedOutput *output) { return output->window() == event->window; }
|
|
|
|
);
|
|
|
|
if (it == m_outputs.end()) {
|
2015-03-19 07:29:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-06-13 09:27:01 +00:00
|
|
|
|
|
|
|
(*it)->setHostPosition(QPoint(event->x, event->y));
|
|
|
|
|
|
|
|
const QSize s = QSize(event->width, event->height);
|
|
|
|
if (s != (*it)->pixelSize()) {
|
|
|
|
(*it)->setGeometry((*it)->internalPosition(), s);
|
2015-03-19 07:29:34 +00:00
|
|
|
}
|
2019-06-13 09:27:01 +00:00
|
|
|
emit sizeChanged();
|
2015-03-19 07:29:34 +00:00
|
|
|
}
|
|
|
|
|
2018-06-23 17:13:48 +00:00
|
|
|
void X11WindowedBackend::createCursor(const QImage &srcImage, const QPoint &hotspot)
|
2015-06-04 20:05:54 +00:00
|
|
|
{
|
|
|
|
const xcb_pixmap_t pix = xcb_generate_id(m_connection);
|
|
|
|
const xcb_gcontext_t gc = xcb_generate_id(m_connection);
|
|
|
|
const xcb_cursor_t cid = xcb_generate_id(m_connection);
|
|
|
|
|
2018-06-23 17:13:48 +00:00
|
|
|
//right now on X we only have one scale between all screens, and we know we will have at least one screen
|
|
|
|
const qreal outputScale = screenScales().first();
|
|
|
|
const QSize targetSize = srcImage.size() * outputScale / srcImage.devicePixelRatio();
|
|
|
|
const QImage img = srcImage.scaled(targetSize, Qt::KeepAspectRatio);
|
|
|
|
|
2015-06-04 20:05:54 +00:00
|
|
|
xcb_create_pixmap(m_connection, 32, pix, m_screen->root, img.width(), img.height());
|
|
|
|
xcb_create_gc(m_connection, gc, pix, 0, nullptr);
|
|
|
|
|
2019-07-09 21:10:56 +00:00
|
|
|
xcb_put_image(m_connection, XCB_IMAGE_FORMAT_Z_PIXMAP, pix, gc, img.width(), img.height(), 0, 0, 0, 32, img.sizeInBytes(), img.constBits());
|
2015-06-04 20:05:54 +00:00
|
|
|
|
|
|
|
XRenderPicture pic(pix, 32);
|
2018-06-23 17:13:48 +00:00
|
|
|
xcb_render_create_cursor(m_connection, cid, pic, qRound(hotspot.x() * outputScale), qRound(hotspot.y() * outputScale));
|
2019-06-13 09:27:01 +00:00
|
|
|
for (auto it = m_outputs.constBegin(); it != m_outputs.constEnd(); ++it) {
|
|
|
|
xcb_change_window_attributes(m_connection, (*it)->window(), XCB_CW_CURSOR, &cid);
|
2015-11-24 09:47:52 +00:00
|
|
|
}
|
2015-06-04 20:05:54 +00:00
|
|
|
|
|
|
|
xcb_free_pixmap(m_connection, pix);
|
|
|
|
xcb_free_gc(m_connection, gc);
|
|
|
|
if (m_cursor) {
|
|
|
|
xcb_free_cursor(m_connection, m_cursor);
|
|
|
|
}
|
|
|
|
m_cursor = cid;
|
|
|
|
xcb_flush(m_connection);
|
2016-02-23 11:29:05 +00:00
|
|
|
markCursorAsRendered();
|
2015-06-04 20:05:54 +00:00
|
|
|
}
|
|
|
|
|
2015-03-19 10:26:53 +00:00
|
|
|
xcb_window_t X11WindowedBackend::rootWindow() const
|
|
|
|
{
|
|
|
|
if (!m_screen) {
|
|
|
|
return XCB_WINDOW_NONE;
|
|
|
|
}
|
|
|
|
return m_screen->root;
|
|
|
|
}
|
|
|
|
|
2015-03-27 06:52:59 +00:00
|
|
|
Screens *X11WindowedBackend::createScreens(QObject *parent)
|
|
|
|
{
|
2019-06-13 09:27:01 +00:00
|
|
|
return new OutputScreens(this, parent);
|
2015-03-27 06:52:59 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 07:51:56 +00:00
|
|
|
OpenGLBackend *X11WindowedBackend::createOpenGLBackend()
|
|
|
|
{
|
2015-11-25 12:33:40 +00:00
|
|
|
return new EglX11Backend(this);
|
2015-03-27 07:51:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 08:05:03 +00:00
|
|
|
QPainterBackend *X11WindowedBackend::createQPainterBackend()
|
|
|
|
{
|
|
|
|
return new X11WindowedQPainterBackend(this);
|
|
|
|
}
|
|
|
|
|
2015-06-05 17:34:03 +00:00
|
|
|
void X11WindowedBackend::warpPointer(const QPointF &globalPos)
|
|
|
|
{
|
2019-06-13 09:27:01 +00:00
|
|
|
const xcb_window_t w = m_outputs.at(0)->window();
|
2015-11-24 09:47:52 +00:00
|
|
|
xcb_warp_pointer(m_connection, w, w, 0, 0, 0, 0, globalPos.x(), globalPos.y());
|
2015-06-05 17:34:03 +00:00
|
|
|
xcb_flush(m_connection);
|
|
|
|
}
|
|
|
|
|
2015-11-24 08:34:56 +00:00
|
|
|
xcb_window_t X11WindowedBackend::windowForScreen(int screen) const
|
|
|
|
{
|
2019-06-13 09:27:01 +00:00
|
|
|
if (screen > m_outputs.count()) {
|
2015-11-24 09:47:52 +00:00
|
|
|
return XCB_WINDOW_NONE;
|
|
|
|
}
|
2019-06-13 09:27:01 +00:00
|
|
|
return m_outputs.at(screen)->window();
|
2015-11-24 09:47:52 +00:00
|
|
|
}
|
|
|
|
|
2019-06-13 09:27:01 +00:00
|
|
|
Outputs X11WindowedBackend::outputs() const
|
2015-11-24 09:47:52 +00:00
|
|
|
{
|
2019-06-13 09:27:01 +00:00
|
|
|
return m_outputs;
|
2015-11-24 08:34:56 +00:00
|
|
|
}
|
|
|
|
|
2019-06-13 09:27:01 +00:00
|
|
|
Outputs X11WindowedBackend::enabledOutputs() const
|
2016-10-25 23:36:02 +00:00
|
|
|
{
|
2019-06-13 09:27:01 +00:00
|
|
|
return m_outputs;
|
2016-10-25 23:36:02 +00:00
|
|
|
}
|
|
|
|
|
2015-03-19 07:29:34 +00:00
|
|
|
}
|