1 /**
2  * @file tray.h
3  * @author Joe Wingbermuehle
4  * @date 2004-2006
5  *
6  * @brief Tray functions.
7  *
8  */
9 
10 #ifndef TRAY_H
11 #define TRAY_H
12 
13 #include "hint.h"
14 
15 /** Enumeration of tray layouts. */
16 typedef unsigned char LayoutType;
17 #define LAYOUT_HORIZONTAL  0  /**< Left-to-right. */
18 #define LAYOUT_VERTICAL    1  /**< Top-to-bottom. */
19 
20 /** Enumeration of tray alignments. */
21 typedef unsigned char TrayAlignmentType;
22 #define TALIGN_FIXED    0 /**< Fixed at user specified x and y coordinates. */
23 #define TALIGN_LEFT     1 /**< Left aligned. */
24 #define TALIGN_TOP      2 /**< Top aligned. */
25 #define TALIGN_CENTER   3 /**< Center aligned. */
26 #define TALIGN_RIGHT    4 /**< Right aligned. */
27 #define TALIGN_BOTTOM   5 /**< Bottom aligned. */
28 
29 /** Enumeration of tray autohide values. */
30 typedef unsigned char TrayAutoHideType;
31 #define THIDE_OFF       0 /**< No autohide. */
32 #define THIDE_LEFT      1 /**< Hide on the left. */
33 #define THIDE_RIGHT     2 /**< Hide on the right. */
34 #define THIDE_TOP       3 /**< Hide on the top. */
35 #define THIDE_BOTTOM    4 /**< Hide on the bottom. */
36 #define THIDE_RAISED    8 /**< Mask to indicate the tray is raised. */
37 
38 /** Structure to hold common tray component data.
39  * Sizing is handled as follows:
40  *  - The component is created via a factory method. It sets its
41  *    requested size (0 for no preference).
42  *  - The SetSize callback is issued with size constraints
43  *    (0 for no constraint). The component should update
44  *    width and height in SetSize.
45  *  - The Create callback is issued with finalized size information.
46  * Resizing is handled as follows:
47  *  - A component determines that it needs to change size. It updates
48  *    its requested size (0 for no preference).
49  *  - The component calls ResizeTray.
50  *  - The SetSize callback is issued with size constraints
51  *    (0 for no constraint). The component should update
52  *    width and height in SetSize.
53  *  - The Resize callback is issued with finalized size information.
54  */
55 typedef struct TrayComponentType {
56 
57    /** The tray containing the component.
58     * UpdateSpecificTray(TrayType*, TrayComponentType*) should be called
59     * when content changes.
60     */
61    struct TrayType *tray;
62 
63    /** Additional information needed for the component. */
64    void *object;
65 
66    int x;   /**< x-coordinate on the tray (valid only after Create). */
67    int y;   /**< y-coordinate on the tray (valid only after Create). */
68 
69    int screenx;   /**< x-coordinate on the screen (valid only after Create). */
70    int screeny;   /**< y-coordinate on the screen (valid only after Create). */
71 
72 
73    int requestedWidth;  /**< Requested width. */
74    int requestedHeight; /**< Requested height. */
75 
76    int width;     /**< Actual width. */
77    int height;    /**< Actual height. */
78 
79    char grabbed;     /**< 1 if the mouse was grabbed by this component. */
80 
81    Window window;    /**< Content (if a window, otherwise None). */
82    Pixmap pixmap;    /**< Content (if a pixmap, otherwise None). */
83 
84    /** Callback to create the component. */
85    void (*Create)(struct TrayComponentType *cp);
86 
87    /** Callback to destroy the component. */
88    void (*Destroy)(struct TrayComponentType *cp);
89 
90    /** Callback to set the size known so far.
91     * This is needed for items that maintain width/height ratios.
92     * Either width or height may be zero.
93     * This is called before Create.
94     */
95    void (*SetSize)(struct TrayComponentType *cp, int width, int height);
96 
97    /** Callback to resize the component. */
98    void (*Resize)(struct TrayComponentType *cp);
99 
100    /** Callback for mouse presses. */
101    void (*ProcessButtonPress)(struct TrayComponentType *cp,
102                               int x, int y, int mask);
103 
104    /** Callback for mouse releases. */
105    void (*ProcessButtonRelease)(struct TrayComponentType *cp,
106                                 int x, int y, int mask);
107 
108    /** Callback for mouse motion. */
109    void (*ProcessMotionEvent)(struct TrayComponentType *cp,
110                               int x, int y, int mask);
111 
112    /** Callback to redraw the component contents.
113     * This is only needed for components that use actions.
114     */
115    void (*Redraw)(struct TrayComponentType *cp);
116 
117    /** The next component in the tray. */
118    struct TrayComponentType *next;
119 
120 } TrayComponentType;
121 
122 /** Structure to represent a tray. */
123 typedef struct TrayType {
124 
125    int requestedX;      /**< The user-requested x-coordinate of the tray. */
126    int requestedY;      /**< The user-requested y-coordinate of the tray. */
127 
128    int x;   /**< The x-coordinate of the tray. */
129    int y;   /**< The y-coordinate of the tray. */
130 
131    int requestedWidth;  /**< Total requested width of the tray. */
132    int requestedHeight; /**< Total requested height of the tray. */
133 
134    int width;     /**< Actual width of the tray. */
135    int height;    /**< Actual height of the tray. */
136 
137    WinLayerType layer;        /**< Layer. */
138    LayoutType layout;         /**< Layout. */
139    TrayAlignmentType valign;  /**< Vertical alignment. */
140    TrayAlignmentType halign;  /**< Horizontal alignment. */
141 
142    TrayAutoHideType  autoHide;
143    char hidden;     /**< 1 if hidden (due to autohide), 0 otherwise. */
144 
145    Window window; /**< The tray window. */
146 
147    /** Start of the tray components. */
148    struct TrayComponentType *components;
149 
150    /** End of the tray components. */
151    struct TrayComponentType *componentsTail;
152 
153    struct TrayType *next;  /**< Next tray. */
154 
155 } TrayType;
156 
157 void InitializeTray(void);
158 void StartupTray(void);
159 void ShutdownTray(void);
160 void DestroyTray(void);
161 
162 /** Create a new tray.
163  * @return A new, empty tray.
164  */
165 TrayType *CreateTray(void);
166 
167 /** Create a tray component.
168  * @return A new tray component structure.
169  */
170 TrayComponentType *CreateTrayComponent(void);
171 
172 /** Add a tray component to a tray.
173  * @param tp The tray to update.
174  * @param cp The tray component to add.
175  */
176 void AddTrayComponent(TrayType *tp, TrayComponentType *cp);
177 
178 /** Show a tray.
179  * @param tp The tray to show.
180  */
181 void ShowTray(TrayType *tp);
182 
183 /** Show all trays. */
184 void ShowAllTrays(void);
185 
186 /** Hide a tray.
187  * @param tp The tray to hide.
188  */
189 void HideTray(TrayType *tp);
190 
191 /** Draw all trays. */
192 void DrawTray(void);
193 
194 /** Draw a specific tray.
195  * @param tp The tray to draw.
196  */
197 void DrawSpecificTray(const TrayType *tp);
198 
199 /** Raise tray windows. */
200 void RaiseTrays(void);
201 
202 /** Lower tray windows. */
203 void LowerTrays(void);
204 
205 /** Update a component on a tray.
206  * @param tp The tray containing the component.
207  * @param cp The component that needs updating.
208  */
209 void UpdateSpecificTray(const TrayType *tp, const TrayComponentType *cp);
210 
211 /** Resize a tray.
212  * @param tp The tray to resize containing the new requested size information.
213  */
214 void ResizeTray(TrayType *tp);
215 
216 /** Draw the tray background on a drawable. */
217 void ClearTrayDrawable(const TrayComponentType *cp);
218 
219 /** Get a linked list of trays.
220  * @return The trays.
221  */
222 TrayType *GetTrays(void);
223 
224 /** Get the number of trays.
225  * @return The number of trays.
226  */
227 unsigned int GetTrayCount(void);
228 
229 /** Process an event that may be for a tray.
230  * @param event The event to process.
231  * @return 1 if this event was for a tray, 0 otherwise.
232  */
233 char ProcessTrayEvent(const XEvent *event);
234 
235 /** Set whether auto hide is enabled for a tray.
236  * @param tp The tray.
237  * @param autohide The auto hide setting.
238  */
239 void SetAutoHideTray(TrayType *tp, TrayAutoHideType autohide);
240 
241 /** Set the tray x-coordinate.
242  * @param tp The tray.
243  * @param str The x-coordinate (ASCII, pixels, negative ok).
244  */
245 void SetTrayX(TrayType *tp, const char *str);
246 
247 /** Set the tray y-coordinate.
248  * @param tp The tray.
249  * @param str The y-coordinate (ASCII, pixels, negative ok).
250  */
251 void SetTrayY(TrayType *tp, const char *str);
252 
253 /** Set the tray width.
254  * @param tp The tray.
255  * @param str The width (ASCII, pixels).
256  */
257 void SetTrayWidth(TrayType *tp, const char *str);
258 
259 /** Set the tray height.
260  * @param tp The tray.
261  * @param str The height (ASCII, pixels).
262  */
263 void SetTrayHeight(TrayType *tp, const char *str);
264 
265 /** Set the tray layout.
266  * @param tp The tray.
267  * @param str A string representation of the layout to use.
268  */
269 void SetTrayLayout(TrayType *tp, const char *str);
270 
271 /** Set the tray layer.
272  * @param tp The tray.
273  * @param layer The layer.
274  */
275 void SetTrayLayer(TrayType *tp, WinLayerType layer);
276 
277 /** Set the tray horizontal alignment.
278  * @param tp The tray.
279  * @param str The alignment (ASCII).
280  */
281 void SetTrayHorizontalAlignment(TrayType *tp, const char *str);
282 
283 /** Set the tray vertical alignment.
284  * @param tp The tray.
285  * @param str The alignment (ASCII).
286  */
287 void SetTrayVerticalAlignment(TrayType *tp, const char *str);
288 
289 #endif /* TRAY_H */
290 
291