diff -Nru virtkey-0.60.0/debian/changelog virtkey-0.61.0/debian/changelog --- virtkey-0.60.0/debian/changelog 2012-06-30 15:13:05.000000000 +0000 +++ virtkey-0.61.0/debian/changelog 2012-06-30 14:54:01.000000000 +0000 @@ -1,3 +1,30 @@ +virtkey (0.61.0-0ppa~quantal1) quantal; urgency=low + + * Add support for python3. Create two binary packages now: + - python-virtkey + - python3-virtkey + * Reduce the number of unnecessarily linked libraries + * Make XkbGetKeyboard use correct constants (thanks Gerd Kohlberger) + * Switch the name of the source code package back to virtkey + * debian: + - add python-virtkey.install and python3-virtkey.install + - add folder and file to set debian source format to 3.0 (quilt) + * debian/control: + - change the name of the source from python-virtkey to virtkey + - add the creation of the python3-virtkey package + - remove cdbs build-dependency + - raise debhelper build-dependency to (>= 7.0.50~) + - update Standards-Version to 3.9.3 + * debian/rules: + - have dh_python2 create the puthon2 and python3 packages + - override dh_auto_install + * debian/copyright: + - adjust hosting site to use virtkey instead of python-virtkey + - add the copyright information for the year 2012 + * debian/watch: replace python-virtkey with virtkey in the urls + + -- Francesco Fumanti Wed, 27 Jun 2012 21:28:33 +0200 + virtkey (0.60.0-0ubuntu5) precise; urgency=low * Rebuild to drop python2.6 dependencies. diff -Nru virtkey-0.60.0/debian/compat virtkey-0.61.0/debian/compat --- virtkey-0.60.0/debian/compat 2012-06-30 15:13:05.000000000 +0000 +++ virtkey-0.61.0/debian/compat 2012-06-27 16:25:42.000000000 +0000 @@ -1 +1 @@ -5 +7 diff -Nru virtkey-0.60.0/debian/control virtkey-0.61.0/debian/control --- virtkey-0.60.0/debian/control 2012-06-30 15:13:05.000000000 +0000 +++ virtkey-0.61.0/debian/control 2012-06-27 20:14:02.000000000 +0000 @@ -1,16 +1,33 @@ Source: virtkey Section: python Priority: optional -Build-Depends: debhelper, python-all-dev (>= 2.6.6-3~), libx11-dev, libxext-dev, libxtst-dev, cdbs (>= 0.4.90~), libgtk2.0-dev Maintainer: Ubuntu Developers -XSBC-Original-Maintainer: Chris Jones -Standards-Version: 3.7.2 -Homepage: https://launchpad.net/python-virtkey -X-Python-Version: >= 2.5 +XSBC-Original-Maintainer: Chris Jones +Build-Depends: debhelper (>= 7.0.50~), + python-all-dev (>= 2.6.6-3~), + python3-all-dev (>= 3.2), + libx11-dev, + libxext-dev, + libxtst-dev, + libgtk2.0-dev +Standards-Version: 3.9.3 +Homepage: https://launchpad.net/virtkey +Vcs-Bzr: https://code.launchpad.net/virtkey +X-Python-Version: >= 2.6 +X-Python3-Version: >= 3.2 Package: python-virtkey Architecture: any +XB-Python-Version: ${python:Versions} Depends: ${shlibs:Depends}, ${misc:Depends}, ${python:Depends} Description: Library to emulate keyboard keypresses. python-virtkey is a python extension for emulating keypresses and getting the keyboard geometry from the xserver. + +Package: python3-virtkey +Architecture: any +XB-Python3-Version: ${python3:Versions} +Depends: ${shlibs:Depends}, ${misc:Depends}, ${python3:Depends} +Description: Library to emulate keyboard keypresses. + python3-virtkey is a python3 extension for emulating keypresses and + getting the keyboard geometry from the xserver. diff -Nru virtkey-0.60.0/debian/copyright virtkey-0.61.0/debian/copyright --- virtkey-0.60.0/debian/copyright 2012-06-30 15:13:05.000000000 +0000 +++ virtkey-0.61.0/debian/copyright 2012-06-27 19:48:58.000000000 +0000 @@ -1,10 +1,10 @@ -This python-virtkey package was built by: +The python-virtkey and python3-virtkey packages were built by: - Francesco Fumanti on Tue, 17 Aug 2010 11:39:38 +0200 - -The source is hosted at: + Francesco Fumanti on Tue, 28 Jun 2012 10:35:22 +0200 - https://launchpad.net/python-virtkey/+download +The virtkey source code used to build the packages is hosted at: + + https://launchpad.net/virtkey/+download Upstream Authors: @@ -17,6 +17,7 @@ Copyright (C) 2006, 2007, 2008 Chris Jones Copyright (C) 2010 marmuta Copyright (C) 2010 Francesco Fumanti + Copyright (C) 2012 marmuta, Francesco Fumanti License: @@ -24,13 +25,13 @@ modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - - python-virtkey is distributed in the hope that it will be useful, + + virtkey 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 Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public - License along with python-virtkey package. Otherwise, please have a + License along with virtkey source package. Otherwise, please have a look at /usr/share/common-licenses or . diff -Nru virtkey-0.60.0/debian/pycompat virtkey-0.61.0/debian/pycompat --- virtkey-0.60.0/debian/pycompat 2012-06-30 15:13:05.000000000 +0000 +++ virtkey-0.61.0/debian/pycompat 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -2 diff -Nru virtkey-0.60.0/debian/python3-virtkey.install virtkey-0.61.0/debian/python3-virtkey.install --- virtkey-0.60.0/debian/python3-virtkey.install 1970-01-01 00:00:00.000000000 +0000 +++ virtkey-0.61.0/debian/python3-virtkey.install 2012-06-27 16:25:42.000000000 +0000 @@ -0,0 +1,2 @@ +usr/lib/python3*/* + diff -Nru virtkey-0.60.0/debian/python-virtkey.install virtkey-0.61.0/debian/python-virtkey.install --- virtkey-0.60.0/debian/python-virtkey.install 1970-01-01 00:00:00.000000000 +0000 +++ virtkey-0.61.0/debian/python-virtkey.install 2012-06-27 16:25:42.000000000 +0000 @@ -0,0 +1,2 @@ +usr/lib/python2.*/* + diff -Nru virtkey-0.60.0/debian/rules virtkey-0.61.0/debian/rules --- virtkey-0.60.0/debian/rules 2012-06-30 15:13:05.000000000 +0000 +++ virtkey-0.61.0/debian/rules 2012-06-27 19:52:40.000000000 +0000 @@ -1,6 +1,14 @@ #!/usr/bin/make -f -DEB_AUTO_CLEANUP_RCS := yes - -include /usr/share/cdbs/1/class/python-distutils.mk -include /usr/share/cdbs/1/rules/debhelper.mk + +DH_VERBOSE=1 +LDFLAGS += -Wl,--as-needed + +%: + dh $@ --buildsystem=python_distutils --with python2,python3 + +override_dh_auto_install: + dh_auto_install + for python in $(shell py3versions -vr); do \ + python$$python setup.py install --install-layout=deb --root=debian/tmp; \ + done diff -Nru virtkey-0.60.0/debian/source/format virtkey-0.61.0/debian/source/format --- virtkey-0.60.0/debian/source/format 1970-01-01 00:00:00.000000000 +0000 +++ virtkey-0.61.0/debian/source/format 2012-06-30 15:13:05.000000000 +0000 @@ -0,0 +1 @@ +3.0 (quilt) diff -Nru virtkey-0.60.0/debian/watch virtkey-0.61.0/debian/watch --- virtkey-0.60.0/debian/watch 2012-06-30 15:13:05.000000000 +0000 +++ virtkey-0.61.0/debian/watch 2012-06-27 18:59:26.000000000 +0000 @@ -1,2 +1,2 @@ version=3 -http://launchpad.net/python-virtkey/+download http://launchpad.net/python-virtkey/.*/python-virtkey-([\d\.]+).tar.gz +http://launchpad.net/virtkey/+download http://launchpad.net/virtkey/.*/virtkey-([\d\.]+).tar.gz diff -Nru virtkey-0.60.0/docs/api.txt virtkey-0.61.0/docs/api.txt --- virtkey-0.60.0/docs/api.txt 2010-08-13 14:04:00.000000000 +0000 +++ virtkey-0.61.0/docs/api.txt 2012-06-27 18:54:36.000000000 +0000 @@ -1,7 +1,7 @@ -= Documentation for python-virtkey = += Documentation for virtkey = -python-virtkey is a python extension for emulating keypresses and -getting the keyboard geometry from the xserver. +virtkey is a extension python and python3 to emulate keypresses and +to get the keyboard geometry from the xserver. The documentation below is brief and incomplete. I will finish it when I get time. diff -Nru virtkey-0.60.0/NEWS virtkey-0.61.0/NEWS --- virtkey-0.60.0/NEWS 2010-08-17 18:49:48.000000000 +0000 +++ virtkey-0.61.0/NEWS 2012-06-27 19:26:41.000000000 +0000 @@ -1,3 +1,13 @@ +Version 0.61.0 +-------------- + + * Add support for python3. Create two binary packages now: + - python-virtkey + - python3-virtkey + * Reduce the number of unnecessarily linked libraries + * Make XkbGetKeyboard use correct constants (thanks Gerd Kohlberger) + * Switch the name of the source code package back to virtkey + Version 0.60.0 -------------- diff -Nru virtkey-0.60.0/PKG-INFO virtkey-0.61.0/PKG-INFO --- virtkey-0.60.0/PKG-INFO 2010-08-18 12:47:40.000000000 +0000 +++ virtkey-0.61.0/PKG-INFO 2012-06-28 12:36:11.000000000 +0000 @@ -1,8 +1,8 @@ Metadata-Version: 1.0 -Name: python-virtkey -Version: 0.60.0 -Summary: python extension for emulating keypresses and getting keyboard layout -Home-page: https://launchpad.net/python-virtkey/ +Name: virtkey +Version: 0.61.0 +Summary: Extension for python and python3 to emulate keypresses and to get the layout information from the X server. +Home-page: https://launchpad.net/virtkey/ Author: Ubuntu Core Developers Author-email: ubuntu-devel-discuss@lists.ubuntu.com License: LGPL diff -Nru virtkey-0.60.0/README virtkey-0.61.0/README --- virtkey-0.60.0/README 2010-08-13 14:04:00.000000000 +0000 +++ virtkey-0.61.0/README 2012-06-27 19:35:31.000000000 +0000 @@ -1,29 +1,29 @@ -python-virtkey 0.60.0 +virtkey 0.61.0 --------------------- Description: - python-virtkey is a python extension for emulating keypresses and - getting the keyboard geometry from the xserver. + virtkey is a extension python and python3 to emulate keypresses and + to get the keyboard geometry from the xserver. It uses ideas from Fontconfig, libvirtkeys.c, keysym2ucs.c and dasher. Homepage: - https://launchpad.net/python-virtkey + https://launchpad.net/virtkey Source Code: - https://code.launchpad.net/python-virtkey + https://code.launchpad.net/virtkey Reporting Bugs: - https://bugs.launchpad.net/python-virtkey + https://bugs.launchpad.net/virtkey Questions: - https://answers.launchpad.net/python-virtkey + https://answers.launchpad.net/virtkey License: diff -Nru virtkey-0.60.0/setup.py virtkey-0.61.0/setup.py --- virtkey-0.60.0/setup.py 2010-08-13 14:04:00.000000000 +0000 +++ virtkey-0.61.0/setup.py 2012-06-27 18:53:26.000000000 +0000 @@ -2,32 +2,35 @@ # # Authored by Chris Jones # Modified by Francesco Fumanti +# Modified by marmuta # # Copyright (C) 2006, 2007, 2008 Chris Jones # Copyright (C) 2010 Francesco Fumanti +# Copyright (C) 2011 marmuta +# Copyright (C) 2012 Francesco Fumanti, marmuta # -# ------------------------------------------------------------------ +# -------------------------------------------------------------------- # -# This file is part of the python-virtkey library. +# This file is part of the virtkey library. # -# python-virtkey is free software: you can redistribute it and/or +# virtkey is free software: you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public License # as published by the Free Software Foundation, either version 3 of # the License, or (at your option) any later version. # -# python-virtkey is distributed in the hope that it will be useful, +# virtkey 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 Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public -# License along with python-virtkey. If not, see +# License along with virtkey. If not, see # . # -# ------------------------------------------------------------------ +# -------------------------------------------------------------------- # -# python-virtkey is a python extension for emulating keypresses and -# getting the keyboard geometry from the xserver. +# virtkey is an extension for python and python3 to emulate keypresses +# and to get the keyboard geometry from the xserver. # # It uses ideas from Fontconfig, libvirtkeys.c, keysym2ucs.c and # dasher. @@ -35,30 +38,35 @@ from distutils.core import setup from distutils.extension import Extension -import commands +try: + # try python 3 + from subprocess import getoutput +except: + # python 2 fallback + from commands import getoutput # From http://code.activestate.com/recipes/502261-python-distutils-pkg-config/ def pkgconfig(*packages, **kw): flag_map = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries'} - for token in commands.getoutput("pkg-config --libs --cflags %s" % ' '.join(packages)).split(): - if flag_map.has_key(token[:2]): + for token in getoutput("pkg-config --libs --cflags %s" % ' '.join(packages)).split(): + if token[:2] in flag_map: kw.setdefault(flag_map.get(token[:2]), []).append(token[2:]) else: # throw others to extra_link_args kw.setdefault('extra_link_args', []).append(token) - for k, v in kw.iteritems(): # remove duplicated + for k, v in kw.items(): # remove duplicated kw[k] = list(set(v)) return kw setup( - name="python-virtkey", - version="0.60.0", + name="virtkey", + version="0.61.0", author = 'Chris Jones', author_email = 'chris.e.jones@gmail.com', maintainer = 'Ubuntu Core Developers', maintainer_email = 'ubuntu-devel-discuss@lists.ubuntu.com', - url = 'https://launchpad.net/python-virtkey/', + url = 'https://launchpad.net/virtkey/', license = 'LGPL', - description = 'python extension for emulating keypresses and getting keyboard layout', + description = 'Extension for python and python3 to emulate keypresses and to get the layout information from the X server.', ext_modules=[ Extension("virtkey", ["src/python-virtkey.c","src/ucs2keysym.c"], **pkgconfig('glib-2.0', 'gdk-2.0', 'x11', 'xtst'))] diff -Nru virtkey-0.60.0/src/python-virtkey.c virtkey-0.61.0/src/python-virtkey.c --- virtkey-0.60.0/src/python-virtkey.c 2010-08-13 14:04:00.000000000 +0000 +++ virtkey-0.61.0/src/python-virtkey.c 2012-06-27 18:36:05.000000000 +0000 @@ -7,20 +7,20 @@ * * ------------------------------------------------------------------ * - * This file is part of the python-virtkey library. - * - * python-virtkey is free software: you can redistribute it and/or + * This file is part of the virtkey library. + * + * virtkey is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. - * - * python-virtkey is distributed in the hope that it will be useful, + * + * virtkey 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 Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public - * License along with python-virtkey. If not, see + * License along with virtkey. If not, see * . */ @@ -30,70 +30,78 @@ #include #include +#if PY_MAJOR_VERSION >= 3 + #define PyString_FromString PyUnicode_FromString + #define PyString_FromStringAndSize PyUnicode_FromStringAndSize + + #define PyInt_FromLong PyLong_FromLong +#else +#endif + /* constructor */ static PyObject * virtkey_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - //initialize python object and open display. + //initialize python object and open display. virtkey *object = (virtkey*)type->tp_alloc(type, 0); if (object == NULL) return NULL; - memset(((char*)object)+sizeof(PyObject), 0, + memset(((char*)object)+sizeof(PyObject), 0, sizeof(*object)-sizeof(PyObject)); object->displayString = getenv ("DISPLAY"); if (!object->displayString) object->displayString = ":0.0"; object->display = XOpenDisplay(object->displayString); - + if (!object->display) { PyErr_SetString(virtkey_error, "failed initialize display :("); return NULL; } - - - XModifierKeymap *modifiers; - int mod_index; - int mod_key; - KeyCode *kp; - - XDisplayKeycodes(object->display, + + + XModifierKeymap *modifiers; + int mod_index; + int mod_key; + KeyCode *kp; + + XDisplayKeycodes(object->display, &object->min_keycode, &object->max_keycode); - - object->keysyms = XGetKeyboardMapping(object->display, - object->min_keycode, - object->max_keycode - object->min_keycode + 1, - &object->n_keysyms_per_keycode); - - modifiers = XGetModifierMapping(object->display); - - kp = modifiers->modifiermap; - - for (mod_index = 0; mod_index < 8; mod_index++) + + object->keysyms = XGetKeyboardMapping(object->display, + object->min_keycode, + object->max_keycode - object->min_keycode + 1, + &object->n_keysyms_per_keycode); + + modifiers = XGetModifierMapping(object->display); + + kp = modifiers->modifiermap; + + for (mod_index = 0; mod_index < 8; mod_index++) { object->modifier_table[mod_index] = 0; - + for (mod_key = 0; mod_key < modifiers->max_keypermod; mod_key++) - { - int keycode = kp[mod_index * modifiers->max_keypermod + mod_key]; - + { + int keycode = kp[mod_index * modifiers->max_keypermod + mod_key]; + if (keycode != 0) { object->modifier_table[mod_index] = keycode; break; } - } + } } - + for (mod_index = Mod1MapIndex; mod_index <= Mod5MapIndex; mod_index++) { if (object->modifier_table[mod_index]) - { - KeySym ks = XKeycodeToKeysym(object->display, + { + KeySym ks = XKeycodeToKeysym(object->display, object->modifier_table[mod_index], 0); - /* + /* * Note: ControlMapIndex is already defined by xlib * ShiftMapIndex*/ @@ -104,37 +112,37 @@ case XK_Meta_L: object->meta_mod_index = mod_index; break; - + case XK_Alt_R: case XK_Alt_L: object->alt_mod_index = mod_index; break; - + case XK_Shift_R: case XK_Shift_L: object->shift_mod_index = mod_index; break; } - } + } } - + if (modifiers) - XFreeModifiermap(modifiers); - + XFreeModifiermap(modifiers); + - getKbd(object); + getKbd(object); if (PyErr_Occurred()){ Py_DECREF(object); /* cleanup, call dealloc */ return NULL; } - + return (PyObject *)object; - + } static void -virtkey_dealloc(PyObject * self){ +virtkey_dealloc(PyObject * self){ virtkey * cvirt = (virtkey *)self; if (cvirt->kbd) XkbFreeKeyboard (cvirt->kbd, XkbAllComponentsMask, True); @@ -142,7 +150,7 @@ XFree(cvirt->keysyms); if (cvirt->display) XCloseDisplay(cvirt->display); - self->ob_type->tp_free((PyObject*)self); + Py_TYPE(self)->tp_free((PyObject*)self); } //Need to handle errors here properly. @@ -151,12 +159,10 @@ XkbFreeKeyboard (cvirt->kbd, XkbAllComponentsMask, True); cvirt->kbd = XkbGetKeyboard (cvirt->display, - XkbGBN_GeometryMask | - XkbGBN_KeyNamesMask | - XkbGBN_OtherNamesMask | - XkbGBN_SymbolsMask | - XkbGBN_IndicatorMapMask, - XkbUseCoreKbd); + XkbCompatMapMask | + XkbNamesMask | + XkbGeometryMask, + XkbUseCoreKbd); #if 0 /* test missing keyboard (LP: 526791) keyboard on/off every 10 seconds */ @@ -179,66 +185,66 @@ /* Status stat = XkbGetGeometry (cvirt->display, cvirt->kbd); - if (stat == BadValue) - PyErr_SetString(virtkey_error, + if (stat == BadValue) + PyErr_SetString(virtkey_error, "Error getting keyboard geometry info, Bad Value.\n"); - if (stat == BadImplementation) - PyErr_SetString(virtkey_error, + if (stat == BadImplementation) + PyErr_SetString(virtkey_error, "Error getting keyboard geometry info, Bad Implementation.\n"); - if (stat == BadName) - PyErr_SetString(virtkey_error, + if (stat == BadName) + PyErr_SetString(virtkey_error, "Error getting keyboard geometry info, Bad Name.\n"); - if (stat == BadAlloc) - PyErr_SetString(virtkey_error, + if (stat == BadAlloc) + PyErr_SetString(virtkey_error, "Error getting keyboard geometry info, Bad Alloc.\n"); */ - - if (XkbGetNames (cvirt->display, XkbAllNamesMask, cvirt->kbd) != Success) + + if (XkbGetNames (cvirt->display, XkbAllNamesMask, cvirt->kbd) != Success) PyErr_SetString(virtkey_error, "Error getting key name info.\n"); - + return; } long keysym2keycode(virtkey * cvirt, KeySym keysym, int * flags){ static int modifiedkey; KeyCode code = 0; - + if ((code = XKeysymToKeycode(cvirt->display, keysym)) != 0) { if (XKeycodeToKeysym(cvirt->display, code, 0) != keysym) - { - - if (XKeycodeToKeysym(cvirt->display, code, 1) == keysym) - *flags |= 1; //can get at it via shift - else - code = 0; // urg, some other modifier do it the heavy way - } + { + + if (XKeycodeToKeysym(cvirt->display, code, 1) == keysym) + *flags |= 1; //can get at it via shift + else + code = 0; // urg, some other modifier do it the heavy way + } } - + if (!code) { int index; // Change one of the last 10 keysyms to our converted utf8, - // remapping the x keyboard on the fly. + // remapping the x keyboard on the fly. // // This make assumption the last 10 arn't already used. - // TODO: probably safer to check for this. + // TODO: probably safer to check for this. modifiedkey = (modifiedkey+1) % 10; - // Point at the end of keysyms, modifier 0 + // Point at the end of keysyms, modifier 0 index = (cvirt->max_keycode - cvirt->min_keycode - modifiedkey - 1) * cvirt->n_keysyms_per_keycode; cvirt->keysyms[index] = keysym; - XChangeKeyboardMapping(cvirt->display, - cvirt->min_keycode, - cvirt->n_keysyms_per_keycode, - cvirt->keysyms, + XChangeKeyboardMapping(cvirt->display, + cvirt->min_keycode, + cvirt->n_keysyms_per_keycode, + cvirt->keysyms, (cvirt->max_keycode-cvirt->min_keycode)); XSync(cvirt->display, False); @@ -246,18 +252,18 @@ // From dasher src; // There's no way whatsoever that this could ever possibly // be guaranteed to work (ever), but it does. - + code = cvirt->max_keycode - modifiedkey - 1; // The below is lightly safer; // // code = XKeysymToKeycode(fk->display, keysym); // - // but this appears to break in that the new mapping is not immediatly + // but this appears to break in that the new mapping is not immediatly // put to work. It would seem a MappingNotify event is needed so - // Xlib can do some changes internally ? ( xlib is doing something + // Xlib can do some changes internally ? ( xlib is doing something // related to above ? ) - // + // // Probably better to try and grab the mapping notify *here* ? @@ -269,174 +275,174 @@ static PyObject * get_label (KeySym keyval) { - gchar buf[5]; - gunichar uc; + gchar buf[5]; + gunichar uc; PyObject * label; - switch (keyval) { - case GDK_Scroll_Lock: - label = PyString_FromString("Scroll\nLock"); - break; - - case GDK_space: - label = PyString_FromString(" "); - break; - - case GDK_Sys_Req: - label = PyString_FromString("Sys Rq"); - break; - - case GDK_Page_Up: - label = PyString_FromString("Page\nUp"); - break; - - case GDK_Page_Down: - label = PyString_FromString("Page\nDown"); - break; - - case GDK_Num_Lock: - label = PyString_FromString("Num\nLock"); - break; - - case GDK_KP_Page_Up: - label = PyString_FromString("Pg Up"); - break; - - case GDK_KP_Page_Down: - label = PyString_FromString("Pg Dn"); - break; - - case GDK_KP_Home: - label = PyString_FromString("Home"); - break; - - case GDK_KP_Left: - label = PyString_FromString("Left"); - break; - - case GDK_KP_End: - label = PyString_FromString("End"); - break; - - case GDK_KP_Up: - label = PyString_FromString("Up"); - break; - - case GDK_KP_Begin: - label = PyString_FromString("Begin"); - break; - - case GDK_KP_Right: - label = PyString_FromString("Right"); - break; - - case GDK_KP_Enter: - label = PyString_FromString("Enter"); - break; - - case GDK_KP_Down: - label = PyString_FromString("Down"); - break; - - case GDK_KP_Insert: - label = PyString_FromString("Ins"); - break; - - case GDK_KP_Delete: - label = PyString_FromString("Del"); - break; - - case GDK_dead_grave: - label = PyString_FromString("ˋ"); - break; - - case GDK_dead_acute: - label = PyString_FromString("ˊ"); - break; - - case GDK_dead_circumflex: - label = PyString_FromString("ˆ"); - break; - - case GDK_dead_tilde: - label = PyString_FromString("~"); - break; - - case GDK_dead_macron: - label = PyString_FromString("ˉ"); - break; - - case GDK_dead_breve: - label = PyString_FromString("˘"); - break; - - case GDK_dead_abovedot: - label = PyString_FromString("˙"); - break; - - case GDK_dead_diaeresis: - label = PyString_FromString("¨"); - break; - - case GDK_dead_abovering: - label = PyString_FromString("˚"); - break; - - case GDK_dead_doubleacute: - label = PyString_FromString("˝"); - break; - - case GDK_dead_caron: - label = PyString_FromString("ˇ"); - break; - - case GDK_dead_cedilla: - label = PyString_FromString("¸"); - break; - - case GDK_dead_ogonek: - label = PyString_FromString("˛"); - break; - - /* case GDK_dead_iota: - * case GDK_dead_voiced_sound: - * case GDK_dead_semivoiced_sound: */ - - case GDK_dead_belowdot: - label = PyString_FromString("."); - break; - - case GDK_horizconnector: - label = PyString_FromString("horiz\nconn"); - break; - - case GDK_Mode_switch: - label = PyString_FromString("AltGr"); - break; - - case GDK_Multi_key: - label = PyString_FromString("Compose"); - break; - - default: - uc = gdk_keyval_to_unicode (keyval); - if (uc != 0 && g_unichar_isgraph (uc)) { - buf[g_unichar_to_utf8 (uc, buf)] = '\0'; + switch (keyval) { + case GDK_Scroll_Lock: + label = PyString_FromString("Scroll\nLock"); + break; + + case GDK_space: + label = PyString_FromString(" "); + break; + + case GDK_Sys_Req: + label = PyString_FromString("Sys Rq"); + break; + + case GDK_Page_Up: + label = PyString_FromString("Page\nUp"); + break; + + case GDK_Page_Down: + label = PyString_FromString("Page\nDown"); + break; + + case GDK_Num_Lock: + label = PyString_FromString("Num\nLock"); + break; + + case GDK_KP_Page_Up: + label = PyString_FromString("Pg Up"); + break; + + case GDK_KP_Page_Down: + label = PyString_FromString("Pg Dn"); + break; + + case GDK_KP_Home: + label = PyString_FromString("Home"); + break; + + case GDK_KP_Left: + label = PyString_FromString("Left"); + break; + + case GDK_KP_End: + label = PyString_FromString("End"); + break; + + case GDK_KP_Up: + label = PyString_FromString("Up"); + break; + + case GDK_KP_Begin: + label = PyString_FromString("Begin"); + break; + + case GDK_KP_Right: + label = PyString_FromString("Right"); + break; + + case GDK_KP_Enter: + label = PyString_FromString("Enter"); + break; + + case GDK_KP_Down: + label = PyString_FromString("Down"); + break; + + case GDK_KP_Insert: + label = PyString_FromString("Ins"); + break; + + case GDK_KP_Delete: + label = PyString_FromString("Del"); + break; + + case GDK_dead_grave: + label = PyString_FromString("ˋ"); + break; + + case GDK_dead_acute: + label = PyString_FromString("ˊ"); + break; + + case GDK_dead_circumflex: + label = PyString_FromString("ˆ"); + break; + + case GDK_dead_tilde: + label = PyString_FromString("~"); + break; + + case GDK_dead_macron: + label = PyString_FromString("ˉ"); + break; + + case GDK_dead_breve: + label = PyString_FromString("˘"); + break; + + case GDK_dead_abovedot: + label = PyString_FromString("˙"); + break; + + case GDK_dead_diaeresis: + label = PyString_FromString("¨"); + break; + + case GDK_dead_abovering: + label = PyString_FromString("˚"); + break; + + case GDK_dead_doubleacute: + label = PyString_FromString("˝"); + break; + + case GDK_dead_caron: + label = PyString_FromString("ˇ"); + break; + + case GDK_dead_cedilla: + label = PyString_FromString("¸"); + break; + + case GDK_dead_ogonek: + label = PyString_FromString("˛"); + break; + + /* case GDK_dead_iota: + * case GDK_dead_voiced_sound: + * case GDK_dead_semivoiced_sound: */ + + case GDK_dead_belowdot: + label = PyString_FromString("."); + break; + + case GDK_horizconnector: + label = PyString_FromString("horiz\nconn"); + break; + + case GDK_Mode_switch: + label = PyString_FromString("AltGr"); + break; + + case GDK_Multi_key: + label = PyString_FromString("Compose"); + break; + + default: + uc = gdk_keyval_to_unicode (keyval); + if (uc != 0 && g_unichar_isgraph (uc)) { + buf[g_unichar_to_utf8 (uc, buf)] = '\0'; label = PyString_FromString(buf); - } - else + } + else { - - gchar *name = gdk_keyval_name (keyval); - - if (name) - label = PyString_FromStringAndSize(name,2); - else - label = PyString_FromString(" "); - - } - } + + gchar *name = gdk_keyval_name (keyval); + + if (name) + label = PyString_FromStringAndSize(name,2); + else + label = PyString_FromString(" "); + + } + } return label; } @@ -458,8 +464,8 @@ for(m = 4; m >= 0; --m) { - if (XkbTranslateKeyCode (cvirt->kbd, (KeyCode) keycode, - XkbBuildCoreState (mods[m], group), + if (XkbTranslateKeyCode (cvirt->kbd, (KeyCode) keycode, + XkbBuildCoreState (mods[m], group), &mods_rtn, &keysym)){ PyTuple_SetItem(labelTuple,m,get_label(keysym)); } @@ -470,12 +476,12 @@ } -static PyObject * +static PyObject * report_key_info (virtkey * cvirt, XkbKeyPtr key, int col, int *x, int *y) { PyObject * keyObject = PyDict_New(); - PyDict_SetItemString(keyObject,"name", + PyDict_SetItemString(keyObject,"name", PyString_FromStringAndSize(key->name.name,XkbKeyNameLength)); int x1 = 0; @@ -492,8 +498,8 @@ // Above calculation is - // WORKAROUND FOR BUG in XFree86's XKB implementation, - // which reports kbd->names->num_keys == 0! + // WORKAROUND FOR BUG in XFree86's XKB implementation, + // which reports kbd->names->num_keys == 0! // In fact, num_keys should be max_key_code-1, and the names->keys // array is indeed valid! // @@ -507,44 +513,44 @@ PyObject * labelTuple = PyTuple_New(5);//del - for (k = cvirt->kbd->min_key_code; k < cvirt->kbd->max_key_code; ++k) + for (k = cvirt->kbd->min_key_code; k < cvirt->kbd->max_key_code; ++k) { if (!strncmp (name, cvirt->kbd->names->keys[k].name, XkbKeyNameLength)) - { + { labelTuple = virtkey_get_labels_from_keycode_internal(cvirt, k); - + x1 = *x + geom->shapes[key->shape_ndx].bounds.x1/10; y1 = *y + geom->shapes[key->shape_ndx].bounds.y1/10; - x2 = geom->shapes[key->shape_ndx].bounds.x2/10 - + x2 = geom->shapes[key->shape_ndx].bounds.x2/10 - geom->shapes[key->shape_ndx].bounds.x1/10; - y2 = geom->shapes[key->shape_ndx].bounds.y2/10 - + y2 = geom->shapes[key->shape_ndx].bounds.y2/10 - geom->shapes[key->shape_ndx].bounds.y1/10; *x += geom->shapes[key->shape_ndx].bounds.x2/10; - break; - } + break; + } } PyObject * x1ob = PyInt_FromLong(x1); PyObject * y1ob = PyInt_FromLong(y1); PyObject * x2ob = PyInt_FromLong(x2); PyObject * y2ob = PyInt_FromLong(y2); - - + + PyObject * shape = PyTuple_Pack(4, x1ob, y1ob, x2ob, y2ob); - + Py_DECREF(x1ob); - Py_DECREF(y1ob); + Py_DECREF(y1ob); Py_DECREF(x2ob); Py_DECREF(y2ob); - + PyDict_SetItemString(keyObject,"shape",shape); - Py_DECREF(shape); - + Py_DECREF(shape); + PyObject * keycodeOb = PyInt_FromLong(k); PyDict_SetItemString(keyObject, "keycode", keycodeOb); Py_DECREF(keycodeOb); @@ -556,28 +562,28 @@ */ PyDict_SetItemString(keyObject,"labels", labelTuple); - + return keyObject; } static PyObject * virtkey_reload_kbd(PyObject * self, PyObject *args) { - virtkey * cvirt = (virtkey *)self; - getKbd(cvirt); - + virtkey * cvirt = (virtkey *)self; + getKbd(cvirt); + if (PyErr_Occurred()) return NULL; - - Py_INCREF(Py_None); - return Py_None; + + Py_INCREF(Py_None); + return Py_None; } -static PyObject * +static PyObject * virtkey_layout_get_section_info(PyObject * self,PyObject *args) { char * requestedSection; if (PyArg_ParseTuple(args, "s", &requestedSection)){ - + XkbGeometryPtr geom; virtkey * cvirt = (virtkey *)self; @@ -590,7 +596,7 @@ geom = cvirt->kbd->geom; - for (i = 0; i < geom->num_sections; ++i) + for (i = 0; i < geom->num_sections; ++i) { XkbSectionPtr section = &geom->sections[i]; sectionString = XGetAtomName (cvirt->display, section->name); @@ -598,13 +604,13 @@ { PyObject * width = PyInt_FromLong(section->width/10); PyObject * height = PyInt_FromLong(section->height/10); - - + + //Increfs width, height returnTuple = PyTuple_Pack(2, width, height); - + Py_DECREF(width); Py_DECREF(height); @@ -636,7 +642,7 @@ PyObject * rowTuple; - for (i = 0; i < geom->num_sections; ++i) + for (i = 0; i < geom->num_sections; ++i) { XkbSectionPtr section = &geom->sections[i]; sectionString = XGetAtomName (cvirt->display, section->name); @@ -650,40 +656,40 @@ PyObject * keyTuple = PyTuple_New(rowp->num_keys); - for (col = 0; col < rowp->num_keys; ++col) + for (col = 0; col < rowp->num_keys; ++col) { - PyObject * key = report_key_info (cvirt, + PyObject * key = report_key_info (cvirt, &rowp->keys[col], col, &x, &y); PyTuple_SET_ITEM(keyTuple,col,key); } PyTuple_SET_ITEM(rowTuple, row,keyTuple); } - free(sectionString); + free(sectionString); return rowTuple; } free(sectionString); } } - + return PyTuple_New(0); } static PyObject * virtkey_layout_get_sections(PyObject * self,PyObject *args) { - + XkbGeometryPtr geom; int i; - virtkey * cvirt = (virtkey *)self; + virtkey * cvirt = (virtkey *)self; geom = cvirt->kbd->geom; char * sectionString; PyObject * sectionTuple = PyTuple_New(geom->num_sections); - for (i = 0; i < geom->num_sections; ++i) + for (i = 0; i < geom->num_sections; ++i) { XkbSectionPtr section = &geom->sections[i]; sectionString = XGetAtomName (cvirt->display, section->name); @@ -695,21 +701,21 @@ } static PyObject * virtkey_send(virtkey * cvirt, long out, Bool press){ - - if (out != 0) - { - - XTestFakeKeyEvent(cvirt->display, out, press, CurrentTime); - XSync(cvirt->display, False); - - }else { - PyErr_SetString(virtkey_error, "failed to get keycode"); + + if (out != 0) + { + + XTestFakeKeyEvent(cvirt->display, out, press, CurrentTime); + XSync(cvirt->display, False); + + }else { + PyErr_SetString(virtkey_error, "failed to get keycode"); return NULL; - } - - Py_INCREF(Py_None); - return Py_None; -} + } + + Py_INCREF(Py_None); + return Py_None; +} static PyObject * virtkey_get_labels_from_keycode(PyObject *self, PyObject *args) @@ -717,39 +723,39 @@ virtkey *cvirt = (virtkey *)self; long keycode; - if (!(PyArg_ParseTuple(args, "i", &keycode))) + if (!(PyArg_ParseTuple(args, "i", &keycode))) return NULL; return virtkey_get_labels_from_keycode_internal(cvirt, keycode); } static PyObject * virtkey_send_unicode(PyObject * self,PyObject *args, Bool press){ - virtkey * cvirt = (virtkey *)self; - long in = 0; - long out = 0; - int flags = 0; - if ((PyArg_ParseTuple(args, "i", &in))){//find unicode arg in args tuple. - out = keysym2keycode(cvirt, ucs2keysym(in), &flags); - } - if (flags) - change_locked_mods(flags,press,cvirt); - - return virtkey_send(cvirt, out, press); + virtkey * cvirt = (virtkey *)self; + long in = 0; + long out = 0; + int flags = 0; + if ((PyArg_ParseTuple(args, "i", &in))){//find unicode arg in args tuple. + out = keysym2keycode(cvirt, ucs2keysym(in), &flags); + } + if (flags) + change_locked_mods(flags,press,cvirt); + + return virtkey_send(cvirt, out, press); } static PyObject * virtkey_send_keysym(PyObject * self,PyObject *args, Bool press){ - virtkey * cvirt = (virtkey *)self; - long in = 0; - long out = 0; - int flags = 0; - if ((PyArg_ParseTuple(args, "i", &in))){//find keysym arg in args tuple. - - out = keysym2keycode(cvirt, in, &flags); - } - - if (flags) - change_locked_mods(flags,press,cvirt); - return virtkey_send(cvirt, out, press); + virtkey * cvirt = (virtkey *)self; + long in = 0; + long out = 0; + int flags = 0; + if ((PyArg_ParseTuple(args, "i", &in))){//find keysym arg in args tuple. + + out = keysym2keycode(cvirt, in, &flags); + } + + if (flags) + change_locked_mods(flags,press,cvirt); + return virtkey_send(cvirt, out, press); } static PyObject * @@ -762,12 +768,12 @@ return virtkey_send_keycode(self, args, True); } -static PyObject * +static PyObject * virtkey_send_keycode(PyObject *self, PyObject *args, Bool press){ - virtkey * cvirt = (virtkey *)self; + virtkey * cvirt = (virtkey *)self; long keycode; - if(!PyArg_ParseTuple(args, "i", &keycode)){ + if(!PyArg_ParseTuple(args, "i", &keycode)){ return NULL; } @@ -776,88 +782,88 @@ static PyObject * virtkey_latch_mod(PyObject * self,PyObject *args) { - int mask = 0; - - virtkey * cvirt = (virtkey *)self; - - if ((PyArg_ParseTuple(args, "i", &mask))){//find mask arg in args tuple. - XkbLatchModifiers(cvirt->display, XkbUseCoreKbd, mask, mask); - XSync(cvirt->display, False); //Otherwise it waits until next keypress - } - Py_INCREF(Py_None); - return Py_None; + int mask = 0; + + virtkey * cvirt = (virtkey *)self; + + if ((PyArg_ParseTuple(args, "i", &mask))){//find mask arg in args tuple. + XkbLatchModifiers(cvirt->display, XkbUseCoreKbd, mask, mask); + XSync(cvirt->display, False); //Otherwise it waits until next keypress + } + Py_INCREF(Py_None); + return Py_None; } void change_locked_mods(int mask, Bool lock, virtkey * cvirt){ - - if (lock){ - XkbLockModifiers(cvirt->display, XkbUseCoreKbd, mask, mask); - } - else{ - XkbLockModifiers(cvirt->display, XkbUseCoreKbd, mask, 0); - } - XSync(cvirt->display, False); + + if (lock){ + XkbLockModifiers(cvirt->display, XkbUseCoreKbd, mask, mask); + } + else{ + XkbLockModifiers(cvirt->display, XkbUseCoreKbd, mask, 0); + } + XSync(cvirt->display, False); } static PyObject * virtkey_lock_mod(PyObject * self,PyObject *args) -{ - int mask = 0; - - virtkey * cvirt = (virtkey *)self; - - if ((PyArg_ParseTuple(args, "i", &mask))){//find mask arg in args tuple. - change_locked_mods(mask, True, cvirt); - } - Py_INCREF(Py_None); - return Py_None; - +{ + int mask = 0; + + virtkey * cvirt = (virtkey *)self; + + if ((PyArg_ParseTuple(args, "i", &mask))){//find mask arg in args tuple. + change_locked_mods(mask, True, cvirt); + } + Py_INCREF(Py_None); + return Py_None; + } static PyObject * virtkey_unlatch_mod(PyObject * self,PyObject *args) { - int mask = 0; - - virtkey * cvirt = (virtkey *)self; - - if ((PyArg_ParseTuple(args, "i", &mask))){//find mask arg in args tuple. - XkbLatchModifiers(cvirt->display, XkbUseCoreKbd, mask, 0); - XSync(cvirt->display, False); - } - Py_INCREF(Py_None); - return Py_None; - + int mask = 0; + + virtkey * cvirt = (virtkey *)self; + + if ((PyArg_ParseTuple(args, "i", &mask))){//find mask arg in args tuple. + XkbLatchModifiers(cvirt->display, XkbUseCoreKbd, mask, 0); + XSync(cvirt->display, False); + } + Py_INCREF(Py_None); + return Py_None; + } static PyObject * virtkey_unlock_mod(PyObject * self,PyObject *args) -{ - int mask = 0; - - virtkey * cvirt = (virtkey *)self; - - if ((PyArg_ParseTuple(args, "i", &mask))){//find mask arg in args tuple. - change_locked_mods(mask, False, cvirt); - } - Py_INCREF(Py_None); - return Py_None; - +{ + int mask = 0; + + virtkey * cvirt = (virtkey *)self; + + if ((PyArg_ParseTuple(args, "i", &mask))){//find mask arg in args tuple. + change_locked_mods(mask, False, cvirt); + } + Py_INCREF(Py_None); + return Py_None; + } static PyObject * virtkey_get_layouts(PyObject * self, PyObject *args) { - int inout = 20; + int inout = 20; int i=0; - virtkey * cvirt = (virtkey *)self; + virtkey * cvirt = (virtkey *)self; - XkbComponentNamesRec names; - XkbComponentNamesPtr namesPtr = &names; - - namesPtr->keymap = "*"; + XkbComponentNamesRec names; + XkbComponentNamesPtr namesPtr = &names; + namesPtr->keymap = "*"; - XkbComponentListPtr components = XkbListComponents(cvirt->display, + + XkbComponentListPtr components = XkbListComponents(cvirt->display, XkbUseCoreKbd,namesPtr,&inout); PyObject *tuple = PyTuple_New(components->num_keymaps); @@ -871,57 +877,57 @@ XkbFreeComponentList(components); - return tuple; + return tuple; } static PyObject * virtkey_press_keysym(PyObject * self,PyObject *args) { - return virtkey_send_keysym(self, args, True); + return virtkey_send_keysym(self, args, True); } static PyObject * virtkey_release_keysym(PyObject * self,PyObject *args) { - return virtkey_send_keysym(self, args, False); + return virtkey_send_keysym(self, args, False); } static PyObject * virtkey_press_unicode(PyObject * self,PyObject *args) { - return virtkey_send_unicode(self, args, True); - + return virtkey_send_unicode(self, args, True); + } static PyObject * virtkey_release_unicode(PyObject * self,PyObject *args) { - return virtkey_send_unicode(self, args, False); - + return virtkey_send_unicode(self, args, False); + } -static PyObject * virtkey_get_current_group_name(PyObject * self, +static PyObject * virtkey_get_current_group_name(PyObject * self, PyObject * noargs) { PyObject * result = NULL; - virtkey * cvirt = (virtkey *)self; - Display * display = cvirt->display; - + virtkey * cvirt = (virtkey *)self; + Display * display = cvirt->display; + /* get current group index */ XkbStateRec state; if (Success != XkbGetState(display, XkbUseCoreKbd, &state)) - PyErr_SetString(virtkey_error, "XkbGetState failed"); + PyErr_SetString(virtkey_error, "XkbGetState failed"); else{ int group = state.locked_group; if (!XkbIsLegalGroup(group)) /* be defensive */ - PyErr_SetString(virtkey_error, - "invalid effective group"); + PyErr_SetString(virtkey_error, + "invalid effective group"); else{ /* get group name */ if (!cvirt->kbd->names || !cvirt->kbd->names->groups) - PyErr_SetString(virtkey_error, "no group names available"); + PyErr_SetString(virtkey_error, "no group names available"); else{ Atom atom = cvirt->kbd->names->groups[group]; if (atom != None){ char * group_name = XGetAtomName(display, atom); - if (group_name){ + if (group_name){ result = PyString_FromString(group_name); XFree(group_name); } @@ -929,18 +935,18 @@ } } } - + if (PyErr_Occurred()) return NULL; - + if (!result) Py_RETURN_NONE; - + return result; } /* returns a plus-sign separated string of all keyboard layouts */ -static PyObject * virtkey_get_layout_symbols(PyObject * self, +static PyObject * virtkey_get_layout_symbols(PyObject * self, PyObject * noargs) { PyObject * result = NULL; @@ -948,7 +954,7 @@ Display * display = cvirt->display; if (!cvirt->kbd->names || !cvirt->kbd->names->symbols) - PyErr_SetString(virtkey_error, "no symbols names available"); + PyErr_SetString(virtkey_error, "no symbols names available"); else{ char * symbols = XGetAtomName(display, cvirt->kbd->names->symbols); if (symbols){ @@ -992,28 +998,21 @@ /* Callback routines */ -static PyObject * -virtkey_GetAttr(PyObject * self,char * attrname) -{ - return Py_FindMethod(virtkey_methods, self, attrname); -} - static PyObject * virtkey_Repr(PyObject * self) -{ +{ return PyString_FromString("I am a virtkey object"); } /* Type definition */ /* remember the forward declaration above, this is the real definition */ static PyTypeObject virtkey_Type = { - PyObject_HEAD_INIT(&PyType_Type) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT(&PyType_Type, 0) "virtkey", /*tp_name*/ sizeof(virtkey), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor)virtkey_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ - (getattrfunc)virtkey_GetAttr, /*tp_getattr*/ + 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ (reprfunc)virtkey_Repr, /*tp_repr*/ @@ -1028,13 +1027,13 @@ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ "virtkey objects", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + virtkey_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ @@ -1049,27 +1048,50 @@ /* Module functions */ -static PyMethodDef methods[] = { +static PyMethodDef module_methods[] = { {NULL, NULL}, }; /* Module init function */ -void initvirtkey() -{ +#if PY_MAJOR_VERSION >= 3 + static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + "virtkey", /* m_name */ + "virtkey module", /* m_doc */ + -1, /* m_size */ + module_methods, /* m_methods */ + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL, /* m_free */ + }; +#endif + +static PyObject * +moduleinit(void) +{ PyObject *m, *d; /* finish type object initialization */ if (PyType_Ready(&virtkey_Type) < 0) - return; - - m = Py_InitModule("virtkey", methods); + return NULL; + + #if PY_MAJOR_VERSION >= 3 + m = PyModule_Create(&moduledef); + #else + m = Py_InitModule("virtkey", module_methods); + #endif + + if (m == NULL) + return NULL; + d = PyModule_GetDict(m); /* add types here that are allowed to be instantiated from python */ Py_INCREF(&virtkey_Type); PyModule_AddObject(m, "virtkey", (PyObject *)&virtkey_Type); - + /* initialize module variables/constants */ #if PYTHON_API_VERSION >= 1007 @@ -1078,6 +1100,21 @@ virtkey_error = Py_BuildValue("s", "virtkey.error"); #endif PyDict_SetItemString(d, "error", virtkey_error); + + return m; } +#if PY_MAJOR_VERSION < 3 + PyMODINIT_FUNC + initvirtkey(void) + { + moduleinit(); + } +#else + PyMODINIT_FUNC + PyInit_virtkey(void) + { + return moduleinit(); + } +#endif diff -Nru virtkey-0.60.0/src/python-virtkey.h virtkey-0.61.0/src/python-virtkey.h --- virtkey-0.60.0/src/python-virtkey.h 2010-08-13 14:04:00.000000000 +0000 +++ virtkey-0.61.0/src/python-virtkey.h 2012-06-27 18:34:05.000000000 +0000 @@ -7,20 +7,20 @@ * * ------------------------------------------------------------------ * - * This file is part of the python-virtkey library. - * - * python-virtkey is free software: you can redistribute it and/or + * This file is part of the virtkey library. + * + * virtkey is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. - * - * python-virtkey is distributed in the hope that it will be useful, + * + * virtkey 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 Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public - * License along with python-virtkey. If not, see + * License along with virtkey. If not, see * . */ @@ -43,15 +43,15 @@ static PyObject *virtkey_error = NULL; /* type */ -staticforward PyTypeObject virtkey_Type; +static PyTypeObject virtkey_Type; /* object */ typedef struct { PyObject_HEAD char* displayString; Display * display; - - + + int min_keycode, max_keycode; int n_keysyms_per_keycode; KeySym *keysyms; diff -Nru virtkey-0.60.0/src/ucs2keysym.c virtkey-0.61.0/src/ucs2keysym.c --- virtkey-0.60.0/src/ucs2keysym.c 2010-08-13 14:04:00.000000000 +0000 +++ virtkey-0.61.0/src/ucs2keysym.c 2012-06-27 18:35:20.000000000 +0000 @@ -5,23 +5,23 @@ * * ------------------------------------------------------------------ * - * This file is part of the python-virtkey library. - * - * python-virtkey is free software: you can redistribute it and/or + * This file is part of the virtkey library. + * + * virtkey is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. - * - * python-virtkey is distributed in the hope that it will be useful, + * + * virtkey 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 Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public - * License along with python-virtkey. If not, see + * License along with virtkey. If not, see * . */ - + #include "ucs2keysym.h" @@ -825,14 +825,14 @@ else { return keysymtab[mid].keysym; } - + }*/ for(i = 0; i < max; i++){ if (keysymtab[i].ucs == ucs){ return keysymtab[i].keysym; } - } - + } + return ucs | 0x01000000; diff -Nru virtkey-0.60.0/src/ucs2keysym.h virtkey-0.61.0/src/ucs2keysym.h --- virtkey-0.60.0/src/ucs2keysym.h 2010-08-13 14:04:00.000000000 +0000 +++ virtkey-0.61.0/src/ucs2keysym.h 2012-06-27 18:34:46.000000000 +0000 @@ -5,20 +5,20 @@ * * ------------------------------------------------------------------ * - * This file is part of the python-virtkey library. - * - * python-virtkey is free software: you can redistribute it and/or + * This file is part of the virtkey library. + * + * virtkey is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. - * - * python-virtkey is distributed in the hope that it will be useful, + * + * virtkey 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 Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public - * License along with python-virtkey. If not, see + * License along with virtkey. If not, see * . */