1

I have a 2022 HP 14" Spectre x360, which can flip into tablet mode and has an accelerometer to switch the screen orientation. However, when I installed Ubuntu 22.04 on it, I found that switching it in or out of tablet mode, switching the orientation of the screen, or closing or opening the lid all toggle airplane mode.

This seems to be a relatively common problem for HP laptops (although my previous Spectre never experienced it). There is a fix for found in the first answer to this post, but unfortunately it doesn't seem to work on my system.

This fix relies on setting the keycodes for both the "close lid" and "orient" actions (e057 and e058 respectively) to the "KEY_UNKNOWN" keycode (240). My theory as to why it won't work for my system is because for some reason either my new laptop, or Ubuntu 22.04 has changed the action IDs for closing the lid and changing the orientation. I tried to figure out the new keycodes using xev, but switching orientation/tablet mode didn't show anything, and closing the lid gave output I didn't find helpful (seen below):

MappingNotify event, serial 37, synthetic NO, window 0x0,
    request MappingKeyboard, first_keycode 8, count 248

FocusOut event, serial 37, synthetic NO, window 0x3400001,
    mode NotifyGrab, detail NotifyAncestor

FocusIn event, serial 38, synthetic NO, window 0x3400001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 38, synthetic NO, window 0x0,
    keys:  4294967225 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   

FocusOut event, serial 38, synthetic NO, window 0x3400001,
    mode NotifyGrab, detail NotifyAncestor

FocusIn event, serial 38, synthetic NO, window 0x3400001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 38, synthetic NO, window 0x0,
    keys:  2   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   

FocusOut event, serial 38, synthetic NO, window 0x3400001,
    mode NotifyGrab, detail NotifyAncestor

FocusIn event, serial 38, synthetic NO, window 0x3400001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 38, synthetic NO, window 0x0,
    keys:  2   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   

MappingNotify event, serial 38, synthetic NO, window 0x0,
    request MappingKeyboard, first_keycode 8, count 248

KeyPress event, serial 38, synthetic NO, window 0x3400001,
    root 0x7b9, subw 0x0, time 3122108, (1160,-364), root:(1209,776),
    state 0x0, keycode 248 (keysym 0x0, NoSymbol), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 39, synthetic NO, window 0x3400001,
    root 0x7b9, subw 0x0, time 3122125, (1160,-364), root:(1209,776),
    state 0x0, keycode 248 (keysym 0x0, NoSymbol), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

PropertyNotify event, serial 39, synthetic NO, window 0x3400001,
    atom 0x1a4 (_GTK_EDGE_CONSTRAINTS), time 3122199, state PropertyNewValue

PropertyNotify event, serial 39, synthetic NO, window 0x3400001,
    atom 0x1a4 (_GTK_EDGE_CONSTRAINTS), time 3122203, state PropertyNewValue

KeyPress event, serial 39, synthetic NO, window 0x3400001,
    root 0x7b9, subw 0x0, time 3123167, (1160,-364), root:(1209,776),
    state 0x0, keycode 248 (keysym 0x0, NoSymbol), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 39, synthetic NO, window 0x3400001,
    root 0x7b9, subw 0x0, time 3123184, (1160,-364), root:(1209,776),
    state 0x0, keycode 248 (keysym 0x0, NoSymbol), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

PropertyNotify event, serial 39, synthetic NO, window 0x3400001,
    atom 0x1a4 (_GTK_EDGE_CONSTRAINTS), time 3123191, state PropertyNewValue

PropertyNotify event, serial 39, synthetic NO, window 0x3400001,
    atom 0x1a4 (_GTK_EDGE_CONSTRAINTS), time 3123197, state PropertyNewValue

MappingNotify event, serial 39, synthetic NO, window 0x0,
    request MappingKeyboard, first_keycode 8, count 248

FocusOut event, serial 39, synthetic NO, window 0x3400001,
    mode NotifyGrab, detail NotifyAncestor

FocusIn event, serial 40, synthetic NO, window 0x3400001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 40, synthetic NO, window 0x0,
    keys:  2   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   

