• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Konsole

XKB.cpp

Go to the documentation of this file.
00001 /*
00002  Originally comes from NumLockX http://dforce.sh.charactervut.characterz/~seli/en/numlockx
00003 
00004  NumLockX
00005  
00006  Copyright 2000-2001 Lubos Lunak        <l.lunak@kde.org>
00007  Copyright 2001      Oswald Buddenhagen <ossi@kde.org>
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a
00010 copy of this software and associated documentation files (the "Software"),
00011 to deal in the Software without restriction, including without limitation
00012 the rights to use, copy, modify, merge, publish, distribute, sublicense,
00013 and/or sell copies of the Software, and to permit persons to whom the
00014 Software is furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00022 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00024 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00025 DEALINGS IN THE SOFTWARE.
00026 
00027 ****************************************************************************/
00028 
00029 #include <config-konsole.h>
00030 
00031 #if defined(HAVE_XKB)
00032     #include <QtGui/QX11Info>
00033 
00034 
00035     #include <X11/Xlib.h>
00036 
00037     #define explicit myexplicit
00038     #include <X11/XKBlib.h>
00039     #undef explicit
00040 
00041     #include <X11/keysym.h>
00042 
00043 /* the XKB stuff is based on code created by Oswald Buddenhagen <ossi@kde.org> */
00044 int xkb_init()
00045 {
00046     int xkb_opcode, xkb_event, xkb_error;
00047     int xkb_lmaj = XkbMajorVersion;
00048     int xkb_lmin = XkbMinorVersion;
00049     return XkbLibraryVersion( &xkb_lmaj, &xkb_lmin )
00050         && XkbQueryExtension( QX11Info::display(), &xkb_opcode, &xkb_event, &xkb_error,
00051                    &xkb_lmaj, &xkb_lmin );
00052 }
00053     
00054 #if 0
00055 // This method doesn't work in all cases. The atom "ScrollLock" doesn't seem
00056 // to exist on all XFree versions (at least it's not here with my 3.3.6) - DF
00057 static unsigned int xkb_mask_modifier( XkbDescPtr xkb, const char *name )
00058 {
00059     int i;
00060     if( !xkb || !xkb->names )
00061     return 0;
00062 
00063     Atom atom = XInternAtom( xkb->dpy, name, true );
00064     if (atom == None)
00065         return 0;
00066 
00067     for( i = 0;
00068          i < XkbNumVirtualMods;
00069      i++ )
00070     {
00071     if (atom == xkb->names->vmods[i] )
00072     {
00073         unsigned int mask;
00074         XkbVirtualModsToReal( xkb, 1 << i, &mask );
00075         return mask;
00076     }
00077     }
00078     return 0;
00079 }
00080 
00081 static unsigned int xkb_scrolllock_mask()
00082 {
00083     XkbDescPtr xkb;
00084     if(( xkb = XkbGetKeyboard( QX11Info::display(), XkbAllComponentsMask, XkbUseCoreKbd )) != NULL )
00085     {
00086         unsigned int mask = xkb_mask_modifier( xkb, "ScrollLock" );
00087         XkbFreeKeyboard( xkb, 0, True );
00088         return mask;
00089     }
00090     return 0;
00091 }
00092 
00093 #else
00094 unsigned int xkb_scrolllock_mask()
00095 {
00096     int scrolllock_mask = 0;
00097     XModifierKeymap* map = XGetModifierMapping( QX11Info::display() );
00098     KeyCode scrolllock_keycode = XKeysymToKeycode( QX11Info::display(), XK_Scroll_Lock );
00099     if( scrolllock_keycode == NoSymbol ) {
00100         XFreeModifiermap(map);
00101         return 0;
00102     }
00103     for( int i = 0;
00104          i < 8;
00105          ++i )
00106         {
00107        if( map->modifiermap[ map->max_keypermod * i ] == scrolllock_keycode )
00108                scrolllock_mask += 1 << i;
00109        }
00110 
00111     XFreeModifiermap(map);
00112     return scrolllock_mask;
00113 }
00114 #endif
00115 
00116 
00117 unsigned int scrolllock_mask = 0;
00118         
00119 int xkb_set_on()
00120 {
00121     if (!scrolllock_mask)
00122     {
00123        if( !xkb_init())
00124           return 0;
00125        scrolllock_mask = xkb_scrolllock_mask();
00126        if( scrolllock_mask == 0 )
00127           return 0;
00128     }
00129     XkbLockModifiers ( QX11Info::display(), XkbUseCoreKbd, scrolllock_mask, scrolllock_mask);
00130     return 1;
00131 }
00132     
00133 int xkb_set_off()
00134 {
00135     if (!scrolllock_mask)
00136     {
00137        if( !xkb_init())
00138           return 0;
00139        scrolllock_mask = xkb_scrolllock_mask();
00140        if( scrolllock_mask == 0 )
00141           return 0;
00142     }
00143     XkbLockModifiers ( QX11Info::display(), XkbUseCoreKbd, scrolllock_mask, 0);
00144     return 1;
00145 }
00146 
00147 void scrolllock_set_on()
00148 {
00149     xkb_set_on();
00150 }
00151 
00152 void scrolllock_set_off()
00153 {
00154     xkb_set_off();
00155 }
00156 
00157 #endif // defined(HAVE_XKB)
00158 

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • Konsole
  • Libraries
  •   libkonq
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal