[xmonad] Updating focus after switching workspaces.

adam vogt vogt.adam at gmail.com
Tue Jan 15 00:41:00 CET 2013


On Mon, Jan 14, 2013 at 3:41 PM, Allen S. Rout <asr at ufl.edu> wrote:
>
> Could someone point me to the right area of the Fine Manual in which I'd
> find techniques to assert focus changes?
>
> I've got a bunch of workspace display features set more or less as I
> desire, with chords set to things like "Show me the web on the right,
> the mail client on the left, and the two screens for project 6 on the
> center two monitors".   But when I've done so, I often find the focus is
> set differently than I'd prefer.
>
> As an initial goal, I was aiming for something like 'See where the mouse
> is?  Put focus there'.

Hi Allen,

I think the xlib function XQueryPointer (called queryPointer in the
haskell X11 binding) tells you which window is under the pointer. You
could try 'man XQueryPointer'.

Once you have that specific Window, you just have to:

focusWindowUnderPointer :: X ()
focusWindowUnderPointer = do
  w <- queryPointer ...
  windows (XMonad.StackSet.focusWindow w)

Then in your keybinding you'll just have something like:

 do
   arrangeWorkspacesAsDesired
   focusWindowUnderPointer

In some cases it's possible to combine calls to `windows'. For example:

 windows ( W.focusMaster . W.view "2" )

is a better way to do get the same result as:

 windows (W.view "2")
 windows W.focusMaster

With `focusWindowUnderPointer' that transformation is probably
possible too, but then you can't use queryPointer since the windows
aren't arranged when there's a chance to call queryPointer.

Regards,
Adam



More information about the xmonad mailing list