FocusOut event, serial 40, synthetic NO, window 0x3400001,
    mode NotifyNormal, detail NotifyNonlinear

PropertyNotify event, serial 40, synthetic NO, window 0x3400001,
    atom 0x175 (_NET_WM_STATE), time 3151384, state PropertyNewValue

PropertyNotify event, serial 40, synthetic NO, window 0x3400001,
    atom 0x1a4 (_GTK_EDGE_CONSTRAINTS), time 3151384, state PropertyNewValue

MappingNotify event, serial 40, synthetic NO, window 0x0,
    request MappingKeyboard, first_keycode 8, count 248

I also looked to journalctl -f, which gives the following output when switching tablet mode, switching orientation, or opening/ closing the lid:

Aug 27 10:48:57 puter gnome-shell[2029]: Window manager warning: Overwriting existing binding of keysym 32 with keysym 32 (keycode b).
Aug 27 10:48:57 puter gnome-shell[2029]: Window manager warning: Overwriting existing binding of keysym 31 with keysym 31 (keycode a).
Aug 27 10:48:57 puter gnome-shell[2029]: Window manager warning: Overwriting existing binding of keysym 33 with keysym 33 (keycode c).
Aug 27 10:48:57 puter gnome-shell[2029]: Window manager warning: Overwriting existing binding of keysym 34 with keysym 34 (keycode d).
Aug 27 10:48:57 puter gnome-shell[2029]: Window manager warning: Overwriting existing binding of keysym 35 with keysym 35 (keycode e).
Aug 27 10:48:57 puter gnome-shell[2029]: Window manager warning: Overwriting existing binding of keysym 36 with keysym 36 (keycode f).
Aug 27 10:48:57 puter gnome-shell[2029]: Window manager warning: Overwriting existing binding of keysym 37 with keysym 37 (keycode 10).
Aug 27 10:48:57 puter gnome-shell[2029]: Window manager warning: Overwriting existing binding of keysym 39 with keysym 39 (keycode 12).
Aug 27 10:48:57 puter gnome-shell[2029]: Window manager warning: Overwriting existing binding of keysym 38 with keysym 38 (keycode 11).
Aug 27 10:48:57 puter systemd[1]: Starting Load/Save RF Kill Switch Status...
Aug 27 10:48:57 puter NetworkManager[675]: <info>  [1661618937.7480] manager: rfkill: Wi-Fi now enabled by radio killswitch
Aug 27 10:48:57 puter systemd[1]: Started Load/Save RF Kill Switch Status.
Aug 27 10:48:58 puter NetworkManager[675]: <info>  [1661618938.0189] manager: rfkill: WWAN hardware radio set enabled
Aug 27 10:48:58 puter NetworkManager[675]: <info>  [1661618938.0193] audit: op="radio-control" arg="wwan-enabled:on" pid=2237 uid=1000 result="success"
Aug 27 10:48:58 puter NetworkManager[675]: <info>  [1661618938.0543] device (wlo1): supplicant interface state: internal-starting -> disconnected
Aug 27 10:48:58 puter NetworkManager[675]: <info>  [1661618938.0544] device (p2p-dev-wlo1): state change: unavailable -> unmanaged (reason 'removed', sys-iface-state: 'removed')
Aug 27 10:48:58 puter NetworkManager[675]: <info>  [1661618938.0549] Wi-Fi P2P device controlled by interface wlo1 created
Aug 27 10:48:58 puter NetworkManager[675]: <info>  [1661618938.0552] manager: (p2p-dev-wlo1): new 802.11 Wi-Fi P2P device (/org/freedesktop/NetworkManager/Devices/7)
Aug 27 10:48:58 puter NetworkManager[675]: <info>  [1661618938.0554] device (p2p-dev-wlo1): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'external')
Aug 27 10:48:58 puter NetworkManager[675]: <info>  [1661618938.0558] device (wlo1): state change: unavailable -> disconnected (reason 'supplicant-available', sys-iface-state: 'managed')
Aug 27 10:48:58 puter NetworkManager[675]: <info>  [1661618938.0563] device (p2p-dev-wlo1): state change: unavailable -> disconnected (reason 'none', sys-iface-state: 'managed')
Aug 27 10:48:58 puter gnome-shell[2029]: Removing a network device that was not added
Aug 27 10:49:01 puter wpa_supplicant[696]: wlo1: CTRL-EVENT-REGDOM-CHANGE init=DRIVER type=COUNTRY alpha2=US
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.2389] policy: auto-activating connection 'hcdj' (4888999a-9a1c-4c66-9e1a-a833d092f6c0)
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.2396] device (wlo1): Activation: starting connection 'hcdj' (4888999a-9a1c-4c66-9e1a-a833d092f6c0)
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.2397] device (wlo1): state change: disconnected -> prepare (reason 'none', sys-iface-state: 'managed')
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.2401] manager: NetworkManager state is now CONNECTING
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.2403] device (wlo1): state change: prepare -> config (reason 'none', sys-iface-state: 'managed')
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.2407] device (wlo1): Activation: (wifi) access point 'hcdj' has security, but secrets are required.
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.2408] device (wlo1): state change: config -> need-auth (reason 'none', sys-iface-state: 'managed')
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.2425] device (wlo1): state change: need-auth -> prepare (reason 'none', sys-iface-state: 'managed')
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.2428] device (wlo1): state change: prepare -> config (reason 'none', sys-iface-state: 'managed')
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.2431] device (wlo1): Activation: (wifi) connection 'hcdj' has security, and secrets exist.  No new secrets needed.
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.2432] Config: added 'ssid' value 'hcdj'
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.2432] Config: added 'scan_ssid' value '1'
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.2432] Config: added 'bgscan' value 'simple:30:-70:86400'
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.2433] Config: added 'key_mgmt' value 'WPA-PSK WPA-PSK-SHA256 FT-PSK SAE FT-SAE'
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.2433] Config: added 'auth_alg' value 'OPEN'
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.2433] Config: added 'psk' value '<hidden>'
Aug 27 10:49:01 puter wpa_supplicant[696]: wlo1: SME: Trying to authenticate with 58:24:29:94:95:3a (SSID='hcdj' freq=5745 MHz)
Aug 27 10:49:01 puter kernel: wlo1: authenticate with 58:24:29:94:95:3a
Aug 27 10:49:01 puter kernel: wlo1: send auth to 58:24:29:94:95:3a (try 1/3)
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.2651] device (wlo1): supplicant interface state: disconnected -> authenticating
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.2652] device (p2p-dev-wlo1): supplicant management interface state: disconnected -> authenticating
Aug 27 10:49:01 puter wpa_supplicant[696]: wlo1: Trying to associate with 58:24:29:94:95:3a (SSID='hcdj' freq=5745 MHz)
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.3030] device (wlo1): supplicant interface state: authenticating -> associating
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.3031] device (p2p-dev-wlo1): supplicant management interface state: authenticating -> associating
Aug 27 10:49:01 puter kernel: wlo1: authenticated
Aug 27 10:49:01 puter kernel: wlo1: associate with 58:24:29:94:95:3a (try 1/3)
Aug 27 10:49:01 puter kernel: wlo1: RX AssocResp from 58:24:29:94:95:3a (capab=0x1011 status=0 aid=8)
Aug 27 10:49:01 puter wpa_supplicant[696]: wlo1: Associated with 58:24:29:94:95:3a
Aug 27 10:49:01 puter wpa_supplicant[696]: wlo1: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0
Aug 27 10:49:01 puter kernel: wlo1: associated
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.3324] device (wlo1): supplicant interface state: associating -> 4way_handshake
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.3324] device (p2p-dev-wlo1): supplicant management interface state: associating -> 4way_handshake
Aug 27 10:49:01 puter wpa_supplicant[696]: wlo1: WPA: Key negotiation completed with 58:24:29:94:95:3a [PTK=CCMP GTK=CCMP]
Aug 27 10:49:01 puter wpa_supplicant[696]: wlo1: CTRL-EVENT-CONNECTED - Connection to 58:24:29:94:95:3a completed [id=0 id_str=]
Aug 27 10:49:01 puter kernel: IPv6: ADDRCONF(NETDEV_CHANGE): wlo1: link becomes ready
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.3791] device (wlo1): supplicant interface state: 4way_handshake -> completed
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.3792] device (wlo1): Activation: (wifi) Stage 2 of 5 (Device Configure) successful. Connected to wireless network "hcdj"
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.3793] device (p2p-dev-wlo1): supplicant management interface state: 4way_handshake -> completed
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.3795] device (wlo1): state change: config -> ip-config (reason 'none', sys-iface-state: 'managed')
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.3803] dhcp4 (wlo1): activation: beginning transaction (timeout in 45 seconds)
Aug 27 10:49:01 puter avahi-daemon[669]: Joining mDNS multicast group on interface wlo1.IPv6 with address fe80::821d:62c4:9abf:42fa.
Aug 27 10:49:01 puter avahi-daemon[669]: New relevant interface wlo1.IPv6 for mDNS.
Aug 27 10:49:01 puter avahi-daemon[669]: Registering new address record for fe80::821d:62c4:9abf:42fa on wlo1.*.
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.4146] dhcp4 (wlo1): state changed new lease, address=192.168.86.82
Aug 27 10:49:01 puter kernel: wlo1: Limiting TX power to 30 (30 - 0) dBm as advertised by 58:24:29:94:95:3a
Aug 27 10:49:01 puter avahi-daemon[669]: Joining mDNS multicast group on interface wlo1.IPv4 with address 192.168.86.82.
Aug 27 10:49:01 puter avahi-daemon[669]: New relevant interface wlo1.IPv4 for mDNS.
Aug 27 10:49:01 puter avahi-daemon[669]: Registering new address record for 192.168.86.82 on wlo1.IPv4.
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.4191] device (wlo1): state change: ip-config -> ip-check (reason 'none', sys-iface-state: 'managed')
Aug 27 10:49:01 puter dbus-daemon[673]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service' requested by ':1.10' (uid=0 pid=675 comm="/usr/sbin/NetworkManager --no-daemon " label="unconfined")
Aug 27 10:49:01 puter systemd[1]: Starting Network Manager Script Dispatcher Service...
Aug 27 10:49:01 puter dbus-daemon[673]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Aug 27 10:49:01 puter systemd[1]: Started Network Manager Script Dispatcher Service.
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.4349] device (wlo1): state change: ip-check -> secondaries (reason 'none', sys-iface-state: 'managed')
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.4351] device (wlo1): state change: secondaries -> activated (reason 'none', sys-iface-state: 'managed')
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.4354] manager: NetworkManager state is now CONNECTED_LOCAL
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.4367] manager: NetworkManager state is now CONNECTED_SITE
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.4368] policy: set 'hcdj' (wlo1) as default for IPv4 routing and DNS
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.4380] device (wlo1): Activation: successful, device activated.
Aug 27 10:49:01 puter systemd-resolved[607]: wlo1: Bus client set search domain list to: lan
Aug 27 10:49:01 puter systemd-resolved[607]: wlo1: Bus client set default route setting: yes
Aug 27 10:49:01 puter systemd-resolved[607]: wlo1: Bus client set DNS server list to: 192.168.86.1
Aug 27 10:49:01 puter wpa_supplicant[696]: wlo1: CTRL-EVENT-SIGNAL-CHANGE above=1 signal=-54 noise=9999 txrate=234000
Aug 27 10:49:01 puter NetworkManager[675]: <info>  [1661618941.5717] manager: NetworkManager state is now CONNECTED_GLOBAL
Aug 27 10:49:02 puter systemd[1]: systemd-rfkill.service: Deactivated successfully.
Aug 27 10:49:06 puter NetworkManager[675]: <info>  [1661618946.0826] manager: rfkill: Wi-Fi now disabled by radio killswitch
Aug 27 10:49:06 puter NetworkManager[675]: <info>  [1661618946.0827] device (wlo1): state change: activated -> unavailable (reason 'none', sys-iface-state: 'managed')
Aug 27 10:49:06 puter systemd[1]: Starting Load/Save RF Kill Switch Status...
Aug 27 10:49:06 puter kernel: wlo1: deauthenticating from 58:24:29:94:95:3a by local choice (Reason: 3=DEAUTH_LEAVING)
Aug 27 10:49:06 puter NetworkManager[675]: <info>  [1661618946.0829] dhcp4 (wlo1): canceled DHCP transaction
Aug 27 10:49:06 puter NetworkManager[675]: <info>  [1661618946.0829] dhcp4 (wlo1): activation: beginning transaction (timeout in 45 seconds)
Aug 27 10:49:06 puter NetworkManager[675]: <info>  [1661618946.0830] dhcp4 (wlo1): state changed no lease
Aug 27 10:49:06 puter systemd[1]: Started Load/Save RF Kill Switch Status.
Aug 27 10:49:06 puter wpa_supplicant[696]: wlo1: CTRL-EVENT-DISCONNECTED bssid=58:24:29:94:95:3a reason=3 locally_generated=1
Aug 27 10:49:06 puter wpa_supplicant[696]: BSSID 58:24:29:94:95:3a ignore list count incremented to 2, ignoring for 10 seconds
Aug 27 10:49:06 puter avahi-daemon[669]: Interface wlo1.IPv6 no longer relevant for mDNS.
Aug 27 10:49:06 puter avahi-daemon[669]: Leaving mDNS multicast group on interface wlo1.IPv6 with address fe80::821d:62c4:9abf:42fa.
Aug 27 10:49:06 puter avahi-daemon[669]: Interface wlo1.IPv4 no longer relevant for mDNS.
Aug 27 10:49:06 puter avahi-daemon[669]: Leaving mDNS multicast group on interface wlo1.IPv4 with address 192.168.86.82.
Aug 27 10:49:06 puter avahi-daemon[669]: Withdrawing address record for fe80::821d:62c4:9abf:42fa on wlo1.
Aug 27 10:49:06 puter avahi-daemon[669]: Withdrawing address record for 192.168.86.82 on wlo1.
Aug 27 10:49:06 puter wpa_supplicant[696]: rfkill: WLAN soft blocked
Aug 27 10:49:06 puter wpa_supplicant[696]: rfkill: WLAN soft blocked
Aug 27 10:49:06 puter systemd-resolved[607]: wlo1: Bus client reset search domain list.
Aug 27 10:49:06 puter systemd-resolved[607]: wlo1: Bus client set default route setting: no
Aug 27 10:49:06 puter systemd-resolved[607]: wlo1: Bus client reset DNS server list.
Aug 27 10:49:06 puter NetworkManager[675]: <info>  [1661618946.1568] manager: NetworkManager state is now DISCONNECTED
Aug 27 10:49:06 puter wpa_supplicant[696]: p2p-dev-wlo1: CTRL-EVENT-DSCP-POLICY clear_all
Aug 27 10:49:06 puter wpa_supplicant[696]: p2p-dev-wlo1: CTRL-EVENT-DSCP-POLICY clear_all
Aug 27 10:49:06 puter wpa_supplicant[696]: nl80211: deinit ifname=p2p-dev-wlo1 disabled_11b_rates=0
Aug 27 10:49:06 puter wpa_supplicant[696]: wlo1: CTRL-EVENT-DSCP-POLICY clear_all
Aug 27 10:49:06 puter NetworkManager[675]: <info>  [1661618946.2158] device (p2p-dev-wlo1): state change: disconnected -> unavailable (reason 'supplicant-failed', sys-iface-state: 'managed')
Aug 27 10:49:06 puter NetworkManager[675]: <info>  [1661618946.2379] manager: rfkill: WWAN hardware radio set disabled
Aug 27 10:49:06 puter NetworkManager[675]: <info>  [1661618946.2380] audit: op="radio-control" arg="wwan-enabled:off" pid=2237 uid=1000 result="success"
Aug 27 10:49:06 puter wpa_supplicant[696]: wlo1: CTRL-EVENT-DSCP-POLICY clear_all
Aug 27 10:49:06 puter wpa_supplicant[696]: nl80211: deinit ifname=wlo1 disabled_11b_rates=0
Aug 27 10:49:08 puter google-chrome.desktop[2759]: [2753:2782:0827/104908.122472:ERROR:connection_factory_impl.cc(425)] Failed to connect to MCS endpoint with error -106
Aug 27 10:49:11 puter systemd[1]: systemd-rfkill.service: Deactivated successfully.
Aug 27 10:49:16 puter systemd[1]: NetworkManager-dispatcher.service: Deactivated successfully.

