Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

window_destroyed signal fires before window is removed #154

Closed
dominiklohmann opened this issue Jul 24, 2019 · 11 comments
Closed

window_destroyed signal fires before window is removed #154

dominiklohmann opened this issue Jul 24, 2019 · 11 comments
Labels
bug Something isn't working

Comments

@dominiklohmann
Copy link
Collaborator

dominiklohmann commented Jul 24, 2019

Bug report

The event=window_destroyed signal is unreliable, as querying windows from it may or may not include the destroyed window.

This bug has been haunting me for weeks now, making me question my sanity and why signals were unreliable sometimes. I think I've found the root cause:

The signal is transmitted asynchronously before the event is processed internally by yabai. The actual handling of the event happens in the event_destroy function, which is called after event_signal_transmit.

yabai/src/event_loop.c

Lines 60 to 66 in b3eb9d1

int result = event_handler[event->type](event->context, event->param1, event->param2);
if (result == EVENT_SUCCESS) event_signal_transmit(event->context, event->type);
if (event->status) *event->status = EVENT_PROCESSED;
if (event->result) *event->result = result;
event_destroy(event);

@koekeishiya
Copy link
Owner

I don't see a clean solution to this problem as long as the window_destroyed signal transmits both the window id and the window pid.

@dominiklohmann
Copy link
Collaborator Author

Let's rephrase the question then: Iff window_destroyed, application_terminated and display_removed signals were not carrying any arguments, could this issue be resolved?

This might break some scripts that rely on argc=$# or pid=$1, but other than that the data was mostly unusable in practice anyways for these signals.

@koekeishiya
Copy link
Owner

application_terminated and display_removed doesn't have this problem. I can solve this issue and have window_destroyed pass the window id, just not the application pid.

@dominiklohmann
Copy link
Collaborator Author

dominiklohmann commented Jul 28, 2019

I've been wondering whether including the pid is necessary anyways. I've only needed to use it once, but I can get it from the wid anyways with a simple query.

pid="$(yabai -m query --windows --window "${wid}") | jq -r '.pid'" 

@koekeishiya
Copy link
Owner

koekeishiya commented Jul 28, 2019

Note that that query will not work in your handler for the window_destroyed signal script.

@dominiklohmann
Copy link
Collaborator Author

Yeah, that was for all queries. The pid seems useless outside of the application_* events.

@koekeishiya
Copy link
Owner

Should we just remove the pid from all window_* signals to be consistent?

@dominiklohmann
Copy link
Collaborator Author

That's a breaking change as it shifts $2 to $1. I'm all for it though. Better break now than later.

@koekeishiya koekeishiya added addressed on master; not released Fixed upstream, but not yet released bug Something isn't working labels Jul 28, 2019
@koekeishiya
Copy link
Owner

Fixed on master.

@dominiklohmann
Copy link
Collaborator Author

Two small things:

  • window_created still passed the pid, you only changed the docs for it.
  • The ordering issue isn't fixed for window_destroyed, right? Just asking because I don't see it reflected in the code and the issue is labeled addressed not released already.

@koekeishiya
Copy link
Owner

koekeishiya commented Jul 28, 2019

window_created still passed the pid, you only changed the docs for it.

Thanks for catching that, I was under the impression all window events had their args populated in the same codepath.

The ordering issue isn't fixed for window_destroyed, right?

It's fixed, yes. Windows are now destroyed when the event is handled, before the signal is emitted.

@koekeishiya koekeishiya removed the addressed on master; not released Fixed upstream, but not yet released label Sep 3, 2019
JDKardia pushed a commit to JDKardia/yabai that referenced this issue Apr 7, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants