📄 gdkproperty-x11.c
字号:
/* GDK - The GIMP Drawing Kit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. *//* * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS * file for a list of people on the GTK+ Team. See the ChangeLog * files for a list of changes. These files are distributed with * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */#include <config.h>#include <X11/Xlib.h>#include <X11/Xatom.h>#include <string.h>#include "gdk.h" /* For gdk_error_trap_push/pop() */#include "gdkx.h"#include "gdkproperty.h"#include "gdkprivate.h"#include "gdkinternals.h"#include "gdkdisplay-x11.h"#include "gdkscreen-x11.h"#include "gdkselection.h" /* only from predefined atom */#include "gdkalias.h"static GPtrArray *virtual_atom_array;static GHashTable *virtual_atom_hash;static const gchar *const XAtomsStrings[] = { /* These are all the standard predefined X atoms */ "NONE", "PRIMARY", "SECONDARY", "ARC", "ATOM", "BITMAP", "CARDINAL", "COLORMAP", "CURSOR", "CUT_BUFFER0", "CUT_BUFFER1", "CUT_BUFFER2", "CUT_BUFFER3", "CUT_BUFFER4", "CUT_BUFFER5", "CUT_BUFFER6", "CUT_BUFFER7", "DRAWABLE", "FONT", "INTEGER", "PIXMAP", "POINT", "RECTANGLE", "RESOURCE_MANAGER", "RGB_COLOR_MAP", "RGB_BEST_MAP", "RGB_BLUE_MAP", "RGB_DEFAULT_MAP", "RGB_GRAY_MAP", "RGB_GREEN_MAP", "RGB_RED_MAP", "STRING", "VISUALID", "WINDOW", "WM_COMMAND", "WM_HINTS", "WM_CLIENT_MACHINE", "WM_ICON_NAME", "WM_ICON_SIZE", "WM_NAME", "WM_NORMAL_HINTS", "WM_SIZE_HINTS", "WM_ZOOM_HINTS", "MIN_SPACE", "NORM_SPACE", "MAX_SPACE", "END_SPACE", "SUPERSCRIPT_X", "SUPERSCRIPT_Y", "SUBSCRIPT_X", "SUBSCRIPT_Y", "UNDERLINE_POSITION", "UNDERLINE_THICKNESS", "STRIKEOUT_ASCENT", "STRIKEOUT_DESCENT", "ITALIC_ANGLE", "X_HEIGHT", "QUAD_WIDTH", "WEIGHT", "POINT_SIZE", "RESOLUTION", "COPYRIGHT", "NOTICE", "FONT_NAME", "FAMILY_NAME", "FULL_NAME", "CAP_HEIGHT", "WM_CLASS", "WM_TRANSIENT_FOR", /* Below here, these are our additions. Increment N_CUSTOM_PREDEFINED * if you add any. */ "CLIPBOARD" /* = 69 */};#define N_CUSTOM_PREDEFINED 1#define ATOM_TO_INDEX(atom) (GPOINTER_TO_UINT(atom))#define INDEX_TO_ATOM(atom) ((GdkAtom)GUINT_TO_POINTER(atom))static voidinsert_atom_pair (GdkDisplay *display, GdkAtom virtual_atom, Atom xatom){ GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display); if (!display_x11->atom_from_virtual) { display_x11->atom_from_virtual = g_hash_table_new (g_direct_hash, NULL); display_x11->atom_to_virtual = g_hash_table_new (g_direct_hash, NULL); } g_hash_table_insert (display_x11->atom_from_virtual, GDK_ATOM_TO_POINTER (virtual_atom), GUINT_TO_POINTER (xatom)); g_hash_table_insert (display_x11->atom_to_virtual, GUINT_TO_POINTER (xatom), GDK_ATOM_TO_POINTER (virtual_atom));}static Atomlookup_cached_xatom (GdkDisplay *display, GdkAtom atom){ GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display); if (ATOM_TO_INDEX (atom) < G_N_ELEMENTS (XAtomsStrings) - N_CUSTOM_PREDEFINED) return ATOM_TO_INDEX (atom); if (display_x11->atom_from_virtual) return GPOINTER_TO_UINT (g_hash_table_lookup (display_x11->atom_from_virtual, GDK_ATOM_TO_POINTER (atom))); return None;}/** * gdk_x11_atom_to_xatom_for_display: * @display: A #GdkDisplay * @atom: A #GdkAtom * * Converts from a #GdkAtom to the X atom for a #GdkDisplay * with the same string value. * * Return value: the X atom corresponding to @atom. * * Since: 2.2 **/Atomgdk_x11_atom_to_xatom_for_display (GdkDisplay *display, GdkAtom atom){ Atom xatom = None; g_return_val_if_fail (GDK_IS_DISPLAY (display), None); if (display->closed) return None; xatom = lookup_cached_xatom (display, atom); if (!xatom) { char *name; g_return_val_if_fail (ATOM_TO_INDEX (atom) < virtual_atom_array->len, None); name = g_ptr_array_index (virtual_atom_array, ATOM_TO_INDEX (atom)); xatom = XInternAtom (GDK_DISPLAY_XDISPLAY (display), name, FALSE); insert_atom_pair (display, atom, xatom); } return xatom;}void_gdk_x11_precache_atoms (GdkDisplay *display, const gchar * const *atom_names, gint n_atoms){ Atom *xatoms; GdkAtom *atoms; const gchar **xatom_names; gint n_xatoms; gint i; xatoms = g_new (Atom, n_atoms); xatom_names = g_new (const gchar *, n_atoms); atoms = g_new (GdkAtom, n_atoms); n_xatoms = 0; for (i = 0; i < n_atoms; i++) { GdkAtom atom = gdk_atom_intern (atom_names[i], FALSE); if (lookup_cached_xatom (display, atom) == None) { atoms[n_xatoms] = atom; xatom_names[n_xatoms] = atom_names[i]; n_xatoms++; } } if (n_xatoms) {#ifdef HAVE_XINTERNATOMS XInternAtoms (GDK_DISPLAY_XDISPLAY (display), (char **)xatom_names, n_xatoms, False, xatoms);#else for (i = 0; i < n_xatoms; i++) xatoms[i] = XInternAtom (GDK_DISPLAY_XDISPLAY (display), xatom_names[i], False);#endif } for (i = 0; i < n_xatoms; i++) insert_atom_pair (display, atoms[i], xatoms[i]); g_free (xatoms); g_free (xatom_names); g_free (atoms);}/** * gdk_x11_atom_to_xatom: * @atom: A #GdkAtom * * Converts from a #GdkAtom to the X atom for the default GDK display * with the same string value. * * Return value: the X atom corresponding to @atom. **/Atomgdk_x11_atom_to_xatom (GdkAtom atom){ return gdk_x11_atom_to_xatom_for_display (gdk_display_get_default (), atom);}/** * gdk_x11_xatom_to_atom_for_display: * @display: A #GdkDisplay * @xatom: an X atom * * Convert from an X atom for a #GdkDisplay to the corresponding * #GdkAtom. * * Return value: the corresponding #GdkAtom. * * Since: 2.2 **/GdkAtomgdk_x11_xatom_to_atom_for_display (GdkDisplay *display, Atom xatom){ GdkDisplayX11 *display_x11; GdkAtom virtual_atom = GDK_NONE; g_return_val_if_fail (GDK_IS_DISPLAY (display), GDK_NONE); if (display->closed) return GDK_NONE; display_x11 = GDK_DISPLAY_X11 (display); if (xatom < G_N_ELEMENTS (XAtomsStrings) - N_CUSTOM_PREDEFINED) return INDEX_TO_ATOM (xatom); if (display_x11->atom_to_virtual) virtual_atom = GDK_POINTER_TO_ATOM (g_hash_table_lookup (display_x11->atom_to_virtual, GUINT_TO_POINTER (xatom))); if (!virtual_atom) { /* If this atom doesn't exist, we'll die with an X error unless * we take precautions */ char *name; gdk_error_trap_push (); name = XGetAtomName (GDK_DISPLAY_XDISPLAY (display), xatom); if (gdk_error_trap_pop ()) { g_warning (G_STRLOC " invalid X atom: %ld", xatom); } else { virtual_atom = gdk_atom_intern (name, FALSE); XFree (name); insert_atom_pair (display, virtual_atom, xatom); } } return virtual_atom;}/** * gdk_x11_xatom_to_atom: * @xatom: an X atom for the default GDK display * * Convert from an X atom for the default display to the corresponding * #GdkAtom. * * Return value: the corresponding G#dkAtom. **/GdkAtomgdk_x11_xatom_to_atom (Atom xatom){ return gdk_x11_xatom_to_atom_for_display (gdk_display_get_default (), xatom);}static voidvirtual_atom_check_init (void){ if (!virtual_atom_hash) { gint i; virtual_atom_hash = g_hash_table_new (g_str_hash, g_str_equal); virtual_atom_array = g_ptr_array_new (); for (i = 0; i < G_N_ELEMENTS (XAtomsStrings); i++) { g_ptr_array_add (virtual_atom_array, (gchar *) XAtomsStrings[i]); g_hash_table_insert (virtual_atom_hash, (gchar *) XAtomsStrings[i], GUINT_TO_POINTER (i)); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -