Skip to content

Commit

Permalink
feat: library updates and removed refl/introspection for Skia (#33)
Browse files Browse the repository at this point in the history
* feat: library updates and removed refl/introspection for Skia

* chore: removed unused properties
  • Loading branch information
alexfacciorusso authored Sep 16, 2023
1 parent 4090e1c commit 74e14eb
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 35 deletions.
2 changes: 0 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
kotlin.code.style=official
kotlin.version=1.6.10
compose.version=1.1.1
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
kotlin = "1.7.20"
compose = "1.2.2"
kotlin = "1.9.10"
compose = "1.5.1"

jna = "5.13.0"

Expand Down
1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pluginManagement {
repositories {
google()
gradlePluginPortal()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
Expand Down
6 changes: 2 additions & 4 deletions window-styler-demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ plugins {
}

kotlin {
jvm {
compilations.all {
kotlinOptions.jvmTarget = "11"
}
jvmToolchain(17)

jvm {
withJava()
}

Expand Down
5 changes: 1 addition & 4 deletions window-styler/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ group = extra["GROUP"] as String
version = extra["VERSION_NAME"] as String

kotlin {
jvmToolchain(17)
jvm {
compilations.all {
kotlinOptions.jvmTarget = "11"
}

withJava()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ package com.mayakapps.compose.windowstyler

import androidx.compose.ui.awt.ComposeWindow
import org.jetbrains.skiko.SkiaLayer
import java.awt.*
import java.awt.BorderLayout
import java.awt.Color
import java.awt.Component
import java.awt.Container
import java.awt.Frame
import java.awt.Window
import javax.swing.JComponent
import javax.swing.JDialog
import javax.swing.JWindow

internal fun ComposeWindow.setComposeLayerTransparency(isTransparent: Boolean) {
skiaLayer.transparency = isTransparent
findSkiaLayer()?.transparency = isTransparent
}

internal fun Window.hackContentPane() {
Expand All @@ -30,17 +35,24 @@ internal fun Window.hackContentPane() {
contentPane = newContentPane
}

private fun <T : JComponent> findComponent(
container: Container,
klass: Class<T>,
): T? {
val componentSequence = container.components.asSequence()
return componentSequence.filter { klass.isInstance(it) }.ifEmpty {
componentSequence.filterIsInstance<Container>()
.mapNotNull { findComponent(it, klass) }
}.map { klass.cast(it) }.firstOrNull()
}

internal val ComposeWindow.skiaLayer: SkiaLayer
get() {
val delegate = delegateField.get(this)
val layer = getLayerMethod.invoke(delegate)
return getComponentMethod.invoke(layer) as SkiaLayer
}
private inline fun <reified T : JComponent> Container.findComponent() = findComponent(this, T::class.java)

fun ComposeWindow.findSkiaLayer(): SkiaLayer? = findComponent<SkiaLayer>()

internal val Window.isTransparent
get() = when (this) {
is ComposeWindow -> skiaLayer.transparency
is ComposeWindow -> findSkiaLayer()?.transparency ?: false
else -> background.alpha != 255
}

Expand All @@ -51,16 +63,3 @@ internal val Window.isUndecorated
is JWindow -> true
else -> false
}


private val delegateField by lazy {
ComposeWindow::class.java.getDeclaredField("delegate").apply { isAccessible = true }
}

private val getLayerMethod by lazy {
delegateField.type.getDeclaredMethod("getLayer").apply { isAccessible = true }
}

private val getComponentMethod by lazy {
getLayerMethod.returnType.getDeclaredMethod("getComponent")
}

0 comments on commit 74e14eb

Please sign in to comment.