Adjust keybinding depending on number of screens in Xmonad

54 Views Asked by At

I'm trying to adjust my key bindings in Xmonad depending on the number of screen (physical screens/monitors) I am currently using. Somehow I am failing with this task, probably due to my lack of Haskell knowledge.

Somewhere in my xmonad.hs file I define my keybindings:

myKeys =
    [ ...
    , ...
    , ("M-x", showSet1)
    , ...
    ]

So far I defined showSet1 elsewhere in the file (abc is a placeholder for the actual definition:

showSet1 = abc

Then I used myKeys like this:

main :: IO ()
main = xmonad
     . ewmhFullscreen
     ...
     $ myConfig

myConfig = def
    { modMask = myModMask
    , ...
    } `additionalKeysP` myKeys

This worked perfectly so far, but now I want to adjust showSet1 depending on the number of screens. I found this thread and from there use the following to get the number of screens:

numScreens :: X Int
numScreens = withDisplay (io.fmap length.getScreenInfo)

My plan was to use the following to define showSet1:

showSet1 = if numScreens == 4
    then abc
    else xyz

When compiling xmonad, I get the following error:

    • No instance for (Eq (X Int)) arising from a use of ‘==’
    • In the expression: numScreens == 4
      In the expression:
        if numScreens == 4 then
            abc
        else
            xyz

If I understand that correctly, numScreens is of type X Int and I cannot compare that to 4. Any idea how I can do that? I have tried a lot of things, including playing with the function screenCount, but nothing worked so far.

1

There are 1 best solutions below

2
arrowd On BEST ANSWER

Since you're getting the number of screens from X, it isn't a pure computation. Hence, it is a X Int rather than plain Int. Depending on what asd and xyz are, this might help:

showSet1 = do
  ns <- numScreens
  if ns == 4
    then abc
    else xyz