-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
[feat] [macOS] Configure acceptsFirstMouse
for specific elements
#4316
Comments
I have this problem too,And Gaussian blur doesn't work when you lose focus |
I ran into this too. I thought it might have something to do with the acceptsFirstMouse method. It looks like at least tao is overriding that to be
It looks like wry already has a WryWebView that subclasses WKWebView and that might be a good place to put this override. It would be overzealous though, and then filtering of mouse clicks would need to happen somewhere or we'd end up in the reverse situation where the window shouldn't respond to the first mouse click in a lot of situations. I guess ideally it would be up to the application whether it accepts those clicks, but I'm not sure where that would go. |
Enabling If we're able to detect the first mouse click position, we would be able to forward it to the frontend to decide if the window should be dragged |
If it were special-cased for only
I think a system like that would still let the developer do their custom |
I think the solution there is to have |
data-tauri-drag-region
requires focus on macOSacceptsFirstMouse
/upstream tauri-apps/tao |
Upstream issue at tauri-apps/tao#575 has been closed. |
/upstream tauri-apps/wry |
Upstream issue at tauri-apps/wry#714 has been closed. |
acceptsFirstMouse
data-tauri-drag-region
when unfocused
data-tauri-drag-region
when unfocusedacceptsFirstMouse
for specific elements
Opened #5347 for exposing |
/upstream tauri-apps/wry |
Setting acceptFirstMouse to true will not allow drag on Macs decorations: false,
transparent: true, |
I'm not entirely sure if this solution will work for everyone, but it successfully resolved the issue in my case. The problem I was encountering involved dragging a window in a Tauri app on macOS, particularly when using the But, through some trial and error (mostly error), I came up with this temporary hack...I mean, solution! [dependencies]
tauri = { version = "1.7.2", features = ["macos-private-api", "api-all"] } The
{
"tauri": {
"allowlist": {
"all": true,
"window": {
"startDragging": true
}
},
"macOSPrivateApi": true,
"windows": [
{
"fullscreen": false,
"resizable": false,
"height": 600,
"width": 410,
"title": "",
"titleBarStyle": "Overlay"
}
]
}
}
"use client";
import { useEffect } from "react";
const TitleBarHandler = () => {
useEffect(() => {
const handleMouseMove = (event) => {
if (event.clientY >= 0 && event.clientY <= 50) {
document.documentElement.setAttribute("data-tauri-drag-region", "true");
} else {
document.documentElement.removeAttribute("data-tauri-drag-region");
}
};
window.addEventListener("mousemove", handleMouseMove);
return () => {
window.removeEventListener("mousemove", handleMouseMove);
document.documentElement.removeAttribute("data-tauri-drag-region"); // Clean up when unmounting
};
}, []);
return null; // No need to render anything for the title bar
};
export default TitleBarHandler;
import TitleBarHandler from "../components/titleBarHandler";
export default function RootLayout({ children }) {
return (
<html lang='en'>
<body>
<TitleBarHandler /> {/* Import handler */}
{children}
</body>
</html>
);
} .titlebar {
height: 50px;
user-select: none;
display: flex;
justify-content: flex-end;
position: fixed;
top: 0;
left: 0;
right: 0;
}
.titlebar-button {
display: inline-flex;
justify-content: center;
align-items: center;
width: 30px;
height: 30px;
} |
How to work with Tauri 2.0? |
This configuration isn't compatible with Tauri v2.0 however the issue is persistent. Any ideas? |
Yeah, the config won’t work with Tauri v2.0 because of some changes, but I figured out a way around it. Here’s what I did: I used the recommended Tauri framework setup along with vanilla JavaScript [dependencies]
cocoa = "0.25"
tauri = { version = "2.0.0", features = ["macos-private-api"] }
"app": {
"macOSPrivateApi": true,
"windows": [],
...
} Here’s the code I used to set up the custom drag area and macOS title bar [./src/styles.css]: .dragble-state {
width: 100%;
height: 1.75rem;
position: fixed;
user-select: none;
display: flex;
justify-content: flex-end;
top: 0;
left: 0;
} [./src/main.ts]: document.addEventListener("DOMContentLoaded", () => {
const dragRegionDiv = document.createElement("div");
dragRegionDiv.setAttribute("data-tauri-drag-region", "");
dragRegionDiv.className = "dragble-state";
document.documentElement.insertBefore(dragRegionDiv, document.body);
}); [./src-tauri/capabilities/default.json]: {
...
"permissions": ["core:window:default", "core:window:allow-start-dragging"]
} [./src-tauri/src/lib.rs] pub fn run() {
tauri::Builder::default()
.setup(|app| {
let win_builder = WebviewWindowBuilder::new(app, "main", WebviewUrl::default())
.hidden_title(true)
.inner_size(800.0, 600.0);
#[cfg(target_os = "macos")]
let win_builder = win_builder.title_bar_style(TitleBarStyle::Overlay);
let _window = win_builder.build().unwrap();
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
} This setup works fine for me. |
Describe the bug
Elements with
data-tauri-drag-region
can't be dragged while the window isn't in focus, which is not how native windows (or Electron's implementation) worksNote:
acceptsFirstMouse
doesn't entirely solve this because that would also make everything in the window clickableReproduction
No response
Expected behavior
No response
Platform and versions
Stack trace
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: