mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-22 18:09:49 +01:00
Generalize DPMS, remove DRM refs from example
This commit is contained in:
parent
03c9b46034
commit
fee409bd0a
10 changed files with 65 additions and 50 deletions
|
@ -2,7 +2,9 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <wlr/session.h>
|
||||
#include "common/log.h"
|
||||
#include "backend/drm/backend.h"
|
||||
#include "backend.h"
|
||||
|
||||
struct wlr_backend *wlr_backend_create(const struct wlr_backend_impl *impl,
|
||||
|
@ -34,3 +36,11 @@ void wlr_backend_destroy(struct wlr_backend *backend) {
|
|||
// TODO: free outputs
|
||||
free(backend);
|
||||
}
|
||||
|
||||
struct wlr_backend *wlr_backend_autocreate(struct wl_display *display,
|
||||
struct wlr_session *session) {
|
||||
// TODO: Choose the most appropriate backend for the situation
|
||||
struct wlr_backend *wlr;
|
||||
wlr = wlr_drm_backend_create(display, session);
|
||||
return wlr;
|
||||
}
|
||||
|
|
|
@ -101,11 +101,3 @@ 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -236,6 +236,28 @@ error:
|
|||
return false;
|
||||
}
|
||||
|
||||
static void wlr_drm_output_enable(struct wlr_output_state *output, bool enable) {
|
||||
struct wlr_backend_state *state =
|
||||
wl_container_of(output->renderer, state, renderer);
|
||||
if (output->state != DRM_OUTPUT_CONNECTED) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enable) {
|
||||
drmModeConnectorSetProperty(state->fd, output->connector, output->props.dpms,
|
||||
DRM_MODE_DPMS_ON);
|
||||
|
||||
// Start rendering loop again by drawing a black frame
|
||||
wlr_drm_output_begin(output);
|
||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
wlr_drm_output_end(output);
|
||||
} else {
|
||||
drmModeConnectorSetProperty(state->fd, output->connector, output->props.dpms,
|
||||
DRM_MODE_DPMS_STANDBY);
|
||||
}
|
||||
}
|
||||
|
||||
static void wlr_drm_output_destroy(struct wlr_output_state *output) {
|
||||
wlr_drm_output_cleanup(output, true);
|
||||
wlr_drm_renderer_free(output->renderer);
|
||||
|
@ -244,6 +266,7 @@ static void wlr_drm_output_destroy(struct wlr_output_state *output) {
|
|||
|
||||
static struct wlr_output_impl output_impl = {
|
||||
.set_mode = wlr_drm_output_set_mode,
|
||||
.enable = wlr_drm_output_enable,
|
||||
.destroy = wlr_drm_output_destroy,
|
||||
};
|
||||
|
||||
|
@ -454,23 +477,3 @@ 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);
|
||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
wlr_drm_output_end(output);
|
||||
} else {
|
||||
drmModeConnectorSetProperty(fd, output->connector, output->props.dpms,
|
||||
DRM_MODE_DPMS_STANDBY);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
#include <time.h>
|
||||
#include <wayland-server.h>
|
||||
#include <GLES3/gl3.h>
|
||||
#include <wlr/backend/drm.h>
|
||||
#include <wlr/backend.h>
|
||||
#include <wlr/session.h>
|
||||
#include <wlr/wayland.h>
|
||||
#include <wlr/common/list.h>
|
||||
|
||||
struct state {
|
||||
|
@ -40,7 +41,6 @@ void output_frame(struct wl_listener *listener, void *data) {
|
|||
if (s->color[s->dec] < 0.0f) {
|
||||
s->color[inc] = 1.0f;
|
||||
s->color[s->dec] = 0.0f;
|
||||
|
||||
s->dec = inc;
|
||||
}
|
||||
|
||||
|
@ -75,15 +75,23 @@ int timer_done(void *data) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int dpms_on(void *data) {
|
||||
struct wlr_backend *backend = data;
|
||||
wlr_drm_backend_dpms(backend, false);
|
||||
int enable_outputs(void *data) {
|
||||
struct state *state = data;
|
||||
for (size_t i = 0; i < state->outputs->length; ++i) {
|
||||
struct output_state *ostate = state->outputs->items[i];
|
||||
struct wlr_output *output = ostate->output;
|
||||
wlr_output_enable(output, true);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dpms_off(void *data) {
|
||||
struct wlr_backend *backend = data;
|
||||
wlr_drm_backend_dpms(backend, true);
|
||||
int disable_outputs(void *data) {
|
||||
struct state *state = data;
|
||||
for (size_t i = 0; i < state->outputs->length; ++i) {
|
||||
struct output_state *ostate = state->outputs->items[i];
|
||||
struct wlr_output *output = ostate->output;
|
||||
wlr_output_enable(output, false);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -116,7 +124,7 @@ int main() {
|
|||
return 1;
|
||||
}
|
||||
|
||||
struct wlr_backend *wlr = wlr_drm_backend_create(display, session);
|
||||
struct wlr_backend *wlr = wlr_backend_autocreate(display, session);
|
||||
wl_signal_add(&wlr->events.output_add, &state.output_add);
|
||||
wl_signal_add(&wlr->events.output_remove, &state.output_remove);
|
||||
if (!wlr || !wlr_backend_init(wlr)) {
|
||||
|
@ -126,14 +134,14 @@ int main() {
|
|||
bool done = false;
|
||||
struct wl_event_source *timer = wl_event_loop_add_timer(event_loop,
|
||||
timer_done, &done);
|
||||
struct wl_event_source *timer_dpms_on = wl_event_loop_add_timer(event_loop,
|
||||
dpms_on, wlr);
|
||||
struct wl_event_source *timer_dpms_off = wl_event_loop_add_timer(event_loop,
|
||||
dpms_off, wlr);
|
||||
struct wl_event_source *timer_disable_outputs =
|
||||
wl_event_loop_add_timer(event_loop, disable_outputs, &state);
|
||||
struct wl_event_source *timer_enable_outputs =
|
||||
wl_event_loop_add_timer(event_loop, enable_outputs, &state);
|
||||
|
||||
wl_event_source_timer_update(timer, 20000);
|
||||
wl_event_source_timer_update(timer_dpms_on, 5000);
|
||||
wl_event_source_timer_update(timer_dpms_off, 10000);
|
||||
wl_event_source_timer_update(timer_disable_outputs, 5000);
|
||||
wl_event_source_timer_update(timer_enable_outputs, 10000);
|
||||
|
||||
while (!done) {
|
||||
wl_event_loop_dispatch(event_loop, 0);
|
||||
|
|
|
@ -55,7 +55,6 @@ struct wlr_output_state {
|
|||
};
|
||||
|
||||
void wlr_drm_output_cleanup(struct wlr_output_state *output, bool restore);
|
||||
void wlr_drm_output_dpms(int fd, struct wlr_output_state *output, bool screen_on);
|
||||
|
||||
void wlr_drm_scan_connectors(struct wlr_backend_state *state);
|
||||
int wlr_drm_event(int fd, uint32_t mask, void *data);
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
|
||||
struct wlr_output_impl {
|
||||
bool (*set_mode)(struct wlr_output_state *state, struct wlr_output_mode *mode);
|
||||
void (*enable)(struct wlr_output_state *state, bool enable);
|
||||
void (*destroy)(struct wlr_output_state *state);
|
||||
};
|
||||
|
||||
struct wlr_output *wlr_output_create(struct wlr_output_impl *impl,
|
||||
struct wlr_output_state *state);
|
||||
|
||||
void wlr_output_free(struct wlr_output *output);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define _WLR_BACKEND_H
|
||||
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/session.h>
|
||||
|
||||
struct wlr_backend_impl;
|
||||
struct wlr_backend_state;
|
||||
|
@ -22,7 +23,8 @@ struct wlr_backend {
|
|||
} events;
|
||||
};
|
||||
|
||||
struct wlr_backend *wlr_backend_autocreate();
|
||||
struct wlr_backend *wlr_backend_autocreate(struct wl_display *display,
|
||||
struct wlr_session *session);
|
||||
bool wlr_backend_init(struct wlr_backend *backend);
|
||||
void wlr_backend_destroy(struct wlr_backend *backend);
|
||||
|
||||
|
|
|
@ -4,12 +4,8 @@
|
|||
#include <wayland-server.h>
|
||||
#include <wlr/session.h>
|
||||
#include <wlr/backend.h>
|
||||
#include <xf86drmMode.h> // drmModeModeInfo
|
||||
#include <wlr/wayland.h>
|
||||
|
||||
struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
|
||||
struct wlr_session *session);
|
||||
|
||||
void wlr_drm_backend_dpms(struct wlr_backend *backend, bool screen_on);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -40,5 +40,6 @@ struct wlr_output {
|
|||
};
|
||||
|
||||
bool wlr_output_set_mode(struct wlr_output *output, struct wlr_output_mode *mode);
|
||||
void wlr_output_enable(struct wlr_output *output, bool enable);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,3 +29,7 @@ void wlr_output_free(struct wlr_output *output) {
|
|||
bool wlr_output_set_mode(struct wlr_output *output, struct wlr_output_mode *mode) {
|
||||
return output->impl->set_mode(output->state, mode);
|
||||
}
|
||||
|
||||
void wlr_output_enable(struct wlr_output *output, bool enable) {
|
||||
output->impl->enable(output->state, enable);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue