]> git.tdb.fi Git - libs/gui.git/commitdiff
Refactor storage of monitor settings
authorMikko Rasa <tdb@tdb.fi>
Fri, 16 Sep 2016 21:34:26 +0000 (00:34 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 16 Sep 2016 21:42:30 +0000 (00:42 +0300)
source/graphics/display.cpp
source/graphics/monitor.cpp
source/graphics/monitor.h
source/graphics/window.cpp
source/graphics/windows/display.cpp
source/graphics/x11/display.cpp

index 1c7b639a06d8f993b72ef92fb19d9d211271ed5b..ebf14ea489c9d1befa6c8efd192a12806d5833d6 100644 (file)
@@ -25,16 +25,16 @@ void Display::remove_window(Window &wnd)
 
 const VideoMode &Display::get_desktop_mode() const
 {
-       if(!primary_monitor || !primary_monitor->desktop_mode)
+       if(!primary_monitor || !primary_monitor->desktop_settings.mode)
                throw logic_error("no desktop mode");
-       return *primary_monitor->desktop_mode;
+       return *primary_monitor->desktop_settings.mode;
 }
 
 void Display::restore_mode()
 {
        for(list<Monitor>::const_iterator i=monitors.begin(); i!=monitors.end(); ++i)
-               if(i->desktop_mode)
-                       set_mode(*i->desktop_mode, false);
+               if(i->desktop_settings.mode)
+                       set_mode(*i->desktop_settings.mode, false);
 }
 
 const VideoMode *Display::find_mode(const VideoMode &mode, float rate_tolerance) const
index 1ac438317b927a4b7e2dc145d9b8fbbcd842b5f3..d1bdd43b784b14efbc531480e2d1654247e68514 100644 (file)
@@ -7,15 +7,17 @@ namespace Graphics {
 
 Monitor::Monitor():
        index(0),
-       desktop_mode(0),
-       desktop_rotation(ROTATE_NORMAL),
-       current_mode(0),
-       current_rotation(ROTATE_NORMAL),
-       x(0),
-       y(0),
        next_left(0),
        next_right(0)
 { }
 
+
+Monitor::Settings::Settings():
+       mode(0),
+       rotation(ROTATE_NORMAL),
+       x(0),
+       y(0)
+{ }
+
 } // namespace Graphics
 } // namespace Msp
index 35abce19d5e511ead6cb05fe40a7c6935b6ff5e8..fefd9867f8f78e2962696fe26f07f654c3f1982c 100644 (file)
@@ -10,14 +10,20 @@ namespace Graphics {
 
 struct Monitor
 {
+       struct Settings
+       {
+               const VideoMode *mode;
+               VideoRotation rotation;
+               int x, y;
+
+               Settings();
+       };
+
        unsigned index;
        std::string name;
        std::list<const VideoMode *> video_modes;
-       const VideoMode *desktop_mode;
-       VideoRotation desktop_rotation;
-       const VideoMode *current_mode;
-       VideoRotation current_rotation;
-       int x, y;
+       Settings desktop_settings;
+       Settings current_settings;
        const Monitor *next_left;
        const Monitor *next_right;
 
index 073cd8d5c819311277bfeb6e0ff0444521a4eeb9..958667ead5698165d18508a7685f7ea1eebcfa9f 100644 (file)
@@ -91,7 +91,7 @@ void Window::reconfigure(const WindowOptions &opts)
 void Window::set_fullscreen_mode()
 {
        VideoMode mode(options.width, options.height);
-       mode.rotation = display.get_desktop_mode().monitor->desktop_rotation;
+       mode.rotation = display.get_desktop_mode().monitor->desktop_settings.rotation;
        if(mode.rotation==ROTATE_LEFT || mode.rotation==ROTATE_RIGHT)
                swap(mode.width, mode.height);
        display.set_mode(mode, true);
index d767bebd2e8ea11e67ddfd8a442f22ad1c539522..aaaa985c3cc21cb740d5e5bcd693472f57e9f4e9 100644 (file)
@@ -53,7 +53,7 @@ Display::Display(const string &):
                        monitor.video_modes.push_back(&modes.back());
 
                        if(have_current && info.dmPelsWidth==current.dmPelsWidth && info.dmPelsHeight==current.dmPelsHeight && info.dmDisplayFrequency==current.dmDisplayFrequency)
-                               monitor.desktop_mode = &modes.back();
+                               monitor.desktop_settings.mode = &modes.back();
                }
        }
 }
