From 077d60c3d40a693c1c5578190fd593298c1087fd Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Mon, 1 Dec 2008 01:37:34 +0100 Subject: [PATCH] config/screen: Multi-Head support: Add screen option in tag {} in the configuration file, Improved other things... --- CMakeLists.txt | 3 +-- src/config.c | 69 ++++++++++++++++++++++++++------------------------ src/event.c | 8 +++--- src/infobar.c | 16 ++++++++---- src/layout.c | 2 -- src/screen.c | 4 +-- src/structs.h | 2 +- src/tag.c | 4 +-- 8 files changed, 57 insertions(+), 51 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b46bc7d..8ced6a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,8 +99,7 @@ pkg_check_modules(wmfs_required x11 libconfuse freetype2 - xft - xinerama) + xft) # Find exterbal programs macro(a_find_program var prg req) diff --git a/src/config.c b/src/config.c index a58fa78..badf05b 100644 --- a/src/config.c +++ b/src/config.c @@ -63,7 +63,7 @@ static cfg_opt_t bar_opts[] = static cfg_opt_t mouse_button_opts[] = { - CFG_INT("tag", -1, CFGF_NONE), + CFG_INT("tag", 0, CFGF_NONE), CFG_STR("button", "Button1", CFGF_NONE), CFG_STR("func", "", CFGF_NONE), CFG_STR("cmd", "", CFGF_NONE), @@ -115,6 +115,7 @@ static cfg_opt_t layouts_opts[] = static cfg_opt_t tag_opts[] = { + CFG_INT("screen", 0, CFGF_NONE), CFG_STR("name", "", CFGF_NONE), CFG_FLOAT("mwfact", 0.65, CFGF_NONE), CFG_INT("nmaster", 1, CFGF_NONE), @@ -449,50 +450,52 @@ init_conf(void) } } - /* tag - * if there is no tag in the conf or more than + /* Tag + * If there is no tag in the conf or more than * MAXTAG (32) print an error and create only one. */ conf.colors.tagselfg = strdup(var_to_str(cfg_getstr(cfg_tags, "sel_fg"))); conf.colors.tagselbg = getcolor(var_to_str(cfg_getstr(cfg_tags, "sel_bg"))); conf.colors.tagbord = getcolor(var_to_str(cfg_getstr(cfg_tags, "border"))); - conf.ntag = cfg_size(cfg_tags, "tag"); - if(!conf.ntag || conf.ntag > MAXTAG) + /* Alloc all */ + conf.ntag = emalloc(screen_count(), sizeof(int)); + tags = emalloc(screen_count(), sizeof(Tag*)); + for(i = 0; i < screen_count(); ++i) + tags[i] = emalloc(cfg_size(cfg_tags, "tag") + 1, sizeof(Tag)); + + for(i = 0; i < cfg_size(cfg_tags, "tag"); ++i) { - fprintf(stderr, "WMFS Configuration: Too many or no tag" - " (%d) in the configration file\n", conf.ntag); - conf.ntag = 1; - conf.tag[0].name = strdup("WMFS"); - conf.tag[0].mwfact = 0.65; - conf.tag[0].nmaster = 1; - conf.tag[0].resizehint = False; - conf.tag[0].layout = layout_name_to_struct(conf.layout, "tile_right", conf.nlayout); - } - else - { - for(i = 0; i < conf.ntag; ++i) - { - cfgtmp = cfg_getnsec(cfg_tags, "tag", i); - if(strlen(strdup(cfg_getstr(cfgtmp, "name"))) > 256) - fprintf(stderr, "WMFS Configuration: name of tag %d too long !\n", i); - conf.tag[i].name = strdup(cfg_getstr(cfgtmp, "name")); - conf.tag[i].mwfact = cfg_getfloat(cfgtmp, "mwfact"); - conf.tag[i].nmaster = cfg_getint(cfgtmp, "nmaster"); - conf.tag[i].resizehint = cfg_getbool(cfgtmp, "resizehint"); - conf.tag[i].layout = layout_name_to_struct(conf.layout, cfg_getstr(cfgtmp, "layout"), conf.nlayout); - } + cfgtmp = cfg_getnsec(cfg_tags, "tag", i); + j = cfg_getint(cfgtmp, "screen"); + if(j < 0 || j > screen_count() - 1) + j = 0; + ++conf.ntag[j]; + + tags[j][conf.ntag[j]].name = strdup(cfg_getstr(cfgtmp, "name")); + tags[j][conf.ntag[j]].mwfact = cfg_getfloat(cfgtmp, "mwfact"); + tags[j][conf.ntag[j]].nmaster = cfg_getint(cfgtmp, "nmaster"); + tags[j][conf.ntag[j]].resizehint = cfg_getbool(cfgtmp, "resizehint"); + tags[j][conf.ntag[j]].layout = layout_name_to_struct(conf.layout, cfg_getstr(cfgtmp, "layout"), conf.nlayout); } + for(i = 0; i < screen_count(); ++i) + if(!conf.ntag[i] || conf.ntag[i] > MAXTAG) + { + fprintf(stderr, "WMFS Configuration: Too many or no tag" + " (%d) in the screen %d\n", conf.ntag[i], i); + + conf.ntag[i] = 1; + tags[i][1].name = strdup("WMFS"); + tags[i][1].mwfact = 0.50; + tags[i][1].nmaster = 1; + tags[i][1].resizehint = False; + tags[i][1].layout = layout_name_to_struct(conf.layout, "tile_right", conf.nlayout); + } + seltag = emalloc(screen_count(), sizeof(int)); - tags = emalloc(screen_count(), sizeof(Tag*)); for(j = 0; j < screen_count(); ++j) - { - tags[j] = emalloc(conf.ntag + 1, sizeof(Tag)); seltag[j] = 1; - for(i = 0; i < conf.ntag; ++i) - tags[j][i + 1] = conf.tag[i]; - } /* keybind */ conf.nkeybind = cfg_size(cfg_keys, "key"); diff --git a/src/event.c b/src/event.c index 7684f40..f2e5de0 100644 --- a/src/event.c +++ b/src/event.c @@ -72,10 +72,10 @@ buttonpress(XButtonEvent *ev) conf.root.mouse[i].func(conf.root.mouse[i].cmd); /* Tag */ - for(i = 1; i < conf.ntag + 1; ++i) + for(i = 1; i < conf.ntag[screen_get_sel()]+ 1; ++i) { ITOA(s, i); - if(ev->window == infobar[screen_get_sel()].tags[i]->win) + if(ev->window == infobar[selscreen].tags[i]->win) { if(ev->button == Button1) uicb_tag(s); @@ -89,7 +89,7 @@ buttonpress(XButtonEvent *ev) } /* Layout button */ - if(ev->window == infobar[screen_get_sel()].layout_button->win) + if(ev->window == infobar[selscreen].layout_button->win) { if(ev->button == Button1 || ev->button == Button4) @@ -213,7 +213,7 @@ expose(XExposeEvent *ev) barwin_refresh(infobar[sc].bar); if(ev->window == infobar[sc].layout_button->win) barwin_refresh(infobar[sc].layout_button); - for(i = 1; i < conf.ntag + 1; ++i) + for(i = 1; i < conf.ntag[sc] + 1; ++i) if(ev->window == infobar[sc].tags[i]->win) barwin_refresh(infobar[sc].tags[i]); } diff --git a/src/infobar.c b/src/infobar.c index ce4a30e..332b082 100644 --- a/src/infobar.c +++ b/src/infobar.c @@ -55,7 +55,7 @@ infobar_init(void) screen_get_geo(sc).width, infobar[sc].geo.height, conf.colors.bar, False); /* Create tags window */ - for(i = 1; i < conf.ntag + 1; ++i) + for(i = 1; i < conf.ntag[sc] + 1; ++i) { infobar[sc].tags[i] = barwin_create(infobar[sc].bar->win, j, 0, textw(tags[sc][i].name) + PAD, infobar[sc].geo.height, conf.colors.bar, False); @@ -110,6 +110,7 @@ infobar_draw_layout(int sc) { barwin_resize(infobar[sc].layout_button, textw(tags[sc][seltag[sc]].layout.symbol) + PAD, infobar[sc].geo.height); barwin_refresh_color(infobar[sc].layout_button); + if(tags[sc][seltag[sc]].layout.symbol) draw_text(infobar[sc].layout_button->dr, PAD / 2, font->height, conf.colors.layout_fg, 0, tags[sc][seltag[sc]].layout.symbol); barwin_refresh(infobar[sc].layout_button); @@ -124,12 +125,17 @@ infobar_draw_taglist(int sc) { int i; - for(i = 1; i < conf.ntag + 1; ++i) + for(i = 1; i < conf.ntag[sc] + 1; ++i) { infobar[sc].tags[i]->color = ((i == seltag[sc]) ? conf.colors.tagselbg : conf.colors.bar); barwin_refresh_color(infobar[sc].tags[i]); - draw_text(infobar[sc].tags[i]->dr, PAD / 2, font->height, - ((i == seltag[sc]) ? conf.colors.tagselfg : conf.colors.text), 0, tags[sc][i].name); + if(tags[sc][i].name) + draw_text(infobar[sc].tags[i]->dr, + PAD / 2, + font->height, + ((i == seltag[sc]) ? conf.colors.tagselfg : conf.colors.text), + 0, + tags[sc][i].name); barwin_refresh(infobar[sc].tags[i]); } @@ -147,7 +153,7 @@ infobar_destroy(void) { barwin_delete(infobar[sc].layout_button); barwin_delete_subwin(infobar[sc].layout_button); - for(i = 1; i < conf.ntag + 1; ++i) + for(i = 1; i < conf.ntag[sc] + 1; ++i) { barwin_delete_subwin(infobar[sc].tags[i]); barwin_delete(infobar[sc].tags[i]); diff --git a/src/layout.c b/src/layout.c index 8482fc6..9a3058e 100644 --- a/src/layout.c +++ b/src/layout.c @@ -51,9 +51,7 @@ arrange(void) } tags[selscreen][seltag[selscreen]].layout.func(); - client_focus(NULL); - infobar_draw(selscreen); return; diff --git a/src/screen.c b/src/screen.c index 4c82f1b..ab37b07 100644 --- a/src/screen.c +++ b/src/screen.c @@ -70,12 +70,12 @@ screen_get_geo(int s) geo.height = xsi[s].height - INFOBARH - TBARH; geo.width = xsi[s].width; - free(xsi); + XFree(xsi); } else { geo.x = BORDH; - geo.y = (conf.bartop) ? INFOBARH + TBARH : TBARH; ; + geo.y = (conf.bartop) ? INFOBARH + TBARH : TBARH; geo.height = MAXH - INFOBARH - TBARH; geo.width = MAXW; } diff --git a/src/structs.h b/src/structs.h index e425ff7..b5934e7 100644 --- a/src/structs.h +++ b/src/structs.h @@ -203,7 +203,7 @@ typedef struct } titlebar; Tag tag[MAXTAG]; Layout layout[NUM_OF_LAYOUT]; - int ntag; + int *ntag; int nkeybind; int nbutton; int nlayout; diff --git a/src/tag.c b/src/tag.c index 0918d66..3fbbad6 100644 --- a/src/tag.c +++ b/src/tag.c @@ -48,14 +48,14 @@ uicb_tag(uicb_t cmd) if(cmd[0] == '+' || cmd[0] == '-') { if(tmp + seltag[selscreen] < 1 - || tmp + seltag[selscreen] > conf.ntag) + || tmp + seltag[selscreen] > conf.ntag[selscreen]) return; seltag[selscreen] += tmp; } else { if(tmp == seltag[selscreen] - || tmp > conf.ntag) + || tmp > conf.ntag[selscreen]) return; seltag[selscreen] = tmp; }