mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
bar-kblayout: proper tooltip with full layout name and cycle on click
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -673,4 +673,8 @@ Item {
|
||||
function logout() {
|
||||
Quickshell.execDetached(["mmsg", "-s", "-q"]);
|
||||
}
|
||||
|
||||
function cycleKeyboardLayout() {
|
||||
Logger.w("MangoService", "Keyboard layout cycling not supported");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user