aboutsummaryrefslogtreecommitdiff
path: root/src/tray.h
blob: bae38c550d3d1b9b9670815d3f1a4371aa8182ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/**
 * @file tray.h
 * @author Joe Wingbermuehle
 * @date 2004-2006
 *
 * @brief Header for the tray functions.
 *
 */

#ifndef TRAY_H
#define TRAY_H

#include "hint.h"

struct TimeType;

typedef enum {
	LAYOUT_HORIZONTAL,
	LAYOUT_VERTICAL
} LayoutType;

typedef enum {
	TALIGN_FIXED,
	TALIGN_LEFT,
	TALIGN_TOP,
	TALIGN_CENTER,
	TALIGN_RIGHT,
	TALIGN_BOTTOM
} TrayAlignmentType;

typedef struct TrayComponentType {

	/* The tray containing the component.
	 * UpdateSpecificTray(TrayType*, TrayComponentType*) should be called
	 * when content changes.
	 */
	struct TrayType *tray;

	/* Additional information needed for the component. */
	void *object;

	/* Coordinates on the tray (valid only after Create). */
	int x, y;

	/* Coordinates on the screen (valid only after Create). */
	int screenx, screeny;

	/* Sizing is handled as follows:
	 *  - The component is created via a factory method. It sets its
	 *    requested size (0 for no preference).
	 *  - The SetSize callback is issued with size constraints
	 *    (0 for no constraint). The component should update
	 *    width and height in SetSize.
	 *  - The Create callback is issued with finalized size information.
	 * Resizing is handled as follows:
	 *  - A component determines that it needs to change size. It updates
	 *    its requested size (0 for no preference).
	 *  - The component calls ResizeTray.
	 *  - The SetSize callback is issued with size constraints
	 *    (0 for no constraint). The component should update
	 *    width and height in SetSize.
	 *  - The Resize callback is issued with finalized size information.
	 */

	/* Requested component size. */
	int requestedWidth, requestedHeight;

	/* Actual component size. */
	int width, height;

	/* Content. */
	Window window;
	Pixmap pixmap;

	/* Create the component. */
	void (*Create)(struct TrayComponentType *cp);

	/* Destroy the component. */
	void (*Destroy)(struct TrayComponentType *cp);

	/* Set the size known so far for items that need width/height ratios.
	 * Either width or height may be zero.
	 * This is called before Create.
	 */
	void (*SetSize)(struct TrayComponentType *cp, int width, int height);

	/* Resize the component. */
	void (*Resize)(struct TrayComponentType *cp);

	/* Callback for mouse clicks. */
	void (*ProcessButtonEvent)(struct TrayComponentType *cp,
		int x, int y, int mask);

	/* Callback for mouse motion. */
	void (*ProcessMotionEvent)(struct TrayComponentType *cp,
		int x, int y, int mask);

	/* The next component in the tray. */
	struct TrayComponentType *next;

} TrayComponentType;

typedef struct TrayType {

	int x, y;
	int requestedWidth, requestedHeight;
	int width, height;
	int border;
	WinLayerType layer;
	LayoutType layout;
	TrayAlignmentType valign, halign;

	int autoHide;
	int hidden;

	Window window;

	struct TrayComponentType *components;
	struct TrayComponentType *componentsTail;

	struct TrayType *next;

} TrayType;


void InitializeTray();
void StartupTray();
void ShutdownTray();
void DestroyTray();

/** Create a new tray.
 * @return A new, empty tray.
 */
TrayType *CreateTray();

/** Create a tray component.
 * @return A new tray component structure.
 */
TrayComponentType *CreateTrayComponent();

/** Add a tray component to a tray.
 * @param tp The tray to update.
 * @param cp The tray component to add.
 */
void AddTrayComponent(TrayType *tp, TrayComponentType *cp);

/** Show a tray.
 * @param tp The tray to show.
 */
void ShowTray(TrayType *tp);

/** Hide a tray.
 * @param tp The tray to hide.
 */
void HideTray(TrayType *tp);

/** Draw all trays. */
void DrawTray();

/** Draw a specific tray.
 * @param tp The tray to draw.
 */
void DrawSpecificTray(const TrayType *tp);

/** Update a component on a tray.
 * @param tp The tray containing the component.
 * @param cp The component that needs updating.
 */
void UpdateSpecificTray(const TrayType *tp, const TrayComponentType *cp);

/** Resize a tray.
 * @param tp The tray to resize containing the new requested size information.
 */
void ResizeTray(TrayType *tp);

/** Get a linked list of trays.
 * @return The trays.
 */
TrayType *GetTrays();

/** Get a window to use as the supporting window.
 * This is used by clients to validate that compliant window manager is
 * running.
 * @return The supporting window.
 */
Window GetSupportingWindow();

/** Process an event that may be for a tray.
 * @param event The event to process.
 * @return 1 if this event was for a tray, 0 otherwise.
 */
int ProcessTrayEvent(const XEvent *event);

/** Signal the trays.
 * This function is called regularly so that autohide, etc. can take place.
 * @param now The current time.
 * @param x The mouse x-coordinate (root relative).
 * @param y The mouse y-coordinate (root relative).
 */
void SignalTray(const struct TimeType *now, int x, int y);

void SetAutoHideTray(TrayType *tp, int v);
void SetTrayX(TrayType *tp, const char *str);
void SetTrayY(TrayType *tp, const char *str);
void SetTrayWidth(TrayType *tp, const char *str);
void SetTrayHeight(TrayType *tp, const char *str);
void SetTrayLayout(TrayType *tp, const char *str);
void SetTrayLayer(TrayType *tp, const char *str);
void SetTrayBorder(TrayType *tp, const char *str);
void SetTrayHorizontalAlignment(TrayType *tp, const char *str);
void SetTrayVerticalAlignment(TrayType *tp, const char *str);

#endif