diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 8ac5c87..be132c8 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -75,4 +75,4 @@ jobs: - uses: ncipollo/release-action@v1 with: - body: See [CHANGELOG.md](https://github.com/dynobo/keyhint/blob/main/CHANGELOG.md] for details. + body: See [CHANGELOG.md](https://github.com/dynobo/keyhint/blob/main/CHANGELOG.md) for details. diff --git a/keyhint/context.py b/keyhint/context.py index 5ad6e28..616fdc1 100644 --- a/keyhint/context.py +++ b/keyhint/context.py @@ -41,9 +41,9 @@ def get_gnome_version() -> str: return "(n/a)" try: - output = subprocess.check_output( + output = subprocess.check_output( # noqa: S603 ["gnome-shell", "--version"], # noqa: S607 - shell=False, # noqa: S603 + shell=False, text=True, ) if result := re.search(r"\s+([\d\.]+)", output.strip()): @@ -70,9 +70,9 @@ def get_kde_version() -> str: return "(n/a)" try: - output = subprocess.check_output( + output = subprocess.check_output( # noqa: S603 ["plasmashell", "--version"], # noqa: S607 - shell=False, # noqa: S603 + shell=False, text=True, ) if result := re.search(r"([\d+\.]+)", output.strip()): @@ -216,9 +216,9 @@ def get_active_window_via_kwin() -> tuple[str, str]: # The output has to be read through journalctl instead. A timestamp for # filtering speeds up the process. log_lines = ( - subprocess.check_output( + subprocess.check_output( # noqa: S602 f'journalctl --user -o cat --since "{since}"', - shell=True, # noqa: S602 + shell=True, ) .decode() .split("\n") @@ -243,9 +243,9 @@ def get_active_window_via_xprop() -> tuple[str, str]: Tuple(str, str): window class, window title """ # Query id of active window - stdout_bytes: bytes = subprocess.check_output( + stdout_bytes: bytes = subprocess.check_output( # noqa: S602 "xprop -root _NET_ACTIVE_WINDOW", # noqa: S607 - shell=True, # noqa: S602 + shell=True, ) stdout = stdout_bytes.decode() @@ -257,9 +257,9 @@ def get_active_window_via_xprop() -> tuple[str, str]: window_id: str = match.group(1) # Query app_title and app_process - stdout_bytes = subprocess.check_output( + stdout_bytes = subprocess.check_output( # noqa: S602 f"xprop -id {window_id} WM_NAME WM_CLASS", - shell=True, # noqa: S602 + shell=True, ) stdout = stdout_bytes.decode() diff --git a/keyhint/window.py b/keyhint/window.py index a5a5277..8dc8e7d 100644 --- a/keyhint/window.py +++ b/keyhint/window.py @@ -339,6 +339,15 @@ def init_sheet_dropdown(self) -> None: for sheet_id in sorted([s["id"] for s in self.sheets]): model.append(sheet_id) + @property + def active_headerbar(self) -> headerbar.HeaderBarBox: + """Return the currently active headerbar depending on window state.""" + return ( + self.headerbars.fullscreen + if self.is_fullscreen() + else self.headerbars.normal + ) + @check_state def on_set_fallback_sheet( self, action: Gio.SimpleAction, state: GLib.Variant @@ -458,12 +467,8 @@ def scroll(self, to_start: bool, by_page: bool) -> None: def focus_search_entry(self) -> None: """Focus search entry of the active headerbar.""" - if self.is_fullscreen(): - self.headerbars.fullscreen.search_entry.grab_focus() - self.headerbars.fullscreen.search_entry.set_position(-1) - else: - self.headerbars.normal.search_entry.grab_focus() - self.headerbars.normal.search_entry.set_position(-1) + self.active_headerbar.search_entry.grab_focus() + self.active_headerbar.search_entry.set_position(-1) def show_create_new_sheet_toast(self) -> None: """Display a toast notification to offer the creation of a new cheatsheet.""" @@ -523,15 +528,9 @@ def on_key_pressed( case Gdk.KEY_F11, _: self.activate_action("win.fullscreen") case Gdk.KEY_f, True: - if self.is_fullscreen(): - self.headerbars.fullscreen.search_entry.grab_focus() - else: - self.headerbars.normal.search_entry.grab_focus() + self.active_headerbar.grab_focus() case Gdk.KEY_s, True: - if self.is_fullscreen(): - self.headerbars.fullscreen.sheet_dropdown.grab_focus() - else: - self.headerbars.normal.sheet_dropdown.grab_focus() + self.active_headerbar.sheet_dropdown.grab_focus() case (Gdk.KEY_Up, _) | (Gdk.KEY_k, True): self.scroll(to_start=True, by_page=False) case (Gdk.KEY_Down, _) | (Gdk.KEY_j, True):