titlebar: generate mouse_enter and button events for the entire titlebar (and redirect them to the client)
Signed-off-by: Maarten Maathuis <madman2003@gmail.com> Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
566c5e8639
commit
3cf17a9fae
|
@ -50,16 +50,24 @@ function add(c, args)
|
||||||
|
|
||||||
local title = capi.widget({ type = "textbox", name = "title", align = "flex" })
|
local title = capi.widget({ type = "textbox", name = "title", align = "flex" })
|
||||||
title.text = " " .. util.escape(c.name) .. " "
|
title.text = " " .. util.escape(c.name) .. " "
|
||||||
|
|
||||||
|
-- Redirect relevant events to the client the titlebar belongs to
|
||||||
local bts =
|
local bts =
|
||||||
{
|
{
|
||||||
capi.button({ }, 1, function (t) t.client:mouse_move() end),
|
capi.button({ }, 1, function (t) capi.client.focus = t.client t.client:raise() t.client:mouse_move() end),
|
||||||
|
capi.button({ args.modkey }, 1, function (t) t.client:mouse_move() end),
|
||||||
capi.button({ args.modkey }, 3, function (t) t.client:mouse_resize() end)
|
capi.button({ args.modkey }, 3, function (t) t.client:mouse_resize() end)
|
||||||
}
|
}
|
||||||
title:buttons(bts)
|
title:buttons(bts)
|
||||||
|
function title.mouse_enter(s) hooks.user.call('mouse_enter', c) end
|
||||||
|
|
||||||
local appicon = capi.widget({ type = "imagebox", name = "appicon", align = "left" })
|
local appicon = capi.widget({ type = "imagebox", name = "appicon", align = "left" })
|
||||||
appicon.image = c.icon
|
appicon.image = c.icon
|
||||||
|
|
||||||
|
-- Also redirect events for appicon (So the entire titlebar behaves consistently)
|
||||||
|
appicon:buttons(bts)
|
||||||
|
function appicon.mouse_enter(s) hooks.user.call('mouse_enter', c) end
|
||||||
|
|
||||||
if theme.titlebar_close_button == "true" then
|
if theme.titlebar_close_button == "true" then
|
||||||
local closef = widget.button({ name = "closef", align = "right",
|
local closef = widget.button({ name = "closef", align = "right",
|
||||||
image = theme.titlebar_close_button_focus
|
image = theme.titlebar_close_button_focus
|
||||||
|
@ -70,15 +78,18 @@ function add(c, args)
|
||||||
or theme.titlebar_close_button_img_normal
|
or theme.titlebar_close_button_img_normal
|
||||||
or "@AWESOME_ICON_PATH@/titlebar/close.png" })
|
or "@AWESOME_ICON_PATH@/titlebar/close.png" })
|
||||||
|
|
||||||
-- Bind kill button
|
-- Bind kill button, also allow moving and resizing on this widget
|
||||||
local b = capi.button({ }, 1, nil, function (t) t.client:kill() end)
|
local bts =
|
||||||
local bts = closef:buttons()
|
{
|
||||||
bts[#bts + 1] = b
|
capi.button({ }, 1, nil, function (t) t.client:kill() end),
|
||||||
closef:buttons(bts)
|
capi.button({ args.modkey }, 1, function (t) t.client:mouse_move() end),
|
||||||
|
capi.button({ args.modkey }, 3, function (t) t.client:mouse_resize() end)
|
||||||
bts = close:buttons()
|
}
|
||||||
bts[#bts + 1] = b
|
|
||||||
close:buttons(bts)
|
close:buttons(bts)
|
||||||
|
closef:buttons(bts)
|
||||||
|
-- Needed for sloppy focus beheaviour
|
||||||
|
function close.mouse_enter(s) hooks.user.call('mouse_enter', c) end
|
||||||
|
function closef.mouse_enter(s) hooks.user.call('mouse_enter', c) end
|
||||||
|
|
||||||
tb.widgets = { appicon, title, closef, close }
|
tb.widgets = { appicon, title, closef, close }
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue