summaryrefslogtreecommitdiffstats
path: root/oldsrc/output.cpp
blob: 94f6c89d6c33c10186c3be9f42eb7dd08c4eeb28 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#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);
}