Codebase list xapp / debian/2.0.5-1 libxapp / xapp-gtk-window.c
debian/2.0.5-1

Tree @debian/2.0.5-1 (Download .tar.gz)

xapp-gtk-window.c @debian/2.0.5-1raw · history · blame

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
#include <config.h>

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>

#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include "xapp-gtk-window.h"

#define ICON_NAME_HINT "_NET_WM_XAPP_ICON_NAME"
#define PROGRESS_HINT  "_NET_WM_XAPP_PROGRESS"
#define PROGRESS_PULSE_HINT  "_NET_WM_XAPP_PROGRESS_PULSE"

/**
 * SECTION:xapp-gtk-window
 * @Short_description: A subclass of %GtkWindow that allows additional
   communication with the window manager.
 * @Title: XAppGtkWindow
 *
 * This widget is a simple subclass of GtkWindow that provides the following
 * additional capabilities:
 *
 * - Ability to set an icon name or icon file path for the window manager to
 *   make use of, rather than relying on a desktop file or fixed-size window-
 *   backed icon that Gtk normally generates.  The window manager must support
 *   the NET_WM_XAPP_ICON_NAME hint.
 *
 * - Ability to send progress info to the window manager, in the form of an integer,
 *   0-100, which can then be used to display this progress in some manner in a task
 *   manager or window list.  The window manager must support the NET_WM_XAPP_PROGRESS
 *   hint.
 *
 * - Ability to signal a 'pulsing' progress state, of potentially indeterminate value,
 *   in the form of a boolean, which can be passed on to a window list.  The window
 *   manager must support the NET_WM_XAPP_PROGRESS_PULSE hint
 *
 * Wrappers:
 *
 * Also provided are corresponding wrapper functions for normal GtkWindows.
 * They are not class methods - they are called with the target widget as their first
 * argument.
 *
 * For example:
 *
 * win = Gtk.Window()
 * XApp.set_window_icon_name(win, "foobar")
 *
 * These functions mirror those of the #XAppGtkWindow class, but allow the properties
 * to work with normal GtkWindows and descendants of GtkWindow.
 */

typedef struct
{
    gchar   *icon_name;
    gchar   *icon_path;
    guint    progress;
    gboolean progress_pulse;
} XAppGtkWindowPrivate;

G_DEFINE_TYPE_WITH_PRIVATE (XAppGtkWindow, xapp_gtk_window, GTK_TYPE_WINDOW)

static gboolean
is_x11_session (void)
{
    static gboolean running_x11 = FALSE;
    static gsize once_init_value = 0;

    if (g_once_init_enter (&once_init_value))
    {
        running_x11 = GDK_IS_X11_DISPLAY(gdk_display_get_default());
        g_debug ("XAppGtkWindow: is_x11_session: %s\n", running_x11 ? "TRUE" : "FALSE");

        g_once_init_leave (&once_init_value, 1);
    }

    return running_x11;
}

static void
clear_icon_strings (XAppGtkWindowPrivate *priv)
{
    g_clear_pointer (&priv->icon_name, g_free);
    g_clear_pointer (&priv->icon_path, g_free);
}

static void
set_window_hint_utf8 (Window       xid,
                      const gchar *atom_name,
                      const gchar *str)
{
    GdkDisplay *display;

    display = gdk_display_get_default ();

    if (str != NULL)
    {
        XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
                         xid,
                         gdk_x11_get_xatom_by_name_for_display (display, atom_name),
                         gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
                         PropModeReplace, (guchar *) str, strlen (str));
    }
    else
    {
        XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
                         xid,
                         gdk_x11_get_xatom_by_name_for_display (display, atom_name));
    }
}

static void
set_window_hint_cardinal (Window       xid,
                          const gchar *atom_name,
                          gulong       cardinal)
{
    GdkDisplay *display;

    display = gdk_display_get_default ();

    gdk_error_trap_push ();

    if (cardinal > 0)
    {
        XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
                         xid,
                         gdk_x11_get_xatom_by_name_for_display (display, atom_name),
                         XA_CARDINAL, 32,
                         PropModeReplace,
                         (guchar *) &cardinal, 1);
    }
    else
    {
        XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
                         xid,
                         gdk_x11_get_xatom_by_name_for_display (display, atom_name));
    }

    gdk_error_trap_pop_ignored ();
}

static Window
get_window_xid (GtkWindow *window)
{
    GdkWindow *gdk_window;

    gdk_window = gtk_widget_get_window (GTK_WIDGET (window));

    if (gdk_window_get_effective_toplevel (gdk_window) != gdk_window)
    {
        g_warning ("Window is not toplevel");
        return 0;
    }

    return GDK_WINDOW_XID (gdk_window);
}

static void
update_window_icon (GtkWindow            *window,
                    XAppGtkWindowPrivate *priv)
{
    if (!is_x11_session ()) {
        return;
    }

    /* Icon name/path */
    if (priv->icon_name != NULL)
    {
        set_window_hint_utf8 (get_window_xid (window),
                              ICON_NAME_HINT,
                              priv->icon_name);
    }
    else if (priv->icon_path != NULL)
    {
        set_window_hint_utf8 (get_window_xid (window),
                              ICON_NAME_HINT,
                              priv->icon_path);
    }
    else
    {
        set_window_hint_utf8 (get_window_xid (window),
                              ICON_NAME_HINT,
                              NULL);
    }
}

static void
update_window_progress (GtkWindow            *window,
                        XAppGtkWindowPrivate *priv)
{
    if (!is_x11_session ()) {
        return;
    }

    /* Progress: 0 - 100 */
    set_window_hint_cardinal (get_window_xid (window),
                              PROGRESS_HINT,
                              (gulong) priv->progress);

    set_window_hint_cardinal (get_window_xid (window),
                              PROGRESS_PULSE_HINT,
                              (gulong) (priv->progress_pulse ? 1 : 0));
}

static void
set_icon_name_internal (GtkWindow            *window,
                        XAppGtkWindowPrivate *priv,
                        const gchar          *icon_name)
{
    if (g_strcmp0 (icon_name, priv->icon_name) == 0)
    {
        gtk_window_set_icon_name (window, icon_name);
        return;
    }

    /* Clear both strings when either is set - this ensures the
     * correct value is set during update_window() */
    clear_icon_strings (priv);

    if (icon_name != NULL)
    {
        priv->icon_name = g_strdup (icon_name);
    }

    /* If the window is realized, set the icon name immediately.
     * If it's not, it will be set by xapp_gtk_window_realize(). */
    if (gtk_widget_get_realized (GTK_WIDGET (window)))
    {
        update_window_icon (window, priv);
    }

    /* Call the GtkWindow method for compatibility */
    gtk_window_set_icon_name (GTK_WINDOW (window), icon_name);
}

static void
set_icon_from_file_internal (GtkWindow            *window,
                             XAppGtkWindowPrivate *priv,
                             const gchar          *file_name,
                             GError              **error)
{
    if (g_strcmp0 (file_name, priv->icon_path) == 0)
    {
        gtk_window_set_icon_from_file (window, file_name, error);
        return;
    }

    /* Clear both strings when either is set - this ensures the correct
     * value is set during update_window() */
    clear_icon_strings (priv);

    if (file_name != NULL)
    {
        priv->icon_path = g_strdup (file_name);
    }

    /* If the window is realized, set the icon path immediately.
     * If it's not, it will be set by xapp_gtk_window_realize(). */
    if (gtk_widget_get_realized (GTK_WIDGET (window)))
    {
        update_window_icon (window, priv);
    }

    gtk_window_set_icon_from_file (GTK_WINDOW (window), file_name, error);
}

static void
set_progress_internal (GtkWindow            *window,
                       XAppGtkWindowPrivate *priv,
                       gint                 progress)
{
    gboolean update;
    guint clamped_progress;

    update = FALSE;

    if (priv->progress_pulse)
    {
        priv->progress_pulse = FALSE;
        update = TRUE;
    }

    clamped_progress = CLAMP (progress, 0, 100);

    if (clamped_progress != priv->progress)
    {
        priv->progress = clamped_progress;
        update = TRUE;
    }

    /* If the window is realized, set the progress immediately.
     * If it's not, it will be set by xapp_gtk_window_realize(). */
    if (gtk_widget_get_realized (GTK_WIDGET (window)))
    {
        if (update)
        {
            update_window_progress (window, priv);
        }
    }
}

static void
set_progress_pulse_internal (GtkWindow            *window,
                             XAppGtkWindowPrivate *priv,
                             gboolean              pulse)
{
    gboolean update;

    update = FALSE;

    if (priv->progress_pulse != pulse)
    {
        priv->progress_pulse = pulse;

        update = TRUE;
    }

    /* If the window is realized, set the progress immediately.
     * If it's not, it will be set by xapp_gtk_window_realize(). */
    if (gtk_widget_get_realized (GTK_WIDGET (window)))
    {
        if (update)
        {
            update_window_progress (window, priv);
        }
    }
}

static void
xapp_gtk_window_realize (GtkWidget *widget)
{
    XAppGtkWindow *window = XAPP_GTK_WINDOW (widget);
    XAppGtkWindowPrivate *priv = xapp_gtk_window_get_instance_private (window);

    GTK_WIDGET_CLASS (xapp_gtk_window_parent_class)->realize (widget);

    update_window_icon (GTK_WINDOW (window), priv);
    update_window_progress (GTK_WINDOW (window), priv);
}

static void
xapp_gtk_window_unrealize (GtkWidget *widget)
{
    GTK_WIDGET_CLASS (xapp_gtk_window_parent_class)->unrealize (widget);
}

static void
xapp_gtk_window_finalize (GObject *object)
{
    XAppGtkWindow *window = XAPP_GTK_WINDOW (object);
    XAppGtkWindowPrivate *priv = xapp_gtk_window_get_instance_private (window);

    clear_icon_strings (priv);

    G_OBJECT_CLASS (xapp_gtk_window_parent_class)->finalize (object);
}

static void
xapp_gtk_window_init (XAppGtkWindow *window)
{
    XAppGtkWindowPrivate *priv;
    priv = xapp_gtk_window_get_instance_private (window);

    priv->icon_name = NULL;
    priv->icon_path = NULL;
}

static void
xapp_gtk_window_class_init (XAppGtkWindowClass *klass)
{
    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
    GtkWidgetClass *wclass = GTK_WIDGET_CLASS (klass);

    gobject_class->finalize = xapp_gtk_window_finalize;
    wclass->realize = xapp_gtk_window_realize;
    wclass->unrealize = xapp_gtk_window_unrealize;
}

/**
 * xapp_gtk_window_new:
 * @type: The #GtkWindowType to use
 *
 * Creates a new #XAppGtkWindow of type @type.  See gtk_window_new()
 * for more details.
 *
 * Returns: A new #XAppGtkWindow (transfer: full)
 */
GtkWidget *
xapp_gtk_window_new (GtkWindowType type)
{
    return g_object_new (XAPP_TYPE_GTK_WINDOW, "type", type, NULL);
}

/**
 * xapp_gtk_window_set_icon_name:
 * @window: The #XAppGtkWindow to set the icon name for
 * @icon_name: (nullable): The icon name or path to set, or %NULL to unset.
 * 
 * Sets the icon name hint for a window manager (like muffin) to make
 * available when applications want to change their icons during runtime
 * without having to resort to the internal low-res pixbufs that GdkWindow
 * sets on the client side.  This also chains up and calls GtkWindow.set_icon_name
 * for convenience and compatibility.  Set to %NULL to unset.
 */
void
xapp_gtk_window_set_icon_name (XAppGtkWindow   *window,
                               const gchar     *icon_name)
{
    g_return_if_fail (XAPP_IS_GTK_WINDOW (window));

    XAppGtkWindowPrivate *priv = xapp_gtk_window_get_instance_private (window);

    set_icon_name_internal (GTK_WINDOW (window), priv, icon_name);
}

