xmonad-contrib patch

Hi all,
Just wanted to say Thanks! to everyone for XMonad. I've got it
running with gnome for the panels but it blows the gnome WM out of
the water.
I did run across some functionality I wanted that didn't exist so I
wrote it up (attached). On reflection I should have added a long
patch message. I found WindowGo for runOrRaise but often I want to
pull a window (browser, mail, etc) to my current workspace instead
of going to the one it's in. copyOrRun (and underlying copyMaybe)
do that.
Cheers,
-ljr
New patches:
[XMonad.Actions.CopyWindow runOrCopy
lan3ny@gmail.com**20080602205742] {
hunk ./XMonad/Actions/CopyWindow.hs 5
--- Copyright : (c) David Roundy

On 2008.06.02 16:26:57 -0500, Lanny Ripple
Hi all,
Just wanted to say Thanks! to everyone for XMonad. I've got it running with gnome for the panels but it blows the gnome WM out of the water.
I did run across some functionality I wanted that didn't exist so I wrote it up (attached). On reflection I should have added a long patch message. I found WindowGo for runOrRaise but often I want to pull a window (browser, mail, etc) to my current workspace instead of going to the one it's in. copyOrRun (and underlying copyMaybe) do that.
Cheers, -ljr
This looks interesting, but I am not thrilled by the duplication of raiseMaybe's code (DRY). Could raiseMaybe and copyMaybe be specialized functions instead, perhaps? It would look something like this, I guess: somethingMaybe ∷ (Window -> X ()) -> X () → Query Bool → X () somethingMaybe doWin f thatUserQuery = withWindowSet $ λs → do maybeResult ← filterM (runQuery thatUserQuery) (W.allWindows s) case maybeResult of [] → f (x:_) → doWin x raiseMaybe = somethingMaybe focus copyMaybe = somethingMaybe (windows . flip copyWindow (currentTag s)) -- gwern SBU botux Crust SALDV hrt .45 Threat Nike comsat 747

I wasn't thrilled with it either but wasn't sure where to put actionMaybe (the name I had for it). In WindowGo and import into CopyWindow? In a new Util module and import into both? There's also the problem that focus :: win -> X () (windows . copyWindow) :: win -> ws -> X() where 'ws' has to be discovered in actionMaybe. So raiseMaybe = actionMaybe (focus . const) copyMaybe = actionMaybe (windows . copyWindow) actionMaybe = (Window -> Workspace -> X ()) -> Query Bool -> X () actionMaybe doWin f thatUserQuery = withWindowSet $ \x -> do maybeResult <- filterM (runQuery thatUserQuery) (allWindows s) case maybeResult of [] -> f (win:_) -> doWin win (currentTag s) which I don't know if I'm happy about. Anyway happy to make the changes if I can get some advice on where to put the abstracted (hoisted?, common?) code. -ljr Gwern Branwen wrote:
On 2008.06.02 16:26:57 -0500, Lanny Ripple
scribbled 21K characters: Hi all,
Just wanted to say Thanks! to everyone for XMonad. I've got it running with gnome for the panels but it blows the gnome WM out of the water.
I did run across some functionality I wanted that didn't exist so I wrote it up (attached). On reflection I should have added a long patch message. I found WindowGo for runOrRaise but often I want to pull a window (browser, mail, etc) to my current workspace instead of going to the one it's in. copyOrRun (and underlying copyMaybe) do that.
Cheers, -ljr
This looks interesting, but I am not thrilled by the duplication of raiseMaybe's code (DRY). Could raiseMaybe and copyMaybe be specialized functions instead, perhaps?
It would look something like this, I guess:
somethingMaybe ∷ (Window -> X ()) -> X () → Query Bool → X () somethingMaybe doWin f thatUserQuery = withWindowSet $ λs → do maybeResult ↠filterM (runQuery thatUserQuery) (W.allWindows s) case maybeResult of [] → f (x:_) → doWin x
raiseMaybe = somethingMaybe focus copyMaybe = somethingMaybe (windows . flip copyWindow (currentTag s))
-- gwern SBU botux Crust SALDV hrt .45 Threat Nike comsat 747

On 2008.06.03 09:42:42 -0500, Lanny Ripple
I wasn't thrilled with it either but wasn't sure where to put actionMaybe (the name I had for it). In WindowGo and import into CopyWindow? In a new Util module and import into both?
For now I would stick it in WindowGo, and import it. One function isn't enough to make a module if there is no compelling reason to. (I mean, if importing WindowGo added some huge dependencies to CopyWindow, sure, but they're both in XMC and depend on the same stuff.)
There's also the problem that
focus :: win -> X ()
(windows . copyWindow) :: win -> ws -> X()
where 'ws' has to be discovered in actionMaybe. So
raiseMaybe = actionMaybe (focus . const) copyMaybe = actionMaybe (windows . copyWindow)
actionMaybe = (Window -> Workspace -> X ()) -> Query Bool -> X () actionMaybe doWin f thatUserQuery = withWindowSet $ \x -> do maybeResult <- filterM (runQuery thatUserQuery) (allWindows s) case maybeResult of [] -> f (win:_) -> doWin win (currentTag s)
which I don't know if I'm happy about.
Anyway happy to make the changes if I can get some advice on where to put the abstracted (hoisted?, common?) code.
-ljr
I think it's a good idea to do the abstraction. Right now there are only two users, yes, but I suspect sooner or later, someone will want a 'deleteMaybe', a 'moveMaybe'... Actually, if we get as many as 4 users, it might make sense to copy it over into XMonad's source whereever the Query monad stuff lives. It would've proven its chops as a utility function, after all. -- gwern Ronco psyops BX Pod SUR House SO13 BBE Blowpipe Satellite

