我是Lua和hammerspoon的新手,我无法理解为什么下面的代码在我的主屏幕上运行良好,但是循环通过位置在我的辅助显示器上不起作用。点击辅助显示器上窗口上的快捷键可启用第一个位置,但第二次按不起任何作用。
读取文档,hs.screen.mainScreen()启用当前聚焦的屏幕,这样它就可以工作了吗?
因为aside...the辅助显示器实际上在物理上与运行的主显示器相同(否则显卡无法处理分辨率)
我只在下面发布了我认为相关的代码:
local rightScreen = hs.screen.primaryScreen(0x600003f98880)
local leftScreen = rightScreen:toWest()
function bindKey(key, fn)
hs.hotkey.bind({"cmd", "ctrl","alt"}, key, fn)
end
grid = {
{key="q", units={positions.leftthird, positions.left50, positions.left66}},
{key="w", units={positions.middlethird}},
{key="e", units={positions.rightthird}},
{key="r", units={positions.left50, positions.lower50Left50, positions.upper50Left50, positions.upper50, positions.lower50}}, -- virker IKKE på sekundære skærm
{key="t", units={positions.right50, positions.lower50Right50, positions.upper50Right50, positions.upper50, positions.lower50}}, -- virker IKKE på sekundære skærm
}
hs.fnutils.each(grid, function(entry)
bindKey(entry.key, function()
local units = entry.units
local screen = hs.screen.mainScreen()
local window = hs.window.focusedWindow()
local windowGeo = window:frame()
local index = 0
hs.fnutils.find(units, function(unit)
index = index + 1
local geo = hs.geometry.new(unit):fromUnitRect(screen:frame()):floor()
return windowGeo:equals(geo)
end)
if index == #units then index = 0 end
window:moveToUnit(units[index + 1])
end)
end)发布于 2020-03-18 20:33:45
我能做的最好的事情就是发布我自己的代码,和我几年前写的3+类似,从那时起,它在内部和外部的监视器上都运行得很好。如您所见,我使用的是win:setFrame而不是:moveToUnit。抱歉,我不能帮助调试您的问题,但我已经忘记了Lua和Hammerspoon…希望这能有所帮助
function coords ()
return hs.window.focusedWindow(), hs.window.focusedWindow():frame(),
hs.window.focusedWindow():screen(), hs.window.focusedWindow():screen():frame()
end
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "left", function()
local win, wf, scr, sf = coords()
if wf.x <= sf.x and wf.w <= math.floor(sf.w/3) then
wf.x = sf.x
wf.w = math.floor(sf.w/4)
elseif wf.x <= sf.x and wf.w <= math.floor(sf.w/2) then
wf.x = sf.x
wf.w = math.floor(sf.w/3)
else
wf.x = sf.x
wf.w = math.floor(sf.w/2)
end
wf.y=sf.y
wf.h=sf.h
win:setFrame(wf, 0)
end)
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "right", function()
local win, wf, scr, sf = coords()
if wf.x >= math.floor(sf.x + sf.w/3) and wf.w <= math.floor(sf.w/3) then
wf.w = sf.w/4
wf.x = math.floor(sf.x + 3 * sf.w/4)
elseif wf.x >= math.floor(sf.x + sf.w/2) and wf.w <= math.floor(sf.w/2) then
wf.w = sf.w/3
wf.x = math.floor(sf.x + 2 * sf.w/3)
else
wf.w = sf.w/2
wf.x = math.floor(sf.x + sf.w/2)
end
wf.y=sf.y
wf.h=sf.h
win:setFrame(wf, 0)
end)
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "up", function()
local win, wf, scr, sf = coords()
win:setFrame(sf, 0)
end)
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "down", function()
local win, wf, scr, sf = coords()
if wf.x ~= math.floor(sf.x + sf.w/3) and wf.w ~= math.floor(sf.w/3) then
wf.w = math.floor(sf.w/3)
wf.x = math.floor(sf.x + sf.w/3)
else
wf.w = sf.w/2
wf.x = math.floor(sf.x + sf.w/4)
end
wf.y=sf.y
wf.h=sf.h
win:setFrame(wf, 0)
end)https://stackoverflow.com/questions/60728601
复制相似问题