diff options
Diffstat (limited to 'lxde-base/lxpanel/files/lxpanel-0.5.8-thermal-plugin.patch')
-rw-r--r-- | lxde-base/lxpanel/files/lxpanel-0.5.8-thermal-plugin.patch | 378 |
1 files changed, 0 insertions, 378 deletions
diff --git a/lxde-base/lxpanel/files/lxpanel-0.5.8-thermal-plugin.patch b/lxde-base/lxpanel/files/lxpanel-0.5.8-thermal-plugin.patch deleted file mode 100644 index 0d9a1e7ecf99..000000000000 --- a/lxde-base/lxpanel/files/lxpanel-0.5.8-thermal-plugin.patch +++ /dev/null @@ -1,378 +0,0 @@ -X-Git-Url: http://lxde.git.sourceforge.net/git/gitweb.cgi?p=lxde%2Flxpanel;a=blobdiff_plain;f=src%2Fplugins%2Fthermal%2Fthermal.c;h=1ac80939630e4c26b376a45dc7474ddca8246189;hp=afe5e89135fa28d72f7aa625f70214c3adb3239e;hb=HEAD;hpb=8e33d60b30bb9236d7a16c06e8f079936c8dd9b0 - -diff --git a/src/plugins/thermal/thermal.c b/src/plugins/thermal/thermal.c -index afe5e89..1ac8093 100644 ---- a/src/plugins/thermal/thermal.c -+++ b/src/plugins/thermal/thermal.c -@@ -32,12 +32,18 @@ - - #include "dbg.h" - --#define THERMAL_DIRECTORY "/proc/acpi/thermal_zone/" /* must be slash-terminated */ --#define THERMAL_TEMPF "temperature" --#define THERMAL_TRIP "trip_points" --#define TRIP_CRITICAL "critical (S5):" -+#define PROC_THERMAL_DIRECTORY "/proc/acpi/thermal_zone/" /* must be slash-terminated */ -+#define PROC_THERMAL_TEMPF "temperature" -+#define PROC_THERMAL_TRIP "trip_points" -+#define PROC_TRIP_CRITICAL "critical (S5):" - --typedef struct { -+#define SYSFS_THERMAL_DIRECTORY "/sys/class/thermal/" /* must be slash-terminated */ -+#define SYSFS_THERMAL_SUBDIR_PREFIX "thermal_zone" -+#define SYSFS_THERMAL_TEMPF "temp" -+#define SYSFS_THERMAL_TRIP "trip_point_0_temp" -+ -+ -+typedef struct thermal { - Plugin * plugin; - GtkWidget *main; - GtkWidget *namew; -@@ -45,7 +51,7 @@ typedef struct { - int critical; - int warning1; - int warning2; -- int custom_levels, auto_sensor; -+ int not_custom_levels, auto_sensor; - char *sensor, - *str_cl_normal, - *str_cl_warning1, -@@ -54,17 +60,20 @@ typedef struct { - GdkColor cl_normal, - cl_warning1, - cl_warning2; -+ gint (*get_temperature)(struct thermal *th); -+ gint (*get_critical)(struct thermal *th); - } thermal; - -+ - static gint --get_critical(thermal *th){ -+proc_get_critical(thermal *th){ - FILE *state; - char buf[ 256 ], sstmp [ 100 ]; - char* pstr; - - if(th->sensor == NULL) return -1; - -- sprintf(sstmp,"%s%s",th->sensor,THERMAL_TRIP); -+ sprintf(sstmp,"%s%s",th->sensor,PROC_THERMAL_TRIP); - - if (!(state = fopen( sstmp, "r"))) { - //printf("cannot open %s\n",sstmp); -@@ -72,15 +81,15 @@ get_critical(thermal *th){ - } - - while( fgets(buf, 256, state) && -- ! ( pstr = strstr(buf, TRIP_CRITICAL) ) ); -+ ! ( pstr = strstr(buf, PROC_TRIP_CRITICAL) ) ); - if( pstr ) - { -- pstr += strlen(TRIP_CRITICAL); -+ pstr += strlen(PROC_TRIP_CRITICAL); - while( *pstr && *pstr == ' ' ) - ++pstr; - - pstr[strlen(pstr)-3] = '\0'; -- printf("Critical: [%s]\n",pstr); -+ //printf("Critical: [%s]\n",pstr); - fclose(state); - return atoi(pstr); - } -@@ -90,14 +99,14 @@ get_critical(thermal *th){ - } - - static gint --get_temperature(thermal *th){ -+proc_get_temperature(thermal *th){ - FILE *state; - char buf[ 256 ], sstmp [ 100 ]; - char* pstr; - - if(th->sensor == NULL) return -1; - -- sprintf(sstmp,"%s%s",th->sensor,THERMAL_TEMPF); -+ sprintf(sstmp,"%s%s",th->sensor,PROC_THERMAL_TEMPF); - - if (!(state = fopen( sstmp, "r"))) { - //printf("cannot open %s\n",sstmp); -@@ -122,11 +131,77 @@ get_temperature(thermal *th){ - } - - static gint -+sysfs_get_critical(thermal *th){ -+ FILE *state; -+ char buf[ 256 ], sstmp [ 100 ]; -+ char* pstr; -+ -+ if(th->sensor == NULL) return -1; -+ -+ sprintf(sstmp,"%s%s",th->sensor,SYSFS_THERMAL_TRIP); -+ -+ if (!(state = fopen( sstmp, "r"))) { -+ //printf("cannot open %s\n",sstmp); -+ return -1; -+ } -+ -+ while( fgets(buf, 256, state) && -+ ! ( pstr = buf ) ); -+ if( pstr ) -+ { -+ fclose(state); -+ return atoi(pstr)/1000; -+ } -+ -+ fclose(state); -+ return -1; -+} -+ -+static gint -+sysfs_get_temperature(thermal *th){ -+ FILE *state; -+ char buf[ 256 ], sstmp [ 100 ]; -+ char* pstr; -+ -+ if(th->sensor == NULL) return -1; -+ -+ sprintf(sstmp,"%s%s",th->sensor,SYSFS_THERMAL_TEMPF); -+ -+ if (!(state = fopen( sstmp, "r"))) { -+ //printf("cannot open %s\n",sstmp); -+ return -1; -+ } -+ -+ while (fgets(buf, 256, state) && -+ ! ( pstr = buf ) ); -+ if( pstr ) -+ { -+ fclose(state); -+ return atoi(pstr)/1000; -+ } -+ -+ fclose(state); -+ return -1; -+} -+ -+ -+static void -+set_get_functions(thermal *th) -+{ -+ if (th->sensor && strncmp(th->sensor, "/sys/", 5) == 0){ -+ th->get_temperature = sysfs_get_temperature; -+ th->get_critical = sysfs_get_critical; -+ } else { -+ th->get_temperature = proc_get_temperature; -+ th->get_critical = proc_get_critical; -+ } -+} -+ -+static gint - update_display(thermal *th) - { - char buffer [60]; -- int n; -- int temp = get_temperature(th); -+ int temp = th->get_temperature(th); - GdkColor color; - - if(temp >= th->warning2) -@@ -141,42 +216,92 @@ update_display(thermal *th) - panel_draw_label_text(th->plugin->panel, th->namew, "NA", TRUE, TRUE); - else - { -- n = sprintf(buffer, "<span color=\"#%06x\"><b>%02d</b></span>", gcolor2rgb24(&color), temp); -+ sprintf(buffer, "<span color=\"#%06x\"><b>%02d</b></span>", gcolor2rgb24(&color), temp); - gtk_label_set_markup (GTK_LABEL(th->namew), buffer) ; - } - - RET(TRUE); - } - -+ -+/* get_sensor(): -+ * - Get the sensor directory, and store it in '*sensor'. -+ * - It is searched for in 'directory'. -+ * - Only the subdirectories starting with 'subdir_prefix' are accepted as sensors. -+ * - 'subdir_prefix' may be NULL, in which case any subdir is considered a sensor. */ - static void --check_sensors( thermal* th ) -+get_sensor(char** sensor, char const* directory, char const* subdir_prefix) - { - GDir *sensorsDirectory; - const char *sensor_name; - char sensor_path[100]; - -- if (! (sensorsDirectory = g_dir_open(THERMAL_DIRECTORY, 0, NULL))) -+ if (! (sensorsDirectory = g_dir_open(directory, 0, NULL))) - { -- th->sensor = NULL; -+ *sensor = NULL; - return; - } - - /* Scan the thermal_zone directory for available sensors */ - while ((sensor_name = g_dir_read_name(sensorsDirectory))) { - if (sensor_name[0] != '.') { -- sprintf(sensor_path,"%s%s/",THERMAL_DIRECTORY, sensor_name); -- if(th->sensor) { -- g_free(th->sensor); -- th->sensor = NULL; -+ if (subdir_prefix) { -+ if (strncmp(sensor_name, subdir_prefix, strlen(subdir_prefix)) != 0) -+ continue; - } -- th->sensor = strdup(sensor_path); -- //printf("sensor: %s\n", b->sensor); -+ sprintf(sensor_path,"%s%s/", directory, sensor_name); -+ if(*sensor) { -+ g_free(*sensor); -+ *sensor = NULL; -+ } -+ *sensor = strdup(sensor_path); - break; - } - } - g_dir_close(sensorsDirectory); - } - -+static void -+check_sensors( thermal *th ) -+{ -+ if(th->sensor) { -+ g_free(th->sensor); -+ th->sensor = NULL; -+ } -+ -+ get_sensor(&th->sensor, PROC_THERMAL_DIRECTORY, NULL); -+ -+ if (!th->sensor) -+ get_sensor(&th->sensor, SYSFS_THERMAL_DIRECTORY, SYSFS_THERMAL_SUBDIR_PREFIX); -+ -+ //printf("thermal sensor: %s\n", th->sensor); -+} -+ -+ -+static void applyConfig(Plugin* p) -+{ -+ thermal *th = p->priv; -+ ENTER; -+ -+ if (th->str_cl_normal) gdk_color_parse(th->str_cl_normal, &th->cl_normal); -+ if (th->str_cl_warning1) gdk_color_parse(th->str_cl_warning1, &th->cl_warning1); -+ if (th->str_cl_warning2) gdk_color_parse(th->str_cl_warning2, &th->cl_warning2); -+ -+ if(th->sensor == NULL) th->auto_sensor = TRUE; -+ if(th->auto_sensor) check_sensors(th); -+ -+ set_get_functions(th); -+ -+ th->critical = th->get_critical(th); -+ -+ if(th->not_custom_levels){ -+ th->warning1 = th->critical - 10; -+ th->warning2 = th->critical - 5; -+ } -+ -+ RET(); -+} -+ - static int - thermal_constructor(Plugin *p, char** fp) - { -@@ -197,6 +322,11 @@ thermal_constructor(Plugin *p, char** fp) - th->main = p->pwid; - th->tip = gtk_tooltips_new(); - -+ /* By default, use automatic, that is, "not custom" temperature levels. If -+ * we were using custom levels, they would be 0°C at startup, so we would -+ * display in warning colors by default. */ -+ th->not_custom_levels = TRUE; -+ - g_signal_connect (G_OBJECT (p->pwid), "button_press_event", - G_CALLBACK (plugin_button_press_event), (gpointer) p); - -@@ -220,7 +350,7 @@ thermal_constructor(Plugin *p, char** fp) - }else if (!g_ascii_strcasecmp(s.t[0], "AutomaticSensor")){ - th->auto_sensor= atoi(s.t[1]); - }else if (!g_ascii_strcasecmp(s.t[0], "CustomLevels")){ -- th->custom_levels= atoi(s.t[1]); -+ th->not_custom_levels= atoi(s.t[1]); - }else if (!g_ascii_strcasecmp(s.t[0], "Sensor")){ - th->sensor= g_strdup(s.t[1]); - }else if (!g_ascii_strcasecmp(s.t[0], "Warning1Temp")){ -@@ -236,7 +366,6 @@ thermal_constructor(Plugin *p, char** fp) - goto error; - } - } -- - } - - if(!th->str_cl_normal) -@@ -246,20 +375,7 @@ thermal_constructor(Plugin *p, char** fp) - if(!th->str_cl_warning2) - th->str_cl_warning2 = g_strdup("#ff0000"); - -- gdk_color_parse(th->str_cl_normal, &(th->cl_normal)); -- gdk_color_parse(th->str_cl_warning1, &(th->cl_warning1)); -- gdk_color_parse(th->str_cl_warning2, &(th->cl_warning2)); -- -- -- if(th->sensor == NULL) th->auto_sensor = TRUE; -- if(th->auto_sensor) check_sensors(th); -- -- th->critical = get_critical(th); -- -- if(!th->custom_levels){ -- th->warning1 = th->critical - 10; -- th->warning2 = th->critical - 5; -- } -+ applyConfig(p); - - gtk_widget_show(th->namew); - -@@ -272,27 +388,6 @@ error: - RET(FALSE); - } - --static void applyConfig(Plugin* p) --{ -- -- thermal *th = (thermal *)p->priv; -- -- ENTER; -- -- if (th->str_cl_normal) gdk_color_parse(th->str_cl_normal, &th->cl_normal); -- if (th->str_cl_warning1) gdk_color_parse(th->str_cl_warning1, &th->cl_warning1); -- if (th->str_cl_warning2) gdk_color_parse(th->str_cl_warning2, &th->cl_warning2); -- -- if(th->auto_sensor) check_sensors(th); -- -- if(th->custom_levels){ -- th->warning1 = th->critical - 10; -- th->warning2 = th->critical - 5; -- } -- -- RET(); --} -- - static void config(Plugin *p, GtkWindow* parent) { - ENTER; - -@@ -306,7 +401,7 @@ static void config(Plugin *p, GtkWindow* parent) { - _("Warning2"), &th->str_cl_warning2, CONF_TYPE_STR, - _("Automatic sensor location"), &th->auto_sensor, CONF_TYPE_BOOL, - _("Sensor"), &th->sensor, CONF_TYPE_STR, -- _("Automatic temperature levels"), &th->custom_levels, CONF_TYPE_BOOL, -+ _("Automatic temperature levels"), &th->not_custom_levels, CONF_TYPE_BOOL, - _("Warning1 Temperature"), &th->warning1, CONF_TYPE_INT, - _("Warning2 Temperature"), &th->warning2, CONF_TYPE_INT, - NULL); -@@ -338,7 +433,7 @@ static void save_config( Plugin* p, FILE* fp ) - lxpanel_put_str( fp, "NormalColor", th->str_cl_normal ); - lxpanel_put_str( fp, "Warning1Color", th->str_cl_warning1 ); - lxpanel_put_str( fp, "Warning2Color", th->str_cl_warning2 ); -- lxpanel_put_int( fp, "CustomLevels", th->custom_levels ); -+ lxpanel_put_int( fp, "CustomLevels", th->not_custom_levels ); - lxpanel_put_int( fp, "Warning1Temp", th->warning1 ); - lxpanel_put_int( fp, "Warning2Temp", th->warning2 ); - lxpanel_put_int( fp, "AutomaticSensor", th->auto_sensor ); |