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
,
75 *width
= WMWidthOfString(scr
->info_text_font
, "-8888 x -8888", 13);
77 *height
= (7 * WMFontHeight(scr
->info_text_font
)) / 4 - 1;
82 *----------------------------------------------------------------------
83 * moveGeometryDisplayCentered
85 * routine that moves the geometry/position window on scr so it is
86 * centered over the given coordinates (x,y). Also the window position
87 * is clamped so it stays on the screen at all times.
88 *----------------------------------------------------------------------
91 moveGeometryDisplayCentered(WScreen
*scr
, int x
, int y
)
93 x
-= scr
->geometry_display_width
/ 2;
94 y
-= scr
->geometry_display_height
/ 2;
98 else if (x
> (scr
->scr_width
- scr
->geometry_display_width
- 3))
99 x
= scr
->scr_width
- scr
->geometry_display_width
- 3;
103 else if (y
> (scr
->scr_height
- scr
->geometry_display_height
- 3))
104 y
= scr
->scr_height
- scr
->geometry_display_height
- 3;
106 XMoveWindow(dpy
, scr
->geometry_display
, x
, y
);
111 showPosition(WWindow
*wwin
, int x
, int y
)
113 WScreen
*scr
= wwin
->screen_ptr
;
114 GC gc
= scr
->info_text_gc
;
118 if (wPreferences
.move_display
== WDIS_NEW
) {
120 int width
= wwin
->frame
->core
->width
;
121 int height
= wwin
->frame
->core
->height
;
123 GC lgc
= scr
->line_gc
;
124 XSetForeground(dpy
, lgc
, scr
->line_pixel
);
125 sprintf(num
, "%i", x
);
127 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
-1, scr
->scr_width
, y
-1);
128 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
+height
+2, scr
->scr_width
,
130 XDrawLine(dpy
, scr
->root_win
, lgc
, x
-1, 0, x
-1, scr
->scr_height
);
131 XDrawLine(dpy
, scr
->root_win
, lgc
, x
+width
+2, 0, x
+width
+2,
135 XClearArea(dpy
, scr
->geometry_display
, 1, 1,
136 scr
->geometry_display_width
-2, scr
->geometry_display_height
-2,
138 sprintf(num
, "%+i %-+i", x
, y
);
139 fw
= WMWidthOfString(scr
->info_text_font
, num
, strlen(num
));
141 XSetForeground(dpy
, gc
, scr
->black_pixel
);
143 fh
= WMFontHeight(scr
->info_text_font
);
144 WMDrawString(scr
->wmscreen
, scr
->geometry_display
, gc
,
146 (scr
->geometry_display_width
- 2 - fw
) / 2,
147 (scr
->geometry_display_height
-fh
)/2, num
, strlen(num
));
148 wDrawBevel(scr
->geometry_display
, scr
->geometry_display_width
+1,
149 scr
->geometry_display_height
+1,
150 scr
->widget_texture
, WREL_RAISED
);
156 cyclePositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
158 WScreen
*scr
= wwin
->screen_ptr
;
160 wPreferences
.move_display
++;
161 wPreferences
.move_display
%= NUM_DISPLAYS
;
163 if (wPreferences
.move_display
== WDIS_NEW
) {
164 XUnmapWindow(dpy
, scr
->geometry_display
);
166 if (wPreferences
.move_display
== WDIS_CENTER
) {
167 moveGeometryDisplayCentered(scr
,
168 scr
->scr_width
/2, scr
->scr_height
/2);
169 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
170 moveGeometryDisplayCentered(scr
, 1, 1);
171 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
172 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
174 XMapRaised(dpy
, scr
->geometry_display
);
180 mapPositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
182 WScreen
*scr
= wwin
->screen_ptr
;
184 if (wPreferences
.move_display
== WDIS_NEW
) {
186 } else if (wPreferences
.move_display
== WDIS_CENTER
) {
187 moveGeometryDisplayCentered(scr
, scr
->scr_width
/ 2,
188 scr
->scr_height
/ 2);
189 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
190 moveGeometryDisplayCentered(scr
, 1, 1);
191 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
192 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
194 XMapRaised(dpy
, scr
->geometry_display
);
195 showPosition(wwin
, x
, y
);
198 #define unmapPositionDisplay(w) \
199 XUnmapWindow(dpy, (w)->screen_ptr->geometry_display);
203 showGeometry(WWindow
*wwin
, int x1
, int y1
, int x2
, int y2
, int direction
)
205 WScreen
*scr
= wwin
->screen_ptr
;
206 Window root
= scr
->root_win
;
207 GC gc
= scr
->line_gc
;
208 int ty
, by
, my
, x
, y
, mx
, s
;
213 ty
= y1
+ wwin
->frame
->top_width
;
214 by
= y2
- wwin
->frame
->bottom_width
;
215 fw
= WMWidthOfString(scr
->info_text_font
, "8888", 4);
216 fh
= WMFontHeight(scr
->info_text_font
);
218 if (wPreferences
.size_display
== WDIS_NEW
) {
219 XSetForeground(dpy
, gc
, scr
->line_pixel
);
221 /* vertical geometry */
222 if (((direction
& LEFT
) && (x2
< scr
->scr_width
- fw
)) || (x1
< fw
)) {
233 segment
[0].x1
= x
- (s
+ 6); segment
[0].y1
= ty
;
234 segment
[0].x2
= x
- (s
- 10); segment
[0].y2
= ty
;
237 segment
[1].x1
= x
- (s
- 2); segment
[1].y1
= ty
+ 1;
238 segment
[1].x2
= x
- (s
- 5); segment
[1].y2
= ty
+ 7;
240 segment
[2].x1
= x
- (s
- 2); segment
[2].y1
= ty
+ 1;
241 segment
[2].x2
= x
- (s
+ 1); segment
[2].y2
= ty
+ 7;
244 segment
[3].x1
= x
- (s
- 2); segment
[3].y1
= ty
+ 1;
245 segment
[3].x2
= x
- (s
- 2); segment
[3].y2
= my
- fh
/2 - 1;
247 XDrawSegments(dpy
, root
, gc
, segment
, 4);
255 segment
[1].y1
= by
- 1;
256 segment
[1].y2
= by
- 7;
258 segment
[2].y1
= by
- 1;
259 segment
[2].y2
= by
- 7;
262 segment
[3].y1
= my
+ fh
/2 + 2;
263 segment
[3].y2
= by
- 1;
265 XDrawSegments(dpy
, root
, gc
, segment
, 4);
267 sprintf(num
, "%i", (by
- ty
- wwin
->normal_hints
->base_height
) /
268 wwin
->normal_hints
->height_inc
);
269 fw
= WMWidthOfString(scr
->info_text_font
, num
, strlen(num
));
271 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
273 /* Display the height. */
274 WMDrawString(scr
->wmscreen
, root
, gc
, scr
->info_text_font
,
275 x
- s
+ 3 - fw
/2, my
- fh
/2 + 1, num
, strlen(num
));
276 XSetForeground(dpy
, gc
, scr
->line_pixel
);
277 /* horizontal geometry */
285 mx
= x1
+ (x2
- x1
)/2;
286 sprintf(num
, "%i", (x2
- x1
- wwin
->normal_hints
->base_width
) /
287 wwin
->normal_hints
->width_inc
);
288 fw
= WMWidthOfString(scr
->info_text_font
, num
, strlen(num
));
292 segment
[0].x1
= x1
; segment
[0].y1
= y
- (s
+ 6);
293 segment
[0].x2
= x1
; segment
[0].y2
= y
- (s
- 10);
296 segment
[1].x1
= x1
+ 7; segment
[1].y1
= y
- (s
+ 1);
297 segment
[1].x2
= x1
+ 1; segment
[1].y2
= y
- (s
- 2);
299 segment
[2].x1
= x1
+ 1; segment
[2].y1
= y
- (s
- 2);
300 segment
[2].x2
= x1
+ 7; segment
[2].y2
= y
- (s
- 5);
303 segment
[3].x1
= x1
+ 1; segment
[3].y1
= y
- (s
- 2);
304 segment
[3].x2
= mx
- fw
/2 - 2; segment
[3].y2
= y
- (s
- 2);
306 XDrawSegments(dpy
, root
, gc
, segment
, 4);
310 segment
[0].x1
= x2
+ 1;
311 segment
[0].x2
= x2
+ 1;
314 segment
[1].x1
= x2
- 6;
318 segment
[2].x2
= x2
- 6;
321 segment
[3].x1
= mx
+ fw
/2 + 2;
324 XDrawSegments(dpy
, root
, gc
, segment
, 4);
326 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
328 /* Display the width. */
329 WMDrawString(scr
->wmscreen
, root
, gc
, scr
->info_text_font
,
330 mx
- fw
/2 + 1, y
- s
+ fh
/2 + 1, num
, strlen(num
));
332 XClearArea(dpy
, scr
->geometry_display
, 1, 1,
333 scr
->geometry_display_width
-2, scr
->geometry_display_height
-2,
335 sprintf(num
, "%i x %-i", (x2
- x1
- wwin
->normal_hints
->base_width
)
336 / wwin
->normal_hints
->width_inc
,
337 (by
- ty
- wwin
->normal_hints
->base_height
)
338 / wwin
->normal_hints
->height_inc
);
339 fw
= WMWidthOfString(scr
->info_text_font
, num
, strlen(num
));
341 XSetForeground(dpy
, scr
->info_text_gc
, scr
->black_pixel
);
343 /* Display the height. */
344 WMDrawString(scr
->wmscreen
, scr
->geometry_display
, scr
->info_text_gc
,
346 (scr
->geometry_display_width
-fw
)/2,
347 (scr
->geometry_display_height
-fh
)/2, num
, strlen(num
));
348 wDrawBevel(scr
->geometry_display
, scr
->geometry_display_width
+1,
349 scr
->geometry_display_height
+1,
350 scr
->widget_texture
, WREL_RAISED
);
356 cycleGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
, int dir
)
358 WScreen
*scr
= wwin
->screen_ptr
;
360 wPreferences
.size_display
++;
361 wPreferences
.size_display
%= NUM_DISPLAYS
;
363 if (wPreferences
.size_display
== WDIS_NEW
) {
364 XUnmapWindow(dpy
, scr
->geometry_display
);
366 if (wPreferences
.size_display
== WDIS_CENTER
) {
367 moveGeometryDisplayCentered(scr
,
368 scr
->scr_width
/ 2, scr
->scr_height
/ 2);
369 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
370 moveGeometryDisplayCentered(scr
, 1, 1);
371 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
372 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
374 XMapRaised(dpy
, scr
->geometry_display
);
375 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, dir
);
381 mapGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
383 WScreen
*scr
= wwin
->screen_ptr
;
385 if (wPreferences
.size_display
== WDIS_NEW
)
388 if (wPreferences
.size_display
== WDIS_CENTER
) {
389 moveGeometryDisplayCentered(scr
, scr
->scr_width
/ 2,
390 scr
->scr_height
/ 2);
391 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
392 moveGeometryDisplayCentered(scr
, 1, 1);
393 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
394 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
396 XMapRaised(dpy
, scr
->geometry_display
);
397 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, 0);
400 #define unmapGeometryDisplay(w) \
401 XUnmapWindow(dpy, (w)->screen_ptr->geometry_display);
405 doWindowMove(WWindow
*wwin
, LinkedList
*list
, int dx
, int dy
)
409 int scr_width
= wwin
->screen_ptr
->scr_width
;
410 int scr_height
= wwin
->screen_ptr
->scr_height
;
413 wWindowMove(wwin
, wwin
->frame_x
+ dx
, wwin
->frame_y
+ dy
);
417 x
= tmpw
->frame_x
+ dx
;
418 y
= tmpw
->frame_y
+ dy
;
420 /* don't let windows become unreachable */
422 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
423 x
= 20 - (int)tmpw
->frame
->core
->width
;
424 else if (x
+ 20 > scr_width
)
427 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
428 y
= 20 - (int)tmpw
->frame
->core
->height
;
429 else if (y
+ 20 > scr_height
)
432 wWindowMove(tmpw
, x
, y
);
440 drawTransparentFrame(WWindow
*wwin
, int x
, int y
, int width
, int height
)
442 Window root
= wwin
->screen_ptr
->root_win
;
443 GC gc
= wwin
->screen_ptr
->frame_gc
;
447 if (!WFLAGP(wwin
, no_titlebar
) && !wwin
->flags
.shaded
) {
448 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + TITLEBAR_EXTRA_HEIGHT
;
450 if (!WFLAGP(wwin
, no_resizebar
) && !wwin
->flags
.shaded
) {
451 /* Can't use wwin-frame->bottom_width because, in some cases
452 (e.g. interactive placement), frame does not point to anything. */
453 bottom
= RESIZEBAR_HEIGHT
- 1;
455 XDrawRectangle(dpy
, root
, gc
, x
, y
, width
+ 1, height
+ 1);
458 XDrawLine(dpy
, root
, gc
, x
+ 1, y
+ h
, x
+ width
+ 1, y
+ h
);
461 XDrawLine(dpy
, root
, gc
, x
+ 1,
464 y
+ height
- bottom
);
470 drawFrames(WWindow
*wwin
, LinkedList
*list
, int dx
, int dy
)
473 int scr_width
= wwin
->screen_ptr
->scr_width
;
474 int scr_height
= wwin
->screen_ptr
->scr_height
;
479 x
= wwin
->frame_x
+ dx
;
480 y
= wwin
->frame_y
+ dy
;
482 drawTransparentFrame(wwin
, x
, y
,
483 wwin
->frame
->core
->width
,
484 wwin
->frame
->core
->height
);
489 x
= tmpw
->frame_x
+ dx
;
490 y
= tmpw
->frame_y
+ dy
;
492 /* don't let windows become unreachable */
494 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
495 x
= 20 - (int)tmpw
->frame
->core
->width
;
496 else if (x
+ 20 > scr_width
)
499 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
500 y
= 20 - (int)tmpw
->frame
->core
->height
;
501 else if (y
+ 20 > scr_height
)
504 drawTransparentFrame(tmpw
, x
, y
, tmpw
->frame
->core
->width
,
505 tmpw
->frame
->core
->height
);
520 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &ev
)) ;
525 crossWorkspace(WScreen
*scr
, WWindow
*wwin
, int opaque_move
,
526 int new_workspace
, int rewind
)
528 /* do not let window be unmapped */
530 wwin
->flags
.changing_workspace
= 1;
531 wWindowChangeWorkspace(wwin
, new_workspace
);
533 /* go to new workspace */
534 wWorkspaceChange(scr
, new_workspace
);
536 wwin
->flags
.changing_workspace
= 0;
539 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, scr
->scr_width
- 20, 0);
541 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, -(scr
->scr_width
- 20), 0);
546 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
547 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
548 GrabModeAsync
, None
, wCursor
[WCUR_MOVE
], CurrentTime
);
556 /* arrays of WWindows sorted by the respective border position */
557 WWindow
**topList
; /* top border */
558 WWindow
**leftList
; /* left border */
559 WWindow
**rightList
; /* right border */
560 WWindow
**bottomList
; /* bottom border */
563 /* index of window in the above lists indicating the relative position
564 * of the window with the others */
570 int rubCount
; /* for workspace switching */
572 int winWidth
, winHeight
; /* width/height of the window */
573 int realX
, realY
; /* actual position of the window */
574 int calcX
, calcY
; /* calculated position of window */
575 int omouseX
, omouseY
; /* old mouse position */
576 int mouseX
, mouseY
; /* last known position of the pointer */
579 #define WTOP(w) (w)->frame_y
580 #define WLEFT(w) (w)->frame_x
581 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width + FRAME_BORDER_WIDTH)
582 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height + FRAME_BORDER_WIDTH)
585 compareWTop(const void *a
, const void *b
)
587 WWindow
*wwin1
= *(WWindow
**)a
;
588 WWindow
*wwin2
= *(WWindow
**)b
;
590 if (WTOP(wwin1
) > WTOP(wwin2
))
592 else if (WTOP(wwin1
) < WTOP(wwin2
))
600 compareWLeft(const void *a
, const void *b
)
602 WWindow
*wwin1
= *(WWindow
**)a
;
603 WWindow
*wwin2
= *(WWindow
**)b
;
605 if (WLEFT(wwin1
) > WLEFT(wwin2
))
607 else if (WLEFT(wwin1
) < WLEFT(wwin2
))
615 compareWRight(const void *a
, const void *b
)
617 WWindow
*wwin1
= *(WWindow
**)a
;
618 WWindow
*wwin2
= *(WWindow
**)b
;
620 if (WRIGHT(wwin1
) < WRIGHT(wwin2
))
622 else if (WRIGHT(wwin1
) > WRIGHT(wwin2
))
631 compareWBottom(const void *a
, const void *b
)
633 WWindow
*wwin1
= *(WWindow
**)a
;
634 WWindow
*wwin2
= *(WWindow
**)b
;
636 if (WBOTTOM(wwin1
) < WBOTTOM(wwin2
))
638 else if (WBOTTOM(wwin1
) > WBOTTOM(wwin2
))
646 updateResistance(WWindow
*wwin
, MoveData
*data
, int newX
, int newY
)
649 int newX2
= newX
+ data
->winWidth
;
650 int newY2
= newY
+ data
->winHeight
;
653 if (newX
< data
->realX
) {
654 if (data
->rightIndex
> 0
655 && newX
< WRIGHT(data
->rightList
[data
->rightIndex
-1])) {
657 } else if (data
->leftIndex
<= data
->count
-1
658 && newX2
<= WLEFT(data
->leftList
[data
->leftIndex
])) {
661 } else if (newX
> data
->realX
) {
662 if (data
->leftIndex
> 0
663 && newX2
> WLEFT(data
->leftList
[data
->leftIndex
-1])) {
665 } else if (data
->rightIndex
<= data
->count
-1
666 && newX
>= WRIGHT(data
->rightList
[data
->rightIndex
])) {
672 if (newY
< data
->realY
) {
673 if (data
->bottomIndex
> 0
674 && newY
< WBOTTOM(data
->bottomList
[data
->bottomIndex
-1])) {
676 } else if (data
->topIndex
<= data
->count
-1
677 && newY2
<= WTOP(data
->topList
[data
->topIndex
])) {
680 } else if (newY
> data
->realY
) {
681 if (data
->topIndex
> 0
682 && newY2
> WTOP(data
->topList
[data
->topIndex
-1])) {
684 } else if (data
->bottomIndex
<= data
->count
-1
685 && newY
>= WBOTTOM(data
->bottomList
[data
->bottomIndex
])) {
694 /* TODO: optimize this */
695 if (data
->realY
< WBOTTOM(data
->bottomList
[0])) {
696 data
->bottomIndex
= 0;
698 if (data
->realX
< WRIGHT(data
->rightList
[0])) {
699 data
->rightIndex
= 0;
701 if ((data
->realX
+ data
->winWidth
) > WLEFT(data
->leftList
[0])) {
704 if ((data
->realY
+ data
->winHeight
) > WTOP(data
->topList
[0])) {
707 for (i
= 0; i
< data
->count
; i
++) {
708 if (data
->realY
> WBOTTOM(data
->bottomList
[i
])) {
709 data
->bottomIndex
= i
+ 1;
711 if (data
->realX
> WRIGHT(data
->rightList
[i
])) {
712 data
->rightIndex
= i
+ 1;
714 if ((data
->realX
+ data
->winWidth
) < WLEFT(data
->leftList
[i
])) {
715 data
->leftIndex
= i
+ 1;
717 if ((data
->realY
+ data
->winHeight
) < WTOP(data
->topList
[i
])) {
718 data
->topIndex
= i
+ 1;
725 freeMoveData(MoveData
*data
)
730 free(data
->leftList
);
732 free(data
->rightList
);
733 if (data
->bottomList
)
734 free(data
->bottomList
);
739 updateMoveData(WWindow
*wwin
, MoveData
*data
)
741 WScreen
*scr
= wwin
->screen_ptr
;
746 tmp
= scr
->focused_window
;
748 if (tmp
!= wwin
&& scr
->current_workspace
== tmp
->frame
->workspace
749 && !tmp
->flags
.miniaturized
750 && !tmp
->flags
.hidden
751 && !tmp
->flags
.obscured
) {
752 data
->topList
[data
->count
] = tmp
;
753 data
->leftList
[data
->count
] = tmp
;
754 data
->rightList
[data
->count
] = tmp
;
755 data
->bottomList
[data
->count
] = tmp
;
761 if (data
->count
== 0) {
764 data
->rightIndex
= 0;
765 data
->bottomIndex
= 0;
770 * order from closest to the border of the screen to farthest
772 qsort(data
->topList
, data
->count
, sizeof(WWindow
**), compareWTop
);
773 qsort(data
->leftList
, data
->count
, sizeof(WWindow
**), compareWLeft
);
774 qsort(data
->rightList
, data
->count
, sizeof(WWindow
**), compareWRight
);
775 qsort(data
->bottomList
, data
->count
, sizeof(WWindow
**), compareWBottom
);
777 /* figure the position of the window relative to the others */
780 data
->leftIndex
= -1;
781 data
->rightIndex
= -1;
782 data
->bottomIndex
= -1;
784 if (WTOP(wwin
) < WBOTTOM(data
->bottomList
[0])) {
785 data
->bottomIndex
= 0;
787 if (WLEFT(wwin
) < WRIGHT(data
->rightList
[0])) {
788 data
->rightIndex
= 0;
790 if (WRIGHT(wwin
) > WLEFT(data
->leftList
[0])) {
793 if (WBOTTOM(wwin
) > WTOP(data
->topList
[0])) {
796 for (i
= 0; i
< data
->count
; i
++) {
797 if (WTOP(wwin
) >= WBOTTOM(data
->bottomList
[i
])) {
798 data
->bottomIndex
= i
+ 1;
800 if (WLEFT(wwin
) >= WRIGHT(data
->rightList
[i
])) {
801 data
->rightIndex
= i
+ 1;
803 if (WRIGHT(wwin
) <= WLEFT(data
->leftList
[i
])) {
804 data
->leftIndex
= i
+ 1;
806 if (WBOTTOM(wwin
) <= WTOP(data
->topList
[i
])) {
807 data
->topIndex
= i
+ 1;
814 initMoveData(WWindow
*wwin
, MoveData
*data
)
819 memset(data
, 0, sizeof(MoveData
));
821 for (i
= 0, tmp
= wwin
->screen_ptr
->focused_window
;
823 tmp
= tmp
->prev
, i
++);
826 data
->topList
= wmalloc(sizeof(WWindow
*) * i
);
827 data
->leftList
= wmalloc(sizeof(WWindow
*) * i
);
828 data
->rightList
= wmalloc(sizeof(WWindow
*) * i
);
829 data
->bottomList
= wmalloc(sizeof(WWindow
*) * i
);
831 updateMoveData(wwin
, data
);
834 data
->realX
= wwin
->frame_x
;
835 data
->realY
= wwin
->frame_y
;
836 data
->calcX
= wwin
->frame_x
;
837 data
->calcY
= wwin
->frame_y
;
839 data
->winWidth
= wwin
->frame
->core
->width
+ 2;
840 data
->winHeight
= wwin
->frame
->core
->height
+ 2;
845 checkWorkspaceChange(WWindow
*wwin
, MoveData
*data
, Bool opaqueMove
)
847 WScreen
*scr
= wwin
->screen_ptr
;
848 Bool changed
= False
;
850 if (data
->mouseX
<= 1) {
851 if (scr
->current_workspace
> 0) {
853 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
- 1,
858 } else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
) {
860 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->workspace_count
- 1,
865 } else if (data
->mouseX
>= scr
->scr_width
- 2) {
867 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
869 if (wPreferences
.ws_cycle
870 || scr
->workspace_count
== MAX_WORKSPACES
) {
872 crossWorkspace(scr
, wwin
, opaqueMove
, 0, False
);
876 /* if user insists on trying to go to next workspace even when
877 * it's already the last, create a new one */
878 else if (data
->omouseX
== data
->mouseX
879 && wPreferences
.ws_advance
) {
881 /* detect user "rubbing" the window against the edge */
882 if (data
->rubCount
> 0
883 && data
->omouseY
- data
->mouseY
> MOVE_THRESHOLD
) {
885 data
->rubCount
= -(data
->rubCount
+ 1);
887 } else if (data
->rubCount
<= 0
888 && data
->mouseY
- data
->omouseY
> MOVE_THRESHOLD
) {
890 data
->rubCount
= -data
->rubCount
+ 1;
893 /* create a new workspace */
894 if (abs(data
->rubCount
) > 2) {
895 /* go to next workspace */
898 crossWorkspace(scr
, wwin
, opaqueMove
,
899 scr
->current_workspace
+1, False
);
903 } else if (scr
->current_workspace
< scr
->workspace_count
) {
905 /* go to next workspace */
906 crossWorkspace(scr
, wwin
, opaqueMove
,
907 scr
->current_workspace
+1, False
);
920 updateWindowPosition(WWindow
*wwin
, MoveData
*data
, Bool doResistance
,
921 Bool opaqueMove
, int newMouseX
, int newMouseY
)
923 WScreen
*scr
= wwin
->screen_ptr
;
924 int dx
, dy
; /* how much mouse moved */
925 int winL
, winR
, winT
, winB
; /* requested new window position */
926 int newX
, newY
; /* actual new window position */
927 Bool hresist
, vresist
;
935 /* check the direction of the movement */
936 dx
= newMouseX
- data
->mouseX
;
937 dy
= newMouseY
- data
->mouseY
;
939 data
->omouseX
= data
->mouseX
;
940 data
->omouseY
= data
->mouseY
;
941 data
->mouseX
= newMouseX
;
942 data
->mouseY
= newMouseY
;
944 winL
= data
->calcX
+ dx
;
945 winR
= data
->calcX
+ data
->winWidth
+ dx
;
946 winT
= data
->calcY
+ dy
;
947 winB
= data
->calcY
+ data
->winHeight
+ dy
;
957 resist
= wPreferences
.edge_resistance
;
958 /* horizontal movement: check horizontal edge resistances */
960 /* window is the leftmost window: check against screen edge */
961 edge
= scr
->totalUsableArea
.x1
;
963 /* check position of nearest window to the left */
964 if (data
->rightIndex
> 0) {
965 /* there is some window at the left: check if it will block
967 rwin
= data
->rightList
[data
->rightIndex
- 1];
969 if (data
->realY
> WBOTTOM(rwin
)
970 || (data
->realY
+ data
->winHeight
) < WTOP(rwin
)) {
973 edge
= WRIGHT(rwin
) + 1;
974 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
977 if (resist
> 0 && winL
>= edge
- resist
&& winL
<= edge
) {
982 /* window is the rightmost window: check against screen edge */
983 edge
= scr
->totalUsableArea
.x2
;
985 /* check position of nearest window to the right */
986 if (data
->leftIndex
> 0) {
987 /* there is some window at the right: check if it will block
989 rwin
= data
->leftList
[data
->leftIndex
- 1];
991 if (data
->realY
> WBOTTOM(rwin
)
992 || (data
->realY
+ data
->winHeight
) < WTOP(rwin
)) {
996 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
999 if (resist
> 0 && winR
<= edge
+ resist
&& winR
>= edge
) {
1000 newX
= edge
- data
->winWidth
;
1005 resist
= wPreferences
.edge_resistance
;
1006 /* vertical movement: check vertical edge resistances */
1008 /* window is the topmost window: check against screen edge */
1009 edge
= scr
->totalUsableArea
.y1
;
1011 /* check position of nearest window to the top */
1012 if (data
->bottomIndex
> 0) {
1013 /* there is some window at the top: check if it will block
1015 rwin
= data
->bottomList
[data
->bottomIndex
- 1];
1017 if (data
->realX
> WRIGHT(rwin
)
1018 || (data
->realX
+ data
->winWidth
) < WLEFT(rwin
)) {
1021 edge
= WBOTTOM(rwin
) + 1;
1022 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1025 if (resist
> 0 && winT
>= edge
- resist
&& winT
<= edge
) {
1029 } else if (dy
> 0) {
1030 /* window is the bottommost window: check against screen edge */
1031 edge
= scr
->totalUsableArea
.y2
;
1033 /* check position of nearest window to the bottom */
1034 if (data
->topIndex
> 0) {
1035 /* there is some window at the bottom: check if it will block
1037 rwin
= data
->topList
[data
->topIndex
- 1];
1039 if (data
->realX
> WRIGHT(rwin
)
1040 || (data
->realX
+ data
->winWidth
) < WLEFT(rwin
)) {
1044 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1047 if (resist
> 0 && winB
<= edge
+ resist
&& winB
>= edge
) {
1048 newY
= edge
- data
->winHeight
;
1054 /* update window position */
1058 if (((dx
> 0 && data
->calcX
- data
->realX
> 0)
1059 || (dx
< 0 && data
->calcX
- data
->realX
< 0)) && !hresist
)
1062 if (((dy
> 0 && data
->calcY
- data
->realY
> 0)
1063 || (dy
< 0 && data
->calcY
- data
->realY
< 0)) && !vresist
)
1066 if (data
->realX
!= newX
|| data
->realY
!= newY
) {
1068 if (wPreferences
.move_display
== WDIS_NEW
1069 && !scr
->selected_windows
) {
1070 showPosition(wwin
, data
->realX
, data
->realY
);
1073 doWindowMove(wwin
, scr
->selected_windows
,
1074 newX
- wwin
->frame_x
,
1075 newY
- wwin
->frame_y
);
1078 drawFrames(wwin
, scr
->selected_windows
,
1079 data
->realX
- wwin
->frame_x
,
1080 data
->realY
- wwin
->frame_y
);
1083 if (!scr
->selected_windows
1084 && wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
1086 moveGeometryDisplayCentered(scr
, newX
+ data
->winWidth
/2,
1087 newY
+ data
->winHeight
/2);
1092 drawFrames(wwin
, scr
->selected_windows
,
1093 newX
- wwin
->frame_x
,
1094 newY
- wwin
->frame_y
);
1097 if (!scr
->selected_windows
) {
1098 showPosition(wwin
, newX
, newY
);
1103 /* recalc relative window position */
1104 if (doResistance
&& (data
->realX
!= newX
|| data
->realY
!= newY
)) {
1105 updateResistance(wwin
, data
, newX
, newY
);
1113 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1116 wKeyboardMoveResizeWindow(WWindow
*wwin
)
1118 WScreen
*scr
= wwin
->screen_ptr
;
1119 Window root
= scr
->root_win
;
1121 int w
= wwin
->frame
->core
->width
;
1122 int h
= wwin
->frame
->core
->height
;
1123 int scr_width
= wwin
->screen_ptr
->scr_width
;
1124 int scr_height
= wwin
->screen_ptr
->scr_height
;
1125 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1126 int src_x
= wwin
->frame_x
;
1127 int src_y
= wwin
->frame_y
;
1128 int done
,off_x
,off_y
,ww
,wh
;
1131 KeySym keysym
=NoSymbol
;
1133 KeyCode shiftl
,shiftr
,ctrll
,ctrlmode
;
1135 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1136 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1137 ctrll
= XKeysymToKeycode(dpy
, XK_Control_L
);
1138 ctrlmode
=done
=off_x
=off_y
=0;
1142 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1144 if (!wwin
->flags
.selected
) {
1145 wUnselectWindows(scr
);
1148 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1149 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
1150 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
);
1152 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1153 if(scr
->selected_windows
)
1154 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1155 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1156 if(!scr
->selected_windows
)
1157 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1159 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1168 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1169 | ButtonPressMask
| ExposureMask
, &event
);
1170 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1171 if(scr
->selected_windows
)
1172 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1173 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1174 /*** I HATE EDGE RESISTANCE - ]d ***/
1177 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1181 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1186 switch (event
.type
) {
1189 if (event
.xkey
.time
- lastTime
> 50) {
1190 kspeed
/=(1 + (event
.xkey
.time
- lastTime
)/100);
1196 if (kspeed
< _KS
) kspeed
= _KS
;
1197 lastTime
= event
.xkey
.time
;
1199 if (event
.xkey
.state
& ControlMask
&& !wwin
->flags
.shaded
) {
1201 wUnselectWindows(scr
);
1206 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
) {
1208 cycleGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
, 0);
1210 cyclePositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1214 keysym
= XLookupKeysym(&event
.xkey
, 0);
1261 if (moment
!= RIGHT
)
1272 wWindowConstrainSize(wwin
, &ww
, &wh
);
1275 if (wPreferences
.ws_cycle
){
1276 if (src_x
+ off_x
+ ww
< 20){
1277 if(!scr
->current_workspace
) {
1278 wWorkspaceChange(scr
, scr
->workspace_count
-1);
1280 else wWorkspaceChange(scr
, scr
->current_workspace
-1);
1283 else if (src_x
+ off_x
+ 20 > scr_width
){
1284 if(scr
->current_workspace
== scr
->workspace_count
-1) {
1285 wWorkspaceChange(scr
, 0);
1287 else wWorkspaceChange(scr
, scr
->current_workspace
+1);
1292 if (src_x
+ off_x
+ ww
< 20)
1293 off_x
= 20 - ww
- src_x
;
1294 else if (src_x
+ off_x
+ 20 > scr_width
)
1295 off_x
= scr_width
- 20 - src_x
;
1298 if (src_y
+ off_y
+ wh
< 20) {
1299 off_y
= 20 - wh
- src_y
;
1301 else if (src_y
+ off_y
+ 20 > scr_height
) {
1302 off_y
= scr_height
- 20 - src_y
;
1311 WMHandleEvent(&event
);
1318 if (wwin
->flags
.shaded
&& !scr
->selected_windows
){
1319 moveGeometryDisplayCentered(scr
, src_x
+off_x
+ w
/2, src_y
+off_y
+ h
/2);
1323 unmapPositionDisplay(wwin
);
1324 mapGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1326 else if(!scr
->selected_windows
){
1327 unmapGeometryDisplay(wwin
);
1328 mapPositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1332 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1333 if(scr
->selected_windows
)
1334 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1335 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1338 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1343 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1345 else if(!scr
->selected_windows
)
1346 showPosition(wwin
, src_x
+off_x
, src_y
+off_y
);
1350 scr
->keymove_tick
=0;
1352 WMDeleteTimerWithClientData(&looper);
1354 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1355 if(scr
->selected_windows
)
1356 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1357 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1360 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1364 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1365 unmapGeometryDisplay(wwin
);
1368 unmapPositionDisplay(wwin
);
1369 XUngrabKeyboard(dpy
, CurrentTime
);
1370 XUngrabPointer(dpy
, CurrentTime
);
1374 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1376 list
=scr
->selected_windows
;
1377 if (!scr
->selected_windows
) {
1378 wWindowMove(wwin
, src_x
+off_x
, src_y
+off_y
);
1379 wWindowSynthConfigureNotify(wwin
);
1381 doWindowMove(wwin
,scr
->selected_windows
,off_x
,off_y
);
1383 wWindowSynthConfigureNotify(list
->head
);
1388 if (wwin
->client
.width
!= ww
)
1389 wwin
->flags
.user_changed_width
= 1;
1391 if (wwin
->client
.height
!= wh
- vert_border
)
1392 wwin
->flags
.user_changed_height
= 1;
1394 wWindowConfigure(wwin
, src_x
+off_x
, src_y
+off_y
,
1395 ww
, wh
- vert_border
);
1396 wWindowSynthConfigureNotify(wwin
);
1398 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1399 wSetFocusTo(scr
, wwin
);
1408 *----------------------------------------------------------------------
1409 * wMouseMoveWindow--
1410 * Move the named window and the other selected ones (if any),
1411 * interactively. Also shows the position of the window, if only one
1412 * window is being moved.
1413 * If the window is not on the selected window list, the selected
1414 * windows are deselected.
1415 * If shift is pressed during the operation, the position display
1416 * is changed to another type.
1419 * True if the window was moved, False otherwise.
1422 * The window(s) position is changed, and the client(s) are
1423 * notified about that.
1424 * The position display configuration may be changed.
1425 *----------------------------------------------------------------------
1428 wMouseMoveWindow(WWindow
*wwin
, XEvent
*ev
)
1430 WScreen
*scr
= wwin
->screen_ptr
;
1432 Window root
= scr
->root_win
;
1433 KeyCode shiftl
, shiftr
;
1437 /* This needs not to change while moving, else bad things can happen */
1438 int opaqueMove
= wPreferences
.opaque_move
;
1440 #ifdef GHOST_WINDOW_MOVE
1443 rimg
= InitGhostWindowMove(scr
);
1446 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1447 XSetWindowAttributes attr
;
1449 attr
.save_under
= True
;
1450 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
,
1451 CWSaveUnder
, &attr
);
1454 initMoveData(wwin
, &moveData
);
1456 moveData
.mouseX
= ev
->xmotion
.x_root
;
1457 moveData
.mouseY
= ev
->xmotion
.y_root
;
1459 if (!wwin
->flags
.selected
) {
1460 /* this window is not selected, unselect others and move only wwin */
1461 wUnselectWindows(scr
);
1464 puts("Moving window");
1466 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1467 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1473 /* XWarpPointer() doesn't seem to generate Motion events, so
1474 we've got to simulate them */
1475 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1476 &event
.xmotion
.y_root
, &junk
, &junk
,
1477 (unsigned *) &junk
);
1479 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1480 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
,
1483 if (event
.type
== MotionNotify
) {
1484 /* compress MotionNotify events */
1485 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1488 switch (event
.type
) {
1490 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1491 && started
&& !scr
->selected_windows
) {
1494 drawFrames(wwin
, scr
->selected_windows
,
1495 moveData
.realX
- wwin
->frame_x
,
1496 moveData
.realY
- wwin
->frame_y
);
1499 if (wPreferences
.move_display
== WDIS_NEW
1500 && !scr
->selected_windows
) {
1501 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1504 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1505 moveData
.winWidth
, moveData
.winHeight
);
1507 if (wPreferences
.move_display
== WDIS_NEW
1508 && !scr
->selected_windows
) {
1510 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1514 drawFrames(wwin
, scr
->selected_windows
,
1515 moveData
.realX
- wwin
->frame_x
,
1516 moveData
.realY
- wwin
->frame_y
);
1523 updateWindowPosition(wwin
, &moveData
,
1524 scr
->selected_windows
== NULL
1525 && wPreferences
.edge_resistance
> 0,
1527 event
.xmotion
.x_root
,
1528 event
.xmotion
.y_root
);
1530 if (!warped
&& !wPreferences
.no_autowrap
) {
1531 int oldWorkspace
= scr
->current_workspace
;
1533 if (wPreferences
.move_display
== WDIS_NEW
1534 && !scr
->selected_windows
) {
1535 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1539 drawFrames(wwin
, scr
->selected_windows
,
1540 moveData
.realX
- wwin
->frame_x
,
1541 moveData
.realY
- wwin
->frame_y
);
1543 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1544 if (scr
->current_workspace
!= oldWorkspace
1545 && wPreferences
.edge_resistance
> 0
1546 && scr
->selected_windows
== NULL
)
1547 updateMoveData(wwin
, &moveData
);
1551 drawFrames(wwin
, scr
->selected_windows
,
1552 moveData
.realX
- wwin
->frame_x
,
1553 moveData
.realY
- wwin
->frame_y
);
1555 if (wPreferences
.move_display
== WDIS_NEW
1556 && !scr
->selected_windows
) {
1558 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
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);
1581 if (!opaqueMove
|| (wPreferences
.move_display
==WDIS_NEW
1582 && !scr
->selected_windows
)) {
1584 if (wPreferences
.move_display
==WDIS_NEW
)
1585 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1594 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1599 drawFrames(wwin
, scr
->selected_windows
,
1600 moveData
.realX
- wwin
->frame_x
,
1601 moveData
.realY
- wwin
->frame_y
);
1603 doWindowMove(wwin
, scr
->selected_windows
,
1604 moveData
.realX
- wwin
->frame_x
,
1605 moveData
.realY
- wwin
->frame_y
);
1607 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1608 wWindowSynthConfigureNotify(wwin
);
1610 XUngrabKeyboard(dpy
, CurrentTime
);
1613 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1614 wSetFocusTo(scr
, wwin
);
1616 if (wPreferences
.move_display
== WDIS_NEW
)
1617 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1619 if (!scr
->selected_windows
) {
1620 /* get rid of the geometry window */
1621 unmapPositionDisplay(wwin
);
1625 puts("End move window");
1631 if (started
&& !opaqueMove
) {
1632 drawFrames(wwin
, scr
->selected_windows
,
1633 moveData
.realX
- wwin
->frame_x
,
1634 moveData
.realY
- wwin
->frame_y
);
1636 WMHandleEvent(&event
);
1639 drawFrames(wwin
, scr
->selected_windows
,
1640 moveData
.realX
- wwin
->frame_x
,
1641 moveData
.realY
- wwin
->frame_y
);
1643 WMHandleEvent(&event
);
1649 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1650 XSetWindowAttributes attr
;
1652 attr
.save_under
= False
;
1653 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
,
1654 CWSaveUnder
, &attr
);
1657 freeMoveData(&moveData
);
1664 #define HCONSTRAIN 2
1667 getResizeDirection(WWindow
*wwin
, int x
, int y
, int dx
, int dy
,
1670 int w
= wwin
->frame
->core
->width
- 1;
1671 int cw
= wwin
->frame
->resizebar_corner_width
;
1674 /* if not resizing through the resizebar */
1675 if (!(flags
& RESIZEBAR
)) {
1676 int xdir
= (abs(x
) < (wwin
->client
.width
/2)) ? LEFT
: RIGHT
;
1677 int ydir
= (abs(y
) < (wwin
->client
.height
/2)) ? UP
: DOWN
;
1678 if (abs(dx
) < 2 || abs(dy
) < 2) {
1679 if (abs(dy
) > abs(dx
))
1684 return (xdir
| ydir
);
1687 /* window is too narrow. allow diagonal resize */
1691 if (flags
& HCONSTRAIN
)
1696 return (LEFT
| ydir
);
1698 return (RIGHT
| ydir
);
1700 /* vertical resize */
1701 if ((x
> cw
) && (x
< w
- cw
))
1709 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1717 wMouseResizeWindow(WWindow
*wwin
, XEvent
*ev
)
1720 WScreen
*scr
= wwin
->screen_ptr
;
1721 Window root
= scr
->root_win
;
1722 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1723 int fw
= wwin
->frame
->core
->width
;
1724 int fh
= wwin
->frame
->core
->height
;
1725 int fx
= wwin
->frame_x
;
1726 int fy
= wwin
->frame_y
;
1727 int is_resizebar
= (wwin
->frame
->resizebar
1728 && ev
->xany
.window
==wwin
->frame
->resizebar
->window
);
1732 int rw
= fw
, rh
= fh
;
1733 int rx1
, ry1
, rx2
, ry2
;
1735 KeyCode shiftl
, shiftr
;
1742 if (wwin
->flags
.shaded
) {
1743 wwarning("internal error: tryein");
1746 orig_x
= ev
->xbutton
.x_root
;
1747 orig_y
= ev
->xbutton
.y_root
;
1751 puts("Resizing window");
1754 wUnselectWindows(scr
);
1759 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1760 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1761 if (!WFLAGP(wwin
, no_titlebar
))
1762 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + TITLEBAR_EXTRA_HEIGHT
;
1766 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
| ButtonReleaseMask
1767 | ButtonPressMask
| ExposureMask
, &event
);
1768 switch (event
.type
) {
1770 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1771 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1773 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1774 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
1775 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1777 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1791 dw
= orig_x
- event
.xmotion
.x_root
;
1792 else if (res
& RIGHT
)
1793 dw
= event
.xmotion
.x_root
- orig_x
;
1795 dh
= orig_y
- event
.xmotion
.y_root
;
1796 else if (res
& DOWN
)
1797 dh
= event
.xmotion
.y_root
- orig_y
;
1799 orig_x
= event
.xmotion
.x_root
;
1800 orig_y
= event
.xmotion
.y_root
;
1805 fh
= rh
- vert_border
;
1806 wWindowConstrainSize(wwin
, &fw
, &fh
);
1810 else if (res
& RIGHT
)
1814 else if (res
& DOWN
)
1816 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1817 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1822 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
1823 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
1825 /* check if resizing through resizebar */
1831 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
1832 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
1833 flags
|= HCONSTRAIN
;
1835 res
= getResizeDirection(wwin
, tx
, ty
,
1836 orig_x
- event
.xmotion
.x_root
,
1837 orig_y
- event
.xmotion
.y_root
, flags
);
1839 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1840 | ButtonReleaseMask
| ButtonPressMask
,
1841 wCursor
[WCUR_RESIZE
], CurrentTime
);
1842 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1847 /* Draw the resize frame for the first time. */
1848 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
1850 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1852 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1857 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
1858 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
1860 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
1861 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1863 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
1865 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1867 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
1868 if (wPreferences
.size_display
== WDIS_NEW
) {
1869 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
1870 orig_fy
+ orig_fh
, res
);
1872 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1881 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1885 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1887 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1889 XUngrabKeyboard(dpy
, CurrentTime
);
1890 unmapGeometryDisplay(wwin
);
1893 if (wwin
->client
.width
!= fw
)
1894 wwin
->flags
.user_changed_width
= 1;
1896 if (wwin
->client
.height
!= fh
- vert_border
)
1897 wwin
->flags
.user_changed_height
= 1;
1899 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
1902 puts("End resize window");
1907 WMHandleEvent(&event
);
1922 wUnselectWindows(WScreen
*scr
)
1926 while (scr
->selected_windows
) {
1927 wwin
= scr
->selected_windows
->head
;
1928 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
1929 wIconSelect(wwin
->icon
);
1931 wSelectWindow(wwin
, False
);
1937 selectWindowsInside(WScreen
*scr
, int x1
, int y1
, int x2
, int y2
)
1941 /* select the windows and put them in the selected window list */
1942 tmpw
= scr
->focused_window
;
1943 while (tmpw
!= NULL
) {
1944 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
1945 if ((tmpw
->frame
->workspace
== scr
->current_workspace
1946 || IS_OMNIPRESENT(tmpw
))
1947 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
1948 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
1949 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
1950 wSelectWindow(tmpw
, True
);
1959 wSelectWindows(WScreen
*scr
, XEvent
*ev
)
1962 Window root
= scr
->root_win
;
1963 GC gc
= scr
->frame_gc
;
1964 int xp
= ev
->xbutton
.x_root
;
1965 int yp
= ev
->xbutton
.y_root
;
1970 puts("Selecting windows");
1972 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
1973 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
1974 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
],
1975 CurrentTime
) != Success
) {
1980 wUnselectWindows(scr
);
1982 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
1984 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
1985 | ButtonPressMask
, &event
);
1987 switch (event
.type
) {
1989 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
1990 x
= event
.xmotion
.x_root
;
1997 y
= event
.xmotion
.y_root
;
2004 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2011 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2014 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2016 XUngrabPointer(dpy
, CurrentTime
);
2017 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
2020 wKWMSelectRootRegion(scr
, x
, y
, w
, h
,
2021 event
.xbutton
.state
& ControlMask
);
2022 #endif /* KWM_HINTS */
2025 puts("End window selection");
2030 WMHandleEvent(&event
);
2038 InteractivePlaceWindow(WWindow
*wwin
, int *x_ret
, int *y_ret
,
2039 unsigned width
, unsigned height
)
2041 WScreen
*scr
= wwin
->screen_ptr
;
2042 Window root
= scr
->root_win
;
2045 KeyCode shiftl
, shiftr
;
2049 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2050 GrabModeAsync
, GrabModeAsync
, None
,
2051 wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2056 if (!WFLAGP(wwin
, no_titlebar
)) {
2057 h
= WMFontHeight(scr
->title_font
) + TITLEBAR_EXTRA_HEIGHT
;
2060 if (!WFLAGP(wwin
, no_resizebar
)) {
2061 height
+= RESIZEBAR_HEIGHT
;
2063 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2064 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
,
2065 (unsigned *) &junk
);
2066 mapPositionDisplay(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2068 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2070 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2071 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2073 WMMaskEvent(dpy
, PointerMotionMask
|ButtonPressMask
|ExposureMask
|KeyPressMask
,
2075 switch (event
.type
) {
2077 if ((event
.xkey
.keycode
== shiftl
)
2078 || (event
.xkey
.keycode
== shiftr
)) {
2079 drawTransparentFrame(wwin
,
2080 x
- width
/2, y
- h
/2, width
, height
);
2081 cyclePositionDisplay(wwin
,
2082 x
- width
/2, y
- h
/2, width
, height
);
2083 drawTransparentFrame(wwin
,
2084 x
- width
/2, y
- h
/2, width
, height
);
2089 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2091 x
= event
.xmotion
.x_root
;
2092 y
= event
.xmotion
.y_root
;
2094 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2095 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2097 showPosition(wwin
, x
- width
/2, y
- h
/2);
2099 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2104 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2106 *x_ret
= x
- width
/2;
2108 XUngrabPointer(dpy
, CurrentTime
);
2109 XUngrabKeyboard(dpy
, CurrentTime
);
2110 /* get rid of the geometry window */
2111 unmapPositionDisplay(wwin
);
2115 WMHandleEvent(&event
);