diff options
| author | Victor Kareh <[email protected]> | 2026-08-17 15:01:53 -0400 |
|---|---|---|
| committer | Victor Kareh <[email protected]> | 2026-08-17 20:37:49 +0000 |
| commit | 10a3197b2d957e32f85491fa7aa8d52baacdcab4 (patch) | |
| tree | 04cfdad1231d870669e5352a314d612715b2317e | |
| parent | c8f681887970f207d153881464ac0937346d464f (diff) | |
| download | mate-power-manager-10a3197b2d957e32f85491fa7aa8d52baacdcab4.tar.bz2 mate-power-manager-10a3197b2d957e32f85491fa7aa8d52baacdcab4.tar.xz | |
Make ayatana-appindicator dependency optional
Adding Wayland support made ayatana-appindicator3 a hard requirement,
which breaks on systems without it (the previous tray icon is still
perfectly usable there).
This makes it optional and auto-detected at configure time, falling back
to the tray icon when the ayatana is unavailable.
Also make sure Wayland auto-detection only gets enables when every
Wayland dependency is actually present, instead of leaking the build
flag when an optional dependency is missing.
Fixes #432
| -rw-r--r-- | configure.ac | 39 | ||||
| -rw-r--r-- | meson.build | 4 | ||||
| -rw-r--r-- | meson_options.txt | 1 | ||||
| -rw-r--r-- | src/gpm-tray-icon.c | 103 |
4 files changed, 143 insertions, 4 deletions
diff --git a/configure.ac b/configure.ac index 15b9570..cfc84d4 100644 --- a/configure.ac +++ b/configure.ac @@ -114,7 +114,34 @@ PKG_CHECK_MODULES(LIBNOTIFY, libnotify >= $LIBNOTIFY_REQUIRED) PKG_CHECK_MODULES(UPOWER, upower-glib >= $UPOWER_REQUIRED) -PKG_CHECK_MODULES(APPLICATION_INDICATOR, ayatana-appindicator3-0.1) +dnl --------------------------------------------------------------------------- +dnl - Build with appindicator support +dnl --------------------------------------------------------------------------- +AC_ARG_ENABLE(appindicator, + AS_HELP_STRING([--enable-appindicator], + [Enable ayatana appindicator support (default: auto)]), + [enable_appindicator=$enableval], + [enable_appindicator=auto]) + +AC_MSG_CHECKING([whether to support appindicator]) + +have_appindicator=no +if test "x$enable_appindicator" != "xno"; then + PKG_CHECK_MODULES(APPLICATION_INDICATOR, ayatana-appindicator3-0.1, [ + have_appindicator=yes + AC_DEFINE([HAVE_APP_INDICATOR], 1, [Define if appindicator support is enabled]) + ], [ + if test "x$enable_appindicator" = "xyes"; then + AC_MSG_ERROR([appindicator support requested but ayatana-appindicator3-0.1 not found]) + fi + ]) +fi + +if test "x$have_appindicator" = "xyes"; then + AC_MSG_RESULT([yes]) +else + AC_MSG_RESULT([no]) +fi dnl --------------------------------------------------------------------------- dnl - Make paths available for source files @@ -139,7 +166,6 @@ have_wayland=no if test "x$enable_wayland" != "xno"; then PKG_CHECK_MODULES(WAYLAND_CLIENT, wayland-client, [ have_wayland=yes - AC_DEFINE([HAVE_WAYLAND], 1, [Define if Wayland support is enabled]) ], [ if test "x$enable_wayland" = "xyes"; then AC_MSG_ERROR([Wayland support requested but wayland-client not found]) @@ -159,9 +185,14 @@ if test "x$enable_wayland" != "xno"; then AC_SUBST(WAYLAND_PROTOCOLS_DATADIR) AC_PATH_PROG([WAYLAND_SCANNER], [wayland-scanner], [no]) if test "x$WAYLAND_SCANNER" = "xno"; then - AC_MSG_ERROR([wayland-scanner not found]) + if test "x$enable_wayland" = "xyes"; then + AC_MSG_ERROR([Wayland support requested but wayland-scanner not found]) + fi + have_wayland=no fi + fi + if test "x$have_wayland" = "xyes"; then AC_MSG_CHECKING([for wlr-output-power-management-unstable-v1.xml]) WLR_PROTOCOLS_XML="${srcdir}/src/wlr-output-power-management-unstable-v1.xml" if test ! -f "$WLR_PROTOCOLS_XML"; then @@ -183,6 +214,7 @@ if test "x$enable_wayland" != "xno"; then fi if test "x$have_wayland" = "xyes"; then + AC_DEFINE([HAVE_WAYLAND], 1, [Define if Wayland support is enabled]) AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) @@ -339,6 +371,7 @@ Configure summary: gnome-keyring support .......: ${with_keyring} Building extra applets ......: ${enable_applets} Applets in-process...........: ${enable_applets_inprocess} + Appindicator support ........: ${have_appindicator} Wayland support .............: ${have_wayland} Self test support ...........: ${have_tests} dbus-1 services dir .........: $DBUS_SERVICES_DIR diff --git a/meson.build b/meson.build index 73f4db6..bb71043 100644 --- a/meson.build +++ b/meson.build @@ -92,6 +92,7 @@ enable_applets_inprocess = get_option('applets-in-process') enable_keyring = get_option('gnome-keyring') enable_libsecret = get_option('libsecret') enable_wayland = get_option('enable-wayland') +enable_appindicator = get_option('appindicator') gtk = dependency('gtk+-3.0', version : '>= 3.22.0') glib = dependency('glib-2.0', version : '>= 2.50.0') @@ -103,7 +104,7 @@ notify = dependency('libnotify', version : '>= 0.7.0') canberra = dependency('libcanberra-gtk3', version : '>= 0.10') matepanel = dependency('libmatepanelapplet-4.0', version : '>= 1.17.0',required: enable_applet) upower = dependency('upower-glib', version : '>= 0.99.8') -appindicator = dependency('ayatana-appindicator3-0.1') +appindicator = dependency('ayatana-appindicator3-0.1', required: enable_appindicator) libsecret = dependency('libsecret-1', version : '>= 0.11', required: enable_libsecret) keyring = dependency('gnome-keyring-1', version : '>= 3.0.0', required: enable_keyring) md = dependency('mate-desktop-2.0', version : '>= 1.27.1') @@ -129,6 +130,7 @@ conf.set('WITH_KEYRING', keyring.found()) conf.set('WITH_LIBSECRET', libsecret.found()) conf.set('APPLETS_INPROCESS', enable_applets_inprocess) conf.set('HAVE_X11', 1) +conf.set('HAVE_APP_INDICATOR', appindicator.found()) conf.set_quoted('GETTEXT_PACKAGE', meson.project_name()) conf.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), diff --git a/meson_options.txt b/meson_options.txt index 7c6f4b5..ab12533 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -4,3 +4,4 @@ option('libsecret', type : 'boolean', value : true, description : 'libsecret ena option('applets', type : 'boolean', value : true, description : 'applets enabled') option('applets-in-process', type : 'boolean', value : false, description : 'build applets in-process') option('enable-wayland', type : 'boolean', value : false, description : 'Wayland support') +option('appindicator', type : 'feature', value : 'auto', description : 'ayatana appindicator support') diff --git a/src/gpm-tray-icon.c b/src/gpm-tray-icon.c index d26f5a0..80dd67b 100644 --- a/src/gpm-tray-icon.c +++ b/src/gpm-tray-icon.c @@ -43,7 +43,9 @@ #include <libmate-desktop/mate-image-menu-item.h> +#ifdef HAVE_APP_INDICATOR #include <libayatana-appindicator/app-indicator.h> +#endif #include "gpm-upower.h" #include "gpm-engine.h" @@ -57,7 +59,11 @@ struct GpmTrayIconPrivate { GSettings *settings; GpmEngine *engine; +#ifdef HAVE_APP_INDICATOR AppIndicator *indicator; +#else + GtkStatusIcon *status_icon; +#endif gchar *current_icon; gboolean show_actions; }; @@ -82,8 +88,12 @@ static void gpm_tray_icon_show (GpmTrayIcon *icon, gboolean enabled) { g_return_if_fail (GPM_IS_TRAY_ICON (icon)); +#ifdef HAVE_APP_INDICATOR app_indicator_set_status (icon->priv->indicator, enabled ? APP_INDICATOR_STATUS_ACTIVE : APP_INDICATOR_STATUS_PASSIVE); +#else + gtk_status_icon_set_visible (icon->priv->status_icon, enabled); +#endif } /** @@ -97,7 +107,12 @@ gpm_tray_icon_set_tooltip (GpmTrayIcon *icon, const gchar *tooltip) g_return_val_if_fail (GPM_IS_TRAY_ICON (icon), FALSE); g_return_val_if_fail (tooltip != NULL, FALSE); +#ifdef HAVE_APP_INDICATOR app_indicator_set_title (icon->priv->indicator, tooltip); +#else + gtk_status_icon_set_tooltip_text (icon->priv->status_icon, tooltip); + gtk_status_icon_set_title (icon->priv->status_icon, tooltip); +#endif return TRUE; } @@ -126,7 +141,12 @@ gpm_tray_icon_set_icon (GpmTrayIcon *icon, const gchar *icon_name) if (icon_name != NULL) { g_debug ("Setting icon to %s", icon_name); +#ifdef HAVE_APP_INDICATOR app_indicator_set_icon (icon->priv->indicator, icon_name); +#else + gtk_status_icon_set_from_icon_name (icon->priv->status_icon, + icon_name); +#endif g_free (icon->priv->current_icon); icon->priv->current_icon = g_strdup (icon_name); @@ -417,6 +437,70 @@ skip_prefs: return menu; } +#ifndef HAVE_APP_INDICATOR +/** + * gpm_tray_icon_popup_cleared_cd: + * @widget: The popup Gtkwidget + * + * We have to re-enable the tooltip when the popup is removed + **/ +static void +gpm_tray_icon_popup_cleared_cd (GtkWidget *widget, GpmTrayIcon *icon) +{ + g_return_if_fail (GPM_IS_TRAY_ICON (icon)); + g_debug ("clear tray"); + g_object_ref_sink (widget); + g_object_unref (widget); +} + +/** + * gpm_tray_icon_popup_menu: + * + * Display the popup menu. + **/ +static void +gpm_tray_icon_popup_menu (GpmTrayIcon *icon, guint32 timestamp) +{ + GtkMenu *menu; + + menu = gpm_tray_icon_create_menu (icon); + + /* show the menu */ + gtk_widget_show_all (GTK_WIDGET (menu)); + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, + gtk_status_icon_position_menu, icon->priv->status_icon, + 1, timestamp); + + g_signal_connect (GTK_WIDGET (menu), "hide", + G_CALLBACK (gpm_tray_icon_popup_cleared_cd), icon); +} + +/** + * gpm_tray_icon_popup_menu_cb: + * + * Display the popup menu. + **/ +static void +gpm_tray_icon_popup_menu_cb (GtkStatusIcon *status_icon, guint button, guint32 timestamp, GpmTrayIcon *icon) +{ + g_debug ("icon right clicked"); + gpm_tray_icon_popup_menu (icon, timestamp); +} + +/** + * gpm_tray_icon_activate_cb: + * @button: Which buttons are pressed + * + * Callback when the icon is clicked + **/ +static void +gpm_tray_icon_activate_cb (GtkStatusIcon *status_icon, GpmTrayIcon *icon) +{ + g_debug ("icon left clicked"); + gpm_tray_icon_popup_menu (icon, gtk_get_current_event_time()); +} +#endif /* !HAVE_APP_INDICATOR */ + /** * gpm_tray_icon_rebuild_menu: * @@ -425,11 +509,13 @@ skip_prefs: static void gpm_tray_icon_rebuild_menu (GpmTrayIcon *icon) { +#ifdef HAVE_APP_INDICATOR GtkMenu *menu; menu = gpm_tray_icon_create_menu (icon); gtk_widget_show_all (GTK_WIDGET (menu)); app_indicator_set_menu (icon->priv->indicator, menu); +#endif } /** @@ -467,6 +553,7 @@ gpm_tray_icon_init (GpmTrayIcon *icon) g_signal_connect (icon->priv->settings, "changed", G_CALLBACK (gpm_tray_icon_settings_changed_cb), icon); +#ifdef HAVE_APP_INDICATOR icon->priv->indicator = app_indicator_new ("mate-power-manager", "mate-power-manager", APP_INDICATOR_CATEGORY_HARDWARE); @@ -474,6 +561,18 @@ gpm_tray_icon_init (GpmTrayIcon *icon) /* start hidden; the engine decides when to show the icon */ app_indicator_set_status (icon->priv->indicator, APP_INDICATOR_STATUS_PASSIVE); +#else + icon->priv->status_icon = gtk_status_icon_new (); + gpm_tray_icon_show (icon, FALSE); + g_signal_connect_object (G_OBJECT (icon->priv->status_icon), + "popup_menu", + G_CALLBACK (gpm_tray_icon_popup_menu_cb), + icon, 0); + g_signal_connect_object (G_OBJECT (icon->priv->status_icon), + "activate", + G_CALLBACK (gpm_tray_icon_activate_cb), + icon, 0); +#endif allowed_in_menu = g_settings_get_boolean (icon->priv->settings, GPM_SETTINGS_SHOW_ACTIONS); gpm_tray_icon_enable_actions (icon, allowed_in_menu); @@ -496,7 +595,11 @@ gpm_tray_icon_finalize (GObject *object) tray_icon = GPM_TRAY_ICON (object); g_object_unref (tray_icon->priv->settings); +#ifdef HAVE_APP_INDICATOR g_object_unref (tray_icon->priv->indicator); +#else + g_object_unref (tray_icon->priv->status_icon); +#endif g_object_unref (tray_icon->priv->engine); g_free (tray_icon->priv->current_icon); g_return_if_fail (tray_icon->priv != NULL); |
