summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhuyaliang <[email protected]>2023-10-18 16:28:00 +0800
committerraveit65 <[email protected]>2023-10-24 18:11:10 +0200
commit1a837ccdb078c0021588809814bfa80641acc3a8 (patch)
treef36b20165c4dfaf2a76fd3f4c4d6e3029e5177c7
parentf27d27edf0b97f292a8b6b93fe262fd9b5a4ff2a (diff)
downloadmate-control-center-1a837ccdb078c0021588809814bfa80641acc3a8.tar.bz2
mate-control-center-1a837ccdb078c0021588809814bfa80641acc3a8.tar.xz
typing-break: Force dependency on appindicator and remove deprecated GtkStatusIcon
-rw-r--r--.build.yml2
-rw-r--r--configure.ac50
-rw-r--r--typing-break/Makefile.am8
-rw-r--r--typing-break/drwright.c285
-rw-r--r--typing-break/main.c48
5 files changed, 61 insertions, 332 deletions
diff --git a/.build.yml b/.build.yml
index 102a9ada..279b7198 100644
--- a/.build.yml
+++ b/.build.yml
@@ -38,6 +38,7 @@ requires:
- intltool
- libcanberra-gtk3-dev
- libdconf-dev
+ - libayatana-appindicator3-dev
- libglib2.0-dev
- libgtk-3-dev
- libgtop2-dev
@@ -83,6 +84,7 @@ requires:
- gtk3-devel
- iso-codes-devel
- itstool
+ - libappindicator-gtk3-devel
- libSM-devel
- libXScrnSaver-devel
- libcanberra-devel
diff --git a/configure.ac b/configure.ac
index 19e11db5..30ff9ca3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -85,31 +85,6 @@ AM_CONDITIONAL(HAVE_LIBCANBERRA_GTK, test "x$CANBERRA_GTK" = "x1")
AM_CONDITIONAL(HAVE_TYPING_BREAK, test "x$TYPING_BREAK" = xtyping-break)
-dnl app indicator
-APPINDICATOR_PKG=appindicator3-0.1
-
-AC_ARG_ENABLE(appindicator,
- AS_HELP_STRING([--enable-appindicator[=@<:@no/auto/yes@:>@]],[Build support for application indicators ]),
- [enable_appindicator=$enableval],
- [enable_appindicator="auto"])
-
-if test x$enable_appindicator = xauto ; then
- PKG_CHECK_EXISTS([$APPINDICATOR_PKG >= $APPINDICATOR_REQUIRED],
- enable_appindicator="yes",
- enable_appindicator="no")
-fi
-
-if test x$enable_appindicator = xyes ; then
- PKG_CHECK_EXISTS([$APPINDICATOR_PKG >= $APPINDICATOR_REQUIRED],,
- AC_MSG_ERROR([appindicator-0.1 is not installed]))
- PKG_CHECK_MODULES(APP_INDICATOR,
- $APPINDICATOR_PKG >= $APPINDICATOR_REQUIRED)
- AC_SUBST(APP_INDICATOR_CFLAGS)
- AC_SUBST(APP_INDICATOR_LIBS)
- AC_DEFINE(HAVE_APP_INDICATOR, 1, [Have AppIndicator])
-fi
-AM_CONDITIONAL(HAVE_APP_INDICATOR, test x"$enable_appindicator" = xyes)
-
dnl keyboard-properties-capplet
savecppflags=$CPPFLAGS
CPPFLAGS="$CPPFLAGS $X_CFLAGS"
@@ -193,6 +168,27 @@ fi
AM_CONDITIONAL([HAVE_ACCOUNTSSERVICE], [test "x$have_accountsservice" = xyes])
+AYATANA_APPINDICATOR_PKG=ayatana-appindicator3-0.1
+UBUNTU_APPINDICATOR_PKG=appindicator3-0.1
+
+AC_ARG_ENABLE([libappindicator],
+ [AS_HELP_STRING([--enable-libappindicator[=@<:@no/auto/yes@:>@]],[Use libappindicator instead of ayatana-indicator @<:@default=auto@:>@])],
+ [enable_appindicator=$enableval],
+ [PKG_CHECK_EXISTS([$AYATANA_APPINDICATOR_PKG >= $APPINDICATOR_REQUIRED],
+ [enable_appindicator=no],
+ [PKG_CHECK_EXISTS([$UBUNTU_APPINDICATOR_PKG >= $APPINDICATOR_REQUIRED],
+ [enable_appindicator=yes],
+ [enable_appindicator=no])])])
+
+AS_IF([test "x$enable_appindicator" = xyes],
+ [AC_MSG_NOTICE([Buidling against Ubuntu AppIndicator.])
+ PKG_CHECK_MODULES([APPINDICATOR],
+ [$UBUNTU_APPINDICATOR_PKG >= $APPINDICATOR_REQUIRED],
+ [AC_DEFINE(HAVE_UBUNTU_APPINDICATOR, 1, [Have Ubuntu AppIndicator])])],
+ [AC_MSG_NOTICE([Buidling against Ayatana AppIndicator.])
+ PKG_CHECK_MODULES([APPINDICATOR],
+ [$AYATANA_APPINDICATOR_PKG >= $APPINDICATOR_REQUIRED],
+ [AC_DEFINE(HAVE_AYATANA_APPINDICATOR, 1, [Have Ayatana AppIndicator])])])
PKG_CHECK_MODULES(FONT_CAPPLET, $COMMON_MODULES pango)
PKG_CHECK_MODULES(FONT_VIEWER, $COMMON_MODULES fontconfig freetype2 mate-desktop-2.0)
@@ -329,7 +325,9 @@ Configure summary:
Warning flags: ${WARN_CFLAGS}
Linker flags: ${LDFLAGS}
- Appindicator: ${enable_appindicator}
+ Ayatana AppIndicator (preferred) $(test "x$enable_appindicator" = xyes && echo no || echo yes)
+ Ubuntu AppIndicator (legacy) $(test "x$enable_appindicator" = xyes && echo yes || echo no)
+
Libmate-slab: ${have_libmateslab}
Accountsservice: ${have_accountsservice}
Native Language support: ${USE_NLS}
diff --git a/typing-break/Makefile.am b/typing-break/Makefile.am
index 8233b4c1..5290b041 100644
--- a/typing-break/Makefile.am
+++ b/typing-break/Makefile.am
@@ -21,22 +21,18 @@ mate_typing_monitor_CPPFLAGS = \
$(AM_CPPFLAGS)
mate_typing_monitor_CFLAGS = \
@TYPING_CFLAGS@ \
+ @APPINDICATOR_CFLAGS@ \
@MATE_DESKTOP_CFLAGS@ \
$(WARN_CFLAGS) \
$(AM_CFLAGS)
-mate_typing_monitor_LDADD = @TYPING_LIBS@ @MATE_DESKTOP_LIBS@ @SCREENSAVER_LIBS@
+mate_typing_monitor_LDADD = @TYPING_LIBS@ @APPINDICATOR_LIBS@ @MATE_DESKTOP_LIBS@ @SCREENSAVER_LIBS@
if HAVE_LIBCANBERRA_GTK
mate_typing_monitor_CFLAGS += -DHAVE_CANBERRA_GTK @LIBCANBERRA_GTK_CFLAGS@
mate_typing_monitor_LDADD += @LIBCANBERRA_GTK_LIBS@
endif
-if HAVE_APP_INDICATOR
- mate_typing_monitor_CFLAGS += -DHAVE_APP_INDICATOR @APP_INDICATOR_CFLAGS@
- mate_typing_monitor_LDADD += @APP_INDICATOR_LIBS@
-endif
-
imagedir = $(pkgdatadir)/pixmaps
dist_image_DATA = bar.png bar-red.png bar-green.png bar-disabled.png ocean-stripes.png
diff --git a/typing-break/drwright.c b/typing-break/drwright.c
index bc97a437..82306111 100644
--- a/typing-break/drwright.c
+++ b/typing-break/drwright.c
@@ -30,9 +30,11 @@
#include <gtk/gtk.h>
#include <gio/gio.h>
-#ifdef HAVE_APP_INDICATOR
+#ifdef HAVE_UBUNTU_APPINDICATOR
#include <libappindicator/app-indicator.h>
-#endif /* HAVE_APP_INDICATOR */
+#else
+#include <libayatana-appindicator/app-indicator.h>
+#endif
#define MATE_DESKTOP_USE_UNSTABLE_API
#include <libmate-desktop/mate-desktop-utils.h>
@@ -43,12 +45,6 @@
#include "drw-utils.h"
#include "drw-timer.h"
-#ifndef HAVE_APP_INDICATOR
-#define BLINK_TIMEOUT 200
-#define BLINK_TIMEOUT_MIN 120
-#define BLINK_TIMEOUT_FACTOR 100
-#endif /* HAVE_APP_INDICATOR */
-
typedef enum {
STATE_START,
STATE_RUNNING,
@@ -59,10 +55,8 @@ typedef enum {
STATE_BREAK_DONE
} DrwState;
-#ifdef HAVE_APP_INDICATOR
#define TYPING_MONITOR_ACTIVE_ICON "bar-green"
#define TYPING_MONITOR_ATTENTION_ICON "bar-red"
-#endif /* HAVE_APP_INDICATOR */
struct _DrWright {
/* Widgets. */
@@ -89,22 +83,7 @@ struct _DrWright {
gboolean enabled;
guint clock_timeout_id;
-#ifdef HAVE_APP_INDICATOR
AppIndicator *indicator;
-#else
- guint blink_timeout_id;
-
- gboolean blink_on;
-
- GtkStatusIcon *icon;
-
- cairo_surface_t *neutral_bar;
- cairo_surface_t *red_bar;
- cairo_surface_t *green_bar;
- cairo_surface_t *disabled_bar;
- GdkPixbuf *composite_bar;
-#endif /* HAVE_APP_INDICATOR */
-
GtkWidget *warn_dialog;
};
@@ -130,11 +109,7 @@ static void popup_preferences_cb (GSimpleAction *action,
static void popup_about_cb (GSimpleAction *action,
GVariant *parameter,
gpointer data);
-#ifdef HAVE_APP_INDICATOR
static void init_app_indicator (DrWright *dr);
-#else
-static void init_tray_icon (DrWright *dr);
-#endif /* HAVE_APP_INDICATOR */
static GList * create_secondary_break_windows (void);
static const GActionEntry action_entries[] = {
@@ -153,7 +128,6 @@ setup_debug_values (DrWright *dr)
dr->break_time = 10;
}
-#ifdef HAVE_APP_INDICATOR
static void
update_app_indicator (DrWright *dr)
{
@@ -177,166 +151,6 @@ update_app_indicator (DrWright *dr)
app_indicator_set_status (dr->indicator, new_status);
}
-#else
-
-static void
-set_status_icon (GtkStatusIcon *icon, cairo_surface_t *surface)
-{
- GdkPixbuf *pixbuf;
-
- pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0,
- cairo_image_surface_get_width (surface),
- cairo_image_surface_get_height (surface));
-
- gtk_status_icon_set_from_pixbuf (icon, pixbuf);
-
- g_object_unref (pixbuf);
-}
-
-static void
-update_icon (DrWright *dr)
-{
- GdkPixbuf *pixbuf;
- GdkPixbuf *tmp_pixbuf;
- gint width, height;
- gfloat r;
- gint offset;
- gboolean set_pixbuf;
-
- if (!dr->enabled) {
- set_status_icon (dr->icon, dr->disabled_bar);
- return;
- }
-
- width = cairo_image_surface_get_width (dr->neutral_bar);
- height = cairo_image_surface_get_height (dr->neutral_bar);
-
- tmp_pixbuf = gdk_pixbuf_get_from_surface (dr->neutral_bar,
- 0, 0,
- width, height);
-
- set_pixbuf = TRUE;
-
- switch (dr->state) {
- case STATE_BREAK:
- case STATE_BREAK_SETUP:
- r = 1;
- break;
-
- case STATE_BREAK_DONE:
- case STATE_BREAK_DONE_SETUP:
- case STATE_START:
- r = 0;
- break;
-
- default:
- r = (float) (drw_timer_elapsed (dr->timer) + dr->save_last_time) /
- (float) dr->type_time;
- break;
- }
-
- offset = CLAMP ((height - 0) * (1.0 - r), 1, height - 0);
-
- switch (dr->state) {
- case STATE_WARN:
- pixbuf = gdk_pixbuf_get_from_surface (dr->red_bar, 0, 0, width, height);
- set_pixbuf = FALSE;
- break;
-
- case STATE_BREAK_SETUP:
- case STATE_BREAK:
- pixbuf = gdk_pixbuf_get_from_surface (dr->red_bar, 0, 0, width, height);
- break;
-
- default:
- pixbuf = gdk_pixbuf_get_from_surface (dr->green_bar, 0, 0, width, height);
- }
-
- gdk_pixbuf_composite (pixbuf,
- tmp_pixbuf,
- 0,
- offset,
- width,
- height - offset,
- 0,
- 0,
- 1.0,
- 1.0,
- GDK_INTERP_BILINEAR,
- 255);
-
- if (set_pixbuf) {
- gtk_status_icon_set_from_pixbuf (dr->icon,
- tmp_pixbuf);
- }
-
- if (dr->composite_bar) {
- g_object_unref (dr->composite_bar);
- }
-
- dr->composite_bar = tmp_pixbuf;
-
- g_object_unref (pixbuf);
-}
-
-static gboolean
-blink_timeout_cb (DrWright *dr)
-{
- gfloat r;
- gint timeout;
-
- r = (dr->type_time - drw_timer_elapsed (dr->timer) - dr->save_last_time) / dr->warn_time;
- timeout = BLINK_TIMEOUT + BLINK_TIMEOUT_FACTOR * r;
-
- if (timeout < BLINK_TIMEOUT_MIN) {
- timeout = BLINK_TIMEOUT_MIN;
- }
-
- if (dr->blink_on || timeout == 0) {
- gtk_status_icon_set_from_pixbuf (dr->icon, dr->composite_bar);
- } else {
- set_status_icon (dr->icon, dr->neutral_bar);
- }
-
- dr->blink_on = !dr->blink_on;
-
- if (timeout) {
- dr->blink_timeout_id = g_timeout_add (timeout,
- (GSourceFunc) blink_timeout_cb,
- dr);
- } else {
- dr->blink_timeout_id = 0;
- }
-
- return FALSE;
-}
-#endif /* HAVE_APP_INDICATOR */
-
-static void
-start_blinking (DrWright *dr)
-{
-#ifndef HAVE_APP_INDICATOR
- if (!dr->blink_timeout_id) {
- dr->blink_on = TRUE;
- blink_timeout_cb (dr);
- }
-
- /*gtk_widget_show (GTK_WIDGET (dr->icon));*/
-#endif /* HAVE_APP_INDICATOR */
-}
-
-static void
-stop_blinking (DrWright *dr)
-{
-#ifndef HAVE_APP_INDICATOR
- if (dr->blink_timeout_id) {
- g_source_remove (dr->blink_timeout_id);
- dr->blink_timeout_id = 0;
- }
-
- /*gtk_widget_hide (GTK_WIDGET (dr->icon));*/
-#endif /* HAVE_APP_INDICATOR */
-}
static gboolean
grab_keyboard_on_window (GdkWindow *window,
@@ -403,10 +217,6 @@ maybe_change_state (DrWright *dr)
dr->break_window = NULL;
}
-#ifndef HAVE_APP_INDICATOR
- set_status_icon (dr->icon, dr->neutral_bar);
-#endif /* HAVE_APP_INDICATOR */
-
dr->save_last_time = 0;
drw_timer_start (dr->timer);
@@ -417,7 +227,6 @@ maybe_change_state (DrWright *dr)
}
update_status (dr);
- stop_blinking (dr);
break;
case STATE_RUNNING:
@@ -429,7 +238,6 @@ maybe_change_state (DrWright *dr)
} else if (dr->state != STATE_WARN
&& elapsed_time >= dr->type_time - dr->warn_time) {
dr->state = STATE_WARN;
- start_blinking (dr);
}
break;
@@ -442,11 +250,6 @@ maybe_change_state (DrWright *dr)
break;
}
- stop_blinking (dr);
-#ifndef HAVE_APP_INDICATOR
- set_status_icon (dr->icon, dr->red_bar);
-#endif /* HAVE_APP_INDICATOR */
-
drw_timer_start (dr->timer);
dr->break_window = drw_break_window_new ();
@@ -485,10 +288,6 @@ maybe_change_state (DrWright *dr)
break;
case STATE_BREAK_DONE_SETUP:
- stop_blinking (dr);
-#ifndef HAVE_APP_INDICATOR
- set_status_icon (dr->icon, dr->green_bar);
-#endif /* HAVE_APP_INDICATOR */
dr->state = STATE_BREAK_DONE;
break;
@@ -504,11 +303,7 @@ maybe_change_state (DrWright *dr)
dr->last_elapsed_time = elapsed_time;
-#ifdef HAVE_APP_INDICATOR
update_app_indicator (dr);
-#else
- update_icon (dr);
-#endif /* HAVE_APP_INDICATOR */
return TRUE;
}
@@ -520,39 +315,20 @@ update_status (DrWright *dr)
gchar *str;
if (!dr->enabled) {
-#ifdef HAVE_APP_INDICATOR
app_indicator_set_status (dr->indicator,
APP_INDICATOR_STATUS_PASSIVE);
-#else
- gtk_status_icon_set_tooltip_text (dr->icon,
- _("Disabled"));
-#endif /* HAVE_APP_INDICATOR */
return TRUE;
}
min = get_time_left (dr);
if (min >= 1) {
-#ifdef HAVE_APP_INDICATOR
str = g_strdup_printf (_("Take a break now (next in %dm)"), min);
-#else
- str = g_strdup_printf (ngettext("%d minute until the next break",
- "%d minutes until the next break",
- min), min);
-#endif /* HAVE_APP_INDICATOR */
} else {
-#ifdef HAVE_APP_INDICATOR
str = g_strdup_printf (_("Take a break now (next in less than one minute)"));
-#else
- str = g_strdup_printf (_("Less than one minute until the next break"));
-#endif /* HAVE_APP_INDICATOR */
}
-#ifdef HAVE_APP_INDICATOR
gtk_menu_item_set_label (GTK_MENU_ITEM (dr->break_item), str);
-#else
- gtk_status_icon_set_tooltip_text (dr->icon, str);
-#endif /* HAVE_APP_INDICATOR */
g_free (str);
@@ -670,23 +446,6 @@ popup_about_cb (GSimpleAction *action,
NULL);
}
-#ifndef HAVE_APP_INDICATOR
-static void
-popup_menu_cb (GtkWidget *widget,
- guint button,
- guint activate_time,
- DrWright *dr)
-{
- gtk_menu_popup (GTK_MENU (dr->menu),
- NULL,
- NULL,
- gtk_status_icon_position_menu,
- dr->icon,
- button,
- activate_time);
-}
-#endif /* HAVE_APP_INDICATOR */
-
static void
break_window_done_cb (GtkWidget *window,
DrWright *dr)
@@ -725,11 +484,7 @@ break_window_postpone_cb (GtkWidget *window,
drw_timer_start (dr->timer);
maybe_change_state (dr);
update_status (dr);
-#ifdef HAVE_APP_INDICATOR
update_app_indicator (dr);
-#else
- update_icon (dr);
-#endif /* HAVE_APP_INDICATOR */
}
static void
@@ -746,7 +501,6 @@ break_window_destroy_cb (GtkWidget *window,
dr->secondary_break_windows = NULL;
}
-#ifdef HAVE_APP_INDICATOR
static void
init_app_indicator (DrWright *dr)
{
@@ -769,28 +523,6 @@ init_app_indicator (DrWright *dr)
update_status (dr);
update_app_indicator (dr);
}
-#else
-static void
-init_tray_icon (DrWright *dr)
-{
- GdkPixbuf *pixbuf;
-
- pixbuf = gdk_pixbuf_get_from_surface (dr->neutral_bar, 0, 0,
- cairo_image_surface_get_width (dr->neutral_bar),
- cairo_image_surface_get_height (dr->neutral_bar));
-
- dr->icon = gtk_status_icon_new_from_pixbuf (pixbuf);
- g_object_unref (pixbuf);
-
- update_status (dr);
- update_icon (dr);
-
- g_signal_connect (dr->icon,
- "popup_menu",
- G_CALLBACK (popup_menu_cb),
- dr);
-}
-#endif /* HAVE_APP_INDICATOR */
static GList *
create_secondary_break_windows (void)
@@ -930,16 +662,7 @@ drwright_new (void)
G_CALLBACK (activity_detected_cb),
dr);
-#ifdef HAVE_APP_INDICATOR
init_app_indicator (dr);
-#else
- dr->neutral_bar = cairo_image_surface_create_from_png (IMAGEDIR "/bar.png");
- dr->red_bar = cairo_image_surface_create_from_png (IMAGEDIR "/bar-red.png");
- dr->green_bar = cairo_image_surface_create_from_png (IMAGEDIR "/bar-green.png");
- dr->disabled_bar = cairo_image_surface_create_from_png (IMAGEDIR "/bar-disabled.png");
-
- init_tray_icon (dr);
-#endif /* HAVE_APP_INDICATOR */
g_timeout_add_seconds (12,
(GSourceFunc) update_status,
diff --git a/typing-break/main.c b/typing-break/main.c
index 9e9f4685..4edd38f3 100644
--- a/typing-break/main.c
+++ b/typing-break/main.c
@@ -29,28 +29,40 @@
#include "drw-selection.h"
#include "drwright.h"
+#define NOTIFIERAREA_NAME "org.kde.StatusNotifierWatcher"
+#define NOTIFIERAREA_PATH "/StatusNotifierWatcher"
+#define NOTIFIERAREA_INTERFACE "org.kde.StatusNotifierWatcher"
+#define NOTIFIERAREA_PROPERTY "IsStatusNotifierHostRegistered"
+
gboolean debug = FALSE;
-#ifndef HAVE_APP_INDICATOR
static gboolean
-have_tray (void)
+is_status_notifier_host_available (void)
{
- Screen *xscreen = DefaultScreenOfDisplay (gdk_x11_display_get_xdisplay(gdk_display_get_default()));
- Atom selection_atom;
- char *selection_atom_name;
-
- selection_atom_name = g_strdup_printf ("_NET_SYSTEM_TRAY_S%d",
- XScreenNumberOfScreen (xscreen));
- selection_atom = gdk_x11_get_xatom_by_name (selection_atom_name);
- g_free (selection_atom_name);
-
- if (XGetSelectionOwner (DisplayOfScreen (xscreen), selection_atom)) {
- return TRUE;
- } else {
+ g_autoptr (GDBusProxy) proxy = NULL;
+ g_autoptr (GError) error = NULL;
+
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS |
+ G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
+ NULL,
+ NOTIFIERAREA_NAME,
+ NOTIFIERAREA_PATH,
+ NOTIFIERAREA_INTERFACE,
+ NULL, &error);
+
+ if (proxy == NULL || error)
+ {
+ return FALSE;
+ }
+ g_autoptr (GVariant) variant = g_dbus_proxy_get_cached_property (proxy, NOTIFIERAREA_PROPERTY);
+ if (! variant)
+ {
return FALSE;
}
+
+ return g_variant_get_boolean (variant);
}
-#endif /* HAVE_APP_INDICATOR */
int
main (int argc, char *argv[])
@@ -70,7 +82,7 @@ main (int argc, char *argv[])
#ifdef ENABLE_NLS
bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
- bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
#endif /* ENABLE_NLS */
@@ -98,8 +110,7 @@ main (int argc, char *argv[])
return 0;
}
-#ifndef HAVE_APP_INDICATOR
- if (!no_check && !have_tray ()) {
+ if (!no_check && !is_status_notifier_host_available ()) {
GtkWidget *dialog;
dialog = gtk_message_dialog_new (
@@ -116,7 +127,6 @@ main (int argc, char *argv[])
gtk_widget_destroy (dialog);
}
-#endif /* HAVE_APP_INDICATOR */
drwright_new ();