summaryrefslogtreecommitdiffstats
path: root/kxkb/kxkbconfig.cpp
diff options
context:
space:
mode:
authorMavridis Philippe <[email protected]>2023-01-06 15:30:57 +0200
committerMavridis Philippe <[email protected]>2023-03-24 15:28:11 +0200
commita67db2d4847d798c01d4fd7584c5bb9297e109e3 (patch)
tree6cb5bb70f6201fa62dec021b92e838d32a6036ec /kxkb/kxkbconfig.cpp
parentb50ab13974adf6f16d72f172f0cf768a44c161da (diff)
downloadtdebase-a67db2d4847d798c01d4fd7584c5bb9297e109e3.tar.gz
tdebase-a67db2d4847d798c01d4fd7584c5bb9297e109e3.zip
Kxkb: Improve layout switching
1) New layout switching approach The new approach is based on the "grp" options group of Xkb and so enables us to use predefined X11 layout (group) switching hotkeys like "Caps Lock" or "Shift+Alt" (you can see the full list in the Options tab). The added bonus to this is that we conform to the Xkb setting. The code lets Xkb handle the keyboard layout switching hotkey(s) and is similar to the one that is used in kkbswitch, monitoring for an Xkb group (layout) change event. This solution required me to remove some hacky and obsolete code which was there to support really old pre-XFree-4.2 era systems and included the "include groups" hack. This means that the "Enable latin layout" checkbox is now gone and setxkbmap is only called when the keyboard layouts and/or options are modified, and not for every layout change. 2) Common layout switching hotkeys combobox A combobox was added to the first page of the Keyboard Layouts KCM module. It provides to the users a quick way to set a layout switching key combination. It also controls the "grp" group in the Xkb tab. A special note about this combobox is that, even if Append Mode was selected in the Xkb Options tab, this hotkey will overwrite previous hotkey options. This means that all grp: options will be forced removed before applying the option from the combobox (in contrast to specifying options via the Xkb Options tab, which, in Append Mode, will not get overwritten until next login). Signed-off-by: Mavridis Philippe <[email protected]>
Diffstat (limited to 'kxkb/kxkbconfig.cpp')
-rw-r--r--kxkb/kxkbconfig.cpp81
1 files changed, 23 insertions, 58 deletions
diff --git a/kxkb/kxkbconfig.cpp b/kxkb/kxkbconfig.cpp
index 8e6890161..183709769 100644
--- a/kxkb/kxkbconfig.cpp
+++ b/kxkb/kxkbconfig.cpp
@@ -30,27 +30,14 @@ static const char* switchModes[SWITCH_POLICY_COUNT] = {
const LayoutUnit DEFAULT_LAYOUT_UNIT = LayoutUnit("us", "");
const char* DEFAULT_MODEL = "pc104";
-LayoutUnit KxkbConfig::getDefaultLayout()
-{
- if( m_layouts.size() == 0 )
- return DEFAULT_LAYOUT_UNIT;
-
- return m_layouts[0];
-}
-
bool KxkbConfig::load(int loadMode)
{
TDEConfig *config = new TDEConfig("kxkbrc", true, false);
config->setGroup("Layout");
-// Even if the layouts have been disabled we still want to set Xkb options
-// user can always switch them off now in the "Options" tab
- m_enableXkbOptions = config->readBoolEntry("EnableXkbOptions", false);
-
- if( m_enableXkbOptions == true || loadMode == LOAD_ALL ) {
+ if( loadMode == LOAD_ALL ) {
m_resetOldOptions = config->readBoolEntry("ResetOldOptions", false);
m_options = config->readEntry("Options", "");
- kdDebug() << "Xkb options (enabled=" << m_enableXkbOptions << "): " << m_options << endl;
}
m_useKxkb = config->readBoolEntry("Use", false);
@@ -81,7 +68,7 @@ bool KxkbConfig::load(int loadMode)
kdDebug() << " layout " << LayoutUnit(*it).toPair() << " in list: " << m_layouts.contains( LayoutUnit(*it) ) << endl;
}
- kdDebug() << "Found " << m_layouts.count() << " layouts, default is " << getDefaultLayout().toPair() << endl;
+ kdDebug() << "Found " << m_layouts.count() << " layouts" << endl;
TQStringList displayNamesList = config->readListEntry("DisplayNames", ',');
for(TQStringList::ConstIterator it = displayNamesList.begin(); it != displayNamesList.end() ; ++it) {
@@ -94,37 +81,6 @@ bool KxkbConfig::load(int loadMode)
}
}
-// m_includes.clear();
- if( X11Helper::areSingleGroupsSupported() ) {
- if( config->hasKey("IncludeGroups") ) {
- TQStringList includeList = config->readListEntry("IncludeGroups", ',');
- for(TQStringList::ConstIterator it = includeList.begin(); it != includeList.end() ; ++it) {
- TQStringList includePair = TQStringList::split(':', *it );
- if( includePair.count() == 2 ) {
- LayoutUnit layoutUnit( includePair[0] );
- if( m_layouts.contains( layoutUnit ) ) {
- m_layouts[m_layouts.findIndex(layoutUnit)].includeGroup = includePair[1];
- kdDebug() << "Got inc group: " << includePair[0] << ": " << includePair[1] << endl;
- }
- }
- }
- }
- else { //old includes format
- kdDebug() << "Old includes..." << endl;
- TQStringList includeList = config->readListEntry("Includes");
- for(TQStringList::ConstIterator it = includeList.begin(); it != includeList.end() ; ++it) {
- TQString layoutName = LayoutUnit::parseLayout( *it );
- LayoutUnit layoutUnit( layoutName, "" );
- kdDebug() << "old layout for inc: " << layoutUnit.toPair() << " included " << m_layouts.contains( layoutUnit ) << endl;
- if( m_layouts.contains( layoutUnit ) ) {
- TQString variantName = LayoutUnit::parseVariant(*it);
- m_layouts[m_layouts.findIndex(layoutUnit)].includeGroup = variantName;
- kdDebug() << "Got inc group: " << layoutUnit.toPair() << ": " << variantName << endl;
- }
- }
- }
- }
-
m_showSingle = config->readBoolEntry("ShowSingle", false);
m_showFlag = config->readBoolEntry("ShowFlag", true);
m_showLabel = config->readBoolEntry("ShowLabel", true);
@@ -185,12 +141,10 @@ void KxkbConfig::save()
config->writeEntry("Model", m_model);
- config->writeEntry("EnableXkbOptions", m_enableXkbOptions );
config->writeEntry("ResetOldOptions", m_resetOldOptions);
config->writeEntry("Options", m_options );
TQStringList layoutList;
- TQStringList includeList;
TQStringList displayNamesList;
TQValueList<LayoutUnit>::ConstIterator it;
@@ -199,11 +153,6 @@ void KxkbConfig::save()
layoutList.append( layoutUnit.toPair() );
- if( layoutUnit.includeGroup.isEmpty() == false ) {
- TQString incGroupUnit = TQString("%1:%2").arg(layoutUnit.toPair(), layoutUnit.includeGroup);
- includeList.append( incGroupUnit );
- }
-
TQString displayName( layoutUnit.displayName );
kdDebug() << " displayName " << layoutUnit.toPair() << " : " << displayName << endl;
if( displayName.isEmpty() == false && displayName != layoutUnit.layout ) {
@@ -215,9 +164,6 @@ void KxkbConfig::save()
config->writeEntry("LayoutList", layoutList);
kdDebug() << "Saving Layouts: " << layoutList << endl;
- config->writeEntry("IncludeGroups", includeList);
- kdDebug() << "Saving includeGroups: " << includeList << endl;
-
// if( displayNamesList.empty() == false )
config->writeEntry("DisplayNames", displayNamesList);
// else
@@ -259,7 +205,6 @@ void KxkbConfig::setDefaults()
{
m_model = DEFAULT_MODEL;
- m_enableXkbOptions = false;
m_resetOldOptions = false;
m_options = "";
@@ -321,6 +266,26 @@ TQString KxkbConfig::getDefaultDisplayName(const LayoutUnit& layoutUnit, bool si
return displayName;
}
+const XkbOptions KxkbConfig::getXkbOptions() {
+ load(LOAD_ALL);
+
+ XkbOptions options;
+ TQStringList layouts;
+ TQStringList variants;
+ for(TQValueList<LayoutUnit>::ConstIterator it = m_layouts.begin(); it != m_layouts.end(); ++it) {
+ const LayoutUnit& layoutUnit = *it;
+ layouts << layoutUnit.layout;
+ variants << layoutUnit.variant;
+ }
+ options.layouts = layouts.join(",");
+ options.variants = variants.join(",");
+ options.model = m_model;
+ options.options = m_options;
+ kdDebug() << "[getXkbOptions] options: " << m_options << endl;
+ options.resetOld = m_resetOldOptions;
+ return options;
+}
+
/**
* @brief Gets the single layout part of a layout(variant) string
* @param[in] layvar String in form layout(variant) to parse
@@ -356,4 +321,4 @@ const TQString LayoutUnit::parseVariant(const TQString &layvar)
if( pos < 2 || len < 2 )
return "";
return varLine.mid(pos+1, len-2);
-}
+} \ No newline at end of file