Skip to content

Add support to use mouse buttons (including X1 & X2) as shortcuts (fix #598) #4927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: beta
Choose a base branch
from

Conversation

dacap
Copy link
Member

@dacap dacap commented Jan 10, 2025

This is a work-in-progress to fix #598

@dacap dacap self-assigned this Jan 10, 2025
Copy link
Collaborator

@aseprite-bot aseprite-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

return os::Shortcut(
(accel.unicodeChar() ? accel.unicodeChar() : from_scancode_to_unicode(accel.scancode())),
accel.modifiers());
return os::Shortcut((shortcut.unicodeChar() ? shortcut.unicodeChar() :
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion]

Suggested change
return os::Shortcut((shortcut.unicodeChar() ? shortcut.unicodeChar() :
return os::Shortcut(((shortcut.unicodeChar() != 0) ? shortcut.unicodeChar() :

{
LockButtons lock(this);
ui::Accelerator accel;
SelectAccelerator window(accel, m_key ? m_key->keycontext() : KeyContext::Any, m_keys);
ui::Shortcut shortcut;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'shortcut' of type 'ui::Shortcut' can be declared 'const' [misc-const-correctness]

Suggested change
ui::Shortcut shortcut;
ui::Shortcut const shortcut;

int y = bounds.y;
int dh = textSize().h + 4 * guiscale();
int maxi = (accels && accels->size() > 1 ? accels->size() : 1);
int maxi = (shortcuts && shortcuts->size() > 1 ? shortcuts->size() : 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'maxi' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int maxi = (shortcuts && shortcuts->size() > 1 ? shortcuts->size() : 1);
int const maxi = (shortcuts && shortcuts->size() > 1 ? shortcuts->size() : 1);

}

std::string getAccelText(const Accelerator& accel) const
std::string getShortcutText(const Shortcut& shortcut) const
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: method 'getShortcutText' can be made static [readability-convert-member-functions-to-static]

Suggested change
std::string getShortcutText(const Shortcut& shortcut) const
static std::string getShortcutText(const Shortcut& shortcut)

const ui::Accelerator* isPressed(const ui::Message* msg,
const KeyboardShortcuts& globalKeys) const;
const ui::Shortcuts& shortcuts() const;
const KeySourceShortcutList addsKeys() const { return m_adds; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: return type 'const KeySourceShortcutList' (aka 'const vector<std::pair<KeySource, ui::Shortcut>>') is 'const'-qualified at the top level, which may reduce code readability without improving const correctness [readability-const-return-type]

Suggested change
const KeySourceShortcutList addsKeys() const { return m_adds; }
KeySourceShortcutList addsKeys() const { return m_adds; }

const KeyboardShortcuts& globalKeys,
const KeyContext keyContext) const
const ui::Shortcut* Key::isPressed(const Message* msg,
const KeyboardShortcuts& globalKeys,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: parameter 'globalKeys' is unused [misc-unused-parameters]

Suggested change
const KeyboardShortcuts& globalKeys,
const KeyboardShortcuts& /*globalKeys*/,

}

bool Key::hasUserDefinedAccels() const
bool Key::hasUserDefinedShortcuts() const
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: method 'hasUserDefinedShortcuts' can be made static [readability-convert-member-functions-to-static]

src/app/ui/key.h:135:

-   bool hasUserDefinedShortcuts() const;
+   static bool hasUserDefinedShortcuts() ;
Suggested change
bool Key::hasUserDefinedShortcuts() const
bool Key::hasUserDefinedShortcuts()

const Key* key,
const ui::Accelerator& accel,
bool removed)
void KeyboardShortcuts::exportShortcut(XMLElement* parent,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: method 'exportShortcut' can be made static [readability-convert-member-functions-to-static]

src/app/ui/keyboard_shortcuts.h:79:

-   void exportShortcut(tinyxml2::XMLElement* parent,
+   static void exportShortcut(tinyxml2::XMLElement* parent,

const KeyContext keyContext,
const Key* newKey);
void disableShortcut(const ui::Shortcut& shortcut,
const KeySource source,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: parameter 'source' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls]

Suggested change
const KeySource source,
KeySource source,

const Key* newKey);
void disableShortcut(const ui::Shortcut& shortcut,
const KeySource source,
const KeyContext keyContext,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: parameter 'keyContext' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls]

Suggested change
const KeyContext keyContext,
KeyContext keyContext,

@dacap dacap linked an issue Jan 10, 2025 that may be closed by this pull request
Copy link
Collaborator

@aseprite-bot aseprite-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@@ -1753,6 +1757,11 @@ void Manager::onNewDisplayConfiguration(Display* display)
container->flushRedraw();
}

bool Manager::onEnqueueMouseDown(MouseMessage* mouseMsg)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: parameter 'mouseMsg' is unused [misc-unused-parameters]

Suggested change
bool Manager::onEnqueueMouseDown(MouseMessage* mouseMsg)
bool Manager::onEnqueueMouseDown(MouseMessage* /*mouseMsg*/)

Copy link
Collaborator

@aseprite-bot aseprite-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

updateText();
}

obs::signal<void(const ui::Shortcut*)> ShortcutChange;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable 'ShortcutChange' has public visibility [misc-non-private-member-variables-in-classes]

  obs::signal<void(const ui::Shortcut*)> ShortcutChange;
                                         ^

case kKeyDownMessage:
if (hasFocus() && !isReadOnly()) {
KeyMessage* keymsg = static_cast<KeyMessage*>(msg);
if (!keymsg->scancode() && keymsg->unicodeChar() < 32)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: implicit conversion 'KeyScancode' (aka 'os::KeyScancode') -> 'bool' [readability-implicit-bool-conversion]

Suggested change
if (!keymsg->scancode() && keymsg->unicodeChar() < 32)
if ((keymsg->scancode() == 0u) && keymsg->unicodeChar() < 32)

setText(tmp.toString());
}

Shortcut m_shortcut;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable 'm_shortcut' has protected visibility [misc-non-private-member-variables-in-classes]

  Shortcut m_shortcut;
           ^

addChild(&m_tooltipManager);
}

void SelectShortcut::onModifierChange(KeyModifiers modifier, CheckBox* checkbox)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: pointer parameter 'checkbox' can be pointer to const [readability-non-const-parameter]

Suggested change
void SelectShortcut::onModifierChange(KeyModifiers modifier, CheckBox* checkbox)
void SelectShortcut::onModifierChange(KeyModifiers modifier, const CheckBox* checkbox)

{
bool state = (checkbox->isSelected());
KeyModifiers modifiers = m_shortcut.modifiers();
KeyScancode scancode = m_shortcut.scancode();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'scancode' of type 'KeyScancode' (aka 'os::KeyScancode') can be declared 'const' [misc-const-correctness]

Suggested change
KeyScancode scancode = m_shortcut.scancode();
KeyScancode const scancode = m_shortcut.scancode();

alt()->setSelected(m_shortcut.modifiers() & kKeyAltModifier ? true : false);
ctrl()->setSelected(m_shortcut.modifiers() & kKeyCtrlModifier ? true : false);
shift()->setSelected(m_shortcut.modifiers() & kKeyShiftModifier ? true : false);
space()->setSelected(m_shortcut.modifiers() & kKeySpaceModifier ? true : false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion]

  space()->setSelected(m_shortcut.modifiers() & kKeySpaceModifier ? true : false);
                       ^

this fix will not be applied because it overlaps with another fix

alt()->setSelected(m_shortcut.modifiers() & kKeyAltModifier ? true : false);
ctrl()->setSelected(m_shortcut.modifiers() & kKeyCtrlModifier ? true : false);
shift()->setSelected(m_shortcut.modifiers() & kKeyShiftModifier ? true : false);
space()->setSelected(m_shortcut.modifiers() & kKeySpaceModifier ? true : false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: redundant boolean literal in ternary expression result [readability-simplify-boolean-expr]

Suggested change
space()->setSelected(m_shortcut.modifiers() & kKeySpaceModifier ? true : false);
space()->setSelected((m_shortcut.modifiers() & kKeySpaceModifier) != 0);

"Also known as Windows key, logo key,\ncommand key, or system key.",
TOP);
#endif
win()->setSelected(m_shortcut.modifiers() & kKeyWinModifier ? true : false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion]

  win()->setSelected(m_shortcut.modifiers() & kKeyWinModifier ? true : false);
                     ^

this fix will not be applied because it overlaps with another fix

"Also known as Windows key, logo key,\ncommand key, or system key.",
TOP);
#endif
win()->setSelected(m_shortcut.modifiers() & kKeyWinModifier ? true : false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: redundant boolean literal in ternary expression result [readability-simplify-boolean-expr]

Suggested change
win()->setSelected(m_shortcut.modifiers() & kKeyWinModifier ? true : false);
win()->setSelected((m_shortcut.modifiers() & kKeyWinModifier) != 0);

#endif
}

void SelectShortcut::updateAssignedTo()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: method 'updateAssignedTo' can be made static [readability-convert-member-functions-to-static]

src/app/ui/select_shortcut.h:37:

-   void updateAssignedTo();
+   static void updateAssignedTo();

dacap added 2 commits February 7, 2025 15:13
This was a pending refactor, where "user.aseprite-keys" files were
already using the "shortcut" attribute (instead of "accelerator").
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make special mouse buttons customizable
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy