From 8475c103767344bd9c6a47052794cc14675d24cd Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Mon, 1 Nov 2021 13:59:03 -0600 Subject: Add more DMenu integration & Add ability to change the spacing with Mod+Shift+[]. --- src/Internal/DMenu.hs | 29 +++++++++++++++++++++++++++++ src/Internal/Keys.hs | 11 +++++++++-- src/Internal/Lib.hs | 31 ++++++++++++++++++++----------- 3 files changed, 58 insertions(+), 13 deletions(-) (limited to 'src/Internal') diff --git a/src/Internal/DMenu.hs b/src/Internal/DMenu.hs index c5cac49..d91c7ba 100644 --- a/src/Internal/DMenu.hs +++ b/src/Internal/DMenu.hs @@ -1,10 +1,39 @@ module Internal.DMenu where +import XMonad.Util.Dmenu import XMonad import XMonad.Util.Run import Control.Monad +import Data.Map (Map) +import qualified Data.Map as Map +import XMonad.Util.Run +import Data.List (intercalate) + +data Colors = + Colors { + fg :: String, + bg :: String + } | DefaultColors runDMenu :: X () runDMenu = void $ safeSpawn "/usr/bin/dmenu_run" [ "-p", "Execute ", "-l", "12", "-dim", "0.4"] + +runDMenuPrompt :: String -> Maybe String -> [String] -> X String +runDMenuPrompt prompt color select = + let realColor = maybe [] (\c -> ["-sb", c, "-nf", c]) color + in + runProcessWithInput "/home/rahm/.local/bin/dmenu_debug.sh" ([ + "-p", prompt, + "-l", "12", + "-dim", "0.4" ] ++ realColor) (intercalate "\n" select) + + +runDMenuPromptWithMap :: String -> Maybe String -> Map String a -> X (Maybe a) +runDMenuPromptWithMap prompt color map = do + let realColor = maybe [] (\c -> ["-sb", c, "-nf", c]) color + menuMapArgs "dmenu"([ + "-p", prompt, + "-l", "12", + "-dim", "0.4" ] ++ realColor) map diff --git a/src/Internal/Keys.hs b/src/Internal/Keys.hs index 91d033d..c97736f 100644 --- a/src/Internal/Keys.hs +++ b/src/Internal/Keys.hs @@ -4,6 +4,7 @@ module Internal.Keys where import Graphics.X11.ExtraTypes.XorgDefault import System.Process import XMonad.Util.Ungrab +import XMonad.Layout.Spacing import Internal.XPlus import Data.Maybe (isJust) import Debug.Trace @@ -65,6 +66,10 @@ click = do (_, _, window, _, _, _, _, _) <- io $ queryPointer dpy root focus window +modifyWindowBorder :: Integer -> SpacingModifier +modifyWindowBorder i = ModifyWindowBorder $ \(Border a b c d) -> + (Border (a + i) (b + i) (c + i) (d + i)) + newKeys :: MarkContext -> IO (KeyMap l) newKeys markContext = return $ \config@(XConfig {modMask = modm}) -> @@ -102,8 +107,10 @@ newKeys markContext = mapNumbersAndAlpha 0 ( runXPlus markContext config . swapWorkspace))) - , ((modm .|. shiftMask, xK_bracketleft), sendMessage (IncMasterN (-1))) - , ((modm .|. shiftMask, xK_bracketright), sendMessage (IncMasterN 1)) + , ((modm, xK_minus), sendMessage (IncMasterN (-1))) + , ((modm, xK_plus), sendMessage (IncMasterN 1)) + , ((modm .|. shiftMask, xK_bracketleft), sendMessage (modifyWindowBorder (-1))) + , ((modm .|. shiftMask, xK_bracketright), sendMessage (modifyWindowBorder 1)) , ((modm, xK_bracketleft), sendMessage ShrinkZoom) , ((modm, xK_bracketright), sendMessage ExpandZoom) diff --git a/src/Internal/Lib.hs b/src/Internal/Lib.hs index e0b78c5..feb5f26 100644 --- a/src/Internal/Lib.hs +++ b/src/Internal/Lib.hs @@ -3,6 +3,7 @@ module Internal.Lib where import Prelude hiding ((!!)) +import XMonad.Util.Run import XMonad.Prompt import XMonad.Prompt.Input import XMonad.Prompt.Shell @@ -19,6 +20,7 @@ import Text.Printf import XMonad hiding (workspaces, Screen) import XMonad.StackSet hiding (filter, focus) import qualified Data.Map as Map +import Internal.DMenu type WorkspaceName = Char newtype Selector = Selector (forall a. (Eq a) => a -> [a] -> a) @@ -123,15 +125,22 @@ windowJump = do windowTitlesToWinId <- withWindowSet $ \ss -> Map.fromList <$> mapM (\wid -> (,) <$> getString wid <*> return wid) (allWindows ss) - mkXPrompt - WinPrompt - xpConfig - (\input -> return $ filter (fuzzyCompletion input) (Map.keys windowTitlesToWinId)) $ - \str -> do + windowId <- runDMenuPromptWithMap "Window" (Just "#f542f5") windowTitlesToWinId + + case windowId of + Nothing -> return () + Just wid -> do saveLastMark markContext - case Map.lookup str windowTitlesToWinId of - Just w -> focus w - Nothing -> - case filter (fuzzyCompletion str) (Map.keys windowTitlesToWinId) of - [s] -> mapM_ focus (Map.lookup s windowTitlesToWinId) - _ -> return () + focus wid + -- mkXPrompt + -- WinPrompt + -- xpConfig + -- (\input -> return $ filter (fuzzyCompletion input) (Map.keys windowTitlesToWinId)) $ + -- \str -> do + -- saveLastMark markContext + -- case Map.lookup str windowTitlesToWinId of + -- Just w -> focus w + -- Nothing -> + -- case filter (fuzzyCompletion str) (Map.keys windowTitlesToWinId) of + -- [s] -> mapM_ focus (Map.lookup s windowTitlesToWinId) + -- _ -> return () -- cgit