X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/526955ecda819d3471e04bef63df802edbdec63f..8894244cb8ad92569a1cbe9854ba3a7b97102e20:/slstatus.c diff --git a/slstatus.c b/slstatus.c index 6ca36e0..b34ea30 100644 --- a/slstatus.c +++ b/slstatus.c @@ -217,7 +217,7 @@ volume() { int mute = 0; long vol = 0, max = 0, min = 0; - + /* get volume from alsa */ snd_mixer_t *handle; snd_mixer_elem_t *pcm_mixer, *mas_mixer; @@ -232,12 +232,9 @@ volume() snd_mixer_selem_id_set_name(mute_info, channel); pcm_mixer = snd_mixer_find_selem(handle, vol_info); mas_mixer = snd_mixer_find_selem(handle, mute_info); - snd_mixer_selem_get_playback_volume_range((snd_mixer_elem_t *)pcm_mixer, - &min, &max); - snd_mixer_selem_get_playback_volume((snd_mixer_elem_t *)pcm_mixer, - SND_MIXER_SCHN_MONO, &vol); - snd_mixer_selem_get_playback_switch(mas_mixer, SND_MIXER_SCHN_MONO, - &mute); + snd_mixer_selem_get_playback_volume_range((snd_mixer_elem_t *)pcm_mixer, &min, &max); + snd_mixer_selem_get_playback_volume((snd_mixer_elem_t *)pcm_mixer, SND_MIXER_SCHN_MONO, &vol); + snd_mixer_selem_get_playback_switch(mas_mixer, SND_MIXER_SCHN_MONO, &mute); if (vol_info) snd_mixer_selem_id_free(vol_info); if (mute_info) @@ -247,7 +244,7 @@ volume() /* return the string (mute) */ if (!mute) - return "mute"; + return smprintf("mute"); else return smprintf("%d%%", (vol * 100) / max); } @@ -264,9 +261,12 @@ wifi_signal() char path_end[11] = "/operstate"; char path[32]; char status[5]; + char needle[sizeof wificard + 1]; FILE *fp; /* generate the path name */ + + memset(path, 0, sizeof path); strcat(path, path_start); strcat(path, wificard); strcat(path, path_end); @@ -295,10 +295,12 @@ wifi_signal() } /* extract the signal strength */ + strcpy(needle, wificard); + strcat(needle, ":"); fgets(buf, bufsize, fp); fgets(buf, bufsize, fp); fgets(buf, bufsize, fp); - if ((datastart = strstr(buf, "wlp3s0:")) != NULL) { + if ((datastart = strstr(buf, needle)) != NULL) { datastart = strstr(buf, ":"); sscanf(datastart + 1, " %*d %d %*d %*d %*d %*d %*d %*d %*d %*d", &strength); } @@ -322,10 +324,32 @@ main() exit(1); } - /* return status every second */ + char *pWifi_signal = NULL; + char *pBattery = NULL; + char *pCpu_usage = NULL; + char *pCpu_temperature = NULL; + char *pRam_usage = NULL; + char *pVolume = NULL; + char *pDatetime = NULL; + + /* return status every second */ for (;;) { + pWifi_signal = wifi_signal(); + pBattery = battery(); + pCpu_usage = cpu_usage(); + pCpu_temperature = cpu_temperature(); + pRam_usage = ram_usage(); + pVolume = volume(); + pDatetime = datetime(); sprintf(status, FORMATSTRING, ARGUMENTS); setstatus(status); + free(pWifi_signal); + free(pBattery); + free(pCpu_usage); + free(pCpu_temperature); + free(pRam_usage); + free(pVolume); + free(pDatetime); } /* close display */