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>
54 /* How many different types of geometry/position
55 display thingies are there? */
56 #define NUM_DISPLAYS 5
60 #define HORIZONTAL (LEFT|RIGHT)
63 #define VERTICAL (UP|DOWN)
66 /* True if window currently has a border. This also includes borderless
67 * windows which are currently selected
69 #define HAS_BORDER_WITH_SELECT(w) ((w)->flags.selected || HAS_BORDER(w))
72 /****** Global Variables ******/
73 extern Time LastTimestamp
;
75 extern Cursor wCursor
[WCUR_LAST
];
77 extern WPreferences wPreferences
;
79 extern Atom _XA_WM_PROTOCOLS
;
84 *----------------------------------------------------------------------
85 * checkMouseSamplingRate-
86 * For lowering the mouse motion sampling rate for machines where
87 * it's too high (SGIs). If it returns False then the event should be
89 *----------------------------------------------------------------------
92 checkMouseSamplingRate(XEvent
*ev
)
94 static Time previousMotion
= 0;
96 if (ev
->type
== MotionNotify
) {
97 if (ev
->xmotion
.time
- previousMotion
< DELAY_BETWEEN_MOUSE_SAMPLING
) {
100 previousMotion
= ev
->xmotion
.time
;
109 *----------------------------------------------------------------------
110 * moveGeometryDisplayCentered
112 * routine that moves the geometry/position window on scr so it is
113 * centered over the given coordinates (x,y). Also the window position
114 * is clamped so it stays on the screen at all times.
115 *----------------------------------------------------------------------
118 moveGeometryDisplayCentered(WScreen
*scr
, int x
, int y
)
120 unsigned int w
= WMWidgetWidth(scr
->gview
);
121 unsigned int h
= WMWidgetHeight(scr
->gview
);
122 int x1
= 0, y1
= 0, x2
= scr
->scr_width
, y2
= scr
->scr_height
;
127 /* dead area check */
128 if (scr
->xine_info
.count
) {
135 rect
.size
.height
= h
;
137 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
139 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
140 rect
= wGetRectForHead(scr
, head
);
143 x2
= x1
+ rect
.size
.width
;
144 y2
= y1
+ rect
.size
.height
;
150 else if (x
> (x2
- w
))
155 else if (y
> (y2
- h
))
159 WMMoveWidget(scr
->gview
, x
, y
);
164 showPosition(WWindow
*wwin
, int x
, int y
)
166 WScreen
*scr
= wwin
->screen_ptr
;
168 if (wPreferences
.move_display
== WDIS_NEW
) {
170 int width
= wwin
->frame
->core
->width
;
171 int height
= wwin
->frame
->core
->height
;
173 GC lgc
= scr
->line_gc
;
174 XSetForeground(dpy
, lgc
, scr
->line_pixel
);
175 sprintf(num
, "%i", x
);
177 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
-1, scr
->scr_width
, y
-1);
178 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
+height
+2, scr
->scr_width
,
180 XDrawLine(dpy
, scr
->root_win
, lgc
, x
-1, 0, x
-1, scr
->scr_height
);
181 XDrawLine(dpy
, scr
->root_win
, lgc
, x
+width
+2, 0, x
+width
+2,
185 #ifdef VIRTUAL_DESKTOP
186 WSetGeometryViewShownPosition(scr
->gview
,
187 x
+ scr
->workspaces
[scr
->current_workspace
]->view_x
,
188 y
+ scr
->workspaces
[scr
->current_workspace
]->view_y
);
190 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
197 cyclePositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
199 WScreen
*scr
= wwin
->screen_ptr
;
202 wPreferences
.move_display
++;
203 wPreferences
.move_display
%= NUM_DISPLAYS
;
205 if (wPreferences
.move_display
== WDIS_NEW
) {
206 wPreferences
.move_display
++;
207 wPreferences
.move_display
%= NUM_DISPLAYS
;
210 if (wPreferences
.move_display
== WDIS_NONE
) {
211 WMUnmapWidget(scr
->gview
);
213 if (wPreferences
.move_display
== WDIS_CENTER
) {
214 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
215 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/2,
216 rect
.pos
.y
+ rect
.size
.height
/2);
217 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
218 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
219 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
220 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
221 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
223 WMMapWidget(scr
->gview
);
229 mapPositionDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
231 WScreen
*scr
= wwin
->screen_ptr
;
234 if (wPreferences
.move_display
== WDIS_NEW
235 || wPreferences
.move_display
== WDIS_NONE
) {
237 } else if (wPreferences
.move_display
== WDIS_CENTER
) {
238 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
239 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/2,
240 rect
.pos
.y
+ rect
.size
.height
/2);
241 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
242 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
243 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
244 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
245 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
247 WMMapWidget(scr
->gview
);
248 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
253 showGeometry(WWindow
*wwin
, int x1
, int y1
, int x2
, int y2
, int direction
)
255 WScreen
*scr
= wwin
->screen_ptr
;
256 Window root
= scr
->root_win
;
257 GC gc
= scr
->line_gc
;
258 int ty
, by
, my
, x
, y
, mx
, s
;
263 /* This seems necessary for some odd reason (too lazy to write x1-1 and
264 * x2-1 everywhere below in the code). But why only for x? */
267 if (HAS_BORDER_WITH_SELECT(wwin
)) {
268 x1
+= FRAME_BORDER_WIDTH
;
269 x2
+= FRAME_BORDER_WIDTH
;
270 y1
+= FRAME_BORDER_WIDTH
;
271 y2
+= FRAME_BORDER_WIDTH
;
274 ty
= y1
+ wwin
->frame
->top_width
;
275 by
= y2
- wwin
->frame
->bottom_width
;
277 if (wPreferences
.size_display
== WDIS_NEW
) {
278 fw
= XTextWidth(scr
->tech_draw_font
, "8888", 4);
279 fh
= scr
->tech_draw_font
->ascent
+scr
->tech_draw_font
->descent
;
281 XSetForeground(dpy
, gc
, scr
->line_pixel
);
283 /* vertical geometry */
284 if (((direction
& LEFT
) && (x2
< scr
->scr_width
- fw
)) || (x1
< fw
)) {
293 /* top arrow & end bar */
294 segment
[0].x1
= x
- (s
+ 6); segment
[0].y1
= ty
;
295 segment
[0].x2
= x
- (s
- 10); segment
[0].y2
= ty
;
298 segment
[1].x1
= x
- (s
- 2); segment
[1].y1
= ty
+ 1;
299 segment
[1].x2
= x
- (s
- 5); segment
[1].y2
= ty
+ 7;
301 segment
[2].x1
= x
- (s
- 2); segment
[2].y1
= ty
+ 1;
302 segment
[2].x2
= x
- (s
+ 1); segment
[2].y2
= ty
+ 7;
305 segment
[3].x1
= x
- (s
- 2); segment
[3].y1
= ty
+ 1;
306 segment
[3].x2
= x
- (s
- 2); segment
[3].y2
= my
- fh
/2 - 1;
308 XDrawSegments(dpy
, root
, gc
, segment
, 4);
310 /* bottom arrow & end bar */
315 segment
[1].y1
= by
- 1;
316 segment
[1].y2
= by
- 7;
318 segment
[2].y1
= by
- 1;
319 segment
[2].y2
= by
- 7;
322 segment
[3].y1
= my
+ fh
/2 + 2;
323 segment
[3].y2
= by
- 1;
325 XDrawSegments(dpy
, root
, gc
, segment
, 4);
327 snprintf(num
, sizeof(num
), "%i", (by
- ty
- wwin
->normal_hints
->base_height
) /
328 wwin
->normal_hints
->height_inc
);
329 fw
= XTextWidth(scr
->tech_draw_font
, num
, strlen(num
));
331 /* Display the height. */
332 XSetFont(dpy
, gc
, scr
->tech_draw_font
->fid
);
333 XDrawString(dpy
, root
, gc
, x
- s
+ 3 - fw
/2, my
+ scr
->tech_draw_font
->ascent
- fh
/2 + 1, num
, strlen(num
));
335 /* horizontal geometry */
343 mx
= x1
+ (x2
- x1
)/2;
344 snprintf(num
, sizeof(num
), "%i", (x2
- x1
- wwin
->normal_hints
->base_width
) /
345 wwin
->normal_hints
->width_inc
);
346 fw
= XTextWidth(scr
->tech_draw_font
, num
, strlen(num
));
348 /* left arrow & end bar */
349 segment
[0].x1
= x1
; segment
[0].y1
= y
- (s
+ 6);
350 segment
[0].x2
= x1
; segment
[0].y2
= y
- (s
- 10);
353 segment
[1].x1
= x1
+ 7; segment
[1].y1
= y
- (s
+ 1);
354 segment
[1].x2
= x1
+ 1; segment
[1].y2
= y
- (s
- 2);
356 segment
[2].x1
= x1
+ 1; segment
[2].y1
= y
- (s
- 2);
357 segment
[2].x2
= x1
+ 7; segment
[2].y2
= y
- (s
- 5);
360 segment
[3].x1
= x1
+ 1; segment
[3].y1
= y
- (s
- 2);
361 segment
[3].x2
= mx
- fw
/2 - 2; segment
[3].y2
= y
- (s
- 2);
363 XDrawSegments(dpy
, root
, gc
, segment
, 4);
365 /* right arrow & end bar */
366 segment
[0].x1
= x2
+ 1;
367 segment
[0].x2
= x2
+ 1;
370 segment
[1].x1
= x2
- 6;
374 segment
[2].x2
= x2
- 6;
377 segment
[3].x1
= mx
+ fw
/2 + 2;
380 XDrawSegments(dpy
, root
, gc
, segment
, 4);
382 /* Display the width. */
383 XDrawString(dpy
, root
, gc
, mx
- fw
/2 + 1, y
- s
+ scr
->tech_draw_font
->ascent
- fh
/2 + 1, num
, strlen(num
));
385 WSetGeometryViewShownSize(scr
->gview
,
386 (x2
- x1
- wwin
->normal_hints
->base_width
)
387 / wwin
->normal_hints
->width_inc
,
388 (by
- ty
- wwin
->normal_hints
->base_height
)
389 / wwin
->normal_hints
->height_inc
);
395 cycleGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
, int dir
)
397 WScreen
*scr
= wwin
->screen_ptr
;
400 wPreferences
.size_display
++;
401 wPreferences
.size_display
%= NUM_DISPLAYS
;
403 if (wPreferences
.size_display
== WDIS_NEW
404 || wPreferences
.size_display
== WDIS_NONE
) {
405 WMUnmapWidget(scr
->gview
);
407 if (wPreferences
.size_display
== WDIS_CENTER
) {
408 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
409 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/2,
410 rect
.pos
.y
+ rect
.size
.height
/2);
411 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
412 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
413 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
414 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
415 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
417 WMMapWidget(scr
->gview
);
418 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, dir
);
424 mapGeometryDisplay(WWindow
*wwin
, int x
, int y
, int w
, int h
)
426 WScreen
*scr
= wwin
->screen_ptr
;
429 if (wPreferences
.size_display
== WDIS_NEW
430 || wPreferences
.size_display
== WDIS_NONE
)
433 if (wPreferences
.size_display
== WDIS_CENTER
) {
434 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
435 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/2,
436 rect
.pos
.y
+ rect
.size
.height
/2);
437 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
438 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
439 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
440 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
441 moveGeometryDisplayCentered(scr
, x
+ w
/2, y
+ h
/2);
443 WMMapWidget(scr
->gview
);
444 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, 0);
450 doWindowMove(WWindow
*wwin
, WMArray
*array
, int dx
, int dy
)
453 WScreen
*scr
= wwin
->screen_ptr
;
456 if (!array
|| !WMGetArrayItemCount(array
)) {
457 wWindowMove(wwin
, wwin
->frame_x
+ dx
, wwin
->frame_y
+ dy
);
459 WMArrayIterator iter
;
461 WM_ITERATE_ARRAY(array
, tmpw
, iter
) {
462 x
= tmpw
->frame_x
+ dx
;
463 y
= tmpw
->frame_y
+ dy
;
465 #if 1 /* XXX: with xinerama patch was #if 0, check this */
466 /* don't let windows become unreachable */
468 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
469 x
= 20 - (int)tmpw
->frame
->core
->width
;
470 else if (x
+ 20 > scr
->scr_width
)
471 x
= scr
->scr_width
- 20;
473 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
474 y
= 20 - (int)tmpw
->frame
->core
->height
;
475 else if (y
+ 20 > scr
->scr_height
)
476 y
= scr
->scr_height
- 20;
478 wScreenBringInside(scr
, &x
, &y
,
479 (int)tmpw
->frame
->core
->width
,
480 (int)tmpw
->frame
->core
->height
);
483 wWindowMove(tmpw
, x
, y
);
490 drawTransparentFrame(WWindow
*wwin
, int x
, int y
, int width
, int height
)
492 Window root
= wwin
->screen_ptr
->root_win
;
493 GC gc
= wwin
->screen_ptr
->frame_gc
;
497 if (HAS_BORDER_WITH_SELECT(wwin
)) {
498 x
+= FRAME_BORDER_WIDTH
;
499 y
+= FRAME_BORDER_WIDTH
;
502 if (HAS_TITLEBAR(wwin
) && !wwin
->flags
.shaded
) {
503 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + (wPreferences
.window_title_clearance
+ TITLEBAR_EXTEND_SPACE
) * 2;
505 if (HAS_RESIZEBAR(wwin
) && !wwin
->flags
.shaded
) {
506 /* Can't use wwin-frame->bottom_width because, in some cases
507 (e.g. interactive placement), frame does not point to anything. */
508 bottom
= RESIZEBAR_HEIGHT
;
510 XDrawRectangle(dpy
, root
, gc
, x
- 1, y
- 1, width
+ 1, height
+ 1);
513 XDrawLine(dpy
, root
, gc
, x
, y
+ h
- 1, x
+ width
, y
+ h
- 1);
516 XDrawLine(dpy
, root
, gc
, x
, y
+ height
- bottom
,
517 x
+ width
, y
+ height
- bottom
);
523 drawFrames(WWindow
*wwin
, WMArray
*array
, int dx
, int dy
)
526 int scr_width
= wwin
->screen_ptr
->scr_width
;
527 int scr_height
= wwin
->screen_ptr
->scr_height
;
532 x
= wwin
->frame_x
+ dx
;
533 y
= wwin
->frame_y
+ dy
;
535 drawTransparentFrame(wwin
, x
, y
,
536 wwin
->frame
->core
->width
,
537 wwin
->frame
->core
->height
);
540 WMArrayIterator iter
;
542 WM_ITERATE_ARRAY(array
, tmpw
, iter
) {
543 x
= tmpw
->frame_x
+ dx
;
544 y
= tmpw
->frame_y
+ dy
;
546 /* don't let windows become unreachable */
547 #if 1 /* XXX: was 0 in XINERAMA patch, check */
548 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
549 x
= 20 - (int)tmpw
->frame
->core
->width
;
550 else if (x
+ 20 > scr_width
)
553 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
554 y
= 20 - (int)tmpw
->frame
->core
->height
;
555 else if (y
+ 20 > scr_height
)
559 wScreenBringInside(wwin
->screen_ptr
, &x
, &y
,
560 (int)tmpw
->frame
->core
->width
,
561 (int)tmpw
->frame
->core
->height
);
564 drawTransparentFrame(tmpw
, x
, y
, tmpw
->frame
->core
->width
,
565 tmpw
->frame
->core
->height
);
578 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &ev
)) ;
583 crossWorkspace(WScreen
*scr
, WWindow
*wwin
, int opaque_move
,
584 int new_workspace
, int rewind
)
586 /* do not let window be unmapped */
588 wwin
->flags
.changing_workspace
= 1;
589 wWindowChangeWorkspace(wwin
, new_workspace
);
591 /* go to new workspace */
592 wWorkspaceChange(scr
, new_workspace
);
594 wwin
->flags
.changing_workspace
= 0;
597 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, scr
->scr_width
- 20, 0);
599 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, -(scr
->scr_width
- 20), 0);
604 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
605 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
606 GrabModeAsync
, None
, wCursor
[WCUR_MOVE
], CurrentTime
);
614 /* arrays of WWindows sorted by the respective border position */
615 WWindow
**topList
; /* top border */
616 WWindow
**leftList
; /* left border */
617 WWindow
**rightList
; /* right border */
618 WWindow
**bottomList
; /* bottom border */
621 /* index of window in the above lists indicating the relative position
622 * of the window with the others */
628 int rubCount
; /* for workspace switching */
630 int winWidth
, winHeight
; /* width/height of the window */
631 int realX
, realY
; /* actual position of the window */
632 int calcX
, calcY
; /* calculated position of window */
633 int omouseX
, omouseY
; /* old mouse position */
634 int mouseX
, mouseY
; /* last known position of the pointer */
637 #define WTOP(w) (w)->frame_y
638 #define WLEFT(w) (w)->frame_x
639 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width - 1 + \
640 (HAS_BORDER_WITH_SELECT(w) ? 2*FRAME_BORDER_WIDTH : 0))
641 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height - 1 + \
642 (HAS_BORDER_WITH_SELECT(w) ? 2*FRAME_BORDER_WIDTH : 0))
645 compareWTop(const void *a
, const void *b
)
647 WWindow
*wwin1
= *(WWindow
**)a
;
648 WWindow
*wwin2
= *(WWindow
**)b
;
650 if (WTOP(wwin1
) > WTOP(wwin2
))
652 else if (WTOP(wwin1
) < WTOP(wwin2
))
660 compareWLeft(const void *a
, const void *b
)
662 WWindow
*wwin1
= *(WWindow
**)a
;
663 WWindow
*wwin2
= *(WWindow
**)b
;
665 if (WLEFT(wwin1
) > WLEFT(wwin2
))
667 else if (WLEFT(wwin1
) < WLEFT(wwin2
))
675 compareWRight(const void *a
, const void *b
)
677 WWindow
*wwin1
= *(WWindow
**)a
;
678 WWindow
*wwin2
= *(WWindow
**)b
;
680 if (WRIGHT(wwin1
) < WRIGHT(wwin2
))
682 else if (WRIGHT(wwin1
) > WRIGHT(wwin2
))
691 compareWBottom(const void *a
, const void *b
)
693 WWindow
*wwin1
= *(WWindow
**)a
;
694 WWindow
*wwin2
= *(WWindow
**)b
;
696 if (WBOTTOM(wwin1
) < WBOTTOM(wwin2
))
698 else if (WBOTTOM(wwin1
) > WBOTTOM(wwin2
))
706 updateResistance(WWindow
*wwin
, MoveData
*data
, int newX
, int newY
)
709 int newX2
= newX
+ data
->winWidth
;
710 int newY2
= newY
+ data
->winHeight
;
713 if (newX
< data
->realX
) {
714 if (data
->rightIndex
> 0
715 && newX
< WRIGHT(data
->rightList
[data
->rightIndex
-1])) {
717 } else if (data
->leftIndex
<= data
->count
-1
718 && newX2
<= WLEFT(data
->leftList
[data
->leftIndex
])) {
721 } else if (newX
> data
->realX
) {
722 if (data
->leftIndex
> 0
723 && newX2
> WLEFT(data
->leftList
[data
->leftIndex
-1])) {
725 } else if (data
->rightIndex
<= data
->count
-1
726 && newX
>= WRIGHT(data
->rightList
[data
->rightIndex
])) {
732 if (newY
< data
->realY
) {
733 if (data
->bottomIndex
> 0
734 && newY
< WBOTTOM(data
->bottomList
[data
->bottomIndex
-1])) {
736 } else if (data
->topIndex
<= data
->count
-1
737 && newY2
<= WTOP(data
->topList
[data
->topIndex
])) {
740 } else if (newY
> data
->realY
) {
741 if (data
->topIndex
> 0
742 && newY2
> WTOP(data
->topList
[data
->topIndex
-1])) {
744 } else if (data
->bottomIndex
<= data
->count
-1
745 && newY
>= WBOTTOM(data
->bottomList
[data
->bottomIndex
])) {
754 /* TODO: optimize this */
755 if (data
->realY
< WBOTTOM(data
->bottomList
[0])) {
756 data
->bottomIndex
= 0;
758 if (data
->realX
< WRIGHT(data
->rightList
[0])) {
759 data
->rightIndex
= 0;
761 if ((data
->realX
+ data
->winWidth
) > WLEFT(data
->leftList
[0])) {
764 if ((data
->realY
+ data
->winHeight
) > WTOP(data
->topList
[0])) {
767 for (i
= 0; i
< data
->count
; i
++) {
768 if (data
->realY
> WBOTTOM(data
->bottomList
[i
])) {
769 data
->bottomIndex
= i
+ 1;
771 if (data
->realX
> WRIGHT(data
->rightList
[i
])) {
772 data
->rightIndex
= i
+ 1;
774 if ((data
->realX
+ data
->winWidth
) < WLEFT(data
->leftList
[i
])) {
775 data
->leftIndex
= i
+ 1;
777 if ((data
->realY
+ data
->winHeight
) < WTOP(data
->topList
[i
])) {
778 data
->topIndex
= i
+ 1;
785 freeMoveData(MoveData
*data
)
788 wfree(data
->topList
);
790 wfree(data
->leftList
);
792 wfree(data
->rightList
);
793 if (data
->bottomList
)
794 wfree(data
->bottomList
);
799 updateMoveData(WWindow
*wwin
, MoveData
*data
)
801 WScreen
*scr
= wwin
->screen_ptr
;
806 tmp
= scr
->focused_window
;
808 if (tmp
!= wwin
&& scr
->current_workspace
== tmp
->frame
->workspace
809 && !tmp
->flags
.miniaturized
810 && !tmp
->flags
.hidden
811 && !tmp
->flags
.obscured
812 && !WFLAGP(tmp
, sunken
)) {
813 data
->topList
[data
->count
] = tmp
;
814 data
->leftList
[data
->count
] = tmp
;
815 data
->rightList
[data
->count
] = tmp
;
816 data
->bottomList
[data
->count
] = tmp
;
822 if (data
->count
== 0) {
825 data
->rightIndex
= 0;
826 data
->bottomIndex
= 0;
830 /* order from closest to the border of the screen to farthest */
832 qsort(data
->topList
, data
->count
, sizeof(WWindow
**), compareWTop
);
833 qsort(data
->leftList
, data
->count
, sizeof(WWindow
**), compareWLeft
);
834 qsort(data
->rightList
, data
->count
, sizeof(WWindow
**), compareWRight
);
835 qsort(data
->bottomList
, data
->count
, sizeof(WWindow
**), compareWBottom
);
837 /* figure the position of the window relative to the others */
840 data
->leftIndex
= -1;
841 data
->rightIndex
= -1;
842 data
->bottomIndex
= -1;
844 if (WTOP(wwin
) < WBOTTOM(data
->bottomList
[0])) {
845 data
->bottomIndex
= 0;
847 if (WLEFT(wwin
) < WRIGHT(data
->rightList
[0])) {
848 data
->rightIndex
= 0;
850 if (WRIGHT(wwin
) > WLEFT(data
->leftList
[0])) {
853 if (WBOTTOM(wwin
) > WTOP(data
->topList
[0])) {
856 for (i
= 0; i
< data
->count
; i
++) {
857 if (WTOP(wwin
) >= WBOTTOM(data
->bottomList
[i
])) {
858 data
->bottomIndex
= i
+ 1;
860 if (WLEFT(wwin
) >= WRIGHT(data
->rightList
[i
])) {
861 data
->rightIndex
= i
+ 1;
863 if (WRIGHT(wwin
) <= WLEFT(data
->leftList
[i
])) {
864 data
->leftIndex
= i
+ 1;
866 if (WBOTTOM(wwin
) <= WTOP(data
->topList
[i
])) {
867 data
->topIndex
= i
+ 1;
874 initMoveData(WWindow
*wwin
, MoveData
*data
)
879 memset(data
, 0, sizeof(MoveData
));
881 for (i
= 0, tmp
= wwin
->screen_ptr
->focused_window
;
883 tmp
= tmp
->prev
, i
++);
886 data
->topList
= wmalloc(sizeof(WWindow
*) * i
);
887 data
->leftList
= wmalloc(sizeof(WWindow
*) * i
);
888 data
->rightList
= wmalloc(sizeof(WWindow
*) * i
);
889 data
->bottomList
= wmalloc(sizeof(WWindow
*) * i
);
891 updateMoveData(wwin
, data
);
894 data
->realX
= wwin
->frame_x
;
895 data
->realY
= wwin
->frame_y
;
896 data
->calcX
= wwin
->frame_x
;
897 data
->calcY
= wwin
->frame_y
;
899 data
->winWidth
= wwin
->frame
->core
->width
+
900 (HAS_BORDER_WITH_SELECT(wwin
) ? 2*FRAME_BORDER_WIDTH
: 0);
901 data
->winHeight
= wwin
->frame
->core
->height
+
902 (HAS_BORDER_WITH_SELECT(wwin
) ? 2*FRAME_BORDER_WIDTH
: 0);
907 checkWorkspaceChange(WWindow
*wwin
, MoveData
*data
, Bool opaqueMove
)
909 WScreen
*scr
= wwin
->screen_ptr
;
910 Bool changed
= False
;
912 if (data
->mouseX
<= 1) {
913 if (scr
->current_workspace
> 0) {
915 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
- 1,
920 } else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
) {
922 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->workspace_count
- 1,
927 } else if (data
->mouseX
>= scr
->scr_width
- 2) {
929 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
931 if (wPreferences
.ws_cycle
932 || scr
->workspace_count
== MAX_WORKSPACES
) {
934 crossWorkspace(scr
, wwin
, opaqueMove
, 0, False
);
938 /* if user insists on trying to go to next workspace even when
939 * it's already the last, create a new one */
940 else if (data
->omouseX
== data
->mouseX
941 && wPreferences
.ws_advance
) {
943 /* detect user "rubbing" the window against the edge */
944 if (data
->rubCount
> 0
945 && data
->omouseY
- data
->mouseY
> MOVE_THRESHOLD
) {
947 data
->rubCount
= -(data
->rubCount
+ 1);
949 } else if (data
->rubCount
<= 0
950 && data
->mouseY
- data
->omouseY
> MOVE_THRESHOLD
) {
952 data
->rubCount
= -data
->rubCount
+ 1;
955 /* create a new workspace */
956 if (abs(data
->rubCount
) > 2) {
957 /* go to next workspace */
960 crossWorkspace(scr
, wwin
, opaqueMove
,
961 scr
->current_workspace
+1, False
);
965 } else if (scr
->current_workspace
< scr
->workspace_count
) {
967 /* go to next workspace */
968 crossWorkspace(scr
, wwin
, opaqueMove
,
969 scr
->current_workspace
+1, False
);
982 updateWindowPosition(WWindow
*wwin
, MoveData
*data
, Bool doResistance
,
983 Bool opaqueMove
, int newMouseX
, int newMouseY
)
985 WScreen
*scr
= wwin
->screen_ptr
;
986 int dx
, dy
; /* how much mouse moved */
987 int winL
, winR
, winT
, winB
; /* requested new window position */
988 int newX
, newY
; /* actual new window position */
989 Bool hresist
, vresist
;
998 /* check the direction of the movement */
999 dx
= newMouseX
- data
->mouseX
;
1000 dy
= newMouseY
- data
->mouseY
;
1002 data
->omouseX
= data
->mouseX
;
1003 data
->omouseY
= data
->mouseY
;
1004 data
->mouseX
= newMouseX
;
1005 data
->mouseY
= newMouseY
;
1007 winL
= data
->calcX
+ dx
;
1008 winR
= data
->calcX
+ data
->winWidth
+ dx
;
1009 winT
= data
->calcY
+ dy
;
1010 winB
= data
->calcY
+ data
->winHeight
+ dy
;
1022 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1023 attract
= wPreferences
.attract
;
1024 /* horizontal movement: check horizontal edge resistances */
1028 /* window is the leftmost window: check against screen edge */
1030 /* Add inter head resistance 1/2 (if needed) */
1031 head
= wGetHeadForPointerLocation(scr
);
1032 rect
= wGetRectForHead(scr
, head
);
1034 l_edge
= WMAX(scr
->totalUsableArea
[head
].x1
, rect
.pos
.x
);
1035 edge_l
= l_edge
- resist
;
1036 edge_r
= WMIN(scr
->totalUsableArea
[head
].x2
, rect
.pos
.x
+ rect
.size
.width
);
1037 r_edge
= edge_r
+ resist
;
1040 if ((data
->rightIndex
>= 0) && (data
->rightIndex
<= data
->count
)) {
1043 for (i
= data
->rightIndex
- 1; i
>= 0; i
--) {
1044 looprw
= data
->rightList
[i
];
1045 if (!(data
->realY
> WBOTTOM(looprw
)
1046 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1048 || ((data
->realX
< (WRIGHT(looprw
) + 2)) && dx
< 0)) {
1049 l_edge
= WRIGHT(looprw
) + 1;
1050 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1057 for (i
= data
->rightIndex
; i
< data
->count
; i
++) {
1058 looprw
= data
->rightList
[i
];
1059 if(!(data
->realY
> WBOTTOM(looprw
)
1060 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1061 r_edge
= WRIGHT(looprw
) + 1;
1062 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1069 if ((data
->leftIndex
>= 0) && (data
->leftIndex
<= data
->count
)) {
1072 for (i
= data
->leftIndex
- 1; i
>= 0; i
--) {
1073 looprw
= data
->leftList
[i
];
1074 if (!(data
->realY
> WBOTTOM(looprw
)
1075 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1077 || (((data
->realX
+ data
->winWidth
) > (WLEFT(looprw
) - 1)) && dx
> 0)) {
1078 edge_r
= WLEFT(looprw
);
1079 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1086 for (i
= data
->leftIndex
; i
< data
->count
; i
++) {
1087 looprw
= data
->leftList
[i
];
1088 if(!(data
->realY
> WBOTTOM(looprw
)
1089 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1090 edge_l
= WLEFT(looprw
);
1091 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1098 printf("%d %d\n",winL,winR);
1099 printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);
1102 if ((winL
- l_edge
) < (r_edge
- winL
)) {
1104 if ((attract
&& winL
<= l_edge
+ resist
&& winL
>= l_edge
- resist
)
1105 || (dx
< 0 && winL
<= l_edge
&& winL
>= l_edge
- resist
)) {
1111 if (resist
> 0 && attract
&& winL
>= r_edge
- resist
&& winL
<= r_edge
+ resist
) {
1117 if ((winR
- edge_l
) < (edge_r
- winR
)) {
1118 if (resist
> 0 && attract
&& winR
<= edge_l
+ resist
&& winR
>= edge_l
- resist
) {
1119 newX
= edge_l
- data
->winWidth
;
1124 if ((attract
&& winR
>= edge_r
- resist
&& winR
<= edge_r
+ resist
)
1125 || (dx
> 0 && winR
>= edge_r
&& winR
<= edge_r
+ resist
)) {
1126 newX
= edge_r
- data
->winWidth
;
1133 /* Add inter head resistance 2/2 (if needed) */
1134 t_edge
= WMAX(scr
->totalUsableArea
[head
].y1
, rect
.pos
.y
);
1135 edge_t
= t_edge
- resist
;
1136 edge_b
= WMIN(scr
->totalUsableArea
[head
].y2
, rect
.pos
.y
+ rect
.size
.height
);
1137 b_edge
= edge_b
+ resist
;
1139 if ((data
->bottomIndex
>= 0) && (data
->bottomIndex
<= data
->count
)) {
1142 for (i
= data
->bottomIndex
- 1; i
>= 0; i
--) {
1143 looprw
= data
->bottomList
[i
];
1144 if (!(data
->realX
> WRIGHT(looprw
)
1145 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1147 || ((data
->realY
< (WBOTTOM(looprw
) + 2)) && dy
< 0)) {
1148 t_edge
= WBOTTOM(looprw
) + 1;
1149 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1156 for (i
= data
->bottomIndex
; i
< data
->count
; i
++) {
1157 looprw
= data
->bottomList
[i
];
1158 if(!(data
->realX
> WRIGHT(looprw
)
1159 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1160 b_edge
= WBOTTOM(looprw
) + 1;
1161 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1168 if ((data
->topIndex
>= 0) && (data
->topIndex
<= data
->count
)) {
1171 for (i
= data
->topIndex
- 1; i
>= 0; i
--) {
1172 looprw
= data
->topList
[i
];
1173 if (!(data
->realX
> WRIGHT(looprw
)
1174 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1176 || (((data
->realY
+ data
->winHeight
) > (WTOP(looprw
) - 1)) && dy
> 0)) {
1177 edge_b
= WTOP(looprw
);
1178 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1185 for (i
= data
->topIndex
; i
< data
->count
; i
++) {
1186 looprw
= data
->topList
[i
];
1187 if(!(data
->realX
> WRIGHT(looprw
)
1188 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1189 edge_t
= WTOP(looprw
);
1190 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1196 if ((winT
- t_edge
) < (b_edge
- winT
)) {
1198 if ((attract
&& winT
<= t_edge
+ resist
&& winT
>= t_edge
- resist
)
1199 || (dy
< 0 && winT
<= t_edge
&& winT
>= t_edge
- resist
)) {
1206 if (resist
> 0 && attract
&& winT
>= b_edge
- resist
&& winT
<= b_edge
+ resist
) {
1212 if ((winB
- edge_t
) < (edge_b
- winB
)) {
1213 if (resist
> 0 && attract
&& winB
<= edge_t
+ resist
&& winB
>= edge_t
- resist
) {
1214 newY
= edge_t
- data
->winHeight
;
1220 if ((attract
&& winB
>= edge_b
- resist
&& winB
<= edge_b
+ resist
)
1221 || (dy
> 0 && winB
>= edge_b
&& winB
<= edge_b
+ resist
)) {
1222 newY
= edge_b
- data
->winHeight
;
1232 /* update window position */
1236 if (((dx
> 0 && data
->calcX
- data
->realX
> 0)
1237 || (dx
< 0 && data
->calcX
- data
->realX
< 0)) && !hresist
)
1240 if (((dy
> 0 && data
->calcY
- data
->realY
> 0)
1241 || (dy
< 0 && data
->calcY
- data
->realY
< 0)) && !vresist
)
1244 if (data
->realX
!= newX
|| data
->realY
!= newY
) {
1246 if (wPreferences
.move_display
== WDIS_NEW
1247 && !scr
->selected_windows
) {
1248 showPosition(wwin
, data
->realX
, data
->realY
);
1251 doWindowMove(wwin
, scr
->selected_windows
,
1252 newX
- wwin
->frame_x
,
1253 newY
- wwin
->frame_y
);
1256 drawFrames(wwin
, scr
->selected_windows
,
1257 data
->realX
- wwin
->frame_x
,
1258 data
->realY
- wwin
->frame_y
);
1261 if (!scr
->selected_windows
1262 && wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
1264 moveGeometryDisplayCentered(scr
, newX
+ data
->winWidth
/2,
1265 newY
+ data
->winHeight
/2);
1270 drawFrames(wwin
, scr
->selected_windows
,
1271 newX
- wwin
->frame_x
,
1272 newY
- wwin
->frame_y
);
1275 if (!scr
->selected_windows
) {
1276 showPosition(wwin
, newX
, newY
);
1281 /* recalc relative window position */
1282 if (doResistance
&& (data
->realX
!= newX
|| data
->realY
!= newY
)) {
1283 updateResistance(wwin
, data
, newX
, newY
);
1291 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1293 #define MOVABLE_BIT 0x01
1294 #define RESIZABLE_BIT 0x02
1297 wKeyboardMoveResizeWindow(WWindow
*wwin
)
1299 WScreen
*scr
= wwin
->screen_ptr
;
1300 Window root
= scr
->root_win
;
1302 int w
= wwin
->frame
->core
->width
;
1303 int h
= wwin
->frame
->core
->height
;
1304 int scr_width
= wwin
->screen_ptr
->scr_width
;
1305 int scr_height
= wwin
->screen_ptr
->scr_height
;
1306 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1307 int src_x
= wwin
->frame_x
;
1308 int src_y
= wwin
->frame_y
;
1309 int done
,off_x
,off_y
,ww
,wh
;
1312 KeyCode shiftl
, shiftr
, ctrll
, ctrlmode
;
1313 KeySym keysym
=NoSymbol
;
1315 int modes
= ((IS_MOVABLE(wwin
) ? MOVABLE_BIT
: 0) |
1316 (IS_RESIZABLE(wwin
) ? RESIZABLE_BIT
: 0));
1317 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
)>1)
1318 ? wGetHeadForWindow(wwin
)
1319 : scr
->xine_info
.primary_head
);
1321 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1322 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1323 ctrll
= XKeysymToKeycode(dpy
, XK_Control_L
);
1324 ctrlmode
=done
=off_x
=off_y
=0;
1326 if (modes
== RESIZABLE_BIT
) {
1332 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1334 if (!wwin
->flags
.selected
) {
1335 wUnselectWindows(scr
);
1338 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1339 |ButtonReleaseMask
|ButtonPressMask
, GrabModeAsync
,
1340 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
);
1342 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1343 if(scr
->selected_windows
)
1344 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1345 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1346 if(!scr
->selected_windows
)
1347 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1349 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1359 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1360 | ButtonPressMask
| ExposureMask
, &event
);
1361 if (event
.type
== Expose
) {
1362 WMHandleEvent(&event
);
1364 } while (event
.type
== Expose
);
1367 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1368 if(scr
->selected_windows
)
1369 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1370 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1371 /*** I HATE EDGE RESISTANCE - ]d ***/
1374 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1378 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1383 switch (event
.type
) {
1386 if (event
.xkey
.time
- lastTime
> 50) {
1387 kspeed
/=(1 + (event
.xkey
.time
- lastTime
)/100);
1393 if (kspeed
< _KS
) kspeed
= _KS
;
1394 lastTime
= event
.xkey
.time
;
1395 if (modes
== (MOVABLE_BIT
|RESIZABLE_BIT
)) {
1396 if ((event
.xkey
.state
& ControlMask
) && !wwin
->flags
.shaded
) {
1398 wUnselectWindows(scr
);
1404 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
) {
1406 cycleGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
, 0);
1408 cyclePositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1412 keysym
= XLookupKeysym(&event
.xkey
, 0);
1467 if (moment
!= RIGHT
)
1478 wWindowConstrainSize(wwin
, &ww
, &wh
);
1481 if (wPreferences
.ws_cycle
){
1482 if (src_x
+ off_x
+ ww
< 20){
1483 if(!scr
->current_workspace
) {
1484 wWorkspaceChange(scr
, scr
->workspace_count
-1);
1486 else wWorkspaceChange(scr
, scr
->current_workspace
-1);
1489 else if (src_x
+ off_x
+ 20 > scr_width
){
1490 if(scr
->current_workspace
== scr
->workspace_count
-1) {
1491 wWorkspaceChange(scr
, 0);
1493 else wWorkspaceChange(scr
, scr
->current_workspace
+1);
1498 if (src_x
+ off_x
+ ww
< 20)
1499 off_x
= 20 - ww
- src_x
;
1500 else if (src_x
+ off_x
+ 20 > scr_width
)
1501 off_x
= scr_width
- 20 - src_x
;
1504 if (src_y
+ off_y
+ wh
< 20) {
1505 off_y
= 20 - wh
- src_y
;
1507 else if (src_y
+ off_y
+ 20 > scr_height
) {
1508 off_y
= scr_height
- 20 - src_y
;
1517 WMHandleEvent(&event
);
1518 while (XCheckTypedEvent(dpy
, Expose
, &event
)) {
1519 WMHandleEvent(&event
);
1524 WMHandleEvent(&event
);
1531 if (wwin
->flags
.shaded
&& !scr
->selected_windows
){
1532 moveGeometryDisplayCentered(scr
, src_x
+off_x
+ w
/2, src_y
+off_y
+ h
/2);
1535 WMUnmapWidget(scr
->gview
);
1536 mapGeometryDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1537 } else if(!scr
->selected_windows
) {
1538 WMUnmapWidget(scr
->gview
);
1539 mapPositionDisplay(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1543 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1544 if (scr
->selected_windows
)
1545 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1547 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1549 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1554 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1555 } else if(!scr
->selected_windows
)
1556 showPosition(wwin
, src_x
+off_x
, src_y
+off_y
);
1560 scr
->keymove_tick
=0;
1562 WMDeleteTimerWithClientData(&looper);
1564 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1565 if(scr
->selected_windows
)
1566 drawFrames(wwin
,scr
->selected_windows
,off_x
,off_y
);
1567 else drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, w
, h
);
1570 drawTransparentFrame(wwin
, src_x
+off_x
, src_y
+off_y
, ww
, wh
);
1574 showGeometry(wwin
, src_x
+off_x
, src_y
+off_y
, src_x
+off_x
+ww
, src_y
+off_y
+wh
,0);
1575 WMUnmapWidget(scr
->gview
);
1577 WMUnmapWidget(scr
->gview
);
1579 XUngrabKeyboard(dpy
, CurrentTime
);
1580 XUngrabPointer(dpy
, CurrentTime
);
1584 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1585 if (!scr
->selected_windows
) {
1586 wWindowMove(wwin
, src_x
+off_x
, src_y
+off_y
);
1587 wWindowSynthConfigureNotify(wwin
);
1589 WMArrayIterator iter
;
1592 doWindowMove(wwin
, scr
->selected_windows
, off_x
, off_y
);
1594 WM_ITERATE_ARRAY(scr
->selected_windows
, foo
, iter
) {
1595 wWindowSynthConfigureNotify(foo
);
1599 if (wwin
->client
.width
!= ww
)
1600 wwin
->flags
.user_changed_width
= 1;
1602 if (wwin
->client
.height
!= wh
- vert_border
)
1603 wwin
->flags
.user_changed_height
= 1;
1605 wWindowConfigure(wwin
, src_x
+off_x
, src_y
+off_y
,
1606 ww
, wh
- vert_border
);
1607 wWindowSynthConfigureNotify(wwin
);
1609 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1610 wSetFocusTo(scr
, wwin
);
1613 if (wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
)>1 &&
1614 head
!= wGetHeadForWindow(wwin
)) {
1615 wArrangeIcons(scr
, True
);
1619 #if defined(NETWM_HINTS) && defined(VIRTUAL_DESKTOP)
1620 wWorkspaceResizeViewPort(scr
, scr
->current_workspace
);
1630 *----------------------------------------------------------------------
1631 * wMouseMoveWindow--
1632 * Move the named window and the other selected ones (if any),
1633 * interactively. Also shows the position of the window, if only one
1634 * window is being moved.
1635 * If the window is not on the selected window list, the selected
1636 * windows are deselected.
1637 * If shift is pressed during the operation, the position display
1638 * is changed to another type.
1641 * True if the window was moved, False otherwise.
1644 * The window(s) position is changed, and the client(s) are
1645 * notified about that.
1646 * The position display configuration may be changed.
1647 *----------------------------------------------------------------------
1650 wMouseMoveWindow(WWindow
*wwin
, XEvent
*ev
)
1652 WScreen
*scr
= wwin
->screen_ptr
;
1654 Window root
= scr
->root_win
;
1655 KeyCode shiftl
, shiftr
;
1659 /* This needs not to change while moving, else bad things can happen */
1660 int opaqueMove
= wPreferences
.opaque_move
;
1662 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1663 ? wGetHeadForWindow(wwin
)
1664 : scr
->xine_info
.primary_head
);
1665 #ifdef GHOST_WINDOW_MOVE
1666 RImage
*rimg
= InitGhostWindowMove(scr
);
1669 if (!IS_MOVABLE(wwin
))
1672 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1673 XSetWindowAttributes attr
;
1675 attr
.save_under
= True
;
1676 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
,
1677 CWSaveUnder
, &attr
);
1681 initMoveData(wwin
, &moveData
);
1683 moveData
.mouseX
= ev
->xmotion
.x_root
;
1684 moveData
.mouseY
= ev
->xmotion
.y_root
;
1686 if (!wwin
->flags
.selected
) {
1687 /* this window is not selected, unselect others and move only wwin */
1688 wUnselectWindows(scr
);
1691 puts("Moving window");
1693 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1694 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1700 /* XWarpPointer() doesn't seem to generate Motion events, so
1701 * we've got to simulate them */
1702 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1703 &event
.xmotion
.y_root
, &junk
, &junk
,
1704 (unsigned *) &junk
);
1706 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1707 | PointerMotionHintMask
1708 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
,
1711 if (event
.type
== MotionNotify
) {
1712 /* compress MotionNotify events */
1713 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1714 if (!checkMouseSamplingRate(&event
))
1718 switch (event
.type
) {
1720 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1721 && started
&& !scr
->selected_windows
) {
1724 drawFrames(wwin
, scr
->selected_windows
,
1725 moveData
.realX
- wwin
->frame_x
,
1726 moveData
.realY
- wwin
->frame_y
);
1729 if (wPreferences
.move_display
== WDIS_NEW
1730 && !scr
->selected_windows
) {
1731 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1734 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1735 moveData
.winWidth
, moveData
.winHeight
);
1737 if (wPreferences
.move_display
== WDIS_NEW
1738 && !scr
->selected_windows
) {
1740 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1744 drawFrames(wwin
, scr
->selected_windows
,
1745 moveData
.realX
- wwin
->frame_x
,
1746 moveData
.realY
- wwin
->frame_y
);
1749 WMHandleEvent(&event); this causes problems needs fixing */
1755 updateWindowPosition(wwin
, &moveData
,
1756 scr
->selected_windows
== NULL
1757 && wPreferences
.edge_resistance
> 0,
1759 event
.xmotion
.x_root
,
1760 event
.xmotion
.y_root
);
1762 if (!warped
&& !wPreferences
.no_autowrap
) {
1763 int oldWorkspace
= scr
->current_workspace
;
1765 if (wPreferences
.move_display
== WDIS_NEW
1766 && !scr
->selected_windows
) {
1767 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1771 drawFrames(wwin
, scr
->selected_windows
,
1772 moveData
.realX
- wwin
->frame_x
,
1773 moveData
.realY
- wwin
->frame_y
);
1775 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1776 if (scr
->current_workspace
!= oldWorkspace
1777 && wPreferences
.edge_resistance
> 0
1778 && scr
->selected_windows
== NULL
)
1779 updateMoveData(wwin
, &moveData
);
1783 drawFrames(wwin
, scr
->selected_windows
,
1784 moveData
.realX
- wwin
->frame_x
,
1785 moveData
.realY
- wwin
->frame_y
);
1787 if (wPreferences
.move_display
== WDIS_NEW
1788 && !scr
->selected_windows
) {
1790 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1796 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1797 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1799 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1800 | ButtonReleaseMask
| ButtonPressMask
,
1801 wCursor
[WCUR_MOVE
], CurrentTime
);
1803 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
1806 if (!scr
->selected_windows
)
1807 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1808 moveData
.winWidth
, moveData
.winHeight
);
1810 if (started
&& !opaqueMove
)
1811 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1813 if (!opaqueMove
|| (wPreferences
.move_display
==WDIS_NEW
1814 && !scr
->selected_windows
)) {
1816 if (wPreferences
.move_display
==WDIS_NEW
)
1817 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1826 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1832 drawFrames(wwin
, scr
->selected_windows
,
1833 moveData
.realX
- wwin
->frame_x
,
1834 moveData
.realY
- wwin
->frame_y
);
1836 doWindowMove(wwin
, scr
->selected_windows
,
1837 moveData
.realX
- wwin
->frame_x
,
1838 moveData
.realY
- wwin
->frame_y
);
1840 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1841 wWindowSynthConfigureNotify(wwin
);
1843 XUngrabKeyboard(dpy
, CurrentTime
);
1846 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1847 wSetFocusTo(scr
, wwin
);
1849 if (wPreferences
.move_display
== WDIS_NEW
)
1850 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1852 /* discard all enter/leave events that happened until
1853 * the time the button was released */
1854 while (XCheckTypedEvent(dpy
, EnterNotify
, &e
)) {
1855 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1856 XPutBackEvent(dpy
, &e
);
1860 while (XCheckTypedEvent(dpy
, LeaveNotify
, &e
)) {
1861 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1862 XPutBackEvent(dpy
, &e
);
1867 if (!scr
->selected_windows
) {
1868 /* get rid of the geometry window */
1869 WMUnmapWidget(scr
->gview
);
1873 puts("End move window");
1879 if (started
&& !opaqueMove
) {
1880 drawFrames(wwin
, scr
->selected_windows
,
1881 moveData
.realX
- wwin
->frame_x
,
1882 moveData
.realY
- wwin
->frame_y
);
1884 WMHandleEvent(&event
);
1887 drawFrames(wwin
, scr
->selected_windows
,
1888 moveData
.realX
- wwin
->frame_x
,
1889 moveData
.realY
- wwin
->frame_y
);
1891 WMHandleEvent(&event
);
1897 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1898 XSetWindowAttributes attr
;
1900 attr
.save_under
= False
;
1901 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
,
1902 CWSaveUnder
, &attr
);
1906 freeMoveData(&moveData
);
1908 if (started
&& wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
)>1 &&
1909 head
!= wGetHeadForWindow(wwin
)) {
1910 wArrangeIcons(scr
, True
);
1913 #if defined(NETWM_HINTS) && defined(VIRTUAL_DESKTOP)
1915 wWorkspaceResizeViewPort(scr
, scr
->current_workspace
);
1923 #define HCONSTRAIN 2
1926 getResizeDirection(WWindow
*wwin
, int x
, int y
, int dx
, int dy
,
1929 int w
= wwin
->frame
->core
->width
- 1;
1930 int cw
= wwin
->frame
->resizebar_corner_width
;
1933 /* if not resizing through the resizebar */
1934 if (!(flags
& RESIZEBAR
)) {
1935 int xdir
= (abs(x
) < (wwin
->client
.width
/2)) ? LEFT
: RIGHT
;
1936 int ydir
= (abs(y
) < (wwin
->client
.height
/2)) ? UP
: DOWN
;
1937 if (abs(dx
) < 2 || abs(dy
) < 2) {
1938 if (abs(dy
) > abs(dx
))
1943 return (xdir
| ydir
);
1946 /* window is too narrow. allow diagonal resize */
1950 if (flags
& HCONSTRAIN
)
1955 return (LEFT
| ydir
);
1957 return (RIGHT
| ydir
);
1959 /* vertical resize */
1960 if ((x
> cw
) && (x
< w
- cw
))
1968 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1976 wMouseResizeWindow(WWindow
*wwin
, XEvent
*ev
)
1979 WScreen
*scr
= wwin
->screen_ptr
;
1980 Window root
= scr
->root_win
;
1981 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1982 int fw
= wwin
->frame
->core
->width
;
1983 int fh
= wwin
->frame
->core
->height
;
1984 int fx
= wwin
->frame_x
;
1985 int fy
= wwin
->frame_y
;
1986 int is_resizebar
= (wwin
->frame
->resizebar
1987 && ev
->xany
.window
==wwin
->frame
->resizebar
->window
);
1991 int rw
= fw
, rh
= fh
;
1992 int rx1
, ry1
, rx2
, ry2
;
1994 KeyCode shiftl
, shiftr
;
2000 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
)>1)
2001 ? wGetHeadForWindow(wwin
)
2002 : scr
->xine_info
.primary_head
);
2004 if (!IS_RESIZABLE(wwin
))
2007 if (wwin
->flags
.shaded
) {
2008 wwarning("internal error: tryein");
2011 orig_x
= ev
->xbutton
.x_root
;
2012 orig_y
= ev
->xbutton
.y_root
;
2016 puts("Resizing window");
2019 wUnselectWindows(scr
);
2024 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2025 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2026 if (HAS_TITLEBAR(wwin
))
2027 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + (wPreferences
.window_title_clearance
+ TITLEBAR_EXTEND_SPACE
) * 2;
2031 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
2032 | ButtonReleaseMask
| PointerMotionHintMask
2033 | ButtonPressMask
| ExposureMask
, &event
);
2034 if (!checkMouseSamplingRate(&event
))
2037 switch (event
.type
) {
2039 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2040 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
2042 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2043 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
2044 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2046 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2051 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
2062 dw
= orig_x
- event
.xmotion
.x_root
;
2063 else if (res
& RIGHT
)
2064 dw
= event
.xmotion
.x_root
- orig_x
;
2066 dh
= orig_y
- event
.xmotion
.y_root
;
2067 else if (res
& DOWN
)
2068 dh
= event
.xmotion
.y_root
- orig_y
;
2070 orig_x
= event
.xmotion
.x_root
;
2071 orig_y
= event
.xmotion
.y_root
;
2076 fh
= rh
- vert_border
;
2077 wWindowConstrainSize(wwin
, &fw
, &fh
);
2081 else if (res
& RIGHT
)
2085 else if (res
& DOWN
)
2087 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
2088 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
2093 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
2094 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
2096 /* check if resizing through resizebar */
2102 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
2103 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
2104 flags
|= HCONSTRAIN
;
2106 res
= getResizeDirection(wwin
, tx
, ty
,
2107 orig_x
- event
.xmotion
.x_root
,
2108 orig_y
- event
.xmotion
.y_root
, flags
);
2110 if (res
== (UP
|LEFT
))
2111 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2112 | ButtonReleaseMask
| ButtonPressMask
,
2113 wCursor
[WCUR_TOPLEFTRESIZE
], CurrentTime
);
2114 else if (res
== (UP
|RIGHT
))
2115 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2116 | ButtonReleaseMask
| ButtonPressMask
,
2117 wCursor
[WCUR_TOPRIGHTRESIZE
], CurrentTime
);
2118 else if (res
== (DOWN
|LEFT
))
2119 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2120 | ButtonReleaseMask
| ButtonPressMask
,
2121 wCursor
[WCUR_BOTTOMLEFTRESIZE
], CurrentTime
);
2122 else if (res
== (DOWN
|RIGHT
))
2123 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2124 | ButtonReleaseMask
| ButtonPressMask
,
2125 wCursor
[WCUR_BOTTOMRIGHTRESIZE
], CurrentTime
);
2126 else if (res
== DOWN
|| res
== UP
)
2127 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2128 | ButtonReleaseMask
| ButtonPressMask
,
2129 wCursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2130 else if (res
& (DOWN
|UP
))
2131 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2132 | ButtonReleaseMask
| ButtonPressMask
,
2133 wCursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2134 else if (res
& (LEFT
|RIGHT
))
2135 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2136 | ButtonReleaseMask
| ButtonPressMask
,
2137 wCursor
[WCUR_HORIZONRESIZE
], CurrentTime
);
2139 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
,
2144 /* Draw the resize frame for the first time. */
2145 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
2147 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2149 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2154 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
2155 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
2157 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
2158 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2160 drawTransparentFrame(wwin
, orig_fx
, orig_fy
,
2162 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2164 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
2165 if (wPreferences
.size_display
== WDIS_NEW
) {
2166 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
2167 orig_fy
+ orig_fh
, res
);
2169 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2178 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2182 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2184 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2186 XUngrabKeyboard(dpy
, CurrentTime
);
2187 WMUnmapWidget(scr
->gview
);
2190 if (wwin
->client
.width
!= fw
)
2191 wwin
->flags
.user_changed_width
= 1;
2193 if (wwin
->client
.height
!= fh
- vert_border
)
2194 wwin
->flags
.user_changed_height
= 1;
2196 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
2199 puts("End resize window");
2204 WMHandleEvent(&event
);
2208 if (wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 &&
2209 head
!= wGetHeadForWindow(wwin
)) {
2210 wArrangeIcons(scr
, True
);
2213 #if defined(NETWM_HINTS) && defined(VIRTUAL_DESKTOP)
2214 wWorkspaceResizeViewPort(scr
, scr
->current_workspace
);
2228 wUnselectWindows(WScreen
*scr
)
2232 if (!scr
->selected_windows
)
2235 while (WMGetArrayItemCount(scr
->selected_windows
)) {
2236 wwin
= WMGetFromArray(scr
->selected_windows
, 0);
2237 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
2238 wIconSelect(wwin
->icon
);
2240 wSelectWindow(wwin
, False
);
2242 WMFreeArray(scr
->selected_windows
);
2243 scr
->selected_windows
= NULL
;
2248 selectWindowsInside(WScreen
*scr
, int x1
, int y1
, int x2
, int y2
)
2252 /* select the windows and put them in the selected window list */
2253 tmpw
= scr
->focused_window
;
2254 while (tmpw
!= NULL
) {
2255 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
2256 if ((tmpw
->frame
->workspace
== scr
->current_workspace
2257 || IS_OMNIPRESENT(tmpw
))
2258 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
2259 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
2260 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
2261 wSelectWindow(tmpw
, True
);
2270 wSelectWindows(WScreen
*scr
, XEvent
*ev
)
2273 Window root
= scr
->root_win
;
2274 GC gc
= scr
->frame_gc
;
2275 int xp
= ev
->xbutton
.x_root
;
2276 int yp
= ev
->xbutton
.y_root
;
2281 puts("Selecting windows");
2283 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
2284 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
2285 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
],
2286 CurrentTime
) != Success
) {
2291 wUnselectWindows(scr
);
2293 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
2295 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
2296 | ButtonPressMask
, &event
);
2298 switch (event
.type
) {
2300 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2301 x
= event
.xmotion
.x_root
;
2308 y
= event
.xmotion
.y_root
;
2315 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2322 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2325 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2327 XUngrabPointer(dpy
, CurrentTime
);
2328 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
2331 wKWMSelectRootRegion(scr
, xp
, yp
, w
, h
,
2332 event
.xbutton
.state
& ControlMask
);
2333 #endif /* KWM_HINTS */
2336 puts("End window selection");
2341 WMHandleEvent(&event
);
2349 InteractivePlaceWindow(WWindow
*wwin
, int *x_ret
, int *y_ret
,
2350 unsigned width
, unsigned height
)
2352 WScreen
*scr
= wwin
->screen_ptr
;
2353 Window root
= scr
->root_win
;
2356 KeyCode shiftl
, shiftr
;
2360 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2361 GrabModeAsync
, GrabModeAsync
, None
,
2362 wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2367 if (HAS_TITLEBAR(wwin
)) {
2368 h
= WMFontHeight(scr
->title_font
) + (wPreferences
.window_title_clearance
+ TITLEBAR_EXTEND_SPACE
) * 2;
2371 if (HAS_RESIZEBAR(wwin
)) {
2372 height
+= RESIZEBAR_HEIGHT
;
2374 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2375 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
,
2376 (unsigned *) &junk
);
2377 mapPositionDisplay(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2379 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2381 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2382 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2384 WMMaskEvent(dpy
, PointerMotionMask
|ButtonPressMask
|ExposureMask
|KeyPressMask
,
2387 if (!checkMouseSamplingRate(&event
))
2390 switch (event
.type
) {
2392 if ((event
.xkey
.keycode
== shiftl
)
2393 || (event
.xkey
.keycode
== shiftr
)) {
2394 drawTransparentFrame(wwin
,
2395 x
- width
/2, y
- h
/2, width
, height
);
2396 cyclePositionDisplay(wwin
,
2397 x
- width
/2, y
- h
/2, width
, height
);
2398 drawTransparentFrame(wwin
,
2399 x
- width
/2, y
- h
/2, width
, height
);
2404 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2406 x
= event
.xmotion
.x_root
;
2407 y
= event
.xmotion
.y_root
;
2409 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2410 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2412 showPosition(wwin
, x
- width
/2, y
- h
/2);
2414 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2419 drawTransparentFrame(wwin
, x
- width
/2, y
- h
/2, width
, height
);
2421 *x_ret
= x
- width
/2;
2423 XUngrabPointer(dpy
, CurrentTime
);
2424 XUngrabKeyboard(dpy
, CurrentTime
);
2425 /* get rid of the geometry window */
2426 WMUnmapWidget(scr
->gview
);
2430 WMHandleEvent(&event
);