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"
40 #include "placement.h"
46 #include <WINGs/WINGsP.h>
48 /* How many different types of geometry/position
49 display thingies are there? */
50 #define NUM_DISPLAYS 5
54 #define HORIZONTAL (LEFT|RIGHT)
57 #define VERTICAL (UP|DOWN)
59 /* True if window currently has a border. This also includes borderless
60 * windows which are currently selected
62 #define HAS_BORDER_WITH_SELECT(w) ((w)->flags.selected || HAS_BORDER(w))
64 /****** Global Variables ******/
65 extern Cursor wCursor
[WCUR_LAST
];
66 extern WPreferences wPreferences
;
69 *----------------------------------------------------------------------
70 * checkMouseSamplingRate-
71 * For lowering the mouse motion sampling rate for machines where
72 * it's too high (SGIs). If it returns False then the event should be
74 *----------------------------------------------------------------------
76 static Bool
checkMouseSamplingRate(XEvent
* ev
)
78 static Time previousMotion
= 0;
80 if (ev
->type
== MotionNotify
) {
81 if (ev
->xmotion
.time
- previousMotion
< DELAY_BETWEEN_MOUSE_SAMPLING
) {
84 previousMotion
= ev
->xmotion
.time
;
91 *----------------------------------------------------------------------
92 * moveGeometryDisplayCentered
94 * routine that moves the geometry/position window on scr so it is
95 * centered over the given coordinates (x,y). Also the window position
96 * is clamped so it stays on the screen at all times.
97 *----------------------------------------------------------------------
99 static void moveGeometryDisplayCentered(WScreen
* scr
, int x
, int y
)
101 unsigned int w
= WMWidgetWidth(scr
->gview
);
102 unsigned int h
= WMWidgetHeight(scr
->gview
);
103 int x1
= 0, y1
= 0, x2
= scr
->scr_width
, y2
= scr
->scr_height
;
108 /* dead area check */
109 if (scr
->xine_info
.count
) {
116 rect
.size
.height
= h
;
118 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
120 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
121 rect
= wGetRectForHead(scr
, head
);
124 x2
= x1
+ rect
.size
.width
;
125 y2
= y1
+ rect
.size
.height
;
131 else if (x
> (x2
- w
))
136 else if (y
> (y2
- h
))
139 WMMoveWidget(scr
->gview
, x
, y
);
142 static void showPosition(WWindow
* wwin
, int x
, int y
)
144 WScreen
*scr
= wwin
->screen_ptr
;
146 if (wPreferences
.move_display
== WDIS_NEW
) {
148 int width
= wwin
->frame
->core
->width
;
149 int height
= wwin
->frame
->core
->height
;
151 GC lgc
= scr
->line_gc
;
152 XSetForeground(dpy
, lgc
, scr
->line_pixel
);
153 sprintf(num
, "%i", x
);
155 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
- 1, scr
->scr_width
, y
- 1);
156 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
+ height
+ 2, scr
->scr_width
, y
+ height
+ 2);
157 XDrawLine(dpy
, scr
->root_win
, lgc
, x
- 1, 0, x
- 1, scr
->scr_height
);
158 XDrawLine(dpy
, scr
->root_win
, lgc
, x
+ width
+ 2, 0, x
+ width
+ 2, scr
->scr_height
);
161 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
165 static void cyclePositionDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
)
167 WScreen
*scr
= wwin
->screen_ptr
;
170 wPreferences
.move_display
++;
171 wPreferences
.move_display
%= NUM_DISPLAYS
;
173 if (wPreferences
.move_display
== WDIS_NEW
) {
174 wPreferences
.move_display
++;
175 wPreferences
.move_display
%= NUM_DISPLAYS
;
178 if (wPreferences
.move_display
== WDIS_NONE
) {
179 WMUnmapWidget(scr
->gview
);
181 if (wPreferences
.move_display
== WDIS_CENTER
) {
182 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
183 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
184 rect
.pos
.y
+ rect
.size
.height
/ 2);
185 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
186 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
187 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
188 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
189 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
191 WMMapWidget(scr
->gview
);
195 static void mapPositionDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
)
197 WScreen
*scr
= wwin
->screen_ptr
;
200 if (wPreferences
.move_display
== WDIS_NEW
|| wPreferences
.move_display
== WDIS_NONE
) {
202 } else if (wPreferences
.move_display
== WDIS_CENTER
) {
203 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
204 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
205 rect
.pos
.y
+ rect
.size
.height
/ 2);
206 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
207 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
208 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
209 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
210 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
212 WMMapWidget(scr
->gview
);
213 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
216 static void showGeometry(WWindow
* wwin
, int x1
, int y1
, int x2
, int y2
, int direction
)
218 WScreen
*scr
= wwin
->screen_ptr
;
219 Window root
= scr
->root_win
;
220 GC gc
= scr
->line_gc
;
221 int ty
, by
, my
, x
, y
, mx
, s
;
226 /* This seems necessary for some odd reason (too lazy to write x1-1 and
227 * x2-1 everywhere below in the code). But why only for x? */
231 if (HAS_BORDER_WITH_SELECT(wwin
)) {
232 x1
+= scr
->frame_border_width
;
233 x2
+= scr
->frame_border_width
;
234 y1
+= scr
->frame_border_width
;
235 y2
+= scr
->frame_border_width
;
238 ty
= y1
+ wwin
->frame
->top_width
;
239 by
= y2
- wwin
->frame
->bottom_width
;
241 if (wPreferences
.size_display
== WDIS_NEW
) {
242 fw
= XTextWidth(scr
->tech_draw_font
, "8888", 4);
243 fh
= scr
->tech_draw_font
->ascent
+ scr
->tech_draw_font
->descent
;
245 XSetForeground(dpy
, gc
, scr
->line_pixel
);
247 /* vertical geometry */
248 if (((direction
& LEFT
) && (x2
< scr
->scr_width
- fw
)) || (x1
< fw
)) {
257 /* top arrow & end bar */
258 segment
[0].x1
= x
- (s
+ 6);
260 segment
[0].x2
= x
- (s
- 10);
264 segment
[1].x1
= x
- (s
- 2);
265 segment
[1].y1
= ty
+ 1;
266 segment
[1].x2
= x
- (s
- 5);
267 segment
[1].y2
= ty
+ 7;
269 segment
[2].x1
= x
- (s
- 2);
270 segment
[2].y1
= ty
+ 1;
271 segment
[2].x2
= x
- (s
+ 1);
272 segment
[2].y2
= ty
+ 7;
275 segment
[3].x1
= x
- (s
- 2);
276 segment
[3].y1
= ty
+ 1;
277 segment
[3].x2
= x
- (s
- 2);
278 segment
[3].y2
= my
- fh
/ 2 - 1;
280 XDrawSegments(dpy
, root
, gc
, segment
, 4);
282 /* bottom arrow & end bar */
287 segment
[1].y1
= by
- 1;
288 segment
[1].y2
= by
- 7;
290 segment
[2].y1
= by
- 1;
291 segment
[2].y2
= by
- 7;
294 segment
[3].y1
= my
+ fh
/ 2 + 2;
295 segment
[3].y2
= by
- 1;
297 XDrawSegments(dpy
, root
, gc
, segment
, 4);
299 snprintf(num
, sizeof(num
), "%i", (by
- ty
- wwin
->normal_hints
->base_height
) /
300 wwin
->normal_hints
->height_inc
);
301 fw
= XTextWidth(scr
->tech_draw_font
, num
, strlen(num
));
303 /* Display the height. */
304 XSetFont(dpy
, gc
, scr
->tech_draw_font
->fid
);
305 XDrawString(dpy
, root
, gc
, x
- s
+ 3 - fw
/ 2, my
+ scr
->tech_draw_font
->ascent
- fh
/ 2 + 1, num
,
308 /* horizontal geometry */
316 mx
= x1
+ (x2
- x1
) / 2;
317 snprintf(num
, sizeof(num
), "%i", (x2
- x1
- wwin
->normal_hints
->base_width
) /
318 wwin
->normal_hints
->width_inc
);
319 fw
= XTextWidth(scr
->tech_draw_font
, num
, strlen(num
));
321 /* left arrow & end bar */
323 segment
[0].y1
= y
- (s
+ 6);
325 segment
[0].y2
= y
- (s
- 10);
328 segment
[1].x1
= x1
+ 7;
329 segment
[1].y1
= y
- (s
+ 1);
330 segment
[1].x2
= x1
+ 1;
331 segment
[1].y2
= y
- (s
- 2);
333 segment
[2].x1
= x1
+ 1;
334 segment
[2].y1
= y
- (s
- 2);
335 segment
[2].x2
= x1
+ 7;
336 segment
[2].y2
= y
- (s
- 5);
339 segment
[3].x1
= x1
+ 1;
340 segment
[3].y1
= y
- (s
- 2);
341 segment
[3].x2
= mx
- fw
/ 2 - 2;
342 segment
[3].y2
= y
- (s
- 2);
344 XDrawSegments(dpy
, root
, gc
, segment
, 4);
346 /* right arrow & end bar */
347 segment
[0].x1
= x2
+ 1;
348 segment
[0].x2
= x2
+ 1;
351 segment
[1].x1
= x2
- 6;
355 segment
[2].x2
= x2
- 6;
358 segment
[3].x1
= mx
+ fw
/ 2 + 2;
361 XDrawSegments(dpy
, root
, gc
, segment
, 4);
363 /* Display the width. */
364 XDrawString(dpy
, root
, gc
, mx
- fw
/ 2 + 1, y
- s
+ scr
->tech_draw_font
->ascent
- fh
/ 2 + 1, num
,
367 WSetGeometryViewShownSize(scr
->gview
, (x2
- x1
- wwin
->normal_hints
->base_width
)
368 / wwin
->normal_hints
->width_inc
,
369 (by
- ty
- wwin
->normal_hints
->base_height
)
370 / wwin
->normal_hints
->height_inc
);
374 static void cycleGeometryDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
, int dir
)
376 WScreen
*scr
= wwin
->screen_ptr
;
379 wPreferences
.size_display
++;
380 wPreferences
.size_display
%= NUM_DISPLAYS
;
382 if (wPreferences
.size_display
== WDIS_NEW
|| wPreferences
.size_display
== WDIS_NONE
) {
383 WMUnmapWidget(scr
->gview
);
385 if (wPreferences
.size_display
== WDIS_CENTER
) {
386 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
387 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
388 rect
.pos
.y
+ rect
.size
.height
/ 2);
389 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
390 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
391 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
392 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
393 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
395 WMMapWidget(scr
->gview
);
396 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, dir
);
400 static void mapGeometryDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
)
402 WScreen
*scr
= wwin
->screen_ptr
;
405 if (wPreferences
.size_display
== WDIS_NEW
|| wPreferences
.size_display
== WDIS_NONE
)
408 if (wPreferences
.size_display
== WDIS_CENTER
) {
409 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
410 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
411 rect
.pos
.y
+ rect
.size
.height
/ 2);
412 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
413 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
414 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
415 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
416 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
418 WMMapWidget(scr
->gview
);
419 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, 0);
422 static void doWindowMove(WWindow
* wwin
, WMArray
* array
, int dx
, int dy
)
425 WScreen
*scr
= wwin
->screen_ptr
;
428 if (!array
|| !WMGetArrayItemCount(array
)) {
429 wWindowMove(wwin
, wwin
->frame_x
+ dx
, wwin
->frame_y
+ dy
);
431 WMArrayIterator iter
;
433 WM_ITERATE_ARRAY(array
, tmpw
, iter
) {
434 x
= tmpw
->frame_x
+ dx
;
435 y
= tmpw
->frame_y
+ dy
;
437 #if 1 /* XXX: with xinerama patch was #if 0, check this */
438 /* don't let windows become unreachable */
440 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
441 x
= 20 - (int)tmpw
->frame
->core
->width
;
442 else if (x
+ 20 > scr
->scr_width
)
443 x
= scr
->scr_width
- 20;
445 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
446 y
= 20 - (int)tmpw
->frame
->core
->height
;
447 else if (y
+ 20 > scr
->scr_height
)
448 y
= scr
->scr_height
- 20;
450 wScreenBringInside(scr
, &x
, &y
,
451 (int)tmpw
->frame
->core
->width
, (int)tmpw
->frame
->core
->height
);
454 wWindowMove(tmpw
, x
, y
);
459 static void drawTransparentFrame(WWindow
* wwin
, int x
, int y
, int width
, int height
)
461 Window root
= wwin
->screen_ptr
->root_win
;
462 GC gc
= wwin
->screen_ptr
->frame_gc
;
466 if (HAS_BORDER_WITH_SELECT(wwin
)) {
467 x
+= wwin
->screen_ptr
->frame_border_width
;
468 y
+= wwin
->screen_ptr
->frame_border_width
;
471 if (HAS_TITLEBAR(wwin
) && !wwin
->flags
.shaded
) {
472 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + (wPreferences
.window_title_clearance
+
473 TITLEBAR_EXTEND_SPACE
) * 2;
475 if (h
> wPreferences
.window_title_max_height
)
476 h
= wPreferences
.window_title_max_height
;
478 if (h
< wPreferences
.window_title_min_height
)
479 h
= wPreferences
.window_title_min_height
;
481 if (HAS_RESIZEBAR(wwin
) && !wwin
->flags
.shaded
) {
482 /* Can't use wwin-frame->bottom_width because, in some cases
483 (e.g. interactive placement), frame does not point to anything. */
484 bottom
= RESIZEBAR_HEIGHT
;
486 XDrawRectangle(dpy
, root
, gc
, x
- 1, y
- 1, width
+ 1, height
+ 1);
489 XDrawLine(dpy
, root
, gc
, x
, y
+ h
- 1, x
+ width
, y
+ h
- 1);
492 XDrawLine(dpy
, root
, gc
, x
, y
+ height
- bottom
, x
+ width
, y
+ height
- bottom
);
496 static void drawFrames(WWindow
* wwin
, WMArray
* array
, int dx
, int dy
)
499 int scr_width
= wwin
->screen_ptr
->scr_width
;
500 int scr_height
= wwin
->screen_ptr
->scr_height
;
505 x
= wwin
->frame_x
+ dx
;
506 y
= wwin
->frame_y
+ dy
;
508 drawTransparentFrame(wwin
, x
, y
, wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
511 WMArrayIterator iter
;
513 WM_ITERATE_ARRAY(array
, tmpw
, iter
) {
514 x
= tmpw
->frame_x
+ dx
;
515 y
= tmpw
->frame_y
+ dy
;
517 /* don't let windows become unreachable */
518 #if 1 /* XXX: was 0 in XINERAMA patch, check */
519 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
520 x
= 20 - (int)tmpw
->frame
->core
->width
;
521 else if (x
+ 20 > scr_width
)
524 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
525 y
= 20 - (int)tmpw
->frame
->core
->height
;
526 else if (y
+ 20 > scr_height
)
530 wScreenBringInside(wwin
->screen_ptr
, &x
, &y
,
531 (int)tmpw
->frame
->core
->width
, (int)tmpw
->frame
->core
->height
);
534 drawTransparentFrame(tmpw
, x
, y
, tmpw
->frame
->core
->width
, tmpw
->frame
->core
->height
);
539 static void flushMotion(void)
544 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &ev
)) ;
547 static void crossWorkspace(WScreen
* scr
, WWindow
* wwin
, int opaque_move
, int new_workspace
, int rewind
)
549 /* do not let window be unmapped */
551 wwin
->flags
.changing_workspace
= 1;
552 wWindowChangeWorkspace(wwin
, new_workspace
);
554 /* go to new workspace */
555 wWorkspaceChange(scr
, new_workspace
);
557 wwin
->flags
.changing_workspace
= 0;
560 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, scr
->scr_width
- 20, 0);
562 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, -(scr
->scr_width
- 20), 0);
567 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
568 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
569 GrabModeAsync
, None
, wCursor
[WCUR_MOVE
], CurrentTime
);
574 /* arrays of WWindows sorted by the respective border position */
575 WWindow
**topList
; /* top border */
576 WWindow
**leftList
; /* left border */
577 WWindow
**rightList
; /* right border */
578 WWindow
**bottomList
; /* bottom border */
581 /* index of window in the above lists indicating the relative position
582 * of the window with the others */
588 int rubCount
; /* for workspace switching */
590 int winWidth
, winHeight
; /* width/height of the window */
591 int realX
, realY
; /* actual position of the window */
592 int calcX
, calcY
; /* calculated position of window */
593 int omouseX
, omouseY
; /* old mouse position */
594 int mouseX
, mouseY
; /* last known position of the pointer */
597 #define WTOP(w) (w)->frame_y
598 #define WLEFT(w) (w)->frame_x
599 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width - 1 + \
600 (HAS_BORDER_WITH_SELECT(w) ? 2*(w)->screen_ptr->frame_border_width : 0))
601 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height - 1 + \
602 (HAS_BORDER_WITH_SELECT(w) ? 2*(w)->screen_ptr->frame_border_width : 0))
604 static int compareWTop(const void *a
, const void *b
)
606 WWindow
*wwin1
= *(WWindow
**) a
;
607 WWindow
*wwin2
= *(WWindow
**) b
;
609 if (WTOP(wwin1
) > WTOP(wwin2
))
611 else if (WTOP(wwin1
) < WTOP(wwin2
))
617 static int compareWLeft(const void *a
, const void *b
)
619 WWindow
*wwin1
= *(WWindow
**) a
;
620 WWindow
*wwin2
= *(WWindow
**) b
;
622 if (WLEFT(wwin1
) > WLEFT(wwin2
))
624 else if (WLEFT(wwin1
) < WLEFT(wwin2
))
630 static int compareWRight(const void *a
, const void *b
)
632 WWindow
*wwin1
= *(WWindow
**) a
;
633 WWindow
*wwin2
= *(WWindow
**) b
;
635 if (WRIGHT(wwin1
) < WRIGHT(wwin2
))
637 else if (WRIGHT(wwin1
) > WRIGHT(wwin2
))
643 static int compareWBottom(const void *a
, const void *b
)
645 WWindow
*wwin1
= *(WWindow
**) a
;
646 WWindow
*wwin2
= *(WWindow
**) b
;
648 if (WBOTTOM(wwin1
) < WBOTTOM(wwin2
))
650 else if (WBOTTOM(wwin1
) > WBOTTOM(wwin2
))
656 static void updateResistance(WWindow
* wwin
, MoveData
* data
, int newX
, int newY
)
659 int newX2
= newX
+ data
->winWidth
;
660 int newY2
= newY
+ data
->winHeight
;
663 if (newX
< data
->realX
) {
664 if (data
->rightIndex
> 0 && newX
< WRIGHT(data
->rightList
[data
->rightIndex
- 1])) {
666 } else if (data
->leftIndex
<= data
->count
- 1 && newX2
<= WLEFT(data
->leftList
[data
->leftIndex
])) {
669 } else if (newX
> data
->realX
) {
670 if (data
->leftIndex
> 0 && newX2
> WLEFT(data
->leftList
[data
->leftIndex
- 1])) {
672 } else if (data
->rightIndex
<= data
->count
- 1
673 && newX
>= WRIGHT(data
->rightList
[data
->rightIndex
])) {
679 if (newY
< data
->realY
) {
680 if (data
->bottomIndex
> 0 && newY
< WBOTTOM(data
->bottomList
[data
->bottomIndex
- 1])) {
682 } else if (data
->topIndex
<= data
->count
- 1
683 && newY2
<= WTOP(data
->topList
[data
->topIndex
])) {
686 } else if (newY
> data
->realY
) {
687 if (data
->topIndex
> 0 && newY2
> WTOP(data
->topList
[data
->topIndex
- 1])) {
689 } else if (data
->bottomIndex
<= data
->count
- 1
690 && newY
>= WBOTTOM(data
->bottomList
[data
->bottomIndex
])) {
699 /* TODO: optimize this */
700 if (data
->realY
< WBOTTOM(data
->bottomList
[0])) {
701 data
->bottomIndex
= 0;
703 if (data
->realX
< WRIGHT(data
->rightList
[0])) {
704 data
->rightIndex
= 0;
706 if ((data
->realX
+ data
->winWidth
) > WLEFT(data
->leftList
[0])) {
709 if ((data
->realY
+ data
->winHeight
) > WTOP(data
->topList
[0])) {
712 for (i
= 0; i
< data
->count
; i
++) {
713 if (data
->realY
> WBOTTOM(data
->bottomList
[i
])) {
714 data
->bottomIndex
= i
+ 1;
716 if (data
->realX
> WRIGHT(data
->rightList
[i
])) {
717 data
->rightIndex
= i
+ 1;
719 if ((data
->realX
+ data
->winWidth
) < WLEFT(data
->leftList
[i
])) {
720 data
->leftIndex
= i
+ 1;
722 if ((data
->realY
+ data
->winHeight
) < WTOP(data
->topList
[i
])) {
723 data
->topIndex
= i
+ 1;
728 static void freeMoveData(MoveData
* data
)
731 wfree(data
->topList
);
733 wfree(data
->leftList
);
735 wfree(data
->rightList
);
736 if (data
->bottomList
)
737 wfree(data
->bottomList
);
740 static void updateMoveData(WWindow
* wwin
, MoveData
* data
)
742 WScreen
*scr
= wwin
->screen_ptr
;
747 tmp
= scr
->focused_window
;
749 if (tmp
!= wwin
&& scr
->current_workspace
== tmp
->frame
->workspace
750 && !tmp
->flags
.miniaturized
751 && !tmp
->flags
.hidden
&& !tmp
->flags
.obscured
&& !WFLAGP(tmp
, sunken
)) {
752 data
->topList
[data
->count
] = tmp
;
753 data
->leftList
[data
->count
] = tmp
;
754 data
->rightList
[data
->count
] = tmp
;
755 data
->bottomList
[data
->count
] = tmp
;
761 if (data
->count
== 0) {
764 data
->rightIndex
= 0;
765 data
->bottomIndex
= 0;
769 /* order from closest to the border of the screen to farthest */
771 qsort(data
->topList
, data
->count
, sizeof(WWindow
**), compareWTop
);
772 qsort(data
->leftList
, data
->count
, sizeof(WWindow
**), compareWLeft
);
773 qsort(data
->rightList
, data
->count
, sizeof(WWindow
**), compareWRight
);
774 qsort(data
->bottomList
, data
->count
, sizeof(WWindow
**), compareWBottom
);
776 /* figure the position of the window relative to the others */
779 data
->leftIndex
= -1;
780 data
->rightIndex
= -1;
781 data
->bottomIndex
= -1;
783 if (WTOP(wwin
) < WBOTTOM(data
->bottomList
[0])) {
784 data
->bottomIndex
= 0;
786 if (WLEFT(wwin
) < WRIGHT(data
->rightList
[0])) {
787 data
->rightIndex
= 0;
789 if (WRIGHT(wwin
) > WLEFT(data
->leftList
[0])) {
792 if (WBOTTOM(wwin
) > WTOP(data
->topList
[0])) {
795 for (i
= 0; i
< data
->count
; i
++) {
796 if (WTOP(wwin
) >= WBOTTOM(data
->bottomList
[i
])) {
797 data
->bottomIndex
= i
+ 1;
799 if (WLEFT(wwin
) >= WRIGHT(data
->rightList
[i
])) {
800 data
->rightIndex
= i
+ 1;
802 if (WRIGHT(wwin
) <= WLEFT(data
->leftList
[i
])) {
803 data
->leftIndex
= i
+ 1;
805 if (WBOTTOM(wwin
) <= WTOP(data
->topList
[i
])) {
806 data
->topIndex
= i
+ 1;
811 static void initMoveData(WWindow
* wwin
, MoveData
* data
)
816 memset(data
, 0, sizeof(MoveData
));
818 for (i
= 0, tmp
= wwin
->screen_ptr
->focused_window
; tmp
!= NULL
; tmp
= tmp
->prev
, i
++) ;
821 data
->topList
= wmalloc(sizeof(WWindow
*) * i
);
822 data
->leftList
= wmalloc(sizeof(WWindow
*) * i
);
823 data
->rightList
= wmalloc(sizeof(WWindow
*) * i
);
824 data
->bottomList
= wmalloc(sizeof(WWindow
*) * i
);
826 updateMoveData(wwin
, data
);
829 data
->realX
= wwin
->frame_x
;
830 data
->realY
= wwin
->frame_y
;
831 data
->calcX
= wwin
->frame_x
;
832 data
->calcY
= wwin
->frame_y
;
834 data
->winWidth
= wwin
->frame
->core
->width
+ (HAS_BORDER_WITH_SELECT(wwin
) ? 2 * wwin
->screen_ptr
->frame_border_width
: 0);
835 data
->winHeight
= wwin
->frame
->core
->height
+ (HAS_BORDER_WITH_SELECT(wwin
) ? 2 * wwin
->screen_ptr
->frame_border_width
: 0);
838 static Bool
checkWorkspaceChange(WWindow
* wwin
, MoveData
* data
, Bool opaqueMove
)
840 WScreen
*scr
= wwin
->screen_ptr
;
841 Bool changed
= False
;
843 if (data
->mouseX
<= 1) {
844 if (scr
->current_workspace
> 0) {
846 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
- 1, True
);
850 } else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
) {
852 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->workspace_count
- 1, True
);
856 } else if (data
->mouseX
>= scr
->scr_width
- 2) {
858 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
860 if (wPreferences
.ws_cycle
|| scr
->workspace_count
== MAX_WORKSPACES
) {
862 crossWorkspace(scr
, wwin
, opaqueMove
, 0, False
);
866 /* if user insists on trying to go to next workspace even when
867 * it's already the last, create a new one */
868 else if (data
->omouseX
== data
->mouseX
&& wPreferences
.ws_advance
) {
870 /* detect user "rubbing" the window against the edge */
871 if (data
->rubCount
> 0 && data
->omouseY
- data
->mouseY
> MOVE_THRESHOLD
) {
873 data
->rubCount
= -(data
->rubCount
+ 1);
875 } else if (data
->rubCount
<= 0 && data
->mouseY
- data
->omouseY
> MOVE_THRESHOLD
) {
877 data
->rubCount
= -data
->rubCount
+ 1;
880 /* create a new workspace */
881 if (abs(data
->rubCount
) > 2) {
882 /* go to next workspace */
885 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
+ 1, False
);
889 } else if (scr
->current_workspace
< scr
->workspace_count
) {
891 /* go to next workspace */
892 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
+ 1, False
);
904 updateWindowPosition(WWindow
* wwin
, MoveData
* data
, Bool doResistance
,
905 Bool opaqueMove
, int newMouseX
, int newMouseY
)
907 WScreen
*scr
= wwin
->screen_ptr
;
908 int dx
, dy
; /* how much mouse moved */
909 int winL
, winR
, winT
, winB
; /* requested new window position */
910 int newX
, newY
; /* actual new window position */
911 Bool hresist
, vresist
;
917 /* check the direction of the movement */
918 dx
= newMouseX
- data
->mouseX
;
919 dy
= newMouseY
- data
->mouseY
;
921 data
->omouseX
= data
->mouseX
;
922 data
->omouseY
= data
->mouseY
;
923 data
->mouseX
= newMouseX
;
924 data
->mouseY
= newMouseY
;
926 winL
= data
->calcX
+ dx
;
927 winR
= data
->calcX
+ data
->winWidth
+ dx
;
928 winT
= data
->calcY
+ dy
;
929 winB
= data
->calcY
+ data
->winHeight
+ dy
;
941 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
942 attract
= wPreferences
.attract
;
943 /* horizontal movement: check horizontal edge resistances */
947 /* window is the leftmost window: check against screen edge */
949 /* Add inter head resistance 1/2 (if needed) */
950 head
= wGetHeadForPointerLocation(scr
);
951 rect
= wGetRectForHead(scr
, head
);
953 l_edge
= WMAX(scr
->totalUsableArea
[head
].x1
, rect
.pos
.x
);
954 edge_l
= l_edge
- resist
;
955 edge_r
= WMIN(scr
->totalUsableArea
[head
].x2
, rect
.pos
.x
+ rect
.size
.width
);
956 r_edge
= edge_r
+ resist
;
959 if ((data
->rightIndex
>= 0) && (data
->rightIndex
<= data
->count
)) {
962 for (i
= data
->rightIndex
- 1; i
>= 0; i
--) {
963 looprw
= data
->rightList
[i
];
964 if (!(data
->realY
> WBOTTOM(looprw
)
965 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
966 if (attract
|| ((data
->realX
< (WRIGHT(looprw
) + 2)) && dx
< 0)) {
967 l_edge
= WRIGHT(looprw
) + 1;
968 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
975 for (i
= data
->rightIndex
; i
< data
->count
; i
++) {
976 looprw
= data
->rightList
[i
];
977 if (!(data
->realY
> WBOTTOM(looprw
)
978 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
979 r_edge
= WRIGHT(looprw
) + 1;
980 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
987 if ((data
->leftIndex
>= 0) && (data
->leftIndex
<= data
->count
)) {
990 for (i
= data
->leftIndex
- 1; i
>= 0; i
--) {
991 looprw
= data
->leftList
[i
];
992 if (!(data
->realY
> WBOTTOM(looprw
)
993 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
995 || (((data
->realX
+ data
->winWidth
) > (WLEFT(looprw
) - 1))
997 edge_r
= WLEFT(looprw
);
998 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1005 for (i
= data
->leftIndex
; i
< data
->count
; i
++) {
1006 looprw
= data
->leftList
[i
];
1007 if (!(data
->realY
> WBOTTOM(looprw
)
1008 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1009 edge_l
= WLEFT(looprw
);
1010 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1017 printf("%d %d\n",winL,winR);
1018 printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);
1021 if ((winL
- l_edge
) < (r_edge
- winL
)) {
1023 if ((attract
&& winL
<= l_edge
+ resist
&& winL
>= l_edge
- resist
)
1024 || (dx
< 0 && winL
<= l_edge
&& winL
>= l_edge
- resist
)) {
1030 if (resist
> 0 && attract
&& winL
>= r_edge
- resist
&& winL
<= r_edge
+ resist
) {
1036 if ((winR
- edge_l
) < (edge_r
- winR
)) {
1037 if (resist
> 0 && attract
&& winR
<= edge_l
+ resist
&& winR
>= edge_l
- resist
) {
1038 newX
= edge_l
- data
->winWidth
;
1043 if ((attract
&& winR
>= edge_r
- resist
&& winR
<= edge_r
+ resist
)
1044 || (dx
> 0 && winR
>= edge_r
&& winR
<= edge_r
+ resist
)) {
1045 newX
= edge_r
- data
->winWidth
;
1052 /* Add inter head resistance 2/2 (if needed) */
1053 t_edge
= WMAX(scr
->totalUsableArea
[head
].y1
, rect
.pos
.y
);
1054 edge_t
= t_edge
- resist
;
1055 edge_b
= WMIN(scr
->totalUsableArea
[head
].y2
, rect
.pos
.y
+ rect
.size
.height
);
1056 b_edge
= edge_b
+ resist
;
1058 if ((data
->bottomIndex
>= 0) && (data
->bottomIndex
<= data
->count
)) {
1061 for (i
= data
->bottomIndex
- 1; i
>= 0; i
--) {
1062 looprw
= data
->bottomList
[i
];
1063 if (!(data
->realX
> WRIGHT(looprw
)
1064 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1065 if (attract
|| ((data
->realY
< (WBOTTOM(looprw
) + 2)) && dy
< 0)) {
1066 t_edge
= WBOTTOM(looprw
) + 1;
1067 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1074 for (i
= data
->bottomIndex
; i
< data
->count
; i
++) {
1075 looprw
= data
->bottomList
[i
];
1076 if (!(data
->realX
> WRIGHT(looprw
)
1077 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1078 b_edge
= WBOTTOM(looprw
) + 1;
1079 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1086 if ((data
->topIndex
>= 0) && (data
->topIndex
<= data
->count
)) {
1089 for (i
= data
->topIndex
- 1; i
>= 0; i
--) {
1090 looprw
= data
->topList
[i
];
1091 if (!(data
->realX
> WRIGHT(looprw
)
1092 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1094 || (((data
->realY
+ data
->winHeight
) > (WTOP(looprw
) - 1))
1096 edge_b
= WTOP(looprw
);
1097 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1104 for (i
= data
->topIndex
; i
< data
->count
; i
++) {
1105 looprw
= data
->topList
[i
];
1106 if (!(data
->realX
> WRIGHT(looprw
)
1107 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1108 edge_t
= WTOP(looprw
);
1109 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1115 if ((winT
- t_edge
) < (b_edge
- winT
)) {
1117 if ((attract
&& winT
<= t_edge
+ resist
&& winT
>= t_edge
- resist
)
1118 || (dy
< 0 && winT
<= t_edge
&& winT
>= t_edge
- resist
)) {
1124 if (resist
> 0 && attract
&& winT
>= b_edge
- resist
&& winT
<= b_edge
+ resist
) {
1130 if ((winB
- edge_t
) < (edge_b
- winB
)) {
1131 if (resist
> 0 && attract
&& winB
<= edge_t
+ resist
&& winB
>= edge_t
- resist
) {
1132 newY
= edge_t
- data
->winHeight
;
1137 if ((attract
&& winB
>= edge_b
- resist
&& winB
<= edge_b
+ resist
)
1138 || (dy
> 0 && winB
>= edge_b
&& winB
<= edge_b
+ resist
)) {
1139 newY
= edge_b
- data
->winHeight
;
1149 /* update window position */
1153 if (((dx
> 0 && data
->calcX
- data
->realX
> 0)
1154 || (dx
< 0 && data
->calcX
- data
->realX
< 0)) && !hresist
)
1157 if (((dy
> 0 && data
->calcY
- data
->realY
> 0)
1158 || (dy
< 0 && data
->calcY
- data
->realY
< 0)) && !vresist
)
1161 if (data
->realX
!= newX
|| data
->realY
!= newY
) {
1163 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1164 showPosition(wwin
, data
->realX
, data
->realY
);
1167 doWindowMove(wwin
, scr
->selected_windows
, newX
- wwin
->frame_x
, newY
- wwin
->frame_y
);
1170 drawFrames(wwin
, scr
->selected_windows
,
1171 data
->realX
- wwin
->frame_x
, data
->realY
- wwin
->frame_y
);
1174 if (!scr
->selected_windows
&& wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
1176 moveGeometryDisplayCentered(scr
, newX
+ data
->winWidth
/ 2, newY
+ data
->winHeight
/ 2);
1181 drawFrames(wwin
, scr
->selected_windows
, newX
- wwin
->frame_x
, newY
- wwin
->frame_y
);
1184 if (!scr
->selected_windows
) {
1185 showPosition(wwin
, newX
, newY
);
1189 /* recalc relative window position */
1190 if (doResistance
&& (data
->realX
!= newX
|| data
->realY
!= newY
)) {
1191 updateResistance(wwin
, data
, newX
, newY
);
1198 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1200 #define MOVABLE_BIT 0x01
1201 #define RESIZABLE_BIT 0x02
1203 int wKeyboardMoveResizeWindow(WWindow
* wwin
)
1205 WScreen
*scr
= wwin
->screen_ptr
;
1206 Window root
= scr
->root_win
;
1208 int w
= wwin
->frame
->core
->width
;
1209 int h
= wwin
->frame
->core
->height
;
1210 int scr_width
= wwin
->screen_ptr
->scr_width
;
1211 int scr_height
= wwin
->screen_ptr
->scr_height
;
1212 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1213 int src_x
= wwin
->frame_x
;
1214 int src_y
= wwin
->frame_y
;
1217 int done
, off_x
, off_y
, ww
, wh
;
1219 int opaqueMoveResize
= wPreferences
.opaque_move_resize_keyboard
;
1221 KeyCode shiftl
, shiftr
, ctrlmode
;
1222 KeySym keysym
= NoSymbol
;
1224 int modes
= ((IS_MOVABLE(wwin
) ? MOVABLE_BIT
: 0) | (IS_RESIZABLE(wwin
) ? RESIZABLE_BIT
: 0));
1225 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1226 ? wGetHeadForWindow(wwin
)
1227 : scr
->xine_info
.primary_head
);
1229 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1230 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1231 ctrlmode
= done
= off_x
= off_y
= 0;
1233 if (modes
== RESIZABLE_BIT
) {
1239 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1241 if (!wwin
->flags
.selected
) {
1242 wUnselectWindows(scr
);
1245 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1246 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
1247 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
);
1251 if (!opaqueMoveResize
) {
1252 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1253 if (scr
->selected_windows
)
1254 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1256 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1258 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1261 if ((wwin
->flags
.shaded
|| scr
->selected_windows
) && (!scr
->selected_windows
)) {
1262 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1273 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1274 | ButtonPressMask
| ExposureMask
, &event
);
1275 if (event
.type
== Expose
) {
1276 WMHandleEvent(&event
);
1278 } while (event
.type
== Expose
);
1280 if (!opaqueMoveResize
) {
1281 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1282 if (scr
->selected_windows
)
1283 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1285 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1286 /*** I HATE EDGE RESISTANCE - ]d ***/
1288 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1293 showGeometry(wwin
, src_x
+ off_x
, src_y
+ off_y
, src_x
+ off_x
+ ww
, src_y
+ off_y
+ wh
,
1299 switch (event
.type
) {
1302 if (event
.xkey
.time
- lastTime
> 50) {
1303 kspeed
/= (1 + (event
.xkey
.time
- lastTime
) / 100);
1311 lastTime
= event
.xkey
.time
;
1312 if (modes
== (MOVABLE_BIT
| RESIZABLE_BIT
)) {
1313 if ((event
.xkey
.state
& ControlMask
) && !wwin
->flags
.shaded
) {
1315 wUnselectWindows(scr
);
1320 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
) {
1322 cycleGeometryDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
, 0);
1324 cyclePositionDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1327 keysym
= XLookupKeysym(&event
.xkey
, 0);
1384 if (moment
!= RIGHT
)
1396 wWindowConstrainSize(wwin
, (unsigned int *)&ww
, (unsigned int *)&wh
);
1399 if (wPreferences
.ws_cycle
) {
1400 if (src_x
+ off_x
+ ww
< 20) {
1401 if (!scr
->current_workspace
) {
1402 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
1404 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
1406 } else if (src_x
+ off_x
+ 20 > scr_width
) {
1407 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
1408 wWorkspaceChange(scr
, 0);
1410 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
1414 if (src_x
+ off_x
+ ww
< 20)
1415 off_x
= 20 - ww
- src_x
;
1416 else if (src_x
+ off_x
+ 20 > scr_width
)
1417 off_x
= scr_width
- 20 - src_x
;
1420 if (src_y
+ off_y
+ wh
< 20) {
1421 off_y
= 20 - wh
- src_y
;
1422 } else if (src_y
+ off_y
+ 20 > scr_height
) {
1423 off_y
= scr_height
- 20 - src_y
;
1432 WMHandleEvent(&event
);
1433 while (XCheckTypedEvent(dpy
, Expose
, &event
)) {
1434 WMHandleEvent(&event
);
1439 WMHandleEvent(&event
);
1446 if (wwin
->flags
.shaded
&& !scr
->selected_windows
) {
1447 moveGeometryDisplayCentered(scr
, src_x
+ off_x
+ w
/ 2, src_y
+ off_y
+ h
/ 2);
1450 WMUnmapWidget(scr
->gview
);
1451 mapGeometryDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1452 } else if (!scr
->selected_windows
) {
1453 WMUnmapWidget(scr
->gview
);
1454 mapPositionDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1458 if (!opaqueMoveResize
) {
1459 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1460 if (scr
->selected_windows
)
1461 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1463 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1465 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1470 showGeometry(wwin
, src_x
+ off_x
, src_y
+ off_y
, src_x
+ off_x
+ ww
, src_y
+ off_y
+ wh
,
1472 } else if (!scr
->selected_windows
)
1473 showPosition(wwin
, src_x
+ off_x
, src_y
+ off_y
);
1475 if (opaqueMoveResize
) {
1477 wWindowConfigure(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
- vert_border
);
1481 scr
->keymove_tick
= 0;
1483 WMDeleteTimerWithClientData(&looper);
1485 if (!opaqueMoveResize
) {/*ctrlmode=> resize */
1486 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1487 if (scr
->selected_windows
)
1488 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1490 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1492 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1497 showGeometry(wwin
, src_x
+ off_x
, src_y
+ off_y
, src_x
+ off_x
+ ww
,
1498 src_y
+ off_y
+ wh
, 0);
1499 WMUnmapWidget(scr
->gview
);
1501 WMUnmapWidget(scr
->gview
);
1503 XUngrabKeyboard(dpy
, CurrentTime
);
1504 XUngrabPointer(dpy
, CurrentTime
);
1508 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1509 if (!scr
->selected_windows
) {
1510 wWindowMove(wwin
, src_x
+ off_x
, src_y
+ off_y
);
1511 wWindowSynthConfigureNotify(wwin
);
1513 WMArrayIterator iter
;
1516 doWindowMove(wwin
, scr
->selected_windows
, off_x
, off_y
);
1518 WM_ITERATE_ARRAY(scr
->selected_windows
, foo
, iter
) {
1519 wWindowSynthConfigureNotify(foo
);
1523 if (ww
!= original_w
)
1524 wwin
->flags
.maximized
&= ~(MAX_HORIZONTAL
| MAX_MAXIMUS
);
1526 if (wh
!= original_h
)
1527 wwin
->flags
.maximized
&= ~(MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
1529 wWindowConfigure(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
- vert_border
);
1530 wWindowSynthConfigureNotify(wwin
);
1532 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1533 wSetFocusTo(scr
, wwin
);
1536 if (wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 &&
1537 head
!= wGetHeadForWindow(wwin
)) {
1538 wArrangeIcons(scr
, True
);
1541 update_saved_geometry(wwin
);
1549 *----------------------------------------------------------------------
1550 * wMouseMoveWindow--
1551 * Move the named window and the other selected ones (if any),
1552 * interactively. Also shows the position of the window, if only one
1553 * window is being moved.
1554 * If the window is not on the selected window list, the selected
1555 * windows are deselected.
1556 * If shift is pressed during the operation, the position display
1557 * is changed to another type.
1560 * True if the window was moved, False otherwise.
1563 * The window(s) position is changed, and the client(s) are
1564 * notified about that.
1565 * The position display configuration may be changed.
1566 *----------------------------------------------------------------------
1568 int wMouseMoveWindow(WWindow
* wwin
, XEvent
* ev
)
1570 WScreen
*scr
= wwin
->screen_ptr
;
1572 Window root
= scr
->root_win
;
1573 KeyCode shiftl
, shiftr
;
1577 /* This needs not to change while moving, else bad things can happen */
1578 int opaqueMove
= wPreferences
.opaque_move
;
1580 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1581 ? wGetHeadForWindow(wwin
)
1582 : scr
->xine_info
.primary_head
);
1584 if (!IS_MOVABLE(wwin
))
1587 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1588 XSetWindowAttributes attr
;
1590 attr
.save_under
= True
;
1591 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
, CWSaveUnder
, &attr
);
1594 initMoveData(wwin
, &moveData
);
1596 moveData
.mouseX
= ev
->xmotion
.x_root
;
1597 moveData
.mouseY
= ev
->xmotion
.y_root
;
1599 if (!wwin
->flags
.selected
) {
1600 /* this window is not selected, unselect others and move only wwin */
1601 wUnselectWindows(scr
);
1603 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1604 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1610 /* XWarpPointer() doesn't seem to generate Motion events, so
1611 * we've got to simulate them */
1612 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1613 &event
.xmotion
.y_root
, &junk
, &junk
, (unsigned *)&junk
);
1615 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1616 | PointerMotionHintMask
1617 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
, &event
);
1619 if (event
.type
== MotionNotify
) {
1620 /* compress MotionNotify events */
1621 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1622 if (!checkMouseSamplingRate(&event
))
1626 switch (event
.type
) {
1628 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1629 && started
&& !scr
->selected_windows
) {
1632 drawFrames(wwin
, scr
->selected_windows
,
1633 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1636 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1637 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1640 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1641 moveData
.winWidth
, moveData
.winHeight
);
1643 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1645 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1649 drawFrames(wwin
, scr
->selected_windows
,
1650 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1653 WMHandleEvent(&event); this causes problems needs fixing */
1659 updateWindowPosition(wwin
, &moveData
,
1660 scr
->selected_windows
== NULL
1661 && wPreferences
.edge_resistance
> 0,
1662 opaqueMove
, event
.xmotion
.x_root
, event
.xmotion
.y_root
);
1664 if (!warped
&& !wPreferences
.no_autowrap
) {
1665 int oldWorkspace
= scr
->current_workspace
;
1667 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1668 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1672 drawFrames(wwin
, scr
->selected_windows
,
1673 moveData
.realX
- wwin
->frame_x
,
1674 moveData
.realY
- wwin
->frame_y
);
1676 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1677 if (scr
->current_workspace
!= oldWorkspace
1678 && wPreferences
.edge_resistance
> 0
1679 && scr
->selected_windows
== NULL
)
1680 updateMoveData(wwin
, &moveData
);
1684 drawFrames(wwin
, scr
->selected_windows
,
1685 moveData
.realX
- wwin
->frame_x
,
1686 moveData
.realY
- wwin
->frame_y
);
1688 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1690 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1696 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1697 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1699 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1700 | ButtonReleaseMask
| ButtonPressMask
,
1701 wCursor
[WCUR_MOVE
], CurrentTime
);
1703 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1705 if (!scr
->selected_windows
)
1706 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1707 moveData
.winWidth
, moveData
.winHeight
);
1709 if (started
&& !opaqueMove
)
1710 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1712 if (!opaqueMove
|| (wPreferences
.move_display
== WDIS_NEW
1713 && !scr
->selected_windows
)) {
1715 if (wPreferences
.move_display
== WDIS_NEW
)
1716 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1725 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1731 drawFrames(wwin
, scr
->selected_windows
,
1732 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1734 doWindowMove(wwin
, scr
->selected_windows
,
1735 moveData
.realX
- wwin
->frame_x
,
1736 moveData
.realY
- wwin
->frame_y
);
1738 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1739 wWindowSynthConfigureNotify(wwin
);
1741 XUngrabKeyboard(dpy
, CurrentTime
);
1744 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1745 wSetFocusTo(scr
, wwin
);
1747 if (wPreferences
.move_display
== WDIS_NEW
)
1748 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1750 /* discard all enter/leave events that happened until
1751 * the time the button was released */
1752 while (XCheckTypedEvent(dpy
, EnterNotify
, &e
)) {
1753 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1754 XPutBackEvent(dpy
, &e
);
1758 while (XCheckTypedEvent(dpy
, LeaveNotify
, &e
)) {
1759 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1760 XPutBackEvent(dpy
, &e
);
1765 if (!scr
->selected_windows
) {
1766 /* get rid of the geometry window */
1767 WMUnmapWidget(scr
->gview
);
1774 if (started
&& !opaqueMove
) {
1775 drawFrames(wwin
, scr
->selected_windows
,
1776 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1778 WMHandleEvent(&event
);
1781 drawFrames(wwin
, scr
->selected_windows
,
1782 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1784 WMHandleEvent(&event
);
1790 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1791 XSetWindowAttributes attr
;
1793 attr
.save_under
= False
;
1794 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
, CWSaveUnder
, &attr
);
1798 freeMoveData(&moveData
);
1800 if (started
&& wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 &&
1801 head
!= wGetHeadForWindow(wwin
)) {
1802 wArrangeIcons(scr
, True
);
1806 update_saved_geometry(wwin
);
1812 #define HCONSTRAIN 2
1814 static int getResizeDirection(WWindow
* wwin
, int x
, int y
, int dx
, int dy
, int flags
)
1816 int w
= wwin
->frame
->core
->width
- 1;
1817 int cw
= wwin
->frame
->resizebar_corner_width
;
1820 /* if not resizing through the resizebar */
1821 if (!(flags
& RESIZEBAR
)) {
1822 int xdir
= (abs(x
) < (wwin
->client
.width
/ 2)) ? LEFT
: RIGHT
;
1823 int ydir
= (abs(y
) < (wwin
->client
.height
/ 2)) ? UP
: DOWN
;
1824 if (abs(dx
) < 2 || abs(dy
) < 2) {
1825 if (abs(dy
) > abs(dx
))
1830 return (xdir
| ydir
);
1833 /* window is too narrow. allow diagonal resize */
1837 if (flags
& HCONSTRAIN
)
1842 return (LEFT
| ydir
);
1844 return (RIGHT
| ydir
);
1846 /* vertical resize */
1847 if ((x
> cw
) && (x
< w
- cw
))
1855 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1861 void wMouseResizeWindow(WWindow
* wwin
, XEvent
* ev
)
1864 WScreen
*scr
= wwin
->screen_ptr
;
1865 Window root
= scr
->root_win
;
1866 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1867 int fw
= wwin
->frame
->core
->width
;
1868 int fh
= wwin
->frame
->core
->height
;
1869 int fx
= wwin
->frame_x
;
1870 int fy
= wwin
->frame_y
;
1871 int is_resizebar
= (wwin
->frame
->resizebar
&& ev
->xany
.window
== wwin
->frame
->resizebar
->window
);
1875 int rw
= fw
, rh
= fh
;
1876 int rx1
, ry1
, rx2
, ry2
;
1878 KeyCode shiftl
, shiftr
;
1883 int original_fw
= fw
;
1884 int original_fh
= fh
;
1885 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1886 ? wGetHeadForWindow(wwin
)
1887 : scr
->xine_info
.primary_head
);
1888 int opaqueResize
= wPreferences
.opaque_resize
;
1890 if (!IS_RESIZABLE(wwin
))
1893 if (wwin
->flags
.shaded
) {
1894 wwarning("internal error: tryein");
1897 orig_x
= ev
->xbutton
.x_root
;
1898 orig_y
= ev
->xbutton
.y_root
;
1901 wUnselectWindows(scr
);
1906 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1907 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1910 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1911 | ButtonReleaseMask
| PointerMotionHintMask
| ButtonPressMask
| ExposureMask
, &event
);
1912 if (!checkMouseSamplingRate(&event
))
1915 switch (event
.type
) {
1917 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1918 if (!opaqueResize
) {
1919 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1921 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1922 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
1923 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1926 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1931 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1942 dw
= orig_x
- event
.xmotion
.x_root
;
1943 else if (res
& RIGHT
)
1944 dw
= event
.xmotion
.x_root
- orig_x
;
1946 dh
= orig_y
- event
.xmotion
.y_root
;
1947 else if (res
& DOWN
)
1948 dh
= event
.xmotion
.y_root
- orig_y
;
1950 orig_x
= event
.xmotion
.x_root
;
1951 orig_y
= event
.xmotion
.y_root
;
1956 fh
= rh
- vert_border
;
1957 wWindowConstrainSize(wwin
, (unsigned int *)&fw
, (unsigned int *)&fh
);
1961 else if (res
& RIGHT
)
1965 else if (res
& DOWN
)
1967 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1968 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1973 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
1974 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
1976 /* check if resizing through resizebar */
1982 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
1983 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
1984 flags
|= HCONSTRAIN
;
1986 res
= getResizeDirection(wwin
, tx
, ty
,
1987 orig_x
- event
.xmotion
.x_root
,
1988 orig_y
- event
.xmotion
.y_root
, flags
);
1990 if (res
== (UP
| LEFT
))
1991 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1992 | ButtonReleaseMask
| ButtonPressMask
,
1993 wCursor
[WCUR_TOPLEFTRESIZE
], CurrentTime
);
1994 else if (res
== (UP
| RIGHT
))
1995 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1996 | ButtonReleaseMask
| ButtonPressMask
,
1997 wCursor
[WCUR_TOPRIGHTRESIZE
], CurrentTime
);
1998 else if (res
== (DOWN
| LEFT
))
1999 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2000 | ButtonReleaseMask
| ButtonPressMask
,
2001 wCursor
[WCUR_BOTTOMLEFTRESIZE
], CurrentTime
);
2002 else if (res
== (DOWN
| RIGHT
))
2003 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2004 | ButtonReleaseMask
| ButtonPressMask
,
2005 wCursor
[WCUR_BOTTOMRIGHTRESIZE
], CurrentTime
);
2006 else if (res
== DOWN
|| res
== UP
)
2007 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2008 | ButtonReleaseMask
| ButtonPressMask
,
2009 wCursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2010 else if (res
& (DOWN
| UP
))
2011 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2012 | ButtonReleaseMask
| ButtonPressMask
,
2013 wCursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2014 else if (res
& (LEFT
| RIGHT
))
2015 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2016 | ButtonReleaseMask
| ButtonPressMask
,
2017 wCursor
[WCUR_HORIZONRESIZE
], CurrentTime
);
2019 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2023 /* Draw the resize frame for the first time. */
2024 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
2027 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2029 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2035 drawTransparentFrame(wwin
, orig_fx
, orig_fy
, orig_fw
, orig_fh
);
2037 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
)
2038 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
2041 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2043 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
2044 if (wPreferences
.size_display
== WDIS_NEW
)
2045 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
2046 orig_fy
+ orig_fh
, res
);
2048 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2052 /* Fist clean the geometry line */
2053 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2054 /* Now, continue drawing */
2056 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
2057 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
2058 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2067 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2071 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2074 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2076 XUngrabKeyboard(dpy
, CurrentTime
);
2077 WMUnmapWidget(scr
->gview
);
2080 if (fw
!= original_fw
)
2081 wwin
->flags
.maximized
&= ~(MAX_HORIZONTAL
| MAX_MAXIMUS
);
2083 if (fh
!= original_fh
)
2084 wwin
->flags
.maximized
&= ~(MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
2086 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
2087 wWindowSynthConfigureNotify(wwin
);
2092 WMHandleEvent(&event
);
2096 if (wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 && head
!= wGetHeadForWindow(wwin
))
2097 wArrangeIcons(scr
, True
);
2109 void wUnselectWindows(WScreen
* scr
)
2113 if (!scr
->selected_windows
)
2116 while (WMGetArrayItemCount(scr
->selected_windows
)) {
2117 wwin
= WMGetFromArray(scr
->selected_windows
, 0);
2118 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
2119 wIconSelect(wwin
->icon
);
2121 wSelectWindow(wwin
, False
);
2123 WMFreeArray(scr
->selected_windows
);
2124 scr
->selected_windows
= NULL
;
2127 static void selectWindowsInside(WScreen
* scr
, int x1
, int y1
, int x2
, int y2
)
2131 /* select the windows and put them in the selected window list */
2132 tmpw
= scr
->focused_window
;
2133 while (tmpw
!= NULL
) {
2134 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
2135 if ((tmpw
->frame
->workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(tmpw
))
2136 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
2137 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
2138 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
2139 wSelectWindow(tmpw
, True
);
2146 void wSelectWindows(WScreen
* scr
, XEvent
* ev
)
2149 Window root
= scr
->root_win
;
2150 GC gc
= scr
->frame_gc
;
2151 int xp
= ev
->xbutton
.x_root
;
2152 int yp
= ev
->xbutton
.y_root
;
2156 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
2157 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
2158 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2163 wUnselectWindows(scr
);
2165 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
2167 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
| ButtonPressMask
, &event
);
2169 switch (event
.type
) {
2171 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2172 x
= event
.xmotion
.x_root
;
2179 y
= event
.xmotion
.y_root
;
2186 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2193 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2196 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2198 XUngrabPointer(dpy
, CurrentTime
);
2199 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
2203 WMHandleEvent(&event
);
2209 void InteractivePlaceWindow(WWindow
* wwin
, int *x_ret
, int *y_ret
, unsigned width
, unsigned height
)
2211 WScreen
*scr
= wwin
->screen_ptr
;
2212 Window root
= scr
->root_win
;
2215 KeyCode shiftl
, shiftr
;
2219 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2220 GrabModeAsync
, GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2225 if (HAS_TITLEBAR(wwin
)) {
2226 h
= WMFontHeight(scr
->title_font
) + (wPreferences
.window_title_clearance
+
2227 TITLEBAR_EXTEND_SPACE
) * 2;
2229 if (h
> wPreferences
.window_title_max_height
)
2230 h
= wPreferences
.window_title_max_height
;
2232 if (h
< wPreferences
.window_title_min_height
)
2233 h
= wPreferences
.window_title_min_height
;
2237 if (HAS_RESIZEBAR(wwin
)) {
2238 height
+= RESIZEBAR_HEIGHT
;
2240 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2241 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
, (unsigned *)&junk
);
2242 mapPositionDisplay(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2244 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2246 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2247 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2249 WMMaskEvent(dpy
, PointerMotionMask
| ButtonPressMask
| ExposureMask
| KeyPressMask
, &event
);
2251 if (!checkMouseSamplingRate(&event
))
2254 switch (event
.type
) {
2256 if ((event
.xkey
.keycode
== shiftl
)
2257 || (event
.xkey
.keycode
== shiftr
)) {
2258 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2259 cyclePositionDisplay(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2260 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2265 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2267 x
= event
.xmotion
.x_root
;
2268 y
= event
.xmotion
.y_root
;
2270 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2271 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2273 showPosition(wwin
, x
- width
/ 2, y
- h
/ 2);
2275 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2280 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2282 *x_ret
= x
- width
/ 2;
2284 XUngrabPointer(dpy
, CurrentTime
);
2285 XUngrabKeyboard(dpy
, CurrentTime
);
2286 /* get rid of the geometry window */
2287 WMUnmapWidget(scr
->gview
);
2291 WMHandleEvent(&event
);