~ubuntu-branches/ubuntu/wily/kdebase-workspace/wily

« back to all changes in this revision

Viewing changes to .pc/initialize_variables_crashfix.diff/libs/kephal/service/xrandroutputs.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas, Jonathan Thomas, Tarun Kumar Mall, Philip Muškovac, Stéphane Graber, James Hunt
  • Date: 2011-06-01 02:09:54 UTC
  • mfrom: (0.1.21 sid)
  • Revision ID: james.westby@ubuntu.com-20110601020954-id2t0x9rwxwrmjn2
Tags: 4:4.6.3-1ubuntu1
[ Jonathan Thomas ]
* Merge with Debian Unstable, remaining changes:
  - Add kdebase-workspace-wallpapers.{links, install}
  - Add kdebase-workspace-data.links
  - kdebase-workspace-data.install: don't add wallpapers that are in
    kdebase-workspace-wallpapers.install
  - Add kdm.{links, upstart}
  - kdm.logrotate: rotate 2 -> rotate 7
  - Make kdm work with upstart in kdm.prerm, kdm.postrm, kdm.postinst
  - debian/control:
    - don't build against libggadget-1.0-dev, libggadget-qt-1.0-dev
      (they are in Universe)
    - Build against libbost1.46-dev instead of libboost-dev
    - Add libxml2-dev, libpolkit-qt-1-dev to build-deps
    - Add python-kde4, python-sip, python-qt4 to build-dependencies
    - Keep bumped our replaces/breaks
    - plasma-netbook replaces plasma-widgets-workspace (<= 4:4.5.2-1ubuntu1)
    - kdebase-workspace-bin suggests plasma-scriptengines instead of
      recommend
    - kdebase-workspace-data depends on oxygen-cursor-theme instead of oxygencursors
    - Keep kdebase-workspace-wallpapers
    - plasma-dataengines-workspace replaces plasma-widget-workspace (<= 4:4.5.2-1ubuntu1)
    - plasma-widgets-workspace depends on akonadi-server and kdepim-runtime
    - plasma-scriptengines not depends on plasma-scriptengine-googlegadgets
    - plasma-scriptengine-ruby depends on libkde4-ruby
    - Don't build plasma-scriptengine-googlegadgets
    - freespacenotifier replaces kdebase-workspace-data (<= 4:4.5.2-1ubuntu1)
      and kdebase-workspace-bin (<= 4:4.5.2-1ubuntu1)
    - kinfocenter replaces kdebase-workspace-bin and systemsettings
    - libplasmagenericshell4 replaces plasma-widgets-workspace (<= 4:4.5.2-1ubuntu1)
  - debian/patches:
    - Use 07_kdmrc_defaults_kubuntu.diff instead of 07_kdmrc_defaults.diff
    - Don't add be_better_at_honouring_user_kdm_theming
    - Don't add use_dejavu_as_default_font
    - Don't add fix_target_link_libraries
    - Keep our patches
* Try a polkit-kde-1 | policykit-gnome-1 or-dependency again to see if policykit-1-gnome
  is a suitable policykit solution a year later.

[ Tarun Kumar Mall ]
* New uptream release
* Bumped kde-sc-dev-latest version to 4.6.3
* Removed patches kubuntu_120_ksysguard_sensors.diff and
  kubuntu_121_kdm_halt_cmd.diff, applied upstream
* Refreshed kubuntu_122_akonadi_calendar_dataengine.diff 

[ Philip Muškovac ]
* drop kubuntu_123_effectframe_glflush.diff, applied upstream
* Refresh symbol files 

[ Stéphane Graber ]
* Updated Vcs fields to point to kubuntu-uploaders instead of
  kubuntu-members

[ James Hunt ]
* Updated kdm.conf to fix kdm in single user mode (LP: #436936)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright 2008 Aike J Sommer <dev@aikesommer.name>
 
3
 *
 
4
 *   This program is free software; you can redistribute it and/or modify
 
5
 *   it under the terms of the GNU General Public License as
 
6
 *   published by the Free Software Foundation; either version 2,
 
7
 *   or (at your option) any later version.
 
8
 *
 
9
 *   This program is distributed in the hope that it will be useful,
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *   GNU General Public License for more details
 
13
 *
 
14
 *   You should have received a copy of the GNU Library General Public
 
15
 *   License along with this program; if not, write to the
 
16
 *   Free Software Foundation, Inc.,
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 */
 
19
 
 
20
 
 
21
#include "xrandroutputs.h"
 
22
#include "edid.h"
 
23
 
 
24
#include "xrandr12/randrscreen.h"
 
25
#include "xrandr12/randroutput.h"
 
26
 
 
27
#include <X11/Xatom.h>
 
28
 
 
29
#include <QX11Info>
 
30
 
 
31
#include <KDebug>
 
32
#include <QX11Info>
 
33
 
 
34
namespace Kephal {
 
35
 
 
36
    XRandROutputs::XRandROutputs(QObject * parent, RandRDisplay * display)
 
37
            : BackendOutputs(parent)
 
38
    {
 
39
        m_display = display;
 
40
        init();
 
41
    }
 
42
 
 
43
    QList<Output *> XRandROutputs::outputs() {
 
44
        QList<Output *> result;
 
45
        foreach (XRandROutput * output, m_outputs) {
 
46
            result.append(output);
 
47
        }
 
48
        return result;
 
49
    }
 
50
 
 
51
    void XRandROutputs::init() {
 
52
        kDebug();
 
53
        RandRScreen * screen = m_display->screen(0);
 
54
        foreach (RandROutput * output, screen->outputs()) {
 
55
            XRandROutput * o = new XRandROutput(this, output->id());
 
56
 
 
57
            connect(o, SIGNAL(outputConnected(Kephal::Output *)),
 
58
                    this, SIGNAL(outputConnected(Kephal::Output *)));
 
59
 
 
60
            connect(o, SIGNAL(outputDisconnected(Kephal::Output *)),
 
61
                    this, SIGNAL(outputDisconnected(Kephal::Output *)));
 
62
 
 
63
            connect(o, SIGNAL(outputActivated(Kephal::Output *)),
 
64
                    this, SIGNAL(outputActivated(Kephal::Output *)));
 
65
 
 
66
            connect(o, SIGNAL(outputDeactivated(Kephal::Output *)),
 
67
                    this, SIGNAL(outputDeactivated(Kephal::Output *)));
 
68
 
 
69
            connect(o, SIGNAL(outputResized(Kephal::Output *, QSize, QSize)),
 
70
                    this, SIGNAL(outputResized(Kephal::Output *, QSize, QSize)));
 
71
 
 
72
            connect(o, SIGNAL(outputMoved(Kephal::Output *, QPoint, QPoint)),
 
73
                    this, SIGNAL(outputMoved(Kephal::Output *, QPoint, QPoint)));
 
74
 
 
75
            connect(o, SIGNAL(outputRateChanged(Kephal::Output *, float, float)),
 
76
                    this, SIGNAL(outputRateChanged(Kephal::Output *, float, float)));
 
77
 
 
78
            connect(o, SIGNAL(outputRotated(Kephal::Output *, Kephal::Rotation, Kephal::Rotation)),
 
79
                    this, SIGNAL(outputRotated(Kephal::Output *, Kephal::Rotation, Kephal::Rotation)));
 
80
            connect(o, SIGNAL(outputReflected(Kephal::Output *, bool, bool, bool, bool)),
 
81
                    this, SIGNAL(outputReflected(Kephal::Output *, bool, bool, bool, bool)));
 
82
 
 
83
            kDebug() << "  added output " << output->id();
 
84
            m_outputs.insert(o->id(), o);
 
85
        }
 
86
    }
 
87
 
 
88
    RandROutput * XRandROutputs::output(RROutput rrId) {
 
89
        return m_display->screen(0)->outputs()[rrId];
 
90
    }
 
91
 
 
92
    RandRDisplay * XRandROutputs::display() {
 
93
        return m_display;
 
94
    }
 
95
 
 
96
    XRandROutput::XRandROutput(XRandROutputs * parent, RROutput rrId)
 
97
            : BackendOutput(parent), m_productId(-1), m_serialNumber(0)
 
98
    {
 
99
        m_outputs = parent;
 
100
        m_rrId = rrId;
 
101
 
 
102
        parseEdid();
 
103
 
 
104
        saveAsPrevious();
 
105
 
 
106
        connect(output(), SIGNAL(outputChanged(RROutput, int)),
 
107
                this, SLOT(outputChanged(RROutput, int)));
 
108
        //connect(this, SLOT(_activate()), output(), SLOT(slotEnable()));
 
109
        //connect(this, SLOT(_deactivate()), output(), SLOT(slotDisable()));
 
110
    }
 
111
 
 
112
    void XRandROutput::parseEdid() {
 
113
 
 
114
        Atom atom = XInternAtom (QX11Info::display(), "EDID_DATA", false);
 
115
        Atom type;
 
116
        unsigned char * data;
 
117
        unsigned long size;
 
118
        unsigned long after;
 
119
        int format;
 
120
 
 
121
        XRRGetOutputProperty(QX11Info::display(), m_rrId, atom, 0, 100,
 
122
                False, False, AnyPropertyType,
 
123
                &type, &format, &size, &after, &data);
 
124
 
 
125
        if (type == XA_INTEGER && format == 8 && EDID_TEST_HEADER(data)) {
 
126
            //kDebug() << "got a valid edid block...";
 
127
 
 
128
            /**
 
129
             * parse the 3 letter vendor code
 
130
             */
 
131
            char * vendor = new char[4];
 
132
 
 
133
            vendor[0] = EDID_VENDOR_1(data);
 
134
            vendor[1] = EDID_VENDOR_2(data);
 
135
            vendor[2] = EDID_VENDOR_3(data);
 
136
            vendor[3] = 0x00;
 
137
            m_vendor = vendor;
 
138
 
 
139
            kDebug() << "vendor code:" << m_vendor;
 
140
 
 
141
            delete[] vendor;
 
142
 
 
143
            /**
 
144
             * parse the 16bit product id
 
145
             */
 
146
            m_productId = EDID_PRODUCT_ID(data);
 
147
 
 
148
            kDebug() << "product id:" << m_productId;
 
149
 
 
150
            /**
 
151
             * parse the 32bit serial number
 
152
             */
 
153
            m_serialNumber = EDID_SERIAL_NUMBER(data);
 
154
 
 
155
            kDebug() << "serial number:" << m_serialNumber;
 
156
        } else {
 
157
            m_vendor = QString();
 
158
            m_productId = -1;
 
159
            m_serialNumber = 0;
 
160
        }
 
161
 
 
162
        XFree(data);
 
163
    }
 
164
 
 
165
    void XRandROutput::outputChanged(RROutput id, int changes) {
 
166
        Q_ASSERT(id == m_rrId);
 
167
        kDebug() << isConnected() << isActivated() << geom();
 
168
        if (isConnected() != m_previousConnected) {
 
169
            if (isConnected()) {
 
170
                saveAsPrevious();
 
171
                parseEdid();
 
172
                emit outputConnected(this);
 
173
                if (isActivated()) {
 
174
                    emit outputActivated(this);
 
175
                }
 
176
            } else {
 
177
                if (m_previousActivated) {
 
178
                    saveAsPrevious();
 
179
                    emit outputDeactivated(this);
 
180
                }
 
181
                saveAsPrevious();
 
182
                emit outputDisconnected(this);
 
183
            }
 
184
            return;
 
185
        }
 
186
        if (! isConnected()) {
 
187
            return;
 
188
        }
 
189
        if (isActivated() != m_previousActivated) {
 
190
            saveAsPrevious();
 
191
            if (isActivated()) {
 
192
                emit outputActivated(this);
 
193
            } else {
 
194
                emit outputDeactivated(this);
 
195
            }
 
196
            return;
 
197
        }
 
198
 
 
199
        QRect previousGeom = m_previousGeom;
 
200
        Rotation previousRotation = m_previousRotation;
 
201
        float previousRate = m_previousRate;
 
202
        bool previousReflectX = m_previousReflectX;
 
203
        bool previousReflectY = m_previousReflectY;
 
204
        saveAsPrevious();
 
205
        if (size() != previousGeom.size()) {
 
206
            emit outputResized(this, previousGeom.size(), size());
 
207
        }
 
208
        if (position() != previousGeom.topLeft()) {
 
209
            emit outputMoved(this, previousGeom.topLeft(), position());
 
210
        }
 
211
        if (rotation() != previousRotation) {
 
212
            emit outputRotated(this, previousRotation, rotation());
 
213
        }
 
214
        if (rate() != previousRate) {
 
215
            emit outputRateChanged(this, previousRate, rate());
 
216
        }
 
217
        if ((reflectX() != previousReflectX) || (reflectY() != previousReflectY)) {
 
218
            emit outputReflected(this, previousReflectX, previousReflectY, reflectX(), reflectY());
 
219
        }
 
220
    }
 
221
 
 
222
    void XRandROutput::saveAsPrevious() {
 
223
        m_previousConnected = isConnected();
 
224
        m_previousActivated = isActivated();
 
225
        m_previousGeom = geom();
 
226
        m_previousRotation = rotation();
 
227
        m_previousRate = rate();
 
228
        m_previousReflectX = reflectX();
 
229
        m_previousReflectY = reflectY();
 
230
    }
 
231
 
 
232
    bool XRandROutput::applyGeom(const QRect & geom, float rate) {
 
233
        if ((geom == this->geom()) && ((rate < 1) || (qFuzzyCompare(rate, this->rate())))) {
 
234
            return true;
 
235
        }
 
236
 
 
237
        output()->proposeRect(geom);
 
238
        if (rate < 1) {
 
239
            rate = output()->refreshRate();
 
240
        }
 
241
        bool found = false;
 
242
        QList<float> rates = output()->refreshRates(geom.size());
 
243
        foreach (float r, rates) {
 
244
            if (qFuzzyCompare(rate, r)) {
 
245
                rate = r;
 
246
                found = true;
 
247
                break;
 
248
            }
 
249
        }
 
250
        if ((! found) && (! rates.empty())) {
 
251
            rate = rates[0];
 
252
        }
 
253
        if (rate > 1) {
 
254
            output()->proposeRefreshRate(rate);
 
255
        }
 
256
 
 
257
        return output()->applyProposed();
 
258
    }
 
259
 
 
260
    bool XRandROutput::applyOrientation(Rotation rotation, bool reflectX, bool reflectY) {
 
261
        if ((rotation == this->rotation()) && (reflectX == this->reflectX()) && (reflectY == this->reflectY())) {
 
262
            return true;
 
263
        }
 
264
 
 
265
        int orientation = 0;
 
266
 
 
267
        switch (rotation) {
 
268
            case RotateRight:
 
269
                orientation |= RandR::Rotate90;
 
270
                break;
 
271
            case RotateLeft:
 
272
                orientation |= RandR::Rotate270;
 
273
                break;
 
274
            case RotateInverted:
 
275
                orientation |= RandR::Rotate180;
 
276
                break;
 
277
            default:
 
278
                orientation |= RandR::Rotate0;
 
279
        }
 
280
 
 
281
        if (reflectX) {
 
282
            orientation |= RandR::ReflectX;
 
283
        }
 
284
        if (reflectY) {
 
285
            orientation |= RandR::ReflectY;
 
286
        }
 
287
 
 
288
        output()->proposeRotation(orientation);
 
289
        return output()->applyProposed();
 
290
    }
 
291
 
 
292
    void XRandROutput::deactivate()
 
293
    {
 
294
        output()->slotDisable();
 
295
    }
 
296
 
 
297
    RandROutput * XRandROutput::output() const
 
298
    {
 
299
        return m_outputs->output(m_rrId);
 
300
    }
 
301
 
 
302
    QString XRandROutput::id() const
 
303
    {
 
304
        return output()->name();
 
305
    }
 
306
 
 
307
    QSize XRandROutput::size() const
 
308
    {
 
309
        return output()->rect().size();
 
310
    }
 
311
 
 
312
    QSize XRandROutput::preferredSize() const
 
313
    {
 
314
        if (output()->preferredMode().size().isEmpty()) {
 
315
            return QSize();
 
316
        } else {
 
317
            return output()->preferredMode().size();
 
318
        }
 
319
    }
 
320
 
 
321
    QList<QSize> XRandROutput::availableSizes() const {
 
322
        QList<QSize> sizes = output()->sizes();
 
323
        return sizes;
 
324
    }
 
325
 
 
326
    QPoint XRandROutput::position() const {
 
327
        return output()->rect().topLeft();
 
328
    }
 
329
 
 
330
    bool XRandROutput::isConnected() const {
 
331
        return output()->isConnected();
 
332
    }
 
333
 
 
334
    bool XRandROutput::isActivated() const
 
335
    {
 
336
        return output()->isActive();
 
337
    }
 
338
 
 
339
    QString XRandROutput::vendor() const
 
340
    {
 
341
        return m_vendor;
 
342
    }
 
343
 
 
344
    int XRandROutput::productId() const
 
345
    {
 
346
        return m_productId;
 
347
    }
 
348
 
 
349
    unsigned int XRandROutput::serialNumber() const
 
350
    {
 
351
        return m_serialNumber;
 
352
    }
 
353
 
 
354
    RROutput XRandROutput::_id() const {
 
355
        return m_rrId;
 
356
    }
 
357
 
 
358
    Rotation XRandROutput::rotation() const
 
359
    {
 
360
        switch (output()->rotation() & RandR::RotateMask) {
 
361
            case RandR::Rotate90:
 
362
                return RotateRight;
 
363
            case RandR::Rotate180:
 
364
                return RotateInverted;
 
365
            case RandR::Rotate270:
 
366
                return RotateLeft;
 
367
            default:
 
368
                return RotateNormal;
 
369
        }
 
370
    }
 
371
 
 
372
    bool XRandROutput::reflectX() const
 
373
    {
 
374
        return (output()->rotation() & RandR::ReflectX);
 
375
    }
 
376
 
 
377
    bool XRandROutput::reflectY() const
 
378
    {
 
379
        return (output()->rotation() & RandR::ReflectY);
 
380
    }
 
381
 
 
382
    float XRandROutput::rate() const
 
383
    {
 
384
        return output()->refreshRate();
 
385
    }
 
386
 
 
387
    QList<float> XRandROutput::availableRates() const
 
388
    {
 
389
        return output()->refreshRates(size());
 
390
    }
 
391
 
 
392
    void XRandROutput::resize(const QSize & size)
 
393
    {
 
394
        Q_UNUSED(size)
 
395
#warning implement!
 
396
    }
 
397
 
 
398
    void XRandROutput::rotate(Rotation rotation)
 
399
    {
 
400
        Q_UNUSED(rotation)
 
401
#warning implement!
 
402
    }
 
403
 
 
404
    void XRandROutput::setReflectX(bool reflect)
 
405
    {
 
406
        Q_UNUSED(reflect)
 
407
#warning implement!
 
408
    }
 
409
 
 
410
    void XRandROutput::setReflectY(bool reflect)
 
411
    {
 
412
        Q_UNUSED(reflect)
 
413
#warning implement!
 
414
    }
 
415
 
 
416
    void XRandROutput::changeRate(double rate)
 
417
    {
 
418
        Q_UNUSED(rate)
 
419
#warning implement!
 
420
    }
 
421
 
 
422
}
 
423