Skip to content

Commit

Permalink
Merge pull request #485 from BambooEngine/feat/revamp-setup-ui
Browse files Browse the repository at this point in the history
Add option to workaround WPS
  • Loading branch information
luongthanhlam committed May 19, 2024
2 parents 1491c3f + 841a9dd commit 8160c9b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 19 deletions.
4 changes: 2 additions & 2 deletions config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const (
_IBrestoreKeyStrokesEnabled //deprecated
IBmouseCapturing
IBworkaroundForFBMessenger
IBworkaroundForWPS
IBstdFlags = IBspellCheckEnabled | IBspellCheckWithRules | IBautoNonVnRestore | IBddFreeStyle |
IBmouseCapturing | IBautoCapitalizeMacro | IBnoUnderline
IBmouseCapturing | IBautoCapitalizeMacro | IBnoUnderline | IBworkaroundForWPS
)

3 changes: 3 additions & 0 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,17 @@ func (e *IBusBambooEngine) PropertyActivate(propName string, propState uint32) *
}
if propName == PropKeyConfiguration {
ui.OpenGUI(e.engineName)
e.config = config.LoadConfig(e.engineName)
return nil
}
if propName == PropKeyInputModeLookupTableShortcut {
ui.OpenGUI(e.engineName)
e.config = config.LoadConfig(e.engineName)
return nil
}
if propName == PropKeyMacroTable {
ui.OpenGUI(e.engineName)
e.config = config.LoadConfig(e.engineName)
return nil
}

Expand Down
7 changes: 4 additions & 3 deletions engine_preedit.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func (e *IBusBambooEngine) preeditProcessKeyEvent(keyVal uint32, keyCode uint32,
newText, isWordBreakRune := e.getCommitText(keyVal, keyCode, state)
isPrintableKey := e.isPrintableKey(state, keyVal)
if isWordBreakRune {
// fmt.Printf("isWordBreakRune=%v isPrintable=%v\n", isWordBreakRune, isPrintableKey)
e.commitPreeditAndResetForWBS(newText, isPrintableKey)
return isPrintableKey, nil
}
Expand Down Expand Up @@ -106,7 +105,7 @@ func (e *IBusBambooEngine) updatePreedit(processedStr string) {
return
}
var ibusText = ibus.NewText(encodedStr)
if inStringList(enabledAuxiliaryTextList, e.getWmClass()) {
if inStringList(enabledAuxiliaryTextList, e.getWmClass()) && e.config.IBflags&config.IBworkaroundForWPS != 0 {
e.UpdateAuxiliaryText(ibusText, true)
return
}
Expand Down Expand Up @@ -200,7 +199,9 @@ func (e *IBusBambooEngine) resetPreedit() {
}

func (e *IBusBambooEngine) commitPreeditAndResetForWBS(s string, isWBS bool) {
if isWBS {
if e.config.IBflags&config.IBworkaroundForFBMessenger != 0 || isWBS {
// Fix missing the first word while typing in FB Messager as FB prefers
// committing text before hiding preedit
e.commitText(s)
e.HidePreeditText()
} else {
Expand Down
40 changes: 35 additions & 5 deletions ui/keyboard-shortcut-editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define TOTAL_ROWS 5
#define TOTAL_MASKS_PER_ROW 4
#define IBworkaroundForFBMessenger 1<<19
#define IBworkaroundForWPS 1<<20

int row = 0;
int col = 0;
Expand Down Expand Up @@ -286,13 +287,35 @@ static void set_margin ( GtkWidget *vbox, gint hmargin, gint vmargin )
gtk_widget_set_margin_top(vbox, vmargin);
gtk_widget_set_margin_bottom(vbox, vmargin);
}

static void on_toggle_fix_wps_clicked (GtkWidget *checkbox, gpointer data)
{
guint flags = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(checkbox), "flags"));
gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox));
if (active) {
if (data != NULL) {
show_input_mode_alert((char*)data);
}
flags |= IBworkaroundForWPS;
} else {
flags &= ~(IBworkaroundForWPS);
}
saveFlags(flags);
}

