xlayout
xlayout is a terminal based utility to get and set information about X11 windows and the pointer. Its designed to be easily integrated into bash shell scripts and takes advantage of the X11 protocol to allow it to access remote X11 desktops. With the aid of the libease library, xlayout provides you with the ability to smoothly ease the windows and pointer into position.
Requirements
In order to install xlayout from the source code you need the following:
- You will need a c compiler on your system such as gcc.
- You need to have the X11 header files installed on your system.
- You need to have the standard c libraries installed on your system.
- optional: Installing libease will give you the ability to ease the windows and pointer into position. Please see http://www.stroppytux.net/projects/libease/ for more details.
Downloading xlayout
xlayout can be downloaded directly from the subversion repository or downloaded as a compressed package.
-
Subversion (http://www.stroppytux.net/svn/xlayout/tags/<version>)
When checking out a revision from subversion, you will need to have installed the automake utilities. Once checked out, run ‘autoremake –install’ within the root directory of xlayout. This will build the Makefiles and configure scripts needed to build xlayout.
-
Direct download (http://sourceforge.net/projects/xlayout/)
The packaged source files located on Sourceforge already have the automake scripts run on them, and so, dont need to be run. Simply download the tar.bz2 file and run ‘tar -jxf xlayout-<version>.tar.bz2′.
Building xlayout
In order to build xlayout from source, start by configuring your environment. This is done by executing the ‘./configure’ script in xlayouts root directory with the configure options set. (Refer to ‘./configure –help’ for options.
Once the configuration is done, run the ‘make’ command to compile the source. This will compile xlayout and set the required files to be installed.
Now that you have xlayout compiled, run ‘make install’ to install xlayout, and the man pages and documentation into your system.
Using xlayout
For these examples I am going to start a new X11 session on another tty. This will enable us to use xlayout without fighting with the window manager running on the default desktop. If you use this method, look up how to use the ‘chvt’ command.
Save the bash script below to a file and execute it as a super user (sudo).
#!/bin/bash # starts up an empty X server on localhost:1 export DISPLAY=:1 export XINITRC= X :1 tty9 & xterm -geometry 80x25+20+20 -name terminal1 & xterm -geometry 80x25+20-20 -name terminal2 & xclock -geometry 200x200-20-20 & xmessage -center "Type 'chvt 7' to return to desktop" & xsetroot -solid \#807060 & xlayout -spg 0x0+50+50
Working with the pointer
Getting the pointer coordinates on the current display is done by combining the -p, –pointer and the -i, –info arguments. The output will be the x and y coordinates in pixels of the pointer relative to the top left of the screen. If you would like to parse the output in a bash script, set the verbosity level to 1 by adding the argument -v, –verbose 1.
stroppytux@stroppytux-laptop:~$ xlayout -ip ↵
X Position: 398
Y Position: 530
stroppytux@stroppytux-laptop:~$ xlayout -ipv 1 ↵
398
530
stroppytux@stroppytux-laptop:~$

Now we know the position of the pointer, lets try set the pointer to a new location on the screen. Setting the pointers location is done by combining the -p, –pointer, -s, –set and the -g, –geometry arguments. The geometry argument contains the x, y, width, and height values, but for the pointer only the x and y values are used.
In the example below, we set the width and height to zero as they arn’t used. We then set the pointer to be 50 pixels from the left of the screen, and 50 pixels from the top of the screen. If we wanted to set the pointer starting at the bottom left, we would change the geometry option to be negative. For example 0×0+50-50 would position the pointer 50 pixels from the left, and 50 pixels from the bottom.
If you are embedding this in a bash script, the exist code of zero is returned if the pointer has been position correctly, else an exit code of one is returned. This allows you to use the if [ $? -eq 0 ] syntax.
stroppytux@stroppytux-laptop:~$ xlayout -spg 0x0+50+50 ↵
stroppytux@stroppytux-laptop:~$

Getting a list of windows
To retrieve a list of all the windows running on your current display, use the -l, –list argument.
In the example below, you will notice that the results are indented. Most applications use multiple windows to do tasks like positioning icons, or giving the user the ability to have tabbed windows. The indenting shows you which window is the main parent window, and then shows you its children windows.
The first column contains the windows id in hexadecimal format, then the windows visibility (can be visible, unmapped, unviewable), the windows geometry, the applications name, then the applications title name.
stroppytux@stroppytux-laptop:~$ xlayout -lv 4 ↵
0xa00024 (visible, 270x52+376+357, xmessage, "xmessage")
0xa00025 (visible, 270x52+0+0, unknown, "unknown")
0xa00029 (visible, 260x18+4+4, unknown, "unknown")
0x80000a (visible, 100x100+904+20, xclock "xclock")
0x80000b (visible, 100x100+0+0, unknown "unknown")
0x400016 (visible, 484x329+20+417, terminal2 "stroppytux@stroppytux-laptop: ~")
0x400021 (visible, 484x329+0+0, unknown "unknown")
0x200016 (visible, 484x329+20+20, terminal1 "stroppytux@stroppytux-laptop: ~")
0x200021 (visible, 484x329+0+0, unknown "unknown")
…
stroppytux@stroppytux-laptop:~$

Obtaining a windows information
To get information about a specific window, you combine the -i, –info argument with either the –root argument to get the root windows information, or one of -n, –name or -w, –id. If you use the -w, –id argument, you need to enter the full hexadecimal value of the window (eg. 0x80000a). If you use the -n, –name argument, provide the application name of the window. When using the -n, –name argument, the first window to match the name will be used.
stroppytux@stroppytux-laptop:~$ xlayout -in xclock ↵
Window Name: xclock
WM Name: xclock
Window id: 0x80000a
geometry: 200x200+804+548
X Position: 804
Y Position: 548
Window Width: 200
Window Height: 200
Border Width: 1
Map state: visible
Type: InputOnly
Overridable: true
stroppytux@stroppytux-laptop:~$

Setting a windows pisition and size
Setting a windows size and position is done using a combination of the -s, –set argument and one of -n, –name or -w, –id arguments and the -g, –geometry argument. For more information on how the geometry argument works, please refer to the pointer description above.
stroppytux@stroppytux-laptop:~$ xlayout -sw 0x80000a -g 100x100-20+20 ↵
stroppytux@stroppytux-laptop:~$


