add keyboard layout config
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import json
|
||||
import os
|
||||
import signal
|
||||
import subprocess
|
||||
@@ -12,13 +13,14 @@ gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk, Gdk, GLib
|
||||
|
||||
from nwg_panel.tools import get_config_dir, local_dir, load_json, save_json, load_string, list_outputs, check_key, \
|
||||
list_configs, update_gtk_entry, is_command, check_commands, cmd2string, eprint, temp_dir, load_shell_data
|
||||
list_configs, update_gtk_entry, is_command, check_commands, cmd2string, eprint, temp_dir, load_shell_data, hyprctl
|
||||
|
||||
from nwg_panel.__about__ import __version__
|
||||
|
||||
dir_name = os.path.dirname(__file__)
|
||||
|
||||
sway = os.getenv('SWAYSOCK') is not None
|
||||
hyprland = os.getenv("HYPRLAND_INSTANCE_SIGNATURE")
|
||||
|
||||
config_dir = get_config_dir()
|
||||
data_home = os.getenv('XDG_DATA_HOME') if os.getenv('XDG_DATA_HOME') else os.path.join(os.getenv("HOME"),
|
||||
@@ -724,6 +726,7 @@ class EditorWrapper(object):
|
||||
builder.get_object("hyprland-taskbar").set_text(voc["hyprland-taskbar"])
|
||||
builder.get_object("hyprland-workspaces").set_text(voc["hyprland-workspaces"])
|
||||
builder.get_object("brightness-slider").set_text(voc["brightness-slider"])
|
||||
builder.get_object("keyboard-layout").set_text(voc["keyboard-layout"])
|
||||
builder.get_object("executors").set_text(voc["executors"])
|
||||
builder.get_object("buttons").set_text(voc["buttons"])
|
||||
builder.get_object("menu-start").set_text(voc["menu-start"])
|
||||
@@ -751,6 +754,7 @@ class EditorWrapper(object):
|
||||
"dwl-tags",
|
||||
"hyprland-taskbar",
|
||||
"hyprland-workspaces",
|
||||
"keyboard-layout",
|
||||
"tray"
|
||||
]
|
||||
|
||||
@@ -788,6 +792,9 @@ class EditorWrapper(object):
|
||||
builder.get_object("eb-dwl-tags").connect("button-press-event", self.edit_dwl_tags)
|
||||
builder.get_object("eb-hyprland-taskbar").connect("button-press-event", self.edit_hyprland_taskbar)
|
||||
builder.get_object("eb-hyprland-workspaces").connect("button-press-event", self.edit_hyprland_workspaces)
|
||||
|
||||
builder.get_object("eb-keyboard-layout").connect("button-press-event", self.edit_keyboard_layout)
|
||||
|
||||
builder.get_object("eb-executors").connect("button-press-event", self.select_executor)
|
||||
builder.get_object("eb-buttons").connect("button-press-event", self.select_button)
|
||||
|
||||
@@ -1197,6 +1204,8 @@ class EditorWrapper(object):
|
||||
self.update_hyprland_taskbar()
|
||||
elif self.edited == "hyprland-workspaces":
|
||||
self.update_hyprland_workspaces()
|
||||
elif self.edited == "keyboard-layout":
|
||||
self.update_keyboard_layout()
|
||||
elif self.edited == "openweather":
|
||||
self.update_openweather()
|
||||
elif self.edited == "brightness-slider":
|
||||
@@ -2178,6 +2187,105 @@ class EditorWrapper(object):
|
||||
|
||||
save_json(self.config, self.file)
|
||||
|
||||
def edit_keyboard_layout(self, *args):
|
||||
self.load_panel()
|
||||
self.edited = "keyboard-layout"
|
||||
check_key(self.panel, "keyboard-layout", {})
|
||||
settings = self.panel["keyboard-layout"]
|
||||
defaults = {
|
||||
"keyboard-device-sway": "",
|
||||
"keyboard-device-hyprland": "",
|
||||
"root-css-name": "root-executor",
|
||||
"css-name": "executor",
|
||||
"show-icon": True,
|
||||
"icon-size": 16,
|
||||
"icon-placement": "left",
|
||||
"tooltip-text": "LMB: Next layout, RMB: Menu",
|
||||
"angle": 0.0
|
||||
}
|
||||
for key in defaults:
|
||||
check_key(settings, key, defaults[key])
|
||||
|
||||
builder = Gtk.Builder.new_from_file(os.path.join(dir_name, "glade/config_keyboard_layout.glade"))
|
||||
builder.get_object("lbl-device").set_text("{}:".format(voc["device"]))
|
||||
builder.get_object("lbl-tooltip-text").set_text("{}:".format(voc["tooltip-text"]))
|
||||
builder.get_object("lbl-root-css-name").set_text("{}:".format(voc["root-css-name"]))
|
||||
builder.get_object("lbl-css-name").set_text("{}:".format(voc["css-name"]))
|
||||
builder.get_object("lbl-icon-placement").set_text("{}:".format(voc["icon-placement"]))
|
||||
builder.get_object("lbl-icon-size").set_text("{}:".format(voc["icon-size"]))
|
||||
builder.get_object("show-icon").set_label("{}".format(voc["show-icon"]))
|
||||
builder.get_object("lbl-angle").set_text("{}:".format(voc["angle"]))
|
||||
|
||||
frame = builder.get_object("frame")
|
||||
frame.set_label(" {}: KeyboardLayout ".format(voc["module"]))
|
||||
|
||||
self.kl_combo_device = builder.get_object("device")
|
||||
if sway:
|
||||
from i3ipc import Connection
|
||||
i3 = Connection()
|
||||
inputs = i3.get_inputs()
|
||||
self.kl_combo_device.append("", voc["all"])
|
||||
for i in inputs:
|
||||
if i.type == "keyboard":
|
||||
self.kl_combo_device.append(i, i)
|
||||
self.kl_combo_device.set_active_id(settings["keyboard-device-sway"])
|
||||
else:
|
||||
o = hyprctl("j/devices")
|
||||
devices = json.loads(o)
|
||||
keyboards = devices["keyboards"] if "keyboards" in devices else []
|
||||
self.kl_combo_device.append("", voc["all"])
|
||||
for k in keyboards:
|
||||
self.kl_combo_device.append(k["name"], k["name"])
|
||||
self.kl_combo_device.set_active_id(settings["keyboard-device-hyprland"])
|
||||
|
||||
self.kl_tooltip_text = builder.get_object("tooltip-text")
|
||||
self.kl_tooltip_text.set_text(settings["tooltip-text"])
|
||||
|
||||
self.kl_root_css_name = builder.get_object("root-css-name")
|
||||
self.kl_root_css_name.set_text(settings["root-css-name"])
|
||||
|
||||
self.kl_css_name = builder.get_object("css-name")
|
||||
self.kl_css_name.set_text(settings["css-name"])
|
||||
|
||||
self.kl_icon_placement = builder.get_object("icon-placement")
|
||||
self.kl_icon_placement.set_active_id(settings["icon-placement"])
|
||||
|
||||
self.kl_icon_size = builder.get_object("icon-size")
|
||||
self.kl_icon_size.set_numeric(True)
|
||||
adj = Gtk.Adjustment(value=0, lower=8, upper=129, step_increment=1, page_increment=10, page_size=1)
|
||||
self.kl_icon_size.configure(adj, 1, 0)
|
||||
self.kl_icon_size.set_value(settings["icon-size"])
|
||||
|
||||
self.ws_angle = builder.get_object("angle")
|
||||
self.ws_angle.set_tooltip_text(voc["angle-tooltip"])
|
||||
self.ws_angle.set_active_id(str(settings["angle"]))
|
||||
|
||||
self.cb_show_icon = builder.get_object("show-icon")
|
||||
self.cb_show_icon.set_active(settings["show-icon"])
|
||||
|
||||
for item in self.scrolled_window.get_children():
|
||||
item.destroy()
|
||||
self.scrolled_window.add(frame)
|
||||
|
||||
def update_keyboard_layout(self):
|
||||
settings = self.panel["keyboard-layout"]
|
||||
if sway:
|
||||
settings["keyboard-device-sway"] = self.kl_combo_device.get_active_id()
|
||||
elif hyprland:
|
||||
settings["keyboard-device-hyprland"] = self.kl_combo_device.get_active_id()
|
||||
settings["tooltip-text"] = self.kl_tooltip_text.get_text()
|
||||
settings["root-css-name"] = self.kl_root_css_name.get_text()
|
||||
settings["css-name"] = self.kl_css_name.get_text()
|
||||
settings["icon-placement"] = self.kl_icon_placement.get_active_id()
|
||||
settings["icon-size"] = self.kl_icon_size.get_value()
|
||||
settings["show-icon"] = self.cb_show_icon.get_active()
|
||||
try:
|
||||
settings["angle"] = float(self.ws_angle.get_active_id())
|
||||
except:
|
||||
settings["angle"] = 0.0
|
||||
|
||||
save_json(self.config, self.file)
|
||||
|
||||
def edit_menu_start(self, *args):
|
||||
self.load_panel()
|
||||
self.edited = "menu-start"
|
||||
|
231
nwg_panel/glade/config_keyboard_layout.glade
Normal file
231
nwg_panel/glade/config_keyboard_layout.glade
Normal file
@@ -0,0 +1,231 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.40.0 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.24"/>
|
||||
<object class="GtkFrame" id="frame">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label-xalign">0.5</property>
|
||||
<property name="shadow-type">out</property>
|
||||
<child>
|
||||
<!-- n-columns=2 n-rows=10 -->
|
||||
<object class="GtkGrid" id="grid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="margin-start">6</property>
|
||||
<property name="margin-end">6</property>
|
||||
<property name="margin-top">6</property>
|
||||
<property name="margin-bottom">6</property>
|
||||
<property name="row-spacing">6</property>
|
||||
<property name="column-spacing">12</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="label" translatable="yes"><span size="small"><b>Note:</b> on sway switching lang for one keyboard device selects the same value for the others.
|
||||
Either it's a bug or I don't understand 'man sway-input' ¯\_(•_•)_/¯</span></property>
|
||||
<property name="use-markup">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">9</property>
|
||||
<property name="width">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="tooltip-text">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="lbl-tooltip-text">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="label" translatable="yes">Tooltip text:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="root-css-name">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="lbl-root-css-name">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="label" translatable="yes">Root CSS name:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="css-name">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="lbl-css-name">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="label" translatable="yes">CSS name:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBoxText" id="icon-placement">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<items>
|
||||
<item id="left" translatable="yes">left</item>
|
||||
<item id="right" translatable="yes">right</item>
|
||||
</items>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="lbl-icon-placement">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="label" translatable="yes">Icon placement:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSpinButton" id="icon-size">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">5</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="lbl-icon-size">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="label" translatable="yes">Icon size:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">5</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="show-icon">
|
||||
<property name="label" translatable="yes">Show icon</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">False</property>
|
||||
<property name="draw-indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">6</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBoxText" id="angle">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<items>
|
||||
<item id="0.0" translatable="yes">0°</item>
|
||||
<item id="90.0" translatable="yes">90°</item>
|
||||
<item id="270.0" translatable="yes">270°</item>
|
||||
</items>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">7</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="lbl-angle">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="label" translatable="yes">Angle:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">7</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="lbl-device">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="label" translatable="yes">Device:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">8</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBoxText" id="device">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">8</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child type="label">
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">Module: Executor</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
@@ -434,6 +434,29 @@
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkListBoxRow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="selectable">False</property>
|
||||
<child>
|
||||
<object class="GtkEventBox" id="eb-keyboard-layout">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="keyboard-layout">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="margin-left">6</property>
|
||||
<property name="margin-start">6</property>
|
||||
<property name="label" translatable="yes">Keyboard layout</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkListBoxRow">
|
||||
<property name="visible">True</property>
|
||||
|
@@ -253,6 +253,7 @@
|
||||
"units": "Units",
|
||||
"use-signal": "Use signal",
|
||||
"user-menu": "User menu",
|
||||
"values-in-widget":"Values in widget",
|
||||
"values-in-widget-tooltip": "Show value in the panel widget",
|
||||
"vertical-padding": "Vertical padding",
|
||||
"vertical-window-margin": "Vertical window margin",
|
||||
|
@@ -253,6 +253,7 @@
|
||||
"units": "Jednostki",
|
||||
"use-signal": "Używaj sygnału",
|
||||
"user-menu": "Menu użytkownika",
|
||||
"values-in-widget":"Wartości w widgecie",
|
||||
"values-in-widget-tooltip": "Pokazuj wartość w widgecie panelu",
|
||||
"vertical-padding": "Wypełnienie pionowe",
|
||||
"vertical-window-margin": "Pionowy margines okna",
|
||||
|
Reference in New Issue
Block a user