summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2024-11-15 20:24:40 +0100
committerMatthias Melcher <github@matthiasm.com>2024-11-15 20:27:07 +0100
commit114fb66cd38f10c14a076108eb8f77e75a107174 (patch)
tree0a4187a22e27d7ea8388d25fb2393587040bce7a
parent176b0a06a32c15869893a5bc44b7f961d081c838 (diff)
Fixes Alt-modifier handling in Fl_Shorcut_Button on macOS
-rw-r--r--src/Fl_Shortcut_Button.cxx13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/Fl_Shortcut_Button.cxx b/src/Fl_Shortcut_Button.cxx
index 9f19fa0b4..7e04183bc 100644
--- a/src/Fl_Shortcut_Button.cxx
+++ b/src/Fl_Shortcut_Button.cxx
@@ -19,6 +19,7 @@
#include <FL/Fl.H>
#include <FL/fl_draw.H>
#include <FL/fl_utf8.h>
+#include "Fl_System_Driver.H"
#include "flstring.h"
#include <ctype.h>
@@ -174,6 +175,7 @@ void Fl_Shortcut_Button::do_end_hot_callback() {
Handle keystrokes to catch the user's shortcut.
*/
int Fl_Shortcut_Button::handle(int e) {
+ static int alt_modifier_extra_handler = Fl::system_driver()->need_test_shortcut_extra();
#if 0
bool inside_default_button = false;
if (default_set_ && ( (e == FL_PUSH) || (e == FL_DRAG) || (e == FL_RELEASE) ) ) {
@@ -235,6 +237,17 @@ int Fl_Shortcut_Button::handle(int e) {
// type, so we don't handle them here either
// Todo: use fl_utf_tolower and fl_utf_toupper
int v = fl_utf8decode(Fl::event_text(), 0, 0);
+ if (alt_modifier_extra_handler && Fl::event_state(FL_ALT)) {
+ // MacOS returns special characters when the alt modifier is held down.
+ // FLTK handles shortcuts as ASCII keys, so let's convert the keystroke.
+ int c = Fl::event_key();
+ if ( (c>32) && (c<128) && (isalnum(c)) ) {
+ v = c;
+ if (Fl::event_state(FL_SHIFT)) {
+ v = toupper(c);
+ }
+ }
+ }
if ( (v > 32 && v < 0x7f) || (v > 0xa0 && v <= 0xff) ) {
if (isupper(v)) {
v = tolower(v);