示例#1
0
文件: key.c 项目: GregBowyer/wmii
void
kpress(XWindow w, ulong mod, KeyCode keycode) {
	Key *k, *found;

	for(k=key; k; k=k->lnext)
		 k->tnext = k->lnext;

	found = match_keys(key, mod, keycode, false);
	if(!found) /* grabbed but not found */
		XBell(display, 0);
	else if(!found->tnext && !found->next)
		event("Key %s\n", found->name);
	else {
		XGrabKeyboard(display, w, true, GrabModeAsync, GrabModeAsync, CurrentTime);
		event_flush(FocusChangeMask, true);
		kpress_seq(w, found);
		XUngrabKeyboard(display, CurrentTime);
	}
}
示例#2
0
文件: init.c 项目: 9072997/wikireader
int MenuHandler(void)
{
	lcd_clear(LCD_WHITE);

	int x;
	int y;
	size_t i = 0;
	for (y = 0; y < Y_COUNT; ++y) {
		for (x = 0; x < X_COUNT; ++x) {
			if (MenuRecord[i].ok) {
				MenuRecord[i].x = X_START + (X_SIZE + X_GAP) * x;
				MenuRecord[i].y = Y_START + (Y_SIZE + Y_GAP) * y;
				lcd_bitmap(lcd_get_framebuffer(), LCD_BUFFER_WIDTH_BYTES,
					   MenuRecord[i].x, MenuRecord[i].y,
					   X_SIZE, Y_SIZE, false, MenuRecord[i].icon);
			}
			++i;
		}
	}


	event_flush();

	int cursor = -1;  // valid cursor positions are: 0 .. SizeOfArray(MenuRecord) - 1

	for (;;) {
		event_t event;

		switch(event_wait(&event, NULL, NULL)) {  // no callback, just power off

		case EVENT_NONE:
			break;

		case EVENT_KEY:
			break;

		case EVENT_TOUCH_DOWN:
		case EVENT_TOUCH_MOTION:
		{
			int position = CursorPosition(event.touch.x, event.touch.y);

			if (cursor != position) {
				if (cursor >= 0) {
					lcd_bitmap(lcd_get_framebuffer(), LCD_BUFFER_WIDTH_BYTES,
						   MenuRecord[cursor].x, MenuRecord[cursor].y,
						   X_SIZE, Y_SIZE, false, MenuRecord[cursor].icon);
				}
				if (position >= 0 && position < (int)SizeOfArray(MenuRecord)
				    && MenuRecord[position].ok) {
					cursor = position;
					lcd_bitmap(lcd_get_framebuffer(), LCD_BUFFER_WIDTH_BYTES,
						   MenuRecord[cursor].x, MenuRecord[cursor].y,
						   X_SIZE, Y_SIZE, true, MenuRecord[cursor].icon);
				} else {
					cursor = -1;
				}
			}
		}
		break;

		case EVENT_TOUCH_UP:
			if (cursor >= 0 && cursor < (int)SizeOfArray(MenuRecord)) {
				chain(MenuRecord[cursor].command);
			}
			break;

		case EVENT_BUTTON_DOWN:
			break;

		case EVENT_BUTTON_UP:
			break;

		case EVENT_BATTERY_LOW:
			break;
		}
	}
	return EXIT_POWER_OFF;
}
示例#3
0
文件: main.c 项目: pfhchaos/cabrio
int main( int argc, char *arvg[] ) {
	int quit = 0;
	int config_status = 0;
	int event;

#ifdef __WIN32__
	freopen( "cabrio.out", "w", stdout );
	freopen( "cabrio.err", "w", stderr );
#endif

	config_status = config_open( NULL );
	if( config_status == -1 )
		return -1;

	if( sdl_init() != 0 )
		bail();

	if( ogl_init() != 0 )
		bail();
	
	/* Clear the screen as soon as we can. This avoids graphics
	 * glitches which can occur with some SDL implementations. */
	ogl_clear();
	sdl_swap();

	if( event_init() != 0 )
		bail();

	if( font_init() != 0 )
		bail();

	if( config_status == 1 ) {
		/* Config file didn't exist, so run the setup utility */
		if( setup() != 0 )
			return -1;
		config_update();
		if( config_create() != 0 )
			return -1;
	}

	location_init();

	/* If config or location results in a new font, it'll be loaded here. */
	font_free();
	font_init();

	/* Large game lists take a while to initialise,
	 * so show the background while we wait... */
	bg_init();
	bg_clear();
	bg_draw();
	sdl_swap();

	if( platform_init() != 0 )
		bail();

	if( category_init() != 0 )
		bail();

	if( game_sel_init() != 0 )
		bail();

	if( hint_init() != 0 )
		bail();

	if( snap_init() != 0 )
		bail();
	
	if( game_list_create() != 0 )
		bail();

	if( menu_init() != 0 )
		bail();

	if( submenu_init() != 0 )
		bail();

	sound_init();
	video_init();
	
	event_flush();

	if( !config_get()->iface.theme.menu.auto_hide )
		menu_show();
		
	focus_set( FOCUS_GAMESEL );

	while( !quit ) {
		ogl_clear();
		bg_draw();
		snap_draw();
		if (!config_get()->iface.hide_buttons)
			hint_draw();
		menu_draw();
		submenu_draw();
		game_sel_draw();
		sdl_swap();
		if (Mix_PlayingMusic() != 1 && config_get()->iface.theme_sound && reader_running == 0) 
			playmusic();
		if (( event = event_poll() )) {
			if( supress_wait == 0 ) {
				if( event == EVENT_QUIT ) {
					quit = 1;
				}
				else {
					supress();
					event_process( event );
				}
			}
		}
		if( supress_wait > 0 )
			supress_wait--;
		
		sdl_frame_delay();
	}
	clean_up();
	return 0;
}
示例#4
0
INTERNAL void
setprobe(char *spec) {
	char server[100];
	char instname[100];
	char *s, *t;
	int  param;
	int  id, nc;
	int  clientid = 0;
	ECLIENT_LIST  clients[MAX_CLIENT];
	EVENT_EFI_CTL eprobe;

	s = spec;

	if (substr(PREFIX, s)) s += strlen(PREFIX);
	if (substr("//", s))   s += 2;

	t = server;
	while (*s && *s != '/') *t++ = *s++;
	*t = '\0';

	if (*s++ != '/') probe_error(spec);
	if (*s == '/') ++s;

	t = instname;
	while (*s != '.') *t++ = *s++;
	*t = '\0';

	if (*s++ != '.') probe_error(spec);

	if (isdigit(instname[0])) clientid = atoi(instname);

	param = atoi(s);
	if (!param) probe_error(spec);

	printf("setprobe: setting probe daffie://%s/%s.%d\n",
		server, instname, param);

	efi_init();
	event_select_type(0, ET_MIN, ET_MAX);

	id = event_join(server, &nc);
	if (!id) {
		fprintf(stderr, "%s: couldn't join server \"%s\"\n", Pgm, server);
		exit(4);
	}
	printf("%s: joined %s as client id %d (%d clients)\n", Pgm, server, id, nc);

	event_register("earlab", "control", Pgm);

	event_callback(ET_EFI_WAVEDATA,  receive_wavedata);
	event_callback(ET_EFI_SPIKEDATA, receive_spikedata);
	event_select_type(1, ET_EFI_WAVEDATA,  ET_EFI_WAVEDATA);
	event_select_type(1, ET_EFI_SPIKEDATA, ET_EFI_SPIKEDATA);
	event_receive_enable(0);
	event_flush(0);

	eclient_monitor();
	if (!clientid)
	   nc = eclient_match(clients, "*", "earlab", "*", instname);
	else
	   nc = eclient_match_id(clients, clientid);

	if (nc < 1) {
		fprintf(stderr, "%s: couldn't find match for %s\n",
			Pgm, instname);
		event_leave();
		exit(1);
	}
	if (nc > 1) {
		fprintf(stderr, "%s: %s matched multiple (%d) clients\n",
			Pgm, instname, nc);
		event_leave();
		exit(1);
	}

	eprobe.type     = EFI_CTL_PROBE;
	eprobe.clientid = id;
	eprobe.tag      = getpid();
	eprobe.param    = param - 1;
	eprobe.flag     = 1;
	eprobe.value    = 0;

	SEND(clients[0].id, EFI_CTL, eprobe);

}
示例#5
0
INTERNAL int
start_logger(AGENT_REQ *areq, char *logserver, char *cmd, char *args, int *retpid) {
	int   argc;
	int   logpid;
	int   rc, id, nc;

	if (Debug)
	   printf("starting logger as proc %d.%d for server %s\n",
		   getpid(), mp_gettid(), logserver);

	logpid = fork();
	if (logpid < 0) {
		fprintf(stderr, "start_logger: fork failed\n");
		perror("start_logger");
		return(0);
	}

	/* Parent process, send a response to requester and return */
	if (logpid > 0) {
		EVENT_AGENTD_STAT estat;
		if (areq) {
			areq->status = AGENTD_AGENT_RUNNING;
			areq->pid    = logpid;

			estat.reqseq  = EventSeq(areq->ereq);
			estat.tag     = areq->ereq.tag;
			estat.reqtype = AGENTD_CTL_START;
			estat.result  = logpid;
			estat.rstatus = AGENTD_STATUS_OK;
			SEND(EventFrom(areq->ereq), AGENTD_STAT, estat);
		}

		*retpid = logpid;

		return(AGENTD_STATUS_OK);
	}

	/*
	 * We are now in the logger child proc
	 *  - leave agent event server
	 *  - join logger server
	 *  - start agent task
	 */
	event_exit_();
	mp_fini();

	mp_init();

	fprintf(stderr, "logger: running as proc %d.%d\n", getpid(), mp_gettid());
	Exitlock = mp_alloclock();
	Exitwait = mp_allocsema();

	event_tunnel_enable(0);
	event_init();
	event_threadsafe(EVENT_SAFE_ALL);

	id = event_join(logserver, &nc);
	if (!id) {
		fprintf(stderr, "start_logger: couldn't join %s\n", logserver);
		exit(8);
	}

	/*
	 * N.B. For the moment disable the reading of all events
	 *  if we need to process incoming events, for some reason, we
	 *  should launch a separate thread, similar to the stdout/err
	 * "reader" threads that get started in "start_agent".
	 * Note that start_agent does not return until the subproccess,
	 * i.e. the agent, terminates
	 */
	event_select_type(0, ET_MIN, ET_MAX);
     /*** No, not even these
	event_select_type(1, ET_AGENTD_MIN, ET_AGENTD_MAX);
     ***/
	event_receive_enable(0);
	event_flush(1);

	fprintf(stderr, "logger: %d.%d joined %s as client %d\n",
		getpid(), mp_gettid(), logserver, id);

	event_register(LOGGERCLASS, LOGGERSPEC, cmd);

	rc = start_agent(NULL, cmd, args, retpid);

	fprintf(stderr, "logger: %d.%d done and exiting with %d\n",
		getpid(), mp_gettid(), rc);

	event_leave();

	exit(rc);
}
示例#6
0
/*
 * Logger helper app  [only for non-unix systems]
 */
INTERNAL void
logger(char *pgm, int argc, char **argv) {
	char *logserver;
	char *cmd;
	char  args[AGENTD_PATHLEN];
	int   id, nc;
	int   pid;
	int   ok, help;
	int   i;
	int   rc;

	ok      = 1;
	help    = 0;
	Verbose = 0;
	while (argc && *argv[0] == '-') {
		char *opt;

		opt = argv[0] + 1;
		++argv; --argc;

		if      (substr(opt, "help"))    ++help;
		else if (substr(opt, "debug"))   ++Debug;
		else if (substr(opt, "nodebug")) Debug   = 0;
		else if (substr(opt, "verbose")) Verbose = 1;
		else if (substr(opt, "quiet"))   Verbose = 0;
		else if (substr(opt, "wd")) {
			if (argc < 1) {
				fprintf(stderr, "%s: missing argument to -%s\n",
					pgm, opt);
				ok = 0;
				break;
			}
			WorkDir = argv[0];
			++argv; --argc;
		}
		else if (substr(opt, "bin")) {
			if (argc < 1) {
				fprintf(stderr, "%s: missing argument to -%s\n",
					pgm, opt);
				ok = 0;
				break;
			}
			strcpy(ExecPath, argv[0]);
			++argv; --argc;
		}
		else {
			fprintf(stderr, "%s: ignoring argument -%s\n", pgm, opt);
			help = 1;
			ok   = 0;
		}
	}
	if (!ok || argc == 0) {
		logger_usage(pgm, help);
		exit(!help);
	}

	if (argc < 2) {
		fprintf(stderr, "usage: %s logserver cmd [args]\n", pgm);
		exit(4);
	}

	logserver = argv[0];
	++argv; --argc;

	cmd = argv[0];
	++argv; --argc;

	args[0] = '\0';
	while (argc) {
		strcat(args, " ");
		strcat(args, argv[0]);
		++argv; --argc;
	}

	/* Initialize agent control structures */
	for (i = 0; i < MAX_AGENT; ++i) {
		Agent[i].pid    = 0;
		Agent[i].status = AGENTD_AGENT_FREE;
	}

	event_verbose(Verbose);
	event_tunnel_enable(0);

	agentd_init();

	siginit(); /* deal with signals */

	id = event_join(logserver, &nc);
	if (id <= 0) {
		fprintf(stderr, "%s: couldn't join server %s\n", pgm, logserver);
		exit(4);
	}

	/*
	 * N.B. For the moment disable the reading of all events
	 *  if we need to process incoming events, for some reason, we
	 *  should launch a separate thread, similar to the stdout/err
	 * "reader" threads that get started in "start_agent".
	 * Note that start_agent does not return until the subproccess,
	 * i.e. the agent, terminates
	 */
	event_select_type(0, ET_MIN, ET_MAX);
     /*** No, not even these
	event_select_type(1, ET_AGENTD_MIN, ET_AGENTD_MAX);
     ***/
	event_receive_enable(0);
	event_flush(1);

	event_register(LOGGERCLASS, LOGGERSPEC, cmd);

	rc = start_agent(NULL, cmd, args, &pid);

	event_leave();

	exit(rc);
}