+static int xrandr_resize(int xsz, int ysz, int just_checking)
+{
+ int res = -1;
+
+#ifdef HAVE_X11_EXTENSIONS_XRANDR_H
+ int event_base, error_base;
+ Status st;
+ XRRScreenConfiguration *xrr_config;
+ XRRScreenSize *ssizes;
+ Rotation rot;
+ int i, ssizes_count, curr;
+ Time timestamp, cfg_timestamp;
+
+ /* must check at runtime for the availability of the extension */
+ if(!XRRQueryExtension(fgDisplay.Display, &event_base, &error_base)) {
+ return -1;
+ }
+
+ if(!(xrr_config = XRRGetScreenInfo(fgDisplay.Display, fgDisplay.RootWindow))) {
+ fgWarning("XRRGetScreenInfo failed");
+ return -1;
+ }
+ ssizes = XRRConfigSizes(xrr_config, &ssizes_count);
+ curr = XRRConfigCurrentConfiguration(xrr_config, &rot);
+ timestamp = XRRConfigTimes(xrr_config, &cfg_timestamp);
+
+ if(xsz == ssizes[curr].width && ysz == ssizes[curr].height) {
+ /* no need to switch, we're already in the requested mode */
+ res = 0;
+ goto done;
+ }
+
+ for(i=0; i<ssizes_count; i++) {
+ if(ssizes[i].width == xsz && ssizes[i].height == ysz) {
+ break; /* found it */
+ }
+ }
+ if(i == ssizes_count)
+ goto done;
+
+ if(just_checking) {
+ res = 0;
+ goto done;
+ }
+
+ if((st = XRRSetScreenConfig(fgDisplay.Display, xrr_config, fgDisplay.RootWindow,
+ i, rot, timestamp)) != 0) {
+ fgWarning("XRRSetScreenConfig failed");
+ goto done;
+ }
+ res = 0;
+
+done:
+ XRRFreeScreenConfigInfo(xrr_config);
+#endif
+ return res;
+}
+
+