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)
585 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height)
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
.obscured
) {
753 data
->topList
[data
->count
] = tmp
;
754 data
->leftList
[data
->count
] = tmp
;
755 data
->rightList
[data
->count
] = tmp
;
756 data
->bottomList
[data
->count
] = tmp
;
762 if (data
->count
== 0) {
765 data
->rightIndex
= 0;
766 data
->bottomIndex
= 0;
771 * order from closest to the border of the screen to farthest
773 qsort(data
->topList
, data
->count
, sizeof(WWindow
**), compareWTop
);
774 qsort(data
->leftList
, data
->count
, sizeof(WWindow
**), compareWLeft
);
775 qsort(data
->rightList
, data
->count
, sizeof(WWindow
**), compareWRight
);
776 qsort(data
->bottomList
, data
->count
, sizeof(WWindow
**), compareWBottom
);
778 /* figure the position of the window relative to the others */
781 data
->leftIndex
= -1;
782 data
->rightIndex
= -1;
783 data
->bottomIndex
= -1;
785 if (WTOP(wwin
) < WBOTTOM(data
->bottomList
[0])) {
786 data
->bottomIndex
= 0;
788 if (WLEFT(wwin
) < WRIGHT(data
->rightList
[0])) {
789 data
->rightIndex
= 0;
791 if (WRIGHT(wwin
) > WLEFT(data
->leftList
[0])) {
794 if (WBOTTOM(wwin
) > WTOP(data
->topList
[0])) {
797 for (i
= 0; i
< data
->count
; i
++) {
798 if (WTOP(wwin
) >= WBOTTOM(data
->bottomList
[i
])) {
799 data
->bottomIndex
= i
+ 1;
801 if (WLEFT(wwin
) >= WRIGHT(data
->rightList
[i
])) {
802 data
->rightIndex
= i
+ 1;
804 if (WRIGHT(wwin
) <= WLEFT(data
->leftList
[i
])) {
805 data
->leftIndex
= i
+ 1;
807 if (WBOTTOM(wwin
) <= WTOP(data
->topList
[i
])) {
808 data
->topIndex
= i
+ 1;
815 initMoveData(WWindow
*wwin
, MoveData
*data
)
820 memset(data
, 0, sizeof(MoveData
));
822 for (i
= 0, tmp
= wwin
->screen_ptr
->focused_window
;
824 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
);
836 data
->realX
= wwin
->frame_x
;
837 data
->realY
= wwin
->frame_y
;
838 data
->calcX
= wwin
->frame_x
;
839 data
->calcY
= wwin
->frame_y
;
841 data
->winWidth
= wwin
->frame
->core
->width
+ 2;
842 data
->winHeight
= wwin
->frame
->core
->height
+ 2;
847 checkWorkspaceChange(WWindow
*wwin
, MoveData
*data
, Bool opaqueMove
)
849 WScreen
*scr
= wwin
->screen_ptr
;
850 Bool changed
= False
;
852 if (data
->mouseX
<= 1) {
853 if (scr
->current_workspace
> 0) {
855 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
- 1,
860 } else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
) {
862 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->workspace_count
- 1,
867 } else if (data
->mouseX
>= scr
->scr_width
- 2) {
869 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
871 if (wPreferences
.ws_cycle
872 || scr
->workspace_count
== MAX_WORKSPACES
) {
874 crossWorkspace(scr
, wwin
, opaqueMove
, 0, False
);
878 /* if user insists on trying to go to next workspace even when
879 * it's already the last, create a new one */
880 else if (data
->omouseX
== data
->mouseX
881 && wPreferences
.ws_advance
) {
883 /* detect user "rubbing" the window against the edge */
884 if (data
->rubCount
> 0
885 && data
->omouseY
- data
->mouseY
> MOVE_THRESHOLD
) {
887 data
->rubCount
= -(data
->rubCount
+ 1);
889 } else if (data
->rubCount
<= 0
890 && data
->mouseY
- data
->omouseY
> MOVE_THRESHOLD
) {
892 data
->rubCount
= -data
->rubCount
+ 1;
895 /* create a new workspace */
896 if (abs(data
->rubCount
) > 2) {
897 /* go to next workspace */
900 crossWorkspace(scr
, wwin
, opaqueMove
,
901 scr
->current_workspace
+1, False
);
905 } else if (scr
->current_workspace
< scr
->workspace_count
) {
907 /* go to next workspace */
908 crossWorkspace(scr
, wwin
, opaqueMove
,
909 scr
->current_workspace
+1, False
);
922 updateWindowPosition(WWindow
*wwin
, MoveData
*data
, Bool doResistance
,
923 Bool opaqueMove
, int newMouseX
, int newMouseY
)
925 WScreen
*scr
= wwin
->screen_ptr
;
926 int dx
, dy
; /* how much mouse moved */
927 int winL
, winR
, winT
, winB
; /* requested new window position */
928 int newX
, newY
; /* actual new window position */
929 Bool hresist
, vresist
;
937 /* check the direction of the movement */
938 dx
= newMouseX
- data
->mouseX
;
939 dy
= newMouseY
- data
->mouseY
;
941 data
->omouseX
= data
->mouseX
;
942 data
->omouseY
= data
->mouseY
;
943 data
->mouseX
= newMouseX
;
944 data
->mouseY
= newMouseY
;
946 winL
= data
->calcX
+ dx
;
947 winR
= data
->calcX
+ data
->winWidth
+ dx
;
948 winT
= data
->calcY
+ dy
;
949 winB
= data
->calcY
+ data
->winHeight
+ dy
;
959 resist
= wPreferences
.edge_resistance
;
960 /* horizontal movement: check horizontal edge resistances */
962 /* window is the leftmost window: check against screen edge */
965 /* check position of nearest window to the left */
966 if (data
->rightIndex
> 0) {
967 /* there is some window at the left: check if it will block
969 rwin
= data
->rightList
[data
->rightIndex
- 1];
971 if (data
->realY
> WBOTTOM(rwin
)
972 || (data
->realY
+ data
->winHeight
) < WTOP(rwin
)) {
975 edge
= WRIGHT(rwin
) + 1;
976 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
979 if (resist
> 0 && winL
>= edge
- resist
&& winL
<= edge
) {
984 /* window is the rightmost window: check against screen edge */
985 edge
= scr
->scr_width
;
987 /* check position of nearest window to the right */
988 if (data
->leftIndex
> 0) {
989 /* there is some window at the right: check if it will block
991 rwin
= data
->leftList
[data
->leftIndex
- 1];
993 if (data
->realY
> WBOTTOM(rwin
)
994 || (data
->realY
+ data
->winHeight
) < WTOP(rwin
)) {
998 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1001 if (resist
> 0 && winR
<= edge
+ resist
&& winR
>= edge
) {
1002 newX
= edge
- data
->winWidth
;
1007 resist
= wPreferences
.edge_resistance
;
1008 /* vertical movement: check vertical edge resistances */
1010 /* window is the topmost window: check against screen edge */
1013 /* check position of nearest window to the top */
1014 if (data
->bottomIndex
> 0) {
1015 /* there is some window at the top: check if it will block
1017 rwin
= data
->bottomList
[data
->bottomIndex
- 1];
1019 if (data
->realX
> WRIGHT(rwin
)
1020 || (data
->realX
+ data
->winWidth
) < WLEFT(rwin
)) {
1023 edge
= WBOTTOM(rwin
) + 1;
1024 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1027 if (resist
> 0 && winT
>= edge
- resist
&& winT
<= edge
) {
1031 } else if (dy
> 0) {
1032 /* window is the bottommost window: check against screen edge */
1033 edge
= scr
->scr_height
;
1035 /* check position of nearest window to the bottom */
1036 if (data
->topIndex
> 0) {
1037 /* there is some window at the bottom: check if it will block
1039 rwin
= data
->topList
[data
->topIndex
- 1];
1041 if (data
->realX
> WRIGHT(rwin
)
1042 || (data
->realX
+ data
->winWidth
) < WLEFT(rwin
)) {
1046 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1049 if (resist
> 0 && winB
<= edge
+ resist
&& winB
>= edge
) {
1050 newY
= edge
- data
->winHeight
;
1056 /* update window position */
1060 if (((dx
> 0 && data
->calcX
- data
->realX
> 0)
1061 || (dx
< 0 && data
->calcX
- data
->realX
< 0)) && !hresist
)
1064 if (((dy
> 0 && data
->calcY
- data
->realY
> 0)
1065 || (dy
< 0 && data
->calcY
- data
->realY
< 0)) && !vresist
)
1068 if (data
->realX
!= newX
|| data
->realY
!= newY
) {
1070 doWindowMove(wwin
, scr
->selected_windows
,
1071 newX
- wwin
->frame_x
,
1072 newY
- wwin
->frame_y
);
1075 drawFrames(wwin
, scr
->selected_windows
,
1076 data
->realX
- wwin
->frame_x
,
1077 data
->realY
- wwin
->frame_y
);
1080 drawFrames(wwin
, scr
->selected_windows
,
1081 newX
- wwin
->frame_x
,
1082 newY
- wwin
->frame_y
);
1086 if (!scr
->selected_windows
) {
1088 if (wPreferences
.move_display
== WDIS_NEW
) {
1090 showPosition(wwin
, data
->realX
, data
->realY
);
1092 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
1094 moveGeometryDisplayCentered(scr
, newX
+ data
->winWidth
/2,
1095 newY
+ data
->winHeight
/2);
1097 showPosition(wwin
, newX
, newY
);
1100 /* recalc relative window position */
1101 if (doResistance
&& (data
->realX
!= newX
|| data
->realY
!= newY
)) {
1102 updateResistance(wwin
, data
, newX
, newY
);
1113 typedef struct _looper
{
1119 _keyloop(_looper
*lpr
){
1120 WWindow
*wwin
= lpr
->wwin
;
1121 WScreen
*scr
= wwin
->screen_ptr
;
1122 int w
= wwin
->frame
->core
->width
;
1123 int h
= wwin
->frame
->core
->height
;
1124 int src_x
= wwin
->frame_x
;
1125 int src_y
= wwin
->frame_y
;
1127 if (!scr
->selected_windows
){
1128 drawTransparentFrame(wwin
, src_x
+lpr
->ox
, src_y
+lpr
->oy
, w
, h
);
1134 /* printf("called\n");*/
1135 if (!scr
->selected_windows
){
1136 drawTransparentFrame(wwin
, src_x
+lpr
->ox
, src_y
+lpr
->oy
, w
, h
);
1139 if(scr
->keymove_tick
)
1140 WMAddTimerHandler(15000,(WMCallback
*)_keyloop
, lpr
);
1147 wKeyboardMoveResizeWindow(WWindow
*wwin
)
1149 WScreen
*scr
= wwin
->screen_ptr
;
1150 Window root
= scr
->root_win
;
1152 int w
= wwin
->frame
->core
->width
;
1153 int h
= wwin
->frame
->core
->height
;
1154 int scr_width
= wwin
->screen_ptr
->scr_width
;
1155 int scr_height
= wwin
->screen_ptr
->scr_height
;
1156 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1157 int src_x
= wwin
->frame_x
;
1158 int src_y
= wwin
->frame_y
;
1159 int done
,off_x
,off_y
,ww
,wh
;
1162 KeySym keysym
=NoSymbol
;
1163 KeyCode shiftl
,shiftr
,ctrll
,ctrlmode
;
1169 scr->keymove_tick=1;
1170 WMAddTimerHandler(1000,(WMCallback*)_keyloop, &looper);
1173 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1174 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1175 ctrll
= XKeysymToKeycode(dpy
, XK_Control_L
);
1176 ctrlmode
=done
=off_x
=off_y
=0;
1180 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1182 if (!wwin
->flags
.selected
) {
1183 wUnselectWindows(scr
);
1186 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1187 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
1188 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
);
1190 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1191 if(scr
->selected_windows
)
1192 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1193 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1194 if(!scr
->selected_windows
)
1195 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1197 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1206 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1207 | ButtonPressMask
| ExposureMask
, &event
);
1208 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1209 if(scr
->selected_windows
)
1210 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1211 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1212 /*** I HATE EDGE RESISTANCE - ]d ***/
1215 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1219 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1224 switch (event
.type
) {
1227 if (event
.xkey
.time
- lastTime
> 50) {
1233 lastTime
= event
.xkey
.time
;
1235 if (event
.xkey
.state
& ControlMask
&& !wwin
->flags
.shaded
){
1237 wUnselectWindows(scr
);
1242 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
){
1244 cycleGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
, 0);
1246 cyclePositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1249 keysym
= XLookupKeysym(&event
.xkey
, 0);
1292 wWindowConstrainSize(wwin
, &ww
, &wh
);
1295 if (wPreferences
.ws_cycle
){
1296 if (src_x
+ off_x
+ wwin
->frame
->core
->width
< 20){
1297 if(!scr
->current_workspace
) {
1298 wWorkspaceChange(scr
, scr
->workspace_count
-1);
1300 else wWorkspaceChange(scr
, scr
->current_workspace
-1);
1303 else if (src_x
+ off_x
+ 20 > scr_width
){
1304 if(scr
->current_workspace
== scr
->workspace_count
-1) {
1305 wWorkspaceChange(scr
, 0);
1307 else wWorkspaceChange(scr
, scr
->current_workspace
+1);
1312 if (src_x
+ off_x
+ wwin
->frame
->core
->width
< 20)
1313 off_x
= 20 - wwin
->frame
->core
->width
- src_x
;
1314 else if (src_x
+ off_x
+ 20 > scr_width
)
1315 off_x
= scr_width
- 20 - src_x
;
1318 if (src_y
+ off_y
+ wwin
->frame
->core
->height
< 20)
1319 off_y
= 20 - wwin
->frame
->core
->height
- src_y
;
1320 else if (src_y
+ off_y
+ 20 > scr_height
)
1321 off_y
= scr_height
- 20 - src_y
;
1330 WMHandleEvent(&event
);
1337 if (wwin
->flags
.shaded
&& !scr
->selected_windows
){
1338 moveGeometryDisplayCentered(scr
, src_x
+off_x
+ w
/2, src_y
+off_y
+ h
/2);
1342 unmapPositionDisplay(wwin
);
1343 mapGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1345 else if(!scr
->selected_windows
){
1346 unmapGeometryDisplay(wwin
);
1347 mapPositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1351 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1352 if(scr
->selected_windows
)
1353 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1354 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1357 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1362 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1364 else if(!scr
->selected_windows
)
1365 showPosition(wwin
, src_x
+off_x
, src_y
+off_y
);
1369 scr
->keymove_tick
=0;
1371 WMDeleteTimerWithClientData(&looper);
1373 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1374 if(scr
->selected_windows
)
1375 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1376 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1379 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1383 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1384 unmapGeometryDisplay(wwin
);
1387 unmapPositionDisplay(wwin
);
1388 XUngrabKeyboard(dpy
, CurrentTime
);
1389 XUngrabPointer(dpy
, CurrentTime
);
1392 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1394 list
=scr
->selected_windows
;
1395 if(!scr
->selected_windows
){
1396 wWindowMove(wwin
, src_x
+off_x
, src_y
+off_y
);
1397 wWindowSynthConfigureNotify(wwin
);
1400 doWindowMove(wwin
,scr
->selected_windows
,off_x
,off_y
);
1402 wWindowSynthConfigureNotify(list
->head
);
1408 wWindowConfigure(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
- vert_border
);
1409 wWindowSynthConfigureNotify(wwin
);
1411 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1412 wSetFocusTo(scr
, wwin
);
1421 *----------------------------------------------------------------------
1422 * wMouseMoveWindow--
1423 * Move the named window and the other selected ones (if any),
1424 * interactively. Also shows the position of the window, if only one
1425 * window is being moved.
1426 * If the window is not on the selected window list, the selected
1427 * windows are deselected.
1428 * If shift is pressed during the operation, the position display
1429 * is changed to another type.
1432 * True if the window was moved, False otherwise.
1435 * The window(s) position is changed, and the client(s) are
1436 * notified about that.
1437 * The position display configuration may be changed.
1438 *----------------------------------------------------------------------
1441 wMouseMoveWindow(WWindow
*wwin
, XEvent
*ev
)
1443 WScreen
*scr
= wwin
->screen_ptr
;
1445 Window root
= scr
->root_win
;
1446 KeyCode shiftl
, shiftr
;
1449 /* This needs not to change while moving, else bad things can happen */
1450 int opaqueMove
= wPreferences
.opaque_move
;
1453 initMoveData(wwin
, &moveData
);
1455 moveData
.mouseX
= ev
->xmotion
.x_root
;
1456 moveData
.mouseY
= ev
->xmotion
.y_root
;
1458 if (!wwin
->flags
.selected
) {
1459 /* this window is not selected, unselect others and move only wwin */
1460 wUnselectWindows(scr
);
1463 puts("Moving window");
1465 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1466 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1472 /* XWarpPointer() doesn't seem to generate Motion events, so
1473 we've got to simulate them */
1474 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1475 &event
.xmotion
.y_root
, &junk
, &junk
,
1476 (unsigned *) &junk
);
1478 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1479 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
,
1482 if (event
.type
== MotionNotify
) {
1483 /* compress MotionNotify events */
1484 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1487 switch (event
.type
) {
1489 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1490 && started
&& !scr
->selected_windows
) {
1493 drawFrames(wwin
, scr
->selected_windows
,
1494 moveData
.realX
- wwin
->frame_x
,
1495 moveData
.realY
- wwin
->frame_y
);
1498 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1499 moveData
.winWidth
, moveData
.winHeight
);
1502 drawFrames(wwin
, scr
->selected_windows
,
1503 moveData
.realX
- wwin
->frame_x
,
1504 moveData
.realY
- wwin
->frame_y
);
1511 updateWindowPosition(wwin
, &moveData
,
1512 scr
->selected_windows
== NULL
1513 && wPreferences
.edge_resistance
> 0,
1515 event
.xmotion
.x_root
,
1516 event
.xmotion
.y_root
);
1518 if (!warped
&& !wPreferences
.no_autowrap
) {
1519 int oldWorkspace
= scr
->current_workspace
;
1521 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1522 if (scr
->current_workspace
!= oldWorkspace
1523 && wPreferences
.edge_resistance
> 0
1524 && scr
->selected_windows
== NULL
)
1525 updateMoveData(wwin
, &moveData
);
1532 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1533 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1535 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1536 | ButtonReleaseMask
| ButtonPressMask
,
1537 wCursor
[WCUR_MOVE
], CurrentTime
);
1539 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1542 if (!scr
->selected_windows
)
1543 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1544 moveData
.winWidth
, moveData
.winHeight
);
1546 if (started
&& !opaqueMove
)
1547 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1558 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1563 drawFrames(wwin
, scr
->selected_windows
,
1564 moveData
.realX
- wwin
->frame_x
,
1565 moveData
.realY
- wwin
->frame_y
);
1567 doWindowMove(wwin
, scr
->selected_windows
,
1568 moveData
.realX
- wwin
->frame_x
,
1569 moveData
.realY
- wwin
->frame_y
);
1571 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1572 wWindowSynthConfigureNotify(wwin
);
1574 XUngrabKeyboard(dpy
, CurrentTime
);
1577 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1578 wSetFocusTo(scr
, wwin
);
1580 if (wPreferences
.move_display
== WDIS_NEW
)
1581 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1583 if (!scr
->selected_windows
) {
1584 /* get rid of the geometry window */
1585 unmapPositionDisplay(wwin
);
1589 puts("End move window");
1591 freeMoveData(&moveData
);
1596 if (started
&& !opaqueMove
) {
1597 drawFrames(wwin
, scr
->selected_windows
,
1598 moveData
.realX
- wwin
->frame_x
,
1599 moveData
.realY
- wwin
->frame_y
);
1601 WMHandleEvent(&event
);
1604 drawFrames(wwin
, scr
->selected_windows
,
1605 moveData
.realX
- wwin
->frame_x
,
1606 moveData
.realY
- wwin
->frame_y
);
1608 WMHandleEvent(&event
);
1614 freeMoveData(&moveData
);
1621 #define HCONSTRAIN 2
1624 getResizeDirection(WWindow
*wwin
, int x
, int y
, int dx
, int dy
,
1627 int w
= wwin
->frame
->core
->width
- 1;
1628 int cw
= wwin
->frame
->resizebar_corner_width
;
1631 /* if not resizing through the resizebar */
1632 if (!(flags
& RESIZEBAR
)) {
1633 int xdir
= (abs(x
) < (wwin
->client
.width
/2)) ? LEFT
: RIGHT
;
1634 int ydir
= (abs(y
) < (wwin
->client
.height
/2)) ? UP
: DOWN
;
1635 if (abs(dx
) < 2 || abs(dy
) < 2) {
1636 if (abs(dy
) > abs(dx
))
1641 return (xdir
| ydir
);
1644 /* window is too narrow. allow diagonal resize */
1648 if (flags
& HCONSTRAIN
)
1653 return (LEFT
| ydir
);
1655 return (RIGHT
| ydir
);
1657 /* vertical resize */
1658 if ((x
> cw
) && (x
< w
- cw
))
1666 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1674 wMouseResizeWindow(WWindow
*wwin
, XEvent
*ev
)
1677 WScreen
*scr
= wwin
->screen_ptr
;
1678 Window root
= scr
->root_win
;
1679 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1680 int fw
= wwin
->frame
->core
->width
;
1681 int fh
= wwin
->frame
->core
->height
;
1682 int fx
= wwin
->frame_x
;
1683 int fy
= wwin
->frame_y
;
1684 int is_resizebar
= (wwin
->frame
->resizebar
1685 && ev
->xany
.window
==wwin
->frame
->resizebar
->window
);
1689 int rw
= fw
, rh
= fh
;
1690 int rx1
, ry1
, rx2
, ry2
;
1692 KeyCode shiftl
, shiftr
;
1699 if (wwin
->flags
.shaded
) {
1700 wwarning("internal error: tryein");
1703 orig_x
= ev
->xbutton
.x_root
;
1704 orig_y
= ev
->xbutton
.y_root
;
1708 puts("Resizing window");
1711 wUnselectWindows(scr
);
1716 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1717 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1718 if (!WFLAGP(wwin
, no_titlebar
))
1719 h
= wwin
->screen_ptr
->title_font
->height
+ TITLEBAR_EXTRA_HEIGHT
;
1723 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
| ButtonReleaseMask
1724 | ButtonPressMask
| ExposureMask
, &event
);
1725 switch (event
.type
) {
1727 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1728 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1730 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1731 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
1732 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1734 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1748 dw
= orig_x
- event
.xmotion
.x_root
;
1749 else if (res
& RIGHT
)
1750 dw
= event
.xmotion
.x_root
- orig_x
;
1752 dh
= orig_y
- event
.xmotion
.y_root
;
1753 else if (res
& DOWN
)
1754 dh
= event
.xmotion
.y_root
- orig_y
;
1756 orig_x
= event
.xmotion
.x_root
;
1757 orig_y
= event
.xmotion
.y_root
;
1762 fh
= rh
- vert_border
;
1763 wWindowConstrainSize(wwin
, &fw
, &fh
);
1767 else if (res
& RIGHT
)
1771 else if (res
& DOWN
)
1773 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1774 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1779 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
1780 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
1782 /* check if resizing through resizebar */
1788 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
1789 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
1790 flags
|= HCONSTRAIN
;
1792 res
= getResizeDirection(wwin
, tx
, ty
,
1793 orig_x
- event
.xmotion
.x_root
,
1794 orig_y
- event
.xmotion
.y_root
, flags
);
1796 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1797 | ButtonReleaseMask
| ButtonPressMask
,
1798 wCursor
[WCUR_RESIZE
], CurrentTime
);
1799 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1804 /* Draw the resize frame for the first time. */
1805 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
1807 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1809 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1814 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
1815 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
1817 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
1818 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1820 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
1822 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1824 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
1825 if (wPreferences
.size_display
== WDIS_NEW
) {
1826 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
1827 orig_fy
+ orig_fh
, res
);
1829 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1838 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1842 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1844 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1846 XUngrabKeyboard(dpy
, CurrentTime
);
1847 unmapGeometryDisplay(wwin
);
1849 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
1852 puts("End resize window");
1857 WMHandleEvent(&event
);
1872 wUnselectWindows(WScreen
*scr
)
1876 while (scr
->selected_windows
) {
1877 wwin
= scr
->selected_windows
->head
;
1878 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
1879 wIconSelect(wwin
->icon
);
1881 wSelectWindow(wwin
, False
);
1887 selectWindowsInside(WScreen
*scr
, int x1
, int y1
, int x2
, int y2
)
1891 /* select the windows and put them in the selected window list */
1892 tmpw
= scr
->focused_window
;
1893 while (tmpw
!= NULL
) {
1894 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
1895 if ((tmpw
->frame
->workspace
== scr
->current_workspace
1896 || IS_OMNIPRESENT(tmpw
))
1897 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
1898 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
1899 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
1900 wSelectWindow(tmpw
, True
);
1909 wSelectWindows(WScreen
*scr
, XEvent
*ev
)
1912 Window root
= scr
->root_win
;
1913 GC gc
= scr
->frame_gc
;
1914 int xp
= ev
->xbutton
.x_root
;
1915 int yp
= ev
->xbutton
.y_root
;
1920 puts("Selecting windows");
1922 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
1923 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
1924 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
],
1925 CurrentTime
) != Success
) {
1930 wUnselectWindows(scr
);
1932 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
1934 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
1935 | ButtonPressMask
, &event
);
1937 switch (event
.type
) {
1939 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
1940 x
= event
.xmotion
.x_root
;
1947 y
= event
.xmotion
.y_root
;
1954 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
1961 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1964 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
1966 XUngrabPointer(dpy
, CurrentTime
);
1967 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
1969 puts("End window selection");
1974 WMHandleEvent(&event
);
1982 InteractivePlaceWindow(WWindow
*wwin
, int *x_ret
, int *y_ret
,
1983 unsigned width
, unsigned height
)
1985 WScreen
*scr
= wwin
->screen_ptr
;
1986 Window root
= scr
->root_win
;
1989 KeyCode shiftl
, shiftr
;
1993 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
1994 GrabModeAsync
, GrabModeAsync
, None
,
1995 wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2000 if (!WFLAGP(wwin
, no_titlebar
)) {
2001 h
= scr
->title_font
->height
+ TITLEBAR_EXTRA_HEIGHT
;
2004 if (!WFLAGP(wwin
, no_resizebar
)) {
2005 height
+= RESIZEBAR_HEIGHT
;
2007 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2008 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
,
2009 (unsigned *) &junk
);
2010 mapPositionDisplay(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2012 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2014 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2015 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2017 WMMaskEvent(dpy
, PointerMotionMask
|ButtonPressMask
|ExposureMask
|KeyPressMask
,
2019 switch (event
.type
) {
2021 if ((event
.xkey
.keycode
== shiftl
)
2022 || (event
.xkey
.keycode
== shiftr
)) {
2023 drawTransparentFrame(wwin
,
2024 x
- width
/2, y
- h
/2, width
, height
);
2025 cyclePositionDisplay(wwin
,
2026 x
- width
/2, y
- h
/2, width
, height
);
2027 drawTransparentFrame(wwin
,
2028 x
- width
/2, y
- h
/2, width
, height
);
2033 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2035 x
= event
.xmotion
.x_root
;
2036 y
= event
.xmotion
.y_root
;
2038 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2039 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2041 showPosition(wwin
, x
- width
/2, y
- h
/2);
2043 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2048 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2050 *x_ret
= x
- width
/2;
2052 XUngrabPointer(dpy
, CurrentTime
);
2053 XUngrabKeyboard(dpy
, CurrentTime
);
2054 /* get rid of the geometry window */
2055 unmapPositionDisplay(wwin
);
2059 WMHandleEvent(&event
);