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 #ifdef VIRTUAL_DESKTOP
152 WSetGeometryViewShownPosition(scr
->gview
,
153 x
+ scr
->workspaces
[scr
->current_workspace
]->view_x
,
154 y
+ scr
->workspaces
[scr
->current_workspace
]->view_y
);
156 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
163 cyclePositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
165 WScreen
*scr
= wwin
->screen_ptr
;
167 wPreferences
.move_display
++;
168 wPreferences
.move_display
%= NUM_DISPLAYS
;
170 if (wPreferences
.move_display
== WDIS_NEW
) {
171 WMUnmapWidget(scr
->gview
);
173 if (wPreferences
.move_display
== WDIS_CENTER
) {
174 moveGeometryDisplayCentered(scr
,
175 scr
->scr_width
/2, scr
->scr_height
/2);
176 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
177 moveGeometryDisplayCentered(scr
, 1, 1);
178 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
179 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
181 WMMapWidget(scr
->gview
);
187 mapPositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
189 WScreen
*scr
= wwin
->screen_ptr
;
191 if (wPreferences
.move_display
== WDIS_NEW
) {
193 } else if (wPreferences
.move_display
== WDIS_CENTER
) {
194 moveGeometryDisplayCentered(scr
, scr
->scr_width
/ 2,
195 scr
->scr_height
/ 2);
196 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
197 moveGeometryDisplayCentered(scr
, 1, 1);
198 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
199 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
201 WMMapWidget(scr
->gview
);
202 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
207 showGeometry(WWindow
*wwin
, int x1
, int y1
, int x2
, int y2
, int direction
)
209 WScreen
*scr
= wwin
->screen_ptr
;
210 Window root
= scr
->root_win
;
211 GC gc
= scr
->line_gc
;
212 int ty
, by
, my
, x
, y
, mx
, s
;
217 ty
= y1
+ wwin
->frame
->top_width
;
218 by
= y2
- wwin
->frame
->bottom_width
;
219 fw
= WMWidthOfString(scr
->info_text_font
, "8888", 4);
220 fh
= WMFontHeight(scr
->info_text_font
);
222 if (wPreferences
.size_display
== WDIS_NEW
) {
223 XSetForeground(dpy
, gc
, scr
->line_pixel
);
225 /* vertical geometry */
226 if (((direction
& LEFT
) && (x2
< scr
->scr_width
- fw
)) || (x1
< fw
)) {
237 segment
[0].x1
= x
- (s
+ 6); segment
[0].y1
= ty
;
238 segment
[0].x2
= x
- (s
- 10); segment
[0].y2
= ty
;
241 segment
[1].x1
= x
- (s
- 2); segment
[1].y1
= ty
+ 1;
242 segment
[1].x2
= x
- (s
- 5); segment
[1].y2
= ty
+ 7;
244 segment
[2].x1
= x
- (s
- 2); segment
[2].y1
= ty
+ 1;
245 segment
[2].x2
= x
- (s
+ 1); segment
[2].y2
= ty
+ 7;
248 segment
[3].x1
= x
- (s
- 2); segment
[3].y1
= ty
+ 1;
249 segment
[3].x2
= x
- (s
- 2); segment
[3].y2
= my
- fh
/2 - 1;
251 XDrawSegments(dpy
, root
, gc
, segment
, 4);
259 segment
[1].y1
= by
- 1;
260 segment
[1].y2
= by
- 7;
262 segment
[2].y1
= by
- 1;
263 segment
[2].y2
= by
- 7;
266 segment
[3].y1
= my
+ fh
/2 + 2;
267 segment
[3].y2
= by
- 1;
269 XDrawSegments(dpy
, root
, gc
, segment
, 4);
271 sprintf(num
, "%i", (by
- ty
- wwin
->normal_hints
->base_height
) /
272 wwin
->normal_hints
->height_inc
);
273 fw
= WMWidthOfString(scr
->info_text_font
, num
, strlen(num
));
275 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
277 /* Display the height. */
278 WMDrawString(scr
->wmscreen
, root
, gc
, scr
->info_text_font
,
279 x
- s
+ 3 - fw
/2, my
- fh
/2 + 1, num
, strlen(num
));
280 XSetForeground(dpy
, gc
, scr
->line_pixel
);
281 /* horizontal geometry */
289 mx
= x1
+ (x2
- x1
)/2;
290 sprintf(num
, "%i", (x2
- x1
- wwin
->normal_hints
->base_width
) /
291 wwin
->normal_hints
->width_inc
);
292 fw
= WMWidthOfString(scr
->info_text_font
, num
, strlen(num
));
296 segment
[0].x1
= x1
; segment
[0].y1
= y
- (s
+ 6);
297 segment
[0].x2
= x1
; segment
[0].y2
= y
- (s
- 10);
300 segment
[1].x1
= x1
+ 7; segment
[1].y1
= y
- (s
+ 1);
301 segment
[1].x2
= x1
+ 1; segment
[1].y2
= y
- (s
- 2);
303 segment
[2].x1
= x1
+ 1; segment
[2].y1
= y
- (s
- 2);
304 segment
[2].x2
= x1
+ 7; segment
[2].y2
= y
- (s
- 5);
307 segment
[3].x1
= x1
+ 1; segment
[3].y1
= y
- (s
- 2);
308 segment
[3].x2
= mx
- fw
/2 - 2; segment
[3].y2
= y
- (s
- 2);
310 XDrawSegments(dpy
, root
, gc
, segment
, 4);
314 segment
[0].x1
= x2
+ 1;
315 segment
[0].x2
= x2
+ 1;
318 segment
[1].x1
= x2
- 6;
322 segment
[2].x2
= x2
- 6;
325 segment
[3].x1
= mx
+ fw
/2 + 2;
328 XDrawSegments(dpy
, root
, gc
, segment
, 4);
330 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
332 /* Display the width. */
333 WMDrawString(scr
->wmscreen
, root
, gc
, scr
->info_text_font
,
334 mx
- fw
/2 + 1, y
- s
- fh
/2 + 1, num
, strlen(num
));
336 WSetGeometryViewShownSize(scr
->gview
,
337 (x2
- x1
- wwin
->normal_hints
->base_width
)
338 / wwin
->normal_hints
->width_inc
,
339 (by
- ty
- wwin
->normal_hints
->base_height
)
340 / wwin
->normal_hints
->height_inc
);
346 cycleGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
, int dir
)
348 WScreen
*scr
= wwin
->screen_ptr
;
350 wPreferences
.size_display
++;
351 wPreferences
.size_display
%= NUM_DISPLAYS
;
353 if (wPreferences
.size_display
== WDIS_NEW
) {
354 WMUnmapWidget(scr
->gview
);
356 if (wPreferences
.size_display
== WDIS_CENTER
) {
357 moveGeometryDisplayCentered(scr
,
358 scr
->scr_width
/ 2, scr
->scr_height
/ 2);
359 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
360 moveGeometryDisplayCentered(scr
, 1, 1);
361 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
362 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
364 WMMapWidget(scr
->gview
);
365 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, dir
);
371 mapGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
373 WScreen
*scr
= wwin
->screen_ptr
;
375 if (wPreferences
.size_display
== WDIS_NEW
)
378 if (wPreferences
.size_display
== WDIS_CENTER
) {
379 moveGeometryDisplayCentered(scr
, scr
->scr_width
/ 2,
380 scr
->scr_height
/ 2);
381 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
382 moveGeometryDisplayCentered(scr
, 1, 1);
383 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
384 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
386 WMMapWidget(scr
->gview
);
387 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, 0);
393 doWindowMove(WWindow
*wwin
, WMBag
*bag
, int dx
, int dy
)
397 int scr_width
= wwin
->screen_ptr
->scr_width
;
398 int scr_height
= wwin
->screen_ptr
->scr_height
;
400 if (!bag
|| !WMGetBagItemCount(bag
)) {
401 wWindowMove(wwin
, wwin
->frame_x
+ dx
, wwin
->frame_y
+ dy
);
404 for (i
= 0; i
< WMGetBagItemCount(bag
); i
++) {
405 tmpw
= WMGetFromBag(bag
, i
);
406 x
= tmpw
->frame_x
+ dx
;
407 y
= tmpw
->frame_y
+ dy
;
409 /* don't let windows become unreachable */
411 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
412 x
= 20 - (int)tmpw
->frame
->core
->width
;
413 else if (x
+ 20 > scr_width
)
416 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
417 y
= 20 - (int)tmpw
->frame
->core
->height
;
418 else if (y
+ 20 > scr_height
)
421 wWindowMove(tmpw
, x
, y
);
428 drawTransparentFrame(WWindow
*wwin
, int x
, int y
, int width
, int height
)
430 Window root
= wwin
->screen_ptr
->root_win
;
431 GC gc
= wwin
->screen_ptr
->frame_gc
;
435 if (!WFLAGP(wwin
, no_titlebar
) && !wwin
->flags
.shaded
) {
436 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + (wPreferences
.window_title_clearance
+ TITLEBAR_EXTEND_SPACE
) * 2;
438 if (!WFLAGP(wwin
, no_resizebar
) && !wwin
->flags
.shaded
) {
439 /* Can't use wwin-frame->bottom_width because, in some cases
440 (e.g. interactive placement), frame does not point to anything. */
441 bottom
= RESIZEBAR_HEIGHT
- 1;
443 XDrawRectangle(dpy
, root
, gc
, x
, y
, width
+ 1, height
+ 1);
446 XDrawLine(dpy
, root
, gc
, x
+ 1, y
+ h
, x
+ width
+ 1, y
+ h
);
449 XDrawLine(dpy
, root
, gc
, x
+ 1,
452 y
+ height
- bottom
);
458 drawFrames(WWindow
*wwin
, WMBag
*bag
, int dx
, int dy
)
461 int scr_width
= wwin
->screen_ptr
->scr_width
;
462 int scr_height
= wwin
->screen_ptr
->scr_height
;
467 x
= wwin
->frame_x
+ dx
;
468 y
= wwin
->frame_y
+ dy
;
470 drawTransparentFrame(wwin
, x
, y
,
471 wwin
->frame
->core
->width
,
472 wwin
->frame
->core
->height
);
476 for (i
= 0; i
< WMGetBagItemCount(bag
); i
++) {
477 tmpw
= WMGetFromBag(bag
, i
);
478 x
= tmpw
->frame_x
+ dx
;
479 y
= tmpw
->frame_y
+ dy
;
481 /* don't let windows become unreachable */
483 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
484 x
= 20 - (int)tmpw
->frame
->core
->width
;
485 else if (x
+ 20 > scr_width
)
488 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
489 y
= 20 - (int)tmpw
->frame
->core
->height
;
490 else if (y
+ 20 > scr_height
)
493 drawTransparentFrame(tmpw
, x
, y
, tmpw
->frame
->core
->width
,
494 tmpw
->frame
->core
->height
);
507 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &ev
)) ;
512 crossWorkspace(WScreen
*scr
, WWindow
*wwin
, int opaque_move
,
513 int new_workspace
, int rewind
)
515 /* do not let window be unmapped */
517 wwin
->flags
.changing_workspace
= 1;
518 wWindowChangeWorkspace(wwin
, new_workspace
);
520 /* go to new workspace */
521 wWorkspaceChange(scr
, new_workspace
);
523 wwin
->flags
.changing_workspace
= 0;
526 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, scr
->scr_width
- 20, 0);
528 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, -(scr
->scr_width
- 20), 0);
533 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
534 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
535 GrabModeAsync
, None
, wCursor
[WCUR_MOVE
], CurrentTime
);
543 /* arrays of WWindows sorted by the respective border position */
544 WWindow
**topList
; /* top border */
545 WWindow
**leftList
; /* left border */
546 WWindow
**rightList
; /* right border */
547 WWindow
**bottomList
; /* bottom border */
550 /* index of window in the above lists indicating the relative position
551 * of the window with the others */
557 int rubCount
; /* for workspace switching */
559 int winWidth
, winHeight
; /* width/height of the window */
560 int realX
, realY
; /* actual position of the window */
561 int calcX
, calcY
; /* calculated position of window */
562 int omouseX
, omouseY
; /* old mouse position */
563 int mouseX
, mouseY
; /* last known position of the pointer */
566 #define WTOP(w) (w)->frame_y
567 #define WLEFT(w) (w)->frame_x
568 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width + FRAME_BORDER_WIDTH)
569 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height + FRAME_BORDER_WIDTH)
572 compareWTop(const void *a
, const void *b
)
574 WWindow
*wwin1
= *(WWindow
**)a
;
575 WWindow
*wwin2
= *(WWindow
**)b
;
577 if (WTOP(wwin1
) > WTOP(wwin2
))
579 else if (WTOP(wwin1
) < WTOP(wwin2
))
587 compareWLeft(const void *a
, const void *b
)
589 WWindow
*wwin1
= *(WWindow
**)a
;
590 WWindow
*wwin2
= *(WWindow
**)b
;
592 if (WLEFT(wwin1
) > WLEFT(wwin2
))
594 else if (WLEFT(wwin1
) < WLEFT(wwin2
))
602 compareWRight(const void *a
, const void *b
)
604 WWindow
*wwin1
= *(WWindow
**)a
;
605 WWindow
*wwin2
= *(WWindow
**)b
;
607 if (WRIGHT(wwin1
) < WRIGHT(wwin2
))
609 else if (WRIGHT(wwin1
) > WRIGHT(wwin2
))
618 compareWBottom(const void *a
, const void *b
)
620 WWindow
*wwin1
= *(WWindow
**)a
;
621 WWindow
*wwin2
= *(WWindow
**)b
;
623 if (WBOTTOM(wwin1
) < WBOTTOM(wwin2
))
625 else if (WBOTTOM(wwin1
) > WBOTTOM(wwin2
))
633 updateResistance(WWindow
*wwin
, MoveData
*data
, int newX
, int newY
)
636 int newX2
= newX
+ data
->winWidth
;
637 int newY2
= newY
+ data
->winHeight
;
640 if (newX
< data
->realX
) {
641 if (data
->rightIndex
> 0
642 && newX
< WRIGHT(data
->rightList
[data
->rightIndex
-1])) {
644 } else if (data
->leftIndex
<= data
->count
-1
645 && newX2
<= WLEFT(data
->leftList
[data
->leftIndex
])) {
648 } else if (newX
> data
->realX
) {
649 if (data
->leftIndex
> 0
650 && newX2
> WLEFT(data
->leftList
[data
->leftIndex
-1])) {
652 } else if (data
->rightIndex
<= data
->count
-1
653 && newX
>= WRIGHT(data
->rightList
[data
->rightIndex
])) {
659 if (newY
< data
->realY
) {
660 if (data
->bottomIndex
> 0
661 && newY
< WBOTTOM(data
->bottomList
[data
->bottomIndex
-1])) {
663 } else if (data
->topIndex
<= data
->count
-1
664 && newY2
<= WTOP(data
->topList
[data
->topIndex
])) {
667 } else if (newY
> data
->realY
) {
668 if (data
->topIndex
> 0
669 && newY2
> WTOP(data
->topList
[data
->topIndex
-1])) {
671 } else if (data
->bottomIndex
<= data
->count
-1
672 && newY
>= WBOTTOM(data
->bottomList
[data
->bottomIndex
])) {
681 /* TODO: optimize this */
682 if (data
->realY
< WBOTTOM(data
->bottomList
[0])) {
683 data
->bottomIndex
= 0;
685 if (data
->realX
< WRIGHT(data
->rightList
[0])) {
686 data
->rightIndex
= 0;
688 if ((data
->realX
+ data
->winWidth
) > WLEFT(data
->leftList
[0])) {
691 if ((data
->realY
+ data
->winHeight
) > WTOP(data
->topList
[0])) {
694 for (i
= 0; i
< data
->count
; i
++) {
695 if (data
->realY
> WBOTTOM(data
->bottomList
[i
])) {
696 data
->bottomIndex
= i
+ 1;
698 if (data
->realX
> WRIGHT(data
->rightList
[i
])) {
699 data
->rightIndex
= i
+ 1;
701 if ((data
->realX
+ data
->winWidth
) < WLEFT(data
->leftList
[i
])) {
702 data
->leftIndex
= i
+ 1;
704 if ((data
->realY
+ data
->winHeight
) < WTOP(data
->topList
[i
])) {
705 data
->topIndex
= i
+ 1;
712 freeMoveData(MoveData
*data
)
715 wfree(data
->topList
);
717 wfree(data
->leftList
);
719 wfree(data
->rightList
);
720 if (data
->bottomList
)
721 wfree(data
->bottomList
);
726 updateMoveData(WWindow
*wwin
, MoveData
*data
)
728 WScreen
*scr
= wwin
->screen_ptr
;
733 tmp
= scr
->focused_window
;
735 if (tmp
!= wwin
&& scr
->current_workspace
== tmp
->frame
->workspace
736 && !tmp
->flags
.miniaturized
737 && !tmp
->flags
.hidden
738 && !tmp
->flags
.obscured
739 && !WFLAGP(tmp
, sunken
)) {
740 data
->topList
[data
->count
] = tmp
;
741 data
->leftList
[data
->count
] = tmp
;
742 data
->rightList
[data
->count
] = tmp
;
743 data
->bottomList
[data
->count
] = tmp
;
749 if (data
->count
== 0) {
752 data
->rightIndex
= 0;
753 data
->bottomIndex
= 0;
758 * order from closest to the border of the screen to farthest
760 qsort(data
->topList
, data
->count
, sizeof(WWindow
**), compareWTop
);
761 qsort(data
->leftList
, data
->count
, sizeof(WWindow
**), compareWLeft
);
762 qsort(data
->rightList
, data
->count
, sizeof(WWindow
**), compareWRight
);
763 qsort(data
->bottomList
, data
->count
, sizeof(WWindow
**), compareWBottom
);
765 /* figure the position of the window relative to the others */
768 data
->leftIndex
= -1;
769 data
->rightIndex
= -1;
770 data
->bottomIndex
= -1;
772 if (WTOP(wwin
) < WBOTTOM(data
->bottomList
[0])) {
773 data
->bottomIndex
= 0;
775 if (WLEFT(wwin
) < WRIGHT(data
->rightList
[0])) {
776 data
->rightIndex
= 0;
778 if (WRIGHT(wwin
) > WLEFT(data
->leftList
[0])) {
781 if (WBOTTOM(wwin
) > WTOP(data
->topList
[0])) {
784 for (i
= 0; i
< data
->count
; i
++) {
785 if (WTOP(wwin
) >= WBOTTOM(data
->bottomList
[i
])) {
786 data
->bottomIndex
= i
+ 1;
788 if (WLEFT(wwin
) >= WRIGHT(data
->rightList
[i
])) {
789 data
->rightIndex
= i
+ 1;
791 if (WRIGHT(wwin
) <= WLEFT(data
->leftList
[i
])) {
792 data
->leftIndex
= i
+ 1;
794 if (WBOTTOM(wwin
) <= WTOP(data
->topList
[i
])) {
795 data
->topIndex
= i
+ 1;
802 initMoveData(WWindow
*wwin
, MoveData
*data
)
807 memset(data
, 0, sizeof(MoveData
));
809 for (i
= 0, tmp
= wwin
->screen_ptr
->focused_window
;
811 tmp
= tmp
->prev
, i
++);
814 data
->topList
= wmalloc(sizeof(WWindow
*) * i
);
815 data
->leftList
= wmalloc(sizeof(WWindow
*) * i
);
816 data
->rightList
= wmalloc(sizeof(WWindow
*) * i
);
817 data
->bottomList
= wmalloc(sizeof(WWindow
*) * i
);
819 updateMoveData(wwin
, data
);
822 data
->realX
= wwin
->frame_x
;
823 data
->realY
= wwin
->frame_y
;
824 data
->calcX
= wwin
->frame_x
;
825 data
->calcY
= wwin
->frame_y
;
827 data
->winWidth
= wwin
->frame
->core
->width
+ 2;
828 data
->winHeight
= wwin
->frame
->core
->height
+ 2;
833 checkWorkspaceChange(WWindow
*wwin
, MoveData
*data
, Bool opaqueMove
)
835 WScreen
*scr
= wwin
->screen_ptr
;
836 Bool changed
= False
;
838 if (data
->mouseX
<= 1) {
839 if (scr
->current_workspace
> 0) {
841 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
- 1,
846 } else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
) {
848 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->workspace_count
- 1,
853 } else if (data
->mouseX
>= scr
->scr_width
- 2) {
855 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
857 if (wPreferences
.ws_cycle
858 || scr
->workspace_count
== MAX_WORKSPACES
) {
860 crossWorkspace(scr
, wwin
, opaqueMove
, 0, False
);
864 /* if user insists on trying to go to next workspace even when
865 * it's already the last, create a new one */
866 else if (data
->omouseX
== data
->mouseX
867 && wPreferences
.ws_advance
) {
869 /* detect user "rubbing" the window against the edge */
870 if (data
->rubCount
> 0
871 && data
->omouseY
- data
->mouseY
> MOVE_THRESHOLD
) {
873 data
->rubCount
= -(data
->rubCount
+ 1);
875 } else if (data
->rubCount
<= 0
876 && data
->mouseY
- data
->omouseY
> MOVE_THRESHOLD
) {
878 data
->rubCount
= -data
->rubCount
+ 1;
881 /* create a new workspace */
882 if (abs(data
->rubCount
) > 2) {
883 /* go to next workspace */
886 crossWorkspace(scr
, wwin
, opaqueMove
,
887 scr
->current_workspace
+1, False
);
891 } else if (scr
->current_workspace
< scr
->workspace_count
) {
893 /* go to next workspace */
894 crossWorkspace(scr
, wwin
, opaqueMove
,
895 scr
->current_workspace
+1, False
);
908 updateWindowPosition(WWindow
*wwin
, MoveData
*data
, Bool doResistance
,
909 Bool opaqueMove
, int newMouseX
, int newMouseY
)
911 WScreen
*scr
= wwin
->screen_ptr
;
912 int dx
, dy
; /* how much mouse moved */
913 int winL
, winR
, winT
, winB
; /* requested new window position */
914 int newX
, newY
; /* actual new window position */
915 Bool hresist
, vresist
;
924 /* check the direction of the movement */
925 dx
= newMouseX
- data
->mouseX
;
926 dy
= newMouseY
- data
->mouseY
;
928 data
->omouseX
= data
->mouseX
;
929 data
->omouseY
= data
->mouseY
;
930 data
->mouseX
= newMouseX
;
931 data
->mouseY
= newMouseY
;
933 winL
= data
->calcX
+ dx
;
934 winR
= data
->calcX
+ data
->winWidth
+ dx
;
935 winT
= data
->calcY
+ dy
;
936 winB
= data
->calcY
+ data
->winHeight
+ dy
;
948 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
949 attract
= wPreferences
.attract
;
950 /* horizontal movement: check horizontal edge resistances */
953 /* window is the leftmost window: check against screen edge */
954 l_edge
= scr
->totalUsableArea
.x1
;
955 r_edge
= scr
->totalUsableArea
.x2
+ resist
;
956 edge_l
= scr
->totalUsableArea
.x1
- resist
;
957 edge_r
= scr
->totalUsableArea
.x2
;
960 if ((data
->rightIndex
>= 0) && (data
->rightIndex
<= data
->count
)) {
963 for (i
= data
->rightIndex
- 1; i
>= 0; i
--) {
964 looprw
= data
->rightList
[i
];
965 if (!(data
->realY
> WBOTTOM(looprw
)
966 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
968 || ((data
->realX
< (WRIGHT(looprw
) + 2)) && dx
< 0)) {
969 l_edge
= WRIGHT(looprw
) + 1;
970 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
977 for (i
= data
->rightIndex
; i
< data
->count
; i
++) {
978 looprw
= data
->rightList
[i
];
979 if(!(data
->realY
> WBOTTOM(looprw
)
980 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
981 r_edge
= WRIGHT(looprw
) + 1;
982 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
989 if ((data
->leftIndex
>= 0) && (data
->leftIndex
<= data
->count
)) {
992 for (i
= data
->leftIndex
- 1; i
>= 0; i
--) {
993 looprw
= data
->leftList
[i
];
994 if (!(data
->realY
> WBOTTOM(looprw
)
995 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
997 || (((data
->realX
+ data
->winWidth
) > (WLEFT(looprw
) - 1)) && dx
> 0)) {
998 edge_r
= WLEFT(looprw
);
999 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1006 for (i
= data
->leftIndex
; i
< data
->count
; i
++) {
1007 looprw
= data
->leftList
[i
];
1008 if(!(data
->realY
> WBOTTOM(looprw
)
1009 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1010 edge_l
= WLEFT(looprw
);
1011 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1018 printf("%d %d\n",winL,winR);
1019 printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);
1022 if ((winL
- l_edge
) < (r_edge
- winL
)) {
1024 if ((attract
&& winL
<= l_edge
+ resist
&& winL
>= l_edge
- resist
)
1025 || (dx
< 0 && winL
<= l_edge
&& winL
>= l_edge
- resist
)) {
1031 if (resist
> 0 && attract
&& winL
>= r_edge
- resist
&& winL
<= r_edge
+ resist
) {
1037 if ((winR
- edge_l
) < (edge_r
- winR
)) {
1038 if (resist
> 0 && attract
&& winR
<= edge_l
+ resist
&& winR
>= edge_l
- resist
) {
1039 newX
= edge_l
- data
->winWidth
;
1044 if ((attract
&& winR
>= edge_r
- resist
&& winR
<= edge_r
+ resist
)
1045 || (dx
> 0 && winR
>= edge_r
&& winR
<= edge_r
+ resist
)) {
1046 newX
= edge_r
- data
->winWidth
;
1053 t_edge
= scr
->totalUsableArea
.y1
;
1054 b_edge
= scr
->totalUsableArea
.y2
+ resist
;
1055 edge_t
= scr
->totalUsableArea
.y1
- resist
;
1056 edge_b
= scr
->totalUsableArea
.y2
;
1058 if ((data
->bottomIndex
>= 0) && (data
->bottomIndex
<= data
->count
)) {
1061 for (i
= data
->bottomIndex
- 1; i
>= 0; i
--) {
1062 looprw
= data
->bottomList
[i
];
1063 if (!(data
->realX
> WRIGHT(looprw
)
1064 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1066 || ((data
->realY
< (WBOTTOM(looprw
) + 2)) && dy
< 0)) {
1067 t_edge
= WBOTTOM(looprw
) + 1;
1068 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1075 for (i
= data
->bottomIndex
; i
< data
->count
; i
++) {
1076 looprw
= data
->bottomList
[i
];
1077 if(!(data
->realX
> WRIGHT(looprw
)
1078 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1079 b_edge
= WBOTTOM(looprw
) + 1;
1080 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1087 if ((data
->topIndex
>= 0) && (data
->topIndex
<= data
->count
)) {
1090 for (i
= data
->topIndex
- 1; i
>= 0; i
--) {
1091 looprw
= data
->topList
[i
];
1092 if (!(data
->realX
> WRIGHT(looprw
)
1093 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1095 || (((data
->realY
+ data
->winHeight
) > (WTOP(looprw
) - 1)) && dy
> 0)) {
1096 edge_b
= WTOP(looprw
);
1097 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1104 for (i
= data
->topIndex
; i
< data
->count
; i
++) {
1105 looprw
= data
->topList
[i
];
1106 if(!(data
->realX
> WRIGHT(looprw
)
1107 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1108 edge_t
= WTOP(looprw
);
1109 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1115 if ((winT
- t_edge
) < (b_edge
- winT
)) {
1117 if ((attract
&& winT
<= t_edge
+ resist
&& winT
>= t_edge
- resist
)
1118 || (dy
< 0 && winT
<= t_edge
&& winT
>= t_edge
- resist
)) {
1125 if (resist
> 0 && attract
&& winT
>= b_edge
- resist
&& winT
<= b_edge
+ resist
) {
1131 if ((winB
- edge_t
) < (edge_b
- winB
)) {
1132 if (resist
> 0 && attract
&& winB
<= edge_t
+ resist
&& winB
>= edge_t
- resist
) {
1133 newY
= edge_t
- data
->winHeight
;
1139 if ((attract
&& winB
>= edge_b
- resist
&& winB
<= edge_b
+ resist
)
1140 || (dy
> 0 && winB
>= edge_b
&& winB
<= edge_b
+ resist
)) {
1141 newY
= edge_b
- data
->winHeight
;
1151 /* update window position */
1155 if (((dx
> 0 && data
->calcX
- data
->realX
> 0)
1156 || (dx
< 0 && data
->calcX
- data
->realX
< 0)) && !hresist
)
1159 if (((dy
> 0 && data
->calcY
- data
->realY
> 0)
1160 || (dy
< 0 && data
->calcY
- data
->realY
< 0)) && !vresist
)
1163 if (data
->realX
!= newX
|| data
->realY
!= newY
) {
1165 if (wPreferences
.move_display
== WDIS_NEW
1166 && !scr
->selected_windows
) {
1167 showPosition(wwin
, data
->realX
, data
->realY
);
1170 doWindowMove(wwin
, scr
->selected_windows
,
1171 newX
- wwin
->frame_x
,
1172 newY
- wwin
->frame_y
);
1175 drawFrames(wwin
, scr
->selected_windows
,
1176 data
->realX
- wwin
->frame_x
,
1177 data
->realY
- wwin
->frame_y
);
1180 if (!scr
->selected_windows
1181 && wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
1183 moveGeometryDisplayCentered(scr
, newX
+ data
->winWidth
/2,
1184 newY
+ data
->winHeight
/2);
1189 drawFrames(wwin
, scr
->selected_windows
,
1190 newX
- wwin
->frame_x
,
1191 newY
- wwin
->frame_y
);
1194 if (!scr
->selected_windows
) {
1195 showPosition(wwin
, newX
, newY
);
1200 /* recalc relative window position */
1201 if (doResistance
&& (data
->realX
!= newX
|| data
->realY
!= newY
)) {
1202 updateResistance(wwin
, data
, newX
, newY
);
1210 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1213 wKeyboardMoveResizeWindow(WWindow
*wwin
)
1215 WScreen
*scr
= wwin
->screen_ptr
;
1216 Window root
= scr
->root_win
;
1218 int w
= wwin
->frame
->core
->width
;
1219 int h
= wwin
->frame
->core
->height
;
1220 int scr_width
= wwin
->screen_ptr
->scr_width
;
1221 int scr_height
= wwin
->screen_ptr
->scr_height
;
1222 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1223 int src_x
= wwin
->frame_x
;
1224 int src_y
= wwin
->frame_y
;
1225 int done
,off_x
,off_y
,ww
,wh
;
1228 KeySym keysym
=NoSymbol
;
1230 KeyCode shiftl
,shiftr
,ctrll
,ctrlmode
;
1232 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1233 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1234 ctrll
= XKeysymToKeycode(dpy
, XK_Control_L
);
1235 ctrlmode
=done
=off_x
=off_y
=0;
1239 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1241 if (!wwin
->flags
.selected
) {
1242 wUnselectWindows(scr
);
1245 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1246 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
1247 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
);
1249 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1250 if(scr
->selected_windows
)
1251 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1252 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1253 if(!scr
->selected_windows
)
1254 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1256 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1266 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1267 | ButtonPressMask
| ExposureMask
, &event
);
1268 if (event
.type
== Expose
) {
1269 WMHandleEvent(&event
);
1271 } while (event
.type
== Expose
);
1274 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1275 if(scr
->selected_windows
)
1276 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1277 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1278 /*** I HATE EDGE RESISTANCE - ]d ***/
1281 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1285 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1290 switch (event
.type
) {
1293 if (event
.xkey
.time
- lastTime
> 50) {
1294 kspeed
/=(1 + (event
.xkey
.time
- lastTime
)/100);
1300 if (kspeed
< _KS
) kspeed
= _KS
;
1301 lastTime
= event
.xkey
.time
;
1303 if (event
.xkey
.state
& ControlMask
&& !wwin
->flags
.shaded
) {
1305 wUnselectWindows(scr
);
1310 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
) {
1312 cycleGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
, 0);
1314 cyclePositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1318 keysym
= XLookupKeysym(&event
.xkey
, 0);
1373 if (moment
!= RIGHT
)
1384 wWindowConstrainSize(wwin
, &ww
, &wh
);
1387 if (wPreferences
.ws_cycle
){
1388 if (src_x
+ off_x
+ ww
< 20){
1389 if(!scr
->current_workspace
) {
1390 wWorkspaceChange(scr
, scr
->workspace_count
-1);
1392 else wWorkspaceChange(scr
, scr
->current_workspace
-1);
1395 else if (src_x
+ off_x
+ 20 > scr_width
){
1396 if(scr
->current_workspace
== scr
->workspace_count
-1) {
1397 wWorkspaceChange(scr
, 0);
1399 else wWorkspaceChange(scr
, scr
->current_workspace
+1);
1404 if (src_x
+ off_x
+ ww
< 20)
1405 off_x
= 20 - ww
- src_x
;
1406 else if (src_x
+ off_x
+ 20 > scr_width
)
1407 off_x
= scr_width
- 20 - src_x
;
1410 if (src_y
+ off_y
+ wh
< 20) {
1411 off_y
= 20 - wh
- src_y
;
1413 else if (src_y
+ off_y
+ 20 > scr_height
) {
1414 off_y
= scr_height
- 20 - src_y
;
1423 WMHandleEvent(&event
);
1424 while (XCheckTypedEvent(dpy
, Expose
, &event
)) {
1425 WMHandleEvent(&event
);
1430 WMHandleEvent(&event
);
1437 if (wwin
->flags
.shaded
&& !scr
->selected_windows
){
1438 moveGeometryDisplayCentered(scr
, src_x
+off_x
+ w
/2, src_y
+off_y
+ h
/2);
1441 WMUnmapWidget(scr
->gview
);
1442 mapGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1443 } else if(!scr
->selected_windows
) {
1444 WMUnmapWidget(scr
->gview
);
1445 mapPositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1449 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1450 if (scr
->selected_windows
)
1451 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1453 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1455 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 } else if(!scr
->selected_windows
)
1462 showPosition(wwin
, src_x
+off_x
, src_y
+off_y
);
1466 scr
->keymove_tick
=0;
1468 WMDeleteTimerWithClientData(&looper);
1470 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1471 if(scr
->selected_windows
)
1472 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1473 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1476 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1480 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1481 WMUnmapWidget(scr
->gview
);
1483 WMUnmapWidget(scr
->gview
);
1485 XUngrabKeyboard(dpy
, CurrentTime
);
1486 XUngrabPointer(dpy
, CurrentTime
);
1490 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1491 if (!scr
->selected_windows
) {
1492 wWindowMove(wwin
, src_x
+off_x
, src_y
+off_y
);
1493 wWindowSynthConfigureNotify(wwin
);
1496 WMBag
*bag
= scr
->selected_windows
;
1497 doWindowMove(wwin
,scr
->selected_windows
,off_x
,off_y
);
1498 for (i
= 0; i
< WMGetBagItemCount(bag
); i
++) {
1499 wWindowSynthConfigureNotify(WMGetFromBag(bag
, i
));
1503 if (wwin
->client
.width
!= ww
)
1504 wwin
->flags
.user_changed_width
= 1;
1506 if (wwin
->client
.height
!= wh
- vert_border
)
1507 wwin
->flags
.user_changed_height
= 1;
1509 wWindowConfigure(wwin
, src_x
+off_x
, src_y
+off_y
,
1510 ww
, wh
- vert_border
);
1511 wWindowSynthConfigureNotify(wwin
);
1513 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1514 wSetFocusTo(scr
, wwin
);
1523 *----------------------------------------------------------------------
1524 * wMouseMoveWindow--
1525 * Move the named window and the other selected ones (if any),
1526 * interactively. Also shows the position of the window, if only one
1527 * window is being moved.
1528 * If the window is not on the selected window list, the selected
1529 * windows are deselected.
1530 * If shift is pressed during the operation, the position display
1531 * is changed to another type.
1534 * True if the window was moved, False otherwise.
1537 * The window(s) position is changed, and the client(s) are
1538 * notified about that.
1539 * The position display configuration may be changed.
1540 *----------------------------------------------------------------------
1543 wMouseMoveWindow(WWindow
*wwin
, XEvent
*ev
)
1545 WScreen
*scr
= wwin
->screen_ptr
;
1547 Window root
= scr
->root_win
;
1548 KeyCode shiftl
, shiftr
;
1552 /* This needs not to change while moving, else bad things can happen */
1553 int opaqueMove
= wPreferences
.opaque_move
;
1555 #ifdef GHOST_WINDOW_MOVE
1558 rimg
= InitGhostWindowMove(scr
);
1562 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1563 XSetWindowAttributes attr
;
1565 attr
.save_under
= True
;
1566 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
,
1567 CWSaveUnder
, &attr
);
1571 initMoveData(wwin
, &moveData
);
1573 moveData
.mouseX
= ev
->xmotion
.x_root
;
1574 moveData
.mouseY
= ev
->xmotion
.y_root
;
1576 if (!wwin
->flags
.selected
) {
1577 /* this window is not selected, unselect others and move only wwin */
1578 wUnselectWindows(scr
);
1581 puts("Moving window");
1583 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1584 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1590 /* XWarpPointer() doesn't seem to generate Motion events, so
1591 we've got to simulate them */
1592 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1593 &event
.xmotion
.y_root
, &junk
, &junk
,
1594 (unsigned *) &junk
);
1596 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1597 | PointerMotionHintMask
1598 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
,
1601 if (event
.type
== MotionNotify
) {
1602 /* compress MotionNotify events */
1603 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1604 if (!checkMouseSamplingRate(&event
))
1608 switch (event
.type
) {
1610 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1611 && started
&& !scr
->selected_windows
) {
1614 drawFrames(wwin
, scr
->selected_windows
,
1615 moveData
.realX
- wwin
->frame_x
,
1616 moveData
.realY
- wwin
->frame_y
);
1619 if (wPreferences
.move_display
== WDIS_NEW
1620 && !scr
->selected_windows
) {
1621 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1624 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1625 moveData
.winWidth
, moveData
.winHeight
);
1627 if (wPreferences
.move_display
== WDIS_NEW
1628 && !scr
->selected_windows
) {
1630 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1634 drawFrames(wwin
, scr
->selected_windows
,
1635 moveData
.realX
- wwin
->frame_x
,
1636 moveData
.realY
- wwin
->frame_y
);
1643 updateWindowPosition(wwin
, &moveData
,
1644 scr
->selected_windows
== NULL
1645 && wPreferences
.edge_resistance
> 0,
1647 event
.xmotion
.x_root
,
1648 event
.xmotion
.y_root
);
1650 if (!warped
&& !wPreferences
.no_autowrap
) {
1651 int oldWorkspace
= scr
->current_workspace
;
1653 if (wPreferences
.move_display
== WDIS_NEW
1654 && !scr
->selected_windows
) {
1655 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1659 drawFrames(wwin
, scr
->selected_windows
,
1660 moveData
.realX
- wwin
->frame_x
,
1661 moveData
.realY
- wwin
->frame_y
);
1663 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1664 if (scr
->current_workspace
!= oldWorkspace
1665 && wPreferences
.edge_resistance
> 0
1666 && scr
->selected_windows
== NULL
)
1667 updateMoveData(wwin
, &moveData
);
1671 drawFrames(wwin
, scr
->selected_windows
,
1672 moveData
.realX
- wwin
->frame_x
,
1673 moveData
.realY
- wwin
->frame_y
);
1675 if (wPreferences
.move_display
== WDIS_NEW
1676 && !scr
->selected_windows
) {
1678 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1684 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1685 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1687 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1688 | ButtonReleaseMask
| ButtonPressMask
,
1689 wCursor
[WCUR_MOVE
], CurrentTime
);
1691 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1694 if (!scr
->selected_windows
)
1695 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1696 moveData
.winWidth
, moveData
.winHeight
);
1698 if (started
&& !opaqueMove
)
1699 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1701 if (!opaqueMove
|| (wPreferences
.move_display
==WDIS_NEW
1702 && !scr
->selected_windows
)) {
1704 if (wPreferences
.move_display
==WDIS_NEW
)
1705 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1714 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1720 drawFrames(wwin
, scr
->selected_windows
,
1721 moveData
.realX
- wwin
->frame_x
,
1722 moveData
.realY
- wwin
->frame_y
);
1724 doWindowMove(wwin
, scr
->selected_windows
,
1725 moveData
.realX
- wwin
->frame_x
,
1726 moveData
.realY
- wwin
->frame_y
);
1728 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1729 wWindowSynthConfigureNotify(wwin
);
1731 XUngrabKeyboard(dpy
, CurrentTime
);
1734 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1735 wSetFocusTo(scr
, wwin
);
1737 if (wPreferences
.move_display
== WDIS_NEW
)
1738 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1740 /* discard all enter/leave events that happened until
1741 * the time the button was released */
1742 while (XCheckTypedEvent(dpy
, EnterNotify
, &e
)) {
1743 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1744 XPutBackEvent(dpy
, &e
);
1748 while (XCheckTypedEvent(dpy
, LeaveNotify
, &e
)) {
1749 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1750 XPutBackEvent(dpy
, &e
);
1755 if (!scr
->selected_windows
) {
1756 /* get rid of the geometry window */
1757 WMUnmapWidget(scr
->gview
);
1761 puts("End move window");
1767 if (started
&& !opaqueMove
) {
1768 drawFrames(wwin
, scr
->selected_windows
,
1769 moveData
.realX
- wwin
->frame_x
,
1770 moveData
.realY
- wwin
->frame_y
);
1772 WMHandleEvent(&event
);
1775 drawFrames(wwin
, scr
->selected_windows
,
1776 moveData
.realX
- wwin
->frame_x
,
1777 moveData
.realY
- wwin
->frame_y
);
1779 WMHandleEvent(&event
);
1785 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1786 XSetWindowAttributes attr
;
1789 attr
.save_under
= False
;
1790 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
,
1791 CWSaveUnder
, &attr
);
1795 freeMoveData(&moveData
);
1802 #define HCONSTRAIN 2
1805 getResizeDirection(WWindow
*wwin
, int x
, int y
, int dx
, int dy
,
1808 int w
= wwin
->frame
->core
->width
- 1;
1809 int cw
= wwin
->frame
->resizebar_corner_width
;
1812 /* if not resizing through the resizebar */
1813 if (!(flags
& RESIZEBAR
)) {
1814 int xdir
= (abs(x
) < (wwin
->client
.width
/2)) ? LEFT
: RIGHT
;
1815 int ydir
= (abs(y
) < (wwin
->client
.height
/2)) ? UP
: DOWN
;
1816 if (abs(dx
) < 2 || abs(dy
) < 2) {
1817 if (abs(dy
) > abs(dx
))
1822 return (xdir
| ydir
);
1825 /* window is too narrow. allow diagonal resize */
1829 if (flags
& HCONSTRAIN
)
1834 return (LEFT
| ydir
);
1836 return (RIGHT
| ydir
);
1838 /* vertical resize */
1839 if ((x
> cw
) && (x
< w
- cw
))
1847 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1855 wMouseResizeWindow(WWindow
*wwin
, XEvent
*ev
)
1858 WScreen
*scr
= wwin
->screen_ptr
;
1859 Window root
= scr
->root_win
;
1860 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1861 int fw
= wwin
->frame
->core
->width
;
1862 int fh
= wwin
->frame
->core
->height
;
1863 int fx
= wwin
->frame_x
;
1864 int fy
= wwin
->frame_y
;
1865 int is_resizebar
= (wwin
->frame
->resizebar
1866 && ev
->xany
.window
==wwin
->frame
->resizebar
->window
);
1870 int rw
= fw
, rh
= fh
;
1871 int rx1
, ry1
, rx2
, ry2
;
1873 KeyCode shiftl
, shiftr
;
1880 if (wwin
->flags
.shaded
) {
1881 wwarning("internal error: tryein");
1884 orig_x
= ev
->xbutton
.x_root
;
1885 orig_y
= ev
->xbutton
.y_root
;
1889 puts("Resizing window");
1892 wUnselectWindows(scr
);
1897 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1898 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1899 if (!WFLAGP(wwin
, no_titlebar
))
1900 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + (wPreferences
.window_title_clearance
+ TITLEBAR_EXTEND_SPACE
) * 2;
1904 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1905 | ButtonReleaseMask
| PointerMotionHintMask
1906 | ButtonPressMask
| ExposureMask
, &event
);
1907 if (!checkMouseSamplingRate(&event
))
1910 switch (event
.type
) {
1912 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1913 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1915 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1916 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
1917 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1919 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1924 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1935 dw
= orig_x
- event
.xmotion
.x_root
;
1936 else if (res
& RIGHT
)
1937 dw
= event
.xmotion
.x_root
- orig_x
;
1939 dh
= orig_y
- event
.xmotion
.y_root
;
1940 else if (res
& DOWN
)
1941 dh
= event
.xmotion
.y_root
- orig_y
;
1943 orig_x
= event
.xmotion
.x_root
;
1944 orig_y
= event
.xmotion
.y_root
;
1949 fh
= rh
- vert_border
;
1950 wWindowConstrainSize(wwin
, &fw
, &fh
);
1954 else if (res
& RIGHT
)
1958 else if (res
& DOWN
)
1960 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1961 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1966 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
1967 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
1969 /* check if resizing through resizebar */
1975 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
1976 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
1977 flags
|= HCONSTRAIN
;
1979 res
= getResizeDirection(wwin
, tx
, ty
,
1980 orig_x
- event
.xmotion
.x_root
,
1981 orig_y
- event
.xmotion
.y_root
, flags
);
1983 if (res
== (UP
|LEFT
))
1984 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1985 | ButtonReleaseMask
| ButtonPressMask
,
1986 wCursor
[WCUR_TOPLEFTRESIZE
], CurrentTime
);
1987 else if (res
== (UP
|RIGHT
))
1988 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1989 | ButtonReleaseMask
| ButtonPressMask
,
1990 wCursor
[WCUR_TOPRIGHTRESIZE
], CurrentTime
);
1991 else if (res
== (DOWN
|LEFT
))
1992 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1993 | ButtonReleaseMask
| ButtonPressMask
,
1994 wCursor
[WCUR_BOTTOMLEFTRESIZE
], CurrentTime
);
1995 else if (res
== (DOWN
|RIGHT
))
1996 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1997 | ButtonReleaseMask
| ButtonPressMask
,
1998 wCursor
[WCUR_BOTTOMRIGHTRESIZE
], CurrentTime
);
1999 else if (res
== DOWN
|| res
== UP
)
2000 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2001 | ButtonReleaseMask
| ButtonPressMask
,
2002 wCursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2003 else if (res
& (DOWN
|UP
))
2004 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2005 | ButtonReleaseMask
| ButtonPressMask
,
2006 wCursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2007 else if (res
& (LEFT
|RIGHT
))
2008 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2009 | ButtonReleaseMask
| ButtonPressMask
,
2010 wCursor
[WCUR_HORIZONRESIZE
], CurrentTime
);
2012 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
2017 /* Draw the resize frame for the first time. */
2018 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
2020 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2022 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2027 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
2028 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
2030 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
2031 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2033 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
2035 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2037 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
2038 if (wPreferences
.size_display
== WDIS_NEW
) {
2039 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
2040 orig_fy
+ orig_fh
, res
);
2042 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2051 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2055 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2057 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2059 XUngrabKeyboard(dpy
, CurrentTime
);
2060 WMUnmapWidget(scr
->gview
);
2063 if (wwin
->client
.width
!= fw
)
2064 wwin
->flags
.user_changed_width
= 1;
2066 if (wwin
->client
.height
!= fh
- vert_border
)
2067 wwin
->flags
.user_changed_height
= 1;
2069 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
2072 puts("End resize window");
2077 WMHandleEvent(&event
);
2092 wUnselectWindows(WScreen
*scr
)
2096 if (!scr
->selected_windows
)
2099 while (WMGetBagItemCount(scr
->selected_windows
)) {
2100 WMBagIterator dummy
;
2102 wwin
= WMBagFirst(scr
->selected_windows
, &dummy
);
2103 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
2104 wIconSelect(wwin
->icon
);
2106 wSelectWindow(wwin
, False
);
2108 WMFreeBag(scr
->selected_windows
);
2109 scr
->selected_windows
= NULL
;
2114 selectWindowsInside(WScreen
*scr
, int x1
, int y1
, int x2
, int y2
)
2118 /* select the windows and put them in the selected window list */
2119 tmpw
= scr
->focused_window
;
2120 while (tmpw
!= NULL
) {
2121 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
2122 if ((tmpw
->frame
->workspace
== scr
->current_workspace
2123 || IS_OMNIPRESENT(tmpw
))
2124 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
2125 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
2126 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
2127 wSelectWindow(tmpw
, True
);
2136 wSelectWindows(WScreen
*scr
, XEvent
*ev
)
2139 Window root
= scr
->root_win
;
2140 GC gc
= scr
->frame_gc
;
2141 int xp
= ev
->xbutton
.x_root
;
2142 int yp
= ev
->xbutton
.y_root
;
2147 puts("Selecting windows");
2149 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
2150 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
2151 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
],
2152 CurrentTime
) != Success
) {
2157 wUnselectWindows(scr
);
2159 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
2161 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
2162 | ButtonPressMask
, &event
);
2164 switch (event
.type
) {
2166 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2167 x
= event
.xmotion
.x_root
;
2174 y
= event
.xmotion
.y_root
;
2181 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2188 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2191 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2193 XUngrabPointer(dpy
, CurrentTime
);
2194 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
2197 wKWMSelectRootRegion(scr
, xp
, yp
, w
, h
,
2198 event
.xbutton
.state
& ControlMask
);
2199 #endif /* KWM_HINTS */
2202 puts("End window selection");
2207 WMHandleEvent(&event
);
2215 InteractivePlaceWindow(WWindow
*wwin
, int *x_ret
, int *y_ret
,
2216 unsigned width
, unsigned height
)
2218 WScreen
*scr
= wwin
->screen_ptr
;
2219 Window root
= scr
->root_win
;
2222 KeyCode shiftl
, shiftr
;
2226 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2227 GrabModeAsync
, GrabModeAsync
, None
,
2228 wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2233 if (!WFLAGP(wwin
, no_titlebar
)) {
2234 h
= WMFontHeight(scr
->title_font
) + (wPreferences
.window_title_clearance
+ TITLEBAR_EXTEND_SPACE
) * 2;
2237 if (!WFLAGP(wwin
, no_resizebar
)) {
2238 height
+= RESIZEBAR_HEIGHT
;
2240 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2241 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
,
2242 (unsigned *) &junk
);
2243 mapPositionDisplay(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2245 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2247 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2248 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2250 WMMaskEvent(dpy
, PointerMotionMask
|ButtonPressMask
|ExposureMask
|KeyPressMask
,
2253 if (!checkMouseSamplingRate(&event
))
2256 switch (event
.type
) {
2258 if ((event
.xkey
.keycode
== shiftl
)
2259 || (event
.xkey
.keycode
== shiftr
)) {
2260 drawTransparentFrame(wwin
,
2261 x
- width
/2, y
- h
/2, width
, height
);
2262 cyclePositionDisplay(wwin
,
2263 x
- width
/2, y
- h
/2, width
, height
);
2264 drawTransparentFrame(wwin
,
2265 x
- width
/2, y
- h
/2, width
, height
);
2270 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2272 x
= event
.xmotion
.x_root
;
2273 y
= event
.xmotion
.y_root
;
2275 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2276 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2278 showPosition(wwin
, x
- width
/2, y
- h
/2);
2280 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2285 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2287 *x_ret
= x
- width
/2;
2289 XUngrabPointer(dpy
, CurrentTime
);
2290 XUngrabKeyboard(dpy
, CurrentTime
);
2291 /* get rid of the geometry window */
2292 WMUnmapWidget(scr
->gview
);
2296 WMHandleEvent(&event
);