forked from quickshell/quickshell
service/tray: provide default sorting for SystemTray.items
Items are first sorted by category, and then by name.
This commit is contained in:
parent
392f56c40e
commit
69430e3873
3 changed files with 30 additions and 2 deletions
|
@ -17,10 +17,20 @@ SystemTray::SystemTray(QObject* parent): QObject(parent) {
|
|||
// clang-format on
|
||||
|
||||
for (auto* item: host->items()) {
|
||||
this->mItems.insertObject(item);
|
||||
this->mItems.insertObjectSorted(item, &SystemTray::compareItems);
|
||||
}
|
||||
}
|
||||
|
||||
void SystemTray::onItemRegistered(StatusNotifierItem* item) { this->mItems.insertObject(item); }
|
||||
void SystemTray::onItemRegistered(StatusNotifierItem* item) {
|
||||
this->mItems.insertObjectSorted(item, &SystemTray::compareItems);
|
||||
}
|
||||
|
||||
void SystemTray::onItemUnregistered(StatusNotifierItem* item) { this->mItems.removeObject(item); }
|
||||
ObjectModel<StatusNotifierItem>* SystemTray::items() { return &this->mItems; }
|
||||
|
||||
bool SystemTray::compareItems(
|
||||
qs::service::sni::StatusNotifierItem* a,
|
||||
qs::service::sni::StatusNotifierItem* b
|
||||
) {
|
||||
return a->category() > b->category() || a->id().compare(b->id(), Qt::CaseInsensitive) >= 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue