From 670c49ea5ea3601b46d8562fb409fda2c711d422 Mon Sep 17 00:00:00 2001 From: eythaann Date: Wed, 28 Aug 2024 10:52:44 -0500 Subject: [PATCH] enh(tb): remove hitbox implementation by synthetic mouse event --- src/apps/toolbar-hitbox/index.css | 19 -- src/apps/toolbar-hitbox/index.html | 8 - src/apps/toolbar-hitbox/index.tsx | 48 ---- src/apps/toolbar/app.tsx | 106 +++---- src/apps/toolbar/events.ts | 105 +++---- src/apps/toolbar/index.tsx | 78 ++--- .../toolbar/modules/shared/hooks/infra.ts | 72 ++--- src/apps/toolbar/styles/global.css | 13 +- src/apps/toolbar/styles/reset.css | 268 +++++++++--------- src/background/hook.rs | 21 +- src/background/seelen_bar/cli.rs | 7 - src/background/seelen_bar/hook.rs | 6 - src/background/seelen_bar/mod.rs | 68 +---- src/background/utils/ahk/mocks/seelen.lib.ahk | 1 - 14 files changed, 357 insertions(+), 463 deletions(-) delete mode 100644 src/apps/toolbar-hitbox/index.css delete mode 100644 src/apps/toolbar-hitbox/index.html delete mode 100644 src/apps/toolbar-hitbox/index.tsx diff --git a/src/apps/toolbar-hitbox/index.css b/src/apps/toolbar-hitbox/index.css deleted file mode 100644 index e280d721..00000000 --- a/src/apps/toolbar-hitbox/index.css +++ /dev/null @@ -1,19 +0,0 @@ -*, -*:after, -*:before { - margin: 0; - padding: 0; - border: 0; - outline: none; - box-sizing: border-box; - vertical-align: baseline; -} - -body { - border-top: 1px solid #000; - - &.debug-hitbox { - border-top: 1px solid lime; - background: red; - } -} diff --git a/src/apps/toolbar-hitbox/index.html b/src/apps/toolbar-hitbox/index.html deleted file mode 100644 index aa458273..00000000 --- a/src/apps/toolbar-hitbox/index.html +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/src/apps/toolbar-hitbox/index.tsx b/src/apps/toolbar-hitbox/index.tsx deleted file mode 100644 index b9334f3f..00000000 --- a/src/apps/toolbar-hitbox/index.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import { wrapConsole } from '../shared/ConsoleWrapper'; -import { invoke } from '@tauri-apps/api/core'; -import { emitTo } from '@tauri-apps/api/event'; -import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow'; - -import './index.css'; - -async function Main() { - wrapConsole(); - let view = getCurrentWebviewWindow(); - let main = view.label.replace('-hitbox', ''); - - view.listen('init', async () => { - await getCurrentWebviewWindow().show(); - - async function onClick(e: MouseEvent | TouchEvent) { - invoke('ensure_hitboxes_zorder').catch(console.error); - - let x = 0; - let y = 0; - if (e instanceof MouseEvent) { - x = e.clientX; - y = e.clientY; - emitTo(main, 'click', { x, y }); - return; - } - - if (e.touches && e.touches.length > 0) { - x = e.touches[0]?.clientX || 0; - y = e.touches[0]?.clientY || 0; - emitTo(main, 'click', { x, y }); - } - } - - document.body.addEventListener('mouseenter', () => { - emitTo(main, 'mouseenter'); - invoke('ensure_hitboxes_zorder').catch(console.error); - }); - document.body.addEventListener('click', onClick); - document.body.addEventListener('touchend', onClick); - }); - - view.listen('debug-hitbox', () => { - document.body.classList.toggle('debug-hitbox'); - }); -} - -Main(); diff --git a/src/apps/toolbar/app.tsx b/src/apps/toolbar/app.tsx index ab4185df..a6ed934c 100644 --- a/src/apps/toolbar/app.tsx +++ b/src/apps/toolbar/app.tsx @@ -1,53 +1,53 @@ -import { ErrorBoundary } from '../seelenweg/components/Error'; -import { getRootContainer } from '../shared'; -import { useDarkMode } from '../shared/styles'; -import { ErrorFallback } from './components/Error'; -import { emit, emitTo } from '@tauri-apps/api/event'; -import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow'; -import { ConfigProvider, theme } from 'antd'; -import { useEffect } from 'react'; -import { useSelector } from 'react-redux'; - -import { ToolBar } from './modules/main/infra'; - -import { Selectors } from './modules/shared/store/app'; - -async function onMount() { - let view = getCurrentWebviewWindow(); - await emitTo(view.label.replace('/', '-hitbox/'), 'init'); - await view.show(); - await emit('register-colors-events'); -} - -export function App() { - const version = useSelector(Selectors.version); - - const structure = useSelector(Selectors.placeholder); - const colors = useSelector(Selectors.colors); - - const isDarkMode = useDarkMode(); - - useEffect(() => { - onMount().catch(console.error); - }, []); - - if (!structure) { - return ; - } - - return ( - getRootContainer()} - theme={{ - token: { - colorPrimary: isDarkMode ? colors.accent_light : colors.accent_dark, - }, - algorithm: isDarkMode ? theme.darkAlgorithm : theme.defaultAlgorithm, - }} - > - }> - - - - ); -} +import { ErrorBoundary } from '../seelenweg/components/Error'; +import { getRootContainer } from '../shared'; +import { useDarkMode } from '../shared/styles'; +import { ErrorFallback } from './components/Error'; +import { emit, emitTo } from '@tauri-apps/api/event'; +import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow'; +import { ConfigProvider, theme } from 'antd'; +import { useEffect } from 'react'; +import { useSelector } from 'react-redux'; + +import { ToolBar } from './modules/main/infra'; + +import { Selectors } from './modules/shared/store/app'; + +async function onMount() { + let view = getCurrentWebviewWindow(); + await emitTo(view.label.replace('/', '-hitbox/'), 'init'); + await emit('register-colors-events'); + await view.show(); +} + +export function App() { + const version = useSelector(Selectors.version); + + const structure = useSelector(Selectors.placeholder); + const colors = useSelector(Selectors.colors); + + const isDarkMode = useDarkMode(); + + useEffect(() => { + onMount().catch(console.error); + }, []); + + if (!structure) { + return ; + } + + return ( + getRootContainer()} + theme={{ + token: { + colorPrimary: isDarkMode ? colors.accent_light : colors.accent_dark, + }, + algorithm: isDarkMode ? theme.darkAlgorithm : theme.defaultAlgorithm, + }} + > + }> + + + + ); +} diff --git a/src/apps/toolbar/events.ts b/src/apps/toolbar/events.ts index 573408a0..359fd399 100644 --- a/src/apps/toolbar/events.ts +++ b/src/apps/toolbar/events.ts @@ -1,48 +1,57 @@ -import { debounce, TimeoutIdRef } from '../shared/Timing'; -import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow'; - -import { CallbacksManager } from './modules/shared/utils/app'; - -export const ExtraCallbacksOnLeave = new CallbacksManager(); -export const ExtraCallbacksOnActivate = new CallbacksManager(); - -export function registerDocumentEvents(container: HTMLElement) { - const timeoutId: TimeoutIdRef = { current: null }; - const webview = getCurrentWebviewWindow(); - - const onMouseLeave = debounce( - () => { - webview.setIgnoreCursorEvents(true); - ExtraCallbacksOnLeave.execute(); - }, - 200, - timeoutId, - ); - - const onMouseEnter = () => { - if (timeoutId.current) { - clearTimeout(timeoutId.current); - } - webview.setIgnoreCursorEvents(false); - ExtraCallbacksOnActivate.execute(); - }; - - container.addEventListener('mouseleave', onMouseLeave); - // if for some reazon mouseleave is not emitted - // set ignore cursor events when user click on screen - document.body.addEventListener('click', (event) => { - if (event.target === document.body) { - onMouseLeave(); - } - }); - - container.addEventListener('mouseenter', onMouseEnter); - webview.listen('mouseenter', onMouseEnter); // listener for hitbox - - webview.listen<{ x: number; y: number }>('click', (event) => { - let element = document.elementFromPoint(event.payload.x, event.payload.y); - if (element && 'click' in element && typeof element.click === 'function') { - element.click(); - } - }); -} +import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow'; + +import { CallbacksManager } from './modules/shared/utils/app'; + +export const ExtraCallbacksOnBlur = new CallbacksManager(); +export const ExtraCallbacksOnFocus = new CallbacksManager(); + +export function registerDocumentEvents() { + const webview = getCurrentWebviewWindow(); + + function onAppBlur() { + webview.setIgnoreCursorEvents(true); + ExtraCallbacksOnBlur.execute(); + } + + function onAppFocus() { + webview.setIgnoreCursorEvents(false); + ExtraCallbacksOnFocus.execute(); + } + + // TODO handle touches + /* webview.listen<{ x: number; y: number }>('click', (event) => { + let element = document.elementFromPoint(event.payload.x, event.payload.y); + if (element && 'click' in element && typeof element.click === 'function') { + element.click(); + } + }); */ + + webview.onFocusChanged((event) => { + if (event.payload) { + onAppFocus(); + } else { + onAppBlur(); + } + }); + + // this is started as true on rust side but to be secure we set it to false + let ignoring_cursor_events = false; + webview.listen<[x: number, y: number]>('global-mouse-move', async (event) => { + if (!(await webview.isVisible())) { + return; + } + + const [x, y] = event.payload; + const adjustedX = x / window.devicePixelRatio; + const adjustedY = y / window.devicePixelRatio; + + let element = document.elementFromPoint(adjustedX, adjustedY); + if (element != document.body && ignoring_cursor_events) { + webview.setIgnoreCursorEvents(false); + ignoring_cursor_events = false; + } else if (element == document.body && !ignoring_cursor_events) { + webview.setIgnoreCursorEvents(true); + ignoring_cursor_events = true; + } + }); +} diff --git a/src/apps/toolbar/index.tsx b/src/apps/toolbar/index.tsx index efd3fa2b..fee0e4ab 100644 --- a/src/apps/toolbar/index.tsx +++ b/src/apps/toolbar/index.tsx @@ -1,39 +1,39 @@ -import { getRootContainer } from '../shared'; -import { wrapConsole } from '../shared/ConsoleWrapper'; -import { registerDocumentEvents } from './events'; -import i18n, { loadTranslations } from './i18n'; -import { createRoot } from 'react-dom/client'; -import { I18nextProvider } from 'react-i18next'; -import { Provider } from 'react-redux'; - -import { loadStore, registerStoreEvents, store } from './modules/shared/store/infra'; -import { loadConstants } from './modules/shared/utils/infra'; - -import { App } from './app'; - -import './styles/colors.css'; -import './styles/variables.css'; -import './styles/reset.css'; -import './styles/global.css'; - -async function Main() { - wrapConsole(); - const container = getRootContainer(); - - registerDocumentEvents(container); - - await loadConstants(); - await registerStoreEvents(); - await loadStore(); - await loadTranslations(); - - createRoot(container).render( - - - - - , - ); -} - -Main(); +import { getRootContainer } from '../shared'; +import { wrapConsole } from '../shared/ConsoleWrapper'; +import { registerDocumentEvents } from './events'; +import i18n, { loadTranslations } from './i18n'; +import { createRoot } from 'react-dom/client'; +import { I18nextProvider } from 'react-i18next'; +import { Provider } from 'react-redux'; + +import { loadStore, registerStoreEvents, store } from './modules/shared/store/infra'; +import { loadConstants } from './modules/shared/utils/infra'; + +import { App } from './app'; + +import './styles/colors.css'; +import './styles/variables.css'; +import './styles/reset.css'; +import './styles/global.css'; + +async function Main() { + wrapConsole(); + registerDocumentEvents(); + + const container = getRootContainer(); + + await loadConstants(); + await registerStoreEvents(); + await loadStore(); + await loadTranslations(); + + createRoot(container).render( + + + + + , + ); +} + +Main(); diff --git a/src/apps/toolbar/modules/shared/hooks/infra.ts b/src/apps/toolbar/modules/shared/hooks/infra.ts index f03765de..c4d94a57 100644 --- a/src/apps/toolbar/modules/shared/hooks/infra.ts +++ b/src/apps/toolbar/modules/shared/hooks/infra.ts @@ -1,37 +1,37 @@ -import { ExtraCallbacksOnActivate, ExtraCallbacksOnLeave } from '../../../events'; -import { useEffect, useRef } from 'react'; - -export function useAppBlur(cb: () => void, deps: any[] = []) { - const key = useRef(crypto.randomUUID()); - useEffect(() => { - ExtraCallbacksOnLeave.remove(key.current); - ExtraCallbacksOnLeave.add(cb, key.current); - return () => { - ExtraCallbacksOnLeave.remove(key.current); - }; - }, deps); -} - -export function useAppActivation(cb: () => void, deps: any[] = []) { - const key = useRef(crypto.randomUUID()); - useEffect(() => { - ExtraCallbacksOnActivate.remove(key.current); - ExtraCallbacksOnActivate.add(cb, key.current); - return () => { - ExtraCallbacksOnActivate.remove(key.current); - }; - }, deps); -} - -export function useInterval(callback: () => void, delay: number, deps: any[] = []) { - const key = useRef(); - - // Set up the interval. - useEffect(() => { - if (key.current) { - clearInterval(key.current); - } - key.current = window.setInterval(callback, delay); - return () => clearInterval(key.current); - }, [callback, delay, ...deps]); +import { ExtraCallbacksOnBlur, ExtraCallbacksOnFocus } from '../../../events'; +import { useEffect, useRef } from 'react'; + +export function useAppBlur(cb: () => void, deps: any[] = []) { + const key = useRef(crypto.randomUUID()); + useEffect(() => { + ExtraCallbacksOnBlur.remove(key.current); + ExtraCallbacksOnBlur.add(cb, key.current); + return () => { + ExtraCallbacksOnBlur.remove(key.current); + }; + }, deps); +} + +export function useAppActivation(cb: () => void, deps: any[] = []) { + const key = useRef(crypto.randomUUID()); + useEffect(() => { + ExtraCallbacksOnFocus.remove(key.current); + ExtraCallbacksOnFocus.add(cb, key.current); + return () => { + ExtraCallbacksOnFocus.remove(key.current); + }; + }, deps); +} + +export function useInterval(callback: () => void, delay: number, deps: any[] = []) { + const key = useRef(); + + // Set up the interval. + useEffect(() => { + if (key.current) { + clearInterval(key.current); + } + key.current = window.setInterval(callback, delay); + return () => clearInterval(key.current); + }, [callback, delay, ...deps]); } \ No newline at end of file diff --git a/src/apps/toolbar/styles/global.css b/src/apps/toolbar/styles/global.css index 943a703c..c79c48fd 100644 --- a/src/apps/toolbar/styles/global.css +++ b/src/apps/toolbar/styles/global.css @@ -8,10 +8,18 @@ body { background: transparent; width: 100vw; height: 100vh; + border-top: 1px solid #000; } .fancy-toolbar { width: 100vw; + margin-top: -1px; + transition: transform 0.2s ease-in-out; + + &:has(.ft-bar-hidden):not(:hover) { + transform: translateY(calc(-100% + 1px)); + border-bottom: 1px solid transparent; + } .ft-bar { position: relative; @@ -21,11 +29,6 @@ body { justify-content: space-between; align-items: center; padding: 0 var(--config-padding-at-side); - transition: transform 0.2s ease-in-out; - - &.ft-bar-hidden { - transform: translateY(-100%); - } .ft-bar-left, .ft-bar-center, diff --git a/src/apps/toolbar/styles/reset.css b/src/apps/toolbar/styles/reset.css index 596dad8d..af4e57ca 100644 --- a/src/apps/toolbar/styles/reset.css +++ b/src/apps/toolbar/styles/reset.css @@ -1,135 +1,135 @@ -:root { - font-size: 100%; - --main-typo: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; - --primary-color: var(--color-gray-900); - --secondary-color: var(--color-gray-50); -} - -*, *:after, *:before { - margin: 0; - padding: 0; - border: 0; - outline: none; - box-sizing: border-box; - vertical-align: baseline; - -webkit-user-select: none; - user-select: none; -} - -img, image, picture, video, iframe, figure { - max-width: 100%; - width: 100%; - display: block; -} - -a { - display: block; -} - -p a { - display: inline; -} - -li { - list-style-type: none; -} - -html { - scroll-behavior: smooth; -} - -h1, h2, h3, h4, h5, h6, p, span, a, strong, blockquote, i, b, em, pre { - font-size: 1em; - font-weight: inherit; - font-style: inherit; - text-decoration: none; - color: inherit; -} - -form, input, textarea, select, button, label { - font-family: inherit; - font-size: inherit; - hyphens: auto; - background-color: transparent; - display: block; - color: inherit; -} - -table, tr, td { - border-collapse: collapse; - border-spacing: 0; -} - -svg { - width: 100%; - display: block; -} - -body { - font-size: 1em; - line-height: 1.4em; - font-family: var(--main-typo); - color: var(--primary-color); - background-color: var(--secondary-color); - hyphens: auto; - font-smooth: always; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; -} - -hr { - border: 1px solid; - margin: 1em 0; - opacity: 0.8; - color: var(--color-gray-200); -} - -/* Antd reset */ -#root { - .ant-popover { - .ant-popover-inner { - background: transparent; - border-radius: 0; - box-shadow: none; - padding: 0; - } - } - - .ant-dropdown-menu-submenu, - .ant-dropdown-menu, - .ant-menu { - background: transparent; - box-shadow: none; - display: flex; - flex-direction: column; - gap: 4px; - - .ant-menu-item, - .ant-dropdown-menu-item { - padding: 10px; - height: min-content; - width: 100%; - line-height: 12px; - margin: 0; - border-radius: 8px; - } - - .ant-menu-item:not(.ant-menu-item-danger), - .ant-dropdown-menu-item:not(.ant-dropdown-menu-item-danger) { - color: inherit; - - &:hover { - backdrop-filter: brightness(0.6); - } - } - - .ant-menu-item-divider, - .ant-dropdown-menu-item-divider { - backdrop-filter: brightness(0.85); - } - - .ant-dropdown-menu-submenu-title { - color: inherit; - } - } +:root { + font-size: 100%; + --main-typo: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + --primary-color: var(--color-gray-900); + --secondary-color: var(--color-gray-50); +} + +*, *:after, *:before { + margin: 0; + padding: 0; + border: 0; + outline: none; + box-sizing: border-box; + vertical-align: baseline; + -webkit-user-select: none; + user-select: none; +} + +img, image, picture, video, iframe, figure { + max-width: 100%; + width: 100%; + display: block; +} + +a { + display: block; +} + +p a { + display: inline; +} + +li { + list-style-type: none; +} + +html { + scroll-behavior: smooth; +} + +h1, h2, h3, h4, h5, h6, p, span, a, strong, blockquote, i, b, em, pre { + font-size: 1em; + font-weight: inherit; + font-style: inherit; + text-decoration: none; + color: inherit; +} + +form, input, textarea, select, button, label { + font-family: inherit; + font-size: inherit; + hyphens: auto; + background-color: transparent; + display: block; + color: inherit; +} + +table, tr, td { + border-collapse: collapse; + border-spacing: 0; +} + +svg { + width: 100%; + display: block; +} + +body { + font-size: 1em; + line-height: 1.4em; + font-family: var(--main-typo); + color: var(--primary-color); + background-color: var(--secondary-color); + hyphens: auto; + font-smooth: always; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +hr { + border: 1px solid; + margin: 1em 0; + opacity: 0.8; + color: var(--color-gray-200); +} + +/* Antd reset */ +#root { + .ant-popover { + .ant-popover-inner { + background: transparent; + border-radius: 0; + box-shadow: none; + padding: 0; + } + } + + .ant-dropdown-menu-submenu, + .ant-dropdown-menu, + .ant-menu { + background: transparent; + box-shadow: none; + display: flex; + flex-direction: column; + gap: 4px; + + .ant-menu-item, + .ant-dropdown-menu-item { + padding: 10px; + height: min-content; + width: 100%; + line-height: 12px; + margin: 0; + border-radius: 8px; + } + + .ant-menu-item:not(.ant-menu-item-danger), + .ant-dropdown-menu-item:not(.ant-dropdown-menu-item-danger) { + color: inherit; + + &:hover { + backdrop-filter: brightness(0.6); + } + } + + .ant-menu-item-divider, + .ant-dropdown-menu-item-divider { + backdrop-filter: brightness(0.85); + } + + .ant-dropdown-menu-submenu-title { + color: inherit; + } + } } \ No newline at end of file diff --git a/src/background/hook.rs b/src/background/hook.rs index 8b7e1c1b..807c0f26 100644 --- a/src/background/hook.rs +++ b/src/background/hook.rs @@ -25,8 +25,11 @@ use windows::Win32::{ use crate::{ error_handler::Result, log_error, - modules::virtual_desk::{get_vd_manager, VirtualDesktopEvent, VirtualDesktopManager}, - seelen::{Seelen, SEELEN}, + modules::{ + input::{domain::Point, Mouse}, + virtual_desk::{get_vd_manager, VirtualDesktopEvent, VirtualDesktopManager}, + }, + seelen::{get_app_handle, Seelen, SEELEN}, seelen_weg::SeelenWeg, state::{application::FULL_STATE, domain::AppExtraFlag}, trace_lock, @@ -278,5 +281,19 @@ pub fn register_win_hook() -> Result<()> { } })?; + spawn_named_thread("MouseEventHook", || { + let handle = get_app_handle(); + let mut last_pos = Point::default(); + loop { + if let Ok(pos) = Mouse::get_cursor_pos() { + if last_pos != pos { + let _ = handle.emit("global-mouse-move", &[pos.get_x(), pos.get_y()]); + last_pos = pos; + } + } + std::thread::sleep(Duration::from_millis(66)); // 15 FPS + } + })?; + Ok(()) } diff --git a/src/background/seelen_bar/cli.rs b/src/background/seelen_bar/cli.rs index a49b6732..bc1b923a 100644 --- a/src/background/seelen_bar/cli.rs +++ b/src/background/seelen_bar/cli.rs @@ -1,5 +1,4 @@ use clap::Command; -use tauri::Emitter; use crate::{error_handler::Result, get_subcommands}; @@ -8,8 +7,6 @@ use super::FancyToolbar; get_subcommands![ /** Open Dev Tools (only works if the app is running in dev mode) */ Debug, - /** Shows the invisible hitbox */ - DebugHitbox, ]; impl FancyToolbar { @@ -30,10 +27,6 @@ impl FancyToolbar { #[cfg(any(debug_assertions, feature = "devtools"))] self.window.open_devtools(); } - SubCommand::DebugHitbox => { - self.hitbox - .emit_to(self.hitbox.label(), "debug-hitbox", ())?; - } }; Ok(()) } diff --git a/src/background/seelen_bar/hook.rs b/src/background/seelen_bar/hook.rs index 74fc8b5a..1c6a3e01 100644 --- a/src/background/seelen_bar/hook.rs +++ b/src/background/seelen_bar/hook.rs @@ -24,12 +24,6 @@ impl FancyToolbar { WinEvent::SyntheticFullscreenStart(event_data) => { let monitor = WindowsApi::monitor_from_window(self.window.hwnd()?); if monitor == event_data.monitor { - log::trace!( - "Fullscreen on {} || {} || {}", - WindowsApi::exe(origin).unwrap_or_default(), - WindowsApi::get_class(origin).unwrap_or_default(), - WindowsApi::get_window_text(origin) - ); self.hide()?; } } diff --git a/src/background/seelen_bar/mod.rs b/src/background/seelen_bar/mod.rs index 34624270..c1931f2d 100644 --- a/src/background/seelen_bar/mod.rs +++ b/src/background/seelen_bar/mod.rs @@ -25,8 +25,6 @@ use windows::Win32::{ pub struct FancyToolbar { window: WebviewWindow, - hitbox: WebviewWindow, - // -- -- -- -- pub cached_monitor: HMONITOR, last_focus: Option, hidden: bool, @@ -43,21 +41,18 @@ pub struct ActiveApp { impl Drop for FancyToolbar { fn drop(&mut self) { log::info!("Dropping {}", self.window.label()); - if let Ok(hwnd) = self.hitbox.hwnd() { + if let Ok(hwnd) = self.window.hwnd() { AppBarData::from_handle(hwnd).unregister_bar(); } log_error!(self.window.destroy()); - log_error!(self.hitbox.destroy()); } } impl FancyToolbar { pub fn new(postfix: &str) -> Result { log::info!("Creating {}/{}", Self::TARGET, postfix); - let (window, hitbox) = Self::create_window(postfix)?; Ok(Self { - window, - hitbox, + window: Self::create_window(postfix)?, last_focus: None, hidden: false, cached_monitor: HMONITOR(-1), @@ -86,7 +81,6 @@ impl FancyToolbar { return Ok(()); } self.overlaped = is_overlaped; - self.set_positions(self.cached_monitor.0)?; self.emit("set-auto-hide", self.overlaped)?; Ok(()) } @@ -105,14 +99,12 @@ impl FancyToolbar { pub fn hide(&mut self) -> Result<()> { WindowsApi::show_window_async(self.window.hwnd()?, SW_HIDE)?; - WindowsApi::show_window_async(self.hitbox.hwnd()?, SW_HIDE)?; self.hidden = true; Ok(()) } pub fn show(&mut self) -> Result<()> { WindowsApi::show_window_async(self.window.hwnd()?, SW_SHOWNOACTIVATE)?; - WindowsApi::show_window_async(self.hitbox.hwnd()?, SW_SHOWNOACTIVATE)?; self.hidden = false; Ok(()) } @@ -133,8 +125,8 @@ impl FancyToolbar { } pub fn ensure_hitbox_zorder(&self) -> Result<()> { - let hitbox = HWND(self.hitbox.hwnd()?.0); - WindowsApi::bring_to(hitbox, HWND_TOPMOST)?; + let hwnd = HWND(self.window.hwnd()?.0); + WindowsApi::bring_to(hwnd, HWND_TOPMOST)?; self.set_positions(self.cached_monitor.0)?; Ok(()) } @@ -143,7 +135,6 @@ impl FancyToolbar { // statics impl FancyToolbar { const TARGET: &'static str = "fancy-toolbar"; - const TARGET_HITBOX: &'static str = "fancy-toolbar-hitbox"; /// Work area no works fine on multiple monitors /// so we use this functions that only takes the toolbar in account @@ -172,27 +163,17 @@ impl FancyToolbar { let rc_monitor = monitor_info.monitorInfo.rcMonitor; let main_hwnd = HWND(self.window.hwnd()?.0); - let hitbox_hwnd = HWND(self.hitbox.hwnd()?.0); let state = FULL_STATE.load(); let settings = &state.settings().fancy_toolbar; - let dpi = WindowsApi::get_device_pixel_ratio(hmonitor)?; - - let mut abd = AppBarData::from_handle(hitbox_hwnd); + let mut abd = AppBarData::from_handle(main_hwnd); let mut abd_rect = rc_monitor; - let mut hitbox_rect = rc_monitor; - abd_rect.bottom = abd_rect.top + (settings.height as f32 * dpi) as i32; - hitbox_rect.bottom = hitbox_rect.top + (settings.height as f32 * dpi) as i32; - - if settings.hide_mode == HideMode::Always { + if settings.hide_mode == HideMode::Always || settings.hide_mode == HideMode::OnOverlap { abd_rect.bottom = abd_rect.top + 1; - hitbox_rect.bottom = hitbox_rect.top + 1; - } else if settings.hide_mode == HideMode::OnOverlap { - abd_rect.bottom = abd_rect.top + 1; - if self.overlaped { - hitbox_rect.bottom = hitbox_rect.top + 1; - } + } else { + let dpi = WindowsApi::get_device_pixel_ratio(hmonitor)?; + abd_rect.bottom = abd_rect.top + (settings.height as f32 * dpi) as i32; } abd.set_edge(AppBarDataEdge::Top); @@ -200,39 +181,14 @@ impl FancyToolbar { abd.register_as_new_bar(); // pre set position for resize in case of multiples dpi - WindowsApi::move_window(hitbox_hwnd, &hitbox_rect)?; - WindowsApi::set_position(hitbox_hwnd, None, &hitbox_rect, SWP_NOACTIVATE)?; - WindowsApi::move_window(main_hwnd, &rc_monitor)?; WindowsApi::set_position(main_hwnd, None, &rc_monitor, SWP_NOACTIVATE)?; Ok(()) } - fn create_window(postfix: &str) -> Result<(WebviewWindow, WebviewWindow)> { + fn create_window(postfix: &str) -> Result { let manager = get_app_handle(); - let label = format!("{}/{}", Self::TARGET_HITBOX, postfix); - let hitbox = match manager.get_webview_window(&label) { - Some(window) => window, - None => tauri::WebviewWindowBuilder::new( - &manager, - label, - tauri::WebviewUrl::App("toolbar-hitbox/index.html".into()), - ) - .title("Seelen Fancy Toolbar Hitbox") - .maximizable(false) - .minimizable(false) - .resizable(false) - .visible(false) - .decorations(false) - .transparent(true) - .shadow(false) - .skip_taskbar(true) - .always_on_top(true) - .drag_and_drop(false) - .build()?, - }; - let label = format!("{}/{}", Self::TARGET, postfix); let window = match manager.get_webview_window(&label) { Some(window) => window, @@ -252,14 +208,12 @@ impl FancyToolbar { .skip_taskbar(true) .always_on_top(true) .drag_and_drop(false) - .owner(&hitbox)? .build()?, }; window.set_ignore_cursor_events(true)?; - window.once("store-events-ready", Self::on_store_events_ready); - Ok((window, hitbox)) + Ok(window) } fn on_store_events_ready(_: tauri::Event) { diff --git a/src/background/utils/ahk/mocks/seelen.lib.ahk b/src/background/utils/ahk/mocks/seelen.lib.ahk index 42df80df..b53ff174 100644 --- a/src/background/utils/ahk/mocks/seelen.lib.ahk +++ b/src/background/utils/ahk/mocks/seelen.lib.ahk @@ -73,6 +73,5 @@ ResumeWM() { } DebugHitboxes() { - RunWait(seelen " tb debug-hitbox", , "Hide") RunWait(seelen " weg debug-hitbox", , "Hide") } \ No newline at end of file