简体   繁体   English

当input_passthrough为true时,awesome-wm wibox无法响应鼠标信号

[英]awesome-wm wibox not reacting to mouse signals when input_passthrough is true

Basically, what I'm trying to do is have a sidebar, and have it show up when I move my mouse to the left edge of the screen, and have the sidebar disappear when I move my mouse TOO MUCH away from the sidebar. 基本上,我想做的是有一个侧边栏,当我将鼠标移到屏幕的左边缘时会显示它,而当我将鼠标移离侧边栏太多时,侧边栏会消失。

So I made three widgets: 因此,我制作了三个小部件:

  • one that's one pixel wide on the side and that, when it detects the mouse entering, shows the sidebar 一个边宽为一个像素的像素,当它检测到鼠标进入时,显示侧边栏

  • the actual sidebar 实际的侧边栏

  • and a widget that's wider than the sidebar, is fully transparent, has input_passthrough set to true , and its only purpose is to look for the "mouse::leave" signal and when the mouse leaves, it would make itself and the sidebar disappear. 一个比边栏宽的小部件是完全透明的,并且将input_passthrough设置为true ,其唯一目的是寻找“ mouse :: leave”信号,当鼠标离开时,它将使自身和边栏消失。

I got most of it to work but there's this particular error that I can't solve: 我大部分都可以使用,但是有一个我无法解决的特殊错误:

The wibox function takes as argument a table of fields. wibox函数将字段表作为参数。 If you look through the code I provided, you can notice that the input_passthrough field of the sidebar_visible_limit hasn't been put in the body of the table, but supplied afterwards, right after the creation of the widget. 如果仔细阅读我提供的代码,您会注意到sidebar_visible_limitinput_passthrough字段尚未放置在表的主体中,而是在创建小部件之后立即提供的。

The problem with this is that it simply doesn't close the sidebar or itself when the mouse leaves. 问题在于,鼠标离开时,它根本不会关闭侧边栏或自身。 It doesn't detect the mouse leaving. 它不会检测到鼠标离开。

BUT if put the input_passthrough = true in the table provided to the wibox function, like this: 但是如果将input_passthrough = true放在提供给wibox函数的表中,则如下所示:

    bar.sidebar_visible_limit = wibox({ 
    x = 0, 
    y = 0, 
    ontop = false, 
    visible = false,
    width = bar.sidebar.width + dpi(100),
    height = bar.sidebar.height,
    bg = '#000000',
    opacity = 0.3, -- when it's all done this will be '0'
    input_passthrough = true
    })

then everything works fine, EXCEPT that now it doesn't allow input to pass through. 然后一切正常,除了现在不允许输入通过。

I would greatly appreciate an explanation as to why this happens. 我非常感谢您解释为什么会发生这种情况。

This is the code: 这是代码:

awful = require("awful")
local wibox = require("wibox")
local naughty = require("naughty")
local gears = require("gears")
local beautiful = require("beautiful")
xresources = require("beautiful.xresources")
dpi = xresources.apply_dpi

bar = {}

-- make the sidebar
bar.sidebar = wibox({ 
    x = 0, 
    y = 0,  
    ontop = false, 
    visible = false,
    width = beautiful.sidebar_width or dpi(450),
    bg = beautiful.sidebar_bg or "#2f2e3a",
    type = "dock",
    height = beautiful.sidebar_height or awful.screen.focused().geometry.height,
})

-- Hide sidebar when mouse leaves too much from the sidebar
-- It's incorporated along in the same table with the sidebar so the users
-- can implement these however they want, e.g. in the 'keys.lua' module

bar.sidebar_visible_limit = wibox({ 
    x = 0, 
    y = 0, 
    ontop = false, 
    visible = false,
    width = bar.sidebar.width + dpi(100),
    height = bar.sidebar.height,
    bg = '#000000',
    opacity = 0.3, --when it's all done this will be '0'
    })
bar.sidebar_visible_limit.input_passthrough = true

-- Show sidebar when mouse touches edge
local sidebar_displayer = wibox({ 
    x = 0,
    y = 0, 
    height = bar.sidebar.height,
    ontop = true,
    width = 1,
    visible = true, 
    opacity = 0,
    input_passthrough = true
})

