diff --git a/libqtile/core/manager.py b/libqtile/core/manager.py index 962a788995..e1e1849c5e 100644 --- a/libqtile/core/manager.py +++ b/libqtile/core/manager.py @@ -36,7 +36,7 @@ import xcffib.xproto import libqtile -from libqtile import confreader, hook, ipc, utils, window +from libqtile import hook, ipc, utils, window from libqtile.backend.x11 import xcbq from libqtile.command import interface from libqtile.command.base import CommandError, CommandException, CommandObject @@ -104,11 +104,8 @@ def load_config(self): self.config.load() self.config.validate() except Exception as e: - logger.exception('Error while reading config file (%s)', e) - self.config = confreader.Config() - from libqtile.widget import TextBox - widgets = self.config.screens[0].bottom.widgets - widgets.insert(0, TextBox('Config Err!')) + msg = "Woops! Error in config: " + e.__class__.__name__ + send_notification("Qtile Config", msg, timeout=20000) self.core.wmname = getattr(self.config, "wmname", "qtile") diff --git a/libqtile/popup.py b/libqtile/popup.py index e6708ca132..560eda3908 100644 --- a/libqtile/popup.py +++ b/libqtile/popup.py @@ -19,8 +19,11 @@ # SOFTWARE. +import asyncio + from xcffib.xproto import StackMode +import libqtile from libqtile import configurable, drawer, pangocffi, window @@ -29,26 +32,30 @@ class Popup(configurable.Configurable): This class can be used to create popup windows that display images and/or text. """ defaults = [ - ('opacity', 1.0, 'Opacity of notifications.'), + ('opacity', 1.0, 'Opacity of window.'), ('foreground', '#ffffff', 'Colour of text.'), ('background', '#111111', 'Background colour.'), - ('border', '#111111', 'Border colour.'), - ('border_width', 0, 'Line width of drawn borders.'), + ('border', '#ffffff', 'Border colour.'), + ('border_width', 1, 'Line width of drawn borders.'), ('corner_radius', None, 'Corner radius for round corners, or None.'), ('font', 'sans', 'Font used in notifications.'), ('font_size', 14, 'Size of font.'), ('fontshadow', None, 'Colour for text shadows, or None for no shadows.'), - ('horizontal_padding', 0, 'Padding at sides of text.'), - ('vertical_padding', 0, 'Padding at top and bottom of text.'), + ('horizontal_padding', 4, 'Padding at sides of text.'), + ('vertical_padding', 4, 'Padding at top and bottom of text.'), ('text_alignment', 'left', 'Text alignment: left, center or right.'), ('wrap', True, 'Whether to wrap text.'), ] def __init__(self, qtile, x=50, y=50, width=256, height=64, **config): - configurable.Configurable.__init__(self, **config) + configurable.Configurable.__init__(self, x=x, y=y, width=width, height=height, **config) self.add_defaults(Popup.defaults) self.qtile = qtile + if qtile.current_screen: + self.x += qtile.current_screen.x + self.y += qtile.current_screen.y + win = qtile.conn.create_window(x, y, width, height) win.set_property("QTILE_INTERNAL", 1) self.win = window.Internal(win, qtile) @@ -77,8 +84,6 @@ def __init__(self, qtile, x=50, y=50, width=256, height=64, **config): self.win.handle_KeyPress = self._handle_KeyPress self.win.handle_ButtonPress = self._handle_ButtonPress - self.x = self.win.x - self.y = self.win.y if not self.border_width: self.border = None @@ -166,3 +171,22 @@ def hide(self): def kill(self): self.win.kill() + + +def send_popup(message, timeout=10000, **config): + """Create a transient popup window to display some text.""" + popup = Popup(libqtile.qtile, **config) + popup.win.handle_ButtonPress = lambda ev: popup.kill() + popup.clear() + popup.text = message + popup.draw_text() + popup.place() + popup.unhide() + popup.draw() + + if timeout: + try: + loop = asyncio.get_running_loop() + except RuntimeError: + return + loop.call_later(timeout / 1000, popup.kill) diff --git a/libqtile/utils.py b/libqtile/utils.py index 08ac252351..acd05cb625 100644 --- a/libqtile/utils.py +++ b/libqtile/utils.py @@ -194,9 +194,8 @@ def send_notification(title, message, urgent=False, timeout=10000, id=None): https://developer.gnome.org/notification-spec/ """ if not has_dbus: - logger.warning( - "dbus-next is not installed. Unable to send notifications." - ) + from libqtile.popup import send_popup + send_popup(f"{title}\n{message}", timeout=timeout) return -1 id = randint(10, 1000) if id is None else id diff --git a/test/test_popup.py b/test/test_popup.py index 4a52631b66..33039d1b03 100644 --- a/test/test_popup.py +++ b/test/test_popup.py @@ -33,6 +33,7 @@ def test_popup_focus(manager): # we have to add .conn so that Popup thinks this is libqtile.qtile manager.conn = xcbq.Connection(manager.display) + manager.current_screen = None try: popup = Popup(manager)