You are not logged in.

#1 2009-10-13 22:08:29

Confuseling
Member
Registered: 2009-07-23
Posts: 13

xmonad: focusfollowsmouse runtime toggle?

Hello Gods of Haskell,

I would love to be able to bind an xmonad key to toggle focus follows mouse at runtime, so when needed I can switch it off, and mouse wheel scroll a window I'm transcribing from more easily.

Any suggestions as to how that would be doable (example code or links to it if at all possible - I'm new to Haskell)?

I suppose if not possible, I could use layout per workspace and use a specific workspace without FFM for such tasks? I'll look into that. Or, if there's another way of scrolling one window while focusing another that I'm overlooking, tips will be gratefully received.

Thanks...

Last edited by Confuseling (2009-10-13 22:09:18)

Offline

#2 2009-10-25 03:44:09

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

Re: xmonad: focusfollowsmouse runtime toggle?

Here's how you can do it with xmonad-0.9.

{-# LANGUAGE ImplicitParams, NoMonomorphismRestriction, PatternGuards #-}

import Data.IORef
import Data.Monoid
import XMonad
import XMonad.Util.EZConfig

main = do
    focusFollow <- newIORef True; let ?focusFollow = focusFollow
    xmonad myConfig

myConfig = defaultConfig
    { focusFollowsMouse = False
    , handleEventHook = \e -> case e of
       CrossingEvent {ev_window=w, ev_event_type=t}
        | t == enterNotify, ev_mode e == notifyNormal -> do
            whenX (io $ readIORef ?focusFollow) (focus w) 
            return $ All True
       _ -> return $ All True
    }
    `additionalKeysP`
    [("M-v", io $ modifyIORef ?focusFollow not)]

EDIT: 0.9 is out.

For references here was my note about porting this back to 0.8.1 (and probably a bit earlier too):

It can be done with 0.8.1, but the event handler (for catching the crossing events) would be written as a layout modifier (see how XMonad.Hooks.EwmhDesktops did it in xmonad 0.8), instead of a handleEventHook.

Last edited by vogt (2009-10-27 01:03:07)

Offline

#3 2009-10-27 11:12:51

Confuseling
Member
Registered: 2009-07-23
Posts: 13

Re: xmonad: focusfollowsmouse runtime toggle?

Thank you!

I was getting a little concerned that the Gods of Haskell didn't use mice at all any more! tongue

I'll give that a whirl as soon as I have a chance. Cheers.

ETA - out of curiosity, did you work this out yourself?

Last edited by Confuseling (2009-10-27 19:04:27)

Offline

#4 2009-10-28 16:26:27

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

Re: xmonad: focusfollowsmouse runtime toggle?

I basically ripped the code that listens to events when you have focusFollowsMouse = True, and used a conditional that depends on some global mutable state, instead of the immutable focusFollowsMouse field.

EDIT: and of course, xmonad lets you run code to intercept arbitrary events using the handleEventHook, so you can accomplish much without modifying the core source code.

Last edited by vogt (2009-10-28 16:28:14)

Offline

Board footer

Powered by FluxBB