fixed many bugs, removed linked list
[wmaker-crm.git] / src / moveres.c
blob26b9baf2b5a0f80cf8815ca4aa5cc76a006a32dd
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"
44 #ifdef KWM_HINTS
45 #include "kwm.h"
46 #endif
48 /* How many different types of geometry/position
49 display thingies are there? */
50 #define NUM_DISPLAYS 4
52 #define LEFT 1
53 #define RIGHT 2
54 #define HORIZONTAL (LEFT|RIGHT)
55 #define UP 4
56 #define DOWN 8
57 #define VERTICAL (UP|DOWN)
59 /****** Global Variables ******/
60 extern Time LastTimestamp;
62 extern Cursor wCursor[WCUR_LAST];
64 extern WPreferences wPreferences;
66 extern Atom _XA_WM_PROTOCOLS;
70 void
71 wGetGeometryWindowSize(WScreen *scr, unsigned int *width,
72 unsigned int *height)
74 *width = WMWidthOfString(scr->info_text_font, "-8888 x -8888", 13);
76 *height = (6 * WMFontHeight(scr->info_text_font)) / 4 - 1;
81 *----------------------------------------------------------------------
82 * moveGeometryDisplayCentered
84 * routine that moves the geometry/position window on scr so it is
85 * centered over the given coordinates (x,y). Also the window position
86 * is clamped so it stays on the screen at all times.
87 *----------------------------------------------------------------------
89 static void
90 moveGeometryDisplayCentered(WScreen *scr, int x, int y)
92 x -= scr->geometry_display_width / 2;
93 y -= scr->geometry_display_height / 2;
95 if (x < 1)
96 x = 1;
97 else if (x > (scr->scr_width - scr->geometry_display_width - 3))
98 x = scr->scr_width - scr->geometry_display_width - 3;
100 if (y < 1)
101 y = 1;
102 else if (y > (scr->scr_height - scr->geometry_display_height - 3))
103 y = scr->scr_height - scr->geometry_display_height - 3;
105 XMoveWindow(dpy, scr->geometry_display, x, y);
109 static void
110 showPosition(WWindow *wwin, int x, int y)
112 WScreen *scr = wwin->screen_ptr;
113 GC gc = scr->info_text_gc;
114 char num[16];
115 int fw, fh;
117 if (wPreferences.move_display == WDIS_NEW) {
118 #if 1
119 int width = wwin->frame->core->width;
120 int height = wwin->frame->core->height;
122 GC lgc = scr->line_gc;
123 XSetForeground(dpy, lgc, scr->line_pixel);
124 sprintf(num, "%i", x);
126 XDrawLine(dpy, scr->root_win, lgc, 0, y-1, scr->scr_width, y-1);
127 XDrawLine(dpy, scr->root_win, lgc, 0, y+height+2, scr->scr_width,
128 y+height+2);
129 XDrawLine(dpy, scr->root_win, lgc, x-1, 0, x-1, scr->scr_height);
130 XDrawLine(dpy, scr->root_win, lgc, x+width+2, 0, x+width+2,
131 scr->scr_height);
132 #endif
133 } else {
134 XClearArea(dpy, scr->geometry_display, 1, 1,
135 scr->geometry_display_width-2, scr->geometry_display_height-2,
136 False);
137 sprintf(num, "%+i %-+i", x, y);
138 fw = WMWidthOfString(scr->info_text_font, num, strlen(num));
140 XSetForeground(dpy, gc, scr->black_pixel);
142 fh = WMFontHeight(scr->info_text_font);
143 WMDrawString(scr->wmscreen, scr->geometry_display, gc,
144 scr->info_text_font,
145 (scr->geometry_display_width - 2 - fw) / 2,
146 (scr->geometry_display_height-fh)/2, num, strlen(num));
147 wDrawBevel(scr->geometry_display, scr->geometry_display_width+1,
148 scr->geometry_display_height+1,
149 scr->widget_texture, WREL_RAISED);
154 static void
155 cyclePositionDisplay(WWindow *wwin, int x, int y, int w, int h)
157 WScreen *scr = wwin->screen_ptr;
159 wPreferences.move_display++;
160 wPreferences.move_display %= NUM_DISPLAYS;
162 if (wPreferences.move_display == WDIS_NEW) {
163 XUnmapWindow(dpy, scr->geometry_display);
164 } else {
165 if (wPreferences.move_display == WDIS_CENTER) {
166 moveGeometryDisplayCentered(scr,
167 scr->scr_width/2, scr->scr_height/2);
168 } else if (wPreferences.move_display == WDIS_TOPLEFT) {
169 moveGeometryDisplayCentered(scr, 1, 1);
170 } else if (wPreferences.move_display == WDIS_FRAME_CENTER) {
171 moveGeometryDisplayCentered(scr, x + w/2, y + h/2);
173 XMapRaised(dpy, scr->geometry_display);
178 static void
179 mapPositionDisplay(WWindow *wwin, int x, int y, int w, int h)
181 WScreen *scr = wwin->screen_ptr;
183 if (wPreferences.move_display == WDIS_NEW) {
184 return;
185 } else if (wPreferences.move_display == WDIS_CENTER) {
186 moveGeometryDisplayCentered(scr, scr->scr_width / 2,
187 scr->scr_height / 2);
188 } else if (wPreferences.move_display == WDIS_TOPLEFT) {
189 moveGeometryDisplayCentered(scr, 1, 1);
190 } else if (wPreferences.move_display == WDIS_FRAME_CENTER) {
191 moveGeometryDisplayCentered(scr, x + w/2, y + h/2);
193 XMapRaised(dpy, scr->geometry_display);
194 showPosition(wwin, x, y);
197 #define unmapPositionDisplay(w) \
198 XUnmapWindow(dpy, (w)->screen_ptr->geometry_display);
201 static void
202 showGeometry(WWindow *wwin, int x1, int y1, int x2, int y2, int direction)
204 WScreen *scr = wwin->screen_ptr;
205 Window root = scr->root_win;
206 GC gc = scr->line_gc;
207 int ty, by, my, x, y, mx, s;
208 char num[16];
209 XSegment segment[4];
210 int fw, fh;
212 ty = y1 + wwin->frame->top_width;
213 by = y2 - wwin->frame->bottom_width;
214 fw = WMWidthOfString(scr->info_text_font, "8888", 4);
215 fh = WMFontHeight(scr->info_text_font);
217 if (wPreferences.size_display == WDIS_NEW) {
218 XSetForeground(dpy, gc, scr->line_pixel);
220 /* vertical geometry */
221 if (((direction & LEFT) && (x2 < scr->scr_width - fw)) || (x1 < fw)) {
222 x = x2;
223 s = -15;
224 } else {
225 x = x1;
226 s = 15;
228 my = (ty + by) / 2;
230 /* top arrow */
231 /* end bar */
232 segment[0].x1 = x - (s + 6); segment[0].y1 = ty;
233 segment[0].x2 = x - (s - 10); segment[0].y2 = ty;
235 /* arrowhead */
236 segment[1].x1 = x - (s - 2); segment[1].y1 = ty + 1;
237 segment[1].x2 = x - (s - 5); segment[1].y2 = ty + 7;
239 segment[2].x1 = x - (s - 2); segment[2].y1 = ty + 1;
240 segment[2].x2 = x - (s + 1); segment[2].y2 = ty + 7;
242 /* line */
243 segment[3].x1 = x - (s - 2); segment[3].y1 = ty + 1;
244 segment[3].x2 = x - (s - 2); segment[3].y2 = my - fh/2 - 1;
246 XDrawSegments(dpy, root, gc, segment, 4);
248 /* bottom arrow */
249 /* end bar */
250 segment[0].y1 = by;
251 segment[0].y2 = by;
253 /* arrowhead */
254 segment[1].y1 = by - 1;
255 segment[1].y2 = by - 7;
257 segment[2].y1 = by - 1;
258 segment[2].y2 = by - 7;
260 /* line */
261 segment[3].y1 = my + fh/2 + 2;
262 segment[3].y2 = by - 1;
264 XDrawSegments(dpy, root, gc, segment, 4);
266 sprintf(num, "%i", (by - ty - wwin->normal_hints->base_height) /
267 wwin->normal_hints->height_inc);
268 fw = WMWidthOfString(scr->info_text_font, num, strlen(num));
270 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
272 /* Display the height. */
273 WMDrawString(scr->wmscreen, root, gc, scr->info_text_font,
274 x - s + 3 - fw/2, my - fh/2 + 1, num, strlen(num));
275 XSetForeground(dpy, gc, scr->line_pixel);
276 /* horizontal geometry */
277 if (y1 < 15) {
278 y = y2;
279 s = -15;
280 } else {
281 y = y1;
282 s = 15;
284 mx = x1 + (x2 - x1)/2;
285 sprintf(num, "%i", (x2 - x1 - wwin->normal_hints->base_width) /
286 wwin->normal_hints->width_inc);
287 fw = WMWidthOfString(scr->info_text_font, num, strlen(num));
289 /* left arrow */
290 /* end bar */
291 segment[0].x1 = x1; segment[0].y1 = y - (s + 6);
292 segment[0].x2 = x1; segment[0].y2 = y - (s - 10);
294 /* arrowhead */
295 segment[1].x1 = x1 + 7; segment[1].y1 = y - (s + 1);
296 segment[1].x2 = x1 + 1; segment[1].y2 = y - (s - 2);
298 segment[2].x1 = x1 + 1; segment[2].y1 = y - (s - 2);
299 segment[2].x2 = x1 + 7; segment[2].y2 = y - (s - 5);
301 /* line */
302 segment[3].x1 = x1 + 1; segment[3].y1 = y - (s - 2);
303 segment[3].x2 = mx - fw/2 - 2; segment[3].y2 = y - (s - 2);
305 XDrawSegments(dpy, root, gc, segment, 4);
307 /* right arrow */
308 /* end bar */
309 segment[0].x1 = x2 + 1;
310 segment[0].x2 = x2 + 1;
312 /* arrowhead */
313 segment[1].x1 = x2 - 6;
314 segment[1].x2 = x2;
316 segment[2].x1 = x2;
317 segment[2].x2 = x2 - 6;
319 /* line */
320 segment[3].x1 = mx + fw/2 + 2;
321 segment[3].x2 = x2;
323 XDrawSegments(dpy, root, gc, segment, 4);
325 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
327 /* Display the width. */
328 WMDrawString(scr->wmscreen, root, gc, scr->info_text_font,
329 mx - fw/2 + 1, y - s - fh/2 + 1, num, strlen(num));
330 } else {
331 XClearArea(dpy, scr->geometry_display, 1, 1,
332 scr->geometry_display_width-2, scr->geometry_display_height-2,
333 False);
334 sprintf(num, "%i x %-i", (x2 - x1 - wwin->normal_hints->base_width)
335 / wwin->normal_hints->width_inc,
336 (by - ty - wwin->normal_hints->base_height)
337 / wwin->normal_hints->height_inc);
338 fw = WMWidthOfString(scr->info_text_font, num, strlen(num));
340 XSetForeground(dpy, scr->info_text_gc, scr->black_pixel);
342 /* Display the height. */
343 WMDrawString(scr->wmscreen, scr->geometry_display, scr->info_text_gc,
344 scr->info_text_font,
345 (scr->geometry_display_width-fw)/2,
346 (scr->geometry_display_height-fh)/2, num, strlen(num));
347 wDrawBevel(scr->geometry_display, scr->geometry_display_width+1,
348 scr->geometry_display_height+1,
349 scr->widget_texture, WREL_RAISED);
354 static void
355 cycleGeometryDisplay(WWindow *wwin, int x, int y, int w, int h, int dir)
357 WScreen *scr = wwin->screen_ptr;
359 wPreferences.size_display++;
360 wPreferences.size_display %= NUM_DISPLAYS;
362 if (wPreferences.size_display == WDIS_NEW) {
363 XUnmapWindow(dpy, scr->geometry_display);
364 } else {
365 if (wPreferences.size_display == WDIS_CENTER) {
366 moveGeometryDisplayCentered(scr,
367 scr->scr_width / 2, scr->scr_height / 2);
368 } else if (wPreferences.size_display == WDIS_TOPLEFT) {
369 moveGeometryDisplayCentered(scr, 1, 1);
370 } else if (wPreferences.size_display == WDIS_FRAME_CENTER) {
371 moveGeometryDisplayCentered(scr, x + w/2, y + h/2);
373 XMapRaised(dpy, scr->geometry_display);
374 showGeometry(wwin, x, y, x + w, y + h, dir);
379 static void
380 mapGeometryDisplay(WWindow *wwin, int x, int y, int w, int h)
382 WScreen *scr = wwin->screen_ptr;
384 if (wPreferences.size_display == WDIS_NEW)
385 return;
387 if (wPreferences.size_display == WDIS_CENTER) {
388 moveGeometryDisplayCentered(scr, scr->scr_width / 2,
389 scr->scr_height / 2);
390 } else if (wPreferences.size_display == WDIS_TOPLEFT) {
391 moveGeometryDisplayCentered(scr, 1, 1);
392 } else if (wPreferences.size_display == WDIS_FRAME_CENTER) {
393 moveGeometryDisplayCentered(scr, x + w/2, y + h/2);
395 XMapRaised(dpy, scr->geometry_display);
396 showGeometry(wwin, x, y, x + w, y + h, 0);
399 #define unmapGeometryDisplay(w) \
400 XUnmapWindow(dpy, (w)->screen_ptr->geometry_display);
403 static void
404 doWindowMove(WWindow *wwin, WMBag *bag, int dx, int dy)
406 WWindow *tmpw;
407 int x, y;
408 int scr_width = wwin->screen_ptr->scr_width;
409 int scr_height = wwin->screen_ptr->scr_height;
411 if (!bag || !WMGetBagItemCount(bag)) {
412 wWindowMove(wwin, wwin->frame_x + dx, wwin->frame_y + dy);
413 } else {
414 int i;
415 for (i = 0; i < WMGetBagItemCount(bag); i++) {
416 tmpw = WMGetFromBag(bag, i);
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);
438 static void
439 drawTransparentFrame(WWindow *wwin, int x, int y, int width, int height)
441 Window root = wwin->screen_ptr->root_win;
442 GC gc = wwin->screen_ptr->frame_gc;
443 int h = 0;
444 int bottom = 0;
446 if (!WFLAGP(wwin, no_titlebar) && !wwin->flags.shaded) {
447 h = WMFontHeight(wwin->screen_ptr->title_font) + TITLEBAR_EXTRA_HEIGHT;
449 if (!WFLAGP(wwin, no_resizebar) && !wwin->flags.shaded) {
450 /* Can't use wwin-frame->bottom_width because, in some cases
451 (e.g. interactive placement), frame does not point to anything. */
452 bottom = RESIZEBAR_HEIGHT - 1;
454 XDrawRectangle(dpy, root, gc, x, y, width + 1, height + 1);
456 if (h > 0) {
457 XDrawLine(dpy, root, gc, x + 1, y + h, x + width + 1, y + h);
459 if (bottom > 0) {
460 XDrawLine(dpy, root, gc, x + 1,
461 y + height - bottom,
462 x + width + 1,
463 y + height - bottom);
468 static void
469 drawFrames(WWindow *wwin, WMBag *bag, int dx, int dy)
471 WWindow *tmpw;
472 int scr_width = wwin->screen_ptr->scr_width;
473 int scr_height = wwin->screen_ptr->scr_height;
474 int x, y;
476 if (!bag) {
478 x = wwin->frame_x + dx;
479 y = wwin->frame_y + dy;
481 drawTransparentFrame(wwin, x, y,
482 wwin->frame->core->width,
483 wwin->frame->core->height);
485 } else {
486 int i;
487 for (i = 0; i < WMGetBagItemCount(bag); i++) {
488 tmpw = WMGetFromBag(bag, i);
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);
512 static void
513 flushMotion()
515 XEvent ev;
517 XSync(dpy, False);
518 while (XCheckMaskEvent(dpy, ButtonMotionMask, &ev)) ;
522 static void
523 crossWorkspace(WScreen *scr, WWindow *wwin, int opaque_move,
524 int new_workspace, int rewind)
526 /* do not let window be unmapped */
527 if (opaque_move) {
528 wwin->flags.changing_workspace = 1;
529 wWindowChangeWorkspace(wwin, new_workspace);
531 /* go to new workspace */
532 wWorkspaceChange(scr, new_workspace);
534 wwin->flags.changing_workspace = 0;
536 if (rewind)
537 XWarpPointer(dpy, None, None, 0, 0, 0, 0, scr->scr_width - 20, 0);
538 else
539 XWarpPointer(dpy, None, None, 0, 0, 0, 0, -(scr->scr_width - 20), 0);
541 flushMotion();
543 if (!opaque_move) {
544 XGrabPointer(dpy, scr->root_win, True, PointerMotionMask
545 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
546 GrabModeAsync, None, wCursor[WCUR_MOVE], CurrentTime);
553 typedef struct {
554 /* arrays of WWindows sorted by the respective border position */
555 WWindow **topList; /* top border */
556 WWindow **leftList; /* left border */
557 WWindow **rightList; /* right border */
558 WWindow **bottomList; /* bottom border */
559 int count;
561 /* index of window in the above lists indicating the relative position
562 * of the window with the others */
563 int topIndex;
564 int leftIndex;
565 int rightIndex;
566 int bottomIndex;
568 int rubCount; /* for workspace switching */
570 int winWidth, winHeight; /* width/height of the window */
571 int realX, realY; /* actual position of the window */
572 int calcX, calcY; /* calculated position of window */
573 int omouseX, omouseY; /* old mouse position */
574 int mouseX, mouseY; /* last known position of the pointer */
575 } MoveData;
577 #define WTOP(w) (w)->frame_y
578 #define WLEFT(w) (w)->frame_x
579 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width + FRAME_BORDER_WIDTH)
580 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height + FRAME_BORDER_WIDTH)
582 static int
583 compareWTop(const void *a, const void *b)
585 WWindow *wwin1 = *(WWindow**)a;
586 WWindow *wwin2 = *(WWindow**)b;
588 if (WTOP(wwin1) > WTOP(wwin2))
589 return -1;
590 else if (WTOP(wwin1) < WTOP(wwin2))
591 return 1;
592 else
593 return 0;
597 static int
598 compareWLeft(const void *a, const void *b)
600 WWindow *wwin1 = *(WWindow**)a;
601 WWindow *wwin2 = *(WWindow**)b;
603 if (WLEFT(wwin1) > WLEFT(wwin2))
604 return -1;
605 else if (WLEFT(wwin1) < WLEFT(wwin2))
606 return 1;
607 else
608 return 0;
612 static int
613 compareWRight(const void *a, const void *b)
615 WWindow *wwin1 = *(WWindow**)a;
616 WWindow *wwin2 = *(WWindow**)b;
618 if (WRIGHT(wwin1) < WRIGHT(wwin2))
619 return -1;
620 else if (WRIGHT(wwin1) > WRIGHT(wwin2))
621 return 1;
622 else
623 return 0;
628 static int
629 compareWBottom(const void *a, const void *b)
631 WWindow *wwin1 = *(WWindow**)a;
632 WWindow *wwin2 = *(WWindow**)b;
634 if (WBOTTOM(wwin1) < WBOTTOM(wwin2))
635 return -1;
636 else if (WBOTTOM(wwin1) > WBOTTOM(wwin2))
637 return 1;
638 else
639 return 0;
643 static void
644 updateResistance(WWindow *wwin, MoveData *data, int newX, int newY)
646 int i;
647 int newX2 = newX + data->winWidth;
648 int newY2 = newY + data->winHeight;
649 Bool ok = False;
651 if (newX < data->realX) {
652 if (data->rightIndex > 0
653 && newX < WRIGHT(data->rightList[data->rightIndex-1])) {
654 ok = True;
655 } else if (data->leftIndex <= data->count-1
656 && newX2 <= WLEFT(data->leftList[data->leftIndex])) {
657 ok = True;
659 } else if (newX > data->realX) {
660 if (data->leftIndex > 0
661 && newX2 > WLEFT(data->leftList[data->leftIndex-1])) {
662 ok = True;
663 } else if (data->rightIndex <= data->count-1
664 && newX >= WRIGHT(data->rightList[data->rightIndex])) {
665 ok = True;
669 if (!ok) {
670 if (newY < data->realY) {
671 if (data->bottomIndex > 0
672 && newY < WBOTTOM(data->bottomList[data->bottomIndex-1])) {
673 ok = True;
674 } else if (data->topIndex <= data->count-1
675 && newY2 <= WTOP(data->topList[data->topIndex])) {
676 ok = True;
678 } else if (newY > data->realY) {
679 if (data->topIndex > 0
680 && newY2 > WTOP(data->topList[data->topIndex-1])) {
681 ok = True;
682 } else if (data->bottomIndex <= data->count-1
683 && newY >= WBOTTOM(data->bottomList[data->bottomIndex])) {
684 ok = True;
689 if (!ok)
690 return;
692 /* TODO: optimize this */
693 if (data->realY < WBOTTOM(data->bottomList[0])) {
694 data->bottomIndex = 0;
696 if (data->realX < WRIGHT(data->rightList[0])) {
697 data->rightIndex = 0;
699 if ((data->realX + data->winWidth) > WLEFT(data->leftList[0])) {
700 data->leftIndex = 0;
702 if ((data->realY + data->winHeight) > WTOP(data->topList[0])) {
703 data->topIndex = 0;
705 for (i = 0; i < data->count; i++) {
706 if (data->realY > WBOTTOM(data->bottomList[i])) {
707 data->bottomIndex = i + 1;
709 if (data->realX > WRIGHT(data->rightList[i])) {
710 data->rightIndex = i + 1;
712 if ((data->realX + data->winWidth) < WLEFT(data->leftList[i])) {
713 data->leftIndex = i + 1;
715 if ((data->realY + data->winHeight) < WTOP(data->topList[i])) {
716 data->topIndex = i + 1;
722 static void
723 freeMoveData(MoveData *data)
725 if (data->topList)
726 free(data->topList);
727 if (data->leftList)
728 free(data->leftList);
729 if (data->rightList)
730 free(data->rightList);
731 if (data->bottomList)
732 free(data->bottomList);
736 static void
737 updateMoveData(WWindow *wwin, MoveData *data)
739 WScreen *scr = wwin->screen_ptr;
740 WWindow *tmp;
741 int i;
743 data->count = 0;
744 tmp = scr->focused_window;
745 while (tmp) {
746 if (tmp != wwin && scr->current_workspace == tmp->frame->workspace
747 && !tmp->flags.miniaturized
748 && !tmp->flags.hidden
749 && !tmp->flags.obscured
750 && !WFLAGP(tmp, sunken)) {
751 data->topList[data->count] = tmp;
752 data->leftList[data->count] = tmp;
753 data->rightList[data->count] = tmp;
754 data->bottomList[data->count] = tmp;
755 data->count++;
757 tmp = tmp->prev;
760 if (data->count == 0) {
761 data->topIndex = 0;
762 data->leftIndex = 0;
763 data->rightIndex = 0;
764 data->bottomIndex = 0;
765 return;
769 * order from closest to the border of the screen to farthest
771 qsort(data->topList, data->count, sizeof(WWindow**), compareWTop);
772 qsort(data->leftList, data->count, sizeof(WWindow**), compareWLeft);
773 qsort(data->rightList, data->count, sizeof(WWindow**), compareWRight);
774 qsort(data->bottomList, data->count, sizeof(WWindow**), compareWBottom);
776 /* figure the position of the window relative to the others */
778 data->topIndex = -1;
779 data->leftIndex = -1;
780 data->rightIndex = -1;
781 data->bottomIndex = -1;
783 if (WTOP(wwin) < WBOTTOM(data->bottomList[0])) {
784 data->bottomIndex = 0;
786 if (WLEFT(wwin) < WRIGHT(data->rightList[0])) {
787 data->rightIndex = 0;
789 if (WRIGHT(wwin) > WLEFT(data->leftList[0])) {
790 data->leftIndex = 0;
792 if (WBOTTOM(wwin) > WTOP(data->topList[0])) {
793 data->topIndex = 0;
795 for (i = 0; i < data->count; i++) {
796 if (WTOP(wwin) >= WBOTTOM(data->bottomList[i])) {
797 data->bottomIndex = i + 1;
799 if (WLEFT(wwin) >= WRIGHT(data->rightList[i])) {
800 data->rightIndex = i + 1;
802 if (WRIGHT(wwin) <= WLEFT(data->leftList[i])) {
803 data->leftIndex = i + 1;
805 if (WBOTTOM(wwin) <= WTOP(data->topList[i])) {
806 data->topIndex = i + 1;
812 static void
813 initMoveData(WWindow *wwin, MoveData *data)
815 int i;
816 WWindow *tmp;
818 memset(data, 0, sizeof(MoveData));
820 for (i = 0, tmp = wwin->screen_ptr->focused_window;
821 tmp != NULL;
822 tmp = tmp->prev, i++);
824 if (i > 1) {
825 data->topList = wmalloc(sizeof(WWindow*) * i);
826 data->leftList = wmalloc(sizeof(WWindow*) * i);
827 data->rightList = wmalloc(sizeof(WWindow*) * i);
828 data->bottomList = wmalloc(sizeof(WWindow*) * i);
830 updateMoveData(wwin, data);
833 data->realX = wwin->frame_x;
834 data->realY = wwin->frame_y;
835 data->calcX = wwin->frame_x;
836 data->calcY = wwin->frame_y;
838 data->winWidth = wwin->frame->core->width + 2;
839 data->winHeight = wwin->frame->core->height + 2;
843 static Bool
844 checkWorkspaceChange(WWindow *wwin, MoveData *data, Bool opaqueMove)
846 WScreen *scr = wwin->screen_ptr;
847 Bool changed = False;
849 if (data->mouseX <= 1) {
850 if (scr->current_workspace > 0) {
852 crossWorkspace(scr, wwin, opaqueMove, scr->current_workspace - 1,
853 True);
854 changed = True;
855 data->rubCount = 0;
857 } else if (scr->current_workspace == 0 && wPreferences.ws_cycle) {
859 crossWorkspace(scr, wwin, opaqueMove, scr->workspace_count - 1,
860 True);
861 changed = True;
862 data->rubCount = 0;
864 } else if (data->mouseX >= scr->scr_width - 2) {
866 if (scr->current_workspace == scr->workspace_count - 1) {
868 if (wPreferences.ws_cycle
869 || scr->workspace_count == MAX_WORKSPACES) {
871 crossWorkspace(scr, wwin, opaqueMove, 0, False);
872 changed = True;
873 data->rubCount = 0;
875 /* if user insists on trying to go to next workspace even when
876 * it's already the last, create a new one */
877 else if (data->omouseX == data->mouseX
878 && wPreferences.ws_advance) {
880 /* detect user "rubbing" the window against the edge */
881 if (data->rubCount > 0
882 && data->omouseY - data->mouseY > MOVE_THRESHOLD) {
884 data->rubCount = -(data->rubCount + 1);
886 } else if (data->rubCount <= 0
887 && data->mouseY - data->omouseY > MOVE_THRESHOLD) {
889 data->rubCount = -data->rubCount + 1;
892 /* create a new workspace */
893 if (abs(data->rubCount) > 2) {
894 /* go to next workspace */
895 wWorkspaceNew(scr);
897 crossWorkspace(scr, wwin, opaqueMove,
898 scr->current_workspace+1, False);
899 changed = True;
900 data->rubCount = 0;
902 } else if (scr->current_workspace < scr->workspace_count) {
904 /* go to next workspace */
905 crossWorkspace(scr, wwin, opaqueMove,
906 scr->current_workspace+1, False);
907 changed = True;
908 data->rubCount = 0;
910 } else {
911 data->rubCount = 0;
914 return changed;
918 static void
919 updateWindowPosition(WWindow *wwin, MoveData *data, Bool doResistance,
920 Bool opaqueMove, int newMouseX, int newMouseY)
922 WScreen *scr = wwin->screen_ptr;
923 int dx, dy; /* how much mouse moved */
924 int winL, winR, winT, winB; /* requested new window position */
925 int newX, newY; /* actual new window position */
926 Bool hresist, vresist;
927 Bool updateIndex;
928 Bool attract;
930 hresist = False;
931 vresist = False;
933 updateIndex = False;
935 /* check the direction of the movement */
936 dx = newMouseX - data->mouseX;
937 dy = newMouseY - data->mouseY;
939 data->omouseX = data->mouseX;
940 data->omouseY = data->mouseY;
941 data->mouseX = newMouseX;
942 data->mouseY = newMouseY;
944 winL = data->calcX + dx;
945 winR = data->calcX + data->winWidth + dx;
946 winT = data->calcY + dy;
947 winB = data->calcY + data->winHeight + dy;
949 newX = data->realX;
950 newY = data->realY;
952 if (doResistance) {
953 int l_edge, r_edge;
954 int edge_l, edge_r;
955 int t_edge, b_edge;
956 int edge_t, edge_b;
957 int resist;
959 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
960 attract = wPreferences.attract;
961 /* horizontal movement: check horizontal edge resistances */
962 if (dx || dy) {
963 int i;
964 /* window is the leftmost window: check against screen edge */
965 l_edge = scr->totalUsableArea.x1;
966 r_edge = scr->totalUsableArea.x2 + resist;
967 edge_l = scr->totalUsableArea.x1 - resist;
968 edge_r = scr->totalUsableArea.x2;
970 /* 1 */
971 if ((data->rightIndex >= 0) && (data->rightIndex <= data->count)) {
972 WWindow *looprw;
974 for (i = data->rightIndex - 1; i >= 0; i--) {
975 looprw = data->rightList[i];
976 if (!(data->realY > WBOTTOM(looprw)
977 || (data->realY + data->winHeight) < WTOP(looprw))) {
978 if (attract
979 || ((data->realX < (WRIGHT(looprw) + 2)) && dx < 0)) {
980 l_edge = WRIGHT(looprw) + 1;
981 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
983 break;
987 if (attract) {
988 for (i = data->rightIndex; i < data->count; i++) {
989 looprw = data->rightList[i];
990 if(!(data->realY > WBOTTOM(looprw)
991 || (data->realY + data->winHeight) < WTOP(looprw))) {
992 r_edge = WRIGHT(looprw) + 1;
993 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
994 break;
1000 if ((data->leftIndex >= 0) && (data->leftIndex <= data->count)) {
1001 WWindow *looprw;
1003 for (i = data->leftIndex - 1; i >= 0; i--) {
1004 looprw = data->leftList[i];
1005 if (!(data->realY > WBOTTOM(looprw)
1006 || (data->realY + data->winHeight) < WTOP(looprw))) {
1007 if (attract
1008 || (((data->realX + data->winWidth) > (WLEFT(looprw) - 1)) && dx > 0)) {
1009 edge_r = WLEFT(looprw);
1010 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1012 break;
1016 if (attract)
1017 for (i = data->leftIndex; i < data->count; i++) {
1018 looprw = data->leftList[i];
1019 if(!(data->realY > WBOTTOM(looprw)
1020 || (data->realY + data->winHeight) < WTOP(looprw))) {
1021 edge_l = WLEFT(looprw);
1022 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1023 break;
1029 printf("%d %d\n",winL,winR);
1030 printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);
1033 if ((winL - l_edge) < (r_edge - winL)) {
1034 if (resist > 0) {
1035 if ((attract && winL <= l_edge + resist && winL >= l_edge - resist)
1036 || (dx < 0 && winL <= l_edge && winL >= l_edge - resist)) {
1037 newX = l_edge;
1038 hresist = True;
1041 } else {
1042 if (resist > 0 && attract && winL >= r_edge - resist && winL <= r_edge + resist) {
1043 newX = r_edge;
1044 hresist = True;
1048 if ((winR - edge_l) < (edge_r - winR)) {
1049 if (resist > 0 && attract && winR <= edge_l + resist && winR >= edge_l - resist) {
1050 newX = edge_l - data->winWidth;
1051 hresist = True;
1053 } else {
1054 if (resist > 0) {
1055 if ((attract && winR >= edge_r - resist && winR <= edge_r + resist)
1056 || (dx > 0 && winR >= edge_r && winR <= edge_r + resist)) {
1057 newX = edge_r - data->winWidth;
1058 hresist = True;
1063 /* VeRT */
1064 t_edge = scr->totalUsableArea.y1;
1065 b_edge = scr->totalUsableArea.y2 + resist;
1066 edge_t = scr->totalUsableArea.y1 - resist;
1067 edge_b = scr->totalUsableArea.y2;
1069 if ((data->bottomIndex >= 0) && (data->bottomIndex <= data->count)) {
1070 WWindow *looprw;
1072 for (i = data->bottomIndex - 1; i >= 0; i--) {
1073 looprw = data->bottomList[i];
1074 if (!(data->realX > WRIGHT(looprw)
1075 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1076 if (attract
1077 || ((data->realY < (WBOTTOM(looprw) + 2)) && dy < 0)) {
1078 t_edge = WBOTTOM(looprw) + 1;
1079 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1081 break;
1085 if (attract) {
1086 for (i = data->bottomIndex; i < data->count; i++) {
1087 looprw = data->bottomList[i];
1088 if(!(data->realX > WRIGHT(looprw)
1089 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1090 b_edge = WBOTTOM(looprw) + 1;
1091 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1092 break;
1098 if ((data->topIndex >= 0) && (data->topIndex <= data->count)) {
1099 WWindow *looprw;
1101 for (i = data->topIndex - 1; i >= 0; i--) {
1102 looprw = data->topList[i];
1103 if (!(data->realX > WRIGHT(looprw)
1104 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1105 if (attract
1106 || (((data->realY + data->winHeight) > (WTOP(looprw) - 1)) && dy > 0)) {
1107 edge_b = WTOP(looprw);
1108 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1110 break;
1114 if (attract)
1115 for (i = data->topIndex; i < data->count; i++) {
1116 looprw = data->topList[i];
1117 if(!(data->realX > WRIGHT(looprw)
1118 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1119 edge_t = WTOP(looprw);
1120 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1121 break;
1126 if ((winT - t_edge) < (b_edge - winT)) {
1127 if (resist > 0) {
1128 if ((attract && winT <= t_edge + resist && winT >= t_edge - resist)
1129 || (dy < 0 && winT <= t_edge && winT >= t_edge - resist)) {
1130 newY = t_edge;
1131 vresist = True;
1135 else {
1136 if (resist > 0 && attract && winT >= b_edge - resist && winT <= b_edge + resist) {
1137 newY = b_edge;
1138 vresist = True;
1142 if ((winB - edge_t) < (edge_b - winB)) {
1143 if (resist > 0 && attract && winB <= edge_t + resist && winB >= edge_t - resist) {
1144 newY = edge_t - data->winHeight;
1145 vresist = True;
1148 else {
1149 if (resist > 0) {
1150 if ((attract && winB >= edge_b - resist && winB <= edge_b + resist)
1151 || (dy > 0 && winB >= edge_b && winB <= edge_b + resist)) {
1152 newY = edge_b - data->winHeight;
1153 vresist = True;
1158 /* END VeRT */
1162 /* update window position */
1163 data->calcX += dx;
1164 data->calcY += dy;
1166 if (((dx > 0 && data->calcX - data->realX > 0)
1167 || (dx < 0 && data->calcX - data->realX < 0)) && !hresist)
1168 newX = data->calcX;
1170 if (((dy > 0 && data->calcY - data->realY > 0)
1171 || (dy < 0 && data->calcY - data->realY < 0)) && !vresist)
1172 newY = data->calcY;
1174 if (data->realX != newX || data->realY != newY) {
1176 if (wPreferences.move_display == WDIS_NEW
1177 && !scr->selected_windows) {
1178 showPosition(wwin, data->realX, data->realY);
1180 if (opaqueMove) {
1181 doWindowMove(wwin, scr->selected_windows,
1182 newX - wwin->frame_x,
1183 newY - wwin->frame_y);
1184 } else {
1185 /* erase frames */
1186 drawFrames(wwin, scr->selected_windows,
1187 data->realX - wwin->frame_x,
1188 data->realY - wwin->frame_y);
1191 if (!scr->selected_windows
1192 && wPreferences.move_display == WDIS_FRAME_CENTER) {
1194 moveGeometryDisplayCentered(scr, newX + data->winWidth/2,
1195 newY + data->winHeight/2);
1198 if (!opaqueMove) {
1199 /* draw frames */
1200 drawFrames(wwin, scr->selected_windows,
1201 newX - wwin->frame_x,
1202 newY - wwin->frame_y);
1205 if (!scr->selected_windows) {
1206 showPosition(wwin, newX, newY);
1211 /* recalc relative window position */
1212 if (doResistance && (data->realX != newX || data->realY != newY)) {
1213 updateResistance(wwin, data, newX, newY);
1216 data->realX = newX;
1217 data->realY = newY;
1221 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1224 wKeyboardMoveResizeWindow(WWindow *wwin)
1226 WScreen *scr = wwin->screen_ptr;
1227 Window root = scr->root_win;
1228 XEvent event;
1229 int w = wwin->frame->core->width;
1230 int h = wwin->frame->core->height;
1231 int scr_width = wwin->screen_ptr->scr_width;
1232 int scr_height = wwin->screen_ptr->scr_height;
1233 int vert_border = wwin->frame->top_width + wwin->frame->bottom_width;
1234 int src_x = wwin->frame_x;
1235 int src_y = wwin->frame_y;
1236 int done,off_x,off_y,ww,wh;
1237 int kspeed = _KS;
1238 Time lastTime = 0;
1239 KeySym keysym=NoSymbol;
1240 int moment=0;
1241 KeyCode shiftl,shiftr,ctrll,ctrlmode;
1243 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1244 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1245 ctrll = XKeysymToKeycode(dpy, XK_Control_L);
1246 ctrlmode=done=off_x=off_y=0;
1248 XSync(dpy, False);
1249 wusleep(10000);
1250 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync, CurrentTime);
1252 if (!wwin->flags.selected) {
1253 wUnselectWindows(scr);
1255 XGrabServer(dpy);
1256 XGrabPointer(dpy, scr->root_win, True, PointerMotionMask
1257 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
1258 GrabModeAsync, None, wCursor[WCUR_DEFAULT], CurrentTime);
1260 if (wwin->flags.shaded || scr->selected_windows) {
1261 if(scr->selected_windows)
1262 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1263 else drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1264 if(!scr->selected_windows)
1265 mapPositionDisplay(wwin, src_x, src_y, w, h);
1266 } else {
1267 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1269 ww=w;
1270 wh=h;
1271 while(1) {
1273 looper.ox=off_x;
1274 looper.oy=off_y;
1276 WMMaskEvent(dpy, KeyPressMask | ButtonReleaseMask
1277 | ButtonPressMask | ExposureMask, &event);
1278 if (wwin->flags.shaded || scr->selected_windows) {
1279 if(scr->selected_windows)
1280 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1281 else drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1282 /*** I HATE EDGE RESISTANCE - ]d ***/
1284 else {
1285 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, ww, wh);
1288 if(ctrlmode)
1289 showGeometry(wwin, src_x+off_x, src_y+off_y, src_x+off_x+ww, src_y+off_y+wh,0);
1291 XUngrabServer(dpy);
1292 XSync(dpy, False);
1294 switch (event.type) {
1295 case KeyPress:
1296 /* accelerate */
1297 if (event.xkey.time - lastTime > 50) {
1298 kspeed/=(1 + (event.xkey.time - lastTime)/100);
1299 } else {
1300 if (kspeed < 20) {
1301 kspeed++;
1304 if (kspeed < _KS) kspeed = _KS;
1305 lastTime = event.xkey.time;
1307 if (event.xkey.state & ControlMask && !wwin->flags.shaded) {
1308 ctrlmode=1;
1309 wUnselectWindows(scr);
1311 else {
1312 ctrlmode=0;
1314 if (event.xkey.keycode == shiftl || event.xkey.keycode == shiftr) {
1315 if (ctrlmode)
1316 cycleGeometryDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh, 0);
1317 else
1318 cyclePositionDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh);
1320 else {
1322 keysym = XLookupKeysym(&event.xkey, 0);
1323 switch (keysym) {
1324 case XK_Return:
1325 done=2;
1326 break;
1327 case XK_Escape:
1328 done=1;
1329 break;
1330 case XK_Up:
1331 case XK_KP_Up:
1332 case XK_k:
1333 if (ctrlmode){
1334 if (moment != UP)
1335 h = wh;
1336 h-=kspeed;
1337 moment = UP;
1338 if (h < 1) h = 1;
1340 else off_y-=kspeed;
1341 break;
1342 case XK_Down:
1343 case XK_KP_Down:
1344 case XK_j:
1345 if (ctrlmode){
1346 if (moment != DOWN)
1347 h = wh;
1348 h+=kspeed;
1349 moment = DOWN;
1351 else off_y+=kspeed;
1352 break;
1353 case XK_Left:
1354 case XK_KP_Left:
1355 case XK_h:
1356 if (ctrlmode) {
1357 if (moment != LEFT)
1358 w = ww;
1359 w-=kspeed;
1360 if (w < 1) w = 1;
1361 moment = LEFT;
1363 else off_x-=kspeed;
1364 break;
1365 case XK_Right:
1366 case XK_KP_Right:
1367 case XK_l:
1368 if (ctrlmode) {
1369 if (moment != RIGHT)
1370 w = ww;
1371 w+=kspeed;
1372 moment = RIGHT;
1374 else off_x+=kspeed;
1375 break;
1378 ww=w;wh=h;
1379 wh-=vert_border;
1380 wWindowConstrainSize(wwin, &ww, &wh);
1381 wh+=vert_border;
1383 if (wPreferences.ws_cycle){
1384 if (src_x + off_x + ww < 20){
1385 if(!scr->current_workspace) {
1386 wWorkspaceChange(scr, scr->workspace_count-1);
1388 else wWorkspaceChange(scr, scr->current_workspace-1);
1389 off_x += scr_width;
1391 else if (src_x + off_x + 20 > scr_width){
1392 if(scr->current_workspace == scr->workspace_count-1) {
1393 wWorkspaceChange(scr, 0);
1395 else wWorkspaceChange(scr, scr->current_workspace+1);
1396 off_x -= scr_width;
1399 else {
1400 if (src_x + off_x + ww < 20)
1401 off_x = 20 - ww - src_x;
1402 else if (src_x + off_x + 20 > scr_width)
1403 off_x = scr_width - 20 - src_x;
1406 if (src_y + off_y + wh < 20) {
1407 off_y = 20 - wh - src_y;
1409 else if (src_y + off_y + 20 > scr_height) {
1410 off_y = scr_height - 20 - src_y;
1413 break;
1414 case ButtonPress:
1415 case ButtonRelease:
1416 done=1;
1417 break;
1418 default:
1419 WMHandleEvent(&event);
1420 break;
1423 XGrabServer(dpy);
1424 /*xxx*/
1426 if (wwin->flags.shaded && !scr->selected_windows){
1427 moveGeometryDisplayCentered(scr, src_x+off_x + w/2, src_y+off_y + h/2);
1429 else {
1430 if(ctrlmode){
1431 unmapPositionDisplay(wwin);
1432 mapGeometryDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh);
1434 else if(!scr->selected_windows){
1435 unmapGeometryDisplay(wwin);
1436 mapPositionDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh);
1440 if (wwin->flags.shaded || scr->selected_windows) {
1441 if(scr->selected_windows)
1442 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1443 else drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1445 else {
1446 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, ww, wh);
1450 if(ctrlmode){
1451 showGeometry(wwin, src_x+off_x, src_y+off_y, src_x+off_x+ww, src_y+off_y+wh,0);
1453 else if(!scr->selected_windows)
1454 showPosition(wwin, src_x+off_x, src_y+off_y);
1455 /**/
1457 if(done){
1458 scr->keymove_tick=0;
1460 WMDeleteTimerWithClientData(&looper);
1462 if (wwin->flags.shaded || scr->selected_windows) {
1463 if(scr->selected_windows)
1464 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1465 else drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1467 else {
1468 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, ww, wh);
1471 if(ctrlmode){
1472 showGeometry(wwin, src_x+off_x, src_y+off_y, src_x+off_x+ww, src_y+off_y+wh,0);
1473 unmapGeometryDisplay(wwin);
1475 else
1476 unmapPositionDisplay(wwin);
1477 XUngrabKeyboard(dpy, CurrentTime);
1478 XUngrabPointer(dpy, CurrentTime);
1479 XUngrabServer(dpy);
1481 if(done==2) {
1482 if (wwin->flags.shaded || scr->selected_windows) {
1483 WMBag *bag;
1484 bag=scr->selected_windows;
1485 if (!WMGetBagItemCount(scr->selected_windows)) {
1486 wWindowMove(wwin, src_x+off_x, src_y+off_y);
1487 wWindowSynthConfigureNotify(wwin);
1488 } else {
1489 int i;
1490 doWindowMove(wwin,scr->selected_windows,off_x,off_y);
1491 for (i = 0; i < WMGetBagItemCount(bag); i++) {
1492 wWindowSynthConfigureNotify(WMGetFromBag(bag, i));
1495 } else {
1496 if (wwin->client.width != ww)
1497 wwin->flags.user_changed_width = 1;
1499 if (wwin->client.height != wh - vert_border)
1500 wwin->flags.user_changed_height = 1;
1502 wWindowConfigure(wwin, src_x+off_x, src_y+off_y,
1503 ww, wh - vert_border);
1504 wWindowSynthConfigureNotify(wwin);
1506 wWindowChangeWorkspace(wwin, scr->current_workspace);
1507 wSetFocusTo(scr, wwin);
1509 return 1;
1516 *----------------------------------------------------------------------
1517 * wMouseMoveWindow--
1518 * Move the named window and the other selected ones (if any),
1519 * interactively. Also shows the position of the window, if only one
1520 * window is being moved.
1521 * If the window is not on the selected window list, the selected
1522 * windows are deselected.
1523 * If shift is pressed during the operation, the position display
1524 * is changed to another type.
1526 * Returns:
1527 * True if the window was moved, False otherwise.
1529 * Side effects:
1530 * The window(s) position is changed, and the client(s) are
1531 * notified about that.
1532 * The position display configuration may be changed.
1533 *----------------------------------------------------------------------
1536 wMouseMoveWindow(WWindow *wwin, XEvent *ev)
1538 WScreen *scr = wwin->screen_ptr;
1539 XEvent event;
1540 Window root = scr->root_win;
1541 KeyCode shiftl, shiftr;
1542 Bool done = False;
1543 int started = 0;
1544 int warped = 0;
1545 /* This needs not to change while moving, else bad things can happen */
1546 int opaqueMove = wPreferences.opaque_move;
1547 MoveData moveData;
1548 #ifdef GHOST_WINDOW_MOVE
1549 RImage *rimg;
1551 rimg = InitGhostWindowMove(scr);
1552 #endif
1555 if (wPreferences.opaque_move && !wPreferences.use_saveunders) {
1556 XSetWindowAttributes attr;
1558 attr.save_under = True;
1559 XChangeWindowAttributes(dpy, wwin->frame->core->window,
1560 CWSaveUnder, &attr);
1564 initMoveData(wwin, &moveData);
1566 moveData.mouseX = ev->xmotion.x_root;
1567 moveData.mouseY = ev->xmotion.y_root;
1569 if (!wwin->flags.selected) {
1570 /* this window is not selected, unselect others and move only wwin */
1571 wUnselectWindows(scr);
1573 #ifdef DEBUG
1574 puts("Moving window");
1575 #endif
1576 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1577 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1578 while (!done) {
1579 if (warped) {
1580 int junk;
1581 Window junkw;
1583 /* XWarpPointer() doesn't seem to generate Motion events, so
1584 we've got to simulate them */
1585 XQueryPointer(dpy, root, &junkw, &junkw, &event.xmotion.x_root,
1586 &event.xmotion.y_root, &junk, &junk,
1587 (unsigned *) &junk);
1588 } else {
1589 WMMaskEvent(dpy, KeyPressMask | ButtonMotionMask
1590 | ButtonReleaseMask | ButtonPressMask | ExposureMask,
1591 &event);
1593 if (event.type == MotionNotify) {
1594 /* compress MotionNotify events */
1595 while (XCheckMaskEvent(dpy, ButtonMotionMask, &event)) ;
1598 switch (event.type) {
1599 case KeyPress:
1600 if ((event.xkey.keycode == shiftl || event.xkey.keycode == shiftr)
1601 && started && !scr->selected_windows) {
1603 if (!opaqueMove) {
1604 drawFrames(wwin, scr->selected_windows,
1605 moveData.realX - wwin->frame_x,
1606 moveData.realY - wwin->frame_y);
1609 if (wPreferences.move_display == WDIS_NEW
1610 && !scr->selected_windows) {
1611 showPosition(wwin, moveData.realX, moveData.realY);
1612 XUngrabServer(dpy);
1614 cyclePositionDisplay(wwin, moveData.realX, moveData.realY,
1615 moveData.winWidth, moveData.winHeight);
1617 if (wPreferences.move_display == WDIS_NEW
1618 && !scr->selected_windows) {
1619 XGrabServer(dpy);
1620 showPosition(wwin, moveData.realX, moveData.realY);
1623 if (!opaqueMove) {
1624 drawFrames(wwin, scr->selected_windows,
1625 moveData.realX - wwin->frame_x,
1626 moveData.realY - wwin->frame_y);
1629 break;
1631 case MotionNotify:
1632 if (started) {
1633 updateWindowPosition(wwin, &moveData,
1634 scr->selected_windows == NULL
1635 && wPreferences.edge_resistance > 0,
1636 opaqueMove,
1637 event.xmotion.x_root,
1638 event.xmotion.y_root);
1640 if (!warped && !wPreferences.no_autowrap) {
1641 int oldWorkspace = scr->current_workspace;
1643 if (wPreferences.move_display == WDIS_NEW
1644 && !scr->selected_windows) {
1645 showPosition(wwin, moveData.realX, moveData.realY);
1646 XUngrabServer(dpy);
1648 if (!opaqueMove) {
1649 drawFrames(wwin, scr->selected_windows,
1650 moveData.realX - wwin->frame_x,
1651 moveData.realY - wwin->frame_y);
1653 if (checkWorkspaceChange(wwin, &moveData, opaqueMove)) {
1654 if (scr->current_workspace != oldWorkspace
1655 && wPreferences.edge_resistance > 0
1656 && scr->selected_windows == NULL)
1657 updateMoveData(wwin, &moveData);
1658 warped = 1;
1660 if (!opaqueMove) {
1661 drawFrames(wwin, scr->selected_windows,
1662 moveData.realX - wwin->frame_x,
1663 moveData.realY - wwin->frame_y);
1665 if (wPreferences.move_display == WDIS_NEW
1666 && !scr->selected_windows) {
1667 XSync(dpy, False);
1668 showPosition(wwin, moveData.realX, moveData.realY);
1669 XGrabServer(dpy);
1671 } else {
1672 warped = 0;
1674 } else if (abs(ev->xmotion.x_root - event.xmotion.x_root) >= MOVE_THRESHOLD
1675 || abs(ev->xmotion.y_root - event.xmotion.y_root) >= MOVE_THRESHOLD) {
1677 XChangeActivePointerGrab(dpy, ButtonMotionMask
1678 | ButtonReleaseMask | ButtonPressMask,
1679 wCursor[WCUR_MOVE], CurrentTime);
1680 started = 1;
1681 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync,
1682 CurrentTime);
1684 if (!scr->selected_windows)
1685 mapPositionDisplay(wwin, moveData.realX, moveData.realY,
1686 moveData.winWidth, moveData.winHeight);
1688 if (started && !opaqueMove)
1689 drawFrames(wwin, scr->selected_windows, 0, 0);
1691 if (!opaqueMove || (wPreferences.move_display==WDIS_NEW
1692 && !scr->selected_windows)) {
1693 XGrabServer(dpy);
1694 if (wPreferences.move_display==WDIS_NEW)
1695 showPosition(wwin, moveData.realX, moveData.realY);
1698 break;
1700 case ButtonPress:
1701 break;
1703 case ButtonRelease:
1704 if (event.xbutton.button != ev->xbutton.button)
1705 break;
1707 if (started) {
1708 if (!opaqueMove) {
1709 drawFrames(wwin, scr->selected_windows,
1710 moveData.realX - wwin->frame_x,
1711 moveData.realY - wwin->frame_y);
1712 XSync(dpy, 0);
1713 doWindowMove(wwin, scr->selected_windows,
1714 moveData.realX - wwin->frame_x,
1715 moveData.realY - wwin->frame_y);
1717 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1718 wWindowSynthConfigureNotify(wwin);
1719 #endif
1720 XUngrabKeyboard(dpy, CurrentTime);
1721 XUngrabServer(dpy);
1722 if (!opaqueMove) {
1723 wWindowChangeWorkspace(wwin, scr->current_workspace);
1724 wSetFocusTo(scr, wwin);
1726 if (wPreferences.move_display == WDIS_NEW)
1727 showPosition(wwin, moveData.realX, moveData.realY);
1729 if (!scr->selected_windows) {
1730 /* get rid of the geometry window */
1731 unmapPositionDisplay(wwin);
1734 #ifdef DEBUG
1735 puts("End move window");
1736 #endif
1737 done = True;
1738 break;
1740 default:
1741 if (started && !opaqueMove) {
1742 drawFrames(wwin, scr->selected_windows,
1743 moveData.realX - wwin->frame_x,
1744 moveData.realY - wwin->frame_y);
1745 XUngrabServer(dpy);
1746 WMHandleEvent(&event);
1747 XSync(dpy, False);
1748 XGrabServer(dpy);
1749 drawFrames(wwin, scr->selected_windows,
1750 moveData.realX - wwin->frame_x,
1751 moveData.realY - wwin->frame_y);
1752 } else {
1753 WMHandleEvent(&event);
1755 break;
1759 if (wPreferences.opaque_move && !wPreferences.use_saveunders) {
1760 XSetWindowAttributes attr;
1763 attr.save_under = False;
1764 XChangeWindowAttributes(dpy, wwin->frame->core->window,
1765 CWSaveUnder, &attr);
1769 freeMoveData(&moveData);
1771 return started;
1775 #define RESIZEBAR 1
1776 #define HCONSTRAIN 2
1778 static int
1779 getResizeDirection(WWindow *wwin, int x, int y, int dx, int dy,
1780 int flags)
1782 int w = wwin->frame->core->width - 1;
1783 int cw = wwin->frame->resizebar_corner_width;
1784 int dir;
1786 /* if not resizing through the resizebar */
1787 if (!(flags & RESIZEBAR)) {
1788 int xdir = (abs(x) < (wwin->client.width/2)) ? LEFT : RIGHT;
1789 int ydir = (abs(y) < (wwin->client.height/2)) ? UP : DOWN;
1790 if (abs(dx) < 2 || abs(dy) < 2) {
1791 if (abs(dy) > abs(dx))
1792 xdir = 0;
1793 else
1794 ydir = 0;
1796 return (xdir | ydir);
1799 /* window is too narrow. allow diagonal resize */
1800 if (cw * 2 >= w) {
1801 int ydir;
1803 if (flags & HCONSTRAIN)
1804 ydir = 0;
1805 else
1806 ydir = DOWN;
1807 if (x < cw)
1808 return (LEFT | ydir);
1809 else
1810 return (RIGHT | ydir);
1812 /* vertical resize */
1813 if ((x > cw) && (x < w - cw))
1814 return DOWN;
1816 if (x < cw)
1817 dir = LEFT;
1818 else
1819 dir = RIGHT;
1821 if ((abs(dy) > 0) && !(flags & HCONSTRAIN))
1822 dir |= DOWN;
1824 return dir;
1828 void
1829 wMouseResizeWindow(WWindow *wwin, XEvent *ev)
1831 XEvent event;
1832 WScreen *scr = wwin->screen_ptr;
1833 Window root = scr->root_win;
1834 int vert_border = wwin->frame->top_width + wwin->frame->bottom_width;
1835 int fw = wwin->frame->core->width;
1836 int fh = wwin->frame->core->height;
1837 int fx = wwin->frame_x;
1838 int fy = wwin->frame_y;
1839 int is_resizebar = (wwin->frame->resizebar
1840 && ev->xany.window==wwin->frame->resizebar->window);
1841 int orig_x, orig_y;
1842 int started;
1843 int dw, dh;
1844 int rw = fw, rh = fh;
1845 int rx1, ry1, rx2, ry2;
1846 int res = 0;
1847 KeyCode shiftl, shiftr;
1848 int h = 0;
1849 int orig_fx = fx;
1850 int orig_fy = fy;
1851 int orig_fw = fw;
1852 int orig_fh = fh;
1854 if (wwin->flags.shaded) {
1855 wwarning("internal error: tryein");
1856 return;
1858 orig_x = ev->xbutton.x_root;
1859 orig_y = ev->xbutton.y_root;
1861 started = 0;
1862 #ifdef DEBUG
1863 puts("Resizing window");
1864 #endif
1866 wUnselectWindows(scr);
1867 rx1 = fx;
1868 rx2 = fx + fw - 1;
1869 ry1 = fy;
1870 ry2 = fy + fh - 1;
1871 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1872 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1873 if (!WFLAGP(wwin, no_titlebar))
1874 h = WMFontHeight(wwin->screen_ptr->title_font) + TITLEBAR_EXTRA_HEIGHT;
1875 else
1876 h = 0;
1877 while (1) {
1878 WMMaskEvent(dpy, KeyPressMask | ButtonMotionMask | ButtonReleaseMask
1879 | ButtonPressMask | ExposureMask, &event);
1880 switch (event.type) {
1881 case KeyPress:
1882 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1883 if ((event.xkey.keycode == shiftl || event.xkey.keycode == shiftr)
1884 && started) {
1885 drawTransparentFrame(wwin, fx, fy, fw, fh);
1886 cycleGeometryDisplay(wwin, fx, fy, fw, fh, res);
1887 drawTransparentFrame(wwin, fx, fy, fw, fh);
1889 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1890 break;
1892 case MotionNotify:
1893 if (started) {
1894 dw = 0;
1895 dh = 0;
1897 orig_fx = fx;
1898 orig_fy = fy;
1899 orig_fw = fw;
1900 orig_fh = fh;
1902 if (res & LEFT)
1903 dw = orig_x - event.xmotion.x_root;
1904 else if (res & RIGHT)
1905 dw = event.xmotion.x_root - orig_x;
1906 if (res & UP)
1907 dh = orig_y - event.xmotion.y_root;
1908 else if (res & DOWN)
1909 dh = event.xmotion.y_root - orig_y;
1911 orig_x = event.xmotion.x_root;
1912 orig_y = event.xmotion.y_root;
1914 rw += dw;
1915 rh += dh;
1916 fw = rw;
1917 fh = rh - vert_border;
1918 wWindowConstrainSize(wwin, &fw, &fh);
1919 fh += vert_border;
1920 if (res & LEFT)
1921 fx = rx2 - fw + 1;
1922 else if (res & RIGHT)
1923 fx = rx1;
1924 if (res & UP)
1925 fy = ry2 - fh + 1;
1926 else if (res & DOWN)
1927 fy = ry1;
1928 } else if (abs(orig_x - event.xmotion.x_root) >= MOVE_THRESHOLD
1929 || abs(orig_y - event.xmotion.y_root) >= MOVE_THRESHOLD) {
1930 int tx, ty;
1931 Window junkw;
1932 int flags;
1934 XTranslateCoordinates(dpy, root, wwin->frame->core->window,
1935 orig_x, orig_y, &tx, &ty, &junkw);
1937 /* check if resizing through resizebar */
1938 if (is_resizebar)
1939 flags = RESIZEBAR;
1940 else
1941 flags = 0;
1943 if (is_resizebar && ((ev->xbutton.state & ShiftMask)
1944 || abs(orig_y - event.xmotion.y_root) < HRESIZE_THRESHOLD))
1945 flags |= HCONSTRAIN;
1947 res = getResizeDirection(wwin, tx, ty,
1948 orig_x - event.xmotion.x_root,
1949 orig_y - event.xmotion.y_root, flags);
1951 XChangeActivePointerGrab(dpy, ButtonMotionMask
1952 | ButtonReleaseMask | ButtonPressMask,
1953 wCursor[WCUR_RESIZE], CurrentTime);
1954 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync,
1955 CurrentTime);
1957 XGrabServer(dpy);
1959 /* Draw the resize frame for the first time. */
1960 mapGeometryDisplay(wwin, fx, fy, fw, fh);
1962 drawTransparentFrame(wwin, fx, fy, fw, fh);
1964 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1966 started = 1;
1968 if (started) {
1969 if (wPreferences.size_display == WDIS_FRAME_CENTER) {
1970 drawTransparentFrame(wwin, orig_fx, orig_fy,
1971 orig_fw, orig_fh);
1972 moveGeometryDisplayCentered(scr, fx + fw / 2, fy + fh / 2);
1973 drawTransparentFrame(wwin, fx, fy, fw, fh);
1974 } else {
1975 drawTransparentFrame(wwin, orig_fx, orig_fy,
1976 orig_fw, orig_fh);
1977 drawTransparentFrame(wwin, fx, fy, fw, fh);
1979 if (fh != orig_fh || fw != orig_fw) {
1980 if (wPreferences.size_display == WDIS_NEW) {
1981 showGeometry(wwin, orig_fx, orig_fy, orig_fx + orig_fw,
1982 orig_fy + orig_fh, res);
1984 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1987 break;
1989 case ButtonPress:
1990 break;
1992 case ButtonRelease:
1993 if (event.xbutton.button != ev->xbutton.button)
1994 break;
1996 if (started) {
1997 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1999 drawTransparentFrame(wwin, fx, fy, fw, fh);
2001 XUngrabKeyboard(dpy, CurrentTime);
2002 unmapGeometryDisplay(wwin);
2003 XUngrabServer(dpy);
2005 if (wwin->client.width != fw)
2006 wwin->flags.user_changed_width = 1;
2008 if (wwin->client.height != fh - vert_border)
2009 wwin->flags.user_changed_height = 1;
2011 wWindowConfigure(wwin, fx, fy, fw, fh - vert_border);
2013 #ifdef DEBUG
2014 puts("End resize window");
2015 #endif
2016 return;
2018 default:
2019 WMHandleEvent(&event);
2024 #undef LEFT
2025 #undef RIGHT
2026 #undef HORIZONTAL
2027 #undef UP
2028 #undef DOWN
2029 #undef VERTICAL
2030 #undef HCONSTRAIN
2031 #undef RESIZEBAR
2033 void
2034 wUnselectWindows(WScreen *scr)
2036 WWindow *wwin;
2038 if (!scr->selected_windows)
2039 return;
2041 while (WMGetBagItemCount(scr->selected_windows)) {
2042 wwin = WMGetFromBag(scr->selected_windows, 0);
2043 if (wwin->flags.miniaturized && wwin->icon && wwin->icon->selected)
2044 wIconSelect(wwin->icon);
2046 wSelectWindow(wwin, False);
2048 WMFreeBag(scr->selected_windows);
2049 scr->selected_windows = NULL;
2052 #ifndef LITE
2053 static void
2054 selectWindowsInside(WScreen *scr, int x1, int y1, int x2, int y2)
2056 WWindow *tmpw;
2058 /* select the windows and put them in the selected window list */
2059 tmpw = scr->focused_window;
2060 while (tmpw != NULL) {
2061 if (!(tmpw->flags.miniaturized || tmpw->flags.hidden)) {
2062 if ((tmpw->frame->workspace == scr->current_workspace
2063 || IS_OMNIPRESENT(tmpw))
2064 && (tmpw->frame_x >= x1) && (tmpw->frame_y >= y1)
2065 && (tmpw->frame->core->width + tmpw->frame_x <= x2)
2066 && (tmpw->frame->core->height + tmpw->frame_y <= y2)) {
2067 wSelectWindow(tmpw, True);
2070 tmpw = tmpw->prev;
2075 void
2076 wSelectWindows(WScreen *scr, XEvent *ev)
2078 XEvent event;
2079 Window root = scr->root_win;
2080 GC gc = scr->frame_gc;
2081 int xp = ev->xbutton.x_root;
2082 int yp = ev->xbutton.y_root;
2083 int w = 0, h = 0;
2084 int x = xp, y = yp;
2086 #ifdef DEBUG
2087 puts("Selecting windows");
2088 #endif
2089 if (XGrabPointer(dpy, scr->root_win, False, ButtonMotionMask
2090 | ButtonReleaseMask | ButtonPressMask, GrabModeAsync,
2091 GrabModeAsync, None, wCursor[WCUR_DEFAULT],
2092 CurrentTime) != Success) {
2093 return;
2095 XGrabServer(dpy);
2097 wUnselectWindows(scr);
2099 XDrawRectangle(dpy, root, gc, xp, yp, w, h);
2100 while (1) {
2101 WMMaskEvent(dpy, ButtonReleaseMask | PointerMotionMask
2102 | ButtonPressMask, &event);
2104 switch (event.type) {
2105 case MotionNotify:
2106 XDrawRectangle(dpy, root, gc, x, y, w, h);
2107 x = event.xmotion.x_root;
2108 if (x < xp) {
2109 w = xp - x;
2110 } else {
2111 w = x - xp;
2112 x = xp;
2114 y = event.xmotion.y_root;
2115 if (y < yp) {
2116 h = yp - y;
2117 } else {
2118 h = y - yp;
2119 y = yp;
2121 XDrawRectangle(dpy, root, gc, x, y, w, h);
2122 break;
2124 case ButtonPress:
2125 break;
2127 case ButtonRelease:
2128 if (event.xbutton.button != ev->xbutton.button)
2129 break;
2131 XDrawRectangle(dpy, root, gc, x, y, w, h);
2132 XUngrabServer(dpy);
2133 XUngrabPointer(dpy, CurrentTime);
2134 selectWindowsInside(scr, x, y, x + w, y + h);
2136 #ifdef KWM_HINTS
2137 wKWMSelectRootRegion(scr, x, y, w, h,
2138 event.xbutton.state & ControlMask);
2139 #endif /* KWM_HINTS */
2141 #ifdef DEBUG
2142 puts("End window selection");
2143 #endif
2144 return;
2146 default:
2147 WMHandleEvent(&event);
2148 break;
2152 #endif /* !LITE */
2154 void
2155 InteractivePlaceWindow(WWindow *wwin, int *x_ret, int *y_ret,
2156 unsigned width, unsigned height)
2158 WScreen *scr = wwin->screen_ptr;
2159 Window root = scr->root_win;
2160 int x, y, h = 0;
2161 XEvent event;
2162 KeyCode shiftl, shiftr;
2163 Window junkw;
2164 int junk;
2166 if (XGrabPointer(dpy, root, True, PointerMotionMask | ButtonPressMask,
2167 GrabModeAsync, GrabModeAsync, None,
2168 wCursor[WCUR_DEFAULT], CurrentTime) != Success) {
2169 *x_ret = 0;
2170 *y_ret = 0;
2171 return;
2173 if (!WFLAGP(wwin, no_titlebar)) {
2174 h = WMFontHeight(scr->title_font) + TITLEBAR_EXTRA_HEIGHT;
2175 height += h;
2177 if (!WFLAGP(wwin, no_resizebar)) {
2178 height += RESIZEBAR_HEIGHT;
2180 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync, CurrentTime);
2181 XQueryPointer(dpy, root, &junkw, &junkw, &x, &y, &junk, &junk,
2182 (unsigned *) &junk);
2183 mapPositionDisplay(wwin, x - width/2, y - h/2, width, height);
2185 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2187 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
2188 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
2189 while (1) {
2190 WMMaskEvent(dpy, PointerMotionMask|ButtonPressMask|ExposureMask|KeyPressMask,
2191 &event);
2192 switch (event.type) {
2193 case KeyPress:
2194 if ((event.xkey.keycode == shiftl)
2195 || (event.xkey.keycode == shiftr)) {
2196 drawTransparentFrame(wwin,
2197 x - width/2, y - h/2, width, height);
2198 cyclePositionDisplay(wwin,
2199 x - width/2, y - h/2, width, height);
2200 drawTransparentFrame(wwin,
2201 x - width/2, y - h/2, width, height);
2203 break;
2205 case MotionNotify:
2206 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2208 x = event.xmotion.x_root;
2209 y = event.xmotion.y_root;
2211 if (wPreferences.move_display == WDIS_FRAME_CENTER)
2212 moveGeometryDisplayCentered(scr, x, y + (height - h) / 2);
2214 showPosition(wwin, x - width/2, y - h/2);
2216 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2218 break;
2220 case ButtonPress:
2221 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2222 XSync(dpy, 0);
2223 *x_ret = x - width/2;
2224 *y_ret = y - h/2;
2225 XUngrabPointer(dpy, CurrentTime);
2226 XUngrabKeyboard(dpy, CurrentTime);
2227 /* get rid of the geometry window */
2228 unmapPositionDisplay(wwin);
2229 return;
2231 default:
2232 WMHandleEvent(&event);
2233 break;