mask_screen.c revision 0bbfda8a
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 ColorPair WelcomeCp; 410bbfda8aSnia XColor black; 420bbfda8aSnia 430bbfda8aSnia NewFontCursor(&waitcursor, "watch"); 440bbfda8aSnia 450bbfda8aSnia valuemask = (CWBackPixel | CWOverrideRedirect | CWEventMask | CWCursor); 460bbfda8aSnia attributes.override_redirect = True; 470bbfda8aSnia attributes.event_mask = ExposureMask; 480bbfda8aSnia attributes.cursor = waitcursor; 490bbfda8aSnia attributes.background_pixel = Scr->Black; 500bbfda8aSnia Scr->WindowMask = XCreateWindow(dpy, Scr->Root, 0, 0, 510bbfda8aSnia Scr->rootw, 520bbfda8aSnia Scr->rooth, 530bbfda8aSnia 0, 540bbfda8aSnia CopyFromParent, CopyFromParent, 550bbfda8aSnia CopyFromParent, valuemask, 560bbfda8aSnia &attributes); 570bbfda8aSnia XMapWindow(dpy, Scr->WindowMask); 580bbfda8aSnia XMaskEvent(dpy, ExposureMask, &event); 590bbfda8aSnia 600bbfda8aSnia if(Scr->Monochrome != COLOR) { 610bbfda8aSnia return; 620bbfda8aSnia } 630bbfda8aSnia 640bbfda8aSnia WelcomeCp.fore = Scr->Black; 650bbfda8aSnia WelcomeCp.back = Scr->White; 660bbfda8aSnia Scr->WelcomeCmap = XCreateColormap(dpy, Scr->WindowMask, Scr->d_visual, 670bbfda8aSnia AllocNone); 680bbfda8aSnia if(! Scr->WelcomeCmap) { 690bbfda8aSnia return; 700bbfda8aSnia } 710bbfda8aSnia XSetWindowColormap(dpy, Scr->WindowMask, Scr->WelcomeCmap); 720bbfda8aSnia black.red = 0; 730bbfda8aSnia black.green = 0; 740bbfda8aSnia black.blue = 0; 750bbfda8aSnia XAllocColor(dpy, Scr->WelcomeCmap, &black); 760bbfda8aSnia 770bbfda8aSnia AlternateCmap = Scr->WelcomeCmap; 780bbfda8aSnia if(! file) { 790bbfda8aSnia Scr->WelcomeImage = GetImage("xwd:welcome.xwd", WelcomeCp); 800bbfda8aSnia#ifdef XPM 810bbfda8aSnia if(Scr->WelcomeImage == None) { 820bbfda8aSnia Scr->WelcomeImage = GetImage("xpm:welcome.xpm", WelcomeCp); 830bbfda8aSnia } 840bbfda8aSnia#endif 850bbfda8aSnia } 860bbfda8aSnia else { 870bbfda8aSnia Scr->WelcomeImage = GetImage(file, WelcomeCp); 880bbfda8aSnia } 890bbfda8aSnia AlternateCmap = None; 900bbfda8aSnia if(Scr->WelcomeImage == None) { 910bbfda8aSnia return; 920bbfda8aSnia } 930bbfda8aSnia 940bbfda8aSnia if(CLarg.is_captive) { 950bbfda8aSnia XSetWindowColormap(dpy, Scr->WindowMask, Scr->WelcomeCmap); 960bbfda8aSnia XSetWMColormapWindows(dpy, Scr->Root, &(Scr->WindowMask), 1); 970bbfda8aSnia } 980bbfda8aSnia else { 990bbfda8aSnia XInstallColormap(dpy, Scr->WelcomeCmap); 1000bbfda8aSnia } 1010bbfda8aSnia 1020bbfda8aSnia Scr->WelcomeGC = XCreateGC(dpy, Scr->WindowMask, 0, NULL); 1030bbfda8aSnia x = (Scr->rootw - Scr->WelcomeImage->width) / 2; 1040bbfda8aSnia y = (Scr->rooth - Scr->WelcomeImage->height) / 2; 1050bbfda8aSnia 1060bbfda8aSnia XSetWindowBackground(dpy, Scr->WindowMask, black.pixel); 1070bbfda8aSnia XClearWindow(dpy, Scr->WindowMask); 1080bbfda8aSnia XCopyArea(dpy, Scr->WelcomeImage->pixmap, Scr->WindowMask, Scr->WelcomeGC, 0, 0, 1090bbfda8aSnia Scr->WelcomeImage->width, Scr->WelcomeImage->height, x, y); 1100bbfda8aSnia} 1110bbfda8aSnia 1120bbfda8aSnia 1130bbfda8aSnia 1140bbfda8aSniavoid 1150bbfda8aSniaUnmaskScreen(void) 1160bbfda8aSnia{ 1170bbfda8aSnia struct timeval timeout; 1180bbfda8aSnia Colormap stdcmap = Scr->RootColormaps.cwins[0]->colormap->c; 1190bbfda8aSnia Colormap cmap; 1200bbfda8aSnia XColor colors [256], stdcolors [256]; 1210bbfda8aSnia int i, j, usec; 1220bbfda8aSnia 1230bbfda8aSnia usec = 6000; 1240bbfda8aSnia timeout.tv_usec = usec % (unsigned long) 1000000; 1250bbfda8aSnia timeout.tv_sec = usec / (unsigned long) 1000000; 1260bbfda8aSnia 1270bbfda8aSnia if(Scr->WelcomeImage) { 1280bbfda8aSnia Pixel pixels [256]; 1290bbfda8aSnia 1300bbfda8aSnia cmap = Scr->WelcomeCmap; 1310bbfda8aSnia for(i = 0; i < 256; i++) { 1320bbfda8aSnia pixels [i] = i; 1330bbfda8aSnia colors [i].pixel = i; 1340bbfda8aSnia } 1350bbfda8aSnia XQueryColors(dpy, cmap, colors, 256); 1360bbfda8aSnia XFreeColors(dpy, cmap, pixels, 256, 0L); 1370bbfda8aSnia XFreeColors(dpy, cmap, pixels, 256, 0L); /* Ah Ah */ 1380bbfda8aSnia 1390bbfda8aSnia for(i = 0; i < 256; i++) { 1400bbfda8aSnia colors [i].pixel = i; 1410bbfda8aSnia colors [i].flags = DoRed | DoGreen | DoBlue; 1420bbfda8aSnia stdcolors [i].red = colors [i].red; 1430bbfda8aSnia stdcolors [i].green = colors [i].green; 1440bbfda8aSnia stdcolors [i].blue = colors [i].blue; 1450bbfda8aSnia } 1460bbfda8aSnia for(i = 0; i < 128; i++) { 1470bbfda8aSnia for(j = 0; j < 256; j++) { 1480bbfda8aSnia colors [j].red = stdcolors [j].red * ((127.0 - i) / 128.0); 1490bbfda8aSnia colors [j].green = stdcolors [j].green * ((127.0 - i) / 128.0); 1500bbfda8aSnia colors [j].blue = stdcolors [j].blue * ((127.0 - i) / 128.0); 1510bbfda8aSnia } 1520bbfda8aSnia XStoreColors(dpy, cmap, colors, 256); 1530bbfda8aSnia select(0, NULL, NULL, NULL, &timeout); 1540bbfda8aSnia } 1550bbfda8aSnia XFreeColors(dpy, cmap, pixels, 256, 0L); 1560bbfda8aSnia XFreeGC(dpy, Scr->WelcomeGC); 1570bbfda8aSnia FreeImage(Scr->WelcomeImage); 1580bbfda8aSnia } 1590bbfda8aSnia if(Scr->Monochrome != COLOR) { 1600bbfda8aSnia goto fin; 1610bbfda8aSnia } 1620bbfda8aSnia 1630bbfda8aSnia cmap = XCreateColormap(dpy, Scr->Root, Scr->d_visual, AllocNone); 1640bbfda8aSnia if(! cmap) { 1650bbfda8aSnia goto fin; 1660bbfda8aSnia } 1670bbfda8aSnia for(i = 0; i < 256; i++) { 1680bbfda8aSnia colors [i].pixel = i; 1690bbfda8aSnia colors [i].red = 0; 1700bbfda8aSnia colors [i].green = 0; 1710bbfda8aSnia colors [i].blue = 0; 1720bbfda8aSnia colors [i].flags = DoRed | DoGreen | DoBlue; 1730bbfda8aSnia } 1740bbfda8aSnia XStoreColors(dpy, cmap, colors, 256); 1750bbfda8aSnia 1760bbfda8aSnia if(CLarg.is_captive) { 1770bbfda8aSnia XSetWindowColormap(dpy, Scr->Root, cmap); 1780bbfda8aSnia } 1790bbfda8aSnia else { 1800bbfda8aSnia XInstallColormap(dpy, cmap); 1810bbfda8aSnia } 1820bbfda8aSnia 1830bbfda8aSnia XUnmapWindow(dpy, Scr->WindowMask); 1840bbfda8aSnia XClearWindow(dpy, Scr->Root); 1850bbfda8aSnia XSync(dpy, 0); 1860bbfda8aSnia PaintAllDecoration(); 1870bbfda8aSnia 1880bbfda8aSnia for(i = 0; i < 256; i++) { 1890bbfda8aSnia stdcolors [i].pixel = i; 1900bbfda8aSnia } 1910bbfda8aSnia XQueryColors(dpy, stdcmap, stdcolors, 256); 1920bbfda8aSnia for(i = 0; i < 128; i++) { 1930bbfda8aSnia for(j = 0; j < 256; j++) { 1940bbfda8aSnia colors [j].pixel = j; 1950bbfda8aSnia colors [j].red = stdcolors [j].red * (i / 127.0); 1960bbfda8aSnia colors [j].green = stdcolors [j].green * (i / 127.0); 1970bbfda8aSnia colors [j].blue = stdcolors [j].blue * (i / 127.0); 1980bbfda8aSnia colors [j].flags = DoRed | DoGreen | DoBlue; 1990bbfda8aSnia } 2000bbfda8aSnia XStoreColors(dpy, cmap, colors, 256); 2010bbfda8aSnia select(0, NULL, NULL, NULL, &timeout); 2020bbfda8aSnia } 2030bbfda8aSnia 2040bbfda8aSnia if(CLarg.is_captive) { 2050bbfda8aSnia XSetWindowColormap(dpy, Scr->Root, stdcmap); 2060bbfda8aSnia } 2070bbfda8aSnia else { 2080bbfda8aSnia XInstallColormap(dpy, stdcmap); 2090bbfda8aSnia } 2100bbfda8aSnia 2110bbfda8aSnia XFreeColormap(dpy, cmap); 2120bbfda8aSnia 2130bbfda8aSniafin: 2140bbfda8aSnia if(Scr->WelcomeCmap) { 2150bbfda8aSnia XFreeColormap(dpy, Scr->WelcomeCmap); 2160bbfda8aSnia } 2170bbfda8aSnia XDestroyWindow(dpy, Scr->WindowMask); 2180bbfda8aSnia Scr->WindowMask = (Window) 0; 2190bbfda8aSnia} 2200bbfda8aSnia 2210bbfda8aSnia 2220bbfda8aSnia 2230bbfda8aSnia 2240bbfda8aSnia/* 2250bbfda8aSnia * Internal utils 2260bbfda8aSnia */ 2270bbfda8aSniastatic void 2280bbfda8aSniaPaintAllDecoration(void) 2290bbfda8aSnia{ 2300bbfda8aSnia TwmWindow *tmp_win; 2310bbfda8aSnia VirtualScreen *vs; 2320bbfda8aSnia 2330bbfda8aSnia for(tmp_win = Scr->FirstWindow; tmp_win != NULL; tmp_win = tmp_win->next) { 2340bbfda8aSnia if(! visible(tmp_win)) { 2350bbfda8aSnia continue; 2360bbfda8aSnia } 2370bbfda8aSnia if(tmp_win->mapped) { 2380bbfda8aSnia if(tmp_win->frame_bw3D) { 2390bbfda8aSnia PaintBorders(tmp_win, 2400bbfda8aSnia (tmp_win->highlight && tmp_win == Scr->Focus)); 2410bbfda8aSnia } 2420bbfda8aSnia if(tmp_win->title_w) { 2430bbfda8aSnia PaintTitle(tmp_win); 2440bbfda8aSnia } 2450bbfda8aSnia if(tmp_win->titlebuttons) { 2460bbfda8aSnia PaintTitleButtons(tmp_win); 2470bbfda8aSnia } 2480bbfda8aSnia } 2490bbfda8aSnia else if((tmp_win->icon_on == true) && 2500bbfda8aSnia !Scr->NoIconTitlebar && 2510bbfda8aSnia tmp_win->icon && 2520bbfda8aSnia tmp_win->icon->w && 2530bbfda8aSnia !tmp_win->icon->w_not_ours && 2540bbfda8aSnia ! LookInList(Scr->NoIconTitle, tmp_win->name, &tmp_win->class)) { 2550bbfda8aSnia PaintIcon(tmp_win); 2560bbfda8aSnia } 2570bbfda8aSnia } 2580bbfda8aSnia for(vs = Scr->vScreenList; vs != NULL; vs = vs->next) { 2590bbfda8aSnia PaintWorkSpaceManager(vs); 2600bbfda8aSnia } 2610bbfda8aSnia} 262