* X selections and multi tty
@ 2011-05-26 22:49 Chong Yidong
2011-05-27 0:47 ` Stefan Monnier
0 siblings, 1 reply; 5+ messages in thread
From: Chong Yidong @ 2011-05-26 22:49 UTC (permalink / raw)
To: emacs-devel
I'm doing a cleanup of xselect.c, and came across something puzzling.
AFAIU, clipboards and other X selections are per-X-server, which
corresponds to terminal objects in Emacs (or close enough; each terminal
corresponds to an X display opened by XOpenDisplay).
Emacs currently uses a global variable, Vselection_alist, to keep track
of what X selections it controls. This seems incorrect, and OTOH it
should lead to funky behavior when you use the same Emacs session on two
different X servers.
For instance, Emacs might own the clipboard on two X servers
simultaneously; when it receives a SelectionClear on one, it will act as
though it's lost the clipboard period---when in fact the second X server
still think Emacs owns the clipboard.
The obvious solution seems to be to change Vselection_alist into a
terminal-local variable. However, there exists this code in
x_handle_selection_clear:
/* If the new selection owner is also Emacs,
don't clear the new selection. */
BLOCK_INPUT;
/* Check each display on the same terminal,
to see if this Emacs job now owns the selection
through that display. */
for (t_dpyinfo = x_display_list; t_dpyinfo; t_dpyinfo = t_dpyinfo->next)
if (t_dpyinfo->terminal->kboard == dpyinfo->terminal->kboard)
{
Window owner_window
= XGetSelectionOwner (t_dpyinfo->display, selection);
if (x_window_to_frame (t_dpyinfo, owner_window) != 0)
{
UNBLOCK_INPUT;
return;
}
}
UNBLOCK_INPUT;
This contradicts what I thought: it assumes that if Emacs owns the
selection on a different display, it doesn't need to relinquish
ownership of the selection.
Anyone know what's going on?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: X selections and multi tty
2011-05-26 22:49 X selections and multi tty Chong Yidong
@ 2011-05-27 0:47 ` Stefan Monnier
2011-05-27 2:47 ` Chong Yidong
2011-05-27 3:43 ` Chong Yidong
0 siblings, 2 replies; 5+ messages in thread
From: Stefan Monnier @ 2011-05-27 0:47 UTC (permalink / raw)
To: Chong Yidong; +Cc: emacs-devel
> /* Check each display on the same terminal,
> to see if this Emacs job now owns the selection
> through that display. */
[...]
> This contradicts what I thought: it assumes that if Emacs owns the
> selection on a different display, it doesn't need to relinquish
> ownership of the selection.
I think it only checks to see if it owns the selection *on the same
"display"*, just via some other "terminal" (since several terminals can
share the same display).
This distinction between terminals and displays is pretty subtle and I'm
sure we have bugs around it in the keyboard code. So-called
terminal-local variables are actually keyboard-local (aka
"display"-local), but terminal-parameter is really per-terminal rather
than per-keyboard. And we have somewhat explicit visibility of
terminals but OTOH keyboards are hidden pretty deep from Elisp.
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: X selections and multi tty
2011-05-27 0:47 ` Stefan Monnier
@ 2011-05-27 2:47 ` Chong Yidong
2011-05-27 3:43 ` Chong Yidong
1 sibling, 0 replies; 5+ messages in thread
From: Chong Yidong @ 2011-05-27 2:47 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> I think it only checks to see if it owns the selection *on the same
> "display"*, just via some other "terminal" (since several terminals can
> share the same display).
>
> This distinction between terminals and displays is pretty subtle and I'm
> sure we have bugs around it in the keyboard code. So-called
> terminal-local variables are actually keyboard-local (aka
> "display"-local), but terminal-parameter is really per-terminal rather
> than per-keyboard. And we have somewhat explicit visibility of
> terminals but OTOH keyboards are hidden pretty deep from Elisp.
I see.
The way Vselection_alist is used (i.e. it's looked up when Emacs
receives X events, and we know which X window got the event), we should
be safe making it a terminal parameter. The main thing is not to have a
global variable that can get clobbered by events coming in to windows on
different displays. I'll give that a shot.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: X selections and multi tty
2011-05-27 0:47 ` Stefan Monnier
2011-05-27 2:47 ` Chong Yidong
@ 2011-05-27 3:43 ` Chong Yidong
2011-05-27 12:33 ` Stefan Monnier
1 sibling, 1 reply; 5+ messages in thread
From: Chong Yidong @ 2011-05-27 3:43 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> I think it only checks to see if it owns the selection *on the same
> "display"*, just via some other "terminal" (since several terminals can
> share the same display).
On second thought, I'm still a bit confused. When you say that two
terminals can share the same display, are you literally referring to
pointers to X display structures? i.e.
t1->display_info.x->display == t2->display_info.x->display
with t1 not the same terminal as t2? I don't think that's possible,
since the (Display *) pointers are received from XOpenDisplay in
x_term_init, and each x_display_info has a one to one correspondences
with a terminal.
By "display", I think you're referring to equivalence under
same_x_server(), but with different (Display *) pointers, right?
If that's the case, making Vselection_alist a terminal parameter is
exactly TRT, since interactions with the X server for selection
operations are all done with (Display *).
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: X selections and multi tty
2011-05-27 3:43 ` Chong Yidong
@ 2011-05-27 12:33 ` Stefan Monnier
0 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2011-05-27 12:33 UTC (permalink / raw)
To: Chong Yidong; +Cc: emacs-devel
> On second thought, I'm still a bit confused. When you say that two
> terminals can share the same display, are you literally referring to
> pointers to X display structures? i.e.
No, more like "same X server" (it may even be a different display on
the same server, IIUC).
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-05-27 12:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-26 22:49 X selections and multi tty Chong Yidong
2011-05-27 0:47 ` Stefan Monnier
2011-05-27 2:47 ` Chong Yidong
2011-05-27 3:43 ` Chong Yidong
2011-05-27 12:33 ` Stefan Monnier
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.