Changes relate to virtual edge.
[wmaker-crm.git] / src / moveres.c
blobf0fac049738304cfc28d1eba1a63ef0bae384df1
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 "geomview.h"
46 #ifdef KWM_HINTS
47 #include "kwm.h"
48 #endif
50 /* How many different types of geometry/position
51 display thingies are there? */
52 #define NUM_DISPLAYS 4
54 #define LEFT 1
55 #define RIGHT 2
56 #define HORIZONTAL (LEFT|RIGHT)
57 #define UP 4
58 #define DOWN 8
59 #define VERTICAL (UP|DOWN)
61 /****** Global Variables ******/
62 extern Time LastTimestamp;
64 extern Cursor wCursor[WCUR_LAST];
66 extern WPreferences wPreferences;
68 extern Atom _XA_WM_PROTOCOLS;
73 *----------------------------------------------------------------------
74 * checkMouseSamplingRate-
75 * For lowering the mouse motion sampling rate for machines where
76 * it's too high (SGIs). If it returns False then the event should be
77 * ignored.
78 *----------------------------------------------------------------------
80 static Bool
81 checkMouseSamplingRate(XEvent *ev)
83 static Time previousMotion = 0;
85 if (ev->type == MotionNotify) {
86 if (ev->xmotion.time - previousMotion < DELAY_BETWEEN_MOUSE_SAMPLING) {
87 return False;
88 } else {
89 previousMotion = ev->xmotion.time;
92 return True;
98 *----------------------------------------------------------------------
99 * moveGeometryDisplayCentered
101 * routine that moves the geometry/position window on scr so it is
102 * centered over the given coordinates (x,y). Also the window position
103 * is clamped so it stays on the screen at all times.
104 *----------------------------------------------------------------------
106 static void
107 moveGeometryDisplayCentered(WScreen *scr, int x, int y)
109 unsigned int w = WMWidgetWidth(scr->gview);
110 unsigned int h = WMWidgetHeight(scr->gview);
112 x -= w / 2;
113 y -= h / 2;
115 if (x < 1)
116 x = 1;
117 else if (x > (scr->scr_width - w - 3))
118 x = scr->scr_width - w - 3;
120 if (y < 1)
121 y = 1;
122 else if (y > (scr->scr_height - h - 3))
123 y = scr->scr_height - h - 3;
125 WMMoveWidget(scr->gview, x, y);
129 static void
130 showPosition(WWindow *wwin, int x, int y)
132 WScreen *scr = wwin->screen_ptr;
134 if (wPreferences.move_display == WDIS_NEW) {
135 #if 0
136 int width = wwin->frame->core->width;
137 int height = wwin->frame->core->height;
139 GC lgc = scr->line_gc;
140 XSetForeground(dpy, lgc, scr->line_pixel);
141 sprintf(num, "%i", x);
143 XDrawLine(dpy, scr->root_win, lgc, 0, y-1, scr->scr_width, y-1);
144 XDrawLine(dpy, scr->root_win, lgc, 0, y+height+2, scr->scr_width,
145 y+height+2);
146 XDrawLine(dpy, scr->root_win, lgc, x-1, 0, x-1, scr->scr_height);
147 XDrawLine(dpy, scr->root_win, lgc, x+width+2, 0, x+width+2,
148 scr->scr_height);
149 #endif
150 } else {
151 #ifdef VIRTUAL_DESKTOP
152 WSetGeometryViewShownPosition(scr->gview,
153 x + scr->workspaces[scr->current_workspace]->view_x,
154 y + scr->workspaces[scr->current_workspace]->view_y);
155 #else
156 WSetGeometryViewShownPosition(scr->gview, x, y);
157 #endif
162 static void
163 cyclePositionDisplay(WWindow *wwin, int x, int y, int w, int h)
165 WScreen *scr = wwin->screen_ptr;
167 wPreferences.move_display++;
168 wPreferences.move_display %= NUM_DISPLAYS;
170 if (wPreferences.move_display == WDIS_NEW) {
171 WMUnmapWidget(scr->gview);
172 } else {
173 if (wPreferences.move_display == WDIS_CENTER) {
174 moveGeometryDisplayCentered(scr,
175 scr->scr_width/2, scr->scr_height/2);
176 } else if (wPreferences.move_display == WDIS_TOPLEFT) {
177 moveGeometryDisplayCentered(scr, 1, 1);
178 } else if (wPreferences.move_display == WDIS_FRAME_CENTER) {
179 moveGeometryDisplayCentered(scr, x + w/2, y + h/2);
181 WMMapWidget(scr->gview);
186 static void
187 mapPositionDisplay(WWindow *wwin, int x, int y, int w, int h)
189 WScreen *scr = wwin->screen_ptr;
191 if (wPreferences.move_display == WDIS_NEW) {
192 return;
193 } else if (wPreferences.move_display == WDIS_CENTER) {
194 moveGeometryDisplayCentered(scr, scr->scr_width / 2,
195 scr->scr_height / 2);
196 } else if (wPreferences.move_display == WDIS_TOPLEFT) {
197 moveGeometryDisplayCentered(scr, 1, 1);
198 } else if (wPreferences.move_display == WDIS_FRAME_CENTER) {
199 moveGeometryDisplayCentered(scr, x + w/2, y + h/2);
201 WMMapWidget(scr->gview);
202 WSetGeometryViewShownPosition(scr->gview, x, y);
206 static void
207 showGeometry(WWindow *wwin, int x1, int y1, int x2, int y2, int direction)
209 WScreen *scr = wwin->screen_ptr;
210 Window root = scr->root_win;
211 GC gc = scr->line_gc;
212 int ty, by, my, x, y, mx, s;
213 char num[16];
214 XSegment segment[4];
215 int fw, fh;
217 ty = y1 + wwin->frame->top_width;
218 by = y2 - wwin->frame->bottom_width;
219 fw = WMWidthOfString(scr->info_text_font, "8888", 4);
220 fh = WMFontHeight(scr->info_text_font);
222 if (wPreferences.size_display == WDIS_NEW) {
223 XSetForeground(dpy, gc, scr->line_pixel);
225 /* vertical geometry */
226 if (((direction & LEFT) && (x2 < scr->scr_width - fw)) || (x1 < fw)) {
227 x = x2;
228 s = -15;
229 } else {
230 x = x1;
231 s = 15;
233 my = (ty + by) / 2;
235 /* top arrow */
236 /* end bar */
237 segment[0].x1 = x - (s + 6); segment[0].y1 = ty;
238 segment[0].x2 = x - (s - 10); segment[0].y2 = ty;
240 /* arrowhead */
241 segment[1].x1 = x - (s - 2); segment[1].y1 = ty + 1;
242 segment[1].x2 = x - (s - 5); segment[1].y2 = ty + 7;
244 segment[2].x1 = x - (s - 2); segment[2].y1 = ty + 1;
245 segment[2].x2 = x - (s + 1); segment[2].y2 = ty + 7;
247 /* line */
248 segment[3].x1 = x - (s - 2); segment[3].y1 = ty + 1;
249 segment[3].x2 = x - (s - 2); segment[3].y2 = my - fh/2 - 1;
251 XDrawSegments(dpy, root, gc, segment, 4);
253 /* bottom arrow */
254 /* end bar */
255 segment[0].y1 = by;
256 segment[0].y2 = by;
258 /* arrowhead */
259 segment[1].y1 = by - 1;
260 segment[1].y2 = by - 7;
262 segment[2].y1 = by - 1;
263 segment[2].y2 = by - 7;
265 /* line */
266 segment[3].y1 = my + fh/2 + 2;
267 segment[3].y2 = by - 1;
269 XDrawSegments(dpy, root, gc, segment, 4);
271 sprintf(num, "%i", (by - ty - wwin->normal_hints->base_height) /
272 wwin->normal_hints->height_inc);
273 fw = WMWidthOfString(scr->info_text_font, num, strlen(num));
275 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
277 /* Display the height. */
278 WMDrawString(scr->wmscreen, root, gc, scr->info_text_font,
279 x - s + 3 - fw/2, my - fh/2 + 1, num, strlen(num));
280 XSetForeground(dpy, gc, scr->line_pixel);
281 /* horizontal geometry */
282 if (y1 < 15) {
283 y = y2;
284 s = -15;
285 } else {
286 y = y1;
287 s = 15;
289 mx = x1 + (x2 - x1)/2;
290 sprintf(num, "%i", (x2 - x1 - wwin->normal_hints->base_width) /
291 wwin->normal_hints->width_inc);
292 fw = WMWidthOfString(scr->info_text_font, num, strlen(num));
294 /* left arrow */
295 /* end bar */
296 segment[0].x1 = x1; segment[0].y1 = y - (s + 6);
297 segment[0].x2 = x1; segment[0].y2 = y - (s - 10);
299 /* arrowhead */
300 segment[1].x1 = x1 + 7; segment[1].y1 = y - (s + 1);
301 segment[1].x2 = x1 + 1; segment[1].y2 = y - (s - 2);
303 segment[2].x1 = x1 + 1; segment[2].y1 = y - (s - 2);
304 segment[2].x2 = x1 + 7; segment[2].y2 = y - (s - 5);
306 /* line */
307 segment[3].x1 = x1 + 1; segment[3].y1 = y - (s - 2);
308 segment[3].x2 = mx - fw/2 - 2; segment[3].y2 = y - (s - 2);
310 XDrawSegments(dpy, root, gc, segment, 4);
312 /* right arrow */
313 /* end bar */
314 segment[0].x1 = x2 + 1;
315 segment[0].x2 = x2 + 1;
317 /* arrowhead */
318 segment[1].x1 = x2 - 6;
319 segment[1].x2 = x2;
321 segment[2].x1 = x2;
322 segment[2].x2 = x2 - 6;
324 /* line */
325 segment[3].x1 = mx + fw/2 + 2;
326 segment[3].x2 = x2;
328 XDrawSegments(dpy, root, gc, segment, 4);
330 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
332 /* Display the width. */
333 WMDrawString(scr->wmscreen, root, gc, scr->info_text_font,
334 mx - fw/2 + 1, y - s - fh/2 + 1, num, strlen(num));
335 } else {
336 WSetGeometryViewShownSize(scr->gview,
337 (x2 - x1 - wwin->normal_hints->base_width)
338 / wwin->normal_hints->width_inc,
339 (by - ty - wwin->normal_hints->base_height)
340 / wwin->normal_hints->height_inc);
345 static void
346 cycleGeometryDisplay(WWindow *wwin, int x, int y, int w, int h, int dir)
348 WScreen *scr = wwin->screen_ptr;
350 wPreferences.size_display++;
351 wPreferences.size_display %= NUM_DISPLAYS;
353 if (wPreferences.size_display == WDIS_NEW) {
354 WMUnmapWidget(scr->gview);
355 } else {
356 if (wPreferences.size_display == WDIS_CENTER) {
357 moveGeometryDisplayCentered(scr,
358 scr->scr_width / 2, scr->scr_height / 2);
359 } else if (wPreferences.size_display == WDIS_TOPLEFT) {
360 moveGeometryDisplayCentered(scr, 1, 1);
361 } else if (wPreferences.size_display == WDIS_FRAME_CENTER) {
362 moveGeometryDisplayCentered(scr, x + w/2, y + h/2);
364 WMMapWidget(scr->gview);
365 showGeometry(wwin, x, y, x + w, y + h, dir);
370 static void
371 mapGeometryDisplay(WWindow *wwin, int x, int y, int w, int h)
373 WScreen *scr = wwin->screen_ptr;
375 if (wPreferences.size_display == WDIS_NEW)
376 return;
378 if (wPreferences.size_display == WDIS_CENTER) {
379 moveGeometryDisplayCentered(scr, scr->scr_width / 2,
380 scr->scr_height / 2);
381 } else if (wPreferences.size_display == WDIS_TOPLEFT) {
382 moveGeometryDisplayCentered(scr, 1, 1);
383 } else if (wPreferences.size_display == WDIS_FRAME_CENTER) {
384 moveGeometryDisplayCentered(scr, x + w/2, y + h/2);
386 WMMapWidget(scr->gview);
387 showGeometry(wwin, x, y, x + w, y + h, 0);
392 static void
393 doWindowMove(WWindow *wwin, WMBag *bag, int dx, int dy)
395 WWindow *tmpw;
396 int x, y;
397 int scr_width = wwin->screen_ptr->scr_width;
398 int scr_height = wwin->screen_ptr->scr_height;
400 if (!bag || !WMGetBagItemCount(bag)) {
401 wWindowMove(wwin, wwin->frame_x + dx, wwin->frame_y + dy);
402 } else {
403 int i;
404 for (i = 0; i < WMGetBagItemCount(bag); i++) {
405 tmpw = WMGetFromBag(bag, i);
406 x = tmpw->frame_x + dx;
407 y = tmpw->frame_y + dy;
409 /* don't let windows become unreachable */
411 if (x + (int)tmpw->frame->core->width < 20)
412 x = 20 - (int)tmpw->frame->core->width;
413 else if (x + 20 > scr_width)
414 x = scr_width - 20;
416 if (y + (int)tmpw->frame->core->height < 20)
417 y = 20 - (int)tmpw->frame->core->height;
418 else if (y + 20 > scr_height)
419 y = scr_height - 20;
421 wWindowMove(tmpw, x, y);
427 static void
428 drawTransparentFrame(WWindow *wwin, int x, int y, int width, int height)
430 Window root = wwin->screen_ptr->root_win;
431 GC gc = wwin->screen_ptr->frame_gc;
432 int h = 0;
433 int bottom = 0;
435 if (!WFLAGP(wwin, no_titlebar) && !wwin->flags.shaded) {
436 h = WMFontHeight(wwin->screen_ptr->title_font) + (wPreferences.window_title_clearance + TITLEBAR_EXTEND_SPACE) * 2;
438 if (!WFLAGP(wwin, no_resizebar) && !wwin->flags.shaded) {
439 /* Can't use wwin-frame->bottom_width because, in some cases
440 (e.g. interactive placement), frame does not point to anything. */
441 bottom = RESIZEBAR_HEIGHT - 1;
443 XDrawRectangle(dpy, root, gc, x, y, width + 1, height + 1);
445 if (h > 0) {
446 XDrawLine(dpy, root, gc, x + 1, y + h, x + width + 1, y + h);
448 if (bottom > 0) {
449 XDrawLine(dpy, root, gc, x + 1,
450 y + height - bottom,
451 x + width + 1,
452 y + height - bottom);
457 static void
458 drawFrames(WWindow *wwin, WMBag *bag, int dx, int dy)
460 WWindow *tmpw;
461 int scr_width = wwin->screen_ptr->scr_width;
462 int scr_height = wwin->screen_ptr->scr_height;
463 int x, y;
465 if (!bag) {
467 x = wwin->frame_x + dx;
468 y = wwin->frame_y + dy;
470 drawTransparentFrame(wwin, x, y,
471 wwin->frame->core->width,
472 wwin->frame->core->height);
474 } else {
475 int i;
476 for (i = 0; i < WMGetBagItemCount(bag); i++) {
477 tmpw = WMGetFromBag(bag, i);
478 x = tmpw->frame_x + dx;
479 y = tmpw->frame_y + dy;
481 /* don't let windows become unreachable */
483 if (x + (int)tmpw->frame->core->width < 20)
484 x = 20 - (int)tmpw->frame->core->width;
485 else if (x + 20 > scr_width)
486 x = scr_width - 20;
488 if (y + (int)tmpw->frame->core->height < 20)
489 y = 20 - (int)tmpw->frame->core->height;
490 else if (y + 20 > scr_height)
491 y = scr_height - 20;
493 drawTransparentFrame(tmpw, x, y, tmpw->frame->core->width,
494 tmpw->frame->core->height);
501 static void
502 flushMotion()
504 XEvent ev;
506 XSync(dpy, False);
507 while (XCheckMaskEvent(dpy, ButtonMotionMask, &ev)) ;
511 static void
512 crossWorkspace(WScreen *scr, WWindow *wwin, int opaque_move,
513 int new_workspace, int rewind)
515 /* do not let window be unmapped */
516 if (opaque_move) {
517 wwin->flags.changing_workspace = 1;
518 wWindowChangeWorkspace(wwin, new_workspace);
520 /* go to new workspace */
521 wWorkspaceChange(scr, new_workspace);
523 wwin->flags.changing_workspace = 0;
525 if (rewind)
526 XWarpPointer(dpy, None, None, 0, 0, 0, 0, scr->scr_width - 20, 0);
527 else
528 XWarpPointer(dpy, None, None, 0, 0, 0, 0, -(scr->scr_width - 20), 0);
530 flushMotion();
532 if (!opaque_move) {
533 XGrabPointer(dpy, scr->root_win, True, PointerMotionMask
534 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
535 GrabModeAsync, None, wCursor[WCUR_MOVE], CurrentTime);
542 typedef struct {
543 /* arrays of WWindows sorted by the respective border position */
544 WWindow **topList; /* top border */
545 WWindow **leftList; /* left border */
546 WWindow **rightList; /* right border */
547 WWindow **bottomList; /* bottom border */
548 int count;
550 /* index of window in the above lists indicating the relative position
551 * of the window with the others */
552 int topIndex;
553 int leftIndex;
554 int rightIndex;
555 int bottomIndex;
557 int rubCount; /* for workspace switching */
559 int winWidth, winHeight; /* width/height of the window */
560 int realX, realY; /* actual position of the window */
561 int calcX, calcY; /* calculated position of window */
562 int omouseX, omouseY; /* old mouse position */
563 int mouseX, mouseY; /* last known position of the pointer */
564 } MoveData;
566 #define WTOP(w) (w)->frame_y
567 #define WLEFT(w) (w)->frame_x
568 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width + FRAME_BORDER_WIDTH)
569 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height + FRAME_BORDER_WIDTH)
571 static int
572 compareWTop(const void *a, const void *b)
574 WWindow *wwin1 = *(WWindow**)a;
575 WWindow *wwin2 = *(WWindow**)b;
577 if (WTOP(wwin1) > WTOP(wwin2))
578 return -1;
579 else if (WTOP(wwin1) < WTOP(wwin2))
580 return 1;
581 else
582 return 0;
586 static int
587 compareWLeft(const void *a, const void *b)
589 WWindow *wwin1 = *(WWindow**)a;
590 WWindow *wwin2 = *(WWindow**)b;
592 if (WLEFT(wwin1) > WLEFT(wwin2))
593 return -1;
594 else if (WLEFT(wwin1) < WLEFT(wwin2))
595 return 1;
596 else
597 return 0;
601 static int
602 compareWRight(const void *a, const void *b)
604 WWindow *wwin1 = *(WWindow**)a;
605 WWindow *wwin2 = *(WWindow**)b;
607 if (WRIGHT(wwin1) < WRIGHT(wwin2))
608 return -1;
609 else if (WRIGHT(wwin1) > WRIGHT(wwin2))
610 return 1;
611 else
612 return 0;
617 static int
618 compareWBottom(const void *a, const void *b)
620 WWindow *wwin1 = *(WWindow**)a;
621 WWindow *wwin2 = *(WWindow**)b;
623 if (WBOTTOM(wwin1) < WBOTTOM(wwin2))
624 return -1;
625 else if (WBOTTOM(wwin1) > WBOTTOM(wwin2))
626 return 1;
627 else
628 return 0;
632 static void
633 updateResistance(WWindow *wwin, MoveData *data, int newX, int newY)
635 int i;
636 int newX2 = newX + data->winWidth;
637 int newY2 = newY + data->winHeight;
638 Bool ok = False;
640 if (newX < data->realX) {
641 if (data->rightIndex > 0
642 && newX < WRIGHT(data->rightList[data->rightIndex-1])) {
643 ok = True;
644 } else if (data->leftIndex <= data->count-1
645 && newX2 <= WLEFT(data->leftList[data->leftIndex])) {
646 ok = True;
648 } else if (newX > data->realX) {
649 if (data->leftIndex > 0
650 && newX2 > WLEFT(data->leftList[data->leftIndex-1])) {
651 ok = True;
652 } else if (data->rightIndex <= data->count-1
653 && newX >= WRIGHT(data->rightList[data->rightIndex])) {
654 ok = True;
658 if (!ok) {
659 if (newY < data->realY) {
660 if (data->bottomIndex > 0
661 && newY < WBOTTOM(data->bottomList[data->bottomIndex-1])) {
662 ok = True;
663 } else if (data->topIndex <= data->count-1
664 && newY2 <= WTOP(data->topList[data->topIndex])) {
665 ok = True;
667 } else if (newY > data->realY) {
668 if (data->topIndex > 0
669 && newY2 > WTOP(data->topList[data->topIndex-1])) {
670 ok = True;
671 } else if (data->bottomIndex <= data->count-1
672 && newY >= WBOTTOM(data->bottomList[data->bottomIndex])) {
673 ok = True;
678 if (!ok)
679 return;
681 /* TODO: optimize this */
682 if (data->realY < WBOTTOM(data->bottomList[0])) {
683 data->bottomIndex = 0;
685 if (data->realX < WRIGHT(data->rightList[0])) {
686 data->rightIndex = 0;
688 if ((data->realX + data->winWidth) > WLEFT(data->leftList[0])) {
689 data->leftIndex = 0;
691 if ((data->realY + data->winHeight) > WTOP(data->topList[0])) {
692 data->topIndex = 0;
694 for (i = 0; i < data->count; i++) {
695 if (data->realY > WBOTTOM(data->bottomList[i])) {
696 data->bottomIndex = i + 1;
698 if (data->realX > WRIGHT(data->rightList[i])) {
699 data->rightIndex = i + 1;
701 if ((data->realX + data->winWidth) < WLEFT(data->leftList[i])) {
702 data->leftIndex = i + 1;
704 if ((data->realY + data->winHeight) < WTOP(data->topList[i])) {
705 data->topIndex = i + 1;
711 static void
712 freeMoveData(MoveData *data)
714 if (data->topList)
715 wfree(data->topList);
716 if (data->leftList)
717 wfree(data->leftList);
718 if (data->rightList)
719 wfree(data->rightList);
720 if (data->bottomList)
721 wfree(data->bottomList);
725 static void
726 updateMoveData(WWindow *wwin, MoveData *data)
728 WScreen *scr = wwin->screen_ptr;
729 WWindow *tmp;
730 int i;
732 data->count = 0;
733 tmp = scr->focused_window;
734 while (tmp) {
735 if (tmp != wwin && scr->current_workspace == tmp->frame->workspace
736 && !tmp->flags.miniaturized
737 && !tmp->flags.hidden
738 && !tmp->flags.obscured
739 && !WFLAGP(tmp, sunken)) {
740 data->topList[data->count] = tmp;
741 data->leftList[data->count] = tmp;
742 data->rightList[data->count] = tmp;
743 data->bottomList[data->count] = tmp;
744 data->count++;
746 tmp = tmp->prev;
749 if (data->count == 0) {
750 data->topIndex = 0;
751 data->leftIndex = 0;
752 data->rightIndex = 0;
753 data->bottomIndex = 0;
754 return;
758 * order from closest to the border of the screen to farthest
760 qsort(data->topList, data->count, sizeof(WWindow**), compareWTop);
761 qsort(data->leftList, data->count, sizeof(WWindow**), compareWLeft);
762 qsort(data->rightList, data->count, sizeof(WWindow**), compareWRight);
763 qsort(data->bottomList, data->count, sizeof(WWindow**), compareWBottom);
765 /* figure the position of the window relative to the others */
767 data->topIndex = -1;
768 data->leftIndex = -1;
769 data->rightIndex = -1;
770 data->bottomIndex = -1;
772 if (WTOP(wwin) < WBOTTOM(data->bottomList[0])) {
773 data->bottomIndex = 0;
775 if (WLEFT(wwin) < WRIGHT(data->rightList[0])) {
776 data->rightIndex = 0;
778 if (WRIGHT(wwin) > WLEFT(data->leftList[0])) {
779 data->leftIndex = 0;
781 if (WBOTTOM(wwin) > WTOP(data->topList[0])) {
782 data->topIndex = 0;
784 for (i = 0; i < data->count; i++) {
785 if (WTOP(wwin) >= WBOTTOM(data->bottomList[i])) {
786 data->bottomIndex = i + 1;
788 if (WLEFT(wwin) >= WRIGHT(data->rightList[i])) {
789 data->rightIndex = i + 1;
791 if (WRIGHT(wwin) <= WLEFT(data->leftList[i])) {
792 data->leftIndex = i + 1;
794 if (WBOTTOM(wwin) <= WTOP(data->topList[i])) {
795 data->topIndex = i + 1;
801 static void
802 initMoveData(WWindow *wwin, MoveData *data)
804 int i;
805 WWindow *tmp;
807 memset(data, 0, sizeof(MoveData));
809 for (i = 0, tmp = wwin->screen_ptr->focused_window;
810 tmp != NULL;
811 tmp = tmp->prev, i++);
813 if (i > 1) {
814 data->topList = wmalloc(sizeof(WWindow*) * i);
815 data->leftList = wmalloc(sizeof(WWindow*) * i);
816 data->rightList = wmalloc(sizeof(WWindow*) * i);
817 data->bottomList = wmalloc(sizeof(WWindow*) * i);
819 updateMoveData(wwin, data);
822 data->realX = wwin->frame_x;
823 data->realY = wwin->frame_y;
824 data->calcX = wwin->frame_x;
825 data->calcY = wwin->frame_y;
827 data->winWidth = wwin->frame->core->width + 2;
828 data->winHeight = wwin->frame->core->height + 2;
832 static Bool
833 checkWorkspaceChange(WWindow *wwin, MoveData *data, Bool opaqueMove)
835 WScreen *scr = wwin->screen_ptr;
836 Bool changed = False;
838 if (data->mouseX <= 1) {
839 if (scr->current_workspace > 0) {
841 crossWorkspace(scr, wwin, opaqueMove, scr->current_workspace - 1,
842 True);
843 changed = True;
844 data->rubCount = 0;
846 } else if (scr->current_workspace == 0 && wPreferences.ws_cycle) {
848 crossWorkspace(scr, wwin, opaqueMove, scr->workspace_count - 1,
849 True);
850 changed = True;
851 data->rubCount = 0;
853 } else if (data->mouseX >= scr->scr_width - 2) {
855 if (scr->current_workspace == scr->workspace_count - 1) {
857 if (wPreferences.ws_cycle
858 || scr->workspace_count == MAX_WORKSPACES) {
860 crossWorkspace(scr, wwin, opaqueMove, 0, False);
861 changed = True;
862 data->rubCount = 0;
864 /* if user insists on trying to go to next workspace even when
865 * it's already the last, create a new one */
866 else if (data->omouseX == data->mouseX
867 && wPreferences.ws_advance) {
869 /* detect user "rubbing" the window against the edge */
870 if (data->rubCount > 0
871 && data->omouseY - data->mouseY > MOVE_THRESHOLD) {
873 data->rubCount = -(data->rubCount + 1);
875 } else if (data->rubCount <= 0
876 && data->mouseY - data->omouseY > MOVE_THRESHOLD) {
878 data->rubCount = -data->rubCount + 1;
881 /* create a new workspace */
882 if (abs(data->rubCount) > 2) {
883 /* go to next workspace */
884 wWorkspaceNew(scr);
886 crossWorkspace(scr, wwin, opaqueMove,
887 scr->current_workspace+1, False);
888 changed = True;
889 data->rubCount = 0;
891 } else if (scr->current_workspace < scr->workspace_count) {
893 /* go to next workspace */
894 crossWorkspace(scr, wwin, opaqueMove,
895 scr->current_workspace+1, False);
896 changed = True;
897 data->rubCount = 0;
899 } else {
900 data->rubCount = 0;
903 return changed;
907 static void
908 updateWindowPosition(WWindow *wwin, MoveData *data, Bool doResistance,
909 Bool opaqueMove, int newMouseX, int newMouseY)
911 WScreen *scr = wwin->screen_ptr;
912 int dx, dy; /* how much mouse moved */
913 int winL, winR, winT, winB; /* requested new window position */
914 int newX, newY; /* actual new window position */
915 Bool hresist, vresist;
916 Bool updateIndex;
917 Bool attract;
919 hresist = False;
920 vresist = False;
922 updateIndex = False;
924 /* check the direction of the movement */
925 dx = newMouseX - data->mouseX;
926 dy = newMouseY - data->mouseY;
928 data->omouseX = data->mouseX;
929 data->omouseY = data->mouseY;
930 data->mouseX = newMouseX;
931 data->mouseY = newMouseY;
933 winL = data->calcX + dx;
934 winR = data->calcX + data->winWidth + dx;
935 winT = data->calcY + dy;
936 winB = data->calcY + data->winHeight + dy;
938 newX = data->realX;
939 newY = data->realY;
941 if (doResistance) {
942 int l_edge, r_edge;
943 int edge_l, edge_r;
944 int t_edge, b_edge;
945 int edge_t, edge_b;
946 int resist;
948 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
949 attract = wPreferences.attract;
950 /* horizontal movement: check horizontal edge resistances */
951 if (dx || dy) {
952 int i;
953 /* window is the leftmost window: check against screen edge */
954 l_edge = scr->totalUsableArea.x1;
955 r_edge = scr->totalUsableArea.x2 + resist;
956 edge_l = scr->totalUsableArea.x1 - resist;
957 edge_r = scr->totalUsableArea.x2;
959 /* 1 */
960 if ((data->rightIndex >= 0) && (data->rightIndex <= data->count)) {
961 WWindow *looprw;
963 for (i = data->rightIndex - 1; i >= 0; i--) {
964 looprw = data->rightList[i];
965 if (!(data->realY > WBOTTOM(looprw)
966 || (data->realY + data->winHeight) < WTOP(looprw))) {
967 if (attract
968 || ((data->realX < (WRIGHT(looprw) + 2)) && dx < 0)) {
969 l_edge = WRIGHT(looprw) + 1;
970 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
972 break;
976 if (attract) {
977 for (i = data->rightIndex; i < data->count; i++) {
978 looprw = data->rightList[i];
979 if(!(data->realY > WBOTTOM(looprw)
980 || (data->realY + data->winHeight) < WTOP(looprw))) {
981 r_edge = WRIGHT(looprw) + 1;
982 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
983 break;
989 if ((data->leftIndex >= 0) && (data->leftIndex <= data->count)) {
990 WWindow *looprw;
992 for (i = data->leftIndex - 1; i >= 0; i--) {
993 looprw = data->leftList[i];
994 if (!(data->realY > WBOTTOM(looprw)
995 || (data->realY + data->winHeight) < WTOP(looprw))) {
996 if (attract
997 || (((data->realX + data->winWidth) > (WLEFT(looprw) - 1)) && dx > 0)) {
998 edge_r = WLEFT(looprw);
999 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1001 break;
1005 if (attract)
1006 for (i = data->leftIndex; i < data->count; i++) {
1007 looprw = data->leftList[i];
1008 if(!(data->realY > WBOTTOM(looprw)
1009 || (data->realY + data->winHeight) < WTOP(looprw))) {
1010 edge_l = WLEFT(looprw);
1011 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1012 break;
1018 printf("%d %d\n",winL,winR);
1019 printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);
1022 if ((winL - l_edge) < (r_edge - winL)) {
1023 if (resist > 0) {
1024 if ((attract && winL <= l_edge + resist && winL >= l_edge - resist)
1025 || (dx < 0 && winL <= l_edge && winL >= l_edge - resist)) {
1026 newX = l_edge;
1027 hresist = True;
1030 } else {
1031 if (resist > 0 && attract && winL >= r_edge - resist && winL <= r_edge + resist) {
1032 newX = r_edge;
1033 hresist = True;
1037 if ((winR - edge_l) < (edge_r - winR)) {
1038 if (resist > 0 && attract && winR <= edge_l + resist && winR >= edge_l - resist) {
1039 newX = edge_l - data->winWidth;
1040 hresist = True;
1042 } else {
1043 if (resist > 0) {
1044 if ((attract && winR >= edge_r - resist && winR <= edge_r + resist)
1045 || (dx > 0 && winR >= edge_r && winR <= edge_r + resist)) {
1046 newX = edge_r - data->winWidth;
1047 hresist = True;
1052 /* VeRT */
1053 t_edge = scr->totalUsableArea.y1;
1054 b_edge = scr->totalUsableArea.y2 + resist;
1055 edge_t = scr->totalUsableArea.y1 - resist;
1056 edge_b = scr->totalUsableArea.y2;
1058 if ((data->bottomIndex >= 0) && (data->bottomIndex <= data->count)) {
1059 WWindow *looprw;
1061 for (i = data->bottomIndex - 1; i >= 0; i--) {
1062 looprw = data->bottomList[i];
1063 if (!(data->realX > WRIGHT(looprw)
1064 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1065 if (attract
1066 || ((data->realY < (WBOTTOM(looprw) + 2)) && dy < 0)) {
1067 t_edge = WBOTTOM(looprw) + 1;
1068 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1070 break;
1074 if (attract) {
1075 for (i = data->bottomIndex; i < data->count; i++) {
1076 looprw = data->bottomList[i];
1077 if(!(data->realX > WRIGHT(looprw)
1078 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1079 b_edge = WBOTTOM(looprw) + 1;
1080 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1081 break;
1087 if ((data->topIndex >= 0) && (data->topIndex <= data->count)) {
1088 WWindow *looprw;
1090 for (i = data->topIndex - 1; i >= 0; i--) {
1091 looprw = data->topList[i];
1092 if (!(data->realX > WRIGHT(looprw)
1093 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1094 if (attract
1095 || (((data->realY + data->winHeight) > (WTOP(looprw) - 1)) && dy > 0)) {
1096 edge_b = WTOP(looprw);
1097 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1099 break;
1103 if (attract)
1104 for (i = data->topIndex; i < data->count; i++) {
1105 looprw = data->topList[i];
1106 if(!(data->realX > WRIGHT(looprw)
1107 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1108 edge_t = WTOP(looprw);
1109 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1110 break;
1115 if ((winT - t_edge) < (b_edge - winT)) {
1116 if (resist > 0) {
1117 if ((attract && winT <= t_edge + resist && winT >= t_edge - resist)
1118 || (dy < 0 && winT <= t_edge && winT >= t_edge - resist)) {
1119 newY = t_edge;
1120 vresist = True;
1124 else {
1125 if (resist > 0 && attract && winT >= b_edge - resist && winT <= b_edge + resist) {
1126 newY = b_edge;
1127 vresist = True;
1131 if ((winB - edge_t) < (edge_b - winB)) {
1132 if (resist > 0 && attract && winB <= edge_t + resist && winB >= edge_t - resist) {
1133 newY = edge_t - data->winHeight;
1134 vresist = True;
1137 else {
1138 if (resist > 0) {
1139 if ((attract && winB >= edge_b - resist && winB <= edge_b + resist)
1140 || (dy > 0 && winB >= edge_b && winB <= edge_b + resist)) {
1141 newY = edge_b - data->winHeight;
1142 vresist = True;
1147 /* END VeRT */
1151 /* update window position */
1152 data->calcX += dx;
1153 data->calcY += dy;
1155 if (((dx > 0 && data->calcX - data->realX > 0)
1156 || (dx < 0 && data->calcX - data->realX < 0)) && !hresist)
1157 newX = data->calcX;
1159 if (((dy > 0 && data->calcY - data->realY > 0)
1160 || (dy < 0 && data->calcY - data->realY < 0)) && !vresist)
1161 newY = data->calcY;
1163 if (data->realX != newX || data->realY != newY) {
1165 if (wPreferences.move_display == WDIS_NEW
1166 && !scr->selected_windows) {
1167 showPosition(wwin, data->realX, data->realY);
1169 if (opaqueMove) {
1170 doWindowMove(wwin, scr->selected_windows,
1171 newX - wwin->frame_x,
1172 newY - wwin->frame_y);
1173 } else {
1174 /* erase frames */
1175 drawFrames(wwin, scr->selected_windows,
1176 data->realX - wwin->frame_x,
1177 data->realY - wwin->frame_y);
1180 if (!scr->selected_windows
1181 && wPreferences.move_display == WDIS_FRAME_CENTER) {
1183 moveGeometryDisplayCentered(scr, newX + data->winWidth/2,
1184 newY + data->winHeight/2);
1187 if (!opaqueMove) {
1188 /* draw frames */
1189 drawFrames(wwin, scr->selected_windows,
1190 newX - wwin->frame_x,
1191 newY - wwin->frame_y);
1194 if (!scr->selected_windows) {
1195 showPosition(wwin, newX, newY);
1200 /* recalc relative window position */
1201 if (doResistance && (data->realX != newX || data->realY != newY)) {
1202 updateResistance(wwin, data, newX, newY);
1205 data->realX = newX;
1206 data->realY = newY;
1210 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1213 wKeyboardMoveResizeWindow(WWindow *wwin)
1215 WScreen *scr = wwin->screen_ptr;
1216 Window root = scr->root_win;
1217 XEvent event;
1218 int w = wwin->frame->core->width;
1219 int h = wwin->frame->core->height;
1220 int scr_width = wwin->screen_ptr->scr_width;
1221 int scr_height = wwin->screen_ptr->scr_height;
1222 int vert_border = wwin->frame->top_width + wwin->frame->bottom_width;
1223 int src_x = wwin->frame_x;
1224 int src_y = wwin->frame_y;
1225 int done,off_x,off_y,ww,wh;
1226 int kspeed = _KS;
1227 Time lastTime = 0;
1228 KeySym keysym=NoSymbol;
1229 int moment=0;
1230 KeyCode shiftl,shiftr,ctrll,ctrlmode;
1232 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1233 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1234 ctrll = XKeysymToKeycode(dpy, XK_Control_L);
1235 ctrlmode=done=off_x=off_y=0;
1237 XSync(dpy, False);
1238 wusleep(10000);
1239 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync, CurrentTime);
1241 if (!wwin->flags.selected) {
1242 wUnselectWindows(scr);
1244 XGrabServer(dpy);
1245 XGrabPointer(dpy, scr->root_win, True, PointerMotionMask
1246 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
1247 GrabModeAsync, None, wCursor[WCUR_DEFAULT], CurrentTime);
1249 if (wwin->flags.shaded || scr->selected_windows) {
1250 if(scr->selected_windows)
1251 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1252 else drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1253 if(!scr->selected_windows)
1254 mapPositionDisplay(wwin, src_x, src_y, w, h);
1255 } else {
1256 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1258 ww=w;
1259 wh=h;
1260 while(1) {
1262 looper.ox=off_x;
1263 looper.oy=off_y;
1265 WMMaskEvent(dpy, KeyPressMask | ButtonReleaseMask
1266 | ButtonPressMask | ExposureMask, &event);
1267 if (wwin->flags.shaded || scr->selected_windows) {
1268 if(scr->selected_windows)
1269 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1270 else drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1271 /*** I HATE EDGE RESISTANCE - ]d ***/
1273 else {
1274 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, ww, wh);
1277 if(ctrlmode)
1278 showGeometry(wwin, src_x+off_x, src_y+off_y, src_x+off_x+ww, src_y+off_y+wh,0);
1280 XUngrabServer(dpy);
1281 XSync(dpy, False);
1283 switch (event.type) {
1284 case KeyPress:
1285 /* accelerate */
1286 if (event.xkey.time - lastTime > 50) {
1287 kspeed/=(1 + (event.xkey.time - lastTime)/100);
1288 } else {
1289 if (kspeed < 20) {
1290 kspeed++;
1293 if (kspeed < _KS) kspeed = _KS;
1294 lastTime = event.xkey.time;
1296 if (event.xkey.state & ControlMask && !wwin->flags.shaded) {
1297 ctrlmode=1;
1298 wUnselectWindows(scr);
1300 else {
1301 ctrlmode=0;
1303 if (event.xkey.keycode == shiftl || event.xkey.keycode == shiftr) {
1304 if (ctrlmode)
1305 cycleGeometryDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh, 0);
1306 else
1307 cyclePositionDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh);
1309 else {
1311 keysym = XLookupKeysym(&event.xkey, 0);
1312 switch (keysym) {
1313 case XK_Return:
1314 done=2;
1315 break;
1316 case XK_Escape:
1317 done=1;
1318 break;
1319 case XK_Up:
1320 #ifdef XK_KP_Up
1321 case XK_KP_Up:
1322 #endif
1323 case XK_k:
1324 if (ctrlmode){
1325 if (moment != UP)
1326 h = wh;
1327 h-=kspeed;
1328 moment = UP;
1329 if (h < 1) h = 1;
1331 else off_y-=kspeed;
1332 break;
1333 case XK_Down:
1334 #ifdef XK_KP_Down
1335 case XK_KP_Down:
1336 #endif
1337 case XK_j:
1338 if (ctrlmode){
1339 if (moment != DOWN)
1340 h = wh;
1341 h+=kspeed;
1342 moment = DOWN;
1344 else off_y+=kspeed;
1345 break;
1346 case XK_Left:
1347 #ifdef XK_KP_Left
1348 case XK_KP_Left:
1349 #endif
1350 case XK_h:
1351 if (ctrlmode) {
1352 if (moment != LEFT)
1353 w = ww;
1354 w-=kspeed;
1355 if (w < 1) w = 1;
1356 moment = LEFT;
1358 else off_x-=kspeed;
1359 break;
1360 case XK_Right:
1361 #ifdef XK_KP_Right
1362 case XK_KP_Right:
1363 #endif
1364 case XK_l:
1365 if (ctrlmode) {
1366 if (moment != RIGHT)
1367 w = ww;
1368 w+=kspeed;
1369 moment = RIGHT;
1371 else off_x+=kspeed;
1372 break;
1375 ww=w;wh=h;
1376 wh-=vert_border;
1377 wWindowConstrainSize(wwin, &ww, &wh);
1378 wh+=vert_border;
1380 if (wPreferences.ws_cycle){
1381 if (src_x + off_x + ww < 20){
1382 if(!scr->current_workspace) {
1383 wWorkspaceChange(scr, scr->workspace_count-1);
1385 else wWorkspaceChange(scr, scr->current_workspace-1);
1386 off_x += scr_width;
1388 else if (src_x + off_x + 20 > scr_width){
1389 if(scr->current_workspace == scr->workspace_count-1) {
1390 wWorkspaceChange(scr, 0);
1392 else wWorkspaceChange(scr, scr->current_workspace+1);
1393 off_x -= scr_width;
1396 else {
1397 if (src_x + off_x + ww < 20)
1398 off_x = 20 - ww - src_x;
1399 else if (src_x + off_x + 20 > scr_width)
1400 off_x = scr_width - 20 - src_x;
1403 if (src_y + off_y + wh < 20) {
1404 off_y = 20 - wh - src_y;
1406 else if (src_y + off_y + 20 > scr_height) {
1407 off_y = scr_height - 20 - src_y;
1410 break;
1411 case ButtonPress:
1412 case ButtonRelease:
1413 done=1;
1414 break;
1415 default:
1416 WMHandleEvent(&event);
1417 break;
1420 XGrabServer(dpy);
1421 /*xxx*/
1423 if (wwin->flags.shaded && !scr->selected_windows){
1424 moveGeometryDisplayCentered(scr, src_x+off_x + w/2, src_y+off_y + h/2);
1425 } else {
1426 if (ctrlmode) {
1427 WMUnmapWidget(scr->gview);
1428 mapGeometryDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh);
1429 } else if(!scr->selected_windows) {
1430 WMUnmapWidget(scr->gview);
1431 mapPositionDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh);
1435 if (wwin->flags.shaded || scr->selected_windows) {
1436 if (scr->selected_windows)
1437 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1438 else
1439 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1440 } else {
1441 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, ww, wh);
1445 if (ctrlmode) {
1446 showGeometry(wwin, src_x+off_x, src_y+off_y, src_x+off_x+ww, src_y+off_y+wh,0);
1447 } else if(!scr->selected_windows)
1448 showPosition(wwin, src_x+off_x, src_y+off_y);
1449 /**/
1451 if(done){
1452 scr->keymove_tick=0;
1454 WMDeleteTimerWithClientData(&looper);
1456 if (wwin->flags.shaded || scr->selected_windows) {
1457 if(scr->selected_windows)
1458 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1459 else drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1461 else {
1462 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, ww, wh);
1465 if (ctrlmode) {
1466 showGeometry(wwin, src_x+off_x, src_y+off_y, src_x+off_x+ww, src_y+off_y+wh,0);
1467 WMUnmapWidget(scr->gview);
1468 } else
1469 WMUnmapWidget(scr->gview);
1471 XUngrabKeyboard(dpy, CurrentTime);
1472 XUngrabPointer(dpy, CurrentTime);
1473 XUngrabServer(dpy);
1475 if(done==2) {
1476 if (wwin->flags.shaded || scr->selected_windows) {
1477 if (!scr->selected_windows) {
1478 wWindowMove(wwin, src_x+off_x, src_y+off_y);
1479 wWindowSynthConfigureNotify(wwin);
1480 } else {
1481 int i;
1482 WMBag *bag = scr->selected_windows;
1483 doWindowMove(wwin,scr->selected_windows,off_x,off_y);
1484 for (i = 0; i < WMGetBagItemCount(bag); i++) {
1485 wWindowSynthConfigureNotify(WMGetFromBag(bag, i));
1488 } else {
1489 if (wwin->client.width != ww)
1490 wwin->flags.user_changed_width = 1;
1492 if (wwin->client.height != wh - vert_border)
1493 wwin->flags.user_changed_height = 1;
1495 wWindowConfigure(wwin, src_x+off_x, src_y+off_y,
1496 ww, wh - vert_border);
1497 wWindowSynthConfigureNotify(wwin);
1499 wWindowChangeWorkspace(wwin, scr->current_workspace);
1500 wSetFocusTo(scr, wwin);
1502 return 1;
1509 *----------------------------------------------------------------------
1510 * wMouseMoveWindow--
1511 * Move the named window and the other selected ones (if any),
1512 * interactively. Also shows the position of the window, if only one
1513 * window is being moved.
1514 * If the window is not on the selected window list, the selected
1515 * windows are deselected.
1516 * If shift is pressed during the operation, the position display
1517 * is changed to another type.
1519 * Returns:
1520 * True if the window was moved, False otherwise.
1522 * Side effects:
1523 * The window(s) position is changed, and the client(s) are
1524 * notified about that.
1525 * The position display configuration may be changed.
1526 *----------------------------------------------------------------------
1529 wMouseMoveWindow(WWindow *wwin, XEvent *ev)
1531 WScreen *scr = wwin->screen_ptr;
1532 XEvent event;
1533 Window root = scr->root_win;
1534 KeyCode shiftl, shiftr;
1535 Bool done = False;
1536 int started = 0;
1537 int warped = 0;
1538 /* This needs not to change while moving, else bad things can happen */
1539 int opaqueMove = wPreferences.opaque_move;
1540 MoveData moveData;
1541 #ifdef GHOST_WINDOW_MOVE
1542 RImage *rimg;
1544 rimg = InitGhostWindowMove(scr);
1545 #endif
1548 if (wPreferences.opaque_move && !wPreferences.use_saveunders) {
1549 XSetWindowAttributes attr;
1551 attr.save_under = True;
1552 XChangeWindowAttributes(dpy, wwin->frame->core->window,
1553 CWSaveUnder, &attr);
1557 initMoveData(wwin, &moveData);
1559 moveData.mouseX = ev->xmotion.x_root;
1560 moveData.mouseY = ev->xmotion.y_root;
1562 if (!wwin->flags.selected) {
1563 /* this window is not selected, unselect others and move only wwin */
1564 wUnselectWindows(scr);
1566 #ifdef DEBUG
1567 puts("Moving window");
1568 #endif
1569 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1570 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1571 while (!done) {
1572 if (warped) {
1573 int junk;
1574 Window junkw;
1576 /* XWarpPointer() doesn't seem to generate Motion events, so
1577 we've got to simulate them */
1578 XQueryPointer(dpy, root, &junkw, &junkw, &event.xmotion.x_root,
1579 &event.xmotion.y_root, &junk, &junk,
1580 (unsigned *) &junk);
1581 } else {
1582 WMMaskEvent(dpy, KeyPressMask | ButtonMotionMask
1583 | PointerMotionHintMask
1584 | ButtonReleaseMask | ButtonPressMask | ExposureMask,
1585 &event);
1587 if (event.type == MotionNotify) {
1588 /* compress MotionNotify events */
1589 while (XCheckMaskEvent(dpy, ButtonMotionMask, &event)) ;
1590 if (!checkMouseSamplingRate(&event))
1591 continue;
1594 switch (event.type) {
1595 case KeyPress:
1596 if ((event.xkey.keycode == shiftl || event.xkey.keycode == shiftr)
1597 && started && !scr->selected_windows) {
1599 if (!opaqueMove) {
1600 drawFrames(wwin, scr->selected_windows,
1601 moveData.realX - wwin->frame_x,
1602 moveData.realY - wwin->frame_y);
1605 if (wPreferences.move_display == WDIS_NEW
1606 && !scr->selected_windows) {
1607 showPosition(wwin, moveData.realX, moveData.realY);
1608 XUngrabServer(dpy);
1610 cyclePositionDisplay(wwin, moveData.realX, moveData.realY,
1611 moveData.winWidth, moveData.winHeight);
1613 if (wPreferences.move_display == WDIS_NEW
1614 && !scr->selected_windows) {
1615 XGrabServer(dpy);
1616 showPosition(wwin, moveData.realX, moveData.realY);
1619 if (!opaqueMove) {
1620 drawFrames(wwin, scr->selected_windows,
1621 moveData.realX - wwin->frame_x,
1622 moveData.realY - wwin->frame_y);
1625 break;
1627 case MotionNotify:
1628 if (started) {
1629 updateWindowPosition(wwin, &moveData,
1630 scr->selected_windows == NULL
1631 && wPreferences.edge_resistance > 0,
1632 opaqueMove,
1633 event.xmotion.x_root,
1634 event.xmotion.y_root);
1636 if (!warped && !wPreferences.no_autowrap) {
1637 int oldWorkspace = scr->current_workspace;
1639 if (wPreferences.move_display == WDIS_NEW
1640 && !scr->selected_windows) {
1641 showPosition(wwin, moveData.realX, moveData.realY);
1642 XUngrabServer(dpy);
1644 if (!opaqueMove) {
1645 drawFrames(wwin, scr->selected_windows,
1646 moveData.realX - wwin->frame_x,
1647 moveData.realY - wwin->frame_y);
1649 if (checkWorkspaceChange(wwin, &moveData, opaqueMove)) {
1650 if (scr->current_workspace != oldWorkspace
1651 && wPreferences.edge_resistance > 0
1652 && scr->selected_windows == NULL)
1653 updateMoveData(wwin, &moveData);
1654 warped = 1;
1656 if (!opaqueMove) {
1657 drawFrames(wwin, scr->selected_windows,
1658 moveData.realX - wwin->frame_x,
1659 moveData.realY - wwin->frame_y);
1661 if (wPreferences.move_display == WDIS_NEW
1662 && !scr->selected_windows) {
1663 XSync(dpy, False);
1664 showPosition(wwin, moveData.realX, moveData.realY);
1665 XGrabServer(dpy);
1667 } else {
1668 warped = 0;
1670 } else if (abs(ev->xmotion.x_root - event.xmotion.x_root) >= MOVE_THRESHOLD
1671 || abs(ev->xmotion.y_root - event.xmotion.y_root) >= MOVE_THRESHOLD) {
1673 XChangeActivePointerGrab(dpy, ButtonMotionMask
1674 | ButtonReleaseMask | ButtonPressMask,
1675 wCursor[WCUR_MOVE], CurrentTime);
1676 started = 1;
1677 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync,
1678 CurrentTime);
1680 if (!scr->selected_windows)
1681 mapPositionDisplay(wwin, moveData.realX, moveData.realY,
1682 moveData.winWidth, moveData.winHeight);
1684 if (started && !opaqueMove)
1685 drawFrames(wwin, scr->selected_windows, 0, 0);
1687 if (!opaqueMove || (wPreferences.move_display==WDIS_NEW
1688 && !scr->selected_windows)) {
1689 XGrabServer(dpy);
1690 if (wPreferences.move_display==WDIS_NEW)
1691 showPosition(wwin, moveData.realX, moveData.realY);
1694 break;
1696 case ButtonPress:
1697 break;
1699 case ButtonRelease:
1700 if (event.xbutton.button != ev->xbutton.button)
1701 break;
1703 if (started) {
1704 XEvent e;
1705 if (!opaqueMove) {
1706 drawFrames(wwin, scr->selected_windows,
1707 moveData.realX - wwin->frame_x,
1708 moveData.realY - wwin->frame_y);
1709 XSync(dpy, 0);
1710 doWindowMove(wwin, scr->selected_windows,
1711 moveData.realX - wwin->frame_x,
1712 moveData.realY - wwin->frame_y);
1714 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1715 wWindowSynthConfigureNotify(wwin);
1716 #endif
1717 XUngrabKeyboard(dpy, CurrentTime);
1718 XUngrabServer(dpy);
1719 if (!opaqueMove) {
1720 wWindowChangeWorkspace(wwin, scr->current_workspace);
1721 wSetFocusTo(scr, wwin);
1723 if (wPreferences.move_display == WDIS_NEW)
1724 showPosition(wwin, moveData.realX, moveData.realY);
1726 /* discard all enter/leave events that happened until
1727 * the time the button was released */
1728 while (XCheckTypedEvent(dpy, EnterNotify, &e)) {
1729 if (e.xcrossing.time > event.xbutton.time) {
1730 XPutBackEvent(dpy, &e);
1731 break;
1734 while (XCheckTypedEvent(dpy, LeaveNotify, &e)) {
1735 if (e.xcrossing.time > event.xbutton.time) {
1736 XPutBackEvent(dpy, &e);
1737 break;
1741 if (!scr->selected_windows) {
1742 /* get rid of the geometry window */
1743 WMUnmapWidget(scr->gview);
1746 #ifdef DEBUG
1747 puts("End move window");
1748 #endif
1749 done = True;
1750 break;
1752 default:
1753 if (started && !opaqueMove) {
1754 drawFrames(wwin, scr->selected_windows,
1755 moveData.realX - wwin->frame_x,
1756 moveData.realY - wwin->frame_y);
1757 XUngrabServer(dpy);
1758 WMHandleEvent(&event);
1759 XSync(dpy, False);
1760 XGrabServer(dpy);
1761 drawFrames(wwin, scr->selected_windows,
1762 moveData.realX - wwin->frame_x,
1763 moveData.realY - wwin->frame_y);
1764 } else {
1765 WMHandleEvent(&event);
1767 break;
1771 if (wPreferences.opaque_move && !wPreferences.use_saveunders) {
1772 XSetWindowAttributes attr;
1775 attr.save_under = False;
1776 XChangeWindowAttributes(dpy, wwin->frame->core->window,
1777 CWSaveUnder, &attr);
1781 freeMoveData(&moveData);
1783 return started;
1787 #define RESIZEBAR 1
1788 #define HCONSTRAIN 2
1790 static int
1791 getResizeDirection(WWindow *wwin, int x, int y, int dx, int dy,
1792 int flags)
1794 int w = wwin->frame->core->width - 1;
1795 int cw = wwin->frame->resizebar_corner_width;
1796 int dir;
1798 /* if not resizing through the resizebar */
1799 if (!(flags & RESIZEBAR)) {
1800 int xdir = (abs(x) < (wwin->client.width/2)) ? LEFT : RIGHT;
1801 int ydir = (abs(y) < (wwin->client.height/2)) ? UP : DOWN;
1802 if (abs(dx) < 2 || abs(dy) < 2) {
1803 if (abs(dy) > abs(dx))
1804 xdir = 0;
1805 else
1806 ydir = 0;
1808 return (xdir | ydir);
1811 /* window is too narrow. allow diagonal resize */
1812 if (cw * 2 >= w) {
1813 int ydir;
1815 if (flags & HCONSTRAIN)
1816 ydir = 0;
1817 else
1818 ydir = DOWN;
1819 if (x < cw)
1820 return (LEFT | ydir);
1821 else
1822 return (RIGHT | ydir);
1824 /* vertical resize */
1825 if ((x > cw) && (x < w - cw))
1826 return DOWN;
1828 if (x < cw)
1829 dir = LEFT;
1830 else
1831 dir = RIGHT;
1833 if ((abs(dy) > 0) && !(flags & HCONSTRAIN))
1834 dir |= DOWN;
1836 return dir;
1840 void
1841 wMouseResizeWindow(WWindow *wwin, XEvent *ev)
1843 XEvent event;
1844 WScreen *scr = wwin->screen_ptr;
1845 Window root = scr->root_win;
1846 int vert_border = wwin->frame->top_width + wwin->frame->bottom_width;
1847 int fw = wwin->frame->core->width;
1848 int fh = wwin->frame->core->height;
1849 int fx = wwin->frame_x;
1850 int fy = wwin->frame_y;
1851 int is_resizebar = (wwin->frame->resizebar
1852 && ev->xany.window==wwin->frame->resizebar->window);
1853 int orig_x, orig_y;
1854 int started;
1855 int dw, dh;
1856 int rw = fw, rh = fh;
1857 int rx1, ry1, rx2, ry2;
1858 int res = 0;
1859 KeyCode shiftl, shiftr;
1860 int h = 0;
1861 int orig_fx = fx;
1862 int orig_fy = fy;
1863 int orig_fw = fw;
1864 int orig_fh = fh;
1866 if (wwin->flags.shaded) {
1867 wwarning("internal error: tryein");
1868 return;
1870 orig_x = ev->xbutton.x_root;
1871 orig_y = ev->xbutton.y_root;
1873 started = 0;
1874 #ifdef DEBUG
1875 puts("Resizing window");
1876 #endif
1878 wUnselectWindows(scr);
1879 rx1 = fx;
1880 rx2 = fx + fw - 1;
1881 ry1 = fy;
1882 ry2 = fy + fh - 1;
1883 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1884 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1885 if (!WFLAGP(wwin, no_titlebar))
1886 h = WMFontHeight(wwin->screen_ptr->title_font) + (wPreferences.window_title_clearance + TITLEBAR_EXTEND_SPACE) * 2;
1887 else
1888 h = 0;
1889 while (1) {
1890 WMMaskEvent(dpy, KeyPressMask | ButtonMotionMask
1891 | ButtonReleaseMask | PointerMotionHintMask
1892 | ButtonPressMask | ExposureMask, &event);
1893 if (!checkMouseSamplingRate(&event))
1894 continue;
1896 switch (event.type) {
1897 case KeyPress:
1898 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1899 if ((event.xkey.keycode == shiftl || event.xkey.keycode == shiftr)
1900 && started) {
1901 drawTransparentFrame(wwin, fx, fy, fw, fh);
1902 cycleGeometryDisplay(wwin, fx, fy, fw, fh, res);
1903 drawTransparentFrame(wwin, fx, fy, fw, fh);
1905 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1906 break;
1908 case MotionNotify:
1909 if (started) {
1910 while (XCheckMaskEvent(dpy, ButtonMotionMask, &event)) ;
1912 dw = 0;
1913 dh = 0;
1915 orig_fx = fx;
1916 orig_fy = fy;
1917 orig_fw = fw;
1918 orig_fh = fh;
1920 if (res & LEFT)
1921 dw = orig_x - event.xmotion.x_root;
1922 else if (res & RIGHT)
1923 dw = event.xmotion.x_root - orig_x;
1924 if (res & UP)
1925 dh = orig_y - event.xmotion.y_root;
1926 else if (res & DOWN)
1927 dh = event.xmotion.y_root - orig_y;
1929 orig_x = event.xmotion.x_root;
1930 orig_y = event.xmotion.y_root;
1932 rw += dw;
1933 rh += dh;
1934 fw = rw;
1935 fh = rh - vert_border;
1936 wWindowConstrainSize(wwin, &fw, &fh);
1937 fh += vert_border;
1938 if (res & LEFT)
1939 fx = rx2 - fw + 1;
1940 else if (res & RIGHT)
1941 fx = rx1;
1942 if (res & UP)
1943 fy = ry2 - fh + 1;
1944 else if (res & DOWN)
1945 fy = ry1;
1946 } else if (abs(orig_x - event.xmotion.x_root) >= MOVE_THRESHOLD
1947 || abs(orig_y - event.xmotion.y_root) >= MOVE_THRESHOLD) {
1948 int tx, ty;
1949 Window junkw;
1950 int flags;
1952 XTranslateCoordinates(dpy, root, wwin->frame->core->window,
1953 orig_x, orig_y, &tx, &ty, &junkw);
1955 /* check if resizing through resizebar */
1956 if (is_resizebar)
1957 flags = RESIZEBAR;
1958 else
1959 flags = 0;
1961 if (is_resizebar && ((ev->xbutton.state & ShiftMask)
1962 || abs(orig_y - event.xmotion.y_root) < HRESIZE_THRESHOLD))
1963 flags |= HCONSTRAIN;
1965 res = getResizeDirection(wwin, tx, ty,
1966 orig_x - event.xmotion.x_root,
1967 orig_y - event.xmotion.y_root, flags);
1969 if (res == (UP|LEFT))
1970 XChangeActivePointerGrab(dpy, ButtonMotionMask
1971 | ButtonReleaseMask | ButtonPressMask,
1972 wCursor[WCUR_TOPLEFTRESIZE], CurrentTime);
1973 else if (res == (UP|RIGHT))
1974 XChangeActivePointerGrab(dpy, ButtonMotionMask
1975 | ButtonReleaseMask | ButtonPressMask,
1976 wCursor[WCUR_TOPRIGHTRESIZE], CurrentTime);
1977 else if (res == (DOWN|LEFT))
1978 XChangeActivePointerGrab(dpy, ButtonMotionMask
1979 | ButtonReleaseMask | ButtonPressMask,
1980 wCursor[WCUR_BOTTOMLEFTRESIZE], CurrentTime);
1981 else if (res == (DOWN|RIGHT))
1982 XChangeActivePointerGrab(dpy, ButtonMotionMask
1983 | ButtonReleaseMask | ButtonPressMask,
1984 wCursor[WCUR_BOTTOMRIGHTRESIZE], CurrentTime);
1985 else if (res == DOWN || res == UP)
1986 XChangeActivePointerGrab(dpy, ButtonMotionMask
1987 | ButtonReleaseMask | ButtonPressMask,
1988 wCursor[WCUR_VERTICALRESIZE], CurrentTime);
1989 else if (res & (DOWN|UP))
1990 XChangeActivePointerGrab(dpy, ButtonMotionMask
1991 | ButtonReleaseMask | ButtonPressMask,
1992 wCursor[WCUR_VERTICALRESIZE], CurrentTime);
1993 else if (res & (LEFT|RIGHT))
1994 XChangeActivePointerGrab(dpy, ButtonMotionMask
1995 | ButtonReleaseMask | ButtonPressMask,
1996 wCursor[WCUR_HORIZONRESIZE], CurrentTime);
1998 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync,
1999 CurrentTime);
2001 XGrabServer(dpy);
2003 /* Draw the resize frame for the first time. */
2004 mapGeometryDisplay(wwin, fx, fy, fw, fh);
2006 drawTransparentFrame(wwin, fx, fy, fw, fh);
2008 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
2010 started = 1;
2012 if (started) {
2013 if (wPreferences.size_display == WDIS_FRAME_CENTER) {
2014 drawTransparentFrame(wwin, orig_fx, orig_fy,
2015 orig_fw, orig_fh);
2016 moveGeometryDisplayCentered(scr, fx + fw / 2, fy + fh / 2);
2017 drawTransparentFrame(wwin, fx, fy, fw, fh);
2018 } else {
2019 drawTransparentFrame(wwin, orig_fx, orig_fy,
2020 orig_fw, orig_fh);
2021 drawTransparentFrame(wwin, fx, fy, fw, fh);
2023 if (fh != orig_fh || fw != orig_fw) {
2024 if (wPreferences.size_display == WDIS_NEW) {
2025 showGeometry(wwin, orig_fx, orig_fy, orig_fx + orig_fw,
2026 orig_fy + orig_fh, res);
2028 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
2031 break;
2033 case ButtonPress:
2034 break;
2036 case ButtonRelease:
2037 if (event.xbutton.button != ev->xbutton.button)
2038 break;
2040 if (started) {
2041 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
2043 drawTransparentFrame(wwin, fx, fy, fw, fh);
2045 XUngrabKeyboard(dpy, CurrentTime);
2046 WMUnmapWidget(scr->gview);
2047 XUngrabServer(dpy);
2049 if (wwin->client.width != fw)
2050 wwin->flags.user_changed_width = 1;
2052 if (wwin->client.height != fh - vert_border)
2053 wwin->flags.user_changed_height = 1;
2055 wWindowConfigure(wwin, fx, fy, fw, fh - vert_border);
2057 #ifdef DEBUG
2058 puts("End resize window");
2059 #endif
2060 return;
2062 default:
2063 WMHandleEvent(&event);
2068 #undef LEFT
2069 #undef RIGHT
2070 #undef HORIZONTAL
2071 #undef UP
2072 #undef DOWN
2073 #undef VERTICAL
2074 #undef HCONSTRAIN
2075 #undef RESIZEBAR
2077 void
2078 wUnselectWindows(WScreen *scr)
2080 WWindow *wwin;
2082 if (!scr->selected_windows)
2083 return;
2085 while (WMGetBagItemCount(scr->selected_windows)) {
2086 WMBagIterator dummy;
2088 wwin = WMBagFirst(scr->selected_windows, &dummy);
2089 if (wwin->flags.miniaturized && wwin->icon && wwin->icon->selected)
2090 wIconSelect(wwin->icon);
2092 wSelectWindow(wwin, False);
2094 WMFreeBag(scr->selected_windows);
2095 scr->selected_windows = NULL;
2098 #ifndef LITE
2099 static void
2100 selectWindowsInside(WScreen *scr, int x1, int y1, int x2, int y2)
2102 WWindow *tmpw;
2104 /* select the windows and put them in the selected window list */
2105 tmpw = scr->focused_window;
2106 while (tmpw != NULL) {
2107 if (!(tmpw->flags.miniaturized || tmpw->flags.hidden)) {
2108 if ((tmpw->frame->workspace == scr->current_workspace
2109 || IS_OMNIPRESENT(tmpw))
2110 && (tmpw->frame_x >= x1) && (tmpw->frame_y >= y1)
2111 && (tmpw->frame->core->width + tmpw->frame_x <= x2)
2112 && (tmpw->frame->core->height + tmpw->frame_y <= y2)) {
2113 wSelectWindow(tmpw, True);
2116 tmpw = tmpw->prev;
2121 void
2122 wSelectWindows(WScreen *scr, XEvent *ev)
2124 XEvent event;
2125 Window root = scr->root_win;
2126 GC gc = scr->frame_gc;
2127 int xp = ev->xbutton.x_root;
2128 int yp = ev->xbutton.y_root;
2129 int w = 0, h = 0;
2130 int x = xp, y = yp;
2132 #ifdef DEBUG
2133 puts("Selecting windows");
2134 #endif
2135 if (XGrabPointer(dpy, scr->root_win, False, ButtonMotionMask
2136 | ButtonReleaseMask | ButtonPressMask, GrabModeAsync,
2137 GrabModeAsync, None, wCursor[WCUR_DEFAULT],
2138 CurrentTime) != Success) {
2139 return;
2141 XGrabServer(dpy);
2143 wUnselectWindows(scr);
2145 XDrawRectangle(dpy, root, gc, xp, yp, w, h);
2146 while (1) {
2147 WMMaskEvent(dpy, ButtonReleaseMask | PointerMotionMask
2148 | ButtonPressMask, &event);
2150 switch (event.type) {
2151 case MotionNotify:
2152 XDrawRectangle(dpy, root, gc, x, y, w, h);
2153 x = event.xmotion.x_root;
2154 if (x < xp) {
2155 w = xp - x;
2156 } else {
2157 w = x - xp;
2158 x = xp;
2160 y = event.xmotion.y_root;
2161 if (y < yp) {
2162 h = yp - y;
2163 } else {
2164 h = y - yp;
2165 y = yp;
2167 XDrawRectangle(dpy, root, gc, x, y, w, h);
2168 break;
2170 case ButtonPress:
2171 break;
2173 case ButtonRelease:
2174 if (event.xbutton.button != ev->xbutton.button)
2175 break;
2177 XDrawRectangle(dpy, root, gc, x, y, w, h);
2178 XUngrabServer(dpy);
2179 XUngrabPointer(dpy, CurrentTime);
2180 selectWindowsInside(scr, x, y, x + w, y + h);
2182 #ifdef KWM_HINTS
2183 wKWMSelectRootRegion(scr, xp, yp, w, h,
2184 event.xbutton.state & ControlMask);
2185 #endif /* KWM_HINTS */
2187 #ifdef DEBUG
2188 puts("End window selection");
2189 #endif
2190 return;
2192 default:
2193 WMHandleEvent(&event);
2194 break;
2198 #endif /* !LITE */
2200 void
2201 InteractivePlaceWindow(WWindow *wwin, int *x_ret, int *y_ret,
2202 unsigned width, unsigned height)
2204 WScreen *scr = wwin->screen_ptr;
2205 Window root = scr->root_win;
2206 int x, y, h = 0;
2207 XEvent event;
2208 KeyCode shiftl, shiftr;
2209 Window junkw;
2210 int junk;
2212 if (XGrabPointer(dpy, root, True, PointerMotionMask | ButtonPressMask,
2213 GrabModeAsync, GrabModeAsync, None,
2214 wCursor[WCUR_DEFAULT], CurrentTime) != Success) {
2215 *x_ret = 0;
2216 *y_ret = 0;
2217 return;
2219 if (!WFLAGP(wwin, no_titlebar)) {
2220 h = WMFontHeight(scr->title_font) + (wPreferences.window_title_clearance + TITLEBAR_EXTEND_SPACE) * 2;
2221 height += h;
2223 if (!WFLAGP(wwin, no_resizebar)) {
2224 height += RESIZEBAR_HEIGHT;
2226 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync, CurrentTime);
2227 XQueryPointer(dpy, root, &junkw, &junkw, &x, &y, &junk, &junk,
2228 (unsigned *) &junk);
2229 mapPositionDisplay(wwin, x - width/2, y - h/2, width, height);
2231 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2233 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
2234 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
2235 while (1) {
2236 WMMaskEvent(dpy, PointerMotionMask|ButtonPressMask|ExposureMask|KeyPressMask,
2237 &event);
2239 if (!checkMouseSamplingRate(&event))
2240 continue;
2242 switch (event.type) {
2243 case KeyPress:
2244 if ((event.xkey.keycode == shiftl)
2245 || (event.xkey.keycode == shiftr)) {
2246 drawTransparentFrame(wwin,
2247 x - width/2, y - h/2, width, height);
2248 cyclePositionDisplay(wwin,
2249 x - width/2, y - h/2, width, height);
2250 drawTransparentFrame(wwin,
2251 x - width/2, y - h/2, width, height);
2253 break;
2255 case MotionNotify:
2256 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2258 x = event.xmotion.x_root;
2259 y = event.xmotion.y_root;
2261 if (wPreferences.move_display == WDIS_FRAME_CENTER)
2262 moveGeometryDisplayCentered(scr, x, y + (height - h) / 2);
2264 showPosition(wwin, x - width/2, y - h/2);
2266 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2268 break;
2270 case ButtonPress:
2271 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2272 XSync(dpy, 0);
2273 *x_ret = x - width/2;
2274 *y_ret = y - h/2;
2275 XUngrabPointer(dpy, CurrentTime);
2276 XUngrabKeyboard(dpy, CurrentTime);
2277 /* get rid of the geometry window */
2278 WMUnmapWidget(scr->gview);
2279 return;
2281 default:
2282 WMHandleEvent(&event);
2283 break;