📄 config.c
字号:
/* GKrellM| Copyright (C) 1999-2006 Bill Wilson|| Author: Bill Wilson billw@gkrellm.net| Latest versions might be found at: http://gkrellm.net|| This program is free software which I release under the GNU General Public| License. You may redistribute and/or modify this program under the terms| of that license as published by the Free Software Foundation; either| version 2 of the License, or (at your option) any later version.|| This program 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 General Public License for more details. Version 2 is in the| COPYRIGHT file in the top level directory of this distribution.| | To get a copy of the GNU General Puplic License, write to the Free Software| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/#include "gkrellm.h"#include "gkrellm-private.h"#if !defined(WIN32)#include <unistd.h> /* needed for gethostname() */#else#include <winsock2.h> /* needed for gethostname() */#endif#include "pixmaps/frame_top.xpm"#include "pixmaps/frame_bottom.xpm"#include "pixmaps/frame_left.xpm"#include "pixmaps/frame_right.xpm"#include "pixmaps/button_panel_out.xpm"#include "pixmaps/button_panel_in.xpm"#include "pixmaps/button_meter_out.xpm"#include "pixmaps/button_meter_in.xpm"#include "pixmaps/bg_chart.xpm"#include "pixmaps/bg_grid.xpm"#include "pixmaps/bg_panel.xpm"#include "pixmaps/bg_separator.xpm"#include "pixmaps/bg_meter.xpm"#include "pixmaps/decal_alarm.xpm"#include "pixmaps/decal_warn.xpm"//#include "pixmaps/krell_alarm.xpm"//#include "pixmaps/krell_warn.xpm" /* These data images are used only for the default theme */#include "pixmaps/data_in.xpm"#include "pixmaps/data_in_grid.xpm"#include "pixmaps/data_out.xpm"#include "pixmaps/data_out_grid.xpm"#include "pixmaps/decal_misc.xpm"#include "pixmaps/decal_button.xpm"#include "pixmaps/krell_panel.xpm"#include "pixmaps/krell_meter.xpm"#include "pixmaps/krell_slider.xpm"#include "pixmaps/krell_mini.xpm" /* Theme images for builtin monitors. */#include "pixmaps/cal/bg_panel.xpm"#include "pixmaps/clock/bg_panel.xpm"#include "pixmaps/cpu/nice.xpm"#include "pixmaps/cpu/nice_grid.xpm"#include "pixmaps/fs/bg_panel.xpm"#include "pixmaps/fs/bg_panel_1.xpm"#include "pixmaps/fs/bg_panel_2.xpm"#include "pixmaps/fs/spacer_top.xpm"#include "pixmaps/fs/spacer_bottom.xpm"#include "pixmaps/host/bg_panel.xpm"#ifdef BSD#include "pixmaps/mail/krell_mail_daemon.xpm"#else#include "pixmaps/mail/krell_mail.xpm"#endif#include "pixmaps/mem/bg_panel.xpm"#include "pixmaps/mem/krell.xpm"#include "pixmaps/sensors/bg_panel.xpm"#include "pixmaps/sensors/bg_panel_1.xpm"#include "pixmaps/sensors/bg_panel_2.xpm"#include "pixmaps/swap/bg_panel.xpm"#include "pixmaps/swap/krell.xpm"#include "pixmaps/uptime/bg_panel.xpm"#include "pixmaps/timer/bg_panel.xpm" /* Default theme images for various plugins */#include "pixmaps/gkrellmms/krell.xpm"#include "pixmaps/gkrellmms/bg_scroll.xpm"#include "pixmaps/gkrellmms/bg_panel.xpm"#include "pixmaps/gkrellmms/bg_panel_1.xpm"#include "pixmaps/gkrellmms/bg_panel_2.xpm"#include "pixmaps/gkrellmms/spacer_top.xpm"#include "pixmaps/gkrellmms/spacer_bottom.xpm"#include "pixmaps/gkrellmms/play_button.xpm"#include "pixmaps/gkrellmms/prev_button.xpm"#include "pixmaps/gkrellmms/stop_button.xpm"#include "pixmaps/gkrellmms/next_button.xpm"#include "pixmaps/gkrellmms/eject_button.xpm"#include "pixmaps/gkrellmms/led_indicator.xpm"#include "pixmaps/timers/bg_panel.xpm"#include "pixmaps/timers/bg_panel_1.xpm"#include "pixmaps/timers/bg_panel_2.xpm"#include "pixmaps/timers/spacer_top.xpm"#include "pixmaps/timers/spacer_bottom.xpm"#include "pixmaps/volume/bg_panel.xpm"#include "pixmaps/volume/bg_panel_1.xpm"#include "pixmaps/volume/bg_panel_2.xpm"#include "pixmaps/volume/spacer_top.xpm"#include "pixmaps/volume/spacer_bottom.xpm"#include "pixmaps/pmu/bg_panel.xpm"#include "pixmaps/pmu/bg_panel_1.xpm"#include "pixmaps/pmu/bg_panel_2.xpm"#include "pixmaps/pmu/spacer_top.xpm"#include "pixmaps/pmu/spacer_bottom.xpm"#define SET_ALL_MARGINS 0x1000000#define OLD_SET_MARGIN 0x2000000static gchar *image_type[] = { ".png", ".jpg", ".xpm", ".gif" };gchar *gkrellm_theme_file_exists(char *name, gchar *subdir) { gint i; static gchar *path; struct stat st; if (gkrellm_using_default_theme()) return NULL; if (path) g_free(path); if (_GK.theme_alternative > 0) { for (i = 0; i < sizeof(image_type) / sizeof(char *); ++i) { if (subdir) path = g_strdup_printf("%s/%s/%s_%d%s", _GK.theme_path, subdir, name, _GK.theme_alternative, image_type[i]); else path = g_strdup_printf("%s/%s_%d%s", _GK.theme_path, name, _GK.theme_alternative, image_type[i]); if ( stat(path, &st) == 0 && (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) ) return path; g_free(path); path = NULL; } } for (i = 0; i < sizeof(image_type) / sizeof(char *); ++i) { if (subdir) path = g_strdup_printf("%s/%s/%s%s", _GK.theme_path, subdir, name, image_type[i]); else path = g_strdup_printf("%s/%s%s", _GK.theme_path, name, image_type[i]); if ( stat(path, &st) == 0 && (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) ) return path; g_free(path); path = NULL; } return NULL; }static voidset_border(GkrellmBorder *border, char *string) { if (!border) return; border->left = 0; border->right = 0; border->top = 0; border->bottom = 0; if (string == NULL) return; sscanf(string, "%d,%d,%d,%d", &border->left, &border->right, &border->top, &border->bottom); }static voidset_margins(GkrellmStyle *style, char *string) { GkrellmMargin *m; _GK.use_top_bottom_margins = TRUE; if (!style) return; m = &style->margin; m->left = 0; m->right = 0; m->top = 0; m->bottom = 0; if (string == NULL) return; sscanf(string, "%d,%d,%d,%d", &m->left, &m->right, &m->top, &m->bottom); m->left = m->left * _GK.theme_scale / 100; m->right = m->right * _GK.theme_scale / 100; m->top = m->top * _GK.theme_scale / 100; m->bottom = m->bottom * _GK.theme_scale / 100; }static voidassign_font(GkrellmStyle *style, gchar *fontname, gint AorB) { GkrellmTextstyle *ts; ts = (AorB == GKRELLMSTYLE_TEXTFONT_A) ? &style->label_tsA : &style->label_tsB; if (strcmp(fontname, "large_font") == 0) ts->font_seed = &_GK.large_font; else if (strcmp(fontname, "normal_font") == 0) ts->font_seed = &_GK.normal_font; else if (strcmp(fontname, "small_font") == 0) ts->font_seed = &_GK.small_font; }static voidassign_textcolor(GkrellmStyle *style, gchar *arg, gint AorB) { GkrellmTextstyle *ts; gchar *values, *s; gchar *color, *shadowcolor, *effect; values = g_strconcat(arg, NULL); color = gkrellm_cut_quoted_string(values, &s); shadowcolor = gkrellm_cut_quoted_string(s, &s); effect = gkrellm_cut_quoted_string(s, &s); if (*color == '\0' || *shadowcolor == '\0' || *effect == '\0') { printf(_("Bad textcolor line %s\n"), arg); g_free(values); return; } ts = (AorB == GKRELLMSTYLE_TEXTCOLOR_A) ? &style->label_tsA : &style->label_tsB; gkrellm_map_color_string(color, &(ts->color)); gkrellm_map_color_string(shadowcolor, &(ts->shadow_color)); ts->effect = gkrellm_effect_string_value(effect); g_free(values); }gbooleangkrellm_style_is_themed(GkrellmStyle *style, gint query) { if (query == 0) query = ~0; return (style->themed & query) ? TRUE : FALSE; }voidgkrellm_set_style_krell_values(GkrellmStyle *s, gint yoff, gint depth, gint x_hot, gint expand, gint ema, gint left_margin, gint right_margin) { if (!s) return; if (yoff >= -3) { s->krell_yoff = yoff; if (yoff > 0) s->krell_yoff_not_scalable = TRUE; } if (left_margin >= 0) s->krell_left_margin = left_margin; if (right_margin >= 0) s->krell_right_margin = right_margin; if (depth > 0) s->krell_depth = depth; if (x_hot >= -1) s->krell_x_hot = x_hot; if (expand >= 0) s->krell_expand = expand; if (ema > 0) s->krell_ema_period = ema; }voidgkrellm_set_style_krell_values_default(GkrellmStyle *s, gint yoff, gint depth, gint x_hot, gint expand, gint ema, gint left_margin, gint right_margin) { if (!s) return; if (yoff >= -3 && !(s->themed & GKRELLMSTYLE_KRELL_YOFF)) { s->krell_yoff = yoff; if (yoff > 0) s->krell_yoff_not_scalable = TRUE; } if (left_margin >= 0 && !(s->themed & GKRELLMSTYLE_KRELL_LEFT_MARGIN)) s->krell_left_margin = left_margin; if (right_margin >= 0 && !(s->themed & GKRELLMSTYLE_KRELL_RIGHT_MARGIN)) s->krell_right_margin = right_margin; if (depth > 0 && !(s->themed & GKRELLMSTYLE_KRELL_DEPTH)) s->krell_depth = depth; if (x_hot >= -1 && !(s->themed & GKRELLMSTYLE_KRELL_X_HOT)) s->krell_x_hot = x_hot; if (expand >= 0 && !(s->themed & GKRELLMSTYLE_KRELL_EXPAND)) s->krell_expand = expand; if (ema > 0 && !(s->themed & GKRELLMSTYLE_KRELL_EMA_PERIOD)) s->krell_ema_period = ema; }voidgkrellm_set_style_slider_values_default(GkrellmStyle *s, gint yoff, gint left_margin, gint right_margin) { gint themed, y, left, right; if (!s) return; themed = s->themed; y = s->krell_yoff; left = s->krell_left_margin; right = s->krell_right_margin; gkrellm_copy_style_values(s, _GK.krell_slider_style); s->themed = themed; s->krell_yoff = y; s->krell_left_margin = left; s->krell_right_margin = right; if (yoff >= - 3 && !(s->themed & GKRELLMSTYLE_KRELL_YOFF)) { s->krell_yoff = yoff; if (yoff > 0) s->krell_yoff_not_scalable = TRUE; } if (left_margin >= 0 && !(s->themed & GKRELLMSTYLE_KRELL_LEFT_MARGIN)) s->krell_left_margin = left_margin; if (right_margin >= 0 && !(s->themed & GKRELLMSTYLE_KRELL_RIGHT_MARGIN)) s->krell_right_margin = right_margin; }voidgkrellm_set_krell_expand(GkrellmStyle *style, gchar *value) { gint expand = KRELL_EXPAND_NONE; if (!style) return; if (value) { if (!strcmp(value, "left")) expand = KRELL_EXPAND_LEFT; else if (!strcmp(value, "left-scaled")) expand = KRELL_EXPAND_LEFT_SCALED; else if (!strcmp(value, "right")) expand = KRELL_EXPAND_RIGHT; else if (!strcmp(value, "right-scaled")) expand = KRELL_EXPAND_RIGHT_SCALED; else if (!strcmp(value, "bar-mode")) expand = KRELL_EXPAND_BAR_MODE; else if (!strcmp(value, "bar-mode-scaled")) expand = KRELL_EXPAND_BAR_MODE_SCALED; } style->krell_expand = expand; }static gbooleanparse_boolean(gchar *value) { if ( !strcmp("1", value) || !strcasecmp("true", value) || !strcasecmp("on", value) || !strcasecmp("yes", value) ) return TRUE; return FALSE; }static voidassign_style_entry(GkrellmStyle *style, gchar *value, gint entry_flag) { if (entry_flag == GKRELLMSTYLE_KRELL_YOFF) style->krell_yoff = atoi(value); else if (entry_flag == GKRELLMSTYLE_KRELL_YOFF_NOT_SCALABLE) style->krell_yoff_not_scalable = parse_boolean(value); else if (entry_flag == GKRELLMSTYLE_KRELL_EXPAND) gkrellm_set_krell_expand(style, value); else if (entry_flag == GKRELLMSTYLE_KRELL_X_HOT) style->krell_x_hot = atoi(value); else if (entry_flag == GKRELLMSTYLE_KRELL_EMA_PERIOD) style->krell_ema_period = atoi(value); else if (entry_flag == GKRELLMSTYLE_KRELL_DEPTH) style->krell_depth = atoi(value); else if (entry_flag == GKRELLMSTYLE_KRELL_LEFT_MARGIN) style->krell_left_margin = atoi(value); else if (entry_flag == GKRELLMSTYLE_KRELL_RIGHT_MARGIN) style->krell_right_margin = atoi(value); else if (entry_flag == GKRELLMSTYLE_LABEL_POSITION) { if (strcmp(value, "center") == 0) style->label_position = GKRELLM_LABEL_CENTER; else if (isdigit(*value)) style->label_position = atoi(value); else style->label_position = GKRELLM_LABEL_NONE; } else if (entry_flag == GKRELLMSTYLE_LABEL_YOFF) style->label_yoff = atoi(value) * _GK.theme_scale / 100; else if (entry_flag == OLD_SET_MARGIN) /* Deprecated as of 1.2.9 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -