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"
49 /* How many different types of geometry/position
50 display thingies are there? */
51 #define NUM_DISPLAYS 4
55 #define HORIZONTAL (LEFT|RIGHT)
58 #define VERTICAL (UP|DOWN)
60 /****** Global Variables ******/
61 extern Time LastTimestamp
;
63 extern Cursor wCursor
[WCUR_LAST
];
65 extern WPreferences wPreferences
;
67 extern Atom _XA_WM_PROTOCOLS
;
72 wGetGeometryWindowSize(WScreen
*scr
, unsigned int *width
,
76 *width
= XmbTextEscapement(scr
->info_text_font
->font
, "-8888 x -8888", 13);
77 *height
= (7 * scr
->info_text_font
->height
) / 4 - 1;
79 *width
= XTextWidth(scr
->info_text_font
->font
, "-8888 x -8888", 13);
80 *height
= (7 * scr
->info_text_font
->font
->ascent
) / 4 - 1;
86 *----------------------------------------------------------------------
87 * moveGeometryDisplayCentered
89 * routine that moves the geometry/position window on scr so it is
90 * centered over the given coordinates (x,y). Also the window position
91 * is clamped so it stays on the screen at all times.
92 *----------------------------------------------------------------------
95 moveGeometryDisplayCentered(WScreen
*scr
, int x
, int y
)
97 x
-= scr
->geometry_display_width
/ 2;
98 y
-= scr
->geometry_display_height
/ 2;
102 else if (x
> (scr
->scr_width
- scr
->geometry_display_width
- 3))
103 x
= scr
->scr_width
- scr
->geometry_display_width
- 3;
107 else if (y
> (scr
->scr_height
- scr
->geometry_display_height
- 3))
108 y
= scr
->scr_height
- scr
->geometry_display_height
- 3;
110 XMoveWindow(dpy
, scr
->geometry_display
, x
, y
);
115 showPosition(WWindow
*wwin
, int x
, int y
)
117 WScreen
*scr
= wwin
->screen_ptr
;
118 GC gc
= scr
->info_text_gc
;
122 if (wPreferences
.move_display
== WDIS_NEW
) {
124 int width
= wwin
->frame
->core
->width
;
125 int height
= wwin
->frame
->core
->height
;
127 GC lgc
= scr
->line_gc
;
128 XSetForeground(dpy
, lgc
, scr
->line_pixel
);
129 sprintf(num
, "%i", x
);
131 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
-1, scr
->scr_width
, y
-1);
132 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
+height
+2, scr
->scr_width
,
134 XDrawLine(dpy
, scr
->root_win
, lgc
, x
-1, 0, x
-1, scr
->scr_height
);
135 XDrawLine(dpy
, scr
->root_win
, lgc
, x
+width
+2, 0, x
+width
+2,
139 XClearArea(dpy
, scr
->geometry_display
, 1, 1,
140 scr
->geometry_display_width
-2, scr
->geometry_display_height
-2,
142 sprintf(num
, "%+i %-+i", x
, y
);
143 fw
= wTextWidth(scr
->info_text_font
->font
, num
, strlen(num
));
145 XSetForeground(dpy
, gc
, scr
->black_pixel
);
147 fh
= scr
->info_text_font
->height
;
148 wDrawString(scr
->geometry_display
, scr
->info_text_font
, gc
,
149 (scr
->geometry_display_width
- 2 - fw
) / 2,
150 (scr
->geometry_display_height
-fh
)/2 + scr
->info_text_font
->y
,
152 wDrawBevel(scr
->geometry_display
, scr
->geometry_display_width
+1,
153 scr
->geometry_display_height
+1,
154 scr
->widget_texture
, WREL_RAISED
);
160 cyclePositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
162 WScreen
*scr
= wwin
->screen_ptr
;
164 wPreferences
.move_display
++;
165 wPreferences
.move_display
%= NUM_DISPLAYS
;
167 if (wPreferences
.move_display
== WDIS_NEW
) {
168 XUnmapWindow(dpy
, scr
->geometry_display
);
170 if (wPreferences
.move_display
== WDIS_CENTER
) {
171 moveGeometryDisplayCentered(scr
,
172 scr
->scr_width
/2, scr
->scr_height
/2);
173 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
174 moveGeometryDisplayCentered(scr
, 1, 1);
175 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
176 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
178 XMapRaised(dpy
, scr
->geometry_display
);
184 mapPositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
186 WScreen
*scr
= wwin
->screen_ptr
;
188 if (wPreferences
.move_display
== WDIS_NEW
) {
190 } else if (wPreferences
.move_display
== WDIS_CENTER
) {
191 moveGeometryDisplayCentered(scr
, scr
->scr_width
/ 2,
192 scr
->scr_height
/ 2);
193 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
194 moveGeometryDisplayCentered(scr
, 1, 1);
195 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
196 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
198 XMapRaised(dpy
, scr
->geometry_display
);
199 showPosition(wwin
, x
, y
);
202 #define unmapPositionDisplay(w) \
203 XUnmapWindow(dpy, (w)->screen_ptr->geometry_display);
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
= wTextWidth(scr
->info_text_font
->font
, "8888", 4);
220 fh
= scr
->info_text_font
->height
;
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
= wTextWidth(scr
->info_text_font
->font
, num
, strlen(num
));
275 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
277 /* Display the height. */
278 wDrawString(root
, scr
->info_text_font
, gc
,
279 x
- s
+ 3 - fw
/2, my
- fh
/2 + scr
->info_text_font
->y
+ 1,
281 XSetForeground(dpy
, gc
, scr
->line_pixel
);
282 /* horizontal geometry */
290 mx
= x1
+ (x2
- x1
)/2;
291 sprintf(num
, "%i", (x2
- x1
- wwin
->normal_hints
->base_width
) /
292 wwin
->normal_hints
->width_inc
);
293 fw
= wTextWidth(scr
->info_text_font
->font
, num
, strlen(num
));
297 segment
[0].x1
= x1
; segment
[0].y1
= y
- (s
+ 6);
298 segment
[0].x2
= x1
; segment
[0].y2
= y
- (s
- 10);
301 segment
[1].x1
= x1
+ 7; segment
[1].y1
= y
- (s
+ 1);
302 segment
[1].x2
= x1
+ 1; segment
[1].y2
= y
- (s
- 2);
304 segment
[2].x1
= x1
+ 1; segment
[2].y1
= y
- (s
- 2);
305 segment
[2].x2
= x1
+ 7; segment
[2].y2
= y
- (s
- 5);
308 segment
[3].x1
= x1
+ 1; segment
[3].y1
= y
- (s
- 2);
309 segment
[3].x2
= mx
- fw
/2 - 2; segment
[3].y2
= y
- (s
- 2);
311 XDrawSegments(dpy
, root
, gc
, segment
, 4);
315 segment
[0].x1
= x2
+ 1;
316 segment
[0].x2
= x2
+ 1;
319 segment
[1].x1
= x2
- 6;
323 segment
[2].x2
= x2
- 6;
326 segment
[3].x1
= mx
+ fw
/2 + 2;
329 XDrawSegments(dpy
, root
, gc
, segment
, 4);
331 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
333 /* Display the width. */
334 wDrawString(root
, scr
->info_text_font
, gc
,
335 mx
- fw
/2 + 1, y
- s
+ fh
/2 + 1, num
, strlen(num
));
337 XClearArea(dpy
, scr
->geometry_display
, 1, 1,
338 scr
->geometry_display_width
-2, scr
->geometry_display_height
-2,
340 sprintf(num
, "%i x %-i", (x2
- x1
- wwin
->normal_hints
->base_width
)
341 / wwin
->normal_hints
->width_inc
,
342 (by
- ty
- wwin
->normal_hints
->base_height
)
343 / wwin
->normal_hints
->height_inc
);
344 fw
= wTextWidth(scr
->info_text_font
->font
, num
, strlen(num
));
346 XSetForeground(dpy
, scr
->info_text_gc
, scr
->black_pixel
);
348 /* Display the height. */
349 wDrawString(scr
->geometry_display
, scr
->info_text_font
,
351 (scr
->geometry_display_width
-fw
)/2,
352 (scr
->geometry_display_height
-fh
)/2 +scr
->info_text_font
->y
,
354 wDrawBevel(scr
->geometry_display
, scr
->geometry_display_width
+1,
355 scr
->geometry_display_height
+1,
356 scr
->widget_texture
, WREL_RAISED
);
362 cycleGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
, int dir
)
364 WScreen
*scr
= wwin
->screen_ptr
;
366 wPreferences
.size_display
++;
367 wPreferences
.size_display
%= NUM_DISPLAYS
;
369 if (wPreferences
.size_display
== WDIS_NEW
) {
370 XUnmapWindow(dpy
, scr
->geometry_display
);
372 if (wPreferences
.size_display
== WDIS_CENTER
) {
373 moveGeometryDisplayCentered(scr
,
374 scr
->scr_width
/ 2, scr
->scr_height
/ 2);
375 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
376 moveGeometryDisplayCentered(scr
, 1, 1);
377 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
378 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
380 XMapRaised(dpy
, scr
->geometry_display
);
381 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, dir
);
387 mapGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
389 WScreen
*scr
= wwin
->screen_ptr
;
391 if (wPreferences
.size_display
== WDIS_NEW
)
394 if (wPreferences
.size_display
== WDIS_CENTER
) {
395 moveGeometryDisplayCentered(scr
, scr
->scr_width
/ 2,
396 scr
->scr_height
/ 2);
397 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
398 moveGeometryDisplayCentered(scr
, 1, 1);
399 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
400 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
402 XMapRaised(dpy
, scr
->geometry_display
);
403 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, 0);
406 #define unmapGeometryDisplay(w) \
407 XUnmapWindow(dpy, (w)->screen_ptr->geometry_display);
411 doWindowMove(WWindow
*wwin
, LinkedList
*list
, int dx
, int dy
)
415 int scr_width
= wwin
->screen_ptr
->scr_width
;
416 int scr_height
= wwin
->screen_ptr
->scr_height
;
419 wWindowMove(wwin
, wwin
->frame_x
+ dx
, wwin
->frame_y
+ dy
);
423 x
= tmpw
->frame_x
+ dx
;
424 y
= tmpw
->frame_y
+ dy
;
426 /* don't let windows become unreachable */
428 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
429 x
= 20 - (int)tmpw
->frame
->core
->width
;
430 else if (x
+ 20 > scr_width
)
433 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
434 y
= 20 - (int)tmpw
->frame
->core
->height
;
435 else if (y
+ 20 > scr_height
)
438 wWindowMove(tmpw
, x
, y
);
446 drawTransparentFrame(WWindow
*wwin
, int x
, int y
, int width
, int height
)
448 Window root
= wwin
->screen_ptr
->root_win
;
449 GC gc
= wwin
->screen_ptr
->frame_gc
;
453 if (!WFLAGP(wwin
, no_titlebar
) && !wwin
->flags
.shaded
) {
454 h
= wwin
->screen_ptr
->title_font
->height
+ TITLEBAR_EXTRA_HEIGHT
;
456 if (!WFLAGP(wwin
, no_resizebar
) && !wwin
->flags
.shaded
) {
457 /* Can't use wwin-frame->bottom_width because, in some cases
458 (e.g. interactive placement), frame does not point to anything. */
459 bottom
= RESIZEBAR_HEIGHT
- 1;
461 XDrawRectangle(dpy
, root
, gc
, x
, y
, width
+ 1, height
+ 1);
464 XDrawLine(dpy
, root
, gc
, x
+ 1, y
+ h
, x
+ width
+ 1, y
+ h
);
467 XDrawLine(dpy
, root
, gc
, x
+ 1,
470 y
+ height
- bottom
);
476 drawFrames(WWindow
*wwin
, LinkedList
*list
, int dx
, int dy
)
479 int scr_width
= wwin
->screen_ptr
->scr_width
;
480 int scr_height
= wwin
->screen_ptr
->scr_height
;
485 x
= wwin
->frame_x
+ dx
;
486 y
= wwin
->frame_y
+ dy
;
488 drawTransparentFrame(wwin
, x
, y
,
489 wwin
->frame
->core
->width
,
490 wwin
->frame
->core
->height
);
495 x
= tmpw
->frame_x
+ dx
;
496 y
= tmpw
->frame_y
+ dy
;
498 /* don't let windows become unreachable */
500 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
501 x
= 20 - (int)tmpw
->frame
->core
->width
;
502 else if (x
+ 20 > scr_width
)
505 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
506 y
= 20 - (int)tmpw
->frame
->core
->height
;
507 else if (y
+ 20 > scr_height
)
510 drawTransparentFrame(tmpw
, x
, y
, tmpw
->frame
->core
->width
,
511 tmpw
->frame
->core
->height
);
526 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &ev
)) ;
531 crossWorkspace(WScreen
*scr
, WWindow
*wwin
, int opaque_move
,
532 int new_workspace
, int rewind
)
534 /* do not let window be unmapped */
536 wwin
->flags
.changing_workspace
= 1;
537 wWindowChangeWorkspace(wwin
, new_workspace
);
539 /* go to new workspace */
540 wWorkspaceChange(scr
, new_workspace
);
542 wwin
->flags
.changing_workspace
= 0;
545 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, scr
->scr_width
- 20, 0);
547 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, -(scr
->scr_width
- 20), 0);
552 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
553 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
554 GrabModeAsync
, None
, wCursor
[WCUR_MOVE
], CurrentTime
);
562 /* arrays of WWindows sorted by the respective border position */
563 WWindow
**topList
; /* top border */
564 WWindow
**leftList
; /* left border */
565 WWindow
**rightList
; /* right border */
566 WWindow
**bottomList
; /* bottom border */
569 /* index of window in the above lists indicating the relative position
570 * of the window with the others */
576 int rubCount
; /* for workspace switching */
578 int winWidth
, winHeight
; /* width/height of the window */
579 int realX
, realY
; /* actual position of the window */
580 int calcX
, calcY
; /* calculated position of window */
581 int omouseX
, omouseY
; /* old mouse position */
582 int mouseX
, mouseY
; /* last known position of the pointer */
585 #define WTOP(w) (w)->frame_y
586 #define WLEFT(w) (w)->frame_x
587 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width + FRAME_BORDER_WIDTH)
588 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height + FRAME_BORDER_WIDTH)
591 compareWTop(const void *a
, const void *b
)
593 WWindow
*wwin1
= *(WWindow
**)a
;
594 WWindow
*wwin2
= *(WWindow
**)b
;
596 if (WTOP(wwin1
) > WTOP(wwin2
))
598 else if (WTOP(wwin1
) < WTOP(wwin2
))
606 compareWLeft(const void *a
, const void *b
)
608 WWindow
*wwin1
= *(WWindow
**)a
;
609 WWindow
*wwin2
= *(WWindow
**)b
;
611 if (WLEFT(wwin1
) > WLEFT(wwin2
))
613 else if (WLEFT(wwin1
) < WLEFT(wwin2
))
621 compareWRight(const void *a
, const void *b
)
623 WWindow
*wwin1
= *(WWindow
**)a
;
624 WWindow
*wwin2
= *(WWindow
**)b
;
626 if (WRIGHT(wwin1
) < WRIGHT(wwin2
))
628 else if (WRIGHT(wwin1
) > WRIGHT(wwin2
))
637 compareWBottom(const void *a
, const void *b
)
639 WWindow
*wwin1
= *(WWindow
**)a
;
640 WWindow
*wwin2
= *(WWindow
**)b
;
642 if (WBOTTOM(wwin1
) < WBOTTOM(wwin2
))
644 else if (WBOTTOM(wwin1
) > WBOTTOM(wwin2
))
652 updateResistance(WWindow
*wwin
, MoveData
*data
, int newX
, int newY
)
655 int newX2
= newX
+ data
->winWidth
;
656 int newY2
= newY
+ data
->winHeight
;
659 if (newX
< data
->realX
) {
660 if (data
->rightIndex
> 0
661 && newX
< WRIGHT(data
->rightList
[data
->rightIndex
-1])) {
663 } else if (data
->leftIndex
<= data
->count
-1
664 && newX2
<= WLEFT(data
->leftList
[data
->leftIndex
])) {
667 } else if (newX
> data
->realX
) {
668 if (data
->leftIndex
> 0
669 && newX2
> WLEFT(data
->leftList
[data
->leftIndex
-1])) {
671 } else if (data
->rightIndex
<= data
->count
-1
672 && newX
>= WRIGHT(data
->rightList
[data
->rightIndex
])) {
678 if (newY
< data
->realY
) {
679 if (data
->bottomIndex
> 0
680 && newY
< WBOTTOM(data
->bottomList
[data
->bottomIndex
-1])) {
682 } else if (data
->topIndex
<= data
->count
-1
683 && newY2
<= WTOP(data
->topList
[data
->topIndex
])) {
686 } else if (newY
> data
->realY
) {
687 if (data
->topIndex
> 0
688 && newY2
> WTOP(data
->topList
[data
->topIndex
-1])) {
690 } else if (data
->bottomIndex
<= data
->count
-1
691 && newY
>= WBOTTOM(data
->bottomList
[data
->bottomIndex
])) {
700 /* TODO: optimize this */
701 if (data
->realY
< WBOTTOM(data
->bottomList
[0])) {
702 data
->bottomIndex
= 0;
704 if (data
->realX
< WRIGHT(data
->rightList
[0])) {
705 data
->rightIndex
= 0;
707 if ((data
->realX
+ data
->winWidth
) > WLEFT(data
->leftList
[0])) {
710 if ((data
->realY
+ data
->winHeight
) > WTOP(data
->topList
[0])) {
713 for (i
= 0; i
< data
->count
; i
++) {
714 if (data
->realY
> WBOTTOM(data
->bottomList
[i
])) {
715 data
->bottomIndex
= i
+ 1;
717 if (data
->realX
> WRIGHT(data
->rightList
[i
])) {
718 data
->rightIndex
= i
+ 1;
720 if ((data
->realX
+ data
->winWidth
) < WLEFT(data
->leftList
[i
])) {
721 data
->leftIndex
= i
+ 1;
723 if ((data
->realY
+ data
->winHeight
) < WTOP(data
->topList
[i
])) {
724 data
->topIndex
= i
+ 1;
731 freeMoveData(MoveData
*data
)
736 free(data
->leftList
);
738 free(data
->rightList
);
739 if (data
->bottomList
)
740 free(data
->bottomList
);
745 updateMoveData(WWindow
*wwin
, MoveData
*data
)
747 WScreen
*scr
= wwin
->screen_ptr
;
752 tmp
= scr
->focused_window
;
754 if (tmp
!= wwin
&& scr
->current_workspace
== tmp
->frame
->workspace
755 && !tmp
->flags
.miniaturized
756 && !tmp
->flags
.hidden
757 && !tmp
->flags
.obscured
) {
758 data
->topList
[data
->count
] = tmp
;
759 data
->leftList
[data
->count
] = tmp
;
760 data
->rightList
[data
->count
] = tmp
;
761 data
->bottomList
[data
->count
] = tmp
;
767 if (data
->count
== 0) {
770 data
->rightIndex
= 0;
771 data
->bottomIndex
= 0;
776 * order from closest to the border of the screen to farthest
778 qsort(data
->topList
, data
->count
, sizeof(WWindow
**), compareWTop
);
779 qsort(data
->leftList
, data
->count
, sizeof(WWindow
**), compareWLeft
);
780 qsort(data
->rightList
, data
->count
, sizeof(WWindow
**), compareWRight
);
781 qsort(data
->bottomList
, data
->count
, sizeof(WWindow
**), compareWBottom
);
783 /* figure the position of the window relative to the others */
786 data
->leftIndex
= -1;
787 data
->rightIndex
= -1;
788 data
->bottomIndex
= -1;
790 if (WTOP(wwin
) < WBOTTOM(data
->bottomList
[0])) {
791 data
->bottomIndex
= 0;
793 if (WLEFT(wwin
) < WRIGHT(data
->rightList
[0])) {
794 data
->rightIndex
= 0;
796 if (WRIGHT(wwin
) > WLEFT(data
->leftList
[0])) {
799 if (WBOTTOM(wwin
) > WTOP(data
->topList
[0])) {
802 for (i
= 0; i
< data
->count
; i
++) {
803 if (WTOP(wwin
) >= WBOTTOM(data
->bottomList
[i
])) {
804 data
->bottomIndex
= i
+ 1;
806 if (WLEFT(wwin
) >= WRIGHT(data
->rightList
[i
])) {
807 data
->rightIndex
= i
+ 1;
809 if (WRIGHT(wwin
) <= WLEFT(data
->leftList
[i
])) {
810 data
->leftIndex
= i
+ 1;
812 if (WBOTTOM(wwin
) <= WTOP(data
->topList
[i
])) {
813 data
->topIndex
= i
+ 1;
820 initMoveData(WWindow
*wwin
, MoveData
*data
)
825 memset(data
, 0, sizeof(MoveData
));
827 for (i
= 0, tmp
= wwin
->screen_ptr
->focused_window
;
829 tmp
= tmp
->prev
, i
++);
832 data
->topList
= wmalloc(sizeof(WWindow
*) * i
);
833 data
->leftList
= wmalloc(sizeof(WWindow
*) * i
);
834 data
->rightList
= wmalloc(sizeof(WWindow
*) * i
);
835 data
->bottomList
= wmalloc(sizeof(WWindow
*) * i
);
837 updateMoveData(wwin
, data
);
840 data
->realX
= wwin
->frame_x
;
841 data
->realY
= wwin
->frame_y
;
842 data
->calcX
= wwin
->frame_x
;
843 data
->calcY
= wwin
->frame_y
;
845 data
->winWidth
= wwin
->frame
->core
->width
+ 2;
846 data
->winHeight
= wwin
->frame
->core
->height
+ 2;
851 checkWorkspaceChange(WWindow
*wwin
, MoveData
*data
, Bool opaqueMove
)
853 WScreen
*scr
= wwin
->screen_ptr
;
854 Bool changed
= False
;
856 if (data
->mouseX
<= 1) {
857 if (scr
->current_workspace
> 0) {
859 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
- 1,
864 } else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
) {
866 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->workspace_count
- 1,
871 } else if (data
->mouseX
>= scr
->scr_width
- 2) {
873 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
875 if (wPreferences
.ws_cycle
876 || scr
->workspace_count
== MAX_WORKSPACES
) {
878 crossWorkspace(scr
, wwin
, opaqueMove
, 0, False
);
882 /* if user insists on trying to go to next workspace even when
883 * it's already the last, create a new one */
884 else if (data
->omouseX
== data
->mouseX
885 && wPreferences
.ws_advance
) {
887 /* detect user "rubbing" the window against the edge */
888 if (data
->rubCount
> 0
889 && data
->omouseY
- data
->mouseY
> MOVE_THRESHOLD
) {
891 data
->rubCount
= -(data
->rubCount
+ 1);
893 } else if (data
->rubCount
<= 0
894 && data
->mouseY
- data
->omouseY
> MOVE_THRESHOLD
) {
896 data
->rubCount
= -data
->rubCount
+ 1;
899 /* create a new workspace */
900 if (abs(data
->rubCount
) > 2) {
901 /* go to next workspace */
904 crossWorkspace(scr
, wwin
, opaqueMove
,
905 scr
->current_workspace
+1, False
);
909 } else if (scr
->current_workspace
< scr
->workspace_count
) {
911 /* go to next workspace */
912 crossWorkspace(scr
, wwin
, opaqueMove
,
913 scr
->current_workspace
+1, False
);
926 updateWindowPosition(WWindow
*wwin
, MoveData
*data
, Bool doResistance
,
927 Bool opaqueMove
, int newMouseX
, int newMouseY
)
929 WScreen
*scr
= wwin
->screen_ptr
;
930 int dx
, dy
; /* how much mouse moved */
931 int winL
, winR
, winT
, winB
; /* requested new window position */
932 int newX
, newY
; /* actual new window position */
933 Bool hresist
, vresist
;
941 /* check the direction of the movement */
942 dx
= newMouseX
- data
->mouseX
;
943 dy
= newMouseY
- data
->mouseY
;
945 data
->omouseX
= data
->mouseX
;
946 data
->omouseY
= data
->mouseY
;
947 data
->mouseX
= newMouseX
;
948 data
->mouseY
= newMouseY
;
950 winL
= data
->calcX
+ dx
;
951 winR
= data
->calcX
+ data
->winWidth
+ dx
;
952 winT
= data
->calcY
+ dy
;
953 winB
= data
->calcY
+ data
->winHeight
+ dy
;
963 resist
= wPreferences
.edge_resistance
;
964 /* horizontal movement: check horizontal edge resistances */
966 /* window is the leftmost window: check against screen edge */
967 edge
= scr
->totalUsableArea
.x1
;
969 /* check position of nearest window to the left */
970 if (data
->rightIndex
> 0) {
971 /* there is some window at the left: check if it will block
973 rwin
= data
->rightList
[data
->rightIndex
- 1];
975 if (data
->realY
> WBOTTOM(rwin
)
976 || (data
->realY
+ data
->winHeight
) < WTOP(rwin
)) {
979 edge
= WRIGHT(rwin
) + 1;
980 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
983 if (resist
> 0 && winL
>= edge
- resist
&& winL
<= edge
) {
988 /* window is the rightmost window: check against screen edge */
989 edge
= scr
->totalUsableArea
.x2
;
991 /* check position of nearest window to the right */
992 if (data
->leftIndex
> 0) {
993 /* there is some window at the right: check if it will block
995 rwin
= data
->leftList
[data
->leftIndex
- 1];
997 if (data
->realY
> WBOTTOM(rwin
)
998 || (data
->realY
+ data
->winHeight
) < WTOP(rwin
)) {
1002 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1005 if (resist
> 0 && winR
<= edge
+ resist
&& winR
>= edge
) {
1006 newX
= edge
- data
->winWidth
;
1011 resist
= wPreferences
.edge_resistance
;
1012 /* vertical movement: check vertical edge resistances */
1014 /* window is the topmost window: check against screen edge */
1015 edge
= scr
->totalUsableArea
.y1
;
1017 /* check position of nearest window to the top */
1018 if (data
->bottomIndex
> 0) {
1019 /* there is some window at the top: check if it will block
1021 rwin
= data
->bottomList
[data
->bottomIndex
- 1];
1023 if (data
->realX
> WRIGHT(rwin
)
1024 || (data
->realX
+ data
->winWidth
) < WLEFT(rwin
)) {
1027 edge
= WBOTTOM(rwin
) + 1;
1028 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1031 if (resist
> 0 && winT
>= edge
- resist
&& winT
<= edge
) {
1035 } else if (dy
> 0) {
1036 /* window is the bottommost window: check against screen edge */
1037 edge
= scr
->totalUsableArea
.y2
;
1039 /* check position of nearest window to the bottom */
1040 if (data
->topIndex
> 0) {
1041 /* there is some window at the bottom: check if it will block
1043 rwin
= data
->topList
[data
->topIndex
- 1];
1045 if (data
->realX
> WRIGHT(rwin
)
1046 || (data
->realX
+ data
->winWidth
) < WLEFT(rwin
)) {
1050 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1053 if (resist
> 0 && winB
<= edge
+ resist
&& winB
>= edge
) {
1054 newY
= edge
- data
->winHeight
;
1060 /* update window position */
1064 if (((dx
> 0 && data
->calcX
- data
->realX
> 0)
1065 || (dx
< 0 && data
->calcX
- data
->realX
< 0)) && !hresist
)
1068 if (((dy
> 0 && data
->calcY
- data
->realY
> 0)
1069 || (dy
< 0 && data
->calcY
- data
->realY
< 0)) && !vresist
)
1072 if (data
->realX
!= newX
|| data
->realY
!= newY
) {
1074 if (wPreferences
.move_display
== WDIS_NEW
1075 && !scr
->selected_windows
) {
1076 showPosition(wwin
, data
->realX
, data
->realY
);
1079 doWindowMove(wwin
, scr
->selected_windows
,
1080 newX
- wwin
->frame_x
,
1081 newY
- wwin
->frame_y
);
1084 drawFrames(wwin
, scr
->selected_windows
,
1085 data
->realX
- wwin
->frame_x
,
1086 data
->realY
- wwin
->frame_y
);
1089 if (!scr
->selected_windows
1090 && wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
1092 moveGeometryDisplayCentered(scr
, newX
+ data
->winWidth
/2,
1093 newY
+ data
->winHeight
/2);
1098 drawFrames(wwin
, scr
->selected_windows
,
1099 newX
- wwin
->frame_x
,
1100 newY
- wwin
->frame_y
);
1103 if (!scr
->selected_windows
) {
1104 showPosition(wwin
, newX
, newY
);
1109 /* recalc relative window position */
1110 if (doResistance
&& (data
->realX
!= newX
|| data
->realY
!= newY
)) {
1111 updateResistance(wwin
, data
, newX
, newY
);
1119 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1122 wKeyboardMoveResizeWindow(WWindow
*wwin
)
1124 WScreen
*scr
= wwin
->screen_ptr
;
1125 Window root
= scr
->root_win
;
1127 int w
= wwin
->frame
->core
->width
;
1128 int h
= wwin
->frame
->core
->height
;
1129 int scr_width
= wwin
->screen_ptr
->scr_width
;
1130 int scr_height
= wwin
->screen_ptr
->scr_height
;
1131 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1132 int src_x
= wwin
->frame_x
;
1133 int src_y
= wwin
->frame_y
;
1134 int done
,off_x
,off_y
,ww
,wh
;
1137 KeySym keysym
=NoSymbol
;
1139 KeyCode shiftl
,shiftr
,ctrll
,ctrlmode
;
1141 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1142 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1143 ctrll
= XKeysymToKeycode(dpy
, XK_Control_L
);
1144 ctrlmode
=done
=off_x
=off_y
=0;
1148 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1150 if (!wwin
->flags
.selected
) {
1151 wUnselectWindows(scr
);
1154 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1155 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
1156 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
);
1158 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1159 if(scr
->selected_windows
)
1160 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1161 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1162 if(!scr
->selected_windows
)
1163 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1165 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1174 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1175 | ButtonPressMask
| ExposureMask
, &event
);
1176 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1177 if(scr
->selected_windows
)
1178 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1179 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1180 /*** I HATE EDGE RESISTANCE - ]d ***/
1183 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1187 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1192 switch (event
.type
) {
1195 if (event
.xkey
.time
- lastTime
> 50) {
1196 kspeed
/=(1 + (event
.xkey
.time
- lastTime
)/100);
1202 if (kspeed
< _KS
) kspeed
= _KS
;
1203 lastTime
= event
.xkey
.time
;
1205 if (event
.xkey
.state
& ControlMask
&& !wwin
->flags
.shaded
) {
1207 wUnselectWindows(scr
);
1212 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
) {
1214 cycleGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
, 0);
1216 cyclePositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1220 keysym
= XLookupKeysym(&event
.xkey
, 0);
1267 if (moment
!= RIGHT
)
1278 wWindowConstrainSize(wwin
, &ww
, &wh
);
1281 if (wPreferences
.ws_cycle
){
1282 if (src_x
+ off_x
+ ww
< 20){
1283 if(!scr
->current_workspace
) {
1284 wWorkspaceChange(scr
, scr
->workspace_count
-1);
1286 else wWorkspaceChange(scr
, scr
->current_workspace
-1);
1289 else if (src_x
+ off_x
+ 20 > scr_width
){
1290 if(scr
->current_workspace
== scr
->workspace_count
-1) {
1291 wWorkspaceChange(scr
, 0);
1293 else wWorkspaceChange(scr
, scr
->current_workspace
+1);
1298 if (src_x
+ off_x
+ ww
< 20)
1299 off_x
= 20 - ww
- src_x
;
1300 else if (src_x
+ off_x
+ 20 > scr_width
)
1301 off_x
= scr_width
- 20 - src_x
;
1304 if (src_y
+ off_y
+ wh
< 20) {
1305 off_y
= 20 - wh
- src_y
;
1307 else if (src_y
+ off_y
+ 20 > scr_height
) {
1308 off_y
= scr_height
- 20 - src_y
;
1317 WMHandleEvent(&event
);
1324 if (wwin
->flags
.shaded
&& !scr
->selected_windows
){
1325 moveGeometryDisplayCentered(scr
, src_x
+off_x
+ w
/2, src_y
+off_y
+ h
/2);
1329 unmapPositionDisplay(wwin
);
1330 mapGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1332 else if(!scr
->selected_windows
){
1333 unmapGeometryDisplay(wwin
);
1334 mapPositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1338 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1339 if(scr
->selected_windows
)
1340 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1341 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1344 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1349 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1351 else if(!scr
->selected_windows
)
1352 showPosition(wwin
, src_x
+off_x
, src_y
+off_y
);
1356 scr
->keymove_tick
=0;
1358 WMDeleteTimerWithClientData(&looper);
1360 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1361 if(scr
->selected_windows
)
1362 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1363 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1366 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1370 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1371 unmapGeometryDisplay(wwin
);
1374 unmapPositionDisplay(wwin
);
1375 XUngrabKeyboard(dpy
, CurrentTime
);
1376 XUngrabPointer(dpy
, CurrentTime
);
1380 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1382 list
=scr
->selected_windows
;
1383 if (!scr
->selected_windows
) {
1384 wWindowMove(wwin
, src_x
+off_x
, src_y
+off_y
);
1385 wWindowSynthConfigureNotify(wwin
);
1387 doWindowMove(wwin
,scr
->selected_windows
,off_x
,off_y
);
1389 wWindowSynthConfigureNotify(list
->head
);
1394 if (wwin
->client
.width
!= ww
)
1395 wwin
->flags
.user_changed_width
= 1;
1397 if (wwin
->client
.height
!= wh
- vert_border
)
1398 wwin
->flags
.user_changed_height
= 1;
1400 wWindowConfigure(wwin
, src_x
+off_x
, src_y
+off_y
,
1401 ww
, wh
- vert_border
);
1402 wWindowSynthConfigureNotify(wwin
);
1404 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1405 wSetFocusTo(scr
, wwin
);
1414 *----------------------------------------------------------------------
1415 * wMouseMoveWindow--
1416 * Move the named window and the other selected ones (if any),
1417 * interactively. Also shows the position of the window, if only one
1418 * window is being moved.
1419 * If the window is not on the selected window list, the selected
1420 * windows are deselected.
1421 * If shift is pressed during the operation, the position display
1422 * is changed to another type.
1425 * True if the window was moved, False otherwise.
1428 * The window(s) position is changed, and the client(s) are
1429 * notified about that.
1430 * The position display configuration may be changed.
1431 *----------------------------------------------------------------------
1434 wMouseMoveWindow(WWindow
*wwin
, XEvent
*ev
)
1436 WScreen
*scr
= wwin
->screen_ptr
;
1438 Window root
= scr
->root_win
;
1439 KeyCode shiftl
, shiftr
;
1443 /* This needs not to change while moving, else bad things can happen */
1444 int opaqueMove
= wPreferences
.opaque_move
;
1446 #ifdef GHOST_WINDOW_MOVE
1449 rimg
= InitGhostWindowMove(scr
);
1452 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1453 XSetWindowAttributes attr
;
1455 attr
.save_under
= True
;
1456 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
,
1457 CWSaveUnder
, &attr
);
1460 initMoveData(wwin
, &moveData
);
1462 moveData
.mouseX
= ev
->xmotion
.x_root
;
1463 moveData
.mouseY
= ev
->xmotion
.y_root
;
1465 if (!wwin
->flags
.selected
) {
1466 /* this window is not selected, unselect others and move only wwin */
1467 wUnselectWindows(scr
);
1470 puts("Moving window");
1472 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1473 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1479 /* XWarpPointer() doesn't seem to generate Motion events, so
1480 we've got to simulate them */
1481 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1482 &event
.xmotion
.y_root
, &junk
, &junk
,
1483 (unsigned *) &junk
);
1485 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1486 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
,
1489 if (event
.type
== MotionNotify
) {
1490 /* compress MotionNotify events */
1491 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1494 switch (event
.type
) {
1496 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1497 && started
&& !scr
->selected_windows
) {
1500 drawFrames(wwin
, scr
->selected_windows
,
1501 moveData
.realX
- wwin
->frame_x
,
1502 moveData
.realY
- wwin
->frame_y
);
1505 if (wPreferences
.move_display
== WDIS_NEW
1506 && !scr
->selected_windows
) {
1507 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1510 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1511 moveData
.winWidth
, moveData
.winHeight
);
1513 if (wPreferences
.move_display
== WDIS_NEW
1514 && !scr
->selected_windows
) {
1516 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1520 drawFrames(wwin
, scr
->selected_windows
,
1521 moveData
.realX
- wwin
->frame_x
,
1522 moveData
.realY
- wwin
->frame_y
);
1529 updateWindowPosition(wwin
, &moveData
,
1530 scr
->selected_windows
== NULL
1531 && wPreferences
.edge_resistance
> 0,
1533 event
.xmotion
.x_root
,
1534 event
.xmotion
.y_root
);
1536 if (!warped
&& !wPreferences
.no_autowrap
) {
1537 int oldWorkspace
= scr
->current_workspace
;
1539 if (wPreferences
.move_display
== WDIS_NEW
1540 && !scr
->selected_windows
) {
1541 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1545 drawFrames(wwin
, scr
->selected_windows
,
1546 moveData
.realX
- wwin
->frame_x
,
1547 moveData
.realY
- wwin
->frame_y
);
1549 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1550 if (scr
->current_workspace
!= oldWorkspace
1551 && wPreferences
.edge_resistance
> 0
1552 && scr
->selected_windows
== NULL
)
1553 updateMoveData(wwin
, &moveData
);
1557 drawFrames(wwin
, scr
->selected_windows
,
1558 moveData
.realX
- wwin
->frame_x
,
1559 moveData
.realY
- wwin
->frame_y
);
1561 if (wPreferences
.move_display
== WDIS_NEW
1562 && !scr
->selected_windows
) {
1564 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1570 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1571 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1573 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1574 | ButtonReleaseMask
| ButtonPressMask
,
1575 wCursor
[WCUR_MOVE
], CurrentTime
);
1577 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1580 if (!scr
->selected_windows
)
1581 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1582 moveData
.winWidth
, moveData
.winHeight
);
1584 if (started
&& !opaqueMove
)
1585 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1587 if (!opaqueMove
|| (wPreferences
.move_display
==WDIS_NEW
1588 && !scr
->selected_windows
)) {
1590 if (wPreferences
.move_display
==WDIS_NEW
)
1591 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1600 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1605 drawFrames(wwin
, scr
->selected_windows
,
1606 moveData
.realX
- wwin
->frame_x
,
1607 moveData
.realY
- wwin
->frame_y
);
1609 doWindowMove(wwin
, scr
->selected_windows
,
1610 moveData
.realX
- wwin
->frame_x
,
1611 moveData
.realY
- wwin
->frame_y
);
1613 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1614 wWindowSynthConfigureNotify(wwin
);
1616 XUngrabKeyboard(dpy
, CurrentTime
);
1619 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1620 wSetFocusTo(scr
, wwin
);
1622 if (wPreferences
.move_display
== WDIS_NEW
)
1623 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1625 if (!scr
->selected_windows
) {
1626 /* get rid of the geometry window */
1627 unmapPositionDisplay(wwin
);
1631 puts("End move window");
1637 if (started
&& !opaqueMove
) {
1638 drawFrames(wwin
, scr
->selected_windows
,
1639 moveData
.realX
- wwin
->frame_x
,
1640 moveData
.realY
- wwin
->frame_y
);
1642 WMHandleEvent(&event
);
1645 drawFrames(wwin
, scr
->selected_windows
,
1646 moveData
.realX
- wwin
->frame_x
,
1647 moveData
.realY
- wwin
->frame_y
);
1649 WMHandleEvent(&event
);
1655 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1656 XSetWindowAttributes attr
;
1658 attr
.save_under
= False
;
1659 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
,
1660 CWSaveUnder
, &attr
);
1663 freeMoveData(&moveData
);
1670 #define HCONSTRAIN 2
1673 getResizeDirection(WWindow
*wwin
, int x
, int y
, int dx
, int dy
,
1676 int w
= wwin
->frame
->core
->width
- 1;
1677 int cw
= wwin
->frame
->resizebar_corner_width
;
1680 /* if not resizing through the resizebar */
1681 if (!(flags
& RESIZEBAR
)) {
1682 int xdir
= (abs(x
) < (wwin
->client
.width
/2)) ? LEFT
: RIGHT
;
1683 int ydir
= (abs(y
) < (wwin
->client
.height
/2)) ? UP
: DOWN
;
1684 if (abs(dx
) < 2 || abs(dy
) < 2) {
1685 if (abs(dy
) > abs(dx
))
1690 return (xdir
| ydir
);
1693 /* window is too narrow. allow diagonal resize */
1697 if (flags
& HCONSTRAIN
)
1702 return (LEFT
| ydir
);
1704 return (RIGHT
| ydir
);
1706 /* vertical resize */
1707 if ((x
> cw
) && (x
< w
- cw
))
1715 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1723 wMouseResizeWindow(WWindow
*wwin
, XEvent
*ev
)
1726 WScreen
*scr
= wwin
->screen_ptr
;
1727 Window root
= scr
->root_win
;
1728 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1729 int fw
= wwin
->frame
->core
->width
;
1730 int fh
= wwin
->frame
->core
->height
;
1731 int fx
= wwin
->frame_x
;
1732 int fy
= wwin
->frame_y
;
1733 int is_resizebar
= (wwin
->frame
->resizebar
1734 && ev
->xany
.window
==wwin
->frame
->resizebar
->window
);
1738 int rw
= fw
, rh
= fh
;
1739 int rx1
, ry1
, rx2
, ry2
;
1741 KeyCode shiftl
, shiftr
;
1748 if (wwin
->flags
.shaded
) {
1749 wwarning("internal error: tryein");
1752 orig_x
= ev
->xbutton
.x_root
;
1753 orig_y
= ev
->xbutton
.y_root
;
1757 puts("Resizing window");
1760 wUnselectWindows(scr
);
1765 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1766 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1767 if (!WFLAGP(wwin
, no_titlebar
))
1768 h
= wwin
->screen_ptr
->title_font
->height
+ TITLEBAR_EXTRA_HEIGHT
;
1772 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
| ButtonReleaseMask
1773 | ButtonPressMask
| ExposureMask
, &event
);
1774 switch (event
.type
) {
1776 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1777 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1779 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1780 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
1781 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1783 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1797 dw
= orig_x
- event
.xmotion
.x_root
;
1798 else if (res
& RIGHT
)
1799 dw
= event
.xmotion
.x_root
- orig_x
;
1801 dh
= orig_y
- event
.xmotion
.y_root
;
1802 else if (res
& DOWN
)
1803 dh
= event
.xmotion
.y_root
- orig_y
;
1805 orig_x
= event
.xmotion
.x_root
;
1806 orig_y
= event
.xmotion
.y_root
;
1811 fh
= rh
- vert_border
;
1812 wWindowConstrainSize(wwin
, &fw
, &fh
);
1816 else if (res
& RIGHT
)
1820 else if (res
& DOWN
)
1822 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1823 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1828 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
1829 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
1831 /* check if resizing through resizebar */
1837 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
1838 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
1839 flags
|= HCONSTRAIN
;
1841 res
= getResizeDirection(wwin
, tx
, ty
,
1842 orig_x
- event
.xmotion
.x_root
,
1843 orig_y
- event
.xmotion
.y_root
, flags
);
1845 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1846 | ButtonReleaseMask
| ButtonPressMask
,
1847 wCursor
[WCUR_RESIZE
], CurrentTime
);
1848 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1853 /* Draw the resize frame for the first time. */
1854 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
1856 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1858 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1863 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
1864 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
1866 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
1867 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1869 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
1871 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1873 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
1874 if (wPreferences
.size_display
== WDIS_NEW
) {
1875 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
1876 orig_fy
+ orig_fh
, res
);
1878 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1887 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1891 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1893 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1895 XUngrabKeyboard(dpy
, CurrentTime
);
1896 unmapGeometryDisplay(wwin
);
1899 if (wwin
->client
.width
!= fw
)
1900 wwin
->flags
.user_changed_width
= 1;
1902 if (wwin
->client
.height
!= fh
- vert_border
)
1903 wwin
->flags
.user_changed_height
= 1;
1905 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
1908 puts("End resize window");
1913 WMHandleEvent(&event
);
1928 wUnselectWindows(WScreen
*scr
)
1932 while (scr
->selected_windows
) {
1933 wwin
= scr
->selected_windows
->head
;
1934 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
1935 wIconSelect(wwin
->icon
);
1937 wSelectWindow(wwin
, False
);
1943 selectWindowsInside(WScreen
*scr
, int x1
, int y1
, int x2
, int y2
)
1947 /* select the windows and put them in the selected window list */
1948 tmpw
= scr
->focused_window
;
1949 while (tmpw
!= NULL
) {
1950 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
1951 if ((tmpw
->frame
->workspace
== scr
->current_workspace
1952 || IS_OMNIPRESENT(tmpw
))
1953 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
1954 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
1955 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
1956 wSelectWindow(tmpw
, True
);
1965 wSelectWindows(WScreen
*scr
, XEvent
*ev
)
1968 Window root
= scr
->root_win
;
1969 GC gc
= scr
->frame_gc
;
1970 int xp
= ev
->xbutton
.x_root
;
1971 int yp
= ev
->xbutton
.y_root
;
1976 puts("Selecting windows");
1978 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
1979 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
1980 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
],
1981 CurrentTime
) != Success
) {
1986 wUnselectWindows(scr
);
1988 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
1990 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
1991 | ButtonPressMask
, &event
);
1993 switch (event
.type
) {
1995 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
1996 x
= event
.xmotion
.x_root
;
2003 y
= event
.xmotion
.y_root
;
2010 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2017 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2020 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2022 XUngrabPointer(dpy
, CurrentTime
);
2023 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
2026 wKWMSelectRootRegion(scr
, x
, y
, w
, h
,
2027 event
.xbutton
.state
& ControlMask
);
2028 #endif /* KWM_HINTS */
2031 puts("End window selection");
2036 WMHandleEvent(&event
);
2044 InteractivePlaceWindow(WWindow
*wwin
, int *x_ret
, int *y_ret
,
2045 unsigned width
, unsigned height
)
2047 WScreen
*scr
= wwin
->screen_ptr
;
2048 Window root
= scr
->root_win
;
2051 KeyCode shiftl
, shiftr
;
2055 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2056 GrabModeAsync
, GrabModeAsync
, None
,
2057 wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2062 if (!WFLAGP(wwin
, no_titlebar
)) {
2063 h
= scr
->title_font
->height
+ TITLEBAR_EXTRA_HEIGHT
;
2066 if (!WFLAGP(wwin
, no_resizebar
)) {
2067 height
+= RESIZEBAR_HEIGHT
;
2069 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2070 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
,
2071 (unsigned *) &junk
);
2072 mapPositionDisplay(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2074 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2076 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2077 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2079 WMMaskEvent(dpy
, PointerMotionMask
|ButtonPressMask
|ExposureMask
|KeyPressMask
,
2081 switch (event
.type
) {
2083 if ((event
.xkey
.keycode
== shiftl
)
2084 || (event
.xkey
.keycode
== shiftr
)) {
2085 drawTransparentFrame(wwin
,
2086 x
- width
/2, y
- h
/2, width
, height
);
2087 cyclePositionDisplay(wwin
,
2088 x
- width
/2, y
- h
/2, width
, height
);
2089 drawTransparentFrame(wwin
,
2090 x
- width
/2, y
- h
/2, width
, height
);
2095 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2097 x
= event
.xmotion
.x_root
;
2098 y
= event
.xmotion
.y_root
;
2100 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2101 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2103 showPosition(wwin
, x
- width
/2, y
- h
/2);
2105 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2110 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2112 *x_ret
= x
- width
/2;
2114 XUngrabPointer(dpy
, CurrentTime
);
2115 XUngrabKeyboard(dpy
, CurrentTime
);
2116 /* get rid of the geometry window */
2117 unmapPositionDisplay(wwin
);
2121 WMHandleEvent(&event
);