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
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25 #include <X11/Xutil.h>
26 #include <X11/keysym.h>
32 #include "WindowMaker.h"
41 #include "workspace.h"
47 #include <WINGs/WINGsP.h>
50 /* How many different types of geometry/position
51 display thingies are there? */
52 #define NUM_DISPLAYS 5
56 #define HORIZONTAL (LEFT|RIGHT)
59 #define VERTICAL (UP|DOWN)
62 /* True if window currently has a border. This also includes borderless
63 * windows which are currently selected
65 #define HAS_BORDER_WITH_SELECT(w) ((w)->flags.selected || HAS_BORDER(w))
68 /****** Global Variables ******/
69 extern Time LastTimestamp
;
71 extern Cursor wCursor
[WCUR_LAST
];
73 extern WPreferences wPreferences
;
75 extern Atom _XA_WM_PROTOCOLS
;
80 *----------------------------------------------------------------------
81 * checkMouseSamplingRate-
82 * For lowering the mouse motion sampling rate for machines where
83 * it's too high (SGIs). If it returns False then the event should be
85 *----------------------------------------------------------------------
88 checkMouseSamplingRate(XEvent
*ev
)
90 static Time previousMotion
= 0;
92 if (ev
->type
== MotionNotify
) {
93 if (ev
->xmotion
.time
- previousMotion
< DELAY_BETWEEN_MOUSE_SAMPLING
) {
96 previousMotion
= ev
->xmotion
.time
;
105 *----------------------------------------------------------------------
106 * moveGeometryDisplayCentered
108 * routine that moves the geometry/position window on scr so it is
109 * centered over the given coordinates (x,y). Also the window position
110 * is clamped so it stays on the screen at all times.
111 *----------------------------------------------------------------------
114 moveGeometryDisplayCentered(WScreen
*scr
, int x
, int y
)
116 unsigned int w
= WMWidgetWidth(scr
->gview
);
117 unsigned int h
= WMWidgetHeight(scr
->gview
);
118 int x1
= 0, y1
= 0, x2
= scr
->scr_width
, y2
= scr
->scr_height
;
123 /* dead area check */
124 if (scr
->xine_info
.count
) {
131 rect
.size
.height
= h
;
133 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
135 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
136 rect
= wGetRectForHead(scr
, head
);
139 x2
= x1
+ rect
.size
.width
;
140 y2
= y1
+ rect
.size
.height
;
146 else if (x
> (x2
- w
))
151 else if (y
> (y2
- h
))
155 WMMoveWidget(scr
->gview
, x
, y
);
160 showPosition(WWindow
*wwin
, int x
, int y
)
162 WScreen
*scr
= wwin
->screen_ptr
;
164 if (wPreferences
.move_display
== WDIS_NEW
) {
166 int width
= wwin
->frame
->core
->width
;
167 int height
= wwin
->frame
->core
->height
;
169 GC lgc
= scr
->line_gc
;
170 XSetForeground(dpy
, lgc
, scr
->line_pixel
);
171 sprintf(num
, "%i", x
);
173 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
-1, scr
->scr_width
, y
-1);
174 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
+height
+2, scr
->scr_width
,
176 XDrawLine(dpy
, scr
->root_win
, lgc
, x
-1, 0, x
-1, scr
->scr_height
);
177 XDrawLine(dpy
, scr
->root_win
, lgc
, x
+width
+2, 0, x
+width
+2,
181 #ifdef VIRTUAL_DESKTOP
182 WSetGeometryViewShownPosition(scr
->gview
,
183 x
+ scr
->workspaces
[scr
->current_workspace
]->view_x
,
184 y
+ scr
->workspaces
[scr
->current_workspace
]->view_y
);
186 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
193 cyclePositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
195 WScreen
*scr
= wwin
->screen_ptr
;
198 wPreferences
.move_display
++;
199 wPreferences
.move_display
%= NUM_DISPLAYS
;
201 if (wPreferences
.move_display
== WDIS_NEW
) {
202 wPreferences
.move_display
++;
203 wPreferences
.move_display
%= NUM_DISPLAYS
;
206 if (wPreferences
.move_display
== WDIS_NONE
) {
207 WMUnmapWidget(scr
->gview
);
209 if (wPreferences
.move_display
== WDIS_CENTER
) {
210 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
211 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/2,
212 rect
.pos
.y
+ rect
.size
.height
/2);
213 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
214 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
215 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
216 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
217 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
219 WMMapWidget(scr
->gview
);
225 mapPositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
227 WScreen
*scr
= wwin
->screen_ptr
;
230 if (wPreferences
.move_display
== WDIS_NEW
231 || wPreferences
.move_display
== WDIS_NONE
) {
233 } else if (wPreferences
.move_display
== WDIS_CENTER
) {
234 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
235 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/2,
236 rect
.pos
.y
+ rect
.size
.height
/2);
237 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
238 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
239 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
240 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
241 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
243 WMMapWidget(scr
->gview
);
244 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
249 showGeometry(WWindow
*wwin
, int x1
, int y1
, int x2
, int y2
, int direction
)
251 WScreen
*scr
= wwin
->screen_ptr
;
252 Window root
= scr
->root_win
;
253 GC gc
= scr
->line_gc
;
254 int ty
, by
, my
, x
, y
, mx
, s
;
259 /* This seems necessary for some odd reason (too lazy to write x1-1 and
260 * x2-1 everywhere below in the code). But why only for x? */
263 if (HAS_BORDER_WITH_SELECT(wwin
)) {
264 x1
+= FRAME_BORDER_WIDTH
;
265 x2
+= FRAME_BORDER_WIDTH
;
266 y1
+= FRAME_BORDER_WIDTH
;
267 y2
+= FRAME_BORDER_WIDTH
;
270 ty
= y1
+ wwin
->frame
->top_width
;
271 by
= y2
- wwin
->frame
->bottom_width
;
273 if (wPreferences
.size_display
== WDIS_NEW
) {
274 fw
= XTextWidth(scr
->tech_draw_font
, "8888", 4);
275 fh
= scr
->tech_draw_font
->ascent
+scr
->tech_draw_font
->descent
;
277 XSetForeground(dpy
, gc
, scr
->line_pixel
);
279 /* vertical geometry */
280 if (((direction
& LEFT
) && (x2
< scr
->scr_width
- fw
)) || (x1
< fw
)) {
289 /* top arrow & end bar */
290 segment
[0].x1
= x
- (s
+ 6); segment
[0].y1
= ty
;
291 segment
[0].x2
= x
- (s
- 10); segment
[0].y2
= ty
;
294 segment
[1].x1
= x
- (s
- 2); segment
[1].y1
= ty
+ 1;
295 segment
[1].x2
= x
- (s
- 5); segment
[1].y2
= ty
+ 7;
297 segment
[2].x1
= x
- (s
- 2); segment
[2].y1
= ty
+ 1;
298 segment
[2].x2
= x
- (s
+ 1); segment
[2].y2
= ty
+ 7;
301 segment
[3].x1
= x
- (s
- 2); segment
[3].y1
= ty
+ 1;
302 segment
[3].x2
= x
- (s
- 2); segment
[3].y2
= my
- fh
/2 - 1;
304 XDrawSegments(dpy
, root
, gc
, segment
, 4);
306 /* bottom arrow & end bar */
311 segment
[1].y1
= by
- 1;
312 segment
[1].y2
= by
- 7;
314 segment
[2].y1
= by
- 1;
315 segment
[2].y2
= by
- 7;
318 segment
[3].y1
= my
+ fh
/2 + 2;
319 segment
[3].y2
= by
- 1;
321 XDrawSegments(dpy
, root
, gc
, segment
, 4);
323 snprintf(num
, sizeof(num
), "%i", (by
- ty
- wwin
->normal_hints
->base_height
) /
324 wwin
->normal_hints
->height_inc
);
325 fw
= XTextWidth(scr
->tech_draw_font
, num
, strlen(num
));
327 /* Display the height. */
328 XSetFont(dpy
, gc
, scr
->tech_draw_font
->fid
);
329 XDrawString(dpy
, root
, gc
, x
- s
+ 3 - fw
/2, my
+ scr
->tech_draw_font
->ascent
- fh
/2 + 1, num
, strlen(num
));
331 /* horizontal geometry */
339 mx
= x1
+ (x2
- x1
)/2;
340 snprintf(num
, sizeof(num
), "%i", (x2
- x1
- wwin
->normal_hints
->base_width
) /
341 wwin
->normal_hints
->width_inc
);
342 fw
= XTextWidth(scr
->tech_draw_font
, num
, strlen(num
));
344 /* left arrow & end bar */
345 segment
[0].x1
= x1
; segment
[0].y1
= y
- (s
+ 6);
346 segment
[0].x2
= x1
; segment
[0].y2
= y
- (s
- 10);
349 segment
[1].x1
= x1
+ 7; segment
[1].y1
= y
- (s
+ 1);
350 segment
[1].x2
= x1
+ 1; segment
[1].y2
= y
- (s
- 2);
352 segment
[2].x1
= x1
+ 1; segment
[2].y1
= y
- (s
- 2);
353 segment
[2].x2
= x1
+ 7; segment
[2].y2
= y
- (s
- 5);
356 segment
[3].x1
= x1
+ 1; segment
[3].y1
= y
- (s
- 2);
357 segment
[3].x2
= mx
- fw
/2 - 2; segment
[3].y2
= y
- (s
- 2);
359 XDrawSegments(dpy
, root
, gc
, segment
, 4);
361 /* right arrow & end bar */
362 segment
[0].x1
= x2
+ 1;
363 segment
[0].x2
= x2
+ 1;
366 segment
[1].x1
= x2
- 6;
370 segment
[2].x2
= x2
- 6;
373 segment
[3].x1
= mx
+ fw
/2 + 2;
376 XDrawSegments(dpy
, root
, gc
, segment
, 4);
378 /* Display the width. */
379 XDrawString(dpy
, root
, gc
, mx
- fw
/2 + 1, y
- s
+ scr
->tech_draw_font
->ascent
- fh
/2 + 1, num
, strlen(num
));
381 WSetGeometryViewShownSize(scr
->gview
,
382 (x2
- x1
- wwin
->normal_hints
->base_width
)
383 / wwin
->normal_hints
->width_inc
,
384 (by
- ty
- wwin
->normal_hints
->base_height
)
385 / wwin
->normal_hints
->height_inc
);
391 cycleGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
, int dir
)
393 WScreen
*scr
= wwin
->screen_ptr
;
396 wPreferences
.size_display
++;
397 wPreferences
.size_display
%= NUM_DISPLAYS
;
399 if (wPreferences
.size_display
== WDIS_NEW
400 || wPreferences
.size_display
== WDIS_NONE
) {
401 WMUnmapWidget(scr
->gview
);
403 if (wPreferences
.size_display
== WDIS_CENTER
) {
404 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
405 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/2,
406 rect
.pos
.y
+ rect
.size
.height
/2);
407 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
408 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
409 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
410 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
411 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
413 WMMapWidget(scr
->gview
);
414 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, dir
);
420 mapGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
422 WScreen
*scr
= wwin
->screen_ptr
;
425 if (wPreferences
.size_display
== WDIS_NEW
426 || wPreferences
.size_display
== WDIS_NONE
)
429 if (wPreferences
.size_display
== WDIS_CENTER
) {
430 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
431 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/2,
432 rect
.pos
.y
+ rect
.size
.height
/2);
433 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
434 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
435 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
436 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
437 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
439 WMMapWidget(scr
->gview
);
440 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, 0);
446 doWindowMove(WWindow
*wwin
, WMArray
*array
, int dx
, int dy
)
449 WScreen
*scr
= wwin
->screen_ptr
;
452 if (!array
|| !WMGetArrayItemCount(array
)) {
453 wWindowMove(wwin
, wwin
->frame_x
+ dx
, wwin
->frame_y
+ dy
);
455 WMArrayIterator iter
;
457 WM_ITERATE_ARRAY(array
, tmpw
, iter
) {
458 x
= tmpw
->frame_x
+ dx
;
459 y
= tmpw
->frame_y
+ dy
;
461 #if 1 /* XXX: with xinerama patch was #if 0, check this */
462 /* don't let windows become unreachable */
464 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
465 x
= 20 - (int)tmpw
->frame
->core
->width
;
466 else if (x
+ 20 > scr
->scr_width
)
467 x
= scr
->scr_width
- 20;
469 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
470 y
= 20 - (int)tmpw
->frame
->core
->height
;
471 else if (y
+ 20 > scr
->scr_height
)
472 y
= scr
->scr_height
- 20;
474 wScreenBringInside(scr
, &x
, &y
,
475 (int)tmpw
->frame
->core
->width
,
476 (int)tmpw
->frame
->core
->height
);
479 wWindowMove(tmpw
, x
, y
);
486 drawTransparentFrame(WWindow
*wwin
, int x
, int y
, int width
, int height
)
488 Window root
= wwin
->screen_ptr
->root_win
;
489 GC gc
= wwin
->screen_ptr
->frame_gc
;
493 if (HAS_BORDER_WITH_SELECT(wwin
)) {
494 x
+= FRAME_BORDER_WIDTH
;
495 y
+= FRAME_BORDER_WIDTH
;
498 if (HAS_TITLEBAR(wwin
) && !wwin
->flags
.shaded
) {
499 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + (wPreferences
.window_title_clearance
+ TITLEBAR_EXTEND_SPACE
) * 2;
501 if (HAS_RESIZEBAR(wwin
) && !wwin
->flags
.shaded
) {
502 /* Can't use wwin-frame->bottom_width because, in some cases
503 (e.g. interactive placement), frame does not point to anything. */
504 bottom
= RESIZEBAR_HEIGHT
;
506 XDrawRectangle(dpy
, root
, gc
, x
- 1, y
- 1, width
+ 1, height
+ 1);
509 XDrawLine(dpy
, root
, gc
, x
, y
+ h
- 1, x
+ width
, y
+ h
- 1);
512 XDrawLine(dpy
, root
, gc
, x
, y
+ height
- bottom
,
513 x
+ width
, y
+ height
- bottom
);
519 drawFrames(WWindow
*wwin
, WMArray
*array
, int dx
, int dy
)
522 int scr_width
= wwin
->screen_ptr
->scr_width
;
523 int scr_height
= wwin
->screen_ptr
->scr_height
;
528 x
= wwin
->frame_x
+ dx
;
529 y
= wwin
->frame_y
+ dy
;
531 drawTransparentFrame(wwin
, x
, y
,
532 wwin
->frame
->core
->width
,
533 wwin
->frame
->core
->height
);
536 WMArrayIterator iter
;
538 WM_ITERATE_ARRAY(array
, tmpw
, iter
) {
539 x
= tmpw
->frame_x
+ dx
;
540 y
= tmpw
->frame_y
+ dy
;
542 /* don't let windows become unreachable */
543 #if 1 /* XXX: was 0 in XINERAMA patch, check */
544 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
545 x
= 20 - (int)tmpw
->frame
->core
->width
;
546 else if (x
+ 20 > scr_width
)
549 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
550 y
= 20 - (int)tmpw
->frame
->core
->height
;
551 else if (y
+ 20 > scr_height
)
555 wScreenBringInside(wwin
->screen_ptr
, &x
, &y
,
556 (int)tmpw
->frame
->core
->width
,
557 (int)tmpw
->frame
->core
->height
);
560 drawTransparentFrame(tmpw
, x
, y
, tmpw
->frame
->core
->width
,
561 tmpw
->frame
->core
->height
);
574 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &ev
)) ;
579 crossWorkspace(WScreen
*scr
, WWindow
*wwin
, int opaque_move
,
580 int new_workspace
, int rewind
)
582 /* do not let window be unmapped */
584 wwin
->flags
.changing_workspace
= 1;
585 wWindowChangeWorkspace(wwin
, new_workspace
);
587 /* go to new workspace */
588 wWorkspaceChange(scr
, new_workspace
);
590 wwin
->flags
.changing_workspace
= 0;
593 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, scr
->scr_width
- 20, 0);
595 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, -(scr
->scr_width
- 20), 0);
600 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
601 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
602 GrabModeAsync
, None
, wCursor
[WCUR_MOVE
], CurrentTime
);
610 /* arrays of WWindows sorted by the respective border position */
611 WWindow
**topList
; /* top border */
612 WWindow
**leftList
; /* left border */
613 WWindow
**rightList
; /* right border */
614 WWindow
**bottomList
; /* bottom border */
617 /* index of window in the above lists indicating the relative position
618 * of the window with the others */
624 int rubCount
; /* for workspace switching */
626 int winWidth
, winHeight
; /* width/height of the window */
627 int realX
, realY
; /* actual position of the window */
628 int calcX
, calcY
; /* calculated position of window */
629 int omouseX
, omouseY
; /* old mouse position */
630 int mouseX
, mouseY
; /* last known position of the pointer */
633 #define WTOP(w) (w)->frame_y
634 #define WLEFT(w) (w)->frame_x
635 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width - 1 + \
636 (HAS_BORDER_WITH_SELECT(w) ? 2*FRAME_BORDER_WIDTH : 0))
637 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height - 1 + \
638 (HAS_BORDER_WITH_SELECT(w) ? 2*FRAME_BORDER_WIDTH : 0))
641 compareWTop(const void *a
, const void *b
)
643 WWindow
*wwin1
= *(WWindow
**)a
;
644 WWindow
*wwin2
= *(WWindow
**)b
;
646 if (WTOP(wwin1
) > WTOP(wwin2
))
648 else if (WTOP(wwin1
) < WTOP(wwin2
))
656 compareWLeft(const void *a
, const void *b
)
658 WWindow
*wwin1
= *(WWindow
**)a
;
659 WWindow
*wwin2
= *(WWindow
**)b
;
661 if (WLEFT(wwin1
) > WLEFT(wwin2
))
663 else if (WLEFT(wwin1
) < WLEFT(wwin2
))
671 compareWRight(const void *a
, const void *b
)
673 WWindow
*wwin1
= *(WWindow
**)a
;
674 WWindow
*wwin2
= *(WWindow
**)b
;
676 if (WRIGHT(wwin1
) < WRIGHT(wwin2
))
678 else if (WRIGHT(wwin1
) > WRIGHT(wwin2
))
687 compareWBottom(const void *a
, const void *b
)
689 WWindow
*wwin1
= *(WWindow
**)a
;
690 WWindow
*wwin2
= *(WWindow
**)b
;
692 if (WBOTTOM(wwin1
) < WBOTTOM(wwin2
))
694 else if (WBOTTOM(wwin1
) > WBOTTOM(wwin2
))
702 updateResistance(WWindow
*wwin
, MoveData
*data
, int newX
, int newY
)
705 int newX2
= newX
+ data
->winWidth
;
706 int newY2
= newY
+ data
->winHeight
;
709 if (newX
< data
->realX
) {
710 if (data
->rightIndex
> 0
711 && newX
< WRIGHT(data
->rightList
[data
->rightIndex
-1])) {
713 } else if (data
->leftIndex
<= data
->count
-1
714 && newX2
<= WLEFT(data
->leftList
[data
->leftIndex
])) {
717 } else if (newX
> data
->realX
) {
718 if (data
->leftIndex
> 0
719 && newX2
> WLEFT(data
->leftList
[data
->leftIndex
-1])) {
721 } else if (data
->rightIndex
<= data
->count
-1
722 && newX
>= WRIGHT(data
->rightList
[data
->rightIndex
])) {
728 if (newY
< data
->realY
) {
729 if (data
->bottomIndex
> 0
730 && newY
< WBOTTOM(data
->bottomList
[data
->bottomIndex
-1])) {
732 } else if (data
->topIndex
<= data
->count
-1
733 && newY2
<= WTOP(data
->topList
[data
->topIndex
])) {
736 } else if (newY
> data
->realY
) {
737 if (data
->topIndex
> 0
738 && newY2
> WTOP(data
->topList
[data
->topIndex
-1])) {
740 } else if (data
->bottomIndex
<= data
->count
-1
741 && newY
>= WBOTTOM(data
->bottomList
[data
->bottomIndex
])) {
750 /* TODO: optimize this */
751 if (data
->realY
< WBOTTOM(data
->bottomList
[0])) {
752 data
->bottomIndex
= 0;
754 if (data
->realX
< WRIGHT(data
->rightList
[0])) {
755 data
->rightIndex
= 0;
757 if ((data
->realX
+ data
->winWidth
) > WLEFT(data
->leftList
[0])) {
760 if ((data
->realY
+ data
->winHeight
) > WTOP(data
->topList
[0])) {
763 for (i
= 0; i
< data
->count
; i
++) {
764 if (data
->realY
> WBOTTOM(data
->bottomList
[i
])) {
765 data
->bottomIndex
= i
+ 1;
767 if (data
->realX
> WRIGHT(data
->rightList
[i
])) {
768 data
->rightIndex
= i
+ 1;
770 if ((data
->realX
+ data
->winWidth
) < WLEFT(data
->leftList
[i
])) {
771 data
->leftIndex
= i
+ 1;
773 if ((data
->realY
+ data
->winHeight
) < WTOP(data
->topList
[i
])) {
774 data
->topIndex
= i
+ 1;
781 freeMoveData(MoveData
*data
)
784 wfree(data
->topList
);
786 wfree(data
->leftList
);
788 wfree(data
->rightList
);
789 if (data
->bottomList
)
790 wfree(data
->bottomList
);
795 updateMoveData(WWindow
*wwin
, MoveData
*data
)
797 WScreen
*scr
= wwin
->screen_ptr
;
802 tmp
= scr
->focused_window
;
804 if (tmp
!= wwin
&& scr
->current_workspace
== tmp
->frame
->workspace
805 && !tmp
->flags
.miniaturized
806 && !tmp
->flags
.hidden
807 && !tmp
->flags
.obscured
808 && !WFLAGP(tmp
, sunken
)) {
809 data
->topList
[data
->count
] = tmp
;
810 data
->leftList
[data
->count
] = tmp
;
811 data
->rightList
[data
->count
] = tmp
;
812 data
->bottomList
[data
->count
] = tmp
;
818 if (data
->count
== 0) {
821 data
->rightIndex
= 0;
822 data
->bottomIndex
= 0;
826 /* order from closest to the border of the screen to farthest */
828 qsort(data
->topList
, data
->count
, sizeof(WWindow
**), compareWTop
);
829 qsort(data
->leftList
, data
->count
, sizeof(WWindow
**), compareWLeft
);
830 qsort(data
->rightList
, data
->count
, sizeof(WWindow
**), compareWRight
);
831 qsort(data
->bottomList
, data
->count
, sizeof(WWindow
**), compareWBottom
);
833 /* figure the position of the window relative to the others */
836 data
->leftIndex
= -1;
837 data
->rightIndex
= -1;
838 data
->bottomIndex
= -1;
840 if (WTOP(wwin
) < WBOTTOM(data
->bottomList
[0])) {
841 data
->bottomIndex
= 0;
843 if (WLEFT(wwin
) < WRIGHT(data
->rightList
[0])) {
844 data
->rightIndex
= 0;
846 if (WRIGHT(wwin
) > WLEFT(data
->leftList
[0])) {
849 if (WBOTTOM(wwin
) > WTOP(data
->topList
[0])) {
852 for (i
= 0; i
< data
->count
; i
++) {
853 if (WTOP(wwin
) >= WBOTTOM(data
->bottomList
[i
])) {
854 data
->bottomIndex
= i
+ 1;
856 if (WLEFT(wwin
) >= WRIGHT(data
->rightList
[i
])) {
857 data
->rightIndex
= i
+ 1;
859 if (WRIGHT(wwin
) <= WLEFT(data
->leftList
[i
])) {
860 data
->leftIndex
= i
+ 1;
862 if (WBOTTOM(wwin
) <= WTOP(data
->topList
[i
])) {
863 data
->topIndex
= i
+ 1;
870 initMoveData(WWindow
*wwin
, MoveData
*data
)
875 memset(data
, 0, sizeof(MoveData
));
877 for (i
= 0, tmp
= wwin
->screen_ptr
->focused_window
;
879 tmp
= tmp
->prev
, i
++);
882 data
->topList
= wmalloc(sizeof(WWindow
*) * i
);
883 data
->leftList
= wmalloc(sizeof(WWindow
*) * i
);
884 data
->rightList
= wmalloc(sizeof(WWindow
*) * i
);
885 data
->bottomList
= wmalloc(sizeof(WWindow
*) * i
);
887 updateMoveData(wwin
, data
);
890 data
->realX
= wwin
->frame_x
;
891 data
->realY
= wwin
->frame_y
;
892 data
->calcX
= wwin
->frame_x
;
893 data
->calcY
= wwin
->frame_y
;
895 data
->winWidth
= wwin
->frame
->core
->width
+
896 (HAS_BORDER_WITH_SELECT(wwin
) ? 2*FRAME_BORDER_WIDTH
: 0);
897 data
->winHeight
= wwin
->frame
->core
->height
+
898 (HAS_BORDER_WITH_SELECT(wwin
) ? 2*FRAME_BORDER_WIDTH
: 0);
903 checkWorkspaceChange(WWindow
*wwin
, MoveData
*data
, Bool opaqueMove
)
905 WScreen
*scr
= wwin
->screen_ptr
;
906 Bool changed
= False
;
908 if (data
->mouseX
<= 1) {
909 if (scr
->current_workspace
> 0) {
911 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
- 1,
916 } else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
) {
918 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->workspace_count
- 1,
923 } else if (data
->mouseX
>= scr
->scr_width
- 2) {
925 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
927 if (wPreferences
.ws_cycle
928 || scr
->workspace_count
== MAX_WORKSPACES
) {
930 crossWorkspace(scr
, wwin
, opaqueMove
, 0, False
);
934 /* if user insists on trying to go to next workspace even when
935 * it's already the last, create a new one */
936 else if (data
->omouseX
== data
->mouseX
937 && wPreferences
.ws_advance
) {
939 /* detect user "rubbing" the window against the edge */
940 if (data
->rubCount
> 0
941 && data
->omouseY
- data
->mouseY
> MOVE_THRESHOLD
) {
943 data
->rubCount
= -(data
->rubCount
+ 1);
945 } else if (data
->rubCount
<= 0
946 && data
->mouseY
- data
->omouseY
> MOVE_THRESHOLD
) {
948 data
->rubCount
= -data
->rubCount
+ 1;
951 /* create a new workspace */
952 if (abs(data
->rubCount
) > 2) {
953 /* go to next workspace */
956 crossWorkspace(scr
, wwin
, opaqueMove
,
957 scr
->current_workspace
+1, False
);
961 } else if (scr
->current_workspace
< scr
->workspace_count
) {
963 /* go to next workspace */
964 crossWorkspace(scr
, wwin
, opaqueMove
,
965 scr
->current_workspace
+1, False
);
978 updateWindowPosition(WWindow
*wwin
, MoveData
*data
, Bool doResistance
,
979 Bool opaqueMove
, int newMouseX
, int newMouseY
)
981 WScreen
*scr
= wwin
->screen_ptr
;
982 int dx
, dy
; /* how much mouse moved */
983 int winL
, winR
, winT
, winB
; /* requested new window position */
984 int newX
, newY
; /* actual new window position */
985 Bool hresist
, vresist
;
994 /* check the direction of the movement */
995 dx
= newMouseX
- data
->mouseX
;
996 dy
= newMouseY
- data
->mouseY
;
998 data
->omouseX
= data
->mouseX
;
999 data
->omouseY
= data
->mouseY
;
1000 data
->mouseX
= newMouseX
;
1001 data
->mouseY
= newMouseY
;
1003 winL
= data
->calcX
+ dx
;
1004 winR
= data
->calcX
+ data
->winWidth
+ dx
;
1005 winT
= data
->calcY
+ dy
;
1006 winB
= data
->calcY
+ data
->winHeight
+ dy
;
1018 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1019 attract
= wPreferences
.attract
;
1020 /* horizontal movement: check horizontal edge resistances */
1024 /* window is the leftmost window: check against screen edge */
1026 /* Add inter head resistance 1/2 (if needed) */
1027 head
= wGetHeadForPointerLocation(scr
);
1028 rect
= wGetRectForHead(scr
, head
);
1030 l_edge
= WMAX(scr
->totalUsableArea
[head
].x1
, rect
.pos
.x
);
1031 edge_l
= l_edge
- resist
;
1032 edge_r
= WMIN(scr
->totalUsableArea
[head
].x2
, rect
.pos
.x
+ rect
.size
.width
);
1033 r_edge
= edge_r
+ resist
;
1036 if ((data
->rightIndex
>= 0) && (data
->rightIndex
<= data
->count
)) {
1039 for (i
= data
->rightIndex
- 1; i
>= 0; i
--) {
1040 looprw
= data
->rightList
[i
];
1041 if (!(data
->realY
> WBOTTOM(looprw
)
1042 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1044 || ((data
->realX
< (WRIGHT(looprw
) + 2)) && dx
< 0)) {
1045 l_edge
= WRIGHT(looprw
) + 1;
1046 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1053 for (i
= data
->rightIndex
; i
< data
->count
; i
++) {
1054 looprw
= data
->rightList
[i
];
1055 if(!(data
->realY
> WBOTTOM(looprw
)
1056 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1057 r_edge
= WRIGHT(looprw
) + 1;
1058 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1065 if ((data
->leftIndex
>= 0) && (data
->leftIndex
<= data
->count
)) {
1068 for (i
= data
->leftIndex
- 1; i
>= 0; i
--) {
1069 looprw
= data
->leftList
[i
];
1070 if (!(data
->realY
> WBOTTOM(looprw
)
1071 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1073 || (((data
->realX
+ data
->winWidth
) > (WLEFT(looprw
) - 1)) && dx
> 0)) {
1074 edge_r
= WLEFT(looprw
);
1075 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1082 for (i
= data
->leftIndex
; i
< data
->count
; i
++) {
1083 looprw
= data
->leftList
[i
];
1084 if(!(data
->realY
> WBOTTOM(looprw
)
1085 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1086 edge_l
= WLEFT(looprw
);
1087 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1094 printf("%d %d\n",winL,winR);
1095 printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);
1098 if ((winL
- l_edge
) < (r_edge
- winL
)) {
1100 if ((attract
&& winL
<= l_edge
+ resist
&& winL
>= l_edge
- resist
)
1101 || (dx
< 0 && winL
<= l_edge
&& winL
>= l_edge
- resist
)) {
1107 if (resist
> 0 && attract
&& winL
>= r_edge
- resist
&& winL
<= r_edge
+ resist
) {
1113 if ((winR
- edge_l
) < (edge_r
- winR
)) {
1114 if (resist
> 0 && attract
&& winR
<= edge_l
+ resist
&& winR
>= edge_l
- resist
) {
1115 newX
= edge_l
- data
->winWidth
;
1120 if ((attract
&& winR
>= edge_r
- resist
&& winR
<= edge_r
+ resist
)
1121 || (dx
> 0 && winR
>= edge_r
&& winR
<= edge_r
+ resist
)) {
1122 newX
= edge_r
- data
->winWidth
;
1129 /* Add inter head resistance 2/2 (if needed) */
1130 t_edge
= WMAX(scr
->totalUsableArea
[head
].y1
, rect
.pos
.y
);
1131 edge_t
= t_edge
- resist
;
1132 edge_b
= WMIN(scr
->totalUsableArea
[head
].y2
, rect
.pos
.y
+ rect
.size
.height
);
1133 b_edge
= edge_b
+ resist
;
1135 if ((data
->bottomIndex
>= 0) && (data
->bottomIndex
<= data
->count
)) {
1138 for (i
= data
->bottomIndex
- 1; i
>= 0; i
--) {
1139 looprw
= data
->bottomList
[i
];
1140 if (!(data
->realX
> WRIGHT(looprw
)
1141 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1143 || ((data
->realY
< (WBOTTOM(looprw
) + 2)) && dy
< 0)) {
1144 t_edge
= WBOTTOM(looprw
) + 1;
1145 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1152 for (i
= data
->bottomIndex
; i
< data
->count
; i
++) {
1153 looprw
= data
->bottomList
[i
];
1154 if(!(data
->realX
> WRIGHT(looprw
)
1155 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1156 b_edge
= WBOTTOM(looprw
) + 1;
1157 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1164 if ((data
->topIndex
>= 0) && (data
->topIndex
<= data
->count
)) {
1167 for (i
= data
->topIndex
- 1; i
>= 0; i
--) {
1168 looprw
= data
->topList
[i
];
1169 if (!(data
->realX
> WRIGHT(looprw
)
1170 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1172 || (((data
->realY
+ data
->winHeight
) > (WTOP(looprw
) - 1)) && dy
> 0)) {
1173 edge_b
= WTOP(looprw
);
1174 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1181 for (i
= data
->topIndex
; i
< data
->count
; i
++) {
1182 looprw
= data
->topList
[i
];
1183 if(!(data
->realX
> WRIGHT(looprw
)
1184 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1185 edge_t
= WTOP(looprw
);
1186 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1192 if ((winT
- t_edge
) < (b_edge
- winT
)) {
1194 if ((attract
&& winT
<= t_edge
+ resist
&& winT
>= t_edge
- resist
)
1195 || (dy
< 0 && winT
<= t_edge
&& winT
>= t_edge
- resist
)) {
1202 if (resist
> 0 && attract
&& winT
>= b_edge
- resist
&& winT
<= b_edge
+ resist
) {
1208 if ((winB
- edge_t
) < (edge_b
- winB
)) {
1209 if (resist
> 0 && attract
&& winB
<= edge_t
+ resist
&& winB
>= edge_t
- resist
) {
1210 newY
= edge_t
- data
->winHeight
;
1216 if ((attract
&& winB
>= edge_b
- resist
&& winB
<= edge_b
+ resist
)
1217 || (dy
> 0 && winB
>= edge_b
&& winB
<= edge_b
+ resist
)) {
1218 newY
= edge_b
- data
->winHeight
;
1228 /* update window position */
1232 if (((dx
> 0 && data
->calcX
- data
->realX
> 0)
1233 || (dx
< 0 && data
->calcX
- data
->realX
< 0)) && !hresist
)
1236 if (((dy
> 0 && data
->calcY
- data
->realY
> 0)
1237 || (dy
< 0 && data
->calcY
- data
->realY
< 0)) && !vresist
)
1240 if (data
->realX
!= newX
|| data
->realY
!= newY
) {
1242 if (wPreferences
.move_display
== WDIS_NEW
1243 && !scr
->selected_windows
) {
1244 showPosition(wwin
, data
->realX
, data
->realY
);
1247 doWindowMove(wwin
, scr
->selected_windows
,
1248 newX
- wwin
->frame_x
,
1249 newY
- wwin
->frame_y
);
1252 drawFrames(wwin
, scr
->selected_windows
,
1253 data
->realX
- wwin
->frame_x
,
1254 data
->realY
- wwin
->frame_y
);
1257 if (!scr
->selected_windows
1258 && wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
1260 moveGeometryDisplayCentered(scr
, newX
+ data
->winWidth
/2,
1261 newY
+ data
->winHeight
/2);
1266 drawFrames(wwin
, scr
->selected_windows
,
1267 newX
- wwin
->frame_x
,
1268 newY
- wwin
->frame_y
);
1271 if (!scr
->selected_windows
) {
1272 showPosition(wwin
, newX
, newY
);
1277 /* recalc relative window position */
1278 if (doResistance
&& (data
->realX
!= newX
|| data
->realY
!= newY
)) {
1279 updateResistance(wwin
, data
, newX
, newY
);
1287 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1289 #define MOVABLE_BIT 0x01
1290 #define RESIZABLE_BIT 0x02
1293 wKeyboardMoveResizeWindow(WWindow
*wwin
)
1295 WScreen
*scr
= wwin
->screen_ptr
;
1296 Window root
= scr
->root_win
;
1298 int w
= wwin
->frame
->core
->width
;
1299 int h
= wwin
->frame
->core
->height
;
1300 int scr_width
= wwin
->screen_ptr
->scr_width
;
1301 int scr_height
= wwin
->screen_ptr
->scr_height
;
1302 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1303 int src_x
= wwin
->frame_x
;
1304 int src_y
= wwin
->frame_y
;
1305 int done
,off_x
,off_y
,ww
,wh
;
1308 KeyCode shiftl
, shiftr
, ctrll
, ctrlmode
;
1309 KeySym keysym
=NoSymbol
;
1311 int modes
= ((IS_MOVABLE(wwin
) ? MOVABLE_BIT
: 0) |
1312 (IS_RESIZABLE(wwin
) ? RESIZABLE_BIT
: 0));
1313 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
)>1)
1314 ? wGetHeadForWindow(wwin
)
1315 : scr
->xine_info
.primary_head
);
1317 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1318 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1319 ctrll
= XKeysymToKeycode(dpy
, XK_Control_L
);
1320 ctrlmode
=done
=off_x
=off_y
=0;
1322 if (modes
== RESIZABLE_BIT
) {
1328 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1330 if (!wwin
->flags
.selected
) {
1331 wUnselectWindows(scr
);
1334 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1335 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
1336 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
);
1338 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1339 if(scr
->selected_windows
)
1340 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1341 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1342 if(!scr
->selected_windows
)
1343 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1345 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1355 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1356 | ButtonPressMask
| ExposureMask
, &event
);
1357 if (event
.type
== Expose
) {
1358 WMHandleEvent(&event
);
1360 } while (event
.type
== Expose
);
1363 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1364 if(scr
->selected_windows
)
1365 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1366 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1367 /*** I HATE EDGE RESISTANCE - ]d ***/
1370 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1374 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1379 switch (event
.type
) {
1382 if (event
.xkey
.time
- lastTime
> 50) {
1383 kspeed
/=(1 + (event
.xkey
.time
- lastTime
)/100);
1389 if (kspeed
< _KS
) kspeed
= _KS
;
1390 lastTime
= event
.xkey
.time
;
1391 if (modes
== (MOVABLE_BIT
|RESIZABLE_BIT
)) {
1392 if ((event
.xkey
.state
& ControlMask
) && !wwin
->flags
.shaded
) {
1394 wUnselectWindows(scr
);
1400 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
) {
1402 cycleGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
, 0);
1404 cyclePositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1408 keysym
= XLookupKeysym(&event
.xkey
, 0);
1463 if (moment
!= RIGHT
)
1474 wWindowConstrainSize(wwin
, &ww
, &wh
);
1477 if (wPreferences
.ws_cycle
){
1478 if (src_x
+ off_x
+ ww
< 20){
1479 if(!scr
->current_workspace
) {
1480 wWorkspaceChange(scr
, scr
->workspace_count
-1);
1482 else wWorkspaceChange(scr
, scr
->current_workspace
-1);
1485 else if (src_x
+ off_x
+ 20 > scr_width
){
1486 if(scr
->current_workspace
== scr
->workspace_count
-1) {
1487 wWorkspaceChange(scr
, 0);
1489 else wWorkspaceChange(scr
, scr
->current_workspace
+1);
1494 if (src_x
+ off_x
+ ww
< 20)
1495 off_x
= 20 - ww
- src_x
;
1496 else if (src_x
+ off_x
+ 20 > scr_width
)
1497 off_x
= scr_width
- 20 - src_x
;
1500 if (src_y
+ off_y
+ wh
< 20) {
1501 off_y
= 20 - wh
- src_y
;
1503 else if (src_y
+ off_y
+ 20 > scr_height
) {
1504 off_y
= scr_height
- 20 - src_y
;
1513 WMHandleEvent(&event
);
1514 while (XCheckTypedEvent(dpy
, Expose
, &event
)) {
1515 WMHandleEvent(&event
);
1520 WMHandleEvent(&event
);
1527 if (wwin
->flags
.shaded
&& !scr
->selected_windows
){
1528 moveGeometryDisplayCentered(scr
, src_x
+off_x
+ w
/2, src_y
+off_y
+ h
/2);
1531 WMUnmapWidget(scr
->gview
);
1532 mapGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1533 } else if(!scr
->selected_windows
) {
1534 WMUnmapWidget(scr
->gview
);
1535 mapPositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1539 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1540 if (scr
->selected_windows
)
1541 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1543 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1545 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1550 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1551 } else if(!scr
->selected_windows
)
1552 showPosition(wwin
, src_x
+off_x
, src_y
+off_y
);
1556 scr
->keymove_tick
=0;
1558 WMDeleteTimerWithClientData(&looper);
1560 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1561 if(scr
->selected_windows
)
1562 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1563 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1566 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1570 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1571 WMUnmapWidget(scr
->gview
);
1573 WMUnmapWidget(scr
->gview
);
1575 XUngrabKeyboard(dpy
, CurrentTime
);
1576 XUngrabPointer(dpy
, CurrentTime
);
1580 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1581 if (!scr
->selected_windows
) {
1582 wWindowMove(wwin
, src_x
+off_x
, src_y
+off_y
);
1583 wWindowSynthConfigureNotify(wwin
);
1585 WMArrayIterator iter
;
1588 doWindowMove(wwin
, scr
->selected_windows
, off_x
, off_y
);
1590 WM_ITERATE_ARRAY(scr
->selected_windows
, foo
, iter
) {
1591 wWindowSynthConfigureNotify(foo
);
1595 if (wwin
->client
.width
!= ww
)
1596 wwin
->flags
.user_changed_width
= 1;
1598 if (wwin
->client
.height
!= wh
- vert_border
)
1599 wwin
->flags
.user_changed_height
= 1;
1601 wWindowConfigure(wwin
, src_x
+off_x
, src_y
+off_y
,
1602 ww
, wh
- vert_border
);
1603 wWindowSynthConfigureNotify(wwin
);
1605 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1606 wSetFocusTo(scr
, wwin
);
1609 if (wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
)>1 &&
1610 head
!= wGetHeadForWindow(wwin
)) {
1611 wArrangeIcons(scr
, True
);
1615 #if defined(NETWM_HINTS) && defined(VIRTUAL_DESKTOP)
1616 wWorkspaceResizeViewport(scr
, scr
->current_workspace
);
1626 *----------------------------------------------------------------------
1627 * wMouseMoveWindow--
1628 * Move the named window and the other selected ones (if any),
1629 * interactively. Also shows the position of the window, if only one
1630 * window is being moved.
1631 * If the window is not on the selected window list, the selected
1632 * windows are deselected.
1633 * If shift is pressed during the operation, the position display
1634 * is changed to another type.
1637 * True if the window was moved, False otherwise.
1640 * The window(s) position is changed, and the client(s) are
1641 * notified about that.
1642 * The position display configuration may be changed.
1643 *----------------------------------------------------------------------
1646 wMouseMoveWindow(WWindow
*wwin
, XEvent
*ev
)
1648 WScreen
*scr
= wwin
->screen_ptr
;
1650 Window root
= scr
->root_win
;
1651 KeyCode shiftl
, shiftr
;
1655 /* This needs not to change while moving, else bad things can happen */
1656 int opaqueMove
= wPreferences
.opaque_move
;
1658 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1659 ? wGetHeadForWindow(wwin
)
1660 : scr
->xine_info
.primary_head
);
1661 #ifdef GHOST_WINDOW_MOVE
1662 RImage
*rimg
= InitGhostWindowMove(scr
);
1665 if (!IS_MOVABLE(wwin
))
1668 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1669 XSetWindowAttributes attr
;
1671 attr
.save_under
= True
;
1672 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
,
1673 CWSaveUnder
, &attr
);
1677 initMoveData(wwin
, &moveData
);
1679 moveData
.mouseX
= ev
->xmotion
.x_root
;
1680 moveData
.mouseY
= ev
->xmotion
.y_root
;
1682 if (!wwin
->flags
.selected
) {
1683 /* this window is not selected, unselect others and move only wwin */
1684 wUnselectWindows(scr
);
1687 puts("Moving window");
1689 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1690 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1696 /* XWarpPointer() doesn't seem to generate Motion events, so
1697 * we've got to simulate them */
1698 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1699 &event
.xmotion
.y_root
, &junk
, &junk
,
1700 (unsigned *) &junk
);
1702 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1703 | PointerMotionHintMask
1704 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
,
1707 if (event
.type
== MotionNotify
) {
1708 /* compress MotionNotify events */
1709 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1710 if (!checkMouseSamplingRate(&event
))
1714 switch (event
.type
) {
1716 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1717 && started
&& !scr
->selected_windows
) {
1720 drawFrames(wwin
, scr
->selected_windows
,
1721 moveData
.realX
- wwin
->frame_x
,
1722 moveData
.realY
- wwin
->frame_y
);
1725 if (wPreferences
.move_display
== WDIS_NEW
1726 && !scr
->selected_windows
) {
1727 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1730 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1731 moveData
.winWidth
, moveData
.winHeight
);
1733 if (wPreferences
.move_display
== WDIS_NEW
1734 && !scr
->selected_windows
) {
1736 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1740 drawFrames(wwin
, scr
->selected_windows
,
1741 moveData
.realX
- wwin
->frame_x
,
1742 moveData
.realY
- wwin
->frame_y
);
1745 WMHandleEvent(&event); this causes problems needs fixing */
1751 updateWindowPosition(wwin
, &moveData
,
1752 scr
->selected_windows
== NULL
1753 && wPreferences
.edge_resistance
> 0,
1755 event
.xmotion
.x_root
,
1756 event
.xmotion
.y_root
);
1758 if (!warped
&& !wPreferences
.no_autowrap
) {
1759 int oldWorkspace
= scr
->current_workspace
;
1761 if (wPreferences
.move_display
== WDIS_NEW
1762 && !scr
->selected_windows
) {
1763 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1767 drawFrames(wwin
, scr
->selected_windows
,
1768 moveData
.realX
- wwin
->frame_x
,
1769 moveData
.realY
- wwin
->frame_y
);
1771 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1772 if (scr
->current_workspace
!= oldWorkspace
1773 && wPreferences
.edge_resistance
> 0
1774 && scr
->selected_windows
== NULL
)
1775 updateMoveData(wwin
, &moveData
);
1779 drawFrames(wwin
, scr
->selected_windows
,
1780 moveData
.realX
- wwin
->frame_x
,
1781 moveData
.realY
- wwin
->frame_y
);
1783 if (wPreferences
.move_display
== WDIS_NEW
1784 && !scr
->selected_windows
) {
1786 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1792 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1793 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1795 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1796 | ButtonReleaseMask
| ButtonPressMask
,
1797 wCursor
[WCUR_MOVE
], CurrentTime
);
1799 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1802 if (!scr
->selected_windows
)
1803 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1804 moveData
.winWidth
, moveData
.winHeight
);
1806 if (started
&& !opaqueMove
)
1807 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1809 if (!opaqueMove
|| (wPreferences
.move_display
==WDIS_NEW
1810 && !scr
->selected_windows
)) {
1812 if (wPreferences
.move_display
==WDIS_NEW
)
1813 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1822 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1828 drawFrames(wwin
, scr
->selected_windows
,
1829 moveData
.realX
- wwin
->frame_x
,
1830 moveData
.realY
- wwin
->frame_y
);
1832 doWindowMove(wwin
, scr
->selected_windows
,
1833 moveData
.realX
- wwin
->frame_x
,
1834 moveData
.realY
- wwin
->frame_y
);
1836 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1837 wWindowSynthConfigureNotify(wwin
);
1839 XUngrabKeyboard(dpy
, CurrentTime
);
1842 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1843 wSetFocusTo(scr
, wwin
);
1845 if (wPreferences
.move_display
== WDIS_NEW
)
1846 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1848 /* discard all enter/leave events that happened until
1849 * the time the button was released */
1850 while (XCheckTypedEvent(dpy
, EnterNotify
, &e
)) {
1851 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1852 XPutBackEvent(dpy
, &e
);
1856 while (XCheckTypedEvent(dpy
, LeaveNotify
, &e
)) {
1857 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1858 XPutBackEvent(dpy
, &e
);
1863 if (!scr
->selected_windows
) {
1864 /* get rid of the geometry window */
1865 WMUnmapWidget(scr
->gview
);
1869 puts("End move window");
1875 if (started
&& !opaqueMove
) {
1876 drawFrames(wwin
, scr
->selected_windows
,
1877 moveData
.realX
- wwin
->frame_x
,
1878 moveData
.realY
- wwin
->frame_y
);
1880 WMHandleEvent(&event
);
1883 drawFrames(wwin
, scr
->selected_windows
,
1884 moveData
.realX
- wwin
->frame_x
,
1885 moveData
.realY
- wwin
->frame_y
);
1887 WMHandleEvent(&event
);
1893 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1894 XSetWindowAttributes attr
;
1896 attr
.save_under
= False
;
1897 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
,
1898 CWSaveUnder
, &attr
);
1902 freeMoveData(&moveData
);
1904 if (started
&& wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
)>1 &&
1905 head
!= wGetHeadForWindow(wwin
)) {
1906 wArrangeIcons(scr
, True
);
1909 #if defined(NETWM_HINTS) && defined(VIRTUAL_DESKTOP)
1911 wWorkspaceResizeViewport(scr
, scr
->current_workspace
);
1919 #define HCONSTRAIN 2
1922 getResizeDirection(WWindow
*wwin
, int x
, int y
, int dx
, int dy
,
1925 int w
= wwin
->frame
->core
->width
- 1;
1926 int cw
= wwin
->frame
->resizebar_corner_width
;
1929 /* if not resizing through the resizebar */
1930 if (!(flags
& RESIZEBAR
)) {
1931 int xdir
= (abs(x
) < (wwin
->client
.width
/2)) ? LEFT
: RIGHT
;
1932 int ydir
= (abs(y
) < (wwin
->client
.height
/2)) ? UP
: DOWN
;
1933 if (abs(dx
) < 2 || abs(dy
) < 2) {
1934 if (abs(dy
) > abs(dx
))
1939 return (xdir
| ydir
);
1942 /* window is too narrow. allow diagonal resize */
1946 if (flags
& HCONSTRAIN
)
1951 return (LEFT
| ydir
);
1953 return (RIGHT
| ydir
);
1955 /* vertical resize */
1956 if ((x
> cw
) && (x
< w
- cw
))
1964 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1972 wMouseResizeWindow(WWindow
*wwin
, XEvent
*ev
)
1975 WScreen
*scr
= wwin
->screen_ptr
;
1976 Window root
= scr
->root_win
;
1977 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1978 int fw
= wwin
->frame
->core
->width
;
1979 int fh
= wwin
->frame
->core
->height
;
1980 int fx
= wwin
->frame_x
;
1981 int fy
= wwin
->frame_y
;
1982 int is_resizebar
= (wwin
->frame
->resizebar
1983 && ev
->xany
.window
==wwin
->frame
->resizebar
->window
);
1987 int rw
= fw
, rh
= fh
;
1988 int rx1
, ry1
, rx2
, ry2
;
1990 KeyCode shiftl
, shiftr
;
1996 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
)>1)
1997 ? wGetHeadForWindow(wwin
)
1998 : scr
->xine_info
.primary_head
);
2000 if (!IS_RESIZABLE(wwin
))
2003 if (wwin
->flags
.shaded
) {
2004 wwarning("internal error: tryein");
2007 orig_x
= ev
->xbutton
.x_root
;
2008 orig_y
= ev
->xbutton
.y_root
;
2012 puts("Resizing window");
2015 wUnselectWindows(scr
);
2020 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2021 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2022 if (HAS_TITLEBAR(wwin
))
2023 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + (wPreferences
.window_title_clearance
+ TITLEBAR_EXTEND_SPACE
) * 2;
2027 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
2028 | ButtonReleaseMask
| PointerMotionHintMask
2029 | ButtonPressMask
| ExposureMask
, &event
);
2030 if (!checkMouseSamplingRate(&event
))
2033 switch (event
.type
) {
2035 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2036 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
2038 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2039 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
2040 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2042 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2047 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
2058 dw
= orig_x
- event
.xmotion
.x_root
;
2059 else if (res
& RIGHT
)
2060 dw
= event
.xmotion
.x_root
- orig_x
;
2062 dh
= orig_y
- event
.xmotion
.y_root
;
2063 else if (res
& DOWN
)
2064 dh
= event
.xmotion
.y_root
- orig_y
;
2066 orig_x
= event
.xmotion
.x_root
;
2067 orig_y
= event
.xmotion
.y_root
;
2072 fh
= rh
- vert_border
;
2073 wWindowConstrainSize(wwin
, &fw
, &fh
);
2077 else if (res
& RIGHT
)
2081 else if (res
& DOWN
)
2083 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
2084 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
2089 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
2090 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
2092 /* check if resizing through resizebar */
2098 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
2099 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
2100 flags
|= HCONSTRAIN
;
2102 res
= getResizeDirection(wwin
, tx
, ty
,
2103 orig_x
- event
.xmotion
.x_root
,
2104 orig_y
- event
.xmotion
.y_root
, flags
);
2106 if (res
== (UP
|LEFT
))
2107 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2108 | ButtonReleaseMask
| ButtonPressMask
,
2109 wCursor
[WCUR_TOPLEFTRESIZE
], CurrentTime
);
2110 else if (res
== (UP
|RIGHT
))
2111 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2112 | ButtonReleaseMask
| ButtonPressMask
,
2113 wCursor
[WCUR_TOPRIGHTRESIZE
], CurrentTime
);
2114 else if (res
== (DOWN
|LEFT
))
2115 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2116 | ButtonReleaseMask
| ButtonPressMask
,
2117 wCursor
[WCUR_BOTTOMLEFTRESIZE
], CurrentTime
);
2118 else if (res
== (DOWN
|RIGHT
))
2119 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2120 | ButtonReleaseMask
| ButtonPressMask
,
2121 wCursor
[WCUR_BOTTOMRIGHTRESIZE
], CurrentTime
);
2122 else if (res
== DOWN
|| res
== UP
)
2123 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2124 | ButtonReleaseMask
| ButtonPressMask
,
2125 wCursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2126 else if (res
& (DOWN
|UP
))
2127 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2128 | ButtonReleaseMask
| ButtonPressMask
,
2129 wCursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2130 else if (res
& (LEFT
|RIGHT
))
2131 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2132 | ButtonReleaseMask
| ButtonPressMask
,
2133 wCursor
[WCUR_HORIZONRESIZE
], CurrentTime
);
2135 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
2140 /* Draw the resize frame for the first time. */
2141 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
2143 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2145 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2150 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
2151 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
2153 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
2154 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2156 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
2158 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2160 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
2161 if (wPreferences
.size_display
== WDIS_NEW
) {
2162 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
2163 orig_fy
+ orig_fh
, res
);
2165 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2174 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2178 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2180 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2182 XUngrabKeyboard(dpy
, CurrentTime
);
2183 WMUnmapWidget(scr
->gview
);
2186 if (wwin
->client
.width
!= fw
)
2187 wwin
->flags
.user_changed_width
= 1;
2189 if (wwin
->client
.height
!= fh
- vert_border
)
2190 wwin
->flags
.user_changed_height
= 1;
2192 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
2195 puts("End resize window");
2200 WMHandleEvent(&event
);
2204 if (wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 &&
2205 head
!= wGetHeadForWindow(wwin
)) {
2206 wArrangeIcons(scr
, True
);
2209 #if defined(NETWM_HINTS) && defined(VIRTUAL_DESKTOP)
2210 wWorkspaceResizeViewport(scr
, scr
->current_workspace
);
2224 wUnselectWindows(WScreen
*scr
)
2228 if (!scr
->selected_windows
)
2231 while (WMGetArrayItemCount(scr
->selected_windows
)) {
2232 wwin
= WMGetFromArray(scr
->selected_windows
, 0);
2233 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
2234 wIconSelect(wwin
->icon
);
2236 wSelectWindow(wwin
, False
);
2238 WMFreeArray(scr
->selected_windows
);
2239 scr
->selected_windows
= NULL
;
2244 selectWindowsInside(WScreen
*scr
, int x1
, int y1
, int x2
, int y2
)
2248 /* select the windows and put them in the selected window list */
2249 tmpw
= scr
->focused_window
;
2250 while (tmpw
!= NULL
) {
2251 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
2252 if ((tmpw
->frame
->workspace
== scr
->current_workspace
2253 || IS_OMNIPRESENT(tmpw
))
2254 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
2255 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
2256 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
2257 wSelectWindow(tmpw
, True
);
2266 wSelectWindows(WScreen
*scr
, XEvent
*ev
)
2269 Window root
= scr
->root_win
;
2270 GC gc
= scr
->frame_gc
;
2271 int xp
= ev
->xbutton
.x_root
;
2272 int yp
= ev
->xbutton
.y_root
;
2277 puts("Selecting windows");
2279 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
2280 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
2281 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
],
2282 CurrentTime
) != Success
) {
2287 wUnselectWindows(scr
);
2289 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
2291 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
2292 | ButtonPressMask
, &event
);
2294 switch (event
.type
) {
2296 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2297 x
= event
.xmotion
.x_root
;
2304 y
= event
.xmotion
.y_root
;
2311 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2318 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2321 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2323 XUngrabPointer(dpy
, CurrentTime
);
2324 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
2327 puts("End window selection");
2332 WMHandleEvent(&event
);
2340 InteractivePlaceWindow(WWindow
*wwin
, int *x_ret
, int *y_ret
,
2341 unsigned width
, unsigned height
)
2343 WScreen
*scr
= wwin
->screen_ptr
;
2344 Window root
= scr
->root_win
;
2347 KeyCode shiftl
, shiftr
;
2351 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2352 GrabModeAsync
, GrabModeAsync
, None
,
2353 wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2358 if (HAS_TITLEBAR(wwin
)) {
2359 h
= WMFontHeight(scr
->title_font
) + (wPreferences
.window_title_clearance
+ TITLEBAR_EXTEND_SPACE
) * 2;
2362 if (HAS_RESIZEBAR(wwin
)) {
2363 height
+= RESIZEBAR_HEIGHT
;
2365 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2366 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
,
2367 (unsigned *) &junk
);
2368 mapPositionDisplay(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2370 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2372 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2373 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2375 WMMaskEvent(dpy
, PointerMotionMask
|ButtonPressMask
|ExposureMask
|KeyPressMask
,
2378 if (!checkMouseSamplingRate(&event
))
2381 switch (event
.type
) {
2383 if ((event
.xkey
.keycode
== shiftl
)
2384 || (event
.xkey
.keycode
== shiftr
)) {
2385 drawTransparentFrame(wwin
,
2386 x
- width
/2, y
- h
/2, width
, height
);
2387 cyclePositionDisplay(wwin
,
2388 x
- width
/2, y
- h
/2, width
, height
);
2389 drawTransparentFrame(wwin
,
2390 x
- width
/2, y
- h
/2, width
, height
);
2395 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2397 x
= event
.xmotion
.x_root
;
2398 y
= event
.xmotion
.y_root
;
2400 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2401 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2403 showPosition(wwin
, x
- width
/2, y
- h
/2);
2405 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2410 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2412 *x_ret
= x
- width
/2;
2414 XUngrabPointer(dpy
, CurrentTime
);
2415 XUngrabKeyboard(dpy
, CurrentTime
);
2416 /* get rid of the geometry window */
2417 WMUnmapWidget(scr
->gview
);
2421 WMHandleEvent(&event
);