From: Mikko Rasa Date: Fri, 16 Sep 2016 23:00:36 +0000 (+0300) Subject: Retain monitor positions when setting non-exclusive modes X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=35d4d400521d30d84c20cd1434626e131cbf9304;p=libs%2Fgui.git Retain monitor positions when setting non-exclusive modes Trying to rearrange the monitors was a stupid idea, as it can easily mess up the user's configuration. --- diff --git a/source/graphics/x11/display.cpp b/source/graphics/x11/display.cpp index ba8d253..972cc82 100644 --- a/source/graphics/x11/display.cpp +++ b/source/graphics/x11/display.cpp @@ -273,11 +273,17 @@ void Display::set_mode(const VideoMode &requested_mode, bool exclusive) } } - int x = 0; - int y = 0; + /* Due to the semantics of find_mode, the mode's monitor pointer must point + to one of the elements of the monitors list, which is non-const here. */ + Monitor *monitor = const_cast(mode->monitor); if(exclusive) { + monitor->current_settings.mode = mode; + monitor->current_settings.rotation = requested_rotation; + monitor->current_settings.x = 0; + monitor->current_settings.y = 0; + // Disable other outputs for exclusive mode for(list::iterator i=monitors.begin(); i!=monitors.end(); ++i) if(&*i!=mode->monitor) @@ -295,63 +301,15 @@ void Display::set_mode(const VideoMode &requested_mode, bool exclusive) } else { - const Monitor *left = mode->monitor->next_left; - while(left && !left->current_settings.mode) - left = left->next_left; - - if(left) - { - const Monitor::Settings &cs = left->current_settings; - x = cs.x+mode_width(*cs.mode, cs.rotation); - y = cs.y; - } + monitor->current_settings.x = monitor->desktop_settings.x; + monitor->current_settings.y = monitor->desktop_settings.y; } - XRRSetCrtcConfig(priv->display, res, crtc, CurrentTime, x, y, priv->modes[mode->index], rotation_to_sys(requested_rotation), &output, 1); - - list::iterator i; - for(i=monitors.begin(); i!=monitors.end(); ++i) - if(&*i==mode->monitor) - { - 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; - break; - } - - for(; i!=monitors.end(); ++i) - 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_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_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; - panning.track_height = panning.height; - panning.border_left = 0; - panning.border_top = 0; - panning.border_right = 0; - panning.border_bottom = 0; - XRRSetPanning(priv->display, res, o->crtc, &panning); - - XRRFreeOutputInfo(o); - - i->current_settings.x = x; - i->current_settings.y = y; - - x += mode_width(*i->current_settings.mode, i->current_settings.rotation); - } + RRMode mode_id = priv->modes[mode->index]; + int x = monitor->current_settings.x; + int y = monitor->current_settings.y; + Rotation sys_rot = rotation_to_sys(requested_rotation); + XRRSetCrtcConfig(priv->display, res, crtc, CurrentTime, x, y, mode_id, sys_rot, &output, 1); XRRFreeOutputInfo(output_info); XRRFreeCrtcInfo(crtc_info);