From ecda429cecfb974aa82483788a2f3adf5ebafd85 Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Fri, 17 Oct 2008 20:46:21 +0200 Subject: [PATCH] ALL: Remove XPM support --- icons/free.xpm | 17 ----------------- icons/max.xpm | 18 ------------------ icons/tile.xpm | 17 ----------------- src/bar.c | 37 +++++++++++++----------------------- src/config.c | 22 +++++++--------------- src/draw.c | 51 +++----------------------------------------------- src/event.c | 40 +++++++++++++++++++-------------------- src/layout.c | 2 +- src/structs.h | 3 +-- src/wmfs.c | 5 ++--- src/wmfs.h | 8 ++------ wmfsrc | 6 +++--- 12 files changed, 52 insertions(+), 174 deletions(-) delete mode 100644 icons/free.xpm delete mode 100644 icons/max.xpm delete mode 100644 icons/tile.xpm diff --git a/icons/free.xpm b/icons/free.xpm deleted file mode 100644 index a62b0a1..0000000 --- a/icons/free.xpm +++ /dev/null @@ -1,17 +0,0 @@ -/* XPM */ -static char * free_xpm[] = -{ - "10 10 2 1", - " c None", - "+ c #ffffff", - "++++++++++", - "+ +", - "+ +++++ +", - "+ + + +", - "+ + ++ +", - "+ ++++++ +", - "+ + + +", - "+ +++++ +", - "+ +", - "++++++++++" -}; diff --git a/icons/max.xpm b/icons/max.xpm deleted file mode 100644 index 53a979d..0000000 --- a/icons/max.xpm +++ /dev/null @@ -1,18 +0,0 @@ -/* XPM */ -static char * max_xpm[] = -{ - "10 10 2 1", - " c None", - "+ c #ffffff", - "++++++++++", - "++++++++++", - "+ +", - "+ +", - "+ +", - "+ +", - "+ +", - "+ +", - "++++++++++", - "++++++++++" -}; - diff --git a/icons/tile.xpm b/icons/tile.xpm deleted file mode 100644 index efbea80..0000000 --- a/icons/tile.xpm +++ /dev/null @@ -1,17 +0,0 @@ -/* XPM */ -static char * tile_xpm[] = -{ - "10 10 2 1", - " c None", - "+ c #ffffff", - "++++++++++", - "+ + +", - "+ + +", - "+ ++++++", - "+ + +", - "+ + +", - "+ ++++++", - "+ + +", - "+ + +", - "++++++++++" -}; diff --git a/src/bar.c b/src/bar.c index 1f604dc..a936e5a 100644 --- a/src/bar.c +++ b/src/bar.c @@ -118,7 +118,7 @@ updatebar(void) draw_taglist(bar->dr); /* Draw layout symbol */ - draw_layout(taglen[conf.ntag], bary + (!conf.bartop)); + draw_layout(); /* Draw status text */ draw_text(bar->dr, mw - textw(bartext), fonth, conf.colors.text, conf.colors.bar, 0, bartext); @@ -151,11 +151,10 @@ updatebutton(Bool c) int y = 0, hi = 0; /* Calcul the position of the first button with the layout image size */ - j = taglen[conf.ntag] + get_image_attribute(tags[seltag].layout.image)->width + PAD / 2; + j = taglen[conf.ntag] + textw(tags[seltag].layout.symbol) + PAD*1.5; if(!conf.bartop) - y = bary + 1; - + y = bary + 2; if(conf.tagbordwidth) hi = -1; @@ -164,22 +163,18 @@ updatebutton(Bool c) /* CALCUL POSITION */ { + buttonw = textw(conf.barbutton[i].content) + BPAD; + if(!(x = conf.barbutton[i].x)) { if(i) - pm += (conf.barbutton[i-1].type) ? - get_image_attribute(conf.barbutton[i-1].content)->width : - textw(conf.barbutton[i-1].content) + BPAD; + pm += textw(conf.barbutton[i-1].content) + BPAD; - x = (!i) ? j : j + pm; + buttonw = textw(conf.barbutton[i].content) + BPAD; + x = (!i) ? j : j + pm; } - - buttonw = (conf.barbutton[i].type) ? - get_image_attribute(conf.barbutton[i].content)->width : - textw(conf.barbutton[i].content) + BPAD; } - /* FIRST TIME */ { if(!c) @@ -190,21 +185,15 @@ updatebutton(Bool c) } } - /* REFRESH/DRAW TEXT/IMAGE */ + /* REFRESH TEXT */ { if(!conf.barbutton[i].bw) return; - if(!conf.barbutton[i].type) - bar_refresh_color(conf.barbutton[i].bw); - bar_moveresize(conf.barbutton[i].bw, x, y, buttonw, barheight + hi); - /* Check the button type (image/text) */ - if(conf.barbutton[i].type) - draw_image(conf.barbutton[i].bw->dr, 0, 0, - conf.barbutton[i].content); - else - draw_text(conf.barbutton[i].bw->dr, BPAD/2, fonth, conf.barbutton[i].fg_color, - conf.barbutton[i].bg_color, BPAD, conf.barbutton[i].content); + bar_refresh_color(conf.barbutton[i].bw); + bar_moveresize(conf.barbutton[i].bw, x, y, buttonw, barheight + hi); + draw_text(conf.barbutton[i].bw->dr, BPAD/2, fonth, conf.barbutton[i].fg_color, + conf.barbutton[i].bg_color, PAD, conf.barbutton[i].content); /* Refresh button */ bar_refresh(conf.barbutton[i].bw); diff --git a/src/config.c b/src/config.c index 83f4345..bea1580 100644 --- a/src/config.c +++ b/src/config.c @@ -190,7 +190,7 @@ init_conf(void) static cfg_opt_t layout_opts[] = { CFG_STR("type", "", CFGF_NONE), - CFG_STR("image", "", CFGF_NONE), + CFG_STR("symbol", "", CFGF_NONE), CFG_END() }; @@ -241,7 +241,6 @@ init_conf(void) static cfg_opt_t button_opts[] = { - CFG_STR("type", "text", CFGF_NONE), CFG_STR("content", "", CFGF_NONE), CFG_SEC("mouse", mouse_button_opts, CFGF_MULTI), CFG_STR("fg_color", "#000000", CFGF_NONE), @@ -358,12 +357,12 @@ init_conf(void) { fprintf(stderr, "WMFS Configuration: Too much or no layouts\n"); conf.nlayout = 1; - conf.layout[0].image = strdup("TILE"); + conf.layout[0].symbol = strdup("TILE"); conf.layout[0].func = tile; } - if(!conf.layout[0].image - && !conf.layout[0].func) + if(!conf.layout[0].symbol + && !conf.layout[0].func) { for(i = 0; i < conf.nlayout; ++i) { @@ -376,7 +375,7 @@ init_conf(void) } else { - conf.layout[i].image = strdup(var_to_str(cfg_getstr(cfgtmp, "image"))); + conf.layout[i].symbol = strdup(var_to_str(cfg_getstr(cfgtmp, "symbol"))); conf.layout[i].func = name_to_func(strdup(cfg_getstr(cfgtmp, "type")), layout_list); } } @@ -460,16 +459,9 @@ init_conf(void) conf.barbutton[i].mouse[j] = char_to_button(cfg_getstr(cfgtmp3, "button")); } conf.barbutton[i].nmousesec = cfg_size(cfgtmp2, "mouse"); - if(strcmp("image", strdup(cfg_getstr(cfgtmp2, "type"))) == 0) - conf.barbutton[i].type = True; - else - conf.barbutton[i].type = False; conf.barbutton[i].content = strdup(var_to_str(cfg_getstr(cfgtmp2, "content"))); - if(!conf.barbutton[i].type) - { - conf.barbutton[i].fg_color = strdup(var_to_str(cfg_getstr(cfgtmp2, "fg_color"))); - conf.barbutton[i].bg_color = getcolor(strdup(var_to_str(cfg_getstr(cfgtmp2, "bg_color")))); - } + conf.barbutton[i].fg_color = strdup(var_to_str(cfg_getstr(cfgtmp2, "fg_color"))); + conf.barbutton[i].bg_color = getcolor(strdup(var_to_str(cfg_getstr(cfgtmp2, "bg_color")))); conf.barbutton[i].x = cfg_getint(cfgtmp2, "x"); } diff --git a/src/draw.c b/src/draw.c index c329d2d..b68c2df 100644 --- a/src/draw.c +++ b/src/draw.c @@ -57,24 +57,6 @@ draw_text(Drawable d, int x, int y, char* fg, uint bg, int pad, char *str) return; } -/* Drawing image function : - * Only *.xpm file for now. */ -void -draw_image(Drawable dr, int x, int y, char *file) -{ - XImage *img; - - if (XpmReadFileToImage(dpy, file, &img, NULL, NULL)) { - fprintf(stderr, "WMFS Error: reading xpm file %s\n", file); - exit(EXIT_FAILURE); - } - XPutImage(dpy, dr, gc, img, 0, 0, x, y, img->width, img->height); - - XFree(img); - - return; -} - void draw_taglist(Drawable dr) { @@ -106,24 +88,10 @@ draw_taglist(Drawable dr) } void -draw_layout(int x, int y) +draw_layout(void) { - if(!layoutsym) - { - layoutsym = bar_create(x, y, - get_image_attribute(tags[seltag].layout.image)->width, - barheight-1, 0, conf.colors.bar, False); - XMapRaised(dpy, layoutsym->win); - } - - bar_refresh_color(layoutsym); - bar_moveresize(layoutsym, x, y, get_image_attribute(tags[seltag].layout.image)->width, barheight-1); - - draw_image(layoutsym->dr, 0, - (barheight/2 - get_image_attribute(tags[seltag].layout.image)->height/2), - tags[seltag].layout.image); - - bar_refresh(layoutsym); + draw_text(bar->dr, taglen[conf.ntag] + PAD/2, fonth, conf.colors.layout_fg, + conf.colors.layout_bg, PAD, tags[seltag].layout.symbol); return; } @@ -139,19 +107,6 @@ draw_rectangle(Drawable dr, int x, int y, uint w, uint h, uint color) return; } -XImage* -get_image_attribute(char *file) -{ - XImage *ret; - - if (XpmReadFileToImage(dpy, file, &ret, NULL, NULL)) { - fprintf(stderr, "WMFS Error: reading xpm file %s\n", file); - exit(EXIT_FAILURE); - } - - return ret; -} - void draw_border(Window win, int color) { diff --git a/src/event.c b/src/event.c index 49020ca..91e3cde 100644 --- a/src/event.c +++ b/src/event.c @@ -158,32 +158,32 @@ buttonpress(XEvent ev) uicb_tag("-1"); } } - } - - } - } - /* ****** */ - /* LAYOUT */ - /* ****** */ - else if(ev.xbutton.window == layoutsym->win) - { - /* BUTTON 1 / 4 */ + /* ****** */ + /* LAYOUT */ + /* ****** */ { - if(ev.xbutton.button == Button1 - || ev.xbutton.button == Button4) - layoutswitch(True); + if(ev.xbutton.x >= taglen[conf.ntag] + && ev.xbutton.x <= taglen[conf.ntag] + textw(tags[seltag].layout.symbol) + PAD/2) + { + /* BUTTON 1 / 4 */ + { + if(ev.xbutton.button == Button1 + || ev.xbutton.button == Button4) + layoutswitch(True); + } + /* BUTTON 3 / 5 */ + { + if(ev.xbutton.button == Button3 + || ev.xbutton.button == Button5) + layoutswitch(False); + } + } } - /* BUTTON 3 / 5 */ - { - if(ev.xbutton.button == Button3 - || ev.xbutton.button == Button5) - layoutswitch(False); - } - } + } } /* **** */ diff --git a/src/layout.c b/src/layout.c index 9f8a771..3c104c8 100644 --- a/src/layout.c +++ b/src/layout.c @@ -83,7 +83,7 @@ layoutswitch(Bool b) for(i = 0; i < conf.nlayout; ++i) { - if(tags[seltag].layout.image == conf.layout[i].image + if(tags[seltag].layout.symbol == conf.layout[i].symbol && tags[seltag].layout.func == conf.layout[i].func) { if(b) diff --git a/src/structs.h b/src/structs.h index 8d37598..a691fd9 100644 --- a/src/structs.h +++ b/src/structs.h @@ -103,7 +103,6 @@ typedef struct /* Bar Button */ typedef struct { - Bool type; /* False -> text, True -> image. */ char *content; BarWindow *bw; char *fg_color; @@ -118,7 +117,7 @@ typedef struct /* Layout Structure */ typedef struct { - char *image; + char *symbol; void (*func)(void); } Layout; diff --git a/src/wmfs.c b/src/wmfs.c index 3ca5a6b..835656b 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -96,7 +96,6 @@ quit(void) XFreeCursor(dpy, cursor[CurMove]); XFreeCursor(dpy, cursor[CurResize]); bar_delete(bar); - bar_delete(layoutsym); if(conf.nbutton) for(i = 0; i < conf.nbutton; ++i) bar_delete(conf.barbutton[i].bw); @@ -134,8 +133,8 @@ init(void) fprintf(stderr, "WMFS Error: Cannot initialize font\n"); xftfont = XftFontOpenName(dpy, screen, "sans-10"); } - fonth = (xftfont->ascent + xftfont->descent); - barheight = fonth + 3; + fonth = (xftfont->ascent + xftfont->descent) - 1; + barheight = fonth + 4; /* INIT CURSOR */ diff --git a/src/wmfs.h b/src/wmfs.h index a0d4151..7b731cf 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -50,8 +51,6 @@ #include #include #include -#include -#include /* Local headers */ #include "config.h" @@ -80,11 +79,9 @@ void uicb_togglebarpos(uicb_t); /* draw.c */ void draw_text(Drawable d, int x, int y, char* fg, uint bg, int pad, char *str); -void draw_image(Drawable dr, int x, int y, char *file); void draw_taglist(Drawable dr); -void draw_layout(int x, int y); +void draw_layout(void); void draw_rectangle(Drawable dr, int x, int y, uint w, uint h, uint color); -XImage* get_image_attribute(char *file); void draw_border(Window win, int color); ushort textw(const char *text); @@ -192,7 +189,6 @@ XftFont *xftfont; /* Bar / Tags */ BarWindow *bar; -BarWindow *layoutsym; Tag tags[MAXTAG]; int barheight; char bartext[1024]; diff --git a/wmfsrc b/wmfsrc index f437d4e..e1deb23 100644 --- a/wmfsrc +++ b/wmfsrc @@ -42,9 +42,9 @@ colors layouts { - layout { type = "tile" image = "/usr/local/share/wmfs/icons/tile.xpm" } - layout { type = "max" image = "/usr/local/share/wmfs/icons/max.xpm" } - layout { type = "free" image = "/usr/local/share/wmfs/icons/free.xpm" } + layout { type = "tile" symbol = "TILE" } + layout { type = "max" symbol = "MAX" } + layout { type = "free" symbol = "FREE" } } tags