Commit 4172ef3b authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Turn switch statement into a hash

Summary: This way we can reverse-lookup if we ever want the opposite information.

Reviewers: #kwin, romangg

Reviewed By: #kwin, romangg

Subscribers: zzag, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D25763
parent f5a73b87
...@@ -59,52 +59,38 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -59,52 +59,38 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin namespace KWin
{ {
static const QHash<uint32_t, Qt::MouseButton> s_buttonToQtMouseButton = {
{ BTN_LEFT , Qt::LeftButton },
{ BTN_MIDDLE , Qt::MiddleButton },
{ BTN_RIGHT , Qt::RightButton },
// in QtWayland mapped like that
{ BTN_SIDE , Qt::ExtraButton1 },
// in QtWayland mapped like that
{ BTN_EXTRA , Qt::ExtraButton2 },
{ BTN_BACK , Qt::BackButton },
{ BTN_FORWARD , Qt::ForwardButton },
{ BTN_TASK , Qt::TaskButton },
// mapped like that in QtWayland
{ 0x118 , Qt::ExtraButton6 },
{ 0x119 , Qt::ExtraButton7 },
{ 0x11a , Qt::ExtraButton8 },
{ 0x11b , Qt::ExtraButton9 },
{ 0x11c , Qt::ExtraButton10 },
{ 0x11d , Qt::ExtraButton11 },
{ 0x11e , Qt::ExtraButton12 },
{ 0x11f , Qt::ExtraButton13 },
};
static Qt::MouseButton buttonToQtMouseButton(uint32_t button) static Qt::MouseButton buttonToQtMouseButton(uint32_t button)
{ {
switch (button) {
case BTN_LEFT:
return Qt::LeftButton;
case BTN_MIDDLE:
return Qt::MiddleButton;
case BTN_RIGHT:
return Qt::RightButton;
case BTN_SIDE:
// in QtWayland mapped like that
return Qt::ExtraButton1;
case BTN_EXTRA:
// in QtWayland mapped like that
return Qt::ExtraButton2;
case BTN_BACK:
return Qt::BackButton;
case BTN_FORWARD:
return Qt::ForwardButton;
case BTN_TASK:
return Qt::TaskButton;
// mapped like that in QtWayland
case 0x118:
return Qt::ExtraButton6;
case 0x119:
return Qt::ExtraButton7;
case 0x11a:
return Qt::ExtraButton8;
case 0x11b:
return Qt::ExtraButton9;
case 0x11c:
return Qt::ExtraButton10;
case 0x11d:
return Qt::ExtraButton11;
case 0x11e:
return Qt::ExtraButton12;
case 0x11f:
return Qt::ExtraButton13;
}
// all other values get mapped to ExtraButton24 // all other values get mapped to ExtraButton24
// this is actually incorrect but doesn't matter in our usage // this is actually incorrect but doesn't matter in our usage
// KWin internally doesn't use these high extra buttons anyway // KWin internally doesn't use these high extra buttons anyway
// it's only needed for recognizing whether buttons are pressed // it's only needed for recognizing whether buttons are pressed
// if multiple buttons are mapped to the value the evaluation whether // if multiple buttons are mapped to the value the evaluation whether
// buttons are pressed is correct and that's all we care about. // buttons are pressed is correct and that's all we care about.
return Qt::ExtraButton24; return s_buttonToQtMouseButton.value(button, Qt::ExtraButton24);
}
} }
static bool screenContainsPos(const QPointF &pos) static bool screenContainsPos(const QPointF &pos)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment