4 | 4 |
#include <string.h>
|
5 | 5 |
#include <math.h>
|
6 | 6 |
#include <X11/Xlib.h>
|
|
7 |
#include <X11/Xatom.h>
|
7 | 8 |
|
8 | 9 |
#include <gdk/gdk.h>
|
9 | 10 |
#include <gdk/gdkx.h>
|
10 | 11 |
#include "xapp-gtk-window.h"
|
11 | 12 |
|
|
13 |
#define ICON_NAME_HINT "_NET_WM_XAPP_ICON_NAME"
|
|
14 |
#define PROGRESS_HINT "_NET_WM_XAPP_PROGRESS"
|
|
15 |
#define PROGRESS_PULSE_HINT "_NET_WM_XAPP_PROGRESS_PULSE"
|
|
16 |
|
12 | 17 |
struct _XAppGtkWindowPrivate
|
13 | 18 |
{
|
14 | |
gchar *icon_name;
|
15 | |
gchar *icon_path;
|
16 | |
gboolean need_set_at_realize;
|
|
19 |
gchar *icon_name;
|
|
20 |
gchar *icon_path;
|
|
21 |
guint progress;
|
|
22 |
gboolean progress_pulse;
|
17 | 23 |
};
|
18 | 24 |
|
19 | 25 |
G_DEFINE_TYPE (XAppGtkWindow, xapp_gtk_window, GTK_TYPE_WINDOW);
|
20 | 26 |
|
21 | 27 |
static void
|
22 | |
clear_strings (XAppGtkWindow *window)
|
23 | |
{
|
24 | |
XAppGtkWindowPrivate *priv = window->priv;
|
25 | |
|
|
28 |
clear_icon_strings (XAppGtkWindowPrivate *priv)
|
|
29 |
{
|
26 | 30 |
g_clear_pointer (&priv->icon_name, g_free);
|
27 | 31 |
g_clear_pointer (&priv->icon_path, g_free);
|
28 | 32 |
}
|
29 | 33 |
|
30 | 34 |
static void
|
31 | |
set_window_hint (GtkWidget *widget,
|
32 | |
const gchar *str)
|
|
35 |
set_window_hint_utf8 (GtkWidget *widget,
|
|
36 |
const gchar *atom_name,
|
|
37 |
const gchar *str)
|
33 | 38 |
{
|
34 | 39 |
GdkDisplay *display;
|
35 | 40 |
GdkWindow *window;
|
|
48 | 53 |
{
|
49 | 54 |
XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
|
50 | 55 |
GDK_WINDOW_XID (window),
|
51 | |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_XAPP_ICON_NAME"),
|
|
56 |
gdk_x11_get_xatom_by_name_for_display (display, atom_name),
|
52 | 57 |
gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
|
53 | 58 |
PropModeReplace, (guchar *) str, strlen (str));
|
54 | 59 |
}
|
|
56 | 61 |
{
|
57 | 62 |
XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
|
58 | 63 |
GDK_WINDOW_XID (window),
|
59 | |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_XAPP_ICON_NAME"));
|
60 | |
}
|
61 | |
}
|
62 | |
|
63 | |
static void
|
64 | |
update_window (XAppGtkWindow *window)
|
65 | |
{
|
66 | |
XAppGtkWindowPrivate *priv = window->priv;
|
67 | |
|
|
64 |
gdk_x11_get_xatom_by_name_for_display (display, atom_name));
|
|
65 |
}
|
|
66 |
}
|
|
67 |
|
|
68 |
static void
|
|
69 |
set_window_hint_cardinal (GtkWidget *widget,
|
|
70 |
const gchar *atom_name,
|
|
71 |
gulong cardinal)
|
|
72 |
{
|
|
73 |
GdkDisplay *display;
|
|
74 |
GdkWindow *window;
|
|
75 |
|
|
76 |
window = gtk_widget_get_window (widget);
|
|
77 |
|
|
78 |
if (gdk_window_get_effective_toplevel (window) != window)
|
|
79 |
{
|
|
80 |
g_warning ("Window is not toplevel");
|
|
81 |
return;
|
|
82 |
}
|
|
83 |
|
|
84 |
display = gdk_window_get_display (window);
|
|
85 |
|
|
86 |
if (cardinal > 0)
|
|
87 |
{
|
|
88 |
XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
|
|
89 |
GDK_WINDOW_XID (window),
|
|
90 |
gdk_x11_get_xatom_by_name_for_display (display, atom_name),
|
|
91 |
XA_CARDINAL, 32,
|
|
92 |
PropModeReplace,
|
|
93 |
(guchar *) &cardinal, 1);
|
|
94 |
}
|
|
95 |
else
|
|
96 |
{
|
|
97 |
XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
|
|
98 |
GDK_WINDOW_XID (window),
|
|
99 |
gdk_x11_get_xatom_by_name_for_display (display, atom_name));
|
|
100 |
}
|
|
101 |
}
|
|
102 |
|
|
103 |
static void
|
|
104 |
update_window_icon (GtkWindow *window,
|
|
105 |
XAppGtkWindowPrivate *priv)
|
|
106 |
{
|
|
107 |
/* Icon name/path */
|
68 | 108 |
if (priv->icon_name != NULL)
|
69 | 109 |
{
|
70 | |
set_window_hint (GTK_WIDGET (window), priv->icon_name);
|
|
110 |
set_window_hint_utf8 (GTK_WIDGET (window), ICON_NAME_HINT, priv->icon_name);
|
71 | 111 |
}
|
72 | 112 |
else if (priv->icon_path != NULL)
|
73 | 113 |
{
|
74 | |
set_window_hint (GTK_WIDGET (window), priv->icon_path);
|
|
114 |
set_window_hint_utf8 (GTK_WIDGET (window), ICON_NAME_HINT, priv->icon_path);
|
|
115 |
}
|
|
116 |
else
|
|
117 |
{
|
|
118 |
set_window_hint_utf8 (GTK_WIDGET (window), ICON_NAME_HINT, NULL);
|
|
119 |
}
|
|
120 |
}
|
|
121 |
|
|
122 |
static void
|
|
123 |
update_window_progress (GtkWindow *window,
|
|
124 |
XAppGtkWindowPrivate *priv)
|
|
125 |
{
|
|
126 |
/* Progress: 0 - 100 */
|
|
127 |
set_window_hint_cardinal (GTK_WIDGET (window), PROGRESS_HINT, (gulong) priv->progress);
|
|
128 |
set_window_hint_cardinal (GTK_WIDGET (window), PROGRESS_PULSE_HINT, (gulong) (priv->progress_pulse ? 1 : 0));
|
|
129 |
}
|
|
130 |
|
|
131 |
static void
|
|
132 |
set_icon_name_internal (GtkWindow *window,
|
|
133 |
XAppGtkWindowPrivate *priv,
|
|
134 |
const gchar *icon_name)
|
|
135 |
{
|
|
136 |
if (g_strcmp0 (icon_name, priv->icon_name) == 0)
|
|
137 |
{
|
|
138 |
gtk_window_set_icon_name (window, icon_name);
|
|
139 |
return;
|
|
140 |
}
|
|
141 |
|
|
142 |
/* Clear both strings when either is set - this ensures the
|
|
143 |
* correct value is set during update_window() */
|
|
144 |
clear_icon_strings (priv);
|
|
145 |
|
|
146 |
if (icon_name != NULL)
|
|
147 |
{
|
|
148 |
priv->icon_name = g_strdup (icon_name);
|
|
149 |
}
|
|
150 |
|
|
151 |
/* If the window is realized, set the icon name immediately.
|
|
152 |
* If it's not, it will be set by xapp_gtk_window_realize(). */
|
|
153 |
if (gtk_widget_get_realized (GTK_WIDGET (window)))
|
|
154 |
{
|
|
155 |
update_window_icon (window, priv);
|
|
156 |
}
|
|
157 |
|
|
158 |
/* Call the GtkWindow method for compatibility */
|
|
159 |
gtk_window_set_icon_name (GTK_WINDOW (window), icon_name);
|
|
160 |
}
|
|
161 |
|
|
162 |
static void
|
|
163 |
set_icon_from_file_internal (GtkWindow *window,
|
|
164 |
XAppGtkWindowPrivate *priv,
|
|
165 |
const gchar *file_name,
|
|
166 |
GError **error)
|
|
167 |
{
|
|
168 |
if (g_strcmp0 (file_name, priv->icon_path) == 0)
|
|
169 |
{
|
|
170 |
gtk_window_set_icon_from_file (window, file_name, error);
|
|
171 |
return;
|
|
172 |
}
|
|
173 |
|
|
174 |
/* Clear both strings when either is set - this ensures the correct
|
|
175 |
* value is set during update_window() */
|
|
176 |
clear_icon_strings (priv);
|
|
177 |
|
|
178 |
if (file_name != NULL)
|
|
179 |
{
|
|
180 |
priv->icon_path = g_strdup (file_name);
|
|
181 |
}
|
|
182 |
|
|
183 |
/* If the window is realized, set the icon path immediately.
|
|
184 |
* If it's not, it will be set by xapp_gtk_window_realize(). */
|
|
185 |
if (gtk_widget_get_realized (GTK_WIDGET (window)))
|
|
186 |
{
|
|
187 |
update_window_icon (window, priv);
|
|
188 |
}
|
|
189 |
|
|
190 |
gtk_window_set_icon_from_file (GTK_WINDOW (window), file_name, error);
|
|
191 |
}
|
|
192 |
|
|
193 |
static void
|
|
194 |
set_progress_internal (GtkWindow *window,
|
|
195 |
XAppGtkWindowPrivate *priv,
|
|
196 |
gint progress)
|
|
197 |
{
|
|
198 |
gboolean update;
|
|
199 |
guint clamped_progress;
|
|
200 |
|
|
201 |
update = FALSE;
|
|
202 |
|
|
203 |
if (priv->progress_pulse)
|
|
204 |
{
|
|
205 |
priv->progress_pulse = FALSE;
|
|
206 |
update = TRUE;
|
|
207 |
}
|
|
208 |
|
|
209 |
clamped_progress = CLAMP (progress, 0, 100);
|
|
210 |
|
|
211 |
if (clamped_progress != priv->progress)
|
|
212 |
{
|
|
213 |
priv->progress = clamped_progress;
|
|
214 |
update = TRUE;
|
|
215 |
}
|
|
216 |
|
|
217 |
/* If the window is realized, set the progress immediately.
|
|
218 |
* If it's not, it will be set by xapp_gtk_window_realize(). */
|
|
219 |
if (gtk_widget_get_realized (GTK_WIDGET (window)))
|
|
220 |
{
|
|
221 |
if (update)
|
|
222 |
{
|
|
223 |
update_window_progress (window, priv);
|
|
224 |
}
|
|
225 |
}
|
|
226 |
}
|
|
227 |
|
|
228 |
static void
|
|
229 |
set_progress_pulse_internal (GtkWindow *window,
|
|
230 |
XAppGtkWindowPrivate *priv,
|
|
231 |
gboolean pulse)
|
|
232 |
{
|
|
233 |
gboolean update;
|
|
234 |
|
|
235 |
update = FALSE;
|
|
236 |
|
|
237 |
if (priv->progress_pulse != pulse)
|
|
238 |
{
|
|
239 |
priv->progress_pulse = pulse;
|
|
240 |
|
|
241 |
update = TRUE;
|
|
242 |
}
|
|
243 |
|
|
244 |
/* If the window is realized, set the progress immediately.
|
|
245 |
* If it's not, it will be set by xapp_gtk_window_realize(). */
|
|
246 |
if (gtk_widget_get_realized (GTK_WIDGET (window)))
|
|
247 |
{
|
|
248 |
if (update)
|
|
249 |
{
|
|
250 |
update_window_progress (window, priv);
|
|
251 |
}
|
75 | 252 |
}
|
76 | 253 |
}
|
77 | 254 |
|
|
83 | 260 |
|
84 | 261 |
GTK_WIDGET_CLASS (xapp_gtk_window_parent_class)->realize (widget);
|
85 | 262 |
|
86 | |
if (priv->need_set_at_realize)
|
87 | |
{
|
88 | |
update_window (window);
|
89 | |
priv->need_set_at_realize = FALSE;
|
90 | |
}
|
|
263 |
update_window_icon (GTK_WINDOW (window), priv);
|
|
264 |
update_window_progress (GTK_WINDOW (window), priv);
|
91 | 265 |
}
|
92 | 266 |
|
93 | 267 |
static void
|
94 | 268 |
xapp_gtk_window_unrealize (GtkWidget *widget)
|
95 | 269 |
{
|
96 | 270 |
XAppGtkWindow *window = XAPP_GTK_WINDOW (widget);
|
97 | |
XAppGtkWindowPrivate *priv = window->priv;
|
98 | 271 |
|
99 | 272 |
GTK_WIDGET_CLASS (xapp_gtk_window_parent_class)->unrealize (widget);
|
100 | |
|
101 | |
if (priv->icon_name != NULL || priv->icon_path != NULL)
|
102 | |
{
|
103 | |
priv->need_set_at_realize = TRUE;
|
104 | |
}
|
105 | 273 |
}
|
106 | 274 |
|
107 | 275 |
static void
|
|
110 | 278 |
XAppGtkWindow *window = XAPP_GTK_WINDOW (object);
|
111 | 279 |
XAppGtkWindowPrivate *priv = window->priv;
|
112 | 280 |
|
113 | |
g_clear_pointer (&priv->icon_name, g_free);
|
114 | |
g_clear_pointer (&priv->icon_path, g_free);
|
|
281 |
clear_icon_strings (priv);
|
115 | 282 |
|
116 | 283 |
G_OBJECT_CLASS (xapp_gtk_window_parent_class)->finalize (object);
|
117 | 284 |
}
|
|
127 | 294 |
|
128 | 295 |
priv->icon_name = NULL;
|
129 | 296 |
priv->icon_path = NULL;
|
130 | |
priv->need_set_at_realize = FALSE;
|
131 | 297 |
}
|
132 | 298 |
|
133 | 299 |
static void
|
|
151 | 317 |
|
152 | 318 |
/**
|
153 | 319 |
* xapp_gtk_window_set_icon_name:
|
154 | |
* @window: The #GtkWindow to set the icon name for
|
|
320 |
* @window: The #XAppGtkWindow to set the icon name for
|
155 | 321 |
* @icon_name: (nullable): The icon name or path to set, or %NULL to unset.
|
156 | 322 |
*
|
157 | 323 |
* Sets the icon name hint for a window manager (like muffin) to make
|
|
166 | 332 |
{
|
167 | 333 |
g_return_if_fail (XAPP_IS_GTK_WINDOW (window));
|
168 | 334 |
|
169 | |
clear_strings (window);
|
170 | |
|
171 | |
if (icon_name != NULL)
|
172 | |
{
|
173 | |
window->priv->icon_name = g_strdup (icon_name);
|
174 | |
}
|
175 | |
|
176 | |
/* If the window is realized, set the icon name immediately */
|
177 | |
if (gtk_widget_get_realized (GTK_WIDGET (window)))
|
178 | |
{
|
179 | |
update_window (window);
|
180 | |
}
|
181 | |
/* Otherwise, remind ourselves to do it in our realize vfunc */
|
182 | |
else
|
183 | |
{
|
184 | |
window->priv->need_set_at_realize = TRUE;
|
185 | |
}
|
186 | |
|
187 | |
/* Call the GtkWindow method for compatibility */
|
188 | |
gtk_window_set_icon_name (GTK_WINDOW (window), icon_name);
|
189 | |
}
|
190 | |
|
|
335 |
set_icon_name_internal (GTK_WINDOW (window), window->priv, icon_name);
|
|
336 |
}
|
191 | 337 |
|
192 | 338 |
/**
|
193 | 339 |
* xapp_gtk_window_set_icon_from_file:
|
|
208 | 354 |
{
|
209 | 355 |
g_return_if_fail (XAPP_IS_GTK_WINDOW (window));
|
210 | 356 |
|
211 | |
clear_strings (window);
|
212 | |
|
213 | |
if (file_name != NULL)
|
214 | |
{
|
215 | |
window->priv->icon_path = g_strdup (file_name);
|
216 | |
}
|
217 | |
|
218 | |
/* If the window is realized, set the icon path immediately */
|
219 | |
if (gtk_widget_get_realized (GTK_WIDGET (window)))
|
220 | |
{
|
221 | |
update_window (window);
|
222 | |
}
|
223 | |
/* Otherwise, remind ourselves to do it later */
|
224 | |
else
|
225 | |
{
|
226 | |
window->priv->need_set_at_realize = TRUE;
|
227 | |
}
|
228 | |
|
229 | |
gtk_window_set_icon_from_file (GTK_WINDOW (window), file_name, error);
|
230 | |
}
|
|
357 |
set_icon_from_file_internal (GTK_WINDOW (window), window->priv, file_name, error);
|
|
358 |
}
|
|
359 |
|
|
360 |
/**
|
|
361 |
* xapp_gtk_window_set_progress:
|
|
362 |
* @window: The #XAppGtkWindow to set the progress for
|
|
363 |
* @progress: The value to set for progress.
|
|
364 |
*
|
|
365 |
* Sets the progress hint for a window manager (like muffin) to make
|
|
366 |
* available when applications want to display the application's progress
|
|
367 |
* in some operation. The value sent to the WM will be clamped to
|
|
368 |
* between 0 and 100.
|
|
369 |
*
|
|
370 |
* Setting progress will also cancel the 'pulsing' flag on the window as
|
|
371 |
* well, if it has been set.
|
|
372 |
*/
|
|
373 |
void
|
|
374 |
xapp_gtk_window_set_progress (XAppGtkWindow *window,
|
|
375 |
gint progress)
|
|
376 |
{
|
|
377 |
g_return_if_fail (XAPP_IS_GTK_WINDOW (window));
|
|
378 |
|
|
379 |
set_progress_internal (GTK_WINDOW (window), window->priv, progress);
|
|
380 |
}
|
|
381 |
|
|
382 |
/**
|
|
383 |
* xapp_gtk_window_set_progress_pulse:
|
|
384 |
* @window: The #XAppGtkWindow to set the progress for
|
|
385 |
* @pulse: Whether to have pulsing set or not.
|
|
386 |
*
|
|
387 |
* Sets the progress pulse hint hint for a window manager (like muffin)
|
|
388 |
* to make available when applications want to display indeterminate or
|
|
389 |
* ongoing progress in a task manager.
|
|
390 |
*
|
|
391 |
* Setting an explicit progress value will unset this flag.
|
|
392 |
*/
|
|
393 |
void
|
|
394 |
xapp_gtk_window_set_progress_pulse (XAppGtkWindow *window,
|
|
395 |
gboolean pulse)
|
|
396 |
{
|
|
397 |
g_return_if_fail (XAPP_IS_GTK_WINDOW (window));
|
|
398 |
g_return_if_fail (XAPP_IS_GTK_WINDOW (window));
|
|
399 |
|
|
400 |
set_progress_pulse_internal (GTK_WINDOW (window), window->priv, pulse);
|
|
401 |
}
|
|
402 |
|
231 | 403 |
|
232 | 404 |
/* Wrappers (for GtkWindow subclasses like GtkDialog)
|
233 | 405 |
* window must be a GtkWindow or descendant */
|
234 | |
|
235 | 406 |
static void
|
236 | 407 |
on_gtk_window_realized (GtkWidget *widget,
|
237 | 408 |
gpointer user_data)
|
238 | 409 |
{
|
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);
|
|
410 |
XAppGtkWindowPrivate *priv;
|
|
411 |
|
|
412 |
priv = (XAppGtkWindowPrivate *) user_data;
|
|
413 |
|
|
414 |
update_window_icon (GTK_WINDOW (widget), priv);
|
|
415 |
update_window_progress (GTK_WINDOW (widget), priv);
|
|
416 |
}
|
|
417 |
|
|
418 |
static void
|
|
419 |
destroy_xapp_struct (gpointer user_data)
|
|
420 |
{
|
|
421 |
XAppGtkWindowPrivate *priv = (XAppGtkWindowPrivate *) user_data;
|
|
422 |
|
|
423 |
g_clear_pointer (&priv->icon_name, g_free);
|
|
424 |
g_clear_pointer (&priv->icon_path, g_free);
|
|
425 |
|
|
426 |
g_slice_free (XAppGtkWindowPrivate, priv);
|
|
427 |
}
|
|
428 |
|
|
429 |
static XAppGtkWindowPrivate *
|
|
430 |
get_xapp_struct (GtkWindow *window)
|
|
431 |
{
|
|
432 |
XAppGtkWindowPrivate *priv;
|
|
433 |
|
|
434 |
priv = g_object_get_data (G_OBJECT (window),
|
|
435 |
"xapp-window-struct");
|
|
436 |
|
|
437 |
if (priv)
|
|
438 |
{
|
|
439 |
return priv;
|
|
440 |
}
|
|
441 |
|
|
442 |
priv = g_slice_new0 (XAppGtkWindowPrivate);
|
|
443 |
|
|
444 |
g_object_set_data_full (G_OBJECT (window),
|
|
445 |
"xapp-window-struct",
|
|
446 |
priv,
|
|
447 |
(GDestroyNotify) destroy_xapp_struct);
|
|
448 |
|
|
449 |
g_signal_connect_after (GTK_WIDGET (window),
|
|
450 |
"realize",
|
|
451 |
G_CALLBACK (on_gtk_window_realized),
|
|
452 |
priv);
|
|
453 |
|
|
454 |
return priv;
|
251 | 455 |
}
|
252 | 456 |
|
253 | 457 |
/**
|
|
268 | 472 |
xapp_set_window_icon_name (GtkWindow *window,
|
269 | 473 |
const gchar *icon_name)
|
270 | 474 |
{
|
|
475 |
XAppGtkWindowPrivate *priv;
|
|
476 |
|
271 | 477 |
g_return_if_fail (GTK_IS_WINDOW (window));
|
272 | 478 |
|
|
479 |
priv = get_xapp_struct (window);
|
|
480 |
|
273 | 481 |
if (XAPP_IS_GTK_WINDOW (window))
|
274 | 482 |
{
|
275 | 483 |
g_warning("Window is an instance of XAppGtkWindow. Use the instance set_icon_name method instead.");
|
276 | 484 |
}
|
277 | 485 |
|
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);
|
|
486 |
set_icon_name_internal (window, priv, icon_name);
|
303 | 487 |
}
|
304 | 488 |
|
305 | 489 |
|
|
320 | 504 |
const gchar *file_name,
|
321 | 505 |
GError **error)
|
322 | 506 |
{
|
|
507 |
XAppGtkWindowPrivate *priv;
|
|
508 |
|
323 | 509 |
g_return_if_fail (GTK_IS_WINDOW (window));
|
324 | 510 |
|
|
511 |
priv = get_xapp_struct (window);
|
|
512 |
|
325 | 513 |
if (XAPP_IS_GTK_WINDOW (window))
|
326 | 514 |
{
|
327 | 515 |
g_warning("Window is an instance of XAppGtkWindow. Use the instance set_icon_from_file method instead.");
|
328 | 516 |
}
|
329 | 517 |
|
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 | |
}
|
|
518 |
set_icon_from_file_internal (window, priv, file_name, error);
|
|
519 |
}
|
|
520 |
|
|
521 |
/**
|
|
522 |
* xapp_set_window_progress:
|
|
523 |
* @window: The #GtkWindow to set the progress for
|
|
524 |
* @progress: The value to set for progress.
|
|
525 |
*
|
|
526 |
* Sets the progress hint for a window manager (like muffin) to make
|
|
527 |
* available when applications want to display the application's progress
|
|
528 |
* in some operation. The value sent to the WM will be clamped to
|
|
529 |
* between 0 and 100.
|
|
530 |
*
|
|
531 |
* Setting progress will also cancel the 'pulsing' flag on the window as
|
|
532 |
* well, if it has been set.
|
|
533 |
*/
|
|
534 |
void
|
|
535 |
xapp_set_window_progress (GtkWindow *window,
|
|
536 |
gint progress)
|
|
537 |
{
|
|
538 |
XAppGtkWindowPrivate *priv;
|
|
539 |
|
|
540 |
g_return_if_fail (GTK_IS_WINDOW (window));
|
|
541 |
|
|
542 |
priv = get_xapp_struct (window);
|
|
543 |
|
|
544 |
if (XAPP_IS_GTK_WINDOW (window))
|
|
545 |
{
|
|
546 |
g_warning("Window is an instance of XAppGtkWindow. Use the instance set_progress method instead.");
|
|
547 |
}
|
|
548 |
|
|
549 |
set_progress_internal (window, priv, progress);
|
|
550 |
}
|
|
551 |
|
|
552 |
/**
|
|
553 |
* xapp_set_window_progress_pulse:
|
|
554 |
* @window: The #GtkWindow to set the progress for
|
|
555 |
* @pulse: Whether to have pulsing set or not.
|
|
556 |
*
|
|
557 |
* Sets the progress pulse hint hint for a window manager (like muffin)
|
|
558 |
* to make available when applications want to display indeterminate or
|
|
559 |
* ongoing progress in a task manager.
|
|
560 |
*
|
|
561 |
* Setting an explicit progress value will unset this flag.
|
|
562 |
*/
|
|
563 |
void
|
|
564 |
xapp_set_window_progress_pulse (GtkWindow *window,
|
|
565 |
gboolean pulse)
|
|
566 |
{
|
|
567 |
XAppGtkWindowPrivate *priv;
|
|
568 |
|
|
569 |
g_return_if_fail (GTK_IS_WINDOW (window));
|
|
570 |
|
|
571 |
priv = get_xapp_struct (window);
|
|
572 |
|
|
573 |
if (XAPP_IS_GTK_WINDOW (window))
|
|
574 |
{
|
|
575 |
g_warning("Window is an instance of XAppGtkWindow. Use the instance set_progress_pulse method instead.");
|
|
576 |
}
|
|
577 |
|
|
578 |
set_progress_pulse_internal (GTK_WINDOW (window), priv, pulse);
|
|
579 |
}
|