📄 initapp.c
字号:
signal (SIGCHLD, childhandler);}static void set_alarm (void){ memset (&xevent, 0, sizeof (XEvent)); xevent.type = 0; xevent.xany.display = CDisplay; xevent.xany.send_event = 1; CSetCursorBlinkRate (7); /* theta rhythms ? */ signal (SIGALRM, alarmhandler); setitimer (ITIMER_REAL, &alarm_every, NULL);}void CEnableAlarm (void){ set_alarm ();}void CDisableAlarm (void){ setitimer (ITIMER_REAL, &alarm_off, NULL); signal (SIGALRM, 0);}void get_temp_dir (void){ if (temp_dir) return; temp_dir = getenv ("TEMP"); if (temp_dir) if (*temp_dir) { temp_dir = (char *) strdup (temp_dir); return; } temp_dir = getenv ("TMP"); if (temp_dir) if (*temp_dir) { temp_dir = (char *) strdup (temp_dir); return; } temp_dir = (char *) strdup ("/tmp");}void get_home_dir (void){ if (home_dir) /* already been set */ return; home_dir = getenv ("HOME"); if (home_dir) if (*home_dir) { home_dir = (char *) strdup (home_dir); return; } home_dir = (getpwuid (geteuid ()))->pw_dir; if (home_dir) if (*home_dir) { home_dir = (char *) strdup (home_dir); return; } fprintf (stderr, _ ("%s: HOME environment variable not set and no passwd entry - aborting\n"), CAppName); abort ();}void get_dir (void){ if (!get_current_wd (current_dir, MAX_PATH_LEN)) *current_dir = 0; get_temp_dir (); get_home_dir ();}void wm_interaction_init (void){ ATOM_WM_PROTOCOLS = XInternAtom (CDisplay, "WM_PROTOCOLS", False); ATOM_WM_DELETE_WINDOW = XInternAtom (CDisplay, "WM_DELETE_WINDOW", False); ATOM_WM_NAME = XInternAtom (CDisplay, "WM_NAME", False); ATOM_WM_TAKE_FOCUS = XInternAtom (CDisplay, "WM_TAKE_FOCUS", False);}#ifdef GUESS_VISUALchar visual_name[16][16];void make_visual_list (void){ memset (visual_name, 0, sizeof (visual_name)); strcpy (visual_name[StaticGray], "StaticGray"); strcpy (visual_name[GrayScale], "GrayScale"); strcpy (visual_name[StaticColor], "StaticColor"); strcpy (visual_name[PseudoColor], "PseudoColor"); strcpy (visual_name[TrueColor], "TrueColor"); strcpy (visual_name[DirectColor], "DirectColor");}struct visual_priority { int class; int depth_low; int depth_high;} visual_priority[] = { { TrueColor, 15, 16 }, { TrueColor, 12, 14 }, { PseudoColor, 6, 999 }, { DirectColor, 12, 999 }, { TrueColor, 17, 999 }, { DirectColor, 8, 11 }, { TrueColor, 8, 11 }, { StaticColor, 8, 999 }, { PseudoColor, 4, 5 }, { DirectColor, 6, 7 }, { TrueColor, 6, 7 }, { StaticColor, 6, 7 }, { DirectColor, 4, 5 }, { TrueColor, 4, 5 }, { StaticColor, 4, 5 }, { GrayScale, 6, 999 }, { StaticGray, 6, 999 }, { GrayScale, 4, 5 }, { StaticGray, 4, 5 },};#endifchar *option_preferred_visual = 0;int option_force_own_colormap = 0;int option_force_default_colormap = 0;void get_preferred (XVisualInfo * v, int n, Visual ** vis, int *depth){#ifndef GUESS_VISUAL *vis = DefaultVisual (CDisplay, DefaultScreen (CDisplay)); *depth = DefaultDepth (CDisplay, DefaultScreen (CDisplay));#else int i, j; Visual *def = 0; int def_depth = 0; if (option_preferred_visual) if (!*option_preferred_visual) option_preferred_visual = 0;/* NLS ? */ if (option_preferred_visual) if (!strcasecmp (option_preferred_visual, "help") || !strcasecmp (option_preferred_visual, "h")) { printf (_ ("%s:\n The <visual-class> is the hardware technique used by the\n" \ "computer to draw pixels to the screen. _Usually_ only one\n" \ "visual is truly supported. This option is provided\n" \ "if you would rather use a TrueColor than a PseudoColor\n" \ "visual where you are short of color palette space.\n" \ "The depth is the number of bits per pixel used by the hardware.\n" \ "It is automatically selected using heuristics.\n"), \ CAppName); printf (_ ("Available visuals on this system are:\n")); for (i = 0; i < n; i++) printf (" class %s, depth %d\n", visual_name[v[i].class], v[i].depth); exit (1); } if (option_preferred_visual) { /* first check if the user wants the default visual */ int default_name; default_name = ClassOfVisual (DefaultVisual (CDisplay, DefaultScreen (CDisplay))); if (visual_name[default_name]) if (!strcasecmp (visual_name[default_name], option_preferred_visual)) { *vis = DefaultVisual (CDisplay, DefaultScreen (CDisplay)); *depth = DefaultDepth (CDisplay, DefaultScreen (CDisplay)); return; } } for (j = 0; j < sizeof (visual_priority) / sizeof (struct visual_priority); j++) for (i = 0; i < n; i++) if (v[i].class == visual_priority[j].class) if (v[i].depth >= visual_priority[j].depth_low && v[i].depth <= visual_priority[j].depth_high) { if (option_preferred_visual) { if (!strcasecmp (visual_name[v[i].class], option_preferred_visual)) { *vis = v[i].visual; *depth = v[i].depth; return; } } if (!def) { def = v[i].visual; def_depth = v[i].depth; } } if (option_preferred_visual)/* We will select a visual in place of the one you specified, since yours is unavailable */ fprintf (stderr, _ ("%s: preferred visual not found, selecting...\n"), CAppName); if (def) { *vis = def; *depth = def_depth; } else {/* We will select the default visual, since the list didn't have a matching visual */ fprintf (stderr, _ ("%s: no known visuals found, using default...\n"), CAppName); *vis = DefaultVisual (CDisplay, DefaultScreen (CDisplay)); *depth = DefaultDepth (CDisplay, DefaultScreen (CDisplay)); } option_preferred_visual = 0;#endif}static void get_preferred_visual_and_depth (void){ XVisualInfo *v, t; int n;#ifdef GUESS_VISUAL make_visual_list ();#endif t.screen = DefaultScreen (CDisplay); v = XGetVisualInfo (CDisplay, VisualScreenMask, &t, &n); get_preferred (v, n, &CVisual, &CDepth);}static void assign_default_cmap (void){ if (verbose_operation) printf (_ ("Using DefaultColormap()\n")); CColormap = DefaultColormap (CDisplay, DefaultScreen (CDisplay));}static void assign_own_cmap (void){ if (verbose_operation) printf (_ ("Creating own colormap\n")); CColormap = XCreateColormap (CDisplay, RootWindow (CDisplay, DefaultScreen (CDisplay)), CVisual, AllocNone);}static void assign_check_colormap (void){#if 0 /* What do I do here ? */ switch (ClassOfVisual (CVisual)) { case PseudoColor: case GrayScale: case DirectColor: assign_default_cmap (); return; }#endif assign_own_cmap ();}/* #define TRY_WM_COLORMAP 1 */#define COLORMAP_PROPERTY "RGB_DEFAULT_MAP"static void get_colormap (void){#ifdef TRY_WM_COLORMAP Atom DEFAULT_CMAPS;#endif if (option_force_default_colormap) { assign_default_cmap (); return; } if (option_force_own_colormap) { assign_own_cmap (); return; } if (XVisualIDFromVisual (CVisual) == XVisualIDFromVisual (DefaultVisual (CDisplay, DefaultScreen (CDisplay)))) { if (verbose_operation) printf (_ ("Default visual ID found\n")); assign_default_cmap (); return; }#ifdef TRY_WM_COLORMAP/* NLS ? */ if (verbose_operation) printf ("I don't really know what I'm doing here, so feel free to help - paul\n"); DEFAULT_CMAPS = XInternAtom (CDisplay, COLORMAP_PROPERTY, True); if (DEFAULT_CMAPS == None) { if (verbose_operation)/* "An Atom of name %s could not be found". 'Atom' is X terminology */ printf (_ ("No Atom %s \n"), COLORMAP_PROPERTY); assign_check_colormap (); return; } else { int i, n; XStandardColormap *cmap; if (!XGetRGBColormaps (CDisplay, CRoot, &cmap, &n, DEFAULT_CMAPS)) { if (verbose_operation) printf (_ ("XGetRGBColormaps(%s) failed\n"), COLORMAP_PROPERTY); assign_check_colormap (); return; } if (verbose_operation) printf (_ ("Choosing from %d 'XGetRGBColormaps' colormaps\n"), n); for (i = 0; i < n; i++) { if (XVisualIDFromVisual (CVisual) == cmap[i].visualid) { if (verbose_operation) printf (_ ("Colormap %d matches visual ID\n"), i); CColormap = cmap[i].colormap; return; } } if (verbose_operation) printf (_ ("No colormap found matching our visual ID\n")); }#endif assign_check_colormap ();}int ignore_handler (Display * c, XErrorEvent * e){ return 0;}void init_cursors (void);/*-------------------------------------------------------------*/void CInitialise (CInitData * config_start){ if (!config_start->look) config_start->look = init_look; if (!strncmp (config_start->look, "gtk", 3)) { look = &look_gtk; } else if (!strncmp (config_start->look, "next", 4)) {#ifdef NEXT_LOOK look = &look_next;#else fprintf (stderr, _ ("%s: NeXT look was not compiled into this binary\n"), config_start->name); exit (1);#endif } else if (!strncmp (config_start->look, "cool", 4)) { look = &look_cool; } else { look = &look_gtk; } option_interwidget_spacing = (*look->get_default_interwidget_spacing) (); init_widget_font = (*look->get_default_widget_font) (); given = config_start; verbose_operation = (given->options & CINIT_OPTION_VERBOSE); if (verbose_operation) printf ("sizeof(CWidget) = %d\n", (int) sizeof (CWidget)); CAppName = given->name; option_using_grey_scale = (given->options & CINIT_OPTION_USE_GREY);/* Initialise the widget library */ init_widgets ();/* get home dir directory into home_dir and current directory into current_dir */ get_dir ();/* Get resources from the resource file */ get_resources (); if (given->display) init_display = given->display; if (given->geometry) init_geometry = given->geometry; if (given->font) init_font = given->font; if (given->widget_font) init_widget_font = given->widget_font; if (given->bg) init_bg_color = given->bg; if (given->fg_red) init_fg_color_red = given->fg_red; if (given->fg_green) init_fg_color_green = given->fg_green; if (given->fg_blue) init_fg_color_blue = given->fg_blue;/* Open connection to display selected by user */ open_display (CAppName, given->options & CINIT_OPTION_WAIT_FOR_DISPLAY); XSetErrorHandler (ignore_handler);/* Initialise window manager atoms to detect a user close */ wm_interaction_init ();/* Now set up the visual and colors */ get_preferred_visual_and_depth (); if (verbose_operation) { printf (_ ("Found a visual, depth = %d,\n visual class = "), CDepth); visual_comments (ClassOfVisual (CVisual)); } get_colormap ();/* Now setup that color map discribed above */ setup_colormap (ClassOfVisual (CVisual));/* Set up font */ load_font ();#ifdef USE_XIM/* set the XIM locale */ init_xlocale ();#endif/* some special cursors */ init_cursors ();#ifdef HAVE_DND/* Initialise drag and drop capabilities cursius dnd protocol version 1 */ initialise_drag_n_drop ();#else/* Initialise drag and drop capabilities xdnd protocol */ xdnd_init (CDndClass, CDisplay); mouse_init ();#endif XAaInit (CDisplay, CVisual, CDepth, CRoot);/* set child handler */ set_child_handler ();/* an alarm handler generates xevent of tyoe AlarmEvent every 1/4 second to flash the cursor */ set_alarm ();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -