[Kde-accessibility] Keyboard gestures for enabling AccessX features

Bill Haneman Bill.Haneman at Sun.COM
Wed Dec 15 19:16:21 GMT 2004


Gunnar Schmi Dt wrote:

>Hello,
>
>Attached you can find a patch that enables keyboard gestures for AccessX 
>features:
>  
>

Great!  It's really nice to make these keyboard gestures available under 
KDE by default.

I have one small nit-picky comment ;-)

>Mouse Keys: Press Alt+left Shift+Num Lock simultaneously
>  
>
This shortcut isn't actually specified by XKB/AccessX - it depends on 
the XKB keymap which is installed.  It's _often_  Alt-LeftShift-NumLock, 
but not always.

You may want to modify your documentation accordingly.  In order to know 
exactly what the MouseKeys shortcut is for your current keyboard 
description, you'll probably need to look at the XKB map. I believe 
there are two relevant pieces of information - there's a X keysym for 
XK_Mousekeys_Enable, and for cases where that keysym is not explicitly 
provided, there's a special key 'action' in the XKB actions map for 
enabling MouseKeys.

regards

Bill

>Sticky keys: Press Shift key 5 consecutive times to
>Slow keys: Hold down Shift for 8 seconds
>
>These gestures are also available under GNOME and other window managers 
>(actually they are defined by X).
>
>If there are no objections I will commit this patch tomorrow evening (so 
>that is in CVS before the freeze starts).
>
>Gunnar Schmi Dt
>
>P.S.
>Sorry for the cross-posting, but this is relevant to two mailing lists.
>  
>
>------------------------------------------------------------------------
>
>Index: kcontrol/access/kaccess.cpp
>===================================================================
>RCS file: /home/kde/kdebase/kcontrol/access/kaccess.cpp,v
>retrieving revision 1.20
>diff -u -p -r1.20 kaccess.cpp
>--- kcontrol/access/kaccess.cpp	26 Oct 2003 23:38:39 -0000	1.20
>+++ kcontrol/access/kaccess.cpp	15 Dec 2004 15:23:51 -0000
>@@ -4,11 +4,12 @@
> #include <qtimer.h>
> #include <qpainter.h>
> 
>-
>+#include <kmessagebox.h>
> #include <kdebug.h>
> #include <kaudioplayer.h>
> #include <kconfig.h>
> #include <kglobal.h>
>+#include <klocale.h>
> #include <netwm.h>
> 
> 
>@@ -46,6 +47,8 @@ KAccessApp::KAccessApp(bool allowStyles,
> 
>   artsBellTimer = new QTimer( this );
>   connect( artsBellTimer, SIGNAL( timeout() ), SLOT( slotArtsBellTimeout() ));
>+
>+  features = 0;
> }
> 
> int KAccessApp::newInstance()
>@@ -112,22 +115,21 @@ void KAccessApp::readSettings()
> 
>   // slow keys
>   if (config->readBoolEntry("SlowKeys", false))
>-    {
>-      xkb->ctrls->slow_keys_delay = config->readNumEntry("SlowKeysDelay", 500);
>       xkb->ctrls->enabled_ctrls |= XkbSlowKeysMask;
>-    }
>   else
>       xkb->ctrls->enabled_ctrls &= ~XkbSlowKeysMask;
>+  xkb->ctrls->slow_keys_delay = config->readNumEntry("SlowKeysDelay", 500);
> 
>   // bounce keys
>   if (config->readBoolEntry("BounceKeys", false))
>-    {
>-      xkb->ctrls->debounce_delay = config->readNumEntry("BounceKeysDelay", 500);
>       xkb->ctrls->enabled_ctrls |= XkbBounceKeysMask;
>-    }
>   else
>       xkb->ctrls->enabled_ctrls &= ~XkbBounceKeysMask;
>+  xkb->ctrls->debounce_delay = config->readNumEntry("BounceKeysDelay", 500);
> 
>+  // gestures for enabling the other features
>+  if (config->readBoolEntry("Gestures", true))
>+      xkb->ctrls->enabled_ctrls |= XkbAccessXKeysMask;
> 
>   // mouse-by-keyboard ----------------------------------------------
> 
>@@ -147,11 +149,18 @@ void KAccessApp::readSettings()
>   else
>     xkb->ctrls->enabled_ctrls &= ~XkbMouseKeysMask;
> 
>+   features = xkb->ctrls->enabled_ctrls & (XkbSlowKeysMask | XkbBounceKeysMask | XkbStickyKeysMask | XkbMouseKeysMask);
>   // set state
>-  XkbSetControls(qt_xdisplay(), XkbControlsEnabledMask | XkbMouseKeysAccelMask | XkbStickyKeysMask, xkb);
>+  XkbSetControls(qt_xdisplay(), XkbControlsEnabledMask | XkbMouseKeysAccelMask | XkbStickyKeysMask | XkbAccessXKeysMask, xkb);
>+
>+  // select AccessX events if we need them
>+  config->setGroup("Keyboard");
>+  bool gestures = config->readBoolEntry("Gestures", true);
>+  state = gestures ? XkbControlsNotifyMask : 0;
>+  XkbSelectEvents(qt_xdisplay(), XkbUseCoreKbd, XkbControlsNotifyMask, state);
> 
>   // reset them after program exit
>-  uint ctrls = XkbStickyKeysMask | XkbSlowKeysMask | XkbBounceKeysMask | XkbMouseKeysMask | XkbAudibleBellMask;
>+  uint ctrls = XkbStickyKeysMask | XkbSlowKeysMask | XkbBounceKeysMask | XkbMouseKeysMask | XkbAudibleBellMask | XkbControlsNotifyMask;
>   uint values = XkbAudibleBellMask;
>   XkbSetAutoResetControls(qt_xdisplay(), ctrls, &ctrls, &values);
> 
>@@ -169,6 +178,8 @@ bool KAccessApp::x11EventFilter(XEvent *
> 
>       if (ev->xkb_type == XkbBellNotify)
> 	xkbBellNotify((XkbBellNotifyEvent*)event);
>+      else if (ev->xkb_type == XkbControlsNotify)
>+	xkbControlsNotify((XkbControlsNotifyEvent*)event);
> 
>       return true;
>     }
>@@ -239,6 +250,138 @@ void KAccessApp::xkbBellNotify(XkbBellNo
>   }
> }
> 
>+void KAccessApp::xkbControlsNotify(XkbControlsNotifyEvent *event)
>+{
>+   unsigned int newFeatures = event->enabled_ctrls & (XkbSlowKeysMask | XkbBounceKeysMask | XkbStickyKeysMask | XkbMouseKeysMask);
>+   if (newFeatures != features) {
>+     unsigned int enabled  = newFeatures & ~features;
>+     unsigned int disabled = features & ~newFeatures;
>+     features = newFeatures;
>+
>+     QString message;
>+     if (disabled == 0) {
>+        switch (enabled) {
>+        case 0:
>+           message = i18n("Nothing happend?");
>+           break;
>+        case XkbSlowKeysMask:
>+           message = i18n("Slow keys is now enabled.\n"
>+           "This may be because you hold down the Shift key for 8 seconds "
>+           "or because some application has enabed this feature.\n"
>+           "You can configure slow keys and similar features in the "
>+           "Regional & Accessibility->Accessibility module of the "
>+           "KDE Control Center.\n"
>+           "To quickly disable slow keys, press the Shift key for another 8 seconds.");
>+           break;
>+        case XkbBounceKeysMask:
>+           message = i18n("Bounce keys is now enabled.\n"
>+           "This may be because some application has enabed this feature.\n"
>+           "You can configure bounce keys and similar features in the "
>+           "Regional & Accessibility->Accessibility module of the "
>+           "KDE Control Center.");
>+           break;
>+        case XkbStickyKeysMask:
>+           message = i18n("Sticky keys is now enabled.\n"
>+           "This may be because you pressed the Shift key 5 consecutive "
>+           "times or because some application has enabed this feature.\n"
>+           "You can configure sticky keys and similar features in the "
>+           "Regional & Accessibility->Accessibility module of the "
>+           "KDE Control Center.\n"
>+           "To quickly disable sticky keys, press the Shift key for another 5 times.");
>+           break;
>+        case XkbMouseKeysMask:
>+           message = i18n("Mouse keys is now enabled.\n"
>+           "This may be because you pressed Alt+left Shift+Num Lock "
>+           "or because some application has enabed this feature.\n"
>+           "You can configure sticky keys and similar features in the "
>+           "Regional & Accessibility->Accessibility module of the "
>+           "KDE Control Center.\n"
>+           "To quickly disable mouse keys, press Alt+left Shift+Num Lock again.");
>+           break;
>+        default:
>+           message = i18n("Multiple AccessX features have been enabled.\n"
>+           "This may be because some application has enabed these features.\n"
>+           "You can configure them in the "
>+           "Regional & Accessibility->Accessibility module of the "
>+           "KDE Control Center.");
>+        }
>+     }
>+     else if (enabled == 0) {
>+        switch (disabled) {
>+        case XkbSlowKeysMask:
>+           message = i18n("Slow keys is now disabled.\n"
>+           "This may be because you hold down the Shift key for 8 seconds "
>+           "or because some application has disabed this feature.\n"
>+           "You can configure slow keys and similar features in the "
>+           "Regional & Accessibility->Accessibility module of the "
>+           "KDE Control Center.");
>+           break;
>+        case XkbBounceKeysMask:
>+           message = i18n("Bounce keys is now disabled.\n"
>+           "This may be because some application has disabed this feature.\n"
>+           "You can configure bounce keys and similar features in the "
>+           "Regional & Accessibility->Accessibility module of the "
>+           "KDE Control Center.");
>+           break;
>+        case XkbStickyKeysMask:
>+           message = i18n("Sticky keys is now disabled.\n"
>+           "This may be because you pressed the Shift key 5 consecutive "
>+           "times or because some application has disabed this feature.\n"
>+           "You can configure sticky keys and similar features in the "
>+           "Regional & Accessibility->Accessibility module of the "
>+           "KDE Control Center.");
>+           break;
>+        case XkbMouseKeysMask:
>+           message = i18n("Mouse keys is now disabled.\n"
>+           "This may be because you pressed Alt+left Shift+Num Lock "
>+           "or because some application has disabed this feature.\n"
>+           "You can configure sticky keys and similar features in the "
>+           "Regional & Accessibility->Accessibility module of the "
>+           "KDE Control Center.");
>+           break;
>+        default:
>+           message = i18n("Multiple AccessX features have been disabled.\n"
>+           "This may be because some application has disabed these features.\n"
>+           "You can configure them in the "
>+           "Regional & Accessibility->Accessibility module of the "
>+           "KDE Control Center.");
>+        }
>+     }
>+     else
>+        message = i18n("Multiple AccessX features have been changed.");
>+
>+     KMessageBox::information (0, message, "Accessibility");
>+     
>+     KConfig *config = KGlobal::config();
>+
>+     config->setGroup("Keyboard");
>+
>+     if (enabled & XkbSlowKeysMask)
>+        config->writeEntry("SlowKeys", true);
>+     else if (enabled & XkbSlowKeysMask)
>+        config->writeEntry("SlowKeys", false);
>+
>+     if (enabled & XkbBounceKeysMask)
>+        config->writeEntry("BounceKeys", true);
>+     else if (enabled & XkbBounceKeysMask)
>+        config->writeEntry("BounceKeys", false);
>+
>+     if (enabled & XkbStickyKeysMask)
>+        config->writeEntry("StickyKeys", true);
>+     else if (enabled & XkbStickyKeysMask)
>+        config->writeEntry("StickyKeys", false);
>+
>+     config->setGroup("Mouse");
>+
>+     if (enabled & XkbMouseKeysMask)
>+        config->writeEntry("MouseKeys", true);
>+     else if (disabled & XkbMouseKeysMask)
>+        config->writeEntry("MouseKeys", false);
>+
>+     config->sync();
>+  }
>+}
>+
> void KAccessApp::slotArtsBellTimeout()
> {
>   _artsBellBlocked = false;
>Index: kcontrol/access/kaccess.h
>===================================================================
>RCS file: /home/kde/kdebase/kcontrol/access/kaccess.h,v
>retrieving revision 1.8
>diff -u -p -r1.8 kaccess.h
>--- kcontrol/access/kaccess.h	9 Oct 2003 12:35:59 -0000	1.8
>+++ kcontrol/access/kaccess.h	15 Dec 2004 15:23:51 -0000
>@@ -34,6 +34,7 @@ protected:
>   void readSettings();
> 
>   void xkbBellNotify(XkbBellNotifyEvent *event);
>+  void xkbControlsNotify(XkbControlsNotifyEvent *event);
> 
> 
> private slots:
>@@ -45,6 +46,7 @@ private slots:
> private:
> 
>   int xkb_opcode;
>+  unsigned int features;
> 
>   bool    _systemBell, _artsBell, _visibleBell, _visibleBellInvert;
>   bool    _artsBellBlocked;
>Index: kcontrol/access/kcmaccess.cpp
>===================================================================
>RCS file: /home/kde/kdebase/kcontrol/access/kcmaccess.cpp,v
>retrieving revision 1.38
>diff -u -p -r1.38 kcmaccess.cpp
>--- kcontrol/access/kcmaccess.cpp	22 Nov 2004 03:00:06 -0000	1.38
>+++ kcontrol/access/kcmaccess.cpp	15 Dec 2004 15:23:51 -0000
>@@ -235,6 +235,18 @@ KAccessConfig::KAccessConfig(QWidget *pa
>   bounceKeysDelay->setLabel(i18n("D&elay:"));
>   hbox->addWidget(bounceKeysDelay);
> 
>+  grp = new QGroupBox(i18n("Activation Gestures"), keys);
>+  grp->setColumnLayout( 0, Qt::Horizontal );
>+  vbox->addWidget(grp);
>+
>+  vvbox = new QVBoxLayout(grp->layout(), KDialog::spacingHint());
>+
>+  gestures = new QCheckBox(i18n("Use gestures for activating the above features"), grp);
>+  vvbox->addWidget(gestures);
>+  QWhatsThis::add( gestures, i18n("Here you can activate keyboard gestures that turn on the following features: \n"
>+  "Mouse Keys: Press Alt+left Shift+Num Lock simultaneously\n"
>+  "Sticky keys: Press Shift key 5 consecutive times\n"
>+  "Slow keys: Hold down Shift for 8 seconds") );
> 
>   connect(stickyKeys, SIGNAL(clicked()), this, SLOT(configChanged()));
>   connect(stickyKeysLock, SIGNAL(clicked()), this, SLOT(configChanged()));
>@@ -247,6 +259,8 @@ KAccessConfig::KAccessConfig(QWidget *pa
>   connect(bounceKeys, SIGNAL(clicked()), this, SLOT(configChanged()));
>   connect(bounceKeys, SIGNAL(clicked()), this, SLOT(checkAccess()));
> 
>+  connect(gestures, SIGNAL(clicked()), this, SLOT(configChanged()));
>+
>   vbox->addStretch();
> 
>   tab->addTab(keys, i18n("&Keyboard"));
>@@ -312,6 +326,7 @@ void KAccessConfig::load()
>   slowKeysDelay->setValue(config->readNumEntry("SlowKeysDelay", 500));
>   bounceKeys->setChecked(config->readBoolEntry("BounceKeys", false));
>   bounceKeysDelay->setValue(config->readNumEntry("BounceKeysDelay", 500));
>+  gestures->setChecked(config->readBoolEntry("Gestures", true));
> 
> 
>   delete config;
>@@ -349,6 +364,8 @@ void KAccessConfig::save()
> 
>   config->writeEntry("BounceKeys", bounceKeys->isChecked());
>   config->writeEntry("BounceKeysDelay", bounceKeysDelay->value());
>+  
>+  config->writeEntry("Gestures", gestures->isChecked());
> 
> 
>   config->sync();
>@@ -398,9 +415,11 @@ void KAccessConfig::defaults()
>   bounceKeys->setChecked(false);
>   bounceKeysDelay->setValue(500);
> 
>-  stickyKeys->setChecked(true);
>+  stickyKeys->setChecked(false);
>   stickyKeysLock->setChecked(true);
> 
>+  gestures->setChecked(true);
>+
>   checkAccess();
> 
>   emit changed(true);
>Index: kcontrol/access/kcmaccess.h
>===================================================================
>RCS file: /home/kde/kdebase/kcontrol/access/kcmaccess.h,v
>retrieving revision 1.7
>diff -u -p -r1.7 kcmaccess.h
>--- kcontrol/access/kcmaccess.h	18 Jul 2004 23:05:37 -0000	1.7
>+++ kcontrol/access/kcmaccess.h	15 Dec 2004 15:23:51 -0000
>@@ -59,7 +59,8 @@ private:
> 
>   QCheckBox *slowKeys, *bounceKeys;    
>   KIntNumInput *slowKeysDelay, *bounceKeysDelay;
>-
>+  
>+  QCheckBox *gestures;
> };
> 
> 
>  
>
>------------------------------------------------------------------------
>
>_______________________________________________
>kde-accessibility mailing list
>kde-accessibility at kde.org
>https://mail.kde.org/mailman/listinfo/kde-accessibility
>  
>





More information about the kde-core-devel mailing list