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

Add custom labels on launchers from cmd+icon combo #51

Merged
merged 5 commits into from
May 3, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
38 changes: 26 additions & 12 deletions src/panel/widgets/launchers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,16 @@ struct FileLauncherInfo : public LauncherInfo
{
std::string command;
std::string icon;
std::string label;

bool load(std::string name, std::string icon)
bool load(std::string command, std::string icon, std::string label)
{
command = name;
this->command = command;
this->icon = icon;
if(label == "")
ammen99 marked this conversation as resolved.
Show resolved Hide resolved
this->label = command;
else
this->label = label;

return load_icon_pixbuf_safe(icon, 24).get() != nullptr;
}
Expand All @@ -78,7 +83,7 @@ struct FileLauncherInfo : public LauncherInfo

std::string get_text()
{
return command;
return label;
}

void execute()
Expand All @@ -104,7 +109,7 @@ void WfLauncherButton::set_size(int size)
on_scale_update();
}

bool WfLauncherButton::initialize(std::string name, std::string icon)
bool WfLauncherButton::initialize(std::string name, std::string icon, std::string label)
{
launcher_name = name;
base_size = WfOption<int> {"panel/launcher_size"} / LAUNCHERS_ICON_SCALE;
Expand All @@ -120,7 +125,7 @@ bool WfLauncherButton::initialize(std::string name, std::string icon)
} else
{
auto fl = new FileLauncherInfo();
if (!fl->load(name, icon))
if (!fl->load(name, icon, label))
{
std::cerr << "Failed to load icon " << icon << std::endl;
return false;
Expand Down Expand Up @@ -248,13 +253,14 @@ launcher_container WayfireLaunchers::get_launchers_from_config()
const std::string desktop_prefix = "launcher_";
const std::string file_icon_prefix = "launcher_icon_";
const std::string file_cmd_prefix = "launcher_cmd_";
const std::string file_label_prefix = "launcher_label_";

launcher_container launchers;
auto try_push_launcher = [&launchers] (
const std::string cmd, const std::string icon)
const std::string cmd, const std::string icon, const std::string label = "")
{
auto launcher = new WfLauncherButton();
if (launcher->initialize(cmd, icon)) {
if (launcher->initialize(cmd, icon, label)) {
launchers.push_back(std::unique_ptr<WfLauncherButton>(launcher));
} else {
delete launcher;
Expand All @@ -272,17 +278,25 @@ launcher_container WayfireLaunchers::get_launchers_from_config()
auto icon_option = section->get_option_or(file_icon_prefix + launcher_name);
if (icon_option)
{
/* bingo, found command + icon */
try_push_launcher(opt->get_value_str(),
icon_option->get_value_str());
/* bingo, found command + icon
* now look for the corresponding label */
auto label_option = section->get_option_or(file_label_prefix + launcher_name);
if(label_option)
{
/* found label */
try_push_launcher(opt->get_value_str(), icon_option->get_value_str(), label_option->get_value_str());
ammen99 marked this conversation as resolved.
Show resolved Hide resolved
} else {
try_push_launcher(opt->get_value_str(), icon_option->get_value_str());
}
}
}

/* an entry is a deskop-file entry if the it has the desktop prefix
* but not the file_icon or file_cmd prefix */
* but not the file_icon, file_cmd or file_label prefix */
if (begins_with(opt->get_name(), desktop_prefix) &&
!begins_with(opt->get_name(), file_icon_prefix) &&
!begins_with(opt->get_name(), file_cmd_prefix))
!begins_with(opt->get_name(), file_cmd_prefix) &&
!begins_with(opt->get_name(), file_label_prefix))
{
try_push_launcher(opt->get_value_str(), "none");
}
Expand Down
2 changes: 1 addition & 1 deletion src/panel/widgets/launchers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct WfLauncherButton
WfLauncherButton& operator = (const WfLauncherButton&) = delete;
~WfLauncherButton();

bool initialize(std::string name, std::string icon = "none");
bool initialize(std::string name, std::string icon = "none", std::string label = "");

bool on_click(GdkEventButton *ev);
bool on_enter(GdkEventCrossing *ev);
Expand Down