Skip to content

Commit

Permalink
Add a new helper function to display custom input method information. (
Browse files Browse the repository at this point in the history
…#1071)

This may be a better alternative for system notification in lots of
places.
  • Loading branch information
wengxt authored Jun 9, 2024
1 parent 63b2ba5 commit f2a1561
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/lib/fcitx/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <ctime>
#include <memory>
#include <stdexcept>
#include <string>
#include <unordered_map>
#include <utility>
#include <fmt/format.h>
Expand Down Expand Up @@ -2490,6 +2491,14 @@ void Instance::showInputMethodInformation(InputContext *ic) {
d->showInputMethodInformation(ic);
}

void Instance::showCustomInputMethodInformation(InputContext *ic,
const std::string &message) {
FCITX_DEBUG() << "Input method switched";
FCITX_D();
auto *inputState = ic->propertyFor(&d->inputStateFactory_);
inputState->showInputMethodInformation(message);
}

bool Instance::checkUpdate() const {
FCITX_D();
return (isInFlatpak() && fs::isreg("/app/.updated")) ||
Expand Down
22 changes: 22 additions & 0 deletions src/lib/fcitx/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define _FCITX_INSTANCE_H_

#include <memory>
#include <string>
#include <fcitx-utils/connectableobject.h>
#include <fcitx-utils/macros.h>
#include <fcitx/event.h>
Expand Down Expand Up @@ -441,13 +442,34 @@ class FCITXCORE_EXPORT Instance : public ConnectableObject {
* Show a small popup with input popup window with current input method
* information.
*
* The popup will be hidden after certain amount of time.
*
* This is useful for input method that has multiple sub modes. It can be
* called with switching sub modes within the input method.
*
* The behavior is controlled by global config.
*
* @param ic input context.
*/
void showInputMethodInformation(InputContext *ic);

/**
* Show a small popup with input popup window with current input method
* information.
*
* The popup will be hidden after certain amount of time. The popup will
* always be displayed, regardless of the showInputMethodInformation in
* global config.
*
* This is useful for input method that has internal switches.
*
* @param ic input context.
* @param message message string to be displayed
* @since 5.1.11
*/
void showCustomInputMethodInformation(InputContext *ic,
const std::string &message);

/**
* Check if need to invoke Instance::refresh.
*
Expand Down

0 comments on commit f2a1561

Please sign in to comment.