ctwm.h revision 0bbfda8a
1/*
2 *       Copyright 1988 by Evans & Sutherland Computer Corporation,
3 *                          Salt Lake City, Utah
4 *  Portions Copyright 1989 by the Massachusetts Institute of Technology
5 *                        Cambridge, Massachusetts
6 *
7 * $XConsortium: twm.h,v 1.74 91/05/31 17:38:30 dave Exp $
8 *
9 * twm include file
10 *
11 * 28-Oct-87 Thomas E. LaStrange        File created
12 * 10-Oct-90 David M. Sternlicht        Storeing saved colors on root
13 *
14 * Copyright 1992 Claude Lecommandeur.
15 */
16#ifndef _CTWM_CTWM_H
17#define _CTWM_CTWM_H
18
19/*
20 * Include config first, before anything else.  Including ctwm.h should
21 * be the first action of any of our files, so this happens before
22 * ANYthing else, anywhere.
23 */
24#include "ctwm_config.h"
25
26#ifdef DMALLOC
27#include <dmalloc.h>
28#endif
29
30#include <stdbool.h>
31
32/*
33 * Intrinsic.h is needed for at least the Pixel type, which we use in
34 * this file.  And Intrinsic.h (always?) implicitly brings in Xlib.h
35 * anyway.
36 */
37//#include <X11/Xlib.h>
38#include <X11/Intrinsic.h>
39
40#include "types.h"
41#ifdef EWMH
42#include "ewmh.h"
43#endif
44
45/*
46 * This appears to be the standard way of testing this for portability,
47 * though calling it GNUC is sorta non-portable portability   :)
48 */
49#ifndef __GNUC__
50#define  __attribute__(x)  /*NOTHING*/
51#endif
52
53/* signal(3) handlers have been void since c89 */
54#define SIGNAL_T void
55
56#define BW 2                    /* border width */
57#define BW2 4                   /* border width  * 2 */
58
59#define MAX_BUTTONS     11      /* max mouse buttons supported */
60
61/* contexts for button presses */
62#define Alt1Mask        (1<<8)
63#define Alt2Mask        (1<<9)
64#define Alt3Mask        (1<<10)
65#define Alt4Mask        (1<<11)
66#define Alt5Mask        (1<<12)
67
68#define C_NO_CONTEXT    -1
69#define C_WINDOW        0
70#define C_TITLE         1
71#define C_ICON          2
72#define C_ROOT          3
73#define C_FRAME         4
74#define C_ICONMGR       5
75#define C_NAME          6
76#define C_IDENTIFY      7
77#define C_ALTERNATE     8
78#define C_WORKSPACE     9
79#define NUM_CONTEXTS    10
80
81#define C_WINDOW_BIT    (1 << C_WINDOW)
82#define C_TITLE_BIT     (1 << C_TITLE)
83#define C_ICON_BIT      (1 << C_ICON)
84#define C_ROOT_BIT      (1 << C_ROOT)
85#define C_FRAME_BIT     (1 << C_FRAME)
86#define C_ICONMGR_BIT   (1 << C_ICONMGR)
87#define C_NAME_BIT      (1 << C_NAME)
88#define C_ALTER_BIT     (1 << C_ALTERNATE)
89#define C_WORKSPACE_BIT (1 << C_WORKSPACE)
90
91#define C_ALL_BITS      (C_WINDOW_BIT | C_TITLE_BIT | C_ICON_BIT |\
92                         C_ROOT_BIT | C_FRAME_BIT | C_ICONMGR_BIT |\
93                         C_WORKSPACE_BIT)
94
95/* modifiers for button presses */
96#define MOD_SIZE        ((ShiftMask | ControlMask | Mod1Mask \
97                          | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask) + 1)
98
99/*
100 * Used for TwmWindow.zoomed.  Var holds the number of the function that
101 * caused zooming, if one has, else ZOOM_NONE.  This mirror F_NOP
102 * currently, but that's OK, because f.nop doesn't do anything, so it
103 * can't be a real cause of zooming.
104 */
105#define ZOOM_NONE 0
106
107#define FBF(fix_fore, fix_back, fix_font)\
108    Gcv.foreground = fix_fore;\
109    Gcv.background = fix_back;\
110    Gcv.font = fix_font;\
111    XChangeGC(dpy, Scr->NormalGC, GCFont|GCForeground|GCBackground,&Gcv)
112
113#define FB(fix_fore, fix_back)\
114    Gcv.foreground = fix_fore;\
115    Gcv.background = fix_back;\
116    XChangeGC(dpy, Scr->NormalGC, GCForeground|GCBackground,&Gcv)
117
118#define MaxSize(a, b)  (((a) < (b)) ? (b) : (a))
119#define MinSize(a, b)  (((a) > (b)) ? (b) : (a))
120
121struct MyFont {
122	char       *basename;       /* name of the font */
123	XFontSet    font_set;
124	int         ascent;
125	int         descent;
126	int         height;         /* height of the font */
127	int         y;              /* Y coordinate to draw characters */
128	/* Average height, maintained using the extra two auxiliary fields.  */
129	unsigned int avg_height;
130	float       avg_fheight;
131	unsigned int avg_count;
132};
133
134struct ColorPair {
135	Pixel fore, back, shadc, shadd;
136};
137
138struct TitleButtonFunc {
139	struct TitleButtonFunc *next;  /* next in the list of function buttons */
140	int num;                       /* button number */
141	int mods;                      /* modifiers */
142	int func;                      /* function to execute */
143	char *action;                  /* optional action arg */
144	struct MenuRoot *menuroot;     /* menu to pop on F_MENU */
145};
146
147struct TitleButton {
148	struct TitleButton *next;           /* next link in chain */
149	char *name;                         /* bitmap name in case of deferal */
150	Image *image;                       /* image to display in button */
151	int srcx, srcy;                     /* from where to start copying */
152	unsigned int width, height;         /* size of pixmap */
153	int dstx, dsty;                     /* to where to start copying */
154	bool rightside;                     /* t: on right, f: on left */
155	TitleButtonFunc *funs;              /* funcs assoc'd to each button */
156};
157
158struct TBWindow {
159	Window window;                      /* which window in this frame */
160	Image *image;                       /* image to display in button */
161	TitleButton *info;                  /* description of this window */
162};
163
164
165typedef enum {
166	SIJ_LEFT,
167	SIJ_CENTER,
168	SIJ_RIGHT,
169} SIJust;
170
171struct SqueezeInfo {
172	SIJust justify;
173	int num;                            /* signed pixel count or numerator */
174	int denom;                          /* 0 for pix count or denominator */
175};
176
177
178/*
179 * Type for IconRegion alignment and config entries relating
180 *
181 * Misspeelt for hysterical raisins
182 */
183typedef enum {
184	IRA_UNDEF,
185	IRA_TOP,
186	IRA_CENTER,
187	IRA_BOTTOM,
188	IRA_BORDER,
189} IRAlignement;
190
191/*
192 * Justification for title stuff.  Window titles (TitleJustification),
193 * icon titles (IconJustification).  _Not_ the same as for
194 * IconRegionJustification.
195 */
196typedef enum {
197	TJ_UNDEF,
198	TJ_LEFT,
199	TJ_CENTER,
200	TJ_RIGHT,
201} TitleJust;
202
203/*
204 * And IconRegion Justification's.
205 */
206typedef enum {
207	IRJ_UNDEF,
208	IRJ_LEFT,
209	IRJ_CENTER,
210	IRJ_RIGHT,
211	IRJ_BORDER,
212} IRJust;
213
214
215/*
216 * Gravity used by IconRegion and WindowRegion.  Strictly, there should
217 * probably be separate vertical/horizontal types, but it'll take some
218 * nontrivial code reshuffling to make that possible because of how the
219 * values are used in the split* functions.
220 */
221typedef enum {
222	GRAV_NORTH,
223	GRAV_EAST,
224	GRAV_SOUTH,
225	GRAV_WEST,
226} RegGravity;
227
228
229/* RandomPlacement bits */
230typedef enum {
231	RP_OFF,
232	RP_ALL,
233	RP_UNMAPPED,
234} RandPlac;
235
236/* UsePPosition */
237typedef enum {
238	PPOS_OFF,
239	PPOS_ON,
240	PPOS_NON_ZERO,
241	/*
242	 * may eventually want an option for having the PPosition be the
243	 * initial location for the drag lines.
244	 */
245} UsePPoss;
246
247
248/* Colormap window entry for each window in WM_COLORMAP_WINDOWS
249 * ICCCM property.
250 */
251struct TwmColormap {
252	Colormap c;                 /* Colormap id */
253	int state;                  /* install(ability) state */
254	unsigned long install_req;  /* request number which installed it */
255	Window w;                   /* window causing load of color table */
256	int refcnt;
257};
258
259/* TwmColormap.state bit definitions */
260#define CM_INSTALLABLE          1
261#define CM_INSTALLED            2
262#define CM_INSTALL              4
263
264
265struct ColormapWindow {
266	Window w;                   /* Window id */
267	TwmColormap *colormap;      /* Colormap for this window */
268	int visibility;             /* Visibility of this window */
269	int refcnt;
270};
271
272struct Colormaps {
273	ColormapWindow **cwins;     /* current list of colormap windows */
274	int number_cwins;           /* number of elements in current list */
275	char *scoreboard;           /* conflicts between installable colortables */
276};
277
278#define ColormapsScoreboardLength(cm) ((cm)->number_cwins * \
279                                       ((cm)->number_cwins - 1) / 2)
280
281struct WindowRegion {
282	struct WindowRegion *next;
283	int                 x, y, w, h;
284	RegGravity          grav1, grav2;
285	name_list           *clientlist;
286	struct WindowEntry  *entries;
287};
288
289struct WindowEntry {
290	struct WindowEntry  *next;
291	int                 x, y, w, h;
292	struct TwmWindow    *twm_win;
293	bool                used;
294};
295
296struct WindowBox {
297	struct WindowBox    *next;
298	char                *name;
299	char                *geometry;
300	name_list           *winlist;
301	Window              window;
302	struct TwmWindow    *twmwin;
303};
304
305
306/*
307 * Pull in struct TwmWindow.  Moved to a separate file to ease scanning
308 * through both it and the other stuff in here.
309 */
310#include "twm_window_struct.h"
311
312
313/* Flags for TwmWindow.protocols */
314#define DoesWmTakeFocus         (1L << 0)
315#define DoesWmSaveYourself      (1L << 1)
316#define DoesWmDeleteWindow      (1L << 2)
317
318
319void Reborder(Time tim);
320SIGNAL_T Done(int signum) __attribute__((noreturn));
321void CreateFonts(ScreenInfo *scr);
322
323void RestoreWithdrawnLocation(TwmWindow *tmp);
324extern char *ProgramName;
325extern Display *dpy;
326extern XtAppContext appContext;
327extern Window ResizeWindow;     /* the window we are resizing */
328extern bool HasShape;           /* this server supports Shape extension */
329extern int ShapeEventBase, ShapeErrorBase;
330
331extern int PreviousScreen;
332
333extern Cursor UpperLeftCursor;
334extern Cursor RightButt;
335extern Cursor MiddleButt;
336extern Cursor LeftButt;
337
338extern XClassHint NoClass;
339
340extern XContext TwmContext;
341extern XContext MenuContext;
342extern XContext ScreenContext;
343extern XContext ColormapContext;
344
345extern char *Home;
346extern int HomeLen;
347
348extern bool HandlingEvents;
349extern Cursor TopCursor, TopLeftCursor, LeftCursor, BottomLeftCursor,
350       BottomCursor, BottomRightCursor, RightCursor, TopRightCursor;
351
352/* Junk vars; see comment in ctwm.c about usage */
353extern Window JunkRoot, JunkChild;
354extern int JunkX, JunkY;
355extern unsigned int JunkWidth, JunkHeight, JunkBW, JunkDepth, JunkMask;
356
357extern XGCValues Gcv;
358extern int Argc;
359extern char **Argv;
360
361extern bool RestartPreviousState;
362
363extern bool RestartFlag;        /* Flag that is set when SIGHUP is caught */
364void DoRestart(Time t);         /* Function to perform a restart */
365
366#define OCCUPY(w, b) ((b == NULL) ? 1 : (w->occupation & (1 << b->number)))
367
368
369/*
370 * Command-line arg handling bits
371 */
372typedef struct _ctwm_cl_args {
373	bool   MultiScreen;        // ! --single, grab multiple screens
374	bool   Monochrome;         // --mono, force monochrome
375	bool   cfgchk;             // --cfgchk, check config and exit
376	char  *InitFile;           // --file, config filename
377	char  *display_name;       // --display, X server display
378
379	bool   PrintErrorMessages; // --verbose, show more debug output
380	bool   ShowWelcomeWindow;  // ! --nowelcome, show splash screen
381
382	bool   is_captive;         // --window (flag), running captive
383	Window capwin;             // --window (arg), existing window to capture
384	char  *captivename;        // --name, captive name
385
386#ifdef USEM4
387	bool   KeepTmpFile;        // --keep-defs, keep generated m4 defs
388	char  *keepM4_filename;    // --keep, keep m4 post-processed output
389	bool   GoThroughM4;        // ! --nom4, do m4 processing
390#endif
391
392#ifdef EWMH
393	bool   ewmh_replace;       // --replace, replacing running WM
394#endif
395
396	char  *client_id;          // --clientId, session client id
397	char  *restore_filename;   // --restore, session filename
398} ctwm_cl_args;
399extern ctwm_cl_args CLarg;
400
401
402#endif /* _CTWM_CTWM_H */
403