Home | History | Annotate | Line # | Download | only in src
      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        Storing saved colors on root
     59  ***********************************************************************/
     60 
     61 #ifndef TWM_H
     62 #define TWM_H
     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 APP_NAME
     78 #define APP_NAME "twm"
     79 #endif
     80 
     81 #ifndef APP_CLASS
     82 #define APP_CLASS "twm"
     83 #endif
     84 
     85 #ifndef APP_VERSION
     86 #define APP_VERSION "unknown"
     87 #endif
     88 
     89 #ifndef DATADIR
     90 #define DATADIR "/usr/local/share"
     91 #endif
     92 
     93 #ifndef XVENDORNAME
     94 #define XVENDORNAME "The X.Org Foundation"
     95 #endif
     96 
     97 #ifndef WithdrawnState
     98 #define WithdrawnState 0
     99 #endif
    100 
    101 #define PIXEL_ALREADY_TYPEDEFED /* for Xmu/Drawing.h */
    102 
    103 #define BW 2                    /* border width */
    104 #define BW2 4                   /* border width  * 2 */
    105 
    106 #ifndef TRUE
    107 #define TRUE    1
    108 #define FALSE   0
    109 #endif
    110 
    111 #define NULLSTR ((char *) NULL)
    112 
    113 #define MAX_BUTTONS     16      /* max mouse buttons supported */
    114 
    115 /* info strings defines */
    116 #define INFO_LINES 30
    117 #define INFO_SIZE 200
    118 
    119 /* contexts for button presses */
    120 #define C_NO_CONTEXT    -1
    121 #define C_WINDOW        0
    122 #define C_TITLE         1
    123 #define C_ICON          2
    124 #define C_ROOT          3
    125 #define C_FRAME         4
    126 #define C_ICONMGR       5
    127 #define C_NAME          6
    128 #define C_IDENTIFY      7
    129 #define NUM_CONTEXTS    8
    130 
    131 #define C_WINDOW_BIT    (1 << C_WINDOW)
    132 #define C_TITLE_BIT     (1 << C_TITLE)
    133 #define C_ICON_BIT      (1 << C_ICON)
    134 #define C_ROOT_BIT      (1 << C_ROOT)
    135 #define C_FRAME_BIT     (1 << C_FRAME)
    136 #define C_ICONMGR_BIT   (1 << C_ICONMGR)
    137 #define C_NAME_BIT      (1 << C_NAME)
    138 
    139 #define C_ALL_BITS      (C_WINDOW_BIT | C_TITLE_BIT | C_ICON_BIT |\
    140                          C_ROOT_BIT | C_FRAME_BIT | C_ICONMGR_BIT)
    141 
    142 /* modifiers for button presses */
    143 #define MOD_SIZE        ((ShiftMask | ControlMask | Mod1Mask \
    144                           | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask) + 1)
    145 
    146 #define TITLE_BAR_SPACE         1       /* 2 pixel space bordering chars */
    147 #define TITLE_BAR_FONT_HEIGHT   15      /* max of 15 pixel high chars */
    148 #define TITLE_BAR_HEIGHT        (TITLE_BAR_FONT_HEIGHT+(2*TITLE_BAR_SPACE))
    149 
    150 /* defines for zooming/unzooming */
    151 #define ZOOM_NONE 0
    152 
    153 #define FB(fix_fore, fix_back)\
    154     Gcv.foreground = fix_fore;\
    155     Gcv.background = fix_back;\
    156     XChangeGC(dpy, Scr->NormalGC, GCForeground|GCBackground,&Gcv)
    157 
    158 typedef struct MyFont {
    159     const char *name;           /* name of the font */
    160     XFontStruct *font;          /* font structure */
    161     XFontSet fontset;           /* fontset structure */
    162     int height;                 /* height of the font */
    163     int y;                      /* Y coordinate to draw characters */
    164     int ascent;
    165     int descent;
    166 } MyFont;
    167 
    168 typedef struct ColorPair {
    169     Pixel fore, back;
    170 } ColorPair;
    171 
    172 typedef struct _TitleButton {
    173     struct _TitleButton *next;  /* next link in chain */
    174     const char *name;           /* bitmap name in case of deferral */
    175     Pixmap bitmap;              /* image to display in button */
    176     int srcx, srcy;             /* from where to start copying */
    177     unsigned int width, height; /* size of pixmap */
    178     int dstx, dsty;             /* to where to start copying */
    179     int func;                   /* function to execute */
    180     const char *action;         /* optional action arg */
    181     struct MenuRoot *menuroot;  /* menu to pop on F_MENU */
    182     Bool rightside;             /* t: on right, f: on left */
    183 } TitleButton;
    184 
    185 typedef struct _TBWindow {
    186     Window window;              /* which window in this frame */
    187     TitleButton *info;          /* description of this window */
    188 } TBWindow;
    189 
    190 typedef struct _SqueezeInfo {
    191     int justify;                /* left, center, right */
    192     int num;                    /* signed pixel count or numerator */
    193     int denom;                  /* 0 for pix count or denominator */
    194 } SqueezeInfo;
    195 
    196 #define J_LEFT                  1
    197 #define J_CENTER                2
    198 #define J_RIGHT                 3
    199 
    200 /* Colormap window entry for each window in WM_COLORMAP_WINDOWS
    201  * ICCCM property.
    202  */
    203 typedef struct TwmColormap {
    204     Colormap c;                 /* Colormap id */
    205     int state;                  /* install(ability) state */
    206     unsigned long install_req;  /* request number which installed it */
    207     Window w;                   /* window causing load of color table */
    208     int refcnt;
    209 } TwmColormap;
    210 
    211 #define CM_INSTALLABLE          1
    212 #define CM_INSTALLED            2
    213 #define CM_INSTALL              4
    214 
    215 typedef struct ColormapWindow {
    216     Window w;                   /* Window id */
    217     TwmColormap *colormap;      /* Colormap for this window */
    218     int visibility;             /* Visibility of this window */
    219     int refcnt;
    220 } ColormapWindow;
    221 
    222 typedef struct Colormaps {
    223     ColormapWindow **cwins;     /* current list of colormap windows */
    224     int number_cwins;           /* number of elements in current list */
    225     char *scoreboard;           /* conflicts between installable colortables */
    226 } Colormaps;
    227 
    228 #define ColormapsScoreboardLength(cm) (size_t)((cm)->number_cwins * \
    229                                                ((cm)->number_cwins - 1) / 2)
    230 
    231 /* for each window that is on the display, one of these structures
    232  * is allocated and linked into a list
    233  */
    234 typedef struct TwmWindow {
    235     struct TwmWindow *next;     /* next twm window */
    236     struct TwmWindow *prev;     /* previous twm window */
    237     Window w;                   /* the child window */
    238     int old_bw;                 /* border width before reparenting */
    239     Window frame;               /* the frame window */
    240     Window title_w;             /* the title bar window */
    241     Window hilite_w;            /* the hilite window */
    242     Pixmap gray;
    243     Window icon_w;              /* the icon window */
    244     Window icon_bm_w;           /* the icon bitmap window */
    245     int frame_x;                /* x position of frame */
    246     int frame_y;                /* y position of frame */
    247     int frame_width;            /* width of frame */
    248     int frame_height;           /* height of frame */
    249     int frame_bw;               /* borderwidth of frame */
    250     int title_x;
    251     int title_y;
    252     int icon_x;                 /* icon text x coordinate */
    253     int icon_y;                 /* icon text y coordinate */
    254     int icon_w_width;           /* width of the icon window */
    255     int icon_w_height;          /* height of the icon window */
    256     int icon_width;             /* width of the icon bitmap */
    257     int icon_height;            /* height of the icon bitmap */
    258     int title_height;           /* height of the title bar */
    259     int title_width;            /* width of the title bar */
    260     char *full_name;            /* full name of the window */
    261     char *name;                 /* name of the window */
    262     char *icon_name;            /* name of the icon */
    263     int name_width;             /* width of name text */
    264     int highlightx;             /* start of highlight window */
    265     int rightx;                 /* start of right buttons */
    266     XWindowAttributes attr;     /* the child window attributes */
    267     XSizeHints hints;           /* normal hints */
    268     XWMHints *wmhints;          /* WM hints */
    269     Window group;               /* group ID */
    270     XClassHint xclass;
    271     struct WList *list;
    272     /***********************************************************************
    273      * color definitions per window
    274      **********************************************************************/
    275     Pixel border;               /* border color */
    276     Pixel icon_border;          /* border color */
    277     ColorPair border_tile;
    278     ColorPair title;
    279     ColorPair iconc;
    280     short iconified;            /* has the window ever been iconified? */
    281     short icon;                 /* is the window an icon now ? */
    282     short icon_on;              /* is the icon visible */
    283     short mapped;               /* is the window mapped ? */
    284     short auto_raise;           /* should we auto-raise this window ? */
    285     short forced;               /* has had an icon forced upon it */
    286     short icon_not_ours;        /* icon pixmap or window supplied to us */
    287     short icon_moved;           /* user explicitly moved the icon */
    288     short highlight;            /* should highlight this window */
    289     short stackmode;            /* honor stackmode requests */
    290     short iconify_by_unmapping; /* unmap window to iconify it */
    291     short iconmgr;              /* this is an icon manager window */
    292     short transient;            /* this is a transient window */
    293     Window transientfor;        /* window contained in XA_XM_TRANSIENT_FOR */
    294     short titlehighlight;       /* should I highlight the title bar */
    295     struct IconMgr *iconmgrp;   /* pointer to it if this is an icon manager */
    296     int save_frame_x;           /* x position of frame */
    297     int save_frame_y;           /* y position of frame */
    298     int save_frame_width;       /* width of frame */
    299     int save_frame_height;      /* height of frame */
    300     short zoomed;               /* is the window zoomed? */
    301     short wShaped;              /* this window has a bounding shape */
    302     unsigned long protocols;    /* which protocols this window handles */
    303     Colormaps cmaps;            /* colormaps for this application */
    304     TBWindow *titlebuttons;
    305     SqueezeInfo *squeeze_info;  /* should the title be squeezed? */
    306     struct {
    307         struct TwmWindow *next, *prev;
    308         Bool cursor_valid;
    309         int curs_x, curs_y;
    310     } ring;
    311 
    312     Bool nameChanged;           /* did WM_NAME ever change? */
    313 
    314     /* did the user ever change the width/height? {yes, no, or unknown} */
    315 
    316     Bool widthEverChangedByUser;
    317     Bool heightEverChangedByUser;
    318 
    319 } TwmWindow;
    320 
    321 typedef struct TWMWinConfigEntry {
    322     struct TWMWinConfigEntry *next;
    323     int tag;
    324     char *client_id;
    325     char *window_role;
    326     XClassHint xclass;
    327     char *wm_name;
    328     int wm_command_count;
    329     char **wm_command;
    330     short x, y;
    331     unsigned short width, height;
    332     short icon_x, icon_y;
    333     Bool iconified;
    334     Bool icon_info_present;
    335     Bool width_ever_changed_by_user;
    336     Bool height_ever_changed_by_user;
    337 } TWMWinConfigEntry;
    338 
    339 #define DoesWmTakeFocus         (1L << 0)
    340 #define DoesWmSaveYourself      (1L << 1)
    341 #define DoesWmDeleteWindow      (1L << 2)
    342 
    343 #define TBPM_DOT ":dot"         /* name of titlebar pixmap for dot */
    344 #define TBPM_ICONIFY ":iconify" /* same image as dot */
    345 #define TBPM_RESIZE ":resize"   /* name of titlebar pixmap for resize button */
    346 #define TBPM_XLOGO ":xlogo"     /* name of titlebar pixmap for xlogo */
    347 #define TBPM_DELETE ":delete"   /* same image as xlogo */
    348 #define TBPM_MENU ":menu"       /* name of titlebar pixmap for menus */
    349 #define TBPM_QUESTION ":question"       /* name of unknown titlebar pixmap */
    350 
    351 #include <X11/Xosdefs.h>
    352 #include <stdlib.h>
    353 extern void CreateFonts(void);
    354 extern void RestoreWithdrawnLocation(TwmWindow *tmp);
    355 extern void Reborder(Time time);
    356 extern void
    357 Done(XtPointer, XtSignalId *) _X_NORETURN;
    358 extern void
    359 ComputeCommonTitleOffsets(void);
    360 extern void
    361 ComputeTitleLocation(TwmWindow *tmp);
    362 extern void
    363 ComputeWindowTitleOffsets(TwmWindow *tmp_win, int width, Bool squeeze);
    364 extern char *ProgramName;
    365 extern Display *dpy;
    366 extern Window ResizeWindow;     /* the window we are resizing */
    367 extern int HasShape;            /* this server supports Shape extension */
    368 extern int HasSync;             /* this server supports SYNC extension */
    369 
    370 #ifdef HAVE_XRANDR
    371 extern int HasXrandr;           /* this server supports Xrandr extension */
    372 #endif
    373 
    374 extern int PreviousScreen;
    375 
    376 extern Cursor UpperLeftCursor;
    377 extern Cursor RightButt;
    378 extern Cursor MiddleButt;
    379 extern Cursor LeftButt;
    380 
    381 extern XClassHint NoClass;
    382 
    383 extern XContext TwmContext;
    384 extern XContext MenuContext;
    385 extern XContext IconManagerContext;
    386 extern XContext ScreenContext;
    387 extern XContext ColormapContext;
    388 
    389 extern const char *Home;
    390 extern int HomeLen;
    391 extern int ParseError;
    392 
    393 extern int HandlingEvents;
    394 
    395 extern XGCValues Gcv;
    396 extern int InfoLines;
    397 extern char Info[][INFO_SIZE];
    398 extern int Argc;
    399 extern char **Argv;
    400 extern void
    401 NewFontCursor(Cursor *cp, const char *str);
    402 extern void
    403 NewBitmapCursor(Cursor *cp, char *source, char *mask);
    404 extern Pixmap
    405 CreateMenuIcon(int height, unsigned int *widthp, unsigned int *heightp);
    406 
    407 extern void twmError(const char *, ...) _X_ATTRIBUTE_PRINTF(1,2) _X_NORETURN;
    408 extern void twmWarning(const char *, ...) _X_ATTRIBUTE_PRINTF(1,2);
    409 extern void twmVerbose(const char *, ...) _X_ATTRIBUTE_PRINTF(1,2);
    410 extern void twmMessage(const char *, ...) _X_ATTRIBUTE_PRINTF(1,2);
    411 
    412 extern Bool ErrorOccurred;
    413 extern XErrorEvent LastErrorEvent;
    414 
    415 #define ResetError() (ErrorOccurred = False)
    416 
    417 extern Bool RestartPreviousState;
    418 extern Bool
    419 GetWMState(Window w, int *statep, Window *iwp);
    420 
    421 extern void parseWarning(const char *, ...) _X_ATTRIBUTE_PRINTF(1,2);
    422 
    423 extern Atom TwmAtoms[];
    424 
    425 extern int message_level;
    426 extern Bool use_fontset;
    427 
    428 extern int ShapeEventBase;
    429 extern int ShapeErrorBase;
    430 
    431 #ifdef HAVE_XRANDR
    432 extern int XrandrEventBase;
    433 extern int XrandrErrorBase;
    434 #endif
    435 
    436 #define _XA_MIT_PRIORITY_COLORS         TwmAtoms[0]
    437 #define _XA_WM_CHANGE_STATE             TwmAtoms[1]
    438 #define _XA_WM_STATE                    TwmAtoms[2]
    439 #define _XA_WM_COLORMAP_WINDOWS         TwmAtoms[3]
    440 #define _XA_WM_PROTOCOLS                TwmAtoms[4]
    441 #define _XA_WM_TAKE_FOCUS               TwmAtoms[5]
    442 #define _XA_WM_SAVE_YOURSELF            TwmAtoms[6]
    443 #define _XA_WM_DELETE_WINDOW            TwmAtoms[7]
    444 #define _XA_SM_CLIENT_ID                TwmAtoms[8]
    445 #define _XA_WM_CLIENT_LEADER            TwmAtoms[9]
    446 #define _XA_WM_WINDOW_ROLE              TwmAtoms[10]
    447 
    448 /* *INDENT-ON* */
    449 #endif /* TWM_H */
    450