aboutsummaryrefslogtreecommitdiff
path: root/src/status.c
blob: 88c7ddbddc1f12031c3bbdfa767cdb2cc00289bd (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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*************************************************************************
 * Functions for displaying window move/resize status.
 * Copyright (C) 2004 Joe Wingbermuehle
 *************************************************************************/

#include "jwm.h"
#include "status.h"
#include "font.h"
#include "screen.h"
#include "color.h"
#include "main.h"
#include "client.h"
#include "error.h"

typedef enum {
	SW_INVALID,
	SW_OFF,
	SW_SCREEN,
	SW_WINDOW,
	SW_CORNER
} StatusWindowType;

static Window statusWindow;
static unsigned int statusWindowHeight;
static unsigned int statusWindowWidth;
static int statusWindowX, statusWindowY;
static StatusWindowType moveStatusType;
static StatusWindowType resizeStatusType;

static void CreateMoveResizeWindow(const ClientNode *np,
	StatusWindowType type);
static void DrawMoveResizeWindow(const ClientNode *np, StatusWindowType type);
static void DestroyMoveResizeWindow();
static void GetMoveResizeCoordinates(const ClientNode *np,
	StatusWindowType type, int *x, int *y);
static StatusWindowType ParseType(const char *str);

/*************************************************************************
 *************************************************************************/
void GetMoveResizeCoordinates(const ClientNode *np, StatusWindowType type,
	int *x, int *y) {

	const ScreenType *sp;

	if(type == SW_WINDOW) {
		*x = np->x + np->width / 2 - statusWindowWidth / 2;
		*y = np->y + np->height / 2 - statusWindowHeight / 2;
		return;
	}

	sp = GetCurrentScreen(np->x, np->y);

	if(type == SW_CORNER) {
		*x = sp->x;
		*y = sp->y;
		return;
	}

	/* SW_SCREEN */

	*x = sp->x + sp->width / 2 - statusWindowWidth / 2;
	*y = sp->y + sp->height / 2 - statusWindowHeight / 2;

}

/*************************************************************************
 *************************************************************************/
void CreateMoveResizeWindow(const ClientNode *np, StatusWindowType type) {

	XSetWindowAttributes attrs;

	if(type == SW_OFF) {
		return;
	}

	statusWindowHeight = GetStringHeight(FONT_MENU) + 8;
	statusWindowWidth = GetStringWidth(FONT_MENU, " 00000 x 00000 ");

	GetMoveResizeCoordinates(np, type, &statusWindowX, &statusWindowY);

	attrs.background_pixel = colors[COLOR_MENU_BG];
	attrs.save_under = True;
	attrs.override_redirect = True;

	statusWindow = JXCreateWindow(display, rootWindow,
		statusWindowX, statusWindowY,
		statusWindowWidth, statusWindowHeight, 0,
		CopyFromParent, InputOutput, CopyFromParent,
		CWBackPixel | CWOverrideRedirect | CWSaveUnder,
		&attrs);

	JXMapRaised(display, statusWindow);

}

/*************************************************************************
 *************************************************************************/
void DrawMoveResizeWindow(const ClientNode *np, StatusWindowType type) {

	int x, y;

	GetMoveResizeCoordinates(np, type, &x, &y);
	if(x != statusWindowX || y != statusWindowX) {
		statusWindowX = x;
		statusWindowY = y;
		JXMoveResizeWindow(display, statusWindow, x, y,
			statusWindowWidth, statusWindowHeight);
	}

	JXSetForeground(display, rootGC, colors[COLOR_MENU_BG]);
	JXFillRectangle(display, statusWindow, rootGC, 2, 2,
		statusWindowWidth - 3, statusWindowHeight - 3);

	JXSetForeground(display, rootGC, colors[COLOR_MENU_UP]);
	JXDrawLine(display, statusWindow, rootGC,
		0, 0, statusWindowWidth - 1, 0);
	JXDrawLine(display, statusWindow, rootGC,
		0, 1, statusWindowWidth - 2, 1);
	JXDrawLine(display, statusWindow, rootGC,
		0, 2, 0, statusWindowHeight - 1);
	JXDrawLine(display, statusWindow, rootGC,
		1, 2, 1, statusWindowHeight - 2);

	JXSetForeground(display, rootGC, colors[COLOR_MENU_DOWN]);
	JXDrawLine(display, statusWindow, rootGC,
		1, statusWindowHeight - 1, statusWindowWidth - 1,
		statusWindowHeight - 1);
	JXDrawLine(display, statusWindow, rootGC,
		2, statusWindowHeight - 2, statusWindowWidth - 1,
		statusWindowHeight - 2);
	JXDrawLine(display, statusWindow, rootGC,
		statusWindowWidth - 1, 1, statusWindowWidth - 1,
		statusWindowHeight - 3);
	JXDrawLine(display, statusWindow, rootGC,
		statusWindowWidth - 2, 2, statusWindowWidth - 2,
		statusWindowHeight - 3);

}

/*************************************************************************
 *************************************************************************/
void DestroyMoveResizeWindow() {

	if(statusWindow != None) {
		JXDestroyWindow(display, statusWindow);
		statusWindow = None;
	}

}

/*************************************************************************
 *************************************************************************/
void CreateMoveWindow(ClientNode *np) {

	CreateMoveResizeWindow(np, moveStatusType);

}

/*************************************************************************
 *************************************************************************/
void UpdateMoveWindow(ClientNode *np) {

	char str[80];
	unsigned int width;

	if(moveStatusType == SW_OFF) {
		return;
	}

	DrawMoveResizeWindow(np, moveStatusType);

	snprintf(str, sizeof(str), "(%d, %d)", np->x, np->y);
	width = GetStringWidth(FONT_MENU, str);
	RenderString(statusWindow, FONT_MENU, COLOR_MENU_FG,
		statusWindowWidth / 2 - width / 2, 4, rootWidth, NULL, str);

}

/*************************************************************************
 *************************************************************************/
void DestroyMoveWindow() {

	DestroyMoveResizeWindow();

}

/*************************************************************************
 *************************************************************************/
void CreateResizeWindow(ClientNode *np) {

	CreateMoveResizeWindow(np, resizeStatusType);

}

/*************************************************************************
 *************************************************************************/
void UpdateResizeWindow(ClientNode *np, int gwidth, int gheight) {

	char str[80];
	unsigned int fontWidth;

	if(resizeStatusType == SW_OFF) {
		return;
	}

	DrawMoveResizeWindow(np, resizeStatusType);

	snprintf(str, sizeof(str), "%d x %d", gwidth, gheight);
	fontWidth = GetStringWidth(FONT_MENU, str);
	RenderString(statusWindow, FONT_MENU, COLOR_MENU_FG,
		statusWindowWidth / 2 - fontWidth / 2, 4, rootWidth, NULL, str);

}

/*************************************************************************
 *************************************************************************/
void DestroyResizeWindow() {

	DestroyMoveResizeWindow();

}

/*************************************************************************
 *************************************************************************/
StatusWindowType ParseType(const char *str) {

	if(!str) {
		return SW_SCREEN;
	} else if(!strcmp(str, "off")) {
		return SW_OFF;
	} else if(!strcmp(str, "screen")) {
		return SW_SCREEN;
	} else if(!strcmp(str, "window")) {
		return SW_WINDOW;
	} else if(!strcmp(str, "corner")) {
		return SW_CORNER;
	} else {
		return SW_INVALID;
	}

}

/*************************************************************************
 *************************************************************************/
void SetMoveStatusType(const char *str) {

	StatusWindowType type;

	type = ParseType(str);
	if(type == SW_INVALID) {
		moveStatusType = SW_SCREEN;
		Warning("invalid MoveMode coordinates: \"%s\"", str);
	} else {
		moveStatusType = type;
	}

}

/*************************************************************************
 *************************************************************************/
void SetResizeStatusType(const char *str) {

	StatusWindowType type;

	type = ParseType(str);
	if(type == SW_INVALID) {
		resizeStatusType = SW_SCREEN;
		Warning("invalid ResizeMode coordinates: \"%s\"", str);
	} else {
		resizeStatusType = type;
	}

}