Initial revision
[wmaker-crm.git] / src / colormap.c
blobb33f9a6d0a07f323606d6c0c4caa044de8c91b72
1 /* colormap.c - colormap handling code
2 *
3 * WindowMaker window manager
4 *
5 * Copyright (c) 1998 Alfredo K. Kojima
6 *
7 * This code slightly based on fvwm code,
8 * Copyright (c) Rob Nation and others
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
23 * USA.
27 #include "wconfig.h"
29 #include "WindowMaker.h"
30 #include <X11/Xatom.h>
31 #include "window.h"
35 void
36 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) {
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;
71 XInstallColormap(dpy, attributes.colormap);
76 if (!done) {
77 XGetWindowAttributes(dpy, xwin, &attributes);
78 if (attributes.colormap == None)
79 attributes.colormap = scr->colormap;
81 if (scr->current_colormap != attributes.colormap) {
82 scr->current_colormap = attributes.colormap;
83 XInstallColormap(dpy, attributes.colormap);
89 void
90 wColormapInstallRoot(WScreen *scr)
92 if (scr->root_colormap_install_count == 0) {
93 wColormapInstallForWindow(scr, NULL);
94 scr->original_cmap_window = scr->cmap_window;
96 scr->root_colormap_install_count++;
100 void
101 wColormapUninstallRoot(WScreen *scr)
103 if (scr->root_colormap_install_count > 0)
104 scr->root_colormap_install_count--;
106 if (scr->root_colormap_install_count == 0) {
107 wColormapInstallForWindow(scr, scr->original_cmap_window);
108 scr->original_cmap_window = NULL;