diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-03-06 22:04:14 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-03-06 22:04:14 +0100 |
commit | 901eb8d36a8caba382818d36583aa0da963f0060 (patch) | |
tree | 666f4195c2ce02a12a35e966fa77dea0ba78a10f /src | |
parent | add lunar class (diff) | |
download | xpybar-901eb8d36a8caba382818d36583aa0da963f0060.tar.gz xpybar-901eb8d36a8caba382818d36583aa0da963f0060.tar.bz2 xpybar-901eb8d36a8caba382818d36583aa0da963f0060.tar.xz |
add lock key monitoring
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/xkb.py | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/plugins/xkb.py b/src/plugins/xkb.py new file mode 100644 index 0000000..40ecf8d --- /dev/null +++ b/src/plugins/xkb.py @@ -0,0 +1,73 @@ +# -*- python -*- +''' +xpybar – xmobar replacement written in python +Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +''' + +import Xlib.XK + + +class XKB: + ''' + X keyboard monitor + ''' + + + NUM = 1 + ''' + :int The bit in `get_locks` representing Num Lock + ''' + + CAPS = 2 + ''' + :int The bit in `get_locks` representing Royal Canterlot Voice + ''' + + SCROLL = 4 + ''' + :int The bit in `get_locks` representing Scroll Lock + ''' + + + def __init__(self): + ''' + Constructor + ''' + self.__root = get_screen().root + + lockkey = lambda lock : self.__display.keysym_to_keycode(Xlib.XK.string_to_keysym(lock + '_Lock')) + find = lambda array, item : (1 << array.index(item)) if item in array else -1 + mods = [x[0] for x in get_display().get_modifier_mapping()] + + self.__num = find(mods, lockkey('Num')) + self.__caps = find(mods, lockkey('Caps')) + self.__scroll = find(mods, lockkey('Scroll')) + + + def get_locks(self): + ''' + Get the currently active lock keys (num lock, caps lock and scroll lock, but not compose) + + @return :int The bitwise OR of the active lock keys (XKB.NUM, XKB.CAPS, XKB.SCROLL) + ''' + # TODO add update listener + mask = self.__root.query_pointer().mask + rc = 0 + rc |= XKB.NUM if (mask & self.__num) == self.__num else 0 + rc |= XKB.CAPS if (mask & self.__caps) == self.__caps else 0 + rc |= XKB.SCROLL if (mask & self.__scroll) == self.__scroll else 0 + return rc + |