示例#1
0
static void
event_loop(Display *dpy, GLXWindow win)
{
   while (1) {
      while (XPending(dpy) > 0) {
         XEvent event;
         XNextEvent(dpy, &event);
         switch (event.type) {
	 case Expose:
            /* we'll redraw below */
	    break;
	 case ConfigureNotify:
	    reshape(event.xconfigure.width, event.xconfigure.height);
	    break;
         case KeyPress:
            {
               char buffer[10];
               int code;
               code = XLookupKeysym(&event.xkey, 0);
               if (code == XK_Left) {
                  view_roty += 5.0;
               }
               else if (code == XK_Right) {
                  view_roty -= 5.0;
               }
               else if (code == XK_Up) {
                  view_rotx += 5.0;
               }
               else if (code == XK_Down) {
                  view_rotx -= 5.0;
               }
               else {
                  XLookupString(&event.xkey, buffer, sizeof(buffer),
                                NULL, NULL);
                  if (buffer[0] == 27) {
                     /* escape */
                     return;
                  }
               }
            }
         }
      }

      /* next frame */
      angle += 2.0;

      draw();
      glXSwapBuffers(dpy, win);

      /* calc framerate */
      {
         static int t0 = -1;
         static int frames = 0;
         int t = current_time();

         if (t0 < 0)
            t0 = t;

         frames++;

         if (t - t0 >= 5.0) {
            GLfloat seconds = t - t0;
            GLfloat fps = frames / seconds;
            printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds,
                   fps);
            fflush(stdout);
            t0 = t;
            frames = 0;
         }
      }
   }
}
static void
X11_DispatchEvent(_THIS)
{
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
    SDL_WindowData *data;
    XEvent xevent;
    int i;

    SDL_zero(xevent);           /* valgrind fix. --ryan. */
    XNextEvent(videodata->display, &xevent);

    /* filter events catchs XIM events and sends them to the correct
       handler */
    if (XFilterEvent(&xevent, None) == True) {
#if 0
        printf("Filtered event type = %d display = %d window = %d\n",
               xevent.type, xevent.xany.display, xevent.xany.window);
#endif
        return;
    }

    /* Send a SDL_SYSWMEVENT if the application wants them */
    if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
        SDL_SysWMmsg wmmsg;

        SDL_VERSION(&wmmsg.version);
        wmmsg.subsystem = SDL_SYSWM_X11;
        wmmsg.event.xevent = xevent;
        SDL_SendSysWMEvent(&wmmsg);
    }

    data = NULL;
    if (videodata && videodata->windowlist) {
        for (i = 0; i < videodata->numwindows; ++i) {
            if ((videodata->windowlist[i] != NULL) &&
                (videodata->windowlist[i]->xwindow == xevent.xany.window)) {
                data = videodata->windowlist[i];
                break;
            }
        }
    }
    if (!data) {
        return;
    }
#if 0
    printf("type = %d display = %d window = %d\n",
           xevent.type, xevent.xany.display, xevent.xany.window);
