diff --git a/core/src/main/kotlin/org/jetbrains/jewel/IconButton.kt b/core/src/main/kotlin/org/jetbrains/jewel/IconButton.kt index 08611bf95d..6b50384f60 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/IconButton.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/IconButton.kt @@ -76,7 +76,7 @@ fun IconButton( .border(style.metrics.borderWidth, border), contentAlignment = Alignment.Center, content = { - onBackground(backgroundColor) { + onBackground(background) { content(buttonState) } }, diff --git a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/DecoratedWindow.kt b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/DecoratedWindow.kt index 5618f00a51..67ef87a6d6 100644 --- a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/DecoratedWindow.kt +++ b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/DecoratedWindow.kt @@ -30,11 +30,14 @@ import androidx.compose.ui.window.Window import androidx.compose.ui.window.WindowPlacement import androidx.compose.ui.window.WindowState import androidx.compose.ui.window.rememberWindowState +import com.jetbrains.JBR import org.jetbrains.jewel.IntelliJTheme import org.jetbrains.jewel.foundation.Stroke import org.jetbrains.jewel.foundation.border import org.jetbrains.jewel.window.styling.DecoratedWindowStyle import org.jetbrains.jewel.window.utils.DesktopPlatform +import java.awt.event.ComponentEvent +import java.awt.event.ComponentListener import java.awt.event.WindowAdapter import java.awt.event.WindowEvent import javax.swing.JFrame @@ -54,6 +57,14 @@ import javax.swing.JFrame style: DecoratedWindowStyle = IntelliJTheme.defaultDecoratedWindowStyle, content: @Composable DecoratedWindowScope.() -> Unit, ) { + remember { + if (!JBR.isAvailable()) { + error( + "DecoratedWindow only can be used on JetBrainsRuntime(JBR) platform, please check the document https://github.com/JetBrains/jewel#int-ui-standalone-theme", + ) + } + } + // Using undecorated window for linux val undecorated = DesktopPlatform.Linux == DesktopPlatform.Current @@ -75,7 +86,7 @@ import javax.swing.JFrame var decoratedWindowState by remember { mutableStateOf(DecoratedWindowState.of(window)) } DisposableEffect(window) { - val adapter = object : WindowAdapter() { + val adapter = object : WindowAdapter(), ComponentListener { override fun windowActivated(e: WindowEvent?) { decoratedWindowState = DecoratedWindowState.of(window) } @@ -95,12 +106,27 @@ import javax.swing.JFrame override fun windowStateChanged(e: WindowEvent) { decoratedWindowState = DecoratedWindowState.of(window) } + + override fun componentResized(e: ComponentEvent?) { + decoratedWindowState = DecoratedWindowState.of(window) + } + + override fun componentMoved(e: ComponentEvent?) { + } + + override fun componentShown(e: ComponentEvent?) { + } + + override fun componentHidden(e: ComponentEvent?) { + } } window.addWindowListener(adapter) window.addWindowStateListener(adapter) + window.addComponentListener(adapter) onDispose { window.removeWindowListener(adapter) window.removeWindowStateListener(adapter) + window.removeComponentListener(adapter) } } diff --git a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.Linux.kt b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.Linux.kt index 47b40b1af6..9f40459fb6 100644 --- a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.Linux.kt +++ b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.Linux.kt @@ -12,6 +12,7 @@ import androidx.compose.ui.input.pointer.PointerButton import androidx.compose.ui.input.pointer.PointerEventPass import androidx.compose.ui.input.pointer.PointerEventType import androidx.compose.ui.input.pointer.onPointerEvent +import androidx.compose.ui.platform.LocalViewConfiguration import androidx.compose.ui.unit.dp import com.jetbrains.JBR import org.jetbrains.jewel.Icon @@ -31,11 +32,21 @@ import java.awt.event.WindowEvent style: TitleBarStyle = IntelliJTheme.defaultTitleBarStyle, content: @Composable TitleBarScope.(DecoratedWindowState) -> Unit, ) { + var lastPress = 0L + val viewConfig = LocalViewConfiguration.current TitleBarImpl( modifier.onPointerEvent(PointerEventType.Press, PointerEventPass.Main) { if (this.currentEvent.button == PointerButton.Primary) { if (this.currentEvent.changes.any { !it.isConsumed }) { - JBR.getWindowMove().startMovingTogetherWithMouse(window, MouseEvent.BUTTON1) + JBR.getWindowMove()?.startMovingTogetherWithMouse(window, MouseEvent.BUTTON1) + if (System.currentTimeMillis() - lastPress in viewConfig.doubleTapMinTimeMillis..viewConfig.doubleTapTimeoutMillis) { + if (state.isMaximized) { + window.extendedState = Frame.NORMAL + } else { + window.extendedState = Frame.MAXIMIZED_BOTH + } + } + lastPress = System.currentTimeMillis() } } }, diff --git a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/utils/macos/MacUtil.kt b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/utils/macos/MacUtil.kt index 448c49d084..0f5ba844c2 100644 --- a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/utils/macos/MacUtil.kt +++ b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/utils/macos/MacUtil.kt @@ -7,6 +7,7 @@ import java.awt.Window import java.lang.reflect.InvocationTargetException import java.util.logging.Level import java.util.logging.Logger +import javax.swing.SwingUtilities internal object MacUtil { @@ -69,22 +70,26 @@ internal object MacUtil { } fun updateColors(w: Window) { - val window = MacUtil.getWindowFromJavaWindow(w) - val delegate = Foundation.invoke(window, "delegate") - if (Foundation.invoke(delegate, "respondsToSelector:", Foundation.createSelector("updateColors")) - .booleanValue() - ) { - Foundation.invoke(delegate, "updateColors") + SwingUtilities.invokeLater { + val window = MacUtil.getWindowFromJavaWindow(w) + val delegate = Foundation.invoke(window, "delegate") + if (Foundation.invoke(delegate, "respondsToSelector:", Foundation.createSelector("updateColors")) + .booleanValue() + ) { + Foundation.invoke(delegate, "updateColors") + } } } fun updateFullScreenButtons(w: Window) { - val selector = Foundation.createSelector("updateFullScreenButtons") - val window = getWindowFromJavaWindow(w) - val delegate = Foundation.invoke(window, "delegate") + SwingUtilities.invokeLater { + val selector = Foundation.createSelector("updateFullScreenButtons") + val window = getWindowFromJavaWindow(w) + val delegate = Foundation.invoke(window, "delegate") - if (Foundation.invoke(delegate, "respondsToSelector:", selector).booleanValue()) { - Foundation.invoke(delegate, "updateFullScreenButtons") + if (Foundation.invoke(delegate, "respondsToSelector:", selector).booleanValue()) { + Foundation.invoke(delegate, "updateFullScreenButtons") + } } } } diff --git a/int-ui/int-ui-decorated-window/src/main/kotlin/org/jetbrains/jewel/intui/window/styling/IntUiTitleBarStyling.kt b/int-ui/int-ui-decorated-window/src/main/kotlin/org/jetbrains/jewel/intui/window/styling/IntUiTitleBarStyling.kt index aa753ce5fd..a617a70251 100644 --- a/int-ui/int-ui-decorated-window/src/main/kotlin/org/jetbrains/jewel/intui/window/styling/IntUiTitleBarStyling.kt +++ b/int-ui/int-ui-decorated-window/src/main/kotlin/org/jetbrains/jewel/intui/window/styling/IntUiTitleBarStyling.kt @@ -39,8 +39,13 @@ import org.jetbrains.jewel.window.styling.TitleBarStyle Color.Transparent, colors.iconButtonPressBackground, colors.iconButtonHoverBackground, + Color.Transparent, + Color.Transparent, + Color.Transparent, + Color.Transparent, + Color.Transparent, ), - IntUiIconButtonMetrics(), + IntUiIconButtonMetrics(borderWidth = 0.dp), ) } @@ -52,8 +57,13 @@ import org.jetbrains.jewel.window.styling.TitleBarStyle Color.Transparent, colors.titlePaneButtonPressBackground, colors.titlePaneButtonHoverBackground, + Color.Transparent, + Color.Transparent, + Color.Transparent, + Color.Transparent, + Color.Transparent, ), - IntUiIconButtonMetrics(CornerSize(0.dp)), + IntUiIconButtonMetrics(CornerSize(0.dp), borderWidth = 0.dp), ) } @@ -65,8 +75,13 @@ import org.jetbrains.jewel.window.styling.TitleBarStyle Color.Transparent, colors.titlePaneCloseButtonPressBackground, colors.titlePaneCloseButtonHoverBackground, + Color.Transparent, + Color.Transparent, + Color.Transparent, + Color.Transparent, + Color.Transparent, ), - IntUiIconButtonMetrics(CornerSize(0.dp)), + IntUiIconButtonMetrics(CornerSize(0.dp), borderWidth = 0.dp), ) }