It starts with several key IDs, but changing any of them doesn't fix the problem.

So I guess my question is what's the best way to figure out which key IDs to set to 240 in order to prevent airplane mode when changing my laptop screen.

1
  • 1
    I have this problem too. Thanks for posting!
    – dayer4b
    Oct 5, 2022 at 1:42

1 Answer 1

2

I had the same issue that airplane mode would be activated and deactivated (at least when moving the lid).

  • device: HP HP Spectre x360 2-in-1 Laptop 14-ef2xxx
  • with German keyboard
  • Ubuntu 22.04 LTS

Mapping scancodes e057 and e058 to keycode 240 did not help. Using

sudo showkey

and moving the lid shows that key 247 (which is airplane mode on my machine) is pressed and released if the lid crosses certain angles, approximately 45 degrees relative to the table (or lap :D) in both forward or backward direction.

However, repeating the same procedure with

sudo showkey -s

shows that no scancodes are activated. So this can probably not be fixed by just mapping some scancode to some keycode using setkeycodes.

I fixed it with the help of [1], which is similar to [2]. Following the latter one-to-one did not work for me. Apparently, I needed a different device than the author to be affected by the key mapping.

I spent a really long time searching for answers, trial and error, and being confused by posts written on an expert level. At least I learned something. To hopefully spare you and others from that, I try to make this step-by-step solution as newbie-friendly as possible.

