compose-multiplatform-core icon indicating copy to clipboard operation
compose-multiplatform-core copied to clipboard

Update `WindowInfo.containerSize` on window resize to keep it correct when window is moved between displays

Open m-sasha opened this issue 1 year ago • 0 comments

ComposeContainter currently registers the listener for window size and position on the windowContainer, which is a JLayeredPane. It ends up not being called at all when the window is resized or moved. According to @MatkovIvan, however, this is intentional and merely poorly named (e.g. onChangeWindowPosition is meant to be called when the windowContainer's position changes, not the window's).

Because of this, when a window is moved to another screen with a different density, the size we store for it in WindowInfo.containerSize isn't updated. This, in turn, causes issues with popup positioning.

This PR registers an additional size listener on the window, in order to update WindowInfo.containerSize when the window size changes. It also renames all the related listener functions.

Fixes https://github.com/JetBrains/compose-multiplatform/issues/4697 Possibly fixes additional issues where the window size was not being updated after moving it to a different screen.

Testing

Tested manually with this code:

@Composable
fun TestButton(text: String) {
    val displayHover = remember { mutableStateOf(false) }

    Column(
        modifier = Modifier
    ) {
        Button(
            onClick = {
                displayHover.value = true
            },
            modifier = Modifier.pointerHoverIcon(PointerIcon.Hand)
        ) {
            Text(text)
        }
        DropdownMenu(
            displayHover.value,
            onDismissRequest = {
                displayHover.value = false
            },
            modifier = Modifier.background(MaterialTheme.colors.background),
        ) {
            Row(Modifier.width(200.dp), horizontalArrangement = Arrangement.SpaceBetween) {
                Text(
                    text = "My tooltip",
                )
                Text(
                    text = "2 tooltip",
                )
            }

        }
    }
}

fun main() = singleWindowApplication {
    MaterialTheme {
        Box(Modifier.fillMaxSize(), contentAlignment = Alignment.TopEnd) {
            TestButton("Hello, World!")
        }
    }
}

To simulate a 2nd screen, I've used this app: https://github.com/Stengo/DeskPad and configured the 2nd screen to be of a very low resolution (such that the density is 1.0).

This could be tested by QA

Release Notes

Fixes - Desktop

  • Fix dropdown/popup positioning when a window is moved to a screen with a different density

m-sasha avatar Apr 30 '24 14:04 m-sasha