Clever repositioning of mouse

If you appreciate SloppyFocus or MouseFocus but can’t get used to the mouse pointer jumping to the upper left corner of the window as you switch windows with Alt+Tab or similar, you could try something like this:

AddToFunc reposition_pointer
+ I PipeRead 'echo $[pointer.x] $[pointer.y] $[w.width] $[w.height] $[w.x] \
	$[w.y] | $[fvwm_scrpt]/reposition_pointer'

DestroyFunc WindowListFunc
AddToFunc WindowListFunc
+ I Iconify off
+ I FlipFocus
+ I Raise
+ I reposition_pointer

This requires that you put a little program named “reposition_pointer” in your Fvwm script catalogue. The source looks like this:

#include <stdio.h>

int main ()
	int pointer_x, pointer_y, width, height, left, top, right, bottom;

	scanf("%i %i %i %i %i %i", &pointer_x, &pointer_y, &width, &height, &left, &top);
	right	= left + width;
	bottom	= top + height;

	if (pointer_x > right)
		pointer_x = right - 5;
	else if (pointer_x < left)
		pointer_x = left + 5;
	if (pointer_y > bottom)
		pointer_y = bottom - 5;
	else if (pointer_y < top)
		pointer_y = top + 5;
	printf("WindowId root WarpToWindow %ip %ip\n", pointer_x, pointer_y);
	return 0;

(Compile it with gcc reposition_pointer.c -o reposition_pointer)

So what does it do? Well, while switching between windows Alt-Tab style it never moves the mouse pointer more than necessary; if the pointer is already inside the newly raised window, it doesn’t move at all, and if it’s outside it moves to the nearest border.

So much effort when the Direction command in FVWM already does this.

– Thomas Adam