Add --keep-focus for @new-window
This commit is contained in:
parent
7b33a87725
commit
23f2b29069
@ -136,6 +136,16 @@ class Boss:
|
||||
if tab:
|
||||
yield tab
|
||||
|
||||
def set_active_window(self, window):
|
||||
for tm in self.os_window_map.values():
|
||||
for tab in tm:
|
||||
for w in tab:
|
||||
if w.id == window.id:
|
||||
if tab is not self.active_tab:
|
||||
tm.set_active_tab(tab)
|
||||
tab.set_active_window(w)
|
||||
return
|
||||
|
||||
def _new_os_window(self, args, cwd_from=None):
|
||||
sw = self.args_to_special_window(args, cwd_from) if args else None
|
||||
startup_session = create_session(self.opts, special_window=sw, cwd_from=cwd_from)
|
||||
|
||||
@ -281,6 +281,11 @@ program running in it.
|
||||
The initial working directory for the new window.
|
||||
|
||||
|
||||
--keep-focus
|
||||
type=bool-set
|
||||
Keep the current window focused instead of switching to the newly opened window
|
||||
|
||||
|
||||
--new-tab
|
||||
type=bool-set
|
||||
Open a new tab
|
||||
@ -293,17 +298,21 @@ When using --new-tab set the title of the tab.
|
||||
def cmd_new_window(global_opts, opts, args):
|
||||
return {'match': opts.match, 'title': opts.title, 'cwd': opts.cwd,
|
||||
'new_tab': opts.new_tab, 'tab_title': opts.tab_title,
|
||||
'args': args or []}
|
||||
'keep_focus': opts.keep_focus, 'args': args or []}
|
||||
|
||||
|
||||
def new_window(boss, window, payload):
|
||||
w = SpecialWindow(cmd=payload['args'] or None, override_title=payload['title'], cwd=payload['cwd'])
|
||||
old_window = boss.active_window
|
||||
if payload['new_tab']:
|
||||
boss._new_tab(w)
|
||||
tab = boss.active_tab
|
||||
if payload['tab_title']:
|
||||
tab.set_title(payload['tab_title'])
|
||||
return str(boss.active_window.id)
|
||||
wid = boss.active_window.id
|
||||
if payload['keep_focus'] and old_window:
|
||||
boss.set_active_window(old_window)
|
||||
return str(wid)
|
||||
|
||||
match = payload['match']
|
||||
if match:
|
||||
@ -314,6 +323,8 @@ def new_window(boss, window, payload):
|
||||
tabs = [boss.active_tab]
|
||||
tab = tabs[0]
|
||||
w = tab.new_special_window(w)
|
||||
if payload['keep_focus'] and old_window:
|
||||
boss.set_active_window(old_window)
|
||||
return str(w.id)
|
||||
|
||||
|
||||
|
||||
@ -376,18 +376,25 @@ class TabManager: # {{{
|
||||
for tab in self.tabs:
|
||||
tab.relayout()
|
||||
|
||||
def set_active_tab(self, idx):
|
||||
def set_active_tab_idx(self, idx):
|
||||
self._set_active_tab(idx)
|
||||
self.active_tab.relayout_borders()
|
||||
self.update_tab_bar()
|
||||
|
||||
def set_active_tab(self, tab):
|
||||
try:
|
||||
idx = self.tabs.index(tab)
|
||||
except Exception:
|
||||
return
|
||||
self.set_active_tab_idx(idx)
|
||||
|
||||
def next_tab(self, delta=1):
|
||||
if len(self.tabs) > 1:
|
||||
self.set_active_tab((self.active_tab_idx + len(self.tabs) + delta) % len(self.tabs))
|
||||
self.set_active_tab_idx((self.active_tab_idx + len(self.tabs) + delta) % len(self.tabs))
|
||||
|
||||
def goto_tab(self, tab_num):
|
||||
if tab_num < len(self.tabs) and 0 <= tab_num:
|
||||
self.set_active_tab(tab_num)
|
||||
self.set_active_tab_idx(tab_num)
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.tabs)
|
||||
@ -460,7 +467,7 @@ class TabManager: # {{{
|
||||
def activate_tab_at(self, x):
|
||||
i = self.tab_bar.tab_at(x)
|
||||
if i is not None:
|
||||
self.set_active_tab(i)
|
||||
self.set_active_tab_idx(i)
|
||||
|
||||
@property
|
||||
def blank_rects(self):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user