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 5
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 || wPreferences
.move_display
== WDIS_NONE
) {
172 WMUnmapWidget(scr
->gview
);
174 if (wPreferences
.move_display
== WDIS_CENTER
) {
175 moveGeometryDisplayCentered(scr
,
176 scr
->scr_width
/2, scr
->scr_height
/2);
177 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
178 moveGeometryDisplayCentered(scr
, 1, 1);
179 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
180 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
182 WMMapWidget(scr
->gview
);
188 mapPositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
190 WScreen
*scr
= wwin
->screen_ptr
;
192 if (wPreferences
.move_display
== WDIS_NEW
193 || wPreferences
.move_display
== WDIS_NONE
) {
195 } else if (wPreferences
.move_display
== WDIS_CENTER
) {
196 moveGeometryDisplayCentered(scr
, scr
->scr_width
/ 2,
197 scr
->scr_height
/ 2);
198 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
199 moveGeometryDisplayCentered(scr
, 1, 1);
200 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
201 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
203 WMMapWidget(scr
->gview
);
204 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
209 showGeometry(WWindow
*wwin
, int x1
, int y1
, int x2
, int y2
, int direction
)
211 WScreen
*scr
= wwin
->screen_ptr
;
212 Window root
= scr
->root_win
;
213 GC gc
= scr
->line_gc
;
214 int ty
, by
, my
, x
, y
, mx
, s
;
219 ty
= y1
+ wwin
->frame
->top_width
;
220 by
= y2
- wwin
->frame
->bottom_width
;
221 fw
= WMWidthOfString(scr
->info_text_font
, "8888", 4);
222 fh
= WMFontHeight(scr
->info_text_font
);
224 if (wPreferences
.size_display
== WDIS_NEW
) {
225 XSetForeground(dpy
, gc
, scr
->line_pixel
);
227 /* vertical geometry */
228 if (((direction
& LEFT
) && (x2
< scr
->scr_width
- fw
)) || (x1
< fw
)) {
239 segment
[0].x1
= x
- (s
+ 6); segment
[0].y1
= ty
;
240 segment
[0].x2
= x
- (s
- 10); segment
[0].y2
= ty
;
243 segment
[1].x1
= x
- (s
- 2); segment
[1].y1
= ty
+ 1;
244 segment
[1].x2
= x
- (s
- 5); segment
[1].y2
= ty
+ 7;
246 segment
[2].x1
= x
- (s
- 2); segment
[2].y1
= ty
+ 1;
247 segment
[2].x2
= x
- (s
+ 1); segment
[2].y2
= ty
+ 7;
250 segment
[3].x1
= x
- (s
- 2); segment
[3].y1
= ty
+ 1;
251 segment
[3].x2
= x
- (s
- 2); segment
[3].y2
= my
- fh
/2 - 1;
253 XDrawSegments(dpy
, root
, gc
, segment
, 4);
261 segment
[1].y1
= by
- 1;
262 segment
[1].y2
= by
- 7;
264 segment
[2].y1
= by
- 1;
265 segment
[2].y2
= by
- 7;
268 segment
[3].y1
= my
+ fh
/2 + 2;
269 segment
[3].y2
= by
- 1;
271 XDrawSegments(dpy
, root
, gc
, segment
, 4);
273 snprintf(num
, sizeof(num
), "%i", (by
- ty
- wwin
->normal_hints
->base_height
) /
274 wwin
->normal_hints
->height_inc
);
275 fw
= WMWidthOfString(scr
->info_text_font
, num
, strlen(num
));
277 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
279 /* Display the height. */
280 WMDrawString(scr
->wmscreen
, root
, gc
, scr
->info_text_font
,
281 x
- s
+ 3 - fw
/2, my
- fh
/2 + 1, num
, strlen(num
));
282 XSetForeground(dpy
, gc
, scr
->line_pixel
);
283 /* horizontal geometry */
291 mx
= x1
+ (x2
- x1
)/2;
292 snprintf(num
, sizeof(num
), "%i", (x2
- x1
- wwin
->normal_hints
->base_width
) /
293 wwin
->normal_hints
->width_inc
);
294 fw
= WMWidthOfString(scr
->info_text_font
, num
, strlen(num
));
298 segment
[0].x1
= x1
; segment
[0].y1
= y
- (s
+ 6);
299 segment
[0].x2
= x1
; segment
[0].y2
= y
- (s
- 10);
302 segment
[1].x1
= x1
+ 7; segment
[1].y1
= y
- (s
+ 1);
303 segment
[1].x2
= x1
+ 1; segment
[1].y2
= y
- (s
- 2);
305 segment
[2].x1
= x1
+ 1; segment
[2].y1
= y
- (s
- 2);
306 segment
[2].x2
= x1
+ 7; segment
[2].y2
= y
- (s
- 5);
309 segment
[3].x1
= x1
+ 1; segment
[3].y1
= y
- (s
- 2);
310 segment
[3].x2
= mx
- fw
/2 - 2; segment
[3].y2
= y
- (s
- 2);
312 XDrawSegments(dpy
, root
, gc
, segment
, 4);
316 segment
[0].x1
= x2
+ 1;
317 segment
[0].x2
= x2
+ 1;
320 segment
[1].x1
= x2
- 6;
324 segment
[2].x2
= x2
- 6;
327 segment
[3].x1
= mx
+ fw
/2 + 2;
330 XDrawSegments(dpy
, root
, gc
, segment
, 4);
332 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
334 /* Display the width. */
335 WMDrawString(scr
->wmscreen
, root
, gc
, scr
->info_text_font
,
336 mx
- fw
/2 + 1, y
- s
- fh
/2 + 1, num
, strlen(num
));
338 WSetGeometryViewShownSize(scr
->gview
,
339 (x2
- x1
- wwin
->normal_hints
->base_width
)
340 / wwin
->normal_hints
->width_inc
,
341 (by
- ty
- wwin
->normal_hints
->base_height
)
342 / wwin
->normal_hints
->height_inc
);
348 cycleGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
, int dir
)
350 WScreen
*scr
= wwin
->screen_ptr
;
352 wPreferences
.size_display
++;
353 wPreferences
.size_display
%= NUM_DISPLAYS
;
355 if (wPreferences
.size_display
== WDIS_NEW
356 || wPreferences
.size_display
== WDIS_NONE
) {
357 WMUnmapWidget(scr
->gview
);
359 if (wPreferences
.size_display
== WDIS_CENTER
) {
360 moveGeometryDisplayCentered(scr
,
361 scr
->scr_width
/ 2, scr
->scr_height
/ 2);
362 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
363 moveGeometryDisplayCentered(scr
, 1, 1);
364 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
365 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
367 WMMapWidget(scr
->gview
);
368 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, dir
);
374 mapGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
376 WScreen
*scr
= wwin
->screen_ptr
;
378 if (wPreferences
.size_display
== WDIS_NEW
379 || wPreferences
.size_display
== WDIS_NONE
)
382 if (wPreferences
.size_display
== WDIS_CENTER
) {
383 moveGeometryDisplayCentered(scr
, scr
->scr_width
/ 2,
384 scr
->scr_height
/ 2);
385 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
386 moveGeometryDisplayCentered(scr
, 1, 1);
387 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
388 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
390 WMMapWidget(scr
->gview
);
391 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, 0);
397 doWindowMove(WWindow
*wwin
, WMArray
*array
, int dx
, int dy
)
401 int scr_width
= wwin
->screen_ptr
->scr_width
;
402 int scr_height
= wwin
->screen_ptr
->scr_height
;
404 if (!array
|| !WMGetArrayItemCount(array
)) {
405 wWindowMove(wwin
, wwin
->frame_x
+ dx
, wwin
->frame_y
+ dy
);
407 WMArrayIterator iter
;
409 WM_ITERATE_ARRAY(array
, tmpw
, iter
) {
410 x
= tmpw
->frame_x
+ dx
;
411 y
= tmpw
->frame_y
+ dy
;
413 /* don't let windows become unreachable */
415 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
416 x
= 20 - (int)tmpw
->frame
->core
->width
;
417 else if (x
+ 20 > scr_width
)
420 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
421 y
= 20 - (int)tmpw
->frame
->core
->height
;
422 else if (y
+ 20 > scr_height
)
425 wWindowMove(tmpw
, x
, y
);
432 drawTransparentFrame(WWindow
*wwin
, int x
, int y
, int width
, int height
)
434 Window root
= wwin
->screen_ptr
->root_win
;
435 GC gc
= wwin
->screen_ptr
->frame_gc
;
439 if (!WFLAGP(wwin
, no_titlebar
) && !wwin
->flags
.shaded
) {
440 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + (wPreferences
.window_title_clearance
+ TITLEBAR_EXTEND_SPACE
) * 2;
442 if (!WFLAGP(wwin
, no_resizebar
) && !wwin
->flags
.shaded
) {
443 /* Can't use wwin-frame->bottom_width because, in some cases
444 (e.g. interactive placement), frame does not point to anything. */
445 bottom
= RESIZEBAR_HEIGHT
- 1;
447 XDrawRectangle(dpy
, root
, gc
, x
, y
, width
+ 1, height
+ 1);
450 XDrawLine(dpy
, root
, gc
, x
+ 1, y
+ h
, x
+ width
+ 1, y
+ h
);
453 XDrawLine(dpy
, root
, gc
, x
+ 1,
456 y
+ height
- bottom
);
462 drawFrames(WWindow
*wwin
, WMArray
*array
, int dx
, int dy
)
465 int scr_width
= wwin
->screen_ptr
->scr_width
;
466 int scr_height
= wwin
->screen_ptr
->scr_height
;
471 x
= wwin
->frame_x
+ dx
;
472 y
= wwin
->frame_y
+ dy
;
474 drawTransparentFrame(wwin
, x
, y
,
475 wwin
->frame
->core
->width
,
476 wwin
->frame
->core
->height
);
479 WMArrayIterator iter
;
481 WM_ITERATE_ARRAY(array
, tmpw
, iter
) {
482 x
= tmpw
->frame_x
+ dx
;
483 y
= tmpw
->frame_y
+ dy
;
485 /* don't let windows become unreachable */
487 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
488 x
= 20 - (int)tmpw
->frame
->core
->width
;
489 else if (x
+ 20 > scr_width
)
492 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
493 y
= 20 - (int)tmpw
->frame
->core
->height
;
494 else if (y
+ 20 > scr_height
)
497 drawTransparentFrame(tmpw
, x
, y
, tmpw
->frame
->core
->width
,
498 tmpw
->frame
->core
->height
);
511 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &ev
)) ;
516 crossWorkspace(WScreen
*scr
, WWindow
*wwin
, int opaque_move
,
517 int new_workspace
, int rewind
)
519 /* do not let window be unmapped */
521 wwin
->flags
.changing_workspace
= 1;
522 wWindowChangeWorkspace(wwin
, new_workspace
);
524 /* go to new workspace */
525 wWorkspaceChange(scr
, new_workspace
);
527 wwin
->flags
.changing_workspace
= 0;
530 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, scr
->scr_width
- 20, 0);
532 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, -(scr
->scr_width
- 20), 0);
537 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
538 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
539 GrabModeAsync
, None
, wCursor
[WCUR_MOVE
], CurrentTime
);
547 /* arrays of WWindows sorted by the respective border position */
548 WWindow
**topList
; /* top border */
549 WWindow
**leftList
; /* left border */
550 WWindow
**rightList
; /* right border */
551 WWindow
**bottomList
; /* bottom border */
554 /* index of window in the above lists indicating the relative position
555 * of the window with the others */
561 int rubCount
; /* for workspace switching */
563 int winWidth
, winHeight
; /* width/height of the window */
564 int realX
, realY
; /* actual position of the window */
565 int calcX
, calcY
; /* calculated position of window */
566 int omouseX
, omouseY
; /* old mouse position */
567 int mouseX
, mouseY
; /* last known position of the pointer */
570 #define WTOP(w) (w)->frame_y
571 #define WLEFT(w) (w)->frame_x
572 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width + FRAME_BORDER_WIDTH)
573 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height + FRAME_BORDER_WIDTH)
576 compareWTop(const void *a
, const void *b
)
578 WWindow
*wwin1
= *(WWindow
**)a
;
579 WWindow
*wwin2
= *(WWindow
**)b
;
581 if (WTOP(wwin1
) > WTOP(wwin2
))
583 else if (WTOP(wwin1
) < WTOP(wwin2
))
591 compareWLeft(const void *a
, const void *b
)
593 WWindow
*wwin1
= *(WWindow
**)a
;
594 WWindow
*wwin2
= *(WWindow
**)b
;
596 if (WLEFT(wwin1
) > WLEFT(wwin2
))
598 else if (WLEFT(wwin1
) < WLEFT(wwin2
))
606 compareWRight(const void *a
, const void *b
)
608 WWindow
*wwin1
= *(WWindow
**)a
;
609 WWindow
*wwin2
= *(WWindow
**)b
;
611 if (WRIGHT(wwin1
) < WRIGHT(wwin2
))
613 else if (WRIGHT(wwin1
) > WRIGHT(wwin2
))
622 compareWBottom(const void *a
, const void *b
)
624 WWindow
*wwin1
= *(WWindow
**)a
;
625 WWindow
*wwin2
= *(WWindow
**)b
;
627 if (WBOTTOM(wwin1
) < WBOTTOM(wwin2
))
629 else if (WBOTTOM(wwin1
) > WBOTTOM(wwin2
))
637 updateResistance(WWindow
*wwin
, MoveData
*data
, int newX
, int newY
)
640 int newX2
= newX
+ data
->winWidth
;
641 int newY2
= newY
+ data
->winHeight
;
644 if (newX
< data
->realX
) {
645 if (data
->rightIndex
> 0
646 && newX
< WRIGHT(data
->rightList
[data
->rightIndex
-1])) {
648 } else if (data
->leftIndex
<= data
->count
-1
649 && newX2
<= WLEFT(data
->leftList
[data
->leftIndex
])) {
652 } else if (newX
> data
->realX
) {
653 if (data
->leftIndex
> 0
654 && newX2
> WLEFT(data
->leftList
[data
->leftIndex
-1])) {
656 } else if (data
->rightIndex
<= data
->count
-1
657 && newX
>= WRIGHT(data
->rightList
[data
->rightIndex
])) {
663 if (newY
< data
->realY
) {
664 if (data
->bottomIndex
> 0
665 && newY
< WBOTTOM(data
->bottomList
[data
->bottomIndex
-1])) {
667 } else if (data
->topIndex
<= data
->count
-1
668 && newY2
<= WTOP(data
->topList
[data
->topIndex
])) {
671 } else if (newY
> data
->realY
) {
672 if (data
->topIndex
> 0
673 && newY2
> WTOP(data
->topList
[data
->topIndex
-1])) {
675 } else if (data
->bottomIndex
<= data
->count
-1
676 && newY
>= WBOTTOM(data
->bottomList
[data
->bottomIndex
])) {
685 /* TODO: optimize this */
686 if (data
->realY
< WBOTTOM(data
->bottomList
[0])) {
687 data
->bottomIndex
= 0;
689 if (data
->realX
< WRIGHT(data
->rightList
[0])) {
690 data
->rightIndex
= 0;
692 if ((data
->realX
+ data
->winWidth
) > WLEFT(data
->leftList
[0])) {
695 if ((data
->realY
+ data
->winHeight
) > WTOP(data
->topList
[0])) {
698 for (i
= 0; i
< data
->count
; i
++) {
699 if (data
->realY
> WBOTTOM(data
->bottomList
[i
])) {
700 data
->bottomIndex
= i
+ 1;
702 if (data
->realX
> WRIGHT(data
->rightList
[i
])) {
703 data
->rightIndex
= i
+ 1;
705 if ((data
->realX
+ data
->winWidth
) < WLEFT(data
->leftList
[i
])) {
706 data
->leftIndex
= i
+ 1;
708 if ((data
->realY
+ data
->winHeight
) < WTOP(data
->topList
[i
])) {
709 data
->topIndex
= i
+ 1;
716 freeMoveData(MoveData
*data
)
719 wfree(data
->topList
);
721 wfree(data
->leftList
);
723 wfree(data
->rightList
);
724 if (data
->bottomList
)
725 wfree(data
->bottomList
);
730 updateMoveData(WWindow
*wwin
, MoveData
*data
)
732 WScreen
*scr
= wwin
->screen_ptr
;
737 tmp
= scr
->focused_window
;
739 if (tmp
!= wwin
&& scr
->current_workspace
== tmp
->frame
->workspace
740 && !tmp
->flags
.miniaturized
741 && !tmp
->flags
.hidden
742 && !tmp
->flags
.obscured
743 && !WFLAGP(tmp
, sunken
)) {
744 data
->topList
[data
->count
] = tmp
;
745 data
->leftList
[data
->count
] = tmp
;
746 data
->rightList
[data
->count
] = tmp
;
747 data
->bottomList
[data
->count
] = tmp
;
753 if (data
->count
== 0) {
756 data
->rightIndex
= 0;
757 data
->bottomIndex
= 0;
762 * order from closest to the border of the screen to farthest
764 qsort(data
->topList
, data
->count
, sizeof(WWindow
**), compareWTop
);
765 qsort(data
->leftList
, data
->count
, sizeof(WWindow
**), compareWLeft
);
766 qsort(data
->rightList
, data
->count
, sizeof(WWindow
**), compareWRight
);
767 qsort(data
->bottomList
, data
->count
, sizeof(WWindow
**), compareWBottom
);
769 /* figure the position of the window relative to the others */
772 data
->leftIndex
= -1;
773 data
->rightIndex
= -1;
774 data
->bottomIndex
= -1;
776 if (WTOP(wwin
) < WBOTTOM(data
->bottomList
[0])) {
777 data
->bottomIndex
= 0;
779 if (WLEFT(wwin
) < WRIGHT(data
->rightList
[0])) {
780 data
->rightIndex
= 0;
782 if (WRIGHT(wwin
) > WLEFT(data
->leftList
[0])) {
785 if (WBOTTOM(wwin
) > WTOP(data
->topList
[0])) {
788 for (i
= 0; i
< data
->count
; i
++) {
789 if (WTOP(wwin
) >= WBOTTOM(data
->bottomList
[i
])) {
790 data
->bottomIndex
= i
+ 1;
792 if (WLEFT(wwin
) >= WRIGHT(data
->rightList
[i
])) {
793 data
->rightIndex
= i
+ 1;
795 if (WRIGHT(wwin
) <= WLEFT(data
->leftList
[i
])) {
796 data
->leftIndex
= i
+ 1;
798 if (WBOTTOM(wwin
) <= WTOP(data
->topList
[i
])) {
799 data
->topIndex
= i
+ 1;
806 initMoveData(WWindow
*wwin
, MoveData
*data
)
811 memset(data
, 0, sizeof(MoveData
));
813 for (i
= 0, tmp
= wwin
->screen_ptr
->focused_window
;
815 tmp
= tmp
->prev
, i
++);
818 data
->topList
= wmalloc(sizeof(WWindow
*) * i
);
819 data
->leftList
= wmalloc(sizeof(WWindow
*) * i
);
820 data
->rightList
= wmalloc(sizeof(WWindow
*) * i
);
821 data
->bottomList
= wmalloc(sizeof(WWindow
*) * i
);
823 updateMoveData(wwin
, data
);
826 data
->realX
= wwin
->frame_x
;
827 data
->realY
= wwin
->frame_y
;
828 data
->calcX
= wwin
->frame_x
;
829 data
->calcY
= wwin
->frame_y
;
831 data
->winWidth
= wwin
->frame
->core
->width
+ 2;
832 data
->winHeight
= wwin
->frame
->core
->height
+ 2;
837 checkWorkspaceChange(WWindow
*wwin
, MoveData
*data
, Bool opaqueMove
)
839 WScreen
*scr
= wwin
->screen_ptr
;
840 Bool changed
= False
;
842 if (data
->mouseX
<= 1) {
843 if (scr
->current_workspace
> 0) {
845 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
- 1,
850 } else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
) {
852 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->workspace_count
- 1,
857 } else if (data
->mouseX
>= scr
->scr_width
- 2) {
859 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
861 if (wPreferences
.ws_cycle
862 || scr
->workspace_count
== MAX_WORKSPACES
) {
864 crossWorkspace(scr
, wwin
, opaqueMove
, 0, False
);
868 /* if user insists on trying to go to next workspace even when
869 * it's already the last, create a new one */
870 else if (data
->omouseX
== data
->mouseX
871 && wPreferences
.ws_advance
) {
873 /* detect user "rubbing" the window against the edge */
874 if (data
->rubCount
> 0
875 && data
->omouseY
- data
->mouseY
> MOVE_THRESHOLD
) {
877 data
->rubCount
= -(data
->rubCount
+ 1);
879 } else if (data
->rubCount
<= 0
880 && data
->mouseY
- data
->omouseY
> MOVE_THRESHOLD
) {
882 data
->rubCount
= -data
->rubCount
+ 1;
885 /* create a new workspace */
886 if (abs(data
->rubCount
) > 2) {
887 /* go to next workspace */
890 crossWorkspace(scr
, wwin
, opaqueMove
,
891 scr
->current_workspace
+1, False
);
895 } else if (scr
->current_workspace
< scr
->workspace_count
) {
897 /* go to next workspace */
898 crossWorkspace(scr
, wwin
, opaqueMove
,
899 scr
->current_workspace
+1, False
);
912 updateWindowPosition(WWindow
*wwin
, MoveData
*data
, Bool doResistance
,
913 Bool opaqueMove
, int newMouseX
, int newMouseY
)
915 WScreen
*scr
= wwin
->screen_ptr
;
916 int dx
, dy
; /* how much mouse moved */
917 int winL
, winR
, winT
, winB
; /* requested new window position */
918 int newX
, newY
; /* actual new window position */
919 Bool hresist
, vresist
;
928 /* check the direction of the movement */
929 dx
= newMouseX
- data
->mouseX
;
930 dy
= newMouseY
- data
->mouseY
;
932 data
->omouseX
= data
->mouseX
;
933 data
->omouseY
= data
->mouseY
;
934 data
->mouseX
= newMouseX
;
935 data
->mouseY
= newMouseY
;
937 winL
= data
->calcX
+ dx
;
938 winR
= data
->calcX
+ data
->winWidth
+ dx
;
939 winT
= data
->calcY
+ dy
;
940 winB
= data
->calcY
+ data
->winHeight
+ dy
;
952 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
953 attract
= wPreferences
.attract
;
954 /* horizontal movement: check horizontal edge resistances */
957 /* window is the leftmost window: check against screen edge */
958 l_edge
= scr
->totalUsableArea
.x1
;
959 r_edge
= scr
->totalUsableArea
.x2
+ resist
;
960 edge_l
= scr
->totalUsableArea
.x1
- resist
;
961 edge_r
= scr
->totalUsableArea
.x2
;
964 if ((data
->rightIndex
>= 0) && (data
->rightIndex
<= data
->count
)) {
967 for (i
= data
->rightIndex
- 1; i
>= 0; i
--) {
968 looprw
= data
->rightList
[i
];
969 if (!(data
->realY
> WBOTTOM(looprw
)
970 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
972 || ((data
->realX
< (WRIGHT(looprw
) + 2)) && dx
< 0)) {
973 l_edge
= WRIGHT(looprw
) + 1;
974 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
981 for (i
= data
->rightIndex
; i
< data
->count
; i
++) {
982 looprw
= data
->rightList
[i
];
983 if(!(data
->realY
> WBOTTOM(looprw
)
984 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
985 r_edge
= WRIGHT(looprw
) + 1;
986 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
993 if ((data
->leftIndex
>= 0) && (data
->leftIndex
<= data
->count
)) {
996 for (i
= data
->leftIndex
- 1; i
>= 0; i
--) {
997 looprw
= data
->leftList
[i
];
998 if (!(data
->realY
> WBOTTOM(looprw
)
999 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1001 || (((data
->realX
+ data
->winWidth
) > (WLEFT(looprw
) - 1)) && dx
> 0)) {
1002 edge_r
= WLEFT(looprw
);
1003 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1010 for (i
= data
->leftIndex
; i
< data
->count
; i
++) {
1011 looprw
= data
->leftList
[i
];
1012 if(!(data
->realY
> WBOTTOM(looprw
)
1013 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1014 edge_l
= WLEFT(looprw
);
1015 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1022 printf("%d %d\n",winL,winR);
1023 printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);
1026 if ((winL
- l_edge
) < (r_edge
- winL
)) {
1028 if ((attract
&& winL
<= l_edge
+ resist
&& winL
>= l_edge
- resist
)
1029 || (dx
< 0 && winL
<= l_edge
&& winL
>= l_edge
- resist
)) {
1035 if (resist
> 0 && attract
&& winL
>= r_edge
- resist
&& winL
<= r_edge
+ resist
) {
1041 if ((winR
- edge_l
) < (edge_r
- winR
)) {
1042 if (resist
> 0 && attract
&& winR
<= edge_l
+ resist
&& winR
>= edge_l
- resist
) {
1043 newX
= edge_l
- data
->winWidth
;
1048 if ((attract
&& winR
>= edge_r
- resist
&& winR
<= edge_r
+ resist
)
1049 || (dx
> 0 && winR
>= edge_r
&& winR
<= edge_r
+ resist
)) {
1050 newX
= edge_r
- data
->winWidth
;
1057 t_edge
= scr
->totalUsableArea
.y1
;
1058 b_edge
= scr
->totalUsableArea
.y2
+ resist
;
1059 edge_t
= scr
->totalUsableArea
.y1
- resist
;
1060 edge_b
= scr
->totalUsableArea
.y2
;
1062 if ((data
->bottomIndex
>= 0) && (data
->bottomIndex
<= data
->count
)) {
1065 for (i
= data
->bottomIndex
- 1; i
>= 0; i
--) {
1066 looprw
= data
->bottomList
[i
];
1067 if (!(data
->realX
> WRIGHT(looprw
)
1068 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1070 || ((data
->realY
< (WBOTTOM(looprw
) + 2)) && dy
< 0)) {
1071 t_edge
= WBOTTOM(looprw
) + 1;
1072 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1079 for (i
= data
->bottomIndex
; i
< data
->count
; i
++) {
1080 looprw
= data
->bottomList
[i
];
1081 if(!(data
->realX
> WRIGHT(looprw
)
1082 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1083 b_edge
= WBOTTOM(looprw
) + 1;
1084 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1091 if ((data
->topIndex
>= 0) && (data
->topIndex
<= data
->count
)) {
1094 for (i
= data
->topIndex
- 1; i
>= 0; i
--) {
1095 looprw
= data
->topList
[i
];
1096 if (!(data
->realX
> WRIGHT(looprw
)
1097 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1099 || (((data
->realY
+ data
->winHeight
) > (WTOP(looprw
) - 1)) && dy
> 0)) {
1100 edge_b
= WTOP(looprw
);
1101 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1108 for (i
= data
->topIndex
; i
< data
->count
; i
++) {
1109 looprw
= data
->topList
[i
];
1110 if(!(data
->realX
> WRIGHT(looprw
)
1111 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1112 edge_t
= WTOP(looprw
);
1113 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1119 if ((winT
- t_edge
) < (b_edge
- winT
)) {
1121 if ((attract
&& winT
<= t_edge
+ resist
&& winT
>= t_edge
- resist
)
1122 || (dy
< 0 && winT
<= t_edge
&& winT
>= t_edge
- resist
)) {
1129 if (resist
> 0 && attract
&& winT
>= b_edge
- resist
&& winT
<= b_edge
+ resist
) {
1135 if ((winB
- edge_t
) < (edge_b
- winB
)) {
1136 if (resist
> 0 && attract
&& winB
<= edge_t
+ resist
&& winB
>= edge_t
- resist
) {
1137 newY
= edge_t
- data
->winHeight
;
1143 if ((attract
&& winB
>= edge_b
- resist
&& winB
<= edge_b
+ resist
)
1144 || (dy
> 0 && winB
>= edge_b
&& winB
<= edge_b
+ resist
)) {
1145 newY
= edge_b
- data
->winHeight
;
1155 /* update window position */
1159 if (((dx
> 0 && data
->calcX
- data
->realX
> 0)
1160 || (dx
< 0 && data
->calcX
- data
->realX
< 0)) && !hresist
)
1163 if (((dy
> 0 && data
->calcY
- data
->realY
> 0)
1164 || (dy
< 0 && data
->calcY
- data
->realY
< 0)) && !vresist
)
1167 if (data
->realX
!= newX
|| data
->realY
!= newY
) {
1169 if (wPreferences
.move_display
== WDIS_NEW
1170 && !scr
->selected_windows
) {
1171 showPosition(wwin
, data
->realX
, data
->realY
);
1174 doWindowMove(wwin
, scr
->selected_windows
,
1175 newX
- wwin
->frame_x
,
1176 newY
- wwin
->frame_y
);
1179 drawFrames(wwin
, scr
->selected_windows
,
1180 data
->realX
- wwin
->frame_x
,
1181 data
->realY
- wwin
->frame_y
);
1184 if (!scr
->selected_windows
1185 && wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
1187 moveGeometryDisplayCentered(scr
, newX
+ data
->winWidth
/2,
1188 newY
+ data
->winHeight
/2);
1193 drawFrames(wwin
, scr
->selected_windows
,
1194 newX
- wwin
->frame_x
,
1195 newY
- wwin
->frame_y
);
1198 if (!scr
->selected_windows
) {
1199 showPosition(wwin
, newX
, newY
);
1204 /* recalc relative window position */
1205 if (doResistance
&& (data
->realX
!= newX
|| data
->realY
!= newY
)) {
1206 updateResistance(wwin
, data
, newX
, newY
);
1214 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1217 wKeyboardMoveResizeWindow(WWindow
*wwin
)
1219 WScreen
*scr
= wwin
->screen_ptr
;
1220 Window root
= scr
->root_win
;
1222 int w
= wwin
->frame
->core
->width
;
1223 int h
= wwin
->frame
->core
->height
;
1224 int scr_width
= wwin
->screen_ptr
->scr_width
;
1225 int scr_height
= wwin
->screen_ptr
->scr_height
;
1226 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1227 int src_x
= wwin
->frame_x
;
1228 int src_y
= wwin
->frame_y
;
1229 int done
,off_x
,off_y
,ww
,wh
;
1232 KeySym keysym
=NoSymbol
;
1234 KeyCode shiftl
,shiftr
,ctrll
,ctrlmode
;
1236 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1237 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1238 ctrll
= XKeysymToKeycode(dpy
, XK_Control_L
);
1239 ctrlmode
=done
=off_x
=off_y
=0;
1243 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1245 if (!wwin
->flags
.selected
) {
1246 wUnselectWindows(scr
);
1249 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1250 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
1251 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
);
1253 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1254 if(scr
->selected_windows
)
1255 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1256 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1257 if(!scr
->selected_windows
)
1258 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1260 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1270 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1271 | ButtonPressMask
| ExposureMask
, &event
);
1272 if (event
.type
== Expose
) {
1273 WMHandleEvent(&event
);
1275 } while (event
.type
== Expose
);
1278 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1279 if(scr
->selected_windows
)
1280 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1281 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1282 /*** I HATE EDGE RESISTANCE - ]d ***/
1285 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1289 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1294 switch (event
.type
) {
1297 if (event
.xkey
.time
- lastTime
> 50) {
1298 kspeed
/=(1 + (event
.xkey
.time
- lastTime
)/100);
1304 if (kspeed
< _KS
) kspeed
= _KS
;
1305 lastTime
= event
.xkey
.time
;
1307 if (event
.xkey
.state
& ControlMask
&& !wwin
->flags
.shaded
) {
1309 wUnselectWindows(scr
);
1314 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
) {
1316 cycleGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
, 0);
1318 cyclePositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1322 keysym
= XLookupKeysym(&event
.xkey
, 0);
1377 if (moment
!= RIGHT
)
1388 wWindowConstrainSize(wwin
, &ww
, &wh
);
1391 if (wPreferences
.ws_cycle
){
1392 if (src_x
+ off_x
+ ww
< 20){
1393 if(!scr
->current_workspace
) {
1394 wWorkspaceChange(scr
, scr
->workspace_count
-1);
1396 else wWorkspaceChange(scr
, scr
->current_workspace
-1);
1399 else if (src_x
+ off_x
+ 20 > scr_width
){
1400 if(scr
->current_workspace
== scr
->workspace_count
-1) {
1401 wWorkspaceChange(scr
, 0);
1403 else wWorkspaceChange(scr
, scr
->current_workspace
+1);
1408 if (src_x
+ off_x
+ ww
< 20)
1409 off_x
= 20 - ww
- src_x
;
1410 else if (src_x
+ off_x
+ 20 > scr_width
)
1411 off_x
= scr_width
- 20 - src_x
;
1414 if (src_y
+ off_y
+ wh
< 20) {
1415 off_y
= 20 - wh
- src_y
;
1417 else if (src_y
+ off_y
+ 20 > scr_height
) {
1418 off_y
= scr_height
- 20 - src_y
;
1427 WMHandleEvent(&event
);
1428 while (XCheckTypedEvent(dpy
, Expose
, &event
)) {
1429 WMHandleEvent(&event
);
1434 WMHandleEvent(&event
);
1441 if (wwin
->flags
.shaded
&& !scr
->selected_windows
){
1442 moveGeometryDisplayCentered(scr
, src_x
+off_x
+ w
/2, src_y
+off_y
+ h
/2);
1445 WMUnmapWidget(scr
->gview
);
1446 mapGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1447 } else if(!scr
->selected_windows
) {
1448 WMUnmapWidget(scr
->gview
);
1449 mapPositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1453 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1454 if (scr
->selected_windows
)
1455 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1457 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1459 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1464 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1465 } else if(!scr
->selected_windows
)
1466 showPosition(wwin
, src_x
+off_x
, src_y
+off_y
);
1470 scr
->keymove_tick
=0;
1472 WMDeleteTimerWithClientData(&looper);
1474 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1475 if(scr
->selected_windows
)
1476 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1477 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1480 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1484 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1485 WMUnmapWidget(scr
->gview
);
1487 WMUnmapWidget(scr
->gview
);
1489 XUngrabKeyboard(dpy
, CurrentTime
);
1490 XUngrabPointer(dpy
, CurrentTime
);
1494 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1495 if (!scr
->selected_windows
) {
1496 wWindowMove(wwin
, src_x
+off_x
, src_y
+off_y
);
1497 wWindowSynthConfigureNotify(wwin
);
1499 WMArrayIterator iter
;
1502 doWindowMove(wwin
, scr
->selected_windows
, off_x
, off_y
);
1504 WM_ITERATE_ARRAY(scr
->selected_windows
, foo
, iter
) {
1505 wWindowSynthConfigureNotify(foo
);
1509 if (wwin
->client
.width
!= ww
)
1510 wwin
->flags
.user_changed_width
= 1;
1512 if (wwin
->client
.height
!= wh
- vert_border
)
1513 wwin
->flags
.user_changed_height
= 1;
1515 wWindowConfigure(wwin
, src_x
+off_x
, src_y
+off_y
,
1516 ww
, wh
- vert_border
);
1517 wWindowSynthConfigureNotify(wwin
);
1519 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1520 wSetFocusTo(scr
, wwin
);
1529 *----------------------------------------------------------------------
1530 * wMouseMoveWindow--
1531 * Move the named window and the other selected ones (if any),
1532 * interactively. Also shows the position of the window, if only one
1533 * window is being moved.
1534 * If the window is not on the selected window list, the selected
1535 * windows are deselected.
1536 * If shift is pressed during the operation, the position display
1537 * is changed to another type.
1540 * True if the window was moved, False otherwise.
1543 * The window(s) position is changed, and the client(s) are
1544 * notified about that.
1545 * The position display configuration may be changed.
1546 *----------------------------------------------------------------------
1549 wMouseMoveWindow(WWindow
*wwin
, XEvent
*ev
)
1551 WScreen
*scr
= wwin
->screen_ptr
;
1553 Window root
= scr
->root_win
;
1554 KeyCode shiftl
, shiftr
;
1558 /* This needs not to change while moving, else bad things can happen */
1559 int opaqueMove
= wPreferences
.opaque_move
;
1561 #ifdef GHOST_WINDOW_MOVE
1564 rimg
= InitGhostWindowMove(scr
);
1568 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1569 XSetWindowAttributes attr
;
1571 attr
.save_under
= True
;
1572 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
,
1573 CWSaveUnder
, &attr
);
1577 initMoveData(wwin
, &moveData
);
1579 moveData
.mouseX
= ev
->xmotion
.x_root
;
1580 moveData
.mouseY
= ev
->xmotion
.y_root
;
1582 if (!wwin
->flags
.selected
) {
1583 /* this window is not selected, unselect others and move only wwin */
1584 wUnselectWindows(scr
);
1587 puts("Moving window");
1589 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1590 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1596 /* XWarpPointer() doesn't seem to generate Motion events, so
1597 we've got to simulate them */
1598 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1599 &event
.xmotion
.y_root
, &junk
, &junk
,
1600 (unsigned *) &junk
);
1602 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1603 | PointerMotionHintMask
1604 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
,
1607 if (event
.type
== MotionNotify
) {
1608 /* compress MotionNotify events */
1609 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1610 if (!checkMouseSamplingRate(&event
))
1614 switch (event
.type
) {
1616 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1617 && started
&& !scr
->selected_windows
) {
1620 drawFrames(wwin
, scr
->selected_windows
,
1621 moveData
.realX
- wwin
->frame_x
,
1622 moveData
.realY
- wwin
->frame_y
);
1625 if (wPreferences
.move_display
== WDIS_NEW
1626 && !scr
->selected_windows
) {
1627 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1630 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1631 moveData
.winWidth
, moveData
.winHeight
);
1633 if (wPreferences
.move_display
== WDIS_NEW
1634 && !scr
->selected_windows
) {
1636 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1640 drawFrames(wwin
, scr
->selected_windows
,
1641 moveData
.realX
- wwin
->frame_x
,
1642 moveData
.realY
- wwin
->frame_y
);
1645 WMHandleEvent(&event
);
1651 updateWindowPosition(wwin
, &moveData
,
1652 scr
->selected_windows
== NULL
1653 && wPreferences
.edge_resistance
> 0,
1655 event
.xmotion
.x_root
,
1656 event
.xmotion
.y_root
);
1658 if (!warped
&& !wPreferences
.no_autowrap
) {
1659 int oldWorkspace
= scr
->current_workspace
;
1661 if (wPreferences
.move_display
== WDIS_NEW
1662 && !scr
->selected_windows
) {
1663 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1667 drawFrames(wwin
, scr
->selected_windows
,
1668 moveData
.realX
- wwin
->frame_x
,
1669 moveData
.realY
- wwin
->frame_y
);
1671 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1672 if (scr
->current_workspace
!= oldWorkspace
1673 && wPreferences
.edge_resistance
> 0
1674 && scr
->selected_windows
== NULL
)
1675 updateMoveData(wwin
, &moveData
);
1679 drawFrames(wwin
, scr
->selected_windows
,
1680 moveData
.realX
- wwin
->frame_x
,
1681 moveData
.realY
- wwin
->frame_y
);
1683 if (wPreferences
.move_display
== WDIS_NEW
1684 && !scr
->selected_windows
) {
1686 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1692 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1693 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1695 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1696 | ButtonReleaseMask
| ButtonPressMask
,
1697 wCursor
[WCUR_MOVE
], CurrentTime
);
1699 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1702 if (!scr
->selected_windows
)
1703 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1704 moveData
.winWidth
, moveData
.winHeight
);
1706 if (started
&& !opaqueMove
)
1707 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1709 if (!opaqueMove
|| (wPreferences
.move_display
==WDIS_NEW
1710 && !scr
->selected_windows
)) {
1712 if (wPreferences
.move_display
==WDIS_NEW
)
1713 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1722 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1728 drawFrames(wwin
, scr
->selected_windows
,
1729 moveData
.realX
- wwin
->frame_x
,
1730 moveData
.realY
- wwin
->frame_y
);
1732 doWindowMove(wwin
, scr
->selected_windows
,
1733 moveData
.realX
- wwin
->frame_x
,
1734 moveData
.realY
- wwin
->frame_y
);
1736 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1737 wWindowSynthConfigureNotify(wwin
);
1739 XUngrabKeyboard(dpy
, CurrentTime
);
1742 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1743 wSetFocusTo(scr
, wwin
);
1745 if (wPreferences
.move_display
== WDIS_NEW
)
1746 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1748 /* discard all enter/leave events that happened until
1749 * the time the button was released */
1750 while (XCheckTypedEvent(dpy
, EnterNotify
, &e
)) {
1751 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1752 XPutBackEvent(dpy
, &e
);
1756 while (XCheckTypedEvent(dpy
, LeaveNotify
, &e
)) {
1757 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1758 XPutBackEvent(dpy
, &e
);
1763 if (!scr
->selected_windows
) {
1764 /* get rid of the geometry window */
1765 WMUnmapWidget(scr
->gview
);
1769 puts("End move window");
1775 if (started
&& !opaqueMove
) {
1776 drawFrames(wwin
, scr
->selected_windows
,
1777 moveData
.realX
- wwin
->frame_x
,
1778 moveData
.realY
- wwin
->frame_y
);
1780 WMHandleEvent(&event
);
1783 drawFrames(wwin
, scr
->selected_windows
,
1784 moveData
.realX
- wwin
->frame_x
,
1785 moveData
.realY
- wwin
->frame_y
);
1787 WMHandleEvent(&event
);
1793 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1794 XSetWindowAttributes attr
;
1797 attr
.save_under
= False
;
1798 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
,
1799 CWSaveUnder
, &attr
);
1803 freeMoveData(&moveData
);
1810 #define HCONSTRAIN 2
1813 getResizeDirection(WWindow
*wwin
, int x
, int y
, int dx
, int dy
,
1816 int w
= wwin
->frame
->core
->width
- 1;
1817 int cw
= wwin
->frame
->resizebar_corner_width
;
1820 /* if not resizing through the resizebar */
1821 if (!(flags
& RESIZEBAR
)) {
1822 int xdir
= (abs(x
) < (wwin
->client
.width
/2)) ? LEFT
: RIGHT
;
1823 int ydir
= (abs(y
) < (wwin
->client
.height
/2)) ? UP
: DOWN
;
1824 if (abs(dx
) < 2 || abs(dy
) < 2) {
1825 if (abs(dy
) > abs(dx
))
1830 return (xdir
| ydir
);
1833 /* window is too narrow. allow diagonal resize */
1837 if (flags
& HCONSTRAIN
)
1842 return (LEFT
| ydir
);
1844 return (RIGHT
| ydir
);
1846 /* vertical resize */
1847 if ((x
> cw
) && (x
< w
- cw
))
1855 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1863 wMouseResizeWindow(WWindow
*wwin
, XEvent
*ev
)
1866 WScreen
*scr
= wwin
->screen_ptr
;
1867 Window root
= scr
->root_win
;
1868 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1869 int fw
= wwin
->frame
->core
->width
;
1870 int fh
= wwin
->frame
->core
->height
;
1871 int fx
= wwin
->frame_x
;
1872 int fy
= wwin
->frame_y
;
1873 int is_resizebar
= (wwin
->frame
->resizebar
1874 && ev
->xany
.window
==wwin
->frame
->resizebar
->window
);
1878 int rw
= fw
, rh
= fh
;
1879 int rx1
, ry1
, rx2
, ry2
;
1881 KeyCode shiftl
, shiftr
;
1888 if (wwin
->flags
.shaded
) {
1889 wwarning("internal error: tryein");
1892 orig_x
= ev
->xbutton
.x_root
;
1893 orig_y
= ev
->xbutton
.y_root
;
1897 puts("Resizing window");
1900 wUnselectWindows(scr
);
1905 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1906 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1907 if (!WFLAGP(wwin
, no_titlebar
))
1908 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + (wPreferences
.window_title_clearance
+ TITLEBAR_EXTEND_SPACE
) * 2;
1912 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1913 | ButtonReleaseMask
| PointerMotionHintMask
1914 | ButtonPressMask
| ExposureMask
, &event
);
1915 if (!checkMouseSamplingRate(&event
))
1918 switch (event
.type
) {
1920 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1921 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1923 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1924 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
1925 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1927 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1932 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1943 dw
= orig_x
- event
.xmotion
.x_root
;
1944 else if (res
& RIGHT
)
1945 dw
= event
.xmotion
.x_root
- orig_x
;
1947 dh
= orig_y
- event
.xmotion
.y_root
;
1948 else if (res
& DOWN
)
1949 dh
= event
.xmotion
.y_root
- orig_y
;
1951 orig_x
= event
.xmotion
.x_root
;
1952 orig_y
= event
.xmotion
.y_root
;
1957 fh
= rh
- vert_border
;
1958 wWindowConstrainSize(wwin
, &fw
, &fh
);
1962 else if (res
& RIGHT
)
1966 else if (res
& DOWN
)
1968 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1969 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1974 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
1975 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
1977 /* check if resizing through resizebar */
1983 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
1984 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
1985 flags
|= HCONSTRAIN
;
1987 res
= getResizeDirection(wwin
, tx
, ty
,
1988 orig_x
- event
.xmotion
.x_root
,
1989 orig_y
- event
.xmotion
.y_root
, flags
);
1991 if (res
== (UP
|LEFT
))
1992 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1993 | ButtonReleaseMask
| ButtonPressMask
,
1994 wCursor
[WCUR_TOPLEFTRESIZE
], CurrentTime
);
1995 else if (res
== (UP
|RIGHT
))
1996 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1997 | ButtonReleaseMask
| ButtonPressMask
,
1998 wCursor
[WCUR_TOPRIGHTRESIZE
], CurrentTime
);
1999 else if (res
== (DOWN
|LEFT
))
2000 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2001 | ButtonReleaseMask
| ButtonPressMask
,
2002 wCursor
[WCUR_BOTTOMLEFTRESIZE
], CurrentTime
);
2003 else if (res
== (DOWN
|RIGHT
))
2004 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2005 | ButtonReleaseMask
| ButtonPressMask
,
2006 wCursor
[WCUR_BOTTOMRIGHTRESIZE
], CurrentTime
);
2007 else if (res
== DOWN
|| res
== UP
)
2008 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2009 | ButtonReleaseMask
| ButtonPressMask
,
2010 wCursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2011 else if (res
& (DOWN
|UP
))
2012 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2013 | ButtonReleaseMask
| ButtonPressMask
,
2014 wCursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2015 else if (res
& (LEFT
|RIGHT
))
2016 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2017 | ButtonReleaseMask
| ButtonPressMask
,
2018 wCursor
[WCUR_HORIZONRESIZE
], CurrentTime
);
2020 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
2025 /* Draw the resize frame for the first time. */
2026 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
2028 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2030 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2035 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
2036 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
2038 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
2039 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2041 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
2043 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2045 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
2046 if (wPreferences
.size_display
== WDIS_NEW
) {
2047 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
2048 orig_fy
+ orig_fh
, res
);
2050 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2059 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2063 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2065 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2067 XUngrabKeyboard(dpy
, CurrentTime
);
2068 WMUnmapWidget(scr
->gview
);
2071 if (wwin
->client
.width
!= fw
)
2072 wwin
->flags
.user_changed_width
= 1;
2074 if (wwin
->client
.height
!= fh
- vert_border
)
2075 wwin
->flags
.user_changed_height
= 1;
2077 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
2080 puts("End resize window");
2085 WMHandleEvent(&event
);
2100 wUnselectWindows(WScreen
*scr
)
2104 if (!scr
->selected_windows
)
2107 while (WMGetArrayItemCount(scr
->selected_windows
)) {
2108 wwin
= WMGetFromArray(scr
->selected_windows
, 0);
2109 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
2110 wIconSelect(wwin
->icon
);
2112 wSelectWindow(wwin
, False
);
2114 WMFreeArray(scr
->selected_windows
);
2115 scr
->selected_windows
= NULL
;
2120 selectWindowsInside(WScreen
*scr
, int x1
, int y1
, int x2
, int y2
)
2124 /* select the windows and put them in the selected window list */
2125 tmpw
= scr
->focused_window
;
2126 while (tmpw
!= NULL
) {
2127 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
2128 if ((tmpw
->frame
->workspace
== scr
->current_workspace
2129 || IS_OMNIPRESENT(tmpw
))
2130 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
2131 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
2132 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
2133 wSelectWindow(tmpw
, True
);
2142 wSelectWindows(WScreen
*scr
, XEvent
*ev
)
2145 Window root
= scr
->root_win
;
2146 GC gc
= scr
->frame_gc
;
2147 int xp
= ev
->xbutton
.x_root
;
2148 int yp
= ev
->xbutton
.y_root
;
2153 puts("Selecting windows");
2155 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
2156 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
2157 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
],
2158 CurrentTime
) != Success
) {
2163 wUnselectWindows(scr
);
2165 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
2167 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
2168 | ButtonPressMask
, &event
);
2170 switch (event
.type
) {
2172 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2173 x
= event
.xmotion
.x_root
;
2180 y
= event
.xmotion
.y_root
;
2187 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2194 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2197 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2199 XUngrabPointer(dpy
, CurrentTime
);
2200 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
2203 wKWMSelectRootRegion(scr
, xp
, yp
, w
, h
,
2204 event
.xbutton
.state
& ControlMask
);
2205 #endif /* KWM_HINTS */
2208 puts("End window selection");
2213 WMHandleEvent(&event
);
2221 InteractivePlaceWindow(WWindow
*wwin
, int *x_ret
, int *y_ret
,
2222 unsigned width
, unsigned height
)
2224 WScreen
*scr
= wwin
->screen_ptr
;
2225 Window root
= scr
->root_win
;
2228 KeyCode shiftl
, shiftr
;
2232 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2233 GrabModeAsync
, GrabModeAsync
, None
,
2234 wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2239 if (!WFLAGP(wwin
, no_titlebar
)) {
2240 h
= WMFontHeight(scr
->title_font
) + (wPreferences
.window_title_clearance
+ TITLEBAR_EXTEND_SPACE
) * 2;
2243 if (!WFLAGP(wwin
, no_resizebar
)) {
2244 height
+= RESIZEBAR_HEIGHT
;
2246 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2247 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
,
2248 (unsigned *) &junk
);
2249 mapPositionDisplay(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2251 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2253 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2254 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2256 WMMaskEvent(dpy
, PointerMotionMask
|ButtonPressMask
|ExposureMask
|KeyPressMask
,
2259 if (!checkMouseSamplingRate(&event
))
2262 switch (event
.type
) {
2264 if ((event
.xkey
.keycode
== shiftl
)
2265 || (event
.xkey
.keycode
== shiftr
)) {
2266 drawTransparentFrame(wwin
,
2267 x
- width
/2, y
- h
/2, width
, height
);
2268 cyclePositionDisplay(wwin
,
2269 x
- width
/2, y
- h
/2, width
, height
);
2270 drawTransparentFrame(wwin
,
2271 x
- width
/2, y
- h
/2, width
, height
);
2276 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2278 x
= event
.xmotion
.x_root
;
2279 y
= event
.xmotion
.y_root
;
2281 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2282 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2284 showPosition(wwin
, x
- width
/2, y
- h
/2);
2286 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2291 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2293 *x_ret
= x
- width
/2;
2295 XUngrabPointer(dpy
, CurrentTime
);
2296 XUngrabKeyboard(dpy
, CurrentTime
);
2297 /* get rid of the geometry window */
2298 WMUnmapWidget(scr
->gview
);
2302 WMHandleEvent(&event
);