[enhancement] Add a "find" command #1809

Closed
Airblader opened this Issue Jul 23, 2015 · 13 comments

Comments

Projects
None yet
4 participants
@Airblader
Member

Airblader commented Jul 23, 2015

I've seen many people ask for a way to see if a window they want to match on is already open. Could we introduce a "find" command for that? It would return true if any window is found which matches the criteria and false otherwise.

[window_role="app"] find

@i3bot i3bot added the enhancement label Jul 23, 2015

@Airblader

This comment has been minimized.

Show comment
Hide comment
@Airblader

Airblader Jul 23, 2015

Member

Note that this can of course be done in external programs but I think it makes sense to be able to use the exact same match mechanism that the super would use afterwards. Given that this is very little code to add I think it's worth implementing unless there's other reasons against it.

The command could even return the number of matched windows.

Member

Airblader commented Jul 23, 2015

Note that this can of course be done in external programs but I think it makes sense to be able to use the exact same match mechanism that the super would use afterwards. Given that this is very little code to add I think it's worth implementing unless there's other reasons against it.

The command could even return the number of matched windows.

@stapelberg

This comment has been minimized.

Show comment
Hide comment
@stapelberg

stapelberg Jul 23, 2015

Member

That sounds reasonable to me. I think it’d be even better if the command returned the IDs of the windows so that you can use the IDs in further commands.

Member

stapelberg commented Jul 23, 2015

That sounds reasonable to me. I think it’d be even better if the command returned the IDs of the windows so that you can use the IDs in further commands.

@Airblader Airblader added the accepted label Jul 23, 2015

@Airblader

This comment has been minimized.

Show comment
Hide comment
@Airblader

Airblader Jul 23, 2015

Member

Great. I'll work on this, though probably not until the weekend / next week since I'll be travelling for the rest of the week.

Member

Airblader commented Jul 23, 2015

Great. I'll work on this, though probably not until the weekend / next week since I'll be travelling for the rest of the week.

@acrisci

This comment has been minimized.

Show comment
Hide comment
@acrisci

acrisci Jul 24, 2015

Member

I don't understand the use case for this. It doesn't seem too useful in a config.

All the info needed to find containers in the tree is already present in the get_tree ipc query. All the advanced ipc libraries have ways to query the tree based on criteria that are much more flexible for the purpose of scripting.

Even in scripts, this isn't a great solution because you need to parse the json output of the result.

Would you provide an actual use of this command to clarify what you are trying to achieve?

Member

acrisci commented Jul 24, 2015

I don't understand the use case for this. It doesn't seem too useful in a config.

All the info needed to find containers in the tree is already present in the get_tree ipc query. All the advanced ipc libraries have ways to query the tree based on criteria that are much more flexible for the purpose of scripting.

Even in scripts, this isn't a great solution because you need to parse the json output of the result.

Would you provide an actual use of this command to clarify what you are trying to achieve?

@Airblader

This comment has been minimized.

Show comment
Hide comment
@Airblader

Airblader Jul 27, 2015

Member

It's true that IPC libraries could do this as well, but I'm also not convinced that this means i3 shouldn't allow to do it by itself. It seems to be requested / asked for again and again so that users are able to, for example, start an application only if it isn't running yet or focus it otherwise.

Having to parse the output is indeed somewhat annoying. Nothing simple command line tools couldn't take care of, though.

Member

Airblader commented Jul 27, 2015

It's true that IPC libraries could do this as well, but I'm also not convinced that this means i3 shouldn't allow to do it by itself. It seems to be requested / asked for again and again so that users are able to, for example, start an application only if it isn't running yet or focus it otherwise.

Having to parse the output is indeed somewhat annoying. Nothing simple command line tools couldn't take care of, though.

@acrisci

This comment has been minimized.

Show comment
Hide comment
@acrisci

acrisci Jul 27, 2015

Member

I'd like to see

  1. an actual example of the command being useful (this may lead to discussion that will improve the feature)

  2. a spec for the command output

How was this accepted without those two things? New ideas should be at least minimally speced and have an example use case to be accepted. This is the process we have used in all the time I have been a contributor and it works very well.

Member

acrisci commented Jul 27, 2015

I'd like to see

  1. an actual example of the command being useful (this may lead to discussion that will improve the feature)

  2. a spec for the command output

How was this accepted without those two things? New ideas should be at least minimally speced and have an example use case to be accepted. This is the process we have used in all the time I have been a contributor and it works very well.

@stapelberg

This comment has been minimized.

