mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-26 04:17:33 +00:00
Add new text objects to retrieve the currently used keyboard layout and mouse speed in percentage and generate random password of chosen length and get the cpu clock speed from assembly (#550)
* Add new text object to capitalize the first character of each word * Fix for issue https://github.com/brndnmtthws/conky/issues/46 * Fix for issue https://github.com/brndnmtthws/conky/issues/35 * Fix for issue https://github.com/brndnmtthws/conky/issues/35 * Fix for https://github.com/brndnmtthws/conky/issues/206 * Fix for https://github.com/brndnmtthws/conky/issues/474 * Add new "temp2" variable to print the temperature in floating number * Make the "temp2" variable static and add some explanation above it * openbsd.cc: Add one more formal parameter to "temp_print()" * extras/convert.lua: change url to wiki page (#554)
This commit is contained in:
parent
cb5833e2fc
commit
a3b7905df6
@ -44,12 +44,12 @@ set(conky_sources
|
||||
common.cc common.h
|
||||
conky.cc conky.h
|
||||
core.cc core.h
|
||||
cat.cc cat.h
|
||||
diskio.cc diskio.h
|
||||
entropy.cc entropy.h
|
||||
exec.cc exec.h
|
||||
fs.cc fs.h
|
||||
mail.cc mail.h
|
||||
misc.cc misc.h
|
||||
net_stat.cc net_stat.h
|
||||
template.cc template.h
|
||||
mboxscan.cc mboxscan.h
|
||||
|
@ -307,10 +307,7 @@ void update_stuff() {
|
||||
|
||||
/* Ohkie to return negative values for temperatures */
|
||||
int round_to_int_temp(float f) {
|
||||
if (f >= 0.0) {
|
||||
return static_cast<int>(f + 0.5);
|
||||
}
|
||||
return static_cast<int>(f - 0.5);
|
||||
return static_cast<int>(f);
|
||||
}
|
||||
/* Don't return negative values for cpugraph, bar, gauge, percentage.
|
||||
* Causes unreasonable numbers to show */
|
||||
@ -588,7 +585,7 @@ int if_running_iftest(struct text_object *obj) {
|
||||
|
||||
#ifndef __OpenBSD__
|
||||
void print_acpitemp(struct text_object *obj, char *p, int p_max_size) {
|
||||
temp_print(p, p_max_size, get_acpi_temperature(obj->data.i), TEMP_CELSIUS);
|
||||
temp_print(p, p_max_size, get_acpi_temperature(obj->data.i), TEMP_CELSIUS, 1);
|
||||
}
|
||||
|
||||
void free_acpitemp(struct text_object *obj) { close(obj->data.i); }
|
||||
|
@ -31,7 +31,7 @@
|
||||
#include "algebra.h"
|
||||
#include "bsdapm.h"
|
||||
#include "build.h"
|
||||
#include "cat.h"
|
||||
#include "misc.h"
|
||||
#include "colours.h"
|
||||
#include "combine.h"
|
||||
#include "core.h"
|
||||
@ -825,6 +825,11 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
|
||||
obj->callbacks.print = &print_scroll_led;
|
||||
#endif /* BUILD_X11 */
|
||||
|
||||
END OBJ(cap, 0)
|
||||
obj->data.s = strndup(arg ? arg : "", text_buffer_size.get(*state));
|
||||
obj->callbacks.print = &print_cap;
|
||||
obj->callbacks.free = &gen_free_opaque;
|
||||
|
||||
END OBJ(catp, 0)
|
||||
obj->data.s = strndup(arg ? arg : "", text_buffer_size.get(*state));
|
||||
obj->callbacks.print = &print_catp;
|
||||
|
@ -641,6 +641,9 @@ int update_diskio(void) {
|
||||
free(dev_select);
|
||||
}
|
||||
|
||||
if (statinfo_cur.dinfo->mem_ptr) {
|
||||
free(statinfo_cur.dinfo->mem_ptr);
|
||||
}
|
||||
free(statinfo_cur.dinfo);
|
||||
return 0;
|
||||
}
|
||||
|
@ -228,6 +228,6 @@ void print_hddtemp(struct text_object *obj, char *p, int p_max_size) {
|
||||
snprintf(p, p_max_size, "%s", "N/A");
|
||||
} else {
|
||||
temp_print(p, p_max_size, (double)val,
|
||||
(unit == 'C' ? TEMP_CELSIUS : TEMP_FAHRENHEIT));
|
||||
(unit == 'C' ? TEMP_CELSIUS : TEMP_FAHRENHEIT), 1);
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ void print_i8k_cpu_temp(struct text_object *obj, char *p, int p_max_size) {
|
||||
(void)obj;
|
||||
|
||||
sscanf(i8k.cpu_temp, "%d", &cpu_temp);
|
||||
temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS);
|
||||
temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS, 1);
|
||||
}
|
||||
|
||||
void print_i8k_right_fan_status(struct text_object *obj, char *p,
|
||||
|
@ -318,5 +318,5 @@ void parse_ibm_temps_arg(struct text_object *obj, const char *arg) {
|
||||
}
|
||||
|
||||
void print_ibm_temps(struct text_object *obj, char *p, int p_max_size) {
|
||||
temp_print(p, p_max_size, ibm_acpi_temps[obj->data.l], TEMP_CELSIUS);
|
||||
temp_print(p, p_max_size, ibm_acpi_temps[obj->data.l], TEMP_CELSIUS, 1);
|
||||
}
|
||||
|
17
src/linux.cc
17
src/linux.cc
@ -106,6 +106,10 @@ static conky::simple_config_setting<bool> top_cpu_separate("top_cpu_separate",
|
||||
* using a flag in this manner creates less confusing code. */
|
||||
static int prefer_proc = 0;
|
||||
|
||||
/* To tell 'print_sysfs_sensor' whether to print the temperature
|
||||
* in int or float */
|
||||
static const char *temp2 = "empty";
|
||||
|
||||
void prepare_update(void) {}
|
||||
|
||||
int update_uptime(void) {
|
||||
@ -1046,6 +1050,8 @@ static int open_sysfs_sensor(const char *dir, const char *dev, const char *type,
|
||||
type = "in";
|
||||
} else if (strcmp(type, "tempf") == 0) {
|
||||
type = "temp";
|
||||
} else if (strcmp(type, "temp2") == 0) {
|
||||
type = "temp";
|
||||
}
|
||||
|
||||
/* construct path */
|
||||
@ -1140,6 +1146,11 @@ static double get_sysfs_info(int *fd, int divisor, char *devtype, char *type) {
|
||||
|
||||
/* divide voltage and temperature by 1000 */
|
||||
/* or if any other divisor is given, use that */
|
||||
if (0 == (strcmp(type, "temp2"))) {
|
||||
temp2 = "temp2";
|
||||
} else {
|
||||
temp2 = "empty";
|
||||
}
|
||||
if (strcmp(type, "tempf") == 0) {
|
||||
if (divisor > 1) {
|
||||
return ((val / divisor + 40) * 9.0 / 5) - 40;
|
||||
@ -1226,8 +1237,10 @@ void print_sysfs_sensor(struct text_object *obj, char *p, int p_max_size) {
|
||||
|
||||
r = r * sf->factor + sf->offset;
|
||||
|
||||
if (!strncmp(sf->type, "temp", 4)) {
|
||||
temp_print(p, p_max_size, r, TEMP_CELSIUS);
|
||||
if (0 == (strcmp(temp2, "temp2"))) {
|
||||
temp_print(p, p_max_size, r, TEMP_CELSIUS, 0);
|
||||
} else if (!strncmp(sf->type, "temp", 4)) {
|
||||
temp_print(p, p_max_size, r, TEMP_CELSIUS, 1);
|
||||
} else if (r >= 100.0 || r == 0) {
|
||||
snprintf(p, p_max_size, "%d", (int)r);
|
||||
} else {
|
||||
|
@ -37,6 +37,8 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
static inline void read_file(const char *data, char *buf, const int size)
|
||||
@ -91,3 +93,23 @@ void print_catp(struct text_object *obj, char *p, int p_max_size)
|
||||
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
void print_cap(struct text_object *obj, char *p, int p_max_size) {
|
||||
int x = 0;
|
||||
int z = 0;
|
||||
char buf[p_max_size];
|
||||
char *src = obj->data.s;
|
||||
char *dest = buf;
|
||||
|
||||
for (; *src && p_max_size-1 > x; src++, x++) {
|
||||
if (0 == z) {
|
||||
*dest++ = (toupper((unsigned char) *src));
|
||||
z++;
|
||||
continue;
|
||||
}
|
||||
*dest++ = *src;
|
||||
if (' ' == *src) z = 0;
|
||||
}
|
||||
*dest = '\0';
|
||||
snprintf(p, p_max_size, "%s", buf);
|
||||
}
|
@ -28,12 +28,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _CAT_H
|
||||
#define _CAT_H
|
||||
#ifndef _MISC_H
|
||||
#define _MISC_H
|
||||
|
||||
#include "text_object.h"
|
||||
|
||||
void print_cat(struct text_object *, char *, int);
|
||||
void print_catp(struct text_object *, char *, int);
|
||||
void print_cap(struct text_object *, char *, int);
|
||||
|
||||
#endif /* _CAT_H */
|
||||
#endif /* _MISC_H */
|
@ -234,7 +234,9 @@ void mpd_cb::work() {
|
||||
mpd_info.is_playing = 1;
|
||||
mpd_info.bitrate = status->bitRate;
|
||||
mpd_info.progress =
|
||||
static_cast<float>(status->elapsedTime) / status->totalTime;
|
||||
((0 != status->totalTime) ?
|
||||
static_cast<float>(status->elapsedTime) / status->totalTime
|
||||
: 0.0);
|
||||
mpd_info.elapsed = status->elapsedTime;
|
||||
mpd_info.length = status->totalTime;
|
||||
} else {
|
||||
|
@ -489,7 +489,7 @@ void print_obsd_sensors_temp(struct text_object *obj, char *p, int p_max_size) {
|
||||
obsd_sensors.device = sensor_device.get(*state);
|
||||
update_obsd_sensors();
|
||||
temp_print(p, p_max_size, obsd_sensors.temp[obsd_sensors.device][obj->data.l],
|
||||
TEMP_CELSIUS);
|
||||
TEMP_CELSIUS, 1);
|
||||
}
|
||||
|
||||
void print_obsd_sensors_fan(struct text_object *obj, char *p, int p_max_size) {
|
||||
|
@ -240,7 +240,7 @@ void print_pid_nice(struct text_object *obj, char *p, int p_max_size) {
|
||||
|
||||
generate_text_internal(objbuf.get(), max_user_text.get(*state), *obj->sub);
|
||||
|
||||
if (*(obj->data.s) != 0) {
|
||||
if (!obj->data.s) {
|
||||
snprintf(pathbuf, 64, PROCDIR "/%d/stat", strtopid(objbuf.get()));
|
||||
buf = readfile(pathbuf, &bytes_read, 1);
|
||||
if (buf != nullptr) {
|
||||
|
@ -139,7 +139,7 @@ void print_smapi_bat_temp(struct text_object *obj, char *p, int p_max_size) {
|
||||
? smapi_get_bat_int(idx, "temperature")
|
||||
: 0;
|
||||
/* temperature is in milli degree celsius */
|
||||
temp_print(p, p_max_size, val / 1000, TEMP_CELSIUS);
|
||||
temp_print(p, p_max_size, val / 1000, TEMP_CELSIUS, 1);
|
||||
} else
|
||||
NORM_ERR("argument to smapi_bat_temp must be an integer");
|
||||
}
|
||||
|
@ -56,12 +56,17 @@ static double convert_temp_output(double n, enum TEMP_UNIT input_unit) {
|
||||
}
|
||||
|
||||
int temp_print(char *p, size_t p_max_size, double n,
|
||||
enum TEMP_UNIT input_unit) {
|
||||
int out;
|
||||
size_t plen;
|
||||
|
||||
out = round_to_int_temp(convert_temp_output(n, input_unit));
|
||||
plen = spaced_print(p, p_max_size, "%d", 3, out);
|
||||
enum TEMP_UNIT input_unit, int to_int) {
|
||||
int i_out = 0;
|
||||
float f_out = 0.0;
|
||||
size_t plen = 0;
|
||||
|
||||
if (1 == to_int) {
|
||||
i_out = round_to_int_temp(convert_temp_output(n, input_unit));
|
||||
plen = spaced_print(p, p_max_size, "%d", 3, i_out);
|
||||
} else {
|
||||
f_out = convert_temp_output(n, input_unit);
|
||||
plen = spaced_print(p, p_max_size, "%.2f", 3, f_out);
|
||||
}
|
||||
return static_cast<int>(!(plen >= p_max_size));
|
||||
}
|
||||
|
@ -28,6 +28,6 @@
|
||||
|
||||
enum TEMP_UNIT { TEMP_CELSIUS, TEMP_FAHRENHEIT };
|
||||
|
||||
int temp_print(char *, std::size_t, double, enum TEMP_UNIT);
|
||||
int temp_print(char *, std::size_t, double, enum TEMP_UNIT, int);
|
||||
|
||||
#endif /* TEMPHELPER_H */
|
||||
|
@ -721,9 +721,9 @@ static void weather_forecast_process_info(char *p, int p_max_size,
|
||||
std::lock_guard<std::mutex> lock(cb->result_mutex);
|
||||
const weather_forecast &data = cb->get_result();
|
||||
if (strcmp(data_type, "hi") == EQUAL) {
|
||||
temp_print(p, p_max_size, data[day].hi, TEMP_CELSIUS);
|
||||
temp_print(p, p_max_size, data[day].hi, TEMP_CELSIUS, 1);
|
||||
} else if (strcmp(data_type, "low") == EQUAL) {
|
||||
temp_print(p, p_max_size, data[day].low, TEMP_CELSIUS);
|
||||
temp_print(p, p_max_size, data[day].low, TEMP_CELSIUS, 1);
|
||||
} else if (strcmp(data_type, "icon") == EQUAL) {
|
||||
strncpy(p, data[day].icon.c_str(), p_max_size);
|
||||
} else if (strcmp(data_type, "forecast") == EQUAL) {
|
||||
@ -777,7 +777,7 @@ static void weather_process_info(char *p, int p_max_size,
|
||||
if (strcmp(data_type, "last_update") == EQUAL) {
|
||||
strncpy(p, data->lastupd.c_str(), p_max_size);
|
||||
} else if (strcmp(data_type, "temperature") == EQUAL) {
|
||||
temp_print(p, p_max_size, data->temp, TEMP_CELSIUS);
|
||||
temp_print(p, p_max_size, data->temp, TEMP_CELSIUS, 1);
|
||||
} else if (strcmp(data_type, "cloud_cover") == EQUAL) {
|
||||
#ifdef BUILD_WEATHER_XOAP
|
||||
if (data->xoap_t[0] != '\0') {
|
||||
|
Loading…
Reference in New Issue
Block a user