Skip to content

Commit

Permalink
Respect NoDisplay=true #84
Browse files Browse the repository at this point in the history
  • Loading branch information
nwg-piotr committed Aug 22, 2020
1 parent 40e9234 commit 8bb44db
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
1 change: 1 addition & 0 deletions common/nwg_classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ struct DesktopEntry {
std::string exec;
std::string icon;
std::string comment;
bool no_display {false};
};
39 changes: 22 additions & 17 deletions grid/grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,17 @@ int main(int argc, char *argv[]) {
/* Create buttons for all desktop entries */
/* @Siborgium: We can not std::move them here, it breaks favourites: (de.exec == entry.exec) is always false */
for (auto& entry : desktop_entries) {
if (std::find(pinned.begin(), pinned.end(), entry.exec) == pinned.end()) {
auto& ab = window.all_boxes.emplace_back(entry.name,
entry.exec,
entry.comment,
false);
Gtk::Image* image = app_image(icon_theme_ref, entry.icon);
ab.set_image_position(Gtk::POS_TOP);
ab.set_image(*image);
// Ignore .desktop entries with NoDisplay=true
if (!entry.no_display) {
if (std::find(pinned.begin(), pinned.end(), entry.exec) == pinned.end()) {
auto& ab = window.all_boxes.emplace_back(entry.name,
entry.exec,
entry.comment,
false);
Gtk::Image* image = app_image(icon_theme_ref, entry.icon);
ab.set_image_position(Gtk::POS_TOP);
ab.set_image(*image);
}
}
}
window.label_desc.set_text(std::to_string(window.all_boxes.size()));
Expand All @@ -323,7 +326,7 @@ int main(int argc, char *argv[]) {
if (favs && favourites.size() > 0) {
for (auto& entry : favourites) {
for (auto& de : desktop_entries) {
if (de.exec == entry.exec) {
if (de.exec == entry.exec && !de.no_display) {

// avoid adding twice the same exec w/ another name
bool already_added {false};
Expand Down Expand Up @@ -353,14 +356,16 @@ int main(int argc, char *argv[]) {
/* Create buttons for pinned entries */
if (pins && pinned.size() > 0) {
for(auto& entry : desktop_entries) {
if (std::find(pinned.begin(), pinned.end(), entry.exec) != pinned.end()) {
auto& ab = window.pinned_boxes.emplace_back(std::move(entry.name),
std::move(entry.exec),
std::move(entry.comment),
true);
Gtk::Image* image = app_image(icon_theme_ref, entry.icon);
ab.set_image_position(Gtk::POS_TOP);
ab.set_image(*image);
if (!entry.no_display) {
if (std::find(pinned.begin(), pinned.end(), entry.exec) != pinned.end()) {
auto& ab = window.pinned_boxes.emplace_back(std::move(entry.name),
std::move(entry.exec),
std::move(entry.comment),
true);
Gtk::Image* image = app_image(icon_theme_ref, entry.icon);
ab.set_image_position(Gtk::POS_TOP);
ab.set_image(*image);
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions grid/grid_tools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ DesktopEntry desktop_entry(std::string&& path, const std::string& lang) {
}
}
if (read_me) {
// This is to resolve `Respect the NoDisplay setting in .desktop files #84`,
// see https://wiki.archlinux.org/index.php/desktop_entries#Hide_desktop_entries.
// The ~/.local/share/applications folder is going to be read first. Entries created from here won't be
// overwritten from e.g. /usr/share/applications, as duplicates are being skipped.
if (view.find("NoDisplay=true") == 0) {
entry.no_display = true;
}

if (view.find(loc_name) == 0) {
if (auto idx = view.find_first_of("="); idx != std::string_view::npos) {
name_ln = view.substr(idx + 1);
Expand Down

0 comments on commit 8bb44db

Please sign in to comment.