~ctwm/ctwm/trunk

510.1.2 by Matthew Fuller
Break the functions used for parsing/applying the various workspace
1
/*
2
 * Routines using in setting up the config for workspace stuff.
3
 */
4
5
#include "ctwm.h"
6
7
#include <stdio.h>
8
#include <string.h>
9
#include <stdlib.h>
10
11
#include "image.h"
12
#include "list.h"
524.1.1 by Matthew Fuller
Pull occupation.h out of screen.h, and include it directly in the
13
#include "occupation.h"
510.1.2 by Matthew Fuller
Break the functions used for parsing/applying the various workspace
14
#include "screen.h"
15
#include "util.h"
16
#include "workspace_config.h"
510.1.5 by Matthew Fuller
Break the general/utility workspace functions out into their own file.
17
#include "workspace_utils.h"
510.1.2 by Matthew Fuller
Break the functions used for parsing/applying the various workspace
18
19
510.1.17 by Matthew Fuller
GC the useBackgroundInfo setter; since we're already exporting the var
20
// Temp; x-ref desc in workspace_utils
21
extern bool useBackgroundInfo;
22
510.1.2 by Matthew Fuller
Break the functions used for parsing/applying the various workspace
23
24
/*
25
 * Create a workspace.  This is what gets called when parsing
26
 * WorkSpaces {} config file entries.
27
 *
28
 * WorkSpaces {
29
 *  "One" { name background foreground backback backfore "backpix.jpg" }
30
 *  #         |      |           |        |       |            |
31
 *  #     WS name    |      Button Text   |   Map/Root FG      |
32
 *  #            Button BG             Map BG            Map/Root BG img
33
 * }
34
 */
35
void
36
AddWorkSpace(const char *name, const char *background, const char *foreground,
37
             const char *backback, const char *backfore, const char *backpix)
38
{
39
	WorkSpace *ws;
40
41
	/* XXX Shouldn't just silently return if we're already at max...  */
42
	if(Scr->workSpaceMgr.count == MAXWORKSPACE) {
43
		return;
44
	}
45
46
	/* Init.  Label can change over time, but starts the same as name. */
47
	ws = calloc(1, sizeof(WorkSpace));
48
	ws->name  = strdup(name);
49
	ws->label = strdup(name);
50
	ws->number = Scr->workSpaceMgr.count++;
51
52
	/* We're a new entry on the "everything" list */
53
	fullOccupation |= (1 << ws->number);
54
55
56
	/*
57
	 * FB/BG colors for the button state may be specified, or fallback to
58
	 * the icon manager's if not.
59
	 */
60
	if(background == NULL) {
61
		ws->cp.back = Scr->IconManagerC.back;
62
	}
63
	else {
64
		GetColor(Scr->Monochrome, &(ws->cp.back), background);
65
	}
66
67
	if(foreground == NULL) {
68
		ws->cp.fore = Scr->IconManagerC.fore;
69
	}
70
	else {
71
		GetColor(Scr->Monochrome, &(ws->cp.fore), foreground);
72
	}
73
74
	/* Shadows for 3d buttons derived from that */
75
#ifdef COLOR_BLIND_USER
76
	ws->cp.shadc = Scr->White;
77
	ws->cp.shadd = Scr->Black;
78
#else
79
	if(!Scr->BeNiceToColormap) {
80
		GetShadeColors(&ws->cp);
81
	}
82
#endif
83
84
85
	/*
86
	 * Map-state fb/bg color, as well as root win background.
87
	 */
88
	if(backback == NULL) {
89
		GetColor(Scr->Monochrome, &(ws->backcp.back), "Black");
90
	}
91
	else {
92
		GetColor(Scr->Monochrome, &(ws->backcp.back), backback);
510.1.17 by Matthew Fuller
GC the useBackgroundInfo setter; since we're already exporting the var
93
		useBackgroundInfo = true;
510.1.2 by Matthew Fuller
Break the functions used for parsing/applying the various workspace
94
	}
95
96
	if(backfore == NULL) {
97
		GetColor(Scr->Monochrome, &(ws->backcp.fore), "White");
98
	}
99
	else {
100
		GetColor(Scr->Monochrome, &(ws->backcp.fore), backfore);
510.1.17 by Matthew Fuller
GC the useBackgroundInfo setter; since we're already exporting the var
101
		useBackgroundInfo = true;
510.1.2 by Matthew Fuller
Break the functions used for parsing/applying the various workspace
102
	}
103
104
105
	/* Maybe there's an image to stick on the root as well */
106
	ws->image = GetImage(backpix, ws->backcp);
107
	if(ws->image != NULL) {
510.1.17 by Matthew Fuller
GC the useBackgroundInfo setter; since we're already exporting the var
108
		useBackgroundInfo = true;
510.1.2 by Matthew Fuller
Break the functions used for parsing/applying the various workspace
109
	}
110
111
112
	/* Put ourselves on the end of the workspace list */
113
	if(Scr->workSpaceMgr.workSpaceList == NULL) {
114
		Scr->workSpaceMgr.workSpaceList = ws;
115
	}
116
	else {
117
		WorkSpace *wstmp = Scr->workSpaceMgr.workSpaceList;
118
		while(wstmp->next != NULL) {
119
			wstmp = wstmp->next;
120
		}
121
		wstmp->next = ws;
122
	}
123
124
	/* There's at least one defined WS now */
125
	Scr->workSpaceManagerActive = true;
126
127
	return;
128
}
129
130
131
132
/*
133
 * MapWindowCurrentWorkSpace {} parsing
134
 */
135
void
510.1.3 by Matthew Fuller
const-ify these func args.
136
WMapCreateCurrentBackGround(const char *border,
137
                            const char *background, const char *foreground,
138
                            const char *pixmap)
510.1.2 by Matthew Fuller
Break the functions used for parsing/applying the various workspace
139
{
140
	Image *image;
141
	WorkSpaceMgr *ws = &Scr->workSpaceMgr;
142
143
	ws->curBorderColor = Scr->Black;
144
	ws->curColors.back = Scr->White;
145
	ws->curColors.fore = Scr->Black;
146
	ws->curImage       = NULL;
147
148
	if(border == NULL) {
149
		return;
150
	}
151
	GetColor(Scr->Monochrome, &ws->curBorderColor, border);
152
	if(background == NULL) {
153
		return;
154
	}
155
	ws->curPaint = true;
156
	GetColor(Scr->Monochrome, &ws->curColors.back, background);
157
	if(foreground == NULL) {
158
		return;
159
	}
160
	GetColor(Scr->Monochrome, &ws->curColors.fore, foreground);
161
162
	if(pixmap == NULL) {
163
		return;
164
	}
165
	if((image = GetImage(pixmap, Scr->workSpaceMgr.curColors)) == NULL) {
166
		fprintf(stderr, "Can't find pixmap %s\n", pixmap);
167
		return;
168
	}
169
	ws->curImage = image;
170
}
171
172
173
174
/*
175
 * MapWindowDefaultWorkSpace {} parsing
176
 */
177
void
510.1.3 by Matthew Fuller
const-ify these func args.
178
WMapCreateDefaultBackGround(const char *border,
179
                            const char *background, const char *foreground,
180
                            const char *pixmap)
510.1.2 by Matthew Fuller
Break the functions used for parsing/applying the various workspace
181
{
182
	Image *image;
183
	WorkSpaceMgr *ws = &Scr->workSpaceMgr;
184
185
	ws->defBorderColor = Scr->Black;
186
	ws->defColors.back = Scr->White;
187
	ws->defColors.fore = Scr->Black;
188
	ws->defImage       = NULL;
189
190
	if(border == NULL) {
191
		return;
192
	}
193
	GetColor(Scr->Monochrome, &ws->defBorderColor, border);
194
	if(background == NULL) {
195
		return;
196
	}
197
	GetColor(Scr->Monochrome, &ws->defColors.back, background);
198
	if(foreground == NULL) {
199
		return;
200
	}
201
	GetColor(Scr->Monochrome, &ws->defColors.fore, foreground);
202
	if(pixmap == NULL) {
203
		return;
204
	}
205
	if((image = GetImage(pixmap, ws->defColors)) == NULL) {
206
		return;
207
	}
208
	ws->defImage = image;
209
}