/**
 * xapp_gtk_window_set_icon_from_file:
 * @window: The #XAppGtkWindow to set the icon name for
 * @file_name: (nullable): The icon path to set, or %NULL to unset.
 * @error: (nullable): An error to set if something goes wrong.
 * 
 * Sets the icon name hint for a window manager (like muffin) to make
 * available when applications want to change their icons during runtime
 * without having to resort to the internal low-res pixbufs that GdkWindow
 * sets on the client side.  This also chains up and calls GtkWindow.set_icon_from_file
 * for convenience and compatibility.  Set to %NULL to unset.
 */
void
xapp_gtk_window_set_icon_from_file (XAppGtkWindow   *window,
                                    const gchar     *file_name,
                                    GError         **error)
{
    g_return_if_fail (XAPP_IS_GTK_WINDOW (window));

    XAppGtkWindowPrivate *priv = xapp_gtk_window_get_instance_private (window);

    set_icon_from_file_internal (GTK_WINDOW (window), priv, file_name, error);
}

/**
 * xapp_gtk_window_set_progress:
 * @window: The #XAppGtkWindow to set the progress for
 * @progress: The value to set for progress.
 *
 * Sets the progress hint for a window manager (like muffin) to make
 * available when applications want to display the application's progress
 * in some operation. The value sent to the WM will be clamped to
 * between 0 and 100.
 *
 * Note: If a window will stick around after progress is complete, you will
 * probaby need to set progress to 0 to remove any progress effects on taskbars
 * and window lists.
 *
 * Setting progress will also cancel the 'pulsing' flag on the window as
 * well, if it has been set.
 */
void
xapp_gtk_window_set_progress (XAppGtkWindow   *window,
                              gint             progress)
{
    g_return_if_fail (XAPP_IS_GTK_WINDOW (window));

    XAppGtkWindowPrivate *priv = xapp_gtk_window_get_instance_private (window);

    set_progress_internal (GTK_WINDOW (window), priv, progress);
}

/**
 * xapp_gtk_window_set_progress_pulse:
 * @window: The #XAppGtkWindow to set the progress for
 * @pulse: Whether to have pulsing set or not.
 * 
 * Sets the progress pulse hint hint for a window manager (like muffin)
 * to make available when applications want to display indeterminate or
 * ongoing progress in a task manager.
 *
 * Note: If a window will stick around after progress is complete, you will
 * probaby need to set progress to 0 to remove any progress effects on taskbars
 * and window lists.  This will also remove the pulse state, if it is set.
 *
 * Setting an explicit progress value will unset this flag.
 */
void
xapp_gtk_window_set_progress_pulse (XAppGtkWindow   *window,
                                    gboolean         pulse)
{
    g_return_if_fail (XAPP_IS_GTK_WINDOW (window));

    XAppGtkWindowPrivate *priv = xapp_gtk_window_get_instance_private (window);

    set_progress_pulse_internal (GTK_WINDOW (window), priv, pulse);
}


/* Wrappers (for GtkWindow subclasses like GtkDialog)
 * window must be a GtkWindow or descendant */
static void
on_gtk_window_realized (GtkWidget *widget,
                        gpointer   user_data)
{
    XAppGtkWindowPrivate *priv;

    priv = (XAppGtkWindowPrivate *) user_data;

    update_window_icon (GTK_WINDOW (widget), priv);
    update_window_progress (GTK_WINDOW (widget), priv);
}

static void
destroy_xapp_struct (gpointer user_data)
{
    XAppGtkWindowPrivate *priv = (XAppGtkWindowPrivate *) user_data;

    g_clear_pointer (&priv->icon_name, g_free);
    g_clear_pointer (&priv->icon_path, g_free);

    g_slice_free (XAppGtkWindowPrivate, priv);
}

static XAppGtkWindowPrivate *
get_xapp_struct (GtkWindow *window)
{
    XAppGtkWindowPrivate *priv;

    priv = g_object_get_data (G_OBJECT (window),
                              "xapp-window-struct");

    if (priv)
    {
        return priv;
    }

    priv = g_slice_new0 (XAppGtkWindowPrivate);

    g_object_set_data_full (G_OBJECT (window),
                            "xapp-window-struct",
                            priv,
                            (GDestroyNotify) destroy_xapp_struct);

    g_signal_connect_after (GTK_WIDGET (window),
                            "realize",
                            G_CALLBACK (on_gtk_window_realized),
                            priv);

    return priv;
}

