void flush_kbd(void) { XEvent evnt; while (XCheckTypedEvent(disp, KeyPress, &evnt) == True #ifdef USE_XDGA && XCheckTypedEvent(disp, dgaEventBase+KeyPress, &evnt) == True #endif ); }
bool GLWindow::GetEvent(Event &event) { if (XPending(dpy)) { int keysyms_per_keycode_return; XEvent xev; // Keyboard Key Press (Keysym code available in /usr/include/X11/keysymdef.h) if (XCheckWindowEvent(dpy, glWin, KeyPressMask, &xev)) { event.type = TMGL_Press; KeySym ks = *XGetKeyboardMapping(dpy,xev.xkey.keycode,1,&keysyms_per_keycode_return); MapKey(ks, event.input); } // Keyboard Key Release (Keysym code available in /usr/include/X11/keysymdef.h) else if (XCheckWindowEvent(dpy, glWin, KeyReleaseMask, &xev)) { event.type = TMGL_Release; KeySym ks = *XGetKeyboardMapping(dpy,xev.xkey.keycode,1,&keysyms_per_keycode_return); MapKey(ks, event.input); } // Mouse Button Press else if (XCheckWindowEvent(dpy, glWin, ButtonPressMask, &xev)) { event.type = TMGL_Press; MapMouse(xev.xbutton.button, event.input); event.motion.x = xev.xmotion.x; event.motion.y = xev.xmotion.y; } // Mouse Button Release else if (XCheckWindowEvent(dpy, glWin, ButtonReleaseMask, &xev)) { event.type = TMGL_Release; MapMouse(xev.xbutton.button, event.input); event.motion.x = xev.xmotion.x; event.motion.y = xev.xmotion.y; } // Mouse Motion else if (XCheckWindowEvent(dpy, glWin, PointerMotionMask, &xev)) { event.type = TMGL_Motion; event.motion.x = xev.xmotion.x; event.motion.y = xev.xmotion.y; } // Window Exposure else if (XCheckWindowEvent(dpy, glWin, ExposureMask, &xev)) { XWindowAttributes gwa; event.type = TMGL_Expose; XGetWindowAttributes(dpy, glWin, &gwa); event.expose.width = gwa.width; event.expose.height = gwa.height; } // Quit button pressed else if (XCheckTypedEvent(dpy, ClientMessage, &xev)) { event.type = TMGL_Quit; } // Other Events else { return false; } return true; } return false; }
gboolean grab_key(gpointer user_data) { GtkWidget *window = GTK_WIDGET(user_data); XCheckTypedEvent(x_disp, KeyRelease, &event); switch(event.type) { case KeyRelease: INFO("Got an event %d\n", event.xkey.keycode); event.type = 0; if (window) { if (GTK_WIDGET_VISIBLE(window)) { gtk_widget_hide(window); } else { gtk_widget_show(window); } } break; default: break; } usleep(100000); return TRUE; }
static __inline__ int X11_WarpedMotion(_THIS, XEvent *xevent) { int w, h, i; int deltax, deltay; int posted; w = SDL_VideoSurface->w; h = SDL_VideoSurface->h; deltax = xevent->xmotion.x - mouse_last.x; deltay = xevent->xmotion.y - mouse_last.y; #ifdef DEBUG_MOTION printf("Warped mouse motion: %d,%d\n", deltax, deltay); #endif mouse_last.x = xevent->xmotion.x; mouse_last.y = xevent->xmotion.y; posted = SDL_PrivateMouseMotion(0, 1, deltax, deltay); if ( (xevent->xmotion.x < MOUSE_FUDGE_FACTOR) || (xevent->xmotion.x > (w-MOUSE_FUDGE_FACTOR)) || (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) || (xevent->xmotion.y > (h-MOUSE_FUDGE_FACTOR)) ) { /* Get the events that have accumulated */ while ( XCheckTypedEvent(SDL_Display, MotionNotify, xevent) ) { deltax = xevent->xmotion.x - mouse_last.x; deltay = xevent->xmotion.y - mouse_last.y; #ifdef DEBUG_MOTION printf("Extra mouse motion: %d,%d\n", deltax, deltay); #endif mouse_last.x = xevent->xmotion.x; mouse_last.y = xevent->xmotion.y; posted += SDL_PrivateMouseMotion(0, 1, deltax, deltay); } mouse_last.x = w/2; mouse_last.y = h/2; XWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0, mouse_last.x, mouse_last.y); for ( i=0; i<10; ++i ) { XMaskEvent(SDL_Display, PointerMotionMask, xevent); if ( (xevent->xmotion.x > (mouse_last.x-MOUSE_FUDGE_FACTOR)) && (xevent->xmotion.x < (mouse_last.x+MOUSE_FUDGE_FACTOR)) && (xevent->xmotion.y > (mouse_last.y-MOUSE_FUDGE_FACTOR)) && (xevent->xmotion.y < (mouse_last.y+MOUSE_FUDGE_FACTOR)) ) { break; } #ifdef DEBUG_XEVENTS printf("Lost mouse motion: %d,%d\n", xevent->xmotion.x, xevent->xmotion.y); #endif } #ifdef DEBUG_XEVENTS if ( i == 10 ) { printf("Warning: didn't detect mouse warp motion\n"); } #endif } return(posted); }
/* * We call this periodically to process any bell events that have * taken place. */ void check_bell_event(void) { XEvent xev; XkbAnyEvent *xkb_ev; int got_bell = 0; if (! xkb_base_event_type) { return; } RAWFB_RET_VOID /* caller does X_LOCK */ if (! XCheckTypedEvent(dpy, xkb_base_event_type, &xev)) { return; } if (! watch_bell) { /* we return here to avoid xkb events piling up */ return; } xkb_ev = (XkbAnyEvent *) &xev; if (xkb_ev->xkb_type == XkbBellNotify) { got_bell = 1; } if (got_bell && sound_bell) { if (! all_clients_initialized()) { rfbLog("check_bell_event: not sending bell: " "uninitialized clients\n"); } else { if (screen && client_count) { rfbSendBell(screen); } } } }
void _glfwPlatformPollEvents(void) { XEvent event; _GLFWwindow* window; while (XCheckMaskEvent(_glfwLibrary.X11.display, ~0, &event) || XCheckTypedEvent(_glfwLibrary.X11.display, ClientMessage, &event)) { processEvent(&event); } // Check whether the cursor has moved inside an active window that has // captured the cursor (because then it needs to be re-centered) window = _glfwLibrary.activeWindow; if (window) { if (window->cursorMode == GLFW_CURSOR_CAPTURED && !window->X11.cursorCentered) { _glfwPlatformSetCursorPos(window, window->width / 2, window->height / 2); window->X11.cursorCentered = GL_TRUE; // NOTE: This is a temporary fix. It works as long as you use // offsets accumulated over the course of a frame, instead of // performing the necessary actions per callback call. XFlush( _glfwLibrary.X11.display ); } } }
int Display::GetDisplayCount(DisplaySearchHandle* handle, bool extended, bool applicationOnly, bool edidInfo) { OVR_UNUSED4(handle, extended, applicationOnly, edidInfo); static int extendedCount = -1; static int numScreens = -1; Linux::LinuxDisplaySearchHandle* localHandle = (Linux::LinuxDisplaySearchHandle*)handle; if (localHandle == NULL) { OVR::LogError("[Linux Display] No search handle passed into GetDisplayCount. Return 0 rifts."); return 0; } if (X11Display == NULL) { OVR::LogError("[Linux Display] Unable to open X Display!"); return 0; } int screen_count = XScreenCount(X11Display); if (screen_count != numScreens) { numScreens = screen_count; extended = true; for (int screen = 0; screen < numScreens; ++screen) { // Be sure we're subscribed to config changes on all screens. XRRSelectInput(X11Display, XRootWindow(X11Display, screen), RRScreenChangeNotifyMask | RRCrtcChangeNotifyMask | RROutputChangeNotifyMask | RROutputPropertyNotifyMask); } } XEvent event_return = XEvent(); if (XCheckTypedEvent(X11Display, BaseRREvent + RRScreenChangeNotify, &event_return)) { extended = true; } if (extendedCount == -1 || extended) { extendedCount = discoverExtendedRifts(localHandle->cachedDescriptorArray, Linux::LinuxDisplaySearchHandle::DescArraySize, edidInfo); } localHandle->extended = true; localHandle->extendedDisplayCount = extendedCount; int totalCount = extendedCount; localHandle->application = false; localHandle->applicationDisplayCount = 0; localHandle->displayCount = totalCount; return totalCount; }
void slop::Mouse::update() { XEvent event; while ( XCheckTypedEvent( x11->display, ButtonPress, &event ) ) { setButton( event.xbutton.button, 1 ); } bool findNewWindow = false; while ( XCheckTypedEvent( x11->display, MotionNotify, &event ) ) { findNewWindow = true; } if ( findNewWindow ) { hoverWindow = findWindow(x11->root); } while ( XCheckTypedEvent( x11->display, ButtonRelease, &event ) ) { setButton( event.xbutton.button, 0 ); } while ( XCheckTypedEvent( x11->display, EnterNotify, &event ) ) { hoverWindow = event.xcrossing.window; } }
Bool check_event_typed (register int event_type, register XEvent * event_return) { register int res; res = XCheckTypedEvent (dpy, event_type, event_return); if (res) stash_event_time (event_return); return res; }
void configure_notify(XEvent *e) { client *c = window_build_client(e->xconfigure.window); if (c && c->manage) { while (XCheckTypedEvent(display, ConfigureNotify, e)); ewmh_client_list(); update_bars(); } client_free(c); }
/* get cursor position when button pressed */ int EZX_TestGetCursorw(int *xp, int *yp, Window *win) { *xp = -1; *yp = -1; if (XCheckMaskEvent(theDisplay, ButtonPressMask, &theEvent)){ theButtonEvent=theEvent.xbutton; if (win != NULL) *win = theButtonEvent.window; /* this is the window the button * was pressed in */ *xp = theButtonEvent.x; *yp = theButtonEvent.y; if (theButtonEvent.button == Button1) return(LEFT_BUTTON); else if (theButtonEvent.button == Button2) return(MIDDLE_BUTTON); else if (theButtonEvent.button == Button3) return(RIGHT_BUTTON); else return(OTHER_BUTTON); } else if (XCheckTypedEvent(theDisplay, MotionNotify, &theEvent)){ do{ theMotionEvent=theEvent.xmotion; if (win != NULL) *win = theMotionEvent.window; /* this is the window pointer * was moved in */ *xp = theMotionEvent.x; *yp = theMotionEvent.y; } while(XCheckTypedEvent(theDisplay, MotionNotify, &theEvent)); return -1; } else{ /* ...nothing found here */ *xp = -1; *yp = -1; return -1; } }
static PetscErrorCode PetscDrawGetMouseButton_X(PetscDraw draw,PetscDrawButton *button,PetscReal* x_user,PetscReal *y_user,PetscReal *x_phys,PetscReal *y_phys) { XEvent report; PetscDraw_X* win = (PetscDraw_X*)draw->data; Window root,child; int root_x,root_y,px,py; unsigned int keys_button; Cursor cursor = 0; PetscFunctionBegin; /* change cursor to indicate input */ if (!cursor) { cursor = XCreateFontCursor(win->disp,XC_hand2); if (!cursor) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Unable to create X cursor"); } XDefineCursor(win->disp,win->win,cursor); XSelectInput(win->disp,win->win,ButtonPressMask | ButtonReleaseMask); while (XCheckTypedEvent(win->disp,ButtonPress,&report)); XMaskEvent(win->disp,ButtonReleaseMask,&report); switch (report.xbutton.button) { case Button1: if (report.xbutton.state & ShiftMask) *button = PETSC_BUTTON_LEFT_SHIFT; else *button = PETSC_BUTTON_LEFT; break; case Button2: if (report.xbutton.state & ShiftMask) *button = PETSC_BUTTON_CENTER_SHIFT; else *button = PETSC_BUTTON_CENTER; break; case Button3: if (report.xbutton.state & ShiftMask) *button = PETSC_BUTTON_RIGHT_SHIFT; else *button = PETSC_BUTTON_RIGHT; break; } XQueryPointer(win->disp,report.xmotion.window,&root,&child,&root_x,&root_y,&px,&py,&keys_button); if (x_phys) *x_phys = ((double)px)/((double)win->w); if (y_phys) *y_phys = 1.0 - ((double)py)/((double)win->h); if (x_user) *x_user = draw->coor_xl + ((((double)px)/((double)win->w)-draw->port_xl))*(draw->coor_xr - draw->coor_xl)/(draw->port_xr - draw->port_xl); if (y_user) *y_user = draw->coor_yl + ((1.0 - ((double)py)/((double)win->h)-draw->port_yl))*(draw->coor_yr - draw->coor_yl)/(draw->port_yr - draw->port_yl); XUndefineCursor(win->disp,win->win); XFlush(win->disp); XSync(win->disp,False); PetscFunctionReturn(0); }
bool GWindow::getNextEvent(XEvent& e) { long eventMask = ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | PointerMotionMask | StructureNotifyMask // For resize event | SubstructureNotifyMask | FocusChangeMask; return ( XCheckMaskEvent(m_Display, eventMask, &e) != 0 || XCheckTypedEvent(m_Display, ClientMessage, &e) != 0 ); }
i4_bool x11_shm_image_actual_class::copy_part_to_vram(x11_shm_extension_class * use, i4_coord x, i4_coord y, i4_coord x1, i4_coord y1, i4_coord x2, i4_coord y2) { XEvent ev; XSync(display,False); if (y1>y2 || x1>x2) { return i4_T; } if (use->need_sync_event) { XEvent ev; while (XCheckTypedEvent(display,use->shm_base+ShmCompletion,&ev)==False) XSync(display,False); use->need_sync_event=i4_F; } if (XCheckTypedEvent(display, ConfigureNotify,&ev)==False) { XShmPutImage(display,window,gc,im,x1,y1,x,y,x2-x1+1,y2-y1+1,True); XSync(display,False); use->need_sync_event=i4_T; return i4_T; } else // screen size changed, better wait till this event is handled cause put might be invalid { XPutBackEvent(display,&ev); return i4_F; } }
void EventsHandler::handleMotion(XEvent* event) { int xdiff, ydiff; while (XCheckTypedEvent(mShared.display, MotionNotify, event)); xdiff = event->xbutton.x_root - buttonEvent.x_root; ydiff = event->xbutton.y_root - buttonEvent.y_root; XMoveResizeWindow(mShared.display, event -> xmotion.window, attributes.x + (buttonEvent.button == 1 ? xdiff : 0), attributes.y + (buttonEvent.button == 1 ? ydiff : 0), MAX(1, attributes.width + (buttonEvent.button == 3 ? xdiff : 0)), MAX(1, attributes.height + (buttonEvent.button == 3 ? ydiff : 0)) ); }
void clear_xdamage_mark_region(sraRegionPtr markregion, int flush) { #if HAVE_LIBXDAMAGE XEvent ev; sraRegionPtr tmpregion; int count = 0; RAWFB_RET_VOID if (! xdamage_present || ! use_xdamage) { return; } if (! xdamage) { return; } if (! xdamage_base_event_type) { return; } if (unixpw_in_progress) return; X_LOCK; if (flush) { XFlush_wr(dpy); } while (XCheckTypedEvent(dpy, xdamage_base_event_type+XDamageNotify, &ev)) { count++; } /* clear the whole damage region */ XDamageSubtract(dpy, xdamage, None, None); X_UNLOCK; if (debug_tiles || debug_xdamage) { fprintf(stderr, "clear_xdamage_mark_region: %d\n", count); } if (! markregion) { /* NULL means mark the whole display */ tmpregion = sraRgnCreateRect(0, 0, dpy_x, dpy_y); add_region_xdamage(tmpregion); sraRgnDestroy(tmpregion); } else { add_region_xdamage(markregion); } #else if (0) flush++; /* compiler warnings */ if (0) markregion = NULL; #endif }
void configurenotify(XEvent *ev) { while (XCheckTypedEvent(dpy,ConfigureNotify, ev)); XConfigureEvent *e = &ev->xconfigure; if (e->window == win) { /* The XServer is not storing the new/current values for width + * height. These must be retrieved directly. * Is this an X11 bug? */ Window wig; int ig; unsigned int uig; XGetGeometry(dpy, win, &wig, &ig, &ig, &ww, &wh, &uig, &uig); //ww = e->width; wh = e->height; spectro_draw(); XSetWindowBackgroundPixmap(dpy, win, buf); XClearWindow(dpy,win); } }
static void mf_repaint P3C(Widget, w, XtPointer, data, XEvent*, ev) { if (!mf_mapped || !ev || ev->type != Expose) return; /* We are a ``simple application''. */ if (ev->xexpose.count == 0) { XEvent event; /* skip all excess redraws */ while (XCheckTypedEvent (mf_display, Expose, &event) != False) continue; mf_redraw (); } }
void EvtMouseVScrollBar(struct XObj *xobj, XButtonEvent *EvtButton) { static XEvent event; int oldy = 0; int oldvalue = -1; int newvalue; int x1,y1,x2,y2; Window Win1,Win2; unsigned int modif; fd_set in_fdset; do { /* On suit les mouvements de la souris */ XQueryPointer(dpy, *xobj->ParentWin, &Win1, &Win2, &x1, &y1, &x2, &y2, &modif); y2 = y2 - xobj->y; if (y2 < 15) y2 = 15; if (y2 > xobj->height - 21) y2 = xobj->height - 21; if (oldy != y2) { oldy = y2; /* calcule de xobj->value */ newvalue = (y2-15)*xobj->height/(xobj->height - 36) * (xobj->value2 - xobj->value3)/(xobj->height) + xobj->value3; if (newvalue!=oldvalue) { HideThumbV(xobj); xobj->value = newvalue; DrawThumbV(xobj); oldvalue = newvalue; SendMsg(xobj,SingleClic); } } FD_ZERO(&in_fdset); FD_SET(x_fd, &in_fdset); select(32, SELECT_FD_SET_CAST &in_fdset, NULL, NULL, NULL); } while (!XCheckTypedEvent(dpy, ButtonRelease, &event) && EvtButton != NULL); }
DWORD DriverPeekTypedEvent(int event_type, Window w) { XEvent Report; Bool bIsEvent; int nCount = 0; PRIVATEDISPLAY *dp; dp = GETDP(); if (XEventsQueued(dp->display,QueuedAfterFlush)) { while ((bIsEvent = (w == (Window)0))? XCheckTypedEvent(dp->display,event_type,&Report): XCheckTypedWindowEvent(dp->display,w,event_type,&Report)) { nCount++; DriverPrivateEvents(&Report); } } return (DWORD)nCount; }
void EvtMouseHScrollBar(struct XObj *xobj,XButtonEvent *EvtButton) { static XEvent event; int x,y,w,h; int oldx=0; int oldvalue=-1; int newvalue; int x1,y1,x2,y2; Window Win1,Win2; unsigned int modif; x=3+((xobj->width-36)*xobj->value)/(xobj->value3-xobj->value2); y=xobj->height/2-9; w=30; h=18; do { /* On suit les mouvements de la souris */ XQueryPointer(xobj->display,*xobj->ParentWin,&Win1,&Win2,&x1,&y1,&x2,&y2,&modif); x2=x2-xobj->x; if (x2<15) x2=15; if (x2>xobj->width-21) x2=xobj->width-21; if (oldx!=x2) { oldx=x2; /* calcule de xobj->value */ newvalue=(x2-15)*xobj->width/(xobj->width-36)*(xobj->value3-xobj->value2)/(xobj->width)+xobj->value2; if (newvalue!=oldvalue) { HideThumbH(xobj); xobj->value=newvalue; DrawThumbH(xobj); oldvalue=newvalue; SendMsg(xobj,SingleClic); } } } while (!XCheckTypedEvent(xobj->display,ButtonRelease,&event)); }
void handler_motionnotify(XEvent *ev) { XMotionEvent *mev = &ev->xmotion; struct monitor *mon; struct client *c; if ((c = find_client_by_window(mons, mev->window))) { while(XCheckTypedEvent(dpy, MotionNotify, ev)); if (c->mon->sel != c) monitor_select_client(c->mon, c, false); if (motion->type == MovementMotion) handler_motionnotify_move(c, mev); else if (motion->type == ResizeMotion) handler_motionnotify_resize(c, mev); } else { mon = find_monitor_by_pos(mons, mev->x_root, mev->y_root); set_monitor(mon); } }
static int xlib_handle_event() { XEvent event; int num_handled_events = 0; while(XCheckMaskEvent(glwt.x11.display, ~0, &event) || XCheckTypedEvent(glwt.x11.display, ClientMessage, &event)) { ++num_handled_events; GLWTWindow *win = 0; if(XFindContext( glwt.x11.display, event.xany.window, glwt.x11.xcontext, (XPointer*)&win) != 0) continue; switch(event.type) { case ConfigureNotify: if(win->win_callback) { GLWTWindowEvent e; e.window = win; e.type = GLWT_WINDOW_RESIZE; e.resize.width = event.xconfigure.width; e.resize.height = event.xconfigure.height; win->win_callback(win, &e, win->userdata); } break; case MapNotify: case UnmapNotify: if(win->win_callback) { GLWTWindowEvent e; e.window = win; e.type = event.type == MapNotify ? GLWT_WINDOW_SHOW : GLWT_WINDOW_HIDE; e.dummy.dummy = 0; win->win_callback(win, &e, win->userdata); } break; case Expose: if(win->win_callback) { GLWTWindowEvent e; e.window = win; e.type = GLWT_WINDOW_EXPOSE; e.dummy.dummy = 0; win->win_callback(win, &e, win->userdata); } break; case KeyPress: case KeyRelease: if(win->win_callback) { GLWTWindowEvent e; e.window = win; e.type = event.type == KeyPress ? GLWT_WINDOW_KEY_DOWN : GLWT_WINDOW_KEY_UP; e.key.keysym = translate_key(XkbKeycodeToKeysym(glwt.x11.display, event.xkey.keycode, 0, 0)); e.key.scancode = event.xkey.keycode; e.key.mod = mapKeyMod(event.xkey.state); win->win_callback(win, &e, win->userdata); } break; case FocusIn: case FocusOut: if(win->win_callback) { GLWTWindowEvent e; e.window = win; e.type = event.type == FocusIn ? GLWT_WINDOW_FOCUS_IN : GLWT_WINDOW_FOCUS_OUT; e.dummy.dummy = 0; win->win_callback(win, &e, win->userdata); } break; case ButtonPress: case ButtonRelease: if(win->win_callback) { GLWTWindowEvent e; e.window = win; e.type = event.type == ButtonPress ? GLWT_WINDOW_BUTTON_DOWN : GLWT_WINDOW_BUTTON_UP; e.button.x = event.xbutton.x; e.button.y = event.xbutton.y; e.button.button = event.xbutton.button; // todo: make these consistent on different platforms e.button.mod = mapKeyMod(event.xbutton.state); win->win_callback(win, &e, win->userdata); } break; case MotionNotify: if(win->win_callback) { GLWTWindowEvent e; e.window = win; e.type = GLWT_WINDOW_MOUSE_MOTION; e.motion.x = event.xmotion.x; e.motion.y = event.xmotion.y; e.motion.buttons = mapButtons(event.xmotion.state); win->win_callback(win, &e, win->userdata); } break; case EnterNotify: case LeaveNotify: if(win->win_callback) { GLWTWindowEvent e; e.window = win; e.type = event.type == EnterNotify ? GLWT_WINDOW_MOUSE_ENTER : GLWT_WINDOW_MOUSE_LEAVE; e.dummy.dummy = 0; win->win_callback(win, &e, win->userdata); } break; case ClientMessage: if((Atom)event.xclient.data.l[0] == glwt.x11.atoms.WM_DELETE_WINDOW) { win->closed = 1; if(win->win_callback) { GLWTWindowEvent e; e.window = win; e.type = GLWT_WINDOW_CLOSE; e.dummy.dummy = 0; win->win_callback(win, &e, win->userdata); } } else if((Atom)event.xclient.data.l[0] == glwt.x11.atoms._NET_WM_PING) { event.xclient.window = RootWindow(glwt.x11.display, glwt.x11.screen_num); XSendEvent( glwt.x11.display, event.xclient.window, False, SubstructureNotifyMask | SubstructureRedirectMask, &event); } break; default: break; } } return num_handled_events; }
/* Finds NaCl/Chromium shm memory using external handler. * Reply must be in the form PID:file */ struct cache_entry* find_shm(uint64_t paddr, uint64_t sig, size_t length) { struct cache_entry* entry = NULL; /* Find entry in cache */ if (cache[0].paddr == paddr) { entry = &cache[0]; } else if (cache[1].paddr == paddr) { entry = &cache[1]; } else { /* Not found: erase an existing entry. */ entry = &cache[next_entry]; next_entry = (next_entry + 1) % 2; close_mmap(entry); } int try; for (try = 0; try < 2; try++) { /* Check signature */ if (entry->map) { if (*((uint64_t*)entry->map) == sig) return entry; log(1, "Invalid signature, fetching new shm!"); close_mmap(entry); } /* Setup parameters and run command */ char arg1[32], arg2[32]; int c; c = snprintf(arg1, sizeof(arg1), "%08lx", (long)paddr & 0xffffffff); trueorabort(c > 0, "snprintf"); int i, p = 0; for (i = 0; i < 8; i++) { c = snprintf(arg2 + p, sizeof(arg2) - p, "%02x", ((uint8_t*)&sig)[i]); trueorabort(c > 0, "snprintf"); p += c; } char* cmd = "croutonfindnacl"; char* args[] = {cmd, arg1, arg2, NULL}; char buffer[256]; log(2, "Running %s %s %s", cmd, arg1, arg2); c = popen2(cmd, args, NULL, 0, buffer, sizeof(buffer)); if (c <= 0) { error("Error running helper."); return NULL; } buffer[c < sizeof(buffer) ? c : (sizeof(buffer)-1)] = 0; log(2, "Result: %s", buffer); /* Parse PID:file output */ char* cut = strchr(buffer, ':'); if (!cut) { error("No ':' in helper reply: %s.", cut); return NULL; } *cut = 0; char* endptr; long pid = strtol(buffer, &endptr, 10); if(buffer == endptr || *endptr != '\0') { error("Invalid pid: %s", buffer); return NULL; } char* file = cut+1; log(2, "PID:%ld, FILE:%s", pid, file); entry->paddr = paddr; entry->fd = open(file, O_RDWR); if (entry->fd < 0) { error("Cannot open file %s\n", file); return NULL; } entry->length = length; entry->map = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED, entry->fd, 0); if (!entry->map) { error("Cannot mmap %s\n", file); close(entry->fd); return NULL; } log(2, "mmap ok %p %zu %d", entry->map, entry->length, entry->fd); } error("Cannot find shm."); return NULL; } /* WebSocket functions */ XImage* img = NULL; XShmSegmentInfo shminfo; /* Writes framebuffer image to websocket/shm */ int write_image(const struct screen* screen) { char reply_raw[FRAMEMAXHEADERSIZE + sizeof(struct screen_reply)]; struct screen_reply* reply = (struct screen_reply*)(reply_raw + FRAMEMAXHEADERSIZE); int refresh = 0; memset(reply_raw, 0, sizeof(reply_raw)); reply->type = 'S'; reply->width = screen->width; reply->height = screen->height; /* Allocate XShmImage */ if (!img || img->width != screen->width || img->height != screen->height) { if (img) { XDestroyImage(img); shmdt(shminfo.shmaddr); shmctl(shminfo.shmid, IPC_RMID, 0); } /* FIXME: Some error checking should happen here... */ img = XShmCreateImage(dpy, DefaultVisual(dpy, 0), 24, ZPixmap, NULL, &shminfo, screen->width, screen->height); trueorabort(img, "XShmCreateImage"); shminfo.shmid = shmget(IPC_PRIVATE, img->bytes_per_line*img->height, IPC_CREAT|0777); trueorabort(shminfo.shmid != -1, "shmget"); shminfo.shmaddr = img->data = shmat(shminfo.shmid, 0, 0); trueorabort(shminfo.shmaddr != (void*)-1, "shmat"); shminfo.readOnly = False; int ret = XShmAttach(dpy, &shminfo); trueorabort(ret, "XShmAttach"); /* Force refresh */ refresh = 1; } if (screen->refresh) { log(1, "Force refresh from client."); /* refresh forced by the client */ refresh = 1; } XEvent ev; /* Register damage on new windows */ while (XCheckTypedEvent(dpy, MapNotify, &ev)) { register_damage(dpy, ev.xcreatewindow.window); refresh = 1; } /* Check for damage */ while (XCheckTypedEvent(dpy, damageEvent + XDamageNotify, &ev)) { refresh = 1; } /* Check for cursor events */ reply->cursor_updated = 0; while (XCheckTypedEvent(dpy, fixesEvent + XFixesCursorNotify, &ev)) { XFixesCursorNotifyEvent* curev = (XFixesCursorNotifyEvent*)&ev; if (verbose >= 2) { char* name = XGetAtomName(dpy, curev->cursor_name); log(2, "cursor! %ld %s", curev->cursor_serial, name); XFree(name); } reply->cursor_updated = 1; reply->cursor_serial = curev->cursor_serial; } /* No update */ if (!refresh) { reply->shm = 0; reply->updated = 0; socket_client_write_frame(reply_raw, sizeof(*reply), WS_OPCODE_BINARY, 1); return 0; } /* Get new image from framebuffer */ XShmGetImage(dpy, DefaultRootWindow(dpy), img, 0, 0, AllPlanes); int size = img->bytes_per_line * img->height; trueorabort(size == screen->width*screen->height*4, "Invalid screen byte count"); trueorabort(screen->shm, "Non-SHM rendering is not supported"); struct cache_entry* entry = find_shm(screen->paddr, screen->sig, size); reply->shm = 1; reply->updated = 1; reply->shmfailed = 0; if (entry && entry->map) { if (size == entry->length) { memcpy(entry->map, img->data, size); msync(entry->map, size, MS_SYNC); } else { /* This should never happen (it means the client passed an * outdated buffer to us). */ error("Invalid shm entry length (client bug!)."); reply->shmfailed = 1; } } else { /* Keep the flow going, even if we cannot find the shm. Next time * the NaCl client reallocates the buffer, we are likely to be able * to find it. */ error("Cannot find shm, moving on..."); reply->shmfailed = 1; } /* Confirm write is done */ socket_client_write_frame(reply_raw, sizeof(*reply), WS_OPCODE_BINARY, 1); return 0; } /* Writes cursor image to websocket */ int write_cursor() { XFixesCursorImage *img = XFixesGetCursorImage(dpy); if (!img) { error("XFixesGetCursorImage returned NULL"); return -1; } int size = img->width*img->height; const int replylength = sizeof(struct cursor_reply) + size*sizeof(uint32_t); char reply_raw[FRAMEMAXHEADERSIZE + replylength]; struct cursor_reply* reply = (struct cursor_reply*)(reply_raw + FRAMEMAXHEADERSIZE); memset(reply_raw, 0, sizeof(*reply_raw)); reply->type = 'P'; reply->width = img->width; reply->height = img->height; reply->xhot = img->xhot; reply->yhot = img->yhot; reply->cursor_serial = img->cursor_serial; /* This casts long[] to uint32_t[] */ int i; for (i = 0; i < size; i++) reply->pixels[i] = img->pixels[i]; socket_client_write_frame(reply_raw, replylength, WS_OPCODE_BINARY, 1); XFree(img); return 0; }
void gemglxwindow::dispatch(void) { if(!m_pimpl->doDispatch) { return; } XEvent event; XButtonEvent* eb = (XButtonEvent*)&event; XKeyEvent* kb = (XKeyEvent*)&event; char keystring[2]; KeySym keysym_return; unsigned long devID=0; while (XCheckWindowEvent(m_pimpl->dpy,m_pimpl->win, StructureNotifyMask | KeyPressMask | KeyReleaseMask | PointerMotionMask | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask, &event)) { switch (event.type) { case ButtonPress: button(devID, eb->button-1, 1); motion(devID, eb->x, eb->y); break; case ButtonRelease: button(devID, eb->button-1, 0); motion(devID, eb->x, eb->y); break; case MotionNotify: motion(devID, eb->x, eb->y); if(!m_pimpl->have_border) { int err=XSetInputFocus(m_pimpl->dpy, m_pimpl->win, RevertToParent, CurrentTime); err=0; } break; case KeyPress: key(devID, m_pimpl->key2string(kb), kb->keycode, 1); break; case KeyRelease: key(devID, m_pimpl->key2string(kb), kb->keycode, 0); break; case ConfigureNotify: if ((event.xconfigure.width != m_width) || (event.xconfigure.height != m_height)) { m_width=event.xconfigure.width; m_height=event.xconfigure.height; XResizeWindow(m_pimpl->dpy, m_pimpl->win, m_width, m_height); dimension(m_width, m_height); } if ((event.xconfigure.send_event) && ((event.xconfigure.x != m_xoffset) || (event.xconfigure.y != m_yoffset))) { m_xoffset=event.xconfigure.x; m_yoffset=event.xconfigure.y; position(m_xoffset, m_yoffset); } break; default: // post("event %d", event.type); break; } } if (XCheckTypedEvent(m_pimpl->dpy, ClientMessage, &event)) { info("window", "destroy"); // GemMan::destroyWindowSoon(); } }
int check_xrandr_event(char *msg) { XEvent xev; RAWFB_RET(0) /* it is assumed that X_LOCK is on at this point. */ if (subwin) { return handle_subwin_resize(msg); } #if LIBVNCSERVER_HAVE_LIBXRANDR if (! xrandr_present) { return 0; } if (! xrandr && ! xrandr_maybe) { return 0; } if (xrandr_base_event_type && XCheckTypedEvent(dpy, xrandr_base_event_type + RRScreenChangeNotify, &xev)) { int do_change, qout = 0; static int first = 1; XRRScreenChangeNotifyEvent *rev; rev = (XRRScreenChangeNotifyEvent *) &xev; if (first && ! xrandr) { fprintf(stderr, "\n"); if (getenv("X11VNC_DEBUG_XRANDR") == NULL) { qout = 1; } } first = 0; rfbLog("check_xrandr_event():\n"); rfbLog("Detected XRANDR event at location '%s':\n", msg); if (qout) { ; } else { rfbLog(" serial: %d\n", (int) rev->serial); rfbLog(" timestamp: %d\n", (int) rev->timestamp); rfbLog(" cfg_timestamp: %d\n", (int) rev->config_timestamp); rfbLog(" size_id: %d\n", (int) rev->size_index); rfbLog(" sub_pixel: %d\n", (int) rev->subpixel_order); rfbLog(" rotation: %d\n", (int) rev->rotation); rfbLog(" width: %d\n", (int) rev->width); rfbLog(" height: %d\n", (int) rev->height); rfbLog(" mwidth: %d mm\n", (int) rev->mwidth); rfbLog(" mheight: %d mm\n", (int) rev->mheight); rfbLog("\n"); rfbLog("check_xrandr_event: previous WxH: %dx%d\n", wdpy_x, wdpy_y); } if (wdpy_x == rev->width && wdpy_y == rev->height && xrandr_rotation == (int) rev->rotation) { rfbLog("check_xrandr_event: no change detected.\n"); do_change = 0; if (! xrandr) { rfbLog("check_xrandr_event: " "enabling full XRANDR trapping anyway.\n"); xrandr = 1; } } else { do_change = 1; if (! xrandr) { rfbLog("check_xrandr_event: Resize; " "enabling full XRANDR trapping.\n"); xrandr = 1; } } xrandr_width = rev->width; xrandr_height = rev->height; xrandr_timestamp = rev->timestamp; xrandr_cfg_time = rev->config_timestamp; xrandr_rotation = (int) rev->rotation; if (! qout) rfbLog("check_xrandr_event: updating config...\n"); XRRUpdateConfiguration(&xev); if (do_change) { /* under do_change caller normally returns before its X_UNLOCK */ X_UNLOCK; handle_xrandr_change(rev->width, rev->height); } if (qout) { return do_change; } rfbLog("check_xrandr_event: current WxH: %dx%d\n", XDisplayWidth(dpy, scr), XDisplayHeight(dpy, scr)); rfbLog("check_xrandr_event(): returning control to" " caller...\n"); return do_change; } #else xev.type = 0; #endif return 0; }
/* Called in the gl thread */ void gst_gl_window_run_loop (GstGLWindow * window) { GstGLWindowPrivate *priv = window->priv; g_debug ("begin loop\n"); g_mutex_lock (priv->x_lock); while (priv->running) { XEvent event; XEvent pending_event; g_mutex_unlock (priv->x_lock); /* XSendEvent (which are called in other threads) are done from another display structure */ XNextEvent (priv->device, &event); g_mutex_lock (priv->x_lock); // use in generic/cube and other related uses priv->allow_extra_expose_events = XPending (priv->device) <= 2; switch (event.type) { case ClientMessage: { Atom wm_delete = XInternAtom (priv->device, "WM_DELETE_WINDOW", True); Atom wm_gl = XInternAtom (priv->device, "WM_GL_WINDOW", True); Atom wm_quit_loop = XInternAtom (priv->device, "WM_QUIT_LOOP", True); if (wm_delete == None) g_debug ("Cannot create WM_DELETE_WINDOW\n"); if (wm_gl == None) g_debug ("Cannot create WM_GL_WINDOW\n"); if (wm_quit_loop == None) g_debug ("Cannot create WM_QUIT_LOOP\n"); /* Message sent with gst_gl_window_send_message */ if (wm_gl != None && event.xclient.message_type == wm_gl) { if (priv->running) { #if SIZEOF_VOID_P == 8 GstGLWindowCB custom_cb = (GstGLWindowCB) (((event.xclient.data. l[0] & 0xffffffff) << 32) | (event.xclient.data. l[1] & 0xffffffff)); gpointer custom_data = (gpointer) (((event.xclient.data. l[2] & 0xffffffff) << 32) | (event.xclient.data. l[3] & 0xffffffff)); #else GstGLWindowCB custom_cb = (GstGLWindowCB) event.xclient.data.l[0]; gpointer custom_data = (gpointer) event.xclient.data.l[1]; #endif if (!custom_cb || !custom_data) g_debug ("custom cb not initialized\n"); custom_cb (custom_data); } g_cond_signal (priv->cond_send_message); } /* User clicked on the cross */ else if (wm_delete != None && (Atom) event.xclient.data.l[0] == wm_delete) { g_debug ("Close %lud\n", (gulong) priv->internal_win_id); if (priv->close_cb) priv->close_cb (priv->close_data); priv->draw_cb = NULL; priv->draw_data = NULL; priv->resize_cb = NULL; priv->resize_data = NULL; priv->close_cb = NULL; priv->close_data = NULL; } /* message sent with gst_gl_window_quit_loop */ else if (wm_quit_loop != None && event.xclient.message_type == wm_quit_loop) { #if SIZEOF_VOID_P == 8 GstGLWindowCB destroy_cb = (GstGLWindowCB) (((event.xclient.data. l[0] & 0xffffffff) << 32) | (event.xclient.data. l[1] & 0xffffffff)); gpointer destroy_data = (gpointer) (((event.xclient.data. l[2] & 0xffffffff) << 32) | (event.xclient.data. l[3] & 0xffffffff)); #else GstGLWindowCB destroy_cb = (GstGLWindowCB) event.xclient.data.l[0]; gpointer destroy_data = (gpointer) event.xclient.data.l[1]; #endif g_debug ("Quit loop message %lud\n", (gulong) priv->internal_win_id); /* exit loop */ priv->running = FALSE; /* make sure last pendings send message calls are executed */ XFlush (priv->device); while (XCheckTypedEvent (priv->device, ClientMessage, &pending_event)) { #if SIZEOF_VOID_P == 8 GstGLWindowCB custom_cb = (GstGLWindowCB) (((event.xclient.data. l[0] & 0xffffffff) << 32) | (event.xclient.data. l[1] & 0xffffffff)); gpointer custom_data = (gpointer) (((event.xclient.data. l[2] & 0xffffffff) << 32) | (event.xclient.data. l[3] & 0xffffffff)); #else GstGLWindowCB custom_cb = (GstGLWindowCB) event.xclient.data.l[0]; gpointer custom_data = (gpointer) event.xclient.data.l[1]; #endif g_debug ("execute last pending custom x events\n"); if (!custom_cb || !custom_data) g_debug ("custom cb not initialized\n"); custom_cb (custom_data); g_cond_signal (priv->cond_send_message); } /* Finally we can destroy opengl ressources (texture/shaders/fbo) */ if (!destroy_cb || !destroy_data) g_debug ("destroy cb not correclty set\n"); destroy_cb (destroy_data); } else g_debug ("client message not reconized \n"); break; } case CreateNotify: case ConfigureNotify: { if (priv->resize_cb) priv->resize_cb (priv->resize_data, event.xconfigure.width, event.xconfigure.height); break; } case DestroyNotify: g_debug ("DestroyNotify\n"); break; case Expose: if (priv->draw_cb) { priv->draw_cb (priv->draw_data); glFlush (); eglSwapBuffers (priv->gl_display, priv->gl_surface); } break; case VisibilityNotify: { switch (event.xvisibility.state) { case VisibilityUnobscured: if (priv->draw_cb) priv->draw_cb (priv->draw_data); break; case VisibilityPartiallyObscured: if (priv->draw_cb) priv->draw_cb (priv->draw_data); break; case VisibilityFullyObscured: break; default: g_debug ("unknown xvisibility event: %d\n", event.xvisibility.state); break; } break; } default: g_debug ("unknow\n"); break; } // switch } // while running g_mutex_unlock (priv->x_lock); g_debug ("end loop\n"); }
bool qapp::x11EventFilter(XEvent *event) { xwindow *client; Window w; XEvent ev; XConfigureRequestEvent *cev; XClientMessageEvent *mev; XCrossingEvent *xev; XCirculateRequestEvent *rev; XPropertyEvent *pev; #ifdef DEBUGMSG #include "eventnames.h" if(event->type < 36) logmsg << "Received: " << event_names[event->type] << " (WId:" << event->xany.window << ")\n"; #endif while(waitpid(-1, NULL, WNOHANG) > 0); if(sighup) { wm_restart(); tb_mn->readmenu(); read_cprops(); sighup = FALSE; } switch(event->type) { case DestroyNotify: w = event->xdestroywindow.window; if((client = cwindows.find(w)) != NULL) { clients.remove(client); if(smode && client->isstate()) keyboard::tscreen(); // turn off screen mode tb_pg->draw_pager(); return TRUE; } if(tb_ap->remove(w)) // client on toolbar return TRUE; if(event->xdestroywindow.event != w) return TRUE; if(w == tb->winId() || w == tb_pg->winId() || w == tb_wl->winId() || w == tb_mn->winId() || w == tb_pb->winId()) sig_term(SIGTERM); return FALSE; case MapNotify: if(event->xmap.event != event->xmap.window) return TRUE; if((client = pwindows.find(event->xmap.window)) != NULL) tb_pg->add(client); // add to pager return FALSE; case UnmapNotify: if((client = cwindows.find(event->xunmap.window)) != NULL) { if(event->xunmap.send_event) { // client requested transitions // normal -> withdrawn // iconic -> withdrawn client->withdraw(); } else client->unmap(); return TRUE; } if(event->xunmap.event != event->xunmap.window) return TRUE; if(pwindows.find(event->xunmap.window) != NULL) tb_pg->draw_pager(); return FALSE; case EnterNotify: xev = &event->xcrossing; if(event->xcrossing.window == qt_xrootwin()) { stopautofocus(); rootptr = TRUE; } else if(mrb == FALSE && menu_open == FALSE && (client = (xwindow *)widgetAt(xev->x_root, xev->y_root)) != NULL && clients.find(client) != -1 && ((client = clients.current()) != focusclient || rootptr)) { rootptr = FALSE; setinactive(client); // old client to inactive, save new client if(xev->detail != NotifyInferior) client->startautofocus(); client->setchildfocus(xev->time); client->setcmapfocus(); } return FALSE; case ColormapNotify: if((client = cwindows.find(event->xcolormap.window)) != NULL) { client->setcmap(event->xcolormap.colormap); return TRUE; } return FALSE; case PropertyNotify: pev = &event->xproperty; if((client = cwindows.find(pev->window)) != NULL) { if(pev->atom == XA_WM_NORMAL_HINTS) { client->get_wmnormalhints(); } else if(pev->atom == XA_WM_HINTS) { client->get_wmhints(); } else if(pev->atom == XA_WM_NAME || pev->atom == XA_WM_ICON_NAME) { client->get_wmname(); } else if(pev->atom == wm_colormaps) { client->get_colormaps(); if(client == focusclient) client->setcmapfocus(); } return TRUE; } return FALSE; case ConfigureNotify: if(event->xconfigure.event != event->xconfigure.window) return TRUE; if((client = pwindows.find(event->xconfigure.window)) != NULL) { tb_pg->draw_pager(); while(XCheckTypedEvent(qt_xdisplay(), ConfigureNotify, &ev)); } return TRUE; case ReparentNotify: if((client = cwindows.find(event->xreparent.window)) != NULL && event->xreparent.parent != client->winId()) { clients.remove(client); tb_pg->draw_pager(); } return TRUE; case ButtonPress: w = event->xbutton.window; if(w == qt_xrootwin()) // set focus to root window XSetInputFocus(qt_xdisplay(), w, RevertToPointerRoot, CurrentTime); if(w == tb->winId() || w == tb_pb->winId() || w == tb_ap->winId()) XRaiseWindow(qt_xdisplay(), tb->winId()); if(w == qt_xrootwin() || w == tb_pg->winId()) install_colormap(None); return FALSE; case FocusOut: if(menu_open) // Qt 2.2.4 does not seem to like this if a menu is open return TRUE; return FALSE; case ClientMessage: mev = &event->xclient; if(mev->message_type == wm_change_state && mev->format == 32 && mev->data.l[0] == IconicState && (client = cwindows.find(mev->window)) != NULL) client->iconify(); return TRUE; case CirculateRequest: rev = &event->xcirculaterequest; if(rev->place == PlaceOnTop) XRaiseWindow(qt_xdisplay(), rev->window); else XLowerWindow(qt_xdisplay(), rev->window); return TRUE; case ConfigureRequest: cev = &event->xconfigurerequest; XWindowChanges wc; if((client = cwindows.find(cev->window)) != NULL) { #ifdef DEBUGMSG logmsg << "configure request to client (WId:" << client->winId() << ")\n"; #endif if(cev->value_mask & (CWWidth|CWHeight|CWX|CWY)) { if(smode && client->isstate()) keyboard::tscreen(); if(! client->is_tiled() || client == tmaxclient) { int cx,cy,cw,ch; if(cev->value_mask & CWWidth) cw = cev->width; else cw = client->width(); if(cev->value_mask & CWHeight) ch = cev->height; else ch = client->getcheight(); if((cev->value_mask & CWX) && ! client->is_tiled()) cx = cev->x; else cx = client->x(); if((cev->value_mask & CWY) && ! client->is_tiled()) cy = cev->y; else cy = client->y(); client->resize_request(cx, cy, cw, ch); } cev->value_mask &= ~(CWWidth|CWHeight|CWX|CWY); } if(! cev->value_mask) return TRUE; wc.width = client->width(); wc.height = client->height(); wc.x = client->x(); wc.y = client->y(); wc.border_width = 0; wc.sibling = cev->above; wc.stack_mode = cev->detail; XConfigureWindow(qt_xdisplay(), client->winId(), cev->value_mask, &wc); send_configurenotify(client); } else // never mapped window { if(cev->window == tb->winId() || tb_ap->client_exists(cev->window)) // deny requests on toolbar return TRUE; #ifdef DEBUGMSG logmsg << "configure request to unreparented window (WId:" << cev->window << ")\n"; #endif wc.x = cev->x; wc.y = cev->y; wc.width = cev->width; wc.height = cev->height; cev->value_mask &= (CWX|CWY|CWWidth|CWHeight); XConfigureWindow(qt_xdisplay(), cev->window, cev->value_mask, &wc); } return TRUE; case MapRequest: run_client(event->xmaprequest.window); return TRUE; case KeyPress: return(keyboard::keypress(&event->xkey)); default: if(servershapes && event->type == (ShapeEventBase + ShapeNotify)) { XShapeEvent *sev = (XShapeEvent *)event; if((client = cwindows.find(sev->window)) != NULL) { client->reshape(); return TRUE; } } } return FALSE; }
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; }
void HandleEvent (XEvent * event) { XEvent loop_ev; /* for clearing the queue of events */ switch (event->type) { case (KeyPress): { XKeyEvent *key_event = (XKeyEvent *) event; char buf[128]; KeySym ks; XComposeStatus status; XLookupString (key_event, buf, 128, &ks, &status); x_key_shifted = ShiftMask & key_event->state; x_key_value = buf[0]; switch (ks) { case XK_Left: x_key_value = 1; break; case XK_Down: x_key_value = 2; break; case XK_Up: x_key_value = 3; break; case XK_Right: x_key_value = 4; break; case 'C': if (!confine_pointer(-10,-10,200,200)) unconfine_pointer(); break; case XK_BackSpace: case XK_Delete: x_key_value = 127; break; } } break; case (MotionNotify): { XMotionEvent *ev = (XMotionEvent *) event; while (XCheckMaskEvent(display.dpy,PointerMotionMask,&loop_ev)) { ev = (XMotionEvent *) &loop_ev; } printf("pointer motion event\n"); if (ev->state & Button2Mask) drag_screen(); } break; case (ButtonPress): { XButtonEvent *ev = (XButtonEvent *) event; if ((ev->state & ShiftMask) != 0) cs_mouse_shifted = 1; else cs_mouse_shifted = 0; #ifdef DEBUG_X11_MOUSE printf("button press: ev->button = %d\n",ev->button); #endif #if defined (commentout) mouse_button = ev->button; #endif switch (ev->button) { case Button1: mouse_button = LC_MOUSE_LEFTBUTTON | LC_MOUSE_PRESS; break; case Button2: mouse_button = LC_MOUSE_MIDDLEBUTTON | LC_MOUSE_PRESS; break; case Button3: mouse_button = LC_MOUSE_RIGHTBUTTON | LC_MOUSE_PRESS; break; /* Wheel mouse support Move further for Shift (in main.c: process_keystrokes() ), left to right instead of up and down for Control */ case Button4: /* Up (3); Left (1) if Control */ x_key_shifted = ShiftMask & ev->state; x_key_value = (ControlMask & ev->state) ? 1 : 3; break; case Button5: /* Down (4); Right (2) if control */ x_key_shifted = ShiftMask & ev->state; x_key_value = (ControlMask & ev->state) ? 4 : 2; break; /* XFree86-3 only supports 5 buttons, no Button6 or higher */ } cs_mouse_handler (mouse_button, 0, 0); mouse_button = 0; } break; case (ButtonRelease): { XButtonEvent *ev = (XButtonEvent *) event; mouse_button = ev->button; #ifdef DEBUG_X11_MOUSE printf("button release: ev->button = %d\n",ev->button); #endif switch (ev->button) { case Button1: mouse_button = LC_MOUSE_LEFTBUTTON | LC_MOUSE_RELEASE; break; case Button2: mouse_button = LC_MOUSE_MIDDLEBUTTON | LC_MOUSE_RELEASE; break; case Button3: mouse_button = LC_MOUSE_RIGHTBUTTON | LC_MOUSE_RELEASE; break; } cs_mouse_handler (mouse_button, 0, 0); mouse_button = 0; } break; case (Expose): { XExposeEvent *ev = (XExposeEvent *) event; while (XCheckMaskEvent(display.dpy,ExposureMask,&loop_ev)) { ev = (XExposeEvent *) &loop_ev; } if (suppress_next_expose) { suppress_next_expose = 0; break; } refresh_screen (ev->x, ev->y, ev->x + ev->width, ev->y + ev->height); } break; case ConfigureNotify: { XConfigureEvent *ev = (XConfigureEvent *) event; #if defined (commentout) /* Not sure yet, but need ResizeRedirectMask or VisibilityChangeMask */ while (XCheckMaskEvent(display.dpy,StructureNotifyMask, &loop_ev)) { if (loop_ev.type != ConfigureNotify) { /* We don't seem to do anything with the others anyway, but I want to know for now */ fprintf(stderr,"StructureNotifyMask != ConfigureNotify, " "loop_ev.type = %d\n", loop_ev.type); return; } ev = (XConfigureEvent *) &loop_ev; } #endif while (XCheckTypedEvent(display.dpy, ConfigureNotify, &loop_ev)) { ev = (XConfigureEvent *) &loop_ev; } resize_geometry (ev->width, ev->height); } break; } /*fprintf(stderr,"Handler fell through, event->type = %d\n",event->type);*/ }