Skip to content

switch to recent os window: nth_os_window -1#7009

Closed
jackielii wants to merge 2 commits into
kovidgoyal:masterfrom
jackielii:last-os-window
Closed

switch to recent os window: nth_os_window -1#7009
jackielii wants to merge 2 commits into
kovidgoyal:masterfrom
jackielii:last-os-window

Conversation

@jackielii

@jackielii jackielii commented Jan 17, 2024

Copy link
Copy Markdown
Contributor

fix #7008

  1. expose last_focused_counter(os_window_id) -> int
  2. allow mappable action nth_os_window -1 to switch to last focused OS window

@jackielii
jackielii marked this pull request as ready for review January 17, 2024 16:10
@kovidgoyal

Copy link
Copy Markdown
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

Copy link
Copy Markdown
Contributor Author

added per your suggestion. Thanks

@jackielii

Copy link
Copy Markdown
Contributor Author

Thanks

@jackielii
jackielii deleted the last-os-window branch January 18, 2024 09:01
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)
```
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

Successfully merging this pull request may close these issues.

feature: Switch to recent os window

2 participants