Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements and minor bug fixes #8

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/meson_cpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Meson Build and Test
on:
push:
branches: [main]
paths:
- "**.cpp"
- "**.h"
- "**.build"
pull_request:
branches: [main]
paths:
- "**.cpp"
- "**.h"
- "**.build"

jobs:
build:
name: Build and Test on ${{ matrix.os }} with Meson v${{ matrix.meson_version }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04]
meson_version: ["1.4.1"]
steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.16
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install Fcitx5 dev packages
run: sudo apt install -y fcitx5-modules-dev
- name: Build and install Varnam
run: |
cd ../
git clone https://github.com/varnamproject/govarnam.git govarnam
cd govarnam
make
sudo make install
- name: Install Meson
run: python -m pip install meson==${{ matrix.meson_version }} ninja
- name: Checkout code
uses: actions/checkout@v4
- name: Configure Project
run: meson setup builddir/
env:
CC: g++
- name: Run Build
run: |
cd builddir
meson compile
- name: Run Tests
run: meson test -C builddir/ -v
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ builddir/
*.o
*.a

**/varnamfcitx-addon.conf
**/CMakeLists.txt
**/CMakeCache.txt
CMakeFiles/
meson_options.txt
meson_options.txt

compile_commands.json
.cache/
.vscode/
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ A wrapper to add Varnam Input Method Engine support in Fcitx5 Input Method.

Install `fcitx5-modules-dev` if you're building it on a debian based distribution.

## Build & Install
## Installation

### Build & Install

> [!IMPORTANT]
> Please Uninstall the older version first, to avoid conflicts.

```bash
git clone https://github.com/varnamproject/varnam-fcitx5.git
Expand All @@ -43,12 +48,17 @@ If meson version is less than `1.1` run the following command before `meson setu
mv meson.options meson_options.txt
```

## Uninstall

### Uninstall
```
cd buildir
sudo ninja uninstall
```
---

[![Packaging status](https://repology.org/badge/vertical-allrepos/varnam-fcitx5.svg)](https://repology.org/project/varnam-fcitx5/versions)

* Thank you [@mohammedbilalns](https://github.com/mohammedbilalns) for the Arch Linux Package([AUR](https://aur.archlinux.org/packages/varnam-fcitx5-git))
## Configuration

Varnam Fcitx can be configured using `fcitx5-configtool`. Please refer the [official documentation](https://fcitx-im.org/wiki/Configtool_(Fcitx_5)).
Expand Down
19 changes: 19 additions & 0 deletions com.varnamproject.Fcitx5.Addon.varnamfcitx.metainfo.xml.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<component type="addon">
<id>com.varnamproject.Fcitx5.Addon.varnamfcitx</id>
<extends>org.fcitx.Fcitx5</extends>
<metadata_license>CC0-1.0</metadata_license>
<project_license>GPL-3.0+</project_license>
<name>Varnam Fcitx5</name>
<summary>Varnam Engine for Fcitx5</summary>
<developer id="com.varnamproject">
<name>The Varnam Project</name>
</developer>
<url type="homepage">https://varnamproject.com/</url>
<url type="bugtracker">https://github.com/varnamproject/varnam-fcitx5/issues</url>
<url type="vcs-browser">https://github.com/varnamproject/varnam-fcitx5</url>
<project_group>Fcitx</project_group>
<releases>
<release version="0.0.1" date="2024-07-07"/>
</releases>
</component>
27 changes: 19 additions & 8 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,30 @@ else
lib_dir = get_option('libdir')
endif

if (fs.exists('/usr/local/share/fcitx5/inputmethod'))
data_dir = '/usr/local/share'
elif (fs.exists('/usr/share/fcitx5/inputmethod'))
data_dir = '/usr/share/'
else
data_dir = get_option('datadir')
endif
data_dir = get_option('datadir')

if get_option('varnam_debug')
add_global_arguments('-DDEBUG_MODE', language: 'cpp')
endif

config_data = configuration_data()
if (get_option('version') != '')
config_data.set('version', get_option('version'))
elif (run_command('git', 'describe', check: false).stdout().strip() == '')
config_data.set('version', meson.project_version())
else
git_tag = run_command('git', 'describe', '--always', '--dirty', check: false).stdout().strip()
config_data.set('version', git_tag.strip('v'))
endif

# source
subdir('src')
# icons
subdir('icons')
subdir('icons')

# install AppStream Metadata file
install_data(
'com.varnamproject.Fcitx5.Addon.varnamfcitx.metainfo.xml.in',
rename: 'com.varnamproject.Fcitx5.Addon.varnamfcitx.metainfo.xml',
install_dir: data_dir + '/metainfo',
)
3 changes: 2 additions & 1 deletion meson.options
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
option('varnam_debug', type: 'boolean', value: false)
option('varnam_debug', type: 'boolean', value: false)
option('version', type: 'string', value: '')
8 changes: 4 additions & 4 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ shared_library(
dependencies: [fcitx5_core_dep, fcitx5_module_dep, varnam_dep],
install: true,
install_dir: lib_dir + '/fcitx5',
name_prefix: '',
)

# Input Method registration file
Expand All @@ -22,8 +21,9 @@ install_data(
)

# Addon config file
install_data(
'varnamfcitx-addon.conf.in',
rename: 'varnamfcitx.conf',
configure_file(
configuration: config_data,
input: 'varnamfcitx-addon.conf.in',
output: 'varnamfcitx.conf',
install_dir: data_dir + '/fcitx5/addon',
)
14 changes: 9 additions & 5 deletions src/varnam_candidate.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "varnam_candidate.h"
#include "varnam_utils.h"
#include "varnam_config.h"
#include "varnam_state.h"

Expand All @@ -20,12 +19,15 @@ VarnamCandidateList::VarnamCandidateList(VarnamEngine *engine, InputContext *ic)
: engine_(engine), ic_(ic) {
const VarnamEngineConfig *config =
static_cast<const VarnamEngineConfig *>(engine_->getConfig());
CandidateLayoutHint layout;
if (!config) {
VARNAM_WARN() << "Invalid configuration";
throw std::runtime_error("invalid config");
layout = CandidateLayoutHint::Vertical;
} else {
layout = config->candidateLayout.value();
}
setPageable(this);
setLayoutHint(config->candidateLayout.value());
setLayoutHint(layout);
}

void VarnamCandidateList::prev() {
Expand Down Expand Up @@ -55,8 +57,9 @@ void VarnamCandidateList::prevCandidate() {
if (index >= pageSize() && (currentPage() > 0)) {
setPage(currentPage());
}
state->selectCandidate(cursorIndex());
setGlobalCursorIndex(index);
state->selectCandidate(cursorIndex());
ic_->updateUserInterface(UserInterfaceComponent::InputPanel);
}

void VarnamCandidateList::nextCandidate() {
Expand All @@ -66,8 +69,9 @@ void VarnamCandidateList::nextCandidate() {
if (index >= pageSize() && (currentPage() < totalPages())) {
setPage(currentPage());
}
state->selectCandidate(cursorIndex());
setGlobalCursorIndex(index);
state->selectCandidate(cursorIndex());
ic_->updateUserInterface(UserInterfaceComponent::InputPanel);
}

} // namespace fcitx
20 changes: 9 additions & 11 deletions src/varnam_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ FCITX_CONFIGURATION(
IntConstrain(3, 10)};

// Enable Learning Words on commit
Option<bool> shouldLearnWords{this, "Learn Words",
_("Enable Learning New Words"), true};

Option<bool> shouldLearnWords{this, "Learn Words", _("Learn New Words"),
true};
// Strictly Follow Schema
Option<bool> strictlyFollowScheme{
this, "Strictly Follow Scheme",
_("Strictly Follow Scheme For Dictionary Results"), false};

// Dictionary Suggestions Limit
Option<int, IntConstrain> dictionarySuggestionsLimit{
this, "Dictionary Suggestions Limit", _("Dictionary Suggestions Limit"),
Expand All @@ -57,33 +56,32 @@ FCITX_CONFIGURATION(
this,
"PrevCandidate",
_("Previous Candidate"),
{Key("Alt+Up")},
{Key("Up")},
KeyListConstrain(KeyConstrainFlag::AllowModifierLess)};

// Next Candidate Shortcut
KeyListOption nextCandidate{
this,
"NextCandidate",
_("Next Candidate"),
{Key("Alt+Down")},
{Key("Down")},
KeyListConstrain(KeyConstrainFlag::AllowModifierLess)};

// Previous Page
KeyListOption prevPage{
this,
"PrevPage",
_("Previous Page"),
{Key("Alt+Left")},
KeyListConstrain(KeyConstrainFlag::AllowModifierLess)};
{Key("Alt+Up")},
KeyListConstrain(KeyConstrainFlag::AllowModifierOnly)};

// Next Page
KeyListOption nextPage{
this,
"NextPage",
_("Next Page"),
{Key("Alt+Right")},
KeyListConstrain(KeyConstrainFlag::AllowModifierLess)};
);
{Key("Alt+Down")},
KeyListConstrain(KeyConstrainFlag::AllowModifierOnly)};);

} // namespace fcitx
#endif
14 changes: 7 additions & 7 deletions src/varnam_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <fcitx-config/iniparser.h>
#include <fcitx/inputpanel.h>
#include <libgovarnam/c-shared.h>

extern "C" {
#include <libgovarnam/libgovarnam.h>
Expand All @@ -14,7 +15,6 @@ namespace fcitx {
VarnamEngine::VarnamEngine(Instance *instance)
: instance_(instance),
factory_([this](InputContext &ic) { return new VarnamState(this, ic); }) {
reloadConfig();
instance->inputContextManager().registerProperty("varnamState", &factory_);
}

Expand All @@ -30,6 +30,8 @@ VarnamEngine::~VarnamEngine() {

void VarnamEngine::activate(const InputMethodEntry &entry,
InputContextEvent &contextEvent) {
FCITX_UNUSED(contextEvent);
reloadConfig();
#ifdef DEBUG_MODE
VARNAM_INFO() << "activate scheme:" << entry.uniqueName();
#endif
Expand All @@ -39,7 +41,7 @@ void VarnamEngine::activate(const InputMethodEntry &entry,
VARNAM_WARN() << "Failed to initialize Varnam";
throw std::runtime_error("failed to initialize varnam");
}

varnam_config(varnam_handle, VARNAM_CONFIG_SET_DICTIONARY_MATCH_EXACT,
config_.strictlyFollowScheme.value());
varnam_config(varnam_handle, VARNAM_CONFIG_SET_DICTIONARY_SUGGESTIONS_LIMIT,
Expand All @@ -59,7 +61,7 @@ void VarnamEngine::deactivate(const InputMethodEntry &entry,
if (event.type() == EventType::InputContextSwitchInputMethod) {
auto ic = event.inputContext();
auto state = ic->propertyFor(&factory_);
state->commitPreedit();
state->commitText();
state->updateUI();
}
reset(entry, event);
Expand Down Expand Up @@ -117,11 +119,9 @@ void VarnamEngine::reset(const InputMethodEntry &entry,
InputContextEvent &event) {
FCITX_UNUSED(entry);
auto ic = event.inputContext();
auto state = event.inputContext()->propertyFor(&factory_);
auto state = ic->propertyFor(&factory_);
state->reset();
ic->inputPanel().reset();
ic->updatePreedit();
ic->updateUserInterface(UserInterfaceComponent::InputPanel);
state->updateUI();
}

void VarnamEngine::setConfig(const RawConfig &config) {
Expand Down
Loading
Loading