From 34b7062948757868c931fc04fc90c89bfa9400fd Mon Sep 17 00:00:00 2001 From: Ivan Morgillo Date: Mon, 20 Jan 2025 14:17:10 +0100 Subject: [PATCH] [jewel] Bugfix decorated window on windows Reference https://github.com/JetBrains/jewel/pull/731 closes https://github.com/JetBrains/intellij-community/pull/2920 (cherry picked from commit 61be2b8b30ef3417937e0966b7f2e2d5082542ed) (cherry picked from commit 97ce6439aa53ec5c13241e3607508ab8b378929d) IJ-MR-155570 GitOrigin-RevId: 1f8fdb352c6cbac72d7e22fd9e4ce8624ee5281d --- .../decorated-window/api-dump-unreviewed.txt | 4 ++ .../decorated-window/api/decorated-window.api | 7 ++++ .../jewel/window/TitleBar.Windows.kt | 5 ++- .../org/jetbrains/jewel/window/TitleBar.kt | 40 +++++++++++-------- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/platform/jewel/decorated-window/api-dump-unreviewed.txt b/platform/jewel/decorated-window/api-dump-unreviewed.txt index 6a8dbae28396..6168210e9074 100644 --- a/platform/jewel/decorated-window/api-dump-unreviewed.txt +++ b/platform/jewel/decorated-window/api-dump-unreviewed.txt @@ -35,6 +35,10 @@ com.jetbrains.WindowDecorations$CustomTitleBar - a:setHeight(F):V com.jetbrains.WindowMove - a:startMovingTogetherWithMouse(java.awt.Window,I):V +f:org.jetbrains.jewel.window.ComposableSingletons$TitleBarKt +- sf:INSTANCE:org.jetbrains.jewel.window.ComposableSingletons$TitleBarKt +- ():V +- f:getLambda-1$intellij_platform_jewel_decoratedWindow():kotlin.jvm.functions.Function2 f:org.jetbrains.jewel.window.DecoratedWindowKt - sf:DecoratedWindow(kotlin.jvm.functions.Function0,androidx.compose.ui.window.WindowState,Z,java.lang.String,androidx.compose.ui.graphics.painter.Painter,Z,Z,Z,Z,kotlin.jvm.functions.Function1,kotlin.jvm.functions.Function1,org.jetbrains.jewel.window.styling.DecoratedWindowStyle,kotlin.jvm.functions.Function3,androidx.compose.runtime.Composer,I,I,I):V org.jetbrains.jewel.window.DecoratedWindowScope diff --git a/platform/jewel/decorated-window/api/decorated-window.api b/platform/jewel/decorated-window/api/decorated-window.api index 8e469e0d85a9..c0502f19e4c1 100644 --- a/platform/jewel/decorated-window/api/decorated-window.api +++ b/platform/jewel/decorated-window/api/decorated-window.api @@ -49,6 +49,13 @@ public abstract interface class com/jetbrains/WindowMove { public abstract fun startMovingTogetherWithMouse (Ljava/awt/Window;I)V } +public final class org/jetbrains/jewel/window/ComposableSingletons$TitleBarKt { + public static final field INSTANCE Lorg/jetbrains/jewel/window/ComposableSingletons$TitleBarKt; + public static field lambda-1 Lkotlin/jvm/functions/Function2; + public fun ()V + public final fun getLambda-1$decorated_window ()Lkotlin/jvm/functions/Function2; +} + public final class org/jetbrains/jewel/window/DecoratedWindowKt { public static final fun DecoratedWindow (Lkotlin/jvm/functions/Function0;Landroidx/compose/ui/window/WindowState;ZLjava/lang/String;Landroidx/compose/ui/graphics/painter/Painter;ZZZZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lorg/jetbrains/jewel/window/styling/DecoratedWindowStyle;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;III)V } diff --git a/platform/jewel/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.Windows.kt b/platform/jewel/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.Windows.kt index e342f36baead..a25acea21b5c 100644 --- a/platform/jewel/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.Windows.kt +++ b/platform/jewel/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.Windows.kt @@ -1,6 +1,8 @@ package org.jetbrains.jewel.window import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Modifier @@ -27,7 +29,7 @@ internal fun DecoratedWindowScope.TitleBarOnWindows( val titleBar = remember { JBR.getWindowDecorations().createCustomTitleBar() } TitleBarImpl( - modifier = modifier.customTitleBarMouseEventHandler(titleBar), + modifier = modifier, gradientStartColor = gradientStartColor, style = style, applyTitleBar = { height, _ -> @@ -36,6 +38,7 @@ internal fun DecoratedWindowScope.TitleBarOnWindows( JBR.getWindowDecorations().setCustomTitleBar(window, titleBar) PaddingValues(start = titleBar.leftInset.dp, end = titleBar.rightInset.dp) }, + backgroundContent = { Spacer(modifier = modifier.fillMaxSize().customTitleBarMouseEventHandler(titleBar)) }, content = content, ) } diff --git a/platform/jewel/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.kt b/platform/jewel/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.kt index 8a84e264cb36..41b60c305d86 100644 --- a/platform/jewel/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.kt +++ b/platform/jewel/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.kt @@ -1,8 +1,10 @@ package org.jetbrains.jewel.window import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.runtime.Composable @@ -77,6 +79,7 @@ internal fun DecoratedWindowScope.TitleBarImpl( gradientStartColor: Color = Color.Unspecified, style: TitleBarStyle = JewelTheme.defaultTitleBarStyle, applyTitleBar: (Dp, DecoratedWindowState) -> PaddingValues, + backgroundContent: @Composable () -> Unit = {}, content: @Composable TitleBarScope.(DecoratedWindowState) -> Unit, ) { val titleBarInfo = LocalTitleBarInfo.current @@ -102,19 +105,7 @@ internal fun DecoratedWindowScope.TitleBarImpl( } } - Layout( - content = { - CompositionLocalProvider( - LocalContentColor provides style.colors.content, - LocalIconButtonStyle provides style.iconButtonStyle, - LocalDefaultDropdownStyle provides style.dropdownStyle, - ) { - OverrideDarkMode(background.isDark()) { - val scope = TitleBarScopeImpl(titleBarInfo.title, titleBarInfo.icon) - scope.content(state) - } - } - }, + Box( modifier = modifier .background(backgroundBrush) @@ -122,9 +113,26 @@ internal fun DecoratedWindowScope.TitleBarImpl( .layoutId(TITLE_BAR_LAYOUT_ID) .height(style.metrics.height) .onSizeChanged { with(density) { applyTitleBar(it.height.toDp(), state) } } - .fillMaxWidth(), - measurePolicy = rememberTitleBarMeasurePolicy(window, state, applyTitleBar), - ) + .fillMaxWidth() + ) { + backgroundContent() + Layout( + content = { + CompositionLocalProvider( + LocalContentColor provides style.colors.content, + LocalIconButtonStyle provides style.iconButtonStyle, + LocalDefaultDropdownStyle provides style.dropdownStyle, + ) { + OverrideDarkMode(background.isDark()) { + val scope = TitleBarScopeImpl(titleBarInfo.title, titleBarInfo.icon) + scope.content(state) + } + } + }, + modifier = modifier.fillMaxSize(), + measurePolicy = rememberTitleBarMeasurePolicy(window, state, applyTitleBar), + ) + } Spacer(Modifier.layoutId(TITLE_BAR_BORDER_LAYOUT_ID).height(1.dp).fillMaxWidth().background(style.colors.border)) }