codehenry / xmonad

Automatically exported from code.google.com/p/xmonad
0 stars 0 forks source link

Feature request: greedyFocusWindow #548

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
It would be nice to have a greedy counterpart of the focusWindow function.
I work with two screens, one of which is my main screen and the other one
used occasionally. I use WindowGo.runOrRaise to focus my browser window and I 
expect the focusing to be greedy. Currently I use the following code (with 
focusWindowGreedy being a copy of focusWindow with view replaced by greedyView).
If you find this relevant, I can provide a patch.

Thanks!

focusWindowGreedy :: (Eq s, Eq a, Eq i) => a -> W.StackSet i l a s sd -> 
W.StackSet i l a s sd
focusWindowGreedy w s | Just w == W.peek s = s 
                | otherwise        = fromMaybe s $ do
                    n <- W.findTag w s 
                    return $ until ((Just w ==) . W.peek) W.focusUp (W.greedyView n s)

raiseGreedy :: Query Bool -> X ()
raiseGreedy = raiseMaybeGreedy $ return ()

runOrRaiseGreedy :: String -> Query Bool -> X ()
runOrRaiseGreedy = raiseMaybeGreedy . safeSpawnProg

raiseMaybeGreedy :: X () -> Query Bool -> X ()
raiseMaybeGreedy f qry = ifWindow qry raiseHookGreedy f

raiseHookGreedy :: ManageHook
raiseHookGreedy = ask >>= doF . focusWindowGreedy

browserQuery = className =? "Google-chrome"

Original issue reported on code.google.com by yurac...@gmail.com on 18 Jun 2013 at 7:29

GoogleCodeExporter commented 8 years ago
Yes these are useful. A good question is whether these versions/copies belong 
alongside the versions based on W.view, or maybe there's a better approach:

It should be possible to write a function which corrects which workspaces are 
on each screen after some other action runs (which is slightly bad because then 
you have two calls to `XMonad.Operations.windows'):

greedy :: X () -> X ()

It could do something similar to the following:

greedy2 :: (Eq s, Eq i) => (W.StackSet i l1 a1 s sd1 -> W.StackSet i l a s sd) 
-> W.StackSet i l1 a1 s sd1 -> W.StackSet i l a s sd
greedy2 f ws0 = let
        swap a b = W.greedyView a . W.view b
        s0 = W.screen $ W.current ws0
        ws1 = f ws0
    in if s0 == W.screen (W.current ws1) then ws1 else swap (W.currentTag ws1) (W.currentTag ws0) ws1

At least to some approximation, greedy2 . W.view == W.greedyView

Original comment by vogt.a...@gmail.com on 19 Jun 2013 at 6:15

GoogleCodeExporter commented 8 years ago
Seems like the greedy2 function you propose is the more generic and useful 
solution

Thanks!

Original comment by yurac...@gmail.com on 19 Jun 2013 at 7:09