Well this is odd. Working on actionMaybe I see some new functions (since 7.0) in WindowGo so figure I'll incorporate them too. actionMaybe :: ([a] -> WindowSet -> X ()) -> X () -> Query Bool -> X () actionMaybe doWin doNoWin thatUserQuery = withWindowSet $ \s -> do ws <- filterM (runQuery thatUserQuery) (W.allWindows s) case ws of [] -> doNoWin otherwise -> doWin ws s raiseMaybe, raiseNextMaybe, copyMaybe :: X () -> Query Bool -> X () raiseMaybe = actionMaybe doRaise where doRaise (x:_) _ = focus x raiseNextMaybe = actionMaybe doRaiseNext where ... copyMaybe = actionMaybe doCopyWindow where doCopyWindow (x:_) s = windows $ copyWindow x (currentTag s) But this doesn't work. As near as I can tell actionMaybe is demanding (I'm using typeOf from http://cgi.cse.unsw.edu.au/~dons/blog/2006/12/14#vim-typeof) to be type actionMaybe :: ([Graphics.X11.Types.Window] -> WindowSet -> X ()) -> X () -> Query Bool -> X () which is even more odd because when I then try and get the compiler to tell me what other types should be (as a cross-check) I get Not in scope: type constructor or class `Graphics.X11.Types.Window' And sure enough on compilation XMonad/Actions/WindowGo.hs:174:27: Couldn't match expected type `a' against inferred type `Graphics.X11.Types.Window' `a' is a rigid type variable bound by the type signature for `actionMaybe' at XMonad/Actions/WindowGo.hs:169:17 Expected type: [a] Inferred type: [Graphics.X11.Types.Window] In the first argument of `doWin', namely `ws' In the expression: doWin ws s I tried Rank2Types {-# OPTIONS_GHC -XRank2Types #-} actionMaybe :: (forall a. [a] -> WindowSet -> X ()) -> ... with the same result. The solution to this is beyond my Haskell knowledge. I can see that (runQuery thatUserQuery) is reaching down into the X11 implementation and pulling back [Graphics.X11.Types.Window] but why can't I set up a function type that will bind to this type while being as "generic" as the rest of the types in the module? Stumped, -ljr Gwern Branwen wrote:
On 2008.06.03 09:42:42 -0500, Lanny Ripple
scribbled 2.2K characters: I wasn't thrilled with it either but wasn't sure where to put actionMaybe (the name I had for it). In WindowGo and import into CopyWindow? In a new Util module and import into both?
For now I would stick it in WindowGo, and import it. One function isn't enough to make a module if there is no compelling reason to. (I mean, if importing WindowGo added some huge dependencies to CopyWindow, sure, but they're both in XMC and depend on the same stuff.)
There's also the problem that
focus :: win -> X ()
(windows . copyWindow) :: win -> ws -> X()
where 'ws' has to be discovered in actionMaybe. So
raiseMaybe = actionMaybe (focus . const) copyMaybe = actionMaybe (windows . copyWindow)
actionMaybe = (Window -> Workspace -> X ()) -> Query Bool -> X () actionMaybe doWin f thatUserQuery = withWindowSet $ \x -> do maybeResult <- filterM (runQuery thatUserQuery) (allWindows s) case maybeResult of [] -> f (win:_) -> doWin win (currentTag s)
which I don't know if I'm happy about.
Anyway happy to make the changes if I can get some advice on where to put the abstracted (hoisted?, common?) code.
-ljr
I think it's a good idea to do the abstraction. Right now there are only two users, yes, but I suspect sooner or later, someone will want a 'deleteMaybe', a 'moveMaybe'...
Actually, if we get as many as 4 users, it might make sense to copy it over into XMonad's source whereever the Query monad stuff lives. It would've proven its chops as a utility function, after all.
-- gwern Ronco psyops BX Pod SUR House SO13 BBE Blowpipe Satellite

