File indexing completed on 2025-04-27 11:33:01

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 1999, 2000 Matthias Ettrich <ettrich@kde.org>
0006     SPDX-FileCopyrightText: 2003 Lubos Lunak <l.lunak@kde.org>
0007     SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org>
0008 
0009     SPDX-License-Identifier: GPL-2.0-or-later
0010 */
0011 
0012 #pragma once
0013 
0014 #include "x11eventfilter.h"
0015 
0016 #include <xcb/xcb.h>
0017 
0018 #include <functional>
0019 
0020 class QPoint;
0021 
0022 namespace KWin
0023 {
0024 class Window;
0025 
0026 class WindowSelector : public X11EventFilter
0027 {
0028 public:
0029     WindowSelector();
0030     ~WindowSelector() override;
0031 
0032     void start(std::function<void(KWin::Window *)> callback, const QByteArray &cursorName);
0033     void start(std::function<void(const QPoint &)> callback);
0034     bool isActive() const
0035     {
0036         return m_active;
0037     }
0038     void processEvent(xcb_generic_event_t *event);
0039 
0040     bool event(xcb_generic_event_t *event) override;
0041 
0042 private:
0043     xcb_cursor_t createCursor(const QByteArray &cursorName);
0044     void release();
0045     void selectWindowUnderPointer();
0046     void handleKeyPress(xcb_keycode_t keycode, uint16_t state);
0047     void handleButtonRelease(xcb_button_t button, xcb_window_t window);
0048     void selectWindowId(xcb_window_t window_to_kill);
0049     bool activate(const QByteArray &cursorName = QByteArray());
0050     void cancelCallback();
0051     bool m_active;
0052     std::function<void(KWin::Window *)> m_callback;
0053     std::function<void(const QPoint &)> m_pointSelectionFallback;
0054 };
0055 
0056 } // namespace