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>
31 #include "WindowMaker.h"
40 #include "workspace.h"
48 /* How many different types of geometry/position
49 display thingies are there? */
50 #define NUM_DISPLAYS 4
54 #define HORIZONTAL (LEFT|RIGHT)
57 #define VERTICAL (UP|DOWN)
59 /****** Global Variables ******/
60 extern Time LastTimestamp
;
62 extern Cursor wCursor
[WCUR_LAST
];
64 extern WPreferences wPreferences
;
66 extern Atom _XA_WM_PROTOCOLS
;
71 wGetGeometryWindowSize(WScreen
*scr
, unsigned int *width
,
75 *width
= XmbTextEscapement(scr
->info_text_font
->font
, "-8888 x -8888", 13);
76 *height
= (7 * scr
->info_text_font
->height
) / 4 - 1;
78 *width
= XTextWidth(scr
->info_text_font
->font
, "-8888 x -8888", 13);
79 *height
= (7 * scr
->info_text_font
->font
->ascent
) / 4 - 1;
85 *----------------------------------------------------------------------
86 * moveGeometryDisplayCentered
88 * routine that moves the geometry/position window on scr so it is
89 * centered over the given coordinates (x,y). Also the window position
90 * is clamped so it stays on the screen at all times.
91 *----------------------------------------------------------------------
94 moveGeometryDisplayCentered(WScreen
*scr
, int x
, int y
)
96 x
-= scr
->geometry_display_width
/ 2;
97 y
-= scr
->geometry_display_height
/ 2;
101 else if (x
> (scr
->scr_width
- scr
->geometry_display_width
- 3))
102 x
= scr
->scr_width
- scr
->geometry_display_width
- 3;
106 else if (y
> (scr
->scr_height
- scr
->geometry_display_height
- 3))
107 y
= scr
->scr_height
- scr
->geometry_display_height
- 3;
109 XMoveWindow(dpy
, scr
->geometry_display
, x
, y
);
114 showPosition(WWindow
*wwin
, int x
, int y
)
116 WScreen
*scr
= wwin
->screen_ptr
;
117 GC gc
= scr
->info_text_gc
;
121 if (wPreferences
.move_display
== WDIS_NEW
) {
123 int width
= wwin
->frame
->core
->width
;
124 int height
= wwin
->frame
->core
->height
;
126 GC lgc
= scr
->line_gc
;
127 XSetForeground(dpy
, lgc
, scr
->line_pixel
);
128 sprintf(num
, "%i", x
);
130 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
-1, scr
->scr_width
, y
-1);
131 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
+height
+2, scr
->scr_width
,
133 XDrawLine(dpy
, scr
->root_win
, lgc
, x
-1, 0, x
-1, scr
->scr_height
);
134 XDrawLine(dpy
, scr
->root_win
, lgc
, x
+width
+2, 0, x
+width
+2,
138 XClearArea(dpy
, scr
->geometry_display
, 1, 1,
139 scr
->geometry_display_width
-2, scr
->geometry_display_height
-2,
141 sprintf(num
, "%+i %-+i", x
, y
);
142 fw
= wTextWidth(scr
->info_text_font
->font
, num
, strlen(num
));
144 XSetForeground(dpy
, gc
, scr
->black_pixel
);
146 fh
= scr
->info_text_font
->height
;
147 wDrawString(scr
->geometry_display
, scr
->info_text_font
, gc
,
148 (scr
->geometry_display_width
- 2 - fw
) / 2,
149 (scr
->geometry_display_height
-fh
)/2 + scr
->info_text_font
->y
,
151 wDrawBevel(scr
->geometry_display
, scr
->geometry_display_width
+1,
152 scr
->geometry_display_height
+1,
153 scr
->widget_texture
, WREL_RAISED
);
159 cyclePositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
161 WScreen
*scr
= wwin
->screen_ptr
;
163 wPreferences
.move_display
++;
164 wPreferences
.move_display
%= NUM_DISPLAYS
;
166 if (wPreferences
.move_display
== WDIS_NEW
) {
167 XUnmapWindow(dpy
, scr
->geometry_display
);
169 if (wPreferences
.move_display
== WDIS_CENTER
) {
170 moveGeometryDisplayCentered(scr
,
171 scr
->scr_width
/2, scr
->scr_height
/2);
172 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
173 moveGeometryDisplayCentered(scr
, 1, 1);
174 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
175 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
177 XMapRaised(dpy
, scr
->geometry_display
);
178 showPosition(wwin
, x
, y
);
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 doWindowMove(wwin
, scr
->selected_windows
,
1075 newX
- wwin
->frame_x
,
1076 newY
- wwin
->frame_y
);
1079 drawFrames(wwin
, scr
->selected_windows
,
1080 data
->realX
- wwin
->frame_x
,
1081 data
->realY
- wwin
->frame_y
);
1084 if (!scr
->selected_windows
1085 && wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
1087 moveGeometryDisplayCentered(scr
, newX
+ data
->winWidth
/2,
1088 newY
+ data
->winHeight
/2);
1093 drawFrames(wwin
, scr
->selected_windows
,
1094 newX
- wwin
->frame_x
,
1095 newY
- wwin
->frame_y
);
1098 if (!scr
->selected_windows
) {
1100 if (wPreferences
.move_display
== WDIS_NEW
) {
1102 showPosition(wwin
, data
->realX
, data
->realY
);
1105 showPosition(wwin
, newX
, newY
);
1110 /* recalc relative window position */
1111 if (doResistance
&& (data
->realX
!= newX
|| data
->realY
!= newY
)) {
1112 updateResistance(wwin
, data
, newX
, newY
);
1123 typedef struct _looper
{
1129 _keyloop(_looper
*lpr
){
1130 WWindow
*wwin
= lpr
->wwin
;
1131 WScreen
*scr
= wwin
->screen_ptr
;
1132 int w
= wwin
->frame
->core
->width
;
1133 int h
= wwin
->frame
->core
->height
;
1134 int src_x
= wwin
->frame_x
;
1135 int src_y
= wwin
->frame_y
;
1137 if (!scr
->selected_windows
){
1138 drawTransparentFrame(wwin
, src_x
+lpr
->ox
, src_y
+lpr
->oy
, w
, h
);
1144 /* printf("called\n");*/
1145 if (!scr
->selected_windows
){
1146 drawTransparentFrame(wwin
, src_x
+lpr
->ox
, src_y
+lpr
->oy
, w
, h
);
1149 if(scr
->keymove_tick
)
1150 WMAddTimerHandler(15000,(WMCallback
*)_keyloop
, lpr
);
1157 wKeyboardMoveResizeWindow(WWindow
*wwin
)
1159 WScreen
*scr
= wwin
->screen_ptr
;
1160 Window root
= scr
->root_win
;
1162 int w
= wwin
->frame
->core
->width
;
1163 int h
= wwin
->frame
->core
->height
;
1164 int scr_width
= wwin
->screen_ptr
->scr_width
;
1165 int scr_height
= wwin
->screen_ptr
->scr_height
;
1166 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1167 int src_x
= wwin
->frame_x
;
1168 int src_y
= wwin
->frame_y
;
1169 int done
,off_x
,off_y
,ww
,wh
;
1172 KeySym keysym
=NoSymbol
;
1173 KeyCode shiftl
,shiftr
,ctrll
,ctrlmode
;
1179 scr->keymove_tick=1;
1180 WMAddTimerHandler(1000,(WMCallback*)_keyloop, &looper);
1183 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1184 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1185 ctrll
= XKeysymToKeycode(dpy
, XK_Control_L
);
1186 ctrlmode
=done
=off_x
=off_y
=0;
1190 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1192 if (!wwin
->flags
.selected
) {
1193 wUnselectWindows(scr
);
1196 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1197 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
1198 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
);
1200 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1201 if(scr
->selected_windows
)
1202 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1203 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1204 if(!scr
->selected_windows
)
1205 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1207 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1216 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1217 | ButtonPressMask
| ExposureMask
, &event
);
1218 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1219 if(scr
->selected_windows
)
1220 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1221 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1222 /*** I HATE EDGE RESISTANCE - ]d ***/
1225 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1229 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1234 switch (event
.type
) {
1237 if (event
.xkey
.time
- lastTime
> 50) {
1243 lastTime
= event
.xkey
.time
;
1245 if (event
.xkey
.state
& ControlMask
&& !wwin
->flags
.shaded
){
1247 wUnselectWindows(scr
);
1252 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
){
1254 cycleGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
, 0);
1256 cyclePositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1259 keysym
= XLookupKeysym(&event
.xkey
, 0);
1302 wWindowConstrainSize(wwin
, &ww
, &wh
);
1305 if (wPreferences
.ws_cycle
){
1306 if (src_x
+ off_x
+ wwin
->frame
->core
->width
< 20){
1307 if(!scr
->current_workspace
) {
1308 wWorkspaceChange(scr
, scr
->workspace_count
-1);
1310 else wWorkspaceChange(scr
, scr
->current_workspace
-1);
1313 else if (src_x
+ off_x
+ 20 > scr_width
){
1314 if(scr
->current_workspace
== scr
->workspace_count
-1) {
1315 wWorkspaceChange(scr
, 0);
1317 else wWorkspaceChange(scr
, scr
->current_workspace
+1);
1322 if (src_x
+ off_x
+ wwin
->frame
->core
->width
< 20)
1323 off_x
= 20 - wwin
->frame
->core
->width
- src_x
;
1324 else if (src_x
+ off_x
+ 20 > scr_width
)
1325 off_x
= scr_width
- 20 - src_x
;
1328 if (src_y
+ off_y
+ wwin
->frame
->core
->height
< 20)
1329 off_y
= 20 - wwin
->frame
->core
->height
- src_y
;
1330 else if (src_y
+ off_y
+ 20 > scr_height
)
1331 off_y
= scr_height
- 20 - src_y
;
1340 WMHandleEvent(&event
);
1347 if (wwin
->flags
.shaded
&& !scr
->selected_windows
){
1348 moveGeometryDisplayCentered(scr
, src_x
+off_x
+ w
/2, src_y
+off_y
+ h
/2);
1352 unmapPositionDisplay(wwin
);
1353 mapGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1355 else if(!scr
->selected_windows
){
1356 unmapGeometryDisplay(wwin
);
1357 mapPositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1361 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1362 if(scr
->selected_windows
)
1363 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1364 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1367 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1372 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1374 else if(!scr
->selected_windows
)
1375 showPosition(wwin
, src_x
+off_x
, src_y
+off_y
);
1379 scr
->keymove_tick
=0;
1381 WMDeleteTimerWithClientData(&looper);
1383 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1384 if(scr
->selected_windows
)
1385 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1386 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1389 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1393 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1394 unmapGeometryDisplay(wwin
);
1397 unmapPositionDisplay(wwin
);
1398 XUngrabKeyboard(dpy
, CurrentTime
);
1399 XUngrabPointer(dpy
, CurrentTime
);
1403 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1405 list
=scr
->selected_windows
;
1406 if (!scr
->selected_windows
) {
1407 wWindowMove(wwin
, src_x
+off_x
, src_y
+off_y
);
1408 wWindowSynthConfigureNotify(wwin
);
1410 doWindowMove(wwin
,scr
->selected_windows
,off_x
,off_y
);
1412 wWindowSynthConfigureNotify(list
->head
);
1417 if (wwin
->client
.width
!= ww
)
1418 wwin
->flags
.user_changed_width
= 1;
1420 if (wwin
->client
.height
!= wh
- vert_border
)
1421 wwin
->flags
.user_changed_height
= 1;
1423 wWindowConfigure(wwin
, src_x
+off_x
, src_y
+off_y
,
1424 ww
, wh
- vert_border
);
1425 wWindowSynthConfigureNotify(wwin
);
1427 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1428 wSetFocusTo(scr
, wwin
);
1437 *----------------------------------------------------------------------
1438 * wMouseMoveWindow--
1439 * Move the named window and the other selected ones (if any),
1440 * interactively. Also shows the position of the window, if only one
1441 * window is being moved.
1442 * If the window is not on the selected window list, the selected
1443 * windows are deselected.
1444 * If shift is pressed during the operation, the position display
1445 * is changed to another type.
1448 * True if the window was moved, False otherwise.
1451 * The window(s) position is changed, and the client(s) are
1452 * notified about that.
1453 * The position display configuration may be changed.
1454 *----------------------------------------------------------------------
1457 wMouseMoveWindow(WWindow
*wwin
, XEvent
*ev
)
1459 WScreen
*scr
= wwin
->screen_ptr
;
1461 Window root
= scr
->root_win
;
1462 KeyCode shiftl
, shiftr
;
1465 /* This needs not to change while moving, else bad things can happen */
1466 int opaqueMove
= wPreferences
.opaque_move
;
1468 #ifdef GHOST_WINDOW_MOVE
1471 rimg
= InitGhostWindowMove(scr
);
1474 initMoveData(wwin
, &moveData
);
1476 moveData
.mouseX
= ev
->xmotion
.x_root
;
1477 moveData
.mouseY
= ev
->xmotion
.y_root
;
1479 if (!wwin
->flags
.selected
) {
1480 /* this window is not selected, unselect others and move only wwin */
1481 wUnselectWindows(scr
);
1484 puts("Moving window");
1486 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1487 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1493 /* XWarpPointer() doesn't seem to generate Motion events, so
1494 we've got to simulate them */
1495 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1496 &event
.xmotion
.y_root
, &junk
, &junk
,
1497 (unsigned *) &junk
);
1499 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1500 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
,
1503 if (event
.type
== MotionNotify
) {
1504 /* compress MotionNotify events */
1505 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1508 switch (event
.type
) {
1510 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1511 && started
&& !scr
->selected_windows
) {
1514 drawFrames(wwin
, scr
->selected_windows
,
1515 moveData
.realX
- wwin
->frame_x
,
1516 moveData
.realY
- wwin
->frame_y
);
1519 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1520 moveData
.winWidth
, moveData
.winHeight
);
1523 drawFrames(wwin
, scr
->selected_windows
,
1524 moveData
.realX
- wwin
->frame_x
,
1525 moveData
.realY
- wwin
->frame_y
);
1532 updateWindowPosition(wwin
, &moveData
,
1533 scr
->selected_windows
== NULL
1534 && wPreferences
.edge_resistance
> 0,
1536 event
.xmotion
.x_root
,
1537 event
.xmotion
.y_root
);
1539 if (!warped
&& !wPreferences
.no_autowrap
) {
1540 int oldWorkspace
= scr
->current_workspace
;
1543 drawFrames(wwin
, scr
->selected_windows
,
1544 moveData
.realX
- wwin
->frame_x
,
1545 moveData
.realY
- wwin
->frame_y
);
1547 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1548 if (scr
->current_workspace
!= oldWorkspace
1549 && wPreferences
.edge_resistance
> 0
1550 && scr
->selected_windows
== NULL
)
1551 updateMoveData(wwin
, &moveData
);
1556 drawFrames(wwin
, scr
->selected_windows
,
1557 moveData
.realX
- wwin
->frame_x
,
1558 moveData
.realY
- wwin
->frame_y
);
1563 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1564 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1566 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1567 | ButtonReleaseMask
| ButtonPressMask
,
1568 wCursor
[WCUR_MOVE
], CurrentTime
);
1570 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1573 if (!scr
->selected_windows
)
1574 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1575 moveData
.winWidth
, moveData
.winHeight
);
1577 if (started
&& !opaqueMove
)
1578 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1589 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1594 drawFrames(wwin
, scr
->selected_windows
,
1595 moveData
.realX
- wwin
->frame_x
,
1596 moveData
.realY
- wwin
->frame_y
);
1598 doWindowMove(wwin
, scr
->selected_windows
,
1599 moveData
.realX
- wwin
->frame_x
,
1600 moveData
.realY
- wwin
->frame_y
);
1602 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1603 wWindowSynthConfigureNotify(wwin
);
1605 XUngrabKeyboard(dpy
, CurrentTime
);
1608 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1609 wSetFocusTo(scr
, wwin
);
1611 if (wPreferences
.move_display
== WDIS_NEW
)
1612 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1614 if (!scr
->selected_windows
) {
1615 /* get rid of the geometry window */
1616 unmapPositionDisplay(wwin
);
1620 puts("End move window");
1622 freeMoveData(&moveData
);
1627 if (started
&& !opaqueMove
) {
1628 drawFrames(wwin
, scr
->selected_windows
,
1629 moveData
.realX
- wwin
->frame_x
,
1630 moveData
.realY
- wwin
->frame_y
);
1632 WMHandleEvent(&event
);
1635 drawFrames(wwin
, scr
->selected_windows
,
1636 moveData
.realX
- wwin
->frame_x
,
1637 moveData
.realY
- wwin
->frame_y
);
1639 WMHandleEvent(&event
);
1645 freeMoveData(&moveData
);
1652 #define HCONSTRAIN 2
1655 getResizeDirection(WWindow
*wwin
, int x
, int y
, int dx
, int dy
,
1658 int w
= wwin
->frame
->core
->width
- 1;
1659 int cw
= wwin
->frame
->resizebar_corner_width
;
1662 /* if not resizing through the resizebar */
1663 if (!(flags
& RESIZEBAR
)) {
1664 int xdir
= (abs(x
) < (wwin
->client
.width
/2)) ? LEFT
: RIGHT
;
1665 int ydir
= (abs(y
) < (wwin
->client
.height
/2)) ? UP
: DOWN
;
1666 if (abs(dx
) < 2 || abs(dy
) < 2) {
1667 if (abs(dy
) > abs(dx
))
1672 return (xdir
| ydir
);
1675 /* window is too narrow. allow diagonal resize */
1679 if (flags
& HCONSTRAIN
)
1684 return (LEFT
| ydir
);
1686 return (RIGHT
| ydir
);
1688 /* vertical resize */
1689 if ((x
> cw
) && (x
< w
- cw
))
1697 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1705 wMouseResizeWindow(WWindow
*wwin
, XEvent
*ev
)
1708 WScreen
*scr
= wwin
->screen_ptr
;
1709 Window root
= scr
->root_win
;
1710 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1711 int fw
= wwin
->frame
->core
->width
;
1712 int fh
= wwin
->frame
->core
->height
;
1713 int fx
= wwin
->frame_x
;
1714 int fy
= wwin
->frame_y
;
1715 int is_resizebar
= (wwin
->frame
->resizebar
1716 && ev
->xany
.window
==wwin
->frame
->resizebar
->window
);
1720 int rw
= fw
, rh
= fh
;
1721 int rx1
, ry1
, rx2
, ry2
;
1723 KeyCode shiftl
, shiftr
;
1730 if (wwin
->flags
.shaded
) {
1731 wwarning("internal error: tryein");
1734 orig_x
= ev
->xbutton
.x_root
;
1735 orig_y
= ev
->xbutton
.y_root
;
1739 puts("Resizing window");
1742 wUnselectWindows(scr
);
1747 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1748 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1749 if (!WFLAGP(wwin
, no_titlebar
))
1750 h
= wwin
->screen_ptr
->title_font
->height
+ TITLEBAR_EXTRA_HEIGHT
;
1754 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
| ButtonReleaseMask
1755 | ButtonPressMask
| ExposureMask
, &event
);
1756 switch (event
.type
) {
1758 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1759 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1761 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1762 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
1763 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1765 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1779 dw
= orig_x
- event
.xmotion
.x_root
;
1780 else if (res
& RIGHT
)
1781 dw
= event
.xmotion
.x_root
- orig_x
;
1783 dh
= orig_y
- event
.xmotion
.y_root
;
1784 else if (res
& DOWN
)
1785 dh
= event
.xmotion
.y_root
- orig_y
;
1787 orig_x
= event
.xmotion
.x_root
;
1788 orig_y
= event
.xmotion
.y_root
;
1793 fh
= rh
- vert_border
;
1794 wWindowConstrainSize(wwin
, &fw
, &fh
);
1798 else if (res
& RIGHT
)
1802 else if (res
& DOWN
)
1804 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1805 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1810 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
1811 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
1813 /* check if resizing through resizebar */
1819 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
1820 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
1821 flags
|= HCONSTRAIN
;
1823 res
= getResizeDirection(wwin
, tx
, ty
,
1824 orig_x
- event
.xmotion
.x_root
,
1825 orig_y
- event
.xmotion
.y_root
, flags
);
1827 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1828 | ButtonReleaseMask
| ButtonPressMask
,
1829 wCursor
[WCUR_RESIZE
], CurrentTime
);
1830 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1835 /* Draw the resize frame for the first time. */
1836 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
1838 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1840 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1845 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
1846 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
1848 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
1849 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1851 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
1853 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1855 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
1856 if (wPreferences
.size_display
== WDIS_NEW
) {
1857 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
1858 orig_fy
+ orig_fh
, res
);
1860 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1869 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1873 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1875 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1877 XUngrabKeyboard(dpy
, CurrentTime
);
1878 unmapGeometryDisplay(wwin
);
1881 if (wwin
->client
.width
!= fw
)
1882 wwin
->flags
.user_changed_width
= 1;
1884 if (wwin
->client
.height
!= fh
- vert_border
)
1885 wwin
->flags
.user_changed_height
= 1;
1887 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
1890 puts("End resize window");
1895 WMHandleEvent(&event
);
1910 wUnselectWindows(WScreen
*scr
)
1914 while (scr
->selected_windows
) {
1915 wwin
= scr
->selected_windows
->head
;
1916 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
1917 wIconSelect(wwin
->icon
);
1919 wSelectWindow(wwin
, False
);
1925 selectWindowsInside(WScreen
*scr
, int x1
, int y1
, int x2
, int y2
)
1929 /* select the windows and put them in the selected window list */
1930 tmpw
= scr
->focused_window
;
1931 while (tmpw
!= NULL
) {
1932 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
1933 if ((tmpw
->frame
->workspace
== scr
->current_workspace
1934 || IS_OMNIPRESENT(tmpw
))
1935 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
1936 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
1937 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
1938 wSelectWindow(tmpw
, True
);
1947 wSelectWindows(WScreen
*scr
, XEvent
*ev
)
1950 Window root
= scr
->root_win
;
1951 GC gc
= scr
->frame_gc
;
1952 int xp
= ev
->xbutton
.x_root
;
1953 int yp
= ev
->xbutton
.y_root
;
1958 puts("Selecting windows");
1960 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
1961 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
1962 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
],
1963 CurrentTime
) != Success
) {
1968 wUnselectWindows(scr
);
1970 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
1972 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
1973 | ButtonPressMask
, &event
);
1975 switch (event
.type
) {
1977 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
1978 x
= event
.xmotion
.x_root
;
1985 y
= event
.xmotion
.y_root
;
1992 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
1999 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2002 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2004 XUngrabPointer(dpy
, CurrentTime
);
2005 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
2008 wKWMSelectRootRegion(scr
, x
, y
, w
, h
,
2009 event
.xbutton
.state
& ControlMask
);
2010 #endif /* KWM_HINTS */
2013 puts("End window selection");
2018 WMHandleEvent(&event
);
2026 InteractivePlaceWindow(WWindow
*wwin
, int *x_ret
, int *y_ret
,
2027 unsigned width
, unsigned height
)
2029 WScreen
*scr
= wwin
->screen_ptr
;
2030 Window root
= scr
->root_win
;
2033 KeyCode shiftl
, shiftr
;
2037 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2038 GrabModeAsync
, GrabModeAsync
, None
,
2039 wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2044 if (!WFLAGP(wwin
, no_titlebar
)) {
2045 h
= scr
->title_font
->height
+ TITLEBAR_EXTRA_HEIGHT
;
2048 if (!WFLAGP(wwin
, no_resizebar
)) {
2049 height
+= RESIZEBAR_HEIGHT
;
2051 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2052 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
,
2053 (unsigned *) &junk
);
2054 mapPositionDisplay(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2056 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2058 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2059 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2061 WMMaskEvent(dpy
, PointerMotionMask
|ButtonPressMask
|ExposureMask
|KeyPressMask
,
2063 switch (event
.type
) {
2065 if ((event
.xkey
.keycode
== shiftl
)
2066 || (event
.xkey
.keycode
== shiftr
)) {
2067 drawTransparentFrame(wwin
,
2068 x
- width
/2, y
- h
/2, width
, height
);
2069 cyclePositionDisplay(wwin
,
2070 x
- width
/2, y
- h
/2, width
, height
);
2071 drawTransparentFrame(wwin
,
2072 x
- width
/2, y
- h
/2, width
, height
);
2077 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2079 x
= event
.xmotion
.x_root
;
2080 y
= event
.xmotion
.y_root
;
2082 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2083 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2085 showPosition(wwin
, x
- width
/2, y
- h
/2);
2087 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2092 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2094 *x_ret
= x
- width
/2;
2096 XUngrabPointer(dpy
, CurrentTime
);
2097 XUngrabKeyboard(dpy
, CurrentTime
);
2098 /* get rid of the geometry window */
2099 unmapPositionDisplay(wwin
);
2103 WMHandleEvent(&event
);