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

[Ubuntu 20.04] WindowEvents.onMaximize is never called #965

Closed
arkivanov opened this issue Aug 1, 2021 · 5 comments
Closed

[Ubuntu 20.04] WindowEvents.onMaximize is never called #965

arkivanov opened this issue Aug 1, 2021 · 5 comments
Assignees
Labels
desktop enhancement New feature or request linux

Comments

@arkivanov
Copy link
Contributor

arkivanov commented Aug 1, 2021

If I pass WindowEvents.onMaximize to the main Window, it is never called.

    Window(
        title = "Example",
        events = WindowEvents(
            onMaximize = { println("onMaximize") },
        )
    ) {
        // Some content here
    }

I tried to minimize/maximize/restore the window, no output in the console.

Also maybe unrelated, but KDoc says about WindowEvents.onRestore the following:

@param onRestore The event that is invoked when the window is restored after the window has been maximized or minimized.

Currently on my machine it is called only when the window's state is changed from minimized to normal. It is not called when the window is de-maximized. So it seems, either the KDoc is incorrect or there is a bug.

@acousticksan
Copy link

Have you tried the new Windows API?

fun main() = application {
    val windowState = rememberWindowState()
     Window(
        onCloseRequest = ::exitApplication,
        state = windowState,
    ) {
            LaunchedEffect(windowState){
                snapshotFlow { windowState.placement }
                  .onEach {
                      if (it == WindowPlacement.Maximized){
                          println("onMaximize")
                      }
                  }
                .launchIn(this)
        }
    }
}    

@arkivanov
Copy link
Contributor Author

Checked the new API, it works fine

@arkivanov
Copy link
Contributor Author

However I could not find any replacement for onFocusGet and onFocusLost events.

@igordmn
Copy link
Collaborator

igordmn commented Aug 1, 2021

However I could not find any replacement for onFocusGet and onFocusLost events.

Unfortunately, we haven't implemented it for the new API yet (but we plan to). As a temporary workaround, you can use Swing interop:

import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.window.singleWindowApplication
import java.awt.event.FocusEvent
import java.awt.event.FocusListener

fun main() = singleWindowApplication {
    DisposableEffect(Unit) {
        window.addWindowFocusListener(object : WindowFocusListener {
            override fun windowGainedFocus(e: WindowEvent) {
            }

            override fun windowLostFocus(e: WindowEvent) {
            }
        })
        onDispose {}
    }
}

@igordmn
Copy link
Collaborator

igordmn commented Nov 2, 2021

Let's move requestFocus/isFocused to another issue

@igordmn igordmn closed this as completed Nov 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
desktop enhancement New feature or request linux
Projects
None yet
Development

No branches or pull requests

4 participants