From: Elias N. <eli...@us...> - 2005-08-21 20:27:29
|
Update of /cvsroot/java-game-lib/LWJGL/src/native/linux In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21091/src/native/linux Modified Files: display.c Log Message: Linux: Made the XRRSetScreenConfigAndRate retry loop more robust in order to avoid endless loops Index: display.c =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/linux/display.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- display.c 16 Jan 2005 10:43:30 -0000 1.7 +++ display.c 21 Aug 2005 20:27:20 -0000 1.8 @@ -213,19 +213,36 @@ 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) { - Status success; - do { - Time config_time; - Drawable root_window = RootWindow(disp, screen); - XRRScreenConfiguration *screen_configuration = XRRGetScreenInfo (disp, root_window); - XRRConfigTimes(screen_configuration, &config_time); - Rotation current_rotation; - XRRConfigRotations(screen_configuration, ¤t_rotation); - success = XRRSetScreenConfigAndRate(disp, screen_configuration, root_window, mode->mode_data.size_index, current_rotation, mode->freq, config_time); - XRRFreeScreenConfigInfo(screen_configuration); - } while (success != 0); - return true; + Time timestamp; + Status status = trySetXrandrMode(disp, screen, mode, ×tamp); + if (status == 0) + return true; // Success + Time new_timestamp; + while (true) { + status = trySetXrandrMode(disp, screen, mode, &new_timestamp); + if (status == 0) + return true; // Success + if (new_timestamp == timestamp) + return false; // Failure, and the stamps are equal meaning that the failure is not merely transient + timestamp = new_timestamp; + } } static bool setMode(JNIEnv *env, Display *disp, int screen, int width, int height, int freq, bool temporary) { |