Autoraising panels and graph windows upon mouseover (focus follows cursor)

Average rating
(0 votes)

This snippet turns on and off autoraising of panel and graph windows on mouseover. It is turned on/off from the menu, Misc > Autoraise. Once turned on, a hook is installed on mousemoved event for all the panels and graphs. When turned off the hook is removed for all panels and graphs. If this event is already occupied by another function for a particular panel or graph, the function will be overwritten with the autoraise function. A possible solution may be to find another suitable event to trigger the autoraising event. A more refined solution would be to save the previous hook in userdata and restore it upon hook remove. An even more refined solution might be to chain the hook functions.

menu "Misc", dynamic
	"--"
	ugsk_autoraise_menu_title(), /Q, ugsk_autoraise_toggle()
	help={"Auto-raise panels and graphs on hover"}
end
 
function/s ugsk_autoraise_menu_title()
 
	nvar/z v_chk = root:autoraise:ui:v_chk
	if (!nvar_exists(v_chk))
		newdatafolder/o root:autoraise
		newdatafolder/o root:autoraise:ui
		variable/g root:autoraise:ui:v_chk = 0
		return "Autoraise: is off"
	elseif (v_chk == 0)
		return "Autoraise: is off"
	else
		return "Autoraise: is on"
	endif
end
 
function ugsk_autoraise_toggle()
	nvar/z v_chk = root:autoraise:ui:v_chk
	if (v_chk == 1)
		v_chk = 0
		ugsk_autoraise_hook_kill()
		return 0
	else
		v_chk = 1
		ugsk_autoraise_hook_install()
	endif
end
 
function ugsk_autoraise_hook_kill()
	string s_win = ""
	string s_winlist = winlist("*",";","WIN:65,VISIBLE:1")
	variable v_win = itemsinlist(s_winlist)
	variable i = 0
	string s_hook = ""
	for ( i=0; i<v_win; i+=1 )
		s_win = stringfromlist(i, s_winlist, ";")
 
		setwindow $s_win hook(mousemoved)=$""
 
	endfor
end
 
function ugsk_autoraise_hook_install()
	string s_win = ""
	string s_winlist = winlist("*",";","WIN:65,VISIBLE:1")
	variable v_win = itemsinlist(s_winlist)
	variable i = 0
	string s_hook = ""
	for ( i=0; i<v_win; i+=1 )
		s_win = stringfromlist(i, s_winlist, ";")
 
		setwindow $s_win hook(mousemoved)=ugsk_autoraise_raise
 
	endfor
end
 
 
function ugsk_autoraise_raise(s)
 
	STRUCT WMWinHookStruct &s
 
	if (s.eventcode == 4)
		dowindow/F $(s.winname)
		return 0
	endif
end

I have some thoughts ... -

I have some thoughts ...

- The recommended practice is to put package globals in a root:Packages:MYPACKAGE folder.
- I'm confused why the sub-sub-folder autoraise:ui is needed????
- Hook functions are to return 1 to indicate they have processed the event or 0 to allow other events to handle the eventcode. This might improve the behavior with regard to your concern about overlaps with other user-set mouse-moved events

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH

Back to top