Commit 268a2ccc authored by kimidaisuki22's avatar kimidaisuki22

add support for linux.

parent 34763fc8
...@@ -12,10 +12,16 @@ target_include_directories(tray ...@@ -12,10 +12,16 @@ target_include_directories(tray
if(UNIX AND NOT APPLE) if(UNIX AND NOT APPLE)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
pkg_check_modules(APPINDICATOR REQUIRED appindicator3-0.1) message(STATUS "To install appindicator3[ayatana-appindicator3-0.1], sudo apt install libayatana-appindicator3-dev")
pkg_check_modules(APPINDICATOR REQUIRED ayatana-appindicator3-0.1)
target_compile_options(tray PRIVATE ${APPINDICATOR_CFLAGS}) target_compile_options(tray PRIVATE ${APPINDICATOR_CFLAGS})
target_link_libraries(tray PRIVATE ${APPINDICATOR_LIBRARIES}) target_link_libraries(tray PRIVATE ${APPINDICATOR_LIBRARIES})
target_link_directories(tray PRIVATE ${APPINDICATOR_LIBRARY_DIRS}) target_link_directories(tray PRIVATE ${APPINDICATOR_LIBRARY_DIRS})
pkg_check_modules(GTK REQUIRED gtk+-3.0)
target_compile_options(tray PRIVATE ${GTK_CFLAGS})
target_link_libraries(tray PRIVATE ${GTK_LIBRARIES})
target_link_directories(tray PRIVATE ${GTK_LIBRARY_DIRS})
elseif(APPLE) elseif(APPLE)
target_link_libraries(tray PRIVATE "-framework Cocoa") target_link_libraries(tray PRIVATE "-framework Cocoa")
endif() endif()
......
#include "tray/tray.h" #include "tray/tray.h"
#include <filesystem>
#include <stdlib.h> #include <stdlib.h>
int main() { int main() {
trays::Menu m; trays::Menu m;
m.text_ = "Open work dir"; m.text_ = "Open work dir";
m.on_click_ = [](auto) { system("start ."); }; m.on_click_ = [](auto) { system("open ."); };
trays::Tray t{"icon.ico", {m}};
// absolute path for linux.
// linux: png, svg
std::string icon_name = "icon.png";
auto icon_path =std::filesystem::current_path() / icon_name;
trays::Tray t{icon_path.string(), {m}};
// t.add(m); // t.add(m);
t.run(); t.run();
} }
\ No newline at end of file
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <libappindicator/app-indicator.h> #include <libayatana-appindicator/app-indicator.h>
#define TRAY_APPINDICATOR_ID "tray-id" #define TRAY_APPINDICATOR_ID "tray-id"
...@@ -38,7 +38,7 @@ static GtkMenuShell *_tray_menu(struct tray_menu *m) { ...@@ -38,7 +38,7 @@ static GtkMenuShell *_tray_menu(struct tray_menu *m) {
return menu; return menu;
} }
static int tray_init(struct tray *tray) { int tray_init(struct tray *tray) {
if (gtk_init_check(0, NULL) == FALSE) { if (gtk_init_check(0, NULL) == FALSE) {
return -1; return -1;
} }
...@@ -49,16 +49,16 @@ static int tray_init(struct tray *tray) { ...@@ -49,16 +49,16 @@ static int tray_init(struct tray *tray) {
return 0; return 0;
} }
static int tray_loop(int blocking) { int tray_loop(int blocking) {
gtk_main_iteration_do(blocking); gtk_main_iteration_do(blocking);
return loop_result; return loop_result;
} }
static void tray_update(struct tray *tray) { void tray_update(struct tray *tray) {
app_indicator_set_icon(indicator, tray->icon); app_indicator_set_icon(indicator, tray->icon);
// GTK is all about reference counting, so previous menu should be destroyed // GTK is all about reference counting, so previous menu should be destroyed
// here // here
app_indicator_set_menu(indicator, GTK_MENU(_tray_menu(tray->menu))); app_indicator_set_menu(indicator, GTK_MENU(_tray_menu(tray->menu)));
} }
static void tray_exit() { loop_result = -1; } void tray_exit() { loop_result = -1; }
\ No newline at end of file \ No newline at end of file
#include "tray/tray_raw.h" #include "tray/tray_raw.h"
#if defined(TRAY_APPINDICATOR) #if defined(__linux__)
#include "linux.h" #include "linux.h"
#elif defined(TRAY_APPKIT) #elif defined(TARGET_OS_MAC)
#include "macos.h" #include "macos.h"
#elif defined(_WIN32) #elif defined(_WIN32)
#include "windows.h" #include "windows.h"
......
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