fixed bugs in configure.in, removed
[wmaker-crm.git] / src / moveres.c
blobe323e56d56ad3477b884b45d0323ac18a8d487fe
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 do {
1266 WMMaskEvent(dpy, KeyPressMask | ButtonReleaseMask
1267 | ButtonPressMask | ExposureMask, &event);
1268 if (event.type == Expose) {
1269 WMHandleEvent(&event);
1271 } while (event.type == Expose);
1274 if (wwin->flags.shaded || scr->selected_windows) {
1275 if(scr->selected_windows)
1276 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1277 else drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1278 /*** I HATE EDGE RESISTANCE - ]d ***/
1280 else {
1281 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, ww, wh);
1284 if(ctrlmode)
1285 showGeometry(wwin, src_x+off_x, src_y+off_y, src_x+off_x+ww, src_y+off_y+wh,0);
1287 XUngrabServer(dpy);
1288 XSync(dpy, False);
1290 switch (event.type) {
1291 case KeyPress:
1292 /* accelerate */
1293 if (event.xkey.time - lastTime > 50) {
1294 kspeed/=(1 + (event.xkey.time - lastTime)/100);
1295 } else {
1296 if (kspeed < 20) {
1297 kspeed++;
1300 if (kspeed < _KS) kspeed = _KS;
1301 lastTime = event.xkey.time;
1303 if (event.xkey.state & ControlMask && !wwin->flags.shaded) {
1304 ctrlmode=1;
1305 wUnselectWindows(scr);
1307 else {
1308 ctrlmode=0;
1310 if (event.xkey.keycode == shiftl || event.xkey.keycode == shiftr) {
1311 if (ctrlmode)
1312 cycleGeometryDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh, 0);
1313 else
1314 cyclePositionDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh);
1316 else {
1318 keysym = XLookupKeysym(&event.xkey, 0);
1319 switch (keysym) {
1320 case XK_Return:
1321 done=2;
1322 break;
1323 case XK_Escape:
1324 done=1;
1325 break;
1326 case XK_Up:
1327 #ifdef XK_KP_Up
1328 case XK_KP_Up:
1329 #endif
1330 case XK_k:
1331 if (ctrlmode){
1332 if (moment != UP)
1333 h = wh;
1334 h-=kspeed;
1335 moment = UP;
1336 if (h < 1) h = 1;
1338 else off_y-=kspeed;
1339 break;
1340 case XK_Down:
1341 #ifdef XK_KP_Down
1342 case XK_KP_Down:
1343 #endif
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 #ifdef XK_KP_Left
1355 case XK_KP_Left:
1356 #endif
1357 case XK_h:
1358 if (ctrlmode) {
1359 if (moment != LEFT)
1360 w = ww;
1361 w-=kspeed;
1362 if (w < 1) w = 1;
1363 moment = LEFT;
1365 else off_x-=kspeed;
1366 break;
1367 case XK_Right:
1368 #ifdef XK_KP_Right
1369 case XK_KP_Right:
1370 #endif
1371 case XK_l:
1372 if (ctrlmode) {
1373 if (moment != RIGHT)
1374 w = ww;
1375 w+=kspeed;
1376 moment = RIGHT;
1378 else off_x+=kspeed;
1379 break;
1382 ww=w;wh=h;
1383 wh-=vert_border;
1384 wWindowConstrainSize(wwin, &ww, &wh);
1385 wh+=vert_border;
1387 if (wPreferences.ws_cycle){
1388 if (src_x + off_x + ww < 20){
1389 if(!scr->current_workspace) {
1390 wWorkspaceChange(scr, scr->workspace_count-1);
1392 else wWorkspaceChange(scr, scr->current_workspace-1);
1393 off_x += scr_width;
1395 else if (src_x + off_x + 20 > scr_width){
1396 if(scr->current_workspace == scr->workspace_count-1) {
1397 wWorkspaceChange(scr, 0);
1399 else wWorkspaceChange(scr, scr->current_workspace+1);
1400 off_x -= scr_width;
1403 else {
1404 if (src_x + off_x + ww < 20)
1405 off_x = 20 - ww - src_x;
1406 else if (src_x + off_x + 20 > scr_width)
1407 off_x = scr_width - 20 - src_x;
1410 if (src_y + off_y + wh < 20) {
1411 off_y = 20 - wh - src_y;
1413 else if (src_y + off_y + 20 > scr_height) {
1414 off_y = scr_height - 20 - src_y;
1417 break;
1418 case ButtonPress:
1419 case ButtonRelease:
1420 done=1;
1421 break;
1422 case Expose:
1423 WMHandleEvent(&event);
1424 while (XCheckTypedEvent(dpy, Expose, &event)) {
1425 WMHandleEvent(&event);
1427 break;
1429 default:
1430 WMHandleEvent(&event);
1431 break;
1434 XGrabServer(dpy);
1435 /*xxx*/
1437 if (wwin->flags.shaded && !scr->selected_windows){
1438 moveGeometryDisplayCentered(scr, src_x+off_x + w/2, src_y+off_y + h/2);
1439 } else {
1440 if (ctrlmode) {
1441 WMUnmapWidget(scr->gview);
1442 mapGeometryDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh);
1443 } else if(!scr->selected_windows) {
1444 WMUnmapWidget(scr->gview);
1445 mapPositionDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh);
1449 if (wwin->flags.shaded || scr->selected_windows) {
1450 if (scr->selected_windows)
1451 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1452 else
1453 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1454 } else {
1455 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, ww, wh);
1459 if (ctrlmode) {
1460 showGeometry(wwin, src_x+off_x, src_y+off_y, src_x+off_x+ww, src_y+off_y+wh,0);
1461 } else if(!scr->selected_windows)
1462 showPosition(wwin, src_x+off_x, src_y+off_y);
1463 /**/
1465 if (done) {
1466 scr->keymove_tick=0;
1468 WMDeleteTimerWithClientData(&looper);
1470 if (wwin->flags.shaded || scr->selected_windows) {
1471 if(scr->selected_windows)
1472 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1473 else drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1475 else {
1476 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, ww, wh);
1479 if (ctrlmode) {
1480 showGeometry(wwin, src_x+off_x, src_y+off_y, src_x+off_x+ww, src_y+off_y+wh,0);
1481 WMUnmapWidget(scr->gview);
1482 } else
1483 WMUnmapWidget(scr->gview);
1485 XUngrabKeyboard(dpy, CurrentTime);
1486 XUngrabPointer(dpy, CurrentTime);
1487 XUngrabServer(dpy);
1489 if(done==2) {
1490 if (wwin->flags.shaded || scr->selected_windows) {
1491 if (!scr->selected_windows) {
1492 wWindowMove(wwin, src_x+off_x, src_y+off_y);
1493 wWindowSynthConfigureNotify(wwin);
1494 } else {
1495 int i;
1496 WMBag *bag = scr->selected_windows;
1497 doWindowMove(wwin,scr->selected_windows,off_x,off_y);
1498 for (i = 0; i < WMGetBagItemCount(bag); i++) {
1499 wWindowSynthConfigureNotify(WMGetFromBag(bag, i));
1502 } else {
1503 if (wwin->client.width != ww)
1504 wwin->flags.user_changed_width = 1;
1506 if (wwin->client.height != wh - vert_border)
1507 wwin->flags.user_changed_height = 1;
1509 wWindowConfigure(wwin, src_x+off_x, src_y+off_y,
1510 ww, wh - vert_border);
1511 wWindowSynthConfigureNotify(wwin);
1513 wWindowChangeWorkspace(wwin, scr->current_workspace);
1514 wSetFocusTo(scr, wwin);
1516 return 1;
1523 *----------------------------------------------------------------------
1524 * wMouseMoveWindow--
1525 * Move the named window and the other selected ones (if any),
1526 * interactively. Also shows the position of the window, if only one
1527 * window is being moved.
1528 * If the window is not on the selected window list, the selected
1529 * windows are deselected.
1530 * If shift is pressed during the operation, the position display
1531 * is changed to another type.
1533 * Returns:
1534 * True if the window was moved, False otherwise.
1536 * Side effects:
1537 * The window(s) position is changed, and the client(s) are
1538 * notified about that.
1539 * The position display configuration may be changed.
1540 *----------------------------------------------------------------------
1543 wMouseMoveWindow(WWindow *wwin, XEvent *ev)
1545 WScreen *scr = wwin->screen_ptr;
1546 XEvent event;
1547 Window root = scr->root_win;
1548 KeyCode shiftl, shiftr;
1549 Bool done = False;
1550 int started = 0;
1551 int warped = 0;
1552 /* This needs not to change while moving, else bad things can happen */
1553 int opaqueMove = wPreferences.opaque_move;
1554 MoveData moveData;
1555 #ifdef GHOST_WINDOW_MOVE
1556 RImage *rimg;
1558 rimg = InitGhostWindowMove(scr);
1559 #endif
1562 if (wPreferences.opaque_move && !wPreferences.use_saveunders) {
1563 XSetWindowAttributes attr;
1565 attr.save_under = True;
1566 XChangeWindowAttributes(dpy, wwin->frame->core->window,
1567 CWSaveUnder, &attr);
1571 initMoveData(wwin, &moveData);
1573 moveData.mouseX = ev->xmotion.x_root;
1574 moveData.mouseY = ev->xmotion.y_root;
1576 if (!wwin->flags.selected) {
1577 /* this window is not selected, unselect others and move only wwin */
1578 wUnselectWindows(scr);
1580 #ifdef DEBUG
1581 puts("Moving window");
1582 #endif
1583 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1584 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1585 while (!done) {
1586 if (warped) {
1587 int junk;
1588 Window junkw;
1590 /* XWarpPointer() doesn't seem to generate Motion events, so
1591 we've got to simulate them */
1592 XQueryPointer(dpy, root, &junkw, &junkw, &event.xmotion.x_root,
1593 &event.xmotion.y_root, &junk, &junk,
1594 (unsigned *) &junk);
1595 } else {
1596 WMMaskEvent(dpy, KeyPressMask | ButtonMotionMask
1597 | PointerMotionHintMask
1598 | ButtonReleaseMask | ButtonPressMask | ExposureMask,
1599 &event);
1601 if (event.type == MotionNotify) {
1602 /* compress MotionNotify events */
1603 while (XCheckMaskEvent(dpy, ButtonMotionMask, &event)) ;
1604 if (!checkMouseSamplingRate(&event))
1605 continue;
1608 switch (event.type) {
1609 case KeyPress:
1610 if ((event.xkey.keycode == shiftl || event.xkey.keycode == shiftr)
1611 && started && !scr->selected_windows) {
1613 if (!opaqueMove) {
1614 drawFrames(wwin, scr->selected_windows,
1615 moveData.realX - wwin->frame_x,
1616 moveData.realY - wwin->frame_y);
1619 if (wPreferences.move_display == WDIS_NEW
1620 && !scr->selected_windows) {
1621 showPosition(wwin, moveData.realX, moveData.realY);
1622 XUngrabServer(dpy);
1624 cyclePositionDisplay(wwin, moveData.realX, moveData.realY,
1625 moveData.winWidth, moveData.winHeight);
1627 if (wPreferences.move_display == WDIS_NEW
1628 && !scr->selected_windows) {
1629 XGrabServer(dpy);
1630 showPosition(wwin, moveData.realX, moveData.realY);
1633 if (!opaqueMove) {
1634 drawFrames(wwin, scr->selected_windows,
1635 moveData.realX - wwin->frame_x,
1636 moveData.realY - wwin->frame_y);
1639 break;
1641 case MotionNotify:
1642 if (started) {
1643 updateWindowPosition(wwin, &moveData,
1644 scr->selected_windows == NULL
1645 && wPreferences.edge_resistance > 0,
1646 opaqueMove,
1647 event.xmotion.x_root,
1648 event.xmotion.y_root);
1650 if (!warped && !wPreferences.no_autowrap) {
1651 int oldWorkspace = scr->current_workspace;
1653 if (wPreferences.move_display == WDIS_NEW
1654 && !scr->selected_windows) {
1655 showPosition(wwin, moveData.realX, moveData.realY);
1656 XUngrabServer(dpy);
1658 if (!opaqueMove) {
1659 drawFrames(wwin, scr->selected_windows,
1660 moveData.realX - wwin->frame_x,
1661 moveData.realY - wwin->frame_y);
1663 if (checkWorkspaceChange(wwin, &moveData, opaqueMove)) {
1664 if (scr->current_workspace != oldWorkspace
1665 && wPreferences.edge_resistance > 0
1666 && scr->selected_windows == NULL)
1667 updateMoveData(wwin, &moveData);
1668 warped = 1;
1670 if (!opaqueMove) {
1671 drawFrames(wwin, scr->selected_windows,
1672 moveData.realX - wwin->frame_x,
1673 moveData.realY - wwin->frame_y);
1675 if (wPreferences.move_display == WDIS_NEW
1676 && !scr->selected_windows) {
1677 XSync(dpy, False);
1678 showPosition(wwin, moveData.realX, moveData.realY);
1679 XGrabServer(dpy);
1681 } else {
1682 warped = 0;
1684 } else if (abs(ev->xmotion.x_root - event.xmotion.x_root) >= MOVE_THRESHOLD
1685 || abs(ev->xmotion.y_root - event.xmotion.y_root) >= MOVE_THRESHOLD) {
1687 XChangeActivePointerGrab(dpy, ButtonMotionMask
1688 | ButtonReleaseMask | ButtonPressMask,
1689 wCursor[WCUR_MOVE], CurrentTime);
1690 started = 1;
1691 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync,
1692 CurrentTime);
1694 if (!scr->selected_windows)
1695 mapPositionDisplay(wwin, moveData.realX, moveData.realY,
1696 moveData.winWidth, moveData.winHeight);
1698 if (started && !opaqueMove)
1699 drawFrames(wwin, scr->selected_windows, 0, 0);
1701 if (!opaqueMove || (wPreferences.move_display==WDIS_NEW
1702 && !scr->selected_windows)) {
1703 XGrabServer(dpy);
1704 if (wPreferences.move_display==WDIS_NEW)
1705 showPosition(wwin, moveData.realX, moveData.realY);
1708 break;
1710 case ButtonPress:
1711 break;
1713 case ButtonRelease:
1714 if (event.xbutton.button != ev->xbutton.button)
1715 break;
1717 if (started) {
1718 XEvent e;
1719 if (!opaqueMove) {
1720 drawFrames(wwin, scr->selected_windows,
1721 moveData.realX - wwin->frame_x,
1722 moveData.realY - wwin->frame_y);
1723 XSync(dpy, 0);
1724 doWindowMove(wwin, scr->selected_windows,
1725 moveData.realX - wwin->frame_x,
1726 moveData.realY - wwin->frame_y);
1728 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1729 wWindowSynthConfigureNotify(wwin);
1730 #endif
1731 XUngrabKeyboard(dpy, CurrentTime);
1732 XUngrabServer(dpy);
1733 if (!opaqueMove) {
1734 wWindowChangeWorkspace(wwin, scr->current_workspace);
1735 wSetFocusTo(scr, wwin);
1737 if (wPreferences.move_display == WDIS_NEW)
1738 showPosition(wwin, moveData.realX, moveData.realY);
1740 /* discard all enter/leave events that happened until
1741 * the time the button was released */
1742 while (XCheckTypedEvent(dpy, EnterNotify, &e)) {
1743 if (e.xcrossing.time > event.xbutton.time) {
1744 XPutBackEvent(dpy, &e);
1745 break;
1748 while (XCheckTypedEvent(dpy, LeaveNotify, &e)) {
1749 if (e.xcrossing.time > event.xbutton.time) {
1750 XPutBackEvent(dpy, &e);
1751 break;
1755 if (!scr->selected_windows) {
1756 /* get rid of the geometry window */
1757 WMUnmapWidget(scr->gview);
1760 #ifdef DEBUG
1761 puts("End move window");
1762 #endif
1763 done = True;
1764 break;
1766 default:
1767 if (started && !opaqueMove) {
1768 drawFrames(wwin, scr->selected_windows,
1769 moveData.realX - wwin->frame_x,
1770 moveData.realY - wwin->frame_y);
1771 XUngrabServer(dpy);
1772 WMHandleEvent(&event);
1773 XSync(dpy, False);
1774 XGrabServer(dpy);
1775 drawFrames(wwin, scr->selected_windows,
1776 moveData.realX - wwin->frame_x,
1777 moveData.realY - wwin->frame_y);
1778 } else {
1779 WMHandleEvent(&event);
1781 break;
1785 if (wPreferences.opaque_move && !wPreferences.use_saveunders) {
1786 XSetWindowAttributes attr;
1789 attr.save_under = False;
1790 XChangeWindowAttributes(dpy, wwin->frame->core->window,
1791 CWSaveUnder, &attr);
1795 freeMoveData(&moveData);
1797 return started;
1801 #define RESIZEBAR 1
1802 #define HCONSTRAIN 2
1804 static int
1805 getResizeDirection(WWindow *wwin, int x, int y, int dx, int dy,
1806 int flags)
1808 int w = wwin->frame->core->width - 1;
1809 int cw = wwin->frame->resizebar_corner_width;
1810 int dir;
1812 /* if not resizing through the resizebar */
1813 if (!(flags & RESIZEBAR)) {
1814 int xdir = (abs(x) < (wwin->client.width/2)) ? LEFT : RIGHT;
1815 int ydir = (abs(y) < (wwin->client.height/2)) ? UP : DOWN;
1816 if (abs(dx) < 2 || abs(dy) < 2) {
1817 if (abs(dy) > abs(dx))
1818 xdir = 0;
1819 else
1820 ydir = 0;
1822 return (xdir | ydir);
1825 /* window is too narrow. allow diagonal resize */
1826 if (cw * 2 >= w) {
1827 int ydir;
1829 if (flags & HCONSTRAIN)
1830 ydir = 0;
1831 else
1832 ydir = DOWN;
1833 if (x < cw)
1834 return (LEFT | ydir);
1835 else
1836 return (RIGHT | ydir);
1838 /* vertical resize */
1839 if ((x > cw) && (x < w - cw))
1840 return DOWN;
1842 if (x < cw)
1843 dir = LEFT;
1844 else
1845 dir = RIGHT;
1847 if ((abs(dy) > 0) && !(flags & HCONSTRAIN))
1848 dir |= DOWN;
1850 return dir;
1854 void
1855 wMouseResizeWindow(WWindow *wwin, XEvent *ev)
1857 XEvent event;
1858 WScreen *scr = wwin->screen_ptr;
1859 Window root = scr->root_win;
1860 int vert_border = wwin->frame->top_width + wwin->frame->bottom_width;
1861 int fw = wwin->frame->core->width;
1862 int fh = wwin->frame->core->height;
1863 int fx = wwin->frame_x;
1864 int fy = wwin->frame_y;
1865 int is_resizebar = (wwin->frame->resizebar
1866 && ev->xany.window==wwin->frame->resizebar->window);
1867 int orig_x, orig_y;
1868 int started;
1869 int dw, dh;
1870 int rw = fw, rh = fh;
1871 int rx1, ry1, rx2, ry2;
1872 int res = 0;
1873 KeyCode shiftl, shiftr;
1874 int h = 0;
1875 int orig_fx = fx;
1876 int orig_fy = fy;
1877 int orig_fw = fw;
1878 int orig_fh = fh;
1880 if (wwin->flags.shaded) {
1881 wwarning("internal error: tryein");
1882 return;
1884 orig_x = ev->xbutton.x_root;
1885 orig_y = ev->xbutton.y_root;
1887 started = 0;
1888 #ifdef DEBUG
1889 puts("Resizing window");
1890 #endif
1892 wUnselectWindows(scr);
1893 rx1 = fx;
1894 rx2 = fx + fw - 1;
1895 ry1 = fy;
1896 ry2 = fy + fh - 1;
1897 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1898 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1899 if (!WFLAGP(wwin, no_titlebar))
1900 h = WMFontHeight(wwin->screen_ptr->title_font) + (wPreferences.window_title_clearance + TITLEBAR_EXTEND_SPACE) * 2;
1901 else
1902 h = 0;
1903 while (1) {
1904 WMMaskEvent(dpy, KeyPressMask | ButtonMotionMask
1905 | ButtonReleaseMask | PointerMotionHintMask
1906 | ButtonPressMask | ExposureMask, &event);
1907 if (!checkMouseSamplingRate(&event))
1908 continue;
1910 switch (event.type) {
1911 case KeyPress:
1912 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1913 if ((event.xkey.keycode == shiftl || event.xkey.keycode == shiftr)
1914 && started) {
1915 drawTransparentFrame(wwin, fx, fy, fw, fh);
1916 cycleGeometryDisplay(wwin, fx, fy, fw, fh, res);
1917 drawTransparentFrame(wwin, fx, fy, fw, fh);
1919 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1920 break;
1922 case MotionNotify:
1923 if (started) {
1924 while (XCheckMaskEvent(dpy, ButtonMotionMask, &event)) ;
1926 dw = 0;
1927 dh = 0;
1929 orig_fx = fx;
1930 orig_fy = fy;
1931 orig_fw = fw;
1932 orig_fh = fh;
1934 if (res & LEFT)
1935 dw = orig_x - event.xmotion.x_root;
1936 else if (res & RIGHT)
1937 dw = event.xmotion.x_root - orig_x;
1938 if (res & UP)
1939 dh = orig_y - event.xmotion.y_root;
1940 else if (res & DOWN)
1941 dh = event.xmotion.y_root - orig_y;
1943 orig_x = event.xmotion.x_root;
1944 orig_y = event.xmotion.y_root;
1946 rw += dw;
1947 rh += dh;
1948 fw = rw;
1949 fh = rh - vert_border;
1950 wWindowConstrainSize(wwin, &fw, &fh);
1951 fh += vert_border;
1952 if (res & LEFT)
1953 fx = rx2 - fw + 1;
1954 else if (res & RIGHT)
1955 fx = rx1;
1956 if (res & UP)
1957 fy = ry2 - fh + 1;
1958 else if (res & DOWN)
1959 fy = ry1;
1960 } else if (abs(orig_x - event.xmotion.x_root) >= MOVE_THRESHOLD
1961 || abs(orig_y - event.xmotion.y_root) >= MOVE_THRESHOLD) {
1962 int tx, ty;
1963 Window junkw;
1964 int flags;
1966 XTranslateCoordinates(dpy, root, wwin->frame->core->window,
1967 orig_x, orig_y, &tx, &ty, &junkw);
1969 /* check if resizing through resizebar */
1970 if (is_resizebar)
1971 flags = RESIZEBAR;
1972 else
1973 flags = 0;
1975 if (is_resizebar && ((ev->xbutton.state & ShiftMask)
1976 || abs(orig_y - event.xmotion.y_root) < HRESIZE_THRESHOLD))
1977 flags |= HCONSTRAIN;
1979 res = getResizeDirection(wwin, tx, ty,
1980 orig_x - event.xmotion.x_root,
1981 orig_y - event.xmotion.y_root, flags);
1983 if (res == (UP|LEFT))
1984 XChangeActivePointerGrab(dpy, ButtonMotionMask
1985 | ButtonReleaseMask | ButtonPressMask,
1986 wCursor[WCUR_TOPLEFTRESIZE], CurrentTime);
1987 else if (res == (UP|RIGHT))
1988 XChangeActivePointerGrab(dpy, ButtonMotionMask
1989 | ButtonReleaseMask | ButtonPressMask,
1990 wCursor[WCUR_TOPRIGHTRESIZE], CurrentTime);
1991 else if (res == (DOWN|LEFT))
1992 XChangeActivePointerGrab(dpy, ButtonMotionMask
1993 | ButtonReleaseMask | ButtonPressMask,
1994 wCursor[WCUR_BOTTOMLEFTRESIZE], CurrentTime);
1995 else if (res == (DOWN|RIGHT))
1996 XChangeActivePointerGrab(dpy, ButtonMotionMask
1997 | ButtonReleaseMask | ButtonPressMask,
1998 wCursor[WCUR_BOTTOMRIGHTRESIZE], CurrentTime);
1999 else if (res == DOWN || res == UP)
2000 XChangeActivePointerGrab(dpy, ButtonMotionMask
2001 | ButtonReleaseMask | ButtonPressMask,
2002 wCursor[WCUR_VERTICALRESIZE], CurrentTime);
2003 else if (res & (DOWN|UP))
2004 XChangeActivePointerGrab(dpy, ButtonMotionMask
2005 | ButtonReleaseMask | ButtonPressMask,
2006 wCursor[WCUR_VERTICALRESIZE], CurrentTime);
2007 else if (res & (LEFT|RIGHT))
2008 XChangeActivePointerGrab(dpy, ButtonMotionMask
2009 | ButtonReleaseMask | ButtonPressMask,
2010 wCursor[WCUR_HORIZONRESIZE], CurrentTime);
2012 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync,
2013 CurrentTime);
2015 XGrabServer(dpy);
2017 /* Draw the resize frame for the first time. */
2018 mapGeometryDisplay(wwin, fx, fy, fw, fh);
2020 drawTransparentFrame(wwin, fx, fy, fw, fh);
2022 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
2024 started = 1;
2026 if (started) {
2027 if (wPreferences.size_display == WDIS_FRAME_CENTER) {
2028 drawTransparentFrame(wwin, orig_fx, orig_fy,
2029 orig_fw, orig_fh);
2030 moveGeometryDisplayCentered(scr, fx + fw / 2, fy + fh / 2);
2031 drawTransparentFrame(wwin, fx, fy, fw, fh);
2032 } else {
2033 drawTransparentFrame(wwin, orig_fx, orig_fy,
2034 orig_fw, orig_fh);
2035 drawTransparentFrame(wwin, fx, fy, fw, fh);
2037 if (fh != orig_fh || fw != orig_fw) {
2038 if (wPreferences.size_display == WDIS_NEW) {
2039 showGeometry(wwin, orig_fx, orig_fy, orig_fx + orig_fw,
2040 orig_fy + orig_fh, res);
2042 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
2045 break;
2047 case ButtonPress:
2048 break;
2050 case ButtonRelease:
2051 if (event.xbutton.button != ev->xbutton.button)
2052 break;
2054 if (started) {
2055 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
2057 drawTransparentFrame(wwin, fx, fy, fw, fh);
2059 XUngrabKeyboard(dpy, CurrentTime);
2060 WMUnmapWidget(scr->gview);
2061 XUngrabServer(dpy);
2063 if (wwin->client.width != fw)
2064 wwin->flags.user_changed_width = 1;
2066 if (wwin->client.height != fh - vert_border)
2067 wwin->flags.user_changed_height = 1;
2069 wWindowConfigure(wwin, fx, fy, fw, fh - vert_border);
2071 #ifdef DEBUG
2072 puts("End resize window");
2073 #endif
2074 return;
2076 default:
2077 WMHandleEvent(&event);
2082 #undef LEFT
2083 #undef RIGHT
2084 #undef HORIZONTAL
2085 #undef UP
2086 #undef DOWN
2087 #undef VERTICAL
2088 #undef HCONSTRAIN
2089 #undef RESIZEBAR
2091 void
2092 wUnselectWindows(WScreen *scr)
2094 WWindow *wwin;
2096 if (!scr->selected_windows)
2097 return;
2099 while (WMGetBagItemCount(scr->selected_windows)) {
2100 WMBagIterator dummy;
2102 wwin = WMBagFirst(scr->selected_windows, &dummy);
2103 if (wwin->flags.miniaturized && wwin->icon && wwin->icon->selected)
2104 wIconSelect(wwin->icon);
2106 wSelectWindow(wwin, False);
2108 WMFreeBag(scr->selected_windows);
2109 scr->selected_windows = NULL;
2112 #ifndef LITE
2113 static void
2114 selectWindowsInside(WScreen *scr, int x1, int y1, int x2, int y2)
2116 WWindow *tmpw;
2118 /* select the windows and put them in the selected window list */
2119 tmpw = scr->focused_window;
2120 while (tmpw != NULL) {
2121 if (!(tmpw->flags.miniaturized || tmpw->flags.hidden)) {
2122 if ((tmpw->frame->workspace == scr->current_workspace
2123 || IS_OMNIPRESENT(tmpw))
2124 && (tmpw->frame_x >= x1) && (tmpw->frame_y >= y1)
2125 && (tmpw->frame->core->width + tmpw->frame_x <= x2)
2126 && (tmpw->frame->core->height + tmpw->frame_y <= y2)) {
2127 wSelectWindow(tmpw, True);
2130 tmpw = tmpw->prev;
2135 void
2136 wSelectWindows(WScreen *scr, XEvent *ev)
2138 XEvent event;
2139 Window root = scr->root_win;
2140 GC gc = scr->frame_gc;
2141 int xp = ev->xbutton.x_root;
2142 int yp = ev->xbutton.y_root;
2143 int w = 0, h = 0;
2144 int x = xp, y = yp;
2146 #ifdef DEBUG
2147 puts("Selecting windows");
2148 #endif
2149 if (XGrabPointer(dpy, scr->root_win, False, ButtonMotionMask
2150 | ButtonReleaseMask | ButtonPressMask, GrabModeAsync,
2151 GrabModeAsync, None, wCursor[WCUR_DEFAULT],
2152 CurrentTime) != Success) {
2153 return;
2155 XGrabServer(dpy);
2157 wUnselectWindows(scr);
2159 XDrawRectangle(dpy, root, gc, xp, yp, w, h);
2160 while (1) {
2161 WMMaskEvent(dpy, ButtonReleaseMask | PointerMotionMask
2162 | ButtonPressMask, &event);
2164 switch (event.type) {
2165 case MotionNotify:
2166 XDrawRectangle(dpy, root, gc, x, y, w, h);
2167 x = event.xmotion.x_root;
2168 if (x < xp) {
2169 w = xp - x;
2170 } else {
2171 w = x - xp;
2172 x = xp;
2174 y = event.xmotion.y_root;
2175 if (y < yp) {
2176 h = yp - y;
2177 } else {
2178 h = y - yp;
2179 y = yp;
2181 XDrawRectangle(dpy, root, gc, x, y, w, h);
2182 break;
2184 case ButtonPress:
2185 break;
2187 case ButtonRelease:
2188 if (event.xbutton.button != ev->xbutton.button)
2189 break;
2191 XDrawRectangle(dpy, root, gc, x, y, w, h);
2192 XUngrabServer(dpy);
2193 XUngrabPointer(dpy, CurrentTime);
2194 selectWindowsInside(scr, x, y, x + w, y + h);
2196 #ifdef KWM_HINTS
2197 wKWMSelectRootRegion(scr, xp, yp, w, h,
2198 event.xbutton.state & ControlMask);
2199 #endif /* KWM_HINTS */
2201 #ifdef DEBUG
2202 puts("End window selection");
2203 #endif
2204 return;
2206 default:
2207 WMHandleEvent(&event);
2208 break;
2212 #endif /* !LITE */
2214 void
2215 InteractivePlaceWindow(WWindow *wwin, int *x_ret, int *y_ret,
2216 unsigned width, unsigned height)
2218 WScreen *scr = wwin->screen_ptr;
2219 Window root = scr->root_win;
2220 int x, y, h = 0;
2221 XEvent event;
2222 KeyCode shiftl, shiftr;
2223 Window junkw;
2224 int junk;
2226 if (XGrabPointer(dpy, root, True, PointerMotionMask | ButtonPressMask,
2227 GrabModeAsync, GrabModeAsync, None,
2228 wCursor[WCUR_DEFAULT], CurrentTime) != Success) {
2229 *x_ret = 0;
2230 *y_ret = 0;
2231 return;
2233 if (!WFLAGP(wwin, no_titlebar)) {
2234 h = WMFontHeight(scr->title_font) + (wPreferences.window_title_clearance + TITLEBAR_EXTEND_SPACE) * 2;
2235 height += h;
2237 if (!WFLAGP(wwin, no_resizebar)) {
2238 height += RESIZEBAR_HEIGHT;
2240 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync, CurrentTime);
2241 XQueryPointer(dpy, root, &junkw, &junkw, &x, &y, &junk, &junk,
2242 (unsigned *) &junk);
2243 mapPositionDisplay(wwin, x - width/2, y - h/2, width, height);
2245 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2247 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
2248 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
2249 while (1) {
2250 WMMaskEvent(dpy, PointerMotionMask|ButtonPressMask|ExposureMask|KeyPressMask,
2251 &event);
2253 if (!checkMouseSamplingRate(&event))
2254 continue;
2256 switch (event.type) {
2257 case KeyPress:
2258 if ((event.xkey.keycode == shiftl)
2259 || (event.xkey.keycode == shiftr)) {
2260 drawTransparentFrame(wwin,
2261 x - width/2, y - h/2, width, height);
2262 cyclePositionDisplay(wwin,
2263 x - width/2, y - h/2, width, height);
2264 drawTransparentFrame(wwin,
2265 x - width/2, y - h/2, width, height);
2267 break;
2269 case MotionNotify:
2270 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2272 x = event.xmotion.x_root;
2273 y = event.xmotion.y_root;
2275 if (wPreferences.move_display == WDIS_FRAME_CENTER)
2276 moveGeometryDisplayCentered(scr, x, y + (height - h) / 2);
2278 showPosition(wwin, x - width/2, y - h/2);
2280 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2282 break;
2284 case ButtonPress:
2285 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2286 XSync(dpy, 0);
2287 *x_ret = x - width/2;
2288 *y_ret = y - h/2;
2289 XUngrabPointer(dpy, CurrentTime);
2290 XUngrabKeyboard(dpy, CurrentTime);
2291 /* get rid of the geometry window */
2292 WMUnmapWidget(scr->gview);
2293 return;
2295 default:
2296 WMHandleEvent(&event);
2297 break;