Norad
09-10-2002, 15:49
Hi :)
Ich hab da im kleinen GNOME2-Applet led_applet evtl. eine mögliche Lösung zum Tastaturauslesen gefunden. Das Dingen liegt auf led_applet-0.3.tar.gz (http://mfcn.ilo.de/led_applet/led_applet-0.3.tar.gz).
Hier mal ein paar evtl. brauchbare Zeilen:
#include <X11/XKBlib.h>
XkbSelectEvents(applet->rootwin, XkbUseCoreKbd, XkbIndicatorStateNotifyMask, XkbIndicatorStateNotifyMask)
static unsigned int
get_lockmask(LedApplet *applet)
{
int i;
unsigned int mask = 0;
XkbDescPtr xkb;
g_assert(applet);
if (!(xkb = XkbGetKeyboard(applet->rootwin, XkbAllComponentsMask, XkbUseCoreKbd)))
return 0;
if (!xkb->names)
return 0;
for(i = 0;i <= XkbNumVirtualMods;i++)
{
unsigned int tmp = 0;
char* name = NULL;
if (!xkb->names->vmods[i])
continue;
name = XGetAtomName(xkb->dpy, xkb->names->vmods[i]);
if (name)
{
if (!strcmp(name, "Caps Lock") && applet->on[CAPSLOCK])
{
XkbVirtualModsToReal(xkb, 1 << i, &tmp);
if (!tmp)
tmp = 2; /* Hack to make it work. Maybe a bug in xkb? */
}
if (!strcmp(name, "NumLock") && applet->on[NUMLOCK])
XkbVirtualModsToReal(xkb, 1 << i, &tmp);
if (!strcmp(name, "ScrollLock") && applet->on[SCROLLLOCK])
XkbVirtualModsToReal(xkb, 1 << i, &tmp);
mask += tmp;
}
}
XkbFreeKeyboard(xkb, 0, True);
return mask;
}
Ich hab da im kleinen GNOME2-Applet led_applet evtl. eine mögliche Lösung zum Tastaturauslesen gefunden. Das Dingen liegt auf led_applet-0.3.tar.gz (http://mfcn.ilo.de/led_applet/led_applet-0.3.tar.gz).
Hier mal ein paar evtl. brauchbare Zeilen:
#include <X11/XKBlib.h>
XkbSelectEvents(applet->rootwin, XkbUseCoreKbd, XkbIndicatorStateNotifyMask, XkbIndicatorStateNotifyMask)
static unsigned int
get_lockmask(LedApplet *applet)
{
int i;
unsigned int mask = 0;
XkbDescPtr xkb;
g_assert(applet);
if (!(xkb = XkbGetKeyboard(applet->rootwin, XkbAllComponentsMask, XkbUseCoreKbd)))
return 0;
if (!xkb->names)
return 0;
for(i = 0;i <= XkbNumVirtualMods;i++)
{
unsigned int tmp = 0;
char* name = NULL;
if (!xkb->names->vmods[i])
continue;
name = XGetAtomName(xkb->dpy, xkb->names->vmods[i]);
if (name)
{
if (!strcmp(name, "Caps Lock") && applet->on[CAPSLOCK])
{
XkbVirtualModsToReal(xkb, 1 << i, &tmp);
if (!tmp)
tmp = 2; /* Hack to make it work. Maybe a bug in xkb? */
}
if (!strcmp(name, "NumLock") && applet->on[NUMLOCK])
XkbVirtualModsToReal(xkb, 1 << i, &tmp);
if (!strcmp(name, "ScrollLock") && applet->on[SCROLLLOCK])
XkbVirtualModsToReal(xkb, 1 << i, &tmp);
mask += tmp;
}
}
XkbFreeKeyboard(xkb, 0, True);
return mask;
}