10bbfda8aSnia/*
20bbfda8aSnia *       Copyright 1988 by Evans & Sutherland Computer Corporation,
30bbfda8aSnia *                          Salt Lake City, Utah
40bbfda8aSnia *  Portions Copyright 1989 by the Massachusetts Institute of Technology
50bbfda8aSnia *                        Cambridge, Massachusetts
6645f5050Syouri *
70bbfda8aSnia * $XConsortium: twm.h,v 1.74 91/05/31 17:38:30 dave Exp $
8645f5050Syouri *
90bbfda8aSnia * twm include file
10645f5050Syouri *
110bbfda8aSnia * 28-Oct-87 Thomas E. LaStrange        File created
120bbfda8aSnia * 10-Oct-90 David M. Sternlicht        Storeing saved colors on root
130bbfda8aSnia *
140bbfda8aSnia * Copyright 1992 Claude Lecommandeur.
150bbfda8aSnia */
160bbfda8aSnia#ifndef _CTWM_CTWM_H
170bbfda8aSnia#define _CTWM_CTWM_H
180bbfda8aSnia
190bbfda8aSnia/*
200bbfda8aSnia * Include config first, before anything else.  Including ctwm.h should
210bbfda8aSnia * be the first action of any of our files, so this happens before
220bbfda8aSnia * ANYthing else, anywhere.
230bbfda8aSnia */
240bbfda8aSnia#include "ctwm_config.h"
250bbfda8aSnia
260bbfda8aSnia#ifdef DMALLOC
270bbfda8aSnia#include <dmalloc.h>
280bbfda8aSnia#endif
290bbfda8aSnia
300bbfda8aSnia#include <stdbool.h>
310bbfda8aSnia
320bbfda8aSnia/*
330bbfda8aSnia * Intrinsic.h is needed for at least the Pixel type, which we use in
340bbfda8aSnia * this file.  And Intrinsic.h (always?) implicitly brings in Xlib.h
350bbfda8aSnia * anyway.
360bbfda8aSnia */
370bbfda8aSnia//#include <X11/Xlib.h>
380bbfda8aSnia#include <X11/Intrinsic.h>
390bbfda8aSnia
400bbfda8aSnia#include "types.h"
410bbfda8aSnia#ifdef EWMH
420bbfda8aSnia#include "ewmh.h"
430bbfda8aSnia#endif
440bbfda8aSnia
450bbfda8aSnia/*
460bbfda8aSnia * This appears to be the standard way of testing this for portability,
470bbfda8aSnia * though calling it GNUC is sorta non-portable portability   :)
480bbfda8aSnia */
490bbfda8aSnia#ifndef __GNUC__
500bbfda8aSnia#define  __attribute__(x)  /*NOTHING*/
510bbfda8aSnia#endif
520bbfda8aSnia
530bbfda8aSnia#define BW 2                    /* border width */
540bbfda8aSnia#define BW2 4                   /* border width  * 2 */
550bbfda8aSnia
560bbfda8aSnia#define MAX_BUTTONS     11      /* max mouse buttons supported */
570bbfda8aSnia
58df1c27a6Snia
59df1c27a6Snia/*
60df1c27a6Snia * Contexts for button presses.
61df1c27a6Snia * n.b.: These go alongside the ModXMask X11 defs, so better stay above
62df1c27a6Snia * them!
63df1c27a6Snia */
640bbfda8aSnia#define Alt1Mask        (1<<8)
650bbfda8aSnia#define Alt2Mask        (1<<9)
660bbfda8aSnia#define Alt3Mask        (1<<10)
670bbfda8aSnia#define Alt4Mask        (1<<11)
680bbfda8aSnia#define Alt5Mask        (1<<12)
690bbfda8aSnia
70df1c27a6Snia// X-ref the Over_Mask's used for testing in mk_twmkeys_entry() if we
71df1c27a6Snia// grow more here, to avoid collision.
72df1c27a6Snia
73df1c27a6Snia
740bbfda8aSnia#define C_NO_CONTEXT    -1
750bbfda8aSnia#define C_WINDOW        0
760bbfda8aSnia#define C_TITLE         1
770bbfda8aSnia#define C_ICON          2
780bbfda8aSnia#define C_ROOT          3
790bbfda8aSnia#define C_FRAME         4
800bbfda8aSnia#define C_ICONMGR       5
810bbfda8aSnia#define C_NAME          6
820bbfda8aSnia#define C_IDENTIFY      7
830bbfda8aSnia#define C_ALTERNATE     8
840bbfda8aSnia#define C_WORKSPACE     9
850bbfda8aSnia#define NUM_CONTEXTS    10
860bbfda8aSnia
870bbfda8aSnia#define C_WINDOW_BIT    (1 << C_WINDOW)
880bbfda8aSnia#define C_TITLE_BIT     (1 << C_TITLE)
890bbfda8aSnia#define C_ICON_BIT      (1 << C_ICON)
900bbfda8aSnia#define C_ROOT_BIT      (1 << C_ROOT)
910bbfda8aSnia#define C_FRAME_BIT     (1 << C_FRAME)
920bbfda8aSnia#define C_ICONMGR_BIT   (1 << C_ICONMGR)
930bbfda8aSnia#define C_NAME_BIT      (1 << C_NAME)
940bbfda8aSnia#define C_ALTER_BIT     (1 << C_ALTERNATE)
950bbfda8aSnia#define C_WORKSPACE_BIT (1 << C_WORKSPACE)
960bbfda8aSnia
970bbfda8aSnia#define C_ALL_BITS      (C_WINDOW_BIT | C_TITLE_BIT | C_ICON_BIT |\
980bbfda8aSnia                         C_ROOT_BIT | C_FRAME_BIT | C_ICONMGR_BIT |\
990bbfda8aSnia                         C_WORKSPACE_BIT)
1000bbfda8aSnia
1010bbfda8aSnia/* modifiers for button presses */
1020bbfda8aSnia#define MOD_SIZE        ((ShiftMask | ControlMask | Mod1Mask \
1030bbfda8aSnia                          | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask) + 1)
1040bbfda8aSnia
1050bbfda8aSnia/*
1060bbfda8aSnia * Used for TwmWindow.zoomed.  Var holds the number of the function that
1070bbfda8aSnia * caused zooming, if one has, else ZOOM_NONE.  This mirror F_NOP
1080bbfda8aSnia * currently, but that's OK, because f.nop doesn't do anything, so it
1090bbfda8aSnia * can't be a real cause of zooming.
1100bbfda8aSnia */
1110bbfda8aSnia#define ZOOM_NONE 0
1120bbfda8aSnia
1130bbfda8aSnia#define FBF(fix_fore, fix_back, fix_font)\
1140bbfda8aSnia    Gcv.foreground = fix_fore;\
1150bbfda8aSnia    Gcv.background = fix_back;\
1160bbfda8aSnia    Gcv.font = fix_font;\
1170bbfda8aSnia    XChangeGC(dpy, Scr->NormalGC, GCFont|GCForeground|GCBackground,&Gcv)
1180bbfda8aSnia
1190bbfda8aSnia#define FB(fix_fore, fix_back)\
1200bbfda8aSnia    Gcv.foreground = fix_fore;\
1210bbfda8aSnia    Gcv.background = fix_back;\
1220bbfda8aSnia    XChangeGC(dpy, Scr->NormalGC, GCForeground|GCBackground,&Gcv)
1230bbfda8aSnia
1240bbfda8aSnia#define MaxSize(a, b)  (((a) < (b)) ? (b) : (a))
1250bbfda8aSnia#define MinSize(a, b)  (((a) > (b)) ? (b) : (a))
1260bbfda8aSnia
1270bbfda8aSniastruct MyFont {
1280bbfda8aSnia	char       *basename;       /* name of the font */
1290bbfda8aSnia	XFontSet    font_set;
1300bbfda8aSnia	int         ascent;
1310bbfda8aSnia	int         descent;
1320bbfda8aSnia	int         height;         /* height of the font */
1330bbfda8aSnia	int         y;              /* Y coordinate to draw characters */
1340bbfda8aSnia	/* Average height, maintained using the extra two auxiliary fields.  */
1350bbfda8aSnia	unsigned int avg_height;
1360bbfda8aSnia	float       avg_fheight;
1370bbfda8aSnia	unsigned int avg_count;
1380bbfda8aSnia};
1390bbfda8aSnia
1400bbfda8aSniastruct ColorPair {
1410bbfda8aSnia	Pixel fore, back, shadc, shadd;
1420bbfda8aSnia};
1430bbfda8aSnia
1440bbfda8aSniastruct TitleButtonFunc {
1450bbfda8aSnia	struct TitleButtonFunc *next;  /* next in the list of function buttons */
1460bbfda8aSnia	int num;                       /* button number */
1470bbfda8aSnia	int mods;                      /* modifiers */
1480bbfda8aSnia	int func;                      /* function to execute */
1490bbfda8aSnia	char *action;                  /* optional action arg */
1500bbfda8aSnia	struct MenuRoot *menuroot;     /* menu to pop on F_MENU */
1510bbfda8aSnia};
1520bbfda8aSnia
1530bbfda8aSniastruct TitleButton {
1540bbfda8aSnia	struct TitleButton *next;           /* next link in chain */
1550bbfda8aSnia	char *name;                         /* bitmap name in case of deferal */
1560bbfda8aSnia	Image *image;                       /* image to display in button */
1570bbfda8aSnia	int srcx, srcy;                     /* from where to start copying */
1580bbfda8aSnia	unsigned int width, height;         /* size of pixmap */
1590bbfda8aSnia	int dstx, dsty;                     /* to where to start copying */
1600bbfda8aSnia	bool rightside;                     /* t: on right, f: on left */
1610bbfda8aSnia	TitleButtonFunc *funs;              /* funcs assoc'd to each button */
1620bbfda8aSnia};
1630bbfda8aSnia
1640bbfda8aSniastruct TBWindow {
1650bbfda8aSnia	Window window;                      /* which window in this frame */
1660bbfda8aSnia	Image *image;                       /* image to display in button */
1670bbfda8aSnia	TitleButton *info;                  /* description of this window */
1680bbfda8aSnia};
1690bbfda8aSnia
1700bbfda8aSnia
1710bbfda8aSniatypedef enum {
1720bbfda8aSnia	SIJ_LEFT,
1730bbfda8aSnia	SIJ_CENTER,
1740bbfda8aSnia	SIJ_RIGHT,
1750bbfda8aSnia} SIJust;
1760bbfda8aSnia
1770bbfda8aSniastruct SqueezeInfo {
1780bbfda8aSnia	SIJust justify;
1790bbfda8aSnia	int num;                            /* signed pixel count or numerator */
1800bbfda8aSnia	int denom;                          /* 0 for pix count or denominator */
1810bbfda8aSnia};
1820bbfda8aSnia
1830bbfda8aSnia
1840bbfda8aSnia/*
1850bbfda8aSnia * Type for IconRegion alignment and config entries relating
1860bbfda8aSnia *
1870bbfda8aSnia * Misspeelt for hysterical raisins
1880bbfda8aSnia */
1890bbfda8aSniatypedef enum {
1900bbfda8aSnia	IRA_UNDEF,
1910bbfda8aSnia	IRA_TOP,
1920bbfda8aSnia	IRA_CENTER,
1930bbfda8aSnia	IRA_BOTTOM,
1940bbfda8aSnia	IRA_BORDER,
1950bbfda8aSnia} IRAlignement;
1960bbfda8aSnia
1970bbfda8aSnia/*
1980bbfda8aSnia * Justification for title stuff.  Window titles (TitleJustification),
1990bbfda8aSnia * icon titles (IconJustification).  _Not_ the same as for
2000bbfda8aSnia * IconRegionJustification.
2010bbfda8aSnia */
2020bbfda8aSniatypedef enum {
2030bbfda8aSnia	TJ_UNDEF,
2040bbfda8aSnia	TJ_LEFT,
2050bbfda8aSnia	TJ_CENTER,
2060bbfda8aSnia	TJ_RIGHT,
2070bbfda8aSnia} TitleJust;
2080bbfda8aSnia
2090bbfda8aSnia/*
2100bbfda8aSnia * And IconRegion Justification's.
2110bbfda8aSnia */
2120bbfda8aSniatypedef enum {
2130bbfda8aSnia	IRJ_UNDEF,
2140bbfda8aSnia	IRJ_LEFT,
2150bbfda8aSnia	IRJ_CENTER,
2160bbfda8aSnia	IRJ_RIGHT,
2170bbfda8aSnia	IRJ_BORDER,
2180bbfda8aSnia} IRJust;
2190bbfda8aSnia
2200bbfda8aSnia
2210bbfda8aSnia/*
2220bbfda8aSnia * Gravity used by IconRegion and WindowRegion.  Strictly, there should
2230bbfda8aSnia * probably be separate vertical/horizontal types, but it'll take some
2240bbfda8aSnia * nontrivial code reshuffling to make that possible because of how the
2250bbfda8aSnia * values are used in the split* functions.
2260bbfda8aSnia */
2270bbfda8aSniatypedef enum {
2280bbfda8aSnia	GRAV_NORTH,
2290bbfda8aSnia	GRAV_EAST,
2300bbfda8aSnia	GRAV_SOUTH,
2310bbfda8aSnia	GRAV_WEST,
2320bbfda8aSnia} RegGravity;
2330bbfda8aSnia
2340bbfda8aSnia
2350bbfda8aSnia/* RandomPlacement bits */
2360bbfda8aSniatypedef enum {
2370bbfda8aSnia	RP_OFF,
2380bbfda8aSnia	RP_ALL,
2390bbfda8aSnia	RP_UNMAPPED,
2400bbfda8aSnia} RandPlac;
2410bbfda8aSnia
2420bbfda8aSnia/* UsePPosition */
2430bbfda8aSniatypedef enum {
2440bbfda8aSnia	PPOS_OFF,
2450bbfda8aSnia	PPOS_ON,
2460bbfda8aSnia	PPOS_NON_ZERO,
2470bbfda8aSnia	/*
2480bbfda8aSnia	 * may eventually want an option for having the PPosition be the
2490bbfda8aSnia	 * initial location for the drag lines.
2500bbfda8aSnia	 */
2510bbfda8aSnia} UsePPoss;
2520bbfda8aSnia
2530bbfda8aSnia
2540bbfda8aSnia/* Colormap window entry for each window in WM_COLORMAP_WINDOWS
2550bbfda8aSnia * ICCCM property.
2560bbfda8aSnia */
2570bbfda8aSniastruct TwmColormap {
2580bbfda8aSnia	Colormap c;                 /* Colormap id */
2590bbfda8aSnia	int state;                  /* install(ability) state */
2600bbfda8aSnia	unsigned long install_req;  /* request number which installed it */
2610bbfda8aSnia	Window w;                   /* window causing load of color table */
2620bbfda8aSnia	int refcnt;
2630bbfda8aSnia};
2640bbfda8aSnia
2650bbfda8aSnia/* TwmColormap.state bit definitions */
2660bbfda8aSnia#define CM_INSTALLABLE          1
2670bbfda8aSnia#define CM_INSTALLED            2
2680bbfda8aSnia#define CM_INSTALL              4
2690bbfda8aSnia
2700bbfda8aSnia
2710bbfda8aSniastruct ColormapWindow {
2720bbfda8aSnia	Window w;                   /* Window id */
2730bbfda8aSnia	TwmColormap *colormap;      /* Colormap for this window */
2740bbfda8aSnia	int visibility;             /* Visibility of this window */
2750bbfda8aSnia	int refcnt;
2760bbfda8aSnia};
2770bbfda8aSnia
2780bbfda8aSniastruct Colormaps {
2790bbfda8aSnia	ColormapWindow **cwins;     /* current list of colormap windows */
2800bbfda8aSnia	int number_cwins;           /* number of elements in current list */
2810bbfda8aSnia	char *scoreboard;           /* conflicts between installable colortables */
2820bbfda8aSnia};
2830bbfda8aSnia
2840bbfda8aSnia#define ColormapsScoreboardLength(cm) ((cm)->number_cwins * \
2850bbfda8aSnia                                       ((cm)->number_cwins - 1) / 2)
2860bbfda8aSnia
2870bbfda8aSniastruct WindowRegion {
2880bbfda8aSnia	struct WindowRegion *next;
2890bbfda8aSnia	int                 x, y, w, h;
2900bbfda8aSnia	RegGravity          grav1, grav2;
2910bbfda8aSnia	name_list           *clientlist;
2920bbfda8aSnia	struct WindowEntry  *entries;
2930bbfda8aSnia};
2940bbfda8aSnia
2950bbfda8aSniastruct WindowEntry {
2960bbfda8aSnia	struct WindowEntry  *next;
2970bbfda8aSnia	int                 x, y, w, h;
2980bbfda8aSnia	struct TwmWindow    *twm_win;
2990bbfda8aSnia	bool                used;
3000bbfda8aSnia};
3010bbfda8aSnia
302df1c27a6Snia#ifdef WINBOX
3030bbfda8aSniastruct WindowBox {
3040bbfda8aSnia	struct WindowBox    *next;
3050bbfda8aSnia	char                *name;
3060bbfda8aSnia	char                *geometry;
3070bbfda8aSnia	name_list           *winlist;
3080bbfda8aSnia	Window              window;
3090bbfda8aSnia	struct TwmWindow    *twmwin;
3100bbfda8aSnia};
311df1c27a6Snia#endif
3120bbfda8aSnia
3130bbfda8aSnia
3140bbfda8aSnia/*
3150bbfda8aSnia * Pull in struct TwmWindow.  Moved to a separate file to ease scanning
3160bbfda8aSnia * through both it and the other stuff in here.
3170bbfda8aSnia */
3180bbfda8aSnia#include "twm_window_struct.h"
3190bbfda8aSnia
3200bbfda8aSnia
3210bbfda8aSnia/* Flags for TwmWindow.protocols */
3220bbfda8aSnia#define DoesWmTakeFocus         (1L << 0)
3230bbfda8aSnia#define DoesWmSaveYourself      (1L << 1)
3240bbfda8aSnia#define DoesWmDeleteWindow      (1L << 2)
3250bbfda8aSnia
3260bbfda8aSnia
3270bbfda8aSniaextern char *ProgramName;
328df1c27a6Sniaextern size_t ProgramNameLen;
3290bbfda8aSniaextern Display *dpy;
3300bbfda8aSniaextern XtAppContext appContext;
3310bbfda8aSniaextern Window ResizeWindow;     /* the window we are resizing */
3320bbfda8aSniaextern bool HasShape;           /* this server supports Shape extension */
3330bbfda8aSniaextern int ShapeEventBase, ShapeErrorBase;
3340bbfda8aSnia
3350bbfda8aSniaextern int PreviousScreen;
3360bbfda8aSnia
3370bbfda8aSniaextern Cursor UpperLeftCursor;
3380bbfda8aSniaextern Cursor RightButt;
3390bbfda8aSniaextern Cursor MiddleButt;
3400bbfda8aSniaextern Cursor LeftButt;
3410bbfda8aSnia
3420bbfda8aSniaextern XClassHint NoClass;
3430bbfda8aSnia
3440bbfda8aSniaextern XContext TwmContext;
3450bbfda8aSniaextern XContext MenuContext;
3460bbfda8aSniaextern XContext ScreenContext;
3470bbfda8aSniaextern XContext ColormapContext;
3480bbfda8aSnia
3490bbfda8aSniaextern char *Home;
3500bbfda8aSniaextern int HomeLen;
3510bbfda8aSnia
3520bbfda8aSniaextern bool HandlingEvents;
3530bbfda8aSniaextern Cursor TopCursor, TopLeftCursor, LeftCursor, BottomLeftCursor,
3540bbfda8aSnia       BottomCursor, BottomRightCursor, RightCursor, TopRightCursor;
3550bbfda8aSnia
3560bbfda8aSnia/* Junk vars; see comment in ctwm.c about usage */
3570bbfda8aSniaextern Window JunkRoot, JunkChild;
3580bbfda8aSniaextern int JunkX, JunkY;
3590bbfda8aSniaextern unsigned int JunkWidth, JunkHeight, JunkBW, JunkDepth, JunkMask;
3600bbfda8aSnia
3610bbfda8aSniaextern XGCValues Gcv;
3620bbfda8aSniaextern int Argc;
3630bbfda8aSniaextern char **Argv;
3640bbfda8aSnia
3650bbfda8aSniaextern bool RestartPreviousState;
3660bbfda8aSnia
367df1c27a6Sniaextern bool SignalFlag;    ///< Some signal flag has been set
3680bbfda8aSnia
3690bbfda8aSnia#define OCCUPY(w, b) ((b == NULL) ? 1 : (w->occupation & (1 << b->number)))
3700bbfda8aSnia
3710bbfda8aSnia
372df1c27a6Snia/*
373df1c27a6Snia * Dev utils
374df1c27a6Snia */
375df1c27a6Snia// Quiet static analyzer warnings
376df1c27a6Snia#if defined(__clang_analyzer__)
377df1c27a6Snia#define ALLOW_DEAD_STORE(x) (void)(x)
378df1c27a6Snia#else
379df1c27a6Snia#define ALLOW_DEAD_STORE(x) (void)0
380df1c27a6Snia#endif
381df1c27a6Snia
382df1c27a6Snia
3830bbfda8aSnia/*
3840bbfda8aSnia * Command-line arg handling bits
3850bbfda8aSnia */
3860bbfda8aSniatypedef struct _ctwm_cl_args {
3870bbfda8aSnia	bool   MultiScreen;        // ! --single, grab multiple screens
3880bbfda8aSnia	bool   Monochrome;         // --mono, force monochrome
3890bbfda8aSnia	bool   cfgchk;             // --cfgchk, check config and exit
3900bbfda8aSnia	char  *InitFile;           // --file, config filename
3910bbfda8aSnia	char  *display_name;       // --display, X server display
3920bbfda8aSnia
3930bbfda8aSnia	bool   PrintErrorMessages; // --verbose, show more debug output
3940bbfda8aSnia	bool   ShowWelcomeWindow;  // ! --nowelcome, show splash screen
3950bbfda8aSnia
396df1c27a6Snia#ifdef CAPTIVE
3970bbfda8aSnia	bool   is_captive;         // --window (flag), running captive
3980bbfda8aSnia	Window capwin;             // --window (arg), existing window to capture
3990bbfda8aSnia	char  *captivename;        // --name, captive name
400df1c27a6Snia#endif
4010bbfda8aSnia
4020bbfda8aSnia#ifdef USEM4
4030bbfda8aSnia	bool   KeepTmpFile;        // --keep-defs, keep generated m4 defs
4040bbfda8aSnia	char  *keepM4_filename;    // --keep, keep m4 post-processed output
4050bbfda8aSnia	bool   GoThroughM4;        // ! --nom4, do m4 processing
4060bbfda8aSnia#endif
4070bbfda8aSnia
4080bbfda8aSnia#ifdef EWMH
4090bbfda8aSnia	bool   ewmh_replace;       // --replace, replacing running WM
4100bbfda8aSnia#endif
4110bbfda8aSnia
4120bbfda8aSnia	char  *client_id;          // --clientId, session client id
4130bbfda8aSnia	char  *restore_filename;   // --restore, session filename
4140bbfda8aSnia} ctwm_cl_args;
4150bbfda8aSniaextern ctwm_cl_args CLarg;
4160bbfda8aSnia
4170bbfda8aSnia
4180bbfda8aSnia#endif /* _CTWM_CTWM_H */
419