Skip to main content

An improved Python library for i3wm extensions

Project description

An improved Python library to control i3wm.

About

i3’s interprocess communication (or ipc) is the interface i3wm uses to receive commands from client applications such as i3-msg. It also features a publish/subscribe mechanism for notifying interested parties of window manager events.

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.

If you have an idea for a script to extend i3wm, you can add your script to the examples folder or make a script request on the issue tracker.

Installation

i3ipc is on PyPI.

pip install i3ipc

You’ll also need python-gobject and python-dbus from your package manager.

Example

#!/usr/bin/env python3

import i3ipc

# Create the Connection object that can be used to send commands and subscribe
# to events.
conn = i3ipc.Connection()

# Query the ipc for outputs. The result is a list that represents the parsed
# reply of a command like `i3-msg -t get_outputs`.
outputs = conn.get_outputs()

print('Active outputs:')

for output in filter(lambda o: o.active, outputs):
    print(output.name)

# Send a command to be executed synchronously.
conn.command('focus left')

# Define a callback to be called when you switch workspaces.
def on_workspace(self, e):
    # The first parameter is the connection to the ipc and the second is an object
    # with the data of the event sent from i3.
    if e.current:
        print('Windows on this workspace:')
        for w in e.current.leaves():
            print(w.name)

# Subscribe to the workspace event
conn.on('workspace::focus', on_workspace)

# Start the main loop and wait for events to come in.
conn.main()

Contributing

Please feel free to report bugs, request features or add examples by submitting a pull request.

License

This work is available under a BSD license (see LICENSE)

Copyright © 2015, Tony Crisci

All rights reserved.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

i3ipc-1.1.3.tar.gz (6.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page