twm.h revision f66df612
1/*****************************************************************************/
2/**       Copyright 1988 by Evans & Sutherland Computer Corporation,        **/
3/**                          Salt Lake City, Utah                           **/
4/**                                                                         **/
5/**                           All Rights Reserved                           **/
6/**                                                                         **/
7/**    Permission to use, copy, modify, and distribute this software and    **/
8/**    its documentation  for  any  purpose  and  without  fee is hereby    **/
9/**    granted, provided that the above copyright notice appear  in  all    **/
10/**    copies and that both  that  copyright  notice  and  this  permis-    **/
11/**    sion  notice appear in supporting  documentation,  and  that  the    **/
12/**    names of Evans & Sutherland not be used in advertising               **/
13/**    in publicity pertaining to distribution of the  software  without    **/
14/**    specific, written prior permission.                                  **/
15/**                                                                         **/
16/**    EVANS & SUTHERLAND AND DISCLAIMS ALL WARRANTIES WITH REGARD          **/
17/**    TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES  OF  MERCHANT-    **/
18/**    ABILITY  AND  FITNESS,  IN  NO  EVENT SHALL EVANS & SUTHERLAND       **/
19/**    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL  DAMAGES        **/
20/**    OR  ANY DAMAGES WHATSOEVER  RESULTING FROM LOSS OF USE, DATA         **/
21/**    OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER    **/
22/**    TORTIOUS ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE    **/
23/**    OR PERFORMANCE OF THIS SOFTWARE.                                     **/
24/*****************************************************************************/
25/*
26
27Portions Copyright 1989, 1998  The Open Group
28
29Permission to use, copy, modify, distribute, and sell this software and its
30documentation for any purpose is hereby granted without fee, provided that
31the above copyright notice appear in all copies and that both that
32copyright notice and this permission notice appear in supporting
33documentation.
34
35The above copyright notice and this permission notice shall be included
36in all copies or substantial portions of the Software.
37
38THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
39OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
40MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
41IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
42OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
43ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
44OTHER DEALINGS IN THE SOFTWARE.
45
46Except as contained in this notice, the name of The Open Group shall
47not be used in advertising or otherwise to promote the sale, use or
48other dealings in this Software without prior written authorization
49from The Open Group.
50
51*/
52
53/***********************************************************************
54 *
55 * twm include file
56 *
57 * 28-Oct-87 Thomas E. LaStrange        File created
58 * 10-Oct-90 David M. Sternlicht        Storing saved colors on root
59 ***********************************************************************/
60
61#ifndef _TWM_
62#define _TWM_
63/* *INDENT-OFF* */
64
65#ifdef HAVE_CONFIG_H
66#include "config.h"
67#endif
68
69#include <X11/Xlib.h>
70#include <X11/Xutil.h>
71#include <X11/cursorfont.h>
72#include <X11/extensions/shape.h>
73#include <X11/Xfuncs.h>
74#include <X11/StringDefs.h>
75#include <X11/Intrinsic.h>
76
77#ifndef GCC_PRINTFLIKE
78#if defined(GCC_PRINTF) && !defined(printf)
79#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
80#else
81#define GCC_PRINTFLIKE(fmt,var) /*nothing*/
82#endif
83#endif
84
85#ifndef GCC_NORETURN
86#define GCC_NORETURN _X_NORETURN
87#endif
88
89#ifndef WithdrawnState
90#define WithdrawnState 0
91#endif
92
93#define PIXEL_ALREADY_TYPEDEFED /* for Xmu/Drawing.h */
94
95typedef void (*SigProc) (int);  /* type of function returned by signal() */
96
97#define BW 2                    /* border width */
98#define BW2 4                   /* border width  * 2 */
99
100#ifndef TRUE
101#define TRUE    1
102#define FALSE   0
103#endif
104
105#define NULLSTR ((char *) NULL)
106
107#define MAX_BUTTONS     16      /* max mouse buttons supported */
108
109/* info strings defines */
110#define INFO_LINES 30
111#define INFO_SIZE 200
112
113/* contexts for button presses */
114#define C_NO_CONTEXT    -1
115#define C_WINDOW        0
116#define C_TITLE         1
117#define C_ICON          2
118#define C_ROOT          3
119#define C_FRAME         4
120#define C_ICONMGR       5
121#define C_NAME          6
122#define C_IDENTIFY      7
123#define NUM_CONTEXTS    8
124
125#define C_WINDOW_BIT    (1 << C_WINDOW)
126#define C_TITLE_BIT     (1 << C_TITLE)
127#define C_ICON_BIT      (1 << C_ICON)
128#define C_ROOT_BIT      (1 << C_ROOT)
129#define C_FRAME_BIT     (1 << C_FRAME)
130#define C_ICONMGR_BIT   (1 << C_ICONMGR)
131#define C_NAME_BIT      (1 << C_NAME)
132
133#define C_ALL_BITS      (C_WINDOW_BIT | C_TITLE_BIT | C_ICON_BIT |\
134                         C_ROOT_BIT | C_FRAME_BIT | C_ICONMGR_BIT)
135
136/* modifiers for button presses */
137#define MOD_SIZE        ((ShiftMask | ControlMask | Mod1Mask \
138                          | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask) + 1)
139
140#define TITLE_BAR_SPACE         1       /* 2 pixel space bordering chars */
141#define TITLE_BAR_FONT_HEIGHT   15      /* max of 15 pixel high chars */
142#define TITLE_BAR_HEIGHT        (TITLE_BAR_FONT_HEIGHT+(2*TITLE_BAR_SPACE))
143
144/* defines for zooming/unzooming */
145#define ZOOM_NONE 0
146
147#define FB(fix_fore, fix_back)\
148    Gcv.foreground = fix_fore;\
149    Gcv.background = fix_back;\
150    XChangeGC(dpy, Scr->NormalGC, GCForeground|GCBackground,&Gcv)
151
152typedef struct MyFont {
153    const char *name;           /* name of the font */
154    XFontStruct *font;          /* font structure */
155    XFontSet fontset;           /* fontset structure */
156    int height;                 /* height of the font */
157    int y;                      /* Y coordinate to draw characters */
158    int ascent;
159    int descent;
160} MyFont;
161
162typedef struct ColorPair {
163    Pixel fore, back;
164} ColorPair;
165
166typedef struct _TitleButton {
167    struct _TitleButton *next;  /* next link in chain */
168    const char *name;           /* bitmap name in case of deferral */
169    Pixmap bitmap;              /* image to display in button */
170    int srcx, srcy;             /* from where to start copying */
171    unsigned int width, height; /* size of pixmap */
172    int dstx, dsty;             /* to where to start copying */
173    int func;                   /* function to execute */
174    const char *action;         /* optional action arg */
175    struct MenuRoot *menuroot;  /* menu to pop on F_MENU */
176    Bool rightside;             /* t: on right, f: on left */
177} TitleButton;
178
179typedef struct _TBWindow {
180    Window window;              /* which window in this frame */
181    TitleButton *info;          /* description of this window */
182} TBWindow;
183
184typedef struct _SqueezeInfo {
185    int justify;                /* left, center, right */
186    int num;                    /* signed pixel count or numerator */
187    int denom;                  /* 0 for pix count or denominator */
188} SqueezeInfo;
189
190#define J_LEFT                  1
191#define J_CENTER                2
192#define J_RIGHT                 3
193
194/* Colormap window entry for each window in WM_COLORMAP_WINDOWS
195 * ICCCM property.
196 */
197typedef struct TwmColormap {
198    Colormap c;                 /* Colormap id */
199    int state;                  /* install(ability) state */
200    unsigned long install_req;  /* request number which installed it */
201    Window w;                   /* window causing load of color table */
202    int refcnt;
203} TwmColormap;
204
205#define CM_INSTALLABLE          1
206#define CM_INSTALLED            2
207#define CM_INSTALL              4
208
209typedef struct ColormapWindow {
210    Window w;                   /* Window id */
211    TwmColormap *colormap;      /* Colormap for this window */
212    int visibility;             /* Visibility of this window */
213    int refcnt;
214} ColormapWindow;
215
216typedef struct Colormaps {
217    ColormapWindow **cwins;     /* current list of colormap windows */
218    int number_cwins;           /* number of elements in current list */
219    char *scoreboard;           /* conflicts between installable colortables */
220} Colormaps;
221
222#define ColormapsScoreboardLength(cm) (size_t)((cm)->number_cwins * \
223                                               ((cm)->number_cwins - 1) / 2)
224
225/* for each window that is on the display, one of these structures
226 * is allocated and linked into a list
227 */
228typedef struct TwmWindow {
229    struct TwmWindow *next;     /* next twm window */
230    struct TwmWindow *prev;     /* previous twm window */
231    Window w;                   /* the child window */
232    int old_bw;                 /* border width before reparenting */
233    Window frame;               /* the frame window */
234    Window title_w;             /* the title bar window */
235    Window hilite_w;            /* the hilite window */
236    Pixmap gray;
237    Window icon_w;              /* the icon window */
238    Window icon_bm_w;           /* the icon bitmap window */
239    int frame_x;                /* x position of frame */
240    int frame_y;                /* y position of frame */
241    int frame_width;            /* width of frame */
242    int frame_height;           /* height of frame */
243    int frame_bw;               /* borderwidth of frame */
244    int title_x;
245    int title_y;
246    int icon_x;                 /* icon text x coordinate */
247    int icon_y;                 /* icon text y coordinate */
248    int icon_w_width;           /* width of the icon window */
249    int icon_w_height;          /* height of the icon window */
250    int icon_width;             /* width of the icon bitmap */
251    int icon_height;            /* height of the icon bitmap */
252    int title_height;           /* height of the title bar */
253    int title_width;            /* width of the title bar */
254    char *full_name;            /* full name of the window */
255    char *name;                 /* name of the window */
256    char *icon_name;            /* name of the icon */
257    int name_width;             /* width of name text */
258    int highlightx;             /* start of highlight window */
259    int rightx;                 /* start of right buttons */
260    XWindowAttributes attr;     /* the child window attributes */
261    XSizeHints hints;           /* normal hints */
262    XWMHints *wmhints;          /* WM hints */
263    Window group;               /* group ID */
264    XClassHint class;
265    struct WList *list;
266    /***********************************************************************
267     * color definitions per window
268     **********************************************************************/
269    Pixel border;               /* border color */
270    Pixel icon_border;          /* border color */
271    ColorPair border_tile;
272    ColorPair title;
273    ColorPair iconc;
274    short iconified;            /* has the window ever been iconified? */
275    short icon;                 /* is the window an icon now ? */
276    short icon_on;              /* is the icon visible */
277    short mapped;               /* is the window mapped ? */
278    short auto_raise;           /* should we auto-raise this window ? */
279    short forced;               /* has had an icon forced upon it */
280    short icon_not_ours;        /* icon pixmap or window supplied to us */
281    short icon_moved;           /* user explicitly moved the icon */
282    short highlight;            /* should highlight this window */
283    short stackmode;            /* honor stackmode requests */
284    short iconify_by_unmapping; /* unmap window to iconify it */
285    short iconmgr;              /* this is an icon manager window */
286    short transient;            /* this is a transient window */
287    Window transientfor;        /* window contained in XA_XM_TRANSIENT_FOR */
288    short titlehighlight;       /* should I highlight the title bar */
289    struct IconMgr *iconmgrp;   /* pointer to it if this is an icon manager */
290    int save_frame_x;           /* x position of frame */
291    int save_frame_y;           /* y position of frame */
292    int save_frame_width;       /* width of frame */
293    int save_frame_height;      /* height of frame */
294    short zoomed;               /* is the window zoomed? */
295    short wShaped;              /* this window has a bounding shape */
296    unsigned long protocols;    /* which protocols this window handles */
297    Colormaps cmaps;            /* colormaps for this application */
298    TBWindow *titlebuttons;
299    SqueezeInfo *squeeze_info;  /* should the title be squeezed? */
300    struct {
301        struct TwmWindow *next, *prev;
302        Bool cursor_valid;
303        int curs_x, curs_y;
304    } ring;
305
306    Bool nameChanged;           /* did WM_NAME ever change? */
307
308    /* did the user ever change the width/height? {yes, no, or unknown} */
309
310    Bool widthEverChangedByUser;
311    Bool heightEverChangedByUser;
312
313} TwmWindow;
314
315typedef struct TWMWinConfigEntry {
316    struct TWMWinConfigEntry *next;
317    int tag;
318    char *client_id;
319    char *window_role;
320    XClassHint class;
321    char *wm_name;
322    int wm_command_count;
323    char **wm_command;
324    short x, y;
325    unsigned short width, height;
326    short icon_x, icon_y;
327    Bool iconified;
328    Bool icon_info_present;
329    Bool width_ever_changed_by_user;
330    Bool height_ever_changed_by_user;
331} TWMWinConfigEntry;
332
333#define DoesWmTakeFocus         (1L << 0)
334#define DoesWmSaveYourself      (1L << 1)
335#define DoesWmDeleteWindow      (1L << 2)
336
337#define TBPM_DOT ":dot"         /* name of titlebar pixmap for dot */
338#define TBPM_ICONIFY ":iconify" /* same image as dot */
339#define TBPM_RESIZE ":resize"   /* name of titlebar pixmap for resize button */
340#define TBPM_XLOGO ":xlogo"     /* name of titlebar pixmap for xlogo */
341#define TBPM_DELETE ":delete"   /* same image as xlogo */
342#define TBPM_MENU ":menu"       /* name of titlebar pixmap for menus */
343#define TBPM_QUESTION ":question"       /* name of unknown titlebar pixmap */
344
345#include <X11/Xosdefs.h>
346#include <stdlib.h>
347extern void CreateFonts(void);
348extern void RestoreWithdrawnLocation(TwmWindow *tmp);
349extern void Reborder(Time time);
350extern void
351Done(XtPointer, XtSignalId *) _X_NORETURN;
352extern void
353ComputeCommonTitleOffsets(void);
354extern void
355ComputeTitleLocation(TwmWindow *tmp);
356extern void
357ComputeWindowTitleOffsets(TwmWindow *tmp_win, int width, Bool squeeze);
358extern char *ProgramName;
359extern Display *dpy;
360extern XtAppContext appContext;
361extern Window ResizeWindow;     /* the window we are resizing */
362extern int HasShape;            /* this server supports Shape extension */
363extern int HasSync;             /* this server supports SYNC extension */
364
365#ifdef HAVE_XRANDR
366extern int HasXrandr;           /* this server supports Xrandr extension */
367#endif
368
369extern int PreviousScreen;
370
371extern Cursor UpperLeftCursor;
372extern Cursor RightButt;
373extern Cursor MiddleButt;
374extern Cursor LeftButt;
375
376extern XClassHint NoClass;
377
378extern XContext TwmContext;
379extern XContext MenuContext;
380extern XContext IconManagerContext;
381extern XContext ScreenContext;
382extern XContext ColormapContext;
383
384extern const char *Home;
385extern int HomeLen;
386extern int ParseError;
387
388extern int HandlingEvents;
389
390extern Window JunkRoot;
391extern Window JunkChild;
392extern int JunkX;
393extern int JunkY;
394extern unsigned int JunkWidth, JunkHeight, JunkBW, JunkDepth, JunkMask;
395extern XGCValues Gcv;
396extern int InfoLines;
397extern char Info[][INFO_SIZE];
398extern int Argc;
399extern char **Argv;
400extern void
401NewFontCursor(Cursor *cp, const char *str);
402extern void
403NewBitmapCursor(Cursor *cp, char *source, char *mask);
404extern Pixmap
405CreateMenuIcon(int height, unsigned int *widthp, unsigned int *heightp);
406
407extern void twmError(const char *, ...) GCC_PRINTFLIKE(1,2) GCC_NORETURN;
408extern void twmWarning(const char *, ...) GCC_PRINTFLIKE(1,2);
409extern void twmVerbose(const char *, ...) GCC_PRINTFLIKE(1,2);
410extern void twmMessage(const char *, ...) GCC_PRINTFLIKE(1,2);
411
412extern Bool ErrorOccurred;
413extern XErrorEvent LastErrorEvent;
414
415#define ResetError() (ErrorOccurred = False)
416
417extern Bool RestartPreviousState;
418extern Bool
419GetWMState(Window w, int *statep, Window *iwp);
420
421extern int
422yyparse(void);
423extern int
424yylex(void);
425
426extern void parseWarning(const char *, ...) GCC_PRINTFLIKE(1,2);
427
428extern Atom TwmAtoms[];
429
430extern int message_level;
431extern Bool use_fontset;
432
433extern int ShapeEventBase;
434extern int ShapeErrorBase;
435
436#ifdef HAVE_XRANDR
437extern int XrandrEventBase;
438extern int XrandrErrorBase;
439#endif
440
441#define _XA_MIT_PRIORITY_COLORS         TwmAtoms[0]
442#define _XA_WM_CHANGE_STATE             TwmAtoms[1]
443#define _XA_WM_STATE                    TwmAtoms[2]
444#define _XA_WM_COLORMAP_WINDOWS         TwmAtoms[3]
445#define _XA_WM_PROTOCOLS                TwmAtoms[4]
446#define _XA_WM_TAKE_FOCUS               TwmAtoms[5]
447#define _XA_WM_SAVE_YOURSELF            TwmAtoms[6]
448#define _XA_WM_DELETE_WINDOW            TwmAtoms[7]
449#define _XA_SM_CLIENT_ID                TwmAtoms[8]
450#define _XA_WM_CLIENT_LEADER            TwmAtoms[9]
451#define _XA_WM_WINDOW_ROLE              TwmAtoms[10]
452
453/* *INDENT-ON* */
454#endif                          /* _TWM_ */
455