XF86VidModeGetAllModeLines() returns fewer modes each time

Basin Ilya basinilya at gmail.com
Mon Apr 3 19:56:22 UTC 2017


Hi list.
I wrote a test program to list available screen resolutions and maybe switch to one of them. Apparently, my program is incomplete and I have to restore the resolution using my DE settings, but after I restore it and run my program again, that mode disappears from the output of `XF86VidModeGetAllModeLines()`. Originally it contained `1400x1050`, `1600x900`, and `1440x900`, but each time I repeat my actions, the function returns fewer results. Why is that?

    $ gcc -o test test.c -lX11 -lXxf86vm
    $ ./test
	1920x1080
	1680x1050
	1920x1080
	1920x1080
	1280x1024
	1280x1024
	1280x800
	1280x720
	1152x864
	1024x768
	1024x768
	800x600
	800x600
	800x600
	640x480
	640x480
	1366x768

_

	#include <stdio.h>
	#include <sys/types.h>
	#include <string.h>
	#include <X11/Xlib.h>
	#include <X11/extensions/xf86vmode.h>

	static Bool b;
	static Display* display = NULL;


	void dostuff(int screen)
	{
		int flag = 0;
		int modeCount;
		XF86VidModeModeInfo** modes;
	
		if (XF86VidModeGetAllModeLines(display, screen, &modeCount, &modes))
		{
			for(int i = 0; i < modeCount; i ++)
			{
				printf("%hdx%hd\n", modes[i]->hdisplay, modes[i]->vdisplay);
				//continue;
				if (!flag && 1600 == modes[i]->hdisplay && 900 == modes[i]->vdisplay) {
					flag = 1;
					b = XF86VidModeSwitchToMode(display, screen, modes[i]);
					printf("%d\n", b);
					b = XF86VidModeSetViewPort(display, screen, 0, 0);
					printf("%d\n", b);
					XFlush(display);
				}
			}
			XFree(modes);

		}
	}

	int main(int argc, char *argv[]) {
		if (display == NULL) {
			display = XOpenDisplay(NULL);
		}
		if (display == NULL) {
			return 1;
		}		
		dostuff(0);
		XCloseDisplay(display);

		return 0;
	}

My card is GeForce 9600, driver version: 340.101.


More information about the xorg mailing list