Question

I've been programming in Linux for years but don't have too much knowledge in the perspective of display. Now I'm asked to write a separate process that will monitor which window (probably not the window created by my process) is focused by the user and do some simple manipulations such as move and resize.

Is it possible? Is there a general way to achieve that? Can someone give any hint I can look into? Thanks!

Was it helpful?

Solution

Use xdotool. It can emulate keystrokes, mouse-actions, find active windows etc.

Example: Run this command in your (non maximized) terminal window and it will jump 10 pixels down and to the right:

xdotool windowmove --relative $(xdotool getwindowfocus) 10 10

It should be available in most distributions, ie sudo apt-get install xdotool or similar for other package managers.

OTHER TIPS

Essentially its the XWindow system that does it all. However you can control a lot of it using simple utilities. For example if I wan to change the title of a VLC window, I can do it like this:

# this will ask me to point to a window and I will point to VLC player
$ xwininfo -all | grep 'xwininfo: Window id:'
xwininfo: Window id: 0x2000011 (has no name)

Here 0x2000011 is the window id of VLC Player running on my system. We can use this window to get or set properties. To do that we can use xprop utility:

for p in _NET_WM_VISIBLE_NAME _NET_WM_NAME; \
   do xprop -id 0x2000011 -format $p 8s -set $p "MyVLC"; done

This will change the window title of VLC Player to MyVLC.

Although this is what xdotool also does behind the scenes, these commands are fairly low level, and are very likely be installed by default.

References:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top