switch to recent os window: nth_os_window -1#7009
Closed
jackielii wants to merge 2 commits into
Closed
Conversation
jackielii
marked this pull request as ready for review
January 17, 2024 16:10
Owner
|
As I mentioned on #7007 that function is for the case when no OS window has focus. So it is correct. I suggest you instead create another function that returns the value of last_focused_counter given and os_window_id. Then any history algorithm can be implemented in python code using that function. |
jackielii
force-pushed
the
last-os-window
branch
from
January 17, 2024 17:04
f64bd20 to
8b13361
Compare
Contributor
Author
|
added per your suggestion. Thanks |
jackielii
force-pushed
the
last-os-window
branch
from
January 17, 2024 23:31
cdfb46e to
b82c76e
Compare
Contributor
Author
|
Thanks |
jackielii
added a commit
to jackielii/kitty
that referenced
this pull request
Jan 18, 2024
Oops, the num is already negative index, no need to reverse here.
Alternatively this is shorter:
```
def nth_os_window(self, num: int = 1) -> None:
if not self.os_window_map:
return
if num == 0:
os_window_id = current_focused_os_window_id() or last_focused_os_window_id()
elif num > 0:
ids = tuple(self.os_window_map.keys())
os_window_id = ids[min(num, len(ids)) - 1]
else:
fc_map = os_window_focus_counters()
ids = sorted(fc_map.keys(), key=fc_map.__getitem__, reverse=True)
os_window_id = ids[min(-num, len(ids)-1)]
focus_os_window(os_window_id, True)
```
zchee
pushed a commit
to zchee/kitty
that referenced
this pull request
Jul 8, 2026
zchee
pushed a commit
to zchee/kitty
that referenced
this pull request
Jul 8, 2026
Oops, the num is already negative index, no need to reverse here.
Alternatively this is shorter:
```
def nth_os_window(self, num: int = 1) -> None:
if not self.os_window_map:
return
if num == 0:
os_window_id = current_focused_os_window_id() or last_focused_os_window_id()
elif num > 0:
ids = tuple(self.os_window_map.keys())
os_window_id = ids[min(num, len(ids)) - 1]
else:
fc_map = os_window_focus_counters()
ids = sorted(fc_map.keys(), key=fc_map.__getitem__, reverse=True)
os_window_id = ids[min(-num, len(ids)-1)]
focus_os_window(os_window_id, True)
```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix #7008
last_focused_counter(os_window_id) -> intnth_os_window -1to switch to last focused OS window