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

Avoid calling Window.setVisible(true) on every AwtWindow recomposition #863

Conversation

m-sasha
Copy link
Member

@m-sasha m-sasha commented Oct 7, 2023

Currently, we're calling Window.isVisible = true on every AwtWindow recomposition, which has the unfortunate side-effect of calling Window.toFront().

Proposed Changes

Replace the SideEffect + DisposableEffect that shows/hides the window with just one

   DisposableEffect(currentVisible) {
        val showJob = GlobalScope.launch(MainUIDispatcher) {
            window().isVisible = currentVisible
        }

        onDispose {
            showJob.cancel()
        }
    }

Testing

Test: Added two unit tests: one to test that a window isn't brought to front when recomposed, and another (per @igordmn's request) that rendering in the parent window isn't blocked by a modal DialogWindow.

Issues Fixed

Fixes: JetBrains/compose-multiplatform#2994

@m-sasha m-sasha requested a review from igordmn October 7, 2023 11:25
@m-sasha m-sasha force-pushed the m-sasha/fix-window-setvisible-called-on-every-awtwindow-recomposition branch from 235dc30 to 2ff798b Compare October 7, 2023 12:02
@m-sasha m-sasha force-pushed the m-sasha/fix-window-setvisible-called-on-every-awtwindow-recomposition branch from 2ff798b to 5f161c2 Compare October 7, 2023 14:29
@m-sasha m-sasha force-pushed the m-sasha/fix-window-setvisible-called-on-every-awtwindow-recomposition branch from 5f161c2 to 3b6226b Compare October 7, 2023 17:52
@m-sasha m-sasha merged commit 6fe4bd4 into jb-main Oct 10, 2023
3 checks passed
@m-sasha m-sasha deleted the m-sasha/fix-window-setvisible-called-on-every-awtwindow-recomposition branch October 10, 2023 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Window loses its focus after recomposition of another window
2 participants