Beispiel #1
0
/*
 * similar to any ya_exec function in this file, this function is used to obtain text buffer and
 * draw it. However, this function is called upon X events.
 */
inline static void ya_exec_intern_ewmh_blk(ya_block_t *blk) {
	switch(blk->internal->index) {
		case YA_INT_TITLE: {
			ya_get_cur_window_title(blk);
//#ifdef YA_MUTEX
//			pthread_mutex_lock(&blk->mutex);
//#endif
#ifdef YA_VAR_WIDTH
			DRAW_TEXT(blk);
#else
			ya_draw_pango_text(blk);
#endif //YA_VAR_WIDTH
//#ifdef YA_MUTEX
//			pthread_mutex_unlock(&blk->mutex);
//#endif
			break;
		}
		case YA_INT_WORKSPACE: {
			//uint32_t current_desktop;
			//xcb_get_property_cookie_t ck = xcb_ewmh_get_current_desktop(ya.ewmh, 0);
			//xcb_ewmh_get_current_desktop_reply(ya.ewmh, ck, &current_desktop, NULL);
			if(blk->internal->option[0]==NULL)
				sprintf(blk->buf, "%u", ya.curws+1);
			else {
				ya_copy_buf_from_index(blk, ya.curws);
			}

//#ifdef YA_MUTEX
//			pthread_mutex_lock(&blk->mutex);
//#endif
#ifdef YA_VAR_WIDTH
			DRAW_TEXT(blk);
#else
			ya_draw_pango_text(blk);
#endif //YA_VAR_WIDTH
//#ifdef YA_MUTEX
//			pthread_mutex_unlock(&blk->mutex);
//#endif
			break;
		}
	}

}
Beispiel #2
0
void ya_int_thermal(ya_block_t *blk) {
	FILE *tfile;
	int temp, wrntemp, crttemp, space;
	uint32_t wrnbg, wrnfg; //warning colors
	uint32_t crtbg, crtfg; //critical colors
	char *startstr = blk->buf;
	size_t prflen=0,suflen=0;
	ya_setup_prefix_suffix(blk, &prflen, &suflen, &startstr);
	if(blk->internal->spacing)
		space = 3;
	else
		space = 0;
	char fpath[128];
	snprintf(fpath, 128, "/sys/class/thermal/%s/temp", blk->internal->option[0]);

	if((blk->internal->option[1]==NULL) ||
			(sscanf(blk->internal->option[1], "%d %u %u", &crttemp, &crtfg, &crtbg)!=3)) {
		crttemp = 70;
		crtbg = 0xFFED303C;
		crtfg = blk->fgcolor;
	}
	if((blk->internal->option[2]==NULL) ||
			(sscanf(blk->internal->option[2], "%d %u %u", &wrntemp, &wrnfg, &wrnbg)!=3)) {
		wrntemp = 58;
		wrnbg = 0xFFF4A345;
		wrnfg = blk->fgcolor;
	}
	tfile = fopen(fpath, "r");
	if (tfile == NULL) {
		fprintf(stderr, "Error opening file %s\n", fpath);
		strncpy(blk->buf, "BLOCK ERROR!", strlen("BLOCK ERROR!"));
		ya_draw_pango_text(blk);
		pthread_detach(blk->thread);
		pthread_exit(NULL);
	}
	fclose(tfile);
	while (1) {
		tfile = fopen(fpath, "r");
		if(fscanf(tfile, "%d", &temp) != 1) {
			fprintf(stderr, "Error getting values from file (%s)\n", fpath);
		}
		temp/=1000;

#ifdef YA_DYN_COL
		if(temp > crttemp) {
			blk->bgcolor = crtbg;
			xcb_change_gc(ya.c, blk->gc, XCB_GC_FOREGROUND, (const uint32_t[]){crtbg});
			blk->attr |= BLKA_DIRTY_COL;
			blk->fgcolor = crtfg;
		}
Beispiel #3
0
void ya_int_date(ya_block_t * blk) {
	time_t rawtime;
	struct tm * ya_tm;
	char *startstr = blk->buf;
	size_t prflen=0,suflen=0;
	ya_setup_prefix_suffix(blk, &prflen, &suflen, &startstr);
	while(1) {
		time(&rawtime);
		ya_tm = localtime(&rawtime);
		strftime(startstr, 100, blk->internal->option[0], ya_tm);
		if(suflen)
			strcat(blk->buf, blk->internal->suffix);
		ya_draw_pango_text(blk);
		sleep(blk->sleep);
	}
}
Beispiel #4
0
static void ya_exec_redir_persist(ya_block_t *blk) {
	int opipe[2];
	if(pipe(opipe)==-1) {
		fprintf(stderr, "Error opening pipe for block %s.%s. Terminating block's thread...\n", blk->bar->name, blk->name);
		pthread_detach(blk->thread);
		pthread_exit(NULL);
	}
	pid_t pid = fork();
	if (pid == 0) {
		dup2(opipe[1], STDOUT_FILENO);
		close(opipe[1]);
		setvbuf(stdout,NULL,_IONBF,0);

		execl(yashell, yashell, "-c", blk->cmd, (char *) NULL);
		_exit(EXIT_SUCCESS);
	}
	blk->pid = pid;
	close(opipe[1]);

	ssize_t read_ret;
	while (1) {
		read_ret = read(opipe[0], blk->buf, blk->bufsize);
		if(read_ret == 0) {
			break;
		} else if (read_ret < 0) {
			fprintf(stderr, "Error with block %s: %s\n", blk->name, strerror(errno));
			continue;
		} else {
			blk->buf[read_ret] = '\0';
#ifdef YA_DYN_COL
			ya_buf_color_parse(blk);
#endif

//#ifdef YA_MUTEX
//			pthread_mutex_lock(&blk->mutex);
//#endif
#ifdef YA_VAR_WIDTH
			DRAW_TEXT(blk);
#else
			ya_draw_pango_text(blk);
#endif //YA_VAR_WIDTH
//#ifdef YA_MUTEX
//			pthread_mutex_unlock(&blk->mutex);
//#endif
		}
	}
}
Beispiel #5
0
void ya_int_uptime(ya_block_t *blk) {
	struct sysinfo ya_sysinfo;
	long hr, tmp;
	uint8_t min;
	char *startstr = blk->buf;
	size_t prflen=0,suflen=0;
	ya_setup_prefix_suffix(blk, &prflen, &suflen, &startstr);
	while(1) {
		sysinfo(&ya_sysinfo);
		tmp = ya_sysinfo.uptime;
		hr = tmp/3600;
		tmp %= 3600;
		min = tmp/60;
		//tmp %= 60;
		sprintf(startstr, "%ld:%02d", hr, min);
		if(suflen)
			strcat(blk->buf, blk->internal->suffix);
		ya_draw_pango_text(blk);
		sleep(blk->sleep);
	}
}