Find the device responsible

Open a terminal via Ctrl + Alt + T.

Type (then Enter)

cat /proc/bus/input/devices

to get a list of devices. The one called "Intel HID events",

I: Bus=0019 Vendor=0000 Product=0000 Version=0000
N: Name="Intel HID events"
P: Phys=
S: Sysfs=/devices/platform/INTC1070:00/input/input35
U: Uniq=
H: Handlers=rfkill kbd event17 
B: PROP=0
B: EV=13
B: KEY=1000300000000 5000004000 1e294000000020 0
B: MSC=10

could be responsible, because it has rfkill (deactivate all radios, i.e., wlan, bluetooth etc.) as a handler. I will call it the device from here on.

Get the keycodes

Before testing the device and getting the keycodes install evtest. Type (then enter)

sudo apt install -y evtest

Provide your password if promted. To test if the device is responsible and get the keycodes, open a virtual terminal (in a normal terminal X, basically your Ubuntu GUI, may make this test impossible). Often this is done via Ctrl + Alt + F1, but in my case F1 has to replaced by F3. To get back to X, press Ctrl + Alt + F2 (in my case). On other machines it often seems to be F7. I found the right keys for me by trial and error.

Provide your username and password. Type (then Enter)

sudo evtest /dev/input/event17

In my case it is event17, because this was in the Handler field of the device, see above. I noticed that the number changes if I connect, e.g., a mouse and keyboard to my laptop. Hence, in your case it might be a different number.

