From f048605205a3c511fd865225613ab181da0152cf Mon Sep 17 00:00:00 2001 From: MFlisar Date: Sun, 15 Dec 2024 12:13:03 +0100 Subject: [PATCH 1/2] Bugfix decorated window on windows - clickable components inside title area should work now --- .../jewel/window/TitleBar.Windows.kt | 7 ++- .../org/jetbrains/jewel/window/TitleBar.kt | 51 +++++++++++-------- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.Windows.kt b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.Windows.kt index e342f36bae..efef53dea4 100644 --- a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.Windows.kt +++ b/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,9 @@ 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/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.kt b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.kt index 8a84e264cb..a5559a4187 100644 --- a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.kt +++ b/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,29 +105,33 @@ 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) + .focusProperties { canFocus = false } + .layoutId(TITLE_BAR_LAYOUT_ID) + .height(style.metrics.height) + .onSizeChanged { with(density) { applyTitleBar(it.height.toDp(), state) } } + .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 - .background(backgroundBrush) - .focusProperties { canFocus = false } - .layoutId(TITLE_BAR_LAYOUT_ID) - .height(style.metrics.height) - .onSizeChanged { with(density) { applyTitleBar(it.height.toDp(), state) } } - .fillMaxWidth(), - measurePolicy = rememberTitleBarMeasurePolicy(window, state, applyTitleBar), - ) + }, + modifier = modifier.fillMaxSize(), + measurePolicy = rememberTitleBarMeasurePolicy(window, state, applyTitleBar), + ) + } Spacer(Modifier.layoutId(TITLE_BAR_BORDER_LAYOUT_ID).height(1.dp).fillMaxWidth().background(style.colors.border)) } From d2662f55bc618f25699ccd7fb4736eb302508888 Mon Sep 17 00:00:00 2001 From: Ivan Morgillo Date: Tue, 17 Dec 2024 16:12:58 +0100 Subject: [PATCH 2/2] reformat and update API files Signed-off-by: Ivan Morgillo --- decorated-window/api/decorated-window.api | 7 +++++++ .../jetbrains/jewel/window/TitleBar.Windows.kt | 4 +--- .../kotlin/org/jetbrains/jewel/window/TitleBar.kt | 15 ++++++++------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/decorated-window/api/decorated-window.api b/decorated-window/api/decorated-window.api index d84dece450..5264dffd10 100644 --- a/decorated-window/api/decorated-window.api +++ b/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/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.Windows.kt b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.Windows.kt index efef53dea4..a25acea21b 100644 --- a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.Windows.kt +++ b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.Windows.kt @@ -38,9 +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)) - }, + backgroundContent = { Spacer(modifier = modifier.fillMaxSize().customTitleBarMouseEventHandler(titleBar)) }, content = content, ) } diff --git a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.kt b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.kt index a5559a4187..41b60c305d 100644 --- a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.kt +++ b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.kt @@ -106,13 +106,14 @@ internal fun DecoratedWindowScope.TitleBarImpl( } Box( - modifier = modifier - .background(backgroundBrush) - .focusProperties { canFocus = false } - .layoutId(TITLE_BAR_LAYOUT_ID) - .height(style.metrics.height) - .onSizeChanged { with(density) { applyTitleBar(it.height.toDp(), state) } } - .fillMaxWidth() + modifier = + modifier + .background(backgroundBrush) + .focusProperties { canFocus = false } + .layoutId(TITLE_BAR_LAYOUT_ID) + .height(style.metrics.height) + .onSizeChanged { with(density) { applyTitleBar(it.height.toDp(), state) } } + .fillMaxWidth() ) { backgroundContent() Layout(