Improve dockapp recognition
[wmaker-crm.git] / src / moveres.c
blob040e88df0cd82430da7d672ad0e7cd420635b90e
1 /*
2 * Window Maker window manager
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
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 "framewin.h"
34 #include "window.h"
35 #include "client.h"
36 #include "icon.h"
37 #include "dock.h"
38 #include "funcs.h"
39 #include "actions.h"
40 #include "workspace.h"
42 #include "geomview.h"
43 #include "screen.h"
44 #include "xinerama.h"
46 #include <WINGs/WINGsP.h>
48 /* How many different types of geometry/position
49 display thingies are there? */
50 #define NUM_DISPLAYS 5
52 #define LEFT 1
53 #define RIGHT 2
54 #define HORIZONTAL (LEFT|RIGHT)
55 #define UP 4
56 #define DOWN 8
57 #define VERTICAL (UP|DOWN)
59 /* True if window currently has a border. This also includes borderless
60 * windows which are currently selected
62 #define HAS_BORDER_WITH_SELECT(w) ((w)->flags.selected || HAS_BORDER(w))
64 /****** Global Variables ******/
65 extern Cursor wCursor[WCUR_LAST];
66 extern WPreferences wPreferences;
69 *----------------------------------------------------------------------
70 * checkMouseSamplingRate-
71 * For lowering the mouse motion sampling rate for machines where
72 * it's too high (SGIs). If it returns False then the event should be
73 * ignored.
74 *----------------------------------------------------------------------
76 static Bool checkMouseSamplingRate(XEvent * ev)
78 static Time previousMotion = 0;
80 if (ev->type == MotionNotify) {
81 if (ev->xmotion.time - previousMotion < DELAY_BETWEEN_MOUSE_SAMPLING) {
82 return False;
83 } else {
84 previousMotion = ev->xmotion.time;
87 return True;
91 *----------------------------------------------------------------------
92 * moveGeometryDisplayCentered
94 * routine that moves the geometry/position window on scr so it is
95 * centered over the given coordinates (x,y). Also the window position
96 * is clamped so it stays on the screen at all times.
97 *----------------------------------------------------------------------
99 static void moveGeometryDisplayCentered(WScreen * scr, int x, int y)
101 unsigned int w = WMWidgetWidth(scr->gview);
102 unsigned int h = WMWidgetHeight(scr->gview);
103 int x1 = 0, y1 = 0, x2 = scr->scr_width, y2 = scr->scr_height;
105 x -= w / 2;
106 y -= h / 2;
108 /* dead area check */
109 if (scr->xine_info.count) {
110 WMRect rect;
111 int head, flags;
113 rect.pos.x = x;
114 rect.pos.y = y;
115 rect.size.width = w;
116 rect.size.height = h;
118 head = wGetRectPlacementInfo(scr, rect, &flags);
120 if (flags & (XFLAG_DEAD | XFLAG_PARTIAL)) {
121 rect = wGetRectForHead(scr, head);
122 x1 = rect.pos.x;
123 y1 = rect.pos.y;
124 x2 = x1 + rect.size.width;
125 y2 = y1 + rect.size.height;
129 if (x < x1 + 1)
130 x = x1 + 1;
131 else if (x > (x2 - w))
132 x = x2 - w;
134 if (y < y1 + 1)
135 y = y1 + 1;
136 else if (y > (y2 - h))
137 y = y2 - h;
139 WMMoveWidget(scr->gview, x, y);
142 static void showPosition(WWindow * wwin, int x, int y)
144 WScreen *scr = wwin->screen_ptr;
146 if (wPreferences.move_display == WDIS_NEW) {
147 #if 0
148 int width = wwin->frame->core->width;
149 int height = wwin->frame->core->height;
151 GC lgc = scr->line_gc;
152 XSetForeground(dpy, lgc, scr->line_pixel);
153 sprintf(num, "%i", x);
155 XDrawLine(dpy, scr->root_win, lgc, 0, y - 1, scr->scr_width, y - 1);
156 XDrawLine(dpy, scr->root_win, lgc, 0, y + height + 2, scr->scr_width, y + height + 2);
157 XDrawLine(dpy, scr->root_win, lgc, x - 1, 0, x - 1, scr->scr_height);
158 XDrawLine(dpy, scr->root_win, lgc, x + width + 2, 0, x + width + 2, scr->scr_height);
159 #endif
160 } else {
161 WSetGeometryViewShownPosition(scr->gview, x, y);
165 static void cyclePositionDisplay(WWindow * wwin, int x, int y, int w, int h)
167 WScreen *scr = wwin->screen_ptr;
168 WMRect rect;
170 wPreferences.move_display++;
171 wPreferences.move_display %= NUM_DISPLAYS;
173 if (wPreferences.move_display == WDIS_NEW) {
174 wPreferences.move_display++;
175 wPreferences.move_display %= NUM_DISPLAYS;
178 if (wPreferences.move_display == WDIS_NONE) {
179 WMUnmapWidget(scr->gview);
180 } else {
181 if (wPreferences.move_display == WDIS_CENTER) {
182 rect = wGetRectForHead(scr, wGetHeadForWindow(wwin));
183 moveGeometryDisplayCentered(scr, rect.pos.x + rect.size.width / 2,
184 rect.pos.y + rect.size.height / 2);
185 } else if (wPreferences.move_display == WDIS_TOPLEFT) {
186 rect = wGetRectForHead(scr, wGetHeadForWindow(wwin));
187 moveGeometryDisplayCentered(scr, rect.pos.x + 1, rect.pos.y + 1);
188 } else if (wPreferences.move_display == WDIS_FRAME_CENTER) {
189 moveGeometryDisplayCentered(scr, x + w / 2, y + h / 2);
191 WMMapWidget(scr->gview);
195 static void mapPositionDisplay(WWindow * wwin, int x, int y, int w, int h)
197 WScreen *scr = wwin->screen_ptr;
198 WMRect rect;
200 if (wPreferences.move_display == WDIS_NEW || wPreferences.move_display == WDIS_NONE) {
201 return;
202 } else if (wPreferences.move_display == WDIS_CENTER) {
203 rect = wGetRectForHead(scr, wGetHeadForWindow(wwin));
204 moveGeometryDisplayCentered(scr, rect.pos.x + rect.size.width / 2,
205 rect.pos.y + rect.size.height / 2);
206 } else if (wPreferences.move_display == WDIS_TOPLEFT) {
207 rect = wGetRectForHead(scr, wGetHeadForWindow(wwin));
208 moveGeometryDisplayCentered(scr, rect.pos.x + 1, rect.pos.y + 1);
209 } else if (wPreferences.move_display == WDIS_FRAME_CENTER) {
210 moveGeometryDisplayCentered(scr, x + w / 2, y + h / 2);
212 WMMapWidget(scr->gview);
213 WSetGeometryViewShownPosition(scr->gview, x, y);
216 static void showGeometry(WWindow * wwin, int x1, int y1, int x2, int y2, int direction)
218 WScreen *scr = wwin->screen_ptr;
219 Window root = scr->root_win;
220 GC gc = scr->line_gc;
221 int ty, by, my, x, y, mx, s;
222 char num[16];
223 XSegment segment[4];
224 int fw, fh;
226 /* This seems necessary for some odd reason (too lazy to write x1-1 and
227 * x2-1 everywhere below in the code). But why only for x? */
228 x1--;
229 x2--;
231 if (HAS_BORDER_WITH_SELECT(wwin)) {
232 x1 += FRAME_BORDER_WIDTH;
233 x2 += FRAME_BORDER_WIDTH;
234 y1 += FRAME_BORDER_WIDTH;
235 y2 += FRAME_BORDER_WIDTH;
238 ty = y1 + wwin->frame->top_width;
239 by = y2 - wwin->frame->bottom_width;
241 if (wPreferences.size_display == WDIS_NEW) {
242 fw = XTextWidth(scr->tech_draw_font, "8888", 4);
243 fh = scr->tech_draw_font->ascent + scr->tech_draw_font->descent;
245 XSetForeground(dpy, gc, scr->line_pixel);
247 /* vertical geometry */
248 if (((direction & LEFT) && (x2 < scr->scr_width - fw)) || (x1 < fw)) {
249 x = x2;
250 s = -15;
251 } else {
252 x = x1;
253 s = 15;
255 my = (ty + by) / 2;
257 /* top arrow & end bar */
258 segment[0].x1 = x - (s + 6);
259 segment[0].y1 = ty;
260 segment[0].x2 = x - (s - 10);
261 segment[0].y2 = ty;
263 /* arrowhead */
264 segment[1].x1 = x - (s - 2);
265 segment[1].y1 = ty + 1;
266 segment[1].x2 = x - (s - 5);
267 segment[1].y2 = ty + 7;
269 segment[2].x1 = x - (s - 2);
270 segment[2].y1 = ty + 1;
271 segment[2].x2 = x - (s + 1);
272 segment[2].y2 = ty + 7;
274 /* line */
275 segment[3].x1 = x - (s - 2);
276 segment[3].y1 = ty + 1;
277 segment[3].x2 = x - (s - 2);
278 segment[3].y2 = my - fh / 2 - 1;
280 XDrawSegments(dpy, root, gc, segment, 4);
282 /* bottom arrow & end bar */
283 segment[0].y1 = by;
284 segment[0].y2 = by;
286 /* arrowhead */
287 segment[1].y1 = by - 1;
288 segment[1].y2 = by - 7;
290 segment[2].y1 = by - 1;
291 segment[2].y2 = by - 7;
293 /* line */
294 segment[3].y1 = my + fh / 2 + 2;
295 segment[3].y2 = by - 1;
297 XDrawSegments(dpy, root, gc, segment, 4);
299 snprintf(num, sizeof(num), "%i", (by - ty - wwin->normal_hints->base_height) /
300 wwin->normal_hints->height_inc);
301 fw = XTextWidth(scr->tech_draw_font, num, strlen(num));
303 /* Display the height. */
304 XSetFont(dpy, gc, scr->tech_draw_font->fid);
305 XDrawString(dpy, root, gc, x - s + 3 - fw / 2, my + scr->tech_draw_font->ascent - fh / 2 + 1, num,
306 strlen(num));
308 /* horizontal geometry */
309 if (y1 < 15) {
310 y = y2;
311 s = -15;
312 } else {
313 y = y1;
314 s = 15;
316 mx = x1 + (x2 - x1) / 2;
317 snprintf(num, sizeof(num), "%i", (x2 - x1 - wwin->normal_hints->base_width) /
318 wwin->normal_hints->width_inc);
319 fw = XTextWidth(scr->tech_draw_font, num, strlen(num));
321 /* left arrow & end bar */
322 segment[0].x1 = x1;
323 segment[0].y1 = y - (s + 6);
324 segment[0].x2 = x1;
325 segment[0].y2 = y - (s - 10);
327 /* arrowhead */
328 segment[1].x1 = x1 + 7;
329 segment[1].y1 = y - (s + 1);
330 segment[1].x2 = x1 + 1;
331 segment[1].y2 = y - (s - 2);
333 segment[2].x1 = x1 + 1;
334 segment[2].y1 = y - (s - 2);
335 segment[2].x2 = x1 + 7;
336 segment[2].y2 = y - (s - 5);
338 /* line */
339 segment[3].x1 = x1 + 1;
340 segment[3].y1 = y - (s - 2);
341 segment[3].x2 = mx - fw / 2 - 2;
342 segment[3].y2 = y - (s - 2);
344 XDrawSegments(dpy, root, gc, segment, 4);
346 /* right arrow & end bar */
347 segment[0].x1 = x2 + 1;
348 segment[0].x2 = x2 + 1;
350 /* arrowhead */
351 segment[1].x1 = x2 - 6;
352 segment[1].x2 = x2;
354 segment[2].x1 = x2;
355 segment[2].x2 = x2 - 6;
357 /* line */
358 segment[3].x1 = mx + fw / 2 + 2;
359 segment[3].x2 = x2;
361 XDrawSegments(dpy, root, gc, segment, 4);
363 /* Display the width. */
364 XDrawString(dpy, root, gc, mx - fw / 2 + 1, y - s + scr->tech_draw_font->ascent - fh / 2 + 1, num,
365 strlen(num));
366 } else {
367 WSetGeometryViewShownSize(scr->gview, (x2 - x1 - wwin->normal_hints->base_width)
368 / wwin->normal_hints->width_inc,
369 (by - ty - wwin->normal_hints->base_height)
370 / wwin->normal_hints->height_inc);
374 static void cycleGeometryDisplay(WWindow * wwin, int x, int y, int w, int h, int dir)
376 WScreen *scr = wwin->screen_ptr;
377 WMRect rect;
379 wPreferences.size_display++;
380 wPreferences.size_display %= NUM_DISPLAYS;
382 if (wPreferences.size_display == WDIS_NEW || wPreferences.size_display == WDIS_NONE) {
383 WMUnmapWidget(scr->gview);
384 } else {
385 if (wPreferences.size_display == WDIS_CENTER) {
386 rect = wGetRectForHead(scr, wGetHeadForWindow(wwin));
387 moveGeometryDisplayCentered(scr, rect.pos.x + rect.size.width / 2,
388 rect.pos.y + rect.size.height / 2);
389 } else if (wPreferences.size_display == WDIS_TOPLEFT) {
390 rect = wGetRectForHead(scr, wGetHeadForWindow(wwin));
391 moveGeometryDisplayCentered(scr, rect.pos.x + 1, rect.pos.y + 1);
392 } else if (wPreferences.size_display == WDIS_FRAME_CENTER) {
393 moveGeometryDisplayCentered(scr, x + w / 2, y + h / 2);
395 WMMapWidget(scr->gview);
396 showGeometry(wwin, x, y, x + w, y + h, dir);
400 static void mapGeometryDisplay(WWindow * wwin, int x, int y, int w, int h)
402 WScreen *scr = wwin->screen_ptr;
403 WMRect rect;
405 if (wPreferences.size_display == WDIS_NEW || wPreferences.size_display == WDIS_NONE)
406 return;
408 if (wPreferences.size_display == WDIS_CENTER) {
409 rect = wGetRectForHead(scr, wGetHeadForWindow(wwin));
410 moveGeometryDisplayCentered(scr, rect.pos.x + rect.size.width / 2,
411 rect.pos.y + rect.size.height / 2);
412 } else if (wPreferences.size_display == WDIS_TOPLEFT) {
413 rect = wGetRectForHead(scr, wGetHeadForWindow(wwin));
414 moveGeometryDisplayCentered(scr, rect.pos.x + 1, rect.pos.y + 1);
415 } else if (wPreferences.size_display == WDIS_FRAME_CENTER) {
416 moveGeometryDisplayCentered(scr, x + w / 2, y + h / 2);
418 WMMapWidget(scr->gview);
419 showGeometry(wwin, x, y, x + w, y + h, 0);
422 static void doWindowMove(WWindow * wwin, WMArray * array, int dx, int dy)
424 WWindow *tmpw;
425 WScreen *scr = wwin->screen_ptr;
426 int x, y;
428 if (!array || !WMGetArrayItemCount(array)) {
429 wWindowMove(wwin, wwin->frame_x + dx, wwin->frame_y + dy);
430 } else {
431 WMArrayIterator iter;
433 WM_ITERATE_ARRAY(array, tmpw, iter) {
434 x = tmpw->frame_x + dx;
435 y = tmpw->frame_y + dy;
437 #if 1 /* XXX: with xinerama patch was #if 0, check this */
438 /* don't let windows become unreachable */
440 if (x + (int)tmpw->frame->core->width < 20)
441 x = 20 - (int)tmpw->frame->core->width;
442 else if (x + 20 > scr->scr_width)
443 x = scr->scr_width - 20;
445 if (y + (int)tmpw->frame->core->height < 20)
446 y = 20 - (int)tmpw->frame->core->height;
447 else if (y + 20 > scr->scr_height)
448 y = scr->scr_height - 20;
449 #else
450 wScreenBringInside(scr, &x, &y,
451 (int)tmpw->frame->core->width, (int)tmpw->frame->core->height);
452 #endif
454 wWindowMove(tmpw, x, y);
459 static void drawTransparentFrame(WWindow * wwin, int x, int y, int width, int height)
461 Window root = wwin->screen_ptr->root_win;
462 GC gc = wwin->screen_ptr->frame_gc;
463 int h = 0;
464 int bottom = 0;
466 if (HAS_BORDER_WITH_SELECT(wwin)) {
467 x += FRAME_BORDER_WIDTH;
468 y += FRAME_BORDER_WIDTH;
471 if (HAS_TITLEBAR(wwin) && !wwin->flags.shaded) {
472 h = WMFontHeight(wwin->screen_ptr->title_font) + (wPreferences.window_title_clearance +
473 TITLEBAR_EXTEND_SPACE) * 2;
475 if (HAS_RESIZEBAR(wwin) && !wwin->flags.shaded) {
476 /* Can't use wwin-frame->bottom_width because, in some cases
477 (e.g. interactive placement), frame does not point to anything. */
478 bottom = RESIZEBAR_HEIGHT;
480 XDrawRectangle(dpy, root, gc, x - 1, y - 1, width + 1, height + 1);
482 if (h > 0) {
483 XDrawLine(dpy, root, gc, x, y + h - 1, x + width, y + h - 1);
485 if (bottom > 0) {
486 XDrawLine(dpy, root, gc, x, y + height - bottom, x + width, y + height - bottom);
490 static void drawFrames(WWindow * wwin, WMArray * array, int dx, int dy)
492 WWindow *tmpw;
493 int scr_width = wwin->screen_ptr->scr_width;
494 int scr_height = wwin->screen_ptr->scr_height;
495 int x, y;
497 if (!array) {
499 x = wwin->frame_x + dx;
500 y = wwin->frame_y + dy;
502 drawTransparentFrame(wwin, x, y, wwin->frame->core->width, wwin->frame->core->height);
504 } else {
505 WMArrayIterator iter;
507 WM_ITERATE_ARRAY(array, tmpw, iter) {
508 x = tmpw->frame_x + dx;
509 y = tmpw->frame_y + dy;
511 /* don't let windows become unreachable */
512 #if 1 /* XXX: was 0 in XINERAMA patch, check */
513 if (x + (int)tmpw->frame->core->width < 20)
514 x = 20 - (int)tmpw->frame->core->width;
515 else if (x + 20 > scr_width)
516 x = scr_width - 20;
518 if (y + (int)tmpw->frame->core->height < 20)
519 y = 20 - (int)tmpw->frame->core->height;
520 else if (y + 20 > scr_height)
521 y = scr_height - 20;
523 #else
524 wScreenBringInside(wwin->screen_ptr, &x, &y,
525 (int)tmpw->frame->core->width, (int)tmpw->frame->core->height);
526 #endif
528 drawTransparentFrame(tmpw, x, y, tmpw->frame->core->width, tmpw->frame->core->height);
533 static void flushMotion()
535 XEvent ev;
537 XSync(dpy, False);
538 while (XCheckMaskEvent(dpy, ButtonMotionMask, &ev)) ;
541 static void crossWorkspace(WScreen * scr, WWindow * wwin, int opaque_move, int new_workspace, int rewind)
543 /* do not let window be unmapped */
544 if (opaque_move) {
545 wwin->flags.changing_workspace = 1;
546 wWindowChangeWorkspace(wwin, new_workspace);
548 /* go to new workspace */
549 wWorkspaceChange(scr, new_workspace);
551 wwin->flags.changing_workspace = 0;
553 if (rewind)
554 XWarpPointer(dpy, None, None, 0, 0, 0, 0, scr->scr_width - 20, 0);
555 else
556 XWarpPointer(dpy, None, None, 0, 0, 0, 0, -(scr->scr_width - 20), 0);
558 flushMotion();
560 if (!opaque_move) {
561 XGrabPointer(dpy, scr->root_win, True, PointerMotionMask
562 | ButtonReleaseMask | ButtonPressMask, GrabModeAsync,
563 GrabModeAsync, None, wCursor[WCUR_MOVE], CurrentTime);
567 typedef struct {
568 /* arrays of WWindows sorted by the respective border position */
569 WWindow **topList; /* top border */
570 WWindow **leftList; /* left border */
571 WWindow **rightList; /* right border */
572 WWindow **bottomList; /* bottom border */
573 int count;
575 /* index of window in the above lists indicating the relative position
576 * of the window with the others */
577 int topIndex;
578 int leftIndex;
579 int rightIndex;
580 int bottomIndex;
582 int rubCount; /* for workspace switching */
584 int winWidth, winHeight; /* width/height of the window */
585 int realX, realY; /* actual position of the window */
586 int calcX, calcY; /* calculated position of window */
587 int omouseX, omouseY; /* old mouse position */
588 int mouseX, mouseY; /* last known position of the pointer */
589 } MoveData;
591 #define WTOP(w) (w)->frame_y
592 #define WLEFT(w) (w)->frame_x
593 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width - 1 + \
594 (HAS_BORDER_WITH_SELECT(w) ? 2*FRAME_BORDER_WIDTH : 0))
595 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height - 1 + \
596 (HAS_BORDER_WITH_SELECT(w) ? 2*FRAME_BORDER_WIDTH : 0))
598 static int compareWTop(const void *a, const void *b)
600 WWindow *wwin1 = *(WWindow **) a;
601 WWindow *wwin2 = *(WWindow **) b;
603 if (WTOP(wwin1) > WTOP(wwin2))
604 return -1;
605 else if (WTOP(wwin1) < WTOP(wwin2))
606 return 1;
607 else
608 return 0;
611 static int compareWLeft(const void *a, const void *b)
613 WWindow *wwin1 = *(WWindow **) a;
614 WWindow *wwin2 = *(WWindow **) b;
616 if (WLEFT(wwin1) > WLEFT(wwin2))
617 return -1;
618 else if (WLEFT(wwin1) < WLEFT(wwin2))
619 return 1;
620 else
621 return 0;
624 static int compareWRight(const void *a, const void *b)
626 WWindow *wwin1 = *(WWindow **) a;
627 WWindow *wwin2 = *(WWindow **) b;
629 if (WRIGHT(wwin1) < WRIGHT(wwin2))
630 return -1;
631 else if (WRIGHT(wwin1) > WRIGHT(wwin2))
632 return 1;
633 else
634 return 0;
637 static int compareWBottom(const void *a, const void *b)
639 WWindow *wwin1 = *(WWindow **) a;
640 WWindow *wwin2 = *(WWindow **) b;
642 if (WBOTTOM(wwin1) < WBOTTOM(wwin2))
643 return -1;
644 else if (WBOTTOM(wwin1) > WBOTTOM(wwin2))
645 return 1;
646 else
647 return 0;
650 static void updateResistance(WWindow * wwin, MoveData * data, int newX, int newY)
652 int i;
653 int newX2 = newX + data->winWidth;
654 int newY2 = newY + data->winHeight;
655 Bool ok = False;
657 if (newX < data->realX) {
658 if (data->rightIndex > 0 && newX < WRIGHT(data->rightList[data->rightIndex - 1])) {
659 ok = True;
660 } else if (data->leftIndex <= data->count - 1 && newX2 <= WLEFT(data->leftList[data->leftIndex])) {
661 ok = True;
663 } else if (newX > data->realX) {
664 if (data->leftIndex > 0 && newX2 > WLEFT(data->leftList[data->leftIndex - 1])) {
665 ok = True;
666 } else if (data->rightIndex <= data->count - 1
667 && newX >= WRIGHT(data->rightList[data->rightIndex])) {
668 ok = True;
672 if (!ok) {
673 if (newY < data->realY) {
674 if (data->bottomIndex > 0 && newY < WBOTTOM(data->bottomList[data->bottomIndex - 1])) {
675 ok = True;
676 } else if (data->topIndex <= data->count - 1
677 && newY2 <= WTOP(data->topList[data->topIndex])) {
678 ok = True;
680 } else if (newY > data->realY) {
681 if (data->topIndex > 0 && newY2 > WTOP(data->topList[data->topIndex - 1])) {
682 ok = True;
683 } else if (data->bottomIndex <= data->count - 1
684 && newY >= WBOTTOM(data->bottomList[data->bottomIndex])) {
685 ok = True;
690 if (!ok)
691 return;
693 /* TODO: optimize this */
694 if (data->realY < WBOTTOM(data->bottomList[0])) {
695 data->bottomIndex = 0;
697 if (data->realX < WRIGHT(data->rightList[0])) {
698 data->rightIndex = 0;
700 if ((data->realX + data->winWidth) > WLEFT(data->leftList[0])) {
701 data->leftIndex = 0;
703 if ((data->realY + data->winHeight) > WTOP(data->topList[0])) {
704 data->topIndex = 0;
706 for (i = 0; i < data->count; i++) {
707 if (data->realY > WBOTTOM(data->bottomList[i])) {
708 data->bottomIndex = i + 1;
710 if (data->realX > WRIGHT(data->rightList[i])) {
711 data->rightIndex = i + 1;
713 if ((data->realX + data->winWidth) < WLEFT(data->leftList[i])) {
714 data->leftIndex = i + 1;
716 if ((data->realY + data->winHeight) < WTOP(data->topList[i])) {
717 data->topIndex = i + 1;
722 static void freeMoveData(MoveData * data)
724 if (data->topList)
725 wfree(data->topList);
726 if (data->leftList)
727 wfree(data->leftList);
728 if (data->rightList)
729 wfree(data->rightList);
730 if (data->bottomList)
731 wfree(data->bottomList);
734 static void updateMoveData(WWindow * wwin, MoveData * data)
736 WScreen *scr = wwin->screen_ptr;
737 WWindow *tmp;
738 int i;
740 data->count = 0;
741 tmp = scr->focused_window;
742 while (tmp) {
743 if (tmp != wwin && scr->current_workspace == tmp->frame->workspace
744 && !tmp->flags.miniaturized
745 && !tmp->flags.hidden && !tmp->flags.obscured && !WFLAGP(tmp, sunken)) {
746 data->topList[data->count] = tmp;
747 data->leftList[data->count] = tmp;
748 data->rightList[data->count] = tmp;
749 data->bottomList[data->count] = tmp;
750 data->count++;
752 tmp = tmp->prev;
755 if (data->count == 0) {
756 data->topIndex = 0;
757 data->leftIndex = 0;
758 data->rightIndex = 0;
759 data->bottomIndex = 0;
760 return;
763 /* order from closest to the border of the screen to farthest */
765 qsort(data->topList, data->count, sizeof(WWindow **), compareWTop);
766 qsort(data->leftList, data->count, sizeof(WWindow **), compareWLeft);
767 qsort(data->rightList, data->count, sizeof(WWindow **), compareWRight);
768 qsort(data->bottomList, data->count, sizeof(WWindow **), compareWBottom);
770 /* figure the position of the window relative to the others */
772 data->topIndex = -1;
773 data->leftIndex = -1;
774 data->rightIndex = -1;
775 data->bottomIndex = -1;
777 if (WTOP(wwin) < WBOTTOM(data->bottomList[0])) {
778 data->bottomIndex = 0;
780 if (WLEFT(wwin) < WRIGHT(data->rightList[0])) {
781 data->rightIndex = 0;
783 if (WRIGHT(wwin) > WLEFT(data->leftList[0])) {
784 data->leftIndex = 0;
786 if (WBOTTOM(wwin) > WTOP(data->topList[0])) {
787 data->topIndex = 0;
789 for (i = 0; i < data->count; i++) {
790 if (WTOP(wwin) >= WBOTTOM(data->bottomList[i])) {
791 data->bottomIndex = i + 1;
793 if (WLEFT(wwin) >= WRIGHT(data->rightList[i])) {
794 data->rightIndex = i + 1;
796 if (WRIGHT(wwin) <= WLEFT(data->leftList[i])) {
797 data->leftIndex = i + 1;
799 if (WBOTTOM(wwin) <= WTOP(data->topList[i])) {
800 data->topIndex = i + 1;
805 static void initMoveData(WWindow * wwin, MoveData * data)
807 int i;
808 WWindow *tmp;
810 memset(data, 0, sizeof(MoveData));
812 for (i = 0, tmp = wwin->screen_ptr->focused_window; tmp != NULL; tmp = tmp->prev, i++) ;
814 if (i > 1) {
815 data->topList = wmalloc(sizeof(WWindow *) * i);
816 data->leftList = wmalloc(sizeof(WWindow *) * i);
817 data->rightList = wmalloc(sizeof(WWindow *) * i);
818 data->bottomList = wmalloc(sizeof(WWindow *) * i);
820 updateMoveData(wwin, data);
823 data->realX = wwin->frame_x;
824 data->realY = wwin->frame_y;
825 data->calcX = wwin->frame_x;
826 data->calcY = wwin->frame_y;
828 data->winWidth = wwin->frame->core->width + (HAS_BORDER_WITH_SELECT(wwin) ? 2 * FRAME_BORDER_WIDTH : 0);
829 data->winHeight = wwin->frame->core->height + (HAS_BORDER_WITH_SELECT(wwin) ? 2 * FRAME_BORDER_WIDTH : 0);
832 static Bool checkWorkspaceChange(WWindow * wwin, MoveData * data, Bool opaqueMove)
834 WScreen *scr = wwin->screen_ptr;
835 Bool changed = False;
837 if (data->mouseX <= 1) {
838 if (scr->current_workspace > 0) {
840 crossWorkspace(scr, wwin, opaqueMove, scr->current_workspace - 1, True);
841 changed = True;
842 data->rubCount = 0;
844 } else if (scr->current_workspace == 0 && wPreferences.ws_cycle) {
846 crossWorkspace(scr, wwin, opaqueMove, scr->workspace_count - 1, True);
847 changed = True;
848 data->rubCount = 0;
850 } else if (data->mouseX >= scr->scr_width - 2) {
852 if (scr->current_workspace == scr->workspace_count - 1) {
854 if (wPreferences.ws_cycle || scr->workspace_count == MAX_WORKSPACES) {
856 crossWorkspace(scr, wwin, opaqueMove, 0, False);
857 changed = True;
858 data->rubCount = 0;
860 /* if user insists on trying to go to next workspace even when
861 * it's already the last, create a new one */
862 else if (data->omouseX == data->mouseX && wPreferences.ws_advance) {
864 /* detect user "rubbing" the window against the edge */
865 if (data->rubCount > 0 && data->omouseY - data->mouseY > MOVE_THRESHOLD) {
867 data->rubCount = -(data->rubCount + 1);
869 } else if (data->rubCount <= 0 && data->mouseY - data->omouseY > MOVE_THRESHOLD) {
871 data->rubCount = -data->rubCount + 1;
874 /* create a new workspace */
875 if (abs(data->rubCount) > 2) {
876 /* go to next workspace */
877 wWorkspaceNew(scr);
879 crossWorkspace(scr, wwin, opaqueMove, scr->current_workspace + 1, False);
880 changed = True;
881 data->rubCount = 0;
883 } else if (scr->current_workspace < scr->workspace_count) {
885 /* go to next workspace */
886 crossWorkspace(scr, wwin, opaqueMove, scr->current_workspace + 1, False);
887 changed = True;
888 data->rubCount = 0;
890 } else {
891 data->rubCount = 0;
894 return changed;
897 static void
898 updateWindowPosition(WWindow * wwin, MoveData * data, Bool doResistance,
899 Bool opaqueMove, int newMouseX, int newMouseY)
901 WScreen *scr = wwin->screen_ptr;
902 int dx, dy; /* how much mouse moved */
903 int winL, winR, winT, winB; /* requested new window position */
904 int newX, newY; /* actual new window position */
905 Bool hresist, vresist;
906 Bool updateIndex;
907 Bool attract;
909 hresist = False;
910 vresist = False;
912 updateIndex = False;
914 /* check the direction of the movement */
915 dx = newMouseX - data->mouseX;
916 dy = newMouseY - data->mouseY;
918 data->omouseX = data->mouseX;
919 data->omouseY = data->mouseY;
920 data->mouseX = newMouseX;
921 data->mouseY = newMouseY;
923 winL = data->calcX + dx;
924 winR = data->calcX + data->winWidth + dx;
925 winT = data->calcY + dy;
926 winB = data->calcY + data->winHeight + dy;
928 newX = data->realX;
929 newY = data->realY;
931 if (doResistance) {
932 int l_edge, r_edge;
933 int edge_l, edge_r;
934 int t_edge, b_edge;
935 int edge_t, edge_b;
936 int resist;
938 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
939 attract = wPreferences.attract;
940 /* horizontal movement: check horizontal edge resistances */
941 if (dx || dy) {
942 WMRect rect;
943 int i, head;
944 /* window is the leftmost window: check against screen edge */
946 /* Add inter head resistance 1/2 (if needed) */
947 head = wGetHeadForPointerLocation(scr);
948 rect = wGetRectForHead(scr, head);
950 l_edge = WMAX(scr->totalUsableArea[head].x1, rect.pos.x);
951 edge_l = l_edge - resist;
952 edge_r = WMIN(scr->totalUsableArea[head].x2, rect.pos.x + rect.size.width);
953 r_edge = edge_r + resist;
955 /* 1 */
956 if ((data->rightIndex >= 0) && (data->rightIndex <= data->count)) {
957 WWindow *looprw;
959 for (i = data->rightIndex - 1; i >= 0; i--) {
960 looprw = data->rightList[i];
961 if (!(data->realY > WBOTTOM(looprw)
962 || (data->realY + data->winHeight) < WTOP(looprw))) {
963 if (attract || ((data->realX < (WRIGHT(looprw) + 2)) && dx < 0)) {
964 l_edge = WRIGHT(looprw) + 1;
965 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
967 break;
971 if (attract) {
972 for (i = data->rightIndex; i < data->count; i++) {
973 looprw = data->rightList[i];
974 if (!(data->realY > WBOTTOM(looprw)
975 || (data->realY + data->winHeight) < WTOP(looprw))) {
976 r_edge = WRIGHT(looprw) + 1;
977 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
978 break;
984 if ((data->leftIndex >= 0) && (data->leftIndex <= data->count)) {
985 WWindow *looprw;
987 for (i = data->leftIndex - 1; i >= 0; i--) {
988 looprw = data->leftList[i];
989 if (!(data->realY > WBOTTOM(looprw)
990 || (data->realY + data->winHeight) < WTOP(looprw))) {
991 if (attract
992 || (((data->realX + data->winWidth) > (WLEFT(looprw) - 1))
993 && dx > 0)) {
994 edge_r = WLEFT(looprw);
995 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
997 break;
1001 if (attract)
1002 for (i = data->leftIndex; i < data->count; i++) {
1003 looprw = data->leftList[i];
1004 if (!(data->realY > WBOTTOM(looprw)
1005 || (data->realY + data->winHeight) < WTOP(looprw))) {
1006 edge_l = WLEFT(looprw);
1007 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1008 break;
1014 printf("%d %d\n",winL,winR);
1015 printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);
1018 if ((winL - l_edge) < (r_edge - winL)) {
1019 if (resist > 0) {
1020 if ((attract && winL <= l_edge + resist && winL >= l_edge - resist)
1021 || (dx < 0 && winL <= l_edge && winL >= l_edge - resist)) {
1022 newX = l_edge;
1023 hresist = True;
1026 } else {
1027 if (resist > 0 && attract && winL >= r_edge - resist && winL <= r_edge + resist) {
1028 newX = r_edge;
1029 hresist = True;
1033 if ((winR - edge_l) < (edge_r - winR)) {
1034 if (resist > 0 && attract && winR <= edge_l + resist && winR >= edge_l - resist) {
1035 newX = edge_l - data->winWidth;
1036 hresist = True;
1038 } else {
1039 if (resist > 0) {
1040 if ((attract && winR >= edge_r - resist && winR <= edge_r + resist)
1041 || (dx > 0 && winR >= edge_r && winR <= edge_r + resist)) {
1042 newX = edge_r - data->winWidth;
1043 hresist = True;
1048 /* VeRT */
1049 /* Add inter head resistance 2/2 (if needed) */
1050 t_edge = WMAX(scr->totalUsableArea[head].y1, rect.pos.y);
1051 edge_t = t_edge - resist;
1052 edge_b = WMIN(scr->totalUsableArea[head].y2, rect.pos.y + rect.size.height);
1053 b_edge = edge_b + resist;
1055 if ((data->bottomIndex >= 0) && (data->bottomIndex <= data->count)) {
1056 WWindow *looprw;
1058 for (i = data->bottomIndex - 1; i >= 0; i--) {
1059 looprw = data->bottomList[i];
1060 if (!(data->realX > WRIGHT(looprw)
1061 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1062 if (attract || ((data->realY < (WBOTTOM(looprw) + 2)) && dy < 0)) {
1063 t_edge = WBOTTOM(looprw) + 1;
1064 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1066 break;
1070 if (attract) {
1071 for (i = data->bottomIndex; i < data->count; i++) {
1072 looprw = data->bottomList[i];
1073 if (!(data->realX > WRIGHT(looprw)
1074 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1075 b_edge = WBOTTOM(looprw) + 1;
1076 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1077 break;
1083 if ((data->topIndex >= 0) && (data->topIndex <= data->count)) {
1084 WWindow *looprw;
1086 for (i = data->topIndex - 1; i >= 0; i--) {
1087 looprw = data->topList[i];
1088 if (!(data->realX > WRIGHT(looprw)
1089 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1090 if (attract
1091 || (((data->realY + data->winHeight) > (WTOP(looprw) - 1))
1092 && dy > 0)) {
1093 edge_b = WTOP(looprw);
1094 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1096 break;
1100 if (attract)
1101 for (i = data->topIndex; i < data->count; i++) {
1102 looprw = data->topList[i];
1103 if (!(data->realX > WRIGHT(looprw)
1104 || (data->realX + data->winWidth) < WLEFT(looprw))) {
1105 edge_t = WTOP(looprw);
1106 resist = WIN_RESISTANCE(wPreferences.edge_resistance);
1107 break;
1112 if ((winT - t_edge) < (b_edge - winT)) {
1113 if (resist > 0) {
1114 if ((attract && winT <= t_edge + resist && winT >= t_edge - resist)
1115 || (dy < 0 && winT <= t_edge && winT >= t_edge - resist)) {
1116 newY = t_edge;
1117 vresist = True;
1120 } else {
1121 if (resist > 0 && attract && winT >= b_edge - resist && winT <= b_edge + resist) {
1122 newY = b_edge;
1123 vresist = True;
1127 if ((winB - edge_t) < (edge_b - winB)) {
1128 if (resist > 0 && attract && winB <= edge_t + resist && winB >= edge_t - resist) {
1129 newY = edge_t - data->winHeight;
1130 vresist = True;
1132 } else {
1133 if (resist > 0) {
1134 if ((attract && winB >= edge_b - resist && winB <= edge_b + resist)
1135 || (dy > 0 && winB >= edge_b && winB <= edge_b + resist)) {
1136 newY = edge_b - data->winHeight;
1137 vresist = True;
1142 /* END VeRT */
1146 /* update window position */
1147 data->calcX += dx;
1148 data->calcY += dy;
1150 if (((dx > 0 && data->calcX - data->realX > 0)
1151 || (dx < 0 && data->calcX - data->realX < 0)) && !hresist)
1152 newX = data->calcX;
1154 if (((dy > 0 && data->calcY - data->realY > 0)
1155 || (dy < 0 && data->calcY - data->realY < 0)) && !vresist)
1156 newY = data->calcY;
1158 if (data->realX != newX || data->realY != newY) {
1160 if (wPreferences.move_display == WDIS_NEW && !scr->selected_windows) {
1161 showPosition(wwin, data->realX, data->realY);
1163 if (opaqueMove) {
1164 doWindowMove(wwin, scr->selected_windows, newX - wwin->frame_x, newY - wwin->frame_y);
1165 } else {
1166 /* erase frames */
1167 drawFrames(wwin, scr->selected_windows,
1168 data->realX - wwin->frame_x, data->realY - wwin->frame_y);
1171 if (!scr->selected_windows && wPreferences.move_display == WDIS_FRAME_CENTER) {
1173 moveGeometryDisplayCentered(scr, newX + data->winWidth / 2, newY + data->winHeight / 2);
1176 if (!opaqueMove) {
1177 /* draw frames */
1178 drawFrames(wwin, scr->selected_windows, newX - wwin->frame_x, newY - wwin->frame_y);
1181 if (!scr->selected_windows) {
1182 showPosition(wwin, newX, newY);
1186 /* recalc relative window position */
1187 if (doResistance && (data->realX != newX || data->realY != newY)) {
1188 updateResistance(wwin, data, newX, newY);
1191 data->realX = newX;
1192 data->realY = newY;
1195 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1197 #define MOVABLE_BIT 0x01
1198 #define RESIZABLE_BIT 0x02
1200 int wKeyboardMoveResizeWindow(WWindow * wwin)
1202 WScreen *scr = wwin->screen_ptr;
1203 Window root = scr->root_win;
1204 XEvent event;
1205 int w = wwin->frame->core->width;
1206 int h = wwin->frame->core->height;
1207 int scr_width = wwin->screen_ptr->scr_width;
1208 int scr_height = wwin->screen_ptr->scr_height;
1209 int vert_border = wwin->frame->top_width + wwin->frame->bottom_width;
1210 int src_x = wwin->frame_x;
1211 int src_y = wwin->frame_y;
1212 int done, off_x, off_y, ww, wh;
1213 int kspeed = _KS;
1214 Time lastTime = 0;
1215 KeyCode shiftl, shiftr, ctrll, ctrlmode;
1216 KeySym keysym = NoSymbol;
1217 int moment = 0;
1218 int modes = ((IS_MOVABLE(wwin) ? MOVABLE_BIT : 0) | (IS_RESIZABLE(wwin) ? RESIZABLE_BIT : 0));
1219 int head = ((wPreferences.auto_arrange_icons && wXineramaHeads(scr) > 1)
1220 ? wGetHeadForWindow(wwin)
1221 : scr->xine_info.primary_head);
1223 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1224 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1225 ctrll = XKeysymToKeycode(dpy, XK_Control_L);
1226 ctrlmode = done = off_x = off_y = 0;
1228 if (modes == RESIZABLE_BIT) {
1229 ctrlmode = 1;
1232 XSync(dpy, False);
1233 wusleep(10000);
1234 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync, CurrentTime);
1236 if (!wwin->flags.selected) {
1237 wUnselectWindows(scr);
1239 XGrabServer(dpy);
1240 XGrabPointer(dpy, scr->root_win, True, PointerMotionMask
1241 | ButtonReleaseMask | ButtonPressMask, GrabModeAsync,
1242 GrabModeAsync, None, wCursor[WCUR_DEFAULT], CurrentTime);
1244 if (wwin->flags.shaded || scr->selected_windows) {
1245 if (scr->selected_windows)
1246 drawFrames(wwin, scr->selected_windows, off_x, off_y);
1247 else
1248 drawTransparentFrame(wwin, src_x + off_x, src_y + off_y, w, h);
1249 if (!scr->selected_windows)
1250 mapPositionDisplay(wwin, src_x, src_y, w, h);
1251 } else {
1252 drawTransparentFrame(wwin, src_x + off_x, src_y + off_y, w, h);
1254 ww = w;
1255 wh = h;
1256 while (1) {
1258 looper.ox=off_x;
1259 looper.oy=off_y;
1261 do {
1262 WMMaskEvent(dpy, KeyPressMask | ButtonReleaseMask
1263 | ButtonPressMask | ExposureMask, &event);
1264 if (event.type == Expose) {
1265 WMHandleEvent(&event);
1267 } while (event.type == Expose);
1269 if (wwin->flags.shaded || scr->selected_windows) {
1270 if (scr->selected_windows)
1271 drawFrames(wwin, scr->selected_windows, off_x, off_y);
1272 else
1273 drawTransparentFrame(wwin, src_x + off_x, src_y + off_y, w, h);
1274 /*** I HATE EDGE RESISTANCE - ]d ***/
1275 } else {
1276 drawTransparentFrame(wwin, src_x + off_x, src_y + off_y, ww, wh);
1279 if (ctrlmode)
1280 showGeometry(wwin, src_x + off_x, src_y + off_y, src_x + off_x + ww, src_y + off_y + wh,
1283 XUngrabServer(dpy);
1284 XSync(dpy, False);
1286 switch (event.type) {
1287 case KeyPress:
1288 /* accelerate */
1289 if (event.xkey.time - lastTime > 50) {
1290 kspeed /= (1 + (event.xkey.time - lastTime) / 100);
1291 } else {
1292 if (kspeed < 20) {
1293 kspeed++;
1296 if (kspeed < _KS)
1297 kspeed = _KS;
1298 lastTime = event.xkey.time;
1299 if (modes == (MOVABLE_BIT | RESIZABLE_BIT)) {
1300 if ((event.xkey.state & ControlMask) && !wwin->flags.shaded) {
1301 ctrlmode = 1;
1302 wUnselectWindows(scr);
1303 } else {
1304 ctrlmode = 0;
1307 if (event.xkey.keycode == shiftl || event.xkey.keycode == shiftr) {
1308 if (ctrlmode)
1309 cycleGeometryDisplay(wwin, src_x + off_x, src_y + off_y, ww, wh, 0);
1310 else
1311 cyclePositionDisplay(wwin, src_x + off_x, src_y + off_y, ww, wh);
1312 } else {
1314 keysym = XLookupKeysym(&event.xkey, 0);
1315 switch (keysym) {
1316 case XK_Return:
1317 done = 2;
1318 break;
1319 case XK_Escape:
1320 done = 1;
1321 break;
1322 case XK_Up:
1323 #ifdef XK_KP_Up
1324 case XK_KP_Up:
1325 #endif
1326 case XK_k:
1327 if (ctrlmode) {
1328 if (moment != UP)
1329 h = wh;
1330 h -= kspeed;
1331 moment = UP;
1332 if (h < 1)
1333 h = 1;
1334 } else
1335 off_y -= kspeed;
1336 break;
1337 case XK_Down:
1338 #ifdef XK_KP_Down
1339 case XK_KP_Down:
1340 #endif
1341 case XK_j:
1342 if (ctrlmode) {
1343 if (moment != DOWN)
1344 h = wh;
1345 h += kspeed;
1346 moment = DOWN;
1347 } else
1348 off_y += kspeed;
1349 break;
1350 case XK_Left:
1351 #ifdef XK_KP_Left
1352 case XK_KP_Left:
1353 #endif
1354 case XK_h:
1355 if (ctrlmode) {
1356 if (moment != LEFT)
1357 w = ww;
1358 w -= kspeed;
1359 if (w < 1)
1360 w = 1;
1361 moment = LEFT;
1362 } else
1363 off_x -= kspeed;
1364 break;
1365 case XK_Right:
1366 #ifdef XK_KP_Right
1367 case XK_KP_Right:
1368 #endif
1369 case XK_l:
1370 if (ctrlmode) {
1371 if (moment != RIGHT)
1372 w = ww;
1373 w += kspeed;
1374 moment = RIGHT;
1375 } else
1376 off_x += kspeed;
1377 break;
1380 ww = w;
1381 wh = h;
1382 wh -= vert_border;
1383 wWindowConstrainSize(wwin, (unsigned int *)&ww, (unsigned int *)&wh);
1384 wh += vert_border;
1386 if (wPreferences.ws_cycle) {
1387 if (src_x + off_x + ww < 20) {
1388 if (!scr->current_workspace) {
1389 wWorkspaceChange(scr, scr->workspace_count - 1);
1390 } else
1391 wWorkspaceChange(scr, scr->current_workspace - 1);
1392 off_x += scr_width;
1393 } else if (src_x + off_x + 20 > scr_width) {
1394 if (scr->current_workspace == scr->workspace_count - 1) {
1395 wWorkspaceChange(scr, 0);
1396 } else
1397 wWorkspaceChange(scr, scr->current_workspace + 1);
1398 off_x -= scr_width;
1400 } else {
1401 if (src_x + off_x + ww < 20)
1402 off_x = 20 - ww - src_x;
1403 else if (src_x + off_x + 20 > scr_width)
1404 off_x = scr_width - 20 - src_x;
1407 if (src_y + off_y + wh < 20) {
1408 off_y = 20 - wh - src_y;
1409 } else if (src_y + off_y + 20 > scr_height) {
1410 off_y = scr_height - 20 - src_y;
1413 break;
1414 case ButtonPress:
1415 case ButtonRelease:
1416 done = 1;
1417 break;
1418 case Expose:
1419 WMHandleEvent(&event);
1420 while (XCheckTypedEvent(dpy, Expose, &event)) {
1421 WMHandleEvent(&event);
1423 break;
1425 default:
1426 WMHandleEvent(&event);
1427 break;
1430 XGrabServer(dpy);
1431 /*xxx */
1433 if (wwin->flags.shaded && !scr->selected_windows) {
1434 moveGeometryDisplayCentered(scr, src_x + off_x + w / 2, src_y + off_y + h / 2);
1435 } else {
1436 if (ctrlmode) {
1437 WMUnmapWidget(scr->gview);
1438 mapGeometryDisplay(wwin, src_x + off_x, src_y + off_y, ww, wh);
1439 } else if (!scr->selected_windows) {
1440 WMUnmapWidget(scr->gview);
1441 mapPositionDisplay(wwin, src_x + off_x, src_y + off_y, ww, wh);
1445 if (wwin->flags.shaded || scr->selected_windows) {
1446 if (scr->selected_windows)
1447 drawFrames(wwin, scr->selected_windows, off_x, off_y);
1448 else
1449 drawTransparentFrame(wwin, src_x + off_x, src_y + off_y, w, h);
1450 } else {
1451 drawTransparentFrame(wwin, src_x + off_x, src_y + off_y, ww, wh);
1454 if (ctrlmode) {
1455 showGeometry(wwin, src_x + off_x, src_y + off_y, src_x + off_x + ww, src_y + off_y + wh,
1457 } else if (!scr->selected_windows)
1458 showPosition(wwin, src_x + off_x, src_y + off_y);
1460 if (done) {
1461 scr->keymove_tick = 0;
1463 WMDeleteTimerWithClientData(&looper);
1465 if (wwin->flags.shaded || scr->selected_windows) {
1466 if (scr->selected_windows)
1467 drawFrames(wwin, scr->selected_windows, off_x, off_y);
1468 else
1469 drawTransparentFrame(wwin, src_x + off_x, src_y + off_y, w, h);
1470 } else {
1471 drawTransparentFrame(wwin, src_x + off_x, src_y + off_y, ww, wh);
1474 if (ctrlmode) {
1475 showGeometry(wwin, src_x + off_x, src_y + off_y, src_x + off_x + ww,
1476 src_y + off_y + wh, 0);
1477 WMUnmapWidget(scr->gview);
1478 } else
1479 WMUnmapWidget(scr->gview);
1481 XUngrabKeyboard(dpy, CurrentTime);
1482 XUngrabPointer(dpy, CurrentTime);
1483 XUngrabServer(dpy);
1485 if (done == 2) {
1486 if (wwin->flags.shaded || scr->selected_windows) {
1487 if (!scr->selected_windows) {
1488 wWindowMove(wwin, src_x + off_x, src_y + off_y);
1489 wWindowSynthConfigureNotify(wwin);
1490 } else {
1491 WMArrayIterator iter;
1492 WWindow *foo;
1494 doWindowMove(wwin, scr->selected_windows, off_x, off_y);
1496 WM_ITERATE_ARRAY(scr->selected_windows, foo, iter) {
1497 wWindowSynthConfigureNotify(foo);
1500 } else {
1501 if (wwin->client.width != ww) {
1502 wwin->flags.user_changed_width = 1;
1503 wwin->flags.maximized &= ~(MAX_HORIZONTAL | MAX_MAXIMUS);
1506 if (wwin->client.height != wh - vert_border) {
1507 wwin->flags.user_changed_height = 1;
1508 wwin->flags.maximized &= ~(MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_MAXIMUS);
1511 wWindowConfigure(wwin, src_x + off_x, src_y + off_y, ww, wh - vert_border);
1512 wWindowSynthConfigureNotify(wwin);
1514 wWindowChangeWorkspace(wwin, scr->current_workspace);
1515 wSetFocusTo(scr, wwin);
1518 if (wPreferences.auto_arrange_icons && wXineramaHeads(scr) > 1 &&
1519 head != wGetHeadForWindow(wwin)) {
1520 wArrangeIcons(scr, True);
1523 return 1;
1529 *----------------------------------------------------------------------
1530 * wMouseMoveWindow--
1531 * Move the named window and the other selected ones (if any),
1532 * interactively. Also shows the position of the window, if only one
1533 * window is being moved.
1534 * If the window is not on the selected window list, the selected
1535 * windows are deselected.
1536 * If shift is pressed during the operation, the position display
1537 * is changed to another type.
1539 * Returns:
1540 * True if the window was moved, False otherwise.
1542 * Side effects:
1543 * The window(s) position is changed, and the client(s) are
1544 * notified about that.
1545 * The position display configuration may be changed.
1546 *----------------------------------------------------------------------
1548 int wMouseMoveWindow(WWindow * wwin, XEvent * ev)
1550 WScreen *scr = wwin->screen_ptr;
1551 XEvent event;
1552 Window root = scr->root_win;
1553 KeyCode shiftl, shiftr;
1554 Bool done = False;
1555 int started = 0;
1556 int warped = 0;
1557 /* This needs not to change while moving, else bad things can happen */
1558 int opaqueMove = wPreferences.opaque_move;
1559 MoveData moveData;
1560 int head = ((wPreferences.auto_arrange_icons && wXineramaHeads(scr) > 1)
1561 ? wGetHeadForWindow(wwin)
1562 : scr->xine_info.primary_head);
1564 if (!IS_MOVABLE(wwin))
1565 return False;
1567 if (wPreferences.opaque_move && !wPreferences.use_saveunders) {
1568 XSetWindowAttributes attr;
1570 attr.save_under = True;
1571 XChangeWindowAttributes(dpy, wwin->frame->core->window, CWSaveUnder, &attr);
1574 initMoveData(wwin, &moveData);
1576 moveData.mouseX = ev->xmotion.x_root;
1577 moveData.mouseY = ev->xmotion.y_root;
1579 if (!wwin->flags.selected) {
1580 /* this window is not selected, unselect others and move only wwin */
1581 wUnselectWindows(scr);
1583 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1584 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1585 while (!done) {
1586 if (warped) {
1587 int junk;
1588 Window junkw;
1590 /* XWarpPointer() doesn't seem to generate Motion events, so
1591 * we've got to simulate them */
1592 XQueryPointer(dpy, root, &junkw, &junkw, &event.xmotion.x_root,
1593 &event.xmotion.y_root, &junk, &junk, (unsigned *)&junk);
1594 } else {
1595 WMMaskEvent(dpy, KeyPressMask | ButtonMotionMask
1596 | PointerMotionHintMask
1597 | ButtonReleaseMask | ButtonPressMask | ExposureMask, &event);
1599 if (event.type == MotionNotify) {
1600 /* compress MotionNotify events */
1601 while (XCheckMaskEvent(dpy, ButtonMotionMask, &event)) ;
1602 if (!checkMouseSamplingRate(&event))
1603 continue;
1606 switch (event.type) {
1607 case KeyPress:
1608 if ((event.xkey.keycode == shiftl || event.xkey.keycode == shiftr)
1609 && started && !scr->selected_windows) {
1611 if (!opaqueMove) {
1612 drawFrames(wwin, scr->selected_windows,
1613 moveData.realX - wwin->frame_x, moveData.realY - wwin->frame_y);
1616 if (wPreferences.move_display == WDIS_NEW && !scr->selected_windows) {
1617 showPosition(wwin, moveData.realX, moveData.realY);
1618 XUngrabServer(dpy);
1620 cyclePositionDisplay(wwin, moveData.realX, moveData.realY,
1621 moveData.winWidth, moveData.winHeight);
1623 if (wPreferences.move_display == WDIS_NEW && !scr->selected_windows) {
1624 XGrabServer(dpy);
1625 showPosition(wwin, moveData.realX, moveData.realY);
1628 if (!opaqueMove) {
1629 drawFrames(wwin, scr->selected_windows,
1630 moveData.realX - wwin->frame_x, moveData.realY - wwin->frame_y);
1632 /*} else {
1633 WMHandleEvent(&event); this causes problems needs fixing */
1635 break;
1637 case MotionNotify:
1638 if (started) {
1639 updateWindowPosition(wwin, &moveData,
1640 scr->selected_windows == NULL
1641 && wPreferences.edge_resistance > 0,
1642 opaqueMove, event.xmotion.x_root, event.xmotion.y_root);
1644 if (!warped && !wPreferences.no_autowrap) {
1645 int oldWorkspace = scr->current_workspace;
1647 if (wPreferences.move_display == WDIS_NEW && !scr->selected_windows) {
1648 showPosition(wwin, moveData.realX, moveData.realY);
1649 XUngrabServer(dpy);
1651 if (!opaqueMove) {
1652 drawFrames(wwin, scr->selected_windows,
1653 moveData.realX - wwin->frame_x,
1654 moveData.realY - wwin->frame_y);
1656 if (checkWorkspaceChange(wwin, &moveData, opaqueMove)) {
1657 if (scr->current_workspace != oldWorkspace
1658 && wPreferences.edge_resistance > 0
1659 && scr->selected_windows == NULL)
1660 updateMoveData(wwin, &moveData);
1661 warped = 1;
1663 if (!opaqueMove) {
1664 drawFrames(wwin, scr->selected_windows,
1665 moveData.realX - wwin->frame_x,
1666 moveData.realY - wwin->frame_y);
1668 if (wPreferences.move_display == WDIS_NEW && !scr->selected_windows) {
1669 XSync(dpy, False);
1670 showPosition(wwin, moveData.realX, moveData.realY);
1671 XGrabServer(dpy);
1673 } else {
1674 warped = 0;
1676 } else if (abs(ev->xmotion.x_root - event.xmotion.x_root) >= MOVE_THRESHOLD
1677 || abs(ev->xmotion.y_root - event.xmotion.y_root) >= MOVE_THRESHOLD) {
1679 XChangeActivePointerGrab(dpy, ButtonMotionMask
1680 | ButtonReleaseMask | ButtonPressMask,
1681 wCursor[WCUR_MOVE], CurrentTime);
1682 started = 1;
1683 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync, CurrentTime);
1685 if (!scr->selected_windows)
1686 mapPositionDisplay(wwin, moveData.realX, moveData.realY,
1687 moveData.winWidth, moveData.winHeight);
1689 if (started && !opaqueMove)
1690 drawFrames(wwin, scr->selected_windows, 0, 0);
1692 if (!opaqueMove || (wPreferences.move_display == WDIS_NEW
1693 && !scr->selected_windows)) {
1694 XGrabServer(dpy);
1695 if (wPreferences.move_display == WDIS_NEW)
1696 showPosition(wwin, moveData.realX, moveData.realY);
1699 break;
1701 case ButtonPress:
1702 break;
1704 case ButtonRelease:
1705 if (event.xbutton.button != ev->xbutton.button)
1706 break;
1708 if (started) {
1709 XEvent e;
1710 if (!opaqueMove) {
1711 drawFrames(wwin, scr->selected_windows,
1712 moveData.realX - wwin->frame_x, moveData.realY - wwin->frame_y);
1713 XSync(dpy, 0);
1714 doWindowMove(wwin, scr->selected_windows,
1715 moveData.realX - wwin->frame_x,
1716 moveData.realY - wwin->frame_y);
1718 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1719 wWindowSynthConfigureNotify(wwin);
1720 #endif
1721 XUngrabKeyboard(dpy, CurrentTime);
1722 XUngrabServer(dpy);
1723 if (!opaqueMove) {
1724 wWindowChangeWorkspace(wwin, scr->current_workspace);
1725 wSetFocusTo(scr, wwin);
1727 if (wPreferences.move_display == WDIS_NEW)
1728 showPosition(wwin, moveData.realX, moveData.realY);
1730 /* discard all enter/leave events that happened until
1731 * the time the button was released */
1732 while (XCheckTypedEvent(dpy, EnterNotify, &e)) {
1733 if (e.xcrossing.time > event.xbutton.time) {
1734 XPutBackEvent(dpy, &e);
1735 break;
1738 while (XCheckTypedEvent(dpy, LeaveNotify, &e)) {
1739 if (e.xcrossing.time > event.xbutton.time) {
1740 XPutBackEvent(dpy, &e);
1741 break;
1745 if (!scr->selected_windows) {
1746 /* get rid of the geometry window */
1747 WMUnmapWidget(scr->gview);
1750 done = True;
1751 break;
1753 default:
1754 if (started && !opaqueMove) {
1755 drawFrames(wwin, scr->selected_windows,
1756 moveData.realX - wwin->frame_x, moveData.realY - wwin->frame_y);
1757 XUngrabServer(dpy);
1758 WMHandleEvent(&event);
1759 XSync(dpy, False);
1760 XGrabServer(dpy);
1761 drawFrames(wwin, scr->selected_windows,
1762 moveData.realX - wwin->frame_x, moveData.realY - wwin->frame_y);
1763 } else {
1764 WMHandleEvent(&event);
1766 break;
1770 if (wPreferences.opaque_move && !wPreferences.use_saveunders) {
1771 XSetWindowAttributes attr;
1773 attr.save_under = False;
1774 XChangeWindowAttributes(dpy, wwin->frame->core->window, CWSaveUnder, &attr);
1778 freeMoveData(&moveData);
1780 if (started && wPreferences.auto_arrange_icons && wXineramaHeads(scr) > 1 &&
1781 head != wGetHeadForWindow(wwin)) {
1782 wArrangeIcons(scr, True);
1784 return started;
1787 #define RESIZEBAR 1
1788 #define HCONSTRAIN 2
1790 static int getResizeDirection(WWindow * wwin, int x, int y, int dx, int dy, int flags)
1792 int w = wwin->frame->core->width - 1;
1793 int cw = wwin->frame->resizebar_corner_width;
1794 int dir;
1796 /* if not resizing through the resizebar */
1797 if (!(flags & RESIZEBAR)) {
1798 int xdir = (abs(x) < (wwin->client.width / 2)) ? LEFT : RIGHT;
1799 int ydir = (abs(y) < (wwin->client.height / 2)) ? UP : DOWN;
1800 if (abs(dx) < 2 || abs(dy) < 2) {
1801 if (abs(dy) > abs(dx))
1802 xdir = 0;
1803 else
1804 ydir = 0;
1806 return (xdir | ydir);
1809 /* window is too narrow. allow diagonal resize */
1810 if (cw * 2 >= w) {
1811 int ydir;
1813 if (flags & HCONSTRAIN)
1814 ydir = 0;
1815 else
1816 ydir = DOWN;
1817 if (x < cw)
1818 return (LEFT | ydir);
1819 else
1820 return (RIGHT | ydir);
1822 /* vertical resize */
1823 if ((x > cw) && (x < w - cw))
1824 return DOWN;
1826 if (x < cw)
1827 dir = LEFT;
1828 else
1829 dir = RIGHT;
1831 if ((abs(dy) > 0) && !(flags & HCONSTRAIN))
1832 dir |= DOWN;
1834 return dir;
1837 void wMouseResizeWindow(WWindow * wwin, XEvent * ev)
1839 XEvent event;
1840 WScreen *scr = wwin->screen_ptr;
1841 Window root = scr->root_win;
1842 int vert_border = wwin->frame->top_width + wwin->frame->bottom_width;
1843 int fw = wwin->frame->core->width;
1844 int fh = wwin->frame->core->height;
1845 int fx = wwin->frame_x;
1846 int fy = wwin->frame_y;
1847 int is_resizebar = (wwin->frame->resizebar && ev->xany.window == wwin->frame->resizebar->window);
1848 int orig_x, orig_y;
1849 int started;
1850 int dw, dh;
1851 int rw = fw, rh = fh;
1852 int rx1, ry1, rx2, ry2;
1853 int res = 0;
1854 KeyCode shiftl, shiftr;
1855 int h = 0;
1856 int orig_fx = fx;
1857 int orig_fy = fy;
1858 int orig_fw = fw;
1859 int orig_fh = fh;
1860 int head = ((wPreferences.auto_arrange_icons && wXineramaHeads(scr) > 1)
1861 ? wGetHeadForWindow(wwin)
1862 : scr->xine_info.primary_head);
1864 if (!IS_RESIZABLE(wwin))
1865 return;
1867 if (wwin->flags.shaded) {
1868 wwarning("internal error: tryein");
1869 return;
1871 orig_x = ev->xbutton.x_root;
1872 orig_y = ev->xbutton.y_root;
1874 started = 0;
1875 wUnselectWindows(scr);
1876 rx1 = fx;
1877 rx2 = fx + fw - 1;
1878 ry1 = fy;
1879 ry2 = fy + fh - 1;
1880 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
1881 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
1882 if (HAS_TITLEBAR(wwin))
1883 h = WMFontHeight(wwin->screen_ptr->title_font) + (wPreferences.window_title_clearance +
1884 TITLEBAR_EXTEND_SPACE) * 2;
1885 else
1886 h = 0;
1887 while (1) {
1888 WMMaskEvent(dpy, KeyPressMask | ButtonMotionMask
1889 | ButtonReleaseMask | PointerMotionHintMask | ButtonPressMask | ExposureMask, &event);
1890 if (!checkMouseSamplingRate(&event))
1891 continue;
1893 switch (event.type) {
1894 case KeyPress:
1895 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1896 if ((event.xkey.keycode == shiftl || event.xkey.keycode == shiftr)
1897 && started) {
1898 drawTransparentFrame(wwin, fx, fy, fw, fh);
1899 cycleGeometryDisplay(wwin, fx, fy, fw, fh, res);
1900 drawTransparentFrame(wwin, fx, fy, fw, fh);
1902 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
1903 break;
1905 case MotionNotify:
1906 if (started) {
1907 while (XCheckMaskEvent(dpy, ButtonMotionMask, &event)) ;
1909 dw = 0;
1910 dh = 0;
1912 orig_fx = fx;
1913 orig_fy = fy;
1914 orig_fw = fw;
1915 orig_fh = fh;
1917 if (res & LEFT)
1918 dw = orig_x - event.xmotion.x_root;
1919 else if (res & RIGHT)
1920 dw = event.xmotion.x_root - orig_x;
1921 if (res & UP)
1922 dh = orig_y - event.xmotion.y_root;
1923 else if (res & DOWN)
1924 dh = event.xmotion.y_root - orig_y;
1926 orig_x = event.xmotion.x_root;
1927 orig_y = event.xmotion.y_root;
1929 rw += dw;
1930 rh += dh;
1931 fw = rw;
1932 fh = rh - vert_border;
1933 wWindowConstrainSize(wwin, (unsigned int *)&fw, (unsigned int *)&fh);
1934 fh += vert_border;
1935 if (res & LEFT)
1936 fx = rx2 - fw + 1;
1937 else if (res & RIGHT)
1938 fx = rx1;
1939 if (res & UP)
1940 fy = ry2 - fh + 1;
1941 else if (res & DOWN)
1942 fy = ry1;
1943 } else if (abs(orig_x - event.xmotion.x_root) >= MOVE_THRESHOLD
1944 || abs(orig_y - event.xmotion.y_root) >= MOVE_THRESHOLD) {
1945 int tx, ty;
1946 Window junkw;
1947 int flags;
1949 XTranslateCoordinates(dpy, root, wwin->frame->core->window,
1950 orig_x, orig_y, &tx, &ty, &junkw);
1952 /* check if resizing through resizebar */
1953 if (is_resizebar)
1954 flags = RESIZEBAR;
1955 else
1956 flags = 0;
1958 if (is_resizebar && ((ev->xbutton.state & ShiftMask)
1959 || abs(orig_y - event.xmotion.y_root) < HRESIZE_THRESHOLD))
1960 flags |= HCONSTRAIN;
1962 res = getResizeDirection(wwin, tx, ty,
1963 orig_x - event.xmotion.x_root,
1964 orig_y - event.xmotion.y_root, flags);
1966 if (res == (UP | LEFT))
1967 XChangeActivePointerGrab(dpy, ButtonMotionMask
1968 | ButtonReleaseMask | ButtonPressMask,
1969 wCursor[WCUR_TOPLEFTRESIZE], CurrentTime);
1970 else if (res == (UP | RIGHT))
1971 XChangeActivePointerGrab(dpy, ButtonMotionMask
1972 | ButtonReleaseMask | ButtonPressMask,
1973 wCursor[WCUR_TOPRIGHTRESIZE], CurrentTime);
1974 else if (res == (DOWN | LEFT))
1975 XChangeActivePointerGrab(dpy, ButtonMotionMask
1976 | ButtonReleaseMask | ButtonPressMask,
1977 wCursor[WCUR_BOTTOMLEFTRESIZE], CurrentTime);
1978 else if (res == (DOWN | RIGHT))
1979 XChangeActivePointerGrab(dpy, ButtonMotionMask
1980 | ButtonReleaseMask | ButtonPressMask,
1981 wCursor[WCUR_BOTTOMRIGHTRESIZE], CurrentTime);
1982 else if (res == DOWN || res == UP)
1983 XChangeActivePointerGrab(dpy, ButtonMotionMask
1984 | ButtonReleaseMask | ButtonPressMask,
1985 wCursor[WCUR_VERTICALRESIZE], CurrentTime);
1986 else if (res & (DOWN | UP))
1987 XChangeActivePointerGrab(dpy, ButtonMotionMask
1988 | ButtonReleaseMask | ButtonPressMask,
1989 wCursor[WCUR_VERTICALRESIZE], CurrentTime);
1990 else if (res & (LEFT | RIGHT))
1991 XChangeActivePointerGrab(dpy, ButtonMotionMask
1992 | ButtonReleaseMask | ButtonPressMask,
1993 wCursor[WCUR_HORIZONRESIZE], CurrentTime);
1995 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync, CurrentTime);
1997 XGrabServer(dpy);
1999 /* Draw the resize frame for the first time. */
2000 mapGeometryDisplay(wwin, fx, fy, fw, fh);
2002 drawTransparentFrame(wwin, fx, fy, fw, fh);
2004 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
2006 started = 1;
2008 if (started) {
2009 if (wPreferences.size_display == WDIS_FRAME_CENTER) {
2010 drawTransparentFrame(wwin, orig_fx, orig_fy, orig_fw, orig_fh);
2011 moveGeometryDisplayCentered(scr, fx + fw / 2, fy + fh / 2);
2012 drawTransparentFrame(wwin, fx, fy, fw, fh);
2013 } else {
2014 drawTransparentFrame(wwin, orig_fx, orig_fy, orig_fw, orig_fh);
2015 drawTransparentFrame(wwin, fx, fy, fw, fh);
2017 if (fh != orig_fh || fw != orig_fw) {
2018 if (wPreferences.size_display == WDIS_NEW) {
2019 showGeometry(wwin, orig_fx, orig_fy, orig_fx + orig_fw,
2020 orig_fy + orig_fh, res);
2022 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
2025 break;
2027 case ButtonPress:
2028 break;
2030 case ButtonRelease:
2031 if (event.xbutton.button != ev->xbutton.button)
2032 break;
2034 if (started) {
2035 showGeometry(wwin, fx, fy, fx + fw, fy + fh, res);
2037 drawTransparentFrame(wwin, fx, fy, fw, fh);
2039 XUngrabKeyboard(dpy, CurrentTime);
2040 WMUnmapWidget(scr->gview);
2041 XUngrabServer(dpy);
2043 if (wwin->client.width != fw) {
2044 wwin->flags.user_changed_width = 1;
2045 wwin->flags.maximized &= ~(MAX_HORIZONTAL | MAX_MAXIMUS);
2048 if (wwin->client.height != fh - vert_border) {
2049 wwin->flags.user_changed_height = 1;
2050 wwin->flags.maximized &= ~(MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_MAXIMUS);
2053 wWindowConfigure(wwin, fx, fy, fw, fh - vert_border);
2055 return;
2057 default:
2058 WMHandleEvent(&event);
2062 if (wPreferences.auto_arrange_icons && wXineramaHeads(scr) > 1 && head != wGetHeadForWindow(wwin)) {
2063 wArrangeIcons(scr, True);
2067 #undef LEFT
2068 #undef RIGHT
2069 #undef HORIZONTAL
2070 #undef UP
2071 #undef DOWN
2072 #undef VERTICAL
2073 #undef HCONSTRAIN
2074 #undef RESIZEBAR
2076 void wUnselectWindows(WScreen * scr)
2078 WWindow *wwin;
2080 if (!scr->selected_windows)
2081 return;
2083 while (WMGetArrayItemCount(scr->selected_windows)) {
2084 wwin = WMGetFromArray(scr->selected_windows, 0);
2085 if (wwin->flags.miniaturized && wwin->icon && wwin->icon->selected)
2086 wIconSelect(wwin->icon);
2088 wSelectWindow(wwin, False);
2090 WMFreeArray(scr->selected_windows);
2091 scr->selected_windows = NULL;
2094 static void selectWindowsInside(WScreen * scr, int x1, int y1, int x2, int y2)
2096 WWindow *tmpw;
2098 /* select the windows and put them in the selected window list */
2099 tmpw = scr->focused_window;
2100 while (tmpw != NULL) {
2101 if (!(tmpw->flags.miniaturized || tmpw->flags.hidden)) {
2102 if ((tmpw->frame->workspace == scr->current_workspace || IS_OMNIPRESENT(tmpw))
2103 && (tmpw->frame_x >= x1) && (tmpw->frame_y >= y1)
2104 && (tmpw->frame->core->width + tmpw->frame_x <= x2)
2105 && (tmpw->frame->core->height + tmpw->frame_y <= y2)) {
2106 wSelectWindow(tmpw, True);
2109 tmpw = tmpw->prev;
2113 void wSelectWindows(WScreen * scr, XEvent * ev)
2115 XEvent event;
2116 Window root = scr->root_win;
2117 GC gc = scr->frame_gc;
2118 int xp = ev->xbutton.x_root;
2119 int yp = ev->xbutton.y_root;
2120 int w = 0, h = 0;
2121 int x = xp, y = yp;
2123 if (XGrabPointer(dpy, scr->root_win, False, ButtonMotionMask
2124 | ButtonReleaseMask | ButtonPressMask, GrabModeAsync,
2125 GrabModeAsync, None, wCursor[WCUR_DEFAULT], CurrentTime) != Success) {
2126 return;
2128 XGrabServer(dpy);
2130 wUnselectWindows(scr);
2132 XDrawRectangle(dpy, root, gc, xp, yp, w, h);
2133 while (1) {
2134 WMMaskEvent(dpy, ButtonReleaseMask | PointerMotionMask | ButtonPressMask, &event);
2136 switch (event.type) {
2137 case MotionNotify:
2138 XDrawRectangle(dpy, root, gc, x, y, w, h);
2139 x = event.xmotion.x_root;
2140 if (x < xp) {
2141 w = xp - x;
2142 } else {
2143 w = x - xp;
2144 x = xp;
2146 y = event.xmotion.y_root;
2147 if (y < yp) {
2148 h = yp - y;
2149 } else {
2150 h = y - yp;
2151 y = yp;
2153 XDrawRectangle(dpy, root, gc, x, y, w, h);
2154 break;
2156 case ButtonPress:
2157 break;
2159 case ButtonRelease:
2160 if (event.xbutton.button != ev->xbutton.button)
2161 break;
2163 XDrawRectangle(dpy, root, gc, x, y, w, h);
2164 XUngrabServer(dpy);
2165 XUngrabPointer(dpy, CurrentTime);
2166 selectWindowsInside(scr, x, y, x + w, y + h);
2167 return;
2169 default:
2170 WMHandleEvent(&event);
2171 break;
2176 void InteractivePlaceWindow(WWindow * wwin, int *x_ret, int *y_ret, unsigned width, unsigned height)
2178 WScreen *scr = wwin->screen_ptr;
2179 Window root = scr->root_win;
2180 int x, y, h = 0;
2181 XEvent event;
2182 KeyCode shiftl, shiftr;
2183 Window junkw;
2184 int junk;
2186 if (XGrabPointer(dpy, root, True, PointerMotionMask | ButtonPressMask,
2187 GrabModeAsync, GrabModeAsync, None, wCursor[WCUR_DEFAULT], CurrentTime) != Success) {
2188 *x_ret = 0;
2189 *y_ret = 0;
2190 return;
2192 if (HAS_TITLEBAR(wwin)) {
2193 h = WMFontHeight(scr->title_font) + (wPreferences.window_title_clearance +
2194 TITLEBAR_EXTEND_SPACE) * 2;
2195 height += h;
2197 if (HAS_RESIZEBAR(wwin)) {
2198 height += RESIZEBAR_HEIGHT;
2200 XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync, CurrentTime);
2201 XQueryPointer(dpy, root, &junkw, &junkw, &x, &y, &junk, &junk, (unsigned *)&junk);
2202 mapPositionDisplay(wwin, x - width / 2, y - h / 2, width, height);
2204 drawTransparentFrame(wwin, x - width / 2, y - h / 2, width, height);
2206 shiftl = XKeysymToKeycode(dpy, XK_Shift_L);
2207 shiftr = XKeysymToKeycode(dpy, XK_Shift_R);
2208 while (1) {
2209 WMMaskEvent(dpy, PointerMotionMask | ButtonPressMask | ExposureMask | KeyPressMask, &event);
2211 if (!checkMouseSamplingRate(&event))
2212 continue;
2214 switch (event.type) {
2215 case KeyPress:
2216 if ((event.xkey.keycode == shiftl)
2217 || (event.xkey.keycode == shiftr)) {
2218 drawTransparentFrame(wwin, x - width / 2, y - h / 2, width, height);
2219 cyclePositionDisplay(wwin, x - width / 2, y - h / 2, width, height);
2220 drawTransparentFrame(wwin, x - width / 2, y - h / 2, width, height);
2222 break;
2224 case MotionNotify:
2225 drawTransparentFrame(wwin, x - width / 2, y - h / 2, width, height);
2227 x = event.xmotion.x_root;
2228 y = event.xmotion.y_root;
2230 if (wPreferences.move_display == WDIS_FRAME_CENTER)
2231 moveGeometryDisplayCentered(scr, x, y + (height - h) / 2);
2233 showPosition(wwin, x - width / 2, y - h / 2);
2235 drawTransparentFrame(wwin, x - width / 2, y - h / 2, width, height);
2237 break;
2239 case ButtonPress:
2240 drawTransparentFrame(wwin, x - width / 2, y - h / 2, width, height);
2241 XSync(dpy, 0);
2242 *x_ret = x - width / 2;
2243 *y_ret = y - h / 2;
2244 XUngrabPointer(dpy, CurrentTime);
2245 XUngrabKeyboard(dpy, CurrentTime);
2246 /* get rid of the geometry window */
2247 WMUnmapWidget(scr->gview);
2248 return;
2250 default:
2251 WMHandleEvent(&event);
2252 break;