titlebar: Massive change for the titlebar : Add a titlebar section in the configuration file + text alignement : left / center / right. Remove the titlebar border (useless)

This commit is contained in:
Martin Duquesnoy 2008-10-20 03:05:37 +02:00
parent 5a9ac485eb
commit bfefc41d96
8 changed files with 93 additions and 47 deletions

View File

@ -210,7 +210,7 @@ uicb_togglebarpos(uicb_t cmd)
int i; int i;
conf.bartop = !conf.bartop; conf.bartop = !conf.bartop;
sgeo.y = (conf.bartop) ? barheight + conf.ttbarheight : conf.ttbarheight; sgeo.y = (conf.bartop) ? barheight + conf.titlebar.height : conf.titlebar.height;
if(conf.bartop) if(conf.bartop)
bary = 0; bary = 0;
@ -232,19 +232,35 @@ uicb_togglebarpos(uicb_t cmd)
void void
updatetitlebar(Client *c) updatetitlebar(Client *c)
{ {
int pos_y, pos_x;
XFetchName(dpy, c->win, &(c->title)); XFetchName(dpy, c->win, &(c->title));
if(!c->title) if(!c->title)
c->title = strdup("WMFS"); c->title = strdup("WMFS");
if(conf.ttbarheight > 10) bar_refresh_color(c->tbar);
{
bar_refresh_color(c->tbar);
draw_text(c->tbar->dr, 3, ((fonth - xftfont->descent) + ((conf.ttbarheight - fonth) / 2)),
((c == sel) ? conf.colors.ttbar_text_focus : conf.colors.ttbar_text_normal),
conf.colors.bar, 0, c->title);
bar_refresh(c->tbar); /* Draw the client title in the titlebar *logeek* */
if(conf.titlebar.height > 9)
{
/* Set the text alignement */
switch(conf.titlebar.text_align)
{
case Center: pos_x = (c->geo.width / 2) - (textw(c->title) / 2); break;
case Right: pos_x = c->geo.width - textw(c->title) - 2; break;
default: case Left: pos_x = 2; break;
}
/* Set y text position (always at the middle) */
pos_y = (fonth - (xftfont->descent - 1)) + ((conf.titlebar.height - fonth) / 2);
/* Draw title */
draw_text(c->tbar->dr, pos_x, pos_y,
((c == sel) ? conf.titlebar.fg_focus : conf.titlebar.fg_normal),
conf.titlebar.bg, 0, c->title);
} }
bar_refresh(c->tbar);
return; return;
} }

View File

@ -132,8 +132,6 @@ client_focus(Client *c)
{ {
grabbuttons(sel, False); grabbuttons(sel, False);
XSetWindowBorder(dpy, sel->win, conf.colors.bordernormal); XSetWindowBorder(dpy, sel->win, conf.colors.bordernormal);
if(conf.ttbarheight)
XSetWindowBorder(dpy, sel->tbar->win, conf.colors.bordernormal);
} }
if(c) if(c)
@ -145,8 +143,6 @@ client_focus(Client *c)
if(c) if(c)
{ {
XSetWindowBorder(dpy, c->win, conf.colors.borderfocus); XSetWindowBorder(dpy, c->win, conf.colors.borderfocus);
if(c->tbar->win)
XSetWindowBorder(dpy, c->tbar->win, conf.colors.borderfocus);
if(conf.raisefocus) if(conf.raisefocus)
client_raise(c); client_raise(c);
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
@ -176,7 +172,7 @@ client_gettbar(Window w)
{ {
Client *c; Client *c;
if(!conf.ttbarheight) if(!conf.titlebar.height)
return NULL; return NULL;
for(c = clients; c && c->tbar->win != w; c = c->next); for(c = clients; c && c->tbar->win != w; c = c->next);
@ -188,7 +184,7 @@ void
client_hide(Client *c) client_hide(Client *c)
{ {
XUnmapWindow(dpy, c->win); XUnmapWindow(dpy, c->win);
if(conf.ttbarheight) if(conf.titlebar.height)
XUnmapWindow(dpy, c->tbar->win); XUnmapWindow(dpy, c->tbar->win);
setwinstate(c->win, IconicState); setwinstate(c->win, IconicState);
@ -233,7 +229,7 @@ client_map(Client *c)
return; return;
XMapWindow(dpy, c->win); XMapWindow(dpy, c->win);
if(conf.ttbarheight) if(conf.titlebar.height)
{ {
XMapWindow(dpy, c->tbar->win); XMapWindow(dpy, c->tbar->win);
bar_refresh(c->tbar); bar_refresh(c->tbar);
@ -253,17 +249,19 @@ client_manage(Window w, XWindowAttributes *wa)
c = emalloc(1, sizeof(Client)); c = emalloc(1, sizeof(Client));
c->win = w; c->win = w;
c->geo.x = wa->x; c->geo.x = wa->x;
c->geo.y = wa->y + sgeo.y + conf.ttbarheight; /* Default free placement */ c->geo.y = wa->y + sgeo.y + conf.titlebar.height; /* Default free placement */
c->geo.width = wa->width; c->geo.width = wa->width;
c->geo.height = wa->height; c->geo.height = wa->height;
c->tag = seltag; c->tag = seltag;
c->border = conf.borderheight; c->border = conf.borderheight;
/* Create titlebar */ /* Create titlebar */
if(conf.ttbarheight) if(conf.titlebar.height)
c->tbar = bar_create(c->geo.x, c->geo.y - conf.ttbarheight, c->tbar = bar_create(c->geo.x,
c->geo.width, conf.ttbarheight, conf.borderheight, c->geo.y - conf.titlebar.height,
conf.colors.bar, True); c->geo.width + c->border,
conf.titlebar.height, 0,
conf.titlebar.bg, True);
winc.border_width = c->border; winc.border_width = c->border;
XConfigureWindow(dpy, w, CWBorderWidth, &winc); XConfigureWindow(dpy, w, CWBorderWidth, &winc);
@ -356,8 +354,11 @@ client_moveresize(Client *c, XRectangle geo, bool r)
XMoveResizeWindow(dpy, c->win, geo.x, geo.y, XMoveResizeWindow(dpy, c->win, geo.x, geo.y,
geo.width, geo.height); geo.width, geo.height);
if(conf.ttbarheight) if(conf.titlebar.height)
bar_moveresize(c->tbar, geo.x, geo.y - conf.ttbarheight, geo.width, conf.ttbarheight); bar_moveresize(c->tbar, geo.x,
geo.y - conf.titlebar.height,
geo.width + c->border*2,
conf.titlebar.height);
updatetitlebar(c); updatetitlebar(c);
XSync(dpy, False); XSync(dpy, False);
@ -444,7 +445,7 @@ client_raise(Client *c)
return; return;
XRaiseWindow(dpy, c->win); XRaiseWindow(dpy, c->win);
if(conf.ttbarheight) if(conf.titlebar.height)
{ {
XRaiseWindow(dpy, c->tbar->win); XRaiseWindow(dpy, c->tbar->win);
updatetitlebar(c); updatetitlebar(c);
@ -457,7 +458,7 @@ void
client_unhide(Client *c) client_unhide(Client *c)
{ {
XMapWindow(dpy, c->win); XMapWindow(dpy, c->win);
if(conf.ttbarheight) if(conf.titlebar.height)
XMapWindow(dpy, c->tbar->win); XMapWindow(dpy, c->tbar->win);
setwinstate(c->win, NormalState); setwinstate(c->win, NormalState);
@ -472,7 +473,7 @@ client_unmanage(Client *c)
sel = ((sel == c) ? ((c->next) ? c->next : NULL) : NULL); sel = ((sel == c) ? ((c->next) ? c->next : NULL) : NULL);
selbytag[seltag] = (sel && sel->tag == seltag) ? sel : NULL; selbytag[seltag] = (sel && sel->tag == seltag) ? sel : NULL;
client_detach(c); client_detach(c);
if(conf.ttbarheight) if(conf.titlebar.height)
bar_delete(c->tbar); bar_delete(c->tbar);
setwinstate(c->win, WithdrawnState); setwinstate(c->win, WithdrawnState);
free(c); free(c);
@ -490,7 +491,7 @@ client_unmap(Client *c)
return; return;
XUnmapWindow(dpy, c->win); XUnmapWindow(dpy, c->win);
if(conf.ttbarheight) if(conf.titlebar.height)
XUnmapWindow(dpy, c->tbar->win); XUnmapWindow(dpy, c->tbar->win);
return; return;

View File

@ -170,7 +170,6 @@ init_conf(void)
CFG_BOOL("raisefocus", cfg_false, CFGF_NONE), CFG_BOOL("raisefocus", cfg_false, CFGF_NONE),
CFG_BOOL("raiseswitch", cfg_true, CFGF_NONE), CFG_BOOL("raiseswitch", cfg_true, CFGF_NONE),
CFG_INT("border_height", 1, CFGF_NONE), CFG_INT("border_height", 1, CFGF_NONE),
CFG_INT("titlebar_height", 0, CFGF_NONE),
CFG_INT("tag_border_width", 0, CFGF_NONE), CFG_INT("tag_border_width", 0, CFGF_NONE),
CFG_END() CFG_END()
}; };
@ -186,11 +185,18 @@ init_conf(void)
CFG_STR("tag_border", "#090909", CFGF_NONE), CFG_STR("tag_border", "#090909", CFGF_NONE),
CFG_STR("layout_fg", "#FFFFFF", CFGF_NONE), CFG_STR("layout_fg", "#FFFFFF", CFGF_NONE),
CFG_STR("layout_bg", "#292929", CFGF_NONE), CFG_STR("layout_bg", "#292929", CFGF_NONE),
CFG_STR("titlebar_text_focus", "#FFFFFF", CFGF_NONE),
CFG_STR("titlebar_text_normal", "#FFFFFF", CFGF_NONE),
CFG_END() CFG_END()
}; };
static cfg_opt_t titlebar_opts[] =
{
CFG_INT("height", 0, CFGF_NONE),
CFG_STR("bg", "#090909", CFGF_NONE),
CFG_STR("fg_focus", "#FFFFFF", CFGF_NONE),
CFG_STR("fg_normal", "#FFFFFF", CFGF_NONE),
CFG_STR("text_align", "left", CFGF_NONE),
};
static cfg_opt_t layout_opts[] = static cfg_opt_t layout_opts[] =
{ {
CFG_STR("type", "", CFGF_NONE), CFG_STR("type", "", CFGF_NONE),
@ -275,6 +281,7 @@ init_conf(void)
{ {
CFG_SEC("misc", misc_opts, CFGF_NONE), CFG_SEC("misc", misc_opts, CFGF_NONE),
CFG_SEC("variables", variables_opts, CFGF_NONE), CFG_SEC("variables", variables_opts, CFGF_NONE),
CFG_SEC("titlebar", titlebar_opts, CFGF_NONE),
CFG_SEC("colors", colors_opts, CFGF_NONE), CFG_SEC("colors", colors_opts, CFGF_NONE),
CFG_SEC("layouts", layouts_opts, CFGF_NONE), CFG_SEC("layouts", layouts_opts, CFGF_NONE),
CFG_SEC("tags", tags_opts, CFGF_NONE), CFG_SEC("tags", tags_opts, CFGF_NONE),
@ -287,6 +294,7 @@ init_conf(void)
cfg_t *cfg_misc; cfg_t *cfg_misc;
cfg_t *cfg_colors; cfg_t *cfg_colors;
cfg_t *cfg_variables; cfg_t *cfg_variables;
cfg_t *cfg_titlebar;
cfg_t *cfg_layouts; cfg_t *cfg_layouts;
cfg_t *cfg_tags; cfg_t *cfg_tags;
cfg_t *cfg_keys; cfg_t *cfg_keys;
@ -314,6 +322,7 @@ init_conf(void)
cfg_misc = cfg_getsec(cfg, "misc"); cfg_misc = cfg_getsec(cfg, "misc");
cfg_variables = cfg_getsec(cfg, "variables"); cfg_variables = cfg_getsec(cfg, "variables");
cfg_titlebar = cfg_getsec(cfg, "titlebar");
cfg_colors = cfg_getsec(cfg, "colors"); cfg_colors = cfg_getsec(cfg, "colors");
cfg_layouts = cfg_getsec(cfg, "layouts"); cfg_layouts = cfg_getsec(cfg, "layouts");
cfg_tags = cfg_getsec(cfg, "tags"); cfg_tags = cfg_getsec(cfg, "tags");
@ -338,7 +347,6 @@ init_conf(void)
conf.raisefocus = cfg_getbool(cfg_misc, "raisefocus"); conf.raisefocus = cfg_getbool(cfg_misc, "raisefocus");
conf.raiseswitch = cfg_getbool(cfg_misc, "raiseswitch"); conf.raiseswitch = cfg_getbool(cfg_misc, "raiseswitch");
conf.borderheight = cfg_getint(cfg_misc, "border_height"); conf.borderheight = cfg_getint(cfg_misc, "border_height");
conf.ttbarheight = cfg_getint(cfg_misc, "titlebar_height");
conf.tagbordwidth = cfg_getint(cfg_misc, "tag_border_width"); conf.tagbordwidth = cfg_getint(cfg_misc, "tag_border_width");
conf.bartop = (strcmp(strdup(cfg_getstr(cfg_misc, "bar_position")), "top") == 0) ? True : False; conf.bartop = (strcmp(strdup(cfg_getstr(cfg_misc, "bar_position")), "top") == 0) ? True : False;
@ -352,8 +360,19 @@ init_conf(void)
conf.colors.tagbord = getcolor(var_to_str(cfg_getstr(cfg_colors, "tag_border"))); conf.colors.tagbord = getcolor(var_to_str(cfg_getstr(cfg_colors, "tag_border")));
conf.colors.layout_fg = strdup(var_to_str(cfg_getstr(cfg_colors, "layout_fg"))); conf.colors.layout_fg = strdup(var_to_str(cfg_getstr(cfg_colors, "layout_fg")));
conf.colors.layout_bg = getcolor(var_to_str(cfg_getstr(cfg_colors, "layout_bg"))); conf.colors.layout_bg = getcolor(var_to_str(cfg_getstr(cfg_colors, "layout_bg")));
conf.colors.ttbar_text_focus = strdup(var_to_str(cfg_getstr(cfg_colors, "titlebar_text_focus")));
conf.colors.ttbar_text_normal = strdup(var_to_str(cfg_getstr(cfg_colors, "titlebar_text_normal"))); /* titlebar */
conf.titlebar.height = cfg_getint(cfg_titlebar, "height");
conf.titlebar.bg = getcolor(var_to_str(cfg_getstr(cfg_titlebar, "bg")));
conf.titlebar.fg_focus = var_to_str(cfg_getstr(cfg_titlebar, "fg_focus"));
conf.titlebar.fg_normal = var_to_str(cfg_getstr(cfg_titlebar, "fg_normal"));
if(strcmp(var_to_str(cfg_getstr(cfg_titlebar, "text_align")), "center") == 0)
conf.titlebar.text_align = Center;
else if(strcmp(var_to_str(cfg_getstr(cfg_titlebar, "text_align")), "right") == 0)
conf.titlebar.text_align = Right;
else
conf.titlebar.text_align = Left;
/* layout */ /* layout */
if((conf.nlayout = cfg_size(cfg_layouts, "layout")) > MAXLAYOUT if((conf.nlayout = cfg_size(cfg_layouts, "layout")) > MAXLAYOUT

View File

@ -43,7 +43,7 @@ buttonpress(XEvent ev)
int i, j; int i, j;
char s[6]; char s[6];
if(conf.ttbarheight) if(conf.titlebar.height)
{ {
/* ******** */ /* ******** */
/* TITLEBAR */ /* TITLEBAR */
@ -287,7 +287,7 @@ expose(XEvent ev)
&& (ev.xexpose.window == bar->win)) && (ev.xexpose.window == bar->win))
updatebar(); updatebar();
if(conf.ttbarheight) if(conf.titlebar.height)
for(c = clients; c; c = c->next) for(c = clients; c; c = c->next)
if(ev.xexpose.window == c->tbar->win) if(ev.xexpose.window == c->tbar->win)
updatetitlebar(c); updatetitlebar(c);

View File

@ -233,9 +233,9 @@ tile(void)
/* Remainder */ /* Remainder */
if(i + 1 == (n < nmaster ? n : nmaster)) if(i + 1 == (n < nmaster ? n : nmaster))
cgeo.height = (sgeo.height - mastergeo.height * i) + conf.ttbarheight; cgeo.height = (sgeo.height - mastergeo.height * i) + conf.titlebar.height;
cgeo.height -= border + conf.ttbarheight; cgeo.height -= border + conf.titlebar.height;
} }
/* Tiled Client */ /* Tiled Client */
@ -253,13 +253,13 @@ tile(void)
if(i + 1 == n) if(i + 1 == n)
cgeo.height = (sgeo.y + sgeo.height) - cgeo.y - border; cgeo.height = (sgeo.y + sgeo.height) - cgeo.y - border;
else else
cgeo.height = tileheight - (border + conf.ttbarheight); cgeo.height = tileheight - (border + conf.titlebar.height);
} }
client_moveresize(c, cgeo, tags[seltag].resizehint); client_moveresize(c, cgeo, tags[seltag].resizehint);
if(n > nmaster && tileheight != sgeo.height) if(n > nmaster && tileheight != sgeo.height)
cgeo.y = c->geo.y + c->geo.height + border + conf.ttbarheight; cgeo.y = c->geo.y + c->geo.height + border + conf.titlebar.height;
} }
return; return;

View File

@ -50,6 +50,7 @@ typedef unsigned char uchar;
enum { CurNormal, CurResize, CurMove, CurLast }; enum { CurNormal, CurResize, CurMove, CurLast };
enum { WMState, WMProtocols, WMName, WMDelete, WMLast }; enum { WMState, WMProtocols, WMName, WMDelete, WMLast };
enum { NetSupported, NetWMName, NetLast }; enum { NetSupported, NetWMName, NetLast };
enum { Left = 0, Center, Right, AlignLast};
/* BarWindow Structure /* BarWindow Structure
* (titlebar, topbar..) */ * (titlebar, topbar..) */
@ -143,7 +144,6 @@ typedef struct
bool raiseswitch; bool raiseswitch;
bool bartop; bool bartop;
int borderheight; int borderheight;
int ttbarheight;
int tagbordwidth; int tagbordwidth;
struct struct
{ {
@ -158,9 +158,15 @@ typedef struct
uint tagbord; uint tagbord;
char *layout_fg; char *layout_fg;
uint layout_bg; uint layout_bg;
char *ttbar_text_focus;
char *ttbar_text_normal;
} colors; } colors;
struct
{
int height;
uint bg;
char *fg_focus;
char *fg_normal;
int text_align;
} titlebar;
Tag tag[MAXTAG]; Tag tag[MAXTAG];
Layout layout[MAXLAYOUT]; Layout layout[MAXLAYOUT];
BarButton *barbutton; BarButton *barbutton;

View File

@ -177,9 +177,9 @@ init(void)
/* INIT WORKABLE SPACE */ /* INIT WORKABLE SPACE */
sgeo.x = 0; sgeo.x = 0;
sgeo.y = (conf.bartop) ? barheight + conf.ttbarheight : conf.ttbarheight; sgeo.y = (conf.bartop) ? barheight + conf.titlebar.height : conf.titlebar.height;
sgeo.width = DisplayWidth(dpy, screen); sgeo.width = DisplayWidth(dpy, screen);
sgeo.height = DisplayHeight(dpy, screen) - (barheight + conf.ttbarheight); sgeo.height = DisplayHeight(dpy, screen) - (barheight + conf.titlebar.height);
/* INIT STUFF */ /* INIT STUFF */

12
wmfsrc
View File

@ -12,7 +12,6 @@ misc
raisefocus = false raisefocus = false
raiseswitch = true raiseswitch = true
border_height = 1 border_height = 1
titlebar_height = 12
tag_border_width = 1 tag_border_width = 1
} }
@ -34,10 +33,15 @@ colors
#Layout #Layout
layout_fg = "#191919" layout_fg = "#191919"
layout_bg = "#7E89A2" layout_bg = "#7E89A2"
}
#Titlebar titlebar
titlebar_text_focus = "#D4D4D4" {
titlebar_text_normal = "#D4D4D4" height = 12
bg = "#191919"
fg_normal = "#D4D4D4"
fg_focus = "#D4D4D4"
text_align = "center"
} }
layouts layouts