WIP: Cleanups
The click handling code is a bad copy of the C code. It also carries a lot of things explicitly way too deep down the handlers, becoming hairier with time.
Since this would get even more hairy once clicking popover elements will be able to influence "overlay" layouts (so need to carry layout state as well), it's worth to introduce some order to the chaos here.