根据 Xmonad 中的屏幕数量调整按键绑定

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

我正在尝试根据 Xmonad 的数量调整我的按键绑定 我当前正在使用的屏幕(物理屏幕/显示器)。不知何故我失败了 完成这项任务,可能是因为我缺乏 Haskell 知识。

在我的 xmonad.hs 文件中的某个地方我定义了我的键绑定:

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

到目前为止,我在文件中的其他位置定义了

showSet1
abc
是实际定义的占位符:

showSet1 = abc

然后我像这样使用

myKeys

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

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

到目前为止效果很好,但现在我想根据屏幕数量进行调整

showSet1
。我找到了这个线程,并从那里使用以下内容来获取屏幕数量:

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

我的计划是使用以下内容来定义

showSet1

showSet1 = if numScreens == 4
    then abc
    else xyz

编译xmonad时,出现以下错误:

    • 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

如果我理解正确的话,numScreens 是

X Int
类型,我不能 与
4
进行比较。知道我该怎么做吗?我尝试过很多事情, 包括使用 screenCount 函数,但到目前为止没有任何效果。

haskell screen xmonad
1个回答
0
投票

由于您从 X 获取屏幕数量,因此它不是纯粹的计算。因此,它是一个

X Int
而不是普通的
Int
。根据
asd
xyz
的含义,这可能会有所帮助:

showSet1 = do
  ns <- numScreens
  if ns == 4
    then abc
    else xyz
© www.soinside.com 2019 - 2024. All rights reserved.