Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

struct zwp_idle_inhibitor_v1;
struct zwp_idle_inhibit_manager_v1;
struct ext_idle_notifier_v1;

namespace waybar {

Expand All @@ -27,6 +28,7 @@ class Client {
struct wl_registry *registry = nullptr;
struct zxdg_output_manager_v1 *xdg_output_manager = nullptr;
struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager = nullptr;
struct ext_idle_notifier_v1 *idle_notifier = nullptr;
std::vector<std::unique_ptr<Bar>> bars;
Config config;
std::string bar_id;
Expand Down
10 changes: 10 additions & 0 deletions include/modules/idle_inhibitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,35 @@
#include "bar.hpp"
#include "client.hpp"

struct ext_idle_notification_v1;

namespace waybar::modules {

class IdleInhibitor : public ALabel {
sigc::connection timeout_;
ext_idle_notification_v1* idle_notification_;
uint32_t idle_timeout_ms_;

public:
IdleInhibitor(const std::string&, const waybar::Bar&, const Json::Value&);
virtual ~IdleInhibitor();
auto update() -> void override;
auto refresh(int) -> void override;
static std::list<waybar::AModule*> modules;
static bool status;

private:
bool handleToggle(GdkEventButton* const& e) override;
void toggleStatus();
void setupIdleNotification();
void teardownIdleNotification();
static void handleIdled(void* data, ext_idle_notification_v1* notification);
static void handleResumed(void* data, ext_idle_notification_v1* notification);

const Bar& bar_;
struct zwp_idle_inhibitor_v1* idle_inhibitor_;
int pid_;
bool wait_for_activity_;
};

} // namespace waybar::modules
44 changes: 42 additions & 2 deletions man/waybar-idle-inhibitor.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ screensaver, also known as "presentation mode".
typeof: double ++
The number of minutes the inhibition should last.

*wait-for-activity*: ++
typeof: bool ++
default: *false* ++
When enabled, the idle inhibitor remains active as long as there is keyboard or mouse activity on the bar. If there is no activity for the duration specified in *timeout*, the inhibitor will automatically toggle off. This option requires *timeout* to be set.

*signal*: ++
typeof: integer ++
The signal number used to toggle the idle inhibitor externally. ++
The number is valid between 1 and N, where *SIGRTMIN+N* = *SIGRTMAX*. ++
Use `pkill -SIGRTMIN+N waybar` to toggle the idle inhibitor from scripts or keybindings.

*tooltip*: ++
typeof: bool ++
default: true ++
Expand Down Expand Up @@ -115,17 +126,46 @@ screensaver, also known as "presentation mode".

# EXAMPLES

Basic usage with timeout:

```
"idle_inhibitor": {
"format": "{icon}",
"format-icons": {
"activated": "",
"deactivated": ""
"activated": "",
"deactivated": ""
},
"timeout": 30.5
}
```

With external control via signals (can be toggled with `pkill -SIGRTMIN+8 waybar`):

```
"idle_inhibitor": {
"format": "{icon}",
"format-icons": {
"activated": "",
"deactivated": ""
},
"signal": 8
}
```

With wait-for-activity feature:

```
"idle_inhibitor": {
"format": "{icon}",
"format-icons": {
"activated": "",
"deactivated": ""
},
"timeout": 5.0,
"wait-for-activity": true
}
```

# STYLE

- *#idle_inhibitor*
Expand Down
131 changes: 131 additions & 0 deletions protocol/ext-idle-notify-v1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="ext_idle_notify_v1">
<copyright>
Copyright © 2015 Martin Gräßlin
Copyright © 2022 Simon Ser

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</copyright>

<interface name="ext_idle_notifier_v1" version="2">
<description summary="idle notification manager">
This interface allows clients to monitor user idle status.

After binding to this global, clients can create ext_idle_notification_v1
objects to get notified when the user is idle for a given amount of time.
</description>

<request name="destroy" type="destructor">
<description summary="destroy the manager">
Destroy the manager object. All objects created via this interface
remain valid.
</description>
</request>

<request name="get_idle_notification">
<description summary="create a notification object">
Create a new idle notification object.

The notification object has a minimum timeout duration and is tied to a
seat. The client will be notified if the seat is inactive for at least
the provided timeout. See ext_idle_notification_v1 for more details.

A zero timeout is valid and means the client wants to be notified as
soon as possible when the seat is inactive.
</description>
<arg name="id" type="new_id" interface="ext_idle_notification_v1"/>
<arg name="timeout" type="uint" summary="minimum idle timeout in msec"/>
<arg name="seat" type="object" interface="wl_seat"/>
</request>

<!-- Version 2 additions -->

<request name="get_input_idle_notification" since="2">
<description summary="create a notification object">
Create a new idle notification object to track input from the
user, such as keyboard and mouse movement. Because this object is
meant to track user input alone, it ignores idle inhibitors.

The notification object has a minimum timeout duration and is tied to a
seat. The client will be notified if the seat is inactive for at least
the provided timeout. See ext_idle_notification_v1 for more details.

A zero timeout is valid and means the client wants to be notified as
soon as possible when the seat is inactive.
</description>
<arg name="id" type="new_id" interface="ext_idle_notification_v1"/>
<arg name="timeout" type="uint" summary="minimum idle timeout in msec"/>
<arg name="seat" type="object" interface="wl_seat"/>
</request>

</interface>

<interface name="ext_idle_notification_v1" version="2">
<description summary="idle notification">
This interface is used by the compositor to send idle notification events
to clients.

Initially the notification object is not idle. The notification object
becomes idle when no user activity has happened for at least the timeout
duration, starting from the creation of the notification object. User
activity may include input events or a presence sensor, but is
compositor-specific.

How this notification responds to idle inhibitors depends on how
it was constructed. If constructed from the
get_idle_notification request, then if an idle inhibitor is
active (e.g. another client has created a zwp_idle_inhibitor_v1
on a visible surface), the compositor must not make the
notification object idle. However, if constructed from the
get_input_idle_notification request, then idle inhibitors are
ignored, and only input from the user, e.g. from a keyboard or
mouse, counts as activity.

When the notification object becomes idle, an idled event is sent. When
user activity starts again, the notification object stops being idle,
a resumed event is sent and the timeout is restarted.
</description>

<request name="destroy" type="destructor">
<description summary="destroy the notification object">
Destroy the notification object.
</description>
</request>

<event name="idled">
<description summary="notification object is idle">
This event is sent when the notification object becomes idle.

It's a compositor protocol error to send this event twice without a
resumed event in-between.
</description>
</event>

<event name="resumed">
<description summary="notification object is no longer idle">
This event is sent when the notification object stops being idle.

It's a compositor protocol error to send this event twice without an
idled event in-between. It's a compositor protocol error to send this
event prior to any idled event.
</description>
</event>
</interface>
</protocol>
1 change: 1 addition & 0 deletions protocol/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ client_protocols = [
['river-status-unstable-v1.xml'],
['river-control-unstable-v1.xml'],
['dwl-ipc-unstable-v2.xml'],
['ext-idle-notify-v1.xml'],
]

if wayland_protos.version().version_compare('>=1.39')
Expand Down
8 changes: 8 additions & 0 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#include <gtk-layer-shell.h>
#include <spdlog/spdlog.h>

#include <algorithm>
#include <iostream>
#include <utility>

#include "gtkmm/icontheme.h"
#include "ext-idle-notify-v1-client-protocol.h"
#include "idle-inhibit-unstable-v1-client-protocol.h"
#include "util/clara.hpp"
#include "util/format.hpp"
Expand All @@ -26,6 +28,12 @@ void waybar::Client::handleGlobal(void *data, struct wl_registry *registry, uint
} else if (strcmp(interface, zwp_idle_inhibit_manager_v1_interface.name) == 0) {
client->idle_inhibit_manager = static_cast<struct zwp_idle_inhibit_manager_v1 *>(
wl_registry_bind(registry, name, &zwp_idle_inhibit_manager_v1_interface, 1));
} else if (strcmp(interface, ext_idle_notifier_v1_interface.name) == 0) {
// Bind version 2 if available (for get_input_idle_notification), otherwise version 1
auto bind_version = std::min(version, 2u);
client->idle_notifier = static_cast<struct ext_idle_notifier_v1 *>(
wl_registry_bind(registry, name, &ext_idle_notifier_v1_interface, bind_version));
spdlog::debug("Bound ext-idle-notifier-v1 at version {}", bind_version);
}
}

Expand Down
Loading
Loading