titlebar: Add titlebar.c and titlebar position in the configuration
This commit is contained in:
parent
fb256b333f
commit
7514d55d6f
@ -35,7 +35,8 @@ set(wmfs_src
|
||||
src/tag.c
|
||||
src/bar.c
|
||||
src/draw.c
|
||||
src/client.c)
|
||||
src/client.c
|
||||
src/titlebar.c)
|
||||
|
||||
# Set the executable from the wmfs_src
|
||||
add_executable(wmfs ${wmfs_src})
|
||||
|
||||
52
src/bar.c
52
src/bar.c
@ -192,7 +192,7 @@ updatebutton(Bool c)
|
||||
|
||||
bar_refresh_color(conf.barbutton[i].bw);
|
||||
bar_moveresize(conf.barbutton[i].bw, x, y, buttonw, barheight + hi);
|
||||
draw_text(conf.barbutton[i].bw->dr, BPAD/2, fonth, conf.barbutton[i].fg_color,
|
||||
draw_text(conf.barbutton[i].bw->dr, BPAD/2, fonth - 1, conf.barbutton[i].fg_color,
|
||||
conf.barbutton[i].bg_color, PAD, conf.barbutton[i].content);
|
||||
|
||||
/* Refresh button */
|
||||
@ -210,7 +210,10 @@ uicb_togglebarpos(uicb_t cmd)
|
||||
int i;
|
||||
|
||||
conf.bartop = !conf.bartop;
|
||||
sgeo.y = (conf.bartop) ? barheight + conf.titlebar.height : conf.titlebar.height;
|
||||
if(conf.bartop)
|
||||
sgeo.y = conf.titlebar.pos ? barheight : barheight + conf.titlebar.height;
|
||||
else
|
||||
sgeo.y = conf.titlebar.pos ? 0 : conf.titlebar.height;
|
||||
|
||||
if(conf.bartop)
|
||||
bary = 0;
|
||||
@ -228,48 +231,3 @@ uicb_togglebarpos(uicb_t cmd)
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
updatetitlebar(Client *c)
|
||||
{
|
||||
int pos_y, pos_x;
|
||||
char *tmpcolor = NULL;
|
||||
|
||||
XFetchName(dpy, c->win, &(c->title));
|
||||
if(!c->title)
|
||||
c->title = strdup("WMFS");
|
||||
|
||||
if(!conf.titlebar.height)
|
||||
return;
|
||||
|
||||
bar_refresh_color(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) and fg color */
|
||||
pos_y = (fonth - (xftfont->descent - 1)) + ((conf.titlebar.height - fonth) / 2);
|
||||
tmpcolor = ((c == sel) ? conf.titlebar.fg_focus : conf.titlebar.fg_normal);
|
||||
|
||||
/* Draw title */
|
||||
draw_text(c->tbar->dr, pos_x, pos_y, tmpcolor, conf.titlebar.bg, 0, c->title);
|
||||
}
|
||||
bar_refresh(c->tbar);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
42
src/client.c
42
src/client.c
@ -66,7 +66,7 @@ client_detach(Client *c)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Fixed, need testing4 */
|
||||
/* Fixed, need testing */
|
||||
void
|
||||
uicb_client_prev(uicb_t cmd)
|
||||
{
|
||||
@ -149,7 +149,7 @@ client_focus(Client *c)
|
||||
|
||||
for(cc = clients; cc; cc = cc->next)
|
||||
if(!ishide(cc))
|
||||
updatetitlebar(cc);
|
||||
titlebar_update(cc);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -164,19 +164,6 @@ client_get(Window w)
|
||||
return c;
|
||||
}
|
||||
|
||||
Client*
|
||||
client_gettbar(Window w)
|
||||
{
|
||||
Client *c;
|
||||
|
||||
if(!conf.titlebar.height)
|
||||
return NULL;
|
||||
|
||||
for(c = clients; c && c->tbar->win != w; c = c->next);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void
|
||||
client_hide(Client *c)
|
||||
{
|
||||
@ -249,17 +236,9 @@ client_manage(Window w, XWindowAttributes *wa)
|
||||
c->tag = seltag;
|
||||
c->border = conf.client.borderheight;
|
||||
|
||||
/* Create titlebar (or not) */
|
||||
/* Create titlebar */
|
||||
if(conf.titlebar.height)
|
||||
{
|
||||
c->tbar = bar_create(c->geo.x,
|
||||
c->geo.y - conf.titlebar.height,
|
||||
c->geo.width,
|
||||
conf.titlebar.height - conf.client.borderheight,
|
||||
conf.client.borderheight,
|
||||
conf.titlebar.bg, True);
|
||||
XSetWindowBorder(dpy, c->tbar->win, conf.client.bordernormal);
|
||||
}
|
||||
titlebar_create(c);
|
||||
|
||||
winc.border_width = c->border;
|
||||
XConfigureWindow(dpy, w, CWBorderWidth, &winc);
|
||||
@ -269,7 +248,7 @@ client_manage(Window w, XWindowAttributes *wa)
|
||||
| PropertyChangeMask | StructureNotifyMask);
|
||||
|
||||
client_size_hints(c);
|
||||
updatetitlebar(c);
|
||||
titlebar_update(c);
|
||||
if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success))
|
||||
for(t = clients; t && t->win != trans; t = t->next);
|
||||
if(t)
|
||||
@ -353,12 +332,9 @@ client_moveresize(Client *c, XRectangle geo, bool r)
|
||||
geo.width, geo.height);
|
||||
|
||||
if(conf.titlebar.height)
|
||||
bar_moveresize(c->tbar, geo.x,
|
||||
geo.y - conf.titlebar.height,
|
||||
geo.width,
|
||||
conf.titlebar.height - conf.client.borderheight);
|
||||
titlebar_update_position(c);
|
||||
|
||||
updatetitlebar(c);
|
||||
titlebar_update(c);
|
||||
XSync(dpy, False);
|
||||
}
|
||||
|
||||
@ -446,7 +422,7 @@ client_raise(Client *c)
|
||||
if(conf.titlebar.height)
|
||||
{
|
||||
XRaiseWindow(dpy, c->tbar->win);
|
||||
updatetitlebar(c);
|
||||
titlebar_update(c);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -465,7 +441,7 @@ client_unhide(Client *c)
|
||||
{
|
||||
XMoveWindow(dpy, c->win, c->geo.x, c->geo.y);
|
||||
if(conf.titlebar.height)
|
||||
XMoveWindow(dpy, c->tbar->win, c->geo.x, c->geo.y - conf.titlebar.height);
|
||||
titlebar_update_position(c);
|
||||
setwinstate(c->win, NormalState);
|
||||
|
||||
return;
|
||||
|
||||
@ -193,6 +193,7 @@ init_conf(void)
|
||||
|
||||
static cfg_opt_t titlebar_opts[] =
|
||||
{
|
||||
CFG_STR("position", "top", CFGF_NONE),
|
||||
CFG_INT("height", 0, CFGF_NONE),
|
||||
CFG_STR("bg", "#090909", CFGF_NONE),
|
||||
CFG_STR("fg_focus", "#FFFFFF", CFGF_NONE),
|
||||
@ -367,6 +368,11 @@ init_conf(void)
|
||||
conf.bartop = (strcmp(strdup(cfg_getstr(cfg_bar, "position")), "top") == 0) ? True : False;
|
||||
|
||||
/* titlebar */
|
||||
if(strcmp(var_to_str(cfg_getstr(cfg_titlebar, "position")), "bottom") == 0)
|
||||
conf.titlebar.pos = True;
|
||||
else
|
||||
conf.titlebar.pos = False;
|
||||
|
||||
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"));
|
||||
|
||||
@ -90,8 +90,10 @@ draw_taglist(Drawable dr)
|
||||
void
|
||||
draw_layout(void)
|
||||
{
|
||||
draw_text(bar->dr, taglen[conf.ntag] + BPAD/2, fonth, conf.colors.layout_fg,
|
||||
conf.colors.layout_bg, BPAD, tags[seltag].layout.symbol);
|
||||
draw_text(bar->dr, taglen[conf.ntag] + BPAD/2, fonth,
|
||||
conf.colors.layout_fg,
|
||||
conf.colors.layout_bg,
|
||||
BPAD, tags[seltag].layout.symbol);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ buttonpress(XEvent ev)
|
||||
|
||||
/* Titlebar */
|
||||
if(conf.titlebar.height)
|
||||
if((c = client_gettbar(ev.xbutton.window)))
|
||||
if((c = titlebar_get(ev.xbutton.window)))
|
||||
for(i = 0; i < conf.titlebar.nmouse; ++i)
|
||||
if(ev.xbutton.button == conf.titlebar.mouse[i].button)
|
||||
if(conf.titlebar.mouse[i].func)
|
||||
@ -165,7 +165,7 @@ enternotify(XEvent ev)
|
||||
|| ev.xcrossing.detail == NotifyInferior)
|
||||
return;
|
||||
if((c = client_get(ev.xcrossing.window))
|
||||
|| (c = client_gettbar(ev.xcrossing.window)))
|
||||
|| (c = titlebar_get(ev.xcrossing.window)))
|
||||
client_focus(c);
|
||||
else
|
||||
client_focus(NULL);
|
||||
@ -186,7 +186,7 @@ expose(XEvent ev)
|
||||
if(conf.titlebar.height)
|
||||
for(c = clients; c; c = c->next)
|
||||
if(ev.xexpose.window == c->tbar->win)
|
||||
updatetitlebar(c);
|
||||
titlebar_update(c);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -394,7 +394,7 @@ propertynotify(XEvent ev)
|
||||
}
|
||||
if(ev.xproperty.atom == XA_WM_NAME
|
||||
|| ev.xproperty.atom == net_atom[NetWMName])
|
||||
updatetitlebar(c);
|
||||
titlebar_update(c);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
@ -172,6 +172,7 @@ typedef struct
|
||||
} client;
|
||||
struct
|
||||
{
|
||||
Bool pos;
|
||||
int height;
|
||||
uint bg;
|
||||
char *fg_focus;
|
||||
|
||||
131
src/titlebar.c
Normal file
131
src/titlebar.c
Normal file
@ -0,0 +1,131 @@
|
||||
/*
|
||||
* titlebar.c
|
||||
* Copyright © 2008 Martin Duquesnoy <xorg62@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of the nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "wmfs.h"
|
||||
|
||||
void
|
||||
titlebar_create(Client *c)
|
||||
{
|
||||
int y;
|
||||
|
||||
/* Set titlebar position : Top/Bottom */
|
||||
if(conf.titlebar.pos)
|
||||
y = c->geo.y + c->geo.height + conf.client.borderheight;
|
||||
else
|
||||
y = c->geo.y - conf.titlebar.height;
|
||||
|
||||
c->tbar = bar_create(c->geo.x,
|
||||
c->geo.y - conf.titlebar.height,
|
||||
c->geo.width,
|
||||
conf.titlebar.height - conf.client.borderheight,
|
||||
conf.client.borderheight,
|
||||
conf.titlebar.bg, True);
|
||||
XSetWindowBorder(dpy, c->tbar->win, conf.client.bordernormal);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Client*
|
||||
titlebar_get(Window w)
|
||||
{
|
||||
Client *c;
|
||||
|
||||
if(!conf.titlebar.height)
|
||||
return NULL;
|
||||
|
||||
for(c = clients; c && c->tbar->win != w; c = c->next);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void
|
||||
titlebar_update_position(Client *c)
|
||||
{
|
||||
int y;
|
||||
|
||||
/* Set titlebar position : Top/Bottom */
|
||||
if(conf.titlebar.pos)
|
||||
y = c->geo.y + c->geo.height + conf.client.borderheight;
|
||||
else
|
||||
y = c->geo.y - conf.titlebar.height;
|
||||
|
||||
bar_moveresize(c->tbar, c->geo.x, y, c->geo.width,
|
||||
conf.titlebar.height - conf.client.borderheight);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
titlebar_update(Client *c)
|
||||
{
|
||||
int pos_y, pos_x;
|
||||
char *tmpcolor = NULL;
|
||||
|
||||
XFetchName(dpy, c->win, &(c->title));
|
||||
if(!c->title)
|
||||
c->title = strdup("WMFS");
|
||||
|
||||
if(!conf.titlebar.height)
|
||||
return;
|
||||
|
||||
bar_refresh_color(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) and fg color */
|
||||
pos_y = (fonth - (xftfont->descent )) + ((conf.titlebar.height - fonth) / 2);
|
||||
tmpcolor = ((c == sel) ? conf.titlebar.fg_focus : conf.titlebar.fg_normal);
|
||||
|
||||
/* Draw title */
|
||||
draw_text(c->tbar->dr, pos_x, pos_y, tmpcolor, conf.titlebar.bg, 0, c->title);
|
||||
}
|
||||
bar_refresh(c->tbar);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -135,8 +135,8 @@ init(void)
|
||||
fprintf(stderr, "WMFS Error: Cannot initialize font\n");
|
||||
xftfont = XftFontOpenName(dpy, screen, "sans-10");
|
||||
}
|
||||
fonth = (xftfont->ascent + xftfont->descent) - 1;
|
||||
barheight = fonth + 4;
|
||||
fonth = (xftfont->ascent + xftfont->descent);
|
||||
barheight = fonth + (float)4.5;
|
||||
|
||||
|
||||
/* INIT CURSOR */
|
||||
@ -180,7 +180,10 @@ init(void)
|
||||
/* INIT WORKABLE SPACE GEOMETRY */
|
||||
conf.titlebar.height += conf.client.borderheight;
|
||||
sgeo.x = 0;
|
||||
sgeo.y = (conf.bartop) ? barheight + conf.titlebar.height : conf.titlebar.height;
|
||||
if(conf.bartop)
|
||||
sgeo.y = conf.titlebar.pos ? barheight : barheight + conf.titlebar.height;
|
||||
else
|
||||
sgeo.y = conf.titlebar.pos ? 0 : conf.titlebar.height;
|
||||
sgeo.width = DisplayWidth(dpy, screen);
|
||||
sgeo.height = DisplayHeight(dpy, screen) - (barheight + conf.titlebar.height);
|
||||
|
||||
|
||||
@ -70,7 +70,6 @@ void bar_refresh_color(BarWindow *bw);
|
||||
void bar_refresh(BarWindow *bw);
|
||||
void updatebar(void);
|
||||
void updatebutton(Bool c);
|
||||
void updatetitlebar(Client *c);
|
||||
void uicb_togglebarpos(uicb_t);
|
||||
|
||||
/* draw.c */
|
||||
@ -86,7 +85,6 @@ void client_attach(Client *c);
|
||||
void client_detach(Client *c);
|
||||
void client_focus(Client *c);
|
||||
Client *client_get(Window w);
|
||||
Client *client_gettbar(Window w);
|
||||
void client_hide(Client *c);
|
||||
Bool ishide(Client *c);
|
||||
void client_map(Client *c);
|
||||
@ -137,6 +135,12 @@ void uicb_tag_next(uicb_t);
|
||||
void uicb_tag_prev(uicb_t);
|
||||
void uicb_tagtransfert(uicb_t);
|
||||
|
||||
/* titlebar.c */
|
||||
void titlebar_create(Client *c);
|
||||
Client* titlebar_get(Window w);
|
||||
void titlebar_update_position(Client *c);
|
||||
void titlebar_update(Client *c);
|
||||
|
||||
/* layout.c */
|
||||
void arrange(void);
|
||||
void freelayout(void);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user