Linux: Made the XRRSetScreenConfigAndRate retry loop more robust in order to avoid endless loops
This commit is contained in:
parent
7b57affe3c
commit
c1350ff363
|
@ -213,19 +213,36 @@ static bool setXF86VidModeMode(Display *disp, int screen, mode_info *mode) {
|
||||||
return True == XF86VidModeSwitchToMode(disp, screen, &mode->mode_data.xf86vm_modeinfo);
|
return True == XF86VidModeSwitchToMode(disp, screen, &mode->mode_data.xf86vm_modeinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Try to set the mode specified through XRandR.
|
||||||
|
* Return value is the Status code of the mode switch
|
||||||
|
* The timestamp parameter is filled with the latest timestamp returned from XRRConfigTimes
|
||||||
|
*/
|
||||||
|
static Status trySetXrandrMode(Display *disp, int screen, mode_info *mode, Time *timestamp) {
|
||||||
|
Status status;
|
||||||
|
Drawable root_window = RootWindow(disp, screen);
|
||||||
|
XRRScreenConfiguration *screen_configuration = XRRGetScreenInfo (disp, root_window);
|
||||||
|
XRRConfigTimes(screen_configuration, timestamp);
|
||||||
|
Rotation current_rotation;
|
||||||
|
XRRConfigRotations(screen_configuration, ¤t_rotation);
|
||||||
|
status = XRRSetScreenConfigAndRate(disp, screen_configuration, root_window, mode->mode_data.size_index, current_rotation, mode->freq, *timestamp);
|
||||||
|
XRRFreeScreenConfigInfo(screen_configuration);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
static bool setXrandrMode(Display *disp, int screen, mode_info *mode) {
|
static bool setXrandrMode(Display *disp, int screen, mode_info *mode) {
|
||||||
Status success;
|
Time timestamp;
|
||||||
do {
|
Status status = trySetXrandrMode(disp, screen, mode, ×tamp);
|
||||||
Time config_time;
|
if (status == 0)
|
||||||
Drawable root_window = RootWindow(disp, screen);
|
return true; // Success
|
||||||
XRRScreenConfiguration *screen_configuration = XRRGetScreenInfo (disp, root_window);
|
Time new_timestamp;
|
||||||
XRRConfigTimes(screen_configuration, &config_time);
|
while (true) {
|
||||||
Rotation current_rotation;
|
status = trySetXrandrMode(disp, screen, mode, &new_timestamp);
|
||||||
XRRConfigRotations(screen_configuration, ¤t_rotation);
|
if (status == 0)
|
||||||
success = XRRSetScreenConfigAndRate(disp, screen_configuration, root_window, mode->mode_data.size_index, current_rotation, mode->freq, config_time);
|
return true; // Success
|
||||||
XRRFreeScreenConfigInfo(screen_configuration);
|
if (new_timestamp == timestamp)
|
||||||
} while (success != 0);
|
return false; // Failure, and the stamps are equal meaning that the failure is not merely transient
|
||||||
return true;
|
timestamp = new_timestamp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool setMode(JNIEnv *env, Display *disp, int screen, int width, int height, int freq, bool temporary) {
|
static bool setMode(JNIEnv *env, Display *disp, int screen, int width, int height, int freq, bool temporary) {
|
||||||
|
|
Loading…
Reference in New Issue