EDIT: This solution has been superseded by a fix for the actual, root issue I found. Please disregard the following information
TL;DR: https://github.com/snyball/hawck. Use this tool to remap keycode 255 to a null character and the problem's solved.
The issue here is that whatever driver Linux uses for the lid/tablet mode switches erroneously interprets them as generating Keycode 255 (or 247, depending on... stuff. I never quite figured out why it's sometimes one or the other). Keyvode 255 happens to be the rfkill key, which puts the system into airplane mode.
It took me so. freaking. long. to fix this. I tried messing with DKMS, I tried using Xmodmap (which actually worked for awhile, until I realized X11 was messing with my touchpad), I ran a program in the background that constantly ran rfkill unblock all
, and I even tried disabling the keycode at the kernel level. What finally worked? A free and open source program called Hawck.
Hawck (https://github.com/snyball/hawck) is by far the best solution for this issue, at least until whatever malfunctioning kernel driver is updated. It's desktop-agnostic (heck, it even works in console mode), it's designed to be run on startup, and unlike Xmodmap it's modular and scriptable. What I did was I created a script called "fixapmode.hwk" (the name doesn't matter), with the following contents:
key(255) => insert ""
(If you replicate my method, please keep in mind there is NO SPACE between the quotation marks).
I then set the script as executable, enabled it in Hawck, set Hawck to run on startup, and it worked! The only lingering issue was that my laptop would still start in Airplane mode, since Hawck didn't immediately kick in on boot. I solved that issue by making a new startup program with the command rfkill unblock all
. With that, I can say that the problem is completely fixed. The only annoying thing is that the first time you login from boot, you'll get a notification from Hawck letting you know it loaded your script successfully. However, there's probably a way to turn this off, and it's much much better than the alternative.
Hope this helps. Cheers!
gsettings set org.gnome.settings-daemon.plugins.rfkill active false
helps me for 2 years Debian. – nobody Mar 04 '20 at 10:51