Next, close and open the lid. Exit the testing mode of evtest via Ctrl + C, and exit the virtual terminal via Ctrl + Alt + F2 (in my case). On my screen, this was printed during evtest:

Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x0 product 0x0 version 0x0
Input device name: "Intel HID events"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 69 (KEY_NUMLOCK)
    Event code 102 (KEY_HOME)
    Event code 104 (KEY_PAGEUP)
    Event code 107 (KEY_END)
    Event code 109 (KEY_PAGEDOWN)
    Event code 113 (KEY_MUTE)
    Event code 114 (KEY_VOLUMEDOWN)
    Event code 115 (KEY_VOLUMEUP)
    Event code 116 (KEY_POWER)
    Event code 142 (KEY_SLEEP)
    Event code 164 (KEY_PLAYPAUSE)
    Event code 166 (KEY_STOPCD)
    Event code 224 (KEY_BRIGHTNESSDOWN)
    Event code 225 (KEY_BRIGHTNESSUP)
    Event code 240 (KEY_UNKNOWN)
  Event type 4 (EV_MSC)
    Event code 4 (MSC_SCAN)
Properties:
Testing ... (interrupt to exit)
Event: time 1684340717.813043, type 4 (EV_MSC), code 4 (MSC_SCAN), value 08
Event: time 1684340717.813043, type 1 (EV_KEY), code 247 (KEY_RFKILL), value 1
Event: time 1684340717.813043, -------------- SYN_REPORT ------------
Event: time 1684340717.813055, type 1 (EV_KEY), code 247 (KEY_RFKILL), value 0
Event: time 1684340717.813055, -------------- SYN_REPORT ------------
Event: time 1684340721.308956, type 4 (EV_MSC), code 4 (MSC_SCAN), value 08
Event: time 1684340721.308956, type 1 (EV_KEY), code 247 (KEY_RFKILL), value 1
Event: time 1684340721.308956, -------------- SYN_REPORT ------------
Event: time 1684340721.308963, type 1 (EV_KEY), code 247 (KEY_RFKILL), value 0
Event: time 1684340721.308963, -------------- SYN_REPORT ------------

