6

I am using Backtrack 5. As it is based on Ubuntu 10.04 I decided to ask my question to here:

I'm having problems selecting text with my mouse. For example when I try to rename a folder, sometimes I can successfully highlight the text but when I release the mouse button, it is no longer highlighted. Sometimes I can't even successfully highlight the part of the text that I want. It highlights more or less of the text then actually selected.

First I thought it was a problem caused by my mouse, however, I tried another mouse and the problem continues. This problem really bothers me while surfing on the net. Could you please help me?

Runium
  • 28,133
  • 5
  • 50
  • 71
Xentius
  • 161
  • 1
  • 2

1 Answers1

15

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.

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501