Skip to content

Commit 1e00e3e

Browse files
committed
V8: Add functionality to modify IBus Background picture; Font set Bug Fix
During [fixing Unity8-Wood theme and add support for IBus Backgound](openSUSE/mentoring#158 (comment)), I found that if I add the following style for class `.candidate-popup-content`: ```css background: url("assets/bg.png"); background-repeat:no-repeat; background-size:cover; ``` I can modify the background picture. Further combining [ibus-font-setting](https://extensions.gnome.org/extension/1121/ibus-font-setting/) and [background-logo](https://pagure.io/background-logo-extension), referring to GNOME-Shell's source code, I found the [corresponding widget](https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/master/js/ui/ibusCandidatePopup.js#L154) for class `candidate-popup-content`, and modified the style to realize modifying IBus background picture without restarting GNOME-Shell. Signed-off-by: Hollow Man <hollowman@hollowman.ml>
1 parent 9e78b74 commit 1e00e3e

12 files changed

Lines changed: 221 additions & 42 deletions

File tree

README.md

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
(English version is down below)
1919

20-
在GNOME Shell中更改IBus的候选框方向、主题、字体和输入法默认语言。
20+
在GNOME Shell中更改IBus的候选框方向、shell主题、背景图片、字体和输入法默认语言。
2121

2222
![demo](img/demo.png)
2323

@@ -44,28 +44,44 @@ cd Customize-IBus && make install
4444

4545
### *提示:*
4646
1. 推荐使用X11。如果你在Wayland中更改IBus主题,你的当前所有工作都将会丢失,因为Wayland下只支持通过重新登陆来重启GNOME-shell。
47-
2. 在Fedora和Ubuntu,GNOME-shell [3.38](../../tree/3.38)(v3,v5),40.0(v4,v6)中通过了测试。
48-
3. 对于那些不使用GNOME而是使用如KDE等桌面环境的用户,更改IBus主题最简单的方法请参见[这里](https://github.com/qvshuo/Ibus-custom-theme),从而为IBus指定一个不同的GTK主题。
47+
2. 在Fedora和Ubuntu,GNOME-shell [3.38](../../tree/3.38)(v3,v5,v7),40.0(v4,v6,v8)中通过了测试。
48+
3. 对于那些不使用GNOME而是使用如KDE等桌面环境的用户,更改IBus主题最简单的方法请参见[这里](https://github.com/qvshuo/Ibus-custom-theme),从而为IBus指定一个不同的GTK主题。
49+
50+
## 更改IBus背景图片的实现
51+
52+
[修复Unity8-Wood主题对IBus背景支持](https://github.com/openSUSE/mentoring/issues/158#issuecomment-813837436)时发现为`.candidate-popup-content`增加如下样式:
53+
54+
```css
55+
background: url("assets/bg.png");
56+
background-repeat:no-repeat;
57+
background-size:cover;
58+
```
59+
60+
即可实现对背景的修改。
61+
62+
进一步结合[ibus-font-setting](https://extensions.gnome.org/extension/1121/ibus-font-setting/)和[background-logo](https://pagure.io/background-logo-extension),参考GNOME-Shell源代码中`candidate-popup-content`样式[对应组件](https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/master/js/ui/ibusCandidatePopup.js#L154),并对其修改样式实现不重启GNOME-Shell进行IBus背景图片的修改。
4963

5064
## 备忘
5165

5266
- [X] 从[ibus-tweaker](https://github.com/tuberry/ibus-tweaker)中导入,去除与IBus无关功能。
5367
- [X] 从用户主题中读取IBus相关样式
5468
- [X] 将相关功能合并在一起。
5569
- [X] V4: 从GTK3升级到GTK4来适配GNOME40。
70+
- [X] V8: 增加更改IBus背景图片功能。
5671

5772
## 致谢
5873

5974
1. [ibus-font-setting](https://extensions.gnome.org/extension/1121/ibus-font-setting/)
6075
2. [ibus-tweaker](https://github.com/tuberry/ibus-tweaker)
6176
3. [user-theme](https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/tree/master/extensions/user-theme)
6277
4. [shell-restarter](https://github.com/koolskateguy89/gnome-shell-extension-shell-restarter)
78+
5. [background-logo](https://pagure.io/background-logo-extension)
6379

6480
*该项目是谷歌编程之夏 (GSoC) 2021于[OpenSUSE](https://github.com/openSUSE/mentoring/issues/158)社区成果的一部分。*
6581

6682
# Customize IBus
6783

68-
Customize IBus in GNOME Shell for orientation, theme, font and input mode auto-switch.
84+
Customize IBus for orientation, shell theme, background picture, font and ascii mode auto-switch.
6985

7086
![demo](img/demo-en.png)
7187

@@ -92,19 +108,35 @@ When user chooses a theme from the list, this extension will first read the them
92108
2. Tested on Fedora and Ubuntu, GNOME-shell [3.38](../../tree/3.38)(v3, v5), 40.0(v4, v6).
93109
3. For users who don't use GNOME but other desktop environments like KDE, the easiest way to change the IBus theme is to act as described in [here](https://github.com/qvshuo/Ibus-custom-theme) to use a different GTK theme for IBus.
94110

111+
## Realization of Modifying IBus Background Picture
112+
113+
During [fixing Unity8-Wood theme and add support for IBus Backgound](https://github.com/openSUSE/mentoring/issues/158#issuecomment-813837436), I found that if I add the following style for class `.candidate-popup-content`:
114+
115+
```css
116+
background: url("assets/bg.png");
117+
background-repeat:no-repeat;
118+
background-size:cover;
119+
```
120+
121+
I can modify the background picture.
122+
123+
Further combining [ibus-font-setting](https://extensions.gnome.org/extension/1121/ibus-font-setting/) and [background-logo](https://pagure.io/background-logo-extension), referring to GNOME-Shell's source code, I found the [corresponding widget](https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/master/js/ui/ibusCandidatePopup.js#L154) for class `candidate-popup-content`, and modified the style to realize modifying IBus background picture without restarting GNOME-Shell.
124+
95125
## To-do
96126

97127
- [X] Import from [ibus-tweaker](https://github.com/tuberry/ibus-tweaker) and remove features unrelated to IBus.
98128
- [X] Read from user themes and apply only for ibus.
99129
- [X] Merge functions related together.
100130
- [X] V4: Update from GTK3 to GTK4 to adapt for GNOME40.
131+
- [X] V8: Add functionality to modify IBus Background picture.
101132

102133
## Acknowledgements
103134

104135
1. [ibus-font-setting](https://extensions.gnome.org/extension/1121/ibus-font-setting/)
105136
2. [ibus-tweaker](https://github.com/tuberry/ibus-tweaker)
106137
3. [user-theme](https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/tree/master/extensions/user-theme)
107138
4. [shell-restarter](https://github.com/koolskateguy89/gnome-shell-extension-shell-restarter)
139+
5. [background-logo](https://pagure.io/background-logo-extension)
108140

109141
*This project is part of the achievement of the Google Summer of Code 2021 at [OpenSUSE](https://github.com/openSUSE/mentoring/issues/158).*
110142

customize-ibus@hollowman.ml/extension.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,42 @@ const IBusFontSetting = GObject.registerClass(
192192
}
193193
);
194194

195+
const IBusBGSetting = GObject.registerClass(
196+
{
197+
Properties: {
198+
background: GObject.param_spec_string(
199+
"bg",
200+
"bg",
201+
"background",
202+
"",
203+
GObject.ParamFlags.WRITABLE
204+
),
205+
},
206+
},
207+
class IBusBGSetting extends GObject.Object {
208+
_init() {
209+
super._init();
210+
gsettings.bind(Fields.CUSTOMBG, this, "bg", Gio.SettingsBindFlags.GET);
211+
}
212+
213+
set bg(bg) {
214+
global.log(_("loading background for IBus:") + bg);
215+
let candidateBox = CandidatePopup.bin.get_children();
216+
if (candidateBox)
217+
candidateBox[0].set_style(
218+
'background: url("%s"); background-repeat:no-repeat; background-size:cover;'.format(
219+
bg
220+
)
221+
);
222+
}
223+
224+
destroy() {
225+
let candidateBox = CandidatePopup.bin.get_children();
226+
if (candidateBox) candidateBox[0].set_style("");
227+
}
228+
}
229+
);
230+
195231
const IBusOrientation = GObject.registerClass(
196232
{
197233
Properties: {
@@ -577,6 +613,13 @@ const Extensions = GObject.registerClass(
577613
false,
578614
GObject.ParamFlags.WRITABLE
579615
),
616+
bg: GObject.param_spec_boolean(
617+
"bg",
618+
"bg",
619+
"bg",
620+
false,
621+
GObject.ParamFlags.WRITABLE
622+
),
580623
input: GObject.param_spec_boolean(
581624
"input",
582625
"input",
@@ -626,6 +669,7 @@ const Extensions = GObject.registerClass(
626669
"font",
627670
Gio.SettingsBindFlags.GET
628671
);
672+
gsettings.bind(Fields.USECUSTOMBG, this, "bg", Gio.SettingsBindFlags.GET);
629673
gsettings.bind(
630674
Fields.ENABLEORIEN,
631675
this,
@@ -668,6 +712,17 @@ const Extensions = GObject.registerClass(
668712
}
669713
}
670714

715+
set bg(bg) {
716+
if (bg) {
717+
if (this._bg) return;
718+
this._bg = new IBusBGSetting();
719+
} else {
720+
if (!this._bg) return;
721+
this._bg.destroy();
722+
delete this._bg;
723+
}
724+
}
725+
671726
set orien(orien) {
672727
if (orien) {
673728
if (this._orien) return;
@@ -702,6 +757,7 @@ const Extensions = GObject.registerClass(
702757
}
703758

704759
destroy() {
760+
this.bg = false;
705761
this.font = false;
706762
this.input = false;
707763
this.orien = false;

customize-ibus@hollowman.ml/locale/customize-ibus.pot

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#, fuzzy
77
msgid ""
88
msgstr ""
9-
"Project-Id-Version: Customize Ibus 6\n"
9+
"Project-Id-Version: Customize Ibus 8\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2021-04-05 16:45+0800\n"
11+
"POT-Creation-Date: 2021-04-06 22:05+0800\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -17,58 +17,74 @@ msgstr ""
1717
"Content-Type: text/plain; charset=CHARSET\n"
1818
"Content-Transfer-Encoding: 8bit\n"
1919

20-
#: extension.js:288
20+
#: extension.js:214
21+
msgid "loading background for IBus:"
22+
msgstr ""
23+
24+
#: extension.js:324
2125
msgid "loading user theme for IBus:"
2226
msgstr ""
2327

24-
#: extension.js:374
28+
#: extension.js:410
2529
msgid "loading default theme for IBus"
2630
msgstr ""
2731

28-
#: extension.js:423
32+
#: extension.js:459
2933
msgid "Restarting..."
3034
msgstr ""
3135

32-
#: prefs.js:78
36+
#: prefs.js:80
3337
msgid "Custom IME theme"
3438
msgstr ""
3539

36-
#: prefs.js:79
40+
#: prefs.js:81
3741
msgid "Use custom font"
3842
msgstr ""
3943

40-
#: prefs.js:80
44+
#: prefs.js:82
45+
msgid "Use custom background"
46+
msgstr ""
47+
48+
#: prefs.js:83
4149
msgid "Auto switch ASCII mode"
4250
msgstr ""
4351

44-
#: prefs.js:81
52+
#: prefs.js:84
4553
msgid "Candidates orientation"
4654
msgstr ""
4755

48-
#: prefs.js:84
56+
#: prefs.js:87
4957
msgid "Vertical"
5058
msgstr ""
5159

52-
#: prefs.js:85
60+
#: prefs.js:88
5361
msgid "Horizontal"
5462
msgstr ""
5563

56-
#: prefs.js:88
64+
#: prefs.js:91
5765
msgid "On"
5866
msgstr ""
5967

60-
#: prefs.js:89
68+
#: prefs.js:92
6169
msgid "Off"
6270
msgstr ""
6371

64-
#: prefs.js:90
72+
#: prefs.js:93
6573
msgid "Default"
6674
msgstr ""
6775

68-
#: prefs.js:123
76+
#: prefs.js:101
77+
msgid "Select an Image"
78+
msgstr ""
79+
80+
#: prefs.js:111
81+
msgid "(None)"
82+
msgstr ""
83+
84+
#: prefs.js:155
6985
msgid "Customize IBus"
7086
msgstr ""
7187

72-
#: prefs.js:359
88+
#: prefs.js:410
7389
msgid "Follow User Theme"
7490
msgstr ""

customize-ibus@hollowman.ml/locale/zh_CN/LC_MESSAGES/customize-ibus.po

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: customize-ibus 1\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2021-04-05 16:45+0800\n"
11+
"POT-Creation-Date: 2021-04-06 22:02+0800\n"
1212
"PO-Revision-Date: 2021-03-27 16:22+0800\n"
1313
"Last-Translator: Hollow Man <hollowman@hollowman.ml>\n"
1414
"Language-Team: Chinese (simplified) <i18n-zh@googlegroups.com>\n"
@@ -17,58 +17,74 @@ msgstr ""
1717
"Content-Type: text/plain; charset=UTF-8\n"
1818
"Content-Transfer-Encoding: 8bit\n"
1919

20-
#: extension.js:288
20+
#: extension.js:214
21+
msgid "loading background for IBus:"
22+
msgstr "正在为IBus加载背景:"
23+
24+
#: extension.js:324
2125
msgid "loading user theme for IBus:"
2226
msgstr "正在为IBus加载用户主题:"
2327

24-
#: extension.js:374
28+
#: extension.js:410
2529
msgid "loading default theme for IBus"
2630
msgstr "正在为IBus加载当前系统主题"
2731

28-
#: extension.js:423
32+
#: extension.js:459
2933
msgid "Restarting..."
3034
msgstr "正在重新启动⋯⋯"
3135

32-
#: prefs.js:78
36+
#: prefs.js:80
3337
msgid "Custom IME theme"
3438
msgstr "自定义主题"
3539

36-
#: prefs.js:79
40+
#: prefs.js:81
3741
msgid "Use custom font"
3842
msgstr "自定义字体"
3943

40-
#: prefs.js:80
44+
#: prefs.js:82
45+
msgid "Use custom background"
46+
msgstr "自定义背景"
47+
48+
#: prefs.js:83
4149
msgid "Auto switch ASCII mode"
4250
msgstr "默认中英文"
4351

44-
#: prefs.js:81
52+
#: prefs.js:84
4553
msgid "Candidates orientation"
4654
msgstr "候选框方向"
4755

48-
#: prefs.js:84
56+
#: prefs.js:87
4957
msgid "Vertical"
5058
msgstr "竖直"
5159

52-
#: prefs.js:85
60+
#: prefs.js:88
5361
msgid "Horizontal"
5462
msgstr "水平"
5563

56-
#: prefs.js:88
64+
#: prefs.js:91
5765
msgid "On"
5866
msgstr "英文"
5967

60-
#: prefs.js:89
68+
#: prefs.js:92
6169
msgid "Off"
6270
msgstr "中文"
6371

64-
#: prefs.js:90
72+
#: prefs.js:93
6573
msgid "Default"
6674
msgstr "默认"
6775

68-
#: prefs.js:123
76+
#: prefs.js:101
77+
msgid "Select an Image"
78+
msgstr "选择一个图片"
79+
80+
#: prefs.js:111
81+
msgid "(None)"
82+
msgstr "(无)"
83+
84+
#: prefs.js:155
6985
msgid "Customize IBus"
7086
msgstr "自定义IBus"
7187

72-
#: prefs.js:359
88+
#: prefs.js:410
7389
msgid "Follow User Theme"
7490
msgstr "跟随系统主题"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"description": "Customize IBus for orientation, theme, font and ascii mode auto-switch",
2+
"description": "Customize IBus for orientation, shell theme, background picture, font and ascii mode auto-switch",
33
"gettext-domain": "customize-ibus",
44
"name": "Customize IBus",
55
"settings-schema": "org.gnome.shell.extensions.customize-ibus",
@@ -8,5 +8,5 @@
88
"original-authors": ["hollowman@hollowman.ml"],
99
"uuid": "customize-ibus@hollowman.ml",
1010
"extension-id": "customize-ibus",
11-
"version": 6
11+
"version": 8
1212
}

0 commit comments

Comments
 (0)