-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Raise the window more reliably #274
Comments
And there are much bigger issues with that code. I'm at the end of my awake hours, so I'll take a closer look tomorrow with fresh eyes before elaborating. |
Other place with the same pattern: Lines 152 to 158 in 3b281db
This one seems similar on the surface: Lines 248 to 256 in 5ef8a82
But I don't know if there's a way to sleep until the keyboard can be grabbed. |
XSelectInput(disp, target, FocusChangeMask); This subscribes us to focus-change events, not visibility events. For visibility events,
There's so much issues with this code that I'd rather not try and fix it, instead I'd much rather figure out what exact problem that code was trying to solve and then solve that from scratch. |
Related: #67 My wm doesn't seem to respect the raise request. So it'll be difficult for me to test. |
One more bug, if the selected window was already raised, then there won't be any visibility event (as nothing changed) and so scrot will just sleep for that entire duration. |
What we ideally want here is something like the following:
But I'm not sure if this can be done. The only thing close to it in ICCCM/EWMH I can find is this. But it's not exactly what we're looking for, it's about the currently focused window - I'm not sure if there's anything that says that a focused window cannot be obscured. And then there's this:
And in practice, there's plently of WMs that take this route. For example, |
this patch simply removes the fluff and indirection and shows what's actually going on already. since we never subscribed to visibility event, we're never going to receive it anyways and will end up sleeping the entire duration. also reduce the sleep from ~300ms to ~160ms, which should be enough for local X server. (note: it's fine to call nanosleep in loop, it's just a fuzzy sleep, doesn't have to be exact). ref: resurrecting-open-source-projects#274
this patch simply removes the fluff and indirection and shows what's actually going on already. since we never subscribed to visibility event, we're never going to receive it anyways and will end up sleeping the entire duration. also reduce the sleep from ~300ms to ~160ms, which should be enough for local X server. ref: #274
If a WM supports |
This is a different issue altogether. But yes you can wait for a focus event to come (since grabbing/ungrabbing the keyboard generates focus in/out events). It's what I do in In order to do a timeout as well, I think you'd need to either setup a sigalarm handler that Unless there's some pitfall involved, setting up an alarm with a fatal handler seems to be the simplest solution. I'd rather not go |
Instead of polling for the event (with drift from calling
nanosleep()
in a loop...), this code:scrot/src/scrot.c
Lines 373 to 379 in dc65e96
Should use
select()
orpoll()
to wait for the fd used to communicate with the X server to have some data, then useXCheckIfEvent()
to check if the data is what we're watching for.Edit: Is 300ms enough of a delay? 10ms is often the precision OSes offer to the userland when it comes to timers, there's probably significant drift in polling every 10ms, fixing this might expose an issue with the delay being too short, but I find it unlikely for local X servers.
Edit 2: fixed incorrect statement about
poll()
The text was updated successfully, but these errors were encountered: