Skip to content

Commit

Permalink
feat(taskbar): add functionality to hide and show Windows taskbar bas…
Browse files Browse the repository at this point in the history
…ed on config

- Introduced WindowsTaskbar class to manage taskbar visibility.
- Added 'hide_taskbar' configuration option to control taskbar state.
- Integrated taskbar visibility logic into main application flow.
  • Loading branch information
amnweb committed Dec 22, 2024
1 parent 95f98dd commit 27da0e7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
20 changes: 19 additions & 1 deletion src/core/utils/win32/windows.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ctypes.wintypes
from core.event_enums import Event
import logging

user32 = ctypes.windll.user32
user32.SetWinEventHook.restype = ctypes.wintypes.HANDLE
Expand Down Expand Up @@ -101,4 +102,21 @@ class WinEvent(Event):
EventUIAEventIdEnd = 0x4EFF
EventUIAPropIdStart = 0x7500
EventUIAPropIdEnd = 0x75FF



class WindowsTaskbar:
@staticmethod
def hide(state, debug):
SW_SHOWNORMAL = 1
SW_HIDE = 0
user32 = ctypes.WinDLL('user32', use_last_error=True)
try:
for class_name in ["Shell_TrayWnd", "Shell_SecondaryTrayWnd"]:
taskbar = user32.FindWindowW(class_name, None)
if taskbar:
user32.ShowWindow(taskbar, SW_HIDE if state else SW_SHOWNORMAL)
if debug:
logging.info(f"Taskbar {taskbar} found and {'hide' if state else 'restore'}.")
except Exception as e:
if debug:
logging.error(f"Failed to hide taskbar: {e}")
5 changes: 5 additions & 0 deletions src/core/validation/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
'default': False,
'required': False,
},
'hide_taskbar': {
'type': 'boolean',
'default': False,
'required': False,
},
'komorebi': {
'type': 'dict',
'schema': {
Expand Down
13 changes: 11 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
import settings
import ctypes
import ctypes.wintypes
from core.utils.win32.windows import WindowsTaskbar

logging.getLogger('asyncio').setLevel(logging.WARNING)

def main():
config, stylesheet = get_config_and_stylesheet()
global hide_taskbar
hide_taskbar = config['hide_taskbar']

if config['debug']:
settings.DEBUG = True
logging.info("Debug mode enabled.")

app = QApplication(argv)
app.setQuitOnLastWindowClosed(False)

Expand Down Expand Up @@ -49,18 +52,24 @@ def stop_observer():
if observer:
observer.stop()
observer.join()
if hide_taskbar:
WindowsTaskbar.hide(False, settings.DEBUG)
app.aboutToQuit.connect(stop_observer)

with loop:
if hide_taskbar:
WindowsTaskbar.hide(True, settings.DEBUG)
loop.run_forever()


if __name__ == "__main__":
init_logger()
base_excepthook = sys.excepthook
def exception_hook(exctype, value, traceback):
if hide_taskbar:
WindowsTaskbar.hide(False, settings.DEBUG)
EventService().clear()
logging.error("Unhandled exception", exc_info=value)
# base_excepthook(exctype, value, traceback)
sys.exit(1)
sys.excepthook = exception_hook

Expand Down

0 comments on commit 27da0e7

Please sign in to comment.