~canonical-dx-team/ubuntu/maverick/gtk+2.0/menuproxy

« back to all changes in this revision

Viewing changes to docs/faq/html/x482.html

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-05-04 12:24:25 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20070504122425-0m8midgzrp40y8w2
Tags: 2.10.12-1ubuntu1
* Sync with Debian
* New upstream version:
  Fixed bugs:
  - 379414 file chooser warnings when changing path in the entry
  - 418585 GtkFileChooserDefault sizing code is not DPI independent
  - 419568 Crash in search if start with special letter
  - 435062 build dies with icon cache validation
  - 379399 Segfault to call gtk_print_operation_run twice.
  - 387889 cups backend has problems when there are too many printers
  - 418531 invalid read to gtkicontheme.c gtk_icon_theme_lookup_icon...
  - 423916 crash in color scheme code
  - 424042 Segmentation fault while quickly pressing Alt+arrows
  - 415260 Protect against negative indices when setting values in G...
  - 419171 XGetVisualInfo() may not set nxvisuals
  - 128852 Gdk cursors don't look good on win32
  - 344657 Ctrl-H doesn't toggle "Show Hidden Files" setting
  - 345345 PrintOperation::paginate is not emitted for class handler
  - 347567 GtkPrintOperation::end-print is not emitted if it's cance...
  - 369112 gtk_ui_manager_add_ui should accept unnamed separator
  - 392015 Selected menu item invisible on Windows Vista
  - 399253 MS-Windows Theme Bottom Tab placement rendering glitches
  - 399425 gtk_input_dialog_fill_axes() adds child to gtkscrolledwin...
  - 403251 [patch] little memory leak in GtkPrintJob
  - 403267 [patch] memory leak in GtkPageSetupUnixDialog
  - 403470 MS-Windows Theme tab placement other than on top leaks a ...
  - 404506 Windows system fonts that have multi-byte font names cann...
  - 405089 Incorrect window placement for GtkEventBox private window
  - 405515 Minor leak in gtkfilesystemmodel.c
  - 405539 gdk_pixbuf_save() for PNG saver can return FALSE without ...
  - 415681 gdk_window_clear_area includes an extra line and column o...
  - 418219 GtkRecentChooser should apply filter before sorting and c...
  - 418403 Scroll to printer after selecting it from settings
  - 421985 _gtk_print_operation_platform_backend_launch_preview
  - 421990 gtk_print_job_get_surface
  - 421993 gtk_print_operation_init
  - 423064 Conditional jump or move depends on uninitialised value(s...
  - 423722 Fix printing header in gtk-demo
  - 424168 gtk_print_operation_run on async preview
  - 425655 Don't install gtk+-unix-print-2.0.pc on non-UNIX platforms
  - 425786 GDK segfaults if XineramaQueryScreens fails
  - 428665 Lpr Backend gets stuck in infinite loop during gtk_enumer...
  - 429902 GtkPrintOperation leaks cairo contextes
  - 431997 First delay of GdkPixbufAnimationIter is wrong
  - 433242 Inconsistent scroll arrow position calculations
  - 433972 Placing gtk.Expander inside a gtk.TextView() changes gtk....
  - 434261 _gtk_toolbar_elide_underscores incorrectly handles some s...
  - 383354 ctrl-L should make 'Location' entry disappear
  - 418673 gtk_recent_manager_add_item
  - 429732 gtk_accel_group_finalize accesses invalid memory
  - 435028 WM_CLIENT_LEADER is wrong on the leader_window
  - 431067 Background of the header window is not updated
  - 338843 add recent files support inside the ui manager
  - 148535 add drop shadow to menus, tooltips, etc. under Windows XP
* debian/control.in:
  - Conflicts on ubuntulooks (<= 0.9.11-1)
* debian/patches/15_default-fallback-icon-theme.patch:
  - patch from Debian, fallback on gnome icon theme

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
2
<HTML
 
3
><HEAD
 
4
><TITLE
 
5
>Is GTK+ thread safe? How do I write multi-threaded GTK+
 
6
applications? [GTK 2.x]</TITLE
 
7
><META
 
8
NAME="GENERATOR"
 
9
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
 
10
REL="HOME"
 
11
TITLE="GTK+ FAQ"
 
12
HREF="book1.html"><LINK
 
13
REL="UP"
 
14
TITLE="Development with GTK+: general questions"
 
15
HREF="c476.html"><LINK
 
16
REL="PREVIOUS"
 
17
TITLE="Development with GTK+: general questions"
 
18
HREF="c476.html"><LINK
 
19
REL="NEXT"
 
20
TITLE="I'm doing some stuff with GTK+ in a separate thread, and
 
21
properly locking with gdk_threads_enter/gdk_threads_leave()
 
22
but the display doesn't update properly. [GTK 2.x]"
 
23
HREF="x492.html"></HEAD
 
24
><BODY
 
25
CLASS="SECT1"
 
26
BGCOLOR="#FFFFFF"
 
27
TEXT="#000000"
 
28
LINK="#0000FF"
 
29
VLINK="#840084"
 
30
ALINK="#0000FF"
 
31
><DIV
 
32
CLASS="NAVHEADER"
 
33
><TABLE
 
34
SUMMARY="Header navigation table"
 
35
WIDTH="100%"
 
36
BORDER="0"
 
37
CELLPADDING="0"
 
38
CELLSPACING="0"
 
39
><TR
 
40
><TH
 
41
COLSPAN="3"
 
42
ALIGN="center"
 
43
>GTK+ FAQ</TH
 
44
></TR
 
45
><TR
 
46
><TD
 
47
WIDTH="10%"
 
48
ALIGN="left"
 
49
VALIGN="bottom"
 
50
><A
 
51
HREF="c476.html"
 
52
ACCESSKEY="P"
 
53
>&#60;&#60;&#60; Previous</A
 
54
></TD
 
55
><TD
 
56
WIDTH="80%"
 
57
ALIGN="center"
 
58
VALIGN="bottom"
 
59
>Development with GTK+: general questions</TD
 
60
><TD
 
61
WIDTH="10%"
 
62
ALIGN="right"
 
63
VALIGN="bottom"
 
64
><A
 
65
HREF="x492.html"
 
66
ACCESSKEY="N"
 
67
>Next &#62;&#62;&#62;</A
 
68
></TD
 
69
></TR
 
70
></TABLE
 
71
><HR
 
72
ALIGN="LEFT"
 
73
WIDTH="100%"></DIV
 
74
><DIV
 
75
CLASS="SECT1"
 
76
><H1
 
77
CLASS="SECT1"
 
78
><A
 
79
NAME="AEN482"
 
80
>Is GTK+ thread safe? How do I write multi-threaded GTK+
 
81
applications? <I
 
82
CLASS="EMPHASIS"
 
83
>[GTK 2.x]</I
 
84
></A
 
85
></H1
 
86
><P
 
87
>The GLib library can be used in a thread-safe mode by
 
88
calling g_thread_init() before making any other GLib
 
89
calls. In this mode GLib automatically locks all internal
 
90
data structures as needed.  This does not mean that two
 
91
threads can simultaneously access, for example, a single hash
 
92
table, but they can access two different hash tables
 
93
simultaneously. If two different threads need to access the
 
94
same hash table, the application is responsible for locking
 
95
itself.</P
 
96
><P
 
97
>In order to make GDK thread aware, you also need to
 
98
call gdk_threads_init() in conjunction with the above call.
 
99
There is a single global
 
100
lock that you must acquire with gdk_threads_enter() before
 
101
making any GDK calls, and release with gdk_threads_leave()
 
102
afterwards throughout your code.</P
 
103
><P
 
104
>A minimal main program for a threaded GTK+ application
 
105
looks like:</P
 
106
><TABLE
 
107
BORDER="0"
 
108
BGCOLOR="#E0E0E0"
 
109
WIDTH="100%"
 
110
><TR
 
111
><TD
 
112
><PRE
 
113
CLASS="PROGRAMLISTING"
 
114
>int
 
115
main (int argc, char *argv[])
 
116
{
 
117
  GtkWidget *window;
 
118
 
 
119
  /* init threads */    
 
120
  g_thread_init(NULL);
 
121
  gdk_threads_init();
 
122
  
 
123
  /* init gtk */
 
124
  gtk_init(&#38;argc, &#38;argv);
 
125
 
 
126
  window = create_window();
 
127
  gtk_widget_show(window);
 
128
 
 
129
  gdk_threads_enter();
 
130
  gtk_main();
 
131
  gdk_threads_leave();
 
132
 
 
133
  return 0;
 
134
}</PRE
 
135
></TD
 
136
></TR
 
137
></TABLE
 
138
><P
 
139
>Callbacks require a bit of attention. Callbacks from
 
140
GTK+ (signals) are made within the GTK+ lock. However
 
141
callbacks from GLib (timeouts, IO callbacks, and idle
 
142
functions) are made outside of the GTK+ lock. So, within a
 
143
signal handler you do not need to call gdk_threads_enter(),
 
144
but within the other types of callbacks, you do.</P
 
145
><P
 
146
>Erik Mouw contributed the following code example to
 
147
illustrate how to use threads within GTK+ programs.</P
 
148
><TABLE
 
149
BORDER="0"
 
150
BGCOLOR="#E0E0E0"
 
151
WIDTH="100%"
 
152
><TR
 
153
><TD
 
154
><PRE
 
155
CLASS="PROGRAMLISTING"
 
156
>/*-------------------------------------------------------------------------
 
157
 * Filename:      gtk-thread.c
 
158
 * Version:       1.99.1
 
159
 * Copyright:     Copyright (C) 1999, Erik Mouw
 
160
 * Author:        Erik Mouw &#60;J.A.K.Mouw@its.tudelft.nl&#62;
 
161
 * Description:   GTK threads example.
 
162
 * Created at:    Sun Oct 17 21:27:09 1999
 
163
 * Modified by:   Owen Taylor &#60;otaylor@gtk.org&#62;
 
164
 * Modified at:   Wed May 28 10:43:00 2003
 
165
 *-----------------------------------------------------------------------*/
 
166
/*
 
167
 * Compile with:
 
168
 *
 
169
 * cc -o gtk-thread gtk-thread.c `pkg-config --cflags --libs gtk+-2.0 gthread-2.0`
 
170
 *
 
171
 * Thanks to Sebastian Wilhelmi for pointing out some bugs in earlier versions.
 
172
 *
 
173
 */
 
174
 
 
175
#include &#60;unistd.h&#62;
 
176
#include &#60;gtk/gtk.h&#62;
 
177
 
 
178
#define YES_IT_IS    (1)
 
179
#define NO_IT_IS_NOT (0)
 
180
 
 
181
typedef struct
 
182
{
 
183
  GtkWidget *label;
 
184
  int what;
 
185
} yes_or_no_args;
 
186
 
 
187
G_LOCK_DEFINE_STATIC (yes_or_no);
 
188
static volatile int yes_or_no = YES_IT_IS;
 
189
 
 
190
void destroy(GtkWidget *widget, gpointer data)
 
191
{
 
192
  gtk_main_quit();
 
193
}
 
194
 
 
195
void *argument_thread(void *args)
 
196
{
 
197
  yes_or_no_args *data = (yes_or_no_args *)args;
 
198
  gboolean say_something;
 
199
 
 
200
  for(;;)
 
201
    {
 
202
      /* sleep a while */
 
203
      sleep(g_random_int_range (1, 4));
 
204
 
 
205
      /* lock the yes_or_no_variable */
 
206
      G_LOCK(yes_or_no);
 
207
 
 
208
      /* do we have to say something? */
 
209
      say_something = (yes_or_no != data-&#62;what);
 
210
 
 
211
      if(say_something)
 
212
        {
 
213
          /* set the variable */
 
214
          yes_or_no = data-&#62;what;
 
215
        }
 
216
 
 
217
      /* Unlock the yes_or_no variable */
 
218
      G_UNLOCK(yes_or_no);
 
219
 
 
220
      if(say_something)
 
221
        {
 
222
          /* get GTK thread lock */
 
223
          gdk_threads_enter();
 
224
 
 
225
          /* set label text */
 
226
          if(data-&#62;what == YES_IT_IS)
 
227
            gtk_label_set_text(GTK_LABEL(data-&#62;label), "O yes, it is!");
 
228
          else
 
229
            gtk_label_set_text(GTK_LABEL(data-&#62;label), "O no, it isn't!");
 
230
 
 
231
          /* Make sure all X commands are sent to the X server; not strictly
 
232
           * necessary here, but always a good idea when you do anything
 
233
           * from a thread other than the one where the main loop is running.
 
234
           */
 
235
          gdk_flush ();
 
236
 
 
237
          /* release GTK thread lock */
 
238
          gdk_threads_leave();
 
239
        }
 
240
    }
 
241
 
 
242
  return NULL;
 
243
}
 
244
 
 
245
int main(int argc, char *argv[])
 
246
{
 
247
  GtkWidget *window;
 
248
  GtkWidget *label;
 
249
  GError *error = NULL;
 
250
  yes_or_no_args yes_args, no_args;
 
251
 
 
252
  /* init threads */
 
253
  g_thread_init(NULL);
 
254
  gdk_threads_init();
 
255
 
 
256
  /* init gtk */
 
257
  gtk_init(&#38;argc, &#38;argv);
 
258
 
 
259
  /* create a window */
 
260
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 
261
 
 
262
  g_signal_connect(window, "destroy",
 
263
                   G_CALLBACK(destroy), NULL);
 
264
 
 
265
  gtk_container_set_border_width(GTK_CONTAINER (window), 10);
 
266
 
 
267
  /* create a label */
 
268
  label = gtk_label_new("And now for something completely different ...");
 
269
  gtk_container_add(GTK_CONTAINER(window), label);
 
270
 
 
271
  /* show everything */
 
272
  gtk_widget_show(label);
 
273
  gtk_widget_show (window);
 
274
 
 
275
  /* create the threads */
 
276
  yes_args.label = label;
 
277
  yes_args.what = YES_IT_IS;
 
278
  if (!g_thread_create(argument_thread, &#38;yes_args, FALSE, &#38;error))
 
279
    {
 
280
      g_printerr ("Failed to create YES thread: %s\n", error-&#62;message);
 
281
      return 1;
 
282
    }
 
283
 
 
284
  no_args.label = label;
 
285
  no_args.what = NO_IT_IS_NOT;
 
286
  if (!g_thread_create(argument_thread, &#38;no_args, FALSE, &#38;error))
 
287
    {
 
288
      g_printerr ("Failed to create NO thread: %s\n", error-&#62;message);
 
289
      return 1;
 
290
    }
 
291
 
 
292
  /* enter the GTK main loop */
 
293
  gdk_threads_enter();
 
294
  gtk_main();
 
295
  gdk_threads_leave();
 
296
 
 
297
  return 0;
 
298
}</PRE
 
299
></TD
 
300
></TR
 
301
></TABLE
 
302
></DIV
 
303
><DIV
 
304
CLASS="NAVFOOTER"
 
305
><HR
 
306
ALIGN="LEFT"
 
307
WIDTH="100%"><TABLE
 
308
SUMMARY="Footer navigation table"
 
309
WIDTH="100%"
 
310
BORDER="0"
 
311
CELLPADDING="0"
 
312
CELLSPACING="0"
 
313
><TR
 
314
><TD
 
315
WIDTH="33%"
 
316
ALIGN="left"
 
317
VALIGN="top"
 
318
><A
 
319
HREF="c476.html"
 
320
ACCESSKEY="P"
 
321
>&#60;&#60;&#60; Previous</A
 
322
></TD
 
323
><TD
 
324
WIDTH="34%"
 
325
ALIGN="center"
 
326
VALIGN="top"
 
327
><A
 
328
HREF="book1.html"
 
329
ACCESSKEY="H"
 
330
>Home</A
 
331
></TD
 
332
><TD
 
333
WIDTH="33%"
 
334
ALIGN="right"
 
335
VALIGN="top"
 
336
><A
 
337
HREF="x492.html"
 
338
ACCESSKEY="N"
 
339
>Next &#62;&#62;&#62;</A
 
340
></TD
 
341
></TR
 
342
><TR
 
343
><TD
 
344
WIDTH="33%"
 
345
ALIGN="left"
 
346
VALIGN="top"
 
347
>Development with GTK+: general questions</TD
 
348
><TD
 
349
WIDTH="34%"
 
350
ALIGN="center"
 
351
VALIGN="top"
 
352
><A
 
353
HREF="c476.html"
 
354
ACCESSKEY="U"
 
355
>Up</A
 
356
></TD
 
357
><TD
 
358
WIDTH="33%"
 
359
ALIGN="right"
 
360
VALIGN="top"
 
361
>I'm doing some stuff with GTK+ in a separate thread, and
 
362
properly locking with gdk_threads_enter/gdk_threads_leave()
 
363
but the display doesn't update properly. <I
 
364
CLASS="EMPHASIS"
 
365
>[GTK 2.x]</I
 
366
></TD
 
367
></TR
 
368
></TABLE
 
369
></DIV
 
370
></BODY
 
371
></HTML
 
372
>
 
 
b'\\ No newline at end of file'