|
|
1.1 root 1: #include <X/mit-copyright.h>
2:
3: /* Copyright Massachusetts Institute of Technology 1985 */
4:
5: /*
6: * Move - Window movement subroutine for the X Window System window
7: * manager (xwm).
8: *
9: * File: Move.c
10: */
11: #ifndef lint
12: static char *rcsid_Move_c = "$Header: Move.c,v 10.3 86/02/01 16:09:58 tony Rel $";
13: #endif
14:
15: #include "xwm.h"
16:
17: Move(window, x, y)
18: Window window;
19: int x;
20: int y;
21: {
22: register int prev_x; /* Previous event window X location. */
23: register int prev_y; /* Previous event window Y location. */
24: register WindowInfo window_info; /* Event window information. */
25: int cur_x; /* Current event window X location. */
26: int cur_y; /* Current event window Y location. */
27: int ulx, uly; /* Event window upper left X and Y. */
28: int lrx, lry; /* Event window lower right X and Y. */
29: int init_ulx, init_uly; /* Init window upper left X and Y. */
30: int init_lrx, init_lry; /* Init window lower right X and Y. */
31: int status; /* Routine call status. */
32: int num_vectors; /* Number of vectors in box. */
33: Window sub_window; /* Query mouse event sub-window. */
34: XButtonEvent button_event; /* Button event packet. */
35: Bool moving; /* Are we moving the window? */
36: Vertex box[MAX_BOX_VECTORS]; /* Box vertex buffer. */
37: Vertex zap[MAX_ZAP_VECTORS]; /* Zap effect verted buffer. */
38:
39: /*
40: * Clear the vector buffers.
41: */
42: bzero(box, sizeof(box));
43: if (Zap) bzero(zap, sizeof(zap));
44:
45: /*
46: * Gather info on the event window since we may move it.
47: */
48: status = XQueryWindow(window, &window_info);
49: if (status == FAILURE) {
50: /*
51: * If there is a query error, abort the operation and return.
52: */
53: return;
54: }
55:
56: /*
57: * Initialize movement variables.
58: */
59: ulx = window_info.x;
60: init_ulx = ulx;
61: uly = window_info.y;
62: init_uly = uly;
63: lrx = window_info.x + window_info.width + (window_info.bdrwidth << 1) - 1;
64: init_lrx = lrx;
65: lry = window_info.y + window_info.height + (window_info.bdrwidth << 1) - 1;
66: init_lry = lry;
67:
68: moving = FALSE;
69:
70: while (TRUE) {
71:
72: /*
73: * Check to see if we have a change in mouse button status.
74: * This is how we get out of this "while" loop.
75: */
76: if (XPending() && GetButton(&button_event)) {
77: /*
78: * Process the pending events, this sequence is the only
79: * way out of the loop and the routine.
80: */
81: if (
82: (button_event.type == ButtonReleased) &&
83: ((button_event.detail & ValueMask) == RightButton)
84: ){
85: /*
86: * Ok, the right button was released.
87: * If we are not moving see if we should be. If we
88: * have move more than Delta pixels then start moving
89: * the window.
90: */
91: cur_x = button_event.x;
92: cur_y = button_event.y;
93:
94: if (
95: !moving &&
96: (abs(cur_x - x) > Delta) || (abs(cur_y - y) > Delta)
97: ){
98: /*
99: * Start moving.
100: */
101: /*
102: * Change the cursor.
103: */
104: status = XGrabButton(
105: RootWindow,
106: ArrowCrossCursor,
107: (RightMask | ButtonMask),
108: (ButtonPressed | ButtonReleased)
109: );
110: if (status == FAILURE) {
111: Error("Move -> Unable to grab right button and change cursor.");
112: }
113:
114: /*
115: * Set the moving flag.
116: */
117: moving = TRUE;
118: }
119:
120: if (moving) {
121: /*
122: * We are moveing so reset the cursor and move the
123: * window.
124: */
125: status = XGrabButton(
126: RootWindow,
127: CircleCursor,
128: (RightMask | ButtonMask),
129: (ButtonPressed | ButtonReleased)
130: );
131: if (status == FAILURE) {
132: Error("Move -> Unable to grab right button and change cursor.");
133: }
134:
135: if (Zap) {
136: num_vectors = StoreZap(
137: zap,
138: init_ulx, init_uly,
139: init_lrx, init_lry,
140: ulx, uly,
141: lrx, lry
142: );
143: XDraw(
144: RootWindow,
145: zap, num_vectors,
146: DRAW_HEIGHT, DRAW_WIDTH,
147: DRAW_VALUE, DRAW_FUNC, DRAW_PLANES
148: );
149: XDraw(
150: RootWindow,
151: zap, num_vectors,
152: DRAW_HEIGHT, DRAW_WIDTH,
153: DRAW_VALUE, DRAW_FUNC, DRAW_PLANES
154: );
155: }
156:
157: XMoveWindow(window, ulx, uly);
158: return;
159: }
160: else {
161: /*
162: * We didn't move so this must have been a raise
163: * window operation only. No need to reset the
164: * cursor since we only change it if we are moving.
165: */
166: XRaiseWindow(window);
167: return;
168: }
169: }
170: else {
171: /*
172: * Some other button event occured, this aborts the
173: * current operation.
174: */
175: if (moving) {
176: /*
177: * If we were moving then reset the cursor.
178: */
179: status = XGrabButton(
180: RootWindow,
181: CircleCursor,
182: (RightMask | ButtonMask),
183: (ButtonPressed | ButtonReleased)
184: );
185: if (status == FAILURE) {
186: Error("Move -> Unable to grab right button and change cursor.");
187: }
188: }
189: return;
190: }
191: }
192:
193: if (!moving) {
194: /*
195: * If we are not moving see if we should be. If we
196: * have move more than Delta pixels then start moving
197: * the window.
198: */
199: XQueryMouse(RootWindow, &cur_x, &cur_y, &sub_window);
200: if ((abs(cur_x - x) > Delta) || (abs(cur_y - y) > Delta)) {
201: /*
202: * Start moving.
203: */
204:
205: /*
206: * Change the cursor.
207: */
208: status = XGrabButton(
209: RootWindow,
210: ArrowCrossCursor,
211: (RightMask | ButtonMask),
212: (ButtonPressed | ButtonReleased)
213: );
214: if (status == FAILURE) {
215: Error("Move -> Unable to grab right button and change cursor.");
216: }
217:
218: /*
219: * Store the box.
220: */
221: if (Grid) {
222: num_vectors = StoreGridBox(box, ulx, uly, lrx, lry);
223: }
224: else {
225: num_vectors = StoreBox(box, ulx, uly, lrx, lry);
226: }
227:
228: /*
229: * Initialize the previous location variables.
230: */
231: prev_x = x;
232: prev_y = y;
233:
234: /*
235: * Set the moving flag.
236: */
237: moving = TRUE;
238: }
239: else {
240: /*
241: * We haven't moved enough yet.
242: */
243: continue;
244: }
245: }
246:
247: if (moving) {
248: /*
249: * If we have begun moving or have been moving take care
250: * of all the little that have to change.
251: */
252: XQueryMouse(RootWindow, &cur_x, &cur_y, &sub_window);
253: if ((cur_x != prev_x) || (cur_y != prev_y)) {
254: /*
255: * Box position has changed.
256: */
257: ulx += cur_x - prev_x;
258: uly += cur_y - prev_y;
259: lrx += cur_x - prev_x;
260: lry += cur_y - prev_y;
261:
262: /*
263: * Box needs to be restored.
264: */
265: if (Grid) {
266: num_vectors = StoreGridBox(box, ulx, uly, lrx, lry);
267: }
268: else {
269: num_vectors = StoreBox(box, ulx, uly, lrx, lry);
270: }
271:
272: /*
273: * Save old box position.
274: */
275: prev_x = cur_x;
276: prev_y = cur_y;
277: }
278:
279: /*
280: * Draw Box.
281: */
282: XDraw(
283: RootWindow,
284: box, num_vectors,
285: DRAW_HEIGHT, DRAW_WIDTH,
286: DRAW_VALUE, DRAW_FUNC, DRAW_PLANES
287: );
288: XDraw(
289: RootWindow,
290: box, num_vectors,
291: DRAW_HEIGHT, DRAW_WIDTH,
292: DRAW_VALUE, DRAW_FUNC, DRAW_PLANES
293: );
294: }
295: }
296: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.