1 /***************************************************************************
2  *   Copyright (C) 2011~2012 by CSSlayer                                   *
3  *   wengxt@gmail.com                                                      *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.              *
19  ***************************************************************************/
20 /**
21  * @file   instance-internal.h
22  *
23  */
24 
25 #ifndef _FCITX_INSTANCE_INTERNAL_H_
26 #define _FCITX_INSTANCE_INTERNAL_H_
27 
28 #include <sys/stat.h>
29 #include <pthread.h>
30 #include <semaphore.h>
31 
32 #include "fcitx-utils/utarray.h"
33 #include "fcitx-utils/utils.h"
34 #include "ui-internal.h"
35 #include "configfile.h"
36 #include "profile.h"
37 #include "addon.h"
38 #include "context.h"
39 
40 typedef struct _UnusedIMItem {
41     char* name;
42     boolean status;
43     UT_hash_handle hh;
44 } UnusedIMItem;
45 
46 typedef struct _TimeoutItem {
47     FcitxTimeoutCallback callback;
48     void* arg;
49     unsigned long int milli;
50     uint64_t idx;
51     uint64_t time;
52 } TimeoutItem;
53 
54 typedef struct _FcitxICDataInfo {
55     FcitxICDataAllocCallback allocCallback;
56     FcitxICDataCopyCallback copyCallback;
57     FcitxICDataFreeCallback freeCallback;
58     void* arg;
59 } FcitxICDataInfo;
60 
61 typedef enum _FcitxEventFlag {
62     FEF_NONE = 0,
63     FEF_UI_MOVE = (1 << 1),
64     FEF_UI_UPDATE = (1 << 2),
65     FEF_EVENT_CHECK = (1 << 3),
66     FEF_RELOAD_ADDON = (1 << 4),
67     FEF_PROCESS_EVENT_MASK = ( FEF_UI_MOVE | FEF_UI_UPDATE | FEF_EVENT_CHECK )
68 } FcitxUIFlag;
69 
70 struct _FcitxInstance {
71     pthread_mutex_t fcitxMutex;
72     UT_array uistats;
73     UT_array uimenus;
74     UT_array uicompstats;
75     FcitxAddon* ui;
76     FcitxInputState* input;
77     boolean bMutexInited;
78     FcitxUIMenu imMenu;
79 
80     /* Fcitx is not good at multi process, so put a readonlyMode in it */
81     boolean readonlyMode;
82 
83     /* config file */
84     FcitxGlobalConfig* config;
85     FcitxProfile* profile;
86     UT_array addons;
87     UT_array imeclasses;
88     UT_array imes;
89     UT_array frontends;
90     UT_array modules;
91     UT_array eventmodules;
92 
93     struct _FcitxInputContext *CurrentIC;
94     struct _FcitxInputContext *ic_list;
95     struct _FcitxInputContext *free_list;
96     sem_t* sem;
97     sem_t startUpSem;
98     sem_t notifySem;
99     pthread_t pid;
100     fd_set rfds, wfds, efds;
101     int maxfd;
102     char* uiname;
103 
104     struct _HookStack* hookPreInputFilter;
105     struct _HookStack* hookPostInputFilter;
106     struct _HookStack* hookPreReleaseInputFilter;
107     struct _HookStack* hookPostReleaseInputFilter;
108     struct _HookStack* hookOutputFilter;
109     struct _HookStack* hookHotkeyFilter;
110     struct _HookStack* hookResetInputHook;
111     struct _HookStack* hookTriggerOnHook;
112     struct _HookStack* hookTriggerOffHook;
113     struct _HookStack* hookInputFocusHook;
114     struct _HookStack* hookInputUnFocusHook;
115     struct _HookStack* hookUpdateCandidateWordHook;
116     struct _HookStack* hookUpdateIMListHook;
117     struct _HookStack* hookCommitFilter;
118     struct _HookStack* hookICStateChangedHook;
119     struct _HookStack* hookIMChangedHook;
120     struct _HookStack* hookUIStatusChangedHook;
121 
122     uint32_t eventflag;
123 
124     FcitxContextState globalState;
125 
126     time_t totaltime;
127     time_t timeStart;
128     int iHZInputed;
129 
130     int iIMIndex;
131 
132     UT_array availimes;
133 
134     boolean imLoaded;
135 
136     FcitxAddon* uifallback;
137 
138     FcitxAddon* uinormal;
139 
140     FcitxContext* context;
141 
142     boolean tryReplace;
143 
144     char* globalIMName;
145 
146     char* fallbackuiName;
147 
148     FcitxAddon* currentIMAddon;
149 
150     UnusedIMItem* unusedItem;
151     UT_array* disableList;
152     UT_array* enableList;
153 
154     UT_array timeout;
155     volatile boolean initialized;
156     uint64_t timeoutIdx;
157 
158     UT_array icdata;
159     volatile boolean loadingFatalError;
160     volatile boolean quietQuit;
161     volatile boolean destroy;
162     volatile boolean restart;
163     int fd;
164     int overrideDelay;
165 
166     UT_array eventQueue;
167     UT_array* no_preedit_app_list;
168 
169     FcitxInputContext* lastIC;
170     char* delayedIM;
171 };
172 
173 void FcitxInstanceSetLastIC(FcitxInstance* instance, FcitxInputContext* ic);
174 void FcitxInstanceSetDelayedIM(FcitxInstance* instance, const char* im);
175 
176 static inline FcitxAddon**
FcitxInstanceGetPFrontend(FcitxInstance * instance,int id)177 FcitxInstanceGetPFrontend(FcitxInstance *instance, int id)
178 {
179     return fcitx_array_eltptr(&instance->frontends, id);
180 }
181 
182 #endif
183