📄 gdkmain-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 <glib/gprintf.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <limits.h>#include <errno.h>#include <X11/Xatom.h>#include <X11/Xlib.h>#include <X11/Xutil.h>#ifdef HAVE_XKB#include <X11/XKBlib.h>#endif#include "gdk.h"#include "gdkx.h"#include "gdkdisplay-x11.h"#include "gdkinternals.h"#include "gdkintl.h"#include "gdkregion-generic.h"#include "gdkinputprivate.h"#include "gdkalias.h"typedef struct _GdkPredicate GdkPredicate;typedef struct _GdkErrorTrap GdkErrorTrap;struct _GdkPredicate{ GdkEventFunc func; gpointer data;};struct _GdkErrorTrap{ int (*old_handler) (Display *, XErrorEvent *); gint error_warnings; gint error_code;};/* * Private function declarations */#ifndef HAVE_XCONVERTCASEstatic void gdkx_XConvertCase (KeySym symbol, KeySym *lower, KeySym *upper);#define XConvertCase gdkx_XConvertCase#endifstatic int gdk_x_error (Display *display, XErrorEvent *error);static int gdk_x_io_error (Display *display);/* Private variable declarations */static GSList *gdk_error_traps = NULL; /* List of error traps */static GSList *gdk_error_trap_free_list = NULL; /* Free list */GOptionEntry _gdk_windowing_args[] = { { "sync", 0, 0, G_OPTION_ARG_NONE, &_gdk_synchronize, /* Description of --sync in --help output */ N_("Make X calls synchronous"), NULL }, { NULL }};void_gdk_windowing_init (void){ _gdk_x11_initialize_locale (); XSetErrorHandler (gdk_x_error); XSetIOErrorHandler (gdk_x_io_error); _gdk_selection_property = gdk_atom_intern ("GDK_SELECTION", FALSE);}voidgdk_set_use_xshm (gboolean use_xshm){}gbooleangdk_get_use_xshm (void){ return GDK_DISPLAY_X11 (gdk_display_get_default ())->use_xshm;}static GdkGrabStatusgdk_x11_convert_grab_status (gint status){ switch (status) { case GrabSuccess: return GDK_GRAB_SUCCESS; case AlreadyGrabbed: return GDK_GRAB_ALREADY_GRABBED; case GrabInvalidTime: return GDK_GRAB_INVALID_TIME; case GrabNotViewable: return GDK_GRAB_NOT_VIEWABLE; case GrabFrozen: return GDK_GRAB_FROZEN; } g_assert_not_reached(); return 0;}/* *-------------------------------------------------------------- * gdk_pointer_grab * * Grabs the pointer to a specific window * * Arguments: * "window" is the window which will receive the grab * "owner_events" specifies whether events will be reported as is, * or relative to "window" * "event_mask" masks only interesting events * "confine_to" limits the cursor movement to the specified window * "cursor" changes the cursor for the duration of the grab * "time" specifies the time * * Results: * * Side effects: * requires a corresponding call to gdk_pointer_ungrab * *-------------------------------------------------------------- */GdkGrabStatusgdk_pointer_grab (GdkWindow * window, gboolean owner_events, GdkEventMask event_mask, GdkWindow * confine_to, GdkCursor * cursor, guint32 time){ gint return_val; GdkCursorPrivate *cursor_private; guint xevent_mask; Window xwindow; Window xconfine_to; Cursor xcursor; unsigned long serial; int i; g_return_val_if_fail (window != NULL, 0); g_return_val_if_fail (GDK_IS_WINDOW (window), 0); g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0); cursor_private = (GdkCursorPrivate*) cursor; xwindow = GDK_WINDOW_XID (window); serial = NextRequest (GDK_WINDOW_XDISPLAY (window)); if (!confine_to || GDK_WINDOW_DESTROYED (confine_to)) xconfine_to = None; else xconfine_to = GDK_WINDOW_XID (confine_to); if (!cursor) xcursor = None; else xcursor = cursor_private->xcursor; xevent_mask = 0; for (i = 0; i < _gdk_nenvent_masks; i++) { if (event_mask & (1 << (i + 1))) xevent_mask |= _gdk_event_mask_table[i]; } return_val = _gdk_input_grab_pointer (window, owner_events, event_mask, confine_to, time); if (return_val == GrabSuccess) { if (!GDK_WINDOW_DESTROYED (window)) {#ifdef G_ENABLE_DEBUG if (_gdk_debug_flags & GDK_DEBUG_NOGRABS) return_val = GrabSuccess; else#endif return_val = XGrabPointer (GDK_WINDOW_XDISPLAY (window), xwindow, owner_events, xevent_mask, GrabModeAsync, GrabModeAsync, xconfine_to, xcursor, time); } else return_val = AlreadyGrabbed; } if (return_val == GrabSuccess) { GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (GDK_WINDOW_DISPLAY (window)); display_x11->pointer_xgrab_window = (GdkWindowObject *)window; display_x11->pointer_xgrab_serial = serial; display_x11->pointer_xgrab_owner_events = owner_events; } return gdk_x11_convert_grab_status (return_val);}/** * gdk_pointer_grab_info_libgtk_only: * @display: the #GdkDisplay for which to get the grab information * @grab_window: location to store current grab window * @owner_events: location to store boolean indicating whether * the @owner_events flag to gdk_pointer_grab() was %TRUE. * * Determines information about the current pointer grab. * This is not public API and must not be used by applications. * * Return value: %TRUE if this application currently has the * pointer grabbed. **/gbooleangdk_pointer_grab_info_libgtk_only (GdkDisplay *display, GdkWindow **grab_window, gboolean *owner_events){ GdkDisplayX11 *display_x11; g_return_val_if_fail (GDK_IS_DISPLAY (display), False); display_x11 = GDK_DISPLAY_X11 (display); if (display_x11->pointer_xgrab_window) { if (grab_window) *grab_window = (GdkWindow *)display_x11->pointer_xgrab_window; if (owner_events) *owner_events = display_x11->pointer_xgrab_owner_events; return TRUE; } else return FALSE;}/* *-------------------------------------------------------------- * gdk_keyboard_grab * * Grabs the keyboard to a specific window * * Arguments: * "window" is the window which will receive the grab * "owner_events" specifies whether events will be reported as is, * or relative to "window" * "time" specifies the time * * Results: * * Side effects: * requires a corresponding call to gdk_keyboard_ungrab * *-------------------------------------------------------------- */GdkGrabStatusgdk_keyboard_grab (GdkWindow * window, gboolean owner_events, guint32 time){ gint return_val; unsigned long serial; g_return_val_if_fail (window != NULL, 0); g_return_val_if_fail (GDK_IS_WINDOW (window), 0); serial = NextRequest (GDK_WINDOW_XDISPLAY (window)); if (!GDK_WINDOW_DESTROYED (window)) {#ifdef G_ENABLE_DEBUG if (_gdk_debug_flags & GDK_DEBUG_NOGRABS) return_val = GrabSuccess; else#endif return_val = XGrabKeyboard (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window), owner_events, GrabModeAsync, GrabModeAsync, time); } else return_val = AlreadyGrabbed; if (return_val == GrabSuccess) { GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (gdk_drawable_get_display (window)); display_x11->keyboard_xgrab_window = (GdkWindowObject *)window; display_x11->keyboard_xgrab_serial = serial; display_x11->keyboard_xgrab_owner_events = owner_events; } return gdk_x11_convert_grab_status (return_val);}/** * gdk_keyboard_grab_info_libgtk_only: * @display: the display for which to get the grab information * @grab_window: location to store current grab window * @owner_events: location to store boolean indicating whether * the @owner_events flag to gdk_keyboard_grab() was %TRUE. * * Determines information about the current keyboard grab. * This is not public API and must not be used by applications. * * Return value: %TRUE if this application currently has the * keyboard grabbed. **/gbooleangdk_keyboard_grab_info_libgtk_only (GdkDisplay *display, GdkWindow **grab_window, gboolean *owner_events){ GdkDisplayX11 *display_x11; g_return_val_if_fail (GDK_IS_DISPLAY (display), False); display_x11 = GDK_DISPLAY_X11 (display); if (display_x11->keyboard_xgrab_window) { if (grab_window) *grab_window = (GdkWindow *)display_x11->keyboard_xgrab_window; if (owner_events) *owner_events = display_x11->keyboard_xgrab_owner_events; return TRUE; } else return FALSE;}/** * _gdk_xgrab_check_unmap: * @window: a #GdkWindow * @serial: serial from Unmap event (or from NextRequest(display) * if the unmap is being done by this client.) * * Checks to see if an unmap request or event causes the current * grab window to become not viewable, and if so, clear the * the pointer we keep to it. **/void_gdk_xgrab_check_unmap (GdkWindow *window, gulong serial){ GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (gdk_drawable_get_display (window)); if (display_x11->pointer_xgrab_window && serial >= display_x11->pointer_xgrab_serial) { GdkWindowObject *private = GDK_WINDOW_OBJECT (window); GdkWindowObject *tmp = display_x11->pointer_xgrab_window;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -