replaced linked lists with WMBag, added progress indicator
[wmaker-crm.git] / src / moveres.c
blob3d872180a31b0847e2e83fd2606b8756fa9d2047
1 /*
2 * Window Maker window manager
3 *
4 * Copyright (c) 1997, 1998, 1999 Alfredo K. Kojima
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 * USA.
22 #include "wconfig.h"
24 #include <X11/Xlib.h>
25 #include <X11/Xutil.h>
26 #include <X11/keysym.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
32 #include "WindowMaker.h"
33 #include "wcore.h"
34 #include "framewin.h"
35 #include "window.h"
36 #include "client.h"
37 #include "icon.h"
38 #include "dock.h"
39 #include "funcs.h"
40 #include "actions.h"
41 #include "workspace.h"
43 #include "list.h"
45 #ifdef KWM_HINTS
46 #include "kwm.h"
47 #endif
49 /* How many different types of geometry/position
50 display thingies are there? */
51 #define NUM_DISPLAYS 4
53 #define LEFT 1
54 #define RIGHT 2
55 #define HORIZONTAL (LEFT|RIGHT)
56 #define UP 4
57 #define DOWN 8
58 #define VERTICAL (UP|DOWN)
60 /****** Global Variables ******/
61 extern Time LastTimestamp;
63 extern Cursor wCursor[WCUR_LAST];
65 extern WPreferences wPreferences;
67 extern Atom _XA_WM_PROTOCOLS;
71 void
72 wGetGeometryWindowSize(WScreen *scr, unsigned int *width,
73 unsigned int *height)
75 *width = WMWidthOfString(scr->info_text_font, "-8888 x -8888", 13);
77 *height = (6 * WMFontHeight(scr->info_text_font)) / 4 - 1;
82 *----------------------------------------------------------------------
83 * moveGeometryDisplayCentered
85 * routine that moves the geometry/position window on scr so it is
86 * centered over the given coordinates (x,y). Also the window position
87 * is clamped so it stays on the screen at all times.
88 *----------------------------------------------------------------------
90 static void
91 moveGeometryDisplayCentered(WScreen *scr, int x, int y)
93 x -= scr->geometry_display_width / 2;
94 y -= scr->geometry_display_height / 2;
96 if (x < 1)
97 x = 1;
98 else if (x > (scr->scr_width - scr->geometry_display_width - 3))
99 x = scr->scr_width - scr->geometry_display_width - 3;
101 if (y < 1)
102 y = 1;
103 else if (y > (scr->scr_height - scr->geometry_display_height - 3))
104 y = scr->scr_height - scr->geometry_display_height - 3;
106 XMoveWindow(dpy, scr->geometry_display, x, y);
110 static void
111 showPosition(WWindow *wwin, int x, int y)
113 WScreen *scr = wwin->screen_ptr;
114 GC gc = scr->info_text_gc;
115 char num[16];
116 int fw, fh;
118 if (wPreferences.move_display == WDIS_NEW) {
119 #if 1
120 int width = wwin->frame->core->width;
121 int height = wwin->frame->core->height;
123 GC lgc = scr->line_gc;
124 XSetForeground(dpy, lgc, scr->line_pixel);
125 sprintf(num, "%i", x);
127 XDrawLine(dpy, scr->root_win, lgc, 0, y-1, scr->scr_width, y-1);
128 XDrawLine(dpy, scr->root_win, lgc, 0, y+height+2, scr->scr_width,
129 y+height+2);
130 XDrawLine(dpy, scr->root_win, lgc, x-1, 0, x-1, scr->scr_height);
131 XDrawLine(dpy, scr->root_win, lgc, x+width+2, 0, x+width+2,
132 scr->scr_height);
133 #endif
134 } else {
135 XClearArea(dpy, scr->geometry_display, 1, 1,
136 scr->geometry_display_width-2, scr->geometry_display_height-2,
137 False);
138 sprintf(num, "%+i %-+i", x, y);
139 fw = WMWidthOfString(scr->info_text_font, num, strlen(num));
141 XSetForeground(dpy, gc, scr->black_pixel);
143 fh = WMFontHeight(scr->info_text_font);
144 WMDrawString(scr->wmscreen, scr->geometry_display, gc,
145 scr->info_text_font,
146 (scr->geometry_display_width - 2 - fw) / 2,
147 (scr->geometry_display_height-fh)/2, num, strlen(num));
148 wDrawBevel(scr->geometry_display, scr->geometry_display_width+1,
149 scr->geometry_display_height+1,
150 scr->widget_texture, WREL_RAISED);
155 static void
156 cyclePositionDisplay(WWindow *wwin, int x, int y, int w, int h)
158 WScreen *scr = wwin->screen_ptr;
160 wPreferences.move_display++;
161 wPreferences.move_display %= NUM_DISPLAYS;
163 if (wPreferences.move_display == WDIS_NEW) {
164 XUnmapWindow(dpy, scr->geometry_display);
165 } else {
166 if (wPreferences.move_display == WDIS_CENTER) {
167 moveGeometryDisplayCentered(scr,
168 scr->scr_width/2, scr->scr_height/2);
169 } else if (wPreferences.move_display == WDIS_TOPLEFT) {
170 moveGeometryDisplayCentered(scr, 1, 1);
171 } else if (wPreferences.move_display == WDIS_FRAME_CENTER) {
172 moveGeometryDisplayCentered(scr, x + w/2, y + h/2);
174 XMapRaised(dpy, scr->geometry_display);
179 static void
180 mapPositionDisplay(WWindow *wwin, int x, int y, int w, int h)
182 WScreen *scr = wwin->screen_ptr;
184 if (wPreferences.move_display == WDIS_NEW) {
185 return;
186 } else if (wPreferences.move_display == WDIS_CENTER) {
187 moveGeometryDisplayCentered(scr, scr->scr_width / 2,
188 scr->scr_height / 2);
189 } else if (wPreferences.move_display == WDIS_TOPLEFT) {
190 moveGeometryDisplayCentered(scr, 1, 1);
191 } else if (wPreferences.move_display == WDIS_FRAME_CENTER) {
192 moveGeometryDisplayCentered(scr, x + w/2, y + h/2);
194 XMapRaised(dpy, scr->geometry_display);
195 showPosition(wwin, x, y);
198 #define unmapPositionDisplay(w) \
199 XUnmapWindow(dpy, (w)->screen_ptr->geometry_display);
202 static void
203 showGeometry(WWindow *wwin, int x1, int y1, int x2, int y2, int direction)
205 WScreen *scr = wwin->screen_ptr;
206 Window root = scr->root_win;
207 GC gc = scr->line_gc;
208 int ty, by, my, x, y, mx, s;
209 char num[16];
210 XSegment segment[4];
211 int fw, fh;
213 ty = y1 + wwin->frame->top_width;
214 by = y2 - wwin->frame->bottom_width;
215 fw = WMWidthOfString(scr->info_text_font, "8888", 4);
216 fh = WMFontHeight(scr->info_text_font);
218 if (wPreferences.size_display == WDIS_NEW) {
219 XSetForeground(dpy, gc, scr->line_pixel);
221 /* vertical geometry */
222 if (((direction & LEFT) && (x2 < scr->scr_width - fw)) || (x1 < fw)) {
223 x = x2;
224 s = -15;
225 } else {
226 x = x1;
227 s = 15;
229 my = (ty + by) / 2;
231 /* top arrow */
232 /* end bar */
233 segment[0].x1 = x - (s + 6); segment[0].y1 = ty;
234 segment[0].x2 = x - (s - 10); segment[0].y2 = ty;
236 /* arrowhead */
237 segment[1].x1 = x - (s - 2); segment[1].y1 = ty + 1;
238 segment[1].x2 = x - (s - 5); segment[1].y2 = ty + 7;
240 segment[2].x1 = x - (s - 2); segment[2].y1 = ty + 1;
241 segment[2].x2 = x - (s + 1); segment[2].y2 = ty + 7;
243 /* line */
244 segment[3].x1 = x - (s - 2); segment[3].y1 = ty + 1;
245 segment[3].x2 = x - (s - 2); segment[3].y2 = my - fh/2 - 1;
247 XDrawSegments(dpy, root, gc, segment, 4);
249 /* bottom arrow */
250 /* end bar */
251 segment[0].y1 = by;
252 segment[0].y2 = by;
254 /* arrowhead */
255 segment[1].y1 = by - 1;
256 segment[1].y2 = by - 7;
258 segment[2].y1 = by - 1;
259 segment[2].y2 = by - 7;
261 /* line */
262 segment[3].y1 = my + fh/2 + 2;
263 segment[3].y2 = by - 1;
265 XDrawSegments(dpy, root, gc, segment, 4);
267 sprintf(num, "%i", (by - ty - wwin->normal_hints->base_height) /
268 wwin->normal_hints->height_inc);
269 fw = WMWidthOfString(scr->info_text_font, num, strlen(num));
271 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
273 /* Display the height. */
274 WMDrawString(scr->wmscreen, root, gc, scr->info_text_font,
275 x - s + 3 - fw/2, my - fh/2 + 1, num, strlen(num));
276 XSetForeground(dpy, gc, scr->line_pixel);
277 /* horizontal geometry */
278 if (y1 < 15) {
279 y = y2;
280 s = -15;
281 } else {
282 y = y1;
283 s = 15;
285 mx = x1 + (x2 - x1)/2;
286 sprintf(num, "%i", (x2 - x1 - wwin->normal_hints->base_width) /
287 wwin->normal_hints->width_inc);
288 fw = WMWidthOfString(scr->info_text_font, num, strlen(num));
290 /* left arrow */
291 /* end bar */
292 segment[0].x1 = x1; segment[0].y1 = y - (s + 6);
293 segment[0].x2 = x1; segment[0].y2 = y - (s - 10);
295 /* arrowhead */
296 segment[1].x1 = x1 + 7; segment[1].y1 = y - (s + 1);
297 segment[1].x2 = x1 + 1; segment[1].y2 = y - (s - 2);
299 segment[2].x1 = x1 + 1; segment[2].y1 = y - (s - 2);
300 segment[2].x2 = x1 + 7; segment[2].y2 = y - (s - 5);
302 /* line */
303 segment[3].x1 = x1 + 1; segment[3].y1 = y - (s - 2);
304 segment[3].x2 = mx - fw/2 - 2; segment[3].y2 = y - (s - 2);
306 XDrawSegments(dpy, root, gc, segment, 4);
308 /* right arrow */
309 /* end bar */
310 segment[0].x1 = x2 + 1;
311 segment[0].x2 = x2 + 1;
313 /* arrowhead */
314 segment[1].x1 = x2 - 6;
315 segment[1].x2 = x2;
317 segment[2].x1 = x2;
318 segment[2].x2 = x2 - 6;
320 /* line */
321 segment[3].x1 = mx + fw/2 + 2;
322 segment[3].x2 = x2;
324 XDrawSegments(dpy, root, gc, segment, 4);
326 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
328 /* Display the width. */
329 WMDrawString(scr->wmscreen, root, gc, scr->info_text_font,
330 mx - fw/2 + 1, y - s + fh/2 + 1, num, strlen(num));
331 } else {
332 XClearArea(dpy, scr->geometry_display, 1, 1,
333 scr->geometry_display_width-2, scr->geometry_display_height-2,
334 False);
335 sprintf(num, "%i x %-i", (x2 - x1 - wwin->normal_hints->base_width)
336 / wwin->normal_hints->width_inc,
337 (by - ty - wwin->normal_hints->base_height)
338 / wwin->normal_hints->height_inc);
339 fw = WMWidthOfString(scr->info_text_font, num, strlen(num));
341 XSetForeground(dpy, scr->info_text_gc, scr->black_pixel);
343 /* Display the height. */
344 WMDrawString(scr->wmscreen, scr->geometry_display, scr->info_text_gc,
345 scr->info_text_font,
346 (scr->geometry_display_width-fw)/2,
347 (scr->geometry_display_height-fh)/2, num, strlen(num));
348 wDrawBevel(scr->geometry_display, scr->geometry_display_width+1,
349 scr->geometry_display_height+1,
350 scr->widget_texture, WREL_RAISED);
355 static void
356 cycleGeometryDisplay(WWindow *wwin, int x, int y, int w, int h, int dir)
358 WScreen *scr = wwin->screen_ptr;
360 wPreferences.size_display++;
361 wPreferences.size_display %= NUM_DISPLAYS;
363 if (wPreferences.size_display == WDIS_NEW) {
364 XUnmapWindow(dpy, scr->geometry_display);
365 } else {
366 if (wPreferences.size_display == WDIS_CENTER) {
367 moveGeometryDisplayCentered(scr,
368 scr->scr_width / 2, scr->scr_height / 2);
369 } else if (wPreferences.size_display == WDIS_TOPLEFT) {
370 moveGeometryDisplayCentered(scr, 1, 1);
371 } else if (wPreferences.size_display == WDIS_FRAME_CENTER) {
372 moveGeometryDisplayCentered(scr, x + w/2, y + h/2);
374 XMapRaised(dpy, scr->geometry_display);
375 showGeometry(wwin, x, y, x + w, y + h, dir);
380 static void
381 mapGeometryDisplay(WWindow *wwin, int x, int y, int w, int h)
383 WScreen *scr = wwin->screen_ptr;
385 if (wPreferences.size_display == WDIS_NEW)
386 return;
388 if (wPreferences.size_display == WDIS_CENTER) {
389 moveGeometryDisplayCentered(scr, scr->scr_width / 2,
390 scr->scr_height / 2);
391 } else if (wPreferences.size_display == WDIS_TOPLEFT) {
392 moveGeometryDisplayCentered(scr, 1, 1);
393 } else if (wPreferences.size_display == WDIS_FRAME_CENTER) {
394 moveGeometryDisplayCentered(scr, x + w/2, y + h/2);
396 XMapRaised(dpy, scr->geometry_display);
397 showGeometry(wwin, x, y, x + w, y + h, 0);
400 #define unmapGeometryDisplay(w) \
401 XUnmapWindow(dpy, (w)->screen_ptr->geometry_display);
404 static void
405 doWindowMove(WWindow *wwin, LinkedList *list, int dx, int dy)
407 WWindow *tmpw;
408 int x, y;
409 int scr_width = wwin->screen_ptr->scr_width;
410 int scr_height = wwin->screen_ptr->scr_height;
412 if (!list) {
413 wWindowMove(wwin, wwin->frame_x + dx, wwin->frame_y + dy);
414 } else {
415 while (list) {
416 tmpw = list->head;
417 x = tmpw->frame_x + dx;
418 y = tmpw->frame_y + dy;
420 /* don't let windows become unreachable */
422 if (x + (int)tmpw->frame->core->width < 20)
423 x = 20 - (int)tmpw->frame->core->width;
424 else if (x + 20 > scr_width)
425 x = scr_width - 20;
427 if (y + (int)tmpw->frame->core->height < 20)
428 y = 20 - (int)tmpw->frame->core->height;
429 else if (y + 20 > scr_height)
430 y = scr_height - 20;
432 wWindowMove(tmpw, x, y);
433 list = list->tail;
439 static void
440 drawTransparentFrame(WWindow *wwin, int x, int y, int width, int height)
442 Window root = wwin->screen_ptr->root_win;
443 GC gc = wwin->screen_ptr->frame_gc;
444 int h = 0;
445 int bottom = 0;
447 if (!WFLAGP(wwin, no_titlebar) && !wwin->flags.shaded) {
448 h = WMFontHeight(wwin->screen_ptr->title_font) + TITLEBAR_EXTRA_HEIGHT;
450 if (!WFLAGP(wwin, no_resizebar) && !wwin->flags.shaded) {
451 /* Can't use wwin-frame->bottom_width because, in some cases
452 (e.g. interactive placement), frame does not point to anything. */
453 bottom = RESIZEBAR_HEIGHT - 1;
455 XDrawRectangle(dpy, root, gc, x, y, width + 1, height + 1);
457 if (h > 0) {
458 XDrawLine(dpy, root, gc, x + 1, y + h, x + width + 1, y + h);
460 if (bottom > 0) {
461 XDrawLine(dpy, root, gc, x + 1,
462 y + height - bottom,
463 x + width + 1,
464 y + height - bottom);
469 static void
470 drawFrames(WWindow *wwin, LinkedList *list, int dx, int dy)
472 WWindow *tmpw;
473 int scr_width = wwin->screen_ptr->scr_width;
474 int scr_height = wwin->screen_ptr->scr_height;
475 int x, y;
477 if (!list) {
479 x = wwin->frame_x + dx;
480 y = wwin->frame_y + dy;
482 drawTransparentFrame(wwin, x, y,
483 wwin->frame->core->width,
484 wwin->frame->core->height);
486 } else {
487 while (list) {
488 tmpw = list->head;
489 x = tmpw->frame_x + dx;
490 y = tmpw->frame_y + dy;
492 /* don't let windows become unreachable */
494 if (x + (int)tmpw->frame->core->width < 20)
495 x = 20 - (int)tmpw->frame->core->width;
496 else if (x + 20 > scr_width)
497 x = scr_width - 20;
499 if (y + (int)tmpw->frame->core->height < 20)
500 y = 20 - (int)tmpw->frame->core->height;
501 else if (y + 20 > scr_height)
502 y = scr_height - 20;
504 drawTransparentFrame(tmpw, x, y, tmpw->frame->core->width,
505 tmpw->frame->core->height);
507 list = list->tail;
514 static void
515 flushMotion()
517 XEvent ev;
519 XSync(dpy, False);
520 while (XCheckMaskEvent(dpy, ButtonMotionMask, &ev)) ;
524 static void
525 crossWorkspace(WScreen *scr, WWindow *wwin, int opaque_move,
526 int new_workspace, int rewind)
528 /* do not let window be unmapped */
529 if (opaque_move) {
530 wwin->flags.changing_workspace = 1;
531 wWindowChangeWorkspace(wwin, new_workspace);
533 /* go to new workspace */
534 wWorkspaceChange(scr, new_workspace);
536 wwin->flags.changing_workspace = 0;
538 if (rewind)
539 XWarpPointer(dpy, None, None, 0, 0, 0, 0, scr->scr_width - 20, 0);
540 else
541 XWarpPointer(dpy, None, None, 0, 0, 0, 0, -(scr->scr_width - 20), 0);
543 flushMotion();
545 if (!opaque_move) {
546 XGrabPointer(dpy, scr->root_win, True, PointerMotionMask
547 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
548 GrabModeAsync, None, wCursor[WCUR_MOVE], CurrentTime);
555 typedef struct {
556 /* arrays of WWindows sorted by the respective border position */
557 WWindow **topList; /* top border */
558 WWindow **leftList; /* left border */
559 WWindow **rightList; /* right border */
560 WWindow **bottomList; /* bottom border */
561 int count;
563 /* index of window in the above lists indicating the relative position
564 * of the window with the others */
565 int topIndex;
566 int leftIndex;
567 int rightIndex;
568 int bottomIndex;
570 int rubCount; /* for workspace switching */
572 int winWidth, winHeight; /* width/height of the window */
573 int realX, realY; /* actual position of the window */
574 int calcX, calcY; /* calculated position of window */
575 int omouseX, omouseY; /* old mouse position */
576 int mouseX, mouseY; /* last known position of the pointer */
577 } MoveData;
579 #define WTOP(w) (w)->frame_y
580 #define WLEFT(w) (w)->frame_x
581 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width + FRAME_BORDER_WIDTH)
582 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height + FRAME_BORDER_WIDTH)
584 static int
585 compareWTop(const void *a, const void *b)
587 WWindow *wwin1 = *(WWindow**)a;
588 WWindow *wwin2 = *(WWindow**)b;
590 if (WTOP(wwin1) > WTOP(wwin2))
591 return -1;
592 else if (WTOP(wwin1) < WTOP(wwin2))
593 return 1;
594 else
595 return 0;
599 static int
600 compareWLeft(const void *a, const void *b)
602 WWindow *wwin1 = *(WWindow**)a;
603 WWindow *wwin2 = *(WWindow**)b;
605 if (WLEFT(wwin1) > WLEFT(wwin2))
606 return -1;
607 else if (WLEFT(wwin1) < WLEFT(wwin2))
608 return 1;
609 else
610 return 0;
614 static int
615 compareWRight(const void *a, const void *b)
617 WWindow *wwin1 = *(WWindow**)a;
618 WWindow *wwin2 = *(WWindow**)b;
620 if (WRIGHT(wwin1) < WRIGHT(wwin2))
621 return -1;
622 else if (WRIGHT(wwin1) > WRIGHT(wwin2))
623 return 1;
624 else
625 return 0;
630 static int
631 compareWBottom(const void *a, const void *b)
633 WWindow *wwin1 = *(WWindow**)a;
634 WWindow *wwin2 = *(WWindow**)b;
636 if (WBOTTOM(wwin1) < WBOTTOM(wwin2))
637 return -1;
638 else if (WBOTTOM(wwin1) > WBOTTOM(wwin2))
639 return 1;
640 else
641 return 0;
645 static void
646 updateResistance(WWindow *wwin, MoveData *data, int newX, int newY)
648 int i;
649 int newX2 = newX + data->winWidth;
650 int newY2 = newY + data->winHeight;
651 Bool ok = False;
653 if (newX < data->realX) {
654 if (data->rightIndex > 0
655 && newX < WRIGHT(data->rightList[data->rightIndex-1])) {
656 ok = True;
657 } else if (data->leftIndex <= data->count-1
658 && newX2 <= WLEFT(data->leftList[data->leftIndex])) {
659 ok = True;
661 } else if (newX > data->realX) {
662 if (data->leftIndex > 0
663 && newX2 > WLEFT(data->leftList[data->leftIndex-1])) {
664 ok = True;
665 } else if (data->rightIndex <= data->count-1
666 && newX >= WRIGHT(data->rightList[data->rightIndex])) {
667 ok = True;
671 if (!ok) {
672 if (newY < data->realY) {
673 if (data->bottomIndex > 0
674 && newY < WBOTTOM(data->bottomList[data->bottomIndex-1])) {
675 ok = True;
676 } else if (data->topIndex <= data->count-1
677 && newY2 <= WTOP(data->topList[data->topIndex])) {
678 ok = True;
680 } else if (newY > data->realY) {
681 if (data->topIndex > 0
682 && newY2 > WTOP(data->topList[data->topIndex-1])) {
683 ok = True;
684 } else if (data->bottomIndex <= data->count-1
685 && newY >= WBOTTOM(data->bottomList[data->bottomIndex])) {
686 ok = True;
691 if (!ok)
692 return;
694 /* TODO: optimize this */
695 if (data->realY < WBOTTOM(data->bottomList[0])) {
696 data->bottomIndex = 0;
698 if (data->realX < WRIGHT(data->rightList[0])) {
699 data->rightIndex = 0;
701 if ((data->realX + data->winWidth) > WLEFT(data->leftList[0])) {
702 data->leftIndex = 0;
704 if ((data->realY + data->winHeight) > WTOP(data->topList[0])) {
705 data->topIndex = 0;
707 for (i = 0; i < data->count; i++) {
708 if (data->realY > WBOTTOM(data->bottomList[i])) {
709 data->bottomIndex = i + 1;
711 if (data->realX > WRIGHT(data->rightList[i])) {
712 data->rightIndex = i + 1;
714 if ((data->realX + data->winWidth) < WLEFT(data->leftList[i])) {
715 data->leftIndex = i + 1;
717 if ((data->realY + data->winHeight) < WTOP(data->topList[i])) {
718 data->topIndex = i + 1;
724 static void
725 freeMoveData(MoveData *data)
727 if (data->topList)
728 free(data->topList);
729 if (data->leftList)
730 free(data->leftList);
731 if (data->rightList)
732 free(data->rightList);
733 if (data->bottomList)
734 free(data->bottomList);
738 static void
739 updateMoveData(WWindow *wwin, MoveData *data)
741 WScreen *scr = wwin->screen_ptr;
742 WWindow *tmp;
743 int i;
745 data->count = 0;
746 tmp = scr->focused_window;
747 while (tmp) {
748 if (tmp != wwin && scr->current_workspace == tmp->frame->workspace
749 && !tmp->flags.miniaturized
750 && !tmp->flags.hidden
751 && !tmp->flags.obscured
752 && !WFLAGP(tmp, sunken)) {
753 data->topList[data->count] = tmp;
754 data->leftList[data->count] = tmp;
755 data->rightList[data->count] = tmp;
756 data->bottomList[data->count] = tmp;
757 data->count++;
759 tmp = tmp->prev;
762 if (data->count == 0) {
763 data->topIndex = 0;
764 data->leftIndex = 0;
765 data->rightIndex = 0;
766 data->bottomIndex = 0;
767 return;
771 * order from closest to the border of the screen to farthest
773 qsort(data->topList, data->count, sizeof(WWindow**), compareWTop);
774 qsort(data->leftList, data->count, sizeof(WWindow**), compareWLeft);
775 qsort(data->rightList, data->count, sizeof(WWindow**), compareWRight);
776 qsort(data->bottomList, data->count, sizeof(WWindow**), compareWBottom);
778 /* figure the position of the window relative to the others */
780 data->topIndex = -1;
781 data->leftIndex = -1;
782 data->rightIndex = -1;
783 data->bottomIndex = -1;
785 if (WTOP(wwin) < WBOTTOM(data->bottomList[0])) {
786 data->bottomIndex = 0;
788 if (WLEFT(wwin) < WRIGHT(data->rightList[0])) {
789 data->rightIndex = 0;
791 if (WRIGHT(wwin) > WLEFT(data->leftList[0])) {
792 data->leftIndex = 0;
794 if (WBOTTOM(wwin) > WTOP(data->topList[0])) {
795 data->topIndex = 0;
797 for (i = 0; i < data->count; i++) {
798 if (WTOP(wwin) >= WBOTTOM(data->bottomList[i])) {
799 data->bottomIndex = i + 1;
801 if (WLEFT(wwin) >= WRIGHT(data->rightList[i])) {
802 data->rightIndex = i + 1;
804 if (WRIGHT(wwin) <= WLEFT(data->leftList[i])) {
805 data->leftIndex = i + 1;
807 if (WBOTTOM(wwin) <= WTOP(data->topList[i])) {
808 data->topIndex = i + 1;
814 static void
815 initMoveData(WWindow *wwin, MoveData *data)
817 int i;
818 WWindow *tmp;
820 memset(data, 0, sizeof(MoveData));
822 for (i = 0, tmp = wwin->screen_ptr->focused_window;
823 tmp != NULL;
824 tmp = tmp->prev, i++);
826 if (i > 1) {
827 data->topList = wmalloc(sizeof(WWindow*) * i);
828 data->leftList = wmalloc(sizeof(WWindow*) * i);
829 data->rightList = wmalloc(sizeof(WWindow*) * i);
830 data->bottomList = wmalloc(sizeof(WWindow*) * i);
832 updateMoveData(wwin, data);
835 data->realX = wwin->frame_x;
836 data->realY = wwin->frame_y;
837 data->calcX = wwin->frame_x;
838 data->calcY = wwin->frame_y;
840 data->winWidth = wwin->frame->core->width + 2;
841 data->winHeight = wwin->frame->core->height + 2;
845 static Bool
846 checkWorkspaceChange(WWindow *wwin, MoveData *data, Bool opaqueMove)
848 WScreen *scr = wwin->screen_ptr;
849 Bool changed = False;
851 if (data->mouseX <= 1) {
852 if (scr->current_workspace > 0) {
854 crossWorkspace(scr, wwin, opaqueMove, scr->current_workspace - 1,
855 True);
856 changed = True;
857 data->rubCount = 0;
859 } else if (scr->current_workspace == 0 && wPreferences.ws_cycle) {
861 crossWorkspace(scr, wwin, opaqueMove, scr->workspace_count - 1,
862 True);
863 changed = True;
864 data->rubCount = 0;
866 } else if (data->mouseX >= scr->scr_width - 2) {
868 if (scr->current_workspace == scr->workspace_count - 1) {
870 if (wPreferences.ws_cycle
871 || scr->workspace_count == MAX_WORKSPACES) {
873 crossWorkspace(scr, wwin, opaqueMove, 0, False);
874 changed = True;
875 data->rubCount = 0;
877 /* if user insists on trying to go to next workspace even when
878 * it's already the last, create a new one */
879 else if (data->omouseX == data->mouseX
880 && wPreferences.ws_advance) {
882 /* detect user "rubbing" the window against the edge */
883 if (data->rubCount > 0
884 && data->omouseY - data->mouseY > MOVE_THRESHOLD) {
886 data->rubCount = -(data->rubCount + 1);
888 } else if (data->rubCount <= 0
889 && data->mouseY - data->omouseY > MOVE_THRESHOLD) {
891 data->rubCount = -data->rubCount + 1;
894 /* create a new workspace */
895 if (abs(data->rubCount) > 2) {
896 /* go to next workspace */
897 wWorkspaceNew(scr);
899 crossWorkspace(scr, wwin, opaqueMove,
900 scr->current_workspace+1, False);
901 changed = True;
902 data->rubCount = 0;
904 } else if (scr->current_workspace < scr->workspace_count) {
906 /* go to next workspace */
907 crossWorkspace(scr, wwin, opaqueMove,
908 scr->current_workspace+1, False);
909 changed = True;
910 data->rubCount = 0;
912 } else {
913 data->rubCount = 0;
916 return changed;
920 static void
921 updateWindowPosition(WWindow *wwin, MoveData *data, Bool doResistance,
922 Bool opaqueMove, int newMouseX, int newMouseY)
924 WScreen *scr = wwin->screen_ptr;
925 int dx, dy; /* how much mouse moved */
926 int winL, winR, winT, winB; /* requested new window position */
927 int newX, newY; /* actual new window position */
928 Bool hresist, vresist;
929 Bool updateIndex;
930 Bool attract;
932 hresist = False;
933 vresist = False;
935 updateIndex = False;
937 /* check the direction of the movement */
938 dx = newMouseX - data->mouseX;
939 dy = newMouseY - data->mouseY;
941 data->omouseX = data->mouseX;
942 data->omouseY = data->mouseY;
943 data->mouseX = newMouseX;
944 data->mouseY = newMouseY;
946 winL = data->calcX + dx;
947 winR = data->calcX + data->winWidth + dx;
948 winT = data->calcY + dy;
949 winB = data->calcY + data->winHeight + dy;
951 newX = data->realX;
952 newY = data->realY;
954 if (doResistance) {
955 int l_edge, r_edge;
956 int edge_l, edge_r;
957 int t_edge, b_edge;
958 int edge_t, edge_b;
959 int resist;
960 WWindow *rwin;
961 WWindow *rrwin;
963 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
964 attract = wPreferences.attract;
965 /* horizontal movement: check horizontal edge resistances */
966 if (dx || dy) {
967 int i;
968 /* window is the leftmost window: check against screen edge */
969 l_edge = scr->totalUsableArea.x1;
970 r_edge = scr->totalUsableArea.x2 + resist;
971 edge_l = scr->totalUsableArea.x1 - resist;
972 edge_r = scr->totalUsableArea.x2;
974 /* 1 */
975 if ((data->rightIndex >= 0) && (data->rightIndex <= data->count)) {
976 WWindow *looprw;
978 for (i = data->rightIndex - 1; i >= 0; i--) {
979 looprw = data->rightList[i];
980 if (!(data->realY > WBOTTOM(looprw)
981 || (data->realY + data->winHeight) < WTOP(looprw))) {
982 if (attract || (data->realX < (WRIGHT(looprw) + 2)) && dx < 0) {
983 l_edge = WRIGHT(looprw) + 1;
984 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
986 break;
990 if (attract) {
991 for (i = data->rightIndex; i < data->count; i++) {
992 looprw = data->rightList[i];
993 if(!(data->realY > WBOTTOM(looprw)
994 || (data->realY + data->winHeight) < WTOP(looprw))) {
995 r_edge = WRIGHT(looprw) + 1;
996 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
997 break;
1003 if ((data->leftIndex >= 0) && (data->leftIndex <= data->count)) {
1004 WWindow *looprw;
1006 for (i = data->leftIndex - 1; i >= 0; i--) {
1007 looprw = data->leftList[i];
1008 if (!(data->realY > WBOTTOM(looprw)
1009 || (data->realY + data->winHeight) < WTOP(looprw))) {
1010 if (attract || ((data->realX + data->winWidth) > (WLEFT(looprw) - 1)) && dx > 0) {
1011 edge_r = WLEFT(looprw);
1012 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1014 break;
1018 if (attract)
1019 for (i = data->leftIndex; i < data->count; i++) {
1020 looprw = data->leftList[i];
1021 if(!(data->realY > WBOTTOM(looprw)
1022 || (data->realY + data->winHeight) < WTOP(looprw))) {
1023 edge_l = WLEFT(looprw);
1024 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1025 break;
1031 printf("%d %d\n",winL,winR);
1032 printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);
1035 if ((winL - l_edge) < (r_edge - winL)) {
1036 if (resist > 0) {
1037 if ((attract && winL <= l_edge + resist && winL >= l_edge - resist)
1038 || (dx < 0 && winL <= l_edge && winL >= l_edge - resist)) {
1039 newX = l_edge;
1040 hresist = True;
1044 else {
1045 if (resist > 0 && attract && winL >= r_edge - resist && winL <= r_edge + resist) {
1046 newX = r_edge;
1047 hresist = True;
1051 if ((winR - edge_l) < (edge_r - winR)) {
1052 if (resist > 0 && attract && winR <= edge_l + resist && winR >= edge_l - resist) {
1053 newX = edge_l - data->winWidth;
1054 hresist = True;
1057 else {
1058 if (resist > 0) {
1059 if ((attract && winR >= edge_r - resist && winR <= edge_r + resist)
1060 || (dx > 0 && winR >= edge_r && winR <= edge_r + resist)) {
1061 newX = edge_r - data->winWidth;
1062 hresist = True;
1067 /* VeRT */
1068 t_edge = scr->totalUsableArea.y1;
1069 b_edge = scr->totalUsableArea.y2 + resist;
1070 edge_t = scr->totalUsableArea.y1 - resist;
1071 edge_b = scr->totalUsableArea.y2;
1073 if ((data->bottomIndex >= 0) && (data->bottomIndex <= data->count)) {
1074 WWindow *looprw;
1076 for (i = data->bottomIndex - 1; i >= 0; i--) {
1077 looprw = data->bottomList[i];
1078 if (!(data->realX > WRIGHT(looprw)
1079 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1080 if (attract || (data->realY < (WBOTTOM(looprw) + 2)) && dy < 0) {
1081 t_edge = WBOTTOM(looprw) + 1;
1082 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1084 break;
1088 if (attract) {
1089 for (i = data->bottomIndex; i < data->count; i++) {
1090 looprw = data->bottomList[i];
1091 if(!(data->realX > WRIGHT(looprw)
1092 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1093 b_edge = WBOTTOM(looprw) + 1;
1094 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1095 break;
1101 if ((data->topIndex >= 0) && (data->topIndex <= data->count)) {
1102 WWindow *looprw;
1104 for (i = data->topIndex - 1; i >= 0; i--) {
1105 looprw = data->topList[i];
1106 if (!(data->realX > WRIGHT(looprw)
1107 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1108 if (attract || ((data->realY + data->winHeight) > (WTOP(looprw) - 1)) && dy > 0) {
1109 edge_b = WTOP(looprw);
1110 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1112 break;
1116 if (attract)
1117 for (i = data->topIndex; i < data->count; i++) {
1118 looprw = data->topList[i];
1119 if(!(data->realX > WRIGHT(looprw)
1120 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1121 edge_t = WTOP(looprw);
1122 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1123 break;
1128 if ((winT - t_edge) < (b_edge - winT)) {
1129 if (resist > 0) {
1130 if ((attract && winT <= t_edge + resist && winT >= t_edge - resist)
1131 || (dy < 0 && winT <= t_edge && winT >= t_edge - resist)) {
1132 newY = t_edge;
1133 vresist = True;
1137 else {
1138 if (resist > 0 && attract && winT >= b_edge - resist && winT <= b_edge + resist) {
1139 newY = b_edge;
1140 vresist = True;
1144 if ((winB - edge_t) < (edge_b - winB)) {
1145 if (resist > 0 && attract && winB <= edge_t + resist && winB >= edge_t - resist) {
1146 newY = edge_t - data->winHeight;
1147 vresist = True;
1150 else {
1151 if (resist > 0) {
1152 if ((attract && winB >= edge_b - resist && winB <= edge_b + resist)
1153 || (dy > 0 && winB >= edge_b && winB <= edge_b + resist)) {
1154 newY = edge_b - data->winHeight;
1155 vresist = True;
1160 /* END VeRT */
1164 /* update window position */
1165 data->calcX += dx;
1166 data->calcY += dy;
1168 if (((dx > 0 && data->calcX - data->realX > 0)
1169 || (dx < 0 && data->calcX - data->realX < 0)) && !hresist)
1170 newX = data->calcX;
1172 if (((dy > 0 && data->calcY - data->realY > 0)
1173 || (dy < 0 && data->calcY - data->realY < 0)) && !vresist)
1174 newY = data->calcY;
1176 if (data->realX != newX || data->realY != newY) {
1178 if (wPreferences.move_display == WDIS_NEW
1179 && !scr->selected_windows) {
1180 showPosition(wwin, data->realX, data->realY);
1182 if (opaqueMove) {
1183 doWindowMove(wwin, scr->selected_windows,
1184 newX - wwin->frame_x,
1185 newY - wwin->frame_y);
1186 } else {
1187 /* erase frames */
1188 drawFrames(wwin, scr->selected_windows,
1189 data->realX - wwin->frame_x,
1190 data->realY - wwin->frame_y);
1193 if (!scr->selected_windows
1194 && wPreferences.move_display == WDIS_FRAME_CENTER) {
1196 moveGeometryDisplayCentered(scr, newX + data->winWidth/2,
1197 newY + data->winHeight/2);
1200 if (!opaqueMove) {
1201 /* draw frames */
1202 drawFrames(wwin, scr->selected_windows,
1203 newX - wwin->frame_x,
1204 newY - wwin->frame_y);
1207 if (!scr->selected_windows) {
1208 showPosition(wwin, newX, newY);
1213 /* recalc relative window position */
1214 if (doResistance && (data->realX != newX || data->realY != newY)) {
1215 updateResistance(wwin, data, newX, newY);
1218 data->realX = newX;
1219 data->realY = newY;
1223 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1226 wKeyboardMoveResizeWindow(WWindow *wwin)
1228 WScreen *scr = wwin->screen_ptr;
1229 Window root = scr->root_win;
1230 XEvent event;
1231 int w = wwin->frame->core->width;
1232 int h = wwin->frame->core->height;
1233 int scr_width = wwin->screen_ptr->scr_width;
1234 int scr_height = wwin->screen_ptr->scr_height;
1235 int vert_border = wwin->frame->top_width + wwin->frame->bottom_width;
1236 int src_x = wwin->frame_x;
1237 int src_y = wwin->frame_y;
1238 int done,off_x,off_y,ww,wh;
1239 int kspeed = _KS;
1240 Time lastTime = 0;
1241 KeySym keysym=NoSymbol;
1242 int moment=0;
1243 KeyCode shiftl,shiftr,ctrll,ctrlmode;
1245 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1246 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1247 ctrll = XKeysymToKeycode(dpy, XK_Control_L);
1248 ctrlmode=done=off_x=off_y=0;
1250 XSync(dpy, False);
1251 wusleep(10000);
1252 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync, CurrentTime);
1254 if (!wwin->flags.selected) {
1255 wUnselectWindows(scr);
1257 XGrabServer(dpy);
1258 XGrabPointer(dpy, scr->root_win, True, PointerMotionMask
1259 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
1260 GrabModeAsync, None, wCursor[WCUR_DEFAULT], CurrentTime);
1262 if (wwin->flags.shaded || scr->selected_windows) {
1263 if(scr->selected_windows)
1264 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1265 else drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1266 if(!scr->selected_windows)
1267 mapPositionDisplay(wwin, src_x, src_y, w, h);
1268 } else {
1269 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1271 ww=w;
1272 wh=h;
1273 while(1) {
1275 looper.ox=off_x;
1276 looper.oy=off_y;
1278 WMMaskEvent(dpy, KeyPressMask | ButtonReleaseMask
1279 | ButtonPressMask | ExposureMask, &event);
1280 if (wwin->flags.shaded || scr->selected_windows) {
1281 if(scr->selected_windows)
1282 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1283 else drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1284 /*** I HATE EDGE RESISTANCE - ]d ***/
1286 else {
1287 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, ww, wh);
1290 if(ctrlmode)
1291 showGeometry(wwin, src_x+off_x, src_y+off_y, src_x+off_x+ww, src_y+off_y+wh,0);
1293 XUngrabServer(dpy);
1294 XSync(dpy, False);
1296 switch (event.type) {
1297 case KeyPress:
1298 /* accelerate */
1299 if (event.xkey.time - lastTime > 50) {
1300 kspeed/=(1 + (event.xkey.time - lastTime)/100);
1301 } else {
1302 if (kspeed < 20) {
1303 kspeed++;
1306 if (kspeed < _KS) kspeed = _KS;
1307 lastTime = event.xkey.time;
1309 if (event.xkey.state & ControlMask && !wwin->flags.shaded) {
1310 ctrlmode=1;
1311 wUnselectWindows(scr);
1313 else {
1314 ctrlmode=0;
1316 if (event.xkey.keycode == shiftl || event.xkey.keycode == shiftr) {
1317 if (ctrlmode)
1318 cycleGeometryDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh, 0);
1319 else
1320 cyclePositionDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh);
1322 else {
1324 keysym = XLookupKeysym(&event.xkey, 0);
1325 switch (keysym) {
1326 case XK_Return:
1327 done=2;
1328 break;
1329 case XK_Escape:
1330 done=1;
1331 break;
1332 case XK_Up:
1333 case XK_KP_Up:
1334 case XK_k:
1335 if (ctrlmode){
1336 if (moment != UP)
1337 h = wh;
1338 h-=kspeed;
1339 moment = UP;
1340 if (h < 1) h = 1;
1342 else off_y-=kspeed;
1343 break;
1344 case XK_Down:
1345 case XK_KP_Down:
1346 case XK_j:
1347 if (ctrlmode){
1348 if (moment != DOWN)
1349 h = wh;
1350 h+=kspeed;
1351 moment = DOWN;
1353 else off_y+=kspeed;
1354 break;
1355 case XK_Left:
1356 case XK_KP_Left:
1357 case XK_h:
1358 if (ctrlmode) {
1359 if (moment != LEFT)
1360 w = ww;
1361 w-=kspeed;
1362 if (w < 1) w = 1;
1363 moment = LEFT;
1365 else off_x-=kspeed;
1366 break;
1367 case XK_Right:
1368 case XK_KP_Right:
1369 case XK_l:
1370 if (ctrlmode) {
1371 if (moment != RIGHT)
1372 w = ww;
1373 w+=kspeed;
1374 moment = RIGHT;
1376 else off_x+=kspeed;
1377 break;
1380 ww=w;wh=h;
1381 wh-=vert_border;
1382 wWindowConstrainSize(wwin, &ww, &wh);
1383 wh+=vert_border;
1385 if (wPreferences.ws_cycle){
1386 if (src_x + off_x + ww < 20){
1387 if(!scr->current_workspace) {
1388 wWorkspaceChange(scr, scr->workspace_count-1);
1390 else wWorkspaceChange(scr, scr->current_workspace-1);
1391 off_x += scr_width;
1393 else if (src_x + off_x + 20 > scr_width){
1394 if(scr->current_workspace == scr->workspace_count-1) {
1395 wWorkspaceChange(scr, 0);
1397 else wWorkspaceChange(scr, scr->current_workspace+1);
1398 off_x -= scr_width;
1401 else {
1402 if (src_x + off_x + ww < 20)
1403 off_x = 20 - ww - src_x;
1404 else if (src_x + off_x + 20 > scr_width)
1405 off_x = scr_width - 20 - src_x;
1408 if (src_y + off_y + wh < 20) {
1409 off_y = 20 - wh - src_y;
1411 else if (src_y + off_y + 20 > scr_height) {
1412 off_y = scr_height - 20 - src_y;
1415 break;
1416 case ButtonPress:
1417 case ButtonRelease:
1418 done=1;
1419 break;
1420 default:
1421 WMHandleEvent(&event);
1422 break;
1425 XGrabServer(dpy);
1426 /*xxx*/
1428 if (wwin->flags.shaded && !scr->selected_windows){
1429 moveGeometryDisplayCentered(scr, src_x+off_x + w/2, src_y+off_y + h/2);
1431 else {
1432 if(ctrlmode){
1433 unmapPositionDisplay(wwin);
1434 mapGeometryDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh);
1436 else if(!scr->selected_windows){
1437 unmapGeometryDisplay(wwin);
1438 mapPositionDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh);
1442 if (wwin->flags.shaded || scr->selected_windows) {
1443 if(scr->selected_windows)
1444 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1445 else drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1447 else {
1448 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, ww, wh);
1452 if(ctrlmode){
1453 showGeometry(wwin, src_x+off_x, src_y+off_y, src_x+off_x+ww, src_y+off_y+wh,0);
1455 else if(!scr->selected_windows)
1456 showPosition(wwin, src_x+off_x, src_y+off_y);
1457 /**/
1459 if(done){
1460 scr->keymove_tick=0;
1462 WMDeleteTimerWithClientData(&looper);
1464 if (wwin->flags.shaded || scr->selected_windows) {
1465 if(scr->selected_windows)
1466 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1467 else drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1469 else {
1470 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, ww, wh);
1473 if(ctrlmode){
1474 showGeometry(wwin, src_x+off_x, src_y+off_y, src_x+off_x+ww, src_y+off_y+wh,0);
1475 unmapGeometryDisplay(wwin);
1477 else
1478 unmapPositionDisplay(wwin);
1479 XUngrabKeyboard(dpy, CurrentTime);
1480 XUngrabPointer(dpy, CurrentTime);
1481 XUngrabServer(dpy);
1483 if(done==2) {
1484 if (wwin->flags.shaded || scr->selected_windows) {
1485 LinkedList *list;
1486 list=scr->selected_windows;
1487 if (!scr->selected_windows) {
1488 wWindowMove(wwin, src_x+off_x, src_y+off_y);
1489 wWindowSynthConfigureNotify(wwin);
1490 } else {
1491 doWindowMove(wwin,scr->selected_windows,off_x,off_y);
1492 while (list) {
1493 wWindowSynthConfigureNotify(list->head);
1494 list = list->tail;
1497 } else {
1498 if (wwin->client.width != ww)
1499 wwin->flags.user_changed_width = 1;
1501 if (wwin->client.height != wh - vert_border)
1502 wwin->flags.user_changed_height = 1;
1504 wWindowConfigure(wwin, src_x+off_x, src_y+off_y,
1505 ww, wh - vert_border);
1506 wWindowSynthConfigureNotify(wwin);
1508 wWindowChangeWorkspace(wwin, scr->current_workspace);
1509 wSetFocusTo(scr, wwin);
1511 return 1;
1518 *----------------------------------------------------------------------
1519 * wMouseMoveWindow--
1520 * Move the named window and the other selected ones (if any),
1521 * interactively. Also shows the position of the window, if only one
1522 * window is being moved.
1523 * If the window is not on the selected window list, the selected
1524 * windows are deselected.
1525 * If shift is pressed during the operation, the position display
1526 * is changed to another type.
1528 * Returns:
1529 * True if the window was moved, False otherwise.
1531 * Side effects:
1532 * The window(s) position is changed, and the client(s) are
1533 * notified about that.
1534 * The position display configuration may be changed.
1535 *----------------------------------------------------------------------
1538 wMouseMoveWindow(WWindow *wwin, XEvent *ev)
1540 WScreen *scr = wwin->screen_ptr;
1541 XEvent event;
1542 Window root = scr->root_win;
1543 KeyCode shiftl, shiftr;
1544 Bool done = False;
1545 int started = 0;
1546 int warped = 0;
1547 /* This needs not to change while moving, else bad things can happen */
1548 int opaqueMove = wPreferences.opaque_move;
1549 MoveData moveData;
1550 #ifdef GHOST_WINDOW_MOVE
1551 RImage *rimg;
1553 rimg = InitGhostWindowMove(scr);
1554 #endif
1557 if (wPreferences.opaque_move && !wPreferences.use_saveunders) {
1558 XSetWindowAttributes attr;
1560 attr.save_under = True;
1561 XChangeWindowAttributes(dpy, wwin->frame->core->window,
1562 CWSaveUnder, &attr);
1566 initMoveData(wwin, &moveData);
1568 moveData.mouseX = ev->xmotion.x_root;
1569 moveData.mouseY = ev->xmotion.y_root;
1571 if (!wwin->flags.selected) {
1572 /* this window is not selected, unselect others and move only wwin */
1573 wUnselectWindows(scr);
1575 #ifdef DEBUG
1576 puts("Moving window");
1577 #endif
1578 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1579 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1580 while (!done) {
1581 if (warped) {
1582 int junk;
1583 Window junkw;
1585 /* XWarpPointer() doesn't seem to generate Motion events, so
1586 we've got to simulate them */
1587 XQueryPointer(dpy, root, &junkw, &junkw, &event.xmotion.x_root,
1588 &event.xmotion.y_root, &junk, &junk,
1589 (unsigned *) &junk);
1590 } else {
1591 WMMaskEvent(dpy, KeyPressMask | ButtonMotionMask
1592 | ButtonReleaseMask | ButtonPressMask | ExposureMask,
1593 &event);
1595 if (event.type == MotionNotify) {
1596 /* compress MotionNotify events */
1597 while (XCheckMaskEvent(dpy, ButtonMotionMask, &event)) ;
1600 switch (event.type) {
1601 case KeyPress:
1602 if ((event.xkey.keycode == shiftl || event.xkey.keycode == shiftr)
1603 && started && !scr->selected_windows) {
1605 if (!opaqueMove) {
1606 drawFrames(wwin, scr->selected_windows,
1607 moveData.realX - wwin->frame_x,
1608 moveData.realY - wwin->frame_y);
1611 if (wPreferences.move_display == WDIS_NEW
1612 && !scr->selected_windows) {
1613 showPosition(wwin, moveData.realX, moveData.realY);
1614 XUngrabServer(dpy);
1616 cyclePositionDisplay(wwin, moveData.realX, moveData.realY,
1617 moveData.winWidth, moveData.winHeight);
1619 if (wPreferences.move_display == WDIS_NEW
1620 && !scr->selected_windows) {
1621 XGrabServer(dpy);
1622 showPosition(wwin, moveData.realX, moveData.realY);
1625 if (!opaqueMove) {
1626 drawFrames(wwin, scr->selected_windows,
1627 moveData.realX - wwin->frame_x,
1628 moveData.realY - wwin->frame_y);
1631 break;
1633 case MotionNotify:
1634 if (started) {
1635 updateWindowPosition(wwin, &moveData,
1636 scr->selected_windows == NULL
1637 && wPreferences.edge_resistance > 0,
1638 opaqueMove,
1639 event.xmotion.x_root,
1640 event.xmotion.y_root);
1642 if (!warped && !wPreferences.no_autowrap) {
1643 int oldWorkspace = scr->current_workspace;
1645 if (wPreferences.move_display == WDIS_NEW
1646 && !scr->selected_windows) {
1647 showPosition(wwin, moveData.realX, moveData.realY);
1648 XUngrabServer(dpy);
1650 if (!opaqueMove) {
1651 drawFrames(wwin, scr->selected_windows,
1652 moveData.realX - wwin->frame_x,
1653 moveData.realY - wwin->frame_y);
1655 if (checkWorkspaceChange(wwin, &moveData, opaqueMove)) {
1656 if (scr->current_workspace != oldWorkspace
1657 && wPreferences.edge_resistance > 0
1658 && scr->selected_windows == NULL)
1659 updateMoveData(wwin, &moveData);
1660 warped = 1;
1662 if (!opaqueMove) {
1663 drawFrames(wwin, scr->selected_windows,
1664 moveData.realX - wwin->frame_x,
1665 moveData.realY - wwin->frame_y);
1667 if (wPreferences.move_display == WDIS_NEW
1668 && !scr->selected_windows) {
1669 XSync(dpy, False);
1670 showPosition(wwin, moveData.realX, moveData.realY);
1671 XGrabServer(dpy);
1673 } else {
1674 warped = 0;
1676 } else if (abs(ev->xmotion.x_root - event.xmotion.x_root) >= MOVE_THRESHOLD
1677 || abs(ev->xmotion.y_root - event.xmotion.y_root) >= MOVE_THRESHOLD) {
1679 XChangeActivePointerGrab(dpy, ButtonMotionMask
1680 | ButtonReleaseMask | ButtonPressMask,
1681 wCursor[WCUR_MOVE], CurrentTime);
1682 started = 1;
1683 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync,
1684 CurrentTime);
1686 if (!scr->selected_windows)
1687 mapPositionDisplay(wwin, moveData.realX, moveData.realY,
1688 moveData.winWidth, moveData.winHeight);
1690 if (started && !opaqueMove)
1691 drawFrames(wwin, scr->selected_windows, 0, 0);
1693 if (!opaqueMove || (wPreferences.move_display==WDIS_NEW
1694 && !scr->selected_windows)) {
1695 XGrabServer(dpy);
1696 if (wPreferences.move_display==WDIS_NEW)
1697 showPosition(wwin, moveData.realX, moveData.realY);
1700 break;
1702 case ButtonPress:
1703 break;
1705 case ButtonRelease:
1706 if (event.xbutton.button != ev->xbutton.button)
1707 break;
1709 if (started) {
1710 if (!opaqueMove) {
1711 drawFrames(wwin, scr->selected_windows,
1712 moveData.realX - wwin->frame_x,
1713 moveData.realY - wwin->frame_y);
1714 XSync(dpy, 0);
1715 doWindowMove(wwin, scr->selected_windows,
1716 moveData.realX - wwin->frame_x,
1717 moveData.realY - wwin->frame_y);
1719 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1720 wWindowSynthConfigureNotify(wwin);
1721 #endif
1722 XUngrabKeyboard(dpy, CurrentTime);
1723 XUngrabServer(dpy);
1724 if (!opaqueMove) {
1725 wWindowChangeWorkspace(wwin, scr->current_workspace);
1726 wSetFocusTo(scr, wwin);
1728 if (wPreferences.move_display == WDIS_NEW)
1729 showPosition(wwin, moveData.realX, moveData.realY);
1731 if (!scr->selected_windows) {
1732 /* get rid of the geometry window */
1733 unmapPositionDisplay(wwin);
1736 #ifdef DEBUG
1737 puts("End move window");
1738 #endif
1739 done = True;
1740 break;
1742 default:
1743 if (started && !opaqueMove) {
1744 drawFrames(wwin, scr->selected_windows,
1745 moveData.realX - wwin->frame_x,
1746 moveData.realY - wwin->frame_y);
1747 XUngrabServer(dpy);
1748 WMHandleEvent(&event);
1749 XSync(dpy, False);
1750 XGrabServer(dpy);
1751 drawFrames(wwin, scr->selected_windows,
1752 moveData.realX - wwin->frame_x,
1753 moveData.realY - wwin->frame_y);
1754 } else {
1755 WMHandleEvent(&event);
1757 break;
1761 if (wPreferences.opaque_move && !wPreferences.use_saveunders) {
1762 XSetWindowAttributes attr;
1765 attr.save_under = False;
1766 XChangeWindowAttributes(dpy, wwin->frame->core->window,
1767 CWSaveUnder, &attr);
1771 freeMoveData(&moveData);
1773 return started;
1777 #define RESIZEBAR 1
1778 #define HCONSTRAIN 2
1780 static int
1781 getResizeDirection(WWindow *wwin, int x, int y, int dx, int dy,
1782 int flags)
1784 int w = wwin->frame->core->width - 1;
1785 int cw = wwin->frame->resizebar_corner_width;
1786 int dir;
1788 /* if not resizing through the resizebar */
1789 if (!(flags & RESIZEBAR)) {
1790 int xdir = (abs(x) < (wwin->client.width/2)) ? LEFT : RIGHT;
1791 int ydir = (abs(y) < (wwin->client.height/2)) ? UP : DOWN;
1792 if (abs(dx) < 2 || abs(dy) < 2) {
1793 if (abs(dy) > abs(dx))
1794 xdir = 0;
1795 else
1796 ydir = 0;
1798 return (xdir | ydir);
1801 /* window is too narrow. allow diagonal resize */
1802 if (cw * 2 >= w) {
1803 int ydir;
1805 if (flags & HCONSTRAIN)
1806 ydir = 0;
1807 else
1808 ydir = DOWN;
1809 if (x < cw)
1810 return (LEFT | ydir);
1811 else
1812 return (RIGHT | ydir);
1814 /* vertical resize */
1815 if ((x > cw) && (x < w - cw))
1816 return DOWN;
1818 if (x < cw)
1819 dir = LEFT;
1820 else
1821 dir = RIGHT;
1823 if ((abs(dy) > 0) && !(flags & HCONSTRAIN))
1824 dir |= DOWN;
1826 return dir;
1830 void
1831 wMouseResizeWindow(WWindow *wwin, XEvent *ev)
1833 XEvent event;
1834 WScreen *scr = wwin->screen_ptr;
1835 Window root = scr->root_win;
1836 int vert_border = wwin->frame->top_width + wwin->frame->bottom_width;
1837 int fw = wwin->frame->core->width;
1838 int fh = wwin->frame->core->height;
1839 int fx = wwin->frame_x;
1840 int fy = wwin->frame_y;
1841 int is_resizebar = (wwin->frame->resizebar
1842 && ev->xany.window==wwin->frame->resizebar->window);
1843 int orig_x, orig_y;
1844 int started;
1845 int dw, dh;
1846 int rw = fw, rh = fh;
1847 int rx1, ry1, rx2, ry2;
1848 int res = 0;
1849 KeyCode shiftl, shiftr;
1850 int h = 0;
1851 int orig_fx = fx;
1852 int orig_fy = fy;
1853 int orig_fw = fw;
1854 int orig_fh = fh;
1856 if (wwin->flags.shaded) {
1857 wwarning("internal error: tryein");
1858 return;
1860 orig_x = ev->xbutton.x_root;
1861 orig_y = ev->xbutton.y_root;
1863 started = 0;
1864 #ifdef DEBUG
1865 puts("Resizing window");
1866 #endif
1868 wUnselectWindows(scr);
1869 rx1 = fx;
1870 rx2 = fx + fw - 1;
1871 ry1 = fy;
1872 ry2 = fy + fh - 1;
1873 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1874 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1875 if (!WFLAGP(wwin, no_titlebar))
1876 h = WMFontHeight(wwin->screen_ptr->title_font) + TITLEBAR_EXTRA_HEIGHT;
1877 else
1878 h = 0;
1879 while (1) {
1880 WMMaskEvent(dpy, KeyPressMask | ButtonMotionMask | ButtonReleaseMask
1881 | ButtonPressMask | ExposureMask, &event);
1882 switch (event.type) {
1883 case KeyPress:
1884 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1885 if ((event.xkey.keycode == shiftl || event.xkey.keycode == shiftr)
1886 && started) {
1887 drawTransparentFrame(wwin, fx, fy, fw, fh);
1888 cycleGeometryDisplay(wwin, fx, fy, fw, fh, res);
1889 drawTransparentFrame(wwin, fx, fy, fw, fh);
1891 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1892 break;
1894 case MotionNotify:
1895 if (started) {
1896 dw = 0;
1897 dh = 0;
1899 orig_fx = fx;
1900 orig_fy = fy;
1901 orig_fw = fw;
1902 orig_fh = fh;
1904 if (res & LEFT)
1905 dw = orig_x - event.xmotion.x_root;
1906 else if (res & RIGHT)
1907 dw = event.xmotion.x_root - orig_x;
1908 if (res & UP)
1909 dh = orig_y - event.xmotion.y_root;
1910 else if (res & DOWN)
1911 dh = event.xmotion.y_root - orig_y;
1913 orig_x = event.xmotion.x_root;
1914 orig_y = event.xmotion.y_root;
1916 rw += dw;
1917 rh += dh;
1918 fw = rw;
1919 fh = rh - vert_border;
1920 wWindowConstrainSize(wwin, &fw, &fh);
1921 fh += vert_border;
1922 if (res & LEFT)
1923 fx = rx2 - fw + 1;
1924 else if (res & RIGHT)
1925 fx = rx1;
1926 if (res & UP)
1927 fy = ry2 - fh + 1;
1928 else if (res & DOWN)
1929 fy = ry1;
1930 } else if (abs(orig_x - event.xmotion.x_root) >= MOVE_THRESHOLD
1931 || abs(orig_y - event.xmotion.y_root) >= MOVE_THRESHOLD) {
1932 int tx, ty;
1933 Window junkw;
1934 int flags;
1936 XTranslateCoordinates(dpy, root, wwin->frame->core->window,
1937 orig_x, orig_y, &tx, &ty, &junkw);
1939 /* check if resizing through resizebar */
1940 if (is_resizebar)
1941 flags = RESIZEBAR;
1942 else
1943 flags = 0;
1945 if (is_resizebar && ((ev->xbutton.state & ShiftMask)
1946 || abs(orig_y - event.xmotion.y_root) < HRESIZE_THRESHOLD))
1947 flags |= HCONSTRAIN;
1949 res = getResizeDirection(wwin, tx, ty,
1950 orig_x - event.xmotion.x_root,
1951 orig_y - event.xmotion.y_root, flags);
1953 XChangeActivePointerGrab(dpy, ButtonMotionMask
1954 | ButtonReleaseMask | ButtonPressMask,
1955 wCursor[WCUR_RESIZE], CurrentTime);
1956 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync,
1957 CurrentTime);
1959 XGrabServer(dpy);
1961 /* Draw the resize frame for the first time. */
1962 mapGeometryDisplay(wwin, fx, fy, fw, fh);
1964 drawTransparentFrame(wwin, fx, fy, fw, fh);
1966 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1968 started = 1;
1970 if (started) {
1971 if (wPreferences.size_display == WDIS_FRAME_CENTER) {
1972 drawTransparentFrame(wwin, orig_fx, orig_fy,
1973 orig_fw, orig_fh);
1974 moveGeometryDisplayCentered(scr, fx + fw / 2, fy + fh / 2);
1975 drawTransparentFrame(wwin, fx, fy, fw, fh);
1976 } else {
1977 drawTransparentFrame(wwin, orig_fx, orig_fy,
1978 orig_fw, orig_fh);
1979 drawTransparentFrame(wwin, fx, fy, fw, fh);
1981 if (fh != orig_fh || fw != orig_fw) {
1982 if (wPreferences.size_display == WDIS_NEW) {
1983 showGeometry(wwin, orig_fx, orig_fy, orig_fx + orig_fw,
1984 orig_fy + orig_fh, res);
1986 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1989 break;
1991 case ButtonPress:
1992 break;
1994 case ButtonRelease:
1995 if (event.xbutton.button != ev->xbutton.button)
1996 break;
1998 if (started) {
1999 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
2001 drawTransparentFrame(wwin, fx, fy, fw, fh);
2003 XUngrabKeyboard(dpy, CurrentTime);
2004 unmapGeometryDisplay(wwin);
2005 XUngrabServer(dpy);
2007 if (wwin->client.width != fw)
2008 wwin->flags.user_changed_width = 1;
2010 if (wwin->client.height != fh - vert_border)
2011 wwin->flags.user_changed_height = 1;
2013 wWindowConfigure(wwin, fx, fy, fw, fh - vert_border);
2015 #ifdef DEBUG
2016 puts("End resize window");
2017 #endif
2018 return;
2020 default:
2021 WMHandleEvent(&event);
2026 #undef LEFT
2027 #undef RIGHT
2028 #undef HORIZONTAL
2029 #undef UP
2030 #undef DOWN
2031 #undef VERTICAL
2032 #undef HCONSTRAIN
2033 #undef RESIZEBAR
2035 void
2036 wUnselectWindows(WScreen *scr)
2038 WWindow *wwin;
2040 while (scr->selected_windows) {
2041 wwin = scr->selected_windows->head;
2042 if (wwin->flags.miniaturized && wwin->icon && wwin->icon->selected)
2043 wIconSelect(wwin->icon);
2045 wSelectWindow(wwin, False);
2049 #ifndef LITE
2050 static void
2051 selectWindowsInside(WScreen *scr, int x1, int y1, int x2, int y2)
2053 WWindow *tmpw;
2055 /* select the windows and put them in the selected window list */
2056 tmpw = scr->focused_window;
2057 while (tmpw != NULL) {
2058 if (!(tmpw->flags.miniaturized || tmpw->flags.hidden)) {
2059 if ((tmpw->frame->workspace == scr->current_workspace
2060 || IS_OMNIPRESENT(tmpw))
2061 && (tmpw->frame_x >= x1) && (tmpw->frame_y >= y1)
2062 && (tmpw->frame->core->width + tmpw->frame_x <= x2)
2063 && (tmpw->frame->core->height + tmpw->frame_y <= y2)) {
2064 wSelectWindow(tmpw, True);
2067 tmpw = tmpw->prev;
2072 void
2073 wSelectWindows(WScreen *scr, XEvent *ev)
2075 XEvent event;
2076 Window root = scr->root_win;
2077 GC gc = scr->frame_gc;
2078 int xp = ev->xbutton.x_root;
2079 int yp = ev->xbutton.y_root;
2080 int w = 0, h = 0;
2081 int x = xp, y = yp;
2083 #ifdef DEBUG
2084 puts("Selecting windows");
2085 #endif
2086 if (XGrabPointer(dpy, scr->root_win, False, ButtonMotionMask
2087 | ButtonReleaseMask | ButtonPressMask, GrabModeAsync,
2088 GrabModeAsync, None, wCursor[WCUR_DEFAULT],
2089 CurrentTime) != Success) {
2090 return;
2092 XGrabServer(dpy);
2094 wUnselectWindows(scr);
2096 XDrawRectangle(dpy, root, gc, xp, yp, w, h);
2097 while (1) {
2098 WMMaskEvent(dpy, ButtonReleaseMask | PointerMotionMask
2099 | ButtonPressMask, &event);
2101 switch (event.type) {
2102 case MotionNotify:
2103 XDrawRectangle(dpy, root, gc, x, y, w, h);
2104 x = event.xmotion.x_root;
2105 if (x < xp) {
2106 w = xp - x;
2107 } else {
2108 w = x - xp;
2109 x = xp;
2111 y = event.xmotion.y_root;
2112 if (y < yp) {
2113 h = yp - y;
2114 } else {
2115 h = y - yp;
2116 y = yp;
2118 XDrawRectangle(dpy, root, gc, x, y, w, h);
2119 break;
2121 case ButtonPress:
2122 break;
2124 case ButtonRelease:
2125 if (event.xbutton.button != ev->xbutton.button)
2126 break;
2128 XDrawRectangle(dpy, root, gc, x, y, w, h);
2129 XUngrabServer(dpy);
2130 XUngrabPointer(dpy, CurrentTime);
2131 selectWindowsInside(scr, x, y, x + w, y + h);
2133 #ifdef KWM_HINTS
2134 wKWMSelectRootRegion(scr, x, y, w, h,
2135 event.xbutton.state & ControlMask);
2136 #endif /* KWM_HINTS */
2138 #ifdef DEBUG
2139 puts("End window selection");
2140 #endif
2141 return;
2143 default:
2144 WMHandleEvent(&event);
2145 break;
2149 #endif /* !LITE */
2151 void
2152 InteractivePlaceWindow(WWindow *wwin, int *x_ret, int *y_ret,
2153 unsigned width, unsigned height)
2155 WScreen *scr = wwin->screen_ptr;
2156 Window root = scr->root_win;
2157 int x, y, h = 0;
2158 XEvent event;
2159 KeyCode shiftl, shiftr;
2160 Window junkw;
2161 int junk;
2163 if (XGrabPointer(dpy, root, True, PointerMotionMask | ButtonPressMask,
2164 GrabModeAsync, GrabModeAsync, None,
2165 wCursor[WCUR_DEFAULT], CurrentTime) != Success) {
2166 *x_ret = 0;
2167 *y_ret = 0;
2168 return;
2170 if (!WFLAGP(wwin, no_titlebar)) {
2171 h = WMFontHeight(scr->title_font) + TITLEBAR_EXTRA_HEIGHT;
2172 height += h;
2174 if (!WFLAGP(wwin, no_resizebar)) {
2175 height += RESIZEBAR_HEIGHT;
2177 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync, CurrentTime);
2178 XQueryPointer(dpy, root, &junkw, &junkw, &x, &y, &junk, &junk,
2179 (unsigned *) &junk);
2180 mapPositionDisplay(wwin, x - width/2, y - h/2, width, height);
2182 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2184 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
2185 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
2186 while (1) {
2187 WMMaskEvent(dpy, PointerMotionMask|ButtonPressMask|ExposureMask|KeyPressMask,
2188 &event);
2189 switch (event.type) {
2190 case KeyPress:
2191 if ((event.xkey.keycode == shiftl)
2192 || (event.xkey.keycode == shiftr)) {
2193 drawTransparentFrame(wwin,
2194 x - width/2, y - h/2, width, height);
2195 cyclePositionDisplay(wwin,
2196 x - width/2, y - h/2, width, height);
2197 drawTransparentFrame(wwin,
2198 x - width/2, y - h/2, width, height);
2200 break;
2202 case MotionNotify:
2203 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2205 x = event.xmotion.x_root;
2206 y = event.xmotion.y_root;
2208 if (wPreferences.move_display == WDIS_FRAME_CENTER)
2209 moveGeometryDisplayCentered(scr, x, y + (height - h) / 2);
2211 showPosition(wwin, x - width/2, y - h/2);
2213 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2215 break;
2217 case ButtonPress:
2218 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2219 XSync(dpy, 0);
2220 *x_ret = x - width/2;
2221 *y_ret = y - h/2;
2222 XUngrabPointer(dpy, CurrentTime);
2223 XUngrabKeyboard(dpy, CurrentTime);
2224 /* get rid of the geometry window */
2225 unmapPositionDisplay(wwin);
2226 return;
2228 default:
2229 WMHandleEvent(&event);
2230 break;