Linux Patches ?

Started by Robot Guy, June 27, 2005, 21:54:28

Previous topic - Next topic

Robot Guy

I've just downloaded lwjgl and had a play and it looks wonderful but I did come across two little niggles that are quite easy to work around and I wondered if this was the right place to suggest the changes ? I don't know if anybody else is having these problems perhaps the person who maintains the Linux version could take a look ?

The first problem I had was that on my system lwjgl uses the Xrandr extension to change the screen resolution when going to full screen. This works well but my window manager (KDE 3.2) decides to adjust the size of all the other windows that are on my desktop, normally leving me with very short or narrow terminals. Very annoying! If it uses XF86VidMode then it works perfectly so I put a patch in that optionally disables the use of Xrandr.

In src/native/linux/display.c isXrandrSupported I query to see if the environmental variable LWJGL_DISABLE_XRANDR is set and if so return that Xrandr is not supported.

static bool isXrandrSupported(JNIEnv *env, Display *disp) {
	int major, minor;
>	if(getenv("LWJGL_DISABLE_XRANDR") != NULL)
>		return false;
	if (!getXrandrVersion(env, disp, &major, &minor))
		return false;
	return major >= 1;
}


The second problem, which on the message boards I did see that others suffered with, is that if the program crashes then the key auto repeat isn't reset. The patch to this is a bit of a hack as it always resets the auto repeat even when it isn't needed and probably fails to shutdown other things that probably need doing but with a quick look I couldn't figure out how to tell if the window needs to be closed.

Added to src/native/linux/org_lwjgl_opengl_Display.c but it could really go anywhere:

void __attribute__ ((destructor)) my_fini(void) {
	XKeyboardControl repeat_mode;
	repeat_mode.auto_repeat_mode = AutoRepeatModeDefault;
	Display *disp = XOpenDisplay(NULL);
	if (disp != NULL) {
		XChangeKeyboardControl(disp, KBAutoRepeatMode, &repeat_mode);
		XCloseDisplay(disp);
	}
}


This basically resets the auto repeat mode when liblwjgl.so is unloaded. How was cribbed from
http://en.tldp.org/HOWTO/Program-Library-HOWTO/miscellaneous.html#INIT-AND-FINI
and it seems to work for me but more extensive testing might be warrented.

For a better solution I'd add a flag to indicate if the window was opened (by setting in createWindow and clearing in destroyWindow) and if set in the fini function run a modified versien of destroyWindow (one that doesn't need a java environment), but I didn't want to poke around too much with bits I didn't understand well.

elias

Thanks. The second patch (reset keyboard repeat) has been applied. You should be able to achieve the same effect as the first patch by setting the environment variable LWJGL_DISABLE_NETWM, which should both disable NETWM and Xrandr.

- elias

biggeruniverse

Along these XRANDR lines, I'm using RH9.1/Gnome2.3, and after just upgrading to LWJGL 0.99, everything broke. The initial error was a non-descript NoClassDefError on the Display.destroy() line, and after fiddling with and finally commenting out this line, I get this:

java.lang.Error: getenv no longer supported, use properties and -D instead: LWJGL_DISABLE_XRANDR
   at java.lang.System.getenv(System.java:689)
   at org.lwjgl.opengl.LinuxDisplay.isXrandrSupported(LinuxDisplay.java:124)
   at org.lwjgl.opengl.LinuxDisplay.getBestDisplayModeExtension(LinuxDisplay.java:110)
   at org.lwjgl.opengl.LinuxDisplay.init(LinuxDisplay.java:366)
   at org.lwjgl.opengl.Display.<clinit>(Display.java:107)
   at march2.render.LwjglDisplay.getDisplayMode(LwjglDisplay.java:94)
   at march2.render.LwjglDisplay.createDisplay(LwjglDisplay.java:121)
   at march2.demos.OutdoorTest.init(OutdoorTest.java:73)
   at march2.util.GlApp.run(GlApp.java:150)

I don't mind using a work around, but perhaps this should be better caught?`

EDIT: java 1.4.1_05

On further investigation, I find http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#getenv(java.lang.String). It seems System.getProperty() is a better choice, since many JVMs support it (1.3 & 1.4 deprecate System.getenv)

Fool Running

Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D