Difference between revisions of "X11"

From Noah.org
Jump to navigationJump to search
m
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
[[Category:Engineering]]
 +
= Xorg X-Windows X11R7 =
  
== Get Background color of shell ==
+
== Capture screen shot of the current window ==
  
 +
This works on `xterm` and `gnome-terminal`. It should work on any terminal that defines '''WINDOWID'''.
 +
 +
<pre>
 +
xwd -id $WINDOWID -silent | xwud
 +
</pre>
 +
 +
This is similar but saves output to a PNG file.
 +
 +
<pre>
 +
xwd -id $WINDOWID -silent | xwdtopnm | pnmtopng > terminal_screenshot.png
 +
</pre>
 +
 +
== Get background color of shell ==
 +
 +
This was motivated by the desire to have Vim start with the best color scheme depending on whether the terminal has a dark background or light background. It's sort of a ridiculous thing to do, but Xterm will not report its background color.
 +
 
This is a hack. I'm still working on this.
 
This is a hack. I'm still working on this.
  
Should be average color, but seems to be more like median. Pretty fast:
+
This is the fastest way I found to guess the background color of a given window. This should give average color, but it seems to be more like median.
 
<pre>
 
<pre>
 
time xwd -silent -nobdrs -id $WINDOWID | convert - -gravity center -crop 1x1+0+0 -depth 8 txt:-
 
time xwd -silent -nobdrs -id $WINDOWID | convert - -gravity center -crop 1x1+0+0 -depth 8 txt:-
 
</pre>
 
</pre>
  
Average, Slower:
+
Average color, Slower:
 
<pre>
 
<pre>
 
time xwd -silent -nobdrs -id $WINDOWID | convert - -colors 1 -crop 1x1+0+0 -depth 8 txt:-
 
time xwd -silent -nobdrs -id $WINDOWID | convert - -colors 1 -crop 1x1+0+0 -depth 8 txt:-
 
</pre>
 
</pre>
  
Desktop icon of a window:
+
This makes a Desktop icon of a window:
 
<pre>
 
<pre>
 
time xwd -silent -nobdrs -id $WINDOWID | convert - -crop 32x32+0+0 -depth 8 xpm:-
 
time xwd -silent -nobdrs -id $WINDOWID | convert - -crop 32x32+0+0 -depth 8 xpm:-
 +
</pre>
 +
 +
== Display apps on remote X11 desktop ==
 +
 +
If you xserver was started to listen to TCP port 6000 then this will work. If your Xorg was started with the '''-nolisten''' option then this will '''not''' work. Note that running your X server this way is very insecure. This is the old-fashioned way of doing it. This was invented before they invented security.
 +
 +
On your server you need to allow clients to connect to your display. From a command-line run this command:
 +
<pre>
 +
xhost +
 +
</pre>
 +
 +
On your client machine simply set your DISPLAY to the IP address of the server and then run your X app.
 +
<pre>
 +
export DISPLAY=192.168.1.2:0.0
 +
xclock
 
</pre>
 
</pre>

Latest revision as of 03:00, 15 June 2011

Xorg X-Windows X11R7

Capture screen shot of the current window

This works on `xterm` and `gnome-terminal`. It should work on any terminal that defines WINDOWID.

xwd -id $WINDOWID -silent | xwud

This is similar but saves output to a PNG file.

xwd -id $WINDOWID -silent | xwdtopnm | pnmtopng > terminal_screenshot.png

Get background color of shell

This was motivated by the desire to have Vim start with the best color scheme depending on whether the terminal has a dark background or light background. It's sort of a ridiculous thing to do, but Xterm will not report its background color.

This is a hack. I'm still working on this.

This is the fastest way I found to guess the background color of a given window. This should give average color, but it seems to be more like median.

time xwd -silent -nobdrs -id $WINDOWID | convert - -gravity center -crop 1x1+0+0 -depth 8 txt:-

Average color, Slower:

time xwd -silent -nobdrs -id $WINDOWID | convert - -colors 1 -crop 1x1+0+0 -depth 8 txt:-

This makes a Desktop icon of a window:

time xwd -silent -nobdrs -id $WINDOWID | convert - -crop 32x32+0+0 -depth 8 xpm:-

Display apps on remote X11 desktop

If you xserver was started to listen to TCP port 6000 then this will work. If your Xorg was started with the -nolisten option then this will not work. Note that running your X server this way is very insecure. This is the old-fashioned way of doing it. This was invented before they invented security.

On your server you need to allow clients to connect to your display. From a command-line run this command:

xhost +

On your client machine simply set your DISPLAY to the IP address of the server and then run your X app.

export DISPLAY=192.168.1.2:0.0
xclock