You are not logged in.

#1 2009-03-05 20:10:03

Nepherte
Member
From: Singapore
Registered: 2008-09-09
Posts: 427

xmonad: shift and focus window

Is there a way to focus a window when it is spawned/shifted to a workspace in xmonad? For example, I shift my firefox instances to the "web" workspace, but the focus/view remains on the current workspace.

Last edited by Nepherte (2009-03-05 20:13:00)

Offline

#2 2009-03-05 21:22:34

vogt
Member
From: Toronto, Canada
Registered: 2006-11-25
Posts: 389

Re: xmonad: shift and focus window

You want a keybinding that shifts a window to a workspace, and then focuses the workspace?

    -- other keybindings above here
    ++
    [((m .|. modm, k), windows $ f i)
        | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
        , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)
                    , (\i -> W.greedyView i . W.shift i, controlMask)]]

That probably isn't what you want (it moves the focused window to that workspace, and then focuses the same workspace).

Instead of manually moving windows to specific workspace you probably should be using a manageHook.

Offline

#3 2009-03-05 21:31:56

Nepherte
Member
From: Singapore
Registered: 2008-09-09
Posts: 427

Re: xmonad: shift and focus window

It's not really what I was looking for indeed but it comes close. I already use the manageHook to match ClassNames and whatsoever to open applications in a workspace. But if I open firefox from workspace a, manageHook will put firefox in workspace b as defined by the managehook, but the focus remains in workspace a. I want it to focus the just opened firefox in workspace b. I hope I made myself clear.

Offline

#4 2009-03-05 22:30:23

HashBox
Member
Registered: 2009-01-22
Posts: 271

Re: xmonad: shift and focus window

I'm not much of a Haskell coder but I think I know what you're saying, if I understand correctly you want to change something like ", className =? "Gran Paradiso" --> doShift "2:www"" so that it switches to the "2:www" workspace aswell? Are there any resident Haskell/Xmonad experts on this board who can help out with this? I assume it should be almost as simple as adding an extra couple of statements to that line, and I would appreciate this functionality aswell.

Offline

#5 2009-03-05 22:32:15

Nepherte
Member
From: Singapore
Registered: 2008-09-09
Posts: 427

Re: xmonad: shift and focus window

That's exactly what I want

Offline

#6 2009-03-06 05:17:07

abesto
Member
From: Hungary
Registered: 2009-03-05
Posts: 49
Website

Re: xmonad: shift and focus window

I think it's better to keep the workspace-switching in the keybinding. If you run a few of the applications on startup, you'll be jumping around like crazy. I'm not really an expert, but this function should do it:

startFocus command workspace = do
        spawn command
        windows $ W.greedyView workspace

So, for example, to run Firefox and switch to "2:www", bind startFocus "firefox" "2:www" to the key(s) you want. This creates duplication (you have Firefox and 2:www together in both the hook and in the keybinding), so you may want to move these app-workspace pairs into a list.
I tried to get the "move-focus" to work in tha manage hook, but it always dies with a type error.

Fixed code indenting.

Last edited by abesto (2009-03-06 05:18:03)


Linux user #476135 || Dotfiles hosted by GitHub

Offline

#7 2009-03-06 19:25:46

Nepherte
Member
From: Singapore
Registered: 2008-09-09
Posts: 427

Re: xmonad: shift and focus window

W.greedyView seems to do the trick. Any idea how I can combine it in my manageHook so it does both W.shift "web" and W.greedyView "web"? Here's a part of my manageHook

-- Define the workspace an application has to go to
myManageHook = composeAll . concat $ 
        [ -- The applications that go to web
          [ className =? b --> doF (W.shift "web" ) | b <- myClassWebShifts]

Offline

#8 2009-03-06 19:45:41

Ashren
Member
From: Denmark
Registered: 2007-06-13
Posts: 1,229
Website

Re: xmonad: shift and focus window

Here's a way to do it:

className =? b        --> doF (W.shift "web") <+> doF (W.greedyview "web") | b <- myClassWebShifts]

Offline

#9 2009-03-06 21:41:15

Nepherte
Member
From: Singapore
Registered: 2008-09-09
Posts: 427

Re: xmonad: shift and focus window

Thanks, I just figured it out before you posted. Unfortunately it doesn't give the wanted behaviour sad What it does is leave myClassWebShifts unshifted and switches to workspace "web".

Offline

#10 2009-03-07 05:02:57

abesto
Member
From: Hungary
Registered: 2009-03-05
Posts: 49
Website

Re: xmonad: shift and focus window

A somewhat hacky approach: create two managehooks - one with the shift, and the other with the greedyView function. Then do something like this:

newManageHook = myShiftHook <+> myViewHook <+> manageHook defaultConfig

Linux user #476135 || Dotfiles hosted by GitHub

Offline

#11 2009-03-21 20:43:39

Nepherte
Member
From: Singapore
Registered: 2008-09-09
Posts: 427

Re: xmonad: shift and focus window

Unfortunately that doesn't work either. Again, it leaves myClassWebShifts unshifted and it switches to workspace "web". I guess I'll just leave it at that, manually switching to the workspace. I used to resolve this issue by using devilspie back in the days when I used gnome + xmonad. Now that I use xmonad only, I'll have to leave it be since devilspie only works with gnome unless someone comes up with another solution smile

Offline

#12 2009-05-30 08:40:10

eol
Member
Registered: 2009-05-30
Posts: 23

Re: xmonad: shift and focus window

Hello,

, ((0, xK_f), (windows $ W.greedyView "web") >> spawn "firefox")

The above line focuses the "web" workspace and opens firefox in this particular workspace.
Was it what you want?

Offline

#13 2010-09-02 23:02:33

ben.armston
Member
Registered: 2010-09-02
Posts: 1

Re: xmonad: shift and focus window

A few hours of looking for this my self and I finally discovered http://www.haskell.org/haskellwiki/Xmon … onfig_tips which contains the answer.

The following will put new FocusMeNow windows on the "doc" workspace and also greedily view that workspace.

import Control.Monad (liftM2)
 
myManageHook = composeAll
    [ className = "FocusMeNow" --> viewShift "doc"
    -- more hooks
    ]
  where viewShift = doF . liftM2 (.) W.greedyView W.shift

This works just fine for me. I hope it is of some help to you.

Ben.

Offline

#14 2010-09-03 00:05:50

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: xmonad: shift and focus window

Thanks for the solution Ben, but I doubt that the op is still looking for an answer considering that the last post in the thread was over a year ago. Your solution will probably help someone else looking for it.

Closing...


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

Board footer

Powered by FluxBB