Просмотр исходного кода

backgrond main window

backgrond main window
milan jurkulák 2 лет назад
Родитель
Сommit
7e476b4a79

+ 6 - 4
src/main/kotlin/eu/mjdev/desktop/windows/ChromeWindow.kt

@@ -30,7 +30,7 @@ fun ChromeWindow(
     onCloseRequest: () -> Unit = {},
     onPreviewKeyEvent: (KeyEvent) -> Boolean = { false },
     onKeyEvent: (KeyEvent) -> Boolean = { false },
-    onFocusChange: (Boolean) -> Unit = {},
+    onFocusChange: ChromeWindowState.(Boolean) -> Unit = {},
     onOpened: () -> Unit = {},
     onClosed: () -> Unit = {},
     content: @Composable ChromeWindowScope.() -> Unit = {}
@@ -68,7 +68,7 @@ fun ChromeWindow(
     onCloseRequest: () -> Unit = {},
     onPreviewKeyEvent: (KeyEvent) -> Boolean = { false },
     onKeyEvent: (KeyEvent) -> Boolean = { false },
-    onFocusChange: (Boolean) -> Unit = {},
+    onFocusChange: ChromeWindowState.(Boolean) -> Unit = {},
     onOpened: () -> Unit = {},
     onClosed: () -> Unit = {},
     content: @Composable ChromeWindowScope.() -> Unit = {}
@@ -105,7 +105,7 @@ fun ChromeWindow(
     onCloseRequest: () -> Unit = {},
     onPreviewKeyEvent: (KeyEvent) -> Boolean = { false },
     onKeyEvent: (KeyEvent) -> Boolean = { false },
-    onFocusChange: (Boolean) -> Unit = {},
+    onFocusChange: ChromeWindowState.(Boolean) -> Unit = {},
     onOpened: () -> Unit = {},
     onClosed: () -> Unit = {},
     content: @Composable ChromeWindowScope.() -> Unit = {}
@@ -113,7 +113,9 @@ fun ChromeWindow(
     val animState = rememberAnimState(visible)
     val wnState = rememberWnState()
     windowState.onOpened.add {
-        windowState.requestFocus()
+        if (focusable) {
+            windowState.requestFocus()
+        }
         windowState.updatePositionAndSize()
         if (visible) {
             animState.value.targetState = true

+ 5 - 2
src/main/kotlin/eu/mjdev/desktop/windows/ChromeWindowState.kt

@@ -17,13 +17,13 @@ class ChromeWindowState(
     closeAction: WindowCloseAction,
 ) : WindowState {
 
-    var onFocusChange: MutableList<(focus: Boolean) -> Unit> = mutableStateListOf()
+    var onFocusChange: MutableList<ChromeWindowState.(focus: Boolean) -> Unit> = mutableStateListOf()
     var onOpened: MutableList<() -> Unit> = mutableStateListOf()
     var onClosed: MutableList<() -> Unit> = mutableStateListOf()
 
     val focusHelper: WindowFocusHelper = WindowFocusHelper { _, focus ->
         this@ChromeWindowState.onFocusChange.forEach {
-            it.invoke(focus)
+            it.invoke(this@ChromeWindowState, focus)
         }
     }
 
@@ -38,6 +38,9 @@ class ChromeWindowState(
         }
     })
 
+    val window
+        get() = stateHelper.window
+
     @Suppress("CanBePrimaryConstructorProperty")
     val closeAction: WindowCloseAction = closeAction
 

+ 6 - 3
src/main/kotlin/eu/mjdev/desktop/windows/FullScreenWindow.kt

@@ -12,6 +12,8 @@ import eu.mjdev.desktop.windows.ChromeWindowState.Companion.rememberChromeWindow
 @Composable
 fun FullScreenWindow(
     api: DesktopProvider = LocalDesktop.current,
+    enabled: Boolean = true,
+    focusable: Boolean = true,
     onCloseRequest: () -> Unit = {},
     onPreviewKeyEvent: (KeyEvent) -> Boolean = { false },
     onKeyEvent: (KeyEvent) -> Boolean = { false },
@@ -20,18 +22,19 @@ fun FullScreenWindow(
         size = api.containerSize,
         position = WindowPosition.Aligned(Alignment.Center)
     ),
+    onFocusChange: ChromeWindowState.(Boolean) -> Unit = {},
     content: @Composable ChromeWindowScope.() -> Unit = {}
 ) = ChromeWindow(
     windowState = windowState,
+    enabled = enabled,
     resizable = false,
     transparent = true,
+    focusable = focusable,
     visible = true,
-    focusable = false,
     alwaysOnTop = false,
     onPreviewKeyEvent = onPreviewKeyEvent,
     onKeyEvent = onKeyEvent,
     onCloseRequest = onCloseRequest,
-    onFocusChange = {
-    },
+    onFocusChange = onFocusChange,
     content = content
 )

+ 6 - 1
src/main/kotlin/eu/mjdev/desktop/windows/MainWindow.kt

@@ -34,7 +34,12 @@ fun MainWindow(
 //    onDesktopMenuShow: () -> Unit = {},
     contextMenuState: ContextMenuState = rememberContextMenuState("item1", "item2"),
     content: @Composable BoxScope.() -> Unit = {}
-) = FullScreenWindow {
+) = FullScreenWindow(
+    onFocusChange = {
+        // todo better solution
+        window?.toBack()
+    }
+) {
     Box(
         modifier = Modifier
             .fillMaxSize()

+ 0 - 4
src/main/kotlin/eu/mjdev/desktop/windows/WindowFocusHelper.kt

@@ -24,10 +24,6 @@ class WindowFocusHelper(
         window.removeWindowStateListener(this)
     }
 
-    fun requestFocus() {
-        window?.requestFocus()
-    }
-
     override fun windowGainedFocus(e: WindowEvent?) {
         onFocusChange(window, true)
     }