xmonad: Handle volume keys

This commit is contained in:
Alexander Kobjolke 2024-02-27 22:23:39 +01:00
parent 579901e786
commit 56d9b0d93e

View file

@ -10,6 +10,8 @@ import XMonad.Hooks.EwmhDesktops
import XMonad.Hooks.SetWMName
import qualified XMonad.Hooks.ManageDocks as Docks
import qualified XMonad.Util.EZConfig as EZ
import Numeric.Natural
import Control.Monad (when)
import Text.Printf (printf)
import System.Posix.Process (executeFile)
@ -41,6 +43,26 @@ myLayout = borderResize $ Docks.avoidStruts $ layout
main :: IO ()
main = getDirectories >>= launch myConfig
-- change size of window using direction so that it can be used together with the navigation2D function
-- see: similar to windowGo and windowSwap
windowMoveSplit :: Direction2D -> Bool -> X ()
windowMoveSplit direction _ = sendMessage $ MoveSplit direction
data VolumeCommand = ToggleVolume
| LowerVolume Natural
| RaiseVolume Natural
interpretVolumeCommand :: VolumeCommand -> String
interpretVolumeCommand command = "amixer -q set Master " <> cmd
where
cmd = case command of
ToggleVolume -> "toggle"
LowerVolume delta -> show delta <> "%-"
RaiseVolume delta -> show delta <> "%+"
changeVolume :: VolumeCommand -> X ()
changeVolume = spawn . interpretVolumeCommand
myConfig = ewmhFullscreen $ ewmh $ Docks.docks $ nav $ def
{ modMask = mod4Mask -- Use Super instead of Alt
, terminal = "alacritty"
@ -61,21 +83,27 @@ myConfig = ewmhFullscreen $ ewmh $ Docks.docks $ nav $ def
, ("M-l", WS.toggleWS)
, ("M-g", WS.prevWS)
, ("M-r", WS.nextWS)
-- backlight control
, ("<XF86MonBrightnessDown>", spawn "xbacklight -dec 5")
, ("<XF86MonBrightnessUp>", spawn "xbacklight -inc 5")
, ("<F5>", spawn "xbacklight -dec 5")
, ("<F6>", spawn "xbacklight -inc 5")
, ("M-S-c", sendMessage $ MoveSplit U)
, ("M-S-h", sendMessage $ MoveSplit L)
, ("M-S-t", sendMessage $ MoveSplit D)
, ("M-S-n", sendMessage $ MoveSplit R)
-- volume control
, ("<XF86AudioMute>", changeVolume ToggleVolume)
, ("<XF86AudioLowerVolume>", changeVolume $ LowerVolume 5)
, ("<XF86AudioRaiseVolume>", changeVolume $ RaiseVolume 5)
, ("M-a", sendMessage Balance)
, ("M-S-a", sendMessage Equalize)
, ("M-o", sendMessage Rotate)
]
where
-- navigate using dvorak bindings
nav = navigation2DP def ("c", "h", "t", "n") [("M-", windowGo), ("M-C-", windowSwap)] True
nav = navigation2DP def ("c", "h", "t", "n") [("M-", windowGo), ("M-C-", windowSwap), ("M-S-", windowMoveSplit)] True
appLauncher = "rofi -show combi -modes combi -combi-modes window,drun,run,ssh"
passLauncher = "rofi-pass"