Skip to content

Commit

Permalink
Merge pull request #33 from eskerda/eskerda-thinklight
Browse files Browse the repository at this point in the history
add support for $ibm_thinklight
  • Loading branch information
brndnmtthws committed Dec 17, 2013
2 parents b5e17a4 + 68263d4 commit 120d6e1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
10 changes: 10 additions & 0 deletions doc/variables.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,16 @@
Sensor 0 is on the CPU, 3 is on the GPU.
<para /></listitem>
</varlistentry>
<varlistentry>
<term>
<command>
<option>ibm_thinklight</option>
</command>
</term>
<listitem>If running the IBM ACPI, displays the status of your
ThinkLight™. Value is either 'on', 'off' or 'unknown'.
<para /></listitem>
</varlistentry>
<varlistentry>
<term>
<command>
Expand Down
2 changes: 2 additions & 0 deletions src/core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@ struct text_object *construct_text_object(char *s, const char *arg,
obj->callbacks.print = &get_ibm_acpi_volume;
END OBJ(ibm_brightness, 0)
obj->callbacks.print = &get_ibm_acpi_brightness;
END OBJ(ibm_thinklight, 0)
obj->callbacks.print = &get_ibm_acpi_thinklight;
#endif
/* information from sony_laptop kernel module
* /sys/devices/platform/sony-laptop */
Expand Down
44 changes: 44 additions & 0 deletions src/ibm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,50 @@ void get_ibm_acpi_brightness(struct text_object *obj, char *p, int p_max_size)
snprintf(p, p_max_size, "%d", brightness);
}

/* get ThinkLight status on IBM/Lenovo laptops running the ibm acpi.
* /proc/acpi/ibm/light looks like this (2 lines):
status: off
commands: on, off
* http://ibm-acpi.sourceforge.net/README reports that it's also possible to
* get "unknown" for a few models that do not make the status available.
* Lluis Esquerda ([email protected]) */

void get_ibm_acpi_thinklight(struct text_object *obj, char *p, int p_max_size)
{
FILE *fp;
char thinklight[8];
char filename[128];

(void)obj;

if (!p || p_max_size <= 0) {
return;
}

snprintf(filename, 127, "%s/light", IBM_ACPI_DIR);

fp = fopen(filename, "r");
if (fp != NULL) {
while (!feof(fp)) {
char line[256];

if (fgets(line, 255, fp) == NULL) {
break;
}
if (sscanf(line, "status: %s", thinklight)) {
break;
}
}
} else {
CRIT_ERR(NULL, NULL, "can't open '%s': %s\nYou are not using the IBM "
"ACPI. Remove ibm* from your " PACKAGE_NAME" config file.",
filename, strerror(errno));
}

fclose(fp);
snprintf(p, p_max_size, "%s", thinklight);
}

void parse_ibm_temps_arg(struct text_object *obj, const char *arg)
{
if (!isdigit(arg[0]) || strlen(arg) > 1 || atoi(&arg[0]) >= 8) {
Expand Down
1 change: 1 addition & 0 deletions src/ibm.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void get_ibm_acpi_fan(struct text_object *, char *, int);
int get_ibm_acpi_temps(void);
void get_ibm_acpi_volume(struct text_object *, char *, int);
void get_ibm_acpi_brightness(struct text_object *, char *, int);
void get_ibm_acpi_thinklight(struct text_object *, char *, int);

void parse_ibm_temps_arg(struct text_object *, const char *);
void print_ibm_temps(struct text_object *, char *, int);
Expand Down

0 comments on commit 120d6e1

Please sign in to comment.