IJPL-43747 2023.2 IDE Window frame does not respect GTK Theme

GitOrigin-RevId: ce53a3ec897c0042465a58455a307aedcc4928eb
This commit is contained in:
Pavel Porvatov
2024-05-13 20:12:05 +00:00
committed by intellij-monorepo-bot
parent 41fc92978a
commit 53a511158d
10 changed files with 45 additions and 41 deletions
@@ -0,0 +1,13 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.openapi.wm.impl.customFrameDecorations
import javax.swing.JComponent
internal interface CustomFrameButtons {
var isCompactMode: Boolean
fun getContent(): JComponent
fun updateVisibility()
}
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.openapi.wm.impl.customFrameDecorations
import com.intellij.icons.AllIcons
@@ -19,10 +19,10 @@ import javax.swing.*
import javax.swing.plaf.ButtonUI
import javax.swing.plaf.basic.BasicButtonUI
internal open class CustomFrameTitleButtons(myCloseAction: Action) {
internal open class LinuxCustomFrameTitleButtons(myCloseAction: Action): CustomFrameButtons {
companion object {
fun create(closeAction: Action): CustomFrameTitleButtons {
val darculaTitleButtons = CustomFrameTitleButtons(closeAction)
fun create(closeAction: Action): CustomFrameButtons {
val darculaTitleButtons = LinuxCustomFrameTitleButtons(closeAction)
darculaTitleButtons.createChildren()
return darculaTitleButtons
}
@@ -68,7 +68,7 @@ internal open class CustomFrameTitleButtons(myCloseAction: Action) {
val closeButton: JButton = createButton("Close", myCloseAction)
internal var isCompactMode: Boolean
override var isCompactMode: Boolean
set(value) {
panel.isCompactMode = value
}
@@ -94,9 +94,9 @@ internal open class CustomFrameTitleButtons(myCloseAction: Action) {
updateStyles()
}
fun getView(): JComponent = panel
override fun getContent(): JComponent = panel
open fun updateVisibility() {
override fun updateVisibility() {
}
protected fun addComponent(component: JComponent) {
@@ -6,11 +6,11 @@ import com.intellij.openapi.wm.impl.WindowButtonsConfiguration
import com.intellij.openapi.wm.impl.customFrameDecorations.style.StyleManager
import javax.swing.Action
internal class ResizableCustomFrameTitleButtons(closeAction: Action,
private val myRestoreAction: Action,
private val myIconifyAction: Action,
private val myMaximizeAction: Action
) : CustomFrameTitleButtons(closeAction) {
internal class LinuxResizableCustomFrameTitleButtons(closeAction: Action,
private val myRestoreAction: Action,
private val myIconifyAction: Action,
private val myMaximizeAction: Action
) : LinuxCustomFrameTitleButtons(closeAction) {
companion object {
private val restoreIcon = AllIcons.Windows.Restore
private val restoreInactiveIcon = AllIcons.Windows.RestoreInactive
@@ -24,8 +24,8 @@ internal class ResizableCustomFrameTitleButtons(closeAction: Action,
fun create(myCloseAction: Action,
myRestoreAction: Action,
myIconifyAction: Action,
myMaximizeAction: Action): ResizableCustomFrameTitleButtons {
val darculaTitleButtons = ResizableCustomFrameTitleButtons(myCloseAction, myRestoreAction, myIconifyAction, myMaximizeAction)
myMaximizeAction: Action): CustomFrameButtons {
val darculaTitleButtons = LinuxResizableCustomFrameTitleButtons(myCloseAction, myRestoreAction, myIconifyAction, myMaximizeAction)
darculaTitleButtons.createChildren()
return darculaTitleButtons
}
@@ -56,7 +56,7 @@ internal class ResizableCustomFrameTitleButtons(closeAction: Action,
}
fun fillContent(state: WindowButtonsConfiguration.State?) {
getView().removeAll()
getContent().removeAll()
val buttons: List<WindowButtonsConfiguration.WindowButton> =
state?.buttons
@@ -25,7 +25,7 @@ internal class DefaultFrameHeader(frame: JFrame, isForDockContainerProvider: Boo
val gb = GridBag().setDefaultFill(GridBagConstraints.VERTICAL).setDefaultAnchor(GridBagConstraints.WEST)
add(productIcon, gb.next())
add(customDecorationTitle.view, gb.next().fillCell().weightx(1.0))
buttonPanes?.let { add(it.getView(), gb.next().anchor(GridBagConstraints.EAST)) }
buttonPanes?.let { add(it.getContent(), gb.next().anchor(GridBagConstraints.EAST)) }
setCustomFrameTopBorder(isTopNeeded = { state != Frame.MAXIMIZED_VERT && state != Frame.MAXIMIZED_BOTH })
}
@@ -3,7 +3,8 @@ package com.intellij.openapi.wm.impl.customFrameDecorations.header
import com.intellij.openapi.util.NlsContexts
import com.intellij.openapi.wm.impl.IdeRootPane
import com.intellij.openapi.wm.impl.customFrameDecorations.CustomFrameTitleButtons
import com.intellij.openapi.wm.impl.customFrameDecorations.CustomFrameButtons
import com.intellij.openapi.wm.impl.customFrameDecorations.LinuxCustomFrameTitleButtons
import com.intellij.util.ui.GridBag
import com.intellij.util.ui.JBSwingUtilities
import com.intellij.util.ui.JBUI
@@ -31,7 +32,7 @@ internal class DialogHeader(window: Window) : CustomHeader(window) {
val gb = GridBag().setDefaultFill(GridBagConstraints.VERTICAL).setDefaultAnchor(GridBagConstraints.WEST)
add(productIcon, gb.next())
add(titleLabel, gb.next().fillCell().weightx(1.0))
createButtonsPane()?.let { add(it.getView(), gb.next().anchor(GridBagConstraints.EAST)) }
createButtonsPane()?.let { add(it.getContent(), gb.next().anchor(GridBagConstraints.EAST)) }
}
private val dragListener = object : MouseAdapter() { //passing events to OS handler to make it draggable
@@ -89,7 +90,7 @@ internal class DialogHeader(window: Window) : CustomHeader(window) {
return JBSwingUtilities.runGlobalCGTransform(this, super.getComponentGraphics(g))
}
private fun createButtonsPane(): CustomFrameTitleButtons? {
return if (IdeRootPane.hideNativeLinuxTitle) CustomFrameTitleButtons.create(createCloseAction(this)) else null
private fun createButtonsPane(): CustomFrameButtons? {
return if (IdeRootPane.hideNativeLinuxTitle) LinuxCustomFrameTitleButtons.create(createCloseAction(this)) else null
}
}
@@ -6,7 +6,8 @@ import com.intellij.icons.AllIcons
import com.intellij.ide.IdeBundle
import com.intellij.idea.ActionsBundle
import com.intellij.openapi.wm.impl.IdeRootPane
import com.intellij.openapi.wm.impl.customFrameDecorations.ResizableCustomFrameTitleButtons
import com.intellij.openapi.wm.impl.customFrameDecorations.CustomFrameButtons
import com.intellij.openapi.wm.impl.customFrameDecorations.LinuxResizableCustomFrameTitleButtons
import com.intellij.util.ui.JBFont
import java.awt.Font
import java.awt.Frame
@@ -28,7 +29,7 @@ internal open class FrameHeader(protected val frame: JFrame) : CustomHeader(fram
@Suppress("LeakingThis")
private val closeAction = createCloseAction(this)
protected val buttonPanes: ResizableCustomFrameTitleButtons? by lazy {
protected val buttonPanes: CustomFrameButtons? by lazy {
createButtonsPane()
}
@@ -95,9 +96,9 @@ internal open class FrameHeader(protected val frame: JFrame) : CustomHeader(fram
closeMenuItem.font = JBFont.label().deriveFont(Font.BOLD)
}
private fun createButtonsPane(): ResizableCustomFrameTitleButtons? {
private fun createButtonsPane(): CustomFrameButtons? {
if (IdeRootPane.hideNativeLinuxTitle) {
return ResizableCustomFrameTitleButtons.create(closeAction, restoreAction, iconifyAction, maximizeAction)
return LinuxResizableCustomFrameTitleButtons.create(closeAction, restoreAction, iconifyAction, maximizeAction)
}
return null
}
@@ -50,7 +50,7 @@ internal class MenuFrameHeader(frame: JFrame,
view.border = empty
add(view, "left, growx, gapbottom 1")
buttonPanes?.let { add(it.getView(), "right, gapbottom 1") }
buttonPanes?.let { add(it.getContent(), "right, gapbottom 1") }
setCustomFrameTopBorder({ state != Frame.MAXIMIZED_VERT && state != Frame.MAXIMIZED_BOTH }, {true})
@@ -9,6 +9,7 @@ import com.intellij.openapi.application.EDT
import com.intellij.openapi.application.ModalityState
import com.intellij.openapi.application.asContextElement
import com.intellij.openapi.wm.impl.*
import com.intellij.openapi.wm.impl.customFrameDecorations.LinuxResizableCustomFrameTitleButtons
import com.intellij.openapi.wm.impl.customFrameDecorations.header.FrameHeader
import com.intellij.openapi.wm.impl.customFrameDecorations.header.HEADER_HEIGHT_DFM
import com.intellij.openapi.wm.impl.customFrameDecorations.header.MainFrameCustomHeader
@@ -92,7 +93,7 @@ internal class ToolbarFrameHeader(private val coroutineScope: CoroutineScope,
// Skip initial call
if (currentContentState !== value) {
fillContent(value)
buttonPanes?.fillContent(value)
(buttonPanes as? LinuxResizableCustomFrameTitleButtons)?.fillContent(value)
}
}
}
@@ -181,10 +182,10 @@ internal class ToolbarFrameHeader(private val coroutineScope: CoroutineScope,
if (state == null || state.rightPosition) {
add(productIcon, gb.nextLine().next().anchor(WEST).insetLeft(H))
add(headerContent, gb.next().fillCell().anchor(GridBagConstraints.CENTER).weightx(1.0).weighty(1.0))
buttonPanes?.let { add(wrap(it.getView()), gb.next().anchor(GridBagConstraints.EAST)) }
buttonPanes?.let { add(wrap(it.getContent()), gb.next().anchor(GridBagConstraints.EAST)) }
}
else {
buttonPanes?.let { add(wrap(it.getView()), gb.nextLine().next().anchor(WEST)) }
buttonPanes?.let { add(wrap(it.getContent()), gb.nextLine().next().anchor(WEST)) }
add(headerContent, gb.next().fillCell().anchor(GridBagConstraints.CENTER).weightx(1.0).weighty(1.0))
add(productIcon, gb.next().anchor(GridBagConstraints.EAST).insets(0, H, 0, H))
}
@@ -2,7 +2,6 @@
package com.intellij.openapi.wm.impl.customFrameDecorations.style
import java.awt.Color
import java.awt.Insets
import javax.swing.Icon
import javax.swing.JComponent
import javax.swing.border.Border
@@ -28,9 +27,6 @@ internal class Properties {
var icon: Icon?
set(value) = setValue(StyleProperty.ICON, value)
get() = getValue(StyleProperty.ICON) as Icon
var margin: Insets?
set(value) = setValue(StyleProperty.MARGIN, value)
get() = getValue(StyleProperty.MARGIN) as Insets
fun setValue(prop: StyleProperty, value: Any?) {
map[prop] = value
@@ -4,7 +4,6 @@ package com.intellij.openapi.wm.impl.customFrameDecorations.style
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.diagnostic.logger
import java.awt.Color
import java.awt.Insets
import javax.swing.AbstractButton
import javax.swing.Icon
import javax.swing.JComponent
@@ -23,7 +22,7 @@ internal sealed class StyleProperty(
companion object {
fun getPropertySnapshot(component: JComponent): Properties {
val base = Properties()
for (p in arrayOf(FOREGROUND, BACKGROUND, OPAQUE, BORDER, ICON, MARGIN)) {
for (p in arrayOf(FOREGROUND, BACKGROUND, OPAQUE, BORDER, ICON)) {
if (p.componentType.isInstance(component))
base.setValue(p, p.getProperty(component))
}
@@ -68,13 +67,6 @@ internal sealed class StyleProperty(
AbstractButton::class.java
)
object MARGIN : StyleProperty(
{ component, margin -> (component as AbstractButton).margin = margin as Insets? },
{ component -> (component as AbstractButton).margin },
Insets::class.java,
AbstractButton::class.java
)
private fun checkTypes(component: JComponent, value: Any?): Boolean {
if (!componentType.isInstance(component)) {
LOG.warn("${javaClass.canonicalName} Incorrect class type: ${component.javaClass.canonicalName} instead of ${componentType.canonicalName}")