Prevent crash when switchpanel is not initialised.
[wmaker-crm.git] / src / colormap.c
blob121d33b3073d791ba950ef67814299deca55a325
1 /* colormap.c - colormap handling code
3 * Window Maker window manager
5 * Copyright (c) 1998-2003 Alfredo K. Kojima
7 * This code slightly based on fvwm code,
8 * Copyright (c) Rob Nation and others
9 * but completely rewritten.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "wconfig.h"
28 #include "WindowMaker.h"
29 #include <X11/Xatom.h>
31 #include "window.h"
32 #include "framewin.h"
33 #include "colormap.h"
36 void wColormapInstallForWindow(WScreen * scr, WWindow * wwin)
38 int i;
39 XWindowAttributes attributes;
40 int done = 0;
41 Window xwin = None;
43 if (wwin) {
44 xwin = wwin->client_win;
45 } else {
46 xwin = scr->root_win;
49 scr->cmap_window = wwin;
51 if (scr->root_colormap_install_count > 0) {
52 scr->original_cmap_window = wwin;
53 return;
56 /* install colormap for all windows of the client */
57 if (wwin && wwin->cmap_window_no > 0 && wwin->cmap_windows) {
58 for (i = wwin->cmap_window_no - 1; i >= 0; i--) {
59 Window w;
61 w = wwin->cmap_windows[i];
62 if (w == wwin->client_win)
63 done = 1;
65 XGetWindowAttributes(dpy, w, &attributes);
66 if (attributes.colormap == None)
67 attributes.colormap = scr->colormap;
69 if (scr->current_colormap != attributes.colormap) {
70 scr->current_colormap = attributes.colormap;
72 * ICCCM 2.0: some client requested permission
73 * to install colormaps by itself and we granted.
74 * So, we can't install any colormaps.
76 if (!scr->flags.colormap_stuff_blocked)
77 XInstallColormap(dpy, attributes.colormap);
82 if (!done) {
83 attributes.colormap = None;
84 if (xwin != None)
85 XGetWindowAttributes(dpy, xwin, &attributes);
86 if (attributes.colormap == None)
87 attributes.colormap = scr->colormap;
89 if (scr->current_colormap != attributes.colormap) {
90 scr->current_colormap = attributes.colormap;
91 if (!scr->flags.colormap_stuff_blocked)
92 XInstallColormap(dpy, attributes.colormap);
95 XSync(dpy, False);
98 void wColormapAllowClientInstallation(WScreen * scr, Bool starting)
100 scr->flags.colormap_stuff_blocked = starting;
102 * Client stopped managing the colormap stuff. Restore the colormap
103 * that would be installed if the client did not request colormap
104 * stuff.
106 if (!starting) {
107 XInstallColormap(dpy, scr->current_colormap);
108 XSync(dpy, False);