KWin
Loading...
Searching...
No Matches
mousebuttons.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2022 David Redondo <kde@david-redondo.de>
3
4 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
5*/
6
7#include "mousebuttons.h"
8#include <QHash>
9#include <linux/input-event-codes.h>
10
11namespace KWin
12{
13
14static const QHash<uint32_t, Qt::MouseButton> s_buttonToQtMouseButton = {
15 {BTN_LEFT, Qt::LeftButton},
16 {BTN_MIDDLE, Qt::MiddleButton},
17 {BTN_RIGHT, Qt::RightButton},
18 // in QtWayland mapped like that
19 {BTN_SIDE, Qt::ExtraButton1},
20 {BTN_EXTRA, Qt::ExtraButton2},
21 {BTN_FORWARD, Qt::ExtraButton3},
22 {BTN_BACK, Qt::ExtraButton4},
23 {BTN_TASK, Qt::ExtraButton5},
24 {0x118, Qt::ExtraButton6},
25 {0x119, Qt::ExtraButton7},
26 {0x11a, Qt::ExtraButton8},
27 {0x11b, Qt::ExtraButton9},
28 {0x11c, Qt::ExtraButton10},
29 {0x11d, Qt::ExtraButton11},
30 {0x11e, Qt::ExtraButton12},
31 {0x11f, Qt::ExtraButton13},
32};
33
34uint32_t qtMouseButtonToButton(Qt::MouseButton button)
35{
36 return s_buttonToQtMouseButton.key(button);
37}
38
39Qt::MouseButton buttonToQtMouseButton(uint32_t button)
40{
41 // all other values get mapped to ExtraButton24
42 // this is actually incorrect but doesn't matter in our usage
43 // KWin internally doesn't use these high extra buttons anyway
44 // it's only needed for recognizing whether buttons are pressed
45 // if multiple buttons are mapped to the value the evaluation whether
46 // buttons are pressed is correct and that's all we care about.
47 return s_buttonToQtMouseButton.value(button, Qt::ExtraButton24);
48}
49
50}
uint32_t qtMouseButtonToButton(Qt::MouseButton button)
Qt::MouseButton buttonToQtMouseButton(uint32_t button)