From c528a9ef498e38062b4f95643c9e15049187af33 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sat, 5 Mar 2022 00:38:02 +0100 Subject: [PATCH] Explicitly handle no and pointer root input focus This will never happen under normal X11. Apparently Crostini isn't normal X11. See #167. --- CHANGELOG.md | 2 ++ src/wine-host/editor.cpp | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b182475d..15d940e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,8 @@ Versioning](https://semver.org/spec/v2.0.0.html). If you try to process audio from the...audio thread, then they will produce silence and hang afterwards (which a fix in yabridge 3.7.0 previously addressed). +- Fixed crashes when opening plugin editors under **Crostini** on ChromeOS due + to non-standard X11 implementations. - Worked around a bug in the _RandARP_ VST2 plugin where the plugin would report that its editor window is 0 by 0 pixels. - Fixed building under (the currently upcoming) Wine 7.2 because of definition diff --git a/src/wine-host/editor.cpp b/src/wine-host/editor.cpp index 9b7de9ef..1e745654 100644 --- a/src/wine-host/editor.cpp +++ b/src/wine-host/editor.cpp @@ -839,10 +839,18 @@ void Editor::set_input_focus(bool grab) const { // we don't just check whether `current_focus` and `focus_target` are the // same window but we'll also allow `current_focus` to be a child of // `focus_target`. + // NOTE: To make matters even more complicated, the focused window can also + // be `None` or `PoointerRoot`. In a normal Xorg setup this will never + // happen, but apparently Crostini does some strange things and it can + // happen there. Since those flags aren't valid windows, we must avoid + // calling `is_child_window_or_same()` in those cases. + // https://github.com/robbert-vdh/yabridge/issues/167 const xcb_window_t current_focus = focus_reply->focus; if (current_focus == focus_target || - (grab && is_child_window_or_same(*x11_connection_, current_focus, - focus_target))) { + (grab && current_focus != XCB_INPUT_FOCUS_NONE && + current_focus != XCB_INPUT_FOCUS_POINTER_ROOT && + is_child_window_or_same(*x11_connection_, current_focus, + focus_target))) { logger_.log_editor_trace([&]() { std::string reason = "unknown reason"; if (current_focus == focus_target) {