Skip to content

Commit

Permalink
#812: add X11 selection events to GTK glue code
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@22212 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Mar 22, 2019
1 parent de552ab commit 32b5f29
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 7 deletions.
31 changes: 25 additions & 6 deletions src/xpra/x11/bindings/window_bindings.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ cdef extern from "X11/Xlib.h":
unsigned int state # key or button mask
unsigned int button
Bool same_screen
ctypedef struct XSelectionEvent:
Window requestor
Atom selection
Atom target
Atom property
Time time
# The only way we can learn about override redirects is through MapNotify,
# which means we need to be able to get MapNotify for windows we have
# never seen before, which means we can't rely on GDK:
Expand All @@ -136,6 +142,7 @@ cdef extern from "X11/Xlib.h":
XButtonEvent xbutton
XConfigureEvent xconfigure
XClientMessageEvent xclient
XSelectionEvent xselection

Status XSendEvent(Display *, Window target, Bool propagate,
unsigned long event_mask, XEvent * event)
Expand Down Expand Up @@ -522,11 +529,9 @@ cdef class _X11WindowBindings(_X11CoreBindings):
return depth

# Focus management
def XSetInputFocus(self, Window xwindow, object time=None):
def XSetInputFocus(self, Window xwindow, object time=CurrentTime):
self.context_check()
# Always does RevertToParent
if time is None:
time = CurrentTime
XSetInputFocus(self.display, xwindow, RevertToParent, time)

def XGetInputFocus(self):
Expand Down Expand Up @@ -722,10 +727,8 @@ cdef class _X11WindowBindings(_X11CoreBindings):
self.context_check()
return XGetSelectionOwner(self.display, self.xatom(atom))

def XSetSelectionOwner(self, Window xwindow, atom, time=None):
def XSetSelectionOwner(self, Window xwindow, atom, time=CurrentTime):
self.context_check()
if time is None:
time = CurrentTime
return XSetSelectionOwner(self.display, self.xatom(atom), xwindow, time)

