Skip to content

Commit

Permalink
fix: Not showing up in taskbar (windows specific)
Browse files Browse the repository at this point in the history
- window decorations are not removed for linux, mac
  • Loading branch information
tomlin7 committed Aug 4, 2023
1 parent 19da01f commit 0f8a358
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 21 deletions.
24 changes: 18 additions & 6 deletions biscuit/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import platform
import subprocess
import sys
import tkinter as tk
Expand All @@ -13,10 +14,7 @@ def __init__(self, appdir=None, dir=None, *args, **kwargs):
super().__init__(*args, **kwargs)
self.base = self
self.setup_path(appdir)
# TODO app is not added to taskbar
self.overrideredirect(True)

self.withdraw()

self.setup()
self.late_setup()
self.initialize_editor()
Expand Down Expand Up @@ -92,10 +90,25 @@ def setup_configs(self):
def setup_tk(self):
"""Sets up the Tkinter window size, title, and scaling"""

if self.sysinfo.os == "Windows":
if platform.system() == "Windows":
print("hii")
from ctypes import windll
windll.shcore.SetProcessDpiAwareness(1)

self.overrideredirect(True)
self.update_idletasks()

GWL_EXSTYLE=-20
WS_EX_APPWINDOW=0x00040000
WS_EX_TOOLWINDOW=0x00000080
hwnd = windll.user32.GetParent(self.winfo_id())
style = windll.user32.GetWindowLongW(hwnd, GWL_EXSTYLE)
style = style & ~WS_EX_TOOLWINDOW
style = style | WS_EX_APPWINDOW
windll.user32.SetWindowLongW(hwnd, GWL_EXSTYLE, style)
self.withdraw()
self.after(10, lambda:self.wm_deiconify())

self.dpi_value = self.winfo_fpixels('1i')
self.scale = self.dpi_value / 72
self.tk.call('tk', 'scaling', self.scale)
Expand Down Expand Up @@ -142,7 +155,6 @@ def initialize_editor(self):
self.logger.info('Initializing editor finished.')

self.update_idletasks()
self.deiconify()

def open_directory(self, dir):
"""Opens a directory in the explorer and updates the Git status."""
Expand Down
2 changes: 1 addition & 1 deletion biscuit/core/components/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .editors import BaseEditor, Editor
from .floating import *
from .games import BaseGame, register_game
from .git import Git
from .floating import *
43 changes: 32 additions & 11 deletions biscuit/core/utils/events.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
import platform
import tkinter.filedialog as filedialog
from tkinter.filedialog import asksaveasfilename

Expand All @@ -9,6 +9,7 @@ def __init__(self, base):
self.count = 1
self.maximized = False
self.minimized = False
self.previous_pos = None

def new_file(self, *_):
self.base.open_editor(f"Untitled-{self.count}", exists=False)
Expand Down Expand Up @@ -57,24 +58,44 @@ def quit(self, *_):
self.base.destroy()

def toggle_maximize(self, *_):
if self.base.sysinfo.os != "Linux":
self.base.wm_state('normal' if self.maximized else 'zoomed')
else:
self.base.wm_attributes('-zoomed', self.maximized)
match platform.system():
case "Windows" | "Darwin":
self.base.wm_state('normal' if self.maximized else 'zoomed')
# TODO windows specific maximizing
# case "Windows":
# from ctypes import windll
# if not self.maximized:
# hwnd = windll.user32.GetParent(self.base.winfo_id())
# SWP_SHOWWINDOW = 0x40
# windll.user32.SetWindowPos(hwnd, 0, 0, 0, int(self.base.winfo_screenwidth()), int(self.base.winfo_screenheight()-48),SWP_SHOWWINDOW)
# else:
# hwnd = windll.user32.GetParent(self.base.winfo_id())
# SWP_SHOWWINDOW = 0x40
# windll.user32.SetWindowPos(hwnd, 0, self.previous_pos[0], self.previous_pos[1], int(self.base.minsize()[0]), int(self.base.minsize()[1]), SWP_SHOWWINDOW)
case _:
self.base.wm_attributes('-zoomed', self.maximized)

self.maximized = not self.maximized


def minimize(self, *_):
self.base.update_idletasks()
self.base.overrideredirect(False)
self.base.state('iconic')

if platform.system() == 'Windows':
from ctypes import windll
hwnd = windll.user32.GetParent(self.base.winfo_id())
windll.user32.ShowWindow(hwnd, 6)
else:
self.base.withdraw()

self.minimized = True

def window_mapped(self, *_):
self.base.update_idletasks()
if self.minimized:
self.base.update_idletasks()
self.base.overrideredirect(True)
self.base.state('normal')

self.base.deiconify()
self.minimized = False

#TODO implement undo-redo
def undo(self, *_):
print('undo event')
Expand Down
4 changes: 1 addition & 3 deletions biscuit/core/utils/window_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow

import tkinter as tk
from tkinter import ttk
from ctypes import windll
from tkinter import ttk


def set_appwindow():
Expand Down Expand Up @@ -163,7 +163,5 @@ def maximizeToggle():
#ctype
hasstyle = False
root.update_idletasks()
root.withdraw()
set_appwindow()

root.mainloop()

0 comments on commit 0f8a358

Please sign in to comment.