mirror of
https://github.com/0PandaDEV/Qopy.git
synced 2025-04-21 21:24:05 +02:00
Fix focus issue when opening Qopy
Fixes #10 Implement platform-specific focus management to prevent the underlying window from losing focus when the shortcut is pressed. * **src-tauri/src/api/hotkeys.rs** - Add platform-specific modules for Windows, macOS, and Linux to manage focus between windows. - Modify the `setup` function to use platform-specific APIs to manage focus between windows. - Replace `window.set_focus()` with `platform::manage_focus(&window)`. * **src-tauri/src/api/tray.rs** - Add platform-specific modules for Windows, macOS, and Linux to manage focus between windows when the tray menu is used. - Modify the `setup` function to use platform-specific APIs to manage focus between windows. - Replace `window_clone_for_tray.set_focus()` with `platform::manage_focus(&window_clone_for_tray)`. * **app.vue** - Add `manageFocus` function to handle platform-specific focus management. - Call `manageFocus` function when the `change_keybind` event is triggered. * **src-tauri/src/main.rs** - Remove logic to hide the window when it loses focus. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/0PandaDEV/Qopy/issues/10?shareId=XXXX-XXXX-XXXX-XXXX).
This commit is contained in:
parent
fd0fdd2d51
commit
fbd159c68b
4 changed files with 121 additions and 7 deletions
26
app.vue
26
app.vue
|
@ -14,12 +14,36 @@ onMounted(async () => {
|
|||
await navigateTo('/keybind')
|
||||
await app.show();
|
||||
await window.getCurrentWindow().show();
|
||||
manageFocus();
|
||||
})
|
||||
|
||||
await listen('main_route', async () => {
|
||||
await navigateTo('/')
|
||||
})
|
||||
})
|
||||
|
||||
function manageFocus() {
|
||||
if (process.platform === 'win32') {
|
||||
const { SetForegroundWindow, AttachThreadInput, GetForegroundWindow, GetWindowThreadProcessId } = require('windows-api');
|
||||
const foregroundWindow = GetForegroundWindow();
|
||||
const currentThreadId = GetWindowThreadProcessId(foregroundWindow, null);
|
||||
const targetThreadId = GetWindowThreadProcessId(window.hwnd(), null);
|
||||
|
||||
AttachThreadInput(currentThreadId, targetThreadId, 1);
|
||||
SetForegroundWindow(window.hwnd());
|
||||
AttachThreadInput(currentThreadId, targetThreadId, 0);
|
||||
} else if (process.platform === 'darwin') {
|
||||
const { NSWindow } = require('cocoa');
|
||||
const nsWindow = window.ns_window();
|
||||
nsWindow.makeKeyAndOrderFront(true);
|
||||
} else if (process.platform === 'linux') {
|
||||
const { XOpenDisplay, XDefaultRootWindow, XSetInputFocus, XCloseDisplay, RevertToParent } = require('xlib');
|
||||
const display = XOpenDisplay(null);
|
||||
const rootWindow = XDefaultRootWindow(display);
|
||||
XSetInputFocus(display, rootWindow, RevertToParent, 0);
|
||||
XCloseDisplay(display);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
|
@ -72,4 +96,4 @@ body,
|
|||
.os-scrollbar-horizontal {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue