1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-20 04:48:06 +01:00

- 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
This commit is contained in:
kojima
2004-10-16 22:05:04 +00:00
parent 9402724e40
commit 7055530895
17 changed files with 305 additions and 549 deletions

View File

@@ -159,6 +159,8 @@ Changes since version 0.80.2:
- Removed old code to store/restore workspace state (now relies on netwm) - Removed old code to store/restore workspace state (now relies on netwm)
- Added a (simple) Font Configuration for fontconfig fonts - Added a (simple) Font Configuration for fontconfig fonts
- MacOS X style window switching panel (navigate through windows with Alt-Tab or arrow keys) - 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: Changes since version 0.80.1:
............................. .............................

7
TODO
View File

@@ -5,18 +5,11 @@ To do before next release:
and give a warning if font is not converted, but let user manually convert 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 it with convertfonts as the process may need manual tweaking for best
results) 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 - Append .UTF-8 to locale
- figure out a better gnustep path for wprefs.app installation - figure out a better gnustep path for wprefs.app installation
- pick a good font fallback
- figure a better fullscreen level - figure a better fullscreen level
- clean up netwm hints on exit
- check whether window states are being saved/restored properly via netwm - check whether window states are being saved/restored properly via netwm
on restart/crash-restart (grep for XXX/TODO) on restart/crash-restart (grep for XXX/TODO)
- review wmaker.inst
remake wrlib rule to not compile with -fomit-frame-pointer and stuff remake wrlib rule to not compile with -fomit-frame-pointer and stuff
if its added to CFLAGS if its added to CFLAGS

View File

@@ -234,17 +234,6 @@ lookup_available_fonts(_Panel *panel)
FcObjectSetDestroy(os); FcObjectSetDestroy(os);
if (pat) if (pat)
FcPatternDestroy(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"); panel->fonts->families[panel->fonts->familyn++].name= wstrdup("sans");
family= panel->fonts->families + panel->fonts->familyn-1; family= panel->fonts->families + panel->fonts->familyn-1;

View File

@@ -325,25 +325,31 @@ wClientCheckProperty(WWindow *wwin, XPropertyEvent *event)
switch (event->atom) { switch (event->atom) {
case XA_WM_NAME: case XA_WM_NAME:
/* window title was changed */ if (!wwin->flags.net_has_title)
if (!wFetchName(dpy, wwin->client_win, &tmp)) { {
wWindowUpdateName(wwin, NULL); /* window title was changed */
} else { if (!wFetchName(dpy, wwin->client_win, &tmp)) {
wWindowUpdateName(wwin, tmp); wWindowUpdateName(wwin, NULL);
} else {
wWindowUpdateName(wwin, tmp);
}
if (tmp)
XFree(tmp);
} }
if (tmp)
XFree(tmp);
break; break;
case XA_WM_ICON_NAME: case XA_WM_ICON_NAME:
if (!wwin->icon) if (!wwin->flags.net_has_icon_title)
break; {
else { if (!wwin->icon)
char *new_title; break;
else {
/* icon title was changed */ char *new_title;
wGetIconName(dpy, wwin->client_win, &new_title);
wIconChangeTitle(wwin->icon, new_title); /* icon title was changed */
wGetIconName(dpy, wwin->client_win, &new_title);
wIconChangeTitle(wwin->icon, new_title);
}
} }
break; break;

View File

@@ -43,8 +43,9 @@
#include "application.h" #include "application.h"
#include "defaults.h" #include "defaults.h"
#include "appicon.h" #include "appicon.h"
#include "wmspec.h"
/**** Global variables ****/ /**** Global varianebles ****/
extern WPreferences wPreferences; extern WPreferences wPreferences;
#define MOD_MASK wPreferences.modifier_mask #define MOD_MASK wPreferences.modifier_mask
@@ -179,7 +180,11 @@ wIconCreate(WWindow *wwin)
icon->file = wstrdup(file); 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; icon->tile_type = TILE_NORMAL;

View File

@@ -1084,8 +1084,6 @@ wScreenSaveState(WScreen *scr)
WWindow *wwin; WWindow *wwin;
char *str; char *str;
WMPropList *old_state, *foo; WMPropList *old_state, *foo;
CARD32 data[2];
make_keys(); make_keys();

View File

@@ -36,6 +36,7 @@
#include "properties.h" #include "properties.h"
#include "session.h" #include "session.h"
#include "winspector.h" #include "winspector.h"
#include "wmspec.h"
extern Atom _XA_WM_DELETE_WINDOW; extern Atom _XA_WM_DELETE_WINDOW;
extern Time LastTimestamp; extern Time LastTimestamp;
@@ -197,6 +198,7 @@ RestoreDesktop(WScreen *scr)
XSetInputFocus(dpy, PointerRoot, RevertToParent, CurrentTime); XSetInputFocus(dpy, PointerRoot, RevertToParent, CurrentTime);
wColormapInstallForWindow(scr, NULL); wColormapInstallForWindow(scr, NULL);
PropCleanUp(scr->root_win); PropCleanUp(scr->root_win);
wNETWMCleanup(scr);
XSync(dpy, 0); XSync(dpy, 0);
} }

View File

@@ -722,12 +722,14 @@ wManageWindow(WScreen *scr, Window window)
return NULL; return NULL;
} }
if (!wFetchName(dpy, window, &title)) {
title = NULL;
}
wwin = wWindowCreate(); 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); XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
#ifdef DEBUG #ifdef DEBUG

