Open hakoptak opened 1 year ago
@hakoptak I have encountered a similar problem
https://github.com/ahkohd/tauri-macos-menubar-app-example/issues/54
My current version of Tauri = 1.6.2
and I don't see a similar problem with a regular window (NSWindow).
Has the current problem persisted for you in the latest stable version of Tauri?
I would like to point out that this problem only occurs when clicking on the data-tauri-drag-region
area
@hakoptak If you are still facing this problem, try this solution and post whether it solved your problem or not? https://github.com/ahkohd/tauri-macos-menubar-app-example/issues/54#issuecomment-2121013207
The gist of the problem:
When you first click on a data-tauri-drag-region
in an inactive window with .always_on_top
and .acceptFirstMouse
, sometimes there is a conflict between acceptFirstMouse
and start_dragging
events and the window shifts.
Demo: https://youtu.be/McfLrebxq7I?t=20
This is my final solution that solves the problem perfectly:
<script setup lang="ts">
import { appWindow } from "@tauri-apps/api/window";
const fixDragging = (event: MouseEvent) => {
if (
event.currentTarget === event.target &&
// and was left mouse button
event.button === 0 &&
// and was normal click or double click
(event.detail === 1 || event.detail === 2)
) {
event.preventDefault();
setTimeout(() => appWindow.startDragging(), 100);
}
};
</script>
<template>
<div class="title-bar" @mousedown="fixDragging"></div>
</template>
Note that the minimum delay should be exactly
100ms
, because if you set for example 50ms, it will not work.
@FabianLars I don't want to create a new issue, ping you to notice how quick and easy it is to close this problem. https://github.com/tauri-apps/tauri/blob/0c61784efbec4ae5e9d1c89460dcb3380e46b65e/core/tauri/src/window/scripts/drag.js#L42
setTimeout(() => window.__TAURI_INTERNALS__.invoke('plugin:window|' + cmd), 100);
I think it also makes sense to add a delay to maximize the window, as perhaps double-clicking could also cause a problem. https://github.com/tauri-apps/tauri/blob/0c61784efbec4ae5e9d1c89460dcb3380e46b65e/core/tauri/src/window/scripts/drag.js#L60
setTimeout(() => window.__TAURI_INTERNALS__.invoke('plugin:window|internal_toggle_maximize'), 100);
Hi @doroved, thanks for addressing the issue.
I have disabled the AcceptFirstMouse feature and never looked back. If I have time I will try to enable it to see if this is fixed. If so I will close this issue.
Hi @doroved, thanks for addressing the issue.
I have disabled the AcceptFirstMouse feature and never looked back. If I have time I will try to enable it to see if this is fixed. If so I will close this issue.
I doubt it's fixed, since you had this problem on version 2+beta and I had it on 1.6.7 Do not hurry to close the problem, enable AcceptFirstMouse and if the problem does not appear immediately, then use the program for a few days, because the bug at least with me randomly pops out. + for the sake of interest try my solution, at the moment I have never caught the bug.
Describe the bug
Hello,
My app has two windows, one is alwaysOnTop and has acceptFirstMouse, the other is a normal window. The problem (see recording below) occurs when the normal window is clicked and then the on top window. When the op top window is clicked its window suddenly shifts position:
https://user-images.githubusercontent.com/26923796/227799984-5b74572e-8066-4ed0-8b27-043ec4a796f4.mov
In the recording I try to explain that the offset of the shifted window is exactly the mouse position + top left window offset.
This bug may be related to https://github.com/tauri-apps/tauri/issues/4056.
Reproduction
See recording. Below you find the window properties:
Expected behavior
The always on top window should not shift in position.
Platform and versions
Stack trace
Additional context
No response