Skip to content

switch to recent os window: nth_os_window -1 #7009

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

Closed
wants to merge 2 commits into from

Conversation

jackielii
Copy link
Contributor

@jackielii jackielii commented Jan 17, 2024

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
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
Contributor Author

added per your suggestion. Thanks

@jackielii
Copy link
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)
```
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