Skip to content

Commit 0ae02ab

Browse files
authored
Add custom labels on launchers from cmd+icon combo (#51)
* 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
1 parent d865383 commit 0ae02ab

2 files changed

Lines changed: 30 additions & 14 deletions

File tree

src/panel/widgets/launchers.cpp

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,18 @@ struct FileLauncherInfo : public LauncherInfo
6262
{
6363
std::string command;
6464
std::string icon;
65+
std::string label;
6566

66-
bool load(std::string name, std::string icon)
67+
bool load(std::string command, std::string icon, std::string label)
6768
{
68-
command = name;
69+
this->command = command;
6970
this->icon = icon;
70-
71+
if(label == "")
72+
{
73+
this->label = command;
74+
} else {
75+
this->label = label;
76+
}
7177
return load_icon_pixbuf_safe(icon, 24).get() != nullptr;
7278
}
7379

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

7985
std::string get_text()
8086
{
81-
return command;
87+
return label;
8288
}
8389

8490
void execute()
@@ -104,7 +110,7 @@ void WfLauncherButton::set_size(int size)
104110
on_scale_update();
105111
}
106112

107-
bool WfLauncherButton::initialize(std::string name, std::string icon)
113+
bool WfLauncherButton::initialize(std::string name, std::string icon, std::string label)
108114
{
109115
launcher_name = name;
110116
base_size = WfOption<int> {"panel/launcher_size"} / LAUNCHERS_ICON_SCALE;
@@ -120,7 +126,7 @@ bool WfLauncherButton::initialize(std::string name, std::string icon)
120126
} else
121127
{
122128
auto fl = new FileLauncherInfo();
123-
if (!fl->load(name, icon))
129+
if (!fl->load(name, icon, label))
124130
{
125131
std::cerr << "Failed to load icon " << icon << std::endl;
126132
return false;
@@ -248,13 +254,14 @@ launcher_container WayfireLaunchers::get_launchers_from_config()
248254
const std::string desktop_prefix = "launcher_";
249255
const std::string file_icon_prefix = "launcher_icon_";
250256
const std::string file_cmd_prefix = "launcher_cmd_";
257+
const std::string file_label_prefix = "launcher_label_";
251258

252259
launcher_container launchers;
253260
auto try_push_launcher = [&launchers] (
254-
const std::string cmd, const std::string icon)
261+
const std::string cmd, const std::string icon, const std::string label = "")
255262
{
256263
auto launcher = new WfLauncherButton();
257-
if (launcher->initialize(cmd, icon)) {
264+
if (launcher->initialize(cmd, icon, label)) {
258265
launchers.push_back(std::unique_ptr<WfLauncherButton>(launcher));
259266
} else {
260267
delete launcher;
@@ -272,17 +279,26 @@ launcher_container WayfireLaunchers::get_launchers_from_config()
272279
auto icon_option = section->get_option_or(file_icon_prefix + launcher_name);
273280
if (icon_option)
274281
{
275-
/* bingo, found command + icon */
276-
try_push_launcher(opt->get_value_str(),
277-
icon_option->get_value_str());
282+
/* bingo, found command + icon
283+
* now look for the corresponding label */
284+
auto label_option = section->get_option_or(file_label_prefix + launcher_name);
285+
if(label_option)
286+
{
287+
/* found label */
288+
try_push_launcher(opt->get_value_str(), icon_option->get_value_str(),
289+
label_option->get_value_str());
290+
} else {
291+
try_push_launcher(opt->get_value_str(), icon_option->get_value_str());
292+
}
278293
}
279294
}
280295

281296
/* an entry is a deskop-file entry if the it has the desktop prefix
282-
* but not the file_icon or file_cmd prefix */
297+
* but not the file_icon, file_cmd or file_label prefix */
283298
if (begins_with(opt->get_name(), desktop_prefix) &&
284299
!begins_with(opt->get_name(), file_icon_prefix) &&
285-
!begins_with(opt->get_name(), file_cmd_prefix))
300+
!begins_with(opt->get_name(), file_cmd_prefix) &&
301+
!begins_with(opt->get_name(), file_label_prefix))
286302
{
287303
try_push_launcher(opt->get_value_str(), "none");
288304
}

src/panel/widgets/launchers.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct WfLauncherButton
4949
WfLauncherButton& operator = (const WfLauncherButton&) = delete;
5050
~WfLauncherButton();
5151

52-
bool initialize(std::string name, std::string icon = "none");
52+
bool initialize(std::string name, std::string icon = "none", std::string label = "");
5353

5454
bool on_click(GdkEventButton *ev);
5555
bool on_enter(GdkEventCrossing *ev);

0 commit comments

Comments
 (0)