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>
49 /* How many different types of geometry/position
50 display thingies are there? */
51 #define NUM_DISPLAYS 5
55 #define HORIZONTAL (LEFT|RIGHT)
58 #define VERTICAL (UP|DOWN)
60 /* True if window currently has a border. This also includes borderless
61 * windows which are currently selected
63 #define HAS_BORDER_WITH_SELECT(w) ((w)->flags.selected || HAS_BORDER(w))
65 /****** Global Variables ******/
66 extern Time LastTimestamp
;
68 extern Cursor wCursor
[WCUR_LAST
];
70 extern WPreferences wPreferences
;
72 extern Atom _XA_WM_PROTOCOLS
;
75 *----------------------------------------------------------------------
76 * checkMouseSamplingRate-
77 * For lowering the mouse motion sampling rate for machines where
78 * it's too high (SGIs). If it returns False then the event should be
80 *----------------------------------------------------------------------
82 static Bool
checkMouseSamplingRate(XEvent
* ev
)
84 static Time previousMotion
= 0;
86 if (ev
->type
== MotionNotify
) {
87 if (ev
->xmotion
.time
- previousMotion
< DELAY_BETWEEN_MOUSE_SAMPLING
) {
90 previousMotion
= ev
->xmotion
.time
;
97 *----------------------------------------------------------------------
98 * moveGeometryDisplayCentered
100 * routine that moves the geometry/position window on scr so it is
101 * centered over the given coordinates (x,y). Also the window position
102 * is clamped so it stays on the screen at all times.
103 *----------------------------------------------------------------------
105 static void moveGeometryDisplayCentered(WScreen
* scr
, int x
, int y
)
107 unsigned int w
= WMWidgetWidth(scr
->gview
);
108 unsigned int h
= WMWidgetHeight(scr
->gview
);
109 int x1
= 0, y1
= 0, x2
= scr
->scr_width
, y2
= scr
->scr_height
;
114 /* dead area check */
115 if (scr
->xine_info
.count
) {
122 rect
.size
.height
= h
;
124 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
126 if (flags
& (XFLAG_DEAD
| XFLAG_PARTIAL
)) {
127 rect
= wGetRectForHead(scr
, head
);
130 x2
= x1
+ rect
.size
.width
;
131 y2
= y1
+ rect
.size
.height
;
137 else if (x
> (x2
- w
))
142 else if (y
> (y2
- h
))
145 WMMoveWidget(scr
->gview
, x
, y
);
148 static void showPosition(WWindow
* wwin
, int x
, int y
)
150 WScreen
*scr
= wwin
->screen_ptr
;
152 if (wPreferences
.move_display
== WDIS_NEW
) {
154 int width
= wwin
->frame
->core
->width
;
155 int height
= wwin
->frame
->core
->height
;
157 GC lgc
= scr
->line_gc
;
158 XSetForeground(dpy
, lgc
, scr
->line_pixel
);
159 sprintf(num
, "%i", x
);
161 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
- 1, scr
->scr_width
, y
- 1);
162 XDrawLine(dpy
, scr
->root_win
, lgc
, 0, y
+ height
+ 2, scr
->scr_width
, y
+ height
+ 2);
163 XDrawLine(dpy
, scr
->root_win
, lgc
, x
- 1, 0, x
- 1, scr
->scr_height
);
164 XDrawLine(dpy
, scr
->root_win
, lgc
, x
+ width
+ 2, 0, x
+ width
+ 2, scr
->scr_height
);
167 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
171 static void cyclePositionDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
)
173 WScreen
*scr
= wwin
->screen_ptr
;
176 wPreferences
.move_display
++;
177 wPreferences
.move_display
%= NUM_DISPLAYS
;
179 if (wPreferences
.move_display
== WDIS_NEW
) {
180 wPreferences
.move_display
++;
181 wPreferences
.move_display
%= NUM_DISPLAYS
;
184 if (wPreferences
.move_display
== WDIS_NONE
) {
185 WMUnmapWidget(scr
->gview
);
187 if (wPreferences
.move_display
== WDIS_CENTER
) {
188 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
189 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
190 rect
.pos
.y
+ rect
.size
.height
/ 2);
191 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
192 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
193 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
194 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
195 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
197 WMMapWidget(scr
->gview
);
201 static void mapPositionDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
)
203 WScreen
*scr
= wwin
->screen_ptr
;
206 if (wPreferences
.move_display
== WDIS_NEW
|| wPreferences
.move_display
== WDIS_NONE
) {
208 } else if (wPreferences
.move_display
== WDIS_CENTER
) {
209 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
210 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
211 rect
.pos
.y
+ rect
.size
.height
/ 2);
212 } else if (wPreferences
.move_display
== WDIS_TOPLEFT
) {
213 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
214 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
215 } else if (wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
216 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
218 WMMapWidget(scr
->gview
);
219 WSetGeometryViewShownPosition(scr
->gview
, x
, y
);
222 static void showGeometry(WWindow
* wwin
, int x1
, int y1
, int x2
, int y2
, int direction
)
224 WScreen
*scr
= wwin
->screen_ptr
;
225 Window root
= scr
->root_win
;
226 GC gc
= scr
->line_gc
;
227 int ty
, by
, my
, x
, y
, mx
, s
;
232 /* This seems necessary for some odd reason (too lazy to write x1-1 and
233 * x2-1 everywhere below in the code). But why only for x? */
237 if (HAS_BORDER_WITH_SELECT(wwin
)) {
238 x1
+= FRAME_BORDER_WIDTH
;
239 x2
+= FRAME_BORDER_WIDTH
;
240 y1
+= FRAME_BORDER_WIDTH
;
241 y2
+= FRAME_BORDER_WIDTH
;
244 ty
= y1
+ wwin
->frame
->top_width
;
245 by
= y2
- wwin
->frame
->bottom_width
;
247 if (wPreferences
.size_display
== WDIS_NEW
) {
248 fw
= XTextWidth(scr
->tech_draw_font
, "8888", 4);
249 fh
= scr
->tech_draw_font
->ascent
+ scr
->tech_draw_font
->descent
;
251 XSetForeground(dpy
, gc
, scr
->line_pixel
);
253 /* vertical geometry */
254 if (((direction
& LEFT
) && (x2
< scr
->scr_width
- fw
)) || (x1
< fw
)) {
263 /* top arrow & end bar */
264 segment
[0].x1
= x
- (s
+ 6);
266 segment
[0].x2
= x
- (s
- 10);
270 segment
[1].x1
= x
- (s
- 2);
271 segment
[1].y1
= ty
+ 1;
272 segment
[1].x2
= x
- (s
- 5);
273 segment
[1].y2
= ty
+ 7;
275 segment
[2].x1
= x
- (s
- 2);
276 segment
[2].y1
= ty
+ 1;
277 segment
[2].x2
= x
- (s
+ 1);
278 segment
[2].y2
= ty
+ 7;
281 segment
[3].x1
= x
- (s
- 2);
282 segment
[3].y1
= ty
+ 1;
283 segment
[3].x2
= x
- (s
- 2);
284 segment
[3].y2
= my
- fh
/ 2 - 1;
286 XDrawSegments(dpy
, root
, gc
, segment
, 4);
288 /* bottom arrow & end bar */
293 segment
[1].y1
= by
- 1;
294 segment
[1].y2
= by
- 7;
296 segment
[2].y1
= by
- 1;
297 segment
[2].y2
= by
- 7;
300 segment
[3].y1
= my
+ fh
/ 2 + 2;
301 segment
[3].y2
= by
- 1;
303 XDrawSegments(dpy
, root
, gc
, segment
, 4);
305 snprintf(num
, sizeof(num
), "%i", (by
- ty
- wwin
->normal_hints
->base_height
) /
306 wwin
->normal_hints
->height_inc
);
307 fw
= XTextWidth(scr
->tech_draw_font
, num
, strlen(num
));
309 /* Display the height. */
310 XSetFont(dpy
, gc
, scr
->tech_draw_font
->fid
);
311 XDrawString(dpy
, root
, gc
, x
- s
+ 3 - fw
/ 2, my
+ scr
->tech_draw_font
->ascent
- fh
/ 2 + 1, num
,
314 /* horizontal geometry */
322 mx
= x1
+ (x2
- x1
) / 2;
323 snprintf(num
, sizeof(num
), "%i", (x2
- x1
- wwin
->normal_hints
->base_width
) /
324 wwin
->normal_hints
->width_inc
);
325 fw
= XTextWidth(scr
->tech_draw_font
, num
, strlen(num
));
327 /* left arrow & end bar */
329 segment
[0].y1
= y
- (s
+ 6);
331 segment
[0].y2
= y
- (s
- 10);
334 segment
[1].x1
= x1
+ 7;
335 segment
[1].y1
= y
- (s
+ 1);
336 segment
[1].x2
= x1
+ 1;
337 segment
[1].y2
= y
- (s
- 2);
339 segment
[2].x1
= x1
+ 1;
340 segment
[2].y1
= y
- (s
- 2);
341 segment
[2].x2
= x1
+ 7;
342 segment
[2].y2
= y
- (s
- 5);
345 segment
[3].x1
= x1
+ 1;
346 segment
[3].y1
= y
- (s
- 2);
347 segment
[3].x2
= mx
- fw
/ 2 - 2;
348 segment
[3].y2
= y
- (s
- 2);
350 XDrawSegments(dpy
, root
, gc
, segment
, 4);
352 /* right arrow & end bar */
353 segment
[0].x1
= x2
+ 1;
354 segment
[0].x2
= x2
+ 1;
357 segment
[1].x1
= x2
- 6;
361 segment
[2].x2
= x2
- 6;
364 segment
[3].x1
= mx
+ fw
/ 2 + 2;
367 XDrawSegments(dpy
, root
, gc
, segment
, 4);
369 /* Display the width. */
370 XDrawString(dpy
, root
, gc
, mx
- fw
/ 2 + 1, y
- s
+ scr
->tech_draw_font
->ascent
- fh
/ 2 + 1, num
,
373 WSetGeometryViewShownSize(scr
->gview
, (x2
- x1
- wwin
->normal_hints
->base_width
)
374 / wwin
->normal_hints
->width_inc
,
375 (by
- ty
- wwin
->normal_hints
->base_height
)
376 / wwin
->normal_hints
->height_inc
);
380 static void cycleGeometryDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
, int dir
)
382 WScreen
*scr
= wwin
->screen_ptr
;
385 wPreferences
.size_display
++;
386 wPreferences
.size_display
%= NUM_DISPLAYS
;
388 if (wPreferences
.size_display
== WDIS_NEW
|| wPreferences
.size_display
== WDIS_NONE
) {
389 WMUnmapWidget(scr
->gview
);
391 if (wPreferences
.size_display
== WDIS_CENTER
) {
392 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
393 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
394 rect
.pos
.y
+ rect
.size
.height
/ 2);
395 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
396 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
397 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
398 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
399 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
401 WMMapWidget(scr
->gview
);
402 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, dir
);
406 static void mapGeometryDisplay(WWindow
* wwin
, int x
, int y
, int w
, int h
)
408 WScreen
*scr
= wwin
->screen_ptr
;
411 if (wPreferences
.size_display
== WDIS_NEW
|| wPreferences
.size_display
== WDIS_NONE
)
414 if (wPreferences
.size_display
== WDIS_CENTER
) {
415 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
416 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2,
417 rect
.pos
.y
+ rect
.size
.height
/ 2);
418 } else if (wPreferences
.size_display
== WDIS_TOPLEFT
) {
419 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
420 moveGeometryDisplayCentered(scr
, rect
.pos
.x
+ 1, rect
.pos
.y
+ 1);
421 } else if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
422 moveGeometryDisplayCentered(scr
, x
+ w
/ 2, y
+ h
/ 2);
424 WMMapWidget(scr
->gview
);
425 showGeometry(wwin
, x
, y
, x
+ w
, y
+ h
, 0);
428 static void doWindowMove(WWindow
* wwin
, WMArray
* array
, int dx
, int dy
)
431 WScreen
*scr
= wwin
->screen_ptr
;
434 if (!array
|| !WMGetArrayItemCount(array
)) {
435 wWindowMove(wwin
, wwin
->frame_x
+ dx
, wwin
->frame_y
+ dy
);
437 WMArrayIterator iter
;
439 WM_ITERATE_ARRAY(array
, tmpw
, iter
) {
440 x
= tmpw
->frame_x
+ dx
;
441 y
= tmpw
->frame_y
+ dy
;
443 #if 1 /* XXX: with xinerama patch was #if 0, check this */
444 /* don't let windows become unreachable */
446 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
447 x
= 20 - (int)tmpw
->frame
->core
->width
;
448 else if (x
+ 20 > scr
->scr_width
)
449 x
= scr
->scr_width
- 20;
451 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
452 y
= 20 - (int)tmpw
->frame
->core
->height
;
453 else if (y
+ 20 > scr
->scr_height
)
454 y
= scr
->scr_height
- 20;
456 wScreenBringInside(scr
, &x
, &y
,
457 (int)tmpw
->frame
->core
->width
, (int)tmpw
->frame
->core
->height
);
460 wWindowMove(tmpw
, x
, y
);
465 static void drawTransparentFrame(WWindow
* wwin
, int x
, int y
, int width
, int height
)
467 Window root
= wwin
->screen_ptr
->root_win
;
468 GC gc
= wwin
->screen_ptr
->frame_gc
;
472 if (HAS_BORDER_WITH_SELECT(wwin
)) {
473 x
+= FRAME_BORDER_WIDTH
;
474 y
+= FRAME_BORDER_WIDTH
;
477 if (HAS_TITLEBAR(wwin
) && !wwin
->flags
.shaded
) {
478 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + (wPreferences
.window_title_clearance
+
479 TITLEBAR_EXTEND_SPACE
) * 2;
481 if (HAS_RESIZEBAR(wwin
) && !wwin
->flags
.shaded
) {
482 /* Can't use wwin-frame->bottom_width because, in some cases
483 (e.g. interactive placement), frame does not point to anything. */
484 bottom
= RESIZEBAR_HEIGHT
;
486 XDrawRectangle(dpy
, root
, gc
, x
- 1, y
- 1, width
+ 1, height
+ 1);
489 XDrawLine(dpy
, root
, gc
, x
, y
+ h
- 1, x
+ width
, y
+ h
- 1);
492 XDrawLine(dpy
, root
, gc
, x
, y
+ height
- bottom
, x
+ width
, y
+ height
- bottom
);
496 static void drawFrames(WWindow
* wwin
, WMArray
* array
, int dx
, int dy
)
499 int scr_width
= wwin
->screen_ptr
->scr_width
;
500 int scr_height
= wwin
->screen_ptr
->scr_height
;
505 x
= wwin
->frame_x
+ dx
;
506 y
= wwin
->frame_y
+ dy
;
508 drawTransparentFrame(wwin
, x
, y
, wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
511 WMArrayIterator iter
;
513 WM_ITERATE_ARRAY(array
, tmpw
, iter
) {
514 x
= tmpw
->frame_x
+ dx
;
515 y
= tmpw
->frame_y
+ dy
;
517 /* don't let windows become unreachable */
518 #if 1 /* XXX: was 0 in XINERAMA patch, check */
519 if (x
+ (int)tmpw
->frame
->core
->width
< 20)
520 x
= 20 - (int)tmpw
->frame
->core
->width
;
521 else if (x
+ 20 > scr_width
)
524 if (y
+ (int)tmpw
->frame
->core
->height
< 20)
525 y
= 20 - (int)tmpw
->frame
->core
->height
;
526 else if (y
+ 20 > scr_height
)
530 wScreenBringInside(wwin
->screen_ptr
, &x
, &y
,
531 (int)tmpw
->frame
->core
->width
, (int)tmpw
->frame
->core
->height
);
534 drawTransparentFrame(tmpw
, x
, y
, tmpw
->frame
->core
->width
, tmpw
->frame
->core
->height
);
539 static void flushMotion()
544 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &ev
)) ;
547 static void crossWorkspace(WScreen
* scr
, WWindow
* wwin
, int opaque_move
, int new_workspace
, int rewind
)
549 /* do not let window be unmapped */
551 wwin
->flags
.changing_workspace
= 1;
552 wWindowChangeWorkspace(wwin
, new_workspace
);
554 /* go to new workspace */
555 wWorkspaceChange(scr
, new_workspace
);
557 wwin
->flags
.changing_workspace
= 0;
560 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, scr
->scr_width
- 20, 0);
562 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, -(scr
->scr_width
- 20), 0);
567 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
568 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
569 GrabModeAsync
, None
, wCursor
[WCUR_MOVE
], CurrentTime
);
574 /* arrays of WWindows sorted by the respective border position */
575 WWindow
**topList
; /* top border */
576 WWindow
**leftList
; /* left border */
577 WWindow
**rightList
; /* right border */
578 WWindow
**bottomList
; /* bottom border */
581 /* index of window in the above lists indicating the relative position
582 * of the window with the others */
588 int rubCount
; /* for workspace switching */
590 int winWidth
, winHeight
; /* width/height of the window */
591 int realX
, realY
; /* actual position of the window */
592 int calcX
, calcY
; /* calculated position of window */
593 int omouseX
, omouseY
; /* old mouse position */
594 int mouseX
, mouseY
; /* last known position of the pointer */
597 #define WTOP(w) (w)->frame_y
598 #define WLEFT(w) (w)->frame_x
599 #define WRIGHT(w) ((w)->frame_x + (int)(w)->frame->core->width - 1 + \
600 (HAS_BORDER_WITH_SELECT(w) ? 2*FRAME_BORDER_WIDTH : 0))
601 #define WBOTTOM(w) ((w)->frame_y + (int)(w)->frame->core->height - 1 + \
602 (HAS_BORDER_WITH_SELECT(w) ? 2*FRAME_BORDER_WIDTH : 0))
604 static int compareWTop(const void *a
, const void *b
)
606 WWindow
*wwin1
= *(WWindow
**) a
;
607 WWindow
*wwin2
= *(WWindow
**) b
;
609 if (WTOP(wwin1
) > WTOP(wwin2
))
611 else if (WTOP(wwin1
) < WTOP(wwin2
))
617 static int compareWLeft(const void *a
, const void *b
)
619 WWindow
*wwin1
= *(WWindow
**) a
;
620 WWindow
*wwin2
= *(WWindow
**) b
;
622 if (WLEFT(wwin1
) > WLEFT(wwin2
))
624 else if (WLEFT(wwin1
) < WLEFT(wwin2
))
630 static int compareWRight(const void *a
, const void *b
)
632 WWindow
*wwin1
= *(WWindow
**) a
;
633 WWindow
*wwin2
= *(WWindow
**) b
;
635 if (WRIGHT(wwin1
) < WRIGHT(wwin2
))
637 else if (WRIGHT(wwin1
) > WRIGHT(wwin2
))
643 static int compareWBottom(const void *a
, const void *b
)
645 WWindow
*wwin1
= *(WWindow
**) a
;
646 WWindow
*wwin2
= *(WWindow
**) b
;
648 if (WBOTTOM(wwin1
) < WBOTTOM(wwin2
))
650 else if (WBOTTOM(wwin1
) > WBOTTOM(wwin2
))
656 static void updateResistance(WWindow
* wwin
, MoveData
* data
, int newX
, int newY
)
659 int newX2
= newX
+ data
->winWidth
;
660 int newY2
= newY
+ data
->winHeight
;
663 if (newX
< data
->realX
) {
664 if (data
->rightIndex
> 0 && newX
< WRIGHT(data
->rightList
[data
->rightIndex
- 1])) {
666 } else if (data
->leftIndex
<= data
->count
- 1 && newX2
<= WLEFT(data
->leftList
[data
->leftIndex
])) {
669 } else if (newX
> data
->realX
) {
670 if (data
->leftIndex
> 0 && newX2
> WLEFT(data
->leftList
[data
->leftIndex
- 1])) {
672 } else if (data
->rightIndex
<= data
->count
- 1
673 && newX
>= WRIGHT(data
->rightList
[data
->rightIndex
])) {
679 if (newY
< data
->realY
) {
680 if (data
->bottomIndex
> 0 && newY
< WBOTTOM(data
->bottomList
[data
->bottomIndex
- 1])) {
682 } else if (data
->topIndex
<= data
->count
- 1
683 && newY2
<= WTOP(data
->topList
[data
->topIndex
])) {
686 } else if (newY
> data
->realY
) {
687 if (data
->topIndex
> 0 && newY2
> WTOP(data
->topList
[data
->topIndex
- 1])) {
689 } else if (data
->bottomIndex
<= data
->count
- 1
690 && newY
>= WBOTTOM(data
->bottomList
[data
->bottomIndex
])) {
699 /* TODO: optimize this */
700 if (data
->realY
< WBOTTOM(data
->bottomList
[0])) {
701 data
->bottomIndex
= 0;
703 if (data
->realX
< WRIGHT(data
->rightList
[0])) {
704 data
->rightIndex
= 0;
706 if ((data
->realX
+ data
->winWidth
) > WLEFT(data
->leftList
[0])) {
709 if ((data
->realY
+ data
->winHeight
) > WTOP(data
->topList
[0])) {
712 for (i
= 0; i
< data
->count
; i
++) {
713 if (data
->realY
> WBOTTOM(data
->bottomList
[i
])) {
714 data
->bottomIndex
= i
+ 1;
716 if (data
->realX
> WRIGHT(data
->rightList
[i
])) {
717 data
->rightIndex
= i
+ 1;
719 if ((data
->realX
+ data
->winWidth
) < WLEFT(data
->leftList
[i
])) {
720 data
->leftIndex
= i
+ 1;
722 if ((data
->realY
+ data
->winHeight
) < WTOP(data
->topList
[i
])) {
723 data
->topIndex
= i
+ 1;
728 static void freeMoveData(MoveData
* data
)
731 wfree(data
->topList
);
733 wfree(data
->leftList
);
735 wfree(data
->rightList
);
736 if (data
->bottomList
)
737 wfree(data
->bottomList
);
740 static void updateMoveData(WWindow
* wwin
, MoveData
* data
)
742 WScreen
*scr
= wwin
->screen_ptr
;
747 tmp
= scr
->focused_window
;
749 if (tmp
!= wwin
&& scr
->current_workspace
== tmp
->frame
->workspace
750 && !tmp
->flags
.miniaturized
751 && !tmp
->flags
.hidden
&& !tmp
->flags
.obscured
&& !WFLAGP(tmp
, sunken
)) {
752 data
->topList
[data
->count
] = tmp
;
753 data
->leftList
[data
->count
] = tmp
;
754 data
->rightList
[data
->count
] = tmp
;
755 data
->bottomList
[data
->count
] = tmp
;
761 if (data
->count
== 0) {
764 data
->rightIndex
= 0;
765 data
->bottomIndex
= 0;
769 /* order from closest to the border of the screen to farthest */
771 qsort(data
->topList
, data
->count
, sizeof(WWindow
**), compareWTop
);
772 qsort(data
->leftList
, data
->count
, sizeof(WWindow
**), compareWLeft
);
773 qsort(data
->rightList
, data
->count
, sizeof(WWindow
**), compareWRight
);
774 qsort(data
->bottomList
, data
->count
, sizeof(WWindow
**), compareWBottom
);
776 /* figure the position of the window relative to the others */
779 data
->leftIndex
= -1;
780 data
->rightIndex
= -1;
781 data
->bottomIndex
= -1;
783 if (WTOP(wwin
) < WBOTTOM(data
->bottomList
[0])) {
784 data
->bottomIndex
= 0;
786 if (WLEFT(wwin
) < WRIGHT(data
->rightList
[0])) {
787 data
->rightIndex
= 0;
789 if (WRIGHT(wwin
) > WLEFT(data
->leftList
[0])) {
792 if (WBOTTOM(wwin
) > WTOP(data
->topList
[0])) {
795 for (i
= 0; i
< data
->count
; i
++) {
796 if (WTOP(wwin
) >= WBOTTOM(data
->bottomList
[i
])) {
797 data
->bottomIndex
= i
+ 1;
799 if (WLEFT(wwin
) >= WRIGHT(data
->rightList
[i
])) {
800 data
->rightIndex
= i
+ 1;
802 if (WRIGHT(wwin
) <= WLEFT(data
->leftList
[i
])) {
803 data
->leftIndex
= i
+ 1;
805 if (WBOTTOM(wwin
) <= WTOP(data
->topList
[i
])) {
806 data
->topIndex
= i
+ 1;
811 static void initMoveData(WWindow
* wwin
, MoveData
* data
)
816 memset(data
, 0, sizeof(MoveData
));
818 for (i
= 0, tmp
= wwin
->screen_ptr
->focused_window
; tmp
!= NULL
; tmp
= tmp
->prev
, i
++) ;
821 data
->topList
= wmalloc(sizeof(WWindow
*) * i
);
822 data
->leftList
= wmalloc(sizeof(WWindow
*) * i
);
823 data
->rightList
= wmalloc(sizeof(WWindow
*) * i
);
824 data
->bottomList
= wmalloc(sizeof(WWindow
*) * i
);
826 updateMoveData(wwin
, data
);
829 data
->realX
= wwin
->frame_x
;
830 data
->realY
= wwin
->frame_y
;
831 data
->calcX
= wwin
->frame_x
;
832 data
->calcY
= wwin
->frame_y
;
834 data
->winWidth
= wwin
->frame
->core
->width
+ (HAS_BORDER_WITH_SELECT(wwin
) ? 2 * FRAME_BORDER_WIDTH
: 0);
835 data
->winHeight
= wwin
->frame
->core
->height
+ (HAS_BORDER_WITH_SELECT(wwin
) ? 2 * FRAME_BORDER_WIDTH
: 0);
838 static Bool
checkWorkspaceChange(WWindow
* wwin
, MoveData
* data
, Bool opaqueMove
)
840 WScreen
*scr
= wwin
->screen_ptr
;
841 Bool changed
= False
;
843 if (data
->mouseX
<= 1) {
844 if (scr
->current_workspace
> 0) {
846 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
- 1, True
);
850 } else if (scr
->current_workspace
== 0 && wPreferences
.ws_cycle
) {
852 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->workspace_count
- 1, True
);
856 } else if (data
->mouseX
>= scr
->scr_width
- 2) {
858 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
860 if (wPreferences
.ws_cycle
|| scr
->workspace_count
== MAX_WORKSPACES
) {
862 crossWorkspace(scr
, wwin
, opaqueMove
, 0, False
);
866 /* if user insists on trying to go to next workspace even when
867 * it's already the last, create a new one */
868 else if (data
->omouseX
== data
->mouseX
&& wPreferences
.ws_advance
) {
870 /* detect user "rubbing" the window against the edge */
871 if (data
->rubCount
> 0 && data
->omouseY
- data
->mouseY
> MOVE_THRESHOLD
) {
873 data
->rubCount
= -(data
->rubCount
+ 1);
875 } else if (data
->rubCount
<= 0 && data
->mouseY
- data
->omouseY
> MOVE_THRESHOLD
) {
877 data
->rubCount
= -data
->rubCount
+ 1;
880 /* create a new workspace */
881 if (abs(data
->rubCount
) > 2) {
882 /* go to next workspace */
885 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
+ 1, False
);
889 } else if (scr
->current_workspace
< scr
->workspace_count
) {
891 /* go to next workspace */
892 crossWorkspace(scr
, wwin
, opaqueMove
, scr
->current_workspace
+ 1, False
);
904 updateWindowPosition(WWindow
* wwin
, MoveData
* data
, Bool doResistance
,
905 Bool opaqueMove
, int newMouseX
, int newMouseY
)
907 WScreen
*scr
= wwin
->screen_ptr
;
908 int dx
, dy
; /* how much mouse moved */
909 int winL
, winR
, winT
, winB
; /* requested new window position */
910 int newX
, newY
; /* actual new window position */
911 Bool hresist
, vresist
;
920 /* check the direction of the movement */
921 dx
= newMouseX
- data
->mouseX
;
922 dy
= newMouseY
- data
->mouseY
;
924 data
->omouseX
= data
->mouseX
;
925 data
->omouseY
= data
->mouseY
;
926 data
->mouseX
= newMouseX
;
927 data
->mouseY
= newMouseY
;
929 winL
= data
->calcX
+ dx
;
930 winR
= data
->calcX
+ data
->winWidth
+ dx
;
931 winT
= data
->calcY
+ dy
;
932 winB
= data
->calcY
+ data
->winHeight
+ dy
;
944 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
945 attract
= wPreferences
.attract
;
946 /* horizontal movement: check horizontal edge resistances */
950 /* window is the leftmost window: check against screen edge */
952 /* Add inter head resistance 1/2 (if needed) */
953 head
= wGetHeadForPointerLocation(scr
);
954 rect
= wGetRectForHead(scr
, head
);
956 l_edge
= WMAX(scr
->totalUsableArea
[head
].x1
, rect
.pos
.x
);
957 edge_l
= l_edge
- resist
;
958 edge_r
= WMIN(scr
->totalUsableArea
[head
].x2
, rect
.pos
.x
+ rect
.size
.width
);
959 r_edge
= edge_r
+ resist
;
962 if ((data
->rightIndex
>= 0) && (data
->rightIndex
<= data
->count
)) {
965 for (i
= data
->rightIndex
- 1; i
>= 0; i
--) {
966 looprw
= data
->rightList
[i
];
967 if (!(data
->realY
> WBOTTOM(looprw
)
968 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
969 if (attract
|| ((data
->realX
< (WRIGHT(looprw
) + 2)) && dx
< 0)) {
970 l_edge
= WRIGHT(looprw
) + 1;
971 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
978 for (i
= data
->rightIndex
; i
< data
->count
; i
++) {
979 looprw
= data
->rightList
[i
];
980 if (!(data
->realY
> WBOTTOM(looprw
)
981 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
982 r_edge
= WRIGHT(looprw
) + 1;
983 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
990 if ((data
->leftIndex
>= 0) && (data
->leftIndex
<= data
->count
)) {
993 for (i
= data
->leftIndex
- 1; i
>= 0; i
--) {
994 looprw
= data
->leftList
[i
];
995 if (!(data
->realY
> WBOTTOM(looprw
)
996 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
998 || (((data
->realX
+ data
->winWidth
) > (WLEFT(looprw
) - 1))
1000 edge_r
= WLEFT(looprw
);
1001 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1008 for (i
= data
->leftIndex
; i
< data
->count
; i
++) {
1009 looprw
= data
->leftList
[i
];
1010 if (!(data
->realY
> WBOTTOM(looprw
)
1011 || (data
->realY
+ data
->winHeight
) < WTOP(looprw
))) {
1012 edge_l
= WLEFT(looprw
);
1013 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1020 printf("%d %d\n",winL,winR);
1021 printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);
1024 if ((winL
- l_edge
) < (r_edge
- winL
)) {
1026 if ((attract
&& winL
<= l_edge
+ resist
&& winL
>= l_edge
- resist
)
1027 || (dx
< 0 && winL
<= l_edge
&& winL
>= l_edge
- resist
)) {
1033 if (resist
> 0 && attract
&& winL
>= r_edge
- resist
&& winL
<= r_edge
+ resist
) {
1039 if ((winR
- edge_l
) < (edge_r
- winR
)) {
1040 if (resist
> 0 && attract
&& winR
<= edge_l
+ resist
&& winR
>= edge_l
- resist
) {
1041 newX
= edge_l
- data
->winWidth
;
1046 if ((attract
&& winR
>= edge_r
- resist
&& winR
<= edge_r
+ resist
)
1047 || (dx
> 0 && winR
>= edge_r
&& winR
<= edge_r
+ resist
)) {
1048 newX
= edge_r
- data
->winWidth
;
1055 /* Add inter head resistance 2/2 (if needed) */
1056 t_edge
= WMAX(scr
->totalUsableArea
[head
].y1
, rect
.pos
.y
);
1057 edge_t
= t_edge
- resist
;
1058 edge_b
= WMIN(scr
->totalUsableArea
[head
].y2
, rect
.pos
.y
+ rect
.size
.height
);
1059 b_edge
= edge_b
+ resist
;
1061 if ((data
->bottomIndex
>= 0) && (data
->bottomIndex
<= data
->count
)) {
1064 for (i
= data
->bottomIndex
- 1; i
>= 0; i
--) {
1065 looprw
= data
->bottomList
[i
];
1066 if (!(data
->realX
> WRIGHT(looprw
)
1067 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1068 if (attract
|| ((data
->realY
< (WBOTTOM(looprw
) + 2)) && dy
< 0)) {
1069 t_edge
= WBOTTOM(looprw
) + 1;
1070 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1077 for (i
= data
->bottomIndex
; i
< data
->count
; i
++) {
1078 looprw
= data
->bottomList
[i
];
1079 if (!(data
->realX
> WRIGHT(looprw
)
1080 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1081 b_edge
= WBOTTOM(looprw
) + 1;
1082 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1089 if ((data
->topIndex
>= 0) && (data
->topIndex
<= data
->count
)) {
1092 for (i
= data
->topIndex
- 1; i
>= 0; i
--) {
1093 looprw
= data
->topList
[i
];
1094 if (!(data
->realX
> WRIGHT(looprw
)
1095 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1097 || (((data
->realY
+ data
->winHeight
) > (WTOP(looprw
) - 1))
1099 edge_b
= WTOP(looprw
);
1100 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1107 for (i
= data
->topIndex
; i
< data
->count
; i
++) {
1108 looprw
= data
->topList
[i
];
1109 if (!(data
->realX
> WRIGHT(looprw
)
1110 || (data
->realX
+ data
->winWidth
) < WLEFT(looprw
))) {
1111 edge_t
= WTOP(looprw
);
1112 resist
= WIN_RESISTANCE(wPreferences
.edge_resistance
);
1118 if ((winT
- t_edge
) < (b_edge
- winT
)) {
1120 if ((attract
&& winT
<= t_edge
+ resist
&& winT
>= t_edge
- resist
)
1121 || (dy
< 0 && winT
<= t_edge
&& winT
>= t_edge
- resist
)) {
1127 if (resist
> 0 && attract
&& winT
>= b_edge
- resist
&& winT
<= b_edge
+ resist
) {
1133 if ((winB
- edge_t
) < (edge_b
- winB
)) {
1134 if (resist
> 0 && attract
&& winB
<= edge_t
+ resist
&& winB
>= edge_t
- resist
) {
1135 newY
= edge_t
- data
->winHeight
;
1140 if ((attract
&& winB
>= edge_b
- resist
&& winB
<= edge_b
+ resist
)
1141 || (dy
> 0 && winB
>= edge_b
&& winB
<= edge_b
+ resist
)) {
1142 newY
= edge_b
- data
->winHeight
;
1152 /* update window position */
1156 if (((dx
> 0 && data
->calcX
- data
->realX
> 0)
1157 || (dx
< 0 && data
->calcX
- data
->realX
< 0)) && !hresist
)
1160 if (((dy
> 0 && data
->calcY
- data
->realY
> 0)
1161 || (dy
< 0 && data
->calcY
- data
->realY
< 0)) && !vresist
)
1164 if (data
->realX
!= newX
|| data
->realY
!= newY
) {
1166 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1167 showPosition(wwin
, data
->realX
, data
->realY
);
1170 doWindowMove(wwin
, scr
->selected_windows
, newX
- wwin
->frame_x
, newY
- wwin
->frame_y
);
1173 drawFrames(wwin
, scr
->selected_windows
,
1174 data
->realX
- wwin
->frame_x
, data
->realY
- wwin
->frame_y
);
1177 if (!scr
->selected_windows
&& wPreferences
.move_display
== WDIS_FRAME_CENTER
) {
1179 moveGeometryDisplayCentered(scr
, newX
+ data
->winWidth
/ 2, newY
+ data
->winHeight
/ 2);
1184 drawFrames(wwin
, scr
->selected_windows
, newX
- wwin
->frame_x
, newY
- wwin
->frame_y
);
1187 if (!scr
->selected_windows
) {
1188 showPosition(wwin
, newX
, newY
);
1192 /* recalc relative window position */
1193 if (doResistance
&& (data
->realX
!= newX
|| data
->realY
!= newY
)) {
1194 updateResistance(wwin
, data
, newX
, newY
);
1201 #define _KS KEY_CONTROL_WINDOW_WEIGHT
1203 #define MOVABLE_BIT 0x01
1204 #define RESIZABLE_BIT 0x02
1206 int wKeyboardMoveResizeWindow(WWindow
* wwin
)
1208 WScreen
*scr
= wwin
->screen_ptr
;
1209 Window root
= scr
->root_win
;
1211 int w
= wwin
->frame
->core
->width
;
1212 int h
= wwin
->frame
->core
->height
;
1213 int scr_width
= wwin
->screen_ptr
->scr_width
;
1214 int scr_height
= wwin
->screen_ptr
->scr_height
;
1215 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1216 int src_x
= wwin
->frame_x
;
1217 int src_y
= wwin
->frame_y
;
1218 int done
, off_x
, off_y
, ww
, wh
;
1221 KeyCode shiftl
, shiftr
, ctrll
, ctrlmode
;
1222 KeySym keysym
= NoSymbol
;
1224 int modes
= ((IS_MOVABLE(wwin
) ? MOVABLE_BIT
: 0) | (IS_RESIZABLE(wwin
) ? RESIZABLE_BIT
: 0));
1225 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1226 ? wGetHeadForWindow(wwin
)
1227 : scr
->xine_info
.primary_head
);
1229 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1230 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1231 ctrll
= XKeysymToKeycode(dpy
, XK_Control_L
);
1232 ctrlmode
= done
= off_x
= off_y
= 0;
1234 if (modes
== RESIZABLE_BIT
) {
1240 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1242 if (!wwin
->flags
.selected
) {
1243 wUnselectWindows(scr
);
1246 XGrabPointer(dpy
, scr
->root_win
, True
, PointerMotionMask
1247 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
1248 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
);
1250 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1251 if (scr
->selected_windows
)
1252 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1254 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1255 if (!scr
->selected_windows
)
1256 mapPositionDisplay(wwin
, src_x
, src_y
, w
, h
);
1258 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1268 WMMaskEvent(dpy
, KeyPressMask
| ButtonReleaseMask
1269 | ButtonPressMask
| ExposureMask
, &event
);
1270 if (event
.type
== Expose
) {
1271 WMHandleEvent(&event
);
1273 } while (event
.type
== Expose
);
1275 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1276 if (scr
->selected_windows
)
1277 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1279 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1280 /*** I HATE EDGE RESISTANCE - ]d ***/
1282 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1286 showGeometry(wwin
, src_x
+ off_x
, src_y
+ off_y
, src_x
+ off_x
+ ww
, src_y
+ off_y
+ wh
,
1292 switch (event
.type
) {
1295 if (event
.xkey
.time
- lastTime
> 50) {
1296 kspeed
/= (1 + (event
.xkey
.time
- lastTime
) / 100);
1304 lastTime
= event
.xkey
.time
;
1305 if (modes
== (MOVABLE_BIT
| RESIZABLE_BIT
)) {
1306 if ((event
.xkey
.state
& ControlMask
) && !wwin
->flags
.shaded
) {
1308 wUnselectWindows(scr
);
1313 if (event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
) {
1315 cycleGeometryDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
, 0);
1317 cyclePositionDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1320 keysym
= XLookupKeysym(&event
.xkey
, 0);
1377 if (moment
!= RIGHT
)
1389 wWindowConstrainSize(wwin
, (unsigned int *)&ww
, (unsigned int *)&wh
);
1392 if (wPreferences
.ws_cycle
) {
1393 if (src_x
+ off_x
+ ww
< 20) {
1394 if (!scr
->current_workspace
) {
1395 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
1397 wWorkspaceChange(scr
, scr
->current_workspace
- 1);
1399 } else if (src_x
+ off_x
+ 20 > scr_width
) {
1400 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
1401 wWorkspaceChange(scr
, 0);
1403 wWorkspaceChange(scr
, scr
->current_workspace
+ 1);
1407 if (src_x
+ off_x
+ ww
< 20)
1408 off_x
= 20 - ww
- src_x
;
1409 else if (src_x
+ off_x
+ 20 > scr_width
)
1410 off_x
= scr_width
- 20 - src_x
;
1413 if (src_y
+ off_y
+ wh
< 20) {
1414 off_y
= 20 - wh
- src_y
;
1415 } else if (src_y
+ off_y
+ 20 > scr_height
) {
1416 off_y
= scr_height
- 20 - src_y
;
1425 WMHandleEvent(&event
);
1426 while (XCheckTypedEvent(dpy
, Expose
, &event
)) {
1427 WMHandleEvent(&event
);
1432 WMHandleEvent(&event
);
1439 if (wwin
->flags
.shaded
&& !scr
->selected_windows
) {
1440 moveGeometryDisplayCentered(scr
, src_x
+ off_x
+ w
/ 2, src_y
+ off_y
+ h
/ 2);
1443 WMUnmapWidget(scr
->gview
);
1444 mapGeometryDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1445 } else if (!scr
->selected_windows
) {
1446 WMUnmapWidget(scr
->gview
);
1447 mapPositionDisplay(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1451 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1452 if (scr
->selected_windows
)
1453 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1455 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1457 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1461 showGeometry(wwin
, src_x
+ off_x
, src_y
+ off_y
, src_x
+ off_x
+ ww
, src_y
+ off_y
+ wh
,
1463 } else if (!scr
->selected_windows
)
1464 showPosition(wwin
, src_x
+ off_x
, src_y
+ off_y
);
1467 scr
->keymove_tick
= 0;
1469 WMDeleteTimerWithClientData(&looper);
1471 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1472 if (scr
->selected_windows
)
1473 drawFrames(wwin
, scr
->selected_windows
, off_x
, off_y
);
1475 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, w
, h
);
1477 drawTransparentFrame(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
);
1481 showGeometry(wwin
, src_x
+ off_x
, src_y
+ off_y
, src_x
+ off_x
+ ww
,
1482 src_y
+ off_y
+ wh
, 0);
1483 WMUnmapWidget(scr
->gview
);
1485 WMUnmapWidget(scr
->gview
);
1487 XUngrabKeyboard(dpy
, CurrentTime
);
1488 XUngrabPointer(dpy
, CurrentTime
);
1492 if (wwin
->flags
.shaded
|| scr
->selected_windows
) {
1493 if (!scr
->selected_windows
) {
1494 wWindowMove(wwin
, src_x
+ off_x
, src_y
+ off_y
);
1495 wWindowSynthConfigureNotify(wwin
);
1497 WMArrayIterator iter
;
1500 doWindowMove(wwin
, scr
->selected_windows
, off_x
, off_y
);
1502 WM_ITERATE_ARRAY(scr
->selected_windows
, foo
, iter
) {
1503 wWindowSynthConfigureNotify(foo
);
1507 if (wwin
->client
.width
!= ww
) {
1508 wwin
->flags
.user_changed_width
= 1;
1509 wwin
->flags
.maximized
&= ~(MAX_HORIZONTAL
| MAX_MAXIMUS
);
1512 if (wwin
->client
.height
!= wh
- vert_border
) {
1513 wwin
->flags
.user_changed_height
= 1;
1514 wwin
->flags
.maximized
&= ~(MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
1517 wWindowConfigure(wwin
, src_x
+ off_x
, src_y
+ off_y
, ww
, wh
- vert_border
);
1518 wWindowSynthConfigureNotify(wwin
);
1520 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1521 wSetFocusTo(scr
, wwin
);
1524 if (wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 &&
1525 head
!= wGetHeadForWindow(wwin
)) {
1526 wArrangeIcons(scr
, True
);
1535 *----------------------------------------------------------------------
1536 * wMouseMoveWindow--
1537 * Move the named window and the other selected ones (if any),
1538 * interactively. Also shows the position of the window, if only one
1539 * window is being moved.
1540 * If the window is not on the selected window list, the selected
1541 * windows are deselected.
1542 * If shift is pressed during the operation, the position display
1543 * is changed to another type.
1546 * True if the window was moved, False otherwise.
1549 * The window(s) position is changed, and the client(s) are
1550 * notified about that.
1551 * The position display configuration may be changed.
1552 *----------------------------------------------------------------------
1554 int wMouseMoveWindow(WWindow
* wwin
, XEvent
* ev
)
1556 WScreen
*scr
= wwin
->screen_ptr
;
1558 Window root
= scr
->root_win
;
1559 KeyCode shiftl
, shiftr
;
1563 /* This needs not to change while moving, else bad things can happen */
1564 int opaqueMove
= wPreferences
.opaque_move
;
1566 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1567 ? wGetHeadForWindow(wwin
)
1568 : scr
->xine_info
.primary_head
);
1570 if (!IS_MOVABLE(wwin
))
1573 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1574 XSetWindowAttributes attr
;
1576 attr
.save_under
= True
;
1577 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
, CWSaveUnder
, &attr
);
1580 initMoveData(wwin
, &moveData
);
1582 moveData
.mouseX
= ev
->xmotion
.x_root
;
1583 moveData
.mouseY
= ev
->xmotion
.y_root
;
1585 if (!wwin
->flags
.selected
) {
1586 /* this window is not selected, unselect others and move only wwin */
1587 wUnselectWindows(scr
);
1590 puts("Moving window");
1592 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1593 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1599 /* XWarpPointer() doesn't seem to generate Motion events, so
1600 * we've got to simulate them */
1601 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &event
.xmotion
.x_root
,
1602 &event
.xmotion
.y_root
, &junk
, &junk
, (unsigned *)&junk
);
1604 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1605 | PointerMotionHintMask
1606 | ButtonReleaseMask
| ButtonPressMask
| ExposureMask
, &event
);
1608 if (event
.type
== MotionNotify
) {
1609 /* compress MotionNotify events */
1610 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1611 if (!checkMouseSamplingRate(&event
))
1615 switch (event
.type
) {
1617 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1618 && started
&& !scr
->selected_windows
) {
1621 drawFrames(wwin
, scr
->selected_windows
,
1622 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1625 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1626 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1629 cyclePositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1630 moveData
.winWidth
, moveData
.winHeight
);
1632 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1634 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1638 drawFrames(wwin
, scr
->selected_windows
,
1639 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1642 WMHandleEvent(&event); this causes problems needs fixing */
1648 updateWindowPosition(wwin
, &moveData
,
1649 scr
->selected_windows
== NULL
1650 && wPreferences
.edge_resistance
> 0,
1651 opaqueMove
, event
.xmotion
.x_root
, event
.xmotion
.y_root
);
1653 if (!warped
&& !wPreferences
.no_autowrap
) {
1654 int oldWorkspace
= scr
->current_workspace
;
1656 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1657 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1661 drawFrames(wwin
, scr
->selected_windows
,
1662 moveData
.realX
- wwin
->frame_x
,
1663 moveData
.realY
- wwin
->frame_y
);
1665 if (checkWorkspaceChange(wwin
, &moveData
, opaqueMove
)) {
1666 if (scr
->current_workspace
!= oldWorkspace
1667 && wPreferences
.edge_resistance
> 0
1668 && scr
->selected_windows
== NULL
)
1669 updateMoveData(wwin
, &moveData
);
1673 drawFrames(wwin
, scr
->selected_windows
,
1674 moveData
.realX
- wwin
->frame_x
,
1675 moveData
.realY
- wwin
->frame_y
);
1677 if (wPreferences
.move_display
== WDIS_NEW
&& !scr
->selected_windows
) {
1679 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1685 } else if (abs(ev
->xmotion
.x_root
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1686 || abs(ev
->xmotion
.y_root
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1688 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1689 | ButtonReleaseMask
| ButtonPressMask
,
1690 wCursor
[WCUR_MOVE
], CurrentTime
);
1692 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
1694 if (!scr
->selected_windows
)
1695 mapPositionDisplay(wwin
, moveData
.realX
, moveData
.realY
,
1696 moveData
.winWidth
, moveData
.winHeight
);
1698 if (started
&& !opaqueMove
)
1699 drawFrames(wwin
, scr
->selected_windows
, 0, 0);
1701 if (!opaqueMove
|| (wPreferences
.move_display
== WDIS_NEW
1702 && !scr
->selected_windows
)) {
1704 if (wPreferences
.move_display
== WDIS_NEW
)
1705 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1714 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
1720 drawFrames(wwin
, scr
->selected_windows
,
1721 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1723 doWindowMove(wwin
, scr
->selected_windows
,
1724 moveData
.realX
- wwin
->frame_x
,
1725 moveData
.realY
- wwin
->frame_y
);
1727 #ifndef CONFIGURE_WINDOW_WHILE_MOVING
1728 wWindowSynthConfigureNotify(wwin
);
1730 XUngrabKeyboard(dpy
, CurrentTime
);
1733 wWindowChangeWorkspace(wwin
, scr
->current_workspace
);
1734 wSetFocusTo(scr
, wwin
);
1736 if (wPreferences
.move_display
== WDIS_NEW
)
1737 showPosition(wwin
, moveData
.realX
, moveData
.realY
);
1739 /* discard all enter/leave events that happened until
1740 * the time the button was released */
1741 while (XCheckTypedEvent(dpy
, EnterNotify
, &e
)) {
1742 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1743 XPutBackEvent(dpy
, &e
);
1747 while (XCheckTypedEvent(dpy
, LeaveNotify
, &e
)) {
1748 if (e
.xcrossing
.time
> event
.xbutton
.time
) {
1749 XPutBackEvent(dpy
, &e
);
1754 if (!scr
->selected_windows
) {
1755 /* get rid of the geometry window */
1756 WMUnmapWidget(scr
->gview
);
1760 puts("End move window");
1766 if (started
&& !opaqueMove
) {
1767 drawFrames(wwin
, scr
->selected_windows
,
1768 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1770 WMHandleEvent(&event
);
1773 drawFrames(wwin
, scr
->selected_windows
,
1774 moveData
.realX
- wwin
->frame_x
, moveData
.realY
- wwin
->frame_y
);
1776 WMHandleEvent(&event
);
1782 if (wPreferences
.opaque_move
&& !wPreferences
.use_saveunders
) {
1783 XSetWindowAttributes attr
;
1785 attr
.save_under
= False
;
1786 XChangeWindowAttributes(dpy
, wwin
->frame
->core
->window
, CWSaveUnder
, &attr
);
1790 freeMoveData(&moveData
);
1792 if (started
&& wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 &&
1793 head
!= wGetHeadForWindow(wwin
)) {
1794 wArrangeIcons(scr
, True
);
1800 #define HCONSTRAIN 2
1802 static int getResizeDirection(WWindow
* wwin
, int x
, int y
, int dx
, int dy
, int flags
)
1804 int w
= wwin
->frame
->core
->width
- 1;
1805 int cw
= wwin
->frame
->resizebar_corner_width
;
1808 /* if not resizing through the resizebar */
1809 if (!(flags
& RESIZEBAR
)) {
1810 int xdir
= (abs(x
) < (wwin
->client
.width
/ 2)) ? LEFT
: RIGHT
;
1811 int ydir
= (abs(y
) < (wwin
->client
.height
/ 2)) ? UP
: DOWN
;
1812 if (abs(dx
) < 2 || abs(dy
) < 2) {
1813 if (abs(dy
) > abs(dx
))
1818 return (xdir
| ydir
);
1821 /* window is too narrow. allow diagonal resize */
1825 if (flags
& HCONSTRAIN
)
1830 return (LEFT
| ydir
);
1832 return (RIGHT
| ydir
);
1834 /* vertical resize */
1835 if ((x
> cw
) && (x
< w
- cw
))
1843 if ((abs(dy
) > 0) && !(flags
& HCONSTRAIN
))
1849 void wMouseResizeWindow(WWindow
* wwin
, XEvent
* ev
)
1852 WScreen
*scr
= wwin
->screen_ptr
;
1853 Window root
= scr
->root_win
;
1854 int vert_border
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1855 int fw
= wwin
->frame
->core
->width
;
1856 int fh
= wwin
->frame
->core
->height
;
1857 int fx
= wwin
->frame_x
;
1858 int fy
= wwin
->frame_y
;
1859 int is_resizebar
= (wwin
->frame
->resizebar
&& ev
->xany
.window
== wwin
->frame
->resizebar
->window
);
1863 int rw
= fw
, rh
= fh
;
1864 int rx1
, ry1
, rx2
, ry2
;
1866 KeyCode shiftl
, shiftr
;
1872 int head
= ((wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1)
1873 ? wGetHeadForWindow(wwin
)
1874 : scr
->xine_info
.primary_head
);
1876 if (!IS_RESIZABLE(wwin
))
1879 if (wwin
->flags
.shaded
) {
1880 wwarning("internal error: tryein");
1883 orig_x
= ev
->xbutton
.x_root
;
1884 orig_y
= ev
->xbutton
.y_root
;
1888 puts("Resizing window");
1891 wUnselectWindows(scr
);
1896 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
1897 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
1898 if (HAS_TITLEBAR(wwin
))
1899 h
= WMFontHeight(wwin
->screen_ptr
->title_font
) + (wPreferences
.window_title_clearance
+
1900 TITLEBAR_EXTEND_SPACE
) * 2;
1904 WMMaskEvent(dpy
, KeyPressMask
| ButtonMotionMask
1905 | ButtonReleaseMask
| PointerMotionHintMask
| ButtonPressMask
| ExposureMask
, &event
);
1906 if (!checkMouseSamplingRate(&event
))
1909 switch (event
.type
) {
1911 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1912 if ((event
.xkey
.keycode
== shiftl
|| event
.xkey
.keycode
== shiftr
)
1914 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1915 cycleGeometryDisplay(wwin
, fx
, fy
, fw
, fh
, res
);
1916 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
1918 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
1923 while (XCheckMaskEvent(dpy
, ButtonMotionMask
, &event
)) ;
1934 dw
= orig_x
- event
.xmotion
.x_root
;
1935 else if (res
& RIGHT
)
1936 dw
= event
.xmotion
.x_root
- orig_x
;
1938 dh
= orig_y
- event
.xmotion
.y_root
;
1939 else if (res
& DOWN
)
1940 dh
= event
.xmotion
.y_root
- orig_y
;
1942 orig_x
= event
.xmotion
.x_root
;
1943 orig_y
= event
.xmotion
.y_root
;
1948 fh
= rh
- vert_border
;
1949 wWindowConstrainSize(wwin
, (unsigned int *)&fw
, (unsigned int *)&fh
);
1953 else if (res
& RIGHT
)
1957 else if (res
& DOWN
)
1959 } else if (abs(orig_x
- event
.xmotion
.x_root
) >= MOVE_THRESHOLD
1960 || abs(orig_y
- event
.xmotion
.y_root
) >= MOVE_THRESHOLD
) {
1965 XTranslateCoordinates(dpy
, root
, wwin
->frame
->core
->window
,
1966 orig_x
, orig_y
, &tx
, &ty
, &junkw
);
1968 /* check if resizing through resizebar */
1974 if (is_resizebar
&& ((ev
->xbutton
.state
& ShiftMask
)
1975 || abs(orig_y
- event
.xmotion
.y_root
) < HRESIZE_THRESHOLD
))
1976 flags
|= HCONSTRAIN
;
1978 res
= getResizeDirection(wwin
, tx
, ty
,
1979 orig_x
- event
.xmotion
.x_root
,
1980 orig_y
- event
.xmotion
.y_root
, flags
);
1982 if (res
== (UP
| LEFT
))
1983 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1984 | ButtonReleaseMask
| ButtonPressMask
,
1985 wCursor
[WCUR_TOPLEFTRESIZE
], CurrentTime
);
1986 else if (res
== (UP
| RIGHT
))
1987 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1988 | ButtonReleaseMask
| ButtonPressMask
,
1989 wCursor
[WCUR_TOPRIGHTRESIZE
], CurrentTime
);
1990 else if (res
== (DOWN
| LEFT
))
1991 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1992 | ButtonReleaseMask
| ButtonPressMask
,
1993 wCursor
[WCUR_BOTTOMLEFTRESIZE
], CurrentTime
);
1994 else if (res
== (DOWN
| RIGHT
))
1995 XChangeActivePointerGrab(dpy
, ButtonMotionMask
1996 | ButtonReleaseMask
| ButtonPressMask
,
1997 wCursor
[WCUR_BOTTOMRIGHTRESIZE
], CurrentTime
);
1998 else if (res
== DOWN
|| res
== UP
)
1999 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2000 | ButtonReleaseMask
| ButtonPressMask
,
2001 wCursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2002 else if (res
& (DOWN
| UP
))
2003 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2004 | ButtonReleaseMask
| ButtonPressMask
,
2005 wCursor
[WCUR_VERTICALRESIZE
], CurrentTime
);
2006 else if (res
& (LEFT
| RIGHT
))
2007 XChangeActivePointerGrab(dpy
, ButtonMotionMask
2008 | ButtonReleaseMask
| ButtonPressMask
,
2009 wCursor
[WCUR_HORIZONRESIZE
], CurrentTime
);
2011 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2015 /* Draw the resize frame for the first time. */
2016 mapGeometryDisplay(wwin
, fx
, fy
, fw
, fh
);
2018 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2020 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2025 if (wPreferences
.size_display
== WDIS_FRAME_CENTER
) {
2026 drawTransparentFrame(wwin
, orig_fx
, orig_fy
, orig_fw
, orig_fh
);
2027 moveGeometryDisplayCentered(scr
, fx
+ fw
/ 2, fy
+ fh
/ 2);
2028 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2030 drawTransparentFrame(wwin
, orig_fx
, orig_fy
, orig_fw
, orig_fh
);
2031 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2033 if (fh
!= orig_fh
|| fw
!= orig_fw
) {
2034 if (wPreferences
.size_display
== WDIS_NEW
) {
2035 showGeometry(wwin
, orig_fx
, orig_fy
, orig_fx
+ orig_fw
,
2036 orig_fy
+ orig_fh
, res
);
2038 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2047 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2051 showGeometry(wwin
, fx
, fy
, fx
+ fw
, fy
+ fh
, res
);
2053 drawTransparentFrame(wwin
, fx
, fy
, fw
, fh
);
2055 XUngrabKeyboard(dpy
, CurrentTime
);
2056 WMUnmapWidget(scr
->gview
);
2059 if (wwin
->client
.width
!= fw
) {
2060 wwin
->flags
.user_changed_width
= 1;
2061 wwin
->flags
.maximized
&= ~(MAX_HORIZONTAL
| MAX_MAXIMUS
);
2064 if (wwin
->client
.height
!= fh
- vert_border
) {
2065 wwin
->flags
.user_changed_height
= 1;
2066 wwin
->flags
.maximized
&= ~(MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
2069 wWindowConfigure(wwin
, fx
, fy
, fw
, fh
- vert_border
);
2072 puts("End resize window");
2077 WMHandleEvent(&event
);
2081 if (wPreferences
.auto_arrange_icons
&& wXineramaHeads(scr
) > 1 && head
!= wGetHeadForWindow(wwin
)) {
2082 wArrangeIcons(scr
, True
);
2095 void wUnselectWindows(WScreen
* scr
)
2099 if (!scr
->selected_windows
)
2102 while (WMGetArrayItemCount(scr
->selected_windows
)) {
2103 wwin
= WMGetFromArray(scr
->selected_windows
, 0);
2104 if (wwin
->flags
.miniaturized
&& wwin
->icon
&& wwin
->icon
->selected
)
2105 wIconSelect(wwin
->icon
);
2107 wSelectWindow(wwin
, False
);
2109 WMFreeArray(scr
->selected_windows
);
2110 scr
->selected_windows
= NULL
;
2113 static void selectWindowsInside(WScreen
* scr
, int x1
, int y1
, int x2
, int y2
)
2117 /* select the windows and put them in the selected window list */
2118 tmpw
= scr
->focused_window
;
2119 while (tmpw
!= NULL
) {
2120 if (!(tmpw
->flags
.miniaturized
|| tmpw
->flags
.hidden
)) {
2121 if ((tmpw
->frame
->workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(tmpw
))
2122 && (tmpw
->frame_x
>= x1
) && (tmpw
->frame_y
>= y1
)
2123 && (tmpw
->frame
->core
->width
+ tmpw
->frame_x
<= x2
)
2124 && (tmpw
->frame
->core
->height
+ tmpw
->frame_y
<= y2
)) {
2125 wSelectWindow(tmpw
, True
);
2132 void wSelectWindows(WScreen
* scr
, XEvent
* ev
)
2135 Window root
= scr
->root_win
;
2136 GC gc
= scr
->frame_gc
;
2137 int xp
= ev
->xbutton
.x_root
;
2138 int yp
= ev
->xbutton
.y_root
;
2143 puts("Selecting windows");
2145 if (XGrabPointer(dpy
, scr
->root_win
, False
, ButtonMotionMask
2146 | ButtonReleaseMask
| ButtonPressMask
, GrabModeAsync
,
2147 GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2152 wUnselectWindows(scr
);
2154 XDrawRectangle(dpy
, root
, gc
, xp
, yp
, w
, h
);
2156 WMMaskEvent(dpy
, ButtonReleaseMask
| PointerMotionMask
| ButtonPressMask
, &event
);
2158 switch (event
.type
) {
2160 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2161 x
= event
.xmotion
.x_root
;
2168 y
= event
.xmotion
.y_root
;
2175 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2182 if (event
.xbutton
.button
!= ev
->xbutton
.button
)
2185 XDrawRectangle(dpy
, root
, gc
, x
, y
, w
, h
);
2187 XUngrabPointer(dpy
, CurrentTime
);
2188 selectWindowsInside(scr
, x
, y
, x
+ w
, y
+ h
);
2191 puts("End window selection");
2196 WMHandleEvent(&event
);
2202 void InteractivePlaceWindow(WWindow
* wwin
, int *x_ret
, int *y_ret
, unsigned width
, unsigned height
)
2204 WScreen
*scr
= wwin
->screen_ptr
;
2205 Window root
= scr
->root_win
;
2208 KeyCode shiftl
, shiftr
;
2212 if (XGrabPointer(dpy
, root
, True
, PointerMotionMask
| ButtonPressMask
,
2213 GrabModeAsync
, GrabModeAsync
, None
, wCursor
[WCUR_DEFAULT
], CurrentTime
) != Success
) {
2218 if (HAS_TITLEBAR(wwin
)) {
2219 h
= WMFontHeight(scr
->title_font
) + (wPreferences
.window_title_clearance
+
2220 TITLEBAR_EXTEND_SPACE
) * 2;
2223 if (HAS_RESIZEBAR(wwin
)) {
2224 height
+= RESIZEBAR_HEIGHT
;
2226 XGrabKeyboard(dpy
, root
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
2227 XQueryPointer(dpy
, root
, &junkw
, &junkw
, &x
, &y
, &junk
, &junk
, (unsigned *)&junk
);
2228 mapPositionDisplay(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2230 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2232 shiftl
= XKeysymToKeycode(dpy
, XK_Shift_L
);
2233 shiftr
= XKeysymToKeycode(dpy
, XK_Shift_R
);
2235 WMMaskEvent(dpy
, PointerMotionMask
| ButtonPressMask
| ExposureMask
| KeyPressMask
, &event
);
2237 if (!checkMouseSamplingRate(&event
))
2240 switch (event
.type
) {
2242 if ((event
.xkey
.keycode
== shiftl
)
2243 || (event
.xkey
.keycode
== shiftr
)) {
2244 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2245 cyclePositionDisplay(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2246 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2251 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2253 x
= event
.xmotion
.x_root
;
2254 y
= event
.xmotion
.y_root
;
2256 if (wPreferences
.move_display
== WDIS_FRAME_CENTER
)
2257 moveGeometryDisplayCentered(scr
, x
, y
+ (height
- h
) / 2);
2259 showPosition(wwin
, x
- width
/ 2, y
- h
/ 2);
2261 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2266 drawTransparentFrame(wwin
, x
- width
/ 2, y
- h
/ 2, width
, height
);
2268 *x_ret
= x
- width
/ 2;
2270 XUngrabPointer(dpy
, CurrentTime
);
2271 XUngrabKeyboard(dpy
, CurrentTime
);
2272 /* get rid of the geometry window */
2273 WMUnmapWidget(scr
->gview
);
2277 WMHandleEvent(&event
);