gpt4 book ai didi

lua - Awesome WM (v3.5.5) keygrabber 替代品

转载 作者:行者123 更新时间:2023-12-04 18:06:46 25 4
gpt4 key购买 nike

我从来都不喜欢 Awesome 中默认的窗口切换可能性,所以我想我应该实现考虑到历史的 Alt-Tab 行为(并且做花哨的不透明效果)。

当按下 Alt-Tab 时,整个历史记录在一个表中,并附加到该历史记录的是最小化的窗口(在同一标签内)。生成此表后,我实例化一个捕获 Tab 键事件(切换到表中的下一个客户端)和 Alt 键释放事件(完全中止)的键盘抓取器。

一个标记会跟踪用户是否在按 Alt-tabbing 的过程中,以防止表格被一遍又一遍地生成。

代码(很多,你可能不需要看,但我的经验告诉我,当我不发布所有代码时,人们最终会要求它):

altTabbing = false
altTabIndex = 1
altTabHistory = {}
clientOpacities = {}

function altTabSetOpacities(restore)
for i,c in pairs(altTabHistory) do
if not restore and i ~= altTabIndex then
c.opacity = 0.5
else
c.opacity = clientOpacities[i]
end
end
end

function myAltTab()
-- First check if the user is already alttabbing, in which case the history
-- should NOT be updated. If the user has just pressed alt-tab, generate a new
-- history-table

if not altTabbing then -- generate history-table

-- Clear Tables
for i in pairs(altTabHistory) do altTabHistory[i] = nil end
for i in pairs(clientOpacities) do clientOpacities[i] = nil end

-- Get focus history for current tag
local s = mouse.screen;
local idx = 0
local c = awful.client.focus.history.get(s, idx)

while c do
table.insert(altTabHistory, c)
table.insert(clientOpacities, c.opacity)

idx = idx + 1
c = awful.client.focus.history.get(s, idx)
end

-- Minimized clients will not appear in the focus history
-- Find them by cycling through all clients, and adding them to the list
-- if not already there.
-- This will preserve the history AND enable you to focus on minimized clients

local t = awful.tag.selected(s)
local all = client.get(s)

for i = 1, #all do
local c = all[i]
local ctags = c:tags();

-- check if the client is on the current tag
local isCurrentTag = false
for j = 1, #ctags do
if t == ctags[j] then
isCurrentTag = true
break
end
end

if isCurrentTag then
-- check if client is already in the history
-- if not, add it
local addToHistory = true
for k = 1, #altTabHistory do
if altTabHistory[k] == c then
addToHistory = false
break
end
end

if addToHistory then
table.insert(altTabHistory, c)
table.insert(clientOpacities, c.opacity)
end
end
end

-- reset current index and flag
altTabIndex = 1
altTabbing = true

-- Now that we have collected all windows, we should run a keygrabber
-- as long as the user is alt-tabbing:
keygrabber.run(
function (mod, key, event)
-- Stop alt-tabbing when the alt-key is released
if key == "Alt_L" and event == "release" then
altTabbing = false
altTabSetOpacities(true)
c = altTabHistory[altTabIndex]
client.focus = c
c:raise()
return false -- stop keygrabber
end

-- Move to next client on each Tab-press
if key == "Tab" and event == "press" then
myAltTab()
return true -- keep going
end

return true -- keep going
end
)

end -- if not altTabbing

-- at this point, the user is alt-tabbing, so we should raise
-- the next client in the history-table
if #altTabHistory < 2 then return end

-- Switch to next client
altTabIndex = altTabIndex + 1
if altTabIndex > #altTabHistory then
altTabIndex = 1 -- wrap around
end

-- focus on current client
local c = altTabHistory[altTabIndex]
c.minimized = false
c:raise()

-- make current client stand out
altTabSetOpacities(false)
end

我知道有很多代码,但最主要的是 keygrabber。由于仍然未知的原因,当我使用这种方法使用 Alt-Tabbing 时,Awesome 有时会崩溃。我想通过将信号连接到 Alt 和 Tab 键来替换 keygrabber,并在用户完成后立即断开它们。但是,出于某种原因,我无法执行此操作。

我像这样实例化一个新的键对象:

local altkey = awful.key({}, "Alt_L")[1]

我通过反复试验发现 awful.key() 实际上返回了一个表,我可以在其中查询第一个元素的 keykeysym 等,因此 [1]。但是,当我尝试将信号连接到该对象时,LUA 解释器会提示并告诉我它是一个 nil 对象。所以我的问题是:我在这里做的事情对吗?是否有可能按照我打算的方式更换 keygrabber?

最佳答案

要在 Awesome 中使用 Alt_L 键,您应该在 rc.lua 文件中引用“Mod1”,为了使其更具可读性,我在配置的开头添加了以下行,以便可以使用 Alt_L。

Alt_L = "Mod1"

关于lua - Awesome WM (v3.5.5) keygrabber 替代品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24756997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com