xmonad:设置屏幕和工作区

发布于 2024-11-13 11:34:45 字数 1039 浏览 3 评论 0原文

我无法让这个功能按我的预期工作。

setScreenAndWorkspace i =
  windows (viewOnScreen screenId workspaceId)
  where
    screenId = ((i-1) `mod` numberOfScreens)
    -- workspaceId = show i -- doesn't work for some reason
    workspaceId =
      case i of
        1 -> "1"
        2 -> "2"
        3 -> "3"
        4 -> "4"
        5 -> "5"
        6 -> "6"
        7 -> "7"
        8 -> "8"
        9 -> "9"

我这样调用该函数:

myKeys =
  [
    ("M-1"   , setScreenAndWorkspace 1),
    ("M-2"   , setScreenAndWorkspace 2),
    ("M-3"   , setScreenAndWorkspace 3),
    ("M-4"   , setScreenAndWorkspace 4),
    ("M-5"   , setScreenAndWorkspace 5),
    ("M-6"   , setScreenAndWorkspace 6),
    ("M-7"   , setScreenAndWorkspace 7),
    ("M-8"   , setScreenAndWorkspace 8),
    ("M-9"   , setScreenAndWorkspace 9)
  ]

首先,显示 i 似乎没有执行与 case i 相同的操作。我一定是误解了一些基本的 Haskell 东西;如果我使用 show i 似乎 xmonad 找不到任何工作区。

第二个问题是该功能可以工作,但并不总是转移焦点。我必须按两次按键序列才能设置屏幕、设置工作区并将焦点设置在该工作区上。

I'm having trouble getting this function to work as I expect.

setScreenAndWorkspace i =
  windows (viewOnScreen screenId workspaceId)
  where
    screenId = ((i-1) `mod` numberOfScreens)
    -- workspaceId = show i -- doesn't work for some reason
    workspaceId =
      case i of
        1 -> "1"
        2 -> "2"
        3 -> "3"
        4 -> "4"
        5 -> "5"
        6 -> "6"
        7 -> "7"
        8 -> "8"
        9 -> "9"

I'm calling the function like so:

myKeys =
  [
    ("M-1"   , setScreenAndWorkspace 1),
    ("M-2"   , setScreenAndWorkspace 2),
    ("M-3"   , setScreenAndWorkspace 3),
    ("M-4"   , setScreenAndWorkspace 4),
    ("M-5"   , setScreenAndWorkspace 5),
    ("M-6"   , setScreenAndWorkspace 6),
    ("M-7"   , setScreenAndWorkspace 7),
    ("M-8"   , setScreenAndWorkspace 8),
    ("M-9"   , setScreenAndWorkspace 9)
  ]

Firstly, show i doesn't seem to do the same as the case i of. I must be misunderstanding some basic Haskell thing; if I use the show i it seems that xmonad can't find any workspace.

The second problem is that the function works, but doesn't always transfer focus. I have to hit the key sequence twice to set the screen, set the workspace, AND set the focus on that workspace.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅淡淡 2024-11-20 11:34:45

对于 show i 问题,很容易在提示中看出为什么它没有按您期望的方式工作:

Prelude XMonad> show (1 :: Integer)
"1"
Prelude XMonad> show (1 :: ScreenId)
"S 1"

您可以使用类似 drop 2 的内容。显示 如果您感觉特别老套,或者

unS (S i) = i
workspaceId = show (unS i)

如果您不感觉老套。

至于为什么 viewOnScreen 不聚焦屏幕,嗯......这只是因为它不是这样设计的。从文档中:“切换到屏幕 sc 上的工作区 i。如果 i 可见,请使用视图将焦点切换到工作区 i。”。因此,只有当 i 已经可见时,它才会改变焦点。为什么不直接调用两次呢?像这样的事情应该做:

windows (viewOnScreen screenId workspaceId . viewOnScreen screenId workspaceId)

For the show i question, it's easy to see at the prompt why it's not working the way you expect:

Prelude XMonad> show (1 :: Integer)
"1"
Prelude XMonad> show (1 :: ScreenId)
"S 1"

You could use something like drop 2 . show if you feel particularly hacky, or something like

unS (S i) = i
workspaceId = show (unS i)

if you're not feeling hacky.

As for why viewOnScreen doesn't focus the screen, well... it's just because it wasn't designed to. From the documentation: "Switch to workspace i on screen sc. If i is visible use view to switch focus to the workspace i.". So it only changes focus when i is already visible. Why not just call it twice? Something like this should do:

windows (viewOnScreen screenId workspaceId . viewOnScreen screenId workspaceId)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文