void xt_grab_pointer (EIF_POINTER widget, EIF_POINTER cursor) { /* Grab the pointer and the * keyboard */ if (cursor) XtGrabPointer ((Widget) widget, False, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeSync, None, (Cursor) cursor, CurrentTime); else XtGrabPointer ((Widget) widget, False, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeSync, None, None, CurrentTime); }
/* * Starts up the rubber band UI. * It grab the pointer and adds an event handler * which detects the ButtonRelease. It also sets the * rubber band func. */ int ui_initiate_rubberband( Widget widget, Boolean confine_to_window, UiRubberBandFunc rb_func, XtPointer client_data ) { XtAddEventHandler(widget, ButtonReleaseMask, False, rubberband_release, client_data); if (XtGrabPointer(widget, False, ButtonReleaseMask | ButtonMotionMask | PointerMotionMask, GrabModeAsync, GrabModeAsync, confine_to_window ? XtWindow(widget) : None, NULL, CurrentTime) == GrabSuccess) { rband_in_progress = True; rubberband_func = rb_func; return OK; } rband_in_progress = False; rubberband_func = NULL; return ERROR; }
static void PluginResizeAction(Widget w, XEvent *event, String *params, Cardinal *n) { XtAppContext app_context = XtWidgetToApplicationContext(w); int owner_events = True; unsigned int event_mask = ButtonReleaseMask | PointerMotionMask; int pointer_mode = GrabModeAsync; int keyboard_mode = GrabModeAsync; Window confine_to = XtWindow(XtParent(w)); static Cursor cursor = None; Time time = CurrentTime; int waiting = True; Dimension wi, he, wi2, he2; int ph = plugin_find_by_widget(w); if (ph == -1) return; wi = event->xbutton.x; he = event->xbutton.y; XtVaGetValues(w, XtNwidth, &wi2, XtNheight, &he2, (char *)0); if (wi2-wi > 10 || he2-he > 10) return; /* snipped from colnum_grab */ if (cursor == None) cursor = XCreateFontCursor(XtDisplay(w), XC_bottom_right_corner); XtGrabPointer(w, owner_events, event_mask, pointer_mode, keyboard_mode, confine_to, cursor, time); while (waiting) { XEvent event_return; XtAppNextEvent(app_context, &event_return); if (event_return.type == ButtonRelease) { waiting = False; } else if (event_return.type == MotionNotify) { wi = event_return.xmotion.x; he = event_return.xmotion.y; plugin_size_set(ph, wi, he); } else { XtDispatchEvent(&event_return); } } XtUngrabPointer(w, CurrentTime); pr_scr_flag = TRUE; }
/*ARGSUSED*/ static void MapNotifyHandler(Widget shell, XtPointer client_data, XEvent *event, Boolean *cont) { XmGrabShellWidget grabshell = (XmGrabShellWidget)shell; Time time; XErrorHandler old_handler; /* Only handles map events */ if (event -> type != MapNotify) return; /* CR 9920: Popdown may be called before MapNotify. */ grabshell->grab_shell.mapped = True; if (!(time = XtLastTimestampProcessed(XtDisplay(shell)))) time = CurrentTime; if (grabshell->grab_shell.cursor == None) grabshell->grab_shell.cursor = XCreateFontCursor (XtDisplay(grabshell), XC_arrow); _XmFastExpose(shell); (void) XtGrabKeyboard(shell, grabshell -> grab_shell.owner_events, grabshell -> grab_shell.grab_style, GrabModeAsync, time); (void) XtGrabPointer(shell, grabshell -> grab_shell.owner_events, Events, grabshell -> grab_shell.grab_style, GrabModeAsync, None, grabshell->grab_shell.cursor, time); GSAllowEvents(shell, SyncPointer, time); /* Fix focus to shell */ XGetInputFocus(XtDisplay(shell), &grabshell->grab_shell.old_focus, &grabshell->grab_shell.old_revert_to); old_handler = XSetErrorHandler(IgnoreXErrors); XSetInputFocus(XtDisplay(shell), XtWindow(shell), RevertToParent, time); XSync(XtDisplay(shell), False); XSetErrorHandler(old_handler); }
int main (int argc, char **argv) { XtResource desktopBackingStoreResources[] = { { XtNbackingStore, XtCBackingStore, XtRBackingStore, sizeof(int), 0, XtRImmediate, (XtPointer) Always, }, }; Display * display; Visual * vis; XSetWindowAttributes attr; unsigned long valuemask; Pixmap src, msk; XColor fg, bg; int blackColor; GC gc; Widget toplevel; Dimension displayWidth, displayHeight; Cursor blankcursor; Widget form, viewport, desktop; Window desktop_win; char srcBits[] = { 0,0,0,0,0 }; char mskBits[] = { 0,0,0,0,0 }; /* Call the main Xt initialisation function. It parses command-line options, generating appropriate resource specs, and makes a * connection to the X display. */ toplevel = XtVaAppInitialize(NULL, "ScreenLocker", NULL, 0, &argc, argv, NULL, XtNborderWidth, 0, NULL); display = XtDisplay(toplevel); vis = DefaultVisual(display, DefaultScreen(display)); displayWidth = WidthOfScreen(DefaultScreenOfDisplay(display)); displayHeight = HeightOfScreen(DefaultScreenOfDisplay(display)); /* full screen - set position to 0,0, but defer size calculation until widgets are realized */ XtVaSetValues(toplevel, XtNoverrideRedirect, True, XtNgeometry, "+0+0", NULL); form = XtVaCreateManagedWidget("form", formWidgetClass, toplevel, XtNborderWidth, 0, XtNdefaultDistance, 0, NULL); viewport = XtVaCreateManagedWidget("viewport", viewportWidgetClass, form, XtNborderWidth, 0, NULL); desktop = XtVaCreateManagedWidget("desktop", coreWidgetClass, viewport, XtNborderWidth, 0, NULL); XtVaSetValues(desktop, XtNwidth, displayWidth, XtNheight, displayHeight, NULL); /* "Realize" all the widgets, i.e. actually create and map their X windows */ XtRealizeWidget(toplevel); /* We want to stop the window manager from managing our toplevel window. This is not really a nice thing to do, so may not work * properly with every window manager. We do this simply by setting overrideRedirect and reparenting our window to the root. * The window manager will get a ReparentNotify and hopefully clean up its frame window. */ XtVaSetValues(toplevel, XtNoverrideRedirect, True, NULL); XReparentWindow(display, XtWindow(toplevel), DefaultRootWindow(display), 0, 0); /* Now we want to fix the size of "viewport". We shouldn't just change it directly. * Instead we set "toplevel" to the required size (which should propagate through "form" to "viewport"). * Then we remove "viewport" from being managed by "form", change its resources to position it and make sure that "form" won't * attempt to resize it, then ask "form" to manage it again. */ XtResizeWidget(toplevel, displayWidth, displayHeight, 0); XtUnmanageChild(viewport); XtVaSetValues(viewport, XtNhorizDistance, 0, XtNvertDistance, 0, XtNleft, XtChainLeft, XtNright, XtChainLeft, XtNtop, XtChainTop, XtNbottom, XtChainTop, NULL); XtManageChild(viewport); /* Now we can set "toplevel" to its proper size. */ XtResizeWidget(toplevel, displayWidth, displayHeight, 0); /*image = XCreateImage(display, vis, 32, ZPixmap, 0, NULL, 2000, 2000, BitmapPad(display), 0);*/ blackColor = BlackPixel(display, DefaultScreen(display)); desktop_win = XtWindow(desktop); gc = XCreateGC(display, desktop_win, 0, NULL); /* Tell the GC we draw using the black color*/ XSetForeground(display, gc, blackColor); XFillRectangle(display, desktop_win, gc, 0, 0, displayWidth, displayHeight); src = XCreateBitmapFromData(display, DefaultRootWindow(display), srcBits, 5, 5); msk = XCreateBitmapFromData(display, DefaultRootWindow(display), mskBits, 5, 5); XAllocNamedColor(display, DefaultColormap(display,DefaultScreen(display)), "black", &fg, &fg); XAllocNamedColor(display, DefaultColormap(display,DefaultScreen(display)), "white", &bg, &bg); blankcursor = XCreatePixmapCursor(display, src, msk, &fg, &bg, 2, 2); XFreePixmap(display, src); XFreePixmap(display, msk); XtVaGetApplicationResources(desktop, (XtPointer)&attr.backing_store, desktopBackingStoreResources, 1, NULL); valuemask = CWBackingStore; attr.cursor = blankcursor; valuemask |= CWCursor; XChangeWindowAttributes(display, desktop_win, valuemask, &attr); /* Try to get the input focus. */ XSetInputFocus(display, DefaultRootWindow(display), RevertToPointerRoot, CurrentTime); /* now grab keyboard and mouse */ if (XtGrabKeyboard(desktop, True, GrabModeAsync, GrabModeAsync, CurrentTime) != GrabSuccess || XtGrabPointer(desktop, True, (unsigned int) AllPointerEventMask, GrabModeAsync, GrabModeAsync, None, blankcursor, CurrentTime) != GrabSuccess) { printf ("Could not grab keyboard and mouse.\n"); } while (1) { /* sleep a little bit - only for better task-scheduling... */ sleep (5); } return (0); }
static void Input (Widget W, StrokeStatePtr State, XEvent *event) { /* fprintf(stderr, "Input(%s,%i) - %s %i %i %i %i\n", XtName(State->widget), event->xany.type, XtName(W), event->xbutton.x, event->xbutton.y, event->xbutton.x_root, event->xbutton.y_root); */ switch (event->xany.type) { case KeyRelease: case ButtonRelease: if (State->InStroke) { int i; if (!State->Debug) { for (i = 1; i < State->npoints; i++) { XDrawLine(XtDisplay(W), event->xbutton.root, State->gc, State->points[i - 1].x, State->points[i - 1].y, State->points[i].x, State->points[i].y); /* XDrawRectangle(XtDisplay(State->widget), XtWindow(State->widget), State->gc, State->points[State->npoints].x - 2, State->points[State->npoints].y - 2, 4, 4); */ } } XtUngrabPointer(W, event->xbutton.time); XUngrabServer(XtDisplay(W)); DoStroke(event, State); State->InStroke = False; State->npoints = 0; } break; case KeyPress: case ButtonPress: if (!State->InStroke) { State->widget = W; State->npoints = 0; AllocatePoints(State); /* TranslateCoords(W, State->widget, &((XButtonPressedEvent *)event)->x, &((XButtonPressedEvent *)event)->y); */ State->points[State->npoints].x = event->xbutton.x_root; State->points[State->npoints].y = event->xbutton.y_root; State->xmin = State->points[State->npoints].x; State->ymin = State->points[State->npoints].y; State->xmax = State->points[State->npoints].x; State->ymax = State->points[State->npoints].y; State->npoints++; State->InStroke = True; XGrabServer(XtDisplay(W)); XtGrabPointer(W, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None, event->xbutton.time); } break; case MotionNotify: if (State->gc == (GC)NULL) { Pixel Background; State->gc = XCreateGC(XtDisplay(State->widget), XtWindow(State->widget), 0, NULL); XtVaGetValues(State->widget, XtNbackground, &Background, NULL); XSetForeground(XtDisplay(State->widget), State->gc, Background); XSetFunction(XtDisplay(State->widget), State->gc, GXxor); XSetSubwindowMode(XtDisplay(State->widget), State->gc, IncludeInferiors); } if (State->InStroke) { int dx = State->points[State->npoints - 1].x - event->xmotion.x_root; int dy = State->points[State->npoints - 1].y - event->xmotion.y_root; if (dx * dx + dy * dy > State->slop) { AllocatePoints(State); State->points[State->npoints].x = event->xmotion.x_root; State->points[State->npoints].y = event->xmotion.y_root; XDrawLine(XtDisplay(State->widget), event->xmotion.root, State->gc, State->points[State->npoints - 1].x, State->points[State->npoints - 1].y, State->points[State->npoints].x, State->points[State->npoints].y); State->xmin = State->xmin < State->points[State->npoints].x ? State->xmin : State->points[State->npoints].x; State->xmax = State->xmax > State->points[State->npoints].x ? State->xmax : State->points[State->npoints].x; State->ymin = State->ymin < State->points[State->npoints].y ? State->ymin : State->points[State->npoints].y; State->ymax = State->ymax > State->points[State->npoints].y ? State->ymax : State->points[State->npoints].y; State->npoints++; } } break; default: fprintf(stderr, "%s(%i): Input(%s) - %s Unknown event type %i\n", __FILE__, __LINE__, XtName(State->widget), XtName(W), event->type); } }