]> git.tdb.fi Git - libs/gui.git/commitdiff
Add an example program for listing video modes
authorMikko Rasa <tdb@tdb.fi>
Sun, 27 Nov 2022 14:29:34 +0000 (16:29 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 27 Nov 2022 14:29:34 +0000 (16:29 +0200)
.gitignore
Build
examples/lsmodes.cpp [new file with mode: 0644]

index da9894e5990c4acb9b637121876e5184865ae991..07cc29fb4bcc925e0fc265cca26d397c97b186f7 100644 (file)
@@ -5,3 +5,4 @@ temp
 /libmspgui.so
 /libmspgui.dylib
 /mspgui.pc
+/lsmodes
diff --git a/Build b/Build
index 690ff5a6ed8d5f4031c7dc21fe4f27b7be86c812..049250514f9daa68b258a0463b6a4df386207efb 100644 (file)
--- 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 (file)
index 0000000..39581d5
--- /dev/null
@@ -0,0 +1,53 @@
+#include <msp/core/application.h>
+#include <msp/graphics/display.h>
+#include <msp/io/print.h>
+
+using namespace std;
+using namespace Msp;
+
+class LsModes: public RegisteredApplication<LsModes>
+{
+private:
+       Graphics::Display display;
+
+public:
+       LsModes(int, char **);
+
+       virtual int main();
+};
+
+LsModes::LsModes(int, char **)
+{
+}
+
+int LsModes::main()
+{
+       const vector<Graphics::Monitor> &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;
+}