10bbfda8aSnia/* 20bbfda8aSnia * Routines for un/masking the whole screen. 30bbfda8aSnia * 40bbfda8aSnia * Used in showing the WelcomeWindow splash screen. 50bbfda8aSnia */ 60bbfda8aSnia 70bbfda8aSnia#include "ctwm.h" 80bbfda8aSnia 90bbfda8aSnia#include <sys/select.h> 100bbfda8aSnia 110bbfda8aSnia#include "screen.h" 120bbfda8aSnia#include "icons.h" 130bbfda8aSnia#include "cursor.h" 140bbfda8aSnia#include "image.h" 150bbfda8aSnia#include "gram.tab.h" 160bbfda8aSnia#include "list.h" 170bbfda8aSnia#include "vscreen.h" 180bbfda8aSnia#include "win_decorations.h" 190bbfda8aSnia#include "win_utils.h" 200bbfda8aSnia#include "workspace_manager.h" 210bbfda8aSnia 220bbfda8aSnia#include "mask_screen.h" 230bbfda8aSnia 240bbfda8aSnia 250bbfda8aSnia/* Various internal subbits */ 260bbfda8aSniastatic void PaintAllDecoration(void); 270bbfda8aSnia 280bbfda8aSnia 290bbfda8aSnia/* 300bbfda8aSnia * Masking and unmasking; our public interface 310bbfda8aSnia */ 320bbfda8aSniavoid 330bbfda8aSniaMaskScreen(char *file) 340bbfda8aSnia{ 350bbfda8aSnia unsigned long valuemask; 360bbfda8aSnia XSetWindowAttributes attributes; 370bbfda8aSnia XEvent event; 380bbfda8aSnia Cursor waitcursor; 390bbfda8aSnia int x, y; 400bbfda8aSnia XColor black; 410bbfda8aSnia 420bbfda8aSnia NewFontCursor(&waitcursor, "watch"); 430bbfda8aSnia 440bbfda8aSnia valuemask = (CWBackPixel | CWOverrideRedirect | CWEventMask | CWCursor); 450bbfda8aSnia attributes.override_redirect = True; 460bbfda8aSnia attributes.event_mask = ExposureMask; 470bbfda8aSnia attributes.cursor = waitcursor; 480bbfda8aSnia attributes.background_pixel = Scr->Black; 490bbfda8aSnia Scr->WindowMask = XCreateWindow(dpy, Scr->Root, 0, 0, 500bbfda8aSnia Scr->rootw, 510bbfda8aSnia Scr->rooth, 520bbfda8aSnia 0, 530bbfda8aSnia CopyFromParent, CopyFromParent, 540bbfda8aSnia CopyFromParent, valuemask, 550bbfda8aSnia &attributes); 560bbfda8aSnia XMapWindow(dpy, Scr->WindowMask); 570bbfda8aSnia XMaskEvent(dpy, ExposureMask, &event); 580bbfda8aSnia 590bbfda8aSnia if(Scr->Monochrome != COLOR) { 600bbfda8aSnia return; 610bbfda8aSnia } 620bbfda8aSnia 63b18c2d1eSnia ColorPair WelcomeCp = { 64b18c2d1eSnia .fore = Scr->Black, 65b18c2d1eSnia .back = Scr->White, 66b18c2d1eSnia }; 670bbfda8aSnia Scr->WelcomeCmap = XCreateColormap(dpy, Scr->WindowMask, Scr->d_visual, 680bbfda8aSnia AllocNone); 690bbfda8aSnia if(! Scr->WelcomeCmap) { 700bbfda8aSnia return; 710bbfda8aSnia } 720bbfda8aSnia XSetWindowColormap(dpy, Scr->WindowMask, Scr->WelcomeCmap); 730bbfda8aSnia black.red = 0; 740bbfda8aSnia black.green = 0; 750bbfda8aSnia black.blue = 0; 760bbfda8aSnia XAllocColor(dpy, Scr->WelcomeCmap, &black); 770bbfda8aSnia 780bbfda8aSnia AlternateCmap = Scr->WelcomeCmap; 790bbfda8aSnia if(! file) { 800bbfda8aSnia Scr->WelcomeImage = GetImage("xwd:welcome.xwd", WelcomeCp); 810bbfda8aSnia#ifdef XPM 820bbfda8aSnia if(Scr->WelcomeImage == None) { 830bbfda8aSnia Scr->WelcomeImage = GetImage("xpm:welcome.xpm", WelcomeCp); 840bbfda8aSnia } 850bbfda8aSnia#endif 860bbfda8aSnia } 870bbfda8aSnia else { 880bbfda8aSnia Scr->WelcomeImage = GetImage(file, WelcomeCp); 890bbfda8aSnia } 900bbfda8aSnia AlternateCmap = None; 910bbfda8aSnia if(Scr->WelcomeImage == None) { 920bbfda8aSnia return; 930bbfda8aSnia } 940bbfda8aSnia 95b18c2d1eSnia if(0) { 96b18c2d1eSnia // Dummy 97b18c2d1eSnia } 98b18c2d1eSnia#ifdef CAPTIVE 99b18c2d1eSnia else if(CLarg.is_captive) { 1000bbfda8aSnia XSetWindowColormap(dpy, Scr->WindowMask, Scr->WelcomeCmap); 1010bbfda8aSnia XSetWMColormapWindows(dpy, Scr->Root, &(Scr->WindowMask), 1); 1020bbfda8aSnia } 103b18c2d1eSnia#endif 1040bbfda8aSnia else { 1050bbfda8aSnia XInstallColormap(dpy, Scr->WelcomeCmap); 1060bbfda8aSnia } 1070bbfda8aSnia 1080bbfda8aSnia Scr->WelcomeGC = XCreateGC(dpy, Scr->WindowMask, 0, NULL); 1090bbfda8aSnia x = (Scr->rootw - Scr->WelcomeImage->width) / 2; 1100bbfda8aSnia y = (Scr->rooth - Scr->WelcomeImage->height) / 2; 1110bbfda8aSnia 1120bbfda8aSnia XSetWindowBackground(dpy, Scr->WindowMask, black.pixel); 1130bbfda8aSnia XClearWindow(dpy, Scr->WindowMask); 1140bbfda8aSnia XCopyArea(dpy, Scr->WelcomeImage->pixmap, Scr->WindowMask, Scr->WelcomeGC, 0, 0, 1150bbfda8aSnia Scr->WelcomeImage->width, Scr->WelcomeImage->height, x, y); 1160bbfda8aSnia} 1170bbfda8aSnia 1180bbfda8aSnia 1190bbfda8aSnia 1200bbfda8aSniavoid 1210bbfda8aSniaUnmaskScreen(void) 1220bbfda8aSnia{ 1230bbfda8aSnia struct timeval timeout; 1240bbfda8aSnia Colormap stdcmap = Scr->RootColormaps.cwins[0]->colormap->c; 1250bbfda8aSnia Colormap cmap; 1260bbfda8aSnia XColor colors [256], stdcolors [256]; 1270bbfda8aSnia int i, j, usec; 1280bbfda8aSnia 1290bbfda8aSnia usec = 6000; 1300bbfda8aSnia timeout.tv_usec = usec % (unsigned long) 1000000; 1310bbfda8aSnia timeout.tv_sec = usec / (unsigned long) 1000000; 1320bbfda8aSnia 1330bbfda8aSnia if(Scr->WelcomeImage) { 1340bbfda8aSnia Pixel pixels [256]; 1350bbfda8aSnia 1360bbfda8aSnia cmap = Scr->WelcomeCmap; 1370bbfda8aSnia for(i = 0; i < 256; i++) { 1380bbfda8aSnia pixels [i] = i; 1390bbfda8aSnia colors [i].pixel = i; 1400bbfda8aSnia } 1410bbfda8aSnia XQueryColors(dpy, cmap, colors, 256); 1420bbfda8aSnia XFreeColors(dpy, cmap, pixels, 256, 0L); 1430bbfda8aSnia XFreeColors(dpy, cmap, pixels, 256, 0L); /* Ah Ah */ 1440bbfda8aSnia 1450bbfda8aSnia for(i = 0; i < 256; i++) { 1460bbfda8aSnia colors [i].pixel = i; 1470bbfda8aSnia colors [i].flags = DoRed | DoGreen | DoBlue; 1480bbfda8aSnia stdcolors [i].red = colors [i].red; 1490bbfda8aSnia stdcolors [i].green = colors [i].green; 1500bbfda8aSnia stdcolors [i].blue = colors [i].blue; 1510bbfda8aSnia } 1520bbfda8aSnia for(i = 0; i < 128; i++) { 1530bbfda8aSnia for(j = 0; j < 256; j++) { 1540bbfda8aSnia colors [j].red = stdcolors [j].red * ((127.0 - i) / 128.0); 1550bbfda8aSnia colors [j].green = stdcolors [j].green * ((127.0 - i) / 128.0); 1560bbfda8aSnia colors [j].blue = stdcolors [j].blue * ((127.0 - i) / 128.0); 1570bbfda8aSnia } 1580bbfda8aSnia XStoreColors(dpy, cmap, colors, 256); 1590bbfda8aSnia select(0, NULL, NULL, NULL, &timeout); 1600bbfda8aSnia } 1610bbfda8aSnia XFreeColors(dpy, cmap, pixels, 256, 0L); 1620bbfda8aSnia XFreeGC(dpy, Scr->WelcomeGC); 1630bbfda8aSnia FreeImage(Scr->WelcomeImage); 1640bbfda8aSnia } 1650bbfda8aSnia if(Scr->Monochrome != COLOR) { 1660bbfda8aSnia goto fin; 1670bbfda8aSnia } 1680bbfda8aSnia 1690bbfda8aSnia cmap = XCreateColormap(dpy, Scr->Root, Scr->d_visual, AllocNone); 1700bbfda8aSnia if(! cmap) { 1710bbfda8aSnia goto fin; 1720bbfda8aSnia } 1730bbfda8aSnia for(i = 0; i < 256; i++) { 1740bbfda8aSnia colors [i].pixel = i; 1750bbfda8aSnia colors [i].red = 0; 1760bbfda8aSnia colors [i].green = 0; 1770bbfda8aSnia colors [i].blue = 0; 1780bbfda8aSnia colors [i].flags = DoRed | DoGreen | DoBlue; 1790bbfda8aSnia } 1800bbfda8aSnia XStoreColors(dpy, cmap, colors, 256); 1810bbfda8aSnia 182b18c2d1eSnia if(0) { 183b18c2d1eSnia // Dummy 184b18c2d1eSnia } 185b18c2d1eSnia#ifdef CAPTIVE 186b18c2d1eSnia else if(CLarg.is_captive) { 1870bbfda8aSnia XSetWindowColormap(dpy, Scr->Root, cmap); 1880bbfda8aSnia } 189b18c2d1eSnia#endif 1900bbfda8aSnia else { 1910bbfda8aSnia XInstallColormap(dpy, cmap); 1920bbfda8aSnia } 1930bbfda8aSnia 1940bbfda8aSnia XUnmapWindow(dpy, Scr->WindowMask); 1950bbfda8aSnia XClearWindow(dpy, Scr->Root); 1960bbfda8aSnia XSync(dpy, 0); 1970bbfda8aSnia PaintAllDecoration(); 1980bbfda8aSnia 1990bbfda8aSnia for(i = 0; i < 256; i++) { 2000bbfda8aSnia stdcolors [i].pixel = i; 2010bbfda8aSnia } 2020bbfda8aSnia XQueryColors(dpy, stdcmap, stdcolors, 256); 2030bbfda8aSnia for(i = 0; i < 128; i++) { 2040bbfda8aSnia for(j = 0; j < 256; j++) { 2050bbfda8aSnia colors [j].pixel = j; 2060bbfda8aSnia colors [j].red = stdcolors [j].red * (i / 127.0); 2070bbfda8aSnia colors [j].green = stdcolors [j].green * (i / 127.0); 2080bbfda8aSnia colors [j].blue = stdcolors [j].blue * (i / 127.0); 2090bbfda8aSnia colors [j].flags = DoRed | DoGreen | DoBlue; 2100bbfda8aSnia } 2110bbfda8aSnia XStoreColors(dpy, cmap, colors, 256); 2120bbfda8aSnia select(0, NULL, NULL, NULL, &timeout); 2130bbfda8aSnia } 2140bbfda8aSnia 215b18c2d1eSnia if(0) { 216b18c2d1eSnia // Dummy 217b18c2d1eSnia } 218b18c2d1eSnia#ifdef CAPTIVE 219b18c2d1eSnia else if(CLarg.is_captive) { 2200bbfda8aSnia XSetWindowColormap(dpy, Scr->Root, stdcmap); 2210bbfda8aSnia } 222b18c2d1eSnia#endif 2230bbfda8aSnia else { 2240bbfda8aSnia XInstallColormap(dpy, stdcmap); 2250bbfda8aSnia } 2260bbfda8aSnia 2270bbfda8aSnia XFreeColormap(dpy, cmap); 2280bbfda8aSnia 2290bbfda8aSniafin: 2300bbfda8aSnia if(Scr->WelcomeCmap) { 2310bbfda8aSnia XFreeColormap(dpy, Scr->WelcomeCmap); 2320bbfda8aSnia } 2330bbfda8aSnia XDestroyWindow(dpy, Scr->WindowMask); 2340bbfda8aSnia Scr->WindowMask = (Window) 0; 2350bbfda8aSnia} 2360bbfda8aSnia 2370bbfda8aSnia 2380bbfda8aSnia 2390bbfda8aSnia 2400bbfda8aSnia/* 2410bbfda8aSnia * Internal utils 2420bbfda8aSnia */ 2430bbfda8aSniastatic void 2440bbfda8aSniaPaintAllDecoration(void) 2450bbfda8aSnia{ 2460bbfda8aSnia TwmWindow *tmp_win; 2470bbfda8aSnia VirtualScreen *vs; 2480bbfda8aSnia 2490bbfda8aSnia for(tmp_win = Scr->FirstWindow; tmp_win != NULL; tmp_win = tmp_win->next) { 2500bbfda8aSnia if(! visible(tmp_win)) { 2510bbfda8aSnia continue; 2520bbfda8aSnia } 2530bbfda8aSnia if(tmp_win->mapped) { 2540bbfda8aSnia if(tmp_win->frame_bw3D) { 2550bbfda8aSnia PaintBorders(tmp_win, 2560bbfda8aSnia (tmp_win->highlight && tmp_win == Scr->Focus)); 2570bbfda8aSnia } 2580bbfda8aSnia if(tmp_win->title_w) { 2590bbfda8aSnia PaintTitle(tmp_win); 2600bbfda8aSnia } 2610bbfda8aSnia if(tmp_win->titlebuttons) { 2620bbfda8aSnia PaintTitleButtons(tmp_win); 2630bbfda8aSnia } 2640bbfda8aSnia } 2650bbfda8aSnia else if((tmp_win->icon_on == true) && 2660bbfda8aSnia !Scr->NoIconTitlebar && 2670bbfda8aSnia tmp_win->icon && 2680bbfda8aSnia tmp_win->icon->w && 2690bbfda8aSnia !tmp_win->icon->w_not_ours && 2700bbfda8aSnia ! LookInList(Scr->NoIconTitle, tmp_win->name, &tmp_win->class)) { 2710bbfda8aSnia PaintIcon(tmp_win); 2720bbfda8aSnia } 2730bbfda8aSnia } 2740bbfda8aSnia for(vs = Scr->vScreenList; vs != NULL; vs = vs->next) { 2750bbfda8aSnia PaintWorkSpaceManager(vs); 2760bbfda8aSnia } 2770bbfda8aSnia} 278