diff --git a/include/compiz.h b/include/compiz.h index d50996f..b7e0e32 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,12 @@ typedef void (*MatchExpHandlerChangedProc) (CompDisplay *display); typedef void (*MatchPropertyChangedProc) (CompDisplay *display, CompWindow *window); +typedef void (*LogMessageProc) (CompDisplay *d, + char *componentName, + CompLogLevel level, + char *format, + va_list args); + struct _CompDisplay { Display *display; CompScreen *screens; @@ -925,9 +940,12 @@ struct _CompDisplay { MatchExpHandlerChangedProc matchExpHandlerChanged; MatchPropertyChangedProc matchPropertyChanged; + LogMessageProc logMessage; + CompPrivate *privates; }; + extern CompDisplay *compDisplays; int @@ -979,6 +997,12 @@ 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 *format, va_list args); + 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..034196c 100644 --- a/src/main.c +++ b/src/main.c @@ -120,6 +120,37 @@ usage (void) programName); } +void +compLogMessage (CompDisplay *d, char *componentName, + CompLogLevel level, char *format, ...) +{ + va_list args; + + if (!d) + d = compDisplays; + + va_start(args, format); + + if (!d) + logMessage (d, componentName, level, format, args); + else + (*d->logMessage) (d, componentName, level, format, args); + + va_end(args); +} + +void +logMessage (CompDisplay *d, char *componentName, + CompLogLevel level, char *format, va_list args) +{ + char defaultMessage[1024]; + + snprintf (defaultMessage, 1024, "%s (%s): %s", + programName, componentName, format); + + vfprintf (stderr, defaultMessage, args); +} + static void signalHandler (int sig) { @@ -227,6 +258,8 @@ main (int argc, char **argv) programArgc = argc; programArgv = argv; + compDisplays = NULL; + signal (SIGHUP, signalHandler); signal (SIGCHLD, signalHandler); signal (SIGINT, signalHandler); @@ -329,7 +362,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 {