📄 main.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"#include "gkrellm-sysdeps.h"#if GTK_CHECK_VERSION(2,4,0)#include "icon.xpm"#endif#include <signal.h>struct GkrellmConfig _GK;GkrellmTicks GK;struct { GtkWidget *window; /* Top level window */ GtkWidget *vbox; GtkWidget *top0_event_box; /* Top frame event box */ GtkWidget *top0_vbox; /* Top frame */ GtkWidget *middle_hbox; GtkWidget *left_event_box; /* Holds left vbox. */ GtkWidget *left_vbox; /* Holds left frame. */ GtkWidget *middle_vbox; /* A handle for sliding shut */ GtkWidget *monitor_vbox; /* All monitors go in here. */ GtkWidget *top1_event_box; /* First event box */ GtkWidget *top1_vbox; /* hostname */ GtkWidget *right_event_box; /* Holds right vbox. */ GtkWidget *right_vbox; /* Holds right frame. */ GtkWidget *bottom_vbox; /* Bottom frame */ GdkPixmap *frame_left_pixmap; GdkBitmap *frame_left_mask; GdkPixmap *frame_right_pixmap; GdkBitmap *frame_right_mask; GdkPixmap *frame_top_pixmap; GdkBitmap *frame_top_mask; GdkPixmap *frame_bottom_pixmap; GdkBitmap *frame_bottom_mask; GdkPixmap *window_transparency_mask; } gtree;static GtkWidget *top_window;GList *gkrellm_monitor_list;time_t gkrellm_time_now;static GtkItemFactory *item_factory;static gchar *geometry;static gint y_pack;static gint monitor_previous_height;static gint monitors_visible = TRUE;static gint mask_monitors_visible = TRUE;static gint check_rootpixmap_transparency;static gboolean no_transparency, do_intro, decorated, configure_position_lock;static void apply_frame_transparency(gboolean force);#define N_FALLBACK_FONTS 3static gchar *fail_large_font[N_FALLBACK_FONTS] ={"Serif 10","Ariel 10","fixed"};static gchar *fail_normal_font[N_FALLBACK_FONTS] ={"Serif 9","Ariel 9","fixed"};static gchar *fail_small_font[N_FALLBACK_FONTS] ={"Serif 8","Ariel 8","fixed"};static gchar *intro_msg =N_( "You can configure your monitors by right clicking on\n" "the top frame of GKrellM or by hitting the F1 key\n" "with the mouse in the GKrellM window.\n\n" "Read the Info pages in the config for setup help.");static voidload_font(gchar *font_string, PangoFontDescription **gk_font, gchar **fallback_fonts) { PangoFontDescription *font_desc = NULL; gint i; if (font_string) font_desc = pango_font_description_from_string(font_string); if (_GK.debug_level & DEBUG_GUI) printf("load_font: %s %p\n", font_string, font_desc); if (!font_desc) { for (i = 0; !font_desc && i < N_FALLBACK_FONTS; ++i) { font_desc = pango_font_description_from_string(fallback_fonts[i]); if (_GK.debug_level & DEBUG_GUI) printf("load_font trying fallback: %s\n", fallback_fonts[i]); } } if (*gk_font) pango_font_description_free(*gk_font); *gk_font = font_desc; }static voidsetup_fonts() { load_font(_GK.large_font_string, &_GK.large_font, fail_large_font); load_font(_GK.normal_font_string, &_GK.normal_font, fail_normal_font); load_font(_GK.small_font_string, &_GK.small_font, fail_small_font); if (!_GK.large_font || !_GK.normal_font || !_GK.small_font) { g_print(_("Error: Could not load all fonts.\n")); exit(0); } _GK.font_load_count += 1; }voidgkrellm_map_color_string(gchar *color_string, GdkColor *color) { static GdkColormap *colormap; if (colormap == NULL) colormap = gtk_widget_get_colormap(top_window); if (color->red || color->green || color->blue) gdk_colormap_free_colors(colormap, color, 1); if (!color_string) color_string = "black"; gdk_color_parse(color_string, color); gdk_colormap_alloc_color(colormap, color, FALSE, TRUE); }static voidsetup_colors() { GtkWidget *win = top_window; gkrellm_map_color_string(_GK.chart_in_color, &_GK.in_color); gkrellm_map_color_string(_GK.chart_in_color_grid, &_GK.in_color_grid); gkrellm_map_color_string(_GK.chart_out_color, &_GK.out_color); gkrellm_map_color_string(_GK.chart_out_color_grid, &_GK.out_color_grid); gkrellm_map_color_string("#000000", &_GK.background_color); gkrellm_map_color_string("#FFFFFF", &_GK.white_color); if (_GK.draw1_GC == NULL) { _GK.draw1_GC = gdk_gc_new( win->window ); gdk_gc_copy( _GK.draw1_GC, win->style->white_gc ); } if (_GK.draw2_GC == NULL) { _GK.draw2_GC = gdk_gc_new( win->window ); gdk_gc_copy( _GK.draw2_GC, win->style->white_gc ); } if (_GK.draw3_GC == NULL) { _GK.draw3_GC = gdk_gc_new( win->window ); gdk_gc_copy( _GK.draw3_GC, win->style->white_gc ); } if (_GK.draw_stencil_GC == NULL) { _GK.draw_stencil_GC = gdk_gc_new( win->window ); gdk_gc_copy(_GK.draw_stencil_GC, win->style->white_gc ); } if (_GK.text_GC == NULL) { _GK.text_GC = gdk_gc_new( win->window ); gdk_gc_copy( _GK.text_GC, win->style->white_gc ); } /* Set up the depth 1 GCs */ /* printf("white pixel = %ld\n", _GK.white_color.pixel); */ if (_GK.bit1_GC == NULL) { GdkBitmap *dummy_bitmap; GdkColor bit_color; dummy_bitmap = gdk_pixmap_new(top_window->window, 16, 16, 1); _GK.bit1_GC = gdk_gc_new(dummy_bitmap); _GK.bit0_GC = gdk_gc_new(dummy_bitmap); bit_color.pixel = 1; gdk_gc_set_foreground(_GK.bit1_GC, &bit_color); bit_color.pixel = 0; gdk_gc_set_foreground(_GK.bit0_GC, &bit_color); g_object_unref(G_OBJECT(dummy_bitmap)); } }static gint save_position_countdown;static voidset_or_save_position(gint save) { FILE *f; gchar *path; gint x, y; static gint x_last = -1, y_last = -1; path = gkrellm_make_data_file_name(NULL, "startup_position"); if (save) { if (!configure_position_lock && y_pack < 0) { /* Most recent configure event may have happened before | gkrellm has removed it's lock, so get gdk's cached values. | Eg. gkrellm is moved < 2 sec after startup by the window | manager. See cb_configure_notify(). | But don't update _GK.y_position if current gkrellm position | reflects a packed move (ie, not a user set position). */ gdk_window_get_position(top_window->window, &_GK.x_position, &_GK.y_position); } if ( (_GK.x_position != x_last || _GK.y_position != y_last) && (f = fopen(path, "w")) != NULL ) { x_last = _GK.x_position; y_last = _GK.y_position; fprintf(f, "%d %d\n", _GK.x_position, _GK.y_position); fclose(f); if (_GK.debug_level & DEBUG_POSITION) printf("save_position: %d %d\n", x_last, y_last); } save_position_countdown = 0; } else if (!_GK.withdrawn) /* In slit conflicts with setting position */ { if ((f = fopen(path, "r")) != NULL) { x = y = 0; fscanf(f, "%d %d", &x, &y); fclose(f); if ( x >= 0 && x < _GK.w_display - 10 && y >= 0 && y < _GK.h_display - 25 ) { _GK.x_position = x_last = x; _GK.y_position = y_last = y; _GK.position_valid = TRUE; gdk_window_move(gtree.window->window, x, y); if (_GK.debug_level & DEBUG_POSITION) printf("startup_position moveto %d %d (valid)\n", x, y); } } } g_free(path); }static gintupdate_monitors() { GList *list; GkrellmMonitor *mon; struct tm *pCur, *pPrev; static time_t time_prev; time(&_GK.time_now); GK.second_tick = (_GK.time_now == time_prev) ? FALSE : TRUE; time_prev = _GK.time_now; if (GK.second_tick) { pPrev = &gkrellm_current_tm; pCur = localtime(&_GK.time_now); GK.two_second_tick = ((pCur->tm_sec % 2) == 0) ? TRUE : FALSE; GK.five_second_tick = ((pCur->tm_sec % 5) == 0) ? TRUE : FALSE; GK.ten_second_tick = ((pCur->tm_sec % 10) == 0) ? TRUE : FALSE; GK.minute_tick = (pCur->tm_min != pPrev->tm_min) ? TRUE : FALSE; GK.hour_tick = (pCur->tm_hour != pPrev->tm_hour) ? TRUE : FALSE; GK.day_tick = (pCur->tm_mday != pPrev->tm_mday) ? TRUE : FALSE; /* Copy localtime() data to my global struct tm data so clock (or | anybody) has access to current struct tm data. Must copy so | data is not munged by plugins which might call localtime(). */ gkrellm_current_tm = *pCur; } else { GK.two_second_tick = FALSE; GK.five_second_tick = FALSE; GK.ten_second_tick = FALSE; GK.minute_tick = FALSE; GK.hour_tick = FALSE; GK.day_tick = FALSE; } gkrellm_alert_update(); for (list = gkrellm_monitor_list; list; list = list->next) { mon = (GkrellmMonitor *) list->data; gkrellm_record_state(UPDATE_MONITOR, mon); if (mon->update_monitor && mon->privat->enabled) (*(mon->update_monitor))(); } gkrellm_record_state(INTERNAL, NULL); ++GK.timer_ticks; if (save_position_countdown > 0 && --save_position_countdown == 0) set_or_save_position(1); if (configure_position_lock && (GK.timer_ticks / _GK.update_HZ) > 1) configure_position_lock = FALSE; /* Update if background has changed */ if ( GK.second_tick && !no_transparency && gkrellm_winop_updated_background() && check_rootpixmap_transparency == 0 ) check_rootpixmap_transparency = 1; if (_GK.need_frame_packing) { gkrellm_pack_side_frames(); apply_frame_transparency(TRUE); if (!no_transparency) gkrellm_winop_apply_rootpixmap_transparency(); check_rootpixmap_transparency = 0; } if (check_rootpixmap_transparency > 0) if (--check_rootpixmap_transparency == 0 && !no_transparency) gkrellm_winop_apply_rootpixmap_transparency(); if ( GK.minute_tick && _GK.config_modified && !gkrellm_config_window_shown() ) gkrellm_save_user_config(); return TRUE; /* restarts timeout */ }voidgkrellm_start_timer(gint Hz) { static gint timeout_id = 0; gint interval; if (timeout_id) gtk_timeout_remove(timeout_id); timeout_id = 0; if (Hz > 0) { interval = 1000 / Hz; interval = interval * 60 / 63; /* Compensate for overhead XXX */ timeout_id = gtk_timeout_add(interval, (GtkFunction) update_monitors,NULL); } }GtkWidget *gkrellm_get_top_window() { return top_window; }GkrellmTicks *gkrellm_ticks(void) { return &GK; }gintgkrellm_get_timer_ticks(void) { return GK.timer_ticks; } /* Nice set of effects I have here... Either shadow effect or none. | Returning 1 means shadow effect and the return value is also used by | callers to increment height fields to allow for the offset shadow draw. */gintgkrellm_effect_string_value(gchar *effect_string) { if (effect_string) return (strcmp(effect_string, "shadow") == 0) ? 1 : 0; return 0; } /* Before 1.0.3 text, decals, krells used top/bottom borders for placement. | This is to allow themes to transition to using top/bottom_margin. */voidgkrellm_get_top_bottom_margins(GkrellmStyle *style, gint *top, gint *bottom) { gint t = 0, b = 0; if (style) { if ( _GK.use_top_bottom_margins /* XXX */ || g_list_find(_GK.chart_style_list, style)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -