diff --git a/include/compiz.h b/include/compiz.h index d50996f..0622c9b 100644 --- a/include/compiz.h +++ b/include/compiz.h @@ -26,7 +26,7 @@ #ifndef _COMPIZ_H #define _COMPIZ_H -#define ABIVERSION 20070507 +#define ABIVERSION 20070524 #include #include @@ -309,6 +309,15 @@ typedef enum { CompActionStateAutoGrab = 1 << 11 } CompActionState; +typedef enum { + CompLogLevelFatal = 0, + CompLogLevelError, + CompLogLevelWarn, + CompLogLevelInfo, + CompLogLevelDebug + +} CompLogLevel; + typedef struct _CompKeyBinding { int keycode; unsigned int modifiers; @@ -728,6 +737,11 @@ typedef void (*MatchExpHandlerChangedProc) (CompDisplay *display); typedef void (*MatchPropertyChangedProc) (CompDisplay *display, CompWindow *window); +typedef void (*LogMessageProc) (CompDisplay *d, + char *componentName, + CompLogLevel level, + char *message); + struct _CompDisplay { Display *display; CompScreen *screens; @@ -925,9 +939,12 @@ struct _CompDisplay { MatchExpHandlerChangedProc matchExpHandlerChanged; MatchPropertyChangedProc matchPropertyChanged; + LogMessageProc logMessage; + CompPrivate *privates; }; + extern CompDisplay *compDisplays; int @@ -979,6 +996,15 @@ void fileWatchRemoved (CompDisplay *display, CompFileWatch *fileWatch); +void +compLogMessage (CompDisplay *d, char *componentName, CompLogLevel level, char *format, ...); + +void +logMessage (CompDisplay *d, char *componentName, CompLogLevel level, char *message); + +char * +logLevelToString (CompLogLevel level); + int compCheckForError (Display *dpy); diff --git a/src/display.c b/src/display.c index 45ba4f0..616d8a3 100644 --- a/src/display.c +++ b/src/display.c @@ -2003,6 +2003,8 @@ addDisplay (char *name) d->matchExpHandlerChanged = matchExpHandlerChanged; d->matchPropertyChanged = matchPropertyChanged; + d->logMessage = logMessage; + d->supportedAtom = XInternAtom (dpy, "_NET_SUPPORTED", 0); d->supportingWmCheckAtom = XInternAtom (dpy, "_NET_SUPPORTING_WM_CHECK", 0); diff --git a/src/main.c b/src/main.c index 477e3d0..3b9c397 100644 --- a/src/main.c +++ b/src/main.c @@ -120,6 +120,76 @@ usage (void) programName); } +void +compLogMessage (CompDisplay *d, + char *componentName, + CompLogLevel level, + char *format, + ...) +{ + va_list args; + char message[2048]; + + if (!d) + d = compDisplays; + + va_start (args, format); + + vsnprintf (message, 2048, format, args); + + if (!d) + logMessage (d, componentName, level, message); + else + (*d->logMessage) (d, componentName, level, message); + + va_end (args); +} + +void +logMessage (CompDisplay *d, + char *componentName, + CompLogLevel level, + char *message) +{ + char defaultMessage[2048]; + + snprintf (defaultMessage, 2048, "%s (%s): %s", + programName, componentName, message); + + fprintf (stderr, defaultMessage); + fprintf (stderr, "\n"); +} + +char * +logLevelToString (CompLogLevel level) +{ + char *logStr; + + switch (level) + { + case CompLogLevelFatal: + logStr = strdup ("Fatal"); + break; + case CompLogLevelError: + logStr = strdup ("Error"); + break; + case CompLogLevelWarn: + logStr = strdup ("Warn"); + break; + case CompLogLevelInfo: + logStr = strdup ("Info"); + break; + case CompLogLevelDebug: + logStr = strdup ("Debug"); + break; + default: + logStr = strdup ("Unknown"); + break; + } + + return logStr; +} + static void signalHandler (int sig) { @@ -227,6 +297,8 @@ main (int argc, char **argv) programArgc = argc; programArgv = argv; + compDisplays = NULL; + signal (SIGHUP, signalHandler); signal (SIGCHLD, signalHandler); signal (SIGINT, signalHandler); @@ -329,7 +401,8 @@ main (int argc, char **argv) } else if (*argv[i] == '-') { - fprintf (stderr, "%s: Unknown option '%s'\n", programName, argv[i]); + compLogMessage (NULL, "core", CompLogLevelWarn, + "Unknown option '%s'\n", argv[i]); } else { diff --git a/src/plugin.c b/src/plugin.c index e4e49be..2f26e2e 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -499,7 +499,7 @@ loadPlugin (char *name) if (status) return p; - fprintf (stderr, "%s: Couldn't load plugin '%s'\n", programName, name); + compLogMessage (NULL, "core", CompLogLevelError, "Couldn't load plugin '%s'", name); return 0; }