Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Taskbar] Add name field #1240

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/modules/wlr/taskbar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Task

std::string title_;
std::string app_id_;
std::string name_;
uint32_t state_ = 0;

private:
Expand All @@ -83,6 +84,7 @@ class Task
uint32_t id() const { return id_; }
std::string title() const { return title_; }
std::string app_id() const { return app_id_; }
std::string name() const { return name_; }
uint32_t state() const { return state_; }
bool maximized() const { return state_ & MAXIMIZED; }
bool minimized() const { return state_ & MINIMIZED; }
Expand Down
2 changes: 2 additions & 0 deletions man/waybar-wlr-taskbar.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Addressed by *wlr/taskbar*

*{app_id}*: The app_id (== application name) of the application.

*{name}*: The name of the application.

*{state}*: The state (minimized, maximized, active, fullscreen) of the application.

*{short_state}*: The state (minimize == m, maximized == M, active == A, fullscreen == F) represented as one character of the application.
Expand Down
47 changes: 34 additions & 13 deletions src/modules/wlr/taskbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ static std::string trim(const std::string& s)
}


/* Icon loading functions */
static std::vector<std::string> search_prefix()
{
std::vector<std::string> prefixes = {""};
Expand Down Expand Up @@ -76,18 +75,7 @@ static std::vector<std::string> search_prefix()
return prefixes;
}

static Glib::RefPtr<Gdk::Pixbuf> load_icon_from_file(std::string icon_path, int size)
{
try {
auto pb = Gdk::Pixbuf::create_from_file(icon_path, size, size);
return pb;
} catch(...) {
return {};
}
}

/* Method 1 - get the correct icon name from the desktop file */
static std::string get_from_desktop_app_info(const std::string &app_id)
Glib::RefPtr<Gio::DesktopAppInfo> gen_app_info(const std::string app_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why gen* instead of get*?

{
static std::vector<std::string> prefixes = search_prefix();

Expand All @@ -111,6 +99,25 @@ static std::string get_from_desktop_app_info(const std::string &app_id)
if (!app_info)
app_info = Gio::DesktopAppInfo::create_from_filename(prefix + folder + app_id + suffix);

return app_info;
}

/* Icon loading functions */
static Glib::RefPtr<Gdk::Pixbuf> load_icon_from_file(std::string icon_path, int size)
{
try {
auto pb = Gdk::Pixbuf::create_from_file(icon_path, size, size);
return pb;
} catch(...) {
return {};
}
}

/* Method 1 - get the correct icon name from the desktop file */
static std::string get_from_desktop_app_info(const std::string &app_id)
{
Glib::RefPtr<Gio::DesktopAppInfo> app_info = gen_app_info(app_id);

if (app_info && app_info->get_icon())
return app_info->get_icon()->to_string();

Expand Down Expand Up @@ -383,6 +390,15 @@ void Task::handle_app_id(const char *app_id)
{
app_id_ = app_id;

Glib::RefPtr<Gio::DesktopAppInfo> app_info = gen_app_info(app_id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case missing icon and name options it will cost unnecessary overhead. And it will be searched twice, as app_info was't saved.


if(app_info) {
name_ = app_info->get_display_name();
}
else {
name_ = app_id;
}

if (tbar_->ignore_list().count(app_id)) {
ignored_ = true;
if (button_visible_) {
Expand Down Expand Up @@ -561,14 +577,17 @@ void Task::update()
bool markup = config_["markup"].isBool() ? config_["markup"].asBool() : false;
std::string title = title_;
std::string app_id = app_id_;
std::string name = name_;
if (markup) {
title = Glib::Markup::escape_text(title);
app_id = Glib::Markup::escape_text(app_id);
name = Glib::Markup::escape_text(name);
}
if (!format_before_.empty()) {
auto txt = fmt::format(format_before_,
fmt::arg("title", title),
fmt::arg("app_id", app_id),
fmt::arg("name", name),
fmt::arg("state", state_string()),
fmt::arg("short_state", state_string(true))
);
Expand All @@ -582,6 +601,7 @@ void Task::update()
auto txt = fmt::format(format_after_,
fmt::arg("title", title),
fmt::arg("app_id", app_id),
fmt::arg("name", name),
fmt::arg("state", state_string()),
fmt::arg("short_state", state_string(true))
);
Expand All @@ -596,6 +616,7 @@ void Task::update()
auto txt = fmt::format(format_tooltip_,
fmt::arg("title", title),
fmt::arg("app_id", app_id),
fmt::arg("name", name),
fmt::arg("state", state_string()),
fmt::arg("short_state", state_string(true))
);
Expand Down