diff options
author | Owen Taylor <otaylor@redhat.com> | 2002-08-01 15:28:40 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2002-08-01 15:28:40 +0000 |
commit | e5ae081ebea69057c9e9da5175869b87b0972ed0 (patch) | |
tree | e6be8246d4b84e8cfbe2c859de97683065211344 /gdk | |
parent | d202b55bc05460d36b759de33b93cfea0f9870c7 (diff) | |
download | gdk-pixbuf-e5ae081ebea69057c9e9da5175869b87b0972ed0.tar.gz |
Start implementing display/screen closing scheme; keep a flag for whether
Thu Aug 1 11:26:03 2002 Owen Taylor <otaylor@redhat.com>
* gdk/gdkdisplay.[ch] gdk/gdkscreen.[ch] gdkinternals.h:
Start implementing display/screen closing scheme; keep a
flag for whether displays and screens are closed,
call g_object_run_dispose(). Remove public gdk_screen_close().
* gdk/x11/gdkdisplay-x11.c gdk/x11/gdkscreen-x11.c: Add
dispose() methods; move appropriate parts of the finalize
there.
* gdk/x11/gdkcolor-x11.c gdk/x11/gdkimage-x11.c
gdk/x11/gdkmain-x11.c gdk/x11/gdkpango-x11.c
gdk/x11/gdkpixmap-x11.c gdk/x11/gdkproperty-x11.c
gdk/x11/gdkselection-x11.c gdk/x11/gdkwindow-x11.c:
Start of making everything correctly ignore operations
when a display has been closed.
* gdk/x11/gdkwindow-x11.c (gdk_window_get_decorations):
Handle decorations == NULL.
* gdk/x11/gdkcolor-x11.c (gdk_colormap_remove):
Remove unnecessary hash table creation.
* gdk/x11/gdkinput.c gdk/x11/gdkinput-x11.c gdk/win32/gdkinput.c
Fix up gdk_device_get_history - handle events, n_events == NULL,
etc.
* gdk/x11/gdkproperty-x11.c (gdk_property_get):
Handle failure better.
* gdk/x11/gdkselection-x11.c (gdk_selection_property_get):
Handle failure better, handle data == NULL, move docs
here, remove an excess round trip by asking for
all selection data at once.
* gdk/gdkselection.c gdk/win32/{x11,win32}/gdkselection-{x11,win32}.c
gdk/{x11,win32}/gdkmain-{x11,win32}.c gdk/gdkdisplay.c: Move
gdk_text_property_to_text_list(), gdk_string_to_compound_text(),
gdk_display_set_sm_client_id() to display-independent part of GDK.
* gdk/Makefile.am (gdk_c_sources): Sort gdkdisplay/screen.[ch]
into the right place.
Diffstat (limited to 'gdk')
-rw-r--r-- | gdk/Makefile.am | 8 | ||||
-rw-r--r-- | gdk/gdkdisplay.c | 42 | ||||
-rw-r--r-- | gdk/gdkdisplay.h | 3 | ||||
-rw-r--r-- | gdk/gdkinternals.h | 3 | ||||
-rw-r--r-- | gdk/gdkscreen.c | 18 | ||||
-rw-r--r-- | gdk/gdkscreen.h | 3 | ||||
-rw-r--r-- | gdk/gdkselection.c | 23 | ||||
-rw-r--r-- | gdk/win32/gdkinput.c | 6 | ||||
-rw-r--r-- | gdk/win32/gdkmain-win32.c | 2 | ||||
-rw-r--r-- | gdk/win32/gdkselection-win32.c | 20 | ||||
-rw-r--r-- | gdk/x11/gdkcolor-x11.c | 54 | ||||
-rw-r--r-- | gdk/x11/gdkcursor-x11.c | 16 | ||||
-rw-r--r-- | gdk/x11/gdkdisplay-x11.c | 26 | ||||
-rw-r--r-- | gdk/x11/gdkimage-x11.c | 80 | ||||
-rw-r--r-- | gdk/x11/gdkinput-x11.c | 7 | ||||
-rw-r--r-- | gdk/x11/gdkinput-xfree.c | 2 | ||||
-rw-r--r-- | gdk/x11/gdkinput.c | 56 | ||||
-rw-r--r-- | gdk/x11/gdkmain-x11.c | 30 | ||||
-rw-r--r-- | gdk/x11/gdkpango-x11.c | 3 | ||||
-rw-r--r-- | gdk/x11/gdkpixmap-x11.c | 24 | ||||
-rw-r--r-- | gdk/x11/gdkproperty-x11.c | 33 | ||||
-rw-r--r-- | gdk/x11/gdkscreen-x11.c | 28 | ||||
-rw-r--r-- | gdk/x11/gdkscreen-x11.h | 1 | ||||
-rw-r--r-- | gdk/x11/gdkselection-x11.c | 190 | ||||
-rw-r--r-- | gdk/x11/gdkwindow-x11.c | 16 |
25 files changed, 443 insertions, 251 deletions
diff --git a/gdk/Makefile.am b/gdk/Makefile.am index 8881a3124..62ae6275b 100644 --- a/gdk/Makefile.am +++ b/gdk/Makefile.am @@ -91,6 +91,7 @@ gdk_public_h_sources = @STRIP_BEGIN@ \ gdk.h \ gdkcolor.h \ gdkcursor.h \ + gdkdisplay.h \ gdkdnd.h \ gdkdrawable.h \ gdkevents.h \ @@ -108,12 +109,11 @@ gdk_public_h_sources = @STRIP_BEGIN@ \ gdkproperty.h \ gdkregion.h \ gdkrgb.h \ + gdkscreen.h \ gdkselection.h \ gdktypes.h \ gdkvisual.h \ gdkwindow.h \ - gdkdisplay.h \ - gdkscreen.h \ @STRIP_END@ gdk_headers = @STRIP_BEGIN@ \ @@ -126,6 +126,7 @@ gdk_c_sources = @STRIP_BEGIN@ \ gdk.c \ gdkcolor.c \ gdkcursor.c \ + gdkdisplay.c \ gdkdraw.c \ gdkevents.c \ gdkfont.c \ @@ -147,11 +148,10 @@ gdk_c_sources = @STRIP_BEGIN@ \ gdkrectangle.c \ gdkregion-generic.c \ gdkregion-generic.h \ + gdkscreen.c \ gdkselection.c \ gdkvisual.c \ gdkwindow.c \ - gdkdisplay.c \ - gdkscreen.c \ @STRIP_END@ # diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c index 2351d1d54..05c929389 100644 --- a/gdk/gdkdisplay.c +++ b/gdk/gdkdisplay.c @@ -29,6 +29,7 @@ static void gdk_display_class_init (GdkDisplayClass *class); static void gdk_display_init (GdkDisplay *display); +static void gdk_display_dispose (GObject *object); static void gdk_display_finalize (GObject *object); static GObjectClass *parent_class; @@ -67,6 +68,7 @@ gdk_display_class_init (GdkDisplayClass *class) parent_class = g_type_class_peek_parent (class); object_class->finalize = gdk_display_finalize; + object_class->dispose = gdk_display_dispose; } static void @@ -82,6 +84,12 @@ gdk_display_init (GdkDisplay *display) } static void +gdk_display_dispose (GObject *object) +{ + GdkDisplay *display = GDK_DISPLAY_OBJECT (object); +} + +static void gdk_display_finalize (GObject *object) { GdkDisplay *display = GDK_DISPLAY_OBJECT (object); @@ -99,13 +107,22 @@ gdk_display_finalize (GObject *object) * gdk_display_close: * @display: a #GdkDisplay * - * Closes and cleanup the resources used by the @display + * Closes the connection windowing system for the given display, + * and cleans up associated resources. */ void gdk_display_close (GdkDisplay *display) { g_return_if_fail (GDK_IS_DISPLAY (display)); - g_object_unref (G_OBJECT (display)); + + if (!display->closed) + { + display->closed = TRUE; + + g_object_run_dispose (G_OBJECT (display)); + + g_object_unref (G_OBJECT (display)); + } } /** @@ -294,3 +311,24 @@ gdk_display_get_core_pointer (GdkDisplay *display) { return display->core_pointer; } + +/** + * gdk_set_sm_client_id: + * @sm_client_id: the client id assigned by the session manager when the + * connection was opened, or %NULL to remove the property. + * + * Sets the <literal>SM_CLIENT_ID</literal> property on the application's leader window so that + * the window manager can save the application's state using the X11R6 ICCCM + * session management protocol. + * + * See the X Session Management Library documentation for more information on + * session management and the Inter-Client Communication Conventions Manual + * (ICCCM) for information on the <literal>WM_CLIENT_LEADER</literal> property. + * (Both documents are part of the X Window System distribution.) + **/ +void +gdk_set_sm_client_id (const gchar* sm_client_id) +{ + gdk_display_set_sm_client_id (gdk_display_get_default (), sm_client_id); +} + diff --git a/gdk/gdkdisplay.h b/gdk/gdkdisplay.h index 61419932d..25ed1e301 100644 --- a/gdk/gdkdisplay.h +++ b/gdk/gdkdisplay.h @@ -55,9 +55,10 @@ struct _GdkDisplay GdkWindow *button_window[2]; /* The last 2 windows to receive button presses. */ guint button_number[2]; /* The last 2 buttons to be pressed. */ + guint double_click_time; /* Maximum time between clicks in msecs */ GdkDevice *core_pointer; /* Core pointer device */ - guint double_click_time; /* Maximum time between clicks in msecs */ + guint closed : 1; /* Whether this display has been closed */ }; struct _GdkDisplayClass diff --git a/gdk/gdkinternals.h b/gdk/gdkinternals.h index c31dc1615..632c13096 100644 --- a/gdk/gdkinternals.h +++ b/gdk/gdkinternals.h @@ -216,7 +216,8 @@ GdkImage *_gdk_drawable_copy_to_image (GdkDrawable *drawable, void _gdk_window_destroy (GdkWindow *window, gboolean foreign_destroy); void _gdk_window_clear_update_area (GdkWindow *window); - + +void _gdk_screen_close (GdkScreen *screen); /***************************************** * Interfaces provided by windowing code * diff --git a/gdk/gdkscreen.c b/gdk/gdkscreen.c index c28855e2c..e822d6466 100644 --- a/gdk/gdkscreen.c +++ b/gdk/gdkscreen.c @@ -54,20 +54,16 @@ gdk_screen_get_type (void) return object_type; } - -/** - * gdk_screen_close: - * @screen: a #GdkScreen - * - * Closes the @screen connection and cleanup its resources. - * Note that this function is called automatically by gdk_display_close(). - **/ void -gdk_screen_close (GdkScreen *screen) +_gdk_screen_close (GdkScreen *screen) { g_return_if_fail (GDK_IS_SCREEN (screen)); - - g_object_run_dispose (G_OBJECT (screen)); + + if (!screen->closed) + { + screen->closed = TRUE; + g_object_run_dispose (G_OBJECT (screen)); + } } /** diff --git a/gdk/gdkscreen.h b/gdk/gdkscreen.h index d4d26dd91..6ca97bfc4 100644 --- a/gdk/gdkscreen.h +++ b/gdk/gdkscreen.h @@ -41,6 +41,8 @@ typedef struct _GdkScreenClass GdkScreenClass; struct _GdkScreen { GObject parent_instance; + + guint closed : 1; }; struct _GdkScreenClass @@ -67,7 +69,6 @@ gint gdk_screen_get_width (GdkScreen *screen); gint gdk_screen_get_height (GdkScreen *screen); gint gdk_screen_get_width_mm (GdkScreen *screen); gint gdk_screen_get_height_mm (GdkScreen *screen); -void gdk_screen_close (GdkScreen *screen); GList * gdk_screen_list_visuals (GdkScreen *screen); GList * gdk_screen_get_toplevel_windows (GdkScreen *screen); diff --git a/gdk/gdkselection.c b/gdk/gdkselection.c index df501957f..4aecef886 100644 --- a/gdk/gdkselection.c +++ b/gdk/gdkselection.c @@ -32,6 +32,17 @@ gdk_selection_send_notify (guint32 requestor, target, property, time); } +gint +gdk_text_property_to_text_list (GdkAtom encoding, + gint format, + const guchar *text, + gint length, + gchar ***list) +{ + return gdk_text_property_to_text_list_for_display (gdk_display_get_default (), + encoding, format, text, length, list); +} + /** * gdk_text_property_to_utf8_list: * @encoding: an atom representing the encoding of the text @@ -58,6 +69,18 @@ gdk_text_property_to_utf8_list (GdkAtom encoding, encoding, format, text, length, list); } +gint +gdk_string_to_compound_text (const gchar *str, + GdkAtom *encoding, + gint *format, + guchar **ctext, + gint *length) +{ + return gdk_string_to_compound_text_for_display (gdk_display_get_default (), + str, encoding, format, + ctext, length); +} + /** * gdk_utf8_to_compound_text: * @str: a UTF-8 string diff --git a/gdk/win32/gdkinput.c b/gdk/win32/gdkinput.c index 767ed2b9f..21bc7f2ee 100644 --- a/gdk/win32/gdkinput.c +++ b/gdk/win32/gdkinput.c @@ -184,8 +184,10 @@ gdk_device_get_history (GdkDevice *device, g_return_val_if_fail (events != NULL, FALSE); g_return_val_if_fail (n_events != NULL, FALSE); - *n_events = 0; - *events = NULL; + if (n_events) + *n_events = 0; + if (events) + *events = NULL; if (GDK_WINDOW_DESTROYED (window)) return FALSE; diff --git a/gdk/win32/gdkmain-win32.c b/gdk/win32/gdkmain-win32.c index a762cee78..40926eddc 100644 --- a/gdk/win32/gdkmain-win32.c +++ b/gdk/win32/gdkmain-win32.c @@ -181,7 +181,7 @@ gdk_screen_get_height_mm (GdkScreen *screen) } void -gdk_set_sm_client_id (const gchar* sm_client_id) +gdk_display_set_sm_client_id (const gchar* sm_client_id) { g_warning("gdk_set_sm_client_id %s", sm_client_id ? sm_client_id : "NULL"); } diff --git a/gdk/win32/gdkselection-win32.c b/gdk/win32/gdkselection-win32.c index d6b9d82ee..fcbd5cb59 100644 --- a/gdk/win32/gdkselection-win32.c +++ b/gdk/win32/gdkselection-win32.c @@ -560,11 +560,11 @@ gdk_selection_send_notify_for_display (GdkDisplay *display, /* Simplistic implementations of text list and compound text functions */ gint -gdk_text_property_to_text_list (GdkAtom encoding, - gint format, - const guchar *text, - gint length, - gchar ***list) +gdk_text_property_to_text_list_for_display (GdkAtom encoding, + gint format, + const guchar *text, + gint length, + gchar ***list) { gchar *enc_name; @@ -592,11 +592,11 @@ gdk_free_text_list (gchar **list) } gint -gdk_string_to_compound_text (const gchar *str, - GdkAtom *encoding, - gint *format, - guchar **ctext, - gint *length) +gdk_string_to_compound_text_for_display (const gchar *str, + GdkAtom *encoding, + gint *format, + guchar **ctext, + gint *length) { GDK_NOTE (DND, g_print ("gdk_string_to_compound_text: %.20s\n", str)); diff --git a/gdk/x11/gdkcolor-x11.c b/gdk/x11/gdkcolor-x11.c index 93f392937..40be6ef6c 100644 --- a/gdk/x11/gdkcolor-x11.c +++ b/gdk/x11/gdkcolor-x11.c @@ -131,7 +131,8 @@ gdk_colormap_finalize (GObject *object) gdk_colormap_remove (colormap); - XFreeColormap (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap); + if (!private->screen->closed) + XFreeColormap (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap); if (private->hash) g_hash_table_destroy (private->hash); @@ -278,7 +279,7 @@ gdk_colormap_sync_palette (GdkColormap *colormap) nlookup++; } } - + XQueryColors (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap, xpalette, nlookup); @@ -334,9 +335,12 @@ gdk_colormap_sync (GdkColormap *colormap, { time_t current_time; GdkColormapPrivateX11 *private = GDK_COLORMAP_PRIVATE_DATA (colormap); - + g_return_if_fail (GDK_IS_COLORMAP (colormap)); + if (private->screen->closed) + return; + current_time = time (NULL); if (!force && ((current_time - private->last_sync_time) < MIN_SYNC_TIME)) return; @@ -434,6 +438,9 @@ gdk_colormap_change (GdkColormap *colormap, private = GDK_COLORMAP_PRIVATE_DATA (colormap); + if (private->screen->closed) + return; + xdisplay = GDK_SCREEN_XDISPLAY (private->screen); palette = g_new (XColor, ncolors); @@ -519,6 +526,9 @@ gdk_colors_alloc (GdkColormap *colormap, private = GDK_COLORMAP_PRIVATE_DATA (colormap); + if (private->screen->closed) + return FALSE; + return_val = XAllocColorCells (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap,contiguous, planes, nplanes, pixels, npixels); @@ -577,7 +587,7 @@ gdk_colors_free (GdkColormap *colormap, } } - if (npixels) + if (npixels && !private->screen->closed) XFreeColors (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap, pixels, npixels, planes); g_free (pixels); @@ -625,7 +635,7 @@ gdk_colormap_free_colors (GdkColormap *colormap, } } - if (npixels) + if (npixels && !private->screen->closed) XFreeColors (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap, pixels, npixels, 0); @@ -979,11 +989,14 @@ gdk_colormap_alloc_colors (GdkColormap *colormap, gint nremaining = 0; XColor xcolor; - g_return_val_if_fail (GDK_IS_COLORMAP (colormap), FALSE); - g_return_val_if_fail (colors != NULL, FALSE); + g_return_val_if_fail (GDK_IS_COLORMAP (colormap), ncolors); + g_return_val_if_fail (colors != NULL, ncolors); private = GDK_COLORMAP_PRIVATE_DATA (colormap); + if (private->screen->closed) + return ncolors; + for (i=0; i<ncolors; i++) { success[i] = FALSE; @@ -1051,7 +1064,7 @@ gdk_colormap_alloc_colors (GdkColormap *colormap, * #GdkImage contains image data in hardware format, a #GdkPixbuf * contains image data in a canonical 24-bit RGB format.) * - * This function is rarely useful, it's used for example to + * This function is rarely useful; it's used for example to * implement the eyedropper feature in #GtkColorSelection. * **/ @@ -1083,10 +1096,15 @@ gdk_colormap_query_color (GdkColormap *colormap, break; case GDK_VISUAL_STATIC_COLOR: xcolor.pixel = pixel; - XQueryColor (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap, &xcolor); - result->red = xcolor.red; - result->green = xcolor.green; - result->blue = xcolor.blue; + if (!private->screen->closed) + { + XQueryColor (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap, &xcolor); + result->red = xcolor.red; + result->green = xcolor.green; + result->blue = xcolor.blue; + } + else + result->red = result->green = result->blue = 0; break; case GDK_VISUAL_PSEUDO_COLOR: g_return_if_fail (pixel < colormap->size); @@ -1117,7 +1135,8 @@ gdk_color_change (GdkColormap *colormap, xcolor.flags = DoRed | DoGreen | DoBlue; private = GDK_COLORMAP_PRIVATE_DATA (colormap); - XStoreColor (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap, &xcolor); + if (!private->screen->closed) + XStoreColor (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap, &xcolor); return TRUE; } @@ -1252,10 +1271,6 @@ gdk_colormap_remove (GdkColormap *cmap) { GdkColormapPrivateX11 *private; - if (!colormap_hash) - colormap_hash = g_hash_table_new ((GHashFunc) gdk_colormap_hash, - (GEqualFunc) gdk_colormap_equal); - private = GDK_COLORMAP_PRIVATE_DATA (cmap); g_hash_table_remove (colormap_hash, &private->xcolormap); @@ -1295,7 +1310,10 @@ gdk_x11_colormap_get_xcolormap (GdkColormap *colormap) private = GDK_COLORMAP_PRIVATE_DATA (colormap); - return private->xcolormap; + if (private->screen->closed) + return None; + else + return private->xcolormap; } /** diff --git a/gdk/x11/gdkcursor-x11.c b/gdk/x11/gdkcursor-x11.c index 813b9acec..f7ce4bf86 100644 --- a/gdk/x11/gdkcursor-x11.c +++ b/gdk/x11/gdkcursor-x11.c @@ -109,7 +109,11 @@ gdk_cursor_new_for_display (GdkDisplay *display, g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL); - xcursor = XCreateFontCursor (GDK_DISPLAY_XDISPLAY (display), cursor_type); + if (display->closed) + xcursor = None; + else + xcursor = XCreateFontCursor (GDK_DISPLAY_XDISPLAY (display), cursor_type); + private = g_new (GdkCursorPrivate, 1); private->display = display; private->xcursor = xcursor; @@ -153,8 +157,11 @@ gdk_cursor_new_from_pixmap (GdkPixmap *source, xbg.blue = bg->blue; xbg.green = bg->green; - xcursor = XCreatePixmapCursor (GDK_DISPLAY_XDISPLAY (display), - source_pixmap, mask_pixmap, &xfg, &xbg, x, y); + if (display->closed) + xcursor = None; + else + xcursor = XCreatePixmapCursor (GDK_DISPLAY_XDISPLAY (display), + source_pixmap, mask_pixmap, &xfg, &xbg, x, y); private = g_new (GdkCursorPrivate, 1); private->display = display; private->xcursor = xcursor; @@ -174,7 +181,8 @@ _gdk_cursor_destroy (GdkCursor *cursor) g_return_if_fail (cursor->ref_count == 0); private = (GdkCursorPrivate *) cursor; - XFreeCursor (GDK_DISPLAY_XDISPLAY (private->display), private->xcursor); + if (!private->display->closed && private->xcursor) + XFreeCursor (GDK_DISPLAY_XDISPLAY (private->display), private->xcursor); g_free (private); } diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c index 6fa8803c5..28cea282b 100644 --- a/gdk/x11/gdkdisplay-x11.c +++ b/gdk/x11/gdkdisplay-x11.c @@ -42,6 +42,7 @@ #endif static void gdk_display_x11_class_init (GdkDisplayX11Class *class); +static void gdk_display_x11_dispose (GObject *object); static void gdk_display_x11_finalize (GObject *object); static void gdk_internal_connection_watch (Display *display, @@ -83,7 +84,10 @@ _gdk_display_x11_get_type (void) static void gdk_display_x11_class_init (GdkDisplayX11Class * class) { - G_OBJECT_CLASS (class)->finalize = gdk_display_x11_finalize; + GObjectClass *object_class = G_OBJECT_CLASS (class); + + object_class->dispose = gdk_display_x11_dispose; + object_class->finalize = gdk_display_x11_finalize; parent_class = g_type_class_peek_parent (class); } @@ -479,6 +483,23 @@ gdk_x11_display_ungrab (GdkDisplay * display) } static void +gdk_display_x11_dispose (GObject *object) +{ + GdkDisplayX11 *display_x11; + gint i; + + display_x11 = GDK_DISPLAY_X11 (object);; + + for (i = 0; i < ScreenCount (display_x11->xdisplay); i++) + _gdk_screen_close (display_x11->screens[i]); + + XCloseDisplay (display_x11->xdisplay); + display_x11->xdisplay = NULL; + + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void gdk_display_x11_finalize (GObject *object) { GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (object); @@ -517,7 +538,6 @@ gdk_display_x11_finalize (GObject *object) for (i = 0; i < ScreenCount (display_x11->xdisplay); i++) g_object_unref (G_OBJECT (display_x11->screens[i])); g_free (display_x11->screens); - XCloseDisplay (display_x11->xdisplay); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -582,5 +602,3 @@ gdk_x11_display_get_xdisplay (GdkDisplay *display) { return GDK_DISPLAY_X11 (display)->xdisplay; } - - diff --git a/gdk/x11/gdkimage-x11.c b/gdk/x11/gdkimage-x11.c index 7836c06bd..6bbff5fc3 100644 --- a/gdk/x11/gdkimage-x11.c +++ b/gdk/x11/gdkimage-x11.c @@ -142,28 +142,49 @@ _gdk_image_exit (void) } } +/** + * gdk_image_new_bitmap: + * @visual: the #GdkVisual to use for the image. + * @data: the pixel data. + * @w: the width of the image in pixels. + * @h: the height of the image in pixels. + * + * Creates a new #GdkImage with a depth of 1 from the given data. + * <warning><para>THIS FUNCTION IS INCREDIBLY BROKEN. The passed-in data must + * be allocated by malloc() (NOT g_malloc()) and will be freed when the + * image is freed.</para></warning> + * + * Return value: a new #GdkImage. + **/ GdkImage * gdk_image_new_bitmap(GdkVisual *visual, gpointer data, gint w, gint h) -/* - * Desc: create a new bitmap image - */ { Visual *xvisual; GdkImage *image; + GdkDisplay *display; GdkImagePrivateX11 *private; + image = g_object_new (gdk_image_get_type (), NULL); private = PRIVATE_DATA (image); private->screen = gdk_visual_get_screen (visual); + display = GDK_SCREEN_DISPLAY (private->screen); + image->type = GDK_IMAGE_NORMAL; image->visual = visual; image->width = w; image->height = h; image->depth = 1; image->bits_per_pixel = 1; - xvisual = ((GdkVisualPrivate*) visual)->xvisual; - private->ximage = XCreateImage (GDK_SCREEN_XDISPLAY (private->screen), - xvisual, 1, XYBitmap, - 0, 0, w ,h, 8, 0); + if (display->closed) + private->ximage = NULL; + else + { + xvisual = ((GdkVisualPrivate*) visual)->xvisual; + private->ximage = XCreateImage (GDK_SCREEN_XDISPLAY (private->screen), + xvisual, 1, XYBitmap, + 0, 0, w ,h, 8, 0); + } + private->ximage->data = data; private->ximage->bitmap_bit_order = MSBFirst; private->ximage->byte_order = MSBFirst; @@ -174,14 +195,14 @@ gdk_image_new_bitmap(GdkVisual *visual, gpointer data, gint w, gint h) return(image); } /* gdk_image_new_bitmap() */ -static int -gdk_image_check_xshm(Display *display) /* * Desc: query the server for support for the MIT_SHM extension * Return: 0 = not available * 1 = shared XImage support available * 2 = shared Pixmap support available also */ +static int +gdk_image_check_xshm(Display *display) { #ifdef USE_SHM int major, minor, ignore; @@ -410,6 +431,9 @@ _gdk_x11_image_get_shm_pixmap (GdkImage *image) GdkImagePrivateX11 *private = PRIVATE_DATA (image); GdkDisplay *display = GDK_SCREEN_DISPLAY (private->screen); + if (display->closed) + return None; + #ifdef USE_SHM /* Future: do we need one of these per-screen per-image? ShmPixmaps * are the same for every screen, but can they be shared? Not a concern @@ -500,7 +524,9 @@ _gdk_x11_copy_to_image (GdkDrawable *drawable, impl = GDK_DRAWABLE_IMPL_X11 (drawable); display = gdk_drawable_get_display (drawable); xdisplay = gdk_x11_display_get_xdisplay (display); - + + if (display->closed) + return NULL; have_grab = FALSE; @@ -674,7 +700,10 @@ gdk_image_get_pixel (GdkImage *image, private = PRIVATE_DATA (image); - pixel = XGetPixel (private->ximage, x, y); + if (!private->screen->closed) + pixel = XGetPixel (private->ximage, x, y); + else + pixel = 0; return pixel; } @@ -691,7 +720,8 @@ gdk_image_put_pixel (GdkImage *image, private = PRIVATE_DATA (image); - pixel = XPutPixel (private->ximage, x, y, pixel); + if (!private->screen->closed) + pixel = XPutPixel (private->ximage, x, y, pixel); } static void @@ -717,20 +747,25 @@ gdk_x11_image_destroy (GdkImage *image) switch (image->type) { case GDK_IMAGE_NORMAL: - XDestroyImage (private->ximage); + if (!private->screen->closed) + XDestroyImage (private->ximage); break; case GDK_IMAGE_SHARED: #ifdef USE_SHM - gdk_display_sync (GDK_SCREEN_DISPLAY (private->screen)); + if (!private->screen->closed) + { + gdk_display_sync (GDK_SCREEN_DISPLAY (private->screen)); - if (private->shm_pixmap) - XFreePixmap (GDK_SCREEN_XDISPLAY (private->screen), private->shm_pixmap); + if (private->shm_pixmap) + XFreePixmap (GDK_SCREEN_XDISPLAY (private->screen), private->shm_pixmap); - image_list = g_list_remove (image_list, image); - XShmDetach (GDK_SCREEN_XDISPLAY (private->screen), private->x_shm_info); - XDestroyImage (private->ximage); + XShmDetach (GDK_SCREEN_XDISPLAY (private->screen), private->x_shm_info); + XDestroyImage (private->ximage); + } + image_list = g_list_remove (image_list, image); + x_shm_info = private->x_shm_info; shmdt (x_shm_info->shmaddr); @@ -772,7 +807,10 @@ gdk_x11_image_get_ximage (GdkImage *image) private = PRIVATE_DATA (image); - return private->ximage; + if (private->screen->closed) + return NULL; + else + return private->ximage; } gint @@ -781,7 +819,7 @@ _gdk_windowing_get_bits_for_depth (GdkDisplay *display, { XPixmapFormatValues *formats; gint count, i; - + formats = XListPixmapFormats (GDK_DISPLAY_XDISPLAY (display), &count); for (i = 0; i < count; i++) diff --git a/gdk/x11/gdkinput-x11.c b/gdk/x11/gdkinput-x11.c index b54ff9d57..13ffb8edb 100644 --- a/gdk/x11/gdkinput-x11.c +++ b/gdk/x11/gdkinput-x11.c @@ -720,12 +720,7 @@ _gdk_device_get_history (GdkDevice *device, return TRUE; } else - { - *events = NULL; - *n_events = 0; - - return FALSE; - } + return FALSE; } void diff --git a/gdk/x11/gdkinput-xfree.c b/gdk/x11/gdkinput-xfree.c index 499222678..a4af774cb 100644 --- a/gdk/x11/gdkinput-xfree.c +++ b/gdk/x11/gdkinput-xfree.c @@ -34,7 +34,7 @@ static void gdk_input_check_proximity (GdkDisplay *display); void _gdk_input_init(GdkDisplay *display) { - _gdk_init_input_core (); + _gdk_init_input_core (display); GDK_DISPLAY_X11 (display)->input_ignore_core = FALSE; gdk_input_common_init (display, FALSE); } diff --git a/gdk/x11/gdkinput.c b/gdk/x11/gdkinput.c index 24c99fe03..79edd0612 100644 --- a/gdk/x11/gdkinput.c +++ b/gdk/x11/gdkinput.c @@ -171,6 +171,25 @@ gdk_device_set_axis_use (GdkDevice *device, } } +/** + * gdk_device_get_history: + * @device: a #GdkDevice + * @window: the window with respect to which which the event coordinates will be reported + * @start: starting timestamp for range of events to return + * @stop: ending timestamp for the range of events to return + * @events: location to store a newly-allocated array of #GdkTimeCoord, or %NULL + * @n_events: location to store the length of @events, or %NULL + * + * Obtains the motion history for a device; given a starting and + * ending timestamp, return all events in the motion history for + * the device in the given range of time. Some windowing systems + * do not support motion history, in which case, %FALSE will + * be returned. (This is not distinguishable from the case where + * motion history is supported and no events were found.) + * + * Return value: %TRUE if the windowing system supports motion history and + * at least one event was found. + **/ gboolean gdk_device_get_history (GdkDevice *device, GdkWindow *window, @@ -179,31 +198,26 @@ gdk_device_get_history (GdkDevice *device, GdkTimeCoord ***events, gint *n_events) { - GdkTimeCoord **coords; + GdkTimeCoord **coords = NULL; + gboolean result = FALSE; + int tmp_n_events = 0; int i; - g_return_val_if_fail (window != NULL, FALSE); g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE); - g_return_val_if_fail (events != NULL, FALSE); - g_return_val_if_fail (n_events != NULL, FALSE); - - *n_events = 0; - *events = NULL; if (GDK_WINDOW_DESTROYED (window)) - return FALSE; - - if (GDK_IS_CORE (device)) + /* Nothing */ ; + else if (GDK_IS_CORE (device)) { XTimeCoord *xcoords; xcoords = XGetMotionEvents (GDK_DRAWABLE_XDISPLAY (window), GDK_DRAWABLE_XID (window), - start, stop, n_events); + start, stop, &tmp_n_events); if (xcoords) { - coords = _gdk_device_allocate_history (device, *n_events); - for (i=0; i<*n_events; i++) + coords = _gdk_device_allocate_history (device, tmp_n_events); + for (i=0; i<tmp_n_events; i++) { coords[i]->time = xcoords[i].time; coords[i]->axes[0] = xcoords[i].x; @@ -212,14 +226,22 @@ gdk_device_get_history (GdkDevice *device, XFree (xcoords); - *events = coords; - return TRUE; + result = TRUE; } else - return FALSE; + result = FALSE; } else - return _gdk_device_get_history (device, window, start, stop, events, n_events); + result = _gdk_device_get_history (device, window, start, stop, &coords, &tmp_n_events); + + if (n_events) + *n_events = tmp_n_events; + if (events) + *events = coords; + else if (coords) + gdk_device_free_history (coords, tmp_n_events); + + return result; } GdkTimeCoord ** diff --git a/gdk/x11/gdkmain-x11.c b/gdk/x11/gdkmain-x11.c index 36b1d2be2..e38490c8f 100644 --- a/gdk/x11/gdkmain-x11.c +++ b/gdk/x11/gdkmain-x11.c @@ -450,26 +450,6 @@ _gdk_xgrab_check_destroy (GdkWindow *window) } /** - * gdk_set_sm_client_id: - * @sm_client_id: the client id assigned by the session manager when the - * connection was opened, or %NULL to remove the property. - * - * Sets the <literal>SM_CLIENT_ID</literal> property on the application's leader window so that - * the window manager can save the application's state using the X11R6 ICCCM - * session management protocol. - * - * See the X Session Management Library documentation for more information on - * session management and the Inter-Client Communication Conventions Manual - * (ICCCM) for information on the <literal>WM_CLIENT_LEADER</literal> property. - * (Both documents are part of the X Window System distribution.) - **/ -void -gdk_set_sm_client_id (const gchar* sm_client_id) -{ - gdk_display_set_sm_client_id (gdk_display_get_default (),sm_client_id); -} - -/** * gdk_display_set_sm_client_id: * @display: a #GdkDisplay * @sm_client_id: the client id assigned by the session manager when the @@ -490,6 +470,9 @@ gdk_display_set_sm_client_id (GdkDisplay *display, { GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display); + if (display->closed) + return; + if (sm_client_id && strcmp (sm_client_id, "")) { XChangeProperty (display_x11->xdisplay, display_x11->leader_window, @@ -738,6 +721,9 @@ _gdk_send_xevent (GdkDisplay *display, { gboolean result; + if (display->closed) + return FALSE; + gdk_error_trap_push (); result = XSendEvent (GDK_DISPLAY_XDISPLAY (display), window, propagate, event_mask, event_send); @@ -787,8 +773,8 @@ gdk_x11_ungrab_server () * Gets the default GTK+ screen number. * * Return value: returns the screen number specified by - * the --display command line option on the DISPLAY environment - * variable gdk_init() calls XOpenDisplay(). + * the --display command line option or the DISPLAY environment + * variable when gdk_init() calls XOpenDisplay(). **/ gint gdk_x11_get_default_screen (void) diff --git a/gdk/x11/gdkpango-x11.c b/gdk/x11/gdkpango-x11.c index 6432e99fc..bcc43e08d 100644 --- a/gdk/x11/gdkpango-x11.c +++ b/gdk/x11/gdkpango-x11.c @@ -49,6 +49,9 @@ gdk_pango_context_get_for_screen (GdkScreen *screen) GdkDisplayX11 *display_x11; g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); + + if (screen->closed) + return NULL; display_x11 = GDK_DISPLAY_X11 (GDK_SCREEN_DISPLAY (screen)); diff --git a/gdk/x11/gdkpixmap-x11.c b/gdk/x11/gdkpixmap-x11.c index f5f1de7c6..7d9c5a016 100644 --- a/gdk/x11/gdkpixmap-x11.c +++ b/gdk/x11/gdkpixmap-x11.c @@ -125,20 +125,24 @@ gdk_pixmap_impl_x11_finalize (GObject *object) { GdkPixmapImplX11 *impl = GDK_PIXMAP_IMPL_X11 (object); GdkPixmap *wrapper = GDK_PIXMAP (GDK_DRAWABLE_IMPL_X11 (impl)->wrapper); + GdkDisplay *display = GDK_PIXMAP_DISPLAY (wrapper); + if (!display->closed) + { #ifdef HAVE_XFT - { - GdkDrawableImplX11 *draw_impl = GDK_DRAWABLE_IMPL_X11 (impl); - - if (draw_impl->picture) - XRenderFreePicture (GDK_PIXMAP_XDISPLAY (wrapper), draw_impl->picture); - } + { + GdkDrawableImplX11 *draw_impl = GDK_DRAWABLE_IMPL_X11 (impl); + + if (draw_impl->picture) + XRenderFreePicture (GDK_DISPLAY_XDISPLAY (display), draw_impl->picture); + } #endif /* HAVE_XFT */ - if (!impl->is_foreign) - XFreePixmap (GDK_PIXMAP_XDISPLAY (wrapper), GDK_PIXMAP_XID (wrapper)); - - _gdk_xid_table_remove (GDK_PIXMAP_DISPLAY (wrapper), GDK_PIXMAP_XID (wrapper)); + if (!impl->is_foreign) + XFreePixmap (GDK_DISPLAY_XDISPLAY (display), GDK_PIXMAP_XID (wrapper)); + } + + _gdk_xid_table_remove (display, GDK_PIXMAP_XID (wrapper)); G_OBJECT_CLASS (parent_class)->finalize (object); } diff --git a/gdk/x11/gdkproperty-x11.c b/gdk/x11/gdkproperty-x11.c index 2ddde8c64..162d16b55 100644 --- a/gdk/x11/gdkproperty-x11.c +++ b/gdk/x11/gdkproperty-x11.c @@ -111,7 +111,7 @@ static gchar *XAtomsStrings[] = { "CAP_HEIGHT", "WM_CLASS", "WM_TRANSIENT_FOR", - /* Below here, these our our additions. Increment N_CUSTOM_PREDEFINED + /* Below here, these are our additions. Increment N_CUSTOM_PREDEFINED * if you add any. */ "CLIPBOARD" /* = 69 */ @@ -160,6 +160,9 @@ gdk_x11_atom_to_xatom_for_display (GdkDisplay *display, Atom xatom = None; g_return_val_if_fail (GDK_IS_DISPLAY (display), None); + + if (display->closed) + return None; display_x11 = GDK_DISPLAY_X11 (display); @@ -216,7 +219,10 @@ gdk_x11_xatom_to_atom_for_display (GdkDisplay *display, GdkDisplayX11 *display_x11; GdkAtom virtual_atom = GDK_NONE; - g_return_val_if_fail (GDK_IS_DISPLAY (display), virtual_atom); + g_return_val_if_fail (GDK_IS_DISPLAY (display), GDK_NONE); + + if (display->closed) + return GDK_NONE; display_x11 = GDK_DISPLAY_X11 (display); @@ -425,6 +431,7 @@ gdk_property_get (GdkWindow *window, guchar *ret_data; Atom xproperty; Atom xtype; + int res; g_return_val_if_fail (!window || GDK_IS_WINDOW (window), FALSE); @@ -436,20 +443,23 @@ gdk_property_get (GdkWindow *window, GDK_NOTE (MULTIHEAD, g_message ("gdk_property_get(): window is NULL\n")); } + if (GDK_WINDOW_DESTROYED (window)) + return FALSE; + display = gdk_drawable_get_display (window); xproperty = gdk_x11_atom_to_xatom_for_display (display, property); xtype = gdk_x11_atom_to_xatom_for_display (display, type); ret_data = NULL; - XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), - GDK_WINDOW_XWINDOW (window), xproperty, - offset, (length + 3) / 4, pdelete, - xtype, &ret_prop_type, &ret_format, - &ret_nitems, &ret_bytes_after, - &ret_data); - - if ((ret_prop_type == None) && (ret_format == 0)) + res = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), + GDK_WINDOW_XWINDOW (window), xproperty, + offset, (length + 3) / 4, pdelete, + xtype, &ret_prop_type, &ret_format, + &ret_nitems, &ret_bytes_after, + &ret_data); + + if (res != Success || (ret_prop_type == None && ret_format == 0)) { return FALSE; } @@ -549,6 +559,9 @@ gdk_property_change (GdkWindow *window, } + if (GDK_WINDOW_DESTROYED (window)) + return; + display = gdk_drawable_get_display (window); xproperty = gdk_x11_atom_to_xatom_for_display (display, property); diff --git a/gdk/x11/gdkscreen-x11.c b/gdk/x11/gdkscreen-x11.c index 91b7d6858..cab6a9ad6 100644 --- a/gdk/x11/gdkscreen-x11.c +++ b/gdk/x11/gdkscreen-x11.c @@ -36,6 +36,7 @@ #endif static void gdk_screen_x11_class_init (GdkScreenX11Class *klass); +static void gdk_screen_x11_dispose (GObject *object); static void gdk_screen_x11_finalize (GObject *object); static void init_xinerama_support (GdkScreen *screen); @@ -69,9 +70,13 @@ _gdk_screen_x11_get_type () } void -gdk_screen_x11_class_init (GdkScreenX11Class * klass) +gdk_screen_x11_class_init (GdkScreenX11Class *klass) { - G_OBJECT_CLASS (klass)->finalize = gdk_screen_x11_finalize; + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = gdk_screen_x11_dispose; + object_class->finalize = gdk_screen_x11_finalize; + parent_class = g_type_class_peek_parent (klass); } @@ -223,6 +228,22 @@ gdk_screen_set_default_colormap (GdkScreen *screen, } static void +gdk_screen_x11_dispose (GObject *object) +{ + GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (object); + + screen_x11->root_window = NULL; + + screen_x11->xdisplay = NULL; + screen_x11->xscreen = NULL; + screen_x11->screen_num = -1; + screen_x11->xroot_window = None; + screen_x11->wmspec_check_window = None; + + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void gdk_screen_x11_finalize (GObject *object) { GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (object); @@ -237,6 +258,9 @@ gdk_screen_x11_finalize (GObject *object) g_hash_table_destroy (screen_x11->visual_hash); /* X settings */ g_free (screen_x11->xsettings_client); + + g_free (screen_x11->monitors); + G_OBJECT_CLASS (parent_class)->finalize (object); } diff --git a/gdk/x11/gdkscreen-x11.h b/gdk/x11/gdkscreen-x11.h index 4b6ed33a7..e96c6c043 100644 --- a/gdk/x11/gdkscreen-x11.h +++ b/gdk/x11/gdkscreen-x11.h @@ -85,6 +85,7 @@ struct _GdkScreenX11Class GType _gdk_screen_x11_get_type (void); GdkScreen * _gdk_x11_screen_new (GdkDisplay *display, gint screen_number); + G_END_DECLS #endif /* __GDK_SCREEN_X11_H__ */ diff --git a/gdk/x11/gdkselection-x11.c b/gdk/x11/gdkselection-x11.c index 26400adfb..5dafa8b81 100644 --- a/gdk/x11/gdkselection-x11.c +++ b/gdk/x11/gdkselection-x11.c @@ -131,6 +131,9 @@ gdk_selection_owner_set_for_display (GdkDisplay *display, g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE); + if (display->closed) + return FALSE; + if (owner) { if (GDK_WINDOW_DESTROYED (owner)) @@ -198,6 +201,9 @@ gdk_selection_owner_get_for_display (GdkDisplay *display, Window xwindow; g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL); + if (display->closed) + return NULL; + xwindow = XGetSelectionOwner (GDK_DISPLAY_XDISPLAY (display), gdk_x11_atom_to_xatom_for_display (display, selection)); @@ -227,6 +233,26 @@ gdk_selection_convert (GdkWindow *requestor, GDK_WINDOW_XID (requestor), time); } +/** + * gdk_selection_property_get: + * @requestor: the window on which the data is stored + * @data: location to store a pointer to the retrieved data. + If the retrieval failed, %NULL we be stored here, otherwise, it + will be non-%NULL and the returned data should be freed with g_free() + when you are finished using it. The length of the + allocated memory is one more than the the length + of the returned data, and the final byte will always + be zero, to ensure nul-termination of strings. + * @prop_type: location to store the type of the property. + * @prop_format: location to store the format of the property. + * + * Retrieves selection data that was stored by the selection + * data in response to a call to gdk_selection_convert(). This function + * will not be used by applications, who should use the #GtkClipboard + * API instead. + * + * Return value: the length of the retrieved data. + **/ gint gdk_selection_property_get (GdkWindow *requestor, guchar **data, @@ -246,86 +272,75 @@ gdk_selection_property_get (GdkWindow *requestor, display = GDK_WINDOW_DISPLAY (requestor); - /* If retrieved chunks are typically small, (and the ICCCM says the - should be) it would be a win to try first with a buffer of - moderate length, to avoid two round trips to the server */ - if (GDK_WINDOW_DESTROYED (requestor)) - return 0; + goto err; t = NULL; - XGetWindowProperty (GDK_WINDOW_XDISPLAY (requestor), - GDK_WINDOW_XID (requestor), - gdk_x11_atom_to_xatom_for_display (display, _gdk_selection_property), - 0, 0, False, - AnyPropertyType, &prop_type, - &prop_format, &nitems, &nbytes, &t); - if (ret_type) - *ret_type = gdk_x11_xatom_to_atom_for_display (display, prop_type); - if (ret_format) - *ret_format = prop_format; - - if (prop_type == None) - { - *data = NULL; - return 0; - } - - if (t) - { - XFree (t); - t = NULL; - } - - /* Add on an extra byte to handle null termination. X guarantees - that t will be 1 longer than nbytes and null terminated */ - length = nbytes + 1; /* We can't delete the selection here, because it might be the INCR protocol, in which case the client has to make sure they'll be notified of PropertyChange events _before_ the property is deleted. Otherwise there's no guarantee we'll win the race ... */ - XGetWindowProperty (GDK_DRAWABLE_XDISPLAY (requestor), - GDK_DRAWABLE_XID (requestor), - gdk_x11_atom_to_xatom_for_display (display, _gdk_selection_property), - 0, (nbytes + 3) / 4, False, - AnyPropertyType, &prop_type, &prop_format, - &nitems, &nbytes, &t); - + if (XGetWindowProperty (GDK_DRAWABLE_XDISPLAY (requestor), + GDK_DRAWABLE_XID (requestor), + gdk_x11_atom_to_xatom_for_display (display, _gdk_selection_property), + 0, 0x1FFFFFFF /* MAXINT32 / 4 */, False, + AnyPropertyType, &prop_type, &prop_format, + &nitems, &nbytes, &t) != Success) + goto err; + if (prop_type != None) { - *data = g_new (guchar, length); + if (ret_type) + *ret_type = gdk_x11_xatom_to_atom_for_display (display, prop_type); + if (ret_format) + *ret_format = prop_format; - if (prop_type == XA_ATOM || - prop_type == gdk_x11_get_xatom_by_name_for_display (display, "ATOM_PAIR")) - { - Atom* atoms = (Atom*) t; - GdkAtom* atoms_dest; - gint num_atom, i; - - num_atom = (length - 1) / sizeof (Atom); - length = sizeof (GdkAtom) * num_atom + 1; - *data = g_malloc (length); - (*data)[length - 1] = '\0'; - atoms_dest = (GdkAtom *)(*data); - - for (i=0; i < num_atom; i++) - atoms_dest[i] = gdk_x11_xatom_to_atom_for_display (display, atoms[i]); - } - else + /* Add on an extra byte to handle null termination. X guarantees + that t will be 1 longer than nbytes and null terminated */ + length = nbytes + 1; + + if (data) { - *data = g_memdup (t, length); + *data = g_new (guchar, length); + + if (prop_type == XA_ATOM || + prop_type == gdk_x11_get_xatom_by_name_for_display (display, "ATOM_PAIR")) + { + Atom* atoms = (Atom*) t; + GdkAtom* atoms_dest; + gint num_atom, i; + + num_atom = (length - 1) / sizeof (Atom); + length = sizeof (GdkAtom) * num_atom + 1; + *data = g_malloc (length); + (*data)[length - 1] = '\0'; + atoms_dest = (GdkAtom *)(*data); + + for (i=0; i < num_atom; i++) + atoms_dest[i] = gdk_x11_xatom_to_atom_for_display (display, atoms[i]); + } + else + { + *data = g_memdup (t, length); + } } if (t) XFree (t); - return length-1; - } - else - { - *data = NULL; - return 0; + + return length - 1; } + + err: + if (ret_type) + *ret_type = GDK_NONE; + if (ret_format) + *ret_format = 0; + if (data) + *data = NULL; + + return 0; } /** @@ -399,21 +414,20 @@ gdk_text_property_to_text_list_for_display (GdkDisplay *display, gchar **local_list; g_return_val_if_fail (GDK_IS_DISPLAY (display), 0); + if (list) + *list = NULL; + + if (display->closed) + return 0; + property.value = (guchar *)text; property.encoding = gdk_x11_atom_to_xatom_for_display (display, encoding); property.format = format; property.nitems = length; res = XmbTextPropertyToTextList (GDK_DISPLAY_XDISPLAY (display), &property, &local_list, &count); - - if (res == XNoMemory || res == XLocaleNotSupported || - res == XConverterNotFound) - { - if (list) - *list = NULL; - - return 0; - } + if (res == XNoMemory || res == XLocaleNotSupported || res == XConverterNotFound) + return 0; else { if (list) @@ -425,17 +439,6 @@ gdk_text_property_to_text_list_for_display (GdkDisplay *display, } } -gint -gdk_text_property_to_text_list (GdkAtom encoding, - gint format, - const guchar *text, - gint length, - gchar ***list) -{ - return gdk_text_property_to_text_list_for_display (gdk_display_get_default (), - encoding, format, text, length, list); -} - void gdk_free_text_list (gchar **list) { @@ -638,9 +641,12 @@ gdk_string_to_compound_text_for_display (GdkDisplay *display, g_return_val_if_fail (GDK_IS_DISPLAY (display), 0); - res = XmbTextListToTextProperty (GDK_DISPLAY_XDISPLAY (display), - (char **)&str, 1, XCompoundTextStyle, - &property); + if (display->closed) + res = XLocaleNotSupported; + else + res = XmbTextListToTextProperty (GDK_DISPLAY_XDISPLAY (display), + (char **)&str, 1, XCompoundTextStyle, + &property); if (res != Success) { property.encoding = None; @@ -661,18 +667,6 @@ gdk_string_to_compound_text_for_display (GdkDisplay *display, return res; } -gint -gdk_string_to_compound_text (const gchar *str, - GdkAtom *encoding, - gint *format, - guchar **ctext, - gint *length) -{ - return gdk_string_to_compound_text_for_display (gdk_display_get_default (), - str, encoding, format, - ctext, length); -} - /* The specifications for COMPOUND_TEXT and STRING specify that C0 and * C1 are not allowed except for \n and \t, however the X conversions * routines for COMPOUND_TEXT only enforce this in one direction, diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c index a93247f25..a47c831e8 100644 --- a/gdk/x11/gdkwindow-x11.c +++ b/gdk/x11/gdkwindow-x11.c @@ -220,6 +220,9 @@ gdk_window_impl_x11_set_colormap (GdkDrawable *drawable, impl = GDK_WINDOW_IMPL_X11 (drawable); draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable); + if (GDK_WINDOW_DESTROYED (draw_impl->wrapper)) + return; + /* chain up */ GDK_DRAWABLE_CLASS (parent_class)->set_colormap (drawable, cmap); @@ -2628,10 +2631,10 @@ gdk_window_add_colormap_windows (GdkWindow *window) g_return_if_fail (window != NULL); g_return_if_fail (GDK_IS_WINDOW (window)); - - toplevel = gdk_window_get_toplevel (window); - if (GDK_WINDOW_DESTROYED (toplevel)) + + if (GDK_WINDOW_DESTROYED (window)) return; + toplevel = gdk_window_get_toplevel (window); old_windows = NULL; if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel), @@ -3513,19 +3516,22 @@ gdk_window_set_decorations (GdkWindow *window, * Returns: TRUE if the window has decorations set, FALSE otherwise. **/ gboolean -gdk_window_get_decorations(GdkWindow *window, +gdk_window_get_decorations(GdkWindow *window, GdkWMDecoration *decorations) { MotifWmHints *hints; gboolean result = FALSE; + g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE); + hints = gdk_window_get_mwm_hints (window); if (hints) { if (hints->flags & MWM_HINTS_DECORATIONS) { - *decorations = hints->decorations; + if (decorations) + *decorations = hints->decorations; result = TRUE; } |