Difference between revisions of "Xterm"

From ArchWiki
Jump to: navigation, search
(Introduction)
m
(27 intermediate revisions by 13 users not shown)
Line 1: Line 1:
[[Category:Eye candy (English)]]
+
[[Category:Terminal emulators]]
[[Category:Desktop environments (English)]]
+
[[de:Xterm]]
 +
[[ru:Xterm]]
 +
'''xterm''' is the standard [[Wikipedia:Terminal emulator|terminal emulator]] for the [[X Window System]].
  
== More General Approach ==
+
==Automatic transparency==
This can be done for any application using devilspie. See [[Per Application Transparency]].
+
  
== Introduction ==
+
[[pacman|Install]] the package {{pkg|transset-df}} and a [[Wikipedia:Compositing window manager|composite manager]] like [[Xcompmgr]].
Pacman -S transset-df. Add "xcompmgr &" to .xinitrc, or use another compositing manager. Then add this to openbox's rc.xml(inside chosen keybind/mousebind of course)-
+
  
<action name="execute">
+
Add the following line to your {{ic|~/.bashrc}}:
<execute>sh -c 'xterm &amp; sleep 1s &amp;&amp; transset-df -a'</execute>
+
</action>
+
  
Rest of this page is excessive.
+
[ -n "$XTERM_VERSION" ] && transset-df -a >/dev/null
  
Using openbox, it is as yet impossible to automatically apply transparency to a window as it opens.
+
Now, each time you launch a shell in an xterm and a composite manager is running, it will become transparent.
This is a way of automatically applying tranparency to an opening xterm using transset-df.
+
the test in front of the transset-df command keeps it from executing if that variable is not defined. Note that your terminal will not be transparent if you launch a program other than the shell this way. It is probably possible to work around this if you want the functionality.
It uses a trick of running a script as you start the xterm which then runs another script which calls transset-df.
+
The reason that it is so complicated, is that to run transet-df on the new xterm window as it opens, we need the XWINDOWID value for the window.
+
  
The three steps which happen to run transset-df on an opening xterm are:
+
===See Also===
 +
*[[Per Application Transparency]]
  
* Start xterm
+
==Tips==
* Run a script which executes a command, then starts a bash shell
+
===Xterm menu===
** (This step is necessary because when you open an xterm with 'xterm -e' the command is executed and then the xterm closes. This is not what we want.)
+
Xterm has a hidden menu that can be viewed by holding the {{Keypress|Ctrl}} key and pressing the first mouse button (left click) on a Xterm window.
* Run a script which finds the XWINDOWID of the current xterm and passes it to transset-df to set the transparency
+
  
== Making it work ==
+
===Enable bell urgency===
Make a script in (for instance) /usr/local/bin called '''pre-exec'''. Make sure you have execute permission for everyone. The script is:
+
Add the following line to your {{ic|~/.Xresources}} file:
  
  ${*}
+
  xterm*bellIsUrgent: true
exec /bin/bash
+
  
Make a script in (for instance) /usr/local/bin called '''fader'''. Make sure you have execute permission for everyone. The script is:
+
===Remove black border===
 +
Xterm has a black border in some cases, you can disable this by adding the following line to your {{ic|~/.Xresources}} file.
  
  transset-df -i `set | grep WINDOWID | awk 'BEGIN { FS = "=" } ; { print $2 }'` $1 >/dev/null 2>&1
+
  xterm*borderWidth: 0
  
When you want an xterm to open with a transparency level of 70%, call:
+
===My Alt key doesn't work correctly===
 +
You can fix this on a per-term basis by enabling the Meta Sends Escape option in the Xterm menu, or for all Xterm terminals by adding the following line to your {{ic|~/.Xresources}} file.
  
  xterm -geom 80x50 -T xterm -e /usr/local/bin/pre-exec /usr/local/bin/fader 0.7 &
+
  xterm*metaSendsEscape: true
  
I have put this line in my .config/openbox/menu.xml file so I always get a transparent xterm.
+
===Change background and font color===
 +
First you make an Xresource file which is a regular textfile and it is described at [[X resources]]. You find a color you like at http://www.colorpicker.com/ and copy the 6 alphanumerical above the picture. Then to change your background you add
 +
{{bc|
 +
xterm*background: #<alphanumeric>
 +
}}
 +
and for the font you add
 +
{{bc|
 +
xterm*foreground: #<alphanumeric>
 +
}}
 +
Notice the casing on xterm. It did not work for me with XTerm or Xterm. Also after you make changes and do
 +
{{bc|
 +
xrdb -merge /path/to/Xresources
 +
}}
 +
