|
| 1 | +# i3ipc-python |
| 2 | + |
| 3 | +An improved Python library to control [i3wm](http://i3wm.org). |
| 4 | + |
| 5 | +## About |
| 6 | + |
| 7 | +i3's interprocess communication (or [ipc](http://i3wm.org/docs/ipc.html)) is the interface i3wm uses to receive [commands](http://i3wm.org/docs/userguide.html#_list_of_commands) from client applications such as `i3-msg`. It also features a publish/subscribe mechanism for notifying interested parties of window manager events. |
| 8 | + |
| 9 | +i3ipc-python is a Python library for controlling the window manager. This project is intended to be useful for general scripting, and for applications that interact with the window manager like status line generators, notification daemons, and pagers. |
| 10 | + |
| 11 | +## Documentation |
| 12 | + |
| 13 | +The latest documentation can be found [here](http://dubstepdish.com/i3ipc-glib). i3ipc-python is a [GObject introspection](https://developer.gnome.org/gobject/stable/) library (kind of like [gtk](https://developer.gnome.org/)). |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +i3ipc-python requires [i3ipc-GLib](https://github.com/acrisci/i3ipc-glib) and [PyGObject](https://wiki.gnome.org/action/show/Projects/PyGObject). |
| 18 | + |
| 19 | +Then simply do: |
| 20 | + |
| 21 | +```shell |
| 22 | +./autogen.sh |
| 23 | +sudo make install |
| 24 | +``` |
| 25 | + |
| 26 | +Or get someone to host a package for your distro. |
| 27 | + |
| 28 | +## Example |
| 29 | + |
| 30 | +```python |
| 31 | +#!/usr/bin/env python3 |
| 32 | + |
| 33 | +from gi.repository import i3ipc |
| 34 | + |
| 35 | +# Create the Connection object that can be used to send commands and subscribe |
| 36 | +# to events. |
| 37 | +conn = i3ipc.Connection() |
| 38 | + |
| 39 | +# Query the ipc for outputs. The result is a list that represents the parsed |
| 40 | +# reply of a command like `i3-msg -t get_outputs`. |
| 41 | +outputs = conn.get_outputs() |
| 42 | + |
| 43 | +print('Active outputs:') |
| 44 | + |
| 45 | +for output in filter(lambda o: o.active, outputs): |
| 46 | + print(output.name) |
| 47 | + |
| 48 | +# Send a command to be executed synchronously. |
| 49 | +conn.command('focus left') |
| 50 | + |
| 51 | +# Define a callback to be called when you switch workspaces. |
| 52 | +def on_workspace(self, e): |
| 53 | + # The first parameter is the connection to the ipc and the second is an object |
| 54 | + # with the data of the event sent from i3. |
| 55 | + if e.current: |
| 56 | + print('Windows on this workspace:') |
| 57 | + for w in e.current.descendents(): |
| 58 | + print(w.name) |
| 59 | + |
| 60 | +# Subscribe to the workspace event |
| 61 | +conn.on('workspace', on_workspace) |
| 62 | + |
| 63 | +# Start the main loop and wait for events to come in. |
| 64 | +conn.main() |
| 65 | +``` |
| 66 | + |
| 67 | +## Contributing |
| 68 | + |
| 69 | +We should do what we can to make this library as "Pythonic" as good tastes allows. New features should be implemented on the main project at [i3ipc-GLib](https://github.com/acrisci/i3ipc-glib). |
| 70 | + |
| 71 | +## License |
| 72 | + |
| 73 | +This work is available under the GNU General Public License (See COPYING). |
| 74 | + |
| 75 | +Copyright © 2014, Tony Crisci |
| 76 | + |
| 77 | +All rights reserved. |
0 commit comments