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