Merge branch 'add-win-key-modifier' of https://github.com/sirblackheart/aseprite into sirblackheart-add-win-key-modifier

This commit is contained in:
David Capello 2016-03-02 09:38:06 -03:00
commit cd8dabb3d2
10 changed files with 32 additions and 3 deletions

View File

@ -15,6 +15,7 @@
<check text="Alt" id="alt" />
<check text="Shift" id="shift" />
<check text="Space" id="space" />
<check text="Win" id="win" />
</hbox>
<label text="Assigned to:" />

View File

@ -95,6 +95,7 @@ SelectAccelerator::SelectAccelerator(const ui::Accelerator& accel, KeyContext ke
ctrl()->Click.connect(base::Bind<void>(&SelectAccelerator::onModifierChange, this, kKeyCtrlModifier, ctrl()));
shift()->Click.connect(base::Bind<void>(&SelectAccelerator::onModifierChange, this, kKeyShiftModifier, shift()));
space()->Click.connect(base::Bind<void>(&SelectAccelerator::onModifierChange, this, kKeySpaceModifier, space()));
win()->Click.connect(base::Bind<void>(&SelectAccelerator::onModifierChange, this, kKeyWinModifier, win()));
m_keyField->AccelChange.connect(&SelectAccelerator::onAccelChange, this);
clearButton()->Click.connect(base::Bind<void>(&SelectAccelerator::onClear, this));
@ -156,8 +157,13 @@ void SelectAccelerator::updateModifiers()
shift()->setSelected(m_accel.modifiers() & kKeyShiftModifier ? true: false);
space()->setSelected(m_accel.modifiers() & kKeySpaceModifier ? true: false);
#if __APPLE__
win()->setVisible(false);
cmd()->setSelected(m_accel.modifiers() & kKeyCmdModifier ? true: false);
#else
#if __linux__
win()->setText(winKeyName);
#endif
win()->setSelected(m_accel.modifiers() & kKeyWinModifier ? true: false);
cmd()->setVisible(false);
#endif
}

View File

@ -46,7 +46,9 @@ void she_keyboard_lowlevel_callback(int scancode)
scancode == KEY_LSHIFT ||
scancode == KEY_LCONTROL ||
scancode == KEY_ALT ||
scancode == KEY_COMMAND) {
scancode == KEY_COMMAND ||
scancode == KEY_LWIN ||
scancode == KEY_RWIN ) {
she_keyboard_ucallback(-1, &scancode);
}
return;

View File

@ -17,7 +17,8 @@ namespace she {
kKeyAltModifier = 4,
kKeyCmdModifier = 8,
kKeySpaceModifier = 16,
kKeyUninitializedModifier = 32,
kKeyWinModifier = 32,
kKeyUninitializedModifier = 64,
};
enum KeyScancode {

View File

@ -309,6 +309,9 @@ KeyModifiers get_modifiers_from_last_win32_message()
modifiers |= kKeyAltModifier;
if (GetKeyState(VK_SPACE) & 0x8000)
modifiers |= kKeySpaceModifier;
if (GetKeyState(kKeyLWin) & 0x8000) ||
(GetKeyState(kKeyRWin) & 0x8000))
modifiers |= kKeyWinModifier;
return (KeyModifiers)modifiers;
}

View File

@ -36,6 +36,8 @@ static KeyModifiers get_pressed_modifiers_from_she()
if (she::is_key_pressed(kKeyRControl)) mods = KeyModifiers(int(mods) | int(kKeyCtrlModifier));
if (she::is_key_pressed(kKeyAlt) ) mods = KeyModifiers(int(mods) | int(kKeyAltModifier));
if (she::is_key_pressed(kKeyCommand) ) mods = KeyModifiers(int(mods) | int(kKeyCmdModifier));
if (she::is_key_pressed(kKeyLWin) ) mods = KeyModifiers(int(mods) | int(kKeyWinModifier));
if (she::is_key_pressed(kKeyRWin) ) mods = KeyModifiers(int(mods) | int(kKeyWinModifier));
return mods;
}
@ -89,6 +91,9 @@ Accelerator::Accelerator(const std::string& str)
else if (tok == "cmd") {
m_modifiers = (KeyModifiers)((int)m_modifiers | (int)kKeyCmdModifier);
}
else if (tok == base::string_to_lower(winKeyName)) {
m_modifiers = (KeyModifiers)((int)m_modifiers | (int)kKeyWinModifier);
}
// Scancode
@ -347,6 +352,7 @@ std::string Accelerator::toString() const
if (m_modifiers & kKeyAltModifier) buf += "Alt+";
if (m_modifiers & kKeyShiftModifier) buf += "Shift+";
if (m_modifiers & kKeySpaceModifier) buf += "Space+";
if (m_modifiers & kKeyWinModifier) { buf += winKeyName; buf += "+"; }
// Key
if (m_unicodeChar) {

View File

@ -15,6 +15,12 @@
namespace ui {
#ifdef _WIN32
const std::string winKeyName = "Win";
#else
const std::string winKeyName = "Super";
#endif
class Accelerator {
public:
Accelerator();

View File

@ -21,6 +21,7 @@ namespace ui {
using she::kKeyAltModifier;
using she::kKeyCmdModifier;
using she::kKeySpaceModifier;
using she::kKeyWinModifier;
using she::kKeyUninitializedModifier;
using she::kKeyNil;

View File

@ -30,7 +30,8 @@ Message::Message(MessageType type, KeyModifiers modifiers)
(she::is_key_pressed(kKeyLControl) || she::is_key_pressed(kKeyRControl) ? kKeyCtrlModifier: 0) |
(she::is_key_pressed(kKeyAlt) ? kKeyAltModifier: 0) |
(she::is_key_pressed(kKeyCommand) ? kKeyCmdModifier: 0) |
(she::is_key_pressed(kKeySpace) ? kKeySpaceModifier: 0));
(she::is_key_pressed(kKeySpace) ? kKeySpaceModifier: 0) |
(she::is_key_pressed(kKeyLWin) || she::is_key_pressed(kKeyRWin) ? kKeyWinModifier: 0));
}
else {
m_modifiers = modifiers;

View File

@ -42,10 +42,12 @@ namespace ui {
bool ctrlPressed() const { return (m_modifiers & kKeyCtrlModifier) == kKeyCtrlModifier; }
bool altPressed() const { return (m_modifiers & kKeyAltModifier) == kKeyAltModifier; }
bool cmdPressed() const { return (m_modifiers & kKeyCmdModifier) == kKeyCmdModifier; }
bool winPressed() const { return (m_modifiers & kKeyWinModifier) == kKeyWinModifier; }
bool onlyShiftPressed() const { return m_modifiers == kKeyShiftModifier; }
bool onlyCtrlPressed() const { return m_modifiers == kKeyCtrlModifier; }
bool onlyAltPressed() const { return m_modifiers == kKeyAltModifier; }
bool onlyCmdPressed() const { return m_modifiers == kKeyCmdModifier; }
bool onlyWinPressed() const { return m_modifiers == kKeyWinModifier; }
void addRecipient(Widget* widget);
void prependRecipient(Widget* widget);