Fix indentation inconsistencies

This commit is contained in:
geommer 2016-03-15 05:30:07 +02:00
parent 53ad261911
commit 9967a0de81
4 changed files with 153 additions and 157 deletions

View file

@ -97,8 +97,8 @@ int ya_create_bar(ya_bar_t * bar) {
xcb_visualtype_t * ya_get_visualtype() {
xcb_depth_iterator_t depth_iter;
xcb_visualtype_t *vist;
depth_iter = xcb_screen_allowed_depths_iterator (ya.scr);
for (; depth_iter.rem; xcb_depth_next (&depth_iter)) {
depth_iter = xcb_screen_allowed_depths_iterator (ya.scr);
for (; depth_iter.rem; xcb_depth_next (&depth_iter)) {
xcb_visualtype_iterator_t visual_iter;
visual_iter = xcb_depth_visuals_iterator (depth_iter.data);
for (; visual_iter.rem; xcb_visualtype_next (&visual_iter)) {
@ -106,7 +106,6 @@ xcb_visualtype_t * ya_get_visualtype() {
}
}
return vist;
}
void ya_draw_pango_text(struct ya_block *blk) {
@ -174,66 +173,65 @@ void ya_draw_pango_text(struct ya_block *blk) {
enum {
NET_WM_WINDOW_TYPE,
NET_WM_WINDOW_TYPE_DOCK,
NET_WM_DESKTOP,
NET_WM_STRUT_PARTIAL,
NET_WM_STRUT,
NET_WM_STATE,
NET_WM_STATE_STICKY,
NET_WM_STATE_ABOVE,
NET_WM_WINDOW_TYPE,
NET_WM_WINDOW_TYPE_DOCK,
NET_WM_DESKTOP,
NET_WM_STRUT_PARTIAL,
NET_WM_STRUT,
NET_WM_STATE,
NET_WM_STATE_STICKY,
NET_WM_STATE_ABOVE,
};
void ya_setup_ewmh(ya_bar_t *bar) {
// I really hope I understood this from lemonbar code :|
const char *atom_names[] = {
"_NET_WM_WINDOW_TYPE",
"_NET_WM_WINDOW_TYPE_DOCK",
"_NET_WM_DESKTOP",
"_NET_WM_STRUT_PARTIAL",
"_NET_WM_STRUT",
"_NET_WM_STATE",
"_NET_WM_STATE_STICKY",
"_NET_WM_STATE_ABOVE",
};
const int atoms = sizeof(atom_names)/sizeof(char *);
xcb_intern_atom_cookie_t atom_cookie[atoms];
xcb_atom_t atom_list[atoms];
xcb_intern_atom_reply_t *atom_reply;
// I really hope I understood this correctly from lemonbar code :|
const char *atom_names[] = {
"_NET_WM_WINDOW_TYPE",
"_NET_WM_WINDOW_TYPE_DOCK",
"_NET_WM_DESKTOP",
"_NET_WM_STRUT_PARTIAL",
"_NET_WM_STRUT",
"_NET_WM_STATE",
"_NET_WM_STATE_STICKY",
"_NET_WM_STATE_ABOVE",
};
const int atoms = sizeof(atom_names)/sizeof(char *);
xcb_intern_atom_cookie_t atom_cookie[atoms];
xcb_atom_t atom_list[atoms];
xcb_intern_atom_reply_t *atom_reply;
for (int i = 0; i < atoms; i++)
atom_cookie[i] = xcb_intern_atom(ya.c, 0, strlen(atom_names[i]), atom_names[i]);
for (int i = 0; i < atoms; i++)
atom_cookie[i] = xcb_intern_atom(ya.c, 0, strlen(atom_names[i]), atom_names[i]);
for (int i = 0; i < atoms; i++) {
atom_reply = xcb_intern_atom_reply(ya.c, atom_cookie[i], NULL);
if (!atom_reply)
return;
atom_list[i] = atom_reply->atom;
free(atom_reply);
}
for (int i = 0; i < atoms; i++) {
atom_reply = xcb_intern_atom_reply(ya.c, atom_cookie[i], NULL);
if (!atom_reply)
return;
atom_list[i] = atom_reply->atom;
free(atom_reply);
}
int strut[12];
int strut[12];
if (bar->position == YA_TOP) {
strut[2] = bar->height;
strut[8] = bar->hgap;
strut[9] = bar->hgap + bar->width;
}
else if (bar->position == YA_BOTTOM) {
strut[3] = bar->height;
strut[10] = bar->hgap;
strut[11] = bar->hgap + bar->width;
}
else {
//TODO right and left bars if implemented.
}
if (bar->position == YA_TOP) {
strut[2] = bar->height;
strut[8] = bar->hgap;
strut[9] = bar->hgap + bar->width;
}
else if (bar->position == YA_BOTTOM) {
strut[3] = bar->height;
strut[10] = bar->hgap;
strut[11] = bar->hgap + bar->width;
}
else {
//TODO right and left bars if implemented.
}
xcb_change_property(ya.c, XCB_PROP_MODE_REPLACE, bar->win, atom_list[NET_WM_WINDOW_TYPE], XCB_ATOM_ATOM, 32, 1, &atom_list[NET_WM_WINDOW_TYPE_DOCK]);
xcb_change_property(ya.c, XCB_PROP_MODE_APPEND, bar->win, atom_list[NET_WM_STATE], XCB_ATOM_ATOM, 32, 2, &atom_list[NET_WM_STATE_STICKY]);
xcb_change_property(ya.c, XCB_PROP_MODE_REPLACE, bar->win, atom_list[NET_WM_DESKTOP], XCB_ATOM_CARDINAL, 32, 1, (const uint32_t []){ -1 } );
xcb_change_property(ya.c, XCB_PROP_MODE_REPLACE, bar->win, atom_list[NET_WM_STRUT_PARTIAL], XCB_ATOM_CARDINAL, 32, 12, strut);
xcb_change_property(ya.c, XCB_PROP_MODE_REPLACE, bar->win, atom_list[NET_WM_STRUT], XCB_ATOM_CARDINAL, 32, 4, strut);
xcb_change_property(ya.c, XCB_PROP_MODE_REPLACE, bar->win, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, strlen("Yabar"), "Yabar");
xcb_change_property(ya.c, XCB_PROP_MODE_REPLACE, bar->win, atom_list[NET_WM_WINDOW_TYPE], XCB_ATOM_ATOM, 32, 1, &atom_list[NET_WM_WINDOW_TYPE_DOCK]);
xcb_change_property(ya.c, XCB_PROP_MODE_APPEND, bar->win, atom_list[NET_WM_STATE], XCB_ATOM_ATOM, 32, 2, &atom_list[NET_WM_STATE_STICKY]);
xcb_change_property(ya.c, XCB_PROP_MODE_REPLACE, bar->win, atom_list[NET_WM_DESKTOP], XCB_ATOM_CARDINAL, 32, 1, (const uint32_t []){ -1 } );
xcb_change_property(ya.c, XCB_PROP_MODE_REPLACE, bar->win, atom_list[NET_WM_STRUT_PARTIAL], XCB_ATOM_CARDINAL, 32, 12, strut);
xcb_change_property(ya.c, XCB_PROP_MODE_REPLACE, bar->win, atom_list[NET_WM_STRUT], XCB_ATOM_CARDINAL, 32, 4, strut);
xcb_change_property(ya.c, XCB_PROP_MODE_REPLACE, bar->win, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, strlen("Yabar"), "Yabar");
}

View file

@ -14,88 +14,86 @@ static const char * const yashell = "/bin/sh";
static void ya_exec_redir_once(ya_block_t *blk) {
int opipe[2];
pipe(opipe);
if (fork() == 0) {
dup2(opipe[1], STDOUT_FILENO);
close(opipe[1]);
setvbuf(stdout,NULL,_IONBF,0);
if (fork() == 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);
execl(yashell, yashell, "-c", blk->cmd, (char *) NULL);
exit(EXIT_SUCCESS);
}
else {
wait(NULL);
else {
wait(NULL);
if (read(opipe[0], blk->buf, BUFSIZE) != 0) {
ya_draw_pango_text(blk);
}
}
ya_draw_pango_text(blk);
}
}
}
static void ya_exec_redir_period(ya_block_t *blk) {
int opipe[2];
pipe(opipe);
while (1) {
if (fork() == 0) {
dup2(opipe[1], STDOUT_FILENO);
close(opipe[1]);
setvbuf(stdout,NULL,_IONBF,0);
while (1) {
if (fork() == 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);
}
execl(yashell, yashell, "-c", blk->cmd, (char *) NULL);
exit(EXIT_SUCCESS);
}
//close(opipe[1]);
wait(NULL);
if (read(opipe[0], blk->buf, BUFSIZE) != 0) {
ya_draw_pango_text(blk);
memset(blk->buf, '\0', BUFSIZE);
}
sleep(blk->sleep);
}
ya_draw_pango_text(blk);
memset(blk->buf, '\0', BUFSIZE);
}
sleep(blk->sleep);
}
}
static void ya_exec_redir_persist(ya_block_t *blk) {
int opipe[2];
pipe(opipe);
if (fork() == 0) {
dup2(opipe[1], STDOUT_FILENO);
close(opipe[1]);
setvbuf(stdout,NULL,_IONBF,0);
if (fork() == 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);
execl(yashell, yashell, "-c", blk->cmd, (char *) NULL);
_exit(EXIT_SUCCESS);
}
close(opipe[1]);
while (read(opipe[0], blk->buf, BUFSIZE) != 0) {
ya_draw_pango_text(blk);
memset(blk->buf, '\0', BUFSIZE);
}
ya_draw_pango_text(blk);
memset(blk->buf, '\0', BUFSIZE);
}
}
void * ya_exec_l (void * _blk) {
ya_block_t *blk = (ya_block_t *) _blk;
if (blk->type & BLKA_EXTERNAL) {
if (blk->type & BLKA_PERIODIC) {
ya_exec_redir_period(blk);
}
else if (blk->type & BLKA_PERSIST) {
ya_exec_redir_persist(blk);
}
else if (blk->type & BLKA_ONCE) {
ya_exec_redir_once(blk);
}
/*Shouldn't get here*/
else {
}
}
else if (blk->type & BLKA_INTERNAL) {
/*TODO*/
}
/*Shouldn't get here*/
else {
}
return NULL;
ya_block_t *blk = (ya_block_t *) _blk;
if (blk->type & BLKA_EXTERNAL) {
if (blk->type & BLKA_PERIODIC) {
ya_exec_redir_period(blk);
}
else if (blk->type & BLKA_PERSIST) {
ya_exec_redir_persist(blk);
}
else if (blk->type & BLKA_ONCE) {
ya_exec_redir_once(blk);
}
/*Shouldn't get here*/
else {
}
}
else if (blk->type & BLKA_INTERNAL) {
/*TODO*/
}
/*Shouldn't get here*/
else {
}
return NULL;
}
@ -222,8 +220,10 @@ void ya_setup_bar(config_setting_t * set) {
}
ya_create_bar(bar);
}
#define YA_RESERVED_NUM 1
char *ya_reserved_blocks[YA_RESERVED_NUM]={"ya_time"};
void ya_setup_block(config_setting_t * set, uint32_t type_init) {
struct ya_block * blk = calloc(1,sizeof(ya_block_t));
int retcnf, retint;
@ -235,15 +235,15 @@ void ya_setup_block(config_setting_t * set, uint32_t type_init) {
return;
}
else {
int len = strlen(retstr);
if (len) {
blk->cmd = malloc(len);
strcpy(blk->cmd, retstr);
}
else {
free(blk);
return;
}
int len = strlen(retstr);
if (len) {
blk->cmd = malloc(len);
strcpy(blk->cmd, retstr);
}
else {
free(blk);
return;
}
}
retcnf = config_setting_lookup_string(set, "command-button1", &retstr);
if(retcnf == CONFIG_TRUE) {
@ -441,42 +441,42 @@ void ya_execute() {
void ya_exec_cmd(char * cmd) {
if (fork() == 0) {
execl(yashell, yashell, "-c", cmd, (char *) NULL);
_exit(EXIT_SUCCESS);
}
else
wait(NULL);
execl(yashell, yashell, "-c", cmd, (char *) NULL);
_exit(EXIT_SUCCESS);
}
else
wait(NULL);
}
void ya_process_path(char *cpath) {
struct stat st;
if (stat(cpath, &st)==0) {
strncpy(conf_file, cpath, CFILELEN);
ya.gen_flag |= GEN_EXT_CONF;
}
else {
printf("Invalid config file path.\nExiting...\n");
exit(EXIT_SUCCESS);
}
struct stat st;
if (stat(cpath, &st)==0) {
strncpy(conf_file, cpath, CFILELEN);
ya.gen_flag |= GEN_EXT_CONF;
}
else {
printf("Invalid config file path.\nExiting...\n");
exit(EXIT_SUCCESS);
}
}
void ya_process_opt(int argc, char *argv[]) {
char opt;
char opt;
while ((opt = getopt(argc, argv, "cvh")) != (char)-1) {
switch (opt) {
case 'c':
ya_process_path(*(argv+2));
break;
case 'h':
printf("Usage: yabar [-c CONFIG_FILE] [-h] [-v]\n");
exit(EXIT_SUCCESS);
case 'v':
printf ("%s\n", "0.1.0-alpha");
exit(EXIT_SUCCESS);
default:
break;
}
}
while ((opt = getopt(argc, argv, "cvh")) != (char)-1) {
switch (opt) {
case 'c':
ya_process_path(*(argv+2));
break;
case 'h':
printf("Usage: yabar [-c CONFIG_FILE] [-h] [-v]\n");
exit(EXIT_SUCCESS);
case 'v':
printf ("%s\n", "0.1.0-alpha");
exit(EXIT_SUCCESS);
default:
break;
}
}
}

View file

@ -12,9 +12,7 @@
yabar_info_t ya;
int main (int argc, char * argv[]) {
ya_process_opt(argc, argv);
ya_process_opt(argc, argv);
ya_init();
ya_execute();
@ -37,7 +35,7 @@ int main (int argc, char * argv[]) {
}
free(ev);
}
//shouldn't get here
//shouldn't get here
xcb_disconnect(ya.c);
}

View file

@ -129,7 +129,7 @@ struct ya_bar {
typedef struct ya_bar ya_bar_t;
enum {
GEN_EXT_CONF = 1 << 0
GEN_EXT_CONF = 1 << 0
};
struct yabar_gen_info {