Skip to content
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

input method #1735

Merged
merged 20 commits into from
Nov 8, 2022
Merged

input method #1735

merged 20 commits into from
Nov 8, 2022

Conversation

duarm
Copy link
Contributor

@duarm duarm commented Oct 27, 2022

input method draft, it works, but it was hacked together since I'm not familiar with rofi's code base, nor an ime expert

demo

We just create an XIM handler with a new dependency xcb-imdkit, and forward each PRESS event to it.
only tested with fcitx5.

  • fix warning
  • window position is slightly off
  • unresponsive typing (because of rofi_set_im_window_pos)
  • first character is delayed

Copy link
Collaborator

@sardemff7 sardemff7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an IM expert, but a few remarks across the board

Looks good from here, with some tweaks it’ll be mergeable in my book

source/xcb.c Outdated Show resolved Hide resolved
source/xcb.c Outdated Show resolved Hide resolved
source/view.c Outdated Show resolved Hide resolved
source/view.c Outdated Show resolved Hide resolved
source/view.c Outdated Show resolved Hide resolved
@duarm
Copy link
Contributor Author

duarm commented Oct 27, 2022

related libgwater PR sardemff7/libgwater#4

@duarm
Copy link
Contributor Author

duarm commented Oct 27, 2022

fixed the event forwarding, we only forward the event if we have a xim server in place (when xcb->ic is created), so typing works without an xim server.

added a disconnection callback too, so if the xim server is down, we properly revert to not forwarding events.

both warnings are related to event type 31 (XCB_SELECTION_NOTIFY), for some reason we receive one as soon as we get to the x11 main loop, and rofi returns a "Failed to convert selection" if the xim server is down, or a "Failed" if the server is up. Not sure why. this isn't affecting anything as far as I know.

XIM server window position is slightly off, the position can be offsetted changing the open_xim_callback spot, not sure how to get the necessary information to reposition it in rofi, may be you can help with this one and the warnings?

@DaveDavenport
Copy link
Collaborator

DaveDavenport commented Oct 27, 2022

I currently do not keep a relative (or absolute) x,y position for widgets (that I can remember). This is something I could look at adding. (never really had a use for that information before).

Ugh, my brain is foggy. I already do this (for the mouse handling). We just need to recurse back to sum up all relative positions.

Do you need position relative to rofi window or absolute position?

There is a widget_get_absolute_xpos/ypos function you can call on state->text that gives you the top left position of the entry box. Adding widget_get_height(state->text) to y offset should allow you to find the bottom of the widget.

@duarm
Copy link
Contributor Author

duarm commented Oct 27, 2022

Do you need position relative to rofi window or absolute position?

not sure, I'm passing the CacheState.mainWindow to the server, we define an offset, the window by default (offset 0,0) appears here
image

on my launcher, it appears here
image

There is a widget_get_absolute_xpos/ypos function you can call on state->text that gives you the top right position of the entry box. Adding widget_get_height(state->text) to y offset should allow you to find the bottom of the widget.

I'll take a look later

@sardemff7
Copy link
Collaborator

As noted in sardemff7/libgwater#4 the xcb_xim_t should be created on the rofi side

@DaveDavenport
Copy link
Collaborator

I wanted to say:

  • top left..

Copy link
Collaborator

@sardemff7 sardemff7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We’re getting closer!

source/xcb.c Outdated Show resolved Hide resolved
source/xcb.c Outdated Show resolved Hide resolved
source/xcb.c Outdated Show resolved Hide resolved
source/xcb.c Outdated Show resolved Hide resolved
@duarm
Copy link
Contributor Author

duarm commented Oct 27, 2022

how can I get the text width? the IM window is already at the correct height for most widgets ([thanks @DaveDavenport), but now I need the current text width so the window follows the text.

@DaveDavenport
Copy link
Collaborator

how can I get the text width? the IM window is already at the correct height for most widgets ([thanks @DaveDavenport), but now I need the current text width so the window follows the text.

That is currently not stored. I will try to add a function that gets the cursor position (I think this is what we want).

@duarm
Copy link
Contributor Author

duarm commented Oct 27, 2022

xim context creation was moved to rofi, a little easier to test now

@duarm
Copy link
Contributor Author

duarm commented Oct 27, 2022

sorry for the next two commits, forgot to unstage the changes

@DaveDavenport
Copy link
Collaborator

I've added a get_cursor_x_pos method to textbox

textbox_get_cursor_x_pos(state->text);

Copy link
Collaborator

@sardemff7 sardemff7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it’s some hard-to-read code (as any code related to input, apparently), I’m good with this version on the plumbing side 🙂

Guess it just need some polishing on the UI side

I’ll let @DaveDavenport handle the rest 😄 (but don’t hesitate to ping again if needed)

@duarm
Copy link
Contributor Author

duarm commented Oct 27, 2022

tried the new get_cursor_x_pos() and everything's almost working, the problem I found is that get_cursor_x_pos() is returning the cached cursor_pos which is calculated on the previous draw, so just placing the update on rofi_view_handle_text() doesn't work, where should I put the window position update?

Peek 2022-10-27 18-42

@duarm
Copy link
Contributor Author

duarm commented Oct 27, 2022

actually I think the expected behaviour is for the window to follow as you type, before commiting the text. Think I can do that through the callbacks, but that will complicate some things, I would need to preview typed text without actually triggering the fuzzy finder, we might want to do that later, on another PR.

@DaveDavenport
Copy link
Collaborator

the new position is available once drawn.. So after 'widget_draw' so in rofi_view_update

@duarm
Copy link
Contributor Author

duarm commented Oct 27, 2022

removed the positioning queue, tested without and had no problems, added a new rofi_set_im_window_pos(x,y)
here's the current behaviour
Peek 2022-10-27 19-05

the kitty one for reference, we might want to do something like that on the future.
Peek 2022-10-27 18-51

@duarm duarm marked this pull request as ready for review October 27, 2022 22:22
@duarm duarm changed the title [WIP] input method input method Oct 27, 2022
@duarm
Copy link
Contributor Author

duarm commented Oct 28, 2022

hello, I won't be able to work on this for a few days, couldn't make the preedit callbacks work, but aside from this small problem, it's quite ready, feel free to finish or just hack for now. The problem is that if you're typing normal character (not composing a character, like with japanese), typing really fast is slightly less responsive because of rofi_set_im_window_pos.
Once I get back I might try again. Thanks for the good work.

@DaveDavenport
Copy link
Collaborator

I noticed that with fcitx running, esp the first character takes very long to appear on my test machine. (i5-6500t, 8gb ddr4, nvme disk, not fast, but not a slow machine either).
This is kinda not-ok, so might make it a compile time flag.

@duarm
Copy link
Contributor Author

duarm commented Oct 29, 2022

This doesn't happen on my machine, are you on fcitx5 (latest version)? also, when you're using an input method, it sometimes messes your autorepeat (xset r rate) when changing between servers, try running xset r rate 300 50 or something like that again and see if that was the problem. If it was, we can't do nothing about it.

@DaveDavenport
Copy link
Collaborator

Installed the fcitx5 (deb) on my pop-os test machine. Its up2date but no idea what version.
But there was a clear 'delay' on the first character on first run.

@DaveDavenport
Copy link
Collaborator

@sardemff7 is that 'changes requested' still open or can this be merged?

@DaveDavenport DaveDavenport merged commit 6d02648 into davatorium:next Nov 8, 2022
@DaveDavenport
Copy link
Collaborator

Users report (and shown) extreme slowdown by this patch making rofi near unusable.
(see the discussion I tagged @duarm in)

I will revert unless we can find a solution.

@duarm
Copy link
Contributor Author

duarm commented Nov 23, 2022

revert this for now, tested yersterday under heavy load and it's quite unusuable indeed. There's something wrong with the event forwarding, sometime the keys are swalloed without the string being commited, only to both be commited once the next event is forwarded. This becomes apparent if the code cant run fast enough, which is caused by the window position being updated every draw as I've noted before, we're paying to much round-trip with the server.

Ideally this shouldn't happen, even under heavy loads, this pr requires some more careful handling with the server (only communicate when necessary, throttling, etc.), I'll try to fix when I get the time again, or someone with more knowledge can step in.

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 25, 2022
@davatorium davatorium unlocked this conversation May 5, 2023
@github-actions
Copy link

github-actions bot commented Jun 6, 2023

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 6, 2023
@davatorium davatorium unlocked this conversation Oct 22, 2023
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 23, 2023
@davatorium davatorium unlocked this conversation Nov 23, 2023
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 25, 2023
@davatorium davatorium unlocked this conversation Dec 25, 2023
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 26, 2024
@davatorium davatorium unlocked this conversation Jan 26, 2024
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants