Last active
August 29, 2015 13:56
-
-
Save draftcode/8797636 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <memory> | |
#include <X11/Xlib.h> | |
#include <X11/extensions/Xrandr.h> | |
class unique_display : public std::unique_ptr<Display, int(*)(Display*)> { | |
public: | |
unique_display(Display *dpy) : std::unique_ptr<Display, int(*)(Display*)>( | |
dpy, XCloseDisplay) {} | |
}; | |
class unique_screen_resources : public std::unique_ptr<XRRScreenResources, void(*)(XRRScreenResources*)> { | |
public: | |
unique_screen_resources(XRRScreenResources *res) : std::unique_ptr<XRRScreenResources, void(*)(XRRScreenResources*)>( | |
res, XRRFreeScreenResources) {} | |
}; | |
class unique_output_info : public std::unique_ptr<XRROutputInfo, void(*)(XRROutputInfo*)> { | |
public: | |
unique_output_info(XRROutputInfo *output_info) : std::unique_ptr<XRROutputInfo, void(*)(XRROutputInfo*)>( | |
output_info, XRRFreeOutputInfo) {} | |
}; | |
class unique_crtc_info : public std::unique_ptr<XRRCrtcInfo, void(*)(XRRCrtcInfo*)> { | |
public: | |
unique_crtc_info(XRRCrtcInfo *crtc_info) : std::unique_ptr<XRRCrtcInfo, void(*)(XRRCrtcInfo*)>( | |
crtc_info, XRRFreeCrtcInfo) {} | |
}; | |
int main(void) { | |
unique_display dpy(XOpenDisplay(NULL)); | |
if (!dpy) return 1; | |
unique_screen_resources res( | |
XRRGetScreenResources(dpy.get(), RootWindow(dpy.get(), 0))); | |
if (!res) return 1; | |
for (int output_number = 0; output_number < res->noutput; ++output_number) { | |
unique_output_info output_info( | |
XRRGetOutputInfo(dpy.get(), res.get(), res->outputs[output_number])); | |
if (!output_info) return 1; | |
if (output_info->connection == RR_Connected) { | |
RRCrtc crtc = 0; | |
if (output_info->crtc != 0) { | |
crtc = output_info->crtc; | |
} else if (output_info->ncrtc) { | |
crtc = output_info->crtcs[0]; | |
} | |
unique_crtc_info crtc_info(XRRGetCrtcInfo(dpy.get(), res.get(), crtc)); | |
if (!crtc_info) return 1; | |
RRMode mode = output_info->modes[0]; | |
XRRSetCrtcConfig(dpy.get(), res.get(), crtc, CurrentTime, | |
crtc_info->x, crtc_info->y, mode, | |
crtc_info->rotation, crtc_info->outputs, | |
crtc_info->noutput); | |
} | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all_fullscreen: all_fullscreen.cc | |
${CXX} -std=c++11 -lX11 -lXinerama -lXrandr -o $@ $^ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment