~aperezdc/gtklock-dpms-module

ff9d2fabc05d4c0dd152aa0e08afa7ba50d33f88 — Adrian Perez de Castro 9 months ago 1e8682d
Factor out changing power state of outputs
1 files changed, 20 insertions(+), 20 deletions(-)

M module.c
M module.c => module.c +20 -20
@@ 96,6 96,24 @@ populate_outputs(const GArray *windows)
}

static void
set_outputs_powered(gboolean powered)
{
    const enum zwlr_output_power_v1_mode mode = powered
        ? ZWLR_OUTPUT_POWER_V1_MODE_ON : ZWLR_OUTPUT_POWER_V1_MODE_OFF;

    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 {
            g_debug("%s: Skipping output #%" PRIu32 ", no power control.", G_STRFUNC, output->name);
        }
    }
}

static void
handle_registry_global(void *data, struct wl_registry *registry, uint32_t name,
                       const char *interface, uint32_t version)
{


@@ 121,16 139,7 @@ static void
handle_power_off_timeout(void *data)
{
    s_power_off_timeout = 0;

    DpmsOutput *output;
    wl_list_for_each(output, &s_outputs, link) {
        if (output->power) {
            g_debug("%s: Powering off output #%" PRIu32 ".", G_STRFUNC, output->name);
            zwlr_output_power_v1_set_mode(output->power, ZWLR_OUTPUT_POWER_V1_MODE_OFF);
        } else {
            g_debug("%s: Skipping output #%" PRIu32 ", no power control.", G_STRFUNC, output->name);
        }
    }
    set_outputs_powered(FALSE);
}

G_MODULE_EXPORT void


@@ 190,16 199,7 @@ on_idle_show(struct GtkLock *gtklock)
            gtklock->focused_window, gtklock->hidden ? "true" : "false");

    g_clear_handle_id(&s_power_off_timeout, g_source_remove);

    DpmsOutput *output;
    wl_list_for_each(output, &s_outputs, link) {
        if (output->power) {
            g_debug("%s: Powering on output #%" PRIu32 ".", G_STRFUNC, output->name);
            zwlr_output_power_v1_set_mode(output->power, ZWLR_OUTPUT_POWER_V1_MODE_ON);
        } else {
            g_debug("%s: Skipping output #%" PRIu32 ", no power control.", G_STRFUNC, output->name);
        }
    }
    set_outputs_powered(TRUE);
}

G_MODULE_EXPORT void