简体   繁体   English

xmonad - 使用鼠标按钮6和7切换工作区

[英]xmonad - switching workspaces with mouse buttons 6 and 7

I would like to be able to move to the previous and next workspaces using the buttons 6 and 7 (the rocker buttons either side of the wheel) on my mouse. 我希望能够使用鼠标上的按钮6和7(滚轮两侧的摇杆按钮)移动到上一个和下一个工作区。 I'm guessing it has something to do with additionalMouseBindings , and if that followed the same pattern as additionalKeys I'd be golden. 我猜它与additionalMouseBindings ,如果它跟additionalKeys模式相同,那我就是金色的。 Alas, it is not, and I don't fully understand how to define a new binding. 唉,它不是,我不完全了解如何定义新的绑定。 The naive: 天真的:

`additionalMouseBindings`
[ -- get the middle button to switch views
  ((0, button6), spawn "xdotool key super+Down")
, ((0, button7), spawn "xdotool key super+Up")
]

isn't working, for reasons that will be obvious to somebody who knows Haskell and xmonad. 因为对于知道Haskell和xmonad的人来说显而易见的原因是不起作用的。

TIA for any suggestions. 任何建议的TIA。

By "doesn't work" I suppose you mean it doesn't compile. 通过“不起作用”我想你的意思是它不编译。

After @chi comment, I checked the buttons : button6 and 7 are not defined , so that is a first problem. 在@chi评论之后,我检查了按钮:按钮6和7没有定义 ,所以这是第一个问题。 But according to this post the extra buttons work if you just give their number. 但根据这篇文章 ,如果你只是提供他们的号码,额外的按钮可以工作。

It looks like you are using the additionalMouseBindings function from the XMonad.Util.EZConfig module. 看起来您正在使用XMonad.Util.EZConfig模块中的additionalMouseBindings函数。 Its type is : 它的类型是:

additionalMouseBindings :: XConfig a -> [((ButtonMask, Button), Window -> X ())] -> XConfig a

You are surrounding it in backticks which turns it into an operator. 你在反引号中将它变成了一个操作符。 You aren't showing the first operand here, of type XConfig a , so you could have a first error here. 你没有在这里显示XConfig a类型的第一个操作数,所以你可能在这里遇到第一个错误。 You should have something of the form : 你应该有这样的形式:

 yourPreviousConfig `additionalMouseBindings` listOfBindings 

That expression is equal to your new XConfig. 该表达式等于您的新XConfig。

You can see that the list of bindings for the mouse buttons is not the same type as for the keys. 您可以看到鼠标按钮的绑定列表与键的类型不同。 The elements of the list are of type ((ButtonMask, Button), Window -> X ()) : buttons are associated to a function that takes a Window and returns X() (whereas keys are associated to expressions of type X() ). 列表的元素是类型((ButtonMask, Button), Window -> X ()) :按钮与一个函数相关联,该函数接受一个Window并返回X() (而键与X()类型的表达式相关联)。 XMonad will call the function you specify here with the clicked window as argument. XMonad将使用单击的窗口作为参数调用此处指定的函数。 You don't care about the window in your case. 在你的情况下你不关心窗口。 spawn "xdotool key super+Down" is of type X () , you can turn that into a function that takes a Window (or anything) by making a lambda function : spawn "xdotool key super+Down"X ()类型,您可以通过创建lambda函数将其转换为一个带有Window (或任何东西)的函数

((0, 6), \w -> spawn "xdotool key super+Down")

Or you can use const to get a constant function that always return spawn "xdotool key super+Down" : 或者你可以使用const来获得一个常量函数,它总是返回spawn "xdotool key super+Down"

((0, 6), const $ spawn "xdotool key super+Down")

Finally, it seems really overkill to call xdotool to switch workspaces. 最后,调用xdotool切换工作区似乎真的xdotool了。 Perhaps you are already using some of the functions of the module here in your key bindings ? 也许您已经在密钥绑定中使用了模块的一些功能 You can use them in your mouse bindings too. 您也可以在鼠标绑定中使用它们。 nextWS and prevWS are of type X() , so you need make constant functions with them, like above. nextWSprevWS属于X()类型,因此您需要使用它们生成常量函数,如上所述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM