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

How to find the currently focused workspace in the Node tree? #39

Open
soenkehahn opened this issue Feb 8, 2019 · 5 comments
Open

How to find the currently focused workspace in the Node tree? #39

soenkehahn opened this issue Feb 8, 2019 · 5 comments

Comments

@soenkehahn
Copy link
Contributor

soenkehahn commented Feb 8, 2019

I'd like to be able to get the Node from the Node tree that represents the currently focused workspace.

I think in the current state a possible solution is to

  • call I3Connection::get_workspaces(),
  • traverse the workspaces and find the one where focused is true,
  • remember the name of that workspace,
  • call I3Connection::get_tree(),
  • traverse the tree to find the node that is a workspace and has the same name.

This seems very cumbersome. Also, I'm not 100% sure workspace names in i3 are guaranteed to always be unique. Are there any better solutions?

Also, would it be in the scope of this library to add a helper function for this?

@tmerr
Copy link
Owner

tmerr commented Feb 8, 2019

I think the solution would be similar to the example in #29, but you would stop the recursion short once Node.nodetype == NodeType::Workspace. I agree this is harder than it needs to be and a helper of some sort would make sense. How about this: we provide an node.iter_focused() function, so you could do:

for n in node.iter_focused() {
  if n.nodetype == NodeType::Workspace {
    ... do something
  }
}

@soenkehahn
Copy link
Contributor Author

While the current workspace has focused set to true in the result of get_workspaces(), that's not true in the Node tree (the result from get_tree()). All the Nodes that are workspaces in there have focused set to false. So your proposed solution wouldn't work, if I understand correctly.

@tmerr
Copy link
Owner

tmerr commented Feb 8, 2019

Only one node in the tree has focused set to true. You can walk from the root of the tree toward it using the method is showed. The steps look something like root -> display -> workspace -> ... -> the focused container. Finding the workspace is a matter of filtering that list for the node with workspace type.

@soenkehahn
Copy link
Contributor Author

Oh, I see. Thanks for explaining. That would indeed work fairly well.

@hasufell
Copy link

hasufell commented Feb 9, 2020

What's the status? the python bindings have this https://i3ipc-python.readthedocs.io/en/latest/con.html#i3ipc.Con under workspace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants