Awesome: screen keyboard : how to prevent gaining focus with mouse/touchscreen

Created on 2 May 2018  Â·  4Comments  Â·  Source: awesomeWM/awesome

Output of awesome --version:

awesome v4.2 (Human after all)
• Compiled against Lua 5.3.3 (running with Lua 5.3)
• D-Bus support: ✔
• execinfo support: ✔
• xcb-randr version: 1.6
• LGI version: 0.9.2

How to reproduce the issue:

Install any on screen keyboard, I use cellwriter, but you can try with xvkbd, onboard, ... it is not specific

Actual result:

My laptop can be turned into a tablet (touchscreen), so I would love to benefit from an on screen keyboard. Nevertheless, each time I press a key, with the mouse or touchscreen, the keyboard steals the focus from the application in which I want to write, and subsequent key press do not work anymore until I touch the application itself.

Expected result:

I know there are many ways to prevent the keyboard from stealing the focus at startup for example.

I would need to prevent the keyboard (or any app) from gaining the focus when I do a mouse click on it or when I tap on it through the touchscreen.

Can it be achieved ?

Most helpful comment

Oh, right. I forgot about that "part of magic".

Then let's try something else. Instead of marking the client as unfocusable, let's mess with the part that focuses the client when clicking on it (with mouse button 1, i.e. left mouse button).
In your rc.lua, find the following:

clientbuttons = gears.table.join(
    awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
    awful.button({ modkey }, 1, awful.mouse.client.move),
    awful.button({ modkey }, 3, awful.mouse.client.resize))

Replace this with

clientbuttons = gears.table.join(
    awful.button({ }, 1, function (c)
        if c.name ~= "CellWriter" then
            client.focus = c
            c:raise()
        end
    end),
    awful.button({ modkey }, 1, awful.mouse.client.move),
    awful.button({ modkey }, 3, awful.mouse.client.resize))

All 4 comments

Create an awful.rules-rule which sets focusable = false for your on-screen keyboard.

To find the right properties, run xprop WM_CLASS in a terminal and click on the window of your on-screen keyboard. I don't have a keyboard, so I tried this with my terminal. The result is WM_CLASS(STRING) = "urxvt256c", "URxvt". Now I could write a rule like { rule = { class = "URxvt" }, properties = { focusable = false } } to make my terminal unfocusable (which is a bad idea to do to a terminal...).
(matching on urxvt256c would be instance = "urxvt256c", i.e. the first string is the instance and the second the class)

Edit: https://www.reddit.com/r/awesomewm/comments/8fs141/on_screen_keyboard_for_awesomewm_need_help/

Hi,

Thanks for your fast answeer.

This is what I did :

{ rule = { name = "CellWriter" }, properties = { focusable = false } }

according to xprop output :

WM_STATE(WM_STATE):
        window state: Normal
        icon window: 0x0
_NET_FRAME_EXTENTS(CARDINAL) = 2, 2, 68, 2
_NET_WM_DESKTOP(CARDINAL) = 3
_NET_WM_STATE(ATOM) = _NET_WM_STATE_STICKY, _NET_WM_STATE_SKIP_TASKBAR, _NET_WM_STATE_ABOVE
WM_HINTS(WM_HINTS):
        Client accepts input or input focus: False
        Initial state is Normal State.
        window id # of group leader: 0x1200001
_NET_WM_SYNC_REQUEST_COUNTER(CARDINAL) = 18874409
_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_UTILITY
_NET_WM_USER_TIME(CARDINAL) = 8311004
_NET_WM_USER_TIME_WINDOW(WINDOW): window id # 0x1200028
WM_CLIENT_LEADER(WINDOW): window id # 0x1200001
_NET_WM_PID(CARDINAL) = 16056
WM_LOCALE_NAME(STRING) = "fr_FR.UTF-8"
WM_CLIENT_MACHINE(STRING) = "paquerette"
WM_NORMAL_HINTS(WM_SIZE_HINTS):
        program specified location: 0, 0
        program specified minimum size: 902 by 176
        program specified maximum size: 902 by 176
        window gravity: NorthWest
WM_PROTOCOLS(ATOM): protocols  WM_DELETE_WINDOW, WM_TAKE_FOCUS, _NET_WM_PING, _NET_WM_SYNC_REQUEST
WM_CLASS(STRING) = "cellwriter", "Cellwriter"
WM_ICON_NAME(STRING) = "CellWriter"
_NET_WM_ICON_NAME(UTF8_STRING) = "CellWriter"
WM_NAME(STRING) = "CellWriter"
_NET_WM_NAME(UTF8_STRING) = "CellWriter"

When I launch the keyboard, it is not focused, it remains unfocused if I move the mouse on it.
But it continues to take the focus as soon as I click on it.

This is probably necessary, as for your terminal, otherwise I could not type on the keyboard.
But then I need to click back to the other app (say a terminal), otherwise subsequents key press on the keyboard have not effect.

To sum up, the virtual keyboard is unusable as soon as it gets focus. To be able to work, it should give back the focus as soon as a key press is released.

Is there a way to do that ?

Oh, right. I forgot about that "part of magic".

Then let's try something else. Instead of marking the client as unfocusable, let's mess with the part that focuses the client when clicking on it (with mouse button 1, i.e. left mouse button).
In your rc.lua, find the following:

clientbuttons = gears.table.join(
    awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
    awful.button({ modkey }, 1, awful.mouse.client.move),
    awful.button({ modkey }, 3, awful.mouse.client.resize))

Replace this with

clientbuttons = gears.table.join(
    awful.button({ }, 1, function (c)
        if c.name ~= "CellWriter" then
            client.focus = c
            c:raise()
        end
    end),
    awful.button({ modkey }, 1, awful.mouse.client.move),
    awful.button({ modkey }, 3, awful.mouse.client.resize))

It does the job,

Many thanks !

Was this page helpful?
0 / 5 - 0 ratings