-
Notifications
You must be signed in to change notification settings - Fork 0
/
move.c
281 lines (250 loc) · 7.74 KB
/
move.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/****************************************************************************
* This module is all original code
* by Rob Nation ([email protected]
* Copyright 1993, Robert Nation
* You may use this code for any purpose, as long as the original
* copyright remains in the source code and all documentation
****************************************************************************/
/***********************************************************************
*
* code for moving windows
*
***********************************************************************/
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <X11/Xos.h>
#include <X11/keysym.h>
#include "fvwm.h"
#include "menus.h"
#include "misc.h"
#include "parse.h"
#include "screen.h"
extern XEvent Event;
extern int menuFromFrameOrWindowOrTitlebar;
extern Bool KeyboardGrabbed;
/****************************************************************************
*
* Start a window move operation
*
****************************************************************************/
void move_window(XEvent *eventp,Window w,FvwmWindow *tmp_win,int context)
{
extern int Stashed_X, Stashed_Y;
int origDragX,origDragY,DragX, DragY, DragWidth, DragHeight;
int XOffset, YOffset,FinalX,FinalY;
/* gotta have a window */
if(w == None)
return;
if(!Scr.ClickToFocus)
Scr.Focus = NULL;
InstallRootColormap();
if (menuFromFrameOrWindowOrTitlebar)
{
/* warp the pointer to the cursor position from before menu appeared*/
XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0,
Stashed_X,Stashed_Y);
XFlush(dpy);
}
while(XGrabPointer(dpy, Scr.Root, True,
ButtonPressMask | ButtonReleaseMask |
ButtonMotionMask | PointerMotionMask,
GrabModeAsync, GrabModeAsync,
Scr.Root, Scr.MoveCursor, CurrentTime)!=GrabSuccess);
if(!KeyboardGrabbed)
{
while(XGrabKeyboard(dpy, Scr.Root, True,GrabModeAsync, GrabModeAsync,
CurrentTime)!=GrabSuccess);
}
XGrabServer(dpy);
XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild,
&DragX, &DragY, &JunkX, &JunkY, &JunkMask);
if ((context & C_ICON) && tmp_win->icon_w)
w = tmp_win->icon_w;
else if (w != tmp_win->icon_w)
w = tmp_win->lead_w;
XGetGeometry(dpy, w, &JunkRoot, &origDragX, &origDragY,
(unsigned int *)&DragWidth, (unsigned int *)&DragHeight,
&JunkBW, &JunkDepth);
DragWidth += JunkBW;
DragHeight+= JunkBW;
XOffset = origDragX - DragX;
YOffset = origDragY - DragY;
moveLoop(tmp_win, XOffset,YOffset,DragWidth,DragHeight, &FinalX,&FinalY);
if (w == tmp_win->lead_w)
SetupFrame (tmp_win, FinalX, FinalY,
tmp_win->frame_width, tmp_win->frame_height,FALSE);
else /* icon window */
{
XMoveWindow (dpy, w, FinalX, FinalY);
if(w == tmp_win->icon_w)
{
tmp_win->icon_x_loc = FinalX;
tmp_win->icon_y_loc = FinalY;
}
}
XRaiseWindow(dpy,w);
Scr.LastWindowRaised = tmp_win;
KeepOnTop();
UninstallRootColormap();
XUngrabPointer(dpy,CurrentTime);
if(!KeyboardGrabbed)
{
XUngrabKeyboard(dpy,CurrentTime);
}
XUngrabServer(dpy);
RedrawPager();
return;
}
/****************************************************************************
*
* Move the rubberband around, return with the new window location
*
****************************************************************************/
void moveLoop(FvwmWindow *tmp_win, int XOffset, int YOffset, int Width,
int Height, int *FinalX, int *FinalY)
{
Bool finished = False;
Bool done;
int xl,yt,delta_x,delta_y,orig_Vx,orig_Vy;
XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild,&xl, &yt,
&JunkX, &JunkY, &JunkMask);
xl += XOffset;
yt += YOffset;
MoveOutline(Scr.Root, xl, yt, Width,Height);
while (!finished)
{
/* block until there is an interesting event */
XMaskEvent(dpy, ButtonPressMask | ButtonReleaseMask | KeyPressMask |
ExposureMask | PointerMotionMask | ButtonMotionMask |
VisibilityChangeMask, &Event);
if (Event.type == MotionNotify)
/* discard any extra motion events before a logical release */
while(XCheckMaskEvent(dpy, PointerMotionMask | ButtonMotionMask |
ButtonRelease, &Event))
if(Event.type == ButtonRelease) break;
done = FALSE;
/* Handle a limited number of key press events to allow mouseless
* operation */
if(Event.type == KeyPress)
Keyboard_shortcuts(&Event,ButtonRelease);
switch(Event.type)
{
case EnterNotify:
case KeyPress:
case LeaveNotify:
/* throw away enter and leave events until release */
done = TRUE;
break;
case ButtonRelease:
MoveOutline(Scr.Root, 0, 0, 0, 0);
*FinalX = Event.xmotion.x_root + XOffset;
*FinalY = Event.xmotion.y_root + YOffset;
done = TRUE;
finished = TRUE;
break;
case MotionNotify:
XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild,&xl, &yt,
&JunkX, &JunkY, &JunkMask);
/* need to move the viewport */
if((xl <2)||(xl > Scr.MyDisplayWidth-2)||
(yt <2)||(yt > Scr.MyDisplayHeight-2))
{
/* Turn off the rubberband */
MoveOutline(Scr.Root,0,0,0,0);
/* Move the viewport */
if(xl<2)
delta_x = - Scr.MyDisplayWidth;
else if (xl > Scr.MyDisplayWidth-2)
delta_x = Scr.MyDisplayWidth;
else
delta_x = 0;
if(yt<2)
delta_y = - Scr.MyDisplayHeight;
else if (yt > Scr.MyDisplayHeight-2)
delta_y = Scr.MyDisplayHeight;
else
delta_y = 0;
orig_Vx = Scr.Vx;
orig_Vy = Scr.Vy;
MoveViewport(Scr.Vx + delta_x,Scr.Vy + delta_y);
/* move the cursor back to the approximate correct location */
/* that is, the same place on the virtual desktop that it */
/* started at */
xl -= Scr.Vx - orig_Vx;
yt -= Scr.Vy - orig_Vy;
if(xl < 2)xl = 2;
if(yt < 2)yt = 2;
if(xl > Scr.MyDisplayWidth-2)xl = Scr.MyDisplayWidth-2;
if(yt > Scr.MyDisplayHeight-2)yt = Scr.MyDisplayHeight-2;
XWarpPointer(dpy,None,Scr.Root,0,0,0,0,xl,yt);
XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild,
&xl, &yt,
&JunkX, &JunkY, &JunkMask);
}
/* redraw the rubberband */
xl += XOffset;
yt += YOffset;
MoveOutline(Scr.Root, xl, yt, Width,Height);
done = TRUE;
break;
case ButtonPress:
done = TRUE;
break;
default:
break;
}
if(!done)
{
MoveOutline(Scr.Root,0,0,0,0);
DispatchEvent();
MoveOutline(Scr.Root, xl, yt, Width, Height);
}
}
}
/****************************************************************************
*
* For menus, move, and resize operations, we can effect keyboard
* shortcuts by warping the pointer.
*
****************************************************************************/
void Keyboard_shortcuts(XEvent *Event, int ReturnEvent)
{
int x,y,x_root,y_root;
int move_size,x_move,y_move;
KeySym keysym;
/* Pick the size of the cursor movement */
move_size = Scr.EntryHeight;
if(Event->xkey.state & ControlMask)
move_size = 1;
if(Event->xkey.state & ShiftMask)
move_size = 100;
keysym = XLookupKeysym(&Event->xkey,0);
x_move = 0;
y_move = 0;
if(keysym==XK_Up)
y_move = -move_size;
else if(keysym == XK_Down)
y_move = move_size;
else if(keysym == XK_Left)
x_move = -move_size;
else if(keysym == XK_Right)
x_move = move_size;
else if(keysym == XK_Return)
{
/* beat up the event */
Event->type = ReturnEvent;
}
if((x_move != 0)||(y_move != 0))
{
/* beat up the event */
XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild,
&x_root, &y_root, &x, &y, &JunkMask);
XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, x_root+x_move,
y_root+y_move);
/* beat up the event */
Event->type = MotionNotify;
Event->xkey.x += x_move;
Event->xkey.y += y_move;
}
}