Skip to content

aio container.workspace() always returns None #176

Open

Description

@wonkalous

Here is a repro:

#!/usr/bin/env python3

import asyncio
import logging

from i3ipc.aio import Connection

SOCKET_FILE = '/tmp/.i3-cycle-focus.sock'

class FocusWatcher:
    def __init__(self):
        self.i3 = None

    async def connect(self):
        self.i3 = await Connection().connect()
        self.i3.on('window::focus', self.on_window_focus)

    async def on_window_focus(self, i3conn, event):
        logging.info('got window focus event')
        ws = await event.container.workspace().name  # ***always returns None***

    async def run(self):
        async def handle_switch(reader, writer):
            data = await reader.read(1024)
            logging.info('received data: {}').format(data)

        server = await asyncio.start_unix_server(handle_switch, SOCKET_FILE)
        await server.serve_forever()

async def run_server():
    focus_watcher = FocusWatcher()
    await focus_watcher.connect()
    await focus_watcher.run()


if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    asyncio.run(run_server())

Activity

  1. acrisci commented on Feb 12, 2021

    @acrisci
    Member

    The way workspace() works is it walks up the tree and finds a workspace. The way the i3ipc works, the event container does not contain the information of the tree. It's just the container without parent information.

    To fix this, get the tree with get_tree(), find the container by id, and then call workspace() on that.

    To fix the issue, I think we should throw an error when workspace information is not present within the tree such as in events to avoid confusion.

  2. wonkalous commented on Feb 12, 2021

    @wonkalous
    Author

    Interesting. Using get_tree was my original plan, but that was also not working, as in #175 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions