diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c index 80cafbf135..fac1a5ef52 100644 --- a/gdk/x11/gdkdisplay-x11.c +++ b/gdk/x11/gdkdisplay-x11.c @@ -896,7 +896,7 @@ _gdk_windowing_set_default_display (GdkDisplay *display) gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"), gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8, PropModeReplace, - startup_id, strlen (startup_id)); + (guchar *)startup_id, strlen (startup_id)); } } diff --git a/gdk/x11/gdkdnd-x11.c b/gdk/x11/gdkdnd-x11.c index 15e66e18c3..0154954c14 100644 --- a/gdk/x11/gdkdnd-x11.c +++ b/gdk/x11/gdkdnd-x11.c @@ -1919,7 +1919,7 @@ xdnd_initialize_actions (void) xdnd_actions_initialized = TRUE; for (i=0; i < xdnd_n_actions; i++) - xdnd_actions_table[i].atom = gdk_atom_intern (xdnd_actions_table[i].name, FALSE); + xdnd_actions_table[i].atom = gdk_atom_intern_static_string (xdnd_actions_table[i].name); } static GdkDragAction @@ -2938,14 +2938,14 @@ _gdk_dnd_init (GdkDisplay *display) gdk_display_add_client_message_filter ( display, - gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE), + gdk_atom_intern_static_string ("_MOTIF_DRAG_AND_DROP_MESSAGE"), motif_dnd_filter, NULL); for (i = 0; i < G_N_ELEMENTS (xdnd_filters); i++) { gdk_display_add_client_message_filter ( display, - gdk_atom_intern (xdnd_filters[i].atom_name, FALSE), + gdk_atom_intern_static_string (xdnd_filters[i].atom_name), xdnd_filters[i].func, NULL); } } @@ -3408,8 +3408,8 @@ gdk_drag_motion (GdkDragContext *context, /* GTK+ traditionally has used application/x-rootwin-drop, * but the XDND spec specifies x-rootwindow-drop. */ - GdkAtom target1 = gdk_atom_intern ("application/x-rootwindow-drop", FALSE); - GdkAtom target2 = gdk_atom_intern ("application/x-rootwin-drop", FALSE); + GdkAtom target1 = gdk_atom_intern_static_string ("application/x-rootwindow-drop"); + GdkAtom target2 = gdk_atom_intern_static_string ("application/x-rootwin-drop"); if (g_list_find (context->targets, GDK_ATOM_TO_POINTER (target1)) || @@ -3798,7 +3798,7 @@ gdk_drag_get_selection (GdkDragContext *context) return gdk_x11_xatom_to_atom_for_display (GDK_DRAWABLE_DISPLAY (context->source_window), (PRIVATE_DATA (context))->motif_selection); else if (context->protocol == GDK_DRAG_PROTO_XDND) - return gdk_atom_intern ("XdndSelection", FALSE); + return gdk_atom_intern_static_string ("XdndSelection"); else return GDK_NONE; } diff --git a/gdk/x11/gdkevents-x11.c b/gdk/x11/gdkevents-x11.c index ebf7478116..61ecdeb716 100644 --- a/gdk/x11/gdkevents-x11.c +++ b/gdk/x11/gdkevents-x11.c @@ -222,7 +222,7 @@ _gdk_events_init (GdkDisplay *display) display_sources = g_list_prepend (display_sources,display_source); gdk_display_add_client_message_filter (display, - gdk_atom_intern ("WM_PROTOCOLS", FALSE), + gdk_atom_intern_static_string ("WM_PROTOCOLS"), gdk_wm_protocols_filter, NULL); } diff --git a/gdk/x11/gdkmain-x11.c b/gdk/x11/gdkmain-x11.c index 9b8ee95545..ac1b01335e 100644 --- a/gdk/x11/gdkmain-x11.c +++ b/gdk/x11/gdkmain-x11.c @@ -101,7 +101,7 @@ _gdk_windowing_init (void) XSetErrorHandler (gdk_x_error); XSetIOErrorHandler (gdk_x_io_error); - _gdk_selection_property = gdk_atom_intern ("GDK_SELECTION", FALSE); + _gdk_selection_property = gdk_atom_intern_static_string ("GDK_SELECTION"); } void diff --git a/gdk/x11/gdkproperty-x11.c b/gdk/x11/gdkproperty-x11.c index 8edafaa57e..9c9b7681ec 100644 --- a/gdk/x11/gdkproperty-x11.c +++ b/gdk/x11/gdkproperty-x11.c @@ -219,7 +219,7 @@ _gdk_x11_precache_atoms (GdkDisplay *display, n_xatoms = 0; for (i = 0; i < n_atoms; i++) { - GdkAtom atom = gdk_atom_intern (atom_names[i], FALSE); + GdkAtom atom = gdk_atom_intern_static_string (atom_names[i]); if (lookup_cached_xatom (display, atom) == None) { atoms[n_xatoms] = atom; @@ -354,9 +354,9 @@ virtual_atom_check_init (void) } } -GdkAtom -gdk_atom_intern (const gchar *atom_name, - gboolean only_if_exists) +static GdkAtom +intern_atom (const gchar *atom_name, + gboolean dup) { GdkAtom result; @@ -367,7 +367,7 @@ gdk_atom_intern (const gchar *atom_name, { result = INDEX_TO_ATOM (virtual_atom_array->len); - g_ptr_array_add (virtual_atom_array, g_strdup (atom_name)); + g_ptr_array_add (virtual_atom_array, dup ? g_strdup (atom_name) : atom_name); g_hash_table_insert (virtual_atom_hash, g_ptr_array_index (virtual_atom_array, ATOM_TO_INDEX (result)), @@ -377,6 +377,38 @@ gdk_atom_intern (const gchar *atom_name, return result; } +GdkAtom +gdk_atom_intern (const gchar *atom_name, + gboolean only_if_exists) +{ + return intern_atom (atom_name, TRUE); +} + +/** + * gdk_atom_intern_static_string: + * @atom_name: a static string + * + * Finds or creates an atom corresponding to a given string. + * + * Note that this function is identical to gdk_atom_intern() except + * that if a new #GdkAtom is created the string itself is used rather + * than a copy. This saves memory, but can only be used if the string + * will always exist. It can be used with statically + * allocated strings in the main program, but not with statically + * allocated memory in dynamically loaded modules, if you expect to + * ever unload the module again (e.g. do not use this function in + * GTK+ theme engines). + * + * Returns: the atom corresponding to @atom_name + * + * Since: 2.10 + */ +GdkAtom +gdk_atom_intern_static_string (const gchar *atom_name) +{ + return intern_atom (atom_name, FALSE); +} + static G_CONST_RETURN char * get_atom_name (GdkAtom atom) { diff --git a/gdk/x11/gdkselection-x11.c b/gdk/x11/gdkselection-x11.c index 12eec95ad5..9bf7e478b5 100644 --- a/gdk/x11/gdkselection-x11.c +++ b/gdk/x11/gdkselection-x11.c @@ -591,7 +591,7 @@ gdk_text_property_to_utf8_list_for_display (GdkDisplay *display, { return make_list ((gchar *)text, length, TRUE, list); } - else if (encoding == gdk_atom_intern ("UTF8_STRING", FALSE)) + else if (encoding == gdk_atom_intern_static_string ("UTF8_STRING")) { return make_list ((gchar *)text, length, FALSE, list); } diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c index 3ef562f7e7..f96e693e87 100644 --- a/gdk/x11/gdkwindow-x11.c +++ b/gdk/x11/gdkwindow-x11.c @@ -2042,7 +2042,7 @@ gdk_x11_window_move_to_current_desktop (GdkWindow *window) return; if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window), - gdk_atom_intern ("_NET_WM_DESKTOP", FALSE))) + gdk_atom_intern_static_string ("_NET_WM_DESKTOP"))) { XEvent xev; Atom type; @@ -2116,7 +2116,7 @@ gdk_window_focus (GdkWindow *window, display = GDK_WINDOW_DISPLAY (window); if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window), - gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE))) + gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW"))) { XEvent xev; @@ -2341,7 +2341,7 @@ gdk_window_set_modal_hint (GdkWindow *window, if (GDK_WINDOW_IS_MAPPED (window)) gdk_wmspec_change_state (modal, window, - gdk_atom_intern ("_NET_WM_STATE_MODAL", FALSE), + gdk_atom_intern_static_string ("_NET_WM_STATE_MODAL"), NULL); } @@ -2376,7 +2376,7 @@ gdk_window_set_skip_taskbar_hint (GdkWindow *window, if (GDK_WINDOW_IS_MAPPED (window)) gdk_wmspec_change_state (skips_taskbar, window, - gdk_atom_intern ("_NET_WM_STATE_SKIP_TASKBAR", FALSE), + gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_TASKBAR"), NULL); } @@ -2413,7 +2413,7 @@ gdk_window_set_skip_pager_hint (GdkWindow *window, if (GDK_WINDOW_IS_MAPPED (window)) gdk_wmspec_change_state (skips_pager, window, - gdk_atom_intern ("_NET_WM_STATE_SKIP_PAGER", FALSE), + gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_PAGER"), NULL); } @@ -4279,7 +4279,7 @@ gdk_window_stick (GdkWindow *window) /* Request stick during viewport scroll */ gdk_wmspec_change_state (TRUE, window, - gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE), + gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"), NULL); /* Request desktop 0xFFFFFFFF */ @@ -4340,7 +4340,7 @@ gdk_window_unstick (GdkWindow *window) /* Request unstick from viewport */ gdk_wmspec_change_state (FALSE, window, - gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE), + gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"), NULL); /* Get current desktop, then set it; this is a race, but not @@ -4413,8 +4413,8 @@ gdk_window_maximize (GdkWindow *window) if (GDK_WINDOW_IS_MAPPED (window)) gdk_wmspec_change_state (TRUE, window, - gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE), - gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE)); + gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"), + gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ")); else gdk_synthesize_window_state (window, 0, @@ -4448,8 +4448,8 @@ gdk_window_unmaximize (GdkWindow *window) if (GDK_WINDOW_IS_MAPPED (window)) gdk_wmspec_change_state (FALSE, window, - gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE), - gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE)); + gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"), + gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ")); else gdk_synthesize_window_state (window, GDK_WINDOW_STATE_MAXIMIZED, @@ -4486,7 +4486,7 @@ gdk_window_fullscreen (GdkWindow *window) if (GDK_WINDOW_IS_MAPPED (window)) gdk_wmspec_change_state (TRUE, window, - gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", FALSE), + gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"), GDK_NONE); else @@ -4522,7 +4522,7 @@ gdk_window_unfullscreen (GdkWindow *window) if (GDK_WINDOW_IS_MAPPED (window)) gdk_wmspec_change_state (FALSE, window, - gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", FALSE), + gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"), GDK_NONE); else @@ -4560,10 +4560,10 @@ gdk_window_set_keep_above (GdkWindow *window, gboolean setting) { if (setting) gdk_wmspec_change_state (FALSE, window, - gdk_atom_intern ("_NET_WM_STATE_BELOW", FALSE), + gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"), GDK_NONE); gdk_wmspec_change_state (setting, window, - gdk_atom_intern ("_NET_WM_STATE_ABOVE", FALSE), + gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"), GDK_NONE); } else @@ -4601,10 +4601,10 @@ gdk_window_set_keep_below (GdkWindow *window, gboolean setting) { if (setting) gdk_wmspec_change_state (FALSE, window, - gdk_atom_intern ("_NET_WM_STATE_ABOVE", FALSE), + gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"), GDK_NONE); gdk_wmspec_change_state (setting, window, - gdk_atom_intern ("_NET_WM_STATE_BELOW", FALSE), + gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"), GDK_NONE); } else @@ -5881,7 +5881,7 @@ gdk_window_begin_resize_drag (GdkWindow *window, return; if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window), - gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE))) + gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE"))) wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp); else emulate_resize_drag (window, edge, button, root_x, root_y, timestamp); @@ -5916,7 +5916,7 @@ gdk_window_begin_move_drag (GdkWindow *window, return; if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window), - gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE))) + gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE"))) wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y, timestamp); else