From: Mikko Rasa Date: Fri, 16 Sep 2016 21:34:26 +0000 (+0300) Subject: Refactor storage of monitor settings X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a8a9191481151f049781b670ea8883025a594a5f;p=libs%2Fgui.git Refactor storage of monitor settings --- diff --git a/source/graphics/display.cpp b/source/graphics/display.cpp index 1c7b639..ebf14ea 100644 --- a/source/graphics/display.cpp +++ b/source/graphics/display.cpp @@ -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::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 diff --git a/source/graphics/monitor.cpp b/source/graphics/monitor.cpp index 1ac4383..d1bdd43 100644 --- a/source/graphics/monitor.cpp +++ b/source/graphics/monitor.cpp @@ -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 diff --git a/source/graphics/monitor.h b/source/graphics/monitor.h index 35abce1..fefd986 100644 --- a/source/graphics/monitor.h +++ b/source/graphics/monitor.h @@ -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 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; diff --git a/source/graphics/window.cpp b/source/graphics/window.cpp index 073cd8d..958667e 100644 --- a/source/graphics/window.cpp +++ b/source/graphics/window.cpp @@ -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); diff --git a/source/graphics/windows/display.cpp b/source/graphics/windows/display.cpp index d767beb..aaaa985 100644 --- a/source/graphics/windows/display.cpp +++ b/source/graphics/windows/display.cpp @@ -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::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() diff --git a/source/graphics/x11/display.cpp b/source/graphics/x11/display.cpp index a48f3f8..ba8d253 100644 --- a/source/graphics/x11/display.cpp +++ b/source/graphics/x11/display.cpp @@ -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.xrotation); - 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::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::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);