or
 +
{{bc|
 +
xrdb /path/to/Xresources
 +
}}
 +
you have to start a new xterm window to see the changes.
  
== Explanation ==
+
===Hide the scrollbar===
=== How this doesn't work ===
+
In order to hide xterm's scrollbar, add the following to your .Xresources/.Xdefaults file.
There is some discussion on how to get the correct process id for a launched program.
+
When a shell (in this case gnu bash) is running, it's process id (PID) is found by:
+
echo $$
+
The last process put into the background (like xterm&) is found by:
+
echo $!
+
So, you think - why all this trouble to get the PID of an xterm? Surely you can simply get the PID by doing:
+
xterm & ; echo $!
+
And if you do this at the command line, then this works. You get the PID of the xterm and you can then find the XWINDOWID of the xterm to pass to transset-df. All is well. But who is running xterm when you start it from a menu?
+
The answer is not obvious. If you try to use the $! that is valid in the menu scope, you turn the ''previous'' xterm transparent, not the one you just started.
+
  
=== How this works ===
+
xterm*scrollBar: off
The pre-exec script does two things:
+
* run the commands passed to it in the xterm's bash shell
+
* start a new bash shell
+
The magic comes from
+
${*}
+
which just passes everything on the command line of the script (pre-exec) to the shell which is started because you used the '''-e''' directive. If this was all that happened, then the xterm would immediately exit. But we start a new interactive shell
+
/bin/bash
+
which takes control so there is still an interactive prompt alive in the xterm.
+
 
+
That is quite clever, because it leaves a gap between when the xterm is started with an active shell and when the interactive shell is started up.
+
In that gap, you can run anything you want that needs the same environment as the later interactive shell, but which needs doing before the interactive shell starts. (NB this is a lot like putting something in a .profile or .bashrc file, which will be executed before the interactive prompt when you start a bash shell.)
+
 
+
When the xterm starts its bash shell to execute the '''pre-exec''' script, the automatic environment initialization sets variables like XWINDOWID. The '''fader''' script looks up the XWINDOWID and passes it to transset-df along with the command line argument for the transparency. This command finishes, the new bash shell is started and the shell started by '''-e''' exits, leaving you at a bash prompt.
+
 
+
== Links ==
+
Tried to find the source links for my working on this and they have gone away.
+
Thanks and qudos to all those whose work I've leeched to get this working!
+
 
+
== Problems with this approach ==
+
Your new transparent xterm is called '''pre-exec'''. This can be changed - someone let us all know how :)
+
[edit] Use '-T xterm' on the command line to keep the window called 'xterm'.
+

Revision as of 16:59, 4 November 2012

xterm is the standard terminal emulator for the X Window System.

Automatic transparency

Install the package transset-df and a composite manager like Xcompmgr.

Add the following line to your ~/.bashrc:

[ -n "$XTERM_VERSION" ] && transset-df -a >/dev/null

Now, each time you launch a shell in an xterm and a composite manager is running, it will become transparent. the test in front of the transset-df command keeps it from executing if that variable is not defined. Note that your terminal will not be transparent if you launch a program other than the shell this way. It is probably possible to work around this if you want the functionality.

See Also

Tips

Xterm menu

Xterm has a hidden menu that can be viewed by holding the Template:Keypress key and pressing the first mouse button (left click) on a Xterm window.

Enable bell urgency

Add the following line to your ~/.Xresources file:

xterm*bellIsUrgent: true

Remove black border

Xterm has a black border in some cases, you can disable this by adding the following line to your ~/.Xresources file.

xterm*borderWidth: 0

My Alt key doesn't work correctly

You can fix this on a per-term basis by enabling the Meta Sends Escape option in the Xterm menu, or for all Xterm terminals by adding the following line to your ~/.Xresources file.

xterm*metaSendsEscape: true

Change background and font color

First you make an Xresource file which is a regular textfile and it is described at X resources. You find a color you like at http://www.colorpicker.com/ and copy the 6 alphanumerical above the picture. Then to change your background you add

xterm*background: #<alphanumeric>

and for the font you add

xterm*foreground: #<alphanumeric>

Notice the casing on xterm. It did not work for me with XTerm or Xterm. Also after you make changes and do

xrdb -merge /path/to/Xresources

or

xrdb /path/to/Xresources

you have to start a new xterm window to see the changes.

Hide the scrollbar

In order to hide xterm's scrollbar, add the following to your .Xresources/.Xdefaults file.

xterm*scrollBar: off