diff --git a/backends/xrandr/xrandr.h b/backends/xrandr/xrandr.h --- a/backends/xrandr/xrandr.h +++ b/backends/xrandr/xrandr.h @@ -16,24 +16,20 @@ * License along with this library; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *************************************************************************************/ - -#ifndef XRANDR_BACKEND_H -#define XRANDR_BACKEND_H +#pragma once #include "abstractbackend.h" -#include #include +#include #include "../xcbwrapper.h" class QRect; class QTimer; class XCBEventListener; class XRandRConfig; -namespace KScreen { -} class XRandR : public KScreen::AbstractBackend { @@ -58,27 +54,21 @@ static bool hasProperty(xcb_randr_output_t outputId, const QByteArray &name); - private Q_SLOTS: - void outputChanged(xcb_randr_output_t output, - xcb_randr_crtc_t crtc, - xcb_randr_mode_t mode, + private: + void outputChanged(xcb_randr_output_t output, xcb_randr_crtc_t crtc, xcb_randr_mode_t mode, xcb_randr_connection_t connection); - void crtcChanged(xcb_randr_crtc_t crtc, - xcb_randr_mode_t mode, - xcb_randr_rotation_t rotation, - const QRect &geom); - void screenChanged(xcb_randr_rotation_t rotation, - const QSize &sizePx, - const QSize &sizeMm); + void crtcChanged(xcb_randr_crtc_t crtc, xcb_randr_mode_t mode, + xcb_randr_rotation_t rotation, const QRect &geom); + void screenChanged(xcb_randr_rotation_t rotation, const QSize &sizePx, const QSize &sizeMm); - private: static quint8* getXProperty(xcb_randr_output_t output, xcb_atom_t atom, size_t &len); static xcb_screen_t *s_screen; static xcb_window_t s_rootWindow; static XRandRConfig *s_internalConfig; + static int s_randrBase; static int s_randrError; static bool s_monitorInitialized; @@ -92,4 +82,3 @@ }; Q_DECLARE_LOGGING_CATEGORY(KSCREEN_XRANDR) -#endif //XRandR_BACKEND_H diff --git a/backends/xrandr/xrandr.cpp b/backends/xrandr/xrandr.cpp --- a/backends/xrandr/xrandr.cpp +++ b/backends/xrandr/xrandr.cpp @@ -16,25 +16,22 @@ * License along with this library; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *************************************************************************************/ - #include "xrandr.h" + #include "xrandrconfig.h" #include "xrandrscreen.h" #include "../xcbwrapper.h" #include "../xcbeventlistener.h" #include "config.h" -#include "output.h" #include "edid.h" +#include "output.h" -#include #include -#include #include #include #include -#include xcb_screen_t* XRandR::s_screen = nullptr; xcb_window_t XRandR::s_rootWindow = 0; @@ -66,15 +63,19 @@ xcb_generic_error_t *error = nullptr; xcb_randr_query_version_reply_t* version; XCB::connection(); - version = xcb_randr_query_version_reply(XCB::connection(), xcb_randr_query_version(XCB::connection(), XCB_RANDR_MAJOR_VERSION, XCB_RANDR_MINOR_VERSION), &error); - + version = xcb_randr_query_version_reply(XCB::connection(), + xcb_randr_query_version(XCB::connection(), + XCB_RANDR_MAJOR_VERSION, + XCB_RANDR_MINOR_VERSION), + &error); if (!version || error) { XCB::closeConnection(); free(error); return; } - if ((version->major_version > 1) || ((version->major_version == 1) && (version->minor_version >= 2))) { + if ((version->major_version > 1) || + ((version->major_version == 1) && (version->minor_version >= 2))) { m_isValid = true; } else { XCB::closeConnection(); @@ -92,7 +93,8 @@ s_randrError = reply->first_error; } - XRandR::s_has_1_3 = (version->major_version > 1 || (version->major_version == 1 && version->minor_version >= 3)); + XRandR::s_has_1_3 = (version->major_version > 1 || + (version->major_version == 1 && version->minor_version >= 3)); if (s_internalConfig == nullptr) { s_internalConfig = new XRandRConfig(); @@ -163,7 +165,8 @@ XCB::PrimaryOutput primary(XRandR::rootWindow()); xOutput->update(crtc, mode, connection, (primary->output == output)); - qCDebug(KSCREEN_XRANDR) << "Output" << xOutput->id() << ": connected =" << xOutput->isConnected() << ", enabled =" << xOutput->isEnabled(); + qCDebug(KSCREEN_XRANDR) << "Output" << xOutput->id() << ": connected =" + << xOutput->isConnected() << ", enabled =" << xOutput->isEnabled(); } void XRandR::crtcChanged(xcb_randr_crtc_t crtc, xcb_randr_mode_t mode, @@ -236,6 +239,7 @@ XCB_ATOM_ANY, 0, 100, false, false); auto reply = xcb_randr_get_output_property_reply(XCB::connection(), cookie, nullptr); + if (reply->type == XCB_ATOM_INTEGER && reply->format == 8) { result = new quint8[reply->num_items]; memcpy(result, xcb_randr_get_output_property_data(reply), reply->num_items); @@ -278,7 +282,9 @@ { xcb_generic_error_t *error = nullptr; auto atom = XCB::InternAtom(false, name.length(), name.constData())->atom; - auto cookie = xcb_randr_get_output_property(XCB::connection(), output, atom, XCB_ATOM_ANY, 0, 1, false, false); + + auto cookie = xcb_randr_get_output_property(XCB::connection(), output, atom, XCB_ATOM_ANY, + 0, 1, false, false); auto prop_reply = xcb_randr_get_output_property_reply (XCB::connection(), cookie, &error); const bool ret = prop_reply->num_items == 1; @@ -294,8 +300,9 @@ // and xcb_randr_get_screen_resources_current_reply_t are the same return reinterpret_cast( xcb_randr_get_screen_resources_current_reply(XCB::connection(), - xcb_randr_get_screen_resources_current(XCB::connection(), XRandR::rootWindow()), - nullptr)); + xcb_randr_get_screen_resources_current( + XCB::connection(), + XRandR::rootWindow()), nullptr)); } else { /* XRRGetScreenResourcesCurrent is faster then XRRGetScreenResources * because it returns cached values. However the cached values are not @@ -306,7 +313,10 @@ } return xcb_randr_get_screen_resources_reply(XCB::connection(), - xcb_randr_get_screen_resources(XCB::connection(), XRandR::rootWindow()), nullptr); + xcb_randr_get_screen_resources( + XCB::connection(), + XRandR::rootWindow()), + nullptr); } xcb_window_t XRandR::rootWindow() diff --git a/backends/xrandr/xrandrconfig.h b/backends/xrandr/xrandrconfig.h --- a/backends/xrandr/xrandrconfig.h +++ b/backends/xrandr/xrandrconfig.h @@ -15,9 +15,7 @@ * License along with this library; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *************************************************************************************/ - -#ifndef XRANDRCONFIG_H -#define XRANDRCONFIG_H +#pragma once #include @@ -35,7 +33,7 @@ Q_OBJECT public: - explicit XRandRConfig(); + XRandRConfig(); ~XRandRConfig() override; XRandROutput::Map outputs() const; @@ -54,22 +52,23 @@ void applyKScreenConfig(const KScreen::ConfigPtr &config); private: - /** - * We need to print stuff to discover the damn bug - * where currentMode is null - */ - void printConfig(const KScreen::ConfigPtr &config) const; - void printInternalCond() const; QSize screenSize(const KScreen::ConfigPtr &config) const; bool setScreenSize(const QSize &size) const; + void setPrimaryOutput(xcb_randr_output_t outputId) const; + bool disableOutput(const KScreen::OutputPtr &output) const; bool enableOutput(const KScreen::OutputPtr &output) const; bool changeOutput(const KScreen::OutputPtr &output) const; + /** + * We need to print stuff to discover the damn bug + * where currentMode is null + */ + void printConfig(const KScreen::ConfigPtr &config) const; + void printInternalCond() const; + XRandROutput::Map m_outputs; XRandRCrtc::Map m_crtcs; XRandRScreen *m_screen; }; - -#endif // XRANDRCONFIG_H diff --git a/backends/xrandr/xrandrconfig.cpp b/backends/xrandr/xrandrconfig.cpp --- a/backends/xrandr/xrandrconfig.cpp +++ b/backends/xrandr/xrandrconfig.cpp @@ -16,7 +16,6 @@ * License along with this library; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *************************************************************************************/ - #include "xrandrconfig.h" #include "xrandrscreen.h" #include "xrandr.h" @@ -42,13 +41,16 @@ m_screen = new XRandRScreen(this); XCB::ScopedPointer resources(XRandR::screenResources()); + xcb_randr_crtc_t *crtcs = xcb_randr_get_screen_resources_crtcs(resources.data()); - for (int i = 0, c = xcb_randr_get_screen_resources_crtcs_length(resources.data()); i < c; ++i) { + const int crtcsCount = xcb_randr_get_screen_resources_crtcs_length(resources.data()); + for (int i = 0; i < crtcsCount; ++i) { addNewCrtc(crtcs[i]); } xcb_randr_output_t *outputs = xcb_randr_get_screen_resources_outputs(resources.data()); - for (int i = 0, c = xcb_randr_get_screen_resources_outputs_length(resources.data()); i < c; ++i) { + const int outputsCount = xcb_randr_get_screen_resources_outputs_length(resources.data()); + for (int i = 0; i < outputsCount; ++i) { addNewOutput(outputs[i]); } } @@ -105,14 +107,17 @@ KScreen::ConfigPtr XRandRConfig::toKScreenConfig() const { KScreen::ConfigPtr config(new KScreen::Config); + auto features = Config::Feature::Writable | Config::Feature::PrimaryDisplay; config->setSupportedFeatures(features); + KScreen::OutputList kscreenOutputs; for (auto iter = m_outputs.constBegin(); iter != m_outputs.constEnd(); ++iter) { KScreen::OutputPtr kscreenOutput = (*iter)->toKScreenOutput(); kscreenOutputs.insert(kscreenOutput->id(), kscreenOutput); } + config->setOutputs(kscreenOutputs); config->setScreen(m_screen->toKScreenScreen()); @@ -122,38 +127,45 @@ void XRandRConfig::applyKScreenConfig(const KScreen::ConfigPtr &config) { const KScreen::OutputList kscreenOutputs = config->outputs(); + const QSize newScreenSize = screenSize(config); const QSize currentScreenSize = m_screen->currentSize(); + // When the current screen configuration is bigger than the new size (like // when rotating an output), the XSetScreenSize can fail or apply the smaller // size only partially, because we apply the size (we have to) before the // output changes. To prevent all kinds of weird screen sizes from happening, // we initially set such screen size, that it can take the current as well // as the new configuration, then we apply the output changes, and finally then // (if necessary) we reduce the screen size to fix the new configuration precisely. - const QSize intermediateScreenSize = QSize(qMax(newScreenSize.width(), currentScreenSize.width()), - qMax(newScreenSize.height(), currentScreenSize.height())); + const QSize intermediateScreenSize = QSize(qMax(newScreenSize.width(), + currentScreenSize.width()), + qMax(newScreenSize.height(), + currentScreenSize.height())); + int neededCrtcs = 0; xcb_randr_output_t primaryOutput = 0; xcb_randr_output_t oldPrimaryOutput = 0; - Q_FOREACH (const XRandROutput *xrandrOutput, m_outputs) { + for (const XRandROutput *xrandrOutput : m_outputs) { if (xrandrOutput->isPrimary()) { oldPrimaryOutput = xrandrOutput->id(); break; } } KScreen::OutputList toDisable, toEnable, toChange; - Q_FOREACH(const KScreen::OutputPtr &kscreenOutput, kscreenOutputs) { + + for (const KScreen::OutputPtr &kscreenOutput : kscreenOutputs) { xcb_randr_output_t outputId = kscreenOutput->id(); XRandROutput *currentOutput = output(outputId); //Only set the output as primary if it is enabled. if (kscreenOutput->isPrimary() && kscreenOutput->isEnabled()) { primaryOutput = outputId; } const bool currentEnabled = currentOutput->isEnabled(); + if (!kscreenOutput->isEnabled() && currentEnabled) { toDisable.insert(outputId, kscreenOutput); continue; @@ -185,8 +197,8 @@ } } - XRandRMode *currentMode = currentOutput->modes().value(kscreenOutput->currentModeId().toInt()); - + XRandRMode *currentMode = currentOutput->modes().value( + kscreenOutput->currentModeId().toInt()); // For some reason, in some environments currentMode is null // which doesn't make sense because it is the *current* mode... // Since we haven't been able to figure out the reason why @@ -197,57 +209,66 @@ << "ModeId:" << currentOutput->currentModeId() << "Mode: " << currentOutput->currentMode() << "Output: " << currentOutput->id(); -// qDebug() << kRealBacktrace(256); printConfig(config); printInternalCond(); continue; } - // If the output would not fit into new screen size, we need to disable - // it and reposition it + // When the output would not fit into new screen size, we need to disable and reposition it. const QRect geom = kscreenOutput->geometry(); if (geom.right() > newScreenSize.width() || geom.bottom() > newScreenSize.height()) { if (!toDisable.contains(outputId)) { - qCDebug(KSCREEN_XRANDR) << "The new output would not fit into screen - new geometry: " << geom << ", new screen size:" << newScreenSize; + qCDebug(KSCREEN_XRANDR) + << "The new output would not fit into screen - new geometry: " << geom + << ", new screen size:" << newScreenSize; toDisable.insert(outputId, kscreenOutput); } } - } // Q_FOREACH (const KScreen::OutputPtr &kscreenOutput, kscreenOutputs) + } const KScreen::ScreenPtr kscreenScreen = config->screen(); if (newScreenSize.width() > kscreenScreen->maxSize().width() || newScreenSize.height() > kscreenScreen->maxSize().height()) { - qCDebug(KSCREEN_XRANDR) << "The new screen size is too big - requested: " << newScreenSize << ", maximum: " << kscreenScreen->maxSize(); + qCDebug(KSCREEN_XRANDR) << "The new screen size is too big - requested: " + << newScreenSize << ", maximum: " << kscreenScreen->maxSize(); return; } qCDebug(KSCREEN_XRANDR) << "Needed CRTCs: " << neededCrtcs; - XCB::ScopedPointer screenResources(XRandR::screenResources()); + + XCB::ScopedPointer + screenResources(XRandR::screenResources()); + if (neededCrtcs > screenResources->num_crtcs) { - qCDebug(KSCREEN_XRANDR) << "We need more CRTCs than we have available - requested: " << neededCrtcs << ", available: " << screenResources->num_crtcs; + qCDebug(KSCREEN_XRANDR) << "We need more CRTCs than we have available - requested: " + << neededCrtcs << ", available: " << screenResources->num_crtcs; return; } - qCDebug(KSCREEN_XRANDR) << "Actions to perform:"; - qCDebug(KSCREEN_XRANDR) << "\tPrimary Output:" << (primaryOutput != oldPrimaryOutput); + qCDebug(KSCREEN_XRANDR) << "Actions to perform:" << "\n" + << "\tPrimary Output:" << (primaryOutput != oldPrimaryOutput); if (primaryOutput != oldPrimaryOutput) { - qCDebug(KSCREEN_XRANDR) << "\t\tOld:" << oldPrimaryOutput; - qCDebug(KSCREEN_XRANDR) << "\t\tNew:" << primaryOutput; + qCDebug(KSCREEN_XRANDR) << "\t\tOld:" << oldPrimaryOutput << "\n" + << "\t\tNew:" << primaryOutput; } + qCDebug(KSCREEN_XRANDR) << "\tChange Screen Size:" << (newScreenSize != currentScreenSize); if (newScreenSize != currentScreenSize) { - qCDebug(KSCREEN_XRANDR) << "\t\tOld:" << currentScreenSize; - qCDebug(KSCREEN_XRANDR) << "\t\tIntermediate:" << intermediateScreenSize; - qCDebug(KSCREEN_XRANDR) << "\t\tNew:" << newScreenSize; + qCDebug(KSCREEN_XRANDR) << "\t\tOld:" << currentScreenSize << "\n" + << "\t\tIntermediate:" << intermediateScreenSize << "\n" + << "\t\tNew:" << newScreenSize; } + qCDebug(KSCREEN_XRANDR) << "\tDisable outputs:" << !toDisable.isEmpty(); if (!toDisable.isEmpty()) { qCDebug(KSCREEN_XRANDR) << "\t\t" << toDisable.keys(); } + qCDebug(KSCREEN_XRANDR) << "\tChange outputs:" << !toChange.isEmpty(); if (!toChange.isEmpty()) { qCDebug(KSCREEN_XRANDR) << "\t\t" << toChange.keys(); } + qCDebug(KSCREEN_XRANDR) << "\tEnable outputs:" << !toEnable.isEmpty(); if (!toEnable.isEmpty()) { qCDebug(KSCREEN_XRANDR) << "\t\t" << toEnable.keys(); @@ -258,23 +279,25 @@ XCB::GrabServer grabber; //If there is nothing to do, not even bother - if (oldPrimaryOutput == primaryOutput && toDisable.isEmpty() && toEnable.isEmpty() && toChange.isEmpty()) { + if (oldPrimaryOutput == primaryOutput && toDisable.isEmpty() && + toEnable.isEmpty() && toChange.isEmpty()) { if (newScreenSize != currentScreenSize) { setScreenSize(newScreenSize); } return; } - Q_FOREACH(const KScreen::OutputPtr &output, toDisable) { + for (const KScreen::OutputPtr &output : toDisable) { disableOutput(output); } if (intermediateScreenSize != currentScreenSize) { setScreenSize(intermediateScreenSize); } bool forceScreenSizeUpdate = false; - Q_FOREACH(const KScreen::OutputPtr &output, toChange) { + + for (const KScreen::OutputPtr &output : toChange) { if (!changeOutput(output)) { /* If we disabled the output before changing it and XRandR failed * to re-enable it, then update screen size too */ @@ -286,7 +309,7 @@ } } - Q_FOREACH(const KScreen::OutputPtr &output, toEnable) { + for (const KScreen::OutputPtr &output : toEnable) { if (!enableOutput(output)) { //output->setEnabled(false); qCDebug(KSCREEN_XRANDR) << "Output failed to be Enabled: " << output->name(); @@ -321,60 +344,63 @@ return; } - qCDebug(KSCREEN_XRANDR) << "Screen:"; - qCDebug(KSCREEN_XRANDR) << "\tmaxSize:" << config->screen()->maxSize(); - qCDebug(KSCREEN_XRANDR) << "\tminSize:" << config->screen()->minSize(); - qCDebug(KSCREEN_XRANDR) << "\tcurrentSize:" << config->screen()->currentSize(); + qCDebug(KSCREEN_XRANDR) << "Screen:" << "\n" + << "\tmaxSize:" << config->screen()->maxSize() << "\n" + << "\tminSize:" << config->screen()->minSize() << "\n" + << "\tcurrentSize:" << config->screen()->currentSize(); + + const OutputList outputs = config->outputs(); + for (const OutputPtr &output : outputs) { + qCDebug(KSCREEN_XRANDR) << "\n-----------------------------------------------------\n" << "\n" + << "Id: " << output->id() << "\n" + << "Name: " << output->name() << "\n" + << "Type: " << output->type() << "\n" + << "Connected: " << output->isConnected(); - OutputList outputs = config->outputs(); - Q_FOREACH(const OutputPtr &output, outputs) { - qCDebug(KSCREEN_XRANDR) << "\n-----------------------------------------------------\n"; - qCDebug(KSCREEN_XRANDR) << "Id: " << output->id(); - qCDebug(KSCREEN_XRANDR) << "Name: " << output->name(); - qCDebug(KSCREEN_XRANDR) << "Type: " << output->type(); - qCDebug(KSCREEN_XRANDR) << "Connected: " << output->isConnected(); if (!output->isConnected()) { continue; } - qCDebug(KSCREEN_XRANDR) << "Enabled: " << output->isEnabled(); - qCDebug(KSCREEN_XRANDR) << "Primary: " << output->isPrimary(); - qCDebug(KSCREEN_XRANDR) << "Rotation: " << output->rotation(); - qCDebug(KSCREEN_XRANDR) << "Pos: " << output->pos(); - qCDebug(KSCREEN_XRANDR) << "MMSize: " << output->sizeMm(); + + qCDebug(KSCREEN_XRANDR) << "Enabled: " << output->isEnabled() << "\n" + << "Primary: " << output->isPrimary() << "\n" + << "Rotation: " << output->rotation() << "\n" + << "Pos: " << output->pos() << "\n" + << "MMSize: " << output->sizeMm(); if (output->currentMode()) { qCDebug(KSCREEN_XRANDR) << "Size: " << output->currentMode()->size(); } - if (output->clones().isEmpty()) { - qCDebug(KSCREEN_XRANDR) << "Clones: " << "None"; - } else { - qCDebug(KSCREEN_XRANDR) << "Clones: " << output->clones().count(); - } - qCDebug(KSCREEN_XRANDR) << "Mode: " << output->currentModeId(); - qCDebug(KSCREEN_XRANDR) << "Preferred Mode: " << output->preferredModeId(); - qCDebug(KSCREEN_XRANDR) << "Preferred modes: " << output->preferredModes(); - qCDebug(KSCREEN_XRANDR) << "Modes: "; + + qCDebug(KSCREEN_XRANDR) << "Clones: " + << (output->clones().isEmpty() ? QStringLiteral("None") : + QString::number(output->clones().count())) + << "\n" + << "Mode: " << output->currentModeId() << "\n" + << "Preferred Mode: " << output->preferredModeId() << "\n" + << "Preferred modes: " << output->preferredModes() << "\n" + << "Modes: "; ModeList modes = output->modes(); - Q_FOREACH(const ModePtr &mode, modes) { - qCDebug(KSCREEN_XRANDR) << "\t" << mode->id() << " " << mode->name() << " " << mode->size() << " " << mode->refreshRate(); + for (const ModePtr &mode : modes) { + qCDebug(KSCREEN_XRANDR) << "\t" << mode->id() << " " << mode->name() << " " + << mode->size() << " " << mode->refreshRate(); } Edid* edid = output->edid(); qCDebug(KSCREEN_XRANDR) << "EDID Info: "; if (edid && edid->isValid()) { - qCDebug(KSCREEN_XRANDR) << "\tDevice ID: " << edid->deviceId(); - qCDebug(KSCREEN_XRANDR) << "\tName: " << edid->name(); - qCDebug(KSCREEN_XRANDR) << "\tVendor: " << edid->vendor(); - qCDebug(KSCREEN_XRANDR) << "\tSerial: " << edid->serial(); - qCDebug(KSCREEN_XRANDR) << "\tEISA ID: " << edid->eisaId(); - qCDebug(KSCREEN_XRANDR) << "\tHash: " << edid->hash(); - qCDebug(KSCREEN_XRANDR) << "\tWidth: " << edid->width(); - qCDebug(KSCREEN_XRANDR) << "\tHeight: " << edid->height(); - qCDebug(KSCREEN_XRANDR) << "\tGamma: " << edid->gamma(); - qCDebug(KSCREEN_XRANDR) << "\tRed: " << edid->red(); - qCDebug(KSCREEN_XRANDR) << "\tGreen: " << edid->green(); - qCDebug(KSCREEN_XRANDR) << "\tBlue: " << edid->blue(); - qCDebug(KSCREEN_XRANDR) << "\tWhite: " << edid->white(); + qCDebug(KSCREEN_XRANDR) << "\tDevice ID: " << edid->deviceId() << "\n" + << "\tName: " << edid->name() << "\n" + << "\tVendor: " << edid->vendor() << "\n" + << "\tSerial: " << edid->serial() << "\n" + << "\tEISA ID: " << edid->eisaId() << "\n" + << "\tHash: " << edid->hash() << "\n" + << "\tWidth: " << edid->width() << "\n" + << "\tHeight: " << edid->height() << "\n" + << "\tGamma: " << edid->gamma() << "\n" + << "\tRed: " << edid->red() << "\n" + << "\tGreen: " << edid->green() << "\n" + << "\tBlue: " << edid->blue() << "\n" + << "\tWhite: " << edid->white(); } else { qCDebug(KSCREEN_XRANDR) << "\tUnavailable"; } @@ -384,29 +410,30 @@ void XRandRConfig::printInternalCond() const { qCDebug(KSCREEN_XRANDR) << "Internal config in xrandr"; - Q_FOREACH(XRandROutput *output, m_outputs) { - qCDebug(KSCREEN_XRANDR) << "Id: " << output->id(); - qCDebug(KSCREEN_XRANDR) << "Current Mode: " << output->currentMode(); - qCDebug(KSCREEN_XRANDR) << "Current mode id: " << output->currentModeId(); - qCDebug(KSCREEN_XRANDR) << "Connected: " << output->isConnected(); - qCDebug(KSCREEN_XRANDR) << "Enabled: " << output->isEnabled(); - qCDebug(KSCREEN_XRANDR) << "Primary: " << output->isPrimary(); + for (const XRandROutput *output : m_outputs) { + qCDebug(KSCREEN_XRANDR) << "Id: " << output->id() << "\n" + << "Current Mode: " << output->currentMode() << "\n" + << "Current mode id: " << output->currentModeId() << "\n" + << "Connected: " << output->isConnected() << "\n" + << "Enabled: " << output->isEnabled() << "\n" + << "Primary: " << output->isPrimary(); if (!output->isEnabled()) { continue; } + XRandRMode::Map modes = output->modes(); - Q_FOREACH(XRandRMode *mode, modes) { - qCDebug(KSCREEN_XRANDR) << "\t" << mode->id(); - qCDebug(KSCREEN_XRANDR) << "\t" << mode->name(); - qCDebug(KSCREEN_XRANDR) << "\t" << mode->size() << mode->refreshRate(); + for (const XRandRMode *mode : modes) { + qCDebug(KSCREEN_XRANDR) << "\t" << mode->id() << "\n" + << "\t" << mode->name() << "\n" + << "\t" << mode->size() << mode->refreshRate(); } } } QSize XRandRConfig::screenSize(const KScreen::ConfigPtr &config) const { QRect rect; - Q_FOREACH(const KScreen::OutputPtr &output, config->outputs()) { + for (const KScreen::OutputPtr &output : config->outputs()) { if (!output->isConnected() || !output->isEnabled()) { continue; } @@ -428,14 +455,15 @@ bool XRandRConfig::setScreenSize(const QSize &size) const { - const double dpi = (25.4 * XRandR::screen()->height_in_pixels / XRandR::screen()->height_in_millimeters); - const int widthMM = ((25.4 * size.width()) / dpi); - const int heightMM = ((25.4 * size.height()) / dpi); + const double dpi = 25.4 * XRandR::screen()->height_in_pixels + / XRandR::screen()->height_in_millimeters; + const int widthMM = (25.4 * size.width()) / dpi; + const int heightMM = (25.4 * size.height()) / dpi; - qCDebug(KSCREEN_XRANDR) << "RRSetScreenSize"; - qCDebug(KSCREEN_XRANDR) << "\tDPI:" << dpi; - qCDebug(KSCREEN_XRANDR) << "\tSize:" << size; - qCDebug(KSCREEN_XRANDR) << "\tSizeMM:" << QSize(widthMM, heightMM); + qCDebug(KSCREEN_XRANDR) << "RRSetScreenSize" << "\n" + << "\tDPI:" << dpi << "\n" + << "\tSize:" << size << "\n" + << "\tSizeMM:" << QSize(widthMM, heightMM); xcb_randr_set_screen_size(XCB::connection(), XRandR::rootWindow(), size.width(), size.height(), widthMM, heightMM); @@ -445,8 +473,8 @@ void XRandRConfig::setPrimaryOutput(xcb_randr_output_t outputId) const { - qCDebug(KSCREEN_XRANDR) << "RRSetOutputPrimary"; - qCDebug(KSCREEN_XRANDR) << "\tNew primary:" << outputId; + qCDebug(KSCREEN_XRANDR) << "RRSetOutputPrimary" << "\n" + << "\tNew primary:" << outputId; xcb_randr_set_output_primary(XCB::connection(), XRandR::rootWindow(), outputId); for (XRandROutput *output : m_outputs) { @@ -459,23 +487,27 @@ XRandROutput *xOutput = output(kscreenOutput->id()); Q_ASSERT(xOutput); Q_ASSERT(xOutput->crtc()); + if (!xOutput->crtc()) { qCWarning(KSCREEN_XRANDR) << "Attempting to disable output without CRTC, wth?"; return false; } const xcb_randr_crtc_t crtc = xOutput->crtc()->crtc(); - qCDebug(KSCREEN_XRANDR) << "RRSetCrtcConfig (disable output)"; - qCDebug(KSCREEN_XRANDR) << "\tCRTC:" << crtc; + qCDebug(KSCREEN_XRANDR) << "RRSetCrtcConfig (disable output)" << "\n" + << "\tCRTC:" << crtc; auto cookie = xcb_randr_set_crtc_config(XCB::connection(), crtc, XCB_CURRENT_TIME, XCB_CURRENT_TIME, 0, 0, XCB_NONE, XCB_RANDR_ROTATION_ROTATE_0, 0, nullptr); - XCB::ScopedPointer reply(xcb_randr_set_crtc_config_reply(XCB::connection(), cookie, nullptr)); + + XCB::ScopedPointer + reply(xcb_randr_set_crtc_config_reply(XCB::connection(), cookie, nullptr)); + if (!reply) { qCDebug(KSCREEN_XRANDR) << "\tResult: unknown (error)"; return false; @@ -485,7 +517,9 @@ // Update the cached output now, otherwise we get RRNotify_CrtcChange notification // for an outdated output, which can lead to a crash. if (reply->status == XCB_RANDR_SET_CONFIG_SUCCESS) { - xOutput->update(XCB_NONE, XCB_NONE, xOutput->isConnected() ? XCB_RANDR_CONNECTION_CONNECTED : XCB_RANDR_CONNECTION_DISCONNECTED, + xOutput->update(XCB_NONE, XCB_NONE, + xOutput->isConnected() ? XCB_RANDR_CONNECTION_CONNECTED : + XCB_RANDR_CONNECTION_DISCONNECTED, kscreenOutput->isPrimary()); } return (reply->status == XCB_RANDR_SET_CONFIG_SUCCESS); @@ -497,50 +531,59 @@ XRandRCrtc *freeCrtc = nullptr; qCDebug(KSCREEN_XRANDR) << m_crtcs; - Q_FOREACH (XRandRCrtc *crtc, m_crtcs) { + + for (XRandRCrtc *crtc : m_crtcs) { crtc->update(); - qCDebug(KSCREEN_XRANDR) << "Testing CRTC" << crtc->crtc(); - qCDebug(KSCREEN_XRANDR) << "\tFree:" << crtc->isFree(); - qCDebug(KSCREEN_XRANDR) << "\tMode:" << crtc->mode(); - qCDebug(KSCREEN_XRANDR) << "\tPossible outputs:" << crtc->possibleOutputs(); - qCDebug(KSCREEN_XRANDR) << "\tConnected outputs:" << crtc->outputs(); - qCDebug(KSCREEN_XRANDR) << "\tGeometry:" << crtc->geometry(); + qCDebug(KSCREEN_XRANDR) << "Testing CRTC" << crtc->crtc() << "\n" + << "\tFree:" << crtc->isFree() << "\n" + << "\tMode:" << crtc->mode() << "\n" + << "\tPossible outputs:" << crtc->possibleOutputs() << "\n" + << "\tConnected outputs:" << crtc->outputs() << "\n" + << "\tGeometry:" << crtc->geometry(); + if (crtc->isFree() && crtc->possibleOutputs().contains(kscreenOutput->id())) { freeCrtc = crtc; break; } } + if (!freeCrtc) { qCWarning(KSCREEN_XRANDR) << "Failed to get free CRTC for output" << kscreenOutput->id(); return false; } - const int modeId = kscreenOutput->currentMode() ? kscreenOutput->currentModeId().toInt() : kscreenOutput->preferredModeId().toInt(); + const int modeId = kscreenOutput->currentMode() ? kscreenOutput->currentModeId().toInt() : + kscreenOutput->preferredModeId().toInt(); - qCDebug(KSCREEN_XRANDR) << "RRSetCrtcConfig (enable output)"; - qCDebug(KSCREEN_XRANDR) << "\tOutput:" << kscreenOutput->id() << "(" << kscreenOutput->name() << ")"; - qCDebug(KSCREEN_XRANDR) << "\tNew CRTC:" << freeCrtc->crtc(); - qCDebug(KSCREEN_XRANDR) << "\tPos:" << kscreenOutput->pos(); - qCDebug(KSCREEN_XRANDR) << "\tMode:" << kscreenOutput->currentMode() << "Preferred:" << kscreenOutput->preferredModeId(); - qCDebug(KSCREEN_XRANDR) << "\tRotation:" << kscreenOutput->rotation(); + qCDebug(KSCREEN_XRANDR) << "RRSetCrtcConfig (enable output)" << "\n" + << "\tOutput:" << kscreenOutput->id() << "(" << kscreenOutput->name() + << ")" << "\n" + << "\tNew CRTC:" << freeCrtc->crtc() << "\n" + << "\tPos:" << kscreenOutput->pos() << "\n" + << "\tMode:" << kscreenOutput->currentMode() + << "Preferred:" << kscreenOutput->preferredModeId() << "\n" + << "\tRotation:" << kscreenOutput->rotation(); auto cookie = xcb_randr_set_crtc_config(XCB::connection(), freeCrtc->crtc(), XCB_CURRENT_TIME, XCB_CURRENT_TIME, kscreenOutput->pos().rx(), kscreenOutput->pos().ry(), modeId, kscreenOutput->rotation(), 1, outputs); - XCB::ScopedPointer reply(xcb_randr_set_crtc_config_reply(XCB::connection(), cookie, nullptr)); + + XCB::ScopedPointer + reply(xcb_randr_set_crtc_config_reply(XCB::connection(), cookie, nullptr)); + if (!reply) { qCDebug(KSCREEN_XRANDR) << "Result: unknown (error)"; return false; } qCDebug(KSCREEN_XRANDR) << "\tResult:" << reply->status; if (reply->status == XCB_RANDR_SET_CONFIG_SUCCESS) { XRandROutput *xOutput = output(kscreenOutput->id()); - xOutput->update(freeCrtc->crtc(), modeId, - XCB_RANDR_CONNECTION_CONNECTED, kscreenOutput->isPrimary()); + xOutput->update(freeCrtc->crtc(), modeId, XCB_RANDR_CONNECTION_CONNECTED, + kscreenOutput->isPrimary()); } return (reply->status == XCB_RANDR_SET_CONFIG_SUCCESS); } @@ -550,18 +593,21 @@ XRandROutput *xOutput = output(kscreenOutput->id()); Q_ASSERT(xOutput); if (!xOutput->crtc()) { - qCDebug(KSCREEN_XRANDR) << "Output" << kscreenOutput->id() << "has no CRTC, falling back to enableOutput()"; + qCDebug(KSCREEN_XRANDR) << "Output" << kscreenOutput->id() + << "has no CRTC, falling back to enableOutput()"; return enableOutput(kscreenOutput); } - int modeId = kscreenOutput->currentMode() ? kscreenOutput->currentModeId().toInt() : kscreenOutput->preferredModeId().toInt(); + int modeId = kscreenOutput->currentMode() ? kscreenOutput->currentModeId().toInt() : + kscreenOutput->preferredModeId().toInt(); - qCDebug(KSCREEN_XRANDR) << "RRSetCrtcConfig (change output)"; - qCDebug(KSCREEN_XRANDR) << "\tOutput:" << kscreenOutput->id() << "(" << kscreenOutput->name() << ")"; - qCDebug(KSCREEN_XRANDR) << "\tCRTC:" << xOutput->crtc()->crtc(); - qCDebug(KSCREEN_XRANDR) << "\tPos:" << kscreenOutput->pos(); - qCDebug(KSCREEN_XRANDR) << "\tMode:" << modeId << kscreenOutput->currentMode(); - qCDebug(KSCREEN_XRANDR) << "\tRotation:" << kscreenOutput->rotation(); + qCDebug(KSCREEN_XRANDR) << "RRSetCrtcConfig (change output)" << "\n" + << "\tOutput:" << kscreenOutput->id() << "(" << kscreenOutput->name() + << ")" << "\n" + << "\tCRTC:" << xOutput->crtc()->crtc() << "\n" + << "\tPos:" << kscreenOutput->pos() << "\n" + << "\tMode:" << modeId << kscreenOutput->currentMode() << "\n" + << "\tRotation:" << kscreenOutput->rotation(); xcb_randr_output_t outputs[1] { static_cast(kscreenOutput->id()) }; @@ -571,7 +617,10 @@ modeId, kscreenOutput->rotation(), 1, outputs); - XCB::ScopedPointer reply(xcb_randr_set_crtc_config_reply(XCB::connection(), cookie, nullptr)); + + XCB::ScopedPointer + reply(xcb_randr_set_crtc_config_reply(XCB::connection(), cookie, nullptr)); + if (!reply) { qCDebug(KSCREEN_XRANDR) << "\tResult: unknown (error)"; return false; diff --git a/backends/xrandr/xrandrcrtc.h b/backends/xrandr/xrandrcrtc.h --- a/backends/xrandr/xrandrcrtc.h +++ b/backends/xrandr/xrandrcrtc.h @@ -18,14 +18,12 @@ * along with this program. If not, see . * */ +#pragma once -#ifndef XRANDRCRTC_H -#define XRANDRCRTC_H - +#include #include #include #include -#include #include @@ -43,8 +41,10 @@ xcb_randr_crtc_t crtc() const; xcb_randr_mode_t mode() const; - xcb_randr_rotation_t rotation() const; + QRect geometry() const; + xcb_randr_rotation_t rotation() const; + QVector possibleOutputs(); QVector outputs() const; @@ -59,10 +59,10 @@ private: xcb_randr_crtc_t m_crtc; xcb_randr_mode_t m_mode; - xcb_randr_rotation_t m_rotation; + QRect m_geometry; + xcb_randr_rotation_t m_rotation; + QVector m_possibleOutputs; QVector m_outputs; }; - -#endif // XRANDRCRTC_H diff --git a/backends/xrandr/xrandrcrtc.cpp b/backends/xrandr/xrandrcrtc.cpp --- a/backends/xrandr/xrandrcrtc.cpp +++ b/backends/xrandr/xrandrcrtc.cpp @@ -18,10 +18,10 @@ * along with this program. If not, see . * */ - #include "xrandrcrtc.h" -#include "xrandrconfig.h" + #include "xrandr.h" +#include "xrandrconfig.h" #include "../xcbwrapper.h" @@ -68,8 +68,10 @@ { update(); qCDebug(KSCREEN_XRANDR) << "Connected output" << output << "to CRTC" << m_crtc; + if (!m_possibleOutputs.contains(output)) { - qCDebug(KSCREEN_XRANDR) << "Output" << output << "is not an allowed output for CRTC" << m_crtc; + qCDebug(KSCREEN_XRANDR) << "Output" << output + << "is not an allowed output for CRTC" << m_crtc; return false; } @@ -83,6 +85,7 @@ { update(); qCDebug(KSCREEN_XRANDR) << "Disconnected output" << output << "from CRTC" << m_crtc; + const int index = m_outputs.indexOf(output); if (index > -1) { m_outputs.remove(index); @@ -98,10 +101,13 @@ { XCB::CRTCInfo crtcInfo(m_crtc, XCB_TIME_CURRENT_TIME); m_mode = crtcInfo->mode; - m_rotation = (xcb_randr_rotation_t) crtcInfo->rotation; + m_geometry = QRect(crtcInfo->x, crtcInfo->y, crtcInfo->width, crtcInfo->height); + m_rotation = (xcb_randr_rotation_t) crtcInfo->rotation; + m_possibleOutputs.clear(); m_possibleOutputs.reserve(crtcInfo->num_possible_outputs); + xcb_randr_output_t *possible = xcb_randr_get_crtc_info_possible(crtcInfo); for (int i = 0; i < crtcInfo->num_possible_outputs; ++i) { m_possibleOutputs.append(possible[i]); @@ -117,7 +123,7 @@ void XRandRCrtc::update(xcb_randr_mode_t mode, xcb_randr_rotation_t rotation, const QRect &geom) { m_mode = mode; - m_rotation = rotation; m_geometry = geom; + m_rotation = rotation; } diff --git a/backends/xrandr/xrandrmode.h b/backends/xrandr/xrandrmode.h --- a/backends/xrandr/xrandrmode.h +++ b/backends/xrandr/xrandrmode.h @@ -15,9 +15,7 @@ * License along with this library; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *************************************************************************************/ - -#ifndef XRANDRMODE_H -#define XRANDRMODE_H +#pragma once #include #include @@ -59,5 +57,3 @@ }; Q_DECLARE_METATYPE(XRandRMode::Map) - -#endif // XRANDRMODE_H diff --git a/backends/xrandr/xrandrmode.cpp b/backends/xrandr/xrandrmode.cpp --- a/backends/xrandr/xrandrmode.cpp +++ b/backends/xrandr/xrandrmode.cpp @@ -15,23 +15,23 @@ * License along with this library; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *************************************************************************************/ - #include "xrandrmode.h" -#include "xrandroutput.h" + #include "mode.h" #include "output.h" +#include "xrandroutput.h" XRandRMode::XRandRMode(const xcb_randr_mode_info_t &modeInfo, XRandROutput *output) : QObject(output) { m_id = modeInfo.id; // FIXME XCB //m_name = QString::fromUtf8(modeInfo->name); m_size = QSize(modeInfo.width, modeInfo.height); - m_refreshRate = ((float) modeInfo.dot_clock / ((float) modeInfo.htotal * (float) modeInfo.vtotal)); + m_refreshRate = (float) modeInfo.dot_clock + / ((float) modeInfo.htotal * (float) modeInfo.vtotal); } - XRandRMode::~XRandRMode() { } diff --git a/backends/xrandr/xrandroutput.h b/backends/xrandr/xrandroutput.h --- a/backends/xrandr/xrandroutput.h +++ b/backends/xrandr/xrandroutput.h @@ -15,18 +15,17 @@ * License along with this library; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *************************************************************************************/ +#pragma once -#ifndef XRANDROUTPUT_H -#define XRANDROUTPUT_H +#include "output.h" + +#include "xrandrmode.h" +#include "../xcbwrapper.h" #include #include #include -#include "xrandrmode.h" -#include "output.h" -#include "../xcbwrapper.h" - class XRandRConfig; class XRandRCrtc; namespace KScreen @@ -49,21 +48,27 @@ void disconnected(); void update(); - void update(xcb_randr_crtc_t crtc, xcb_randr_mode_t mode, xcb_randr_connection_t conn, bool primary); + void update(xcb_randr_crtc_t crtc, xcb_randr_mode_t mode, xcb_randr_connection_t conn, + bool primary); void setIsPrimary(bool primary); xcb_randr_output_t id() const; + bool isEnabled() const; bool isConnected() const; bool isPrimary() const; + QPoint position() const; QSize size() const; + QString currentModeId() const; XRandRMode::Map modes() const; XRandRMode* currentMode() const; + KScreen::Output::Rotation rotation() const; bool isHorizontal() const; + QByteArray edid() const; XRandRCrtc* crtc() const; @@ -79,20 +84,23 @@ XRandRConfig *m_config; xcb_randr_output_t m_id; QString m_name; + QString m_icon; + mutable QByteArray m_edid; + xcb_randr_connection_t m_connected; + bool m_primary; KScreen::Output::Type m_type; - QString m_icon; + XRandRMode::Map m_modes; QStringList m_preferredModes; - bool m_primary; + QList m_clones; - mutable QByteArray m_edid; + unsigned int m_widthMm; unsigned int m_heightMm; + bool m_hotplugModeUpdate = false; XRandRCrtc *m_crtc; }; Q_DECLARE_METATYPE(XRandROutput::Map) - -#endif // XRANDROUTPUT_H diff --git a/backends/xrandr/xrandroutput.cpp b/backends/xrandr/xrandroutput.cpp --- a/backends/xrandr/xrandroutput.cpp +++ b/backends/xrandr/xrandroutput.cpp @@ -16,25 +16,22 @@ * License along with this library; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *************************************************************************************/ - #include "xrandroutput.h" -#include "xrandrmode.h" -#include "xrandrconfig.h" -#include "xrandr.h" -#include "output.h" + #include "config.h" +#include "xrandr.h" +#include "xrandrconfig.h" +#include "xrandrmode.h" #include "../utils.h" -#include - Q_DECLARE_METATYPE(QList) XRandROutput::XRandROutput(xcb_randr_output_t id, XRandRConfig *config) : QObject(config) , m_config(config) , m_id(id) - , m_type(KScreen::Output::Unknown) , m_primary(false) + , m_type(KScreen::Output::Unknown) , m_crtc(nullptr) { init(); @@ -89,6 +86,7 @@ if (!m_crtc) { return nullptr; } + unsigned int modeId = m_crtc->mode(); if (!m_modes.contains(modeId)) { return nullptr; @@ -99,7 +97,8 @@ KScreen::Output::Rotation XRandROutput::rotation() const { - return static_cast(m_crtc ? m_crtc->rotation() : XCB_RANDR_ROTATION_ROTATE_0); + return static_cast(m_crtc ? m_crtc->rotation() : + XCB_RANDR_ROTATION_ROTATE_0); } QByteArray XRandROutput::edid() const @@ -120,15 +119,16 @@ init(); } -void XRandROutput::update(xcb_randr_crtc_t crtc, xcb_randr_mode_t mode, xcb_randr_connection_t conn, bool primary) +void XRandROutput::update(xcb_randr_crtc_t crtc, xcb_randr_mode_t mode, xcb_randr_connection_t conn, + bool primary) { - qCDebug(KSCREEN_XRANDR) << "XRandROutput" << m_id << "update"; - qCDebug(KSCREEN_XRANDR) << "\tm_connected:" << m_connected; - qCDebug(KSCREEN_XRANDR) << "\tm_crtc" << m_crtc; - qCDebug(KSCREEN_XRANDR) << "\tCRTC:" << crtc; - qCDebug(KSCREEN_XRANDR) << "\tMODE:" << mode; - qCDebug(KSCREEN_XRANDR) << "\tConnection:" << conn; - qCDebug(KSCREEN_XRANDR) << "\tPrimary:" << primary; + qCDebug(KSCREEN_XRANDR) << "XRandROutput" << m_id << "update" << "\n" + << "\tm_connected:" << m_connected << "\n" + << "\tm_crtc" << m_crtc << "\n" + << "\tCRTC:" << crtc << "\n" + << "\tMODE:" << mode << "\n" + << "\tConnection:" << conn << "\n" + << "\tPrimary:" << primary; // Connected or disconnected if (isConnected() != (conn == XCB_RANDR_CONNECTION_CONNECTED)) { @@ -194,17 +194,21 @@ XCB::PrimaryOutput primary(XRandR::rootWindow()); - m_name = QString::fromUtf8((const char *) xcb_randr_get_output_info_name(outputInfo.data()), outputInfo->name_len); + m_name = QString::fromUtf8((const char *) xcb_randr_get_output_info_name(outputInfo.data()), + outputInfo->name_len); m_type = fetchOutputType(m_id, m_name); m_icon = QString(); m_connected = (xcb_randr_connection_t) outputInfo->connection; m_primary = (primary->output == m_id); + xcb_randr_output_t *clones = xcb_randr_get_output_info_clones(outputInfo.data()); for (int i = 0; i < outputInfo->num_clones; ++i) { m_clones.append(clones[i]); } + m_widthMm = outputInfo->mm_width; m_heightMm = outputInfo->mm_height; + m_crtc = m_config->crtc(outputInfo->crtc); if (m_crtc) { m_crtc->connectOutput(m_id); @@ -217,7 +221,9 @@ void XRandROutput::updateModes(const XCB::OutputInfo &outputInfo) { /* Init modes */ - XCB::ScopedPointer screenResources(XRandR::screenResources()); + XCB::ScopedPointer + screenResources(XRandR::screenResources()); + Q_ASSERT(screenResources); if (!screenResources) { return; @@ -247,7 +253,8 @@ } } -KScreen::Output::Type XRandROutput::fetchOutputType(xcb_randr_output_t outputId, const QString &name) +KScreen::Output::Type XRandROutput::fetchOutputType(xcb_randr_output_t outputId, + const QString &name) { QString type = QString::fromUtf8(typeFromProperty(outputId)); if (type.isEmpty()) { @@ -266,11 +273,10 @@ return type; } - char *connectorType; - auto cookie = xcb_randr_get_output_property(XCB::connection(), outputId, atomType->atom, XCB_ATOM_ANY, 0, 100, false, false); - XCB::ScopedPointer reply(xcb_randr_get_output_property_reply(XCB::connection(), cookie, nullptr)); + XCB::ScopedPointer + reply(xcb_randr_get_output_property_reply(XCB::connection(), cookie, nullptr)); if (!reply) { return type; } @@ -285,7 +291,7 @@ return type; } - connectorType = xcb_get_atom_name_name(atomName); + char *connectorType = xcb_get_atom_name_name(atomName); if (!connectorType) { return type; } diff --git a/backends/xrandr/xrandrscreen.h b/backends/xrandr/xrandrscreen.h --- a/backends/xrandr/xrandrscreen.h +++ b/backends/xrandr/xrandrscreen.h @@ -15,15 +15,13 @@ * License along with this library; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *************************************************************************************/ +#pragma once -#ifndef XRANDRSCREEN_H -#define XRANDRSCREEN_H +#include "types.h" #include #include -#include "types.h" - class XRandRConfig; namespace KScreen { @@ -52,5 +50,3 @@ QSize m_maxSize; QSize m_currentSize; }; - -#endif // XRANDRSCREEN_H diff --git a/backends/xrandr/xrandrscreen.cpp b/backends/xrandr/xrandrscreen.cpp --- a/backends/xrandr/xrandrscreen.cpp +++ b/backends/xrandr/xrandrscreen.cpp @@ -16,16 +16,15 @@ * License along with this library; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *************************************************************************************/ - #include "xrandrscreen.h" -#include "xrandrconfig.h" -#include "screen.h" + #include "config.h" +#include "screen.h" +#include "xrandrconfig.h" +#include "../xcbwrapper.h" #include -#include "../xcbwrapper.h" - XRandRScreen::XRandRScreen(XRandRConfig *config) : QObject(config) { @@ -63,7 +62,8 @@ kscreenScreen->setMinSize(m_minSize); kscreenScreen->setCurrentSize(m_currentSize); - XCB::ScopedPointer screenResources(XRandR::screenResources()); + XCB::ScopedPointer + screenResources(XRandR::screenResources()); kscreenScreen->setMaxActiveOutputsCount(screenResources->num_crtcs); return kscreenScreen;