Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复获取屏幕尺寸 #1145

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions app/shared/src/desktopMain/kotlin/desktop/ScreenUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.compose.ui.unit.dp
import me.him188.ani.utils.platform.Platform
import java.awt.Dimension
import java.awt.GraphicsEnvironment
import java.awt.Toolkit

object ScreenUtils {

Expand All @@ -31,8 +30,8 @@ object ScreenUtils {
* 获取经过缩放后的, 实际可用的屏幕大小. 将窗口设置为这个大小即可占满整个屏幕
*/
fun getScreenSize(): DpSize {
val dimension: Dimension = Toolkit.getDefaultToolkit().screenSize

val graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment()
val dimension: Dimension = graphicsEnvironment.maximumWindowBounds.size
return when (me.him188.ani.utils.platform.currentPlatformDesktop()) {
is Platform.Linux, // TODO: 检查 linux 的 getScreenSize
is Platform.MacOS -> {
Expand All @@ -45,18 +44,9 @@ object ScreenUtils {
}

is Platform.Windows -> {
// windows 的 dimension 是没有经过缩放的
// Get screen dimensions
val screenWidth = dimension.width
val screenHeight = dimension.height

// Convert screen dimensions to dp
// See ui-desktop-1.6.10-sources.jar!/desktopMain/androidx/compose/ui/window/LayoutConfiguration.desktop.kt:45
val density = getScreenDensity()
NieR4ever marked this conversation as resolved.
Show resolved Hide resolved
val screenWidthDp = density.run { screenWidth.toDp() }
val screenHeightDp = density.run { screenHeight.toDp() }

return DpSize(screenWidthDp, screenHeightDp)
// windows 的 dimension 是经过缩放的

DpSize(dimension.width.dp, dimension.height.dp)
}
}
}
Expand Down
Loading