Skip to content

Commit bfc3ab7

Browse files
committed
Add suggestions to the osk
1 parent 31cbe27 commit bfc3ab7

4 files changed

Lines changed: 82 additions & 2 deletions

File tree

daemon/IBus/IBusCandidateWindow.vala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
public class Gala.Daemon.IBusCandidateWindow : Gtk.Window {
99
public IBus.PanelService service { get; construct; }
1010

11+
public bool disabled { get; set; default = false; }
12+
1113
private Gtk.Label preedit_text;
1214
private Gtk.Label auxiliary_text;
1315
private CandidateArea candidate_area;
@@ -61,7 +63,7 @@ public class Gala.Daemon.IBusCandidateWindow : Gtk.Window {
6163
}
6264

6365
private void update_visibility () {
64-
var is_visible = preedit_text.visible || auxiliary_text.visible || candidate_area.visible;
66+
var is_visible = !disabled && (preedit_text.visible || auxiliary_text.visible || candidate_area.visible);
6567

6668
if (is_visible) {
6769
present ();

daemon/IBus/IBusService.vala

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@
66
*/
77

88
public class Gala.Daemon.IBusService : Object {
9+
private ListStore _candidates;
10+
public ListModel candidates { get { return _candidates; } }
11+
12+
public bool disable_popup { get; set; default = false; }
13+
public IBus.PanelService service { get; private set; }
14+
915
private IBus.Bus bus;
10-
private IBus.PanelService service;
1116
private IBusCandidateWindow candidate_window;
1217

1318
construct {
19+
_candidates = new ListStore (typeof (Candidate));
20+
1421
bus = new IBus.Bus.async ();
1522
bus.connected.connect (on_connected);
1623
}
@@ -33,5 +40,34 @@ public class Gala.Daemon.IBusService : Object {
3340
/* We need to go via Object.new because we need to pass construct properties */
3441
service = (IBus.PanelService) Object.@new (typeof (IBus.PanelService), "connection", bus.get_connection (), "object-path", IBus.PATH_PANEL);
3542
candidate_window = new IBusCandidateWindow (service);
43+
bind_property ("disable-popup", candidate_window, "disabled", SYNC_CREATE);
44+
45+
service.update_lookup_table.connect (on_update_lookup_table);
46+
}
47+
48+
private void on_update_lookup_table (IBus.LookupTable table) {
49+
_candidates.remove_all ();
50+
51+
var n_candidates = table.get_number_of_candidates ();
52+
var page_size = table.get_page_size ();
53+
54+
if (page_size == 0) {
55+
/* I don't think 0 is intended to happen so print a warning */
56+
warning ("LookupTable page size is 0, using 5");
57+
page_size = 5;
58+
}
59+
60+
var cursor_pos = table.get_cursor_pos ();
61+
var page = (uint) (cursor_pos / page_size);
62+
63+
var start_index = page * page_size;
64+
var end_index = uint.min (start_index + page_size, n_candidates);
65+
66+
for (uint i = start_index; i < end_index; i++) {
67+
var label = table.get_label (i)?.text;
68+
var candidate = table.get_candidate (i)?.text;
69+
70+
_candidates.append (new Candidate (label, candidate));
71+
}
3672
}
3773
}

daemon/OSK/Window/Suggestions.vala

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2026 elementary, Inc. (https://elementary.io)
3+
* SPDX-License-Identifier: GPL-3.0-or-later
4+
*
5+
* Authored by: Leonhard Kargl <leo.kargl@proton.me>
6+
*/
7+
8+
public class Gala.Daemon.Suggestions : Granite.Bin {
9+
public IBusService ibus_service { private get; construct; }
10+
11+
public Suggestions (IBusService ibus_service) {
12+
Object (ibus_service: ibus_service);
13+
}
14+
15+
construct {
16+
var selection_model = new Gtk.NoSelection (ibus_service.candidates);
17+
18+
var factory = new Gtk.SignalListItemFactory ();
19+
factory.setup.connect (on_setup);
20+
factory.bind.connect (on_bind);
21+
22+
var list_view = new Gtk.ListView (selection_model, factory) {
23+
orientation = HORIZONTAL,
24+
};
25+
child = list_view;
26+
halign = CENTER;
27+
}
28+
29+
private void on_setup (Object obj) {
30+
var item = (Gtk.ListItem) obj;
31+
item.child = new CandidateBox (ibus_service.service, item);
32+
}
33+
34+
private void on_bind (Object obj) {
35+
var item = (Gtk.ListItem) obj;
36+
var candidate = (Candidate) item.item;
37+
38+
var box = (CandidateBox) item.child;
39+
box.set_candidate (candidate);
40+
}
41+
}

daemon/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ gala_daemon_sources = files(
2020
'OSK' / 'KeyboardModel' / 'KeyboardView.vala',
2121
'OSK' / 'Parsers' / 'GnomeOSKParser.vala',
2222
'OSK' / 'Window' / 'OSKWindow.vala',
23+
'OSK' / 'Window' / 'Suggestions.vala',
2324
'OSK' / 'Window' / 'Keyboard' / 'Keyboard.vala',
2425
'OSK' / 'Window' / 'Keyboard' / 'KeyButton.vala',
2526
'OSK' / 'Window' / 'Keyboard' / 'ViewContainer.vala',

0 commit comments

Comments
 (0)