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
);
179 showPosition(wwin
, x
, y
);
185 mapPositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
187 WScreen
*scr
= wwin
->screen_ptr
;
189 if (wPreferences
.move_display
== WDIS_NEW
) {
191 } else if (wPreferences
.move_display
== WDIS_CENTER
) {
192 moveGeometryDisplayCentered(scr
, scr
->scr_width
/ 2,
193 scr
->scr_height
/ 2);
194 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
195 moveGeometryDisplayCentered(scr
, 1, 1);
196 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
197 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
199 XMapRaised(dpy
, scr
->geometry_display
);
200 showPosition(wwin
, x
, y
);
203 #define unmapPositionDisplay(w) \
204 XUnmapWindow(dpy, (w)->screen_ptr->geometry_display);
208 showGeometry(WWindow
*wwin
, int x1
, int y1
, int x2
, int y2
, int direction
)
210 WScreen
*scr
= wwin
->screen_ptr
;
211 Window root
= scr
->root_win
;
212 GC gc
= scr
->line_gc
;
213 int ty
, by
, my
, x
, y
, mx
, s
;
218 ty
= y1
+ wwin
->frame
->top_width
;
219 by
= y2
- wwin
->frame
->bottom_width
;
220 fw
= wTextWidth(scr
->info_text_font
->font
, "8888", 4);
221 fh
= scr
->info_text_font
->height
;
223 if (wPreferences
.size_display
== WDIS_NEW
) {
224 XSetForeground(dpy
, gc
, scr
->line_pixel
);
226 /* vertical geometry */
227 if (((direction
& LEFT
) && (x2
< scr
->scr_width
- fw
)) || (x1
< fw
)) {
238 segment
[0].x1
= x
- (s
+ 6); segment
[0].y1
= ty
;
239 segment
[0].x2
= x
- (s
- 10); segment
[0].y2
= ty
;
242 segment
[1].x1
= x
- (s
- 2); segment
[1].y1
= ty
+ 1;
243 segment
[1].x2
= x
- (s
- 5); segment
[1].y2
= ty
+ 7;
245 segment
[2].x1
= x
- (s
- 2); segment
[2].y1
= ty
+ 1;
246 segment
[2].x2
= x
- (s
+ 1); segment
[2].y2
= ty
+ 7;
249 segment
[3].x1
= x
- (s
- 2); segment
[3].y1
= ty
+ 1;
250 segment
[3].x2
= x
- (s
- 2); segment
[3].y2
= my
- fh
/2 - 1;
252 XDrawSegments(dpy
, root
, gc
, segment
, 4);
260 segment
[1].y1
= by
- 1;
261 segment
[1].y2
= by
- 7;
263 segment
[2].y1
= by
- 1;
264 segment
[2].y2
= by
- 7;
267 segment
[3].y1
= my
+ fh
/2 + 2;
268 segment
[3].y2
= by
- 1;
270 XDrawSegments(dpy
, root
, gc
, segment
, 4);
272 sprintf(num
, "%i", (by
- ty
- wwin
->normal_hints
->base_height
) /
273 wwin
->normal_hints
->height_inc
);
274 fw
= wTextWidth(scr
->info_text_font
->font
, num
, strlen(num
));
276 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
278 /* Display the height. */
279 wDrawString(root
, scr
->info_text_font
, gc
,
280 x
- s
+ 3 - fw
/2, my
- fh
/2 + scr
->info_text_font
->y
+ 1,
282 XSetForeground(dpy
, gc
, scr
->line_pixel
);
283 /* horizontal geometry */
291 mx
= x1
+ (x2
- x1
)/2;
292 sprintf(num
, "%i", (x2
- x1
- wwin
->normal_hints
->base_width
) /
293 wwin
->normal_hints
->width_inc
);
294 fw
= wTextWidth(scr
->info_text_font
->font
, num
, strlen(num
));
298 segment
[0].x1
= x1
; segment
[0].y1
= y
- (s
+ 6);
299 segment
[0].x2
= x1
; segment
[0].y2
= y
- (s
- 10);
302 segment
[1].x1
= x1
+ 7; segment
[1].y1
= y
- (s
+ 1);
303 segment
[1].x2
= x1
+ 1; segment
[1].y2
= y
- (s
- 2);
305 segment
[2].x1
= x1
+ 1; segment
[2].y1
= y
- (s
- 2);
306 segment
[2].x2
= x1
+ 7; segment
[2].y2
= y
- (s
- 5);
309 segment
[3].x1
= x1
+ 1; segment
[3].y1
= y
- (s
- 2);
310 segment
[3].x2
= mx
- fw
/2 - 2; segment
[3].y2
= y
- (s
- 2);
312 XDrawSegments(dpy
, root
, gc
, segment
, 4);
316 segment
[0].x1
= x2
+ 1;
317 segment
[0].x2
= x2
+ 1;
320 segment
[1].x1
= x2
- 6;
324 segment
[2].x2
= x2
- 6;
327 segment
[3].x1
= mx
+ fw
/2 + 2;
330 XDrawSegments(dpy
, root
, gc
, segment
, 4);
332 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
334 /* Display the width. */
335 wDrawString(root
, scr
->info_text_font
, gc
,
336 mx
- fw
/2 + 1, y
- s
+ fh
/2 + 1, num
, strlen(num
));
338 XClearArea(dpy
, scr
->geometry_display
, 1, 1,
339 scr
->geometry_display_width
-2, scr
->geometry_display_height
-2,
341 sprintf(num
, "%i x %-i", (x2
- x1
- wwin
->normal_hints
->base_width
)
342 / wwin
->normal_hints
->width_inc
,
343 (by
- ty
- wwin
->normal_hints
->base_height
)
344 / wwin
->normal_hints
->height_inc
);
345 fw
= wTextWidth(scr
->info_text_font
->font
, num
, strlen(num
));
347 XSetForeground(dpy
, scr
->info_text_gc
, scr
->black_pixel
);
349 /* Display the height. */
350 wDrawString(scr
->geometry_display
, scr
->info_text_font
,
352 (scr
->geometry_display_width
-fw
)/2,
353 (scr
->geometry_display_height
-fh
)/2 +scr
->info_text_font
->y
,
355 wDrawBevel(scr
->geometry_display
, scr
->geometry_display_width
+1,
356 scr
->geometry_display_height
+1,
357 scr
->widget_texture
, WREL_RAISED
);
363 cycleGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
, int dir
)
365 WScreen
*scr
= wwin
->screen_ptr
;
367 wPreferences
.size_display
++;
368 wPreferences
.size_display
%= NUM_DISPLAYS
;
370 if (wPreferences
.size_display
== WDIS_NEW
) {
371 XUnmapWindow(dpy
, scr
->geometry_display
);
373 if (wPreferences
.size_display
== WDIS_CENTER
) {
374 moveGeometryDisplayCentered(scr
,
375 scr
->scr_width
/ 2, scr
->scr_height
/ 2);
376 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
377 moveGeometryDisplayCentered(scr
, 1, 1);
378 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
379 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
381 XMapRaised(dpy
, scr
->geometry_display
);
382 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, dir
);
388 mapGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
390 WScreen
*scr
= wwin
->screen_ptr
;
392 if (wPreferences
.size_display
== WDIS_NEW
)
395 if (wPreferences
.size_display
== WDIS_CENTER
) {
396 moveGeometryDisplayCentered(scr
, scr
->scr_width
/ 2,
397 scr
->scr_height
/ 2);
398 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
399 moveGeometryDisplayCentered(scr
, 1, 1);
400 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
401 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
403 XMapRaised(dpy
, scr
->geometry_display
);
404 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, 0);
407 #define unmapGeometryDisplay(w) \
408 XUnmapWindow(dpy, (w)->screen_ptr->geometry_display);
412 doWindowMove(WWindow
*wwin
, LinkedList
*list
, int dx
, int dy
)
416 int scr_width
= wwin
->screen_ptr
->scr_width
;
417 int scr_height
= wwin
->screen_ptr
->scr_height
;
420 wWindowMove(wwin
, wwin
->frame_x
+ dx
, wwin
->frame_y
+ dy
);
424 x
= tmpw
->frame_x
+ dx
;
425 y
= tmpw
->frame_y
+ dy
;
427 /* don't let windows become unreachable */
429 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
430 x
= 20 - (int)tmpw
->frame
->core
->width
;
431 else if (x
+ 20 > scr_width
)
434 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
435 y
= 20 - (int)tmpw
->frame
->core
->height
;
436 else if (y
+ 20 > scr_height
)
439 wWindowMove(tmpw
, x
, y
);
447 drawTransparentFrame(WWindow
*wwin
, int x
, int y
, int width
, int height
)
449 Window root
= wwin
->screen_ptr
->root_win
;
450 GC gc
= wwin
->screen_ptr
->frame_gc
;
454 if (!WFLAGP(wwin
, no_titlebar
) && !wwin
->flags
.shaded
) {
455 h
= wwin
->screen_ptr
->title_font
->height
+ TITLEBAR_EXTRA_HEIGHT
;
457 if (!WFLAGP(wwin
, no_resizebar
) && !wwin
->flags
.shaded
) {
458 /* Can't use wwin-frame->bottom_width because, in some cases
459 (e.g. interactive placement), frame does not point to anything. */
460 bottom
= RESIZEBAR_HEIGHT
- 1;
462 XDrawRectangle(dpy
, root
, gc
, x
, y
, width
+ 1, height
+ 1);
465 XDrawLine(dpy
, root
, gc
, x
+ 1, y
+ h
, x
+ width
+ 1, y
+ h
);
468 XDrawLine(dpy
, root
, gc
, x
+ 1,
471 y
+ height
- bottom
);
477 drawFrames(WWindow
*wwin
, LinkedList
*list
, int dx
, int dy
)
480 int scr_width
= wwin
->screen_ptr
->scr_width
;
481 int scr_height
= wwin
->screen_ptr
->scr_height
;
486 x
= wwin
->frame_x
+ dx
;
487 y
= wwin
->frame_y
+ dy
;
489 drawTransparentFrame(wwin
, x
, y
,
490 wwin
->frame
->core
->width
,
491 wwin
->frame
->core
->height
);
496 x
= tmpw
->frame_x
+ dx
;
497 y
= tmpw
->frame_y
+ dy
;
499 /* don't let windows become unreachable */
501 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
502 x
= 20 - (int)tmpw
->frame
->core
->width
;
503 else if (x
+ 20 > scr_width
)
506 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
507 y
= 20 - (int)tmpw
->frame
->core
->height
;
508 else if (y
+ 20 > scr_height
)
511 drawTransparentFrame(tmpw
, x
, y
, tmpw
->frame
->core
->width
,
512 tmpw
->frame
->core
->height
);
527 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &ev
)) ;
532 crossWorkspace(WScreen
*scr
, WWindow
*wwin
, int opaque_move
,
533 int new_workspace
, int rewind
)
535 /* do not let window be unmapped */
537 wwin
->flags
.changing_workspace
= 1;
538 wWindowChangeWorkspace(wwin
, new_workspace
);
540 /* go to new workspace */
541 wWorkspaceChange(scr
, new_workspace
);
543 wwin
->flags
.changing_workspace
= 0;
546 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, scr
->scr_width
- 20, 0);
548 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, -(scr
->scr_width
- 20), 0);
553 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
554 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
555 GrabModeAsync
, None
, wCursor
[WCUR_MOVE
], CurrentTime
);
563 /* arrays of WWindows sorted by the respective border position */
564 WWindow
**topList
; /* top border */
565 WWindow
**leftList
; /* left border */
566 WWindow
**rightList
; /* right border */
567 WWindow
**bottomList
; /* bottom border */
570 /* index of window in the above lists indicating the relative position
571 * of the window with the others */
577 int rubCount
; /* for workspace switching */
579 int winWidth
, winHeight
; /* width/height of the window */
580 int realX
, realY
; /* actual position of the window */
581 int calcX
, calcY
; /* calculated position of window */
582 int omouseX
, omouseY
; /* old mouse position */
583 int mouseX
, mouseY
; /* last known position of the pointer */
586 #define WTOP(w) (w)->frame_y
587 #define WLEFT(w) (w)->frame_x
588 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width + FRAME_BORDER_WIDTH)
589 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height + FRAME_BORDER_WIDTH)
592 compareWTop(const void *a
, const void *b
)
594 WWindow
*wwin1
= *(WWindow
**)a
;
595 WWindow
*wwin2
= *(WWindow
**)b
;
597 if (WTOP(wwin1
) > WTOP(wwin2
))
599 else if (WTOP(wwin1
) < WTOP(wwin2
))
607 compareWLeft(const void *a
, const void *b
)
609 WWindow
*wwin1
= *(WWindow
**)a
;
610 WWindow
*wwin2
= *(WWindow
**)b
;
612 if (WLEFT(wwin1
) > WLEFT(wwin2
))
614 else if (WLEFT(wwin1
) < WLEFT(wwin2
))
622 compareWRight(const void *a
, const void *b
)
624 WWindow
*wwin1
= *(WWindow
**)a
;
625 WWindow
*wwin2
= *(WWindow
**)b
;
627 if (WRIGHT(wwin1
) < WRIGHT(wwin2
))
629 else if (WRIGHT(wwin1
) > WRIGHT(wwin2
))
638 compareWBottom(const void *a
, const void *b
)
640 WWindow
*wwin1
= *(WWindow
**)a
;
641 WWindow
*wwin2
= *(WWindow
**)b
;
643 if (WBOTTOM(wwin1
) < WBOTTOM(wwin2
))
645 else if (WBOTTOM(wwin1
) > WBOTTOM(wwin2
))
653 updateResistance(WWindow
*wwin
, MoveData
*data
, int newX
, int newY
)
656 int newX2
= newX
+ data
->winWidth
;
657 int newY2
= newY
+ data
->winHeight
;
660 if (newX
< data
->realX
) {
661 if (data
->rightIndex
> 0
662 && newX
< WRIGHT(data
->rightList
[data
->rightIndex
-1])) {
664 } else if (data
->leftIndex
<= data
->count
-1
665 && newX2
<= WLEFT(data
->leftList
[data
->leftIndex
])) {
668 } else if (newX
> data
->realX
) {
669 if (data
->leftIndex
> 0
670 && newX2
> WLEFT(data
->leftList
[data
->leftIndex
-1])) {
672 } else if (data
->rightIndex
<= data
->count
-1
673 && newX
>= WRIGHT(data
->rightList
[data
->rightIndex
])) {
679 if (newY
< data
->realY
) {
680 if (data
->bottomIndex
> 0
681 && newY
< WBOTTOM(data
->bottomList
[data
->bottomIndex
-1])) {
683 } else if (data
->topIndex
<= data
->count
-1
684 && newY2
<= WTOP(data
->topList
[data
->topIndex
])) {
687 } else if (newY
> data
->realY
) {
688 if (data
->topIndex
> 0
689 && newY2
> WTOP(data
->topList
[data
->topIndex
-1])) {
691 } else if (data
->bottomIndex
<= data
->count
-1
692 && newY
>= WBOTTOM(data
->bottomList
[data
->bottomIndex
])) {
701 /* TODO: optimize this */
702 if (data
->realY
< WBOTTOM(data
->bottomList
[0])) {
703 data
->bottomIndex
= 0;
705 if (data
->realX
< WRIGHT(data
->rightList
[0])) {
706 data
->rightIndex
= 0;
708 if ((data
->realX
+ data
->winWidth
) > WLEFT(data
->leftList
[0])) {
711 if ((data
->realY
+ data
->winHeight
) > WTOP(data
->topList
[0])) {
714 for (i
= 0; i
< data
->count
; i
++) {
715 if (data
->realY
> WBOTTOM(data
->bottomList
[i
])) {
716 data
->bottomIndex
= i
+ 1;
718 if (data
->realX
> WRIGHT(data
->rightList
[i
])) {
719 data
->rightIndex
= i
+ 1;
721 if ((data
->realX
+ data
->winWidth
) < WLEFT(data
->leftList
[i
])) {
722 data
->leftIndex
= i
+ 1;
724 if ((data
->realY
+ data
->winHeight
) < WTOP(data
->topList
[i
])) {
725 data
->topIndex
= i
+ 1;
732 freeMoveData(MoveData
*data
)
737 free(data
->leftList
);
739 free(data
->rightList
);
740 if (data
->bottomList
)
741 free(data
->bottomList
);
746 updateMoveData(WWindow
*wwin
, MoveData
*data
)
748 WScreen
*scr
= wwin
->screen_ptr
;
753 tmp
= scr
->focused_window
;
755 if (tmp
!= wwin
&& scr
->current_workspace
== tmp
->frame
->workspace
756 && !tmp
->flags
.miniaturized
757 && !tmp
->flags
.hidden
758 && !tmp
->flags
.obscured
) {
759 data
->topList
[data
->count
] = tmp
;
760 data
->leftList
[data
->count
] = tmp
;
761 data
->rightList
[data
->count
] = tmp
;
762 data
->bottomList
[data
->count
] = tmp
;
768 if (data
->count
== 0) {
771 data
->rightIndex
= 0;
772 data
->bottomIndex
= 0;
777 * order from closest to the border of the screen to farthest
779 qsort(data
->topList
, data
->count
, sizeof(WWindow
**), compareWTop
);
780 qsort(data
->leftList
, data
->count
, sizeof(WWindow
**), compareWLeft
);
781 qsort(data
->rightList
, data
->count
, sizeof(WWindow
**), compareWRight
);
782 qsort(data
->bottomList
, data
->count
, sizeof(WWindow
**), compareWBottom
);
784 /* figure the position of the window relative to the others */
787 data
->leftIndex
= -1;
788 data
->rightIndex
= -1;
789 data
->bottomIndex
= -1;
791 if (WTOP(wwin
) < WBOTTOM(data
->bottomList
[0])) {
792 data
->bottomIndex
= 0;
794 if (WLEFT(wwin
) < WRIGHT(data
->rightList
[0])) {
795 data
->rightIndex
= 0;
797 if (WRIGHT(wwin
) > WLEFT(data
->leftList
[0])) {
800 if (WBOTTOM(wwin
) > WTOP(data
->topList
[0])) {
803 for (i
= 0; i
< data
->count
; i
++) {
804 if (WTOP(wwin
) >= WBOTTOM(data
->bottomList
[i
])) {
805 data
->bottomIndex
= i
+ 1;
807 if (WLEFT(wwin
) >= WRIGHT(data
->rightList
[i
])) {
808 data
->rightIndex
= i
+ 1;
810 if (WRIGHT(wwin
) <= WLEFT(data
->leftList
[i
])) {
811 data
->leftIndex
= i
+ 1;
813 if (WBOTTOM(wwin
) <= WTOP(data
->topList
[i
])) {
814 data
->topIndex
= i
+ 1;
821 initMoveData(WWindow
*wwin
, MoveData
*data
)
826 memset(data
, 0, sizeof(MoveData
));
828 for (i
= 0, tmp
= wwin
->screen_ptr
->focused_window
;
830 tmp
= tmp
->prev
, i
++);
833 data
->topList
= wmalloc(sizeof(WWindow
*) * i
);
834 data
->leftList
= wmalloc(sizeof(WWindow
*) * i
);
835 data
->rightList
= wmalloc(sizeof(WWindow
*) * i
);
836 data
->bottomList
= wmalloc(sizeof(WWindow
*) * i
);
838 updateMoveData(wwin
, data
);
841 data
->realX
= wwin
->frame_x
;
842 data
->realY
= wwin
->frame_y
;
843 data
->calcX
= wwin
->frame_x
;
844 data
->calcY
= wwin
->frame_y
;
846 data
->winWidth
= wwin
->frame
->core
->width
+ 2;
847 data
->winHeight
= wwin
->frame
->core
->height
+ 2;
852 checkWorkspaceChange(WWindow
*wwin
, MoveData
*data
, Bool opaqueMove
)
854 WScreen
*scr
= wwin
->screen_ptr
;
855 Bool changed
= False
;
857 if (data
->mouseX
<= 1) {
858 if (scr
->current_workspace
> 0) {
860 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
- 1,
865 } else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
) {
867 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->workspace_count
- 1,
872 } else if (data
->mouseX
>= scr
->scr_width
- 2) {
874 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
876 if (wPreferences
.ws_cycle
877 || scr
->workspace_count
== MAX_WORKSPACES
) {
879 crossWorkspace(scr
, wwin
, opaqueMove
, 0, False
);
883 /* if user insists on trying to go to next workspace even when
884 * it's already the last, create a new one */
885 else if (data
->omouseX
== data
->mouseX
886 && wPreferences
.ws_advance
) {
888 /* detect user "rubbing" the window against the edge */
889 if (data
->rubCount
> 0
890 && data
->omouseY
- data
->mouseY
> MOVE_THRESHOLD
) {
892 data
->rubCount
= -(data
->rubCount
+ 1);
894 } else if (data
->rubCount
<= 0
895 && data
->mouseY
- data
->omouseY
> MOVE_THRESHOLD
) {
897 data
->rubCount
= -data
->rubCount
+ 1;
900 /* create a new workspace */
901 if (abs(data
->rubCount
) > 2) {
902 /* go to next workspace */
905 crossWorkspace(scr
, wwin
, opaqueMove
,
906 scr
->current_workspace
+1, False
);
910 } else if (scr
->current_workspace
< scr
->workspace_count
) {
912 /* go to next workspace */
913 crossWorkspace(scr
, wwin
, opaqueMove
,
914 scr
->current_workspace
+1, False
);
927 updateWindowPosition(WWindow
*wwin
, MoveData
*data
, Bool doResistance
,
928 Bool opaqueMove
, int newMouseX
, int newMouseY
)
930 WScreen
*scr
= wwin
->screen_ptr
;
931 int dx
, dy
; /* how much mouse moved */
932 int winL
, winR
, winT
, winB
; /* requested new window position */
933 int newX
, newY
; /* actual new window position */
934 Bool hresist
, vresist
;
942 /* check the direction of the movement */
943 dx
= newMouseX
- data
->mouseX
;
944 dy
= newMouseY
- data
->mouseY
;
946 data
->omouseX
= data
->mouseX
;
947 data
->omouseY
= data
->mouseY
;
948 data
->mouseX
= newMouseX
;
949 data
->mouseY
= newMouseY
;
951 winL
= data
->calcX
+ dx
;
952 winR
= data
->calcX
+ data
->winWidth
+ dx
;
953 winT
= data
->calcY
+ dy
;
954 winB
= data
->calcY
+ data
->winHeight
+ dy
;
964 resist
= wPreferences
.edge_resistance
;
965 /* horizontal movement: check horizontal edge resistances */
967 /* window is the leftmost window: check against screen edge */
968 edge
= scr
->totalUsableArea
.x1
;
970 /* check position of nearest window to the left */
971 if (data
->rightIndex
> 0) {
972 /* there is some window at the left: check if it will block
974 rwin
= data
->rightList
[data
->rightIndex
- 1];
976 if (data
->realY
> WBOTTOM(rwin
)
977 || (data
->realY
+ data
->winHeight
) < WTOP(rwin
)) {
980 edge
= WRIGHT(rwin
) + 1;
981 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
984 if (resist
> 0 && winL
>= edge
- resist
&& winL
<= edge
) {
989 /* window is the rightmost window: check against screen edge */
990 edge
= scr
->totalUsableArea
.x2
;
992 /* check position of nearest window to the right */
993 if (data
->leftIndex
> 0) {
994 /* there is some window at the right: check if it will block
996 rwin
= data
->leftList
[data
->leftIndex
- 1];
998 if (data
->realY
> WBOTTOM(rwin
)
999 || (data
->realY
+ data
->winHeight
) < WTOP(rwin
)) {
1003 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1006 if (resist
> 0 && winR
<= edge
+ resist
&& winR
>= edge
) {
1007 newX
= edge
- data
->winWidth
;
1012 resist
= wPreferences
.edge_resistance
;
1013 /* vertical movement: check vertical edge resistances */
1015 /* window is the topmost window: check against screen edge */
1016 edge
= scr
->totalUsableArea
.y1
;
1018 /* check position of nearest window to the top */
1019 if (data
->bottomIndex
> 0) {
1020 /* there is some window at the top: check if it will block
1022 rwin
= data
->bottomList
[data
->bottomIndex
- 1];
1024 if (data
->realX
> WRIGHT(rwin
)
1025 || (data
->realX
+ data
->winWidth
) < WLEFT(rwin
)) {
1028 edge
= WBOTTOM(rwin
) + 1;
1029 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1032 if (resist
> 0 && winT
>= edge
- resist
&& winT
<= edge
) {
1036 } else if (dy
> 0) {
1037 /* window is the bottommost window: check against screen edge */
1038 edge
= scr
->totalUsableArea
.y2
;
1040 /* check position of nearest window to the bottom */
1041 if (data
->topIndex
> 0) {
1042 /* there is some window at the bottom: check if it will block
1044 rwin
= data
->topList
[data
->topIndex
- 1];
1046 if (data
->realX
> WRIGHT(rwin
)
1047 || (data
->realX
+ data
->winWidth
) < WLEFT(rwin
)) {
1051 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1054 if (resist
> 0 && winB
<= edge
+ resist
&& winB
>= edge
) {
1055 newY
= edge
- data
->winHeight
;
1061 /* update window position */
1065 if (((dx
> 0 && data
->calcX
- data
->realX
> 0)
1066 || (dx
< 0 && data
->calcX
- data
->realX
< 0)) && !hresist
)
1069 if (((dy
> 0 && data
->calcY
- data
->realY
> 0)
1070 || (dy
< 0 && data
->calcY
- data
->realY
< 0)) && !vresist
)
1073 if (data
->realX
!= newX
|| data
->realY
!= newY
) {
1075 doWindowMove(wwin
, scr
->selected_windows
,
1076 newX
- wwin
->frame_x
,
1077 newY
- wwin
->frame_y
);
1080 drawFrames(wwin
, scr
->selected_windows
,
1081 data
->realX
- wwin
->frame_x
,
1082 data
->realY
- wwin
->frame_y
);
1085 if (!scr
->selected_windows
1086 && wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
1088 moveGeometryDisplayCentered(scr
, newX
+ data
->winWidth
/2,
1089 newY
+ data
->winHeight
/2);
1094 drawFrames(wwin
, scr
->selected_windows
,
1095 newX
- wwin
->frame_x
,
1096 newY
- wwin
->frame_y
);
1099 if (!scr
->selected_windows
) {
1101 if (wPreferences
.move_display
== WDIS_NEW
) {
1103 showPosition(wwin
, data
->realX
, data
->realY
);
1106 showPosition(wwin
, newX
, newY
);
1111 /* recalc relative window position */
1112 if (doResistance
&& (data
->realX
!= newX
|| data
->realY
!= newY
)) {
1113 updateResistance(wwin
, data
, newX
, newY
);
1121 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1124 wKeyboardMoveResizeWindow(WWindow
*wwin
)
1126 WScreen
*scr
= wwin
->screen_ptr
;
1127 Window root
= scr
->root_win
;
1129 int w
= wwin
->frame
->core
->width
;
1130 int h
= wwin
->frame
->core
->height
;
1131 int scr_width
= wwin
->screen_ptr
->scr_width
;
1132 int scr_height
= wwin
->screen_ptr
->scr_height
;
1133 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1134 int src_x
= wwin
->frame_x
;
1135 int src_y
= wwin
->frame_y
;
1136 int done
,off_x
,off_y
,ww
,wh
;
1139 KeySym keysym
=NoSymbol
;
1141 KeyCode shiftl
,shiftr
,ctrll
,ctrlmode
;
1143 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1144 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1145 ctrll
= XKeysymToKeycode(dpy
, XK_Control_L
);
1146 ctrlmode
=done
=off_x
=off_y
=0;
1150 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1152 if (!wwin
->flags
.selected
) {
1153 wUnselectWindows(scr
);
1156 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1157 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
1158 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
);
1160 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1161 if(scr
->selected_windows
)
1162 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1163 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1164 if(!scr
->selected_windows
)
1165 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1167 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1176 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1177 | ButtonPressMask
| ExposureMask
, &event
);
1178 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1179 if(scr
->selected_windows
)
1180 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1181 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1182 /*** I HATE EDGE RESISTANCE - ]d ***/
1185 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1189 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1194 switch (event
.type
) {
1197 if (event
.xkey
.time
- lastTime
> 50) {
1198 kspeed
/=(1 + (event
.xkey
.time
- lastTime
)/100);
1204 if (kspeed
< _KS
) kspeed
= _KS
;
1205 lastTime
= event
.xkey
.time
;
1207 if (event
.xkey
.state
& ControlMask
&& !wwin
->flags
.shaded
) {
1209 wUnselectWindows(scr
);
1214 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
) {
1216 cycleGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
, 0);
1218 cyclePositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1222 keysym
= XLookupKeysym(&event
.xkey
, 0);
1269 if (moment
!= RIGHT
)
1280 wWindowConstrainSize(wwin
, &ww
, &wh
);
1283 if (wPreferences
.ws_cycle
){
1284 if (src_x
+ off_x
+ ww
< 20){
1285 if(!scr
->current_workspace
) {
1286 wWorkspaceChange(scr
, scr
->workspace_count
-1);
1288 else wWorkspaceChange(scr
, scr
->current_workspace
-1);
1291 else if (src_x
+ off_x
+ 20 > scr_width
){
1292 if(scr
->current_workspace
== scr
->workspace_count
-1) {
1293 wWorkspaceChange(scr
, 0);
1295 else wWorkspaceChange(scr
, scr
->current_workspace
+1);
1300 if (src_x
+ off_x
+ ww
< 20)
1301 off_x
= 20 - ww
- src_x
;
1302 else if (src_x
+ off_x
+ 20 > scr_width
)
1303 off_x
= scr_width
- 20 - src_x
;
1306 if (src_y
+ off_y
+ wh
< 20) {
1307 off_y
= 20 - wh
- src_y
;
1309 else if (src_y
+ off_y
+ 20 > scr_height
) {
1310 off_y
= scr_height
- 20 - src_y
;
1319 WMHandleEvent(&event
);
1326 if (wwin
->flags
.shaded
&& !scr
->selected_windows
){
1327 moveGeometryDisplayCentered(scr
, src_x
+off_x
+ w
/2, src_y
+off_y
+ h
/2);
1331 unmapPositionDisplay(wwin
);
1332 mapGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1334 else if(!scr
->selected_windows
){
1335 unmapGeometryDisplay(wwin
);
1336 mapPositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1340 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1341 if(scr
->selected_windows
)
1342 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1343 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1346 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1351 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1353 else if(!scr
->selected_windows
)
1354 showPosition(wwin
, src_x
+off_x
, src_y
+off_y
);
1358 scr
->keymove_tick
=0;
1360 WMDeleteTimerWithClientData(&looper);
1362 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1363 if(scr
->selected_windows
)
1364 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1365 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1368 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);
1373 unmapGeometryDisplay(wwin
);
1376 unmapPositionDisplay(wwin
);
1377 XUngrabKeyboard(dpy
, CurrentTime
);
1378 XUngrabPointer(dpy
, CurrentTime
);
1382 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1384 list
=scr
->selected_windows
;
1385 if (!scr
->selected_windows
) {
1386 wWindowMove(wwin
, src_x
+off_x
, src_y
+off_y
);
1387 wWindowSynthConfigureNotify(wwin
);
1389 doWindowMove(wwin
,scr
->selected_windows
,off_x
,off_y
);
1391 wWindowSynthConfigureNotify(list
->head
);
1396 if (wwin
->client
.width
!= ww
)
1397 wwin
->flags
.user_changed_width
= 1;
1399 if (wwin
->client
.height
!= wh
- vert_border
)
1400 wwin
->flags
.user_changed_height
= 1;
1402 wWindowConfigure(wwin
, src_x
+off_x
, src_y
+off_y
,
1403 ww
, wh
- vert_border
);
1404 wWindowSynthConfigureNotify(wwin
);
1406 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1407 wSetFocusTo(scr
, wwin
);
1416 *----------------------------------------------------------------------
1417 * wMouseMoveWindow--
1418 * Move the named window and the other selected ones (if any),
1419 * interactively. Also shows the position of the window, if only one
1420 * window is being moved.
1421 * If the window is not on the selected window list, the selected
1422 * windows are deselected.
1423 * If shift is pressed during the operation, the position display
1424 * is changed to another type.
1427 * True if the window was moved, False otherwise.
1430 * The window(s) position is changed, and the client(s) are
1431 * notified about that.
1432 * The position display configuration may be changed.
1433 *----------------------------------------------------------------------
1436 wMouseMoveWindow(WWindow
*wwin
, XEvent
*ev
)
1438 WScreen
*scr
= wwin
->screen_ptr
;
1440 Window root
= scr
->root_win
;
1441 KeyCode shiftl
, shiftr
;
1444 /* This needs not to change while moving, else bad things can happen */
1445 int opaqueMove
= wPreferences
.opaque_move
;
1447 #ifdef GHOST_WINDOW_MOVE
1450 rimg
= InitGhostWindowMove(scr
);
1453 initMoveData(wwin
, &moveData
);
1455 moveData
.mouseX
= ev
->xmotion
.x_root
;
1456 moveData
.mouseY
= ev
->xmotion
.y_root
;
1458 if (!wwin
->flags
.selected
) {
1459 /* this window is not selected, unselect others and move only wwin */
1460 wUnselectWindows(scr
);
1463 puts("Moving window");
1465 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1466 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1472 /* XWarpPointer() doesn't seem to generate Motion events, so
1473 we've got to simulate them */
1474 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1475 &event
.xmotion
.y_root
, &junk
, &junk
,
1476 (unsigned *) &junk
);
1478 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1479 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
,
1482 if (event
.type
== MotionNotify
) {
1483 /* compress MotionNotify events */
1484 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1487 switch (event
.type
) {
1489 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1490 && started
&& !scr
->selected_windows
) {
1493 drawFrames(wwin
, scr
->selected_windows
,
1494 moveData
.realX
- wwin
->frame_x
,
1495 moveData
.realY
- wwin
->frame_y
);
1498 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1499 moveData
.winWidth
, moveData
.winHeight
);
1502 drawFrames(wwin
, scr
->selected_windows
,
1503 moveData
.realX
- wwin
->frame_x
,
1504 moveData
.realY
- wwin
->frame_y
);
1511 updateWindowPosition(wwin
, &moveData
,
1512 scr
->selected_windows
== NULL
1513 && wPreferences
.edge_resistance
> 0,
1515 event
.xmotion
.x_root
,
1516 event
.xmotion
.y_root
);
1518 if (!warped
&& !wPreferences
.no_autowrap
) {
1519 int oldWorkspace
= scr
->current_workspace
;
1522 drawFrames(wwin
, scr
->selected_windows
,
1523 moveData
.realX
- wwin
->frame_x
,
1524 moveData
.realY
- wwin
->frame_y
);
1526 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1527 if (scr
->current_workspace
!= oldWorkspace
1528 && wPreferences
.edge_resistance
> 0
1529 && scr
->selected_windows
== NULL
)
1530 updateMoveData(wwin
, &moveData
);
1535 drawFrames(wwin
, scr
->selected_windows
,
1536 moveData
.realX
- wwin
->frame_x
,
1537 moveData
.realY
- wwin
->frame_y
);
1542 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1543 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1545 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1546 | ButtonReleaseMask
| ButtonPressMask
,
1547 wCursor
[WCUR_MOVE
], CurrentTime
);
1549 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1552 if (!scr
->selected_windows
)
1553 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1554 moveData
.winWidth
, moveData
.winHeight
);
1556 if (started
&& !opaqueMove
)
1557 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1568 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1573 drawFrames(wwin
, scr
->selected_windows
,
1574 moveData
.realX
- wwin
->frame_x
,
1575 moveData
.realY
- wwin
->frame_y
);
1577 doWindowMove(wwin
, scr
->selected_windows
,
1578 moveData
.realX
- wwin
->frame_x
,
1579 moveData
.realY
- wwin
->frame_y
);
1581 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1582 wWindowSynthConfigureNotify(wwin
);
1584 XUngrabKeyboard(dpy
, CurrentTime
);
1587 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1588 wSetFocusTo(scr
, wwin
);
1590 if (wPreferences
.move_display
== WDIS_NEW
)
1591 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1593 if (!scr
->selected_windows
) {
1594 /* get rid of the geometry window */
1595 unmapPositionDisplay(wwin
);
1599 puts("End move window");
1601 freeMoveData(&moveData
);
1606 if (started
&& !opaqueMove
) {
1607 drawFrames(wwin
, scr
->selected_windows
,
1608 moveData
.realX
- wwin
->frame_x
,
1609 moveData
.realY
- wwin
->frame_y
);
1611 WMHandleEvent(&event
);
1614 drawFrames(wwin
, scr
->selected_windows
,
1615 moveData
.realX
- wwin
->frame_x
,
1616 moveData
.realY
- wwin
->frame_y
);
1618 WMHandleEvent(&event
);
1624 freeMoveData(&moveData
);
1631 #define HCONSTRAIN 2
1634 getResizeDirection(WWindow
*wwin
, int x
, int y
, int dx
, int dy
,
1637 int w
= wwin
->frame
->core
->width
- 1;
1638 int cw
= wwin
->frame
->resizebar_corner_width
;
1641 /* if not resizing through the resizebar */
1642 if (!(flags
& RESIZEBAR
)) {
1643 int xdir
= (abs(x
) < (wwin
->client
.width
/2)) ? LEFT
: RIGHT
;
1644 int ydir
= (abs(y
) < (wwin
->client
.height
/2)) ? UP
: DOWN
;
1645 if (abs(dx
) < 2 || abs(dy
) < 2) {
1646 if (abs(dy
) > abs(dx
))
1651 return (xdir
| ydir
);
1654 /* window is too narrow. allow diagonal resize */
1658 if (flags
& HCONSTRAIN
)
1663 return (LEFT
| ydir
);
1665 return (RIGHT
| ydir
);
1667 /* vertical resize */
1668 if ((x
> cw
) && (x
< w
- cw
))
1676 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1684 wMouseResizeWindow(WWindow
*wwin
, XEvent
*ev
)
1687 WScreen
*scr
= wwin
->screen_ptr
;
1688 Window root
= scr
->root_win
;
1689 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1690 int fw
= wwin
->frame
->core
->width
;
1691 int fh
= wwin
->frame
->core
->height
;
1692 int fx
= wwin
->frame_x
;
1693 int fy
= wwin
->frame_y
;
1694 int is_resizebar
= (wwin
->frame
->resizebar
1695 && ev
->xany
.window
==wwin
->frame
->resizebar
->window
);
1699 int rw
= fw
, rh
= fh
;
1700 int rx1
, ry1
, rx2
, ry2
;
1702 KeyCode shiftl
, shiftr
;
1709 if (wwin
->flags
.shaded
) {
1710 wwarning("internal error: tryein");
1713 orig_x
= ev
->xbutton
.x_root
;
1714 orig_y
= ev
->xbutton
.y_root
;
1718 puts("Resizing window");
1721 wUnselectWindows(scr
);
1726 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1727 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1728 if (!WFLAGP(wwin
, no_titlebar
))
1729 h
= wwin
->screen_ptr
->title_font
->height
+ TITLEBAR_EXTRA_HEIGHT
;
1733 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
| ButtonReleaseMask
1734 | ButtonPressMask
| ExposureMask
, &event
);
1735 switch (event
.type
) {
1737 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1738 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1740 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1741 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
1742 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1744 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1758 dw
= orig_x
- event
.xmotion
.x_root
;
1759 else if (res
& RIGHT
)
1760 dw
= event
.xmotion
.x_root
- orig_x
;
1762 dh
= orig_y
- event
.xmotion
.y_root
;
1763 else if (res
& DOWN
)
1764 dh
= event
.xmotion
.y_root
- orig_y
;
1766 orig_x
= event
.xmotion
.x_root
;
1767 orig_y
= event
.xmotion
.y_root
;
1772 fh
= rh
- vert_border
;
1773 wWindowConstrainSize(wwin
, &fw
, &fh
);
1777 else if (res
& RIGHT
)
1781 else if (res
& DOWN
)
1783 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1784 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1789 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
1790 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
1792 /* check if resizing through resizebar */
1798 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
1799 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
1800 flags
|= HCONSTRAIN
;
1802 res
= getResizeDirection(wwin
, tx
, ty
,
1803 orig_x
- event
.xmotion
.x_root
,
1804 orig_y
- event
.xmotion
.y_root
, flags
);
1806 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1807 | ButtonReleaseMask
| ButtonPressMask
,
1808 wCursor
[WCUR_RESIZE
], CurrentTime
);
1809 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1814 /* Draw the resize frame for the first time. */
1815 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
1817 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1819 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1824 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
1825 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
1827 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
1828 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1830 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
1832 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1834 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
1835 if (wPreferences
.size_display
== WDIS_NEW
) {
1836 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
1837 orig_fy
+ orig_fh
, res
);
1839 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1848 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1852 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1854 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1856 XUngrabKeyboard(dpy
, CurrentTime
);
1857 unmapGeometryDisplay(wwin
);
1860 if (wwin
->client
.width
!= fw
)
1861 wwin
->flags
.user_changed_width
= 1;
1863 if (wwin
->client
.height
!= fh
- vert_border
)
1864 wwin
->flags
.user_changed_height
= 1;
1866 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
1869 puts("End resize window");
1874 WMHandleEvent(&event
);
1889 wUnselectWindows(WScreen
*scr
)
1893 while (scr
->selected_windows
) {
1894 wwin
= scr
->selected_windows
->head
;
1895 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
1896 wIconSelect(wwin
->icon
);
1898 wSelectWindow(wwin
, False
);
1904 selectWindowsInside(WScreen
*scr
, int x1
, int y1
, int x2
, int y2
)
1908 /* select the windows and put them in the selected window list */
1909 tmpw
= scr
->focused_window
;
1910 while (tmpw
!= NULL
) {
1911 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
1912 if ((tmpw
->frame
->workspace
== scr
->current_workspace
1913 || IS_OMNIPRESENT(tmpw
))
1914 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
1915 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
1916 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
1917 wSelectWindow(tmpw
, True
);
1926 wSelectWindows(WScreen
*scr
, XEvent
*ev
)
1929 Window root
= scr
->root_win
;
1930 GC gc
= scr
->frame_gc
;
1931 int xp
= ev
->xbutton
.x_root
;
1932 int yp
= ev
->xbutton
.y_root
;
1937 puts("Selecting windows");
1939 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
1940 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
1941 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
],
1942 CurrentTime
) != Success
) {
1947 wUnselectWindows(scr
);
1949 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
1951 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
1952 | ButtonPressMask
, &event
);
1954 switch (event
.type
) {
1956 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
1957 x
= event
.xmotion
.x_root
;
1964 y
= event
.xmotion
.y_root
;
1971 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
1978 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1981 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
1983 XUngrabPointer(dpy
, CurrentTime
);
1984 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
1987 wKWMSelectRootRegion(scr
, x
, y
, w
, h
,
1988 event
.xbutton
.state
& ControlMask
);
1989 #endif /* KWM_HINTS */
1992 puts("End window selection");
1997 WMHandleEvent(&event
);
2005 InteractivePlaceWindow(WWindow
*wwin
, int *x_ret
, int *y_ret
,
2006 unsigned width
, unsigned height
)
2008 WScreen
*scr
= wwin
->screen_ptr
;
2009 Window root
= scr
->root_win
;
2012 KeyCode shiftl
, shiftr
;
2016 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2017 GrabModeAsync
, GrabModeAsync
, None
,
2018 wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2023 if (!WFLAGP(wwin
, no_titlebar
)) {
2024 h
= scr
->title_font
->height
+ TITLEBAR_EXTRA_HEIGHT
;
2027 if (!WFLAGP(wwin
, no_resizebar
)) {
2028 height
+= RESIZEBAR_HEIGHT
;
2030 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2031 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
,
2032 (unsigned *) &junk
);
2033 mapPositionDisplay(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2035 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2037 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2038 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2040 WMMaskEvent(dpy
, PointerMotionMask
|ButtonPressMask
|ExposureMask
|KeyPressMask
,
2042 switch (event
.type
) {
2044 if ((event
.xkey
.keycode
== shiftl
)
2045 || (event
.xkey
.keycode
== shiftr
)) {
2046 drawTransparentFrame(wwin
,
2047 x
- width
/2, y
- h
/2, width
, height
);
2048 cyclePositionDisplay(wwin
,
2049 x
- width
/2, y
- h
/2, width
, height
);
2050 drawTransparentFrame(wwin
,
2051 x
- width
/2, y
- h
/2, width
, height
);
2056 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2058 x
= event
.xmotion
.x_root
;
2059 y
= event
.xmotion
.y_root
;
2061 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2062 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2064 showPosition(wwin
, x
- width
/2, y
- h
/2);
2066 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2071 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2073 *x_ret
= x
- width
/2;
2075 XUngrabPointer(dpy
, CurrentTime
);
2076 XUngrabKeyboard(dpy
, CurrentTime
);
2077 /* get rid of the geometry window */
2078 unmapPositionDisplay(wwin
);
2082 WMHandleEvent(&event
);