Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added share/icons/hicolor/16x16/apps/iptux-icon-reverse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added share/iptux/pixmaps/icon/iptux-icon-reverse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define __LOCALE_PATH "@SHARE_DIR@/locale"
#define __SOUND_PATH "@SHARE_IPTUX_DIR@/sound"
#define __UI_PATH "@SHARE_IPTUX_DIR@/ui"
#define __ICON_PATH "@SHARE_DIR@/icons/hicolor"

#define IPTUX_PATH "/iptux"
#define LOG_PATH "/iptux/log"
Expand Down
78 changes: 76 additions & 2 deletions src/iptux/AppIndicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
#include <glib/gi18n.h>
#include <libayatana-appindicator/app-indicator.h>

#include "iptux-utils/output.h"

namespace iptux {

class IptuxAppIndicatorPrivate {
public:
IptuxAppIndicatorPrivate(IptuxAppIndicator* owner) : owner(owner) {}
~IptuxAppIndicatorPrivate() {
if (blinkTimerId) {
g_source_remove(blinkTimerId);
}
if (indicator) {
g_object_unref(indicator);
}
Expand All @@ -22,12 +27,49 @@ class IptuxAppIndicatorPrivate {
GtkBuilder* menuBuilder;
StatusIconMode mode = STATUS_ICON_MODE_NORMAL;
int unreadCount = 0;
guint blinkTimerId = 0;
bool blinkState = false;

static void onScrollEvent(IptuxAppIndicatorPrivate* self) {
self->owner->sigActivateMainWindow.emit();
}
};

static gboolean blinkTimerCallback(gpointer data) {
auto priv = static_cast<IptuxAppIndicatorPrivate*>(data);
priv->blinkState = !priv->blinkState;
if (priv->blinkState) {
LOG_DEBUG("blinkTimerCallback: switching to reverse icon");
app_indicator_set_icon_full(priv->indicator, "iptux-icon-reverse",
"iptux-icon-reverse");
} else {
LOG_DEBUG("blinkTimerCallback: switching to normal icon");
app_indicator_set_icon_full(priv->indicator, "iptux-icon", "iptux-icon");
}
return G_SOURCE_CONTINUE;
}

static void startBlinkTimer(IptuxAppIndicatorPrivate* priv) {
if (priv->blinkTimerId) {
LOG_DEBUG("startBlinkTimer: timer already running (id=%u)", priv->blinkTimerId);
return;
}
priv->blinkState = false;
priv->blinkTimerId = g_timeout_add(500, blinkTimerCallback, priv);
LOG_DEBUG("startBlinkTimer: blinking started (timerId=%u)", priv->blinkTimerId);
}

static void stopBlinkTimer(IptuxAppIndicatorPrivate* priv) {
if (priv->blinkTimerId) {
LOG_DEBUG("stopBlinkTimer: blinking stopped (timerId=%u)", priv->blinkTimerId);
g_source_remove(priv->blinkTimerId);
priv->blinkTimerId = 0;
} else {
LOG_DEBUG("stopBlinkTimer: no timer was running");
}
priv->blinkState = false;
}

IptuxAppIndicator::IptuxAppIndicator(GActionGroup* action_group) {
this->priv = std::make_shared<IptuxAppIndicatorPrivate>(this);

Expand All @@ -42,7 +84,7 @@ IptuxAppIndicator::IptuxAppIndicator(GActionGroup* action_group) {
app_indicator_set_status(priv->indicator, APP_INDICATOR_STATUS_ACTIVE);
app_indicator_set_attention_icon_full(priv->indicator, "iptux-attention",
"iptux-attention");

app_indicator_set_icon_theme_path(priv->indicator, __ICON_PATH);
app_indicator_set_title(priv->indicator, _("Iptux"));

priv->menuBuilder =
Expand All @@ -59,8 +101,24 @@ IptuxAppIndicator::IptuxAppIndicator(GActionGroup* action_group) {
}

void IptuxAppIndicator::SetUnreadCount(int i) {
LOG_DEBUG("SetUnreadCount: count=%d, mode=%d", i, priv->mode);
priv->unreadCount = i;
if (priv->mode == STATUS_ICON_MODE_NONE) return;
if (priv->mode == STATUS_ICON_MODE_NONE) {
LOG_DEBUG("SetUnreadCount: early return (mode=NONE)");
return;
}

if (priv->mode == STATUS_ICON_MODE_BLINKING) {
if (i > 0) {
startBlinkTimer(priv.get());
} else {
stopBlinkTimer(priv.get());
app_indicator_set_icon_full(priv->indicator, "iptux-icon", "iptux-icon");
app_indicator_set_status(priv->indicator, APP_INDICATOR_STATUS_ACTIVE);
}
return;
}

if (i > 0) {
app_indicator_set_status(priv->indicator, APP_INDICATOR_STATUS_ATTENTION);
} else {
Expand All @@ -69,12 +127,28 @@ void IptuxAppIndicator::SetUnreadCount(int i) {
}

void IptuxAppIndicator::SetMode(StatusIconMode mode) {
LOG_DEBUG("SetMode: mode=%d (old=%d)", mode, priv->mode);
StatusIconMode oldMode = priv->mode;
priv->mode = mode;

if (oldMode == STATUS_ICON_MODE_BLINKING) {
stopBlinkTimer(priv.get());
app_indicator_set_icon_full(priv->indicator, "iptux-icon", "iptux-icon");
}

if (mode == STATUS_ICON_MODE_NONE) {
app_indicator_set_status(priv->indicator, APP_INDICATOR_STATUS_PASSIVE);
} else {
SetUnreadCount(priv->unreadCount);
}
}

void IptuxAppIndicator::StopBlinking() {
LOG_DEBUG("StopBlinking called");
stopBlinkTimer(priv.get());
app_indicator_set_icon_full(priv->indicator, "iptux-icon", "iptux-icon");
if (priv->mode == STATUS_ICON_MODE_NONE) return;
app_indicator_set_status(priv->indicator, APP_INDICATOR_STATUS_ACTIVE);
}

} // namespace iptux
5 changes: 5 additions & 0 deletions src/iptux/AppIndicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ class IptuxAppIndicator {
IptuxAppIndicator(GActionGroup* action_group);
void SetUnreadCount(int count);
void SetMode(StatusIconMode mode);
void StopBlinking();

sigc::signal<void> sigActivateMainWindow;

private:
std::shared_ptr<IptuxAppIndicatorPrivate> priv;
};
#ifdef __APPLE__
void ActivateApplication();
#endif

} // namespace iptux
4 changes: 4 additions & 0 deletions src/iptux/AppIndicatorDummy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ void IptuxAppIndicator::SetUnreadCount(int) {
void IptuxAppIndicator::SetMode(StatusIconMode) {
// Dummy implementation
}

void IptuxAppIndicator::StopBlinking() {
// Dummy implementation
}
} // namespace iptux
97 changes: 96 additions & 1 deletion src/iptux/AppIndicatorMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>

#include "iptux-utils/output.h"

#import <Cocoa/Cocoa.h>

// Objective-C helper class for NSStatusItem callbacks.
Expand Down Expand Up @@ -36,6 +38,7 @@ - (instancetype)initWithActionGroup:(GActionGroup*)actionGroup

- (void)openMainWindow:(id)sender {
(void)sender;
g_debug("AppIndicatorMac: openMainWindow menu item clicked");
g_action_group_activate_action(actionGroup_, "open_main_window", NULL);
}

Expand Down Expand Up @@ -111,6 +114,9 @@ - (void)statusItemClicked:(id)sender {
public:
IptuxAppIndicatorPrivate() {}
~IptuxAppIndicatorPrivate() {
if (blinkTimerId) {
g_source_remove(blinkTimerId);
}
if (statusItem) {
[[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
[statusItem release];
Expand All @@ -124,14 +130,20 @@ - (void)statusItemClicked:(id)sender {
if (attentionIcon) {
[attentionIcon release];
}
if (reverseIcon) {
[reverseIcon release];
}
}

NSStatusItem* statusItem = nil;
IptuxStatusItemHelper* helper = nil;
NSImage* normalIcon = nil;
NSImage* attentionIcon = nil;
NSImage* reverseIcon = nil;
StatusIconMode mode = STATUS_ICON_MODE_NORMAL;
int unreadCount = 0;
guint blinkTimerId = 0;
bool blinkState = false;
};

IptuxAppIndicator::IptuxAppIndicator(GActionGroup* action_group) {
Expand All @@ -143,6 +155,7 @@ - (void)statusItemClicked:(id)sender {
// Load icons
priv->normalIcon = loadIcon("iptux-icon", 64);
priv->attentionIcon = loadIcon("iptux-attention", 64);
priv->reverseIcon = loadIcon("iptux-icon-reverse", 64);

// Create status item
priv->statusItem =
Expand Down Expand Up @@ -186,9 +199,68 @@ - (void)statusItemClicked:(id)sender {
[menu release];
}

static gboolean blinkTimerCallback(gpointer data) {
auto priv = static_cast<IptuxAppIndicatorPrivate*>(data);
if (!priv->statusItem) {
LOG_DEBUG("blinkTimerCallback: statusItem is nil, removing timer");
return G_SOURCE_REMOVE;
}
priv->blinkState = !priv->blinkState;
if (priv->blinkState && priv->reverseIcon) {
LOG_DEBUG("blinkTimerCallback: switching to reverse icon");
priv->statusItem.button.image = priv->reverseIcon;
} else if (priv->normalIcon) {
LOG_DEBUG("blinkTimerCallback: switching to normal icon");
priv->statusItem.button.image = priv->normalIcon;
} else {
LOG_DEBUG("blinkTimerCallback: no icon available (blinkState=%d, reverseIcon=%p, normalIcon=%p)",
priv->blinkState, priv->reverseIcon, priv->normalIcon);
}
return G_SOURCE_CONTINUE;
}

static void startBlinkTimer(IptuxAppIndicatorPrivate* priv) {
if (priv->blinkTimerId) {
LOG_DEBUG("startBlinkTimer: timer already running (id=%u)", priv->blinkTimerId);
return;
}
priv->blinkState = false;
priv->blinkTimerId = g_timeout_add(500, blinkTimerCallback, priv);
LOG_DEBUG("startBlinkTimer: blinking started (timerId=%u)", priv->blinkTimerId);
}

static void stopBlinkTimer(IptuxAppIndicatorPrivate* priv) {
if (priv->blinkTimerId) {
LOG_DEBUG("stopBlinkTimer: blinking stopped (timerId=%u)", priv->blinkTimerId);
g_source_remove(priv->blinkTimerId);
priv->blinkTimerId = 0;
} else {
LOG_DEBUG("stopBlinkTimer: no timer was running");
}
priv->blinkState = false;
}

void IptuxAppIndicator::SetUnreadCount(int count) {
LOG_DEBUG("SetUnreadCount: count=%d, mode=%d, statusItem=%p", count, priv->mode,
priv->statusItem);
priv->unreadCount = count;
if (!priv->statusItem || priv->mode == STATUS_ICON_MODE_NONE) return;
if (!priv->statusItem || priv->mode == STATUS_ICON_MODE_NONE) {
LOG_DEBUG("SetUnreadCount: early return (statusItem=%p, mode=%d)",
priv->statusItem, priv->mode);
return;
}

if (priv->mode == STATUS_ICON_MODE_BLINKING) {
if (count > 0) {
startBlinkTimer(priv.get());
} else {
stopBlinkTimer(priv.get());
if (priv->normalIcon) {
priv->statusItem.button.image = priv->normalIcon;
}
}
return;
}

if (count > 0 && priv->attentionIcon) {
priv->statusItem.button.image = priv->attentionIcon;
Expand All @@ -198,12 +270,35 @@ - (void)statusItemClicked:(id)sender {
}

void IptuxAppIndicator::SetMode(StatusIconMode mode) {
LOG_DEBUG("SetMode: mode=%d (old=%d)", mode, priv->mode);
StatusIconMode oldMode = priv->mode;
priv->mode = mode;
if (!priv->statusItem) return;
priv->statusItem.visible = (mode != STATUS_ICON_MODE_NONE);

if (oldMode == STATUS_ICON_MODE_BLINKING) {
stopBlinkTimer(priv.get());
if (priv->normalIcon) {
priv->statusItem.button.image = priv->normalIcon;
}
}

if (mode != STATUS_ICON_MODE_NONE) {
SetUnreadCount(priv->unreadCount);
}
}

void IptuxAppIndicator::StopBlinking() {
LOG_DEBUG("StopBlinking called");
stopBlinkTimer(priv.get());
if (!priv->statusItem || priv->mode == STATUS_ICON_MODE_NONE) return;
if (priv->normalIcon) {
priv->statusItem.button.image = priv->normalIcon;
}
}

void ActivateApplication() {
[NSApp activateIgnoringOtherApps:YES];
}

} // namespace iptux
11 changes: 11 additions & 0 deletions src/iptux/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,16 @@ void Application::onStartup(Application& self) {
make_shared<IptuxAppIndicator>(G_ACTION_GROUP(self.app));
self.app_indicator->SetMode(StatusIconMode(self.data->statusIconMode()));
self.app_indicator->sigActivateMainWindow.connect([&self]() {
LOG_DEBUG("sigActivateMainWindow: emitted, activating open_main_window action");
g_action_group_activate_action(G_ACTION_GROUP(self.app),
"open_main_window", NULL);
});
self.cthrd->sigUnreadMsgCountUpdated.connect(
sigc::mem_fun(*self.app_indicator, &IptuxAppIndicator::SetUnreadCount));

// Removed notify::is-active StopBlinking handler.
// Blinking now stops only when the user interacts with the dialog
// (button-press-event or key-press-event via ClearNotify).
}

bool use_app_menu = true;
Expand Down Expand Up @@ -227,6 +232,11 @@ void Application::onActivate(Application& self) {
}

void Application::onQuit(void*, void*, Application& self) {
// Close the preference dialog if it's open, so its modal loop doesn't block quit.
if (self.preference_dialog_) {
gtk_dialog_response(GTK_DIALOG(self.preference_dialog_),
GTK_RESPONSE_DELETE_EVENT);
}
if (!transModelIsFinished(self.transModel)) {
if (!pop_request_quit(GTK_WINDOW(self.window->getWindow()))) {
return;
Expand All @@ -240,6 +250,7 @@ void Application::onPreferences(void*, void*, Application& self) {
}

void Application::onOpenMainWindow(void*, void*, Application& self) {
LOG_DEBUG("onOpenMainWindow: action triggered");
self.getMainWindow()->Show();
}

Expand Down
Loading
Loading