一个用于控制i3wm和sway的改进版Python库
项目描述
关于
i3的进程间通信(或ipc)是i3wm从客户端应用程序(如i3-msg)接收命令的接口。它还包含一个发布/订阅机制,用于通知感兴趣方窗口管理器事件。
i3ipc-python是一个用于控制窗口管理器的Python库。该项目旨在对一般脚本和与应用程序交互的窗口管理器(如状态行生成器、通知守护程序和窗口翻页器)有用。
如果您有一个扩展i3wm的脚本的创意,您可以将其添加到示例文件夹中。
有关如何使用库的详细信息,请参阅参考文档。
安装
i3ipc在PyPI上。
pip3 install i3ipc
示例
from i3ipc import Connection, Event
# Create the Connection object that can be used to send commands and subscribe
# to events.
i3 = Connection()
# Print the name of the focused window
focused = i3.get_tree().find_focused()
print('Focused window %s is on workspace %s' %
(focused.name, focused.workspace().name))
# 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 = i3.get_outputs()
print('Active outputs:')
for output in filter(lambda o: o.active, outputs):
print(output.name)
# Send a command to be executed synchronously.
i3.command('focus left')
# Take all fullscreen windows out of fullscreen
for container in i3.get_tree().find_fullscreen():
container.command('fullscreen')
# Print the names of all the containers in the tree
root = i3.get_tree()
print(root.name)
for con in root:
print(con.name)
# Define a callback to be called when you switch workspaces.
def on_workspace_focus(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)
# Dynamically name your workspaces after the current window class
def on_window_focus(i3, e):
focused = i3.get_tree().find_focused()
ws_name = "%s:%s" % (focused.workspace().num, focused.window_class)
i3.command('rename workspace to "%s"' % ws_name)
# Subscribe to events
i3.on(Event.WORKSPACE_FOCUS, on_workspace_focus)
i3.on(Event.WINDOW_FOCUS, on_window_focus)
# Start the main loop and wait for events to come in.
i3.main()
异步支持
asyncio 的支持包含在 i3ipc.aio 包中。接口与阻塞接口类似,但与套接字交互的方法是协程。
from i3ipc.aio import Connection
from i3ipc import Event
import asyncio
async def main():
def on_window(self, e):
print(e)
c = await Connection(auto_reconnect=True).connect()
workspaces = await c.get_workspaces()
c.on(Event.WINDOW, on_window)
await c.main()
asyncio.get_event_loop().run_until_complete(main())
贡献
开发在 Github 上进行。请随时通过提交拉取请求来报告错误、请求功能或添加示例。
许可证
此作品可在 BSD-3-Clause 许可下使用(见 LICENSE)。
版权 © 2015,Tony Crisci
版权所有。
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源代码分布
i3ipc-2.2.1.tar.gz (47.8 kB 查看散列)
构建分布
i3ipc-2.2.1-py3-none-any.whl (26.6 kB 查看散列)
关闭
i3ipc-2.2.1.tar.gz 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | e880d7d7147959ead5cb34764f08b97b41385b36eb8256e8af1ce163dbcccce8 |
|
MD5 | 89dd6be829f5cf40ca6a963151c40709 |
|
BLAKE2b-256 | 61f3dfab70c888d85d3e933ff4d6b351aaed0ae137a29c896e03e364de3bec94 |
关闭
i3ipc-2.2.1-py3-none-any.whl 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | c0b898223d50d42c90c818deb5033d1304c582755547dee7d15df3e3781bc690 |
|
MD5 | 3b937a28550450b9009bcabddb4ca505 |
|
BLAKE2b-256 | de30294b07ddeccb58855c890c3ef3a951c3b0c1e2d089666d548b6a9edc39fb |