I just figured out, that conky breaks script
lsw lists conky window id first and desktop window id second, but
xdotool getmouselocation ignores conky and gives desktop window id. This occurs when conky config has
own_window_type = 'desktop'. So I guess it results in two desktop windows at the same time and conky is the lowest of them.
I tried other conky window types and found, that
override doesn't work with bspwm,
panel show conky over other windows,
normal makes conky into normal window, but it is not what I want. Adding
own_window_hints = 'below' did not help either.
So at the moment root menu and gap grab don't work with conky. Maybe there is a way to get desktop window id not with
lsw? Or somehow sort out what desktop window is really desktop and what is conky window.
EDIT. I can "fix" it if I run
xdotool search --class "conky" set_window --overrideredirect 1 %@
But if conky restarts or refreshes config, it is broken again.