def sendClientMessage(self, Window xtarget, Window xwindow, int propagate, int event_mask,
Expand Down Expand Up @@ -806,6 +809,22 @@ cdef class _X11WindowBindings(_X11CoreBindings):
if s == 0:
raise ValueError("failed to serialize XEmbed Message")

def sendSelectionNotify(self, Window xwindow, selection, time=CurrentTime):
self.context_check()
cdef XEvent e #@DuplicatedSignature
e.type = SelectionNotify
e.xselection.requestor = xwindow
e.xselection.selection = self.xatom(selection)
e.xselection.target = xwindow
e.xselection.time = time
e.xselection.property = 0
cdef Status s #@DuplicatedSignature
s = XSendEvent(self.display, xwindow, True, 0, &e)
if s == 0:
raise ValueError("failed to serialize SelectionNotify")
self.context_check()


def sendConfigureNotify(self, Window xwindow):
self.context_check()
cdef Window root_window
Expand Down
28 changes: 28 additions & 0 deletions src/xpra/x11/gtk2/gdk_bindings.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ cdef extern from "X11/Xlib.h":
Window above
int detail
unsigned long value_mask
ctypedef struct XSelectionRequestEvent:
Window owner
Window requestor
Atom selection
Atom target
Atom property
Time time
ctypedef struct XSelectionClearEvent:
Window window
Atom selection
Time time
ctypedef struct XResizeRequestEvent:
Window window
int width, height
Expand Down Expand Up @@ -240,6 +251,8 @@ cdef extern from "X11/Xlib.h":
XButtonEvent xbutton
XMapRequestEvent xmaprequest
XConfigureRequestEvent xconfigurerequest
XSelectionRequestEvent xselectionrequest
XSelectionClearEvent xselectionclear
XResizeRequestEvent xresizerequest
XCirculateRequestEvent xcirculaterequest
XConfigureEvent xconfigure
Expand Down Expand Up @@ -650,6 +663,8 @@ cdef init_x11_events():
add_x_event_signals({
MapRequest : (None, "child-map-request-event"),
ConfigureRequest : (None, "child-configure-request-event"),
SelectionRequest : ("xpra-selection-request", None),
SelectionClear : ("xpra-selection-clear", None),
FocusIn : ("xpra-focus-in-event", None),
FocusOut : ("xpra-focus-out-event", None),
ClientMessage : ("xpra-client-message-event", None),
Expand Down Expand Up @@ -1033,6 +1048,19 @@ cdef parse_xevent(GdkXEvent * e_gdk) with gil:
pyev.above = e.xconfigurerequest.above
pyev.detail = e.xconfigurerequest.detail
pyev.value_mask = e.xconfigurerequest.value_mask
elif etype == SelectionRequest:
selectionrequest_e = <XSelectionRequestEvent*> e
pyev.window = _gw(d, selectionrequest_e.owner)
pyev.requestor = _gw(d, selectionrequest_e.requestor)
pyev.selection = get_pyatom(d, selectionrequest_e.selection)
pyev.target = get_pyatom(d, selectionrequest_e.target)
pyev.property = get_pyatom(d, selectionrequest_e.property)
pyev.time = selectionrequest_e.time
elif etype == SelectionClear:
selectionclear_e = <XSelectionClearEvent*> e
pyev.window = _gw(d, selectionclear_e.window)
pyev.selection = get_pyatom(d, selectionclear_e.selection)
pyev.time = selectionclear_e.time
elif etype == ResizeRequest:
pyev.window = _gw(d, e.xresizerequest.window)
pyev.width = e.xresizerequest.width
Expand Down
30 changes: 30 additions & 0 deletions src/xpra/x11/gtk3/gdk_bindings.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ cdef extern from "X11/Xlib.h":
Window above
int detail
unsigned long value_mask
ctypedef struct XSelectionRequestEvent:
Window owner
Window requestor
Atom selection
Atom target
Atom property
Time time
ctypedef struct XSelectionClearEvent:
Window window
Atom selection
Time time
ctypedef struct XResizeRequestEvent:
Window window
int width, height
Expand Down Expand Up @@ -266,6 +277,8 @@ cdef extern from "X11/Xlib.h":
XButtonEvent xbutton
XMapRequestEvent xmaprequest
XConfigureRequestEvent xconfigurerequest
XSelectionRequestEvent xselectionrequest
XSelectionClearEvent xselectionclear
XResizeRequestEvent xresizerequest
XCirculateRequestEvent xcirculaterequest
XConfigureEvent xconfigure
Expand Down Expand Up @@ -680,6 +693,8 @@ cdef init_x11_events():
add_x_event_signals({
MapRequest : (None, "child-map-request-event"),
ConfigureRequest : (None, "child-configure-request-event"),
SelectionRequest : ("xpra-selection-request", None),
SelectionClear : ("xpra-selection-clear", None),
FocusIn : ("xpra-focus-in-event", None),
FocusOut : ("xpra-focus-out-event", None),
ClientMessage : ("xpra-client-message-event", None),
Expand Down Expand Up @@ -1011,6 +1026,8 @@ cdef parse_xevent(GdkXEvent * e_gdk) with gil:
cdef XkbAnyEvent * xkb_e
cdef XkbBellNotifyEvent * bell_e
cdef XShapeEvent * shape_e
cdef XSelectionRequestEvent * selectionrequest_e
cdef XSelectionClearEvent * selectionclear_e
cdef object event_args
cdef object d
cdef object pyev
Expand Down Expand Up @@ -1081,6 +1098,19 @@ cdef parse_xevent(GdkXEvent * e_gdk) with gil:
pyev.above = e.xconfigurerequest.above
pyev.detail = e.xconfigurerequest.detail
pyev.value_mask = e.xconfigurerequest.value_mask
elif etype == SelectionRequest:
selectionrequest_e = <XSelectionRequestEvent*> e
pyev.window = _gw(d, selectionrequest_e.owner)
pyev.requestor = _gw(d, selectionrequest_e.requestor)
pyev.selection = get_pyatom(d, selectionrequest_e.selection)
pyev.target = get_pyatom(d, selectionrequest_e.target)
pyev.property = get_pyatom(d, selectionrequest_e.property)
pyev.time = selectionrequest_e.time
elif etype == SelectionClear:
selectionclear_e = <XSelectionClearEvent*> e
pyev.window = _gw(d, selectionclear_e.window)
pyev.selection = get_pyatom(d, selectionclear_e.selection)
pyev.time = selectionclear_e.time
elif etype == ResizeRequest:
pyev.window = _gw(d, e.xresizerequest.window)
pyev.width = e.xresizerequest.width
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/x11/gtk_x11/gdk_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
x11_get_server_time = None
from xpra.x11.gtk3 import gdk_bindings #@UnresolvedImport, @UnusedImport
else:
from gtk import gdk
from gtk import gdk #@UnresolvedImport
x11_get_server_time = gdk.x11_get_server_time
from xpra.x11.gtk2 import gdk_bindings #@UnresolvedImport, @Reimport

Expand Down

0 comments on commit 32b5f29

Please sign in to comment.