diff options
| author | Josh Rahm <rahm@google.com> | 2023-12-06 19:30:13 -0700 |
|---|---|---|
| committer | Josh Rahm <rahm@google.com> | 2023-12-06 19:30:13 -0700 |
| commit | 0a30958905cfea13e2ee3b62fc38a50d62d8a08e (patch) | |
| tree | c61e5ad3509cef6fbeb26b700017e4c8a08278ae | |
| parent | 74cdda710ffa1f99d8251759a62e1bea9fc61ff5 (diff) | |
| download | rde-0a30958905cfea13e2ee3b62fc38a50d62d8a08e.tar.gz rde-0a30958905cfea13e2ee3b62fc38a50d62d8a08e.tar.bz2 rde-0a30958905cfea13e2ee3b62fc38a50d62d8a08e.zip | |
Add duplicate window
| -rw-r--r-- | src/Rahm/Desktop/Common.hs | 33 | ||||
| -rw-r--r-- | src/Rahm/Desktop/Keys.hs | 14 |
2 files changed, 43 insertions, 4 deletions
diff --git a/src/Rahm/Desktop/Common.hs b/src/Rahm/Desktop/Common.hs index 71ffad0..307dd89 100644 --- a/src/Rahm/Desktop/Common.hs +++ b/src/Rahm/Desktop/Common.hs @@ -2,6 +2,7 @@ module Rahm.Desktop.Common ( focusLocation, masterWindow, windowsInWorkspace, + duplWindow, pointerWorkspace, getString, askWindowId, @@ -26,6 +27,7 @@ module Rahm.Desktop.Common where import Control.Applicative ((<*)) +import Control.Exception (SomeException (SomeException), catch) import Control.Monad (forM_, void, when) import Control.Monad.Trans.Class import Control.Monad.Trans.Except (ExceptT (..), catchE, runExceptT, throwE) @@ -34,9 +36,11 @@ import Control.Monad.Trans.Maybe (MaybeT (..)) import Data.Char (toLower) import Data.Either (either) import Data.List (concatMap, head, isInfixOf, map, (++)) +import Data.List.Split (splitOn) import qualified Data.Map as Map (fromListWith) import Data.Maybe (Maybe (..), maybe) import Data.Void (Void (..), absurd) +import Data.Word (Word32) import Rahm.Desktop.DMenu (runDMenuPromptWithMap) import Rahm.Desktop.Logger import qualified Rahm.Desktop.StackSet as S @@ -63,17 +67,21 @@ import XMonad asks, focus, io, + liftX, refresh, runQuery, setWindowBorderWidth, setWindowBorderWithFallback, + stringProperty, title, windows, withFocused, withWindowSet, ) import qualified XMonad as X +import qualified XMonad.Hooks.ManageHelpers as X import XMonad.Prompt (XPrompt (commandToComplete, showXPrompt)) +import qualified XMonad.Util.Run as X import XMonad.Util.XUtils (pixelToString, stringToPixel) -- A location is a workspace and maybe a window with that workspace. @@ -253,3 +261,28 @@ pointerWorkspace = runMaybeT $ do (S.Screen (S.tag -> ws1) _ _) <- MaybeT $ X.pointScreen x y return ws1 +-- Creates a duplicate process of a window by running the cmdline +-- that created it. +duplWindow :: Window -> X () +duplWindow = runQuery $ do + pid' <- X.pid + liftX $ logs Info "Duplicating for pid %s" (show pid') + forM_ pid' $ \pid -> do + cmd <- + liftX $ + io $ + catch + (fmap (Right . splitOn "\0") $ readFile $ "/proc/" <> show pid <> "/cmdline") + ( \e -> + let ex = e :: SomeException + in return $ Left (printf "Could not read cmdline file: %s" (show ex)) + ) + + liftX $ + case cmd of + Right c -> do + logs Info "executing cmdline: %s\n" (show c) + case c of + (a : (init -> as)) -> X.safeSpawn a as + _ -> return () + Left err -> logs Info "%s" (err :: String) diff --git a/src/Rahm/Desktop/Keys.hs b/src/Rahm/Desktop/Keys.hs index 210d4c5..76634b0 100644 --- a/src/Rahm/Desktop/Keys.hs +++ b/src/Rahm/Desktop/Keys.hs @@ -47,10 +47,11 @@ import Rahm.Desktop.Common gotoWorkspace, locationWindow, locationWorkspace, + pointerWorkspace, runMaybeT_, setBorderColor, withBorderColor, - withBorderColorM, pointerWorkspace, + withBorderColorM, duplWindow, ) import Rahm.Desktop.DMenu (runDMenu) import qualified Rahm.Desktop.Dragging as D @@ -302,6 +303,11 @@ keymap = runKeys $ do (h : _) -> lift (focusLocation h) _ -> return () + bind xK_semicolon $ + justMod $ + doc "Run the command which opened this window again." $ + X.withFocused duplWindow + bind xK_w $ do justMod $ doc "Swap windows with other windows" $ @@ -1102,8 +1108,8 @@ mouseMap = runButtons $ do bind button2 $ noMod $ - doc "Sink the window under the cursor into the tiling" $ - windows . W.sink + doc "Run the command that started a window." $ + duplWindow bind button3 $ noMod $ @@ -1170,7 +1176,7 @@ mouseMap = runButtons $ do bind button2 $ noMod $ - doc "Clear the window selection" (noWindow clearWindowSelection) + doc "Clear the window selection" $ noWindow (clearWindowSelection >> escape) bind button13 $ noMod $ |