Revert "honor configrequest"
[awesome.git] / widget.c
blobf5697533ebb3ce3c10f3b59a8dd243f49a369552
1 /*
2 * widget.c - widget managing
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
5 * Copyright © 2007 Aldo Cortesi <aldo@nullcube.com>
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 "util.h"
24 #include "widget.h"
25 #include "statusbar.h"
26 #include "event.h"
28 extern AwesomeConf globalconf;
30 const NameFuncLink WidgetList[] =
32 {"taglist", taglist_new},
33 {"layoutinfo", layoutinfo_new},
34 {"focustitle", focustitle_new},
35 {"textbox", textbox_new},
36 {"iconbox", iconbox_new},
37 {"netwmicon", netwmicon_new},
38 {"progressbar", progressbar_new},
39 {"tasklist", tasklist_new},
40 {NULL, NULL}
43 void
44 widget_calculate_alignments(Widget *widget)
46 for(; widget; widget = widget->next)
48 if(widget->alignment == AlignFlex)
50 widget = widget->next;
51 break;
53 widget->alignment = AlignLeft;
56 if(widget)
57 for(; widget; widget = widget->next)
59 if (widget->alignment == AlignFlex)
60 warn("Multiple flex widgets in panel -"
61 " ignoring flex for all but the first.");
62 widget->alignment = AlignRight;
66 int
67 widget_calculate_offset(int barwidth, int widgetwidth, int offset, int alignment)
69 switch(alignment)
71 case AlignLeft:
72 case AlignFlex:
73 return offset;
75 return barwidth - offset - widgetwidth;
78 static Widget *
79 widget_find(char *name, int screen)
81 Widget *widget;
82 Statusbar *sb;
84 for(sb = globalconf.screens[screen].statusbar; sb; sb = sb->next)
85 for(widget = sb->widgets; widget; widget = widget->next)
86 if(a_strcmp(name, widget->name) == 0)
87 return widget;
89 return NULL;
92 static void
93 widget_common_button_press(Widget *widget, XButtonPressedEvent *ev)
95 Button *b;
97 for(b = widget->buttons; b; b = b->next)
98 if(ev->button == b->button && CLEANMASK(ev->state) == b->mod && b->func)
99 b->func(widget->statusbar->screen, b->arg);
102 static void
103 widget_common_tell(Widget *widget, char *command __attribute__ ((unused)))
105 warn("%s widget does not accept commands.\n", widget->name);
108 void
109 widget_common_new(Widget *widget, Statusbar *statusbar, cfg_t* config)
111 const char *name;
113 widget->statusbar = statusbar;
114 name = cfg_title(config);
115 widget->name = a_strdup(name);
116 widget->tell = widget_common_tell;
117 widget->button_press = widget_common_button_press;
118 widget->area.x = cfg_getint(config, "x");
119 widget->area.y = cfg_getint(config, "y");
120 widget->user_supplied_x = (widget->area.x != (int) 0xffffffff);
121 widget->user_supplied_y = (widget->area.y != (int) 0xffffffff);
124 /** Send command to widget
125 * \param screen Screen ID
126 * \param arg Widget command. Syntax depends on specific widget.
127 * \ingroup ui_callback
129 void
130 uicb_widget_tell(int screen, char *arg)
132 Widget *widget;
133 char *p, *command;
134 int len;
136 if (!arg)
138 warn("Must specify a widget.\n");
139 return;
142 len = strlen(arg);
143 p = strtok(arg, " ");
144 if (!p)
146 warn("Ignoring malformed widget command.\n");
147 return;
150 widget = widget_find(p, screen);
151 if (!widget)
153 warn("No such widget: %s\n", p);
154 return;
157 if (p+strlen(p) < arg+len)
159 p = p + strlen(p) + 1;
160 command = p_new(char, strlen(p)+1);
161 strncpy(command, p, strlen(p));
162 widget->tell(widget, command);
163 p_delete(&command);
165 else
166 widget->tell(widget, NULL);
168 statusbar_draw_all(screen);
169 return;
172 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80