From 845645395cf6481fa88a5b4725dc4c303d8fecba Mon Sep 17 00:00:00 2001 From: Scott Tringali Date: Thu, 5 Sep 2002 17:48:43 +0000 Subject: [PATCH] Acquire default colors and fonts from the environment if using the default visual. --- doc/help.etx | 8 ++++ source/nedit.c | 129 +++++++++++++++++++++++++++++++++++++++------------------ util/misc.c | 12 ++++-- util/misc.h | 4 +- 4 files changed, 106 insertions(+), 47 deletions(-) diff --git a/doc/help.etx b/doc/help.etx index 9ef100c..dc375b7 100644 --- a/doc/help.etx +++ b/doc/help.etx @@ -3694,6 +3694,14 @@ X Resources xdpyinfo to see the list of visuals supported by your display), or a visual class name: PseudoColor, DirectColor, TrueColor, etc.. + If you are running under a themed environment (like KDE or CDE) that places + its colors in a shallow visual, and you'd rather have that color scheme + instead of more colors available, then you may need set the visual to + "Default" so that NEdit doesn't choose one with more colors. (The reason + for this is: if the "best" visual is not the server's default, then NEdit + cannot use the colors provided by your environment. NEdit will fall back to + its own default color scheme.) + **nedit.installColormap**: False Force the installation of a private colormap. If you have a humble 8-bit diff --git a/source/nedit.c b/source/nedit.c index 57c649c..97a98e2 100644 --- a/source/nedit.c +++ b/source/nedit.c @@ -1,4 +1,4 @@ -static const char CVSID[] = "$Id: nedit.c,v 1.34 2002/07/26 21:39:10 n8gray Exp $"; +static const char CVSID[] = "$Id: nedit.c,v 1.35 2002/09/05 17:48:43 tringali Exp $"; /******************************************************************************* * * * nedit.c -- Nirvana Editor main program * @@ -85,6 +85,7 @@ static void nextArg(int argc, char **argv, int *argIndex); static int checkDoMacroArg(const char *macro); static void maskArgvKeywords(int argc, char **argv, const char **maskArgs); static void unmaskArgvKeywords(int argc, char **argv, const char **maskArgs); +static void patchResourcesForVisual(void); WindowInfo *WindowList = NULL; Display *TheDisplay = NULL; @@ -102,51 +103,57 @@ Boolean IsServer = False; #define NEDIT_FIXED_FONT "-*-courier-medium-r-normal-*-*-120-*-*-*-iso8859-*" static char *fallbackResources[] = { + /* Try to avoid Motif's horrificly ugly default colors and fonts, + if the user's environment provides no usable defaults. We try + to choose a Windows-y default color setting here. Editable text + fields are forced to a fixed-pitch font for usability. */ + "*FontList: " NEDIT_DEFAULT_FONT, + "*XmText.FontList: " NEDIT_FIXED_FONT, + "*XmTextField.FontList: " NEDIT_FIXED_FONT, + "*XmList.FontList: " NEDIT_FIXED_FONT, + "*XmFileSelectionBox*XmList.FontList: " NEDIT_FIXED_FONT, + "*background: #b3b3b3", + "*foreground: black", + "*XmText*foreground: black", + "*XmText*background: #e5e5e5", + "*XmList*foreground: black", + "*XmList*background: #e5e5e5", + "*XmTextField*foreground: black", + "*XmTextField*background: #e5e5e5", + "*XmText.translations: #override\\n" + "Ctrl~Alt~Metav: paste-clipboard()\\n" + "Ctrl~Alt~Metac: copy-clipboard()\\n" + "Ctrl~Alt~Metax: cut-clipboard()\\n" + "Ctrl~Alt~Metau: delete-to-start-of-line()\\n", + "*XmTextField.translations: #override\\n" + "Ctrl~Alt~Metav: paste-clipboard()\\n" + "Ctrl~Alt~Metac: copy-clipboard()\\n" + "Ctrl~Alt~Metax: cut-clipboard()\\n" + "Ctrl~Alt~Metau: delete-to-start-of-line()\\n", + + /* NEdit-specific widgets. Theses things should probably be manually + jammed into the database, rather than fallbacks. We really want + the accelerators to be there even if someone creates an app-defaults + file against our wishes. */ + + "*text.lineNumForeground: #777777", + "*text.background: #e5e5e5", + "*text.foreground: black", + "*text.highlightBackground: red", + "*text.highlightForeground: black", "*menuBar.marginHeight: 0", "*menuBar.shadowThickness: 1", "*pane.sashHeight: 11", "*pane.sashWidth: 11", "*text.selectionArrayCount: 3", - "nedit*fontList: " NEDIT_DEFAULT_FONT, - "nedit*XmList.fontList: " NEDIT_FIXED_FONT, - /* This should not be necessary, but some default in LessTif is - overriding the resource above, and specifying the app-name fixes it */ - "nedit*XmText.fontList: " NEDIT_FIXED_FONT, - /* Same with this, both Solaris Motif and LessTif seem to have some - very specific defaults for file selection box fonts */ - "nedit*XmFileSelectionBox*XmList.fontList: " NEDIT_FIXED_FONT, - "nedit*XmTextField.fontList: " NEDIT_FIXED_FONT, - "nedit*background: #b3b3b3", - "nedit*foreground: black", - "nedit*text.lineNumForeground: #777777", - "nedit*text.background: #e5e5e5", - "nedit*text.foreground: black", - "nedit*text.highlightBackground: red", - "nedit*text.highlightForeground: black", - "nedit*XmText*foreground: black", - "nedit*XmText*background: #cccccc", - "nedit*helpText.background: #cccccc", - "nedit*helpText.foreground: black", - "nedit*helpText.selectBackground: #b3b3b3", - "nedit*statsLine.background: #b3b3b3", - "nedit*statsLine.fontList: " NEDIT_DEFAULT_FONT, - "nedit*helpText.font: " NEDIT_FIXED_FONT, - "*XmText.translations: #override \ -Ctrl~Alt~Metav: paste-clipboard()\\n\ -Ctrl~Alt~Metac: copy-clipboard()\\n\ -Ctrl~Alt~Metax: cut-clipboard()\\n\ -Ctrl~Alt~Metau: delete-to-start-of-line()\\n", - "*XmTextField.translations: #override \ -Ctrl~Alt~Metav: paste-clipboard()\\n\ -Ctrl~Alt~Metac: copy-clipboard()\\n\ -Ctrl~Alt~Metax: cut-clipboard()\\n\ -Ctrl~Alt~Metau: delete-to-start-of-line()\\n", - "nedit*XmList*foreground: black", - "nedit*XmList*background: #cccccc", - "nedit*XmTextField*background: #cccccc", - "nedit*XmTextField*foreground: black", - "nedit*calltip.background: LemonChiffon1", - "nedit*calltip.foreground: black", + "*helpText.background: #cccccc", + "*helpText.foreground: black", + "*helpText.selectBackground: #b3b3b3", + "*statsLine.background: #b3b3b3", + "*statsLine.FontList: " NEDIT_DEFAULT_FONT, + "*helpText.font: " NEDIT_FIXED_FONT, + "*calltip.background: LemonChiffon1", + "*calltip.foreground: black", "*iSearchForm*highlightThickness: 1", "*fileMenu.tearOffModel: XmTEAR_OFF_ENABLED", "*editMenu.tearOffModel: XmTEAR_OFF_ENABLED", @@ -366,6 +373,8 @@ int main(int argc, char **argv) XtWarning ("NEdit: Can't open display\n"); exit(EXIT_FAILURE); } + + patchResourcesForVisual(); /* Initialize global symbols and subroutines used in the macro language */ InitMacroGlobals(); @@ -616,3 +625,41 @@ static void unmaskArgvKeywords(int argc, char **argv, const char **maskArgs) if (argv[i][0]==' ' && !strcmp(&argv[i][1], &maskArgs[k][1])) argv[i][0] = '-'; } + +static void patchResourcesForVisual(void) +{ + int i; + Visual *visual; + int depth; + Colormap map; + Boolean usingDefaultVisual; + XrmDatabase db; + + if (!TheDisplay) + return; + + db = XtDatabase(TheDisplay); + + usingDefaultVisual = FindBestVisual(TheDisplay, + APP_NAME, + APP_CLASS, + &visual, + &depth, + &map); + + if (!usingDefaultVisual) + { + for (i = 0; i < XtNumber(fallbackResources)-1; i++) + { + if (strstr(fallbackResources[i], "*background:") || + strstr(fallbackResources[i], "*foreground:")) + { + /* Qualify by application name to prevent them from being + converted against the wrong colormap. */ + char buf[1024] = "*" APP_NAME; + strcat(buf, fallbackResources[i]); + XrmPutLineResource(&db, buf); + } + } + } +} diff --git a/util/misc.c b/util/misc.c index 8f364ab..1b516ad 100644 --- a/util/misc.c +++ b/util/misc.c @@ -1,4 +1,4 @@ -static const char CVSID[] = "$Id: misc.c,v 1.42 2002/08/12 21:21:36 tringali Exp $"; +static const char CVSID[] = "$Id: misc.c,v 1.43 2002/09/05 17:48:43 tringali Exp $"; /******************************************************************************* * * * misc.c -- Miscelaneous Motif convenience functions * @@ -290,8 +290,10 @@ void RealizeWithoutForcingPosition(Widget shell) ** visual is that some color resources are still converted with the default ** visual (particularly *background), and these must be avoided by widgets ** which are allowed to handle any visual. +** +** Returns True if the best visual is the default, False otherwise. */ -void FindBestVisual(Display *display, const char *appName, const char *appClass, +Boolean FindBestVisual(Display *display, const char *appName, const char *appClass, Visual **visual, int *depth, Colormap *colormap) { char rsrcName[256], rsrcClass[256], *valueString, *type, *endPtr; @@ -314,7 +316,7 @@ void FindBestVisual(Display *display, const char *appName, const char *appClass, *visual = cachedVisual; *depth = cachedDepth; *colormap = cachedColormap; - return; + return (*visual == DefaultVisual(display, screen)); } /* Read the visualID and installColormap resources for the application. @@ -397,7 +399,7 @@ void FindBestVisual(Display *display, const char *appName, const char *appClass, *visual = DefaultVisual(display, screen); *depth = DefaultDepth(display, screen); *colormap = DefaultColormap(display, screen); - return; + return True; } } @@ -444,6 +446,8 @@ void FindBestVisual(Display *display, const char *appName, const char *appClass, if (visList != NULL) { XFree(visList); } + + return (*visual == DefaultVisual(display, screen)); } /* diff --git a/util/misc.h b/util/misc.h index 92624d4..64afb73 100644 --- a/util/misc.h +++ b/util/misc.h @@ -1,4 +1,4 @@ -/* $Id: misc.h,v 1.14 2002/08/12 21:21:36 tringali Exp $ */ +/* $Id: misc.h,v 1.15 2002/09/05 17:48:43 tringali Exp $ */ #ifndef NEDIT_MISC_H_INCLUDED #define NEDIT_MISC_H_INCLUDED @@ -62,7 +62,7 @@ void AddHistoryToTextWidget(Widget textW, char ***historyList, int *nItems); void AddToHistoryList(char *newItem, char ***historyList, int *nItems); void CreateGeometryString(char *string, int x, int y, int width, int height, int bitmask); -void FindBestVisual(Display *display, const char *appName, const char *appClass, +Boolean FindBestVisual(Display *display, const char *appName, const char *appClass, Visual **visual, int *depth, Colormap *colormap); Widget CreateDialogShell(Widget parent, char *name, ArgList arglist, Cardinal argcount); -- 2.11.4.GIT