2 /* Copyright (C) 2001 Olivier Chapuis */
3 /* This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "libs/fvwmlib.h"
25 #include "libs/Flocale.h"
26 #include "libs/FlocaleCharset.h"
27 #include "libs/Ficonv.h"
29 #include "window_flags.h"
31 #include "functions.h"
34 #include "module_interface.h"
36 #include "add_window.h"
39 #include "ewmh_intern.h"
43 * set the visibale window name and icon name
45 void EWMH_SetVisibleName(FvwmWindow
*fw
, Bool is_icon_name
)
49 FlocaleCharset
*fc
= NULL
;
56 /* set the ewmh visible name only if it is != wm name */
59 if ((fw
->icon_name_count
== 0 ||
60 !USE_INDEXED_ICON_NAME(fw
)) &&
61 !HAS_EWMH_WM_ICON_NAME(fw
) &&
62 !HAS_EWMH_WM_NAME(fw
))
65 FW_W(fw
), "_NET_WM_ICON_VISIBLE_NAME",
66 EWMH_ATOM_LIST_FVWM_WIN
);
69 if (IS_ICON_FONT_LOADED(fw
) && fw
->icon_font
!= NULL
)
71 fc
= fw
->icon_font
->str_fc
;
73 tmp_str
= fw
->visible_icon_name
;
77 if ((fw
->name_count
== 0 ||
78 !USE_INDEXED_WINDOW_NAME(fw
)) &&
79 !HAS_EWMH_WM_NAME(fw
) && !HAS_EWMH_WM_ICON_NAME(fw
))
82 FW_W(fw
), "_NET_WM_VISIBLE_NAME",
83 EWMH_ATOM_LIST_FVWM_WIN
);
86 if (IS_WINDOW_FONT_LOADED(fw
) && fw
->title_font
!= NULL
)
88 fc
= fw
->title_font
->str_fc
;
90 tmp_str
= fw
->visible_name
;
95 return; /* should never happen */
98 val
= (unsigned char *)FiconvCharsetToUtf8(
99 dpy
, fc
, tmp_str
, strlen(tmp_str
));
109 FW_W(fw
), "_NET_WM_ICON_VISIBLE_NAME",
110 EWMH_ATOM_LIST_FVWM_WIN
, (unsigned char *)val
,
111 strlen((char *)val
));
116 FW_W(fw
), "_NET_WM_VISIBLE_NAME",
117 EWMH_ATOM_LIST_FVWM_WIN
, (unsigned char *)val
,
118 strlen((char *)val
));
124 * setup and property notify
126 int EWMH_WMIconName(EWMH_CMD_ARGS
)
131 FlocaleCharset
*fc
= NULL
;
138 val
= ewmh_AtomGetByName(
139 FW_W(fw
), "_NET_WM_ICON_NAME",
140 EWMH_ATOM_LIST_PROPERTY_NOTIFY
, &size
);
144 SET_HAS_EWMH_WM_ICON_NAME(fw
,0);
147 if (IS_ICON_FONT_LOADED(fw
) && fw
->icon_font
!= NULL
)
149 fc
= fw
->icon_font
->str_fc
;
152 tmp_str
= (char *)FiconvUtf8ToCharset(
153 dpy
, fc
, (const char *) val
, size
);
157 SET_HAS_EWMH_WM_ICON_NAME(fw
, 0);
160 if (strlen(tmp_str
) > MAX_ICON_NAME_LEN
)
162 tmp_str
[MAX_ICON_NAME_LEN
] = 0;
164 SET_HAS_EWMH_WM_ICON_NAME(fw
, 1);
165 if (fw
->icon_name
.name
&& strcmp(tmp_str
, fw
->icon_name
.name
) == 0)
167 /* migo: some apps update their names every second */
175 free_window_names(fw
, False
, True
);
178 fw
->icon_name
.name
= tmp_str
;
180 SET_WAS_ICON_NAME_PROVIDED(fw
, 1);
184 /* return now for setup */
188 setup_visible_name(fw
, True
);
189 EWMH_SetVisibleName(fw
, True
);
190 BroadcastWindowIconNames(fw
, False
, True
);
195 int EWMH_WMName(EWMH_CMD_ARGS
)
200 FlocaleCharset
*fc
= NULL
;
205 val
= ewmh_AtomGetByName(
206 FW_W(fw
), "_NET_WM_NAME",
207 EWMH_ATOM_LIST_PROPERTY_NOTIFY
, &size
);
211 SET_HAS_EWMH_WM_NAME(fw
,0);
214 if (IS_WINDOW_FONT_LOADED(fw
) && fw
->title_font
!= NULL
)
216 fc
= fw
->title_font
->str_fc
;
219 tmp_str
= (char *)FiconvUtf8ToCharset(
220 dpy
, fc
, (const char *) val
, size
);
224 SET_HAS_EWMH_WM_NAME(fw
,0);
227 if (strlen(tmp_str
) > MAX_WINDOW_NAME_LEN
)
229 tmp_str
[MAX_WINDOW_NAME_LEN
] = 0;
231 SET_HAS_EWMH_WM_NAME(fw
, 1);
232 if (fw
->name
.name
&& strcmp(tmp_str
, fw
->name
.name
) == 0)
234 /* migo: some apps update their names every second */
242 free_window_names(fw
, True
, False
);
245 fw
->name
.name
= tmp_str
;
252 setup_visible_name(fw
, False
);
253 SET_NAME_CHANGED(fw
, 1);
254 EWMH_SetVisibleName(fw
, False
);
255 BroadcastWindowIconNames(fw
, True
, False
);
257 /* fix the name in the title bar */
258 if (!IS_ICONIFIED(fw
))
260 border_draw_decorations(
261 fw
, PART_TITLE
, (Scr
.Hilite
== fw
),
262 True
, CLEAR_ALL
, NULL
, NULL
);
265 if (!WAS_ICON_NAME_PROVIDED(fw
))
267 fw
->icon_name
= fw
->name
;
268 setup_visible_name(fw
, True
);
269 BroadcastWindowIconNames(fw
, False
, True
);
270 EWMH_SetVisibleName(fw
, True
);
276 #define MAX(A,B) ((A)>(B)? (A):(B))
278 * set the desktop name
280 void EWMH_SetDesktopNames(void)
287 unsigned char **names
;
295 d
= Scr
.Desktops
->next
;
296 /* skip negative desk */
297 while (d
!= NULL
&& d
->desk
< 0)
302 while (d
!= NULL
&& d
->name
!= NULL
&& d
->desk
== nbr
)
311 names
= (void *)safemalloc(sizeof(*names
)*nbr
);
312 for (i
= 0; i
< nbr
; i
++)
314 names
[i
] = (unsigned char *)FiconvCharsetToUtf8(
315 dpy
, NULL
, s
->name
, strlen(s
->name
));
318 len
+= strlen((char *)names
[i
]) + 1;
326 val
= (unsigned char *)safemalloc(len
);
327 for (i
= 0; i
< nbr
; i
++)
329 if (names
[i
] != NULL
)
331 memcpy(&val
[j
], names
[i
], strlen((char *)names
[i
]));
332 j
+= strlen((char *)names
[i
]);
338 Scr
.Root
, "_NET_DESKTOP_NAMES", EWMH_ATOM_LIST_CLIENT_ROOT
,
339 (unsigned char *)val
, len
);