重写桌面歌词窗口坐标的计算逻辑
This commit is contained in:
@@ -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 (isLockScreen) {
|
||||
let bounds = getLyricWindowBounds({ x, y, width, height }, { x: null, y: 0, w: width, h: height })
|
||||
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
|
||||
}
|
||||
} 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
|
||||
} 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 (w > maxWinW) w = maxWinW
|
||||
if (h > maxWinH) h = maxWinH
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
const maxX = global.envParams.workAreaSize.width + padding - w
|
||||
const minX = -padding
|
||||
const maxY = global.envParams.workAreaSize.height + padding - h
|
||||
const minY = -padding
|
||||
|
||||
x = winX
|
||||
y = winY
|
||||
x += bounds.x
|
||||
y += bounds.y
|
||||
|
||||
if (x + w > wasW) w = wasW - x
|
||||
if (y + h > wasH) h = wasH - y
|
||||
if (x > maxX) x = maxX
|
||||
else if (x < minX) x = minX
|
||||
|
||||
if (y > maxY) y = maxY
|
||||
else if (y < minY) y = minY
|
||||
} 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 }
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user