Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sleep: don't complain about missing dbus-next #4710

Merged
merged 1 commit into from
Feb 24, 2024

Conversation

tych0
Copy link
Member

@tych0 tych0 commented Feb 24, 2024

This originally started as a patch that looked like this:

diff --git a/libqtile/hook.py b/libqtile/hook.py
index c3df2d16..8640cb8d 100644
--- a/libqtile/hook.py
+++ b/libqtile/hook.py
@@ -192,6 +192,9 @@ class Registry:
             except:  # noqa: E722
                 logger.exception("Error in hook %s", event)

+    def has_hook(self, event):
+        return len(subscriptions[self.name].get(event, [])) > 0
+

 hooks: list[Hook] = [
     Hook(
@@ -1032,3 +1035,4 @@ qtile_hooks = Registry("qtile", hooks)
 subscribe = qtile_hooks.subscribe
 unsubscribe = qtile_hooks.unsubscribe
 fire = qtile_hooks.fire
+has_hook = qtile_hooks.has_hook
diff --git a/libqtile/resources/sleep.py b/libqtile/resources/sleep.py
index 5038b93d..7618f3be 100644
--- a/libqtile/resources/sleep.py
+++ b/libqtile/resources/sleep.py
@@ -82,7 +82,7 @@ class Inhibitor:
         Will create connection to dbus only if we want to listen out
         for a sleep or wake signal.
         """
-        if not has_dbus:
+        if not has_dbus and any(map(hook.has_hook, ["suspend", "resume"])):
             logger.warning("dbus-next is not installed. Cannot run inhibitor process.")
             return

but then when testing it, I realized this functionality already exists, via wants_sleep(), which does:

2024-02-24 08:51:07,524 WARNING libqtile sleep.py:want_sleep():L68 dbus-next must be installed to listen to sleep signals

So let's just drop this message entirely, since it's a duplicate warning in the case where users have hooks installed, and it's a spurious warning in the case when they don't.

This originally started as a patch that looked like this:

    diff --git a/libqtile/hook.py b/libqtile/hook.py
    index c3df2d16..8640cb8d 100644
    --- a/libqtile/hook.py
    +++ b/libqtile/hook.py
    @@ -192,6 +192,9 @@ class Registry:
                 except:  # noqa: E722
                     logger.exception("Error in hook %s", event)

    +    def has_hook(self, event):
    +        return len(subscriptions[self.name].get(event, [])) > 0
    +

     hooks: list[Hook] = [
         Hook(
    @@ -1032,3 +1035,4 @@ qtile_hooks = Registry("qtile", hooks)
     subscribe = qtile_hooks.subscribe
     unsubscribe = qtile_hooks.unsubscribe
     fire = qtile_hooks.fire
    +has_hook = qtile_hooks.has_hook
    diff --git a/libqtile/resources/sleep.py b/libqtile/resources/sleep.py
    index 5038b93d..7618f3be 100644
    --- a/libqtile/resources/sleep.py
    +++ b/libqtile/resources/sleep.py
    @@ -82,7 +82,7 @@ class Inhibitor:
             Will create connection to dbus only if we want to listen out
             for a sleep or wake signal.
             """
    -        if not has_dbus:
    +        if not has_dbus and any(map(hook.has_hook, ["suspend", "resume"])):
                 logger.warning("dbus-next is not installed. Cannot run inhibitor process.")
                 return

but then when testing it, I realized this functionality already exists, via
wants_sleep(), which does:

    2024-02-24 08:51:07,524 WARNING libqtile sleep.py:want_sleep():L68 dbus-next must be installed to listen to sleep signals

So let's just drop this message entirely, since it's a duplicate warning
in the case where users have hooks installed, and it's a spurious warning
in the case when they don't.
Copy link
Member

@elParaguayo elParaguayo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@tych0 tych0 merged commit 2d903b9 into qtile:master Feb 24, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants