Change to the linux kernel coding style
[wmaker-crm.git] / src / colormap.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/* colormap.c - colormap handling code
6830b057 dan2004-10-12 21:28:27 +00002 *
9af1c6c4 dan1998-10-21 14:43:47 +00003 * Window Maker window manager
6830b057 dan2004-10-12 21:28:27 +00004 *
4153e2fd dan2003-01-16 23:30:45 +00005 * Copyright (c) 1998-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00006 *
7 * This code slightly based on fvwm code,
9d2e6ef9 scottc1998-09-29 22:36:29 +00008 * Copyright (c) Rob Nation and others
9af1c6c4 dan1998-10-21 14:43:47 +00009 * but completely rewritten.
6830b057 dan2004-10-12 21:28:27 +000010 *
9d2e6ef9 scottc1998-09-29 22:36:29 +000011 * 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
9d2e6ef9 scottc1998-09-29 22:36:29 +000027#include "wconfig.h"
28
29#include "WindowMaker.h"
30#include <X11/Xatom.h>
31#include "window.h"
32
f2de1c9d kojima2000-01-14 16:30:56 +000033#include "framewin.h"
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020034void wColormapInstallForWindow(WScreen * scr, WWindow * wwin)
9d2e6ef9 scottc1998-09-29 22:36:29 +000035{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020036 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);
9d2e6ef9 scottc1998-09-29 22:36:29 +000094}
95
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020096void wColormapInstallRoot(WScreen * scr)
9d2e6ef9 scottc1998-09-29 22:36:29 +000097{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020098 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++;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000103}
104
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200105void wColormapUninstallRoot(WScreen * scr)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000106{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200107 if (scr->root_colormap_install_count > 0)
108 scr->root_colormap_install_count--;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000109
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200110 if (scr->root_colormap_install_count == 0) {
111 wColormapInstallForWindow(scr, scr->original_cmap_window);
112 scr->original_cmap_window = NULL;
113 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000114}
115
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200116void wColormapAllowClientInstallation(WScreen * scr, Bool starting)
59eb9475 dan1998-11-03 12:53:26 +0000117{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200118 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 }
59eb9475 dan1998-11-03 12:53:26 +0000128}