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
56 /* True if window currently has a border. This also includes borderless
57 * windows which are currently selected
59 #define HAS_BORDER_WITH_SELECT(w) ((w)->flags.selected || HAS_BORDER(w))
63 *----------------------------------------------------------------------
64 * checkMouseSamplingRate-
65 * For lowering the mouse motion sampling rate for machines where
66 * it's too high (SGIs). If it returns False then the event should be
68 *----------------------------------------------------------------------
70 static Bool
checkMouseSamplingRate(XEvent
* ev
)
72 static Time previousMotion
= 0;
74 if (ev
->type
== MotionNotify
) {
75 if (ev
->xmotion
.time
- previousMotion
< DELAY_BETWEEN_MOUSE_SAMPLING
) {
78 previousMotion
= ev
->xmotion
.time
;
85 *----------------------------------------------------------------------
86 * moveGeometryDisplayCentered
88 * routine that moves the geometry/position window on scr so it is
89 * centered over the given coordinates (x,y). Also the window position
90 * is clamped so it stays on the screen at all times.
91 *----------------------------------------------------------------------
93 static void moveGeometryDisplayCentered(WScreen
* scr
, int x
, int y
)
95 unsigned int w
= WMWidgetWidth(scr
->gview
);
96 unsigned int h
= WMWidgetHeight(scr
->gview
);
97 int x1
= 0, y1
= 0, x2
= scr
->scr_width
, y2
= scr
->scr_height
;
102 /* dead area check */
103 if (scr
->xine_info
.count
) {
110 rect
.size
.height
= h
;
112 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
114 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
115 rect
= wGetRectForHead(scr
, head
);
118 x2
= x1
+ rect
.size
.width
;
119 y2
= y1
+ rect
.size
.height
;
125 else if (x
> (x2
- w
))
130 else if (y
> (y2
- h
))
133 WMMoveWidget(scr
->gview
, x
, y
);
136 static void showPosition(WWindow
* wwin
, int x
, int y
)
138 WScreen
*scr
= wwin
->screen_ptr
;
140 if (wPreferences
.move_display
== WDIS_NEW
) {
142 int width
= wwin
->frame
->core
->width
;
143 int height
= wwin
->frame
->core
->height
;
145 GC lgc
= scr
->line_gc
;
146 XSetForeground(dpy
, lgc
, scr
->line_pixel
);
147 sprintf(num
, "%i", x
);
149 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
- 1, scr
->scr_width
, y
- 1);
150 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
+ height
+ 2, scr
->scr_width
, y
+ height
+ 2);
151 XDrawLine(dpy
, scr
->root_win
, lgc
, x
- 1, 0, x
- 1, scr
->scr_height
);
152 XDrawLine(dpy
, scr
->root_win
, lgc
, x
+ width
+ 2, 0, x
+ width
+ 2, scr
->scr_height
);
155 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
159 static void cyclePositionDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
)
161 WScreen
*scr
= wwin
->screen_ptr
;
164 wPreferences
.move_display
++;
165 wPreferences
.move_display
%= NUM_DISPLAYS
;
167 if (wPreferences
.move_display
== WDIS_NEW
) {
168 wPreferences
.move_display
++;
169 wPreferences
.move_display
%= NUM_DISPLAYS
;
172 if (wPreferences
.move_display
== WDIS_NONE
) {
173 WMUnmapWidget(scr
->gview
);
175 if (wPreferences
.move_display
== WDIS_CENTER
) {
176 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
177 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
178 rect
.pos
.y
+ rect
.size
.height
/ 2);
179 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
180 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
181 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
182 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
183 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
185 WMMapWidget(scr
->gview
);
189 static void mapPositionDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
)
191 WScreen
*scr
= wwin
->screen_ptr
;
194 if (wPreferences
.move_display
== WDIS_NEW
|| wPreferences
.move_display
== WDIS_NONE
) {
196 } else if (wPreferences
.move_display
== WDIS_CENTER
) {
197 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
198 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
199 rect
.pos
.y
+ rect
.size
.height
/ 2);
200 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
201 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
202 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
203 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
204 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
206 WMMapWidget(scr
->gview
);
207 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
210 static void showGeometry(WWindow
* wwin
, int x1
, int y1
, int x2
, int y2
, int direction
)
212 WScreen
*scr
= wwin
->screen_ptr
;
213 Window root
= scr
->root_win
;
214 GC gc
= scr
->line_gc
;
215 int ty
, by
, my
, x
, y
, mx
, s
;
220 /* This seems necessary for some odd reason (too lazy to write x1-1 and
221 * x2-1 everywhere below in the code). But why only for x? */
225 if (HAS_BORDER_WITH_SELECT(wwin
)) {
226 x1
+= scr
->frame_border_width
;
227 x2
+= scr
->frame_border_width
;
228 y1
+= scr
->frame_border_width
;
229 y2
+= scr
->frame_border_width
;
232 ty
= y1
+ wwin
->frame
->top_width
;
233 by
= y2
- wwin
->frame
->bottom_width
;
235 if (wPreferences
.size_display
== WDIS_NEW
) {
236 fw
= XTextWidth(scr
->tech_draw_font
, "8888", 4);
237 fh
= scr
->tech_draw_font
->ascent
+ scr
->tech_draw_font
->descent
;
239 XSetForeground(dpy
, gc
, scr
->line_pixel
);
241 /* vertical geometry */
242 if (((direction
& LEFT
) && (x2
< scr
->scr_width
- fw
)) || (x1
< fw
)) {
251 /* top arrow & end bar */
252 segment
[0].x1
= x
- (s
+ 6);
254 segment
[0].x2
= x
- (s
- 10);
258 segment
[1].x1
= x
- (s
- 2);
259 segment
[1].y1
= ty
+ 1;
260 segment
[1].x2
= x
- (s
- 5);
261 segment
[1].y2
= ty
+ 7;
263 segment
[2].x1
= x
- (s
- 2);
264 segment
[2].y1
= ty
+ 1;
265 segment
[2].x2
= x
- (s
+ 1);
266 segment
[2].y2
= ty
+ 7;
269 segment
[3].x1
= x
- (s
- 2);
270 segment
[3].y1
= ty
+ 1;
271 segment
[3].x2
= x
- (s
- 2);
272 segment
[3].y2
= my
- fh
/ 2 - 1;
274 XDrawSegments(dpy
, root
, gc
, segment
, 4);
276 /* bottom arrow & end bar */
281 segment
[1].y1
= by
- 1;
282 segment
[1].y2
= by
- 7;
284 segment
[2].y1
= by
- 1;
285 segment
[2].y2
= by
- 7;
288 segment
[3].y1
= my
+ fh
/ 2 + 2;
289 segment
[3].y2
= by
- 1;
291 XDrawSegments(dpy
, root
, gc
, segment
, 4);
293 snprintf(num
, sizeof(num
), "%i", (by
- ty
- wwin
->normal_hints
->base_height
) /
294 wwin
->normal_hints
->height_inc
);
295 fw
= XTextWidth(scr
->tech_draw_font
, num
, strlen(num
));
297 /* Display the height. */
298 XSetFont(dpy
, gc
, scr
->tech_draw_font
->fid
);
299 XDrawString(dpy
, root
, gc
, x
- s
+ 3 - fw
/ 2, my
+ scr
->tech_draw_font
->ascent
- fh
/ 2 + 1, num
,
302 /* horizontal geometry */
310 mx
= x1
+ (x2
- x1
) / 2;
311 snprintf(num
, sizeof(num
), "%i", (x2
- x1
- wwin
->normal_hints
->base_width
) /
312 wwin
->normal_hints
->width_inc
);
313 fw
= XTextWidth(scr
->tech_draw_font
, num
, strlen(num
));
315 /* left arrow & end bar */
317 segment
[0].y1
= y
- (s
+ 6);
319 segment
[0].y2
= y
- (s
- 10);
322 segment
[1].x1
= x1
+ 7;
323 segment
[1].y1
= y
- (s
+ 1);
324 segment
[1].x2
= x1
+ 1;
325 segment
[1].y2
= y
- (s
- 2);
327 segment
[2].x1
= x1
+ 1;
328 segment
[2].y1
= y
- (s
- 2);
329 segment
[2].x2
= x1
+ 7;
330 segment
[2].y2
= y
- (s
- 5);
333 segment
[3].x1
= x1
+ 1;
334 segment
[3].y1
= y
- (s
- 2);
335 segment
[3].x2
= mx
- fw
/ 2 - 2;
336 segment
[3].y2
= y
- (s
- 2);
338 XDrawSegments(dpy
, root
, gc
, segment
, 4);
340 /* right arrow & end bar */
341 segment
[0].x1
= x2
+ 1;
342 segment
[0].x2
= x2
+ 1;
345 segment
[1].x1
= x2
- 6;
349 segment
[2].x2
= x2
- 6;
352 segment
[3].x1
= mx
+ fw
/ 2 + 2;
355 XDrawSegments(dpy
, root
, gc
, segment
, 4);
357 /* Display the width. */
358 XDrawString(dpy
, root
, gc
, mx
- fw
/ 2 + 1, y
- s
+ scr
->tech_draw_font
->ascent
- fh
/ 2 + 1, num
,
361 WSetGeometryViewShownSize(scr
->gview
, (x2
- x1
- wwin
->normal_hints
->base_width
)
362 / wwin
->normal_hints
->width_inc
,
363 (by
- ty
- wwin
->normal_hints
->base_height
)
364 / wwin
->normal_hints
->height_inc
);
368 static void cycleGeometryDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
, int dir
)
370 WScreen
*scr
= wwin
->screen_ptr
;
373 wPreferences
.size_display
++;
374 wPreferences
.size_display
%= NUM_DISPLAYS
;
376 if (wPreferences
.size_display
== WDIS_NEW
|| wPreferences
.size_display
== WDIS_NONE
) {
377 WMUnmapWidget(scr
->gview
);
379 if (wPreferences
.size_display
== WDIS_CENTER
) {
380 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
381 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
382 rect
.pos
.y
+ rect
.size
.height
/ 2);
383 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
384 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
385 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
386 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
387 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
389 WMMapWidget(scr
->gview
);
390 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, dir
);
394 static void mapGeometryDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
)
396 WScreen
*scr
= wwin
->screen_ptr
;
399 if (wPreferences
.size_display
== WDIS_NEW
|| wPreferences
.size_display
== WDIS_NONE
)
402 if (wPreferences
.size_display
== WDIS_CENTER
) {
403 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
404 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
405 rect
.pos
.y
+ rect
.size
.height
/ 2);
406 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
407 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
408 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
409 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
410 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
412 WMMapWidget(scr
->gview
);
413 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, 0);
416 static void doWindowMove(WWindow
* wwin
, WMArray
* array
, int dx
, int dy
)
419 WScreen
*scr
= wwin
->screen_ptr
;
422 if (!array
|| !WMGetArrayItemCount(array
)) {
423 wWindowMove(wwin
, wwin
->frame_x
+ dx
, wwin
->frame_y
+ dy
);
425 WMArrayIterator iter
;
427 WM_ITERATE_ARRAY(array
, tmpw
, iter
) {
428 x
= tmpw
->frame_x
+ dx
;
429 y
= tmpw
->frame_y
+ dy
;
431 #if 1 /* XXX: with xinerama patch was #if 0, check this */
432 /* don't let windows become unreachable */
434 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
435 x
= 20 - (int)tmpw
->frame
->core
->width
;
436 else if (x
+ 20 > scr
->scr_width
)
437 x
= scr
->scr_width
- 20;
439 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
440 y
= 20 - (int)tmpw
->frame
->core
->height
;
441 else if (y
+ 20 > scr
->scr_height
)
442 y
= scr
->scr_height
- 20;
444 wScreenBringInside(scr
, &x
, &y
,
445 (int)tmpw
->frame
->core
->width
, (int)tmpw
->frame
->core
->height
);
448 wWindowMove(tmpw
, x
, y
);
453 static void drawTransparentFrame(WWindow
* wwin
, int x
, int y
, int width
, int height
)
455 Window root
= wwin
->screen_ptr
->root_win
;
456 GC gc
= wwin
->screen_ptr
->frame_gc
;
460 if (HAS_BORDER_WITH_SELECT(wwin
)) {
461 x
+= wwin
->screen_ptr
->frame_border_width
;
462 y
+= wwin
->screen_ptr
->frame_border_width
;
465 if (HAS_TITLEBAR(wwin
) && !wwin
->flags
.shaded
) {
466 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + (wPreferences
.window_title_clearance
+
467 TITLEBAR_EXTEND_SPACE
) * 2;
469 if (h
> wPreferences
.window_title_max_height
)
470 h
= wPreferences
.window_title_max_height
;
472 if (h
< wPreferences
.window_title_min_height
)
473 h
= wPreferences
.window_title_min_height
;
475 if (HAS_RESIZEBAR(wwin
) && !wwin
->flags
.shaded
) {
476 /* Can't use wwin-frame->bottom_width because, in some cases
477 (e.g. interactive placement), frame does not point to anything. */
478 bottom
= RESIZEBAR_HEIGHT
;
480 XDrawRectangle(dpy
, root
, gc
, x
- 1, y
- 1, width
+ 1, height
+ 1);
483 XDrawLine(dpy
, root
, gc
, x
, y
+ h
- 1, x
+ width
, y
+ h
- 1);
486 XDrawLine(dpy
, root
, gc
, x
, y
+ height
- bottom
, x
+ width
, y
+ height
- bottom
);
490 static void drawFrames(WWindow
* wwin
, WMArray
* array
, int dx
, int dy
)
493 int scr_width
= wwin
->screen_ptr
->scr_width
;
494 int scr_height
= wwin
->screen_ptr
->scr_height
;
499 x
= wwin
->frame_x
+ dx
;
500 y
= wwin
->frame_y
+ dy
;
502 drawTransparentFrame(wwin
, x
, y
, wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
505 WMArrayIterator iter
;
507 WM_ITERATE_ARRAY(array
, tmpw
, iter
) {
508 x
= tmpw
->frame_x
+ dx
;
509 y
= tmpw
->frame_y
+ dy
;
511 /* don't let windows become unreachable */
512 #if 1 /* XXX: was 0 in XINERAMA patch, check */
513 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
514 x
= 20 - (int)tmpw
->frame
->core
->width
;
515 else if (x
+ 20 > scr_width
)
518 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
519 y
= 20 - (int)tmpw
->frame
->core
->height
;
520 else if (y
+ 20 > scr_height
)
524 wScreenBringInside(wwin
->screen_ptr
, &x
, &y
,
525 (int)tmpw
->frame
->core
->width
, (int)tmpw
->frame
->core
->height
);
528 drawTransparentFrame(tmpw
, x
, y
, tmpw
->frame
->core
->width
, tmpw
->frame
->core
->height
);
533 static void flushMotion(void)
538 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &ev
)) ;
541 static void crossWorkspace(WScreen
* scr
, WWindow
* wwin
, int opaque_move
, int new_workspace
, int rewind
)
543 /* do not let window be unmapped */
545 wwin
->flags
.changing_workspace
= 1;
546 wWindowChangeWorkspace(wwin
, new_workspace
);
548 /* go to new workspace */
549 wWorkspaceChange(scr
, new_workspace
);
551 wwin
->flags
.changing_workspace
= 0;
554 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, scr
->scr_width
- 20, 0);
556 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, -(scr
->scr_width
- 20), 0);
561 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
562 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
563 GrabModeAsync
, None
, wPreferences
.cursor
[WCUR_MOVE
], CurrentTime
);
568 /* arrays of WWindows sorted by the respective border position */
569 WWindow
**topList
; /* top border */
570 WWindow
**leftList
; /* left border */
571 WWindow
**rightList
; /* right border */
572 WWindow
**bottomList
; /* bottom border */
575 /* index of window in the above lists indicating the relative position
576 * of the window with the others */
582 int rubCount
; /* for workspace switching */
584 int winWidth
, winHeight
; /* width/height of the window */
585 int realX
, realY
; /* actual position of the window */
586 int calcX
, calcY
; /* calculated position of window */
587 int omouseX
, omouseY
; /* old mouse position */
588 int mouseX
, mouseY
; /* last known position of the pointer */
603 #define WTOP(w) (w)->frame_y
604 #define WLEFT(w) (w)->frame_x
605 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width - 1 + \
606 (HAS_BORDER_WITH_SELECT(w) ? 2*(w)->screen_ptr->frame_border_width : 0))
607 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height - 1 + \
608 (HAS_BORDER_WITH_SELECT(w) ? 2*(w)->screen_ptr->frame_border_width : 0))
610 static int compareWTop(const void *a
, const void *b
)
612 WWindow
*wwin1
= *(WWindow
**) a
;
613 WWindow
*wwin2
= *(WWindow
**) b
;
615 if (WTOP(wwin1
) > WTOP(wwin2
))
617 else if (WTOP(wwin1
) < WTOP(wwin2
))
623 static int compareWLeft(const void *a
, const void *b
)
625 WWindow
*wwin1
= *(WWindow
**) a
;
626 WWindow
*wwin2
= *(WWindow
**) b
;
628 if (WLEFT(wwin1
) > WLEFT(wwin2
))
630 else if (WLEFT(wwin1
) < WLEFT(wwin2
))
636 static int compareWRight(const void *a
, const void *b
)
638 WWindow
*wwin1
= *(WWindow
**) a
;
639 WWindow
*wwin2
= *(WWindow
**) b
;
641 if (WRIGHT(wwin1
) < WRIGHT(wwin2
))
643 else if (WRIGHT(wwin1
) > WRIGHT(wwin2
))
649 static int compareWBottom(const void *a
, const void *b
)
651 WWindow
*wwin1
= *(WWindow
**) a
;
652 WWindow
*wwin2
= *(WWindow
**) b
;
654 if (WBOTTOM(wwin1
) < WBOTTOM(wwin2
))
656 else if (WBOTTOM(wwin1
) > WBOTTOM(wwin2
))
662 static void updateResistance(MoveData
*data
, int newX
, int newY
)
665 int newX2
= newX
+ data
->winWidth
;
666 int newY2
= newY
+ data
->winHeight
;
669 if (newX
< data
->realX
) {
670 if (data
->rightIndex
> 0 && newX
< WRIGHT(data
->rightList
[data
->rightIndex
- 1])) {
672 } else if (data
->leftIndex
<= data
->count
- 1 && newX2
<= WLEFT(data
->leftList
[data
->leftIndex
])) {
675 } else if (newX
> data
->realX
) {
676 if (data
->leftIndex
> 0 && newX2
> WLEFT(data
->leftList
[data
->leftIndex
- 1])) {
678 } else if (data
->rightIndex
<= data
->count
- 1
679 && newX
>= WRIGHT(data
->rightList
[data
->rightIndex
])) {
685 if (newY
< data
->realY
) {
686 if (data
->bottomIndex
> 0 && newY
< WBOTTOM(data
->bottomList
[data
->bottomIndex
- 1])) {
688 } else if (data
->topIndex
<= data
->count
- 1
689 && newY2
<= WTOP(data
->topList
[data
->topIndex
])) {
692 } else if (newY
> data
->realY
) {
693 if (data
->topIndex
> 0 && newY2
> WTOP(data
->topList
[data
->topIndex
- 1])) {
695 } else if (data
->bottomIndex
<= data
->count
- 1
696 && newY
>= WBOTTOM(data
->bottomList
[data
->bottomIndex
])) {
705 /* TODO: optimize this */
706 if (data
->realY
< WBOTTOM(data
->bottomList
[0])) {
707 data
->bottomIndex
= 0;
709 if (data
->realX
< WRIGHT(data
->rightList
[0])) {
710 data
->rightIndex
= 0;
712 if ((data
->realX
+ data
->winWidth
) > WLEFT(data
->leftList
[0])) {
715 if ((data
->realY
+ data
->winHeight
) > WTOP(data
->topList
[0])) {
718 for (i
= 0; i
< data
->count
; i
++) {
719 if (data
->realY
> WBOTTOM(data
->bottomList
[i
])) {
720 data
->bottomIndex
= i
+ 1;
722 if (data
->realX
> WRIGHT(data
->rightList
[i
])) {
723 data
->rightIndex
= i
+ 1;
725 if ((data
->realX
+ data
->winWidth
) < WLEFT(data
->leftList
[i
])) {
726 data
->leftIndex
= i
+ 1;
728 if ((data
->realY
+ data
->winHeight
) < WTOP(data
->topList
[i
])) {
729 data
->topIndex
= i
+ 1;
734 static void freeMoveData(MoveData
* data
)
737 wfree(data
->topList
);
739 wfree(data
->leftList
);
741 wfree(data
->rightList
);
742 if (data
->bottomList
)
743 wfree(data
->bottomList
);
746 static void updateMoveData(WWindow
* wwin
, MoveData
* data
)
748 WScreen
*scr
= wwin
->screen_ptr
;
753 tmp
= scr
->focused_window
;
755 if (tmp
!= wwin
&& scr
->current_workspace
== tmp
->frame
->workspace
756 && !tmp
->flags
.miniaturized
757 && !tmp
->flags
.hidden
&& !tmp
->flags
.obscured
&& !WFLAGP(tmp
, sunken
)) {
758 data
->topList
[data
->count
] = tmp
;
759 data
->leftList
[data
->count
] = tmp
;
760 data
->rightList
[data
->count
] = tmp
;
761 data
->bottomList
[data
->count
] = tmp
;
767 if (data
->count
== 0) {
770 data
->rightIndex
= 0;
771 data
->bottomIndex
= 0;
775 /* order from closest to the border of the screen to farthest */
777 qsort(data
->topList
, data
->count
, sizeof(data
->topList
[0]), compareWTop
);
778 qsort(data
->leftList
, data
->count
, sizeof(data
->leftList
[0]), compareWLeft
);
779 qsort(data
->rightList
, data
->count
, sizeof(data
->rightList
[0]), compareWRight
);
780 qsort(data
->bottomList
, data
->count
, sizeof(data
->bottomList
[0]), compareWBottom
);
782 /* figure the position of the window relative to the others */
785 data
->leftIndex
= -1;
786 data
->rightIndex
= -1;
787 data
->bottomIndex
= -1;
789 if (WTOP(wwin
) < WBOTTOM(data
->bottomList
[0])) {
790 data
->bottomIndex
= 0;
792 if (WLEFT(wwin
) < WRIGHT(data
->rightList
[0])) {
793 data
->rightIndex
= 0;
795 if (WRIGHT(wwin
) > WLEFT(data
->leftList
[0])) {
798 if (WBOTTOM(wwin
) > WTOP(data
->topList
[0])) {
801 for (i
= 0; i
< data
->count
; i
++) {
802 if (WTOP(wwin
) >= WBOTTOM(data
->bottomList
[i
])) {
803 data
->bottomIndex
= i
+ 1;
805 if (WLEFT(wwin
) >= WRIGHT(data
->rightList
[i
])) {
806 data
->rightIndex
= i
+ 1;
808 if (WRIGHT(wwin
) <= WLEFT(data
->leftList
[i
])) {
809 data
->leftIndex
= i
+ 1;
811 if (WBOTTOM(wwin
) <= WTOP(data
->topList
[i
])) {
812 data
->topIndex
= i
+ 1;
817 static void initMoveData(WWindow
* wwin
, MoveData
* data
)
822 memset(data
, 0, sizeof(MoveData
));
824 for (i
= 0, tmp
= wwin
->screen_ptr
->focused_window
; tmp
!= NULL
; tmp
= tmp
->prev
, i
++) ;
827 data
->topList
= wmalloc(sizeof(WWindow
*) * i
);
828 data
->leftList
= wmalloc(sizeof(WWindow
*) * i
);
829 data
->rightList
= wmalloc(sizeof(WWindow
*) * i
);
830 data
->bottomList
= wmalloc(sizeof(WWindow
*) * i
);
832 updateMoveData(wwin
, data
);
835 data
->realX
= wwin
->frame_x
;
836 data
->realY
= wwin
->frame_y
;
837 data
->calcX
= wwin
->frame_x
;
838 data
->calcY
= wwin
->frame_y
;
840 data
->winWidth
= wwin
->frame
->core
->width
+ (HAS_BORDER_WITH_SELECT(wwin
) ? 2 * wwin
->screen_ptr
->frame_border_width
: 0);
841 data
->winHeight
= wwin
->frame
->core
->height
+ (HAS_BORDER_WITH_SELECT(wwin
) ? 2 * wwin
->screen_ptr
->frame_border_width
: 0);
843 data
->snap
= SNAP_NONE
;
846 static Bool
checkWorkspaceChange(WWindow
* wwin
, MoveData
* data
, Bool opaqueMove
)
848 WScreen
*scr
= wwin
->screen_ptr
;
849 Bool changed
= False
;
851 if (data
->mouseX
<= 1) {
852 if (scr
->current_workspace
> 0) {
853 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
- 1, True
);
856 } else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
) {
857 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->workspace_count
- 1, True
);
861 } else if (data
->mouseX
>= scr
->scr_width
- 2) {
862 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
863 if (wPreferences
.ws_cycle
|| scr
->workspace_count
== MAX_WORKSPACES
) {
864 crossWorkspace(scr
, wwin
, opaqueMove
, 0, False
);
868 /* if user insists on trying to go to next workspace even when
869 * it's already the last, create a new one */
870 else if (data
->omouseX
== data
->mouseX
&& wPreferences
.ws_advance
) {
872 /* detect user "rubbing" the window against the edge */
873 if (data
->rubCount
> 0 && data
->omouseY
- data
->mouseY
> MOVE_THRESHOLD
) {
875 data
->rubCount
= -(data
->rubCount
+ 1);
877 } else if (data
->rubCount
<= 0 && data
->mouseY
- data
->omouseY
> MOVE_THRESHOLD
) {
879 data
->rubCount
= -data
->rubCount
+ 1;
882 /* create a new workspace */
883 if (abs(data
->rubCount
) > 2) {
884 /* go to next workspace */
887 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
+ 1, False
);
891 } else if (scr
->current_workspace
< scr
->workspace_count
) {
892 /* go to next workspace */
893 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
+ 1, False
);
905 updateWindowPosition(WWindow
* wwin
, MoveData
* data
, Bool doResistance
,
906 Bool opaqueMove
, int newMouseX
, int newMouseY
)
908 WScreen
*scr
= wwin
->screen_ptr
;
909 int dx
, dy
; /* how much mouse moved */
910 int winL
, winR
, winT
, winB
; /* requested new window position */
911 int newX
, newY
; /* actual new window position */
912 Bool hresist
, vresist
;
918 /* check the direction of the movement */
919 dx
= newMouseX
- data
->mouseX
;
920 dy
= newMouseY
- data
->mouseY
;
922 data
->omouseX
= data
->mouseX
;
923 data
->omouseY
= data
->mouseY
;
924 data
->mouseX
= newMouseX
;
925 data
->mouseY
= newMouseY
;
927 winL
= data
->calcX
+ dx
;
928 winR
= data
->calcX
+ data
->winWidth
+ dx
;
929 winT
= data
->calcY
+ dy
;
930 winB
= data
->calcY
+ data
->winHeight
+ dy
;
942 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
943 attract
= wPreferences
.attract
;
944 /* horizontal movement: check horizontal edge resistances */
948 /* window is the leftmost window: check against screen edge */
950 /* Add inter head resistance 1/2 (if needed) */
951 head
= wGetHeadForPointerLocation(scr
);
952 rect
= wGetRectForHead(scr
, head
);
954 l_edge
= WMAX(scr
->totalUsableArea
[head
].x1
, rect
.pos
.x
);
955 edge_l
= l_edge
- resist
;
956 edge_r
= WMIN(scr
->totalUsableArea
[head
].x2
, rect
.pos
.x
+ rect
.size
.width
);
957 r_edge
= edge_r
+ resist
;
960 if ((data
->rightIndex
>= 0) && (data
->rightIndex
<= data
->count
)) {
963 for (i
= data
->rightIndex
- 1; i
>= 0; i
--) {
964 looprw
= data
->rightList
[i
];
965 if (!(data
->realY
> WBOTTOM(looprw
)
966 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
967 if (attract
|| ((data
->realX
< (WRIGHT(looprw
) + 2)) && dx
< 0)) {
968 l_edge
= WRIGHT(looprw
) + 1;
969 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
976 for (i
= data
->rightIndex
; i
< data
->count
; i
++) {
977 looprw
= data
->rightList
[i
];
978 if (!(data
->realY
> WBOTTOM(looprw
)
979 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
980 r_edge
= WRIGHT(looprw
) + 1;
981 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
988 if ((data
->leftIndex
>= 0) && (data
->leftIndex
<= data
->count
)) {
991 for (i
= data
->leftIndex
- 1; i
>= 0; i
--) {
992 looprw
= data
->leftList
[i
];
993 if (!(data
->realY
> WBOTTOM(looprw
)
994 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
996 || (((data
->realX
+ data
->winWidth
) > (WLEFT(looprw
) - 1))
998 edge_r
= WLEFT(looprw
);
999 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1006 for (i
= data
->leftIndex
; i
< data
->count
; i
++) {
1007 looprw
= data
->leftList
[i
];
1008 if (!(data
->realY
> WBOTTOM(looprw
)
1009 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1010 edge_l
= WLEFT(looprw
);
1011 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1018 printf("%d %d\n",winL,winR);
1019 printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);
1022 if ((winL
- l_edge
) < (r_edge
- winL
)) {
1024 if ((attract
&& winL
<= l_edge
+ resist
&& winL
>= l_edge
- resist
)
1025 || (dx
< 0 && winL
<= l_edge
&& winL
>= l_edge
- resist
)) {
1031 if (resist
> 0 && attract
&& winL
>= r_edge
- resist
&& winL
<= r_edge
+ resist
) {
1037 if ((winR
- edge_l
) < (edge_r
- winR
)) {
1038 if (resist
> 0 && attract
&& winR
<= edge_l
+ resist
&& winR
>= edge_l
- resist
) {
1039 newX
= edge_l
- data
->winWidth
;
1044 if ((attract
&& winR
>= edge_r
- resist
&& winR
<= edge_r
+ resist
)
1045 || (dx
> 0 && winR
>= edge_r
&& winR
<= edge_r
+ resist
)) {
1046 newX
= edge_r
- data
->winWidth
;
1053 /* Add inter head resistance 2/2 (if needed) */
1054 t_edge
= WMAX(scr
->totalUsableArea
[head
].y1
, rect
.pos
.y
);
1055 edge_t
= t_edge
- resist
;
1056 edge_b
= WMIN(scr
->totalUsableArea
[head
].y2
, rect
.pos
.y
+ rect
.size
.height
);
1057 b_edge
= edge_b
+ resist
;
1059 if ((data
->bottomIndex
>= 0) && (data
->bottomIndex
<= data
->count
)) {
1062 for (i
= data
->bottomIndex
- 1; i
>= 0; i
--) {
1063 looprw
= data
->bottomList
[i
];
1064 if (!(data
->realX
> WRIGHT(looprw
)
1065 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1066 if (attract
|| ((data
->realY
< (WBOTTOM(looprw
) + 2)) && dy
< 0)) {
1067 t_edge
= WBOTTOM(looprw
) + 1;
1068 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1075 for (i
= data
->bottomIndex
; i
< data
->count
; i
++) {
1076 looprw
= data
->bottomList
[i
];
1077 if (!(data
->realX
> WRIGHT(looprw
)
1078 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1079 b_edge
= WBOTTOM(looprw
) + 1;
1080 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1087 if ((data
->topIndex
>= 0) && (data
->topIndex
<= data
->count
)) {
1090 for (i
= data
->topIndex
- 1; i
>= 0; i
--) {
1091 looprw
= data
->topList
[i
];
1092 if (!(data
->realX
> WRIGHT(looprw
)
1093 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1095 || (((data
->realY
+ data
->winHeight
) > (WTOP(looprw
) - 1))
1097 edge_b
= WTOP(looprw
);
1098 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1105 for (i
= data
->topIndex
; i
< data
->count
; i
++) {
1106 looprw
= data
->topList
[i
];
1107 if (!(data
->realX
> WRIGHT(looprw
)
1108 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1109 edge_t
= WTOP(looprw
);
1110 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1116 if ((winT
- t_edge
) < (b_edge
- winT
)) {
1118 if ((attract
&& winT
<= t_edge
+ resist
&& winT
>= t_edge
- resist
)
1119 || (dy
< 0 && winT
<= t_edge
&& winT
>= t_edge
- resist
)) {
1125 if (resist
> 0 && attract
&& winT
>= b_edge
- resist
&& winT
<= b_edge
+ resist
) {
1131 if ((winB
- edge_t
) < (edge_b
- winB
)) {
1132 if (resist
> 0 && attract
&& winB
<= edge_t
+ resist
&& winB
>= edge_t
- resist
) {
1133 newY
= edge_t
- data
->winHeight
;
1138 if ((attract
&& winB
>= edge_b
- resist
&& winB
<= edge_b
+ resist
)
1139 || (dy
> 0 && winB
>= edge_b
&& winB
<= edge_b
+ resist
)) {
1140 newY
= edge_b
- data
->winHeight
;
1150 /* update window position */
1154 if (((dx
> 0 && data
->calcX
- data
->realX
> 0)
1155 || (dx
< 0 && data
->calcX
- data
->realX
< 0)) && !hresist
)
1158 if (((dy
> 0 && data
->calcY
- data
->realY
> 0)
1159 || (dy
< 0 && data
->calcY
- data
->realY
< 0)) && !vresist
)
1162 if (data
->realX
!= newX
|| data
->realY
!= newY
) {
1164 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1165 showPosition(wwin
, data
->realX
, data
->realY
);
1168 doWindowMove(wwin
, scr
->selected_windows
, newX
- wwin
->frame_x
, newY
- wwin
->frame_y
);
1171 drawFrames(wwin
, scr
->selected_windows
,
1172 data
->realX
- wwin
->frame_x
, data
->realY
- wwin
->frame_y
);
1175 if (!scr
->selected_windows
&& wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
1177 moveGeometryDisplayCentered(scr
, newX
+ data
->winWidth
/ 2, newY
+ data
->winHeight
/ 2);
1182 drawFrames(wwin
, scr
->selected_windows
, newX
- wwin
->frame_x
, newY
- wwin
->frame_y
);
1185 if (!scr
->selected_windows
) {
1186 showPosition(wwin
, newX
, newY
);
1190 /* recalc relative window position */
1191 if (doResistance
&& (data
->realX
!= newX
|| data
->realY
!= newY
)) {
1192 updateResistance(data
, newX
, newY
);
1199 static void draw_snap_frame(WWindow
*wwin
, int direction
)
1203 scr
= wwin
->screen_ptr
;
1205 switch (direction
) {
1207 drawTransparentFrame(wwin
, 0, 0, scr
->scr_width
/2, scr
->scr_height
);
1211 drawTransparentFrame(wwin
, scr
->scr_width
/2, 0, scr
->scr_width
/2, scr
->scr_height
);
1215 drawTransparentFrame(wwin
, 0, 0, scr
->scr_width
, scr
->scr_height
/2);
1219 drawTransparentFrame(wwin
, 0, scr
->scr_height
/2, scr
->scr_width
, scr
->scr_height
/2);
1223 drawTransparentFrame(wwin
, 0, 0, scr
->scr_width
/2, scr
->scr_height
/2);
1227 drawTransparentFrame(wwin
, scr
->scr_width
/2, 0, scr
->scr_width
/2, scr
->scr_height
/2);
1230 case SNAP_BOTTOMLEFT
:
1231 drawTransparentFrame(wwin
, 0, scr
->scr_height
/2, scr
->scr_width
/2, scr
->scr_height
/2);
1234 case SNAP_BOTTOMRIGHT
:
1235 drawTransparentFrame(wwin
, scr
->scr_width
/2, scr
->scr_height
/2,
1236 scr
->scr_width
/2, scr
->scr_height
/2);
1241 static int get_snap_direction(WScreen
*scr
, int x
, int y
)
1245 edge
= wPreferences
.snap_edge_detect
;
1246 corner
= wPreferences
.snap_corner_detect
;
1248 if (x
< corner
&& y
< corner
)
1249 return SNAP_TOPLEFT
;
1250 if (x
< corner
&& y
>= scr
->scr_height
- corner
)
1251 return SNAP_BOTTOMLEFT
;
1255 if (x
>= scr
->scr_width
- corner
&& y
< corner
)
1256 return SNAP_TOPRIGHT
;
1257 if (x
>= scr
->scr_width
- corner
&& y
>= scr
->scr_height
- corner
)
1258 return SNAP_BOTTOMRIGHT
;
1259 if (x
>= scr
->scr_width
- edge
)
1264 if (y
>= scr
->scr_height
- edge
)
1269 static void do_snap(WWindow
*wwin
, MoveData
*data
, Bool opaqueMove
)
1275 scr
= wwin
->screen_ptr
;
1279 drawFrames(wwin
, scr
->selected_windows
, data
->realX
- wwin
->frame_x
, data
->realY
- wwin
->frame_y
);
1280 draw_snap_frame(wwin
, data
->snap
);
1282 switch (data
->snap
) {
1286 directions
= MAX_VERTICAL
| MAX_LEFTHALF
;
1289 directions
= MAX_VERTICAL
| MAX_RIGHTHALF
;
1292 directions
= MAX_HORIZONTAL
| MAX_TOPHALF
;
1295 directions
= MAX_HORIZONTAL
| MAX_BOTTOMHALF
;
1298 directions
= MAX_TOPHALF
| MAX_LEFTHALF
;
1301 directions
= MAX_TOPHALF
| MAX_RIGHTHALF
;
1303 case SNAP_BOTTOMLEFT
:
1304 directions
= MAX_BOTTOMHALF
| MAX_LEFTHALF
;
1306 case SNAP_BOTTOMRIGHT
:
1307 directions
= MAX_BOTTOMHALF
| MAX_RIGHTHALF
;
1312 handleMaximize(wwin
, directions
);
1313 data
->snap
= SNAP_NONE
;
1316 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1318 #define MOVABLE_BIT 0x01
1319 #define RESIZABLE_BIT 0x02
1321 int wKeyboardMoveResizeWindow(WWindow
* wwin
)
1323 WScreen
*scr
= wwin
->screen_ptr
;
1324 Window root
= scr
->root_win
;
1326 int w
= wwin
->frame
->core
->width
;
1327 int h
= wwin
->frame
->core
->height
;
1328 int scr_width
= wwin
->screen_ptr
->scr_width
;
1329 int scr_height
= wwin
->screen_ptr
->scr_height
;
1330 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1331 int src_x
= wwin
->frame_x
;
1332 int src_y
= wwin
->frame_y
;
1335 int done
, off_x
, off_y
, ww
, wh
;
1337 int opaqueMoveResize
= wPreferences
.opaque_move_resize_keyboard
;
1339 KeyCode shiftl
, shiftr
, ctrlmode
;
1340 KeySym keysym
= NoSymbol
;
1342 int modes
= ((IS_MOVABLE(wwin
) ? MOVABLE_BIT
: 0) | (IS_RESIZABLE(wwin
) ? RESIZABLE_BIT
: 0));
1343 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1344 ? wGetHeadForWindow(wwin
)
1345 : scr
->xine_info
.primary_head
);
1347 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1348 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1349 ctrlmode
= done
= off_x
= off_y
= 0;
1351 if (modes
== RESIZABLE_BIT
) {
1357 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1359 if (!wwin
->flags
.selected
) {
1360 wUnselectWindows(scr
);
1363 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1364 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
1365 GrabModeAsync
, None
, wPreferences
.cursor
[WCUR_NORMAL
], CurrentTime
);
1369 if (!opaqueMoveResize
) {
1370 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1371 if (scr
->selected_windows
)
1372 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1374 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1376 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1379 if ((wwin
->flags
.shaded
|| scr
->selected_windows
) && (!scr
->selected_windows
)) {
1380 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1391 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1392 | ButtonPressMask
| ExposureMask
, &event
);
1393 if (event
.type
== Expose
) {
1394 WMHandleEvent(&event
);
1396 } while (event
.type
== Expose
);
1398 if (!opaqueMoveResize
) {
1399 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1400 if (scr
->selected_windows
)
1401 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1403 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1404 /*** I HATE EDGE RESISTANCE - ]d ***/
1406 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1411 showGeometry(wwin
, src_x
+ off_x
, src_y
+ off_y
, src_x
+ off_x
+ ww
, src_y
+ off_y
+ wh
,
1417 switch (event
.type
) {
1420 if (event
.xkey
.time
- lastTime
> 50) {
1421 kspeed
/= (1 + (event
.xkey
.time
- lastTime
) / 100);
1429 lastTime
= event
.xkey
.time
;
1430 if (modes
== (MOVABLE_BIT
| RESIZABLE_BIT
)) {
1431 if ((event
.xkey
.state
& ControlMask
) && !wwin
->flags
.shaded
) {
1433 wUnselectWindows(scr
);
1438 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
) {
1440 cycleGeometryDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
, 0);
1442 cyclePositionDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1445 keysym
= XLookupKeysym(&event
.xkey
, 0);
1505 if (moment
!= RIGHT
)
1517 wWindowConstrainSize(wwin
, (unsigned int *)&ww
, (unsigned int *)&wh
);
1520 if (wPreferences
.ws_cycle
) {
1521 if (src_x
+ off_x
+ ww
< 20) {
1522 if (!scr
->current_workspace
)
1523 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
1525 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
1528 } else if (src_x
+ off_x
+ 20 > scr_width
) {
1529 if (scr
->current_workspace
== scr
->workspace_count
- 1)
1530 wWorkspaceChange(scr
, 0);
1532 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
1537 if (src_x
+ off_x
+ ww
< 20)
1538 off_x
= 20 - ww
- src_x
;
1539 else if (src_x
+ off_x
+ 20 > scr_width
)
1540 off_x
= scr_width
- 20 - src_x
;
1543 if (src_y
+ off_y
+ wh
< 20) {
1544 off_y
= 20 - wh
- src_y
;
1545 } else if (src_y
+ off_y
+ 20 > scr_height
) {
1546 off_y
= scr_height
- 20 - src_y
;
1555 WMHandleEvent(&event
);
1556 while (XCheckTypedEvent(dpy
, Expose
, &event
)) {
1557 WMHandleEvent(&event
);
1562 WMHandleEvent(&event
);
1569 if (wwin
->flags
.shaded
&& !scr
->selected_windows
) {
1570 moveGeometryDisplayCentered(scr
, src_x
+ off_x
+ w
/ 2, src_y
+ off_y
+ h
/ 2);
1573 WMUnmapWidget(scr
->gview
);
1574 mapGeometryDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1575 } else if (!scr
->selected_windows
) {
1576 WMUnmapWidget(scr
->gview
);
1577 mapPositionDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1581 if (!opaqueMoveResize
) {
1582 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1583 if (scr
->selected_windows
)
1584 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1586 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1588 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1593 showGeometry(wwin
, src_x
+ off_x
, src_y
+ off_y
, src_x
+ off_x
+ ww
, src_y
+ off_y
+ wh
,
1595 } else if (!scr
->selected_windows
)
1596 showPosition(wwin
, src_x
+ off_x
, src_y
+ off_y
);
1598 if (opaqueMoveResize
) {
1600 wWindowConfigure(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
- vert_border
);
1604 if (!opaqueMoveResize
) { /* ctrlmode => resize */
1605 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1606 if (scr
->selected_windows
)
1607 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1609 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1611 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1616 showGeometry(wwin
, src_x
+ off_x
, src_y
+ off_y
, src_x
+ off_x
+ ww
,
1617 src_y
+ off_y
+ wh
, 0);
1618 WMUnmapWidget(scr
->gview
);
1620 WMUnmapWidget(scr
->gview
);
1622 XUngrabKeyboard(dpy
, CurrentTime
);
1623 XUngrabPointer(dpy
, CurrentTime
);
1627 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1628 if (!scr
->selected_windows
) {
1629 wWindowMove(wwin
, src_x
+ off_x
, src_y
+ off_y
);
1630 wWindowSynthConfigureNotify(wwin
);
1632 WMArrayIterator iter
;
1635 doWindowMove(wwin
, scr
->selected_windows
, off_x
, off_y
);
1637 WM_ITERATE_ARRAY(scr
->selected_windows
, foo
, iter
) {
1638 wWindowSynthConfigureNotify(foo
);
1642 if (ww
!= original_w
)
1643 wwin
->flags
.maximized
&= ~(MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
1645 if (wh
!= original_h
)
1646 wwin
->flags
.maximized
&= ~(MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
1648 wWindowConfigure(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
- vert_border
);
1649 wWindowSynthConfigureNotify(wwin
);
1651 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1652 wSetFocusTo(scr
, wwin
);
1655 if (wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 &&
1656 head
!= wGetHeadForWindow(wwin
)) {
1657 wArrangeIcons(scr
, True
);
1660 update_saved_geometry(wwin
);
1668 *----------------------------------------------------------------------
1669 * wMouseMoveWindow--
1670 * Move the named window and the other selected ones (if any),
1671 * interactively. Also shows the position of the window, if only one
1672 * window is being moved.
1673 * If the window is not on the selected window list, the selected
1674 * windows are deselected.
1675 * If shift is pressed during the operation, the position display
1676 * is changed to another type.
1679 * True if the window was moved, False otherwise.
1682 * The window(s) position is changed, and the client(s) are
1683 * notified about that.
1684 * The position display configuration may be changed.
1685 *----------------------------------------------------------------------
1687 int wMouseMoveWindow(WWindow
* wwin
, XEvent
* ev
)
1689 WScreen
*scr
= wwin
->screen_ptr
;
1691 Window root
= scr
->root_win
;
1692 KeyCode shiftl
, shiftr
;
1696 /* This needs not to change while moving, else bad things can happen */
1697 int opaqueMove
= wPreferences
.opaque_move
;
1699 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1700 ? wGetHeadForWindow(wwin
)
1701 : scr
->xine_info
.primary_head
);
1703 if (!IS_MOVABLE(wwin
))
1706 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1707 XSetWindowAttributes attr
;
1709 attr
.save_under
= True
;
1710 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
, CWSaveUnder
, &attr
);
1713 initMoveData(wwin
, &moveData
);
1715 moveData
.mouseX
= ev
->xmotion
.x_root
;
1716 moveData
.mouseY
= ev
->xmotion
.y_root
;
1718 if (!wwin
->flags
.selected
) {
1719 /* this window is not selected, unselect others and move only wwin */
1720 wUnselectWindows(scr
);
1722 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1723 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1729 /* XWarpPointer() doesn't seem to generate Motion events, so
1730 * we've got to simulate them */
1731 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1732 &event
.xmotion
.y_root
, &junk
, &junk
, (unsigned *)&junk
);
1734 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1735 | PointerMotionHintMask
1736 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
, &event
);
1738 if (event
.type
== MotionNotify
) {
1739 /* compress MotionNotify events */
1740 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1741 if (!checkMouseSamplingRate(&event
))
1745 switch (event
.type
) {
1747 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1748 && started
&& !scr
->selected_windows
) {
1751 drawFrames(wwin
, scr
->selected_windows
,
1752 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1755 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1756 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1759 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1760 moveData
.winWidth
, moveData
.winHeight
);
1762 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1764 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1768 drawFrames(wwin
, scr
->selected_windows
,
1769 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1772 WMHandleEvent(&event); this causes problems needs fixing */
1777 if (IS_RESIZABLE(wwin
) && wPreferences
.window_snapping
) {
1780 snap_direction
= get_snap_direction(scr
, moveData
.mouseX
, moveData
.mouseY
);
1782 if (!wPreferences
.no_autowrap
&&
1783 snap_direction
!= SNAP_TOP
&&
1784 snap_direction
!= SNAP_BOTTOM
)
1785 snap_direction
= SNAP_NONE
;
1787 if (moveData
.snap
!= snap_direction
) {
1788 /* erase old frame */
1790 draw_snap_frame(wwin
, moveData
.snap
);
1791 /* draw new frame */
1793 draw_snap_frame(wwin
, snap_direction
);
1794 moveData
.snap
= snap_direction
;
1799 /* erase snap frame */
1801 draw_snap_frame(wwin
, moveData
.snap
);
1803 updateWindowPosition(wwin
, &moveData
,
1804 scr
->selected_windows
== NULL
1805 && wPreferences
.edge_resistance
> 0,
1806 opaqueMove
, event
.xmotion
.x_root
, event
.xmotion
.y_root
);
1808 /* redraw snap frame */
1810 draw_snap_frame(wwin
, moveData
.snap
);
1812 if (!warped
&& !wPreferences
.no_autowrap
) {
1813 int oldWorkspace
= scr
->current_workspace
;
1815 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1816 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1820 drawFrames(wwin
, scr
->selected_windows
,
1821 moveData
.realX
- wwin
->frame_x
,
1822 moveData
.realY
- wwin
->frame_y
);
1824 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1825 if (scr
->current_workspace
!= oldWorkspace
1826 && wPreferences
.edge_resistance
> 0
1827 && scr
->selected_windows
== NULL
)
1828 updateMoveData(wwin
, &moveData
);
1832 drawFrames(wwin
, scr
->selected_windows
,
1833 moveData
.realX
- wwin
->frame_x
,
1834 moveData
.realY
- wwin
->frame_y
);
1836 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1838 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1844 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1845 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1847 if (wwin
->flags
.maximized
) {
1848 if (wPreferences
.drag_maximized_window
== DRAGMAX_RESTORE
) {
1849 float titlebar_ratio
;
1852 titlebar_ratio
= (moveData
.mouseX
- wwin
->frame_x
) /
1853 (float)wwin
->frame
->core
->width
;
1854 new_y
= wwin
->frame_y
;
1855 wUnmaximizeWindow(wwin
);
1856 new_x
= moveData
.mouseX
- titlebar_ratio
* wwin
->frame
->core
->width
;
1857 wWindowMove(wwin
, new_x
, new_y
);
1858 moveData
.realX
= moveData
.calcX
= wwin
->frame_x
;
1859 moveData
.realY
= moveData
.calcY
= wwin
->frame_y
;
1861 if (wPreferences
.drag_maximized_window
== DRAGMAX_UNMAXIMIZE
) {
1862 wwin
->flags
.maximized
= 0;
1863 wwin
->flags
.old_maximized
= 0;
1867 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1868 | ButtonReleaseMask
| ButtonPressMask
,
1869 wPreferences
.cursor
[WCUR_MOVE
], CurrentTime
);
1871 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1873 if (!scr
->selected_windows
)
1874 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1875 moveData
.winWidth
, moveData
.winHeight
);
1877 if (started
&& !opaqueMove
)
1878 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1880 if (!opaqueMove
|| (wPreferences
.move_display
== WDIS_NEW
1881 && !scr
->selected_windows
)) {
1883 if (wPreferences
.move_display
== WDIS_NEW
)
1884 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1894 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1901 do_snap(wwin
, &moveData
, opaqueMove
);
1902 else if (!opaqueMove
) {
1903 drawFrames(wwin
, scr
->selected_windows
,
1904 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1906 doWindowMove(wwin
, scr
->selected_windows
,
1907 moveData
.realX
- wwin
->frame_x
,
1908 moveData
.realY
- wwin
->frame_y
);
1910 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1911 wWindowSynthConfigureNotify(wwin
);
1913 XUngrabKeyboard(dpy
, CurrentTime
);
1916 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1917 wSetFocusTo(scr
, wwin
);
1919 if (wPreferences
.move_display
== WDIS_NEW
)
1920 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1922 /* discard all enter/leave events that happened until
1923 * the time the button was released */
1924 while (XCheckTypedEvent(dpy
, EnterNotify
, &e
)) {
1925 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1926 XPutBackEvent(dpy
, &e
);
1930 while (XCheckTypedEvent(dpy
, LeaveNotify
, &e
)) {
1931 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1932 XPutBackEvent(dpy
, &e
);
1937 if (!scr
->selected_windows
) {
1938 /* get rid of the geometry window */
1939 WMUnmapWidget(scr
->gview
);
1946 if (started
&& !opaqueMove
) {
1947 drawFrames(wwin
, scr
->selected_windows
,
1948 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1950 WMHandleEvent(&event
);
1953 drawFrames(wwin
, scr
->selected_windows
,
1954 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1956 WMHandleEvent(&event
);
1962 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1963 XSetWindowAttributes attr
;
1965 attr
.save_under
= False
;
1966 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
, CWSaveUnder
, &attr
);
1970 freeMoveData(&moveData
);
1972 if (started
&& wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 &&
1973 head
!= wGetHeadForWindow(wwin
)) {
1974 wArrangeIcons(scr
, True
);
1978 update_saved_geometry(wwin
);
1984 #define HCONSTRAIN 2
1986 static int getResizeDirection(WWindow
* wwin
, int x
, int y
, int dy
, int flags
)
1988 int w
= wwin
->frame
->core
->width
- 1;
1989 int cw
= wwin
->frame
->resizebar_corner_width
;
1992 /* if not resizing through the resizebar */
1993 if (!(flags
& RESIZEBAR
)) {
1995 int xdir
= (abs(x
) < (wwin
->client
.width
/ 2)) ? LEFT
: RIGHT
;
1996 int ydir
= (abs(y
) < (wwin
->client
.height
/ 2)) ? UP
: DOWN
;
1998 /* How much resize space is allowed */
1999 int spacew
= abs(wwin
->client
.width
/ 3);
2000 int spaceh
= abs(wwin
->client
.height
/ 3);
2002 /* Determine where x fits */
2003 if ((abs(x
) > wwin
->client
.width
/2 - spacew
/2) &&
2004 (abs(x
) < wwin
->client
.width
/2 + spacew
/2)) {
2005 /* Resize vertically */
2007 } else if ((abs(y
) > wwin
->client
.height
/2 - spaceh
/2) &&
2008 (abs(y
) < wwin
->client
.height
/2 + spaceh
/2)) {
2009 /* Resize horizontally */
2012 return (xdir
| ydir
);
2015 /* window is too narrow. allow diagonal resize */
2019 if (flags
& HCONSTRAIN
)
2024 return (LEFT
| ydir
);
2026 return (RIGHT
| ydir
);
2028 /* vertical resize */
2029 if ((x
> cw
) && (x
< w
- cw
))
2037 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
2043 void wMouseResizeWindow(WWindow
* wwin
, XEvent
* ev
)
2046 WScreen
*scr
= wwin
->screen_ptr
;
2047 Window root
= scr
->root_win
;
2048 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2049 int fw
= wwin
->frame
->core
->width
;
2050 int fh
= wwin
->frame
->core
->height
;
2051 int fx
= wwin
->frame_x
;
2052 int fy
= wwin
->frame_y
;
2053 int is_resizebar
= (wwin
->frame
->resizebar
&& ev
->xany
.window
== wwin
->frame
->resizebar
->window
);
2057 int rw
= fw
, rh
= fh
;
2058 int rx1
, ry1
, rx2
, ry2
;
2060 KeyCode shiftl
, shiftr
;
2065 int original_fw
= fw
;
2066 int original_fh
= fh
;
2067 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
2068 ? wGetHeadForWindow(wwin
)
2069 : scr
->xine_info
.primary_head
);
2070 int opaqueResize
= wPreferences
.opaque_resize
;
2072 if (!IS_RESIZABLE(wwin
))
2075 if (wwin
->flags
.shaded
) {
2076 wwarning("internal error: tryein");
2079 orig_x
= ev
->xbutton
.x_root
;
2080 orig_y
= ev
->xbutton
.y_root
;
2083 wUnselectWindows(scr
);
2088 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2089 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2092 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
2093 | ButtonReleaseMask
| PointerMotionHintMask
| ButtonPressMask
| ExposureMask
, &event
);
2094 if (!checkMouseSamplingRate(&event
))
2097 switch (event
.type
) {
2099 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2100 if (!opaqueResize
) {
2101 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
2103 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2104 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
2105 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2108 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2113 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
2124 dw
= orig_x
- event
.xmotion
.x_root
;
2125 else if (res
& RIGHT
)
2126 dw
= event
.xmotion
.x_root
- orig_x
;
2128 dh
= orig_y
- event
.xmotion
.y_root
;
2129 else if (res
& DOWN
)
2130 dh
= event
.xmotion
.y_root
- orig_y
;
2132 orig_x
= event
.xmotion
.x_root
;
2133 orig_y
= event
.xmotion
.y_root
;
2138 fh
= rh
- vert_border
;
2139 wWindowConstrainSize(wwin
, (unsigned int *)&fw
, (unsigned int *)&fh
);
2143 else if (res
& RIGHT
)
2147 else if (res
& DOWN
)
2149 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
2150 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
2155 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
2156 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
2158 /* check if resizing through resizebar */
2164 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
2165 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
2166 flags
|= HCONSTRAIN
;
2168 res
= getResizeDirection(wwin
, tx
, ty
, orig_y
- event
.xmotion
.y_root
, flags
);
2170 if (res
== (UP
| LEFT
))
2171 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2172 | ButtonReleaseMask
| ButtonPressMask
,
2173 wPreferences
.cursor
[WCUR_TOPLEFTRESIZE
], CurrentTime
);
2174 else if (res
== (UP
| RIGHT
))
2175 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2176 | ButtonReleaseMask
| ButtonPressMask
,
2177 wPreferences
.cursor
[WCUR_TOPRIGHTRESIZE
], CurrentTime
);
2178 else if (res
== (DOWN
| LEFT
))
2179 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2180 | ButtonReleaseMask
| ButtonPressMask
,
2181 wPreferences
.cursor
[WCUR_BOTTOMLEFTRESIZE
], CurrentTime
);
2182 else if (res
== (DOWN
| RIGHT
))
2183 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2184 | ButtonReleaseMask
| ButtonPressMask
,
2185 wPreferences
.cursor
[WCUR_BOTTOMRIGHTRESIZE
], CurrentTime
);
2186 else if (res
== DOWN
|| res
== UP
)
2187 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2188 | ButtonReleaseMask
| ButtonPressMask
,
2189 wPreferences
.cursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2190 else if (res
& (DOWN
| UP
))
2191 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2192 | ButtonReleaseMask
| ButtonPressMask
,
2193 wPreferences
.cursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2194 else if (res
& (LEFT
| RIGHT
))
2195 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2196 | ButtonReleaseMask
| ButtonPressMask
,
2197 wPreferences
.cursor
[WCUR_HORIZONRESIZE
], CurrentTime
);
2199 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2203 /* Draw the resize frame for the first time. */
2204 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
2207 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2209 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2215 drawTransparentFrame(wwin
, orig_fx
, orig_fy
, orig_fw
, orig_fh
);
2217 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
)
2218 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
2221 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2223 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
2224 if (wPreferences
.size_display
== WDIS_NEW
)
2225 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
2226 orig_fy
+ orig_fh
, res
);
2228 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2232 /* Fist clean the geometry line */
2233 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2234 /* Now, continue drawing */
2236 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
2237 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
2238 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2247 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2251 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2254 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2256 XUngrabKeyboard(dpy
, CurrentTime
);
2257 WMUnmapWidget(scr
->gview
);
2260 if (fw
!= original_fw
)
2261 wwin
->flags
.maximized
&= ~(MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
2263 if (fh
!= original_fh
)
2264 wwin
->flags
.maximized
&= ~(MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
2266 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
2267 wWindowSynthConfigureNotify(wwin
);
2272 WMHandleEvent(&event
);
2276 if (wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 && head
!= wGetHeadForWindow(wwin
))
2277 wArrangeIcons(scr
, True
);
2287 void wUnselectWindows(WScreen
* scr
)
2291 if (!scr
->selected_windows
)
2294 while (WMGetArrayItemCount(scr
->selected_windows
)) {
2295 wwin
= WMGetFromArray(scr
->selected_windows
, 0);
2296 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
2297 wIconSelect(wwin
->icon
);
2299 wSelectWindow(wwin
, False
);
2301 WMFreeArray(scr
->selected_windows
);
2302 scr
->selected_windows
= NULL
;
2305 static void selectWindowsInside(WScreen
* scr
, int x1
, int y1
, int x2
, int y2
)
2309 /* select the windows and put them in the selected window list */
2310 tmpw
= scr
->focused_window
;
2311 while (tmpw
!= NULL
) {
2312 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
2313 if ((tmpw
->frame
->workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(tmpw
))
2314 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
2315 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
2316 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
2317 wSelectWindow(tmpw
, True
);
2324 void wSelectWindows(WScreen
* scr
, XEvent
* ev
)
2327 Window root
= scr
->root_win
;
2328 GC gc
= scr
->frame_gc
;
2329 int xp
= ev
->xbutton
.x_root
;
2330 int yp
= ev
->xbutton
.y_root
;
2334 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
2335 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
2336 GrabModeAsync
, None
, wPreferences
.cursor
[WCUR_NORMAL
], CurrentTime
) != Success
) {
2341 wUnselectWindows(scr
);
2343 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
2345 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
| ButtonPressMask
, &event
);
2347 switch (event
.type
) {
2349 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2350 x
= event
.xmotion
.x_root
;
2357 y
= event
.xmotion
.y_root
;
2364 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2371 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2374 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2376 XUngrabPointer(dpy
, CurrentTime
);
2377 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
2381 WMHandleEvent(&event
);
2387 void InteractivePlaceWindow(WWindow
* wwin
, int *x_ret
, int *y_ret
, unsigned width
, unsigned height
)
2389 WScreen
*scr
= wwin
->screen_ptr
;
2390 Window root
= scr
->root_win
;
2393 KeyCode shiftl
, shiftr
;
2397 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2398 GrabModeAsync
, GrabModeAsync
, None
, wPreferences
.cursor
[WCUR_NORMAL
], CurrentTime
) != Success
) {
2403 if (HAS_TITLEBAR(wwin
)) {
2404 h
= WMFontHeight(scr
->title_font
) + (wPreferences
.window_title_clearance
+
2405 TITLEBAR_EXTEND_SPACE
) * 2;
2407 if (h
> wPreferences
.window_title_max_height
)
2408 h
= wPreferences
.window_title_max_height
;
2410 if (h
< wPreferences
.window_title_min_height
)
2411 h
= wPreferences
.window_title_min_height
;
2415 if (HAS_RESIZEBAR(wwin
)) {
2416 height
+= RESIZEBAR_HEIGHT
;
2418 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2419 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
, (unsigned *)&junk
);
2420 mapPositionDisplay(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2422 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2424 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2425 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2427 WMMaskEvent(dpy
, PointerMotionMask
| ButtonPressMask
| ExposureMask
| KeyPressMask
, &event
);
2429 if (!checkMouseSamplingRate(&event
))
2432 switch (event
.type
) {
2434 if ((event
.xkey
.keycode
== shiftl
)
2435 || (event
.xkey
.keycode
== shiftr
)) {
2436 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2437 cyclePositionDisplay(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2438 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2443 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2445 x
= event
.xmotion
.x_root
;
2446 y
= event
.xmotion
.y_root
;
2448 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2449 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2451 showPosition(wwin
, x
- width
/ 2, y
- h
/ 2);
2453 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2458 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2460 *x_ret
= x
- width
/ 2;
2462 XUngrabPointer(dpy
, CurrentTime
);
2463 XUngrabKeyboard(dpy
, CurrentTime
);
2464 /* get rid of the geometry window */
2465 WMUnmapWidget(scr
->gview
);
2469 WMHandleEvent(&event
);