~ubuntu-branches/ubuntu/trusty/compiz/trusty

« back to all changes in this revision

Viewing changes to src/outputdevices.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2013-08-22 06:58:07 UTC
  • mto: This revision was merged to the branch mainline in revision 3352.
  • Revision ID: package-import@ubuntu.com-20130822065807-17nlzez0d30y09so
Tags: upstream-0.9.10+13.10.20130822
ImportĀ upstreamĀ versionĀ 0.9.10+13.10.20130822

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
namespace core
32
32
{
33
33
 
34
 
OutputDevices::OutputDevices() :
 
34
OutputDevices::OutputDevices () :
35
35
    outputDevs (),
36
36
    overlappingOutputs (false),
37
37
    currentOutputDev (0)
39
39
}
40
40
 
41
41
void
42
 
OutputDevices::setGeometryOnDevice(unsigned int const nOutput,
43
 
    int x, int y,
44
 
    const int width, const int height)
 
42
OutputDevices::setGeometryOnDevice (unsigned int const nOutput,
 
43
                                    int                x,
 
44
                                    int                y,
 
45
                                    const int          width,
 
46
                                    const int          height)
45
47
{
46
48
    if (outputDevs.size() < nOutput + 1)
47
 
        outputDevs.resize(nOutput + 1);
 
49
        outputDevs.resize (nOutput + 1);
48
50
 
49
 
    outputDevs[nOutput].setGeometry(x, y, width, height);
 
51
    outputDevs[nOutput].setGeometry (x, y, width, height);
50
52
}
51
53
 
52
54
void
53
 
OutputDevices::adoptDevices(unsigned int nOutput, CompSize* screen)
 
55
OutputDevices::adoptDevices (unsigned int nOutput,
 
56
                             CompSize     *screen)
54
57
{
55
58
    /* make sure we have at least one output */
56
59
    if (!nOutput)
57
60
    {
58
 
        setGeometryOnDevice(nOutput, 0, 0, screen->width(), screen->height());
59
 
        nOutput++;
 
61
        setGeometryOnDevice (nOutput, 0, 0, screen->width (), screen->height ());
 
62
        ++nOutput;
60
63
    }
61
 
    if (outputDevs.size() > nOutput)
62
 
        outputDevs.resize(nOutput);
 
64
 
 
65
    if (outputDevs.size () > nOutput)
 
66
        outputDevs.resize (nOutput);
63
67
 
64
68
    char str[10];
65
69
    /* set name, width, height and update rect pointers in all regions */
66
 
    for (unsigned int i = 0; i < nOutput; i++)
 
70
    for (unsigned int i = 0; i < nOutput; ++i)
67
71
    {
68
72
        snprintf(str, 10, "Output %u", i);
69
 
        outputDevs[i].setId(str, i);
 
73
        outputDevs[i].setId (str, i);
70
74
    }
 
75
 
71
76
    overlappingOutputs = false;
72
77
    setCurrentOutput (currentOutputDev);
73
 
    for (unsigned int i = 0; i < nOutput - 1; i++)
74
 
        for (unsigned int j = i + 1; j < nOutput; j++)
75
 
            if (outputDevs[i].intersects(outputDevs[j]))
 
78
 
 
79
    for (unsigned int i = 0; i < nOutput - 1; ++i)
 
80
        for (unsigned int j = i + 1; j < nOutput; ++j)
 
81
            if (outputDevs[i].intersects (outputDevs[j]))
76
82
                overlappingOutputs = true;
77
83
}
78
84
 
86
92
}
87
93
 
88
94
int
89
 
OutputDevices::outputDeviceForGeometry (
90
 
        const CompWindow::Geometry& gm,
91
 
        int strategy,
92
 
        CompSize* screen) const
 
95
OutputDevices::outputDeviceForGeometry (const CompWindow::Geometry &gm,
 
96
                                        int                        strategy,
 
97
                                        CompSize                   *screen) const
93
98
{
 
99
    if (outputDevs.size () == 1)
 
100
        return 0;
 
101
 
94
102
    int          overlapAreas[outputDevs.size ()];
95
103
    int          highest, seen, highestScore;
96
 
    int          x, y;
97
104
    unsigned int i;
98
 
    CompRect     geomRect;
99
 
 
100
 
    if (outputDevs.size () == 1)
101
 
        return 0;
102
 
 
 
105
    CompRect     geomRect, overlap;
103
106
 
104
107
    if (strategy == CoreOptions::OverlappingOutputsSmartMode)
105
108
    {
113
116
    {
114
117
        /* for biggest/smallest modes, only use the window center to determine
115
118
           the correct output device */
116
 
        x = (gm.x () + (gm.width () / 2) + gm.border ()) % screen->width ();
 
119
        int x = (gm.x () + (gm.width () / 2) + gm.border ()) % screen->width ();
 
120
 
117
121
        if (x < 0)
118
122
            x += screen->width ();
119
 
        y = (gm.y () + (gm.height () / 2) + gm.border ()) % screen->height ();
 
123
 
 
124
        int y = (gm.y () + (gm.height () / 2) + gm.border ()) % screen->height ();
 
125
 
120
126
        if (y < 0)
121
127
            y += screen->height ();
122
128
 
124
130
    }
125
131
 
126
132
    /* get amount of overlap on all output devices */
127
 
    for (i = 0; i < outputDevs.size (); i++)
 
133
    for (i = 0; i < outputDevs.size (); ++i)
128
134
    {
129
 
        CompRect overlap = outputDevs[i] & geomRect;
 
135
        overlap         = outputDevs[i] & geomRect;
130
136
        overlapAreas[i] = overlap.area ();
131
137
    }
132
138
 
133
139
    /* find output with largest overlap */
134
 
    for (i = 0, highest = 0, highestScore = 0;
135
 
         i < outputDevs.size (); i++)
 
140
    for (i = 0, highest = 0, highestScore = 0; i < outputDevs.size (); ++i)
136
141
    {
137
142
        if (overlapAreas[i] > highestScore)
138
143
        {
139
 
            highest = i;
 
144
            highest      = i;
140
145
            highestScore = overlapAreas[i];
141
146
        }
142
147
    }
143
148
 
144
149
    /* look if the highest score is unique */
145
 
    for (i = 0, seen = 0; i < outputDevs.size (); i++)
 
150
    for (i = 0, seen = 0; i < outputDevs.size (); ++i)
146
151
        if (overlapAreas[i] == highestScore)
147
 
            seen++;
 
152
            ++seen;
148
153
 
149
154
    if (seen > 1)
150
155
    {
151
156
        /* it's not unique, select one output of the matching ones and use the
152
157
           user preferred strategy for that */
153
158
        unsigned int currentSize, bestOutputSize;
154
 
        bool         searchLargest;
 
159
        bool         bestFit;
155
160
 
156
 
        searchLargest =
 
161
        bool searchLargest =
157
162
            (strategy != CoreOptions::OverlappingOutputsPreferSmallerOutput);
158
163
 
159
164
        if (searchLargest)
161
166
        else
162
167
            bestOutputSize = UINT_MAX;
163
168
 
164
 
        for (i = 0, highest = 0; i < outputDevs.size (); i++)
 
169
        for (i = 0, highest = 0; i < outputDevs.size (); ++i)
 
170
        {
165
171
            if (overlapAreas[i] == highestScore)
166
172
            {
167
 
                bool bestFit;
168
 
 
169
173
                currentSize = outputDevs[i].area ();
170
174
 
171
175
                if (searchLargest)
175
179
 
176
180
                if (bestFit)
177
181
                {
178
 
                    highest = i;
 
182
                    highest        = i;
179
183
                    bestOutputSize = currentSize;
180
184
                }
181
185
            }
 
186
        }
182
187
    }
183
188
 
184
189
    return highest;
186
191
 
187
192
} // namespace core
188
193
} // namespace compiz
189