-
-
Notifications
You must be signed in to change notification settings - Fork 13
Logic based on window count #26
Comments
No. Windows are processed as they appear, with no relationship information determined. That said I suspect you can work around this for firefox. IF you run this when you have several firefox windows open, and a popup:
You'll probably see what I see, which is a main-window:
vs the window you get from
Notice that |
Test to see if |
In this case the |
Ahh you do mean a literal popup. Maybe that should have been obvious, but it wasn't. Sadly I think you're out of luck here. We literally get called when a new window appears, and we get given that window - and nothing else. I can imagine iterating anew each time, to look to see if it were related to the same process (PID) as an existing idea, but even then it wouldn't necessarily help unless the ordering was stable, and I suspect it wouldn't be. If you know the popup is created at a "small" size then you could catch it that way, but that would be fragile and annoying too :/ |
Could anything be done by checking for a parent window? https://stackoverflow.com/questions/25951656/get-parent-window-of-newly-created-window This would of course be a new feature for kpie and I don't know enough about X to know if every window would have the "root" window as a parent. |
Although thinking about it, in Firefox's case the pop-up window might not be a child of the window that opened it. |
Yeah I've been experimenting with this and there seems to be little bearing between the window ID and the parent IDs I'm finding. Here's the popup:
Here's the parent:
The IDs don't match .. Though they are stable between runs; I wonder if I'm missing something? I added an
then
} I'll sleep on things, but I'm not horribly optimistic .. |
Running |
I think the conclusion here was that there wasn't a simple/obvious way of giving you what you want. I did think of keeping state - since the way the program works is that we get a function invoked every time a window is created. I could record :
Then allow that to be tested, but it doesn't really help you because we still can't tell what kind of window it is. Maybe it's a popup-dialog, maybe it's a new window. Regardless the problem is that there's no notification of when a window is closed, so we'd end up with bogus counts anyway. (I guess I could retest each known window .. but that gets horrible quickly.) I think the best I can do is close this, or tag it "can't fix". Sorry! |
For my case recording the window count would work as I tend to only want to resize the first window but I don't know how useful the feature might be to anyone else to warrant adding it. I don't know if it's possible, but can the concept of global variables/state be made available in lua scripts? That way I could add a window counter in lua without the need to have it added to kpie directly. |
That's an interesting question! Although the script is run again each time a window is created you can preserve state, as I just tested:
The problem here is that the state will increment each time you open a new window, but never decrease. Again the problem is that the callback is invoked when a window is created, but nothing happens for windows being closed. Not sure how to handle that without reworking the API singificantly. |
The global state is a good starting point. Would the API require significant rework, or does it just need an extra signal to be connected? g_signal_connect(screen, "window-closed", G_CALLBACK(on_window_closed), NULL); In theory the callback could also I can't see a I'm speculating a lot, just going by the existing code so the above might not be sensible or workable. |
Right now the script is free-form, and executed from the top every time, when a window is created. So I was kinda thinking if it we invoked a lua-callback on two different events (window open and window close) it would be best if it were changed:
In short all users would need to add the Of course I could just parse the code and invoke Does that clarify my thinking? |
Makes sense, I was thinking more along the lines of if (window_closed) then
-- do something
end but didn't take into account the backwards incompatibilities. |
Let me update the code to monitor window close-events. If I can make that work, I could add a If that all works out I suspect I'll break compatibility in the future - but I think if you could get the window-closed to decrement the count in the global state that'll allow you to differentiate between "first" and "subsequent" windows. Will test this evening anyway. |
This whole thing is horrid! I've added logic to trigger a callback on window-close, but when it is fired the window passed to it is null. i.e. I can call lua when the window close event happens, but all the calls fail. For example:
The output is:
:( Diff attached of code: Sample program that demonstrates how this fails: |
The obvious solution is to have a cache:
Then:
That would allow a destroyed window, which has an ID, to return values. The downside is that it would be a huge change, and it would lead to stale data - for the cases of browsers the title changes on tab-change, etc, not to mention X,Y coords change for other windows. I think we're back to "can't fix" and another hour or two of our lives wasted. Computers are hard! |
Bizarre that the |
What I did to solve a problem similar to this one is add to functions to the
My changes, which if you want I can do a pull request for:
This is just an idea. I am sure |
Is there any way to perform logic based on window count? I currently use kpie to position and size Firefox which works fine, except it also positions and sizes any pop-up windows. What I would like is to only position and size the first "main" window and ignore anything else. The window types and classes are the same for both the main and pop-up windows so I can't use that to distinguish which window is which.
The text was updated successfully, but these errors were encountered: