diff --git a/kitty/boss.py b/kitty/boss.py index 4a5553c8b..2f89d7b78 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -822,6 +822,15 @@ class Boss: args.directory = os.path.join(data['cwd'], args.directory) focused_os_window = os_window_id = 0 for session in create_sessions(opts, args, respect_cwd=True): + if not session.has_non_background_processes: + # background only do not create and OS Window + from .launch import LaunchSpec, launch + for tab in session.tabs: + for window in tab.windows: + if window.is_background_process: + assert isinstance(window.launch_spec, LaunchSpec) + launch(get_boss(), window.launch_spec.opts, window.launch_spec.args) + continue os_window_id = self.add_os_window( session, wclass=args.cls, wname=args.name, opts_for_size=opts, startup_id=startup_id, override_title=args.title or None) diff --git a/kitty/session.py b/kitty/session.py index 3f9866f0f..e334f6a74 100644 --- a/kitty/session.py +++ b/kitty/session.py @@ -39,6 +39,11 @@ class WindowSpec: def __init__(self, launch_spec: Union['LaunchSpec', 'SpecialWindowInstance']): self.launch_spec = launch_spec self.resize_spec: Optional[ResizeSpec] = None + self.is_background_process = False + if hasattr(launch_spec, 'opts'): # LaunchSpec + from .launch import LaunchSpec + assert isinstance(launch_spec, LaunchSpec) + self.is_background_process = launch_spec.opts.type == 'background' class Tab: @@ -53,6 +58,13 @@ class Tab: self.cwd: Optional[str] = None self.next_title: Optional[str] = None + @property + def has_non_background_processes(self) -> bool: + for w in self.windows: + if not w.is_background_process: + return True + return False + class Session: @@ -65,6 +77,13 @@ class Session: self.os_window_state: Optional[str] = None self.focus_os_window: bool = False + @property + def has_non_background_processes(self) -> bool: + for t in self.tabs: + if t.has_non_background_processes: + return True + return False + def add_tab(self, opts: Options, name: str = '') -> None: if self.tabs and not self.tabs[-1].windows: del self.tabs[-1]