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 along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <X11/Xutil.h>
25 #include <X11/keysym.h>
31 #include "WindowMaker.h"
39 #include "workspace.h"
45 #include <WINGs/WINGsP.h>
47 /* How many different types of geometry/position
48 display thingies are there? */
49 #define NUM_DISPLAYS 5
53 #define HORIZONTAL (LEFT|RIGHT)
56 #define VERTICAL (UP|DOWN)
58 /* True if window currently has a border. This also includes borderless
59 * windows which are currently selected
61 #define HAS_BORDER_WITH_SELECT(w) ((w)->flags.selected || HAS_BORDER(w))
63 /****** Global Variables ******/
64 extern Cursor wCursor
[WCUR_LAST
];
65 extern WPreferences wPreferences
;
68 *----------------------------------------------------------------------
69 * checkMouseSamplingRate-
70 * For lowering the mouse motion sampling rate for machines where
71 * it's too high (SGIs). If it returns False then the event should be
73 *----------------------------------------------------------------------
75 static Bool
checkMouseSamplingRate(XEvent
* ev
)
77 static Time previousMotion
= 0;
79 if (ev
->type
== MotionNotify
) {
80 if (ev
->xmotion
.time
- previousMotion
< DELAY_BETWEEN_MOUSE_SAMPLING
) {
83 previousMotion
= ev
->xmotion
.time
;
90 *----------------------------------------------------------------------
91 * moveGeometryDisplayCentered
93 * routine that moves the geometry/position window on scr so it is
94 * centered over the given coordinates (x,y). Also the window position
95 * is clamped so it stays on the screen at all times.
96 *----------------------------------------------------------------------
98 static void moveGeometryDisplayCentered(WScreen
* scr
, int x
, int y
)
100 unsigned int w
= WMWidgetWidth(scr
->gview
);
101 unsigned int h
= WMWidgetHeight(scr
->gview
);
102 int x1
= 0, y1
= 0, x2
= scr
->scr_width
, y2
= scr
->scr_height
;
107 /* dead area check */
108 if (scr
->xine_info
.count
) {
115 rect
.size
.height
= h
;
117 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
119 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
120 rect
= wGetRectForHead(scr
, head
);
123 x2
= x1
+ rect
.size
.width
;
124 y2
= y1
+ rect
.size
.height
;
130 else if (x
> (x2
- w
))
135 else if (y
> (y2
- h
))
138 WMMoveWidget(scr
->gview
, x
, y
);
141 static void showPosition(WWindow
* wwin
, int x
, int y
)
143 WScreen
*scr
= wwin
->screen_ptr
;
145 if (wPreferences
.move_display
== WDIS_NEW
) {
147 int width
= wwin
->frame
->core
->width
;
148 int height
= wwin
->frame
->core
->height
;
150 GC lgc
= scr
->line_gc
;
151 XSetForeground(dpy
, lgc
, scr
->line_pixel
);
152 sprintf(num
, "%i", x
);
154 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
- 1, scr
->scr_width
, y
- 1);
155 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
+ height
+ 2, scr
->scr_width
, y
+ height
+ 2);
156 XDrawLine(dpy
, scr
->root_win
, lgc
, x
- 1, 0, x
- 1, scr
->scr_height
);
157 XDrawLine(dpy
, scr
->root_win
, lgc
, x
+ width
+ 2, 0, x
+ width
+ 2, scr
->scr_height
);
160 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
164 static void cyclePositionDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
)
166 WScreen
*scr
= wwin
->screen_ptr
;
169 wPreferences
.move_display
++;
170 wPreferences
.move_display
%= NUM_DISPLAYS
;
172 if (wPreferences
.move_display
== WDIS_NEW
) {
173 wPreferences
.move_display
++;
174 wPreferences
.move_display
%= NUM_DISPLAYS
;
177 if (wPreferences
.move_display
== WDIS_NONE
) {
178 WMUnmapWidget(scr
->gview
);
180 if (wPreferences
.move_display
== WDIS_CENTER
) {
181 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
182 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
183 rect
.pos
.y
+ rect
.size
.height
/ 2);
184 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
185 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
186 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
187 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
188 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
190 WMMapWidget(scr
->gview
);
194 static void mapPositionDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
)
196 WScreen
*scr
= wwin
->screen_ptr
;
199 if (wPreferences
.move_display
== WDIS_NEW
|| wPreferences
.move_display
== WDIS_NONE
) {
201 } else if (wPreferences
.move_display
== WDIS_CENTER
) {
202 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
203 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
204 rect
.pos
.y
+ rect
.size
.height
/ 2);
205 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
206 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
207 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
208 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
209 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
211 WMMapWidget(scr
->gview
);
212 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
215 static void showGeometry(WWindow
* wwin
, int x1
, int y1
, int x2
, int y2
, int direction
)
217 WScreen
*scr
= wwin
->screen_ptr
;
218 Window root
= scr
->root_win
;
219 GC gc
= scr
->line_gc
;
220 int ty
, by
, my
, x
, y
, mx
, s
;
225 /* This seems necessary for some odd reason (too lazy to write x1-1 and
226 * x2-1 everywhere below in the code). But why only for x? */
230 if (HAS_BORDER_WITH_SELECT(wwin
)) {
231 x1
+= FRAME_BORDER_WIDTH
;
232 x2
+= FRAME_BORDER_WIDTH
;
233 y1
+= FRAME_BORDER_WIDTH
;
234 y2
+= FRAME_BORDER_WIDTH
;
237 ty
= y1
+ wwin
->frame
->top_width
;
238 by
= y2
- wwin
->frame
->bottom_width
;
240 if (wPreferences
.size_display
== WDIS_NEW
) {
241 fw
= XTextWidth(scr
->tech_draw_font
, "8888", 4);
242 fh
= scr
->tech_draw_font
->ascent
+ scr
->tech_draw_font
->descent
;
244 XSetForeground(dpy
, gc
, scr
->line_pixel
);
246 /* vertical geometry */
247 if (((direction
& LEFT
) && (x2
< scr
->scr_width
- fw
)) || (x1
< fw
)) {
256 /* top arrow & end bar */
257 segment
[0].x1
= x
- (s
+ 6);
259 segment
[0].x2
= x
- (s
- 10);
263 segment
[1].x1
= x
- (s
- 2);
264 segment
[1].y1
= ty
+ 1;
265 segment
[1].x2
= x
- (s
- 5);
266 segment
[1].y2
= ty
+ 7;
268 segment
[2].x1
= x
- (s
- 2);
269 segment
[2].y1
= ty
+ 1;
270 segment
[2].x2
= x
- (s
+ 1);
271 segment
[2].y2
= ty
+ 7;
274 segment
[3].x1
= x
- (s
- 2);
275 segment
[3].y1
= ty
+ 1;
276 segment
[3].x2
= x
- (s
- 2);
277 segment
[3].y2
= my
- fh
/ 2 - 1;
279 XDrawSegments(dpy
, root
, gc
, segment
, 4);
281 /* bottom arrow & end bar */
286 segment
[1].y1
= by
- 1;
287 segment
[1].y2
= by
- 7;
289 segment
[2].y1
= by
- 1;
290 segment
[2].y2
= by
- 7;
293 segment
[3].y1
= my
+ fh
/ 2 + 2;
294 segment
[3].y2
= by
- 1;
296 XDrawSegments(dpy
, root
, gc
, segment
, 4);
298 snprintf(num
, sizeof(num
), "%i", (by
- ty
- wwin
->normal_hints
->base_height
) /
299 wwin
->normal_hints
->height_inc
);
300 fw
= XTextWidth(scr
->tech_draw_font
, num
, strlen(num
));
302 /* Display the height. */
303 XSetFont(dpy
, gc
, scr
->tech_draw_font
->fid
);
304 XDrawString(dpy
, root
, gc
, x
- s
+ 3 - fw
/ 2, my
+ scr
->tech_draw_font
->ascent
- fh
/ 2 + 1, num
,
307 /* horizontal geometry */
315 mx
= x1
+ (x2
- x1
) / 2;
316 snprintf(num
, sizeof(num
), "%i", (x2
- x1
- wwin
->normal_hints
->base_width
) /
317 wwin
->normal_hints
->width_inc
);
318 fw
= XTextWidth(scr
->tech_draw_font
, num
, strlen(num
));
320 /* left arrow & end bar */
322 segment
[0].y1
= y
- (s
+ 6);
324 segment
[0].y2
= y
- (s
- 10);
327 segment
[1].x1
= x1
+ 7;
328 segment
[1].y1
= y
- (s
+ 1);
329 segment
[1].x2
= x1
+ 1;
330 segment
[1].y2
= y
- (s
- 2);
332 segment
[2].x1
= x1
+ 1;
333 segment
[2].y1
= y
- (s
- 2);
334 segment
[2].x2
= x1
+ 7;
335 segment
[2].y2
= y
- (s
- 5);
338 segment
[3].x1
= x1
+ 1;
339 segment
[3].y1
= y
- (s
- 2);
340 segment
[3].x2
= mx
- fw
/ 2 - 2;
341 segment
[3].y2
= y
- (s
- 2);
343 XDrawSegments(dpy
, root
, gc
, segment
, 4);
345 /* right arrow & end bar */
346 segment
[0].x1
= x2
+ 1;
347 segment
[0].x2
= x2
+ 1;
350 segment
[1].x1
= x2
- 6;
354 segment
[2].x2
= x2
- 6;
357 segment
[3].x1
= mx
+ fw
/ 2 + 2;
360 XDrawSegments(dpy
, root
, gc
, segment
, 4);
362 /* Display the width. */
363 XDrawString(dpy
, root
, gc
, mx
- fw
/ 2 + 1, y
- s
+ scr
->tech_draw_font
->ascent
- fh
/ 2 + 1, num
,
366 WSetGeometryViewShownSize(scr
->gview
, (x2
- x1
- wwin
->normal_hints
->base_width
)
367 / wwin
->normal_hints
->width_inc
,
368 (by
- ty
- wwin
->normal_hints
->base_height
)
369 / wwin
->normal_hints
->height_inc
);
373 static void cycleGeometryDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
, int dir
)
375 WScreen
*scr
= wwin
->screen_ptr
;
378 wPreferences
.size_display
++;
379 wPreferences
.size_display
%= NUM_DISPLAYS
;
381 if (wPreferences
.size_display
== WDIS_NEW
|| wPreferences
.size_display
== WDIS_NONE
) {
382 WMUnmapWidget(scr
->gview
);
384 if (wPreferences
.size_display
== WDIS_CENTER
) {
385 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
386 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
387 rect
.pos
.y
+ rect
.size
.height
/ 2);
388 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
389 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
390 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
391 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
392 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
394 WMMapWidget(scr
->gview
);
395 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, dir
);
399 static void mapGeometryDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
)
401 WScreen
*scr
= wwin
->screen_ptr
;
404 if (wPreferences
.size_display
== WDIS_NEW
|| wPreferences
.size_display
== WDIS_NONE
)
407 if (wPreferences
.size_display
== WDIS_CENTER
) {
408 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
409 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
410 rect
.pos
.y
+ rect
.size
.height
/ 2);
411 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
412 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
413 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
414 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
415 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
417 WMMapWidget(scr
->gview
);
418 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, 0);
421 static void doWindowMove(WWindow
* wwin
, WMArray
* array
, int dx
, int dy
)
424 WScreen
*scr
= wwin
->screen_ptr
;
427 if (!array
|| !WMGetArrayItemCount(array
)) {
428 wWindowMove(wwin
, wwin
->frame_x
+ dx
, wwin
->frame_y
+ dy
);
430 WMArrayIterator iter
;
432 WM_ITERATE_ARRAY(array
, tmpw
, iter
) {
433 x
= tmpw
->frame_x
+ dx
;
434 y
= tmpw
->frame_y
+ dy
;
436 #if 1 /* XXX: with xinerama patch was #if 0, check this */
437 /* don't let windows become unreachable */
439 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
440 x
= 20 - (int)tmpw
->frame
->core
->width
;
441 else if (x
+ 20 > scr
->scr_width
)
442 x
= scr
->scr_width
- 20;
444 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
445 y
= 20 - (int)tmpw
->frame
->core
->height
;
446 else if (y
+ 20 > scr
->scr_height
)
447 y
= scr
->scr_height
- 20;
449 wScreenBringInside(scr
, &x
, &y
,
450 (int)tmpw
->frame
->core
->width
, (int)tmpw
->frame
->core
->height
);
453 wWindowMove(tmpw
, x
, y
);
458 static void drawTransparentFrame(WWindow
* wwin
, int x
, int y
, int width
, int height
)
460 Window root
= wwin
->screen_ptr
->root_win
;
461 GC gc
= wwin
->screen_ptr
->frame_gc
;
465 if (HAS_BORDER_WITH_SELECT(wwin
)) {
466 x
+= FRAME_BORDER_WIDTH
;
467 y
+= FRAME_BORDER_WIDTH
;
470 if (HAS_TITLEBAR(wwin
) && !wwin
->flags
.shaded
) {
471 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + (wPreferences
.window_title_clearance
+
472 TITLEBAR_EXTEND_SPACE
) * 2;
474 if (HAS_RESIZEBAR(wwin
) && !wwin
->flags
.shaded
) {
475 /* Can't use wwin-frame->bottom_width because, in some cases
476 (e.g. interactive placement), frame does not point to anything. */
477 bottom
= RESIZEBAR_HEIGHT
;
479 XDrawRectangle(dpy
, root
, gc
, x
- 1, y
- 1, width
+ 1, height
+ 1);
482 XDrawLine(dpy
, root
, gc
, x
, y
+ h
- 1, x
+ width
, y
+ h
- 1);
485 XDrawLine(dpy
, root
, gc
, x
, y
+ height
- bottom
, x
+ width
, y
+ height
- bottom
);
489 static void drawFrames(WWindow
* wwin
, WMArray
* array
, int dx
, int dy
)
492 int scr_width
= wwin
->screen_ptr
->scr_width
;
493 int scr_height
= wwin
->screen_ptr
->scr_height
;
498 x
= wwin
->frame_x
+ dx
;
499 y
= wwin
->frame_y
+ dy
;
501 drawTransparentFrame(wwin
, x
, y
, wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
504 WMArrayIterator iter
;
506 WM_ITERATE_ARRAY(array
, tmpw
, iter
) {
507 x
= tmpw
->frame_x
+ dx
;
508 y
= tmpw
->frame_y
+ dy
;
510 /* don't let windows become unreachable */
511 #if 1 /* XXX: was 0 in XINERAMA patch, check */
512 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
513 x
= 20 - (int)tmpw
->frame
->core
->width
;
514 else if (x
+ 20 > scr_width
)
517 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
518 y
= 20 - (int)tmpw
->frame
->core
->height
;
519 else if (y
+ 20 > scr_height
)
523 wScreenBringInside(wwin
->screen_ptr
, &x
, &y
,
524 (int)tmpw
->frame
->core
->width
, (int)tmpw
->frame
->core
->height
);
527 drawTransparentFrame(tmpw
, x
, y
, tmpw
->frame
->core
->width
, tmpw
->frame
->core
->height
);
532 static void flushMotion()
537 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &ev
)) ;
540 static void crossWorkspace(WScreen
* scr
, WWindow
* wwin
, int opaque_move
, int new_workspace
, int rewind
)
542 /* do not let window be unmapped */
544 wwin
->flags
.changing_workspace
= 1;
545 wWindowChangeWorkspace(wwin
, new_workspace
);
547 /* go to new workspace */
548 wWorkspaceChange(scr
, new_workspace
);
550 wwin
->flags
.changing_workspace
= 0;
553 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, scr
->scr_width
- 20, 0);
555 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, -(scr
->scr_width
- 20), 0);
560 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
561 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
562 GrabModeAsync
, None
, wCursor
[WCUR_MOVE
], CurrentTime
);
567 /* arrays of WWindows sorted by the respective border position */
568 WWindow
**topList
; /* top border */
569 WWindow
**leftList
; /* left border */
570 WWindow
**rightList
; /* right border */
571 WWindow
**bottomList
; /* bottom border */
574 /* index of window in the above lists indicating the relative position
575 * of the window with the others */
581 int rubCount
; /* for workspace switching */
583 int winWidth
, winHeight
; /* width/height of the window */
584 int realX
, realY
; /* actual position of the window */
585 int calcX
, calcY
; /* calculated position of window */
586 int omouseX
, omouseY
; /* old mouse position */
587 int mouseX
, mouseY
; /* last known position of the pointer */
590 #define WTOP(w) (w)->frame_y
591 #define WLEFT(w) (w)->frame_x
592 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width - 1 + \
593 (HAS_BORDER_WITH_SELECT(w) ? 2*FRAME_BORDER_WIDTH : 0))
594 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height - 1 + \
595 (HAS_BORDER_WITH_SELECT(w) ? 2*FRAME_BORDER_WIDTH : 0))
597 static int compareWTop(const void *a
, const void *b
)
599 WWindow
*wwin1
= *(WWindow
**) a
;
600 WWindow
*wwin2
= *(WWindow
**) b
;
602 if (WTOP(wwin1
) > WTOP(wwin2
))
604 else if (WTOP(wwin1
) < WTOP(wwin2
))
610 static int compareWLeft(const void *a
, const void *b
)
612 WWindow
*wwin1
= *(WWindow
**) a
;
613 WWindow
*wwin2
= *(WWindow
**) b
;
615 if (WLEFT(wwin1
) > WLEFT(wwin2
))
617 else if (WLEFT(wwin1
) < WLEFT(wwin2
))
623 static int compareWRight(const void *a
, const void *b
)
625 WWindow
*wwin1
= *(WWindow
**) a
;
626 WWindow
*wwin2
= *(WWindow
**) b
;
628 if (WRIGHT(wwin1
) < WRIGHT(wwin2
))
630 else if (WRIGHT(wwin1
) > WRIGHT(wwin2
))
636 static int compareWBottom(const void *a
, const void *b
)
638 WWindow
*wwin1
= *(WWindow
**) a
;
639 WWindow
*wwin2
= *(WWindow
**) b
;
641 if (WBOTTOM(wwin1
) < WBOTTOM(wwin2
))
643 else if (WBOTTOM(wwin1
) > WBOTTOM(wwin2
))
649 static void updateResistance(WWindow
* wwin
, MoveData
* data
, int newX
, int newY
)
652 int newX2
= newX
+ data
->winWidth
;
653 int newY2
= newY
+ data
->winHeight
;
656 if (newX
< data
->realX
) {
657 if (data
->rightIndex
> 0 && newX
< WRIGHT(data
->rightList
[data
->rightIndex
- 1])) {
659 } else if (data
->leftIndex
<= data
->count
- 1 && newX2
<= WLEFT(data
->leftList
[data
->leftIndex
])) {
662 } else if (newX
> data
->realX
) {
663 if (data
->leftIndex
> 0 && newX2
> WLEFT(data
->leftList
[data
->leftIndex
- 1])) {
665 } else if (data
->rightIndex
<= data
->count
- 1
666 && newX
>= WRIGHT(data
->rightList
[data
->rightIndex
])) {
672 if (newY
< data
->realY
) {
673 if (data
->bottomIndex
> 0 && newY
< WBOTTOM(data
->bottomList
[data
->bottomIndex
- 1])) {
675 } else if (data
->topIndex
<= data
->count
- 1
676 && newY2
<= WTOP(data
->topList
[data
->topIndex
])) {
679 } else if (newY
> data
->realY
) {
680 if (data
->topIndex
> 0 && newY2
> WTOP(data
->topList
[data
->topIndex
- 1])) {
682 } else if (data
->bottomIndex
<= data
->count
- 1
683 && newY
>= WBOTTOM(data
->bottomList
[data
->bottomIndex
])) {
692 /* TODO: optimize this */
693 if (data
->realY
< WBOTTOM(data
->bottomList
[0])) {
694 data
->bottomIndex
= 0;
696 if (data
->realX
< WRIGHT(data
->rightList
[0])) {
697 data
->rightIndex
= 0;
699 if ((data
->realX
+ data
->winWidth
) > WLEFT(data
->leftList
[0])) {
702 if ((data
->realY
+ data
->winHeight
) > WTOP(data
->topList
[0])) {
705 for (i
= 0; i
< data
->count
; i
++) {
706 if (data
->realY
> WBOTTOM(data
->bottomList
[i
])) {
707 data
->bottomIndex
= i
+ 1;
709 if (data
->realX
> WRIGHT(data
->rightList
[i
])) {
710 data
->rightIndex
= i
+ 1;
712 if ((data
->realX
+ data
->winWidth
) < WLEFT(data
->leftList
[i
])) {
713 data
->leftIndex
= i
+ 1;
715 if ((data
->realY
+ data
->winHeight
) < WTOP(data
->topList
[i
])) {
716 data
->topIndex
= i
+ 1;
721 static void freeMoveData(MoveData
* data
)
724 wfree(data
->topList
);
726 wfree(data
->leftList
);
728 wfree(data
->rightList
);
729 if (data
->bottomList
)
730 wfree(data
->bottomList
);
733 static void updateMoveData(WWindow
* wwin
, MoveData
* data
)
735 WScreen
*scr
= wwin
->screen_ptr
;
740 tmp
= scr
->focused_window
;
742 if (tmp
!= wwin
&& scr
->current_workspace
== tmp
->frame
->workspace
743 && !tmp
->flags
.miniaturized
744 && !tmp
->flags
.hidden
&& !tmp
->flags
.obscured
&& !WFLAGP(tmp
, sunken
)) {
745 data
->topList
[data
->count
] = tmp
;
746 data
->leftList
[data
->count
] = tmp
;
747 data
->rightList
[data
->count
] = tmp
;
748 data
->bottomList
[data
->count
] = tmp
;
754 if (data
->count
== 0) {
757 data
->rightIndex
= 0;
758 data
->bottomIndex
= 0;
762 /* order from closest to the border of the screen to farthest */
764 qsort(data
->topList
, data
->count
, sizeof(WWindow
**), compareWTop
);
765 qsort(data
->leftList
, data
->count
, sizeof(WWindow
**), compareWLeft
);
766 qsort(data
->rightList
, data
->count
, sizeof(WWindow
**), compareWRight
);
767 qsort(data
->bottomList
, data
->count
, sizeof(WWindow
**), compareWBottom
);
769 /* figure the position of the window relative to the others */
772 data
->leftIndex
= -1;
773 data
->rightIndex
= -1;
774 data
->bottomIndex
= -1;
776 if (WTOP(wwin
) < WBOTTOM(data
->bottomList
[0])) {
777 data
->bottomIndex
= 0;
779 if (WLEFT(wwin
) < WRIGHT(data
->rightList
[0])) {
780 data
->rightIndex
= 0;
782 if (WRIGHT(wwin
) > WLEFT(data
->leftList
[0])) {
785 if (WBOTTOM(wwin
) > WTOP(data
->topList
[0])) {
788 for (i
= 0; i
< data
->count
; i
++) {
789 if (WTOP(wwin
) >= WBOTTOM(data
->bottomList
[i
])) {
790 data
->bottomIndex
= i
+ 1;
792 if (WLEFT(wwin
) >= WRIGHT(data
->rightList
[i
])) {
793 data
->rightIndex
= i
+ 1;
795 if (WRIGHT(wwin
) <= WLEFT(data
->leftList
[i
])) {
796 data
->leftIndex
= i
+ 1;
798 if (WBOTTOM(wwin
) <= WTOP(data
->topList
[i
])) {
799 data
->topIndex
= i
+ 1;
804 static void initMoveData(WWindow
* wwin
, MoveData
* data
)
809 memset(data
, 0, sizeof(MoveData
));
811 for (i
= 0, tmp
= wwin
->screen_ptr
->focused_window
; tmp
!= NULL
; tmp
= tmp
->prev
, i
++) ;
814 data
->topList
= wmalloc(sizeof(WWindow
*) * i
);
815 data
->leftList
= wmalloc(sizeof(WWindow
*) * i
);
816 data
->rightList
= wmalloc(sizeof(WWindow
*) * i
);
817 data
->bottomList
= wmalloc(sizeof(WWindow
*) * i
);
819 updateMoveData(wwin
, data
);
822 data
->realX
= wwin
->frame_x
;
823 data
->realY
= wwin
->frame_y
;
824 data
->calcX
= wwin
->frame_x
;
825 data
->calcY
= wwin
->frame_y
;
827 data
->winWidth
= wwin
->frame
->core
->width
+ (HAS_BORDER_WITH_SELECT(wwin
) ? 2 * FRAME_BORDER_WIDTH
: 0);
828 data
->winHeight
= wwin
->frame
->core
->height
+ (HAS_BORDER_WITH_SELECT(wwin
) ? 2 * FRAME_BORDER_WIDTH
: 0);
831 static Bool
checkWorkspaceChange(WWindow
* wwin
, MoveData
* data
, Bool opaqueMove
)
833 WScreen
*scr
= wwin
->screen_ptr
;
834 Bool changed
= False
;
836 if (data
->mouseX
<= 1) {
837 if (scr
->current_workspace
> 0) {
839 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
- 1, True
);
843 } else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
) {
845 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->workspace_count
- 1, True
);
849 } else if (data
->mouseX
>= scr
->scr_width
- 2) {
851 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
853 if (wPreferences
.ws_cycle
|| scr
->workspace_count
== MAX_WORKSPACES
) {
855 crossWorkspace(scr
, wwin
, opaqueMove
, 0, False
);
859 /* if user insists on trying to go to next workspace even when
860 * it's already the last, create a new one */
861 else if (data
->omouseX
== data
->mouseX
&& wPreferences
.ws_advance
) {
863 /* detect user "rubbing" the window against the edge */
864 if (data
->rubCount
> 0 && data
->omouseY
- data
->mouseY
> MOVE_THRESHOLD
) {
866 data
->rubCount
= -(data
->rubCount
+ 1);
868 } else if (data
->rubCount
<= 0 && data
->mouseY
- data
->omouseY
> MOVE_THRESHOLD
) {
870 data
->rubCount
= -data
->rubCount
+ 1;
873 /* create a new workspace */
874 if (abs(data
->rubCount
) > 2) {
875 /* go to next workspace */
878 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
+ 1, False
);
882 } else if (scr
->current_workspace
< scr
->workspace_count
) {
884 /* go to next workspace */
885 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
+ 1, False
);
897 updateWindowPosition(WWindow
* wwin
, MoveData
* data
, Bool doResistance
,
898 Bool opaqueMove
, int newMouseX
, int newMouseY
)
900 WScreen
*scr
= wwin
->screen_ptr
;
901 int dx
, dy
; /* how much mouse moved */
902 int winL
, winR
, winT
, winB
; /* requested new window position */
903 int newX
, newY
; /* actual new window position */
904 Bool hresist
, vresist
;
910 /* check the direction of the movement */
911 dx
= newMouseX
- data
->mouseX
;
912 dy
= newMouseY
- data
->mouseY
;
914 data
->omouseX
= data
->mouseX
;
915 data
->omouseY
= data
->mouseY
;
916 data
->mouseX
= newMouseX
;
917 data
->mouseY
= newMouseY
;
919 winL
= data
->calcX
+ dx
;
920 winR
= data
->calcX
+ data
->winWidth
+ dx
;
921 winT
= data
->calcY
+ dy
;
922 winB
= data
->calcY
+ data
->winHeight
+ dy
;
934 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
935 attract
= wPreferences
.attract
;
936 /* horizontal movement: check horizontal edge resistances */
940 /* window is the leftmost window: check against screen edge */
942 /* Add inter head resistance 1/2 (if needed) */
943 head
= wGetHeadForPointerLocation(scr
);
944 rect
= wGetRectForHead(scr
, head
);
946 l_edge
= WMAX(scr
->totalUsableArea
[head
].x1
, rect
.pos
.x
);
947 edge_l
= l_edge
- resist
;
948 edge_r
= WMIN(scr
->totalUsableArea
[head
].x2
, rect
.pos
.x
+ rect
.size
.width
);
949 r_edge
= edge_r
+ resist
;
952 if ((data
->rightIndex
>= 0) && (data
->rightIndex
<= data
->count
)) {
955 for (i
= data
->rightIndex
- 1; i
>= 0; i
--) {
956 looprw
= data
->rightList
[i
];
957 if (!(data
->realY
> WBOTTOM(looprw
)
958 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
959 if (attract
|| ((data
->realX
< (WRIGHT(looprw
) + 2)) && dx
< 0)) {
960 l_edge
= WRIGHT(looprw
) + 1;
961 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
968 for (i
= data
->rightIndex
; i
< data
->count
; i
++) {
969 looprw
= data
->rightList
[i
];
970 if (!(data
->realY
> WBOTTOM(looprw
)
971 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
972 r_edge
= WRIGHT(looprw
) + 1;
973 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
980 if ((data
->leftIndex
>= 0) && (data
->leftIndex
<= data
->count
)) {
983 for (i
= data
->leftIndex
- 1; i
>= 0; i
--) {
984 looprw
= data
->leftList
[i
];
985 if (!(data
->realY
> WBOTTOM(looprw
)
986 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
988 || (((data
->realX
+ data
->winWidth
) > (WLEFT(looprw
) - 1))
990 edge_r
= WLEFT(looprw
);
991 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
998 for (i
= data
->leftIndex
; i
< data
->count
; i
++) {
999 looprw
= data
->leftList
[i
];
1000 if (!(data
->realY
> WBOTTOM(looprw
)
1001 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1002 edge_l
= WLEFT(looprw
);
1003 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1010 printf("%d %d\n",winL,winR);
1011 printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);
1014 if ((winL
- l_edge
) < (r_edge
- winL
)) {
1016 if ((attract
&& winL
<= l_edge
+ resist
&& winL
>= l_edge
- resist
)
1017 || (dx
< 0 && winL
<= l_edge
&& winL
>= l_edge
- resist
)) {
1023 if (resist
> 0 && attract
&& winL
>= r_edge
- resist
&& winL
<= r_edge
+ resist
) {
1029 if ((winR
- edge_l
) < (edge_r
- winR
)) {
1030 if (resist
> 0 && attract
&& winR
<= edge_l
+ resist
&& winR
>= edge_l
- resist
) {
1031 newX
= edge_l
- data
->winWidth
;
1036 if ((attract
&& winR
>= edge_r
- resist
&& winR
<= edge_r
+ resist
)
1037 || (dx
> 0 && winR
>= edge_r
&& winR
<= edge_r
+ resist
)) {
1038 newX
= edge_r
- data
->winWidth
;
1045 /* Add inter head resistance 2/2 (if needed) */
1046 t_edge
= WMAX(scr
->totalUsableArea
[head
].y1
, rect
.pos
.y
);
1047 edge_t
= t_edge
- resist
;
1048 edge_b
= WMIN(scr
->totalUsableArea
[head
].y2
, rect
.pos
.y
+ rect
.size
.height
);
1049 b_edge
= edge_b
+ resist
;
1051 if ((data
->bottomIndex
>= 0) && (data
->bottomIndex
<= data
->count
)) {
1054 for (i
= data
->bottomIndex
- 1; i
>= 0; i
--) {
1055 looprw
= data
->bottomList
[i
];
1056 if (!(data
->realX
> WRIGHT(looprw
)
1057 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1058 if (attract
|| ((data
->realY
< (WBOTTOM(looprw
) + 2)) && dy
< 0)) {
1059 t_edge
= WBOTTOM(looprw
) + 1;
1060 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1067 for (i
= data
->bottomIndex
; i
< data
->count
; i
++) {
1068 looprw
= data
->bottomList
[i
];
1069 if (!(data
->realX
> WRIGHT(looprw
)
1070 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1071 b_edge
= WBOTTOM(looprw
) + 1;
1072 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1079 if ((data
->topIndex
>= 0) && (data
->topIndex
<= data
->count
)) {
1082 for (i
= data
->topIndex
- 1; i
>= 0; i
--) {
1083 looprw
= data
->topList
[i
];
1084 if (!(data
->realX
> WRIGHT(looprw
)
1085 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1087 || (((data
->realY
+ data
->winHeight
) > (WTOP(looprw
) - 1))
1089 edge_b
= WTOP(looprw
);
1090 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1097 for (i
= data
->topIndex
; i
< data
->count
; i
++) {
1098 looprw
= data
->topList
[i
];
1099 if (!(data
->realX
> WRIGHT(looprw
)
1100 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1101 edge_t
= WTOP(looprw
);
1102 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1108 if ((winT
- t_edge
) < (b_edge
- winT
)) {
1110 if ((attract
&& winT
<= t_edge
+ resist
&& winT
>= t_edge
- resist
)
1111 || (dy
< 0 && winT
<= t_edge
&& winT
>= t_edge
- resist
)) {
1117 if (resist
> 0 && attract
&& winT
>= b_edge
- resist
&& winT
<= b_edge
+ resist
) {
1123 if ((winB
- edge_t
) < (edge_b
- winB
)) {
1124 if (resist
> 0 && attract
&& winB
<= edge_t
+ resist
&& winB
>= edge_t
- resist
) {
1125 newY
= edge_t
- data
->winHeight
;
1130 if ((attract
&& winB
>= edge_b
- resist
&& winB
<= edge_b
+ resist
)
1131 || (dy
> 0 && winB
>= edge_b
&& winB
<= edge_b
+ resist
)) {
1132 newY
= edge_b
- data
->winHeight
;
1142 /* update window position */
1146 if (((dx
> 0 && data
->calcX
- data
->realX
> 0)
1147 || (dx
< 0 && data
->calcX
- data
->realX
< 0)) && !hresist
)
1150 if (((dy
> 0 && data
->calcY
- data
->realY
> 0)
1151 || (dy
< 0 && data
->calcY
- data
->realY
< 0)) && !vresist
)
1154 if (data
->realX
!= newX
|| data
->realY
!= newY
) {
1156 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1157 showPosition(wwin
, data
->realX
, data
->realY
);
1160 doWindowMove(wwin
, scr
->selected_windows
, newX
- wwin
->frame_x
, newY
- wwin
->frame_y
);
1163 drawFrames(wwin
, scr
->selected_windows
,
1164 data
->realX
- wwin
->frame_x
, data
->realY
- wwin
->frame_y
);
1167 if (!scr
->selected_windows
&& wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
1169 moveGeometryDisplayCentered(scr
, newX
+ data
->winWidth
/ 2, newY
+ data
->winHeight
/ 2);
1174 drawFrames(wwin
, scr
->selected_windows
, newX
- wwin
->frame_x
, newY
- wwin
->frame_y
);
1177 if (!scr
->selected_windows
) {
1178 showPosition(wwin
, newX
, newY
);
1182 /* recalc relative window position */
1183 if (doResistance
&& (data
->realX
!= newX
|| data
->realY
!= newY
)) {
1184 updateResistance(wwin
, data
, newX
, newY
);
1191 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1193 #define MOVABLE_BIT 0x01
1194 #define RESIZABLE_BIT 0x02
1196 int wKeyboardMoveResizeWindow(WWindow
* wwin
)
1198 WScreen
*scr
= wwin
->screen_ptr
;
1199 Window root
= scr
->root_win
;
1201 int w
= wwin
->frame
->core
->width
;
1202 int h
= wwin
->frame
->core
->height
;
1203 int scr_width
= wwin
->screen_ptr
->scr_width
;
1204 int scr_height
= wwin
->screen_ptr
->scr_height
;
1205 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1206 int src_x
= wwin
->frame_x
;
1207 int src_y
= wwin
->frame_y
;
1208 int done
, off_x
, off_y
, ww
, wh
;
1210 int opaqueMoveResize
= wPreferences
.opaque_move_resize_keyboard
;
1212 KeyCode shiftl
, shiftr
, ctrlmode
;
1213 KeySym keysym
= NoSymbol
;
1215 int modes
= ((IS_MOVABLE(wwin
) ? MOVABLE_BIT
: 0) | (IS_RESIZABLE(wwin
) ? RESIZABLE_BIT
: 0));
1216 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1217 ? wGetHeadForWindow(wwin
)
1218 : scr
->xine_info
.primary_head
);
1220 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1221 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1222 ctrlmode
= done
= off_x
= off_y
= 0;
1224 if (modes
== RESIZABLE_BIT
) {
1230 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1232 if (!wwin
->flags
.selected
) {
1233 wUnselectWindows(scr
);
1236 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1237 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
1238 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
);
1242 if (!opaqueMoveResize
) {
1243 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1244 if (scr
->selected_windows
)
1245 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1247 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1249 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1252 if ((wwin
->flags
.shaded
|| scr
->selected_windows
) && (!scr
->selected_windows
)) {
1253 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1264 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1265 | ButtonPressMask
| ExposureMask
, &event
);
1266 if (event
.type
== Expose
) {
1267 WMHandleEvent(&event
);
1269 } while (event
.type
== Expose
);
1271 if (!opaqueMoveResize
) {
1272 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1273 if (scr
->selected_windows
)
1274 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1276 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1277 /*** I HATE EDGE RESISTANCE - ]d ***/
1279 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1284 showGeometry(wwin
, src_x
+ off_x
, src_y
+ off_y
, src_x
+ off_x
+ ww
, src_y
+ off_y
+ wh
,
1290 switch (event
.type
) {
1293 if (event
.xkey
.time
- lastTime
> 50) {
1294 kspeed
/= (1 + (event
.xkey
.time
- lastTime
) / 100);
1302 lastTime
= event
.xkey
.time
;
1303 if (modes
== (MOVABLE_BIT
| RESIZABLE_BIT
)) {
1304 if ((event
.xkey
.state
& ControlMask
) && !wwin
->flags
.shaded
) {
1306 wUnselectWindows(scr
);
1311 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
) {
1313 cycleGeometryDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
, 0);
1315 cyclePositionDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1318 keysym
= XLookupKeysym(&event
.xkey
, 0);
1375 if (moment
!= RIGHT
)
1387 wWindowConstrainSize(wwin
, (unsigned int *)&ww
, (unsigned int *)&wh
);
1390 if (wPreferences
.ws_cycle
) {
1391 if (src_x
+ off_x
+ ww
< 20) {
1392 if (!scr
->current_workspace
) {
1393 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
1395 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
1397 } else if (src_x
+ off_x
+ 20 > scr_width
) {
1398 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
1399 wWorkspaceChange(scr
, 0);
1401 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
1405 if (src_x
+ off_x
+ ww
< 20)
1406 off_x
= 20 - ww
- src_x
;
1407 else if (src_x
+ off_x
+ 20 > scr_width
)
1408 off_x
= scr_width
- 20 - src_x
;
1411 if (src_y
+ off_y
+ wh
< 20) {
1412 off_y
= 20 - wh
- src_y
;
1413 } else if (src_y
+ off_y
+ 20 > scr_height
) {
1414 off_y
= scr_height
- 20 - src_y
;
1423 WMHandleEvent(&event
);
1424 while (XCheckTypedEvent(dpy
, Expose
, &event
)) {
1425 WMHandleEvent(&event
);
1430 WMHandleEvent(&event
);
1437 if (wwin
->flags
.shaded
&& !scr
->selected_windows
) {
1438 moveGeometryDisplayCentered(scr
, src_x
+ off_x
+ w
/ 2, src_y
+ off_y
+ h
/ 2);
1441 WMUnmapWidget(scr
->gview
);
1442 mapGeometryDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1443 } else if (!scr
->selected_windows
) {
1444 WMUnmapWidget(scr
->gview
);
1445 mapPositionDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1449 if (!opaqueMoveResize
) {
1450 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1451 if (scr
->selected_windows
)
1452 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1454 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1456 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1461 showGeometry(wwin
, src_x
+ off_x
, src_y
+ off_y
, src_x
+ off_x
+ ww
, src_y
+ off_y
+ wh
,
1463 } else if (!scr
->selected_windows
)
1464 showPosition(wwin
, src_x
+ off_x
, src_y
+ off_y
);
1466 if (opaqueMoveResize
) {
1468 wwin
->flags
.user_changed_width
= 1;
1469 wWindowConfigure(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
- vert_border
);
1473 scr
->keymove_tick
= 0;
1475 WMDeleteTimerWithClientData(&looper);
1477 if (!opaqueMoveResize
) {/*ctrlmode=> resize */
1478 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1479 if (scr
->selected_windows
)
1480 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1482 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1484 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1489 showGeometry(wwin
, src_x
+ off_x
, src_y
+ off_y
, src_x
+ off_x
+ ww
,
1490 src_y
+ off_y
+ wh
, 0);
1491 WMUnmapWidget(scr
->gview
);
1493 WMUnmapWidget(scr
->gview
);
1495 XUngrabKeyboard(dpy
, CurrentTime
);
1496 XUngrabPointer(dpy
, CurrentTime
);
1500 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1501 if (!scr
->selected_windows
) {
1502 wWindowMove(wwin
, src_x
+ off_x
, src_y
+ off_y
);
1503 wWindowSynthConfigureNotify(wwin
);
1505 WMArrayIterator iter
;
1508 doWindowMove(wwin
, scr
->selected_windows
, off_x
, off_y
);
1510 WM_ITERATE_ARRAY(scr
->selected_windows
, foo
, iter
) {
1511 wWindowSynthConfigureNotify(foo
);
1515 if (wwin
->client
.width
!= ww
) {
1516 wwin
->flags
.user_changed_width
= 1;
1517 wwin
->flags
.maximized
&= ~(MAX_HORIZONTAL
| MAX_MAXIMUS
);
1520 if (wwin
->client
.height
!= wh
- vert_border
) {
1521 wwin
->flags
.user_changed_height
= 1;
1522 wwin
->flags
.maximized
&= ~(MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
1525 wWindowConfigure(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
- vert_border
);
1526 wWindowSynthConfigureNotify(wwin
);
1528 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1529 wSetFocusTo(scr
, wwin
);
1532 if (wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 &&
1533 head
!= wGetHeadForWindow(wwin
)) {
1534 wArrangeIcons(scr
, True
);
1543 *----------------------------------------------------------------------
1544 * wMouseMoveWindow--
1545 * Move the named window and the other selected ones (if any),
1546 * interactively. Also shows the position of the window, if only one
1547 * window is being moved.
1548 * If the window is not on the selected window list, the selected
1549 * windows are deselected.
1550 * If shift is pressed during the operation, the position display
1551 * is changed to another type.
1554 * True if the window was moved, False otherwise.
1557 * The window(s) position is changed, and the client(s) are
1558 * notified about that.
1559 * The position display configuration may be changed.
1560 *----------------------------------------------------------------------
1562 int wMouseMoveWindow(WWindow
* wwin
, XEvent
* ev
)
1564 WScreen
*scr
= wwin
->screen_ptr
;
1566 Window root
= scr
->root_win
;
1567 KeyCode shiftl
, shiftr
;
1571 /* This needs not to change while moving, else bad things can happen */
1572 int opaqueMove
= wPreferences
.opaque_move
;
1574 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1575 ? wGetHeadForWindow(wwin
)
1576 : scr
->xine_info
.primary_head
);
1578 if (!IS_MOVABLE(wwin
))
1581 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1582 XSetWindowAttributes attr
;
1584 attr
.save_under
= True
;
1585 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
, CWSaveUnder
, &attr
);
1588 initMoveData(wwin
, &moveData
);
1590 moveData
.mouseX
= ev
->xmotion
.x_root
;
1591 moveData
.mouseY
= ev
->xmotion
.y_root
;
1593 if (!wwin
->flags
.selected
) {
1594 /* this window is not selected, unselect others and move only wwin */
1595 wUnselectWindows(scr
);
1597 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1598 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1604 /* XWarpPointer() doesn't seem to generate Motion events, so
1605 * we've got to simulate them */
1606 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1607 &event
.xmotion
.y_root
, &junk
, &junk
, (unsigned *)&junk
);
1609 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1610 | PointerMotionHintMask
1611 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
, &event
);
1613 if (event
.type
== MotionNotify
) {
1614 /* compress MotionNotify events */
1615 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1616 if (!checkMouseSamplingRate(&event
))
1620 switch (event
.type
) {
1622 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1623 && started
&& !scr
->selected_windows
) {
1626 drawFrames(wwin
, scr
->selected_windows
,
1627 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1630 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1631 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1634 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1635 moveData
.winWidth
, moveData
.winHeight
);
1637 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1639 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1643 drawFrames(wwin
, scr
->selected_windows
,
1644 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1647 WMHandleEvent(&event); this causes problems needs fixing */
1653 updateWindowPosition(wwin
, &moveData
,
1654 scr
->selected_windows
== NULL
1655 && wPreferences
.edge_resistance
> 0,
1656 opaqueMove
, event
.xmotion
.x_root
, event
.xmotion
.y_root
);
1658 if (!warped
&& !wPreferences
.no_autowrap
) {
1659 int oldWorkspace
= scr
->current_workspace
;
1661 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1662 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1666 drawFrames(wwin
, scr
->selected_windows
,
1667 moveData
.realX
- wwin
->frame_x
,
1668 moveData
.realY
- wwin
->frame_y
);
1670 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1671 if (scr
->current_workspace
!= oldWorkspace
1672 && wPreferences
.edge_resistance
> 0
1673 && scr
->selected_windows
== NULL
)
1674 updateMoveData(wwin
, &moveData
);
1678 drawFrames(wwin
, scr
->selected_windows
,
1679 moveData
.realX
- wwin
->frame_x
,
1680 moveData
.realY
- wwin
->frame_y
);
1682 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1684 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1690 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1691 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1693 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1694 | ButtonReleaseMask
| ButtonPressMask
,
1695 wCursor
[WCUR_MOVE
], CurrentTime
);
1697 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1699 if (!scr
->selected_windows
)
1700 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1701 moveData
.winWidth
, moveData
.winHeight
);
1703 if (started
&& !opaqueMove
)
1704 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1706 if (!opaqueMove
|| (wPreferences
.move_display
== WDIS_NEW
1707 && !scr
->selected_windows
)) {
1709 if (wPreferences
.move_display
== WDIS_NEW
)
1710 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1719 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1725 drawFrames(wwin
, scr
->selected_windows
,
1726 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1728 doWindowMove(wwin
, scr
->selected_windows
,
1729 moveData
.realX
- wwin
->frame_x
,
1730 moveData
.realY
- wwin
->frame_y
);
1732 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1733 wWindowSynthConfigureNotify(wwin
);
1735 XUngrabKeyboard(dpy
, CurrentTime
);
1738 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1739 wSetFocusTo(scr
, wwin
);
1741 if (wPreferences
.move_display
== WDIS_NEW
)
1742 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1744 /* discard all enter/leave events that happened until
1745 * the time the button was released */
1746 while (XCheckTypedEvent(dpy
, EnterNotify
, &e
)) {
1747 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1748 XPutBackEvent(dpy
, &e
);
1752 while (XCheckTypedEvent(dpy
, LeaveNotify
, &e
)) {
1753 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1754 XPutBackEvent(dpy
, &e
);
1759 if (!scr
->selected_windows
) {
1760 /* get rid of the geometry window */
1761 WMUnmapWidget(scr
->gview
);
1768 if (started
&& !opaqueMove
) {
1769 drawFrames(wwin
, scr
->selected_windows
,
1770 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1772 WMHandleEvent(&event
);
1775 drawFrames(wwin
, scr
->selected_windows
,
1776 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1778 WMHandleEvent(&event
);
1784 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1785 XSetWindowAttributes attr
;
1787 attr
.save_under
= False
;
1788 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
, CWSaveUnder
, &attr
);
1792 freeMoveData(&moveData
);
1794 if (started
&& wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 &&
1795 head
!= wGetHeadForWindow(wwin
)) {
1796 wArrangeIcons(scr
, True
);
1802 #define HCONSTRAIN 2
1804 static int getResizeDirection(WWindow
* wwin
, int x
, int y
, int dx
, int dy
, int flags
)
1806 int w
= wwin
->frame
->core
->width
- 1;
1807 int cw
= wwin
->frame
->resizebar_corner_width
;
1810 /* if not resizing through the resizebar */
1811 if (!(flags
& RESIZEBAR
)) {
1812 int xdir
= (abs(x
) < (wwin
->client
.width
/ 2)) ? LEFT
: RIGHT
;
1813 int ydir
= (abs(y
) < (wwin
->client
.height
/ 2)) ? UP
: DOWN
;
1814 if (abs(dx
) < 2 || abs(dy
) < 2) {
1815 if (abs(dy
) > abs(dx
))
1820 return (xdir
| ydir
);
1823 /* window is too narrow. allow diagonal resize */
1827 if (flags
& HCONSTRAIN
)
1832 return (LEFT
| ydir
);
1834 return (RIGHT
| ydir
);
1836 /* vertical resize */
1837 if ((x
> cw
) && (x
< w
- cw
))
1845 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1851 void wMouseResizeWindow(WWindow
* wwin
, XEvent
* ev
)
1854 WScreen
*scr
= wwin
->screen_ptr
;
1855 Window root
= scr
->root_win
;
1856 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1857 int fw
= wwin
->frame
->core
->width
;
1858 int fh
= wwin
->frame
->core
->height
;
1859 int fx
= wwin
->frame_x
;
1860 int fy
= wwin
->frame_y
;
1861 int is_resizebar
= (wwin
->frame
->resizebar
&& ev
->xany
.window
== wwin
->frame
->resizebar
->window
);
1865 int rw
= fw
, rh
= fh
;
1866 int rx1
, ry1
, rx2
, ry2
;
1868 KeyCode shiftl
, shiftr
;
1873 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1874 ? wGetHeadForWindow(wwin
)
1875 : scr
->xine_info
.primary_head
);
1876 int opaqueResize
= wPreferences
.opaque_resize
;
1878 if (!IS_RESIZABLE(wwin
))
1881 if (wwin
->flags
.shaded
) {
1882 wwarning("internal error: tryein");
1885 orig_x
= ev
->xbutton
.x_root
;
1886 orig_y
= ev
->xbutton
.y_root
;
1889 wUnselectWindows(scr
);
1894 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1895 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1898 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1899 | ButtonReleaseMask
| PointerMotionHintMask
| ButtonPressMask
| ExposureMask
, &event
);
1900 if (!checkMouseSamplingRate(&event
))
1903 switch (event
.type
) {
1905 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1906 if (!opaqueResize
) {
1907 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1909 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1910 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
1911 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1914 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1919 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1930 dw
= orig_x
- event
.xmotion
.x_root
;
1931 else if (res
& RIGHT
)
1932 dw
= event
.xmotion
.x_root
- orig_x
;
1934 dh
= orig_y
- event
.xmotion
.y_root
;
1935 else if (res
& DOWN
)
1936 dh
= event
.xmotion
.y_root
- orig_y
;
1938 orig_x
= event
.xmotion
.x_root
;
1939 orig_y
= event
.xmotion
.y_root
;
1944 fh
= rh
- vert_border
;
1945 wWindowConstrainSize(wwin
, (unsigned int *)&fw
, (unsigned int *)&fh
);
1949 else if (res
& RIGHT
)
1953 else if (res
& DOWN
)
1955 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1956 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1961 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
1962 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
1964 /* check if resizing through resizebar */
1970 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
1971 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
1972 flags
|= HCONSTRAIN
;
1974 res
= getResizeDirection(wwin
, tx
, ty
,
1975 orig_x
- event
.xmotion
.x_root
,
1976 orig_y
- event
.xmotion
.y_root
, flags
);
1978 if (res
== (UP
| LEFT
))
1979 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1980 | ButtonReleaseMask
| ButtonPressMask
,
1981 wCursor
[WCUR_TOPLEFTRESIZE
], CurrentTime
);
1982 else if (res
== (UP
| RIGHT
))
1983 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1984 | ButtonReleaseMask
| ButtonPressMask
,
1985 wCursor
[WCUR_TOPRIGHTRESIZE
], CurrentTime
);
1986 else if (res
== (DOWN
| LEFT
))
1987 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1988 | ButtonReleaseMask
| ButtonPressMask
,
1989 wCursor
[WCUR_BOTTOMLEFTRESIZE
], CurrentTime
);
1990 else if (res
== (DOWN
| RIGHT
))
1991 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1992 | ButtonReleaseMask
| ButtonPressMask
,
1993 wCursor
[WCUR_BOTTOMRIGHTRESIZE
], CurrentTime
);
1994 else if (res
== DOWN
|| res
== UP
)
1995 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1996 | ButtonReleaseMask
| ButtonPressMask
,
1997 wCursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
1998 else if (res
& (DOWN
| UP
))
1999 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2000 | ButtonReleaseMask
| ButtonPressMask
,
2001 wCursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2002 else if (res
& (LEFT
| RIGHT
))
2003 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2004 | ButtonReleaseMask
| ButtonPressMask
,
2005 wCursor
[WCUR_HORIZONRESIZE
], CurrentTime
);
2007 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2011 /* Draw the resize frame for the first time. */
2012 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
2013 if (!opaqueResize
) {
2014 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2016 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2021 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
2022 if (!opaqueResize
) {
2023 drawTransparentFrame(wwin
, orig_fx
, orig_fy
, orig_fw
, orig_fh
);
2025 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
2026 if (!opaqueResize
) {
2027 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2030 if (!opaqueResize
) {
2031 drawTransparentFrame(wwin
, orig_fx
, orig_fy
, orig_fw
, orig_fh
);
2032 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2035 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
2036 if (wPreferences
.size_display
== WDIS_NEW
) {
2037 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
2038 orig_fy
+ orig_fh
, res
);
2040 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2044 wwin
->flags
.user_changed_width
= 1;
2045 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
2046 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
2047 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2056 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2060 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2062 if (!opaqueResize
) {
2063 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2065 XUngrabKeyboard(dpy
, CurrentTime
);
2066 WMUnmapWidget(scr
->gview
);
2069 if (wwin
->client
.width
!= fw
) {
2070 wwin
->flags
.user_changed_width
= 1;
2071 wwin
->flags
.maximized
&= ~(MAX_HORIZONTAL
| MAX_MAXIMUS
);
2074 if (wwin
->client
.height
!= fh
- vert_border
) {
2075 wwin
->flags
.user_changed_height
= 1;
2076 wwin
->flags
.maximized
&= ~(MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
2079 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
2080 wWindowSynthConfigureNotify(wwin
);
2085 WMHandleEvent(&event
);
2089 if (wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 && head
!= wGetHeadForWindow(wwin
)) {
2090 wArrangeIcons(scr
, True
);
2103 void wUnselectWindows(WScreen
* scr
)
2107 if (!scr
->selected_windows
)
2110 while (WMGetArrayItemCount(scr
->selected_windows
)) {
2111 wwin
= WMGetFromArray(scr
->selected_windows
, 0);
2112 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
2113 wIconSelect(wwin
->icon
);
2115 wSelectWindow(wwin
, False
);
2117 WMFreeArray(scr
->selected_windows
);
2118 scr
->selected_windows
= NULL
;
2121 static void selectWindowsInside(WScreen
* scr
, int x1
, int y1
, int x2
, int y2
)
2125 /* select the windows and put them in the selected window list */
2126 tmpw
= scr
->focused_window
;
2127 while (tmpw
!= NULL
) {
2128 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
2129 if ((tmpw
->frame
->workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(tmpw
))
2130 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
2131 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
2132 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
2133 wSelectWindow(tmpw
, True
);
2140 void wSelectWindows(WScreen
* scr
, XEvent
* ev
)
2143 Window root
= scr
->root_win
;
2144 GC gc
= scr
->frame_gc
;
2145 int xp
= ev
->xbutton
.x_root
;
2146 int yp
= ev
->xbutton
.y_root
;
2150 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
2151 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
2152 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2157 wUnselectWindows(scr
);
2159 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
2161 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
| ButtonPressMask
, &event
);
2163 switch (event
.type
) {
2165 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2166 x
= event
.xmotion
.x_root
;
2173 y
= event
.xmotion
.y_root
;
2180 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2187 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2190 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2192 XUngrabPointer(dpy
, CurrentTime
);
2193 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
2197 WMHandleEvent(&event
);
2203 void InteractivePlaceWindow(WWindow
* wwin
, int *x_ret
, int *y_ret
, unsigned width
, unsigned height
)
2205 WScreen
*scr
= wwin
->screen_ptr
;
2206 Window root
= scr
->root_win
;
2209 KeyCode shiftl
, shiftr
;
2213 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2214 GrabModeAsync
, GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2219 if (HAS_TITLEBAR(wwin
)) {
2220 h
= WMFontHeight(scr
->title_font
) + (wPreferences
.window_title_clearance
+
2221 TITLEBAR_EXTEND_SPACE
) * 2;
2224 if (HAS_RESIZEBAR(wwin
)) {
2225 height
+= RESIZEBAR_HEIGHT
;
2227 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2228 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
, (unsigned *)&junk
);
2229 mapPositionDisplay(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2231 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2233 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2234 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2236 WMMaskEvent(dpy
, PointerMotionMask
| ButtonPressMask
| ExposureMask
| KeyPressMask
, &event
);
2238 if (!checkMouseSamplingRate(&event
))
2241 switch (event
.type
) {
2243 if ((event
.xkey
.keycode
== shiftl
)
2244 || (event
.xkey
.keycode
== shiftr
)) {
2245 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2246 cyclePositionDisplay(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2247 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2252 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2254 x
= event
.xmotion
.x_root
;
2255 y
= event
.xmotion
.y_root
;
2257 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2258 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2260 showPosition(wwin
, x
- width
/ 2, y
- h
/ 2);
2262 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2267 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2269 *x_ret
= x
- width
/ 2;
2271 XUngrabPointer(dpy
, CurrentTime
);
2272 XUngrabKeyboard(dpy
, CurrentTime
);
2273 /* get rid of the geometry window */
2274 WMUnmapWidget(scr
->gview
);
2278 WMHandleEvent(&event
);