If you want this printed in a file, say evtest_output.txt in your home directory ~, type

sudo evtest /dev/input/event17 > ~/evtest_output.txt

instead in the above step. Note that you will not see the output printed on the screen during the testing, though.

Let's examine the content of evtest_output.txt. First, it tells us some device specifications and the supported events. Beneath Testing... there are ten events that were printed during the movement of the lid. The former five events belong to closing, and the latter five events to opening the lid. Note that I do not close it completely. I tilt of about 45 degrees is enough to trigger the airplane mode. This confirms that the device "Intel HID events" is responsible.

Fix with hwdb

To fix this issue using hwdb, I created the file intel-HID-events.hwdb by typing in the terminal (then Enter)

sudo nano /etc/udev/hwdb.d/intel-HID-events.hwdb

The contents that I typed in are (in my case)

evdev:input:b0019v0000p0000e0000-*
 KEYBOARD_KEY_08=unknown

The numbers in the first line are the bus (0019), vendor (0000), product (0000) and version (0000) fields of the device (see output of cat /proc/us/input/devices prompt above). The asterisk * afterwards is a placeholder for any number of symbols. I did not specify further, as is done in [1], however. My reason is that the modalias of the device seems to change when I (dis)connect other hardware, e.g., my mouse.

Note the indentation of the second line. The key 08, which is the value (after MSC_SCAN) of the first event when closing or opening in evtest, is set to unknown.

Save with Ctrl + O, Enter, and close with Ctrl + X. Then update via

sudo systemd-hwdb update

sudo udevadm trigger

This is from [2].

Move the lid. It should not trigger airplane mode anymore. I did not have to make these changes "permanent" as is done in [2]. After reboot the issue is still fixed. Let's see if the next update unfixes the fix...

I hope this helps you or anybody out there!

Cheers jk


References

[1] https://yulistic.gitlab.io/2017/12/linux-keymapping-with-udev-hwdb/

[2] Airplane mode toggling when switching to tablet mode (HP spectre x360)

2
  • Thank you so much! Your post fixed the problem that has been plaguing me for months. No longer will I have to always ensure my laptop is level when carrying it from room to room, or make sure that the lid doesn't tilt back to much. Also great guide! Very detailed and easy to follow!
    – heduncook
    May 20, 2023 at 23:30
  • Thanks a lot!:) Finally Fixed the problem (on my HP envy x360 13") Same exact parameters as your answer.
    – Guillaume
    Jun 24, 2023 at 0:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .