Skip to content

Commit 7c864d8

Browse files
MGTK: Don't invoke first menu item without shortcuts on ^@
Control+Shift+2 a.k.a. ^@ yields the ASCII NUL value. This was used in the menu definitions to signal "no shortcut". MGTK didn't special-case this, so the first menu item without a shortcut would be invoked when this key combination was pressed. In DeskTop this was "About Apple II DeskTop" so the dialog would show! Address this by having the menu defining macros put a value with the high bit set; MGTK strips the high bit from the keyboard input so it can never match. This allows MGTK apps to actually define a shortcut with ^@ if they want to.
1 parent 8b64809 commit 7c864d8

File tree

5 files changed

+39
-15
lines changed

5 files changed

+39
-15
lines changed

RELEASE-NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Project Page: https://github.com/a2stuff/a2d
3131
* Time window open/close animations using VBL.
3232
* Add Apple+Escape as shortcut to clear selection.
3333
* Prevent volume icon flicker on startup with empty Disk II drives.
34+
* Don't show About dialog when Ctrl+Shift+2 is pressed.
3435

3536
### Selector
3637

src/desktop/auxmem.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ label_show_link:
155155
DEFINE_MENU_ITEM label_close_all
156156
DEFINE_MENU_SEPARATOR
157157
DEFINE_MENU_ITEM label_get_info, res_char_menu_item_get_info_shortcut
158-
DEFINE_MENU_ITEM_NOMOD label_rename_icon, CHAR_RETURN, CHAR_RETURN
158+
DEFINE_MENU_ITEM_NOMOD label_rename_icon, CHAR_RETURN
159159
DEFINE_MENU_ITEM label_duplicate_icon, res_char_menu_item_duplicate_shortcut
160160
DEFINE_MENU_SEPARATOR
161161
DEFINE_MENU_ITEM label_copy_selection

src/mgtk/MGTK.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,12 +513,17 @@ Menu record:
513513
514514
.byte options bit 0=OA, 1=SA, 2=mark, 5=check, 6=filler, 7=disabled
515515
.byte mark_char Custom mark character if mark option set
516-
.byte char1 ASCII code of shortcut #1 (e.g. uppercase B); or 0
517-
.byte char2 ASCII code of shortcut #2 (e.g. lowercase b, or same); or 0
516+
.byte char1 ASCII code of shortcut #1 (e.g. uppercase B); MGTK::no_shortcut if none
517+
.byte char2 ASCII code of shortcut #2 (e.g. lowercase b, or same); MGTK::no_shortcut if none
518518
.addr name Address of length-prefixed string
519519
... repeats for each menu item
520520
```
521521

522+
Since 0 is typeable character (Control+Shift+2 a.k.a. ^@, ASCII `NUL`), a byte with the high bit set signals "no shortcut".
523+
```
524+
MGTK::no_shortcut = $FF
525+
```
526+
522527
### Window "winfo"
523528
```
524529
.byte id

src/mgtk/mgtk.inc

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ SetKeyEvent = $2E ; If set, keypresses are ignored by Tool Kit
324324
;;; --------------------------------------------------
325325
;;; Menu Manager Calls
326326

327+
;;; Since 0 is a valid ASCII code (Ctrl+Shift+2 produces ^@ a.k.a.
328+
;;; NUL), an arbitrary value with the high bit set should be used to
329+
;;; signify "no shortuct".
330+
no_shortcut = $FF
331+
327332
;;; Menu Bar record:
328333
;;;
329334
;;; .word count Number of menu bar items
@@ -347,8 +352,8 @@ SetKeyEvent = $2E ; If set, keypresses are ignored by Tool Kit
347352
.struct MenuItem
348353
options .byte ; bit 0=OA, 1=SA, 2=mark, 5=check, 6=filler, 7=disabled
349354
mark_char .byte ; Custom mark character if mark option set
350-
char1 .byte ; ASCII code of shortcut #1 (e.g. uppercase B); or 0
351-
char2 .byte ; ASCII code of shortcut #2 (e.g. lowercase b, or same); or 0
355+
char1 .byte ; ASCII code of shortcut #1 (e.g. uppercase B); or no_shortcut
356+
char2 .byte ; ASCII code of shortcut #2 (e.g. lowercase b, or same); or no_shortcut
352357
name .addr ; Address of length-prefixed string
353358
.endstruct
354359

@@ -883,38 +888,42 @@ ycoord: .word AS_WORD(top)
883888
.endmacro
884889
885890
;;; For menu items with open-apple modifier shortcuts, or no shortcuts
886-
;;; NOTE: If shortcut is A-Z, char2 is to_lower(char1); else char2=char1
891+
;;; NOTE: If shortcut is A-Z, char2 is to_lower(char1)
887892
.macro DEFINE_MENU_ITEM saddr, shortcut
888-
.if .paramcount > 1
893+
.ifnblank shortcut
889894
890895
.byte MGTK::MenuOpt::open_apple|MGTK::MenuOpt::solid_apple ; option byte
891896
.byte 0 ; mark_char
892897
.byte shortcut ; char1
893898
894-
.if kBuildSupportsLowercase && 'A' <= shortcut && shortcut <= 'Z'
899+
.if kBuildSupportsLowercase && 'A' <= shortcut && shortcut <= 'Z'
895900
.byte TO_LOWER(shortcut) ; char2
896-
.else
897-
.byte shortcut
898-
.endif
901+
.else
902+
.byte MGTK::no_shortcut
903+
.endif
899904
.addr saddr ; item_str_pointer
900905
901-
.else
906+
.else
902907
903908
.byte 0 ; option byte
904909
.byte 0 ; mark_char
905-
.byte 0 ; char1
906-
.byte 0 ; char2
910+
.byte MGTK::no_shortcut ; char1
911+
.byte MGTK::no_shortcut ; char2
907912
.addr saddr ; item_str_pointer
908913
909-
.endif
914+
.endif
910915
.endmacro
911916
912917
;;; For menu items with control keys (e.g. CHAR_RETURN), requiring no modifiers
913918
.macro DEFINE_MENU_ITEM_NOMOD saddr, shortcut1, shortcut2
914919
.byte 0 ; option byte
915920
.byte 0 ; mark_char
916921
.byte shortcut1 ; char1
922+
.ifnblank shortcut2
917923
.byte shortcut2 ; char2
924+
.else
925+
.byte MGTK::no_shortcut
926+
.endif
918927
.addr saddr ; item_str_pointer
919928
.endmacro
920929

tests/menus.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,5 +286,14 @@ test.Step(
286286
a2d.OpenPath("/A2.DESKTOP")
287287
a2d.OpenMenu(a2d.FILE_MENU)
288288
test.Snap("verify New Folder, Close, Close All are enabled")
289+
apple2.EscapeKey()
289290
end)
290291

292+
293+
test.Step(
294+
"Control-Shift-2 doesn't show first menu item without shortcut",
295+
function()
296+
apple2.ControlKey("@")
297+
a2d.WaitForRepaint()
298+
test.Snap("verify About dialog not showing")
299+
end)

0 commit comments

Comments
 (0)