diff --git a/libtaskmanager/groupmanager.cpp b/libtaskmanager/groupmanager.cpp index c95babe4..528a55ee 100644 --- a/libtaskmanager/groupmanager.cpp +++ b/libtaskmanager/groupmanager.cpp @@ -1,1393 +1,1399 @@ /***************************************************************** Copyright 2008 Christian Mollekopf Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************/ #include "groupmanager.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include "abstractsortingstrategy.h" #include "startup.h" #include "task.h" #include "taskitem.h" #include "taskgroup.h" #include "taskmanager.h" #include "strategies/activitysortingstrategy.h" #include "strategies/alphasortingstrategy.h" #include "strategies/desktopsortingstrategy.h" #include "strategies/programgroupingstrategy.h" #include "strategies/manualgroupingstrategy.h" #include "strategies/manualsortingstrategy.h" #include "launcheritem.h" #include "launcherconfig.h" namespace TaskManager { class GroupManagerPrivate { public: GroupManagerPrivate(GroupManager *manager) : q(manager), sortingStrategy(GroupManager::NoSorting), groupingStrategy(GroupManager::NoGrouping), lastGroupingStrategy(GroupManager::NoGrouping), abstractGroupingStrategy(0), abstractSortingStrategy(0), groupIsFullLimit(0), showOnlyCurrentDesktop(false), showOnlyCurrentActivity(true), showOnlyCurrentScreen(false), showOnlyMinimized(false), onlyGroupWhenFull(false), cachedOnlyGroupWhenFull(false), changingGroupingStrategy(false), readingLauncherConfig(false), separateLaunchers(true), forceGrouping(false), launchersLocked(false) { } /** reload all tasks from TaskManager */ void reloadTasks(); void actuallyReloadTasks(); /** * Keep track of changes in Taskmanager */ void currentDesktopChanged(int); void currentActivityChanged(QString); void taskChanged(::TaskManager::Task *, ::TaskManager::TaskChanges); void checkScreenChange(); void taskDestroyed(QObject *item); void startupItemDestroyed(AbstractGroupableItem *); void startupDestroyed(QObject *); void checkIfFull(); void actuallyCheckIfFull(); bool addTask(::TaskManager::Task *); void removeTask(::TaskManager::Task *); void addStartup(::TaskManager::Startup *); void removeStartup(::TaskManager::Startup *); void actuallyRemoveStartup(); void sycocaChanged(const QStringList &types); void launcherVisibilityChange(); void checkLauncherVisibility(LauncherItem *launcher); int launcherIndex(const QUrl &url); KConfigGroup launcherConfig(const KConfigGroup &config = KConfigGroup()); TaskGroup *currentRootGroup(); GroupManager *q; QHash startupList; GroupManager::TaskSortingStrategy sortingStrategy; GroupManager::TaskGroupingStrategy groupingStrategy; GroupManager::TaskGroupingStrategy lastGroupingStrategy; AbstractGroupingStrategy *abstractGroupingStrategy; AbstractSortingStrategy *abstractSortingStrategy; QRect currentScreenGeometry; QTimer screenTimer; QTimer reloadTimer; QTimer checkIfFullTimer; QSet geometryTasks; int groupIsFullLimit; QUuid configToken; QHash > rootGroups; //container for groups QList launchers; QList< ::TaskManager::Startup *> startupRemoveList; int currentDesktop; QString currentActivity; bool showOnlyCurrentDesktop : 1; bool showOnlyCurrentActivity : 1; bool showOnlyCurrentScreen : 1; bool showOnlyMinimized : 1; bool onlyGroupWhenFull : 1; bool cachedOnlyGroupWhenFull : 1; bool changingGroupingStrategy : 1; bool readingLauncherConfig : 1; bool separateLaunchers : 1; bool forceGrouping : 1; bool launchersLocked : 1; }; GroupManager::GroupManager(QObject *parent) : QObject(parent), d(new GroupManagerPrivate(this)) { connect(TaskManager::self(), SIGNAL(taskAdded(::TaskManager::Task *)), this, SLOT(addTask(::TaskManager::Task *))); connect(TaskManager::self(), SIGNAL(taskRemoved(::TaskManager::Task *)), this, SLOT(removeTask(::TaskManager::Task *))); connect(TaskManager::self(), SIGNAL(startupAdded(::TaskManager::Startup *)), this, SLOT(addStartup(::TaskManager::Startup *))); connect(TaskManager::self(), SIGNAL(startupRemoved(::TaskManager::Startup *)), this, SLOT(removeStartup(::TaskManager::Startup *))); connect(KSycoca::self(), SIGNAL(databaseChanged(QStringList)), this, SLOT(sycocaChanged(const QStringList &))); d->currentDesktop = TaskManager::self()->currentDesktop(); d->currentActivity = TaskManager::self()->currentActivity(); d->rootGroups[d->currentActivity][d->currentDesktop] = new TaskGroup(this, QStringLiteral("RootGroup")); d->reloadTimer.setSingleShot(true); d->reloadTimer.setInterval(0); connect(&d->reloadTimer, SIGNAL(timeout()), this, SLOT(actuallyReloadTasks())); d->screenTimer.setSingleShot(true); d->screenTimer.setInterval(100); connect(&d->screenTimer, SIGNAL(timeout()), this, SLOT(checkScreenChange())); d->checkIfFullTimer.setSingleShot(true); d->checkIfFullTimer.setInterval(0); connect(&d->checkIfFullTimer, SIGNAL(timeout()), this, SLOT(actuallyCheckIfFull())); } GroupManager::~GroupManager() { TaskManager::self()->setTrackGeometry(false, d->configToken); delete d->abstractSortingStrategy; if (d->abstractGroupingStrategy) { d->abstractGroupingStrategy->setDestroyGroupsOnDestruction(false); delete d->abstractGroupingStrategy; } delete d; } TaskGroup *GroupManagerPrivate::currentRootGroup() { return rootGroups[currentActivity][currentDesktop]; } void GroupManagerPrivate::reloadTasks() { reloadTimer.start(); } void GroupManagerPrivate::actuallyReloadTasks() { //qDebug() << "number of tasks available " << TaskManager::self()->tasks().size(); QHash taskList = TaskManager::self()->tasks(); QMutableHashIterator it(taskList); while (it.hasNext()) { it.next(); if (addTask(it.value())) { //qDebug() << "task added " << it.value()->visibleName(); it.remove(); } } // Remove what remains it.toFront(); while (it.hasNext()) { it.next(); removeTask(it.value()); } emit q->reload(); } void GroupManagerPrivate::addStartup(::TaskManager::Startup *startup) { if (startupList.contains(startup)) { return; } QHash::iterator it = startupList.begin(); QHash::iterator itEnd = startupList.end(); while (it != itEnd) { if (it.key()->desktopId() == startup->desktopId() && it.key()->bin() == startup->bin()) { return; } ++it; } foreach(const AbstractGroupableItem *item, currentRootGroup()->members()) { if (item->itemType() == TaskItemType) { const TaskItem *task = static_cast(item); if (task->launcherUrl().toLocalFile() == startup->desktopId() || task->taskName().toLower() == startup->bin()) { return; } } } TaskItem *item = new TaskItem(q, startup); foreach (LauncherItem * launcher, launchers) { if (launcher->associateItemIfMatches(item)) { // Task demands attention, so is to be shown, therefore hide the launcher... currentRootGroup()->remove(launcher); } } startupList.insert(startup, item); currentRootGroup()->add(item); QObject::connect(startup, SIGNAL(destroyed(QObject*)), q, SLOT(startupDestroyed(QObject*))); QObject::connect(item, SIGNAL(destroyed(AbstractGroupableItem*)), q, SLOT(startupItemDestroyed(AbstractGroupableItem*))); } void GroupManagerPrivate::removeStartup(::TaskManager::Startup *startup) { startupRemoveList.append(startup); QTimer::singleShot(2000, q, SLOT(actuallyRemoveStartup())); } void GroupManagerPrivate::actuallyRemoveStartup() { if (startupRemoveList.isEmpty()) { return; } ::TaskManager::Startup *startup = startupRemoveList.takeFirst(); if (!startupList.contains(startup)) { return; } TaskItem *item = startupList.take(startup); if (item->parentGroup()) { item->parentGroup()->remove(item); } item->setTaskPointer(0); foreach (LauncherItem * launcher, launchers) { launcher->removeItemIfAssociated(item); } delete startup; } bool GroupManagerPrivate::addTask(::TaskManager::Task *task) { if (!task) { return false; } //qDebug(); /* qDebug() << task->visibleName() << task->visibleNameWithState() << task->name() << task->className() << task->classClass(); */ bool skip = false; if (!task->showInTaskbar()) { //qDebug() << "Do not show in taskbar"; skip = true; } if (showOnlyCurrentScreen && !task->isOnScreen(currentScreenGeometry)) { //qDebug() << "Not on this screen and showOnlyCurrentScreen"; skip = true; } // Should the Task be displayed ? We always display if attention is demaded if (!task->demandsAttention()) { // As the Task doesn't demand attention // go through all filters whether the task should be displayed or not if (showOnlyCurrentDesktop && !task->isOnCurrentDesktop()) { /* qDebug() << "Not on this desktop and showOnlyCurrentDesktop" << KWindowSystem::currentDesktop() << task->desktop(); */ skip = true; } if (showOnlyCurrentActivity && !task->isOnCurrentActivity()) { /* qDebug() << "Not on this desktop and showOnlyCurrentActivity" << KWindowSystem::currentActivity() << task->desktop(); */ skip = true; } if (showOnlyMinimized && !task->isMinimized()) { //qDebug() << "Not minimized and only showing minimized"; skip = true; } NET::WindowType type = task->info().windowType(NET::NormalMask | NET::DialogMask | NET::OverrideMask | NET::UtilityMask); if (type == NET::Utility) { //qDebug() << "skipping utility window" << task->name(); skip = true; } //TODO: should we check for transiency? if so the following code can detect it. /* QHash ::iterator it = d->itemList.begin(); while (it != d->itemList.end()) { TaskItem *item = it.value(); if (item->task()->hasTransient(task->window())) { qDebug() << "TRANSIENT TRANSIENT TRANSIENT!"; return flase; } ++it; } */ } //Ok the Task should be displayed TaskItem *item = qobject_cast(currentRootGroup()->getMemberByWId(task->window())); if (!item || skip) { TaskItem *startupItem = 0; QHash::iterator it = startupList.begin(); QHash::iterator itEnd = startupList.end(); const QString desktopId = TaskItem::launcherUrlFromTask(q, task).toLocalFile(); while (it != itEnd) { if (it.key()->matchesWindow(task->window()) || it.key()->desktopId() == desktopId || it.key()->bin() == task->className()) { //qDebug() << "startup task found"; item = startupItem = it.value(); ::TaskManager::Startup *startup = it.key(); startupRemoveList.removeAll(startup); startupList.erase(it); QObject::disconnect(item, 0, q, 0); if (!skip) { item->setTaskPointer(task); } delete startup; break; } ++it; } // if we are to skip because we don't display, we simply delete the startup related to it if (skip) { delete startupItem; return false; } if (!item) { item = new TaskItem(q, task); } QObject::connect(task, SIGNAL(destroyed(QObject*)), q, SLOT(taskDestroyed(QObject*))); foreach (LauncherItem * launcher, launchers) { if (launcher->associateItemIfMatches(item)) { // Task demands attention, so is to be shown, therefore hide the launcher... currentRootGroup()->remove(launcher); } } } //Find a fitting group for the task with GroupingStrategies if (abstractGroupingStrategy && (forceGrouping || !task->demandsAttention())) { //do not group attention tasks abstractGroupingStrategy->handleItem(item); } else { currentRootGroup()->add(item); if (abstractSortingStrategy) { abstractSortingStrategy->handleItem(item); abstractSortingStrategy->check(item); } } if (showOnlyCurrentScreen) { geometryTasks.insert(task); } return true; } void GroupManagerPrivate::removeTask(::TaskManager::Task *task) { if (!task) { return; } //qDebug() << "remove: " << task->visibleName(); geometryTasks.remove(task); AbstractGroupableItem *item = currentRootGroup()->getMemberByWId(task->window()); if (!item) { // this can happen if the window hasn't been caught previously, // of it it is an ignored type such as a NET::Utility type window //qDebug() << "invalid item"; return; } foreach (LauncherItem * launcher, launchers) { launcher->removeItemIfAssociated(item); } if (item->parentGroup()) { item->parentGroup()->remove(item); } //the item must exist as long as the Task does because of activate calls so don't delete the item here, it will delete itself. } void GroupManagerPrivate::taskDestroyed(QObject *item) { Task *task = static_cast(item); if (showOnlyCurrentScreen) { geometryTasks.remove(task); } } void GroupManagerPrivate::startupDestroyed(QObject *obj) { ::TaskManager::Startup *startup = static_cast< ::TaskManager::Startup *>(obj); if (!startupList.contains(startup)) { return; } TaskItem *item = startupList.take(startup); startupRemoveList.removeAll(startup); if (item->parentGroup()) { item->parentGroup()->remove(item); } item->setTaskPointer(0); foreach (LauncherItem * launcher, launchers) { launcher->removeItemIfAssociated(item); } } void GroupManagerPrivate::startupItemDestroyed(AbstractGroupableItem *item) { TaskItem *taskItem = static_cast(item); startupList.remove(startupList.key(taskItem)); geometryTasks.remove(taskItem->task()); } bool GroupManager::manualGroupingRequest(AbstractGroupableItem* item, TaskGroup* groupItem) { if (d->abstractGroupingStrategy) { return d->abstractGroupingStrategy->manualGroupingRequest(item, groupItem); } return false; } bool GroupManager::manualGroupingRequest(ItemList items) { if (d->abstractGroupingStrategy) { return d->abstractGroupingStrategy->manualGroupingRequest(items); } return false; } bool GroupManager::manualSortingRequest(AbstractGroupableItem* taskItem, int newIndex) { if (d->abstractSortingStrategy && !launchersLocked()) { return d->abstractSortingStrategy->manualSortingRequest(taskItem, newIndex); } return false; } GroupPtr GroupManager::rootGroup() const { return d->currentRootGroup(); } void GroupManagerPrivate::currentActivityChanged(QString newActivity) { if (!showOnlyCurrentActivity || currentActivity == newActivity) { return; } if (!rootGroups.contains(newActivity) || !rootGroups.value(newActivity).contains(currentDesktop)) { qDebug() << "created new desk group"; rootGroups[newActivity][currentDesktop] = new TaskGroup(q, QStringLiteral("RootGroup")); if (abstractSortingStrategy) { abstractSortingStrategy->handleGroup(rootGroups[newActivity][currentDesktop]); } } if (onlyGroupWhenFull) { QObject::disconnect(currentRootGroup(), SIGNAL(itemAdded(AbstractGroupableItem*)), q, SLOT(checkIfFull())); QObject::disconnect(currentRootGroup(), SIGNAL(itemRemoved(AbstractGroupableItem*)), q, SLOT(checkIfFull())); } currentActivity = newActivity; foreach (LauncherItem * item, launchers) { if (item->shouldShow(q)) { rootGroups[currentActivity][currentDesktop]->add(item); } else { rootGroups[currentActivity][currentDesktop]->remove(item); } } if (onlyGroupWhenFull) { QObject::connect(currentRootGroup(), SIGNAL(itemAdded(AbstractGroupableItem*)), q, SLOT(checkIfFull())); QObject::connect(currentRootGroup(), SIGNAL(itemRemoved(AbstractGroupableItem*)), q, SLOT(checkIfFull())); } actuallyReloadTasks(); } void GroupManagerPrivate::currentDesktopChanged(int newDesktop) { //qDebug(); if (!showOnlyCurrentDesktop) { return; } if (currentDesktop == newDesktop) { return; } if (!rootGroups[currentActivity].contains(newDesktop)) { qDebug() << "created new desk group"; rootGroups[currentActivity][newDesktop] = new TaskGroup(q, QStringLiteral("RootGroup")); if (abstractSortingStrategy) { abstractSortingStrategy->handleGroup(rootGroups[currentActivity][newDesktop]); } } if (onlyGroupWhenFull) { QObject::disconnect(currentRootGroup(), SIGNAL(itemAdded(AbstractGroupableItem*)), q, SLOT(checkIfFull())); QObject::disconnect(currentRootGroup(), SIGNAL(itemRemoved(AbstractGroupableItem*)), q, SLOT(checkIfFull())); } currentDesktop = newDesktop; foreach (LauncherItem * item, launchers) { if (item->shouldShow(q)) { rootGroups[currentActivity][currentDesktop]->add(item); } else { rootGroups[currentActivity][currentDesktop]->remove(item); } } if (onlyGroupWhenFull) { QObject::connect(currentRootGroup(), SIGNAL(itemAdded(AbstractGroupableItem*)), q, SLOT(checkIfFull())); QObject::connect(currentRootGroup(), SIGNAL(itemRemoved(AbstractGroupableItem*)), q, SLOT(checkIfFull())); } actuallyReloadTasks(); } void GroupManagerPrivate::taskChanged(::TaskManager::Task *task, ::TaskManager::TaskChanges changes) { //qDebug(); if (!task) { return; } bool takeAction = false; bool show = true; if (showOnlyCurrentDesktop && changes & ::TaskManager::DesktopChanged) { takeAction = true; show = task->isOnCurrentDesktop(); //qDebug() << task->visibleName() << "on" << TaskManager::self()->currentDesktop(); } if (showOnlyCurrentActivity && changes & ::TaskManager::ActivitiesChanged) { takeAction = true; show = task->isOnCurrentActivity(); //qDebug() << task->visibleName() << "on" << TaskManager::self()->currentDesktop(); } if (showOnlyMinimized && changes & ::TaskManager::StateChanged) { //TODO: wouldn't it be nice to get notification of JUST minimization? takeAction = true; show = task->isMinimized(); } if (showOnlyCurrentScreen && changes & ::TaskManager::GeometryChanged) { geometryTasks.insert(task); if (!screenTimer.isActive()) { screenTimer.start(); } } if (changes & ::TaskManager::AttentionChanged) { if (task->demandsAttention()) { takeAction = true; show = true; } else if (task->info().windowType(NET::UtilityMask) == NET::Utility) { removeTask(task); + } else if (abstractGroupingStrategy) { + // Group tasks again when they no longer demands attention. + TaskItem *item = qobject_cast(currentRootGroup()->getMemberByWId(task->window())); + if (item) { + abstractGroupingStrategy->handleItem(item); + } } } // Some apps, eg. LibreOffice, change classClass/className after start-up... if (changes & ::TaskManager::ClassChanged) { // Instead of just moving item (as what happend in the #if below), just remove and re-add the task. // This way the grouping happens properly. AbstractGroupableItem *item = currentRootGroup()->getMemberByWId(task->window()); if (item && TaskItemType == item->itemType()) { static_cast(item)->resetLauncherCheck(); } removeTask(task); addTask(task); } if (!takeAction) { return; } show = show && (!showOnlyCurrentScreen || task->isOnScreen(currentScreenGeometry)); if (show) { //qDebug() << "add(task);"; addTask(task); } else { //qDebug() << "remove(task);"; removeTask(task); } } QRect GroupManager::screenGeometry() const { return d->currentScreenGeometry; } void GroupManager::setScreenGeometry(const QRect& geometry) { if (geometry != d->currentScreenGeometry) { d->currentScreenGeometry = geometry; d->reloadTasks(); emit screenGeometryChanged(geometry); } } void GroupManagerPrivate::checkScreenChange() { //qDebug(); if (showOnlyCurrentScreen) { foreach (Task *task, geometryTasks) { if (task->isOnScreen(currentScreenGeometry)) { addTask(task); } else { removeTask(task); } } } geometryTasks.clear(); } void GroupManager::reconnect() { //qDebug(); disconnect(TaskManager::self(), SIGNAL(desktopChanged(int)), this, SLOT(currentDesktopChanged(int))); disconnect(TaskManager::self(), SIGNAL(activityChanged(QString)), this, SLOT(currentActivityChanged(QString))); disconnect(TaskManager::self(), SIGNAL(windowChanged(::TaskManager::Task *, ::TaskManager::TaskChanges)), this, SLOT(taskChanged(::TaskManager::Task *, ::TaskManager::TaskChanges))); if (d->showOnlyCurrentDesktop || d->showOnlyMinimized || d->showOnlyCurrentScreen || d->showOnlyCurrentActivity) { // listen to the relevant task manager signals if (d->showOnlyCurrentDesktop) { connect(TaskManager::self(), SIGNAL(desktopChanged(int)), this, SLOT(currentDesktopChanged(int))); } if (d->showOnlyCurrentActivity) { connect(TaskManager::self(), SIGNAL(activityChanged(QString)), this, SLOT(currentActivityChanged(QString))); } - - connect(TaskManager::self(), SIGNAL(windowChanged(::TaskManager::Task *, ::TaskManager::TaskChanges)), - this, SLOT(taskChanged(::TaskManager::Task *, ::TaskManager::TaskChanges))); } + connect(TaskManager::self(), SIGNAL(windowChanged(::TaskManager::Task *, ::TaskManager::TaskChanges)), + this, SLOT(taskChanged(::TaskManager::Task *, ::TaskManager::TaskChanges))); + TaskManager::self()->setTrackGeometry(d->showOnlyCurrentScreen, d->configToken); if (!d->showOnlyCurrentScreen) { d->geometryTasks.clear(); } d->reloadTasks(); } bool GroupManager::addLauncher(const QUrl &url, const QIcon &icon, const QString &name, const QString &genericName, const QString &wmClass, int insertPos) { if (url.isEmpty() || launchersLocked()) { return false; } int index = launcherIndex(url); LauncherItem *launcher = -1 != index ? d->launchers.at(index) : 0L; // Do not insert launchers twice if (!launcher) { launcher = new LauncherItem(d->currentRootGroup(), url); if (!launcher->isValid()) { delete launcher; return false; } if (!icon.isNull()) { launcher->setIcon(icon); } if (!name.isEmpty()) { launcher->setName(name); } if (!genericName.isEmpty()) { launcher->setGenericName(genericName); } if (!wmClass.isEmpty()) { launcher->setWmClass(wmClass); } QStack groups; groups.push(d->currentRootGroup()); while (!groups.isEmpty()) { TaskGroup *group = groups.pop(); foreach (AbstractGroupableItem * item, group->members()) { if (item->itemType() == GroupItemType) { groups.push(static_cast(item)); } else { launcher->associateItemIfMatches(item); } } } if (insertPos >= 0 && insertPos < d->launchers.count()) { d->launchers.insert(insertPos, launcher); } else { d->launchers.append(launcher); } connect(launcher, SIGNAL(associationChanged()), this, SLOT(launcherVisibilityChange())); d->checkLauncherVisibility(launcher); if (!d->separateLaunchers && d->abstractSortingStrategy && ManualSorting == d->abstractSortingStrategy->type()) { // Ensure item is placed where launcher would be... foreach (AbstractGroupableItem * item, d->rootGroups[d->currentActivity][d->currentDesktop]->members()) { if (LauncherItemType != item->itemType() && item->launcherUrl() == url) { manualSortingRequest(item, launcherIndex(url)); break; } } } if (d->abstractSortingStrategy) { d->abstractSortingStrategy->check(launcher); } if (!d->readingLauncherConfig) { emit launcherListChanged(); } } return launcher; } void GroupManager::removeLauncher(const QUrl &url) { if (launchersLocked()) { return; } int index = launcherIndex(url); if (index == -1 || index >= d->launchers.count()) { return; } LauncherItem *launcher = d->launchers.at(index); if (!launcher) { return; } d->launchers.removeAt(index); typedef QHash Metagroup; foreach (Metagroup metagroup, d->rootGroups) { foreach (TaskGroup * rootGroup, metagroup) { rootGroup->remove(launcher); } } launcher->deleteLater(); if (!d->separateLaunchers && d->abstractSortingStrategy && ManualSorting == d->abstractSortingStrategy->type()) { // Ensure item is placed at end of launchers... foreach (AbstractGroupableItem * item, d->rootGroups[d->currentActivity][d->currentDesktop]->members()) { if (LauncherItemType != item->itemType() && item->launcherUrl() == url) { manualSortingRequest(item, d->launchers.count()); break; } } } if (!d->readingLauncherConfig) { emit launcherListChanged(); } } void GroupManagerPrivate::sycocaChanged(const QStringList &types) { if (types.contains(QStringLiteral("apps"))) { QList removals; foreach (LauncherItem *launcher, launchers) { if (launcher->launcherUrl().scheme() != QLatin1String("preferred") && !QFile::exists(launcher->launcherUrl().toLocalFile())) { removals << launcher->launcherUrl(); } } foreach (const QUrl & url, removals) { q->removeLauncher(url); } } } void GroupManagerPrivate::launcherVisibilityChange() { checkLauncherVisibility(qobject_cast(q->sender())); } void GroupManagerPrivate::checkLauncherVisibility(LauncherItem *launcher) { if (!launcher) { return; } if (launcher->shouldShow(q)) { rootGroups[currentActivity][currentDesktop]->add(launcher); } else { rootGroups[currentActivity][currentDesktop]->remove(launcher); } } bool GroupManager::launcherExists(const QUrl &url) const { return d->launcherIndex(url) != -1; } int GroupManager::launcherIndex(const QUrl &url) const { return d->launcherIndex(url); } int GroupManager::launcherCount() const { return d->launchers.count(); } bool GroupManager::launchersLocked() const { return d->launchersLocked; } void GroupManager::setLaunchersLocked(bool l) { d->launchersLocked = l; } QUrl GroupManager::launcherForWmClass(const QString &wmClass) const { foreach (LauncherItem * l, d->launchers) { if (l->wmClass() == wmClass) { return l->launcherUrl(); } } return QUrl(); } QString GroupManager::launcherWmClass(const QUrl &url) const { int index = launcherIndex(url); LauncherItem *l = -1 != index ? d->launchers.at(index) : 0L; return l ? l->wmClass() : QString(); } bool GroupManager::isItemAssociatedWithLauncher(AbstractGroupableItem *item) const { if (item) { switch (item->itemType()) { case LauncherItemType: return true; case GroupItemType: { foreach (AbstractGroupableItem * i, static_cast(item)->members()) { if (isItemAssociatedWithLauncher(i)) { return true; } } break; } case TaskItemType: { foreach (LauncherItem * launcher, d->launchers) { if (launcher->isAssociated(item)) { return true; } } } } } return false; } void GroupManager::moveLauncher(const QUrl &url, int newIndex) { if (!url.isValid()) { return; } int oldIndex = launcherIndex(url); if (oldIndex >= 0 && newIndex != oldIndex) { d->launchers.insert(newIndex, d->launchers.takeAt(oldIndex)); emit launcherListChanged(); } } bool GroupManager::separateLaunchers() const { return d->separateLaunchers; } void GroupManager::setSeparateLaunchers(bool s) { if (d->separateLaunchers != s) { d->separateLaunchers = s; emit separateLaunchersChanged(s); } } bool GroupManager::forceGrouping() const { return d->forceGrouping; } void GroupManager::setForceGrouping(bool s) { if (d->forceGrouping != s) { d->forceGrouping = s; emit forceGroupingChanged(s); } } void GroupManager::createConfigurationInterface(KConfigDialog *parent) { new LauncherConfig(parent); } QList GroupManager::launcherList() const { QList launchers; foreach (LauncherItem *l, d->launchers) { QUrl u(l->launcherUrl()); QUrlQuery uQuery(u); if (!l->wmClass().isEmpty()) { uQuery.addQueryItem(QStringLiteral("wmClass"), l->wmClass()); } if (!l->launcherUrl().isValid() || !KDesktopFile::isDesktopFile(l->launcherUrl().toLocalFile())) { if (!l->name().isEmpty()) { uQuery.addQueryItem(QStringLiteral("name"), l->name()); } if (!l->genericName().isEmpty()) { uQuery.addQueryItem(QStringLiteral("genericName"), l->genericName()); } if (!l->icon().name().isEmpty()) { uQuery.addQueryItem(QStringLiteral("icon"), l->icon().name()); } else if (!l->icon().isNull()) { QPixmap pixmap = l->icon().pixmap(QSize(64, 64)); QByteArray bytes; QBuffer buffer(&bytes); buffer.open(QIODevice::WriteOnly); pixmap.save(&buffer, "PNG"); uQuery.addQueryItem(QStringLiteral("iconData"), bytes.toBase64(QByteArray::Base64UrlEncoding)); } } u.setQuery(uQuery); launchers << u; } return launchers; } void GroupManager::setLauncherList(QList launcherList) { d->readingLauncherConfig = true; QSet urls; foreach (QUrl l, launcherList) { QUrlQuery query(l); QString name(query.queryItemValue(QStringLiteral("name"))); QString genericName(query.queryItemValue(QStringLiteral("genericName"))); QString wmClass(query.queryItemValue(QStringLiteral("wmClass"))); QString iconData(query.queryItemValue(QStringLiteral("iconData"))); QIcon icon; if (!iconData.isEmpty()) { QPixmap pixmap; QByteArray bytes = QByteArray::fromBase64(iconData.toLocal8Bit(), QByteArray::Base64UrlEncoding); pixmap.loadFromData(bytes); icon.addPixmap(pixmap); } else { icon = QIcon::fromTheme(query.queryItemValue(QStringLiteral("icon"))); } l.setQuery(QUrlQuery()); if (addLauncher(l, icon, name, genericName, wmClass)) { urls << l; } } QList removals; foreach (LauncherItem *launcher, d->launchers) { if (!urls.contains(launcher->launcherUrl())) { removals << launcher->launcherUrl(); } } foreach (const QUrl & url, removals) { removeLauncher(url); } d->readingLauncherConfig = false; emit launcherListChanged(); } int GroupManagerPrivate::launcherIndex(const QUrl &url) { // we check first for exact matches ... int index = 0; foreach (const LauncherItem * item, launchers) { if (item->launcherUrl() == url) { return index; } ++index; } // .. and if that fails for preferred launcher matches index = 0; foreach (const LauncherItem * item, launchers) { if (item->launcherUrl().scheme() == QLatin1String("preferred")) { KService::Ptr service = KService::serviceByStorageId(item->defaultApplication(item->launcherUrl())); if (service) { QUrl prefUrl(service->entryPath()); if (prefUrl.scheme().isEmpty()) { prefUrl.setScheme(QStringLiteral("file")); } if (prefUrl == url) { return index; } } } ++index; } return -1; } bool GroupManager::onlyGroupWhenFull() const { return d->onlyGroupWhenFull; } void GroupManager::setOnlyGroupWhenFull(bool onlyGroupWhenFull) { //qDebug() << onlyGroupWhenFull; if (d->onlyGroupWhenFull == onlyGroupWhenFull) { return; } d->onlyGroupWhenFull = onlyGroupWhenFull; disconnect(d->currentRootGroup(), SIGNAL(itemAdded(AbstractGroupableItem*)), this, SLOT(checkIfFull())); disconnect(d->currentRootGroup(), SIGNAL(itemRemoved(AbstractGroupableItem*)), this, SLOT(checkIfFull())); if (onlyGroupWhenFull) { connect(d->currentRootGroup(), SIGNAL(itemAdded(AbstractGroupableItem*)), this, SLOT(checkIfFull())); connect(d->currentRootGroup(), SIGNAL(itemRemoved(AbstractGroupableItem*)), this, SLOT(checkIfFull())); d->checkIfFull(); } else { setGroupingStrategy(d->groupingStrategy); } emit onlyGroupWhenFullChanged(onlyGroupWhenFull); } int GroupManager::fullLimit() const { return d->groupIsFullLimit; } void GroupManager::setFullLimit(int limit) { //qDebug() << limit; if (d->groupIsFullLimit != limit) { d->groupIsFullLimit = limit; if (d->onlyGroupWhenFull) { d->checkIfFull(); } emit fullLimitChanged(limit); } } void GroupManagerPrivate::checkIfFull() { // Start a timer so that if we have been triggered by a layouting // we give time for it to finish up instead of starting a new one // right away. checkIfFullTimer.start(); } void GroupManagerPrivate::actuallyCheckIfFull() { //qDebug(); if (!onlyGroupWhenFull || groupingStrategy != GroupManager::ProgramGrouping || changingGroupingStrategy) { return; } if (currentRootGroup()->totalSize() >= groupIsFullLimit) { if (!abstractGroupingStrategy) { geometryTasks.clear(); q->setGroupingStrategy(GroupManager::ProgramGrouping); } } else if (abstractGroupingStrategy) { geometryTasks.clear(); q->setGroupingStrategy(GroupManager::NoGrouping); //let the visualization think we still use the programGrouping groupingStrategy = GroupManager::ProgramGrouping; } } bool GroupManager::showOnlyCurrentScreen() const { return d->showOnlyCurrentScreen; } void GroupManager::setShowOnlyCurrentScreen(bool showOnlyCurrentScreen) { if (showOnlyCurrentScreen != d->showOnlyCurrentScreen) { d->showOnlyCurrentScreen = showOnlyCurrentScreen; reconnect(); emit showOnlyCurrentScreenChanged(showOnlyCurrentScreen); } } bool GroupManager::showOnlyCurrentDesktop() const { return d->showOnlyCurrentDesktop; } void GroupManager::setShowOnlyCurrentDesktop(bool showOnlyCurrentDesktop) { if (showOnlyCurrentDesktop != d->showOnlyCurrentDesktop) { d->showOnlyCurrentDesktop = showOnlyCurrentDesktop; reconnect(); emit showOnlyCurrentDesktopChanged(showOnlyCurrentDesktop); } } bool GroupManager::showOnlyCurrentActivity() const { return d->showOnlyCurrentActivity; } void GroupManager::setShowOnlyCurrentActivity(bool showOnlyCurrentActivity) { if (showOnlyCurrentActivity != d->showOnlyCurrentActivity) { d->showOnlyCurrentActivity = showOnlyCurrentActivity; reconnect(); emit showOnlyCurrentActivityChanged(showOnlyCurrentActivity); } } bool GroupManager::showOnlyMinimized() const { return d->showOnlyMinimized; } void GroupManager::setShowOnlyMinimized(bool showOnlyMinimized) { if (showOnlyMinimized != d->showOnlyMinimized) { d->showOnlyMinimized = showOnlyMinimized; reconnect(); emit showOnlyMinimizedChanged(showOnlyMinimized); } } GroupManager::TaskSortingStrategy GroupManager::sortingStrategy() const { return d->sortingStrategy; } AbstractSortingStrategy* GroupManager::taskSorter() const { return d->abstractSortingStrategy; } void GroupManager::setSortingStrategy(TaskSortingStrategy sortOrder) { if (d->abstractSortingStrategy) { if (d->abstractSortingStrategy->type() == sortOrder) { return; } d->abstractSortingStrategy->deleteLater(); d->abstractSortingStrategy = 0; } switch (sortOrder) { case ManualSorting: d->abstractSortingStrategy = new ManualSortingStrategy(this); break; case AlphaSorting: d->abstractSortingStrategy = new AlphaSortingStrategy(this); break; case DesktopSorting: d->abstractSortingStrategy = new DesktopSortingStrategy(this); break; case ActivitySorting: d->abstractSortingStrategy = new ActivitySortingStrategy(this); break; case NoSorting: //manual and no grouping result both in non automatic grouping break; default: qDebug() << "Invalid Strategy"; } if (d->abstractSortingStrategy) { typedef QHash Metagroup; foreach (Metagroup metagroup, d->rootGroups) { foreach (TaskGroup * group, metagroup) { d->abstractSortingStrategy->handleGroup(group); } } } d->sortingStrategy = sortOrder; reconnect(); emit sortingStrategyChanged(sortOrder); } GroupManager::TaskGroupingStrategy GroupManager::groupingStrategy() const { return d->groupingStrategy; } AbstractGroupingStrategy* GroupManager::taskGrouper() const { return d->abstractGroupingStrategy; } void GroupManager::setGroupingStrategy(TaskGroupingStrategy strategy) { if (d->changingGroupingStrategy || (d->cachedOnlyGroupWhenFull == d->onlyGroupWhenFull && d->groupingStrategy == strategy)) { return; } d->changingGroupingStrategy = true; d->cachedOnlyGroupWhenFull = d->onlyGroupWhenFull; //qDebug() << strategy << kBacktrace(); if (d->onlyGroupWhenFull) { disconnect(d->currentRootGroup(), SIGNAL(itemAdded(AbstractGroupableItem*)), this, SLOT(checkIfFull())); disconnect(d->currentRootGroup(), SIGNAL(itemRemoved(AbstractGroupableItem*)), this, SLOT(checkIfFull())); } if (d->abstractGroupingStrategy) { disconnect(d->abstractGroupingStrategy, 0, this, 0); delete d->abstractGroupingStrategy; d->abstractGroupingStrategy = 0; } switch (strategy) { case ManualGrouping: d->abstractGroupingStrategy = new ManualGroupingStrategy(this); break; case ProgramGrouping: d->abstractGroupingStrategy = new ProgramGroupingStrategy(this); break; case NoGrouping: break; default: qDebug() << "Strategy not implemented"; } d->groupingStrategy = strategy; d->actuallyReloadTasks(); if (d->onlyGroupWhenFull) { connect(d->currentRootGroup(), SIGNAL(itemAdded(AbstractGroupableItem*)), this, SLOT(checkIfFull())); connect(d->currentRootGroup(), SIGNAL(itemRemoved(AbstractGroupableItem*)), this, SLOT(checkIfFull())); } d->changingGroupingStrategy = false; emit groupingStrategyChanged(strategy); } } // TaskManager namespace #include "moc_groupmanager.cpp" diff --git a/libtaskmanager/task.cpp b/libtaskmanager/task.cpp index 35ab14f1..08533916 100644 --- a/libtaskmanager/task.cpp +++ b/libtaskmanager/task.cpp @@ -1,723 +1,726 @@ /***************************************************************** Copyright (c) 2000-2001 Matthias Elter Copyright (c) 2001 Richard Moore Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************/ // Own #include "task.h" #include "task_p.h" // Qt #include #include #include #include // KDE #include #include #include "taskmanager.h" namespace TaskManager { Task::Task(WId w, QObject *parent, const char *name) : QObject(parent), d(new Private(w)) { setObjectName(name); // try to load icon via net_wm refreshIcon(); refreshActivities(); + + // initial demands attention + d->demandedAttention = demandsAttention(); } Task::~Task() { delete d; } void Task::timerEvent(QTimerEvent *) { if (d->cachedChanges.netWindowInfoProperties || d->cachedChanges.netWindowInfoProperties2) { d->lastUpdate = QTime(); refresh(d->cachedChanges); d->cachedChanges.netWindowInfoProperties = 0; d->cachedChanges.netWindowInfoProperties2 = 0; } killTimer(d->cachedChangesTimerId); d->cachedChangesTimerId = 0; } void Task::refreshIcon() { // try to load icon via net_wm d->pixmap = KWindowSystem::icon(d->win, 16, 16, true); // try to guess the icon from the classhint if (d->pixmap.isNull()) { d->pixmap = KIconLoader::global()->loadIcon(className().toLower(), KIconLoader::Small, KIconLoader::Small, KIconLoader::DefaultState, QStringList(), 0, true); // load the icon for X applications if (d->pixmap.isNull()) { d->pixmap = SmallIcon(QStringLiteral("xorg")); } } d->lastIcon = QPixmap(); d->icon = QIcon(); emit changed(IconChanged); } ::TaskManager::TaskChanges Task::refresh(WindowProperties dirty) { if (!d->lastUpdate.isNull() && d->lastUpdate.elapsed() < 200) { d->cachedChanges.netWindowInfoProperties |= dirty.netWindowInfoProperties; d->cachedChanges.netWindowInfoProperties2 |= dirty.netWindowInfoProperties2; if (!d->cachedChangesTimerId) { d->cachedChangesTimerId = startTimer(200 - d->lastUpdate.elapsed()); } return TaskUnchanged; } d->lastUpdate.restart(); KWindowInfo info(d->win, windowInfoFlags, windowInfoFlags2); TaskChanges changes = TaskUnchanged; if (d->info.windowClassClass() != info.windowClassClass() || d->info.windowClassName() != info.windowClassName()) { changes |= ClassChanged; } if (d->info.visibleName() != info.visibleName() || d->info.visibleNameWithState() != info.visibleNameWithState() || d->info.name() != info.name()) { changes |= NameChanged; } d->info = info; if (dirty.netWindowInfoProperties & NET::WMState || dirty.netWindowInfoProperties & NET::XAWMState) { changes |= StateChanged; if (demandsAttention() != d->demandedAttention) { d->demandedAttention = !d->demandedAttention; changes |= AttentionChanged; } } if (dirty.netWindowInfoProperties & NET::WMDesktop) { changes |= DesktopChanged; } if (dirty.netWindowInfoProperties & NET::WMGeometry) { changes |= GeometryChanged; } if (dirty.netWindowInfoProperties & NET::WMWindowType) { changes |= WindowTypeChanged; } if (dirty.netWindowInfoProperties2 & NET::WM2AllowedActions) { changes |= ActionsChanged; } if (dirty.netWindowInfoProperties & NET::WMIcon) { refreshIcon(); } if (dirty.netWindowInfoProperties2 & NET::WM2Activities) { refreshActivities(); changes |= ActivitiesChanged; } if (changes != TaskUnchanged) { emit changed(changes); } return changes; } void Task::setActive(bool a) { d->active = a; TaskChanges changes = StateChanged; if (demandsAttention() != d->demandedAttention) { d->demandedAttention = !d->demandedAttention; changes |= AttentionChanged; } emit changed(changes); if (a) { emit activated(); } else { emit deactivated(); } } bool Task::isMaximized() const { return d->info.valid(true) && (d->info.state() & NET::MaxHoriz) && (d->info.state() & NET::MaxVert); } bool Task::isMinimized() const { return d->info.valid(true) && d->info.isMinimized(); } bool Task::isIconified() const { return d->info.valid(true) && d->info.isMinimized(); } bool Task::isAlwaysOnTop() const { return d->info.valid(true) && (d->info.state() & NET::StaysOnTop); } bool Task::isKeptBelowOthers() const { return d->info.valid(true) && (d->info.state() & NET::KeepBelow); } bool Task::isFullScreen() const { return d->info.valid(true) && (d->info.state() & NET::FullScreen); } bool Task::isShaded() const { return d->info.valid(true) && (d->info.state() & NET::Shaded); } bool Task::isOnCurrentDesktop() const { return d->info.valid(true) && d->info.isOnCurrentDesktop(); } bool Task::isOnAllDesktops() const { return d->info.valid(true) && d->info.onAllDesktops(); } bool Task::isActive() const { if (d->active) { return true; } const WId activeWindow = KWindowSystem::activeWindow(); foreach (WId window, d->transients) { if (activeWindow == window) { return true; } } return false; } bool Task::isOnTop() const { return TaskManager::self()->isOnTop(this); } bool Task::isModified() const { static QString modStr = QLatin1String("[") + i18nc("marks that a task has been modified", "modified") + QLatin1String("]"); int modStrPos = d->info.visibleName().indexOf(modStr); return (modStrPos != -1); } int Task::desktop() const { if (KWindowSystem::numberOfDesktops() < 2) { return 0; } return d->info.desktop(); } bool Task::demandsAttention() const { return (d->info.valid(true) && (d->info.state() & NET::DemandsAttention)) || !d->transientsDemandingAttention.isEmpty(); } bool Task::isOnScreen(const QRect& screen) const { return (d->info.valid(true) && d->info.geometry().intersects(screen)); } QRect Task::screen() const { QRect rv; if (!d->info.valid(true)) { return rv; } int area = 0; foreach (QScreen* screen, QGuiApplication::screens()) { const QRect desktopGeometry = screen->geometry(); const QRect onScreen = desktopGeometry.intersected(d->info.geometry()); if (onScreen.height() * onScreen.width() > area) { area = onScreen.height() * onScreen.width(); rv = screen->geometry(); } } return rv; } bool Task::showInTaskbar() const { return d->info.state() ^ NET::SkipTaskbar; } bool Task::showInPager() const { return d->info.state() ^ NET::SkipPager; } QRect Task::geometry() const { return d->info.geometry(); } void Task::removeTransient(WId w) { d->transients.remove(w); d->transientsDemandingAttention.remove(w); if (demandsAttention() != d->demandedAttention) { d->demandedAttention = !d->demandedAttention; emit changed(AttentionChanged); } } bool Task::hasTransient(WId w) const { return d->transients.contains(w); } WId Task::window() const { return d->win; } KWindowInfo Task::info() const { return d->info; } QString Task::visibleName() const { return d->info.visibleName(); } QString Task::visibleNameWithState() const { return d->info.visibleNameWithState(); } QString Task::name() const { return d->info.name(); } QPixmap Task::icon(int width, int height, bool allowResize) { if (width == d->lastWidth && height == d->lastHeight && allowResize == d->lastResize && !d->lastIcon.isNull()) { return d->lastIcon; } QPixmap newIcon = KWindowSystem::icon(d->win, width, height, allowResize); if (!newIcon.isNull()) { d->lastIcon = newIcon; d->lastWidth = width; d->lastHeight = height; d->lastResize = allowResize; } return newIcon; } QIcon Task::icon() { if (d->icon.isNull()) { d->icon.addPixmap(KWindowSystem::icon(d->win, KIconLoader::SizeSmall, KIconLoader::SizeSmall, false)); d->icon.addPixmap(KWindowSystem::icon(d->win, KIconLoader::SizeSmallMedium, KIconLoader::SizeSmallMedium, false)); d->icon.addPixmap(KWindowSystem::icon(d->win, KIconLoader::SizeMedium, KIconLoader::SizeMedium, false)); d->icon.addPixmap(KWindowSystem::icon(d->win, KIconLoader::SizeLarge, KIconLoader::SizeLarge, false)); } return d->icon; } WindowList Task::transients() const { return d->transients; } QPixmap Task::pixmap() const { return d->pixmap; } QPixmap Task::bestIcon(int size, bool &isStaticIcon) { QPixmap pixmap; isStaticIcon = false; switch (size) { case KIconLoader::SizeSmall: { pixmap = icon(16, 16, true); // Icon of last resort if (pixmap.isNull()) { pixmap = KIconLoader::global()->loadIcon(QStringLiteral("xorg"), KIconLoader::NoGroup, KIconLoader::SizeSmall); isStaticIcon = true; } } break; case KIconLoader::SizeMedium: { // // Try 34x34 first for KDE 2.1 icons with shadows, if we don't // get one then try 32x32. // pixmap = icon(34, 34, false); if (((pixmap.width() != 34) || (pixmap.height() != 34)) && ((pixmap.width() != 32) || (pixmap.height() != 32))) { pixmap = icon(32, 32, true); } // Icon of last resort if (pixmap.isNull()) { pixmap = KIconLoader::global()->loadIcon(QStringLiteral("xorg"), KIconLoader::NoGroup, KIconLoader::SizeMedium); isStaticIcon = true; } } break; case KIconLoader::SizeLarge: { // If there's a 48x48 icon in the hints then use it pixmap = icon(size, size, false); // If not, try to get one from the classname if (pixmap.isNull() || pixmap.width() != size || pixmap.height() != size) { pixmap = KIconLoader::global()->loadIcon(className(), KIconLoader::NoGroup, size, KIconLoader::DefaultState, QStringList(), 0L, true); isStaticIcon = true; } // If we still don't have an icon then scale the one in the hints if (pixmap.isNull() || (pixmap.width() != size) || (pixmap.height() != size)) { pixmap = icon(size, size, true); isStaticIcon = false; } // Icon of last resort if (pixmap.isNull()) { pixmap = KIconLoader::global()->loadIcon(QStringLiteral("xorg"), KIconLoader::NoGroup, size); isStaticIcon = true; } } } return pixmap; } bool Task::idMatch(const QString& id1, const QString& id2) { if (id1.isEmpty() || id2.isEmpty()) return false; if (id1.contains(id2) > 0) return true; if (id2.contains(id1) > 0) return true; return false; } void Task::toggleMaximized() { setMaximized(!isMaximized()); } void Task::setIconified(bool iconify) { // qDebug() <<" going to iconify" << d->win; if (iconify) { KWindowSystem::minimizeWindow(d->win); } else { KWindowInfo info(d->win, NET::WMState | NET::XAWMState | NET::WMDesktop); bool on_current = info.isOnCurrentDesktop(); if (!on_current) { KWindowSystem::setCurrentDesktop(info.desktop()); } KWindowSystem::unminimizeWindow(d->win); if (!on_current) { KWindowSystem::forceActiveWindow(d->win); } } } void Task::toggleIconified() { setIconified(!isIconified()); } void Task::raise() { // kDebug(1210) << "Task::raise(): " << name(); KWindowSystem::raiseWindow(d->win); } void Task::lower() { // kDebug(1210) << "Task::lower(): " << name(); KWindowSystem::lowerWindow(d->win); } void Task::activate() { WId w = d->win; if (!d->transientsDemandingAttention.isEmpty()) { WindowList::const_iterator it = d->transientsDemandingAttention.end(); --it; w = *it; } else if (!d->transients.isEmpty()) { WindowList::const_iterator it = d->transients.end(); --it; KWindowInfo info(*it, NET::WMState | NET::XAWMState | NET::WMDesktop); //this is a work around for (at least?) kwin where a shaded transient will prevent the main //window from being brought forward unless the transient is actually pulled forward, most //easily reproduced by opening a modal file open/save dialog on an app then shading the file //dialog and trying to bring the window forward by clicking on it in a tasks widget //TODO: do we need to check all the transients for shaded? if (info.valid(true) && (info.state() & NET::Shaded)) { w = *it; } } //kDebug(1210) << "Task::activate():" << name() << d->win << w; KWindowSystem::forceActiveWindow(w); } void Task::activateRaiseOrIconify() { //qDebug() << isActive() << isIconified() << isOnTop(); if (!isActive() || isIconified()) { activate(); } else if (!isOnTop()) { raise(); } else { setIconified(true); } } void Task::toCurrentDesktop() { toDesktop(KWindowSystem::currentDesktop()); } void Task::toggleAlwaysOnTop() { setAlwaysOnTop(!isAlwaysOnTop()); } void Task::toggleKeptBelowOthers() { setKeptBelowOthers(!isKeptBelowOthers()); } void Task::toggleFullScreen() { setFullScreen(!isFullScreen()); } void Task::toggleShaded() { setShaded(!isShaded()); } void Task::clearPixmapData() { d->lastIcon = QPixmap(); d->pixmap = QPixmap(); d->icon = QIcon(); } void Task::addMimeData(QMimeData *mimeData) const { Q_ASSERT(mimeData); QByteArray data; data.resize(sizeof(WId)); memcpy(data.data(), &d->win, sizeof(WId)); mimeData->setData(mimetype(), data); } QString Task::mimetype() { return QStringLiteral("windowsystem/winid"); } QString Task::groupMimetype() { return QStringLiteral("windowsystem/multiple-winids"); } QList Task::idsFromMimeData(const QMimeData *mimeData, bool *ok) { Q_ASSERT(mimeData); QList ids; if (ok) { *ok = false; } if (!mimeData->hasFormat(groupMimetype())) { // try to grab a singular id if it exists //qDebug() << "not group type"; bool singularOk; WId id = idFromMimeData(mimeData, &singularOk); if (ok) { *ok = singularOk; } if (singularOk) { //qDebug() << "and singular failed, too"; ids << id; } return ids; } QByteArray data(mimeData->data(groupMimetype())); if ((unsigned int)data.size() < sizeof(int) + sizeof(WId)) { //qDebug() << "wrong size" << data.size() << sizeof(int) + sizeof(WId); return ids; } int count = 0; memcpy(&count, data.data(), sizeof(int)); if (count < 1 || (unsigned int)data.size() < sizeof(int) + sizeof(WId) * count) { //qDebug() << "wrong size, 2" << data.size() << count << sizeof(int) + sizeof(WId) * count; return ids; } WId id; for (int i = 0; i < count; ++i) { memcpy(&id, data.data() + sizeof(int) + sizeof(WId) * i, sizeof(WId)); ids << id; } if (ok) { *ok = true; } return ids; } WId Task::idFromMimeData(const QMimeData *mimeData, bool *ok) { Q_ASSERT(mimeData); if (ok) { *ok = false; } if (!mimeData->hasFormat(mimetype())) { return 0; } QByteArray data(mimeData->data(mimetype())); if (data.size() != sizeof(WId)) { return 0; } WId id; memcpy(&id, data.data(), sizeof(WId)); if (ok) { *ok = true; } return id; } bool Task::isOnCurrentActivity() const { return d->activities.isEmpty() || d->activities.contains(TaskManager::self()->currentActivity()); } bool Task::isOnAllActivities() const { return d->activities.isEmpty(); } QStringList Task::activities() const { return d->activities; } Task::WindowProperties::WindowProperties(unsigned int netWinInfoProperties, unsigned int netWinInfoProperties2) : netWindowInfoProperties(netWinInfoProperties), netWindowInfoProperties2(netWinInfoProperties2) { } } // TaskManager namespace