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>
31 #include "WindowMaker.h"
40 #include "workspace.h"
44 /* How many different types of geometry/position
45 display thingies are there? */
46 #define NUM_DISPLAYS 4
50 #define HORIZONTAL (LEFT|RIGHT)
53 #define VERTICAL (UP|DOWN)
55 /****** Global Variables ******/
56 extern Time LastTimestamp
;
58 extern Cursor wCursor
[WCUR_LAST
];
60 extern WPreferences wPreferences
;
62 extern Atom _XA_WM_PROTOCOLS
;
67 wGetGeometryWindowSize(WScreen
*scr
, unsigned int *width
,
71 *width
= XmbTextEscapement(scr
->info_text_font
->font
, "-8888 x -8888", 13);
72 *height
= (7 * scr
->info_text_font
->height
) / 4 - 1;
74 *width
= XTextWidth(scr
->info_text_font
->font
, "-8888 x -8888", 13);
75 *height
= (7 * scr
->info_text_font
->font
->ascent
) / 4 - 1;
81 *----------------------------------------------------------------------
82 * moveGeometryDisplayCentered
84 * routine that moves the geometry/position window on scr so it is
85 * centered over the given coordinates (x,y). Also the window position
86 * is clamped so it stays on the screen at all times.
87 *----------------------------------------------------------------------
90 moveGeometryDisplayCentered(WScreen
*scr
, int x
, int y
)
92 x
-= scr
->geometry_display_width
/ 2;
93 y
-= scr
->geometry_display_height
/ 2;
97 else if (x
> (scr
->scr_width
- scr
->geometry_display_width
- 3))
98 x
= scr
->scr_width
- scr
->geometry_display_width
- 3;
102 else if (y
> (scr
->scr_height
- scr
->geometry_display_height
- 3))
103 y
= scr
->scr_height
- scr
->geometry_display_height
- 3;
105 XMoveWindow(dpy
, scr
->geometry_display
, x
, y
);
110 showPosition(WWindow
*wwin
, int x
, int y
)
112 WScreen
*scr
= wwin
->screen_ptr
;
113 GC gc
= scr
->info_text_gc
;
117 if (wPreferences
.move_display
== WDIS_NEW
) {
119 int width
= wwin
->frame
->core
->width
;
120 int height
= wwin
->frame
->core
->height
;
122 GC lgc
= scr
->line_gc
;
123 XSetForeground(dpy
, lgc
, scr
->line_pixel
);
124 sprintf(num
, "%i", x
);
126 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
-1, scr
->scr_width
, y
-1);
127 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
+height
+2, scr
->scr_width
,
129 XDrawLine(dpy
, scr
->root_win
, lgc
, x
-1, 0, x
-1, scr
->scr_height
);
130 XDrawLine(dpy
, scr
->root_win
, lgc
, x
+width
+2, 0, x
+width
+2,
134 XClearArea(dpy
, scr
->geometry_display
, 1, 1,
135 scr
->geometry_display_width
-2, scr
->geometry_display_height
-2,
137 sprintf(num
, "%+i %-+i", x
, y
);
138 fw
= wTextWidth(scr
->info_text_font
->font
, num
, strlen(num
));
140 XSetForeground(dpy
, gc
, scr
->window_title_pixel
[WS_UNFOCUSED
]);
142 fh
= scr
->info_text_font
->height
;
143 wDrawString(scr
->geometry_display
, scr
->info_text_font
, gc
,
144 (scr
->geometry_display_width
- 2 - fw
) / 2,
145 (scr
->geometry_display_height
-fh
)/2 + scr
->info_text_font
->y
,
147 wDrawBevel(scr
->geometry_display
, scr
->geometry_display_width
+1,
148 scr
->geometry_display_height
+1, scr
->resizebar_texture
[0],
155 cyclePositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
157 WScreen
*scr
= wwin
->screen_ptr
;
159 wPreferences
.move_display
++;
160 wPreferences
.move_display
%= NUM_DISPLAYS
;
162 if (wPreferences
.move_display
== WDIS_NEW
) {
163 XUnmapWindow(dpy
, scr
->geometry_display
);
165 if (wPreferences
.move_display
== WDIS_CENTER
) {
166 moveGeometryDisplayCentered(scr
,
167 scr
->scr_width
/2, scr
->scr_height
/2);
168 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
169 moveGeometryDisplayCentered(scr
, 1, 1);
170 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
171 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
173 XMapRaised(dpy
, scr
->geometry_display
);
174 showPosition(wwin
, x
, y
);
180 mapPositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
182 WScreen
*scr
= wwin
->screen_ptr
;
184 if (wPreferences
.move_display
== WDIS_NEW
) {
186 } else if (wPreferences
.move_display
== WDIS_CENTER
) {
187 moveGeometryDisplayCentered(scr
, scr
->scr_width
/ 2,
188 scr
->scr_height
/ 2);
189 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
190 moveGeometryDisplayCentered(scr
, 1, 1);
191 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
192 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
194 XMapRaised(dpy
, scr
->geometry_display
);
195 showPosition(wwin
, x
, y
);
198 #define unmapPositionDisplay(w) \
199 XUnmapWindow(dpy, (w)->screen_ptr->geometry_display);
203 showGeometry(WWindow
*wwin
, int x1
, int y1
, int x2
, int y2
, int direction
)
205 WScreen
*scr
= wwin
->screen_ptr
;
206 Window root
= scr
->root_win
;
207 GC gc
= scr
->line_gc
;
208 int ty
, by
, my
, x
, y
, mx
, s
;
213 ty
= y1
+ wwin
->frame
->top_width
;
214 by
= y2
- wwin
->frame
->bottom_width
;
215 fw
= wTextWidth(scr
->info_text_font
->font
, "8888", 4);
216 fh
= scr
->info_text_font
->height
;
218 if (wPreferences
.size_display
== WDIS_NEW
) {
219 XSetForeground(dpy
, gc
, scr
->line_pixel
);
221 /* vertical geometry */
222 if (((direction
& LEFT
) && (x2
< scr
->scr_width
- fw
)) || (x1
< fw
)) {
233 segment
[0].x1
= x
- (s
+ 6); segment
[0].y1
= ty
;
234 segment
[0].x2
= x
- (s
- 10); segment
[0].y2
= ty
;
237 segment
[1].x1
= x
- (s
- 2); segment
[1].y1
= ty
+ 1;
238 segment
[1].x2
= x
- (s
- 5); segment
[1].y2
= ty
+ 7;
240 segment
[2].x1
= x
- (s
- 2); segment
[2].y1
= ty
+ 1;
241 segment
[2].x2
= x
- (s
+ 1); segment
[2].y2
= ty
+ 7;
244 segment
[3].x1
= x
- (s
- 2); segment
[3].y1
= ty
+ 1;
245 segment
[3].x2
= x
- (s
- 2); segment
[3].y2
= my
- fh
/2 - 1;
247 XDrawSegments(dpy
, root
, gc
, segment
, 4);
255 segment
[1].y1
= by
- 1;
256 segment
[1].y2
= by
- 7;
258 segment
[2].y1
= by
- 1;
259 segment
[2].y2
= by
- 7;
262 segment
[3].y1
= my
+ fh
/2 + 2;
263 segment
[3].y2
= by
- 1;
265 XDrawSegments(dpy
, root
, gc
, segment
, 4);
267 sprintf(num
, "%i", (by
- ty
- wwin
->normal_hints
->base_height
) /
268 wwin
->normal_hints
->height_inc
);
269 fw
= wTextWidth(scr
->info_text_font
->font
, num
, strlen(num
));
271 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
273 /* Display the height. */
274 wDrawString(root
, scr
->info_text_font
, gc
,
275 x
- s
+ 3 - fw
/2, my
- fh
/2 + scr
->info_text_font
->y
+ 1,
277 XSetForeground(dpy
, gc
, scr
->line_pixel
);
278 /* horizontal geometry */
286 mx
= x1
+ (x2
- x1
)/2;
287 sprintf(num
, "%i", (x2
- x1
- wwin
->normal_hints
->base_width
) /
288 wwin
->normal_hints
->width_inc
);
289 fw
= wTextWidth(scr
->info_text_font
->font
, num
, strlen(num
));
293 segment
[0].x1
= x1
; segment
[0].y1
= y
- (s
+ 6);
294 segment
[0].x2
= x1
; segment
[0].y2
= y
- (s
- 10);
297 segment
[1].x1
= x1
+ 7; segment
[1].y1
= y
- (s
+ 1);
298 segment
[1].x2
= x1
+ 1; segment
[1].y2
= y
- (s
- 2);
300 segment
[2].x1
= x1
+ 1; segment
[2].y1
= y
- (s
- 2);
301 segment
[2].x2
= x1
+ 7; segment
[2].y2
= y
- (s
- 5);
304 segment
[3].x1
= x1
+ 1; segment
[3].y1
= y
- (s
- 2);
305 segment
[3].x2
= mx
- fw
/2 - 2; segment
[3].y2
= y
- (s
- 2);
307 XDrawSegments(dpy
, root
, gc
, segment
, 4);
311 segment
[0].x1
= x2
+ 1;
312 segment
[0].x2
= x2
+ 1;
315 segment
[1].x1
= x2
- 6;
319 segment
[2].x2
= x2
- 6;
322 segment
[3].x1
= mx
+ fw
/2 + 2;
325 XDrawSegments(dpy
, root
, gc
, segment
, 4);
327 /* XSetForeground(dpy, gc, scr->window_title_pixel[WS_UNFOCUSED]); */
329 /* Display the width. */
330 wDrawString(root
, scr
->info_text_font
, gc
,
331 mx
- fw
/2 + 1, y
- s
+ fh
/2 + 1, num
, strlen(num
));
333 XClearArea(dpy
, scr
->geometry_display
, 1, 1,
334 scr
->geometry_display_width
-2, scr
->geometry_display_height
-2,
336 sprintf(num
, "%i x %-i", (x2
- x1
- wwin
->normal_hints
->base_width
)
337 / wwin
->normal_hints
->width_inc
,
338 (by
- ty
- wwin
->normal_hints
->base_height
)
339 / wwin
->normal_hints
->height_inc
);
340 fw
= wTextWidth(scr
->info_text_font
->font
, num
, strlen(num
));
342 XSetForeground(dpy
, scr
->info_text_gc
,
343 scr
->window_title_pixel
[WS_UNFOCUSED
]);
345 /* Display the height. */
346 wDrawString(scr
->geometry_display
, scr
->info_text_font
,
348 (scr
->geometry_display_width
-fw
)/2,
349 (scr
->geometry_display_height
-fh
)/2 +scr
->info_text_font
->y
,
351 wDrawBevel(scr
->geometry_display
, scr
->geometry_display_width
+1,
352 scr
->geometry_display_height
+1, scr
->resizebar_texture
[0],
359 cycleGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
, int dir
)
361 WScreen
*scr
= wwin
->screen_ptr
;
363 wPreferences
.size_display
++;
364 wPreferences
.size_display
%= NUM_DISPLAYS
;
366 if (wPreferences
.size_display
== WDIS_NEW
) {
367 XUnmapWindow(dpy
, scr
->geometry_display
);
369 if (wPreferences
.size_display
== WDIS_CENTER
) {
370 moveGeometryDisplayCentered(scr
,
371 scr
->scr_width
/ 2, scr
->scr_height
/ 2);
372 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
373 moveGeometryDisplayCentered(scr
, 1, 1);
374 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
375 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
377 XMapRaised(dpy
, scr
->geometry_display
);
378 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, dir
);
384 mapGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
386 WScreen
*scr
= wwin
->screen_ptr
;
388 if (wPreferences
.size_display
== WDIS_NEW
)
391 if (wPreferences
.size_display
== WDIS_CENTER
) {
392 moveGeometryDisplayCentered(scr
, scr
->scr_width
/ 2,
393 scr
->scr_height
/ 2);
394 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
395 moveGeometryDisplayCentered(scr
, 1, 1);
396 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
397 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
399 XMapRaised(dpy
, scr
->geometry_display
);
400 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, 0);
403 #define unmapGeometryDisplay(w) \
404 XUnmapWindow(dpy, (w)->screen_ptr->geometry_display);
408 doWindowMove(WWindow
*wwin
, LinkedList
*list
, int dx
, int dy
)
412 int scr_width
= wwin
->screen_ptr
->scr_width
;
413 int scr_height
= wwin
->screen_ptr
->scr_height
;
416 wWindowMove(wwin
, wwin
->frame_x
+ dx
, wwin
->frame_y
+ dy
);
420 x
= tmpw
->frame_x
+ dx
;
421 y
= tmpw
->frame_y
+ dy
;
423 /* don't let windows become unreachable */
425 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
426 x
= 20 - (int)tmpw
->frame
->core
->width
;
427 else if (x
+ 20 > scr_width
)
430 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
431 y
= 20 - (int)tmpw
->frame
->core
->height
;
432 else if (y
+ 20 > scr_height
)
435 wWindowMove(tmpw
, x
, y
);
443 drawTransparentFrame(WWindow
*wwin
, int x
, int y
, int width
, int height
)
445 Window root
= wwin
->screen_ptr
->root_win
;
446 GC gc
= wwin
->screen_ptr
->frame_gc
;
450 if (!WFLAGP(wwin
, no_titlebar
) && !wwin
->flags
.shaded
) {
451 h
= wwin
->screen_ptr
->title_font
->height
+ TITLEBAR_EXTRA_HEIGHT
;
453 if (!WFLAGP(wwin
, no_resizebar
) && !wwin
->flags
.shaded
) {
454 /* Can't use wwin-frame->bottom_width because, in some cases
455 (e.g. interactive placement), frame does not point to anything. */
456 bottom
= RESIZEBAR_HEIGHT
- 1;
458 XDrawRectangle(dpy
, root
, gc
, x
, y
, width
+ 1, height
+ 1);
461 XDrawLine(dpy
, root
, gc
, x
+ 1, y
+ h
, x
+ width
+ 1, y
+ h
);
464 XDrawLine(dpy
, root
, gc
, x
+ 1,
467 y
+ height
- bottom
);
473 drawFrames(WWindow
*wwin
, LinkedList
*list
, int dx
, int dy
)
476 int scr_width
= wwin
->screen_ptr
->scr_width
;
477 int scr_height
= wwin
->screen_ptr
->scr_height
;
482 x
= wwin
->frame_x
+ dx
;
483 y
= wwin
->frame_y
+ dy
;
485 drawTransparentFrame(wwin
, x
, y
,
486 wwin
->frame
->core
->width
,
487 wwin
->frame
->core
->height
);
492 x
= tmpw
->frame_x
+ dx
;
493 y
= tmpw
->frame_y
+ dy
;
495 /* don't let windows become unreachable */
497 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
498 x
= 20 - (int)tmpw
->frame
->core
->width
;
499 else if (x
+ 20 > scr_width
)
502 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
503 y
= 20 - (int)tmpw
->frame
->core
->height
;
504 else if (y
+ 20 > scr_height
)
507 drawTransparentFrame(tmpw
, x
, y
, tmpw
->frame
->core
->width
,
508 tmpw
->frame
->core
->height
);
523 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &ev
)) ;
528 crossWorkspace(WScreen
*scr
, WWindow
*wwin
, int opaque_move
,
529 int new_workspace
, int rewind
)
531 /* do not let window be unmapped */
533 wwin
->flags
.changing_workspace
= 1;
534 wWindowChangeWorkspace(wwin
, new_workspace
);
536 /* go to new workspace */
537 wWorkspaceChange(scr
, new_workspace
);
539 wwin
->flags
.changing_workspace
= 0;
542 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, scr
->scr_width
- 20, 0);
544 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, -(scr
->scr_width
- 20), 0);
549 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
550 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
551 GrabModeAsync
, None
, wCursor
[WCUR_MOVE
], CurrentTime
);
559 /* arrays of WWindows sorted by the respective border position */
560 WWindow
**topList
; /* top border */
561 WWindow
**leftList
; /* left border */
562 WWindow
**rightList
; /* right border */
563 WWindow
**bottomList
; /* bottom border */
566 /* index of window in the above lists indicating the relative position
567 * of the window with the others */
573 int rubCount
; /* for workspace switching */
575 int winWidth
, winHeight
; /* width/height of the window */
576 int realX
, realY
; /* actual position of the window */
577 int calcX
, calcY
; /* calculated position of window */
578 int omouseX
, omouseY
; /* old mouse position */
579 int mouseX
, mouseY
; /* last known position of the pointer */
582 #define WTOP(w) (w)->frame_y
583 #define WLEFT(w) (w)->frame_x
584 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width + FRAME_BORDER_WIDTH)
585 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height + FRAME_BORDER_WIDTH)
588 compareWTop(const void *a
, const void *b
)
590 WWindow
*wwin1
= *(WWindow
**)a
;
591 WWindow
*wwin2
= *(WWindow
**)b
;
593 if (WTOP(wwin1
) > WTOP(wwin2
))
595 else if (WTOP(wwin1
) < WTOP(wwin2
))
603 compareWLeft(const void *a
, const void *b
)
605 WWindow
*wwin1
= *(WWindow
**)a
;
606 WWindow
*wwin2
= *(WWindow
**)b
;
608 if (WLEFT(wwin1
) > WLEFT(wwin2
))
610 else if (WLEFT(wwin1
) < WLEFT(wwin2
))
618 compareWRight(const void *a
, const void *b
)
620 WWindow
*wwin1
= *(WWindow
**)a
;
621 WWindow
*wwin2
= *(WWindow
**)b
;
623 if (WRIGHT(wwin1
) < WRIGHT(wwin2
))
625 else if (WRIGHT(wwin1
) > WRIGHT(wwin2
))
634 compareWBottom(const void *a
, const void *b
)
636 WWindow
*wwin1
= *(WWindow
**)a
;
637 WWindow
*wwin2
= *(WWindow
**)b
;
639 if (WBOTTOM(wwin1
) < WBOTTOM(wwin2
))
641 else if (WBOTTOM(wwin1
) > WBOTTOM(wwin2
))
649 updateResistance(WWindow
*wwin
, MoveData
*data
, int newX
, int newY
)
652 int newX2
= newX
+ data
->winWidth
;
653 int newY2
= newY
+ data
->winHeight
;
656 if (newX
< data
->realX
) {
657 if (data
->rightIndex
> 0
658 && newX
< WRIGHT(data
->rightList
[data
->rightIndex
-1])) {
660 } else if (data
->leftIndex
<= data
->count
-1
661 && newX2
<= WLEFT(data
->leftList
[data
->leftIndex
])) {
664 } else if (newX
> data
->realX
) {
665 if (data
->leftIndex
> 0
666 && newX2
> WLEFT(data
->leftList
[data
->leftIndex
-1])) {
668 } else if (data
->rightIndex
<= data
->count
-1
669 && newX
>= WRIGHT(data
->rightList
[data
->rightIndex
])) {
675 if (newY
< data
->realY
) {
676 if (data
->bottomIndex
> 0
677 && newY
< WBOTTOM(data
->bottomList
[data
->bottomIndex
-1])) {
679 } else if (data
->topIndex
<= data
->count
-1
680 && newY2
<= WTOP(data
->topList
[data
->topIndex
])) {
683 } else if (newY
> data
->realY
) {
684 if (data
->topIndex
> 0
685 && newY2
> WTOP(data
->topList
[data
->topIndex
-1])) {
687 } else if (data
->bottomIndex
<= data
->count
-1
688 && newY
>= WBOTTOM(data
->bottomList
[data
->bottomIndex
])) {
697 /* TODO: optimize this */
698 if (data
->realY
< WBOTTOM(data
->bottomList
[0])) {
699 data
->bottomIndex
= 0;
701 if (data
->realX
< WRIGHT(data
->rightList
[0])) {
702 data
->rightIndex
= 0;
704 if ((data
->realX
+ data
->winWidth
) > WLEFT(data
->leftList
[0])) {
707 if ((data
->realY
+ data
->winHeight
) > WTOP(data
->topList
[0])) {
710 for (i
= 0; i
< data
->count
; i
++) {
711 if (data
->realY
> WBOTTOM(data
->bottomList
[i
])) {
712 data
->bottomIndex
= i
+ 1;
714 if (data
->realX
> WRIGHT(data
->rightList
[i
])) {
715 data
->rightIndex
= i
+ 1;
717 if ((data
->realX
+ data
->winWidth
) < WLEFT(data
->leftList
[i
])) {
718 data
->leftIndex
= i
+ 1;
720 if ((data
->realY
+ data
->winHeight
) < WTOP(data
->topList
[i
])) {
721 data
->topIndex
= i
+ 1;
728 freeMoveData(MoveData
*data
)
733 free(data
->leftList
);
735 free(data
->rightList
);
736 if (data
->bottomList
)
737 free(data
->bottomList
);
742 updateMoveData(WWindow
*wwin
, MoveData
*data
)
744 WScreen
*scr
= wwin
->screen_ptr
;
749 tmp
= scr
->focused_window
;
751 if (tmp
!= wwin
&& scr
->current_workspace
== tmp
->frame
->workspace
752 && !tmp
->flags
.miniaturized
753 && !tmp
->flags
.hidden
754 && !tmp
->flags
.obscured
) {
755 data
->topList
[data
->count
] = tmp
;
756 data
->leftList
[data
->count
] = tmp
;
757 data
->rightList
[data
->count
] = tmp
;
758 data
->bottomList
[data
->count
] = tmp
;
764 if (data
->count
== 0) {
767 data
->rightIndex
= 0;
768 data
->bottomIndex
= 0;
773 * order from closest to the border of the screen to farthest
775 qsort(data
->topList
, data
->count
, sizeof(WWindow
**), compareWTop
);
776 qsort(data
->leftList
, data
->count
, sizeof(WWindow
**), compareWLeft
);
777 qsort(data
->rightList
, data
->count
, sizeof(WWindow
**), compareWRight
);
778 qsort(data
->bottomList
, data
->count
, sizeof(WWindow
**), compareWBottom
);
780 /* figure the position of the window relative to the others */
783 data
->leftIndex
= -1;
784 data
->rightIndex
= -1;
785 data
->bottomIndex
= -1;
787 if (WTOP(wwin
) < WBOTTOM(data
->bottomList
[0])) {
788 data
->bottomIndex
= 0;
790 if (WLEFT(wwin
) < WRIGHT(data
->rightList
[0])) {
791 data
->rightIndex
= 0;
793 if (WRIGHT(wwin
) > WLEFT(data
->leftList
[0])) {
796 if (WBOTTOM(wwin
) > WTOP(data
->topList
[0])) {
799 for (i
= 0; i
< data
->count
; i
++) {
800 if (WTOP(wwin
) >= WBOTTOM(data
->bottomList
[i
])) {
801 data
->bottomIndex
= i
+ 1;
803 if (WLEFT(wwin
) >= WRIGHT(data
->rightList
[i
])) {
804 data
->rightIndex
= i
+ 1;
806 if (WRIGHT(wwin
) <= WLEFT(data
->leftList
[i
])) {
807 data
->leftIndex
= i
+ 1;
809 if (WBOTTOM(wwin
) <= WTOP(data
->topList
[i
])) {
810 data
->topIndex
= i
+ 1;
817 initMoveData(WWindow
*wwin
, MoveData
*data
)
822 memset(data
, 0, sizeof(MoveData
));
824 for (i
= 0, tmp
= wwin
->screen_ptr
->focused_window
;
826 tmp
= tmp
->prev
, i
++);
829 data
->topList
= wmalloc(sizeof(WWindow
*) * i
);
830 data
->leftList
= wmalloc(sizeof(WWindow
*) * i
);
831 data
->rightList
= wmalloc(sizeof(WWindow
*) * i
);
832 data
->bottomList
= wmalloc(sizeof(WWindow
*) * i
);
834 updateMoveData(wwin
, data
);
837 data
->realX
= wwin
->frame_x
;
838 data
->realY
= wwin
->frame_y
;
839 data
->calcX
= wwin
->frame_x
;
840 data
->calcY
= wwin
->frame_y
;
842 data
->winWidth
= wwin
->frame
->core
->width
+ 2;
843 data
->winHeight
= wwin
->frame
->core
->height
+ 2;
848 checkWorkspaceChange(WWindow
*wwin
, MoveData
*data
, Bool opaqueMove
)
850 WScreen
*scr
= wwin
->screen_ptr
;
851 Bool changed
= False
;
853 if (data
->mouseX
<= 1) {
854 if (scr
->current_workspace
> 0) {
856 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
- 1,
861 } else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
) {
863 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->workspace_count
- 1,
868 } else if (data
->mouseX
>= scr
->scr_width
- 2) {
870 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
872 if (wPreferences
.ws_cycle
873 || scr
->workspace_count
== MAX_WORKSPACES
) {
875 crossWorkspace(scr
, wwin
, opaqueMove
, 0, False
);
879 /* if user insists on trying to go to next workspace even when
880 * it's already the last, create a new one */
881 else if (data
->omouseX
== data
->mouseX
882 && wPreferences
.ws_advance
) {
884 /* detect user "rubbing" the window against the edge */
885 if (data
->rubCount
> 0
886 && data
->omouseY
- data
->mouseY
> MOVE_THRESHOLD
) {
888 data
->rubCount
= -(data
->rubCount
+ 1);
890 } else if (data
->rubCount
<= 0
891 && data
->mouseY
- data
->omouseY
> MOVE_THRESHOLD
) {
893 data
->rubCount
= -data
->rubCount
+ 1;
896 /* create a new workspace */
897 if (abs(data
->rubCount
) > 2) {
898 /* go to next workspace */
901 crossWorkspace(scr
, wwin
, opaqueMove
,
902 scr
->current_workspace
+1, False
);
906 } else if (scr
->current_workspace
< scr
->workspace_count
) {
908 /* go to next workspace */
909 crossWorkspace(scr
, wwin
, opaqueMove
,
910 scr
->current_workspace
+1, False
);
923 updateWindowPosition(WWindow
*wwin
, MoveData
*data
, Bool doResistance
,
924 Bool opaqueMove
, int newMouseX
, int newMouseY
)
926 WScreen
*scr
= wwin
->screen_ptr
;
927 int dx
, dy
; /* how much mouse moved */
928 int winL
, winR
, winT
, winB
; /* requested new window position */
929 int newX
, newY
; /* actual new window position */
930 Bool hresist
, vresist
;
938 /* check the direction of the movement */
939 dx
= newMouseX
- data
->mouseX
;
940 dy
= newMouseY
- data
->mouseY
;
942 data
->omouseX
= data
->mouseX
;
943 data
->omouseY
= data
->mouseY
;
944 data
->mouseX
= newMouseX
;
945 data
->mouseY
= newMouseY
;
947 winL
= data
->calcX
+ dx
;
948 winR
= data
->calcX
+ data
->winWidth
+ dx
;
949 winT
= data
->calcY
+ dy
;
950 winB
= data
->calcY
+ data
->winHeight
+ dy
;
960 resist
= wPreferences
.edge_resistance
;
961 /* horizontal movement: check horizontal edge resistances */
963 /* window is the leftmost window: check against screen edge */
966 /* check position of nearest window to the left */
967 if (data
->rightIndex
> 0) {
968 /* there is some window at the left: check if it will block
970 rwin
= data
->rightList
[data
->rightIndex
- 1];
972 if (data
->realY
> WBOTTOM(rwin
)
973 || (data
->realY
+ data
->winHeight
) < WTOP(rwin
)) {
976 edge
= WRIGHT(rwin
) + 1;
977 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
980 if (resist
> 0 && winL
>= edge
- resist
&& winL
<= edge
) {
985 /* window is the rightmost window: check against screen edge */
986 edge
= scr
->scr_width
;
988 /* check position of nearest window to the right */
989 if (data
->leftIndex
> 0) {
990 /* there is some window at the right: check if it will block
992 rwin
= data
->leftList
[data
->leftIndex
- 1];
994 if (data
->realY
> WBOTTOM(rwin
)
995 || (data
->realY
+ data
->winHeight
) < WTOP(rwin
)) {
999 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1002 if (resist
> 0 && winR
<= edge
+ resist
&& winR
>= edge
) {
1003 newX
= edge
- data
->winWidth
;
1008 resist
= wPreferences
.edge_resistance
;
1009 /* vertical movement: check vertical edge resistances */
1011 /* window is the topmost window: check against screen edge */
1014 /* check position of nearest window to the top */
1015 if (data
->bottomIndex
> 0) {
1016 /* there is some window at the top: check if it will block
1018 rwin
= data
->bottomList
[data
->bottomIndex
- 1];
1020 if (data
->realX
> WRIGHT(rwin
)
1021 || (data
->realX
+ data
->winWidth
) < WLEFT(rwin
)) {
1024 edge
= WBOTTOM(rwin
) + 1;
1025 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1028 if (resist
> 0 && winT
>= edge
- resist
&& winT
<= edge
) {
1032 } else if (dy
> 0) {
1033 /* window is the bottommost window: check against screen edge */
1034 edge
= scr
->scr_height
;
1036 /* check position of nearest window to the bottom */
1037 if (data
->topIndex
> 0) {
1038 /* there is some window at the bottom: check if it will block
1040 rwin
= data
->topList
[data
->topIndex
- 1];
1042 if (data
->realX
> WRIGHT(rwin
)
1043 || (data
->realX
+ data
->winWidth
) < WLEFT(rwin
)) {
1047 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1050 if (resist
> 0 && winB
<= edge
+ resist
&& winB
>= edge
) {
1051 newY
= edge
- data
->winHeight
;
1057 /* update window position */
1061 if (((dx
> 0 && data
->calcX
- data
->realX
> 0)
1062 || (dx
< 0 && data
->calcX
- data
->realX
< 0)) && !hresist
)
1065 if (((dy
> 0 && data
->calcY
- data
->realY
> 0)
1066 || (dy
< 0 && data
->calcY
- data
->realY
< 0)) && !vresist
)
1069 if (data
->realX
!= newX
|| data
->realY
!= newY
) {
1071 doWindowMove(wwin
, scr
->selected_windows
,
1072 newX
- wwin
->frame_x
,
1073 newY
- wwin
->frame_y
);
1076 drawFrames(wwin
, scr
->selected_windows
,
1077 data
->realX
- wwin
->frame_x
,
1078 data
->realY
- wwin
->frame_y
);
1081 if (!scr
->selected_windows
1082 && wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
1084 moveGeometryDisplayCentered(scr
, newX
+ data
->winWidth
/2,
1085 newY
+ data
->winHeight
/2);
1090 drawFrames(wwin
, scr
->selected_windows
,
1091 newX
- wwin
->frame_x
,
1092 newY
- wwin
->frame_y
);
1095 if (!scr
->selected_windows
) {
1097 if (wPreferences
.move_display
== WDIS_NEW
) {
1099 showPosition(wwin
, data
->realX
, data
->realY
);
1102 showPosition(wwin
, newX
, newY
);
1107 /* recalc relative window position */
1108 if (doResistance
&& (data
->realX
!= newX
|| data
->realY
!= newY
)) {
1109 updateResistance(wwin
, data
, newX
, newY
);
1120 typedef struct _looper
{
1126 _keyloop(_looper
*lpr
){
1127 WWindow
*wwin
= lpr
->wwin
;
1128 WScreen
*scr
= wwin
->screen_ptr
;
1129 int w
= wwin
->frame
->core
->width
;
1130 int h
= wwin
->frame
->core
->height
;
1131 int src_x
= wwin
->frame_x
;
1132 int src_y
= wwin
->frame_y
;
1134 if (!scr
->selected_windows
){
1135 drawTransparentFrame(wwin
, src_x
+lpr
->ox
, src_y
+lpr
->oy
, w
, h
);
1141 /* printf("called\n");*/
1142 if (!scr
->selected_windows
){
1143 drawTransparentFrame(wwin
, src_x
+lpr
->ox
, src_y
+lpr
->oy
, w
, h
);
1146 if(scr
->keymove_tick
)
1147 WMAddTimerHandler(15000,(WMCallback
*)_keyloop
, lpr
);
1154 wKeyboardMoveResizeWindow(WWindow
*wwin
)
1156 WScreen
*scr
= wwin
->screen_ptr
;
1157 Window root
= scr
->root_win
;
1159 int w
= wwin
->frame
->core
->width
;
1160 int h
= wwin
->frame
->core
->height
;
1161 int scr_width
= wwin
->screen_ptr
->scr_width
;
1162 int scr_height
= wwin
->screen_ptr
->scr_height
;
1163 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1164 int src_x
= wwin
->frame_x
;
1165 int src_y
= wwin
->frame_y
;
1166 int done
,off_x
,off_y
,ww
,wh
;
1169 KeySym keysym
=NoSymbol
;
1170 KeyCode shiftl
,shiftr
,ctrll
,ctrlmode
;
1176 scr->keymove_tick=1;
1177 WMAddTimerHandler(1000,(WMCallback*)_keyloop, &looper);
1180 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1181 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1182 ctrll
= XKeysymToKeycode(dpy
, XK_Control_L
);
1183 ctrlmode
=done
=off_x
=off_y
=0;
1187 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1189 if (!wwin
->flags
.selected
) {
1190 wUnselectWindows(scr
);
1193 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1194 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
1195 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
);
1197 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1198 if(scr
->selected_windows
)
1199 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1200 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1201 if(!scr
->selected_windows
)
1202 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1204 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1213 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1214 | ButtonPressMask
| ExposureMask
, &event
);
1215 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1216 if(scr
->selected_windows
)
1217 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1218 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1219 /*** I HATE EDGE RESISTANCE - ]d ***/
1222 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1226 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1231 switch (event
.type
) {
1234 if (event
.xkey
.time
- lastTime
> 50) {
1240 lastTime
= event
.xkey
.time
;
1242 if (event
.xkey
.state
& ControlMask
&& !wwin
->flags
.shaded
){
1244 wUnselectWindows(scr
);
1249 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
){
1251 cycleGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
, 0);
1253 cyclePositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1256 keysym
= XLookupKeysym(&event
.xkey
, 0);
1299 wWindowConstrainSize(wwin
, &ww
, &wh
);
1302 if (wPreferences
.ws_cycle
){
1303 if (src_x
+ off_x
+ wwin
->frame
->core
->width
< 20){
1304 if(!scr
->current_workspace
) {
1305 wWorkspaceChange(scr
, scr
->workspace_count
-1);
1307 else wWorkspaceChange(scr
, scr
->current_workspace
-1);
1310 else if (src_x
+ off_x
+ 20 > scr_width
){
1311 if(scr
->current_workspace
== scr
->workspace_count
-1) {
1312 wWorkspaceChange(scr
, 0);
1314 else wWorkspaceChange(scr
, scr
->current_workspace
+1);
1319 if (src_x
+ off_x
+ wwin
->frame
->core
->width
< 20)
1320 off_x
= 20 - wwin
->frame
->core
->width
- src_x
;
1321 else if (src_x
+ off_x
+ 20 > scr_width
)
1322 off_x
= scr_width
- 20 - src_x
;
1325 if (src_y
+ off_y
+ wwin
->frame
->core
->height
< 20)
1326 off_y
= 20 - wwin
->frame
->core
->height
- src_y
;
1327 else if (src_y
+ off_y
+ 20 > scr_height
)
1328 off_y
= scr_height
- 20 - src_y
;
1337 WMHandleEvent(&event
);
1344 if (wwin
->flags
.shaded
&& !scr
->selected_windows
){
1345 moveGeometryDisplayCentered(scr
, src_x
+off_x
+ w
/2, src_y
+off_y
+ h
/2);
1349 unmapPositionDisplay(wwin
);
1350 mapGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1352 else if(!scr
->selected_windows
){
1353 unmapGeometryDisplay(wwin
);
1354 mapPositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1358 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1359 if(scr
->selected_windows
)
1360 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1361 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1364 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1369 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1371 else if(!scr
->selected_windows
)
1372 showPosition(wwin
, src_x
+off_x
, src_y
+off_y
);
1376 scr
->keymove_tick
=0;
1378 WMDeleteTimerWithClientData(&looper);
1380 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1381 if(scr
->selected_windows
)
1382 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1383 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1386 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1390 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1391 unmapGeometryDisplay(wwin
);
1394 unmapPositionDisplay(wwin
);
1395 XUngrabKeyboard(dpy
, CurrentTime
);
1396 XUngrabPointer(dpy
, CurrentTime
);
1399 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1401 list
=scr
->selected_windows
;
1402 if(!scr
->selected_windows
){
1403 wWindowMove(wwin
, src_x
+off_x
, src_y
+off_y
);
1404 wWindowSynthConfigureNotify(wwin
);
1407 doWindowMove(wwin
,scr
->selected_windows
,off_x
,off_y
);
1409 wWindowSynthConfigureNotify(list
->head
);
1415 wWindowConfigure(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
- vert_border
);
1416 wWindowSynthConfigureNotify(wwin
);
1418 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1419 wSetFocusTo(scr
, wwin
);
1428 *----------------------------------------------------------------------
1429 * wMouseMoveWindow--
1430 * Move the named window and the other selected ones (if any),
1431 * interactively. Also shows the position of the window, if only one
1432 * window is being moved.
1433 * If the window is not on the selected window list, the selected
1434 * windows are deselected.
1435 * If shift is pressed during the operation, the position display
1436 * is changed to another type.
1439 * True if the window was moved, False otherwise.
1442 * The window(s) position is changed, and the client(s) are
1443 * notified about that.
1444 * The position display configuration may be changed.
1445 *----------------------------------------------------------------------
1448 wMouseMoveWindow(WWindow
*wwin
, XEvent
*ev
)
1450 WScreen
*scr
= wwin
->screen_ptr
;
1452 Window root
= scr
->root_win
;
1453 KeyCode shiftl
, shiftr
;
1456 /* This needs not to change while moving, else bad things can happen */
1457 int opaqueMove
= wPreferences
.opaque_move
;
1460 initMoveData(wwin
, &moveData
);
1462 moveData
.mouseX
= ev
->xmotion
.x_root
;
1463 moveData
.mouseY
= ev
->xmotion
.y_root
;
1465 if (!wwin
->flags
.selected
) {
1466 /* this window is not selected, unselect others and move only wwin */
1467 wUnselectWindows(scr
);
1470 puts("Moving window");
1472 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1473 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1479 /* XWarpPointer() doesn't seem to generate Motion events, so
1480 we've got to simulate them */
1481 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1482 &event
.xmotion
.y_root
, &junk
, &junk
,
1483 (unsigned *) &junk
);
1485 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1486 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
,
1489 if (event
.type
== MotionNotify
) {
1490 /* compress MotionNotify events */
1491 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1494 switch (event
.type
) {
1496 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1497 && started
&& !scr
->selected_windows
) {
1500 drawFrames(wwin
, scr
->selected_windows
,
1501 moveData
.realX
- wwin
->frame_x
,
1502 moveData
.realY
- wwin
->frame_y
);
1505 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1506 moveData
.winWidth
, moveData
.winHeight
);
1509 drawFrames(wwin
, scr
->selected_windows
,
1510 moveData
.realX
- wwin
->frame_x
,
1511 moveData
.realY
- wwin
->frame_y
);
1518 updateWindowPosition(wwin
, &moveData
,
1519 scr
->selected_windows
== NULL
1520 && wPreferences
.edge_resistance
> 0,
1522 event
.xmotion
.x_root
,
1523 event
.xmotion
.y_root
);
1525 if (!warped
&& !wPreferences
.no_autowrap
) {
1526 int oldWorkspace
= scr
->current_workspace
;
1528 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1529 if (scr
->current_workspace
!= oldWorkspace
1530 && wPreferences
.edge_resistance
> 0
1531 && scr
->selected_windows
== NULL
)
1532 updateMoveData(wwin
, &moveData
);
1539 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1540 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1542 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1543 | ButtonReleaseMask
| ButtonPressMask
,
1544 wCursor
[WCUR_MOVE
], CurrentTime
);
1546 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1549 if (!scr
->selected_windows
)
1550 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1551 moveData
.winWidth
, moveData
.winHeight
);
1553 if (started
&& !opaqueMove
)
1554 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1565 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1570 drawFrames(wwin
, scr
->selected_windows
,
1571 moveData
.realX
- wwin
->frame_x
,
1572 moveData
.realY
- wwin
->frame_y
);
1574 doWindowMove(wwin
, scr
->selected_windows
,
1575 moveData
.realX
- wwin
->frame_x
,
1576 moveData
.realY
- wwin
->frame_y
);
1578 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1579 wWindowSynthConfigureNotify(wwin
);
1581 XUngrabKeyboard(dpy
, CurrentTime
);
1584 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1585 wSetFocusTo(scr
, wwin
);
1587 if (wPreferences
.move_display
== WDIS_NEW
)
1588 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1590 if (!scr
->selected_windows
) {
1591 /* get rid of the geometry window */
1592 unmapPositionDisplay(wwin
);
1596 puts("End move window");
1598 freeMoveData(&moveData
);
1603 if (started
&& !opaqueMove
) {
1604 drawFrames(wwin
, scr
->selected_windows
,
1605 moveData
.realX
- wwin
->frame_x
,
1606 moveData
.realY
- wwin
->frame_y
);
1608 WMHandleEvent(&event
);
1611 drawFrames(wwin
, scr
->selected_windows
,
1612 moveData
.realX
- wwin
->frame_x
,
1613 moveData
.realY
- wwin
->frame_y
);
1615 WMHandleEvent(&event
);
1621 freeMoveData(&moveData
);
1628 #define HCONSTRAIN 2
1631 getResizeDirection(WWindow
*wwin
, int x
, int y
, int dx
, int dy
,
1634 int w
= wwin
->frame
->core
->width
- 1;
1635 int cw
= wwin
->frame
->resizebar_corner_width
;
1638 /* if not resizing through the resizebar */
1639 if (!(flags
& RESIZEBAR
)) {
1640 int xdir
= (abs(x
) < (wwin
->client
.width
/2)) ? LEFT
: RIGHT
;
1641 int ydir
= (abs(y
) < (wwin
->client
.height
/2)) ? UP
: DOWN
;
1642 if (abs(dx
) < 2 || abs(dy
) < 2) {
1643 if (abs(dy
) > abs(dx
))
1648 return (xdir
| ydir
);
1651 /* window is too narrow. allow diagonal resize */
1655 if (flags
& HCONSTRAIN
)
1660 return (LEFT
| ydir
);
1662 return (RIGHT
| ydir
);
1664 /* vertical resize */
1665 if ((x
> cw
) && (x
< w
- cw
))
1673 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1681 wMouseResizeWindow(WWindow
*wwin
, XEvent
*ev
)
1684 WScreen
*scr
= wwin
->screen_ptr
;
1685 Window root
= scr
->root_win
;
1686 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1687 int fw
= wwin
->frame
->core
->width
;
1688 int fh
= wwin
->frame
->core
->height
;
1689 int fx
= wwin
->frame_x
;
1690 int fy
= wwin
->frame_y
;
1691 int is_resizebar
= (wwin
->frame
->resizebar
1692 && ev
->xany
.window
==wwin
->frame
->resizebar
->window
);
1696 int rw
= fw
, rh
= fh
;
1697 int rx1
, ry1
, rx2
, ry2
;
1699 KeyCode shiftl
, shiftr
;
1706 if (wwin
->flags
.shaded
) {
1707 wwarning("internal error: tryein");
1710 orig_x
= ev
->xbutton
.x_root
;
1711 orig_y
= ev
->xbutton
.y_root
;
1715 puts("Resizing window");
1718 wUnselectWindows(scr
);
1723 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1724 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1725 if (!WFLAGP(wwin
, no_titlebar
))
1726 h
= wwin
->screen_ptr
->title_font
->height
+ TITLEBAR_EXTRA_HEIGHT
;
1730 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
| ButtonReleaseMask
1731 | ButtonPressMask
| ExposureMask
, &event
);
1732 switch (event
.type
) {
1734 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1735 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1737 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1738 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
1739 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1741 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1755 dw
= orig_x
- event
.xmotion
.x_root
;
1756 else if (res
& RIGHT
)
1757 dw
= event
.xmotion
.x_root
- orig_x
;
1759 dh
= orig_y
- event
.xmotion
.y_root
;
1760 else if (res
& DOWN
)
1761 dh
= event
.xmotion
.y_root
- orig_y
;
1763 orig_x
= event
.xmotion
.x_root
;
1764 orig_y
= event
.xmotion
.y_root
;
1769 fh
= rh
- vert_border
;
1770 wWindowConstrainSize(wwin
, &fw
, &fh
);
1774 else if (res
& RIGHT
)
1778 else if (res
& DOWN
)
1780 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1781 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1786 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
1787 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
1789 /* check if resizing through resizebar */
1795 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
1796 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
1797 flags
|= HCONSTRAIN
;
1799 res
= getResizeDirection(wwin
, tx
, ty
,
1800 orig_x
- event
.xmotion
.x_root
,
1801 orig_y
- event
.xmotion
.y_root
, flags
);
1803 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1804 | ButtonReleaseMask
| ButtonPressMask
,
1805 wCursor
[WCUR_RESIZE
], CurrentTime
);
1806 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1811 /* Draw the resize frame for the first time. */
1812 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
1814 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1816 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1821 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
1822 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
1824 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
1825 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1827 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
1829 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1831 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
1832 if (wPreferences
.size_display
== WDIS_NEW
) {
1833 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
1834 orig_fy
+ orig_fh
, res
);
1836 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1845 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1849 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1851 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1853 XUngrabKeyboard(dpy
, CurrentTime
);
1854 unmapGeometryDisplay(wwin
);
1856 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
1859 puts("End resize window");
1864 WMHandleEvent(&event
);
1879 wUnselectWindows(WScreen
*scr
)
1883 while (scr
->selected_windows
) {
1884 wwin
= scr
->selected_windows
->head
;
1885 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
1886 wIconSelect(wwin
->icon
);
1888 wSelectWindow(wwin
, False
);
1894 selectWindowsInside(WScreen
*scr
, int x1
, int y1
, int x2
, int y2
)
1898 /* select the windows and put them in the selected window list */
1899 tmpw
= scr
->focused_window
;
1900 while (tmpw
!= NULL
) {
1901 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
1902 if ((tmpw
->frame
->workspace
== scr
->current_workspace
1903 || IS_OMNIPRESENT(tmpw
))
1904 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
1905 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
1906 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
1907 wSelectWindow(tmpw
, True
);
1916 wSelectWindows(WScreen
*scr
, XEvent
*ev
)
1919 Window root
= scr
->root_win
;
1920 GC gc
= scr
->frame_gc
;
1921 int xp
= ev
->xbutton
.x_root
;
1922 int yp
= ev
->xbutton
.y_root
;
1927 puts("Selecting windows");
1929 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
1930 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
1931 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
],
1932 CurrentTime
) != Success
) {
1937 wUnselectWindows(scr
);
1939 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
1941 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
1942 | ButtonPressMask
, &event
);
1944 switch (event
.type
) {
1946 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
1947 x
= event
.xmotion
.x_root
;
1954 y
= event
.xmotion
.y_root
;
1961 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
1968 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1971 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
1973 XUngrabPointer(dpy
, CurrentTime
);
1974 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
1976 puts("End window selection");
1981 WMHandleEvent(&event
);
1989 InteractivePlaceWindow(WWindow
*wwin
, int *x_ret
, int *y_ret
,
1990 unsigned width
, unsigned height
)
1992 WScreen
*scr
= wwin
->screen_ptr
;
1993 Window root
= scr
->root_win
;
1996 KeyCode shiftl
, shiftr
;
2000 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2001 GrabModeAsync
, GrabModeAsync
, None
,
2002 wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2007 if (!WFLAGP(wwin
, no_titlebar
)) {
2008 h
= scr
->title_font
->height
+ TITLEBAR_EXTRA_HEIGHT
;
2011 if (!WFLAGP(wwin
, no_resizebar
)) {
2012 height
+= RESIZEBAR_HEIGHT
;
2014 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2015 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
,
2016 (unsigned *) &junk
);
2017 mapPositionDisplay(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2019 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2021 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2022 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2024 WMMaskEvent(dpy
, PointerMotionMask
|ButtonPressMask
|ExposureMask
|KeyPressMask
,
2026 switch (event
.type
) {
2028 if ((event
.xkey
.keycode
== shiftl
)
2029 || (event
.xkey
.keycode
== shiftr
)) {
2030 drawTransparentFrame(wwin
,
2031 x
- width
/2, y
- h
/2, width
, height
);
2032 cyclePositionDisplay(wwin
,
2033 x
- width
/2, y
- h
/2, width
, height
);
2034 drawTransparentFrame(wwin
,
2035 x
- width
/2, y
- h
/2, width
, height
);
2040 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2042 x
= event
.xmotion
.x_root
;
2043 y
= event
.xmotion
.y_root
;
2045 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2046 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2048 showPosition(wwin
, x
- width
/2, y
- h
/2);
2050 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2055 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2057 *x_ret
= x
- width
/2;
2059 XUngrabPointer(dpy
, CurrentTime
);
2060 XUngrabKeyboard(dpy
, CurrentTime
);
2061 /* get rid of the geometry window */
2062 unmapPositionDisplay(wwin
);
2066 WMHandleEvent(&event
);