diff --git a/applets/pager/package/contents/config/main.xml b/applets/pager/package/contents/config/main.xml --- a/applets/pager/package/contents/config/main.xml +++ b/applets/pager/package/contents/config/main.xml @@ -17,6 +17,9 @@ false + + false + diff --git a/applets/pager/package/contents/ui/configGeneral.qml b/applets/pager/package/contents/ui/configGeneral.qml --- a/applets/pager/package/contents/ui/configGeneral.qml +++ b/applets/pager/package/contents/ui/configGeneral.qml @@ -38,6 +38,7 @@ property int cfg_displayedText property alias cfg_showWindowIcons: showWindowIcons.checked property int cfg_currentDesktopSelected + property alias cfg_showOnlyCurrentScreen: showOnlyCurrentScreen.checked onCfg_displayedTextChanged: { switch (cfg_displayedText) { @@ -119,6 +120,16 @@ text: i18n("Icons") } + Item { + width: 2 + height: 2 + } //spacer + + QtControls.CheckBox { + id: showOnlyCurrentScreen + text: i18n("Only the current screen") + } + QtControls.Label { text: i18n("Selecting current desktop:") Layouts.Layout.alignment: Qt.AlignVCenter|Qt.AlignRight diff --git a/applets/pager/package/contents/ui/main.qml b/applets/pager/package/contents/ui/main.qml --- a/applets/pager/package/contents/ui/main.qml +++ b/applets/pager/package/contents/ui/main.qml @@ -104,6 +104,9 @@ showDesktop: (plasmoid.configuration.currentDesktopSelected == 1) + showOnlyCurrentScreen: plasmoid.configuration.showCurrentScreenOnly + screenGeometry: plasmoid.screenGeometry + pagerType: isActivityPager ? PagerModel.Activities : PagerModel.VirtualDesktops } diff --git a/applets/pager/plugin/pagermodel.h b/applets/pager/plugin/pagermodel.h --- a/applets/pager/plugin/pagermodel.h +++ b/applets/pager/plugin/pagermodel.h @@ -42,6 +42,8 @@ Q_PROPERTY(PagerType pagerType READ pagerType WRITE setPagerType NOTIFY pagerTypeChanged) Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) Q_PROPERTY(bool showDesktop READ showDesktop WRITE setShowDesktop NOTIFY showDesktopChanged) + Q_PROPERTY(bool showOnlyCurrentScreen READ showOnlyCurrentScreen WRITE setShowOnlyCurrentScreen NOTIFY showOnlyCurrentScreenChanged) + Q_PROPERTY(QRect screenGeometry READ screenGeometry WRITE setScreenGeometry NOTIFY screenGeometryChanged) Q_PROPERTY(int currentPage READ currentPage NOTIFY currentPageChanged) Q_PROPERTY(int layoutRows READ layoutRows NOTIFY layoutRowsChanged) Q_PROPERTY(QSize pagerItemSize READ pagerItemSize NOTIFY pagerItemSizeChanged) @@ -74,6 +76,12 @@ bool showDesktop() const; void setShowDesktop(bool show); + bool showOnlyCurrentScreen() const; + void setShowOnlyCurrentScreen(bool show); + + QRect screenGeometry() const; + void setScreenGeometry(const QRect &geometry); + int currentPage() const; int layoutRows() const; @@ -97,6 +105,8 @@ void pagerTypeChanged() const; void enabledChanged() const; void showDesktopChanged() const; + void showOnlyCurrentScreenChanged() const; + void screenGeometryChanged() const; void currentPageChanged() const; void layoutRowsChanged() const; void pagerItemSizeChanged() const; diff --git a/applets/pager/plugin/pagermodel.cpp b/applets/pager/plugin/pagermodel.cpp --- a/applets/pager/plugin/pagermodel.cpp +++ b/applets/pager/plugin/pagermodel.cpp @@ -52,6 +52,9 @@ bool enabled = false; bool showDesktop = false; + bool showOnlyCurrentScreen = false; + QRect screenGeometry; + WindowTasksModel *tasksModel = nullptr; static ActivityInfo *activityInfo; @@ -275,6 +278,46 @@ } } +bool PagerModel::showOnlyCurrentScreen() const +{ + return d->showOnlyCurrentScreen; +} + +void PagerModel::setShowOnlyCurrentScreen(bool show) +{ + if (d->showOnlyCurrentScreen != show) { + d->showOnlyCurrentScreen = show; + + if (d->screenGeometry.isValid()) { + emit pagerItemSizeChanged(); + + refresh(); + } + + emit showOnlyCurrentScreenChanged(); + } +} + +QRect PagerModel::screenGeometry() const +{ + return d->screenGeometry; +} + +void PagerModel::setScreenGeometry(const QRect &geometry) +{ + if (d->screenGeometry != geometry) { + d->screenGeometry = geometry; + + if (d->showOnlyCurrentScreen) { + emit pagerItemSizeChanged(); + + refresh(); + } + + emit showOnlyCurrentScreenChanged(); + } +} + int PagerModel::currentPage() const { if (d->pagerType == VirtualDesktops) { @@ -292,6 +335,10 @@ QSize PagerModel::pagerItemSize() const { + if (d->showOnlyCurrentScreen && d->screenGeometry.isValid()) { + return d->screenGeometry.size(); + } + QRect totalRect; for (int i = 0; i < d->desktopWidget->screenCount(); ++i) { @@ -357,6 +404,15 @@ } } + for (auto windowModel : d->windowModels) { + if (d->showOnlyCurrentScreen && d->screenGeometry.isValid()) { + windowModel->setScreenGeometry(d->screenGeometry); + windowModel->setFilterByScreen(true); + } else { + windowModel->setFilterByScreen(false); + } + } + endResetModel(); emit countChanged(); diff --git a/applets/pager/plugin/windowmodel.cpp b/applets/pager/plugin/windowmodel.cpp --- a/applets/pager/plugin/windowmodel.cpp +++ b/applets/pager/plugin/windowmodel.cpp @@ -74,24 +74,40 @@ QVariant WindowModel::data(const QModelIndex &index, int role) const { - if (role == AbstractTasksModel::Geometry && KWindowSystem::mapViewport()) { - + if (role == AbstractTasksModel::Geometry) { const QRect &windowGeo = TaskFilterProxyModel::data(index, role).toRect(); - const QRect &desktopGeo = d->desktopWidget->geometry(); - int x = windowGeo.center().x() % desktopGeo.width(); - int y = windowGeo.center().y() % desktopGeo.height(); + if (KWindowSystem::mapViewport()) { + const QRect &desktopGeo = d->desktopWidget->geometry(); + + int x = windowGeo.center().x() % desktopGeo.width(); + int y = windowGeo.center().y() % desktopGeo.height(); + + if (x < 0) { + x = x + desktopGeo.width(); + } + + if (y < 0) { + y = y + desktopGeo.height(); + } + + const QRect mappedGeo(x - windowGeo.width() / 2, y - windowGeo.height() / 2, + windowGeo.width(), windowGeo.height()); + + if (filterByScreen() && screenGeometry().isValid()) { + const QPoint &screenOffset = screenGeometry().topLeft(); - if (x < 0) { - x = x + desktopGeo.width(); + return mappedGeo.translated(0 - screenOffset.x(), 0 - screenOffset.y()); + } } - if (y < 0) { - y = y + desktopGeo.height(); + if (filterByScreen() && screenGeometry().isValid()) { + const QPoint &screenOffset = screenGeometry().topLeft(); + + return windowGeo.translated(0 - screenOffset.x(), 0 - screenOffset.y()); } - return QRect(x - windowGeo.width() / 2, y - windowGeo.height() / 2, - windowGeo.width(), windowGeo.height()); + return windowGeo; } else if (role == StackingOrder) { #if HAVE_X11 const QVariantList &winIds = TaskFilterProxyModel::data(index, AbstractTasksModel::LegacyWinIdList).toList();