Bug 277531 - x11/xorg: "Menu" key works on some keyboards not on others
Summary: x11/xorg: "Menu" key works on some keyboards not on others
Status: Open
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-x11 (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-03-06 15:15 UTC by Tim Chase
Modified: 2024-03-08 09:43 UTC (History)
2 users (show)

See Also:
bugzilla: maintainer-feedback? (x11)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Chase 2024-03-06 15:15:46 UTC
While it took a while to track down[1], the Menu key (usually to the right of the spacebar on the standard 105-key keyboard) seems to send two different key-codes.

I have USB keyboard plugged into my laptop.  Pressing the Menu key on the laptop keyboard sends keycode 147 which gets translated to "XF86MenuKB" while pressing the same Menu key on the external USB keyboard sends keycode 135 which gets translated to the "Menu" keysym:

    $ xev 2>/dev/null | awk '/^Key/{k=$1}/keysym/{sub(/, same_screen.*/, "");print k, $0}'
    KeyPress     state 0x10, keycode 147 (keysym 0x1008ff65, XF86MenuKB)
    KeyRelease     state 0x10, keycode 147 (keysym 0x1008ff65, XF86MenuKB)
    KeyPress     state 0x10, keycode 135 (keysym 0xff67, Menu)
    KeyRelease     state 0x10, keycode 135 (keysym 0xff67, Menu)

Critically, AFAICT, most applications expect/respect the "Menu" keysym, but ignore the "XF86MenuKB" symbol.  Thus, if I'm in Firefox or Chromium and hit the Menu key on my laptop, it does nothing; if I hit the Menu key on my external keyboard, it invokes the right-click menu.  In that Reddit thread[1], it seems to be every application we've thrown at it -- KDE for the OP; browsers, office applications, and other applications for me.

It looks like some changes were made a couple years ago[2] and someone else butting their head against the issue[3].

It looks like the solution might involve modifying

    /usr/local/share/X11/xkb/symbols/inet

so that the line currently reading

    key <I147> { [ XF86MenuKB ] };

gets changed, replacing "XF86MenuKB" with "Menu".

(I'm not sure there's a way to update every application that expects "Menu" to also allow "XF86MenuKB" as a synonym).

I can provide additional detail or debugging output if needed (output of `xinput --list --long` and `setxkbmap -print` provided at the bottom of this; the "SEM" is the external USB keyboard).

---------

[1]
original Reddit thread wherein this was tracked down:
https://www.reddit.com/r/freebsd/comments/1b6gi5n/keyboard_menu_key_doesnt_work_on_freebsd14_kde5/

[2]
https://lists.freebsd.org/pipermail/freebsd-current/2020-March/075495.html

[3]
http://www.lemis.com/grog/diary-mar2020.php?subtitle=Daily%20teevee%20update&article=D-20200306-002910#D-20200306-002910


------------

    ⎡ Virtual core pointer                    	id=2	[master pointer  (3)]
    	Reporting 8 classes:
    		Class originated from: 12. Type: XIButtonClass
    		Buttons supported: 12
    		Button labels: "Button Left" "Button Middle" "Button Right" "Button Wheel Up" "Button Wheel Down" "Button Horiz Wheel Left" "Button Horiz Wheel Right" None None None None None
    		Button state:
    		Class originated from: 12. Type: XIValuatorClass
    		Detail for Valuator 0:
    		  Label: Rel X
    		  Range: 1472.000000 - 5772.000000
    		  Resolution: 69000 units/m
    		  Mode: relative
    		Class originated from: 12. Type: XIValuatorClass
    		Detail for Valuator 1:
    		  Label: Rel Y
    		  Range: 1408.000000 - 5086.000000
    		  Resolution: 118000 units/m
    		  Mode: relative
    		Class originated from: 12. Type: XIValuatorClass
    		Detail for Valuator 2:
    		  Label: Rel Horiz Scroll
    		  Range: 0.000000 - -1.000000
    		  Resolution: 0 units/m
    		  Mode: relative
    		Class originated from: 12. Type: XIValuatorClass
    		Detail for Valuator 3:
    		  Label: Rel Vert Scroll
    		  Range: 0.000000 - -1.000000
    		  Resolution: 0 units/m
    		  Mode: relative
    		Class originated from: 12. Type: XIValuatorClass
    		Detail for Valuator 4:
    		  Label: Abs MT Pressure
    		  Range: -1.000000 - -1.000000
    		  Resolution: 0 units/m
    		  Mode: relative
    		Class originated from: 12. Type: XIScrollClass
    		Scroll info for Valuator 2
    		  type: 2 (horizontal)
    		  increment: 113.000000
    		  flags: 0x0
    		Class originated from: 12. Type: XIScrollClass
    		Scroll info for Valuator 3
    		  type: 1 (vertical)
    		  increment: 113.000000
    		  flags: 0x0

    ⎜   ↳ Virtual core XTEST pointer              	id=4	[slave  pointer  (2)]
    	Reporting 3 classes:
    		Class originated from: 4. Type: XIButtonClass
    		Buttons supported: 10
    		Button labels: "Button Left" "Button Middle" "Button Right" "Button Wheel Up" "Button Wheel Down" "Button Horiz Wheel Left" "Button Horiz Wheel Right" None None None
    		Button state:
    		Class originated from: 4. Type: XIValuatorClass
    		Detail for Valuator 0:
    		  Label: Rel X
    		  Range: -1.000000 - -1.000000
    		  Resolution: 0 units/m
    		  Mode: relative
    		Class originated from: 4. Type: XIValuatorClass
    		Detail for Valuator 1:
    		  Label: Rel Y
    		  Range: -1.000000 - -1.000000
    		  Resolution: 0 units/m
    		  Mode: relative

    ⎜   ↳ System mouse                            	id=6	[slave  pointer  (2)]
    	Reporting 7 classes:
    		Class originated from: 6. Type: XIButtonClass
    		Buttons supported: 12
    		Button labels: "Button Left" "Button Middle" "Button Right" "Button Wheel Up" "Button Wheel Down" "Button Horiz Wheel Left" "Button Horiz Wheel Right" "Button Side" "Button Extra" "Button Forward" "Button Back" None
    		Button state:
    		Class originated from: 6. Type: XIValuatorClass
    		Detail for Valuator 0:
    		  Label: Rel X
    		  Range: -1.000000 - -1.000000
    		  Resolution: 0 units/m
    		  Mode: relative
    		Class originated from: 6. Type: XIValuatorClass
    		Detail for Valuator 1:
    		  Label: Rel Y
    		  Range: -1.000000 - -1.000000
    		  Resolution: 0 units/m
    		  Mode: relative
    		Class originated from: 6. Type: XIValuatorClass
    		Detail for Valuator 2:
    		  Label: Rel Horiz Scroll
    		  Range: -1.000000 - -1.000000
    		  Resolution: 0 units/m
    		  Mode: relative
    		Class originated from: 6. Type: XIValuatorClass
    		Detail for Valuator 3:
    		  Label: Rel Vert Scroll
    		  Range: -1.000000 - -1.000000
    		  Resolution: 0 units/m
    		  Mode: relative
    		Class originated from: 6. Type: XIScrollClass
    		Scroll info for Valuator 2
    		  type: 2 (horizontal)
    		  increment: 120.000000
    		  flags: 0x0
    		Class originated from: 6. Type: XIScrollClass
    		Scroll info for Valuator 3
    		  type: 1 (vertical)
    		  increment: 120.000000
    		  flags: 0x0

    ⎜   ↳ SynPS/2 Synaptics TouchPad              	id=12	[slave  pointer  (2)]
    	Reporting 8 classes:
    		Class originated from: 12. Type: XIButtonClass
    		Buttons supported: 12
    		Button labels: "Button Left" "Button Middle" "Button Right" "Button Wheel Up" "Button Wheel Down" "Button Horiz Wheel Left" "Button Horiz Wheel Right" None None None None None
    		Button state:
    		Class originated from: 12. Type: XIValuatorClass
    		Detail for Valuator 0:
    		  Label: Rel X
    		  Range: 1472.000000 - 5772.000000
    		  Resolution: 69000 units/m
    		  Mode: relative
    		Class originated from: 12. Type: XIValuatorClass
    		Detail for Valuator 1:
    		  Label: Rel Y
    		  Range: 1408.000000 - 5086.000000
    		  Resolution: 118000 units/m
    		  Mode: relative
    		Class originated from: 12. Type: XIValuatorClass
    		Detail for Valuator 2:
    		  Label: Rel Horiz Scroll
    		  Range: 0.000000 - -1.000000
    		  Resolution: 0 units/m
    		  Mode: relative
    		Class originated from: 12. Type: XIValuatorClass
    		Detail for Valuator 3:
    		  Label: Rel Vert Scroll
    		  Range: 0.000000 - -1.000000
    		  Resolution: 0 units/m
    		  Mode: relative
    		Class originated from: 12. Type: XIValuatorClass
    		Detail for Valuator 4:
    		  Label: Abs MT Pressure
    		  Range: -1.000000 - -1.000000
    		  Resolution: 0 units/m
    		  Mode: relative
    		Class originated from: 12. Type: XIScrollClass
    		Scroll info for Valuator 2
    		  type: 2 (horizontal)
    		  increment: 113.000000
    		  flags: 0x0
    		Class originated from: 12. Type: XIScrollClass
    		Scroll info for Valuator 3
    		  type: 1 (vertical)
    		  increment: 113.000000
    		  flags: 0x0

    ⎣ Virtual core keyboard                   	id=3	[master keyboard (2)]
    	Reporting 1 classes:
    		Class originated from: 13. Type: XIKeyClass
    		Keycodes supported: 248

        ↳ Virtual core XTEST keyboard             	id=5	[slave  keyboard (3)]
    	Reporting 1 classes:
    		Class originated from: 5. Type: XIKeyClass
    		Keycodes supported: 248

        ↳ System keyboard multiplexer             	id=7	[slave  keyboard (3)]
    	Reporting 1 classes:
    		Class originated from: 7. Type: XIKeyClass
    		Keycodes supported: 248

        ↳ ACPI video extension                    	id=8	[slave  keyboard (3)]
    	Reporting 1 classes:
    		Class originated from: 8. Type: XIKeyClass
    		Keycodes supported: 248

        ↳ Power Button                            	id=9	[slave  keyboard (3)]
    	Reporting 1 classes:
    		Class originated from: 9. Type: XIKeyClass
    		Keycodes supported: 248

        ↳ Sleep Button                            	id=10	[slave  keyboard (3)]
    	Reporting 1 classes:
    		Class originated from: 10. Type: XIKeyClass
    		Keycodes supported: 248

        ↳ AT keyboard                             	id=11	[slave  keyboard (3)]
    	Reporting 1 classes:
    		Class originated from: 11. Type: XIKeyClass
    		Keycodes supported: 248

        ↳ SEM USB Keyboard                        	id=13	[slave  keyboard (3)]
    	Reporting 1 classes:
    		Class originated from: 13. Type: XIKeyClass
    		Keycodes supported: 248



--------------

    xkb_keymap {
    	xkb_keycodes  { include "evdev+aliases(qwerty)"	};
    	xkb_types     { include "complete"	};
    	xkb_compat    { include "complete"	};
    	xkb_symbols   { include "pc+us+inet(evdev)+compose(caps)+shift(both_capslock)"	};
    	xkb_geometry  { include "pc(pc105)"	};
    };
Comment 1 Tatsuki Makino 2024-03-07 07:33:46 UTC
I didn't think much of it, but it looks like my keyboard is also 147 keyboard, and I don't get context menu :)
The following changes also seem to switch from XF86MenuKB to Menu.
Where is the most correct way to make changes?

