(defun sync-shading (W) 
	"Synchronise window->shaded and actual window shading"
	(window-put W 'shaded (not (window-get W 'shaded)))
	(toggle-window-shaded W)
)

(defun non-updating-unshade-window (W)
	"Unshades a window without changing window->shaded"
	(let ((shading (window-get W 'shaded)))
		(unshade-window W)
		(window-put W 'shaded shading)
))

(setq focus-in-hook (cons non-updating-unshade-window focus-in-hook ))
(setq focus-out-hook (cons sync-shading focus-out-hook ))