@@ -89,7 +89,7 @@ void Display::set_mode(const VideoMode &requested_mode, bool)
 
        for(list<Monitor>::iterator i=monitors.begin(); i!=monitors.end(); ++i)
                if(&*i==mode->monitor)
-                       i->current_mode = mode;
+                       i->current_settings.mode = mode;
 }
 
 bool Display::process_events()
index a48f3f874f1a3600da402f9fd88a1138b7f80c89..ba8d2532d914494e31ca847abdb5052926c2b6df 100644 (file)
@@ -63,9 +63,9 @@ inline Rotation rotation_to_sys(Msp::Graphics::VideoRotation r)
 
 inline bool monitor_x_compare(const Msp::Graphics::Monitor &m1, const Msp::Graphics::Monitor &m2)
 {
-       if(m1.desktop_mode && !m2.desktop_mode)
+       if(m1.desktop_settings.mode && !m2.desktop_settings.mode)
                return true;
-       return m1.x<m2.x;
+       return m1.desktop_settings.x<m2.desktop_settings.x;
 }
 #endif
 
@@ -155,10 +155,9 @@ Display::Display(const string &disp_name):
 
                                if(crtc)
                                {
-                                       monitor.desktop_rotation = rotation_from_sys(crtc->rotation);
-                                       monitor.current_rotation = monitor.desktop_rotation;
-                                       monitor.x = crtc->x;
-                                       monitor.y = crtc->y;
+                                       monitor.desktop_settings.rotation = rotation_from_sys(crtc->rotation);
+                                       monitor.desktop_settings.x = crtc->x;
+                                       monitor.desktop_settings.y = crtc->y;
                                }
 
                                if(res->outputs[i]==primary)
@@ -184,12 +183,11 @@ Display::Display(const string &disp_name):
                                        monitor.video_modes.push_back(&modes.back());
 
                                        if(crtc && info->id==crtc->mode)
-                                       {
-                                               monitor.desktop_mode = &modes.back();
-                                               monitor.current_mode = monitor.desktop_mode;
-                                       }
+                                               monitor.desktop_settings.mode = &modes.back();
                                }
 
+                               monitor.current_settings = monitor.desktop_settings;
+
                                XRRFreeOutputInfo(output);
                                if(crtc)
                                        XRRFreeCrtcInfo(crtc);
@@ -200,7 +198,7 @@ Display::Display(const string &disp_name):
                        monitors.sort(monitor_x_compare);
                        Monitor *prev_enabled = 0;
                        for(list<Monitor>::iterator i=monitors.begin(); i!=monitors.end(); ++i)
-                               if(i->desktop_mode)
+                               if(i->desktop_settings.mode)
                                {
                                        i->next_left = prev_enabled;
                                        if(prev_enabled)
@@ -208,14 +206,14 @@ Display::Display(const string &disp_name):
                                        prev_enabled = &*i;
                                }
 
