Skip to content

Commit

Permalink
fix(#66): toolbar hitbox not handling multimonitors
Browse files Browse the repository at this point in the history
  • Loading branch information
eythaann committed Aug 30, 2024
1 parent b54d97b commit 597c7c4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 22 deletions.
6 changes: 5 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## [Unreleased]
## [Unreleased]
### fix
- app crashing if uwp package has missing path.
- app no working fine on multiple monitors.

## [1.10.0]
### features
- add volume changed popup.
Expand Down
57 changes: 37 additions & 20 deletions src/apps/toolbar/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,57 @@ import { CallbacksManager } from './modules/shared/utils/app';
export const ExtraCallbacksOnBlur = new CallbacksManager();
export const ExtraCallbacksOnFocus = new CallbacksManager();

export function registerDocumentEvents() {
export async function registerDocumentEvents() {
let appFocused = true;
const webview = getCurrentWebviewWindow();

function onAppBlur() {
appFocused = false;
webview.setIgnoreCursorEvents(true);
ExtraCallbacksOnBlur.execute();
}

function onAppFocus() {
appFocused = true;
webview.setIgnoreCursorEvents(false);
ExtraCallbacksOnFocus.execute();
}

webview.onFocusChanged((event) => {
if (event.payload) {
onAppFocus();
} else {
onAppBlur();
appFocused = event.payload;
webview.setIgnoreCursorEvents(!appFocused);
if (appFocused) {
return ExtraCallbacksOnFocus.execute();
}
ExtraCallbacksOnBlur.execute();
});

// this is started as true on rust side but to be secure we set it to false
let ignoring_cursor_events = false;

const { x, y } = await webview.outerPosition();
const { width, height } = await webview.outerSize();
let webviewRect = { x, y, width, height };

webview.onMoved((e) => {
webviewRect.x = e.payload.x;
webviewRect.y = e.payload.y;
});

webview.onResized((e) => {
webviewRect.width = e.payload.width;
webviewRect.height = e.payload.height;
});

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;
const [mouseX, mouseY] = event.payload;
let { x: windowX, y: windowY, width: windowWidth, height: windowHeight } = webviewRect;

// check if the mouse is inside the window
const isHoverWindow =
mouseX >= windowX &&
mouseX <= windowX + windowWidth &&
mouseY >= windowY &&
mouseY <= windowY + windowHeight;

if (!isHoverWindow) {
return;
}

const adjustedX = (mouseX - windowX) / window.devicePixelRatio;
const adjustedY = (mouseY - windowY) / window.devicePixelRatio;

let element = document.elementFromPoint(adjustedX, adjustedY);
if (element != document.body && ignoring_cursor_events) {
Expand Down
2 changes: 1 addition & 1 deletion src/apps/toolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import './styles/global.css';

async function Main() {
wrapConsole();
registerDocumentEvents();
await registerDocumentEvents();

const container = getRootContainer();

Expand Down

0 comments on commit 597c7c4

Please sign in to comment.