summaryrefslogblamecommitdiffstats
path: root/oldsrc/output.cpp
blob: 94f6c89d6c33c10186c3be9f42eb7dd08c4eeb28 (plain) (tree)






















































































































                                                                                     
#include "output.h"
#include "stdio.h"


//DEVUTG
#include <inttypes.h>

Output::Output(Display *dpy, XRRScreenResources *resources, RROutput output)
    :dpy(dpy), resources(resources), ID(output)
{

}


bool Output::hasEDID() const
{
    int nprop;
    Atom *props = XRRListOutputProperties(dpy, ID, &nprop);
    Atom actual_type;
    int actual_format;
    unsigned long nitems, bytes_after;
    unsigned char *prop;
    XRRPropertyInfo *propinfo;
    int bytes_per_item, k;

    for (int i = 0; i < nprop; ++i) {
        char *atom_name = XGetAtomName (dpy, props[i]);
        if ( strcmp (atom_name, "EDID") == 0)
        {
            fprintf (stderr, "EDIDCHECK");
            XRRGetOutputProperty (dpy, ID, props[i],
                      0, 100, False, False,
                      AnyPropertyType,
                      &actual_type, &actual_format,
                      &nitems, &bytes_after, &prop);

            propinfo = XRRQueryOutputProperty(dpy, ID, props[i]);
            bytes_per_item = actual_format / 8;

            fprintf (stderr, "\t%s: ", atom_name);

            for (k = 0; k < nitems; k++)
            {
                if (k != 0)
                {
                    if ((k % 16) == 0)
                    {
                        fprintf (stderr, "\n\t\t");
                    }
                }
                const uint8_t *val = prop + (k * bytes_per_item);
                fprintf (stderr, "%d02", *val);

            }
            free(propinfo);
            return true;
        }
    }

}



bool Output::isProjector() const
{
    XRROutputInfo *info = XRRGetOutputInfo (dpy, resources, ID);
    bool result = ( info->mm_height == 0 && info->mm_width == 0 );
    XRRFreeOutputInfo(info);
    return result;
}

Resolution Output::getCurrentMode() const
{
    XRROutputInfo *OutputInfo = XRRGetOutputInfo (dpy, resources, ID);
    XRRCrtcInfo *CrtcInfo = XRRGetCrtcInfo(dpy, resources, OutputInfo->crtc);
    Resolution result = { CrtcInfo->width, CrtcInfo->height };
    XRRFreeCrtcInfo(CrtcInfo);
    XRRFreeOutputInfo(OutputInfo);
    return result;
}


Resolution Output::getPreferredMode() const
{
    XRROutputInfo *OutputInfo = XRRGetOutputInfo (dpy, resources, ID);
    RRMode preferred = OutputInfo->modes[OutputInfo->npreferred];
    XRRFreeOutputInfo(OutputInfo);
    return getResolution(preferred);
}


QSet<Resolution> Output::getSupportedModes() const
{
    QSet<Resolution> result;
    XRROutputInfo *info = XRRGetOutputInfo (dpy, resources, ID);
    for (int i = 0; i < info->nmode; ++i)
        result.insert(getResolution(info->modes[i]));
    XRRFreeOutputInfo(info);
    return result;
}


Resolution Output::addMode(Resolution) const
{
    // TODO
    return Resolution();
}

Resolution Output::getResolution(RRMode mode) const
{
    for (int i = 0; i < resources->nmode; ++i) {
        if ( resources->modes[i].id == mode ) {
            Resolution res = {resources->modes[i].width, resources->modes[i].height};
            return res;
        }
    }
    fprintf ( stderr, "Could not find a mode for the requested XID %d", (int)mode);
    exit(1);
}