Add default_item_margins and default_margins
This commit is contained in:
parent
9d8bcc3882
commit
1a7630e437
|
@ -203,6 +203,8 @@ Multiple items can have multiple sets of options.
|
|||
| disable_submenu_icon| Do not show the submenu icon (arrow) | boolean |
|
||||
| margins | Read/Write table (left,right,top and bottom) | dynamic table |
|
||||
| visible_row_count | Number of visible items -(#max-(#total-#filtered)) | number |
|
||||
| default_item_margins| Default margins for items ({left=1,right=1...}) | array of direction |
|
||||
| default_margins | Default margins for the menu ({left=1,right=1...}) | array of direction |
|
||||
|
||||
###Item options
|
||||
|
||||
|
|
26
bar.lua
26
bar.lua
|
@ -12,6 +12,7 @@ local checkbox = require( "radical.widgets.checkbox" )
|
|||
local item_style = require( "radical.item.style.arrow_single" )
|
||||
-- local vertical = require( "radical.layout.vertical" )
|
||||
local item_layout= require( "radical.item.layout.horizontal" )
|
||||
local margins2 = require("radical.margins" )
|
||||
|
||||
local capi,module = { mouse = mouse , screen = screen, keygrabber = keygrabber },{}
|
||||
|
||||
|
@ -47,11 +48,11 @@ local function setup_drawable(data)
|
|||
local internal = data._internal
|
||||
local private_data = internal.private_data
|
||||
|
||||
internal.layout = internal.layout_func or wibox.layout.fixed.horizontal()
|
||||
internal.layout._draw = internal.layout.draw
|
||||
internal.layout.draw = bg_draw
|
||||
internal.layout._data = data
|
||||
|
||||
internal.layout = internal.layout_func or wibox.layout.fixed.horizontal()
|
||||
internal.layout._draw = internal.layout.draw
|
||||
internal.layout.draw = bg_draw
|
||||
internal.layout._data = data
|
||||
|
||||
--Getters
|
||||
data.get_x = function() return 0 end
|
||||
data.get_y = function() return 0 end
|
||||
|
@ -59,7 +60,16 @@ internal.layout._data = data
|
|||
data.get_height = function() return beautiful.default_height end
|
||||
data.get_visible = function() return true end
|
||||
data.get_direction = function() return "left" end
|
||||
data.get_margins = function() return {left=0,right=0,top=0,bottom=0} end
|
||||
|
||||
-- Setup the margins
|
||||
local m = wibox.layout.margin()
|
||||
m:set_widget(internal.layout)
|
||||
internal.margin = m
|
||||
local mrgns = margins2(m,data.default_margins or {})
|
||||
data._internal.mrgns = mrgns
|
||||
data.get_margins = function()
|
||||
return data._internal.mrgns or {}
|
||||
end
|
||||
|
||||
-- This widget do not use wibox, so setup correct widget interface
|
||||
data.fit = internal.layout
|
||||
|
@ -163,7 +173,7 @@ local function new(args)
|
|||
-- ret._internal.layout:connect_signal("widget::updated",function()
|
||||
-- ret:emit_signal("widget::updated")
|
||||
-- end)
|
||||
return ret,ret._internal.layout
|
||||
return ret,ret._internal.margin
|
||||
end
|
||||
|
||||
function module.flex(args)
|
||||
|
@ -172,7 +182,7 @@ function module.flex(args)
|
|||
args.internal.layout_func = wibox.layout.flex.horizontal()
|
||||
local data = new(args)
|
||||
data._internal.text_fit = function(self,width,height) return width,height end
|
||||
return data
|
||||
return data,data._internal.margin
|
||||
end
|
||||
|
||||
return setmetatable(module, { __call = function(_, ...) return new(...) end })
|
||||
|
|
10
base.lua
10
base.lua
|
@ -290,14 +290,8 @@ local function new(args)
|
|||
-- Default settings
|
||||
bg = args.bg or beautiful.menu_bg_normal or beautiful.bg_normal or "#000000",
|
||||
fg = args.fg or beautiful.menu_fg_normal or beautiful.fg_normal or "#ffffff",
|
||||
-- bg_focus = args.bg_focus or beautiful.menu_bg_focus or beautiful.bg_focus or "#ffffff",
|
||||
-- fg_focus = args.fg_focus or beautiful.menu_fg_focus or beautiful.fg_focus or "#000000",
|
||||
-- bg_alternate = args.bg_alternate or beautiful.menu_bg_alternate or beautiful.bg_alternate or beautiful.bg_normal,
|
||||
-- bg_highlight = args.bg_highlight or beautiful.menu_bg_highlight or beautiful.bg_highlight or beautiful.bg_normal,
|
||||
bg_header = args.bg_header or beautiful.menu_bg_header or beautiful.fg_normal,
|
||||
bg_prefix = args.bg_prefix or nil,
|
||||
-- bg_hover = args.bg_hover or nil,
|
||||
-- fg_hover = args.fg_hover or nil,
|
||||
border_color = args.border_color or beautiful.menu_border_color or beautiful.border_color or "#333333",
|
||||
border_width = args.border_width or beautiful.menu_border_width or beautiful.border_width or 3,
|
||||
separator_color = args.separator_color or beautiful.menu_separator_color or args.border_color or beautiful.menu_border_color or beautiful.border_color or "#333333",
|
||||
|
@ -338,7 +332,9 @@ local function new(args)
|
|||
select_on = args.select_on or module.event.HOVER,
|
||||
overlay = args.overlay or nil,
|
||||
opacity = args.opacity or beautiful.menu_opacity or 1,
|
||||
icon_transformation = args.icon_transformation or nil,
|
||||
default_margins = args.default_margins or {},
|
||||
default_item_margins = args.default_item_margins or {},
|
||||
icon_transformation = args.icon_transformation or nil,
|
||||
filter_underlay_style = args.filter_underlay_style or nil,
|
||||
filter_underlay_color = args.filter_underlay_color,
|
||||
filter_placeholder = args.filter_placeholder or "",
|
||||
|
|
12
context.lua
12
context.lua
|
@ -75,7 +75,7 @@ local function set_position(self)
|
|||
ret={x=parent.x-self.width,y=parent.y+(self.parent_item.y)}
|
||||
else
|
||||
local margins = self.margins
|
||||
ret={x=parent.x+parent.width,y=parent.y+(self.parent_item.y)-(margins and self.margins.top or self.style.margins.TOP)}
|
||||
ret={x=parent.x+parent.width,y=parent.y+(self.parent_item.y)-(margins and self.margins.top or data.default_margins.top or self.style.margins.TOP)}
|
||||
|
||||
--Handle when the menu doesn't fit in the srceen horizontally
|
||||
if ret.x+self.width > src_geo.x + src_geo.width then
|
||||
|
@ -84,7 +84,7 @@ local function set_position(self)
|
|||
|
||||
-- Handle when the menu doesn't fit on the screen vertically
|
||||
if ret.y+self.height > src_geo.y + src_geo.height then
|
||||
ret.y = ret.y - self.height + self.item_height + 2*(margins and self.margins.top or self.style.margins.TOP)
|
||||
ret.y = ret.y - self.height + self.item_height + 2*(margins and self.margins.top or data.default_margins.top or self.style.margins.TOP)
|
||||
end
|
||||
end
|
||||
elseif parent then
|
||||
|
@ -157,10 +157,10 @@ local function setup_drawable(data)
|
|||
data.get_margins = function()
|
||||
if not internal._margins then
|
||||
local ret = {
|
||||
left = data.border_width+(data.style.margins.LEFT or 0),
|
||||
right = data.border_width+(data.style.margins.RIGHT or 0),
|
||||
top = data.border_width+(data.style.margins.TOP or 0),
|
||||
bottom = data.border_width+(data.style.margins.BOTTOM or 0),
|
||||
left = data.border_width+(data.default_margins.left or data.style.margins.LEFT or 0),
|
||||
right = data.border_width+(data.default_margins.right or data.style.margins.RIGHT or 0),
|
||||
top = data.border_width+(data.default_margins.top or data.style.margins.TOP or 0),
|
||||
bottom = data.border_width+(data.default_margins.bottom or data.style.margins.BOTTOM or 0),
|
||||
}
|
||||
local m = margins2(internal.margin,ret)
|
||||
rawset(m,"_reset",m.reset)
|
||||
|
|
|
@ -12,6 +12,17 @@ local capi = { client = client, mouse = mouse, screen = screen}
|
|||
|
||||
local module,pause_monitoring = {},false
|
||||
|
||||
-- Using viewonly to change tag will create an unwanted
|
||||
-- focus event in the awful stack. While this module does
|
||||
-- not use it, it try to be a good citizen and avoid corrupting
|
||||
-- it.
|
||||
local lock_history = false
|
||||
local function awful_client_history_add(c)
|
||||
if not lock_history then
|
||||
client2.focus.history.add(c)
|
||||
end
|
||||
end
|
||||
|
||||
-- Keep its own history instead of using awful.client.focus.history
|
||||
local focusIdx,focusTable = 1,setmetatable({}, { __mode = 'v' })
|
||||
local focusTag = setmetatable({}, { __mode = 'v' })
|
||||
|
@ -89,7 +100,7 @@ local function reload_highlight(i)
|
|||
end
|
||||
tag_list.highlight(hl)
|
||||
|
||||
i._internal.border_color_back = i.client.border_color
|
||||
i._internal.border_color_back = i._internal.border_color_back or i.client.border_color
|
||||
i.client.border_color = beautiful.bg_urgent
|
||||
elseif i._internal.border_color_back then
|
||||
i.client.border_color = i._internal.border_color_back
|
||||
|
@ -138,20 +149,26 @@ local function new(args)
|
|||
|
||||
currentMenu:add_key_hook({}, "Tab", "press", select_next)
|
||||
currentMenu:add_key_hook({}, "Shift_L", "press", function()
|
||||
currentMenu._current_item.checked = not currentMenu._current_item.checked
|
||||
client2.toggletag (t, currentMenu._current_item.client)
|
||||
reload_underlay(currentMenu._current_item.client,currentMenu._current_item)
|
||||
local item = currentMenu._current_item
|
||||
item.checked = not item.checked
|
||||
local c = item.client
|
||||
client2.toggletag (t, c)
|
||||
reload_underlay(c,item)
|
||||
if not auto_release then
|
||||
reload_highlight(currentMenu._current_item)
|
||||
reload_highlight(item)
|
||||
end
|
||||
if item._internal.border_color_back then
|
||||
c.border_color = item._internal.border_color_back
|
||||
end
|
||||
return true
|
||||
end)
|
||||
currentMenu:add_key_hook({}, "Control_L", "press", function()
|
||||
currentMenu._current_item.checked = not currentMenu._current_item.checked
|
||||
client2.movetotag(t, currentMenu._current_item.client)
|
||||
reload_underlay(currentMenu._current_item.client,currentMenu._current_item)
|
||||
local item = currentMenu._current_item
|
||||
item.checked = not item.checked
|
||||
client2.movetotag(t, item.client)
|
||||
reload_underlay(item.client,item)
|
||||
if not auto_release then
|
||||
reload_highlight(currentMenu._current_item)
|
||||
reload_highlight(item)
|
||||
end
|
||||
return true
|
||||
end)
|
||||
|
@ -181,7 +198,9 @@ local function new(args)
|
|||
button1 = function(a,b,c,d,no_hide)
|
||||
local t = focusTag[v] or v:tags()[1]
|
||||
if t and t.selected == false and not util.table.hasitem(v:tags(),tag.selected(v.screen)) then
|
||||
lock_history = true
|
||||
tag.viewonly(t)
|
||||
lock_history = false
|
||||
end
|
||||
capi.client.focus = v
|
||||
v:raise()
|
||||
|
@ -229,5 +248,9 @@ function module.altTabBack(args)
|
|||
new({leap = -1,auto_release = (args or {}).auto_release})
|
||||
end
|
||||
|
||||
-- Sometime need to lock .add
|
||||
capi.client.disconnect_signal("focus", client2.focus.history.add)
|
||||
capi.client.connect_signal("focus", awful_client_history_add)
|
||||
|
||||
return setmetatable(module, { __call = function(_, ...) return new(...) end })
|
||||
-- kate: space-indent on; indent-width 2; replace-tabs on;
|
||||
|
|
|
@ -228,12 +228,15 @@ local function new(s)
|
|||
local track = tracker(s)
|
||||
|
||||
local args = {
|
||||
item_style = beautiful.taglist_theme or radical.item.style.arrow_prefix,
|
||||
item_style = beautiful.taglist_item_style or radical.item.style.arrow_prefix,
|
||||
style = beautiful.taglist_style,
|
||||
select_on = radical.base.event.NEVER,
|
||||
fg = beautiful.taglist_fg or beautiful.fg_normal,
|
||||
bg = beautiful.taglist_bg or beautiful.bg_normal,
|
||||
bg_focus = beautiful.taglist_bg_selected,
|
||||
fg_focus = beautiful.taglist_fg_selected,
|
||||
default_item_margins = beautiful.taglist_default_item_margins,
|
||||
default_margins = beautiful.taglist_default_margins ,
|
||||
-- fkeys_prefix = true,
|
||||
}
|
||||
for k,v in ipairs {"hover","used","urgent","cloned","changed","highlight"} do
|
||||
|
|
|
@ -66,6 +66,7 @@ local function new(s)
|
|||
if not init then
|
||||
capi.tag.connect_signal("property::screen" , reload )
|
||||
capi.tag.connect_signal("property::activated", reload )
|
||||
capi.tag.connect_signal("property::index" , reload )
|
||||
end
|
||||
|
||||
tracker.reload = function()
|
||||
|
|
|
@ -241,12 +241,16 @@ end
|
|||
|
||||
local function new(screen)
|
||||
local args = {
|
||||
select_on=radical.base.event.NEVER,
|
||||
disable_markup = true,
|
||||
fg = beautiful.tasklist_fg or beautiful.fg_normal,
|
||||
bg = beautiful.tasklist_bg or beautiful.bg_normal,
|
||||
underlay_style = beautiful.tasklist_underlay_style or radical.widgets.underlay.draw_arrow,
|
||||
icon_transformation = beautiful.tasklist_icon_transformation
|
||||
select_on = radical.base.event.NEVER ,
|
||||
disable_markup = true ,
|
||||
fg = beautiful.tasklist_fg or beautiful.fg_normal ,
|
||||
bg = beautiful.tasklist_bg or beautiful.bg_normal ,
|
||||
underlay_style = beautiful.tasklist_underlay_style or radical.widgets.underlay.draw_arrow,
|
||||
icon_transformation = beautiful.tasklist_icon_transformation ,
|
||||
default_item_margins = beautiful.tasklist_default_item_margins ,
|
||||
default_margins = beautiful.tasklist_default_margins ,
|
||||
item_style = beautiful.tasklist_item_style ,
|
||||
style = beautiful.tasklist_style ,
|
||||
}
|
||||
for k,v in ipairs {"hover","urgent","minimized","focus"} do
|
||||
args["bg_"..v] = beautiful["tasklist_bg_"..v]
|
||||
|
|
|
@ -5,6 +5,7 @@ local cairo = require( "lgi" ).cairo
|
|||
local wibox = require( "wibox" )
|
||||
local checkbox = require( "radical.widgets.checkbox" )
|
||||
local fkey = require( "radical.widgets.fkey" )
|
||||
local util = require( "awful.util" )
|
||||
local horizontal = require( "radical.item.layout.horizontal" )
|
||||
local margins2 = require("radical.margins")
|
||||
|
||||
|
@ -16,7 +17,7 @@ local function create_item(item,data,args)
|
|||
|
||||
-- Margins
|
||||
local m = wibox.layout.margin(la)
|
||||
local mrgns = margins2(m,data.item_style.margins)
|
||||
local mrgns = margins2(m,util.table.join(data.item_style.margins,data.default_item_margins))
|
||||
item.get_margins = function()
|
||||
return mrgns
|
||||
end
|
||||
|
|
|
@ -7,6 +7,7 @@ local checkbox = require( "radical.widgets.checkbox" )
|
|||
local fkey = require( "radical.widgets.fkey" )
|
||||
local underlay = require( "radical.widgets.underlay" )
|
||||
local theme = require( "radical.theme" )
|
||||
local util = require( "awful.util" )
|
||||
local margins2 = require("radical.margins")
|
||||
|
||||
local module = {}
|
||||
|
@ -162,6 +163,7 @@ end
|
|||
|
||||
-- Force the width or compute the minimum space
|
||||
local function align_fit(box,w,h)
|
||||
local mar = util.table.join(box._data.item_style.margins,box._data.default_item_margins)
|
||||
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
|
||||
|
@ -173,7 +175,8 @@ local function create_item(item,data,args)
|
|||
|
||||
-- Margins
|
||||
local m = wibox.layout.margin(la)
|
||||
local mrgns = margins2(m,(item.item_style or data.item_style).margins)
|
||||
-- print("LA",data.default_item_margins.TOP)
|
||||
local mrgns = margins2(m,util.table.join((item.item_style or data.item_style).margins,data.default_item_margins))
|
||||
item.get_margins = function()
|
||||
return mrgns
|
||||
end
|
||||
|
|
|
@ -6,6 +6,7 @@ local wibox = require( "wibox" )
|
|||
local checkbox = require( "radical.widgets.checkbox" )
|
||||
local fkey = require( "radical.widgets.fkey" )
|
||||
local horizontal = require( "radical.item.layout.horizontal" )
|
||||
local util = require( "awful.util" )
|
||||
local margins2 = require("radical.margins")
|
||||
|
||||
local module = {}
|
||||
|
@ -37,7 +38,7 @@ local function create_item(item,data,args)
|
|||
--Create the main item layout
|
||||
local l,la,lr = wibox.layout.fixed.vertical(),wibox.layout.align.vertical(),wibox.layout.fixed.horizontal()
|
||||
local m = wibox.layout.margin(la)
|
||||
local mrgns = margins2(m,data.item_style.margins)
|
||||
local mrgns = margins2(m,util.table.join(data.item_style.margins,data.default_item_margins))
|
||||
item.get_margins = function()
|
||||
return mrgns
|
||||
end
|
||||
|
|
|
@ -33,7 +33,7 @@ local function gen(width,height,bg_color,border_color)
|
|||
end
|
||||
|
||||
local function widget_draw(self, w, cr, width, height)
|
||||
|
||||
|
||||
local state = self._item.state or {}
|
||||
local current_state = state._current_key or ""
|
||||
if not state_cache[current_state] then
|
||||
|
|
|
@ -18,7 +18,8 @@ local function reset_margins(margins)
|
|||
end
|
||||
|
||||
local function new(widget,defaults)
|
||||
local mt = setmetatable({defaults=awful.util.table.join(defaults,{}),widget=widget,reset=reset_margins,
|
||||
local mt = nil
|
||||
mt = setmetatable({defaults=awful.util.table.join(defaults,{}),widget=widget,reset=reset_margins,
|
||||
merge = function(values)
|
||||
if values.left then
|
||||
widget:set_left(values.left)
|
||||
|
@ -34,18 +35,19 @@ local function new(widget,defaults)
|
|||
end
|
||||
end
|
||||
},{__newindex = function(tab, key,value)
|
||||
key = key:lower()
|
||||
if key == "widget" then
|
||||
rawset(tab,"widget",value)
|
||||
reset_margins(tab)
|
||||
elseif widget then
|
||||
widget["set_"..key](widget,value)
|
||||
else --TODO can't do this
|
||||
defaults[key] = value
|
||||
mt.defaults[key] = value
|
||||
end
|
||||
end
|
||||
,__index=function(table,key)
|
||||
local w = rawget(table,"widget")
|
||||
return w and w[key] or 0 --widget["get_"..key](widget)
|
||||
return w and w[key] or defaults[key] --widget["get_"..key](widget)
|
||||
end})
|
||||
|
||||
reset_margins(mt)
|
||||
|
|
Loading…
Reference in New Issue