eqemu

diff src/main.cc @ 2:48dce4ee4850

the fake device is working
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 15 Jul 2014 14:37:51 +0300
parents 374d91dd2996
children 3d3656360a82
line diff
     1.1 --- a/src/main.cc	Tue Jul 15 05:44:26 2014 +0300
     1.2 +++ b/src/main.cc	Tue Jul 15 14:37:51 2014 +0300
     1.3 @@ -20,6 +20,8 @@
     1.4  static void process_events();
     1.5  static int translate_keysym(KeySym sym);
     1.6  
     1.7 +static int proc_args(int argc, char **argv);
     1.8 +
     1.9  static Display *dpy;
    1.10  static Window win;
    1.11  static GLXContext ctx;
    1.12 @@ -30,10 +32,15 @@
    1.13  static bool redisplay_pending;
    1.14  static bool win_mapped;
    1.15  
    1.16 -int main()
    1.17 +static int fakefd = -1;
    1.18 +static char *fake_devpath;
    1.19 +
    1.20 +int main(int argc, char **argv)
    1.21  {
    1.22 +	if(proc_args(argc, argv) == -1) {
    1.23 +		return 1;
    1.24 +	}
    1.25  	if(!init()) {
    1.26 -		fprintf(stderr, "X11/OpenGL initialization failed\n");
    1.27  		return 1;
    1.28  	}
    1.29  	atexit(cleanup);
    1.30 @@ -45,12 +52,18 @@
    1.31  		FD_ZERO(&rd);
    1.32  
    1.33  		FD_SET(xfd, &rd);
    1.34 +		FD_SET(fakefd, &rd);
    1.35  
    1.36 -		while(select(xfd + 1, &rd, 0, 0, 0) == -1 && errno == EINTR);
    1.37 +		int maxfd = xfd > fakefd ? xfd : fakefd;
    1.38 +
    1.39 +		while(select(maxfd + 1, &rd, 0, 0, 0) == -1 && errno == EINTR);
    1.40  
    1.41  		if(FD_ISSET(xfd, &rd)) {
    1.42  			process_events();
    1.43  		}
    1.44 +		if(FD_ISSET(fakefd, &rd)) {
    1.45 +			proc_dev_input();
    1.46 +		}
    1.47  
    1.48  		if(redisplay_pending) {
    1.49  			display();
    1.50 @@ -62,7 +75,11 @@
    1.51  
    1.52  static bool init()
    1.53  {
    1.54 -	start_dev();
    1.55 +	if(fake_devpath) {
    1.56 +		if((fakefd = start_dev(fake_devpath)) == -1) {
    1.57 +			return false;
    1.58 +		}
    1.59 +	}
    1.60  
    1.61  	if(!(dpy = XOpenDisplay(0))) {
    1.62  		fprintf(stderr, "failed to connect to the X server!\n");
    1.63 @@ -290,3 +307,24 @@
    1.64  	}
    1.65  	return (int)sym;
    1.66  }
    1.67 +
    1.68 +static int proc_args(int argc, char **argv)
    1.69 +{
    1.70 +	for(int i=1; i<argc; i++) {
    1.71 +		if(argv[i][0] == '-') {
    1.72 +			fprintf(stderr, "unexpected option: %s\n", argv[i]);
    1.73 +			return -1;
    1.74 +
    1.75 +		} else {
    1.76 +			if(fake_devpath) {
    1.77 +				fprintf(stderr, "unexpected argument: %s\n", argv[i]);
    1.78 +				return -1;
    1.79 +			}
    1.80 +			fake_devpath = argv[i];
    1.81 +		}
    1.82 +	}
    1.83 +	if(!fake_devpath) {
    1.84 +		fprintf(stderr, "no device path specified, running standalone\n");
    1.85 +	}
    1.86 +	return 0;
    1.87 +}