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"
48 /* How many different types of geometry/position
49 display thingies are there? */
50 #define NUM_DISPLAYS 4
54 #define HORIZONTAL (LEFT|RIGHT)
57 #define VERTICAL (UP|DOWN)
59 /****** Global Variables ******/
60 extern Time LastTimestamp
;
62 extern Cursor wCursor
[WCUR_LAST
];
64 extern WPreferences wPreferences
;
66 extern Atom _XA_WM_PROTOCOLS
;
71 wGetGeometryWindowSize(WScreen
*scr
, unsigned int *width
,
74 *width
= WMWidthOfString(scr
->info_text_font
, "-8888 x -8888", 13);
76 *height
= (6 * WMFontHeight(scr
->info_text_font
)) / 4 - 1;
81 *----------------------------------------------------------------------
82 * checkMouseSamplingRate-
83 * For lowering the mouse motion sampling rate for machines where
84 * it's too high (SGIs). If it returns False then the event should be
86 *----------------------------------------------------------------------
89 checkMouseSamplingRate(XEvent
*ev
)
91 static Time previousMotion
= 0;
93 if (ev
->type
== MotionNotify
) {
94 if (ev
->xmotion
.time
- previousMotion
< DELAY_BETWEEN_MOUSE_SAMPLING
) {
97 previousMotion
= ev
->xmotion
.time
;
106 *----------------------------------------------------------------------
107 * moveGeometryDisplayCentered
109 * routine that moves the geometry/position window on scr so it is
110 * centered over the given coordinates (x,y). Also the window position
111 * is clamped so it stays on the screen at all times.
112 *----------------------------------------------------------------------
115 moveGeometryDisplayCentered(WScreen
*scr
, int x
, int y
)
117 x
-= scr
->geometry_display_width
/ 2;
118 y
-= scr
->geometry_display_height
/ 2;
122 else if (x
> (scr
->scr_width
- scr
->geometry_display_width
- 3))
123 x
= scr
->scr_width
- scr
->geometry_display_width
- 3;
127 else if (y
> (scr
->scr_height
- scr
->geometry_display_height
- 3))
128 y
= scr
->scr_height
- scr
->geometry_display_height
- 3;
130 XMoveWindow(dpy
, scr
->geometry_display
, x
, y
);
135 showPosition(WWindow
*wwin
, int x
, int y
)
137 WScreen
*scr
= wwin
->screen_ptr
;
138 GC gc
= scr
->info_text_gc
;
142 if (wPreferences
.move_display
== WDIS_NEW
) {
144 int width
= wwin
->frame
->core
->width
;
145 int height
= wwin
->frame
->core
->height
;
147 GC lgc
= scr
->line_gc
;
148 XSetForeground(dpy
, lgc
, scr
->line_pixel
);
149 sprintf(num
, "%i", x
);
151 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
-1, scr
->scr_width
, y
-1);
152 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
+height
+2, scr
->scr_width
,
154 XDrawLine(dpy
, scr
->root_win
, lgc
, x
-1, 0, x
-1, scr
->scr_height
);
155 XDrawLine(dpy
, scr
->root_win
, lgc
, x
+width
+2, 0, x
+width
+2,
159 XClearArea(dpy
, scr
->geometry_display
, 1, 1,
160 scr
->geometry_display_width
-2, scr
->geometry_display_height
-2,
162 sprintf(num
, "%+i %-+i", x
, y
);
163 fw
= WMWidthOfString(scr
->info_text_font
, num
, strlen(num
));
165 XSetForeground(dpy
, gc
, scr
->black_pixel
);
167 fh
= WMFontHeight(scr
->info_text_font
);
168 WMDrawString(scr
->wmscreen
, scr
->geometry_display
, gc
,
170 (scr
->geometry_display_width
- 2 - fw
) / 2,
171 (scr
->geometry_display_height
-fh
)/2, num
, strlen(num
));
172 wDrawBevel(scr
->geometry_display
, scr
->geometry_display_width
+1,
173 scr
->geometry_display_height
+1,
174 scr
->widget_texture
, WREL_RAISED
);
180 cyclePositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
182 WScreen
*scr
= wwin
->screen_ptr
;
184 wPreferences
.move_display
++;
185 wPreferences
.move_display
%= NUM_DISPLAYS
;
187 if (wPreferences
.move_display
== WDIS_NEW
) {
188 XUnmapWindow(dpy
, scr
->geometry_display
);
190 if (wPreferences
.move_display
== WDIS_CENTER
) {
191 moveGeometryDisplayCentered(scr
,
192 scr
->scr_width
/2, scr
->scr_height
/2);
193 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
194 moveGeometryDisplayCentered(scr
, 1, 1);
195 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
196 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
198 XMapRaised(dpy
, scr
->geometry_display
);
204 mapPositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
206 WScreen
*scr
= wwin
->screen_ptr
;
208 if (wPreferences
.move_display
== WDIS_NEW
) {
210 } else if (wPreferences
.move_display
== WDIS_CENTER
) {
211 moveGeometryDisplayCentered(scr
, scr
->scr_width
/ 2,
212 scr
->scr_height
/ 2);
213 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
214 moveGeometryDisplayCentered(scr
, 1, 1);
215 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
216 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
218 XMapRaised(dpy
, scr
->geometry_display
);
219 showPosition(wwin
, x
, y
);
222 #define unmapPositionDisplay(w) \
223 XUnmapWindow(dpy, (w)->screen_ptr->geometry_display);
227 showGeometry(WWindow
*wwin
, int x1
, int y1
, int x2
, int y2
, int direction
)
229 WScreen
*scr
= wwin
->screen_ptr
;
230 Window root
= scr
->root_win
;
231 GC gc
= scr
->line_gc
;
232 int ty
, by
, my
, x
, y
, mx
, s
;
237 ty
= y1
+ wwin
->frame
->top_width
;
238 by
= y2
- wwin
->frame
->bottom_width
;
239 fw
= WMWidthOfString(scr
->info_text_font
, "8888", 4);
240 fh
= WMFontHeight(scr
->info_text_font
);
242 if (wPreferences
.size_display
== WDIS_NEW
) {
243 XSetForeground(dpy
, gc
, scr
->line_pixel
);
245 /* vertical geometry */
246 if (((direction
& LEFT
) && (x2
< scr
->scr_width
- fw
)) || (x1
< fw
)) {
257 segment
[0].x1
= x
- (s
+ 6); segment
[0].y1
= ty
;
258 segment
[0].x2
= x
- (s
- 10); segment
[0].y2
= ty
;
261 segment
[1].x1
= x
- (s
- 2); segment
[1].y1
= ty
+ 1;
262 segment
[1].x2
= x
- (s
- 5); segment
[1].y2
= ty
+ 7;
264 segment
[2].x1
= x
- (s
- 2); segment
[2].y1
= ty
+ 1;
265 segment
[2].x2
= x
- (s
+ 1); segment
[2].y2
= ty
+ 7;
268 segment
[3].x1
= x
- (s
- 2); segment
[3].y1
= ty
+ 1;
269 segment
[3].x2
= x
- (s
- 2); segment
[3].y2
= my
- fh
/2 - 1;
271 XDrawSegments(dpy
, root
, gc
, segment
, 4);
279 segment
[1].y1
= by
- 1;
280 segment
[1].y2
= by
- 7;
282 segment
[2].y1
= by
- 1;
283 segment
[2].y2
= by
- 7;
286 segment
[3].y1
= my
+ fh
/2 + 2;
287 segment
[3].y2
= by
- 1;
289 XDrawSegments(dpy
, root
, gc
, segment
, 4);
291 sprintf(num
, "%i", (by
- ty
- wwin
->normal_hints
->base_height
) /
292 wwin
->normal_hints
->height_inc
);
293 fw
= WMWidthOfString(scr
->info_text_font
, num
, strlen(num
));
295 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
297 /* Display the height. */
298 WMDrawString(scr
->wmscreen
, root
, gc
, scr
->info_text_font
,
299 x
- s
+ 3 - fw
/2, my
- fh
/2 + 1, num
, strlen(num
));
300 XSetForeground(dpy
, gc
, scr
->line_pixel
);
301 /* horizontal geometry */
309 mx
= x1
+ (x2
- x1
)/2;
310 sprintf(num
, "%i", (x2
- x1
- wwin
->normal_hints
->base_width
) /
311 wwin
->normal_hints
->width_inc
);
312 fw
= WMWidthOfString(scr
->info_text_font
, num
, strlen(num
));
316 segment
[0].x1
= x1
; segment
[0].y1
= y
- (s
+ 6);
317 segment
[0].x2
= x1
; segment
[0].y2
= y
- (s
- 10);
320 segment
[1].x1
= x1
+ 7; segment
[1].y1
= y
- (s
+ 1);
321 segment
[1].x2
= x1
+ 1; segment
[1].y2
= y
- (s
- 2);
323 segment
[2].x1
= x1
+ 1; segment
[2].y1
= y
- (s
- 2);
324 segment
[2].x2
= x1
+ 7; segment
[2].y2
= y
- (s
- 5);
327 segment
[3].x1
= x1
+ 1; segment
[3].y1
= y
- (s
- 2);
328 segment
[3].x2
= mx
- fw
/2 - 2; segment
[3].y2
= y
- (s
- 2);
330 XDrawSegments(dpy
, root
, gc
, segment
, 4);
334 segment
[0].x1
= x2
+ 1;
335 segment
[0].x2
= x2
+ 1;
338 segment
[1].x1
= x2
- 6;
342 segment
[2].x2
= x2
- 6;
345 segment
[3].x1
= mx
+ fw
/2 + 2;
348 XDrawSegments(dpy
, root
, gc
, segment
, 4);
350 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
352 /* Display the width. */
353 WMDrawString(scr
->wmscreen
, root
, gc
, scr
->info_text_font
,
354 mx
- fw
/2 + 1, y
- s
- fh
/2 + 1, num
, strlen(num
));
356 XClearArea(dpy
, scr
->geometry_display
, 1, 1,
357 scr
->geometry_display_width
-2, scr
->geometry_display_height
-2,
359 sprintf(num
, "%i x %-i", (x2
- x1
- wwin
->normal_hints
->base_width
)
360 / wwin
->normal_hints
->width_inc
,
361 (by
- ty
- wwin
->normal_hints
->base_height
)
362 / wwin
->normal_hints
->height_inc
);
363 fw
= WMWidthOfString(scr
->info_text_font
, num
, strlen(num
));
365 XSetForeground(dpy
, scr
->info_text_gc
, scr
->black_pixel
);
367 /* Display the height. */
368 WMDrawString(scr
->wmscreen
, scr
->geometry_display
, scr
->info_text_gc
,
370 (scr
->geometry_display_width
-fw
)/2,
371 (scr
->geometry_display_height
-fh
)/2, num
, strlen(num
));
372 wDrawBevel(scr
->geometry_display
, scr
->geometry_display_width
+1,
373 scr
->geometry_display_height
+1,
374 scr
->widget_texture
, WREL_RAISED
);
380 cycleGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
, int dir
)
382 WScreen
*scr
= wwin
->screen_ptr
;
384 wPreferences
.size_display
++;
385 wPreferences
.size_display
%= NUM_DISPLAYS
;
387 if (wPreferences
.size_display
== WDIS_NEW
) {
388 XUnmapWindow(dpy
, scr
->geometry_display
);
390 if (wPreferences
.size_display
== WDIS_CENTER
) {
391 moveGeometryDisplayCentered(scr
,
392 scr
->scr_width
/ 2, scr
->scr_height
/ 2);
393 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
394 moveGeometryDisplayCentered(scr
, 1, 1);
395 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
396 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
398 XMapRaised(dpy
, scr
->geometry_display
);
399 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, dir
);
405 mapGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
407 WScreen
*scr
= wwin
->screen_ptr
;
409 if (wPreferences
.size_display
== WDIS_NEW
)
412 if (wPreferences
.size_display
== WDIS_CENTER
) {
413 moveGeometryDisplayCentered(scr
, scr
->scr_width
/ 2,
414 scr
->scr_height
/ 2);
415 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
416 moveGeometryDisplayCentered(scr
, 1, 1);
417 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
418 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
420 XMapRaised(dpy
, scr
->geometry_display
);
421 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, 0);
424 #define unmapGeometryDisplay(w) \
425 XUnmapWindow(dpy, (w)->screen_ptr->geometry_display);
429 doWindowMove(WWindow
*wwin
, WMBag
*bag
, int dx
, int dy
)
433 int scr_width
= wwin
->screen_ptr
->scr_width
;
434 int scr_height
= wwin
->screen_ptr
->scr_height
;
436 if (!bag
|| !WMGetBagItemCount(bag
)) {
437 wWindowMove(wwin
, wwin
->frame_x
+ dx
, wwin
->frame_y
+ dy
);
440 for (i
= 0; i
< WMGetBagItemCount(bag
); i
++) {
441 tmpw
= WMGetFromBag(bag
, i
);
442 x
= tmpw
->frame_x
+ dx
;
443 y
= tmpw
->frame_y
+ dy
;
445 /* don't let windows become unreachable */
447 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
448 x
= 20 - (int)tmpw
->frame
->core
->width
;
449 else if (x
+ 20 > scr_width
)
452 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
453 y
= 20 - (int)tmpw
->frame
->core
->height
;
454 else if (y
+ 20 > scr_height
)
457 wWindowMove(tmpw
, x
, y
);
464 drawTransparentFrame(WWindow
*wwin
, int x
, int y
, int width
, int height
)
466 Window root
= wwin
->screen_ptr
->root_win
;
467 GC gc
= wwin
->screen_ptr
->frame_gc
;
471 if (!WFLAGP(wwin
, no_titlebar
) && !wwin
->flags
.shaded
) {
472 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + TITLEBAR_EXTRA_HEIGHT
;
474 if (!WFLAGP(wwin
, no_resizebar
) && !wwin
->flags
.shaded
) {
475 /* Can't use wwin-frame->bottom_width because, in some cases
476 (e.g. interactive placement), frame does not point to anything. */
477 bottom
= RESIZEBAR_HEIGHT
- 1;
479 XDrawRectangle(dpy
, root
, gc
, x
, y
, width
+ 1, height
+ 1);
482 XDrawLine(dpy
, root
, gc
, x
+ 1, y
+ h
, x
+ width
+ 1, y
+ h
);
485 XDrawLine(dpy
, root
, gc
, x
+ 1,
488 y
+ height
- bottom
);
494 drawFrames(WWindow
*wwin
, WMBag
*bag
, int dx
, int dy
)
497 int scr_width
= wwin
->screen_ptr
->scr_width
;
498 int scr_height
= wwin
->screen_ptr
->scr_height
;
503 x
= wwin
->frame_x
+ dx
;
504 y
= wwin
->frame_y
+ dy
;
506 drawTransparentFrame(wwin
, x
, y
,
507 wwin
->frame
->core
->width
,
508 wwin
->frame
->core
->height
);
512 for (i
= 0; i
< WMGetBagItemCount(bag
); i
++) {
513 tmpw
= WMGetFromBag(bag
, i
);
514 x
= tmpw
->frame_x
+ dx
;
515 y
= tmpw
->frame_y
+ dy
;
517 /* don't let windows become unreachable */
519 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
520 x
= 20 - (int)tmpw
->frame
->core
->width
;
521 else if (x
+ 20 > scr_width
)
524 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
525 y
= 20 - (int)tmpw
->frame
->core
->height
;
526 else if (y
+ 20 > scr_height
)
529 drawTransparentFrame(tmpw
, x
, y
, tmpw
->frame
->core
->width
,
530 tmpw
->frame
->core
->height
);
543 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &ev
)) ;
548 crossWorkspace(WScreen
*scr
, WWindow
*wwin
, int opaque_move
,
549 int new_workspace
, int rewind
)
551 /* do not let window be unmapped */
553 wwin
->flags
.changing_workspace
= 1;
554 wWindowChangeWorkspace(wwin
, new_workspace
);
556 /* go to new workspace */
557 wWorkspaceChange(scr
, new_workspace
);
559 wwin
->flags
.changing_workspace
= 0;
562 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, scr
->scr_width
- 20, 0);
564 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, -(scr
->scr_width
- 20), 0);
569 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
570 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
571 GrabModeAsync
, None
, wCursor
[WCUR_MOVE
], CurrentTime
);
579 /* arrays of WWindows sorted by the respective border position */
580 WWindow
**topList
; /* top border */
581 WWindow
**leftList
; /* left border */
582 WWindow
**rightList
; /* right border */
583 WWindow
**bottomList
; /* bottom border */
586 /* index of window in the above lists indicating the relative position
587 * of the window with the others */
593 int rubCount
; /* for workspace switching */
595 int winWidth
, winHeight
; /* width/height of the window */
596 int realX
, realY
; /* actual position of the window */
597 int calcX
, calcY
; /* calculated position of window */
598 int omouseX
, omouseY
; /* old mouse position */
599 int mouseX
, mouseY
; /* last known position of the pointer */
602 #define WTOP(w) (w)->frame_y
603 #define WLEFT(w) (w)->frame_x
604 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width + FRAME_BORDER_WIDTH)
605 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height + FRAME_BORDER_WIDTH)
608 compareWTop(const void *a
, const void *b
)
610 WWindow
*wwin1
= *(WWindow
**)a
;
611 WWindow
*wwin2
= *(WWindow
**)b
;
613 if (WTOP(wwin1
) > WTOP(wwin2
))
615 else if (WTOP(wwin1
) < WTOP(wwin2
))
623 compareWLeft(const void *a
, const void *b
)
625 WWindow
*wwin1
= *(WWindow
**)a
;
626 WWindow
*wwin2
= *(WWindow
**)b
;
628 if (WLEFT(wwin1
) > WLEFT(wwin2
))
630 else if (WLEFT(wwin1
) < WLEFT(wwin2
))
638 compareWRight(const void *a
, const void *b
)
640 WWindow
*wwin1
= *(WWindow
**)a
;
641 WWindow
*wwin2
= *(WWindow
**)b
;
643 if (WRIGHT(wwin1
) < WRIGHT(wwin2
))
645 else if (WRIGHT(wwin1
) > WRIGHT(wwin2
))
654 compareWBottom(const void *a
, const void *b
)
656 WWindow
*wwin1
= *(WWindow
**)a
;
657 WWindow
*wwin2
= *(WWindow
**)b
;
659 if (WBOTTOM(wwin1
) < WBOTTOM(wwin2
))
661 else if (WBOTTOM(wwin1
) > WBOTTOM(wwin2
))
669 updateResistance(WWindow
*wwin
, MoveData
*data
, int newX
, int newY
)
672 int newX2
= newX
+ data
->winWidth
;
673 int newY2
= newY
+ data
->winHeight
;
676 if (newX
< data
->realX
) {
677 if (data
->rightIndex
> 0
678 && newX
< WRIGHT(data
->rightList
[data
->rightIndex
-1])) {
680 } else if (data
->leftIndex
<= data
->count
-1
681 && newX2
<= WLEFT(data
->leftList
[data
->leftIndex
])) {
684 } else if (newX
> data
->realX
) {
685 if (data
->leftIndex
> 0
686 && newX2
> WLEFT(data
->leftList
[data
->leftIndex
-1])) {
688 } else if (data
->rightIndex
<= data
->count
-1
689 && newX
>= WRIGHT(data
->rightList
[data
->rightIndex
])) {
695 if (newY
< data
->realY
) {
696 if (data
->bottomIndex
> 0
697 && newY
< WBOTTOM(data
->bottomList
[data
->bottomIndex
-1])) {
699 } else if (data
->topIndex
<= data
->count
-1
700 && newY2
<= WTOP(data
->topList
[data
->topIndex
])) {
703 } else if (newY
> data
->realY
) {
704 if (data
->topIndex
> 0
705 && newY2
> WTOP(data
->topList
[data
->topIndex
-1])) {
707 } else if (data
->bottomIndex
<= data
->count
-1
708 && newY
>= WBOTTOM(data
->bottomList
[data
->bottomIndex
])) {
717 /* TODO: optimize this */
718 if (data
->realY
< WBOTTOM(data
->bottomList
[0])) {
719 data
->bottomIndex
= 0;
721 if (data
->realX
< WRIGHT(data
->rightList
[0])) {
722 data
->rightIndex
= 0;
724 if ((data
->realX
+ data
->winWidth
) > WLEFT(data
->leftList
[0])) {
727 if ((data
->realY
+ data
->winHeight
) > WTOP(data
->topList
[0])) {
730 for (i
= 0; i
< data
->count
; i
++) {
731 if (data
->realY
> WBOTTOM(data
->bottomList
[i
])) {
732 data
->bottomIndex
= i
+ 1;
734 if (data
->realX
> WRIGHT(data
->rightList
[i
])) {
735 data
->rightIndex
= i
+ 1;
737 if ((data
->realX
+ data
->winWidth
) < WLEFT(data
->leftList
[i
])) {
738 data
->leftIndex
= i
+ 1;
740 if ((data
->realY
+ data
->winHeight
) < WTOP(data
->topList
[i
])) {
741 data
->topIndex
= i
+ 1;
748 freeMoveData(MoveData
*data
)
753 free(data
->leftList
);
755 free(data
->rightList
);
756 if (data
->bottomList
)
757 free(data
->bottomList
);
762 updateMoveData(WWindow
*wwin
, MoveData
*data
)
764 WScreen
*scr
= wwin
->screen_ptr
;
769 tmp
= scr
->focused_window
;
771 if (tmp
!= wwin
&& scr
->current_workspace
== tmp
->frame
->workspace
772 && !tmp
->flags
.miniaturized
773 && !tmp
->flags
.hidden
774 && !tmp
->flags
.obscured
775 && !WFLAGP(tmp
, sunken
)) {
776 data
->topList
[data
->count
] = tmp
;
777 data
->leftList
[data
->count
] = tmp
;
778 data
->rightList
[data
->count
] = tmp
;
779 data
->bottomList
[data
->count
] = tmp
;
785 if (data
->count
== 0) {
788 data
->rightIndex
= 0;
789 data
->bottomIndex
= 0;
794 * order from closest to the border of the screen to farthest
796 qsort(data
->topList
, data
->count
, sizeof(WWindow
**), compareWTop
);
797 qsort(data
->leftList
, data
->count
, sizeof(WWindow
**), compareWLeft
);
798 qsort(data
->rightList
, data
->count
, sizeof(WWindow
**), compareWRight
);
799 qsort(data
->bottomList
, data
->count
, sizeof(WWindow
**), compareWBottom
);
801 /* figure the position of the window relative to the others */
804 data
->leftIndex
= -1;
805 data
->rightIndex
= -1;
806 data
->bottomIndex
= -1;
808 if (WTOP(wwin
) < WBOTTOM(data
->bottomList
[0])) {
809 data
->bottomIndex
= 0;
811 if (WLEFT(wwin
) < WRIGHT(data
->rightList
[0])) {
812 data
->rightIndex
= 0;
814 if (WRIGHT(wwin
) > WLEFT(data
->leftList
[0])) {
817 if (WBOTTOM(wwin
) > WTOP(data
->topList
[0])) {
820 for (i
= 0; i
< data
->count
; i
++) {
821 if (WTOP(wwin
) >= WBOTTOM(data
->bottomList
[i
])) {
822 data
->bottomIndex
= i
+ 1;
824 if (WLEFT(wwin
) >= WRIGHT(data
->rightList
[i
])) {
825 data
->rightIndex
= i
+ 1;
827 if (WRIGHT(wwin
) <= WLEFT(data
->leftList
[i
])) {
828 data
->leftIndex
= i
+ 1;
830 if (WBOTTOM(wwin
) <= WTOP(data
->topList
[i
])) {
831 data
->topIndex
= i
+ 1;
838 initMoveData(WWindow
*wwin
, MoveData
*data
)
843 memset(data
, 0, sizeof(MoveData
));
845 for (i
= 0, tmp
= wwin
->screen_ptr
->focused_window
;
847 tmp
= tmp
->prev
, i
++);
850 data
->topList
= wmalloc(sizeof(WWindow
*) * i
);
851 data
->leftList
= wmalloc(sizeof(WWindow
*) * i
);
852 data
->rightList
= wmalloc(sizeof(WWindow
*) * i
);
853 data
->bottomList
= wmalloc(sizeof(WWindow
*) * i
);
855 updateMoveData(wwin
, data
);
858 data
->realX
= wwin
->frame_x
;
859 data
->realY
= wwin
->frame_y
;
860 data
->calcX
= wwin
->frame_x
;
861 data
->calcY
= wwin
->frame_y
;
863 data
->winWidth
= wwin
->frame
->core
->width
+ 2;
864 data
->winHeight
= wwin
->frame
->core
->height
+ 2;
869 checkWorkspaceChange(WWindow
*wwin
, MoveData
*data
, Bool opaqueMove
)
871 WScreen
*scr
= wwin
->screen_ptr
;
872 Bool changed
= False
;
874 if (data
->mouseX
<= 1) {
875 if (scr
->current_workspace
> 0) {
877 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
- 1,
882 } else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
) {
884 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->workspace_count
- 1,
889 } else if (data
->mouseX
>= scr
->scr_width
- 2) {
891 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
893 if (wPreferences
.ws_cycle
894 || scr
->workspace_count
== MAX_WORKSPACES
) {
896 crossWorkspace(scr
, wwin
, opaqueMove
, 0, False
);
900 /* if user insists on trying to go to next workspace even when
901 * it's already the last, create a new one */
902 else if (data
->omouseX
== data
->mouseX
903 && wPreferences
.ws_advance
) {
905 /* detect user "rubbing" the window against the edge */
906 if (data
->rubCount
> 0
907 && data
->omouseY
- data
->mouseY
> MOVE_THRESHOLD
) {
909 data
->rubCount
= -(data
->rubCount
+ 1);
911 } else if (data
->rubCount
<= 0
912 && data
->mouseY
- data
->omouseY
> MOVE_THRESHOLD
) {
914 data
->rubCount
= -data
->rubCount
+ 1;
917 /* create a new workspace */
918 if (abs(data
->rubCount
) > 2) {
919 /* go to next workspace */
922 crossWorkspace(scr
, wwin
, opaqueMove
,
923 scr
->current_workspace
+1, False
);
927 } else if (scr
->current_workspace
< scr
->workspace_count
) {
929 /* go to next workspace */
930 crossWorkspace(scr
, wwin
, opaqueMove
,
931 scr
->current_workspace
+1, False
);
944 updateWindowPosition(WWindow
*wwin
, MoveData
*data
, Bool doResistance
,
945 Bool opaqueMove
, int newMouseX
, int newMouseY
)
947 WScreen
*scr
= wwin
->screen_ptr
;
948 int dx
, dy
; /* how much mouse moved */
949 int winL
, winR
, winT
, winB
; /* requested new window position */
950 int newX
, newY
; /* actual new window position */
951 Bool hresist
, vresist
;
960 /* check the direction of the movement */
961 dx
= newMouseX
- data
->mouseX
;
962 dy
= newMouseY
- data
->mouseY
;
964 data
->omouseX
= data
->mouseX
;
965 data
->omouseY
= data
->mouseY
;
966 data
->mouseX
= newMouseX
;
967 data
->mouseY
= newMouseY
;
969 winL
= data
->calcX
+ dx
;
970 winR
= data
->calcX
+ data
->winWidth
+ dx
;
971 winT
= data
->calcY
+ dy
;
972 winB
= data
->calcY
+ data
->winHeight
+ dy
;
984 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
985 attract
= wPreferences
.attract
;
986 /* horizontal movement: check horizontal edge resistances */
989 /* window is the leftmost window: check against screen edge */
990 l_edge
= scr
->totalUsableArea
.x1
;
991 r_edge
= scr
->totalUsableArea
.x2
+ resist
;
992 edge_l
= scr
->totalUsableArea
.x1
- resist
;
993 edge_r
= scr
->totalUsableArea
.x2
;
996 if ((data
->rightIndex
>= 0) && (data
->rightIndex
<= data
->count
)) {
999 for (i
= data
->rightIndex
- 1; i
>= 0; i
--) {
1000 looprw
= data
->rightList
[i
];
1001 if (!(data
->realY
> WBOTTOM(looprw
)
1002 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1004 || ((data
->realX
< (WRIGHT(looprw
) + 2)) && dx
< 0)) {
1005 l_edge
= WRIGHT(looprw
) + 1;
1006 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1013 for (i
= data
->rightIndex
; i
< data
->count
; i
++) {
1014 looprw
= data
->rightList
[i
];
1015 if(!(data
->realY
> WBOTTOM(looprw
)
1016 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1017 r_edge
= WRIGHT(looprw
) + 1;
1018 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1025 if ((data
->leftIndex
>= 0) && (data
->leftIndex
<= data
->count
)) {
1028 for (i
= data
->leftIndex
- 1; i
>= 0; i
--) {
1029 looprw
= data
->leftList
[i
];
1030 if (!(data
->realY
> WBOTTOM(looprw
)
1031 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1033 || (((data
->realX
+ data
->winWidth
) > (WLEFT(looprw
) - 1)) && dx
> 0)) {
1034 edge_r
= WLEFT(looprw
);
1035 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1042 for (i
= data
->leftIndex
; i
< data
->count
; i
++) {
1043 looprw
= data
->leftList
[i
];
1044 if(!(data
->realY
> WBOTTOM(looprw
)
1045 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1046 edge_l
= WLEFT(looprw
);
1047 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1054 printf("%d %d\n",winL,winR);
1055 printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);
1058 if ((winL
- l_edge
) < (r_edge
- winL
)) {
1060 if ((attract
&& winL
<= l_edge
+ resist
&& winL
>= l_edge
- resist
)
1061 || (dx
< 0 && winL
<= l_edge
&& winL
>= l_edge
- resist
)) {
1067 if (resist
> 0 && attract
&& winL
>= r_edge
- resist
&& winL
<= r_edge
+ resist
) {
1073 if ((winR
- edge_l
) < (edge_r
- winR
)) {
1074 if (resist
> 0 && attract
&& winR
<= edge_l
+ resist
&& winR
>= edge_l
- resist
) {
1075 newX
= edge_l
- data
->winWidth
;
1080 if ((attract
&& winR
>= edge_r
- resist
&& winR
<= edge_r
+ resist
)
1081 || (dx
> 0 && winR
>= edge_r
&& winR
<= edge_r
+ resist
)) {
1082 newX
= edge_r
- data
->winWidth
;
1089 t_edge
= scr
->totalUsableArea
.y1
;
1090 b_edge
= scr
->totalUsableArea
.y2
+ resist
;
1091 edge_t
= scr
->totalUsableArea
.y1
- resist
;
1092 edge_b
= scr
->totalUsableArea
.y2
;
1094 if ((data
->bottomIndex
>= 0) && (data
->bottomIndex
<= data
->count
)) {
1097 for (i
= data
->bottomIndex
- 1; i
>= 0; i
--) {
1098 looprw
= data
->bottomList
[i
];
1099 if (!(data
->realX
> WRIGHT(looprw
)
1100 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1102 || ((data
->realY
< (WBOTTOM(looprw
) + 2)) && dy
< 0)) {
1103 t_edge
= WBOTTOM(looprw
) + 1;
1104 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1111 for (i
= data
->bottomIndex
; i
< data
->count
; i
++) {
1112 looprw
= data
->bottomList
[i
];
1113 if(!(data
->realX
> WRIGHT(looprw
)
1114 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1115 b_edge
= WBOTTOM(looprw
) + 1;
1116 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1123 if ((data
->topIndex
>= 0) && (data
->topIndex
<= data
->count
)) {
1126 for (i
= data
->topIndex
- 1; i
>= 0; i
--) {
1127 looprw
= data
->topList
[i
];
1128 if (!(data
->realX
> WRIGHT(looprw
)
1129 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1131 || (((data
->realY
+ data
->winHeight
) > (WTOP(looprw
) - 1)) && dy
> 0)) {
1132 edge_b
= WTOP(looprw
);
1133 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1140 for (i
= data
->topIndex
; i
< data
->count
; i
++) {
1141 looprw
= data
->topList
[i
];
1142 if(!(data
->realX
> WRIGHT(looprw
)
1143 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1144 edge_t
= WTOP(looprw
);
1145 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1151 if ((winT
- t_edge
) < (b_edge
- winT
)) {
1153 if ((attract
&& winT
<= t_edge
+ resist
&& winT
>= t_edge
- resist
)
1154 || (dy
< 0 && winT
<= t_edge
&& winT
>= t_edge
- resist
)) {
1161 if (resist
> 0 && attract
&& winT
>= b_edge
- resist
&& winT
<= b_edge
+ resist
) {
1167 if ((winB
- edge_t
) < (edge_b
- winB
)) {
1168 if (resist
> 0 && attract
&& winB
<= edge_t
+ resist
&& winB
>= edge_t
- resist
) {
1169 newY
= edge_t
- data
->winHeight
;
1175 if ((attract
&& winB
>= edge_b
- resist
&& winB
<= edge_b
+ resist
)
1176 || (dy
> 0 && winB
>= edge_b
&& winB
<= edge_b
+ resist
)) {
1177 newY
= edge_b
- data
->winHeight
;
1187 /* update window position */
1191 if (((dx
> 0 && data
->calcX
- data
->realX
> 0)
1192 || (dx
< 0 && data
->calcX
- data
->realX
< 0)) && !hresist
)
1195 if (((dy
> 0 && data
->calcY
- data
->realY
> 0)
1196 || (dy
< 0 && data
->calcY
- data
->realY
< 0)) && !vresist
)
1199 if (data
->realX
!= newX
|| data
->realY
!= newY
) {
1201 if (wPreferences
.move_display
== WDIS_NEW
1202 && !scr
->selected_windows
) {
1203 showPosition(wwin
, data
->realX
, data
->realY
);
1206 doWindowMove(wwin
, scr
->selected_windows
,
1207 newX
- wwin
->frame_x
,
1208 newY
- wwin
->frame_y
);
1211 drawFrames(wwin
, scr
->selected_windows
,
1212 data
->realX
- wwin
->frame_x
,
1213 data
->realY
- wwin
->frame_y
);
1216 if (!scr
->selected_windows
1217 && wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
1219 moveGeometryDisplayCentered(scr
, newX
+ data
->winWidth
/2,
1220 newY
+ data
->winHeight
/2);
1225 drawFrames(wwin
, scr
->selected_windows
,
1226 newX
- wwin
->frame_x
,
1227 newY
- wwin
->frame_y
);
1230 if (!scr
->selected_windows
) {
1231 showPosition(wwin
, newX
, newY
);
1236 /* recalc relative window position */
1237 if (doResistance
&& (data
->realX
!= newX
|| data
->realY
!= newY
)) {
1238 updateResistance(wwin
, data
, newX
, newY
);
1246 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1249 wKeyboardMoveResizeWindow(WWindow
*wwin
)
1251 WScreen
*scr
= wwin
->screen_ptr
;
1252 Window root
= scr
->root_win
;
1254 int w
= wwin
->frame
->core
->width
;
1255 int h
= wwin
->frame
->core
->height
;
1256 int scr_width
= wwin
->screen_ptr
->scr_width
;
1257 int scr_height
= wwin
->screen_ptr
->scr_height
;
1258 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1259 int src_x
= wwin
->frame_x
;
1260 int src_y
= wwin
->frame_y
;
1261 int done
,off_x
,off_y
,ww
,wh
;
1264 KeySym keysym
=NoSymbol
;
1266 KeyCode shiftl
,shiftr
,ctrll
,ctrlmode
;
1268 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1269 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1270 ctrll
= XKeysymToKeycode(dpy
, XK_Control_L
);
1271 ctrlmode
=done
=off_x
=off_y
=0;
1275 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1277 if (!wwin
->flags
.selected
) {
1278 wUnselectWindows(scr
);
1281 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1282 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
1283 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
);
1285 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1286 if(scr
->selected_windows
)
1287 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1288 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1289 if(!scr
->selected_windows
)
1290 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1292 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1301 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1302 | ButtonPressMask
| ExposureMask
, &event
);
1303 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1304 if(scr
->selected_windows
)
1305 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1306 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1307 /*** I HATE EDGE RESISTANCE - ]d ***/
1310 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1314 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1319 switch (event
.type
) {
1322 if (event
.xkey
.time
- lastTime
> 50) {
1323 kspeed
/=(1 + (event
.xkey
.time
- lastTime
)/100);
1329 if (kspeed
< _KS
) kspeed
= _KS
;
1330 lastTime
= event
.xkey
.time
;
1332 if (event
.xkey
.state
& ControlMask
&& !wwin
->flags
.shaded
) {
1334 wUnselectWindows(scr
);
1339 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
) {
1341 cycleGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
, 0);
1343 cyclePositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1347 keysym
= XLookupKeysym(&event
.xkey
, 0);
1394 if (moment
!= RIGHT
)
1405 wWindowConstrainSize(wwin
, &ww
, &wh
);
1408 if (wPreferences
.ws_cycle
){
1409 if (src_x
+ off_x
+ ww
< 20){
1410 if(!scr
->current_workspace
) {
1411 wWorkspaceChange(scr
, scr
->workspace_count
-1);
1413 else wWorkspaceChange(scr
, scr
->current_workspace
-1);
1416 else if (src_x
+ off_x
+ 20 > scr_width
){
1417 if(scr
->current_workspace
== scr
->workspace_count
-1) {
1418 wWorkspaceChange(scr
, 0);
1420 else wWorkspaceChange(scr
, scr
->current_workspace
+1);
1425 if (src_x
+ off_x
+ ww
< 20)
1426 off_x
= 20 - ww
- src_x
;
1427 else if (src_x
+ off_x
+ 20 > scr_width
)
1428 off_x
= scr_width
- 20 - src_x
;
1431 if (src_y
+ off_y
+ wh
< 20) {
1432 off_y
= 20 - wh
- src_y
;
1434 else if (src_y
+ off_y
+ 20 > scr_height
) {
1435 off_y
= scr_height
- 20 - src_y
;
1444 WMHandleEvent(&event
);
1451 if (wwin
->flags
.shaded
&& !scr
->selected_windows
){
1452 moveGeometryDisplayCentered(scr
, src_x
+off_x
+ w
/2, src_y
+off_y
+ h
/2);
1456 unmapPositionDisplay(wwin
);
1457 mapGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1459 else if(!scr
->selected_windows
){
1460 unmapGeometryDisplay(wwin
);
1461 mapPositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1465 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1466 if(scr
->selected_windows
)
1467 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1468 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1471 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1476 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1478 else if(!scr
->selected_windows
)
1479 showPosition(wwin
, src_x
+off_x
, src_y
+off_y
);
1483 scr
->keymove_tick
=0;
1485 WMDeleteTimerWithClientData(&looper);
1487 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1488 if(scr
->selected_windows
)
1489 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1490 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1493 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1497 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1498 unmapGeometryDisplay(wwin
);
1501 unmapPositionDisplay(wwin
);
1502 XUngrabKeyboard(dpy
, CurrentTime
);
1503 XUngrabPointer(dpy
, CurrentTime
);
1507 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1508 if (!scr
->selected_windows
) {
1509 wWindowMove(wwin
, src_x
+off_x
, src_y
+off_y
);
1510 wWindowSynthConfigureNotify(wwin
);
1513 WMBag
*bag
= scr
->selected_windows
;
1514 doWindowMove(wwin
,scr
->selected_windows
,off_x
,off_y
);
1515 for (i
= 0; i
< WMGetBagItemCount(bag
); i
++) {
1516 wWindowSynthConfigureNotify(WMGetFromBag(bag
, i
));
1520 if (wwin
->client
.width
!= ww
)
1521 wwin
->flags
.user_changed_width
= 1;
1523 if (wwin
->client
.height
!= wh
- vert_border
)
1524 wwin
->flags
.user_changed_height
= 1;
1526 wWindowConfigure(wwin
, src_x
+off_x
, src_y
+off_y
,
1527 ww
, wh
- vert_border
);
1528 wWindowSynthConfigureNotify(wwin
);
1530 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1531 wSetFocusTo(scr
, wwin
);
1540 *----------------------------------------------------------------------
1541 * wMouseMoveWindow--
1542 * Move the named window and the other selected ones (if any),
1543 * interactively. Also shows the position of the window, if only one
1544 * window is being moved.
1545 * If the window is not on the selected window list, the selected
1546 * windows are deselected.
1547 * If shift is pressed during the operation, the position display
1548 * is changed to another type.
1551 * True if the window was moved, False otherwise.
1554 * The window(s) position is changed, and the client(s) are
1555 * notified about that.
1556 * The position display configuration may be changed.
1557 *----------------------------------------------------------------------
1560 wMouseMoveWindow(WWindow
*wwin
, XEvent
*ev
)
1562 WScreen
*scr
= wwin
->screen_ptr
;
1564 Window root
= scr
->root_win
;
1565 KeyCode shiftl
, shiftr
;
1569 /* This needs not to change while moving, else bad things can happen */
1570 int opaqueMove
= wPreferences
.opaque_move
;
1572 #ifdef GHOST_WINDOW_MOVE
1575 rimg
= InitGhostWindowMove(scr
);
1579 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1580 XSetWindowAttributes attr
;
1582 attr
.save_under
= True
;
1583 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
,
1584 CWSaveUnder
, &attr
);
1588 initMoveData(wwin
, &moveData
);
1590 moveData
.mouseX
= ev
->xmotion
.x_root
;
1591 moveData
.mouseY
= ev
->xmotion
.y_root
;
1593 if (!wwin
->flags
.selected
) {
1594 /* this window is not selected, unselect others and move only wwin */
1595 wUnselectWindows(scr
);
1598 puts("Moving window");
1600 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1601 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1607 /* XWarpPointer() doesn't seem to generate Motion events, so
1608 we've got to simulate them */
1609 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1610 &event
.xmotion
.y_root
, &junk
, &junk
,
1611 (unsigned *) &junk
);
1613 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1614 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
,
1617 if (event
.type
== MotionNotify
) {
1618 /* compress MotionNotify events */
1619 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1620 if (!checkMouseSamplingRate(&event
))
1624 switch (event
.type
) {
1626 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1627 && started
&& !scr
->selected_windows
) {
1630 drawFrames(wwin
, scr
->selected_windows
,
1631 moveData
.realX
- wwin
->frame_x
,
1632 moveData
.realY
- wwin
->frame_y
);
1635 if (wPreferences
.move_display
== WDIS_NEW
1636 && !scr
->selected_windows
) {
1637 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1640 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1641 moveData
.winWidth
, moveData
.winHeight
);
1643 if (wPreferences
.move_display
== WDIS_NEW
1644 && !scr
->selected_windows
) {
1646 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1650 drawFrames(wwin
, scr
->selected_windows
,
1651 moveData
.realX
- wwin
->frame_x
,
1652 moveData
.realY
- wwin
->frame_y
);
1659 updateWindowPosition(wwin
, &moveData
,
1660 scr
->selected_windows
== NULL
1661 && wPreferences
.edge_resistance
> 0,
1663 event
.xmotion
.x_root
,
1664 event
.xmotion
.y_root
);
1666 if (!warped
&& !wPreferences
.no_autowrap
) {
1667 int oldWorkspace
= scr
->current_workspace
;
1669 if (wPreferences
.move_display
== WDIS_NEW
1670 && !scr
->selected_windows
) {
1671 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1675 drawFrames(wwin
, scr
->selected_windows
,
1676 moveData
.realX
- wwin
->frame_x
,
1677 moveData
.realY
- wwin
->frame_y
);
1679 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1680 if (scr
->current_workspace
!= oldWorkspace
1681 && wPreferences
.edge_resistance
> 0
1682 && scr
->selected_windows
== NULL
)
1683 updateMoveData(wwin
, &moveData
);
1687 drawFrames(wwin
, scr
->selected_windows
,
1688 moveData
.realX
- wwin
->frame_x
,
1689 moveData
.realY
- wwin
->frame_y
);
1691 if (wPreferences
.move_display
== WDIS_NEW
1692 && !scr
->selected_windows
) {
1694 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1700 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1701 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1703 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1704 | ButtonReleaseMask
| ButtonPressMask
,
1705 wCursor
[WCUR_MOVE
], CurrentTime
);
1707 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1710 if (!scr
->selected_windows
)
1711 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1712 moveData
.winWidth
, moveData
.winHeight
);
1714 if (started
&& !opaqueMove
)
1715 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1717 if (!opaqueMove
|| (wPreferences
.move_display
==WDIS_NEW
1718 && !scr
->selected_windows
)) {
1720 if (wPreferences
.move_display
==WDIS_NEW
)
1721 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1730 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1735 drawFrames(wwin
, scr
->selected_windows
,
1736 moveData
.realX
- wwin
->frame_x
,
1737 moveData
.realY
- wwin
->frame_y
);
1739 doWindowMove(wwin
, scr
->selected_windows
,
1740 moveData
.realX
- wwin
->frame_x
,
1741 moveData
.realY
- wwin
->frame_y
);
1743 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1744 wWindowSynthConfigureNotify(wwin
);
1746 XUngrabKeyboard(dpy
, CurrentTime
);
1749 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1750 wSetFocusTo(scr
, wwin
);
1752 if (wPreferences
.move_display
== WDIS_NEW
)
1753 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1755 if (!scr
->selected_windows
) {
1756 /* get rid of the geometry window */
1757 unmapPositionDisplay(wwin
);
1761 puts("End move window");
1767 if (started
&& !opaqueMove
) {
1768 drawFrames(wwin
, scr
->selected_windows
,
1769 moveData
.realX
- wwin
->frame_x
,
1770 moveData
.realY
- wwin
->frame_y
);
1772 WMHandleEvent(&event
);
1775 drawFrames(wwin
, scr
->selected_windows
,
1776 moveData
.realX
- wwin
->frame_x
,
1777 moveData
.realY
- wwin
->frame_y
);
1779 WMHandleEvent(&event
);
1785 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1786 XSetWindowAttributes attr
;
1789 attr
.save_under
= False
;
1790 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
,
1791 CWSaveUnder
, &attr
);
1795 freeMoveData(&moveData
);
1802 #define HCONSTRAIN 2
1805 getResizeDirection(WWindow
*wwin
, int x
, int y
, int dx
, int dy
,
1808 int w
= wwin
->frame
->core
->width
- 1;
1809 int cw
= wwin
->frame
->resizebar_corner_width
;
1812 /* if not resizing through the resizebar */
1813 if (!(flags
& RESIZEBAR
)) {
1814 int xdir
= (abs(x
) < (wwin
->client
.width
/2)) ? LEFT
: RIGHT
;
1815 int ydir
= (abs(y
) < (wwin
->client
.height
/2)) ? UP
: DOWN
;
1816 if (abs(dx
) < 2 || abs(dy
) < 2) {
1817 if (abs(dy
) > abs(dx
))
1822 return (xdir
| ydir
);
1825 /* window is too narrow. allow diagonal resize */
1829 if (flags
& HCONSTRAIN
)
1834 return (LEFT
| ydir
);
1836 return (RIGHT
| ydir
);
1838 /* vertical resize */
1839 if ((x
> cw
) && (x
< w
- cw
))
1847 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1855 wMouseResizeWindow(WWindow
*wwin
, XEvent
*ev
)
1858 WScreen
*scr
= wwin
->screen_ptr
;
1859 Window root
= scr
->root_win
;
1860 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1861 int fw
= wwin
->frame
->core
->width
;
1862 int fh
= wwin
->frame
->core
->height
;
1863 int fx
= wwin
->frame_x
;
1864 int fy
= wwin
->frame_y
;
1865 int is_resizebar
= (wwin
->frame
->resizebar
1866 && ev
->xany
.window
==wwin
->frame
->resizebar
->window
);
1870 int rw
= fw
, rh
= fh
;
1871 int rx1
, ry1
, rx2
, ry2
;
1873 KeyCode shiftl
, shiftr
;
1880 if (wwin
->flags
.shaded
) {
1881 wwarning("internal error: tryein");
1884 orig_x
= ev
->xbutton
.x_root
;
1885 orig_y
= ev
->xbutton
.y_root
;
1889 puts("Resizing window");
1892 wUnselectWindows(scr
);
1897 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1898 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1899 if (!WFLAGP(wwin
, no_titlebar
))
1900 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + TITLEBAR_EXTRA_HEIGHT
;
1904 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
| ButtonReleaseMask
1905 | ButtonPressMask
| ExposureMask
, &event
);
1906 if (!checkMouseSamplingRate(&event
))
1909 switch (event
.type
) {
1911 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1912 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1914 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1915 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
1916 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1918 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1932 dw
= orig_x
- event
.xmotion
.x_root
;
1933 else if (res
& RIGHT
)
1934 dw
= event
.xmotion
.x_root
- orig_x
;
1936 dh
= orig_y
- event
.xmotion
.y_root
;
1937 else if (res
& DOWN
)
1938 dh
= event
.xmotion
.y_root
- orig_y
;
1940 orig_x
= event
.xmotion
.x_root
;
1941 orig_y
= event
.xmotion
.y_root
;
1946 fh
= rh
- vert_border
;
1947 wWindowConstrainSize(wwin
, &fw
, &fh
);
1951 else if (res
& RIGHT
)
1955 else if (res
& DOWN
)
1957 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1958 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1963 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
1964 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
1966 /* check if resizing through resizebar */
1972 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
1973 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
1974 flags
|= HCONSTRAIN
;
1976 res
= getResizeDirection(wwin
, tx
, ty
,
1977 orig_x
- event
.xmotion
.x_root
,
1978 orig_y
- event
.xmotion
.y_root
, flags
);
1980 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1981 | ButtonReleaseMask
| ButtonPressMask
,
1982 wCursor
[WCUR_RESIZE
], CurrentTime
);
1983 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1988 /* Draw the resize frame for the first time. */
1989 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
1991 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1993 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1998 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
1999 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
2001 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
2002 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2004 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
2006 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2008 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
2009 if (wPreferences
.size_display
== WDIS_NEW
) {
2010 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
2011 orig_fy
+ orig_fh
, res
);
2013 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2022 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2026 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2028 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2030 XUngrabKeyboard(dpy
, CurrentTime
);
2031 unmapGeometryDisplay(wwin
);
2034 if (wwin
->client
.width
!= fw
)
2035 wwin
->flags
.user_changed_width
= 1;
2037 if (wwin
->client
.height
!= fh
- vert_border
)
2038 wwin
->flags
.user_changed_height
= 1;
2040 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
2043 puts("End resize window");
2048 WMHandleEvent(&event
);
2063 wUnselectWindows(WScreen
*scr
)
2067 if (!scr
->selected_windows
)
2070 while (WMGetBagItemCount(scr
->selected_windows
)) {
2071 wwin
= WMGetFromBag(scr
->selected_windows
, 0);
2072 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
2073 wIconSelect(wwin
->icon
);
2075 wSelectWindow(wwin
, False
);
2077 WMFreeBag(scr
->selected_windows
);
2078 scr
->selected_windows
= NULL
;
2083 selectWindowsInside(WScreen
*scr
, int x1
, int y1
, int x2
, int y2
)
2087 /* select the windows and put them in the selected window list */
2088 tmpw
= scr
->focused_window
;
2089 while (tmpw
!= NULL
) {
2090 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
2091 if ((tmpw
->frame
->workspace
== scr
->current_workspace
2092 || IS_OMNIPRESENT(tmpw
))
2093 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
2094 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
2095 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
2096 wSelectWindow(tmpw
, True
);
2105 wSelectWindows(WScreen
*scr
, XEvent
*ev
)
2108 Window root
= scr
->root_win
;
2109 GC gc
= scr
->frame_gc
;
2110 int xp
= ev
->xbutton
.x_root
;
2111 int yp
= ev
->xbutton
.y_root
;
2116 puts("Selecting windows");
2118 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
2119 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
2120 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
],
2121 CurrentTime
) != Success
) {
2126 wUnselectWindows(scr
);
2128 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
2130 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
2131 | ButtonPressMask
, &event
);
2133 switch (event
.type
) {
2135 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2136 x
= event
.xmotion
.x_root
;
2143 y
= event
.xmotion
.y_root
;
2150 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2157 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2160 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2162 XUngrabPointer(dpy
, CurrentTime
);
2163 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
2166 wKWMSelectRootRegion(scr
, xp
, yp
, w
, h
,
2167 event
.xbutton
.state
& ControlMask
);
2168 #endif /* KWM_HINTS */
2171 puts("End window selection");
2176 WMHandleEvent(&event
);
2184 InteractivePlaceWindow(WWindow
*wwin
, int *x_ret
, int *y_ret
,
2185 unsigned width
, unsigned height
)
2187 WScreen
*scr
= wwin
->screen_ptr
;
2188 Window root
= scr
->root_win
;
2191 KeyCode shiftl
, shiftr
;
2195 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2196 GrabModeAsync
, GrabModeAsync
, None
,
2197 wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2202 if (!WFLAGP(wwin
, no_titlebar
)) {
2203 h
= WMFontHeight(scr
->title_font
) + TITLEBAR_EXTRA_HEIGHT
;
2206 if (!WFLAGP(wwin
, no_resizebar
)) {
2207 height
+= RESIZEBAR_HEIGHT
;
2209 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2210 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
,
2211 (unsigned *) &junk
);
2212 mapPositionDisplay(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2214 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2216 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2217 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2219 WMMaskEvent(dpy
, PointerMotionMask
|ButtonPressMask
|ExposureMask
|KeyPressMask
,
2222 if (!checkMouseSamplingRate(&event
))
2225 switch (event
.type
) {
2227 if ((event
.xkey
.keycode
== shiftl
)
2228 || (event
.xkey
.keycode
== shiftr
)) {
2229 drawTransparentFrame(wwin
,
2230 x
- width
/2, y
- h
/2, width
, height
);
2231 cyclePositionDisplay(wwin
,
2232 x
- width
/2, y
- h
/2, width
, height
);
2233 drawTransparentFrame(wwin
,
2234 x
- width
/2, y
- h
/2, width
, height
);
2239 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2241 x
= event
.xmotion
.x_root
;
2242 y
= event
.xmotion
.y_root
;
2244 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2245 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2247 showPosition(wwin
, x
- width
/2, y
- h
/2);
2249 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2254 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2256 *x_ret
= x
- width
/2;
2258 XUngrabPointer(dpy
, CurrentTime
);
2259 XUngrabKeyboard(dpy
, CurrentTime
);
2260 /* get rid of the geometry window */
2261 unmapPositionDisplay(wwin
);
2265 WMHandleEvent(&event
);