Skip to content

Commit

Permalink
clipboard: Make sure to trap errors on the correct display
Browse files Browse the repository at this point in the history
This probably doesn't actually change anything as the manager's display
is the default display, but make sure to trap errors on the display
we're actually working on instead of the default one.
  • Loading branch information
cwendling committed Apr 26, 2022
1 parent ba311c2 commit 69d147f
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions plugins/clipboard/msd-clipboard-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ send_selection_notify (MsdClipboardManager *manager,
notify.property = success ? manager->priv->property : None;
notify.time = manager->priv->time;

display = gdk_display_get_default ();
gdk_x11_display_error_trap_push (display);
display = gdk_x11_lookup_xdisplay (manager->priv->display);
if (display)
gdk_x11_display_error_trap_push (display);

XSendEvent (manager->priv->display,
manager->priv->requestor,
Expand All @@ -149,7 +150,8 @@ send_selection_notify (MsdClipboardManager *manager,
(XEvent *)&notify);
XSync (manager->priv->display, False);

gdk_x11_display_error_trap_pop_ignored (display);
if (display)
gdk_x11_display_error_trap_pop_ignored (display);
}

static void
Expand All @@ -170,15 +172,17 @@ finish_selection_request (MsdClipboardManager *manager,
notify.property = success ? xev->xselectionrequest.property : None;
notify.time = xev->xselectionrequest.time;

display = gdk_display_get_default ();
gdk_x11_display_error_trap_push (display);
display = gdk_x11_lookup_xdisplay (xev->xselectionrequest.display);
if (display)
gdk_x11_display_error_trap_push (display);

XSendEvent (xev->xselectionrequest.display,
xev->xselectionrequest.requestor,
False, NoEventMask, (XEvent *) &notify);
XSync (manager->priv->display, False);
XSync (xev->xselectionrequest.display, False);

gdk_x11_display_error_trap_pop_ignored (display);
if (display)
gdk_x11_display_error_trap_pop_ignored (display);
}

static int
Expand Down Expand Up @@ -400,24 +404,24 @@ static void
convert_clipboard_manager (MsdClipboardManager *manager,
XEvent *xev)
{
GdkDisplay *display;
Atom type = None;
int format;
unsigned long nitems;
unsigned long remaining;

display = gdk_display_get_default ();

if (xev->xselectionrequest.target == XA_SAVE_TARGETS) {
if (manager->priv->requestor != None || manager->priv->contents != NULL) {
/* We're in the middle of a conversion request, or own
* the CLIPBOARD already
*/
finish_selection_request (manager, xev, False);
} else {
Atom *targets = NULL;
Atom *targets = NULL;
GdkDisplay *display;

gdk_x11_display_error_trap_push (display);
display = gdk_x11_lookup_xdisplay (manager->priv->display);
if (display)
gdk_x11_display_error_trap_push (display);

clipboard_manager_watch_cb (manager,
xev->xselectionrequest.requestor,
Expand All @@ -429,10 +433,11 @@ convert_clipboard_manager (MsdClipboardManager *manager,
StructureNotifyMask);
XSync (manager->priv->display, False);

if (gdk_x11_display_error_trap_pop (display) != Success)
if (display && gdk_x11_display_error_trap_pop (display) != Success)
return;

gdk_x11_display_error_trap_push (display);
if (display)
gdk_x11_display_error_trap_push (display);

if (xev->xselectionrequest.property != None) {
XGetWindowProperty (manager->priv->display,
Expand All @@ -442,7 +447,7 @@ convert_clipboard_manager (MsdClipboardManager *manager,
&type, &format, &nitems, &remaining,
(unsigned char **) &targets);

if (gdk_x11_display_error_trap_pop (display) != Success) {
if (display && gdk_x11_display_error_trap_pop (display) != Success) {
if (targets)
XFree (targets);

Expand Down Expand Up @@ -492,16 +497,13 @@ static void
convert_clipboard_target (IncrConversion *rdata,
MsdClipboardManager *manager)
{
GdkDisplay *display;
TargetData *tdata;
Atom *targets;
int n_targets;
List *list;
unsigned long items;
XWindowAttributes atts;

display = gdk_display_get_default ();

if (rdata->target == XA_TARGETS) {
n_targets = list_length (manager->priv->contents) + 2;
targets = (Atom *) malloc (n_targets * sizeof (Atom));
Expand Down Expand Up @@ -545,10 +547,14 @@ convert_clipboard_target (IncrConversion *rdata,
tdata->type, tdata->format, PropModeReplace,
tdata->data, items);
else {
GdkDisplay *display;

/* start incremental transfer */
rdata->offset = 0;

gdk_x11_display_error_trap_push (display);
display = gdk_x11_lookup_xdisplay (manager->priv->display);
if (display)
gdk_x11_display_error_trap_push (display);

XGetWindowAttributes (manager->priv->display, rdata->requestor, &atts);
XSelectInput (manager->priv->display, rdata->requestor,
Expand All @@ -561,7 +567,8 @@ convert_clipboard_target (IncrConversion *rdata,

XSync (manager->priv->display, False);

gdk_x11_display_error_trap_pop_ignored (display);
if (display)
gdk_x11_display_error_trap_pop_ignored (display);
}
}
}
Expand Down

0 comments on commit 69d147f

Please sign in to comment.