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 XMonad.Hooks.SetWMName
import qualified XMonad.Hooks.ManageDocks as Docks import qualified XMonad.Hooks.ManageDocks as Docks
import qualified XMonad.Util.EZConfig as EZ import qualified XMonad.Util.EZConfig as EZ
import Numeric.Natural
import Control.Monad (when) import Control.Monad (when)
import Text.Printf (printf) import Text.Printf (printf)
import System.Posix.Process (executeFile) import System.Posix.Process (executeFile)
@ -41,6 +43,26 @@ myLayout = borderResize $ Docks.avoidStruts $ layout
main :: IO () main :: IO ()
main = getDirectories >>= launch myConfig 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 myConfig = ewmhFullscreen $ ewmh $ Docks.docks $ nav $ def
{ modMask = mod4Mask -- Use Super instead of Alt { modMask = mod4Mask -- Use Super instead of Alt
, terminal = "alacritty" , terminal = "alacritty"
@ -61,21 +83,27 @@ myConfig = ewmhFullscreen $ ewmh $ Docks.docks $ nav $ def
, ("M-l", WS.toggleWS) , ("M-l", WS.toggleWS)
, ("M-g", WS.prevWS) , ("M-g", WS.prevWS)
, ("M-r", WS.nextWS) , ("M-r", WS.nextWS)
-- backlight control
, ("<XF86MonBrightnessDown>", spawn "xbacklight -dec 5") , ("<XF86MonBrightnessDown>", spawn "xbacklight -dec 5")
, ("<XF86MonBrightnessUp>", spawn "xbacklight -inc 5") , ("<XF86MonBrightnessUp>", spawn "xbacklight -inc 5")
, ("<F5>", spawn "xbacklight -dec 5") , ("<F5>", spawn "xbacklight -dec 5")
, ("<F6>", spawn "xbacklight -inc 5") , ("<F6>", spawn "xbacklight -inc 5")
, ("M-S-c", sendMessage $ MoveSplit U)
, ("M-S-h", sendMessage $ MoveSplit L) -- volume control
, ("M-S-t", sendMessage $ MoveSplit D)
, ("M-S-n", sendMessage $ MoveSplit R) , ("<XF86AudioMute>", changeVolume ToggleVolume)
, ("<XF86AudioLowerVolume>", changeVolume $ LowerVolume 5)
, ("<XF86AudioRaiseVolume>", changeVolume $ RaiseVolume 5)
, ("M-a", sendMessage Balance) , ("M-a", sendMessage Balance)
, ("M-S-a", sendMessage Equalize) , ("M-S-a", sendMessage Equalize)
, ("M-o", sendMessage Rotate) , ("M-o", sendMessage Rotate)
] ]
where where
-- navigate using dvorak bindings -- 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" appLauncher = "rofi -show combi -modes combi -combi-modes window,drun,run,ssh"
passLauncher = "rofi-pass" passLauncher = "rofi-pass"