Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 linux fix the problem that the search window does not get the focus when you open it #1250

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.clipevery.app

import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.window.WindowState

Expand All @@ -17,6 +18,8 @@ interface AppWindowManager {

var searchWindowState: WindowState

var focusRequester: FocusRequester

val searchWindowDetailViewDpSize: DpSize

var showToken: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,18 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.focusTarget
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.focus.onFocusEvent
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.InputMode
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onKeyEvent
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalInputModeManager
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
Expand All @@ -64,6 +60,7 @@ import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Popup
import androidx.compose.ui.window.PopupProperties
import com.clipevery.LocalKoinApplication
import com.clipevery.app.AppWindowManager
import com.clipevery.clip.ClipSearchService
import com.clipevery.dao.clip.ClipType
import com.clipevery.i18n.GlobalCopywriter
Expand All @@ -85,31 +82,18 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import java.awt.event.KeyEvent

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun ClipeverySearchWindow() {
val current = LocalKoinApplication.current
val density = LocalDensity.current
val inputModeManager = LocalInputModeManager.current
val copywriter = current.koin.get<GlobalCopywriter>()
val appWindowManager = current.koin.get<AppWindowManager>()
val clipSearchService = current.koin.get<ClipSearchService>()
val appWindowManager = clipSearchService.appWindowManager
val logger = current.koin.get<KLogger>()
val focusRequester = appWindowManager.focusRequester

var lastInputTime by remember { mutableStateOf(0L) }

val focusRequester = remember { FocusRequester() }

LaunchedEffect(appWindowManager.showSearchWindow) {
if (appWindowManager.showSearchWindow) {
delay(200)
inputModeManager.requestInputMode(InputMode.Keyboard)
focusRequester.requestFocus()
} else {
focusRequester.freeFocus()
}
}

LaunchedEffect(clipSearchService.inputSearch) {
val currentTime = System.currentTimeMillis()
lastInputTime = currentTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.WindowPlacement
Expand Down Expand Up @@ -100,6 +101,8 @@ class DesktopAppWindowManager(
),
)

override var focusRequester = FocusRequester()

override val searchWindowDetailViewDpSize = DpSize(width = 500.dp, height = 240.dp)

override var showToken by mutableStateOf(false)
Expand Down Expand Up @@ -192,6 +195,11 @@ class DesktopAppWindowManager(
}

windowManager.bringToFront(SEARCH_WINDOW_TITLE)

if (!AppEnv.isTest()) {
delay(500)
focusRequester.requestFocus()
}
}

override suspend fun activeSearchWindow() {
Expand Down Expand Up @@ -226,6 +234,10 @@ class DesktopAppWindowManager(
windowManager.bringToBack(SEARCH_WINDOW_TITLE, toPaste)
}
showSearchWindow = false

if (!AppEnv.isTest()) {
focusRequester.freeFocus()
}
}

override suspend fun unActiveSearchWindow(preparePaste: suspend () -> Boolean) {
Expand Down
Loading