1+ import type { MouseMoveValue } from './useDevice.ts'
2+ import type { Monitor } from '@tauri-apps/api/window'
3+
14import { LogicalSize , PhysicalSize } from '@tauri-apps/api/dpi'
25import { resolveResource } from '@tauri-apps/api/path'
36import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow'
7+ import { availableMonitors as getAvailableMonitors } from '@tauri-apps/api/window'
48import { message } from 'ant-design-vue'
59import { isNil , round } from 'es-toolkit'
6- import { ref , watch } from 'vue'
10+ import { computed , onBeforeMount , ref , watch } from 'vue'
711
812import live2d from '../utils/live2d'
913import { getCursorMonitor } from '../utils/monitor'
@@ -22,6 +26,13 @@ export function useModel() {
2226 const modelStore = useModelStore ( )
2327 const catStore = useCatStore ( )
2428 const modelSize = ref < ModelSize > ( )
29+ const availableMonitors = ref < Monitor [ ] > ( [ ] )
30+
31+ const isOnlySingleMonitor = computed ( ( ) => availableMonitors . value . length === 1 )
32+
33+ onBeforeMount ( async ( ) => {
34+ availableMonitors . value = await getAvailableMonitors ( )
35+ } )
2536
2637 watch ( ( ) => modelStore . currentModel , handleLoad , { deep : true , immediate : true } )
2738
@@ -91,8 +102,14 @@ export function useModel() {
91102 live2d . setParameterValue ( id , pressed ? max : min )
92103 }
93104
94- async function handleMouseMove ( ) {
95- const monitor = await getCursorMonitor ( )
105+ async function _getCursorMonitor ( mousePosition : MouseMoveValue ) {
106+ return isOnlySingleMonitor . value
107+ ? { ...availableMonitors . value [ 0 ] , cursorPosition : mousePosition }
108+ : await getCursorMonitor ( )
109+ }
110+
111+ async function handleMouseMove ( mousePosition : MouseMoveValue ) {
112+ const monitor = await _getCursorMonitor ( mousePosition )
96113
97114 if ( ! monitor ) return
98115
0 commit comments