Add new notification item layout, improve extensions

This commit is contained in:
Emmanuel Lepage Vallee 2014-04-08 23:38:31 -04:00
parent 879a43fbc4
commit 8da00cbd65
9 changed files with 407 additions and 30 deletions

View File

@ -291,6 +291,8 @@ like when a modifier is applied.
| button::release | A button release | menu,item,button_id,mods |
| mouse::enter | When the mouse enter | menu,item |
| mouse::leave | When the mouse leave | menu,item |
| long::hover | The mouse is hover 1.5 sec | menu,item |
| long::press | The mouse is pressed 1.5 sec | menu,item |
`mods` is an array with the applied modifier as **key**. If the value is `nil`,
then the modifier is not present. Usual modifiers are `Control`, `Shift`, `mod1`

View File

@ -274,6 +274,7 @@ local function new(args)
screen = args.screen or nil,
style = args.style or nil,
item_style = args.item_style or require("radical.item.style.basic"),
item_layout = args.item_layout or nil,
filter = args.filter ~= false,
show_filter = args.show_filter or false,
filter_string = args.filter_string or "",

View File

@ -20,8 +20,18 @@ local global = {}
local extension_list = {}
local function read_add(item,w,position)
if position == "suffix" then
item:add_suffix(w)
elseif position == "prefix" then
item:add_prefix(w)
elseif position == "overlay" then
item:add_overlay(w)
end
end
local per_m,per_glob,per_this = nil
local function persistence_menu(ext)
local function persistence_menu(ext,position)
if not taglist then
taglist = require("radical.impl.taglist")
end
@ -30,14 +40,14 @@ local function persistence_menu(ext)
per_glob = per_m:add_item{text= "All clients" ,checkable = true , button1 = function()
local i1 = taglist.item(current_client)
if i1 and (not i1._internal.has_widget or not i1._internal.has_widget[ext]) then
i1:add_suffix(ext(current_client))
read_add(i1,ext(current_client),position)
i1._internal.has_widget = i1._internal.has_widget or {}
i1._internal.has_widget[ext] = true
end
for k,v in ipairs(capi.client.get()) do
local i2 = taglist.item(v)
if i2 and (not i2._internal.has_widget or not i2._internal.has_widget[ext]) then
i2:add_suffix(ext(v))
read_add(i2,ext(v),position)
i2._internal.has_widget = i2._internal.has_widget or {}
i2._internal.has_widget[ext] = true
end
@ -47,7 +57,7 @@ local function persistence_menu(ext)
per_this = per_m:add_item{text= "This client only" ,checkable = true, button1 = function()
local i1 = taglist.item(current_client)
if i1 and (not i1._internal.has_widget or not i1._internal.has_widget[ext]) then
i1:add_suffix(ext(current_client))
read_add(i1,ext(current_client),position)
i1._internal.has_widget = i1._internal.has_widget or {}
i1._internal.has_widget[ext] = true
end
@ -75,11 +85,11 @@ local function persistence_menu(ext)
end
local ext_list_m = nil
local function extension_list_menu()
local function extension_list_menu(position)
if not ext_list_m then
ext_list_m = radical.context{}
for k,v in pairs(extension_list) do
ext_list_m:add_item{text=k,sub_menu=function() return persistence_menu(v) end}
ext_list_m:add_item{text=k,sub_menu=function() return persistence_menu(v,position) end}
end
end
return ext_list_m
@ -90,9 +100,9 @@ function module.extensions_menu(c)
current_client = c
if not ext_m then
ext_m = radical.context{}
ext_m:add_item{text="Overlay widget", sub_menu=extension_list_menu() }
ext_m:add_item{text="Prefix widget" , sub_menu=extension_list_menu() }
ext_m:add_item{text="Suffix widget" , sub_menu=extension_list_menu() }
ext_m:add_item{text="Overlay widget", sub_menu=function() return extension_list_menu( "overlay" ) end }
ext_m:add_item{text="Prefix widget" , sub_menu=function() return extension_list_menu( "prefix" ) end }
ext_m:add_item{text="Suffix widget" , sub_menu=function() return extension_list_menu( "suffix" ) end }
end
return ext_m
end

View File

@ -20,8 +20,19 @@ local global = {}
local extension_list = {}
local function read_add(item,w,position)
if position == "suffix" then
item:add_suffix(w)
elseif position == "prefix" then
item:add_prefix(w)
elseif position == "overlay" then
item:add_overlay(w)
end
end
local per_m,per_glob,per_class,per_this = nil
local function persistence_menu(ext)
local function persistence_menu(ext,position)
local position=position
if not tasklist then
tasklist = require("radical.impl.tasklist")
end
@ -30,14 +41,14 @@ local function persistence_menu(ext)
per_glob = per_m:add_item{text= "All clients" ,checkable = true , button1 = function()
local i1 = tasklist.item(current_client)
if i1 and (not i1._internal.has_widget or not i1._internal.has_widget[ext]) then
i1:add_suffix(ext(current_client))
read_add(i1,ext(current_client),position)
i1._internal.has_widget = i1._internal.has_widget or {}
i1._internal.has_widget[ext] = true
end
for k,v in ipairs(capi.client.get()) do
local i2 = tasklist.item(v)
if i2 and (not i2._internal.has_widget or not i2._internal.has_widget[ext]) then
i2:add_suffix(ext(v))
read_add(i2,ext(v),position)
i2._internal.has_widget = i2._internal.has_widget or {}
i2._internal.has_widget[ext] = true
end
@ -47,7 +58,7 @@ local function persistence_menu(ext)
per_class = per_m:add_item{text= "This class only" ,checkable = true, button1 = function()
local i1 = tasklist.item(current_client)
if i1 and (not i1._internal.has_widget or not i1._internal.has_widget[ext]) then
i1:add_suffix(ext(current_client))
read_add(i1,ext(current_client),position)
i1._internal.has_widget = i1._internal.has_widget or {}
i1._internal.has_widget[ext] = true
end
@ -55,7 +66,7 @@ local function persistence_menu(ext)
if v.class == current_client.class then
local i2 = tasklist.item(v)
if i2 and (not i2._internal.has_widget or not i2._internal.has_widget[ext]) then
i2:add_suffix(ext(v))
read_add(i2,ext(v),position)
i2._internal.has_widget = i2._internal.has_widget or {}
i2._internal.has_widget[ext] = true
end
@ -66,7 +77,7 @@ local function persistence_menu(ext)
per_this = per_m:add_item{text= "This client only" ,checkable = true, button1 = function()
local i1 = tasklist.item(current_client)
if i1 and (not i1._internal.has_widget or not i1._internal.has_widget[ext]) then
i1:add_suffix(ext(current_client))
read_add(i1,ext(current_client),position)
i1._internal.has_widget = i1._internal.has_widget or {}
i1._internal.has_widget[ext] = true
end
@ -98,11 +109,11 @@ local function persistence_menu(ext)
end
local ext_list_m = nil
local function extension_list_menu()
local function extension_list_menu(position)
if not ext_list_m then
ext_list_m = radical.context{}
for k,v in pairs(extension_list) do
ext_list_m:add_item{text=k,sub_menu=function() return persistence_menu(v) end}
ext_list_m:add_item{text=k,sub_menu=function() return persistence_menu(v,position) end}
end
end
return ext_list_m
@ -113,9 +124,9 @@ function module.extensions_menu(c)
current_client = c
if not ext_m then
ext_m = radical.context{}
ext_m:add_item{text="Overlay widget", sub_menu=extension_list_menu() }
ext_m:add_item{text="Prefix widget" , sub_menu=extension_list_menu() }
ext_m:add_item{text="Suffix widget" , sub_menu=extension_list_menu() }
ext_m:add_item{text="Overlay widget", sub_menu=function() return extension_list_menu( "overlay" ) end }
ext_m:add_item{text="Prefix widget" , sub_menu=function() return extension_list_menu( "prefix" ) end }
ext_m:add_item{text="Suffix widget" , sub_menu=function() return extension_list_menu( "suffix" ) end }
end
return ext_m
end

View File

@ -73,6 +73,19 @@ function module.execute_sub_menu(data,item)
end
end
-- local registered_items = {}
-- local is_watching = false
-- local mouse_tracker = object{}
local function watch_mouse(a,b,c)
print("move",a,b,c)
end
-- local function register_mouse_track()
-- if not is_watching then
--
-- end
-- end
local function new_item(data,args)
local args = args or {}
local item,private_data = object({
@ -175,23 +188,32 @@ local function new_item(data,args)
end)
-- Add support for long hover and press
-- local function test()
-- print("test")
-- end
local main_timer,press_timer = nil
item:connect_signal("mouse::enter",function()
if not main_timer then
main_timer = timer{}
main_timer.timeout = 1.5
main_timer:connect_signal("timeout",function()
item:emit_signal("long::hover")
item._internal._is_long_hover = true
item:emit_signal("long::hover",data,item)
main_timer:stop()
end)
end
if not main_timer.started then
-- item:connect_signal("mouse::move",test)
main_timer:start()
end
end)
item:connect_signal("mouse::leave",function()
if main_timer and main_timer.started then
main_timer:stop()
-- item:disconnect_signal("mouse::move",test)
elseif item._internal._is_long_hover then
item._internal._is_long_hover = nil
item:emit_signal("long::exit",data,item)
end
end)
item:connect_signal("button::press",function()
@ -199,11 +221,13 @@ local function new_item(data,args)
press_timer = timer{}
press_timer.timeout = 1.5
press_timer:connect_signal("timeout",function()
item:emit_signal("long::press")
item:emit_signal("long::press",data,item)
-- item:disconnect_signal("mouse::move",test)
press_timer:stop()
end)
end
if not press_timer.started then
-- item:connect_signal("mouse::move",test)
press_timer:start()
end
end)

View File

@ -18,7 +18,7 @@ function module:setup_fkey(item,data)
item._internal.f_key = value
data:remove_key_hook("F"..value)
data:add_key_hook({}, "F"..value , "press", function()
item.button1()
item.button1(data,menu)
data.visible = false
end)
end
@ -119,6 +119,8 @@ function module.setup_event(data,item,widget)
for k,v in ipairs(mod) do
mods_invert[v] = i
end
item.state[4] = true
data:emit_signal("button::press",item,id,mods_invert)
item:emit_signal("button::press",item,id,mods_invert)
end)
@ -127,6 +129,7 @@ function module.setup_event(data,item,widget)
for k,v in ipairs(mod) do
mods_invert[v] = i
end
item.state[4] = nil
data:emit_signal("button::release",item,id,mods_invert)
item:emit_signal("button::release",item,id,mods_invert)
end)
@ -138,6 +141,21 @@ function module.setup_event(data,item,widget)
data:emit_signal("mouse::leave",item)
item:emit_signal("mouse::leave",item)
end)
-- Always tracking mouse::move is expensive, only do it when necessary
-- local function conn(b,t)
-- item:emit_signal("mouse::move",item)
-- end
-- item:connect_signal("connection",function(_,name,count)
-- if name == "mouse::move" then
-- widget:connect_signal("mouse::move",conn)
-- end
-- end)
-- item:connect_signal("disconnection",function(_,name,count)
-- if count == 0 then
-- widget:connect_signal("mouse::move",conn)
-- end
-- end)
end
-- Use all the space, let "align_fit" compute the right size
@ -267,9 +285,9 @@ local function create_item(item,data,args)
bg:emit_signal("widget::updated")
end)
if item.buttons then
bg:buttons(item.buttons)
end
-- if item.buttons then
-- bg:buttons(item.buttons)
-- end
return bg
end

View File

@ -1,5 +1,6 @@
return {
icon = require( "radical.item.layout.icon" ),
horizontal = require( "radical.item.layout.horizontal" ),
centerred = require( "radical.item.layout.centerred" ),
icon = require( "radical.item.layout.icon" ),
horizontal = require( "radical.item.layout.horizontal" ),
notification = require( "radical.item.layout.notification"),
centerred = require( "radical.item.layout.centerred" ),
}

View File

@ -0,0 +1,309 @@
local setmetatable = setmetatable
local beautiful = require( "beautiful" )
local color = require( "gears.color" )
local cairo = require( "lgi" ).cairo
local wibox = require( "wibox" )
local checkbox = require( "radical.widgets.checkbox" )
local fkey = require( "radical.widgets.fkey" )
local underlay = require( "radical.widgets.underlay" )
local theme = require( "radical.theme" )
local module = {}
-- Add [F1], [F2] ... to items
function module:setup_fkey(item,data)
item.set_f_key = function(_,value)
item._internal.has_changed = true
item._internal.f_key = value
data:remove_key_hook("F"..value)
data:add_key_hook({}, "F"..value , "press", function()
item.button1(data,menu)
data.visible = false
end)
end
item.get_f_key = function() return item._internal.f_key end
end
-- Like an overlay, but under
function module.paint_underlay(data,item,cr,width,height)
cr:save()
local state = item.state or {}
local current_state = state._current_key or nil
local state_name = theme.colors_by_id[current_state] or ""
local udl = underlay.draw(item.underlay,{style=data.underlay_style,height=height,bg=data["underlay_bg_"..state_name]})
cr:set_source_surface(udl,width-udl:get_width()-3)
cr:paint_with_alpha(data.underlay_alpha)
cr:restore()
end
-- Apply icon transformation
function module.set_icon(self,image)
if self._data.icon_transformation then
self._item._original_icon = image
image = self._data.icon_transformation(image,self._data,self._item)
end
wibox.widget.imagebox.set_image(self,image)
end
-- Setup the item icon
function module:setup_icon(item,data)
local icon = wibox.widget.imagebox()
icon.fit = function(...)
local w,h = wibox.widget.imagebox.fit(...)
return w+3,h
end
icon._data = data
icon._item = item
icon.set_image = module.set_icon
if item.icon then
icon:set_image(item.icon)
end
item.set_icon = function (_,value)
icon:set_image(value)
end
return icon
end
-- Show the checkbox
function module:setup_checked(item,data)
if item.checkable then
item.get_checked = function()
if type(item._private_data.checked) == "function" then
return item._private_data.checked()
else
return item._private_data.checked
end
end
local ck = wibox.widget.imagebox()
ck:set_image(item.checked and checkbox.checked() or checkbox.unchecked())
item.set_checked = function (_,value)
item._private_data.checked = value
ck:set_image(item.checked and checkbox.checked() or checkbox.unchecked())
item._internal.has_changed = true
end
return ck
end
end
-- Setup hover
function module:setup_hover(item,data)
item.set_hover = function(_,value)
local item_style = item.item_style or data.item_style
item.state[-1] = value and true or nil
item_style(item,{})
end
end
-- Create sub_menu arrows
local sub_arrow = nil
function module:setup_sub_menu_arrow(item,data)
if item._private_data.sub_menu_f or item._private_data.sub_menu_m then
if not sub_arrow then
sub_arrow = wibox.widget.imagebox() --TODO, make global
sub_arrow.fit = function(box, w, h) return sub_arrow._image:get_width(),item.height end
sub_arrow:set_image( beautiful.menu_submenu_icon )
end
return sub_arrow
end
end
-- Proxy all events to the parent
function module.setup_event(data,item,widget)
local widget = widget or item.widget
-- Setup data signals
widget:connect_signal("button::press",function(_,__,___,id,mod)
local mods_invert = {}
for k,v in ipairs(mod) do
mods_invert[v] = i
end
item.state[4] = true
data:emit_signal("button::press",item,id,mods_invert)
item:emit_signal("button::press",item,id,mods_invert)
end)
widget:connect_signal("button::release",function(_,__,___,id,mod)
local mods_invert = {}
for k,v in ipairs(mod) do
mods_invert[v] = i
end
item.state[4] = nil
data:emit_signal("button::release",item,id,mods_invert)
item:emit_signal("button::release",item,id,mods_invert)
end)
widget:connect_signal("mouse::enter",function(b,t)
data:emit_signal("mouse::enter",item)
item:emit_signal("mouse::enter",item)
end)
widget:connect_signal("mouse::leave",function(b,t)
data:emit_signal("mouse::leave",item)
item:emit_signal("mouse::leave",item)
end)
-- Always tracking mouse::move is expensive, only do it when necessary
-- local function conn(b,t)
-- item:emit_signal("mouse::move",item)
-- end
-- item:connect_signal("connection",function(_,name,count)
-- if name == "mouse::move" then
-- widget:connect_signal("mouse::move",conn)
-- end
-- end)
-- item:connect_signal("disconnection",function(_,name,count)
-- if count == 0 then
-- widget:connect_signal("mouse::move",conn)
-- end
-- end)
end
-- Use all the space, let "align_fit" compute the right size
local function textbox_fit(box,w,h)
local w2,h2 = wibox.widget.textbox.fit(box,w,h)
return w,h2
end
-- Force the width or compute the minimum space
local function align_fit(box,w,h)
if box._item.width then return box._item.width - box._data.item_style.margins.LEFT - box._data.item_style.margins.RIGHT,h end
return box.first:fit(w,h)+wibox.widget.textbox.fit(box.second,w,h)+box.third:fit(w,h),h
end
-- Create the actual widget
local function create_item(item,data,args)
-- Background
local bg = wibox.widget.background()
-- Margins
local m = wibox.layout.margin(la)
m:set_margins (0)
m:set_left ( (item.item_style or data.item_style).margins.LEFT )
m:set_right ( (item.item_style or data.item_style).margins.RIGHT )
m:set_top ( (item.item_style or data.item_style).margins.TOP )
m:set_bottom( (item.item_style or data.item_style).margins.BOTTOM )
-- Layout (left)
local layout = wibox.layout.fixed.horizontal()
bg:set_widget(m)
-- Layout (right)
local right = wibox.layout.fixed.horizontal()
-- F keys
module:setup_fkey(item,data)
if data.fkeys_prefix == true then
layout:add(fkey(data,item))
end
-- Icon
local icon = module:setup_icon(item,data)
layout:add(icon)
-- Prefix
if args.prefix_widget then
layout:add(args.prefix_widget)
end
-- Checkbox
local ck = module:setup_checked(item,data)
if ck then
right:add(ck)
end
-- Hover
module:setup_hover(item,data)
-- Sub_arrow
local ar = module:setup_sub_menu_arrow(item,data)
if ar then
right:add(ar)
end
-- Suffix
if args.suffix_widget then
right:add(args.suffix_widget)
end
-- Vertical text layout
local vert = wibox.layout.fixed.vertical()
-- vert:add(tb)
-- Text
local tb4 = wibox.widget.textbox()
tb4.draw = function(self,w, cr, width, height)
if item.underlay then
module.paint_underlay(data,item,cr,width,height)
end
wibox.widget.textbox.draw(self,w, cr, width, height)
end
item.set_text = function (_,value)
if data.disable_markup then
tb4:set_text(value)
else
tb4:set_markup("<b>"..value.."</b>")
end
item._private_data.text = value
end
item:set_text(item.text or "")
local tb2 = wibox.widget.textbox()
tb2:set_text("alternate")
tb2.fit = function(s,w,h)
return w,h
end
vert:add(tb4)
vert:add(tb2)
-- Layout (align)
local align = wibox.layout.align.horizontal()
align:set_middle( vert )
align:set_left ( layout )
align:set_right ( right )
m:set_widget ( align )
align._item = item
align._data = data
-- align.fit = data._internal.align_fit or align_fit
item._internal.align = align
-- Set widget
item.widget = bg
bg._item = item
-- Tooltip
item.widget:set_tooltip(item.tooltip)
-- Overlay
item.set_overlay = function(_,value)
item._private_data.overlay = value
item.widget:emit_signal("widget::updated")
end
item._internal.text_w = wibox.widget.textbox()--tb4
item._internal.icon_w = icon
item._internal.margin_w = m
-- Draw
local item_style = item.style or data.item_style
item_style(item,{})
item.widget:set_fg(item._private_data.fg)
-- Setup events
module.setup_event(data,item)
-- Setup dynamic underlay
-- Setup dynamic underlay
item:connect_signal("underlay::changed",function(_,udl)
bg:emit_signal("widget::updated")
end)
-- if item.buttons then
-- bg:buttons(item.buttons)
-- end
return bg
end
return setmetatable(module, { __call = function(_, ...) return create_item(...) end })
-- kate: space-indent on; indent-width 2; replace-tabs on;

View File

@ -111,7 +111,8 @@ function module:setup_item(data,item,args)
base = require( "radical.base" )
end
--Create the background
local item_layout = item.item_layout or horizontal_item_layout
local item_layout = item.layout or data.item_layout or horizontal_item_layout
print("\n\n\n\nsadHERE",item.layout,data.item_layout)
item.widget = item_layout(item,data,args)--wibox.widget.background()
cache_pixmap(item)