XMonad卷配置不起作用

时间:2015-03-30 00:42:39

标签: haskell xmonad

我最近进入了XMonad并且不幸的是我根本不了解Haskell。我正在尝试配置我的xmonad.hs文件,以便我可以控制音量。但是,现在,即使我的xmonad.hs文件编译没有错误,我也无法控制音量。

我从此链接获得了音量控制代码:http://dmwit.com/volume/

这是我的配置文件:

import XMonad
import XMonad.Util.Run(spawnPipe)
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Actions.Volume
import XMonad.Util.Dzen
import Data.Map (fromList)
import Data.Monoid (mappend)
import System.IO

alert = dzenConfig centered . show . round
centered =
        onCurr (center 150 66)
    >=> font "-*-helvetica-*-r-*-*-64-*-*-*-*-*-*-*"
    >=> addArgs ["-fg", "#80c0ff"]
    >=> addArgs ["-bg", "#000040"]

main = do 
        xmproc <- spawnPipe "xmobar /home/david/.xmobarrc"
        xmonad $ defaultConfig
                {
                        manageHook = manageDocks <+> manageHook defaultConfig
                        , layoutHook = avoidStruts  $  layoutHook defaultConfig
                        , logHook = dynamicLogWithPP xmobarPP
                                { ppOutput = hPutStrLn xmproc
                                , ppTitle = xmobarColor "green" "" . shorten 50
                                }
                        , modMask = mod4Mask 
                        , keys =
                            keys defaultConfig `mappend`
                            \c -> fromList [
                                ((0, xK_F6), lowerVolume 4 >>= alert),
                                ((0, xK_F7), raiseVolume 4 >>= alert)
                            ]
                }

我已经更改了以下代码,但是音量没有改变:

main = do 
    xmproc <- spawnPipe "xmobar /home/luren/.xmobarrc"
    xmonad $ defaultConfig
            {
                    manageHook = manageDocks <+> manageHook defaultConfig
                    , layoutHook = avoidStruts  $  layoutHook defaultConfig
                    , logHook = dynamicLogWithPP xmobarPP
                            { ppOutput = hPutStrLn xmproc
                            , ppTitle = xmobarColor "green" "" . shorten 50
                            }
                    , modMask = mod4Mask 
                    , keys =
                        keys defaultConfig `mappend`
                        \c -> fromList [
                            ((0, 0x1008FF11), spawn "amixer -D pulse sset Master 4-"),
                            ((0, 0x1008FF13), spawn "amixer -D pulse sset Master 4+")
                        ]
            }

(END)

这些键是我笔记本电脑上的音量媒体键的代码。

我偷偷摸摸地看了一些其他的配置。我决定做一点测试并使音频低音量键打印嗨ppl!按下时不幸的是,这不起作用。

main = do 
    xmproc <- spawnPipe "xmobar /home/luren/.xmobarrc"
    xmonad $ defaultConfig
            {
                    manageHook = manageDocks <+> manageHook defaultConfig
                    , layoutHook = avoidStruts  $  layoutHook defaultConfig
                    , logHook = dynamicLogWithPP xmobarPP
                            { ppOutput = hPutStrLn xmproc
                            , ppTitle = xmobarColor "green" "" . shorten 50
                            }
                    , modMask = mod4Mask
            }
            `additionalKeys`
            [
                    ((0, xF86XK_AudioLowerVolume), spawn "echo 'Hi ppl!'"),
                    ((0, xF86XK_AudioRaiseVolume), spawn "amixer -D pulse sset Master 15%+")
            ]

2 个答案:

答案 0 :(得分:3)

这是我编写的用于控制脉冲音频音量的脚本。将其转储到名为pulse_control.pl的文件中,并确保它在PATH中可执行。它使用pacmdpactl,您可能需要与发行版的软件包管理器一起安装。

#!/usr/bin/perl

use List::Util qw[min max];
use Getopt::Long;

my $_IS_MUTED;
my $_TOGGLE_MUTE;
my $_VOL;
my $_INC_VOL;
my $_DEC_VOL;

GetOptions(
    "is-muted"    => \$_IS_MUTED
,   "toggle-mute" => \$_TOGGLE_MUTE
,   "volume"      => \$_VOL
,   "inc-vol"     => \$_INC_VOL
,   "dec-vol"     => \$_DEC_VOL
);

my $sink = `pactl info | sed -rn 's/^Default Sink: (.+)\$/\\1/gp'`;
chomp $sink;

sub ismuted {
    my $ismuted = `pacmd dump | grep "$sink" | grep sink-mute | grep yes`;
    chomp $ismuted;
    if ($ismuted ne "") {
        return 1;
    } else {
        0;
    }
}

sub curvol {
    my $volline = `pacmd dump | grep "$sink" | grep sink-vol`;
    if ($volline = ~m / (0x[0 - 9 a - f] + ) / ) {
        return hex $1;
    } else {
        return 0;
    }
}

if ($_IS_MUTED) {
    print ismuted(), "\n";
}
elsif($_TOGGLE_MUTE) {
    if (ismuted()) {
        `pactl set-sink-mute $sink 0`;
    } else {
        `pactl set-sink-mute $sink 1`;
    }
}
elsif($_VOL) {
    print int(curvol() * 100.0 / hex("0x10000")), "%\n";
}
elsif($_INC_VOL) {
    my $newvol = min(hex("0x10000"), curvol() + int((hex("0x10000") * .04)));
    `pactl set-sink-volume $sink $newvol`;
}
elsif($_DEC_VOL) {
    my $newvol = max(0, curvol() - int((hex("0x10000") * .04)));
    `pactl set-sink-volume $sink $newvol`;
}

然后在我的xmonad配置中,我将音量控制绑定到ctrl + alt +(页面向上/向下翻页/结束)。

`additionalKeys`
[
    ((controlMask .|. mod1Mask, xK_Page_Up), spawn "pulse_control.pl -inc")
,   ((controlMask .|. mod1Mask, xK_Page_Down), spawn "pulse_control.pl -dec")
,   ((controlMask .|. mod1Mask, xK_End), spawn "pulse_control.pl -toggle")
]

答案 1 :(得分:0)

这也可以使用以下 $userId = 1; $courses = Course::whereDoesntHave('users', function($userQB) use($userId) { $userQB->where('id',$userId); })->get(); 来实现:

spawn

这些是多媒体键,但您也可以使用 x86Vol 绑定而不是十六进制。