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"
38 #include "workspace.h"
39 #include "placement.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))
65 *----------------------------------------------------------------------
66 * checkMouseSamplingRate-
67 * For lowering the mouse motion sampling rate for machines where
68 * it's too high (SGIs). If it returns False then the event should be
70 *----------------------------------------------------------------------
72 static Bool
checkMouseSamplingRate(XEvent
* ev
)
74 static Time previousMotion
= 0;
76 if (ev
->type
== MotionNotify
) {
77 if (ev
->xmotion
.time
- previousMotion
< DELAY_BETWEEN_MOUSE_SAMPLING
) {
80 previousMotion
= ev
->xmotion
.time
;
87 *----------------------------------------------------------------------
88 * moveGeometryDisplayCentered
90 * routine that moves the geometry/position window on scr so it is
91 * centered over the given coordinates (x,y). Also the window position
92 * is clamped so it stays on the screen at all times.
93 *----------------------------------------------------------------------
95 static void moveGeometryDisplayCentered(WScreen
* scr
, int x
, int y
)
97 unsigned int w
= WMWidgetWidth(scr
->gview
);
98 unsigned int h
= WMWidgetHeight(scr
->gview
);
99 int x1
= 0, y1
= 0, x2
= scr
->scr_width
, y2
= scr
->scr_height
;
104 /* dead area check */
105 if (scr
->xine_info
.count
) {
112 rect
.size
.height
= h
;
114 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
116 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
117 rect
= wGetRectForHead(scr
, head
);
120 x2
= x1
+ rect
.size
.width
;
121 y2
= y1
+ rect
.size
.height
;
127 else if (x
> (x2
- w
))
132 else if (y
> (y2
- h
))
135 WMMoveWidget(scr
->gview
, x
, y
);
138 static void showPosition(WWindow
* wwin
, int x
, int y
)
140 WScreen
*scr
= wwin
->screen_ptr
;
142 if (wPreferences
.move_display
== WDIS_NEW
) {
144 int width
= wwin
->frame
->core
->width
;
145 int height
= wwin
->frame
->core
->height
;
147 GC lgc
= scr
->line_gc
;
148 XSetForeground(dpy
, lgc
, scr
->line_pixel
);
149 sprintf(num
, "%i", x
);
151 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
- 1, scr
->scr_width
, y
- 1);
152 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
+ height
+ 2, scr
->scr_width
, y
+ height
+ 2);
153 XDrawLine(dpy
, scr
->root_win
, lgc
, x
- 1, 0, x
- 1, scr
->scr_height
);
154 XDrawLine(dpy
, scr
->root_win
, lgc
, x
+ width
+ 2, 0, x
+ width
+ 2, scr
->scr_height
);
157 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
161 static void cyclePositionDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
)
163 WScreen
*scr
= wwin
->screen_ptr
;
166 wPreferences
.move_display
++;
167 wPreferences
.move_display
%= NUM_DISPLAYS
;
169 if (wPreferences
.move_display
== WDIS_NEW
) {
170 wPreferences
.move_display
++;
171 wPreferences
.move_display
%= NUM_DISPLAYS
;
174 if (wPreferences
.move_display
== WDIS_NONE
) {
175 WMUnmapWidget(scr
->gview
);
177 if (wPreferences
.move_display
== WDIS_CENTER
) {
178 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
179 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
180 rect
.pos
.y
+ rect
.size
.height
/ 2);
181 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
182 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
183 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
184 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
185 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
187 WMMapWidget(scr
->gview
);
191 static void mapPositionDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
)
193 WScreen
*scr
= wwin
->screen_ptr
;
196 if (wPreferences
.move_display
== WDIS_NEW
|| wPreferences
.move_display
== WDIS_NONE
) {
198 } else if (wPreferences
.move_display
== WDIS_CENTER
) {
199 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
200 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
201 rect
.pos
.y
+ rect
.size
.height
/ 2);
202 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
203 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
204 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
205 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
206 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
208 WMMapWidget(scr
->gview
);
209 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
212 static void showGeometry(WWindow
* wwin
, int x1
, int y1
, int x2
, int y2
, int direction
)
214 WScreen
*scr
= wwin
->screen_ptr
;
215 Window root
= scr
->root_win
;
216 GC gc
= scr
->line_gc
;
217 int ty
, by
, my
, x
, y
, mx
, s
;
222 /* This seems necessary for some odd reason (too lazy to write x1-1 and
223 * x2-1 everywhere below in the code). But why only for x? */
227 if (HAS_BORDER_WITH_SELECT(wwin
)) {
228 x1
+= scr
->frame_border_width
;
229 x2
+= scr
->frame_border_width
;
230 y1
+= scr
->frame_border_width
;
231 y2
+= scr
->frame_border_width
;
234 ty
= y1
+ wwin
->frame
->top_width
;
235 by
= y2
- wwin
->frame
->bottom_width
;
237 if (wPreferences
.size_display
== WDIS_NEW
) {
238 fw
= XTextWidth(scr
->tech_draw_font
, "8888", 4);
239 fh
= scr
->tech_draw_font
->ascent
+ scr
->tech_draw_font
->descent
;
241 XSetForeground(dpy
, gc
, scr
->line_pixel
);
243 /* vertical geometry */
244 if (((direction
& LEFT
) && (x2
< scr
->scr_width
- fw
)) || (x1
< fw
)) {
253 /* top arrow & end bar */
254 segment
[0].x1
= x
- (s
+ 6);
256 segment
[0].x2
= x
- (s
- 10);
260 segment
[1].x1
= x
- (s
- 2);
261 segment
[1].y1
= ty
+ 1;
262 segment
[1].x2
= x
- (s
- 5);
263 segment
[1].y2
= ty
+ 7;
265 segment
[2].x1
= x
- (s
- 2);
266 segment
[2].y1
= ty
+ 1;
267 segment
[2].x2
= x
- (s
+ 1);
268 segment
[2].y2
= ty
+ 7;
271 segment
[3].x1
= x
- (s
- 2);
272 segment
[3].y1
= ty
+ 1;
273 segment
[3].x2
= x
- (s
- 2);
274 segment
[3].y2
= my
- fh
/ 2 - 1;
276 XDrawSegments(dpy
, root
, gc
, segment
, 4);
278 /* bottom arrow & end bar */
283 segment
[1].y1
= by
- 1;
284 segment
[1].y2
= by
- 7;
286 segment
[2].y1
= by
- 1;
287 segment
[2].y2
= by
- 7;
290 segment
[3].y1
= my
+ fh
/ 2 + 2;
291 segment
[3].y2
= by
- 1;
293 XDrawSegments(dpy
, root
, gc
, segment
, 4);
295 snprintf(num
, sizeof(num
), "%i", (by
- ty
- wwin
->normal_hints
->base_height
) /
296 wwin
->normal_hints
->height_inc
);
297 fw
= XTextWidth(scr
->tech_draw_font
, num
, strlen(num
));
299 /* Display the height. */
300 XSetFont(dpy
, gc
, scr
->tech_draw_font
->fid
);
301 XDrawString(dpy
, root
, gc
, x
- s
+ 3 - fw
/ 2, my
+ scr
->tech_draw_font
->ascent
- fh
/ 2 + 1, num
,
304 /* horizontal geometry */
312 mx
= x1
+ (x2
- x1
) / 2;
313 snprintf(num
, sizeof(num
), "%i", (x2
- x1
- wwin
->normal_hints
->base_width
) /
314 wwin
->normal_hints
->width_inc
);
315 fw
= XTextWidth(scr
->tech_draw_font
, num
, strlen(num
));
317 /* left arrow & end bar */
319 segment
[0].y1
= y
- (s
+ 6);
321 segment
[0].y2
= y
- (s
- 10);
324 segment
[1].x1
= x1
+ 7;
325 segment
[1].y1
= y
- (s
+ 1);
326 segment
[1].x2
= x1
+ 1;
327 segment
[1].y2
= y
- (s
- 2);
329 segment
[2].x1
= x1
+ 1;
330 segment
[2].y1
= y
- (s
- 2);
331 segment
[2].x2
= x1
+ 7;
332 segment
[2].y2
= y
- (s
- 5);
335 segment
[3].x1
= x1
+ 1;
336 segment
[3].y1
= y
- (s
- 2);
337 segment
[3].x2
= mx
- fw
/ 2 - 2;
338 segment
[3].y2
= y
- (s
- 2);
340 XDrawSegments(dpy
, root
, gc
, segment
, 4);
342 /* right arrow & end bar */
343 segment
[0].x1
= x2
+ 1;
344 segment
[0].x2
= x2
+ 1;
347 segment
[1].x1
= x2
- 6;
351 segment
[2].x2
= x2
- 6;
354 segment
[3].x1
= mx
+ fw
/ 2 + 2;
357 XDrawSegments(dpy
, root
, gc
, segment
, 4);
359 /* Display the width. */
360 XDrawString(dpy
, root
, gc
, mx
- fw
/ 2 + 1, y
- s
+ scr
->tech_draw_font
->ascent
- fh
/ 2 + 1, num
,
363 WSetGeometryViewShownSize(scr
->gview
, (x2
- x1
- wwin
->normal_hints
->base_width
)
364 / wwin
->normal_hints
->width_inc
,
365 (by
- ty
- wwin
->normal_hints
->base_height
)
366 / wwin
->normal_hints
->height_inc
);
370 static void cycleGeometryDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
, int dir
)
372 WScreen
*scr
= wwin
->screen_ptr
;
375 wPreferences
.size_display
++;
376 wPreferences
.size_display
%= NUM_DISPLAYS
;
378 if (wPreferences
.size_display
== WDIS_NEW
|| wPreferences
.size_display
== WDIS_NONE
) {
379 WMUnmapWidget(scr
->gview
);
381 if (wPreferences
.size_display
== WDIS_CENTER
) {
382 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
383 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
384 rect
.pos
.y
+ rect
.size
.height
/ 2);
385 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
386 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
387 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
388 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
389 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
391 WMMapWidget(scr
->gview
);
392 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, dir
);
396 static void mapGeometryDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
)
398 WScreen
*scr
= wwin
->screen_ptr
;
401 if (wPreferences
.size_display
== WDIS_NEW
|| wPreferences
.size_display
== WDIS_NONE
)
404 if (wPreferences
.size_display
== WDIS_CENTER
) {
405 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
406 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
407 rect
.pos
.y
+ rect
.size
.height
/ 2);
408 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
409 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
410 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
411 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
412 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
414 WMMapWidget(scr
->gview
);
415 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, 0);
418 static void doWindowMove(WWindow
* wwin
, WMArray
* array
, int dx
, int dy
)
421 WScreen
*scr
= wwin
->screen_ptr
;
424 if (!array
|| !WMGetArrayItemCount(array
)) {
425 wWindowMove(wwin
, wwin
->frame_x
+ dx
, wwin
->frame_y
+ dy
);
427 WMArrayIterator iter
;
429 WM_ITERATE_ARRAY(array
, tmpw
, iter
) {
430 x
= tmpw
->frame_x
+ dx
;
431 y
= tmpw
->frame_y
+ dy
;
433 #if 1 /* XXX: with xinerama patch was #if 0, check this */
434 /* don't let windows become unreachable */
436 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
437 x
= 20 - (int)tmpw
->frame
->core
->width
;
438 else if (x
+ 20 > scr
->scr_width
)
439 x
= scr
->scr_width
- 20;
441 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
442 y
= 20 - (int)tmpw
->frame
->core
->height
;
443 else if (y
+ 20 > scr
->scr_height
)
444 y
= scr
->scr_height
- 20;
446 wScreenBringInside(scr
, &x
, &y
,
447 (int)tmpw
->frame
->core
->width
, (int)tmpw
->frame
->core
->height
);
450 wWindowMove(tmpw
, x
, y
);
455 static void drawTransparentFrame(WWindow
* wwin
, int x
, int y
, int width
, int height
)
457 Window root
= wwin
->screen_ptr
->root_win
;
458 GC gc
= wwin
->screen_ptr
->frame_gc
;
462 if (HAS_BORDER_WITH_SELECT(wwin
)) {
463 x
+= wwin
->screen_ptr
->frame_border_width
;
464 y
+= wwin
->screen_ptr
->frame_border_width
;
467 if (HAS_TITLEBAR(wwin
) && !wwin
->flags
.shaded
) {
468 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + (wPreferences
.window_title_clearance
+
469 TITLEBAR_EXTEND_SPACE
) * 2;
471 if (h
> wPreferences
.window_title_max_height
)
472 h
= wPreferences
.window_title_max_height
;
474 if (h
< wPreferences
.window_title_min_height
)
475 h
= wPreferences
.window_title_min_height
;
477 if (HAS_RESIZEBAR(wwin
) && !wwin
->flags
.shaded
) {
478 /* Can't use wwin-frame->bottom_width because, in some cases
479 (e.g. interactive placement), frame does not point to anything. */
480 bottom
= RESIZEBAR_HEIGHT
;
482 XDrawRectangle(dpy
, root
, gc
, x
- 1, y
- 1, width
+ 1, height
+ 1);
485 XDrawLine(dpy
, root
, gc
, x
, y
+ h
- 1, x
+ width
, y
+ h
- 1);
488 XDrawLine(dpy
, root
, gc
, x
, y
+ height
- bottom
, x
+ width
, y
+ height
- bottom
);
492 static void drawFrames(WWindow
* wwin
, WMArray
* array
, int dx
, int dy
)
495 int scr_width
= wwin
->screen_ptr
->scr_width
;
496 int scr_height
= wwin
->screen_ptr
->scr_height
;
501 x
= wwin
->frame_x
+ dx
;
502 y
= wwin
->frame_y
+ dy
;
504 drawTransparentFrame(wwin
, x
, y
, wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
507 WMArrayIterator iter
;
509 WM_ITERATE_ARRAY(array
, tmpw
, iter
) {
510 x
= tmpw
->frame_x
+ dx
;
511 y
= tmpw
->frame_y
+ dy
;
513 /* don't let windows become unreachable */
514 #if 1 /* XXX: was 0 in XINERAMA patch, check */
515 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
516 x
= 20 - (int)tmpw
->frame
->core
->width
;
517 else if (x
+ 20 > scr_width
)
520 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
521 y
= 20 - (int)tmpw
->frame
->core
->height
;
522 else if (y
+ 20 > scr_height
)
526 wScreenBringInside(wwin
->screen_ptr
, &x
, &y
,
527 (int)tmpw
->frame
->core
->width
, (int)tmpw
->frame
->core
->height
);
530 drawTransparentFrame(tmpw
, x
, y
, tmpw
->frame
->core
->width
, tmpw
->frame
->core
->height
);
535 static void flushMotion(void)
540 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &ev
)) ;
543 static void crossWorkspace(WScreen
* scr
, WWindow
* wwin
, int opaque_move
, int new_workspace
, int rewind
)
545 /* do not let window be unmapped */
547 wwin
->flags
.changing_workspace
= 1;
548 wWindowChangeWorkspace(wwin
, new_workspace
);
550 /* go to new workspace */
551 wWorkspaceChange(scr
, new_workspace
);
553 wwin
->flags
.changing_workspace
= 0;
556 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, scr
->scr_width
- 20, 0);
558 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, -(scr
->scr_width
- 20), 0);
563 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
564 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
565 GrabModeAsync
, None
, wPreferences
.cursor
[WCUR_MOVE
], CurrentTime
);
570 /* arrays of WWindows sorted by the respective border position */
571 WWindow
**topList
; /* top border */
572 WWindow
**leftList
; /* left border */
573 WWindow
**rightList
; /* right border */
574 WWindow
**bottomList
; /* bottom border */
577 /* index of window in the above lists indicating the relative position
578 * of the window with the others */
584 int rubCount
; /* for workspace switching */
586 int winWidth
, winHeight
; /* width/height of the window */
587 int realX
, realY
; /* actual position of the window */
588 int calcX
, calcY
; /* calculated position of window */
589 int omouseX
, omouseY
; /* old mouse position */
590 int mouseX
, mouseY
; /* last known position of the pointer */
593 #define WTOP(w) (w)->frame_y
594 #define WLEFT(w) (w)->frame_x
595 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width - 1 + \
596 (HAS_BORDER_WITH_SELECT(w) ? 2*(w)->screen_ptr->frame_border_width : 0))
597 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height - 1 + \
598 (HAS_BORDER_WITH_SELECT(w) ? 2*(w)->screen_ptr->frame_border_width : 0))
600 static int compareWTop(const void *a
, const void *b
)
602 WWindow
*wwin1
= *(WWindow
**) a
;
603 WWindow
*wwin2
= *(WWindow
**) b
;
605 if (WTOP(wwin1
) > WTOP(wwin2
))
607 else if (WTOP(wwin1
) < WTOP(wwin2
))
613 static int compareWLeft(const void *a
, const void *b
)
615 WWindow
*wwin1
= *(WWindow
**) a
;
616 WWindow
*wwin2
= *(WWindow
**) b
;
618 if (WLEFT(wwin1
) > WLEFT(wwin2
))
620 else if (WLEFT(wwin1
) < WLEFT(wwin2
))
626 static int compareWRight(const void *a
, const void *b
)
628 WWindow
*wwin1
= *(WWindow
**) a
;
629 WWindow
*wwin2
= *(WWindow
**) b
;
631 if (WRIGHT(wwin1
) < WRIGHT(wwin2
))
633 else if (WRIGHT(wwin1
) > WRIGHT(wwin2
))
639 static int compareWBottom(const void *a
, const void *b
)
641 WWindow
*wwin1
= *(WWindow
**) a
;
642 WWindow
*wwin2
= *(WWindow
**) b
;
644 if (WBOTTOM(wwin1
) < WBOTTOM(wwin2
))
646 else if (WBOTTOM(wwin1
) > WBOTTOM(wwin2
))
652 static void updateResistance(MoveData
*data
, int newX
, int newY
)
655 int newX2
= newX
+ data
->winWidth
;
656 int newY2
= newY
+ data
->winHeight
;
659 if (newX
< data
->realX
) {
660 if (data
->rightIndex
> 0 && newX
< WRIGHT(data
->rightList
[data
->rightIndex
- 1])) {
662 } else if (data
->leftIndex
<= data
->count
- 1 && newX2
<= WLEFT(data
->leftList
[data
->leftIndex
])) {
665 } else if (newX
> data
->realX
) {
666 if (data
->leftIndex
> 0 && newX2
> WLEFT(data
->leftList
[data
->leftIndex
- 1])) {
668 } else if (data
->rightIndex
<= data
->count
- 1
669 && newX
>= WRIGHT(data
->rightList
[data
->rightIndex
])) {
675 if (newY
< data
->realY
) {
676 if (data
->bottomIndex
> 0 && newY
< WBOTTOM(data
->bottomList
[data
->bottomIndex
- 1])) {
678 } else if (data
->topIndex
<= data
->count
- 1
679 && newY2
<= WTOP(data
->topList
[data
->topIndex
])) {
682 } else if (newY
> data
->realY
) {
683 if (data
->topIndex
> 0 && newY2
> WTOP(data
->topList
[data
->topIndex
- 1])) {
685 } else if (data
->bottomIndex
<= data
->count
- 1
686 && newY
>= WBOTTOM(data
->bottomList
[data
->bottomIndex
])) {
695 /* TODO: optimize this */
696 if (data
->realY
< WBOTTOM(data
->bottomList
[0])) {
697 data
->bottomIndex
= 0;
699 if (data
->realX
< WRIGHT(data
->rightList
[0])) {
700 data
->rightIndex
= 0;
702 if ((data
->realX
+ data
->winWidth
) > WLEFT(data
->leftList
[0])) {
705 if ((data
->realY
+ data
->winHeight
) > WTOP(data
->topList
[0])) {
708 for (i
= 0; i
< data
->count
; i
++) {
709 if (data
->realY
> WBOTTOM(data
->bottomList
[i
])) {
710 data
->bottomIndex
= i
+ 1;
712 if (data
->realX
> WRIGHT(data
->rightList
[i
])) {
713 data
->rightIndex
= i
+ 1;
715 if ((data
->realX
+ data
->winWidth
) < WLEFT(data
->leftList
[i
])) {
716 data
->leftIndex
= i
+ 1;
718 if ((data
->realY
+ data
->winHeight
) < WTOP(data
->topList
[i
])) {
719 data
->topIndex
= i
+ 1;
724 static void freeMoveData(MoveData
* data
)
727 wfree(data
->topList
);
729 wfree(data
->leftList
);
731 wfree(data
->rightList
);
732 if (data
->bottomList
)
733 wfree(data
->bottomList
);
736 static void updateMoveData(WWindow
* wwin
, MoveData
* data
)
738 WScreen
*scr
= wwin
->screen_ptr
;
743 tmp
= scr
->focused_window
;
745 if (tmp
!= wwin
&& w_global
.workspace
.current
== tmp
->frame
->workspace
746 && !tmp
->flags
.miniaturized
747 && !tmp
->flags
.hidden
&& !tmp
->flags
.obscured
&& !WFLAGP(tmp
, sunken
)) {
748 data
->topList
[data
->count
] = tmp
;
749 data
->leftList
[data
->count
] = tmp
;
750 data
->rightList
[data
->count
] = tmp
;
751 data
->bottomList
[data
->count
] = tmp
;
757 if (data
->count
== 0) {
760 data
->rightIndex
= 0;
761 data
->bottomIndex
= 0;
765 /* order from closest to the border of the screen to farthest */
767 qsort(data
->topList
, data
->count
, sizeof(WWindow
**), compareWTop
);
768 qsort(data
->leftList
, data
->count
, sizeof(WWindow
**), compareWLeft
);
769 qsort(data
->rightList
, data
->count
, sizeof(WWindow
**), compareWRight
);
770 qsort(data
->bottomList
, data
->count
, sizeof(WWindow
**), compareWBottom
);
772 /* figure the position of the window relative to the others */
775 data
->leftIndex
= -1;
776 data
->rightIndex
= -1;
777 data
->bottomIndex
= -1;
779 if (WTOP(wwin
) < WBOTTOM(data
->bottomList
[0])) {
780 data
->bottomIndex
= 0;
782 if (WLEFT(wwin
) < WRIGHT(data
->rightList
[0])) {
783 data
->rightIndex
= 0;
785 if (WRIGHT(wwin
) > WLEFT(data
->leftList
[0])) {
788 if (WBOTTOM(wwin
) > WTOP(data
->topList
[0])) {
791 for (i
= 0; i
< data
->count
; i
++) {
792 if (WTOP(wwin
) >= WBOTTOM(data
->bottomList
[i
])) {
793 data
->bottomIndex
= i
+ 1;
795 if (WLEFT(wwin
) >= WRIGHT(data
->rightList
[i
])) {
796 data
->rightIndex
= i
+ 1;
798 if (WRIGHT(wwin
) <= WLEFT(data
->leftList
[i
])) {
799 data
->leftIndex
= i
+ 1;
801 if (WBOTTOM(wwin
) <= WTOP(data
->topList
[i
])) {
802 data
->topIndex
= i
+ 1;
807 static void initMoveData(WWindow
* wwin
, MoveData
* data
)
812 memset(data
, 0, sizeof(MoveData
));
814 for (i
= 0, tmp
= wwin
->screen_ptr
->focused_window
; tmp
!= NULL
; tmp
= tmp
->prev
, i
++) ;
817 data
->topList
= wmalloc(sizeof(WWindow
*) * i
);
818 data
->leftList
= wmalloc(sizeof(WWindow
*) * i
);
819 data
->rightList
= wmalloc(sizeof(WWindow
*) * i
);
820 data
->bottomList
= wmalloc(sizeof(WWindow
*) * i
);
822 updateMoveData(wwin
, data
);
825 data
->realX
= wwin
->frame_x
;
826 data
->realY
= wwin
->frame_y
;
827 data
->calcX
= wwin
->frame_x
;
828 data
->calcY
= wwin
->frame_y
;
830 data
->winWidth
= wwin
->frame
->core
->width
+ (HAS_BORDER_WITH_SELECT(wwin
) ? 2 * wwin
->screen_ptr
->frame_border_width
: 0);
831 data
->winHeight
= wwin
->frame
->core
->height
+ (HAS_BORDER_WITH_SELECT(wwin
) ? 2 * wwin
->screen_ptr
->frame_border_width
: 0);
834 static Bool
checkWorkspaceChange(WWindow
* wwin
, MoveData
* data
, Bool opaqueMove
)
836 WScreen
*scr
= wwin
->screen_ptr
;
837 Bool changed
= False
;
839 if (data
->mouseX
<= 1) {
840 if (w_global
.workspace
.current
> 0) {
841 crossWorkspace(scr
, wwin
, opaqueMove
, w_global
.workspace
.current
- 1, True
);
844 } else if (w_global
.workspace
.current
== 0 && wPreferences
.ws_cycle
) {
845 crossWorkspace(scr
, wwin
, opaqueMove
, w_global
.workspace
.count
- 1, True
);
849 } else if (data
->mouseX
>= scr
->scr_width
- 2) {
850 if (w_global
.workspace
.current
== w_global
.workspace
.count
- 1) {
851 if (wPreferences
.ws_cycle
|| w_global
.workspace
.count
== MAX_WORKSPACES
) {
852 crossWorkspace(scr
, wwin
, opaqueMove
, 0, False
);
856 /* if user insists on trying to go to next workspace even when
857 * it's already the last, create a new one */
858 else if (data
->omouseX
== data
->mouseX
&& wPreferences
.ws_advance
) {
860 /* detect user "rubbing" the window against the edge */
861 if (data
->rubCount
> 0 && data
->omouseY
- data
->mouseY
> MOVE_THRESHOLD
) {
863 data
->rubCount
= -(data
->rubCount
+ 1);
865 } else if (data
->rubCount
<= 0 && data
->mouseY
- data
->omouseY
> MOVE_THRESHOLD
) {
867 data
->rubCount
= -data
->rubCount
+ 1;
870 /* create a new workspace */
871 if (abs(data
->rubCount
) > 2) {
872 /* go to next workspace */
875 crossWorkspace(scr
, wwin
, opaqueMove
, w_global
.workspace
.current
+ 1, False
);
879 } else if (w_global
.workspace
.current
< w_global
.workspace
.count
) {
880 /* go to next workspace */
881 crossWorkspace(scr
, wwin
, opaqueMove
, w_global
.workspace
.current
+ 1, False
);
893 updateWindowPosition(WWindow
* wwin
, MoveData
* data
, Bool doResistance
,
894 Bool opaqueMove
, int newMouseX
, int newMouseY
)
896 WScreen
*scr
= wwin
->screen_ptr
;
897 int dx
, dy
; /* how much mouse moved */
898 int winL
, winR
, winT
, winB
; /* requested new window position */
899 int newX
, newY
; /* actual new window position */
900 Bool hresist
, vresist
;
906 /* check the direction of the movement */
907 dx
= newMouseX
- data
->mouseX
;
908 dy
= newMouseY
- data
->mouseY
;
910 data
->omouseX
= data
->mouseX
;
911 data
->omouseY
= data
->mouseY
;
912 data
->mouseX
= newMouseX
;
913 data
->mouseY
= newMouseY
;
915 winL
= data
->calcX
+ dx
;
916 winR
= data
->calcX
+ data
->winWidth
+ dx
;
917 winT
= data
->calcY
+ dy
;
918 winB
= data
->calcY
+ data
->winHeight
+ dy
;
930 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
931 attract
= wPreferences
.attract
;
932 /* horizontal movement: check horizontal edge resistances */
936 /* window is the leftmost window: check against screen edge */
938 /* Add inter head resistance 1/2 (if needed) */
939 head
= wGetHeadForPointerLocation(scr
);
940 rect
= wGetRectForHead(scr
, head
);
942 l_edge
= WMAX(scr
->totalUsableArea
[head
].x1
, rect
.pos
.x
);
943 edge_l
= l_edge
- resist
;
944 edge_r
= WMIN(scr
->totalUsableArea
[head
].x2
, rect
.pos
.x
+ rect
.size
.width
);
945 r_edge
= edge_r
+ resist
;
948 if ((data
->rightIndex
>= 0) && (data
->rightIndex
<= data
->count
)) {
951 for (i
= data
->rightIndex
- 1; i
>= 0; i
--) {
952 looprw
= data
->rightList
[i
];
953 if (!(data
->realY
> WBOTTOM(looprw
)
954 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
955 if (attract
|| ((data
->realX
< (WRIGHT(looprw
) + 2)) && dx
< 0)) {
956 l_edge
= WRIGHT(looprw
) + 1;
957 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
964 for (i
= data
->rightIndex
; i
< data
->count
; i
++) {
965 looprw
= data
->rightList
[i
];
966 if (!(data
->realY
> WBOTTOM(looprw
)
967 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
968 r_edge
= WRIGHT(looprw
) + 1;
969 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
976 if ((data
->leftIndex
>= 0) && (data
->leftIndex
<= data
->count
)) {
979 for (i
= data
->leftIndex
- 1; i
>= 0; i
--) {
980 looprw
= data
->leftList
[i
];
981 if (!(data
->realY
> WBOTTOM(looprw
)
982 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
984 || (((data
->realX
+ data
->winWidth
) > (WLEFT(looprw
) - 1))
986 edge_r
= WLEFT(looprw
);
987 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
994 for (i
= data
->leftIndex
; i
< data
->count
; i
++) {
995 looprw
= data
->leftList
[i
];
996 if (!(data
->realY
> WBOTTOM(looprw
)
997 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
998 edge_l
= WLEFT(looprw
);
999 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1006 printf("%d %d\n",winL,winR);
1007 printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);
1010 if ((winL
- l_edge
) < (r_edge
- winL
)) {
1012 if ((attract
&& winL
<= l_edge
+ resist
&& winL
>= l_edge
- resist
)
1013 || (dx
< 0 && winL
<= l_edge
&& winL
>= l_edge
- resist
)) {
1019 if (resist
> 0 && attract
&& winL
>= r_edge
- resist
&& winL
<= r_edge
+ resist
) {
1025 if ((winR
- edge_l
) < (edge_r
- winR
)) {
1026 if (resist
> 0 && attract
&& winR
<= edge_l
+ resist
&& winR
>= edge_l
- resist
) {
1027 newX
= edge_l
- data
->winWidth
;
1032 if ((attract
&& winR
>= edge_r
- resist
&& winR
<= edge_r
+ resist
)
1033 || (dx
> 0 && winR
>= edge_r
&& winR
<= edge_r
+ resist
)) {
1034 newX
= edge_r
- data
->winWidth
;
1041 /* Add inter head resistance 2/2 (if needed) */
1042 t_edge
= WMAX(scr
->totalUsableArea
[head
].y1
, rect
.pos
.y
);
1043 edge_t
= t_edge
- resist
;
1044 edge_b
= WMIN(scr
->totalUsableArea
[head
].y2
, rect
.pos
.y
+ rect
.size
.height
);
1045 b_edge
= edge_b
+ resist
;
1047 if ((data
->bottomIndex
>= 0) && (data
->bottomIndex
<= data
->count
)) {
1050 for (i
= data
->bottomIndex
- 1; i
>= 0; i
--) {
1051 looprw
= data
->bottomList
[i
];
1052 if (!(data
->realX
> WRIGHT(looprw
)
1053 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1054 if (attract
|| ((data
->realY
< (WBOTTOM(looprw
) + 2)) && dy
< 0)) {
1055 t_edge
= WBOTTOM(looprw
) + 1;
1056 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1063 for (i
= data
->bottomIndex
; i
< data
->count
; i
++) {
1064 looprw
= data
->bottomList
[i
];
1065 if (!(data
->realX
> WRIGHT(looprw
)
1066 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1067 b_edge
= WBOTTOM(looprw
) + 1;
1068 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1075 if ((data
->topIndex
>= 0) && (data
->topIndex
<= data
->count
)) {
1078 for (i
= data
->topIndex
- 1; i
>= 0; i
--) {
1079 looprw
= data
->topList
[i
];
1080 if (!(data
->realX
> WRIGHT(looprw
)
1081 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1083 || (((data
->realY
+ data
->winHeight
) > (WTOP(looprw
) - 1))
1085 edge_b
= WTOP(looprw
);
1086 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1093 for (i
= data
->topIndex
; i
< data
->count
; i
++) {
1094 looprw
= data
->topList
[i
];
1095 if (!(data
->realX
> WRIGHT(looprw
)
1096 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1097 edge_t
= WTOP(looprw
);
1098 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1104 if ((winT
- t_edge
) < (b_edge
- winT
)) {
1106 if ((attract
&& winT
<= t_edge
+ resist
&& winT
>= t_edge
- resist
)
1107 || (dy
< 0 && winT
<= t_edge
&& winT
>= t_edge
- resist
)) {
1113 if (resist
> 0 && attract
&& winT
>= b_edge
- resist
&& winT
<= b_edge
+ resist
) {
1119 if ((winB
- edge_t
) < (edge_b
- winB
)) {
1120 if (resist
> 0 && attract
&& winB
<= edge_t
+ resist
&& winB
>= edge_t
- resist
) {
1121 newY
= edge_t
- data
->winHeight
;
1126 if ((attract
&& winB
>= edge_b
- resist
&& winB
<= edge_b
+ resist
)
1127 || (dy
> 0 && winB
>= edge_b
&& winB
<= edge_b
+ resist
)) {
1128 newY
= edge_b
- data
->winHeight
;
1138 /* update window position */
1142 if (((dx
> 0 && data
->calcX
- data
->realX
> 0)
1143 || (dx
< 0 && data
->calcX
- data
->realX
< 0)) && !hresist
)
1146 if (((dy
> 0 && data
->calcY
- data
->realY
> 0)
1147 || (dy
< 0 && data
->calcY
- data
->realY
< 0)) && !vresist
)
1150 if (data
->realX
!= newX
|| data
->realY
!= newY
) {
1152 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1153 showPosition(wwin
, data
->realX
, data
->realY
);
1156 doWindowMove(wwin
, scr
->selected_windows
, newX
- wwin
->frame_x
, newY
- wwin
->frame_y
);
1159 drawFrames(wwin
, scr
->selected_windows
,
1160 data
->realX
- wwin
->frame_x
, data
->realY
- wwin
->frame_y
);
1163 if (!scr
->selected_windows
&& wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
1165 moveGeometryDisplayCentered(scr
, newX
+ data
->winWidth
/ 2, newY
+ data
->winHeight
/ 2);
1170 drawFrames(wwin
, scr
->selected_windows
, newX
- wwin
->frame_x
, newY
- wwin
->frame_y
);
1173 if (!scr
->selected_windows
) {
1174 showPosition(wwin
, newX
, newY
);
1178 /* recalc relative window position */
1179 if (doResistance
&& (data
->realX
!= newX
|| data
->realY
!= newY
)) {
1180 updateResistance(data
, newX
, newY
);
1187 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1189 #define MOVABLE_BIT 0x01
1190 #define RESIZABLE_BIT 0x02
1192 int wKeyboardMoveResizeWindow(WWindow
* wwin
)
1194 WScreen
*scr
= wwin
->screen_ptr
;
1195 Window root
= scr
->root_win
;
1197 int w
= wwin
->frame
->core
->width
;
1198 int h
= wwin
->frame
->core
->height
;
1199 int scr_width
= wwin
->screen_ptr
->scr_width
;
1200 int scr_height
= wwin
->screen_ptr
->scr_height
;
1201 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1202 int src_x
= wwin
->frame_x
;
1203 int src_y
= wwin
->frame_y
;
1206 int done
, off_x
, off_y
, ww
, wh
;
1208 int opaqueMoveResize
= wPreferences
.opaque_move_resize_keyboard
;
1210 KeyCode shiftl
, shiftr
, ctrlmode
;
1211 KeySym keysym
= NoSymbol
;
1213 int modes
= ((IS_MOVABLE(wwin
) ? MOVABLE_BIT
: 0) | (IS_RESIZABLE(wwin
) ? RESIZABLE_BIT
: 0));
1214 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1215 ? wGetHeadForWindow(wwin
)
1216 : scr
->xine_info
.primary_head
);
1218 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1219 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1220 ctrlmode
= done
= off_x
= off_y
= 0;
1222 if (modes
== RESIZABLE_BIT
) {
1228 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1230 if (!wwin
->flags
.selected
) {
1231 wUnselectWindows(scr
);
1234 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1235 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
1236 GrabModeAsync
, None
, wPreferences
.cursor
[WCUR_NORMAL
], CurrentTime
);
1240 if (!opaqueMoveResize
) {
1241 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1242 if (scr
->selected_windows
)
1243 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1245 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1247 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1250 if ((wwin
->flags
.shaded
|| scr
->selected_windows
) && (!scr
->selected_windows
)) {
1251 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1262 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1263 | ButtonPressMask
| ExposureMask
, &event
);
1264 if (event
.type
== Expose
) {
1265 WMHandleEvent(&event
);
1267 } while (event
.type
== Expose
);
1269 if (!opaqueMoveResize
) {
1270 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1271 if (scr
->selected_windows
)
1272 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1274 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1275 /*** I HATE EDGE RESISTANCE - ]d ***/
1277 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1282 showGeometry(wwin
, src_x
+ off_x
, src_y
+ off_y
, src_x
+ off_x
+ ww
, src_y
+ off_y
+ wh
,
1288 switch (event
.type
) {
1291 if (event
.xkey
.time
- lastTime
> 50) {
1292 kspeed
/= (1 + (event
.xkey
.time
- lastTime
) / 100);
1300 lastTime
= event
.xkey
.time
;
1301 if (modes
== (MOVABLE_BIT
| RESIZABLE_BIT
)) {
1302 if ((event
.xkey
.state
& ControlMask
) && !wwin
->flags
.shaded
) {
1304 wUnselectWindows(scr
);
1309 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
) {
1311 cycleGeometryDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
, 0);
1313 cyclePositionDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1316 keysym
= XLookupKeysym(&event
.xkey
, 0);
1373 if (moment
!= RIGHT
)
1385 wWindowConstrainSize(wwin
, (unsigned int *)&ww
, (unsigned int *)&wh
);
1388 if (wPreferences
.ws_cycle
) {
1389 if (src_x
+ off_x
+ ww
< 20) {
1390 if (!w_global
.workspace
.current
)
1391 wWorkspaceChange(scr
, w_global
.workspace
.count
- 1);
1393 wWorkspaceChange(scr
, w_global
.workspace
.current
- 1);
1396 } else if (src_x
+ off_x
+ 20 > scr_width
) {
1397 if (w_global
.workspace
.current
== w_global
.workspace
.count
- 1)
1398 wWorkspaceChange(scr
, 0);
1400 wWorkspaceChange(scr
, w_global
.workspace
.current
+ 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 wWindowConfigure(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
- vert_border
);
1472 if (!opaqueMoveResize
) { /* ctrlmode => resize */
1473 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1474 if (scr
->selected_windows
)
1475 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1477 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1479 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1484 showGeometry(wwin
, src_x
+ off_x
, src_y
+ off_y
, src_x
+ off_x
+ ww
,
1485 src_y
+ off_y
+ wh
, 0);
1486 WMUnmapWidget(scr
->gview
);
1488 WMUnmapWidget(scr
->gview
);
1490 XUngrabKeyboard(dpy
, CurrentTime
);
1491 XUngrabPointer(dpy
, CurrentTime
);
1495 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1496 if (!scr
->selected_windows
) {
1497 wWindowMove(wwin
, src_x
+ off_x
, src_y
+ off_y
);
1498 wWindowSynthConfigureNotify(wwin
);
1500 WMArrayIterator iter
;
1503 doWindowMove(wwin
, scr
->selected_windows
, off_x
, off_y
);
1505 WM_ITERATE_ARRAY(scr
->selected_windows
, foo
, iter
) {
1506 wWindowSynthConfigureNotify(foo
);
1510 if (ww
!= original_w
)
1511 wwin
->flags
.maximized
&= ~(MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
1513 if (wh
!= original_h
)
1514 wwin
->flags
.maximized
&= ~(MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
1516 wWindowConfigure(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
- vert_border
);
1517 wWindowSynthConfigureNotify(wwin
);
1519 wWindowChangeWorkspace(wwin
, w_global
.workspace
.current
);
1520 wSetFocusTo(scr
, wwin
);
1523 if (wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 &&
1524 head
!= wGetHeadForWindow(wwin
)) {
1525 wArrangeIcons(scr
, True
);
1528 update_saved_geometry(wwin
);
1536 *----------------------------------------------------------------------
1537 * wMouseMoveWindow--
1538 * Move the named window and the other selected ones (if any),
1539 * interactively. Also shows the position of the window, if only one
1540 * window is being moved.
1541 * If the window is not on the selected window list, the selected
1542 * windows are deselected.
1543 * If shift is pressed during the operation, the position display
1544 * is changed to another type.
1547 * True if the window was moved, False otherwise.
1550 * The window(s) position is changed, and the client(s) are
1551 * notified about that.
1552 * The position display configuration may be changed.
1553 *----------------------------------------------------------------------
1555 int wMouseMoveWindow(WWindow
* wwin
, XEvent
* ev
)
1557 WScreen
*scr
= wwin
->screen_ptr
;
1559 Window root
= scr
->root_win
;
1560 KeyCode shiftl
, shiftr
;
1564 /* This needs not to change while moving, else bad things can happen */
1565 int opaqueMove
= wPreferences
.opaque_move
;
1567 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1568 ? wGetHeadForWindow(wwin
)
1569 : scr
->xine_info
.primary_head
);
1571 if (!IS_MOVABLE(wwin
))
1574 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1575 XSetWindowAttributes attr
;
1577 attr
.save_under
= True
;
1578 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
, CWSaveUnder
, &attr
);
1581 initMoveData(wwin
, &moveData
);
1583 moveData
.mouseX
= ev
->xmotion
.x_root
;
1584 moveData
.mouseY
= ev
->xmotion
.y_root
;
1586 if (!wwin
->flags
.selected
) {
1587 /* this window is not selected, unselect others and move only wwin */
1588 wUnselectWindows(scr
);
1590 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1591 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1597 /* XWarpPointer() doesn't seem to generate Motion events, so
1598 * we've got to simulate them */
1599 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1600 &event
.xmotion
.y_root
, &junk
, &junk
, (unsigned *)&junk
);
1602 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1603 | PointerMotionHintMask
1604 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
, &event
);
1606 if (event
.type
== MotionNotify
) {
1607 /* compress MotionNotify events */
1608 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1609 if (!checkMouseSamplingRate(&event
))
1613 switch (event
.type
) {
1615 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1616 && started
&& !scr
->selected_windows
) {
1619 drawFrames(wwin
, scr
->selected_windows
,
1620 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1623 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1624 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1627 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1628 moveData
.winWidth
, moveData
.winHeight
);
1630 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1632 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1636 drawFrames(wwin
, scr
->selected_windows
,
1637 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1640 WMHandleEvent(&event); this causes problems needs fixing */
1646 updateWindowPosition(wwin
, &moveData
,
1647 scr
->selected_windows
== NULL
1648 && wPreferences
.edge_resistance
> 0,
1649 opaqueMove
, event
.xmotion
.x_root
, event
.xmotion
.y_root
);
1651 if (!warped
&& !wPreferences
.no_autowrap
) {
1652 int oldWorkspace
= w_global
.workspace
.current
;
1654 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1655 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1659 drawFrames(wwin
, scr
->selected_windows
,
1660 moveData
.realX
- wwin
->frame_x
,
1661 moveData
.realY
- wwin
->frame_y
);
1663 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1664 if (w_global
.workspace
.current
!= oldWorkspace
1665 && wPreferences
.edge_resistance
> 0
1666 && scr
->selected_windows
== NULL
)
1667 updateMoveData(wwin
, &moveData
);
1671 drawFrames(wwin
, scr
->selected_windows
,
1672 moveData
.realX
- wwin
->frame_x
,
1673 moveData
.realY
- wwin
->frame_y
);
1675 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1677 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1683 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1684 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1686 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1687 | ButtonReleaseMask
| ButtonPressMask
,
1688 wPreferences
.cursor
[WCUR_MOVE
], CurrentTime
);
1690 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1692 if (!scr
->selected_windows
)
1693 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1694 moveData
.winWidth
, moveData
.winHeight
);
1696 if (started
&& !opaqueMove
)
1697 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1699 if (!opaqueMove
|| (wPreferences
.move_display
== WDIS_NEW
1700 && !scr
->selected_windows
)) {
1702 if (wPreferences
.move_display
== WDIS_NEW
)
1703 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1712 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1718 drawFrames(wwin
, scr
->selected_windows
,
1719 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1721 doWindowMove(wwin
, scr
->selected_windows
,
1722 moveData
.realX
- wwin
->frame_x
,
1723 moveData
.realY
- wwin
->frame_y
);
1725 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1726 wWindowSynthConfigureNotify(wwin
);
1728 XUngrabKeyboard(dpy
, CurrentTime
);
1731 wWindowChangeWorkspace(wwin
, w_global
.workspace
.current
);
1732 wSetFocusTo(scr
, wwin
);
1734 if (wPreferences
.move_display
== WDIS_NEW
)
1735 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1737 /* discard all enter/leave events that happened until
1738 * the time the button was released */
1739 while (XCheckTypedEvent(dpy
, EnterNotify
, &e
)) {
1740 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1741 XPutBackEvent(dpy
, &e
);
1745 while (XCheckTypedEvent(dpy
, LeaveNotify
, &e
)) {
1746 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1747 XPutBackEvent(dpy
, &e
);
1752 if (!scr
->selected_windows
) {
1753 /* get rid of the geometry window */
1754 WMUnmapWidget(scr
->gview
);
1761 if (started
&& !opaqueMove
) {
1762 drawFrames(wwin
, scr
->selected_windows
,
1763 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1765 WMHandleEvent(&event
);
1768 drawFrames(wwin
, scr
->selected_windows
,
1769 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1771 WMHandleEvent(&event
);
1777 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1778 XSetWindowAttributes attr
;
1780 attr
.save_under
= False
;
1781 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
, CWSaveUnder
, &attr
);
1785 freeMoveData(&moveData
);
1787 if (started
&& wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 &&
1788 head
!= wGetHeadForWindow(wwin
)) {
1789 wArrangeIcons(scr
, True
);
1793 update_saved_geometry(wwin
);
1799 #define HCONSTRAIN 2
1801 static int getResizeDirection(WWindow
* wwin
, int x
, int y
, int dx
, int dy
, int flags
)
1803 int w
= wwin
->frame
->core
->width
- 1;
1804 int cw
= wwin
->frame
->resizebar_corner_width
;
1807 /* if not resizing through the resizebar */
1808 if (!(flags
& RESIZEBAR
)) {
1809 int xdir
= (abs(x
) < (wwin
->client
.width
/ 2)) ? LEFT
: RIGHT
;
1810 int ydir
= (abs(y
) < (wwin
->client
.height
/ 2)) ? UP
: DOWN
;
1811 if (abs(dx
) < 2 || abs(dy
) < 2) {
1812 if (abs(dy
) > abs(dx
))
1817 return (xdir
| ydir
);
1820 /* window is too narrow. allow diagonal resize */
1824 if (flags
& HCONSTRAIN
)
1829 return (LEFT
| ydir
);
1831 return (RIGHT
| ydir
);
1833 /* vertical resize */
1834 if ((x
> cw
) && (x
< w
- cw
))
1842 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1848 void wMouseResizeWindow(WWindow
* wwin
, XEvent
* ev
)
1851 WScreen
*scr
= wwin
->screen_ptr
;
1852 Window root
= scr
->root_win
;
1853 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1854 int fw
= wwin
->frame
->core
->width
;
1855 int fh
= wwin
->frame
->core
->height
;
1856 int fx
= wwin
->frame_x
;
1857 int fy
= wwin
->frame_y
;
1858 int is_resizebar
= (wwin
->frame
->resizebar
&& ev
->xany
.window
== wwin
->frame
->resizebar
->window
);
1862 int rw
= fw
, rh
= fh
;
1863 int rx1
, ry1
, rx2
, ry2
;
1865 KeyCode shiftl
, shiftr
;
1870 int original_fw
= fw
;
1871 int original_fh
= fh
;
1872 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1873 ? wGetHeadForWindow(wwin
)
1874 : scr
->xine_info
.primary_head
);
1875 int opaqueResize
= wPreferences
.opaque_resize
;
1877 if (!IS_RESIZABLE(wwin
))
1880 if (wwin
->flags
.shaded
) {
1881 wwarning("internal error: tryein");
1884 orig_x
= ev
->xbutton
.x_root
;
1885 orig_y
= ev
->xbutton
.y_root
;
1888 wUnselectWindows(scr
);
1893 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1894 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1897 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1898 | ButtonReleaseMask
| PointerMotionHintMask
| ButtonPressMask
| ExposureMask
, &event
);
1899 if (!checkMouseSamplingRate(&event
))
1902 switch (event
.type
) {
1904 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1905 if (!opaqueResize
) {
1906 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1908 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1909 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
1910 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1913 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1918 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1929 dw
= orig_x
- event
.xmotion
.x_root
;
1930 else if (res
& RIGHT
)
1931 dw
= event
.xmotion
.x_root
- orig_x
;
1933 dh
= orig_y
- event
.xmotion
.y_root
;
1934 else if (res
& DOWN
)
1935 dh
= event
.xmotion
.y_root
- orig_y
;
1937 orig_x
= event
.xmotion
.x_root
;
1938 orig_y
= event
.xmotion
.y_root
;
1943 fh
= rh
- vert_border
;
1944 wWindowConstrainSize(wwin
, (unsigned int *)&fw
, (unsigned int *)&fh
);
1948 else if (res
& RIGHT
)
1952 else if (res
& DOWN
)
1954 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1955 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1960 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
1961 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
1963 /* check if resizing through resizebar */
1969 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
1970 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
1971 flags
|= HCONSTRAIN
;
1973 res
= getResizeDirection(wwin
, tx
, ty
,
1974 orig_x
- event
.xmotion
.x_root
,
1975 orig_y
- event
.xmotion
.y_root
, flags
);
1977 if (res
== (UP
| LEFT
))
1978 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1979 | ButtonReleaseMask
| ButtonPressMask
,
1980 wPreferences
.cursor
[WCUR_TOPLEFTRESIZE
], CurrentTime
);
1981 else if (res
== (UP
| RIGHT
))
1982 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1983 | ButtonReleaseMask
| ButtonPressMask
,
1984 wPreferences
.cursor
[WCUR_TOPRIGHTRESIZE
], CurrentTime
);
1985 else if (res
== (DOWN
| LEFT
))
1986 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1987 | ButtonReleaseMask
| ButtonPressMask
,
1988 wPreferences
.cursor
[WCUR_BOTTOMLEFTRESIZE
], CurrentTime
);
1989 else if (res
== (DOWN
| RIGHT
))
1990 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1991 | ButtonReleaseMask
| ButtonPressMask
,
1992 wPreferences
.cursor
[WCUR_BOTTOMRIGHTRESIZE
], CurrentTime
);
1993 else if (res
== DOWN
|| res
== UP
)
1994 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1995 | ButtonReleaseMask
| ButtonPressMask
,
1996 wPreferences
.cursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
1997 else if (res
& (DOWN
| UP
))
1998 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1999 | ButtonReleaseMask
| ButtonPressMask
,
2000 wPreferences
.cursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2001 else if (res
& (LEFT
| RIGHT
))
2002 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2003 | ButtonReleaseMask
| ButtonPressMask
,
2004 wPreferences
.cursor
[WCUR_HORIZONRESIZE
], CurrentTime
);
2006 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2010 /* Draw the resize frame for the first time. */
2011 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
2014 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2016 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2022 drawTransparentFrame(wwin
, orig_fx
, orig_fy
, orig_fw
, orig_fh
);
2024 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
)
2025 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
2028 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2030 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
2031 if (wPreferences
.size_display
== WDIS_NEW
)
2032 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
2033 orig_fy
+ orig_fh
, res
);
2035 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2039 /* Fist clean the geometry line */
2040 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2041 /* Now, continue drawing */
2043 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
2044 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
2045 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2054 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2058 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2061 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2063 XUngrabKeyboard(dpy
, CurrentTime
);
2064 WMUnmapWidget(scr
->gview
);
2067 if (fw
!= original_fw
)
2068 wwin
->flags
.maximized
&= ~(MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
2070 if (fh
!= original_fh
)
2071 wwin
->flags
.maximized
&= ~(MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
2073 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
2074 wWindowSynthConfigureNotify(wwin
);
2079 WMHandleEvent(&event
);
2083 if (wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 && head
!= wGetHeadForWindow(wwin
))
2084 wArrangeIcons(scr
, True
);
2096 void wUnselectWindows(WScreen
* scr
)
2100 if (!scr
->selected_windows
)
2103 while (WMGetArrayItemCount(scr
->selected_windows
)) {
2104 wwin
= WMGetFromArray(scr
->selected_windows
, 0);
2105 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
2106 wIconSelect(wwin
->icon
);
2108 wSelectWindow(wwin
, False
);
2110 WMFreeArray(scr
->selected_windows
);
2111 scr
->selected_windows
= NULL
;
2114 static void selectWindowsInside(WScreen
* scr
, int x1
, int y1
, int x2
, int y2
)
2118 /* select the windows and put them in the selected window list */
2119 tmpw
= scr
->focused_window
;
2120 while (tmpw
!= NULL
) {
2121 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
2122 if ((tmpw
->frame
->workspace
== w_global
.workspace
.current
|| IS_OMNIPRESENT(tmpw
))
2123 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
2124 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
2125 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
2126 wSelectWindow(tmpw
, True
);
2133 void wSelectWindows(WScreen
* scr
, XEvent
* ev
)
2136 Window root
= scr
->root_win
;
2137 GC gc
= scr
->frame_gc
;
2138 int xp
= ev
->xbutton
.x_root
;
2139 int yp
= ev
->xbutton
.y_root
;
2143 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
2144 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
2145 GrabModeAsync
, None
, wPreferences
.cursor
[WCUR_NORMAL
], CurrentTime
) != Success
) {
2150 wUnselectWindows(scr
);
2152 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
2154 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
| ButtonPressMask
, &event
);
2156 switch (event
.type
) {
2158 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2159 x
= event
.xmotion
.x_root
;
2166 y
= event
.xmotion
.y_root
;
2173 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2180 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2183 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2185 XUngrabPointer(dpy
, CurrentTime
);
2186 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
2190 WMHandleEvent(&event
);
2196 void InteractivePlaceWindow(WWindow
* wwin
, int *x_ret
, int *y_ret
, unsigned width
, unsigned height
)
2198 WScreen
*scr
= wwin
->screen_ptr
;
2199 Window root
= scr
->root_win
;
2202 KeyCode shiftl
, shiftr
;
2206 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2207 GrabModeAsync
, GrabModeAsync
, None
, wPreferences
.cursor
[WCUR_NORMAL
], CurrentTime
) != Success
) {
2212 if (HAS_TITLEBAR(wwin
)) {
2213 h
= WMFontHeight(scr
->title_font
) + (wPreferences
.window_title_clearance
+
2214 TITLEBAR_EXTEND_SPACE
) * 2;
2216 if (h
> wPreferences
.window_title_max_height
)
2217 h
= wPreferences
.window_title_max_height
;
2219 if (h
< wPreferences
.window_title_min_height
)
2220 h
= wPreferences
.window_title_min_height
;
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
);