将 window 移动到另一台显示器时如何保持对焦?
How do I keep window in focus when moving it to another monitor?
我将 xmonad 与 2 个显示器和 XMonad.Layout.IndependentScreens
一起使用。它基本上工作正常,但我遇到的一个问题是,当我将 window 移动到另一台显示器时,它会失去焦点
负责放置的代码在这里:
[((m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f))
| (key, sc) <- zip [xK_e, xK_w, xK_r] [0..] -- switched e and w to accomodate my monitor setup
, (f, m) <- [(W.view, 0), (W.shift, controlMask)]]
不过,我对Haskell还是很陌生,完全看不懂
如何修改上面的代码来实现我想要的?
我不太清楚你真正想要什么。我假设您希望将当前的焦点 windows 移至其他 workspace/monitor 并保持焦点在 windows 上。不是吗?
查看代码片段,我不确定您想要哪种键绑定。让我解释一下
-- This comprehension list expands as below
[ ( (m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f) )
| (key, sc) <- zip [xK_e, xK_w, xK_r] [0..]
, (f, m) <- [(W.view, 0), (W.shift, controlMask)]
]
-- mod + 0 + e moves focus to workspace 0 (but not the focused window)
-- mod + ctrl + e moves focused window to workspace 0 (but doesn't move the focus)
-- mod + 0 + w moves focus to workspace 1 (but not the focused window)
-- etc...
[ ( (0 .|. modm, xK_e), screenWorkspace 0 >>= flip whenJust (windows . W.view) )
, ( (controlMask .|. modm, xK_e), screenWorkspace 0 >>= flip whenJust (windows . W.shift) )
, ( (0 .|. modm, xK_w), screenWorkspace 1 >>= flip whenJust (windows . W.view) )
, ( (controlMask .|. modm, xK_w), screenWorkspace 1 >>= flip whenJust (windows . W.shift) )
, ( (0 .|. modm, xK_r), screenWorkspace 2 >>= flip whenJust (windows . W.view) )
, ( (controlMask .|. modm, xK_r), screenWorkspace 2 >>= flip whenJust (windows . W.shift) )
]
如您所见,您有不同的键绑定来移动焦点和移动焦点 window。我想您希望一个键绑定同时执行这两项操作。我假设您希望 Mod+CTRL+w/e/r
移动到其他工作区。在这种情况下,您需要通过以下方式修改该列表
[ ( (controlMask .|. modm, key), screenWorkspace sc >>= flip whenJust (\wid -> windows $ W.view wid . W.shift wid) )
| (key, sc) <- zip [xK_e, xK_w, xK_r] [0..]
]
由于上面的代码有点含糊,我建议在顶层定义一个辅助函数
moveCurrentWindowsAndFocusIt :: WorkspaceId -> X ()
moveCurrentWindowsAndFocusIt wid = windows $ W.view wid . W.shift wid
-- This is the where your keybindings are
mykeybindings =
...
[ ( (controlMask .|. modm, key), screenWorkspace sc >>= flip whenJust moveCurrentWindowsAndFocusIt )
| (key, sc) <- zip [xK_e, xK_w, xK_r] [0..]
]
我将 xmonad 与 2 个显示器和 XMonad.Layout.IndependentScreens
一起使用。它基本上工作正常,但我遇到的一个问题是,当我将 window 移动到另一台显示器时,它会失去焦点
负责放置的代码在这里:
[((m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f))
| (key, sc) <- zip [xK_e, xK_w, xK_r] [0..] -- switched e and w to accomodate my monitor setup
, (f, m) <- [(W.view, 0), (W.shift, controlMask)]]
不过,我对Haskell还是很陌生,完全看不懂
如何修改上面的代码来实现我想要的?
我不太清楚你真正想要什么。我假设您希望将当前的焦点 windows 移至其他 workspace/monitor 并保持焦点在 windows 上。不是吗?
查看代码片段,我不确定您想要哪种键绑定。让我解释一下
-- This comprehension list expands as below
[ ( (m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f) )
| (key, sc) <- zip [xK_e, xK_w, xK_r] [0..]
, (f, m) <- [(W.view, 0), (W.shift, controlMask)]
]
-- mod + 0 + e moves focus to workspace 0 (but not the focused window)
-- mod + ctrl + e moves focused window to workspace 0 (but doesn't move the focus)
-- mod + 0 + w moves focus to workspace 1 (but not the focused window)
-- etc...
[ ( (0 .|. modm, xK_e), screenWorkspace 0 >>= flip whenJust (windows . W.view) )
, ( (controlMask .|. modm, xK_e), screenWorkspace 0 >>= flip whenJust (windows . W.shift) )
, ( (0 .|. modm, xK_w), screenWorkspace 1 >>= flip whenJust (windows . W.view) )
, ( (controlMask .|. modm, xK_w), screenWorkspace 1 >>= flip whenJust (windows . W.shift) )
, ( (0 .|. modm, xK_r), screenWorkspace 2 >>= flip whenJust (windows . W.view) )
, ( (controlMask .|. modm, xK_r), screenWorkspace 2 >>= flip whenJust (windows . W.shift) )
]
如您所见,您有不同的键绑定来移动焦点和移动焦点 window。我想您希望一个键绑定同时执行这两项操作。我假设您希望 Mod+CTRL+w/e/r
移动到其他工作区。在这种情况下,您需要通过以下方式修改该列表
[ ( (controlMask .|. modm, key), screenWorkspace sc >>= flip whenJust (\wid -> windows $ W.view wid . W.shift wid) )
| (key, sc) <- zip [xK_e, xK_w, xK_r] [0..]
]
由于上面的代码有点含糊,我建议在顶层定义一个辅助函数
moveCurrentWindowsAndFocusIt :: WorkspaceId -> X ()
moveCurrentWindowsAndFocusIt wid = windows $ W.view wid . W.shift wid
-- This is the where your keybindings are
mykeybindings =
...
[ ( (controlMask .|. modm, key), screenWorkspace sc >>= flip whenJust moveCurrentWindowsAndFocusIt )
| (key, sc) <- zip [xK_e, xK_w, xK_r] [0..]
]