JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.87k stars 1.15k forks source link

windowState.isMaximized isn't updated after we switch from fullscreen to maximized #1489

Open igordmn opened 2 years ago

igordmn commented 2 years ago

Compose 1.0.0-rc5, Windows 11

Reproducer 1:

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.material.Checkbox
import androidx.compose.material.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowPlacement
import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState

fun main() = application {
    val state = rememberWindowState(placement = WindowPlacement.Maximized)

    Window(onCloseRequest = ::exitApplication, state = state) {
        Column {
            Text(state.size.toString())

            Row(verticalAlignment = Alignment.CenterVertically) {
                Checkbox(
                    state.placement == WindowPlacement.Fullscreen,
                    {
                        state.placement = if (it) {
                            WindowPlacement.Fullscreen
                        } else {
                            WindowPlacement.Floating
                        }
                    }
                )
                Text("isFullscreen")
            }

            Row(verticalAlignment = Alignment.CenterVertically) {
                Checkbox(
                    state.placement == WindowPlacement.Maximized,
                    {
                        state.placement = if (it) {
                            WindowPlacement.Maximized
                        } else {
                            WindowPlacement.Floating
                        }
                    }
                )
                Text("isMaximized")
            }
        }
    }
}
  1. Check Fullscreen
  2. Check Maximized

Actual: image

Expected: image

Reproducer 2:

import androidx.compose.ui.awt.ComposeWindow
import androidx.compose.ui.window.WindowPlacement
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.swing.Swing
import java.awt.Dimension

fun main()  {
    runBlocking(Dispatchers.Swing) {
        val window = ComposeWindow()
        window.size = Dimension(200, 200)
        window.placement = WindowPlacement.Fullscreen
        window.isVisible = true
        delay(500)
        window.placement = WindowPlacement.Maximized
        println(window.placement)
        window.isVisible = false
    }
}

Prints Fullscreen, but should print Maximized.

It is because we don't update _isFullscreen inside org.jetbrains.skiko.FullscreenAdapter, when we change extendedState in Compose.

m-sasha commented 1 year ago

This seems to be reasonably fixed by clearing the isFullscreen flag from ComposeWindow:

    var placement: WindowPlacement
        get() = when {
            isFullscreen -> WindowPlacement.Fullscreen
            isMaximized -> WindowPlacement.Maximized
            else -> WindowPlacement.Floating
        }
        set(value) {
            when (value) {
                WindowPlacement.Fullscreen -> {
                    isMaximized = false
                    isFullscreen = true
                }
                WindowPlacement.Maximized -> {
                    isFullscreen = false
                    isMaximized = true
                }
                WindowPlacement.Floating -> {
                    isFullscreen = false
                    isMaximized = false
                }
            }
        }
okushnikov commented 2 weeks ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.