diff --git a/src/ya_draw.c b/src/ya_draw.c index 935f7cf..4afd215 100644 --- a/src/ya_draw.c +++ b/src/ya_draw.c @@ -64,14 +64,35 @@ void ya_create_block(ya_block_t *blk) { int ya_create_bar(ya_bar_t * bar) { bar->win = xcb_generate_id(ya.c); int x, y; +#ifdef YABAR_RANDR + if ((ya.gen_flag & GEN_RANDR)) + x = bar->hgap + bar->mon->pos.x; + else + x = bar->hgap; +#else x = bar->hgap; +#endif //YABAR_RANDR switch(bar->position){ case YA_TOP:{ +#ifdef YABAR_RANDR + if ((ya.gen_flag & GEN_RANDR)) + y = bar->vgap + bar->mon->pos.y; + else + y = bar->vgap; +#else y = bar->vgap; +#endif //YABAR_RANDR break; } case YA_BOTTOM: { +#ifdef YABAR_RANDR + if ((ya.gen_flag & GEN_RANDR)) + y = bar->mon->pos.height - bar->vgap - bar->height; + else + y = ya.scr->height_in_pixels - bar->vgap - bar->height; +#else y = ya.scr->height_in_pixels - bar->vgap - bar->height; +#endif //YABAR_RANDR break; } } diff --git a/src/ya_exec.c b/src/ya_exec.c index 5e4c021..b05112e 100644 --- a/src/ya_exec.c +++ b/src/ya_exec.c @@ -180,6 +180,17 @@ void ya_setup_bar(config_setting_t * set) { bar->position = YA_TOP; } } +#ifdef YABAR_RANDR + retcnf = config_setting_lookup_string(set, "monitor", &retstr); + if(retcnf == CONFIG_FALSE) { + //TODO + } + else { + if((ya.gen_flag & GEN_RANDR)) { + bar->mon = ya_get_monitor_from_name(retstr); + } + } +#endif //YABAR_RANDR retcnf = config_setting_lookup_int(set, "gap-horizontal", &retint); if(retcnf == CONFIG_FALSE) { @@ -198,14 +209,23 @@ void ya_setup_bar(config_setting_t * set) { } retcnf = config_setting_lookup_int(set, "height", &retint); if(retcnf == CONFIG_FALSE) { - bar->height = 30; + bar->height = 20; } else { bar->height = retint; } retcnf = config_setting_lookup_int(set, "width", &retint); if(retcnf == CONFIG_FALSE) { +#ifdef YABAR_RANDR + if(bar->mon) { + bar->width = bar->mon->pos.width - 2*(bar->hgap); + } + else { + bar->width = ya.scr->width_in_pixels - 2*(bar->hgap); + } +#else bar->width = ya.scr->width_in_pixels - 2*(bar->hgap); +#endif //YABAR_RANDR } else { bar->width = retint; @@ -545,11 +565,13 @@ int ya_init_randr() { tmpmon->prev_mon = ya.curmon; } ya.curmon = tmpmon; + //printf("%s %d %d %d %d\n", tmpmon->name, tmpmon->pos.x, + // tmpmon->pos.y, tmpmon->pos.width, tmpmon->pos.height); } return 0; } -ya_monitor_t * ya_get_monitor_from_name(char * name) { +ya_monitor_t * ya_get_monitor_from_name(const char *name) { ya_monitor_t *mon = ya.curmon; if (mon == NULL) return NULL; diff --git a/src/yabar.h b/src/yabar.h index dc87e45..76acbed 100644 --- a/src/yabar.h +++ b/src/yabar.h @@ -6,8 +6,8 @@ * */ -#ifndef _YABAR_H -#define _YABAR_H +#ifndef YABAR_H +#define YABAR_H #include #define __USE_XOPEN2K //for setenv implicit function decleration warning @@ -35,6 +35,7 @@ #endif + #define BUFSIZE 512 #define CFILELEN 256 #define YA_DEF_FONT "sans bold 9" @@ -78,6 +79,19 @@ enum { BLKA_OVERLINE = 1<<13 }; +#ifdef YABAR_RANDR + +#define CMONLEN 16 + +typedef struct ya_monitor ya_monitor_t; +struct ya_monitor { + char name[CMONLEN]; + xcb_rectangle_t pos; + struct ya_monitor *prev_mon; + struct ya_monitor *next_mon; +}; +#endif // YABAR_RANDR + typedef struct ya_bar ya_bar_t; struct ya_block { char buf [BUFSIZE]; @@ -132,6 +146,10 @@ struct ya_bar { uint8_t ulsize; uint8_t olsize; uint8_t slack; + +#ifdef YABAR_RANDR + ya_monitor_t *mon; +#endif //YABAR_RANDR }; //typedef struct ya_bar ya_bar_t; @@ -141,19 +159,6 @@ enum { GEN_RANDR = 1 << 1 }; -#ifdef YABAR_RANDR - -#define CMONLEN 16 - -typedef struct ya_monitor ya_monitor_t; -struct ya_monitor { - char name[CMONLEN]; - xcb_rectangle_t pos; - struct ya_monitor *prev_mon; - struct ya_monitor *next_mon; -}; -#endif // YABAR_RANDR - struct yabar_gen_info { xcb_connection_t *c; xcb_screen_t *scr; @@ -188,4 +193,7 @@ void ya_create_block(ya_block_t *blk); ya_block_t * ya_get_blk_from_event( xcb_button_press_event_t *eb); void ya_process_opt(int argc, char *argv[]); int ya_init_randr(); -#endif /*_YABAR_H*/ +#ifdef YABAR_RANDR +ya_monitor_t * ya_get_monitor_from_name(const char *name); +#endif //YABAR_RANDR +#endif /*YABAR_H*/