-
-
Notifications
You must be signed in to change notification settings - Fork 79
Support input methods on wayland and actually via wayland #2793
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
Open
leolost2605
wants to merge
4
commits into
main
Choose a base branch
from
leolost/input-method
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /* | ||
| * Copyright 2026 elementary, Inc. (https://elementary.io) | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| * | ||
| * Authored by: Leonhard Kargl <leo.kargl@proton.me> | ||
| */ | ||
|
|
||
| public class Gala.Daemon.Candidate : Object { | ||
| public string? label { get; construct; } | ||
| public string? candidate { get; construct; } | ||
|
|
||
| public Candidate (string? label, string? candidate) { | ||
| Object (label: label, candidate: candidate); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| /* | ||
| * Copyright 2026 elementary, Inc. (https://elementary.io) | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| * | ||
| * Authored by: Leonhard Kargl <leo.kargl@proton.me> | ||
| */ | ||
|
|
||
| public class Gala.Daemon.CandidateArea : Granite.Bin { | ||
| private const string[] DEFAULT_LABELS = { | ||
| "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "e", "f" | ||
| }; | ||
|
|
||
| public IBus.PanelService service { get; construct; } | ||
|
|
||
| private ListStore model; | ||
| private Gtk.SingleSelection selection_model; | ||
| private Gtk.ListView list_view; | ||
|
|
||
| private Gtk.Button prev_page_button; | ||
| private Gtk.Button next_page_button; | ||
| private Granite.Box button_box; | ||
|
|
||
| private Granite.Box content_box; | ||
|
|
||
| public CandidateArea (IBus.PanelService service) { | ||
| Object (service: service); | ||
| } | ||
|
|
||
| construct { | ||
| model = new ListStore (typeof (Candidate)); | ||
|
|
||
| selection_model = new Gtk.SingleSelection (model); | ||
|
|
||
| var factory = new Gtk.SignalListItemFactory (); | ||
| factory.setup.connect (on_setup); | ||
| factory.bind.connect (on_bind); | ||
|
|
||
| list_view = new Gtk.ListView (selection_model, factory); | ||
|
|
||
| prev_page_button = new Gtk.Button (); | ||
| prev_page_button.clicked.connect (service.page_up); | ||
|
|
||
| next_page_button = new Gtk.Button (); | ||
| next_page_button.clicked.connect (service.page_down); | ||
|
|
||
| button_box = new Granite.Box (HORIZONTAL, LINKED) { | ||
| hexpand = true | ||
| }; | ||
| button_box.append (prev_page_button); | ||
| button_box.append (next_page_button); | ||
|
|
||
| content_box = new Granite.Box (VERTICAL); | ||
| content_box.append (list_view); | ||
| content_box.append (button_box); | ||
|
|
||
| child = content_box; | ||
| } | ||
|
|
||
| private void on_setup (Object obj) { | ||
| var item = (Gtk.ListItem) obj; | ||
| item.child = new CandidateBox (service, item); | ||
| } | ||
|
|
||
| private void on_bind (Object obj) { | ||
| var item = (Gtk.ListItem) obj; | ||
| var candidate = (Candidate) item.item; | ||
|
|
||
| var box = (CandidateBox) item.child; | ||
| box.set_candidate (candidate); | ||
| } | ||
|
|
||
| public void update (IBus.LookupTable table) { | ||
| model.remove_all (); | ||
|
|
||
| if (table.get_orientation () == IBus.Orientation.HORIZONTAL) { | ||
| update_orientation (HORIZONTAL); | ||
| } else { /* VERTICAL or SYSTEM */ | ||
| update_orientation (VERTICAL); | ||
| } | ||
|
|
||
| var n_candidates = table.get_number_of_candidates (); | ||
| var page_size = table.get_page_size (); | ||
|
|
||
| if (page_size == 0) { | ||
| /* I don't think 0 is intended to happen so print a warning */ | ||
| warning ("LookupTable page size is 0, using 5"); | ||
| page_size = 5; | ||
| } | ||
|
|
||
| var cursor_pos = table.get_cursor_pos (); | ||
| var page = (uint) (cursor_pos / page_size); | ||
|
leolost2605 marked this conversation as resolved.
|
||
|
|
||
| var start_index = page * page_size; | ||
| var end_index = uint.min (start_index + page_size, n_candidates); | ||
|
|
||
| for (uint i = start_index; i < end_index; i++) { | ||
| var ibus_label = table.get_label (i)?.text; | ||
| var label = ibus_label != null && ibus_label.strip () != "" ? ibus_label : ( | ||
| i - start_index < DEFAULT_LABELS.length ? DEFAULT_LABELS[i - start_index] : null | ||
| ); | ||
|
|
||
| var candidate = table.get_candidate (i)?.text; | ||
|
|
||
| model.append (new Candidate (label, candidate)); | ||
| } | ||
|
|
||
| selection_model.selected = table.get_cursor_in_page (); | ||
|
|
||
| update_buttons (table.is_round (), page, (uint) ((n_candidates + page_size - 1) / page_size)); | ||
| } | ||
|
|
||
| private void update_orientation (Gtk.Orientation orientation) { | ||
| content_box.orientation = orientation; | ||
| list_view.orientation = orientation; | ||
|
|
||
| if (orientation == HORIZONTAL) { | ||
| prev_page_button.icon_name = "go-previous"; | ||
| next_page_button.icon_name = "go-next"; | ||
| } else { | ||
| prev_page_button.icon_name = "go-up"; | ||
| next_page_button.icon_name = "go-down"; | ||
| } | ||
| } | ||
|
|
||
| private void update_buttons (bool wraps_around, uint page, uint n_pages) { | ||
| button_box.visible = n_pages > 1; | ||
|
|
||
| prev_page_button.sensitive = wraps_around || page > 0; | ||
| next_page_button.sensitive = wraps_around || page < n_pages - 1; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Copyright 2026 elementary, Inc. (https://elementary.io) | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| * | ||
| * Authored by: Leonhard Kargl <leo.kargl@proton.me> | ||
| */ | ||
|
|
||
| public class Gala.Daemon.CandidateBox : Granite.Bin { | ||
| public IBus.PanelService service { get; construct; } | ||
| public unowned Gtk.ListItem list_item { get; construct; } | ||
|
|
||
| private Gtk.Label label_label; | ||
| private Gtk.Label candidate_label; | ||
|
|
||
| public CandidateBox (IBus.PanelService service, Gtk.ListItem list_item) { | ||
| Object (service: service, list_item: list_item); | ||
| } | ||
|
|
||
| construct { | ||
| label_label = new Gtk.Label (null); | ||
| label_label.add_css_class (Granite.CssClass.DIM); | ||
|
|
||
| candidate_label = new Gtk.Label (null); | ||
|
|
||
| var content_box = new Granite.Box (HORIZONTAL, HALF); | ||
| content_box.append (label_label); | ||
| content_box.append (candidate_label); | ||
|
|
||
| child = content_box; | ||
|
|
||
| var gesture_click = new Gtk.GestureClick (); | ||
| gesture_click.released.connect (on_clicked); | ||
| add_controller (gesture_click); | ||
| } | ||
|
|
||
| private void on_clicked (Gtk.GestureClick gesture, int n_press, double x, double y) { | ||
| service.candidate_clicked (list_item.position, gesture.get_current_button (), gesture.get_current_event_state ()); | ||
| } | ||
|
|
||
| public void set_candidate (Candidate candidate) { | ||
| label_label.label = candidate.label; | ||
| candidate_label.label = candidate.candidate; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| /* | ||
| * Copyright 2026 elementary, Inc. (https://elementary.io) | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| * | ||
| * Authored by: Leonhard Kargl <leo.kargl@proton.me> | ||
| */ | ||
|
|
||
| public class Gala.Daemon.IBusCandidateWindow : Gtk.Window { | ||
| public IBus.PanelService service { get; construct; } | ||
|
|
||
| private Gtk.Label preedit_text; | ||
| private Gtk.Label auxiliary_text; | ||
| private CandidateArea candidate_area; | ||
|
|
||
| public IBusCandidateWindow (IBus.PanelService service) { | ||
| Object (service: service); | ||
| } | ||
|
|
||
| construct { | ||
| preedit_text = new Gtk.Label (null) { | ||
| halign = START, | ||
| visible = false, | ||
| }; | ||
|
|
||
| auxiliary_text = new Gtk.Label (null) { | ||
| halign = START, | ||
| visible = false, | ||
| }; | ||
|
|
||
| candidate_area = new CandidateArea (service) { | ||
| hexpand = true, | ||
| visible = false, | ||
| }; | ||
|
|
||
| var content_box = new Granite.Box (VERTICAL) { | ||
| margin_start = 6, | ||
| margin_end = 6, | ||
| margin_top = 6, | ||
| margin_bottom = 6, | ||
| }; | ||
| content_box.append (preedit_text); | ||
| content_box.append (auxiliary_text); | ||
| content_box.append (candidate_area); | ||
|
|
||
| titlebar = new Gtk.Grid () { visible = false }; | ||
| child = content_box; | ||
| /* Used to identify the window for correct positioning in the wm */ | ||
| title = "IBUS_CANDIDATE"; | ||
|
leolost2605 marked this conversation as resolved.
|
||
| resizable = false; | ||
|
|
||
| service.show_preedit_text.connect (on_show_preedit_text); | ||
| service.hide_preedit_text.connect (on_hide_preedit_text); | ||
| service.update_preedit_text.connect (on_update_preedit_text); | ||
| service.show_auxiliary_text.connect (on_show_auxiliary_text); | ||
| service.hide_auxiliary_text.connect (on_hide_auxiliary_text); | ||
| service.update_auxiliary_text.connect (on_update_auxiliary_text); | ||
| service.show_lookup_table.connect (on_show_lookup_table); | ||
| service.hide_lookup_table.connect (on_hide_lookup_table); | ||
| service.update_lookup_table.connect (on_update_lookup_table); | ||
| service.focus_out.connect (hide); | ||
| } | ||
|
|
||
| private void update_visibility () { | ||
| var is_visible = preedit_text.visible || auxiliary_text.visible || candidate_area.visible; | ||
|
|
||
| if (is_visible) { | ||
| present (); | ||
| } else { | ||
| hide (); | ||
| } | ||
| } | ||
|
|
||
| private void on_show_preedit_text () { | ||
| preedit_text.visible = true; | ||
| update_visibility (); | ||
| } | ||
|
|
||
| private void on_hide_preedit_text () { | ||
| preedit_text.visible = false; | ||
| update_visibility (); | ||
| } | ||
|
|
||
| private void on_update_preedit_text (IBus.Text text, uint cursor_pos, bool visible) { | ||
| preedit_text.visible = visible; | ||
| preedit_text.label = text.text; | ||
|
|
||
| update_visibility (); | ||
| } | ||
|
|
||
| private void on_show_auxiliary_text () { | ||
| auxiliary_text.visible = true; | ||
| update_visibility (); | ||
| } | ||
|
|
||
| private void on_hide_auxiliary_text () { | ||
| auxiliary_text.visible = false; | ||
| update_visibility (); | ||
| } | ||
|
|
||
| private void on_update_auxiliary_text (IBus.Text text, bool visible) { | ||
| auxiliary_text.visible = visible; | ||
| auxiliary_text.label = text.text; | ||
|
|
||
| update_visibility (); | ||
| } | ||
|
|
||
| private void on_show_lookup_table () { | ||
| candidate_area.visible = true; | ||
| update_visibility (); | ||
| } | ||
|
|
||
| private void on_hide_lookup_table () { | ||
| candidate_area.visible = false; | ||
| update_visibility (); | ||
| } | ||
|
|
||
| private void on_update_lookup_table (IBus.LookupTable table, bool visible) { | ||
| candidate_area.visible = visible; | ||
| update_visibility (); | ||
|
|
||
| candidate_area.update (table); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * Copyright 2026 elementary, Inc. (https://elementary.io) | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| * | ||
| * Authored by: Leonhard Kargl <leo.kargl@proton.me> | ||
| */ | ||
|
|
||
| public class Gala.Daemon.IBusService : Object { | ||
| private IBus.Bus bus; | ||
| private IBus.PanelService service; | ||
| private IBusCandidateWindow candidate_window; | ||
|
|
||
| construct { | ||
| bus = new IBus.Bus.async (); | ||
| bus.connected.connect (on_connected); | ||
| } | ||
|
|
||
| private void on_connected () { | ||
| bus.request_name_async.begin ( | ||
| IBus.SERVICE_PANEL, IBus.BusNameFlag.REPLACE_EXISTING, -1, null, | ||
| on_name_acquired | ||
| ); | ||
| } | ||
|
|
||
| private void on_name_acquired (Object? obj, AsyncResult res) { | ||
| try { | ||
| bus.request_name_async_finish (res); | ||
| } catch (Error e) { | ||
| warning ("Failed to acquire bus name: %s", e.message); | ||
| return; | ||
| } | ||
|
|
||
| /* We need to go via Object.new because we need to pass construct properties */ | ||
| service = (IBus.PanelService) Object.@new (typeof (IBus.PanelService), "connection", bus.get_connection (), "object-path", IBus.PATH_PANEL); | ||
| candidate_window = new IBusCandidateWindow (service); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.