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