From 590d7129aab49f27b5abd8c4ec2cddbe8cc82099 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 28 Jul 2021 16:40:51 +0200 Subject: [PATCH] drm: add drm_set_resolution Allows to easily switch the output resolution. --- src/drm.cpp | 12 ++++++++++++ src/drm.hpp | 1 + 2 files changed, 13 insertions(+) diff --git a/src/drm.cpp b/src/drm.cpp index b499ee7..4be2c6f 100644 --- a/src/drm.cpp +++ b/src/drm.cpp @@ -1045,3 +1045,15 @@ bool drm_set_refresh( struct drm_t *drm, int refresh ) return drm_set_mode(drm, &mode); } + +bool drm_set_resolution( struct drm_t *drm, int width, int height ) +{ + drmModeConnector *connector = drm->connector->connector; + const drmModeModeInfo *mode = get_matching_mode(connector, width, height, 0); + if ( !mode ) + { + return false; + } + + return drm_set_mode(drm, mode); +} diff --git a/src/drm.hpp b/src/drm.hpp index 86e5f70..82ceaea 100644 --- a/src/drm.hpp +++ b/src/drm.hpp @@ -124,3 +124,4 @@ uint32_t drm_fbid_from_dmabuf( struct drm_t *drm, struct wlr_buffer *buf, struct void drm_drop_fbid( struct drm_t *drm, uint32_t fbid ); bool drm_set_mode( struct drm_t *drm, const drmModeModeInfo *mode ); bool drm_set_refresh( struct drm_t *drm, int refresh ); +bool drm_set_resolution( struct drm_t *drm, int width, int height );