From 8ffc997f99ff48d92437a7617f196757c33f3809 Mon Sep 17 00:00:00 2001 From: Hektor Misplon Date: Sat, 24 Sep 2022 01:07:06 +0200 Subject: [PATCH] Update xmonad configuration --- .vimrc | 2 +- .xmonad/xmonad.hs | 191 +++++++++++++++++++++++++++++++--------------- 2 files changed, 131 insertions(+), 62 deletions(-) diff --git a/.vimrc b/.vimrc index fdb6c23..5292e39 100644 --- a/.vimrc +++ b/.vimrc @@ -1,4 +1,4 @@ -" General config ______________________ +" General config {{{ " " Most acronyms are unreadable, but they keep the overview " I have to do a quick :h lookup for most of these anyway. diff --git a/.xmonad/xmonad.hs b/.xmonad/xmonad.hs index 0b5549b..b547e31 100644 --- a/.xmonad/xmonad.hs +++ b/.xmonad/xmonad.hs @@ -1,85 +1,154 @@ -import System.IO import XMonad -import XMonad.Config.Desktop import XMonad.Hooks.DynamicLog import XMonad.Hooks.ManageDocks -import XMonad.Layout.BorderResize -import XMonad.Layout.Fullscreen -import XMonad.Layout.Grid -import XMonad.Layout.NoBorders (noBorders, smartBorders) -import XMonad.Layout.ResizableTile (MirrorResize (..), - ResizableTall (..)) + +import XMonad.Layout.Magnifier import XMonad.Layout.Spacing import XMonad.Layout.Tabbed (Theme (..), shrinkText, tabbedAlways) +import XMonad.Layout.ThreeColumns import XMonad.Layout.ToggleLayouts (ToggleLayout (..), toggleLayouts) import XMonad.Layout.WindowArranger + import XMonad.Util.EZConfig +import XMonad.Util.Loggers import XMonad.Util.Paste import XMonad.Util.Run (spawnPipe) +import XMonad.Util.Ungrab import XMonad.Actions.CycleWS -import XMonad.Actions.GridSelect import XMonad.Actions.WindowGo -import XMonad.Hooks.EwmhDesktops + import XMonad.Hooks.ManageHelpers import XMonad.Hooks.ScreenCorners +import XMonad.Hooks.StatusBar +import XMonad.Hooks.StatusBar.PP + +import qualified XMonad.Util.Hacks as Hacks + +-- EWMH compliance +import XMonad.Hooks.EwmhDesktops import qualified Data.Map.Strict as M import qualified XMonad.StackSet as W +-- Magnifier is off by default (can be controlled using arrow keys) +myLayout = threeColMid ||| + magnifiercz magnificationFactorH tiled ||| + magnifiercz magnificationFactorV (Mirror tiled) ||| + Full + where + magnificationFactorV = 1.384 + magnificationFactorH = 1.621 + tiled = Tall nmaster delta ratio + threeCol = ThreeCol nmaster delta ratio + threeColMid = ThreeColMid nmaster delta ratio + nmaster = 1 + ratio = 1/2 + delta = 4/100 + myStartupHook = do - addScreenCorners [ (SCLowerRight, nextWS) - , (SCLowerRight, prevWS) + addScreenCorners [ (SCUpperRight, nextWS) + , (SCUpperLeft, prevWS) ] -main = do - xmproc <- spawnPipe "xmobar" - xmonad $ def { - terminal = "alacritty" - -- Use Win key instead of Alt - , modMask = mod4Mask - , workspaces = ["α", "β", "γ", "δ", "ε"] - -- Styling - , focusedBorderColor = "#000000" - , normalBorderColor = "#111111" - , borderWidth = 2 - -- Hooks - , startupHook = myStartupHook - , layoutHook = screenCornerLayoutHook $ layoutHook def - , handleEventHook = handleEventHook def <+> screenCornerEventHook - , logHook = dynamicLogWithPP xmobarPP - { ppOutput = hPutStrLn xmproc - , ppTitle = xmobarColor "green" "" . shorten 50 - } - } `additionalKeysP` - -- Keybindings to be added - [ ("M-S-", withFocused $ windows . W.sink) - , ("M-p", spawn "rofi -show run") - -- Map insert key to paste from clipboard - , ("", pasteSelection) - -- Map print screen to take a screenshot with flameshot - , ("", spawn "flameshot gui") - -- Map audio keys to control volume - , ("", spawn "pactl set-sink-volume @DEFAULT_SINK@ +5%") - , ("", spawn "pactl set-sink-volume @DEFAULT_SINK@ -5%") - , ("", spawn "pactl set-sink-mute @DEFAULT_SINK@ toggle") - -- Map brightness keys to control brightness with brightnessctl - , ("", spawn "brightnessctl set 20+") - , ("", spawn "brightnessctl set 20-") - -- Map brightness keys + shift to adjust redshift temperature - , ("S-", spawn "echo $(($(cat /tmp/temperature) + 50)) > /tmp/temperature && redshift -O $(cat /tmp/temperature) -P && notify < /tmp/temperature -h string:x-canonical-private-synchronous:anything") - , ("S-", spawn "echo $(($(cat /tmp/temperature) - 50)) > /tmp/temperature && redshift -O $(cat /tmp/temperature) -P && notify < /tmp/temperature -h string:x-canonical-private-synchronous:anything") - -- Reset redshift temperature - , ("M-S-", spawn "echo 3000 > /tmp/temperature && redshift -x") - , ("M-S-", spawn "echo 3000 > /tmp/temperature && redshift -x") - -- Use power down key to suspend - , ("", spawn "systemctl suspend") - , ("M-q", spawn "xmonad --recompile; pkill xmobar; xmonad --restart") - ] - `removeKeysP` - -- Keybindings to be removed - [ "M-t" ] +myConfig = def + { + terminal = "alacritty" -mainManageHook = composeAll - [ className =? "plank" --> doIgnore ] + -- Use Win key instead of Alt + , modMask = mod4Mask + , workspaces = ["α", "β", "γ", "δ", "ε", "ζ", "η", "θ", "ι", "κ"] + + -- Styling + , focusedBorderColor = "#888" + , normalBorderColor = "#000" + , borderWidth = 2 + + -- Hooks + , startupHook = myStartupHook + , layoutHook = screenCornerLayoutHook $ avoidStruts myLayout + , handleEventHook = handleEventHook def <> Hacks.windowedFullscreenFixEventHook <+> screenCornerEventHook + } `additionalKeysP` myKeysP + `removeKeysP` myRemoveKeysP + +-- Keybindings to be added/overridden +myKeysP = [ + -- Fit floating windows back to layout + ("M-S-", withFocused $ windows . W.sink) + + -- Use rofi to launch programs + , ("M-p", spawn "rofi -show run") + + -- Map insert key to paste from clipboard + , ("", pasteSelection) + + -- Map print screen to take a screenshot with flameshot + , ("", spawn "flameshot gui") + + -- Map audio keys to control volume + , ("", spawn "pactl set-sink-volume @DEFAULT_SINK@ +5%") + , ("", spawn "pactl set-sink-volume @DEFAULT_SINK@ -5%") + , ("", spawn "pactl set-sink-mute @DEFAULT_SINK@ toggle") + + -- Map brightness keys to control brightness with brightnessctl + , ("", spawn "brightnessctl set 20+") + , ("", spawn "brightnessctl set 20-") + + -- Map brightness keys + shift to adjust redshift temperature + , ("S-", spawn "echo $(($(cat /tmp/temperature) + 50)) > /tmp/temperature && redshift -O $(cat /tmp/temperature) -P && notify < /tmp/temperature -h string:x-canonical-private-synchronous:anything") + , ("S-", spawn "echo $(($(cat /tmp/temperature) - 50)) > /tmp/temperature && redshift -O $(cat /tmp/temperature) -P && notify < /tmp/temperature -h string:x-canonical-private-synchronous:anything") + + -- Reset redshift temperature + , ("M-S-", spawn "echo 3000 > /tmp/temperature && redshift -x") + , ("M-S-", spawn "echo 3000 > /tmp/temperature && redshift -x") + + -- Use power down key to suspend + , ("", spawn "systemctl suspend") + + -- FIXME: Spawn firefox in fullscreen, but not in kiosk mode + , ("M-S-b", spawn "firefox --fullscreen") + + -- Magnify window using arrow keys + , ("M-", sendMessage MagnifyMore) + , ("M-", sendMessage MagnifyLess) + ] + +-- Keybindings to be removed +myRemoveKeysP = [ "M-t" ] + +myXmobarPP :: PP +myXmobarPP = def + { ppSep = tertiaryColor " | " + , ppTitleSanitize = xmobarStrip + , ppCurrent = brackitify + , ppHidden = secondaryColor . wrap " " "" + , ppHiddenNoWindows = secondaryColor . wrap " " "" + , ppUrgent = red . wrap (yellow "!") (yellow "!") + , ppLayout = \l -> case l of "Tall" -> "[]=" + "Magnifier Tall" -> "[]+" + "Magnifier Mirror Tall" -> "+[]" + "Full" -> "[ ]" + "ThreeCol" -> "|||" + _ -> l + , ppTitle = shorten 80 + , ppOrder = \[ws, l, _, wins] -> [ws, l, wins] + , ppExtras = [logTitles formatFocused formatUnfocused] + } + where + + brackitify = wrap "[" "]" + formatFocused = primaryColor . brackitify . ppWindow + formatUnfocused = secondaryColor . brackitify . ppWindow + + ppWindow = xmobarRaw . (\w -> if null w then "Untitled" else w) . shorten 30 + + primaryColor = xmobarColor "#eeeeee" "" + secondaryColor = xmobarColor "#888888" "" + tertiaryColor = xmobarColor "#555555" "" + white = xmobarColor "#ffffff" "" + yellow = xmobarColor "#ff0" "" + red = xmobarColor "#ff5555" "" + +main :: IO () +main = do xmonad $ docks $ ewmh $ withEasySB (statusBarProp "xmobar" (pure myXmobarPP)) defToggleStrutsKey myConfig