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
);
1124 typedef struct _looper
{
1130 _keyloop(_looper
*lpr
){
1131 WWindow
*wwin
= lpr
->wwin
;
1132 WScreen
*scr
= wwin
->screen_ptr
;
1133 int w
= wwin
->frame
->core
->width
;
1134 int h
= wwin
->frame
->core
->height
;
1135 int src_x
= wwin
->frame_x
;
1136 int src_y
= wwin
->frame_y
;
1138 if (!scr
->selected_windows
){
1139 drawTransparentFrame(wwin
, src_x
+lpr
->ox
, src_y
+lpr
->oy
, w
, h
);
1145 /* printf("called\n");*/
1146 if (!scr
->selected_windows
){
1147 drawTransparentFrame(wwin
, src_x
+lpr
->ox
, src_y
+lpr
->oy
, w
, h
);
1150 if(scr
->keymove_tick
)
1151 WMAddTimerHandler(15000,(WMCallback
*)_keyloop
, lpr
);
1158 wKeyboardMoveResizeWindow(WWindow
*wwin
)
1160 WScreen
*scr
= wwin
->screen_ptr
;
1161 Window root
= scr
->root_win
;
1163 int w
= wwin
->frame
->core
->width
;
1164 int h
= wwin
->frame
->core
->height
;
1165 int scr_width
= wwin
->screen_ptr
->scr_width
;
1166 int scr_height
= wwin
->screen_ptr
->scr_height
;
1167 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1168 int src_x
= wwin
->frame_x
;
1169 int src_y
= wwin
->frame_y
;
1170 int done
,off_x
,off_y
,ww
,wh
;
1173 KeySym keysym
=NoSymbol
;
1174 KeyCode shiftl
,shiftr
,ctrll
,ctrlmode
;
1180 scr->keymove_tick=1;
1181 WMAddTimerHandler(1000,(WMCallback*)_keyloop, &looper);
1184 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1185 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1186 ctrll
= XKeysymToKeycode(dpy
, XK_Control_L
);
1187 ctrlmode
=done
=off_x
=off_y
=0;
1191 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1193 if (!wwin
->flags
.selected
) {
1194 wUnselectWindows(scr
);
1197 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1198 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
1199 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
);
1201 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1202 if(scr
->selected_windows
)
1203 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1204 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1205 if(!scr
->selected_windows
)
1206 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1208 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1217 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1218 | ButtonPressMask
| ExposureMask
, &event
);
1219 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1220 if(scr
->selected_windows
)
1221 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1222 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1223 /*** I HATE EDGE RESISTANCE - ]d ***/
1226 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1230 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1235 switch (event
.type
) {
1238 if (event
.xkey
.time
- lastTime
> 50) {
1244 lastTime
= event
.xkey
.time
;
1246 if (event
.xkey
.state
& ControlMask
&& !wwin
->flags
.shaded
){
1248 wUnselectWindows(scr
);
1253 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
){
1255 cycleGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
, 0);
1257 cyclePositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1260 keysym
= XLookupKeysym(&event
.xkey
, 0);
1303 wWindowConstrainSize(wwin
, &ww
, &wh
);
1306 if (wPreferences
.ws_cycle
){
1307 if (src_x
+ off_x
+ wwin
->frame
->core
->width
< 20){
1308 if(!scr
->current_workspace
) {
1309 wWorkspaceChange(scr
, scr
->workspace_count
-1);
1311 else wWorkspaceChange(scr
, scr
->current_workspace
-1);
1314 else if (src_x
+ off_x
+ 20 > scr_width
){
1315 if(scr
->current_workspace
== scr
->workspace_count
-1) {
1316 wWorkspaceChange(scr
, 0);
1318 else wWorkspaceChange(scr
, scr
->current_workspace
+1);
1323 if (src_x
+ off_x
+ wwin
->frame
->core
->width
< 20)
1324 off_x
= 20 - wwin
->frame
->core
->width
- src_x
;
1325 else if (src_x
+ off_x
+ 20 > scr_width
)
1326 off_x
= scr_width
- 20 - src_x
;
1329 if (src_y
+ off_y
+ wwin
->frame
->core
->height
< 20)
1330 off_y
= 20 - wwin
->frame
->core
->height
- src_y
;
1331 else if (src_y
+ off_y
+ 20 > scr_height
)
1332 off_y
= scr_height
- 20 - src_y
;
1341 WMHandleEvent(&event
);
1348 if (wwin
->flags
.shaded
&& !scr
->selected_windows
){
1349 moveGeometryDisplayCentered(scr
, src_x
+off_x
+ w
/2, src_y
+off_y
+ h
/2);
1353 unmapPositionDisplay(wwin
);
1354 mapGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1356 else if(!scr
->selected_windows
){
1357 unmapGeometryDisplay(wwin
);
1358 mapPositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
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
);
1373 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1375 else if(!scr
->selected_windows
)
1376 showPosition(wwin
, src_x
+off_x
, src_y
+off_y
);
1380 scr
->keymove_tick
=0;
1382 WMDeleteTimerWithClientData(&looper);
1384 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1385 if(scr
->selected_windows
)
1386 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1387 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1390 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1394 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1395 unmapGeometryDisplay(wwin
);
1398 unmapPositionDisplay(wwin
);
1399 XUngrabKeyboard(dpy
, CurrentTime
);
1400 XUngrabPointer(dpy
, CurrentTime
);
1404 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1406 list
=scr
->selected_windows
;
1407 if (!scr
->selected_windows
) {
1408 wWindowMove(wwin
, src_x
+off_x
, src_y
+off_y
);
1409 wWindowSynthConfigureNotify(wwin
);
1411 doWindowMove(wwin
,scr
->selected_windows
,off_x
,off_y
);
1413 wWindowSynthConfigureNotify(list
->head
);
1418 if (wwin
->client
.width
!= ww
)
1419 wwin
->flags
.user_changed_width
= 1;
1421 if (wwin
->client
.height
!= wh
- vert_border
)
1422 wwin
->flags
.user_changed_height
= 1;
1424 wWindowConfigure(wwin
, src_x
+off_x
, src_y
+off_y
,
1425 ww
, wh
- vert_border
);
1426 wWindowSynthConfigureNotify(wwin
);
1428 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1429 wSetFocusTo(scr
, wwin
);
1438 *----------------------------------------------------------------------
1439 * wMouseMoveWindow--
1440 * Move the named window and the other selected ones (if any),
1441 * interactively. Also shows the position of the window, if only one
1442 * window is being moved.
1443 * If the window is not on the selected window list, the selected
1444 * windows are deselected.
1445 * If shift is pressed during the operation, the position display
1446 * is changed to another type.
1449 * True if the window was moved, False otherwise.
1452 * The window(s) position is changed, and the client(s) are
1453 * notified about that.
1454 * The position display configuration may be changed.
1455 *----------------------------------------------------------------------
1458 wMouseMoveWindow(WWindow
*wwin
, XEvent
*ev
)
1460 WScreen
*scr
= wwin
->screen_ptr
;
1462 Window root
= scr
->root_win
;
1463 KeyCode shiftl
, shiftr
;
1466 /* This needs not to change while moving, else bad things can happen */
1467 int opaqueMove
= wPreferences
.opaque_move
;
1469 #ifdef GHOST_WINDOW_MOVE
1472 rimg
= InitGhostWindowMove(scr
);
1475 initMoveData(wwin
, &moveData
);
1477 moveData
.mouseX
= ev
->xmotion
.x_root
;
1478 moveData
.mouseY
= ev
->xmotion
.y_root
;
1480 if (!wwin
->flags
.selected
) {
1481 /* this window is not selected, unselect others and move only wwin */
1482 wUnselectWindows(scr
);
1485 puts("Moving window");
1487 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1488 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1494 /* XWarpPointer() doesn't seem to generate Motion events, so
1495 we've got to simulate them */
1496 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1497 &event
.xmotion
.y_root
, &junk
, &junk
,
1498 (unsigned *) &junk
);
1500 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1501 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
,
1504 if (event
.type
== MotionNotify
) {
1505 /* compress MotionNotify events */
1506 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1509 switch (event
.type
) {
1511 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1512 && started
&& !scr
->selected_windows
) {
1515 drawFrames(wwin
, scr
->selected_windows
,
1516 moveData
.realX
- wwin
->frame_x
,
1517 moveData
.realY
- wwin
->frame_y
);
1520 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1521 moveData
.winWidth
, moveData
.winHeight
);
1524 drawFrames(wwin
, scr
->selected_windows
,
1525 moveData
.realX
- wwin
->frame_x
,
1526 moveData
.realY
- wwin
->frame_y
);
1533 updateWindowPosition(wwin
, &moveData
,
1534 scr
->selected_windows
== NULL
1535 && wPreferences
.edge_resistance
> 0,
1537 event
.xmotion
.x_root
,
1538 event
.xmotion
.y_root
);
1540 if (!warped
&& !wPreferences
.no_autowrap
) {
1541 int oldWorkspace
= scr
->current_workspace
;
1544 drawFrames(wwin
, scr
->selected_windows
,
1545 moveData
.realX
- wwin
->frame_x
,
1546 moveData
.realY
- wwin
->frame_y
);
1548 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1549 if (scr
->current_workspace
!= oldWorkspace
1550 && wPreferences
.edge_resistance
> 0
1551 && scr
->selected_windows
== NULL
)
1552 updateMoveData(wwin
, &moveData
);
1557 drawFrames(wwin
, scr
->selected_windows
,
1558 moveData
.realX
- wwin
->frame_x
,
1559 moveData
.realY
- wwin
->frame_y
);
1564 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1565 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1567 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1568 | ButtonReleaseMask
| ButtonPressMask
,
1569 wCursor
[WCUR_MOVE
], CurrentTime
);
1571 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1574 if (!scr
->selected_windows
)
1575 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1576 moveData
.winWidth
, moveData
.winHeight
);
1578 if (started
&& !opaqueMove
)
1579 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1590 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1595 drawFrames(wwin
, scr
->selected_windows
,
1596 moveData
.realX
- wwin
->frame_x
,
1597 moveData
.realY
- wwin
->frame_y
);
1599 doWindowMove(wwin
, scr
->selected_windows
,
1600 moveData
.realX
- wwin
->frame_x
,
1601 moveData
.realY
- wwin
->frame_y
);
1603 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1604 wWindowSynthConfigureNotify(wwin
);
1606 XUngrabKeyboard(dpy
, CurrentTime
);
1609 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1610 wSetFocusTo(scr
, wwin
);
1612 if (wPreferences
.move_display
== WDIS_NEW
)
1613 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1615 if (!scr
->selected_windows
) {
1616 /* get rid of the geometry window */
1617 unmapPositionDisplay(wwin
);
1621 puts("End move window");
1623 freeMoveData(&moveData
);
1628 if (started
&& !opaqueMove
) {
1629 drawFrames(wwin
, scr
->selected_windows
,
1630 moveData
.realX
- wwin
->frame_x
,
1631 moveData
.realY
- wwin
->frame_y
);
1633 WMHandleEvent(&event
);
1636 drawFrames(wwin
, scr
->selected_windows
,
1637 moveData
.realX
- wwin
->frame_x
,
1638 moveData
.realY
- wwin
->frame_y
);
1640 WMHandleEvent(&event
);
1646 freeMoveData(&moveData
);
1653 #define HCONSTRAIN 2
1656 getResizeDirection(WWindow
*wwin
, int x
, int y
, int dx
, int dy
,
1659 int w
= wwin
->frame
->core
->width
- 1;
1660 int cw
= wwin
->frame
->resizebar_corner_width
;
1663 /* if not resizing through the resizebar */
1664 if (!(flags
& RESIZEBAR
)) {
1665 int xdir
= (abs(x
) < (wwin
->client
.width
/2)) ? LEFT
: RIGHT
;
1666 int ydir
= (abs(y
) < (wwin
->client
.height
/2)) ? UP
: DOWN
;
1667 if (abs(dx
) < 2 || abs(dy
) < 2) {
1668 if (abs(dy
) > abs(dx
))
1673 return (xdir
| ydir
);
1676 /* window is too narrow. allow diagonal resize */
1680 if (flags
& HCONSTRAIN
)
1685 return (LEFT
| ydir
);
1687 return (RIGHT
| ydir
);
1689 /* vertical resize */
1690 if ((x
> cw
) && (x
< w
- cw
))
1698 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1706 wMouseResizeWindow(WWindow
*wwin
, XEvent
*ev
)
1709 WScreen
*scr
= wwin
->screen_ptr
;
1710 Window root
= scr
->root_win
;
1711 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1712 int fw
= wwin
->frame
->core
->width
;
1713 int fh
= wwin
->frame
->core
->height
;
1714 int fx
= wwin
->frame_x
;
1715 int fy
= wwin
->frame_y
;
1716 int is_resizebar
= (wwin
->frame
->resizebar
1717 && ev
->xany
.window
==wwin
->frame
->resizebar
->window
);
1721 int rw
= fw
, rh
= fh
;
1722 int rx1
, ry1
, rx2
, ry2
;
1724 KeyCode shiftl
, shiftr
;
1731 if (wwin
->flags
.shaded
) {
1732 wwarning("internal error: tryein");
1735 orig_x
= ev
->xbutton
.x_root
;
1736 orig_y
= ev
->xbutton
.y_root
;
1740 puts("Resizing window");
1743 wUnselectWindows(scr
);
1748 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1749 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1750 if (!WFLAGP(wwin
, no_titlebar
))
1751 h
= wwin
->screen_ptr
->title_font
->height
+ TITLEBAR_EXTRA_HEIGHT
;
1755 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
| ButtonReleaseMask
1756 | ButtonPressMask
| ExposureMask
, &event
);
1757 switch (event
.type
) {
1759 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1760 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1762 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1763 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
1764 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1766 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1780 dw
= orig_x
- event
.xmotion
.x_root
;
1781 else if (res
& RIGHT
)
1782 dw
= event
.xmotion
.x_root
- orig_x
;
1784 dh
= orig_y
- event
.xmotion
.y_root
;
1785 else if (res
& DOWN
)
1786 dh
= event
.xmotion
.y_root
- orig_y
;
1788 orig_x
= event
.xmotion
.x_root
;
1789 orig_y
= event
.xmotion
.y_root
;
1794 fh
= rh
- vert_border
;
1795 wWindowConstrainSize(wwin
, &fw
, &fh
);
1799 else if (res
& RIGHT
)
1803 else if (res
& DOWN
)
1805 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1806 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1811 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
1812 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
1814 /* check if resizing through resizebar */
1820 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
1821 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
1822 flags
|= HCONSTRAIN
;
1824 res
= getResizeDirection(wwin
, tx
, ty
,
1825 orig_x
- event
.xmotion
.x_root
,
1826 orig_y
- event
.xmotion
.y_root
, flags
);
1828 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1829 | ButtonReleaseMask
| ButtonPressMask
,
1830 wCursor
[WCUR_RESIZE
], CurrentTime
);
1831 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1836 /* Draw the resize frame for the first time. */
1837 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
1839 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1841 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1846 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
1847 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
1849 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
1850 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1852 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
1854 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1856 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
1857 if (wPreferences
.size_display
== WDIS_NEW
) {
1858 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
1859 orig_fy
+ orig_fh
, res
);
1861 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1870 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1874 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1876 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1878 XUngrabKeyboard(dpy
, CurrentTime
);
1879 unmapGeometryDisplay(wwin
);
1882 if (wwin
->client
.width
!= fw
)
1883 wwin
->flags
.user_changed_width
= 1;
1885 if (wwin
->client
.height
!= fh
- vert_border
)
1886 wwin
->flags
.user_changed_height
= 1;
1888 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
1891 puts("End resize window");
1896 WMHandleEvent(&event
);
1911 wUnselectWindows(WScreen
*scr
)
1915 while (scr
->selected_windows
) {
1916 wwin
= scr
->selected_windows
->head
;
1917 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
1918 wIconSelect(wwin
->icon
);
1920 wSelectWindow(wwin
, False
);
1926 selectWindowsInside(WScreen
*scr
, int x1
, int y1
, int x2
, int y2
)
1930 /* select the windows and put them in the selected window list */
1931 tmpw
= scr
->focused_window
;
1932 while (tmpw
!= NULL
) {
1933 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
1934 if ((tmpw
->frame
->workspace
== scr
->current_workspace
1935 || IS_OMNIPRESENT(tmpw
))
1936 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
1937 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
1938 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
1939 wSelectWindow(tmpw
, True
);
1948 wSelectWindows(WScreen
*scr
, XEvent
*ev
)
1951 Window root
= scr
->root_win
;
1952 GC gc
= scr
->frame_gc
;
1953 int xp
= ev
->xbutton
.x_root
;
1954 int yp
= ev
->xbutton
.y_root
;
1959 puts("Selecting windows");
1961 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
1962 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
1963 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
],
1964 CurrentTime
) != Success
) {
1969 wUnselectWindows(scr
);
1971 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
1973 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
1974 | ButtonPressMask
, &event
);
1976 switch (event
.type
) {
1978 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
1979 x
= event
.xmotion
.x_root
;
1986 y
= event
.xmotion
.y_root
;
1993 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2000 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2003 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2005 XUngrabPointer(dpy
, CurrentTime
);
2006 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
2009 wKWMSelectRootRegion(scr
, x
, y
, w
, h
,
2010 event
.xbutton
.state
& ControlMask
);
2011 #endif /* KWM_HINTS */
2014 puts("End window selection");
2019 WMHandleEvent(&event
);
2027 InteractivePlaceWindow(WWindow
*wwin
, int *x_ret
, int *y_ret
,
2028 unsigned width
, unsigned height
)
2030 WScreen
*scr
= wwin
->screen_ptr
;
2031 Window root
= scr
->root_win
;
2034 KeyCode shiftl
, shiftr
;
2038 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2039 GrabModeAsync
, GrabModeAsync
, None
,
2040 wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2045 if (!WFLAGP(wwin
, no_titlebar
)) {
2046 h
= scr
->title_font
->height
+ TITLEBAR_EXTRA_HEIGHT
;
2049 if (!WFLAGP(wwin
, no_resizebar
)) {
2050 height
+= RESIZEBAR_HEIGHT
;
2052 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2053 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
,
2054 (unsigned *) &junk
);
2055 mapPositionDisplay(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2057 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2059 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2060 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2062 WMMaskEvent(dpy
, PointerMotionMask
|ButtonPressMask
|ExposureMask
|KeyPressMask
,
2064 switch (event
.type
) {
2066 if ((event
.xkey
.keycode
== shiftl
)
2067 || (event
.xkey
.keycode
== shiftr
)) {
2068 drawTransparentFrame(wwin
,
2069 x
- width
/2, y
- h
/2, width
, height
);
2070 cyclePositionDisplay(wwin
,
2071 x
- width
/2, y
- h
/2, width
, height
);
2072 drawTransparentFrame(wwin
,
2073 x
- width
/2, y
- h
/2, width
, height
);
2078 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2080 x
= event
.xmotion
.x_root
;
2081 y
= event
.xmotion
.y_root
;
2083 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2084 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2086 showPosition(wwin
, x
- width
/2, y
- h
/2);
2088 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2093 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2095 *x_ret
= x
- width
/2;
2097 XUngrabPointer(dpy
, CurrentTime
);
2098 XUngrabKeyboard(dpy
, CurrentTime
);
2099 /* get rid of the geometry window */
2100 unmapPositionDisplay(wwin
);
2104 WMHandleEvent(&event
);