2 * Window Maker window manager
4 * Copyright (c) 1997-2002 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"
45 #include <WINGs/WINGsP.h>
52 /* How many different types of geometry/position
53 display thingies are there? */
54 #define NUM_DISPLAYS 5
58 #define HORIZONTAL (LEFT|RIGHT)
61 #define VERTICAL (UP|DOWN)
63 /****** Global Variables ******/
64 extern Time LastTimestamp
;
66 extern Cursor wCursor
[WCUR_LAST
];
68 extern WPreferences wPreferences
;
70 extern Atom _XA_WM_PROTOCOLS
;
75 *----------------------------------------------------------------------
76 * checkMouseSamplingRate-
77 * For lowering the mouse motion sampling rate for machines where
78 * it's too high (SGIs). If it returns False then the event should be
80 *----------------------------------------------------------------------
83 checkMouseSamplingRate(XEvent
*ev
)
85 static Time previousMotion
= 0;
87 if (ev
->type
== MotionNotify
) {
88 if (ev
->xmotion
.time
- previousMotion
< DELAY_BETWEEN_MOUSE_SAMPLING
) {
91 previousMotion
= ev
->xmotion
.time
;
100 *----------------------------------------------------------------------
101 * moveGeometryDisplayCentered
103 * routine that moves the geometry/position window on scr so it is
104 * centered over the given coordinates (x,y). Also the window position
105 * is clamped so it stays on the screen at all times.
106 *----------------------------------------------------------------------
109 moveGeometryDisplayCentered(WScreen
*scr
, int x
, int y
)
111 unsigned int w
= WMWidgetWidth(scr
->gview
);
112 unsigned int h
= WMWidgetHeight(scr
->gview
);
119 else if (x
> (scr
->scr_width
- w
- 3))
120 x
= scr
->scr_width
- w
- 3;
124 else if (y
> (scr
->scr_height
- h
- 3))
125 y
= scr
->scr_height
- h
- 3;
127 WMMoveWidget(scr
->gview
, x
, y
);
132 showPosition(WWindow
*wwin
, int x
, int y
)
134 WScreen
*scr
= wwin
->screen_ptr
;
136 if (wPreferences
.move_display
== WDIS_NEW
) {
138 int width
= wwin
->frame
->core
->width
;
139 int height
= wwin
->frame
->core
->height
;
141 GC lgc
= scr
->line_gc
;
142 XSetForeground(dpy
, lgc
, scr
->line_pixel
);
143 sprintf(num
, "%i", x
);
145 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
-1, scr
->scr_width
, y
-1);
146 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
+height
+2, scr
->scr_width
,
148 XDrawLine(dpy
, scr
->root_win
, lgc
, x
-1, 0, x
-1, scr
->scr_height
);
149 XDrawLine(dpy
, scr
->root_win
, lgc
, x
+width
+2, 0, x
+width
+2,
153 #ifdef VIRTUAL_DESKTOP
154 WSetGeometryViewShownPosition(scr
->gview
,
155 x
+ scr
->workspaces
[scr
->current_workspace
]->view_x
,
156 y
+ scr
->workspaces
[scr
->current_workspace
]->view_y
);
158 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
165 cyclePositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
167 WScreen
*scr
= wwin
->screen_ptr
;
169 wPreferences
.move_display
++;
170 wPreferences
.move_display
%= NUM_DISPLAYS
;
172 if (wPreferences
.move_display
== WDIS_NEW
) {
173 wPreferences
.move_display
++;
174 wPreferences
.move_display
%= NUM_DISPLAYS
;
177 if (wPreferences
.move_display
== WDIS_NONE
) {
178 WMUnmapWidget(scr
->gview
);
180 if (wPreferences
.move_display
== WDIS_CENTER
) {
181 moveGeometryDisplayCentered(scr
,
182 scr
->scr_width
/2, scr
->scr_height
/2);
183 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
184 moveGeometryDisplayCentered(scr
, 1, 1);
185 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
186 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
188 WMMapWidget(scr
->gview
);
194 mapPositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
196 WScreen
*scr
= wwin
->screen_ptr
;
198 if (wPreferences
.move_display
== WDIS_NEW
199 || wPreferences
.move_display
== WDIS_NONE
) {
201 } else if (wPreferences
.move_display
== WDIS_CENTER
) {
202 moveGeometryDisplayCentered(scr
, scr
->scr_width
/ 2,
203 scr
->scr_height
/ 2);
204 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
205 moveGeometryDisplayCentered(scr
, 1, 1);
206 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
207 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
209 WMMapWidget(scr
->gview
);
210 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
215 showGeometry(WWindow
*wwin
, int x1
, int y1
, int x2
, int y2
, int direction
)
217 WScreen
*scr
= wwin
->screen_ptr
;
218 Window root
= scr
->root_win
;
219 GC gc
= scr
->line_gc
, saveGC
;
220 int ty
, by
, my
, x
, y
, mx
, s
;
227 ty
= y1
+ wwin
->frame
->top_width
;
228 by
= y2
- wwin
->frame
->bottom_width
;
230 if (wPreferences
.size_display
== WDIS_NEW
) {
231 fw
= WMWidthOfString(scr
->tech_draw_font
, "8888", 4);
232 fh
= WMFontHeight(scr
->tech_draw_font
);
234 XSetForeground(dpy
, gc
, scr
->line_pixel
);
236 /* vertical geometry */
237 if (((direction
& LEFT
) && (x2
< scr
->scr_width
- fw
)) || (x1
< fw
)) {
248 segment
[0].x1
= x
- (s
+ 6); segment
[0].y1
= ty
;
249 segment
[0].x2
= x
- (s
- 10); segment
[0].y2
= ty
;
252 segment
[1].x1
= x
- (s
- 2); segment
[1].y1
= ty
+ 1;
253 segment
[1].x2
= x
- (s
- 5); segment
[1].y2
= ty
+ 7;
255 segment
[2].x1
= x
- (s
- 2); segment
[2].y1
= ty
+ 1;
256 segment
[2].x2
= x
- (s
+ 1); segment
[2].y2
= ty
+ 7;
259 segment
[3].x1
= x
- (s
- 2); segment
[3].y1
= ty
+ 1;
260 segment
[3].x2
= x
- (s
- 2); segment
[3].y2
= my
- fh
/2 - 1;
262 XDrawSegments(dpy
, root
, gc
, segment
, 4);
270 segment
[1].y1
= by
- 1;
271 segment
[1].y2
= by
- 7;
273 segment
[2].y1
= by
- 1;
274 segment
[2].y2
= by
- 7;
277 segment
[3].y1
= my
+ fh
/2 + 2;
278 segment
[3].y2
= by
- 1;
280 XDrawSegments(dpy
, root
, gc
, segment
, 4);
282 snprintf(num
, sizeof(num
), "%i", (by
- ty
- wwin
->normal_hints
->base_height
) /
283 wwin
->normal_hints
->height_inc
);
284 fw
= WMWidthOfString(scr
->tech_draw_font
, num
, strlen(num
));
286 /* XSetForeground(dpy, gc, WMColorPixel(scr->window_title_color[WS_UNFOCUSED])); */
288 color
= WMBlackColor(scr
->wmscreen
);
289 saveGC
= scr
->wmscreen
->drawStringGC
;
290 pixel
= color
->color
.pixel
;
292 /* Display the height. */
295 color
->color
.pixel
= scr
->line_pixel
;
296 scr
->wmscreen
->drawStringGC
= gc
;
297 WMDrawString(scr
->wmscreen
, root
, color
, scr
->tech_draw_font
,
298 x
- s
+ 3 - fw
/2, my
- fh
/2 + 1, num
, strlen(num
));
299 scr
->wmscreen
->drawStringGC
= saveGC
;
300 color
->color
.pixel
= pixel
;
302 XSetForeground(dpy
, gc
, scr
->line_pixel
);
303 /* horizontal geometry */
311 mx
= x1
+ (x2
- x1
)/2;
312 snprintf(num
, sizeof(num
), "%i", (x2
- x1
- wwin
->normal_hints
->base_width
) /
313 wwin
->normal_hints
->width_inc
);
314 fw
= WMWidthOfString(scr
->tech_draw_font
, num
, strlen(num
));
318 segment
[0].x1
= x1
; segment
[0].y1
= y
- (s
+ 6);
319 segment
[0].x2
= x1
; segment
[0].y2
= y
- (s
- 10);
322 segment
[1].x1
= x1
+ 7; segment
[1].y1
= y
- (s
+ 1);
323 segment
[1].x2
= x1
+ 1; segment
[1].y2
= y
- (s
- 2);
325 segment
[2].x1
= x1
+ 1; segment
[2].y1
= y
- (s
- 2);
326 segment
[2].x2
= x1
+ 7; segment
[2].y2
= y
- (s
- 5);
329 segment
[3].x1
= x1
+ 1; segment
[3].y1
= y
- (s
- 2);
330 segment
[3].x2
= mx
- fw
/2 - 2; segment
[3].y2
= y
- (s
- 2);
332 XDrawSegments(dpy
, root
, gc
, segment
, 4);
336 segment
[0].x1
= x2
+ 1;
337 segment
[0].x2
= x2
+ 1;
340 segment
[1].x1
= x2
- 6;
344 segment
[2].x2
= x2
- 6;
347 segment
[3].x1
= mx
+ fw
/2 + 2;
350 XDrawSegments(dpy
, root
, gc
, segment
, 4);
352 /* XSetForeground(dpy, gc, WMColorPixel(scr->window_title_color[WS_UNFOCUSED])); */
354 /* Display the width. */
356 color
->color
.pixel
= scr
->line_pixel
;
357 scr
->wmscreen
->drawStringGC
= gc
;
358 WMDrawString(scr
->wmscreen
, root
, color
, scr
->tech_draw_font
,
359 mx
- fw
/2 + 1, y
- s
- fh
/2 + 1, num
, strlen(num
));
360 scr
->wmscreen
->drawStringGC
= saveGC
;
361 color
->color
.pixel
= pixel
;
362 WMReleaseColor(color
);
364 WSetGeometryViewShownSize(scr
->gview
,
365 (x2
- x1
- wwin
->normal_hints
->base_width
)
366 / wwin
->normal_hints
->width_inc
,
367 (by
- ty
- wwin
->normal_hints
->base_height
)
368 / wwin
->normal_hints
->height_inc
);
374 cycleGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
, int dir
)
376 WScreen
*scr
= wwin
->screen_ptr
;
378 wPreferences
.size_display
++;
379 wPreferences
.size_display
%= NUM_DISPLAYS
;
381 if (wPreferences
.size_display
== WDIS_NEW
382 || wPreferences
.size_display
== WDIS_NONE
) {
383 WMUnmapWidget(scr
->gview
);
385 if (wPreferences
.size_display
== WDIS_CENTER
) {
386 moveGeometryDisplayCentered(scr
,
387 scr
->scr_width
/ 2, scr
->scr_height
/ 2);
388 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
389 moveGeometryDisplayCentered(scr
, 1, 1);
390 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
391 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
393 WMMapWidget(scr
->gview
);
394 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, dir
);
400 mapGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
402 WScreen
*scr
= wwin
->screen_ptr
;
404 if (wPreferences
.size_display
== WDIS_NEW
405 || wPreferences
.size_display
== WDIS_NONE
)
408 if (wPreferences
.size_display
== WDIS_CENTER
) {
409 moveGeometryDisplayCentered(scr
, scr
->scr_width
/ 2,
410 scr
->scr_height
/ 2);
411 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
412 moveGeometryDisplayCentered(scr
, 1, 1);
413 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
414 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
416 WMMapWidget(scr
->gview
);
417 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, 0);
423 doWindowMove(WWindow
*wwin
, WMArray
*array
, int dx
, int dy
)
427 int scr_width
= wwin
->screen_ptr
->scr_width
;
428 int scr_height
= wwin
->screen_ptr
->scr_height
;
430 if (!array
|| !WMGetArrayItemCount(array
)) {
431 wWindowMove(wwin
, wwin
->frame_x
+ dx
, wwin
->frame_y
+ dy
);
433 WMArrayIterator iter
;
435 WM_ITERATE_ARRAY(array
, tmpw
, iter
) {
436 x
= tmpw
->frame_x
+ dx
;
437 y
= tmpw
->frame_y
+ dy
;
439 /* don't let windows become unreachable */
441 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
442 x
= 20 - (int)tmpw
->frame
->core
->width
;
443 else if (x
+ 20 > scr_width
)
446 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
447 y
= 20 - (int)tmpw
->frame
->core
->height
;
448 else if (y
+ 20 > scr_height
)
451 wWindowMove(tmpw
, x
, y
);
458 drawTransparentFrame(WWindow
*wwin
, int x
, int y
, int width
, int height
)
460 Window root
= wwin
->screen_ptr
->root_win
;
461 GC gc
= wwin
->screen_ptr
->frame_gc
;
465 if (!WFLAGP(wwin
, no_titlebar
) && !wwin
->flags
.shaded
) {
466 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + (wPreferences
.window_title_clearance
+ TITLEBAR_EXTEND_SPACE
) * 2;
468 if (!WFLAGP(wwin
, no_resizebar
) && !wwin
->flags
.shaded
) {
469 /* Can't use wwin-frame->bottom_width because, in some cases
470 (e.g. interactive placement), frame does not point to anything. */
471 bottom
= RESIZEBAR_HEIGHT
- 1;
473 XDrawRectangle(dpy
, root
, gc
, x
, y
, width
+ 1, height
+ 1);
476 XDrawLine(dpy
, root
, gc
, x
+ 1, y
+ h
, x
+ width
+ 1, y
+ h
);
479 XDrawLine(dpy
, root
, gc
, x
+ 1,
482 y
+ height
- bottom
);
488 drawFrames(WWindow
*wwin
, WMArray
*array
, int dx
, int dy
)
491 int scr_width
= wwin
->screen_ptr
->scr_width
;
492 int scr_height
= wwin
->screen_ptr
->scr_height
;
497 x
= wwin
->frame_x
+ dx
;
498 y
= wwin
->frame_y
+ dy
;
500 drawTransparentFrame(wwin
, x
, y
,
501 wwin
->frame
->core
->width
,
502 wwin
->frame
->core
->height
);
505 WMArrayIterator iter
;
507 WM_ITERATE_ARRAY(array
, tmpw
, iter
) {
508 x
= tmpw
->frame_x
+ dx
;
509 y
= tmpw
->frame_y
+ dy
;
511 /* don't let windows become unreachable */
513 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
514 x
= 20 - (int)tmpw
->frame
->core
->width
;
515 else if (x
+ 20 > scr_width
)
518 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
519 y
= 20 - (int)tmpw
->frame
->core
->height
;
520 else if (y
+ 20 > scr_height
)
523 drawTransparentFrame(tmpw
, x
, y
, tmpw
->frame
->core
->width
,
524 tmpw
->frame
->core
->height
);
537 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &ev
)) ;
542 crossWorkspace(WScreen
*scr
, WWindow
*wwin
, int opaque_move
,
543 int new_workspace
, int rewind
)
545 /* do not let window be unmapped */
547 wwin
->flags
.changing_workspace
= 1;
548 wWindowChangeWorkspace(wwin
, new_workspace
);
550 /* go to new workspace */
551 wWorkspaceChange(scr
, new_workspace
);
553 wwin
->flags
.changing_workspace
= 0;
556 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, scr
->scr_width
- 20, 0);
558 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, -(scr
->scr_width
- 20), 0);
563 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
564 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
565 GrabModeAsync
, None
, wCursor
[WCUR_MOVE
], CurrentTime
);
573 /* arrays of WWindows sorted by the respective border position */
574 WWindow
**topList
; /* top border */
575 WWindow
**leftList
; /* left border */
576 WWindow
**rightList
; /* right border */
577 WWindow
**bottomList
; /* bottom border */
580 /* index of window in the above lists indicating the relative position
581 * of the window with the others */
587 int rubCount
; /* for workspace switching */
589 int winWidth
, winHeight
; /* width/height of the window */
590 int realX
, realY
; /* actual position of the window */
591 int calcX
, calcY
; /* calculated position of window */
592 int omouseX
, omouseY
; /* old mouse position */
593 int mouseX
, mouseY
; /* last known position of the pointer */
596 #define WTOP(w) (w)->frame_y
597 #define WLEFT(w) (w)->frame_x
598 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width + FRAME_BORDER_WIDTH)
599 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height + FRAME_BORDER_WIDTH)
602 compareWTop(const void *a
, const void *b
)
604 WWindow
*wwin1
= *(WWindow
**)a
;
605 WWindow
*wwin2
= *(WWindow
**)b
;
607 if (WTOP(wwin1
) > WTOP(wwin2
))
609 else if (WTOP(wwin1
) < WTOP(wwin2
))
617 compareWLeft(const void *a
, const void *b
)
619 WWindow
*wwin1
= *(WWindow
**)a
;
620 WWindow
*wwin2
= *(WWindow
**)b
;
622 if (WLEFT(wwin1
) > WLEFT(wwin2
))
624 else if (WLEFT(wwin1
) < WLEFT(wwin2
))
632 compareWRight(const void *a
, const void *b
)
634 WWindow
*wwin1
= *(WWindow
**)a
;
635 WWindow
*wwin2
= *(WWindow
**)b
;
637 if (WRIGHT(wwin1
) < WRIGHT(wwin2
))
639 else if (WRIGHT(wwin1
) > WRIGHT(wwin2
))
648 compareWBottom(const void *a
, const void *b
)
650 WWindow
*wwin1
= *(WWindow
**)a
;
651 WWindow
*wwin2
= *(WWindow
**)b
;
653 if (WBOTTOM(wwin1
) < WBOTTOM(wwin2
))
655 else if (WBOTTOM(wwin1
) > WBOTTOM(wwin2
))
663 updateResistance(WWindow
*wwin
, MoveData
*data
, int newX
, int newY
)
666 int newX2
= newX
+ data
->winWidth
;
667 int newY2
= newY
+ data
->winHeight
;
670 if (newX
< data
->realX
) {
671 if (data
->rightIndex
> 0
672 && newX
< WRIGHT(data
->rightList
[data
->rightIndex
-1])) {
674 } else if (data
->leftIndex
<= data
->count
-1
675 && newX2
<= WLEFT(data
->leftList
[data
->leftIndex
])) {
678 } else if (newX
> data
->realX
) {
679 if (data
->leftIndex
> 0
680 && newX2
> WLEFT(data
->leftList
[data
->leftIndex
-1])) {
682 } else if (data
->rightIndex
<= data
->count
-1
683 && newX
>= WRIGHT(data
->rightList
[data
->rightIndex
])) {
689 if (newY
< data
->realY
) {
690 if (data
->bottomIndex
> 0
691 && newY
< WBOTTOM(data
->bottomList
[data
->bottomIndex
-1])) {
693 } else if (data
->topIndex
<= data
->count
-1
694 && newY2
<= WTOP(data
->topList
[data
->topIndex
])) {
697 } else if (newY
> data
->realY
) {
698 if (data
->topIndex
> 0
699 && newY2
> WTOP(data
->topList
[data
->topIndex
-1])) {
701 } else if (data
->bottomIndex
<= data
->count
-1
702 && newY
>= WBOTTOM(data
->bottomList
[data
->bottomIndex
])) {
711 /* TODO: optimize this */
712 if (data
->realY
< WBOTTOM(data
->bottomList
[0])) {
713 data
->bottomIndex
= 0;
715 if (data
->realX
< WRIGHT(data
->rightList
[0])) {
716 data
->rightIndex
= 0;
718 if ((data
->realX
+ data
->winWidth
) > WLEFT(data
->leftList
[0])) {
721 if ((data
->realY
+ data
->winHeight
) > WTOP(data
->topList
[0])) {
724 for (i
= 0; i
< data
->count
; i
++) {
725 if (data
->realY
> WBOTTOM(data
->bottomList
[i
])) {
726 data
->bottomIndex
= i
+ 1;
728 if (data
->realX
> WRIGHT(data
->rightList
[i
])) {
729 data
->rightIndex
= i
+ 1;
731 if ((data
->realX
+ data
->winWidth
) < WLEFT(data
->leftList
[i
])) {
732 data
->leftIndex
= i
+ 1;
734 if ((data
->realY
+ data
->winHeight
) < WTOP(data
->topList
[i
])) {
735 data
->topIndex
= i
+ 1;
742 freeMoveData(MoveData
*data
)
745 wfree(data
->topList
);
747 wfree(data
->leftList
);
749 wfree(data
->rightList
);
750 if (data
->bottomList
)
751 wfree(data
->bottomList
);
756 updateMoveData(WWindow
*wwin
, MoveData
*data
)
758 WScreen
*scr
= wwin
->screen_ptr
;
763 tmp
= scr
->focused_window
;
765 if (tmp
!= wwin
&& scr
->current_workspace
== tmp
->frame
->workspace
766 && !tmp
->flags
.miniaturized
767 && !tmp
->flags
.hidden
768 && !tmp
->flags
.obscured
769 && !WFLAGP(tmp
, sunken
)) {
770 data
->topList
[data
->count
] = tmp
;
771 data
->leftList
[data
->count
] = tmp
;
772 data
->rightList
[data
->count
] = tmp
;
773 data
->bottomList
[data
->count
] = tmp
;
779 if (data
->count
== 0) {
782 data
->rightIndex
= 0;
783 data
->bottomIndex
= 0;
788 * order from closest to the border of the screen to farthest
790 qsort(data
->topList
, data
->count
, sizeof(WWindow
**), compareWTop
);
791 qsort(data
->leftList
, data
->count
, sizeof(WWindow
**), compareWLeft
);
792 qsort(data
->rightList
, data
->count
, sizeof(WWindow
**), compareWRight
);
793 qsort(data
->bottomList
, data
->count
, sizeof(WWindow
**), compareWBottom
);
795 /* figure the position of the window relative to the others */
798 data
->leftIndex
= -1;
799 data
->rightIndex
= -1;
800 data
->bottomIndex
= -1;
802 if (WTOP(wwin
) < WBOTTOM(data
->bottomList
[0])) {
803 data
->bottomIndex
= 0;
805 if (WLEFT(wwin
) < WRIGHT(data
->rightList
[0])) {
806 data
->rightIndex
= 0;
808 if (WRIGHT(wwin
) > WLEFT(data
->leftList
[0])) {
811 if (WBOTTOM(wwin
) > WTOP(data
->topList
[0])) {
814 for (i
= 0; i
< data
->count
; i
++) {
815 if (WTOP(wwin
) >= WBOTTOM(data
->bottomList
[i
])) {
816 data
->bottomIndex
= i
+ 1;
818 if (WLEFT(wwin
) >= WRIGHT(data
->rightList
[i
])) {
819 data
->rightIndex
= i
+ 1;
821 if (WRIGHT(wwin
) <= WLEFT(data
->leftList
[i
])) {
822 data
->leftIndex
= i
+ 1;
824 if (WBOTTOM(wwin
) <= WTOP(data
->topList
[i
])) {
825 data
->topIndex
= i
+ 1;
832 initMoveData(WWindow
*wwin
, MoveData
*data
)
837 memset(data
, 0, sizeof(MoveData
));
839 for (i
= 0, tmp
= wwin
->screen_ptr
->focused_window
;
841 tmp
= tmp
->prev
, i
++);
844 data
->topList
= wmalloc(sizeof(WWindow
*) * i
);
845 data
->leftList
= wmalloc(sizeof(WWindow
*) * i
);
846 data
->rightList
= wmalloc(sizeof(WWindow
*) * i
);
847 data
->bottomList
= wmalloc(sizeof(WWindow
*) * i
);
849 updateMoveData(wwin
, data
);
852 data
->realX
= wwin
->frame_x
;
853 data
->realY
= wwin
->frame_y
;
854 data
->calcX
= wwin
->frame_x
;
855 data
->calcY
= wwin
->frame_y
;
857 data
->winWidth
= wwin
->frame
->core
->width
+ 2;
858 data
->winHeight
= wwin
->frame
->core
->height
+ 2;
863 checkWorkspaceChange(WWindow
*wwin
, MoveData
*data
, Bool opaqueMove
)
865 WScreen
*scr
= wwin
->screen_ptr
;
866 Bool changed
= False
;
868 if (data
->mouseX
<= 1) {
869 if (scr
->current_workspace
> 0) {
871 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
- 1,
876 } else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
) {
878 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->workspace_count
- 1,
883 } else if (data
->mouseX
>= scr
->scr_width
- 2) {
885 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
887 if (wPreferences
.ws_cycle
888 || scr
->workspace_count
== MAX_WORKSPACES
) {
890 crossWorkspace(scr
, wwin
, opaqueMove
, 0, False
);
894 /* if user insists on trying to go to next workspace even when
895 * it's already the last, create a new one */
896 else if (data
->omouseX
== data
->mouseX
897 && wPreferences
.ws_advance
) {
899 /* detect user "rubbing" the window against the edge */
900 if (data
->rubCount
> 0
901 && data
->omouseY
- data
->mouseY
> MOVE_THRESHOLD
) {
903 data
->rubCount
= -(data
->rubCount
+ 1);
905 } else if (data
->rubCount
<= 0
906 && data
->mouseY
- data
->omouseY
> MOVE_THRESHOLD
) {
908 data
->rubCount
= -data
->rubCount
+ 1;
911 /* create a new workspace */
912 if (abs(data
->rubCount
) > 2) {
913 /* go to next workspace */
916 crossWorkspace(scr
, wwin
, opaqueMove
,
917 scr
->current_workspace
+1, False
);
921 } else if (scr
->current_workspace
< scr
->workspace_count
) {
923 /* go to next workspace */
924 crossWorkspace(scr
, wwin
, opaqueMove
,
925 scr
->current_workspace
+1, False
);
938 updateWindowPosition(WWindow
*wwin
, MoveData
*data
, Bool doResistance
,
939 Bool opaqueMove
, int newMouseX
, int newMouseY
)
941 WScreen
*scr
= wwin
->screen_ptr
;
942 int dx
, dy
; /* how much mouse moved */
943 int winL
, winR
, winT
, winB
; /* requested new window position */
944 int newX
, newY
; /* actual new window position */
945 Bool hresist
, vresist
;
954 /* check the direction of the movement */
955 dx
= newMouseX
- data
->mouseX
;
956 dy
= newMouseY
- data
->mouseY
;
958 data
->omouseX
= data
->mouseX
;
959 data
->omouseY
= data
->mouseY
;
960 data
->mouseX
= newMouseX
;
961 data
->mouseY
= newMouseY
;
963 winL
= data
->calcX
+ dx
;
964 winR
= data
->calcX
+ data
->winWidth
+ dx
;
965 winT
= data
->calcY
+ dy
;
966 winB
= data
->calcY
+ data
->winHeight
+ dy
;
978 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
979 attract
= wPreferences
.attract
;
980 /* horizontal movement: check horizontal edge resistances */
983 /* window is the leftmost window: check against screen edge */
984 l_edge
= scr
->totalUsableArea
.x1
;
985 r_edge
= scr
->totalUsableArea
.x2
+ resist
;
986 edge_l
= scr
->totalUsableArea
.x1
- resist
;
987 edge_r
= scr
->totalUsableArea
.x2
;
990 if ((data
->rightIndex
>= 0) && (data
->rightIndex
<= data
->count
)) {
993 for (i
= data
->rightIndex
- 1; i
>= 0; i
--) {
994 looprw
= data
->rightList
[i
];
995 if (!(data
->realY
> WBOTTOM(looprw
)
996 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
998 || ((data
->realX
< (WRIGHT(looprw
) + 2)) && dx
< 0)) {
999 l_edge
= WRIGHT(looprw
) + 1;
1000 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1007 for (i
= data
->rightIndex
; i
< data
->count
; i
++) {
1008 looprw
= data
->rightList
[i
];
1009 if(!(data
->realY
> WBOTTOM(looprw
)
1010 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1011 r_edge
= WRIGHT(looprw
) + 1;
1012 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1019 if ((data
->leftIndex
>= 0) && (data
->leftIndex
<= data
->count
)) {
1022 for (i
= data
->leftIndex
- 1; i
>= 0; i
--) {
1023 looprw
= data
->leftList
[i
];
1024 if (!(data
->realY
> WBOTTOM(looprw
)
1025 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1027 || (((data
->realX
+ data
->winWidth
) > (WLEFT(looprw
) - 1)) && dx
> 0)) {
1028 edge_r
= WLEFT(looprw
);
1029 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1036 for (i
= data
->leftIndex
; i
< data
->count
; i
++) {
1037 looprw
= data
->leftList
[i
];
1038 if(!(data
->realY
> WBOTTOM(looprw
)
1039 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1040 edge_l
= WLEFT(looprw
);
1041 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1048 printf("%d %d\n",winL,winR);
1049 printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);
1052 if ((winL
- l_edge
) < (r_edge
- winL
)) {
1054 if ((attract
&& winL
<= l_edge
+ resist
&& winL
>= l_edge
- resist
)
1055 || (dx
< 0 && winL
<= l_edge
&& winL
>= l_edge
- resist
)) {
1061 if (resist
> 0 && attract
&& winL
>= r_edge
- resist
&& winL
<= r_edge
+ resist
) {
1067 if ((winR
- edge_l
) < (edge_r
- winR
)) {
1068 if (resist
> 0 && attract
&& winR
<= edge_l
+ resist
&& winR
>= edge_l
- resist
) {
1069 newX
= edge_l
- data
->winWidth
;
1074 if ((attract
&& winR
>= edge_r
- resist
&& winR
<= edge_r
+ resist
)
1075 || (dx
> 0 && winR
>= edge_r
&& winR
<= edge_r
+ resist
)) {
1076 newX
= edge_r
- data
->winWidth
;
1083 t_edge
= scr
->totalUsableArea
.y1
;
1084 b_edge
= scr
->totalUsableArea
.y2
+ resist
;
1085 edge_t
= scr
->totalUsableArea
.y1
- resist
;
1086 edge_b
= scr
->totalUsableArea
.y2
;
1088 if ((data
->bottomIndex
>= 0) && (data
->bottomIndex
<= data
->count
)) {
1091 for (i
= data
->bottomIndex
- 1; i
>= 0; i
--) {
1092 looprw
= data
->bottomList
[i
];
1093 if (!(data
->realX
> WRIGHT(looprw
)
1094 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1096 || ((data
->realY
< (WBOTTOM(looprw
) + 2)) && dy
< 0)) {
1097 t_edge
= WBOTTOM(looprw
) + 1;
1098 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1105 for (i
= data
->bottomIndex
; i
< data
->count
; i
++) {
1106 looprw
= data
->bottomList
[i
];
1107 if(!(data
->realX
> WRIGHT(looprw
)
1108 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1109 b_edge
= WBOTTOM(looprw
) + 1;
1110 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1117 if ((data
->topIndex
>= 0) && (data
->topIndex
<= data
->count
)) {
1120 for (i
= data
->topIndex
- 1; i
>= 0; i
--) {
1121 looprw
= data
->topList
[i
];
1122 if (!(data
->realX
> WRIGHT(looprw
)
1123 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1125 || (((data
->realY
+ data
->winHeight
) > (WTOP(looprw
) - 1)) && dy
> 0)) {
1126 edge_b
= WTOP(looprw
);
1127 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1134 for (i
= data
->topIndex
; i
< data
->count
; i
++) {
1135 looprw
= data
->topList
[i
];
1136 if(!(data
->realX
> WRIGHT(looprw
)
1137 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1138 edge_t
= WTOP(looprw
);
1139 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1145 if ((winT
- t_edge
) < (b_edge
- winT
)) {
1147 if ((attract
&& winT
<= t_edge
+ resist
&& winT
>= t_edge
- resist
)
1148 || (dy
< 0 && winT
<= t_edge
&& winT
>= t_edge
- resist
)) {
1155 if (resist
> 0 && attract
&& winT
>= b_edge
- resist
&& winT
<= b_edge
+ resist
) {
1161 if ((winB
- edge_t
) < (edge_b
- winB
)) {
1162 if (resist
> 0 && attract
&& winB
<= edge_t
+ resist
&& winB
>= edge_t
- resist
) {
1163 newY
= edge_t
- data
->winHeight
;
1169 if ((attract
&& winB
>= edge_b
- resist
&& winB
<= edge_b
+ resist
)
1170 || (dy
> 0 && winB
>= edge_b
&& winB
<= edge_b
+ resist
)) {
1171 newY
= edge_b
- data
->winHeight
;
1181 /* update window position */
1185 if (((dx
> 0 && data
->calcX
- data
->realX
> 0)
1186 || (dx
< 0 && data
->calcX
- data
->realX
< 0)) && !hresist
)
1189 if (((dy
> 0 && data
->calcY
- data
->realY
> 0)
1190 || (dy
< 0 && data
->calcY
- data
->realY
< 0)) && !vresist
)
1193 if (data
->realX
!= newX
|| data
->realY
!= newY
) {
1195 if (wPreferences
.move_display
== WDIS_NEW
1196 && !scr
->selected_windows
) {
1197 showPosition(wwin
, data
->realX
, data
->realY
);
1200 doWindowMove(wwin
, scr
->selected_windows
,
1201 newX
- wwin
->frame_x
,
1202 newY
- wwin
->frame_y
);
1205 drawFrames(wwin
, scr
->selected_windows
,
1206 data
->realX
- wwin
->frame_x
,
1207 data
->realY
- wwin
->frame_y
);
1210 if (!scr
->selected_windows
1211 && wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
1213 moveGeometryDisplayCentered(scr
, newX
+ data
->winWidth
/2,
1214 newY
+ data
->winHeight
/2);
1219 drawFrames(wwin
, scr
->selected_windows
,
1220 newX
- wwin
->frame_x
,
1221 newY
- wwin
->frame_y
);
1224 if (!scr
->selected_windows
) {
1225 showPosition(wwin
, newX
, newY
);
1230 /* recalc relative window position */
1231 if (doResistance
&& (data
->realX
!= newX
|| data
->realY
!= newY
)) {
1232 updateResistance(wwin
, data
, newX
, newY
);
1240 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1243 wKeyboardMoveResizeWindow(WWindow
*wwin
)
1245 WScreen
*scr
= wwin
->screen_ptr
;
1246 Window root
= scr
->root_win
;
1248 int w
= wwin
->frame
->core
->width
;
1249 int h
= wwin
->frame
->core
->height
;
1250 int scr_width
= wwin
->screen_ptr
->scr_width
;
1251 int scr_height
= wwin
->screen_ptr
->scr_height
;
1252 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1253 int src_x
= wwin
->frame_x
;
1254 int src_y
= wwin
->frame_y
;
1255 int done
,off_x
,off_y
,ww
,wh
;
1258 KeySym keysym
=NoSymbol
;
1260 KeyCode shiftl
,shiftr
,ctrll
,ctrlmode
;
1262 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1263 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1264 ctrll
= XKeysymToKeycode(dpy
, XK_Control_L
);
1265 ctrlmode
=done
=off_x
=off_y
=0;
1269 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1271 if (!wwin
->flags
.selected
) {
1272 wUnselectWindows(scr
);
1275 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1276 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
1277 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
);
1279 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1280 if(scr
->selected_windows
)
1281 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1282 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1283 if(!scr
->selected_windows
)
1284 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1286 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1296 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1297 | ButtonPressMask
| ExposureMask
, &event
);
1298 if (event
.type
== Expose
) {
1299 WMHandleEvent(&event
);
1301 } while (event
.type
== Expose
);
1304 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1305 if(scr
->selected_windows
)
1306 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1307 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1308 /*** I HATE EDGE RESISTANCE - ]d ***/
1311 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1315 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1320 switch (event
.type
) {
1323 if (event
.xkey
.time
- lastTime
> 50) {
1324 kspeed
/=(1 + (event
.xkey
.time
- lastTime
)/100);
1330 if (kspeed
< _KS
) kspeed
= _KS
;
1331 lastTime
= event
.xkey
.time
;
1333 if (event
.xkey
.state
& ControlMask
&& !wwin
->flags
.shaded
) {
1335 wUnselectWindows(scr
);
1340 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
) {
1342 cycleGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
, 0);
1344 cyclePositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1348 keysym
= XLookupKeysym(&event
.xkey
, 0);
1403 if (moment
!= RIGHT
)
1414 wWindowConstrainSize(wwin
, &ww
, &wh
);
1417 if (wPreferences
.ws_cycle
){
1418 if (src_x
+ off_x
+ ww
< 20){
1419 if(!scr
->current_workspace
) {
1420 wWorkspaceChange(scr
, scr
->workspace_count
-1);
1422 else wWorkspaceChange(scr
, scr
->current_workspace
-1);
1425 else if (src_x
+ off_x
+ 20 > scr_width
){
1426 if(scr
->current_workspace
== scr
->workspace_count
-1) {
1427 wWorkspaceChange(scr
, 0);
1429 else wWorkspaceChange(scr
, scr
->current_workspace
+1);
1434 if (src_x
+ off_x
+ ww
< 20)
1435 off_x
= 20 - ww
- src_x
;
1436 else if (src_x
+ off_x
+ 20 > scr_width
)
1437 off_x
= scr_width
- 20 - src_x
;
1440 if (src_y
+ off_y
+ wh
< 20) {
1441 off_y
= 20 - wh
- src_y
;
1443 else if (src_y
+ off_y
+ 20 > scr_height
) {
1444 off_y
= scr_height
- 20 - src_y
;
1453 WMHandleEvent(&event
);
1454 while (XCheckTypedEvent(dpy
, Expose
, &event
)) {
1455 WMHandleEvent(&event
);
1460 WMHandleEvent(&event
);
1467 if (wwin
->flags
.shaded
&& !scr
->selected_windows
){
1468 moveGeometryDisplayCentered(scr
, src_x
+off_x
+ w
/2, src_y
+off_y
+ h
/2);
1471 WMUnmapWidget(scr
->gview
);
1472 mapGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1473 } else if(!scr
->selected_windows
) {
1474 WMUnmapWidget(scr
->gview
);
1475 mapPositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1479 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1480 if (scr
->selected_windows
)
1481 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1483 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1485 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1490 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1491 } else if(!scr
->selected_windows
)
1492 showPosition(wwin
, src_x
+off_x
, src_y
+off_y
);
1496 scr
->keymove_tick
=0;
1498 WMDeleteTimerWithClientData(&looper);
1500 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1501 if(scr
->selected_windows
)
1502 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1503 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1506 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1510 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1511 WMUnmapWidget(scr
->gview
);
1513 WMUnmapWidget(scr
->gview
);
1515 XUngrabKeyboard(dpy
, CurrentTime
);
1516 XUngrabPointer(dpy
, CurrentTime
);
1520 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1521 if (!scr
->selected_windows
) {
1522 wWindowMove(wwin
, src_x
+off_x
, src_y
+off_y
);
1523 wWindowSynthConfigureNotify(wwin
);
1525 WMArrayIterator iter
;
1528 doWindowMove(wwin
, scr
->selected_windows
, off_x
, off_y
);
1530 WM_ITERATE_ARRAY(scr
->selected_windows
, foo
, iter
) {
1531 wWindowSynthConfigureNotify(foo
);
1535 if (wwin
->client
.width
!= ww
)
1536 wwin
->flags
.user_changed_width
= 1;
1538 if (wwin
->client
.height
!= wh
- vert_border
)
1539 wwin
->flags
.user_changed_height
= 1;
1541 wWindowConfigure(wwin
, src_x
+off_x
, src_y
+off_y
,
1542 ww
, wh
- vert_border
);
1543 wWindowSynthConfigureNotify(wwin
);
1545 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1546 wSetFocusTo(scr
, wwin
);
1555 *----------------------------------------------------------------------
1556 * wMouseMoveWindow--
1557 * Move the named window and the other selected ones (if any),
1558 * interactively. Also shows the position of the window, if only one
1559 * window is being moved.
1560 * If the window is not on the selected window list, the selected
1561 * windows are deselected.
1562 * If shift is pressed during the operation, the position display
1563 * is changed to another type.
1566 * True if the window was moved, False otherwise.
1569 * The window(s) position is changed, and the client(s) are
1570 * notified about that.
1571 * The position display configuration may be changed.
1572 *----------------------------------------------------------------------
1575 wMouseMoveWindow(WWindow
*wwin
, XEvent
*ev
)
1577 WScreen
*scr
= wwin
->screen_ptr
;
1579 Window root
= scr
->root_win
;
1580 KeyCode shiftl
, shiftr
;
1584 /* This needs not to change while moving, else bad things can happen */
1585 int opaqueMove
= wPreferences
.opaque_move
;
1587 #ifdef GHOST_WINDOW_MOVE
1590 rimg
= InitGhostWindowMove(scr
);
1594 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1595 XSetWindowAttributes attr
;
1597 attr
.save_under
= True
;
1598 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
,
1599 CWSaveUnder
, &attr
);
1603 initMoveData(wwin
, &moveData
);
1605 moveData
.mouseX
= ev
->xmotion
.x_root
;
1606 moveData
.mouseY
= ev
->xmotion
.y_root
;
1608 if (!wwin
->flags
.selected
) {
1609 /* this window is not selected, unselect others and move only wwin */
1610 wUnselectWindows(scr
);
1613 puts("Moving window");
1615 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1616 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1622 /* XWarpPointer() doesn't seem to generate Motion events, so
1623 we've got to simulate them */
1624 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1625 &event
.xmotion
.y_root
, &junk
, &junk
,
1626 (unsigned *) &junk
);
1628 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1629 | PointerMotionHintMask
1630 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
,
1633 if (event
.type
== MotionNotify
) {
1634 /* compress MotionNotify events */
1635 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1636 if (!checkMouseSamplingRate(&event
))
1640 switch (event
.type
) {
1642 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1643 && started
&& !scr
->selected_windows
) {
1646 drawFrames(wwin
, scr
->selected_windows
,
1647 moveData
.realX
- wwin
->frame_x
,
1648 moveData
.realY
- wwin
->frame_y
);
1651 if (wPreferences
.move_display
== WDIS_NEW
1652 && !scr
->selected_windows
) {
1653 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1656 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1657 moveData
.winWidth
, moveData
.winHeight
);
1659 if (wPreferences
.move_display
== WDIS_NEW
1660 && !scr
->selected_windows
) {
1662 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1666 drawFrames(wwin
, scr
->selected_windows
,
1667 moveData
.realX
- wwin
->frame_x
,
1668 moveData
.realY
- wwin
->frame_y
);
1671 WMHandleEvent(&event); this causes problems needs fixing */
1677 updateWindowPosition(wwin
, &moveData
,
1678 scr
->selected_windows
== NULL
1679 && wPreferences
.edge_resistance
> 0,
1681 event
.xmotion
.x_root
,
1682 event
.xmotion
.y_root
);
1684 if (!warped
&& !wPreferences
.no_autowrap
) {
1685 int oldWorkspace
= scr
->current_workspace
;
1687 if (wPreferences
.move_display
== WDIS_NEW
1688 && !scr
->selected_windows
) {
1689 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1693 drawFrames(wwin
, scr
->selected_windows
,
1694 moveData
.realX
- wwin
->frame_x
,
1695 moveData
.realY
- wwin
->frame_y
);
1697 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1698 if (scr
->current_workspace
!= oldWorkspace
1699 && wPreferences
.edge_resistance
> 0
1700 && scr
->selected_windows
== NULL
)
1701 updateMoveData(wwin
, &moveData
);
1705 drawFrames(wwin
, scr
->selected_windows
,
1706 moveData
.realX
- wwin
->frame_x
,
1707 moveData
.realY
- wwin
->frame_y
);
1709 if (wPreferences
.move_display
== WDIS_NEW
1710 && !scr
->selected_windows
) {
1712 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1718 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1719 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1721 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1722 | ButtonReleaseMask
| ButtonPressMask
,
1723 wCursor
[WCUR_MOVE
], CurrentTime
);
1725 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1728 if (!scr
->selected_windows
)
1729 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1730 moveData
.winWidth
, moveData
.winHeight
);
1732 if (started
&& !opaqueMove
)
1733 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1735 if (!opaqueMove
|| (wPreferences
.move_display
==WDIS_NEW
1736 && !scr
->selected_windows
)) {
1738 if (wPreferences
.move_display
==WDIS_NEW
)
1739 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1748 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1754 drawFrames(wwin
, scr
->selected_windows
,
1755 moveData
.realX
- wwin
->frame_x
,
1756 moveData
.realY
- wwin
->frame_y
);
1758 doWindowMove(wwin
, scr
->selected_windows
,
1759 moveData
.realX
- wwin
->frame_x
,
1760 moveData
.realY
- wwin
->frame_y
);
1762 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1763 wWindowSynthConfigureNotify(wwin
);
1765 XUngrabKeyboard(dpy
, CurrentTime
);
1768 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1769 wSetFocusTo(scr
, wwin
);
1771 if (wPreferences
.move_display
== WDIS_NEW
)
1772 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1774 /* discard all enter/leave events that happened until
1775 * the time the button was released */
1776 while (XCheckTypedEvent(dpy
, EnterNotify
, &e
)) {
1777 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1778 XPutBackEvent(dpy
, &e
);
1782 while (XCheckTypedEvent(dpy
, LeaveNotify
, &e
)) {
1783 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1784 XPutBackEvent(dpy
, &e
);
1789 if (!scr
->selected_windows
) {
1790 /* get rid of the geometry window */
1791 WMUnmapWidget(scr
->gview
);
1795 puts("End move window");
1801 if (started
&& !opaqueMove
) {
1802 drawFrames(wwin
, scr
->selected_windows
,
1803 moveData
.realX
- wwin
->frame_x
,
1804 moveData
.realY
- wwin
->frame_y
);
1806 WMHandleEvent(&event
);
1809 drawFrames(wwin
, scr
->selected_windows
,
1810 moveData
.realX
- wwin
->frame_x
,
1811 moveData
.realY
- wwin
->frame_y
);
1813 WMHandleEvent(&event
);
1819 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1820 XSetWindowAttributes attr
;
1823 attr
.save_under
= False
;
1824 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
,
1825 CWSaveUnder
, &attr
);
1829 freeMoveData(&moveData
);
1836 #define HCONSTRAIN 2
1839 getResizeDirection(WWindow
*wwin
, int x
, int y
, int dx
, int dy
,
1842 int w
= wwin
->frame
->core
->width
- 1;
1843 int cw
= wwin
->frame
->resizebar_corner_width
;
1846 /* if not resizing through the resizebar */
1847 if (!(flags
& RESIZEBAR
)) {
1848 int xdir
= (abs(x
) < (wwin
->client
.width
/2)) ? LEFT
: RIGHT
;
1849 int ydir
= (abs(y
) < (wwin
->client
.height
/2)) ? UP
: DOWN
;
1850 if (abs(dx
) < 2 || abs(dy
) < 2) {
1851 if (abs(dy
) > abs(dx
))
1856 return (xdir
| ydir
);
1859 /* window is too narrow. allow diagonal resize */
1863 if (flags
& HCONSTRAIN
)
1868 return (LEFT
| ydir
);
1870 return (RIGHT
| ydir
);
1872 /* vertical resize */
1873 if ((x
> cw
) && (x
< w
- cw
))
1881 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1889 wMouseResizeWindow(WWindow
*wwin
, XEvent
*ev
)
1892 WScreen
*scr
= wwin
->screen_ptr
;
1893 Window root
= scr
->root_win
;
1894 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1895 int fw
= wwin
->frame
->core
->width
;
1896 int fh
= wwin
->frame
->core
->height
;
1897 int fx
= wwin
->frame_x
;
1898 int fy
= wwin
->frame_y
;
1899 int is_resizebar
= (wwin
->frame
->resizebar
1900 && ev
->xany
.window
==wwin
->frame
->resizebar
->window
);
1904 int rw
= fw
, rh
= fh
;
1905 int rx1
, ry1
, rx2
, ry2
;
1907 KeyCode shiftl
, shiftr
;
1914 if (wwin
->flags
.shaded
) {
1915 wwarning("internal error: tryein");
1918 orig_x
= ev
->xbutton
.x_root
;
1919 orig_y
= ev
->xbutton
.y_root
;
1923 puts("Resizing window");
1926 wUnselectWindows(scr
);
1931 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1932 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1933 if (!WFLAGP(wwin
, no_titlebar
))
1934 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + (wPreferences
.window_title_clearance
+ TITLEBAR_EXTEND_SPACE
) * 2;
1938 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1939 | ButtonReleaseMask
| PointerMotionHintMask
1940 | ButtonPressMask
| ExposureMask
, &event
);
1941 if (!checkMouseSamplingRate(&event
))
1944 switch (event
.type
) {
1946 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1947 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1949 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1950 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
1951 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1953 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1958 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1969 dw
= orig_x
- event
.xmotion
.x_root
;
1970 else if (res
& RIGHT
)
1971 dw
= event
.xmotion
.x_root
- orig_x
;
1973 dh
= orig_y
- event
.xmotion
.y_root
;
1974 else if (res
& DOWN
)
1975 dh
= event
.xmotion
.y_root
- orig_y
;
1977 orig_x
= event
.xmotion
.x_root
;
1978 orig_y
= event
.xmotion
.y_root
;
1983 fh
= rh
- vert_border
;
1984 wWindowConstrainSize(wwin
, &fw
, &fh
);
1988 else if (res
& RIGHT
)
1992 else if (res
& DOWN
)
1994 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1995 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
2000 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
2001 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
2003 /* check if resizing through resizebar */
2009 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
2010 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
2011 flags
|= HCONSTRAIN
;
2013 res
= getResizeDirection(wwin
, tx
, ty
,
2014 orig_x
- event
.xmotion
.x_root
,
2015 orig_y
- event
.xmotion
.y_root
, flags
);
2017 if (res
== (UP
|LEFT
))
2018 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2019 | ButtonReleaseMask
| ButtonPressMask
,
2020 wCursor
[WCUR_TOPLEFTRESIZE
], CurrentTime
);
2021 else if (res
== (UP
|RIGHT
))
2022 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2023 | ButtonReleaseMask
| ButtonPressMask
,
2024 wCursor
[WCUR_TOPRIGHTRESIZE
], CurrentTime
);
2025 else if (res
== (DOWN
|LEFT
))
2026 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2027 | ButtonReleaseMask
| ButtonPressMask
,
2028 wCursor
[WCUR_BOTTOMLEFTRESIZE
], CurrentTime
);
2029 else if (res
== (DOWN
|RIGHT
))
2030 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2031 | ButtonReleaseMask
| ButtonPressMask
,
2032 wCursor
[WCUR_BOTTOMRIGHTRESIZE
], CurrentTime
);
2033 else if (res
== DOWN
|| res
== UP
)
2034 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2035 | ButtonReleaseMask
| ButtonPressMask
,
2036 wCursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2037 else if (res
& (DOWN
|UP
))
2038 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2039 | ButtonReleaseMask
| ButtonPressMask
,
2040 wCursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2041 else if (res
& (LEFT
|RIGHT
))
2042 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2043 | ButtonReleaseMask
| ButtonPressMask
,
2044 wCursor
[WCUR_HORIZONRESIZE
], CurrentTime
);
2046 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
2051 /* Draw the resize frame for the first time. */
2052 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
2054 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2056 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2061 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
2062 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
2064 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
2065 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2067 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
2069 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2071 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
2072 if (wPreferences
.size_display
== WDIS_NEW
) {
2073 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
2074 orig_fy
+ orig_fh
, res
);
2076 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2085 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2089 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2091 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2093 XUngrabKeyboard(dpy
, CurrentTime
);
2094 WMUnmapWidget(scr
->gview
);
2097 if (wwin
->client
.width
!= fw
)
2098 wwin
->flags
.user_changed_width
= 1;
2100 if (wwin
->client
.height
!= fh
- vert_border
)
2101 wwin
->flags
.user_changed_height
= 1;
2103 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
2106 puts("End resize window");
2111 WMHandleEvent(&event
);
2126 wUnselectWindows(WScreen
*scr
)
2130 if (!scr
->selected_windows
)
2133 while (WMGetArrayItemCount(scr
->selected_windows
)) {
2134 wwin
= WMGetFromArray(scr
->selected_windows
, 0);
2135 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
2136 wIconSelect(wwin
->icon
);
2138 wSelectWindow(wwin
, False
);
2140 WMFreeArray(scr
->selected_windows
);
2141 scr
->selected_windows
= NULL
;
2146 selectWindowsInside(WScreen
*scr
, int x1
, int y1
, int x2
, int y2
)
2150 /* select the windows and put them in the selected window list */
2151 tmpw
= scr
->focused_window
;
2152 while (tmpw
!= NULL
) {
2153 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
2154 if ((tmpw
->frame
->workspace
== scr
->current_workspace
2155 || IS_OMNIPRESENT(tmpw
))
2156 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
2157 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
2158 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
2159 wSelectWindow(tmpw
, True
);
2168 wSelectWindows(WScreen
*scr
, XEvent
*ev
)
2171 Window root
= scr
->root_win
;
2172 GC gc
= scr
->frame_gc
;
2173 int xp
= ev
->xbutton
.x_root
;
2174 int yp
= ev
->xbutton
.y_root
;
2179 puts("Selecting windows");
2181 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
2182 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
2183 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
],
2184 CurrentTime
) != Success
) {
2189 wUnselectWindows(scr
);
2191 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
2193 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
2194 | ButtonPressMask
, &event
);
2196 switch (event
.type
) {
2198 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2199 x
= event
.xmotion
.x_root
;
2206 y
= event
.xmotion
.y_root
;
2213 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2220 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2223 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2225 XUngrabPointer(dpy
, CurrentTime
);
2226 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
2229 wKWMSelectRootRegion(scr
, xp
, yp
, w
, h
,
2230 event
.xbutton
.state
& ControlMask
);
2231 #endif /* KWM_HINTS */
2234 puts("End window selection");
2239 WMHandleEvent(&event
);
2247 InteractivePlaceWindow(WWindow
*wwin
, int *x_ret
, int *y_ret
,
2248 unsigned width
, unsigned height
)
2250 WScreen
*scr
= wwin
->screen_ptr
;
2251 Window root
= scr
->root_win
;
2254 KeyCode shiftl
, shiftr
;
2258 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2259 GrabModeAsync
, GrabModeAsync
, None
,
2260 wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2265 if (!WFLAGP(wwin
, no_titlebar
)) {
2266 h
= WMFontHeight(scr
->title_font
) + (wPreferences
.window_title_clearance
+ TITLEBAR_EXTEND_SPACE
) * 2;
2269 if (!WFLAGP(wwin
, no_resizebar
)) {
2270 height
+= RESIZEBAR_HEIGHT
;
2272 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2273 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
,
2274 (unsigned *) &junk
);
2275 mapPositionDisplay(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2277 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2279 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2280 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2282 WMMaskEvent(dpy
, PointerMotionMask
|ButtonPressMask
|ExposureMask
|KeyPressMask
,
2285 if (!checkMouseSamplingRate(&event
))
2288 switch (event
.type
) {
2290 if ((event
.xkey
.keycode
== shiftl
)
2291 || (event
.xkey
.keycode
== shiftr
)) {
2292 drawTransparentFrame(wwin
,
2293 x
- width
/2, y
- h
/2, width
, height
);
2294 cyclePositionDisplay(wwin
,
2295 x
- width
/2, y
- h
/2, width
, height
);
2296 drawTransparentFrame(wwin
,
2297 x
- width
/2, y
- h
/2, width
, height
);
2302 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2304 x
= event
.xmotion
.x_root
;
2305 y
= event
.xmotion
.y_root
;
2307 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2308 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2310 showPosition(wwin
, x
- width
/2, y
- h
/2);
2312 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2317 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2319 *x_ret
= x
- width
/2;
2321 XUngrabPointer(dpy
, CurrentTime
);
2322 XUngrabKeyboard(dpy
, CurrentTime
);
2323 /* get rid of the geometry window */
2324 WMUnmapWidget(scr
->gview
);
2328 WMHandleEvent(&event
);