2014-02-02 22:53:09 +01:00
|
|
|
local setmetatable = setmetatable
|
2016-02-28 08:04:51 +01:00
|
|
|
local beautiful = require( "beautiful" )
|
|
|
|
local wibox = require( "wibox" )
|
|
|
|
local checkbox = require( "radical.widgets.checkbox" )
|
|
|
|
local fkey = require( "radical.widgets.fkey" )
|
|
|
|
local infoshapes = require( "radical.widgets.infoshapes" )
|
|
|
|
local util = require( "awful.util" )
|
|
|
|
local margins2 = require( "radical.margins" )
|
|
|
|
local shape = require( "gears.shape" )
|
|
|
|
local surface = require( "gears.surface" )
|
2016-03-05 08:14:24 +01:00
|
|
|
local common = require( "radical.item.common" )
|
2014-02-02 22:53:09 +01:00
|
|
|
|
|
|
|
local module = {}
|
|
|
|
|
|
|
|
-- Show the checkbox
|
|
|
|
function module:setup_checked(item,data)
|
|
|
|
if item.checkable then
|
2014-03-05 06:12:48 +01:00
|
|
|
item.get_checked = function()
|
2014-02-02 22:53:09 +01:00
|
|
|
if type(item._private_data.checked) == "function" then
|
2014-11-15 05:46:06 +01:00
|
|
|
return item._private_data.checked(data,item)
|
2014-02-02 22:53:09 +01:00
|
|
|
else
|
|
|
|
return item._private_data.checked
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local ck = wibox.widget.imagebox()
|
|
|
|
ck:set_image(item.checked and checkbox.checked() or checkbox.unchecked())
|
2014-03-05 06:12:48 +01:00
|
|
|
item.set_checked = function (_,value)
|
2014-02-02 22:53:09 +01:00
|
|
|
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
|
|
|
|
|
2014-02-05 05:29:38 +01:00
|
|
|
-- Create sub_menu arrows
|
|
|
|
local sub_arrow = nil
|
|
|
|
function module:setup_sub_menu_arrow(item,data)
|
2014-08-08 08:02:37 +02:00
|
|
|
if (item._private_data.sub_menu_f or item._private_data.sub_menu_m) and not data.disable_submenu_icon then
|
2014-02-05 05:29:38 +01:00
|
|
|
if not sub_arrow then
|
|
|
|
sub_arrow = wibox.widget.imagebox() --TODO, make global
|
2015-12-29 11:19:23 +01:00
|
|
|
sub_arrow.fit = function(box, context,w, h) return (sub_arrow._image and sub_arrow._image:get_width() or 0),item.height end
|
2016-02-11 07:36:50 +01:00
|
|
|
|
|
|
|
if beautiful.menu_submenu_icon then
|
|
|
|
sub_arrow:set_image( beautiful.menu_submenu_icon )
|
|
|
|
else
|
|
|
|
local h = data.item_height
|
|
|
|
sub_arrow:set_image(surface.load_from_shape(7, h,
|
|
|
|
shape.transform(shape.isosceles_triangle) : rotate_at(3.5,h/2,math.pi/2),
|
|
|
|
beautiful.menu_fg_normal or beautiful.menu_fg or beautiful.fg_normal
|
|
|
|
))
|
|
|
|
end
|
2014-02-05 05:29:38 +01:00
|
|
|
end
|
|
|
|
return sub_arrow
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-02 22:53:09 +01:00
|
|
|
-- Create the actual widget
|
|
|
|
local function create_item(item,data,args)
|
2016-03-05 08:14:24 +01:00
|
|
|
-- F keys
|
|
|
|
common.setup_fkey(item,data)
|
|
|
|
|
|
|
|
-- Icon
|
|
|
|
local icon = common.setup_icon(item,data)
|
|
|
|
|
|
|
|
if data.icon_per_state == true then --TODO create an icon widget, see item/common.lua
|
|
|
|
item:connect_signal("state::changed",function(i,d,st)
|
|
|
|
if item._original_icon and data.icon_transformation then
|
|
|
|
wibox.widget.imagebox.set_image(icon,data.icon_transformation(item._original_icon,data,item))
|
|
|
|
end
|
|
|
|
end)
|
2014-02-09 09:04:02 +01:00
|
|
|
end
|
2014-02-13 05:09:55 +01:00
|
|
|
|
2016-02-11 10:21:10 +01:00
|
|
|
-- Define the item layout
|
|
|
|
item.widget = wibox.widget.base.make_widget_declarative {
|
|
|
|
-- Widgets
|
|
|
|
{
|
2016-02-28 08:04:51 +01:00
|
|
|
|
2016-02-11 10:21:10 +01:00
|
|
|
-- Widget
|
|
|
|
{
|
|
|
|
-- This is where the content is placed
|
|
|
|
|
|
|
|
-- Widgets
|
|
|
|
{
|
|
|
|
-- The prefixes
|
|
|
|
|
|
|
|
-- Widget
|
|
|
|
data.fkeys_prefix and fkey(data,item) or nil,
|
2016-03-05 08:14:24 +01:00
|
|
|
{
|
|
|
|
icon ,
|
|
|
|
right = 3 ,
|
|
|
|
widget = wibox.layout.margin ,
|
|
|
|
},
|
2016-02-11 10:21:10 +01:00
|
|
|
args.prefix_widget ,
|
|
|
|
|
|
|
|
-- Attributes
|
|
|
|
layout = wibox.layout.fixed.horizontal
|
|
|
|
},
|
2016-02-28 08:04:51 +01:00
|
|
|
{
|
|
|
|
-- Underlay and overlay
|
2016-03-05 08:14:24 +01:00
|
|
|
{
|
|
|
|
-- The main textbox
|
|
|
|
id = "main_text" ,
|
2016-03-05 09:23:59 +01:00
|
|
|
_data = data ,
|
2016-03-05 08:14:24 +01:00
|
|
|
_private_data = item._private_data ,
|
|
|
|
text = item.text ,
|
|
|
|
widget = wibox.widget.textbox,
|
|
|
|
},
|
2016-02-28 08:04:51 +01:00
|
|
|
|
|
|
|
-- Attributes
|
|
|
|
widget = infoshapes,
|
|
|
|
spacing = 10,
|
|
|
|
infoshapes = item.infoshapes,
|
|
|
|
id = "infoshapes",
|
|
|
|
},
|
2016-02-11 10:21:10 +01:00
|
|
|
{
|
|
|
|
-- Suffixes
|
|
|
|
|
|
|
|
-- Widget
|
|
|
|
module:setup_checked(item,data) ,
|
|
|
|
module:setup_sub_menu_arrow(item,data),
|
|
|
|
args.suffix_widget ,
|
|
|
|
|
|
|
|
-- Attributes
|
|
|
|
layout = wibox.layout.fixed.horizontal
|
|
|
|
},
|
|
|
|
|
|
|
|
-- Attributes
|
|
|
|
_item = item ,
|
|
|
|
_data = data ,
|
|
|
|
id = "main_align" ,
|
|
|
|
layout = wibox.layout.align.horizontal,
|
|
|
|
},
|
|
|
|
|
|
|
|
-- Attributes
|
|
|
|
id = "main_margin" ,
|
|
|
|
layout = wibox.layout.margin,
|
|
|
|
},
|
|
|
|
|
|
|
|
-- Attributes
|
|
|
|
fg = item._private_data.fg ,
|
|
|
|
tooltip = item.tooltip ,
|
|
|
|
_item = item ,
|
|
|
|
_data = data ,
|
|
|
|
widget = wibox.widget.background,
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Make some widgets easier to access
|
|
|
|
item._internal.margin_w = item.widget:get_children_by_id("main_margin")[1]
|
|
|
|
item._internal.align = item.widget:get_children_by_id("main_align" )[1]
|
2016-03-05 08:14:24 +01:00
|
|
|
item._internal.text_w = item.widget:get_children_by_id("main_text" )[1]
|
|
|
|
item._internal.icon_w = icon
|
2016-02-11 10:21:10 +01:00
|
|
|
|
|
|
|
-- Export the margin
|
|
|
|
local mrgns = margins2(
|
|
|
|
item._internal.margin_w,
|
|
|
|
util.table.join(
|
|
|
|
(item.item_style or data.item_style).margins,data.default_item_margins
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
function item:get_margins()
|
|
|
|
return mrgns
|
|
|
|
end
|
2014-03-02 22:28:30 +01:00
|
|
|
|
2016-02-11 10:21:10 +01:00
|
|
|
-- Draw
|
|
|
|
local item_style = item.style or data.item_style
|
|
|
|
item_style(item,{})
|
2014-02-16 03:57:07 +01:00
|
|
|
|
2016-02-11 10:21:10 +01:00
|
|
|
-- Setup events
|
2016-03-05 08:14:24 +01:00
|
|
|
common.setup_event(data,item)
|
2016-01-12 09:33:38 +01:00
|
|
|
|
2016-02-11 10:21:10 +01:00
|
|
|
return item.widget
|
2014-02-02 22:53:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(module, { __call = function(_, ...) return create_item(...) end })
|
2016-02-11 10:21:10 +01:00
|
|
|
-- kate: space-indent on; indent-width 4; replace-tabs on;
|