Window crash when connecting to power

I’ve been having this weird crashes when connecting my laptop to the power socket.
At first I thought it was dwm, but then I tested it with i3 and it was the same.
the behaviour is as follows

  • open a new window (i.e. Firefox)
  • disconnect the power plug
  • wait for a couple of minutes (I think the battery has to tick down a bit)
  • reconnect the plug
  • the window crashes

some applications (i.e. st) don’t crash though.

I think I’m inching towards the problem, but I’m quickly reaching the end of my knowledge. I think this is related to the asus backlight software: when I connect the plug it’s supposed to increase the backlight.

when I connect the plug, I get this in journalctl --system -r

Dec 08 20:02:20 laptop kernel: asus_wmi: Unknown key code 0xcf

so I ran evtest, selecting Asus WMI Hotkeys` as device event and sure enough when I connect the plug I get an event

Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x0 product 0x0 version 0x0
Input device name: "Asus WMI hotkeys"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 113 (KEY_MUTE)
    Event code 114 (KEY_VOLUMEDOWN)
    Event code 115 (KEY_VOLUMEUP)
    Event code 140 (KEY_CALC)
    Event code 148 (KEY_PROG1)
    Event code 149 (KEY_PROG2)
    Event code 150 (KEY_WWW)
    Event code 152 (KEY_SCREENLOCK)
    Event code 163 (KEY_NEXTSONG)
    Event code 164 (KEY_PLAYPAUSE)
    Event code 165 (KEY_PREVIOUSSONG)
    Event code 166 (KEY_STOPCD)
    Event code 169 (KEY_PHONE)
    Event code 183 (KEY_F13)
    Event code 185 (KEY_F15)
    Event code 190 (KEY_F20)
    Event code 191 (KEY_F21)
    Event code 202 (KEY_PROG3)
    Event code 203 (KEY_PROG4)
    Event code 212 (KEY_CAMERA)
    Event code 215 (KEY_EMAIL)
    Event code 224 (KEY_BRIGHTNESSDOWN)
    Event code 225 (KEY_BRIGHTNESSUP)
    Event code 226 (KEY_MEDIA)
    Event code 227 (KEY_SWITCHVIDEOMODE)
    Event code 229 (KEY_KBDILLUMDOWN)
    Event code 230 (KEY_KBDILLUMUP)
    Event code 237 (KEY_BLUETOOTH)
    Event code 238 (KEY_WLAN)
    Event code 240 (KEY_UNKNOWN)
    Event code 247 (KEY_RFKILL)
    Event code 470 (KEY_FN_F5)
    Event code 531 (KEY_TOUCHPAD_ON)
    Event code 560 (KEY_ALS_TOGGLE)
    Event code 634 (?)
  Event type 4 (EV_MSC)
    Event code 4 (MSC_SCAN)
Key repeat handling:
  Repeat type 20 (EV_REP)
    Repeat code 0 (REP_DELAY)
      Value    250
    Repeat code 1 (REP_PERIOD)
      Value     33
Properties:
Testing ... (interrupt to exit)
Event: time 1702066212.219856, type 4 (EV_MSC), code 4 (MSC_SCAN), value cf
Event: time 1702066212.219856, type 1 (EV_KEY), code 240 (KEY_UNKNOWN), value 1
Event: time 1702066212.219856, -------------- SYN_REPORT ------------
Event: time 1702066212.219871, type 1 (EV_KEY), code 240 (KEY_UNKNOWN), value 0
Event: time 1702066212.219871, -------------- SYN_REPORT ------------

So I’m guessing when I connect the plug asus clicks a virtual button to increase the backlight, and the OS doesn’t know what that button is.
Am I right? If so I guess I could just set that functionality to a no-op button, but how would I do it?