我从来不喜欢在Awesome中默认切换窗口的可能性,所以我想我应该实现Alt行为,它考虑到历史(并且具有奇特的不透明度效果)。
当按下Alt时,整个历史记录都记录在一个表中,并附加到该历史记录后面的是最小化窗口(在相同的标记中)。生成此表时,我实例化了一个keygrabber,它捕获Tab-按事件(切换到表中的下一个客户端)和Alt释放事件(完全中止)。
一个标志跟踪用户是否处于Alt选项卡的过程中,以防止表被一次又一次地生成。
代码(它很多,您可能不需要看它,但我的经验告诉我,当我不发布所有的代码,人们最终会要求它):
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我意识到有很多代码,但最主要的是关键抓取器。由于仍然不知道的原因,有时意外的崩溃,而我正在使用这种方法制表。我想通过将信号连接到Alt和Tab键来替换密钥抓取器,并在用户完成后立即断开它们。但是,由于某种原因,我不能这么做。
我实例化一个新的键对象,如下所示:
local altkey = awful.key({}, "Alt_L")[1]通过反复试验,我发现awful.key()实际上返回了一个表,其中我可以查询key、keysym等的第一个元素,从而获得[1]。然而,当我试图将一个信号连接到这个对象时,LUA解释器会抱怨并告诉我它是一个零对象。所以我的问题是:我在这里做得对吗?是否有可能以我想要的方式取代键盘抓取器?
发布于 2015-07-29 20:49:56
要在Alt_L文件中使用Mod1键,您应该在rc.lua文件中引用"Mod1“,为了使它更易读,我在配置的开头添加了下面一行,这样就可以使用Alt_L了。
Alt_L = "Mod1"https://stackoverflow.com/questions/24756997
复制相似问题