开发者

xmonad: set screen and workspace

开发者 https://www.devze.com 2023-03-11 10:44 出处:网络
I\'m having trouble getting this function to work as I expect. setScreenAndWorkspace i = windows (viewOnScreen screenId workspaceId)

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 tr开发者_StackOverflow社区ansfer focus. I have to hit the key sequence twice to set the screen, set the workspace, AND set the focus on that workspace.


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)
0

精彩评论

暂无评论...
验证码 换一张
取 消