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