Skip to content

Commit

Permalink
Merge pull request #50 from Danil0v3s/feat/resizable-window
Browse files Browse the repository at this point in the history
[Feat] Make settings window resizable
  • Loading branch information
Danil0v3s authored Dec 30, 2024
2 parents 921ea5a + 476bc2f commit 91167d0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ fun main(vararg args: String) = singleInstance(args) {
ProcessManager.stop()
})
} else {
}
KeyboardManager.registerKeyboardHook()
}

if (!ApplicationParams.isAutostart) {
ProcessManager.start()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package app.cleanmeter.target.desktop.ui.settings

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.IntOffset
Expand All @@ -16,13 +18,21 @@ import androidx.compose.ui.window.rememberWindowState
import app.cleanmeter.target.desktop.data.PREFERENCE_START_MINIMIZED
import app.cleanmeter.target.desktop.data.PreferencesRepository
import com.github.kwhat.jnativehook.GlobalScreen
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import java.awt.GraphicsEnvironment
import java.awt.event.ComponentAdapter
import java.awt.event.ComponentEvent
import kotlin.math.min

@Composable
fun ApplicationScope.SettingsWindow(
isDarkTheme: Boolean,
getOverlayPosition: () -> IntOffset,
onApplicationExit: () -> Unit,
) {
val maximumWindowBounds = remember { GraphicsEnvironment.getLocalGraphicsEnvironment().maximumWindowBounds.height }
val minimumHeight = remember { min(800, maximumWindowBounds) }
var isVisible by remember {
mutableStateOf(
PreferencesRepository.getPreferenceBooleanNullable(
Expand All @@ -32,7 +42,7 @@ fun ApplicationScope.SettingsWindow(
}
val icon = painterResource("imgs/logo.png")
val state = rememberWindowState().apply {
size = DpSize(650.dp, 650.dp)
size = DpSize(650.dp, minimumHeight.dp)
}

Window(
Expand All @@ -41,10 +51,25 @@ fun ApplicationScope.SettingsWindow(
icon = icon,
visible = isVisible,
title = "Clean Meter",
resizable = false,
resizable = true,
undecorated = true,
transparent = true,
) {
LaunchedEffect(state) {
snapshotFlow { state.size }
.onEach {
var size = it
if (it.width != 650.dp) {
size = it.copy(width = 650.dp)
}
if (it.height < minimumHeight.dp || it.height > maximumWindowBounds.dp ) {
size = it.copy(height = minimumHeight.dp)
}
state.size = size
}
.launchIn(this)
}

Settings(
isDarkTheme = isDarkTheme,
onCloseRequest = { isVisible = false },
Expand Down

0 comments on commit 91167d0

Please sign in to comment.