[widget] Merge common functions.

Not really common after all.

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-05-23 13:38:18 +02:00
parent a04417494b
commit ed44254aeb
5 changed files with 56 additions and 116 deletions

View file

@ -34,7 +34,6 @@ WIDGETS += widgets/iconbox.c
WIDGETS += widgets/progressbar.c WIDGETS += widgets/progressbar.c
WIDGETS += widgets/tasklist.c WIDGETS += widgets/tasklist.c
WIDGETS += widgets/graph.c WIDGETS += widgets/graph.c
WIDGETS += widgets/common.c widgets/common.h
doc_DATA += README doc_DATA += README

View file

@ -1,81 +0,0 @@
/*
* widgets/common.c - some functions used by widgets
*
* Copyright © 2008 Julien Danjou <julien@danjou.info>
* Copyright © 2008 Marco Candrian <mac@calmar.ws>
*
* 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.
*
*/
#include "widgets/common.h"
extern AwesomeConf globalconf;
widget_tell_status_t
widget_set_color_for_data(xcolor_t *color, char *new_value, int data_items, char ** data_title)
{
char *title, *setting;
int i;
title = strtok(new_value, " ");
if(!(setting = strtok(NULL, " ")))
return WIDGET_ERROR_NOVALUE;
for(i = 0; i < data_items; i++)
if(!a_strcmp(title, data_title[i]))
{
if(draw_color_new(globalconf.connection,
globalconf.default_screen,
setting, &color[i]))
return WIDGET_NOERROR;
else
return WIDGET_ERROR_FORMAT_COLOR;
}
return WIDGET_ERROR_FORMAT_SECTION;
}
widget_tell_status_t
widget_set_color_pointer_for_data(xcolor_t **color, char *new_value, int data_items, char ** data_title)
{
char *title, *setting;
int i;
bool flag;
title = strtok(new_value, " ");
if(!(setting = strtok(NULL, " ")))
return WIDGET_ERROR_NOVALUE;
for(i = 0; i < data_items; i++)
if(!a_strcmp(title, data_title[i]))
{
flag = false;
if(!color[i])
{
flag = true; /* p_delete && restore to NULL, if draw_color_new unsuccessful */
color[i] = p_new(xcolor_t, 1);
}
if(!(draw_color_new(globalconf.connection,
globalconf.default_screen,
setting, color[i])))
{
if(flag) /* restore */
{
p_delete(&color[i]);
color[i] = NULL;
}
return WIDGET_ERROR_FORMAT_COLOR;
}
return WIDGET_NOERROR;
}
return WIDGET_ERROR_FORMAT_SECTION;
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View file

@ -1,31 +0,0 @@
/*
* widgets/common.h - some functions headers used by widgets
*
* Copyright © 2008 Julien Danjou <julien@danjou.info>
* Copyright © 2008 Marco Candrian <mac@calmar.ws>
*
* 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.
*
*/
#ifndef AWESOME_WIDGETS_COMMON_H
#define AWESOME_WIDGETS_COMMON_H
#include "widget.h"
widget_tell_status_t widget_set_color_for_data(xcolor_t *, char *, int, char **);
widget_tell_status_t widget_set_color_pointer_for_data(xcolor_t **, char *, int, char **);
#endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View file

@ -23,7 +23,6 @@
#include "widget.h" #include "widget.h"
#include "screen.h" #include "screen.h"
#include "common/draw.h" #include "common/draw.h"
#include "common/configopts.h"
extern AwesomeConf globalconf; extern AwesomeConf globalconf;

View file

@ -21,8 +21,6 @@
*/ */
#include "screen.h" #include "screen.h"
#include "widgets/common.h"
#include "common/configopts.h"
extern AwesomeConf globalconf; extern AwesomeConf globalconf;
@ -66,6 +64,62 @@ typedef struct
xcolor_t *bordercolor; xcolor_t *bordercolor;
} Data; } Data;
static widget_tell_status_t
widget_set_color_for_data(xcolor_t *color, char *new_value, int data_items, char ** data_title)
{
char *title, *setting;
int i;
title = strtok(new_value, " ");
if(!(setting = strtok(NULL, " ")))
return WIDGET_ERROR_NOVALUE;
for(i = 0; i < data_items; i++)
if(!a_strcmp(title, data_title[i]))
{
if(draw_color_new(globalconf.connection,
globalconf.default_screen,
setting, &color[i]))
return WIDGET_NOERROR;
else
return WIDGET_ERROR_FORMAT_COLOR;
}
return WIDGET_ERROR_FORMAT_SECTION;
}
static widget_tell_status_t
widget_set_color_pointer_for_data(xcolor_t **color, char *new_value, int data_items, char ** data_title)
{
char *title, *setting;
int i;
bool flag;
title = strtok(new_value, " ");
if(!(setting = strtok(NULL, " ")))
return WIDGET_ERROR_NOVALUE;
for(i = 0; i < data_items; i++)
if(!a_strcmp(title, data_title[i]))
{
flag = false;
if(!color[i])
{
flag = true; /* p_delete && restore to NULL, if draw_color_new unsuccessful */
color[i] = p_new(xcolor_t, 1);
}
if(!(draw_color_new(globalconf.connection,
globalconf.default_screen,
setting, color[i])))
{
if(flag) /* restore */
{
p_delete(&color[i]);
color[i] = NULL;
}
return WIDGET_ERROR_FORMAT_COLOR;
}
return WIDGET_NOERROR;
}
return WIDGET_ERROR_FORMAT_SECTION;
}
static bool static bool
check_settings(Data *d, int status_height) check_settings(Data *d, int status_height)
{ {