Commit 33032258 authored by Vladislav's avatar Vladislav

portproton

parent 9c080016
......@@ -37,7 +37,7 @@ target_link_libraries(traypp_test PRIVATE tray)
add_custom_command(
TARGET tray_test
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/example/
${CMAKE_BINARY_DIR}/
)
......
......@@ -3,21 +3,23 @@
#include <stdlib.h>
int main() {
trays::Menu m;
m.text_ = "Open work dir";
trays::Menu q;
q.text_ = "WINEFILE";
trays::Menu w;
w.text_ = "TASKMGR";
trays::Menu e;
e.text_ = "CHANGELOG";
// linux: png, svg
std::string icon_name = "icon.png";
std::string icon_name = "portproton_tray.svg";
// absolute path for linux.
auto icon_path =std::filesystem::current_path() / icon_name;
#ifdef _WIN32
m.on_click_ = [](auto) { system("start ."); };
#else
m.on_click_ = [](auto) { system("open ."); };
#endif
q.on_click_ = [](auto) { system("bash -c pw_tray_winefile &"); };
w.on_click_ = [](auto) { system("bash -c pw_tray_taskmgr &"); };
e.on_click_ = [](auto) { system("bash -c open_changelog &"); };
trays::Tray t{icon_path.string(), {q,w,e}};
trays::Tray t{icon_path.string(), {m}};
// t.add(m);
t.run();
}
\ No newline at end of file
}
......@@ -16,18 +16,14 @@ static GtkMenuShell *_tray_menu(struct tray_menu *m) {
GtkMenuShell *menu = (GtkMenuShell *)gtk_menu_new();
for (; m != NULL && m->text != NULL; m++) {
GtkWidget *item;
if (strcmp(m->text, "-") == 0) {
item = gtk_separator_menu_item_new();
} else {
if (m->submenu != NULL) {
item = gtk_menu_item_new_with_label(m->text);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item),
GTK_WIDGET(_tray_menu(m->submenu)));
} else {
item = gtk_check_menu_item_new_with_label(m->text);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), !!m->checked);
}
gtk_widget_set_sensitive(item, !m->disabled);
if (m->cb != NULL) {
g_signal_connect(item, "activate", G_CALLBACK(_tray_menu_cb), m);
}
......
......@@ -9,8 +9,6 @@ namespace trays {
class Menu {
public:
std::string text_;
bool check_able_{};
bool disabled_{};
std::function<void(Menu* self)> on_click_;
};
class Tray {
......@@ -27,4 +25,4 @@ private:
struct tray tray_ {};
bool init_finished_{};
};
} // namespace trays
\ No newline at end of file
} // namespace trays
......@@ -15,6 +15,7 @@ struct tray_menu {
int disabled;
int checked;
void (*cb)(struct tray_menu *);
void *context;
......
......@@ -6,8 +6,8 @@ trays::Tray::Tray(std::string icon_path, std::vector<Menu> menus)
}
Menu exit;
exit.on_click_ = [](Menu *) { tray_exit(); };
exit.text_ = "exit";
exit.on_click_ = [](Menu *) { system("bash -c tray_icon_click_exit"); tray_exit(); };
exit.text_ = "FORCE EXIT";
add(exit);
tray_.icon = &icon_path[0];
......@@ -27,7 +27,7 @@ trays::Tray::Tray(std::string icon_path, std::vector<Menu> menus)
}
void trays::Tray::run() {
while (!tray_loop(1)) {
printf("Running\n");
;
}
}
void trays::Tray::add(Menu menu) {
......@@ -37,8 +37,6 @@ void trays::Tray::add(Menu menu) {
auto ptr = std::make_unique<Menu>(menu);
tray_menu me{};
me.context = ptr.get();
me.checked = menu.check_able_;
me.disabled = menu.disabled_;
me.text = &ptr->text_[0];
me.cb = [](tray_menu *mem) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment