mirror of
https://github.com/gryf/wmtemp.git
synced 2025-12-18 12:00:26 +01:00
Using NVCtrlLib library instead of nvidia-settings program. Refactoring and
code cleanup. Changed version to 0.4.0
This commit is contained in:
@@ -366,7 +366,7 @@ void setMaskXY(int x, int y) {
|
|||||||
/*******************************************************************************\
|
/*******************************************************************************\
|
||||||
|* openXwindow *|
|
|* openXwindow *|
|
||||||
\*******************************************************************************/
|
\*******************************************************************************/
|
||||||
void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bits, int pixmask_width, int pixmask_height) {
|
void openXwindow(int argc, char *argv[], char *pixmap_bytes[], const char *pixmask_bits, int pixmask_width, int pixmask_height) {
|
||||||
|
|
||||||
unsigned int borderwidth = 1;
|
unsigned int borderwidth = 1;
|
||||||
XClassHint classHint;
|
XClassHint classHint;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ Display *display;
|
|||||||
void AddMouseRegion(int index, int left, int top, int right, int bottom);
|
void AddMouseRegion(int index, int left, int top, int right, int bottom);
|
||||||
int CheckMouseRegion(int x, int y);
|
int CheckMouseRegion(int x, int y);
|
||||||
|
|
||||||
void openXwindow(int argc, char *argv[], char **, char *, int, int);
|
void openXwindow(int argc, char *argv[], char **, const char *, int, int);
|
||||||
void RedrawWindow(void);
|
void RedrawWindow(void);
|
||||||
void RedrawWindowXY(int x, int y);
|
void RedrawWindowXY(int x, int y);
|
||||||
|
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ OBJ = $(SRC:.c=.o)
|
|||||||
|
|
||||||
CFLAGS = -Wall -O3
|
CFLAGS = -Wall -O3
|
||||||
|
|
||||||
LIB = -L/usr/X11R6/lib -lXpm -lXext -lX11 -lsensors
|
LIB = -I/usr/include/NVCtrl/ -L/usr/X11R6/lib -lXpm -lXext -lX11 -lsensors -lXNVCtrl
|
||||||
|
|
||||||
INSTALL = /usr/bin/install
|
INSTALL = /usr/bin/install
|
||||||
|
|
||||||
CC = gcc
|
CC = gcc
|
||||||
|
|
||||||
all: $(OBJ)
|
all: $(OBJ)
|
||||||
$(CC) -o $(EXE) $(OBJ) $(LIB)
|
$(CC) $(CFLAGS) -o $(EXE) $(OBJ) $(LIB)
|
||||||
strip $(EXE)
|
strip $(EXE)
|
||||||
|
|
||||||
$(OBJ): %.o : %.c
|
$(OBJ): %.o : %.c
|
||||||
|
|||||||
@@ -2,11 +2,10 @@
|
|||||||
* wmtempnv: a sensor monitor for WindowMaker. this little app is mainly based
|
* wmtempnv: a sensor monitor for WindowMaker. this little app is mainly based
|
||||||
* on wmsensormon and other simple dockapps.
|
* on wmsensormon and other simple dockapps.
|
||||||
*
|
*
|
||||||
* version = 0.1
|
* version = 0.4
|
||||||
* date: Fri Oct 31 20:41:14 CET 2008 @861 /Internet Time/
|
*
|
||||||
* author: Roman 'gryf' Dobosz
|
* requirements: configured lm_sensors, sensor program and
|
||||||
* requirements: configured lm_sensors and sensor program, nvidia-settings, cut,
|
* nvidia-settings package
|
||||||
* grep.
|
|
||||||
* licence: gpl
|
* licence: gpl
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -23,6 +22,9 @@
|
|||||||
#include "wmtempnv_master2.xpm"
|
#include "wmtempnv_master2.xpm"
|
||||||
#include "wmtempnv_mask.xbm"
|
#include "wmtempnv_mask.xbm"
|
||||||
|
|
||||||
|
#include <NVCtrl/NVCtrl.h>
|
||||||
|
#include <NVCtrl/NVCtrlLib.h>
|
||||||
|
|
||||||
#define MAXSTRLEN 8
|
#define MAXSTRLEN 8
|
||||||
#define TEMP 40
|
#define TEMP 40
|
||||||
#define TEMP_OVER 47
|
#define TEMP_OVER 47
|
||||||
@@ -31,35 +33,27 @@
|
|||||||
#define MAXFNAME 50
|
#define MAXFNAME 50
|
||||||
|
|
||||||
void display_values(int, int, int);
|
void display_values(int, int, int);
|
||||||
int get_temp(int core_number, int skip);
|
int get_temp(int core_number, Display*);
|
||||||
int get_offset(int temp, int cpu);
|
int get_offset(int temp, int cpu);
|
||||||
|
Display *display;
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
int temp1=0, temp2=0, temp3=0;
|
int temp1=0, temp2=0, temp3=0;
|
||||||
/* offset is one of 0 (normal), 7 (alert), 14 (warning) */
|
/* offset is one of 0 (normal), 7 (alert), 14 (warning) */
|
||||||
int offset1=0, offset2=0, offset3=0;
|
int offset1=0, offset2=0, offset3=0;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
int skip = 3;
|
display = XOpenDisplay(NULL);
|
||||||
|
|
||||||
/* nvclock.dpy = NULL; */
|
openXwindow(argc, argv, wmtempnv_master2_xpm, wmtempnv_mask_bits,
|
||||||
/* if(!init_nvclock()) return 0; */
|
wmtempnv_mask_width, wmtempnv_mask_height);
|
||||||
/* atexit(unload_nvclock); */
|
|
||||||
/* if(!set_card(0)) return 0; */
|
|
||||||
|
|
||||||
openXwindow(argc, argv, wmtempnv_master2_xpm, wmtempnv_mask_bits, wmtempnv_mask_width, wmtempnv_mask_height);
|
|
||||||
|
|
||||||
while(TRUE){
|
while(TRUE){
|
||||||
if(counter==0){
|
temp1 = get_temp(0, display);
|
||||||
skip--;
|
offset1 = get_offset(temp1, 1);
|
||||||
temp1 = get_temp(0, skip);
|
temp2 = get_temp(1, display);
|
||||||
offset1 = get_offset(temp1, 1);
|
offset2 = get_offset(temp2, 1);
|
||||||
temp2 = get_temp(1, skip);
|
temp3 = get_temp(2, display);
|
||||||
offset2 = get_offset(temp2, 1);
|
offset3 = get_offset(temp3, 0);
|
||||||
temp3 = get_temp(2, skip);
|
|
||||||
offset3 = get_offset(temp3, 0);
|
|
||||||
counter = 500;
|
|
||||||
if (skip == 0) skip = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
// core 1
|
// core 1
|
||||||
copyXPMArea(0, 87 + offset1, 23, 7, 4, 7); // LCD: "CPU"
|
copyXPMArea(0, 87 + offset1, 23, 7, 4, 7); // LCD: "CPU"
|
||||||
@@ -79,7 +73,7 @@ int main(int argc, char **argv){
|
|||||||
display_values(temp3, 28, offset3);
|
display_values(temp3, 28, offset3);
|
||||||
RedrawWindow();
|
RedrawWindow();
|
||||||
counter--;
|
counter--;
|
||||||
usleep(2000);
|
sleep(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,27 +112,20 @@ void display_values(int temp, int offset, int offset2){
|
|||||||
copyXPMArea(5 * num4, 65 + offset2, 5, 7, 51, 7 + offset);
|
copyXPMArea(5 * num4, 65 + offset2, 5, 7, 51, 7 + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_temp(int core_number, int skip){
|
int get_temp(int core_number, Display *disp){
|
||||||
// Core temperature. argument is core number. core no.2 is GPU
|
// Core temperature. argument is core number. core no.2 is GPU
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char filename[MAXFNAME];
|
char filename[MAXFNAME];
|
||||||
int core_temp = 0;
|
int core_temp = 0;
|
||||||
char gpu_cmd[] = "nvidia-settings -tq GPUCoreTemp";
|
Bool res;
|
||||||
|
|
||||||
/* if(core_number == 2 && skip > 0){ */
|
|
||||||
if(core_number == 2){
|
if(core_number == 2){
|
||||||
printf("%d\n", skip);
|
|
||||||
// GPU
|
res = XNVCTRLQueryTargetAttribute(disp,
|
||||||
file = popen(gpu_cmd, "r");
|
NV_CTRL_TARGET_TYPE_GPU, 0, 0,
|
||||||
while (!feof(file)) {
|
NV_CTRL_GPU_CORE_TEMPERATURE, &core_temp);
|
||||||
char line[MAXSTRLEN + 1];
|
|
||||||
bzero(line, MAXSTRLEN + 1);
|
if (res == False) core_temp = 0;
|
||||||
fgets(line, MAXSTRLEN, file);
|
|
||||||
if(line[0] != 0){
|
|
||||||
sscanf(line, "%d", &core_temp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pclose(file);
|
|
||||||
}else{
|
}else{
|
||||||
snprintf(filename, MAXFNAME,
|
snprintf(filename, MAXFNAME,
|
||||||
"/sys/bus/platform/devices/coretemp.0/temp%d_input",
|
"/sys/bus/platform/devices/coretemp.0/temp%d_input",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#define wmtempnv_mask_width 64
|
#define wmtempnv_mask_width 64
|
||||||
#define wmtempnv_mask_height 64
|
#define wmtempnv_mask_height 64
|
||||||
static unsigned char wmtempnv_mask_bits[] = {
|
static const char wmtempnv_mask_bits[] = {
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
|||||||
Reference in New Issue
Block a user