Fcitx
inputcontextmanager.h
1 /*
2  * SPDX-FileCopyrightText: 2016-2016 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 #ifndef _FCITX_INPUTCONTEXTMANAGER_H_
8 #define _FCITX_INPUTCONTEXTMANAGER_H_
9 
10 #include <memory>
11 #include <fcitx-config/enum.h>
12 #include <fcitx-utils/macros.h>
13 #include <fcitx/fcitxcore_export.h>
14 #include <fcitx/inputcontext.h>
15 
16 namespace fcitx {
17 
18 class InputContextManagerPrivate;
19 class FocusGroup;
20 class Instance;
21 class InputContextProperty;
22 typedef std::function<bool(FocusGroup *ic)> FocusGroupVisitor;
23 
24 FCITX_CONFIG_ENUM(PropertyPropagatePolicy, All, Program, No);
25 
26 class FCITXCORE_EXPORT InputContextManager {
27  friend class InputContext;
28  friend class FocusGroup;
29  friend class Instance;
30  friend class InputContextPropertyFactory;
31 
32 public:
34  virtual ~InputContextManager();
35 
36  /**
37  * Find the input context by UUID.
38  *
39  * This is useful when you want to pass a token from another process to
40  * identify the input context.
41  *
42  * @param uuid UUID of input context.
43  * @return pointer to input context or null if nothing is found.
44  *
45  * @see InputContext::uuid
46  */
47  InputContext *findByUUID(ICUUID uuid);
48 
49  /**
50  * Set the property propgate policy.
51  *
52  * The policy can be either All, Program or No, to define whether a certain
53  * state need to be copied to another input context.
54  *
55  * @param policy policy
56  *
57  * @see GlobalConfig::shareInputState
58  */
59  void setPropertyPropagatePolicy(PropertyPropagatePolicy policy);
60 
61  Instance *instance();
62 
63  /**
64  * Register a named property for input context.
65  *
66  * This is used to store the per-input context state.
67  *
68  * @param name unique name of input context.
69  * @param factory factory
70  * @return registration successful or not.
71  */
72  bool registerProperty(const std::string &name,
74 
75  bool foreach(const InputContextVisitor &visitor);
76  bool foreachFocused(const InputContextVisitor &visitor);
77  bool foreachGroup(const FocusGroupVisitor &visitor);
78 
79  /**
80  * Get the last focused input context. This is useful for certain UI to get
81  * the most recently used input context.
82  *
83  * @return pointer of the last focused input context or null if there is no
84  * focus.
85  */
86  InputContext *lastFocusedInputContext();
87  /**
88  * Get the last used input context. This is useful for certain UI to get the
89  * most recently used input context.
90  *
91  * Certain UI implementation may cause focus out in the application, this is
92  * a way for them to get the input context being used.
93  *
94  * When PropertyPropagatePolicy is All, if there is no other recently
95  * focused input context it will return a dummy input context. It is useful
96  * to use this dummy IC to propagate data to other input context, e.g.
97  * change current input method.
98  *
99  * @return fcitx::InputContext*
100  */
101  InputContext *mostRecentInputContext();
102 
103  /**
104  * Return a dummy input context registered with this input method manager.
105  *
106  * The value is useful for a place holder in certain cases, e.g. get some
107  * value from action.
108  *
109  * @return fcitx::InputContext*
110  * @since 5.0.24
111  */
112  InputContext *dummyInputContext() const;
113 
114  void setPreeditEnabledByDefault(bool enable);
115  bool isPreeditEnabledByDefault() const;
116 
117 private:
118  void finalize();
119 
120  void setInstance(Instance *instance);
121  void registerInputContext(InputContext &inputContext);
122  void unregisterInputContext(InputContext &inputContext);
123 
124  void registerFocusGroup(FocusGroup &group);
125  void unregisterFocusGroup(FocusGroup &group);
126  void unregisterProperty(const std::string &name);
127 
128  void notifyFocus(InputContext &inputContext, bool focus);
129 
130  InputContextPropertyFactory *factoryForName(const std::string &name);
131  void propagateProperty(InputContext &inputContext,
132  const InputContextPropertyFactory *factory);
133  InputContextProperty *property(InputContext &inputContext,
134  const InputContextPropertyFactory *factory);
135 
136  std::unique_ptr<InputContextManagerPrivate> d_ptr;
137  FCITX_DECLARE_PRIVATE(InputContextManager);
138 };
139 } // namespace fcitx
140 
141 #endif // _FCITX_INPUTCONTEXTMANAGER_H_
An instance represents a standalone Fcitx instance.
Definition: instance.h:88
Definition: action.cpp:17
Factory class for input context property.
Input Context for Fcitx.
An input context represents a client of Fcitx.
Definition: inputcontext.h:47
This is a class that designed to store state that is specific to certain input context.