【发布时间】:2019-07-13 05:06:36
【问题描述】:
基本上,我想要做的是有一个侧边栏,当我将鼠标移动到屏幕的左边缘时它会显示出来,当我将鼠标移得太远时侧边栏会消失侧边栏。
所以我做了三个小部件:
侧面宽度为 1 像素,并且在检测到鼠标进入时显示侧边栏
实际的侧边栏
还有一个比侧边栏更宽的小部件,完全透明,将
input_passthrough设置为true,它的唯一目的是寻找“mouse::leave”信号以及鼠标何时离开,它会让自己和侧边栏消失。
我已经完成了大部分工作,但有一个我无法解决的特殊错误:
wibox 函数将字段表作为参数。如果您查看我提供的代码,您会注意到sidebar_visible_limit 的input_passthrough 字段没有放在表的主体中,而是在创建小部件之后提供的。
这样做的问题是当鼠标离开时它根本不会关闭侧边栏或自身。它没有检测到鼠标离开。
但是如果将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
})
然后一切正常,除了现在它不允许输入通过。
我非常感谢您解释为什么会发生这种情况。
这是代码:
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 )
【问题讨论】:
标签: awesome-wm