xmonad io绑定不起作用 [英] xmonad io binding not working

查看:124
本文介绍了xmonad io绑定不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的〜/ .xmonad / xmonad.hs 文件中的一个关键绑定是这样的:



<$ p $($)$($)$($)$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b

所以,我试图使用这种模式来制作一个绑定,它可以循环使用键盘布局。我有 cycleKLayouts :: IO(),它在从 ghci 运行时完美运行。然后,我写道:

$ p $ ((modMask,xK_minus),io cycleKLayouts)

编译得很好,但是当我尝试键时,唯一发生的事情是当前终端和鼠标所在的位置(两个术语)闪光微弱。这与使用非绑定键发生的情况不同,后者只是将信件传递给应用程序。



我也试过 liftIO code>,而不是 io ,结果相同。我也有一个直接的 spawn 绑定:

 ((modMask,xK_equal ),产生了setxkbmap -v gb -variant colemak)

这有效,但提供了不同的行为。 ( cycleKLayouts 在某个时间点运行 setxkbmap )。



$ b 编辑:定义 cycleKLayouts

  module键盘其中
import System.Process
import Control.Applicative
kLayouts = [(gb(colemak),UK-CO)
,( gb,UK-QW)
,(us(colemak),US-CO)
,(us,US-QW)]
getKLayout :: IO String
getKLayout = f。 (!! 4)。行< $> readProcesssetxkbmap[-print] []
其中
f('+':cs)= g cs
f(_:cs)= f cs
f _ =

g('+':_)=
g(c:cs)= c:g cs
g _ =

getNextKLayout :: IO String
getNextKLayout = do
l < - getKLayout
let kLayoutNames = map fst kLayouts
let f(x:y:xs)= if x == l then y else f(y:xs)
f _ = head kLayoutNames
return $ f kLayoutNames

setKLayout :: String - > IO()
setKLayout l = readProcesssetxkbmap[-v,l] []>>返回()

cycleKLayouts :: IO()
cycleKLayouts = setKLayout =<< getUpKLayout


解决方案

重写 cycleKLayouts 以类型 X()的形式运行,并且以 spawn 运行命令,当然应该有帮助。我想问题在于 cycleKLayouts 运行命令的方式。可能在结果 setxkbmap 中无法访问您的环境变量,或者分叉并终止。



如果您发布了 cycleKLayouts 的来源,我可能会给出更具体的答案。



更新:



好吧,我只是试图将其添加到我的配置中:

  ((modMask,xK_a),liftIO(readProcesssetxkbmap[-print]>> = putStrLn))

每当我按 Ma 一个错误消息waitForProcess:does not exist(no child process)。我无法真正解释一个原因,但我想这与Xmonad产生键绑定操作的方式有关(可能它是一个潜在的错误)。

然而,将 readProcess 替换为 runProcessWithInput (来自 Xmonad.Util.Run )完全解决了问题: ((modMask,xK_a),liftIO(runProcessWithInputsetxkbmap[-print]>> = putStrLn))

试试这个以确保我们遇到同样的问题。


One of the key bindings in my ~/.xmonad/xmonad.hs file is this:

((modMask .|. shiftMask, xK_q), io (exitWith ExitSuccess))

So, I tried to use this pattern to make a binding that would cycle through keyboard layouts. I have cycleKLayouts :: IO (), which works perfectly when run from ghci. Then, I write:

((modMask, xK_minus), io cycleKLayouts)

This compiles fine, but when I try the key, the only thing that happens is that the current terminal and the one the mouse is under (both Terminology) flash faintly. This is different to what happens with an unbound key, which just passes the letter through to the application.

I've also tried liftIO, rather than io, with the same results. I also have a direct spawn binding:

((modMask, xK_equal), spawn "setxkbmap -v gb -variant colemak")

which works, but provides a different behaviour. (cycleKLayouts runs setxkbmap at some point).


Edit: definition of cycleKLayouts:

module Keyboards where
import System.Process
import Control.Applicative
kLayouts = [("gb(colemak)", "UK-CO")
          ,("gb", "UK-QW")
          ,("us(colemak)", "US-CO")
          ,("us", "US-QW")]
getKLayout :: IO String
getKLayout = f . (!! 4) . lines <$> readProcess "setxkbmap" ["-print"] []
    where
        f ('+':cs) = g cs
        f (_:cs) = f cs
        f _ = ""

        g ('+':_) = ""
        g (c:cs) = c:g cs
        g _ = ""

getNextKLayout :: IO String
getNextKLayout = do
    l <- getKLayout
    let kLayoutNames = map fst kLayouts
    let f (x:y:xs) = if x == l then y else f (y:xs)
        f _ = head kLayoutNames
    return $ f kLayoutNames

setKLayout :: String -> IO ()
setKLayout l = readProcess "setxkbmap" ["-v", l] [] >> return ()

cycleKLayouts :: IO ()
cycleKLayouts = setKLayout =<< getNextKLayout

解决方案

Rewriting cycleKLayouts in such a way that it has type X () and runs your command with spawn, certainly should help. I guess the problem lies in the way that cycleKLayouts runs the command. Probably in result setxkbmap doesn't have access to your environment variables, or gets forked and then terminated.

If you post the source of cycleKLayouts I probably would be able to give more specific answer.

Update:

Well, I've just tried to add this to my configuration:

((modMask, xK_a), liftIO (readProcess "setxkbmap" ["-print"] "" >>= putStrLn))

Whenever I was pressing M-a an error message "waitForProcess: does not exist (no child process)". I can't really explain a reason for that, but I guess it has to do with the way Xmonad spawns keybinded actions (probably it's a potential bug).

However, replacing readProcess to runProcessWithInput (from Xmonad.Util.Run) solved the problem completely:

 ((modMask, xK_a), liftIO (runProcessWithInput "setxkbmap" ["-print"] "" >>= putStrLn))

Try this to make sure that we catched on the same problem.

这篇关于xmonad io绑定不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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