From 7055530895b0734a8d4787ed262019dc7a6c8298 Mon Sep 17 00:00:00 2001 From: kojima Date: Sat, 16 Oct 2004 22:05:04 +0000 Subject: [PATCH] - Added support for NET_WM_NAME/NET_WM_ICON_NAME - moved out font name conversion code from getstyle/setstyle/convertfonts and made it support fontsets --- ChangeLog | 2 + TODO | 7 -- WPrefs.app/FontSimple.c | 11 --- src/client.c | 36 ++++++---- src/icon.c | 9 ++- src/screen.c | 2 - src/shutdown.c | 2 + src/window.c | 10 +-- src/window.h | 2 + src/wmspec.c | 71 +++++++++++++++++-- src/wmspec.h | 3 + util/Makefile.am | 6 ++ util/convertfonts.c | 169 +------------------------------------------- util/fontconv.c | 183 ++++++++++++++++++++++++++++++++++++++++++++++++ util/getstyle.c | 169 +------------------------------------------- util/setstyle.c | 169 +------------------------------------------- util/wmaker.inst.in | 3 - 17 files changed, 305 insertions(+), 549 deletions(-) create mode 100644 util/fontconv.c diff --git a/ChangeLog b/ChangeLog index 54e77953..a16ff25c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -159,6 +159,8 @@ Changes since version 0.80.2: - Removed old code to store/restore workspace state (now relies on netwm) - Added a (simple) Font Configuration for fontconfig fonts - MacOS X style window switching panel (navigate through windows with Alt-Tab or arrow keys) +- Added support for NET_WM_NAME/NET_WM_ICON_NAME +- moved out font name conversion code from getstyle/setstyle/convertfonts and made it support fontsets Changes since version 0.80.1: ............................. diff --git a/TODO b/TODO index cb57bbfd..77caa8df 100644 --- a/TODO +++ b/TODO @@ -5,18 +5,11 @@ To do before next release: and give a warning if font is not converted, but let user manually convert it with convertfonts as the process may need manual tweaking for best results) -- convertfonts to handle fontsets (keep in mind that many people without - multibyte still have a fontsets in their config files). ev use LANG and - MB_CUR_MAX -- automate convertfonts for different locales - Append .UTF-8 to locale - figure out a better gnustep path for wprefs.app installation -- pick a good font fallback - figure a better fullscreen level -- clean up netwm hints on exit - check whether window states are being saved/restored properly via netwm on restart/crash-restart (grep for XXX/TODO) -- review wmaker.inst remake wrlib rule to not compile with -fomit-frame-pointer and stuff if its added to CFLAGS diff --git a/WPrefs.app/FontSimple.c b/WPrefs.app/FontSimple.c index 8c777099..3c10db90 100644 --- a/WPrefs.app/FontSimple.c +++ b/WPrefs.app/FontSimple.c @@ -234,17 +234,6 @@ lookup_available_fonts(_Panel *panel) FcObjectSetDestroy(os); if (pat) FcPatternDestroy(pat); - - panel->fonts->families[panel->fonts->familyn++].name= wstrdup("sans-serif"); - family= panel->fonts->families + panel->fonts->familyn-1; - family->styles= wmalloc(sizeof(FontStyle)*2); - family->stylen= 2; - family->styles[0].weight= FC_WEIGHT_MEDIUM; - family->styles[0].slant= FC_SLANT_ROMAN; - family->styles[0].width= FC_WIDTH_NORMAL; - family->styles[1].weight= FC_WEIGHT_BOLD; - family->styles[1].slant= FC_SLANT_ROMAN; - family->styles[1].width= FC_WIDTH_NORMAL; panel->fonts->families[panel->fonts->familyn++].name= wstrdup("sans"); family= panel->fonts->families + panel->fonts->familyn-1; diff --git a/src/client.c b/src/client.c index 6cec8119..f87435ea 100644 --- a/src/client.c +++ b/src/client.c @@ -325,25 +325,31 @@ wClientCheckProperty(WWindow *wwin, XPropertyEvent *event) switch (event->atom) { case XA_WM_NAME: - /* window title was changed */ - if (!wFetchName(dpy, wwin->client_win, &tmp)) { - wWindowUpdateName(wwin, NULL); - } else { - wWindowUpdateName(wwin, tmp); + if (!wwin->flags.net_has_title) + { + /* window title was changed */ + if (!wFetchName(dpy, wwin->client_win, &tmp)) { + wWindowUpdateName(wwin, NULL); + } else { + wWindowUpdateName(wwin, tmp); + } + if (tmp) + XFree(tmp); } - if (tmp) - XFree(tmp); break; case XA_WM_ICON_NAME: - if (!wwin->icon) - break; - else { - char *new_title; - - /* icon title was changed */ - wGetIconName(dpy, wwin->client_win, &new_title); - wIconChangeTitle(wwin->icon, new_title); + if (!wwin->flags.net_has_icon_title) + { + if (!wwin->icon) + break; + else { + char *new_title; + + /* icon title was changed */ + wGetIconName(dpy, wwin->client_win, &new_title); + wIconChangeTitle(wwin->icon, new_title); + } } break; diff --git a/src/icon.c b/src/icon.c index 92fec5b3..6425a0a0 100644 --- a/src/icon.c +++ b/src/icon.c @@ -43,8 +43,9 @@ #include "application.h" #include "defaults.h" #include "appicon.h" +#include "wmspec.h" -/**** Global variables ****/ +/**** Global varianebles ****/ extern WPreferences wPreferences; #define MOD_MASK wPreferences.modifier_mask @@ -179,7 +180,11 @@ wIconCreate(WWindow *wwin) icon->file = wstrdup(file); } - wGetIconName(dpy, wwin->client_win, &icon->icon_name); + icon->icon_name = wNETWMGetIconName(wwin->client_win); + if (icon->icon_name) + wwin->flags.net_has_icon_title= 1; + else + wGetIconName(dpy, wwin->client_win, &icon->icon_name); icon->tile_type = TILE_NORMAL; diff --git a/src/screen.c b/src/screen.c index 01fe0c6e..85079d95 100644 --- a/src/screen.c +++ b/src/screen.c @@ -1084,8 +1084,6 @@ wScreenSaveState(WScreen *scr) WWindow *wwin; char *str; WMPropList *old_state, *foo; - CARD32 data[2]; - make_keys(); diff --git a/src/shutdown.c b/src/shutdown.c index 3f159c53..d860b5da 100644 --- a/src/shutdown.c +++ b/src/shutdown.c @@ -36,6 +36,7 @@ #include "properties.h" #include "session.h" #include "winspector.h" +#include "wmspec.h" extern Atom _XA_WM_DELETE_WINDOW; extern Time LastTimestamp; @@ -197,6 +198,7 @@ RestoreDesktop(WScreen *scr) XSetInputFocus(dpy, PointerRoot, RevertToParent, CurrentTime); wColormapInstallForWindow(scr, NULL); PropCleanUp(scr->root_win); + wNETWMCleanup(scr); XSync(dpy, 0); } diff --git a/src/window.c b/src/window.c index 96bb7187..35cc9b69 100644 --- a/src/window.c +++ b/src/window.c @@ -722,12 +722,14 @@ wManageWindow(WScreen *scr, Window window) return NULL; } - if (!wFetchName(dpy, window, &title)) { - title = NULL; - } - wwin = wWindowCreate(); + title= wNETWMGetWindowName(window); + if (title) + wwin->flags.net_has_title= 1; + if (!title && !wFetchName(dpy, window, &title)) + title = NULL; + XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor); #ifdef DEBUG diff --git a/src/window.h b/src/window.h index c696175b..54afee81 100644 --- a/src/window.h +++ b/src/window.h @@ -304,6 +304,8 @@ typedef struct WWindow { unsigned int net_skip_pager:1; unsigned int net_handle_icon:1; unsigned int net_show_desktop:1; + unsigned int net_has_title:1; /* use netwm version of WM_NAME */ + unsigned int net_has_icon_title:1; #endif } flags; /* state of the window */ diff --git a/src/wmspec.c b/src/wmspec.c index 602b5f98..2ce0269a 100644 --- a/src/wmspec.c +++ b/src/wmspec.c @@ -74,10 +74,10 @@ static Atom net_moveresize_window; /* TODO */ static Atom net_wm_moveresize; /* TODO */ /* Application Window Properties */ -static Atom net_wm_name; /* TODO */ -static Atom net_wm_visible_name; /* TODO */ -static Atom net_wm_icon_name; /* TODO */ -static Atom net_wm_visible_icon_name; /* TODO */ +static Atom net_wm_name; +static Atom net_wm_visible_name; /* TODO (unnecessary?) */ +static Atom net_wm_icon_name; +static Atom net_wm_visible_icon_name; /* TODO (unnecessary?) */ static Atom net_wm_desktop; static Atom net_wm_window_type; static Atom net_wm_window_type_desktop; @@ -295,6 +295,9 @@ setSupportedHints(WScreen *scr) atom[i++] = net_wm_icon_geometry; atom[i++] = net_wm_icon; atom[i++] = net_wm_handled_icons; + + atom[i++] = net_wm_name; + atom[i++] = net_wm_icon_name; XChangeProperty(dpy, scr->root_win, net_supported, XA_ATOM, 32, PropModeReplace, (unsigned char*)atom, i); @@ -536,6 +539,16 @@ wNETWMInitStuff(WScreen *scr) void +wNETWMCleanup(WScreen *scr) +{ + int i; + + for (i= 0; i < atomNr; i++) + XDeleteProperty(dpy, scr->root_win, *atomNames[i].atom); +} + + +void wNETWMUpdateActions(WWindow *wwin, Bool del) { Atom action[10]; /* nr of actions atoms defined */ @@ -1018,6 +1031,7 @@ doStateAtom(WWindow *wwin, Atom state, int set, Bool init) } } } else if (state == net_wm_state_fullscreen) { + puts("GoT FS ST"); if (set == _NET_WM_STATE_TOGGLE) { set = !(wwin->flags.fullscreen); } @@ -1502,6 +1516,15 @@ wNETWMCheckClientHintChange(WWindow *wwin, XPropertyEvent *event) updateNetIconInfo(wwin); } else if (event->atom == net_wm_window_type) { updateWindowType(wwin); + } else if (event->atom == net_wm_name) { + char *name= wNETWMGetWindowName(wwin->client_win); + wWindowUpdateName(wwin, name); + if (name) wfree(name); + } else if (event->atom == net_wm_icon_name) { + if (wwin->icon) { + char *name= wNETWMGetIconName(wwin->client_win); + wIconChangeTitle(wwin->icon, name); + } } else { ret = False; } @@ -1535,6 +1558,46 @@ wNETWMGetPidForWindow(Window window) } +char* +wNETWMGetWindowName(Window window) +{ + char *name; + char *ret; + int size; + + name= (char*)PropGetCheckProperty(window, + net_wm_name, utf8_string, 0, + 0, &size); + if (name) { + ret= wstrndup(name, size); + XFree(name); + } + else + ret= NULL; + return ret; +} + + +char* +wNETWMGetIconName(Window window) +{ + char *name; + char *ret; + int size; + + name= (char*)PropGetCheckProperty(window, + net_wm_icon_name, utf8_string, 0, + 0, &size); + if (name) { + ret= wstrndup(name, size); + XFree(name); + } + else + ret= NULL; + return ret; +} + + static void observer(void *self, WMNotification *notif) { diff --git a/src/wmspec.h b/src/wmspec.h index adeb4560..978950ae 100644 --- a/src/wmspec.h +++ b/src/wmspec.h @@ -30,6 +30,7 @@ #include void wNETWMInitStuff(WScreen *scr); +void wNETWMCleanup(WScreen *scr); void wNETWMUpdateWorkarea(WScreen *scr, WArea usableArea); Bool wNETWMGetUsableArea(WScreen *scr, int head, WArea *area); Bool wNETWMCheckInitialClientState(WWindow *wwin); @@ -42,4 +43,6 @@ void wNETWMUpdateDesktop(WScreen *scr); void wNETWMPositionSplash(WWindow *wwin, int *x, int *y, int width, int height); int wNETWMGetPidForWindow(Window window); int wNETWMGetCurrentDesktopFromHint(WScreen *scr); +char *wNETWMGetIconName(Window window); +char *wNETWMGetWindowName(Window window); #endif diff --git a/util/Makefile.am b/util/Makefile.am index 1346f994..2c4f7859 100644 --- a/util/Makefile.am +++ b/util/Makefile.am @@ -28,12 +28,18 @@ wxpaste_LDADD = @XLFLAGS@ @XLIBS@ getstyle_LDADD = $(top_builddir)/WINGs/libWUtil.a $(liblist) +getstyle_SOURCES = getstyle.c fontconv.c + setstyle_LDADD = \ $(top_builddir)/WINGs/libWUtil.a \ @XLFLAGS@ @XLIBS@ $(liblist) +setstyle_SOURCES = setstyle.c fontconv.c + convertfonts_LDADD = $(top_builddir)/WINGs/libWUtil.a $(liblist) +convertfonts_SOURCES = convertfonts.c fontconv.c + seticons_LDADD= $(top_builddir)/WINGs/libWUtil.a $(liblist) geticonset_LDADD= $(top_builddir)/WINGs/libWUtil.a $(liblist) diff --git a/util/convertfonts.c b/util/convertfonts.c index 2ed83a8a..3b6e0fa6 100644 --- a/util/convertfonts.c +++ b/util/convertfonts.c @@ -31,7 +31,6 @@ #include "../src/wconfig.h" -#define DEFAULT_FONT "sans-serif:pixelsize=12" char *FontOptions[] = { "IconTitleFont", @@ -49,173 +48,7 @@ char *FontOptions[] = { char *ProgName; - -static int -countChar(char *str, char c) -{ - int count = 0; - - if (!str) - return 0; - - for (; *str!=0; str++) { - if (*str == c) { - count++; - } - } - - return count; -} - - -typedef struct str { - char *str; - int len; -} str; - -#define XLFD_TOKENS 14 - - -static str* -getXLFDTokens(char *xlfd) -{ - static str tokens[XLFD_TOKENS]; - int i, len, size; - char *ptr; - - if (!xlfd || *xlfd!='-' || countChar(xlfd, '-')0; i++) { - /* skip one '-' */ - ptr++; - len--; - if (len <= 0) - break; - size = strcspn(ptr, "-"); - tokens[i].str = ptr; - tokens[i].len = size; - ptr += size; - len -= size; - } - - return tokens; -} - - -static int -strToInt(str *token) -{ - int res=0, pos, c; - - if (token->len==0 || token->str[0]=='*') { - return -1; - } else { - for (res=0, pos=0; poslen; pos++) { - c = token->str[pos] - '0'; - if (c<0 || c>9) - break; - res = res*10 + c; - } - } - return res; -} - - -static char* -mapSlantToName(str *slant) -{ - if (slant->len==0 || slant->str[0]=='*') - return "roman"; - - switch(slant->str[0]) { - case 'i': - return "italic"; - case 'o': - return "oblique"; - case 'r': - default: - return "roman"; - } -} - - -char* -xlfdToFc(char *xlfd, char *useFamily, Bool keepXLFD) -{ - str *tokens, *family, *weight, *slant; - char *name, buf[512]; - int size, pixelsize; - - tokens = getXLFDTokens(xlfd); - if (!tokens) - return wstrdup(DEFAULT_FONT); - - family = &(tokens[1]); - weight = &(tokens[2]); - slant = &(tokens[3]); - - if (useFamily) { - name = wstrdup(useFamily); - } else { - if (family->len==0 || family->str[0]=='*') - return wstrdup(DEFAULT_FONT); - - sprintf(buf, "%.*s", family->len, family->str); - name = wstrdup(buf); - } - - pixelsize = strToInt(&tokens[6]); - size = strToInt(&tokens[7]); - - if (size<=0 && pixelsize<=0) { - name = wstrappend(name, ":pixelsize=12"); - } else if (pixelsize>0) { - /* if pixelsize is present size will be ignored so we skip it */ - sprintf(buf, ":pixelsize=%d", pixelsize); - name = wstrappend(name, buf); - } else { - sprintf(buf, "-%d", size/10); - name = wstrappend(name, buf); - } - - if (weight->len>0 && weight->str[0]!='*') { - sprintf(buf, ":weight=%.*s", weight->len, weight->str); - name = wstrappend(name, buf); - } - - if (slant->len>0 && slant->str[0]!='*') { - sprintf(buf, ":slant=%s", mapSlantToName(slant)); - name = wstrappend(name, buf); - } - - if (keepXLFD) { - name = wstrappend(name, ":xlfd="); - name = wstrappend(name, xlfd); - } - - return name; -} - - -/* return converted font (if conversion is needed) else the original font */ -static char* -convertFont(char *font, Bool keepXLFD) -{ - if (font[0]=='-') { - if (!strchr(font, ',')) { - return xlfdToFc(font, NULL, keepXLFD); - } else { - return xlfdToFc(font, "sans-serif", keepXLFD); - } - } else { - return font; - } -} +extern char* convertFont(char *font, Bool keepXLFD); void diff --git a/util/fontconv.c b/util/fontconv.c new file mode 100644 index 00000000..8111469a --- /dev/null +++ b/util/fontconv.c @@ -0,0 +1,183 @@ + +#include +#include +#include +#include + +#include "../src/wconfig.h" + +#define DEFAULT_FONT "sans-serif:pixelsize=12" + +static int +countChar(char *str, char c) +{ + int count = 0; + + if (!str) + return 0; + + for (; *str!=0; str++) { + if (*str == c) { + count++; + } + } + + return count; +} + + +typedef struct str { + char *str; + int len; +} str; + +#define XLFD_TOKENS 14 + + +static str* +getXLFDTokens(char *xlfd) +{ + static str tokens[XLFD_TOKENS]; + int i, len, size; + char *ptr; + + if (!xlfd || *xlfd!='-' || countChar(xlfd, '-')0; i++) { + /* skip one '-' */ + ptr++; + len--; + if (len <= 0) + break; + size = strcspn(ptr, "-"); + tokens[i].str = ptr; + tokens[i].len = size; + ptr += size; + len -= size; + } + + return tokens; +} + + +static int +strToInt(str *token) +{ + int res=0, pos, c; + + if (token->len==0 || token->str[0]=='*') { + return -1; + } else { + for (res=0, pos=0; poslen; pos++) { + c = token->str[pos] - '0'; + if (c<0 || c>9) + break; + res = res*10 + c; + } + } + return res; +} + + +static char* +mapSlantToName(str *slant) +{ + if (slant->len==0 || slant->str[0]=='*') + return "roman"; + + switch(slant->str[0]) { + case 'i': + return "italic"; + case 'o': + return "oblique"; + case 'r': + default: + return "roman"; + } +} + + +char* +xlfdToFc(char *xlfd, char *useFamily, Bool keepXLFD) +{ + str *tokens, *family, *weight, *slant; + char *name, buf[512]; + int size, pixelsize; + + tokens = getXLFDTokens(xlfd); + if (!tokens) + return wstrdup(DEFAULT_FONT); + + family = &(tokens[1]); + weight = &(tokens[2]); + slant = &(tokens[3]); + + if (useFamily) { + name = wstrdup(useFamily); + } else { + if (family->len==0 || family->str[0]=='*') + return wstrdup(DEFAULT_FONT); + + sprintf(buf, "%.*s", family->len, family->str); + name = wstrdup(buf); + } + + pixelsize = strToInt(&tokens[6]); + size = strToInt(&tokens[7]); + + if (size<=0 && pixelsize<=0) { + name = wstrappend(name, ":pixelsize=12"); + } else if (pixelsize>0) { + /* if pixelsize is present size will be ignored so we skip it */ + sprintf(buf, ":pixelsize=%d", pixelsize); + name = wstrappend(name, buf); + } else { + sprintf(buf, "-%d", size/10); + name = wstrappend(name, buf); + } + + if (weight->len>0 && weight->str[0]!='*') { + sprintf(buf, ":weight=%.*s", weight->len, weight->str); + name = wstrappend(name, buf); + } + + if (slant->len>0 && slant->str[0]!='*') { + sprintf(buf, ":slant=%s", mapSlantToName(slant)); + name = wstrappend(name, buf); + } + + if (keepXLFD) { + name = wstrappend(name, ":xlfd="); + name = wstrappend(name, xlfd); + } + + return name; +} + + +/* return converted font (if conversion is needed) else the original font */ +char* convertFont(char *font, Bool keepXLFD) +{ + if (font[0]=='-') { + char *res; + char *tmp= wstrdup(font); + + if (MB_CUR_MAX < 2) { + char *ptr= strchr(tmp, ','); + if (ptr) *ptr= 0; + res= xlfdToFc(tmp, NULL, keepXLFD); + } else { + res= xlfdToFc(tmp, "sans", keepXLFD); + } + wfree(tmp); + + return res; + } else { + return font; + } +} diff --git a/util/getstyle.c b/util/getstyle.c index 9cfdd908..32e70998 100644 --- a/util/getstyle.c +++ b/util/getstyle.c @@ -123,6 +123,8 @@ WMPropList *PixmapPath = NULL; char *ThemePath = NULL; +extern char* convertFont(char *font, Bool keepXLFD); + void print_help() @@ -403,171 +405,6 @@ isFontOption(char *option) } -static int -countChar(char *str, char c) -{ - int count = 0; - - if (!str) - return 0; - - for (; *str!=0; str++) { - if (*str == c) { - count++; - } - } - - return count; -} - - -typedef struct str { - char *str; - int len; -} str; - -#define XLFD_TOKENS 14 - -static str* -getXLFDTokens(char *xlfd) -{ - static str tokens[XLFD_TOKENS]; - int i, len, size; - char *ptr; - - if (!xlfd || countChar(xlfd, '-')0; i++) { - size = strspn(ptr, "-"); - ptr += size; - len -= size; - if (len <= 0) - break; - size = strcspn(ptr, "-"); - if (size==0) - break; - tokens[i].str = ptr; - tokens[i].len = size; - ptr += size; - len -= size; - } - - return tokens; -} - - -static int -strToInt(str *token) -{ - int res=0, pos, c; - - if (token->len==0 || token->str[0]=='*') { - return -1; - } else { - for (res=0, pos=0; poslen; pos++) { - c = token->str[pos] - '0'; - if (c<0 || c>9) - break; - res = res*10 + c; - } - } - return res; -} - - -static char* -mapSlantToName(str *slant) -{ - if (slant->len==0 || slant->str[0]=='*') - return "roman"; - - switch(slant->str[0]) { - case 'i': - return "italic"; - case 'o': - return "oblique"; - case 'r': - default: - return "roman"; - } -} - - -char* -xlfdToFc(char *xlfd) -{ - str *tokens, *family, *weight, *slant; - char *name, buf[512]; - int size, pixelsize; - - tokens = getXLFDTokens(xlfd); - if (!tokens) - return wstrdup(DEFAULT_FONT); - - family = &(tokens[1]); - weight = &(tokens[2]); - slant = &(tokens[3]); - - if (family->len==0 || family->str[0]=='*') - return wstrdup(DEFAULT_FONT); - - sprintf(buf, "%.*s", family->len, family->str); - name = wstrdup(buf); - - pixelsize = strToInt(&tokens[6]); - size = strToInt(&tokens[7]); - - if (size<=0 && pixelsize<=0) { - name = wstrappend(name, ":pixelsize=12"); - } else if (pixelsize>0) { - /* if pixelsize is present size will be ignored so we skip it */ - sprintf(buf, ":pixelsize=%d", pixelsize); - name = wstrappend(name, buf); - } else { - sprintf(buf, "-%d", size/10); - name = wstrappend(name, buf); - } - - if (weight->len>0 && weight->str[0]!='*') { - sprintf(buf, ":weight=%.*s", weight->len, weight->str); - name = wstrappend(name, buf); - } - - if (slant->len>0 && slant->str[0]!='*') { - sprintf(buf, ":slant=%s", mapSlantToName(slant)); - name = wstrappend(name, buf); - } - - name = wstrappend(name, ":xlfd="); - name = wstrappend(name, xlfd); - - return name; -} - - -/* return converted font (if conversion is needed) else the original font */ -static char* -convertFont(char *font) -{ - if (font[0]=='-') { - if (!strchr(font, ',')) { - return xlfdToFc(font); - } else { - wwarning("fontsets are not supported. replaced " - "with default %s", DEFAULT_FONT); - return wstrdup(DEFAULT_FONT); - } - } else { - return font; - } -} - - void copyFile(char *dir, char *file) { @@ -775,7 +612,7 @@ main(int argc, char **argv) char *newfont, *oldfont; oldfont = WMGetFromPLString(val); - newfont = convertFont(oldfont); + newfont = convertFont(oldfont, False); /* newfont is a reference to old if conversion is not needed */ if (newfont != oldfont) { WMReleasePropList(val); diff --git a/util/setstyle.c b/util/setstyle.c index 869f7d99..f4d6563f 100644 --- a/util/setstyle.c +++ b/util/setstyle.c @@ -76,7 +76,7 @@ int ignoreCursors = 0; Display *dpy; - +extern char* convertFont(char *font, Bool keepXLFD); WMPropList *readBlackBoxStyle(char *path); @@ -111,171 +111,6 @@ isFontOption(char *option) } -static int -countChar(char *str, char c) -{ - int count = 0; - - if (!str) - return 0; - - for (; *str!=0; str++) { - if (*str == c) { - count++; - } - } - - return count; -} - - -typedef struct str { - char *str; - int len; -} str; - -#define XLFD_TOKENS 14 - -static str* -getXLFDTokens(char *xlfd) -{ - static str tokens[XLFD_TOKENS]; - int i, len, size; - char *ptr; - - if (!xlfd || countChar(xlfd, '-')0; i++) { - size = strspn(ptr, "-"); - ptr += size; - len -= size; - if (len <= 0) - break; - size = strcspn(ptr, "-"); - if (size==0) - break; - tokens[i].str = ptr; - tokens[i].len = size; - ptr += size; - len -= size; - } - - return tokens; -} - - -static int -strToInt(str *token) -{ - int res=0, pos, c; - - if (token->len==0 || token->str[0]=='*') { - return -1; - } else { - for (res=0, pos=0; poslen; pos++) { - c = token->str[pos] - '0'; - if (c<0 || c>9) - break; - res = res*10 + c; - } - } - return res; -} - - -static char* -mapSlantToName(str *slant) -{ - if (slant->len==0 || slant->str[0]=='*') - return "roman"; - - switch(slant->str[0]) { - case 'i': - return "italic"; - case 'o': - return "oblique"; - case 'r': - default: - return "roman"; - } -} - - -char* -xlfdToFc(char *xlfd) -{ - str *tokens, *family, *weight, *slant; - char *name, buf[512]; - int size, pixelsize; - - tokens = getXLFDTokens(xlfd); - if (!tokens) - return wstrdup(DEFAULT_FONT); - - family = &(tokens[1]); - weight = &(tokens[2]); - slant = &(tokens[3]); - - if (family->len==0 || family->str[0]=='*') - return wstrdup(DEFAULT_FONT); - - sprintf(buf, "%.*s", family->len, family->str); - name = wstrdup(buf); - - pixelsize = strToInt(&tokens[6]); - size = strToInt(&tokens[7]); - - if (size<=0 && pixelsize<=0) { - name = wstrappend(name, ":pixelsize=12"); - } else if (pixelsize>0) { - /* if pixelsize is present size will be ignored so we skip it */ - sprintf(buf, ":pixelsize=%d", pixelsize); - name = wstrappend(name, buf); - } else { - sprintf(buf, "-%d", size/10); - name = wstrappend(name, buf); - } - - if (weight->len>0 && weight->str[0]!='*') { - sprintf(buf, ":weight=%.*s", weight->len, weight->str); - name = wstrappend(name, buf); - } - - if (slant->len>0 && slant->str[0]!='*') { - sprintf(buf, ":slant=%s", mapSlantToName(slant)); - name = wstrappend(name, buf); - } - - name = wstrappend(name, ":xlfd="); - name = wstrappend(name, xlfd); - - return name; -} - - -/* return converted font (if conversion is needed) else the original font */ -static char* -convertFont(char *font) -{ - if (font[0]=='-') { - if (!strchr(font, ',')) { - return xlfdToFc(font); - } else { - wwarning("fontsets are not supported. replaced " - "with default %s", DEFAULT_FONT); - return wstrdup(DEFAULT_FONT); - } - } else { - return font; - } -} - - char* defaultsPathForDomain(char *domain) { @@ -502,7 +337,7 @@ hackStyle(WMPropList *style) value = WMGetFromPLDictionary(style, tmp); if (value) { oldfont = WMGetFromPLString(value); - newfont = convertFont(oldfont); + newfont = convertFont(oldfont, False); if (newfont != oldfont) { value = WMCreatePLString(newfont); WMPutInPLDictionary(style, tmp, value); diff --git a/util/wmaker.inst.in b/util/wmaker.inst.in index ed07d782..53d253e4 100644 --- a/util/wmaker.inst.in +++ b/util/wmaker.inst.in @@ -272,9 +272,6 @@ test -f ~$GSDIR/Library/WindowMaker/exitscript || \ cp $GLOBALDIR/exitscript.sh $GSDIR/Library/WindowMaker/exitscript chmod +rx $GSDIR/Library/WindowMaker/exitscript -# no need to call wmchlocale --auto, since national menu is already copied -wsetfont --auto - # xx herbert if test -n "$BATCH" ; then echo "Installation Finished" -- 2.11.4.GIT