Change to the linux kernel coding style
[wmaker-crm.git] / src / colormap.c
1 /* colormap.c - colormap handling code
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1998-2003 Alfredo K. Kojima
6 *
7 * This code slightly based on fvwm code,
8 * Copyright (c) Rob Nation and others
9 * but completely rewritten.
10 *
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.
15 *
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.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
24 * USA.
25 */
26
27 #include "wconfig.h"
28
29 #include "WindowMaker.h"
30 #include <X11/Xatom.h>
31 #include "window.h"
32
33 #include "framewin.h"
34 void wColormapInstallForWindow(WScreen * scr, WWindow * wwin)
35 {
36 int i;
37 XWindowAttributes attributes;
38 int done = 0;
39 Window xwin = None;
40
41 if (wwin) {
42 xwin = wwin->client_win;
43 } else {
44 xwin = scr->root_win;
45 }
46
47 scr->cmap_window = wwin;
48
49 if (scr->root_colormap_install_count > 0) {
50 scr->original_cmap_window = wwin;
51 return;
52 }
53
54 /* install colormap for all windows of the client */
55 if (wwin && wwin->cmap_window_no > 0 && wwin->cmap_windows) {
56 for (i = wwin->cmap_window_no - 1; i >= 0; i--) {
57 Window w;
58
59 w = wwin->cmap_windows[i];
60 if (w == wwin->client_win)
61 done = 1;
62
63 XGetWindowAttributes(dpy, w, &attributes);
64 if (attributes.colormap == None)
65 attributes.colormap = scr->colormap;
66
67 if (scr->current_colormap != attributes.colormap) {
68 scr->current_colormap = attributes.colormap;
69 /*
70 * ICCCM 2.0: some client requested permission
71 * to install colormaps by itself and we granted.
72 * So, we can't install any colormaps.
73 */
74 if (!scr->flags.colormap_stuff_blocked)
75 XInstallColormap(dpy, attributes.colormap);
76 }
77 }
78 }
79
80 if (!done) {
81 attributes.colormap = None;
82 if (xwin != None)
83 XGetWindowAttributes(dpy, xwin, &attributes);
84 if (attributes.colormap == None)
85 attributes.colormap = scr->colormap;
86
87 if (scr->current_colormap != attributes.colormap) {
88 scr->current_colormap = attributes.colormap;
89 if (!scr->flags.colormap_stuff_blocked)
90 XInstallColormap(dpy, attributes.colormap);
91 }
92 }
93 XSync(dpy, False);
94 }
95
96 void wColormapInstallRoot(WScreen * scr)
97 {
98 if (scr->root_colormap_install_count == 0) {
99 wColormapInstallForWindow(scr, NULL);
100 scr->original_cmap_window = scr->cmap_window;
101 }
102 scr->root_colormap_install_count++;
103 }
104
105 void wColormapUninstallRoot(WScreen * scr)
106 {
107 if (scr->root_colormap_install_count > 0)
108 scr->root_colormap_install_count--;
109
110 if (scr->root_colormap_install_count == 0) {
111 wColormapInstallForWindow(scr, scr->original_cmap_window);
112 scr->original_cmap_window = NULL;
113 }
114 }
115
116 void wColormapAllowClientInstallation(WScreen * scr, Bool starting)
117 {
118 scr->flags.colormap_stuff_blocked = starting;
119 /*
120 * Client stopped managing the colormap stuff. Restore the colormap
121 * that would be installed if the client did not request colormap
122 * stuff.
123 */
124 if (!starting) {
125 XInstallColormap(dpy, scr->current_colormap);
126 XSync(dpy, False);
127 }
128 }