2 * This code has gone back and forth between myself and Jon Kamens
3 * so many times that neither really knows who wrote it..
6 #include <X11/Intrinsic.h>
7 #include <X11/StringDefs.h>
9 static void _initPopup();
10 void Popup(), PopupSafe(), PopupAtPointer();
12 static int display_height, display_width;
14 static void _initPopup(w)
21 screen = DefaultScreen(dpy);
22 display_height = DisplayHeight(dpy, screen);
23 display_width = DisplayWidth(dpy, screen);
27 void Popup(shell, GrabType, pop_type)
32 PopupAtPointer(shell, GrabType);
35 void PopupSafe(w, x, y, GrabType)
40 static int first_time = 1;
41 Dimension width, height, border;
51 XtNborderWidth, &border,
54 if (x + width + 2 * border > display_width)
55 x = display_width - width - 2 * border;
56 if (y + height + 2 * border > display_height)
57 y = display_height - height - 2 * border;
67 void PopupAtPointer(w, GrabType)
71 Window garbage1, garbage2, window;
72 int root_x, root_y, x2, y2;
74 Dimension width, height, border;
78 window = XtWindow(XtParent(w));
80 if (XQueryPointer(dpy, window, &garbage1, &garbage2,
81 &root_x, &root_y, &x2, &y2, &mask)) {
86 XtNborderWidth, &border,
89 if (root_x >= width / 2 + border)
90 root_x -= width / 2 + border;
93 if (root_y >= height / 2 + border)
94 root_y -= height / 2 + border;
98 PopupSafe(w, (Dimension) root_x, (Dimension) root_y, GrabType);