2 Originally comes from NumLockX http://dforce.sh.charactervut.characterz/~seli/en/numlockx
6 Copyright 2000-2001 Lubos Lunak <l.lunak@kde.org>
7 Copyright 2001 Oswald Buddenhagen <ossi@kde.org>
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the "Software"),
11 to deal in the Software without restriction, including without limitation
12 the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so, subject to the following conditions:
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
27 ****************************************************************************/
29 #include <config-konsole.h>
32 #include <QtGui/QX11Info>
37 #define explicit myexplicit
38 #include <X11/XKBlib.h>
41 #include <X11/keysym.h>
43 /* the XKB stuff is based on code created by Oswald Buddenhagen <ossi@kde.org> */
46 int xkb_opcode
, xkb_event
, xkb_error
;
47 int xkb_lmaj
= XkbMajorVersion
;
48 int xkb_lmin
= XkbMinorVersion
;
49 return XkbLibraryVersion( &xkb_lmaj
, &xkb_lmin
)
50 && XkbQueryExtension( QX11Info::display(), &xkb_opcode
, &xkb_event
, &xkb_error
,
51 &xkb_lmaj
, &xkb_lmin
);
55 // This method doesn't work in all cases. The atom "ScrollLock" doesn't seem
56 // to exist on all XFree versions (at least it's not here with my 3.3.6) - DF
57 static unsigned int xkb_mask_modifier( XkbDescPtr xkb
, const char *name
)
60 if( !xkb
|| !xkb
->names
)
63 Atom atom
= XInternAtom( xkb
->dpy
, name
, true );
68 i
< XkbNumVirtualMods
;
71 if (atom
== xkb
->names
->vmods
[i
] )
74 XkbVirtualModsToReal( xkb
, 1 << i
, &mask
);
81 static unsigned int xkb_scrolllock_mask()
84 if(( xkb
= XkbGetKeyboard( QX11Info::display(), XkbAllComponentsMask
, XkbUseCoreKbd
)) != NULL
)
86 unsigned int mask
= xkb_mask_modifier( xkb
, "ScrollLock" );
87 XkbFreeKeyboard( xkb
, 0, True
);
94 unsigned int xkb_scrolllock_mask()
96 int scrolllock_mask
= 0;
97 XModifierKeymap
* map
= XGetModifierMapping( QX11Info::display() );
98 KeyCode scrolllock_keycode
= XKeysymToKeycode( QX11Info::display(), XK_Scroll_Lock
);
99 if( scrolllock_keycode
== NoSymbol
) {
100 XFreeModifiermap(map
);
107 if( map
->modifiermap
[ map
->max_keypermod
* i
] == scrolllock_keycode
)
108 scrolllock_mask
+= 1 << i
;
111 XFreeModifiermap(map
);
112 return scrolllock_mask
;
117 unsigned int scrolllock_mask
= 0;
121 if (!scrolllock_mask
)
125 scrolllock_mask
= xkb_scrolllock_mask();
126 if( scrolllock_mask
== 0 )
129 XkbLockModifiers ( QX11Info::display(), XkbUseCoreKbd
, scrolllock_mask
, scrolllock_mask
);
135 if (!scrolllock_mask
)
139 scrolllock_mask
= xkb_scrolllock_mask();
140 if( scrolllock_mask
== 0 )
143 XkbLockModifiers ( QX11Info::display(), XkbUseCoreKbd
, scrolllock_mask
, 0);
147 void scrolllock_set_on()
152 void scrolllock_set_off()
157 #endif // defined(HAVE_XKB)