--- /usr/local/share/X11/xkb/keycodes/evdev.orig	2024-02-05 01:24:20.000000000 +0000
+++ /usr/local/share/X11/xkb/keycodes/evdev	2024-03-07 07:20:03.467621000 +0000
@@ -71,7 +71,7 @@
 	alias <ALGR> = <RALT>;
 	<RWIN> = 134;
 	<COMP> = 135;
-	alias <MENU> = <COMP>;
+	//alias <MENU> = <COMP>;
 	<RCTL> = 105;
 
 	<ESC> = 9;
@@ -214,7 +214,7 @@
 	alias <I144> = <FIND>;	// #define KEY_FIND                136
 	alias <I145> = <CUT>;	// #define KEY_CUT                 137
 	alias <I146> = <HELP>;	// #define KEY_HELP                138
-	<I147> = 147;		// #define KEY_MENU                139
+	<MENU> = 147;		// #define KEY_MENU                139
 	<I148> = 148;		// #define KEY_CALC                140
 	<I149> = 149;		// #define KEY_SETUP               141
 	<I150> = 150;		// #define KEY_SLEEP               142
Comment 2 Tim Chase 2024-03-07 12:07:25 UTC
(In reply to Tatsuki Makino from comment #1)

If the hardware is actually reporting two different key-codes for what amounts to the same key, something feels a bit wrong about lying and saying they're the same key because there's some freakishly pathological case where a keyboard could have two different Menu keys, one sending 147 and one sending 135.  So I don't feel satisfied with the solution I proposed.

However, I don't have the ontological expertise in this area of code to make a determination regarding what a "correct" fix would be—your suggestion, mine, or something entirely different.

That said, I'm glad to be shining light on these "my Menu key doesn't work" out there. And I imagine that whatever the _right_ fix is, it will be a similar change of one or two lines. :-)
Comment 3 Alexey Dokuchaev freebsd_committer freebsd_triage 2024-03-08 09:43:26 UTC
(In reply to Tim Chase from comment #0)
>   $ xev 2>/dev/null | awk '/^Key/{k=$1}/keysym/{sub(/, same_screen.*/,
> "");print k, $0}'
>   KeyPress     state 0x10, keycode 147 (keysym 0x1008ff65, XF86MenuKB)
>   KeyRelease     state 0x10, keycode 147 (keysym 0x1008ff65, XF86MenuKB)
>   KeyPress     state 0x10, keycode 135 (keysym 0xff67, Menu)
>   KeyRelease     state 0x10, keycode 135 (keysym 0xff67, Menu)
Interesting.  I never noticed any problems with the Menu key, but decided to try my keyboards nonetheless (main PS/2 one and two pluggable USB ones I had lying around), all three reported the same keycode 117 (with xf86-input-keyboard-1.9.0 driver):

  KeyPress     state 0x0, keycode 117 (keysym 0xff67, Menu)
  KeyRelease     state 0x0, keycode 117 (keysym 0xff67, Menu)