From 5ff71f73851208ec4ebd11ae237f60ae3b20c8b6 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 4 Jan 2014 00:49:20 -0500 Subject: [PATCH] Add new 'bar' menu type --- bar.lua | 163 ++++++++++++++++++++++++++++++++++++++ base.lua | 6 ++ init.lua | 1 + item_style/arrow_alt.lua | 22 +++++ item_style/arrow_grad.lua | 0 item_style/init.lua | 7 +- layout/vertical.lua | 2 +- menu_template.lua.tmpl | 87 ++++++++++++++++++++ radial.lua | 87 ++++++++++++++++++++ wibar.lua | 0 widgets/piechart.lua | 2 +- 11 files changed, 372 insertions(+), 5 deletions(-) create mode 100644 bar.lua create mode 100644 item_style/arrow_alt.lua create mode 100644 item_style/arrow_grad.lua create mode 100644 menu_template.lua.tmpl create mode 100644 wibar.lua diff --git a/bar.lua b/bar.lua new file mode 100644 index 0000000..5440a44 --- /dev/null +++ b/bar.lua @@ -0,0 +1,163 @@ +local base = require( "radical.base" ) +local print = print +local unpack = unpack +local setmetatable = setmetatable +local color = require( "gears.color" ) +local wibox = require( "wibox" ) +local beautiful = require( "beautiful" ) +local cairo = require( "lgi" ).cairo +local awful = require( "awful" ) +local util = require( "awful.util" ) +local button = require( "awful.button" ) +local checkbox = require( "radical.widgets.checkbox" ) +local item_style = require( "radical.item_style.arrow_alt" ) + +local capi,module = { mouse = mouse , screen = screen, keygrabber = keygrabber },{} + +local function get_direction(data) + return "left" -- Nothing to do +end + +local function set_position(self) + return --Nothing to do +end + +local function bg_draw(self, w, cr, width, height) + cr:save() + cr:set_source(color(self._data.bg)) + cr:rectangle(0,0,width,height) + cr:fill() + cr:restore() + wibox.layout.margin.draw(self, w, cr, width, height) +end + +local function setup_drawable(data) + local internal = data._internal + local get_map,set_map,private_data = internal.get_map,internal.set_map,internal.private_data + + --Init + internal.margin = wibox.layout.margin() + internal.margin._data = data + internal.margin.draw = bg_draw + + internal.layout = wibox.layout.fixed.horizontal() --data.layout(data) --TODO fix + internal.margin:set_widget(internal.layout) + + --Getters + get_map.wibox = function() return nil end -- Will this break? + get_map.x = function() return 0 end + get_map.y = function() return 0 end + get_map.width = function() return 500 end + get_map.height = function() return 40 end + get_map.visible = function() return private_data.visible end + get_map.direction = function() return private_data.direction end + get_map.margins = function() + local ret = {left=data.border_width,right=data.border_width,top=data.style.margins.TOP,bottom=data.style.margins.BOTTOM} + if data.arrow_type ~= base.arrow_type.NONE then + ret[data.direction] = ret[data.direction]+13 + end + return ret + end + + --Setters + function internal:set_visible(value) + -- TODO + end + +-- if data.visible then +-- local fit_w,fit_h = data._internal.layout:fit() +-- data.width = fit_w +-- data.height = fit_h +-- end + + -- This widget do not use wibox, so setup correct widget interface + data.fit = internal.margin.fit + data.draw = internal.margin.draw +end + +local function create_item(item,data) + -- Background + local bg = wibox.widget.background() + + -- Margins + local m = wibox.layout.margin(la) + m:set_margins (0) + m:set_left ( data.item_style.margins.LEFT ) + m:set_right ( data.item_style.margins.RIGHT ) + m:set_top ( data.item_style.margins.TOP ) + m:set_bottom( data.item_style.margins.BOTTOM ) + + -- Layout + local layout = wibox.layout.fixed.horizontal() + bg:set_widget(m) + m:set_widget(layout) + + -- Content + local tb = wibox.widget.textbox() + layout:add(tb) + item.widget = bg + tb:set_text("bob") + + -- Draw + data.item_style(data,item,false,false) + item.widget:set_fg(item._private_data.fg) + + return bg +end + +local function setup_item(data,item,args) + + -- Add widgets + data._internal.layout:add(create_item(item,data)) + item.widget:connect_signal("mouse::enter", function() item.selected = true end) + item.widget:connect_signal("mouse::leave", function() item.selected = false end) + + -- Setup buttons + 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 + if not buttons[4] then + buttons[#buttons+1] = button({},4,function() + data:scroll_up() + end) + end + if not buttons[5] then + buttons[#buttons+1] = button({},5,function() + data:scroll_down() + end) + end + item.widget:buttons( util.table.join(unpack(buttons))) +end + +local function new(args) + local args = args or {} + args.internal = args.internal or {} + args.internal.get_direction = args.internal.get_direction or get_direction + args.internal.set_position = args.internal.set_position or set_position + args.internal.setup_drawable = args.internal.setup_drawable or setup_drawable + args.internal.setup_item = args.internal.setup_item or setup_item +-- args.style = args.style or arrow_style + args.item_style = item_style + local ret = base(args) + ret:connect_signal("clear::menu",function(_,vis) + ret._internal.layout:reset() + end) + ret:connect_signal("_hidden::changed",function(_,item) + item.widget:emit_signal("widget::updated") + end) + return ret +end + +return setmetatable(module, { __call = function(_, ...) return new(...) end }) +-- kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/base.lua b/base.lua index f8aa284..208581c 100644 --- a/base.lua +++ b/base.lua @@ -14,6 +14,12 @@ local module = { NONE = 0, PRETTY = 1, CENTERED = 2, + }, + sub_menu_on ={ + SELECTED = 0, + CLICKED = 1, + NEVER = 2, + } }} local function filter(data) diff --git a/init.lua b/init.lua index 2e72298..aaca4be 100644 --- a/init.lua +++ b/init.lua @@ -6,6 +6,7 @@ return { context = require( "radical.context" ), embed = require( "radical.embed" ), box = require( "radical.box" ), + bar = require( "radical.bar" ), style = require( "radical.style" ), item_style = require( "radical.item_style" ), widgets = require( "radical.widgets" ), diff --git a/item_style/arrow_alt.lua b/item_style/arrow_alt.lua new file mode 100644 index 0000000..26dc1f3 --- /dev/null +++ b/item_style/arrow_alt.lua @@ -0,0 +1,22 @@ +local setmetatable = setmetatable +local print = print + +local module = { + margins = { + TOP = 2, + BOTTOM = 2, + RIGHT = 30, + LEFT = 30 + } +} + +local function draw(data,item,is_focussed,is_pressed,col) + if is_focussed or (item._tmp_menu) then + item.widget:set_bg(col or data.bg_focus) + else + item.widget:set_bg(col or nil) + end +end + +return setmetatable(module, { __call = function(_, ...) return draw(...) end }) +-- kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/item_style/arrow_grad.lua b/item_style/arrow_grad.lua new file mode 100644 index 0000000..e69de29 diff --git a/item_style/init.lua b/item_style/init.lua index c9a828e..71c4900 100644 --- a/item_style/init.lua +++ b/item_style/init.lua @@ -1,5 +1,6 @@ return { - basic = require("radical.item_style.basic"), - classic = require("radical.item_style.classic"), - rounded = require("radical.item_style.rounded"), + basic = require("radical.item_style.basic"), + classic = require("radical.item_style.classic"), + rounded = require("radical.item_style.rounded"), + arrow_alt = require("radical.item_style.arrow_alt"), } \ No newline at end of file diff --git a/layout/vertical.lua b/layout/vertical.lua index c2e3a19..bd3e5f0 100644 --- a/layout/vertical.lua +++ b/layout/vertical.lua @@ -99,7 +99,7 @@ function module:setup_item(data,item,args) --Create the background item.widget = wibox.widget.background() cache_pixmap(item) - + data.item_style(data,item,false,false) item.widget:set_fg(item._private_data.fg) item._internal.has_changed = true diff --git a/menu_template.lua.tmpl b/menu_template.lua.tmpl new file mode 100644 index 0000000..ecea7ad --- /dev/null +++ b/menu_template.lua.tmpl @@ -0,0 +1,87 @@ +local base = require( "radical.base" ) +local print = print +local unpack = unpack +local setmetatable = setmetatable +local color = require( "gears.color" ) +local wibox = require( "wibox" ) +local beautiful = require( "beautiful" ) +local cairo = require( "lgi" ).cairo +local awful = require( "awful" ) +local util = require( "awful.util" ) +local button = require( "awful.button" ) +local checkbox = require( "radical.widgets.checkbox" ) + +local capi,module = { mouse = mouse , screen = screen, keygrabber = keygrabber },{} + +local function get_direction(data) + return "left" -- Nothing to do +end + +local function set_position(self) + return --Nothing to do +end + +local function setup_drawable(data) + local internal = data._internal + local get_map,set_map,private_data = internal.get_map,internal.set_map,internal.private_data + + --Init +-- internal.w = wibox({}) + internal.margin = wibox.layout.margin() + if not data.layout then + data.layout = layout.vertical + end + internal.layout = wibox.layout.fixed.horizontal() --data.layout(data) --TODO fix + internal.margin:set_widget(internal.layout) + + --Getters + get_map.wibox = function() return nil end -- Will this break? + get_map.x = function() return 0 end + get_map.y = function() return 0 end + get_map.width = function() return 500 end + get_map.height = function() return 40 end + get_map.visible = function() return private_data.visible end + get_map.direction = function() return private_data.direction end + get_map.margins = function() + local ret = {left=data.border_width,right=data.border_width,top=data.style.margins.TOP,bottom=data.style.margins.BOTTOM} + if data.arrow_type ~= base.arrow_type.NONE then + ret[data.direction] = ret[data.direction]+13 + end + return ret + end + + --Setters + function internal:set_visible(value) + -- TODO + end + +end + +local function setup_item(data,item,args) + -- Add widgets + local tb = wibox.widget.textbox() + data._internal.layout:add(tb) + item.widget = tb + tb:set_text("bob") +end + +local function new(args) + local args = args or {} + args.internal = args.internal or {} + args.internal.get_direction = args.internal.get_direction or get_direction + args.internal.set_position = args.internal.set_position or set_position + args.internal.setup_drawable = args.internal.setup_drawable or setup_drawable + args.internal.setup_item = args.internal.setup_item or setup_item + args.style = args.style or arrow_style + local ret = base(args) + ret:connect_signal("clear::menu",function(_,vis) + ret._internal.layout:reset() + end) + ret:connect_signal("_hidden::changed",function(_,item) + item.widget:emit_signal("widget::updated") + end) + return ret +end + +return setmetatable(module, { __call = function(_, ...) return new(...) end }) +-- kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/radial.lua b/radial.lua index e69de29..ecea7ad 100644 --- a/radial.lua +++ b/radial.lua @@ -0,0 +1,87 @@ +local base = require( "radical.base" ) +local print = print +local unpack = unpack +local setmetatable = setmetatable +local color = require( "gears.color" ) +local wibox = require( "wibox" ) +local beautiful = require( "beautiful" ) +local cairo = require( "lgi" ).cairo +local awful = require( "awful" ) +local util = require( "awful.util" ) +local button = require( "awful.button" ) +local checkbox = require( "radical.widgets.checkbox" ) + +local capi,module = { mouse = mouse , screen = screen, keygrabber = keygrabber },{} + +local function get_direction(data) + return "left" -- Nothing to do +end + +local function set_position(self) + return --Nothing to do +end + +local function setup_drawable(data) + local internal = data._internal + local get_map,set_map,private_data = internal.get_map,internal.set_map,internal.private_data + + --Init +-- internal.w = wibox({}) + internal.margin = wibox.layout.margin() + if not data.layout then + data.layout = layout.vertical + end + internal.layout = wibox.layout.fixed.horizontal() --data.layout(data) --TODO fix + internal.margin:set_widget(internal.layout) + + --Getters + get_map.wibox = function() return nil end -- Will this break? + get_map.x = function() return 0 end + get_map.y = function() return 0 end + get_map.width = function() return 500 end + get_map.height = function() return 40 end + get_map.visible = function() return private_data.visible end + get_map.direction = function() return private_data.direction end + get_map.margins = function() + local ret = {left=data.border_width,right=data.border_width,top=data.style.margins.TOP,bottom=data.style.margins.BOTTOM} + if data.arrow_type ~= base.arrow_type.NONE then + ret[data.direction] = ret[data.direction]+13 + end + return ret + end + + --Setters + function internal:set_visible(value) + -- TODO + end + +end + +local function setup_item(data,item,args) + -- Add widgets + local tb = wibox.widget.textbox() + data._internal.layout:add(tb) + item.widget = tb + tb:set_text("bob") +end + +local function new(args) + local args = args or {} + args.internal = args.internal or {} + args.internal.get_direction = args.internal.get_direction or get_direction + args.internal.set_position = args.internal.set_position or set_position + args.internal.setup_drawable = args.internal.setup_drawable or setup_drawable + args.internal.setup_item = args.internal.setup_item or setup_item + args.style = args.style or arrow_style + local ret = base(args) + ret:connect_signal("clear::menu",function(_,vis) + ret._internal.layout:reset() + end) + ret:connect_signal("_hidden::changed",function(_,item) + item.widget:emit_signal("widget::updated") + end) + return ret +end + +return setmetatable(module, { __call = function(_, ...) return new(...) end }) +-- kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/wibar.lua b/wibar.lua new file mode 100644 index 0000000..e69de29 diff --git a/widgets/piechart.lua b/widgets/piechart.lua index 6420e40..f0a06f6 100644 --- a/widgets/piechart.lua +++ b/widgets/piechart.lua @@ -52,7 +52,7 @@ end local function set_data(self,data) self._data = data - self:emit_signal("widget::changed") + self:emit_signal("widget::updated") end local function new(data)