bakkeby / dmenu-flexipatch

A dmenu build with preprocessor directives to decide which patches to include during build time
MIT License
183 stars 78 forks source link

input method patch #22

Closed duarm closed 1 month ago

duarm commented 1 year ago

A new INPUTMETHOD_PATCH for dmenu to support input method (fctix, ibus). I've been using this for a while with fcitx and it's stable. The implementation is completely borrowed from xprompt.

Peek 2023-04-21 17-02

the preview feature is not implemented, the text is just copied once you commit. Also not sure if all patches compile, I've just made sure it worked with the ones I'm using, hence a draft.

bakkeby commented 1 month ago

For what it is worth I added an implementation of this on a branch inputmethod for now. Will likely need some testing.

I was able to put most of the patch in a separate file patch/inputmethod.c which reduces the footprint in dmenu.c, which should make it easier to maintain.

duarm commented 1 month ago

Thanks, I'm not expecting this to be merged, feel free to close anytime.I needed an input method of dmenu and shared in hopes it might be useful to someone else.

The only problem I could find with this patch is the one I mentioned in the review. I need to grab the focus in order for the input method to work, which is a deal breaker for me. Couldn't find a way to avoid that.

bakkeby commented 1 month ago

I can see if there is a way around that focus issue.

I don't have any practical experience with fctix, could you perhaps give me a quick run-through of how you set this up and/or use it?

duarm commented 1 month ago

You can use either Fcitx or Ibus, I'm using Fcitx, assuming arch linux

You need an input method framework, which is fcitx5 on arch, and an input method for your desired language, mozc for japanese, on arch fcitx5-mozc. You might also install fcitx5-configtool, an UI for configuring fcitx, provides the fcitx5-config-qt binary. Open the UI, enable Mozc (image below)

image

You can then switch between those within "Current Input Method" via a hotkey or by clicking fcitx in the task bar. It'll only work if there's an application listening for the switch event, so if you're trying to switch in an application which does not support input method, it will do nothing, most QT/GTK apps support it. If it doesn't work, try these env variables

# Input method
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export QT4_IM_MODULE=fcitx
export QT5_IM_MODULE=fcitx
export GLFW_IM_MODULE=fcitx
export SDL_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx
bakkeby commented 1 month ago

Hi @duarm,

alright got fcitx and ibus working in the end.

I didn't really understand the significance of the grabfocus(); call before the while loop in the run function, so I had omitted that initially.

Normally dmenu doesn't allow you to use external keybindings, but it seems that when we intentionally call this function to grab focus for the dmenu window something happens to allow the keybinding from fcitx to trigger.

I didn't run into the issue you mentioned about focus loss when closing dmenu, maybe you have a special way to replicate that, but most likely it is just that I have some special focus handling logic in my window manager.

In any case I added an additional call to give input focus back to the root window which I think in principle should trigger the X server to give focus back to the previous window. May not be though.

Let me know if you have time to test the changes on the branch.

duarm commented 1 month ago

Did a quick test and the window doesnt seem to lose focus anymore. It think it's a GTK or QT problem, but I tested some GTK and QT apps, and opening dmenu leaves the program in a weird state, you can still type after closing dmenu, but you can't submit. This happens on stock dmenu too, so it's not relevant for this PR.

QT6 qutebrowser, happens on GTK too 2024-07-17_20:09:25

Thanks for fixing it.

bakkeby commented 1 month ago

That is an odd symptom. I wasn't able to replicate that myself.

In any case I think the patch is good enough to be merged in. Did you have any plans for a standalone patch for dmenu? I was thinking of how users may find more information about this patch. I suppose I could just refer to this pull request.

duarm commented 1 month ago

I'm not planning a standalone dmenu patch, but I might do it when I have some time, I'll let you know. You can close this and merge your branch. Thanks

bakkeby commented 1 month ago

Very good, I'll mark this PR as closed now. Sorry for the long delay.