Possibly something is constantly stealing the X selection. To find out who it is. You could compile this:
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
int main() {
printf("%#lx\n", XGetSelectionOwner (XOpenDisplay(0), XA_PRIMARY));
return 0;
}
With:
gcc that-file.c -lX11
That code is to return the window ID of the owner of the PRIMARY X selection. Then you could use xdotool to get the PID of the process that owns that window (assuming that Window is from a local client and that it lets the Window Manager know its PID):
ps -fp "$(xdotool getwindowpid "$(./a.out)")"
If you don't have xdotool, you can do it the hard way: you can look up that window ID in the output of xwininfo -root -all:
xwininfo -root -all | less "+/$(./a.out)"
The window that owns the selection may not have a name, but you can look at its parent or grandparent for more clue. Once you find the ancestor that is managed by the Window manager, you can get the process ID (assuming the window is from a local process) with:
xprop -id that-id _NET_WM_PID
Example:
$ xwininfo -root -wm -tree | grep -B3 "$(./a.out)"
24 children:
0x2800024 "Sun 12 May - 21:40 - zsh (2)": ("xterm" "XTerm") 1920x1059+0+19 +0+19
1 child:
0x280002f (has no name): () 1920x1059+0+0 +0+19
0x280002f owns the PRIMARY selection, whose parent is "xterm" (0x2800024 managed by the Window Manager).
$ xprop -id 0x2800024 _NET_WM_PID
_NET_WM_PID(CARDINAL) = 9707
$ ps -fp 9707
UID PID PPID C STIME TTY TIME CMD
chazelas 9707 1 0 08:50 ? 00:00:02 xterm
And that's its pid.
Once you know who owns that selection, it may become clearer what's happening.