2007-12-22 15:46:57 +01:00
|
|
|
/*
|
|
|
|
* widget.c - widget managing
|
|
|
|
*
|
|
|
|
* Copyright © 2007 Julien Danjou <julien@danjou.info>
|
|
|
|
* Copyright © 2007 Aldo Cortesi <aldo@nullcube.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-12-15 18:21:02 +01:00
|
|
|
#include "util.h"
|
2007-12-15 07:53:53 +01:00
|
|
|
#include "widget.h"
|
2007-12-17 10:57:17 +01:00
|
|
|
#include "statusbar.h"
|
2007-12-27 15:49:00 +01:00
|
|
|
#include "event.h"
|
2007-12-15 07:53:53 +01:00
|
|
|
|
2007-12-19 04:46:44 +01:00
|
|
|
extern AwesomeConf globalconf;
|
2007-12-16 10:25:13 +01:00
|
|
|
|
2008-01-12 14:34:53 +01:00
|
|
|
const name_func_link_t WidgetList[] =
|
2007-12-15 18:21:02 +01:00
|
|
|
{
|
|
|
|
{"taglist", taglist_new},
|
|
|
|
{"layoutinfo", layoutinfo_new},
|
|
|
|
{"focustitle", focustitle_new},
|
2007-12-15 20:22:20 +01:00
|
|
|
{"textbox", textbox_new},
|
2007-12-22 15:37:43 +01:00
|
|
|
{"iconbox", iconbox_new},
|
2007-12-22 19:32:47 +01:00
|
|
|
{"netwmicon", netwmicon_new},
|
2007-12-23 14:27:56 +01:00
|
|
|
{"progressbar", progressbar_new},
|
2008-01-06 18:23:56 +01:00
|
|
|
{"graph", graph_new},
|
2008-01-03 12:39:28 +01:00
|
|
|
{"tasklist", tasklist_new},
|
2007-12-15 20:22:20 +01:00
|
|
|
{NULL, NULL}
|
2007-12-15 18:21:02 +01:00
|
|
|
};
|
|
|
|
|
2007-12-15 07:53:53 +01:00
|
|
|
void
|
2007-12-22 20:55:17 +01:00
|
|
|
widget_calculate_alignments(Widget *widget)
|
2007-12-15 07:53:53 +01:00
|
|
|
{
|
2007-12-15 13:37:34 +01:00
|
|
|
for(; widget; widget = widget->next)
|
|
|
|
{
|
|
|
|
if(widget->alignment == AlignFlex)
|
|
|
|
{
|
2007-12-15 07:53:53 +01:00
|
|
|
widget = widget->next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
widget->alignment = AlignLeft;
|
|
|
|
}
|
2007-12-15 13:37:34 +01:00
|
|
|
|
|
|
|
if(widget)
|
2007-12-22 15:37:43 +01:00
|
|
|
for(; widget; widget = widget->next)
|
|
|
|
{
|
2007-12-16 04:28:29 +01:00
|
|
|
if (widget->alignment == AlignFlex)
|
2007-12-16 09:34:33 +01:00
|
|
|
warn("Multiple flex widgets in panel -"
|
|
|
|
" ignoring flex for all but the first.");
|
2007-12-15 07:53:53 +01:00
|
|
|
widget->alignment = AlignRight;
|
2007-12-16 04:28:29 +01:00
|
|
|
}
|
2007-12-15 07:53:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-12-22 20:55:17 +01:00
|
|
|
widget_calculate_offset(int barwidth, int widgetwidth, int offset, int alignment)
|
2007-12-15 07:53:53 +01:00
|
|
|
{
|
2008-01-04 19:17:20 +01:00
|
|
|
switch(alignment)
|
|
|
|
{
|
|
|
|
case AlignLeft:
|
|
|
|
case AlignFlex:
|
2007-12-15 07:53:53 +01:00
|
|
|
return offset;
|
2008-01-04 19:17:20 +01:00
|
|
|
}
|
2007-12-15 13:37:34 +01:00
|
|
|
return barwidth - offset - widgetwidth;
|
2007-12-15 07:53:53 +01:00
|
|
|
}
|
|
|
|
|
2007-12-16 10:25:13 +01:00
|
|
|
static Widget *
|
2007-12-22 20:55:17 +01:00
|
|
|
widget_find(char *name, int screen)
|
2007-12-16 10:25:13 +01:00
|
|
|
{
|
|
|
|
Widget *widget;
|
2007-12-30 21:00:34 +01:00
|
|
|
Statusbar *sb;
|
|
|
|
|
|
|
|
for(sb = globalconf.screens[screen].statusbar; sb; sb = sb->next)
|
|
|
|
for(widget = sb->widgets; widget; widget = widget->next)
|
|
|
|
if(a_strcmp(name, widget->name) == 0)
|
|
|
|
return widget;
|
|
|
|
|
2007-12-16 10:25:13 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-12-27 15:49:00 +01:00
|
|
|
static void
|
|
|
|
widget_common_button_press(Widget *widget, XButtonPressedEvent *ev)
|
|
|
|
{
|
|
|
|
Button *b;
|
|
|
|
|
|
|
|
for(b = widget->buttons; b; b = b->next)
|
|
|
|
if(ev->button == b->button && CLEANMASK(ev->state) == b->mod && b->func)
|
|
|
|
b->func(widget->statusbar->screen, b->arg);
|
|
|
|
}
|
|
|
|
|
2007-12-17 10:57:17 +01:00
|
|
|
static void
|
2007-12-22 20:55:17 +01:00
|
|
|
widget_common_tell(Widget *widget, char *command __attribute__ ((unused)))
|
2007-12-17 10:57:17 +01:00
|
|
|
{
|
|
|
|
warn("%s widget does not accept commands.\n", widget->name);
|
|
|
|
}
|
|
|
|
|
2007-12-16 09:34:33 +01:00
|
|
|
void
|
2007-12-22 20:55:17 +01:00
|
|
|
widget_common_new(Widget *widget, Statusbar *statusbar, cfg_t* config)
|
2007-12-16 09:34:33 +01:00
|
|
|
{
|
2007-12-17 10:57:17 +01:00
|
|
|
const char *name;
|
|
|
|
|
2007-12-22 15:46:57 +01:00
|
|
|
widget->statusbar = statusbar;
|
2007-12-17 10:57:17 +01:00
|
|
|
name = cfg_title(config);
|
2007-12-23 13:43:12 +01:00
|
|
|
widget->name = a_strdup(name);
|
2007-12-22 20:55:17 +01:00
|
|
|
widget->tell = widget_common_tell;
|
2007-12-27 15:49:00 +01:00
|
|
|
widget->button_press = widget_common_button_press;
|
2008-01-04 22:05:52 +01:00
|
|
|
widget->area.x = cfg_getint(config, "x");
|
|
|
|
widget->area.y = cfg_getint(config, "y");
|
2008-01-05 13:01:40 +01:00
|
|
|
widget->user_supplied_x = (widget->area.x != (int) 0xffffffff);
|
|
|
|
widget->user_supplied_y = (widget->area.y != (int) 0xffffffff);
|
2007-12-16 09:34:33 +01:00
|
|
|
}
|
|
|
|
|
2008-01-07 18:12:38 +01:00
|
|
|
void
|
|
|
|
widget_invalidate_cache(int screen, int flags)
|
|
|
|
{
|
|
|
|
Statusbar *statusbar;
|
|
|
|
Widget *widget;
|
|
|
|
|
|
|
|
for(statusbar = globalconf.screens[screen].statusbar;
|
|
|
|
statusbar;
|
|
|
|
statusbar = statusbar->next)
|
|
|
|
for(widget = statusbar->widgets; widget; widget = widget->next)
|
2008-01-11 15:53:57 +01:00
|
|
|
if(widget->cache.flags & flags)
|
|
|
|
widget->cache.needs_update = True;
|
2008-01-07 18:12:38 +01:00
|
|
|
}
|
|
|
|
|
2007-12-19 04:39:59 +01:00
|
|
|
/** Send command to widget
|
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg Widget command. Syntax depends on specific widget.
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
2007-12-16 10:25:13 +01:00
|
|
|
void
|
|
|
|
uicb_widget_tell(int screen, char *arg)
|
|
|
|
{
|
|
|
|
Widget *widget;
|
2007-12-17 10:57:17 +01:00
|
|
|
char *p, *command;
|
2008-01-12 23:19:58 +01:00
|
|
|
ssize_t len;
|
2007-12-17 10:57:17 +01:00
|
|
|
|
2007-12-22 15:46:57 +01:00
|
|
|
if (!arg)
|
|
|
|
{
|
2007-12-17 10:57:17 +01:00
|
|
|
warn("Must specify a widget.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-12 23:15:28 +01:00
|
|
|
len = a_strlen(arg);
|
2007-12-16 10:25:13 +01:00
|
|
|
p = strtok(arg, " ");
|
2008-01-12 23:15:28 +01:00
|
|
|
if(!p)
|
2007-12-22 15:46:57 +01:00
|
|
|
{
|
2007-12-17 10:57:17 +01:00
|
|
|
warn("Ignoring malformed widget command.\n");
|
2007-12-16 10:25:13 +01:00
|
|
|
return;
|
|
|
|
}
|
2007-12-22 15:46:57 +01:00
|
|
|
|
2007-12-22 20:55:17 +01:00
|
|
|
widget = widget_find(p, screen);
|
2008-01-12 23:15:28 +01:00
|
|
|
if(!widget)
|
2007-12-22 15:46:57 +01:00
|
|
|
{
|
2007-12-16 10:25:13 +01:00
|
|
|
warn("No such widget: %s\n", p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-12 23:19:58 +01:00
|
|
|
if(p + a_strlen(p) < arg + len)
|
2007-12-17 10:57:17 +01:00
|
|
|
{
|
2008-01-12 23:15:28 +01:00
|
|
|
p = p + a_strlen(p) + 1;
|
2008-01-12 23:19:58 +01:00
|
|
|
len = a_strlen(p);
|
|
|
|
command = p_new(char, len + 1);
|
|
|
|
a_strncpy(command, len + 1, p, len);
|
2007-12-17 10:57:17 +01:00
|
|
|
widget->tell(widget, command);
|
|
|
|
p_delete(&command);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
widget->tell(widget, NULL);
|
2007-12-22 15:46:57 +01:00
|
|
|
|
2008-01-07 18:12:38 +01:00
|
|
|
widget->cache.needs_update = True;
|
|
|
|
|
2007-12-17 10:57:17 +01:00
|
|
|
return;
|
2007-12-16 10:25:13 +01:00
|
|
|
}
|
2007-12-16 09:34:33 +01:00
|
|
|
|
2007-12-18 09:24:15 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|