⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cpu.c

📁 系统任务管理器
💻 C
📖 第 1 页 / 共 3 页
字号:
			gkrellm_update_krell(p, krell, krell_value);			gkrellm_panel_label_on_top_of_decals(p,						gkrellm_alert_decal_visible(cpu->alert));			gkrellm_draw_panel_layers(p);			}		cpu->previous_total = total;		}	}static gintcpu_expose_event(GtkWidget *widget, GdkEventExpose *ev)	{	GList			*list;	GkrellmChart	*cp;	GdkPixmap		*pixmap	= NULL;	for (list = cpu_mon_list; list; list = list->next)		{		cp = ((CpuMon *) list->data)->chart;		if (widget == cp->drawing_area)			pixmap = cp->pixmap;		else if (widget == cp->panel->drawing_area)			pixmap = cp->panel->pixmap;		if (pixmap)			{			gdk_draw_drawable(widget->window, gkrellm_draw_GC(1), pixmap,					ev->area.x, ev->area.y, ev->area.x, ev->area.y,					ev->area.width, ev->area.height);			break;			}		}	return FALSE;	}static gintcb_cpu_extra(GtkWidget *widget, GdkEventButton *ev)	{	GList			*list;	CpuMon			*cpu;	GkrellmChart	*cp;	for (list = cpu_mon_list; list; list = list->next)		{		cpu = (CpuMon *) list->data;		cp = cpu->chart;		if (widget != cpu->chart->drawing_area)			continue;		if (ev->button == 1 && ev->type == GDK_BUTTON_PRESS)			{			cpu->extra_info = !cpu->extra_info;			refresh_cpu_chart(cpu);			gkrellm_config_modified();			}		else if (   ev->button == 3				 || (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS)				)			gkrellm_chartconfig_window_create(cpu->chart);		break;		}	return FALSE;	}static voidsetup_cpu_scaling(GkrellmChartconfig *cf)	{	gint	grids;	grids = gkrellm_get_chartconfig_fixed_grids(cf);	if (!grids)		grids = FULL_SCALE_GRIDS;	gkrellm_set_chartconfig_grid_resolution(cf,				CPU_TICKS_PER_SECOND / grids);	}static gbooleanenable_cpu_visibility(CpuMon *cpu)	{	gint	enabled = cpu_enabled;	if (n_smp_cpus > 0)		{		if (   (cpu->is_composite && smp_mode == SMP_REAL_MODE)			|| (! cpu->is_composite && smp_mode == SMP_COMPOSITE_MODE)		   )			enabled = FALSE;		}	return gkrellm_chart_enable_visibility(cpu->chart, enabled, &cpu->enabled);	}static voidcb_cpu_temp_alert_trigger(GkrellmAlert *alert, CpuMon *cpu)	{	GkrellmAlertdecal	*ad;	GkrellmDecal		*d;	if (alert && cpu && cpu->chart)		{		ad = &alert->ad;		d = cpu->sensor_decal;		if (d)			{			ad->x = d->x - 1;			ad->y = d->y - 1;			ad->w = d->w + 2;			ad->h = d->h + 2;			gkrellm_render_default_alert_decal(alert);			}		alert->panel = cpu->chart->panel;		}	}static voidcb_cpu_fan_alert_trigger(GkrellmAlert *alert, CpuMon *cpu)	{	GkrellmAlertdecal	*ad;	GkrellmDecal		*d;	if (alert && cpu && cpu->chart)		{		ad = &alert->ad;		if (sensor_separate_mode)			d = cpu->fan_decal;		else			d = cpu->sensor_decal;		if (d)			{			ad->x = d->x - 1;			ad->y = d->y - 1;			ad->w = d->w + 2;			ad->h = d->h + 2;			gkrellm_render_default_alert_decal(alert);			}		alert->panel = cpu->chart->panel;		}	}  /* How to decide when to make the sensor_decal and fan_decal visible.  |  The sensor_decal can show temp values, fan values, or alternating  |  temp/fan values.  The fan_decal only shows fan values when non  |  alternating mode is selected. The sensors are mapped in sensors.c  |  |   Sensor and fan decal display truth table:  |   |-----decals visible----||--sensors mapped--|   separate  |  |	  |sensor_decal  fan_decal||   temp     fan   |    mode     |  |   |-----------------------||--------------------------------|  |   |     0           0     ||     0       0          0       |  |   |     1           0     ||     1       0          0       |  |   |     1           0     ||     0       1          0       |  |   |     1           0     ||     1       1          0       |  |   |     0           0     ||     0       0          1       |  |   |     1           0     ||     1       0          1       |  |   |     1           0     ||     0       1          1       |  |   |     1           1     ||     1       1          1       |  |   |----------------------------------------------------------  */static gbooleanadjust_sensors_display(CpuMon *cpu, gint force)	{	GkrellmPanel	*p;	GkrellmDecal	*ds, *df;	GkrellmAlert	*alert;	gint			position = 0;	ds = cpu->sensor_decal;	df = cpu->fan_decal;	if (!ds || !df)		return FALSE;	/* The test for state change is decal state vs success at reading	|  a temperature.	*/	p = cpu->chart->panel;	cpu->show_temperature = cpu->show_fan = FALSE;	if (!_GK.demo)		{		gkrellm_sensor_alert_connect(cpu->sensor_temp,					cb_cpu_temp_alert_trigger, cpu);		gkrellm_sensor_alert_connect(cpu->sensor_fan,					cb_cpu_fan_alert_trigger, cpu);		}	/* If a fan alert is triggered, turn it off in case fan decal being used	|  is changed.  The alert will just retrigger at next fan update.	*/	alert = gkrellm_sensor_alert(cpu->sensor_fan);	gkrellm_reset_alert_soft(alert);	if (cpu->sensor_temp || _GK.demo)		cpu->show_temperature = TRUE;	if (cpu->sensor_fan || _GK.demo)		cpu->show_fan = TRUE;	if (cpu->show_temperature || cpu->show_fan)		{		if (! gkrellm_is_decal_visible(ds) || force)			gkrellm_make_decal_visible(p, ds);		position = 0;		}	else		{		if (gkrellm_is_decal_visible(ds) || force)			gkrellm_make_decal_invisible(p, ds);		position = cpu->save_label_position;		}	if (cpu->show_fan && cpu->show_temperature && sensor_separate_mode)		{		if (! gkrellm_is_decal_visible(df) || force)			gkrellm_make_decal_visible(p, df);		position = -1;		}	else		{		if (gkrellm_is_decal_visible(df) || force)			gkrellm_make_decal_invisible(p, df);		}	if (position != p->label->position || force)		{		if (cpu->save_label_position >= 0)	/* Reassign position only if the */			p->label->position = position;	/* original label was visible.   */		gkrellm_draw_panel_label(p);		draw_sensor_decals(cpu);		gkrellm_draw_panel_layers(p);		}	return TRUE;	}static gintcb_panel_press(GtkWidget *widget, GdkEventButton *ev)	{	if (ev->button == 3)		gkrellm_open_config_window(mon_cpu);	return FALSE;	}static GkrellmPiximage	*nice_data_piximage,						*nice_data_grid_piximage;static GdkPixmap		*nice_data_pixmap,						*nice_data_grid_pixmap;static GdkColor			nice_color,						nice_grid_color;static gchar			*nice_color_string,						*nice_grid_color_string;static voidcb_height(GkrellmChartconfig *cf, CpuMon *cpu)	{	GList			*list;	GkrellmChart	*cp;	gint			h, h_max = 0;	h = gkrellm_get_chartconfig_height(cf);	for (list = cpu_mon_list; list; list = list->next)		{		cp = ((CpuMon *) list->data)->chart;		if (cp->h != h && config_tracking)			{			gkrellm_chartconfig_callback_block(cp->config, TRUE);			gkrellm_set_chart_height(cp, h);			gkrellm_chartconfig_callback_block(cp->config, FALSE);			}		if (cp->h > h_max)			h_max = cp->h;		}	gkrellm_render_data_pixmap(nice_data_piximage,				&nice_data_pixmap, &nice_color, h_max);	}static voidload_nice_data_piximages(void)	{	if (nice_time_unsupported)		return;	g_free(nice_color_string);	g_free(nice_grid_color_string);	nice_color_string = gkrellm_get_gkrellmrc_string("cpu_nice_color");	nice_grid_color_string =				gkrellm_get_gkrellmrc_string("cpu_nice_grid_color");	gkrellm_map_color_string(nice_color_string, &nice_color);	gkrellm_map_color_string(nice_grid_color_string, &nice_grid_color);			if (nice_data_piximage)		gkrellm_destroy_piximage(nice_data_piximage);	if (nice_data_grid_piximage)		gkrellm_destroy_piximage(nice_data_grid_piximage);	nice_data_piximage = nice_data_grid_piximage = NULL;	gkrellm_free_pixmap(&nice_data_pixmap);	gkrellm_free_pixmap(&nice_data_grid_pixmap);	gkrellm_load_piximage("nice", NULL, &nice_data_piximage, CPU_STYLE_NAME);	gkrellm_load_piximage("nice_grid", NULL, &nice_data_grid_piximage,					CPU_STYLE_NAME);	}static voidrender_nice_data_pixmaps(void)	{	GList		*list;	CpuMon		*cpu;	gint		h_max;	gkrellm_render_data_grid_pixmap(nice_data_grid_piximage,				&nice_data_grid_pixmap, &nice_grid_color);	h_max = 2;	for (list = cpu_mon_list; list; list = list->next)		{		cpu = (CpuMon *) list->data;		if (cpu->chart && (cpu->chart->h > h_max))			h_max = cpu->chart->h;		}	gkrellm_render_data_pixmap(nice_data_piximage,				&nice_data_pixmap, &nice_color, h_max);	}static voidcreate_cpu(GtkWidget *vbox, gint first_create)	{	CpuMon			*cpu;	GkrellmChart	*cp;	GkrellmPanel	*p;	GkrellmStyle	*style;	GList			*list;	load_nice_data_piximages();	for (list = cpu_mon_list; list; list = list->next)		{		cpu = (CpuMon *) list->data;		/* Default to all cpu charts visible.  Correct this as last step.		*/		if (first_create)			{			/* don't really need the cpu->vbox unless I start destroying...			*/			cpu->vbox = gtk_vbox_new(FALSE, 0);			gtk_container_add(GTK_CONTAINER(vbox), cpu->vbox);			gtk_widget_show(cpu->vbox);			cpu->chart = gkrellm_chart_new0();			cpu->chart->panel = gkrellm_panel_new0();			cpu->enabled = TRUE;			}		cp = cpu->chart;		p = cp->panel;		style = gkrellm_panel_style(style_id);		gkrellm_create_krell(p, gkrellm_krell_panel_piximage(style_id), style);		gkrellm_chart_create(cpu->vbox, mon_cpu, cp, &cpu->chart_config);		gkrellm_set_draw_chart_function(cp, refresh_cpu_chart, cpu);		cpu->sys_cd = gkrellm_add_default_chartdata(cp, _("sys time"));		cpu->user_cd = gkrellm_add_default_chartdata(cp, _("user time"));		if (!nice_time_unsupported)			{			if (   (nice_data_piximage && nice_data_grid_piximage)				|| (nice_color_string && nice_grid_color_string)			   )				{				render_nice_data_pixmaps();				cpu->nice_cd = gkrellm_add_chartdata(cp, &nice_data_pixmap,							nice_data_grid_pixmap, _("nice time"));				}			else				cpu->nice_cd = gkrellm_add_default_chartdata(cp,							_("nice time"));			}		gkrellm_set_chartdata_flags(cpu->nice_cd, CHARTDATA_ALLOW_HIDE);		/* Since there is a constant Max value of the chart (CPU_TICKS/SEC)		|  I control the grid resolution when fixed grids change.		|  So don't call gkrellm_grid_resolution_adjustment() so there won't		|  be a grid resolution part in the chart config.  Also, make sure		|  auto grid res is off.		*/		gkrellm_set_chartconfig_auto_grid_resolution(cp->config, FALSE);		gkrellm_chartconfig_fixed_grids_connect(cp->config,					setup_cpu_scaling, NULL);		gkrellm_chartconfig_height_connect(cp->config, cb_height, cpu);		setup_cpu_scaling(cp->config);		gkrellm_sensors_create_decals(p, style_id,					&cpu->sensor_decal, &cpu->fan_decal);		gkrellm_panel_configure(p, cpu->panel_label, style);		gkrellm_panel_create(cpu->vbox, mon_cpu, p);		cpu->save_label_position = p->label->position;		if (cpu->sensor_decal)			adjust_sensors_display(cpu, TRUE);		gkrellm_alloc_chartdata(cp);		enable_cpu_visibility(cpu);		cpu->new_text_format = TRUE;		if (first_create)			{			g_signal_connect(G_OBJECT (cp->drawing_area), "expose_event",					G_CALLBACK(cpu_expose_event), NULL);			g_signal_connect(G_OBJECT (p->drawing_area), "expose_event",					G_CALLBACK(cpu_expose_event), NULL);			g_signal_connect(G_OBJECT(cp->drawing_area), "button_press_event",					G_CALLBACK(cb_cpu_extra), NULL);			g_signal_connect(G_OBJECT(p->drawing_area), "button_press_event",					G_CALLBACK(cb_panel_press), NULL);			}		else			refresh_cpu_chart(cpu);		gkrellm_setup_launcher(p, &cpu->launch, CHART_PANEL_TYPE, 4);		}	if (cpu_enabled)		gkrellm_spacers_show(mon_cpu);	else		gkrellm_spacers_hide(mon_cpu);	}/* ------------------------------------------------------------------ */#define	CPU_CONFIG_KEYWORD	"cpu"static GtkWidget	*text_format_combo;static GtkWidget	*smp_button[3];static GtkWidget	*alert_config_nice_button;static voidcb_alert_trigger(GkrellmAlert *alert, CpuMon *cpu)	{	GkrellmAlertdecal	*ad;	GkrellmDecal		*ds, *df;	alert->panel = cpu->chart->panel;	ds = cpu->sensor_decal;	df = cpu->fan_decal;	if (gkrellm_is_decal_visible(ds) && !gkrellm_is_decal_visible(df))		{		ad = &alert->ad;		ad->x = 0;		ad->y = ds->y - 1;		ad->w = ds->x - 1;		ad->h = ds->h + 2;		gkrellm_render_default_alert_decal(alert);		}	}static voiddup_cpu_alert(void)	{	GList	*list;	CpuMon	*cpu;	for (list = cpu_mon_list; list; list = list->next)		{		cpu = (CpuMon *) list->data;		gkrellm_alert_dup(&cpu->alert, cpu_alert);		gkrellm_alert_trigger_connect(cpu->alert, cb_alert_trigger, cpu);		gkrellm_alert_command_process_connect(cpu->alert,					cb_command_process, cpu);		}	}static voidcreate_alert(void)	{	GList		*list;	CpuMon		*cpu;	list = g_list_nth(cpu_mon_list, 0);	if (!list)		return;	cpu = (CpuMon *) list->data;	cpu_alert = gkrellm_alert_create(NULL, _("CPU"),					_("Percent Usage"),					TRUE, FALSE, TRUE,					100, 10, 1, 10, 0);	gkrellm_alert_delay_config(cpu_alert, 1, 60 * 60, 2);	gkrellm_alert_config_connect(cpu_alert, cb_alert_config, NULL);#if !defined(WIN32)	gkrellm_alert_config_create_connect(cpu_alert,							cb_alert_config_create, NULL);#endif	/* This alert is a master to be dupped and is itself never checked */	}static voidsave_cpu_config(FILE *f)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -