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

0001 /*
0002     SPDX-FileCopyrightText: 2022 David Redondo <kde@david-redondo.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "mousebuttons.h"
0008 #include <QHash>
0009 #include <linux/input-event-codes.h>
0010 
0011 namespace KWin
0012 {
0013 
0014 static const QHash<uint32_t, Qt::MouseButton> s_buttonToQtMouseButton = {
0015     {BTN_LEFT, Qt::LeftButton},
0016     {BTN_MIDDLE, Qt::MiddleButton},
0017     {BTN_RIGHT, Qt::RightButton},
0018     // in QtWayland mapped like that
0019     {BTN_SIDE, Qt::ExtraButton1},
0020     {BTN_EXTRA, Qt::ExtraButton2},
0021     {BTN_FORWARD, Qt::ExtraButton3},
0022     {BTN_BACK, Qt::ExtraButton4},
0023     {BTN_TASK, Qt::ExtraButton5},
0024     {0x118, Qt::ExtraButton6},
0025     {0x119, Qt::ExtraButton7},
0026     {0x11a, Qt::ExtraButton8},
0027     {0x11b, Qt::ExtraButton9},
0028     {0x11c, Qt::ExtraButton10},
0029     {0x11d, Qt::ExtraButton11},
0030     {0x11e, Qt::ExtraButton12},
0031     {0x11f, Qt::ExtraButton13},
0032 };
0033 
0034 uint32_t qtMouseButtonToButton(Qt::MouseButton button)
0035 {
0036     return s_buttonToQtMouseButton.key(button);
0037 }
0038 
0039 Qt::MouseButton buttonToQtMouseButton(uint32_t button)
0040 {
0041     // all other values get mapped to ExtraButton24
0042     // this is actually incorrect but doesn't matter in our usage
0043     // KWin internally doesn't use these high extra buttons anyway
0044     // it's only needed for recognizing whether buttons are pressed
0045     // if multiple buttons are mapped to the value the evaluation whether
0046     // buttons are pressed is correct and that's all we care about.
0047     return s_buttonToQtMouseButton.value(button, Qt::ExtraButton24);
0048 }
0049 
0050 }