Konsole
XKB.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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
00056
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