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 */
592 enum {SNAP_NONE
, SNAP_LEFT
, SNAP_RIGHT
} snap
;
595 #define WTOP(w) (w)->frame_y
596 #define WLEFT(w) (w)->frame_x
597 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width - 1 + \
598 (HAS_BORDER_WITH_SELECT(w) ? 2*(w)->screen_ptr->frame_border_width : 0))
599 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height - 1 + \
600 (HAS_BORDER_WITH_SELECT(w) ? 2*(w)->screen_ptr->frame_border_width : 0))
602 static int compareWTop(const void *a
, const void *b
)
604 WWindow
*wwin1
= *(WWindow
**) a
;
605 WWindow
*wwin2
= *(WWindow
**) b
;
607 if (WTOP(wwin1
) > WTOP(wwin2
))
609 else if (WTOP(wwin1
) < WTOP(wwin2
))
615 static int compareWLeft(const void *a
, const void *b
)
617 WWindow
*wwin1
= *(WWindow
**) a
;
618 WWindow
*wwin2
= *(WWindow
**) b
;
620 if (WLEFT(wwin1
) > WLEFT(wwin2
))
622 else if (WLEFT(wwin1
) < WLEFT(wwin2
))
628 static int compareWRight(const void *a
, const void *b
)
630 WWindow
*wwin1
= *(WWindow
**) a
;
631 WWindow
*wwin2
= *(WWindow
**) b
;
633 if (WRIGHT(wwin1
) < WRIGHT(wwin2
))
635 else if (WRIGHT(wwin1
) > WRIGHT(wwin2
))
641 static int compareWBottom(const void *a
, const void *b
)
643 WWindow
*wwin1
= *(WWindow
**) a
;
644 WWindow
*wwin2
= *(WWindow
**) b
;
646 if (WBOTTOM(wwin1
) < WBOTTOM(wwin2
))
648 else if (WBOTTOM(wwin1
) > WBOTTOM(wwin2
))
654 static void updateResistance(MoveData
*data
, int newX
, int newY
)
657 int newX2
= newX
+ data
->winWidth
;
658 int newY2
= newY
+ data
->winHeight
;
661 if (newX
< data
->realX
) {
662 if (data
->rightIndex
> 0 && newX
< WRIGHT(data
->rightList
[data
->rightIndex
- 1])) {
664 } else if (data
->leftIndex
<= data
->count
- 1 && newX2
<= WLEFT(data
->leftList
[data
->leftIndex
])) {
667 } else if (newX
> data
->realX
) {
668 if (data
->leftIndex
> 0 && newX2
> WLEFT(data
->leftList
[data
->leftIndex
- 1])) {
670 } else if (data
->rightIndex
<= data
->count
- 1
671 && newX
>= WRIGHT(data
->rightList
[data
->rightIndex
])) {
677 if (newY
< data
->realY
) {
678 if (data
->bottomIndex
> 0 && newY
< WBOTTOM(data
->bottomList
[data
->bottomIndex
- 1])) {
680 } else if (data
->topIndex
<= data
->count
- 1
681 && newY2
<= WTOP(data
->topList
[data
->topIndex
])) {
684 } else if (newY
> data
->realY
) {
685 if (data
->topIndex
> 0 && newY2
> WTOP(data
->topList
[data
->topIndex
- 1])) {
687 } else if (data
->bottomIndex
<= data
->count
- 1
688 && newY
>= WBOTTOM(data
->bottomList
[data
->bottomIndex
])) {
697 /* TODO: optimize this */
698 if (data
->realY
< WBOTTOM(data
->bottomList
[0])) {
699 data
->bottomIndex
= 0;
701 if (data
->realX
< WRIGHT(data
->rightList
[0])) {
702 data
->rightIndex
= 0;
704 if ((data
->realX
+ data
->winWidth
) > WLEFT(data
->leftList
[0])) {
707 if ((data
->realY
+ data
->winHeight
) > WTOP(data
->topList
[0])) {
710 for (i
= 0; i
< data
->count
; i
++) {
711 if (data
->realY
> WBOTTOM(data
->bottomList
[i
])) {
712 data
->bottomIndex
= i
+ 1;
714 if (data
->realX
> WRIGHT(data
->rightList
[i
])) {
715 data
->rightIndex
= i
+ 1;
717 if ((data
->realX
+ data
->winWidth
) < WLEFT(data
->leftList
[i
])) {
718 data
->leftIndex
= i
+ 1;
720 if ((data
->realY
+ data
->winHeight
) < WTOP(data
->topList
[i
])) {
721 data
->topIndex
= i
+ 1;
726 static void freeMoveData(MoveData
* data
)
729 wfree(data
->topList
);
731 wfree(data
->leftList
);
733 wfree(data
->rightList
);
734 if (data
->bottomList
)
735 wfree(data
->bottomList
);
738 static void updateMoveData(WWindow
* wwin
, MoveData
* data
)
740 WScreen
*scr
= wwin
->screen_ptr
;
745 tmp
= scr
->focused_window
;
747 if (tmp
!= wwin
&& w_global
.workspace
.current
== tmp
->frame
->workspace
748 && !tmp
->flags
.miniaturized
749 && !tmp
->flags
.hidden
&& !tmp
->flags
.obscured
&& !WFLAGP(tmp
, sunken
)) {
750 data
->topList
[data
->count
] = tmp
;
751 data
->leftList
[data
->count
] = tmp
;
752 data
->rightList
[data
->count
] = tmp
;
753 data
->bottomList
[data
->count
] = tmp
;
759 if (data
->count
== 0) {
762 data
->rightIndex
= 0;
763 data
->bottomIndex
= 0;
767 /* order from closest to the border of the screen to farthest */
769 qsort(data
->topList
, data
->count
, sizeof(WWindow
**), compareWTop
);
770 qsort(data
->leftList
, data
->count
, sizeof(WWindow
**), compareWLeft
);
771 qsort(data
->rightList
, data
->count
, sizeof(WWindow
**), compareWRight
);
772 qsort(data
->bottomList
, data
->count
, sizeof(WWindow
**), compareWBottom
);
774 /* figure the position of the window relative to the others */
777 data
->leftIndex
= -1;
778 data
->rightIndex
= -1;
779 data
->bottomIndex
= -1;
781 if (WTOP(wwin
) < WBOTTOM(data
->bottomList
[0])) {
782 data
->bottomIndex
= 0;
784 if (WLEFT(wwin
) < WRIGHT(data
->rightList
[0])) {
785 data
->rightIndex
= 0;
787 if (WRIGHT(wwin
) > WLEFT(data
->leftList
[0])) {
790 if (WBOTTOM(wwin
) > WTOP(data
->topList
[0])) {
793 for (i
= 0; i
< data
->count
; i
++) {
794 if (WTOP(wwin
) >= WBOTTOM(data
->bottomList
[i
])) {
795 data
->bottomIndex
= i
+ 1;
797 if (WLEFT(wwin
) >= WRIGHT(data
->rightList
[i
])) {
798 data
->rightIndex
= i
+ 1;
800 if (WRIGHT(wwin
) <= WLEFT(data
->leftList
[i
])) {
801 data
->leftIndex
= i
+ 1;
803 if (WBOTTOM(wwin
) <= WTOP(data
->topList
[i
])) {
804 data
->topIndex
= i
+ 1;
809 static void initMoveData(WWindow
* wwin
, MoveData
* data
)
814 memset(data
, 0, sizeof(MoveData
));
816 for (i
= 0, tmp
= wwin
->screen_ptr
->focused_window
; tmp
!= NULL
; tmp
= tmp
->prev
, i
++) ;
819 data
->topList
= wmalloc(sizeof(WWindow
*) * i
);
820 data
->leftList
= wmalloc(sizeof(WWindow
*) * i
);
821 data
->rightList
= wmalloc(sizeof(WWindow
*) * i
);
822 data
->bottomList
= wmalloc(sizeof(WWindow
*) * i
);
824 updateMoveData(wwin
, data
);
827 data
->realX
= wwin
->frame_x
;
828 data
->realY
= wwin
->frame_y
;
829 data
->calcX
= wwin
->frame_x
;
830 data
->calcY
= wwin
->frame_y
;
832 data
->winWidth
= wwin
->frame
->core
->width
+ (HAS_BORDER_WITH_SELECT(wwin
) ? 2 * wwin
->screen_ptr
->frame_border_width
: 0);
833 data
->winHeight
= wwin
->frame
->core
->height
+ (HAS_BORDER_WITH_SELECT(wwin
) ? 2 * wwin
->screen_ptr
->frame_border_width
: 0);
835 data
->snap
= SNAP_NONE
;
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 (w_global
.workspace
.current
> 0) {
845 crossWorkspace(scr
, wwin
, opaqueMove
, w_global
.workspace
.current
- 1, True
);
848 } else if (w_global
.workspace
.current
== 0 && wPreferences
.ws_cycle
) {
849 crossWorkspace(scr
, wwin
, opaqueMove
, w_global
.workspace
.count
- 1, True
);
853 } else if (data
->mouseX
>= scr
->scr_width
- 2) {
854 if (w_global
.workspace
.current
== w_global
.workspace
.count
- 1) {
855 if (wPreferences
.ws_cycle
|| w_global
.workspace
.count
== MAX_WORKSPACES
) {
856 crossWorkspace(scr
, wwin
, opaqueMove
, 0, False
);
860 /* if user insists on trying to go to next workspace even when
861 * it's already the last, create a new one */
862 else if (data
->omouseX
== data
->mouseX
&& wPreferences
.ws_advance
) {
864 /* detect user "rubbing" the window against the edge */
865 if (data
->rubCount
> 0 && data
->omouseY
- data
->mouseY
> MOVE_THRESHOLD
) {
867 data
->rubCount
= -(data
->rubCount
+ 1);
869 } else if (data
->rubCount
<= 0 && data
->mouseY
- data
->omouseY
> MOVE_THRESHOLD
) {
871 data
->rubCount
= -data
->rubCount
+ 1;
874 /* create a new workspace */
875 if (abs(data
->rubCount
) > 2) {
876 /* go to next workspace */
879 crossWorkspace(scr
, wwin
, opaqueMove
, w_global
.workspace
.current
+ 1, False
);
883 } else if (w_global
.workspace
.current
< w_global
.workspace
.count
) {
884 /* go to next workspace */
885 crossWorkspace(scr
, wwin
, opaqueMove
, w_global
.workspace
.current
+ 1, False
);
897 updateWindowPosition(WWindow
* wwin
, MoveData
* data
, Bool doResistance
,
898 Bool opaqueMove
, int newMouseX
, int newMouseY
)
900 WScreen
*scr
= wwin
->screen_ptr
;
901 int dx
, dy
; /* how much mouse moved */
902 int winL
, winR
, winT
, winB
; /* requested new window position */
903 int newX
, newY
; /* actual new window position */
904 Bool hresist
, vresist
;
910 /* check the direction of the movement */
911 dx
= newMouseX
- data
->mouseX
;
912 dy
= newMouseY
- data
->mouseY
;
914 data
->omouseX
= data
->mouseX
;
915 data
->omouseY
= data
->mouseY
;
916 data
->mouseX
= newMouseX
;
917 data
->mouseY
= newMouseY
;
919 winL
= data
->calcX
+ dx
;
920 winR
= data
->calcX
+ data
->winWidth
+ dx
;
921 winT
= data
->calcY
+ dy
;
922 winB
= data
->calcY
+ data
->winHeight
+ dy
;
934 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
935 attract
= wPreferences
.attract
;
936 /* horizontal movement: check horizontal edge resistances */
940 /* window is the leftmost window: check against screen edge */
942 /* Add inter head resistance 1/2 (if needed) */
943 head
= wGetHeadForPointerLocation(scr
);
944 rect
= wGetRectForHead(scr
, head
);
946 l_edge
= WMAX(scr
->totalUsableArea
[head
].x1
, rect
.pos
.x
);
947 edge_l
= l_edge
- resist
;
948 edge_r
= WMIN(scr
->totalUsableArea
[head
].x2
, rect
.pos
.x
+ rect
.size
.width
);
949 r_edge
= edge_r
+ resist
;
952 if ((data
->rightIndex
>= 0) && (data
->rightIndex
<= data
->count
)) {
955 for (i
= data
->rightIndex
- 1; i
>= 0; i
--) {
956 looprw
= data
->rightList
[i
];
957 if (!(data
->realY
> WBOTTOM(looprw
)
958 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
959 if (attract
|| ((data
->realX
< (WRIGHT(looprw
) + 2)) && dx
< 0)) {
960 l_edge
= WRIGHT(looprw
) + 1;
961 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
968 for (i
= data
->rightIndex
; i
< data
->count
; i
++) {
969 looprw
= data
->rightList
[i
];
970 if (!(data
->realY
> WBOTTOM(looprw
)
971 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
972 r_edge
= WRIGHT(looprw
) + 1;
973 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
980 if ((data
->leftIndex
>= 0) && (data
->leftIndex
<= data
->count
)) {
983 for (i
= data
->leftIndex
- 1; i
>= 0; i
--) {
984 looprw
= data
->leftList
[i
];
985 if (!(data
->realY
> WBOTTOM(looprw
)
986 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
988 || (((data
->realX
+ data
->winWidth
) > (WLEFT(looprw
) - 1))
990 edge_r
= WLEFT(looprw
);
991 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
998 for (i
= data
->leftIndex
; i
< data
->count
; i
++) {
999 looprw
= data
->leftList
[i
];
1000 if (!(data
->realY
> WBOTTOM(looprw
)
1001 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1002 edge_l
= WLEFT(looprw
);
1003 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1010 printf("%d %d\n",winL,winR);
1011 printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);
1014 if ((winL
- l_edge
) < (r_edge
- winL
)) {
1016 if ((attract
&& winL
<= l_edge
+ resist
&& winL
>= l_edge
- resist
)
1017 || (dx
< 0 && winL
<= l_edge
&& winL
>= l_edge
- resist
)) {
1023 if (resist
> 0 && attract
&& winL
>= r_edge
- resist
&& winL
<= r_edge
+ resist
) {
1029 if ((winR
- edge_l
) < (edge_r
- winR
)) {
1030 if (resist
> 0 && attract
&& winR
<= edge_l
+ resist
&& winR
>= edge_l
- resist
) {
1031 newX
= edge_l
- data
->winWidth
;
1036 if ((attract
&& winR
>= edge_r
- resist
&& winR
<= edge_r
+ resist
)
1037 || (dx
> 0 && winR
>= edge_r
&& winR
<= edge_r
+ resist
)) {
1038 newX
= edge_r
- data
->winWidth
;
1045 /* Add inter head resistance 2/2 (if needed) */
1046 t_edge
= WMAX(scr
->totalUsableArea
[head
].y1
, rect
.pos
.y
);
1047 edge_t
= t_edge
- resist
;
1048 edge_b
= WMIN(scr
->totalUsableArea
[head
].y2
, rect
.pos
.y
+ rect
.size
.height
);
1049 b_edge
= edge_b
+ resist
;
1051 if ((data
->bottomIndex
>= 0) && (data
->bottomIndex
<= data
->count
)) {
1054 for (i
= data
->bottomIndex
- 1; i
>= 0; i
--) {
1055 looprw
= data
->bottomList
[i
];
1056 if (!(data
->realX
> WRIGHT(looprw
)
1057 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1058 if (attract
|| ((data
->realY
< (WBOTTOM(looprw
) + 2)) && dy
< 0)) {
1059 t_edge
= WBOTTOM(looprw
) + 1;
1060 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1067 for (i
= data
->bottomIndex
; i
< data
->count
; i
++) {
1068 looprw
= data
->bottomList
[i
];
1069 if (!(data
->realX
> WRIGHT(looprw
)
1070 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1071 b_edge
= WBOTTOM(looprw
) + 1;
1072 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1079 if ((data
->topIndex
>= 0) && (data
->topIndex
<= data
->count
)) {
1082 for (i
= data
->topIndex
- 1; i
>= 0; i
--) {
1083 looprw
= data
->topList
[i
];
1084 if (!(data
->realX
> WRIGHT(looprw
)
1085 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1087 || (((data
->realY
+ data
->winHeight
) > (WTOP(looprw
) - 1))
1089 edge_b
= WTOP(looprw
);
1090 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1097 for (i
= data
->topIndex
; i
< data
->count
; i
++) {
1098 looprw
= data
->topList
[i
];
1099 if (!(data
->realX
> WRIGHT(looprw
)
1100 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1101 edge_t
= WTOP(looprw
);
1102 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1108 if ((winT
- t_edge
) < (b_edge
- winT
)) {
1110 if ((attract
&& winT
<= t_edge
+ resist
&& winT
>= t_edge
- resist
)
1111 || (dy
< 0 && winT
<= t_edge
&& winT
>= t_edge
- resist
)) {
1117 if (resist
> 0 && attract
&& winT
>= b_edge
- resist
&& winT
<= b_edge
+ resist
) {
1123 if ((winB
- edge_t
) < (edge_b
- winB
)) {
1124 if (resist
> 0 && attract
&& winB
<= edge_t
+ resist
&& winB
>= edge_t
- resist
) {
1125 newY
= edge_t
- data
->winHeight
;
1130 if ((attract
&& winB
>= edge_b
- resist
&& winB
<= edge_b
+ resist
)
1131 || (dy
> 0 && winB
>= edge_b
&& winB
<= edge_b
+ resist
)) {
1132 newY
= edge_b
- data
->winHeight
;
1142 /* update window position */
1146 if (((dx
> 0 && data
->calcX
- data
->realX
> 0)
1147 || (dx
< 0 && data
->calcX
- data
->realX
< 0)) && !hresist
)
1150 if (((dy
> 0 && data
->calcY
- data
->realY
> 0)
1151 || (dy
< 0 && data
->calcY
- data
->realY
< 0)) && !vresist
)
1154 if (data
->realX
!= newX
|| data
->realY
!= newY
) {
1156 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1157 showPosition(wwin
, data
->realX
, data
->realY
);
1160 doWindowMove(wwin
, scr
->selected_windows
, newX
- wwin
->frame_x
, newY
- wwin
->frame_y
);
1163 drawFrames(wwin
, scr
->selected_windows
,
1164 data
->realX
- wwin
->frame_x
, data
->realY
- wwin
->frame_y
);
1167 if (!scr
->selected_windows
&& wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
1169 moveGeometryDisplayCentered(scr
, newX
+ data
->winWidth
/ 2, newY
+ data
->winHeight
/ 2);
1174 drawFrames(wwin
, scr
->selected_windows
, newX
- wwin
->frame_x
, newY
- wwin
->frame_y
);
1177 if (!scr
->selected_windows
) {
1178 showPosition(wwin
, newX
, newY
);
1182 /* recalc relative window position */
1183 if (doResistance
&& (data
->realX
!= newX
|| data
->realY
!= newY
)) {
1184 updateResistance(data
, newX
, newY
);
1191 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1193 #define MOVABLE_BIT 0x01
1194 #define RESIZABLE_BIT 0x02
1196 int wKeyboardMoveResizeWindow(WWindow
* wwin
)
1198 WScreen
*scr
= wwin
->screen_ptr
;
1199 Window root
= scr
->root_win
;
1201 int w
= wwin
->frame
->core
->width
;
1202 int h
= wwin
->frame
->core
->height
;
1203 int scr_width
= wwin
->screen_ptr
->scr_width
;
1204 int scr_height
= wwin
->screen_ptr
->scr_height
;
1205 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1206 int src_x
= wwin
->frame_x
;
1207 int src_y
= wwin
->frame_y
;
1210 int done
, off_x
, off_y
, ww
, wh
;
1212 int opaqueMoveResize
= wPreferences
.opaque_move_resize_keyboard
;
1214 KeyCode shiftl
, shiftr
, ctrlmode
;
1215 KeySym keysym
= NoSymbol
;
1217 int modes
= ((IS_MOVABLE(wwin
) ? MOVABLE_BIT
: 0) | (IS_RESIZABLE(wwin
) ? RESIZABLE_BIT
: 0));
1218 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1219 ? wGetHeadForWindow(wwin
)
1220 : scr
->xine_info
.primary_head
);
1222 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1223 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1224 ctrlmode
= done
= off_x
= off_y
= 0;
1226 if (modes
== RESIZABLE_BIT
) {
1232 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1234 if (!wwin
->flags
.selected
) {
1235 wUnselectWindows(scr
);
1238 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1239 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
1240 GrabModeAsync
, None
, wPreferences
.cursor
[WCUR_NORMAL
], CurrentTime
);
1244 if (!opaqueMoveResize
) {
1245 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1246 if (scr
->selected_windows
)
1247 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1249 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1251 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1254 if ((wwin
->flags
.shaded
|| scr
->selected_windows
) && (!scr
->selected_windows
)) {
1255 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1266 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1267 | ButtonPressMask
| ExposureMask
, &event
);
1268 if (event
.type
== Expose
) {
1269 WMHandleEvent(&event
);
1271 } while (event
.type
== Expose
);
1273 if (!opaqueMoveResize
) {
1274 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1275 if (scr
->selected_windows
)
1276 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1278 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1279 /*** I HATE EDGE RESISTANCE - ]d ***/
1281 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1286 showGeometry(wwin
, src_x
+ off_x
, src_y
+ off_y
, src_x
+ off_x
+ ww
, src_y
+ off_y
+ wh
,
1292 switch (event
.type
) {
1295 if (event
.xkey
.time
- lastTime
> 50) {
1296 kspeed
/= (1 + (event
.xkey
.time
- lastTime
) / 100);
1304 lastTime
= event
.xkey
.time
;
1305 if (modes
== (MOVABLE_BIT
| RESIZABLE_BIT
)) {
1306 if ((event
.xkey
.state
& ControlMask
) && !wwin
->flags
.shaded
) {
1308 wUnselectWindows(scr
);
1313 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
) {
1315 cycleGeometryDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
, 0);
1317 cyclePositionDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1320 keysym
= XLookupKeysym(&event
.xkey
, 0);
1377 if (moment
!= RIGHT
)
1389 wWindowConstrainSize(wwin
, (unsigned int *)&ww
, (unsigned int *)&wh
);
1392 if (wPreferences
.ws_cycle
) {
1393 if (src_x
+ off_x
+ ww
< 20) {
1394 if (!w_global
.workspace
.current
)
1395 wWorkspaceChange(scr
, w_global
.workspace
.count
- 1);
1397 wWorkspaceChange(scr
, w_global
.workspace
.current
- 1);
1400 } else if (src_x
+ off_x
+ 20 > scr_width
) {
1401 if (w_global
.workspace
.current
== w_global
.workspace
.count
- 1)
1402 wWorkspaceChange(scr
, 0);
1404 wWorkspaceChange(scr
, w_global
.workspace
.current
+ 1);
1409 if (src_x
+ off_x
+ ww
< 20)
1410 off_x
= 20 - ww
- src_x
;
1411 else if (src_x
+ off_x
+ 20 > scr_width
)
1412 off_x
= scr_width
- 20 - src_x
;
1415 if (src_y
+ off_y
+ wh
< 20) {
1416 off_y
= 20 - wh
- src_y
;
1417 } else if (src_y
+ off_y
+ 20 > scr_height
) {
1418 off_y
= scr_height
- 20 - src_y
;
1427 WMHandleEvent(&event
);
1428 while (XCheckTypedEvent(dpy
, Expose
, &event
)) {
1429 WMHandleEvent(&event
);
1434 WMHandleEvent(&event
);
1441 if (wwin
->flags
.shaded
&& !scr
->selected_windows
) {
1442 moveGeometryDisplayCentered(scr
, src_x
+ off_x
+ w
/ 2, src_y
+ off_y
+ h
/ 2);
1445 WMUnmapWidget(scr
->gview
);
1446 mapGeometryDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1447 } else if (!scr
->selected_windows
) {
1448 WMUnmapWidget(scr
->gview
);
1449 mapPositionDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1453 if (!opaqueMoveResize
) {
1454 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1455 if (scr
->selected_windows
)
1456 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1458 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1460 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1465 showGeometry(wwin
, src_x
+ off_x
, src_y
+ off_y
, src_x
+ off_x
+ ww
, src_y
+ off_y
+ wh
,
1467 } else if (!scr
->selected_windows
)
1468 showPosition(wwin
, src_x
+ off_x
, src_y
+ off_y
);
1470 if (opaqueMoveResize
) {
1472 wWindowConfigure(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
- vert_border
);
1476 if (!opaqueMoveResize
) { /* ctrlmode => resize */
1477 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1478 if (scr
->selected_windows
)
1479 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1481 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1483 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1488 showGeometry(wwin
, src_x
+ off_x
, src_y
+ off_y
, src_x
+ off_x
+ ww
,
1489 src_y
+ off_y
+ wh
, 0);
1490 WMUnmapWidget(scr
->gview
);
1492 WMUnmapWidget(scr
->gview
);
1494 XUngrabKeyboard(dpy
, CurrentTime
);
1495 XUngrabPointer(dpy
, CurrentTime
);
1499 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1500 if (!scr
->selected_windows
) {
1501 wWindowMove(wwin
, src_x
+ off_x
, src_y
+ off_y
);
1502 wWindowSynthConfigureNotify(wwin
);
1504 WMArrayIterator iter
;
1507 doWindowMove(wwin
, scr
->selected_windows
, off_x
, off_y
);
1509 WM_ITERATE_ARRAY(scr
->selected_windows
, foo
, iter
) {
1510 wWindowSynthConfigureNotify(foo
);
1514 if (ww
!= original_w
)
1515 wwin
->flags
.maximized
&= ~(MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
1517 if (wh
!= original_h
)
1518 wwin
->flags
.maximized
&= ~(MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
1520 wWindowConfigure(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
- vert_border
);
1521 wWindowSynthConfigureNotify(wwin
);
1523 wWindowChangeWorkspace(wwin
, w_global
.workspace
.current
);
1524 wSetFocusTo(scr
, wwin
);
1527 if (wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 &&
1528 head
!= wGetHeadForWindow(wwin
)) {
1529 wArrangeIcons(scr
, True
);
1532 update_saved_geometry(wwin
);
1540 *----------------------------------------------------------------------
1541 * wMouseMoveWindow--
1542 * Move the named window and the other selected ones (if any),
1543 * interactively. Also shows the position of the window, if only one
1544 * window is being moved.
1545 * If the window is not on the selected window list, the selected
1546 * windows are deselected.
1547 * If shift is pressed during the operation, the position display
1548 * is changed to another type.
1551 * True if the window was moved, False otherwise.
1554 * The window(s) position is changed, and the client(s) are
1555 * notified about that.
1556 * The position display configuration may be changed.
1557 *----------------------------------------------------------------------
1559 int wMouseMoveWindow(WWindow
* wwin
, XEvent
* ev
)
1561 WScreen
*scr
= wwin
->screen_ptr
;
1563 Window root
= scr
->root_win
;
1564 KeyCode shiftl
, shiftr
;
1568 /* This needs not to change while moving, else bad things can happen */
1569 int opaqueMove
= wPreferences
.opaque_move
;
1571 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1572 ? wGetHeadForWindow(wwin
)
1573 : scr
->xine_info
.primary_head
);
1575 if (!IS_MOVABLE(wwin
))
1578 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1579 XSetWindowAttributes attr
;
1581 attr
.save_under
= True
;
1582 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
, CWSaveUnder
, &attr
);
1585 initMoveData(wwin
, &moveData
);
1587 moveData
.mouseX
= ev
->xmotion
.x_root
;
1588 moveData
.mouseY
= ev
->xmotion
.y_root
;
1590 if (!wwin
->flags
.selected
) {
1591 /* this window is not selected, unselect others and move only wwin */
1592 wUnselectWindows(scr
);
1594 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1595 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1601 /* XWarpPointer() doesn't seem to generate Motion events, so
1602 * we've got to simulate them */
1603 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1604 &event
.xmotion
.y_root
, &junk
, &junk
, (unsigned *)&junk
);
1606 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1607 | PointerMotionHintMask
1608 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
, &event
);
1610 if (event
.type
== MotionNotify
) {
1611 /* compress MotionNotify events */
1612 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1613 if (!checkMouseSamplingRate(&event
))
1617 switch (event
.type
) {
1619 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1620 && started
&& !scr
->selected_windows
) {
1623 drawFrames(wwin
, scr
->selected_windows
,
1624 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1627 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1628 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1631 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1632 moveData
.winWidth
, moveData
.winHeight
);
1634 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1636 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1640 drawFrames(wwin
, scr
->selected_windows
,
1641 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1644 WMHandleEvent(&event); this causes problems needs fixing */
1649 if (IS_RESIZABLE(wwin
) && wPreferences
.window_snapping
&& wPreferences
.no_autowrap
) {
1650 if (moveData
.snap
== SNAP_LEFT
&& moveData
.mouseX
> 1) {
1651 moveData
.snap
= SNAP_NONE
;
1652 drawTransparentFrame(wwin
, 0, 0, scr
->scr_width
/2, scr
->scr_height
);
1654 if (moveData
.snap
== SNAP_RIGHT
&& moveData
.mouseX
< scr
->scr_width
- 2) {
1655 moveData
.snap
= SNAP_NONE
;
1656 drawTransparentFrame(wwin
, scr
->scr_width
/2, 0, scr
->scr_width
/2,
1659 if (moveData
.snap
== SNAP_NONE
) {
1660 if (moveData
.mouseX
<= 1) {
1661 moveData
.snap
= SNAP_LEFT
;
1662 drawTransparentFrame(wwin
, 0, 0, scr
->scr_width
/2,
1665 if (moveData
.mouseX
>= scr
->scr_width
- 2) {
1666 moveData
.snap
= SNAP_RIGHT
;
1667 drawTransparentFrame(wwin
, scr
->scr_width
/2, 0, scr
->scr_width
/2,
1674 if (moveData
.snap
== SNAP_LEFT
)
1675 drawTransparentFrame(wwin
, 0, 0, scr
->scr_width
/2, scr
->scr_height
);
1676 if (moveData
.snap
== SNAP_RIGHT
)
1677 drawTransparentFrame(wwin
, scr
->scr_width
/2, 0, scr
->scr_width
/2,
1680 updateWindowPosition(wwin
, &moveData
,
1681 scr
->selected_windows
== NULL
1682 && wPreferences
.edge_resistance
> 0,
1683 opaqueMove
, event
.xmotion
.x_root
, event
.xmotion
.y_root
);
1685 if (moveData
.snap
== SNAP_LEFT
)
1686 drawTransparentFrame(wwin
, 0, 0, scr
->scr_width
/2, scr
->scr_height
);
1687 if (moveData
.snap
== SNAP_RIGHT
)
1688 drawTransparentFrame(wwin
, scr
->scr_width
/2, 0, scr
->scr_width
/2,
1691 if (!warped
&& !wPreferences
.no_autowrap
) {
1692 int oldWorkspace
= w_global
.workspace
.current
;
1694 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1695 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1699 drawFrames(wwin
, scr
->selected_windows
,
1700 moveData
.realX
- wwin
->frame_x
,
1701 moveData
.realY
- wwin
->frame_y
);
1703 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1704 if (w_global
.workspace
.current
!= oldWorkspace
1705 && wPreferences
.edge_resistance
> 0
1706 && scr
->selected_windows
== NULL
)
1707 updateMoveData(wwin
, &moveData
);
1711 drawFrames(wwin
, scr
->selected_windows
,
1712 moveData
.realX
- wwin
->frame_x
,
1713 moveData
.realY
- wwin
->frame_y
);
1715 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1717 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1723 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1724 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1726 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1727 | ButtonReleaseMask
| ButtonPressMask
,
1728 wPreferences
.cursor
[WCUR_MOVE
], CurrentTime
);
1730 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1732 if (!scr
->selected_windows
)
1733 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1734 moveData
.winWidth
, moveData
.winHeight
);
1736 if (started
&& !opaqueMove
)
1737 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1739 if (!opaqueMove
|| (wPreferences
.move_display
== WDIS_NEW
1740 && !scr
->selected_windows
)) {
1742 if (wPreferences
.move_display
== WDIS_NEW
)
1743 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1753 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1756 if (moveData
.snap
!= SNAP_NONE
) {
1757 if (moveData
.snap
== SNAP_LEFT
) {
1760 drawFrames(wwin
, scr
->selected_windows
,
1761 moveData
.realX
- wwin
->frame_x
,
1762 moveData
.realY
- wwin
->frame_y
);
1763 drawTransparentFrame(wwin
, 0, 0, scr
->scr_width
/2, scr
->scr_height
);
1764 handleMaximize(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
);
1766 if (moveData
.snap
== SNAP_RIGHT
) {
1769 drawFrames(wwin
, scr
->selected_windows
,
1770 moveData
.realX
- wwin
->frame_x
,
1771 moveData
.realY
- wwin
->frame_y
);
1772 drawTransparentFrame(wwin
, scr
->scr_width
/2, 0, scr
->scr_width
/2,
1774 handleMaximize(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
);
1776 moveData
.snap
= SNAP_NONE
;
1777 } else if (started
) {
1780 drawFrames(wwin
, scr
->selected_windows
,
1781 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1783 doWindowMove(wwin
, scr
->selected_windows
,
1784 moveData
.realX
- wwin
->frame_x
,
1785 moveData
.realY
- wwin
->frame_y
);
1787 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1788 wWindowSynthConfigureNotify(wwin
);
1790 XUngrabKeyboard(dpy
, CurrentTime
);
1793 wWindowChangeWorkspace(wwin
, w_global
.workspace
.current
);
1794 wSetFocusTo(scr
, wwin
);
1796 if (wPreferences
.move_display
== WDIS_NEW
)
1797 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1799 /* discard all enter/leave events that happened until
1800 * the time the button was released */
1801 while (XCheckTypedEvent(dpy
, EnterNotify
, &e
)) {
1802 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1803 XPutBackEvent(dpy
, &e
);
1807 while (XCheckTypedEvent(dpy
, LeaveNotify
, &e
)) {
1808 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1809 XPutBackEvent(dpy
, &e
);
1814 if (!scr
->selected_windows
) {
1815 /* get rid of the geometry window */
1816 WMUnmapWidget(scr
->gview
);
1823 if (started
&& !opaqueMove
) {
1824 drawFrames(wwin
, scr
->selected_windows
,
1825 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1827 WMHandleEvent(&event
);
1830 drawFrames(wwin
, scr
->selected_windows
,
1831 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1833 WMHandleEvent(&event
);
1839 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1840 XSetWindowAttributes attr
;
1842 attr
.save_under
= False
;
1843 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
, CWSaveUnder
, &attr
);
1847 freeMoveData(&moveData
);
1849 if (started
&& wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 &&
1850 head
!= wGetHeadForWindow(wwin
)) {
1851 wArrangeIcons(scr
, True
);
1855 update_saved_geometry(wwin
);
1861 #define HCONSTRAIN 2
1863 static int getResizeDirection(WWindow
* wwin
, int x
, int y
, int dy
, int flags
)
1865 int w
= wwin
->frame
->core
->width
- 1;
1866 int cw
= wwin
->frame
->resizebar_corner_width
;
1869 /* if not resizing through the resizebar */
1870 if (!(flags
& RESIZEBAR
)) {
1872 int xdir
= (abs(x
) < (wwin
->client
.width
/ 2)) ? LEFT
: RIGHT
;
1873 int ydir
= (abs(y
) < (wwin
->client
.height
/ 2)) ? UP
: DOWN
;
1875 /* How much resize space is allowed */
1876 int spacew
= abs(wwin
->client
.width
/ 3);
1877 int spaceh
= abs(wwin
->client
.height
/ 3);
1879 /* Determine where x fits */
1880 if ((abs(x
) > wwin
->client
.width
/2 - spacew
/2) &&
1881 (abs(x
) < wwin
->client
.width
/2 + spacew
/2)) {
1882 /* Resize vertically */
1884 } else if ((abs(y
) > wwin
->client
.height
/2 - spaceh
/2) &&
1885 (abs(y
) < wwin
->client
.height
/2 + spaceh
/2)) {
1886 /* Resize horizontally */
1889 return (xdir
| ydir
);
1892 /* window is too narrow. allow diagonal resize */
1896 if (flags
& HCONSTRAIN
)
1901 return (LEFT
| ydir
);
1903 return (RIGHT
| ydir
);
1905 /* vertical resize */
1906 if ((x
> cw
) && (x
< w
- cw
))
1914 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1920 void wMouseResizeWindow(WWindow
* wwin
, XEvent
* ev
)
1923 WScreen
*scr
= wwin
->screen_ptr
;
1924 Window root
= scr
->root_win
;
1925 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1926 int fw
= wwin
->frame
->core
->width
;
1927 int fh
= wwin
->frame
->core
->height
;
1928 int fx
= wwin
->frame_x
;
1929 int fy
= wwin
->frame_y
;
1930 int is_resizebar
= (wwin
->frame
->resizebar
&& ev
->xany
.window
== wwin
->frame
->resizebar
->window
);
1934 int rw
= fw
, rh
= fh
;
1935 int rx1
, ry1
, rx2
, ry2
;
1937 KeyCode shiftl
, shiftr
;
1942 int original_fw
= fw
;
1943 int original_fh
= fh
;
1944 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1945 ? wGetHeadForWindow(wwin
)
1946 : scr
->xine_info
.primary_head
);
1947 int opaqueResize
= wPreferences
.opaque_resize
;
1949 if (!IS_RESIZABLE(wwin
))
1952 if (wwin
->flags
.shaded
) {
1953 wwarning("internal error: tryein");
1956 orig_x
= ev
->xbutton
.x_root
;
1957 orig_y
= ev
->xbutton
.y_root
;
1960 wUnselectWindows(scr
);
1965 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1966 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1969 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1970 | ButtonReleaseMask
| PointerMotionHintMask
| ButtonPressMask
| ExposureMask
, &event
);
1971 if (!checkMouseSamplingRate(&event
))
1974 switch (event
.type
) {
1976 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1977 if (!opaqueResize
) {
1978 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1980 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1981 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
1982 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1985 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1990 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
2001 dw
= orig_x
- event
.xmotion
.x_root
;
2002 else if (res
& RIGHT
)
2003 dw
= event
.xmotion
.x_root
- orig_x
;
2005 dh
= orig_y
- event
.xmotion
.y_root
;
2006 else if (res
& DOWN
)
2007 dh
= event
.xmotion
.y_root
- orig_y
;
2009 orig_x
= event
.xmotion
.x_root
;
2010 orig_y
= event
.xmotion
.y_root
;
2015 fh
= rh
- vert_border
;
2016 wWindowConstrainSize(wwin
, (unsigned int *)&fw
, (unsigned int *)&fh
);
2020 else if (res
& RIGHT
)
2024 else if (res
& DOWN
)
2026 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
2027 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
2032 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
2033 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
2035 /* check if resizing through resizebar */
2041 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
2042 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
2043 flags
|= HCONSTRAIN
;
2045 res
= getResizeDirection(wwin
, tx
, ty
, orig_y
- event
.xmotion
.y_root
, flags
);
2047 if (res
== (UP
| LEFT
))
2048 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2049 | ButtonReleaseMask
| ButtonPressMask
,
2050 wPreferences
.cursor
[WCUR_TOPLEFTRESIZE
], CurrentTime
);
2051 else if (res
== (UP
| RIGHT
))
2052 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2053 | ButtonReleaseMask
| ButtonPressMask
,
2054 wPreferences
.cursor
[WCUR_TOPRIGHTRESIZE
], CurrentTime
);
2055 else if (res
== (DOWN
| LEFT
))
2056 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2057 | ButtonReleaseMask
| ButtonPressMask
,
2058 wPreferences
.cursor
[WCUR_BOTTOMLEFTRESIZE
], CurrentTime
);
2059 else if (res
== (DOWN
| RIGHT
))
2060 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2061 | ButtonReleaseMask
| ButtonPressMask
,
2062 wPreferences
.cursor
[WCUR_BOTTOMRIGHTRESIZE
], CurrentTime
);
2063 else if (res
== DOWN
|| res
== UP
)
2064 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2065 | ButtonReleaseMask
| ButtonPressMask
,
2066 wPreferences
.cursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2067 else if (res
& (DOWN
| UP
))
2068 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2069 | ButtonReleaseMask
| ButtonPressMask
,
2070 wPreferences
.cursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2071 else if (res
& (LEFT
| RIGHT
))
2072 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2073 | ButtonReleaseMask
| ButtonPressMask
,
2074 wPreferences
.cursor
[WCUR_HORIZONRESIZE
], CurrentTime
);
2076 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2080 /* Draw the resize frame for the first time. */
2081 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
2084 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2086 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2092 drawTransparentFrame(wwin
, orig_fx
, orig_fy
, orig_fw
, orig_fh
);
2094 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
)
2095 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
2098 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2100 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
2101 if (wPreferences
.size_display
== WDIS_NEW
)
2102 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
2103 orig_fy
+ orig_fh
, res
);
2105 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2109 /* Fist clean the geometry line */
2110 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2111 /* Now, continue drawing */
2113 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
2114 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
2115 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2124 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2128 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2131 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2133 XUngrabKeyboard(dpy
, CurrentTime
);
2134 WMUnmapWidget(scr
->gview
);
2137 if (fw
!= original_fw
)
2138 wwin
->flags
.maximized
&= ~(MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
2140 if (fh
!= original_fh
)
2141 wwin
->flags
.maximized
&= ~(MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
2143 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
2144 wWindowSynthConfigureNotify(wwin
);
2149 WMHandleEvent(&event
);
2153 if (wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 && head
!= wGetHeadForWindow(wwin
))
2154 wArrangeIcons(scr
, True
);
2166 void wUnselectWindows(WScreen
* scr
)
2170 if (!scr
->selected_windows
)
2173 while (WMGetArrayItemCount(scr
->selected_windows
)) {
2174 wwin
= WMGetFromArray(scr
->selected_windows
, 0);
2175 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
2176 wIconSelect(wwin
->icon
);
2178 wSelectWindow(wwin
, False
);
2180 WMFreeArray(scr
->selected_windows
);
2181 scr
->selected_windows
= NULL
;
2184 static void selectWindowsInside(WScreen
* scr
, int x1
, int y1
, int x2
, int y2
)
2188 /* select the windows and put them in the selected window list */
2189 tmpw
= scr
->focused_window
;
2190 while (tmpw
!= NULL
) {
2191 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
2192 if ((tmpw
->frame
->workspace
== w_global
.workspace
.current
|| IS_OMNIPRESENT(tmpw
))
2193 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
2194 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
2195 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
2196 wSelectWindow(tmpw
, True
);
2203 void wSelectWindows(WScreen
* scr
, XEvent
* ev
)
2206 Window root
= scr
->root_win
;
2207 GC gc
= scr
->frame_gc
;
2208 int xp
= ev
->xbutton
.x_root
;
2209 int yp
= ev
->xbutton
.y_root
;
2213 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
2214 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
2215 GrabModeAsync
, None
, wPreferences
.cursor
[WCUR_NORMAL
], CurrentTime
) != Success
) {
2220 wUnselectWindows(scr
);
2222 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
2224 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
| ButtonPressMask
, &event
);
2226 switch (event
.type
) {
2228 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2229 x
= event
.xmotion
.x_root
;
2236 y
= event
.xmotion
.y_root
;
2243 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2250 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2253 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2255 XUngrabPointer(dpy
, CurrentTime
);
2256 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
2260 WMHandleEvent(&event
);
2266 void InteractivePlaceWindow(WWindow
* wwin
, int *x_ret
, int *y_ret
, unsigned width
, unsigned height
)
2268 WScreen
*scr
= wwin
->screen_ptr
;
2269 Window root
= scr
->root_win
;
2272 KeyCode shiftl
, shiftr
;
2276 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2277 GrabModeAsync
, GrabModeAsync
, None
, wPreferences
.cursor
[WCUR_NORMAL
], CurrentTime
) != Success
) {
2282 if (HAS_TITLEBAR(wwin
)) {
2283 h
= WMFontHeight(scr
->title_font
) + (wPreferences
.window_title_clearance
+
2284 TITLEBAR_EXTEND_SPACE
) * 2;
2286 if (h
> wPreferences
.window_title_max_height
)
2287 h
= wPreferences
.window_title_max_height
;
2289 if (h
< wPreferences
.window_title_min_height
)
2290 h
= wPreferences
.window_title_min_height
;
2294 if (HAS_RESIZEBAR(wwin
)) {
2295 height
+= RESIZEBAR_HEIGHT
;
2297 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2298 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
, (unsigned *)&junk
);
2299 mapPositionDisplay(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2301 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2303 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2304 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2306 WMMaskEvent(dpy
, PointerMotionMask
| ButtonPressMask
| ExposureMask
| KeyPressMask
, &event
);
2308 if (!checkMouseSamplingRate(&event
))
2311 switch (event
.type
) {
2313 if ((event
.xkey
.keycode
== shiftl
)
2314 || (event
.xkey
.keycode
== shiftr
)) {
2315 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2316 cyclePositionDisplay(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2317 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2322 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2324 x
= event
.xmotion
.x_root
;
2325 y
= event
.xmotion
.y_root
;
2327 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2328 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2330 showPosition(wwin
, x
- width
/ 2, y
- h
/ 2);
2332 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2337 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2339 *x_ret
= x
- width
/ 2;
2341 XUngrabPointer(dpy
, CurrentTime
);
2342 XUngrabKeyboard(dpy
, CurrentTime
);
2343 /* get rid of the geometry window */
2344 WMUnmapWidget(scr
->gview
);
2348 WMHandleEvent(&event
);