Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverRainZ committed Oct 22, 2023
1 parent 448e5c1 commit 098c7bb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
#
# As of meson 0.47.0 -Dopt= and -Dopt=[] both pass an empty list,
# before this -Dopt= would pass a list with an empty string.
meson setup -Ddoc_builders=[] \
meson setup -Ddoc_builders=[] -Dapp_indicator=false \
--prefix=$MINGW_PREFIX \
--datadir=$MINGW_PREFIX/share \
--sysconfdir=$MINGW_PREFIX/etc \
Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
option('doc_builders', type : 'array', choices : ['html', 'man'], value : [])
option('app_indicator', type : 'boolean', value : true)
5 changes: 4 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,13 @@ deps = [
dependency('libsoup-2.4'),
dependency('openssl'),
dependency('libsecret-1'),
dependency('ayatana-appindicator3-0.1'),
generated_meta_h,
]

if get_option('app_indicator')
deps += [dependency('ayatana-appindicator3-0.1')]
endif

incdirs = [
include_directories('inc'),
include_directories('config'),
Expand Down
28 changes: 28 additions & 0 deletions src/sui/sui_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
*/

#include <gtk/gtk.h>

#ifdef ENABLE_APP_INDICATOR
#include <libayatana-appindicator/app-indicator.h>
#endif

#include "sui/sui.h"
#include "meta.h"
Expand All @@ -42,7 +45,12 @@
struct _SuiApplication {
GtkApplication parent;

#ifdef ENABLE_APP_INDICATOR
AppIndicator *tray_icon;
#else
GtkStatusIcon *tray_icon;
#endif

// GtkPopover can not shown at outside of GtkWindow on X11,
// so we need another traditional menu as tray icon menu.
GtkMenu *menu;
Expand Down Expand Up @@ -86,6 +94,10 @@ static void on_activate_exit(GSimpleAction *action, GVariant *parameter,
static void on_toggle_server_visibility(GSimpleAction *action, GVariant *parameter,
gpointer user_data);
static void tray_icon_on_click(GtkStatusIcon *status_icon, gpointer user_data);
#ifdef ENABLE_APP_INDICATOR
static void tray_icon_on_popup_menu(GtkStatusIcon *status_icon, guint button,
guint activate_time, gpointer user_data);
#endif

/*****************************************************************************
* GObject functions
Expand Down Expand Up @@ -457,11 +469,16 @@ static void on_startup(SuiApplication *self){
gtk_builder_get_object(builder, "popover_menu")));
g_object_unref(builder);

#ifdef ENABLE_APP_INDICATOR
self->tray_icon = app_indicator_new(PACKAGE_APPID, PACKAGE_APPID,
APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
app_indicator_set_status(self->tray_icon, APP_INDICATOR_STATUS_ACTIVE);
app_indicator_set_attention_icon(self->tray_icon, "srain-red");
app_indicator_set_menu(self->tray_icon, self->menu);
#else
self->tray_icon = gtk_status_icon_new_from_icon_name(PACKAGE_APPID);
#endif
gtk_widget_set_tooltip_text(GTK_WIDGET(self->tray_icon), PACKAGE);

// Attach to any widget to connect to action
gtk_menu_attach_to_widget(self->menu, GTK_WIDGET(self->popover_menu), NULL);
Expand Down Expand Up @@ -601,3 +618,14 @@ static void tray_icon_on_click(GtkStatusIcon *status_icon, gpointer user_data){
gtk_widget_set_visible(win, !gtk_widget_get_visible(win));
}
}

#ifndef ENABLE_APP_INDICATOR
static void tray_icon_on_popup_menu(GtkStatusIcon *status_icon, guint button,
guint activate_time, gpointer user_data){
SuiApplication *self;

self = user_data;

gtk_menu_popup(self->menu, NULL, NULL, NULL, NULL, button, activate_time);
}
#endif

0 comments on commit 098c7bb

Please sign in to comment.