mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-28 09:38:38 +00:00
Add optional argument to $acpiacadapter
The exact location of the state information seems hardware dependent, so this adds the option to specify it manually. (linux only)
This commit is contained in:
parent
ecbfe50ac7
commit
60a6194b84
@ -4,8 +4,11 @@
|
|||||||
<command>
|
<command>
|
||||||
<option>acpiacadapter</option>
|
<option>acpiacadapter</option>
|
||||||
</command>
|
</command>
|
||||||
|
<option>(adapter)</option>
|
||||||
</term>
|
</term>
|
||||||
<listitem>ACPI ac adapter state.
|
<listitem>ACPI ac adapter state. On linux, the adapter option specifies the
|
||||||
|
subfolder of /sys/class/power_supply containing the state information (defaults
|
||||||
|
to "AC"). Other systems ignore it.
|
||||||
<para /></listitem>
|
<para /></listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
|
@ -61,7 +61,7 @@ extern int no_buffers;
|
|||||||
|
|
||||||
int open_acpi_temperature(const char *name);
|
int open_acpi_temperature(const char *name);
|
||||||
double get_acpi_temperature(int fd);
|
double get_acpi_temperature(int fd);
|
||||||
void get_acpi_ac_adapter(char *, size_t);
|
void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size, const char *adapter);
|
||||||
void get_acpi_fan(char *, size_t);
|
void get_acpi_fan(char *, size_t);
|
||||||
void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item);
|
void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item);
|
||||||
int get_battery_perct(const char *bat);
|
int get_battery_perct(const char *bat);
|
||||||
|
@ -865,7 +865,7 @@ void generate_text_internal(char *p, int p_max_size,
|
|||||||
get_acpi_fan(p, p_max_size);
|
get_acpi_fan(p, p_max_size);
|
||||||
}
|
}
|
||||||
OBJ(acpiacadapter) {
|
OBJ(acpiacadapter) {
|
||||||
get_acpi_ac_adapter(p, p_max_size);
|
get_acpi_ac_adapter(p, p_max_size, (const char *)obj->data.opaque);
|
||||||
}
|
}
|
||||||
OBJ(battery) {
|
OBJ(battery) {
|
||||||
get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
|
get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
|
||||||
|
19
src/core.c
19
src/core.c
@ -157,6 +157,22 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
|||||||
OBJ(acpitemp, 0)
|
OBJ(acpitemp, 0)
|
||||||
obj->data.i = open_acpi_temperature(arg);
|
obj->data.i = open_acpi_temperature(arg);
|
||||||
END OBJ(acpiacadapter, 0)
|
END OBJ(acpiacadapter, 0)
|
||||||
|
if(arg) {
|
||||||
|
#ifdef __linux__
|
||||||
|
if(strpbrk(arg, "/.") != NULL) {
|
||||||
|
/*
|
||||||
|
* a bit of paranoia. screen out funky paths
|
||||||
|
* i hope no device will have a '.' in its name
|
||||||
|
*/
|
||||||
|
NORM_ERR("acpiacadapter: arg must not contain '/' or '.'");
|
||||||
|
} else
|
||||||
|
obj->data.opaque = strdup(arg);
|
||||||
|
#else
|
||||||
|
NORM_ERR("acpiacadapter: arg is only used on linux");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
if(! obj->data.opaque)
|
||||||
|
obj->data.opaque = strdup("AC");
|
||||||
#endif /* !__OpenBSD__ */
|
#endif /* !__OpenBSD__ */
|
||||||
END OBJ(freq, 0)
|
END OBJ(freq, 0)
|
||||||
get_cpu_count();
|
get_cpu_count();
|
||||||
@ -1351,6 +1367,9 @@ void free_text_objects(struct text_object *root, int internal)
|
|||||||
case OBJ_acpitemp:
|
case OBJ_acpitemp:
|
||||||
close(data.i);
|
close(data.i);
|
||||||
break;
|
break;
|
||||||
|
case OBJ_acpiacadapter:
|
||||||
|
free(data.opaque);
|
||||||
|
break;
|
||||||
#endif /* !__OpenBSD__ */
|
#endif /* !__OpenBSD__ */
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
case OBJ_i2c:
|
case OBJ_i2c:
|
||||||
|
@ -518,10 +518,12 @@ int open_acpi_temperature(const char *name)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size)
|
void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size, const char *adapter)
|
||||||
{
|
{
|
||||||
int state;
|
int state;
|
||||||
|
|
||||||
|
(void) adapter; // only linux uses this
|
||||||
|
|
||||||
if (!p_client_buffer || client_buffer_size <= 0) {
|
if (!p_client_buffer || client_buffer_size <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1321,7 +1321,7 @@ void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size)
|
|||||||
snprintf(p_client_buffer, client_buffer_size, "%s", buf);
|
snprintf(p_client_buffer, client_buffer_size, "%s", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SYSFS_AC_ADAPTER_DIR "/sys/class/power_supply/AC"
|
#define SYSFS_AC_ADAPTER_DIR "/sys/class/power_supply"
|
||||||
#define ACPI_AC_ADAPTER_DIR "/proc/acpi/ac_adapter/"
|
#define ACPI_AC_ADAPTER_DIR "/proc/acpi/ac_adapter/"
|
||||||
/* Linux 2.6.25 onwards ac adapter info is in
|
/* Linux 2.6.25 onwards ac adapter info is in
|
||||||
/sys/class/power_supply/AC/
|
/sys/class/power_supply/AC/
|
||||||
@ -1333,9 +1333,12 @@ void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size)
|
|||||||
POWER_SUPPLY_NAME=AC
|
POWER_SUPPLY_NAME=AC
|
||||||
POWER_SUPPLY_TYPE=Mains
|
POWER_SUPPLY_TYPE=Mains
|
||||||
POWER_SUPPLY_ONLINE=1
|
POWER_SUPPLY_ONLINE=1
|
||||||
|
|
||||||
|
Update: it seems the folder name is hardware-dependent. We add an aditional adapter
|
||||||
|
argument, specifying the folder name.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size)
|
void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size, const char *adapter)
|
||||||
{
|
{
|
||||||
static int rep = 0;
|
static int rep = 0;
|
||||||
|
|
||||||
@ -1347,7 +1350,7 @@ void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(buf2, sizeof(buf2), "%s/uevent", SYSFS_AC_ADAPTER_DIR);
|
snprintf(buf2, sizeof(buf2), "%s/%s/uevent", SYSFS_AC_ADAPTER_DIR, adapter);
|
||||||
fp = open_file(buf2, &rep);
|
fp = open_file(buf2, &rep);
|
||||||
if (fp) {
|
if (fp) {
|
||||||
/* sysfs processing */
|
/* sysfs processing */
|
||||||
|
@ -332,8 +332,10 @@ int open_acpi_temperature(const char *name)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size)
|
void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size, const char *adapter)
|
||||||
{
|
{
|
||||||
|
(void) adapter; // only linux uses this
|
||||||
|
|
||||||
if (!p_client_buffer || client_buffer_size <= 0) {
|
if (!p_client_buffer || client_buffer_size <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user