⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdk.c

📁 gtk是linux一款强大的夸平台的图形化开发工具
💻 C
📖 第 1 页 / 共 3 页
字号:
/* 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 Library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library 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-1999.  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 <ctype.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <limits.h>#include <errno.h>#ifdef HAVE_SYS_SELECT_H#include <sys/select.h>#endif /* HAVE_SYS_SELECT_H_ */#define XLIB_ILLEGAL_ACCESS#include <X11/Xatom.h>#include <X11/Xlib.h>#include <X11/Xos.h>#include <X11/Xutil.h>#include <X11/Xmu/WinUtil.h>#include <X11/cursorfont.h>#include "gdk.h"#include "gdkprivate.h"#include "gdkinput.h"#include "gdkx.h"#include "gdki18n.h"#include "gdkkeysyms.h"#ifndef X_GETTIMEOFDAY#define X_GETTIMEOFDAY(tv)  gettimeofday (tv, NULL)#endif /* X_GETTIMEOFDAY */typedef struct _GdkPredicate  GdkPredicate;typedef struct _GdkErrorTrap  GdkErrorTrap;struct _GdkPredicate{  GdkEventFunc func;  gpointer data;};struct _GdkErrorTrap{  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 void	    gdk_exit_func		 (void);static int	    gdk_x_error			 (Display     *display, 						  XErrorEvent *error);static int	    gdk_x_io_error		 (Display     *display);GdkFilterReturn gdk_wm_protocols_filter (GdkXEvent *xev,					 GdkEvent  *event,					 gpointer   data);/* Private variable declarations */static int gdk_initialized = 0;			    /* 1 if the library is initialized,						     * 0 otherwise.						     */static struct timeval start;			    /* The time at which the library was						     *	last initialized.						     */static struct timeval timer;			    /* Timeout interval to use in the call						     *	to "select". This is used in						     *	conjunction with "timerp" to create						     *	a maximum time to wait for an event						     *	to arrive.						     */static struct timeval *timerp;			    /* The actual timer passed to "select"						     *	This may be NULL, in which case						     *	"select" will block until an event						     *	arrives.						     */static guint32 timer_val;			    /* The timeout length as specified by						     *	the user in milliseconds.						     */static gint autorepeat;static GSList *gdk_error_traps = NULL;               /* List of error traps */static GSList *gdk_error_trap_free_list = NULL;      /* Free list */#ifdef G_ENABLE_DEBUGstatic const GDebugKey gdk_debug_keys[] = {  {"events",	    GDK_DEBUG_EVENTS},  {"misc",	    GDK_DEBUG_MISC},  {"dnd",	    GDK_DEBUG_DND},  {"color-context", GDK_DEBUG_COLOR_CONTEXT},  {"xim",	    GDK_DEBUG_XIM}};static const int gdk_ndebug_keys = sizeof(gdk_debug_keys)/sizeof(GDebugKey);#endif /* G_ENABLE_DEBUG *//* *-------------------------------------------------------------- * gdk_init_heck * *   Initialize the library for use. * * Arguments: *   "argc" is the number of arguments. *   "argv" is an array of strings. * * Results: *   "argc" and "argv" are modified to reflect any arguments *   which were not handled. (Such arguments should either *   be handled by the application or dismissed). If initialization *   fails, returns FALSE, otherwise TRUE. * * Side effects: *   The library is initialized. * *-------------------------------------------------------------- */gbooleangdk_init_check (int	 *argc,		char ***argv){  XKeyboardState keyboard_state;  gint synchronize;  gint i, j, k;  XClassHint *class_hint;  gchar **argv_orig = NULL;  gint argc_orig = 0;    if (gdk_initialized)    return TRUE;    if (g_thread_supported ())    gdk_threads_mutex = g_mutex_new ();    if (argc && argv)    {      argc_orig = *argc;            argv_orig = g_malloc ((argc_orig + 1) * sizeof (char*));      for (i = 0; i < argc_orig; i++)	argv_orig[i] = g_strdup ((*argv)[i]);      argv_orig[argc_orig] = NULL;    }    X_GETTIMEOFDAY (&start);    gdk_display_name = NULL;    XSetErrorHandler (gdk_x_error);  XSetIOErrorHandler (gdk_x_io_error);    synchronize = FALSE;  #ifdef G_ENABLE_DEBUG  {    gchar *debug_string = getenv("GDK_DEBUG");    if (debug_string != NULL)      gdk_debug_flags = g_parse_debug_string (debug_string,					      (GDebugKey *) gdk_debug_keys,					      gdk_ndebug_keys);  }#endif	/* G_ENABLE_DEBUG */    if (argc && argv)    {      if (*argc > 0)	{	  gchar *d;	  	  d = strrchr((*argv)[0],'/');	  if (d != NULL)	    g_set_prgname (d + 1);	  else	    g_set_prgname ((*argv)[0]);	}            for (i = 1; i < *argc;)	{#ifdef G_ENABLE_DEBUG	  	  if ((strcmp ("--gdk-debug", (*argv)[i]) == 0) ||	      (strncmp ("--gdk-debug=", (*argv)[i], 12) == 0))	    {	      gchar *equal_pos = strchr ((*argv)[i], '=');	      	      if (equal_pos != NULL)		{		  gdk_debug_flags |= g_parse_debug_string (equal_pos+1,							   (GDebugKey *) gdk_debug_keys,							   gdk_ndebug_keys);		}	      else if ((i + 1) < *argc && (*argv)[i + 1])		{		  gdk_debug_flags |= g_parse_debug_string ((*argv)[i+1],							   (GDebugKey *) gdk_debug_keys,							   gdk_ndebug_keys);		  (*argv)[i] = NULL;		  i += 1;		}	      (*argv)[i] = NULL;	    }	  else if ((strcmp ("--gdk-no-debug", (*argv)[i]) == 0) ||		   (strncmp ("--gdk-no-debug=", (*argv)[i], 15) == 0))	    {	      gchar *equal_pos = strchr ((*argv)[i], '=');	      	      if (equal_pos != NULL)		{		  gdk_debug_flags &= ~g_parse_debug_string (equal_pos+1,							    (GDebugKey *) gdk_debug_keys,							    gdk_ndebug_keys);		}	      else if ((i + 1) < *argc && (*argv)[i + 1])		{		  gdk_debug_flags &= ~g_parse_debug_string ((*argv)[i+1],							    (GDebugKey *) gdk_debug_keys,							    gdk_ndebug_keys);		  (*argv)[i] = NULL;		  i += 1;		}	      (*argv)[i] = NULL;	    }	  else #endif /* G_ENABLE_DEBUG */	    if (strcmp ("--display", (*argv)[i]) == 0)	      {		(*argv)[i] = NULL;				if ((i + 1) < *argc && (*argv)[i + 1])		  {		    gdk_display_name = g_strdup ((*argv)[i + 1]);		    (*argv)[i + 1] = NULL;		    i += 1;		  }	      }	    else if (strcmp ("--sync", (*argv)[i]) == 0)	      {		(*argv)[i] = NULL;		synchronize = TRUE;	      }	    else if (strcmp ("--no-xshm", (*argv)[i]) == 0)	      {		(*argv)[i] = NULL;		gdk_use_xshm = FALSE;	      }	    else if (strcmp ("--name", (*argv)[i]) == 0)	      {		if ((i + 1) < *argc && (*argv)[i + 1])		  {		    (*argv)[i++] = NULL;		    g_set_prgname ((*argv)[i]);		    (*argv)[i] = NULL;		  }	      }	    else if (strcmp ("--class", (*argv)[i]) == 0)	      {		if ((i + 1) < *argc && (*argv)[i + 1])		  {		    (*argv)[i++] = NULL;		    gdk_progclass = (*argv)[i];		    (*argv)[i] = NULL;		  }	      }#ifdef XINPUT_GXI	    else if (strcmp ("--gxid_host", (*argv)[i]) == 0)	      {		if ((i + 1) < *argc && (*argv)[i + 1])		  {		    (*argv)[i++] = NULL;		    gdk_input_gxid_host = ((*argv)[i]);		    (*argv)[i] = NULL;		  }	      }	    else if (strcmp ("--gxid_port", (*argv)[i]) == 0)	      {		if ((i + 1) < *argc && (*argv)[i + 1])		  {		    (*argv)[i++] = NULL;		    gdk_input_gxid_port = atoi ((*argv)[i]);		    (*argv)[i] = NULL;		  }	      }#endif#ifdef USE_XIM	    else if (strcmp ("--xim-preedit", (*argv)[i]) == 0)	      {		if ((i + 1) < *argc && (*argv)[i + 1])		  {		    (*argv)[i++] = NULL;		    if (strcmp ("none", (*argv)[i]) == 0)		      gdk_im_set_best_style (GDK_IM_PREEDIT_NONE);		    else if (strcmp ("nothing", (*argv)[i]) == 0)		      gdk_im_set_best_style (GDK_IM_PREEDIT_NOTHING);		    else if (strcmp ("area", (*argv)[i]) == 0)		      gdk_im_set_best_style (GDK_IM_PREEDIT_AREA);		    else if (strcmp ("position", (*argv)[i]) == 0)		      gdk_im_set_best_style (GDK_IM_PREEDIT_POSITION);		    else if (strcmp ("callbacks", (*argv)[i]) == 0)		      gdk_im_set_best_style (GDK_IM_PREEDIT_CALLBACKS);		    (*argv)[i] = NULL;		  }	      }	    else if (strcmp ("--xim-status", (*argv)[i]) == 0)	      {		if ((i + 1) < *argc && (*argv)[i + 1])		  {		    (*argv)[i++] = NULL;		    if (strcmp ("none", (*argv)[i]) == 0)		      gdk_im_set_best_style (GDK_IM_STATUS_NONE);		    else if (strcmp ("nothing", (*argv)[i]) == 0)		      gdk_im_set_best_style (GDK_IM_STATUS_NOTHING);		    else if (strcmp ("area", (*argv)[i]) == 0)		      gdk_im_set_best_style (GDK_IM_STATUS_AREA);		    else if (strcmp ("callbacks", (*argv)[i]) == 0)		      gdk_im_set_best_style (GDK_IM_STATUS_CALLBACKS);		    (*argv)[i] = NULL;		  }	      }#endif	  	  i += 1;	}            for (i = 1; i < *argc; i++)	{	  for (k = i; k < *argc; k++)	    if ((*argv)[k] != NULL)	      break;	  	  if (k > i)	    {	      k -= i;	      for (j = i + k; j < *argc; j++)		(*argv)[j-k] = (*argv)[j];	      *argc -= k;	    }	}    }  else    {      g_set_prgname ("<unknown>");    }    GDK_NOTE (MISC, g_message ("progname: \"%s\"", g_get_prgname ()));    gdk_display = XOpenDisplay (gdk_display_name);  if (!gdk_display)    return FALSE;    if (synchronize)    XSynchronize (gdk_display, True);    gdk_screen = DefaultScreen (gdk_display);  gdk_root_window = RootWindow (gdk_display, gdk_screen);    gdk_leader_window = XCreateSimpleWindow(gdk_display, gdk_root_window,					  10, 10, 10, 10, 0, 0 , 0);  class_hint = XAllocClassHint();  class_hint->res_name = g_get_prgname ();  if (gdk_progclass == NULL)    {      gdk_progclass = g_strdup (g_get_prgname ());      gdk_progclass[0] = toupper (gdk_progclass[0]);    }  class_hint->res_class = gdk_progclass;  XmbSetWMProperties (gdk_display, gdk_leader_window,                      NULL, NULL, argv_orig, argc_orig,                       NULL, NULL, class_hint);  XFree (class_hint);    for (i = 0; i < argc_orig; i++)    g_free(argv_orig[i]);  g_free(argv_orig);    gdk_wm_delete_window = XInternAtom (gdk_display, "WM_DELETE_WINDOW", False);  gdk_wm_take_focus = XInternAtom (gdk_display, "WM_TAKE_FOCUS", False);  gdk_wm_protocols = XInternAtom (gdk_display, "WM_PROTOCOLS", False);  gdk_wm_window_protocols[0] = gdk_wm_delete_window;  gdk_wm_window_protocols[1] = gdk_wm_take_focus;  gdk_selection_property = XInternAtom (gdk_display, "GDK_SELECTION", False);    XGetKeyboardControl (gdk_display, &keyboard_state);  autorepeat = keyboard_state.global_auto_repeat;    timer.tv_sec = 0;  timer.tv_usec = 0;  timerp = NULL;    g_atexit (gdk_exit_func);    gdk_events_init ();  gdk_visual_init ();  gdk_window_init ();  gdk_image_init ();  gdk_input_init ();  gdk_dnd_init ();#ifdef USE_XIM  gdk_im_open ();#endif    gdk_initialized = 1;  return TRUE;}voidgdk_init (int *argc, char ***argv){  if (!gdk_init_check (argc, argv))    {      g_warning ("cannot open display: %s", gdk_get_display ());      exit(1);    }}/* *-------------------------------------------------------------- * gdk_exit * *   Restores the library to an un-itialized state and exits *   the program using the "exit" system call. * * Arguments: *   "errorcode" is the error value to pass to "exit". * * Results: *   Allocated structures are freed and the program exits *   cleanly. * * Side effects: * *-------------------------------------------------------------- */voidgdk_exit (int errorcode)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -