pax_global_header00006660000000000000000000000064152422161410014510gustar00rootroot0000000000000052 comment=3b5c46f2a58ddd93d0f1269ecdf16b497afeee9c kenhys-fcitx-imlist-ac1f365/000077500000000000000000000000001524221614100160355ustar00rootroot00000000000000kenhys-fcitx-imlist-ac1f365/.github/000077500000000000000000000000001524221614100173755ustar00rootroot00000000000000kenhys-fcitx-imlist-ac1f365/.github/workflows/000077500000000000000000000000001524221614100214325ustar00rootroot00000000000000kenhys-fcitx-imlist-ac1f365/.github/workflows/ci.yml000066400000000000000000000025651524221614100225600ustar00rootroot00000000000000name: CI on: push: branches: - master pull_request: workflow_dispatch: jobs: build: name: ${{ matrix.backend }} with ${{ matrix.compiler }} on ${{ matrix.runner }} runs-on: ${{ matrix.runner }} strategy: fail-fast: false matrix: runner: - ubuntu-latest - ubuntu-24.04-arm compiler: - gcc - clang backend: - fcitx5 - fcitx4 env: CC: ${{ matrix.compiler }} steps: - uses: actions/checkout@v7 - name: Install build dependencies run: | sudo apt-get update -qq sudo apt-get install -y --no-install-recommends \ ${{ matrix.compiler }} \ autoconf \ automake \ make \ pkg-config \ libglib2.0-dev # The Fcitx 5 backend uses GDBus and needs only GIO. - name: Install the Fcitx 4 library if: matrix.backend == 'fcitx4' run: sudo apt-get install -y --no-install-recommends fcitx-libs-dev - name: Build run: | ./autogen.sh ./configure --enable-${{ matrix.backend }} make - name: Install run: sudo make install # fcitx-imlist prints its help before it connects to fcitx, so # this works without a session bus. - name: Run run: fcitx-imlist kenhys-fcitx-imlist-ac1f365/.gitignore000066400000000000000000000005571524221614100200340ustar00rootroot00000000000000# Object files *.o *.ko *.obj *.elf # Auto generated files .deps .libs config.h* config.status config.log autom4te.cache Makefile Makefile.in # Precompiled Headers *.gch *.pch # Libraries *.lib *.a *.la *.lo # Shared objects (inc. Windows DLLs) *.dll *.so *.so.* *.dylib # Executables *.exe *.out *.app *.i*86 *.x86_64 *.hex fcitx-imlist # Debug files *.dSYM/ kenhys-fcitx-imlist-ac1f365/LICENSE000066400000000000000000000431771524221614100170560ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. {description} Copyright (C) {year} {fullname} This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. {signature of Ty Coon}, 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. kenhys-fcitx-imlist-ac1f365/Makefile.am000066400000000000000000000001721524221614100200710ustar00rootroot00000000000000SUBDIRS = src examples EXTRA_DIST = LICENSE tag: git tag -a $(VERSION) -m "fcitx-imlist ${VERSION} has been released!" kenhys-fcitx-imlist-ac1f365/NEWS000066400000000000000000000012011524221614100165260ustar00rootroot00000000000000News of fcitx-imlist * 0.6.0 - Support Fcitx 5, which is now the backend built by default. Use --enable-fcitx4 to build against Fcitx 4 as before. - Support input method groups with the -g option (Fcitx 5 only). - Accept both fcitx-keyboard-us and keyboard-us spellings on either backend. * 0.5.1 (2016-02-24) - Bundle missing license file * 0.5.0 (2016-02-19) - Debianize - Fix some trivial compile warnings * 0.4.0 (2015-07-31) - Support enable (-e) option. * 0.3.0 (2015-07-17) - Support toggle (-t) option. * 0.2.0 (2015-06-05) - Support abbrevation in -s option * 0.1.0 (2015-05-31) - Initial release kenhys-fcitx-imlist-ac1f365/README.md000066400000000000000000000072521524221614100173220ustar00rootroot00000000000000# fcitx-imlist [![CI](https://github.com/kenhys/fcitx-imlist/actions/workflows/ci.yml/badge.svg)](https://github.com/kenhys/fcitx-imlist/actions/workflows/ci.yml) `fcitx-imlist` is a small program to show or change input method list. There is already similar program exists - `fcitx-remote` command. It can support to switch input method by `fcitx-remote -s INPUT_METHOD`, but It doesn't support to change the order of input method list. That is why I wrote this experimental program. Both Fcitx 4 and Fcitx 5 are supported, one backend per build. # Build Fcitx 5 is the default backend. It talks to the `org.fcitx.Fcitx.Controller1` D-Bus interface directly, so GLib and GIO are the only build dependencies. % ./autogen.sh % ./configure % make Pass `--enable-fcitx4` to build against Fcitx 4 instead. That backend uses `fcitx-gclient`, so its development package is required. % ./configure --enable-fcitx4 # Usage Fcitx 4 names its keyboard engines `fcitx-keyboard-us` while Fcitx 5 calls the same thing `keyboard-us`. Both spellings, and the bare `us`, are accepted on either backend. The examples below use Fcitx 4 names. ## How to show input methods? Use `-l` option to list input methods which is enabled. % fcitx-imlist -l fcitx-keyboard-jp (キーボード - 日本語) [enabled] mozc (Mozc) [enabled] fcitx-keyboard-us (キーボード - 英語 (US)) [enabled] ## How to show all input methods? Use `-l` and `-v` option at the same time to list all input methods. % fcitx-imlist -l -v fcitx-keyboard-jp (キーボード - 日本語) [enabled] mozc (Mozc) [enabled] fcitx-keyboard-us (キーボード - 英語 (US)) [enabled] fcitx-keyboard-af (キーボード - アフガニスタン語) [disabled] fcitx-keyboard-af-fa-olpc (キーボード - アフガニスタン語 - ペルシア語 (アフガニスタン、ダリー語 OLPC)) [disabled] fcitx-keyboard-af-olpc-ps (キーボード - アフガニスタン語 - パシュト語 (アフガニスタン、OLPC)) [disabled] ... ## How to change the order of input methods? Use `-s` option with input methods list to change the order. % fcitx-imlist -s fcitx-keyboard-us,mozc fcitx-keyboard-us (キーボード - 英語 (US)) [enabled] mozc (Mozc) [enabled] fcitx-keyboard-jp (キーボード - 日本語) [enabled] Omit `fcitx-keyboard-` prefix if you want. % fcitx-imlist -s us,mozc,jp fcitx-keyboard-us (キーボード - 英語 (US)) [enabled] mozc (Mozc) [enabled] fcitx-keyboard-jp (キーボード - 日本語) [enabled] ## How to toggle input method set? Use `-t` option to toggle input method set. The input method set is pre-configured. Here is the example configuration. % gsettings get org.xdump.fcitximlist fcitx-imlist-default 'jp,mozc' % gsettings get org.xdump.fcitximlist fcitx-imlist-alternative 'us,mozc' In toggle mode, `fcitx-imlist` command switches above configuration. ## How to enable an input method? Use `-e` option to put an input method in use. It is appended to the input methods already in use. % fcitx-imlist -e mozc fcitx-keyboard-jp (キーボード - 日本語) [enabled] mozc (Mozc) [enabled] # Input method groups (Fcitx 5 only) Fcitx 5 keeps input methods in named groups, and the options above act on the group in use. Add `-g` to act on the groups themselves instead. List the groups: % fcitx-imlist -l -g Default [current] Alternative Switch to a group: % fcitx-imlist -s Alternative -g Alternative [current] Toggle to the next group, wrapping around at the end: % fcitx-imlist -t -g Default [current] On Fcitx 4 these fail with a message, since it has no groups. kenhys-fcitx-imlist-ac1f365/autogen.sh000077500000000000000000000000671524221614100200410ustar00rootroot00000000000000#!/bin/sh ${AUTORECONF:-autoreconf} --force --install kenhys-fcitx-imlist-ac1f365/configure.ac000066400000000000000000000066031524221614100203300ustar00rootroot00000000000000# -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) AC_INIT([fcitx-imlist], [0.5.1], [kenhys@gmail.com]) AC_CONFIG_SRCDIR([src/fcitximlist.c]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_AUX_DIR([config]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([foreign tar-pax]) # Checks for programs. AC_PROG_CC # g_clear_pointer() needs 2.34. A stable g_ptr_array_sort_with_data() # needs 2.32. PKG_CHECK_MODULES([GLIB], glib-2.0 >= 2.34) PKG_CHECK_MODULES([GIO], gio-2.0 >= 2.34) # For debug AC_ARG_ENABLE(debug, [AS_HELP_STRING([--enable-debug], [use debug flags (default=no)])], [fcitx_imlist_debug="$enableval"], [fcitx_imlist_debug="no"]) if test "x$fcitx_imlist_debug" != "xno"; then fcitx_imlist_debug="yes" if test "$CLANG" = "yes"; then CFLAGS="$CFLAGS -O0 -g" CXXFLAGS="$CXXFLAGS -O0 -g" elif test "$GCC" = "yes"; then CFLAGS="$CFLAGS -O0 -g3" CXXFLAGS="$CXXFLAGS -O0 -g3" fi fi # Checks for libraries. # The program uses one backend. --enable-fcitx4 turns off the Fcitx 5 # default. Asking for both is an error. AC_ARG_ENABLE(fcitx4, [AS_HELP_STRING([--enable-fcitx4], [use Fcitx 4.x (default=no)])], [fcitx_imlist_fcitx4="$enableval"], [fcitx_imlist_fcitx4="no"]) AC_ARG_ENABLE(fcitx5, [AS_HELP_STRING([--enable-fcitx5], [use Fcitx 5.x (default=yes)])], [fcitx_imlist_fcitx5="$enableval"], [fcitx_imlist_fcitx5="auto"]) if test "x$fcitx_imlist_fcitx4" != "xno"; then fcitx_imlist_fcitx4="yes" if test "x$fcitx_imlist_fcitx5" = "xauto"; then fcitx_imlist_fcitx5="no" fi fi if test "x$fcitx_imlist_fcitx5" = "xauto"; then fcitx_imlist_fcitx5="yes" fi if test "x$fcitx_imlist_fcitx4" = "xyes" && test "x$fcitx_imlist_fcitx5" = "xyes"; then AC_MSG_ERROR([--enable-fcitx4 and --enable-fcitx5 are mutually exclusive.]) fi if test "x$fcitx_imlist_fcitx4" != "xyes" && test "x$fcitx_imlist_fcitx5" != "xyes"; then AC_MSG_ERROR([no backend selected. Use --enable-fcitx4 or --enable-fcitx5.]) fi if test "x$fcitx_imlist_fcitx4" = "xyes"; then PKG_CHECK_MODULES([FCITX4_GCLIENT], [fcitx-gclient], [ AC_MSG_NOTICE([fcitx-gclient found!]) AC_DEFINE([WITH_FCITX4], [1], [Define to 1 if Fcitx 4.x support is enabled]) ], [AC_MSG_ERROR([fcitx-gclient is required but not found.])] ) fi if test "x$fcitx_imlist_fcitx5" = "xyes"; then # Fcitx5GClient has no functions for the input method list, so the # Fcitx 5 backend uses GDBus to call org.fcitx.Fcitx.Controller1. # It needs only GIO to build. AC_DEFINE([WITH_FCITX5], [1], [Define to 1 if Fcitx 5.x support is enabled]) fi AM_CONDITIONAL([WITH_FCITX4], [test "x$fcitx_imlist_fcitx4" = "xyes"]) AM_CONDITIONAL([WITH_FCITX5], [test "x$fcitx_imlist_fcitx5" = "xyes"]) # PKG_CHECK_MODULES sets these, but only when it runs. Set them here # too. Then they are empty on an Fcitx 5 build, and src/Makefile.am # does not need a condition. AC_SUBST([FCITX4_GCLIENT_CFLAGS]) AC_SUBST([FCITX4_GCLIENT_LIBS]) # Checks for header files. # Checks for typedefs, structures, and compiler characteristics. # Checks for library functions. GLIB_GSETTINGS AC_CONFIG_FILES([ Makefile src/Makefile examples/Makefile ]) AC_OUTPUT AC_MSG_RESULT([ Configuration: Fcitx 4 backend: $fcitx_imlist_fcitx4 Fcitx 5 backend: $fcitx_imlist_fcitx5 debug: $fcitx_imlist_debug ]) kenhys-fcitx-imlist-ac1f365/examples/000077500000000000000000000000001524221614100176535ustar00rootroot00000000000000kenhys-fcitx-imlist-ac1f365/examples/Makefile.am000066400000000000000000000001711524221614100217060ustar00rootroot00000000000000EXTRA_DIST = org.xdump.fcitximlist.gschema.xml gsettings_SCHEMAS = org.xdump.fcitximlist.gschema.xml @GSETTINGS_RULES@ kenhys-fcitx-imlist-ac1f365/examples/org.xdump.fcitximlist.gschema.xml000066400000000000000000000014111524221614100262610ustar00rootroot00000000000000 true Use default set The value which indicate to use default set. "jp,mozc" Default set The default input method set. "us,mozc" Alternative set The alternative input method set. kenhys-fcitx-imlist-ac1f365/src/000077500000000000000000000000001524221614100166245ustar00rootroot00000000000000kenhys-fcitx-imlist-ac1f365/src/Makefile.am000066400000000000000000000006011524221614100206550ustar00rootroot00000000000000 AM_CFLAGS = \ $(GLIB_CFLAGS) \ $(GIO_CFLAGS) \ $(FCITX4_GCLIENT_CFLAGS) bin_PROGRAMS = fcitx-imlist fcitx_imlist_SOURCES = \ fcitximlist.c \ fcitximlist.h fcitx_imlist_LDADD = \ $(GLIB_LIBS) \ $(GIO_LIBS) \ $(FCITX4_GCLIENT_LIBS) if WITH_FCITX4 fcitx_imlist_SOURCES += fcitximlist-fcitx4.c endif if WITH_FCITX5 fcitx_imlist_SOURCES += fcitximlist-fcitx5.c endif kenhys-fcitx-imlist-ac1f365/src/fcitximlist-fcitx4.c000066400000000000000000000054701524221614100225340ustar00rootroot00000000000000#include "config.h" #include "fcitximlist.h" #include #include #include static FcitxInputMethod *im; /* * The list from fcitx-gclient. Keep it, because * fcitx_input_method_set_imlist() needs FcitxIMItem again. Each * FcitxImlistItem points to its FcitxIMItem in backend_data. */ static GPtrArray *raw_imlist; gboolean fcitx_imlist_backend_init(GError **error) { if (im) return TRUE; im = fcitx_input_method_new(G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, fcitx_utils_get_display_number(), NULL, error); return im != NULL; } void fcitx_imlist_backend_fini(void) { g_clear_pointer(&raw_imlist, g_ptr_array_unref); g_clear_object(&im); } gboolean fcitx_imlist_backend_has_group_support(void) { return FALSE; } gchar ** fcitx_imlist_backend_get_groups(GError **error) { g_set_error(error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Fcitx 4 has no input method groups"); return NULL; } gchar * fcitx_imlist_backend_get_current_group(GError **error) { g_set_error(error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Fcitx 4 has no input method groups"); return NULL; } gboolean fcitx_imlist_backend_switch_group(const gchar *group, GError **error) { g_set_error(error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Fcitx 4 has no input method groups"); return FALSE; } GPtrArray * fcitx_imlist_backend_get_imlist(GError **error) { GPtrArray *imlist; guint i; g_clear_pointer(&raw_imlist, g_ptr_array_unref); raw_imlist = fcitx_input_method_get_imlist(im); if (!raw_imlist) { g_set_error(error, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to get the input method list from fcitx"); return NULL; } imlist = g_ptr_array_new_with_free_func((GDestroyNotify)fcitx_imlist_item_free); for (i = 0; i < raw_imlist->len; i++) { FcitxIMItem *raw = g_ptr_array_index(raw_imlist, i); FcitxImlistItem *item = fcitx_imlist_item_new(raw->unique_name, raw->name, NULL, raw->enable); item->backend_data = raw; g_ptr_array_add(imlist, item); } return imlist; } gboolean fcitx_imlist_backend_set_imlist(GPtrArray *imlist, GError **error) { GPtrArray *ordered; guint i; /* The items belong to raw_imlist, so do not set a free function. */ ordered = g_ptr_array_new(); for (i = 0; i < imlist->len; i++) { FcitxImlistItem *item = g_ptr_array_index(imlist, i); FcitxIMItem *raw = item->backend_data; if (!raw) continue; raw->enable = item->enable; g_ptr_array_add(ordered, raw); } fcitx_input_method_set_imlist(im, ordered); g_ptr_array_free(ordered, TRUE); return TRUE; } kenhys-fcitx-imlist-ac1f365/src/fcitximlist-fcitx5.c000066400000000000000000000146601524221614100225360ustar00rootroot00000000000000#include "config.h" #include "fcitximlist.h" #include /* * Fcitx5GClient has no functions for the input method list. It only * handles the input context. So this backend uses GDBus and calls the * controller object on the session bus. */ #define FCITX5_BUS_NAME "org.fcitx.Fcitx5" #define FCITX5_CONTROLLER_PATH "/controller" #define FCITX5_CONTROLLER_INTERFACE "org.fcitx.Fcitx.Controller1" static GDBusProxy *controller; static GVariant * call_controller(const gchar *method, GVariant *parameters, GError **error) { return g_dbus_proxy_call_sync(controller, method, parameters, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error); } gboolean fcitx_imlist_backend_init(GError **error) { if (controller) return TRUE; controller = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, NULL, FCITX5_BUS_NAME, FCITX5_CONTROLLER_PATH, FCITX5_CONTROLLER_INTERFACE, NULL, error); return controller != NULL; } void fcitx_imlist_backend_fini(void) { g_clear_object(&controller); } gboolean fcitx_imlist_backend_has_group_support(void) { return TRUE; } gchar * fcitx_imlist_backend_get_current_group(GError **error) { GVariant *reply; gchar *group = NULL; reply = call_controller("CurrentInputMethodGroup", NULL, error); if (!reply) return NULL; g_variant_get(reply, "(s)", &group); g_variant_unref(reply); return group; } gchar ** fcitx_imlist_backend_get_groups(GError **error) { GVariant *reply; gchar **groups = NULL; reply = call_controller("InputMethodGroups", NULL, error); if (!reply) return NULL; g_variant_get(reply, "(^as)", &groups); g_variant_unref(reply); return groups; } gboolean fcitx_imlist_backend_switch_group(const gchar *group, GError **error) { GVariant *reply; reply = call_controller("SwitchInputMethodGroup", g_variant_new("(s)", group), error); if (!reply) return FALSE; g_variant_unref(reply); return TRUE; } /* * Get the information of a group. Pass NULL for default_layout or * entries if you do not need them. */ static gboolean get_group_info(const gchar *group, gchar **default_layout, GVariant **entries, GError **error) { GVariant *reply; GVariant *layout_variant; GVariant *entries_variant; reply = call_controller("InputMethodGroupInfo", g_variant_new("(s)", group), error); if (!reply) return FALSE; layout_variant = g_variant_get_child_value(reply, 0); entries_variant = g_variant_get_child_value(reply, 1); if (default_layout) *default_layout = g_variant_dup_string(layout_variant, NULL); if (entries) *entries = g_variant_ref(entries_variant); g_variant_unref(layout_variant); g_variant_unref(entries_variant); g_variant_unref(reply); return TRUE; } GPtrArray * fcitx_imlist_backend_get_imlist(GError **error) { GPtrArray *imlist; GHashTable *enabled; GVariant *entries = NULL; GVariant *reply; GVariant *available; GVariantIter iter; gchar *group; const gchar *unique_name; const gchar *name; const gchar *native_name; const gchar *icon; const gchar *label; const gchar *language_code; const gchar *layout; gboolean configurable; group = fcitx_imlist_backend_get_current_group(error); if (!group) return NULL; if (!get_group_info(group, NULL, &entries, error)) { g_free(group); return NULL; } g_free(group); imlist = g_ptr_array_new_with_free_func((GDestroyNotify)fcitx_imlist_item_free); enabled = g_hash_table_new(g_str_hash, g_str_equal); /* * The entries of the current group are the enabled input methods, * in the order that fcitx uses them. The group info has no display * name, so it is filled in from AvailableInputMethods below. */ g_variant_iter_init(&iter, entries); while (g_variant_iter_loop(&iter, "(&s&s)", &unique_name, &layout)) { FcitxImlistItem *item = fcitx_imlist_item_new(unique_name, unique_name, layout, TRUE); g_ptr_array_add(imlist, item); g_hash_table_insert(enabled, item->unique_name, item); } g_variant_unref(entries); reply = call_controller("AvailableInputMethods", NULL, error); if (!reply) { g_hash_table_unref(enabled); g_ptr_array_unref(imlist); return NULL; } available = g_variant_get_child_value(reply, 0); g_variant_iter_init(&iter, available); while (g_variant_iter_loop(&iter, "(&s&s&s&s&s&sb)", &unique_name, &name, &native_name, &icon, &label, &language_code, &configurable)) { FcitxImlistItem *item = g_hash_table_lookup(enabled, unique_name); if (item) { g_free(item->name); item->name = g_strdup(name); } else { g_ptr_array_add(imlist, fcitx_imlist_item_new(unique_name, name, "", FALSE)); } } g_variant_unref(available); g_variant_unref(reply); g_hash_table_unref(enabled); return imlist; } gboolean fcitx_imlist_backend_set_imlist(GPtrArray *imlist, GError **error) { GVariantBuilder builder; GVariant *reply; gchar *group; gchar *default_layout = NULL; guint i; group = fcitx_imlist_backend_get_current_group(error); if (!group) return FALSE; if (!get_group_info(group, &default_layout, NULL, error)) { g_free(group); return FALSE; } /* * SetInputMethodGroupInfo replaces the whole list, so send only the * enabled items. In Fcitx 5, an input method is disabled when it is * not in the group. */ g_variant_builder_init(&builder, G_VARIANT_TYPE("a(ss)")); for (i = 0; i < imlist->len; i++) { FcitxImlistItem *item = g_ptr_array_index(imlist, i); if (!item->enable) continue; g_variant_builder_add(&builder, "(ss)", item->unique_name, item->layout ? item->layout : ""); } reply = call_controller("SetInputMethodGroupInfo", g_variant_new("(ssa(ss))", group, default_layout, &builder), error); g_free(group); g_free(default_layout); if (!reply) return FALSE; g_variant_unref(reply); return TRUE; } kenhys-fcitx-imlist-ac1f365/src/fcitximlist.c000066400000000000000000000264521524221614100213400ustar00rootroot00000000000000#include "config.h" #include "fcitximlist.h" #include #include #include #include #define SETTINGS_SCHEMA_ID "org.xdump.fcitximlist" static gboolean list; static gchar *setlist; static gboolean verbose; static gboolean toggle; static gchar *keyboard_layout = NULL; static gboolean group_mode; static GOptionEntry entries[] = { { "list", 'l', 0, G_OPTION_ARG_NONE, &list, "List input method", NULL }, { "set", 's', 0, G_OPTION_ARG_STRING, &setlist, "Set input method list separated by ',' for multiple IM", NULL }, { "toggle", 't', 0, G_OPTION_ARG_NONE, &toggle, "Toggle keyboard layout", NULL }, { "enable", 'e', 0, G_OPTION_ARG_STRING, &keyboard_layout, "Enable keyboard layout", NULL }, { "group", 'g', 0, G_OPTION_ARG_NONE, &group_mode, "Operate on input method groups (Fcitx 5 only)", NULL }, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL }, { NULL } }; FcitxImlistItem * fcitx_imlist_item_new(const gchar *unique_name, const gchar *name, const gchar *layout, gboolean enable) { FcitxImlistItem *item = g_new0(FcitxImlistItem, 1); item->unique_name = g_strdup(unique_name); item->name = g_strdup(name); item->layout = g_strdup(layout); item->enable = enable; return item; } void fcitx_imlist_item_free(FcitxImlistItem *item) { if (!item) return; g_free(item->unique_name); g_free(item->name); g_free(item->layout); g_free(item); } static void report_error(const gchar *context, GError **error) { g_printerr("%s: %s\n", context, (error && *error) ? (*error)->message : "unknown error"); g_clear_error(error); } /* * Fcitx 4 calls a keyboard engine fcitx-keyboard-us. Fcitx 5 calls * the same thing keyboard-us. Accept both names, and also just us, * on both backends. */ static const gchar * strip_keyboard_prefix(const gchar *name) { if (g_str_has_prefix(name, "fcitx-keyboard-")) return name + strlen("fcitx-keyboard-"); if (g_str_has_prefix(name, "keyboard-")) return name + strlen("keyboard-"); return name; } static FcitxImlistItem * find_input_method(GPtrArray *imlist, const gchar *name) { FcitxImlistItem *abbrev = NULL; guint i; for (i = 0; i < imlist->len; i++) { FcitxImlistItem *item = g_ptr_array_index(imlist, i); if (g_strcmp0(item->unique_name, name) == 0) return item; if (!abbrev && g_strcmp0(strip_keyboard_prefix(item->unique_name), strip_keyboard_prefix(name)) == 0) abbrev = item; } return abbrev; } static void print_imlist(GPtrArray *imlist) { guint i; for (i = 0; i < imlist->len; i++) { FcitxImlistItem *item = g_ptr_array_index(imlist, i); if (item->enable || verbose) { printf("%s (%s) [%s]\n", item->unique_name, item->name, item->enable ? "enabled" : "disabled"); } } } static gint compare_by_priority(gconstpointer a, gconstpointer b, gpointer user_data) { FcitxImlistItem *item_a = *(FcitxImlistItem **)a; FcitxImlistItem *item_b = *(FcitxImlistItem **)b; GHashTable *priority = user_data; gsize priority_a; gsize priority_b; /* Input methods that were not named keep their order, and come after the named ones. */ priority_a = GPOINTER_TO_SIZE(g_hash_table_lookup(priority, item_a)); priority_b = GPOINTER_TO_SIZE(g_hash_table_lookup(priority, item_b)); if (priority_a == 0) priority_a = G_MAXSIZE; if (priority_b == 0) priority_b = G_MAXSIZE; if (priority_a < priority_b) return -1; if (priority_a > priority_b) return 1; return 0; } static gboolean list_input_method(void) { GPtrArray *imlist; GError *error = NULL; imlist = fcitx_imlist_backend_get_imlist(&error); if (!imlist) { report_error("Failed to get the input method list", &error); return FALSE; } print_imlist(imlist); g_ptr_array_unref(imlist); return TRUE; } static gboolean set_input_method_list(const gchar *spec) { GPtrArray *imlist; GHashTable *priority; GError *error = NULL; gchar **names; gchar **name; gsize rank = 1; gboolean succeeded; imlist = fcitx_imlist_backend_get_imlist(&error); if (!imlist) { report_error("Failed to get the input method list", &error); return FALSE; } names = g_strsplit(spec, ",", -1); priority = g_hash_table_new(NULL, NULL); for (name = names; *name; name++) { FcitxImlistItem *item = find_input_method(imlist, *name); if (!item) { g_printerr("No such input method: %s\n", *name); g_hash_table_unref(priority); g_strfreev(names); g_ptr_array_unref(imlist); return FALSE; } /* If an input method is named, enable it too. */ item->enable = TRUE; g_hash_table_insert(priority, item, GSIZE_TO_POINTER(rank)); rank++; } g_ptr_array_sort_with_data(imlist, compare_by_priority, priority); succeeded = fcitx_imlist_backend_set_imlist(imlist, &error); if (succeeded) print_imlist(imlist); else report_error("Failed to set the input method list", &error); g_hash_table_unref(priority); g_strfreev(names); g_ptr_array_unref(imlist); return succeeded; } static gboolean enable_input_method(const gchar *name) { GPtrArray *imlist; FcitxImlistItem *item; GError *error = NULL; gboolean succeeded; imlist = fcitx_imlist_backend_get_imlist(&error); if (!imlist) { report_error("Failed to get the input method list", &error); return FALSE; } item = find_input_method(imlist, name); if (!item) { g_printerr("No such input method: %s\n", name); g_ptr_array_unref(imlist); return FALSE; } if (item->enable) { print_imlist(imlist); g_ptr_array_unref(imlist); return TRUE; } item->enable = TRUE; succeeded = fcitx_imlist_backend_set_imlist(imlist, &error); if (succeeded) print_imlist(imlist); else report_error("Failed to set the input method list", &error); g_ptr_array_unref(imlist); return succeeded; } /* * g_settings_new() kills the program when the schema is missing, so * look the schema up first and print an error instead. */ static GSettings * open_settings(void) { GSettingsSchemaSource *source; GSettingsSchema *schema; GSettings *settings; source = g_settings_schema_source_get_default(); schema = source ? g_settings_schema_source_lookup(source, SETTINGS_SCHEMA_ID, TRUE) : NULL; if (!schema) { g_printerr("The GSettings schema %s is not installed.\n" "Install it with make install, or point " "GSETTINGS_SCHEMA_DIR at it.\n", SETTINGS_SCHEMA_ID); return NULL; } settings = g_settings_new_full(schema, NULL, NULL); g_settings_schema_unref(schema); return settings; } static gboolean toggle_input_method_set(void) { GSettings *settings; gboolean use_default; gchar *value; gboolean succeeded; settings = open_settings(); if (!settings) return FALSE; use_default = g_settings_get_boolean(settings, "fcitx-imlist-set"); if (!use_default) { value = g_settings_get_string(settings, "fcitx-imlist-alternative"); } else { value = g_settings_get_string(settings, "fcitx-imlist-default"); } succeeded = set_input_method_list(value); if (succeeded) { g_settings_set_boolean(settings, "fcitx-imlist-set", !use_default); g_settings_sync(); } g_free(value); g_object_unref(settings); return succeeded; } static gboolean require_group_support(void) { if (fcitx_imlist_backend_has_group_support()) return TRUE; g_printerr("Input method groups are supported on Fcitx 5 only.\n"); return FALSE; } static gboolean list_input_method_group(void) { GError *error = NULL; gchar **groups; gchar *current; gchar **group; if (!require_group_support()) return FALSE; groups = fcitx_imlist_backend_get_groups(&error); if (!groups) { report_error("Failed to get the input method groups", &error); return FALSE; } current = fcitx_imlist_backend_get_current_group(&error); if (!current) { report_error("Failed to get the current input method group", &error); g_strfreev(groups); return FALSE; } for (group = groups; *group; group++) { printf("%s%s\n", *group, g_strcmp0(*group, current) == 0 ? " [current]" : ""); } g_free(current); g_strfreev(groups); return TRUE; } static gboolean switch_input_method_group(const gchar *name) { GError *error = NULL; if (!require_group_support()) return FALSE; if (!fcitx_imlist_backend_switch_group(name, &error)) { report_error("Failed to switch the input method group", &error); return FALSE; } printf("%s [current]\n", name); return TRUE; } /* * Go to the next group. After the last group, go back to the first * one. If there are two groups, this switches between them. */ static gboolean toggle_input_method_group(void) { GError *error = NULL; gchar **groups; gchar *current; guint count; guint i; guint next = 0; gboolean succeeded; if (!require_group_support()) return FALSE; groups = fcitx_imlist_backend_get_groups(&error); if (!groups) { report_error("Failed to get the input method groups", &error); return FALSE; } count = g_strv_length(groups); if (count < 2) { g_printerr("Need at least two input method groups to toggle.\n"); g_strfreev(groups); return FALSE; } current = fcitx_imlist_backend_get_current_group(&error); if (!current) { report_error("Failed to get the current input method group", &error); g_strfreev(groups); return FALSE; } for (i = 0; i < count; i++) { if (g_strcmp0(groups[i], current) == 0) { next = (i + 1) % count; break; } } succeeded = switch_input_method_group(groups[next]); g_free(current); g_strfreev(groups); return succeeded; } int main(int argc, char *argv[]) { GOptionContext *context; GError *error = NULL; gboolean succeeded; context = g_option_context_new("- fcitx input method list utility"); g_option_context_set_help_enabled(context, TRUE); g_option_context_add_main_entries(context, entries, ""); if (!g_option_context_parse(context, &argc, &argv, &error)) { g_printerr("option parsing failed: %s\n", error->message); g_clear_error(&error); g_option_context_free(context); exit(1); } if (!list && !setlist && !toggle && !keyboard_layout) { gchar *help = g_option_context_get_help(context, FALSE, NULL); g_print("%s", help); g_free(help); g_option_context_free(context); return 0; } g_option_context_free(context); if (!fcitx_imlist_backend_init(&error)) { report_error("Failed to connect to fcitx", &error); return 1; } if (list) { succeeded = group_mode ? list_input_method_group() : list_input_method(); } else if (setlist) { succeeded = group_mode ? switch_input_method_group(setlist) : set_input_method_list(setlist); } else if (keyboard_layout) { if (group_mode) { g_printerr("--enable cannot be combined with --group.\n"); succeeded = FALSE; } else { succeeded = enable_input_method(keyboard_layout); } } else { succeeded = group_mode ? toggle_input_method_group() : toggle_input_method_set(); } fcitx_imlist_backend_fini(); /* GOption allocated these strings when it parsed the options. */ g_free(setlist); g_free(keyboard_layout); return succeeded ? 0 : 1; } kenhys-fcitx-imlist-ac1f365/src/fcitximlist.h000066400000000000000000000032421524221614100213350ustar00rootroot00000000000000#ifndef FCITX_IMLIST_H #define FCITX_IMLIST_H #include G_BEGIN_DECLS /* * One input method. Both backends use this struct, and only one * backend is built into the program. * * Do not rename this to FcitxIMItem. fcitx-gclient already has a type * with that name, and a fcitx_im_item_free() to go with it. */ typedef struct _FcitxImlistItem { gchar *unique_name; gchar *name; gchar *layout; /* Fcitx 5 only. NULL on Fcitx 4 */ gboolean enable; gpointer backend_data; /* The backend owns this. Do not free it here */ } FcitxImlistItem; FcitxImlistItem *fcitx_imlist_item_new(const gchar *unique_name, const gchar *name, const gchar *layout, gboolean enable); void fcitx_imlist_item_free(FcitxImlistItem *item); gboolean fcitx_imlist_backend_init(GError **error); void fcitx_imlist_backend_fini(void); /* * Get the input method list. It is a GPtrArray of FcitxImlistItem *, * in the order that fcitx uses them. The array owns the items, so * free it with g_ptr_array_unref(). */ GPtrArray *fcitx_imlist_backend_get_imlist(GError **error); gboolean fcitx_imlist_backend_set_imlist(GPtrArray *imlist, GError **error); /* * Only Fcitx 5 has input method groups. On Fcitx 4 the functions * below fail, and has_group_support() returns FALSE. */ gboolean fcitx_imlist_backend_has_group_support(void); gchar **fcitx_imlist_backend_get_groups(GError **error); gchar *fcitx_imlist_backend_get_current_group(GError **error); gboolean fcitx_imlist_backend_switch_group(const gchar *group, GError **error); G_END_DECLS #endif /* FCITX_IMLIST_H */