2013-05-11 21:02:42 +02:00
|
|
|
local setmetatable = setmetatable
|
2013-05-27 02:49:51 +02:00
|
|
|
local print,pairs = print,pairs
|
|
|
|
local unpack=unpack
|
|
|
|
local util = require( "awful.util" )
|
|
|
|
local button = require( "awful.button" )
|
|
|
|
local checkbox = require( "radical.widgets.checkbox" )
|
2013-05-11 21:02:42 +02:00
|
|
|
local wibox = require( "wibox" )
|
2014-02-23 05:59:03 +01:00
|
|
|
local item_layout = require("radical.item.layout.icon")
|
2014-02-06 04:48:26 +01:00
|
|
|
local base = nil
|
2013-05-11 21:02:42 +02:00
|
|
|
|
|
|
|
local module = {}
|
|
|
|
|
|
|
|
local function left(data)
|
|
|
|
if data._current_item._tmp_menu then
|
|
|
|
data = data._current_item._tmp_menu
|
2014-03-22 22:35:43 +01:00
|
|
|
data.items.selected = true
|
2013-05-11 21:02:42 +02:00
|
|
|
return true,data
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function right(data)
|
|
|
|
if data.parent_geometry.is_menu then
|
|
|
|
for k,v in ipairs(data.items) do
|
2014-03-22 22:35:43 +01:00
|
|
|
if v._tmp_menu == data or v.sub_menu_m == data then
|
|
|
|
v.selected = true
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
data.visible = false
|
|
|
|
data = data.parent_geometry
|
|
|
|
return true,data
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function up(data)
|
|
|
|
data.previous_item.selected = true
|
|
|
|
end
|
|
|
|
|
|
|
|
local function down(data)
|
|
|
|
data.next_item.selected = true
|
|
|
|
end
|
|
|
|
|
|
|
|
function module:setup_key_hooks(data)
|
|
|
|
data:add_key_hook({}, "Up" , "press", up )
|
|
|
|
data:add_key_hook({}, "&" , "press", up )
|
|
|
|
data:add_key_hook({}, "Down" , "press", down )
|
|
|
|
data:add_key_hook({}, "KP_Enter", "press", down )
|
|
|
|
data:add_key_hook({}, "Left" , "press", left )
|
|
|
|
data:add_key_hook({}, "\"" , "press", left )
|
|
|
|
data:add_key_hook({}, "Right" , "press", right )
|
|
|
|
data:add_key_hook({}, "#" , "press", right )
|
|
|
|
end
|
|
|
|
|
2014-02-02 23:21:59 +01:00
|
|
|
local function setup_event(data,item,args)
|
2013-05-27 02:49:51 +02:00
|
|
|
--Event handling
|
2014-02-06 04:48:26 +01:00
|
|
|
if data.select_on == base.event.HOVER then
|
|
|
|
item.widget:connect_signal("mouse::enter", function() item.selected = true end)
|
|
|
|
item.widget:connect_signal("mouse::leave", function() item.selected = false end)
|
|
|
|
end
|
2013-05-27 02:49:51 +02:00
|
|
|
data._internal.layout:add(item)
|
|
|
|
local buttons = {}
|
|
|
|
for i=1,10 do
|
|
|
|
if args["button"..i] then
|
|
|
|
buttons[#buttons+1] = button({},i,args["button"..i])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not buttons[3] then --Hide on right click
|
|
|
|
buttons[#buttons+1] = button({},3,function()
|
|
|
|
data.visible = false
|
|
|
|
if data.parent_geometry and data.parent_geometry.is_menu then
|
|
|
|
data.parent_geometry.visible = false
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
--Be sure to always hide sub menus, even when data.visible is set manually
|
|
|
|
data:connect_signal("visible::changed",function(_,vis)
|
|
|
|
if data._tmp_menu and data.visible == false then
|
|
|
|
data._tmp_menu.visible = false
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
data:connect_signal("parent_geometry::changed",function(_,vis)
|
|
|
|
local fit_w,fit_h = data._internal.layout:fit()
|
|
|
|
data.height = fit_h
|
2014-07-28 01:20:04 +02:00
|
|
|
if data.style then
|
|
|
|
data.style(data)
|
|
|
|
end
|
2013-05-27 02:49:51 +02:00
|
|
|
end)
|
|
|
|
item.widget:buttons( util.table.join(unpack(buttons)))
|
2014-02-02 23:21:59 +01:00
|
|
|
end
|
2013-05-27 02:49:51 +02:00
|
|
|
|
2014-02-02 23:21:59 +01:00
|
|
|
function module:setup_item(data,item,args)
|
|
|
|
local bg = item_layout(item,data,args)
|
2013-05-27 02:49:51 +02:00
|
|
|
|
2014-02-02 23:21:59 +01:00
|
|
|
-- Set size
|
2013-05-27 02:49:51 +02:00
|
|
|
local fit_w,fit_h = data._internal.layout:fit()
|
|
|
|
data.width = fit_w
|
|
|
|
data.height = fit_h
|
2014-07-28 01:20:04 +02:00
|
|
|
if data.style then
|
|
|
|
data.style(data)
|
|
|
|
end
|
2014-02-02 23:21:59 +01:00
|
|
|
local text_w = item._internal.text_w
|
|
|
|
local icon_w = item._internal.icon_w
|
|
|
|
|
|
|
|
-- Setup text
|
2014-03-05 06:12:48 +01:00
|
|
|
item.set_text = function (_,value)
|
2013-10-01 04:19:38 +02:00
|
|
|
if data.disable_markup then
|
|
|
|
text_w:set_text(value)
|
|
|
|
else
|
|
|
|
text_w:set_markup(value)
|
|
|
|
end
|
2013-07-02 00:25:25 +02:00
|
|
|
if data.auto_resize then
|
2015-12-29 12:21:13 +01:00
|
|
|
local fit_w,fit_h = text_w:get_preferred_size()
|
2013-07-02 00:25:25 +02:00
|
|
|
local is_largest = item == data._internal.largest_item_h
|
|
|
|
--TODO find new largest is item is smaller
|
|
|
|
if not data._internal.largest_item_h_v or data._internal.largest_item_h_v < fit_h then
|
|
|
|
data._internal.largest_item_h =item
|
|
|
|
data._internal.largest_item_h_v = fit_h
|
|
|
|
end
|
|
|
|
end
|
2013-06-23 04:30:27 +02:00
|
|
|
end
|
2014-03-05 06:12:48 +01:00
|
|
|
item.set_icon = function (_,value)
|
2014-02-02 23:21:59 +01:00
|
|
|
icon_w:set_image(value)
|
2013-06-23 04:30:27 +02:00
|
|
|
end
|
2014-03-05 06:12:48 +01:00
|
|
|
item:set_text(item._private_data.text)
|
2014-01-04 22:51:50 +01:00
|
|
|
|
|
|
|
-- Setup tooltip
|
2014-02-02 23:21:59 +01:00
|
|
|
bg:set_tooltip(item.tooltip)
|
|
|
|
|
|
|
|
-- Set widget
|
|
|
|
item.widget = bg
|
2014-03-02 22:28:30 +01:00
|
|
|
data.item_style(item,{})
|
2014-02-02 23:21:59 +01:00
|
|
|
setup_event(data,item,args)
|
2013-05-27 02:49:51 +02:00
|
|
|
end
|
|
|
|
|
2013-05-11 21:02:42 +02:00
|
|
|
--Get preferred item geometry
|
2016-01-09 10:25:46 +01:00
|
|
|
local function item_fit(data,item,self, content, width, height)
|
2013-07-04 07:51:01 +02:00
|
|
|
if not data.visible then return 1,1 end
|
2016-01-09 10:25:46 +01:00
|
|
|
local w, h = item._private_data._fit(self,content,width,height) --TODO port to new context API
|
2013-05-27 02:49:51 +02:00
|
|
|
return data.item_width or 70, item._private_data.height or h
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function new(data)
|
2014-02-06 04:48:26 +01:00
|
|
|
if not base then
|
|
|
|
base = require( "radical.base" )
|
|
|
|
end
|
2013-05-11 21:02:42 +02:00
|
|
|
local l = wibox.layout.fixed.horizontal()
|
2016-01-09 10:25:46 +01:00
|
|
|
l._fit = l.fit
|
|
|
|
local new_fit
|
|
|
|
new_fit = function(self,context,w,h,force_values) --TODO use the context instead of extra argument
|
|
|
|
|
|
|
|
-- Get the original fit, the function need to be replaced to avoir a stack overflow
|
|
|
|
l.fit = l._fit
|
|
|
|
local result,r2 = self:get_preferred_size(context, force_values and w, force_values and h)
|
|
|
|
l.fit = new_fit
|
|
|
|
|
2014-07-28 01:20:04 +02:00
|
|
|
local w,h
|
2013-07-02 00:25:25 +02:00
|
|
|
if data.auto_resize and data._internal.largest_item_h then
|
2014-07-28 01:20:04 +02:00
|
|
|
w,h = data.rowcount*(data.item_width or data.default_width),data._internal.largest_item_h_v > data.item_height and data._internal.largest_item_h_v or data.item_height
|
2013-07-02 00:25:25 +02:00
|
|
|
else
|
2014-07-28 01:20:04 +02:00
|
|
|
w,h = data.rowcount*(data.item_width or data.default_width),data.item_height
|
2013-07-02 00:25:25 +02:00
|
|
|
end
|
2014-07-28 01:20:04 +02:00
|
|
|
data:emit_signal("layout_size",w,h)
|
|
|
|
return w,h
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
2016-01-09 10:25:46 +01:00
|
|
|
l.fit = new_fit
|
2013-05-11 21:02:42 +02:00
|
|
|
l.add = function(l,item)
|
|
|
|
return wibox.layout.fixed.add(l,item.widget)
|
|
|
|
end
|
|
|
|
l.item_fit = item_fit
|
2013-05-27 02:49:51 +02:00
|
|
|
l.setup_key_hooks = module.setup_key_hooks
|
|
|
|
l.setup_item = module.setup_item
|
2014-03-12 05:31:50 +01:00
|
|
|
|
2016-02-11 07:36:50 +01:00
|
|
|
if data.spacing and l.set_spacing then
|
|
|
|
l:set_spacing(data.spacing)
|
|
|
|
end
|
2015-01-11 05:59:51 +01:00
|
|
|
|
2014-03-12 05:31:50 +01:00
|
|
|
data:connect_signal("widget::added",function(_,item,widget)
|
|
|
|
wibox.layout.fixed.add(l,item.widget)
|
|
|
|
l:emit_signal("widget::updated")
|
|
|
|
end)
|
2013-05-11 21:02:42 +02:00
|
|
|
return l
|
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(module, { __call = function(_, ...) return new(...) end })
|
|
|
|
-- kate: space-indent on; indent-width 2; replace-tabs on;
|