📄 config.hpp
字号:
strcmp (value, "windowmaker") == 0 || strcmp (value, "workspaces") == 0) { __use_workspaces = 1; __use_ewmh = 0; } else if (strcmp (value, "fluxbox") == 0) { __use_ewmh = 1; __early_desktop_switch = 0; } else { return 1; } } else if (strcmp(option, "nozoom") == 0) { entry_exit_movement = !get_boolean (value); } else if (strcmp(option, "zoom") == 0) { entry_exit_movement = get_boolean (value); } else if (strcmp(option, "gotocolumn") == 0) { if (!value) return 1; goto_column = atoi(value); if (goto_column < 1) return 1; } else if (strcmp(option, "gotorow") == 0) { if (!value) return 1; goto_row = atoi(value); if (goto_row < 1) return 1; } else if (strcmp(option, "gotoright") == 0) { goto_column = GOTO_FACE_RIGHT; } else if (strcmp(option, "gotoleft") == 0) { goto_column = GOTO_FACE_LEFT; } else if (strcmp(option, "gotoup") == 0) { goto_row = GOTO_FACE_UP; } else if (strcmp(option, "gotodown") == 0) { goto_row = GOTO_FACE_DOWN; } else if (strcmp(option, "verbose") == 0) { __verbose = get_boolean (value); } else if (strcmp(option, "early_desktop_switch") == 0) { __early_desktop_switch = get_boolean (value); } else if (strcmp(option, "disable_keys_in_goto") == 0) { __disable_keys_in_goto = get_boolean (value); } return 0; // success }; void init_from_command_line (int argc, char **argv) { int c; int option_index; // these are cmd line options to the daemon static struct option long_options[] = { //{"fps", 0, 0, 0}, {"dir", 1, 0, 0}, {"workspaces", 0, 0, 0}, {"texturesize", 1, 0, 0}, {"fastest", 0, 0, 0}, {"win", 0, 0, 0}, {"sawfish", 0, 0, 0}, {"acquire", 2, 0, 0}, {"wm", 1, 0, 0}, {"kde", 0, 0, 0}, {"gnome2", 0, 0, 0}, {"ewmh", 0, 0, 0}, {"kde2", 0, 0, 0}, {"kde3", 0, 0, 0}, {"gnome", 0, 0, 0}, {"gnome1", 0, 0, 0}, {0, 0, 0, 0} }; while (1) { c = getopt_long (argc, argv, "v", long_options, &option_index); if (c == -1) break; switch (c) { case 0: // long option //msgout (DEBUG, "option %s", long_options[option_index].name); if (set_option ((char *)long_options[option_index].name, optarg, 1)) usage_and_bye(); break; case 'v': __verbose = 1; msgout (INFO, "Verbose is ON\n"); break; default: usage_and_bye(); break; } } // end while args };};class Config {private: list <Options *> config_options; Options *cmd_line_options;#if defined(__FreeBSD__) char config_file[MAXNAMLEN + 1];#else char config_file[PATH_MAX];#endif static const int use_tmp = 0;public:#if defined(__FreeBSD__) char working_dir[MAXNAMLEN + 1]; char pidfile[MAXNAMLEN + 1];#else char working_dir[PATH_MAX]; char pidfile[PATH_MAX];#endif int use_kde : 1; int use_ewmh : 1; int sawfish_only : 1; int use_workspaces : 1; int use_viewareas : 1; int early_desktop_switch : 1; int disable_keys_in_goto : 1; int verbose : 1; int texture_size; // ptr to the current option set (either cmd line or a conf "view") Options *options; Config () { strcpy(working_dir, "/tmp/3ddesktop"); pidfile[0] = 0; texture_size = 1024; cmd_line_options = new Options("cmdline"); if (!cmd_line_options) { msgout(ERROR, "out of memory: Config\n"); end_program(-1); } options = cmd_line_options; }; ~Config () { if (pidfile[0]) unlink(pidfile); delete cmd_line_options; list<Options *>::iterator k; for (k = config_options.begin(); k != config_options.end(); k++) delete *k; config_options.clear(); } void sync_global_options (void) { verbose = cmd_line_options->__verbose; texture_size = cmd_line_options->__texture_size; use_kde = cmd_line_options->__use_kde; use_ewmh = cmd_line_options->__use_ewmh; use_workspaces = cmd_line_options->__use_workspaces; use_viewareas = cmd_line_options->__use_viewareas; sawfish_only = cmd_line_options->__sawfish_only; early_desktop_switch = cmd_line_options->__early_desktop_switch; disable_keys_in_goto = cmd_line_options->__disable_keys_in_goto; } void init (int argc, char **argv) { cmd_line_options->init_from_command_line(argc, argv); sync_global_options(); create_working_dir_if_necessary(); }; void set_config_set (char *name) { if (!strcmp(name, "default") || !strcmp(name, "cmdline")) { options = cmd_line_options; return; } list<Options *>::iterator k; for (k = config_options.begin(); k != config_options.end(); k++) { if ( !strcmp ((*k)->name, name) ) { options = *k; msgout (DEBUG, "*** FOUND cfg set %s\n", name); break; } } } void reload () { list<Options *>::iterator k; for (k = config_options.begin(); k != config_options.end(); k++) delete *k; config_options.clear(); options = cmd_line_options; load_conf(); } void load_conf () { // Try opening ~/.3ddesktop/3ddesktop.conf // then /usr/share/3ddesktop/3ddesktop.conf sprintf(config_file, "%s/3ddesktop.conf", working_dir); FILE *fp = fopen(config_file, "r"); if (!fp) { sprintf(config_file, SYSCONFDIR "/3ddesktop.conf"); fp = fopen(config_file, "r"); if (!fp) { // don't error on this - may not be there msgout (DEBUG, "Could not open config file: 3ddesktop.conf: %s\n", strerror(errno)); return; } } msgout (DEBUG, "load_conf: opened %s\n", config_file); char var1[100]; char var2[100]; char var3[100]; char var4[100]; char var5[100]; char buf[1000]; int buf_size = 1000; char *p = NULL; int n, line = 0;; Options *o = NULL; while (fgets (buf, buf_size, fp) ) { line++; //msgout (DEBUG, "config load: line %d read -> %s\n", line, buf); // null terminate at comment p = strpbrk (buf, "#"); if (p) *p = 0; // now see if blank line n = strspn(buf, " \t\n"); if (n == (int)strlen (buf)) continue; n = sscanf(buf, "%s %s %s %s %s", var1, var2, var3, var4, var5); if (n < 2) { msgout (DEBUG, "config load: see %d vars only (line %d)\n", n, line); continue; } // ok something meaningful(less?) in vars //msgout (DEBUG, "config load: line %d found: %s %s\n", line, var1, var2); if (strcmp(var1, "view") == 0) { if (strcmp(var2, "default") == 0) { o = cmd_line_options; } else { o = new Options(var2); if (!o) { msgout (ERROR, "out of memory for Options\n"); end_program(-1); } msgout (DEBUG, "Found view: %s\n", var2); config_options.push_back(o); } continue; } if (!o) { //msgout(DEBUG, "not in a option set\n"); // Treat these as "global" options cmd_line_options->set_option(var1, var2, 0); sync_global_options(); } else { o->set_option(var1, var2, 0); } } fclose (fp); }; void create_working_dir_if_necessary (void) { // first formulat the full path to location char *home_dir = getenv("HOME"); char *username = getenv("USER"); char failsafe[] = "noname"; if (username == NULL) { username = getenv("LOGNAME"); if (username == NULL) { username = getlogin(); if (username == NULL) username = failsafe; } } if (home_dir == NULL || use_tmp) { //msgout (DEBUG, "$HOME not set: using /tmp/.3ddesktop-user\n"); sprintf(working_dir, "/tmp/.3ddesktop-%s", username); } else { sprintf(working_dir, "%s/.3ddesktop", home_dir); } DIR *dir_p = opendir (working_dir); if (dir_p == NULL) { if (errno == ENOENT) { // try to make the dir now //char cmd[100]; //sprintf (cmd, "mkdir %s", working_dir); //system (cmd); if (mkdir (working_dir, S_IRWXU) < 0) { msgout(ERROR, "Could not make directory %s: %s\n", working_dir, strerror(errno)); end_program(1); } } else { msgout(ERROR, "Could not open directory %s: %s\n", working_dir, strerror(errno)); end_program (1); } } else { closedir(dir_p); } }; // END create_working_dir_if_necessary int make_pidfile (void) { pid_t pid; sprintf (pidfile, "%s/pid", working_dir); FILE *fh = fopen (pidfile, "w"); if (fh == NULL) { msgout (ERROR, "Could not open %s: %s\n", pidfile, strerror(errno)); return -1; } pid = getpid(); fprintf (fh, "%d", pid); fclose (fh); return 0; } // END make_pidfile };#endif // _CONFIG_HPP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -