bar-kblayout: proper tooltip with full layout name and cycle on click

This commit is contained in:
Lemmy
2026-01-21 22:51:22 -05:00
parent 291062ca63
commit 89913688b5
8 changed files with 43 additions and 4 deletions
+3 -4
View File
@@ -6,6 +6,7 @@ import Quickshell.Io
import Quickshell.Wayland
import qs.Commons
import qs.Modules.Bar.Extras
import qs.Services.Compositor
import qs.Services.Keyboard
import qs.Services.UI
import qs.Widgets
@@ -72,13 +73,11 @@ Item {
icon: root.showIcon ? "keyboard" : ""
autoHide: false // Important to be false so we can hover as long as we want
text: currentLayout
tooltipText: I18n.tr("tooltips.keyboard-layout", {
"layout": currentLayout
})
tooltipText: KeyboardLayoutService.fullLayoutName
// When icon is disabled, always show the layout text
forceOpen: !root.showIcon || root.displayMode === "forceOpen"
forceClose: root.showIcon && root.displayMode === "alwaysHide"
onClicked: {}
onClicked: CompositorService.cycleKeyboardLayout()
onRightClicked: {
var popupMenuWindow = PanelService.getPopupMenuWindow(screen);
if (popupMenuWindow) {
@@ -431,6 +431,12 @@ Singleton {
Quickshell.execDetached(["sh", "-c", "systemctl hibernate || loginctl hibernate"]);
}
function cycleKeyboardLayout() {
if (backend && backend.cycleKeyboardLayout) {
backend.cycleKeyboardLayout();
}
}
property int lockAndSuspendCheckCount: 0
function lockAndSuspend() {
+8
View File
@@ -464,4 +464,12 @@ Item {
Logger.e("HyprlandService", "Failed to logout:", e);
}
}
function cycleKeyboardLayout() {
try {
Quickshell.execDetached(["hyprctl", "switchxkblayout", "all", "next"]);
} catch (e) {
Logger.e("HyprlandService", "Failed to cycle keyboard layout:", e);
}
}
}
+4
View File
@@ -126,6 +126,10 @@ Item {
}
}
function cycleKeyboardLayout() {
Logger.w("LabwcService", "Keyboard layout cycling not supported");
}
function queryDisplayScales() {
Logger.w("LabwcService", "Display scale queries not supported via ToplevelManager");
}
+4
View File
@@ -673,4 +673,8 @@ Item {
function logout() {
Quickshell.execDetached(["mmsg", "-s", "-q"]);
}
function cycleKeyboardLayout() {
Logger.w("MangoService", "Keyboard layout cycling not supported");
}
}
+8
View File
@@ -469,4 +469,12 @@ Item {
Logger.e("NiriService", "Failed to logout:", e);
}
}
function cycleKeyboardLayout() {
try {
Quickshell.execDetached(["niri", "msg", "action", "switch-layout", "next"]);
} catch (e) {
Logger.e("NiriService", "Failed to cycle keyboard layout:", e);
}
}
}
+8
View File
@@ -377,4 +377,12 @@ Item {
Logger.e("SwayService", "Failed to logout:", e);
}
}
function cycleKeyboardLayout() {
try {
Quickshell.execDetached(["swaymsg", "input", "type:keyboard", "xkb_switch_layout", "next"]);
} catch (e) {
Logger.e("SwayService", "Failed to cycle keyboard layout:", e);
}
}
}
@@ -10,11 +10,13 @@ import qs.Services.UI
Singleton {
id: root
property string currentLayout: I18n.tr("common.unknown")
property string fullLayoutName: I18n.tr("common.unknown")
property string previousLayout: ""
property bool isInitialized: false
// Updates current layout from various format strings. Called by compositors
function setCurrentLayout(layoutString) {
root.fullLayoutName = layoutString || I18n.tr("common.unknown");
root.currentLayout = extractLayoutCode(layoutString);
}