/* * Hlavní cyklus zpracování událostí */ static void event_loop(void) { XEvent event; char buf[10]; KeySym keysym; while(1) { XNextEvent(display, &event); switch(event.type) { case Expose: expose(&event.xexpose); break; case ButtonPress: debug("Button %u pressed\n", event.xbutton.button); return; break; case KeyPress: XLookupString(&event.xkey, buf, 10, &keysym, NULL); debug("Key \"%s\" pressed\n", XKeysymToString(keysym)); return; break; case MappingNotify: /* Naèíst zmìnìné mapování kláves */ if(event.xmapping.request == MappingKeyboard) XRefreshKeyboardMapping(&event.xmapping); break; default: /* Zbylé nezajímavé události */ break; } } }
/* loop while the connection is supposed to be valid */ void xloop(char *message) { XEvent event; init_window(); while (1) { XNextEvent(display, &event); switch (event.type) { case MappingNotify: XRefreshKeyboardMapping(&event.xmapping); break; case Expose: refresh(message); break; case KeyPress: keyevent(&event.xkey); break; case ButtonPress: XCloseDisplay(display); return; break; } } }
/* * Hlavní cyklus zpracování událostí */ static void event_loop(void) { XEvent event; while(1) { XNextEvent(display, &event); switch(event.type) { case Expose: expose(&event.xexpose); break; case ButtonPress: debug("Button %u pressed\n", event.xbutton.button); return; break; case ConfigureNotify: if((int)topwin_w != event.xconfigure.width || (int)topwin_h != event.xconfigure.height) { topwin_w = event.xconfigure.width; topwin_h = event.xconfigure.height; debug("Window resized to %ux%u pixels\n", topwin_w, topwin_h); XClearWindow(display, topwin); } break; case MappingNotify: /* Naèíst zmìnìné mapování kláves */ if(event.xmapping.request == MappingKeyboard) XRefreshKeyboardMapping(&event.xmapping); break; default: /* Zbylé nezajímavé události */ break; } } }
/*-------------------------------------- * Function: UpdateDisplayImpl() * Parameters: * * Description: * Uppdaterar ritytan. *------------------------------------*/ void UpdateDisplayImpl() { glXSwapBuffers(display, window); XEvent xe; //XNextEvent(display, &xe); if (XCheckWindowEvent(display, window, KeyPressMask, &xe)) { if (xe.type == ClientMessage) { if (xe.xclient.data.l[0] == wm_delete_msg) { // Easy h4x, lol. window = NULL; } } else if (xe.type == MappingNotify) { printf("broder dang\n"); XRefreshKeyboardMapping((XMappingEvent*)&xe); } else { char buf[16] = {0}; KeySym keysym; XLookupString((XKeyEvent*)&xe, buf, sizeof(buf), &keysym, NULL); char c = buf[0]; actionT fn = keyPressCB[c]; if (fn) fn(keyPressArg[c]); } } }
static int perform_x11_task() { if(XPending(gcore.disp) == 0) return 0; XEvent myevent; XNextEvent (gcore.disp, &myevent); switch (myevent.type) { case Expose: /* Repaint window on expose */ if (myevent.xexpose.count == 0) { //change_gc(myevent.xexpose.x, myevent.xexpose.y, myevent.xexpose.width, myevent.xexpose.height); repaint_x11(); } break; case MappingNotify: /* Process keyboard mapping changes: */ XRefreshKeyboardMapping (&myevent.xmapping); break; case ConfigureNotify: { XConfigureEvent ev = myevent.xconfigure; if(ev.width != gcore.width || ev.height != gcore.height) { msg_enqueue(ENUM_ROOPKOTHA_GUI_CORE_TASK_WINDOW_TASK, ENUM_ROOPKOTHA_GUI_WINDOW_TASK_RESIZE , 3, gcore.wid, ev.width, ev.height); } } break; #if 0 case ResizeRequest: /* Resize */ { XResizeRequestEvent ev = myevent.xresizerequest; // TODO set the correct window id msg_enqueue(ENUM_ROOPKOTHA_GUI_CORE_TASK_WINDOW_TASK, ENUM_ROOPKOTHA_GUI_WINDOW_TASK_RESIZE, 3, 1, ev.width, ev.height); //set_clip(ev.window, ev.width, ev.height); repaint_x11(); } break; case ButtonPress: /* Process mouse click - output Hi! at mouse: */ XDrawImageString (myevent.xbutton.display, myevent.xbutton.window, mygc, myevent.xbutton.x, myevent.xbutton.y, hi, strlen (hi)); break; #endif case KeyPress: /* Process key press - quit on q: */ { char text[10]; KeySym skey = 0; XComposeStatus compose; int nChar = XLookupString (&myevent.xkey, text, 10, &skey, &compose); int i; int code = key_event_map(skey); if(code) { msg_enqueue(ENUM_ROOPKOTHA_GUI_CORE_TASK_WINDOW_TASK, ENUM_ROOPKOTHA_GUI_WINDOW_TASK_KEY_PRESS, 3, gcore.wid, 0, code); } else { for(i = 0; i < nChar; i++) msg_enqueue(ENUM_ROOPKOTHA_GUI_CORE_TASK_WINDOW_TASK, ENUM_ROOPKOTHA_GUI_WINDOW_TASK_KEY_PRESS, 3, gcore.wid, text[i], code); } } break; } return 0; }
static void mappingnotify(XEvent *e) { XMappingEvent *ev; ev = &e->xmapping; /* Why do you need me to tell you this? */ XRefreshKeyboardMapping(ev); }
static void mappingnotify(XEvent *e) { XMappingEvent *ev = &e->xmapping; XRefreshKeyboardMapping(ev); if(ev->request == MappingKeyboard) grabkeys(); }
void MappingNotifyHandler(Display *display, XEvent *event) { XMappingEvent *mappingEvent = &event->xmapping; XRefreshKeyboardMapping(mappingEvent); if(mappingEvent->request == MappingKeyboard) GrabKeys(display); }
/** MappingNotify handle event * \param ev XMappingEvent pointer */ static void mappingnotify(XMappingEvent *ev) { XRefreshKeyboardMapping(ev); if(ev->request == MappingKeyboard) grabkeys(); return; }
void mappingnotify(XEvent* event) { { // regrab when keyboard map changes XMappingEvent *ev = &event->xmapping; XRefreshKeyboardMapping(ev); if(ev->request == MappingKeyboard) { regrab_keys(); //TODO: mouse_regrab_all(); } } }
int main (int argc, char *argv[]) { Display *my_display = NULL; Window my_window; GC my_gc; XEvent my_event; int my_screen, done = 0; unsigned int foreground, background; my_display = XOpenDisplay (""); if ( my_display == NULL ) { printf ("\n\t Couldn't Open display\n"); exit (-1); } my_screen = DefaultScreen (my_display); foreground = WhitePixel (my_display, my_screen); background = BlackPixel (my_display, my_screen); my_window = XCreateSimpleWindow (my_display, RootWindow (my_display, my_screen), 200, 300, 350, 350, 5, background, foreground); my_gc = XCreateGC (my_display, my_window, 0, 0); XSelectInput (my_display, my_window, ButtonPressMask | KeyPressMask | ExposureMask ); XMapWindow (my_display, my_window ); while (done == 0) { XNextEvent (my_display, &my_event); switch (my_event.type) { case Expose: XDrawString ( my_event.xexpose.display, my_event.xexpose.window, my_gc, 50, 50, hello, strlen (hello) ); break; case ButtonPress: XDrawString ( my_event.xbutton.display, my_event.xbutton.window, my_gc, my_event.xbutton.x, my_event.xbutton.y, hi, strlen (hi)); break; case KeyPress: done = 1; break; case MappingNotify: XRefreshKeyboardMapping ( (struct XMappingEvent *)&my_event); break; } } XFreeGC (my_display, my_gc ); XDestroyWindow (my_display, my_window); XCloseDisplay (my_display); }
void X11KeyFaker::readyRead() { if (dpy) { // Read incoming events and discard them. The only event // we care about is keyboard mapping changes. Since we // don't have any active windows, there's nothing more to do. while (XEventsQueued(dpy, QueuedAfterFlush)) { XEvent event; XNextEvent(dpy, &event); if (event.xany.type == MappingNotify) XRefreshKeyboardMapping(&event.xmapping); } } }
int main(int argc, char* argv[]) { argv0 = argv[0]; /* Open a connection to the X server. */ dpy = XOpenDisplay(""); if (dpy == 0) { panic("can't open display."); } /* Set up signal handlers. */ #if 0 signal(SIGTERM, SIG_IGN); signal(SIGINT, SIG_IGN); #endif signal(SIGHUP, SIG_IGN); signal(SIGCHLD, sigchld_handler); screen_count = ScreenCount(dpy); if (argc != 2) { panic("syntax: speckeysd <keys file>"); } read_hot_key_file(argv[1]); /* Make sure all our communication to the server got through. */ XSync(dpy, False); /* The main event loop. */ for (;;) { XEvent ev; XNextEvent(dpy, &ev); switch (ev.type) { case KeyPress: keypress(&ev); break; case MappingNotify: XRefreshKeyboardMapping((XMappingEvent*) &ev); break; default: /* Do I look like I care? */ break; } } }
void ProcXEvent(XEvent *e) { Atom p; WindowIf *i; switch (e->type) { case SelectionRequest: p = e->xselectionrequest.property; if (p == atom_locales) notifyLocale(e); else if (p == atom_transport) notifyTransport(e); else printf("property %s?\n", XGetAtomName(XimServer::gDpy, e->xselection.property)); break; case Expose: if (e->xexpose.count == 0) { i = findWindowIf(e->xexpose.window); if (i) i->expose(e->xexpose.window); } break; case ConfigureNotify: i = findWindowIf(e->xconfigure.window); if (i) i->resize(e->xconfigure.window, e->xconfigure.x, e->xconfigure.y); break; case DestroyNotify: i = findWindowIf(e->xdestroywindow.window); if (i) i->destroy(e->xdestroywindow.window); remove_window_watch(e->xdestroywindow.window); break; case ClientMessage: procXClientMessage(&e->xclient); break; case MappingNotify: XRefreshKeyboardMapping((XMappingEvent *)e); init_modifier_keys(); break; default:; //printf("unknown type of X event. %d\n", e->type); } }
int AutoTypePlatformX11::platformEventFilter(void* event) { xcb_generic_event_t* genericEvent = static_cast<xcb_generic_event_t*>(event); quint8 type = genericEvent->response_type & 0x7f; if (type == XCB_KEY_PRESS || type == XCB_KEY_RELEASE) { xcb_key_press_event_t* keyPressEvent = static_cast<xcb_key_press_event_t*>(event); if (keyPressEvent->detail == m_currentGlobalKeycode && (keyPressEvent->state & m_modifierMask) == m_currentGlobalNativeModifiers && !QApplication::focusWidget() && m_loaded) { if (type == XCB_KEY_PRESS) { Q_EMIT globalShortcutTriggered(); } return 1; } } else if (type == XCB_MAPPING_NOTIFY) { xcb_mapping_notify_event_t* mappingNotifyEvent = static_cast<xcb_mapping_notify_event_t*>(event); if (mappingNotifyEvent->request == XCB_MAPPING_KEYBOARD || mappingNotifyEvent->request == XCB_MAPPING_MODIFIER) { XMappingEvent xMappingEvent; memset(&xMappingEvent, 0, sizeof(xMappingEvent)); xMappingEvent.type = MappingNotify; xMappingEvent.display = m_dpy; if (mappingNotifyEvent->request == XCB_MAPPING_KEYBOARD) { xMappingEvent.request = MappingKeyboard; } else { xMappingEvent.request = MappingModifier; } xMappingEvent.first_keycode = mappingNotifyEvent->first_keycode; xMappingEvent.count = mappingNotifyEvent->count; XRefreshKeyboardMapping(&xMappingEvent); updateKeymap(); } } return -1; }
int main (int argc, char **argv) { int done = 0; struct drawing canvas; struct window win; XEvent myevent; initialize (&canvas, &win, argc, argv); if (fractal_options.type == MANDELBROT) mandelbrot (&canvas, &win); else julia (&canvas, &win); while (!done) { XNextEvent (win.display, &myevent); switch (myevent.type) { case ButtonPress: handleButtonPress (&myevent, &canvas, &win); break; case Expose: handleExpose (&myevent, &canvas, &win); break; case MappingNotify: XRefreshKeyboardMapping ((XMappingEvent *) &myevent); break; case ReparentNotify: handleReparentNotify (&myevent, &win); break; case KeyPress: exit (EXIT_SUCCESS); break; } } XFreeGC (win.display, win.gc); XDestroyWindow (win.display, win.win); XCloseDisplay (win.display); return EXIT_SUCCESS; }
int AutoTypePlatformX11::platformEventFilter(void* event) { XEvent* xevent = static_cast<XEvent*>(event); if ((xevent->type == KeyPress || xevent->type == KeyRelease) && m_currentGlobalKey && xevent->xkey.keycode == m_currentGlobalKeycode && (xevent->xkey.state & m_modifierMask) == m_currentGlobalNativeModifiers && !QApplication::focusWidget() && m_loaded) { if (xevent->type == KeyPress) { Q_EMIT globalShortcutTriggered(); } return 1; } if (xevent->type == MappingNotify && m_loaded) { XRefreshKeyboardMapping(reinterpret_cast<XMappingEvent*>(xevent)); updateKeymap(); } return -1; }
void fgPlatformProcessSingleEvent ( void ) { SFG_Window* window; XEvent event; /* This code was repeated constantly, so here it goes into a definition: */ #define GETWINDOW(a) \ window = fgWindowByHandle( event.a.window ); \ if( window == NULL ) \ break; #define GETMOUSE(a) \ window->State.MouseX = event.a.x; \ window->State.MouseY = event.a.y; FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" ); while( XPending( fgDisplay.pDisplay.Display ) ) { XNextEvent( fgDisplay.pDisplay.Display, &event ); #if _DEBUG fghPrintEvent( &event ); #endif switch( event.type ) { case ClientMessage: if (fgStructure.CurrentWindow) if(fgIsSpaceballXEvent(&event)) { fgSpaceballHandleXEvent(&event); break; } /* Destroy the window when the WM_DELETE_WINDOW message arrives */ if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.pDisplay.DeleteWindow ) { GETWINDOW( xclient ); fgDestroyWindow ( window ); if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT ) { fgDeinitialize( ); exit( 0 ); } else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS ) fgState.ExecState = GLUT_EXEC_STATE_STOP; return; } break; /* * CreateNotify causes a configure-event so that sub-windows are * handled compatibly with GLUT. Otherwise, your sub-windows * (in freeglut only) will not get an initial reshape event, * which can break things. * * GLUT presumably does this because it generally tries to treat * sub-windows the same as windows. */ case CreateNotify: case ConfigureNotify: { int width, height, x, y; if( event.type == CreateNotify ) { GETWINDOW( xcreatewindow ); width = event.xcreatewindow.width; height = event.xcreatewindow.height; x = event.xcreatewindow.x; y = event.xcreatewindow.y; } else { GETWINDOW( xconfigure ); width = event.xconfigure.width; height = event.xconfigure.height; x = event.xconfigure.x; y = event.xconfigure.y; } /* Update state and call callback, if there was a change */ fghOnPositionNotify(window, x, y, GL_FALSE); /* Update state and call callback, if there was a change */ fghOnReshapeNotify(window, width, height, GL_FALSE); } break; case DestroyNotify: /* * This is sent to confirm the XDestroyWindow call. * * XXX WHY is this commented out? Should we re-enable it? */ /* fgAddToWindowDestroyList ( window ); */ break; case Expose: /* * We are too dumb to process partial exposes... * * XXX Well, we could do it. However, it seems to only * XXX be potentially useful for single-buffered (since * XXX double-buffered does not respect viewport when we * XXX do a buffer-swap). * */ if( event.xexpose.count == 0 ) { GETWINDOW( xexpose ); window->State.WorkMask |= GLUT_DISPLAY_WORK; } break; case MapNotify: break; case UnmapNotify: /* We get this when iconifying a window. */ GETWINDOW( xunmap ); INVOKE_WCB( *window, WindowStatus, ( GLUT_HIDDEN ) ); window->State.Visible = GL_FALSE; break; case MappingNotify: /* * Have the client's keyboard knowledge updated (xlib.ps, * page 206, says that's a good thing to do) */ XRefreshKeyboardMapping( (XMappingEvent *) &event ); break; case VisibilityNotify: { /* * Sending this event, the X server can notify us that the window * has just acquired one of the three possible visibility states: * VisibilityUnobscured, VisibilityPartiallyObscured or * VisibilityFullyObscured. Note that we DO NOT receive a * VisibilityNotify event when iconifying a window, we only get an * UnmapNotify then. */ GETWINDOW( xvisibility ); switch( event.xvisibility.state ) { case VisibilityUnobscured: INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_RETAINED ) ); window->State.Visible = GL_TRUE; break; case VisibilityPartiallyObscured: INVOKE_WCB( *window, WindowStatus, ( GLUT_PARTIALLY_RETAINED ) ); window->State.Visible = GL_TRUE; break; case VisibilityFullyObscured: INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_COVERED ) ); window->State.Visible = GL_FALSE; break; default: fgWarning( "Unknown X visibility state: %d", event.xvisibility.state ); break; } } break; case EnterNotify: case LeaveNotify: GETWINDOW( xcrossing ); GETMOUSE( xcrossing ); if( ( event.type == LeaveNotify ) && window->IsMenu && window->ActiveMenu && window->ActiveMenu->IsActive ) fgUpdateMenuHighlight( window->ActiveMenu ); INVOKE_WCB( *window, Entry, ( ( EnterNotify == event.type ) ? GLUT_ENTERED : GLUT_LEFT ) ); break; case MotionNotify: { /* if GLUT_SKIP_STALE_MOTION_EVENTS is true, then discard all but * the last motion event from the queue */ if(fgState.SkipStaleMotion) { while(XCheckIfEvent(fgDisplay.pDisplay.Display, &event, match_motion, 0)); } GETWINDOW( xmotion ); GETMOUSE( xmotion ); if( window->ActiveMenu ) { if( window == window->ActiveMenu->ParentWindow ) { window->ActiveMenu->Window->State.MouseX = event.xmotion.x_root - window->ActiveMenu->X; window->ActiveMenu->Window->State.MouseY = event.xmotion.y_root - window->ActiveMenu->Y; } fgUpdateMenuHighlight( window->ActiveMenu ); break; } /* * XXX For more than 5 buttons, just check {event.xmotion.state}, * XXX rather than a host of bit-masks? Or maybe we need to * XXX track ButtonPress/ButtonRelease events in our own * XXX bit-mask? */ fgState.Modifiers = fgPlatformGetModifiers( event.xmotion.state ); if ( event.xmotion.state & ( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask ) ) { INVOKE_WCB( *window, Motion, ( event.xmotion.x, event.xmotion.y ) ); } else { INVOKE_WCB( *window, Passive, ( event.xmotion.x, event.xmotion.y ) ); } fgState.Modifiers = INVALID_MODIFIERS; } break; case ButtonRelease: case ButtonPress: { GLboolean pressed = GL_TRUE; int button; if( event.type == ButtonRelease ) pressed = GL_FALSE ; /* * A mouse button has been pressed or released. Traditionally, * break if the window was found within the freeglut structures. */ GETWINDOW( xbutton ); GETMOUSE( xbutton ); /* * An X button (at least in XFree86) is numbered from 1. * A GLUT button is numbered from 0. * Old GLUT passed through buttons other than just the first * three, though it only gave symbolic names and official * support to the first three. */ button = event.xbutton.button - 1; /* * Do not execute the application's mouse callback if a menu * is hooked to this button. In that case an appropriate * private call should be generated. */ if( fgCheckActiveMenu( window, button, pressed, event.xbutton.x, event.xbutton.y ) ) break; /* * Check if there is a mouse or mouse wheel callback hooked to the * window */ if( ! FETCH_WCB( *window, Mouse ) && ! FETCH_WCB( *window, MouseWheel ) ) break; fgState.Modifiers = fgPlatformGetModifiers( event.xbutton.state ); /* Finally execute the mouse or mouse wheel callback */ if( ( button < glutDeviceGet ( GLUT_NUM_MOUSE_BUTTONS ) ) || ( ! FETCH_WCB( *window, MouseWheel ) ) ) INVOKE_WCB( *window, Mouse, ( button, pressed ? GLUT_DOWN : GLUT_UP, event.xbutton.x, event.xbutton.y ) ); else { /* * Map 4 and 5 to wheel zero; EVEN to +1, ODD to -1 * " 6 and 7 " " one; ... * * XXX This *should* be behind some variables/macros, * XXX since the order and numbering isn't certain * XXX See XFree86 configuration docs (even back in the * XXX 3.x days, and especially with 4.x). * * XXX Note that {button} has already been decremented * XXX in mapping from X button numbering to GLUT. * * XXX Should add support for partial wheel turns as Windows does -- 5/27/11 */ int wheel_number = (button - glutDeviceGet ( GLUT_NUM_MOUSE_BUTTONS )) / 2; int direction = -1; if( button % 2 ) direction = 1; if( pressed ) INVOKE_WCB( *window, MouseWheel, ( wheel_number, direction, event.xbutton.x, event.xbutton.y ) ); } fgState.Modifiers = INVALID_MODIFIERS; } break; case KeyRelease: case KeyPress: { FGCBKeyboard keyboard_cb; FGCBSpecial special_cb; GETWINDOW( xkey ); GETMOUSE( xkey ); /* Detect auto repeated keys, if configured globally or per-window */ if ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE ) { if (event.type==KeyRelease) { /* * Look at X11 keystate to detect repeat mode. * While X11 says the key is actually held down, we'll ignore KeyRelease/KeyPress pairs. */ char keys[32]; XQueryKeymap( fgDisplay.pDisplay.Display, keys ); /* Look at X11 keystate to detect repeat mode */ if ( event.xkey.keycode<256 ) /* XQueryKeymap is limited to 256 keycodes */ { if ( keys[event.xkey.keycode>>3] & (1<<(event.xkey.keycode%8)) ) window->State.pWState.KeyRepeating = GL_TRUE; else window->State.pWState.KeyRepeating = GL_FALSE; } } } else window->State.pWState.KeyRepeating = GL_FALSE; /* Cease processing this event if it is auto repeated */ if (window->State.pWState.KeyRepeating) { if (event.type == KeyPress) window->State.pWState.KeyRepeating = GL_FALSE; break; } if( event.type == KeyPress ) { keyboard_cb = (FGCBKeyboard)( FETCH_WCB( *window, Keyboard )); special_cb = (FGCBSpecial) ( FETCH_WCB( *window, Special )); } else { keyboard_cb = (FGCBKeyboard)( FETCH_WCB( *window, KeyboardUp )); special_cb = (FGCBSpecial) ( FETCH_WCB( *window, SpecialUp )); } /* Is there a keyboard/special callback hooked for this window? */ if( keyboard_cb || special_cb ) { XComposeStatus composeStatus; char asciiCode[ 32 ]; KeySym keySym; int len; /* Check for the ASCII/KeySym codes associated with the event: */ len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode), &keySym, &composeStatus ); /* GLUT API tells us to have two separate callbacks... */ if( len > 0 ) { /* ...one for the ASCII translateable keypresses... */ if( keyboard_cb ) { fgSetWindow( window ); fgState.Modifiers = fgPlatformGetModifiers( event.xkey.state ); keyboard_cb( asciiCode[ 0 ], event.xkey.x, event.xkey.y ); fgState.Modifiers = INVALID_MODIFIERS; } } else { int special = -1; /* * ...and one for all the others, which need to be * translated to GLUT_KEY_Xs... */ switch( keySym ) { case XK_F1: special = GLUT_KEY_F1; break; case XK_F2: special = GLUT_KEY_F2; break; case XK_F3: special = GLUT_KEY_F3; break; case XK_F4: special = GLUT_KEY_F4; break; case XK_F5: special = GLUT_KEY_F5; break; case XK_F6: special = GLUT_KEY_F6; break; case XK_F7: special = GLUT_KEY_F7; break; case XK_F8: special = GLUT_KEY_F8; break; case XK_F9: special = GLUT_KEY_F9; break; case XK_F10: special = GLUT_KEY_F10; break; case XK_F11: special = GLUT_KEY_F11; break; case XK_F12: special = GLUT_KEY_F12; break; case XK_KP_Left: case XK_Left: special = GLUT_KEY_LEFT; break; case XK_KP_Right: case XK_Right: special = GLUT_KEY_RIGHT; break; case XK_KP_Up: case XK_Up: special = GLUT_KEY_UP; break; case XK_KP_Down: case XK_Down: special = GLUT_KEY_DOWN; break; case XK_KP_Prior: case XK_Prior: special = GLUT_KEY_PAGE_UP; break; case XK_KP_Next: case XK_Next: special = GLUT_KEY_PAGE_DOWN; break; case XK_KP_Home: case XK_Home: special = GLUT_KEY_HOME; break; case XK_KP_End: case XK_End: special = GLUT_KEY_END; break; case XK_KP_Insert: case XK_Insert: special = GLUT_KEY_INSERT; break; case XK_Num_Lock : special = GLUT_KEY_NUM_LOCK; break; case XK_KP_Begin : special = GLUT_KEY_BEGIN; break; case XK_KP_Delete: special = GLUT_KEY_DELETE; break; case XK_Shift_L: special = GLUT_KEY_SHIFT_L; break; case XK_Shift_R: special = GLUT_KEY_SHIFT_R; break; case XK_Control_L: special = GLUT_KEY_CTRL_L; break; case XK_Control_R: special = GLUT_KEY_CTRL_R; break; case XK_Alt_L: special = GLUT_KEY_ALT_L; break; case XK_Alt_R: special = GLUT_KEY_ALT_R; break; } /* * Execute the callback (if one has been specified), * given that the special code seems to be valid... */ if( special_cb && (special != -1) ) { fgSetWindow( window ); fgState.Modifiers = fgPlatformGetModifiers( event.xkey.state ); special_cb( special, event.xkey.x, event.xkey.y ); fgState.Modifiers = INVALID_MODIFIERS; } } } }
static int DriverPrivateEvents(XEvent *report) { UINT wstate; HWND hWnd,hWndFrame; WINDOWPOS wp; int count; int msgposted = 0; DWORD dwClientWin; RECT rcWnd; PRIVATEDISPLAY *dp; static Window win; Window win_focus; DWORD dwStyle; int revert_return; char *msgstr = 0; dp = GETDP(); switch (report->type) { case SelectionNotify: msgstr = "SelectionNotify"; dp->ServerTime = report->xselection.time; break; case SelectionClear: msgstr = "SelectionClear"; dp->ServerTime = report->xselectionclear.time; break; case SelectionRequest: msgstr = "SelectionRequest"; dp->ServerTime = report->xselectionrequest.time; break; case PropertyNotify: msgstr = "PropertyNotify"; dp->ServerTime = report->xproperty.time; /* * fall through to common code, handle X ICCCM * PropertyNotify will be related to clipboard and DDE * ClientMessage will be either * wm_protocol for user/window manager interactions * ipc_protocol for DDE and low-level interactions */ case ClientMessage: msgstr = "ClientMessage"; if(InternalICCCM(report->type,dp,report)) msgposted--; break; case Expose: { XRectangle rcexpose; Region RgnExpose = 0; RECT rcExpose; HWND hWndFrame = 0; msgstr = "Expose"; count = 0; do { if (count == 0) { if (XFindContext(dp->display,report->xexpose.window, dp->client_hwnd,(caddr_t *)&dwClientWin)) continue; hWndFrame = (HWND)HIWORD(dwClientWin); count = report->xexpose.count; if (count == 0) { rcExpose.left = report->xexpose.x; rcExpose.top = report->xexpose.y; rcExpose.right = report->xexpose.x+ report->xexpose.width; rcExpose.bottom = report->xexpose.y+ report->xexpose.height; lpLibCallback(TWINLIBCALLBACK_EXPOSE,(LPARAM)hWndFrame, SIMPLEREGION, (LPVOID)&rcExpose); msgposted--; continue; } else RgnExpose = XCreateRegion(); } rcexpose.x = report->xexpose.x; rcexpose.y = report->xexpose.y; rcexpose.width = report->xexpose.width; rcexpose.height = report->xexpose.height; XUnionRectWithRegion(&rcexpose,RgnExpose,RgnExpose); if (report->xexpose.count == 0) { lpLibCallback(TWINLIBCALLBACK_EXPOSE,(LPARAM)hWndFrame, COMPLEXREGION,(LPVOID)RgnExpose); msgposted--; XDestroyRegion(RgnExpose); count = 0; } } while (XCheckTypedEvent(dp->display,Expose,report)); break; } case ReparentNotify: msgstr = "ReparentNotify"; if (XFindContext(dp->display,report->xreparent.window, dp->client_hwnd,(caddr_t *)&dwClientWin)) break; /* We have to repeat XResizeWindow for the sake of */ /* OpenWindows, which loses resizing requests */ hWnd = LOWORD(dwClientWin); GetPhysicalRect(hWnd,&rcWnd); XResizeWindow(dp->display, report->xreparent.window, rcWnd.right-rcWnd.left, rcWnd.bottom-rcWnd.top); break; case ConfigureNotify: msgstr = "ConfigureNotify"; if (XFindContext(dp->display,report->xconfigure.window, dp->client_hwnd,(caddr_t *)&dwClientWin)) break; /* Window managers send synthetic ConfigureNotify events */ /* if the window was moved but not resized (July 27, 1988 */ /* ICCCM draft). Some window managers (OpenWin) offset the */ /* origin by some fixed value, so take size portion and go */ /* get origin from Xlib */ wstate = SWP_NOACTIVATE|SWP_DRIVER|SWP_NOZORDER; { int xRoot,yRoot; Window child_return; XTranslateCoordinates(dp->display, report->xconfigure.window, RootWindow(dp->display,dp->screen), 0,0, &xRoot,&yRoot, &child_return); report->xconfigure.x = xRoot; report->xconfigure.y = yRoot; } if (!report->xconfigure.width || !report->xconfigure.height) wstate |= SWP_NOSIZE; wp.hwnd = (HWND)HIWORD(dwClientWin); wp.hwndInsertAfter = (HWND)0; wp.x = report->xconfigure.x; wp.y = report->xconfigure.y; wp.cx = report->xconfigure.width; wp.cy = report->xconfigure.height; wp.flags = wstate; lpLibCallback(TWINLIBCALLBACK_CONFIGURE,(LPARAM)wp.hwnd, 0, (LPVOID)&wp); break; case ButtonPress: msgstr = "ButtonPress"; msgposted = DrvWindowsEvents(0L,0L,(LPVOID)report); break; case ButtonRelease: msgstr = "ButtonRelease"; msgposted = DrvWindowsEvents(0L,0L,(LPVOID)report); break; case MotionNotify: msgstr = "MotionNotify"; msgposted = DrvWindowsEvents(0L,0L,(LPVOID)report); break; case KeyPress: msgstr = "KeyPress"; msgposted = DrvHandleKeyboardEvents(0L,0L,(LPVOID)report); break; case KeyRelease: msgstr = "KeyRelease"; msgposted = DrvHandleKeyboardEvents(0L,0L,(LPVOID)report); break; case EnterNotify: msgstr = "EnterNotify"; if (XFindContext(dp->display,report->xcrossing.window, dp->client_hwnd,(caddr_t *)&dwClientWin)) break; XFindContext(dp->display,report->xcrossing.window, dp->window_style,(caddr_t *)&dwStyle); if ((dwStyle & WS_CAPTION) != WS_CAPTION) { XGetInputFocus(dp->display,&win,&revert_return); if (win != report->xcrossing.window) { XSetInputFocus(dp->display,report->xcrossing.window, revert_return,CurrentTime); } } break; case LeaveNotify: msgstr = "LeaveNotify"; if (XFindContext(dp->display,report->xcrossing.window, dp->client_hwnd,(caddr_t *)&dwClientWin)) break; XFindContext(dp->display,report->xcrossing.window, dp->window_style,(caddr_t *)&dwStyle); if ((dwStyle & WS_CAPTION) != WS_CAPTION) { XGetInputFocus(dp->display,&win_focus,&revert_return); if (win && (win != report->xcrossing.window)) { if (win != RootWindow(dp->display,dp->screen)) { XSetInputFocus(dp->display,win, revert_return,CurrentTime); } else { XSetInputFocus(dp->display,PointerRoot, 0,CurrentTime); } } win = 0; } break; case FocusIn: msgstr = "FocusIn"; case FocusOut: if(msgstr == 0) msgstr = "FocusOut"; if (XFindContext(dp->display,report->xfocus.window, dp->client_hwnd,(caddr_t *)&dwClientWin)) break; hWndFrame = HIWORD(dwClientWin); lpLibCallback(TWINLIBCALLBACK_FOCUS,(LPARAM)hWndFrame, IFC_DRIVERFOCUS, (LPVOID)(report->type == FocusIn)); msgposted--; break; case KeymapNotify: msgstr = "KeymapNotify"; /* this could/should be used to update us on the current * state of the keyboard. Can it be different from what * we know about it? Yes, we could have keydown somewhere * and keyup in our space... */ break; case VisibilityNotify: msgstr = "VisibilityNotify"; /* * The following function call prints the entire tree of * windows known to X11. It is commented out because it * is far too wordy in most debugging situations. */ DrvPrintTree(dp, XRootWindow(dp->display, dp->screen)); if (XFindContext(dp->display, report->xvisibility.window, dp->client_hwnd, (caddr_t *)&dwClientWin)) break; hWnd = (HWND)LOWORD(dwClientWin); switch (report->xvisibility.state) { case VisibilityUnobscured: case VisibilityPartiallyObscured: SetWF(hWnd,WFVISIBILITY); break; case VisibilityFullyObscured: ClearWF(hWnd,WFVISIBILITY); break; } msgposted--; break; case CreateNotify: msgstr = "CreateNotify"; break; case DestroyNotify: msgstr = "DestroyNotify"; break; case MappingNotify: msgstr = "MappingNotify"; XRefreshKeyboardMapping((XMappingEvent *)report); break; case MapNotify: msgstr = "MapNotify"; #ifdef DEBUG if (XFindContext(dp->display,report->xmap.window, dp->client_hwnd,(caddr_t *)&dwClientWin)) break; hWnd = HIWORD(dwClientWin); #endif break; case UnmapNotify: msgstr = "UnmapNotify"; if (XFindContext(dp->display,report->xunmap.window, dp->client_hwnd,(caddr_t *)&dwClientWin)) break; hWnd = HIWORD(dwClientWin); ClearWF(hWnd, WFMAPPED); break; case CirculateNotify: msgstr = "CirculateNotify"; break; case CirculateRequest: msgstr = "CirculateRequest"; break; case NoExpose: msgstr = "NoExpose"; break; default: msgstr = "UNKNOWN"; break; } /* end switch */ return msgposted; }
int _ev_thread(int args, void* argp){ LibGE_LinuxContext* context = (LibGE_LinuxContext*)argp; u32 ticks = geGetTick(); bool finished = false; int key = 0; if(wheel_j == -1){ while(wheel_i == -1); wheel_j = 0; } while(1){ // mouse_warp_x = mouse_warp_y = 0; while(XPending(context->dpy)){ XNextEvent(context->dpy, &event); // if(event.type)printf("event: %d\n", event.type); if((event.type == ButtonPress || event.type == ButtonRelease) && (event.xbutton.button == GEK_MWHEELUP || event.xbutton.button == GEK_MWHEELDOWN)){ memcpy(&wheel_ev[wheel_j], &event.xbutton, sizeof(XButtonEvent)); wheel_j = (wheel_j + 1) % 32; } switch (event.type){ case ClientMessage: if (*XGetAtomName(context->dpy, event.xclient.message_type) == *"WM_PROTOCOLS"){ finished = true; } if (event.xclient.data.l[0] == XInternAtom(context->dpy, "WM_DELETE_WINDOW", False)){ finished = true; } break; case ConfigureNotify: new_w = event.xconfigure.width; new_h = event.xconfigure.height; break; /* case ConfigureNotify: if(event.xexpose.width!=libge_context->width || event.xexpose.height!=libge_context->height){ libge_context->width = event.xconfigure.width; libge_context->height = event.xconfigure.height; libge_context->projection_matrix[0] = (float)0xFFFFFFFF; geGraphicsInit(); geDrawingMode(libge_context->drawing_mode | 0xF0000000); } break; */ case KeymapNotify: XRefreshKeyboardMapping(&event.xmapping); break; case KeyPress: key = (int)XLookupKeysym(&event.xkey, 0); if(key == XK_ISO_Level3_Shift){ key = XK_Alt_L; } if(key >= 0xFF00){ key -= 0xFF00; } if(key >= 'a' && key <= 'z'){ key += ('A' - 'a'); } { char str[25]; int len; KeySym keysym; len = XLookupString(&event.xkey, str, 25, &keysym, NULL); last_pressed = (u8)str[0]; printf("key : %X %X\n", key, last_pressed); } keys_pressed[key] = true; keys_released[key] = false; if(keys_pressed[GEK_LALT] && keys_pressed[GEK_F4]){ finished = true; } break; case KeyRelease: key = (int)XLookupKeysym(&event.xkey, 0); if(key >= 0xFF00){ key -= 0xFF00; } if(key <= 0xFF){ if(key >= 'a' && key <= 'z'){ key += ('A' - 'a'); } keys_pressed[key] = false; keys_released[key] = true; } break; case ButtonPress: if(event.xbutton.button == GEK_MWHEELUP){ wup = 1; }else if(event.xbutton.button == GEK_MWHEELDOWN){ wdown = 1; }else{ keys_pressed[event.xbutton.button] = true; keys_released[event.xbutton.button] = false; } break; case ButtonRelease: if(event.xbutton.button == GEK_MWHEELUP){ pending_wup_release = true; }else if(event.xbutton.button == GEK_MWHEELDOWN){ pending_wdown_release = true; }else{ keys_pressed[event.xbutton.button] = false; keys_released[event.xbutton.button] = true; } break; case MotionNotify: /* if(changed){ changed = false; continue; } if(libge_context->mouse_round){ if(reset){ warp_x = warp_y = 0; reset = false; } warp_x += event.xmotion.x - libge_context->width / 2; warp_y += event.xmotion.y - libge_context->height / 2; libge_context->mouse_x = libge_context->width / 2; libge_context->mouse_y = libge_context->height / 2; changed = true; XWarpPointer(context->dpy, context->win, context->win, 0, 0, 0, 0, libge_context->mouse_x, libge_context->mouse_y); }else{ mouse_last_x = libge_context->mouse_x; mouse_last_y = libge_context->mouse_y; libge_context->mouse_x = event.xmotion.x; libge_context->mouse_y = event.xmotion.y; mouse_warp_x = libge_context->mouse_x-mouse_last_x; mouse_warp_y = libge_context->mouse_y-mouse_last_y; } */ break; default: break; } } if(finished){ _to_close = true; finished = false; geSleep(1000); exit(0); } ticks = geWaitTick(1000 / 120, ticks); } return 0; }
void caml_gr_handle_event(XEvent * event) { switch (event->type) { case Expose: XCopyArea(caml_gr_display, caml_gr_bstore.win, caml_gr_window.win, caml_gr_window.gc, event->xexpose.x, event->xexpose.y + caml_gr_bstore.h - caml_gr_window.h, event->xexpose.width, event->xexpose.height, event->xexpose.x, event->xexpose.y); XFlush(caml_gr_display); break; case ConfigureNotify: caml_gr_window.w = event->xconfigure.width; caml_gr_window.h = event->xconfigure.height; if (caml_gr_window.w > caml_gr_bstore.w || caml_gr_window.h > caml_gr_bstore.h) { /* Allocate a new backing store large enough to accomodate both the old backing store and the current window. */ struct canvas newbstore; newbstore.w = max(caml_gr_window.w, caml_gr_bstore.w); newbstore.h = max(caml_gr_window.h, caml_gr_bstore.h); newbstore.win = XCreatePixmap(caml_gr_display, caml_gr_window.win, newbstore.w, newbstore.h, XDefaultDepth(caml_gr_display, caml_gr_screen)); newbstore.gc = XCreateGC(caml_gr_display, newbstore.win, 0, NULL); XSetBackground(caml_gr_display, newbstore.gc, caml_gr_white); XSetForeground(caml_gr_display, newbstore.gc, caml_gr_white); XFillRectangle(caml_gr_display, newbstore.win, newbstore.gc, 0, 0, newbstore.w, newbstore.h); XSetForeground(caml_gr_display, newbstore.gc, caml_gr_color); if (caml_gr_font != NULL) XSetFont(caml_gr_display, newbstore.gc, caml_gr_font->fid); /* Copy the old backing store into the new one */ XCopyArea(caml_gr_display, caml_gr_bstore.win, newbstore.win, newbstore.gc, 0, 0, caml_gr_bstore.w, caml_gr_bstore.h, 0, newbstore.h - caml_gr_bstore.h); /* Free the old backing store */ XFreeGC(caml_gr_display, caml_gr_bstore.gc); XFreePixmap(caml_gr_display, caml_gr_bstore.win); /* Use the new backing store */ caml_gr_bstore = newbstore; XFlush(caml_gr_display); } break; case MappingNotify: XRefreshKeyboardMapping(&(event->xmapping)); break; case KeyPress: { KeySym thekey; char keytxt[256]; int nchars; char * p; nchars = XLookupString(&(event->xkey), keytxt, sizeof(keytxt), &thekey, 0); for (p = keytxt; nchars > 0; p++, nchars--) caml_gr_enqueue_event(event->type, event->xkey.x, event->xkey.y, BUTTON_STATE(event->xkey.state), *p); break; } case ButtonPress: case ButtonRelease: caml_gr_enqueue_event(event->type, event->xbutton.x, event->xbutton.y, event->type == ButtonPress, 0); break; case MotionNotify: caml_gr_enqueue_event(event->type, event->xmotion.x, event->xmotion.y, BUTTON_STATE(event->xmotion.state), 0); break; } }
void* eventProc(void* ptr) { XEvent event; CXlibToolkit *toolkit = (CXlibToolkit*)ptr; bool stopThread = false; unsigned int time = 0; while (!stopThread) { XNextEvent(toolkit->display, &event); if (event.xany.display != toolkit->display || event.xany.window != toolkit->window) { continue; } switch (event.type) { case ButtonPress: { XButtonEvent *e = (XButtonEvent*)&event; switch (e->button) { case 1: if (e->time - time > 400) { toolkit->editor->OnLButtonDown(e->x, e->y); } else { toolkit->editor->OnLButtonDblClick(e->x, e->y); } time = e->time; break; case 4: toolkit->editor->OnMouseWheel(e->x, e->y, 1); break; case 5: toolkit->editor->OnMouseWheel(e->x, e->y, -1); break; } break; } case ButtonRelease: { toolkit->editor->OnLButtonUp(); break; } case MotionNotify: { XMotionEvent *e = (XMotionEvent*)&event; toolkit->editor->OnMouseMove(e->x, e->y); break; } case KeyPress: { char buffer[64]; int count = XLookupString((XKeyEvent*)&event, buffer, sizeof(buffer), NULL, NULL); if (buffer[0]) { toolkit->editor->OnChar(buffer[0]); } break; } case MappingNotify: { XRefreshKeyboardMapping((XMappingEvent*)&event); break; } case Expose: { XGraphicsExposeEvent *e = (XGraphicsExposeEvent*)&event; XCopyArea(toolkit->display, toolkit->offscreen, toolkit->window, toolkit->gc, e->x, e->y, e->width, e->height, e->x, e->y); break; } case ClientMessage: { XClientMessageEvent *message = (XClientMessageEvent *)&event; if (message->data.l[0] == toolkit->WM_DELETE_WINDOW) { stopThread = true; break; } else if (message->data.l[0] == toolkit->WM_TIMER) { toolkit->editor->Update(); } } } } toolkit->thread1Finished = true; return NULL; }
static void processEventsAndTimeouts(void) { do { #if defined(_WIN32) MSG event; if(!GetMessage(&event, NULL, 0, 0)) /* bail if no more messages */ exit(0); TranslateMessage(&event); /* translate virtual-key messages */ DispatchMessage(&event); /* call the window proc */ /* see win32_event.c for event (message) processing procedures */ #else static int mappedMenuButton; GLUTeventParser *parser; XEvent event, ahead; GLUTwindow *window; GLUTkeyboardCB keyboard; GLUTspecialCB special; int gotEvent, width, height; gotEvent = interruptibleXNextEvent(__glutDisplay, &event); if (gotEvent) { switch (event.type) { case MappingNotify: XRefreshKeyboardMapping((XMappingEvent *) & event); break; case ConfigureNotify: window = __glutGetWindow(event.xconfigure.window); if (window) { if (window->win != event.xconfigure.window) { /* Ignore ConfigureNotify sent to the overlay planes. GLUT could get here because overlays select for StructureNotify events to receive DestroyNotify. */ break; } width = event.xconfigure.width; height = event.xconfigure.height; if (width != window->width || height != window->height) { if (window->overlay) { XResizeWindow(__glutDisplay, window->overlay->win, width, height); } window->width = width; window->height = height; __glutSetWindow(window); /* Do not execute OpenGL out of sequence with respect to the XResizeWindow request! */ glXWaitX(); window->reshape(width, height); window->forceReshape = False; /* A reshape should be considered like posting a repair; this is necessary for the "Mesa glXSwapBuffers to repair damage" hack to operate correctly. Without it, there's not an initial back buffer render from which to blit from when damage happens to the window. */ __glutPostRedisplay(window, GLUT_REPAIR_WORK); } } break; case Expose: /* compress expose events */ while (XEventsQueued(__glutDisplay, QueuedAfterReading) > 0) { XPeekEvent(__glutDisplay, &ahead); if (ahead.type != Expose || ahead.xexpose.window != event.xexpose.window) { break; } XNextEvent(__glutDisplay, &event); } if (event.xexpose.count == 0) { GLUTmenu *menu; if (__glutMappedMenu && (menu = __glutGetMenu(event.xexpose.window))) { __glutPaintMenu(menu); } else { window = __glutGetWindow(event.xexpose.window); if (window) { if (window->win == event.xexpose.window) { __glutPostRedisplay(window, GLUT_REPAIR_WORK); } else if (window->overlay && window->overlay->win == event.xexpose.window) { __glutPostRedisplay(window, GLUT_OVERLAY_REPAIR_WORK); } } } } else { /* there are more exposes to read; wait to redisplay */ } break; case ButtonPress: case ButtonRelease: if (__glutMappedMenu && event.type == ButtonRelease && mappedMenuButton == event.xbutton.button) { /* Menu is currently popped up and its button is released. */ __glutFinishMenu(event.xbutton.window, event.xbutton.x, event.xbutton.y); } else { window = __glutGetWindow(event.xbutton.window); /* added button check for mice with > 3 buttons */ if (window) { GLUTmenu *menu; int menuNum; if (event.xbutton.button <= GLUT_MAX_MENUS) menuNum = window->menu[event.xbutton.button - 1]; else menuNum = 0; /* Make sure that __glutGetMenuByNum is only called if there really is a menu present. */ if ((menuNum > 0) && (menu = __glutGetMenuByNum(menuNum))) { if (event.type == ButtonPress && !__glutMappedMenu) { __glutStartMenu(menu, window, event.xbutton.x_root, event.xbutton.y_root, event.xbutton.x, event.xbutton.y); mappedMenuButton = event.xbutton.button; } else { /* Ignore a release of a button with a menu attatched to it when no menu is popped up, or ignore a press when another menu is already popped up. */ } } else if (window->mouse) { __glutSetWindow(window); __glutModifierMask = event.xbutton.state; window->mouse(event.xbutton.button - 1, event.type == ButtonRelease ? GLUT_UP : GLUT_DOWN, event.xbutton.x, event.xbutton.y); __glutModifierMask = ~0; } else { /* Stray mouse events. Ignore. */ } } else { /* Window might have been destroyed and all the events for the window may not yet be received. */ } } break; case MotionNotify: if (!__glutMappedMenu) { window = __glutGetWindow(event.xmotion.window); if (window) { /* If motion function registered _and_ buttons held * down, call motion function... */ if (window->motion && event.xmotion.state & (Button1Mask | Button2Mask | Button3Mask)) { __glutSetWindow(window); window->motion(event.xmotion.x, event.xmotion.y); } /* If passive motion function registered _and_ buttons not held down, call passive motion function... */ else if (window->passive && ((event.xmotion.state & (Button1Mask | Button2Mask | Button3Mask)) == 0)) { __glutSetWindow(window); window->passive(event.xmotion.x, event.xmotion.y); } } } else { /* Motion events are thrown away when a pop up menu is active. */ } break; case KeyPress: case KeyRelease: window = __glutGetWindow(event.xkey.window); if (!window) { break; } if (event.type == KeyPress) { keyboard = window->keyboard; } else { /* If we are ignoring auto repeated keys for this window, check if the next event in the X event queue is a KeyPress for the exact same key (and at the exact same time) as the key being released. The X11 protocol will send auto repeated keys as such KeyRelease/KeyPress pairs. */ if (window->ignoreKeyRepeat) { if (XEventsQueued(__glutDisplay, QueuedAfterReading)) { XPeekEvent(__glutDisplay, &ahead); if (ahead.type == KeyPress && ahead.xkey.window == event.xkey.window && ahead.xkey.keycode == event.xkey.keycode && ahead.xkey.time == event.xkey.time) { /* Pop off the repeated KeyPress and ignore the auto repeated KeyRelease/KeyPress pair. */ XNextEvent(__glutDisplay, &event); break; } } } keyboard = window->keyboardUp; } if (keyboard) { char tmp[1]; int rc; rc = XLookupString(&event.xkey, tmp, sizeof(tmp), NULL, NULL); if (rc) { __glutSetWindow(window); __glutModifierMask = event.xkey.state; keyboard(tmp[0], event.xkey.x, event.xkey.y); __glutModifierMask = ~0; break; } } if (event.type == KeyPress) { special = window->special; } else { special = window->specialUp; } if (special) { KeySym ks; int key; /* Introduced in X11R6: (Partial list of) Keypad Functions. Define in place in case compiling against an older pre-X11R6 X11/keysymdef.h file. */ #ifndef XK_KP_Home #define XK_KP_Home 0xFF95 #endif #ifndef XK_KP_Left #define XK_KP_Left 0xFF96 #endif #ifndef XK_KP_Up #define XK_KP_Up 0xFF97 #endif #ifndef XK_KP_Right #define XK_KP_Right 0xFF98 #endif #ifndef XK_KP_Down #define XK_KP_Down 0xFF99 #endif #ifndef XK_KP_Prior #define XK_KP_Prior 0xFF9A #endif #ifndef XK_KP_Next #define XK_KP_Next 0xFF9B #endif #ifndef XK_KP_End #define XK_KP_End 0xFF9C #endif #ifndef XK_KP_Insert #define XK_KP_Insert 0xFF9E #endif #ifndef XK_KP_Delete #define XK_KP_Delete 0xFF9F #endif ks = XLookupKeysym((XKeyEvent *) & event, 0); /* XXX Verbose, but makes no assumptions about keysym layout. */ switch (ks) { /* *INDENT-OFF* */ /* function keys */ case XK_F1: key = GLUT_KEY_F1; break; case XK_F2: key = GLUT_KEY_F2; break; case XK_F3: key = GLUT_KEY_F3; break; case XK_F4: key = GLUT_KEY_F4; break; case XK_F5: key = GLUT_KEY_F5; break; case XK_F6: key = GLUT_KEY_F6; break; case XK_F7: key = GLUT_KEY_F7; break; case XK_F8: key = GLUT_KEY_F8; break; case XK_F9: key = GLUT_KEY_F9; break; case XK_F10: key = GLUT_KEY_F10; break; case XK_F11: key = GLUT_KEY_F11; break; case XK_F12: key = GLUT_KEY_F12; break; /* directional keys */ case XK_KP_Left: case XK_Left: key = GLUT_KEY_LEFT; break; case XK_KP_Up: /* Introduced in X11R6. */ case XK_Up: key = GLUT_KEY_UP; break; case XK_KP_Right: /* Introduced in X11R6. */ case XK_Right: key = GLUT_KEY_RIGHT; break; case XK_KP_Down: /* Introduced in X11R6. */ case XK_Down: key = GLUT_KEY_DOWN; break; /* *INDENT-ON* */ case XK_KP_Prior: /* Introduced in X11R6. */ case XK_Prior: /* XK_Prior same as X11R6's XK_Page_Up */ key = GLUT_KEY_PAGE_UP; break; case XK_KP_Next: /* Introduced in X11R6. */ case XK_Next: /* XK_Next same as X11R6's XK_Page_Down */ key = GLUT_KEY_PAGE_DOWN; break; case XK_KP_Home: /* Introduced in X11R6. */ case XK_Home: key = GLUT_KEY_HOME; break; #ifdef __hpux case XK_Select: #endif case XK_KP_End: /* Introduced in X11R6. */ case XK_End: key = GLUT_KEY_END; break; #ifdef __hpux case XK_InsertChar: #endif case XK_KP_Insert: /* Introduced in X11R6. */ case XK_Insert: key = GLUT_KEY_INSERT; break; #ifdef __hpux case XK_DeleteChar: #endif case XK_KP_Delete: /* Introduced in X11R6. */ /* The Delete character is really an ASCII key. */ __glutSetWindow(window); keyboard(127, /* ASCII Delete character. */ event.xkey.x, event.xkey.y); goto skip; default: goto skip; } __glutSetWindow(window); __glutModifierMask = event.xkey.state; special(key, event.xkey.x, event.xkey.y); __glutModifierMask = ~0; skip:; } break; case EnterNotify: case LeaveNotify: if (event.xcrossing.mode != NotifyNormal || event.xcrossing.detail == NotifyNonlinearVirtual || event.xcrossing.detail == NotifyVirtual) { /* Careful to ignore Enter/LeaveNotify events that come from the pop-up menu pointer grab and ungrab. Also, ignore "virtual" Enter/LeaveNotify events since they represent the pointer passing through the window hierarchy without actually entering or leaving the actual real estate of a window. */ break; } if (__glutMappedMenu) { GLUTmenuItem *item; int num; item = __glutGetMenuItem(__glutMappedMenu, event.xcrossing.window, &num); if (item) { __glutMenuItemEnterOrLeave(item, num, event.type); break; } } window = __glutGetWindow(event.xcrossing.window); if (window) { if (window->entry) { if (event.type == EnterNotify) { /* With overlays established, X can report two enter events for both the overlay and normal plane window. Do not generate a second enter callback if we reported one without an intervening leave. */ if (window->entryState != EnterNotify) { int num = window->num; Window xid = window->win; window->entryState = EnterNotify; __glutSetWindow(window); window->entry(GLUT_ENTERED); if (__glutMappedMenu) { /* Do not generate any passive motion events when menus are in use. */ } else { /* An EnterNotify event can result in a "compound" callback if a passive motion callback is also registered. In this case, be a little paranoid about the possibility the window could have been destroyed in the entry callback. */ window = __glutWindowList[num]; if (window && window->passive && window->win == xid) { __glutSetWindow(window); window->passive(event.xcrossing.x, event.xcrossing.y); } } } } else { if (window->entryState != LeaveNotify) { /* When an overlay is established for a window already mapped and with the pointer in it, the X server will generate a leave/enter event pair as the pointer leaves (without moving) from the normal plane X window to the newly mapped overlay X window (or vice versa). This enter/leave pair should not be reported to the GLUT program since the pair is a consequence of creating (or destroying) the overlay, not an actual leave from the GLUT window. */ if (XEventsQueued(__glutDisplay, QueuedAfterReading)) { XPeekEvent(__glutDisplay, &ahead); if (ahead.type == EnterNotify && __glutGetWindow(ahead.xcrossing.window) == window) { XNextEvent(__glutDisplay, &event); break; } } window->entryState = LeaveNotify; __glutSetWindow(window); window->entry(GLUT_LEFT); } } } else if (window->passive) { __glutSetWindow(window); window->passive(event.xcrossing.x, event.xcrossing.y); } } break; case UnmapNotify: /* MapNotify events are not needed to maintain visibility state since VisibilityNotify events will be delivered when a window becomes visible from mapping. However, VisibilityNotify events are not delivered when a window is unmapped (for the window or its children). */ window = __glutGetWindow(event.xunmap.window); if (window) { if (window->win != event.xconfigure.window) { /* Ignore UnmapNotify sent to the overlay planes. GLUT could get here because overlays select for StructureNotify events to receive DestroyNotify. */ break; } markWindowHidden(window); } break; case VisibilityNotify: window = __glutGetWindow(event.xvisibility.window); if (window) { /* VisibilityUnobscured+1 = GLUT_FULLY_RETAINED, VisibilityPartiallyObscured+1 = GLUT_PARTIALLY_RETAINED, VisibilityFullyObscured+1 = GLUT_FULLY_COVERED. */ int visState = event.xvisibility.state + 1; if (visState != window->visState) { if (window->windowStatus) { window->visState = visState; __glutSetWindow(window); window->windowStatus(visState); } } } break; case ClientMessage: if (event.xclient.data.l[0] == __glutWMDeleteWindow) exit(0); break; case DestroyNotify: purgeStaleWindow(event.xdestroywindow.window); break; case CirculateNotify: case CreateNotify: case GravityNotify: case ReparentNotify: /* Uninteresting to GLUT (but possible for GLUT to receive). */ break; default: /* Pass events not directly handled by the GLUT main event loop to any event parsers that have been registered. In this way, X Input extension events are passed to the correct handler without forcing all GLUT programs to support X Input event handling. */ parser = eventParserList; while (parser) { if (parser->func(&event)) break; parser = parser->next; } break; } } #endif /* _WIN32 */ if (__glutTimerList) { handleTimeouts(); } } while (XPending(__glutDisplay)); }
/* read an X event */ void ReadXServer () { static XEvent event,evnt_sel; int i; char *octet; while (XEventsQueued(x11base->display, QueuedAfterReading)) { XNextEvent(x11base->display, &event); switch (event.type) { case Expose: if (event.xexpose.count==0) for (i=0;i<nbobj;i++) tabxobj[i]->DrawObj(tabxobj[i]); break; case KeyPress: /* Touche presse dans un objet */ if (event.xkey.subwindow!=0) { /* Envoi de l'evt à l'objet */ for (i=0;i<nbobj;i++) if (tabxobj[i]->win==event.xkey.subwindow) tabxobj[i]->EvtKey(tabxobj[i],&event.xkey); } break; case ButtonPress: /* Clique dans quel fenetre? */ if (event.xbutton.subwindow!=0) { i=0; while ((tabxobj[i]->win!=event.xbutton.subwindow)&&(i<nbobj-1)) i++; tabxobj[i]->EvtMouse(tabxobj[i],&event.xbutton); } break; case ButtonRelease: break; case EnterNotify: break; case LeaveNotify: break; case MotionNotify: break; case MappingNotify: XRefreshKeyboardMapping((XMappingEvent*)&event); break; case SelectionRequest: if (event.xselectionrequest.selection==XA_PRIMARY) { evnt_sel.type=SelectionNotify; evnt_sel.xselection.requestor=event.xselectionrequest.requestor; evnt_sel.xselection.selection=event.xselectionrequest.selection; evnt_sel.xselection.target=event.xselectionrequest.target; evnt_sel.xselection.time=event.xselectionrequest.time; evnt_sel.xselection.property=event.xselectionrequest.property; switch (event.xselectionrequest.target) { case XA_STRING: XChangeProperty(x11base->display,evnt_sel.xselection.requestor, evnt_sel.xselection.property, evnt_sel.xselection.target, 8,PropModeReplace,Scrapt,strlen(Scrapt)+1); break; default:evnt_sel.xselection.property=None; } XSendEvent(x11base->display,evnt_sel.xselection.requestor,False,0,&evnt_sel); } else SendMsgToScript(event); break; case SelectionClear: if (event.xselectionclear.selection==XA_PRIMARY) UnselectAllTextField(tabxobj); break; case ClientMessage: if ((event.xclient.format==32) && (event.xclient.data.l[0]==wm_del_win)) DeadPipe(1); break; case PropertyNotify: if (event.xproperty.atom==XA_CUT_BUFFER0) octet=XFetchBuffer(x11base->display,&i,0); else if (event.xproperty.atom==XA_CUT_BUFFER1) octet=XFetchBuffer(x11base->display,&i,1); else if (event.xproperty.atom==XA_CUT_BUFFER2) octet=XFetchBuffer(x11base->display,&i,2); else if (event.xproperty.atom==XA_CUT_BUFFER3) octet=XFetchBuffer(x11base->display,&i,3); else if (event.xproperty.atom==XA_CUT_BUFFER4) octet=XFetchBuffer(x11base->display,&i,4); else if (event.xproperty.atom==XA_CUT_BUFFER5) octet=XFetchBuffer(x11base->display,&i,5); else if (event.xproperty.atom==XA_CUT_BUFFER6) octet=XFetchBuffer(x11base->display,&i,6); else if (event.xproperty.atom==XA_CUT_BUFFER7) octet=XFetchBuffer(x11base->display,&i,7); else break; if (i>0) { Scrapt=(char*)realloc((void*)Scrapt,sizeof(char)*(i+1)); Scrapt=strcpy(Scrapt,octet); } break; } } }
bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server) { if (!server) server=&_InternalServer; XWindowAttributes xwa; XGetWindowAttributes (_dpy, _win, &xwa); switch (event.type) { case ButtonPress: { //nlinfo("%d %d %d", event.xbutton.button, event.xbutton.x, event.xbutton.y); float fX = (float) event.xbutton.x / (float) xwa.width; float fY = 1.0f - (float) event.xbutton.y / (float) xwa.height; TMouseButton button=getMouseButton(event.xbutton.state); switch(event.xbutton.button) { case Button1: server->postEvent(new CEventMouseDown(fX, fY, (TMouseButton)(leftButton|(button&~(leftButton|middleButton|rightButton))), this)); break; case Button2: server->postEvent(new CEventMouseDown(fX, fY, (TMouseButton)(middleButton|(button&~(leftButton|middleButton|rightButton))), this)); break; case Button3: server->postEvent(new CEventMouseDown(fX, fY, (TMouseButton)(rightButton|(button&~(leftButton|middleButton|rightButton))), this)); break; case Button4: server->postEvent(new CEventMouseWheel(fX, fY, button, true, this)); break; case Button5: server->postEvent(new CEventMouseWheel(fX, fY, button, false, this)); break; } break; } case ButtonRelease: { //nlinfo("%d %d %d", event.xbutton.button, event.xbutton.x, event.xbutton.y); float fX = (float) event.xbutton.x / (float) xwa.width; float fY = 1.0f - (float) event.xbutton.y / (float) xwa.height; switch(event.xbutton.button) { case Button1: server->postEvent(new CEventMouseUp(fX, fY, leftButton, this)); break; case Button2: server->postEvent(new CEventMouseUp(fX, fY, middleButton, this)); break; case Button3: server->postEvent(new CEventMouseUp(fX, fY, rightButton, this)); break; } break; } case MotionNotify: { TMouseButton button=getMouseButton (event.xbutton.state); // if raw mode should be emulated if(_emulateRawMode) { // when we just wrapped back the pointer to 0.5 / 0.5, ignore event if(event.xbutton.x == xwa.width / 2 && event.xbutton.y == xwa.height / 2) break; // post a CGDMouseMove with the movement delta to the event server server->postEvent( new CGDMouseMove(this, NULL /* no mouse device */, event.xbutton.x - (xwa.width / 2), (xwa.height / 2) - event.xbutton.y)); // move the pointer back to the center of the window XWarpPointer(_dpy, None, _win, None, None, None, None, (xwa.width / 2), (xwa.height / 2)); } // if in normal mouse mode else { // get the relative mouse position float fX = (float) event.xbutton.x / (float) xwa.width; float fY = 1.0f - (float) event.xbutton.y / (float) xwa.height; // post a normal mouse move event to the event server server->postEvent (new CEventMouseMove (fX, fY, button, this)); } break; } case KeyPress: { // save keycode because XFilterEvent could set it to 0 uint keyCode = event.xkey.keycode; KeySym k; static char Text[256]; int c = 0; // check if event is filtered bool filtered = XFilterEvent(&event, _win); // if key event is filtered, we shouldn't use XLookupString to retrieve KeySym if (!filtered) { Status status = XLookupNone; #ifdef X_HAVE_UTF8_STRING if (_ic) c = Xutf8LookupString(_ic, &event.xkey, Text, sizeof(Text), &k, &status); #endif if (status == XLookupNone) c = XLookupString(&event.xkey, Text, sizeof(Text), &k, NULL); } else { k = XKeycodeToKeysym(_dpy, keyCode, 0); } // send CEventKeyDown event only if keyCode is defined if (keyCode) { TKey key = getKeyFromKeySym(k); if(key == KeyNOKEY) key = getKeyFromKeycode(keyCode); // search for key in map std::map<TKey, bool>::const_iterator it = _PressedKeys.find(key); // if key is not found or value is false, that's the first time bool firstTime = (it == _PressedKeys.end()) || !it->second; server->postEvent (new CEventKeyDown (key, getKeyButton(event.xbutton.state), firstTime, this)); _PressedKeys[key] = true; // don't send a control character when deleting if (key == KeyDELETE) c = 0; } Text[c] = '\0'; if(c>0) { #ifdef X_HAVE_UTF8_STRING ucstring ucstr; ucstr.fromUtf8(Text); CEventChar *charEvent = new CEventChar (ucstr[0], getKeyButton(event.xbutton.state), this); // raw if not processed by IME charEvent->setRaw(keyCode != 0); server->postEvent (charEvent); #else for (int i = 0; i < c; i++) { CEventChar *charEvent = new CEventChar ((ucchar)(unsigned char)Text[i], getKeyButton(event.xbutton.state), this); // raw if not processed by IME charEvent->setRaw(keyCode != 0); server->postEvent (charEvent); } #endif } break; } case KeyRelease: { if (!keyRepeat(_dpy, &event)) { KeySym k; // only need to get correct KeySym int c = XLookupString(&event.xkey, NULL, 0, &k, NULL); TKey key = getKeyFromKeySym(k); if(key == KeyNOKEY) key = getKeyFromKeycode(event.xkey.keycode); server->postEvent (new CEventKeyUp (key, getKeyButton(event.xbutton.state), this)); _PressedKeys[key] = false; } break; } case SelectionRequest: { XEvent respond; XSelectionRequestEvent req = event.xselectionrequest; respond.xselection.type= SelectionNotify; respond.xselection.display= req.display; respond.xselection.requestor= req.requestor; respond.xselection.selection=req.selection; respond.xselection.target= req.target; respond.xselection.time = req.time; respond.xselection.property = req.property; if (req.property == None) { respond.xselection.property = req.target; } if (req.target == XA_TARGETS) { Atom targets[] = { XA_TARGETS, XA_STRING, XA_UTF8_STRING }; respond.xselection.property = req.property; XChangeProperty(req.display, req.requestor, req.property, XA_ATOM, 32, PropModeReplace, (unsigned char *)targets, 3 /* number of element */); } else if (req.target == XA_STRING) { respond.xselection.property = req.property; std::string str = _CopiedString.toString(); XChangeProperty(req.display, req.requestor, req.property, XA_STRING, 8, PropModeReplace, (const unsigned char*)str.c_str(), str.length()); } else if (req.target == XA_UTF8_STRING) { respond.xselection.property = req.property; std::string str = _CopiedString.toUtf8(); XChangeProperty(req.display, req.requestor, respond.xselection.property, XA_UTF8_STRING, 8, PropModeReplace, (const unsigned char*)str.c_str(), str.length()); } else { // Note: Calling XGetAtomName with arbitrary value crash the client, maybe req.target have been sanitized by X11 server respond.xselection.property = None; } XSendEvent (_dpy, req.requestor, 0, 0, &respond); break; } case SelectionClear: _SelectionOwned = false; _CopiedString = ""; break; case SelectionNotify: { Atom target = event.xselection.target; Atom actualType = 0; int actualFormat = 0; unsigned long nitems = 0, bytesLeft = 0; // some applications are sending ATOM and other TARGETS if (target == XA_TARGETS || target == XA_ATOM) { Atom *supportedTargets = NULL; // list NeL selection properties if (XGetWindowProperty(_dpy, _win, XA_NEL_SEL, 0, XMaxRequestSize(_dpy), False, AnyPropertyType, &actualType, &actualFormat, &nitems, &bytesLeft, (unsigned char**)&supportedTargets) != Success) return false; if (bytesLeft > 0) { nlwarning("Paste: Supported TARGETS list too long."); } Atom bestTarget = 0; sint bestTargetElect = 0; // Elect best type for (uint i=0; i < nitems; i++) { // nlwarning(" - Type=%s (%u)", XGetAtomName(_dpy, supportedTargets[i]), (uint)supportedTargets[i]); if (supportedTargets[i] == XA_UTF8_STRING ) { if (bestTargetElect < 2) { bestTarget = XA_UTF8_STRING; bestTargetElect = 2; } } else if (supportedTargets[i] == XA_STRING ) { if (bestTargetElect < 1) { bestTarget = XA_STRING; bestTargetElect = 1; } } } XFree(supportedTargets); if (!bestTargetElect) { nlwarning("Paste buffer is not a text buffer."); return false; } // request string conversion XConvertSelection(_dpy, XA_CLIPBOARD, bestTarget, XA_NEL_SEL, _win, CurrentTime); } else if (target == XA_UTF8_STRING || target == XA_STRING) { uint8 *data = NULL; // get selection if (XGetWindowProperty(_dpy, _win, XA_NEL_SEL, 0, XMaxRequestSize(_dpy), False, AnyPropertyType, &actualType, &actualFormat, &nitems, &bytesLeft, (unsigned char**)&data) != Success) return false; ucstring text; std::string tmpData = (const char*)data; XFree(data); // convert buffer to ucstring if (target == XA_UTF8_STRING) { text = ucstring::makeFromUtf8(tmpData); } else if (target == XA_STRING) { text = tmpData; } else { nlwarning("Unknow format %u", (uint)target); } // sent string event to event server server->postEvent (new CEventString (text, this)); } else { nlwarning("Unknow target %u", (uint)target); } break; } case FocusIn: // keyboard focus // server->postEvent (new CEventSetFocus (true, this)); if (_ic) XSetICFocus(_ic); break; case FocusOut: // keyboard focus // server->postEvent (new CEventSetFocus (false, this)); if (_ic) XUnsetICFocus(_ic); break; case KeymapNotify: break; case MappingNotify: // update keymap XRefreshKeyboardMapping((XMappingEvent *)&event); break; case DestroyNotify: // XIM server has crashed createIM(); break; case ClientMessage: if ((event.xclient.format == 32) && ((Atom)event.xclient.data.l[0] == XA_WM_DELETE_WINDOW)) { server->postEvent(new CEventDestroyWindow(this)); } break; default: // nlinfo("UnknownEvent"); // XtDispatchEvent(&event); return false; } return true; }
/* Return the next input character after first passing any keyboard input * to the command. If flags & BUF_ONLY is true then only buffered characters are * returned and once the buffer is empty the special value GCC_NULL is * returned. If flags and GET_XEVENTS is true then GCC_NULL is returned * when an X event arrives. */ static int get_com_char(int flags) { XEvent event; struct xeventst *xe; fd_set in_fdset, out_fdset; unsigned char *s; int count, sv; unsigned char mask = is_eightbit() ? 0xff : 0x7f; extern int errno; if (com_stack_top > com_stack) return(*--com_stack_top); if (com_buf_next < com_buf_top) return(*com_buf_next++ & mask); else if (flags & BUF_ONLY) return(GCC_NULL); for (;;) { FD_ZERO(&in_fdset); while (XPending(display) == 0) { if (FD_ISSET(x_fd,&in_fdset)) /* If we get to this point something is wrong * because there is X input available but no * events. Exit the program to avoid looping * forever. */ quit(0); FD_SET(comm_fd,&in_fdset); FD_SET(x_fd,&in_fdset); FD_ZERO(&out_fdset); if (send_count > 0) FD_SET(comm_fd,&out_fdset); do sv = select(fd_width,&in_fdset,&out_fdset,NULL,NULL); while (sv < 0 && errno == EINTR); if (sv < 0) { error("select failed"); quit(-1); } if (FD_ISSET(comm_fd,&out_fdset)) { count = send_count < 100 ? send_count : 100; count = write(comm_fd,send_nxt,count); if (count < 0) { error("failed to write to command"); quit(-1); } send_count -= count; send_nxt += count; } if (FD_ISSET(comm_fd,&in_fdset)) break; } if (FD_ISSET(comm_fd,&in_fdset)) break; XNextEvent(display,&event); if (event.type == KeyPress) { s = lookup_key(&event,&count); if (count != 0) send_string(s,count); } else if (event.type == ClientMessage) { if (event.xclient.format == 32 && event.xclient.data.l[0] == wm_del_win) quit(0); } else if (event.type == MappingNotify) { XRefreshKeyboardMapping(&event.xmapping); } else if (event.type == SelectionRequest) { xe = (struct xeventst *)cmalloc(sizeof(struct xeventst)); xe->xe_type = event.type; xe->xe_window = event.xselectionrequest.owner; xe->xe_time = event.xselectionrequest.time; xe->xe_requestor = event.xselectionrequest.requestor; xe->xe_target = event.xselectionrequest.target; xe->xe_property = event.xselectionrequest.property; push_xevent(xe); if (flags & GET_XEVENTS) return(GCC_NULL); } else if (event.type == SelectionNotify) { xe = (struct xeventst *)cmalloc(sizeof(struct xeventst)); xe->xe_type = event.type; xe->xe_time = event.xselection.time; xe->xe_requestor = event.xselection.requestor; xe->xe_property = event.xselection.property; push_xevent(xe); if (flags & GET_XEVENTS) return(GCC_NULL); } else if (event.type == FocusIn || event.type == FocusOut) { if (event.xfocus.mode != NotifyNormal) continue; switch (event.xfocus.detail) { case NotifyAncestor : case NotifyInferior : case NotifyNonlinear : break; default : continue; } xe = (struct xeventst *)cmalloc(sizeof(struct xeventst)); xe->xe_window = 0; xe->xe_type = event.type; xe->xe_time = event.xselection.time; xe->xe_detail = event.xfocus.detail; push_xevent(xe); if (flags & GET_XEVENTS) return(GCC_NULL); } else { xe = (struct xeventst *)cmalloc(sizeof(struct xeventst)); xe->xe_type = event.type; xe->xe_window = event.xany.window; if (event.type == Expose || event.type == GraphicsExpose) { xe->xe_x = event.xexpose.x; xe->xe_y = event.xexpose.y; xe->xe_width = event.xexpose.width; xe->xe_height = event.xexpose.height; } else { xe->xe_time = event.xbutton.time; xe->xe_x = event.xbutton.x; xe->xe_y = event.xbutton.y; xe->xe_state = event.xbutton.state; xe->xe_button = event.xbutton.button; } push_xevent(xe); if (flags & GET_XEVENTS) return(GCC_NULL); } } count = read(comm_fd,com_buf,COM_BUF_SIZE); if (count <= 0) { if (errno == EWOULDBLOCK) { return(GCC_NULL); } else { return(EOF); } } com_buf_next = com_buf; com_buf_top = com_buf + count; return(*com_buf_next++ & mask); }
uni_t dpy_getchar(int timeout) { while (numqueued == 0) { /* If a timeout was asked for, wait that long for an event. */ if ((timeout != -1) && !XPending(display)) { struct pollfd pfd = { .fd = ConnectionNumber(display), .events = POLLIN, .revents = 0 }; poll(&pfd, 1, timeout*1000); if (!pfd.revents) return -VK_TIMEOUT; } XEvent e; XNextEvent(display, &e); if (XFilterEvent(&e, window)) continue; switch (e.type) { case MapNotify: break; case Expose: { /* Mark some of the screen as needing redrawing. */ if (frontbuffer) { for (int y=0; y<screenheight; y++) { unsigned int* p = &frontbuffer[y * screenwidth]; for (int x=0; x<screenwidth; x++) p[x] = 0; } } redraw(); break; } case ConfigureNotify: { XConfigureEvent* xce = &e.xconfigure; int w = xce->width / fontwidth; int h = xce->height / fontheight; if ((w != screenwidth) || (h != screenheight)) { screenwidth = w; screenheight = h; if (frontbuffer) free(frontbuffer); frontbuffer = NULL; if (backbuffer) free(backbuffer); backbuffer = calloc(screenwidth * screenheight, sizeof(unsigned int)); push_key(-VK_RESIZE); } break; } case MappingNotify: case KeymapNotify: XRefreshKeyboardMapping(&e.xmapping); break; case KeyPress: { XKeyPressedEvent* xke = &e.xkey; KeySym keysym; char buffer[32]; Status status = 0; int charcount = Xutf8LookupString(xic, xke, buffer, sizeof(buffer)-1, &keysym, &status); int mods = 0; if (xke->state & ShiftMask) mods |= VKM_SHIFT; if (xke->state & ControlMask) mods |= VKM_CTRL; if ((keysym & 0xffffff00) == 0xff00) { /* Special function key. */ if (!IsModifierKey(keysym)) push_key(-(keysym | mods)); } else { const char* p = buffer; while ((p-buffer) < charcount) { uni_t c = readu8(&p); if (c < 32) { /* Ctrl + letter key */ push_key(-(VKM_CTRLASCII | c | mods)); } else { if (xke->state & Mod1Mask) push_key(-XK_Escape); push_key(c); } } } break; } } } return dequeue(); } const char* dpy_getkeyname(uni_t k) { static char buffer[32]; switch (-k) { case VK_RESIZE: return "KEY_RESIZE"; case VK_TIMEOUT: return "KEY_TIMEOUT"; case VK_REDRAW: return "KEY_REDRAW"; } int key = -k & ~VKM__MASK; int mods = -k & VKM__MASK; if (mods & VKM_CTRLASCII) { sprintf(buffer, "KEY_%s^%c", (mods & VKM_SHIFT) ? "S" : "", key + 64); return buffer; } const char* template = NULL;
static ClutterTranslateReturn clutter_stage_x11_translate_event (ClutterEventTranslator *translator, gpointer native, ClutterEvent *event) { ClutterStageX11 *stage_x11; ClutterStageCogl *stage_cogl; ClutterTranslateReturn res = CLUTTER_TRANSLATE_CONTINUE; ClutterBackendX11 *backend_x11; Window stage_xwindow; XEvent *xevent = native; ClutterStage *stage; stage_cogl = clutter_x11_get_stage_window_from_window (xevent->xany.window); if (stage_cogl == NULL) return CLUTTER_TRANSLATE_CONTINUE; stage = stage_cogl->wrapper; stage_x11 = CLUTTER_STAGE_X11 (stage_cogl); backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend); stage_xwindow = stage_x11->xwin; switch (xevent->type) { case ConfigureNotify: if (!stage_x11->is_foreign_xwin) { gboolean size_changed = FALSE; CLUTTER_NOTE (BACKEND, "ConfigureNotify[%x] (%d, %d)", (unsigned int) stage_x11->xwin, xevent->xconfigure.width, xevent->xconfigure.height); /* When fullscreen, we'll keep the xwin_width/height variables to track the old size of the window and we'll assume all ConfigureNotifies constitute a size change */ if (_clutter_stage_is_fullscreen (stage)) size_changed = TRUE; else if ((stage_x11->xwin_width != xevent->xconfigure.width) || (stage_x11->xwin_height != xevent->xconfigure.height)) { size_changed = TRUE; stage_x11->xwin_width = xevent->xconfigure.width; stage_x11->xwin_height = xevent->xconfigure.height; } clutter_actor_set_size (CLUTTER_ACTOR (stage), xevent->xconfigure.width, xevent->xconfigure.height); CLUTTER_UNSET_PRIVATE_FLAGS (stage_cogl->wrapper, CLUTTER_IN_RESIZE); if (size_changed) { /* XXX: This is a workaround for a race condition when * resizing windows while there are in-flight * glXCopySubBuffer blits happening. * * The problem stems from the fact that rectangles for the * blits are described relative to the bottom left of the * window and because we can't guarantee control over the X * window gravity used when resizing so the gravity is * typically NorthWest not SouthWest. * * This means if you grow a window vertically the server * will make sure to place the old contents of the window * at the top-left/north-west of your new larger window, but * that may happen asynchronous to GLX preparing to do a * blit specified relative to the bottom-left/south-west of * the window (based on the old smaller window geometry). * * When the GLX issued blit finally happens relative to the * new bottom of your window, the destination will have * shifted relative to the top-left where all the pixels you * care about are so it will result in a nasty artefact * making resizing look very ugly! * * We can't currently fix this completely, in-part because * the window manager tends to trample any gravity we might * set. This workaround instead simply disables blits for a * while if we are notified of any resizes happening so if * the user is resizing a window via the window manager then * they may see an artefact for one frame but then we will * fallback to redrawing the full stage until the cooling * off period is over. */ if (stage_x11->clipped_redraws_cool_off) g_source_remove (stage_x11->clipped_redraws_cool_off); stage_x11->clipped_redraws_cool_off = clutter_threads_add_timeout (1000, clipped_redraws_cool_off_cb, stage_x11); /* Queue a relayout - we want glViewport to be called * with the correct values, and this is done in ClutterStage * via cogl_onscreen_clutter_backend_set_size (). * * We queue a relayout, because if this ConfigureNotify is * in response to a size we set in the application, the * set_size() call above is essentially a null-op. * * Make sure we do this only when the size has changed, * otherwise we end up relayouting on window moves. */ clutter_actor_queue_relayout (CLUTTER_ACTOR (stage)); /* the resize process is complete, so we can ask the stage * to set up the GL viewport with the new size */ clutter_stage_ensure_viewport (stage); } } break; case PropertyNotify: if (xevent->xproperty.atom == backend_x11->atom_NET_WM_STATE && xevent->xproperty.window == stage_xwindow && !stage_x11->is_foreign_xwin) { Atom type; gint format; gulong n_items, bytes_after; guchar *data = NULL; gboolean fullscreen_set = FALSE; clutter_x11_trap_x_errors (); XGetWindowProperty (backend_x11->xdpy, stage_xwindow, backend_x11->atom_NET_WM_STATE, 0, G_MAXLONG, False, XA_ATOM, &type, &format, &n_items, &bytes_after, &data); clutter_x11_untrap_x_errors (); if (type != None && data != NULL) { gboolean is_fullscreen = FALSE; Atom *atoms = (Atom *) data; gulong i; for (i = 0; i < n_items; i++) { if (atoms[i] == backend_x11->atom_NET_WM_STATE_FULLSCREEN) fullscreen_set = TRUE; } is_fullscreen = _clutter_stage_is_fullscreen (stage_cogl->wrapper); if (fullscreen_set != is_fullscreen) { if (fullscreen_set) _clutter_stage_update_state (stage_cogl->wrapper, 0, CLUTTER_STAGE_STATE_FULLSCREEN); else _clutter_stage_update_state (stage_cogl->wrapper, CLUTTER_STAGE_STATE_FULLSCREEN, 0); } XFree (data); } } break; case FocusIn: if (!_clutter_stage_is_activated (stage_cogl->wrapper)) { _clutter_stage_update_state (stage_cogl->wrapper, 0, CLUTTER_STAGE_STATE_ACTIVATED); } break; case FocusOut: if (_clutter_stage_is_activated (stage_cogl->wrapper)) { _clutter_stage_update_state (stage_cogl->wrapper, CLUTTER_STAGE_STATE_ACTIVATED, 0); } break; case EnterNotify: #if HAVE_XFIXES if (!stage_x11->is_cursor_visible && !stage_x11->cursor_hidden_xfixes) { XFixesHideCursor (backend_x11->xdpy, stage_x11->xwin); stage_x11->cursor_hidden_xfixes = TRUE; } #endif break; case LeaveNotify: #if HAVE_XFIXES if (stage_x11->cursor_hidden_xfixes) { XFixesShowCursor (backend_x11->xdpy, stage_x11->xwin); stage_x11->cursor_hidden_xfixes = FALSE; } #endif break; case Expose: { XExposeEvent *expose = (XExposeEvent *) xevent; cairo_rectangle_int_t clip; CLUTTER_NOTE (EVENT, "expose for stage: %s[%p], win:0x%x - " "redrawing area (x: %d, y: %d, width: %d, height: %d)", _clutter_actor_get_debug_name (CLUTTER_ACTOR (stage)), stage, (unsigned int) stage_xwindow, expose->x, expose->y, expose->width, expose->height); clip.x = expose->x; clip.y = expose->y; clip.width = expose->width; clip.height = expose->height; clutter_actor_queue_redraw_with_clip (CLUTTER_ACTOR (stage), &clip); } break; case DestroyNotify: CLUTTER_NOTE (EVENT, "Destroy notification received for stage %s[%p], win:0x%x", _clutter_actor_get_debug_name (CLUTTER_ACTOR (stage)), stage, (unsigned int) stage_xwindow); event->any.type = CLUTTER_DESTROY_NOTIFY; event->any.stage = stage; res = CLUTTER_TRANSLATE_QUEUE; break; case ClientMessage: CLUTTER_NOTE (EVENT, "Client message for stage %s[%p], win:0x%x", _clutter_actor_get_debug_name (CLUTTER_ACTOR (stage)), stage, (unsigned int) stage_xwindow); if (handle_wm_protocols_event (backend_x11, stage_x11, xevent)) { event->any.type = CLUTTER_DELETE; event->any.stage = stage; res = CLUTTER_TRANSLATE_QUEUE; } break; case MappingNotify: CLUTTER_NOTE (EVENT, "Refresh keyboard mapping"); XRefreshKeyboardMapping (&xevent->xmapping); backend_x11->keymap_serial += 1; res = CLUTTER_TRANSLATE_REMOVE; break; default: res = CLUTTER_TRANSLATE_CONTINUE; break; } return res; }
/* get to handle. Matthias */ int handle_X_event(XEvent event, unsigned char qt_c) { /* no longer needed. Matthias */ /* XEvent event; */ unsigned char *s; int count; Window root, child; int root_x, root_y, x, y; unsigned int mods; static Time buttonpress_time=0; static unsigned int clicks=1; /* this was set in get_com_char originally. Matthias */ refreshed = 0; /* no longer needed. Matthias */ /* XNextEvent(display,&event); */ switch(event.type) { case KeyPress: s = lookup_key(&event,&count, qt_c); send_string(s,count); return 0; case ClientMessage: if (event.xclient.format == 32 && event.xclient.data.l[0] == wm_del_win) clean_exit(0); return 0; case MappingNotify: XRefreshKeyboardMapping(&event.xmapping); return 0; case GraphicsExpose: case Expose: if (!size_set) { /* Force a window resize if an exposure event * arrives before the first resize event. */ resize_window(0,0); size_set = 1; } if(event.xany.window==vt_win) { scr_refresh(event.xexpose.x,event.xexpose.y, event.xexpose.width,event.xexpose.height); return 0; } /* no longer needed */ /* else */ /* { */ /* while(XCheckTypedWindowEvent (display, event.xany.window, Expose, */ /* &dummy)); */ /* while(XCheckTypedWindowEvent (display, event.xany.window, */ /* GraphicsExpose, &dummy)); */ /* } */ return 0; case VisibilityNotify: /* Here's my conclusiion: * If the window is completely onobscured, use bitblt's * to scroll. Even then, they're only used when doing partial * screen scrolling. When partially obscured, we have to fill * in the GraphicsExpose parts, which means that after each refresh, * we need to wait for the graphics expose or Noexpose events, * which ought to make things real slow! */ if(event.xvisibility.state == VisibilityUnobscured) { scr_refresh(0,0,MyWinInfo.cwidth,MyWinInfo.cheight); /* refresh_type = FAST; */ /* use slow here. FAST seems to be buggy sometimes. (Matthias) */ refresh_type = SLOW; } else if(event.xvisibility.state == VisibilityPartiallyObscured) { refresh_type = SLOW; scr_refresh(0,0,MyWinInfo.cwidth,MyWinInfo.cheight); } else { refresh_type = DONT_BOTHER; } break; case FocusIn: scr_focus(1); return 0; case FocusOut: scr_focus(0); return 0; case ConfigureNotify: resize_window(0,0); size_set = 1; return 0; case ButtonPress: if (event.xany.window == vt_win) { if (mouse_rep && ((event.xbutton.state & ShiftMask) == 0) && !mouse_block) { mouse_report (&(event.xbutton), 0); return 1; } else { switch (event.xbutton.button) { case Button1 : /* recognize multiclick. bmg */ if (event.xbutton.time-buttonpress_time < MULTICLICK_TIME) { clicks++; } else { clicks = 1; } /* don't react two times on the same event */ /* Matthias */ if (event.xbutton.time == buttonpress_time) clicks--; buttonpress_time = event.xbutton.time; scr_start_selection(clicks, event.xbutton.x,event.xbutton.y); return 0; /* deactivated since Button3 is for popupmenu. Matthias */ /* case Button3 : */ /* scr_extend_selection(event.xbutton.x,event.xbutton.y); */ /* Scroll up */ case Button4: MyWinInfo.offset += 3; /* check to make sure we aren't at the top already */ if (MyWinInfo.offset > MyWinInfo.sline_top) { MyWinInfo.offset = MyWinInfo.sline_top; } screen_refresh(); return 0; /* Scroll down */ case Button5: MyWinInfo.offset -= 3; /* check to make sure we aren't at the bottom already */ if (MyWinInfo.offset < 0) { MyWinInfo.offset = 0; } screen_refresh(); return 0; default: return 0; } } } return 0; case ButtonRelease: if (event.xany.window == vt_win) { if (mouse_rep && ((event.xbutton.state & ShiftMask) == 0) && !mouse_block) { mouse_report (&(event.xbutton), 1); return 1; } else { switch (event.xbutton.button) { case Button1: /* no longer needed bmg */ /* case Button3: */ scr_make_selection(event.xbutton.time); return 0; case Button2: if ((event.xbutton.state & Mod1Mask) == 0) scr_paste_selection(); return 0; } } } return 0; case MotionNotify: if (event.xany.window == vt_win && ((event.xbutton.state & Button1Mask) == Button1Mask) && !(event.xbutton.state & Button2Mask)) { while(XCheckTypedWindowEvent(display, vt_win, MotionNotify, &event)); XQueryPointer(display,vt_win,&root,&child, &root_x,&root_y,&x,&y,&mods); scr_extend_selection(x,y); return 0; } return 0; default: return 0; } return 0; }
// --------------------------------------------------------------------------- void X11WindowImpl::processEvent(XEvent& ev) { char keybuffer[8]; KeySym keysym; XComposeStatus compose; int count, keycode; ::Window root, child; int rootx, rooty, winx, winy; unsigned int mask; switch(ev.type) { case ButtonPress: switch(ev.xbutton.button) { case 1: if (window) window->buttonPress( GUI_ButtonLeft, ev.xbutton.x, ev.xbutton.y ); break; case 2: if (window) window->buttonPress( GUI_ButtonMiddle, ev.xbutton.x, ev.xbutton.y ); break; case 3: if (window) window->buttonPress( GUI_ButtonRight, ev.xbutton.x, ev.xbutton.y ); break; case 4: if (window) window->wheelRotate( GUI_WheelForward ); break; case 5: if (window) window->wheelRotate( GUI_WheelBackward ); break; } break; case ButtonRelease: switch(ev.xbutton.button) { case 1: if (window) window->buttonRelease( GUI_ButtonLeft, ev.xbutton.x, ev.xbutton.y ); break; case 2: if (window) window->buttonRelease( GUI_ButtonMiddle, ev.xbutton.x, ev.xbutton.y ); break; case 3: if (window) window->buttonRelease( GUI_ButtonRight, ev.xbutton.x, ev.xbutton.y ); break; } break; case KeyPress: count = XLookupString(&ev.xkey, keybuffer, sizeof(keybuffer), &keysym, &compose); keycode = translate_key(keysym); if (keycode) if (window) window->keyPress(keycode); break; case KeyRelease: count = XLookupString(&ev.xkey, keybuffer, sizeof(keybuffer), &keysym, &compose); keycode = translate_key(keysym); if (keycode) if (window) window->keyRelease(keycode); break; case MappingNotify: XRefreshKeyboardMapping(&ev.xmapping); break; case MotionNotify: if( XQueryPointer(factory->xdisplay, xwindow, &root, &child, &rootx, &rooty, &winx, &winy, &mask) == True ) if (window) window->mouseMove( winx, winy ); break; case Expose: if (ev.xexpose.count == 0) { if (window) { if (window->skipRedraw) break; window->paint(); } swap(); } break; case ConfigureNotify: if (window) window->resize( ev.xconfigure.width, ev.xconfigure.height ); break; case MapNotify: if (window) window->show(); break; case UnmapNotify: if (window) window->hide(); break; case ClientMessage: if ( ( (::Atom) ev.xclient.data.l[0] ) == factory->atoms[GUI_X11_ATOM_WM_DELETE]) if (window) window->on_close(); break; case DestroyNotify: factory->notifyDelete(xwindow); xwindow = 0; if (window) window->notifyDestroy(); delete this; break; } }