/**
 * xapp_set_window_icon_name:
 * @window: The #GtkWindow to set the icon name for
 * @icon_name: (nullable): The icon name to set, or %NULL to unset.
 *
 * Sets the icon name hint for a window manager (like muffin) to make
 * available when applications want to change their icons during runtime
 * without having to resort to the internal low-res pixbufs that GdkWindow
 * sets on the client side.  This is a function, not a method, for taking
 * advantage of this feature with descendants of GtkWindows, such as
 * GtkDialogs.  Sets gtk_window_set_icon_name as well, to avoid needing
 * to have two calls each time.  Set to %NULL to unset.
 */
void
xapp_set_window_icon_name (GtkWindow       *window,
                           const gchar     *icon_name)
{
    XAppGtkWindowPrivate *priv;

    g_return_if_fail (GTK_IS_WINDOW (window));

    priv = get_xapp_struct (window);

    if (XAPP_IS_GTK_WINDOW (window))
    {
        g_warning("Window is an instance of XAppGtkWindow.  Use the instance set_icon_name method instead.");
    }

    set_icon_name_internal (window, priv, icon_name);
}


/**
 * xapp_set_window_icon_from_file:
 * @window: The #GtkWindow to set the icon name for
 * @file_name: (nullable): The icon path to set, or %NULL to unset.
 * @error: (nullable): An error to set if something goes wrong.
 *
 * Sets the icon name hint for a window manager (like muffin) to make
 * available when applications want to change their icons during runtime
 * without having to resort to the internal low-res pixbufs that GdkWindow
 * sets on the client side.  This also chains up and calls GtkWindow.set_icon_from_file
 * for convenience and compatibility.  Set to %NULL to unset.
 */
void
xapp_set_window_icon_from_file (GtkWindow   *window,
                                const gchar *file_name,
                                GError     **error)
{
    XAppGtkWindowPrivate *priv;

    g_return_if_fail (GTK_IS_WINDOW (window));

    priv = get_xapp_struct (window);

    if (XAPP_IS_GTK_WINDOW (window))
    {
        g_warning("Window is an instance of XAppGtkWindow.  Use the instance set_icon_from_file method instead.");
    }

    set_icon_from_file_internal (window, priv, file_name, error);
}

/**
 * xapp_set_window_progress:
 * @window: The #GtkWindow to set the progress for
 * @progress: The value to set for progress.
 *
 * Sets the progress hint for a window manager (like muffin) to make
 * available when applications want to display the application's progress
 * in some operation. The value sent to the WM will be clamped to
 * between 0 and 100.
 *
 * Note: If a window will stick around after progress is complete, you will
 * probaby need to set progress to 0 to remove any progress effects on taskbars
 * and window lists.
 *
 * Setting progress will also cancel the 'pulsing' flag on the window as
 * well, if it has been set.
 */
void
xapp_set_window_progress (GtkWindow   *window,
                          gint         progress)
{
    XAppGtkWindowPrivate *priv;

    g_return_if_fail (GTK_IS_WINDOW (window));

    priv = get_xapp_struct (window);

    if (XAPP_IS_GTK_WINDOW (window))
    {
        g_warning("Window is an instance of XAppGtkWindow.  Use the instance set_progress method instead.");
    }

    set_progress_internal (window, priv, progress);
}

/**
 * xapp_set_window_progress_pulse:
 * @window: The #GtkWindow to set the progress for
 * @pulse: Whether to have pulsing set or not.
 * 
 * Sets the progress pulse hint hint for a window manager (like muffin)
 * to make available when applications want to display indeterminate or
 * ongoing progress in a task manager.
 *
 * Note: If a window will stick around after progress is complete, you will
 * probaby need to set progress to 0 to remove any progress effects on taskbars
 * and window lists.  This will also remove the pulse state, if it is set.
 *
 * Setting an explicit progress value will unset this flag.
 */
