feat(screen): expose the recommended resolution and scale

pull/18/head
reionwong 1 month ago
parent 9c1fd8781b
commit 1b7ed0926b

@ -15,7 +15,7 @@ Adapted for Cutefish: a versioned session D-Bus interface without Ash or Mojo.
<method name="GetState">
<arg name="instanceId" type="s" direction="out"/><arg name="seatId" type="s" direction="out"/>
<arg name="topologyGeneration" type="t" direction="out"/><arg name="appliedRevision" type="t" direction="out"/>
<arg name="physicalDisplays" type="a(sssssssasssiiuuua(iiiiiiubbs))" direction="out"/>
<arg name="physicalDisplays" type="a(sssssssasssiiuuuua(iiiiiiubbs))" direction="out"/>
<arg name="logicalDisplays" type="a(ssasiiiiiiiiuub)" direction="out"/><arg name="placements" type="a(ssui)" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out4" value="QList&lt;cutefish::display::ipc::PhysicalDisplay&gt;"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out5" value="QList&lt;cutefish::display::ipc::LogicalDisplay&gt;"/>

@ -41,11 +41,11 @@ WRITE(PhysicalDisplay, << v.sessionId << v.persistentKey << v.portKey << v.edidK
<< v.connectorName << v.devicePath << v.baseConnectorKey << v.pathTopology
<< v.make << v.model << v.serialNumber << v.physicalWidthMm
<< v.physicalHeightMm << v.connectionType << v.panelOrientation
<< v.capabilities << v.modes)
<< v.capabilities << v.recommendedScale120 << v.modes)
READ(PhysicalDisplay, >> v.sessionId >> v.persistentKey >> v.portKey >> v.edidKey >> v.connectorName
>> v.devicePath >> v.baseConnectorKey >> v.pathTopology >> v.make >> v.model
>> v.serialNumber >> v.physicalWidthMm >> v.physicalHeightMm >> v.connectionType
>> v.panelOrientation >> v.capabilities >> v.modes)
>> v.panelOrientation >> v.capabilities >> v.recommendedScale120 >> v.modes)
WRITE(LogicalDisplay, << v.id << v.waylandName << v.destinations << v.x << v.y << v.width
<< v.height << v.workX << v.workY << v.workWidth << v.workHeight << v.scale120
<< v.rotation << v.primary)

@ -59,6 +59,7 @@ struct PhysicalDisplay {
uint connectionType = 0;
uint panelOrientation = 0;
uint capabilities = 0;
uint recommendedScale120 = 120;
QList<Mode> modes;
};

@ -129,6 +129,19 @@ QVariant DisplayOutputModel::data(const QModelIndex &index, int role) const
return i;
}
return 0;
case RecommendedResolutionIndexRole:
// The display's preferred mode, the one the compositor starts it in.
for (int i = 0; i < resolutions.size(); ++i) {
const auto &m = e.physical.modes.at(resolutions.at(i));
for (const auto &preferred : e.physical.modes) {
if (preferred.preferred && m.width == preferred.width
&& m.height == preferred.height)
return i;
}
}
return -1;
case RecommendedScaleRole:
return e.physical.recommendedScale120 / 120.0;
case ResolutionsRole: {
QStringList v;
for (int i : resolutions) {
@ -343,7 +356,9 @@ QHash<int, QByteArray> DisplayOutputModel::roleNames() const
{IdRole, "displayId"},
{CapabilitiesRole, "capabilities"},
{SupportedScalesRole, "supportedScales"},
{DrmConnectorRole, "drmConnector"}};
{DrmConnectorRole, "drmConnector"},
{RecommendedResolutionIndexRole, "recommendedResolutionIndex"},
{RecommendedScaleRole, "recommendedScale"}};
}
void DisplayOutputModel::setState(const DisplayClient::State &state)

@ -41,7 +41,9 @@ public:
IdRole,
CapabilitiesRole,
SupportedScalesRole,
DrmConnectorRole
DrmConnectorRole,
RecommendedResolutionIndexRole,
RecommendedScaleRole
};
explicit DisplayOutputModel(QObject *parent = nullptr);

@ -92,6 +92,35 @@ private slots:
QVERIFY(!edit);
}
void recommendationsFollowTheCompositor()
{
DisplayClient::State state;
cutefish::display::ipc::PhysicalDisplay physical;
physical.sessionId = QStringLiteral("0");
physical.recommendedScale120 = 180;
for (const QSize size : {QSize(1920, 1080), QSize(3840, 2160), QSize(2560, 1440)}) {
cutefish::display::ipc::Mode mode;
mode.width = size.width();
mode.height = size.height();
mode.refreshMilliHz = 60000;
mode.preferred = size.width() == 3840;
mode.current = size.width() == 1920;
physical.modes.append(mode);
}
state.physical.append(physical);
cutefish::display::ipc::LogicalDisplay logical;
logical.id = physical.sessionId;
logical.destinations = {physical.sessionId};
state.logical.append(logical);
DisplayOutputModel model;
model.setState(state);
const auto row = model.index(0);
// Largest first: 3840 × 2160 heads the list.
QCOMPARE(model.data(row, DisplayOutputModel::RecommendedResolutionIndexRole).toInt(), 0);
QCOMPARE(model.data(row, DisplayOutputModel::RecommendedScaleRole).toDouble(), 1.5);
}
void screensAreNamedForPeople()
{
DisplayClient::State state;

Loading…
Cancel
Save