Unix: Adding FindMode() XRandR helper function.
This commit is contained in:
parent
624871486f
commit
186a6e0f14
3 changed files with 53 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
34
source/Platform/Unix/XRandR.cpp
Normal file
34
source/Platform/Unix/XRandR.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#include "XRandR.h"
|
||||
#include <Spectre/System/Log.h>
|
||||
#include <algorithm>
|
||||
|
||||
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
|
||||
18
source/Platform/Unix/XRandR.h
Normal file
18
source/Platform/Unix/XRandR.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
#ifndef PLATFORM_UNIX_XRANDR_H
|
||||
#define PLATFORM_UNIX_XRANDR_H
|
||||
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
|
||||
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 */
|
||||
Loading…
Add table
Add a link
Reference in a new issue