1
0
Fork 0

Unix: Adding FindMode() XRandR helper function.

This commit is contained in:
Henrik Hautakoski 2023-08-02 05:21:35 +02:00
parent 624871486f
commit 186a6e0f14
3 changed files with 53 additions and 0 deletions

View file

@ -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

View 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

View 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 */