Skip to content

Commit

Permalink
fix: Notifications are not rendered topmost
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 committed Jul 13, 2023
1 parent a314a40 commit af8676f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
13 changes: 13 additions & 0 deletions biscuit/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def setup_configs(self):
self.active_directory = None
self.active_branch_name = None
self.onupdate_functions = []
self.onfocus_functions = []

self.sysinfo = SysInfo(self)
self.settings = Settings(self)
Expand Down Expand Up @@ -232,3 +233,15 @@ def on_gui_update(self, *_):
fn()
except tk.TclError:
pass

def register_onfocus(self, fn):
"""Registers a function to be called on focus."""
self.onfocus_functions.append(fn)

def on_focus(self, *_):
"""Calls all registered functions on focus."""
for fn in self.onfocus_functions:
try:
fn()
except tk.TclError:
pass
6 changes: 4 additions & 2 deletions biscuit/core/components/floating/notifications/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def __init__(self, base):
close_button.pack(side=tk.RIGHT, fill=tk.BOTH)

self.withdraw()

self.base.register_onfocus(self.lift)
self.base.register_onupdate(self._follow_root)

def info(self, text):
Expand All @@ -45,12 +47,11 @@ def error(self, text):
self.label.configure(text=text)
self.show()

def _follow_root(self, *_):
def _follow_root(self):
if not self.active:
return

self.update_idletasks()
self.lift()
x = self.base.winfo_x() + self.base.winfo_width() - self.winfo_width() - self.offset
y = self.base.winfo_y() + self.base.winfo_height() - self.winfo_height() - self.offset
self.geometry(f"+{x}+{y}")
Expand All @@ -59,6 +60,7 @@ def show(self, *_):
self.active = True
self._follow_root()
self.deiconify()
self.lift()

def hide(self, *_):
self.active = False
Expand Down
2 changes: 2 additions & 0 deletions biscuit/core/utils/binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def bind_all(self):
def late_bind_all(self):
self.bind(self.bindings.commandpalette, lambda e: self.base.palette.show_prompt(">"))
self.bind(self.bindings.panel, self.base.root.baseframe.contentpane.toggle_panel)

self.bind('<Configure>', self.base.on_gui_update)
self.bind('<FocusIn>', self.base.on_focus)

def bind(self, this, to_this):
self.base.bind(this, to_this)

0 comments on commit af8676f

Please sign in to comment.