summaryrefslogtreecommitdiff
path: root/community/fcitx/add-a-context-variable-to-disable-punc.patch
blob: c0bdd9049e086d2841c22414b95d8b6df0307de5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
From: Xuetian Weng <wengxt@gmail.com>
Date: Tue, 11 Mar 2014 00:13:43 +0800
Subject: add a context variable to disable punc

---
 src/lib/fcitx/context.h |    2 ++
 src/module/punc/punc.c  |   12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/src/lib/fcitx/context.h b/src/lib/fcitx/context.h
index 32115af..05f0f91 100644
--- a/src/lib/fcitx/context.h
+++ b/src/lib/fcitx/context.h
@@ -70,6 +70,8 @@ extern "C" {
     #define CONTEXT_DISABLE_AUTO_FIRST_CANDIDATE_HIGHTLIGHT "CONTEXT_DISABLE_AUTO_FIRST_CANDIDATE_HIGHTLIGHT"
     /** disable auto first candidate highlight */
     #define CONTEXT_DISABLE_FULLWIDTH "CONTEXT_DISABLE_FULLWIDTH"
+    /** disable punc module */
+    #define CONTEXT_DISABLE_PUNC "CONTEXT_DISABLE_PUNC"
 
     /**
      * @brief register a new global context variable
diff --git a/src/module/punc/punc.c b/src/module/punc/punc.c
index be6dec3..3327f9c 100644
--- a/src/module/punc/punc.c
+++ b/src/module/punc/punc.c
@@ -154,6 +154,8 @@ void* PuncCreate(FcitxInstance* instance)
                                                   PuncWhichCopy, PuncWhichFree,
                                                   puncState);
 
+    FcitxInstanceRegisterWatchableContext(instance, CONTEXT_DISABLE_PUNC, FCT_Boolean, FCF_ResetOnInputMethodChange);
+
     FcitxPuncAddFunctions(instance);
     return puncState;
 }
@@ -250,6 +252,11 @@ boolean PuncPreFilter(void* arg, FcitxKeySym sym, unsigned int state,
 {
     FCITX_UNUSED(retVal);
     FcitxPuncState *puncState = (FcitxPuncState*)arg;
+    boolean disablePunc = FcitxInstanceGetContextBoolean(
+        puncState->owner, CONTEXT_DISABLE_PUNC);
+    if (disablePunc)
+        return false;
+
     if (FcitxHotkeyIsHotKeySimple(sym, state) &&
         !FcitxHotkeyIsHotKeyDigit(sym, state) && !IsHotKeyPunc(sym, state))
         puncState->bLastIsNumber = false;
@@ -269,6 +276,11 @@ boolean ProcessPunc(void* arg, FcitxKeySym sym, unsigned int state, INPUT_RETURN
     if (*retVal != IRV_TO_PROCESS)
         return false;
 
+    boolean disablePunc = FcitxInstanceGetContextBoolean(
+        puncState->owner, CONTEXT_DISABLE_PUNC);
+    if (disablePunc)
+        return false;
+
     FcitxCandidateWordList *candList = FcitxInputStateGetCandidateList(input);
     if (FcitxCandidateWordGetListSize(candList) != 0) {
         if (FcitxCandidateWordGetHasGoneToNextPage(candList) &&