View File

@@ -304,6 +304,8 @@ typedef struct WWindow {
unsigned int net_skip_pager:1; unsigned int net_skip_pager:1;
unsigned int net_handle_icon:1; unsigned int net_handle_icon:1;
unsigned int net_show_desktop: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 #endif
} flags; /* state of the window */ } flags; /* state of the window */

View File

@@ -74,10 +74,10 @@ static Atom net_moveresize_window; /* TODO */
static Atom net_wm_moveresize; /* TODO */ static Atom net_wm_moveresize; /* TODO */
/* Application Window Properties */ /* Application Window Properties */
static Atom net_wm_name; /* TODO */ static Atom net_wm_name;
static Atom net_wm_visible_name; /* TODO */ static Atom net_wm_visible_name; /* TODO (unnecessary?) */
static Atom net_wm_icon_name; /* TODO */ static Atom net_wm_icon_name;
static Atom net_wm_visible_icon_name; /* TODO */ static Atom net_wm_visible_icon_name; /* TODO (unnecessary?) */
static Atom net_wm_desktop; static Atom net_wm_desktop;
static Atom net_wm_window_type; static Atom net_wm_window_type;
static Atom net_wm_window_type_desktop; 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_geometry;
atom[i++] = net_wm_icon; atom[i++] = net_wm_icon;
atom[i++] = net_wm_handled_icons; 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, XChangeProperty(dpy, scr->root_win, net_supported, XA_ATOM, 32,
PropModeReplace, (unsigned char*)atom, i); PropModeReplace, (unsigned char*)atom, i);
@@ -535,6 +538,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 void
wNETWMUpdateActions(WWindow *wwin, Bool del) wNETWMUpdateActions(WWindow *wwin, Bool del)
{ {
@@ -1018,6 +1031,7 @@ doStateAtom(WWindow *wwin, Atom state, int set, Bool init)
} }
} }
} else if (state == net_wm_state_fullscreen) { } else if (state == net_wm_state_fullscreen) {
puts("GoT FS ST");
if (set == _NET_WM_STATE_TOGGLE) { if (set == _NET_WM_STATE_TOGGLE) {
set = !(wwin->flags.fullscreen); set = !(wwin->flags.fullscreen);
} }
@@ -1502,6 +1516,15 @@ wNETWMCheckClientHintChange(WWindow *wwin, XPropertyEvent *event)
updateNetIconInfo(wwin); updateNetIconInfo(wwin);
} else if (event->atom == net_wm_window_type) { } else if (event->atom == net_wm_window_type) {
updateWindowType(wwin); 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 { } else {
ret = False; 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 static void
observer(void *self, WMNotification *notif) observer(void *self, WMNotification *notif)
{ {

View File

@@ -30,6 +30,7 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
void wNETWMInitStuff(WScreen *scr); void wNETWMInitStuff(WScreen *scr);
void wNETWMCleanup(WScreen *scr);
void wNETWMUpdateWorkarea(WScreen *scr, WArea usableArea); void wNETWMUpdateWorkarea(WScreen *scr, WArea usableArea);
Bool wNETWMGetUsableArea(WScreen *scr, int head, WArea *area); Bool wNETWMGetUsableArea(WScreen *scr, int head, WArea *area);
Bool wNETWMCheckInitialClientState(WWindow *wwin); Bool wNETWMCheckInitialClientState(WWindow *wwin);
@@ -42,4 +43,6 @@ void wNETWMUpdateDesktop(WScreen *scr);
void wNETWMPositionSplash(WWindow *wwin, int *x, int *y, int width, int height); void wNETWMPositionSplash(WWindow *wwin, int *x, int *y, int width, int height);
int wNETWMGetPidForWindow(Window window); int wNETWMGetPidForWindow(Window window);
int wNETWMGetCurrentDesktopFromHint(WScreen *scr); int wNETWMGetCurrentDesktopFromHint(WScreen *scr);
char *wNETWMGetIconName(Window window);
char *wNETWMGetWindowName(Window window);
#endif #endif

View File

@@ -28,12 +28,18 @@ wxpaste_LDADD = @XLFLAGS@ @XLIBS@
getstyle_LDADD = $(top_builddir)/WINGs/libWUtil.a $(liblist) getstyle_LDADD = $(top_builddir)/WINGs/libWUtil.a $(liblist)
getstyle_SOURCES = getstyle.c fontconv.c
setstyle_LDADD = \ setstyle_LDADD = \
$(top_builddir)/WINGs/libWUtil.a \ $(top_builddir)/WINGs/libWUtil.a \
@XLFLAGS@ @XLIBS@ $(liblist) @XLFLAGS@ @XLIBS@ $(liblist)
setstyle_SOURCES = setstyle.c fontconv.c
convertfonts_LDADD = $(top_builddir)/WINGs/libWUtil.a $(liblist) convertfonts_LDADD = $(top_builddir)/WINGs/libWUtil.a $(liblist)
convertfonts_SOURCES = convertfonts.c fontconv.c
seticons_LDADD= $(top_builddir)/WINGs/libWUtil.a $(liblist) seticons_LDADD= $(top_builddir)/WINGs/libWUtil.a $(liblist)
geticonset_LDADD= $(top_builddir)/WINGs/libWUtil.a $(liblist) geticonset_LDADD= $(top_builddir)/WINGs/libWUtil.a $(liblist)

View File

@@ -31,7 +31,6 @@
#include "../src/wconfig.h" #include "../src/wconfig.h"
#define DEFAULT_FONT "sans-serif:pixelsize=12"
char *FontOptions[] = { char *FontOptions[] = {
"IconTitleFont", "IconTitleFont",
@@ -49,173 +48,7 @@ char *FontOptions[] = {
char *ProgName; char *ProgName;
extern char* convertFont(char *font, Bool keepXLFD);
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, '-')<XLFD_TOKENS)
return NULL;
memset(tokens, 0, sizeof(str)*XLFD_TOKENS);
len = strlen(xlfd);
for (ptr=xlfd, i=0; i<XLFD_TOKENS && len>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; pos<token->len; 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;
}
}
void void

183
util/fontconv.c Normal file
View File

@@ -0,0 +1,183 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <WINGs/WUtil.h>
#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, '-')<XLFD_TOKENS)
return NULL;
memset(tokens, 0, sizeof(str)*XLFD_TOKENS);
len = strlen(xlfd);
for (ptr=xlfd, i=0; i<XLFD_TOKENS && len>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; pos<token->len; 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;
}
}

View File

@@ -123,6 +123,8 @@ WMPropList *PixmapPath = NULL;
char *ThemePath = NULL; char *ThemePath = NULL;
extern char* convertFont(char *font, Bool keepXLFD);
void void
print_help() 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, '-')<XLFD_TOKENS)
return NULL;
memset(tokens, 0, sizeof(str)*XLFD_TOKENS);
len = strlen(xlfd);
for (ptr=xlfd, i=0; i<XLFD_TOKENS && len>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; pos<token->len; 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 void
copyFile(char *dir, char *file) copyFile(char *dir, char *file)
{ {
@@ -775,7 +612,7 @@ main(int argc, char **argv)
char *newfont, *oldfont; char *newfont, *oldfont;
oldfont = WMGetFromPLString(val); oldfont = WMGetFromPLString(val);
newfont = convertFont(oldfont); newfont = convertFont(oldfont, False);
/* newfont is a reference to old if conversion is not needed */ /* newfont is a reference to old if conversion is not needed */
if (newfont != oldfont) { if (newfont != oldfont) {
WMReleasePropList(val); WMReleasePropList(val);

View File

@@ -76,7 +76,7 @@ int ignoreCursors = 0;
Display *dpy; Display *dpy;
extern char* convertFont(char *font, Bool keepXLFD);
WMPropList *readBlackBoxStyle(char *path); 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, '-')<XLFD_TOKENS)
return NULL;
memset(tokens, 0, sizeof(str)*XLFD_TOKENS);
len = strlen(xlfd);
for (ptr=xlfd, i=0; i<XLFD_TOKENS && len>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; pos<token->len; 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* char*
defaultsPathForDomain(char *domain) defaultsPathForDomain(char *domain)
{ {
@@ -502,7 +337,7 @@ hackStyle(WMPropList *style)
value = WMGetFromPLDictionary(style, tmp); value = WMGetFromPLDictionary(style, tmp);
if (value) { if (value) {
oldfont = WMGetFromPLString(value); oldfont = WMGetFromPLString(value);
newfont = convertFont(oldfont); newfont = convertFont(oldfont, False);
if (newfont != oldfont) { if (newfont != oldfont) {
value = WMCreatePLString(newfont); value = WMCreatePLString(newfont);
WMPutInPLDictionary(style, tmp, value); WMPutInPLDictionary(style, tmp, value);

View File

@@ -272,9 +272,6 @@ test -f ~$GSDIR/Library/WindowMaker/exitscript || \
cp $GLOBALDIR/exitscript.sh $GSDIR/Library/WindowMaker/exitscript cp $GLOBALDIR/exitscript.sh $GSDIR/Library/WindowMaker/exitscript
chmod +rx $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 # xx herbert
if test -n "$BATCH" ; then if test -n "$BATCH" ; then
echo "Installation Finished" echo "Installation Finished"