Hammerspoon窗口管理在辅助监视器上无法正常工作

问题描述 投票:2回答:1

我是Lua和Hammerspoon的新手,无法终生了解为什么以下代码在我的主屏幕上可以正常工作,但是虽然位置循环在我的辅助显示器上不起作用。在辅助监视器的窗口上单击快捷方式将启用第一个位置,但是第二次按则不执行任何操作。

阅读文档,hs.screen.mainScreen()启用当前的焦点屏幕,这样它应该可以工作吗?

顺便说一句,辅助监视器实际上与主要运行的PBP在同一台监视器上(否则图形卡无法处理分辨率)

我只在下面发布了我认为相关的代码:

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)
lua hammerspoon
1个回答
1
投票

最好的办法就是发布自己的代码,其目的与我三年前编写的代码类似,自那时以来,它在内部和外部监视器上一直运行良好。如您所见,我使用的是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)
© www.soinside.com 2019 - 2024. All rights reserved.