Skip to content

Commit ced4ba6

Browse files
committed
Disable Cinnamon built-in shortcuts, keyboard applet when using
fcitx. Add an infobar to InputSources.py with explanation and a button to launch fcitx5-configtool. Only pass the primary keyboard layout to the x11 server.
1 parent 2822bbf commit ced4ba6

5 files changed

Lines changed: 66 additions & 5 deletions

File tree

files/usr/share/cinnamon/applets/keyboard@cinnamon.org/applet.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const Signals = imports.signals;
88
const KeyboardManager = imports.ui.keyboardManager;
99
const IBus = imports.gi.IBus;
1010
const IBusManager = imports.misc.ibusManager;
11+
const IMFramework = imports.misc.imFramework;
1112
const SignalManager = imports.misc.signalManager;
1213

1314
const PANEL_EDIT_MODE_KEY = "panel-edit-mode";
@@ -57,11 +58,16 @@ class CinnamonKeyboardApplet extends Applet.Applet {
5758
this._selectedLayout = null;
5859
this._layoutItems = new Map();
5960

61+
// Under fcitx, layout/IME state and indication belong to fcitx's own tray
62+
// icon. Stay hidden and don't suppress the external IM's tray icon.
63+
this._imIsFcitx = IMFramework.getFramework() === IMFramework.FRAMEWORK_FCITX;
6064

6165
try {
6266
this.metadata = metadata;
63-
Main.systrayManager.registerTrayIconReplacement("keyboard", metadata.uuid);
64-
Main.systrayManager.registerTrayIconReplacement("input-method", metadata.uuid);
67+
if (!this._imIsFcitx) {
68+
Main.systrayManager.registerTrayIconReplacement("keyboard", metadata.uuid);
69+
Main.systrayManager.registerTrayIconReplacement("input-method", metadata.uuid);
70+
}
6571

6672
this.menuManager = new PopupMenu.PopupMenuManager(this);
6773
this.menu = new Applet.AppletPopupMenu(this, orientation);
@@ -119,7 +125,8 @@ class CinnamonKeyboardApplet extends Applet.Applet {
119125
}
120126

121127
_onPanelEditModeChanged() {
122-
this.actor.visible = global.settings.get_boolean(PANEL_EDIT_MODE_KEY) || this._inputSourcesManager.multipleSources;
128+
this.actor.visible = !this._imIsFcitx &&
129+
(global.settings.get_boolean(PANEL_EDIT_MODE_KEY) || this._inputSourcesManager.multipleSources);
123130
}
124131

125132
on_applet_added_to_panel() {
@@ -180,7 +187,7 @@ class CinnamonKeyboardApplet extends Applet.Applet {
180187
this._layoutSection.addMenuItem(menuItem);
181188
}
182189

183-
if (!this._inputSourcesManager.multipleSources) {
190+
if (this._imIsFcitx || !this._inputSourcesManager.multipleSources) {
184191
this.menu.close();
185192
this.actor.hide();
186193
} else {
@@ -220,7 +227,7 @@ class CinnamonKeyboardApplet extends Applet.Applet {
220227

221228
this._panel_icon_box.set_child(actor);
222229

223-
if (!this._inputSourcesManager.multipleSources) {
230+
if (this._imIsFcitx || !this._inputSourcesManager.multipleSources) {
224231
this.actor.hide();
225232
}
226233

files/usr/share/cinnamon/cinnamon-settings/bin/InputSources.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from xapp.GSettingsWidgets import PXGSettingsBackend, GSettingsSwitch
1616

1717
from bin import AddKeyboardLayout
18+
from bin.util import using_fcitx
1819

1920
MAX_LAYOUTS_PER_GROUP = 4
2021

@@ -47,6 +48,10 @@ def __init__(self):
4748

4849
self.engine_config_button = builder.get_object("engine_config_button")
4950
self.engine_config_button.connect("clicked", self.on_engine_config_clicked)
51+
# Configure is ibus-engine-specific; fcitx engines are configured in fcitx.
52+
if using_fcitx():
53+
self.engine_config_button.set_no_show_all(True)
54+
self.engine_config_button.set_visible(False)
5055
self.add_layout_button = builder.get_object("add_layout")
5156
self.add_layout_button.connect("clicked", self.on_add_layout_clicked)
5257
self.remove_layout_button = builder.get_object("remove_layout")
@@ -58,6 +63,31 @@ def __init__(self):
5863

5964
self.update_widgets()
6065

66+
if using_fcitx():
67+
# Under fcitx, layout switching, the applet and per-window memory are
68+
# owned by fcitx, and input methods are configured in fcitx's own
69+
# tools. Explain that, with handoffs to those tools, in place of our
70+
# options/shortcuts.
71+
infobar = Gtk.InfoBar()
72+
infobar.set_message_type(Gtk.MessageType.INFO)
73+
label = Gtk.Label(
74+
_("In Fcitx mode, input methods, additional layouts and their "
75+
"switching shortcuts are managed by Fcitx. Only the first "
76+
"layout configured here is used.")
77+
)
78+
label.set_line_wrap(True)
79+
label.set_xalign(0.0)
80+
infobar.get_content_area().add(label)
81+
82+
manage_button = Gtk.Button(label=_("Manage Fcitx"))
83+
manage_button.connect("clicked", lambda widget: subprocess.Popen(["fcitx5-configtool"]))
84+
infobar.get_action_area().pack_start(manage_button, False, False, 0)
85+
86+
infobar.show_all()
87+
self.pack_start(infobar, False, False, 0)
88+
self.reorder_child(infobar, 0)
89+
return
90+
6191
section = self.add_section(_("Options"))
6292
widget = GSettingsSwitch(
6393
_("Remember the last layout used for each window"),

files/usr/share/cinnamon/cinnamon-settings/bin/KeybindingTable.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
gi.require_version("Gtk", "3.0")
1313
from gi.repository import Gtk, Gdk, Gio, GObject, GLib
1414

15+
from bin import util
16+
1517
gettext.install("cinnamon", "/usr/share/locale")
1618

1719
# Keybindings page - check if we need to store custom
@@ -591,6 +593,10 @@ def _load_category(cat):
591593
category.add(kb)
592594

593595
for category in STATIC_KEYBINDINGS:
596+
# The "Keyboard" category is just the layout-switch shortcuts; under
597+
# fcitx, switching is owned by fcitx, so hide the whole category.
598+
if category[1] == "keyboard" and util.using_fcitx():
599+
continue
594600
_load_category(category)
595601

596602
def _on_enabled_spices_changed(self, settings, key, data=None):

files/usr/share/cinnamon/cinnamon-settings/bin/util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,9 @@ def get_session_type():
4747
pass
4848

4949
return None
50+
51+
def using_fcitx():
52+
# Mirror js/misc/imFramework.js: only an explicit fcitx selection (exported by
53+
# im-config at session start) changes our behaviour; everything else is ibus.
54+
mod = (os.environ.get("GTK_IM_MODULE") or os.environ.get("XMODIFIERS") or "").lower()
55+
return "fcitx" in mod

js/ui/keyboardManager.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const Signals = imports.signals;
77
const ByteArray = imports.byteArray;
88

99
const IBusManager = imports.misc.ibusManager;
10+
const IMFramework = imports.misc.imFramework;
1011
const LoginManager = imports.misc.loginManager;
1112
const Main = imports.ui.main;
1213
const PopupMenu = imports.ui.popupMenu;
@@ -165,6 +166,13 @@ var KeyboardManager = class {
165166
}
166167

167168
_buildGroupStrings(_group) {
169+
if (IMFramework.getFramework() === IMFramework.FRAMEWORK_FCITX) {
170+
// Under fcitx, Cinnamon owns only the base layout; fcitx manages any
171+
// alternate layouts itself (in-process). Send a single-group keymap.
172+
let base = _group[0] || this._localeLayoutInfo;
173+
return [base.layout, base.variant];
174+
}
175+
168176
let alreadyIncluded = _group.some(g => g.layout === this._localeLayoutInfo.layout &&
169177
g.variant === this._localeLayoutInfo.variant);
170178
let group = alreadyIncluded ? _group : _group.concat(this._localeLayoutInfo);
@@ -550,6 +558,10 @@ var InputSourceManager = class {
550558
}
551559

552560
_setupKeybindings() {
561+
// Under fcitx, layout/IME switching is owned by fcitx's own shortcuts.
562+
if (IMFramework.getFramework() === IMFramework.FRAMEWORK_FCITX)
563+
return;
564+
553565
let kb = this._kb_settings.get_strv("switch-input-source");
554566
Main.keybindingManager.addHotKeyArray(
555567
"switch-input-source", kb,

0 commit comments

Comments
 (0)