2 * ion/ioncore/colormap.c
4 * Copyright (c) Tuomo Valkonen 1999-2008.
6 * See the included file LICENSE for details.
13 #include "clientwin.h"
20 /*{{{ Installing colormaps */
23 void rootwin_install_colormap(WRootWin *rootwin, Colormap cmap)
26 cmap=rootwin->default_cmap;
27 XInstallColormap(ioncore_g.dpy, cmap);
31 void clientwin_install_colormap(WClientWin *cwin)
33 WRootWin *rw=region_rootwin_of((WRegion*)cwin);
37 for(i=cwin->n_cmapwins-1; i>=0; i--){
38 rootwin_install_colormap(rw, cwin->cmaps[i]);
39 if(cwin->cmapwins[i]==cwin->win)
46 rootwin_install_colormap(rw, cwin->cmap);
56 static XContext ctx=None;
59 void xwindow_unmanaged_selectinput(Window win, long mask)
63 /* We may be monitoring for colourmap changes */
65 if(XFindContext(ioncore_g.dpy, win, ctx, (XPointer*)&p)==0){
67 mask|=ColormapChangeMask;
71 XSelectInput(ioncore_g.dpy, win, mask);
76 static void xwindow_selcmap(Window win)
79 XWindowAttributes attr;
84 if(XFindContext(ioncore_g.dpy, win, ctx, (XPointer*)&p)==0){
92 if(XSaveContext(ioncore_g.dpy, win, ctx, (XPointer)p)!=0){
93 warn(TR("Unable to store colourmap watch info."));
97 if(XWINDOW_REGION_OF(win)==NULL){
98 XGetWindowAttributes(ioncore_g.dpy, win, &attr);
99 XSelectInput(ioncore_g.dpy, win,
100 attr.your_event_mask|ColormapChangeMask);
106 static void xwindow_unselcmap(Window win)
109 XWindowAttributes attr;
114 if(XFindContext(ioncore_g.dpy, win, ctx, (XPointer*)&p)==0){
117 XDeleteContext(ioncore_g.dpy, win, ctx);
119 if(XWINDOW_REGION_OF(win)==NULL){
120 XGetWindowAttributes(ioncore_g.dpy, win, &attr);
121 XSelectInput(ioncore_g.dpy, win,
122 attr.your_event_mask&~ColormapChangeMask);
129 void clientwin_get_colormaps(WClientWin *cwin)
132 XWindowAttributes attr;
135 clientwin_clear_colormaps(cwin);
137 n=xwindow_get_property(cwin->win, ioncore_g.atom_wm_colormaps,
138 XA_WINDOW, 100L, TRUE, (uchar**)&wins);
143 cwin->cmaps=ALLOC_N(Colormap, n);
145 if(cwin->cmaps==NULL)
152 if(wins[i]==cwin->win){
153 cwin->cmaps[i]=cwin->cmap;
155 xwindow_selcmap(wins[i]);
156 XGetWindowAttributes(ioncore_g.dpy, wins[i], &attr);
157 cwin->cmaps[i]=attr.colormap;
163 void clientwin_clear_colormaps(WClientWin *cwin)
166 XWindowAttributes attr;
168 if(cwin->n_cmapwins==0)
171 for(i=0; i<cwin->n_cmapwins; i++){
172 if(cwin->cmapwins[i]!=cwin->win)
173 xwindow_unselcmap(cwin->cmapwins[i]);
176 free(cwin->cmapwins);
187 /*{{{ Event handling */
190 static void handle_cwin_cmap(WClientWin *cwin, const XColormapEvent *ev)
194 if(ev->window==cwin->win){
195 cwin->cmap=ev->colormap;
196 if(REGION_IS_ACTIVE(cwin))
197 clientwin_install_colormap(cwin);
199 for(i=0; i<cwin->n_cmapwins; i++){
200 if(cwin->cmapwins[i]!=ev->window)
202 cwin->cmaps[i]=ev->colormap;
203 if(REGION_IS_ACTIVE(cwin))
204 clientwin_install_colormap(cwin);
211 static void handle_all_cmaps(const XColormapEvent *ev)
215 if(!ioncore_clientwin_ns.initialised)
218 rb_traverse(node, ioncore_clientwin_ns.rb){
219 WClientWin *cwin=(WClientWin*)rb_val(node);
221 handle_cwin_cmap(cwin, ev);
227 void ioncore_handle_colormap_notify(const XColormapEvent *ev)
234 cwin=XWINDOW_REGION_OF_T(ev->window, WClientWin);
237 handle_cwin_cmap(cwin, ev);
238 /*set_cmap(cwin, ev->colormap);*/
240 handle_all_cmaps(ev);