From 599d1bcbdc8e0e9fb2d743d70dbf8b6fa9f3bea2 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sat, 13 May 2017 20:37:15 +1200 Subject: DPMS support --- backend/drm/backend.c | 8 ++++++++ backend/drm/drm.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) (limited to 'backend/drm') diff --git a/backend/drm/backend.c b/backend/drm/backend.c index 0da84745..f202d4d6 100644 --- a/backend/drm/backend.c +++ b/backend/drm/backend.c @@ -101,3 +101,11 @@ error_backend: free(backend); return NULL; } + +void wlr_drm_backend_dpms(struct wlr_backend *backend, bool screen_on) { + struct wlr_backend_state *state = backend->state; + for (size_t i = 0; i < state->outputs->length; ++i) { + struct wlr_output_state *output = state->outputs->items[i]; + wlr_drm_output_dpms(state->fd, output, screen_on); + } +} diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 7cbd3e4a..a8e8c9ae 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -249,6 +249,30 @@ static struct wlr_output_impl output_impl = { .destroy = wlr_drm_output_destroy, }; +static void scan_property_ids(int fd, drmModeConnector *conn, + struct wlr_output_state *output) { + for (int i = 0; i < conn->count_props; ++i) { + drmModePropertyRes *prop = drmModeGetProperty(fd, conn->props[i]); + if (!prop) { + continue; + } + + // I think this is guranteed to exist + if (strcmp(prop->name, "DPMS") == 0) { + output->props.dpms = prop->prop_id; + + /* There may be more properties we want to get, + * but since it's currently only this, we exit early + */ + + drmModeFreeProperty(prop); + break; + } + + drmModeFreeProperty(prop); + } +} + void wlr_drm_scan_connectors(struct wlr_backend_state *state) { wlr_log(L_INFO, "Scanning DRM connectors"); @@ -300,6 +324,8 @@ void wlr_drm_scan_connectors(struct wlr_backend_state *state) { free(curr_enc); } + scan_property_ids(state->fd, conn, output); + list_add(state->outputs, output); wlr_log(L_INFO, "Found display '%s'", output->name); } else { @@ -416,3 +442,23 @@ void wlr_drm_output_cleanup(struct wlr_output_state *output, bool restore) { } // TODO: free wlr_output } + +void wlr_drm_output_dpms(int fd, struct wlr_output_state *output, bool screen_on) { + if (output->state != DRM_OUTPUT_CONNECTED) { + return; + } + + if (screen_on) { + drmModeConnectorSetProperty(fd, output->connector, output->props.dpms, + DRM_MODE_DPMS_ON); + + // Start rendering loop again by drawing a black frame + wlr_drm_output_begin(output->wlr_output); + glClearColor(0.0, 0.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + wlr_drm_output_end(output->wlr_output); + } else { + drmModeConnectorSetProperty(fd, output->connector, output->props.dpms, + DRM_MODE_DPMS_STANDBY); + } +} -- cgit v1.2.3