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
) + TITLEBAR_EXTRA_HEIGHT
;
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);
1352 if (moment
!= RIGHT
)
1363 wWindowConstrainSize(wwin
, &ww
, &wh
);
1366 if (wPreferences
.ws_cycle
){
1367 if (src_x
+ off_x
+ ww
< 20){
1368 if(!scr
->current_workspace
) {
1369 wWorkspaceChange(scr
, scr
->workspace_count
-1);
1371 else wWorkspaceChange(scr
, scr
->current_workspace
-1);
1374 else if (src_x
+ off_x
+ 20 > scr_width
){
1375 if(scr
->current_workspace
== scr
->workspace_count
-1) {
1376 wWorkspaceChange(scr
, 0);
1378 else wWorkspaceChange(scr
, scr
->current_workspace
+1);
1383 if (src_x
+ off_x
+ ww
< 20)
1384 off_x
= 20 - ww
- src_x
;
1385 else if (src_x
+ off_x
+ 20 > scr_width
)
1386 off_x
= scr_width
- 20 - src_x
;
1389 if (src_y
+ off_y
+ wh
< 20) {
1390 off_y
= 20 - wh
- src_y
;
1392 else if (src_y
+ off_y
+ 20 > scr_height
) {
1393 off_y
= scr_height
- 20 - src_y
;
1402 WMHandleEvent(&event
);
1409 if (wwin
->flags
.shaded
&& !scr
->selected_windows
){
1410 moveGeometryDisplayCentered(scr
, src_x
+off_x
+ w
/2, src_y
+off_y
+ h
/2);
1413 WMUnmapWidget(scr
->gview
);
1414 mapGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1415 } else if(!scr
->selected_windows
) {
1416 WMUnmapWidget(scr
->gview
);
1417 mapPositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1421 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1422 if (scr
->selected_windows
)
1423 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1425 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1427 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1432 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1433 } else if(!scr
->selected_windows
)
1434 showPosition(wwin
, src_x
+off_x
, src_y
+off_y
);
1438 scr
->keymove_tick
=0;
1440 WMDeleteTimerWithClientData(&looper);
1442 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1443 if(scr
->selected_windows
)
1444 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1445 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1448 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1452 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1453 WMUnmapWidget(scr
->gview
);
1455 WMUnmapWidget(scr
->gview
);
1457 XUngrabKeyboard(dpy
, CurrentTime
);
1458 XUngrabPointer(dpy
, CurrentTime
);
1462 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1463 if (!scr
->selected_windows
) {
1464 wWindowMove(wwin
, src_x
+off_x
, src_y
+off_y
);
1465 wWindowSynthConfigureNotify(wwin
);
1468 WMBag
*bag
= scr
->selected_windows
;
1469 doWindowMove(wwin
,scr
->selected_windows
,off_x
,off_y
);
1470 for (i
= 0; i
< WMGetBagItemCount(bag
); i
++) {
1471 wWindowSynthConfigureNotify(WMGetFromBag(bag
, i
));
1475 if (wwin
->client
.width
!= ww
)
1476 wwin
->flags
.user_changed_width
= 1;
1478 if (wwin
->client
.height
!= wh
- vert_border
)
1479 wwin
->flags
.user_changed_height
= 1;
1481 wWindowConfigure(wwin
, src_x
+off_x
, src_y
+off_y
,
1482 ww
, wh
- vert_border
);
1483 wWindowSynthConfigureNotify(wwin
);
1485 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1486 wSetFocusTo(scr
, wwin
);
1495 *----------------------------------------------------------------------
1496 * wMouseMoveWindow--
1497 * Move the named window and the other selected ones (if any),
1498 * interactively. Also shows the position of the window, if only one
1499 * window is being moved.
1500 * If the window is not on the selected window list, the selected
1501 * windows are deselected.
1502 * If shift is pressed during the operation, the position display
1503 * is changed to another type.
1506 * True if the window was moved, False otherwise.
1509 * The window(s) position is changed, and the client(s) are
1510 * notified about that.
1511 * The position display configuration may be changed.
1512 *----------------------------------------------------------------------
1515 wMouseMoveWindow(WWindow
*wwin
, XEvent
*ev
)
1517 WScreen
*scr
= wwin
->screen_ptr
;
1519 Window root
= scr
->root_win
;
1520 KeyCode shiftl
, shiftr
;
1524 /* This needs not to change while moving, else bad things can happen */
1525 int opaqueMove
= wPreferences
.opaque_move
;
1527 #ifdef GHOST_WINDOW_MOVE
1530 rimg
= InitGhostWindowMove(scr
);
1534 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1535 XSetWindowAttributes attr
;
1537 attr
.save_under
= True
;
1538 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
,
1539 CWSaveUnder
, &attr
);
1543 initMoveData(wwin
, &moveData
);
1545 moveData
.mouseX
= ev
->xmotion
.x_root
;
1546 moveData
.mouseY
= ev
->xmotion
.y_root
;
1548 if (!wwin
->flags
.selected
) {
1549 /* this window is not selected, unselect others and move only wwin */
1550 wUnselectWindows(scr
);
1553 puts("Moving window");
1555 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1556 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1562 /* XWarpPointer() doesn't seem to generate Motion events, so
1563 we've got to simulate them */
1564 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1565 &event
.xmotion
.y_root
, &junk
, &junk
,
1566 (unsigned *) &junk
);
1568 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1569 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
,
1572 if (event
.type
== MotionNotify
) {
1573 /* compress MotionNotify events */
1574 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1575 if (!checkMouseSamplingRate(&event
))
1579 switch (event
.type
) {
1581 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1582 && started
&& !scr
->selected_windows
) {
1585 drawFrames(wwin
, scr
->selected_windows
,
1586 moveData
.realX
- wwin
->frame_x
,
1587 moveData
.realY
- wwin
->frame_y
);
1590 if (wPreferences
.move_display
== WDIS_NEW
1591 && !scr
->selected_windows
) {
1592 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1595 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1596 moveData
.winWidth
, moveData
.winHeight
);
1598 if (wPreferences
.move_display
== WDIS_NEW
1599 && !scr
->selected_windows
) {
1601 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1605 drawFrames(wwin
, scr
->selected_windows
,
1606 moveData
.realX
- wwin
->frame_x
,
1607 moveData
.realY
- wwin
->frame_y
);
1614 updateWindowPosition(wwin
, &moveData
,
1615 scr
->selected_windows
== NULL
1616 && wPreferences
.edge_resistance
> 0,
1618 event
.xmotion
.x_root
,
1619 event
.xmotion
.y_root
);
1621 if (!warped
&& !wPreferences
.no_autowrap
) {
1622 int oldWorkspace
= scr
->current_workspace
;
1624 if (wPreferences
.move_display
== WDIS_NEW
1625 && !scr
->selected_windows
) {
1626 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1630 drawFrames(wwin
, scr
->selected_windows
,
1631 moveData
.realX
- wwin
->frame_x
,
1632 moveData
.realY
- wwin
->frame_y
);
1634 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1635 if (scr
->current_workspace
!= oldWorkspace
1636 && wPreferences
.edge_resistance
> 0
1637 && scr
->selected_windows
== NULL
)
1638 updateMoveData(wwin
, &moveData
);
1642 drawFrames(wwin
, scr
->selected_windows
,
1643 moveData
.realX
- wwin
->frame_x
,
1644 moveData
.realY
- wwin
->frame_y
);
1646 if (wPreferences
.move_display
== WDIS_NEW
1647 && !scr
->selected_windows
) {
1649 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1655 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1656 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1658 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1659 | ButtonReleaseMask
| ButtonPressMask
,
1660 wCursor
[WCUR_MOVE
], CurrentTime
);
1662 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1665 if (!scr
->selected_windows
)
1666 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1667 moveData
.winWidth
, moveData
.winHeight
);
1669 if (started
&& !opaqueMove
)
1670 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1672 if (!opaqueMove
|| (wPreferences
.move_display
==WDIS_NEW
1673 && !scr
->selected_windows
)) {
1675 if (wPreferences
.move_display
==WDIS_NEW
)
1676 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1685 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1690 drawFrames(wwin
, scr
->selected_windows
,
1691 moveData
.realX
- wwin
->frame_x
,
1692 moveData
.realY
- wwin
->frame_y
);
1694 doWindowMove(wwin
, scr
->selected_windows
,
1695 moveData
.realX
- wwin
->frame_x
,
1696 moveData
.realY
- wwin
->frame_y
);
1698 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1699 wWindowSynthConfigureNotify(wwin
);
1701 XUngrabKeyboard(dpy
, CurrentTime
);
1704 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1705 wSetFocusTo(scr
, wwin
);
1707 if (wPreferences
.move_display
== WDIS_NEW
)
1708 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1710 if (!scr
->selected_windows
) {
1711 /* get rid of the geometry window */
1712 WMUnmapWidget(scr
->gview
);
1716 puts("End move window");
1722 if (started
&& !opaqueMove
) {
1723 drawFrames(wwin
, scr
->selected_windows
,
1724 moveData
.realX
- wwin
->frame_x
,
1725 moveData
.realY
- wwin
->frame_y
);
1727 WMHandleEvent(&event
);
1730 drawFrames(wwin
, scr
->selected_windows
,
1731 moveData
.realX
- wwin
->frame_x
,
1732 moveData
.realY
- wwin
->frame_y
);
1734 WMHandleEvent(&event
);
1740 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1741 XSetWindowAttributes attr
;
1744 attr
.save_under
= False
;
1745 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
,
1746 CWSaveUnder
, &attr
);
1750 freeMoveData(&moveData
);
1757 #define HCONSTRAIN 2
1760 getResizeDirection(WWindow
*wwin
, int x
, int y
, int dx
, int dy
,
1763 int w
= wwin
->frame
->core
->width
- 1;
1764 int cw
= wwin
->frame
->resizebar_corner_width
;
1767 /* if not resizing through the resizebar */
1768 if (!(flags
& RESIZEBAR
)) {
1769 int xdir
= (abs(x
) < (wwin
->client
.width
/2)) ? LEFT
: RIGHT
;
1770 int ydir
= (abs(y
) < (wwin
->client
.height
/2)) ? UP
: DOWN
;
1771 if (abs(dx
) < 2 || abs(dy
) < 2) {
1772 if (abs(dy
) > abs(dx
))
1777 return (xdir
| ydir
);
1780 /* window is too narrow. allow diagonal resize */
1784 if (flags
& HCONSTRAIN
)
1789 return (LEFT
| ydir
);
1791 return (RIGHT
| ydir
);
1793 /* vertical resize */
1794 if ((x
> cw
) && (x
< w
- cw
))
1802 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1810 wMouseResizeWindow(WWindow
*wwin
, XEvent
*ev
)
1813 WScreen
*scr
= wwin
->screen_ptr
;
1814 Window root
= scr
->root_win
;
1815 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1816 int fw
= wwin
->frame
->core
->width
;
1817 int fh
= wwin
->frame
->core
->height
;
1818 int fx
= wwin
->frame_x
;
1819 int fy
= wwin
->frame_y
;
1820 int is_resizebar
= (wwin
->frame
->resizebar
1821 && ev
->xany
.window
==wwin
->frame
->resizebar
->window
);
1825 int rw
= fw
, rh
= fh
;
1826 int rx1
, ry1
, rx2
, ry2
;
1828 KeyCode shiftl
, shiftr
;
1835 if (wwin
->flags
.shaded
) {
1836 wwarning("internal error: tryein");
1839 orig_x
= ev
->xbutton
.x_root
;
1840 orig_y
= ev
->xbutton
.y_root
;
1844 puts("Resizing window");
1847 wUnselectWindows(scr
);
1852 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1853 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1854 if (!WFLAGP(wwin
, no_titlebar
))
1855 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + TITLEBAR_EXTRA_HEIGHT
;
1859 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
| ButtonReleaseMask
1860 | ButtonPressMask
| ExposureMask
, &event
);
1861 if (!checkMouseSamplingRate(&event
))
1864 switch (event
.type
) {
1866 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1867 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1869 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1870 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
1871 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1873 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1887 dw
= orig_x
- event
.xmotion
.x_root
;
1888 else if (res
& RIGHT
)
1889 dw
= event
.xmotion
.x_root
- orig_x
;
1891 dh
= orig_y
- event
.xmotion
.y_root
;
1892 else if (res
& DOWN
)
1893 dh
= event
.xmotion
.y_root
- orig_y
;
1895 orig_x
= event
.xmotion
.x_root
;
1896 orig_y
= event
.xmotion
.y_root
;
1901 fh
= rh
- vert_border
;
1902 wWindowConstrainSize(wwin
, &fw
, &fh
);
1906 else if (res
& RIGHT
)
1910 else if (res
& DOWN
)
1912 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1913 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1918 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
1919 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
1921 /* check if resizing through resizebar */
1927 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
1928 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
1929 flags
|= HCONSTRAIN
;
1931 res
= getResizeDirection(wwin
, tx
, ty
,
1932 orig_x
- event
.xmotion
.x_root
,
1933 orig_y
- event
.xmotion
.y_root
, flags
);
1935 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1936 | ButtonReleaseMask
| ButtonPressMask
,
1937 wCursor
[WCUR_RESIZE
], CurrentTime
);
1938 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1943 /* Draw the resize frame for the first time. */
1944 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
1946 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1948 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1953 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
1954 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
1956 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
1957 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1959 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
1961 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1963 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
1964 if (wPreferences
.size_display
== WDIS_NEW
) {
1965 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
1966 orig_fy
+ orig_fh
, res
);
1968 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1977 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1981 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1983 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1985 XUngrabKeyboard(dpy
, CurrentTime
);
1986 WMUnmapWidget(scr
->gview
);
1989 if (wwin
->client
.width
!= fw
)
1990 wwin
->flags
.user_changed_width
= 1;
1992 if (wwin
->client
.height
!= fh
- vert_border
)
1993 wwin
->flags
.user_changed_height
= 1;
1995 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
1998 puts("End resize window");
2003 WMHandleEvent(&event
);
2018 wUnselectWindows(WScreen
*scr
)
2022 if (!scr
->selected_windows
)
2025 while (WMGetBagItemCount(scr
->selected_windows
)) {
2026 wwin
= WMGetFromBag(scr
->selected_windows
, 0);
2027 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
2028 wIconSelect(wwin
->icon
);
2030 wSelectWindow(wwin
, False
);
2032 WMFreeBag(scr
->selected_windows
);
2033 scr
->selected_windows
= NULL
;
2038 selectWindowsInside(WScreen
*scr
, int x1
, int y1
, int x2
, int y2
)
2042 /* select the windows and put them in the selected window list */
2043 tmpw
= scr
->focused_window
;
2044 while (tmpw
!= NULL
) {
2045 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
2046 if ((tmpw
->frame
->workspace
== scr
->current_workspace
2047 || IS_OMNIPRESENT(tmpw
))
2048 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
2049 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
2050 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
2051 wSelectWindow(tmpw
, True
);
2060 wSelectWindows(WScreen
*scr
, XEvent
*ev
)
2063 Window root
= scr
->root_win
;
2064 GC gc
= scr
->frame_gc
;
2065 int xp
= ev
->xbutton
.x_root
;
2066 int yp
= ev
->xbutton
.y_root
;
2071 puts("Selecting windows");
2073 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
2074 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
2075 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
],
2076 CurrentTime
) != Success
) {
2081 wUnselectWindows(scr
);
2083 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
2085 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
2086 | ButtonPressMask
, &event
);
2088 switch (event
.type
) {
2090 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2091 x
= event
.xmotion
.x_root
;
2098 y
= event
.xmotion
.y_root
;
2105 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2112 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2115 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2117 XUngrabPointer(dpy
, CurrentTime
);
2118 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
2121 wKWMSelectRootRegion(scr
, xp
, yp
, w
, h
,
2122 event
.xbutton
.state
& ControlMask
);
2123 #endif /* KWM_HINTS */
2126 puts("End window selection");
2131 WMHandleEvent(&event
);
2139 InteractivePlaceWindow(WWindow
*wwin
, int *x_ret
, int *y_ret
,
2140 unsigned width
, unsigned height
)
2142 WScreen
*scr
= wwin
->screen_ptr
;
2143 Window root
= scr
->root_win
;
2146 KeyCode shiftl
, shiftr
;
2150 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2151 GrabModeAsync
, GrabModeAsync
, None
,
2152 wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2157 if (!WFLAGP(wwin
, no_titlebar
)) {
2158 h
= WMFontHeight(scr
->title_font
) + TITLEBAR_EXTRA_HEIGHT
;
2161 if (!WFLAGP(wwin
, no_resizebar
)) {
2162 height
+= RESIZEBAR_HEIGHT
;
2164 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2165 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
,
2166 (unsigned *) &junk
);
2167 mapPositionDisplay(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2169 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2171 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2172 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2174 WMMaskEvent(dpy
, PointerMotionMask
|ButtonPressMask
|ExposureMask
|KeyPressMask
,
2177 if (!checkMouseSamplingRate(&event
))
2180 switch (event
.type
) {
2182 if ((event
.xkey
.keycode
== shiftl
)
2183 || (event
.xkey
.keycode
== shiftr
)) {
2184 drawTransparentFrame(wwin
,
2185 x
- width
/2, y
- h
/2, width
, height
);
2186 cyclePositionDisplay(wwin
,
2187 x
- width
/2, y
- h
/2, width
, height
);
2188 drawTransparentFrame(wwin
,
2189 x
- width
/2, y
- h
/2, width
, height
);
2194 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2196 x
= event
.xmotion
.x_root
;
2197 y
= event
.xmotion
.y_root
;
2199 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2200 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2202 showPosition(wwin
, x
- width
/2, y
- h
/2);
2204 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2209 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2211 *x_ret
= x
- width
/2;
2213 XUngrabPointer(dpy
, CurrentTime
);
2214 XUngrabKeyboard(dpy
, CurrentTime
);
2215 /* get rid of the geometry window */
2216 WMUnmapWidget(scr
->gview
);
2220 WMHandleEvent(&event
);