xpra icon
Bug tracker and wiki

This bug tracker and wiki are being discontinued
please use https://github.com/Xpra-org/xpra instead.


Ticket #59: xpra-splitxkb.patch

File xpra-splitxkb.patch, 7.7 KB (added by Antoine Martin, 9 years ago)

split some xkb stuff used in xpra/xposix

  • setup.py

     
    5555                    ".".join([str(part) for part in NEEDED_CYTHON])))
    5656
    5757    ext_modules = [
     58      Extension("xpra.xposix.xkb_bindings",
     59                ["xpra/xposix/xkb_bindings.pyx"],
     60                **pkgconfig("pygobject-2.0", "gdk-x11-2.0", "gtk+-x11-2.0",
     61                            "x11")
     62                ),
    5863      Extension("wimpiggy.lowlevel.bindings",
    5964                ["wimpiggy/lowlevel/bindings.pyx"],
    6065                **pkgconfig("pygobject-2.0", "gdk-x11-2.0", "gtk+-x11-2.0",
  • xpra/xposix/xkb_bindings.pyx

    Property changes on: xpra/xposix
    ___________________________________________________________________
    Added: svn:ignore
       + xkb_bindings.c
    
    
     
     1# This file is part of Parti.
     2# Copyright (C) 2010-2012 Antoine Martin <antoine@devloop.org.uk>
     3# Copyright (C) 2008, 2009 Nathaniel Smith <njs@pobox.com>
     4# Parti is released under the terms of the GNU GPL v2, or, at your option, any
     5# later version. See the file COPYING for details.
     6
     7# This file duplicates the code from wimpiggy/lowlevel/bindings.pyx
     8# TODO: As noted in said file, the proper solution is to split it up
     9
     10import struct
     11
     12import gobject
     13import gtk
     14import gtk.gdk
     15
     16from wimpiggy.log import Logger
     17log = Logger("wimpiggy.bell_bindings")
     18
     19###################################
     20# Headers, python magic
     21###################################
     22cdef extern from "gdk/gdk.h":
     23    pass
     24cdef extern from "gdk/gdkx.h":
     25    pass
     26
     27# Serious black magic happens here (I owe these guys beers):
     28cdef extern from "pygobject.h":
     29    void init_pygobject()
     30init_pygobject()
     31
     32cdef extern from "pygtk/pygtk.h":
     33    void init_pygtk()
     34init_pygtk()
     35# Now all the macros in those header files will work.
     36
     37###################################
     38# GObject
     39###################################
     40
     41cdef extern from "glib-2.0/glib-object.h":
     42    ctypedef struct cGObject "GObject":
     43        pass
     44
     45cdef extern from "pygtk-2.0/pygobject.h":
     46    cGObject * pygobject_get(object box)
     47    ctypedef void** const_void_pp "const void**"
     48
     49    # I am naughty; the exposed accessor for PyGBoxed objects is a macro that
     50    # takes a type name as one of its arguments, and thus is impossible to
     51    # wrap from Pyrex; so I just peek into the object directly:
     52    ctypedef struct PyGBoxed:
     53        void * boxed
     54
     55cdef cGObject * unwrap(box, pyclass) except? NULL:
     56    # Extract a raw GObject* from a PyGObject wrapper.
     57    assert issubclass(pyclass, gobject.GObject)
     58    if not isinstance(box, pyclass):
     59        raise TypeError, ("object %r is not a %r" % (box, pyclass))
     60    return pygobject_get(box)
     61
     62###################################
     63# Raw Xlib and GDK
     64###################################
     65
     66include "../../wimpiggy/lowlevel/constants.pxi"
     67ctypedef unsigned long CARD32
     68
     69cdef extern from "X11/Xlib.h":
     70    ctypedef struct Display:
     71        pass
     72    ctypedef CARD32 XID
     73    ctypedef int Bool
     74    ctypedef XID Window
     75    ctypedef CARD32 Atom
     76
     77# gdk_region_get_rectangles (pygtk bug #517099)
     78cdef extern from "gtk-2.0/gdk/gdktypes.h":
     79    ctypedef struct cGdkWindow "GdkWindow":
     80        pass
     81    Window GDK_WINDOW_XID(cGdkWindow *)
     82
     83    ctypedef struct cGdkDisplay "GdkDisplay":
     84        pass
     85    Display * GDK_DISPLAY_XDISPLAY(cGdkDisplay *)
     86
     87    ctypedef void * GdkAtom
     88    GdkAtom PyGdkAtom_Get(object)
     89    Atom gdk_x11_atom_to_xatom_for_display(cGdkDisplay *, GdkAtom)
     90
     91def get_xwindow(pywindow):
     92    return GDK_WINDOW_XID(<cGdkWindow*>unwrap(pywindow, gtk.gdk.Window))
     93
     94def get_display_for(obj):
     95    if isinstance(obj, gtk.gdk.Display):
     96        return obj
     97    elif isinstance(obj, (gtk.gdk.Drawable,
     98                          gtk.Widget,
     99                          gtk.Clipboard)):
     100        return obj.get_display()
     101    else:
     102        raise TypeError, "Don't know how to get a display from %r" % (obj,)
     103
     104def get_xatom(display_source, str_or_xatom):
     105    """Returns the X atom corresponding to the given Python string or Python
     106    integer (assumed to already be an X atom)."""
     107    if isinstance(str_or_xatom, (int, long)):
     108        return str_or_xatom
     109    assert isinstance(str_or_xatom, str)
     110    gdkatom = gtk.gdk.atom_intern(str_or_xatom)
     111    return gdk_x11_atom_to_xatom_for_display(
     112        get_raw_display_for(display_source),
     113        PyGdkAtom_Get(gdkatom),
     114        )
     115
     116cdef cGdkDisplay * get_raw_display_for(obj) except? NULL:
     117    return <cGdkDisplay*> unwrap(get_display_for(obj), gtk.gdk.Display)
     118
     119cdef Display * get_xdisplay_for(obj) except? NULL:
     120    return GDK_DISPLAY_XDISPLAY(get_raw_display_for(obj))
     121
     122cdef extern from "X11/XKBlib.h":
     123    Bool XkbDeviceBell(Display *, Window w, int deviceSpec, int bellClass, int bellID, int percent, Atom name)
     124    Bool XkbGetAutoRepeatRate(Display *, unsigned int deviceSpec, unsigned int *delayRtrn, unsigned int *intervalRtrn)
     125
     126cdef extern from "X11/extensions/XKB.h":
     127    unsigned int XkbUseCoreKbd
     128
     129def get_key_repeat_rate():
     130    cdef Display * display
     131    cdef unsigned int deviceSpec = XkbUseCoreKbd
     132    cdef unsigned int delay = 0
     133    cdef unsigned int interval = 0
     134    display = get_xdisplay_for(gtk.gdk.get_default_root_window())
     135    if not XkbGetAutoRepeatRate(display, deviceSpec, &delay, &interval):
     136        return None
     137    return (delay, interval)
     138
     139def device_bell(pywindow, deviceSpec, bellClass, bellID, percent, name):
     140    cdef Display * display
     141    cdef Window window
     142    display = get_xdisplay_for(pywindow)
     143    window = get_xwindow(pywindow)
     144    name_atom = get_xatom(pywindow, name)
     145    return XkbDeviceBell(display, window, deviceSpec, bellClass, bellID,  percent, name_atom)
  • xpra/xposix/gui.py

     
    187187    def setup_x11_bell(self):
    188188        self.has_x11_bell = False
    189189        try:
    190             from wimpiggy.lowlevel.bindings import device_bell
     190            from xpra.xposix.xkb_bindings import device_bell
    191191            self.has_x11_bell = device_bell is not None
     192            log.info("has_x11_bell=%s, xkb_bindings=%s" % (self.has_x11_bell, device_bell))
    192193        except ImportError, e:
    193194            log.error("cannot import x11 bell bindings (will use gtk fallback) : %s", e)
    194195
     
    222223            self.client.send(["server-settings", {self.ROOT_PROPS[prop]: value.encode("utf-8")}])
    223224
    224225    def system_bell(self, window, device, percent, pitch, duration, bell_class, bell_id, bell_name):
     226        log.info("system_bell(%s,%s,%s,%s,%s,%s,%s,%s)", window, device, percent, pitch, duration, bell_class, bell_id, bell_name)
    225227        if not self.has_x11_bell:
    226228            import gtk.gdk
    227229            gtk.gdk.beep()
    228230            return
    229         from wimpiggy.lowlevel.bindings import device_bell      #@UnresolvedImport
     231        from xpra.xposix.xkb_bindings import device_bell      #@UnresolvedImport
    230232        device_bell(window, device, bell_class, bell_id, percent, bell_name)
    231233
    232234    def can_notify(self):
     
    313315
    314316    def get_keyboard_repeat(self):
    315317        try:
    316             from wimpiggy.lowlevel import get_key_repeat_rate   #@UnresolvedImport
     318            from xpra.xposix.xkb_bindings import get_key_repeat_rate   #@UnresolvedImport
    317319            delay, interval = get_key_repeat_rate()
     320            log.info("=(%s,%s)" % (delay, interval))
    318321            return delay,interval
    319322        except Exception, e:
    320323            log.error("failed to get keyboard repeat rate: %s", e)