Thanks for your cool project.
When I do the following, exit status is 0.
$ swayr switch-to-mark-or-urgent-or-lru-window non_existent_mark
$ echo $?
0
$
I thought that if exit status is non-zero when there is no item to switch to, it would be simple to express a process such as starting a program, as shown below.
~/.config/sway/config
for_window [app_id="firefox"] mark "browser"
bindsym $mod+ctrl+b exec swayr switch-to-mark-or-urgent-or-lru-window browser || firefox
Hi, right now, the swayr client (the
swayr
executable) only sends a command to the demonswayrd
which executes it but doesn't propagate any indication of success back to the client. Therefore, it always returns zero (unless there's a crash).That said, that could be changed. But then I'd have to evaluate what a success or failure means for each command. In your concrete example of
switch-to-mark-or-urgent-or-lru-window
with a non-existing mark, I'd actually say this is no erroneous case at all. It will just switch to an urgent or to the LRU window which is the documented behavior in that case (ditto if you the current window has the requested mark).Anyway, I can see how this could be useful at least when using
swayr
in scripts. I will have a look at some point in time but right now I'm slowly working on #22 as time permits. :-)
Thank you🤤 I'm currently working on this dirty hack. https://paste.sr.ht/~tkna/7883cba0fdee32c9dcd80574012a386686a5008f I would be happy to consider it again at a time of your choosing.
I'm now done implementing proper criteria queries on the
next
branch, i.e.,switch-to-matching-or-urgent-or-lru-window
now parses and interprets the criteria itself instead of just feeding it tosway
and observing if a focus change happens.And all
switch-to-XXX-or-urgent-or-lru-window
are now cycling commands instead of toggles, i.e., they cycle through all urgent windows, then through windows matching XXX (e.g., name, mark, criteria query), then to the window being the LRU at the start of the sequence, and then back again to where the sequence started. (This may sound as if such a sequence would be very long but usually there are no or just one urgent window, only few windows matching XXX, and obviously no window will be visited twice in a sequence.)
Thanks. I look forward to it.
I started working on this task. It's quite some effort so might take some time.
I was writing a dirty shell script like this. I hope this is helpful. https://paste.sr.ht/~tkna/43f20674a435dff945b97c8899fc702f24d8423c I think it would help a lot of people if this could be a standard feature.
I imagined a way to do something like this if only to run it when swayr can't find the switch destination.
swayr switch-to-app-or-urgent-or-lru-window firefox --skip-lru --or-exec firefox
I also imagined the following as a case where exit is non-zero when there is no such object.
swayr switch-to-app-or-urgent-or-lru-window firefox --skip-lru --check || firefox
I call the above shell script like this https://paste.sr.ht/~tkna/30c89c621d13e8b6df6840a1b7037d816519993a
On the
main
branch, allswitch-to-*-window
commands now returns non-zero if there's no window to be switched to, so yourswayr switch-to-app-or-urgent-or-lru-window firefox --skip-lru --check || firefox
should just work there. In the positive case, they now also tell you what window they focused and the reason it did.Please give it a try if you can build from source.
Thanks. I'll give it some thought and test it.
Test1:
I looked for a pattern where the expected value is "exit is non-zero" but "exit=0".
The
switch-to-urgent-or-lru-window
was excluded from the test because it does not specify a target.$ pacman -Q swayr-git swayr-git r418.55f4c89-1 $
$ cat swayr-test.sh #!/bin/bash testid=a1 ; swayr switch-to-app-or-urgent-or-lru-window NONE --skip-urgent --skip-lru --skip-origin ; echo $testid=$? testid=a2 ; swayr switch-to-app-or-urgent-or-lru-window NONE --skip-urgent ; echo $testid=$? testid=a3 ; swayr switch-to-app-or-urgent-or-lru-window NONE --skip-lru ; echo $testid=$? testid=a4 ; swayr switch-to-app-or-urgent-or-lru-window NONE --skip-origin ; echo $testid=$? testid=a5 ; swayr switch-to-app-or-urgent-or-lru-window NONE --skip-urgent --skip-lru ; echo $testid=$? testid=a6 ; swayr switch-to-app-or-urgent-or-lru-window NONE --skip-lru --skip-origin ; echo $testid=$? testid=a7 ; swayr switch-to-app-or-urgent-or-lru-window NONE --skip-urgent --skip-origin ; echo $testid=$? testid=a8 ; swayr switch-to-app-or-urgent-or-lru-window NONE ; echo $testid=$? testid=b1 ; swayr switch-to-mark-or-urgent-or-lru-window NONE --skip-urgent --skip-lru --skip-origin ; echo $testid=$? testid=b2 ; swayr switch-to-mark-or-urgent-or-lru-window NONE --skip-urgent ; echo $testid=$? testid=b3 ; swayr switch-to-mark-or-urgent-or-lru-window NONE --skip-lru ; echo $testid=$? testid=b4 ; swayr switch-to-mark-or-urgent-or-lru-window NONE --skip-origin ; echo $testid=$? testid=b5 ; swayr switch-to-mark-or-urgent-or-lru-window NONE --skip-urgent --skip-lru ; echo $testid=$? testid=b6 ; swayr switch-to-mark-or-urgent-or-lru-window NONE --skip-lru --skip-origin ; echo $testid=$? testid=b7 ; swayr switch-to-mark-or-urgent-or-lru-window NONE --skip-urgent --skip-origin ; echo $testid=$? testid=b8 ; swayr switch-to-mark-or-urgent-or-lru-window NONE ; echo $testid=$? testid=c1 ; swayr switch-to-matching-or-urgent-or-lru-window '[app_id="NONE"]' --skip-urgent --skip-lru --skip-origin ; echo $testid=$? testid=c2 ; swayr switch-to-matching-or-urgent-or-lru-window '[app_id="NONE"]' --skip-urgent ; echo $testid=$? testid=c3 ; swayr switch-to-matching-or-urgent-or-lru-window '[app_id="NONE"]' --skip-lru ; echo $testid=$? testid=c4 ; swayr switch-to-matching-or-urgent-or-lru-window '[app_id="NONE"]' --skip-origin ; echo $testid=$? testid=c5 ; swayr switch-to-matching-or-urgent-or-lru-window '[app_id="NONE"]' --skip-urgent --skip-lru ; echo $testid=$? testid=c6 ; swayr switch-to-matching-or-urgent-or-lru-window '[app_id="NONE"]' --skip-lru --skip-origin ; echo $testid=$? testid=c7 ; swayr switch-to-matching-or-urgent-or-lru-window '[app_id="NONE"]' --skip-urgent --skip-origin ; echo $testid=$? testid=c8 ; swayr switch-to-matching-or-urgent-or-lru-window '[app_id="NONE"]' ; echo $testid=$? $
The "exit=0" is shown below.
a2=0 a4=0 a7=0 a8=0 b2=0 b4=0 b7=0 b8=0 c2=0 c4=0 c7=0 c8=0
The result is as follows
$ ./swayr-test.sh Error: "Nothing to be switched to." a1=1 Focused node with id 12 because it's the LRU window. a2=0 Error: "Nothing to be switched to." a3=1 Focused node with id 9 because it's the LRU window. a4=0 Error: "Nothing to be switched to." a5=1 Error: "Nothing to be switched to." a6=1 Focused node with id 12 because it's the LRU window. a7=0 Focused node with id 9 because it's the LRU window. a8=0 Error: "Nothing to be switched to." b1=1 Focused node with id 12 because it's the LRU window. b2=0 Error: "Nothing to be switched to." b3=1 Focused node with id 9 because it's the LRU window. b4=0 Error: "Nothing to be switched to." b5=1 Error: "Nothing to be switched to." b6=1 Focused node with id 12 because it's the LRU window. b7=0 Focused node with id 9 because it's the LRU window. b8=0 Error: "Nothing to be switched to." c1=1 Focused node with id 12 because it's the LRU window. c2=0 Error: "Nothing to be switched to." c3=1 Focused node with id 9 because it's the LRU window. c4=0 Error: "Nothing to be switched to." c5=1 Error: "Nothing to be switched to." c6=1 Focused node with id 12 because it's the LRU window. c7=0 Focused node with id 9 because it's the LRU window. c8=0 $
So I assume the tests suggest everything's working correctly, right? Well, you haven't tested the positive case where the target does indeed exist (but I did). Thanks!
Test2:
The switch to a single window was checked below.
Start one alacritty and mark it with "A"
Start kitty and execute the following commands
while true ; do sleep 5 ; echo -e "\a" ; done
Execute the following command to delete the log file.
rm /tmp/swayr-test.log
In the following configuration
test.conf
, press the corresponding key multiple times (5 or more times) and check for any discrepancies compared to the intended behavior.Verify that there is no result other than exit 0 with the following command
sort -u /tmp/swayr-test.log
test.conf
set $mode_test "Test2 key[*]?" mode $mode_test { # There is one alacritty => switch bindsym a exec swayr switch-to-app-or-urgent-or-lru-window Alacritty --skip-urgent --skip-lru --skip-origin || echo "a" >> /tmp/swayr-test.log bindsym b exec swayr switch-to-app-or-urgent-or-lru-window Alacritty --skip-urgent || echo "b" >> /tmp/swayr-test.log bindsym c exec swayr switch-to-app-or-urgent-or-lru-window Alacritty --skip-lru || echo "c" >> /tmp/swayr-test.log bindsym d exec swayr switch-to-app-or-urgent-or-lru-window Alacritty --skip-origin || echo "d" >> /tmp/swayr-test.log bindsym e exec swayr switch-to-app-or-urgent-or-lru-window Alacritty --skip-urgent --skip-lru || echo "e" >> /tmp/swayr-test.log bindsym f exec swayr switch-to-app-or-urgent-or-lru-window Alacritty --skip-lru --skip-origin || echo "f" >> /tmp/swayr-test.log bindsym g exec swayr switch-to-app-or-urgent-or-lru-window Alacritty --skip-urgent --skip-origin || echo "g" >> /tmp/swayr-test.log bindsym h exec swayr switch-to-app-or-urgent-or-lru-window Alacritty || echo "h" >> /tmp/swayr-test.log bindsym i exec swayr switch-to-mark-or-urgent-or-lru-window A --skip-urgent --skip-lru --skip-origin || echo "i" >> /tmp/swayr-test.log bindsym j exec swayr switch-to-mark-or-urgent-or-lru-window A --skip-urgent || echo "j" >> /tmp/swayr-test.log bindsym k exec swayr switch-to-mark-or-urgent-or-lru-window A --skip-lru || echo "k" >> /tmp/swayr-test.log bindsym l exec swayr switch-to-mark-or-urgent-or-lru-window A --skip-origin || echo "l" >> /tmp/swayr-test.log bindsym m exec swayr switch-to-mark-or-urgent-or-lru-window A --skip-urgent --skip-lru || echo "m" >> /tmp/swayr-test.log bindsym n exec swayr switch-to-mark-or-urgent-or-lru-window A --skip-lru --skip-origin || echo "n" >> /tmp/swayr-test.log bindsym o exec swayr switch-to-mark-or-urgent-or-lru-window A --skip-urgent --skip-origin || echo "o" >> /tmp/swayr-test.log bindsym p exec swayr switch-to-mark-or-urgent-or-lru-window A || echo "p" >> /tmp/swayr-test.log bindsym q exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="Alacritty"]' --skip-urgent --skip-lru --skip-origin || echo "q" >> /tmp/swayr-test.log bindsym r exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="Alacritty"]' --skip-urgent || echo "r" >> /tmp/swayr-test.log bindsym s exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="Alacritty"]' --skip-lru || echo "s" >> /tmp/swayr-test.log bindsym t exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="Alacritty"]' --skip-origin || echo "t" >> /tmp/swayr-test.log bindsym u exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="Alacritty"]' --skip-urgent --skip-lru || echo "u" >> /tmp/swayr-test.log bindsym v exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="Alacritty"]' --skip-lru --skip-origin || echo "v" >> /tmp/swayr-test.log bindsym w exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="Alacritty"]' --skip-urgent --skip-origin || echo "w" >> /tmp/swayr-test.log bindsym x exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="Alacritty"]' || echo "x" >> /tmp/swayr-test.log # back to normal: Escape bindsym Escape mode "default" } bindsym $mod+t mode $mode_test
Result: From what I could see, I did not find any particular discrepancies in operation. However, the following seems to have become non-exit 0.
a c e f i k m n q s u v
Test3:
I have checked below to see if I switch to multiple windows.
Activate at least two foot and mark "F".
Start kitty and execute the following commands
while true ; do sleep 5 ; echo -e "\a" ; done
Execute the following command to delete the log file.
rm /tmp/swayr-test.log
In the following configuration
test.conf
, press the corresponding key multiple times (5 or more times) and check for any discrepancies compared to the intended behavior.Verify that there is no result other than exit 0 with the following command
sort -u /tmp/swayr-test.log
test.conf
set $mode_test "Test3 key[*]?" mode $mode_test { # Multiple foot => switch to multiple bindsym a exec swayr switch-to-app-or-urgent-or-lru-window foot --skip-urgent --skip-lru --skip-origin || echo "a" >> /tmp/swayr-test.log bindsym b exec swayr switch-to-app-or-urgent-or-lru-window foot --skip-urgent || echo "b" >> /tmp/swayr-test.log bindsym c exec swayr switch-to-app-or-urgent-or-lru-window foot --skip-lru || echo "c" >> /tmp/swayr-test.log bindsym d exec swayr switch-to-app-or-urgent-or-lru-window foot --skip-origin || echo "d" >> /tmp/swayr-test.log bindsym e exec swayr switch-to-app-or-urgent-or-lru-window foot --skip-urgent --skip-lru || echo "e" >> /tmp/swayr-test.log bindsym f exec swayr switch-to-app-or-urgent-or-lru-window foot --skip-lru --skip-origin || echo "f" >> /tmp/swayr-test.log bindsym g exec swayr switch-to-app-or-urgent-or-lru-window foot --skip-urgent --skip-origin || echo "g" >> /tmp/swayr-test.log bindsym h exec swayr switch-to-app-or-urgent-or-lru-window foot || echo "h" >> /tmp/swayr-test.log bindsym i exec swayr switch-to-mark-or-urgent-or-lru-window F --skip-urgent --skip-lru --skip-origin || echo "i" >> /tmp/swayr-test.log bindsym j exec swayr switch-to-mark-or-urgent-or-lru-window F --skip-urgent || echo "j" >> /tmp/swayr-test.log bindsym k exec swayr switch-to-mark-or-urgent-or-lru-window F --skip-lru || echo "k" >> /tmp/swayr-test.log bindsym l exec swayr switch-to-mark-or-urgent-or-lru-window F --skip-origin || echo "l" >> /tmp/swayr-test.log bindsym m exec swayr switch-to-mark-or-urgent-or-lru-window F --skip-urgent --skip-lru || echo "m" >> /tmp/swayr-test.log bindsym n exec swayr switch-to-mark-or-urgent-or-lru-window F --skip-lru --skip-origin || echo "n" >> /tmp/swayr-test.log bindsym o exec swayr switch-to-mark-or-urgent-or-lru-window F --skip-urgent --skip-origin || echo "o" >> /tmp/swayr-test.log bindsym p exec swayr switch-to-mark-or-urgent-or-lru-window F || echo "p" >> /tmp/swayr-test.log bindsym q exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="foot"]' --skip-urgent --skip-lru --skip-origin || echo "q" >> /tmp/swayr-test.log bindsym r exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="foot"]' --skip-urgent || echo "r" >> /tmp/swayr-test.log bindsym s exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="foot"]' --skip-lru || echo "s" >> /tmp/swayr-test.log bindsym t exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="foot"]' --skip-origin || echo "t" >> /tmp/swayr-test.log bindsym u exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="foot"]' --skip-urgent --skip-lru || echo "u" >> /tmp/swayr-test.log bindsym v exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="foot"]' --skip-lru --skip-origin || echo "v" >> /tmp/swayr-test.log bindsym w exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="foot"]' --skip-urgent --skip-origin || echo "w" >> /tmp/swayr-test.log bindsym x exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="foot"]' || echo "x" >> /tmp/swayr-test.log # back to normal: Escape bindsym Escape mode "default" } bindsym $mod+t mode $mode_test
Result: From what I could see, I did not find any particular discrepancies in operation. However, the following seems to have become non-exit 0.
i m n
Well, have a look at the text output. For example,
swayr switch-to-app-or-urgent-or-lru-window Alacritty --skip-urgent --skip-lru --skip-origin
cannot switch anywhere when the only matching window is already the current one.
I didn't find any problems with the operation of the switch itself, but I imagine that exit should be 0 since all the targets are present. How do you feel about this?
I imagine it is correct that everything about Test1 will be Non-zero exit status, since there is no target.
Hm, I think it would probably better to return zero (but still do nothing) if the current window is already the only matching window. Otherwise, the
swayr switch-to-app... firefox || firefox
trick would not work, i.e., it would spawn a new firefox window in case the existing window has the focus already. Agreed?
Yes!
At least that is true for
Test2-a,i,q
.
I've implemented that behavior. It should now say "The single matching window XXX is already focused." and return zero.
$ pacman -Q swayr-git swayr-git r419.da10661-1 $
The following seems to have become non-exit 0.
Test2-c Test3-k
Test4:
I have checked the following to see if it non-zero exits due to no target.
Start kitty and execute the following commands
while true ; do sleep 5 ; echo -e "\a" ; done
Execute the following command to delete the log file.
rm /tmp/swayr-test.log
In the following configuration
test.conf
, press the corresponding key multiple times (5 or more times) and check for any discrepancies compared to the intended behavior.Verify that there is no result exit 0 with the following command
sort -u /tmp/swayr-test.log
test.conf
set $mode_test "Test4 key[*]?" mode $mode_test { # No target (NONE) => Non-zero exit. bindsym a exec swayr switch-to-app-or-urgent-or-lru-window NONE --skip-urgent --skip-lru --skip-origin && echo "a" >> /tmp/swayr-test.log bindsym b exec swayr switch-to-app-or-urgent-or-lru-window NONE --skip-urgent && echo "b" >> /tmp/swayr-test.log bindsym c exec swayr switch-to-app-or-urgent-or-lru-window NONE --skip-lru && echo "c" >> /tmp/swayr-test.log bindsym d exec swayr switch-to-app-or-urgent-or-lru-window NONE --skip-origin && echo "d" >> /tmp/swayr-test.log bindsym e exec swayr switch-to-app-or-urgent-or-lru-window NONE --skip-urgent --skip-lru && echo "e" >> /tmp/swayr-test.log bindsym f exec swayr switch-to-app-or-urgent-or-lru-window NONE --skip-lru --skip-origin && echo "f" >> /tmp/swayr-test.log bindsym g exec swayr switch-to-app-or-urgent-or-lru-window NONE --skip-urgent --skip-origin && echo "g" >> /tmp/swayr-test.log bindsym h exec swayr switch-to-app-or-urgent-or-lru-window NONE && echo "h" >> /tmp/swayr-test.log bindsym i exec swayr switch-to-mark-or-urgent-or-lru-window N --skip-urgent --skip-lru --skip-origin && echo "i" >> /tmp/swayr-test.log bindsym j exec swayr switch-to-mark-or-urgent-or-lru-window N --skip-urgent && echo "j" >> /tmp/swayr-test.log bindsym k exec swayr switch-to-mark-or-urgent-or-lru-window N --skip-lru && echo "k" >> /tmp/swayr-test.log bindsym l exec swayr switch-to-mark-or-urgent-or-lru-window N --skip-origin && echo "l" >> /tmp/swayr-test.log bindsym m exec swayr switch-to-mark-or-urgent-or-lru-window N --skip-urgent --skip-lru && echo "m" >> /tmp/swayr-test.log bindsym n exec swayr switch-to-mark-or-urgent-or-lru-window N --skip-lru --skip-origin && echo "n" >> /tmp/swayr-test.log bindsym o exec swayr switch-to-mark-or-urgent-or-lru-window N --skip-urgent --skip-origin && echo "o" >> /tmp/swayr-test.log bindsym p exec swayr switch-to-mark-or-urgent-or-lru-window N && echo "p" >> /tmp/swayr-test.log bindsym q exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="NONE"]' --skip-urgent --skip-lru --skip-origin && echo "q" >> /tmp/swayr-test.log bindsym r exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="NONE"]' --skip-urgent && echo "r" >> /tmp/swayr-test.log bindsym s exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="NONE"]' --skip-lru && echo "s" >> /tmp/swayr-test.log bindsym t exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="NONE"]' --skip-origin && echo "t" >> /tmp/swayr-test.log bindsym u exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="NONE"]' --skip-urgent --skip-lru && echo "u" >> /tmp/swayr-test.log bindsym v exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="NONE"]' --skip-lru --skip-origin && echo "v" >> /tmp/swayr-test.log bindsym w exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="NONE"]' --skip-urgent --skip-origin && echo "w" >> /tmp/swayr-test.log bindsym x exec swayr switch-to-matching-or-urgent-or-lru-window '[app_id="NONE"]' && echo "x" >> /tmp/swayr-test.log # back to normal: Escape bindsym Escape mode "default" } bindsym $mod+t mode $mode_test
Result: Each has a movement that follows the default behavior. Since there is no object to switch, I feel it is correct that all movements are "do nothing" and Non-zero exit. The following seems to have become exit 0.
a c e f i k m n q s u v
Please don't make it so time-consuming for me and interpret your results yourself. I only want the executive summary, i.e., when something is not as expected. :-)
My interpretation is as follows.
- Test2 and 3 are all zero exit because there is a target
- Test4 has no target, so it does nothing and non-zero exit.
I have tried to summarize the problem by covering the pattern in my own simple way, but I am sorry if I offended you.
No, no, you didn't offend me at all and I'm thankful for your thorough testing! It's just that it takes more time than I have to go through all your test cases and evaluate myself if the result is sensible. So better just tell if a command doesn't deliver the expected/sensible result.
I tried to reproduce the following problem again clear, but could not. Sorry for the trouble. I should have double-checked. Please forget about this. I will try to write as much as possible in an easy-to-understand, individualized and specific manner.
Test2-c swayr switch-to-app-or-urgent-or-lru-window Alacritty --skip-lru Test3-k swayr switch-to-mark-or-urgent-or-lru-window F --skip-lru
For the following cases where there is no target, it seems to me that it would be better to do nothing and leave it to non-zero exit, what do you think?
swayr switch-to-app-or-urgent-or-lru-window NONE --skip-urgent --skip-lru --skip-origin swayr switch-to-mark-or-urgent-or-lru-window N --skip-urgent swayr switch-to-matching-or-urgent-or-lru-window '[app_id="NONE"]'
Concerning the last 3 cases:
swayr switch-to-app-or-urgent-or-lru-window NONE --skip-urgent --skip-lru --skip-origin # returns non-zero with Error: "Nothing to be switched to." swayr switch-to-mark-or-urgent-or-lru-window N --skip-urgent # This might switch to a window whose app_id contains an N. Note that the argument # is taken as a regular expression, so if you want "equals exactly N" write '^N$'. And # of course it'll switch to the LRU and back to origin. swayr switch-to-matching-or-urgent-or-lru-window '[app_id="NONE"]' # Again, it'll switch to the LRU and the origin.
Well, I think it's kind of expected. Your idea is to make
switch-to-*
commands immediately return non-zero in case there is no single window matching the name/criteria, right? I sympathize with this idea...
Oh, sorry, I've said something wrong:
switch-to-mark-or-urgent-or-lru-window
andswitch-to-app-or-urgent-or-lru-window
don't use regexps but compare literally. And of course you've used the mark and not the app command, so we're comparing with the window's mark name and not app_id.Anyway...
Your idea is to make switch-to-* commands immediately return non-zero in case there is no single window matching the name/criteria, right?
Yes.
If there is no target, do no action and return nonzero.
If there is a target, take the corresponding action and return 0.
If you feel that this is inconsistent with the meaning of the command name, you could add an option such as
--check
, but I think it is simpler to return nonzero without action if there is no target.
I've made it this way. :-)
swayrd seems to be terminating improperly. Sorry if this is my problem.
$ pacman -Q swayr-git swayr-git r425.727195f-1 $ $ swayr switch-to-app-or-urgent-or-lru-window foot thread 'main' panicked at 'Could not read response from swayrd: Error("EOF while parsing a value", line: 1, column: 0)', swayr/src/client.rs:28:10 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace $
[2022-12-02T16:13:31Z DEBUG swayr::shared::cfg] Loading config from /home/a/.config/swayr/config.toml. [2022-12-02T16:13:31Z DEBUG swayr::daemon] Deleted stale socket from previous run. [2022-12-02T16:13:31Z DEBUG swayr::daemon] swayrd starts listening on /run/user/1000/swayr-wayland-1.sock. [2022-12-02T16:13:31Z DEBUG swayr::daemon] Connecting to sway for subscribing to events... [2022-12-02T16:13:31Z WARN swayr::daemon] Could not connect and subscribe: No such file or directory (os error 2) [2022-12-02T16:13:33Z DEBUG swayr::daemon] Received command: SwitchToAppOrUrgentOrLRUWindow { name: "foot", skip_urgent: false, skip_lru: false, skip_origin: false } [2022-12-02T16:13:33Z INFO swayr::cmds] Running SwayrCommand SwitchToAppOrUrgentOrLRUWindow { name: "foot", skip_urgent: false, skip_lru: false, skip_origin: false } thread 'main' panicked at 'Could not open sway IPC connection.: Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })', swayr/src/shared/ipc.rs:27:34 stack backtrace: 0: 0x55b1f35077e8 - <unknown> 1: 0x55b1f344f19c - <unknown> 2: 0x55b1f35040e5 - <unknown> 3: 0x55b1f3508e91 - <unknown> 4: 0x55b1f3508b92 - <unknown> 5: 0x55b1f35094b5 - <unknown> 6: 0x55b1f35093b4 - <unknown> 7: 0x55b1f3507ce4 - <unknown> 8: 0x55b1f3509112 - <unknown> 9: 0x55b1f3428683 - <unknown> 10: 0x55b1f34287d3 - <unknown> 11: 0x55b1f357c6a0 - <unknown> 12: 0x55b1f359457b - <unknown> 13: 0x55b1f346986c - <unknown> 14: 0x55b1f34310e2 - <unknown> 15: 0x55b1f35813a5 - <unknown> 16: 0x55b1f356e767 - <unknown> 17: 0x55b1f3567650 - <unknown> 18: 0x55b1f3589e29 - <unknown> 19: 0x55b1f35872dc - <unknown> 20: 0x55b1f35fe414 - <unknown> 21: 0x55b1f35fe4a3 - <unknown> 22: 0x55b1f35fe0a9 - <unknown> 23: 0x55b1f35001fa - <unknown> 24: 0x55b1f35fe498 - <unknown> 25: 0x7f34b3c0f290 - <unknown> 26: 0x7f34b3c0f34a - __libc_start_main 27: 0x55b1f3433515 - <unknown> 28: 0x0 - <unknown>
The sway unix socket used for IPC seems to be gone. Not sure why...
I found the reason. Probably because I was running swayrd on tmux. Sorry. I ran swayrd on foot without tmux and it worked fine.
Both below and Test4 were fine.
$ pacman -Q swayr-git swayr-git r425.727195f-1 $ swayr switch-to-app-or-urgent-or-lru-window NONE --skip-urgent --skip-lru --skip-origin ; echo $? Error: "No window matches." 1 $ swayr switch-to-mark-or-urgent-or-lru-window N --skip-urgent ; echo $? Error: "No window matches." 1 $ swayr switch-to-matching-or-urgent-or-lru-window '[app_id="NONE"]' ; echo $? Error: "No window matches." 1 $
A little more time than this and I will check Test2,3.
I probably found a case where there is a target but non-zero exit. I think this should be a 0 exit because the target exists.
$ pacman -Q swayr-git swayr-git r426.82e1005-1 $
screencast: https://streamable.com/32gu7m
- run one alacritty
- run two foots
- Execute the following command without locking-in focus on the foot before the foot to be executed.
command:
swayr switch-to-app-or-urgent-or-lru-window Alacritty ; echo $? swayr switch-to-app-or-urgent-or-lru-window Alacritty ; echo $? swayr switch-to-app-or-urgent-or-lru-window Alacritty ; echo $? swayr switch-to-app-or-urgent-or-lru-window Alacritty --skip-lru ; echo $?
result:
Executed sway command '[con_id=24] focus' (It's a matching window.) 0 Executed sway command '[con_id=33] focus' (It's the origin window.) 0 Executed sway command '[con_id=24] focus' (It's a matching window.) 0 Error: "Nothing to be switched to." 1
swayrd log(
RUST_BACKTRACE=full RUST_LOG=swayr=debug swayrd
):[2022-12-03T00:31:55Z INFO swayr::cmds] Running SwayrCommand SwitchToAppOrUrgentOrLRUWindow { name: "Alacritty", skip_urgent: false, skip_lru: true, skip_origin: false } [2022-12-03T00:31:55Z DEBUG swayr::cmds] Initialized SwitchToMatchingData: SwitchToMatchingData { visited: [], lru: Some(33), origin: Some(24), skip_urgent: false, skip_lru: true, skip_origin: false } [2022-12-03T00:31:55Z DEBUG swayr::cmds] Switching back to origin [2022-12-03T00:31:55Z DEBUG swayr::cmds] Origin is already focused or is gone; resetting. [2022-12-03T00:31:55Z DEBUG swayr::daemon] Executed command, returning result Err("Nothing to be switched to.")
I think I've fixed it but the complexity of that function gets out of hand. :-)
Thanks, I have run Test1-4.
$ pacman -Q swayr-git swayr-git r427.6c56b3f-1 $
It may be a problem with my usage, but I was curious about something.
Here is what I want to do: "I want to be able to switch alternately between the window to be marked at any time and the window that is currently or one focus ago."
With the following settings,
a,b
will cause the LRU to intervene between origin and the mark target. It seems thatc
cannot switch anywhere because the mark target is origin.screencast: https://streamable.com/0hm3tb
for_window [app_id="MARK"] mark "MARK" set $mode_test "Test5[*]?" mode $mode_test { bindsym a exec swayr switch-to-mark-or-urgent-or-lru-window --skip-origin MARK || foot --app-id='MARK' bindsym b exec swayr switch-to-mark-or-urgent-or-lru-window MARK || foot --app-id='MARK' bindsym c exec swayr switch-to-mark-or-urgent-or-lru-window --skip-lru MARK || foot --app-id='MARK' # back to normal: Escape bindsym Escape mode "default" } bindsym $mod+t mode $mode_test
Is there any way to fix this?
I've tried to reproduce: both
a
andb
seem to do exactly what you want, e.g., switch alternatingly between the MARK-foot and the current or LRU window, depending if you start with a non-marked foot or the marked foot. Indeed,c
does nothing when you press it when the MARK-foot is already the current window (but still it returns zero).To me, that looks correct. Maybe I don't understand your desire correctly and you want to toggle between MARK-foot, LRU, and the LRU before that? (That would indeed not be possible.)
Sorry if I didn't communicate it well. I would like something that satisfies the following
- When the current window is MARK-foot, I want to switch alternately between only a single LRU (one previously focused window) and only MARK-foot.
- When the current window is not MARK-foot, I want to switch alternately between only MARK-foot and the only current window.
Alright, then I don't know what I'm missing. Both a and b did exactly that in my test... Are you up to date?
I think so.
$ pacman -Q swayr-git swayr-git r427.6c56b3f-1 $
When there are three different windows - mark, current, and one previous focus - I want only mark and current to switch repeatedly.
What is the
lockin_delay
,auto_nop_delay
,seq_inhibit
in your config? My~/.config/swayr/config.toml
is below in default state.[focus] lockin_delay = 750 [misc] seq_inhibit = false
My complete config is this:
[format] fallback_icon = '/usr/share/pixmaps/archlinux-logo.png' [focus] lockin_delay = 1000 [layout] auto_tile = true [misc] auto_nop_delay = 3000The default
lockin_delay
is 750ms,seq_inhibit
defaults tofalse
.auto_nop_delay
is not set by default, so you don't have auto-nops.Anyway, the problem is that
swayr switch-to-mark-or-urgent-or-lru-window --skip-lru MARK
returns 0 but if the MARK window is focused already and origin is the MARK window, too, there is nothing to be done. Using--skip-origin
instead of--skip-lru
seems to do what you want.
I think the current behavior is correct for swayr's specification, but when I want to switch unconditionally and alternately between a target for which the user has specified app_id and mark, and the window that has the previous focus, I have to make the script do the following conditional branching.
e.g. If the target is focused,
swayr switch-to-urgent-or-lru-window
is executed. Otherwise, executeswayr switch-to-app-or-urgent-or-lru-window $app_id_or_class --skip-lru --skip-origin
.That may not be a problem, but it seems a bit frustrating not to be able to use that usage by default.
Yeah, I see. I've added a new flag
-L
/--skip-lru-if-current-doesnt-match
forswitch-to-app/mark/matching-or-urgent-or-lru-window
which is hopefully a cure for your issue. If that's given, the LRU window will only be used if the current window already matches, e.g., has the right app_id, mark, etc. Please give it a try.
Thanks. I tested the following.
$ pacman -Q swayr-git swayr-git r431.ec73a59-1 $
test.conf
for_window [app_id="APP"] mark "MARK" set $mode_test "Test6[*]?" mode $mode_test { bindsym a exec swayr switch-to-mark-or-urgent-or-lru-window --skip-lru-if-current-doesnt-match --skip-lru MARK || foot --app-id='APP' bindsym b exec swayr switch-to-mark-or-urgent-or-lru-window -L --skip-lru MARK || foot --app-id='APP' bindsym c exec swayr switch-to-app-or-urgent-or-lru-window --skip-lru-if-current-doesnt-match --skip-lru APP || foot --app-id='APP' bindsym d exec swayr switch-to-app-or-urgent-or-lru-window -L --skip-lru APP || foot --app-id='APP' bindsym e exec swayr switch-to-matching-or-urgent-or-lru-window --skip-lru-if-current-doesnt-match --skip-lru '[con_mark="MARK"]' || foot --app-id='APP' bindsym f exec swayr switch-to-matching-or-urgent-or-lru-window -L --skip-lru '[app_name="APP"]' || foot --app-id='APP' bindsym g exec swayr switch-to-matching-or-urgent-or-lru-window -L --skip-lru '[app_id="APP"]' || foot --app-id='APP' bindsym z exec foot --app-id='APP' # back to normal: Escape bindsym Escape mode "default" } bindsym $mod+t mode $mode_test
It seems that if I do
a,b,e
whenMARK
has focus, I can't switch.screencast: https://streamable.com/ppvyeg
[2022-12-12T11:39:29Z DEBUG swayr::daemon] Received command: SwitchToMarkOrUrgentOrLRUWindow { con_mark: "MARK", skip_urgent: false, skip_lru: true, skip_lru_if_current_doesnt_match: true, skip_origin: false } [2022-12-12T11:39:29Z INFO swayr::cmds] Running SwayrCommand SwitchToMarkOrUrgentOrLRUWindow { con_mark: "MARK", skip_urgent: false, skip_lru: true, skip_lru_if_current_doesnt_match: true, skip_origin: false } [2022-12-12T11:39:29Z DEBUG swayr::cmds] Initialized SwitchToMatchingData: SwitchToMatchingData { visited: [], lru: Some(12), origin: Some(138), skip_urgent: false, skip_lru: true, skip_lru_if_current_doesnt_match: true, skip_origin: false } [2022-12-12T11:39:29Z DEBUG swayr::cmds] Switching back to origin [2022-12-12T11:39:29Z DEBUG swayr::cmds] Origin is already focused; resetting. [2022-12-12T11:39:29Z DEBUG swayr::daemon] Executed command, returning result Ok("Origin is already focused.")
Sorry if I misunderstood something.
You should not set
--skip-lru
in addition to--skip-lru-if-current-doesnt-match / -L
.
In the following, LRU seems to be included in the switch destination. How can I switch only between MARK and ORIGIN?
swayr switch-to-mark-or-urgent-or-lru-window --skip-lru-if-current-doesnt-match MARK || foot --app-id='APP' swayr switch-to-mark-or-urgent-or-lru-window --skip-lru-if-current-doesnt-match --skip-origin MARK || foot --app-id='APP'
screencast: https://streamable.com/u9k39a
Your last problem was that the command did nothing when
--skip-lru
was given and the marked window was already focused. Of course, origin was the marked window here, too, so unless there was no urgent window, there was nothing to be done.The purpose of the new flag is to include the lru window only in exactly that case.
BTW, my visual ability is not strong enough to follow a screencast. Better give a recipe with a fixed number of foot/alacritty windows and a shell script invoking the commands showing the behavior.
There was a thinking error in the new flag which I have just fixed. Now it should really, really just toggle between the window with mark and the LRU/origin window.
Sorry the screencast is not clear. I wrote a shell script to check how it works this time. (You don't have to check it)
The
-L
is working as expected "unconditionally alternating between target and ORIGIN".swayr-test.sh
#!/bin/bash #set -x LOG=swayrd_$(date --utc +%Y%m%d-%H%M%S).log swayrd-start() { systemctl --user stop swayrd.service pkill swayrd swayrd >> $LOG 2>&1 & #RUST_BACKTRACE=1 RUST_LOG=swayr::cmds=debug swayrd >> $LOG 2>&1 & #RUST_BACKTRACE=1 RUST_LOG=swayr=debug swayrd >> $LOG 2>&1 & } swayrd-end() { sleep 1 pkill swayrd swaymsg [con_mark="swayr-test"] focus cat $LOG } window-open() { swaymsg for_window [app_id="MARK"] mark "MARK" swaymsg mark "swayr-test" foot --app-id=ORIGIN --title=ORIGIN > /dev/null & foot --app-id=LRU --title=LRU > /dev/null & foot --app-id=MARK --title=MARK > /dev/null & } before_the_switch() { sleep 5 echo >> $LOG } between_the_switch() { sleep 5 echo >> $LOG } origin-start() { sleep 1 swaymsg [app_id=LRU] focus sleep 1 swaymsg [app_id=ORIGIN] focus before_the_switch } mark-start() { sleep 1 swaymsg [app_id=LRU] focus sleep 1 swaymsg [app_id=ORIGIN] focus sleep 1 swaymsg [app_id=MARK] focus before_the_switch } pacman -Q swayr-git >> $LOG echo "* cat ~/.config/swayr/config.toml *" >> $LOG cat ~/.config/swayr/config.toml >> $LOG swayrd-start window-open cmd="swayr switch-to-mark-or-urgent-or-lru-window -L MARK" # event1-1 origin-start echo "* event1-1: origin-start - $cmd *" >> $LOG $cmd >> $LOG between_the_switch # event1-2 echo "* event1-2: *" >> $LOG $cmd >> $LOG between_the_switch # event1-3 echo "* event1-3: *" >> $LOG $cmd >> $LOG between_the_switch # event1-4 echo "* event1-4: *" >> $LOG $cmd >> $LOG between_the_switch # event2-1 mark-start echo "* event2-1: mark-start - $cmd *" >> $LOG $cmd >> $LOG between_the_switch # event2-2 echo "* event2-2: *" >> $LOG $cmd >> $LOG between_the_switch # event2-3 echo "* event2-3: *" >> $LOG $cmd >> $LOG between_the_switch # event2-4 echo "* event2-4: *" >> $LOG $cmd >> $LOG between_the_switch cmd="swayr switch-to-mark-or-urgent-or-lru-window MARK" # event3-1 origin-start echo "* event3-1: origin-start - $cmd *" >> $LOG $cmd >> $LOG between_the_switch # event3-2 echo "* event3-2: *" >> $LOG $cmd >> $LOG between_the_switch # event3-3 echo "* event3-3: *" >> $LOG $cmd >> $LOG between_the_switch # event3-4 echo "* event3-4: *" >> $LOG $cmd >> $LOG between_the_switch # event4-1 mark-start echo "* event4-1: mark-start - $cmd *" >> $LOG $cmd >> $LOG between_the_switch # event4-2 echo "* event4-2: *" >> $LOG $cmd >> $LOG between_the_switch # event4-3 echo "* event4-3: *" >> $LOG $cmd >> $LOG between_the_switch # event4-4 echo "* event4-4: *" >> $LOG $cmd >> $LOG between_the_switch swayrd-endresult:
swayr-git r432.0f5c887-1 * cat ~/.config/swayr/config.toml * [focus] lockin_delay = 750 [misc] seq_inhibit = false #auto_nop_delay = 200 * event1-1: origin-start - swayr switch-to-mark-or-urgent-or-lru-window -L MARK * Executed sway command '[con_id=554] focus' (It's a matching window.) * event1-2: * Executed sway command '[con_id=553] focus' (It's the origin window.) * event1-3: * Executed sway command '[con_id=554] focus' (It's a matching window.) * event1-4: * Executed sway command '[con_id=553] focus' (It's the origin window.) * event2-1: mark-start - swayr switch-to-mark-or-urgent-or-lru-window -L MARK * Executed sway command '[con_id=553] focus' (It's the LRU window.) * event2-2: * Executed sway command '[con_id=554] focus' (It's the origin window.) * event2-3: * Executed sway command '[con_id=553] focus' (It's the LRU window.) * event2-4: * Executed sway command '[con_id=554] focus' (It's the origin window.) * event3-1: origin-start - swayr switch-to-mark-or-urgent-or-lru-window MARK * Executed sway command '[con_id=554] focus' (It's a matching window.) * event3-2: * Executed sway command '[con_id=555] focus' (It's the LRU window.) * event3-3: * Executed sway command '[con_id=553] focus' (It's the origin window.) * event3-4: * Executed sway command '[con_id=554] focus' (It's a matching window.) * event4-1: mark-start - swayr switch-to-mark-or-urgent-or-lru-window MARK * Executed sway command '[con_id=555] focus' (It's the LRU window.) * event4-2: * Executed sway command '[con_id=553] focus' (It's the origin window.) * event4-3: * Executed sway command '[con_id=554] focus' (It's a matching window.) * event4-4: * Executed sway command '[con_id=555] focus' (It's the LRU window.)
As I was working on this shell script, I noticed that they all had the expected "unconditionally alternate between target and ORIGIN" behavior this time when
auto_nop_delay = 200
was enabled.result:
auto_nop_delay = 200
swayr-git r432.0f5c887-1 * cat ~/.config/swayr/config.toml * [focus] lockin_delay = 750 [misc] seq_inhibit = false auto_nop_delay = 200 * event1-1: origin-start - swayr switch-to-mark-or-urgent-or-lru-window -L MARK * Executed sway command '[con_id=558] focus' (It's a matching window.) * event1-2: * Executed sway command '[con_id=556] focus' (It's the LRU window.) * event1-3: * Executed sway command '[con_id=558] focus' (It's a matching window.) * event1-4: * Executed sway command '[con_id=556] focus' (It's the LRU window.) * event2-1: mark-start - swayr switch-to-mark-or-urgent-or-lru-window -L MARK * Executed sway command '[con_id=556] focus' (It's the LRU window.) * event2-2: * Executed sway command '[con_id=558] focus' (It's a matching window.) * event2-3: * Executed sway command '[con_id=556] focus' (It's the LRU window.) * event2-4: * Executed sway command '[con_id=558] focus' (It's a matching window.) * event3-1: origin-start - swayr switch-to-mark-or-urgent-or-lru-window MARK * Executed sway command '[con_id=558] focus' (It's a matching window.) * event3-2: * Executed sway command '[con_id=556] focus' (It's the LRU window.) * event3-3: * Executed sway command '[con_id=558] focus' (It's a matching window.) * event3-4: * Executed sway command '[con_id=556] focus' (It's the LRU window.) * event4-1: mark-start - swayr switch-to-mark-or-urgent-or-lru-window MARK * Executed sway command '[con_id=556] focus' (It's the LRU window.) * event4-2: * Executed sway command '[con_id=558] focus' (It's a matching window.) * event4-3: * Executed sway command '[con_id=556] focus' (It's the LRU window.) * event4-4: * Executed sway command '[con_id=558] focus' (It's a matching window.)
However, when I use
-L
, I don't have to consider whether the switching interval is less thanauto_nop_delay
or not, and the result is always the same, which is more convenient for me.I will continue to check these behaviors as I use it.
Thanks for your kind implementation.
Great, thanks a lot for your endurance! I'm closing this bug then.