int main (int argc, char *argv[]) { /* connect to the X server and make a window */ Display *dpy = XOpenDisplay (getenv ("DISPLAY")); Window w = XCreateSimpleWindow (dpy, DefaultRootWindow (dpy), 100, 100, 640, 480, 1, BlackPixel (dpy, DefaultScreen (dpy)), WhitePixel (dpy, DefaultScreen (dpy))); /* raise it and wait */ XSelectInput (dpy, w, StructureNotifyMask); XMapRaised (dpy, w); for(XEvent e; ( e.type != MapNotify ); XWindowEvent (dpy, w, StructureNotifyMask, &e)); /* create a graphics context for drawing in the window */ GC g = XCreateGC (dpy, w, 0, NULL); /* draw a circle */ XDrawArc(dpy,w,g,200,100,150,150,0,360*64); XFlush(dpy); /*wait for key press*/ XSelectInput (dpy, w, KeyReleaseMask); for(XEvent e; ( e.type != KeyRelease ); XWindowEvent (dpy, w, KeyReleaseMask, &e)); /*clean up*/ XDestroyWindow( dpy, w ); XCloseDisplay (dpy); }
Window Select_Window( Display * dpy ) { /*{{{ */ /* * Routine to let user select a window using the mouse * Taken from xfree86. */ int status; Cursor cursor; XEvent event; Window target_win = None, root = DefaultRootWindow( dpy ); int buttons = 0; int dummyi; unsigned int dummy; /* Make the target cursor */ cursor = XCreateFontCursor( dpy, XC_crosshair ); /* Grab the pointer using target cursor, letting it room all over */ status = XGrabPointer( dpy, root, False, ButtonPressMask | ButtonReleaseMask, GrabModeSync, GrabModeAsync, root, cursor, CurrentTime ); if ( status != GrabSuccess ) { fputs( "ERROR: Cannot grab mouse.\n", stderr ); return 0; } /* Let the user select a window... */ while ( ( target_win == None ) || ( buttons != 0 ) ) { /* allow one more event */ XAllowEvents( dpy, SyncPointer, CurrentTime ); XWindowEvent( dpy, root, ButtonPressMask | ButtonReleaseMask, &event ); switch ( event.type ) { case ButtonPress: if ( target_win == None ) { target_win = event.xbutton.subwindow; /* window selected */ if ( target_win == None ) target_win = root; } buttons++; break; case ButtonRelease: if ( buttons > 0 ) /* there may have been some down before we started */ buttons--; break; } } XUngrabPointer( dpy, CurrentTime ); /* Done with pointer */ if ( XGetGeometry( dpy, target_win, &root, &dummyi, &dummyi, &dummy, &dummy, &dummy, &dummy ) && target_win != root ) { target_win = XmuClientWindow( dpy, target_win ); } return ( target_win ); }
static XID get_window_id(Display *dpy, int screen, int button, char *msg) { Cursor cursor; /* cursor to use when selecting */ Window root; /* the current root */ Window retwin = None; /* the window that got selected */ int retbutton = -1; /* button used to select window */ int pressed = 0; /* count of number of buttons pressed */ #define MASK (ButtonPressMask | ButtonReleaseMask) root = RootWindow (dpy, screen); cursor = XCreateFontCursor (dpy, XC_pirate); if (cursor == None) { fprintf (stderr, "%s: unable to create selection cursor\n", ProgramName); Exit (1); } printf ("Select %s with ", msg); if (button == -1) printf ("any button"); else printf ("button %d", button); printf ("....\n"); XSync (dpy, 0); /* give xterm a chance */ if (XGrabPointer (dpy, root, False, MASK, GrabModeSync, GrabModeAsync, None, cursor, CurrentTime) != GrabSuccess) { fprintf (stderr, "%s: unable to grab cursor\n", ProgramName); Exit (1); } /* from dsimple.c in xwininfo */ while (retwin == None || pressed != 0) { XEvent event; XAllowEvents (dpy, SyncPointer, CurrentTime); XWindowEvent (dpy, root, MASK, &event); switch (event.type) { case ButtonPress: if (retwin == None) { retbutton = event.xbutton.button; retwin = ((event.xbutton.subwindow != None) ? event.xbutton.subwindow : root); } pressed++; continue; case ButtonRelease: if (pressed > 0) pressed--; continue; } /* end switch */ } /* end for */ XUngrabPointer (dpy, CurrentTime); XFreeCursor (dpy, cursor); XSync (dpy, 0); return ((button == -1 || retbutton == button) ? retwin : None); }
void openWin(const char *title, int width, int height) { unsigned long blackC,whiteC; XSizeHints sh; XEvent evt; long evtmsk; whiteC = WhitePixel(dsp, DefaultScreen(dsp)); blackC = BlackPixel(dsp, DefaultScreen(dsp)); curC = blackC; win = XCreateSimpleWindow(dsp, DefaultRootWindow(dsp), 0, 0, WinW, WinH, 0, blackC, whiteC); sh.flags=PSize|PMinSize|PMaxSize; sh.width=sh.min_width=sh.max_width=WinW; sh.height=sh.min_height=sh.max_height=WinH; XSetStandardProperties(dsp, win, title, title, None, NULL, 0, &sh); XSelectInput(dsp, win, StructureNotifyMask|KeyPressMask); XMapWindow(dsp, win); do { XWindowEvent(dsp, win, StructureNotifyMask, &evt); } while (evt.type != MapNotify); gc = XCreateGC(dsp, win, 0, NULL); }
Time _XmValidTimestamp( Widget w ) { Window win; Display *dsp = XtDisplay(w); XEvent event; EventMask shellMask; Atom timeProp = XInternAtom(dsp, "_MOTIF_CURRENT_TIME", False); while (!XtIsShell(w)) w = XtParent(w); win = XtWindow(w); if (! ((shellMask = XtBuildEventMask(w)) & PropertyChangeMask) ) XSelectInput(dsp, win, shellMask | PropertyChangeMask); XChangeProperty(dsp, win, timeProp, timeProp, 8, PropModeAppend, NULL, 0); XWindowEvent(dsp, win, PropertyChangeMask, &event); if (!(shellMask & PropertyChangeMask)) XSelectInput(dsp, win, shellMask); return (event.xproperty.time); }
Time get_X_time(){ XEvent ev; XChangeProperty(display, selwindow, XA_WM_CLASS, XA_STRING, 8, PropModeAppend, NULL, 0); XWindowEvent(display, selwindow, PropertyChangeMask, &ev); warn(DEBUG_DEBUG, "X time is %ld", ev.xproperty.time); return ev.xproperty.time; }
void waitForEvent(int type) { XEvent event; do { XWindowEvent(display, window, StructureNotifyMask, &event); describeEvent(event); } while (event.type != type); }
void X11Window::unmap_window() { // Clear exisitng StructureNofify events. XEvent event; while(XCheckMaskEvent(handle.display, StructureNotifyMask, &event)); if (!is_window_mapped) { log_event("debug", "clan::X11Window::unmap_window(): Window already unmapped."); return; } log_event("debug", "clan::X11Window::map_window(): Unmapping window..."); int result = XUnmapWindow(handle.display, handle.window); if ( (result == BadValue) || (result == BadWindow) ) throw Exception("Failed to unmap window."); XFlush(handle.display); do { XWindowEvent(handle.display, handle.window, StructureNotifyMask, &event); } while (event.type != UnmapNotify); XFlush(handle.display); is_window_mapped = false; }
void waitForEvent(int type) { XEvent event; do { XWindowEvent(display, window, StructureNotifyMask | KeyPressMask, &event); processEvent(event); } while (event.type != type); }
void grab_window_position(int *src_x, int *src_y, int *width, int *height) { Cursor cursor; /* cursor to use when selecting */ Window root; /* the current root */ Window retwin = None; /* the window that got selected */ int retbutton = -1; /* button used to select window */ int pressed = 0; /* count of number of buttons pressed */ #define MASK (ButtonPressMask | ButtonReleaseMask) root = DefaultRootWindow(dpy); cursor = XCreateFontCursor(dpy, XC_pirate); if (cursor == None) { fprintf (stderr, "%s: unable to create selection cursor\n", "grab_window_position"); return; } XSync (dpy, 0); /* give xterm a chance */ if (XGrabPointer (dpy, root, False, MASK, GrabModeSync, GrabModeAsync, None, cursor, CurrentTime) != GrabSuccess) { fprintf (stderr, "%s: unable to grab cursor\n", "grab_window_position"); return; } /* from dsimple.c in xwininfo */ while (retwin == None || pressed != 0) { XEvent event; XAllowEvents (dpy, SyncPointer, CurrentTime); XWindowEvent (dpy, root, MASK, &event); switch (event.type) { case ButtonPress: if (retwin == None) { retbutton = event.xbutton.button; retwin = ((event.xbutton.subwindow != None) ? event.xbutton.subwindow : root); } pressed++; continue; case ButtonRelease: if (pressed > 0) pressed--; continue; } /* end switch */ } /* end for */ XUngrabPointer (dpy, CurrentTime); XFreeCursor (dpy, cursor); XSync (dpy, 0); if (retwin != None) { XWindowAttributes attr; XGetWindowAttributes(dpy, retwin, &attr); *src_x = attr.x; *src_y = attr.y; *width = attr.width; *height = attr.height; } else { *src_x = *src_y = *width = *height = 0; } }
void mousefunc_client_resize(void *ctx, union arg *arg, enum xev xev) { struct client_ctx *cc = ctx; XEvent ev; Time ltime = 0; struct screen_ctx *sc = cc->sc; if (cc->flags & CLIENT_FREEZE) return; client_raise(cc); client_ptrsave(cc); xu_ptr_setpos(cc->win, cc->geom.w, cc->geom.h); if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_RESIZE], CurrentTime) != GrabSuccess) return; menu_windraw(sc, cc->win, "%4d x %-4d", cc->dim.w, cc->dim.h); for (;;) { XWindowEvent(X_Dpy, cc->win, MOUSEMASK, &ev); switch (ev.type) { case MotionNotify: /* not more than 60 times / second */ if ((ev.xmotion.time - ltime) <= (1000 / 60)) continue; ltime = ev.xmotion.time; cc->geom.w = ev.xmotion.x; cc->geom.h = ev.xmotion.y; client_applysizehints(cc); client_resize(cc, 1); menu_windraw(sc, cc->win, "%4d x %-4d", cc->dim.w, cc->dim.h); break; case ButtonRelease: client_resize(cc, 1); XUnmapWindow(X_Dpy, sc->menu.win); XReparentWindow(X_Dpy, sc->menu.win, sc->rootwin, 0, 0); XUngrabPointer(X_Dpy, CurrentTime); /* Make sure the pointer stays within the window. */ if (cc->ptr.x > cc->geom.w) cc->ptr.x = cc->geom.w - cc->bwidth; if (cc->ptr.y > cc->geom.h) cc->ptr.y = cc->geom.h - cc->bwidth; client_ptrwarp(cc); return; } } /* NOTREACHED */ }
void Canvas::flush() { XEvent e; XMapRaised(display, wnd); XWindowEvent(display, wnd, ExposureMask, &e); plot(-1, -1); XCopyArea(display, buf, wnd, gc, 0, 0, width, height, 0, 0); XFlush(display); }
RedirectedXCompositeWindow::RedirectedXCompositeWindow(const IntSize& size, GLContextNeeded needsContext) : m_size(size) , m_window(0) , m_parentWindow(0) , m_pixmap(0) , m_needsContext(needsContext) , m_surface(0) , m_needsNewPixmapAfterResize(false) , m_damage(0) , m_damageNotifyCallback(0) , m_damageNotifyData(0) { Display* display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); Screen* screen = DefaultScreenOfDisplay(display); // This is based on code from Chromium: src/content/common/gpu/image_transport_surface_linux.cc XSetWindowAttributes windowAttributes; windowAttributes.override_redirect = True; m_parentWindow = XCreateWindow(display, RootWindowOfScreen(screen), WidthOfScreen(screen) + 1, 0, 1, 1, 0, CopyFromParent, InputOutput, CopyFromParent, CWOverrideRedirect, &windowAttributes); XMapWindow(display, m_parentWindow); windowAttributes.event_mask = StructureNotifyMask; windowAttributes.override_redirect = False; m_window = XCreateWindow(display, m_parentWindow, 0, 0, size.width(), size.height(), 0, CopyFromParent, InputOutput, CopyFromParent, CWEventMask, &windowAttributes); XMapWindow(display, m_window); if (getWindowHashMap().isEmpty()) gdk_window_add_filter(0, reinterpret_cast<GdkFilterFunc>(filterXDamageEvent), 0); getWindowHashMap().add(m_window, this); while (1) { XEvent event; XWindowEvent(display, m_window, StructureNotifyMask, &event); if (event.type == MapNotify && event.xmap.window == m_window) break; } XSelectInput(display, m_window, NoEventMask); XCompositeRedirectWindow(display, m_window, CompositeRedirectManual); m_damage = XDamageCreate(display, m_window, XDamageReportNonEmpty); }
int window_event (Window w, long event_mask, register XEvent * event_return) { register int res; res = XWindowEvent (dpy, w, event_mask, event_return); if (res) stash_event_time (event_return); return res; }
static GdkNativeWindow select_window(GdkScreen *screen) { Display *x_dpy; Cursor x_cursor; XEvent x_event; Window x_win = None; Window x_root; gint x_scr; gint status; gint buttons = 0; x_dpy = GDK_SCREEN_XDISPLAY (screen); x_scr = GDK_SCREEN_XNUMBER (screen); x_root = RootWindow (x_dpy, x_scr); x_cursor = XCreateFontCursor (x_dpy, GDK_CROSSHAIR); status = XGrabPointer (x_dpy, x_root, False, MASK, GrabModeSync, GrabModeAsync, x_root, x_cursor, CurrentTime); if (status != GrabSuccess) { printf("!GrabSucces\n"); return 0; } while ( (x_win == None) || (buttons != 0)) { XAllowEvents (x_dpy, SyncPointer, CurrentTime); XWindowEvent (x_dpy, x_root, MASK, &x_event); switch (x_event.type) { case ButtonPress: if (x_win == None) { x_win = x_event.xbutton.subwindow; if (x_win == None) x_win = x_root; } buttons++; break; case ButtonRelease: if (buttons > 0) buttons--; break; } } XUngrabPointer (x_dpy, CurrentTime); XFreeCursor (x_dpy, x_cursor); return x_win; }
/* from xwininfo , thanks*/ Window Select_Window(){ // Display *dpy; int status; Cursor cursor; XEvent event; Window target_win = None, root = RootWindow(dpy, default_src); int buttons = 0; /* Make the target cursor */ cursor = XCreateFontCursor(dpy, XC_crosshair); /* Grab the pointer using target cursor, letting it room all over */ status = XGrabPointer( dpy, root, False, ButtonPressMask|ButtonReleaseMask, GrabModeSync, GrabModeAsync, root, cursor, CurrentTime); if (status != GrabSuccess) printf("Can't grab the mouse."); /* Let the user select a window... */ while ((target_win == None) || (buttons != 0)) { /* allow one more event */ XAllowEvents(dpy, SyncPointer, CurrentTime); XWindowEvent(dpy, root, ButtonPressMask|ButtonReleaseMask, &event); switch (event.type) { case ButtonPress: if (target_win == None) { target_win = event.xbutton.subwindow; /* window selected */ if (target_win == None) target_win = root; } buttons++; break; case ButtonRelease: if (buttons > 0) /* there may have been some down before we started */ buttons--; break; } } XUngrabPointer(dpy, CurrentTime); /* Done with pointer */ if (target_win) { Window root; int dummyi; uint32_t dummy; if ( XGetGeometry (dpy, target_win, &root, &dummyi, &dummyi, &dummy, &dummy, &dummy, &dummy) && target_win != root) target_win = XmuClientWindow (dpy, target_win); } return(target_win); }
// Wait for keyboard/mouse input and select window static XID wait_click_window(int screen, int button) { Window root = RootWindow(dpy, screen); Cursor cursor = XCreateFontCursor(dpy, XC_question_arrow); if (cursor == None) error_exit("unable to create selection cursor"); XSync(dpy, 0); unsigned int mask = (ButtonPressMask | ButtonReleaseMask); if (XGrabPointer(dpy, root, False, mask, GrabModeSync, GrabModeAsync, None, cursor, CurrentTime) != GrabSuccess) error_exit("unable to grab pointer"); Window win = None; // the window that got selected int buttonPressed = -1; // button used to select window int pressed = 0; // count of number of buttons pressed // from dsimple.c in xwininfo while (win == None || pressed != 0) { XEvent event; XAllowEvents(dpy, SyncPointer, CurrentTime); XWindowEvent(dpy, root, mask, &event); switch (event.type) { case ButtonPress: if (win == None) { buttonPressed = event.xbutton.button; win = (event.xbutton.subwindow != None ? event.xbutton.subwindow : root); } pressed++; break; case ButtonRelease: if (pressed > 0) pressed--; break; } } XUngrabPointer(dpy, CurrentTime); XFreeCursor(dpy, cursor); XSync(dpy, 0); return ((button == -1 || buttonPressed == button) ? win : None); }
/* Copied from libcaja/caja-program-choosing.c; Needed in case * we have no DESKTOP_STARTUP_ID (with its accompanying timestamp). */ static Time slowly_and_stupidly_obtain_timestamp (Display *xdisplay) { Window xwindow; XEvent event; { XSetWindowAttributes attrs; Atom atom_name; Atom atom_type; const char *name; attrs.override_redirect = True; attrs.event_mask = PropertyChangeMask | StructureNotifyMask; xwindow = XCreateWindow (xdisplay, RootWindow (xdisplay, 0), -100, -100, 1, 1, 0, CopyFromParent, CopyFromParent, (Visual *)CopyFromParent, CWOverrideRedirect | CWEventMask, &attrs); atom_name = XInternAtom (xdisplay, "WM_NAME", TRUE); g_assert (atom_name != None); atom_type = XInternAtom (xdisplay, "STRING", TRUE); g_assert (atom_type != None); name = "Fake Window"; XChangeProperty (xdisplay, xwindow, atom_name, atom_type, 8, PropModeReplace, (unsigned char *)name, strlen (name)); } XWindowEvent (xdisplay, xwindow, PropertyChangeMask, &event); XDestroyWindow(xdisplay, xwindow); return event.xproperty.time; }
Window Select_Window(Display *disp, int descend) { int status; Cursor cursor; XEvent event; Window target_win = None, root = RootWindow(disp,screen); int buttons = 0; /* Make the target cursor */ cursor = XCreateFontCursor(disp, XC_crosshair); /* Grab the pointer using target cursor, letting it room all over */ status = XGrabPointer(disp, root, False, ButtonPressMask|ButtonReleaseMask, GrabModeSync, GrabModeAsync, root, cursor, CurrentTime); if (status != GrabSuccess) Fatal_Error("Can't grab the mouse."); /* Let the user select a window... */ while ((target_win == None) || (buttons != 0)) { /* allow one more event */ XAllowEvents(disp, SyncPointer, CurrentTime); XWindowEvent(disp, root, ButtonPressMask|ButtonReleaseMask, &event); switch (event.type) { case ButtonPress: if (target_win == None) { target_win = event.xbutton.subwindow; /* window selected */ if (target_win == None) target_win = root; } buttons++; break; case ButtonRelease: if (buttons > 0) /* there may have been some down before we started */ buttons--; break; } } XUngrabPointer(disp, CurrentTime); /* Done with pointer */ if (!descend || (target_win == root)) return(target_win); target_win = Find_Client(disp, root, target_win); return(target_win); }
void KUI_project::aimSlot() { Display *dpy = XOpenDisplay(NULL); int status; Cursor cursor; XEvent event; Window target_win = None, root = RootWindow(dpy,NULL); int buttons = 0; cursor = XCreateFontCursor(dpy, XC_crosshair); status = XGrabPointer(dpy, root, False, ButtonPressMask|ButtonReleaseMask, GrabModeSync, GrabModeAsync, root, cursor, CurrentTime); while ((target_win == None) || (buttons != 0)) { XAllowEvents(dpy, SyncPointer, CurrentTime); XWindowEvent(dpy, root, ButtonPressMask|ButtonReleaseMask, &event); switch (event.type) { case ButtonPress: if (target_win == None) { target_win = event.xbutton.subwindow; if (target_win == None) target_win = root; } buttons++; break; case ButtonRelease: if (buttons > 0) buttons--; break; } } XUngrabPointer(dpy, CurrentTime); XWindowAttributes selWin; XGetWindowAttributes(dpy, target_win, &selWin); recArea.setTopLeft( QPoint( selWin.x, selWin.y ) ); recArea.setBottomRight( QPoint( selWin.x+selWin.width, selWin.y+selWin.height ) ); XCloseDisplay(dpy); }
Window Select_Window(Display *dpy) { int status; Cursor cursor; XEvent event; Window target_win = None, root = RootWindow(dpy,DefaultScreen(dpy)); int buttons = 0; ENTER; /* Make the target cursor */ cursor = XCreateFontCursor(dpy, XC_crosshair); /* Grab the pointer using target cursor, letting it room all over */ status = XGrabPointer(dpy, root, False, ButtonPressMask|ButtonReleaseMask, GrabModeSync, GrabModeAsync, root, cursor, CurrentTime); if (status != GrabSuccess) { ERR("Can't grab the mouse."); RET(None); } /* Let the user select a window... */ while ((target_win == None) || (buttons != 0)) { /* allow one more event */ XAllowEvents(dpy, SyncPointer, CurrentTime); XWindowEvent(dpy, root, ButtonPressMask|ButtonReleaseMask, &event); switch (event.type) { case ButtonPress: if (target_win == None) { target_win = event.xbutton.subwindow; /* window selected */ DBG("target win = 0x%x\n", target_win); if (target_win == None) target_win = root; } buttons++; break; case ButtonRelease: if (buttons > 0) /* there may have been some down before we started */ buttons--; break; } } XUngrabPointer(dpy, CurrentTime); /* Done with pointer */ RET(target_win); }
void X11Window::map_window() { // Clear exisitng StructureNofify events. XEvent event; while(XCheckMaskEvent(handle.display, StructureNotifyMask, &event)); if (is_window_mapped) { if (!is_minimized()) { log_event("debug", "clan::X11Window::map_window(): Window already mapped."); return; } else log_event("debug", "clan::X11Window::map_window(): Mapping minimized window."); } log_event("debug", "clan::X11Window::map_window(): Mapping window..."); int result = XMapWindow(handle.display, handle.window); if ((result == BadValue) || (result == BadWindow)) throw Exception("Failed to map window."); XFlush(handle.display); do { XWindowEvent(handle.display, handle.window, StructureNotifyMask, &event); } while (event.type != MapNotify); XFlush(handle.display); is_window_mapped = true; if (fullscreen) { XSetInputFocus(handle.display, handle.window, RevertToParent, CurrentTime); XFlush(handle.display); } else { update_frame_extents(); set_position(client_area, true); } request_repaint(); }
/* Routine to let user select a window using the mouse adapted from xfree86. */ XCTRL_API Window select_window(Display *disp, int button) { Cursor cursor; XEvent event; Window target_win = None; Window root = DefaultRootWindow(disp); int buttons = 0; int dumi; unsigned int dum; cursor = XCreateFontCursor(disp, XC_crosshair); if (!GrabMouse()) { XFreeCursor(disp,cursor); return 0; } while ((target_win == None) || (buttons != 0)) { XAllowEvents(disp, SyncPointer, CurrentTime); XWindowEvent(disp, root, ButtonPressMask|ButtonReleaseMask, &event); switch (event.type) { case ButtonPress: if ((button==-1)||(event.xbutton.button==button)) { if (target_win == None) { target_win = event.xbutton.subwindow; /* window selected */ if (target_win == None) target_win = root; } } else { pass_click_to_client(disp,root,&event,ButtonPressMask,cursor); } buttons++; break; case ButtonRelease: if (buttons > 0) { buttons--; } if ((button!=-1)&&(event.xbutton.button!=button)) { pass_click_to_client(disp,root,&event,ButtonReleaseMask,cursor); } break; } } XUngrabPointer(disp, CurrentTime); if (XGetGeometry(disp,target_win,&root,&dumi,&dumi,&dum,&dum,&dum,&dum)&&target_win!=root) { target_win = XmuClientWindow(disp, target_win); } return(target_win); }
QClipboard::QClipboard(QObject *parent) : QObject(*new QClipboardPrivate, parent) { // create desktop widget since we need it to get PropertyNotify or // XFixesSelectionNotify events when someone changes the // clipboard. (void)QApplication::desktop(); #ifndef QT_NO_XFIXES if (X11->use_xfixes && X11->ptrXFixesSelectSelectionInput) { const unsigned long eventMask = XFixesSetSelectionOwnerNotifyMask | XFixesSelectionWindowDestroyNotifyMask | XFixesSelectionClientCloseNotifyMask; for (int i = 0; i < X11->screenCount; ++i) { X11->ptrXFixesSelectSelectionInput(X11->display, QX11Info::appRootWindow(i), XA_PRIMARY, eventMask); X11->ptrXFixesSelectSelectionInput(X11->display, QX11Info::appRootWindow(i), ATOM(CLIPBOARD), eventMask); } } #endif // QT_NO_XFIXES if (X11->time == CurrentTime) { // send a dummy event to myself to get the timestamp from X11. qt_init_timestamp_data data; data.timestamp = CurrentTime; XEvent ev; XCheckIfEvent(X11->display, &ev, &qt_init_timestamp_scanner, (XPointer)&data); if (data.timestamp == CurrentTime) { setupOwner(); // We need this value just for completeness, we don't use it. long dummy = 0; Window ownerId = owner->internalWinId(); XChangeProperty(X11->display, ownerId, ATOM(CLIP_TEMPORARY), XA_INTEGER, 32, PropModeReplace, (uchar*)&dummy, 1); XWindowEvent(X11->display, ownerId, PropertyChangeMask, &ev); data.timestamp = ev.xproperty.time; XDeleteProperty(X11->display, ownerId, ATOM(CLIP_TEMPORARY)); } X11->time = data.timestamp; } }
/* Updates qt_x_time. This used to simply fetch current timestamp from the server, but that can cause qt_x_time to be newer than timestamp of events that are still in our events queue, thus e.g. making XSetInputFocus() caused by such event to be ignored. Therefore events queue is searched for first event with timestamp, and extra PropertyNotify is generated in order to make sure such event is found. */ void updateXTime() { static QWidget *w = 0; if(!w) w = new QWidget; long data = 1; XChangeProperty(qt_xdisplay(), w->winId(), atoms->kwin_running, atoms->kwin_running, 32, PropModeAppend, (unsigned char *)&data, 1); next_x_time = CurrentTime; XEvent dummy; XCheckIfEvent(qt_xdisplay(), &dummy, update_x_time_predicate, NULL); if(next_x_time == CurrentTime) { XSync(qt_xdisplay(), False); XCheckIfEvent(qt_xdisplay(), &dummy, update_x_time_predicate, NULL); } assert(next_x_time != CurrentTime); qt_x_time = next_x_time; XEvent ev; // remove the PropertyNotify event from the events queue XWindowEvent(qt_xdisplay(), w->winId(), PropertyChangeMask, &ev); }
Time GetTimestamp (Display *dpy) { XEvent event; XWindowAttributes attr; Window rwin = RootWindowOfScreen(XtScreen(utmShell)); Atom time_atom = XInternAtom(dsp, "_MOTIF_CURRENT_TIME", False); XGetWindowAttributes(dsp, rwin, &attr); if (! (attr.your_event_mask & PropertyChangeMask)) XSelectInput(dsp, rwin, attr.your_event_mask | PropertyChangeMask); XChangeProperty(dsp, rwin, time_atom, time_atom, 8, PropModeAppend, NULL, 0); XWindowEvent(dsp, rwin, PropertyChangeMask, &event); if (! (attr.your_event_mask & PropertyChangeMask)) XSelectInput(dsp, rwin, attr.your_event_mask); return(event.xproperty.time); }
void sendUserTime(const char *app) { #if defined Q_WS_X11 static unsigned long time = 0; if(time == 0) { Display *dpy = XOpenDisplay(NULL); if(dpy != NULL) { Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 1, 1, 0, 0, 0); XSelectInput(dpy, w, PropertyChangeMask); unsigned char data[1]; XChangeProperty(dpy, w, XA_ATOM, XA_ATOM, 8, PropModeAppend, data, 1); XEvent ev; XWindowEvent(dpy, w, PropertyChangeMask, &ev); time = ev.xproperty.time; XDestroyWindow(dpy, w); } } DCOPRef(app, "MainApplication-Interface").call("updateUserTimestamp", time); #else // ... #endif }
static GdkNativeWindow select_window_x11 (GdkScreen *screen) { Display *x_dpy = GDK_SCREEN_XDISPLAY (screen); gint x_scr = GDK_SCREEN_XNUMBER (screen); Window x_root = RootWindow (x_dpy, x_scr); Window x_win = None; GC x_gc = None; Cursor x_cursor = XCreateFontCursor (x_dpy, GDK_CROSSHAIR); GdkKeymapKey *keys = NULL; gint status; gint i, num_keys; gint buttons = 0; gint mask = ButtonPressMask | ButtonReleaseMask; gboolean cancel = FALSE; if (shootvals.shoot_type == SHOOT_REGION) mask |= PointerMotionMask; status = XGrabPointer (x_dpy, x_root, False, mask, GrabModeSync, GrabModeAsync, x_root, x_cursor, CurrentTime); if (status != GrabSuccess) { gint x, y; guint xmask; /* if we can't grab the pointer, return the window under the pointer */ XQueryPointer (x_dpy, x_root, &x_root, &x_win, &x, &y, &x, &y, &xmask); if (x_win == None || x_win == x_root) g_message (_("Error selecting the window")); } if (shootvals.shoot_type == SHOOT_REGION) { XGCValues gc_values; gc_values.function = GXxor; gc_values.plane_mask = AllPlanes; gc_values.foreground = WhitePixel (x_dpy, x_scr); gc_values.background = BlackPixel (x_dpy, x_scr); gc_values.line_width = 0; gc_values.line_style = LineSolid; gc_values.fill_style = FillSolid; gc_values.cap_style = CapButt; gc_values.join_style = JoinMiter; gc_values.graphics_exposures = FALSE; gc_values.clip_x_origin = 0; gc_values.clip_y_origin = 0; gc_values.clip_mask = None; gc_values.subwindow_mode = IncludeInferiors; x_gc = XCreateGC (x_dpy, x_root, GCFunction | GCPlaneMask | GCForeground | GCLineWidth | GCLineStyle | GCCapStyle | GCJoinStyle | GCGraphicsExposures | GCBackground | GCFillStyle | GCClipXOrigin | GCClipYOrigin | GCClipMask | GCSubwindowMode, &gc_values); } if (gdk_keymap_get_entries_for_keyval (NULL, GDK_Escape, &keys, &num_keys)) { gdk_error_trap_push (); #define X_GRAB_KEY(index, modifiers) \ XGrabKey (x_dpy, keys[index].keycode, modifiers, x_root, False, \ GrabModeAsync, GrabModeAsync) for (i = 0; i < num_keys; i++) { X_GRAB_KEY (i, 0); X_GRAB_KEY (i, LockMask); /* CapsLock */ X_GRAB_KEY (i, Mod2Mask); /* NumLock */ X_GRAB_KEY (i, Mod5Mask); /* ScrollLock */ X_GRAB_KEY (i, LockMask | Mod2Mask); /* CapsLock + NumLock */ X_GRAB_KEY (i, LockMask | Mod5Mask); /* CapsLock + ScrollLock */ X_GRAB_KEY (i, Mod2Mask | Mod5Mask); /* NumLock + ScrollLock */ X_GRAB_KEY (i, LockMask | Mod2Mask | Mod5Mask); /* all */ } #undef X_GRAB_KEY gdk_flush (); gdk_error_trap_pop (); } while (! cancel && ((x_win == None) || (buttons != 0))) { XEvent x_event; gint x, y, w, h; XAllowEvents (x_dpy, SyncPointer, CurrentTime); XWindowEvent (x_dpy, x_root, mask | KeyPressMask, &x_event); switch (x_event.type) { case ButtonPress: if (x_win == None) { x_win = x_event.xbutton.subwindow; if (x_win == None) x_win = x_root; #ifdef HAVE_X11_XMU_WINUTIL_H else if (! shootvals.decorate) x_win = XmuClientWindow (x_dpy, x_win); #endif shootvals.x2 = shootvals.x1 = x_event.xbutton.x_root; shootvals.y2 = shootvals.y1 = x_event.xbutton.y_root; } buttons++; break; case ButtonRelease: if (buttons > 0) buttons--; if (! buttons && shootvals.shoot_type == SHOOT_REGION) { x = MIN (shootvals.x1, shootvals.x2); y = MIN (shootvals.y1, shootvals.y2); w = ABS (shootvals.x2 - shootvals.x1); h = ABS (shootvals.y2 - shootvals.y1); if (w > 0 && h > 0) XDrawRectangle (x_dpy, x_root, x_gc, x, y, w, h); shootvals.x2 = x_event.xbutton.x_root; shootvals.y2 = x_event.xbutton.y_root; } break; case MotionNotify: if (buttons > 0) { x = MIN (shootvals.x1, shootvals.x2); y = MIN (shootvals.y1, shootvals.y2); w = ABS (shootvals.x2 - shootvals.x1); h = ABS (shootvals.y2 - shootvals.y1); if (w > 0 && h > 0) XDrawRectangle (x_dpy, x_root, x_gc, x, y, w, h); shootvals.x2 = x_event.xmotion.x_root; shootvals.y2 = x_event.xmotion.y_root; x = MIN (shootvals.x1, shootvals.x2); y = MIN (shootvals.y1, shootvals.y2); w = ABS (shootvals.x2 - shootvals.x1); h = ABS (shootvals.y2 - shootvals.y1); if (w > 0 && h > 0) XDrawRectangle (x_dpy, x_root, x_gc, x, y, w, h); } break; case KeyPress: { guint *keyvals; gint n; if (gdk_keymap_get_entries_for_keycode (NULL, x_event.xkey.keycode, NULL, &keyvals, &n)) { gint i; for (i = 0; i < n && ! cancel; i++) if (keyvals[i] == GDK_Escape) cancel = TRUE; g_free (keyvals); } } break; default: break; } } if (keys) { #define X_UNGRAB_KEY(index, modifiers) \ XUngrabKey (x_dpy, keys[index].keycode, modifiers, x_root) for (i = 0; i < num_keys; i++) { X_UNGRAB_KEY (i, 0); X_UNGRAB_KEY (i, LockMask); /* CapsLock */ X_UNGRAB_KEY (i, Mod2Mask); /* NumLock */ X_UNGRAB_KEY (i, Mod5Mask); /* ScrollLock */ X_UNGRAB_KEY (i, LockMask | Mod2Mask); /* CapsLock + NumLock */ X_UNGRAB_KEY (i, LockMask | Mod5Mask); /* CapsLock + ScrollLock */ X_UNGRAB_KEY (i, Mod2Mask | Mod5Mask); /* NumLock + ScrollLock */ X_UNGRAB_KEY (i, LockMask | Mod2Mask | Mod5Mask); /* all */ } #undef X_UNGRAB_KEY g_free (keys); } if (status == GrabSuccess) XUngrabPointer (x_dpy, CurrentTime); XFreeCursor (x_dpy, x_cursor); if (x_gc != None) XFreeGC (x_dpy, x_gc); return x_win; }
RedirectedXCompositeWindow::RedirectedXCompositeWindow(GdkWindow* parentWindow, std::function<void()> damageNotify) : m_display(GDK_DISPLAY_XDISPLAY(gdk_window_get_display(parentWindow))) , m_window(0) , m_parentWindow(0) , m_pixmap(0) , m_damage(0) , m_needsNewPixmapAfterResize(false) { Screen* screen = DefaultScreenOfDisplay(m_display); GdkVisual* visual = gdk_window_get_visual(parentWindow); Colormap colormap = XCreateColormap(m_display, RootWindowOfScreen(screen), GDK_VISUAL_XVISUAL(visual), AllocNone); // This is based on code from Chromium: src/content/common/gpu/image_transport_surface_linux.cc XSetWindowAttributes windowAttributes; windowAttributes.override_redirect = True; windowAttributes.colormap = colormap; // CWBorderPixel must be present when the depth doesn't match the parent's one. // See http://cgit.freedesktop.org/xorg/xserver/tree/dix/window.c?id=xorg-server-1.16.0#n703. windowAttributes.border_pixel = 0; m_parentWindow = XCreateWindow(m_display, RootWindowOfScreen(screen), WidthOfScreen(screen) + 1, 0, 1, 1, 0, gdk_visual_get_depth(visual), InputOutput, GDK_VISUAL_XVISUAL(visual), CWOverrideRedirect | CWColormap | CWBorderPixel, &windowAttributes); XMapWindow(m_display, m_parentWindow); windowAttributes.event_mask = StructureNotifyMask; windowAttributes.override_redirect = False; // Create the window of at last 1x1 since X doesn't allow to create empty windows. m_window = XCreateWindow(m_display, m_parentWindow, 0, 0, std::max(1, m_size.width()), std::max(1, m_size.height()), 0, CopyFromParent, InputOutput, CopyFromParent, CWEventMask, &windowAttributes); XMapWindow(m_display, m_window); XFreeColormap(m_display, colormap); xDamageNotifier().add(m_window, WTF::move(damageNotify)); while (1) { XEvent event; XWindowEvent(m_display, m_window, StructureNotifyMask, &event); if (event.type == MapNotify && event.xmap.window == m_window) break; } XSelectInput(m_display, m_window, NoEventMask); XCompositeRedirectWindow(m_display, m_window, CompositeRedirectManual); m_damage = XDamageCreate(m_display, m_window, XDamageReportNonEmpty); }
static void eventLoop(struct aOpts *opts, struct aXInfo *xi) { Display *dpy = xi->display; XEvent ev; KeySym ks; char cbuf[10]; wchar_t pass[128]; unsigned int clen; unsigned int pass_pos = 0, pass_len = 0; unsigned long keypress_time = 0; char rbuf[sizeof(pass)]; debug("entering event main loop"); for (;;) { if (keypress_time) { /* check for any key press event */ if (XCheckWindowEvent(dpy, xi->window[0], KeyPressMask, &ev) == False) { /* user fell asleep while typing (5 seconds inactivity) */ if (alock_mtime() - keypress_time > 5000) { opts->input->setstate(AINPUT_STATE_NONE); keypress_time = 0; } /* wait a bit */ usleep(25000); continue; } } else { /* block until any key press event arrives */ XWindowEvent(dpy, xi->window[0], KeyPressMask, &ev); } switch (ev.type) { case KeyPress: /* swallow up first key press to indicate "enter mode" */ if (keypress_time == 0) { opts->input->setstate(AINPUT_STATE_INIT); keypress_time = alock_mtime(); pass_pos = pass_len = 0; pass[0] = '\0'; break; } keypress_time = alock_mtime(); clen = XLookupString(&ev.xkey, cbuf, sizeof(cbuf), &ks, NULL); debug("key input: %lx, %d, `%s`", ks, clen, cbuf); /* translate key press symbol */ ks = opts->input->keypress(ks); switch (ks) { case NoSymbol: break; /* clear/initialize input buffer */ case XK_Escape: case XK_Clear: pass_pos = pass_len = 0; pass[0] = '\0'; break; /* input position navigation */ case XK_Begin: case XK_Home: pass_pos = 0; break; case XK_End: pass_pos = pass_len; break; case XK_Left: if (pass_pos > 0) pass_pos--; break; case XK_Right: if (pass_pos < pass_len) pass_pos++; break; /* remove entered characters */ case XK_Delete: if (pass_pos < pass_len) { wmemmove(&pass[pass_pos], &pass[pass_pos + 1], pass_len - pass_pos); pass_len--; } break; case XK_BackSpace: if (pass_pos > 0) { wmemmove(&pass[pass_pos - 1], &pass[pass_pos], pass_len - pass_pos + 1); pass_pos--; pass_len--; } break; /* input confirmation and authentication test */ case XK_Linefeed: case XK_Return: opts->input->setstate(AINPUT_STATE_CHECK); wcstombs(rbuf, pass, sizeof(rbuf)); if (opts->auth->auth(rbuf)) { opts->input->setstate(AINPUT_STATE_VALID); return; } opts->input->setstate(AINPUT_STATE_ERROR); opts->input->setstate(AINPUT_STATE_INIT); keypress_time = alock_mtime(); pass_pos = pass_len = 0; pass[0] = '\0'; break; /* input new character at the current input position */ default: if (clen > 0 && !iscntrl(cbuf[0]) && pass_len < (sizeof(pass) / sizeof(*pass) - 1)) { wmemmove(&pass[pass_pos + 1], &pass[pass_pos], pass_len - pass_pos + 1); mbtowc(&pass[pass_pos], cbuf, clen); pass_pos++; pass_len++; } break; } debug("entered phrase [%zu]: `%ls`", wcslen(pass), pass); break; case Expose: XClearWindow(xi->display, ((XExposeEvent*)&ev)->window); break; } } }