📄 sensors.c
字号:
*/ if (volt_name_width) volt_mon_width = volt_name_width + NAME_PAD + w_volt + b->right; else volt_mon_width = w_volt; /* borders encroach into MONITOR_PAD */ }static voidlayout_volt_decals(GkrellmPanel *p, GkrellmStyle *style) { GList *list; SensorMon *volt; GkrellmDecal *dv, *dn; GkrellmMargin *m; gint x, y, w, c, n, cols; m = gkrellm_get_style_margins(style); w = gkrellm_chart_width() - m->left - m->right; cols = (w + MONITOR_PAD) / (volt_mon_width + MONITOR_PAD); if (cols < 1) cols = 1; n = g_list_length(volt_list); if (cols > n) cols = n;; volt_mon_width = w / cols; /* spread them out */ x = (w - cols * volt_mon_width) / 2 + m->left; gkrellm_get_top_bottom_margins(style, &y, NULL); c = 0; for (list = volt_list; list; list = list->next) { volt = (SensorMon *) list->data; dn = volt->name_decal; dv = volt->sensor_decal; /* Right justify the volt decal in each volt_mon field */ dv->x = x + (c+1) * volt_mon_width - dv->w - bezel_style->border.right; if (cols > 1 && !dn) dv->x -= (volt_mon_width - volt_bezel_width) / 2; dv->y = y + bezel_style->border.top; if (dn) { if (cols == 1) dn->x = m->left; else dn->x = dv->x - volt_name_width - NAME_PAD; dn->y = y + bezel_style->border.top; if (dn->h < dv->h) dn->y += (dv->h - dn->h + 1) / 2; } if (++c >= cols) { c = 0; y += volt_mon_height; } } }static voidupdate_disk_temperatures(void) { GList *list; Sensor *sr; gfloat t; gchar units; gboolean display_failed = FALSE; for (list = disk_temperature_list; list; list = list->next) { sr = (Sensor *) list->data; sensor_read_temperature(sr, &t, &units); if (!gkrellm_disk_temperature_display((gpointer) sr, sr->id_name, t, units)) { /* disk panel was disabled, so put temp back on sensors panel */ display_failed = TRUE; sr->location = SENSOR_PANEL_LOCATION; sensor_reset_optionmenu(sr); } } if (display_failed) gkrellm_sensors_rebuild(TRUE, FALSE, FALSE); } /* Squeeze name decal text into a smaller font if it would overlap the | sensor decal. With smaller fonts, the y_ink value may be smaller which | would bump the text upward. So adjust decal offset by difference in | y_ink value. (GKrellM text decal heights don't include the y_ink | space). */static gchar *name_text_fit(Sensor *s, GkrellmDecal *dn, GkrellmDecal *ds) { gchar *string; gint x_limit, w0, w1, y_ink0, y_ink1, h0, h1; x_limit = ds->x; /* Check for '<' in case user is doing his own markup */ if (*(s->name_locale) != '<' && dn->x + dn->w > x_limit) { gkrellm_text_markup_extents(dn->text_style.font, s->name_locale, strlen(s->name_locale), &w0, NULL, NULL, &y_ink0); string = g_strdup_printf("<small>%s</small>", s->name_locale); gkrellm_text_markup_extents(dn->text_style.font, string, strlen(string), &w1, &h0, NULL, &y_ink1); h1 = h0; if (dn->x + w1 > x_limit) { g_free(string); string = g_strdup_printf("<small><small>%s</small></small>", s->name_locale); gkrellm_text_markup_extents(dn->text_style.font, string, strlen(string), &w1, &h1, NULL, &y_ink1); } gkrellm_decal_text_set_offset(dn, 0, y_ink0 - y_ink1 + (h0 - h1 + 1) / 2); } else { gkrellm_decal_text_set_offset(dn, 0, 0); string = g_strdup(s->name_locale); } return string; }static voiddraw_temperatures(gboolean draw_name) { GList *list; SensorMon *smon; Sensor *sensor; gfloat t; gchar *name, units; if (!pTemp) return; for (list = temperature_list; list; list = list->next) { smon = (SensorMon *) list->data; sensor = smon->sensor; if (draw_name && smon->name_decal) { name = name_text_fit(sensor, smon->name_decal, smon->sensor_decal); gkrellm_draw_decal_markup(pTemp, smon->name_decal, name); g_free(name); } if (smon->sensor_decal) { sensor_read_temperature(sensor, &t, &units); gkrellm_sensor_draw_temperature_decal(pTemp, smon->sensor_decal, t, units); } } gkrellm_draw_panel_layers(pTemp); }static voiddraw_fans(gboolean draw_name) { GList *list; SensorMon *smon; Sensor *sensor; gchar *name; gfloat f; if (!pFan) return; for (list = fan_list; list; list = list->next) { smon = (SensorMon *) list->data; sensor = smon->sensor; if (draw_name && smon->name_decal) { name = name_text_fit(sensor, smon->name_decal, smon->sensor_decal); gkrellm_draw_decal_markup(pFan, smon->name_decal, name); g_free(name); } if (smon->sensor_decal) { sensor_read_fan(sensor, &f); gkrellm_sensor_draw_fan_decal(pFan, smon->sensor_decal, f); } } gkrellm_draw_panel_layers(pFan); } /* If s is NULL, draw 'em all */static voiddraw_voltages(Sensor *s, gint do_names) { GList *list; SensorMon *volt; Sensor *sensor; GkrellmDecal *ds, *dn; gchar *name, *fmt, buf[32]; gfloat v; if (!pVolt) return; for (list = volt_list; list; list = list->next) { volt = (SensorMon *) list->data; sensor = volt->sensor; if (s && s != sensor) continue; sensor->value_valid = FALSE; /* In case vref monitoring stops */ dn = volt->name_decal; ds = volt->sensor_decal; if (do_names && dn) { name = name_text_fit(sensor, dn, ds); gkrellm_draw_decal_markup(pVolt, dn, name); g_free(name); } if (ds) { if (sensor->vref && !sensor->vref->value_valid) sensor_read_voltage(sensor->vref, NULL); sensor_read_voltage(sensor, &v); sensor->value_valid = TRUE; if ((v < 10.0 && v > 0.0) || (v > -10.0 && v < 0.0)) fmt = "%.2f"; else fmt = "%.1f"; snprintf(buf, sizeof(buf), fmt, v); ds->x_off = (v < 0.0) ? 0 : minus_width; gkrellm_draw_decal_text(pVolt, ds, buf, -1); } } gkrellm_draw_panel_layers(pVolt); }static voidupdate_sensors(void) { static gboolean first_time_done; if (!GK.five_second_tick && first_time_done) { if (need_disk_temperature_update) /* delayed until disks created */ update_disk_temperatures(); need_disk_temperature_update = FALSE; return; } if (use_threads) { thread_data_valid = TRUE; run_sensors_thread(); } draw_temperatures(FALSE); draw_fans(FALSE); draw_voltages(NULL, FALSE); update_disk_temperatures(); first_time_done = TRUE; }static gintexpose_event(GtkWidget *widget, GdkEventExpose *ev, GkrellmPanel *p) { gdk_draw_drawable(widget->window, gkrellm_draw_GC(1), p->pixmap, ev->area.x, ev->area.y, ev->area.x, ev->area.y, ev->area.width, ev->area.height); return FALSE; }static gintcb_panel_press(GtkWidget *widget, GdkEventButton *ev, GkrellmPanel *p) { if (ev->button == 3) gkrellm_open_config_window(mon_config_sensors); return FALSE; }static GkrellmBorder default_bezel_border = {1,1,1,1};static voidassign_textstyles(GList *smon_list, GkrellmTextstyle **ts_name, GkrellmTextstyle **ts_sensor, gchar *format) { GList *list; GkrellmStyle *style; GkrellmMargin *margin; Sensor *sensor; SensorMon *smon; GkrellmTextstyle *ts, *ts_alt; gint w, w_name, w_sensor; style = gkrellm_meter_style(style_id); margin = gkrellm_get_style_margins(style); ts = gkrellm_copy_textstyle(gkrellm_meter_textstyle(style_id)); ts_alt = gkrellm_copy_textstyle(gkrellm_meter_alt_textstyle(style_id)); w = gkrellm_chart_width() - margin->left - margin->right; w_sensor = gkrellm_gdk_string_width(ts->font, format); w_sensor += bezel_style->border.left + bezel_style->border.right; for (list = smon_list; list; list = list->next) { smon = (SensorMon *)list->data; sensor = smon->sensor; w_name = gkrellm_gdk_string_width(ts_alt->font, sensor->name_locale); if (w_name + w_sensor > w - 2) { ts->font = ts_alt->font; /* downsize the sensor font */ break; } } *ts_name = ts_alt; /* Caller must free these */ *ts_sensor = ts; }static gintadjust_decal_positions(SensorMon *smon) { gint y, d, h_pad; h_pad = bezel_style->border.top + bezel_style->border.bottom; d = smon->sensor_decal->h - smon->name_decal->h; y = smon->sensor_decal->y + smon->sensor_decal->h + h_pad; if (d >= 0) smon->name_decal->y += (d + 1) / 2; else { if (h_pad < -d) y = smon->name_decal->y + smon->name_decal->h; smon->sensor_decal->y += -d / 2; } return y; }static voidmake_temperature_panel(GtkWidget *vbox, gint first_create) { Sensor *sensor; SensorMon *smon = NULL; GkrellmStyle *style; GkrellmMargin *m; GkrellmDecal *d; GList *list; GkrellmTextstyle *ts_sensor, *ts_name; gchar *format; gint y; if (!pTemp) return; style = gkrellm_meter_style(style_id); m = gkrellm_get_style_margins(style); format = units_fahrenheit ? "188.8F" : "88.8C"; assign_textstyles(temperature_list, &ts_name, &ts_sensor, format); gkrellm_get_top_bottom_margins(style, &y, NULL); y += bezel_style->border.top; for (list = temperature_list; list; list = list->next) { smon = (SensorMon *) list->data; sensor = smon->sensor; d = gkrellm_create_decal_text(pTemp, format, ts_sensor, style, -1, y, 0); d->x = gkrellm_chart_width() - d->w - m->right - 1; smon->sensor_decal = d; smon->name_decal = gkrellm_create_decal_text(pTemp, sensor->name_locale, ts_name, style, -1, y, 0); y = adjust_decal_positions(smon); sensor->cb_alert = cb_alert_trigger; sensor->cb_alert_data = smon; gkrellm_alert_trigger_connect(sensor->alert, cb_alert_trigger, smon); gkrellm_alert_command_process_connect(sensor->alert, cb_command_process, sensor); gkrellm_reset_alert_soft(sensor->alert); } g_free(ts_name); g_free(ts_sensor); gkrellm_panel_configure(pTemp, NULL, style); if (smon && smon->sensor_decal->y + smon->sensor_decal->h > smon->name_decal->y + smon->name_decal->h - bezel_style->border.bottom ) gkrellm_panel_configure_add_height(pTemp, bezel_style->border.bottom); gkrellm_panel_create(vbox, mon_sensors, pTemp); draw_bezels(pTemp, temperature_list, 0, 0, 1); if (first_create) { g_signal_connect(G_OBJECT(pTemp->drawing_area), "expose_event", G_CALLBACK(expose_event), pTemp); g_signal_connect(G_OBJECT(pTemp->drawing_area), "button_press_event", G_CALLBACK(cb_panel_press), pTemp); } draw_temperatures(TRUE); }static voidmake_fan_panel(GtkWidget *vbox, gint first_create) { Sensor *sensor; SensorMon *smon = NULL; GkrellmStyle *style; GkrellmMargin *m; GkrellmDecal *d; GList *list; GkrellmTextstyle *ts_sensor, *ts_name; gchar *format; gint y; if (!pFan) return; style = gkrellm_meter_style(style_id); m = gkrellm_get_style_margins(style); format = "8888"; assign_textstyles(temperature_list, &ts_name, &ts_sensor, format); gkrellm_get_top_bottom_margins(style, &y, NULL); y += bezel_style->border.top; for (list = fan_list; list; list = list->next) { smon = (SensorMon *) list->data; sensor = smon->sensor; d = gkrellm_create_decal_text(pFan, format, ts_sensor, style, -1, y, 0); d->x = gkrellm_chart_width() - d->w - m->right - 1; smon->sensor_decal = d; smon->name_decal = gkrellm_create_decal_text(pFan, sensor->name_locale, ts_name, style, -1, y, 0); y = adjust_decal_positions(smon); sensor->cb_alert = cb_alert_trigger; sensor->cb_alert_data = smon; gkrellm_alert_trigger_connect(sensor->alert, cb_alert_trigger, smon); gkrellm_alert_command_process_connect(sensor->alert, cb_command_process, sensor); gkrellm_reset_alert_soft(sensor->alert); } g_free(ts_name); g_free(ts_sensor); gkrellm_panel_configure(pFan, NULL, style); if (smon && smon->sensor_decal->y + smon->sensor_decal->h > smon->name_decal->y + smon->name_decal->h - bezel_style->border.bottom ) gkrellm_panel_configure_add_height(pFan, bezel_style->border.bottom); gkrellm_panel_create(vbox, mon_sensors, pFan); draw_bezels(pFan, fan_list, 0, 0, 0); if (first_create) { g_signal_connect(G_OBJECT(pFan->drawing_area), "expose_event", G_CALLBACK(expose_event), pFan); g_signal_connect(G_OBJECT(pFan->drawing_area), "button_press_event", G_CALLBACK(cb_panel_press), pFan); } draw_fans(TRUE); }static voidmake_volt_panel(GtkWidget *vbox, gint first_create) { GkrellmStyle *style; if (!pVolt) return; style = gkrellm_meter_style(style_id); make_volt_decals(pVolt, style); layout_volt_decals(pVolt, style); gkrellm_panel_configure(pVolt, NULL, style); /* Make the bottom margin reference against the bottom volt decals | bezel image. The volt decal height does not include the bezel so | gkrellm_panel_configure() did not account for the bezel. */ gkrellm_panel_configure_add_height(pVolt, bezel_style->border.bottom); gkrellm_panel_create(vbox, mon_sensors, pVolt); draw_bezels(pVolt, volt_list, volt_bezel_width, volt_mon_height, pixel_grub); if (first_create) { g_signal_connect(G_OBJECT(pVolt->drawing_area), "expose_event", G_CALLBACK(expose_event), pVolt); g_signal_connect(G_OBJECT(pVolt->drawing_area), "button_press_event", G_CALLBACK(cb_panel_press), pVolt); } draw_voltages(NULL, TRUE); }static voiddestroy_sensors_monitor(gboolean do_temp, gboolean do_fan, gboolean do_volt) { if (do_temp) { gkrellm_panel_destroy(pTemp); pTemp = NULL; } if (do_fan) { gkrellm_panel_destroy(pFan); pFan = NULL; } if (do_volt) { gkrellm_panel_destroy(pVolt); pVolt = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -