dail8859 / NotepadNext

A cross-platform, reimplementation of Notepad++
GNU General Public License v3.0
9k stars 548 forks source link

Updated fcitx required for supporting various input methods #218

Open maichaide opened 1 year ago

maichaide commented 1 year ago

If possible, please consider supporting input methods under linux, such as fcitx and ibus, which can't input Chinese at present.

dail8859 commented 1 year ago

I'm not familiar with fcitx, ibus, or dealing with any types of input methods. Not sure if this is something that needs adjusted in Qt or Scintilla currently.

NichtsHsu commented 1 year ago

我印象中这是 Qt 的问题,如果是 fcitx,需要把 libfcitxplatforminputcontextplugin.so 放在某个目录去加载。具体的细节不太记得了

dail8859 commented 1 year ago

@NichtsHsu Thanks for the info. Scintilla seems to have some sort of support for IME events, but not sure myself how to test it. Hopefully someone more familiar with it can give it a shot.

imkos commented 1 year ago

try https://aur.archlinux.org/packages/fcitx5-qt6-git, I succeeded. use fcitx5 replace fcitx

dail8859 commented 1 year ago

@imkos Thanks for looking into this! There isn't much information about fcitx and Qt, but the only thing I found was exactly what you suggested, and that is to update fcitx.

So I guess the question is now is if this project is able to do anything to address this? Or best to leave it up to the user (and possibly document the solution somewhere).

NichtsHsu commented 1 year ago

Hi everybody, here is a way to build NotepadNext with fcitx support.

  1. Clone fcitx-qt5.

  2. Install extra-cmake-modules package.

  3. export your Qt toolkit to $PATH, in my case, it means:

    export PATH=~/Qt/6.4.0/gcc_64/bin:~/Qt/Tools/CMake/bin:$PATH
  4. Enter fcitx-qt5 folder.

  5. If you are using Qt6 like me, modify the CMakeLists.txt as following:

    diff --git a/CMakeLists.txt b/CMakeLists.txt
    index f9c95af..9358528 100644
    --- a/CMakeLists.txt
    +++ b/CMakeLists.txt
    @@ -10,8 +10,8 @@ find_package(ECM 1.4.0 REQUIRED NO_MODULE)
    
     set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} 
    ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
    
    -option(ENABLE_QT5 "Enable Qt5" On)
    -option(ENABLE_QT6 "Enable Qt6 im module" Off)
    +option(ENABLE_QT5 "Enable Qt5" off)
    +option(ENABLE_QT6 "Enable Qt6 im module" on)
     option(ENABLE_LIBRARY "Qt library" On)
    
     include(GNUInstallDirs)
  6. Build it:

    mkdir build && cd build
    cmake ../
    make -j8
  7. Copy the fcitx-qt5/build/qt6/platforminputcontext/libfcitxplatforminputcontextplugin-qt6.so to ~/Qt/6.4.0/gcc_64/plugins/platforminputcontexts/ in my case. Should be similar in Qt5.

  8. Open Qt Creator, build NotepadNext, now you can use fcitx to input Chinese or others.

    image

NichtsHsu commented 1 year ago

I think packaging this library in Appimage allows NotepadNext to support fcitx easily.

dail8859 commented 1 year ago

@NichtsHsu Thanks! If/when this project moves to cmake then this might be the best solution.

So what is the root cause of the need to package fcitx manually? Do Linux OSs just not have an up-to-date fcitx installed by default?

NichtsHsu commented 1 year ago

@dail8859 I guess it might be related with how the AppImage is packaged and executed.

On Ubuntu, fcitx-qt5 is included in the package fcitx5-frontend-qt5. After installing this package, the library file libfcitxplatforminputcontextplugin.so will be installed in the /usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/ directory. At this point, use Qt5 to compile NotepadNext in Qt Creator, and you can input Chinese normally when running program. However, when running your AppImage, fcitx is still not responding.

I observed several Qt programs on my PC and found that some of them installed this library file in their own directory:

$ locate libfcitxplatforminputcontextplugin.so
/opt/kingsoft/wps-office/office6/qt/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.so
/opt/zoom/platforminputcontexts/libfcitxplatforminputcontextplugin.so

I'm not sure why, but they should have a reason for doing so.

dail8859 commented 1 year ago

@NichtsHsu Thanks for the excellent info as always!

I'm not sure why, but they should have a reason for doing so.

Agreed. This would seem to indicate that they've ran into this issue before and came to the same conclusion.

wineee commented 1 year ago

I'm not sure why, but they should have a reason for doing so.

wps use vendor libraries, they can't install libfcitxplatforminputcontextplugin.so to /usr/lib,otherwise it will conflict with fcitx-qt5

wps will set QT_PLUGIN_PATH environment variable when startup,to use this library export QT_PLUGIN_PATH=/opt/kingsoft/wps-office/office6/qt/plugins

shenlebantongying commented 1 year ago

The method mentioned by @NichtsHsu is the right direction.

I added fcitx's support to another Qt6 app and it works:

https://github.com/xiaoyifang/goldendict-ng/pull/802


linuxdeployqt will scan the qt's platforminputcontexts folder.

https://github.com/probonopd/linuxdeployqt/blob/8428c59318b250058e6cf93353e2871072bbf7f9/tools/linuxdeployqt/shared.cpp#L1379-L1381

Just install the libfcitx5platforminputcontextplugin.so to the corresponding qt's dir, and let linuxdeployqt to do the rest.


If AppDir/usr/plugins/platforminputcontexts/libfcitx5platforminputcontextplugin.so exist in the built appimage, then fcitx should work.

P.S. I googled related problems and I somehow came to this issue. I don't even know what is this project. Hopefully, my PR can be a reference if someone wants to add related code to this project's build script :)

shenlebantongying commented 1 year ago

So what is the root cause of the need to package fcitx manually?

No, not bundle fcitx entirely, just an im (input method) plugin (which I don't know in great detail, the app needs to load it so that the fcitx on the host system can communicate with the app?)

There is probably already an ibus plugin under AppDir/usr/plugins/platforminputcontexts/.

Do Linux OSs just not have an up-to-date fcitx installed by default?

Yes, they have, but appimage needs the lowest version possible, and ubuntu20.04 don't have fcitx's qt6 plugin, so we have to build one manually (or bump the ubuntu version to 22.10 and just sudo apt-get install fcitx5-frontend-qt6 in the CI).

aohanhongzhi commented 8 months ago

Hi everybody, here is a way to build NotepadNext with fcitx support.

  1. Clone fcitx-qt5.
  2. Install extra-cmake-modules package.
  3. export your Qt toolkit to $PATH, in my case, it means:
    export PATH=~/Qt/6.4.0/gcc_64/bin:~/Qt/Tools/CMake/bin:$PATH
  4. Enter fcitx-qt5 folder.
  5. If you are using Qt6 like me, modify the CMakeLists.txt as following:

    diff --git a/CMakeLists.txt b/CMakeLists.txt
    index f9c95af..9358528 100644
    --- a/CMakeLists.txt
    +++ b/CMakeLists.txt
    @@ -10,8 +10,8 @@ find_package(ECM 1.4.0 REQUIRED NO_MODULE)
    
    set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} 
    ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
    
    -option(ENABLE_QT5 "Enable Qt5" On)
    -option(ENABLE_QT6 "Enable Qt6 im module" Off)
    +option(ENABLE_QT5 "Enable Qt5" off)
    +option(ENABLE_QT6 "Enable Qt6 im module" on)
    option(ENABLE_LIBRARY "Qt library" On)
    
    include(GNUInstallDirs)
  6. Build it:
    mkdir build && cd build
    cmake ../
    make -j8
  7. Copy the fcitx-qt5/build/qt6/platforminputcontext/libfcitxplatforminputcontextplugin-qt6.so to ~/Qt/6.4.0/gcc_64/plugins/platforminputcontexts/ in my case. Should be similar in Qt5.
  8. Open Qt Creator, build NotepadNext, now you can use fcitx to input Chinese or others. image

pls add the code and PR