diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3d9973a9..abf8104c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 \ diff --git a/meson_options.txt b/meson_options.txt index 27e089db..e5a03e16 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1 +1,2 @@ option('doc_builders', type : 'array', choices : ['html', 'man'], value : []) +option('app_indicator', type : 'boolean', value : true) diff --git a/src/meson.build b/src/meson.build index fce64f44..cedfad92 100644 --- a/src/meson.build +++ b/src/meson.build @@ -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'), diff --git a/src/sui/sui_app.c b/src/sui/sui_app.c index b050702c..0d323630 100644 --- a/src/sui/sui_app.c +++ b/src/sui/sui_app.c @@ -25,7 +25,10 @@ */ #include + +#ifdef ENABLE_APP_INDICATOR #include +#endif #include "sui/sui.h" #include "meta.h" @@ -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; @@ -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 @@ -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); @@ -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