Skip to content

Commit fe41f58

Browse files
authored
feat: 支持「猫咪设置 > 窗口设置 > 鼠标移入隐藏」延迟设置 (#935)
1 parent 29b20f7 commit fe41f58

9 files changed

Lines changed: 62 additions & 18 deletions

File tree

src/components/pro-list-item/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<script setup lang="ts">
22
import { Flex } from 'ant-design-vue'
3-
import { computed, useSlots } from 'vue'
3+
import { computed } from 'vue'
44
55
const { title, description, vertical } = defineProps<{
66
title: string
77
description?: string
88
vertical?: boolean
99
}>()
1010
11-
const slots = useSlots()
11+
const slots = defineSlots()
1212
1313
const hasDescription = computed(() => {
1414
return description || slots.description

src/composables/useDevice.ts

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,26 +114,51 @@ export function useDevice() {
114114
return nextKey
115115
}
116116

117-
const handleCursorMove = async (cursorPoint: CursorPoint) => {
118-
const x = cursorPoint.x * scaleFactor.value
119-
const y = cursorPoint.y * scaleFactor.value
120-
121-
handleMouseMove(new PhysicalPosition(x, y))
117+
const onHideOnHover = (() => {
118+
let timer: ReturnType<typeof setTimeout> | undefined
119+
let wasInWindow = false
122120

123-
if (catStore.window.hideOnHover) {
121+
return (x: number, y: number) => {
124122
const { x: winX, y: winY, width, height } = appStore.windowState[WINDOW_LABEL.MAIN] ?? {}
125123

126124
if (isNil(winX) || isNil(winY) || isNil(width) || isNil(height)) return
127125

128126
const isInWindow = inBetween(x, winX, winX + width)
129127
&& inBetween(y, winY, winY + height)
130128

131-
document.body.style.setProperty('opacity', isInWindow ? '0' : 'unset')
129+
if (isInWindow === wasInWindow) return
130+
131+
if (timer) {
132+
clearTimeout(timer)
133+
134+
timer = void 0
135+
}
136+
137+
if (isInWindow) {
138+
timer = setTimeout(() => {
139+
document.body.style.setProperty('opacity', '0')
140+
141+
appWindow.setIgnoreCursorEvents(true)
142+
}, catStore.window.hideOnHoverDelay * 1000)
143+
} else {
144+
document.body.style.setProperty('opacity', 'unset')
132145

133-
if (!catStore.window.passThrough) {
134-
appWindow.setIgnoreCursorEvents(isInWindow)
146+
appWindow.setIgnoreCursorEvents(catStore.window.passThrough)
135147
}
148+
149+
wasInWindow = isInWindow
136150
}
151+
})()
152+
153+
const handleCursorMove = async (cursorPoint: CursorPoint) => {
154+
const x = cursorPoint.x * scaleFactor.value
155+
const y = cursorPoint.y * scaleFactor.value
156+
157+
handleMouseMove(new PhysicalPosition(x, y))
158+
159+
if (!catStore.window.hideOnHover) return
160+
161+
onHideOnHover(x, y)
137162
}
138163

139164
const handleAutoRelease = (key: string, delay = 100) => {

src/locales/en-US.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"keepInScreen": "When enabled, the window automatically stays within the screen boundaries.",
3838
"windowSize": "Move mouse to window edge, or hold Shift and right-drag to resize.",
3939
"autoReleaseDelay": "On Windows, some system keys cannot capture release events and will auto-release after timeout.",
40-
"hideOnHover": "When enabled, the window hides when mouse hovers over it.",
40+
"hideOnHover": "When enabled, the window hides automatically on mouse hover. You can set a delay; 0 means hide immediately.",
4141
"maxFPS": "Limit the maximum frame rate for model rendering. Lowering the frame rate can reduce CPU/GPU usage."
4242
}
4343
},

src/locales/pt-BR.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"keepInScreen": "Quando ativado, a janela permanece automaticamente dentro dos limites da tela.",
3838
"windowSize": "Mova o mouse para a borda da janela ou segure Shift e arraste com o botão direito para redimensionar.",
3939
"autoReleaseDelay": "Devido ao Windows não capturar eventos de liberação de certas teclas de nível do sistema, elas serão automaticamente tratadas como liberadas após um tempo limite.",
40-
"hideOnHover": "Quando ativado, a janela será ocultada quando o mouse passar sobre ela.",
40+
"hideOnHover": "Quando ativado, a janela se oculta automaticamente ao passar o mouse. Você pode definir um atraso; 0 significa ocultar imediatamente.",
4141
"maxFPS": "Limitar a taxa máxima de quadros para renderização do modelo. Reduzir a taxa de quadros pode diminuir o uso de CPU/GPU."
4242
}
4343
},

src/locales/vi-VN.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"keepInScreen": "Khi bật, cửa sổ sẽ tự động giữ trong ranh giới màn hình.",
3838
"windowSize": "Di chuyển chuột đến mép cửa sổ hoặc giữ Shift và kéo chuột phải để thay đổi kích thước.",
3939
"autoReleaseDelay": "Do Windows không bắt được sự kiện nhả của một số phím hệ thống, các phím đó sẽ được tự động xem như đã nhả sau khi hết thời gian chờ.",
40-
"hideOnHover": "Khi bật, cửa sổ sẽ ẩn khi chuột di chuyển vào.",
40+
"hideOnHover": "Khi bật, cửa sổ tự động ẩn khi chuột di vào. Có thể đặt thời gian trễ, 0 nghĩa là ẩn ngay.",
4141
"maxFPS": "Giới hạn tốc độ khung hình tối đa cho việc render mô hình. Giảm tốc độ khung hình có thể giảm mức sử dụng CPU/GPU."
4242
}
4343
},

src/locales/zh-CN.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"keepInScreen": "启用后,窗口会自动调整位置,防止超出屏幕边界。",
3838
"windowSize": "将鼠标移至窗口边缘,或按住 Shift 并右键拖动,也可以调整窗口大小。",
3939
"autoReleaseDelay": "由于 Windows 下部分系统级按键无法捕获释放事件,超时后将自动视为已释放。",
40-
"hideOnHover": "启用后,鼠标悬停在窗口上时,窗口会隐藏",
40+
"hideOnHover": "启用后,鼠标悬停窗口时自动隐藏。可设置延迟时间,0 表示立即隐藏",
4141
"maxFPS": "限制模型渲染的最大帧率,降低帧率可以减少 CPU/GPU 占用。"
4242
}
4343
},

src/locales/zh-TW.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"keepInScreen": "啟用後,視窗會自動調整位置,防止超出螢幕邊界。",
3838
"windowSize": "將滑鼠游標移至視窗邊緣,或按住 Shift 並右鍵拖曳,也可以調整視窗大小。",
3939
"autoReleaseDelay": "由於 Windows 下部份系統級按鍵無法擷取釋放事件,超時後將自動視為已釋放。",
40-
"hideOnHover": "啟用後,滑鼠游標懸停在視窗上時,視窗會隱藏",
40+
"hideOnHover": "啟用後,滑鼠游標懸停視窗時自動隱藏。可設定延遲時間,0 表示立即隱藏",
4141
"maxFPS": "限制模型渲染的最大幀率,降低幀率可以減少 CPU/GPU 佔用。"
4242
}
4343
},

src/pages/preference/components/cat/index.vue

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { InputNumber, Slider, Switch } from 'ant-design-vue'
2+
import { Divider, Flex, InputNumber, Slider, Switch } from 'ant-design-vue'
33
44
import ProListItem from '@/components/pro-list-item/index.vue'
55
import ProList from '@/components/pro-list/index.vue'
@@ -82,7 +82,24 @@ const catStore = useCatStore()
8282
:description="$t('pages.preference.cat.hints.hideOnHover')"
8383
:title="$t('pages.preference.cat.labels.hideOnHover')"
8484
>
85-
<Switch v-model:checked="catStore.window.hideOnHover" />
85+
<Flex align="center">
86+
<Switch v-model:checked="catStore.window.hideOnHover" />
87+
88+
<Flex
89+
align="center"
90+
class="overflow-hidden transition-all"
91+
:class="[catStore.window.hideOnHover ? 'w-28 opacity-100' : 'w-0 opacity-0']"
92+
>
93+
<Divider type="vertical" />
94+
95+
<InputNumber
96+
v-model:value="catStore.window.hideOnHoverDelay"
97+
addon-after="s"
98+
class="w-24"
99+
:min="0"
100+
/>
101+
</Flex>
102+
</Flex>
86103
</ProListItem>
87104

88105
<ProListItem

src/stores/cat.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface CatStore {
1818
opacity: number
1919
radius: number
2020
hideOnHover: boolean
21+
hideOnHoverDelay: number
2122
keepInScreen: boolean
2223
}
2324
}
@@ -63,6 +64,7 @@ export const useCatStore = defineStore('cat', () => {
6364
opacity: 100,
6465
radius: 0,
6566
hideOnHover: false,
67+
hideOnHoverDelay: 0,
6668
keepInScreen: true,
6769
})
6870

0 commit comments

Comments
 (0)