Arch-Linux

將某些功能鍵 (FN) 綁定到 AwesomeWM 會破壞它們直到未綁定

  • July 17, 2019

使用戴爾 Inspiron 靈越 15 7580。很棒的是4.3版

我使用 . 檢查我的密鑰的名稱xev。按我的音量鍵返回通常的結果。

KeyPress event, serial 36, synthetic NO, window 0x1200001,
   root 0x169, subw 0x1200002, time 13968342, (38,56), root:(841,97),
   state 0x0, keycode 122 (keysym 0x1008ff11, XF86AudioLowerVolume), same_screen YES,
   XLookupString gives 0 bytes:
   XmbLookupString gives 0 bytes:
   XFilterEvent returns: False

KeyRelease event, serial 36, synthetic NO, window 0x1200001,
   root 0x169, subw 0x1200002, time 13968484, (38,56), root:(841,97),
   state 0x0, keycode 122 (keysym 0x1008ff11, XF86AudioLowerVolume), same_screen YES,
   XLookupString gives 0 bytes:
   XFilterEvent returns: False

所以我將密鑰綁定到 AwesomeWM ……

awful.key({ }, "XF86AudioLowerVolume", 
   awful.spawn("amixer set Master 5%-"), {})

但是一旦我刷新 Awesome,綁定就不起作用並xev返回不同的結果

FocusOut event, serial 36, synthetic NO, window 0x1800001,
   mode NotifyGrab, detail NotifyAncestor

FocusIn event, serial 36, synthetic NO, window 0x1800001,
   mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 36, synthetic NO, window 0x0,
   keys:  105 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

一旦我解開它們,功能鍵就會再次起作用。但為什麼會發生這種情況?一旦我綁定它,它甚至不是我的音量鍵。

我想到了。出於某種原因,我不得不awful.spawn在匿名函式中使用。我想因為awful.spawn是一個函式,我不必這樣做。但不幸的是,你這樣做了。

awful.key({ }, "XF86AudioLowerVolume", function() 
   awful.spawn("amixer set Master 5%-") 
end, 
{description = "lower audio", group = "audio"}),

編輯想我會解釋一下。

所以( metatable for ) 的press參數需要 a作為參數。type ,但它返回的不是函式。因此,在這種情況下,只能將函式作為參數傳遞,而不是呼叫函式。key.new``__call``awful.key``function``awful.spawn function

好例子

-- Notice I passed awful.spawn without calling it
awful.key({ }, "t", awful.spawn, {})

不好的例子

-- awful.spawn is called here, so whats returned by it is passed as an argument
awful.key({ }, "t", awful.spawn(), {})

請記住,您始終可以通過呼叫來檢查您在 lua 中的類型type

type(awful.spawn)
function

引用自:https://unix.stackexchange.com/questions/530552