diff --git a/docs/changelog.rst b/docs/changelog.rst index 8c3e57709..77de691fe 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -168,6 +168,9 @@ Detailed list of changes :code:`--base-dir` into account, and file name completion is relative to that directory (:pull:`10851`, :pull:`10852`, :disc:`10867`) +- Fix the bell indicator not being shown on the tab when a bell occurs in the + active window while the OS window does not have keyboard focus (:iss:`10880`) + - Fix the display not being updated while the OS window is otherwise idle after changes made from timers, such as by a custom tab bar updated from a timer or by actions mapped to mouse clicks (:pull:`10878`) diff --git a/kitty/boss.py b/kitty/boss.py index 94388987a..b488b2c59 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -2187,6 +2187,10 @@ class Boss: w = tm.active_window if w is not None: w.focus_changed(focused) + if focused: + # focus_changed() is a no-op if the window became active while + # the OS window was unfocused, so clear the bell indicator here as well + w.clear_needs_attention() if is_macos and focused: cocoa_set_menubar_title(w.title or '') tm.mark_tab_bar_dirty() diff --git a/kitty/layout/base.py b/kitty/layout/base.py index 832026209..5b1b405f1 100644 --- a/kitty/layout/base.py +++ b/kitty/layout/base.py @@ -910,7 +910,6 @@ class Layout: def dock_borders(self, windows: WindowList) -> Iterator[BorderLine]: "Borders on the inner edges of docked groups, separating them from the content they are docked to" needs_borders_map = windows.compute_needs_borders_map(lgd.draw_active_borders) - active_group = windows.active_group for g in windows.iter_dock_groups(only_visible=True): if g.dock is None or (geom := g.geometry) is None or not (bw := g.effective_border()): continue @@ -931,7 +930,7 @@ class Layout: edges, horizontal, wid = Edges(left + margin, top, left + margin + bw, bottom), False, -wid color = BorderColor.inactive if needs_borders_map.get(g.id): - color = BorderColor.active if g is active_group else BorderColor.bell + color = BorderColor.bell if g.needs_attention else BorderColor.active yield BorderLine(edges, color, wid, horizontal) def minimal_borders(self, windows: WindowList) -> Iterator[BorderLine]: diff --git a/kitty/layout/grid.py b/kitty/layout/grid.py index b762bba59..e5405e0d4 100644 --- a/kitty/layout/grid.py +++ b/kitty/layout/grid.py @@ -239,7 +239,6 @@ class Grid(Layout): all_groups_in_order.append(wg) layout_data_map[wg.id] = xl, yl is_last_column = {groups[x].id for x in prev_col_windows} - active_group = windows.active_group def ends(yl: LayoutData) -> tuple[int, int]: return yl.content_pos - yl.space_before, yl.content_pos + yl.content_size + yl.space_after @@ -266,7 +265,7 @@ class Grid(Layout): for wg in all_groups_in_order: color = BorderColor.inactive if needs_borders_map.get(wg.id): - color = BorderColor.active if wg is active_group else BorderColor.bell + color = BorderColor.bell if wg.needs_attention else BorderColor.active wid = wg.active_window_id yield from borders_for_window(wg.id, color, wid) diff --git a/kitty/layout/splits.py b/kitty/layout/splits.py index a23dd4344..7be04f5b4 100644 --- a/kitty/layout/splits.py +++ b/kitty/layout/splits.py @@ -950,16 +950,12 @@ class Splits(Layout): if not lgd.draw_minimal_borders or window_count < 2: return needs_borders_map = windows.compute_needs_borders_map(lgd.draw_active_borders) - ag = windows.active_group - active_group_id = -1 if ag is None else ag.id border_color_map = {} for grp_id, needs_borders in needs_borders_map.items(): if needs_borders: - wid = g.active_window_id if (g := windows.group_for_id(grp_id)) else 0 - if wid: - color = BorderColor.active if grp_id is active_group_id else BorderColor.bell - border_color_map[wid] = color + if (g := windows.group_for_id(grp_id)) and (wid := g.active_window_id): + border_color_map[wid] = BorderColor.bell if g.needs_attention else BorderColor.active for pair in self.pairs_root.self_and_descendants(): if pair.between_borders: diff --git a/kitty/layout/tall.py b/kitty/layout/tall.py index 8d2bea5ed..684301050 100644 --- a/kitty/layout/tall.py +++ b/kitty/layout/tall.py @@ -322,7 +322,6 @@ class Tall(Layout): perp_borders: list[BorderLine] = [] layouts = (self.simple_layout if num <= self.num_full_size_windows else self.full_layout)(windows) needs_borders_map = windows.compute_needs_borders_map(lgd.draw_active_borders) - active_group = windows.active_group mirrored = self.layout_opts.mirrored for wg, xl, yl, is_full_size in layouts: if is_full_size: @@ -330,7 +329,7 @@ class Tall(Layout): else: color = BorderColor.inactive if needs_borders_map.get(wg.id): - color = BorderColor.active if wg is active_group else BorderColor.bell + color = BorderColor.bell if wg.needs_attention else BorderColor.active wid = wg.active_window_id mult = 1 if mirrored else -1 diff --git a/kitty/layout/vertical.py b/kitty/layout/vertical.py index 518144a3d..992283920 100644 --- a/kitty/layout/vertical.py +++ b/kitty/layout/vertical.py @@ -16,7 +16,6 @@ def borders( data: Iterable[tuple[WindowGroup, LayoutData, LayoutData]], is_horizontal: bool, all_windows: WindowList, start_offset: int = 1, end_offset: int = 1 ) -> Generator[BorderLine, None, None]: borders: list[BorderLine] = [] - active_group = all_windows.active_group needs_borders_map = all_windows.compute_needs_borders_map(lgd.draw_active_borders) try: bw = next(all_windows.iter_all_layoutable_groups()).effective_border() @@ -54,7 +53,7 @@ def borders( ) color = BorderColor.inactive if needs_borders_map.get(wg.id): - color = BorderColor.active if wg is active_group else BorderColor.bell + color = BorderColor.bell if wg.needs_attention else BorderColor.active borders.append(BorderLine(e1, color, -wg.active_window_id, not is_horizontal)) borders.append(BorderLine(e2, color, wg.active_window_id, not is_horizontal)) diff --git a/kitty/window.py b/kitty/window.py index 2e42f8278..cd1eb629b 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -1675,12 +1675,7 @@ class Window: self.last_focused_at = monotonic() update_ime_position_for_window(self.id, False, 1) self.program_status_seen_by_user() - changed = self.needs_attention - self.needs_attention = False - if changed: - tab = self.tabref() - if tab is not None: - tab.relayout_borders() + self.clear_needs_attention() if self.last_cmd_end_notification is not None: from .notifications import OnlyWhen @@ -1692,6 +1687,12 @@ class Window: # Cancel IME composition after loses focus update_ime_position_for_window(self.id, False, -1) + def clear_needs_attention(self) -> None: + if self.needs_attention: + self.needs_attention = False + if (tab := self.tabref()) is not None: + tab.relayout_borders() + def title_changed(self, new_title: memoryview | None, is_base64: bool = False) -> None: self.child_title = process_title_from_child(new_title or memoryview(b''), is_base64, self.default_title) self.call_watchers(self.watchers.on_title_change, {'title': self.child_title, 'from_child': True}) @@ -1763,7 +1764,10 @@ class Window: env = self.child.foreground_environ env['KITTY_CHILD_CMDLINE'] = ' '.join(map(shlex.quote, self.child.cmdline)) subprocess.Popen(cb, env=env, cwd=self.child.foreground_cwd, preexec_fn=clear_handled_signals) - if not self.is_active: + # Mark as needing attention unless the user is looking at this window, + # which requires both that it be the active window and that its OS + # window have keyboard focus. Attention is cleared when the window gains focus. + if not self.is_active or self.os_window_id != current_focused_os_window_id(): changed = not self.needs_attention self.needs_attention = True tab = self.tabref() diff --git a/kitty_tests/layout.py b/kitty_tests/layout.py index ac81f8048..f94959a7f 100644 --- a/kitty_tests/layout.py +++ b/kitty_tests/layout.py @@ -1083,6 +1083,32 @@ class TestSplitBorderResize(BaseSplitGeometryTest): self.assertIsNone(data.vertical_id) +class BellWindow(Window): + needs_attention = False + + +class TestMinimalBorderColors(BaseSplitGeometryTest): + def test_active_window_needing_attention_uses_bell_color(self): + # The active window can need attention when its OS window is unfocused, + # its minimal borders must then use the bell color not the active color + for layout_class in (Tall, Fat, Grid, Horizontal, Vertical, Splits): + for draw_active_borders in (True, False): + with self.subTest(layout=layout_class.name, draw_active_borders=draw_active_borders): + layout = create_layout(layout_class) + windows = create_windows(layout, num=3, window_class=BellWindow) + self.stub_dimensions(layout, Region((0, 0, 1499, 1099, 1500, 1100))) + layout(windows) + lgd.draw_active_borders = draw_active_borders + active = windows.active_window + + def colors(): + return {b.color for b in layout.get_minimal_borders(windows) if abs(b.window_id) == active.id} + + self.ae(colors(), {BorderColor.active} if draw_active_borders else {BorderColor.inactive}) + active.needs_attention = True + self.ae(colors(), {BorderColor.bell}) + + class TestReservedSpaces(BaseSplitGeometryTest): def test_reserved_spaces_do_not_overlap(self): # Custom shaders treat the space a layout reserves around the active