How to programatically manipulate application windows?
Anyone know a library, preferably for ruby or python, that will let you access a list of open applications and let you manipulate them? All I really want to be able to do is change their geometry and minimize or close them. I've been messing around with ruby-gnome2 a bit but haven't found anything for manipulating windows other than the ones of your own process.
I'm using 10.10.
Solution 1:
The easiest way to do this would be using wmctrl. You can read man wmctrl
to see how to use it.
sudo apt-get install wmctrl
You could basically bind the command line to a 'Window' class and add methods to it that use wmctrl commands in the background.
class Window
@@windows = []
def self.windows
@@windows
end
def self.get_windows
@@windows.clear
`wmctrl -l`.split("\n").map do |str|
@@windows << self.class.new(str.split(' ')*)
end
end
def initialize window_id, desktop_id, client_machine, window_title
#set up object here
end
#add other methods here
end
That should be a good starting point. It's not tested or anything but you should be able to work it out from here. You could now add instance methods, eg. change_geometry
, which could utilise the -r <WIN> -e <MVARG>
option.
You should familiarise your self with pipes and IO in general before doing this.
Perhaps when you have accomplished what you need to, you can distribute this as a ruby library and package it for Debian/Ubuntu.
Solution 2:
You can use the Extended Window Manager Hints spec to tell the WM to change some windows. This is the trick that wmctrl uses.
Usually you need to use XLib to use EWMH, but for python there is this nice project: PyTile. It's a python program to tile the windows. Not only is it a nice example, it has wrapped the most important functionality into one class. Just download the source and take a look at Probe.py, it does most of what you ask.
This example maximizes all the windows:
import Probe
prob=Probe.Probe()
winlist=prob.get_window_list()
for win in winlist:
prob.window_maximize(win)