Switch OS windows when focusing on platforms where it is supported

This commit is contained in:
Kovid Goyal
2019-11-13 14:59:49 +05:30
parent 080c09d22e
commit 5d639b91b0
2 changed files with 8 additions and 6 deletions

View File

@@ -23,10 +23,10 @@ from .constants import (
from .fast_data_types import (
ChildMonitor, background_opacity_of, change_background_opacity,
change_os_window_state, create_os_window, current_os_window,
destroy_global_data, get_clipboard_string, global_font_size,
mark_os_window_for_close, os_window_font_size, patch_global_colors,
safe_pipe, set_clipboard_string, set_in_sequence_mode, thread_write,
toggle_fullscreen, toggle_maximized
destroy_global_data, focus_os_window, get_clipboard_string,
global_font_size, mark_os_window_for_close, os_window_font_size,
patch_global_colors, safe_pipe, set_clipboard_string, set_in_sequence_mode,
thread_write, toggle_fullscreen, toggle_maximized
)
from .keys import get_shortcut, shortcut_matches
from .layout import set_layout_options
@@ -235,7 +235,7 @@ class Boss:
if tab:
yield tab
def set_active_window(self, window):
def set_active_window(self, window, switch_os_window_if_needed=False):
for os_window_id, tm in self.os_window_map.items():
for tab in tm:
for w in tab:
@@ -243,6 +243,8 @@ class Boss:
if tab is not self.active_tab:
tm.set_active_tab(tab)
tab.set_active_window(w)
if switch_os_window_if_needed and current_os_window() != os_window_id:
focus_os_window(os_window_id, True)
return os_window_id
def _new_os_window(self, args, cwd_from=None):

View File

@@ -198,5 +198,5 @@ def launch(boss, opts, args, target_tab=None):
tab = tab_for_window(boss, opts, target_tab)
new_window = tab.new_window(env=env or None, **kw)
if opts.keep_focus and active:
boss.set_active_window(active)
boss.set_active_window(active, switch_os_window_if_needed=True)
return new_window