Skip to content

Commit

Permalink
Try to fix mouse and keyboard problems using 'window_handler', Helps #49
Browse files Browse the repository at this point in the history
  • Loading branch information
KreitinnSoftware committed Jan 4, 2025
1 parent b4ecf1b commit 9334b18
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
25 changes: 18 additions & 7 deletions app/src/main/java/com/micewine/emu/activities/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ import com.micewine.emu.utils.DriveUtils
import io.ByteWriter
import com.micewine.emu.utils.FilePathResolver
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import mslinks.LinkTargetIDList
Expand Down Expand Up @@ -604,14 +603,24 @@ class MainActivity : AppCompatActivity() {

if (!enableServices) {
lifecycleScope.launch {
val processName = if (exePath == "") "TFM.exe" else File(exePath).name
withContext(Dispatchers.IO) {
val processName = if (exePath == "") "TFM.exe" else File(exePath).name

// Wait for Wine Successfully Start and Execute Specified Program and Kill Services
while (!WineWrapper.wine("tasklist", winePrefix, true).contains(processName)) {
delay(100)
// Wait for Wine Successfully Start and Execute Specified Program and Kill Services
WineWrapper.waitFor(processName, winePrefix)

runCommand("pkill -9 services.exe", false)
}
}
}

runCommand("pkill -9 services.exe", false)
lifecycleScope.launch {
withContext(Dispatchers.IO) {
if (exePath == "") {
WineWrapper.wine("explorer /desktop=shell,$selectedResolution window_handler", winePrefix)
} else {
WineWrapper.wine("start /unix C:\\\\windows\\\\window_handler.exe", winePrefix)
}
}
}

Expand All @@ -633,6 +642,9 @@ class MainActivity : AppCompatActivity() {
}
}
else {
// Wait for window_handler
WineWrapper.waitFor("window_handler.exe", winePrefix)

WineWrapper.wine("'$exePath'", winePrefix, "'${File(exePath).parent!!}'")
}
}
Expand Down Expand Up @@ -878,7 +890,6 @@ class MainActivity : AppCompatActivity() {
WineWrapper.wine("regedit $driveC/Addons/Themes/DarkBlue/DarkBlue.reg", winePrefix)
WineWrapper.wine("reg add HKCU\\\\Software\\\\Wine\\\\X11\\ Driver /t REG_SZ /v Decorated /d N /f", winePrefix)
WineWrapper.wine("reg add HKCU\\\\Software\\\\Wine\\\\X11\\ Driver /t REG_SZ /v Managed /d N /f", winePrefix)
WineWrapper.wine("reg delete HKCU\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\ThemeManager -v DllName /f", winePrefix)
}
}

Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/com/micewine/emu/core/WineWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Build
import com.micewine.emu.core.EnvVars.getEnv
import com.micewine.emu.core.ShellLoader.runCommand
import com.micewine.emu.core.ShellLoader.runCommandWithOutput
import kotlinx.coroutines.delay
import java.io.File

object WineWrapper {
Expand All @@ -15,6 +16,12 @@ object WineWrapper {
)
}

fun waitFor(name: String, winePrefix: File) {
while (!wine("tasklist", winePrefix, true).contains(name)) {
Thread.sleep(100)
}
}

fun wine(args: String, winePrefix: File) {
runCommand(
getEnv() + "WINEPREFIX=$winePrefix $IS_BOX64 wine $args"
Expand All @@ -24,7 +31,7 @@ object WineWrapper {
fun wine(args: String, winePrefix: File, retLog: Boolean): String {
if (retLog) {
return runCommandWithOutput(
getEnv() + "WINEPREFIX=$winePrefix $IS_BOX64 wine $args"
getEnv() + "BOX64_LOG=0 WINEPREFIX=$winePrefix $IS_BOX64 wine $args"
)
}
return ""
Expand Down

0 comments on commit 9334b18

Please sign in to comment.