function toggle_bar()

    -- they have to be in this order, so the sidebar will show first,
    -- and then the wibox that will close the sidebar when the mouse leaves
    -- second. If you do it the other way around, then if you go with the
    -- mouse on the sidebar-closing wibox , then if you try to go back 
    -- to the sidebar, it will close it because it's 'left' the widget.
    -- That's why you have the sidebar-closing wibox on top and allow
    -- input_passthrough for the sidebar-closing wibox

    bar.sidebar.visible = not bar.sidebar.visible
    bar.sidebar.ontop = not bar.sidebar.ontop

    bar.sidebar_visible_limit.visible = not bar.sidebar_visible_limit.visible
    bar.sidebar_visible_limit.ontop = not bar.sidebar_visible_limit.ontop

end

bar.sidebar_visible_limit:connect_signal( "mouse::leave", toggle_bar )
sidebar_displayer:connect_signal( "mouse::enter", toggle_bar )

I would greatly appreciate an explanation as to why this happens. 我非常感谢您解释为什么会发生这种情况。

I think the X11 server reports mouse enter/exit relative to the input region of a window. 我认为X11服务器报告相对于窗口的输入区域的鼠标进入/退出。 With input_passthrough , the input region becomes empty. 使用input_passthrough ,输入区域变为空。 This means that the X11 server will now report the mouse pointer to be inside the window beneath your wibox and not inside of the wibox itself. 这意味着X11服务器现在将报告鼠标指针位于wibox下方的窗口内,而不是wibox本身内。

BUT if put the input_passthrough = true in the table provided to the wibox function then everything works fine, EXCEPT that now it doesn't allow input to pass through. 但是,如果将input_passthrough = true放在提供给wibox函数的表中,则一切正常,除了现在不允许输入通过。

In other words: In this case the input_passthrough property is not set. 换句话说:在这种情况下,未设置input_passthrough属性。 Seems like you found one of the properties that cannot be set this way. 似乎您找到了无法通过这种方式设置的属性之一。 ;-) ;-)


Since I guess you also want some ideas on how you can do what you are trying to do: If you are running a compositing manager ( xcompmgr , compton , ...), you could make a wibox with a completely transparent background. 既然我猜想您也想知道如何做自己想做的事情:如果正在运行合成管理器( xcompmgrcompton ,...),则可以制作一个完全透明背景的wibox。 That way, the X11 server will "think" that the window is there and report input events relative to it, but the wibox will not actually be visible on screen. 这样,X11服务器将“认为”该窗口在那里,并报告与之相关的输入事件,但是wibox实际上不会在屏幕上可见。

(And if you don't have a compositing manager: Make a widget that displays your wallpaper with the proper offset. A hint on how to do this can be found by reading /usr/share/awesome/lib/wibox/drawable.lua , the part that begins with if not capi.awesome.composite_manager_running then and that does something with the wallpaper. Feel free to ask for more details if necessary.) (如果您没有合成管理器,请执行以下操作:创建一个小部件以适当的偏移量显示墙纸。可以通过阅读/usr/share/awesome/lib/wibox/drawable.lua找到有关此操作的提示。 ,该部分以if not capi.awesome.composite_manager_running then开头, if not capi.awesome.composite_manager_running then对墙纸有所作用。如有必要,请询问更多细节。)

You could use a mousegrabber to detect the position of the mouse: 您可以使用mousegrabber来检测鼠标的位置:

bar.sidebar.ontop = true

function show_sidebar()
    bar.sidebar.visible = true
    mousegrabber.run(function(mouse)
        if mouse.x > bar.sidebar.width + dpi(100) then
            hide_sidebar()
            return false
        end
        return true
    end)
end

function hide_sidebar()
    bar.sidebar.visible = false
end

Alternatively, you could use the same mousegrabber to decide when to show the sidebar too: 另外,您也可以使用相同的mousegrabber来决定何时显示侧边栏:

bar.sidebar.ontop = true

function show_sidebar()
    bar.sidebar.visible = true
end

function hide_sidebar()
    bar.sidebar.visible = false
end

mousegrabber.run(function(mouse)
    if bar.sidebar.visible then
        if mouse.x > bar.sidebar.width + dpi(100) then
            hide_sidebar()
        end
    else
        if mouse.x == 1 then
            show_sidebar()
        end
    end
    return true
end)

I think this is nicer than creating an invisible wibox over the whole screen. 我认为这比在整个屏幕上创建不可见的wibox更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM