'Bar' menu cleanup, minor bug fixes
This commit is contained in:
parent
4db83034b8
commit
63bb804a45
103
bar.lua
103
bar.lua
|
@ -1,18 +1,16 @@
|
||||||
local base = require( "radical.base" )
|
local setmetatable,unpack = setmetatable,unpack
|
||||||
local print = print
|
local base = require( "radical.base" )
|
||||||
local unpack = unpack
|
local color = require( "gears.color" )
|
||||||
local setmetatable = setmetatable
|
local wibox = require( "wibox" )
|
||||||
local color = require( "gears.color" )
|
local beautiful = require( "beautiful" )
|
||||||
local wibox = require( "wibox" )
|
local cairo = require( "lgi" ).cairo
|
||||||
local beautiful = require( "beautiful" )
|
local awful = require( "awful" )
|
||||||
local cairo = require( "lgi" ).cairo
|
local util = require( "awful.util" )
|
||||||
local awful = require( "awful" )
|
local fkey = require( "radical.widgets.fkey" )
|
||||||
local util = require( "awful.util" )
|
local button = require( "awful.button" )
|
||||||
local fkey = require( "radical.widgets.fkey" )
|
local checkbox = require( "radical.widgets.checkbox" )
|
||||||
local button = require( "awful.button" )
|
local item_style = require( "radical.item_style.arrow_alt" )
|
||||||
local checkbox = require( "radical.widgets.checkbox" )
|
local vertical = require( "radical.layout.vertical" )
|
||||||
local item_style = require( "radical.item_style.arrow_alt" )
|
|
||||||
local vertical = require( "radical.layout.vertical" )
|
|
||||||
|
|
||||||
local capi,module = { mouse = mouse , screen = screen, keygrabber = keygrabber },{}
|
local capi,module = { mouse = mouse , screen = screen, keygrabber = keygrabber },{}
|
||||||
|
|
||||||
|
@ -24,6 +22,7 @@ local function set_position(self)
|
||||||
return --Nothing to do
|
return --Nothing to do
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Draw the menu background
|
||||||
local function bg_draw(self, w, cr, width, height)
|
local function bg_draw(self, w, cr, width, height)
|
||||||
cr:save()
|
cr:save()
|
||||||
cr:set_source(color(self._data.bg))
|
cr:set_source(color(self._data.bg))
|
||||||
|
@ -42,36 +41,18 @@ local function setup_drawable(data)
|
||||||
internal.margin._data = data
|
internal.margin._data = data
|
||||||
internal.margin.draw = bg_draw
|
internal.margin.draw = bg_draw
|
||||||
|
|
||||||
internal.layout = wibox.layout.fixed.horizontal() --data.layout(data) --TODO fix
|
internal.layout = wibox.layout.fixed.horizontal()
|
||||||
internal.margin:set_widget(internal.layout)
|
internal.margin:set_widget(internal.layout)
|
||||||
|
|
||||||
--Getters
|
--Getters
|
||||||
get_map.wibox = function() return nil end -- Will this break?
|
get_map.x = function() return 0 end
|
||||||
get_map.x = function() return 0 end
|
get_map.y = function() return 0 end
|
||||||
get_map.y = function() return 0 end
|
get_map.width = function() return internal.margin.fix(internal.margin,9999,99) end
|
||||||
get_map.width = function() return 500 end
|
get_map.height = function() return beautiful.default_height end
|
||||||
get_map.height = function() return 40 end
|
get_map.visible = function() return true end
|
||||||
get_map.visible = function() return private_data.visible end
|
get_map.direction = function() return "left" end
|
||||||
get_map.direction = function() return private_data.direction end
|
get_map.margins = function() return {left=0,right=0,top=0,bottom=0} 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
|
-- This widget do not use wibox, so setup correct widget interface
|
||||||
data.fit = internal.margin.fit
|
data.fit = internal.margin.fit
|
||||||
data.draw = internal.margin.draw
|
data.draw = internal.margin.draw
|
||||||
|
@ -85,10 +66,7 @@ end
|
||||||
-- Force the width or compute the minimum space
|
-- Force the width or compute the minimum space
|
||||||
local function align_fit(box,w,h)
|
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
|
if box._item.width then return box._item.width - box._data.item_style.margins.LEFT - box._data.item_style.margins.RIGHT,h end
|
||||||
local lw = box.first:fit(w,h)
|
return box.first:fit(w,h)+wibox.widget.textbox.fit(box.second,w,h)+box.third:fit(w,h),h
|
||||||
local cw = wibox.widget.textbox.fit(box.second,w,h)
|
|
||||||
local lr = box.third:fit(w,h)
|
|
||||||
return lw+cw+lr,h
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Create the actual widget
|
-- Create the actual widget
|
||||||
|
@ -163,33 +141,27 @@ local function create_item(item,data,args)
|
||||||
return bg
|
return bg
|
||||||
end
|
end
|
||||||
|
|
||||||
local function setup_item(data,item,args)
|
local function setup_buttons(data,item,args)
|
||||||
|
|
||||||
-- Add widgets
|
|
||||||
data._internal.layout:add(create_item(item,data,args))
|
|
||||||
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 = {}
|
local buttons = {}
|
||||||
for i=1,10 do
|
for i=1,10 do
|
||||||
if args["button"..i] then
|
if args["button"..i] then
|
||||||
buttons[#buttons+1] = button({},i,args["button"..i])
|
buttons[#buttons+1] = button({},i,args["button"..i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not buttons[3] then --Hide on right click
|
|
||||||
buttons[#buttons+1] = button({},3,function()
|
-- Setup sub_menu
|
||||||
data.visible = false
|
if (item.sub_menu_m or item.sub_menu_f) and data.sub_menu_on >= base.sub_menu_on.BUTTON1 and data.sub_menu_on <= base.sub_menu_on.BUTTON3 then
|
||||||
if data.parent_geometry and data.parent_geometry.is_menu then
|
buttons[data.sub_menu_on] = item.widget:set_menu(item.sub_menu_m or item.sub_menu_f,data.sub_menu_on)
|
||||||
data.parent_geometry.visible = false
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Scrool up
|
||||||
if not buttons[4] then
|
if not buttons[4] then
|
||||||
buttons[#buttons+1] = button({},4,function()
|
buttons[#buttons+1] = button({},4,function()
|
||||||
data:scroll_up()
|
data:scroll_up()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Scroll down
|
||||||
if not buttons[5] then
|
if not buttons[5] then
|
||||||
buttons[#buttons+1] = button({},5,function()
|
buttons[#buttons+1] = button({},5,function()
|
||||||
data:scroll_down()
|
data:scroll_down()
|
||||||
|
@ -198,6 +170,16 @@ local function setup_item(data,item,args)
|
||||||
item.widget:buttons( util.table.join(unpack(buttons)))
|
item.widget:buttons( util.table.join(unpack(buttons)))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function setup_item(data,item,args)
|
||||||
|
-- Add widgets
|
||||||
|
data._internal.layout:add(create_item(item,data,args))
|
||||||
|
item.widget:connect_signal("mouse::enter", function() item.selected = true end)
|
||||||
|
item.widget:connect_signal("mouse::leave", function() item.selected = false end)
|
||||||
|
|
||||||
|
-- Setup buttons
|
||||||
|
setup_buttons(data,item,args)
|
||||||
|
end
|
||||||
|
|
||||||
local function new(args)
|
local function new(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
args.internal = args.internal or {}
|
args.internal = args.internal or {}
|
||||||
|
@ -207,6 +189,7 @@ local function new(args)
|
||||||
args.internal.setup_item = args.internal.setup_item or setup_item
|
args.internal.setup_item = args.internal.setup_item or setup_item
|
||||||
-- args.style = args.style or arrow_style
|
-- args.style = args.style or arrow_style
|
||||||
args.item_style = item_style
|
args.item_style = item_style
|
||||||
|
args.sub_menu_on = base.sub_menu_on.BUTTON1
|
||||||
local ret = base(args)
|
local ret = base(args)
|
||||||
ret:connect_signal("clear::menu",function(_,vis)
|
ret:connect_signal("clear::menu",function(_,vis)
|
||||||
ret._internal.layout:reset()
|
ret._internal.layout:reset()
|
||||||
|
|
4
base.lua
4
base.lua
|
@ -341,9 +341,9 @@ local function new(args)
|
||||||
if internal.has_changed and data.style then
|
if internal.has_changed and data.style then
|
||||||
data.style(data,{arrow_x=20,margin=internal.margin})
|
data.style(data,{arrow_x=20,margin=internal.margin})
|
||||||
end
|
end
|
||||||
if not internal.parent_geometry and data._internal.set_position then
|
-- if not internal.parent_geometry and data._internal.set_position then
|
||||||
internal.set_position(data)
|
internal.set_position(data)
|
||||||
end
|
-- end
|
||||||
if internal.set_visible then
|
if internal.set_visible then
|
||||||
internal:set_visible(value)
|
internal:set_visible(value)
|
||||||
end
|
end
|
||||||
|
|
16
context.lua
16
context.lua
|
@ -37,6 +37,7 @@ local function get_direction(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function set_position(self)
|
local function set_position(self)
|
||||||
|
if not self.visible then return end
|
||||||
local ret,parent = {x=self.wibox.x,y=self.wibox.y},self.parent_geometry
|
local ret,parent = {x=self.wibox.x,y=self.wibox.y},self.parent_geometry
|
||||||
local prefx,prefy = self._internal.private_data.x,self._internal.private_data.y
|
local prefx,prefy = self._internal.private_data.x,self._internal.private_data.y
|
||||||
local src_geo = capi.screen[capi.mouse.screen].geometry
|
local src_geo = capi.screen[capi.mouse.screen].geometry
|
||||||
|
@ -164,9 +165,7 @@ local function setup_drawable(data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function setup_item(data,item,args)
|
local function setup_buttons(data,item,args)
|
||||||
local f = (data._internal.layout.setup_item) or (layout.vertical.setup_item)
|
|
||||||
f(data._internal.layout,data,item,args)
|
|
||||||
local buttons = {}
|
local buttons = {}
|
||||||
for i=1,10 do
|
for i=1,10 do
|
||||||
if args["button"..i] then
|
if args["button"..i] then
|
||||||
|
@ -203,6 +202,17 @@ local function setup_item(data,item,args)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
item.widget:buttons( util.table.join(unpack(buttons)))
|
item.widget:buttons( util.table.join(unpack(buttons)))
|
||||||
|
end
|
||||||
|
|
||||||
|
local function setup_item(data,item,args)
|
||||||
|
-- Layout
|
||||||
|
local f = (data._internal.layout.setup_item) or (layout.vertical.setup_item)
|
||||||
|
f(data._internal.layout,data,item,args)
|
||||||
|
|
||||||
|
-- Buttons
|
||||||
|
setup_buttons(data,item,args)
|
||||||
|
|
||||||
|
-- Tooltip
|
||||||
item.widget:set_tooltip(item.tooltip)
|
item.widget:set_tooltip(item.tooltip)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
2
init.lua
2
init.lua
|
@ -28,6 +28,8 @@ local function set_menu(self,menu,button)
|
||||||
for k, v in pairs(bt) do
|
for k, v in pairs(bt) do
|
||||||
current[type(k) == "number" and (#current+1) or k] = v
|
current[type(k) == "number" and (#current+1) or k] = v
|
||||||
end
|
end
|
||||||
|
self._menu = menu
|
||||||
|
return bt
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Do some monkey patching to extend all wibox.widget
|
-- Do some monkey patching to extend all wibox.widget
|
||||||
|
|
|
@ -44,13 +44,13 @@ end
|
||||||
|
|
||||||
function module:setup_key_hooks(data)
|
function module:setup_key_hooks(data)
|
||||||
data:add_key_hook({}, "Up" , "press", up )
|
data:add_key_hook({}, "Up" , "press", up )
|
||||||
data:add_key_hook({}, "&" , "press", up )
|
data:add_key_hook({}, "&" , "press", up ) -- Xephyr bug
|
||||||
data:add_key_hook({}, "Down" , "press", down )
|
data:add_key_hook({}, "Down" , "press", down )
|
||||||
data:add_key_hook({}, "KP_Enter", "press", down )
|
data:add_key_hook({}, "KP_Enter", "press", down ) -- Xephyr bug
|
||||||
data:add_key_hook({}, "Left" , "press", left )
|
data:add_key_hook({}, "Left" , "press", left )
|
||||||
data:add_key_hook({}, "\"" , "press", left )
|
data:add_key_hook({}, "\"" , "press", left ) -- Xephyr bug
|
||||||
data:add_key_hook({}, "Right" , "press", right )
|
data:add_key_hook({}, "Right" , "press", right )
|
||||||
data:add_key_hook({}, "#" , "press", right )
|
data:add_key_hook({}, "#" , "press", right ) -- Xephyr bug
|
||||||
end
|
end
|
||||||
|
|
||||||
--Get preferred item geometry
|
--Get preferred item geometry
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
local base = require( "radical.base" )
|
local base = require( "radical.base" )
|
||||||
|
local color = require( "gears.color" )
|
||||||
|
|
||||||
local module = {
|
local module = {
|
||||||
margins = {
|
margins = {
|
||||||
|
@ -15,6 +16,7 @@ local function draw(data)
|
||||||
if data.wibox then
|
if data.wibox then
|
||||||
data.wibox.border_width = 1
|
data.wibox.border_width = 1
|
||||||
data.wibox.border_color = data.border_color
|
data.wibox.border_color = data.border_color
|
||||||
|
data.wibox:set_bg(color(data.bg))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue