Package list xapp / 0efb96c
xapp-gtk-window: Add wrapper functions for GtkWindow subclasses. Michael Webster 4 years ago
2 changed file(s) with 134 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
229229 gtk_window_set_icon_from_file (GTK_WINDOW (window), file_name, error);
230230 }
231231
232 /* Wrappers (for GtkWindow subclasses like GtkDialog)
233 * window must be a GtkWindow or descendant */
234
235 static void
236 on_gtk_window_realized (GtkWidget *widget,
237 gpointer user_data)
238 {
239 gchar *int_string;
240
241 g_return_if_fail (GTK_IS_WIDGET (widget));
242
243 int_string = (gchar *) user_data;
244
245 g_signal_handlers_disconnect_by_func (widget, on_gtk_window_realized, int_string);
246 g_object_weak_unref (G_OBJECT (widget), (GWeakNotify) g_free, int_string);
247
248 set_window_hint (widget, int_string);
249
250 g_free (int_string);
251 }
252
253 /**
254 * xapp_set_window_icon_name:
255 * @window: The #GtkWindow to set the icon name for
256 * @icon_name: (nullable): The icon name to set, or %NULL to unset.
257 *
258 * Sets the icon name hint for a window manager (like muffin) to make
259 * available when applications want to change their icons during runtime
260 * without having to resort to the internal low-res pixbufs that GdkWindow
261 * sets on the client side. This is a function, not a method, for taking
262 * advantage of this feature with descendants of GtkWindows, such as
263 * GtkDialogs. Sets gtk_window_set_icon_name as well, to avoid needing
264 * to have two calls each time. Set to %NULL to unset.
265 */
266
267 void
268 xapp_set_window_icon_name (XAppGtkWindow *window,
269 const gchar *icon_name)
270 {
271 g_return_if_fail (GTK_IS_WINDOW (window));
272
273 if (XAPP_IS_GTK_WINDOW (window))
274 {
275 g_warning("Window is an instance of XAppGtkWindow. Use the instance set_icon_name method instead.");
276 }
277
278 /* If the window is realized, set the icon name immediately */
279 if (gtk_widget_get_realized (GTK_WIDGET (window)))
280 {
281 set_window_hint (GTK_WIDGET (window), icon_name);
282 }
283 /* Otherwise, hang a callback on window's realize signal and do it then */
284 else
285 {
286 gchar *int_string;
287
288 int_string = g_strdup (icon_name);
289
290 g_signal_connect_after (GTK_WIDGET (window),
291 "realize",
292 G_CALLBACK (on_gtk_window_realized),
293 int_string);
294
295 /* Insurance, in case window gets destroyed without ever being realized */
296 g_object_weak_ref (G_OBJECT (window),
297 (GWeakNotify) g_free,
298 int_string);
299 }
300
301 /* Call the GtkWindow method for compatibility */
302 gtk_window_set_icon_name (GTK_WINDOW (window), icon_name);
303 }
304
305
306 /**
307 * xapp_set_window_icon_from_file:
308 * @window: The #GtkWindow to set the icon name for
309 * @file_name: (nullable): The icon path to set, or %NULL to unset.
310 * @error: (nullable): An error to set if something goes wrong.
311 *
312 * Sets the icon name hint for a window manager (like muffin) to make
313 * available when applications want to change their icons during runtime
314 * without having to resort to the internal low-res pixbufs that GdkWindow
315 * sets on the client side. This also chains up and calls GtkWindow.set_icon_from_file
316 * for convenience and compatibility. Set to %NULL to unset.
317 */
318 void
319 xapp_set_window_icon_from_file (GtkWindow *window,
320 const gchar *file_name,
321 GError **error)
322 {
323 g_return_if_fail (GTK_IS_WINDOW (window));
324
325 if (XAPP_IS_GTK_WINDOW (window))
326 {
327 g_warning("Window is an instance of XAppGtkWindow. Use the instance set_icon_from_file method instead.");
328 }
329
330 /* If the window is realized, set the icon name immediately */
331 if (gtk_widget_get_realized (GTK_WIDGET (window)))
332 {
333 set_window_hint (GTK_WIDGET (window), file_name);
334 }
335 /* Otherwise, hang a callback on window's realize signal and do it then */
336 else
337 {
338 gchar *int_string;
339
340 int_string = g_strdup (file_name);
341
342 g_signal_connect_after (GTK_WIDGET (window),
343 "realize",
344 G_CALLBACK (on_gtk_window_realized),
345 int_string);
346
347 /* Insurance, in case window gets destroyed without ever being realized */
348 g_object_weak_ref (G_OBJECT (window),
349 (GWeakNotify) g_free,
350 int_string);
351 }
352
353 /* Call the GtkWindow method for compatibility */
354 gtk_window_set_icon_from_file (GTK_WINDOW (window), file_name, error);
355 }
3030 GtkWindowClass parent_class;
3131 };
3232
33 /* Class */
3334 GType xapp_gtk_window_get_type (void);
3435 XAppGtkWindow *xapp_gtk_window_new (void);
3536
4041 const gchar *file_name,
4142 GError **error);
4243
44 /* Wrappers (for GtkWindow subclasses like GtkDialog)*/
45
46 void xapp_set_window_icon_name (XAppGtkWindow *window,
47 const gchar *icon_name);
48
49 void xapp_set_window_icon_from_file (GtkWindow *window,
50 const gchar *file_name,
51 GError **error);
52
4353 G_END_DECLS
4454
4555 #endif /* __XAPP_GTK_WINDOW_H__ */