]> git.tdb.fi Git - libs/gui.git/commitdiff
Retain monitor positions when setting non-exclusive modes
authorMikko Rasa <tdb@tdb.fi>
Fri, 16 Sep 2016 23:00:36 +0000 (02:00 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 16 Sep 2016 23:00:36 +0000 (02:00 +0300)
Trying to rearrange the monitors was a stupid idea, as it can easily mess
up the user's configuration.

source/graphics/x11/display.cpp

index ba8d2532d914494e31ca847abdb5052926c2b6df..972cc8236f25024eec7fee0167811a4aeb76814b 100644 (file)
@@ -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<Monitor *>(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<Monitor>::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<Monitor>::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);