File indexing completed on 2024-04-28 16:49:42

0001 /*
0002  *  SPDX-FileCopyrightText: 2012, 2013 Daniel Vrátil <dvratil@redhat.com>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.1-or-later
0005  */
0006 #include "xrandrmode.h"
0007 
0008 #include "xrandroutput.h"
0009 
0010 #include "mode.h"
0011 
0012 XRandRMode::XRandRMode(const xcb_randr_mode_info_t &modeInfo, XRandROutput *output)
0013     : QObject(output)
0014 {
0015     m_id = modeInfo.id;
0016     // FIXME XCB
0017     // m_name = QString::fromUtf8(modeInfo->name);
0018     m_size = QSize(modeInfo.width, modeInfo.height);
0019 
0020     double vTotal = modeInfo.vtotal;
0021     if (modeInfo.mode_flags & XCB_RANDR_MODE_FLAG_DOUBLE_SCAN) {
0022         /* doublescan doubles the number of lines */
0023         vTotal *= 2;
0024     }
0025 
0026     if (modeInfo.mode_flags & XCB_RANDR_MODE_FLAG_INTERLACE) {
0027         /* interlace splits the frame into two fields */
0028         /* the field rate is what is typically reported by monitors */
0029         vTotal /= 2;
0030     }
0031 
0032     m_refreshRate = (float)modeInfo.dot_clock / ((float)modeInfo.htotal * vTotal);
0033 }
0034 
0035 XRandRMode::~XRandRMode()
0036 {
0037 }
0038 
0039 KScreen::ModePtr XRandRMode::toKScreenMode()
0040 {
0041     KScreen::ModePtr kscreenMode(new KScreen::Mode);
0042 
0043     kscreenMode->setId(QString::number(m_id));
0044     kscreenMode->setName(m_name);
0045     kscreenMode->setSize(m_size);
0046     kscreenMode->setRefreshRate(m_refreshRate);
0047 
0048     return kscreenMode;
0049 }
0050 
0051 xcb_randr_mode_t XRandRMode::id() const
0052 {
0053     return m_id;
0054 }
0055 
0056 QSize XRandRMode::size() const
0057 {
0058     return m_size;
0059 }
0060 
0061 float XRandRMode::refreshRate() const
0062 {
0063     return m_refreshRate;
0064 }
0065 
0066 QString XRandRMode::name() const
0067 {
0068     return m_name;
0069 }