void zoom(const char *arg) { if (show.rendered < show.count - 1) { /* ensure rendering is done */ warn(); return; } XDefineCursor(dpy,win,XCreateFontCursor(dpy,130)); XEvent ev; int x1,y1,x2=-1,y2; while ( !XNextEvent(dpy,&ev) && ev.type!=ButtonPress && ev.type!=KeyPress ); if (ev.type == KeyPress) { XPutBackEvent(dpy,&ev); XDefineCursor(dpy,win,invisible_cursor); return; } XGrabPointer(dpy,ev.xbutton.window,True, PointerMotionMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync,None,None,CurrentTime); x1 = ev.xbutton.x; y1 = ev.xbutton.y; while (!XNextEvent(dpy,&ev) && ev.type != ButtonRelease && ev.type!=KeyPress) { XCopyArea(dpy,show.slide[show.num],win,gc,0,0, aspx*sw,aspy*sh,(sw-aspx*sw)/2,(sh-aspy*sh)/2); XDrawRectangle(dpy,win,hgc,x1,y1,ev.xbutton.x-x1,ev.xbutton.y-y1); XSync(dpy,True); } if (ev.type == KeyPress) { XPutBackEvent(dpy,&ev); XDefineCursor(dpy,win,invisible_cursor); return; } x2 = ev.xbutton.x; y2 = ev.xbutton.y; mute("black"); white_muted = True; Pixmap region = XCreatePixmap(dpy,root,sw,sh,DefaultDepth(dpy,scr)); XFillRectangle(dpy,region,wgc,0,0,sw,sh); PopplerPage *page = poppler_document_get_page(pdf,show.num); cairo_surface_t *target = cairo_xlib_surface_create( dpy, region, DefaultVisual(dpy,scr), sw, sh); cairo_t *cairo = cairo_create(target); double xscale = show.scale * sw/ (x2-x1); double yscale = show.scale * sh/ (y2-y1); if (arg) { if (xscale > yscale) xscale = yscale; else yscale = xscale; } double xoff = ((sw-aspx*sw)/2 - x1)/show.scale*xscale; double yoff = ((sh-aspy*sh)/2 - y1)/show.scale*yscale; cairo_translate(cairo,xoff,yoff); cairo_scale(cairo,xscale,yscale); poppler_page_render(page,cairo); cairo_surface_destroy(target); cairo_destroy(cairo); XCopyArea(dpy,region,win,gc,0,0,sw,sh,0,0); XFreePixmap(dpy,region); XDefineCursor(dpy,win,invisible_cursor); XFlush(dpy); }
static void dot(cairo_t *ctx, cairo_surface_t *buf, cairo_surface_t *cbuf, Theme *q) { XEvent ev; double qe = q->e; while (!XNextEvent(dpy, &ev)) { if (ev.type == KeyPress) { XPutBackEvent(dpy, &ev); break; } else if (ev.type == ButtonPress) { if (ev.xbutton.button == 1) q->e += 4; else if (ev.xbutton.button == 2) q->e = qe; else if (ev.xbutton.button == 3) q->e -= 4; if (q->e < 4) q->e = 4; else if (q->e > sh/4.0) q->e = sh/4.0; ev.type = MotionNotify; } if (ev.type == MotionNotify) { cairo_set_source_surface(ctx, cbuf, 0, 0); cairo_paint(ctx); cairo_set_source_rgba(ctx, q->R, q->G, q->B, q->A); cairo_arc(ctx, ev.xbutton.x, ev.xbutton.y, q->e, 0, 2*M_PI); cairo_fill(ctx); cairo_set_source_surface(show->target[0].ctx, buf, 0, 0); cairo_paint(show->target[0].ctx); } } }
static void pen(cairo_t *ctx, cairo_surface_t *buf, cairo_surface_t *cbuf, Theme *q) { XEvent ev; Bool on = False; XDefineCursor(dpy, wshow, crosshair_cursor); while (!XNextEvent(dpy, &ev)) { if (ev.type == KeyPress) { XPutBackEvent(dpy, &ev); break; } else if (ev.type == ButtonPress) { if (ev.xbutton.button == 1 && (on = !on) ) { cairo_new_sub_path(ctx); cairo_move_to(ctx, ev.xbutton.x, ev.xbutton.y); } else if (ev.xbutton.button == 2) { break; } else if (ev.xbutton.button == 3) { // TODO save changes to slide break; } } else if (ev.type == MotionNotify && on) { cairo_set_source_surface(ctx, cbuf, 0, 0); cairo_paint(ctx); cairo_set_source_rgba(ctx, q->R, q->G, q->B, q->A); cairo_line_to(ctx, ev.xbutton.x, ev.xbutton.y); cairo_stroke_preserve(ctx); cairo_set_source_surface(show->target[0].ctx, buf, 0, 0); cairo_paint(show->target[0].ctx); } } }
void Refresh(void) { XEvent report; unsigned long mask_event; int count = 0; /* * Check for X events that require redrawing the screen... */ while (1) { mask_event = ButtonPressMask | StructureNotifyMask | ExposureMask; while (XCheckMaskEvent(G_xStruct->display, mask_event, &report) == True) { /* put it back first before checking for ButtonPress */ XPutBackEvent(G_xStruct->display, &report); if (cur_img.error_condition == FALSE) { if (XCheckTypedWindowEvent(G_xStruct->display, xcur_img.image_window, ButtonPress, &report) == True) return; } else { if (XCheckTypedWindowEvent(G_xStruct->display, G_big_window, ButtonPress, &report) == True) return; } RefreshImageData(&cur_img, &xcur_img); } (void) sleep(1); } }
void htime(XtPointer client_data, XtIntervalId *timer) { XEvent bogus_event; Display** displays; int numdr; #ifdef DEBUG printf("here\n"); #endif if(--tsec == 0) { // XtDestroyApplicationContext (app_context); #ifdef DEBUG printf("alive\n"); #endif /* This is EVIL */ tflag = 1; XtGetDisplays(app_context, &displays, &numdr); bogus_event.type = 0; /* XAnyEvent type, ignored. */ bogus_event.xany.display = displays[0]; bogus_event.xany.window = 0; XPutBackEvent(displays[0], &bogus_event); XtAppSetExitFlag (app_context); } else { timer = (XtIntervalId)XtAppAddTimeOut(app_context, (unsigned long)1000, (XtTimerCallbackProc)htime, test); } }
static void custom(cairo_t *ctx, cairo_surface_t *buf, cairo_surface_t *cbuf, Theme *q, const char *str) { XEvent ev; double qe = q->e; while (!XNextEvent(dpy, &ev)) { if (ev.type == KeyPress) { XPutBackEvent(dpy, &ev); break; } else if (ev.type == ButtonPress) { if (ev.xbutton.button == 1) q->e += 4; else if (ev.xbutton.button == 2) q->e = qe; else if (ev.xbutton.button == 3) q->e -= 4; if (q->e < 4) q->e = 4; else if (q->e > sh/4.0) q->e = sh/4.0; ev.type = MotionNotify; } if (ev.type == MotionNotify) { cairo_set_source_surface(ctx, cbuf, 0, 0); cairo_paint(ctx); cairo_set_source_rgba(ctx, q->R, q->G, q->B, q->A); cairo_move_to(ctx, ev.xbutton.x, ev.xbutton.y); cairo_set_font_size(ctx, q->e); cairo_show_text(ctx, str); cairo_fill(ctx); cairo_set_source_surface(show->target[0].ctx, buf, 0, 0); cairo_paint(show->target[0].ctx); } } }
static int isAutoRepeat(Display * dpy, Window win, XEvent * e) { XEvent next; XCheckTypedWindowEvent(dpy, win, KeyPress, &next); XPutBackEvent(dpy, &next); return next.xkey.keycode == e->xkey.keycode && next.xkey.time - e->xkey.time < 2; }
void rclick_root(void) { XEvent ev; if (!grab(root, MouseMask, None)) { return; } draw_menubar(); do { XMaskEvent(dsply, MouseMask|KeyMask, &ev); switch (ev.type) { case MotionNotify: if (ev.xmotion.y < BARHEIGHT()) { ungrab(); rclick_taskbar(ev.xmotion.x); return; } break; case KeyPress: XPutBackEvent(dsply, &ev); break; } } while (ev.type != ButtonRelease && ev.type != KeyPress); redraw_taskbar(); ungrab(); }
void _glfwPlatformWaitEvents(void) { XEvent event; // Block waiting for an event to arrive XNextEvent(_glfwLibrary.X11.display, &event); XPutBackEvent(_glfwLibrary.X11.display, &event); _glfwPlatformPollEvents(); }
void idle_timer (XtPointer closure, XtIntervalId *id) { saver_info *si = (saver_info *) closure; XEvent fake_event; fake_event.type = 0; /* XAnyEvent type, ignored. */ fake_event.xany.display = si->dpy; fake_event.xany.window = 0; XPutBackEvent (si->dpy, &fake_event); }
int OGLwin_QTest(void) { XEvent e; if (XCheckIfEvent(Dsp, &e, CheckForWindowEvent, (XPointer) XWindow)) { XPutBackEvent(Dsp, &e); return (1); } else return (0); }
int gfx_event_waiting() { XEvent event; if(XCheckWindowEvent(gfx_display,gfx_window,KeyPressMask|ButtonPressMask,&event)) { XPutBackEvent(gfx_display,&event); return 1; } else { return 0; } }
int kbhit() { XEvent xev; if (XCheckWindowEvent(dpy, win, KeyPressMask, &xev)) { XPutBackEvent(dpy, &xev); return(1); } return(0); }
void sendMessage(void * vp, unsigned long type , unsigned long message){ BWindow self = vp; XEvent xe; xe.type = ClientMessage; xe.xclient.window = self->hwindow; xe.xclient.message_type = bl_message; xe.xclient.data.l[0] = type; xe.xclient.data.l[1] = (long)self; xe.xclient.data.l[2] = (long)message; XPutBackEvent(display, &xe); XSync(display, False); }
//retorna 1 para evento de teclado e 2 para evento de mouse //0 se não tem nenhum evento no buffer int evento_aconteceu(){ XEvent event; repintar(); while (1) { if(XCheckMaskEvent(gfx_display,-1,&event)) { if(event.type==KeyPress) { XPutBackEvent(gfx_display,&event); return 1; } else if (event.type==ButtonPress) { XPutBackEvent(gfx_display,&event); return 2; } else { return 0; } } else { return 0; } } }
void rclick_taskbar(int x) { XEvent ev; int mousex, mousey; Rect bounddims; unsigned int current_item = UINT_MAX; Window constraint_win; XSetWindowAttributes pattr; get_mouse_position(&mousex, &mousey); bounddims.x = 0; bounddims.y = 0; bounddims.width = DisplayWidth(dsply, screen); bounddims.height = BARHEIGHT(); constraint_win = XCreateWindow(dsply, root, bounddims.x, bounddims.y, bounddims.width, bounddims.height, 0, CopyFromParent, InputOnly, CopyFromParent, 0, &pattr); XMapWindow(dsply, constraint_win); if (!(XGrabPointer(dsply, root, False, MouseMask, GrabModeAsync, GrabModeAsync, constraint_win, None, CurrentTime) == GrabSuccess)) { XDestroyWindow(dsply, constraint_win); return; } draw_menubar(); update_menuitem(INT_MAX); // force initial highlight current_item = update_menuitem(x); do { XMaskEvent(dsply, MouseMask|KeyMask, &ev); switch (ev.type) { case MotionNotify: current_item = update_menuitem(ev.xmotion.x); break; case ButtonRelease: if (current_item != UINT_MAX) { fork_exec(menuitems[current_item].command); } break; case KeyPress: XPutBackEvent(dsply, &ev); break; } } while (ev.type != ButtonPress && ev.type != ButtonRelease && ev.type != KeyPress); redraw_taskbar(); XUnmapWindow(dsply, constraint_win); XDestroyWindow(dsply, constraint_win); ungrab(); }
Bool recursively_find_motion_notify (int depth) { XEvent junk_event; if (XCheckMaskEvent (dpy, 0xFFFFFFFF, &junk_event)) { XPutBackEvent (dpy, &junk_event); if (junk_event.type == MotionNotify) return True; if (depth > 0) return recursively_find_motion_notify (depth - 1); } return False; }
static void eatExpose(void) { XEvent event, foo; /* compress all expose events into a single one */ if (XCheckMaskEvent(dpy, ExposureMask, &event)) { /* ignore other exposure events for this window */ while (XCheckWindowEvent(dpy, event.xexpose.window, ExposureMask, &foo)) ; /* eat exposes for other windows */ eatExpose(); event.xexpose.count = 0; XPutBackEvent(dpy, &event); } }
bool x11EventFilter ( XEvent * event ) { if(event->type == KeyPress || event->type == KeyRelease) { XKeyEvent* key = reinterpret_cast<XKeyEvent*> (event); bool autor = false; static uint curr_autorep = 0; if (event->type == KeyPress) { if (curr_autorep == event->xkey.keycode) { autor = true; curr_autorep = 0; } } else { // look ahead for auto-repeat XEvent nextpress; Display* dpy = QX11Info::display(); // was this the last auto-repeater? x_auto_repeat_data auto_repeat_data; auto_repeat_data.keycode = event->xkey.keycode; auto_repeat_data.timestamp = event->xkey.time; auto_repeat_data.release = true; auto_repeat_data.error = false; if (XCheckIfEvent(dpy, &nextpress, &qt_keypress_scanner, (XPointer) &auto_repeat_data)) { autor = true; XPutBackEvent(dpy,&nextpress); } curr_autorep = autor ? event->xkey.keycode : 0; } if(!autor) m_mainwindow->keysActive(key->keycode, key->state, event->type == KeyPress); } return QApplication::x11EventFilter(event); }
int crt0_keypressed(void) { XEvent report; while(XCheckMaskEvent(display,ExposureMask|StructureNotifyMask,&report)) { switch(report.type) { case Expose: if (xw_expose !=NULL) (*xw_expose)(report.xexpose.x,report.xexpose.y, report.xexpose.width,report.xexpose.height); break; case ConfigureNotify: bgi_maxx=report.xconfigure.width-1; bgi_maxy=report.xconfigure.height-1; if (xw_expose !=NULL) (*xw_expose)(0,0,bgi_maxx,bgi_maxy); sizeChanged=1; } } if( XCheckMaskEvent(display,ButtonPressMask|ButtonReleaseMask|KeyPressMask| VisibilityChangeMask| ResizeRedirectMask|PropertyChangeMask|ColormapChangeMask, &report)) { switch(report.type) { case KeyPress: case ButtonPress: case ButtonRelease: XPutBackEvent(display,&report); return 1; default: return 0; } } return sizeChanged; }
void pen(const char *arg) { if (presenter_mode) fprintf(stdout,"PEN\n"); XDefineCursor(dpy,win,None); XEvent ev; int x,y,nx,ny; char pw[3] = " "; pw[0] = arg[0]; pw[1] = arg[1]; Colormap cmap = DefaultColormap(dpy,scr); XColor color; XAllocNamedColor(dpy,cmap,arg+3,&color,&color); XGCValues val; val.foreground = color.pixel; val.line_width = atoi(pw); val.cap_style = CapRound; GC pgc = XCreateGC(dpy,win,GCForeground|GCLineWidth|GCCapStyle,&val); for (;;) { while ( !XNextEvent(dpy,&ev) && ev.type!=ButtonPress && ev.type!=KeyPress ); if (ev.type == KeyPress) { XPutBackEvent(dpy,&ev); break; } XGrabPointer(dpy,ev.xbutton.window,True, PointerMotionMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync,None,None,CurrentTime); x = ev.xbutton.x; y = ev.xbutton.y; while ( !XNextEvent(dpy,&ev) && ev.type != ButtonRelease) { nx = ev.xmotion.x; ny = ev.xmotion.y; XDrawLine(dpy,win,pgc,x,y,nx,ny); x = nx; y = ny; XFlush(dpy); } XUngrabPointer(dpy,CurrentTime); } XDefineCursor(dpy,win,invisible_cursor); /* force a redraw of the background in case pens went outside of the slide */ white_muted = True; }
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; } }
static void zoom(cairo_t *ctx, cairo_surface_t *buf, cairo_surface_t *cbuf, Theme *q) { XEvent ev; double qe = q->e; int x1 = -1, y1, x2, y2; XDefineCursor(dpy, wshow, crosshair_cursor); while (!XNextEvent(dpy, &ev)) { if (ev.type == KeyPress) { XPutBackEvent(dpy, &ev); break; } else if (ev.type == ButtonPress && x1 < 0) { if (ev.xbutton.button == 1) { x1 = ev.xbutton.x; y1 = ev.xbutton.y; } } else if (ev.type == ButtonPress && x1 >= 0) { if (ev.xbutton.button == 1) { x2 = ev.xbutton.x; y2 = ev.xbutton.y; break; } else { x1 = -1; } } else if (ev.type == MotionNotify && x1 >= 0) { cairo_set_source_surface(ctx, cbuf, 0, 0); cairo_paint(ctx); cairo_set_source_rgba(ctx, q->R, q->G, q->B, q->A); cairo_rectangle(ctx, x1, y1, ev.xbutton.x - x1, ev.xbutton.y - y1); cairo_stroke(ctx); cairo_set_source_surface(show->target[0].ctx, buf, 0, 0); cairo_paint(show->target[0].ctx); } } zoom_rect(x1, y1, x2, y2); }
/** * \brief This function is called when an Extension Event is received * and calls the corresponding callback functions for these events. */ void fgHandleExtensionEvents( XEvent* base_ev ) { XEvent std_ev; /* standard single-pointer event to be added to the event queue */ int i, button = 0; XGenericEventCookie* cookie = (XGenericEventCookie*)&(base_ev->xcookie); /* initialize the generic fields from base_ev */ std_ev.xany = base_ev->xany; if ( XGetEventData( fgDisplay.pDisplay.Display, cookie ) && (cookie->type == GenericEvent) && (cookie->extension == xi_opcode) ) { XIDeviceEvent* event = (XIDeviceEvent*)(cookie->data); XIEnterEvent *evcross; /*printf("XI2 event type: %d - %d\n", cookie->evtype, event->type );*/ SFG_Window* window = fgWindowByHandle( event->event ); if (!window) return; switch (cookie->evtype) { case XI_Enter: case XI_Leave: evcross = (XIEnterEvent*)event; fgState.Modifiers = fgPlatformGetModifiers( evcross->mods.base ); INVOKE_WCB( *window, MultiEntry, ( event->deviceid, (event->evtype == XI_Enter ? GLUT_ENTERED : GLUT_LEFT) )); #if _DEBUG fgPrintXILeaveEvent((XILeaveEvent*)event); #endif /* Also process the standard crossing event */ std_ev.type = evcross->evtype == XI_Enter ? EnterNotify : LeaveNotify; std_ev.xcrossing.window = evcross->event; std_ev.xcrossing.root = evcross->root; std_ev.xcrossing.subwindow = evcross->child; std_ev.xcrossing.x = evcross->event_x; std_ev.xcrossing.y = evcross->event_y; std_ev.xcrossing.x_root = evcross->root_x; std_ev.xcrossing.y_root = evcross->root_y; std_ev.xcrossing.mode = evcross->mode; std_ev.xcrossing.detail = evcross->detail; std_ev.xcrossing.same_screen = evcross->same_screen; std_ev.xcrossing.focus = evcross->focus; std_ev.xcrossing.state = BUTTON_MASK(*(unsigned int*)evcross->buttons.mask); XPutBackEvent(fgDisplay.pDisplay.Display, &std_ev); break; case XI_ButtonPress: case XI_ButtonRelease: fgState.Modifiers = fgPlatformGetModifiers( event->mods.base ); INVOKE_WCB( *window, MultiButton, ( event->deviceid, event->event_x, event->event_y, event->detail-1, (event->evtype == XI_ButtonPress ? GLUT_DOWN : GLUT_UP) )); /* Also process the standard button event */ std_ev.type = event->evtype == XI_ButtonPress ? ButtonPress : ButtonRelease; std_ev.xbutton.window = event->event; std_ev.xbutton.root = event->root; std_ev.xbutton.subwindow = event->child; std_ev.xbutton.x = event->event_x; std_ev.xbutton.y = event->event_y; std_ev.xbutton.x_root = event->root_x; std_ev.xbutton.y_root = event->root_y; std_ev.xbutton.state = event->mods.base; std_ev.xbutton.button = event->detail; XPutBackEvent(fgDisplay.pDisplay.Display, &std_ev); break; case XI_Motion: fgState.Modifiers = fgPlatformGetModifiers( event->mods.base ); for (i = 0; i < event->buttons.mask_len; i++) { if (event->buttons.mask[i]) { button = 1; } } if (button) { INVOKE_WCB( *window, MultiMotion, ( event->deviceid, event->event_x, event->event_y ) ); } else { INVOKE_WCB( *window, MultiPassive, ( event->deviceid, event->event_x, event->event_y ) ); } #if _DEBUG fgPrintXIDeviceEvent(event); #endif /* Also process the standard motion event */ std_ev.type = MotionNotify; std_ev.xmotion.window = event->event; std_ev.xmotion.root = event->root; std_ev.xmotion.subwindow = event->child; std_ev.xmotion.time = event->time; std_ev.xmotion.x = event->event_x; std_ev.xmotion.y = event->event_y; std_ev.xmotion.x_root = event->root_x; std_ev.xmotion.y_root = event->root_y; std_ev.xmotion.state = BUTTON_MASK(*(unsigned int*)event->buttons.mask); std_ev.xmotion.is_hint = NotifyNormal; XPutBackEvent(fgDisplay.pDisplay.Display, &std_ev); break; default: #if _DEBUG fgWarning( "Unknown XI2 device event:" ); fgPrintXIDeviceEvent( event ); #endif break; } fgState.Modifiers = INVALID_MODIFIERS; } XFreeEventData( fgDisplay.pDisplay.Display, cookie ); }
int XMenuActivate( register Display *display, /* Display to put menu on. */ register XMenu *menu, /* Menu to activate. */ int *p_num, /* Pane number selected. */ int *s_num, /* Selection number selected. */ int x_pos, /* X coordinate of menu position. */ int y_pos, /* Y coordinate of menu position. */ unsigned int event_mask, /* Mouse button event mask. */ char **data, /* Pointer to return data value. */ void (*help_callback) (char const *, int, int)) /* Help callback. */ { int status; /* X routine call status. */ int orig_x; /* Upper left menu origin X coord. */ int orig_y; /* Upper left menu origin Y coord. */ int ret_val; /* Return value. */ register XMPane *p_ptr; /* Current XMPane. */ register XMPane *event_xmp; /* Event XMPane pointer. */ register XMPane *cur_p; /* Current pane. */ register XMSelect *cur_s; /* Current selection. */ XMWindow *event_xmw; /* Event XMWindow pointer. */ XEvent event; /* X input event. */ XEvent peek_event; /* X input peek ahead event. */ Bool selection = False; /* Selection has been made. */ Bool forward = True; /* Moving forward in the pane list. */ Window root, child; int root_x, root_y, win_x, win_y; unsigned int mask; KeySym keysym; /* * Define and allocate a foreign event queue to hold events * that don't belong to XMenu. These events are later restored * to the X event queue. */ typedef struct _xmeventque { XEvent event; struct _xmeventque *next; } XMEventQue; XMEventQue *feq = NULL; /* Foreign event queue. */ XMEventQue *feq_tmp; /* Foreign event queue temporary. */ /* * If there are no panes in the menu then return failure * because the menu is not initialized. */ if (menu->p_count == 0) { _XMErrorCode = XME_NOT_INIT; return(XM_FAILURE); } /* * Find the desired current pane. */ cur_p = _XMGetPanePtr(menu, *p_num); if (cur_p == NULL) { return(XM_FAILURE); } cur_p->activated = cur_p->active; /* * Find the desired current selection. * If the current selection index is out of range a null current selection * will be assumed and the cursor will be placed in the current pane * header. */ cur_s = _XMGetSelectionPtr(cur_p, *s_num); /* * Compute origin of menu so that cursor is in * Correct pane and selection. */ _XMTransToOrigin(display, menu, cur_p, cur_s, x_pos, y_pos, &orig_x, &orig_y); menu->x_pos = orig_x; /* Store X and Y coords of menu. */ menu->y_pos = orig_y; if (XMenuRecompute(display, menu) == XM_FAILURE) { return(XM_FAILURE); } /* * Flush the window creation queue. * This batches all window creates since lazy evaluation * is more efficient than individual evaluation. * This routine also does an XFlush(). */ if (_XMWinQueFlush(display, menu, cur_p, cur_s) == _FAILURE) { return(XM_FAILURE); } /* * Make sure windows are in correct order (in case we were passed * an already created menu in incorrect order.) */ for(p_ptr = menu->p_list->next; p_ptr != cur_p; p_ptr = p_ptr->next) XRaiseWindow(display, p_ptr->window); for(p_ptr = menu->p_list->prev; p_ptr != cur_p->prev; p_ptr = p_ptr->prev) XRaiseWindow(display, p_ptr->window); /* * Make sure all selection windows are mapped. */ for ( p_ptr = menu->p_list->next; p_ptr != menu->p_list; p_ptr = p_ptr->next ){ XMapSubwindows(display, p_ptr->window); } /* * Synchronize the X buffers and the event queue. * From here on, all events in the queue that don't belong to * XMenu are sent back to the application via an application * provided event handler or discarded if the application has * not provided an event handler. */ XSync(display, 0); /* * Grab the mouse for menu input. */ status = XGrabPointer( display, menu->parent, True, event_mask, GrabModeAsync, GrabModeAsync, None, menu->mouse_cursor, CurrentTime ); if (status == Success && x_menu_grab_keyboard) { status = XGrabKeyboard (display, menu->parent, False, GrabModeAsync, GrabModeAsync, CurrentTime); if (status != Success) XUngrabPointer(display, CurrentTime); } if (status == _X_FAILURE) { _XMErrorCode = XME_GRAB_MOUSE; return(XM_FAILURE); } /* * Map the menu panes. */ XMapWindow(display, cur_p->window); for (p_ptr = menu->p_list->next; p_ptr != cur_p; p_ptr = p_ptr->next) XMapWindow(display, p_ptr->window); for (p_ptr = cur_p->next; p_ptr != menu->p_list; p_ptr = p_ptr->next) XMapWindow(display, p_ptr->window); XRaiseWindow(display, cur_p->window); /* Make sure current */ /* pane is on top. */ cur_s = NULL; /* Clear current selection. */ /* * Begin event processing loop. */ while (1) { if (wait_func) (*wait_func) (wait_data); XNextEvent(display, &event); /* Get next event. */ switch (event.type) { /* Dispatch on the event type. */ case Expose: event_xmp = (XMPane *)XLookUpAssoc(display, menu->assoc_tab, event.xexpose.window); if (event_xmp == NULL) { /* * If AEQ mode is enabled then queue the event. */ if (menu->aeq) { feq_tmp = (XMEventQue *)malloc(sizeof(XMEventQue)); if (feq_tmp == NULL) { _XMErrorCode = XME_CALLOC; return(XM_FAILURE); } feq_tmp->event = event; feq_tmp->next = feq; feq = feq_tmp; } else if (_XMEventHandler) (*_XMEventHandler)(&event); break; } if (event_xmp->activated) { XSetWindowBackground(display, event_xmp->window, menu->bkgnd_color); } else { XSetWindowBackgroundPixmap(display, event_xmp->window, menu->inact_pixmap); } _XMRefreshPane(display, menu, event_xmp); break; case EnterNotify: /* * First wait a small period of time, and see * if another EnterNotify event follows hard on the * heels of this one. i.e., the user is simply * "passing through". If so, ignore this one. */ event_xmw = (XMWindow *)XLookUpAssoc(display, menu->assoc_tab, event.xcrossing.window); if (event_xmw == NULL) break; if (event_xmw->type == SELECTION) { /* * We have entered a selection. */ /* if (XPending(display) == 0) usleep(150000); */ if (XPending(display) != 0) { XPeekEvent(display, &peek_event); if(peek_event.type == LeaveNotify) { break; } } cur_s = (XMSelect *)event_xmw; help_callback (cur_s->help_string, cur_p->serial, cur_s->serial); /* * If the pane we are in is active and the * selection entered is active then activate * the selection. */ if (cur_p->active && cur_s->active > 0) { cur_s->activated = 1; _XMRefreshSelection(display, menu, cur_s); } } else { /* * We have entered a pane. */ /* if (XPending(display) == 0) usleep(150000); */ if (XPending(display) != 0) { XPeekEvent(display, &peek_event); if (peek_event.type == EnterNotify) break; } XQueryPointer(display, menu->parent, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask); event_xmp = (XMPane *)XLookUpAssoc(display, menu->assoc_tab, child); if (event_xmp == NULL) break; if (event_xmp == cur_p) break; if (event_xmp->serial > cur_p->serial) forward = True; else forward = False; p_ptr = cur_p; while (p_ptr != event_xmp) { if (forward) p_ptr = p_ptr->next; else p_ptr = p_ptr->prev; XRaiseWindow(display, p_ptr->window); } if (cur_p->activated) { cur_p->activated = False; XSetWindowBackgroundPixmap(display, cur_p->window, menu->inact_pixmap); _XMRefreshPane(display, menu, cur_p); } if (event_xmp->active) event_xmp->activated = True; #if 1 /* * i suspect the we don't get an EXPOSE event when backing * store is enabled; the menu windows content is probably * not drawn in when it should be in that case. * in that case, this is probably an ugly fix! * i hope someone more familiar with this code would * take it from here. -- [email protected]. */ XSetWindowBackground(display, event_xmp->window, menu->bkgnd_color); _XMRefreshPane(display, menu, event_xmp); #endif cur_p = event_xmp; } break; case LeaveNotify: event_xmw = (XMWindow *)XLookUpAssoc( display, menu->assoc_tab, event.xcrossing.window ); if (event_xmw == NULL) break; if(cur_s == NULL) break; /* * If the current selection was activated then * deactivate it. */ if (cur_s->activated) { cur_s->activated = False; _XMRefreshSelection(display, menu, cur_s); } cur_s = NULL; break; case ButtonPress: case ButtonRelease: *p_num = cur_p->serial; /* * Check to see if there is a current selection. */ if (cur_s != NULL) { /* * Set the selection number to the current selection. */ *s_num = cur_s->serial; /* * If the current selection was activated then * we have a valid selection otherwise we have * an inactive selection. */ if (cur_s->activated) { *data = cur_s->data; ret_val = XM_SUCCESS; } else { ret_val = XM_IA_SELECT; } } else { /* * No selection was current. */ ret_val = XM_NO_SELECT; } selection = True; break; case KeyPress: case KeyRelease: keysym = XLookupKeysym (&event.xkey, 0); /* Pop down on C-g and Escape. */ if ((keysym == XK_g && (event.xkey.state & ControlMask) != 0) || keysym == XK_Escape) /* Any escape, ignore modifiers. */ { ret_val = XM_NO_SELECT; selection = True; } break; default: /* * If AEQ mode is enabled then queue the event. */ if (menu->aeq) { feq_tmp = (XMEventQue *)malloc(sizeof(XMEventQue)); if (feq_tmp == NULL) { _XMErrorCode = XME_CALLOC; return(XM_FAILURE); } feq_tmp->event = event; feq_tmp->next = feq; feq = feq_tmp; } else if (_XMEventHandler) (*_XMEventHandler)(&event); } /* * If a selection has been made, break out of the event loop. */ if (selection == True) break; } /* * Unmap the menu. */ for ( p_ptr = menu->p_list->next; p_ptr != menu->p_list; p_ptr = p_ptr->next) { XUnmapWindow(display, p_ptr->window); } /* * Ungrab the mouse. */ XUngrabPointer(display, CurrentTime); XUngrabKeyboard(display, CurrentTime); /* * Restore bits under where the menu was if we managed * to save them and free the pixmap. */ /* * If there is a current selection deactivate it. */ if (cur_s != NULL) cur_s->activated = 0; /* * Deactivate the current pane. */ cur_p->activated = 0; XSetWindowBackgroundPixmap(display, cur_p->window, menu->inact_pixmap); /* * Synchronize the X buffers and the X event queue. */ XSync(display, 0); /* * Dispatch any events remaining on the queue. */ while (QLength(display)) { /* * Fetch the next event. */ XNextEvent(display, &event); /* * Discard any events left on the queue that belong to XMenu. * All others are held and then returned to the event queue. */ switch (event.type) { case Expose: case EnterNotify: case LeaveNotify: case ButtonPress: case ButtonRelease: /* * Does this event belong to one of XMenu's windows? * If so, discard it and process the next event. * If not fall through and treat it as a foreign event. */ event_xmp = (XMPane *)XLookUpAssoc( display, menu->assoc_tab, event.xbutton.window ); if (event_xmp != NULL) continue; default: /* * This is a foreign event. * Queue it for later return to the X event queue. */ feq_tmp = (XMEventQue *)malloc(sizeof(XMEventQue)); if (feq_tmp == NULL) { _XMErrorCode = XME_CALLOC; return(XM_FAILURE); } feq_tmp->event = event; feq_tmp->next = feq; feq = feq_tmp; } } /* * Return any foreign events that were queued to the X event queue. */ while (feq != NULL) { feq_tmp = feq; XPutBackEvent(display, &feq_tmp->event); feq = feq_tmp->next; free((char *)feq_tmp); } wait_func = 0; /* * Return successfully. */ _XMErrorCode = XME_NO_ERROR; return(ret_val); }
/* * Attempt to read bytes from the mouse and interpret them. * Returns -1 on error, 0 if either no bytes were read or not enough * was read for a complete state, or 1 if the new state was read. * When a new state is read, the current buttons and x and y deltas * are returned. This routine does not block. */ static int X11_Read(MWCOORD *dx, MWCOORD *dy, MWCOORD *dz, int *bp) { static int noevent_count = 0; XEvent ev; int events = 0; long mask = /* x11_event_mask | */ #ifdef USE_EXPOSURE ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask; #else ButtonPressMask | ButtonReleaseMask | PointerMotionMask; #endif while (XCheckMaskEvent(x11_dpy, mask, &ev)) { if (ev.type == MotionNotify) { if (ev.xmotion.window == x11_win) { int button = 0; *dx = ev.xmotion.x; *dy = ev.xmotion.y; *dz = 0; if (ev.xmotion.state & Button1Mask) button |= MWBUTTON_L; if (ev.xmotion.state & Button2Mask) button |= MWBUTTON_M; if (ev.xmotion.state & Button3Mask) button |= MWBUTTON_R; *bp = button; events++; } } else if (ev.type == ButtonPress) { if (ev.xbutton.window == x11_win) { int button = 0; /* Get pressed button */ if(ev.xbutton.button == 1) button = MWBUTTON_L; else if(ev.xbutton.button == 2) button = MWBUTTON_M; else if(ev.xbutton.button == 3) button = MWBUTTON_R; /* Get any other buttons that might be already held */ if (ev.xbutton.state & Button1Mask) button |= MWBUTTON_L; if (ev.xbutton.state & Button2Mask) button |= MWBUTTON_M; if (ev.xbutton.state & Button3Mask) button |= MWBUTTON_R; /* printf("!Pressing button: 0x%x, state: 0x%x, button: 0x%x\n", button,ev.xbutton.state, ev.xbutton.button);*/ *bp = button; *dx = ev.xbutton.x; *dy = ev.xbutton.y; *dz = 0; events++; } } else if (ev.type == ButtonRelease) { if (ev.xbutton.window == x11_win) { int button = 0; int released = 0; /* Get released button */ if(ev.xbutton.button == 1) released = MWBUTTON_L; else if(ev.xbutton.button == 2) released = MWBUTTON_M; else if(ev.xbutton.button == 3) released = MWBUTTON_R; /* Get any other buttons that might be already held */ if (ev.xbutton.state & Button1Mask) button |= MWBUTTON_L; if (ev.xbutton.state & Button2Mask) button |= MWBUTTON_M; if (ev.xbutton.state & Button3Mask) button |= MWBUTTON_R; /* We need to remove the released button from the button mask*/ button &= ~released; /*printf("!Releasing button: 0x%x, state: 0x%x, button: 0x%x\n", button,ev.xbutton.state, ev.xbutton.button);*/ *bp = button; *dx = ev.xbutton.x; *dy = ev.xbutton.y; *dz = 0; events++; } } else { x11_handle_event(&ev); } } if (events == 0) { /* after a bunch of consecutive noevent calls here (meaning select() says there's something to read but nothing is returned......), force an event read (which will most likely terminate the connection) */ if (++noevent_count >= 50) { while(XNextEvent(x11_dpy, &ev)) { /* if we return, then we got an event...put it back so we can properly process it next time through */ XPutBackEvent(x11_dpy, &ev); } noevent_count = 0; } return 0; } noevent_count = 0; return 2; /* absolute position returned*/ }
short WPgrid_dialog(DBint grw_id) /* The grid dialogue. * * In: grw_id = ID of WPGWIN that called us. * * (C)2007-03-12 J.Kjellander * ******************************************************!*/ { char rubrik[81],close[81],help[81],edit[81],pos[81], res[81],show[81],hide[81],move[81],movett[81], edittt[81],showtt[81],hidett[81],bs1[81],bs2[81], closett[81],helptt[81]; char *typ[20]; int bh,wm_x1,wm_y1,wm_x2,wm_y2,butlen,bl1,bl2,actfunc_org; short status,main_dx,main_dy,alt_x,alt_y,butlen1,butlen2,ly,lm; DBint iwin_id,move_id,edit_id,show_id,hide_id,close_id, help_id,but_id; unsigned int dum1,dum2; DBVector newpos; WPWIN *winptr; WPIWIN *iwinpt; WPBUTT *butptr; WPGWIN *gwinpt; XEvent event; XrmValue value; /* ***Set actfunc during user action, see IG/include/futab.h. */ actfunc_org = actfunc; actfunc = 103; /* ***Is this the first time this function is called ? ***Initial window position. */ if ( premiere ) { iwin_x = iwin_y = 5; if ( XrmGetResource(xresDB,"varkon.grid.geometry", "Varkon.Grid.Geometry", typ,&value) ) XParseGeometry((char *)value.addr,&iwin_x,&iwin_y,&dum1,&dum2); premiere = FALSE; } /* ***Get a C ptr to the graphical window that called us. */ gwinpt = (WPGWIN *)wpwtab[grw_id].ptr; /* ***During user interaction the dialogue window may get deleted ***and created again with new contents. This is where we start ***recreating a new instance. */ start: /* ***Window title, position, resolution, move, edit, show, hide, ***close and help from the ini-file. */ if ( !WPgrst("varkon.grid.title",rubrik) ) strcpy(rubrik,"Grid"); if ( !WPgrst("varkon.grid.position.text",pos) ) strcpy(pos,"Position"); if ( !WPgrst("varkon.grid.resolution.text",res) ) strcpy(res,"Resolution"); if ( !WPgrst("varkon.grid.show.text",show) ) strcpy(show,"Show"); if ( !WPgrst("varkon.grid.show.tooltip",showtt) ) strcpy(showtt,""); if ( !WPgrst("varkon.grid.hide.text",hide) ) strcpy(hide,"Hide"); if ( !WPgrst("varkon.grid.hide.tooltip",hidett) ) strcpy(hidett,""); if ( !WPgrst("varkon.grid.move.text",move) ) strcpy(move,"Move"); if ( !WPgrst("varkon.grid.move.tooltip",movett) ) strcpy(movett,""); if ( !WPgrst("varkon.grid.edit.text",edit) ) strcpy(edit,"Edit"); if ( !WPgrst("varkon.grid.edit.tooltip",edittt) ) strcpy(edittt,""); if ( !WPgrst("varkon.input.close",close) ) strcpy(close,"Close"); if ( !WPgrst("varkon.input.close.tooltip",closett) ) strcpy(closett,""); if ( !WPgrst("varkon.input.help",help) ) strcpy(help,"Help"); if ( !WPgrst("varkon.input.help.tooltip",helptt) ) strcpy(helptt,""); /* ***What is the 1.2*length of the longest text ? ***Don't include the title, it will fit anyhow. */ butlen1 = 0; if ( WPstrl(pos) > butlen1 ) butlen1 = WPstrl(pos); if ( WPstrl(res) > butlen1 ) butlen1 = WPstrl(res); if ( WPstrl(move) > butlen1 ) butlen1 = WPstrl(move); if ( WPstrl(edit) > butlen1 ) butlen1 = WPstrl(edit); if ( WPstrl(show) > butlen1 ) butlen1 = WPstrl(show); if ( WPstrl(hide) > butlen1 ) butlen1 = WPstrl(hide); butlen1 *= 1.2; butlen2 = 0; if ( WPstrl(close) > butlen2 ) butlen2 = WPstrl(close); if ( WPstrl(help) > butlen2 ) butlen2 = WPstrl(help); butlen2 *= 1.8; /* ***Calculate outside air (ly), button height (bh) and air between (lm). */ ly = (short)(1.2*WPstrh()); bh = (short)(1.8*WPstrh()); lm = (short)(0.8*WPstrh()); /* ***Calculate the window size in X-direction. */ main_dx = ly + butlen1 + ly + ly + butlen1 + ly; /* ***Calculate the window size in Y-direction. */ main_dy = ly + bh + lm + bh + 0 + bh + lm + bh + bh + bh + bh + bh + bh + ly; /* ***Create the dialogue window as a WPIWIN. */ WPwciw((short)iwin_x,(short)iwin_y,main_dx,main_dy,rubrik,&iwin_id); /* ***Get a C-ptr to the WPIWIN. */ winptr = WPwgwp((wpw_id)iwin_id); iwinpt = (WPIWIN *)winptr->ptr; /* ***A vertical line. */ alt_x = ly + butlen1 + ly; alt_y = ly + lm; WPcreate_3Dline(iwin_id,alt_x,alt_y,alt_x,alt_y + 4*bh + 2*ly - 2*lm); /* ***Position and resolution texts. */ alt_x = ly; alt_y = ly; WPcrlb((wpw_id)iwin_id,alt_x,alt_y,butlen1,bh,pos,&but_id); alt_x = ly + butlen1 + ly + ly; WPcrlb((wpw_id)iwin_id,alt_x,alt_y,butlen1,bh,res,&but_id); /* ***X, Y, DX and DY texts. */ sprintf(bs1,"X = %g",gwinpt->grid_x); bl1 = WPstrl(bs1); sprintf(bs2,"Y = %g",gwinpt->grid_y); bl2 = WPstrl(bs2); if ( bl1 > bl2 ) butlen = bl1; else butlen = bl2; alt_x = (ly + butlen1 + ly - butlen)/2; alt_y = ly + bh + lm; WPcrlb((wpw_id)iwin_id,alt_x,alt_y,bl1,bh,bs1,&but_id); alt_y = ly + bh + lm + bh; WPcrlb((wpw_id)iwin_id,alt_x,alt_y,bl2,bh,bs2,&but_id); sprintf(bs1,"DX = %g",gwinpt->grid_dx); bl1 = WPstrl(bs1); sprintf(bs2,"DY = %g",gwinpt->grid_dy); bl2 = WPstrl(bs2); if ( bl1 > bl2 ) butlen = bl1; else butlen = bl2; alt_x = ly + ly + butlen1 + (ly + butlen1 + ly - butlen)/2; alt_y = ly + bh + lm; WPcrlb((wpw_id)iwin_id,alt_x,alt_y,bl1,bh,bs1,&but_id); alt_y = ly + bh + lm + bh; WPcrlb((wpw_id)iwin_id,alt_x,alt_y,bl2,bh,bs2,&but_id); /* ***Move and edit. */ alt_x = ly; alt_y += bh + lm; status = WPcrpb((wpw_id)iwin_id,alt_x,alt_y,butlen1,bh,(short)2, move,move,"",WP_BGND2,WP_FGND,&move_id); butptr = (WPBUTT *)iwinpt->wintab[move_id].ptr; strcpy(butptr->tt_str,movett); alt_x = ly + butlen1 + ly + ly; status = WPcrpb((wpw_id)iwin_id,alt_x,alt_y,butlen1,bh,(short)2, edit,edit,"",WP_BGND2,WP_FGND,&edit_id); butptr = (WPBUTT *)iwinpt->wintab[edit_id].ptr; strcpy(butptr->tt_str,edittt); /* ***Show and hide. */ alt_x = ly; alt_y += bh + bh; status = WPcrpb((wpw_id)iwin_id,alt_x,alt_y,butlen1,bh,(short)2, show,show,"",WP_BGND2,WP_FGND,&show_id); butptr = (WPBUTT *)iwinpt->wintab[show_id].ptr; strcpy(butptr->tt_str,showtt); alt_x = ly + butlen1 + ly + ly; status = WPcrpb((wpw_id)iwin_id,alt_x,alt_y,butlen1,bh,(short)2, hide,hide,"",WP_BGND2,WP_FGND,&hide_id); butptr = (WPBUTT *)iwinpt->wintab[hide_id].ptr; strcpy(butptr->tt_str,hidett); /* ***A horizontal line. */ alt_x = main_dx/8; alt_y += bh + bh; WPcreate_3Dline(iwin_id,alt_x,alt_y,alt_x + 6*main_dx/8,alt_y); /* ***Close and help. */ alt_x = ly; alt_y += bh; status = WPcrpb((wpw_id)iwin_id,alt_x,alt_y,butlen2,bh,(short)3, close,close,"",WP_BGND2,WP_FGND,&close_id); butptr = (WPBUTT *)iwinpt->wintab[close_id].ptr; strcpy(butptr->tt_str,closett); alt_x = main_dx - ly - butlen2; status = WPcrpb((wpw_id)iwin_id,alt_x,alt_y,butlen2,bh,(short)2, help,help,"",WP_BGND2,WP_FGND,&help_id); butptr = (WPBUTT *)iwinpt->wintab[help_id].ptr; strcpy(butptr->tt_str,helptt); /* ***Show the dialogue. */ WPwshw(iwin_id); XRaiseWindow(xdisp,iwinpt->id.x_id); /* ***Where did it actually get positioned ? ***This code copied from WPmsip(). */ XWindowEvent(xdisp,iwinpt->id.x_id,ExposureMask,&event); XPutBackEvent(xdisp,&event); WPgtwp(iwinpt->id.x_id,&wm_x1,&wm_y1); /* ***Wait for action. SMBPOSM is not an issue in this situation. */ status = 0; loop: if ( WPwwtw(iwin_id,SLEVEL_V3_INP,&but_id) == SMBPOSM ) goto loop; /* ***Move button. */ if ( but_id == move_id ) { WPaddmess_mcwin(IGgtts(44),WP_PROMPT); status = IGcpov(&newpos); WPerhg(); IGrsma(); if ( status == 0 ) { WPdelete_grid(grw_id); gwinpt->grid_x = newpos.x_gm; gwinpt->grid_y = newpos.y_gm; WPdraw_grid(grw_id); goto update; } else goto loop; } /* ***Edit button. */ else if ( but_id == edit_id ) { status = get_resolution(gwinpt,&newpos.x_gm,&newpos.y_gm); if ( status == 0 ) { WPdelete_grid(grw_id); gwinpt->grid_dx = newpos.x_gm; gwinpt->grid_dy = newpos.y_gm; WPdraw_grid(grw_id); goto update; } else goto loop; } /* ***Show button. */ else if ( but_id == show_id ) { WPgrid_on(grw_id); WPdraw_grid(grw_id); goto loop; } /* **Hide button. */ else if ( but_id == hide_id ) { WPdelete_grid(grw_id); WPgrid_off(grw_id); goto loop; } /* ***Close button. */ else if ( but_id == close_id ) { status = 0; goto exit; } /* ***Help button. */ else if ( but_id == help_id ) { IGhelp(); goto loop; } /* ***Unknown event, should not happen. */ else { WPbell(); goto loop; } /* ***A view was added or removed so we need to update the window. ***Before deleting it, update the variables for it's current position. */ update: WPgtwp(iwinpt->id.x_id,&wm_x2,&wm_y2); iwin_x = iwin_x + wm_x2 - wm_x1; iwin_y = iwin_y + wm_y2 - wm_y1; WPwdel(iwin_id); goto start; /* ***Time to exit. Reset global actfunc. Remeber current position. */ exit: actfunc = actfunc_org; WPgtwp(iwinpt->id.x_id,&wm_x2,&wm_y2); iwin_x = iwin_x + wm_x2 - wm_x1; iwin_y = iwin_y + wm_y2 - wm_y1; WPwdel(iwin_id); return(status); }
void QX11Data::motifdndHandle(QWidget *widget, const XEvent * xe, bool /* passive */) { XEvent event = *xe; XClientMessageEvent cm ; DndData dnd_data ; char receiver ; if (!(DndParseClientMessage ((XClientMessageEvent*)&event, &dnd_data, &receiver))) { return; } switch (dnd_data.reason) { case DND_DRAG_MOTION: { QPoint p = widget->mapFromGlobal(QPoint(dnd_data.x, dnd_data.y)); QWidget *c = widget->childAt(p); if (!c || !c->acceptDrops()) { // not over a drop site if (dropWidget) { QDragLeaveEvent dragLeaveEvent; QApplication::sendEvent(dropWidget, &dragLeaveEvent); dropWidget = 0; lastAcceptedAction = Qt::IgnoreAction; dnd_data.reason = DND_DROP_SITE_LEAVE; dnd_data.time = X11->time; DndFillClientMessage (event.xclient.display, sourceWindow, &cm, &dnd_data, receiver); XSendEvent(event.xbutton.display, sourceWindow, False, 0, (XEvent *)&cm) ; } else { dnd_data.reason = DND_DRAG_MOTION; dnd_data.status = DND_NO_DROP_SITE; dnd_data.time = X11->time; dnd_data.operation = DND_NOOP; dnd_data.operations = DND_NOOP; DndFillClientMessage (event.xclient.display, sourceWindow, &cm, &dnd_data, receiver); XSendEvent(event.xbutton.display, sourceWindow, False, 0, (XEvent *)&cm) ; } } else { Q_ASSERT(c != 0); p = c->mapFrom(widget, p); if (dropWidget != c) { if (dropWidget) { QDragLeaveEvent le; QApplication::sendEvent(dropWidget, &le); } dropWidget = c; lastAcceptedAction = Qt::IgnoreAction; const Qt::DropActions possibleActions = DndOperationsToQtDropActions(dnd_data.operations); QDragEnterEvent de(p, possibleActions, QDragManager::self()->dropData, QApplication::mouseButtons(), QApplication::keyboardModifiers()); QApplication::sendEvent(dropWidget, &de); dnd_data.reason = DND_DROP_SITE_ENTER; dnd_data.time = X11->time; if (de.isAccepted()) { lastAcceptedAction = de.dropAction(); dnd_data.status = DND_VALID_DROP_SITE; dnd_data.operation = QtDropActionToDndOperation(lastAcceptedAction); } else { dnd_data.status = DND_INVALID_DROP_SITE; dnd_data.operation = DND_NOOP; dnd_data.operations = DND_NOOP; } DndFillClientMessage (event.xclient.display, sourceWindow, &cm, &dnd_data, receiver); XSendEvent(event.xbutton.display, sourceWindow, False, 0, (XEvent *)&cm); } else { const Qt::DropActions possibleActions = DndOperationsToQtDropActions(dnd_data.operations); QDragMoveEvent me(p, possibleActions, QDragManager::self()->dropData, QApplication::mouseButtons(), QApplication::keyboardModifiers()); if (lastAcceptedAction != Qt::IgnoreAction) { me.setDropAction(lastAcceptedAction); me.accept(); } QApplication::sendEvent(dropWidget, &me); dnd_data.reason = DND_DRAG_MOTION; dnd_data.time = X11->time; if (me.isAccepted()) { lastAcceptedAction = me.dropAction(); dnd_data.status = DND_VALID_DROP_SITE; dnd_data.operation = QtDropActionToDndOperation(lastAcceptedAction); } else { dnd_data.status = DND_INVALID_DROP_SITE; dnd_data.operation = DND_NOOP; dnd_data.operations = DND_NOOP; } DndFillClientMessage (event.xclient.display, sourceWindow, &cm, &dnd_data, receiver); XSendEvent(event.xbutton.display, sourceWindow, False, 0, (XEvent *)&cm); } } break; } case DND_TOP_LEVEL_ENTER: { /* get the size of our drop site for later use */ motifdnd_active = true; sourceWindow = dnd_data.src_window; /* no answer needed, just read source property */ DndReadSourceProperty (event.xclient.display, sourceWindow, dnd_data.property, &src_targets, &num_src_targets); break; } case DND_TOP_LEVEL_LEAVE: { XEvent nextEvent; if (XCheckTypedWindowEvent(X11->display, widget->winId(), ClientMessage, &nextEvent)) { // we just want to check, not eat (should use XPeekIfEvent) XPutBackEvent(X11->display, &nextEvent); if (DndParseClientMessage (&nextEvent.xclient, &dnd_data, &receiver) && dnd_data.reason == DND_DROP_START) { // expecting drop next, keeping DnD alive break; } } // not expecting drop, need to send drag leave events and such here if (dropWidget) { QDragLeaveEvent le; QApplication::sendEvent(dropWidget, &le); } sourceWindow = XNone; dropWidget = 0; lastAcceptedAction = Qt::IgnoreAction; motifdnd_active = false; break; } case DND_OPERATION_CHANGED: // ### need to echo break; case DND_DROP_START: { Q_ASSERT(motifdnd_active); Q_ASSERT(sourceWindow == dnd_data.src_window); if (!dropWidget || lastAcceptedAction == Qt::IgnoreAction) { // echo DROP_START dnd_data.reason = DND_DROP_START; dnd_data.status = DND_NO_DROP_SITE; dnd_data.operation = DND_NOOP; dnd_data.operations = DND_NOOP; DndFillClientMessage (event.xclient.display, sourceWindow, &cm, &dnd_data, 0); XSendEvent(event.xbutton.display, sourceWindow, False, 0, (XEvent *)&cm); // we have to convert selection in order to indicate failure to the initiator XConvertSelection (X11->display, dnd_data.property, ATOM(XmTRANSFER_FAILURE), dnd_data.property, dnd_data.src_window, dnd_data.time); if (dropWidget) { QDragLeaveEvent e; QApplication::sendEvent(dropWidget, &e); } motifdnd_active = false; sourceWindow = XNone; dropWidget = 0; lastAcceptedAction = Qt::IgnoreAction; return; } // store selection and its time Dnd_selection = dnd_data.property; Dnd_selection_time = dnd_data.time; QPoint p(dnd_data.x, dnd_data.y); QDropEvent de(dropWidget->mapFromGlobal(p), Qt::CopyAction, QDragManager::self()->dropData, QApplication::mouseButtons(), QApplication::keyboardModifiers()); if (lastAcceptedAction != Qt::IgnoreAction) { de.setDropAction(lastAcceptedAction); de.accept(); } QApplication::sendEvent(dropWidget, &de); // reset Dnd_selection = XNone; Dnd_selection_time = 0; // echo DROP_START depending on the result of the dropEvent if (de.isAccepted()) { dnd_data.reason = DND_DROP_START; dnd_data.status = DND_VALID_DROP_SITE; dnd_data.operation = QtDropActionToDndOperation(de.dropAction()); } else { dnd_data.reason = DND_DROP_START; dnd_data.status = DND_NO_DROP_SITE; dnd_data.operation = DND_NOOP; dnd_data.operations = DND_NOOP; } DndFillClientMessage (event.xclient.display, sourceWindow, &cm, &dnd_data, 0); XSendEvent(event.xbutton.display, sourceWindow, False, 0, (XEvent *)&cm); sourceWindow = XNone; dropWidget = 0; lastAcceptedAction = Qt::IgnoreAction; motifdnd_active = false; break; } default: break; } // end of switch (dnd_data.reason) }
// =================================== // main... // ----------------------------------- int main (int argc,char *argv[]) { XSetWindowAttributes attr; Display* dpy; Window root; char mydisp [256] = ""; int fg = 0; int screen; int c; // ============================ // get commandline options... // ---------------------------- while (1) { int option_index = 0; static struct option long_options[] = { {"display" , 1 , 0 , 'd'}, {"pid" , 1 , 0 , 'p'}, {"help" , 0 , 0 , 'h'}, {"timeout" , 1 , 0 , 't'}, {"foreground" , 0 , 0 , 'f'}, {"output" , 0 , 0 , 'o'}, {0 , 0 , 0 , 0 } }; c = getopt_long ( argc, argv, "hd:p:t:fo",long_options, &option_index ); if (c == -1) break; switch (c) { case 'h': usage(); exit(0); case 't': timeout = atoi(optarg); break; case 'd': strcpy(mydisp,optarg); break; case 'p': pid = atoi(optarg); break; case 'o': output = 1; break; case 'f': fg = 1; break; default: usage(); exit(1); } } // prove pid... // -------------- if (pid == 0) { printf("xidle: no valid pid defined\n"); exit(1); } // open display... // ------------------ if (strcmp(mydisp,"") == 0) { dpy = XOpen("null"); } else { dpy = XOpen(mydisp); } if (dpy == NULL) { printf("xidle: unable to open display: %s\n",mydisp); exit(1); } // go for daemon... // ----------------- if (fg == 0) { daemon(1,0); } // install signal handler... // -------------------------- signal( SIGHUP , handlesighup ); signal( SIGCHLD , handlesigchld ); signal( SIGTRAP , timerstatus ); signal( SIGCONT , handlesigreset ); // default window is the root window... // ------------------------------------- root = DefaultRootWindow(dpy); screen = DefaultScreen(dpy); // look if the MIT extension is available... // ------------------------------------------- if (!XScreenSaverQueryExtension (dpy, &ss_event, &ss_error)) { exit(1); } XScreenSaverSelectInput (dpy, root, ScreenSaverNotifyMask); XSync (dpy, False); // select keyboard for press and release... // ------------------------------------------ attr.event_mask = KeyPressMask | PointerMotionMask; XSelectInput(dpy, DefaultRootWindow(dpy), attr.event_mask); // set internal screen saver timeout... // --------------------------------------- timersignal(); setsaver(dpy,timeout); while(1) { XEvent event; XScreenSaverNotifyEvent *sevent; XNextEvent (dpy, &event); // ========================================== // reset timer for pointer motion events... // ------------------------------------------ if (event.type == MotionNotify) { triggerreset(); } // ===================================================== // reset timer for keyevents differently from Escape... // ----------------------------------------------------- else if (event.type == KeyPress) { XKeyEvent *e = (XKeyEvent*)&event; if (e->keycode == ESC) { Exit(); } else { triggerreset(); } } // ========================================== // catch screen saver event... // ------------------------------------------ else if (event.type == ss_event) { sevent = (XScreenSaverNotifyEvent *) &event; if (sevent->state == ScreenSaverOn) { // get screen saver event... // -------------------------- Exit(); } } // ============================================== // put back event to the queue if not handled... // ---------------------------------------------- else { XPutBackEvent(dpy,&event); } } XCloseDisplay(dpy); return(0); }
main(int argc, char * argv []) { Display * sdpy = XOpenDisplay(argv[1]); Display * tdpy = XOpenDisplay(argv[2]); int sscr = XDefaultScreen(sdpy); int tscr = XDefaultScreen(tdpy); GC tgc = DefaultGC(tdpy,tscr); Window swin=RootWindow (sdpy,sscr); int width, height, dummy; XGetGeometry(sdpy, swin, (Window *)&dummy, &dummy, &dummy, &width, &height, &dummy, &dummy); Window twin=CreateWindow(tdpy,tscr,width,height); XSelectInput(sdpy, swin, PointerMotionMask); XImage * image; XImage * simage; XImage * timage; int use_shm=1; XShmSegmentInfo xshm_sinfo; XShmSegmentInfo xshm_tinfo; if(use_shm) createShmImage(width,height,&xshm_sinfo,&xshm_tinfo,sdpy,tdpy,sscr,tscr,&simage,&timage); int frame=0; for(;;) { XEvent e; XNextEvent(tdpy, &e); if (e.type == MapNotify) break; } int emulate_events=0; int xmouse, ymouse; while(1) { { XEvent e; //long mask=ButtonPressMask|ButtonReleaseMask|MotionNotifyMask; //while(XCheckWindowEvent(tdpy, twin, mask, &e)!=False) while(XCheckTypedWindowEvent(tdpy, twin, ButtonPress, &e)!=False || XCheckTypedWindowEvent(tdpy, twin, ButtonRelease, &e)!=False) { printf("button event\n"); if(emulate_events) { e.xbutton.display=sdpy; e.xbutton.window=swin; e.xbutton.root=swin; e.xbutton.window=swin; e.xbutton.x_root=e.xbutton.x; e.xbutton.y_root=e.xbutton.y; //XSendEvent( sdpy, swin, True, mask, &e ); XPutBackEvent( sdpy, &e ); //XTestFakeMotionEvent(sdpy,sscr,e.xbutton.x,e.xbutton.y,0); XTestFakeButtonEvent(sdpy,e.xbutton.button,e.xbutton.type==ButtonPress,0); } } while(XCheckTypedWindowEvent(sdpy, swin, MotionNotify, &e)!=False) { //printf("motion event\n"); xmouse=e.xbutton.x_root; ymouse=e.xbutton.y_root; } } //printf("frame %d\n", frame++); usleep(60000); if(!use_shm) { image=CaptRoot(sdpy,sscr); DrawImage(tdpy,twin,image); XDestroyImage(image); } else { // XShmAttach(sdpy, &xshm_sinfo); XShmGetImage (sdpy, swin, simage, 0, 0, AllPlanes); // XShmAttach(sdpy, &xshm_tinfo); //printf("simage: w:%d h:%d d:%d\n",simage->width, simage->height, simage->depth); //printf("timage: w:%d h:%d d:%d\n",timage->width, timage->height, timage->depth); if(!emulate_events) { Window rwin,cwin; int xmouse,ymouse,x,y,mask; XQueryPointer(sdpy,swin,&rwin,&cwin,&xmouse,&ymouse,&x,&y,&mask); drawMouse(timage, xmouse, ymouse); } XShmPutImage (tdpy, twin, tgc, timage, 0, 0, 0, 0, timage->width, timage->height, False); //XPutImage (tdpy, twin, tgc, timage, 0, 0, 0, 0, timage->width, timage->height); } //XFlush(sdpy); XFlush(tdpy); // getchar(); } }