#endif
    switch (xevent.type) {

        /* Gaining mouse coverage? */
    case EnterNotify:{
#ifdef DEBUG_XEVENTS
            printf("EnterNotify! (%d,%d,%d)\n", 
	           xevent.xcrossing.x,
 	           xevent.xcrossing.y,
                   xevent.xcrossing.mode);
            if (xevent.xcrossing.mode == NotifyGrab)
                printf("Mode: NotifyGrab\n");
            if (xevent.xcrossing.mode == NotifyUngrab)
                printf("Mode: NotifyUngrab\n");
#endif
            SDL_SetMouseFocus(data->window);
        }
        break;

        /* Losing mouse coverage? */
    case LeaveNotify:{
#ifdef DEBUG_XEVENTS
            printf("LeaveNotify! (%d,%d,%d)\n", 
	           xevent.xcrossing.x,
 	           xevent.xcrossing.y,
                   xevent.xcrossing.mode);
            if (xevent.xcrossing.mode == NotifyGrab)
                printf("Mode: NotifyGrab\n");
            if (xevent.xcrossing.mode == NotifyUngrab)
                printf("Mode: NotifyUngrab\n");
#endif
            if (xevent.xcrossing.detail != NotifyInferior) {
                SDL_SetMouseFocus(NULL);
            }
        }
        break;

        /* Gaining input focus? */
    case FocusIn:{
#ifdef DEBUG_XEVENTS
            printf("FocusIn!\n");
#endif
            SDL_SetKeyboardFocus(data->window);
#ifdef X_HAVE_UTF8_STRING
            if (data->ic) {
                XSetICFocus(data->ic);
            }
#endif
        }
        break;

        /* Losing input focus? */
    case FocusOut:{
#ifdef DEBUG_XEVENTS
            printf("FocusOut!\n");
#endif
            SDL_SetKeyboardFocus(NULL);
#ifdef X_HAVE_UTF8_STRING
            if (data->ic) {
                XUnsetICFocus(data->ic);
            }
#endif
        }
        break;

        /* Generated upon EnterWindow and FocusIn */
    case KeymapNotify:{
#ifdef DEBUG_XEVENTS
            printf("KeymapNotify!\n");
#endif
            /* FIXME:
               X11_SetKeyboardState(SDL_Display, xevent.xkeymap.key_vector);
             */
        }
        break;

        /* Has the keyboard layout changed? */
    case MappingNotify:{
#ifdef DEBUG_XEVENTS
            printf("MappingNotify!\n");
#endif
            X11_UpdateKeymap(_this);
        }
        break;

        /* Key press? */
    case KeyPress:{
            KeyCode keycode = xevent.xkey.keycode;
            KeySym keysym = NoSymbol;
            char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
            Status status = 0;

#ifdef DEBUG_XEVENTS
            printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
#endif
            SDL_SendKeyboardKey(SDL_PRESSED, videodata->key_layout[keycode]);
#if 0
            if (videodata->key_layout[keycode] == SDLK_UNKNOWN) {
                int min_keycode, max_keycode;
                XDisplayKeycodes(videodata->display, &min_keycode,
                                 &max_keycode);
                keysym = XKeycodeToKeysym(videodata->display, keycode, 0);
                fprintf(stderr,
                        "The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <*****@*****.**> X11 KeyCode %d (%d), X11 KeySym 0x%X (%s).\n",
                        keycode, keycode - min_keycode, keysym,
                        XKeysymToString(keysym));
            }
#endif
            /* */
            SDL_zero(text);
#ifdef X_HAVE_UTF8_STRING
            if (data->ic) {
                Xutf8LookupString(data->ic, &xevent.xkey, text, sizeof(text),
                                  &keysym, &status);
            }
#else
            XLookupString(&xevent.xkey, text, sizeof(text), &keysym, NULL);
#endif
            if (*text) {
                SDL_SendKeyboardText(text);
            }
        }
        break;

        /* Key release? */
    case KeyRelease:{
            KeyCode keycode = xevent.xkey.keycode;

#ifdef DEBUG_XEVENTS
            printf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
#endif
            SDL_SendKeyboardKey(SDL_RELEASED, videodata->key_layout[keycode]);
        }
        break;

        /* Have we been iconified? */
    case UnmapNotify:{
#ifdef DEBUG_XEVENTS
            printf("UnmapNotify!\n");
#endif
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
        }
        break;

        /* Have we been restored? */
    case MapNotify:{
#ifdef DEBUG_XEVENTS
            printf("MapNotify!\n");
#endif
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
        }
        break;

        /* Have we been resized or moved? */
    case ConfigureNotify:{
#ifdef DEBUG_XEVENTS
            printf("ConfigureNotify! (resize: %dx%d)\n",
                   xevent.xconfigure.width, xevent.xconfigure.height);
#endif
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED,
                                xevent.xconfigure.x, xevent.xconfigure.y);
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESIZED,
                                xevent.xconfigure.width,
                                xevent.xconfigure.height);
        }
        break;

        /* Have we been requested to quit (or another client message?) */
    case ClientMessage:{
            if ((xevent.xclient.format == 32) &&
                (xevent.xclient.data.l[0] == videodata->WM_DELETE_WINDOW)) {

                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
            }
        }
        break;

        /* Do we need to refresh ourselves? */
    case Expose:{
#ifdef DEBUG_XEVENTS
            printf("Expose (count = %d)\n", xevent.xexpose.count);
#endif
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
        }
        break;

    case MotionNotify:{
#ifdef DEBUG_MOTION
            printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
#endif
            SDL_SendMouseMotion(0, xevent.xmotion.x, xevent.xmotion.y);
        }
        break;

    case ButtonPress:{
            SDL_SendMouseButton(SDL_PRESSED, xevent.xbutton.button);
        }
        break;

    case ButtonRelease:{
            SDL_SendMouseButton(SDL_RELEASED, xevent.xbutton.button);
        }
        break;

    default:{
#ifdef DEBUG_XEVENTS
            printf("Unhandled event %d\n", xevent.type);
#endif
        }
        break;
    }
}
示例#3
0
void MainLoop::Loop()
{

#ifdef MW_OS_WINDOWS

    MSG msg;
    while (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
    {

        TranslateMessage(&msg);
        DispatchMessage(&msg);

    }
#else
    XEvent               event;
    while(XPending(dpy))
    {


        XNextEvent(dpy, &event);

        switch (event.type)
        {
        case KeyPress:
        {
            KeySym     keysym;
            XKeyEvent *kevent;
            char       buffer[1];

            kevent = (XKeyEvent *) &event;


            if( XLookupString((XKeyEvent *)&event,buffer,1,&keysym,NULL) != 1 )
                break;


            switch (keysym)
            {
            case XK_Up:

                break;

            case XK_Down:
                break;

			case XK_Escape:
			case XK_Q:
			case XK_q:
				exit(0);

            default:
                break;
            }
            break;
        }//key press

        case ButtonPress:
        {
            switch (event.xbutton.button)
            {
            case Button4:
                renderer->ZoomIn();
                break;

            case Button5:
                renderer->ZoomOut();
                break;

            default:
                break;
            }
        }//mouse button press
        break;

        case ConfigureNotify:
            // XResizeWindow( dpy, win, screen_x, screen_y );

        case Expose:
            break;

        }

    }

#endif
    prev_time= current_time;
    current_time= clock();
    level->PhysTick();
    MovePlayer();
    if( sound_system != NULL )
    {
        sound_system->SetListenerPos( player->Position() );
        sound_system->SetListenerAngle( player->AngXY() );
          sound_system->Tick();
    }

    renderer->Draw();
#ifdef MW_OS_WINDOWS
    ::SwapBuffers(hdc);
#else
    glXSwapBuffers(dpy, win);
#endif


    usleep(1000);//1 ms

}
示例#4
0
文件: Login.c 项目: aosm/X11
/* ARGSUSED */
static void
InsertChar (
    Widget	ctxw,
    XEvent	*event,
    String	*params,
    Cardinal	*num_params)
{
    LoginWidget ctx = (LoginWidget)ctxw;

    char strbuf[128];
#ifndef XPM
    int  len;
#else
    int  len,pixels;
#endif /* XPM */
    KeySym  keysym = 0;

    if (ctx->login.xic) {
	static Status status;
	len = XmbLookupString(ctx->login.xic, &event->xkey, strbuf,
			      sizeof (strbuf), &keysym, &status);
    } else {
	static XComposeStatus compose_status = {NULL, 0};
	len = XLookupString (&event->xkey, strbuf, sizeof (strbuf),
			     &keysym, &compose_status);
    }
    strbuf[len] = '\0';

#ifdef XPM
    pixels = 3 + ctx->login.font->max_bounds.width * len +
    	     XTextWidth(ctx->login.font,
    	     		ctx->login.data.name,
    	     		strlen(ctx->login.data.name));
    	     	/* pixels to be added */
#endif /* XPM */

    /*
     * Note: You can override this default key handling
     * by the settings in the translation table
     * loginActionsTable at the end of this file.
     */
    switch (keysym) {
    case XK_Return:
    case XK_KP_Enter:
    case XK_Linefeed:
    case XK_Execute:
	FinishField(ctxw, event, params, num_params);
	return;
    case XK_BackSpace:
	DeleteBackwardChar(ctxw, event, params, num_params);
	return;
    case XK_Delete:
    case XK_KP_Delete:
    case DXK_Remove:
	/* Sorry, it's not a telex machine, it's a terminal */
	DeleteForwardChar(ctxw, event, params, num_params);
	return;
    case XK_Left:
    case XK_KP_Left:
	MoveBackwardChar(ctxw, event, params, num_params);
	return;
    case XK_Right:
    case XK_KP_Right:
	MoveForwardChar(ctxw, event, params, num_params);
	return;
    case XK_End:
    case XK_KP_End:
	MoveToEnd(ctxw, event, params, num_params);
	return;
    case XK_Home:
    case XK_KP_Home:
	MoveToBegining(ctxw, event, params, num_params);
	return;
    default:
	if (len == 0) {
	    if (!IsModifierKey(keysym))  /* it's not a modifier */
		XBell(XtDisplay(ctxw), 60);
	    return;
	} else
	    break;
    }

    switch (ctx->login.state) {
    case GET_NAME:
#ifndef XPM
	if (len + (int)strlen(ctx->login.data.name) >= NAME_LEN - 1)
#else
	if (
	        (len + (int)strlen(ctx->login.data.name) >= NAME_LEN - 1)/* &&
		(pixels <= LOGIN_W(ctx) - PROMPT_W(ctx))*/
	   )
#endif /* XPM */
	    len = NAME_LEN - strlen(ctx->login.data.name) - 2;
    case GET_PASSWD:
	if (len + (int)strlen(ctx->login.data.passwd) >= PASSWORD_LEN - 1)
	    len = PASSWORD_LEN - strlen(ctx->login.data.passwd) - 2;
    }
#ifndef XPM
    if (len == 0)
#else
    if (len == 0 || pixels >= LOGIN_W(ctx) - PROMPT_W(ctx))
#endif /* XPM */
	return;
    XorCursor (ctx);
    RemoveFail (ctx);
    switch (ctx->login.state) {
    case GET_NAME:
	EraseName (ctx, ctx->login.cursor);
	memmove( ctx->login.data.name + ctx->login.cursor + len,
	       ctx->login.data.name + ctx->login.cursor,
	       strlen (ctx->login.data.name + ctx->login.cursor) + 1);
	memmove( ctx->login.data.name + ctx->login.cursor, strbuf, len);
	DrawName (ctx, ctx->login.cursor);
	ctx->login.cursor += len;
	break;
    case GET_PASSWD:
	memmove( ctx->login.data.passwd + ctx->login.cursor + len,
	       ctx->login.data.passwd + ctx->login.cursor,
	       strlen (ctx->login.data.passwd + ctx->login.cursor) + 1);
	memmove( ctx->login.data.passwd + ctx->login.cursor, strbuf, len);
	ctx->login.cursor += len;

#ifdef XPM
	/*as good a place as any Caolan begin*/
	ctx->login.lastEventTime = time(NULL);
	/*as good a place as any Caolan end*/
#endif /* XPM */
	break;
    }
    XorCursor (ctx);
}
示例#5
0
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
static int _XKeyPress(XEvent *event)
{
    int modifiers = 0;  // modifiers sent to AntTweakBar
    int k = 0;          // key sent to AntTweakBar
    KeySym keysym;
    char buffer[buff_sz];
        
    int num_char = XLookupString((XKeyEvent *)event, buffer, buff_sz, &keysym, 0);

    if (event->xkey.state & ControlMask)
        modifiers |= TW_KMOD_CTRL;
    if (event->xkey.state & ShiftMask)
        modifiers |= TW_KMOD_SHIFT;
    if (event->xkey.state & Mod1Mask)
        modifiers |= TW_KMOD_ALT;

    switch (keysym)
    {
    case XK_Control_L:
    case XK_Control_R: s_KMod |= TW_KMOD_CTRL;  break;

    case XK_Shift_L:
    case XK_Shift_R:   s_KMod |= TW_KMOD_SHIFT; break;

    case XK_Alt_L:
    case XK_Alt_R:     s_KMod |= TW_KMOD_ALT;   break;

    case XK_Escape:    k = TW_KEY_ESCAPE;    break;
    case XK_Help:      k = TW_KEY_F1;        break;
    case XK_F1:        k = TW_KEY_F1;        break;
    case XK_F2:        k = TW_KEY_F2;        break;
    case XK_F3:        k = TW_KEY_F3;        break;
    case XK_F4:        k = TW_KEY_F4;        break;
    case XK_F5:        k = TW_KEY_F5;        break;
    case XK_F6:        k = TW_KEY_F6;        break;
    case XK_F7:        k = TW_KEY_F7;        break;
    case XK_F8:        k = TW_KEY_F8;        break;
    case XK_F9:        k = TW_KEY_F9;        break;
    case XK_F10:       k = TW_KEY_F10;       break;
    case XK_F11:       k = TW_KEY_F11;       break;
    case XK_F12:       k = TW_KEY_F12;       break;
    case XK_Up:        k = TW_KEY_UP;        break;
    case XK_Down:      k = TW_KEY_DOWN;      break;
    case XK_Right:     k = TW_KEY_RIGHT;     break;
    case XK_Left:      k = TW_KEY_LEFT;      break;
    case XK_Return:    k = TW_KEY_RETURN;    break;
    case XK_Insert:    k = TW_KEY_INSERT;    break;
    case XK_Delete:    k = TW_KEY_DELETE;    break;
    case XK_BackSpace: k = TW_KEY_BACKSPACE; break;
    case XK_Home:      k = TW_KEY_HOME;      break;
    case XK_Tab:       k = TW_KEY_TAB;       break;
    case XK_End:       k = TW_KEY_END;       break;

#ifdef XK_Enter
    case XK_Enter:     k = TW_KEY_RETURN;    break;
#endif

#ifdef XK_KP_Home
    case XK_KP_Home:   k = TW_KEY_HOME;      break;
    case XK_KP_End:    k = TW_KEY_END;       break;
    case XK_KP_Delete: k = TW_KEY_DELETE;    break;
#endif

#ifdef XK_KP_Up
    case XK_KP_Up:     k = TW_KEY_UP;        break;
    case XK_KP_Down:   k = TW_KEY_DOWN;      break;
    case XK_KP_Right:  k = TW_KEY_RIGHT;     break;
    case XK_KP_Left:   k = TW_KEY_LEFT;      break;
#endif

#ifdef XK_KP_Page_Up
    case XK_KP_Page_Up:   k = TW_KEY_PAGE_UP;    break;
    case XK_KP_Page_Down: k = TW_KEY_PAGE_DOWN;  break;
#endif

#ifdef XK_KP_Tab
    case XK_KP_Tab:    k = TW_KEY_TAB;       break;
#endif

    default:
        if (0)
        {
            // should we do that, or rely on the buffer (see code below)
            if (keysym > 12 && keysym < 127) 
                k = keysym;
        }
        break;
    }  
        
    if (k == 0 && num_char)
    {
        int i, handled = 0;
        for (i=0; i<num_char; ++i)
            if (TwKeyPressed(buffer[i], modifiers))
                handled = 1;
        return handled;
    }

    // if we have a valid key, send to AntTweakBar
    // -------------------------------------------
    return (k > 0) ? TwKeyPressed(k, modifiers) : 0;
}
static int XLateKey( XKeyEvent *ev )
{

	int key;
	char buf[ 64 ];
	KeySym keysym;

	key = 0;

	XLookupString( ev, buf, sizeof buf, &keysym, 0 );

	switch( keysym )
	{
		case XK_KP_Page_Up:	key = K_KP_PGUP;	break;
		case XK_Page_Up:	key = K_PGUP;		break;

		case XK_KP_Page_Down:	key = K_KP_PGDN; 	break;
		case XK_Page_Down:	key = K_PGDN; 		break;

		case XK_KP_Home:	key = K_KP_HOME; 	break;
		case XK_Home:		key = K_HOME; 		break;

		case XK_KP_End:		key = K_KP_END; 	break;
		case XK_End:		key = K_END; 		break;

		case XK_KP_Left: 	key = K_KP_LEFTARROW;	break;
		case XK_Left:	 	key = K_LEFTARROW; 	break;

		case XK_KP_Right:	key = K_KP_RIGHTARROW;	break;
		case XK_Right:		key = K_RIGHTARROW;	break;

		case XK_KP_Down: 	key = K_KP_DOWNARROW; 	break;
		case XK_Down:	 	key = K_DOWNARROW; 	break;

		case XK_KP_Up:		key = K_KP_UPARROW;	break;
		case XK_Up:			key = K_UPARROW;	break;

		case XK_Escape:		key = K_ESCAPE;		break;

		case XK_KP_Enter:	key = K_KP_ENTER;	break;
		case XK_Return:		key = K_ENTER;		break;

		case XK_Tab:		key = K_TAB;		break;

		case XK_F1:		key = K_F1;		break;

		case XK_F2:		key = K_F2;		break;

		case XK_F3:		key = K_F3;		break;

		case XK_F4:		key = K_F4;		break;

		case XK_F5:		key = K_F5;		break;

		case XK_F6:		key = K_F6;		break;

		case XK_F7:		key = K_F7;		break;

		case XK_F8:		key = K_F8;		break;

		case XK_F9:		key = K_F9;		break;

		case XK_F10:		key = K_F10;		break;

		case XK_F11:		key = K_F11;		break;

		case XK_F12:		key = K_F12;		break;

		case XK_BackSpace: 	key = K_BACKSPACE;	break;

		case XK_KP_Delete: 	key = K_KP_DEL;		break;
		case XK_Delete: 	key = K_DEL;		break;

		case XK_Pause:		key = K_PAUSE;		break;

		case XK_Shift_L:
		case XK_Shift_R:	key = K_SHIFT;		break;

		case XK_Execute: 
		case XK_Control_L: 
		case XK_Control_R:	key = K_CTRL;		break;

		case XK_Alt_L:	
		case XK_Meta_L: 
		case XK_Alt_R:	
		case XK_Meta_R: 	key = K_ALT;		break;

		case XK_KP_Begin: 	key = K_KP_5;		break;

		case XK_Insert:		key = K_INS;		break;
		case XK_KP_Insert: 	key = K_KP_INS;		break;

		case XK_KP_Multiply:	key = '*';		break;
		case XK_KP_Add:		key = K_KP_PLUS;	break;
		case XK_KP_Subtract:	key = K_KP_MINUS;	break;
		case XK_KP_Divide:	key = K_KP_SLASH;	break;

#if 0
		case 0x021: key = '1';break;/* [!] */
		case 0x040: key = '2';break;/* [@] */
		case 0x023: key = '3';break;/* [#] */
		case 0x024: key = '4';break;/* [$] */
		case 0x025: key = '5';break;/* [%] */
		case 0x05e: key = '6';break;/* [^] */
		case 0x026: key = '7';break;/* [&] */
		case 0x02a: key = '8';break;/* [*] */
		case 0x028: key = '9';;break;/* [(] */
		case 0x029: key = '0';break;/* [)] */
		case 0x05f: key = '-';break;/* [_] */
		case 0x02b: key = '=';break;/* [+] */
		case 0x07c: key = '\'';break;/* [|] */
		case 0x07d: key = '[';break;/* [}] */
		case 0x07b: key = ']';break;/* [{] */
		case 0x022: key = '\'';break;/* ["] */
		case 0x03a: key = ';';break;/* [:] */
		case 0x03f: key = '/';break;/* [?] */
		case 0x03e: key = '.';break;/* [>] */
		case 0x03c: key = ',';break;/* [<] */
#endif

		default:
			key = *(PW8)buf;
			key = TOLOWER( key );
			break;
	} 

	return key;
}
示例#7
0
文件: x11-itrans.c 项目: 0intro/vx32
static KeySym
_xkeysym(XEvent *e)
{
	KeySym k;

	if(e->xany.type != KeyPress)
		return -1;
//	needstack(64*1024);	/* X has some *huge* buffers in openobject */
		/* and they're even bigger on SuSE */
	XLookupString((XKeyEvent*)e,NULL,0,&k,NULL);
	if(k == XK_Multi_key || k == NoSymbol)
		return -1;

	if(k&0xFF00){
		switch(k){
		case XK_BackSpace:
		case XK_Tab:
		case XK_Escape:
		case XK_Delete:
		case XK_KP_0:
		case XK_KP_1:
		case XK_KP_2:
		case XK_KP_3:
		case XK_KP_4:
		case XK_KP_5:
		case XK_KP_6:
		case XK_KP_7:
		case XK_KP_8:
		case XK_KP_9:
		case XK_KP_Divide:
		case XK_KP_Multiply:
		case XK_KP_Subtract:
		case XK_KP_Add:
		case XK_KP_Decimal:
			k &= 0x7F;
			break;
		case XK_Linefeed:
			k = '\r';
			break;
		case XK_KP_Space:
			k = ' ';
			break;
		case XK_Home:
		case XK_KP_Home:
			k = Khome;
			break;
		case XK_Left:
		case XK_KP_Left:
			k = Kleft;
			break;
		case XK_Up:
		case XK_KP_Up:
			k = Kup;
			break;
		case XK_Down:
		case XK_KP_Down:
			k = Kdown;
			break;
		case XK_Right:
		case XK_KP_Right:
			k = Kright;
			break;
		case XK_Page_Down:
		case XK_KP_Page_Down:
			k = Kpgdown;
			break;
		case XK_End:
		case XK_KP_End:
			k = Kend;
			break;
		case XK_Page_Up:	
		case XK_KP_Page_Up:
			k = Kpgup;
			break;
		case XK_Insert:
		case XK_KP_Insert:
			k = Kins;
			break;
		case XK_KP_Enter:
		case XK_Return:
			k = '\n';
			break;
		case XK_Alt_L:
		case XK_Meta_L:	/* Shift Alt on PCs */
		case XK_Alt_R:
		case XK_Meta_R:	/* Shift Alt on PCs */
			k = Kalt;
			break;
		default:		/* not ISO-1 or tty control */
			if(k>0xff)
				return _xkeysym2rune(k);
			break;
		}
	}

	/* Compensate for servers that call a minus a hyphen */
	if(k == XK_hyphen)
		k = XK_minus;
	/* Do control mapping ourselves if translator doesn't */
	if(e->xkey.state&ControlMask && k != Kalt)
		k &= 0x9f;
	if(k == NoSymbol)
		return -1;
	return k;
}
示例#8
0
void CoreWindow::DoEvents(void)
{
	XEvent evt;
	KeySym key;
	char text[255];
	int mx,my;
	
	XNextEvent(m_display, &evt );
	//printf("EVENT=%d\n",evt.type);
	switch ( evt.type ) {
		case Expose:
			if ( evt.xexpose.count == 0 ) {
				g_win->Draw();
			}
			return;
			
		case ButtonPress:
			mx = evt.xbutton.x;
			my = evt.xbutton.y;
			if( evt.xbutton.button == 1 ){
				g_win->MouseLeftDown(mx,my);
			} else if( evt.xbutton.button == 2 ){
				g_win->MouseMiddleDown(mx,my);
			} else if( evt.xbutton.button == 3 ){
				g_win->MouseRightDown(mx,my);
			} else if( evt.xbutton.button == 4 ){
				g_win->Wheel(0.0f, 1.0f, 0.0f);
			} else if( evt.xbutton.button == 5 ){
				g_win->Wheel(0.0f,-1.0f, 0.0f);
			}
			return;
		case ButtonRelease:
			mx = evt.xbutton.x;
			my = evt.xbutton.y;
			if( evt.xbutton.button == 1 ){
				g_win->MouseLeftUp(mx,my);
			} else if( evt.xbutton.button == 2 ){
				g_win->MouseMiddleUp(mx,my);
			} else if( evt.xbutton.button == 3 ){
				g_win->MouseRightUp(mx,my);
			}
			return;
		case MotionNotify:
			mx = evt.xbutton.x;
			my = evt.xbutton.y;
			g_win->MouseMove(mx, my);
			return;
			
		case KeyPress:
			if (XLookupString(&evt.xkey,text,255,&key,0) == 1) {
				g_win->KeyDown(text[0]);
			}
			return;
		case KeyRelease:
			if (XLookupString(&evt.xkey,text,255,&key,0) == 1) {
				g_win->KeyUp(text[0]);
			}
			return ;
			
		case ResizeRequest:
			g_win->Resize(evt.xresizerequest.width, evt.xresizerequest.height);
			return;
	}
}