Skip to content

Commit

Permalink
Fix windows clickthrough bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Hacksore committed Nov 13, 2023
1 parent cb60997 commit 8c4ce65
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 38 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# overlayed

A discord overlay written with React and built on Tauri.

### Current Features

- Displays talking state
- Displays user deafend / muted
- Displays user deafened / muted
- Transparent window
- Always on top
- Click through mode
Expand Down
58 changes: 21 additions & 37 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,41 @@ const TRAY_RELOAD: &str = "reload";
const TRAY_OPEN_DEVTOOLS: &str = "open_devtools";
const TRAY_QUIT: &str = "quit";

#[cfg(target_os = "macos")]
fn apply_macos_specifics(app: &mut App, window: &Window) {
window.set_transparent_titlebar(true, true);
app.set_activation_policy(ActivationPolicy::Accessory);
}

#[tauri::command]
fn toggle_clickthrough(window: Window, clickthrough: State<'_, Clickthrough>) {
let clickthrough_value = !clickthrough.0.load(std::sync::atomic::Ordering::Relaxed);

set_clickthrough(clickthrough_value, &window, clickthrough);
}

#[tauri::command]
fn get_clickthrough(clickthrough: State<'_, Clickthrough>) -> bool {
clickthrough.0.load(std::sync::atomic::Ordering::Relaxed)
}

fn set_clickthrough(value: bool, window: &Window, clickthrough: State<'_, Clickthrough>) {
clickthrough
.0
.store(clickthrough_value, std::sync::atomic::Ordering::Relaxed);
.store(value, std::sync::atomic::Ordering::Relaxed);

// let the client know
window
.emit(TOGGLE_CLICKTHROUGH, clickthrough_value)
.unwrap();
window.emit(TOGGLE_CLICKTHROUGH, value).unwrap();

#[cfg(target_os = "macos")]
window.with_webview(move |webview| {
#[cfg(target_os = "macos")]
unsafe {
let _: () = msg_send![
webview.ns_window(),
setIgnoresMouseEvents: clickthrough_value
];
let _: () = msg_send![webview.ns_window(), setIgnoresMouseEvents: value];
}
});
}

#[tauri::command]
fn get_clickthrough(clickthrough: State<'_, Clickthrough>) -> bool {
clickthrough.0.load(std::sync::atomic::Ordering::Relaxed)
}

#[cfg(target_os = "macos")]
fn apply_macos_specifics(app: &mut App, window: &Window) {
window.set_transparent_titlebar(true, true);
app.set_activation_policy(ActivationPolicy::Accessory);
window.set_ignore_cursor_events(value);
}

fn main() {
Expand Down Expand Up @@ -119,25 +120,8 @@ fn main() {
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
TRAY_TOGGLE_CLICKTHROUGH => {
let window = app.get_window(MAIN_WINDOW_NAME).unwrap();
let clickthrough = !app
.state::<Clickthrough>()
.0
.load(std::sync::atomic::Ordering::Relaxed);

app
.state::<Clickthrough>()
.0
.store(clickthrough, std::sync::atomic::Ordering::Relaxed);

#[cfg(target_os = "macos")]
window.with_webview(move |webview| {
#[cfg(target_os = "macos")]
unsafe {
let _: () = msg_send![webview.ns_window(), setIgnoresMouseEvents: clickthrough];
}
});
// we might want to knokw on the client
window.emit(TOGGLE_CLICKTHROUGH, clickthrough).unwrap();

toggle_clickthrough(window, app.state::<Clickthrough>())
}
TRAY_SHOW_APP => {
let window = app.get_window(MAIN_WINDOW_NAME).unwrap();
Expand Down

0 comments on commit 8c4ce65

Please sign in to comment.