【发布时间】:2018-07-06 05:23:14
【问题描述】:
所以我一直在尝试配置我的 Awesome WM 配置 (rc.lua) 以检测我的 IBM 型号 M13 是否在登录/重置时连接到我的笔记本电脑。这是为了更改 modkey 应该是什么,因为 M13 没有超级密钥。
以下代码对我来说很有意义,并在为 awesome.spawn.easy_async 函数创建的函数中更改了 modkey,但在完成后 modkey 会更改回 Mod4。
modkey = "Mod4"
awful.spawn.easy_async(
"xinput list",
function(stdout, stderr, reason, code)
local msg = "Regular keyboard Modkey = Super"
-- Debug notification that shows that the modkey is
-- at its default for the superkey Mod4
naughty.notify({
text = modkey,
timeout =7
})
if code ~= 0 then
msg = "Missing xinput to see devices\nModkey = Super"
elseif stdout:match("CHESEN") == "CHESEN" then
-- CHESEN is my PS/2 to USB adapter
msg = "IBM M13 detected\nModkey = Alt"
modkey = "Mod1" -- Sets new modkey to Alt
end
-- Notification message
naughty.notify({
text = msg,
timeout =7
})
end
)
-- Debug notification to verify key but key goes back to Mod4
naughty.notify({
text = modkey,
timeout =7
})
输出可以在这里看到。它不会按顺序打印通知,但 Mod 4 的打印都是调试打印。
除了不时更改我的配置之外,我不怎么使用 Lua,所以我很难理解如何在不重置的情况下更改我的全局变量 modkey。我尝试的其他方法是将函数定义为我调用 setModKey 作为参数传递给 easy_async 的函数,我尝试使用 _G 设置 modkey 将其设置为 _G.modkey,但我最终得到相同的结果。
我是否遗漏了 Lua 的基本内容,或者这是否受到 Awesome WM 如何利用 Lua 的影响?任何帮助将不胜感激。
【问题讨论】:
-
为什么这是
awful.spawn.easy_async?如果您希望每次重置都发生这种情况,只需将函数的内容放在modkey = "Mod4"之后。
标签: lua awesome-wm