Skip to content

Commit a153352

Browse files
committed
Move transparentWindowBackgroundHack from Compose to Skiko
1 parent 9c3169a commit a153352

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

skiko/src/awtMain/kotlin/org/jetbrains/skiko/PlatformOperations.kt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,26 @@ internal val platformOperations: PlatformOperations by lazy {
129129
}
130130

131131
// OSX
132-
external private fun osxIsFullscreenNative(component: Component): Boolean
133-
external private fun osxSetFullscreenNative(component: Component, value: Boolean)
134-
external private fun osxDisableTitleBar(component: Component, headerHeight: Float)
135-
external private fun osxOrderEmojiAndSymbolsPopup()
132+
private external fun osxIsFullscreenNative(component: Component): Boolean
133+
private external fun osxSetFullscreenNative(component: Component, value: Boolean)
134+
private external fun osxDisableTitleBar(component: Component, headerHeight: Float)
135+
private external fun osxOrderEmojiAndSymbolsPopup()
136+
137+
// Transparent window hack
138+
private val TRANSPARENT_COLOR = java.awt.Color(0, 0, 0, 0)
139+
140+
/**
141+
* Returns the color that should be set as the [Window.background] for transparent windows.
142+
*
143+
* There is a hack inside OpenGL and Software redrawers for Windows that makes current
144+
* window transparent without setting `background` to JDK's window. It's done by getting native
145+
* component parent and calling `DwmEnableBlurBehindWindow`.
146+
*
147+
* FIXME: Make OpenGL work inside transparent window (background == Color(0, 0, 0, 0)) without this hack.
148+
*
149+
* See `enableTransparentWindow` (skiko/src/awtMain/cpp/windows/window_util.cc)
150+
*/
151+
fun transparentWindowBackgroundHack(renderApi: GraphicsApi): java.awt.Color? {
152+
val skikoTransparentWindowHack = hostOs == OS.Windows && renderApi != GraphicsApi.DIRECT3D
153+
return if (skikoTransparentWindowHack) null else TRANSPARENT_COLOR
154+
}

skiko/src/awtTest/kotlin/org/jetbrains/skiko/SkiaLayerTest.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,9 +1368,7 @@ class SkiaLayerTest {
13681368
layer.transparency = true
13691369
layer.background = Color(0, 0, 0, 0)
13701370
isUndecorated = true
1371-
1372-
val transparentWindowHack = (hostOs == OS.Windows) && (renderApi != GraphicsApi.DIRECT3D)
1373-
background = if (transparentWindowHack) null else Color(0, 0, 0, 0)
1371+
background = transparentWindowBackgroundHack(renderApi)
13741372
}
13751373
}
13761374

0 commit comments

Comments
 (0)