updated code to use new bags
[wmaker-crm.git] / src / moveres.c
bloba66c3404a32cdb7ab50c10df67895e450be31037
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 WSetGeometryViewShownPosition(scr->gview, x, y);
156 static void
157 cyclePositionDisplay(WWindow *wwin, int x, int y, int w, int h)
159 WScreen *scr = wwin->screen_ptr;
161 wPreferences.move_display++;
162 wPreferences.move_display %= NUM_DISPLAYS;
164 if (wPreferences.move_display == WDIS_NEW) {
165 WMUnmapWidget(scr->gview);
166 } else {
167 if (wPreferences.move_display == WDIS_CENTER) {
168 moveGeometryDisplayCentered(scr,
169 scr->scr_width/2, scr->scr_height/2);
170 } else if (wPreferences.move_display == WDIS_TOPLEFT) {
171 moveGeometryDisplayCentered(scr, 1, 1);
172 } else if (wPreferences.move_display == WDIS_FRAME_CENTER) {
173 moveGeometryDisplayCentered(scr, x + w/2, y + h/2);
175 WMMapWidget(scr->gview);
180 static void
181 mapPositionDisplay(WWindow *wwin, int x, int y, int w, int h)
183 WScreen *scr = wwin->screen_ptr;
185 if (wPreferences.move_display == WDIS_NEW) {
186 return;
187 } else if (wPreferences.move_display == WDIS_CENTER) {
188 moveGeometryDisplayCentered(scr, scr->scr_width / 2,
189 scr->scr_height / 2);
190 } else if (wPreferences.move_display == WDIS_TOPLEFT) {
191 moveGeometryDisplayCentered(scr, 1, 1);
192 } else if (wPreferences.move_display == WDIS_FRAME_CENTER) {
193 moveGeometryDisplayCentered(scr, x + w/2, y + h/2);
195 WMMapWidget(scr->gview);
196 WSetGeometryViewShownPosition(scr->gview, x, y);
200 static void
201 showGeometry(WWindow *wwin, int x1, int y1, int x2, int y2, int direction)
203 WScreen *scr = wwin->screen_ptr;
204 Window root = scr->root_win;
205 GC gc = scr->line_gc;
206 int ty, by, my, x, y, mx, s;
207 char num[16];
208 XSegment segment[4];
209 int fw, fh;
211 ty = y1 + wwin->frame->top_width;
212 by = y2 - wwin->frame->bottom_width;
213 fw = WMWidthOfString(scr->info_text_font, "8888", 4);
214 fh = WMFontHeight(scr->info_text_font);
216 if (wPreferences.size_display == WDIS_NEW) {
217 XSetForeground(dpy, gc, scr->line_pixel);
219 /* vertical geometry */
220 if (((direction & LEFT) && (x2 < scr->scr_width - fw)) || (x1 < fw)) {
221 x = x2;
222 s = -15;
223 } else {
224 x = x1;
225 s = 15;
227 my = (ty + by) / 2;
229 /* top arrow */
230 /* end bar */
231 segment[0].x1 = x - (s + 6); segment[0].y1 = ty;
232 segment[0].x2 = x - (s - 10); segment[0].y2 = ty;
234 /* arrowhead */
235 segment[1].x1 = x - (s - 2); segment[1].y1 = ty + 1;
236 segment[1].x2 = x - (s - 5); segment[1].y2 = ty + 7;
238 segment[2].x1 = x - (s - 2); segment[2].y1 = ty + 1;
239 segment[2].x2 = x - (s + 1); segment[2].y2 = ty + 7;
241 /* line */
242 segment[3].x1 = x - (s - 2); segment[3].y1 = ty + 1;
243 segment[3].x2 = x - (s - 2); segment[3].y2 = my - fh/2 - 1;
245 XDrawSegments(dpy, root, gc, segment, 4);
247 /* bottom arrow */
248 /* end bar */
249 segment[0].y1 = by;
250 segment[0].y2 = by;
252 /* arrowhead */
253 segment[1].y1 = by - 1;
254 segment[1].y2 = by - 7;
256 segment[2].y1 = by - 1;
257 segment[2].y2 = by - 7;
259 /* line */
260 segment[3].y1 = my + fh/2 + 2;
261 segment[3].y2 = by - 1;
263 XDrawSegments(dpy, root, gc, segment, 4);
265 sprintf(num, "%i", (by - ty - wwin->normal_hints->base_height) /
266 wwin->normal_hints->height_inc);
267 fw = WMWidthOfString(scr->info_text_font, num, strlen(num));
269 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
271 /* Display the height. */
272 WMDrawString(scr->wmscreen, root, gc, scr->info_text_font,
273 x - s + 3 - fw/2, my - fh/2 + 1, num, strlen(num));
274 XSetForeground(dpy, gc, scr->line_pixel);
275 /* horizontal geometry */
276 if (y1 < 15) {
277 y = y2;
278 s = -15;
279 } else {
280 y = y1;
281 s = 15;
283 mx = x1 + (x2 - x1)/2;
284 sprintf(num, "%i", (x2 - x1 - wwin->normal_hints->base_width) /
285 wwin->normal_hints->width_inc);
286 fw = WMWidthOfString(scr->info_text_font, num, strlen(num));
288 /* left arrow */
289 /* end bar */
290 segment[0].x1 = x1; segment[0].y1 = y - (s + 6);
291 segment[0].x2 = x1; segment[0].y2 = y - (s - 10);
293 /* arrowhead */
294 segment[1].x1 = x1 + 7; segment[1].y1 = y - (s + 1);
295 segment[1].x2 = x1 + 1; segment[1].y2 = y - (s - 2);
297 segment[2].x1 = x1 + 1; segment[2].y1 = y - (s - 2);
298 segment[2].x2 = x1 + 7; segment[2].y2 = y - (s - 5);
300 /* line */
301 segment[3].x1 = x1 + 1; segment[3].y1 = y - (s - 2);
302 segment[3].x2 = mx - fw/2 - 2; segment[3].y2 = y - (s - 2);
304 XDrawSegments(dpy, root, gc, segment, 4);
306 /* right arrow */
307 /* end bar */
308 segment[0].x1 = x2 + 1;
309 segment[0].x2 = x2 + 1;
311 /* arrowhead */
312 segment[1].x1 = x2 - 6;
313 segment[1].x2 = x2;
315 segment[2].x1 = x2;
316 segment[2].x2 = x2 - 6;
318 /* line */
319 segment[3].x1 = mx + fw/2 + 2;
320 segment[3].x2 = x2;
322 XDrawSegments(dpy, root, gc, segment, 4);
324 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
326 /* Display the width. */
327 WMDrawString(scr->wmscreen, root, gc, scr->info_text_font,
328 mx - fw/2 + 1, y - s - fh/2 + 1, num, strlen(num));
329 } else {
330 WSetGeometryViewShownSize(scr->gview,
331 (x2 - x1 - wwin->normal_hints->base_width)
332 / wwin->normal_hints->width_inc,
333 (by - ty - wwin->normal_hints->base_height)
334 / wwin->normal_hints->height_inc);
339 static void
340 cycleGeometryDisplay(WWindow *wwin, int x, int y, int w, int h, int dir)
342 WScreen *scr = wwin->screen_ptr;
344 wPreferences.size_display++;
345 wPreferences.size_display %= NUM_DISPLAYS;
347 if (wPreferences.size_display == WDIS_NEW) {
348 WMUnmapWidget(scr->gview);
349 } else {
350 if (wPreferences.size_display == WDIS_CENTER) {
351 moveGeometryDisplayCentered(scr,
352 scr->scr_width / 2, scr->scr_height / 2);
353 } else if (wPreferences.size_display == WDIS_TOPLEFT) {
354 moveGeometryDisplayCentered(scr, 1, 1);
355 } else if (wPreferences.size_display == WDIS_FRAME_CENTER) {
356 moveGeometryDisplayCentered(scr, x + w/2, y + h/2);
358 WMMapWidget(scr->gview);
359 showGeometry(wwin, x, y, x + w, y + h, dir);
364 static void
365 mapGeometryDisplay(WWindow *wwin, int x, int y, int w, int h)
367 WScreen *scr = wwin->screen_ptr;
369 if (wPreferences.size_display == WDIS_NEW)
370 return;
372 if (wPreferences.size_display == WDIS_CENTER) {
373 moveGeometryDisplayCentered(scr, scr->scr_width / 2,
374 scr->scr_height / 2);
375 } else if (wPreferences.size_display == WDIS_TOPLEFT) {
376 moveGeometryDisplayCentered(scr, 1, 1);
377 } else if (wPreferences.size_display == WDIS_FRAME_CENTER) {
378 moveGeometryDisplayCentered(scr, x + w/2, y + h/2);
380 WMMapWidget(scr->gview);
381 showGeometry(wwin, x, y, x + w, y + h, 0);
386 static void
387 doWindowMove(WWindow *wwin, WMBag *bag, int dx, int dy)
389 WWindow *tmpw;
390 int x, y;
391 int scr_width = wwin->screen_ptr->scr_width;
392 int scr_height = wwin->screen_ptr->scr_height;
394 if (!bag || !WMGetBagItemCount(bag)) {
395 wWindowMove(wwin, wwin->frame_x + dx, wwin->frame_y + dy);
396 } else {
397 int i;
398 for (i = 0; i < WMGetBagItemCount(bag); i++) {
399 tmpw = WMGetFromBag(bag, i);
400 x = tmpw->frame_x + dx;
401 y = tmpw->frame_y + dy;
403 /* don't let windows become unreachable */
405 if (x + (int)tmpw->frame->core->width < 20)
406 x = 20 - (int)tmpw->frame->core->width;
407 else if (x + 20 > scr_width)
408 x = scr_width - 20;
410 if (y + (int)tmpw->frame->core->height < 20)
411 y = 20 - (int)tmpw->frame->core->height;
412 else if (y + 20 > scr_height)
413 y = scr_height - 20;
415 wWindowMove(tmpw, x, y);
421 static void
422 drawTransparentFrame(WWindow *wwin, int x, int y, int width, int height)
424 Window root = wwin->screen_ptr->root_win;
425 GC gc = wwin->screen_ptr->frame_gc;
426 int h = 0;
427 int bottom = 0;
429 if (!WFLAGP(wwin, no_titlebar) && !wwin->flags.shaded) {
430 h = WMFontHeight(wwin->screen_ptr->title_font) + (wPreferences.window_title_clearance + TITLEBAR_EXTEND_SPACE) * 2;
432 if (!WFLAGP(wwin, no_resizebar) && !wwin->flags.shaded) {
433 /* Can't use wwin-frame->bottom_width because, in some cases
434 (e.g. interactive placement), frame does not point to anything. */
435 bottom = RESIZEBAR_HEIGHT - 1;
437 XDrawRectangle(dpy, root, gc, x, y, width + 1, height + 1);
439 if (h > 0) {
440 XDrawLine(dpy, root, gc, x + 1, y + h, x + width + 1, y + h);
442 if (bottom > 0) {
443 XDrawLine(dpy, root, gc, x + 1,
444 y + height - bottom,
445 x + width + 1,
446 y + height - bottom);
451 static void
452 drawFrames(WWindow *wwin, WMBag *bag, int dx, int dy)
454 WWindow *tmpw;
455 int scr_width = wwin->screen_ptr->scr_width;
456 int scr_height = wwin->screen_ptr->scr_height;
457 int x, y;
459 if (!bag) {
461 x = wwin->frame_x + dx;
462 y = wwin->frame_y + dy;
464 drawTransparentFrame(wwin, x, y,
465 wwin->frame->core->width,
466 wwin->frame->core->height);
468 } else {
469 int i;
470 for (i = 0; i < WMGetBagItemCount(bag); i++) {
471 tmpw = WMGetFromBag(bag, i);
472 x = tmpw->frame_x + dx;
473 y = tmpw->frame_y + dy;
475 /* don't let windows become unreachable */
477 if (x + (int)tmpw->frame->core->width < 20)
478 x = 20 - (int)tmpw->frame->core->width;
479 else if (x + 20 > scr_width)
480 x = scr_width - 20;
482 if (y + (int)tmpw->frame->core->height < 20)
483 y = 20 - (int)tmpw->frame->core->height;
484 else if (y + 20 > scr_height)
485 y = scr_height - 20;
487 drawTransparentFrame(tmpw, x, y, tmpw->frame->core->width,
488 tmpw->frame->core->height);
495 static void
496 flushMotion()
498 XEvent ev;
500 XSync(dpy, False);
501 while (XCheckMaskEvent(dpy, ButtonMotionMask, &ev)) ;
505 static void
506 crossWorkspace(WScreen *scr, WWindow *wwin, int opaque_move,
507 int new_workspace, int rewind)
509 /* do not let window be unmapped */
510 if (opaque_move) {
511 wwin->flags.changing_workspace = 1;
512 wWindowChangeWorkspace(wwin, new_workspace);
514 /* go to new workspace */
515 wWorkspaceChange(scr, new_workspace);
517 wwin->flags.changing_workspace = 0;
519 if (rewind)
520 XWarpPointer(dpy, None, None, 0, 0, 0, 0, scr->scr_width - 20, 0);
521 else
522 XWarpPointer(dpy, None, None, 0, 0, 0, 0, -(scr->scr_width - 20), 0);
524 flushMotion();
526 if (!opaque_move) {
527 XGrabPointer(dpy, scr->root_win, True, PointerMotionMask
528 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
529 GrabModeAsync, None, wCursor[WCUR_MOVE], CurrentTime);
536 typedef struct {
537 /* arrays of WWindows sorted by the respective border position */
538 WWindow **topList; /* top border */
539 WWindow **leftList; /* left border */
540 WWindow **rightList; /* right border */
541 WWindow **bottomList; /* bottom border */
542 int count;
544 /* index of window in the above lists indicating the relative position
545 * of the window with the others */
546 int topIndex;
547 int leftIndex;
548 int rightIndex;
549 int bottomIndex;
551 int rubCount; /* for workspace switching */
553 int winWidth, winHeight; /* width/height of the window */
554 int realX, realY; /* actual position of the window */
555 int calcX, calcY; /* calculated position of window */
556 int omouseX, omouseY; /* old mouse position */
557 int mouseX, mouseY; /* last known position of the pointer */
558 } MoveData;
560 #define WTOP(w) (w)->frame_y
561 #define WLEFT(w) (w)->frame_x
562 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width + FRAME_BORDER_WIDTH)
563 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height + FRAME_BORDER_WIDTH)
565 static int
566 compareWTop(const void *a, const void *b)
568 WWindow *wwin1 = *(WWindow**)a;
569 WWindow *wwin2 = *(WWindow**)b;
571 if (WTOP(wwin1) > WTOP(wwin2))
572 return -1;
573 else if (WTOP(wwin1) < WTOP(wwin2))
574 return 1;
575 else
576 return 0;
580 static int
581 compareWLeft(const void *a, const void *b)
583 WWindow *wwin1 = *(WWindow**)a;
584 WWindow *wwin2 = *(WWindow**)b;
586 if (WLEFT(wwin1) > WLEFT(wwin2))
587 return -1;
588 else if (WLEFT(wwin1) < WLEFT(wwin2))
589 return 1;
590 else
591 return 0;
595 static int
596 compareWRight(const void *a, const void *b)
598 WWindow *wwin1 = *(WWindow**)a;
599 WWindow *wwin2 = *(WWindow**)b;
601 if (WRIGHT(wwin1) < WRIGHT(wwin2))
602 return -1;
603 else if (WRIGHT(wwin1) > WRIGHT(wwin2))
604 return 1;
605 else
606 return 0;
611 static int
612 compareWBottom(const void *a, const void *b)
614 WWindow *wwin1 = *(WWindow**)a;
615 WWindow *wwin2 = *(WWindow**)b;
617 if (WBOTTOM(wwin1) < WBOTTOM(wwin2))
618 return -1;
619 else if (WBOTTOM(wwin1) > WBOTTOM(wwin2))
620 return 1;
621 else
622 return 0;
626 static void
627 updateResistance(WWindow *wwin, MoveData *data, int newX, int newY)
629 int i;
630 int newX2 = newX + data->winWidth;
631 int newY2 = newY + data->winHeight;
632 Bool ok = False;
634 if (newX < data->realX) {
635 if (data->rightIndex > 0
636 && newX < WRIGHT(data->rightList[data->rightIndex-1])) {
637 ok = True;
638 } else if (data->leftIndex <= data->count-1
639 && newX2 <= WLEFT(data->leftList[data->leftIndex])) {
640 ok = True;
642 } else if (newX > data->realX) {
643 if (data->leftIndex > 0
644 && newX2 > WLEFT(data->leftList[data->leftIndex-1])) {
645 ok = True;
646 } else if (data->rightIndex <= data->count-1
647 && newX >= WRIGHT(data->rightList[data->rightIndex])) {
648 ok = True;
652 if (!ok) {
653 if (newY < data->realY) {
654 if (data->bottomIndex > 0
655 && newY < WBOTTOM(data->bottomList[data->bottomIndex-1])) {
656 ok = True;
657 } else if (data->topIndex <= data->count-1
658 && newY2 <= WTOP(data->topList[data->topIndex])) {
659 ok = True;
661 } else if (newY > data->realY) {
662 if (data->topIndex > 0
663 && newY2 > WTOP(data->topList[data->topIndex-1])) {
664 ok = True;
665 } else if (data->bottomIndex <= data->count-1
666 && newY >= WBOTTOM(data->bottomList[data->bottomIndex])) {
667 ok = True;
672 if (!ok)
673 return;
675 /* TODO: optimize this */
676 if (data->realY < WBOTTOM(data->bottomList[0])) {
677 data->bottomIndex = 0;
679 if (data->realX < WRIGHT(data->rightList[0])) {
680 data->rightIndex = 0;
682 if ((data->realX + data->winWidth) > WLEFT(data->leftList[0])) {
683 data->leftIndex = 0;
685 if ((data->realY + data->winHeight) > WTOP(data->topList[0])) {
686 data->topIndex = 0;
688 for (i = 0; i < data->count; i++) {
689 if (data->realY > WBOTTOM(data->bottomList[i])) {
690 data->bottomIndex = i + 1;
692 if (data->realX > WRIGHT(data->rightList[i])) {
693 data->rightIndex = i + 1;
695 if ((data->realX + data->winWidth) < WLEFT(data->leftList[i])) {
696 data->leftIndex = i + 1;
698 if ((data->realY + data->winHeight) < WTOP(data->topList[i])) {
699 data->topIndex = i + 1;
705 static void
706 freeMoveData(MoveData *data)
708 if (data->topList)
709 free(data->topList);
710 if (data->leftList)
711 free(data->leftList);
712 if (data->rightList)
713 free(data->rightList);
714 if (data->bottomList)
715 free(data->bottomList);
719 static void
720 updateMoveData(WWindow *wwin, MoveData *data)
722 WScreen *scr = wwin->screen_ptr;
723 WWindow *tmp;
724 int i;
726 data->count = 0;
727 tmp = scr->focused_window;
728 while (tmp) {
729 if (tmp != wwin && scr->current_workspace == tmp->frame->workspace
730 && !tmp->flags.miniaturized
731 && !tmp->flags.hidden
732 && !tmp->flags.obscured
733 && !WFLAGP(tmp, sunken)) {
734 data->topList[data->count] = tmp;
735 data->leftList[data->count] = tmp;
736 data->rightList[data->count] = tmp;
737 data->bottomList[data->count] = tmp;
738 data->count++;
740 tmp = tmp->prev;
743 if (data->count == 0) {
744 data->topIndex = 0;
745 data->leftIndex = 0;
746 data->rightIndex = 0;
747 data->bottomIndex = 0;
748 return;
752 * order from closest to the border of the screen to farthest
754 qsort(data->topList, data->count, sizeof(WWindow**), compareWTop);
755 qsort(data->leftList, data->count, sizeof(WWindow**), compareWLeft);
756 qsort(data->rightList, data->count, sizeof(WWindow**), compareWRight);
757 qsort(data->bottomList, data->count, sizeof(WWindow**), compareWBottom);
759 /* figure the position of the window relative to the others */
761 data->topIndex = -1;
762 data->leftIndex = -1;
763 data->rightIndex = -1;
764 data->bottomIndex = -1;
766 if (WTOP(wwin) < WBOTTOM(data->bottomList[0])) {
767 data->bottomIndex = 0;
769 if (WLEFT(wwin) < WRIGHT(data->rightList[0])) {
770 data->rightIndex = 0;
772 if (WRIGHT(wwin) > WLEFT(data->leftList[0])) {
773 data->leftIndex = 0;
775 if (WBOTTOM(wwin) > WTOP(data->topList[0])) {
776 data->topIndex = 0;
778 for (i = 0; i < data->count; i++) {
779 if (WTOP(wwin) >= WBOTTOM(data->bottomList[i])) {
780 data->bottomIndex = i + 1;
782 if (WLEFT(wwin) >= WRIGHT(data->rightList[i])) {
783 data->rightIndex = i + 1;
785 if (WRIGHT(wwin) <= WLEFT(data->leftList[i])) {
786 data->leftIndex = i + 1;
788 if (WBOTTOM(wwin) <= WTOP(data->topList[i])) {
789 data->topIndex = i + 1;
795 static void
796 initMoveData(WWindow *wwin, MoveData *data)
798 int i;
799 WWindow *tmp;
801 memset(data, 0, sizeof(MoveData));
803 for (i = 0, tmp = wwin->screen_ptr->focused_window;
804 tmp != NULL;
805 tmp = tmp->prev, i++);
807 if (i > 1) {
808 data->topList = wmalloc(sizeof(WWindow*) * i);
809 data->leftList = wmalloc(sizeof(WWindow*) * i);
810 data->rightList = wmalloc(sizeof(WWindow*) * i);
811 data->bottomList = wmalloc(sizeof(WWindow*) * i);
813 updateMoveData(wwin, data);
816 data->realX = wwin->frame_x;
817 data->realY = wwin->frame_y;
818 data->calcX = wwin->frame_x;
819 data->calcY = wwin->frame_y;
821 data->winWidth = wwin->frame->core->width + 2;
822 data->winHeight = wwin->frame->core->height + 2;
826 static Bool
827 checkWorkspaceChange(WWindow *wwin, MoveData *data, Bool opaqueMove)
829 WScreen *scr = wwin->screen_ptr;
830 Bool changed = False;
832 if (data->mouseX <= 1) {
833 if (scr->current_workspace > 0) {
835 crossWorkspace(scr, wwin, opaqueMove, scr->current_workspace - 1,
836 True);
837 changed = True;
838 data->rubCount = 0;
840 } else if (scr->current_workspace == 0 && wPreferences.ws_cycle) {
842 crossWorkspace(scr, wwin, opaqueMove, scr->workspace_count - 1,
843 True);
844 changed = True;
845 data->rubCount = 0;
847 } else if (data->mouseX >= scr->scr_width - 2) {
849 if (scr->current_workspace == scr->workspace_count - 1) {
851 if (wPreferences.ws_cycle
852 || scr->workspace_count == MAX_WORKSPACES) {
854 crossWorkspace(scr, wwin, opaqueMove, 0, False);
855 changed = True;
856 data->rubCount = 0;
858 /* if user insists on trying to go to next workspace even when
859 * it's already the last, create a new one */
860 else if (data->omouseX == data->mouseX
861 && wPreferences.ws_advance) {
863 /* detect user "rubbing" the window against the edge */
864 if (data->rubCount > 0
865 && data->omouseY - data->mouseY > MOVE_THRESHOLD) {
867 data->rubCount = -(data->rubCount + 1);
869 } else if (data->rubCount <= 0
870 && data->mouseY - data->omouseY > MOVE_THRESHOLD) {
872 data->rubCount = -data->rubCount + 1;
875 /* create a new workspace */
876 if (abs(data->rubCount) > 2) {
877 /* go to next workspace */
878 wWorkspaceNew(scr);
880 crossWorkspace(scr, wwin, opaqueMove,
881 scr->current_workspace+1, False);
882 changed = True;
883 data->rubCount = 0;
885 } else if (scr->current_workspace < scr->workspace_count) {
887 /* go to next workspace */
888 crossWorkspace(scr, wwin, opaqueMove,
889 scr->current_workspace+1, False);
890 changed = True;
891 data->rubCount = 0;
893 } else {
894 data->rubCount = 0;
897 return changed;
901 static void
902 updateWindowPosition(WWindow *wwin, MoveData *data, Bool doResistance,
903 Bool opaqueMove, int newMouseX, int newMouseY)
905 WScreen *scr = wwin->screen_ptr;
906 int dx, dy; /* how much mouse moved */
907 int winL, winR, winT, winB; /* requested new window position */
908 int newX, newY; /* actual new window position */
909 Bool hresist, vresist;
910 Bool updateIndex;
911 Bool attract;
913 hresist = False;
914 vresist = False;
916 updateIndex = False;
918 /* check the direction of the movement */
919 dx = newMouseX - data->mouseX;
920 dy = newMouseY - data->mouseY;
922 data->omouseX = data->mouseX;
923 data->omouseY = data->mouseY;
924 data->mouseX = newMouseX;
925 data->mouseY = newMouseY;
927 winL = data->calcX + dx;
928 winR = data->calcX + data->winWidth + dx;
929 winT = data->calcY + dy;
930 winB = data->calcY + data->winHeight + dy;
932 newX = data->realX;
933 newY = data->realY;
935 if (doResistance) {
936 int l_edge, r_edge;
937 int edge_l, edge_r;
938 int t_edge, b_edge;
939 int edge_t, edge_b;
940 int resist;
942 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
943 attract = wPreferences.attract;
944 /* horizontal movement: check horizontal edge resistances */
945 if (dx || dy) {
946 int i;
947 /* window is the leftmost window: check against screen edge */
948 l_edge = scr->totalUsableArea.x1;
949 r_edge = scr->totalUsableArea.x2 + resist;
950 edge_l = scr->totalUsableArea.x1 - resist;
951 edge_r = scr->totalUsableArea.x2;
953 /* 1 */
954 if ((data->rightIndex >= 0) && (data->rightIndex <= data->count)) {
955 WWindow *looprw;
957 for (i = data->rightIndex - 1; i >= 0; i--) {
958 looprw = data->rightList[i];
959 if (!(data->realY > WBOTTOM(looprw)
960 || (data->realY + data->winHeight) < WTOP(looprw))) {
961 if (attract
962 || ((data->realX < (WRIGHT(looprw) + 2)) && dx < 0)) {
963 l_edge = WRIGHT(looprw) + 1;
964 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
966 break;
970 if (attract) {
971 for (i = data->rightIndex; i < data->count; i++) {
972 looprw = data->rightList[i];
973 if(!(data->realY > WBOTTOM(looprw)
974 || (data->realY + data->winHeight) < WTOP(looprw))) {
975 r_edge = WRIGHT(looprw) + 1;
976 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
977 break;
983 if ((data->leftIndex >= 0) && (data->leftIndex <= data->count)) {
984 WWindow *looprw;
986 for (i = data->leftIndex - 1; i >= 0; i--) {
987 looprw = data->leftList[i];
988 if (!(data->realY > WBOTTOM(looprw)
989 || (data->realY + data->winHeight) < WTOP(looprw))) {
990 if (attract
991 || (((data->realX + data->winWidth) > (WLEFT(looprw) - 1)) && dx > 0)) {
992 edge_r = WLEFT(looprw);
993 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
995 break;
999 if (attract)
1000 for (i = data->leftIndex; i < data->count; i++) {
1001 looprw = data->leftList[i];
1002 if(!(data->realY > WBOTTOM(looprw)
1003 || (data->realY + data->winHeight) < WTOP(looprw))) {
1004 edge_l = WLEFT(looprw);
1005 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1006 break;
1012 printf("%d %d\n",winL,winR);
1013 printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);
1016 if ((winL - l_edge) < (r_edge - winL)) {
1017 if (resist > 0) {
1018 if ((attract && winL <= l_edge + resist && winL >= l_edge - resist)
1019 || (dx < 0 && winL <= l_edge && winL >= l_edge - resist)) {
1020 newX = l_edge;
1021 hresist = True;
1024 } else {
1025 if (resist > 0 && attract && winL >= r_edge - resist && winL <= r_edge + resist) {
1026 newX = r_edge;
1027 hresist = True;
1031 if ((winR - edge_l) < (edge_r - winR)) {
1032 if (resist > 0 && attract && winR <= edge_l + resist && winR >= edge_l - resist) {
1033 newX = edge_l - data->winWidth;
1034 hresist = True;
1036 } else {
1037 if (resist > 0) {
1038 if ((attract && winR >= edge_r - resist && winR <= edge_r + resist)
1039 || (dx > 0 && winR >= edge_r && winR <= edge_r + resist)) {
1040 newX = edge_r - data->winWidth;
1041 hresist = True;
1046 /* VeRT */
1047 t_edge = scr->totalUsableArea.y1;
1048 b_edge = scr->totalUsableArea.y2 + resist;
1049 edge_t = scr->totalUsableArea.y1 - resist;
1050 edge_b = scr->totalUsableArea.y2;
1052 if ((data->bottomIndex >= 0) && (data->bottomIndex <= data->count)) {
1053 WWindow *looprw;
1055 for (i = data->bottomIndex - 1; i >= 0; i--) {
1056 looprw = data->bottomList[i];
1057 if (!(data->realX > WRIGHT(looprw)
1058 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1059 if (attract
1060 || ((data->realY < (WBOTTOM(looprw) + 2)) && dy < 0)) {
1061 t_edge = WBOTTOM(looprw) + 1;
1062 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1064 break;
1068 if (attract) {
1069 for (i = data->bottomIndex; i < data->count; i++) {
1070 looprw = data->bottomList[i];
1071 if(!(data->realX > WRIGHT(looprw)
1072 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1073 b_edge = WBOTTOM(looprw) + 1;
1074 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1075 break;
1081 if ((data->topIndex >= 0) && (data->topIndex <= data->count)) {
1082 WWindow *looprw;
1084 for (i = data->topIndex - 1; i >= 0; i--) {
1085 looprw = data->topList[i];
1086 if (!(data->realX > WRIGHT(looprw)
1087 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1088 if (attract
1089 || (((data->realY + data->winHeight) > (WTOP(looprw) - 1)) && dy > 0)) {
1090 edge_b = WTOP(looprw);
1091 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1093 break;
1097 if (attract)
1098 for (i = data->topIndex; i < data->count; i++) {
1099 looprw = data->topList[i];
1100 if(!(data->realX > WRIGHT(looprw)
1101 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1102 edge_t = WTOP(looprw);
1103 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1104 break;
1109 if ((winT - t_edge) < (b_edge - winT)) {
1110 if (resist > 0) {
1111 if ((attract && winT <= t_edge + resist && winT >= t_edge - resist)
1112 || (dy < 0 && winT <= t_edge && winT >= t_edge - resist)) {
1113 newY = t_edge;
1114 vresist = True;
1118 else {
1119 if (resist > 0 && attract && winT >= b_edge - resist && winT <= b_edge + resist) {
1120 newY = b_edge;
1121 vresist = True;
1125 if ((winB - edge_t) < (edge_b - winB)) {
1126 if (resist > 0 && attract && winB <= edge_t + resist && winB >= edge_t - resist) {
1127 newY = edge_t - data->winHeight;
1128 vresist = True;
1131 else {
1132 if (resist > 0) {
1133 if ((attract && winB >= edge_b - resist && winB <= edge_b + resist)
1134 || (dy > 0 && winB >= edge_b && winB <= edge_b + resist)) {
1135 newY = edge_b - data->winHeight;
1136 vresist = True;
1141 /* END VeRT */
1145 /* update window position */
1146 data->calcX += dx;
1147 data->calcY += dy;
1149 if (((dx > 0 && data->calcX - data->realX > 0)
1150 || (dx < 0 && data->calcX - data->realX < 0)) && !hresist)
1151 newX = data->calcX;
1153 if (((dy > 0 && data->calcY - data->realY > 0)
1154 || (dy < 0 && data->calcY - data->realY < 0)) && !vresist)
1155 newY = data->calcY;
1157 if (data->realX != newX || data->realY != newY) {
1159 if (wPreferences.move_display == WDIS_NEW
1160 && !scr->selected_windows) {
1161 showPosition(wwin, data->realX, data->realY);
1163 if (opaqueMove) {
1164 doWindowMove(wwin, scr->selected_windows,
1165 newX - wwin->frame_x,
1166 newY - wwin->frame_y);
1167 } else {
1168 /* erase frames */
1169 drawFrames(wwin, scr->selected_windows,
1170 data->realX - wwin->frame_x,
1171 data->realY - wwin->frame_y);
1174 if (!scr->selected_windows
1175 && wPreferences.move_display == WDIS_FRAME_CENTER) {
1177 moveGeometryDisplayCentered(scr, newX + data->winWidth/2,
1178 newY + data->winHeight/2);
1181 if (!opaqueMove) {
1182 /* draw frames */
1183 drawFrames(wwin, scr->selected_windows,
1184 newX - wwin->frame_x,
1185 newY - wwin->frame_y);
1188 if (!scr->selected_windows) {
1189 showPosition(wwin, newX, newY);
1194 /* recalc relative window position */
1195 if (doResistance && (data->realX != newX || data->realY != newY)) {
1196 updateResistance(wwin, data, newX, newY);
1199 data->realX = newX;
1200 data->realY = newY;
1204 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1207 wKeyboardMoveResizeWindow(WWindow *wwin)
1209 WScreen *scr = wwin->screen_ptr;
1210 Window root = scr->root_win;
1211 XEvent event;
1212 int w = wwin->frame->core->width;
1213 int h = wwin->frame->core->height;
1214 int scr_width = wwin->screen_ptr->scr_width;
1215 int scr_height = wwin->screen_ptr->scr_height;
1216 int vert_border = wwin->frame->top_width + wwin->frame->bottom_width;
1217 int src_x = wwin->frame_x;
1218 int src_y = wwin->frame_y;
1219 int done,off_x,off_y,ww,wh;
1220 int kspeed = _KS;
1221 Time lastTime = 0;
1222 KeySym keysym=NoSymbol;
1223 int moment=0;
1224 KeyCode shiftl,shiftr,ctrll,ctrlmode;
1226 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1227 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1228 ctrll = XKeysymToKeycode(dpy, XK_Control_L);
1229 ctrlmode=done=off_x=off_y=0;
1231 XSync(dpy, False);
1232 wusleep(10000);
1233 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync, CurrentTime);
1235 if (!wwin->flags.selected) {
1236 wUnselectWindows(scr);
1238 XGrabServer(dpy);
1239 XGrabPointer(dpy, scr->root_win, True, PointerMotionMask
1240 |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
1241 GrabModeAsync, None, wCursor[WCUR_DEFAULT], CurrentTime);
1243 if (wwin->flags.shaded || scr->selected_windows) {
1244 if(scr->selected_windows)
1245 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1246 else drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1247 if(!scr->selected_windows)
1248 mapPositionDisplay(wwin, src_x, src_y, w, h);
1249 } else {
1250 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1252 ww=w;
1253 wh=h;
1254 while(1) {
1256 looper.ox=off_x;
1257 looper.oy=off_y;
1259 WMMaskEvent(dpy, KeyPressMask | ButtonReleaseMask
1260 | ButtonPressMask | ExposureMask, &event);
1261 if (wwin->flags.shaded || scr->selected_windows) {
1262 if(scr->selected_windows)
1263 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1264 else drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1265 /*** I HATE EDGE RESISTANCE - ]d ***/
1267 else {
1268 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, ww, wh);
1271 if(ctrlmode)
1272 showGeometry(wwin, src_x+off_x, src_y+off_y, src_x+off_x+ww, src_y+off_y+wh,0);
1274 XUngrabServer(dpy);
1275 XSync(dpy, False);
1277 switch (event.type) {
1278 case KeyPress:
1279 /* accelerate */
1280 if (event.xkey.time - lastTime > 50) {
1281 kspeed/=(1 + (event.xkey.time - lastTime)/100);
1282 } else {
1283 if (kspeed < 20) {
1284 kspeed++;
1287 if (kspeed < _KS) kspeed = _KS;
1288 lastTime = event.xkey.time;
1290 if (event.xkey.state & ControlMask && !wwin->flags.shaded) {
1291 ctrlmode=1;
1292 wUnselectWindows(scr);
1294 else {
1295 ctrlmode=0;
1297 if (event.xkey.keycode == shiftl || event.xkey.keycode == shiftr) {
1298 if (ctrlmode)
1299 cycleGeometryDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh, 0);
1300 else
1301 cyclePositionDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh);
1303 else {
1305 keysym = XLookupKeysym(&event.xkey, 0);
1306 switch (keysym) {
1307 case XK_Return:
1308 done=2;
1309 break;
1310 case XK_Escape:
1311 done=1;
1312 break;
1313 case XK_Up:
1314 case XK_KP_Up:
1315 case XK_k:
1316 if (ctrlmode){
1317 if (moment != UP)
1318 h = wh;
1319 h-=kspeed;
1320 moment = UP;
1321 if (h < 1) h = 1;
1323 else off_y-=kspeed;
1324 break;
1325 case XK_Down:
1326 case XK_KP_Down:
1327 case XK_j:
1328 if (ctrlmode){
1329 if (moment != DOWN)
1330 h = wh;
1331 h+=kspeed;
1332 moment = DOWN;
1334 else off_y+=kspeed;
1335 break;
1336 case XK_Left:
1337 case XK_KP_Left:
1338 case XK_h:
1339 if (ctrlmode) {
1340 if (moment != LEFT)
1341 w = ww;
1342 w-=kspeed;
1343 if (w < 1) w = 1;
1344 moment = LEFT;
1346 else off_x-=kspeed;
1347 break;
1348 case XK_Right:
1349 case XK_KP_Right:
1350 case XK_l:
1351 if (ctrlmode) {
1352 if (moment != RIGHT)
1353 w = ww;
1354 w+=kspeed;
1355 moment = RIGHT;
1357 else off_x+=kspeed;
1358 break;
1361 ww=w;wh=h;
1362 wh-=vert_border;
1363 wWindowConstrainSize(wwin, &ww, &wh);
1364 wh+=vert_border;
1366 if (wPreferences.ws_cycle){
1367 if (src_x + off_x + ww < 20){
1368 if(!scr->current_workspace) {
1369 wWorkspaceChange(scr, scr->workspace_count-1);
1371 else wWorkspaceChange(scr, scr->current_workspace-1);
1372 off_x += scr_width;
1374 else if (src_x + off_x + 20 > scr_width){
1375 if(scr->current_workspace == scr->workspace_count-1) {
1376 wWorkspaceChange(scr, 0);
1378 else wWorkspaceChange(scr, scr->current_workspace+1);
1379 off_x -= scr_width;
1382 else {
1383 if (src_x + off_x + ww < 20)
1384 off_x = 20 - ww - src_x;
1385 else if (src_x + off_x + 20 > scr_width)
1386 off_x = scr_width - 20 - src_x;
1389 if (src_y + off_y + wh < 20) {
1390 off_y = 20 - wh - src_y;
1392 else if (src_y + off_y + 20 > scr_height) {
1393 off_y = scr_height - 20 - src_y;
1396 break;
1397 case ButtonPress:
1398 case ButtonRelease:
1399 done=1;
1400 break;
1401 default:
1402 WMHandleEvent(&event);
1403 break;
1406 XGrabServer(dpy);
1407 /*xxx*/
1409 if (wwin->flags.shaded && !scr->selected_windows){
1410 moveGeometryDisplayCentered(scr, src_x+off_x + w/2, src_y+off_y + h/2);
1411 } else {
1412 if (ctrlmode) {
1413 WMUnmapWidget(scr->gview);
1414 mapGeometryDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh);
1415 } else if(!scr->selected_windows) {
1416 WMUnmapWidget(scr->gview);
1417 mapPositionDisplay(wwin, src_x+off_x, src_y+off_y, ww, wh);
1421 if (wwin->flags.shaded || scr->selected_windows) {
1422 if (scr->selected_windows)
1423 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1424 else
1425 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1426 } else {
1427 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, ww, wh);
1431 if (ctrlmode) {
1432 showGeometry(wwin, src_x+off_x, src_y+off_y, src_x+off_x+ww, src_y+off_y+wh,0);
1433 } else if(!scr->selected_windows)
1434 showPosition(wwin, src_x+off_x, src_y+off_y);
1435 /**/
1437 if(done){
1438 scr->keymove_tick=0;
1440 WMDeleteTimerWithClientData(&looper);
1442 if (wwin->flags.shaded || scr->selected_windows) {
1443 if(scr->selected_windows)
1444 drawFrames(wwin,scr->selected_windows,off_x,off_y);
1445 else drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, w, h);
1447 else {
1448 drawTransparentFrame(wwin, src_x+off_x, src_y+off_y, ww, wh);
1451 if (ctrlmode) {
1452 showGeometry(wwin, src_x+off_x, src_y+off_y, src_x+off_x+ww, src_y+off_y+wh,0);
1453 WMUnmapWidget(scr->gview);
1454 } else
1455 WMUnmapWidget(scr->gview);
1457 XUngrabKeyboard(dpy, CurrentTime);
1458 XUngrabPointer(dpy, CurrentTime);
1459 XUngrabServer(dpy);
1461 if(done==2) {
1462 if (wwin->flags.shaded || scr->selected_windows) {
1463 if (!scr->selected_windows) {
1464 wWindowMove(wwin, src_x+off_x, src_y+off_y);
1465 wWindowSynthConfigureNotify(wwin);
1466 } else {
1467 int i;
1468 WMBag *bag = scr->selected_windows;
1469 doWindowMove(wwin,scr->selected_windows,off_x,off_y);
1470 for (i = 0; i < WMGetBagItemCount(bag); i++) {
1471 wWindowSynthConfigureNotify(WMGetFromBag(bag, i));
1474 } else {
1475 if (wwin->client.width != ww)
1476 wwin->flags.user_changed_width = 1;
1478 if (wwin->client.height != wh - vert_border)
1479 wwin->flags.user_changed_height = 1;
1481 wWindowConfigure(wwin, src_x+off_x, src_y+off_y,
1482 ww, wh - vert_border);
1483 wWindowSynthConfigureNotify(wwin);
1485 wWindowChangeWorkspace(wwin, scr->current_workspace);
1486 wSetFocusTo(scr, wwin);
1488 return 1;
1495 *----------------------------------------------------------------------
1496 * wMouseMoveWindow--
1497 * Move the named window and the other selected ones (if any),
1498 * interactively. Also shows the position of the window, if only one
1499 * window is being moved.
1500 * If the window is not on the selected window list, the selected
1501 * windows are deselected.
1502 * If shift is pressed during the operation, the position display
1503 * is changed to another type.
1505 * Returns:
1506 * True if the window was moved, False otherwise.
1508 * Side effects:
1509 * The window(s) position is changed, and the client(s) are
1510 * notified about that.
1511 * The position display configuration may be changed.
1512 *----------------------------------------------------------------------
1515 wMouseMoveWindow(WWindow *wwin, XEvent *ev)
1517 WScreen *scr = wwin->screen_ptr;
1518 XEvent event;
1519 Window root = scr->root_win;
1520 KeyCode shiftl, shiftr;
1521 Bool done = False;
1522 int started = 0;
1523 int warped = 0;
1524 /* This needs not to change while moving, else bad things can happen */
1525 int opaqueMove = wPreferences.opaque_move;
1526 MoveData moveData;
1527 #ifdef GHOST_WINDOW_MOVE
1528 RImage *rimg;
1530 rimg = InitGhostWindowMove(scr);
1531 #endif
1534 if (wPreferences.opaque_move && !wPreferences.use_saveunders) {
1535 XSetWindowAttributes attr;
1537 attr.save_under = True;
1538 XChangeWindowAttributes(dpy, wwin->frame->core->window,
1539 CWSaveUnder, &attr);
1543 initMoveData(wwin, &moveData);
1545 moveData.mouseX = ev->xmotion.x_root;
1546 moveData.mouseY = ev->xmotion.y_root;
1548 if (!wwin->flags.selected) {
1549 /* this window is not selected, unselect others and move only wwin */
1550 wUnselectWindows(scr);
1552 #ifdef DEBUG
1553 puts("Moving window");
1554 #endif
1555 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1556 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1557 while (!done) {
1558 if (warped) {
1559 int junk;
1560 Window junkw;
1562 /* XWarpPointer() doesn't seem to generate Motion events, so
1563 we've got to simulate them */
1564 XQueryPointer(dpy, root, &junkw, &junkw, &event.xmotion.x_root,
1565 &event.xmotion.y_root, &junk, &junk,
1566 (unsigned *) &junk);
1567 } else {
1568 WMMaskEvent(dpy, KeyPressMask | ButtonMotionMask
1569 | PointerMotionHintMask
1570 | ButtonReleaseMask | ButtonPressMask | ExposureMask,
1571 &event);
1573 if (event.type == MotionNotify) {
1574 /* compress MotionNotify events */
1575 while (XCheckMaskEvent(dpy, ButtonMotionMask, &event)) ;
1576 if (!checkMouseSamplingRate(&event))
1577 continue;
1580 switch (event.type) {
1581 case KeyPress:
1582 if ((event.xkey.keycode == shiftl || event.xkey.keycode == shiftr)
1583 && started && !scr->selected_windows) {
1585 if (!opaqueMove) {
1586 drawFrames(wwin, scr->selected_windows,
1587 moveData.realX - wwin->frame_x,
1588 moveData.realY - wwin->frame_y);
1591 if (wPreferences.move_display == WDIS_NEW
1592 && !scr->selected_windows) {
1593 showPosition(wwin, moveData.realX, moveData.realY);
1594 XUngrabServer(dpy);
1596 cyclePositionDisplay(wwin, moveData.realX, moveData.realY,
1597 moveData.winWidth, moveData.winHeight);
1599 if (wPreferences.move_display == WDIS_NEW
1600 && !scr->selected_windows) {
1601 XGrabServer(dpy);
1602 showPosition(wwin, moveData.realX, moveData.realY);
1605 if (!opaqueMove) {
1606 drawFrames(wwin, scr->selected_windows,
1607 moveData.realX - wwin->frame_x,
1608 moveData.realY - wwin->frame_y);
1611 break;
1613 case MotionNotify:
1614 if (started) {
1615 updateWindowPosition(wwin, &moveData,
1616 scr->selected_windows == NULL
1617 && wPreferences.edge_resistance > 0,
1618 opaqueMove,
1619 event.xmotion.x_root,
1620 event.xmotion.y_root);
1622 if (!warped && !wPreferences.no_autowrap) {
1623 int oldWorkspace = scr->current_workspace;
1625 if (wPreferences.move_display == WDIS_NEW
1626 && !scr->selected_windows) {
1627 showPosition(wwin, moveData.realX, moveData.realY);
1628 XUngrabServer(dpy);
1630 if (!opaqueMove) {
1631 drawFrames(wwin, scr->selected_windows,
1632 moveData.realX - wwin->frame_x,
1633 moveData.realY - wwin->frame_y);
1635 if (checkWorkspaceChange(wwin, &moveData, opaqueMove)) {
1636 if (scr->current_workspace != oldWorkspace
1637 && wPreferences.edge_resistance > 0
1638 && scr->selected_windows == NULL)
1639 updateMoveData(wwin, &moveData);
1640 warped = 1;
1642 if (!opaqueMove) {
1643 drawFrames(wwin, scr->selected_windows,
1644 moveData.realX - wwin->frame_x,
1645 moveData.realY - wwin->frame_y);
1647 if (wPreferences.move_display == WDIS_NEW
1648 && !scr->selected_windows) {
1649 XSync(dpy, False);
1650 showPosition(wwin, moveData.realX, moveData.realY);
1651 XGrabServer(dpy);
1653 } else {
1654 warped = 0;
1656 } else if (abs(ev->xmotion.x_root - event.xmotion.x_root) >= MOVE_THRESHOLD
1657 || abs(ev->xmotion.y_root - event.xmotion.y_root) >= MOVE_THRESHOLD) {
1659 XChangeActivePointerGrab(dpy, ButtonMotionMask
1660 | ButtonReleaseMask | ButtonPressMask,
1661 wCursor[WCUR_MOVE], CurrentTime);
1662 started = 1;
1663 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync,
1664 CurrentTime);
1666 if (!scr->selected_windows)
1667 mapPositionDisplay(wwin, moveData.realX, moveData.realY,
1668 moveData.winWidth, moveData.winHeight);
1670 if (started && !opaqueMove)
1671 drawFrames(wwin, scr->selected_windows, 0, 0);
1673 if (!opaqueMove || (wPreferences.move_display==WDIS_NEW
1674 && !scr->selected_windows)) {
1675 XGrabServer(dpy);
1676 if (wPreferences.move_display==WDIS_NEW)
1677 showPosition(wwin, moveData.realX, moveData.realY);
1680 break;
1682 case ButtonPress:
1683 break;
1685 case ButtonRelease:
1686 if (event.xbutton.button != ev->xbutton.button)
1687 break;
1689 if (started) {
1690 if (!opaqueMove) {
1691 drawFrames(wwin, scr->selected_windows,
1692 moveData.realX - wwin->frame_x,
1693 moveData.realY - wwin->frame_y);
1694 XSync(dpy, 0);
1695 doWindowMove(wwin, scr->selected_windows,
1696 moveData.realX - wwin->frame_x,
1697 moveData.realY - wwin->frame_y);
1699 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1700 wWindowSynthConfigureNotify(wwin);
1701 #endif
1702 XUngrabKeyboard(dpy, CurrentTime);
1703 XUngrabServer(dpy);
1704 if (!opaqueMove) {
1705 wWindowChangeWorkspace(wwin, scr->current_workspace);
1706 wSetFocusTo(scr, wwin);
1708 if (wPreferences.move_display == WDIS_NEW)
1709 showPosition(wwin, moveData.realX, moveData.realY);
1711 if (!scr->selected_windows) {
1712 /* get rid of the geometry window */
1713 WMUnmapWidget(scr->gview);
1716 #ifdef DEBUG
1717 puts("End move window");
1718 #endif
1719 done = True;
1720 break;
1722 default:
1723 if (started && !opaqueMove) {
1724 drawFrames(wwin, scr->selected_windows,
1725 moveData.realX - wwin->frame_x,
1726 moveData.realY - wwin->frame_y);
1727 XUngrabServer(dpy);
1728 WMHandleEvent(&event);
1729 XSync(dpy, False);
1730 XGrabServer(dpy);
1731 drawFrames(wwin, scr->selected_windows,
1732 moveData.realX - wwin->frame_x,
1733 moveData.realY - wwin->frame_y);
1734 } else {
1735 WMHandleEvent(&event);
1737 break;
1741 if (wPreferences.opaque_move && !wPreferences.use_saveunders) {
1742 XSetWindowAttributes attr;
1745 attr.save_under = False;
1746 XChangeWindowAttributes(dpy, wwin->frame->core->window,
1747 CWSaveUnder, &attr);
1751 freeMoveData(&moveData);
1753 return started;
1757 #define RESIZEBAR 1
1758 #define HCONSTRAIN 2
1760 static int
1761 getResizeDirection(WWindow *wwin, int x, int y, int dx, int dy,
1762 int flags)
1764 int w = wwin->frame->core->width - 1;
1765 int cw = wwin->frame->resizebar_corner_width;
1766 int dir;
1768 /* if not resizing through the resizebar */
1769 if (!(flags & RESIZEBAR)) {
1770 int xdir = (abs(x) < (wwin->client.width/2)) ? LEFT : RIGHT;
1771 int ydir = (abs(y) < (wwin->client.height/2)) ? UP : DOWN;
1772 if (abs(dx) < 2 || abs(dy) < 2) {
1773 if (abs(dy) > abs(dx))
1774 xdir = 0;
1775 else
1776 ydir = 0;
1778 return (xdir | ydir);
1781 /* window is too narrow. allow diagonal resize */
1782 if (cw * 2 >= w) {
1783 int ydir;
1785 if (flags & HCONSTRAIN)
1786 ydir = 0;
1787 else
1788 ydir = DOWN;
1789 if (x < cw)
1790 return (LEFT | ydir);
1791 else
1792 return (RIGHT | ydir);
1794 /* vertical resize */
1795 if ((x > cw) && (x < w - cw))
1796 return DOWN;
1798 if (x < cw)
1799 dir = LEFT;
1800 else
1801 dir = RIGHT;
1803 if ((abs(dy) > 0) && !(flags & HCONSTRAIN))
1804 dir |= DOWN;
1806 return dir;
1810 void
1811 wMouseResizeWindow(WWindow *wwin, XEvent *ev)
1813 XEvent event;
1814 WScreen *scr = wwin->screen_ptr;
1815 Window root = scr->root_win;
1816 int vert_border = wwin->frame->top_width + wwin->frame->bottom_width;
1817 int fw = wwin->frame->core->width;
1818 int fh = wwin->frame->core->height;
1819 int fx = wwin->frame_x;
1820 int fy = wwin->frame_y;
1821 int is_resizebar = (wwin->frame->resizebar
1822 && ev->xany.window==wwin->frame->resizebar->window);
1823 int orig_x, orig_y;
1824 int started;
1825 int dw, dh;
1826 int rw = fw, rh = fh;
1827 int rx1, ry1, rx2, ry2;
1828 int res = 0;
1829 KeyCode shiftl, shiftr;
1830 int h = 0;
1831 int orig_fx = fx;
1832 int orig_fy = fy;
1833 int orig_fw = fw;
1834 int orig_fh = fh;
1836 if (wwin->flags.shaded) {
1837 wwarning("internal error: tryein");
1838 return;
1840 orig_x = ev->xbutton.x_root;
1841 orig_y = ev->xbutton.y_root;
1843 started = 0;
1844 #ifdef DEBUG
1845 puts("Resizing window");
1846 #endif
1848 wUnselectWindows(scr);
1849 rx1 = fx;
1850 rx2 = fx + fw - 1;
1851 ry1 = fy;
1852 ry2 = fy + fh - 1;
1853 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1854 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1855 if (!WFLAGP(wwin, no_titlebar))
1856 h = WMFontHeight(wwin->screen_ptr->title_font) + (wPreferences.window_title_clearance + TITLEBAR_EXTEND_SPACE) * 2;
1857 else
1858 h = 0;
1859 while (1) {
1860 WMMaskEvent(dpy, KeyPressMask | ButtonMotionMask
1861 | ButtonReleaseMask | PointerMotionHintMask
1862 | ButtonPressMask | ExposureMask, &event);
1863 if (!checkMouseSamplingRate(&event))
1864 continue;
1866 switch (event.type) {
1867 case KeyPress:
1868 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1869 if ((event.xkey.keycode == shiftl || event.xkey.keycode == shiftr)
1870 && started) {
1871 drawTransparentFrame(wwin, fx, fy, fw, fh);
1872 cycleGeometryDisplay(wwin, fx, fy, fw, fh, res);
1873 drawTransparentFrame(wwin, fx, fy, fw, fh);
1875 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1876 break;
1878 case MotionNotify:
1879 if (started) {
1880 while (XCheckMaskEvent(dpy, ButtonMotionMask, &event)) ;
1882 dw = 0;
1883 dh = 0;
1885 orig_fx = fx;
1886 orig_fy = fy;
1887 orig_fw = fw;
1888 orig_fh = fh;
1890 if (res & LEFT)
1891 dw = orig_x - event.xmotion.x_root;
1892 else if (res & RIGHT)
1893 dw = event.xmotion.x_root - orig_x;
1894 if (res & UP)
1895 dh = orig_y - event.xmotion.y_root;
1896 else if (res & DOWN)
1897 dh = event.xmotion.y_root - orig_y;
1899 orig_x = event.xmotion.x_root;
1900 orig_y = event.xmotion.y_root;
1902 rw += dw;
1903 rh += dh;
1904 fw = rw;
1905 fh = rh - vert_border;
1906 wWindowConstrainSize(wwin, &fw, &fh);
1907 fh += vert_border;
1908 if (res & LEFT)
1909 fx = rx2 - fw + 1;
1910 else if (res & RIGHT)
1911 fx = rx1;
1912 if (res & UP)
1913 fy = ry2 - fh + 1;
1914 else if (res & DOWN)
1915 fy = ry1;
1916 } else if (abs(orig_x - event.xmotion.x_root) >= MOVE_THRESHOLD
1917 || abs(orig_y - event.xmotion.y_root) >= MOVE_THRESHOLD) {
1918 int tx, ty;
1919 Window junkw;
1920 int flags;
1922 XTranslateCoordinates(dpy, root, wwin->frame->core->window,
1923 orig_x, orig_y, &tx, &ty, &junkw);
1925 /* check if resizing through resizebar */
1926 if (is_resizebar)
1927 flags = RESIZEBAR;
1928 else
1929 flags = 0;
1931 if (is_resizebar && ((ev->xbutton.state & ShiftMask)
1932 || abs(orig_y - event.xmotion.y_root) < HRESIZE_THRESHOLD))
1933 flags |= HCONSTRAIN;
1935 res = getResizeDirection(wwin, tx, ty,
1936 orig_x - event.xmotion.x_root,
1937 orig_y - event.xmotion.y_root, flags);
1939 if (res == (UP|LEFT))
1940 XChangeActivePointerGrab(dpy, ButtonMotionMask
1941 | ButtonReleaseMask | ButtonPressMask,
1942 wCursor[WCUR_TOPLEFTRESIZE], CurrentTime);
1943 else if (res == (UP|RIGHT))
1944 XChangeActivePointerGrab(dpy, ButtonMotionMask
1945 | ButtonReleaseMask | ButtonPressMask,
1946 wCursor[WCUR_TOPRIGHTRESIZE], CurrentTime);
1947 else if (res == (DOWN|LEFT))
1948 XChangeActivePointerGrab(dpy, ButtonMotionMask
1949 | ButtonReleaseMask | ButtonPressMask,
1950 wCursor[WCUR_BOTTOMLEFTRESIZE], CurrentTime);
1951 else if (res == (DOWN|RIGHT))
1952 XChangeActivePointerGrab(dpy, ButtonMotionMask
1953 | ButtonReleaseMask | ButtonPressMask,
1954 wCursor[WCUR_BOTTOMRIGHTRESIZE], CurrentTime);
1955 else if (res == DOWN || res == UP)
1956 XChangeActivePointerGrab(dpy, ButtonMotionMask
1957 | ButtonReleaseMask | ButtonPressMask,
1958 wCursor[WCUR_VERTICALRESIZE], CurrentTime);
1959 else if (res & (DOWN|UP))
1960 XChangeActivePointerGrab(dpy, ButtonMotionMask
1961 | ButtonReleaseMask | ButtonPressMask,
1962 wCursor[WCUR_VERTICALRESIZE], CurrentTime);
1963 else if (res & (LEFT|RIGHT))
1964 XChangeActivePointerGrab(dpy, ButtonMotionMask
1965 | ButtonReleaseMask | ButtonPressMask,
1966 wCursor[WCUR_HORIZONRESIZE], CurrentTime);
1968 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync,
1969 CurrentTime);
1971 XGrabServer(dpy);
1973 /* Draw the resize frame for the first time. */
1974 mapGeometryDisplay(wwin, fx, fy, fw, fh);
1976 drawTransparentFrame(wwin, fx, fy, fw, fh);
1978 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1980 started = 1;
1982 if (started) {
1983 if (wPreferences.size_display == WDIS_FRAME_CENTER) {
1984 drawTransparentFrame(wwin, orig_fx, orig_fy,
1985 orig_fw, orig_fh);
1986 moveGeometryDisplayCentered(scr, fx + fw / 2, fy + fh / 2);
1987 drawTransparentFrame(wwin, fx, fy, fw, fh);
1988 } else {
1989 drawTransparentFrame(wwin, orig_fx, orig_fy,
1990 orig_fw, orig_fh);
1991 drawTransparentFrame(wwin, fx, fy, fw, fh);
1993 if (fh != orig_fh || fw != orig_fw) {
1994 if (wPreferences.size_display == WDIS_NEW) {
1995 showGeometry(wwin, orig_fx, orig_fy, orig_fx + orig_fw,
1996 orig_fy + orig_fh, res);
1998 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
2001 break;
2003 case ButtonPress:
2004 break;
2006 case ButtonRelease:
2007 if (event.xbutton.button != ev->xbutton.button)
2008 break;
2010 if (started) {
2011 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
2013 drawTransparentFrame(wwin, fx, fy, fw, fh);
2015 XUngrabKeyboard(dpy, CurrentTime);
2016 WMUnmapWidget(scr->gview);
2017 XUngrabServer(dpy);
2019 if (wwin->client.width != fw)
2020 wwin->flags.user_changed_width = 1;
2022 if (wwin->client.height != fh - vert_border)
2023 wwin->flags.user_changed_height = 1;
2025 wWindowConfigure(wwin, fx, fy, fw, fh - vert_border);
2027 #ifdef DEBUG
2028 puts("End resize window");
2029 #endif
2030 return;
2032 default:
2033 WMHandleEvent(&event);
2038 #undef LEFT
2039 #undef RIGHT
2040 #undef HORIZONTAL
2041 #undef UP
2042 #undef DOWN
2043 #undef VERTICAL
2044 #undef HCONSTRAIN
2045 #undef RESIZEBAR
2047 void
2048 wUnselectWindows(WScreen *scr)
2050 WWindow *wwin;
2052 if (!scr->selected_windows)
2053 return;
2055 while (WMGetBagItemCount(scr->selected_windows)) {
2056 WMBagIterator dummy;
2058 wwin = WMBagFirst(scr->selected_windows, &dummy);
2059 if (wwin->flags.miniaturized && wwin->icon && wwin->icon->selected)
2060 wIconSelect(wwin->icon);
2062 wSelectWindow(wwin, False);
2064 WMFreeBag(scr->selected_windows);
2065 scr->selected_windows = NULL;
2068 #ifndef LITE
2069 static void
2070 selectWindowsInside(WScreen *scr, int x1, int y1, int x2, int y2)
2072 WWindow *tmpw;
2074 /* select the windows and put them in the selected window list */
2075 tmpw = scr->focused_window;
2076 while (tmpw != NULL) {
2077 if (!(tmpw->flags.miniaturized || tmpw->flags.hidden)) {
2078 if ((tmpw->frame->workspace == scr->current_workspace
2079 || IS_OMNIPRESENT(tmpw))
2080 && (tmpw->frame_x >= x1) && (tmpw->frame_y >= y1)
2081 && (tmpw->frame->core->width + tmpw->frame_x <= x2)
2082 && (tmpw->frame->core->height + tmpw->frame_y <= y2)) {
2083 wSelectWindow(tmpw, True);
2086 tmpw = tmpw->prev;
2091 void
2092 wSelectWindows(WScreen *scr, XEvent *ev)
2094 XEvent event;
2095 Window root = scr->root_win;
2096 GC gc = scr->frame_gc;
2097 int xp = ev->xbutton.x_root;
2098 int yp = ev->xbutton.y_root;
2099 int w = 0, h = 0;
2100 int x = xp, y = yp;
2102 #ifdef DEBUG
2103 puts("Selecting windows");
2104 #endif
2105 if (XGrabPointer(dpy, scr->root_win, False, ButtonMotionMask
2106 | ButtonReleaseMask | ButtonPressMask, GrabModeAsync,
2107 GrabModeAsync, None, wCursor[WCUR_DEFAULT],
2108 CurrentTime) != Success) {
2109 return;
2111 XGrabServer(dpy);
2113 wUnselectWindows(scr);
2115 XDrawRectangle(dpy, root, gc, xp, yp, w, h);
2116 while (1) {
2117 WMMaskEvent(dpy, ButtonReleaseMask | PointerMotionMask
2118 | ButtonPressMask, &event);
2120 switch (event.type) {
2121 case MotionNotify:
2122 XDrawRectangle(dpy, root, gc, x, y, w, h);
2123 x = event.xmotion.x_root;
2124 if (x < xp) {
2125 w = xp - x;
2126 } else {
2127 w = x - xp;
2128 x = xp;
2130 y = event.xmotion.y_root;
2131 if (y < yp) {
2132 h = yp - y;
2133 } else {
2134 h = y - yp;
2135 y = yp;
2137 XDrawRectangle(dpy, root, gc, x, y, w, h);
2138 break;
2140 case ButtonPress:
2141 break;
2143 case ButtonRelease:
2144 if (event.xbutton.button != ev->xbutton.button)
2145 break;
2147 XDrawRectangle(dpy, root, gc, x, y, w, h);
2148 XUngrabServer(dpy);
2149 XUngrabPointer(dpy, CurrentTime);
2150 selectWindowsInside(scr, x, y, x + w, y + h);
2152 #ifdef KWM_HINTS
2153 wKWMSelectRootRegion(scr, xp, yp, w, h,
2154 event.xbutton.state & ControlMask);
2155 #endif /* KWM_HINTS */
2157 #ifdef DEBUG
2158 puts("End window selection");
2159 #endif
2160 return;
2162 default:
2163 WMHandleEvent(&event);
2164 break;
2168 #endif /* !LITE */
2170 void
2171 InteractivePlaceWindow(WWindow *wwin, int *x_ret, int *y_ret,
2172 unsigned width, unsigned height)
2174 WScreen *scr = wwin->screen_ptr;
2175 Window root = scr->root_win;
2176 int x, y, h = 0;
2177 XEvent event;
2178 KeyCode shiftl, shiftr;
2179 Window junkw;
2180 int junk;
2182 if (XGrabPointer(dpy, root, True, PointerMotionMask | ButtonPressMask,
2183 GrabModeAsync, GrabModeAsync, None,
2184 wCursor[WCUR_DEFAULT], CurrentTime) != Success) {
2185 *x_ret = 0;
2186 *y_ret = 0;
2187 return;
2189 if (!WFLAGP(wwin, no_titlebar)) {
2190 h = WMFontHeight(scr->title_font) + (wPreferences.window_title_clearance + TITLEBAR_EXTEND_SPACE) * 2;
2191 height += h;
2193 if (!WFLAGP(wwin, no_resizebar)) {
2194 height += RESIZEBAR_HEIGHT;
2196 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync, CurrentTime);
2197 XQueryPointer(dpy, root, &junkw, &junkw, &x, &y, &junk, &junk,
2198 (unsigned *) &junk);
2199 mapPositionDisplay(wwin, x - width/2, y - h/2, width, height);
2201 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2203 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
2204 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
2205 while (1) {
2206 WMMaskEvent(dpy, PointerMotionMask|ButtonPressMask|ExposureMask|KeyPressMask,
2207 &event);
2209 if (!checkMouseSamplingRate(&event))
2210 continue;
2212 switch (event.type) {
2213 case KeyPress:
2214 if ((event.xkey.keycode == shiftl)
2215 || (event.xkey.keycode == shiftr)) {
2216 drawTransparentFrame(wwin,
2217 x - width/2, y - h/2, width, height);
2218 cyclePositionDisplay(wwin,
2219 x - width/2, y - h/2, width, height);
2220 drawTransparentFrame(wwin,
2221 x - width/2, y - h/2, width, height);
2223 break;
2225 case MotionNotify:
2226 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2228 x = event.xmotion.x_root;
2229 y = event.xmotion.y_root;
2231 if (wPreferences.move_display == WDIS_FRAME_CENTER)
2232 moveGeometryDisplayCentered(scr, x, y + (height - h) / 2);
2234 showPosition(wwin, x - width/2, y - h/2);
2236 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2238 break;
2240 case ButtonPress:
2241 drawTransparentFrame(wwin, x - width/2, y - h/2, width, height);
2242 XSync(dpy, 0);
2243 *x_ret = x - width/2;
2244 *y_ret = y - h/2;
2245 XUngrabPointer(dpy, CurrentTime);
2246 XUngrabKeyboard(dpy, CurrentTime);
2247 /* get rid of the geometry window */
2248 WMUnmapWidget(scr->gview);
2249 return;
2251 default:
2252 WMHandleEvent(&event);
2253 break;