@@ 36,6 36,7 @@ G_MODULE_EXPORT char* module_version = VERSION;
typedef struct {
uint32_t name;
+ gboolean powered;
struct zwlr_output_power_v1 *power;
struct wl_list link;
} DpmsOutput;
@@ 67,13 68,44 @@ output_by_gdk_monitor(GdkMonitor *monitor)
return NULL;
}
+static void
+handle_output_mode(void *data,
+ struct zwlr_output_power_v1 *power,
+ uint32_t mode)
+{
+ DpmsOutput *output = data;
+ output->powered = (mode == ZWLR_OUTPUT_POWER_V1_MODE_ON);
+ g_debug("%s: output #%" PRIu32 " is powered %s.", G_STRFUNC,
+ output->name, output->powered ? "on" : "off");
+}
+
+static void
+handle_output_failed(void *data,
+ struct zwlr_output_power_v1 *power)
+{
+ DpmsOutput *output = data;
+
+ g_debug("%s: output #%" PRIu32 " power control failed.", G_STRFUNC,
+ output->name);
+
+ output_destroy(g_steal_pointer(&output));
+}
+
static DpmsOutput*
output_create_with_gdk_monitor(GdkMonitor *monitor)
{
DpmsOutput *output = g_new0(DpmsOutput, 1);
output->name = wl_proxy_get_id((struct wl_proxy*) gdk_wayland_monitor_get_wl_output(monitor));
output->power = zwlr_output_power_manager_v1_get_output_power(s_power_manager, gdk_wayland_monitor_get_wl_output(monitor));
+ output->powered = TRUE;
wl_list_init(&output->link);
+
+ static const struct zwlr_output_power_v1_listener listener = {
+ .mode = handle_output_mode,
+ .failed = handle_output_failed,
+ };
+ zwlr_output_power_v1_add_listener(output->power, &listener, output);
+
g_debug("%s: output = %p", G_STRFUNC, output);
return output;
}
@@ 103,13 135,20 @@ set_outputs_powered(gboolean powered)
DpmsOutput *output;
wl_list_for_each(output, &s_outputs, link) {
- if (output->power) {
- g_debug("%s: Powering %s output #%" PRIu32 ".", G_STRFUNC,
- powered ? "on" : "off", output->name);
- zwlr_output_power_v1_set_mode(output->power, mode);
- } else {
+ if (output->powered == powered) {
+ g_debug("%s: Skipping output #%" PRIu32 ", already powered %s.",
+ G_STRFUNC, output->name, powered ? "on" : "off");
+ continue;
+ }
+
+ if (!output->power) {
g_debug("%s: Skipping output #%" PRIu32 ", no power control.", G_STRFUNC, output->name);
+ continue;
}
+
+ g_debug("%s: Powering %s output #%" PRIu32 ".", G_STRFUNC,
+ powered ? "on" : "off", output->name);
+ zwlr_output_power_v1_set_mode(output->power, mode);
}
}