Skip to content

Commit

Permalink
Add hitboxes as parent of windows
Browse files Browse the repository at this point in the history
  • Loading branch information
eythaann committed Jun 28, 2024
1 parent 8ed0a21 commit cc06373
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 40 deletions.
4 changes: 0 additions & 4 deletions src/apps/seelenweg-hitbox/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { wrapConsole } from '../shared/ConsoleWrapper';
import { invoke } from '@tauri-apps/api/core';
import { PhysicalPosition, PhysicalSize } from '@tauri-apps/api/dpi';
import { emitTo } from '@tauri-apps/api/event';
import { getCurrent } from '@tauri-apps/api/webviewWindow';
Expand All @@ -16,12 +15,9 @@ async function Main() {

document.body.addEventListener('mousemove', () => {
emitTo(main, 'mouseenter');
invoke('ensure_hitboxes_zorder');
});

async function onClick(e: MouseEvent | TouchEvent) {
invoke('ensure_hitboxes_zorder');

let x = 0;
let y = 0;
if (e instanceof MouseEvent) {
Expand Down
4 changes: 0 additions & 4 deletions src/apps/toolbar-hitbox/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { wrapConsole } from '../shared/ConsoleWrapper';
import { invoke } from '@tauri-apps/api/core';
import { emitTo } from '@tauri-apps/api/event';
import { getCurrent } from '@tauri-apps/api/webviewWindow';

Expand All @@ -14,8 +13,6 @@ async function Main() {
await getCurrent().show();

async function onClick(e: MouseEvent | TouchEvent) {
invoke('ensure_hitboxes_zorder');

let x = 0;
let y = 0;
if (e instanceof MouseEvent) {
Expand All @@ -34,7 +31,6 @@ async function Main() {

document.body.addEventListener('mousemove', () => {
emitTo(main, 'mouseenter');
invoke('ensure_hitboxes_zorder');
});
document.body.addEventListener('click', onClick);
document.body.addEventListener('touchend', onClick);
Expand Down
17 changes: 0 additions & 17 deletions src/background/exposed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,6 @@ fn is_dev_mode() -> bool {
tauri::is_dev()
}

#[command]
fn ensure_hitboxes_zorder() {
std::thread::spawn(|| -> Result<()> {
let seelen = trace_lock!(SEELEN);
for monitor in seelen.monitors() {
if let Some(toolbar) = monitor.toolbar() {
toolbar.ensure_hitbox_zorder()?;
}
if let Some(weg) = monitor.weg() {
weg.ensure_hitbox_zorder()?;
}
}
Ok(())
});
}

#[command]
fn get_accent_color() -> String {
let mut colorization: u32 = 0;
Expand Down Expand Up @@ -222,7 +206,6 @@ pub fn register_invoke_handler(app_builder: Builder<Wry>) -> Builder<Wry> {
get_user_envs,
show_app_settings,
reload_apps_configurations,
ensure_hitboxes_zorder,
switch_workspace,
// Auto Start
set_auto_start,
Expand Down
9 changes: 2 additions & 7 deletions src/background/seelen_bar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ use tauri::{AppHandle, Manager, WebviewWindow, Wry};
use windows::Win32::{
Foundation::HWND,
Graphics::Gdi::HMONITOR,
UI::WindowsAndMessaging::{
HWND_TOPMOST, SWP_ASYNCWINDOWPOS, SWP_NOSIZE, SW_HIDE, SW_SHOWNOACTIVATE,
},
UI::WindowsAndMessaging::{SWP_ASYNCWINDOWPOS, SWP_NOSIZE, SW_HIDE, SW_SHOWNOACTIVATE},
};

pub struct FancyToolbar {
Expand Down Expand Up @@ -79,10 +77,6 @@ impl FancyToolbar {
)?;
Ok(())
}

pub fn ensure_hitbox_zorder(&self) -> Result<()> {
WindowsApi::bring_to(HWND(self.window.hwnd()?.0), HWND_TOPMOST)
}
}

// statics
Expand Down Expand Up @@ -166,6 +160,7 @@ impl FancyToolbar {
.shadow(false)
.skip_taskbar(true)
.always_on_top(true)
.owner(&hitbox)?
.build()?,
};

Expand Down
13 changes: 5 additions & 8 deletions src/background/seelen_weg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use windows::Win32::{
Foundation::{BOOL, HWND, LPARAM, RECT},
Graphics::Gdi::HMONITOR,
UI::WindowsAndMessaging::{
EnumWindows, GetParent, HWND_TOPMOST, SHOW_WINDOW_CMD, SWP_NOACTIVATE, SW_HIDE,
SW_SHOWNOACTIVATE, SW_SHOWNORMAL, WS_EX_APPWINDOW, WS_EX_NOACTIVATE, WS_EX_TOOLWINDOW,
EnumWindows, GetParent, SHOW_WINDOW_CMD, SWP_NOACTIVATE, SW_HIDE, SW_SHOWNOACTIVATE,
SW_SHOWNORMAL, WS_EX_APPWINDOW, WS_EX_NOACTIVATE, WS_EX_TOOLWINDOW,
},
};

Expand Down Expand Up @@ -230,10 +230,6 @@ impl SeelenWeg {
Ok(())
}

pub fn ensure_hitbox_zorder(&self) -> Result<()> {
WindowsApi::bring_to(HWND(self.window.hwnd()?.0), HWND_TOPMOST)
}

pub fn is_real_window(hwnd: HWND, ignore_frame: bool) -> bool {
if !WindowsApi::is_window_visible(hwnd) {
return false;
Expand Down Expand Up @@ -295,7 +291,7 @@ impl SeelenWeg {
let monitor_info = WindowsApi::monitor_info(HMONITOR(monitor_id))?;
let rc_work = monitor_info.monitorInfo.rcWork;

let hitbox = tauri::WebviewWindowBuilder::<Wry, AppHandle<Wry>>::new(
let hitbox = tauri::WebviewWindowBuilder::new(
manager,
format!("{}/{}", Self::TARGET_HITBOX, monitor_id),
tauri::WebviewUrl::App("seelenweg-hitbox/index.html".into()),
Expand All @@ -312,7 +308,7 @@ impl SeelenWeg {
.always_on_top(true)
.build()?;

let window = tauri::WebviewWindowBuilder::<Wry, AppHandle<Wry>>::new(
let window = tauri::WebviewWindowBuilder::new(
manager,
format!("{}/{}", Self::TARGET, monitor_id),
tauri::WebviewUrl::App("seelenweg/index.html".into()),
Expand All @@ -327,6 +323,7 @@ impl SeelenWeg {
.shadow(false)
.skip_taskbar(true)
.always_on_top(true)
.owner(&hitbox)?
.build()?;

window.set_ignore_cursor_events(true)?;
Expand Down

0 comments on commit cc06373

Please sign in to comment.