From c8c5fd83d985fc0a9eb332e5e37e080222e169fe Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 27 Nov 2022 16:29:34 +0200 Subject: [PATCH] Add an example program for listing video modes --- .gitignore | 1 + Build | 6 +++++ examples/lsmodes.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 examples/lsmodes.cpp diff --git a/.gitignore b/.gitignore index da9894e..07cc29f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ temp /libmspgui.so /libmspgui.dylib /mspgui.pc +/lsmodes diff --git a/Build b/Build index 690ff5a..0492505 100644 --- a/Build +++ b/Build @@ -189,6 +189,12 @@ package "mspgui" use "mspgui"; }; + program "lsmodes" + { + source "examples/lsmodes.cpp"; + use "mspgui"; + }; + source_tarball { source "License.txt"; diff --git a/examples/lsmodes.cpp b/examples/lsmodes.cpp new file mode 100644 index 0000000..39581d5 --- /dev/null +++ b/examples/lsmodes.cpp @@ -0,0 +1,53 @@ +#include +#include +#include + +using namespace std; +using namespace Msp; + +class LsModes: public RegisteredApplication +{ +private: + Graphics::Display display; + +public: + LsModes(int, char **); + + virtual int main(); +}; + +LsModes::LsModes(int, char **) +{ +} + +int LsModes::main() +{ + const vector &monitors = display.get_monitors(); + const Graphics::VideoMode &desktop_mode = display.get_desktop_mode(); + unsigned n = 0; + for(auto i=monitors.begin(); i!=monitors.end(); ++i, ++n) + { + IO::print("Monitor #%d", n); + if(&*i==desktop_mode.monitor) + IO::print(" (primary)"); + IO::print(": %s\n", i->name); + + const Graphics::VideoMode *prev_mode = 0; + for(const Graphics::VideoMode *m: i->video_modes) + { + if(!prev_mode || m->width!=prev_mode->width || m->height!=prev_mode->height) + { + if(prev_mode) + IO::print("\n"); + IO::print(" %dx%d", m->width, m->height); + } + IO::print(" %c%d", (m==i->desktop_settings.mode ? '*' : ' '), m->rate); + prev_mode = m; + } + + if(!i->video_modes.empty()) + IO::print("\n\n"); + } + + return 0; +} -- 2.45.2