3

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.

3
  • Belongs to stackoverflow.com, because it's about programming.
    – Lekensteyn
    Jan 21, 2011 at 8:51
  • 1
    It is on topic here because it is about programming on Ubuntu, even though Stack Overflow might be able to give better answers.
    – dv3500ea
    Jan 21, 2011 at 9:44
  • i asked a similar question on SO and go almost no response. the response here has been amazing. askubuntu definitely has more knowledge on ubuntu programming than SO.
    – greg
    Jan 21, 2011 at 16:48

3 Answers 3

5

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.

4

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)
2

Hey there, have a look at wmctrl. It's not an actual library, but a command line script that allows window manipulation via command line switches. You'd certainly be able to call it via system.

sudo apt-get install wmctrl

I use it in many shell scripts, and sometimes perl scripts using system()

hth

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .