コード例 #1
0
ファイル: keys.c プロジェクト: gitkaste/cmus
void normal_mode_ch(uchar ch)
{
	enum key_context c;
	const struct key *k;

	c = view_to_context[cur_view];
	k = ch_to_key(ch);

	if (k == NULL) {
		return;
	}

	/* view-specific ch */
	if (handle_key(key_bindings[c], k))
		return;

	/* common ch */
	if (handle_key(key_bindings[CTX_COMMON], k))
		return;

	/* these can be overridden but have default magic */
	switch (ch) {
	case ':':
		enter_command_mode();
		return;
	case '/':
		enter_search_mode();
		return;
	case '?':
		enter_search_backward_mode();
		return;
	}
}
コード例 #2
0
ファイル: mimerun.c プロジェクト: LRN/mimerun
/* calls handle_key() for HKCR and, if that yields no matches, for HKLM */
int handle (wchar_t *logfile, MimeResults *mres, LPSHELLEXECUTEINFOW einfo, wchar_t *lpfile, wchar_t *lpdir)
{
  logtofilew (logfile, L">handle\n");
  int ret = 0;
  if ((ret = handle_key (logfile, HKEY_CURRENT_USER, mres, einfo, lpfile, lpdir)) < 0)
    ret = handle_key (logfile, HKEY_LOCAL_MACHINE, mres, einfo, lpfile, lpdir);
  logtofilew (logfile, L"<handle %d\n", ret);
  return ret;
}
コード例 #3
0
ファイル: com_gtk.c プロジェクト: atoun/xoscope
gint
key_press_event(GtkWidget *widget, GdkEventKey *event)
{
  if (event->keyval == GDK_Tab) {
    handle_key('\t');
  } else if (event->length == 1) {
    handle_key(event->string[0]);
  }

  return TRUE;
}
コード例 #4
0
ファイル: egl_utils.c プロジェクト: AdamSimpson/TinyLauncher
void process_controller_events(gl_t *state, int controller_fd)
{
    struct input_event events[10];
    int bytes, i, length;

    // Read in events
    bytes = read(controller_fd, events, sizeof(events));
    if(bytes > 0)
    {
        length =  bytes/sizeof(struct input_event);

        // Process events based on type
        for(i=0; i<length; i++)
        {
            switch(events[i].type)
            {
                case EV_KEY:
                    handle_key(state, &events[i]);
                    break;
                case EV_ABS:
                    handle_joystick(state, &events[i]);
                    break;
                case EV_REL:
                    handle_mouse(state, &events[i]);
                    break;
            }
        }
    }
}
コード例 #5
0
void
intercept (XPointer user_data, XRecordInterceptData* data)
{
    XCape_t *self = (XCape_t*)user_data;

    if (data->category == XRecordFromServer)
    {
        int     key_event = data->data[0];
        KeyCode key_code  = data->data[1];
        g_debug ("Intercepted key event %d, key code %d\n",
                key_event, key_code);
        if ( key_code == 133 ) {
            super_press = True;
        }
        self->key = key_code;

        if (key_event == ButtonPress) {
            if ( super_press ) {
                key_press_cnt++;
            }
            /*g_debug ("***Button Pressed!\n");*/
        } else if (key_event == ButtonRelease) {
            if ( super_press ) {
                key_press_cnt++;
            }
            /*g_debug ("***Mouse Pressed!\n");*/
        } else {
            /*g_debug ("***Other Pressed!\n");*/
            handle_key (self, key_event);
        }
    }
}
コード例 #6
0
ファイル: keys.c プロジェクト: gitkaste/cmus
void normal_mode_key(int key)
{
	enum key_context c = view_to_context[cur_view];
	const struct key *k = keycode_to_key(key);

	if (k == NULL) {
		return;
	}

	/* view-specific key */
	if (handle_key(key_bindings[c], k))
		return;

	/* common key */
	handle_key(key_bindings[CTX_COMMON], k);
}
コード例 #7
0
ファイル: c_all.c プロジェクト: daemqn/Atari_ST_Sources
void check(void)
{
  int exit=FALSE;
  RESULT svar;
  char temp[MAXSTRING];
  do
  {
    svar=form_dialog();
    switch(svar.type)
    {
      case MENU_CLICKED:
        exit=!handle_menu(svar);
        break;
      case DIALOG_CLICKED:
      case WINDOW_CLICKED:
        exit=!handle_window(svar);
        break;
      case KEY_CLICKED:
        exit=!handle_key(svar);
        break;
      case BUTTON_CLICKED:
        exit=!handle_button(svar);
        break;
      case TIMER_EXIT:
        exit=TRUE;
        break;
      default:
        sprintf(temp,"[1][ Meddelande #%d][ OK ]",svar.type);
        alertbox(1,temp);
    }
  }while(!exit);
}
コード例 #8
0
ファイル: xcommon.c プロジェクト: abrauchli/allnet
/* handle an incoming packet, acking it if it is a data packet for us
 * returns the message length > 0 if this was a valid data message from a peer.
 * if it gets a valid key, returns -1 (details below)
 * Otherwise returns 0 and does not fill in any of the following results.
 *
 * if it is a data or ack, it is saved in the xchat log
 * if it is a valid data message from a peer or a broadcaster,
 * fills in verified and broadcast
 * fills in contact, message (to point to malloc'd buffers, must be freed)
 * if not broadcast, fills in desc (also malloc'd), sent (if not null)
 * and duplicate.
 * if verified and not broadcast, fills in kset.
 * the data message (if any) is null-terminated
 *
 * if kcontact and ksecret1 are not NULL, assumes we are also looking
 * for key exchange messages sent to us matching either of ksecret1 or
 * (if not NULL) ksecret2.  If such a key is found, returns -1.
 * there are two ways of calling this:
 * - if the user specified the peer's secret, first send initial key,
 *   then call handle_packet with our secret in ksecret1 and our
 *   peer's secret in ksecret2.
 * - otherwise, put our secret in ksecret1, make ksecret2 and kaddr NULL,
 *   and handle_packet is ready to receive a key.
 * In either case, if a matching key is received, it is saved and a
 * response is sent (if a response is a duplicate, it does no harm).
 * kmax_hops specifies the maximum hop count of incoming acceptable keys,
 * and the hop count used in sending the key.
 *
 * if subscription is not null, listens for a reply containing a key
 * matching the subscription, returning -2 if a match is found.
 */
int handle_packet (int sock, char * packet, int psize,
                   char ** contact, keyset * kset,
                   char ** message, char ** desc,
                   int * verified, time_t * sent,
                   int * duplicate, int * broadcast,
                   char * kcontact, char * ksecret1, char * ksecret2,
                   int kmax_hops,
                   char * subscription, 
                   unsigned char * addr, int nbits)
{
  if (! is_valid_message (packet, psize))
    return 0;

  struct allnet_header * hp = (struct allnet_header *) packet;
  int hsize = ALLNET_SIZE (hp->transport);
  if (psize < hsize)
    return 0;

#ifdef DEBUG_PRINT
  if (hp->hops > 0)  /* not my own packet */
    print_packet (packet, psize, "xcommon received", 1);
#endif /* DEBUG_PRINT */

  if (hp->message_type == ALLNET_TYPE_ACK) {
    handle_ack (sock, packet, psize, hsize);
    return 0;
  }

  if (hp->message_type == ALLNET_TYPE_CLEAR) { /* a broadcast packet */
    if ((subscription != NULL) && (addr != NULL)) {
      int sub = handle_sub (sock, hp, packet + hsize, psize - hsize,
                            subscription, addr, nbits);
#ifdef DEBUG_PRINT
      printf ("handle_sub (%d, %p, %p, %d, %s, %p, %d) ==> %d\n",
              sock, hp, packet + hsize, psize - hsize, subscription,
              addr, nbits, sub);
#endif /* DEBUG_PRINT */
      if (sub > 0)   /* received a key in response to our subscription */
        return sub;
    }
#ifdef DEBUG_PRINT
    else
      printf ("subscription %p, addr %p, did not call handle_sub\n",
              subscription, addr);
#endif /* DEBUG_PRINT */
    return handle_clear (hp, packet + hsize, psize - hsize,
                         contact, message, verified, broadcast);
  }

  if (hp->message_type == ALLNET_TYPE_DATA) /* an encrypted data packet */
    return handle_data (sock, hp, packet + hsize, psize - hsize,
                        contact, kset, message, desc, verified, sent,
                        duplicate, broadcast);

  if (hp->message_type == ALLNET_TYPE_KEY_XCHG)
    return handle_key (sock, hp, packet + hsize, psize - hsize,
                       kcontact, ksecret1, ksecret2, kmax_hops);

  return 0;
}
コード例 #9
0
ファイル: read_vt220.c プロジェクト: larsbrinkhoff/kbredir
int
main (int argc, char **argv)
{
  if (argc != 1)
    {
      fprintf (stderr, "%s takes no options\n", argv[0]);
      exit (1);
    }

  if (isatty (0))
    {
      struct termios t;

      if (tcgetattr (0, &t) == -1)
	abort ();
      saved_termios = t;
      t.c_lflag = 0;
      t.c_iflag = 0;
      if (tcsetattr (0, TCSANOW, &t) == -1)
	abort ();
      fprintf (stderr, "Type q (TODO: replace with a sane key (sequence)) "
	       "to quit.\n");
    }

  init_code_to_string ();

  while (handle_key ())
    ;

  tcsetattr (0, TCSANOW, &saved_termios);
  return 0;
}
コード例 #10
0
ファイル: main.c プロジェクト: topnotcher/teabot
int main(void) {
	//allow everything to settle/boot/etc
	//(mainly the mp3 chip takes a while to boot up)
	_delay_ms(2000);

	servo_init();
	keypad_init();
	display_init();
	thermistor_init();
	ssr_init();
	init_timers();
	mp3_init();

	tea_off();

	PMIC.CTRL |= PMIC_MEDLVLEN_bm | PMIC_LOLVLEN_bm | PMIC_HILVLEN_bm;
	sei();

	//another 100 for things to settle
	_delay_ms(100);

	//welcome
	mp3_play(10);

	while (1) {
		char key;
		if ((key = keypad_getc()))
			handle_key(key);
	}
}
コード例 #11
0
ファイル: knumcap.c プロジェクト: viktornar/knumcap
void intercept(XPointer user_data, XRecordInterceptData *data) {
	XCape_t *self = (XCape_t*) user_data;
	static Bool mouse_pressed = False;
	KeyMap_t *km;

	if (data->category == XRecordFromServer) {
		int key_event = data->data[0];
		KeyCode key_code = data->data[1];

		if (self->debug)
			fprintf(stdout, "Intercepted key event %d, key code %d\n",
					key_event, key_code);

		for (km = self->map; km != NULL; km = km->next) {
			if ((km->UseKeyCode == False
					&& XkbKeycodeToKeysym(self->ctrl_conn, key_code, 0, 0)
							== km->ks)
					|| (km->UseKeyCode == True && key_code == km->kc)) {
				handle_key(self, km, mouse_pressed, key_event);
			} else if (km->pressed && key_event == KeyPress) {
				km->used = True;
			}
		}

	}
}
コード例 #12
0
ファイル: vmachine.c プロジェクト: RangelReale/o2em-pnd
void handle_vbl(void){
	if (!app_data.debug) {
		handle_key();
		update_audio();
		update_voice();
	}
	draw_region();
	ext_IRQ();
	mstate = 1;
}
コード例 #13
0
ファイル: gui-readline.c プロジェクト: svn2github/irssi
void readline(void)
{
	int key;

	for (;;) {
		key = getch();
		if (key == ERR) break;

		handle_key(key);
	}
}
コード例 #14
0
            void baxter_sim_application_t::frame(const ros::TimerEvent& event)
            {
                handle_key();

                if( simulator_mode == 1 )
                {
                    if( simulator_counter > 0 )
                    {
                        simulator_running = true;
                        simulator_counter--;
                        loop_timer.reset();
                    }
                    else
                        simulator_running = false;
                }
                if( loop_timer.measure() > 1.0 )
                    loop_timer.reset();
                if( simulator_running )
                {

                    if( replays_states )
                    {
                        if( loop_counter > (int)replay_simulation_states.size() )
                            loop_counter = 0;
                        simulation_state_space->copy_from_point(replay_simulation_states[loop_counter]);
                        simulation_state_space->copy_to_point(simulation_state);
                    }
                    else
                    {
                        simulator->push_control(simulation_control);
                        simulator->propagate_and_respond();
                    }
                    if( stores_states )
                        store_simulation_states.copy_onto_back(simulation_state);

                    if( screenshot_every_simstep )
                    {
                        ((visualization_comm_t*)vis_comm)->take_screenshot(0, 1);
                    }
                    loop_total += loop_timer.measure_reset();
                    loop_counter++;
                    loop_avg = loop_total / loop_counter;

                }

                if(visualization_counter++%visualization_multiple == 0)
                {
                    tf_broadcasting();
                }



            }
コード例 #15
0
ファイル: sim.c プロジェクト: David-Durst/ICFP-Evolution
enum events v_poll_event (int timeout)
{
    SDL_Event event;

    while(SDL_PollEvent(&event)) {
	switch( event.type ) {
	    case SDL_QUIT:
		printf("Got quit event!\n");
		return EVENT_QUIT;
		break;
	    case SDL_KEYDOWN:
	    	return handle_key(event.key.keysym.sym);
		break;
	    case SDL_MOUSEMOTION:
	    	break;
		mouse_to_hex(event.motion.x, event.motion.y, 
		    &mousex , &mousey);
		break;
    	    case SDL_MOUSEBUTTONDOWN:
	    	switch (event.button.button) {
		    case 1:
		    	v_zoom_in(event.button.x, event.button.y);
			break;
			
		    case 2:
		    	v_center_view(event.button.x, event.button.y);
			break;
			
		    case 3:
		    	v_zoom_out(event.button.x, event.button.y);
			break;
		}
		return EVENT_REDISPLAY;
	    	break;
    	    case SDL_MOUSEBUTTONUP:
	    	break;

	    case SDL_ACTIVEEVENT:
		return EVENT_REDISPLAY;
		break;
	    case SDL_VIDEORESIZE:
	    	width = event.resize.w;
	    	height = event.resize.h;
		sdl_resize();
		return EVENT_REDISPLAY;
		break;
	}
    }
	
    return EVENT_NONE;
}
コード例 #16
0
ファイル: kbd.c プロジェクト: BackupTheBerlios/nupkux-svn
void irq_tty_keyboard(registers *regs)
{
	UCHAR scan_code = inportb(KEYBD_PORT);
	USHORT input;
	tty *atty=(tty *)device_pdata(current_tty);
	handle_key(&scan_code,&input,scan_code&KEYUP);
	if (escape) return;
	if (!(scan_code&KEYUP)) {
		atty->input_buffer[atty->in_e++]=input;
		if (atty->in_e==TTY_INBUF_LEN) atty->in_e=0;
		if (atty->in_e==atty->in_s)  //Buffer overflow
			if (++atty->in_s==TTY_INBUF_LEN) atty->in_s=0;
	}
}
コード例 #17
0
ファイル: command_edit.c プロジェクト: mdugot/42sh
int		special_input(int read_ret, t_shprop *shell)
{
	if (read_ret == 0)
		return (1);
	else if (read_ret == -1)
		return (0);
	else if (read_ret != 1)
	{
		read_ret = handle_key(shell, read_ret);
		if (read_ret == 0)
			return (1);
		else if (read_ret == -1)
			return (0);
	}
	return (-1);
}
コード例 #18
0
ファイル: usb-hid.c プロジェクト: KevinOConnor/seabios
// Check if a USB keyboard event is pending and process it if so.
static void
usb_check_key(void)
{
    if (! CONFIG_USB_KEYBOARD)
        return;
    struct usb_pipe *pipe = GET_GLOBAL(keyboard_pipe);
    if (!pipe)
        return;

    for (;;) {
        struct keyevent data;
        int ret = usb_poll_intr(pipe, &data);
        if (ret)
            break;
        handle_key(&data);
    }
}
コード例 #19
0
ファイル: c_all.c プロジェクト: daemqn/Atari_ST_Sources
void check(void)
{
  int exit=FALSE;
  RESULT svar;
  do
  {
    svar=form_dialog();
    switch(svar.type)
    {
      case MENU_CLICKED:
        exit=!handle_menu(svar);
        break;
      case DIALOG_CLICKED:
      case WINDOW_CLICKED:
        exit=!handle_window(svar);
        break;
      case KEY_CLICKED:
        exit=!handle_key(svar);
        break;
      case BUTTON_CLICKED:
        exit=!handle_button(svar);
        break;
      case TIMER_EXIT:
        check_port();
        break;
      default:
        switch(svar.data[0])
        {
          char temp[MAXSTRING];
          case 0x400:                        /* ACC_ID           */
          case 0x4700:                       /* AV_PROTOKOLL     */
          case 0x4724:                       /* VA_ACCWINDOPEN   */
          case 0x4726:                       /* AV_ACCWINDCLOSED */
            break;
          default:
            sprintf(temp,"[1][ Message %#lx|From %d|%d,%d,%d,%d,%d][ NEXT ]",svar.data[0],svar.data[1],
              (unsigned short)svar.data[3],(unsigned short)svar.data[4],(unsigned short)svar.data[5],(unsigned short)svar.data[6],(unsigned short)svar.data[7]);
            alertbox(1,temp);
            break;
        }
    }
  }while(!exit);
}
コード例 #20
0
ファイル: keyboard.c プロジェクト: ksrm/redox
// Turn the column state for the given hand and row into a series of calls to
// handle_key() to process the keys that have changed state.
void handle_row(uint8_t hand, uint8_t row, uint8_t cols) {

    // Row offset into the keystate array
    uint8_t offs = (hand == 0 ? 0 : 5);

    uint8_t change = keystate[row+offs] ^ cols;
    uint8_t i;

    // Check for changed keys on the given row
    for (i=0; i<8; i++) {
        if (change & (1<<i)) {
            handle_key(row+offs, i, cols & (1<<i));
        }
    }

    // Update the row with the current state
    keystate[row+offs] = cols;

}
コード例 #21
0
int			main(int ac, char **av)
{
  t_board		board;

  if (ac < 2 || ac > 3)
    {
      printf("./epikong_etape_1 file.map\n");
      exit(EXIT_FAILURE);
    }
  if (SDL_Init(SDL_INIT_VIDEO) == -1)
    {
      write(2, "SDL_INIT Error\n", 15);
      exit(EXIT_FAILURE);
    }
  get_map(&board, av[1]);
  aff_board(&board);
  handle_key();
  SDL_Quit();
  return (1);
}
コード例 #22
0
ファイル: unix_input.c プロジェクト: Turupawn/DogeWarsow
static void handle_cookie(XGenericEventCookie *cookie)
{
	switch(cookie->evtype) {
	case XI_RawMotion:
		handle_raw_motion(cookie->data);
		break;
	case XI_Enter:
	case XI_Leave:
		break;
	case XI_ButtonPress:
	case XI_ButtonRelease:
		handle_button(cookie);
		break;
	case XI_KeyPress:
	case XI_KeyRelease:
		handle_key(cookie);
		break;
	default:
		break;
	}
}
コード例 #23
0
ファイル: raw-keyboard.c プロジェクト: dranger003/drm-tests
int main(int argc, char *argv[])
{
	struct input_event ev;
	struct xkb_desc *xkb;
	uint32_t modifiers;
	ssize_t bytes;
	int i;

	xkb = create_xkb();
	if (!xkb) {
		fprintf(stderr, "Failed to compile keymap\n");
		return 1;
	}

	while (1) {
		bytes = read(0, &ev, sizeof(ev));
		if (bytes != sizeof(ev))
			break;
		if (EV_KEY == ev.type)
			handle_key(xkb, &ev, &modifiers);
	}

	return 0;
}
コード例 #24
0
ファイル: ui.c プロジェクト: zbanks/radiance
void ui_run() {
        SDL_Event e;

        quit = false;
        while(!quit) {
            ui_render(true);

            while(SDL_PollEvent(&e) != 0) {
                if (midi_command_event != (Uint32) -1 && 
                    e.type == midi_command_event) {
                    struct midi_event * me = e.user.data1;
                    switch (me->type) {
                    case MIDI_EVENT_SLIDER:
                        set_slider_to(me->slider.index, me->slider.value, me->snap);
                        break;
                    case MIDI_EVENT_KEY:;
                        SDL_KeyboardEvent fakekeyev;
                        memset(&fakekeyev, 0, sizeof fakekeyev);
                        fakekeyev.type = SDL_KEYDOWN;
                        fakekeyev.state = SDL_PRESSED;
                        fakekeyev.keysym.sym = me->key.keycode[0];
                        handle_key(&fakekeyev);
                        break;
                    }
                    free(e.user.data1);
                    free(e.user.data2);
                    continue;
                }
                switch(e.type) {
                    case SDL_QUIT:
                        quit = true;
                        break;
                    case SDL_KEYDOWN:
                        handle_key(&e.key);
                        break;
                    case SDL_MOUSEMOTION:
                        mx = e.motion.x;
                        my = e.motion.y;
                        handle_mouse_move();
                        break;
                    case SDL_MOUSEBUTTONDOWN:
                        mx = e.button.x;
                        my = e.button.y;
                        switch(e.button.button) {
                            case SDL_BUTTON_LEFT:
                                handle_mouse_down();
                                break;
                        }
                        break;
                    case SDL_MOUSEBUTTONUP:
                        mx = e.button.x;
                        my = e.button.y;
                        switch(e.button.button) {
                            case SDL_BUTTON_LEFT:
                                handle_mouse_up();
                                break;
                        }
                        break;
                    case SDL_TEXTINPUT:
                        handle_text(e.text.text);
                        break;
                }
            }

            for(int i=0; i<N_DECKS; i++) {
                deck_render(&deck[i]);
            }
            crossfader_render(&crossfader, deck[left_deck_selector].tex_output, deck[right_deck_selector].tex_output);
            ui_render(false);

            render_readback(&render);

            SDL_GL_SwapWindow(window);

            double cur_t = SDL_GetTicks();
            double dt = cur_t - l_t;
            if(dt > 0) time += dt / 1000;
            l_t = cur_t;
        }
}
コード例 #25
0
ファイル: event.c プロジェクト: billpage/open-axiom
static void
handle_event(XEvent * event)
{
    XWindowAttributes wa;
/*    fprintf(stderr,"event:handle_event entered\n");*/
    set_window(event->xany.window);
    if (event->type == MotionNotify) {
/*        fprintf(stderr,"event:handle_event type=MotionNotify\n");*/
        handle_motion_event((XMotionEvent *)event);
        motion = 1;
        return;
    }
    make_busy_cursors();
    switch (event->type) {
      case DestroyNotify:
/*        fprintf(stderr,"event:handle_event type=DestroyNotify\n");*/
        break;
      case Expose:
/*        fprintf(stderr,"event:handle_event type=Expose\n");*/
        XGetWindowAttributes(gXDisplay, gWindow->fMainWindow, &wa);
        if ((gWindow->width == 0 && gWindow->height == 0) ||
            (wa.width != gWindow->width || wa.height != gWindow->height)) {
            gWindow->width = wa.width;
            gWindow->height = wa.height;
            display_page(gWindow->page);
            gWindow->fWindowHashTable = gWindow->page->fLinkHashTable;
        }
        else                    /** just redraw the thing **/
            expose_page(gWindow->page);
        XFlush(gXDisplay);
        clear_exposures(gWindow->fMainWindow);
        clear_exposures(gWindow->fScrollWindow);
        break;
      case ButtonPress:
/*        fprintf(stderr,"event:handle_event type=ButtonPress\n");*/
        handle_button(event->xbutton.button, (XButtonEvent *)event);
        XFlush(gXDisplay);
        if (gWindow) {
            while (XCheckTypedWindowEvent(gXDisplay, gWindow->fMainWindow,
                                          Expose, event));
            while (XCheckTypedWindowEvent(gXDisplay, gWindow->fScrollWindow,
                                          Expose, event));
        }
        break;
      case KeyPress:
/*        fprintf(stderr,"event:handle_event type=KeyPress\n");*/
        handle_key(event);
        if (gWindow) {
            while (XCheckTypedWindowEvent(gXDisplay, gWindow->fMainWindow,
                                          Expose, event));
            while (XCheckTypedWindowEvent(gXDisplay, gWindow->fScrollWindow,
                                          Expose, event));
        }
        break;
      case MapNotify:
/*        fprintf(stderr,"event:handle_event type=MapNotify\n");*/
        create_window();
        break;

      case SelectionNotify:
/*        fprintf(stderr,"event:handle_event type=SelectionNotify\n");*/
        /* this is in response to a previous request in an input area */
        if ( gSavedInputAreaLink ) {
            XSelectionEvent *pSelEvent;
            Atom dataProperty;
            pSelEvent = (XSelectionEvent *) event;
            dataProperty = XInternAtom(gXDisplay, "PASTE_SELECTION", False);
            /* change the input focus */

        /*  change_input_focus(gSavedInputAreaLink); */

            /* try to get the selection as a window property */

            if ( pSelEvent->requestor == gWindow->fMainWindow &&
                 pSelEvent->selection == XA_PRIMARY &&
            /*   pSelEvent->time      == CurrentTime && */
                 pSelEvent->target    == XA_STRING &&
                 pSelEvent->property == dataProperty )
            {
                Atom actual_type;
                int  actual_format;
                unsigned long nitems, leftover;
                char *pSelection = NULL;

                if (Success == XGetWindowProperty(gXDisplay,
                    gWindow->fMainWindow,
                    pSelEvent->property, 0L, 100000000L, True,
                    AnyPropertyType, &actual_type, &actual_format,
                    &nitems, &leftover, (unsigned char **) &pSelection) )
                {
                    char *pBuffer;
                    InputItem *item = gSavedInputAreaLink->reference.string;

                    for (pBuffer = pSelection; *pBuffer; ++pBuffer)
                        add_buffer_to_sym(pBuffer, item);

                    XFree(pSelection);
                }
            }

            /* clear the link info */

            gSavedInputAreaLink = NULL;
        }
        break;

      default:
/*        fprintf(stderr,"event:handle_event type=default\n");*/
        break;
    }

}
コード例 #26
0
ファイル: main.cpp プロジェクト: bothemasterofall/bayou
int main()
{
    //shell vars
    bool render = false;

    //allegro vars
    ALLEGRO_DISPLAY *display = NULL;
    ALLEGRO_EVENT_QUEUE *event_queue = NULL;
    ALLEGRO_TIMER *timer = NULL;

    //allegro init functions
    printf ("Initializing allegro\n");
    if (!al_init())
    {
        al_show_native_message_box(NULL, NULL, NULL, "failed", NULL, 0);
        return -1;
    }

    printf("Creating display\n");
    display = al_create_display(WIDTH, HEIGHT);
    if (!display)
    {
        al_show_native_message_box(NULL, NULL, NULL, "failed", NULL, 0);
        return -1;
    }

    printf("Installing addons\n");
    al_init_font_addon();
    al_init_ttf_addon();
    al_init_primitives_addon();
    al_init_image_addon();
    al_install_keyboard();
    al_install_mouse();
    al_install_audio();
    al_init_acodec_addon();
    al_reserve_samples(10);

    //project inits
    srand(time(NULL));

    printf("Initializing timer\n");
    event_queue = al_create_event_queue();
    timer = al_create_timer(1.0 / FPS);

    printf("Registering event sources\n");
    al_register_event_source(event_queue, al_get_display_event_source(display));
    al_register_event_source(event_queue, al_get_keyboard_event_source());
    al_register_event_source(event_queue, al_get_timer_event_source(timer));
    al_start_timer(timer);

    printf("Init mouse and keyboard\n");
    init_keyboard();
    init_mouse();

    printf("Loading assets\n");
    load_bitmaps();
    load_fonts();
    load_samples();

    printf ("Creating manager\n");
    push_state(new TitleMenu());
    
    printf("Beginning game\n");
    while (!is_game_over())
    {
        //declare an event
        ALLEGRO_EVENT event;

        //monitor event sources
        al_wait_for_event(event_queue, &event);
        if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
        {
            end_game();
        }
        else if (event.type == ALLEGRO_EVENT_TIMER)
        {
            render = true;

            update_mouse();
            update_keyboard();

            handle_key();
            update_game();
        }

        // Render screen
        if (render && al_event_queue_is_empty(event_queue))
        {
            render = false;
            render_game();
            al_flip_display();
        }
    }

    unload_assets();
    al_destroy_event_queue(event_queue);
    al_destroy_display(display);
    al_destroy_timer(timer);

    return 0;
}
コード例 #27
0
ファイル: nenu.c プロジェクト: mytchel/nenu
int main(int argc, char *argv[]) {
	XEvent ev;
	int i, time, pending;
	
	for (i = 1; i < argc; i++) {
		if (strcmp(argv[i], "--pos") == 0) {
			x = atoi(strsep(&argv[++i], ","));
			y = atoi(argv[i]);
		} else if (strcmp(argv[i], "--abs") == 0) {
			absolute_position = 1;
		} else if (strcmp(argv[i], "--fg") == 0) {
			strcpy(fg_name, argv[++i]);
		} else if (strcmp(argv[i], "--bg") == 0) {
			strcpy(bg_name, argv[++i]);
		} else if (strcmp(argv[i], "--fn") == 0) {
			strcpy(font_str, argv[++i]);
		} else if (argv[i][0] == '-') {
			switch (argv[i][1])
			{
			case 'h':
				usage();
				exit(EXIT_SUCCESS);
			case 'o': exit_on_one = 1; break;
			case 'f': first_on_exit = 1; break;
			case 't': text_input = 0; break;
			case 'q': print_on_exit = 0; break;
			case 'n': read_options = 0; break;
			case 'g': grab = 0; break;
			default:
				fprintf(stderr, "Unknown option: %s\n",
					argv[i]);
				usage();
				exit(EXIT_FAILURE);
			}
		} else {
			strcpy(prompt, argv[i]);
		}
	}

	setup();

	if (read_options) read_input();

	XMapWindow(display, win);
	set_position();
	grab_keyboard_pointer();

	for(;;) {
		XNextEvent(display, &ev);
		switch (ev.type) {
		case KeyPress:
			handle_key(ev.xkey);
			render();
			break;
		case ButtonRelease:
			handle_button(ev.xbutton);
			render();
			break;
		case Expose:
			XRaiseWindow(display, win);
			render();
			break;
		}
	}

	clean_resources();
	exit(EXIT_FAILURE);
}
コード例 #28
0
ファイル: xentop.c プロジェクト: Ultra-Seven/gxen
int main(int argc, char **argv)
{
	int opt, optind = 0;
	int ch = ERR;

	struct option lopts[] = {
		{ "help",          no_argument,       NULL, 'h' },
		{ "version",       no_argument,       NULL, 'V' },
		{ "networks",      no_argument,       NULL, 'n' },
		{ "vbds",          no_argument,       NULL, 'x' },
		{ "repeat-header", no_argument,       NULL, 'r' },
		{ "vcpus",         no_argument,       NULL, 'v' },
		{ "delay",         required_argument, NULL, 'd' },
		{ "batch",	   no_argument,	      NULL, 'b' },
		{ "iterations",	   required_argument, NULL, 'i' },
		{ "full-name",     no_argument,       NULL, 'f' },
		{ 0, 0, 0, 0 },
	};
	const char *sopts = "hVnxrvd:bi:f";

	if (atexit(cleanup) != 0)
		fail("Failed to install cleanup handler.\n");

	while ((opt = getopt_long(argc, argv, sopts, lopts, &optind)) != -1) {
		switch (opt) {
		default:
			usage(argv[0]);
			exit(1);
		case '?':
		case 'h':
			usage(argv[0]);
			exit(0);
		case 'V':
			version();
			exit(0);
		case 'n':
			show_networks = 1;
			break;
		case 'x':
			show_vbds = 1;
			break;
		case 'r':
			repeat_header = 1;
			break;
		case 'v':
			show_vcpus = 1;
			break;
		case 'd':
			delay = atoi(optarg);
			break;
		case 'b':
			batch = 1;
			break;
		case 'i':
			iterations = atoi(optarg);
			loop = 0;
			break;
		case 'f':
			show_full_name = 1;
			break;
		case 't':
			show_tmem = 1;
			break;
		}
	}

	/* Get xenstat handle */
	xhandle = xenstat_init();
	if (xhandle == NULL)
		fail("Failed to initialize xenstat library\n");

	if (!batch) {
		/* Begin curses stuff */
		cwin = initscr();
		start_color();
		cbreak();
		noecho();
		nonl();
		keypad(stdscr, TRUE);
		halfdelay(5);
#ifndef __sun__
		use_default_colors();
#endif
		init_pair(1, -1, COLOR_YELLOW);

		do {
			gettimeofday(&curtime, NULL);
			if(ch != ERR || (curtime.tv_sec - oldtime.tv_sec) >= delay) {
				clear();
				top();
				oldtime = curtime;
				refresh();
				if ((!loop) && !(--iterations))
					break;
			}
			ch = getch();
		} while (handle_key(ch));
	} else {
		struct sigaction sa = {
			.sa_handler = signal_exit_handler,
			.sa_flags = 0
		};
		sigemptyset(&sa.sa_mask);
		sigaction(SIGINT, &sa, NULL);
		sigaction(SIGTERM, &sa, NULL);

		do {
			gettimeofday(&curtime, NULL);
			top();
			fflush(stdout);
			oldtime = curtime;
			if ((!loop) && !(--iterations))
				break;
			sleep(delay);
		} while (!signal_exit);
	}

	/* Cleanup occurs in cleanup(), so no work to do here. */

	return 0;
}
コード例 #29
0
ファイル: com_gtk.c プロジェクト: atoun/xoscope
/* simple event callback that emulates the user hitting the given key */
void
hit_key(GtkWidget *w, guint data)
{
  if (fixing_widgets) return;
  handle_key(data);
}
コード例 #30
0
ファイル: midi-core.c プロジェクト: CharlesLio/schismtracker
int midi_engine_handle_event(void *ev)
{
        struct key_event kk = {.is_synthetic = 0};
        int *st;
        SDL_Event *e = ev;

        if (e->type != SCHISM_EVENT_MIDI)
                return 0;

        st = e->user.data1;
        if (midi_flags & MIDI_DISABLE_RECORD) {
                free(e->user.data1);
                return 1;
        }

        switch (e->user.code) {
        case SCHISM_EVENT_MIDI_NOTE:
                if (st[0] == MIDI_NOTEON) {
                        kk.state = KEY_PRESS;
                } else {
                        if (!(midi_flags & MIDI_RECORD_NOTEOFF)) {
                                /* don't record noteoff? okay... */
                                break;
                        }
                        kk.state = KEY_RELEASE;
                }
                kk.midi_channel = st[1]+1;
                kk.midi_note = (st[2]+1 + midi_c5note) - 60;
                if (midi_flags & MIDI_RECORD_VELOCITY)
                        kk.midi_volume = st[3];
                else
                        kk.midi_volume = 128;
                kk.midi_volume = (kk.midi_volume * midi_amplification) / 100;
                handle_key(&kk);
                break;
        case SCHISM_EVENT_MIDI_PITCHBEND:
                /* wheel */
                kk.midi_channel = st[1]+1;
                kk.midi_volume = -1;
                kk.midi_note = -1;
                kk.midi_bend = st[0];
                handle_key(&kk);
                break;
        case SCHISM_EVENT_MIDI_CONTROLLER:
                /* controller events */
                break;
        case SCHISM_EVENT_MIDI_SYSTEM:
                switch (st[0]) {
                case 0x8: /* MIDI tick */
                        break;
                case 0xA: /* MIDI start */
                case 0xB: /* MIDI continue */
                        song_start();
                        break;
                case 0xC: /* MIDI stop */
                case 0xF: /* MIDI reset */
                        /* this is helpful when miditracking */
                        song_stop();
                        break;
                };
        case SCHISM_EVENT_MIDI_SYSEX:
                /* but missing the F0 and the stop byte (F7) */
                //len = *((unsigned int *)e->user.data1);
                //sysex = ((char *)e->user.data1)+sizeof(unsigned int);
                break;

        default:
                break;
        }
        free(e->user.data1);

        return 1;
}