Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aio container.workspace() always returns None #176

Open
wonkalous opened this issue Feb 9, 2021 · 2 comments
Open

aio container.workspace() always returns None #176

wonkalous opened this issue Feb 9, 2021 · 2 comments
Assignees
Labels

Comments

@wonkalous
Copy link

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())
@acrisci
Copy link
Member

acrisci commented Feb 12, 2021

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.

@wonkalous
Copy link
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
Labels
Projects
None yet
Development

No branches or pull requests

2 participants