重写桌面歌词窗口坐标的计算逻辑
parent
4fa88dd7a0
commit
82bea640c4
|
@ -2,3 +2,4 @@
|
|||
### 修复
|
||||
|
||||
- 修复声音输出设备更改时后的自动暂停播放设置无效的问题
|
||||
- 重写桌面歌词窗口坐标的计算逻辑,修复桌面歌词移动到最边缘时,某些情况下在启用歌词后会出现窗口偏移的问题(远古bug了)
|
||||
|
|
|
@ -76,8 +76,8 @@ declare namespace LX {
|
|||
|
||||
|
||||
interface NewBounds {
|
||||
x?: number | null
|
||||
y?: number
|
||||
x: number
|
||||
y: number
|
||||
w: number
|
||||
h: number
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { join } from 'path'
|
||||
import { BrowserWindow } from 'electron'
|
||||
import { debounce, isLinux } from '@common/utils'
|
||||
import { getLyricWindowBounds, offset } from './utils'
|
||||
import { getLyricWindowBounds, minHeight, minWidth, padding } from './utils'
|
||||
import { mainSend } from '@common/mainIpc'
|
||||
import { encodePath } from '@common/utils/electron'
|
||||
|
||||
|
@ -81,15 +81,20 @@ export const createWindow = () => {
|
|||
let width = global.lx.appSetting['desktopLyric.width']
|
||||
let height = global.lx.appSetting['desktopLyric.height']
|
||||
let isAlwaysOnTop = global.lx.appSetting['desktopLyric.isAlwaysOnTop']
|
||||
let isLockScreen = global.lx.appSetting['desktopLyric.isLockScreen']
|
||||
// let isLockScreen = global.lx.appSetting['desktopLyric.isLockScreen']
|
||||
let isShowTaskbar = global.lx.appSetting['desktopLyric.isShowTaskbar']
|
||||
let { width: screenWidth, height: screenHeight } = global.envParams.workAreaSize
|
||||
// let { width: screenWidth, height: screenHeight } = global.envParams.workAreaSize
|
||||
if (x == null || y == null) {
|
||||
x = screenWidth - width + offset
|
||||
y = screenHeight - height + offset
|
||||
if (width < minWidth) width = minWidth
|
||||
if (height < minHeight) height = minHeight
|
||||
if (global.envParams.workAreaSize) {
|
||||
x = global.envParams.workAreaSize.width + padding - width
|
||||
y = global.envParams.workAreaSize.height + padding - height
|
||||
} else {
|
||||
x = y = -padding
|
||||
}
|
||||
if (isLockScreen) {
|
||||
let bounds = getLyricWindowBounds({ x, y, width, height }, { x: null, y: 0, w: width, h: height })
|
||||
} else {
|
||||
let bounds = getLyricWindowBounds({ x, y, width, height }, { x: 0, y: 0, w: width, h: height })
|
||||
x = bounds.x
|
||||
y = bounds.y
|
||||
width = bounds.width
|
||||
|
|
|
@ -1,77 +1,52 @@
|
|||
// 设置窗口位置、大小
|
||||
let winX
|
||||
let winY
|
||||
let wasW
|
||||
let wasH
|
||||
export const offset = 8
|
||||
let minWidth = 80
|
||||
let minHeight = 50
|
||||
export const padding = 8
|
||||
export let minWidth = 80
|
||||
export let minHeight = 50
|
||||
|
||||
|
||||
// const updateBounds = (bounds: Bounds) => {
|
||||
// bounds.x = bounds.x
|
||||
// return bounds
|
||||
// }
|
||||
|
||||
/**
|
||||
*
|
||||
* @param bounds 当前设置
|
||||
* @param param 新设置(相对于当前设置)
|
||||
* @returns
|
||||
*/
|
||||
export const getLyricWindowBounds = (bounds: Electron.Rectangle, { x = 0, y = 0, w = 0, h = 0 }: LX.DesktopLyric.NewBounds): Electron.Rectangle => {
|
||||
if (w < minWidth) w = minWidth
|
||||
if (h < minHeight) h = minHeight
|
||||
|
||||
if (global.lx.appSetting['desktopLyric.isLockScreen']) {
|
||||
if (!global.envParams.workAreaSize) return bounds
|
||||
wasW = (global.envParams.workAreaSize.width ?? 0) + offset
|
||||
wasH = (global.envParams.workAreaSize.height ?? 0) + offset
|
||||
const maxWinW = global.envParams.workAreaSize.width + padding * 2
|
||||
const maxWinH = global.envParams.workAreaSize.height + padding * 2
|
||||
|
||||
if (w > wasW + offset) w = wasW + offset
|
||||
if (h > wasH + offset) h = wasH + offset
|
||||
if (x == null) {
|
||||
if (bounds.x > wasW - w) {
|
||||
x = wasW - w - bounds.x
|
||||
} else if (bounds.x < -offset) {
|
||||
x = bounds.x + offset
|
||||
if (w > maxWinW) w = maxWinW
|
||||
if (h > maxWinH) h = maxWinH
|
||||
|
||||
const maxX = global.envParams.workAreaSize.width + padding - w
|
||||
const minX = -padding
|
||||
const maxY = global.envParams.workAreaSize.height + padding - h
|
||||
const minY = -padding
|
||||
|
||||
x += bounds.x
|
||||
y += bounds.y
|
||||
|
||||
if (x > maxX) x = maxX
|
||||
else if (x < minX) x = minX
|
||||
|
||||
if (y > maxY) y = maxY
|
||||
else if (y < minY) y = minY
|
||||
} else {
|
||||
x = 0
|
||||
}
|
||||
if (bounds.y > wasH - h) {
|
||||
y = wasH - h - bounds.y
|
||||
} else if (bounds.y < -offset) {
|
||||
y = bounds.y + offset
|
||||
} else {
|
||||
y = 0
|
||||
}
|
||||
}
|
||||
winX = bounds.x + x
|
||||
winY = bounds.y + y
|
||||
|
||||
if (x != 0) {
|
||||
if (winX < -offset) {
|
||||
winX = -offset
|
||||
} else if (winX + w > wasW) {
|
||||
winX = wasW - w
|
||||
}
|
||||
}
|
||||
if (y != 0) {
|
||||
if (winY < -offset) {
|
||||
winY = -offset
|
||||
} else if (winY + h > wasH) {
|
||||
winY = wasH - h
|
||||
}
|
||||
}
|
||||
|
||||
x = winX
|
||||
y = winY
|
||||
|
||||
if (x + w > wasW) w = wasW - x
|
||||
if (y + h > wasH) h = wasH - y
|
||||
} else {
|
||||
if (x == null) {
|
||||
x = 0
|
||||
y = 0
|
||||
}
|
||||
y += bounds.y
|
||||
x += bounds.x
|
||||
}
|
||||
|
||||
bounds.width = w
|
||||
bounds.height = h
|
||||
bounds.x = x
|
||||
bounds.y = y
|
||||
// console.log('util bounds', bounds)
|
||||
return bounds
|
||||
return { width: w, height: h, x, y }
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ export default () => {
|
|||
let bounds: LX.DesktopLyric.NewBounds = {
|
||||
w: 0,
|
||||
h: 0,
|
||||
x: 0,
|
||||
y: 0,
|
||||
}
|
||||
let temp
|
||||
|
|
Loading…
Reference in New Issue