2 * Window Maker window manager
4 * Copyright (c) 1997-2003 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 along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <X11/Xutil.h>
25 #include <X11/keysym.h>
31 #include "WindowMaker.h"
38 #include "workspace.h"
39 #include "placement.h"
45 #include <WINGs/WINGsP.h>
47 /* How many different types of geometry/position
48 display thingies are there? */
49 #define NUM_DISPLAYS 5
53 #define HORIZONTAL (LEFT|RIGHT)
56 #define VERTICAL (UP|DOWN)
58 /* True if window currently has a border. This also includes borderless
59 * windows which are currently selected
61 #define HAS_BORDER_WITH_SELECT(w) ((w)->flags.selected || HAS_BORDER(w))
63 /****** Global Variables ******/
64 extern Cursor wCursor
[WCUR_LAST
];
67 *----------------------------------------------------------------------
68 * checkMouseSamplingRate-
69 * For lowering the mouse motion sampling rate for machines where
70 * it's too high (SGIs). If it returns False then the event should be
72 *----------------------------------------------------------------------
74 static Bool
checkMouseSamplingRate(XEvent
* ev
)
76 static Time previousMotion
= 0;
78 if (ev
->type
== MotionNotify
) {
79 if (ev
->xmotion
.time
- previousMotion
< DELAY_BETWEEN_MOUSE_SAMPLING
) {
82 previousMotion
= ev
->xmotion
.time
;
89 *----------------------------------------------------------------------
90 * moveGeometryDisplayCentered
92 * routine that moves the geometry/position window on scr so it is
93 * centered over the given coordinates (x,y). Also the window position
94 * is clamped so it stays on the screen at all times.
95 *----------------------------------------------------------------------
97 static void moveGeometryDisplayCentered(WScreen
* scr
, int x
, int y
)
99 unsigned int w
= WMWidgetWidth(scr
->gview
);
100 unsigned int h
= WMWidgetHeight(scr
->gview
);
101 int x1
= 0, y1
= 0, x2
= scr
->scr_width
, y2
= scr
->scr_height
;
106 /* dead area check */
107 if (scr
->xine_info
.count
) {
114 rect
.size
.height
= h
;
116 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
118 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
119 rect
= wGetRectForHead(scr
, head
);
122 x2
= x1
+ rect
.size
.width
;
123 y2
= y1
+ rect
.size
.height
;
129 else if (x
> (x2
- w
))
134 else if (y
> (y2
- h
))
137 WMMoveWidget(scr
->gview
, x
, y
);
140 static void showPosition(WWindow
* wwin
, int x
, int y
)
142 WScreen
*scr
= wwin
->screen_ptr
;
144 if (wPreferences
.move_display
== WDIS_NEW
) {
146 int width
= wwin
->frame
->core
->width
;
147 int height
= wwin
->frame
->core
->height
;
149 GC lgc
= scr
->line_gc
;
150 XSetForeground(dpy
, lgc
, scr
->line_pixel
);
151 sprintf(num
, "%i", x
);
153 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
- 1, scr
->scr_width
, y
- 1);
154 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
+ height
+ 2, scr
->scr_width
, y
+ height
+ 2);
155 XDrawLine(dpy
, scr
->root_win
, lgc
, x
- 1, 0, x
- 1, scr
->scr_height
);
156 XDrawLine(dpy
, scr
->root_win
, lgc
, x
+ width
+ 2, 0, x
+ width
+ 2, scr
->scr_height
);
159 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
163 static void cyclePositionDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
)
165 WScreen
*scr
= wwin
->screen_ptr
;
168 wPreferences
.move_display
++;
169 wPreferences
.move_display
%= NUM_DISPLAYS
;
171 if (wPreferences
.move_display
== WDIS_NEW
) {
172 wPreferences
.move_display
++;
173 wPreferences
.move_display
%= NUM_DISPLAYS
;
176 if (wPreferences
.move_display
== WDIS_NONE
) {
177 WMUnmapWidget(scr
->gview
);
179 if (wPreferences
.move_display
== WDIS_CENTER
) {
180 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
181 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
182 rect
.pos
.y
+ rect
.size
.height
/ 2);
183 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
184 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
185 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
186 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
187 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
189 WMMapWidget(scr
->gview
);
193 static void mapPositionDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
)
195 WScreen
*scr
= wwin
->screen_ptr
;
198 if (wPreferences
.move_display
== WDIS_NEW
|| wPreferences
.move_display
== WDIS_NONE
) {
200 } else if (wPreferences
.move_display
== WDIS_CENTER
) {
201 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
202 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
203 rect
.pos
.y
+ rect
.size
.height
/ 2);
204 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
205 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
206 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
207 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
208 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
210 WMMapWidget(scr
->gview
);
211 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
214 static void showGeometry(WWindow
* wwin
, int x1
, int y1
, int x2
, int y2
, int direction
)
216 WScreen
*scr
= wwin
->screen_ptr
;
217 Window root
= scr
->root_win
;
218 GC gc
= scr
->line_gc
;
219 int ty
, by
, my
, x
, y
, mx
, s
;
224 /* This seems necessary for some odd reason (too lazy to write x1-1 and
225 * x2-1 everywhere below in the code). But why only for x? */
229 if (HAS_BORDER_WITH_SELECT(wwin
)) {
230 x1
+= scr
->frame_border_width
;
231 x2
+= scr
->frame_border_width
;
232 y1
+= scr
->frame_border_width
;
233 y2
+= scr
->frame_border_width
;
236 ty
= y1
+ wwin
->frame
->top_width
;
237 by
= y2
- wwin
->frame
->bottom_width
;
239 if (wPreferences
.size_display
== WDIS_NEW
) {
240 fw
= XTextWidth(scr
->tech_draw_font
, "8888", 4);
241 fh
= scr
->tech_draw_font
->ascent
+ scr
->tech_draw_font
->descent
;
243 XSetForeground(dpy
, gc
, scr
->line_pixel
);
245 /* vertical geometry */
246 if (((direction
& LEFT
) && (x2
< scr
->scr_width
- fw
)) || (x1
< fw
)) {
255 /* top arrow & end bar */
256 segment
[0].x1
= x
- (s
+ 6);
258 segment
[0].x2
= x
- (s
- 10);
262 segment
[1].x1
= x
- (s
- 2);
263 segment
[1].y1
= ty
+ 1;
264 segment
[1].x2
= x
- (s
- 5);
265 segment
[1].y2
= ty
+ 7;
267 segment
[2].x1
= x
- (s
- 2);
268 segment
[2].y1
= ty
+ 1;
269 segment
[2].x2
= x
- (s
+ 1);
270 segment
[2].y2
= ty
+ 7;
273 segment
[3].x1
= x
- (s
- 2);
274 segment
[3].y1
= ty
+ 1;
275 segment
[3].x2
= x
- (s
- 2);
276 segment
[3].y2
= my
- fh
/ 2 - 1;
278 XDrawSegments(dpy
, root
, gc
, segment
, 4);
280 /* bottom arrow & end bar */
285 segment
[1].y1
= by
- 1;
286 segment
[1].y2
= by
- 7;
288 segment
[2].y1
= by
- 1;
289 segment
[2].y2
= by
- 7;
292 segment
[3].y1
= my
+ fh
/ 2 + 2;
293 segment
[3].y2
= by
- 1;
295 XDrawSegments(dpy
, root
, gc
, segment
, 4);
297 snprintf(num
, sizeof(num
), "%i", (by
- ty
- wwin
->normal_hints
->base_height
) /
298 wwin
->normal_hints
->height_inc
);
299 fw
= XTextWidth(scr
->tech_draw_font
, num
, strlen(num
));
301 /* Display the height. */
302 XSetFont(dpy
, gc
, scr
->tech_draw_font
->fid
);
303 XDrawString(dpy
, root
, gc
, x
- s
+ 3 - fw
/ 2, my
+ scr
->tech_draw_font
->ascent
- fh
/ 2 + 1, num
,
306 /* horizontal geometry */
314 mx
= x1
+ (x2
- x1
) / 2;
315 snprintf(num
, sizeof(num
), "%i", (x2
- x1
- wwin
->normal_hints
->base_width
) /
316 wwin
->normal_hints
->width_inc
);
317 fw
= XTextWidth(scr
->tech_draw_font
, num
, strlen(num
));
319 /* left arrow & end bar */
321 segment
[0].y1
= y
- (s
+ 6);
323 segment
[0].y2
= y
- (s
- 10);
326 segment
[1].x1
= x1
+ 7;
327 segment
[1].y1
= y
- (s
+ 1);
328 segment
[1].x2
= x1
+ 1;
329 segment
[1].y2
= y
- (s
- 2);
331 segment
[2].x1
= x1
+ 1;
332 segment
[2].y1
= y
- (s
- 2);
333 segment
[2].x2
= x1
+ 7;
334 segment
[2].y2
= y
- (s
- 5);
337 segment
[3].x1
= x1
+ 1;
338 segment
[3].y1
= y
- (s
- 2);
339 segment
[3].x2
= mx
- fw
/ 2 - 2;
340 segment
[3].y2
= y
- (s
- 2);
342 XDrawSegments(dpy
, root
, gc
, segment
, 4);
344 /* right arrow & end bar */
345 segment
[0].x1
= x2
+ 1;
346 segment
[0].x2
= x2
+ 1;
349 segment
[1].x1
= x2
- 6;
353 segment
[2].x2
= x2
- 6;
356 segment
[3].x1
= mx
+ fw
/ 2 + 2;
359 XDrawSegments(dpy
, root
, gc
, segment
, 4);
361 /* Display the width. */
362 XDrawString(dpy
, root
, gc
, mx
- fw
/ 2 + 1, y
- s
+ scr
->tech_draw_font
->ascent
- fh
/ 2 + 1, num
,
365 WSetGeometryViewShownSize(scr
->gview
, (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
);
372 static void cycleGeometryDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
, int dir
)
374 WScreen
*scr
= wwin
->screen_ptr
;
377 wPreferences
.size_display
++;
378 wPreferences
.size_display
%= NUM_DISPLAYS
;
380 if (wPreferences
.size_display
== WDIS_NEW
|| wPreferences
.size_display
== WDIS_NONE
) {
381 WMUnmapWidget(scr
->gview
);
383 if (wPreferences
.size_display
== WDIS_CENTER
) {
384 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
385 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
386 rect
.pos
.y
+ rect
.size
.height
/ 2);
387 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
388 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
389 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 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
);
398 static void mapGeometryDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
)
400 WScreen
*scr
= wwin
->screen_ptr
;
403 if (wPreferences
.size_display
== WDIS_NEW
|| wPreferences
.size_display
== WDIS_NONE
)
406 if (wPreferences
.size_display
== WDIS_CENTER
) {
407 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
408 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
409 rect
.pos
.y
+ rect
.size
.height
/ 2);
410 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
411 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
412 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 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);
420 static void doWindowMove(WWindow
* wwin
, WMArray
* array
, int dx
, int dy
)
423 WScreen
*scr
= wwin
->screen_ptr
;
426 if (!array
|| !WMGetArrayItemCount(array
)) {
427 wWindowMove(wwin
, wwin
->frame_x
+ dx
, wwin
->frame_y
+ dy
);
429 WMArrayIterator iter
;
431 WM_ITERATE_ARRAY(array
, tmpw
, iter
) {
432 x
= tmpw
->frame_x
+ dx
;
433 y
= tmpw
->frame_y
+ dy
;
435 #if 1 /* XXX: with xinerama patch was #if 0, check this */
436 /* don't let windows become unreachable */
438 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
439 x
= 20 - (int)tmpw
->frame
->core
->width
;
440 else if (x
+ 20 > scr
->scr_width
)
441 x
= scr
->scr_width
- 20;
443 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
444 y
= 20 - (int)tmpw
->frame
->core
->height
;
445 else if (y
+ 20 > scr
->scr_height
)
446 y
= scr
->scr_height
- 20;
448 wScreenBringInside(scr
, &x
, &y
,
449 (int)tmpw
->frame
->core
->width
, (int)tmpw
->frame
->core
->height
);
452 wWindowMove(tmpw
, x
, y
);
457 static void drawTransparentFrame(WWindow
* wwin
, int x
, int y
, int width
, int height
)
459 Window root
= wwin
->screen_ptr
->root_win
;
460 GC gc
= wwin
->screen_ptr
->frame_gc
;
464 if (HAS_BORDER_WITH_SELECT(wwin
)) {
465 x
+= wwin
->screen_ptr
->frame_border_width
;
466 y
+= wwin
->screen_ptr
->frame_border_width
;
469 if (HAS_TITLEBAR(wwin
) && !wwin
->flags
.shaded
) {
470 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + (wPreferences
.window_title_clearance
+
471 TITLEBAR_EXTEND_SPACE
) * 2;
473 if (h
> wPreferences
.window_title_max_height
)
474 h
= wPreferences
.window_title_max_height
;
476 if (h
< wPreferences
.window_title_min_height
)
477 h
= wPreferences
.window_title_min_height
;
479 if (HAS_RESIZEBAR(wwin
) && !wwin
->flags
.shaded
) {
480 /* Can't use wwin-frame->bottom_width because, in some cases
481 (e.g. interactive placement), frame does not point to anything. */
482 bottom
= RESIZEBAR_HEIGHT
;
484 XDrawRectangle(dpy
, root
, gc
, x
- 1, y
- 1, width
+ 1, height
+ 1);
487 XDrawLine(dpy
, root
, gc
, x
, y
+ h
- 1, x
+ width
, y
+ h
- 1);
490 XDrawLine(dpy
, root
, gc
, x
, y
+ height
- bottom
, x
+ width
, y
+ height
- bottom
);
494 static void drawFrames(WWindow
* wwin
, WMArray
* array
, int dx
, int dy
)
497 int scr_width
= wwin
->screen_ptr
->scr_width
;
498 int scr_height
= wwin
->screen_ptr
->scr_height
;
503 x
= wwin
->frame_x
+ dx
;
504 y
= wwin
->frame_y
+ dy
;
506 drawTransparentFrame(wwin
, x
, y
, wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
509 WMArrayIterator iter
;
511 WM_ITERATE_ARRAY(array
, tmpw
, iter
) {
512 x
= tmpw
->frame_x
+ dx
;
513 y
= tmpw
->frame_y
+ dy
;
515 /* don't let windows become unreachable */
516 #if 1 /* XXX: was 0 in XINERAMA patch, check */
517 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
518 x
= 20 - (int)tmpw
->frame
->core
->width
;
519 else if (x
+ 20 > scr_width
)
522 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
523 y
= 20 - (int)tmpw
->frame
->core
->height
;
524 else if (y
+ 20 > scr_height
)
528 wScreenBringInside(wwin
->screen_ptr
, &x
, &y
,
529 (int)tmpw
->frame
->core
->width
, (int)tmpw
->frame
->core
->height
);
532 drawTransparentFrame(tmpw
, x
, y
, tmpw
->frame
->core
->width
, tmpw
->frame
->core
->height
);
537 static void flushMotion(void)
542 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &ev
)) ;
545 static void crossWorkspace(WScreen
* scr
, WWindow
* wwin
, int opaque_move
, int new_workspace
, int rewind
)
547 /* do not let window be unmapped */
549 wwin
->flags
.changing_workspace
= 1;
550 wWindowChangeWorkspace(wwin
, new_workspace
);
552 /* go to new workspace */
553 wWorkspaceChange(scr
, new_workspace
);
555 wwin
->flags
.changing_workspace
= 0;
558 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, scr
->scr_width
- 20, 0);
560 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, -(scr
->scr_width
- 20), 0);
565 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
566 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
567 GrabModeAsync
, None
, wCursor
[WCUR_MOVE
], CurrentTime
);
572 /* arrays of WWindows sorted by the respective border position */
573 WWindow
**topList
; /* top border */
574 WWindow
**leftList
; /* left border */
575 WWindow
**rightList
; /* right border */
576 WWindow
**bottomList
; /* bottom border */
579 /* index of window in the above lists indicating the relative position
580 * of the window with the others */
586 int rubCount
; /* for workspace switching */
588 int winWidth
, winHeight
; /* width/height of the window */
589 int realX
, realY
; /* actual position of the window */
590 int calcX
, calcY
; /* calculated position of window */
591 int omouseX
, omouseY
; /* old mouse position */
592 int mouseX
, mouseY
; /* last known position of the pointer */
595 #define WTOP(w) (w)->frame_y
596 #define WLEFT(w) (w)->frame_x
597 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width - 1 + \
598 (HAS_BORDER_WITH_SELECT(w) ? 2*(w)->screen_ptr->frame_border_width : 0))
599 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height - 1 + \
600 (HAS_BORDER_WITH_SELECT(w) ? 2*(w)->screen_ptr->frame_border_width : 0))
602 static int 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
))
615 static int compareWLeft(const void *a
, const void *b
)
617 WWindow
*wwin1
= *(WWindow
**) a
;
618 WWindow
*wwin2
= *(WWindow
**) b
;
620 if (WLEFT(wwin1
) > WLEFT(wwin2
))
622 else if (WLEFT(wwin1
) < WLEFT(wwin2
))
628 static int compareWRight(const void *a
, const void *b
)
630 WWindow
*wwin1
= *(WWindow
**) a
;
631 WWindow
*wwin2
= *(WWindow
**) b
;
633 if (WRIGHT(wwin1
) < WRIGHT(wwin2
))
635 else if (WRIGHT(wwin1
) > WRIGHT(wwin2
))
641 static int compareWBottom(const void *a
, const void *b
)
643 WWindow
*wwin1
= *(WWindow
**) a
;
644 WWindow
*wwin2
= *(WWindow
**) b
;
646 if (WBOTTOM(wwin1
) < WBOTTOM(wwin2
))
648 else if (WBOTTOM(wwin1
) > WBOTTOM(wwin2
))
654 static void updateResistance(WWindow
* wwin
, MoveData
* data
, int newX
, int newY
)
657 int newX2
= newX
+ data
->winWidth
;
658 int newY2
= newY
+ data
->winHeight
;
661 if (newX
< data
->realX
) {
662 if (data
->rightIndex
> 0 && newX
< WRIGHT(data
->rightList
[data
->rightIndex
- 1])) {
664 } else if (data
->leftIndex
<= data
->count
- 1 && newX2
<= WLEFT(data
->leftList
[data
->leftIndex
])) {
667 } else if (newX
> data
->realX
) {
668 if (data
->leftIndex
> 0 && newX2
> WLEFT(data
->leftList
[data
->leftIndex
- 1])) {
670 } else if (data
->rightIndex
<= data
->count
- 1
671 && newX
>= WRIGHT(data
->rightList
[data
->rightIndex
])) {
677 if (newY
< data
->realY
) {
678 if (data
->bottomIndex
> 0 && newY
< WBOTTOM(data
->bottomList
[data
->bottomIndex
- 1])) {
680 } else if (data
->topIndex
<= data
->count
- 1
681 && newY2
<= WTOP(data
->topList
[data
->topIndex
])) {
684 } else if (newY
> data
->realY
) {
685 if (data
->topIndex
> 0 && 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;
726 static void freeMoveData(MoveData
* data
)
729 wfree(data
->topList
);
731 wfree(data
->leftList
);
733 wfree(data
->rightList
);
734 if (data
->bottomList
)
735 wfree(data
->bottomList
);
738 static void updateMoveData(WWindow
* wwin
, MoveData
* data
)
740 WScreen
*scr
= wwin
->screen_ptr
;
745 tmp
= scr
->focused_window
;
747 if (tmp
!= wwin
&& scr
->current_workspace
== tmp
->frame
->workspace
748 && !tmp
->flags
.miniaturized
749 && !tmp
->flags
.hidden
&& !tmp
->flags
.obscured
&& !WFLAGP(tmp
, sunken
)) {
750 data
->topList
[data
->count
] = tmp
;
751 data
->leftList
[data
->count
] = tmp
;
752 data
->rightList
[data
->count
] = tmp
;
753 data
->bottomList
[data
->count
] = tmp
;
759 if (data
->count
== 0) {
762 data
->rightIndex
= 0;
763 data
->bottomIndex
= 0;
767 /* order from closest to the border of the screen to farthest */
769 qsort(data
->topList
, data
->count
, sizeof(WWindow
**), compareWTop
);
770 qsort(data
->leftList
, data
->count
, sizeof(WWindow
**), compareWLeft
);
771 qsort(data
->rightList
, data
->count
, sizeof(WWindow
**), compareWRight
);
772 qsort(data
->bottomList
, data
->count
, sizeof(WWindow
**), compareWBottom
);
774 /* figure the position of the window relative to the others */
777 data
->leftIndex
= -1;
778 data
->rightIndex
= -1;
779 data
->bottomIndex
= -1;
781 if (WTOP(wwin
) < WBOTTOM(data
->bottomList
[0])) {
782 data
->bottomIndex
= 0;
784 if (WLEFT(wwin
) < WRIGHT(data
->rightList
[0])) {
785 data
->rightIndex
= 0;
787 if (WRIGHT(wwin
) > WLEFT(data
->leftList
[0])) {
790 if (WBOTTOM(wwin
) > WTOP(data
->topList
[0])) {
793 for (i
= 0; i
< data
->count
; i
++) {
794 if (WTOP(wwin
) >= WBOTTOM(data
->bottomList
[i
])) {
795 data
->bottomIndex
= i
+ 1;
797 if (WLEFT(wwin
) >= WRIGHT(data
->rightList
[i
])) {
798 data
->rightIndex
= i
+ 1;
800 if (WRIGHT(wwin
) <= WLEFT(data
->leftList
[i
])) {
801 data
->leftIndex
= i
+ 1;
803 if (WBOTTOM(wwin
) <= WTOP(data
->topList
[i
])) {
804 data
->topIndex
= i
+ 1;
809 static void initMoveData(WWindow
* wwin
, MoveData
* data
)
814 memset(data
, 0, sizeof(MoveData
));
816 for (i
= 0, tmp
= wwin
->screen_ptr
->focused_window
; tmp
!= NULL
; tmp
= tmp
->prev
, i
++) ;
819 data
->topList
= wmalloc(sizeof(WWindow
*) * i
);
820 data
->leftList
= wmalloc(sizeof(WWindow
*) * i
);
821 data
->rightList
= wmalloc(sizeof(WWindow
*) * i
);
822 data
->bottomList
= wmalloc(sizeof(WWindow
*) * i
);
824 updateMoveData(wwin
, data
);
827 data
->realX
= wwin
->frame_x
;
828 data
->realY
= wwin
->frame_y
;
829 data
->calcX
= wwin
->frame_x
;
830 data
->calcY
= wwin
->frame_y
;
832 data
->winWidth
= wwin
->frame
->core
->width
+ (HAS_BORDER_WITH_SELECT(wwin
) ? 2 * wwin
->screen_ptr
->frame_border_width
: 0);
833 data
->winHeight
= wwin
->frame
->core
->height
+ (HAS_BORDER_WITH_SELECT(wwin
) ? 2 * wwin
->screen_ptr
->frame_border_width
: 0);
836 static Bool
checkWorkspaceChange(WWindow
* wwin
, MoveData
* data
, Bool opaqueMove
)
838 WScreen
*scr
= wwin
->screen_ptr
;
839 Bool changed
= False
;
841 if (data
->mouseX
<= 1) {
842 if (scr
->current_workspace
> 0) {
844 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
- 1, True
);
848 } else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
) {
850 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->workspace_count
- 1, True
);
854 } else if (data
->mouseX
>= scr
->scr_width
- 2) {
856 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
858 if (wPreferences
.ws_cycle
|| scr
->workspace_count
== MAX_WORKSPACES
) {
860 crossWorkspace(scr
, wwin
, opaqueMove
, 0, False
);
864 /* if user insists on trying to go to next workspace even when
865 * it's already the last, create a new one */
866 else if (data
->omouseX
== data
->mouseX
&& wPreferences
.ws_advance
) {
868 /* detect user "rubbing" the window against the edge */
869 if (data
->rubCount
> 0 && data
->omouseY
- data
->mouseY
> MOVE_THRESHOLD
) {
871 data
->rubCount
= -(data
->rubCount
+ 1);
873 } else if (data
->rubCount
<= 0 && data
->mouseY
- data
->omouseY
> MOVE_THRESHOLD
) {
875 data
->rubCount
= -data
->rubCount
+ 1;
878 /* create a new workspace */
879 if (abs(data
->rubCount
) > 2) {
880 /* go to next workspace */
883 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
+ 1, False
);
887 } else if (scr
->current_workspace
< scr
->workspace_count
) {
889 /* go to next workspace */
890 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
+ 1, False
);
902 updateWindowPosition(WWindow
* wwin
, MoveData
* data
, Bool doResistance
,
903 Bool opaqueMove
, int newMouseX
, int newMouseY
)
905 WScreen
*scr
= wwin
->screen_ptr
;
906 int dx
, dy
; /* how much mouse moved */
907 int winL
, winR
, winT
, winB
; /* requested new window position */
908 int newX
, newY
; /* actual new window position */
909 Bool hresist
, vresist
;
915 /* check the direction of the movement */
916 dx
= newMouseX
- data
->mouseX
;
917 dy
= newMouseY
- data
->mouseY
;
919 data
->omouseX
= data
->mouseX
;
920 data
->omouseY
= data
->mouseY
;
921 data
->mouseX
= newMouseX
;
922 data
->mouseY
= newMouseY
;
924 winL
= data
->calcX
+ dx
;
925 winR
= data
->calcX
+ data
->winWidth
+ dx
;
926 winT
= data
->calcY
+ dy
;
927 winB
= data
->calcY
+ data
->winHeight
+ dy
;
939 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
940 attract
= wPreferences
.attract
;
941 /* horizontal movement: check horizontal edge resistances */
945 /* window is the leftmost window: check against screen edge */
947 /* Add inter head resistance 1/2 (if needed) */
948 head
= wGetHeadForPointerLocation(scr
);
949 rect
= wGetRectForHead(scr
, head
);
951 l_edge
= WMAX(scr
->totalUsableArea
[head
].x1
, rect
.pos
.x
);
952 edge_l
= l_edge
- resist
;
953 edge_r
= WMIN(scr
->totalUsableArea
[head
].x2
, rect
.pos
.x
+ rect
.size
.width
);
954 r_edge
= edge_r
+ resist
;
957 if ((data
->rightIndex
>= 0) && (data
->rightIndex
<= data
->count
)) {
960 for (i
= data
->rightIndex
- 1; i
>= 0; i
--) {
961 looprw
= data
->rightList
[i
];
962 if (!(data
->realY
> WBOTTOM(looprw
)
963 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
964 if (attract
|| ((data
->realX
< (WRIGHT(looprw
) + 2)) && dx
< 0)) {
965 l_edge
= WRIGHT(looprw
) + 1;
966 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
973 for (i
= data
->rightIndex
; i
< data
->count
; i
++) {
974 looprw
= data
->rightList
[i
];
975 if (!(data
->realY
> WBOTTOM(looprw
)
976 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
977 r_edge
= WRIGHT(looprw
) + 1;
978 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
985 if ((data
->leftIndex
>= 0) && (data
->leftIndex
<= data
->count
)) {
988 for (i
= data
->leftIndex
- 1; i
>= 0; i
--) {
989 looprw
= data
->leftList
[i
];
990 if (!(data
->realY
> WBOTTOM(looprw
)
991 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
993 || (((data
->realX
+ data
->winWidth
) > (WLEFT(looprw
) - 1))
995 edge_r
= WLEFT(looprw
);
996 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1003 for (i
= data
->leftIndex
; i
< data
->count
; i
++) {
1004 looprw
= data
->leftList
[i
];
1005 if (!(data
->realY
> WBOTTOM(looprw
)
1006 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1007 edge_l
= WLEFT(looprw
);
1008 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1015 printf("%d %d\n",winL,winR);
1016 printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);
1019 if ((winL
- l_edge
) < (r_edge
- winL
)) {
1021 if ((attract
&& winL
<= l_edge
+ resist
&& winL
>= l_edge
- resist
)
1022 || (dx
< 0 && winL
<= l_edge
&& winL
>= l_edge
- resist
)) {
1028 if (resist
> 0 && attract
&& winL
>= r_edge
- resist
&& winL
<= r_edge
+ resist
) {
1034 if ((winR
- edge_l
) < (edge_r
- winR
)) {
1035 if (resist
> 0 && attract
&& winR
<= edge_l
+ resist
&& winR
>= edge_l
- resist
) {
1036 newX
= edge_l
- data
->winWidth
;
1041 if ((attract
&& winR
>= edge_r
- resist
&& winR
<= edge_r
+ resist
)
1042 || (dx
> 0 && winR
>= edge_r
&& winR
<= edge_r
+ resist
)) {
1043 newX
= edge_r
- data
->winWidth
;
1050 /* Add inter head resistance 2/2 (if needed) */
1051 t_edge
= WMAX(scr
->totalUsableArea
[head
].y1
, rect
.pos
.y
);
1052 edge_t
= t_edge
- resist
;
1053 edge_b
= WMIN(scr
->totalUsableArea
[head
].y2
, rect
.pos
.y
+ rect
.size
.height
);
1054 b_edge
= edge_b
+ resist
;
1056 if ((data
->bottomIndex
>= 0) && (data
->bottomIndex
<= data
->count
)) {
1059 for (i
= data
->bottomIndex
- 1; i
>= 0; i
--) {
1060 looprw
= data
->bottomList
[i
];
1061 if (!(data
->realX
> WRIGHT(looprw
)
1062 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1063 if (attract
|| ((data
->realY
< (WBOTTOM(looprw
) + 2)) && dy
< 0)) {
1064 t_edge
= WBOTTOM(looprw
) + 1;
1065 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1072 for (i
= data
->bottomIndex
; i
< data
->count
; i
++) {
1073 looprw
= data
->bottomList
[i
];
1074 if (!(data
->realX
> WRIGHT(looprw
)
1075 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1076 b_edge
= WBOTTOM(looprw
) + 1;
1077 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1084 if ((data
->topIndex
>= 0) && (data
->topIndex
<= data
->count
)) {
1087 for (i
= data
->topIndex
- 1; i
>= 0; i
--) {
1088 looprw
= data
->topList
[i
];
1089 if (!(data
->realX
> WRIGHT(looprw
)
1090 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1092 || (((data
->realY
+ data
->winHeight
) > (WTOP(looprw
) - 1))
1094 edge_b
= WTOP(looprw
);
1095 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1102 for (i
= data
->topIndex
; i
< data
->count
; i
++) {
1103 looprw
= data
->topList
[i
];
1104 if (!(data
->realX
> WRIGHT(looprw
)
1105 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1106 edge_t
= WTOP(looprw
);
1107 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1113 if ((winT
- t_edge
) < (b_edge
- winT
)) {
1115 if ((attract
&& winT
<= t_edge
+ resist
&& winT
>= t_edge
- resist
)
1116 || (dy
< 0 && winT
<= t_edge
&& winT
>= t_edge
- resist
)) {
1122 if (resist
> 0 && attract
&& winT
>= b_edge
- resist
&& winT
<= b_edge
+ resist
) {
1128 if ((winB
- edge_t
) < (edge_b
- winB
)) {
1129 if (resist
> 0 && attract
&& winB
<= edge_t
+ resist
&& winB
>= edge_t
- resist
) {
1130 newY
= edge_t
- data
->winHeight
;
1135 if ((attract
&& winB
>= edge_b
- resist
&& winB
<= edge_b
+ resist
)
1136 || (dy
> 0 && winB
>= edge_b
&& winB
<= edge_b
+ resist
)) {
1137 newY
= edge_b
- data
->winHeight
;
1147 /* update window position */
1151 if (((dx
> 0 && data
->calcX
- data
->realX
> 0)
1152 || (dx
< 0 && data
->calcX
- data
->realX
< 0)) && !hresist
)
1155 if (((dy
> 0 && data
->calcY
- data
->realY
> 0)
1156 || (dy
< 0 && data
->calcY
- data
->realY
< 0)) && !vresist
)
1159 if (data
->realX
!= newX
|| data
->realY
!= newY
) {
1161 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1162 showPosition(wwin
, data
->realX
, data
->realY
);
1165 doWindowMove(wwin
, scr
->selected_windows
, newX
- wwin
->frame_x
, newY
- wwin
->frame_y
);
1168 drawFrames(wwin
, scr
->selected_windows
,
1169 data
->realX
- wwin
->frame_x
, data
->realY
- wwin
->frame_y
);
1172 if (!scr
->selected_windows
&& wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
1174 moveGeometryDisplayCentered(scr
, newX
+ data
->winWidth
/ 2, newY
+ data
->winHeight
/ 2);
1179 drawFrames(wwin
, scr
->selected_windows
, newX
- wwin
->frame_x
, newY
- wwin
->frame_y
);
1182 if (!scr
->selected_windows
) {
1183 showPosition(wwin
, newX
, newY
);
1187 /* recalc relative window position */
1188 if (doResistance
&& (data
->realX
!= newX
|| data
->realY
!= newY
)) {
1189 updateResistance(wwin
, data
, newX
, newY
);
1196 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1198 #define MOVABLE_BIT 0x01
1199 #define RESIZABLE_BIT 0x02
1201 int wKeyboardMoveResizeWindow(WWindow
* wwin
)
1203 WScreen
*scr
= wwin
->screen_ptr
;
1204 Window root
= scr
->root_win
;
1206 int w
= wwin
->frame
->core
->width
;
1207 int h
= wwin
->frame
->core
->height
;
1208 int scr_width
= wwin
->screen_ptr
->scr_width
;
1209 int scr_height
= wwin
->screen_ptr
->scr_height
;
1210 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1211 int src_x
= wwin
->frame_x
;
1212 int src_y
= wwin
->frame_y
;
1215 int done
, off_x
, off_y
, ww
, wh
;
1217 int opaqueMoveResize
= wPreferences
.opaque_move_resize_keyboard
;
1219 KeyCode shiftl
, shiftr
, ctrlmode
;
1220 KeySym keysym
= NoSymbol
;
1222 int modes
= ((IS_MOVABLE(wwin
) ? MOVABLE_BIT
: 0) | (IS_RESIZABLE(wwin
) ? RESIZABLE_BIT
: 0));
1223 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1224 ? wGetHeadForWindow(wwin
)
1225 : scr
->xine_info
.primary_head
);
1227 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1228 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1229 ctrlmode
= done
= off_x
= off_y
= 0;
1231 if (modes
== RESIZABLE_BIT
) {
1237 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1239 if (!wwin
->flags
.selected
) {
1240 wUnselectWindows(scr
);
1243 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1244 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
1245 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
);
1249 if (!opaqueMoveResize
) {
1250 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1251 if (scr
->selected_windows
)
1252 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1254 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1256 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1259 if ((wwin
->flags
.shaded
|| scr
->selected_windows
) && (!scr
->selected_windows
)) {
1260 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1271 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1272 | ButtonPressMask
| ExposureMask
, &event
);
1273 if (event
.type
== Expose
) {
1274 WMHandleEvent(&event
);
1276 } while (event
.type
== Expose
);
1278 if (!opaqueMoveResize
) {
1279 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1280 if (scr
->selected_windows
)
1281 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1283 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1284 /*** I HATE EDGE RESISTANCE - ]d ***/
1286 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1291 showGeometry(wwin
, src_x
+ off_x
, src_y
+ off_y
, src_x
+ off_x
+ ww
, src_y
+ off_y
+ wh
,
1297 switch (event
.type
) {
1300 if (event
.xkey
.time
- lastTime
> 50) {
1301 kspeed
/= (1 + (event
.xkey
.time
- lastTime
) / 100);
1309 lastTime
= event
.xkey
.time
;
1310 if (modes
== (MOVABLE_BIT
| RESIZABLE_BIT
)) {
1311 if ((event
.xkey
.state
& ControlMask
) && !wwin
->flags
.shaded
) {
1313 wUnselectWindows(scr
);
1318 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
) {
1320 cycleGeometryDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
, 0);
1322 cyclePositionDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1325 keysym
= XLookupKeysym(&event
.xkey
, 0);
1382 if (moment
!= RIGHT
)
1394 wWindowConstrainSize(wwin
, (unsigned int *)&ww
, (unsigned int *)&wh
);
1397 if (wPreferences
.ws_cycle
) {
1398 if (src_x
+ off_x
+ ww
< 20) {
1399 if (!scr
->current_workspace
) {
1400 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
1402 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
1404 } else if (src_x
+ off_x
+ 20 > scr_width
) {
1405 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
1406 wWorkspaceChange(scr
, 0);
1408 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
1412 if (src_x
+ off_x
+ ww
< 20)
1413 off_x
= 20 - ww
- src_x
;
1414 else if (src_x
+ off_x
+ 20 > scr_width
)
1415 off_x
= scr_width
- 20 - src_x
;
1418 if (src_y
+ off_y
+ wh
< 20) {
1419 off_y
= 20 - wh
- src_y
;
1420 } else if (src_y
+ off_y
+ 20 > scr_height
) {
1421 off_y
= scr_height
- 20 - src_y
;
1430 WMHandleEvent(&event
);
1431 while (XCheckTypedEvent(dpy
, Expose
, &event
)) {
1432 WMHandleEvent(&event
);
1437 WMHandleEvent(&event
);
1444 if (wwin
->flags
.shaded
&& !scr
->selected_windows
) {
1445 moveGeometryDisplayCentered(scr
, src_x
+ off_x
+ w
/ 2, src_y
+ off_y
+ h
/ 2);
1448 WMUnmapWidget(scr
->gview
);
1449 mapGeometryDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1450 } else if (!scr
->selected_windows
) {
1451 WMUnmapWidget(scr
->gview
);
1452 mapPositionDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1456 if (!opaqueMoveResize
) {
1457 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1458 if (scr
->selected_windows
)
1459 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1461 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1463 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1468 showGeometry(wwin
, src_x
+ off_x
, src_y
+ off_y
, src_x
+ off_x
+ ww
, src_y
+ off_y
+ wh
,
1470 } else if (!scr
->selected_windows
)
1471 showPosition(wwin
, src_x
+ off_x
, src_y
+ off_y
);
1473 if (opaqueMoveResize
) {
1475 wWindowConfigure(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
- vert_border
);
1479 scr
->keymove_tick
= 0;
1481 WMDeleteTimerWithClientData(&looper);
1483 if (!opaqueMoveResize
) {/*ctrlmode=> resize */
1484 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1485 if (scr
->selected_windows
)
1486 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1488 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1490 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1495 showGeometry(wwin
, src_x
+ off_x
, src_y
+ off_y
, src_x
+ off_x
+ ww
,
1496 src_y
+ off_y
+ wh
, 0);
1497 WMUnmapWidget(scr
->gview
);
1499 WMUnmapWidget(scr
->gview
);
1501 XUngrabKeyboard(dpy
, CurrentTime
);
1502 XUngrabPointer(dpy
, CurrentTime
);
1506 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1507 if (!scr
->selected_windows
) {
1508 wWindowMove(wwin
, src_x
+ off_x
, src_y
+ off_y
);
1509 wWindowSynthConfigureNotify(wwin
);
1511 WMArrayIterator iter
;
1514 doWindowMove(wwin
, scr
->selected_windows
, off_x
, off_y
);
1516 WM_ITERATE_ARRAY(scr
->selected_windows
, foo
, iter
) {
1517 wWindowSynthConfigureNotify(foo
);
1521 if (ww
!= original_w
)
1522 wwin
->flags
.maximized
&= ~(MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
1524 if (wh
!= original_h
)
1525 wwin
->flags
.maximized
&= ~(MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
1527 wWindowConfigure(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
- vert_border
);
1528 wWindowSynthConfigureNotify(wwin
);
1530 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1531 wSetFocusTo(scr
, wwin
);
1534 if (wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 &&
1535 head
!= wGetHeadForWindow(wwin
)) {
1536 wArrangeIcons(scr
, True
);
1539 update_saved_geometry(wwin
);
1547 *----------------------------------------------------------------------
1548 * wMouseMoveWindow--
1549 * Move the named window and the other selected ones (if any),
1550 * interactively. Also shows the position of the window, if only one
1551 * window is being moved.
1552 * If the window is not on the selected window list, the selected
1553 * windows are deselected.
1554 * If shift is pressed during the operation, the position display
1555 * is changed to another type.
1558 * True if the window was moved, False otherwise.
1561 * The window(s) position is changed, and the client(s) are
1562 * notified about that.
1563 * The position display configuration may be changed.
1564 *----------------------------------------------------------------------
1566 int wMouseMoveWindow(WWindow
* wwin
, XEvent
* ev
)
1568 WScreen
*scr
= wwin
->screen_ptr
;
1570 Window root
= scr
->root_win
;
1571 KeyCode shiftl
, shiftr
;
1575 /* This needs not to change while moving, else bad things can happen */
1576 int opaqueMove
= wPreferences
.opaque_move
;
1578 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1579 ? wGetHeadForWindow(wwin
)
1580 : scr
->xine_info
.primary_head
);
1582 if (!IS_MOVABLE(wwin
))
1585 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1586 XSetWindowAttributes attr
;
1588 attr
.save_under
= True
;
1589 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
, CWSaveUnder
, &attr
);
1592 initMoveData(wwin
, &moveData
);
1594 moveData
.mouseX
= ev
->xmotion
.x_root
;
1595 moveData
.mouseY
= ev
->xmotion
.y_root
;
1597 if (!wwin
->flags
.selected
) {
1598 /* this window is not selected, unselect others and move only wwin */
1599 wUnselectWindows(scr
);
1601 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1602 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1608 /* XWarpPointer() doesn't seem to generate Motion events, so
1609 * we've got to simulate them */
1610 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1611 &event
.xmotion
.y_root
, &junk
, &junk
, (unsigned *)&junk
);
1613 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1614 | PointerMotionHintMask
1615 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
, &event
);
1617 if (event
.type
== MotionNotify
) {
1618 /* compress MotionNotify events */
1619 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1620 if (!checkMouseSamplingRate(&event
))
1624 switch (event
.type
) {
1626 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1627 && started
&& !scr
->selected_windows
) {
1630 drawFrames(wwin
, scr
->selected_windows
,
1631 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1634 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1635 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1638 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1639 moveData
.winWidth
, moveData
.winHeight
);
1641 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1643 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1647 drawFrames(wwin
, scr
->selected_windows
,
1648 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1651 WMHandleEvent(&event); this causes problems needs fixing */
1657 updateWindowPosition(wwin
, &moveData
,
1658 scr
->selected_windows
== NULL
1659 && wPreferences
.edge_resistance
> 0,
1660 opaqueMove
, event
.xmotion
.x_root
, event
.xmotion
.y_root
);
1662 if (!warped
&& !wPreferences
.no_autowrap
) {
1663 int oldWorkspace
= scr
->current_workspace
;
1665 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1666 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1670 drawFrames(wwin
, scr
->selected_windows
,
1671 moveData
.realX
- wwin
->frame_x
,
1672 moveData
.realY
- wwin
->frame_y
);
1674 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1675 if (scr
->current_workspace
!= oldWorkspace
1676 && wPreferences
.edge_resistance
> 0
1677 && scr
->selected_windows
== NULL
)
1678 updateMoveData(wwin
, &moveData
);
1682 drawFrames(wwin
, scr
->selected_windows
,
1683 moveData
.realX
- wwin
->frame_x
,
1684 moveData
.realY
- wwin
->frame_y
);
1686 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1688 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1694 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1695 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1697 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1698 | ButtonReleaseMask
| ButtonPressMask
,
1699 wCursor
[WCUR_MOVE
], CurrentTime
);
1701 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1703 if (!scr
->selected_windows
)
1704 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1705 moveData
.winWidth
, moveData
.winHeight
);
1707 if (started
&& !opaqueMove
)
1708 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1710 if (!opaqueMove
|| (wPreferences
.move_display
== WDIS_NEW
1711 && !scr
->selected_windows
)) {
1713 if (wPreferences
.move_display
== WDIS_NEW
)
1714 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1723 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1729 drawFrames(wwin
, scr
->selected_windows
,
1730 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1732 doWindowMove(wwin
, scr
->selected_windows
,
1733 moveData
.realX
- wwin
->frame_x
,
1734 moveData
.realY
- wwin
->frame_y
);
1736 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1737 wWindowSynthConfigureNotify(wwin
);
1739 XUngrabKeyboard(dpy
, CurrentTime
);
1742 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1743 wSetFocusTo(scr
, wwin
);
1745 if (wPreferences
.move_display
== WDIS_NEW
)
1746 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1748 /* discard all enter/leave events that happened until
1749 * the time the button was released */
1750 while (XCheckTypedEvent(dpy
, EnterNotify
, &e
)) {
1751 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1752 XPutBackEvent(dpy
, &e
);
1756 while (XCheckTypedEvent(dpy
, LeaveNotify
, &e
)) {
1757 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1758 XPutBackEvent(dpy
, &e
);
1763 if (!scr
->selected_windows
) {
1764 /* get rid of the geometry window */
1765 WMUnmapWidget(scr
->gview
);
1772 if (started
&& !opaqueMove
) {
1773 drawFrames(wwin
, scr
->selected_windows
,
1774 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1776 WMHandleEvent(&event
);
1779 drawFrames(wwin
, scr
->selected_windows
,
1780 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1782 WMHandleEvent(&event
);
1788 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1789 XSetWindowAttributes attr
;
1791 attr
.save_under
= False
;
1792 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
, CWSaveUnder
, &attr
);
1796 freeMoveData(&moveData
);
1798 if (started
&& wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 &&
1799 head
!= wGetHeadForWindow(wwin
)) {
1800 wArrangeIcons(scr
, True
);
1804 update_saved_geometry(wwin
);
1810 #define HCONSTRAIN 2
1812 static int getResizeDirection(WWindow
* wwin
, int x
, int y
, int dx
, int dy
, int flags
)
1814 int w
= wwin
->frame
->core
->width
- 1;
1815 int cw
= wwin
->frame
->resizebar_corner_width
;
1818 /* if not resizing through the resizebar */
1819 if (!(flags
& RESIZEBAR
)) {
1820 int xdir
= (abs(x
) < (wwin
->client
.width
/ 2)) ? LEFT
: RIGHT
;
1821 int ydir
= (abs(y
) < (wwin
->client
.height
/ 2)) ? UP
: DOWN
;
1822 if (abs(dx
) < 2 || abs(dy
) < 2) {
1823 if (abs(dy
) > abs(dx
))
1828 return (xdir
| ydir
);
1831 /* window is too narrow. allow diagonal resize */
1835 if (flags
& HCONSTRAIN
)
1840 return (LEFT
| ydir
);
1842 return (RIGHT
| ydir
);
1844 /* vertical resize */
1845 if ((x
> cw
) && (x
< w
- cw
))
1853 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1859 void wMouseResizeWindow(WWindow
* wwin
, XEvent
* ev
)
1862 WScreen
*scr
= wwin
->screen_ptr
;
1863 Window root
= scr
->root_win
;
1864 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1865 int fw
= wwin
->frame
->core
->width
;
1866 int fh
= wwin
->frame
->core
->height
;
1867 int fx
= wwin
->frame_x
;
1868 int fy
= wwin
->frame_y
;
1869 int is_resizebar
= (wwin
->frame
->resizebar
&& ev
->xany
.window
== wwin
->frame
->resizebar
->window
);
1873 int rw
= fw
, rh
= fh
;
1874 int rx1
, ry1
, rx2
, ry2
;
1876 KeyCode shiftl
, shiftr
;
1881 int original_fw
= fw
;
1882 int original_fh
= fh
;
1883 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1884 ? wGetHeadForWindow(wwin
)
1885 : scr
->xine_info
.primary_head
);
1886 int opaqueResize
= wPreferences
.opaque_resize
;
1888 if (!IS_RESIZABLE(wwin
))
1891 if (wwin
->flags
.shaded
) {
1892 wwarning("internal error: tryein");
1895 orig_x
= ev
->xbutton
.x_root
;
1896 orig_y
= ev
->xbutton
.y_root
;
1899 wUnselectWindows(scr
);
1904 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1905 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1908 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1909 | ButtonReleaseMask
| PointerMotionHintMask
| ButtonPressMask
| ExposureMask
, &event
);
1910 if (!checkMouseSamplingRate(&event
))
1913 switch (event
.type
) {
1915 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1916 if (!opaqueResize
) {
1917 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1919 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1920 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
1921 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1924 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1929 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1940 dw
= orig_x
- event
.xmotion
.x_root
;
1941 else if (res
& RIGHT
)
1942 dw
= event
.xmotion
.x_root
- orig_x
;
1944 dh
= orig_y
- event
.xmotion
.y_root
;
1945 else if (res
& DOWN
)
1946 dh
= event
.xmotion
.y_root
- orig_y
;
1948 orig_x
= event
.xmotion
.x_root
;
1949 orig_y
= event
.xmotion
.y_root
;
1954 fh
= rh
- vert_border
;
1955 wWindowConstrainSize(wwin
, (unsigned int *)&fw
, (unsigned int *)&fh
);
1959 else if (res
& RIGHT
)
1963 else if (res
& DOWN
)
1965 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1966 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1971 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
1972 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
1974 /* check if resizing through resizebar */
1980 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
1981 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
1982 flags
|= HCONSTRAIN
;
1984 res
= getResizeDirection(wwin
, tx
, ty
,
1985 orig_x
- event
.xmotion
.x_root
,
1986 orig_y
- event
.xmotion
.y_root
, flags
);
1988 if (res
== (UP
| LEFT
))
1989 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1990 | ButtonReleaseMask
| ButtonPressMask
,
1991 wCursor
[WCUR_TOPLEFTRESIZE
], CurrentTime
);
1992 else if (res
== (UP
| RIGHT
))
1993 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1994 | ButtonReleaseMask
| ButtonPressMask
,
1995 wCursor
[WCUR_TOPRIGHTRESIZE
], CurrentTime
);
1996 else if (res
== (DOWN
| LEFT
))
1997 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1998 | ButtonReleaseMask
| ButtonPressMask
,
1999 wCursor
[WCUR_BOTTOMLEFTRESIZE
], CurrentTime
);
2000 else if (res
== (DOWN
| RIGHT
))
2001 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2002 | ButtonReleaseMask
| ButtonPressMask
,
2003 wCursor
[WCUR_BOTTOMRIGHTRESIZE
], CurrentTime
);
2004 else if (res
== DOWN
|| res
== UP
)
2005 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2006 | ButtonReleaseMask
| ButtonPressMask
,
2007 wCursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2008 else if (res
& (DOWN
| UP
))
2009 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2010 | ButtonReleaseMask
| ButtonPressMask
,
2011 wCursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2012 else if (res
& (LEFT
| RIGHT
))
2013 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2014 | ButtonReleaseMask
| ButtonPressMask
,
2015 wCursor
[WCUR_HORIZONRESIZE
], CurrentTime
);
2017 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2021 /* Draw the resize frame for the first time. */
2022 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
2025 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2027 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2033 drawTransparentFrame(wwin
, orig_fx
, orig_fy
, orig_fw
, orig_fh
);
2035 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
)
2036 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
2039 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2041 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
2042 if (wPreferences
.size_display
== WDIS_NEW
)
2043 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
2044 orig_fy
+ orig_fh
, res
);
2046 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2050 /* Fist clean the geometry line */
2051 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2052 /* Now, continue drawing */
2054 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
2055 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
2056 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2065 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2069 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2072 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2074 XUngrabKeyboard(dpy
, CurrentTime
);
2075 WMUnmapWidget(scr
->gview
);
2078 if (fw
!= original_fw
)
2079 wwin
->flags
.maximized
&= ~(MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
2081 if (fh
!= original_fh
)
2082 wwin
->flags
.maximized
&= ~(MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
2084 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
2085 wWindowSynthConfigureNotify(wwin
);
2090 WMHandleEvent(&event
);
2094 if (wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 && head
!= wGetHeadForWindow(wwin
))
2095 wArrangeIcons(scr
, True
);
2107 void wUnselectWindows(WScreen
* scr
)
2111 if (!scr
->selected_windows
)
2114 while (WMGetArrayItemCount(scr
->selected_windows
)) {
2115 wwin
= WMGetFromArray(scr
->selected_windows
, 0);
2116 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
2117 wIconSelect(wwin
->icon
);
2119 wSelectWindow(wwin
, False
);
2121 WMFreeArray(scr
->selected_windows
);
2122 scr
->selected_windows
= NULL
;
2125 static void selectWindowsInside(WScreen
* scr
, int x1
, int y1
, int x2
, int y2
)
2129 /* select the windows and put them in the selected window list */
2130 tmpw
= scr
->focused_window
;
2131 while (tmpw
!= NULL
) {
2132 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
2133 if ((tmpw
->frame
->workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(tmpw
))
2134 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
2135 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
2136 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
2137 wSelectWindow(tmpw
, True
);
2144 void wSelectWindows(WScreen
* scr
, XEvent
* ev
)
2147 Window root
= scr
->root_win
;
2148 GC gc
= scr
->frame_gc
;
2149 int xp
= ev
->xbutton
.x_root
;
2150 int yp
= ev
->xbutton
.y_root
;
2154 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
2155 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
2156 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2161 wUnselectWindows(scr
);
2163 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
2165 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
| ButtonPressMask
, &event
);
2167 switch (event
.type
) {
2169 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2170 x
= event
.xmotion
.x_root
;
2177 y
= event
.xmotion
.y_root
;
2184 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2191 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2194 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2196 XUngrabPointer(dpy
, CurrentTime
);
2197 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
2201 WMHandleEvent(&event
);
2207 void InteractivePlaceWindow(WWindow
* wwin
, int *x_ret
, int *y_ret
, unsigned width
, unsigned height
)
2209 WScreen
*scr
= wwin
->screen_ptr
;
2210 Window root
= scr
->root_win
;
2213 KeyCode shiftl
, shiftr
;
2217 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2218 GrabModeAsync
, GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2223 if (HAS_TITLEBAR(wwin
)) {
2224 h
= WMFontHeight(scr
->title_font
) + (wPreferences
.window_title_clearance
+
2225 TITLEBAR_EXTEND_SPACE
) * 2;
2227 if (h
> wPreferences
.window_title_max_height
)
2228 h
= wPreferences
.window_title_max_height
;
2230 if (h
< wPreferences
.window_title_min_height
)
2231 h
= wPreferences
.window_title_min_height
;
2235 if (HAS_RESIZEBAR(wwin
)) {
2236 height
+= RESIZEBAR_HEIGHT
;
2238 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2239 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
, (unsigned *)&junk
);
2240 mapPositionDisplay(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2242 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2244 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2245 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2247 WMMaskEvent(dpy
, PointerMotionMask
| ButtonPressMask
| ExposureMask
| KeyPressMask
, &event
);
2249 if (!checkMouseSamplingRate(&event
))
2252 switch (event
.type
) {
2254 if ((event
.xkey
.keycode
== shiftl
)
2255 || (event
.xkey
.keycode
== shiftr
)) {
2256 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2257 cyclePositionDisplay(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2258 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2263 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2265 x
= event
.xmotion
.x_root
;
2266 y
= event
.xmotion
.y_root
;
2268 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2269 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2271 showPosition(wwin
, x
- width
/ 2, y
- h
/ 2);
2273 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2278 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2280 *x_ret
= x
- width
/ 2;
2282 XUngrabPointer(dpy
, CurrentTime
);
2283 XUngrabKeyboard(dpy
, CurrentTime
);
2284 /* get rid of the geometry window */
2285 WMUnmapWidget(scr
->gview
);
2289 WMHandleEvent(&event
);