From 5cf610ba4c43c4f4e8184cdd7b631c8012f0ed6d Mon Sep 17 00:00:00 2001 From: guillaume Date: Sun, 28 Jan 2007 21:52:20 +0000 Subject: bdm: loadWidgets & al --- src/bdm.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- src/bdm.h | 20 +++------------- 2 files changed, 79 insertions(+), 23 deletions(-) diff --git a/src/bdm.c b/src/bdm.c index cb2f101..e5d5994 100644 --- a/src/bdm.c +++ b/src/bdm.c @@ -16,14 +16,13 @@ #include #include #include +#include #include "bdm.h" #include #include -BDMWidgetList * widgetList; - static void renderImage(cairo_t * cr, BDMImage * image, ScreenArea * area) { cairo_set_source_rgba(cr,0,0,0,0); @@ -116,20 +115,22 @@ static void renderText (cairo_t * cr, BDMText * text, ScreenArea * area) static void updateWidgets(cairo_t * cr,ScreenArea * area) { - BDMWidget * widget = widgetList->head; + GSList * widgets; + BDMWidget * widget; BDMImage * image; BDMText * text; - for (widget=widgetList->head;widget;widget=widget->next) + for (widgets=Widgets;widgets;widgets=widgets->next) { + widget = widgets->data; widget->updateWidget(); if (widget->attrib->needsPainting) { - for (image = widget->getImages(); image; image = image->next) + for (image = widget->images; image; image = image->next) { if (image->attrib->needsPainting) renderImage(cr,image,area); } - for (text = widget->getText(); text; text=text->next) + for (text = widget->texts; text; text=text->next) { if (text->attrib->needsPainting) renderText(cr,text,area); @@ -187,6 +188,58 @@ static void on_alpha_screen_changed(GtkWidget * widget, GdkScreen * pOldScreen, gtk_widget_set_colormap(widget,pColormap); } +static void initPaintAttribs (BDMPaintAttribs * attribs) +{ + attribs->width = attribs->height = attribs->x = attribs->y = attribs->alpha = 0; + attribs->needsPainting = attribs->updateFont = 0; +} + +static int loadWidget (char * path) +{ + void * widgetDL; + widgetDL = dlopen (path, RTLD_NOW); + if (!widgetDL) + return 0; + + BDMWidget * widget = malloc (sizeof (BDMWidget)); + if (!widget) + { + dlclose (widgetDL); + return 0; + } + + widget->attrib = malloc (sizeof (BDMPaintAttribs)); + if (!widget->attrib) + { + free (widget); + dlclose (widgetDL); + return 0; + } + initPaintAttribs (widget->attrib); + + widget->initWidget = dlsym (widgetDL, "init"); + widget->finiWidget = dlsym (widgetDL, "fini"); + widget->updateWidget = dlsym (widgetDL, "update"); + + widget->getImages = dlsym (widgetDL, "getImages"); + widget->getTexts = dlsym (widgetDL, "getTexts"); + + widget->handleEvent = dlsym (widgetDL, "handleEvent"); + widget->setBDMWidget = dlsym (widgetDL, "setBDMWidget"); + + widget->images = widget->getImages (); + widget->texts = widget->getTexts (); + + widget->prev = (BDMWidget *) g_slist_last (Widgets); + widget->prev->next = widget; + widget->next = NULL; + + widget->initWidget (); + + Widgets = g_slist_append (Widgets, widget); + + return 1; +} int main(int argc, char * argv[]) { @@ -285,6 +338,7 @@ int main(int argc, char * argv[]) { free(w); } + g_free (s); } if (!Wallpapers) { @@ -292,6 +346,22 @@ int main(int argc, char * argv[]) return 1; } + keys = g_key_file_get_keys (kf, "widgets", &n_keys, &error); + + if (error != NULL || n_keys == 0) + { + fprintf (stderr, "All your widgets are belong to me.\n"); + } + else + { + for(i = 0; i < n_keys; i++) + { + gchar * s = g_key_file_get_string (kf, "widgets", keys[i], NULL); + loadWidget (s); + g_free (s); + } + } + g_key_file_free (kf); GSList * wp = Wallpapers; diff --git a/src/bdm.h b/src/bdm.h index 8441a13..b72e4e0 100644 --- a/src/bdm.h +++ b/src/bdm.h @@ -123,10 +123,7 @@ typedef int (*BDMWidgetInitProc) (void); typedef int (*BDMWidgetFiniProc) (void); typedef int (*BDMWidgetUpdateProc) (void); -typedef int (*BDMWidgetNumImagesProc) (void); typedef BDMImage * (*BDMWidgetGetImagesProc) (void); - -typedef int (*BDMWidgetNumTextProc) (void); typedef BDMText * (*BDMWidgetGetTextProc) (void); typedef int (*BDMWidgetHandleEventProc) (BDMEvent *event); @@ -137,7 +134,7 @@ struct _BDMWidget { BDMPaintAttribs * attrib; BDMImage * images; - BDMText * text; + BDMText * texts; BDMWidget * next; BDMWidget * prev; @@ -145,25 +142,14 @@ struct _BDMWidget BDMWidgetFiniProc finiWidget; BDMWidgetUpdateProc updateWidget; - BDMWidgetNumImagesProc numImages; BDMWidgetGetImagesProc getImages; - - BDMWidgetNumTextProc numText; - BDMWidgetGetTextProc getText; + BDMWidgetGetTextProc getTexts; BDMWidgetHandleEventProc handleEvent; BDMWidgetSetBDMWidgetProc setBDMWidget; }; -typedef struct _BDMWidgetList -{ - BDMWidget * head; - BDMWidget * tail; - BDMWidget * next; - BDMWidget * prev; -} BDMWidgetList; - - +GSList * Widgets = NULL; GSList * Wallpapers=NULL; -- cgit v1.1