1 // $Id: xxX.hh 4508 2012-05-28 18:01:34Z flaterco $
2 
3 /*  xxX  Globals for interfacing with X11.
4 
5     Copyright (C) 2006  David Flater.
6 
7     This program is free software: you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation, either version 3 of the License, or
10     (at your option) any later version.
11 
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 
17     You should have received a copy of the GNU General Public License
18     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 namespace xxX {
22 
23   // To make efficient use of X11 you need to know that most of these
24   // things that look like big objects are in fact integers or
25   // pointers.
26 
27 
28   // Constants
29 
30   // This is used to help calculate the minimum width of graph and
31   // clock windows.  The minimum width is the string width of the
32   // command button captions plus minWidthFudgeFactor times the number
33   // of buttons.  (All of the buttons must fit on one line to avoid
34   // catastrophe.)
35   extern const unsigned minWidthFudgeFactor;
36 
37   // Size of square icon.
38   extern const unsigned iconSize;
39 
40 
41   // Variables
42 
43   extern XtAppContext appContext;
44   extern Display     *display;
45   extern Screen      *screen;
46   extern int          screenNum;
47   extern Window       rootWindow;
48 
49   // Colormap and visual used by XTide, and the depth thereof.
50   extern Colormap colormap;
51   extern Visual*  visual;
52   extern unsigned colordepth;
53 
54   // Preallocated colors indexed by Colorchoice.
55   // (A Pixel is an index into a colormap and is actually unsigned long.)
56   extern Pixel pixels[Colors::numColors]; // Wants to be [Colors::Colorchoice]
57 
58   // Foreground drawing contexts for five of the colors.
59   // GCs are pointers to private structs.
60   extern GC textGC,
61             backgroundGC,
62             markGC,
63             tidedotGC,
64             currentdotGC;
65   #ifdef HAVE_XAW3DXFT
66   extern XftColor textXftColor;
67   #endif
68 
69   // Foreground drawing context where color is changed every time.
70   extern GC spareGC;
71 
72   // Invert drawing context.
73   extern GC invertGC;
74 
75   // Compatibility layer for plain fonts vs. Xft.
76   // Note that fontHeight is defined in Graph.hh; avoid clash.
77   #ifdef HAVE_XAW3DXFT
78     typedef XftFont FontStruct;
79     #define xxFontHeight(fsptr) (fsptr->height)
80     #define fontArgName (char*)XtNxftFont
81   #else
82     typedef XFontStruct FontStruct;
83     #define xxFontHeight(fsptr) (fsptr->ascent + fsptr->descent)
84     #define fontArgName (char*)XtNfont
85   #endif
86   extern XtArgVal monoFontArgValue;
87 
88   // Fonts.
89   extern FontStruct  *monoFontStruct, *defaultFontStruct;
90   extern XFontStruct *iconFontStruct; // Never freetype
91 
92   // Uh, "atoms."  (Don't blame me, it's X11 terminology.)
93   extern Atom killAtom,
94               protocolAtom;
95 
96   // We try to obtain a TrueColor visual of depth 15 or greater.  If
97   // unsuccessful, displaySucks is true and we follow a protocol
98   // suitable for PseudoColor displays.
99   extern bool displaySucks;
100 
101   // The icon is required to "match" the root window, so we need the
102   // following stuff just for the icon.
103   extern Visual*  iconVisual;
104   extern unsigned iconColordepth;
105 
106   // Foreground drawing contexts for the icon.
107   extern GC iconTextGC,
108             iconBackgroundGC;
109 
110   // Default icon (not the special xxClock one).
111   extern Pixmap iconPixmap;
112 
113 
114   // Functions
115 
116   // Connect to X11 and initialize most xxX variables.  Switches
117   // recognized by X11 are removed from the command line.  Returns
118   // widget for xxRoot.  Do this only once.
119   const Widget connect (int &argc, char **argv);
120 
121   // Initialize the rest of the xxX variables.  Do this only once, after
122   // settings are loaded.  Invokes installColors, loads fonts.
123   void connectPostSettingsHook (Widget rootWidget);
124 
125   // Initialize or update pixels, iconpixels and GCs based on
126   // Global::settings.  Installs fonts in the GCs where applicable.
127   void installColors ();
128 
129   // Get a color from colormap or allocate it if necessary.  If a
130   // color cannot be allocated, this function returns the closest
131   // match.
132   const Pixel getColor (unsigned short red,
133 			unsigned short green,
134 			unsigned short blue);
135 
136   // Create a blank Pixmap.
137   const Pixmap makePixmap     (unsigned width, unsigned height);
138   const Pixmap makeIconPixmap (unsigned width, unsigned height);
139 
140   // Create a Pixmap from an Xpm (limit 256 colors).
141   // XpmCreatePixmapFromData doesn't use const, so neither can I.
142   const Pixmap makePixmap (char **data);
143 
144   // Create a Pixmap from 24-bit RGB data (requires !displaySucks).
145   const Pixmap makePixmap (unsigned width, unsigned height,
146 			   const SafeVector<unsigned char> &rgb);
147 
148   // Return width of string in pixels.
149   // XTextExtents doesn't use const, so neither can I.
150   const unsigned stringWidth (XFontStruct *fs, const Dstr &s);
151   #ifdef HAVE_XAW3DXFT
152   const unsigned stringWidth (FontStruct *fs, const Dstr &s);
153   #endif
154 
155   // Load a client-side font.
156   void getClientSideFont (FontStruct *fs, ClientSide::Font &font_out);
157 
158   // If applicable, set XtNbeNiceToColormap to False for the specified Widget.
159   #ifdef XtNbeNiceToColormap
160     #define setRudeness(w) XtVaSetValues (w, (char*)XtNbeNiceToColormap, (XtArgVal)False, NULL);
161   #else
162     #define setRudeness(w)
163   #endif
164 
165   // Wrapper for XtCreateManagedWidget that automatically adds setRudeness.
166   Widget createXtWidget (constString name, WidgetClass widget_class,
167 			 Widget parent, ArgList args, Cardinal num_args);
168 
169   // If applicable, set XtNbeNiceToColormap to False for the "threeD"
170   // child widget.
171   void fixBorder (Widget widget);
172 
173   // Turn a wimpy Widget into a manly std::auto_ptr<xxWidget>.
174   std::auto_ptr<xxWidget> wrap (Widget widget);
175 }
176