I want to display a few lines at the top of a specific buffer, no matter how much the user has scrolled down (basically, a multi-line version of a header line). Moreover, I want these lines to be visible if and only if that buffer is visible (e.g. if I switch to a different buffer, the lines should disappear. When I switch back, they should be visible again).
(The specific use case I have is a weekly calendar view. The user can scroll to see different hours of the day, but I want the days of the week, all-day events, navigation buttons, etc. to always be visible at the top.)
So far the closest I've got is using a posframe (which uses child frames). This can successfully display such a "multi line header", but the problem I ran into is when killing/changing buffers the posframe does not disappear. The posframe appears to be associated with the whole frame, rather than a specific buffer. I have not found a way to have a posframe appear if and only if a specific buffer is visible.
I would appreciate help on either making the posframes work, or an alternative method for a multi-line sticky header. Thanks!