File indexing completed on 2024-11-10 04:57:51

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2017 Martin Flöser <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #include "moving_client_x11_filter.h"
0010 #include "workspace.h"
0011 #include "x11window.h"
0012 #include <KKeyServer>
0013 #include <xcb/xcb.h>
0014 
0015 namespace KWin
0016 {
0017 
0018 MovingClientX11Filter::MovingClientX11Filter()
0019     : X11EventFilter(QList<int>{XCB_KEY_PRESS, XCB_KEY_RELEASE, XCB_MOTION_NOTIFY, XCB_BUTTON_PRESS, XCB_BUTTON_RELEASE})
0020 {
0021 }
0022 
0023 bool MovingClientX11Filter::event(xcb_generic_event_t *event)
0024 {
0025     auto client = dynamic_cast<X11Window *>(workspace()->moveResizeWindow());
0026     if (!client) {
0027         return false;
0028     }
0029     auto testWindow = [client, event](xcb_window_t window) {
0030         return client->moveResizeGrabWindow() == window && client->windowEvent(event);
0031     };
0032 
0033     const uint8_t eventType = event->response_type & ~0x80;
0034     switch (eventType) {
0035     case XCB_KEY_PRESS: {
0036         int keyQt;
0037         xcb_key_press_event_t *keyEvent = reinterpret_cast<xcb_key_press_event_t *>(event);
0038         KKeyServer::xcbKeyPressEventToQt(keyEvent, &keyQt);
0039         client->keyPressEvent(keyQt, keyEvent->time);
0040         if (client->isInteractiveMove() || client->isInteractiveResize()) {
0041             const QPointF global = QPointF(Xcb::fromXNative(keyEvent->root_x), Xcb::fromXNative(keyEvent->root_y));
0042             client->updateInteractiveMoveResize(global);
0043         }
0044         return true;
0045     }
0046     case XCB_KEY_RELEASE: {
0047         if (client->isInteractiveMove() || client->isInteractiveResize()) {
0048             auto *keyEvent = reinterpret_cast<xcb_key_release_event_t *>(event);
0049             const QPointF global = QPointF(Xcb::fromXNative(keyEvent->root_x), Xcb::fromXNative(keyEvent->root_y));
0050             client->updateInteractiveMoveResize(global);
0051         }
0052         return true;
0053     }
0054     case XCB_BUTTON_PRESS:
0055     case XCB_BUTTON_RELEASE:
0056         return testWindow(reinterpret_cast<xcb_button_press_event_t *>(event)->event);
0057     case XCB_MOTION_NOTIFY:
0058         return testWindow(reinterpret_cast<xcb_motion_notify_event_t *>(event)->event);
0059     }
0060     return false;
0061 }
0062 
0063 }