Skip to content

Commit bf26b98

Browse files
committed
show the current input method name in the tray icon
1 parent 9989e72 commit bf26b98

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/modules/notificationitem/notificationitem.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ class StatusNotifierItem : public dbus::ObjectVTable<StatusNotifierItem> {
7272

7373
std::string label() { return ""; }
7474

75+
std::string title() {
76+
const InputMethodEntry *imEntry = nullptr;
77+
if (auto *ic = parent_->menu()->lastRelevantIc()) {
78+
imEntry = parent_->instance()->inputMethodEntry(ic);
79+
}
80+
return imEntry == nullptr ? _("Input Method") : imEntry->name();
81+
}
82+
7583
static dbus::DBusStruct<
7684
std::string,
7785
std::vector<dbus::DBusStruct<int32_t, int32_t, std::vector<uint8_t>>>,
@@ -104,6 +112,15 @@ class StatusNotifierItem : public dbus::ObjectVTable<StatusNotifierItem> {
104112
lastLabel_ = std::move(label);
105113
}
106114

115+
void notifyNewTitle() {
116+
std::string currentTitle = title();
117+
if (currentTitle.empty() || lastTitle_ == currentTitle) {
118+
return;
119+
}
120+
newTitle();
121+
lastTitle_ = std::move(currentTitle);
122+
}
123+
107124
void reset() {
108125
releaseSlot();
109126
lastIconName_.clear();
@@ -138,8 +155,7 @@ class StatusNotifierItem : public dbus::ObjectVTable<StatusNotifierItem> {
138155
FCITX_OBJECT_VTABLE_PROPERTY(category, "Category", "s",
139156
[]() { return "SystemServices"; });
140157
FCITX_OBJECT_VTABLE_PROPERTY(id, "Id", "s", []() { return "Fcitx"; });
141-
FCITX_OBJECT_VTABLE_PROPERTY(title, "Title", "s",
142-
[]() { return _("Input Method"); });
158+
FCITX_OBJECT_VTABLE_PROPERTY(title, "Title", "s", [this]() { return title(); });
143159
FCITX_OBJECT_VTABLE_PROPERTY(status, "Status", "s",
144160
[]() { return "Active"; });
145161
FCITX_OBJECT_VTABLE_PROPERTY(windowId, "WindowId", "i", []() { return 0; });
@@ -238,6 +254,7 @@ class StatusNotifierItem : public dbus::ObjectVTable<StatusNotifierItem> {
238254
std::string cachedLabel_;
239255
std::vector<dbus::DBusStruct<int, int, std::vector<uint8_t>>>
240256
cachedLabelIcon_;
257+
std::string lastTitle_;
241258
};
242259

243260
NotificationItem::NotificationItem(Instance *instance)
@@ -406,6 +423,13 @@ void NotificationItem::newIcon() {
406423
// sni_->xayatanaNewLabel(sni_->label(), sni_->label());
407424
}
408425

426+
void NotificationItem::newTitle() {
427+
if (!sni_->isRegistered()) {
428+
return;
429+
}
430+
sni_->notifyNewTitle();
431+
}
432+
409433
class NotificationItemFactory : public AddonFactory {
410434
AddonInstance *create(AddonManager *manager) override {
411435
return new NotificationItem(manager->instance());

src/modules/notificationitem/notificationitem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class NotificationItem : public AddonInstance {
4949

5050
void maybeScheduleRegister();
5151
void cleanUp();
52+
void newTitle();
5253

5354
Instance *instance_;
5455
std::unique_ptr<dbus::ServiceWatcher> watcher_;

0 commit comments

Comments
 (0)