diff options
author | Michele Calgaro <[email protected]> | 2021-03-25 10:01:12 +0900 |
---|---|---|
committer | Michele Calgaro <[email protected]> | 2021-03-26 20:35:52 +0900 |
commit | f2290a769bd9ee9bdde3a9c9a25d1fd27decaabc (patch) | |
tree | 0b2024bb26617ca2c4339b5c1a9bd33ec4cbcb1e /src/VButton.cpp | |
parent | 96fd31212c67029bb71e7a0f69ada626e11f2ee2 (diff) | |
download | kvkbd-f2290a769bd9ee9bdde3a9c9a25d1fd27decaabc.tar.gz kvkbd-f2290a769bd9ee9bdde3a9c9a25d1fd27decaabc.zip |
Added support for AltGr characters. This resolves issue #11.
Signed-off-by: Michele Calgaro <[email protected]>
(cherry picked from commit 85af0341dc94a5a65d3643f53d95c21d40017c1c)
Diffstat (limited to 'src/VButton.cpp')
-rw-r--r-- | src/VButton.cpp | 97 |
1 files changed, 74 insertions, 23 deletions
diff --git a/src/VButton.cpp b/src/VButton.cpp index 1959990..95d31e2 100644 --- a/src/VButton.cpp +++ b/src/VButton.cpp @@ -28,61 +28,112 @@ void VButton::setupTexts(Display *display) { // normal text KeySym keysym_c = XkbKeycodeToKeysym(display, keycode, 0, 0); - TQChar c((uint)keysym2ucs(keysym_c)); - if (c == '&') + TQChar nc((uint)keysym2ucs(keysym_c)); + if (nc == '&') { setText("&&"); } else { - setText(c); + setText(nc); } // shift text keysym_c = XkbKeycodeToKeysym(display, keycode, 0, 1); + TQChar sc = (uint)keysym2ucs(keysym_c); + if (sc == '&') + { + setShiftText("&&"); + } + else + { + setShiftText(sc); + } + + // altGr text + keysym_c = XkbKeycodeToKeysym(display, keycode, 0, 2); + TQChar c = (uint)keysym2ucs(keysym_c); + if (c == " ") + { + // use normal text in case altGr does not provide extra characters. + // This is required at least on US keyboards, where altGr works as Alt. + c = nc; + } + if (c == '&') + { + altGrText = "&&"; + } + else + { + altGrText = c; + } + + // altGr + shift text + keysym_c = XkbKeycodeToKeysym(display, keycode, 0, 3); c = (uint)keysym2ucs(keysym_c); + if (c == " ") + { + // use shift text in case altGr does not provide extra characters. + // This is required at least on US keyboards, where altGr works as Alt. + c = sc; + } if (c == '&') { - setShiftText("&&"); + altGrShiftText = "&&"; } else { - setShiftText(c); + altGrShiftText = c; } } -void VButton::shiftCapsPressed(bool shift, bool caps) +void VButton::shiftCapsAltGrPressed(bool shift, bool caps, bool altGrState) { - if (isAlpha) + if (altGrState) { - // Alpha button, both shift and caps affect its state - if (caps && shift) - { - TQPushButton::setText(capsShiftText); - } - else if (caps) - { - TQPushButton::setText(capsText); - } - else if (shift) + // Caps does not seem to make any difference when AltGr is pressed + if (shift) { - TQPushButton::setText(shiftText); + TQPushButton::setText(altGrShiftText); } else { - TQPushButton::setText(normalText); + TQPushButton::setText(altGrText); } } else { - // Non alpha button, only shift affects its state - if (shift) + if (isAlpha) { - TQPushButton::setText(shiftText); + // Alpha button, both shift and caps affect its state + if (caps && shift) + { + TQPushButton::setText(capsShiftText); + } + else if (caps) + { + TQPushButton::setText(capsText); + } + else if (shift) + { + TQPushButton::setText(shiftText); + } + else + { + TQPushButton::setText(normalText); + } } else { - TQPushButton::setText(normalText); + // Non alpha button, only shift affects its state + if (shift) + { + TQPushButton::setText(shiftText); + } + else + { + TQPushButton::setText(normalText); + } } } } |