-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[bug] Dragging window causes focus toggling, plus eats mouse event(s) #10767
Comments
After thinking to record the window messages under the laggy conditions that cause the focus bug to disappear, I produced the following merged chart that shows the diff between a buggy execution and a bug-free execution. Messages arrive in the following order, with the messages on the left, under the "bug only" column, being present only when logging messages under bug-manifesting conditions. Messages on the right are present only under bug-free conditions, and in the middle we have messages which appear to be constant between the buggy and bug-free cases. (Some messages appear to be duplicated, but only because of how Window Detective lists them: when applicable, there's one entry for when the message is posted, and a second for when the message is returned. You can see this annotated in the screenshots above, but not when I transcribe the messages in text only.)
Note the second chunk, where the first bug-only section appears. The messages in that chunk match up with those I highlighted in orange in my first comment. |
遇到了一样的问题 |
当窗口聚焦时, 点击 data-tauri-drag-region attr dom元素会触发 blur 事件 |
Thanks for the detailed issue, the problem is that when clicking inside A fix for that might be sending a mouse up event to the webview, but the webview is created by another process and we may not even be able to send the click to it. Also the webview team decided they won't provide an API to access the webview HWND because it is created from another process. We maybe able to fix this another way by using WebView2 in composition mode instead of hosted mode, but we can't do that until we drop Windows 7 support. Alternatively, you could try WebView2 |
@amrbashir Thanks for linking to the relevant piece of code, and suggesting a possible workaround. Do you have any idea why the window loses and regains focus when clicking? In my reproduction I logged window focus changes from within the webview, but it's not just the webview that experiences the loss of focus: if you print logs in response to |
I am not sure I quite follow what you mean. Could you explain a bit more or provide a repro |
@amrbashir Two things are going on here, on a click that triggers the bug:
You gave a hypothesis for why the former is happening, but not the latter, so I was asking about it. It's all described in detail in the original post, though if you mistake it to be about just the one issue, the other, related one may recede into the background. Here's what I'm referring to, though:
The mouse up event is missing, but also, there's an additional "focus lost / focus gained" in there. If initially unfocused, the only change in focus state that should occur is a singular gain in focus. The last two bullet points shouldn't be present at all. Similarly, when already focused, there should be no change in the focus state at all. Nevertheless:
We still observe a loss and regain of focus. On top of that, this bug occurs even when dragging by the native title bar, which is entirely outside the webview.
Might be worth re-reading the original post with that additional context in mind, since I think it may have been missed the first time. The original post also contains a full reproduction of the given behaviour. It all still reproduces on the latest release version of Tauri. |
These are still related to the same issue. I have added an explanation below
|
This one is a bit interesting and weird but I think it is because Whenever the window hosting the webview gains focus, we automatically focus the webview. See https://github.com/tauri-apps/wry/blob/c1b26b9612bf5c5a9e4e0185f73739a2444343cd/src/webview2/mod.rs#L1077-L1080 |
Describe the bug
On Windows, clicking any draggable region within a Tauri window causes a toggling of window focus and the loss of certain mouse events as observed by the webview. This occurs both with parts of the window which are within the native frame (e.g. titlebar, resize borders), and designated drag regions within the webview. When clicking in a webview drag region, the loss of the mouse up event very rarely seems to cause the window to get stuck in a dragging state, such that it will follow the mouse until the user clicks again.
While draggable regions are associated with this behaviour, actually dragging them is unnecessary. Only clicking is required, though in certain cases you may need to hold the click for a moment before releasing.
A prior issue describes what I believe to be the same problem. I've opened a new issue to provide additional information and up-to-date reproductions steps, since this actually bit me when developing my current project.
When clicking on a drag region within the webview, the following events are observed by the webview in this order:
When clicking without prior focus:
When clicking with prior focus:
Notice the absence of a mouse up event: this will seemingly never be observed by event listeners in the webview. (If you double-click instead of single clicking, then the second mouse up event will be visible: but this is only because it triggers the window maximize handler instead of the drag start handler.)
When clicking in the native window frame area, outside the webview, the observed events are similar, with the addition of a delay:
When clicking without prior focus:
When clicking with prior focus:
(No mouse events are seen by the webview in this case, but this is expected, since they occur in the frame area beyond the webview's bounds.)
About the delay:
I'm not certain the delay will replicate on every system, but the gap is suspiciously close to 500ms.
Here's a recording of a trace of the window messages, captured using Window Detective. Starting without focus on the window, I mouse over the native titlebar, pause, click down, hold for a moment, and then release. While the mouse button is held down, the mouse is not moved at all.
Here also is a static screenshot of those window messages after the fact, with coloured bars drawn along the left-hand side so that you can easily associate them with the cause:
I poked through the Tauri internals a bit to see if I could figure out exactly where this was happening, but I'm still getting familiar with the project and with Rust, so I'm not very effective yet. I hope the above information can help someone else with a better grasp of the project pinpoint where it's happening.
Do let me know if there's anything further information I could provide that would be useful.
Reproduction
Create a minimal Tauri program using
create-tauri-app
:Add
core:window:allow-start-dragging
to the program permissions.Insert the following code at the end of
main.js
:Run the program in dev mode:
Open the dev tools and watch the messages logged in the console as the window is clicked.
Expected behavior
The window should not lose focus when it is clicked while already focused. Mouse up events within the webview should not be silently ignored, even when clicking on a drag region.
Full
tauri info
outputStack trace
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: