updated estonian locale file
[wmaker-crm.git] / src / moveres.c
blobfcde72dad5b3f6356c6d7512d2a94285b442ff30
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, WMArray *array, 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 (!array || !WMGetArrayItemCount(array)) {
401 wWindowMove(wwin, wwin->frame_x + dx, wwin->frame_y + dy);
402 } else {
403 WMArrayIterator iter;
405 WM_ITERATE_ARRAY(array, tmpw, iter) {
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, WMArray *array, 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 (!array) {
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 WMArrayIterator iter;
477 WM_ITERATE_ARRAY(array, tmpw, iter) {
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 WMArrayIterator iter;
1496 WWindow *foo;
1498 doWindowMove(wwin, scr->selected_windows, off_x, off_y);
1500 WM_ITERATE_ARRAY(scr->selected_windows, foo, iter) {
1501 wWindowSynthConfigureNotify(foo);
1504 } else {
1505 if (wwin->client.width != ww)
1506 wwin->flags.user_changed_width = 1;
1508 if (wwin->client.height != wh - vert_border)
1509 wwin->flags.user_changed_height = 1;
1511 wWindowConfigure(wwin, src_x+off_x, src_y+off_y,
1512 ww, wh - vert_border);
1513 wWindowSynthConfigureNotify(wwin);
1515 wWindowChangeWorkspace(wwin, scr->current_workspace);
1516 wSetFocusTo(scr, wwin);
1518 return 1;
1525 *----------------------------------------------------------------------
1526 * wMouseMoveWindow--
1527 * Move the named window and the other selected ones (if any),
1528 * interactively. Also shows the position of the window, if only one
1529 * window is being moved.
1530 * If the window is not on the selected window list, the selected
1531 * windows are deselected.
1532 * If shift is pressed during the operation, the position display
1533 * is changed to another type.
1535 * Returns:
1536 * True if the window was moved, False otherwise.
1538 * Side effects:
1539 * The window(s) position is changed, and the client(s) are
1540 * notified about that.
1541 * The position display configuration may be changed.
1542 *----------------------------------------------------------------------
1545 wMouseMoveWindow(WWindow *wwin, XEvent *ev)
1547 WScreen *scr = wwin->screen_ptr;
1548 XEvent event;
1549 Window root = scr->root_win;
1550 KeyCode shiftl, shiftr;
1551 Bool done = False;
1552 int started = 0;
1553 int warped = 0;
1554 /* This needs not to change while moving, else bad things can happen */
1555 int opaqueMove = wPreferences.opaque_move;
1556 MoveData moveData;
1557 #ifdef GHOST_WINDOW_MOVE
1558 RImage *rimg;
1560 rimg = InitGhostWindowMove(scr);
1561 #endif
1564 if (wPreferences.opaque_move && !wPreferences.use_saveunders) {
1565 XSetWindowAttributes attr;
1567 attr.save_under = True;
1568 XChangeWindowAttributes(dpy, wwin->frame->core->window,
1569 CWSaveUnder, &attr);
1573 initMoveData(wwin, &moveData);
1575 moveData.mouseX = ev->xmotion.x_root;
1576 moveData.mouseY = ev->xmotion.y_root;
1578 if (!wwin->flags.selected) {
1579 /* this window is not selected, unselect others and move only wwin */
1580 wUnselectWindows(scr);
1582 #ifdef DEBUG
1583 puts("Moving window");
1584 #endif
1585 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1586 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1587 while (!done) {
1588 if (warped) {
1589 int junk;
1590 Window junkw;
1592 /* XWarpPointer() doesn't seem to generate Motion events, so
1593 we've got to simulate them */
1594 XQueryPointer(dpy, root, &junkw, &junkw, &event.xmotion.x_root,
1595 &event.xmotion.y_root, &junk, &junk,
1596 (unsigned *) &junk);
1597 } else {
1598 WMMaskEvent(dpy, KeyPressMask | ButtonMotionMask
1599 | PointerMotionHintMask
1600 | ButtonReleaseMask | ButtonPressMask | ExposureMask,
1601 &event);
1603 if (event.type == MotionNotify) {
1604 /* compress MotionNotify events */
1605 while (XCheckMaskEvent(dpy, ButtonMotionMask, &event)) ;
1606 if (!checkMouseSamplingRate(&event))
1607 continue;
1610 switch (event.type) {
1611 case KeyPress:
1612 if ((event.xkey.keycode == shiftl || event.xkey.keycode == shiftr)
1613 && started && !scr->selected_windows) {
1615 if (!opaqueMove) {
1616 drawFrames(wwin, scr->selected_windows,
1617 moveData.realX - wwin->frame_x,
1618 moveData.realY - wwin->frame_y);
1621 if (wPreferences.move_display == WDIS_NEW
1622 && !scr->selected_windows) {
1623 showPosition(wwin, moveData.realX, moveData.realY);
1624 XUngrabServer(dpy);
1626 cyclePositionDisplay(wwin, moveData.realX, moveData.realY,
1627 moveData.winWidth, moveData.winHeight);
1629 if (wPreferences.move_display == WDIS_NEW
1630 && !scr->selected_windows) {
1631 XGrabServer(dpy);
1632 showPosition(wwin, moveData.realX, moveData.realY);
1635 if (!opaqueMove) {
1636 drawFrames(wwin, scr->selected_windows,
1637 moveData.realX - wwin->frame_x,
1638 moveData.realY - wwin->frame_y);
1641 break;
1643 case MotionNotify:
1644 if (started) {
1645 updateWindowPosition(wwin, &moveData,
1646 scr->selected_windows == NULL
1647 && wPreferences.edge_resistance > 0,
1648 opaqueMove,
1649 event.xmotion.x_root,
1650 event.xmotion.y_root);
1652 if (!warped && !wPreferences.no_autowrap) {
1653 int oldWorkspace = scr->current_workspace;
1655 if (wPreferences.move_display == WDIS_NEW
1656 && !scr->selected_windows) {
1657 showPosition(wwin, moveData.realX, moveData.realY);
1658 XUngrabServer(dpy);
1660 if (!opaqueMove) {
1661 drawFrames(wwin, scr->selected_windows,
1662 moveData.realX - wwin->frame_x,
1663 moveData.realY - wwin->frame_y);
1665 if (checkWorkspaceChange(wwin, &moveData, opaqueMove)) {
1666 if (scr->current_workspace != oldWorkspace
1667 && wPreferences.edge_resistance > 0
1668 && scr->selected_windows == NULL)
1669 updateMoveData(wwin, &moveData);
1670 warped = 1;
1672 if (!opaqueMove) {
1673 drawFrames(wwin, scr->selected_windows,
1674 moveData.realX - wwin->frame_x,
1675 moveData.realY - wwin->frame_y);
1677 if (wPreferences.move_display == WDIS_NEW
1678 && !scr->selected_windows) {
1679 XSync(dpy, False);
1680 showPosition(wwin, moveData.realX, moveData.realY);
1681 XGrabServer(dpy);
1683 } else {
1684 warped = 0;
1686 } else if (abs(ev->xmotion.x_root - event.xmotion.x_root) >= MOVE_THRESHOLD
1687 || abs(ev->xmotion.y_root - event.xmotion.y_root) >= MOVE_THRESHOLD) {
1689 XChangeActivePointerGrab(dpy, ButtonMotionMask
1690 | ButtonReleaseMask | ButtonPressMask,
1691 wCursor[WCUR_MOVE], CurrentTime);
1692 started = 1;
1693 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync,
1694 CurrentTime);
1696 if (!scr->selected_windows)
1697 mapPositionDisplay(wwin, moveData.realX, moveData.realY,
1698 moveData.winWidth, moveData.winHeight);
1700 if (started && !opaqueMove)
1701 drawFrames(wwin, scr->selected_windows, 0, 0);
1703 if (!opaqueMove || (wPreferences.move_display==WDIS_NEW
1704 && !scr->selected_windows)) {
1705 XGrabServer(dpy);
1706 if (wPreferences.move_display==WDIS_NEW)
1707 showPosition(wwin, moveData.realX, moveData.realY);
1710 break;
1712 case ButtonPress:
1713 break;
1715 case ButtonRelease:
1716 if (event.xbutton.button != ev->xbutton.button)
1717 break;
1719 if (started) {
1720 XEvent e;
1721 if (!opaqueMove) {
1722 drawFrames(wwin, scr->selected_windows,
1723 moveData.realX - wwin->frame_x,
1724 moveData.realY - wwin->frame_y);
1725 XSync(dpy, 0);
1726 doWindowMove(wwin, scr->selected_windows,
1727 moveData.realX - wwin->frame_x,
1728 moveData.realY - wwin->frame_y);
1730 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1731 wWindowSynthConfigureNotify(wwin);
1732 #endif
1733 XUngrabKeyboard(dpy, CurrentTime);
1734 XUngrabServer(dpy);
1735 if (!opaqueMove) {
1736 wWindowChangeWorkspace(wwin, scr->current_workspace);
1737 wSetFocusTo(scr, wwin);
1739 if (wPreferences.move_display == WDIS_NEW)
1740 showPosition(wwin, moveData.realX, moveData.realY);
1742 /* discard all enter/leave events that happened until
1743 * the time the button was released */
1744 while (XCheckTypedEvent(dpy, EnterNotify, &e)) {
1745 if (e.xcrossing.time > event.xbutton.time) {
1746 XPutBackEvent(dpy, &e);
1747 break;
1750 while (XCheckTypedEvent(dpy, LeaveNotify, &e)) {
1751 if (e.xcrossing.time > event.xbutton.time) {
1752 XPutBackEvent(dpy, &e);
1753 break;
1757 if (!scr->selected_windows) {
1758 /* get rid of the geometry window */
1759 WMUnmapWidget(scr->gview);
1762 #ifdef DEBUG
1763 puts("End move window");
1764 #endif
1765 done = True;
1766 break;
1768 default:
1769 if (started && !opaqueMove) {
1770 drawFrames(wwin, scr->selected_windows,
1771 moveData.realX - wwin->frame_x,
1772 moveData.realY - wwin->frame_y);
1773 XUngrabServer(dpy);
1774 WMHandleEvent(&event);
1775 XSync(dpy, False);
1776 XGrabServer(dpy);
1777 drawFrames(wwin, scr->selected_windows,
1778 moveData.realX - wwin->frame_x,
1779 moveData.realY - wwin->frame_y);
1780 } else {
1781 WMHandleEvent(&event);
1783 break;
1787 if (wPreferences.opaque_move && !wPreferences.use_saveunders) {
1788 XSetWindowAttributes attr;
1791 attr.save_under = False;
1792 XChangeWindowAttributes(dpy, wwin->frame->core->window,
1793 CWSaveUnder, &attr);
1797 freeMoveData(&moveData);
1799 return started;
1803 #define RESIZEBAR 1
1804 #define HCONSTRAIN 2
1806 static int
1807 getResizeDirection(WWindow *wwin, int x, int y, int dx, int dy,
1808 int flags)
1810 int w = wwin->frame->core->width - 1;
1811 int cw = wwin->frame->resizebar_corner_width;
1812 int dir;
1814 /* if not resizing through the resizebar */
1815 if (!(flags & RESIZEBAR)) {
1816 int xdir = (abs(x) < (wwin->client.width/2)) ? LEFT : RIGHT;
1817 int ydir = (abs(y) < (wwin->client.height/2)) ? UP : DOWN;
1818 if (abs(dx) < 2 || abs(dy) < 2) {
1819 if (abs(dy) > abs(dx))
1820 xdir = 0;
1821 else
1822 ydir = 0;
1824 return (xdir | ydir);
1827 /* window is too narrow. allow diagonal resize */
1828 if (cw * 2 >= w) {
1829 int ydir;
1831 if (flags & HCONSTRAIN)
1832 ydir = 0;
1833 else
1834 ydir = DOWN;
1835 if (x < cw)
1836 return (LEFT | ydir);
1837 else
1838 return (RIGHT | ydir);
1840 /* vertical resize */
1841 if ((x > cw) && (x < w - cw))
1842 return DOWN;
1844 if (x < cw)
1845 dir = LEFT;
1846 else
1847 dir = RIGHT;
1849 if ((abs(dy) > 0) && !(flags & HCONSTRAIN))
1850 dir |= DOWN;
1852 return dir;
1856 void
1857 wMouseResizeWindow(WWindow *wwin, XEvent *ev)
1859 XEvent event;
1860 WScreen *scr = wwin->screen_ptr;
1861 Window root = scr->root_win;
1862 int vert_border = wwin->frame->top_width + wwin->frame->bottom_width;
1863 int fw = wwin->frame->core->width;
1864 int fh = wwin->frame->core->height;
1865 int fx = wwin->frame_x;
1866 int fy = wwin->frame_y;
1867 int is_resizebar = (wwin->frame->resizebar
1868 && ev->xany.window==wwin->frame->resizebar->window);
1869 int orig_x, orig_y;
1870 int started;
1871 int dw, dh;
1872 int rw = fw, rh = fh;
1873 int rx1, ry1, rx2, ry2;
1874 int res = 0;
1875 KeyCode shiftl, shiftr;
1876 int h = 0;
1877 int orig_fx = fx;
1878 int orig_fy = fy;
1879 int orig_fw = fw;
1880 int orig_fh = fh;
1882 if (wwin->flags.shaded) {
1883 wwarning("internal error: tryein");
1884 return;
1886 orig_x = ev->xbutton.x_root;
1887 orig_y = ev->xbutton.y_root;
1889 started = 0;
1890 #ifdef DEBUG
1891 puts("Resizing window");
1892 #endif
1894 wUnselectWindows(scr);
1895 rx1 = fx;
1896 rx2 = fx + fw - 1;
1897 ry1 = fy;
1898 ry2 = fy + fh - 1;
1899 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1900 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1901 if (!WFLAGP(wwin, no_titlebar))
1902 h = WMFontHeight(wwin->screen_ptr->title_font) + (wPreferences.window_title_clearance + TITLEBAR_EXTEND_SPACE) * 2;
1903 else
1904 h = 0;
1905 while (1) {
1906 WMMaskEvent(dpy, KeyPressMask | ButtonMotionMask
1907 | ButtonReleaseMask | PointerMotionHintMask
1908 | ButtonPressMask | ExposureMask, &event);
1909 if (!checkMouseSamplingRate(&event))
1910 continue;
1912 switch (event.type) {
1913 case KeyPress:
1914 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1915 if ((event.xkey.keycode == shiftl || event.xkey.keycode == shiftr)
1916 && started) {
1917 drawTransparentFrame(wwin, fx, fy, fw, fh);
1918 cycleGeometryDisplay(wwin, fx, fy, fw, fh, res);
1919 drawTransparentFrame(wwin, fx, fy, fw, fh);
1921 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1922 break;
1924 case MotionNotify:
1925 if (started) {
1926 while (XCheckMaskEvent(dpy, ButtonMotionMask, &event)) ;
1928 dw = 0;
1929 dh = 0;
1931 orig_fx = fx;
1932 orig_fy = fy;
1933 orig_fw = fw;
1934 orig_fh = fh;
1936 if (res & LEFT)
1937 dw = orig_x - event.xmotion.x_root;
1938 else if (res & RIGHT)
1939 dw = event.xmotion.x_root - orig_x;
1940 if (res & UP)
1941 dh = orig_y - event.xmotion.y_root;
1942 else if (res & DOWN)
1943 dh = event.xmotion.y_root - orig_y;
1945 orig_x = event.xmotion.x_root;
1946 orig_y = event.xmotion.y_root;
1948 rw += dw;
1949 rh += dh;
1950 fw = rw;
1951 fh = rh - vert_border;
1952 wWindowConstrainSize(wwin, &fw, &fh);
1953 fh += vert_border;
1954 if (res & LEFT)
1955 fx = rx2 - fw + 1;
1956 else if (res & RIGHT)
1957 fx = rx1;
1958 if (res & UP)
1959 fy = ry2 - fh + 1;
1960 else if (res & DOWN)
1961 fy = ry1;
1962 } else if (abs(orig_x - event.xmotion.x_root) >= MOVE_THRESHOLD
1963 || abs(orig_y - event.xmotion.y_root) >= MOVE_THRESHOLD) {
1964 int tx, ty;
1965 Window junkw;
1966 int flags;
1968 XTranslateCoordinates(dpy, root, wwin->frame->core->window,
1969 orig_x, orig_y, &tx, &ty, &junkw);
1971 /* check if resizing through resizebar */
1972 if (is_resizebar)
1973 flags = RESIZEBAR;
1974 else
1975 flags = 0;
1977 if (is_resizebar && ((ev->xbutton.state & ShiftMask)
1978 || abs(orig_y - event.xmotion.y_root) < HRESIZE_THRESHOLD))
1979 flags |= HCONSTRAIN;
1981 res = getResizeDirection(wwin, tx, ty,
1982 orig_x - event.xmotion.x_root,
1983 orig_y - event.xmotion.y_root, flags);
1985 if (res == (UP|LEFT))
1986 XChangeActivePointerGrab(dpy, ButtonMotionMask
1987 | ButtonReleaseMask | ButtonPressMask,
1988 wCursor[WCUR_TOPLEFTRESIZE], CurrentTime);
1989 else if (res == (UP|RIGHT))
1990 XChangeActivePointerGrab(dpy, ButtonMotionMask
1991 | ButtonReleaseMask | ButtonPressMask,
1992 wCursor[WCUR_TOPRIGHTRESIZE], CurrentTime);
1993 else if (res == (DOWN|LEFT))
1994 XChangeActivePointerGrab(dpy, ButtonMotionMask
1995 | ButtonReleaseMask | ButtonPressMask,
1996 wCursor[WCUR_BOTTOMLEFTRESIZE], CurrentTime);
1997 else if (res == (DOWN|RIGHT))
1998 XChangeActivePointerGrab(dpy, ButtonMotionMask
1999 | ButtonReleaseMask | ButtonPressMask,
2000 wCursor[WCUR_BOTTOMRIGHTRESIZE], CurrentTime);
2001 else if (res == DOWN || res == UP)
2002 XChangeActivePointerGrab(dpy, ButtonMotionMask
2003 | ButtonReleaseMask | ButtonPressMask,
2004 wCursor[WCUR_VERTICALRESIZE], CurrentTime);
2005 else if (res & (DOWN|UP))
2006 XChangeActivePointerGrab(dpy, ButtonMotionMask
2007 | ButtonReleaseMask | ButtonPressMask,
2008 wCursor[WCUR_VERTICALRESIZE], CurrentTime);
2009 else if (res & (LEFT|RIGHT))
2010 XChangeActivePointerGrab(dpy, ButtonMotionMask
2011 | ButtonReleaseMask | ButtonPressMask,
2012 wCursor[WCUR_HORIZONRESIZE], CurrentTime);
2014 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync,
2015 CurrentTime);
2017 XGrabServer(dpy);
2019 /* Draw the resize frame for the first time. */
2020 mapGeometryDisplay(wwin, fx, fy, fw, fh);
2022 drawTransparentFrame(wwin, fx, fy, fw, fh);
2024 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
2026 started = 1;
2028 if (started) {
2029 if (wPreferences.size_display == WDIS_FRAME_CENTER) {
2030 drawTransparentFrame(wwin, orig_fx, orig_fy,
2031 orig_fw, orig_fh);
2032 moveGeometryDisplayCentered(scr, fx + fw / 2, fy + fh / 2);
2033 drawTransparentFrame(wwin, fx, fy, fw, fh);
2034 } else {
2035 drawTransparentFrame(wwin, orig_fx, orig_fy,
2036 orig_fw, orig_fh);
2037 drawTransparentFrame(wwin, fx, fy, fw, fh);
2039 if (fh != orig_fh || fw != orig_fw) {
2040 if (wPreferences.size_display == WDIS_NEW) {
2041 showGeometry(wwin, orig_fx, orig_fy, orig_fx + orig_fw,
2042 orig_fy + orig_fh, res);
2044 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
2047 break;
2049 case ButtonPress:
2050 break;
2052 case ButtonRelease:
2053 if (event.xbutton.button != ev->xbutton.button)
2054 break;
2056 if (started) {
2057 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
2059 drawTransparentFrame(wwin, fx, fy, fw, fh);
2061 XUngrabKeyboard(dpy, CurrentTime);
2062 WMUnmapWidget(scr->gview);
2063 XUngrabServer(dpy);
2065 if (wwin->client.width != fw)
2066 wwin->flags.user_changed_width = 1;
2068 if (wwin->client.height != fh - vert_border)
2069 wwin->flags.user_changed_height = 1;
2071 wWindowConfigure(wwin, fx, fy, fw, fh - vert_border);
2073 #ifdef DEBUG
2074 puts("End resize window");
2075 #endif
2076 return;
2078 default:
2079 WMHandleEvent(&event);
2084 #undef LEFT
2085 #undef RIGHT
2086 #undef HORIZONTAL
2087 #undef UP
2088 #undef DOWN
2089 #undef VERTICAL
2090 #undef HCONSTRAIN
2091 #undef RESIZEBAR
2093 void
2094 wUnselectWindows(WScreen *scr)
2096 WWindow *wwin;
2098 if (!scr->selected_windows)
2099 return;
2101 while (WMGetArrayItemCount(scr->selected_windows)) {
2102 wwin = WMGetFromArray(scr->selected_windows, 0);
2103 if (wwin->flags.miniaturized && wwin->icon && wwin->icon->selected)
2104 wIconSelect(wwin->icon);
2106 wSelectWindow(wwin, False);
2108 WMFreeArray(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;