-                       if(!primary_monitor || !primary_monitor->desktop_mode)
+                       if(!primary_monitor || !primary_monitor->desktop_settings.mode)
                        {
                                // XRandR didn't give a sensible primary monitor.  Try to guess one.
                                unsigned largest = 0;
                                for(list<Monitor>::iterator i=monitors.begin(); i!=monitors.end(); ++i)
-                                       if(i->desktop_mode)
+                                       if(const VideoMode *desktop_mode = i->desktop_settings.mode)
                                        {
-                                               unsigned size = i->desktop_mode->width*i->desktop_mode->height;
+                                               unsigned size = desktop_mode->width*desktop_mode->height;
                                                if(size>largest)
                                                {
                                                        largest = size;
@@ -244,7 +242,7 @@ void Display::set_mode(const VideoMode &requested_mode, bool exclusive)
 
        VideoRotation requested_rotation = requested_mode.rotation;
        if(requested_rotation==ROTATE_ANY)
-               requested_rotation = mode->monitor->desktop_rotation;
+               requested_rotation = mode->monitor->desktop_settings.rotation;
 
        XRRScreenResources *res = XRRGetScreenResources(priv->display, priv->root_window);
        RROutput output = priv->monitors[mode->monitor->index];
@@ -289,22 +287,23 @@ void Display::set_mode(const VideoMode &requested_mode, bool exclusive)
                                        XRRSetCrtcConfig(priv->display, res, o->crtc, CurrentTime, 0, 0, 0, RR_Rotate_0, 0, 0);
                                XRRFreeOutputInfo(o);
 
-                               i->current_mode = 0;
-                               i->current_rotation = ROTATE_NORMAL;
-                               i->x = 0;
-                               i->y = 0;
+                               i->current_settings.mode = 0;
+                               i->current_settings.rotation = ROTATE_NORMAL;
+                               i->current_settings.x = 0;
+                               i->current_settings.y = 0;
                        }
        }
        else
        {
                const Monitor *left = mode->monitor->next_left;
-               while(left && !left->current_mode)
+               while(left && !left->current_settings.mode)
                        left = left->next_left;
 
                if(left)
                {
-                       x = left->x+mode_width(*left->current_mode, left->current_rotation);
-                       y = left->y;
+                       const Monitor::Settings &cs = left->current_settings;
+                       x = cs.x+mode_width(*cs.mode, cs.rotation);
+                       y = cs.y;
                }
        }
 
@@ -314,10 +313,10 @@ void Display::set_mode(const VideoMode &requested_mode, bool exclusive)
        for(i=monitors.begin(); i!=monitors.end(); ++i)
                if(&*i==mode->monitor)
                {
-                       i->current_mode = mode;
-                       i->current_rotation = requested_rotation;
-                       i->x = x;
-                       i->y = y;
+                       i->current_settings.mode = mode;
+                       i->current_settings.rotation = requested_rotation;
+                       i->current_settings.x = x;
+                       i->current_settings.y = y;
 
                        x += mode_width(*mode, requested_rotation);
                        ++i;
@@ -325,17 +324,17 @@ void Display::set_mode(const VideoMode &requested_mode, bool exclusive)
                }
 
        for(; i!=monitors.end(); ++i)
-               if(i->current_mode)
+               if(i->current_settings.mode)
                {
                        XRROutputInfo *o = XRRGetOutputInfo(priv->display, res, priv->monitors[i->index]);
-                       XRRSetCrtcConfig(priv->display, res, o->crtc, CurrentTime, x, y, priv->modes[i->current_mode->index], rotation_to_sys(i->current_rotation), &priv->monitors[i->index], 1);
+                       XRRSetCrtcConfig(priv->display, res, o->crtc, CurrentTime, x, y, priv->modes[i->current_settings.mode->index], rotation_to_sys(i->current_settings.rotation), &priv->monitors[i->index], 1);
 
                        XRRPanning panning;
                        panning.timestamp = CurrentTime;
                        panning.left = x;
                        panning.top = y;
-                       panning.width = i->current_mode->width;
-                       panning.height = i->current_mode->height;
+                       panning.width = i->current_settings.mode->width;
+                       panning.height = i->current_settings.mode->height;
                        panning.track_left = panning.left;
                        panning.track_top = panning.top;
                        panning.track_width = panning.width;
@@ -348,10 +347,10 @@ void Display::set_mode(const VideoMode &requested_mode, bool exclusive)
 
                        XRRFreeOutputInfo(o);
 
-                       i->x = x;
-                       i->y = y;
+                       i->current_settings.x = x;
+                       i->current_settings.y = y;
 
-                       x += mode_width(*i->current_mode, i->current_rotation);
+                       x += mode_width(*i->current_settings.mode, i->current_settings.rotation);
                }
 
        XRRFreeOutputInfo(output_info);