Skip to content

Commit

Permalink
🐛 Fix window window not having a shadow
Browse files Browse the repository at this point in the history
  • Loading branch information
guiyanakuang committed Nov 30, 2023
1 parent 5263b4d commit 75d92e3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
32 changes: 29 additions & 3 deletions composeApp/src/commonMain/kotlin/com/clipevery/ClipeveryApp.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.clipevery

import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -19,25 +20,50 @@ import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.toComposeImageBitmap
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.unit.dp
import com.clipevery.ui.AboutUI
import com.clipevery.ui.HomeUI
import com.clipevery.ui.SettingsUI
import org.koin.core.KoinApplication

@Composable
fun ClipeveryApp(koinApplication: KoinApplication) {
fun ClipeveryApp(koinApplication: KoinApplication, hideWindow: () -> Unit) {
MaterialTheme {
Box(modifier = Modifier
.background(Color.Transparent)
.pointerInput(Unit) {
detectTapGestures(
onDoubleTap = {
hideWindow()
},
onTap = {
hideWindow()
},
onLongPress = {
hideWindow()
},
onPress = {
hideWindow()
},
)
}
.clip(RoundedCornerShape(10.dp))
.fillMaxSize()
.padding(10.dp),
.padding(10.dp, 0.dp, 10.dp, 10.dp),
contentAlignment = Alignment.Center) {
Box(
modifier = Modifier
.shadow(5.dp, RoundedCornerShape(10.dp), false)
.fillMaxSize(),
.fillMaxSize()
.pointerInput(Unit) {
detectTapGestures(
onDoubleTap = {},
onTap = {},
onLongPress = {},
onPress = {},
)
},
contentAlignment = Alignment.Center
) {
Column(Modifier
Expand Down
23 changes: 1 addition & 22 deletions composeApp/src/desktopMain/kotlin/com/clipevery/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.awt.ComposeWindow
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.window.Tray
import androidx.compose.ui.window.Window
Expand Down Expand Up @@ -48,8 +47,6 @@ import kotlinx.coroutines.CoroutineScope
import org.koin.core.KoinApplication
import org.koin.core.context.GlobalContext.startKoin
import org.koin.dsl.module
import java.awt.Rectangle
import java.awt.geom.Area
import kotlin.io.path.pathString


Expand Down Expand Up @@ -123,14 +120,6 @@ fun main() = application {
) {

LaunchedEffect(Unit) {
window.addComponentListener(object : java.awt.event.ComponentAdapter() {
override fun componentResized(e: java.awt.event.ComponentEvent?) {
val currentPlatform = currentPlatform()
if (currentPlatform.isMacos()) {
setWindowShapeWithTransparentEdges(window, 10)
}
}
})
window.addWindowFocusListener(object : java.awt.event.WindowFocusListener {
override fun windowGainedFocus(e: java.awt.event.WindowEvent?) {
showWindow = true
Expand All @@ -141,16 +130,6 @@ fun main() = application {
}
})
}
ClipeveryApp(koinApplication)
ClipeveryApp(koinApplication) { showWindow = false }
}
}

fun setWindowShapeWithTransparentEdges(window: ComposeWindow, transparentHeight: Int) {
val originalRect = Rectangle(0, 0, window.width, window.height)
val area = Area(originalRect)
val topRect = Rectangle(0, 0, window.width, transparentHeight)
val bottomRect = Rectangle(0, window.height - transparentHeight, window.width, transparentHeight)
area.subtract(Area(topRect))
area.subtract(Area(bottomRect))
window.shape = area
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import java.awt.Toolkit

fun initAppUI(): AppUI {
return AppUI(
width = 440.dp,
height = 700.dp
width = 460.dp,
height = 710.dp
)
}
fun getPreferredWindowSize(appUI: AppUI): DpSize {
Expand Down

0 comments on commit 75d92e3

Please sign in to comment.