static void on_toggle_fix_address_bar_clicked (GtkWidget *checkbox, gpointer data)
{
guint flags = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(checkbox), "flags"));
gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox));
if (active) {
show_input_mode_alert((char*)data);
if (data != NULL) {
show_input_mode_alert((char*)data);
}
flags |= IBworkaroundForFBMessenger;
} else {
flags &= ~(IBworkaroundForFBMessenger);
}
fixFB(active);
saveFlags(flags);
}

static void
Expand Down Expand Up @@ -370,13 +393,13 @@ char *options[] = {
"6. XTestFakeKeyEvent (không gạch chân)",
};

static void add_page_other_settings_content(GtkWidget *parent, GtkWidget *w, guint64 flags, int mode)
static void add_page_other_settings_content(GtkWidget *parent, GtkWidget *w, guint flags, int mode)
{
GtkWidget *grid;
GtkWidget *label1;
GtkWidget *label2;
GtkWidget *dropdown1;
GtkWidget *checkbox2;
GtkWidget *checkbox2, *checkbox3;
GtkWidget *cancel_button;
GtkWidget *hbox;

Expand All @@ -392,8 +415,15 @@ static void add_page_other_settings_content(GtkWidget *parent, GtkWidget *w, gui
checkbox2 = gtk_check_button_new_with_label("Sửa lỗi lặp chữ trong FB");
gtk_grid_attach(GTK_GRID(grid), checkbox2, 0, 1, 1, 1);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox2), flags&IBworkaroundForFBMessenger);
g_object_set_data(G_OBJECT(checkbox2), "flags", GUINT_TO_POINTER(flags));
g_signal_connect(checkbox2, "toggled", G_CALLBACK(on_toggle_fix_address_bar_clicked), fix_fb_alert);

checkbox3 = gtk_check_button_new_with_label("Sửa lỗi không hiện chữ trong WPS");
gtk_grid_attach(GTK_GRID(grid), checkbox3, 0, 2, 1, 1);
g_object_set_data(G_OBJECT(checkbox3), "flags", GUINT_TO_POINTER(flags));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox3), flags&IBworkaroundForWPS);
g_signal_connect(checkbox3, "toggled", G_CALLBACK(on_toggle_fix_wps_clicked), NULL);

// Set consistent padding for all rows
gtk_grid_set_row_spacing(GTK_GRID(grid), 10);
gtk_grid_set_column_spacing(GTK_GRID(grid), 20);
Expand Down Expand Up @@ -422,7 +452,7 @@ static void add_page_other_settings_content(GtkWidget *parent, GtkWidget *w, gui
/*
* Main - program begins here
*/
int openGUI(guint64 flags, int mode, guint32 *s, int size, char *mtext, char *cfg_text) {
int openGUI(guint flags, int mode, guint32 *s, int size, char *mtext, char *cfg_text) {
GtkWidget *w;
GtkWidget *vbox, *vcbox;
int which;
Expand Down
14 changes: 5 additions & 9 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package ui
#cgo pkg-config: gtk+-3.0
#include <gtk/gtk.h>
extern int openGUI(guint64 flags, int mode, guint32 *s, int size, char *mtext, char *cfgtext);
extern int openGUI(guint flags, int mode, guint32 *s, int size, char *mtext, char *cfgtext);
*/
import "C"
import (
Expand All @@ -16,17 +16,13 @@ import (

var engineName string

//export fixFB
func fixFB(active int) {
//export saveFlags
func saveFlags(flags C.guint) {
var (
cfg = config.LoadConfig(engineName)
)
config.SaveConfig(cfg, engineName)
if active == 1 {
cfg.IBflags |= config.IBworkaroundForFBMessenger
} else {
cfg.IBflags &= ^config.IBworkaroundForFBMessenger
}
cfg.IBflags = uint(flags)
config.SaveConfig(cfg, engineName)
}

Expand Down Expand Up @@ -100,5 +96,5 @@ func OpenGUI(engName string) {
panic(err)
}
os.Setenv("GTK_IM_MODULE", "gtk-im-context-simple")
C.openGUI(C.guint64(cfg.IBflags), C.int(cfg.DefaultInputMode), s, C.int(size), C.CString(string(mText)), C.CString(string(data)))
C.openGUI(C.guint(cfg.IBflags), C.int(cfg.DefaultInputMode), s, C.int(size), C.CString(string(mText)), C.CString(string(data)))
}

0 comments on commit 8160c9b

Please sign in to comment.