如何设置对xmonad中的键释放执行的操作? [英] How can I set an action to occur on a key release in xmonad?

查看:104
本文介绍了如何设置对xmonad中的键释放执行的操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置对xmonad中的键释放执行的操作?

How can I set an action to occur on a key release in xmonad?

我不喜欢菜单栏和面板. 我希望有一个全屏的信息页面,而不是xmobar之类的面板,(当我按住某个键组合时会显示(时间,当前选定的窗口和工作区等),然后在放开这些键时消失. 我可以自己编写信息页面应用程序的代码. 我可以将信息页面设置为在按键时产生.

I don't like menu bars and panels. Instead of a panel like xmobar I want to have a full screen page of info, (time, currently selected window and workspace etc) appear when I hold down a key combo and then vanish when I let the keys go. I could code the info page application myself. I can set the info page to spawn on a key press.

我无法设置任何在密钥发布中发生的事情.

I can not set anything to happen on a key release.

如何设置在按键释放时要执行的操作?

How can I set an action to occur on a key release?

我正在考虑自己扩展xmonad来做到这一点. 我希望我不必这样做,因为这确实很烦人.

I am considering extending xmonad myself to do this. I hope I don't have to though because it'd be really annoying.

推荐答案

XMonad将所有接收到的事件(包括KeyPress事件)传递给handleEventHook,因此此代码将能够对keyRelease事件做出反应:

XMonad passes all received events, including KeyPress events, to the handleEventHook, so this code would be able to react on keyRelease events:

module KeyUp where

import Data.Monoid
import qualified Data.Map as M

import XMonad
import Control.Monad

keyUpEventHook :: Event -> X All
keyUpEventHook e = handle e >> return (All True)

keyUpKeys (XConf{ config = XConfig {XMonad.modMask = modMask} }) = M.fromList $ 
    [ ((modMask, xK_v), io (print "Hi")) ]

handle :: Event -> X ()
handle (KeyEvent {ev_event_type = t, ev_state = m, ev_keycode = code})
    | t == keyRelease = withDisplay $ \dpy -> do
        s  <- io $ keycodeToKeysym dpy code 0
        mClean <- cleanMask m
        ks <- asks keyUpKeys
        userCodeDef () $ whenJust (M.lookup (mClean, s) ks) id
handle _ = return ()

您将在xmonad.hs文件中像这样使用它:

You would use it like that in your xmonad.hs file:

handleEventHook    = handleEventHook defaultConfig `mappend`
                     keyUpEventHook `mappend`
                     fullscreenEventHook

不幸的是,这还行不通:它将仅对在常规keys配置中具有相应条目的KeyRelease事件作出反应.这是由于XMonad.Main中的grayKeys,仅抓住了keys中提到的键.您可以通过为要在KeyUp中处理的每个组合定义一个虚拟动作来解决此问题:

Unfortunately, this does not work yet: It will only react on KeyRelease events that have a corresponding entry in the regular keys configuration. This is due to grayKeys in XMonad.Main, grabbing only keys mentioned in keys. You can work-around this by defining a dummy action for every combination that you want to handle in KeyUp:

myKeys conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $
    ...
    , ((modMask              , xK_v     ), return ())

这篇关于如何设置对xmonad中的键释放执行的操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