Skip to content

Commit

Permalink
Add custom labels on launchers from cmd+icon combo (#51)
Browse files Browse the repository at this point in the history
* Add 'label' varible to FileLauncherInfo struct

* Add label argument to WfLauncherButton::initialize() & pass it to f1->load()

* Get label value from config

* Add braces for better readability

* Brake to long line
  • Loading branch information
mpolosak committed May 3, 2020
1 parent d865383 commit 0ae02ab
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
42 changes: 29 additions & 13 deletions src/panel/widgets/launchers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,18 @@ 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 == "")
{
this->label = command;
} else {
this->label = label;
}
return load_icon_pixbuf_safe(icon, 24).get() != nullptr;
}

Expand All @@ -78,7 +84,7 @@ struct FileLauncherInfo : public LauncherInfo

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

void execute()
Expand All @@ -104,7 +110,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 +126,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 +254,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 +279,26 @@ 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());
} 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

0 comments on commit 0ae02ab

Please sign in to comment.