diff options
| author | tv <tv@krebsco.de> | 2026-12-04 01:55:06 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-12-04 03:05:12 +0000 |
| commit | 607fb1010baae845910e75ba31687bffb259636b (patch) | |
| tree | 13feecaa2c3c2091c83ea80ebfa1cdbe4db8f361 /pkgs/haskell/xmonad-tv/src/main.hs | |
| parent | 3b8389042fde0a9dcb1eaa8d6401e8332915af88 (diff) | |
xmonad-tv: update from the dirt
Diffstat (limited to 'pkgs/haskell/xmonad-tv/src/main.hs')
| -rw-r--r-- | pkgs/haskell/xmonad-tv/src/main.hs | 120 |
1 files changed, 90 insertions, 30 deletions
diff --git a/pkgs/haskell/xmonad-tv/src/main.hs b/pkgs/haskell/xmonad-tv/src/main.hs index 4e0bbe50..ca5949e7 100644 --- a/pkgs/haskell/xmonad-tv/src/main.hs +++ b/pkgs/haskell/xmonad-tv/src/main.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE ImportQualifiedPost #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE PatternSynonyms #-} @@ -5,19 +6,25 @@ module Main (main) where import System.Exit (exitFailure) -import XMonad.Hooks.EwmhDesktops (ewmh) +import XMonad.Hooks.EwmhDesktops (ewmh, ewmhFullscreen) import XMonad.Hooks.EwmhDesktops.Extra (ewmhExtra) import XMonad.Hooks.RefocusLast (refocusLastLayoutHook, toggleFocus) -import Control.Monad (void) +import Control.Exception (bracket) +import Control.Monad (void, when) import Control.Monad.Extra (whenJustM) -import qualified Data.Aeson -import qualified Data.ByteString.Char8 -import qualified Data.List -import qualified Data.Maybe +import Data.Aeson qualified +import Data.Bits ((.&.)) +import Data.ByteString.Char8 qualified +import Data.Char (isDigit) +import Data.Foldable (traverse_) +import Data.List qualified +import Data.Maybe qualified +import Data.Monoid (All(All)) import Graphics.X11.ExtraTypes.XF86 -import XMonad -import XMonad.Extra (isFloatingX) +import Graphics.X11.Xlib.Display.Extra (defaultDisplayName) +import XMonad hiding (config, directories) +import XMonad.Extra (isFloatingX, withAllFocused) import System.IO (hPutStrLn, stderr) import System.Environment (getArgs, getEnv, getEnvironment, lookupEnv) import System.Posix.Process (executeFile) @@ -26,8 +33,9 @@ import XMonad.Actions.CycleWS (toggleWS) import XMonad.Layout.Gaps (Direction2D(U,R,D,L), gaps) import XMonad.Layout.FocusTracking (focusTracking) import XMonad.Layout.NoBorders (noBorders) -import XMonad.Layout.ResizableTile (ResizableTall(ResizableTall)) import XMonad.Layout.ResizableTile (MirrorResize(MirrorExpand,MirrorShrink)) +import XMonad.Layout.ResizableTile (ResizableTall(ResizableTall)) +import XMonad.Util.ExtensibleState qualified as XS import qualified XMonad.StackSet as W import Data.Map (Map) import qualified Data.Map as Map @@ -39,11 +47,13 @@ import XMonad.Hooks.UrgencyHook , clearUrgents' , withUrgencyHookC ) -import XMonad.Hooks.ManageHelpers (doCenterFloat,doRectFloat) +import XMonad.Hooks.ManageDocks (avoidStruts, docks) +import XMonad.Hooks.ManageHelpers (doCenterFloat, doRectFloat) +import XMonad.ManageHook (doIgnore) import Data.Ratio import XMonad.Hooks.Place (placeHook, smart) -import XMonad.Actions.PerWorkspaceKeys (chooseAction) - +import qualified System.Systemd.Daemon as Systemd +import qualified Shortcuts import SuperToRiver qualified import Shutdown (shutdown, newShutdownEventHandler) import System.IO.Unsafe (unsafePerformIO) @@ -63,6 +73,7 @@ main = getArgs >>= \case (=??) :: Query a -> (a -> Bool) -> Query Bool (=??) x p = fmap p x + readEnv :: Data.Aeson.FromJSON b => String -> IO b readEnv name = readEnv' (error $ "could not get environment variable: " <> name) name @@ -77,16 +88,23 @@ readEnv' defaultValue name = mainNoArgs :: IO () mainNoArgs = do + getEnvironment >>= \env -> writeFile sliceEnvPath $ unlines [ k <> "=" <> v | (k, v) <- env] + myMasterDelta <- readEnv' (1 / 20) "XMONAD_MASTER_DELTA" :: IO Rational myMasterWidth <- readEnv' (1 / 2) "XMONAD_MASTER_WIDTH" :: IO Rational myScreenGaps <- readEnv' [] "XMONAD_SCREEN_GAPS" :: IO [Int] myScreenWidth <- bracket (getEnv "DISPLAY" >>= openDisplay) closeDisplay (return . widthOfScreen . defaultScreenOfDisplay) + shortcuts <- + Shortcuts.new . Data.Maybe.fromMaybe mempty + <$> (Data.Aeson.decodeFileStrict' =<< getEnv "XMONAD_SHORTCUTS") handleShutdownEvent <- newShutdownEventHandler config <- ewmhExtra + $ ewmhFullscreen $ ewmh + $ docks $ withUrgencyHookC BorderUrgencyHook { urgencyBorderColor = "#ff0000" @@ -96,13 +114,15 @@ mainNoArgs = do , suppressWhen = Never } $ def - { terminal = {-pkg:alacritty-tv-}"alacritty" - , clientMask = clientMask def .|. focusChangeMask + { clientMask = clientMask def .|. focusChangeMask , modMask = mod4Mask , keys = \c -> myKeys c `Map.union` SuperToRiver.bindings + `Map.union` shortcuts c + , layoutHook = + avoidStruts $ refocusLastLayoutHook $ gaps (zip [U,R,D,L] myScreenGaps) $ ResizableTall @@ -114,16 +134,17 @@ mainNoArgs = do noBorders (focusTracking Full) , manageHook = composeAll - [ appName =? "fzmenu-urxvt" --> doCenterFloat - , appName =?? Data.List.isPrefixOf "pinentry" --> doCenterFloat + [ appName =?? Data.List.isPrefixOf "pinentry" --> doCenterFloat , appName =?? Data.List.isInfixOf "Float" --> doCenterFloat + , appName =?? Data.List.isInfixOf "Ignore" --> doIgnore , title =? "Upload to Imgur" --> doRectFloat (W.RationalRect 0 0 (1 % 8) (1 % 8)) , placeHook (smart (1,0)) ] - , startupHook = + , startupHook = do whenJustM (io (lookupEnv "XMONAD_STARTUP_HOOK")) (\path -> forkFile path [] Nothing) + io (void Systemd.notifyReady) , normalBorderColor = "#1c1c1c" , focusedBorderColor = "#f000b0" , handleEventHook = handleFocusChangeEvent <> handleShutdownEvent @@ -162,9 +183,16 @@ forkFileInSlice sliceName path args = void . xfork $ Nothing +displayNumber :: Int +displayNumber = + read . takeWhile isDigit . dropWhile (==':') $ defaultDisplayName + + myKeys :: XConfig Layout -> Map (KeyMask, KeySym) (X ()) myKeys conf = Map.fromList $ - [ ((_4 , xK_Escape ), forkFile {-pkg-}"slock" [] Nothing) + [ ((_4 , xK_Escape ), forkFile {-notpkg-}"slock" [] Nothing) + , ((0 , xF86XK_ScreenSaver ), forkFile {-notpkg-}"slock" [] Nothing) + , ((_4S , xK_c ), kill) , ((_4 , xK_o ), forkFile {-pkg:fzmenu-}"otpmenu" [] Nothing) @@ -172,21 +200,57 @@ myKeys conf = Map.fromList $ , ((_4 , xK_p ), forkFile {-pkg:fzmenu-}"passmenu" [] Nothing) , ((_4C , xK_p ), forkFile {-pkg:fzmenu-}"passmenu" ["--phase2-method=copy"] Nothing) - , ((_4 , xK_x ), forkFileInSlice "alacritty" {-pkg:alacritty-tv-}"alacritty" ["--dtach", "--singleton"]) - , ((_4C , xK_x ), forkFileInSlice "alacritty" {-pkg:alacritty-tv-}"alacritty" ["--profile=root", "-e", "/run/wrappers/bin/su", "-"]) + , ((_4 , xK_x ), forkFileInSlice "alacritty" {-pkg:alacritty-tv-}"alacritty" []) - , ((_C , xK_Menu ), toggleWS) + , ((_4C , xK_x ), + forkFileInSlice "alacritty" {-pkg:alacritty-tv-}"alacritty" ["-e", {-pkg-}"su2", "user=root"] + ) + + , ((0 , xK_Menu ), do + focusedWindows <- withAllFocused + forkFile {-pkg-}"desktop-pager" ("view" : map show focusedWindows) Nothing + ) + , ((_S , xK_Menu ), do + focusedWindows <- withAllFocused + forkFile {-pkg-}"desktop-pager" ("shift" : map show focusedWindows) Nothing + ) + , ((_CS , xK_Menu ) , do + focusedWindows <- withAllFocused + forkFile {-pkg-}"desktop-pager" ("shiftview" : map show focusedWindows) Nothing + ) + + , ((_4 , xK_Menu ), toggleWS) + , ((_M , xK_Menu ), toggleWS) + , ((_4 , xK_e ), toggleWS) + + , ((_4 , xK_Delete ), removeEmptyWorkspace) + + , ((0 , xK_Super_R ), do + focusedWindows <- withAllFocused + forkFile {-pkg-}"desktop-pager" ("view" : map show focusedWindows) Nothing + ) + , ((_S , xK_Super_R ), do + focusedWindows <- withAllFocused + forkFile {-pkg-}"desktop-pager" ("shift" : map show focusedWindows) Nothing + ) + , ((_CS , xK_Super_R ) , do + focusedWindows <- withAllFocused + forkFile {-pkg-}"desktop-pager" ("shiftview" : map show focusedWindows) Nothing + ) + + , ((_C , xK_Super_R ), toggleWS) + , ((_M , xK_Super_R ), toggleWS) , ((_4 , xK_space ), withFocused $ \w -> ifM (isFloatingX w) xdeny $ sendMessage NextLayout) , ((_4M , xK_space ), withFocused $ \w -> ifM (isFloatingX w) xdeny $ resetLayout) , ((_4 , xK_l ), toggleFocus) - , ((_4 , xK_m ), windows W.focusMaster) + , ((_4 , xK_h ), windows W.focusMaster) , ((_4 , xK_j ), windows W.focusDown) , ((_4 , xK_k ), windows W.focusUp) - , ((_4S , xK_m ), windows W.swapMaster) + , ((_4S , xK_h ), windows W.swapMaster) , ((_4S , xK_j ), windows W.swapDown) , ((_4S , xK_k ), windows W.swapUp) @@ -201,18 +265,12 @@ myKeys conf = Map.fromList $ , ((_4 , xK_comma ), sendMessage $ IncMasterN 1) , ((_4 , xK_period ), sendMessage $ IncMasterN (-1)) - , ((_4 , xK_Delete ), removeEmptyWorkspace) - - , ((_4 , xK_Return ), toggleWS) + , ((0, xF86XK_MyComputer), forkFile {-notpkg-}"slock" [] Nothing) - , ((0, xF86XK_AudioLowerVolume), audioLowerVolume) - , ((0, xF86XK_AudioRaiseVolume), audioRaiseVolume) , ((0, xF86XK_AudioMute), audioMute) , ((0, xF86XK_AudioMicMute), audioMicMute) , ((_4, xF86XK_AudioMute), pwvucontrol []) - , ((_4, xK_Prior), forkFile {-pkg-}"xcalib" ["-invert", "-alter"] Nothing) - , ((0, xK_Print), forkFile {-pkg:flameshot-once.profiles.tv-}"flameshot-once" [] Nothing) , ((_C, xF86XK_Forward), forkFile {-pkg:xdpytools-}"xdpychvt" ["next"] Nothing) @@ -221,6 +279,8 @@ myKeys conf = Map.fromList $ where _4 = mod4Mask _C = controlMask + _CM = _C .|. _M + _CS = _C .|. _S _S = shiftMask _M = mod1Mask _4C = _4 .|. _C |
