Skip to content

Commit

Permalink
Fixed some typing, get info of all visible windows to make sure all a…
Browse files Browse the repository at this point in the history
…ppears on icons list.
  • Loading branch information
arthurferrai committed Mar 8, 2025
1 parent 8e2b32e commit 1b608d0
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/core/widgets/yasb/taskbar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from typing import Optional
from settings import DEBUG
from core.widgets.base import BaseWidget
from core.utils.win32.windows import WinEvent
Expand All @@ -21,7 +22,9 @@
SystemEventListener = None
logging.warning("Failed to load Win32 System Event Listener")


# Missing from win32con
WS_EX_NOREDIRECTIONBITMAP = 0x20_0000

class TaskbarWidget(BaseWidget):
validation_schema = VALIDATION_SCHEMA
update_event = pyqtSignal(int, WinEvent)
Expand Down Expand Up @@ -187,10 +190,8 @@ def _update_label(self, hwnd: int, win_info: dict, event: WinEvent) -> None:
if self._animation['enabled']:
self._animate_icon(icon_label, start_width=0, end_width=icon_label.sizeHint().width())

def _get_app_icon(self, hwnd: int, title:str, process: dict, event: WinEvent) -> None:
def _get_app_icon(self, hwnd: int, title:str, process: dict, event: WinEvent) -> Optional[QPixmap]:
try:
if hwnd != win32gui.GetForegroundWindow():
return
pid = process["pid"]

if event != WinEvent.WinEventOutOfContext:
Expand All @@ -201,7 +202,7 @@ def _get_app_icon(self, hwnd: int, title:str, process: dict, event: WinEvent) ->
else:
icon_img = get_window_icon(hwnd, self.dpi)
if icon_img:
icon_img = icon_img.resize((int(self._label_icon_size * self.dpi), int(self._label_icon_size * self.dpi)), Image.LANCZOS).convert("RGBA")
icon_img = icon_img.resize((int(self._label_icon_size * self.dpi), int(self._label_icon_size * self.dpi)), Image.Resampling.LANCZOS).convert("RGBA")
else:
# UWP apps I hate it
if process["name"] == "ApplicationFrameHost.exe":
Expand All @@ -211,9 +212,9 @@ def _get_app_icon(self, hwnd: int, title:str, process: dict, event: WinEvent) ->
return
else:
self._update_retry_count = 0
if icon_img:
if not DEBUG:
self._icon_cache[(hwnd, title, pid)] = icon_img
if icon_img:
qimage = QImage(icon_img.tobytes(), icon_img.width, icon_img.height, QImage.Format.Format_RGBA8888)
pixmap = QPixmap.fromImage(qimage)
else:
Expand All @@ -223,22 +224,23 @@ def _get_app_icon(self, hwnd: int, title:str, process: dict, event: WinEvent) ->
if DEBUG:
logging.exception(f"Failed to get icons for window with HWND {hwnd} emitted by event {event}")

def get_visible_windows(self, hwnd: int, win_info: dict, event: WinEvent) -> None:
def get_visible_windows(self, _: int, win_info: dict, event: WinEvent) -> list[tuple[str, int, Optional[QPixmap], WinEvent]]:
process = win_info['process']
def is_window_visible_on_taskbar(hwnd):
if win32gui.IsWindowVisible(hwnd) and win32gui.GetWindowText(hwnd):
if win32gui.IsWindowVisible(hwnd):
ex_style = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
if not (ex_style & win32con.WS_EX_TOOLWINDOW):
if not (ex_style & win32con.WS_EX_TOOLWINDOW or ex_style == WS_EX_NOREDIRECTIONBITMAP):
return True
return False

visible_windows = []

def enum_windows_proc(hwnd, lParam):
def enum_windows_proc(hwnd, _):
if is_window_visible_on_taskbar(hwnd):
title = win32gui.GetWindowText(hwnd)
icon = self._get_app_icon(hwnd, title, process, event)
visible_windows.append((title, hwnd, icon ,process))
if title and icon:
visible_windows.append((title, hwnd, icon, process))
return True
win32gui.EnumWindows(enum_windows_proc, None)
return visible_windows
Expand Down

0 comments on commit 1b608d0

Please sign in to comment.