mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:07:34 +00:00
LibGUI: Allow Shortcuts to have a mouse button associated with them
A Shortcut can now be either have a keyboard key, or a mouse button, along with any modifiers. Decided to add an extra type field instead of subclassing, which means callers will have to be a little careful before accessing a particular input method's "key", but it keeps things simple for now.
This commit is contained in:
parent
8b9b836a0e
commit
a252c3e058
2 changed files with 62 additions and 15 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2022, Geordie Hall <me@geordiehall.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -24,10 +25,17 @@ String Shortcut::to_string() const
|
|||
if (m_modifiers & Mod_Super)
|
||||
parts.append("Super");
|
||||
|
||||
if (auto* key_name = key_code_to_string(m_key))
|
||||
parts.append(key_name);
|
||||
else
|
||||
parts.append("(Invalid)");
|
||||
if (m_type == Type::Keyboard) {
|
||||
if (auto* key_name = key_code_to_string(m_keyboard_key))
|
||||
parts.append(key_name);
|
||||
else
|
||||
parts.append("(Invalid)");
|
||||
} else {
|
||||
if (m_mouse_button != MouseButton::None)
|
||||
parts.append(String::formatted("Mouse {}", mouse_button_to_string(m_mouse_button)));
|
||||
else
|
||||
parts.append("(Invalid)");
|
||||
}
|
||||
|
||||
StringBuilder builder;
|
||||
builder.join('+', parts);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue