14#include <KLocalizedString>
16#include <QDBusConnection>
22static QString outputName(
const Output *screen)
25 const bool shouldShowSerialNumber = std::any_of(screens.cbegin(), screens.cend(), [screen](
const Output *other) {
26 return other != screen && other->manufacturer() == screen->manufacturer() && other->model() == screen->model();
28 const bool shouldShowConnector = shouldShowSerialNumber && std::any_of(screens.cbegin(), screens.cend(), [screen](
const Output *other) {
29 return other != screen && other->serialNumber() == screen->serialNumber();
33 if (!screen->manufacturer().isEmpty()) {
34 parts.append(screen->manufacturer());
37 if (!screen->model().isEmpty()) {
38 parts.append(screen->model());
41 if (shouldShowSerialNumber && !screen->serialNumber().isEmpty()) {
42 parts.append(screen->serialNumber());
45 if (shouldShowConnector) {
46 parts.append(screen->name());
49 if (parts.isEmpty()) {
50 return i18nc(
"@label",
"Unknown");
52 return parts.join(QLatin1Char(
' '));
58 , m_qmlUrl(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation,
"kwin/effects/outputlocator/qml/OutputLabel.qml")))
60 QDBusConnection::sessionBus().registerObject(QStringLiteral(
"/org/kde/KWin/Effect/OutputLocator1"),
61 QStringLiteral(
"org.kde.KWin.Effect.OutputLocator1"),
63 QDBusConnection::ExportAllSlots);
69 return m_showTimer.isActive();
75 m_showTimer.start(std::chrono::milliseconds(2500));
80 for (
const auto screen : screens) {
82 scene->setSource(m_qmlUrl, {{QStringLiteral(
"outputName"), outputName(screen)}, {QStringLiteral(
"resolution"), screen->geometry().size()}, {QStringLiteral(
"scale"), screen->scale()}});
83 QRectF geometry(0, 0, scene->rootItem()->implicitWidth(), scene->rootItem()->implicitHeight());
84 geometry.moveCenter(screen->geometry().center());
85 scene->setGeometry(geometry.toRect());
89 m_scenesByScreens[screen].reset(scene);
92 m_showTimer.start(std::chrono::milliseconds(2500));
99 QRegion repaintRegion;
100 for (
const auto &[screen, scene] : m_scenesByScreens) {
101 repaintRegion += scene->geometry();
104 m_scenesByScreens.clear();
113 if (
auto it = m_scenesByScreens.find(screen); it != m_scenesByScreens.end()) {
117 for (
const auto &[screen, scene] : m_scenesByScreens) {
124#include "moc_outputlocator.cpp"
Base class for all KWin effects.
Display * waylandDisplay() const
void paintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion ®ion, Output *screen)
Q_SCRIPTABLE void addRepaint(const QRectF &r)
QList< Output * > screens() const
void renderOffscreenQuickView(const RenderTarget &renderTarget, const RenderViewport &viewport, OffscreenQuickView *effectQuickView) const
void paintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion ®ion, KWin::Output *screen) override
OutputLocatorEffect(QObject *parent=nullptr)
bool isActive() const override