diff --git a/engine.cmake b/engine.cmake index f12044a..5af28f1 100644 --- a/engine.cmake +++ b/engine.cmake @@ -118,6 +118,7 @@ set(ENGINE_PLATFORM_UNIX_SRC # X11 source/Platform/Unix/Xlib.cpp + source/Platform/Unix/XRandR.cpp source/Platform/Unix/X11Display.cpp source/Platform/Unix/X11Input.cpp source/Platform/Unix/X11Keyboard.cpp diff --git a/source/Platform/Unix/XRandR.cpp b/source/Platform/Unix/XRandR.cpp new file mode 100644 index 0000000..c934218 --- /dev/null +++ b/source/Platform/Unix/XRandR.cpp @@ -0,0 +1,34 @@ +#include "XRandR.h" +#include +#include + +namespace sp { + +bool XRandR::FindMode(::Display* disp, unsigned int width, unsigned int height, unsigned int bpp, SizeID *id, short *rate) +{ + ::XRRScreenSize *xrrs; + int num_sizes; + + xrrs = XRRSizes(disp, 0, &num_sizes); + for(int i = 0; i < num_sizes; i++) { + + Log::debug("Mode %dx%d", xrrs[i].width, xrrs[i].height); + + if (xrrs[i].width != width && xrrs[i].height != height) { + continue; + } + + short *rates; + int num_rates; + + rates = XRRRates(disp, 0, i, &num_rates); + if (num_rates > 0) { + *id = i; + *rate = rates[num_rates - 1]; + return true; + } + } + return false; +} + +} // namespace sp \ No newline at end of file diff --git a/source/Platform/Unix/XRandR.h b/source/Platform/Unix/XRandR.h new file mode 100644 index 0000000..6faac86 --- /dev/null +++ b/source/Platform/Unix/XRandR.h @@ -0,0 +1,18 @@ + +#ifndef PLATFORM_UNIX_XRANDR_H +#define PLATFORM_UNIX_XRANDR_H + +#include + +namespace sp { namespace XRandR { + +struct VideoMode { + SizeID size; + short rate; +}; + +bool FindMode(::Display* disp, unsigned int width, unsigned int height, unsigned int bpp, SizeID *id, short *rate); + +} } // sp::XRandR + +#endif /* PLATFORM_UNIX_XRANDR_H */