-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.c
280 lines (250 loc) · 8.19 KB
/
functions.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 based on Twm, but has been siginificantly modified
* by Rob Nation ([email protected]
****************************************************************************/
/*****************************************************************************/
/** Copyright 1988 by Evans & Sutherland Computer Corporation, **/
/** Salt Lake City, Utah **/
/** Portions Copyright 1989 by the Massachusetts Institute of Technology **/
/** Cambridge, Massachusetts **/
/** **/
/** All Rights Reserved **/
/** **/
/** Permission to use, copy, modify, and distribute this software and **/
/** its documentation for any purpose and without fee is hereby **/
/** granted, provided that the above copyright notice appear in all **/
/** copies and that both that copyright notice and this permis- **/
/** sion notice appear in supporting documentation, and that the **/
/** names of Evans & Sutherland and M.I.T. not be used in advertising **/
/** in publicity pertaining to distribution of the software without **/
/** specific, written prior permission. **/
/** **/
/** EVANS & SUTHERLAND AND M.I.T. DISCLAIM ALL WARRANTIES WITH REGARD **/
/** TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT- **/
/** ABILITY AND FITNESS, IN NO EVENT SHALL EVANS & SUTHERLAND OR **/
/** M.I.T. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAM- **/
/** AGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA **/
/** OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER **/
/** TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE **/
/** OR PERFORMANCE OF THIS SOFTWARE. **/
/*****************************************************************************/
/***********************************************************************
*
* fvwm menu code
*
***********************************************************************/
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <X11/Xos.h>
#include "fvwm.h"
#include "menus.h"
#include "misc.h"
#include "parse.h"
#include "screen.h"
extern XEvent Event;
extern int menuFromFrameOrWindowOrTitlebar;
extern FvwmWindow *Tmp_win;
/***********************************************************************
*
* Procedure:
* DeIconify a window
*
***********************************************************************/
void DeIconify(FvwmWindow *tmp_win)
{
FvwmWindow *t;
/* now de-iconify transients */
for (t = Scr.FvwmRoot.next; t != NULL; t = t->next)
{
if ((t == tmp_win)||
((t->flags & TRANSIENT) &&(t->transientfor == tmp_win->w)))
{
t->flags |= MAPPED;
if(t->title_height)
XMapWindow(dpy, t->w);
XMapRaised(dpy, t->lead_w);
SetMapStateProp(t, NormalState);
if (t->icon_w)
XUnmapWindow(dpy, t->icon_w);
t->flags &= ~ICON;
}
}
Scr.LastWindowRaised = t;
KeepOnTop();
RedrawPager();
XSync (dpy, 0);
return;
}
/****************************************************************************
*
* Iconifies the selected window
*
****************************************************************************/
void Iconify(FvwmWindow *tmp_win, int def_x, int def_y)
{
FvwmWindow *t;
XWindowAttributes winattrs;
unsigned long eventMask;
XGetWindowAttributes(dpy, tmp_win->w, &winattrs);
eventMask = winattrs.your_event_mask;
/* iconify transients first */
for (t = Scr.FvwmRoot.next; t != NULL; t = t->next)
{
if ((t==tmp_win)||
((t->flags & TRANSIENT) && (t->transientfor == tmp_win->w)))
{
/*
* Prevent the receipt of an UnmapNotify, since that would
* cause a transition to the Withdrawn state.
*/
t->flags &= ~MAPPED;
XSelectInput(dpy, t->w, eventMask & ~StructureNotifyMask);
XUnmapWindow(dpy, t->w);
XSelectInput(dpy, t->w, eventMask);
if(t->title_height)
XUnmapWindow(dpy, t->frame);
if (t->icon_w)
XUnmapWindow(dpy, t->icon_w);
SetMapStateProp(t, IconicState);
SetBorder (t, False,False,False);
t->flags |= ICON;
}
}
if (tmp_win->icon_w == (int)NULL)
CreateIconWindow(tmp_win, def_x, def_y);
XMapRaised(dpy, tmp_win->icon_w);
Scr.LastWindowRaised = tmp_win;
RedrawPager();
KeepOnTop();
XSync (dpy, 0);
return;
}
/****************************************************************************
*
* ??????????????????????Got this from twm?????????????????????????
*
****************************************************************************/
void SetMapStateProp(FvwmWindow *tmp_win, int state)
{
unsigned long data[2]; /* "suggested" by ICCCM version 1 */
data[0] = (unsigned long) state;
data[1] = (unsigned long) tmp_win->icon_w;
XChangeProperty (dpy, tmp_win->w, _XA_WM_STATE, _XA_WM_STATE, 32,
PropModeReplace, (unsigned char *) data, 2);
return;
}
/****************************************************************************
*
* Keeps the "StaysOnTop" windows on the top of the pile.
* This is achieved by clearing a flag for OnTop windows here, and waiting
* for a visibility notify on the windows. Eception: OnTop windows which are
* obscured by other OnTop windows, which need to be raised here.
*
****************************************************************************/
void KeepOnTop()
{
FvwmWindow *t;
/* flag that on-top windows should be re-raised */
for (t = Scr.FvwmRoot.next; t != NULL; t = t->next)
{
if((t->flags & ONTOP)&& !(t->flags & VISIBLE))
{
if(t->icon_w)
XRaiseWindow(dpy,t->icon_w);
XRaiseWindow(dpy,t->lead_w);
t->flags &= ~RAISED;
}
else
t->flags |= RAISED;
}
}
/***************************************************************************
*
* Moves the viewport within thwe virtual desktop
*
***************************************************************************/
void MoveViewport(int newx, int newy)
{
FvwmWindow *t;
int deltax,deltay;
if(newx > Scr.VxMax)
newx = Scr.VxMax;
if(newy > Scr.VyMax)
newy = Scr.VyMax;
if(newx <0)
newx = 0;
if(newy <0)
newy = 0;
deltay = Scr.Vy - newy;
deltax = Scr.Vx - newx;
ShowCurrentPort();
if((deltax!=0)||(deltay!=0))
{
for (t = Scr.FvwmRoot.next; t != NULL; t = t->next)
{
if(!(t->flags & STICKY))
{
if(t->icon_w)
{
t->icon_x_loc += deltax;
t->icon_y_loc += deltay;
XMoveWindow(dpy,t->icon_w,t->icon_x_loc,t->icon_y_loc);
}
t->frame_x += deltax;
t->frame_y += deltay;
XMoveWindow(dpy,t->lead_w,t->frame_x,t->frame_y);
}
}
}
Scr.Vx = newx;
Scr.Vy = newy;
ShowCurrentPort();
}
/**************************************************************************
*
* Moves focus to specified window
*
*************************************************************************/
void FocusOn(FvwmWindow *t)
{
int dx,dy;
int cx,cy,x,y;
if(t == (FvwmWindow *)0)
return;
if(t->flags & ICON)
{
cx = t->icon_x_loc + t->icon_w_width/2;
cy = t->icon_y_loc + ICON_HEIGHT/2;
}
else
{
cx = t->frame_x + t->frame_width/2;
cy = t->frame_y + t->frame_height/2;
}
/* Put center of window on the visible screen */
if(Scr.CenterOnCirculate)
{
dx = cx - Scr.MyDisplayWidth/2 + Scr.Vx;
dy = cy - Scr.MyDisplayHeight/2 + Scr.Vy;
}
else
{
dx = (cx + Scr.Vx)/Scr.MyDisplayWidth*Scr.MyDisplayWidth;
dy = (cy +Scr.Vy)/Scr.MyDisplayHeight*Scr.MyDisplayHeight;
}
MoveViewport(dx,dy);
if(t->flags & ICON)
{
x = t->icon_x_loc;
y = t->icon_y_loc;
}
else
{
x = t->frame_x;
y = t->frame_y;
}
XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, x+2,y+2);
XRaiseWindow(dpy,t->lead_w);
SetBorder(t,True,False,True);
}