?? gdkwindow-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/Xutil.h>#include <X11/Xatom.h>#include <netinet/in.h>#include <unistd.h>#include "gdk.h"#include "gdkwindow.h"#include "gdkasync.h"#include "gdkinputprivate.h"#include "gdkdisplay-x11.h"#include "gdkprivate-x11.h"#include "gdkregion.h"#include "gdkinternals.h"#include "MwmUtil.h"#include "gdkwindow-x11.h"#include "gdkalias.h"#include <stdlib.h>#include <stdio.h>#include <string.h>#ifdef HAVE_SHAPE_EXT#include <X11/extensions/shape.h>#endifconst int _gdk_event_mask_table[21] ={ ExposureMask, PointerMotionMask, PointerMotionHintMask, ButtonMotionMask, Button1MotionMask, Button2MotionMask, Button3MotionMask, ButtonPressMask, ButtonReleaseMask, KeyPressMask, KeyReleaseMask, EnterWindowMask, LeaveWindowMask, FocusChangeMask, StructureNotifyMask, PropertyChangeMask, VisibilityChangeMask, 0, /* PROXIMITY_IN */ 0, /* PROXIMTY_OUT */ SubstructureNotifyMask, ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */};const int _gdk_nenvent_masks = sizeof (_gdk_event_mask_table) / sizeof (int);/* Forward declarations */static void gdk_window_set_static_win_gravity (GdkWindow *window, gboolean on);static gboolean gdk_window_have_shape_ext (GdkDisplay *display);static gboolean gdk_window_icon_name_set (GdkWindow *window);static void gdk_window_add_colormap_windows (GdkWindow *window);static void set_wm_name (GdkDisplay *display, Window xwindow, const gchar *name);static GdkColormap* gdk_window_impl_x11_get_colormap (GdkDrawable *drawable);static void gdk_window_impl_x11_set_colormap (GdkDrawable *drawable, GdkColormap *cmap);static void gdk_window_impl_x11_get_size (GdkDrawable *drawable, gint *width, gint *height);static GdkRegion* gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable);static void gdk_window_impl_x11_init (GdkWindowImplX11 *window);static void gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass);static void gdk_window_impl_x11_finalize (GObject *object);static gpointer parent_class = NULL;#define WINDOW_IS_TOPLEVEL(window) \ (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \ GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)/* Return whether time1 is considered later than time2 as far as xserver * time is concerned. Accounts for wraparound. */#define XSERVER_TIME_IS_LATER(time1, time2) \ ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \ (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \ )GTypegdk_window_impl_x11_get_type (void){ static GType object_type = 0; if (!object_type) { static const GTypeInfo object_info = { sizeof (GdkWindowImplX11Class), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gdk_window_impl_x11_class_init, NULL, /* class_finalize */ NULL, /* class_data */ sizeof (GdkWindowImplX11), 0, /* n_preallocs */ (GInstanceInitFunc) gdk_window_impl_x11_init, }; object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_X11, "GdkWindowImplX11", &object_info, 0); } return object_type;}GType_gdk_window_impl_get_type (void){ return gdk_window_impl_x11_get_type ();}static voidgdk_window_impl_x11_init (GdkWindowImplX11 *impl){ impl->width = 1; impl->height = 1; impl->toplevel_window_type = -1;}GdkToplevelX11 *_gdk_x11_window_get_toplevel (GdkWindow *window){ GdkWindowObject *private; GdkWindowImplX11 *impl; g_return_val_if_fail (GDK_IS_WINDOW (window), NULL); if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD) return NULL; private = (GdkWindowObject *)window; impl = GDK_WINDOW_IMPL_X11 (private->impl); if (!impl->toplevel) impl->toplevel = g_new0 (GdkToplevelX11, 1); return impl->toplevel;}static voidgdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass){ GObjectClass *object_class = G_OBJECT_CLASS (klass); GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass); parent_class = g_type_class_peek_parent (klass); object_class->finalize = gdk_window_impl_x11_finalize; drawable_class->set_colormap = gdk_window_impl_x11_set_colormap; drawable_class->get_colormap = gdk_window_impl_x11_get_colormap; drawable_class->get_size = gdk_window_impl_x11_get_size; /* Visible and clip regions are the same */ drawable_class->get_clip_region = gdk_window_impl_x11_get_visible_region; drawable_class->get_visible_region = gdk_window_impl_x11_get_visible_region;}static voidgdk_window_impl_x11_finalize (GObject *object){ GdkWindowObject *wrapper; GdkDrawableImplX11 *draw_impl; GdkWindowImplX11 *window_impl; g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object)); draw_impl = GDK_DRAWABLE_IMPL_X11 (object); window_impl = GDK_WINDOW_IMPL_X11 (object); wrapper = (GdkWindowObject*) draw_impl->wrapper; _gdk_xgrab_check_destroy (GDK_WINDOW (wrapper)); if (!GDK_WINDOW_DESTROYED (wrapper)) { GdkDisplay *display = GDK_WINDOW_DISPLAY (wrapper); _gdk_xid_table_remove (display, draw_impl->xid); if (window_impl->toplevel && window_impl->toplevel->focus_window) _gdk_xid_table_remove (display, window_impl->toplevel->focus_window); } if (window_impl->toplevel) g_free (window_impl->toplevel); G_OBJECT_CLASS (parent_class)->finalize (object);}static voidtmp_unset_bg (GdkWindow *window){ GdkWindowImplX11 *impl; GdkWindowObject *obj; obj = (GdkWindowObject *) window; impl = GDK_WINDOW_IMPL_X11 (obj->impl); /* For windows without EXPOSURE_MASK, we can't do this * unsetting because such windows depend on the drawing * that the X server is going to do */ if (!(obj->event_mask & GDK_EXPOSURE_MASK)) return; impl->position_info.no_bg = TRUE; if (obj->bg_pixmap != GDK_NO_BG) XSetWindowBackgroundPixmap (GDK_DRAWABLE_XDISPLAY (window), GDK_DRAWABLE_XID (window), None);}static voidtmp_reset_bg (GdkWindow *window){ GdkWindowImplX11 *impl; GdkWindowObject *obj; obj = (GdkWindowObject *) window; impl = GDK_WINDOW_IMPL_X11 (obj->impl); if (!(obj->event_mask & GDK_EXPOSURE_MASK)) return; impl->position_info.no_bg = FALSE; if (obj->bg_pixmap == GDK_NO_BG) return; if (obj->bg_pixmap) { Pixmap xpixmap; if (obj->bg_pixmap == GDK_PARENT_RELATIVE_BG) xpixmap = ParentRelative; else xpixmap = GDK_DRAWABLE_XID (obj->bg_pixmap); XSetWindowBackgroundPixmap (GDK_DRAWABLE_XDISPLAY (window), GDK_DRAWABLE_XID (window), xpixmap); } else { XSetWindowBackground (GDK_DRAWABLE_XDISPLAY (window), GDK_DRAWABLE_XID (window), obj->bg_color.pixel); }}void_gdk_x11_window_tmp_unset_bg (GdkWindow *window, gboolean recurse){ GdkWindowObject *private; g_return_if_fail (GDK_IS_WINDOW (window)); private = (GdkWindowObject *)window; if (private->input_only || private->destroyed || (private->window_type != GDK_WINDOW_ROOT && !GDK_WINDOW_IS_MAPPED (window))) { return; } if (private->window_type != GDK_WINDOW_ROOT && private->window_type != GDK_WINDOW_FOREIGN) { tmp_unset_bg (window); } if (recurse) { GList *l; for (l = private->children; l != NULL; l = l->next) _gdk_x11_window_tmp_unset_bg (l->data, TRUE); }}void_gdk_x11_window_tmp_reset_bg (GdkWindow *window, gboolean recurse){ GdkWindowObject *private; g_return_if_fail (GDK_IS_WINDOW (window)); private = (GdkWindowObject *)window; if (private->input_only || private->destroyed || (private->window_type != GDK_WINDOW_ROOT && !GDK_WINDOW_IS_MAPPED (window))) { return; } if (private->window_type != GDK_WINDOW_ROOT && private->window_type != GDK_WINDOW_FOREIGN) { tmp_reset_bg (window); } if (recurse) { GList *l; for (l = private->children; l != NULL; l = l->next) _gdk_x11_window_tmp_reset_bg (l->data, TRUE); }}static GdkColormap*gdk_window_impl_x11_get_colormap (GdkDrawable *drawable){ GdkDrawableImplX11 *drawable_impl; GdkWindowImplX11 *window_impl; g_return_val_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable), NULL); drawable_impl = GDK_DRAWABLE_IMPL_X11 (drawable); window_impl = GDK_WINDOW_IMPL_X11 (drawable); if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only && drawable_impl->colormap == NULL) { XWindowAttributes window_attributes; GdkVisual *visual; XGetWindowAttributes (GDK_SCREEN_XDISPLAY (drawable_impl->screen), drawable_impl->xid, &window_attributes); visual = gdk_x11_screen_lookup_visual (drawable_impl->screen, window_attributes.visual->visualid); drawable_impl->colormap = gdk_x11_colormap_foreign_new (visual, window_attributes.colormap); } return drawable_impl->colormap;}static voidgdk_window_impl_x11_set_colormap (GdkDrawable *drawable, GdkColormap *cmap){ GdkWindowImplX11 *impl; GdkDrawableImplX11 *draw_impl; g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable)); impl = GDK_WINDOW_IMPL_X11 (drawable); draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable); if (cmap && GDK_WINDOW_DESTROYED (draw_impl->wrapper)) return; /* chain up */ GDK_DRAWABLE_CLASS (parent_class)->set_colormap (drawable, cmap); if (cmap) { XSetWindowColormap (GDK_SCREEN_XDISPLAY (draw_impl->screen), draw_impl->xid, GDK_COLORMAP_XCOLORMAP (cmap)); if (((GdkWindowObject*)draw_impl->wrapper)->window_type != GDK_WINDOW_TOPLEVEL) gdk_window_add_colormap_windows (GDK_WINDOW (draw_impl->wrapper)); }}static voidgdk_window_impl_x11_get_size (GdkDrawable *drawable, gint *width, gint *height){ g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable)); if (width) *width = GDK_WINDOW_IMPL_X11 (drawable)->width; if (height) *height = GDK_WINDOW_IMPL_X11 (drawable)->height;}static GdkRegion*gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable){ GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (drawable); GdkRectangle result_rect; result_rect.x = 0; result_rect.y = 0; result_rect.width = impl->width; result_rect.height = impl->height; gdk_rectangle_intersect (&result_rect, &impl->position_info.clip_rect, &result_rect); return gdk_region_rectangle (&result_rect);}void_gdk_windowing_window_init (GdkScreen * screen){ GdkWindowObject *private; GdkWindowImplX11 *impl; GdkDrawableImplX11 *draw_impl; GdkScreenX11 *screen_x11; screen_x11 = GDK_SCREEN_X11 (screen); g_assert (screen_x11->root_window == NULL); gdk_screen_set_default_colormap (screen, gdk_screen_get_system_colormap (screen)); screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL); private = (GdkWindowObject *)screen_x11->root_window; impl = GDK_WINDOW_IMPL_X11 (private->impl); draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl); draw_impl->screen = screen; draw_impl->xid = screen_x11->xroot_window; draw_impl->wrapper = GDK_DRAWABLE (private); draw_impl->colormap = gdk_screen_get_system_colormap (screen); g_object_ref (draw_impl->colormap);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -