You are not logged in.

#1 2012-02-07 07:33:19

ghost
Member
Registered: 2011-11-10
Posts: 44

i3 Mouse follows the focus?

I switched from subtle to i3.

I'm missing the feature that the mouse is always in the focused window.
And when I switch the workspace or window, the mouse jumps in the middle of the window

Is this behaviour possible in i3?

Offline

#2 2012-07-05 11:21:04

kamila
Member
Registered: 2012-07-05
Posts: 7

Re: i3 Mouse follows the focus?

The userguide does not mention this, so I assume there is no simple way (i.e. config option). The following snippet (a two-line "mouse follows focus daemon" tongue) uses xdotool to always move the mouse when a window is focused:

MOVEMOUSE='eval `xdotool getactivewindow getwindowgeometry --shell`; xdotool mousemove $((X+WIDTH/2)) $((Y+HEIGHT/2))'
xdotool search . behave %@ focus exec sh -c "$MOVEMOUSE"

However, it is rather useless as it does this also when focus is moved due to moving the mouse (if you have focus follows mouse on, like I do big_smile). Therefore, currently probably the best option is to have this hard-coded in the config, as in

set $movemouse "sh -c 'eval `xdotool getactivewindow getwindowgeometry --shell`; xdotool mousemove $((X+WIDTH/2)) $((Y+HEIGHT/2))'"
bindsym $m+h focus left; exec $movemouse
bindsym $m+j focus down; exec $movemouse
bindsym $m+k focus up; exec $movemouse
bindsym $m+l focus right; exec $movemouse

instead of just focus left/right/down/up.

Hope this helps!

Offline

#3 2012-07-15 10:49:03

kamila
Member
Registered: 2012-07-05
Posts: 7

Re: i3 Mouse follows the focus?

Just a side note: I have tried to fix the "mouse follows focus daemon" to work properly, and this is the result:

movemouse() {
	#echo "called"
	eval `xdotool getmouselocation --shell`; UNDERMOUSE=$WINDOW
	eval `xdotool getactivewindow getwindowgeometry --shell`
	FOCUSED=$WINDOW
	if [[ $FOCUSED != $UNDERMOUSE ]]; then
		xdotool mousemove $((X+WIDTH/2)) $((Y+HEIGHT/2))
	fi
}
export -f movemouse

xdotool search . behave %@ focus exec sh -c movemouse # do this whenever focus changes

This works, but it is rather slow and I don't like it - every focus change results in like 10 calls to the function. I assume it is because of the fact that when the mouse moves, focus is re-evaluated, which causes the script to be called again etc. This might be fixable, but seeing this I really think hard-coding into the config to move the mouse with focus changing commands is better.

Offline

Board footer

Powered by FluxBB