Show comment
Hide comment
@stapelberg

stapelberg Jul 28, 2015

Member

Note that “accepted” doesn’t mean “I will merge this feature, no matter what”.

The feature sounds innocent enough that we can verify both of your very valid points at pull request-time. Whenever I ask for more details upfront, that’s mainly to avoid people spending time on the implementation and then having to go back and change a lot or even having their feature rejected. In this case, since @Airblader has enough experience to not spend (potentially wasted) hours on this feature, I didn’t ask upfront :).

Member

stapelberg commented Jul 28, 2015

Note that “accepted” doesn’t mean “I will merge this feature, no matter what”.

The feature sounds innocent enough that we can verify both of your very valid points at pull request-time. Whenever I ask for more details upfront, that’s mainly to avoid people spending time on the implementation and then having to go back and change a lot or even having their feature rejected. In this case, since @Airblader has enough experience to not spend (potentially wasted) hours on this feature, I didn’t ask upfront :).

@acrisci

This comment has been minimized.

Show comment
Hide comment
@acrisci

acrisci Jul 28, 2015

Member

The reason why I have made these requests is not a lack of trust or belief in his work, or because I don't like the feature. I want to see these things to start a discussion about how the feature should work among people who will potentially use it.

After all, even good ideas need to be vigorously defended.

And it's not even a duplication of work because you will no doubt require these things for the documentation anyway.

Member

acrisci commented Jul 28, 2015

The reason why I have made these requests is not a lack of trust or belief in his work, or because I don't like the feature. I want to see these things to start a discussion about how the feature should work among people who will potentially use it.

After all, even good ideas need to be vigorously defended.

And it's not even a duplication of work because you will no doubt require these things for the documentation anyway.

@stapelberg

This comment has been minimized.

Show comment
Hide comment
@stapelberg

stapelberg Jul 28, 2015

Member

Fair enough. @Airblader, can you elaborate on the points @acrisci raised please?

Member

stapelberg commented Jul 28, 2015

Fair enough. @Airblader, can you elaborate on the points @acrisci raised please?

@Airblader

This comment has been minimized.

Show comment
Hide comment
@Airblader

Airblader Jul 29, 2015

Member

Yes, I think those are fair points as well. However, I'm really busy right now and for probably at least the next 2.5 weeks. I'll have to get back to this then.

Member

Airblader commented Jul 29, 2015

Yes, I think those are fair points as well. However, I'm really busy right now and for probably at least the next 2.5 weeks. I'll have to get back to this then.

@Airblader

This comment has been minimized.

Show comment
Hide comment
@Airblader

Airblader Aug 27, 2015

Member

Maybe we could also approach the usecase in an entirely different way by introducing a command (that uses criteria) which will

  • focus the window if one was matched
  • execute some command otherwise

Something like focus_or_exec (working title). It'd be a bit less general, but drastically simplify the process of making the usecase work and also make it clearer what the command is for.

Member

Airblader commented Aug 27, 2015

Maybe we could also approach the usecase in an entirely different way by introducing a command (that uses criteria) which will

  • focus the window if one was matched
  • execute some command otherwise

Something like focus_or_exec (working title). It'd be a bit less general, but drastically simplify the process of making the usecase work and also make it clearer what the command is for.

@stapelberg

This comment has been minimized.

Show comment
Hide comment
@stapelberg

stapelberg Aug 28, 2015

Member

Actually, taking a step back, how about we just make the focus command report success properly? Currently it always reports "success":true, but imagine it reported "success":false, then the following could be used:

[ "$(i3-msg '[class=\"firefox\"] focus')" = "[{\"success\":true\}]" ] || i3-msg exec firefox`

Obviously it’s not very pretty as it’s using a string compare, but you can likely make this a one-liner with any of the higher-level languages that have an i3 ipc library.

Member

stapelberg commented Aug 28, 2015

Actually, taking a step back, how about we just make the focus command report success properly? Currently it always reports "success":true, but imagine it reported "success":false, then the following could be used:

[ "$(i3-msg '[class=\"firefox\"] focus')" = "[{\"success\":true\}]" ] || i3-msg exec firefox`

Obviously it’s not very pretty as it’s using a string compare, but you can likely make this a one-liner with any of the higher-level languages that have an i3 ipc library.

@Airblader

This comment has been minimized.

Show comment
Hide comment
@Airblader

Airblader Aug 28, 2015

Member

Yeah, I think that might be the best choice.

Member

Airblader commented Aug 28, 2015

Yeah, I think that might be the best choice.

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