Skip to content

Commit

Permalink
gtk3: support libayatana-appindicator3-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilledheart committed Jun 18, 2024
1 parent 774d705 commit a39a99e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
4 changes: 3 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ Package: yass
Architecture: any
Pre-Depends: ${misc:Pre-Depends}
Build-Profiles: <gtk3> <gtk4> <qt5> <qt6>
Recommends: libappindicator3-1 <gtk3>
Recommends:
libappindicator3-1 <gtk3>,
libayatana-appindicator3-1 <gtk3>
Depends:
lsb-base (>= 3.0-6),
ca-certificates,
Expand Down
28 changes: 19 additions & 9 deletions src/gtk/app-indicator-override.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <stdlib.h>

extern int app_indicator_init(void);
extern void app_indicator_uninit(void);

extern int app_indicator_get_type(void);
extern void* app_indicator_new(const char*, const char*, int);
Expand All @@ -27,7 +28,10 @@ int app_indicator_init(void) {
if (app_indicator_lib != NULL) {
return 0;
}
app_indicator_lib = dlopen("libappindicator3.so.1", RTLD_LAZY);
app_indicator_lib = dlopen("libayatana-appindicator3.so.1", RTLD_LAZY);
if (app_indicator_lib == NULL) {
app_indicator_lib = dlopen("libappindicator3.so.1", RTLD_LAZY);
}
if (app_indicator_lib != NULL) {
o_app_indicator_get_type = dlsym(app_indicator_lib, "app_indicator_get_type");
o_app_indicator_new = dlsym(app_indicator_lib, "app_indicator_new");
Expand All @@ -39,19 +43,25 @@ int app_indicator_init(void) {
if (o_app_indicator_get_type == NULL || o_app_indicator_new == NULL || o_app_indicator_new_with_path == NULL ||
o_app_indicator_set_status == NULL || o_app_indicator_set_menu == NULL ||
o_app_indicator_set_secondary_activate_target == NULL) {
o_app_indicator_get_type = NULL;
o_app_indicator_new = NULL;
o_app_indicator_new_with_path = NULL;
o_app_indicator_set_status = NULL;
o_app_indicator_set_menu = NULL;
o_app_indicator_set_secondary_activate_target = NULL;
dlclose(app_indicator_lib);
app_indicator_lib = NULL;
app_indicator_uninit();
}
}
return app_indicator_lib == NULL ? -1 : 0;
}

void app_indicator_uninit(void) {
if (app_indicator_lib != NULL) {
o_app_indicator_get_type = NULL;
o_app_indicator_new = NULL;
o_app_indicator_new_with_path = NULL;
o_app_indicator_set_status = NULL;
o_app_indicator_set_menu = NULL;
o_app_indicator_set_secondary_activate_target = NULL;
dlclose(app_indicator_lib);
app_indicator_lib = NULL;
}
}

int app_indicator_get_type(void) {
assert(o_app_indicator_get_type && "app_indicator_init is required to call first");

Expand Down
7 changes: 7 additions & 0 deletions src/gtk/yass_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#ifdef HAVE_APP_INDICATOR
extern "C" int app_indicator_init();
extern "C" void app_indicator_uninit();
#include "third_party/libappindicator/app-indicator.h"
#endif

Expand Down Expand Up @@ -259,6 +260,12 @@ YASSWindow::~YASSWindow() {
if (tray_icon_) {
g_object_unref(G_OBJECT(tray_icon_));
}
#ifdef HAVE_APP_INDICATOR
if (tray_indicator_) {
g_object_unref(G_OBJECT(tray_indicator_));
}
app_indicator_uninit();
#endif
}

void YASSWindow::CreateStatusIcon() {
Expand Down
2 changes: 1 addition & 1 deletion src/gtk/yass_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class YASSWindow {
G_GNUC_END_IGNORE_DEPRECATIONS

#ifdef HAVE_APP_INDICATOR
GObject* tray_indicator_;
GObject* tray_indicator_ = nullptr;
#endif

public:
Expand Down

0 comments on commit a39a99e

Please sign in to comment.