simply ignore XSetInputFocus errors
[awesome.git] / widgets / focustitle.c
blobc072bde850716d4538ced369c88412b7acadd5b8
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 "widget.h"
25 #include "layout.h"
26 #include "tag.h"
27 #include "focus.h"
28 #include "screen.h"
29 #include "common/util.h"
31 extern AwesomeConf globalconf;
33 typedef struct
35 Alignment align;
36 XColor fg;
37 XColor bg;
38 } Data;
40 static int
41 focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
43 Data *d = widget->data;
44 Client *sel = focus_get_current_client(widget->statusbar->screen);
46 if(!widget->user_supplied_x)
47 widget->area.x = widget_calculate_offset(widget->statusbar->width,
49 offset,
50 widget->alignment);
52 if(!widget->user_supplied_y)
53 widget->area.y = 0;
55 widget->area.width = widget->statusbar->width - used;
56 widget->area.height = widget->statusbar->height;
58 if(sel)
60 draw_text(ctx, widget->area,
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, True, d->bg);
72 return widget->area.width;
75 Widget *
76 focustitle_new(Statusbar *statusbar, cfg_t *config)
78 Widget *w;
79 Data *d;
80 char *buf;
81 int phys_screen = get_phys_screen(statusbar->screen);
83 w = p_new(Widget, 1);
84 widget_common_new(w, statusbar, config);
85 w->draw = focustitle_draw;
86 w->alignment = AlignFlex;
87 w->data = d = p_new(Data, 1);
89 if((buf = cfg_getstr(config, "fg")))
90 d->fg = draw_color_new(globalconf.display, phys_screen, buf);
91 else
92 d->fg = globalconf.screens[statusbar->screen].colors_selected[ColFG];
94 if((buf = cfg_getstr(config, "bg")))
95 d->bg = draw_color_new(globalconf.display, phys_screen, buf);
96 else
97 d->bg = globalconf.screens[statusbar->screen].colors_selected[ColBG];
99 d->align = draw_get_align(cfg_getstr(config, "align"));
101 if((buf = cfg_getstr(config, "font")))
102 w->font = XftFontOpenName(globalconf.display, get_phys_screen(statusbar->screen), buf);
104 if(!w->font)
105 w->font = globalconf.screens[statusbar->screen].font;
107 /* Set cache property */
108 w->cache.flags = WIDGET_CACHE_CLIENTS | WIDGET_CACHE_TAGS;
110 return w;
113 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80