From e8208c1dfb4dcd17b1168ac2614aa8d5b761f3fd Mon Sep 17 00:00:00 2001 From: Mavridis Philippe Date: Fri, 10 Feb 2023 14:57:28 +0200 Subject: Kxkb: improve TDE Control Centre module. 1) Add conflicts check for hotkey checkboxes Due to the ability to set multiple keyboard layout switching hotkeys, it is important to inform the user of conflicting options that are not handled properly by the X.org server when set at the same time (e.g. Win+Space and Alt+Space). This change adds a warning that informs the user about the problem and the conflicting options. This warning is shown only when setting multiple hotkeys via the Xkb options tab, which is for the advanced user. Most users will ever need only one hotkey, and the combobox on the first tab should be more than enough. 2) Add "none" item to layout switching options 3) Replace Reset old options checkbox with radio buttons As per discussion, this makes the function of the option more apparent. WhatIs hints have been added for additional clarity. 4) Update hotkey combobox per server options 5) Avoid duplication of options by querying Xkb for already set options. This was a problem in Append Mode in which `setxkbmap` strings would get too long due to setting already set options. This code checks for already set options and omits them from the new `setxkbmap` call. This does not apply to Overwrite Mode. 6) Overwrite previous grp: options when using the combobox See previous commit message about the addition of hotkeys combobox. Signed-off-by: Mavridis Philippe --- kxkb/extension.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 8 deletions(-) (limited to 'kxkb/extension.cpp') diff --git a/kxkb/extension.cpp b/kxkb/extension.cpp index 1b6895043..df61e2fa2 100644 --- a/kxkb/extension.cpp +++ b/kxkb/extension.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -89,11 +90,17 @@ bool XKBExtension::setXkbOptions(const XkbOptions options) TDEProcess p; p << exe; - p << "-layout"; - p << options.layouts; - - p << "-variant"; - p << options.variants; + if (!options.layouts.isEmpty()) + { + p << "-layout"; + p << options.layouts; + } + + if (!options.variants.isEmpty()) + { + p << "-variant"; + p << options.variants; + } if (!options.model.isEmpty()) { p << "-model"; @@ -103,17 +110,50 @@ bool XKBExtension::setXkbOptions(const XkbOptions options) if (options.resetOld) { p << "-option"; } + if (!options.options.isEmpty()) { - p << "-option" << options.options; + p << "-option"; + + if (options.resetOld) + { + p << options.options; + } + else + { + // Avoid duplication of options in Append mode + TQStringList srvOptions = TQStringList::split(",", XKBExtension::getServerOptions()); + TQStringList kxkbOptions = TQStringList::split(",", options.options); + TQStringList newOptions; + for (TQStringList::Iterator it = kxkbOptions.begin(); it != kxkbOptions.end(); ++it) + { + TQString option(*it); + if (!srvOptions.contains(option)) + { + newOptions << option; + } + } + p << newOptions.join(","); + } } - kdDebug() << "[kxkb-extension] Command: " << p.args() << endl; + kdDebug() << "[setXkbOptions] Command: " << p.args() << endl; p.start(TDEProcess::Block); return p.normalExit() && (p.exitStatus() == 0); } +TQString XKBExtension::getServerOptions() +{ + XkbRF_VarDefsRec vd; + if (XkbRF_GetNamesProp(tqt_xdisplay(), nullptr, &vd) && vd.options) + { + kdDebug() << "[kxkb-extension] Got server options " << vd.options << endl; + return TQString(vd.options); + } + return TQString::null; +} + bool XKBExtension::setGroup(unsigned int group) { kdDebug() << "[kxkb-extension] Setting group " << group << endl; @@ -136,4 +176,4 @@ void XKBExtension::processXEvent(XEvent *event) { } } -#include "extension.moc" \ No newline at end of file +#include "extension.moc" -- cgit v1.2.1