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 | |
| parent | 3b8389042fde0a9dcb1eaa8d6401e8332915af88 (diff) | |
xmonad-tv: update from the dirt
Diffstat (limited to 'pkgs')
| -rw-r--r-- | pkgs/haskell/xmonad-tv/default.nix | 4 | ||||
| -rw-r--r-- | pkgs/haskell/xmonad-tv/src/Shortcuts.hs | 26 | ||||
| -rw-r--r-- | pkgs/haskell/xmonad-tv/src/XMonad/Extra.hs | 37 | ||||
| -rw-r--r-- | pkgs/haskell/xmonad-tv/src/XMonad/Hooks/EwmhDesktops/Extra.hs | 14 | ||||
| -rw-r--r-- | pkgs/haskell/xmonad-tv/src/main.hs | 120 | ||||
| -rw-r--r-- | pkgs/haskell/xmonad-tv/src/xmonad-tv.cabal | 4 |
6 files changed, 173 insertions, 32 deletions
diff --git a/pkgs/haskell/xmonad-tv/default.nix b/pkgs/haskell/xmonad-tv/default.nix index c1a9f994..b0e58cd7 100644 --- a/pkgs/haskell/xmonad-tv/default.nix +++ b/pkgs/haskell/xmonad-tv/default.nix @@ -1,5 +1,5 @@ { mkDerivation, aeson, base, bytestring, containers, desktop-pager -, directory, extra, filepath, lib, unix, X11, xmonad +, directory, extra, filepath, lib, systemd, unix, X11, xmonad , xmonad-contrib }: mkDerivation { @@ -10,7 +10,7 @@ mkDerivation { isExecutable = true; executableHaskellDepends = [ aeson base bytestring containers desktop-pager directory extra - filepath unix X11 xmonad xmonad-contrib + filepath systemd unix X11 xmonad xmonad-contrib ]; license = lib.licenses.mit; mainProgram = "xmonad"; diff --git a/pkgs/haskell/xmonad-tv/src/Shortcuts.hs b/pkgs/haskell/xmonad-tv/src/Shortcuts.hs new file mode 100644 index 00000000..3ac7070b --- /dev/null +++ b/pkgs/haskell/xmonad-tv/src/Shortcuts.hs @@ -0,0 +1,26 @@ +module Shortcuts + ( Config + , new + ) + where + +import Data.Map (Map) +import System.Posix.Process (executeFile) +import XMonad (Layout, KeyMask, KeySym, X, XConfig, xfork) +import XMonad.Util.EZConfig (mkKeymap) +import qualified Data.Map.Strict as Map + + +type Config = Map String String + + +new :: Config -> XConfig Layout -> Map (KeyMask, KeySym) (X ()) +new config xconfig = + mkKeymap xconfig $ + map (\(key, path) -> (key, forkFile path [] Nothing)) $ + Map.toList config + + +forkFile :: FilePath -> [String] -> Maybe [(String, String)] -> X () +forkFile path args env = + xfork (executeFile path True args env) >> return () diff --git a/pkgs/haskell/xmonad-tv/src/XMonad/Extra.hs b/pkgs/haskell/xmonad-tv/src/XMonad/Extra.hs index 74222712..2a234fe2 100644 --- a/pkgs/haskell/xmonad-tv/src/XMonad/Extra.hs +++ b/pkgs/haskell/xmonad-tv/src/XMonad/Extra.hs @@ -1,9 +1,17 @@ +{-# LANGUAGE LambdaCase #-} module XMonad.Extra where import XMonad +import System.IO (hPutStrLn, stderr) import qualified Data.Map as Map +import qualified Data.Maybe import qualified XMonad.StackSet as W +headMaybe :: [a] -> Maybe a +headMaybe = \case + x : _ -> Just x + [] -> Nothing + isFloating :: Window -> WindowSet -> Bool isFloating w = @@ -12,3 +20,32 @@ isFloating w = isFloatingX :: Window -> X Bool isFloatingX w = isFloating w <$> gets windowset + +withFocusedMaybe :: (Maybe Window -> X a) -> X a +withFocusedMaybe f = + withWindowSet $ f . W.peek + +-- Return list of all focused windows. +-- The first element is the focused window on the focused workspace. +-- If there is any error, the empty list will be returned instead. +withAllFocused :: X [Window] +withAllFocused = do + ws <- gets $ + map W.focus . Data.Maybe.catMaybes + . map W.stack + . W.workspaces + . windowset + withFocusedMaybe $ \case + Just w -> + if headMaybe ws == Just w then + return ws + else do + io $ hPutStrLn stderr $ "withAllFocused: error: bad focus: " <> show (w, ws) + return [] + + Nothing -> do + io $ hPutStrLn stderr $ "withAllFocused: error: no focus" + return [] + + + diff --git a/pkgs/haskell/xmonad-tv/src/XMonad/Hooks/EwmhDesktops/Extra.hs b/pkgs/haskell/xmonad-tv/src/XMonad/Hooks/EwmhDesktops/Extra.hs index 7a8947f3..8fc2a62a 100644 --- a/pkgs/haskell/xmonad-tv/src/XMonad/Hooks/EwmhDesktops/Extra.hs +++ b/pkgs/haskell/xmonad-tv/src/XMonad/Hooks/EwmhDesktops/Extra.hs @@ -111,6 +111,19 @@ ewmhDesktopsExtraEventHook = \case createNames = Set.toAscList $ Set.difference createNameSet renamesTo + when ( not (null createNames) + || not (null deleteNames) + || not (null renames) + ) $ do + let optional c v = if c then v else mempty + let unlessNull c = optional (not (null c)) + trace $ unlines $ filter (/= mempty) + [ "_NET_DESKTOP_NAMES:" + , unlessNull createNames $ " create: " <> show createNames + , unlessNull deleteNames $ " delete: " <> show deleteNames + , unlessNull renames $ " rename: " <> show renames + ] + mapM_ addHiddenWorkspace createNames mapM_ removeEmptyWorkspaceByTag deleteNames when (not (null renames)) $ do @@ -123,6 +136,7 @@ ewmhDesktopsExtraEventHook = \case modifyWindowSet $ mapWorkspace rename + -- if using removeWorkspaceByTag, then names = sort newNames names <- gets $ map tag . sort . workspaces . windowset when (names /= newNames) $ do 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 diff --git a/pkgs/haskell/xmonad-tv/src/xmonad-tv.cabal b/pkgs/haskell/xmonad-tv/src/xmonad-tv.cabal index 2fb909a2..c72e7922 100644 --- a/pkgs/haskell/xmonad-tv/src/xmonad-tv.cabal +++ b/pkgs/haskell/xmonad-tv/src/xmonad-tv.cabal @@ -18,11 +18,15 @@ executable xmonad , directory , extra , filepath + , systemd , unix , xmonad , xmonad-contrib + other-modules: + Shortcuts Shutdown + SuperToRiver XMonad.Extra XMonad.Hooks.EwmhDesktops.Extra default-language: Haskell2010 |
