diff --git a/plugins/libwmfun/drawstring.c b/plugins/libwmfun/drawstring.c index ba02d376..3d557d13 100644 --- a/plugins/libwmfun/drawstring.c +++ b/plugins/libwmfun/drawstring.c @@ -37,8 +37,7 @@ typedef struct __FreeTypeData{ RColor color; WMFreeTypeRImage **glyphs_array; WMFreeTypeRImage **glyphs_shadow_array; - /* will use this when we have frame window plugin */ - /* char *last_titlestr; */ + void (*strwidth)(); } WMFreeTypeData; #endif /* USE_FREETYPE */ @@ -60,14 +59,15 @@ initDrawPlainString(Display *dpy, Colormap *cmap) { } void -destroyDrawPlainString(proplist_t pl, void **func_data) { +destroyDrawPlainString(proplist_t pl, WPluginData *func_data) { return; } +/* FIX FIX FIX */ void drawPlainString (proplist_t pl, Drawable d, int x, int y, unsigned width, unsigned height, - char *text, void **func_data) + char *text, WPluginData *func_data) { XColor color1, color2, color3, color4; char *plcolor; @@ -78,8 +78,8 @@ drawPlainString (proplist_t pl, Drawable d, WMFont *font; length = strlen(text); - gc = func_data[0]; - font = func_data[1]; + gc = func_data->array[2]; + font = func_data->array[3]; /* @@ -188,15 +188,43 @@ WMFreeTypeRImage *renderChar(FT_Face face, FT_ULong char_index, RColor *color) { return tmp_data; } +void +widthOfFreeTypeString (unsigned char *text, int length, WPluginData *func_data, + int *width, int *height, int *top) { + WMFreeTypeData *data; + RImage *rimg; + int i; + + /* see framewin.c for the order of arguments (look in wPluginPackData) */ + data = ((WPluginData*)func_data->array[0])->array[2]; /* initialized data */ + + if (width) *width = 0; + /* may finish height & top later if they really are neccessary */ + + /* create temp for drawing */ + for (i = 0; i < length; i++) { + if (!data->glyphs_array[text[i]]) { + data->glyphs_array[text[i]] = renderChar(data->face, (FT_ULong)text[i], &data->color); + data->glyphs_shadow_array[text[i]] = renderChar(data->face, (FT_ULong)text[i], &black_color); + } + if (data->glyphs_array[text[i]]) + if (data->glyphs_array[text[i]]->image) { + if (width) + *width += data->glyphs_array[text[i]]->advance_x >> 6; + } + } +} + + /* drawFreeTypeString */ -void initDrawFreeTypeString(proplist_t pl, void **init_data) { +void initDrawFreeTypeString(proplist_t pl, WPluginData *init_data) { WMFreeTypeData *data; XColor xcolor; - _debug("invoke initDrawFreeTypeString with init_data[3] %s\n", init_data[3]); - + _debug("invoke initDrawFreeTypeString with init_data[3] %s\n", + init_data->array[2]); _debug("%x is ds_dpy\n", ds_dpy); - initDrawPlainString((Display *)init_data[1], (Colormap *)init_data[2]); + initDrawPlainString((Display *)init_data->array[0], (Colormap *)init_data->array[1]); _debug("then %x is ds_dpy\n", ds_dpy); /* set init_data[2] to array of RImage */ @@ -205,8 +233,8 @@ void initDrawFreeTypeString(proplist_t pl, void **init_data) { * this would better to have sharable font system but * I want to see this more in WINGs though -- ]d */ - init_data[3] = malloc(sizeof(WMFreeTypeData)); - data = init_data[3]; + init_data->array[2] = malloc(sizeof(WMFreeTypeData)); + data = init_data->array[2]; getColor(PLGetString(PLGetArrayElement(pl, 3)), ds_cmap, &xcolor); data->color.red = xcolor.red >> 8; data->color.green = xcolor.green >> 8; @@ -216,6 +244,7 @@ void initDrawFreeTypeString(proplist_t pl, void **init_data) { memset(data->glyphs_array, 0, sizeof(WMFreeTypeRImage*) * MAX_GLYPHS); data->glyphs_shadow_array = malloc(sizeof(WMFreeTypeRImage*) * MAX_GLYPHS); memset(data->glyphs_shadow_array, 0, sizeof(WMFreeTypeRImage*) * MAX_GLYPHS); + data->strwidth = widthOfFreeTypeString; if (!rc) { RContextAttributes rcattr; @@ -239,11 +268,11 @@ void initDrawFreeTypeString(proplist_t pl, void **init_data) { } void -destroyDrawFreeTypeString(proplist_t pl, void **func_data) { +destroyDrawFreeTypeString(proplist_t pl, WPluginData *func_data) { int i; /* error? no no no */ WMFreeTypeData *data; - data = (WMFreeTypeData *) func_data[3]; + data = (WMFreeTypeData *) func_data->array[2]; for (i = 0; i < MAX_GLYPHS; i++) { if (data->glyphs_array[i]) { if (data->glyphs_array[i]->image) @@ -305,10 +334,11 @@ logicalCombineArea(RImage *bg, RImage *image, } } + void drawFreeTypeString (proplist_t pl, Drawable d, int x, int y, - unsigned char *text, int length, void **func_data) { + unsigned char *text, int length, WPluginData *func_data) { WMFreeTypeData *data; RImage *rimg; int i, j, width, height; @@ -318,16 +348,16 @@ drawFreeTypeString (proplist_t pl, Drawable d, Window wdummy; /* see framewin.c for the order of arguments (look in wPluginPackData) */ - data = ((void **)func_data[1])[3]; /* initialized data */ - if (func_data[2]) - pixmap = *(Pixmap *)func_data[2]; - gc = *(GC *)func_data[3]; - width = *(int *)func_data[5]; - height = *(int *)func_data[6]; + data = ((WPluginData*)func_data->array[0])->array[2]; /* initialized data */ + if (func_data->array[1]) + pixmap = *(Pixmap *)func_data->array[1]; + gc = *(GC *)func_data->array[2]; + width = *(int *)func_data->array[4]; + height = *(int *)func_data->array[5]; /* create temp for drawing */ - if (!func_data[2]) { + if (!func_data->array[1]) { XGetGeometry(ds_dpy, d, &wdummy, &dummy, &dummy, &xwidth, &xheight, &dummy, &dummy); pixmap = XCreatePixmap(ds_dpy, d, xwidth, xheight, DefaultDepth(ds_dpy, DefaultScreen(ds_dpy))); XClearWindow(ds_dpy, d); @@ -368,13 +398,6 @@ drawFreeTypeString (proplist_t pl, Drawable d, XFreePixmap(ds_dpy, pixmap); RDestroyImage(rimg); - /* - _debug("%d\n", height); - i = (height + data->face->size->metrics.y_ppem)/2 - data->face->size->metrics.y_ppem; - XDrawLine(ds_dpy, d, gc, 5, y + i, 100, y + data->face->size->metrics.y_ppem); - XDrawLine(ds_dpy, d, gc, 100, y + i, 5, y + data->face->size->metrics.y_ppem); - */ - } } @@ -383,18 +406,27 @@ drawFreeTypeString (proplist_t pl, Drawable d, /* core */ void -destroyDrawString (proplist_t pl, void **init_data) { +destroyDrawString (proplist_t pl, WPluginData *init_data) { if (strcmp(PLGetString(PLGetArrayElement(pl, 2)), "drawPlainString") == 0) - destroyDrawPlainString((Display *)init_data[0], NULL); + destroyDrawPlainString((Display *)init_data->array[0], NULL); else if (strcmp(PLGetString(PLGetArrayElement(pl, 2)), "drawFreeTypeString") == 0) destroyDrawFreeTypeString(pl, init_data); } void -initDrawString (proplist_t pl, void **init_data) { +widthOfString (unsigned char *text, int length, WPluginData *func_data, + int *width, int *height, int *top) { + WMFreeTypeData *data; + + data = ((WPluginData*)func_data->array[0])->array[2]; + data->strwidth(text, length, func_data, width, height, top); +} + +void +initDrawString (proplist_t pl, WPluginData *init_data) { _debug("invoke initDrawString: %s\n", PLGetString(PLGetArrayElement(pl, 2))); if (strcmp(PLGetString(PLGetArrayElement(pl, 2)), "drawPlainString") == 0) - initDrawPlainString((Display *)init_data[1], (Colormap *)init_data[2]); + initDrawPlainString((Display *)init_data->array[0], (Colormap *)init_data->array[1]); #ifdef USE_FREETYPE else if (strcmp(PLGetString(PLGetArrayElement(pl, 2)), "drawFreeTypeString") == 0) initDrawFreeTypeString(pl, init_data); diff --git a/plugins/libwmfun/generic.h b/plugins/libwmfun/generic.h index 6cf9dddb..32be8340 100644 --- a/plugins/libwmfun/generic.h +++ b/plugins/libwmfun/generic.h @@ -22,6 +22,9 @@ * $Id$ * * $Log$ + * Revision 1.3 2000/12/11 03:10:26 id + * changes related to plugin system & drawstring + * * Revision 1.2 2000/12/03 22:18:20 id * initiate * @@ -41,6 +44,11 @@ #include +typedef struct _WPluginData { + int size; + void **array; +} WPluginData; + extern void initWindowMaker (Display *d, Colormap c); extern int start_image (const char *name, int argc, int argc_min, int argc_max, int width, int height, RImage **image); diff --git a/src/defaults.c b/src/defaults.c index e92e9670..45f88749 100644 --- a/src/defaults.c +++ b/src/defaults.c @@ -2212,8 +2212,10 @@ getTextRenderer(WScreen *scr, WDefaultEntry *entry, proplist_t value, elem = PLGetArrayElement(value, 2); /* function name */ if (!elem || !PLIsString(elem)) return False; func = PLGetString(elem); - scr->drawstring_func[changed] = wPluginCreateFunction (W_FUNCTION_DRAWSTRING, - lib, "initDrawString", func, "destroyDrawString", value, + scr->drawstring_func[changed] = wPluginCreateFunction(W_FUNCTION_DRAWSTRING, + lib, "initDrawString", + wPluginPackData(2, func, "widthOfString"), + "destroyDrawString", value, wPluginPackData(3, dpy, &scr->w_colormap, "dummy")); } diff --git a/src/framewin.c b/src/framewin.c index 67cc36d9..72d43ad1 100644 --- a/src/framewin.c +++ b/src/framewin.c @@ -947,9 +947,11 @@ wFrameWindowPaint(WFrameWindow *fwin) { WScreen *scr = fwin->screen_ptr; #ifdef DRAWSTRING_PLUGIN +#define DRAWSTRING_CURRENT_STATE fwin->flags.state + fwin->drawstring_proc_offset Pixmap *background; Pixmap tmp_bg; int tb = fwin->top_width; + WPluginData *pd; #endif if (fwin->flags.is_client_window_frame) @@ -1083,11 +1085,28 @@ wFrameWindowPaint(WFrameWindow *fwin) scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode]; #endif +#ifdef DRAWSTRING_PLUGIN + if(scr->drawstring_func[DRAWSTRING_CURRENT_STATE]) { + title = ShrinkString(*fwin->font, fwin->title, + fwin->titlebar->width - lofs - rofs, + scr->drawstring_func[DRAWSTRING_CURRENT_STATE]); + titlelen = strlen(title); + pd = wPluginPackData(1, scr->drawstring_func[DRAWSTRING_CURRENT_STATE]->data); + scr->drawstring_func[DRAWSTRING_CURRENT_STATE]->proc.widthOfString[W_DSPROC_WIDTHOFSTRING]( + title, titlelen, pd, &w, NULL, NULL); + wfree(pd); + } else { + title = ShrinkString(*fwin->font, fwin->title, + fwin->titlebar->width - lofs - rofs, NULL); + titlelen = strlen(title); + w = WMWidthOfString(*fwin->font, title, titlelen); + } +#else title = ShrinkString(*fwin->font, fwin->title, fwin->titlebar->width - lofs - rofs); titlelen = strlen(title); w = WMWidthOfString(*fwin->font, title, titlelen); - +#endif switch (fwin->flags.justification) { case WTJ_LEFT: x = lofs; @@ -1109,28 +1128,25 @@ wFrameWindowPaint(WFrameWindow *fwin) fwin->title_pixel[fwin->flags.state]); #ifdef DRAWSTRING_PLUGIN -#define DRAWSTRING_CURRENT_STATE fwin->flags.state + fwin->drawstring_proc_offset + /* if the plugin want to do shrinking locally, they can trick + * wmaker by returning a very short value (such as 0) to widthOfString -- I think */ if (scr->drawstring_func[DRAWSTRING_CURRENT_STATE]) { - void **p; - - p = wPluginPackData(6, - /* 0 number of argument, will be passed */ + pd = wPluginPackData(6, /* number of argument, will be passed */ scr->drawstring_func[DRAWSTRING_CURRENT_STATE]->data, - /* 1 plugin data, as it was initialized */ - background, - /* 2 current background Pixmap */ - fwin->title_gc, /* 3 gc */ - *fwin->font, /* 4 WMFont** */ + /* 0 plugin data, as it was initialized */ + background, /* 1 current background Pixmap */ + fwin->title_gc, /* 2 gc */ + *fwin->font, /* 3 WMFont** */ &fwin->titlebar->width, - /* 5 suggested width */ - &tb /* 6 suggested height */ + /* 4 suggested width */ + &tb /* 5 suggested height */ ); - scr->drawstring_func[DRAWSTRING_CURRENT_STATE]->proc.drawString( + scr->drawstring_func[DRAWSTRING_CURRENT_STATE]->proc.drawString[W_DSPROC_DRAWSTRING]( scr->drawstring_func[DRAWSTRING_CURRENT_STATE]->arg, fwin->titlebar->window, x, 0, - fwin->title, strlen(fwin->title), p); - free(p); + title, strlen(fwin->title), pd); + wfree(pd); } else { WMDrawString(scr->wmscreen, fwin->titlebar->window, *fwin->title_gc, *fwin->font, diff --git a/src/funcs.h b/src/funcs.h index 95fcd0f8..d10d6f47 100644 --- a/src/funcs.h +++ b/src/funcs.h @@ -26,6 +26,9 @@ #include #include "window.h" +#ifdef DRAWSTRING_PLUGIN +#include "plugin.h" +#endif typedef void (WCallBack)(void *cdata); @@ -116,7 +119,11 @@ WWindow *NextToFocusBefore(WWindow *wwin); void SlideWindow(Window win, int from_x, int from_y, int to_x, int to_y); +#ifdef DRAWSTRING_PLUGIN +char *ShrinkString(WMFont *font, char *string, int width, WFunction *func); +#else char *ShrinkString(WMFont *font, char *string, int width); +#endif char *FindImage(char *paths, char *file); diff --git a/src/icon.c b/src/icon.c index 283e3534..bb06b279 100644 --- a/src/icon.c +++ b/src/icon.c @@ -824,8 +824,13 @@ wIconPaint(WIcon *icon) int l; int w; +#ifdef DRAWSTRING_PLUGIN + tmp = ShrinkString(scr->icon_title_font, icon->icon_name, + wPreferences.icon_size-4, NULL); +#else tmp = ShrinkString(scr->icon_title_font, icon->icon_name, wPreferences.icon_size-4); +#endif w = WMWidthOfString(scr->icon_title_font, tmp, l=strlen(tmp)); if (w > icon->core->width - 4) diff --git a/src/menu.c b/src/menu.c index a89cef0e..a10de6aa 100644 --- a/src/menu.c +++ b/src/menu.c @@ -731,6 +731,14 @@ paintEntry(WMenu *menu, int index, int selected) WScreen *scr=menu->frame->screen_ptr; Window win = menu->menu->window; WMenuEntry *entry=menu->entries[index]; +#ifdef DRAWSTRING_PLUGIN + Pixmap tmp_bg; + Pixmap *texture_data; + WPluginData *p; + int _y; + int tb = menu->entry_height; /* convert short into int */ +#endif + if (!menu->flags.realized) return; h = menu->entry_height; @@ -800,12 +808,6 @@ paintEntry(WMenu *menu, int index, int selected) #ifdef DRAWSTRING_PLUGIN if (scr->drawstring_func[W_STRING_MTEXT]) { - Pixmap tmp_bg; - Pixmap *texture_data; - void **p; - int _y; - int tb = menu->entry_height; /* convert short into int */ - _y = (wPreferences.menu_style == MS_NORMAL) ? 0 : y; texture_data = menu->flags.brother ? &menu->brother->menu_texture_data : &menu->menu_texture_data; @@ -835,10 +837,9 @@ paintEntry(WMenu *menu, int index, int selected) &textGC, scr->menu_entry_font, &menu->frame->core->width, - &tb, - "extendable"); + &tb, "extendable"); - scr->drawstring_func[W_STRING_MTEXT]->proc.drawString( + scr->drawstring_func[W_STRING_MTEXT]->proc.drawString[W_DSPROC_DRAWSTRING]( scr->drawstring_func[W_STRING_MTEXT]->arg, win, x, y, @@ -908,11 +909,54 @@ paintEntry(WMenu *menu, int index, int selected) /* draw right text */ if (entry->rtext && entry->cascade<0) { + +#ifdef DRAWSTRING_PLUGIN + if (scr->drawstring_func[W_STRING_MTEXT]) { + /* + p = wPluginPackData(1, scr->drawstring_func[W_STRING_MTEXT]->data); + scr->drawstring_func[W_STRING_MTEXT]->proc.widthOfString[W_DSPROC_WIDTHOFSTRING]( + entry->rtext, strlen(entry->rtext), p, &tw, NULL, NULL); + wfree(p); + + texture_data = menu->flags.brother ? + &menu->brother->menu_texture_data : &menu->menu_texture_data; + + tmp_bg = XCreatePixmap(dpy, win, w, menu->entry_height, + DefaultDepth(dpy, DefaultScreen(dpy))); + + XCopyArea(dpy, win, tmp_bg, textGC, + 0, y, w, menu->entry_height, 0, 0); + + p = wPluginPackData(6, + scr->drawstring_func[W_STRING_MTEXT]->data, + &tmp_bg, + &textGC, + scr->menu_entry_font, + &menu->frame->core->width, + &tb, "extendable"); + + scr->drawstring_func[W_STRING_MTEXT]->proc.drawString[W_DSPROC_DRAWSTRING]( + scr->drawstring_func[W_STRING_MTEXT]->arg, + win, + w-0-tw, y, + entry->rtext, strlen(entry->rtext), p); + + XFreePixmap(dpy, tmp_bg); + + free(p); + */ + } else { + tw = WMWidthOfString(scr->menu_entry_font, entry->rtext, + strlen(entry->rtext)); + WMDrawString(scr->wmscreen, win, textGC, scr->menu_entry_font, w-6-tw, + y + 3 + wPreferences.menu_text_clearance, entry->rtext, strlen(entry->rtext)); + } +#else tw = WMWidthOfString(scr->menu_entry_font, entry->rtext, strlen(entry->rtext)); - - WMDrawString(scr->wmscreen, win, textGC, scr->menu_entry_font, w-6-tw, - y + 3 + wPreferences.menu_text_clearance, entry->rtext, strlen(entry->rtext)); + WMDrawString(scr->wmscreen, win, textGC, scr->menu_entry_font, w-6-tw, + y + 3 + wPreferences.menu_text_clearance, entry->rtext, strlen(entry->rtext)); +#endif } } diff --git a/src/misc.c b/src/misc.c index 26373af0..8dedb270 100644 --- a/src/misc.c +++ b/src/misc.c @@ -48,6 +48,7 @@ #include "dialog.h" #include "xutil.h" #include "xmodifier.h" +#include "plugin.h" /**** global variables *****/ @@ -420,23 +421,45 @@ SlideWindow(Window win, int from_x, int from_y, int to_x, int to_y) char* +#ifdef DRAWSTRING_PLUGIN +ShrinkString(WMFont *font, char *string, int width, WFunction *func) +#else ShrinkString(WMFont *font, char *string, int width) +#endif { int w, w1=0; int p; char *pos; char *text; int p1, p2, t; +#ifdef DRAWSTRING_PLUGIN + WPluginData *pd; +#endif if (wPreferences.multi_byte_text) return wstrdup(string); p = strlen(string); +#ifdef DRAWSTRING_PLUGIN + if (func) { + pd = wPluginPackData(1, func->data); + func->proc.widthOfString[W_DSPROC_WIDTHOFSTRING]( + string, strlen(string), pd, &w, NULL, NULL); + } else w = WMWidthOfString(font, string, p); +#else w = WMWidthOfString(font, string, p); +#endif text = wmalloc(strlen(string)+8); strcpy(text, string); if (w<=width) +#ifdef DRAWSTRING_PLUGIN + { + if (func) wfree(pd); + return text; + } +#else return text; +#endif pos = strchr(text, ' '); if (!pos) @@ -445,7 +468,14 @@ ShrinkString(WMFont *font, char *string, int width) if (pos) { *pos = 0; p = strlen(text); - w1 = WMWidthOfString(font, text, p); +#ifdef DRAWSTRING_PLUGIN + if (func) { + func->proc.widthOfString[W_DSPROC_WIDTHOFSTRING]( + text, strlen(text), pd, &w1, NULL, NULL); + } else w1 = WMWidthOfString(font, text, p); +#else + w1 = WMWidthOfString(font, text, p); +#endif if (w1 > width) { w1 = 0; p = 0; @@ -462,14 +492,28 @@ ShrinkString(WMFont *font, char *string, int width) *text=0; } strcat(text, "..."); +#ifdef DRAWSTRING_PLUGIN + if (func) { + func->proc.widthOfString[W_DSPROC_WIDTHOFSTRING]( + "...", 3, pd, &w1, NULL, NULL); + } else w1 = WMWidthOfString(font, "...", 3); + width -= w1; +#else width -= WMWidthOfString(font, "...", 3); - +#endif pos = string; p1=0; p2=p; t = (p2-p1)/2; while (p2>p1 && p1!=t) { +#ifdef DRAWSTRING_PLUGIN + if (func) { + func->proc.widthOfString[W_DSPROC_WIDTHOFSTRING]( + &string[p-t], t, pd, &w, NULL, NULL); + } else w = WMWidthOfString(font, &string[p-t], t); +#else w = WMWidthOfString(font, &string[p-t], t); +#endif if (w>width) { p2 = t; t = p1+(p2-p1)/2; @@ -479,6 +523,9 @@ ShrinkString(WMFont *font, char *string, int width) } else p2=p1=t; } +#ifdef DRAWSTRING_PLUGIN + if (func) wfree(pd); +#endif strcat(text, &string[p-p1]); return text; diff --git a/src/plugin.c b/src/plugin.c index 0aca9fdd..74558306 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -45,30 +45,33 @@ #include -void** +WPluginData* wPluginPackData(int members, ...) { void **p; va_list vp; int i; - p = wmalloc(sizeof(void *) * (members + 1)); - memset(p, 0, sizeof(void *) * (members + 1)); - p[0] = (void *)members; + WPluginData *data; + data = wmalloc(sizeof(WPluginData)); + data->size = members; + data->array = wmalloc(sizeof(void *) * (members)); + memset(data->array, 0, sizeof(void *) * (members)); va_start(vp, members); - for(i=1;iarray[i] = va_arg(vp, void *); } va_end(vp); - return p; + return data; } WFunction * wPluginCreateFunction(int type, char *library_name, - char *init_proc_name, char *proc_name, char *free_data_proc_name, - proplist_t pl_arg, void *init_data) + char *init_proc_name, WPluginData *proc_name, char *free_data_proc_name, + proplist_t pl_arg, WPluginData *init_data) { WFunction *function; _DL_InitDataProc *initProc; + int i; function = wmalloc(sizeof(WFunction)); memset(function, 0, sizeof(WFunction)); @@ -80,12 +83,17 @@ wPluginCreateFunction(int type, char *library_name, return NULL; } - function->proc.any = dlsym(function->handle, proc_name); - if (!function->proc.any) { - wwarning(_("function \"%s\" not found in library \"%s\""), proc_name, library_name); - dlclose(function->handle); - wfree(function); - return NULL; + i = proc_name->size; + function->proc.any = wmalloc(sizeof(_DL_AnyProc) * i); + for (i = 0; i < proc_name->size; i++) { + function->proc.any[i] = dlsym(function->handle, (char *)proc_name->array[i]); + if (!function->proc.any[i]) { + wwarning(_("function \"%s\" not found in library \"%s\""), proc_name, library_name); + dlclose(function->handle); + wfree(function->proc.any); + wfree(function); + return NULL; + } } if (free_data_proc_name) { @@ -129,6 +137,7 @@ wPluginDestroyFunction(WFunction *function) wfree(function->data); } if (function->arg) PLRelease(function->arg); + if (function->proc.any) wfree(function->proc.any); wfree(function); return; } diff --git a/src/plugin.h b/src/plugin.h index 47530659..6f865e29 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -39,6 +39,11 @@ #define W_FUNCTION_ANY 0 #define W_FUNCTION_DRAWSTRING 1 +typedef struct _WPluginData { + int size; + void **array; +} WPluginData; + typedef void _DL_AnyProc(proplist_t); /* first 3 must == WS_FOCUSED WS_UNFOCUSED WS_PFOCUSED -- ]d */ @@ -50,27 +55,29 @@ typedef void _DL_AnyProc(proplist_t); #define W_STRING_MTEXT 4 #define W_STRING_MEMBERS 5 -typedef void _DL_DrawStringProc(proplist_t, Drawable, int, int, char*, int, void**); +typedef void _DL_DrawStringProc(proplist_t, Drawable, int, int, char*, int, WPluginData*); +typedef void _DL_WidthStringProc(char*, int, WPluginData*, int*, int*, int*); #endif -typedef void _DL_FreeDataProc(proplist_t pl, void *free_data); +typedef void _DL_FreeDataProc(proplist_t pl, WPluginData *free_data); -typedef int _DL_InitDataProc(proplist_t pl, void *init_data); /* prototype - for function - initializer - */ +typedef int _DL_InitDataProc(proplist_t pl, WPluginData *init_data); + /* prototype for function initializer */ + +#define W_DSPROC_DRAWSTRING 0 +#define W_DSPROC_WIDTHOFSTRING 1 +#define W_DSPROC_MEMBERS 2 typedef struct _WFunction { int type; void *handle; proplist_t arg; - void *data; + WPluginData *data; _DL_FreeDataProc *freeData; union { - _DL_AnyProc *any; -#ifdef DRAWSTRING_PLUGIN - _DL_DrawStringProc *drawString; -#endif + _DL_AnyProc **any; + _DL_DrawStringProc **drawString; + _DL_WidthStringProc **widthOfString; } proc; /* char *libraryName; @@ -90,11 +97,11 @@ typedef struct _WFunction { */ WFunction* wPluginCreateFunction(int type, char *library_name, - char *init_proc_name, char *proc_name, char *free_data_proc_name, - proplist_t pl_arg, void *init_data); + char *init_proc_name, WPluginData *funcs, char *free_data_proc_name, + proplist_t pl_arg, WPluginData *init_data); void wPluginDestroyFunction(WFunction *function); -void** wPluginPackData(int members, ...); +WPluginData* wPluginPackData(int members, ...); #endif diff --git a/src/switchmenu.c b/src/switchmenu.c index 52328bcb..aba143bb 100644 --- a/src/switchmenu.c +++ b/src/switchmenu.c @@ -195,7 +195,12 @@ UpdateSwitchMenu(WScreen *scr, WWindow *wwin, int action) sprintf(title, "%s", wwin->frame->title); else sprintf(title, "%s", DEF_WINDOW_TITLE); +#ifdef DRAWSTRING_PLUGIN + t = ShrinkString(scr->menu_entry_font, title, MAX_WINDOWLIST_WIDTH, + scr->drawstring_func[W_STRING_MTEXT]); +#else t = ShrinkString(scr->menu_entry_font, title, MAX_WINDOWLIST_WIDTH); +#endif if (IS_OMNIPRESENT(wwin)) idx = -1; @@ -252,8 +257,12 @@ UpdateSwitchMenu(WScreen *scr, WWindow *wwin, int action) else sprintf(title, "%s", DEF_WINDOW_TITLE); - t = ShrinkString(scr->menu_entry_font, title, - MAX_WINDOWLIST_WIDTH); +#ifdef DRAWSTRING_PLUGIN + t = ShrinkString(scr->menu_entry_font, title, MAX_WINDOWLIST_WIDTH, + scr->drawstring_func[W_STRING_MTEXT]); +#else + t = ShrinkString(scr->menu_entry_font, title, MAX_WINDOWLIST_WIDTH); +#endif entry->text = t; wMenuRealize(switchmenu);