mask_screen.c revision 0bbfda8a
1/*
2 * Routines for un/masking the whole screen.
3 *
4 * Used in showing the WelcomeWindow splash screen.
5 */
6
7#include "ctwm.h"
8
9#include <sys/select.h>
10
11#include "screen.h"
12#include "icons.h"
13#include "cursor.h"
14#include "image.h"
15#include "gram.tab.h"
16#include "list.h"
17#include "vscreen.h"
18#include "win_decorations.h"
19#include "win_utils.h"
20#include "workspace_manager.h"
21
22#include "mask_screen.h"
23
24
25/* Various internal subbits */
26static void PaintAllDecoration(void);
27
28
29/*
30 * Masking and unmasking; our public interface
31 */
32void
33MaskScreen(char *file)
34{
35	unsigned long valuemask;
36	XSetWindowAttributes attributes;
37	XEvent event;
38	Cursor waitcursor;
39	int x, y;
40	ColorPair WelcomeCp;
41	XColor black;
42
43	NewFontCursor(&waitcursor, "watch");
44
45	valuemask = (CWBackPixel | CWOverrideRedirect | CWEventMask | CWCursor);
46	attributes.override_redirect = True;
47	attributes.event_mask        = ExposureMask;
48	attributes.cursor            = waitcursor;
49	attributes.background_pixel  = Scr->Black;
50	Scr->WindowMask = XCreateWindow(dpy, Scr->Root, 0, 0,
51	                                Scr->rootw,
52	                                Scr->rooth,
53	                                0,
54	                                CopyFromParent, CopyFromParent,
55	                                CopyFromParent, valuemask,
56	                                &attributes);
57	XMapWindow(dpy, Scr->WindowMask);
58	XMaskEvent(dpy, ExposureMask, &event);
59
60	if(Scr->Monochrome != COLOR) {
61		return;
62	}
63
64	WelcomeCp.fore = Scr->Black;
65	WelcomeCp.back = Scr->White;
66	Scr->WelcomeCmap  = XCreateColormap(dpy, Scr->WindowMask, Scr->d_visual,
67	                                    AllocNone);
68	if(! Scr->WelcomeCmap) {
69		return;
70	}
71	XSetWindowColormap(dpy, Scr->WindowMask, Scr->WelcomeCmap);
72	black.red   = 0;
73	black.green = 0;
74	black.blue  = 0;
75	XAllocColor(dpy, Scr->WelcomeCmap, &black);
76
77	AlternateCmap = Scr->WelcomeCmap;
78	if(! file) {
79		Scr->WelcomeImage  = GetImage("xwd:welcome.xwd", WelcomeCp);
80#ifdef XPM
81		if(Scr->WelcomeImage == None) {
82			Scr->WelcomeImage  = GetImage("xpm:welcome.xpm", WelcomeCp);
83		}
84#endif
85	}
86	else {
87		Scr->WelcomeImage  = GetImage(file, WelcomeCp);
88	}
89	AlternateCmap = None;
90	if(Scr->WelcomeImage == None) {
91		return;
92	}
93
94	if(CLarg.is_captive) {
95		XSetWindowColormap(dpy, Scr->WindowMask, Scr->WelcomeCmap);
96		XSetWMColormapWindows(dpy, Scr->Root, &(Scr->WindowMask), 1);
97	}
98	else {
99		XInstallColormap(dpy, Scr->WelcomeCmap);
100	}
101
102	Scr->WelcomeGC = XCreateGC(dpy, Scr->WindowMask, 0, NULL);
103	x = (Scr->rootw  -  Scr->WelcomeImage->width) / 2;
104	y = (Scr->rooth - Scr->WelcomeImage->height) / 2;
105
106	XSetWindowBackground(dpy, Scr->WindowMask, black.pixel);
107	XClearWindow(dpy, Scr->WindowMask);
108	XCopyArea(dpy, Scr->WelcomeImage->pixmap, Scr->WindowMask, Scr->WelcomeGC, 0, 0,
109	          Scr->WelcomeImage->width, Scr->WelcomeImage->height, x, y);
110}
111
112
113
114void
115UnmaskScreen(void)
116{
117	struct timeval      timeout;
118	Colormap            stdcmap = Scr->RootColormaps.cwins[0]->colormap->c;
119	Colormap            cmap;
120	XColor              colors [256], stdcolors [256];
121	int                 i, j, usec;
122
123	usec = 6000;
124	timeout.tv_usec = usec % (unsigned long) 1000000;
125	timeout.tv_sec  = usec / (unsigned long) 1000000;
126
127	if(Scr->WelcomeImage) {
128		Pixel pixels [256];
129
130		cmap = Scr->WelcomeCmap;
131		for(i = 0; i < 256; i++) {
132			pixels [i] = i;
133			colors [i].pixel = i;
134		}
135		XQueryColors(dpy, cmap, colors, 256);
136		XFreeColors(dpy, cmap, pixels, 256, 0L);
137		XFreeColors(dpy, cmap, pixels, 256, 0L);   /* Ah Ah */
138
139		for(i = 0; i < 256; i++) {
140			colors [i].pixel = i;
141			colors [i].flags = DoRed | DoGreen | DoBlue;
142			stdcolors [i].red   = colors [i].red;
143			stdcolors [i].green = colors [i].green;
144			stdcolors [i].blue  = colors [i].blue;
145		}
146		for(i = 0; i < 128; i++) {
147			for(j = 0; j < 256; j++) {
148				colors [j].red   = stdcolors [j].red   * ((127.0 - i) / 128.0);
149				colors [j].green = stdcolors [j].green * ((127.0 - i) / 128.0);
150				colors [j].blue  = stdcolors [j].blue  * ((127.0 - i) / 128.0);
151			}
152			XStoreColors(dpy, cmap, colors, 256);
153			select(0, NULL, NULL, NULL, &timeout);
154		}
155		XFreeColors(dpy, cmap, pixels, 256, 0L);
156		XFreeGC(dpy, Scr->WelcomeGC);
157		FreeImage(Scr->WelcomeImage);
158	}
159	if(Scr->Monochrome != COLOR) {
160		goto fin;
161	}
162
163	cmap = XCreateColormap(dpy, Scr->Root, Scr->d_visual, AllocNone);
164	if(! cmap) {
165		goto fin;
166	}
167	for(i = 0; i < 256; i++) {
168		colors [i].pixel = i;
169		colors [i].red   = 0;
170		colors [i].green = 0;
171		colors [i].blue  = 0;
172		colors [i].flags = DoRed | DoGreen | DoBlue;
173	}
174	XStoreColors(dpy, cmap, colors, 256);
175
176	if(CLarg.is_captive) {
177		XSetWindowColormap(dpy, Scr->Root, cmap);
178	}
179	else {
180		XInstallColormap(dpy, cmap);
181	}
182
183	XUnmapWindow(dpy, Scr->WindowMask);
184	XClearWindow(dpy, Scr->Root);
185	XSync(dpy, 0);
186	PaintAllDecoration();
187
188	for(i = 0; i < 256; i++) {
189		stdcolors [i].pixel = i;
190	}
191	XQueryColors(dpy, stdcmap, stdcolors, 256);
192	for(i = 0; i < 128; i++) {
193		for(j = 0; j < 256; j++) {
194			colors [j].pixel = j;
195			colors [j].red   = stdcolors [j].red   * (i / 127.0);
196			colors [j].green = stdcolors [j].green * (i / 127.0);
197			colors [j].blue  = stdcolors [j].blue  * (i / 127.0);
198			colors [j].flags = DoRed | DoGreen | DoBlue;
199		}
200		XStoreColors(dpy, cmap, colors, 256);
201		select(0, NULL, NULL, NULL, &timeout);
202	}
203
204	if(CLarg.is_captive) {
205		XSetWindowColormap(dpy, Scr->Root, stdcmap);
206	}
207	else {
208		XInstallColormap(dpy, stdcmap);
209	}
210
211	XFreeColormap(dpy, cmap);
212
213fin:
214	if(Scr->WelcomeCmap) {
215		XFreeColormap(dpy, Scr->WelcomeCmap);
216	}
217	XDestroyWindow(dpy, Scr->WindowMask);
218	Scr->WindowMask = (Window) 0;
219}
220
221
222
223
224/*
225 * Internal utils
226 */
227static void
228PaintAllDecoration(void)
229{
230	TwmWindow *tmp_win;
231	VirtualScreen *vs;
232
233	for(tmp_win = Scr->FirstWindow; tmp_win != NULL; tmp_win = tmp_win->next) {
234		if(! visible(tmp_win)) {
235			continue;
236		}
237		if(tmp_win->mapped) {
238			if(tmp_win->frame_bw3D) {
239				PaintBorders(tmp_win,
240				             (tmp_win->highlight && tmp_win == Scr->Focus));
241			}
242			if(tmp_win->title_w) {
243				PaintTitle(tmp_win);
244			}
245			if(tmp_win->titlebuttons) {
246				PaintTitleButtons(tmp_win);
247			}
248		}
249		else if((tmp_win->icon_on == true)  &&
250		                !Scr->NoIconTitlebar    &&
251		                tmp_win->icon           &&
252		                tmp_win->icon->w        &&
253		                !tmp_win->icon->w_not_ours &&
254		                ! LookInList(Scr->NoIconTitle, tmp_win->name, &tmp_win->class)) {
255			PaintIcon(tmp_win);
256		}
257	}
258	for(vs = Scr->vScreenList; vs != NULL; vs = vs->next) {
259		PaintWorkSpaceManager(vs);
260	}
261}
262