MCPcopy Create free account
hub / github.com/VirtualGL/virtualgl / Select_Window

Function Select_Window

diags/dsimple.c:51–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49 */
50
51Window Select_Window(Display *dpy)
52{
53 int status;
54 Cursor cursor;
55 XEvent event;
56 Window target_win = None, root = DefaultRootWindow(dpy);
57 int buttons = 0;
58
59 /* Make the target cursor */
60 cursor = XCreateFontCursor(dpy, XC_crosshair);
61
62 /* Grab the pointer using target cursor, letting it room all over */
63 status = XGrabPointer(dpy, root, False,
64 ButtonPressMask|ButtonReleaseMask, GrabModeSync,
65 GrabModeAsync, root, cursor, CurrentTime);
66 if (status != GrabSuccess) Fatal_Error("Can't grab the mouse.");
67
68 /* Let the user select a window... */
69 while ((target_win == None) || (buttons != 0)) {
70 /* allow one more event */
71 XAllowEvents(dpy, SyncPointer, CurrentTime);
72 XWindowEvent(dpy, root, ButtonPressMask|ButtonReleaseMask, &event);
73 switch (event.type) {
74 case ButtonPress:
75 if (target_win == None) {
76 target_win = event.xbutton.subwindow; /* window selected */
77 if (target_win == None) target_win = root;
78 }
79 buttons++;
80 break;
81 case ButtonRelease:
82 if (buttons > 0) /* there may have been some down before we started */
83 buttons--;
84 break;
85 }
86 }
87
88 XUngrabPointer(dpy, CurrentTime); /* Done with pointer */
89
90 return(target_win);
91}
92
93
94/*

Callers 1

mainFunction · 0.85

Calls 2

Fatal_ErrorFunction · 0.85
XWindowEventFunction · 0.85

Tested by

no test coverage detected