29 January 2011


One of the problems with wireless keyboards is they have no indicator lights for num lock, caps lock, etc. If you are running Gnome you can use lock-keys-applet, but Xfce currently has no native panel plugin for displaying the lock keys.

Fortunately, Xfce does include a generic monitor panel plugin, which you can use for almost anything.

indicator="Num Lock"
text = ""
on_icon = "/usr/share/pixmaps/pidgin/status/16/available.png"
off_icon = "/usr/share/pixmaps/pidgin/status/16/invisible.png"

from ctypes import *

def GetIndicatorState(name):
    state = c_bool(False)

    libX11 = CDLL("libX11.so")
    display = libX11.XOpenDisplay(0)
    atom = libX11.XInternAtom(display, name, c_bool(False))
    libX11.XkbGetNamedIndicator(display, atom, 0, byref(state), 0, 0)
    return state.value

if GetIndicatorState(indicator):
    print("" + on_icon + "")
    print("" + off_icon + "")
Adjust the four variables at the top to your taste, and set genmon to run it every second. The updates aren't instantaneous, and it's a little resource heavy, but it's better than nothing.

No comments: