drop EnterWindow event to keep focus
[awesome.git] / widgets / focustitle.c
blobb92e93ade3a53d5321156cdc498d6a67e53f86ca
1 /*
2 * focustitle.c - focus title widget
4 * Copyright © 2007 Aldo Cortesi <aldo@nullcube.com>
5 * Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <stdio.h>
24 #include "util.h"
25 #include "widget.h"
26 #include "layout.h"
27 #include "tag.h"
28 #include "focus.h"
29 #include "xutil.h"
30 #include "screen.h"
32 extern AwesomeConf globalconf;
34 typedef struct
36 Alignment align;
37 XColor fg;
38 XColor bg;
39 } Data;
41 static int
42 focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
44 Data *d = widget->data;
45 Client *sel = focus_get_current_client(widget->statusbar->screen);
47 if(!widget->user_supplied_x)
48 widget->area.x = widget_calculate_offset(widget->statusbar->width,
50 offset,
51 widget->alignment);
53 if(!widget->user_supplied_y)
54 widget->area.y = 0;
56 if(sel)
58 draw_text(ctx, widget->area.x, widget->area.y,
59 widget->statusbar->width - used,
60 widget->statusbar->height,
61 d->align,
62 widget->font->height / 2, widget->font, sel->name,
63 d->fg, d->bg);
64 if(sel->isfloating || sel->ismax)
65 draw_circle(ctx, widget->area.x, widget->area.y,
66 (widget->font->height + 2) / 4,
67 sel->ismax, d->fg);
69 else
70 draw_rectangle(ctx, widget->area.x, widget->area.y,
71 widget->statusbar->width - used, widget->statusbar->height, True, d->bg);
73 widget->area.width = widget->statusbar->width - used;
74 widget->area.height = widget->statusbar->height;
76 return widget->area.width;
79 Widget *
80 focustitle_new(Statusbar *statusbar, cfg_t *config)
82 Widget *w;
83 Data *d;
84 char *buf;
85 int phys_screen = get_phys_screen(statusbar->screen);
87 w = p_new(Widget, 1);
88 widget_common_new(w, statusbar, config);
89 w->draw = focustitle_draw;
90 w->alignment = AlignFlex;
91 w->data = d = p_new(Data, 1);
93 if((buf = cfg_getstr(config, "fg")))
94 d->fg = initxcolor(phys_screen, buf);
95 else
96 d->fg = globalconf.screens[statusbar->screen].colors_selected[ColFG];
98 if((buf = cfg_getstr(config, "bg")))
99 d->bg = initxcolor(phys_screen, buf);
100 else
101 d->bg = globalconf.screens[statusbar->screen].colors_selected[ColBG];
103 d->align = draw_get_align(cfg_getstr(config, "align"));
105 if((buf = cfg_getstr(config, "font")))
106 w->font = XftFontOpenName(globalconf.display, get_phys_screen(statusbar->screen), buf);
108 if(!w->font)
109 w->font = globalconf.screens[statusbar->screen].font;
111 /* Set cache property */
112 w->cache.flags = WIDGET_CACHE_CLIENTS | WIDGET_CACHE_TAGS;
114 return w;
117 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80