#ifndef _TWM_
#define _TWM_
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/cursorfont.h>
#include <X11/extensions/shape.h>
#include <X11/Xfuncs.h>
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#ifndef WithdrawnState
#define WithdrawnState 0
#endif
#define PIXEL_ALREADY_TYPEDEFED
#ifdef SIGNALRETURNSINT
#define SIGNAL_T int
#define SIGNAL_RETURN return 0
#else
#define SIGNAL_T void
#define SIGNAL_RETURN return
#endif
typedef SIGNAL_T (*SigProc)(int);
#define BW 2
#define BW2 4
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
#define NULLSTR ((char *) NULL)
#define MAX_BUTTONS 5
#define INFO_LINES 30
#define INFO_SIZE 200
#define C_NO_CONTEXT -1
#define C_WINDOW 0
#define C_TITLE 1
#define C_ICON 2
#define C_ROOT 3
#define C_FRAME 4
#define C_ICONMGR 5
#define C_NAME 6
#define C_IDENTIFY 7
#define NUM_CONTEXTS 8
#define C_WINDOW_BIT (1 << C_WINDOW)
#define C_TITLE_BIT (1 << C_TITLE)
#define C_ICON_BIT (1 << C_ICON)
#define C_ROOT_BIT (1 << C_ROOT)
#define C_FRAME_BIT (1 << C_FRAME)
#define C_ICONMGR_BIT (1 << C_ICONMGR)
#define C_NAME_BIT (1 << C_NAME)
#define C_ALL_BITS (C_WINDOW_BIT | C_TITLE_BIT | C_ICON_BIT |\
C_ROOT_BIT | C_FRAME_BIT | C_ICONMGR_BIT)
#define MOD_SIZE ((ShiftMask | ControlMask | Mod1Mask \
| Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask) + 1)
#define TITLE_BAR_SPACE 1
#define TITLE_BAR_FONT_HEIGHT 15
#define TITLE_BAR_HEIGHT (TITLE_BAR_FONT_HEIGHT+(2*TITLE_BAR_SPACE))
#define ZOOM_NONE 0
#define FB(fix_fore, fix_back)\
Gcv.foreground = fix_fore;\
Gcv.background = fix_back;\
XChangeGC(dpy, Scr->NormalGC, GCForeground|GCBackground,&Gcv)
typedef struct MyFont
{
char *name;
XFontStruct *font;
XFontSet fontset;
int height;
int y;
int ascent;
int descent;
} MyFont;
typedef struct ColorPair
{
Pixel fore, back;
} ColorPair;
typedef struct _TitleButton {
struct _TitleButton *next;
char *name;
Pixmap bitmap;
int srcx, srcy;
unsigned int width, height;
int dstx, dsty;
int func;
char *action;
struct MenuRoot *menuroot;
Bool rightside;
} TitleButton;
typedef struct _TBWindow {
Window window;
TitleButton *info;
} TBWindow;
typedef struct _SqueezeInfo {
int justify;
int num;
int denom;
} SqueezeInfo;
#define J_LEFT 1
#define J_CENTER 2
#define J_RIGHT 3
typedef struct TwmColormap
{
Colormap c;
int state;
unsigned long install_req;
Window w;
int refcnt;
} TwmColormap;
#define CM_INSTALLABLE 1
#define CM_INSTALLED 2
#define CM_INSTALL 4
typedef struct ColormapWindow
{
Window w;
TwmColormap *colormap;
int visibility;
int refcnt;
} ColormapWindow;
typedef struct Colormaps
{
ColormapWindow **cwins;
int number_cwins;
char *scoreboard;
} Colormaps;
#define ColormapsScoreboardLength(cm) ((cm)->number_cwins * \
((cm)->number_cwins - 1) / 2)
typedef struct TwmWindow
{
struct TwmWindow *next;
struct TwmWindow *prev;
Window w;
int old_bw;
Window frame;
Window title_w;
Window hilite_w;
Pixmap gray;
Window icon_w;
Window icon_bm_w;
int frame_x;
int frame_y;
int frame_width;
int frame_height;
int frame_bw;
int title_x;
int title_y;
int icon_x;
int icon_y;
int icon_w_width;
int icon_w_height;
int icon_width;
int icon_height;
int title_height;
int title_width;
char *full_name;
char *name;
char *icon_name;
int name_width;
int highlightx;
int rightx;
XWindowAttributes attr;
XSizeHints hints;
XWMHints *wmhints;
Window group;
XClassHint class;
struct WList *list;
Pixel border;
Pixel icon_border;
ColorPair border_tile;
ColorPair title;
ColorPair iconc;
short iconified;
short icon;
short icon_on;
short mapped;
short auto_raise;
short forced;
short icon_not_ours;
short icon_moved;
short highlight;
short stackmode;
short iconify_by_unmapping;
short iconmgr;
short transient;
Window transientfor;
short titlehighlight;
struct IconMgr *iconmgrp;
int save_frame_x;
int save_frame_y;
int save_frame_width;
int save_frame_height;
short zoomed;
short wShaped;
unsigned long protocols;
Colormaps cmaps;
TBWindow *titlebuttons;
SqueezeInfo *squeeze_info;
struct {
struct TwmWindow *next, *prev;
Bool cursor_valid;
int curs_x, curs_y;
} ring;
Bool nameChanged;
Bool widthEverChangedByUser;
Bool heightEverChangedByUser;
} TwmWindow;
typedef struct TWMWinConfigEntry
{
struct TWMWinConfigEntry *next;
int tag;
char *client_id;
char *window_role;
XClassHint class;
char *wm_name;
int wm_command_count;
char **wm_command;
short x, y;
unsigned short width, height;
short icon_x, icon_y;
Bool iconified;
Bool icon_info_present;
Bool width_ever_changed_by_user;
Bool height_ever_changed_by_user;
} TWMWinConfigEntry;
#define DoesWmTakeFocus (1L << 0)
#define DoesWmSaveYourself (1L << 1)
#define DoesWmDeleteWindow (1L << 2)
#define TBPM_DOT ":dot"
#define TBPM_ICONIFY ":iconify"
#define TBPM_RESIZE ":resize"
#define TBPM_XLOGO ":xlogo"
#define TBPM_DELETE ":delete"
#define TBPM_MENU ":menu"
#define TBPM_QUESTION ":question"
#include <X11/Xosdefs.h>
#include <stdlib.h>
extern void InitVariables ( void );
extern void CreateFonts ( void );
extern void RestoreWithdrawnLocation ( TwmWindow *tmp );
extern void Reborder( Time time);
extern void Done( XtPointer, XtSignalId * );
extern void ComputeCommonTitleOffsets ( void );
extern void ComputeTitleLocation ( TwmWindow *tmp );
extern void ComputeWindowTitleOffsets ( TwmWindow *tmp_win, int width, Bool squeeze );
extern char *ProgramName;
extern Display *dpy;
extern XtAppContext appContext;
extern Window ResizeWindow;
extern int HasShape;
extern int HasSync;
extern int PreviousScreen;
extern Cursor UpperLeftCursor;
extern Cursor RightButt;
extern Cursor MiddleButt;
extern Cursor LeftButt;
extern XClassHint NoClass;
extern XContext TwmContext;
extern XContext MenuContext;
extern XContext IconManagerContext;
extern XContext ScreenContext;
extern XContext ColormapContext;
extern char *Home;
extern int HomeLen;
extern int ParseError;
extern int HandlingEvents;
extern Window JunkRoot;
extern Window JunkChild;
extern int JunkX;
extern int JunkY;
extern unsigned int JunkWidth, JunkHeight, JunkBW, JunkDepth, JunkMask;
extern XGCValues Gcv;
extern int InfoLines;
extern char Info[][INFO_SIZE];
extern int Argc;
extern char **Argv;
extern void NewFontCursor ( Cursor *cp, char *str );
extern void NewBitmapCursor ( Cursor *cp, char *source, char *mask );
extern Pixmap CreateMenuIcon ( int height, unsigned int *widthp, unsigned int *heightp );
extern Bool ErrorOccurred;
extern XErrorEvent LastErrorEvent;
#define ResetError() (ErrorOccurred = False)
extern Bool RestartPreviousState;
extern Bool GetWMState ( Window w, int *statep, Window *iwp );
extern void twmrc_error_prefix ( void );
extern int yyparse ( void );
extern int yylex ( void );
extern void yyerror ( char *s );
extern int doinput ( char *buf, int size );
extern void RemoveDQuote ( char *str );
extern Atom TwmAtoms[];
extern Bool use_fontset;
extern int ShapeEventBase;
extern int ShapeErrorBase;
#define _XA_MIT_PRIORITY_COLORS TwmAtoms[0]
#define _XA_WM_CHANGE_STATE TwmAtoms[1]
#define _XA_WM_STATE TwmAtoms[2]
#define _XA_WM_COLORMAP_WINDOWS TwmAtoms[3]
#define _XA_WM_PROTOCOLS TwmAtoms[4]
#define _XA_WM_TAKE_FOCUS TwmAtoms[5]
#define _XA_WM_SAVE_YOURSELF TwmAtoms[6]
#define _XA_WM_DELETE_WINDOW TwmAtoms[7]
#define _XA_SM_CLIENT_ID TwmAtoms[8]
#define _XA_WM_CLIENT_LEADER TwmAtoms[9]
#define _XA_WM_WINDOW_ROLE TwmAtoms[10]
#endif