File indexing completed on 2024-02-25 17:23:45

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(QVector<int>{XCB_KEY_PRESS, 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         return true;
0041     }
0042     case XCB_BUTTON_PRESS:
0043     case XCB_BUTTON_RELEASE:
0044         return testWindow(reinterpret_cast<xcb_button_press_event_t *>(event)->event);
0045     case XCB_MOTION_NOTIFY:
0046         return testWindow(reinterpret_cast<xcb_motion_notify_event_t *>(event)->event);
0047     }
0048     return false;
0049 }
0050 
0051 }