Edge attraction.
[wmaker-crm.git] / src / moveres.c
blob63f483ed78e9fe9107ea08ce741a99de8b9ec593
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 data->topList[data->count] = tmp;
753 data->leftList[data->count] = tmp;
754 data->rightList[data->count] = tmp;
755 data->bottomList[data->count] = tmp;
756 data->count++;
758 tmp = tmp->prev;
761 if (data->count == 0) {
762 data->topIndex = 0;
763 data->leftIndex = 0;
764 data->rightIndex = 0;
765 data->bottomIndex = 0;
766 return;
770 * order from closest to the border of the screen to farthest
772 qsort(data->topList, data->count, sizeof(WWindow**), compareWTop);
773 qsort(data->leftList, data->count, sizeof(WWindow**), compareWLeft);
774 qsort(data->rightList, data->count, sizeof(WWindow**), compareWRight);
775 qsort(data->bottomList, data->count, sizeof(WWindow**), compareWBottom);
777 /* figure the position of the window relative to the others */
779 data->topIndex = -1;
780 data->leftIndex = -1;
781 data->rightIndex = -1;
782 data->bottomIndex = -1;
784 if (WTOP(wwin) < WBOTTOM(data->bottomList[0])) {
785 data->bottomIndex = 0;
787 if (WLEFT(wwin) < WRIGHT(data->rightList[0])) {
788 data->rightIndex = 0;
790 if (WRIGHT(wwin) > WLEFT(data->leftList[0])) {
791 data->leftIndex = 0;
793 if (WBOTTOM(wwin) > WTOP(data->topList[0])) {
794 data->topIndex = 0;
796 for (i = 0; i < data->count; i++) {
797 if (WTOP(wwin) >= WBOTTOM(data->bottomList[i])) {
798 data->bottomIndex = i + 1;
800 if (WLEFT(wwin) >= WRIGHT(data->rightList[i])) {
801 data->rightIndex = i + 1;
803 if (WRIGHT(wwin) <= WLEFT(data->leftList[i])) {
804 data->leftIndex = i + 1;
806 if (WBOTTOM(wwin) <= WTOP(data->topList[i])) {
807 data->topIndex = i + 1;
813 static void
814 initMoveData(WWindow *wwin, MoveData *data)
816 int i;
817 WWindow *tmp;
819 memset(data, 0, sizeof(MoveData));
821 for (i = 0, tmp = wwin->screen_ptr->focused_window;
822 tmp != NULL;
823 tmp = tmp->prev, i++);
825 if (i > 1) {
826 data->topList = wmalloc(sizeof(WWindow*) * i);
827 data->leftList = wmalloc(sizeof(WWindow*) * i);
828 data->rightList = wmalloc(sizeof(WWindow*) * i);
829 data->bottomList = wmalloc(sizeof(WWindow*) * i);
831 updateMoveData(wwin, data);
834 data->realX = wwin->frame_x;
835 data->realY = wwin->frame_y;
836 data->calcX = wwin->frame_x;
837 data->calcY = wwin->frame_y;
839 data->winWidth = wwin->frame->core->width + 2;
840 data->winHeight = wwin->frame->core->height + 2;
844 static Bool
845 checkWorkspaceChange(WWindow *wwin, MoveData *data, Bool opaqueMove)
847 WScreen *scr = wwin->screen_ptr;
848 Bool changed = False;
850 if (data->mouseX <= 1) {
851 if (scr->current_workspace > 0) {
853 crossWorkspace(scr, wwin, opaqueMove, scr->current_workspace - 1,
854 True);
855 changed = True;
856 data->rubCount = 0;
858 } else if (scr->current_workspace == 0 && wPreferences.ws_cycle) {
860 crossWorkspace(scr, wwin, opaqueMove, scr->workspace_count - 1,
861 True);
862 changed = True;
863 data->rubCount = 0;
865 } else if (data->mouseX >= scr->scr_width - 2) {
867 if (scr->current_workspace == scr->workspace_count - 1) {
869 if (wPreferences.ws_cycle
870 || scr->workspace_count == MAX_WORKSPACES) {
872 crossWorkspace(scr, wwin, opaqueMove, 0, False);
873 changed = True;
874 data->rubCount = 0;
876 /* if user insists on trying to go to next workspace even when
877 * it's already the last, create a new one */
878 else if (data->omouseX == data->mouseX
879 && wPreferences.ws_advance) {
881 /* detect user "rubbing" the window against the edge */
882 if (data->rubCount > 0
883 && data->omouseY - data->mouseY > MOVE_THRESHOLD) {
885 data->rubCount = -(data->rubCount + 1);
887 } else if (data->rubCount <= 0
888 && data->mouseY - data->omouseY > MOVE_THRESHOLD) {
890 data->rubCount = -data->rubCount + 1;
893 /* create a new workspace */
894 if (abs(data->rubCount) > 2) {
895 /* go to next workspace */
896 wWorkspaceNew(scr);
898 crossWorkspace(scr, wwin, opaqueMove,
899 scr->current_workspace+1, False);
900 changed = True;
901 data->rubCount = 0;
903 } else if (scr->current_workspace < scr->workspace_count) {
905 /* go to next workspace */
906 crossWorkspace(scr, wwin, opaqueMove,
907 scr->current_workspace+1, False);
908 changed = True;
909 data->rubCount = 0;
911 } else {
912 data->rubCount = 0;
915 return changed;
919 static void
920 updateWindowPosition(WWindow *wwin, MoveData *data, Bool doResistance,
921 Bool opaqueMove, int newMouseX, int newMouseY)
923 WScreen *scr = wwin->screen_ptr;
924 int dx, dy; /* how much mouse moved */
925 int winL, winR, winT, winB; /* requested new window position */
926 int newX, newY; /* actual new window position */
927 Bool hresist, vresist;
928 Bool updateIndex;
929 Bool attract;
931 hresist = False;
932 vresist = False;
934 updateIndex = False;
936 /* check the direction of the movement */
937 dx = newMouseX - data->mouseX;
938 dy = newMouseY - data->mouseY;
940 data->omouseX = data->mouseX;
941 data->omouseY = data->mouseY;
942 data->mouseX = newMouseX;
943 data->mouseY = newMouseY;
945 winL = data->calcX + dx;
946 winR = data->calcX + data->winWidth + dx;
947 winT = data->calcY + dy;
948 winB = data->calcY + data->winHeight + dy;
950 newX = data->realX;
951 newY = data->realY;
953 if (doResistance) {
954 int l_edge, r_edge;
955 int edge_l, edge_r;
956 int t_edge, b_edge;
957 int edge_t, edge_b;
958 int resist;
959 WWindow *rwin;
960 WWindow *rrwin;
962 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
963 attract = wPreferences.attract;
964 /* horizontal movement: check horizontal edge resistances */
965 if (dx || dy) {
966 int i;
967 /* window is the leftmost window: check against screen edge */
968 l_edge = scr->totalUsableArea.x1;
969 r_edge = scr->totalUsableArea.x2 + resist;
970 edge_l = scr->totalUsableArea.x1 - resist;
971 edge_r = scr->totalUsableArea.x2;
973 /* 1 */
974 if ((data->rightIndex >= 0) && (data->rightIndex <= data->count)) {
975 WWindow *looprw;
977 for (i = data->rightIndex - 1; i >= 0; i--) {
978 looprw = data->rightList[i];
979 if (!(data->realY > WBOTTOM(looprw)
980 || (data->realY + data->winHeight) < WTOP(looprw))) {
981 if (attract || (data->realX < (WRIGHT(looprw) + 2)) && dx < 0) {
982 l_edge = WRIGHT(looprw) + 1;
983 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
985 break;
989 if (attract) {
990 for (i = data->rightIndex; i < data->count; i++) {
991 looprw = data->rightList[i];
992 if(!(data->realY > WBOTTOM(looprw)
993 || (data->realY + data->winHeight) < WTOP(looprw))) {
994 r_edge = WRIGHT(looprw) + 1;
995 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
996 break;
1002 if ((data->leftIndex >= 0) && (data->leftIndex <= data->count)) {
1003 WWindow *looprw;
1005 for (i = data->leftIndex - 1; i >= 0; i--) {
1006 looprw = data->leftList[i];
1007 if (!(data->realY > WBOTTOM(looprw)
1008 || (data->realY + data->winHeight) < WTOP(looprw))) {
1009 if (attract || ((data->realX + data->winWidth) > (WLEFT(looprw) - 1)) && dx > 0) {
1010 edge_r = WLEFT(looprw);
1011 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1013 break;
1017 if (attract)
1018 for (i = data->leftIndex; i < data->count; i++) {
1019 looprw = data->leftList[i];
1020 if(!(data->realY > WBOTTOM(looprw)
1021 || (data->realY + data->winHeight) < WTOP(looprw))) {
1022 edge_l = WLEFT(looprw);
1023 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1024 break;
1030 printf("%d %d\n",winL,winR);
1031 printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);
1034 if ((winL - l_edge) < (r_edge - winL)) {
1035 if (resist > 0) {
1036 if ((attract && winL <= l_edge + resist && winL >= l_edge - resist)
1037 || (dx < 0 && winL <= l_edge && winL >= l_edge - resist)) {
1038 newX = l_edge;
1039 hresist = True;
1043 else {
1044 if (resist > 0 && attract && winL >= r_edge - resist && winL <= r_edge + resist) {
1045 newX = r_edge;
1046 hresist = True;
1050 if ((winR - edge_l) < (edge_r - winR)) {
1051 if (resist > 0 && attract && winR <= edge_l + resist && winR >= edge_l - resist) {
1052 newX = edge_l - data->winWidth;
1053 hresist = True;
1056 else {
1057 if (resist > 0) {
1058 if ((attract && winR >= edge_r - resist && winR <= edge_r + resist)
1059 || (dx > 0 && winR >= edge_r && winR <= edge_r + resist)) {
1060 newX = edge_r - data->winWidth;
1061 hresist = True;
1066 /* VeRT */
1067 t_edge = scr->totalUsableArea.y1;
1068 b_edge = scr->totalUsableArea.y2 + resist;
1069 edge_t = scr->totalUsableArea.y1 - resist;
1070 edge_b = scr->totalUsableArea.y2;
1072 if ((data->bottomIndex >= 0) && (data->bottomIndex <= data->count)) {
1073 WWindow *looprw;
1075 for (i = data->bottomIndex - 1; i >= 0; i--) {
1076 looprw = data->bottomList[i];
1077 if (!(data->realX > WRIGHT(looprw)
1078 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1079 if (attract || (data->realY < (WBOTTOM(looprw) + 2)) && dy < 0) {
1080 t_edge = WBOTTOM(looprw) + 1;
1081 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1083 break;
1087 if (attract) {
1088 for (i = data->bottomIndex; i < data->count; i++) {
1089 looprw = data->bottomList[i];
1090 if(!(data->realX > WRIGHT(looprw)
1091 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1092 b_edge = WBOTTOM(looprw) + 1;
1093 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1094 break;
1100 if ((data->topIndex >= 0) && (data->topIndex <= data->count)) {
1101 WWindow *looprw;
1103 for (i = data->topIndex - 1; i >= 0; i--) {
1104 looprw = data->topList[i];
1105 if (!(data->realX > WRIGHT(looprw)
1106 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1107 if (attract || ((data->realY + data->winHeight) > (WTOP(looprw) - 1)) && dy > 0) {
1108 edge_b = WTOP(looprw);
1109 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1111 break;
1115 if (attract)
1116 for (i = data->topIndex; i < data->count; i++) {
1117 looprw = data->topList[i];
1118 if(!(data->realX > WRIGHT(looprw)
1119 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1120 edge_t = WTOP(looprw);
1121 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1122 break;
1127 if ((winT - t_edge) < (b_edge - winT)) {
1128 if (resist > 0) {
1129 if ((attract && winT <= t_edge + resist && winT >= t_edge - resist)
1130 || (dy < 0 && winT <= t_edge && winT >= t_edge - resist)) {
1131 newY = t_edge;
1132 vresist = True;
1136 else {
1137 if (resist > 0 && attract && winT >= b_edge - resist && winT <= b_edge + resist) {
1138 newY = b_edge;
1139 vresist = True;
1143 if ((winB - edge_t) < (edge_b - winB)) {
1144 if (resist > 0 && attract && winB <= edge_t + resist && winB >= edge_t - resist) {
1145 newY = edge_t - data->winHeight;
1146 vresist = True;
1149 else {
1150 if (resist > 0) {
1151 if ((attract && winB >= edge_b - resist && winB <= edge_b + resist)
1152 || (dy > 0 && winB >= edge_b && winB <= edge_b + resist)) {
1153 newY = edge_b - data->winHeight;
1154 vresist = True;
1159 /* END VeRT */
1163 /* update window position */
1164 data->calcX += dx;
1165 data->calcY += dy;
1167 if (((dx > 0 && data->calcX - data->realX > 0)
1168 || (dx < 0 && data->calcX - data->realX < 0)) && !hresist)
1169 newX = data->calcX;
1171 if (((dy > 0 && data->calcY - data->realY > 0)
1172 || (dy < 0 && data->calcY - data->realY < 0)) && !vresist)
1173 newY = data->calcY;
1175 if (data->realX != newX || data->realY != newY) {
1177 if (wPreferences.move_display == WDIS_NEW
1178 && !scr->selected_windows) {
1179 showPosition(wwin, data->realX, data->realY);
1181 if (opaqueMove) {
1182 doWindowMove(wwin, scr->selected_windows,
1183 newX - wwin->frame_x,
1184 newY - wwin->frame_y);
1185 } else {
1186 /* erase frames */
1187 drawFrames(wwin, scr->selected_windows,
1188 data->realX - wwin->frame_x,
1189 data->realY - wwin->frame_y);
1192 if (!scr->selected_windows
1193 && wPreferences.move_display == WDIS_FRAME_CENTER) {
1195 moveGeometryDisplayCentered(scr, newX + data->winWidth/2,
1196 newY + data->winHeight/2);
1199 if (!opaqueMove) {
1200 /* draw frames */
1201 drawFrames(wwin, scr->selected_windows,
1202 newX - wwin->frame_x,
1203 newY - wwin->frame_y);
1206 if (!scr->selected_windows) {
1207 showPosition(wwin, newX, newY);
1212 /* recalc relative window position */
1213 if (doResistance && (data->realX != newX || data->realY != newY)) {
1214 updateResistance(wwin, data, newX, newY);
1217 data->realX = newX;
1218 data->realY = newY;
1222 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1225 wKeyboardMoveResizeWindow(WWindow *wwin)
1227 WScreen *scr = wwin->screen_ptr;
1228 Window root = scr->root_win;
1229 XEvent event;
1230 int w = wwin->frame->core->width;
1231 int h = wwin->frame->core->height;
1232 int scr_width = wwin->screen_ptr->scr_width;
1233 int scr_height = wwin->screen_ptr->scr_height;
1234 int vert_border = wwin->frame->top_width + wwin->frame->bottom_width;
1235 int src_x = wwin->frame_x;
1236 int src_y = wwin->frame_y;
1237 int done,off_x,off_y,ww,wh;
1238 int kspeed = _KS;
1239 Time lastTime = 0;
1240 KeySym keysym=NoSymbol;
1241 int moment=0;
1242 KeyCode shiftl,shiftr,ctrll,ctrlmode;
1244 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1245 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1246 ctrll = XKeysymToKeycode(dpy, XK_Control_L);
1247 ctrlmode=done=off_x=off_y=0;
1249 XSync(dpy, False);
1250 wusleep(10000);
1251 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync, CurrentTime);
1253 if (!wwin->flags.selected) {
1254 wUnselectWindows(scr);
1256 XGrabServer(dpy);
1257 XGrabPointer(dpy, scr->root_win, True, PointerMotionMask
1258 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
1259 GrabModeAsync, None, wCursor[WCUR_DEFAULT], CurrentTime);
1261 if (wwin->flags.shaded || scr->selected_windows) {
1262 if(scr->selected_windows)
1263 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1264 else drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1265 if(!scr->selected_windows)
1266 mapPositionDisplay(wwin, src_x, src_y, w, h);
1267 } else {
1268 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1270 ww=w;
1271 wh=h;
1272 while(1) {
1274 looper.ox=off_x;
1275 looper.oy=off_y;
1277 WMMaskEvent(dpy, KeyPressMask | ButtonReleaseMask
1278 | ButtonPressMask | ExposureMask, &event);
1279 if (wwin->flags.shaded || scr->selected_windows) {
1280 if(scr->selected_windows)
1281 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1282 else drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1283 /*** I HATE EDGE RESISTANCE - ]d ***/
1285 else {
1286 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, ww, wh);
1289 if(ctrlmode)
1290 showGeometry(wwin, src_x+off_x, src_y+off_y, src_x+off_x+ww, src_y+off_y+wh,0);
1292 XUngrabServer(dpy);
1293 XSync(dpy, False);
1295 switch (event.type) {
1296 case KeyPress:
1297 /* accelerate */
1298 if (event.xkey.time - lastTime > 50) {
1299 kspeed/=(1 + (event.xkey.time - lastTime)/100);
1300 } else {
1301 if (kspeed < 20) {
1302 kspeed++;
1305 if (kspeed < _KS) kspeed = _KS;
1306 lastTime = event.xkey.time;
1308 if (event.xkey.state & ControlMask && !wwin->flags.shaded) {
1309 ctrlmode=1;
1310 wUnselectWindows(scr);
1312 else {
1313 ctrlmode=0;
1315 if (event.xkey.keycode == shiftl || event.xkey.keycode == shiftr) {
1316 if (ctrlmode)
1317 cycleGeometryDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh, 0);
1318 else
1319 cyclePositionDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh);
1321 else {
1323 keysym = XLookupKeysym(&event.xkey, 0);
1324 switch (keysym) {
1325 case XK_Return:
1326 done=2;
1327 break;
1328 case XK_Escape:
1329 done=1;
1330 break;
1331 case XK_Up:
1332 case XK_KP_Up:
1333 case XK_k:
1334 if (ctrlmode){
1335 if (moment != UP)
1336 h = wh;
1337 h-=kspeed;
1338 moment = UP;
1339 if (h < 1) h = 1;
1341 else off_y-=kspeed;
1342 break;
1343 case XK_Down:
1344 case XK_KP_Down:
1345 case XK_j:
1346 if (ctrlmode){
1347 if (moment != DOWN)
1348 h = wh;
1349 h+=kspeed;
1350 moment = DOWN;
1352 else off_y+=kspeed;
1353 break;
1354 case XK_Left:
1355 case XK_KP_Left:
1356 case XK_h:
1357 if (ctrlmode) {
1358 if (moment != LEFT)
1359 w = ww;
1360 w-=kspeed;
1361 if (w < 1) w = 1;
1362 moment = LEFT;
1364 else off_x-=kspeed;
1365 break;
1366 case XK_Right:
1367 case XK_KP_Right:
1368 case XK_l:
1369 if (ctrlmode) {
1370 if (moment != RIGHT)
1371 w = ww;
1372 w+=kspeed;
1373 moment = RIGHT;
1375 else off_x+=kspeed;
1376 break;
1379 ww=w;wh=h;
1380 wh-=vert_border;
1381 wWindowConstrainSize(wwin, &ww, &wh);
1382 wh+=vert_border;
1384 if (wPreferences.ws_cycle){
1385 if (src_x + off_x + ww < 20){
1386 if(!scr->current_workspace) {
1387 wWorkspaceChange(scr, scr->workspace_count-1);
1389 else wWorkspaceChange(scr, scr->current_workspace-1);
1390 off_x += scr_width;
1392 else if (src_x + off_x + 20 > scr_width){
1393 if(scr->current_workspace == scr->workspace_count-1) {
1394 wWorkspaceChange(scr, 0);
1396 else wWorkspaceChange(scr, scr->current_workspace+1);
1397 off_x -= scr_width;
1400 else {
1401 if (src_x + off_x + ww < 20)
1402 off_x = 20 - ww - src_x;
1403 else if (src_x + off_x + 20 > scr_width)
1404 off_x = scr_width - 20 - src_x;
1407 if (src_y + off_y + wh < 20) {
1408 off_y = 20 - wh - src_y;
1410 else if (src_y + off_y + 20 > scr_height) {
1411 off_y = scr_height - 20 - src_y;
1414 break;
1415 case ButtonPress:
1416 case ButtonRelease:
1417 done=1;
1418 break;
1419 default:
1420 WMHandleEvent(&event);
1421 break;
1424 XGrabServer(dpy);
1425 /*xxx*/
1427 if (wwin->flags.shaded && !scr->selected_windows){
1428 moveGeometryDisplayCentered(scr, src_x+off_x + w/2, src_y+off_y + h/2);
1430 else {
1431 if(ctrlmode){
1432 unmapPositionDisplay(wwin);
1433 mapGeometryDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh);
1435 else if(!scr->selected_windows){
1436 unmapGeometryDisplay(wwin);
1437 mapPositionDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh);
1441 if (wwin->flags.shaded || scr->selected_windows) {
1442 if(scr->selected_windows)
1443 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1444 else drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1446 else {
1447 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, ww, wh);
1451 if(ctrlmode){
1452 showGeometry(wwin, src_x+off_x, src_y+off_y, src_x+off_x+ww, src_y+off_y+wh,0);
1454 else if(!scr->selected_windows)
1455 showPosition(wwin, src_x+off_x, src_y+off_y);
1456 /**/
1458 if(done){
1459 scr->keymove_tick=0;
1461 WMDeleteTimerWithClientData(&looper);
1463 if (wwin->flags.shaded || scr->selected_windows) {
1464 if(scr->selected_windows)
1465 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1466 else drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1468 else {
1469 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, ww, wh);
1472 if(ctrlmode){
1473 showGeometry(wwin, src_x+off_x, src_y+off_y, src_x+off_x+ww, src_y+off_y+wh,0);
1474 unmapGeometryDisplay(wwin);
1476 else
1477 unmapPositionDisplay(wwin);
1478 XUngrabKeyboard(dpy, CurrentTime);
1479 XUngrabPointer(dpy, CurrentTime);
1480 XUngrabServer(dpy);
1482 if(done==2) {
1483 if (wwin->flags.shaded || scr->selected_windows) {
1484 LinkedList *list;
1485 list=scr->selected_windows;
1486 if (!scr->selected_windows) {
1487 wWindowMove(wwin, src_x+off_x, src_y+off_y);
1488 wWindowSynthConfigureNotify(wwin);
1489 } else {
1490 doWindowMove(wwin,scr->selected_windows,off_x,off_y);
1491 while (list) {
1492 wWindowSynthConfigureNotify(list->head);
1493 list = list->tail;
1496 } else {
1497 if (wwin->client.width != ww)
1498 wwin->flags.user_changed_width = 1;
1500 if (wwin->client.height != wh - vert_border)
1501 wwin->flags.user_changed_height = 1;
1503 wWindowConfigure(wwin, src_x+off_x, src_y+off_y,
1504 ww, wh - vert_border);
1505 wWindowSynthConfigureNotify(wwin);
1507 wWindowChangeWorkspace(wwin, scr->current_workspace);
1508 wSetFocusTo(scr, wwin);
1510 return 1;
1517 *----------------------------------------------------------------------
1518 * wMouseMoveWindow--
1519 * Move the named window and the other selected ones (if any),
1520 * interactively. Also shows the position of the window, if only one
1521 * window is being moved.
1522 * If the window is not on the selected window list, the selected
1523 * windows are deselected.
1524 * If shift is pressed during the operation, the position display
1525 * is changed to another type.
1527 * Returns:
1528 * True if the window was moved, False otherwise.
1530 * Side effects:
1531 * The window(s) position is changed, and the client(s) are
1532 * notified about that.
1533 * The position display configuration may be changed.
1534 *----------------------------------------------------------------------
1537 wMouseMoveWindow(WWindow *wwin, XEvent *ev)
1539 WScreen *scr = wwin->screen_ptr;
1540 XEvent event;
1541 Window root = scr->root_win;
1542 KeyCode shiftl, shiftr;
1543 Bool done = False;
1544 int started = 0;
1545 int warped = 0;
1546 /* This needs not to change while moving, else bad things can happen */
1547 int opaqueMove = wPreferences.opaque_move;
1548 MoveData moveData;
1549 #ifdef GHOST_WINDOW_MOVE
1550 RImage *rimg;
1552 rimg = InitGhostWindowMove(scr);
1553 #endif
1556 if (wPreferences.opaque_move && !wPreferences.use_saveunders) {
1557 XSetWindowAttributes attr;
1559 attr.save_under = True;
1560 XChangeWindowAttributes(dpy, wwin->frame->core->window,
1561 CWSaveUnder, &attr);
1565 initMoveData(wwin, &moveData);
1567 moveData.mouseX = ev->xmotion.x_root;
1568 moveData.mouseY = ev->xmotion.y_root;
1570 if (!wwin->flags.selected) {
1571 /* this window is not selected, unselect others and move only wwin */
1572 wUnselectWindows(scr);
1574 #ifdef DEBUG
1575 puts("Moving window");
1576 #endif
1577 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1578 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1579 while (!done) {
1580 if (warped) {
1581 int junk;
1582 Window junkw;
1584 /* XWarpPointer() doesn't seem to generate Motion events, so
1585 we've got to simulate them */
1586 XQueryPointer(dpy, root, &junkw, &junkw, &event.xmotion.x_root,
1587 &event.xmotion.y_root, &junk, &junk,
1588 (unsigned *) &junk);
1589 } else {
1590 WMMaskEvent(dpy, KeyPressMask | ButtonMotionMask
1591 | ButtonReleaseMask | ButtonPressMask | ExposureMask,
1592 &event);
1594 if (event.type == MotionNotify) {
1595 /* compress MotionNotify events */
1596 while (XCheckMaskEvent(dpy, ButtonMotionMask, &event)) ;
1599 switch (event.type) {
1600 case KeyPress:
1601 if ((event.xkey.keycode == shiftl || event.xkey.keycode == shiftr)
1602 && started && !scr->selected_windows) {
1604 if (!opaqueMove) {
1605 drawFrames(wwin, scr->selected_windows,
1606 moveData.realX - wwin->frame_x,
1607 moveData.realY - wwin->frame_y);
1610 if (wPreferences.move_display == WDIS_NEW
1611 && !scr->selected_windows) {
1612 showPosition(wwin, moveData.realX, moveData.realY);
1613 XUngrabServer(dpy);
1615 cyclePositionDisplay(wwin, moveData.realX, moveData.realY,
1616 moveData.winWidth, moveData.winHeight);
1618 if (wPreferences.move_display == WDIS_NEW
1619 && !scr->selected_windows) {
1620 XGrabServer(dpy);
1621 showPosition(wwin, moveData.realX, moveData.realY);
1624 if (!opaqueMove) {
1625 drawFrames(wwin, scr->selected_windows,
1626 moveData.realX - wwin->frame_x,
1627 moveData.realY - wwin->frame_y);
1630 break;
1632 case MotionNotify:
1633 if (started) {
1634 updateWindowPosition(wwin, &moveData,
1635 scr->selected_windows == NULL
1636 && wPreferences.edge_resistance > 0,
1637 opaqueMove,
1638 event.xmotion.x_root,
1639 event.xmotion.y_root);
1641 if (!warped && !wPreferences.no_autowrap) {
1642 int oldWorkspace = scr->current_workspace;
1644 if (wPreferences.move_display == WDIS_NEW
1645 && !scr->selected_windows) {
1646 showPosition(wwin, moveData.realX, moveData.realY);
1647 XUngrabServer(dpy);
1649 if (!opaqueMove) {
1650 drawFrames(wwin, scr->selected_windows,
1651 moveData.realX - wwin->frame_x,
1652 moveData.realY - wwin->frame_y);
1654 if (checkWorkspaceChange(wwin, &moveData, opaqueMove)) {
1655 if (scr->current_workspace != oldWorkspace
1656 && wPreferences.edge_resistance > 0
1657 && scr->selected_windows == NULL)
1658 updateMoveData(wwin, &moveData);
1659 warped = 1;
1661 if (!opaqueMove) {
1662 drawFrames(wwin, scr->selected_windows,
1663 moveData.realX - wwin->frame_x,
1664 moveData.realY - wwin->frame_y);
1666 if (wPreferences.move_display == WDIS_NEW
1667 && !scr->selected_windows) {
1668 XSync(dpy, False);
1669 showPosition(wwin, moveData.realX, moveData.realY);
1670 XGrabServer(dpy);
1672 } else {
1673 warped = 0;
1675 } else if (abs(ev->xmotion.x_root - event.xmotion.x_root) >= MOVE_THRESHOLD
1676 || abs(ev->xmotion.y_root - event.xmotion.y_root) >= MOVE_THRESHOLD) {
1678 XChangeActivePointerGrab(dpy, ButtonMotionMask
1679 | ButtonReleaseMask | ButtonPressMask,
1680 wCursor[WCUR_MOVE], CurrentTime);
1681 started = 1;
1682 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync,
1683 CurrentTime);
1685 if (!scr->selected_windows)
1686 mapPositionDisplay(wwin, moveData.realX, moveData.realY,
1687 moveData.winWidth, moveData.winHeight);
1689 if (started && !opaqueMove)
1690 drawFrames(wwin, scr->selected_windows, 0, 0);
1692 if (!opaqueMove || (wPreferences.move_display==WDIS_NEW
1693 && !scr->selected_windows)) {
1694 XGrabServer(dpy);
1695 if (wPreferences.move_display==WDIS_NEW)
1696 showPosition(wwin, moveData.realX, moveData.realY);
1699 break;
1701 case ButtonPress:
1702 break;
1704 case ButtonRelease:
1705 if (event.xbutton.button != ev->xbutton.button)
1706 break;
1708 if (started) {
1709 if (!opaqueMove) {
1710 drawFrames(wwin, scr->selected_windows,
1711 moveData.realX - wwin->frame_x,
1712 moveData.realY - wwin->frame_y);
1713 XSync(dpy, 0);
1714 doWindowMove(wwin, scr->selected_windows,
1715 moveData.realX - wwin->frame_x,
1716 moveData.realY - wwin->frame_y);
1718 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1719 wWindowSynthConfigureNotify(wwin);
1720 #endif
1721 XUngrabKeyboard(dpy, CurrentTime);
1722 XUngrabServer(dpy);
1723 if (!opaqueMove) {
1724 wWindowChangeWorkspace(wwin, scr->current_workspace);
1725 wSetFocusTo(scr, wwin);
1727 if (wPreferences.move_display == WDIS_NEW)
1728 showPosition(wwin, moveData.realX, moveData.realY);
1730 if (!scr->selected_windows) {
1731 /* get rid of the geometry window */
1732 unmapPositionDisplay(wwin);
1735 #ifdef DEBUG
1736 puts("End move window");
1737 #endif
1738 done = True;
1739 break;
1741 default:
1742 if (started && !opaqueMove) {
1743 drawFrames(wwin, scr->selected_windows,
1744 moveData.realX - wwin->frame_x,
1745 moveData.realY - wwin->frame_y);
1746 XUngrabServer(dpy);
1747 WMHandleEvent(&event);
1748 XSync(dpy, False);
1749 XGrabServer(dpy);
1750 drawFrames(wwin, scr->selected_windows,
1751 moveData.realX - wwin->frame_x,
1752 moveData.realY - wwin->frame_y);
1753 } else {
1754 WMHandleEvent(&event);
1756 break;
1760 if (wPreferences.opaque_move && !wPreferences.use_saveunders) {
1761 XSetWindowAttributes attr;
1764 attr.save_under = False;
1765 XChangeWindowAttributes(dpy, wwin->frame->core->window,
1766 CWSaveUnder, &attr);
1770 freeMoveData(&moveData);
1772 return started;
1776 #define RESIZEBAR 1
1777 #define HCONSTRAIN 2
1779 static int
1780 getResizeDirection(WWindow *wwin, int x, int y, int dx, int dy,
1781 int flags)
1783 int w = wwin->frame->core->width - 1;
1784 int cw = wwin->frame->resizebar_corner_width;
1785 int dir;
1787 /* if not resizing through the resizebar */
1788 if (!(flags & RESIZEBAR)) {
1789 int xdir = (abs(x) < (wwin->client.width/2)) ? LEFT : RIGHT;
1790 int ydir = (abs(y) < (wwin->client.height/2)) ? UP : DOWN;
1791 if (abs(dx) < 2 || abs(dy) < 2) {
1792 if (abs(dy) > abs(dx))
1793 xdir = 0;
1794 else
1795 ydir = 0;
1797 return (xdir | ydir);
1800 /* window is too narrow. allow diagonal resize */
1801 if (cw * 2 >= w) {
1802 int ydir;
1804 if (flags & HCONSTRAIN)
1805 ydir = 0;
1806 else
1807 ydir = DOWN;
1808 if (x < cw)
1809 return (LEFT | ydir);
1810 else
1811 return (RIGHT | ydir);
1813 /* vertical resize */
1814 if ((x > cw) && (x < w - cw))
1815 return DOWN;
1817 if (x < cw)
1818 dir = LEFT;
1819 else
1820 dir = RIGHT;
1822 if ((abs(dy) > 0) && !(flags & HCONSTRAIN))
1823 dir |= DOWN;
1825 return dir;
1829 void
1830 wMouseResizeWindow(WWindow *wwin, XEvent *ev)
1832 XEvent event;
1833 WScreen *scr = wwin->screen_ptr;
1834 Window root = scr->root_win;
1835 int vert_border = wwin->frame->top_width + wwin->frame->bottom_width;
1836 int fw = wwin->frame->core->width;
1837 int fh = wwin->frame->core->height;
1838 int fx = wwin->frame_x;
1839 int fy = wwin->frame_y;
1840 int is_resizebar = (wwin->frame->resizebar
1841 && ev->xany.window==wwin->frame->resizebar->window);
1842 int orig_x, orig_y;
1843 int started;
1844 int dw, dh;
1845 int rw = fw, rh = fh;
1846 int rx1, ry1, rx2, ry2;
1847 int res = 0;
1848 KeyCode shiftl, shiftr;
1849 int h = 0;
1850 int orig_fx = fx;
1851 int orig_fy = fy;
1852 int orig_fw = fw;
1853 int orig_fh = fh;
1855 if (wwin->flags.shaded) {
1856 wwarning("internal error: tryein");
1857 return;
1859 orig_x = ev->xbutton.x_root;
1860 orig_y = ev->xbutton.y_root;
1862 started = 0;
1863 #ifdef DEBUG
1864 puts("Resizing window");
1865 #endif
1867 wUnselectWindows(scr);
1868 rx1 = fx;
1869 rx2 = fx + fw - 1;
1870 ry1 = fy;
1871 ry2 = fy + fh - 1;
1872 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1873 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1874 if (!WFLAGP(wwin, no_titlebar))
1875 h = WMFontHeight(wwin->screen_ptr->title_font) + TITLEBAR_EXTRA_HEIGHT;
1876 else
1877 h = 0;
1878 while (1) {
1879 WMMaskEvent(dpy, KeyPressMask | ButtonMotionMask | ButtonReleaseMask
1880 | ButtonPressMask | ExposureMask, &event);
1881 switch (event.type) {
1882 case KeyPress:
1883 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1884 if ((event.xkey.keycode == shiftl || event.xkey.keycode == shiftr)
1885 && started) {
1886 drawTransparentFrame(wwin, fx, fy, fw, fh);
1887 cycleGeometryDisplay(wwin, fx, fy, fw, fh, res);
1888 drawTransparentFrame(wwin, fx, fy, fw, fh);
1890 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1891 break;
1893 case MotionNotify:
1894 if (started) {
1895 dw = 0;
1896 dh = 0;
1898 orig_fx = fx;
1899 orig_fy = fy;
1900 orig_fw = fw;
1901 orig_fh = fh;
1903 if (res & LEFT)
1904 dw = orig_x - event.xmotion.x_root;
1905 else if (res & RIGHT)
1906 dw = event.xmotion.x_root - orig_x;
1907 if (res & UP)
1908 dh = orig_y - event.xmotion.y_root;
1909 else if (res & DOWN)
1910 dh = event.xmotion.y_root - orig_y;
1912 orig_x = event.xmotion.x_root;
1913 orig_y = event.xmotion.y_root;
1915 rw += dw;
1916 rh += dh;
1917 fw = rw;
1918 fh = rh - vert_border;
1919 wWindowConstrainSize(wwin, &fw, &fh);
1920 fh += vert_border;
1921 if (res & LEFT)
1922 fx = rx2 - fw + 1;
1923 else if (res & RIGHT)
1924 fx = rx1;
1925 if (res & UP)
1926 fy = ry2 - fh + 1;
1927 else if (res & DOWN)
1928 fy = ry1;
1929 } else if (abs(orig_x - event.xmotion.x_root) >= MOVE_THRESHOLD
1930 || abs(orig_y - event.xmotion.y_root) >= MOVE_THRESHOLD) {
1931 int tx, ty;
1932 Window junkw;
1933 int flags;
1935 XTranslateCoordinates(dpy, root, wwin->frame->core->window,
1936 orig_x, orig_y, &tx, &ty, &junkw);
1938 /* check if resizing through resizebar */
1939 if (is_resizebar)
1940 flags = RESIZEBAR;
1941 else
1942 flags = 0;
1944 if (is_resizebar && ((ev->xbutton.state & ShiftMask)
1945 || abs(orig_y - event.xmotion.y_root) < HRESIZE_THRESHOLD))
1946 flags |= HCONSTRAIN;
1948 res = getResizeDirection(wwin, tx, ty,
1949 orig_x - event.xmotion.x_root,
1950 orig_y - event.xmotion.y_root, flags);
1952 XChangeActivePointerGrab(dpy, ButtonMotionMask
1953 | ButtonReleaseMask | ButtonPressMask,
1954 wCursor[WCUR_RESIZE], CurrentTime);
1955 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync,
1956 CurrentTime);
1958 XGrabServer(dpy);
1960 /* Draw the resize frame for the first time. */
1961 mapGeometryDisplay(wwin, fx, fy, fw, fh);
1963 drawTransparentFrame(wwin, fx, fy, fw, fh);
1965 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1967 started = 1;
1969 if (started) {
1970 if (wPreferences.size_display == WDIS_FRAME_CENTER) {
1971 drawTransparentFrame(wwin, orig_fx, orig_fy,
1972 orig_fw, orig_fh);
1973 moveGeometryDisplayCentered(scr, fx + fw / 2, fy + fh / 2);
1974 drawTransparentFrame(wwin, fx, fy, fw, fh);
1975 } else {
1976 drawTransparentFrame(wwin, orig_fx, orig_fy,
1977 orig_fw, orig_fh);
1978 drawTransparentFrame(wwin, fx, fy, fw, fh);
1980 if (fh != orig_fh || fw != orig_fw) {
1981 if (wPreferences.size_display == WDIS_NEW) {
1982 showGeometry(wwin, orig_fx, orig_fy, orig_fx + orig_fw,
1983 orig_fy + orig_fh, res);
1985 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1988 break;
1990 case ButtonPress:
1991 break;
1993 case ButtonRelease:
1994 if (event.xbutton.button != ev->xbutton.button)
1995 break;
1997 if (started) {
1998 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
2000 drawTransparentFrame(wwin, fx, fy, fw, fh);
2002 XUngrabKeyboard(dpy, CurrentTime);
2003 unmapGeometryDisplay(wwin);
2004 XUngrabServer(dpy);
2006 if (wwin->client.width != fw)
2007 wwin->flags.user_changed_width = 1;
2009 if (wwin->client.height != fh - vert_border)
2010 wwin->flags.user_changed_height = 1;
2012 wWindowConfigure(wwin, fx, fy, fw, fh - vert_border);
2014 #ifdef DEBUG
2015 puts("End resize window");
2016 #endif
2017 return;
2019 default:
2020 WMHandleEvent(&event);
2025 #undef LEFT
2026 #undef RIGHT
2027 #undef HORIZONTAL
2028 #undef UP
2029 #undef DOWN
2030 #undef VERTICAL
2031 #undef HCONSTRAIN
2032 #undef RESIZEBAR
2034 void
2035 wUnselectWindows(WScreen *scr)
2037 WWindow *wwin;
2039 while (scr->selected_windows) {
2040 wwin = scr->selected_windows->head;
2041 if (wwin->flags.miniaturized && wwin->icon && wwin->icon->selected)
2042 wIconSelect(wwin->icon);
2044 wSelectWindow(wwin, False);
2048 #ifndef LITE
2049 static void
2050 selectWindowsInside(WScreen *scr, int x1, int y1, int x2, int y2)
2052 WWindow *tmpw;
2054 /* select the windows and put them in the selected window list */
2055 tmpw = scr->focused_window;
2056 while (tmpw != NULL) {
2057 if (!(tmpw->flags.miniaturized || tmpw->flags.hidden)) {
2058 if ((tmpw->frame->workspace == scr->current_workspace
2059 || IS_OMNIPRESENT(tmpw))
2060 && (tmpw->frame_x >= x1) && (tmpw->frame_y >= y1)
2061 && (tmpw->frame->core->width + tmpw->frame_x <= x2)
2062 && (tmpw->frame->core->height + tmpw->frame_y <= y2)) {
2063 wSelectWindow(tmpw, True);
2066 tmpw = tmpw->prev;
2071 void
2072 wSelectWindows(WScreen *scr, XEvent *ev)
2074 XEvent event;
2075 Window root = scr->root_win;
2076 GC gc = scr->frame_gc;
2077 int xp = ev->xbutton.x_root;
2078 int yp = ev->xbutton.y_root;
2079 int w = 0, h = 0;
2080 int x = xp, y = yp;
2082 #ifdef DEBUG
2083 puts("Selecting windows");
2084 #endif
2085 if (XGrabPointer(dpy, scr->root_win, False, ButtonMotionMask
2086 | ButtonReleaseMask | ButtonPressMask, GrabModeAsync,
2087 GrabModeAsync, None, wCursor[WCUR_DEFAULT],
2088 CurrentTime) != Success) {
2089 return;
2091 XGrabServer(dpy);
2093 wUnselectWindows(scr);
2095 XDrawRectangle(dpy, root, gc, xp, yp, w, h);
2096 while (1) {
2097 WMMaskEvent(dpy, ButtonReleaseMask | PointerMotionMask
2098 | ButtonPressMask, &event);
2100 switch (event.type) {
2101 case MotionNotify:
2102 XDrawRectangle(dpy, root, gc, x, y, w, h);
2103 x = event.xmotion.x_root;
2104 if (x < xp) {
2105 w = xp - x;
2106 } else {
2107 w = x - xp;
2108 x = xp;
2110 y = event.xmotion.y_root;
2111 if (y < yp) {
2112 h = yp - y;
2113 } else {
2114 h = y - yp;
2115 y = yp;
2117 XDrawRectangle(dpy, root, gc, x, y, w, h);
2118 break;
2120 case ButtonPress:
2121 break;
2123 case ButtonRelease:
2124 if (event.xbutton.button != ev->xbutton.button)
2125 break;
2127 XDrawRectangle(dpy, root, gc, x, y, w, h);
2128 XUngrabServer(dpy);
2129 XUngrabPointer(dpy, CurrentTime);
2130 selectWindowsInside(scr, x, y, x + w, y + h);
2132 #ifdef KWM_HINTS
2133 wKWMSelectRootRegion(scr, x, y, w, h,
2134 event.xbutton.state & ControlMask);
2135 #endif /* KWM_HINTS */
2137 #ifdef DEBUG
2138 puts("End window selection");
2139 #endif
2140 return;
2142 default:
2143 WMHandleEvent(&event);
2144 break;
2148 #endif /* !LITE */
2150 void
2151 InteractivePlaceWindow(WWindow *wwin, int *x_ret, int *y_ret,
2152 unsigned width, unsigned height)
2154 WScreen *scr = wwin->screen_ptr;
2155 Window root = scr->root_win;
2156 int x, y, h = 0;
2157 XEvent event;
2158 KeyCode shiftl, shiftr;
2159 Window junkw;
2160 int junk;
2162 if (XGrabPointer(dpy, root, True, PointerMotionMask | ButtonPressMask,
2163 GrabModeAsync, GrabModeAsync, None,
2164 wCursor[WCUR_DEFAULT], CurrentTime) != Success) {
2165 *x_ret = 0;
2166 *y_ret = 0;
2167 return;
2169 if (!WFLAGP(wwin, no_titlebar)) {
2170 h = WMFontHeight(scr->title_font) + TITLEBAR_EXTRA_HEIGHT;
2171 height += h;
2173 if (!WFLAGP(wwin, no_resizebar)) {
2174 height += RESIZEBAR_HEIGHT;
2176 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync, CurrentTime);
2177 XQueryPointer(dpy, root, &junkw, &junkw, &x, &y, &junk, &junk,
2178 (unsigned *) &junk);
2179 mapPositionDisplay(wwin, x - width/2, y - h/2, width, height);
2181 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2183 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
2184 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
2185 while (1) {
2186 WMMaskEvent(dpy, PointerMotionMask|ButtonPressMask|ExposureMask|KeyPressMask,
2187 &event);
2188 switch (event.type) {
2189 case KeyPress:
2190 if ((event.xkey.keycode == shiftl)
2191 || (event.xkey.keycode == shiftr)) {
2192 drawTransparentFrame(wwin,
2193 x - width/2, y - h/2, width, height);
2194 cyclePositionDisplay(wwin,
2195 x - width/2, y - h/2, width, height);
2196 drawTransparentFrame(wwin,
2197 x - width/2, y - h/2, width, height);
2199 break;
2201 case MotionNotify:
2202 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2204 x = event.xmotion.x_root;
2205 y = event.xmotion.y_root;
2207 if (wPreferences.move_display == WDIS_FRAME_CENTER)
2208 moveGeometryDisplayCentered(scr, x, y + (height - h) / 2);
2210 showPosition(wwin, x - width/2, y - h/2);
2212 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2214 break;
2216 case ButtonPress:
2217 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2218 XSync(dpy, 0);
2219 *x_ret = x - width/2;
2220 *y_ret = y - h/2;
2221 XUngrabPointer(dpy, CurrentTime);
2222 XUngrabKeyboard(dpy, CurrentTime);
2223 /* get rid of the geometry window */
2224 unmapPositionDisplay(wwin);
2225 return;
2227 default:
2228 WMHandleEvent(&event);
2229 break;