2008/6/2 Lanny Ripple
Hi all,
Just wanted to say Thanks! to everyone for XMonad. I've got it running with gnome for the panels but it blows the gnome WM out of the water.
I did run across some functionality I wanted that didn't exist so I wrote it up (attached). On reflection I should have added a long patch message. I found WindowGo for runOrRaise but often I want to pull a window (browser, mail, etc) to my current workspace instead of going to the one it's in. copyOrRun (and underlying copyMaybe) do that.
Cheers, -ljr
New patches:
[XMonad.Actions.CopyWindow runOrCopy lan3ny@gmail.com**20080602205742] { hunk ./XMonad/Actions/CopyWindow.hs 5 --- Copyright : (c) David Roundy
, Ivan Veselov +-- Copyright : (c) David Roundy , Ivan Veselov , Lanny Ripple hunk ./XMonad/Actions/CopyWindow.hs 20 - copy, copyToAll, copyWindow, killAllOtherCopies, kill1 + copy, copyToAll, copyWindow, runOrCopy + , killAllOtherCopies, kill1 hunk ./XMonad/Actions/CopyWindow.hs 25 +import Control.Monad (filterM) hunk ./XMonad/Actions/CopyWindow.hs 55 +-- Instead of copying a window from a workset to a workset maybe you don't +-- want to have to remember where you placed it. For that consider: +-- +-- > , ((modMask x, xK_b ), runOrCopy "firefox" (className =? "Firefox")) -- @@ run or copy firefox +-- hunk ./XMonad/Actions/CopyWindow.hs 68 --- > , ((modMask x, xK_v )", windows copyToAll) -- @@ Make focused window always visible +-- > , ((modMask x, xK_v ), windows copyToAll) -- @@ Make focused window always visible hunk ./XMonad/Actions/CopyWindow.hs 74 --- | copy. Copy the focussed window to a new workspace. +-- | copy. Copy the focused window to a new workspace. hunk ./XMonad/Actions/CopyWindow.hs 94 + +-- | runOrCopy . runOrCopy will run the provided shell command unless it can +-- find a specified window in which case it will copy the window to +-- the current workspace. Similar to (i.e., stolen from) "XMonad.Actions.WindowGo". +runOrCopy :: String -> Query Bool -> X () +runOrCopy action = copyMaybe $ spawn action + +-- | copyMaybe. Flatters "XMonad.Actions.WindowGo" ('raiseMaybe') +copyMaybe :: X () -> Query Bool -> X () +copyMaybe f thatUserQuery = withWindowSet $ \s -> do + maybeResult <- filterM (runQuery thatUserQuery) (allWindows s) + case maybeResult of + [] -> f + (x:_) -> windows $ copyWindow x (currentTag s) + } ...
Applied, thanks. -- gwern
participants (2)
-
Gwern Branwen
-
Lanny Ripple