2 * Window Maker window manager
4 * Copyright (c) 1997, 1998, 1999 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
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25 #include <X11/Xutil.h>
26 #include <X11/keysym.h>
32 #include "WindowMaker.h"
41 #include "workspace.h"
50 /* How many different types of geometry/position
51 display thingies are there? */
52 #define NUM_DISPLAYS 4
56 #define HORIZONTAL (LEFT|RIGHT)
59 #define VERTICAL (UP|DOWN)
61 /****** Global Variables ******/
62 extern Time LastTimestamp
;
64 extern Cursor wCursor
[WCUR_LAST
];
66 extern WPreferences wPreferences
;
68 extern Atom _XA_WM_PROTOCOLS
;
73 *----------------------------------------------------------------------
74 * checkMouseSamplingRate-
75 * For lowering the mouse motion sampling rate for machines where
76 * it's too high (SGIs). If it returns False then the event should be
78 *----------------------------------------------------------------------
81 checkMouseSamplingRate(XEvent
*ev
)
83 static Time previousMotion
= 0;
85 if (ev
->type
== MotionNotify
) {
86 if (ev
->xmotion
.time
- previousMotion
< DELAY_BETWEEN_MOUSE_SAMPLING
) {
89 previousMotion
= ev
->xmotion
.time
;
98 *----------------------------------------------------------------------
99 * moveGeometryDisplayCentered
101 * routine that moves the geometry/position window on scr so it is
102 * centered over the given coordinates (x,y). Also the window position
103 * is clamped so it stays on the screen at all times.
104 *----------------------------------------------------------------------
107 moveGeometryDisplayCentered(WScreen
*scr
, int x
, int y
)
109 unsigned int w
= WMWidgetWidth(scr
->gview
);
110 unsigned int h
= WMWidgetHeight(scr
->gview
);
117 else if (x
> (scr
->scr_width
- w
- 3))
118 x
= scr
->scr_width
- w
- 3;
122 else if (y
> (scr
->scr_height
- h
- 3))
123 y
= scr
->scr_height
- h
- 3;
125 WMMoveWidget(scr
->gview
, x
, y
);
130 showPosition(WWindow
*wwin
, int x
, int y
)
132 WScreen
*scr
= wwin
->screen_ptr
;
134 if (wPreferences
.move_display
== WDIS_NEW
) {
136 int width
= wwin
->frame
->core
->width
;
137 int height
= wwin
->frame
->core
->height
;
139 GC lgc
= scr
->line_gc
;
140 XSetForeground(dpy
, lgc
, scr
->line_pixel
);
141 sprintf(num
, "%i", x
);
143 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
-1, scr
->scr_width
, y
-1);
144 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
+height
+2, scr
->scr_width
,
146 XDrawLine(dpy
, scr
->root_win
, lgc
, x
-1, 0, x
-1, scr
->scr_height
);
147 XDrawLine(dpy
, scr
->root_win
, lgc
, x
+width
+2, 0, x
+width
+2,
151 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
157 cyclePositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
159 WScreen
*scr
= wwin
->screen_ptr
;
161 wPreferences
.move_display
++;
162 wPreferences
.move_display
%= NUM_DISPLAYS
;
164 if (wPreferences
.move_display
== WDIS_NEW
) {
165 WMUnmapWidget(scr
->gview
);
167 if (wPreferences
.move_display
== WDIS_CENTER
) {
168 moveGeometryDisplayCentered(scr
,
169 scr
->scr_width
/2, scr
->scr_height
/2);
170 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
171 moveGeometryDisplayCentered(scr
, 1, 1);
172 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
173 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
175 WMMapWidget(scr
->gview
);
181 mapPositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
183 WScreen
*scr
= wwin
->screen_ptr
;
185 if (wPreferences
.move_display
== WDIS_NEW
) {
187 } else if (wPreferences
.move_display
== WDIS_CENTER
) {
188 moveGeometryDisplayCentered(scr
, scr
->scr_width
/ 2,
189 scr
->scr_height
/ 2);
190 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
191 moveGeometryDisplayCentered(scr
, 1, 1);
192 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
193 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
195 WMMapWidget(scr
->gview
);
196 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
201 showGeometry(WWindow
*wwin
, int x1
, int y1
, int x2
, int y2
, int direction
)
203 WScreen
*scr
= wwin
->screen_ptr
;
204 Window root
= scr
->root_win
;
205 GC gc
= scr
->line_gc
;
206 int ty
, by
, my
, x
, y
, mx
, s
;
211 ty
= y1
+ wwin
->frame
->top_width
;
212 by
= y2
- wwin
->frame
->bottom_width
;
213 fw
= WMWidthOfString(scr
->info_text_font
, "8888", 4);
214 fh
= WMFontHeight(scr
->info_text_font
);
216 if (wPreferences
.size_display
== WDIS_NEW
) {
217 XSetForeground(dpy
, gc
, scr
->line_pixel
);
219 /* vertical geometry */
220 if (((direction
& LEFT
) && (x2
< scr
->scr_width
- fw
)) || (x1
< fw
)) {
231 segment
[0].x1
= x
- (s
+ 6); segment
[0].y1
= ty
;
232 segment
[0].x2
= x
- (s
- 10); segment
[0].y2
= ty
;
235 segment
[1].x1
= x
- (s
- 2); segment
[1].y1
= ty
+ 1;
236 segment
[1].x2
= x
- (s
- 5); segment
[1].y2
= ty
+ 7;
238 segment
[2].x1
= x
- (s
- 2); segment
[2].y1
= ty
+ 1;
239 segment
[2].x2
= x
- (s
+ 1); segment
[2].y2
= ty
+ 7;
242 segment
[3].x1
= x
- (s
- 2); segment
[3].y1
= ty
+ 1;
243 segment
[3].x2
= x
- (s
- 2); segment
[3].y2
= my
- fh
/2 - 1;
245 XDrawSegments(dpy
, root
, gc
, segment
, 4);
253 segment
[1].y1
= by
- 1;
254 segment
[1].y2
= by
- 7;
256 segment
[2].y1
= by
- 1;
257 segment
[2].y2
= by
- 7;
260 segment
[3].y1
= my
+ fh
/2 + 2;
261 segment
[3].y2
= by
- 1;
263 XDrawSegments(dpy
, root
, gc
, segment
, 4);
265 sprintf(num
, "%i", (by
- ty
- wwin
->normal_hints
->base_height
) /
266 wwin
->normal_hints
->height_inc
);
267 fw
= WMWidthOfString(scr
->info_text_font
, num
, strlen(num
));
269 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
271 /* Display the height. */
272 WMDrawString(scr
->wmscreen
, root
, gc
, scr
->info_text_font
,
273 x
- s
+ 3 - fw
/2, my
- fh
/2 + 1, num
, strlen(num
));
274 XSetForeground(dpy
, gc
, scr
->line_pixel
);
275 /* horizontal geometry */
283 mx
= x1
+ (x2
- x1
)/2;
284 sprintf(num
, "%i", (x2
- x1
- wwin
->normal_hints
->base_width
) /
285 wwin
->normal_hints
->width_inc
);
286 fw
= WMWidthOfString(scr
->info_text_font
, num
, strlen(num
));
290 segment
[0].x1
= x1
; segment
[0].y1
= y
- (s
+ 6);
291 segment
[0].x2
= x1
; segment
[0].y2
= y
- (s
- 10);
294 segment
[1].x1
= x1
+ 7; segment
[1].y1
= y
- (s
+ 1);
295 segment
[1].x2
= x1
+ 1; segment
[1].y2
= y
- (s
- 2);
297 segment
[2].x1
= x1
+ 1; segment
[2].y1
= y
- (s
- 2);
298 segment
[2].x2
= x1
+ 7; segment
[2].y2
= y
- (s
- 5);
301 segment
[3].x1
= x1
+ 1; segment
[3].y1
= y
- (s
- 2);
302 segment
[3].x2
= mx
- fw
/2 - 2; segment
[3].y2
= y
- (s
- 2);
304 XDrawSegments(dpy
, root
, gc
, segment
, 4);
308 segment
[0].x1
= x2
+ 1;
309 segment
[0].x2
= x2
+ 1;
312 segment
[1].x1
= x2
- 6;
316 segment
[2].x2
= x2
- 6;
319 segment
[3].x1
= mx
+ fw
/2 + 2;
322 XDrawSegments(dpy
, root
, gc
, segment
, 4);
324 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
326 /* Display the width. */
327 WMDrawString(scr
->wmscreen
, root
, gc
, scr
->info_text_font
,
328 mx
- fw
/2 + 1, y
- s
- fh
/2 + 1, num
, strlen(num
));
330 WSetGeometryViewShownSize(scr
->gview
,
331 (x2
- x1
- wwin
->normal_hints
->base_width
)
332 / wwin
->normal_hints
->width_inc
,
333 (by
- ty
- wwin
->normal_hints
->base_height
)
334 / wwin
->normal_hints
->height_inc
);
340 cycleGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
, int dir
)
342 WScreen
*scr
= wwin
->screen_ptr
;
344 wPreferences
.size_display
++;
345 wPreferences
.size_display
%= NUM_DISPLAYS
;
347 if (wPreferences
.size_display
== WDIS_NEW
) {
348 WMUnmapWidget(scr
->gview
);
350 if (wPreferences
.size_display
== WDIS_CENTER
) {
351 moveGeometryDisplayCentered(scr
,
352 scr
->scr_width
/ 2, scr
->scr_height
/ 2);
353 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
354 moveGeometryDisplayCentered(scr
, 1, 1);
355 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
356 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
358 WMMapWidget(scr
->gview
);
359 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, dir
);
365 mapGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
367 WScreen
*scr
= wwin
->screen_ptr
;
369 if (wPreferences
.size_display
== WDIS_NEW
)
372 if (wPreferences
.size_display
== WDIS_CENTER
) {
373 moveGeometryDisplayCentered(scr
, scr
->scr_width
/ 2,
374 scr
->scr_height
/ 2);
375 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
376 moveGeometryDisplayCentered(scr
, 1, 1);
377 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
378 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
380 WMMapWidget(scr
->gview
);
381 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, 0);
387 doWindowMove(WWindow
*wwin
, WMBag
*bag
, int dx
, int dy
)
391 int scr_width
= wwin
->screen_ptr
->scr_width
;
392 int scr_height
= wwin
->screen_ptr
->scr_height
;
394 if (!bag
|| !WMGetBagItemCount(bag
)) {
395 wWindowMove(wwin
, wwin
->frame_x
+ dx
, wwin
->frame_y
+ dy
);
398 for (i
= 0; i
< WMGetBagItemCount(bag
); i
++) {
399 tmpw
= WMGetFromBag(bag
, i
);
400 x
= tmpw
->frame_x
+ dx
;
401 y
= tmpw
->frame_y
+ dy
;
403 /* don't let windows become unreachable */
405 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
406 x
= 20 - (int)tmpw
->frame
->core
->width
;
407 else if (x
+ 20 > scr_width
)
410 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
411 y
= 20 - (int)tmpw
->frame
->core
->height
;
412 else if (y
+ 20 > scr_height
)
415 wWindowMove(tmpw
, x
, y
);
422 drawTransparentFrame(WWindow
*wwin
, int x
, int y
, int width
, int height
)
424 Window root
= wwin
->screen_ptr
->root_win
;
425 GC gc
= wwin
->screen_ptr
->frame_gc
;
429 if (!WFLAGP(wwin
, no_titlebar
) && !wwin
->flags
.shaded
) {
430 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + (wPreferences
.window_title_clearance
+ TITLEBAR_EXTEND_SPACE
) * 2;
432 if (!WFLAGP(wwin
, no_resizebar
) && !wwin
->flags
.shaded
) {
433 /* Can't use wwin-frame->bottom_width because, in some cases
434 (e.g. interactive placement), frame does not point to anything. */
435 bottom
= RESIZEBAR_HEIGHT
- 1;
437 XDrawRectangle(dpy
, root
, gc
, x
, y
, width
+ 1, height
+ 1);
440 XDrawLine(dpy
, root
, gc
, x
+ 1, y
+ h
, x
+ width
+ 1, y
+ h
);
443 XDrawLine(dpy
, root
, gc
, x
+ 1,
446 y
+ height
- bottom
);
452 drawFrames(WWindow
*wwin
, WMBag
*bag
, int dx
, int dy
)
455 int scr_width
= wwin
->screen_ptr
->scr_width
;
456 int scr_height
= wwin
->screen_ptr
->scr_height
;
461 x
= wwin
->frame_x
+ dx
;
462 y
= wwin
->frame_y
+ dy
;
464 drawTransparentFrame(wwin
, x
, y
,
465 wwin
->frame
->core
->width
,
466 wwin
->frame
->core
->height
);
470 for (i
= 0; i
< WMGetBagItemCount(bag
); i
++) {
471 tmpw
= WMGetFromBag(bag
, i
);
472 x
= tmpw
->frame_x
+ dx
;
473 y
= tmpw
->frame_y
+ dy
;
475 /* don't let windows become unreachable */
477 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
478 x
= 20 - (int)tmpw
->frame
->core
->width
;
479 else if (x
+ 20 > scr_width
)
482 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
483 y
= 20 - (int)tmpw
->frame
->core
->height
;
484 else if (y
+ 20 > scr_height
)
487 drawTransparentFrame(tmpw
, x
, y
, tmpw
->frame
->core
->width
,
488 tmpw
->frame
->core
->height
);
501 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &ev
)) ;
506 crossWorkspace(WScreen
*scr
, WWindow
*wwin
, int opaque_move
,
507 int new_workspace
, int rewind
)
509 /* do not let window be unmapped */
511 wwin
->flags
.changing_workspace
= 1;
512 wWindowChangeWorkspace(wwin
, new_workspace
);
514 /* go to new workspace */
515 wWorkspaceChange(scr
, new_workspace
);
517 wwin
->flags
.changing_workspace
= 0;
520 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, scr
->scr_width
- 20, 0);
522 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, -(scr
->scr_width
- 20), 0);
527 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
528 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
529 GrabModeAsync
, None
, wCursor
[WCUR_MOVE
], CurrentTime
);
537 /* arrays of WWindows sorted by the respective border position */
538 WWindow
**topList
; /* top border */
539 WWindow
**leftList
; /* left border */
540 WWindow
**rightList
; /* right border */
541 WWindow
**bottomList
; /* bottom border */
544 /* index of window in the above lists indicating the relative position
545 * of the window with the others */
551 int rubCount
; /* for workspace switching */
553 int winWidth
, winHeight
; /* width/height of the window */
554 int realX
, realY
; /* actual position of the window */
555 int calcX
, calcY
; /* calculated position of window */
556 int omouseX
, omouseY
; /* old mouse position */
557 int mouseX
, mouseY
; /* last known position of the pointer */
560 #define WTOP(w) (w)->frame_y
561 #define WLEFT(w) (w)->frame_x
562 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width + FRAME_BORDER_WIDTH)
563 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height + FRAME_BORDER_WIDTH)
566 compareWTop(const void *a
, const void *b
)
568 WWindow
*wwin1
= *(WWindow
**)a
;
569 WWindow
*wwin2
= *(WWindow
**)b
;
571 if (WTOP(wwin1
) > WTOP(wwin2
))
573 else if (WTOP(wwin1
) < WTOP(wwin2
))
581 compareWLeft(const void *a
, const void *b
)
583 WWindow
*wwin1
= *(WWindow
**)a
;
584 WWindow
*wwin2
= *(WWindow
**)b
;
586 if (WLEFT(wwin1
) > WLEFT(wwin2
))
588 else if (WLEFT(wwin1
) < WLEFT(wwin2
))
596 compareWRight(const void *a
, const void *b
)
598 WWindow
*wwin1
= *(WWindow
**)a
;
599 WWindow
*wwin2
= *(WWindow
**)b
;
601 if (WRIGHT(wwin1
) < WRIGHT(wwin2
))
603 else if (WRIGHT(wwin1
) > WRIGHT(wwin2
))
612 compareWBottom(const void *a
, const void *b
)
614 WWindow
*wwin1
= *(WWindow
**)a
;
615 WWindow
*wwin2
= *(WWindow
**)b
;
617 if (WBOTTOM(wwin1
) < WBOTTOM(wwin2
))
619 else if (WBOTTOM(wwin1
) > WBOTTOM(wwin2
))
627 updateResistance(WWindow
*wwin
, MoveData
*data
, int newX
, int newY
)
630 int newX2
= newX
+ data
->winWidth
;
631 int newY2
= newY
+ data
->winHeight
;
634 if (newX
< data
->realX
) {
635 if (data
->rightIndex
> 0
636 && newX
< WRIGHT(data
->rightList
[data
->rightIndex
-1])) {
638 } else if (data
->leftIndex
<= data
->count
-1
639 && newX2
<= WLEFT(data
->leftList
[data
->leftIndex
])) {
642 } else if (newX
> data
->realX
) {
643 if (data
->leftIndex
> 0
644 && newX2
> WLEFT(data
->leftList
[data
->leftIndex
-1])) {
646 } else if (data
->rightIndex
<= data
->count
-1
647 && newX
>= WRIGHT(data
->rightList
[data
->rightIndex
])) {
653 if (newY
< data
->realY
) {
654 if (data
->bottomIndex
> 0
655 && newY
< WBOTTOM(data
->bottomList
[data
->bottomIndex
-1])) {
657 } else if (data
->topIndex
<= data
->count
-1
658 && newY2
<= WTOP(data
->topList
[data
->topIndex
])) {
661 } else if (newY
> data
->realY
) {
662 if (data
->topIndex
> 0
663 && newY2
> WTOP(data
->topList
[data
->topIndex
-1])) {
665 } else if (data
->bottomIndex
<= data
->count
-1
666 && newY
>= WBOTTOM(data
->bottomList
[data
->bottomIndex
])) {
675 /* TODO: optimize this */
676 if (data
->realY
< WBOTTOM(data
->bottomList
[0])) {
677 data
->bottomIndex
= 0;
679 if (data
->realX
< WRIGHT(data
->rightList
[0])) {
680 data
->rightIndex
= 0;
682 if ((data
->realX
+ data
->winWidth
) > WLEFT(data
->leftList
[0])) {
685 if ((data
->realY
+ data
->winHeight
) > WTOP(data
->topList
[0])) {
688 for (i
= 0; i
< data
->count
; i
++) {
689 if (data
->realY
> WBOTTOM(data
->bottomList
[i
])) {
690 data
->bottomIndex
= i
+ 1;
692 if (data
->realX
> WRIGHT(data
->rightList
[i
])) {
693 data
->rightIndex
= i
+ 1;
695 if ((data
->realX
+ data
->winWidth
) < WLEFT(data
->leftList
[i
])) {
696 data
->leftIndex
= i
+ 1;
698 if ((data
->realY
+ data
->winHeight
) < WTOP(data
->topList
[i
])) {
699 data
->topIndex
= i
+ 1;
706 freeMoveData(MoveData
*data
)
711 free(data
->leftList
);
713 free(data
->rightList
);
714 if (data
->bottomList
)
715 free(data
->bottomList
);
720 updateMoveData(WWindow
*wwin
, MoveData
*data
)
722 WScreen
*scr
= wwin
->screen_ptr
;
727 tmp
= scr
->focused_window
;
729 if (tmp
!= wwin
&& scr
->current_workspace
== tmp
->frame
->workspace
730 && !tmp
->flags
.miniaturized
731 && !tmp
->flags
.hidden
732 && !tmp
->flags
.obscured
733 && !WFLAGP(tmp
, sunken
)) {
734 data
->topList
[data
->count
] = tmp
;
735 data
->leftList
[data
->count
] = tmp
;
736 data
->rightList
[data
->count
] = tmp
;
737 data
->bottomList
[data
->count
] = tmp
;
743 if (data
->count
== 0) {
746 data
->rightIndex
= 0;
747 data
->bottomIndex
= 0;
752 * order from closest to the border of the screen to farthest
754 qsort(data
->topList
, data
->count
, sizeof(WWindow
**), compareWTop
);
755 qsort(data
->leftList
, data
->count
, sizeof(WWindow
**), compareWLeft
);
756 qsort(data
->rightList
, data
->count
, sizeof(WWindow
**), compareWRight
);
757 qsort(data
->bottomList
, data
->count
, sizeof(WWindow
**), compareWBottom
);
759 /* figure the position of the window relative to the others */
762 data
->leftIndex
= -1;
763 data
->rightIndex
= -1;
764 data
->bottomIndex
= -1;
766 if (WTOP(wwin
) < WBOTTOM(data
->bottomList
[0])) {
767 data
->bottomIndex
= 0;
769 if (WLEFT(wwin
) < WRIGHT(data
->rightList
[0])) {
770 data
->rightIndex
= 0;
772 if (WRIGHT(wwin
) > WLEFT(data
->leftList
[0])) {
775 if (WBOTTOM(wwin
) > WTOP(data
->topList
[0])) {
778 for (i
= 0; i
< data
->count
; i
++) {
779 if (WTOP(wwin
) >= WBOTTOM(data
->bottomList
[i
])) {
780 data
->bottomIndex
= i
+ 1;
782 if (WLEFT(wwin
) >= WRIGHT(data
->rightList
[i
])) {
783 data
->rightIndex
= i
+ 1;
785 if (WRIGHT(wwin
) <= WLEFT(data
->leftList
[i
])) {
786 data
->leftIndex
= i
+ 1;
788 if (WBOTTOM(wwin
) <= WTOP(data
->topList
[i
])) {
789 data
->topIndex
= i
+ 1;
796 initMoveData(WWindow
*wwin
, MoveData
*data
)
801 memset(data
, 0, sizeof(MoveData
));
803 for (i
= 0, tmp
= wwin
->screen_ptr
->focused_window
;
805 tmp
= tmp
->prev
, i
++);
808 data
->topList
= wmalloc(sizeof(WWindow
*) * i
);
809 data
->leftList
= wmalloc(sizeof(WWindow
*) * i
);
810 data
->rightList
= wmalloc(sizeof(WWindow
*) * i
);
811 data
->bottomList
= wmalloc(sizeof(WWindow
*) * i
);
813 updateMoveData(wwin
, data
);
816 data
->realX
= wwin
->frame_x
;
817 data
->realY
= wwin
->frame_y
;
818 data
->calcX
= wwin
->frame_x
;
819 data
->calcY
= wwin
->frame_y
;
821 data
->winWidth
= wwin
->frame
->core
->width
+ 2;
822 data
->winHeight
= wwin
->frame
->core
->height
+ 2;
827 checkWorkspaceChange(WWindow
*wwin
, MoveData
*data
, Bool opaqueMove
)
829 WScreen
*scr
= wwin
->screen_ptr
;
830 Bool changed
= False
;
832 if (data
->mouseX
<= 1) {
833 if (scr
->current_workspace
> 0) {
835 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
- 1,
840 } else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
) {
842 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->workspace_count
- 1,
847 } else if (data
->mouseX
>= scr
->scr_width
- 2) {
849 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
851 if (wPreferences
.ws_cycle
852 || scr
->workspace_count
== MAX_WORKSPACES
) {
854 crossWorkspace(scr
, wwin
, opaqueMove
, 0, False
);
858 /* if user insists on trying to go to next workspace even when
859 * it's already the last, create a new one */
860 else if (data
->omouseX
== data
->mouseX
861 && wPreferences
.ws_advance
) {
863 /* detect user "rubbing" the window against the edge */
864 if (data
->rubCount
> 0
865 && data
->omouseY
- data
->mouseY
> MOVE_THRESHOLD
) {
867 data
->rubCount
= -(data
->rubCount
+ 1);
869 } else if (data
->rubCount
<= 0
870 && data
->mouseY
- data
->omouseY
> MOVE_THRESHOLD
) {
872 data
->rubCount
= -data
->rubCount
+ 1;
875 /* create a new workspace */
876 if (abs(data
->rubCount
) > 2) {
877 /* go to next workspace */
880 crossWorkspace(scr
, wwin
, opaqueMove
,
881 scr
->current_workspace
+1, False
);
885 } else if (scr
->current_workspace
< scr
->workspace_count
) {
887 /* go to next workspace */
888 crossWorkspace(scr
, wwin
, opaqueMove
,
889 scr
->current_workspace
+1, False
);
902 updateWindowPosition(WWindow
*wwin
, MoveData
*data
, Bool doResistance
,
903 Bool opaqueMove
, int newMouseX
, int newMouseY
)
905 WScreen
*scr
= wwin
->screen_ptr
;
906 int dx
, dy
; /* how much mouse moved */
907 int winL
, winR
, winT
, winB
; /* requested new window position */
908 int newX
, newY
; /* actual new window position */
909 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 */
947 /* window is the leftmost window: check against screen edge */
948 l_edge
= scr
->totalUsableArea
.x1
;
949 r_edge
= scr
->totalUsableArea
.x2
+ resist
;
950 edge_l
= scr
->totalUsableArea
.x1
- resist
;
951 edge_r
= scr
->totalUsableArea
.x2
;
954 if ((data
->rightIndex
>= 0) && (data
->rightIndex
<= data
->count
)) {
957 for (i
= data
->rightIndex
- 1; i
>= 0; i
--) {
958 looprw
= data
->rightList
[i
];
959 if (!(data
->realY
> WBOTTOM(looprw
)
960 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
962 || ((data
->realX
< (WRIGHT(looprw
) + 2)) && dx
< 0)) {
963 l_edge
= WRIGHT(looprw
) + 1;
964 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
971 for (i
= data
->rightIndex
; i
< data
->count
; i
++) {
972 looprw
= data
->rightList
[i
];
973 if(!(data
->realY
> WBOTTOM(looprw
)
974 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
975 r_edge
= WRIGHT(looprw
) + 1;
976 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
983 if ((data
->leftIndex
>= 0) && (data
->leftIndex
<= data
->count
)) {
986 for (i
= data
->leftIndex
- 1; i
>= 0; i
--) {
987 looprw
= data
->leftList
[i
];
988 if (!(data
->realY
> WBOTTOM(looprw
)
989 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
991 || (((data
->realX
+ data
->winWidth
) > (WLEFT(looprw
) - 1)) && dx
> 0)) {
992 edge_r
= WLEFT(looprw
);
993 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1000 for (i
= data
->leftIndex
; i
< data
->count
; i
++) {
1001 looprw
= data
->leftList
[i
];
1002 if(!(data
->realY
> WBOTTOM(looprw
)
1003 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1004 edge_l
= WLEFT(looprw
);
1005 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1012 printf("%d %d\n",winL,winR);
1013 printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);
1016 if ((winL
- l_edge
) < (r_edge
- winL
)) {
1018 if ((attract
&& winL
<= l_edge
+ resist
&& winL
>= l_edge
- resist
)
1019 || (dx
< 0 && winL
<= l_edge
&& winL
>= l_edge
- resist
)) {
1025 if (resist
> 0 && attract
&& winL
>= r_edge
- resist
&& winL
<= r_edge
+ resist
) {
1031 if ((winR
- edge_l
) < (edge_r
- winR
)) {
1032 if (resist
> 0 && attract
&& winR
<= edge_l
+ resist
&& winR
>= edge_l
- resist
) {
1033 newX
= edge_l
- data
->winWidth
;
1038 if ((attract
&& winR
>= edge_r
- resist
&& winR
<= edge_r
+ resist
)
1039 || (dx
> 0 && winR
>= edge_r
&& winR
<= edge_r
+ resist
)) {
1040 newX
= edge_r
- data
->winWidth
;
1047 t_edge
= scr
->totalUsableArea
.y1
;
1048 b_edge
= scr
->totalUsableArea
.y2
+ resist
;
1049 edge_t
= scr
->totalUsableArea
.y1
- resist
;
1050 edge_b
= scr
->totalUsableArea
.y2
;
1052 if ((data
->bottomIndex
>= 0) && (data
->bottomIndex
<= data
->count
)) {
1055 for (i
= data
->bottomIndex
- 1; i
>= 0; i
--) {
1056 looprw
= data
->bottomList
[i
];
1057 if (!(data
->realX
> WRIGHT(looprw
)
1058 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1060 || ((data
->realY
< (WBOTTOM(looprw
) + 2)) && dy
< 0)) {
1061 t_edge
= WBOTTOM(looprw
) + 1;
1062 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1069 for (i
= data
->bottomIndex
; i
< data
->count
; i
++) {
1070 looprw
= data
->bottomList
[i
];
1071 if(!(data
->realX
> WRIGHT(looprw
)
1072 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1073 b_edge
= WBOTTOM(looprw
) + 1;
1074 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1081 if ((data
->topIndex
>= 0) && (data
->topIndex
<= data
->count
)) {
1084 for (i
= data
->topIndex
- 1; i
>= 0; i
--) {
1085 looprw
= data
->topList
[i
];
1086 if (!(data
->realX
> WRIGHT(looprw
)
1087 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1089 || (((data
->realY
+ data
->winHeight
) > (WTOP(looprw
) - 1)) && dy
> 0)) {
1090 edge_b
= WTOP(looprw
);
1091 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1098 for (i
= data
->topIndex
; i
< data
->count
; i
++) {
1099 looprw
= data
->topList
[i
];
1100 if(!(data
->realX
> WRIGHT(looprw
)
1101 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1102 edge_t
= WTOP(looprw
);
1103 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1109 if ((winT
- t_edge
) < (b_edge
- winT
)) {
1111 if ((attract
&& winT
<= t_edge
+ resist
&& winT
>= t_edge
- resist
)
1112 || (dy
< 0 && winT
<= t_edge
&& winT
>= t_edge
- resist
)) {
1119 if (resist
> 0 && attract
&& winT
>= b_edge
- resist
&& winT
<= b_edge
+ resist
) {
1125 if ((winB
- edge_t
) < (edge_b
- winB
)) {
1126 if (resist
> 0 && attract
&& winB
<= edge_t
+ resist
&& winB
>= edge_t
- resist
) {
1127 newY
= edge_t
- data
->winHeight
;
1133 if ((attract
&& winB
>= edge_b
- resist
&& winB
<= edge_b
+ resist
)
1134 || (dy
> 0 && winB
>= edge_b
&& winB
<= edge_b
+ resist
)) {
1135 newY
= edge_b
- data
->winHeight
;
1145 /* update window position */
1149 if (((dx
> 0 && data
->calcX
- data
->realX
> 0)
1150 || (dx
< 0 && data
->calcX
- data
->realX
< 0)) && !hresist
)
1153 if (((dy
> 0 && data
->calcY
- data
->realY
> 0)
1154 || (dy
< 0 && data
->calcY
- data
->realY
< 0)) && !vresist
)
1157 if (data
->realX
!= newX
|| data
->realY
!= newY
) {
1159 if (wPreferences
.move_display
== WDIS_NEW
1160 && !scr
->selected_windows
) {
1161 showPosition(wwin
, data
->realX
, data
->realY
);
1164 doWindowMove(wwin
, scr
->selected_windows
,
1165 newX
- wwin
->frame_x
,
1166 newY
- wwin
->frame_y
);
1169 drawFrames(wwin
, scr
->selected_windows
,
1170 data
->realX
- wwin
->frame_x
,
1171 data
->realY
- wwin
->frame_y
);
1174 if (!scr
->selected_windows
1175 && wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
1177 moveGeometryDisplayCentered(scr
, newX
+ data
->winWidth
/2,
1178 newY
+ data
->winHeight
/2);
1183 drawFrames(wwin
, scr
->selected_windows
,
1184 newX
- wwin
->frame_x
,
1185 newY
- wwin
->frame_y
);
1188 if (!scr
->selected_windows
) {
1189 showPosition(wwin
, newX
, newY
);
1194 /* recalc relative window position */
1195 if (doResistance
&& (data
->realX
!= newX
|| data
->realY
!= newY
)) {
1196 updateResistance(wwin
, data
, newX
, newY
);
1204 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1207 wKeyboardMoveResizeWindow(WWindow
*wwin
)
1209 WScreen
*scr
= wwin
->screen_ptr
;
1210 Window root
= scr
->root_win
;
1212 int w
= wwin
->frame
->core
->width
;
1213 int h
= wwin
->frame
->core
->height
;
1214 int scr_width
= wwin
->screen_ptr
->scr_width
;
1215 int scr_height
= wwin
->screen_ptr
->scr_height
;
1216 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1217 int src_x
= wwin
->frame_x
;
1218 int src_y
= wwin
->frame_y
;
1219 int done
,off_x
,off_y
,ww
,wh
;
1222 KeySym keysym
=NoSymbol
;
1224 KeyCode shiftl
,shiftr
,ctrll
,ctrlmode
;
1226 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1227 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1228 ctrll
= XKeysymToKeycode(dpy
, XK_Control_L
);
1229 ctrlmode
=done
=off_x
=off_y
=0;
1233 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1235 if (!wwin
->flags
.selected
) {
1236 wUnselectWindows(scr
);
1239 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1240 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
1241 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
);
1243 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1244 if(scr
->selected_windows
)
1245 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1246 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1247 if(!scr
->selected_windows
)
1248 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1250 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1259 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1260 | ButtonPressMask
| ExposureMask
, &event
);
1261 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1262 if(scr
->selected_windows
)
1263 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1264 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1265 /*** I HATE EDGE RESISTANCE - ]d ***/
1268 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1272 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1277 switch (event
.type
) {
1280 if (event
.xkey
.time
- lastTime
> 50) {
1281 kspeed
/=(1 + (event
.xkey
.time
- lastTime
)/100);
1287 if (kspeed
< _KS
) kspeed
= _KS
;
1288 lastTime
= event
.xkey
.time
;
1290 if (event
.xkey
.state
& ControlMask
&& !wwin
->flags
.shaded
) {
1292 wUnselectWindows(scr
);
1297 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
) {
1299 cycleGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
, 0);
1301 cyclePositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1305 keysym
= XLookupKeysym(&event
.xkey
, 0);
1360 if (moment
!= RIGHT
)
1371 wWindowConstrainSize(wwin
, &ww
, &wh
);
1374 if (wPreferences
.ws_cycle
){
1375 if (src_x
+ off_x
+ ww
< 20){
1376 if(!scr
->current_workspace
) {
1377 wWorkspaceChange(scr
, scr
->workspace_count
-1);
1379 else wWorkspaceChange(scr
, scr
->current_workspace
-1);
1382 else if (src_x
+ off_x
+ 20 > scr_width
){
1383 if(scr
->current_workspace
== scr
->workspace_count
-1) {
1384 wWorkspaceChange(scr
, 0);
1386 else wWorkspaceChange(scr
, scr
->current_workspace
+1);
1391 if (src_x
+ off_x
+ ww
< 20)
1392 off_x
= 20 - ww
- src_x
;
1393 else if (src_x
+ off_x
+ 20 > scr_width
)
1394 off_x
= scr_width
- 20 - src_x
;
1397 if (src_y
+ off_y
+ wh
< 20) {
1398 off_y
= 20 - wh
- src_y
;
1400 else if (src_y
+ off_y
+ 20 > scr_height
) {
1401 off_y
= scr_height
- 20 - src_y
;
1410 WMHandleEvent(&event
);
1417 if (wwin
->flags
.shaded
&& !scr
->selected_windows
){
1418 moveGeometryDisplayCentered(scr
, src_x
+off_x
+ w
/2, src_y
+off_y
+ h
/2);
1421 WMUnmapWidget(scr
->gview
);
1422 mapGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1423 } else if(!scr
->selected_windows
) {
1424 WMUnmapWidget(scr
->gview
);
1425 mapPositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1429 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1430 if (scr
->selected_windows
)
1431 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1433 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1435 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1440 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1441 } else if(!scr
->selected_windows
)
1442 showPosition(wwin
, src_x
+off_x
, src_y
+off_y
);
1446 scr
->keymove_tick
=0;
1448 WMDeleteTimerWithClientData(&looper);
1450 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1451 if(scr
->selected_windows
)
1452 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1453 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1456 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1460 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1461 WMUnmapWidget(scr
->gview
);
1463 WMUnmapWidget(scr
->gview
);
1465 XUngrabKeyboard(dpy
, CurrentTime
);
1466 XUngrabPointer(dpy
, CurrentTime
);
1470 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1471 if (!scr
->selected_windows
) {
1472 wWindowMove(wwin
, src_x
+off_x
, src_y
+off_y
);
1473 wWindowSynthConfigureNotify(wwin
);
1476 WMBag
*bag
= scr
->selected_windows
;
1477 doWindowMove(wwin
,scr
->selected_windows
,off_x
,off_y
);
1478 for (i
= 0; i
< WMGetBagItemCount(bag
); i
++) {
1479 wWindowSynthConfigureNotify(WMGetFromBag(bag
, i
));
1483 if (wwin
->client
.width
!= ww
)
1484 wwin
->flags
.user_changed_width
= 1;
1486 if (wwin
->client
.height
!= wh
- vert_border
)
1487 wwin
->flags
.user_changed_height
= 1;
1489 wWindowConfigure(wwin
, src_x
+off_x
, src_y
+off_y
,
1490 ww
, wh
- vert_border
);
1491 wWindowSynthConfigureNotify(wwin
);
1493 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1494 wSetFocusTo(scr
, wwin
);
1503 *----------------------------------------------------------------------
1504 * wMouseMoveWindow--
1505 * Move the named window and the other selected ones (if any),
1506 * interactively. Also shows the position of the window, if only one
1507 * window is being moved.
1508 * If the window is not on the selected window list, the selected
1509 * windows are deselected.
1510 * If shift is pressed during the operation, the position display
1511 * is changed to another type.
1514 * True if the window was moved, False otherwise.
1517 * The window(s) position is changed, and the client(s) are
1518 * notified about that.
1519 * The position display configuration may be changed.
1520 *----------------------------------------------------------------------
1523 wMouseMoveWindow(WWindow
*wwin
, XEvent
*ev
)
1525 WScreen
*scr
= wwin
->screen_ptr
;
1527 Window root
= scr
->root_win
;
1528 KeyCode shiftl
, shiftr
;
1532 /* This needs not to change while moving, else bad things can happen */
1533 int opaqueMove
= wPreferences
.opaque_move
;
1535 #ifdef GHOST_WINDOW_MOVE
1538 rimg
= InitGhostWindowMove(scr
);
1542 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1543 XSetWindowAttributes attr
;
1545 attr
.save_under
= True
;
1546 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
,
1547 CWSaveUnder
, &attr
);
1551 initMoveData(wwin
, &moveData
);
1553 moveData
.mouseX
= ev
->xmotion
.x_root
;
1554 moveData
.mouseY
= ev
->xmotion
.y_root
;
1556 if (!wwin
->flags
.selected
) {
1557 /* this window is not selected, unselect others and move only wwin */
1558 wUnselectWindows(scr
);
1561 puts("Moving window");
1563 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1564 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1570 /* XWarpPointer() doesn't seem to generate Motion events, so
1571 we've got to simulate them */
1572 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1573 &event
.xmotion
.y_root
, &junk
, &junk
,
1574 (unsigned *) &junk
);
1576 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1577 | PointerMotionHintMask
1578 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
,
1581 if (event
.type
== MotionNotify
) {
1582 /* compress MotionNotify events */
1583 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1584 if (!checkMouseSamplingRate(&event
))
1588 switch (event
.type
) {
1590 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1591 && started
&& !scr
->selected_windows
) {
1594 drawFrames(wwin
, scr
->selected_windows
,
1595 moveData
.realX
- wwin
->frame_x
,
1596 moveData
.realY
- wwin
->frame_y
);
1599 if (wPreferences
.move_display
== WDIS_NEW
1600 && !scr
->selected_windows
) {
1601 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1604 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1605 moveData
.winWidth
, moveData
.winHeight
);
1607 if (wPreferences
.move_display
== WDIS_NEW
1608 && !scr
->selected_windows
) {
1610 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1614 drawFrames(wwin
, scr
->selected_windows
,
1615 moveData
.realX
- wwin
->frame_x
,
1616 moveData
.realY
- wwin
->frame_y
);
1623 updateWindowPosition(wwin
, &moveData
,
1624 scr
->selected_windows
== NULL
1625 && wPreferences
.edge_resistance
> 0,
1627 event
.xmotion
.x_root
,
1628 event
.xmotion
.y_root
);
1630 if (!warped
&& !wPreferences
.no_autowrap
) {
1631 int oldWorkspace
= scr
->current_workspace
;
1633 if (wPreferences
.move_display
== WDIS_NEW
1634 && !scr
->selected_windows
) {
1635 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1639 drawFrames(wwin
, scr
->selected_windows
,
1640 moveData
.realX
- wwin
->frame_x
,
1641 moveData
.realY
- wwin
->frame_y
);
1643 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1644 if (scr
->current_workspace
!= oldWorkspace
1645 && wPreferences
.edge_resistance
> 0
1646 && scr
->selected_windows
== NULL
)
1647 updateMoveData(wwin
, &moveData
);
1651 drawFrames(wwin
, scr
->selected_windows
,
1652 moveData
.realX
- wwin
->frame_x
,
1653 moveData
.realY
- wwin
->frame_y
);
1655 if (wPreferences
.move_display
== WDIS_NEW
1656 && !scr
->selected_windows
) {
1658 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1664 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1665 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1667 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1668 | ButtonReleaseMask
| ButtonPressMask
,
1669 wCursor
[WCUR_MOVE
], CurrentTime
);
1671 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1674 if (!scr
->selected_windows
)
1675 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1676 moveData
.winWidth
, moveData
.winHeight
);
1678 if (started
&& !opaqueMove
)
1679 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1681 if (!opaqueMove
|| (wPreferences
.move_display
==WDIS_NEW
1682 && !scr
->selected_windows
)) {
1684 if (wPreferences
.move_display
==WDIS_NEW
)
1685 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1694 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1700 drawFrames(wwin
, scr
->selected_windows
,
1701 moveData
.realX
- wwin
->frame_x
,
1702 moveData
.realY
- wwin
->frame_y
);
1704 doWindowMove(wwin
, scr
->selected_windows
,
1705 moveData
.realX
- wwin
->frame_x
,
1706 moveData
.realY
- wwin
->frame_y
);
1708 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1709 wWindowSynthConfigureNotify(wwin
);
1711 XUngrabKeyboard(dpy
, CurrentTime
);
1714 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1715 wSetFocusTo(scr
, wwin
);
1717 if (wPreferences
.move_display
== WDIS_NEW
)
1718 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1720 /* discard all enter/leave events that happened until
1721 * the time the button was released */
1722 while (XCheckTypedEvent(dpy
, EnterNotify
, &e
)) {
1723 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1724 XPutBackEvent(dpy
, &e
);
1728 while (XCheckTypedEvent(dpy
, LeaveNotify
, &e
)) {
1729 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1730 XPutBackEvent(dpy
, &e
);
1735 if (!scr
->selected_windows
) {
1736 /* get rid of the geometry window */
1737 WMUnmapWidget(scr
->gview
);
1741 puts("End move window");
1747 if (started
&& !opaqueMove
) {
1748 drawFrames(wwin
, scr
->selected_windows
,
1749 moveData
.realX
- wwin
->frame_x
,
1750 moveData
.realY
- wwin
->frame_y
);
1752 WMHandleEvent(&event
);
1755 drawFrames(wwin
, scr
->selected_windows
,
1756 moveData
.realX
- wwin
->frame_x
,
1757 moveData
.realY
- wwin
->frame_y
);
1759 WMHandleEvent(&event
);
1765 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1766 XSetWindowAttributes attr
;
1769 attr
.save_under
= False
;
1770 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
,
1771 CWSaveUnder
, &attr
);
1775 freeMoveData(&moveData
);
1782 #define HCONSTRAIN 2
1785 getResizeDirection(WWindow
*wwin
, int x
, int y
, int dx
, int dy
,
1788 int w
= wwin
->frame
->core
->width
- 1;
1789 int cw
= wwin
->frame
->resizebar_corner_width
;
1792 /* if not resizing through the resizebar */
1793 if (!(flags
& RESIZEBAR
)) {
1794 int xdir
= (abs(x
) < (wwin
->client
.width
/2)) ? LEFT
: RIGHT
;
1795 int ydir
= (abs(y
) < (wwin
->client
.height
/2)) ? UP
: DOWN
;
1796 if (abs(dx
) < 2 || abs(dy
) < 2) {
1797 if (abs(dy
) > abs(dx
))
1802 return (xdir
| ydir
);
1805 /* window is too narrow. allow diagonal resize */
1809 if (flags
& HCONSTRAIN
)
1814 return (LEFT
| ydir
);
1816 return (RIGHT
| ydir
);
1818 /* vertical resize */
1819 if ((x
> cw
) && (x
< w
- cw
))
1827 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1835 wMouseResizeWindow(WWindow
*wwin
, XEvent
*ev
)
1838 WScreen
*scr
= wwin
->screen_ptr
;
1839 Window root
= scr
->root_win
;
1840 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1841 int fw
= wwin
->frame
->core
->width
;
1842 int fh
= wwin
->frame
->core
->height
;
1843 int fx
= wwin
->frame_x
;
1844 int fy
= wwin
->frame_y
;
1845 int is_resizebar
= (wwin
->frame
->resizebar
1846 && ev
->xany
.window
==wwin
->frame
->resizebar
->window
);
1850 int rw
= fw
, rh
= fh
;
1851 int rx1
, ry1
, rx2
, ry2
;
1853 KeyCode shiftl
, shiftr
;
1860 if (wwin
->flags
.shaded
) {
1861 wwarning("internal error: tryein");
1864 orig_x
= ev
->xbutton
.x_root
;
1865 orig_y
= ev
->xbutton
.y_root
;
1869 puts("Resizing window");
1872 wUnselectWindows(scr
);
1877 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1878 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1879 if (!WFLAGP(wwin
, no_titlebar
))
1880 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + (wPreferences
.window_title_clearance
+ TITLEBAR_EXTEND_SPACE
) * 2;
1884 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1885 | ButtonReleaseMask
| PointerMotionHintMask
1886 | ButtonPressMask
| ExposureMask
, &event
);
1887 if (!checkMouseSamplingRate(&event
))
1890 switch (event
.type
) {
1892 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1893 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1895 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1896 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
1897 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1899 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1904 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1915 dw
= orig_x
- event
.xmotion
.x_root
;
1916 else if (res
& RIGHT
)
1917 dw
= event
.xmotion
.x_root
- orig_x
;
1919 dh
= orig_y
- event
.xmotion
.y_root
;
1920 else if (res
& DOWN
)
1921 dh
= event
.xmotion
.y_root
- orig_y
;
1923 orig_x
= event
.xmotion
.x_root
;
1924 orig_y
= event
.xmotion
.y_root
;
1929 fh
= rh
- vert_border
;
1930 wWindowConstrainSize(wwin
, &fw
, &fh
);
1934 else if (res
& RIGHT
)
1938 else if (res
& DOWN
)
1940 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1941 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1946 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
1947 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
1949 /* check if resizing through resizebar */
1955 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
1956 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
1957 flags
|= HCONSTRAIN
;
1959 res
= getResizeDirection(wwin
, tx
, ty
,
1960 orig_x
- event
.xmotion
.x_root
,
1961 orig_y
- event
.xmotion
.y_root
, flags
);
1963 if (res
== (UP
|LEFT
))
1964 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1965 | ButtonReleaseMask
| ButtonPressMask
,
1966 wCursor
[WCUR_TOPLEFTRESIZE
], CurrentTime
);
1967 else if (res
== (UP
|RIGHT
))
1968 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1969 | ButtonReleaseMask
| ButtonPressMask
,
1970 wCursor
[WCUR_TOPRIGHTRESIZE
], CurrentTime
);
1971 else if (res
== (DOWN
|LEFT
))
1972 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1973 | ButtonReleaseMask
| ButtonPressMask
,
1974 wCursor
[WCUR_BOTTOMLEFTRESIZE
], CurrentTime
);
1975 else if (res
== (DOWN
|RIGHT
))
1976 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1977 | ButtonReleaseMask
| ButtonPressMask
,
1978 wCursor
[WCUR_BOTTOMRIGHTRESIZE
], CurrentTime
);
1979 else if (res
== DOWN
|| res
== UP
)
1980 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1981 | ButtonReleaseMask
| ButtonPressMask
,
1982 wCursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
1983 else if (res
& (DOWN
|UP
))
1984 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1985 | ButtonReleaseMask
| ButtonPressMask
,
1986 wCursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
1987 else if (res
& (LEFT
|RIGHT
))
1988 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1989 | ButtonReleaseMask
| ButtonPressMask
,
1990 wCursor
[WCUR_HORIZONRESIZE
], CurrentTime
);
1992 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1997 /* Draw the resize frame for the first time. */
1998 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
2000 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2002 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2007 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
2008 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
2010 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
2011 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2013 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
2015 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2017 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
2018 if (wPreferences
.size_display
== WDIS_NEW
) {
2019 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
2020 orig_fy
+ orig_fh
, res
);
2022 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2031 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2035 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2037 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2039 XUngrabKeyboard(dpy
, CurrentTime
);
2040 WMUnmapWidget(scr
->gview
);
2043 if (wwin
->client
.width
!= fw
)
2044 wwin
->flags
.user_changed_width
= 1;
2046 if (wwin
->client
.height
!= fh
- vert_border
)
2047 wwin
->flags
.user_changed_height
= 1;
2049 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
2052 puts("End resize window");
2057 WMHandleEvent(&event
);
2072 wUnselectWindows(WScreen
*scr
)
2076 if (!scr
->selected_windows
)
2079 while (WMGetBagItemCount(scr
->selected_windows
)) {
2080 WMBagIterator dummy
;
2082 wwin
= WMBagFirst(scr
->selected_windows
, &dummy
);
2083 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
2084 wIconSelect(wwin
->icon
);
2086 wSelectWindow(wwin
, False
);
2088 WMFreeBag(scr
->selected_windows
);
2089 scr
->selected_windows
= NULL
;
2094 selectWindowsInside(WScreen
*scr
, int x1
, int y1
, int x2
, int y2
)
2098 /* select the windows and put them in the selected window list */
2099 tmpw
= scr
->focused_window
;
2100 while (tmpw
!= NULL
) {
2101 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
2102 if ((tmpw
->frame
->workspace
== scr
->current_workspace
2103 || IS_OMNIPRESENT(tmpw
))
2104 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
2105 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
2106 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
2107 wSelectWindow(tmpw
, True
);
2116 wSelectWindows(WScreen
*scr
, XEvent
*ev
)
2119 Window root
= scr
->root_win
;
2120 GC gc
= scr
->frame_gc
;
2121 int xp
= ev
->xbutton
.x_root
;
2122 int yp
= ev
->xbutton
.y_root
;
2127 puts("Selecting windows");
2129 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
2130 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
2131 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
],
2132 CurrentTime
) != Success
) {
2137 wUnselectWindows(scr
);
2139 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
2141 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
2142 | ButtonPressMask
, &event
);
2144 switch (event
.type
) {
2146 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2147 x
= event
.xmotion
.x_root
;
2154 y
= event
.xmotion
.y_root
;
2161 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2168 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2171 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2173 XUngrabPointer(dpy
, CurrentTime
);
2174 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
2177 wKWMSelectRootRegion(scr
, xp
, yp
, w
, h
,
2178 event
.xbutton
.state
& ControlMask
);
2179 #endif /* KWM_HINTS */
2182 puts("End window selection");
2187 WMHandleEvent(&event
);
2195 InteractivePlaceWindow(WWindow
*wwin
, int *x_ret
, int *y_ret
,
2196 unsigned width
, unsigned height
)
2198 WScreen
*scr
= wwin
->screen_ptr
;
2199 Window root
= scr
->root_win
;
2202 KeyCode shiftl
, shiftr
;
2206 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2207 GrabModeAsync
, GrabModeAsync
, None
,
2208 wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2213 if (!WFLAGP(wwin
, no_titlebar
)) {
2214 h
= WMFontHeight(scr
->title_font
) + (wPreferences
.window_title_clearance
+ TITLEBAR_EXTEND_SPACE
) * 2;
2217 if (!WFLAGP(wwin
, no_resizebar
)) {
2218 height
+= RESIZEBAR_HEIGHT
;
2220 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2221 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
,
2222 (unsigned *) &junk
);
2223 mapPositionDisplay(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2225 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2227 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2228 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2230 WMMaskEvent(dpy
, PointerMotionMask
|ButtonPressMask
|ExposureMask
|KeyPressMask
,
2233 if (!checkMouseSamplingRate(&event
))
2236 switch (event
.type
) {
2238 if ((event
.xkey
.keycode
== shiftl
)
2239 || (event
.xkey
.keycode
== shiftr
)) {
2240 drawTransparentFrame(wwin
,
2241 x
- width
/2, y
- h
/2, width
, height
);
2242 cyclePositionDisplay(wwin
,
2243 x
- width
/2, y
- h
/2, width
, height
);
2244 drawTransparentFrame(wwin
,
2245 x
- width
/2, y
- h
/2, width
, height
);
2250 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2252 x
= event
.xmotion
.x_root
;
2253 y
= event
.xmotion
.y_root
;
2255 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2256 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2258 showPosition(wwin
, x
- width
/2, y
- h
/2);
2260 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2265 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2267 *x_ret
= x
- width
/2;
2269 XUngrabPointer(dpy
, CurrentTime
);
2270 XUngrabKeyboard(dpy
, CurrentTime
);
2271 /* get rid of the geometry window */
2272 WMUnmapWidget(scr
->gview
);
2276 WMHandleEvent(&event
);