mirror of
https://github.com/gryf/wmaker.git
synced 2026-01-08 23:04:15 +01:00
endless loop fix for W_GetSelection when selection is owned by the app itself
This commit is contained in:
@@ -262,7 +262,6 @@ WMCreateSelectionHandler(WMWidget *w, Atom selection, Time timestamp,
|
||||
|
||||
|
||||
|
||||
|
||||
static void
|
||||
timeoutHandler(void *data)
|
||||
{
|
||||
@@ -270,6 +269,55 @@ timeoutHandler(void *data)
|
||||
}
|
||||
|
||||
|
||||
static Bool
|
||||
getInternalSelection(WMScreen *scr, Atom selection, Atom target,
|
||||
void **data, unsigned *length)
|
||||
{
|
||||
Window owner;
|
||||
SelectionHandler *handler;
|
||||
|
||||
/*
|
||||
* Check if the selection is owned by this application and if so,
|
||||
* do the conversion directly.
|
||||
*/
|
||||
|
||||
data = NULL;
|
||||
|
||||
owner = XGetSelectionOwner(scr->display, selection);
|
||||
if (!owner)
|
||||
return False;
|
||||
|
||||
handler = selHandlers;
|
||||
|
||||
while (handler) {
|
||||
if (WMWidgetXID(handler->widget) == owner
|
||||
/* && handler->selection == event->selection*/) {
|
||||
break;
|
||||
}
|
||||
handler = handler->next;
|
||||
}
|
||||
|
||||
if (!handler)
|
||||
return False;
|
||||
|
||||
if (handler->convProc) {
|
||||
Atom atom;
|
||||
int format;
|
||||
|
||||
if (!(*handler->convProc)(handler->widget, handler->selection,
|
||||
target, &atom, data, length, &format)) {
|
||||
return True;
|
||||
}
|
||||
|
||||
if (handler->doneProc) {
|
||||
(*handler->doneProc)(handler->widget, handler->selection, target);
|
||||
}
|
||||
}
|
||||
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
W_GetTextSelection(WMScreen *scr, Atom selection)
|
||||
{
|
||||
@@ -316,8 +364,16 @@ W_GetTextSelection(WMScreen *scr, Atom selection)
|
||||
WMHandlerID timer;
|
||||
int timeout = 0;
|
||||
XEvent ev;
|
||||
unsigned length;
|
||||
|
||||
XDeleteProperty(scr->display, scr->groupLeader, scr->clipboardAtom);
|
||||
|
||||
if (getInternalSelection(scr, selection, XA_STRING, (void**)&data,
|
||||
&length)) {
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
XConvertSelection(scr->display, selection, XA_STRING,
|
||||
scr->clipboardAtom, scr->groupLeader,
|
||||
scr->lastEventTime);
|
||||
@@ -333,7 +389,7 @@ W_GetTextSelection(WMScreen *scr, Atom selection)
|
||||
wwarning("selection retrieval timed out");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* nobody owns the selection or the current owner has
|
||||
* nothing to do with what we need */
|
||||
if (ev.xselection.property == None) {
|
||||
|
||||
Reference in New Issue
Block a user