diff --git a/CHANGELOG.md b/CHANGELOG.md index a763a32..0bb8571 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ ## [Unreleased] +## [1.0.4] - 2023-10-25 +### Changed +- Improve MacOS support + + ## [1.0.3] - 2023-07-28 ### Changed - Improve Linux support diff --git a/gradle.properties b/gradle.properties index a9e73f4..6c4bc27 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ pluginGroup = com.github.siropkin.kursor pluginName = Kursor pluginRepositoryUrl = https://github.com/siropkin/kursor # SemVer format -> https://semver.org -pluginVersion = 1.0.3 +pluginVersion = 1.0.4 # Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html pluginSinceBuild = 221 diff --git a/src/main/kotlin/com/github/siropkin/kursor/Kursor.kt b/src/main/kotlin/com/github/siropkin/kursor/Kursor.kt index fba0685..f40b729 100644 --- a/src/main/kotlin/com/github/siropkin/kursor/Kursor.kt +++ b/src/main/kotlin/com/github/siropkin/kursor/Kursor.kt @@ -71,7 +71,7 @@ class Kursor(private var editor: Editor): JComponent(), ComponentListener, Caret } } - private fun getUbuntuKeyboardLayout(): String { + private fun getLinuxUbuntuKeyboardLayout(): String { val commandOutput = executeNativeCommand("gsettings get org.gnome.desktop.input-sources mru-sources") return commandOutput .substringAfter("('xkb', '") @@ -79,7 +79,7 @@ class Kursor(private var editor: Editor): JComponent(), ComponentListener, Caret .substring(0, 2) } - private fun getNonUbuntuKeyboardLayouts(): List { + private fun getLinuxNonUbuntuKeyboardLayouts(): List { if (linuxKeyboardLayouts.isNotEmpty()) { return linuxKeyboardLayouts } @@ -91,7 +91,7 @@ class Kursor(private var editor: Editor): JComponent(), ComponentListener, Caret return linuxKeyboardLayouts } - private fun getNonUbuntuKeyboardLayoutIndex(): Int { + private fun getLinuxNonUbuntuKeyboardLayoutIndex(): Int { return executeNativeCommand("xset -q") .substringAfter("LED mask:") .substringBefore("\n") @@ -100,26 +100,33 @@ class Kursor(private var editor: Editor): JComponent(), ComponentListener, Caret .toInt(16) } - private fun getNonUbuntuKeyboardLayout(): String { - val linuxKeyboardLayouts = getNonUbuntuKeyboardLayouts() - val linuxCurrentKeyboardLayoutIndex = getNonUbuntuKeyboardLayoutIndex() + private fun getLinuxNonUbuntuKeyboardLayout(): String { + val linuxKeyboardLayouts = getLinuxNonUbuntuKeyboardLayouts() + val linuxCurrentKeyboardLayoutIndex = getLinuxNonUbuntuKeyboardLayoutIndex() return linuxKeyboardLayouts[linuxCurrentKeyboardLayoutIndex] } + private fun getOtherOsKeyboardLayout(): String { + // if locale in format _US_UserDefined_252 then we need to take the first two letters without _ symbol + // otherwise we are expecting the locale in format en_US and taking the first two letters + val locale = InputContext.getInstance().locale.toString() + if (locale.startsWith("_")) { + return locale.substring(1, 3) + } + return locale.substring(0, 2) + } + private fun getKeyboardLayout(): String { // This is not the ideal solution because it involves executing a shell command to know the current keyboard layout // which might affect the performance. And we have different commands for different Linux distributions. // But it is the only solution I found that works on Linux. var language = when (os) { "linux" -> when (linuxDistribution) { - "ubuntu" -> getUbuntuKeyboardLayout() - else -> getNonUbuntuKeyboardLayout() + "ubuntu" -> getLinuxUbuntuKeyboardLayout() + else -> getLinuxNonUbuntuKeyboardLayout() } - else -> InputContext.getInstance() - .locale - .toString() - .substring(0, 2) - } + else -> getOtherOsKeyboardLayout() + }.lowercase() if (language == "us") { language = "en" } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index ca486c2..c1b3d83 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -11,6 +11,11 @@ ]]> + ++++++++++++++++++
+ - Improve MacOS support
+
+
1.0.3 (2023-07-28)
++++++++++++++++++
- Improve Linux support