void
xapp_set_window_progress_pulse (GtkWindow   *window,
                                gboolean     pulse)
{
    XAppGtkWindowPrivate *priv;

    g_return_if_fail (GTK_IS_WINDOW (window));

    priv = get_xapp_struct (window);

    if (XAPP_IS_GTK_WINDOW (window))
    {
        g_warning("Window is an instance of XAppGtkWindow.  Use the instance set_progress_pulse method instead.");
    }

    set_progress_pulse_internal (GTK_WINDOW (window), priv, pulse);
}

/**
 * xapp_set_xid_icon_name:
 * @xid: The Window to set the icon name for
 * @icon_name: (nullable): The icon name to set, or %NULL to unset.
 *
 * Sets the icon name hint for a window manager (like muffin) to make
 * available when applications want to change their icons during runtime
 * without having to resort to the internal low-res pixbufs that GdkWindow
 * sets on the client side.  This is a function, not a method, for applying
 * the icon name property for a given (possibly foreign) window, by passing
 * the window's XID.  Set to %NULL to unset.
 */
void
xapp_set_xid_icon_name (gulong           xid,
                        const gchar     *icon_name)
{
    g_return_if_fail (xid > 0);

    set_window_hint_utf8 (xid, ICON_NAME_HINT, icon_name);
}

/**
 * xapp_set_xid_icon_from_file:
 * @xid: The Window to set the icon name for
 * @file_name: (nullable): The icon path to set, or %NULL to unset.
 *
 * Sets the icon name hint for a window manager (like muffin) to make
 * available when applications want to change their icons during runtime
 * without having to resort to the internal low-res pixbufs that GdkWindow
 * sets on the client side.  This is a function, not a method, for applying
 * the icon name property for a given (possibly foreign) window, by passing
 * the window's XID.  Set to %NULL to unset.
 */
void
xapp_set_xid_icon_from_file (gulong       xid,
                             const gchar *file_name)
{

    g_return_if_fail (xid > 0);

    set_window_hint_utf8 (xid, ICON_NAME_HINT, file_name);
}

/**
 * xapp_set_xid_progress:
 * @xid: The Window to set the progress for
 * @progress: The value to set for progress.
 *
 * Sets the progress hint for a window manager (like muffin) to make
 * available when applications want to display the application's progress
 * in some operation. The value sent to the WM will be clamped to
 * between 0 and 100.
 *
 * Setting progress will also cancel the 'pulsing' flag on the window as
 * well, if it has been set.
 *
 * Note: If a window will stick around after progress is complete, you will
 * probaby need to set progress to 0 to remove any progress effects on taskbars
 * and window lists.
 *
 * This is a function, not a method, for applying the progress property for
 * a given (possibly foreign) window, by passing the window's XID.
 */
void
xapp_set_xid_progress (gulong       xid,
                       gint         progress)
{
    g_return_if_fail (xid > 0);

    set_window_hint_cardinal (xid, PROGRESS_HINT, (gulong) (CLAMP (progress, 0, 100)));
    set_window_hint_cardinal (xid, PROGRESS_PULSE_HINT, (gulong) 0);
}

/**
 * xapp_set_xid_progress_pulse:
 * @xid: The Window to set the progress for
 * @pulse: Whether to have pulsing set or not.
 *
 * Sets the progress pulse hint hint for a window manager (like muffin)
 * to make available when applications want to display indeterminate or
 * ongoing progress in a task manager.
 *
 * Note: If a window will stick around after progress is complete, you will
 * probaby need to set progress to 0 to remove any progress effects on taskbars
 * and window lists.
 *
 * Setting an explicit progress value will unset this flag.
 */
void
xapp_set_xid_progress_pulse (gulong       xid,
                             gboolean     pulse)
{
    g_return_if_fail (xid > 0);

    set_window_hint_cardinal (xid, PROGRESS_PULSE_HINT, (gulong) (pulse ? 1 : 0));
}