/*
 * This file is autogenerated with bcop:
 * The Compiz option code generator
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <compiz.h>

#define _ADDHELPER_OPTIONS_INTERNAL
#include "addhelper_options.h"

static int displayPrivateIndex;

static CompMetadata addhelperOptionsMetadata;

static CompPluginVTable *addhelperPluginVTable = NULL;
CompPluginVTable addhelperOptionsVTable;

#define GET_ADDHELPER_OPTIONS_DISPLAY(d) \
        ((AddhelperOptionsDisplay *) (d)->privates[displayPrivateIndex].ptr)

#define ADDHELPER_OPTIONS_DISPLAY(d) \
        AddhelperOptionsDisplay *od = GET_ADDHELPER_OPTIONS_DISPLAY (d)

#define GET_ADDHELPER_OPTIONS_SCREEN(s, od) \
        ((AddhelperOptionsScreen *) (s)->privates[(od)->screenPrivateIndex].ptr)

#define ADDHELPER_OPTIONS_SCREEN(s) \
        AddhelperOptionsScreen *os = GET_ADDHELPER_OPTIONS_SCREEN (s, GET_ADDHELPER_OPTIONS_DISPLAY (s->display))

typedef struct _AddhelperOptionsDisplay
{
    int screenPrivateIndex;

    CompOption opt[AddhelperDisplayOptionNum];
    addhelperDisplayOptionChangeNotifyProc notify[AddhelperDisplayOptionNum];
} AddhelperOptionsDisplay;

typedef struct _AddhelperOptionsScreen
{
} AddhelperOptionsScreen;

CompAction * addhelperGetToggle (CompDisplay *d)
{
    ADDHELPER_OPTIONS_DISPLAY(d);
    return &od->opt[AddhelperDisplayOptionToggle].value.action;
}

void addhelperSetToggleInitiate (CompDisplay *d, CompActionCallBackProc init)
{
    ADDHELPER_OPTIONS_DISPLAY(d);
    od->opt[AddhelperDisplayOptionToggle].value.action.initiate = init;
}

void addhelperSetToggleTerminate (CompDisplay *d, CompActionCallBackProc term)
{
    ADDHELPER_OPTIONS_DISPLAY(d);
    od->opt[AddhelperDisplayOptionToggle].value.action.terminate = term;
}

CompOption * addhelperGetToggleOption (CompDisplay *d)
{
    ADDHELPER_OPTIONS_DISPLAY(d);
    return &od->opt[AddhelperDisplayOptionToggle];
}

void addhelperSetToggleNotify (CompDisplay *d, addhelperDisplayOptionChangeNotifyProc notify)
{
    ADDHELPER_OPTIONS_DISPLAY(d);
    od->notify[AddhelperDisplayOptionToggle] = notify;
}

CompMatch * addhelperGetWindowTypes (CompDisplay *d)
{
    ADDHELPER_OPTIONS_DISPLAY(d);
    return &od->opt[AddhelperDisplayOptionWindowTypes].value.match;
}

CompOption * addhelperGetWindowTypesOption (CompDisplay *d)
{
    ADDHELPER_OPTIONS_DISPLAY(d);
    return &od->opt[AddhelperDisplayOptionWindowTypes];
}

void addhelperSetWindowTypesNotify (CompDisplay *d, addhelperDisplayOptionChangeNotifyProc notify)
{
    ADDHELPER_OPTIONS_DISPLAY(d);
    od->notify[AddhelperDisplayOptionWindowTypes] = notify;
}

int addhelperGetBrightness (CompDisplay *d)
{
    ADDHELPER_OPTIONS_DISPLAY(d);
    return od->opt[AddhelperDisplayOptionBrightness].value.i;
}

CompOption * addhelperGetBrightnessOption (CompDisplay *d)
{
    ADDHELPER_OPTIONS_DISPLAY(d);
    return &od->opt[AddhelperDisplayOptionBrightness];
}

void addhelperSetBrightnessNotify (CompDisplay *d, addhelperDisplayOptionChangeNotifyProc notify)
{
    ADDHELPER_OPTIONS_DISPLAY(d);
    od->notify[AddhelperDisplayOptionBrightness] = notify;
}

int addhelperGetSaturation (CompDisplay *d)
{
    ADDHELPER_OPTIONS_DISPLAY(d);
    return od->opt[AddhelperDisplayOptionSaturation].value.i;
}

CompOption * addhelperGetSaturationOption (CompDisplay *d)
{
    ADDHELPER_OPTIONS_DISPLAY(d);
    return &od->opt[AddhelperDisplayOptionSaturation];
}

void addhelperSetSaturationNotify (CompDisplay *d, addhelperDisplayOptionChangeNotifyProc notify)
{
    ADDHELPER_OPTIONS_DISPLAY(d);
    od->notify[AddhelperDisplayOptionSaturation] = notify;
}

int addhelperGetOpacity (CompDisplay *d)
{
    ADDHELPER_OPTIONS_DISPLAY(d);
    return od->opt[AddhelperDisplayOptionOpacity].value.i;
}

CompOption * addhelperGetOpacityOption (CompDisplay *d)
{
    ADDHELPER_OPTIONS_DISPLAY(d);
    return &od->opt[AddhelperDisplayOptionOpacity];
}

void addhelperSetOpacityNotify (CompDisplay *d, addhelperDisplayOptionChangeNotifyProc notify)
{
    ADDHELPER_OPTIONS_DISPLAY(d);
    od->notify[AddhelperDisplayOptionOpacity] = notify;
}

CompOption * addhelperGetDisplayOption (CompDisplay *d, AddhelperDisplayOptions num)
{
    ADDHELPER_OPTIONS_DISPLAY(d);
    return &od->opt[num];
}

static const CompMetadataOptionInfo addhelperOptionsDisplayOptionInfo[] = {
    { "toggle", "action", 0, 0, 0 },
    { "window_types", "match", 0, 0, 0 },
    { "brightness", "int", "<min>1</min><max>100</max>", 0, 0 },
    { "saturation", "int", "<min>0</min><max>100</max>", 0, 0 },
    { "opacity", "int", "<min>1</min><max>100</max>", 0, 0 },
};

static Bool addhelperOptionsSetDisplayOption (CompPlugin *plugin, CompDisplay *d, char *name, CompOptionValue *value)
{
    ADDHELPER_OPTIONS_DISPLAY(d);
    CompOption *o;
    int        index;

    o = compFindOption (od->opt, AddhelperDisplayOptionNum, name, &index);

    if (!o)
        return FALSE;

    switch (index)
    {
     case AddhelperDisplayOptionToggle:
        if (compSetDisplayOption (d, o, value))
        {
            if (od->notify[AddhelperDisplayOptionToggle])
                (*od->notify[AddhelperDisplayOptionToggle]) (d, o, AddhelperDisplayOptionToggle);
            return TRUE;
        }
        break;
     case AddhelperDisplayOptionWindowTypes:
        if (compSetDisplayOption (d, o, value))
        {
            if (od->notify[AddhelperDisplayOptionWindowTypes])
                (*od->notify[AddhelperDisplayOptionWindowTypes]) (d, o, AddhelperDisplayOptionWindowTypes);
            return TRUE;
        }
        break;
     case AddhelperDisplayOptionBrightness:
        if (compSetDisplayOption (d, o, value))
        {
            if (od->notify[AddhelperDisplayOptionBrightness])
                (*od->notify[AddhelperDisplayOptionBrightness]) (d, o, AddhelperDisplayOptionBrightness);
            return TRUE;
        }
        break;
     case AddhelperDisplayOptionSaturation:
        if (compSetDisplayOption (d, o, value))
        {
            if (od->notify[AddhelperDisplayOptionSaturation])
                (*od->notify[AddhelperDisplayOptionSaturation]) (d, o, AddhelperDisplayOptionSaturation);
            return TRUE;
        }
        break;
     case AddhelperDisplayOptionOpacity:
        if (compSetDisplayOption (d, o, value))
        {
            if (od->notify[AddhelperDisplayOptionOpacity])
                (*od->notify[AddhelperDisplayOptionOpacity]) (d, o, AddhelperDisplayOptionOpacity);
            return TRUE;
        }
        break;
    default:
        break;
    }
    return FALSE;
}

static CompOption * addhelperOptionsGetDisplayOptions (CompPlugin *plugin, CompDisplay *d, int *count)
{
    ADDHELPER_OPTIONS_DISPLAY(d);
    *count = AddhelperDisplayOptionNum;
    return od->opt;
}

static Bool addhelperOptionsInitScreen (CompPlugin *p, CompScreen *s)
{
    AddhelperOptionsScreen *os;
    
    ADDHELPER_OPTIONS_DISPLAY (s->display);

    os = calloc (1, sizeof(AddhelperOptionsScreen));
    if (!os)
        return FALSE;

    s->privates[od->screenPrivateIndex].ptr = os;

        if (addhelperPluginVTable && addhelperPluginVTable->initScreen)
        return addhelperPluginVTable->initScreen (p, s);
    return TRUE;
}

static void addhelperOptionsFiniScreen (CompPlugin *p, CompScreen *s)
{
    if (addhelperPluginVTable && addhelperPluginVTable->finiScreen)
        return addhelperPluginVTable->finiScreen (p, s);

    ADDHELPER_OPTIONS_SCREEN (s);

    free (os);
}

static Bool addhelperOptionsInitDisplay (CompPlugin *p, CompDisplay *d)
{
    AddhelperOptionsDisplay *od;
   
    
    od = calloc (1, sizeof(AddhelperOptionsDisplay));
    if (!od)
        return FALSE;

    od->screenPrivateIndex = allocateScreenPrivateIndex(d);
    if (od->screenPrivateIndex < 0)
    {
        free(od);
        return FALSE;
    }

    d->privates[displayPrivateIndex].ptr = od;

    if (!compInitDisplayOptionsFromMetadata (d, &addhelperOptionsMetadata, addhelperOptionsDisplayOptionInfo, od->opt, AddhelperDisplayOptionNum))
    {
        free (od);
        return FALSE;
    }
    if (addhelperPluginVTable && addhelperPluginVTable->initDisplay)
        return addhelperPluginVTable->initDisplay (p, d);
    return TRUE;
}

static void addhelperOptionsFiniDisplay (CompPlugin *p, CompDisplay *d)
{
    if (addhelperPluginVTable && addhelperPluginVTable->finiDisplay)
        return addhelperPluginVTable->finiDisplay (p, d);

    ADDHELPER_OPTIONS_DISPLAY (d);

    freeScreenPrivateIndex(d, od->screenPrivateIndex);

    compFiniDisplayOptions (d, od->opt, AddhelperDisplayOptionNum);

    free (od);
}

static Bool addhelperOptionsInit (CompPlugin *p)
{
    displayPrivateIndex = allocateDisplayPrivateIndex();
    if (displayPrivateIndex < 0)
        return FALSE;

    if (!compInitPluginMetadataFromInfo (&addhelperOptionsMetadata, "addhelper",addhelperOptionsDisplayOptionInfo, AddhelperDisplayOptionNum, 0, 0))
        return FALSE;

    compAddMetadataFromFile (&addhelperOptionsMetadata, "addhelper");
    if (addhelperPluginVTable && addhelperPluginVTable->init)
        return addhelperPluginVTable->init (p);
    return TRUE;
}

static void addhelperOptionsFini (CompPlugin *p)
{
    if (addhelperPluginVTable && addhelperPluginVTable->fini)
        return addhelperPluginVTable->fini (p);

    if (displayPrivateIndex >= 0)
        freeDisplayPrivateIndex(displayPrivateIndex);

    compFiniMetadata (&addhelperOptionsMetadata);
}

static CompMetadata *
addhelperOptionsGetMetadata (CompPlugin *plugin)
{
    return &addhelperOptionsMetadata;
}

CompPluginVTable *getCompPluginInfo (void)
{
    if (!addhelperPluginVTable)
    {
        addhelperPluginVTable = addhelperOptionsGetCompPluginInfo ();
        memcpy(&addhelperOptionsVTable, addhelperPluginVTable, sizeof(CompPluginVTable));
        addhelperOptionsVTable.getMetadata = addhelperOptionsGetMetadata;
        addhelperOptionsVTable.init = addhelperOptionsInit;
        addhelperOptionsVTable.fini = addhelperOptionsFini;
        addhelperOptionsVTable.initDisplay = addhelperOptionsInitDisplay;
        addhelperOptionsVTable.finiDisplay = addhelperOptionsFiniDisplay;
        addhelperOptionsVTable.initScreen = addhelperOptionsInitScreen;
        addhelperOptionsVTable.finiScreen = addhelperOptionsFiniScreen;
        addhelperOptionsVTable.getDisplayOptions = addhelperOptionsGetDisplayOptions;
	addhelperOptionsVTable.setDisplayOption = addhelperOptionsSetDisplayOption;
	
    }
    return &addhelperOptionsVTable;
}



syntax highlighted by Code2HTML, v. 0.9.1