diff --git a/README.md b/README.md index 5c8c3a6..f047f6f 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ Item layouts are how widgets (icons, label, prefix) are disposed in the item local m = radical.context { style = radical.style.classic , - item_style = radical.item_style.classic , + item_style = radical.item.style.classic , layout = radical.layout.vertical } ``` diff --git a/bar.lua b/bar.lua index cfe3bc7..1e556cf 100644 --- a/bar.lua +++ b/bar.lua @@ -9,9 +9,9 @@ local util = require( "awful.util" ) local fkey = require( "radical.widgets.fkey" ) local button = require( "awful.button" ) local checkbox = require( "radical.widgets.checkbox" ) -local item_style = require( "radical.item_style.arrow_single" ) +local item_style = require( "radical.item.style.arrow_single" ) local vertical = require( "radical.layout.vertical" ) -local item_layout= require( "radical.item_layout.horizontal" ) +local item_layout= require( "radical.item.layout.horizontal" ) local capi,module = { mouse = mouse , screen = screen, keygrabber = keygrabber },{} diff --git a/base.lua b/base.lua index 07207b7..c5ad370 100644 --- a/base.lua +++ b/base.lua @@ -8,6 +8,8 @@ local util = require( "awful.util" ) local aw_key = require( "awful.key" ) local object = require( "radical.object" ) local vertical = require( "radical.layout.vertical" ) +local theme = require( "radical.theme" ) +local item_mod = require( "radical.item" ) local capi = { mouse = mouse, screen = screen , keygrabber = keygrabber, root=root, } @@ -51,56 +53,18 @@ local module = { USR9 = 109, USR10 = 110, }, - colors_by_id = {} + colors_by_id = theme.colors_by_id } - --- Do some magic to cache the highest state -local function return_data(tab, key) - return tab._real_table[key] -end -local function change_data(tab, key,value) - if not value and key == rawget(tab,"_current_key") then - -- Loop the array to find a new current_key - local win = math.huge - for k,v in pairs(tab._real_table) do - if k < win and k ~= key then - win = k - end - end - rawset(tab,"_current_key",win ~= math.huge and win or nil) - elseif value and (rawget(tab,"_current_key") or math.huge) > key then - rawset(tab,"_current_key",key) - end - tab._real_table[key] = value -end -local function init_state() - local mt = {__newindex = change_data,__index=return_data} - return setmetatable({_real_table={}},mt) -end - --- Util to help match colors to states -local theme_colors = {} -local function register_color(state_id,name,beautiful_name,allow_fallback) - theme_colors[name] = {id=state_id,beautiful_name=beautiful_name,fallback=allow_fallback} - module.colors_by_id[state_id] = name -end -local function setup_colors(data,args) - local priv = data._internal.private_data - for k,v in pairs(theme_colors) do - priv["fg_"..k] = args["fg_"..k] or beautiful["menu_fg_"..v.beautiful_name] or beautiful["fg_"..v.beautiful_name] or (v.fallback and "#ff0000") - priv["bg_"..k] = args["bg_"..k] or beautiful["menu_bg_"..v.beautiful_name] or beautiful["bg_"..v.beautiful_name] or (v.fallback and "#00ff00") - end -end -register_color(module.item_flags.DISABLED , "disabled" , "disabled" , true ) -register_color(module.item_flags.URGENT , "urgent" , "urgent" , true ) -register_color(module.item_flags.SELECTED , "focus" , "focus" , true ) -register_color(module.item_flags.PRESSED , "pressed" , "pressed" , true ) -register_color(module.item_flags.HOVERED , "hover" , "hover" , true ) -register_color(module.item_flags.USED , "used" , "used" , true ) -register_color(module.item_flags.CHECKED , "checked" , "checked" , true ) -register_color(module.item_flags.ALTERNATE , "alternate" , "alternate" , true ) -register_color(module.item_flags.HIGHLIGHT , "highlight" , "highlight" , true ) +theme.register_color(module.item_flags.DISABLED , "disabled" , "disabled" , true ) +theme.register_color(module.item_flags.URGENT , "urgent" , "urgent" , true ) +theme.register_color(module.item_flags.SELECTED , "focus" , "focus" , true ) +theme.register_color(module.item_flags.PRESSED , "pressed" , "pressed" , true ) +theme.register_color(module.item_flags.HOVERED , "hover" , "hover" , true ) +theme.register_color(module.item_flags.USED , "used" , "used" , true ) +theme.register_color(module.item_flags.CHECKED , "checked" , "checked" , true ) +theme.register_color(module.item_flags.ALTERNATE , "alternate" , "alternate" , true ) +theme.register_color(module.item_flags.HIGHLIGHT , "highlight" , "highlight" , true ) -- register_color(item_flags.HEADER , "" -- register_color(item_flags.USR1 , "" -- register_color(item_flags.USR2 , "" @@ -136,21 +100,6 @@ local function filter(data) end end -local function execute_sub_menu(data,item) - if (item._private_data.sub_menu_f or item._private_data.sub_menu_m) then - local sub_menu = item._private_data.sub_menu_m or item._private_data.sub_menu_f(data,item) - if sub_menu and sub_menu.rowcount > 0 then - sub_menu.arrow_type = module.arrow_type.NONE - sub_menu.parent_item = item - sub_menu.parent_geometry = data - sub_menu.visible = true - item._tmp_menu = sub_menu - data._tmp_menu = sub_menu - end - end -end -module._execute_sub_menu = execute_sub_menu - ------------------------------------KEYBOARD HANDLING----------------------------------- local function activateKeyboard(data) if not data then return end @@ -183,7 +132,7 @@ local function activateKeyboard(data) if (key == 'Return') and data._current_item and data._current_item.button1 then if data.sub_menu_on == module.event.BUTTON1 then - execute_sub_menu(data,data._current_item) + item_mod.execute_sub_menu(data,data._current_item) else data._current_item.button1() data.visible = false @@ -209,88 +158,8 @@ end ---------------------------------ITEM HANDLING---------------------------------- local function add_item(data,args) - local args = args or {} - local item,set_map,get_map,private_data = object({ - private_data = { - text = args.text or "" , - height = args.height or beautiful.menu_height or 30 , - width = args.width or nil , - icon = args.icon or nil , - prefix = args.prefix or "" , - suffix = args.suffix or "" , - bg = args.bg or nil , - fg = args.fg or data.fg or beautiful.menu_fg_normal or beautiful.fg_normal , - fg_focus = args.fg_focus or data.fg_focus or beautiful.menu_fg_focus or beautiful.fg_focus , - bg_focus = args.bg_focus or data.bg_focus or beautiful.menu_bg_focus or beautiful.bg_focus , - bg_prefix = args.bg_prefix or data.bg_prefix , - sub_menu_m = (args.sub_menu and type(args.sub_menu) == "table" and args.sub_menu.is_menu) and args.sub_menu or nil, - sub_menu_f = (args.sub_menu and type(args.sub_menu) == "function") and args.sub_menu or nil , - checkable = args.checkable or (args.checked ~= nil) or false , - checked = args.checked or false , - underlay = args.underlay or nil , - tooltip = args.tooltip or nil , - item_style = args.item_style or nil , - item_layout = args.item_layout or nil , - selected = false , - overlay = args.overlay or data.overlay or nil , - state = init_state() , - }, - force_private = { - visible = true, - selected = true, - }, - get_map = { - y = function() return (args.y and args.y >= 0) and args.y or data.height - (data.margins.top or data.border_width) - data.item_height end, --Hack around missing :fit call for last item - }, - autogen_getmap = true, - autogen_setmap = true, - autogen_signals = true, - }) - item._private_data = private_data - item._internal = {get_map=get_map,set_map=set_map} - - for i=1,10 do - item["button"..i] = args["button"..i] - end - - if data.max_items ~= nil and data.rowcount >= data.max_items then-- and (data._start_at or 0) - item._hidden = true - end - - -- Use _internal to avoid the radical.object trigger - data._internal.visible_item_count = (data._internal.visible_item_count or 0) + 1 - item._internal.f_key = data._internal.visible_item_count - - -- Need to be done before painting - data._internal.items[#data._internal.items+1] = {} - data._internal.items[#data._internal.items][1] = item + local item = item_mod(data,args) data._internal.setup_item(data,item,args) - - -- Setters - set_map.selected = function(value) - private_data.selected = value - if value == false then - data.item_style(data,item,{}) - return - end - local current_item = data._current_item - if current_item and current_item ~= item then - current_item.state[module.item_flags.SELECTED] = nil - if current_item._tmp_menu then - current_item._tmp_menu.visible = false - current_item._tmp_menu = nil - data._tmp_menu = nil - end - data.item_style(data,current_item,{}) - current_item.selected = false - end - if data.sub_menu_on == module.event.SELECTED and current_item ~= item then - execute_sub_menu(data,item) - end - item.state[module.item_flags.SELECTED] = true - data.item_style(data,item,{}) - data._current_item = item - end if args.selected == true then item.selected = true end @@ -389,7 +258,7 @@ local function new(args) layout = args.layout or nil, screen = args.screen or nil, style = args.style or nil, - item_style = args.item_style or require("radical.item_style.basic"), + item_style = args.item_style or require("radical.item.style.basic"), filter = args.filter ~= false, show_filter = args.show_filter or false, filter_string = args.filter_string or "", @@ -433,7 +302,7 @@ local function new(args) }) internal.get_map,internal.set_map,internal.private_data = get_map,set_map,private_data data.add_item,data.add_widget,data.add_embeded_menu,data._internal,data.add_key_binding = add_item,add_widget,add_embeded_menu,internal,add_key_binding - setup_colors(data,args) + theme.setup_colors(data,args) set_map.parent_geometry = function(value) private_data.parent_geometry = value if data._internal.get_direction then diff --git a/context.lua b/context.lua index 39d4c61..2f1b130 100644 --- a/context.lua +++ b/context.lua @@ -13,6 +13,7 @@ local util = require( "awful.util" ) local layout = require( "radical.layout" ) local checkbox = require( "radical.widgets.checkbox" ) local arrow_style = require( "radical.style.arrow" ) +local item_mod = require("radical.item") local capi,module = { mouse = mouse , screen = screen, keygrabber = keygrabber },{} @@ -184,7 +185,7 @@ local function setup_buttons(data,item,args) -- Click to open sub_menu if not buttons[1] and data.sub_menu_on == base.event.BUTTON1 then - buttons[1] = function() base._execute_sub_menu(data,item) end + buttons[1] = function() item_mod.execute_sub_menu(data,item) end end --Hide on right click diff --git a/impl/taglist/init.lua b/impl/taglist/init.lua index 1bc32b7..b0f20c9 100644 --- a/impl/taglist/init.lua +++ b/impl/taglist/init.lua @@ -107,7 +107,7 @@ local function new(s) select_on = radical.base.event.NEVER, fg = beautiful.fg_normal, bg_focus = beautiful.taglist_bg_image_selected2 or beautiful.bg_focus, - item_style = radical.item_style.arrow_prefix, + item_style = radical.item.style.arrow_prefix, bg_hover = beautiful.menu_bg_focus } diff --git a/impl/tasklist/client_menu.lua b/impl/tasklist/client_menu.lua index 0c62ce4..3fb178d 100644 --- a/impl/tasklist/client_menu.lua +++ b/impl/tasklist/client_menu.lua @@ -39,40 +39,40 @@ local function singalMenu() return sigMenu end sigMenu = radical.context{max_items=10} - sigterm = sigMenu:add_item({text="SIGTERM" , button1 = function() util.spawn("kill -s TERM "..module.client.pid);sigMenu.visible = false end,underlay="15"}) - sigkill = sigMenu:add_item({text="SIGKILL" , button1 = function() util.spawn("kill -s KILL "..module.client.pid);sigMenu.visible = false end,underlay="9"}) - sigint = sigMenu:add_item({text="SIGINT" , button1 = function() util.spawn("kill -s INT "..module.client.pid);sigMenu.visible = false end,underlay="2"}) - sigquit = sigMenu:add_item({text="SIGQUIT" , button1 = function() util.spawn("kill -s QUIT "..module.client.pid);sigMenu.visible = false end,underlay="3"}) + sigterm = sigMenu:add_item({text="SIGTERM" , button1 = function() util.spawn("kill -s TERM "..module.client.pid);mainMenu.visible = false end,underlay="15"}) + sigkill = sigMenu:add_item({text="SIGKILL" , button1 = function() util.spawn("kill -s KILL "..module.client.pid);mainMenu.visible = false end,underlay="9"}) + sigint = sigMenu:add_item({text="SIGINT" , button1 = function() util.spawn("kill -s INT "..module.client.pid);mainMenu.visible = false end,underlay="2"}) + sigquit = sigMenu:add_item({text="SIGQUIT" , button1 = function() util.spawn("kill -s QUIT "..module.client.pid);mainMenu.visible = false end,underlay="3"}) -- sigMenu:add_widget(radical.widgets.separator()) - sig0 = sigMenu:add_item({text="SIG0" , button1 = function() util.spawn("kill -s 0 "..module.client.pid);sigMenu.visible = false end,underlay=nil}) - sigalrm = sigMenu:add_item({text="SIGALRM" , button1 = function() util.spawn("kill -s ALRM "..module.client.pid);sigMenu.visible = false end,underlay="14"}) - sighup = sigMenu:add_item({text="SIGHUP" , button1 = function() util.spawn("kill -s HUP "..module.client.pid);sigMenu.visible = false end,underlay="1",tooltip="sdfsdfsdf"}) - sigpipe = sigMenu:add_item({text="SIGPIPE" , button1 = function() util.spawn("kill -s PIPE "..module.client.pid);sigMenu.visible = false end,underlay="13"}) - sigpoll = sigMenu:add_item({text="SIGPOLL" , button1 = function() util.spawn("kill -s POLL "..module.client.pid);sigMenu.visible = false end,underlay=nil}) - sigprof = sigMenu:add_item({text="SIGPROF" , button1 = function() util.spawn("kill -s PROF "..module.client.pid);sigMenu.visible = false end,underlay="27"}) - sigusr1 = sigMenu:add_item({text="SIGUSR1" , button1 = function() util.spawn("kill -s USR1 "..module.client.pid);sigMenu.visible = false end,underlay="10"}) - sigusr2 = sigMenu:add_item({text="SIGUSR2" , button1 = function() util.spawn("kill -s USR2 "..module.client.pid);sigMenu.visible = false end,underlay="12"}) - sigsigvtalrm = sigMenu:add_item({text="SIGVTALRM" , button1 = function() util.spawn("kill -s VTALRM "..module.client.pid);sigMenu.visible = false end,underlay=nil}) - sigstkflt = sigMenu:add_item({text="SIGSTKFLT" , button1 = function() util.spawn("kill -s STKFLT "..module.client.pid);sigMenu.visible = false end,underlay=nil}) - sigpwr = sigMenu:add_item({text="SIGPWR" , button1 = function() util.spawn("kill -s PWR "..module.client.pid);sigMenu.visible = false end,underlay=nil}) - sigwinch = sigMenu:add_item({text="SIGWINCH" , button1 = function() util.spawn("kill -s WINCH "..module.client.pid);sigMenu.visible = false end,underlay=nil}) - sigchld = sigMenu:add_item({text="SIGCHLD" , button1 = function() util.spawn("kill -s CHLD "..module.client.pid);sigMenu.visible = false end,underlay="17"}) - sigurg = sigMenu:add_item({text="SIGURG" , button1 = function() util.spawn("kill -s URG "..module.client.pid);sigMenu.visible = false end,underlay=nil}) - sigtstp = sigMenu:add_item({text="SIGTSTP" , button1 = function() util.spawn("kill -s TSTP "..module.client.pid);sigMenu.visible = false end,underlay=nil}) - sigttin = sigMenu:add_item({text="SIGTTIN" , button1 = function() util.spawn("kill -s TTIN "..module.client.pid);sigMenu.visible = false end,underlay="21"}) - sigttou = sigMenu:add_item({text="SIGTTOU" , button1 = function() util.spawn("kill -s TTOU "..module.client.pid);sigMenu.visible = false end,underlay="22"}) - sigstop = sigMenu:add_item({text="SIGSTOP" , button1 = function() util.spawn("kill -s STOP "..module.client.pid);sigMenu.visible = false end,underlay="17"}) - sigcont = sigMenu:add_item({text="SIGCONT" , button1 = function() util.spawn("kill -s CONT "..module.client.pid);sigMenu.visible = false end,underlay="18"}) - sigabrt = sigMenu:add_item({text="SIGABRT" , button1 = function() util.spawn("kill -s ABRT "..module.client.pid);sigMenu.visible = false end,underlay="6"}) - sigfpe = sigMenu:add_item({text="SIGFPE" , button1 = function() util.spawn("kill -s FPE "..module.client.pid);sigMenu.visible = false end,underlay="8"}) - sigill = sigMenu:add_item({text="SIGILL" , button1 = function() util.spawn("kill -s ILL "..module.client.pid);sigMenu.visible = false end,underlay="4"}) - sigsegv = sigMenu:add_item({text="SIGSEGV" , button1 = function() util.spawn("kill -s SEGV "..module.client.pid);sigMenu.visible = false end,underlay="11"}) - sigtrap = sigMenu:add_item({text="SIGTRAP" , button1 = function() util.spawn("kill -s TRAP "..module.client.pid);sigMenu.visible = false end,underlay="5"}) - sigsys = sigMenu:add_item({text="SIGSYS" , button1 = function() util.spawn("kill -s SYS "..module.client.pid);sigMenu.visible = false end,underlay="12"}) - sigemt = sigMenu:add_item({text="SIGEMT" , button1 = function() util.spawn("kill -s EMT "..module.client.pid);sigMenu.visible = false end,underlay=nil}) - sigbus = sigMenu:add_item({text="SIGBUS" , button1 = function() util.spawn("kill -s BUS "..module.client.pid);sigMenu.visible = false end,underlay="7"}) - sigxcpu = sigMenu:add_item({text="SIGXCPU" , button1 = function() util.spawn("kill -s XCPU "..module.client.pid);sigMenu.visible = false end,underlay=nil}) - sigxfsz = sigMenu:add_item({text="SIGXFSZ" , button1 = function() util.spawn("kill -s XFSZ "..module.client.pid);sigMenu.visible = false end,underlay=nil}) + sig0 = sigMenu:add_item({text="SIG0" , button1 = function() util.spawn("kill -s 0 "..module.client.pid);mainMenu.visible = false end,underlay=nil}) + sigalrm = sigMenu:add_item({text="SIGALRM" , button1 = function() util.spawn("kill -s ALRM "..module.client.pid);mainMenu.visible = false end,underlay="14"}) + sighup = sigMenu:add_item({text="SIGHUP" , button1 = function() util.spawn("kill -s HUP "..module.client.pid);mainMenu.visible = false end,underlay="1",tooltip="sdfsdfsdf"}) + sigpipe = sigMenu:add_item({text="SIGPIPE" , button1 = function() util.spawn("kill -s PIPE "..module.client.pid);mainMenu.visible = false end,underlay="13"}) + sigpoll = sigMenu:add_item({text="SIGPOLL" , button1 = function() util.spawn("kill -s POLL "..module.client.pid);mainMenu.visible = false end,underlay=nil}) + sigprof = sigMenu:add_item({text="SIGPROF" , button1 = function() util.spawn("kill -s PROF "..module.client.pid);mainMenu.visible = false end,underlay="27"}) + sigusr1 = sigMenu:add_item({text="SIGUSR1" , button1 = function() util.spawn("kill -s USR1 "..module.client.pid);mainMenu.visible = false end,underlay="10"}) + sigusr2 = sigMenu:add_item({text="SIGUSR2" , button1 = function() util.spawn("kill -s USR2 "..module.client.pid);mainMenu.visible = false end,underlay="12"}) + sigsigvtalrm = sigMenu:add_item({text="SIGVTALRM" , button1 = function() util.spawn("kill -s VTALRM "..module.client.pid);mainMenu.visible = false end,underlay=nil}) + sigstkflt = sigMenu:add_item({text="SIGSTKFLT" , button1 = function() util.spawn("kill -s STKFLT "..module.client.pid);mainMenu.visible = false end,underlay=nil}) + sigpwr = sigMenu:add_item({text="SIGPWR" , button1 = function() util.spawn("kill -s PWR "..module.client.pid);mainMenu.visible = false end,underlay=nil}) + sigwinch = sigMenu:add_item({text="SIGWINCH" , button1 = function() util.spawn("kill -s WINCH "..module.client.pid);mainMenu.visible = false end,underlay=nil}) + sigchld = sigMenu:add_item({text="SIGCHLD" , button1 = function() util.spawn("kill -s CHLD "..module.client.pid);mainMenu.visible = false end,underlay="17"}) + sigurg = sigMenu:add_item({text="SIGURG" , button1 = function() util.spawn("kill -s URG "..module.client.pid);mainMenu.visible = false end,underlay=nil}) + sigtstp = sigMenu:add_item({text="SIGTSTP" , button1 = function() util.spawn("kill -s TSTP "..module.client.pid);mainMenu.visible = false end,underlay=nil}) + sigttin = sigMenu:add_item({text="SIGTTIN" , button1 = function() util.spawn("kill -s TTIN "..module.client.pid);mainMenu.visible = false end,underlay="21"}) + sigttou = sigMenu:add_item({text="SIGTTOU" , button1 = function() util.spawn("kill -s TTOU "..module.client.pid);mainMenu.visible = false end,underlay="22"}) + sigstop = sigMenu:add_item({text="SIGSTOP" , button1 = function() util.spawn("kill -s STOP "..module.client.pid);mainMenu.visible = false end,underlay="17"}) + sigcont = sigMenu:add_item({text="SIGCONT" , button1 = function() util.spawn("kill -s CONT "..module.client.pid);mainMenu.visible = false end,underlay="18"}) + sigabrt = sigMenu:add_item({text="SIGABRT" , button1 = function() util.spawn("kill -s ABRT "..module.client.pid);mainMenu.visible = false end,underlay="6"}) + sigfpe = sigMenu:add_item({text="SIGFPE" , button1 = function() util.spawn("kill -s FPE "..module.client.pid);mainMenu.visible = false end,underlay="8"}) + sigill = sigMenu:add_item({text="SIGILL" , button1 = function() util.spawn("kill -s ILL "..module.client.pid);mainMenu.visible = false end,underlay="4"}) + sigsegv = sigMenu:add_item({text="SIGSEGV" , button1 = function() util.spawn("kill -s SEGV "..module.client.pid);mainMenu.visible = false end,underlay="11"}) + sigtrap = sigMenu:add_item({text="SIGTRAP" , button1 = function() util.spawn("kill -s TRAP "..module.client.pid);mainMenu.visible = false end,underlay="5"}) + sigsys = sigMenu:add_item({text="SIGSYS" , button1 = function() util.spawn("kill -s SYS "..module.client.pid);mainMenu.visible = false end,underlay="12"}) + sigemt = sigMenu:add_item({text="SIGEMT" , button1 = function() util.spawn("kill -s EMT "..module.client.pid);mainMenu.visible = false end,underlay=nil}) + sigbus = sigMenu:add_item({text="SIGBUS" , button1 = function() util.spawn("kill -s BUS "..module.client.pid);mainMenu.visible = false end,underlay="7"}) + sigxcpu = sigMenu:add_item({text="SIGXCPU" , button1 = function() util.spawn("kill -s XCPU "..module.client.pid);mainMenu.visible = false end,underlay=nil}) + sigxfsz = sigMenu:add_item({text="SIGXFSZ" , button1 = function() util.spawn("kill -s XFSZ "..module.client.pid);mainMenu.visible = false end,underlay=nil}) return sigMenu end diff --git a/impl/tasklist/init.lua b/impl/tasklist/init.lua index 277b868..7a5c558 100644 --- a/impl/tasklist/init.lua +++ b/impl/tasklist/init.lua @@ -65,6 +65,10 @@ end local function urgent_callback(c) local val = c.urgent urgent[c] = val and true or nil + local item = instances[c.screen].cache[c] + if item then + item.state[radical.base.item_flags.URGENT] = val or nil + end end local function unmanage_callback(c) diff --git a/init.lua b/init.lua index 91c3ee4..9ac7a14 100644 --- a/init.lua +++ b/init.lua @@ -42,22 +42,21 @@ base.make_widget = function(...) return ret end -local bar = require( "radical.bar" ) +local bar = require( "radical.bar" ) return { - layout = require( "radical.layout" ), - object = require( "radical.object" ), - base = require( "radical.base" ), - radial = require( "radical.radial" ), - context = require( "radical.context" ), - embed = require( "radical.embed" ), - box = require( "radical.box" ), - style = require( "radical.style" ), - item_style = require( "radical.item_style" ), - widgets = require( "radical.widgets" ), - item_layout = require( "radical.item_layout"), - bar = bar, - flexbar = bar.flex, - tooltip = tooltip + layout = require( "radical.layout" ), + object = require( "radical.object" ), + base = require( "radical.base" ), + radial = require( "radical.radial" ), + context = require( "radical.context" ), + embed = require( "radical.embed" ), + box = require( "radical.box" ), + style = require( "radical.style" ), + widgets = require( "radical.widgets" ), + item = require( "radical.item" ), + bar = bar, + flexbar = bar.flex, + tooltip = tooltip } -- kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/item/init.lua b/item/init.lua index e69de29..7ba30d7 100644 --- a/item/init.lua +++ b/item/init.lua @@ -0,0 +1,162 @@ +local type = type +local beautiful = require("beautiful") +local theme = require("radical.theme") +local object = require("radical.object") + +local module = { + -- style = require("radical.item.style"), + -- layout = require("radical.item.layout"), + arrow_type = { + NONE = 0, + PRETTY = 1, + CENTERED = 2, + }, + event ={ + NEVER = 0, + BUTTON1 = 1, + BUTTON2 = 2, + BUTTON3 = 3, + SELECTED = 100, + HOVER = 1000, + LEAVE = 1001, + }, + item_flags = { + NONE = 999999 , + DISABLED = 1 , -- Cannot be interacted with + URGENT = 2 , -- Need attention + SELECTED = 3 , -- Single item selected [[FOCUS]] + PRESSED = 4 , -- Mouse pressed + HOVERED = 5 , -- Mouse hover + USED = 6 , -- Common flag + CHECKED = 7 , -- When checkbox isn't enough + ALTERNATE = 8 , + HIGHLIGHT = 9 , + HEADER = 10, + + -- Implementation defined flags + USR1 = 101, + USR2 = 102, + USR3 = 103, + USR4 = 104, + USR5 = 105, + USR6 = 106, + USR7 = 107, + USR8 = 108, + USR9 = 109, + USR10 = 110, + }, +} + +local function load_async(tab,key) + print("here",key) + if key == "style" then + module.style = require("radical.item.style") + return module.style + elseif key == "layout" then + module.layout = require("radical.item.layout") + return module.layout + end + return rawget(module,key) +end + +function module.execute_sub_menu(data,item) + if (item._private_data.sub_menu_f or item._private_data.sub_menu_m) then + local sub_menu = item._private_data.sub_menu_m or item._private_data.sub_menu_f(data,item) + if sub_menu and sub_menu.rowcount > 0 then + sub_menu.arrow_type = module.arrow_type.NONE + sub_menu.parent_item = item + sub_menu.parent_geometry = data + sub_menu.visible = true + item._tmp_menu = sub_menu + data._tmp_menu = sub_menu + end + end +end + +local function new_item(data,args) + local args = args or {} + local item,set_map,get_map,private_data = object({ + private_data = { + text = args.text or "" , + height = args.height or beautiful.menu_height or 30 , + width = args.width or nil , + icon = args.icon or nil , + prefix = args.prefix or "" , + suffix = args.suffix or "" , + bg = args.bg or nil , + fg = args.fg or data.fg or beautiful.menu_fg_normal or beautiful.fg_normal , + fg_focus = args.fg_focus or data.fg_focus or beautiful.menu_fg_focus or beautiful.fg_focus , + bg_focus = args.bg_focus or data.bg_focus or beautiful.menu_bg_focus or beautiful.bg_focus , + bg_prefix = args.bg_prefix or data.bg_prefix , + sub_menu_m = (args.sub_menu and type(args.sub_menu) == "table" and args.sub_menu.is_menu) and args.sub_menu or nil, + sub_menu_f = (args.sub_menu and type(args.sub_menu) == "function") and args.sub_menu or nil , + checkable = args.checkable or (args.checked ~= nil) or false , + checked = args.checked or false , + underlay = args.underlay or nil , + tooltip = args.tooltip or nil , + item_style = args.item_style or nil , + item_layout = args.item_layout or nil , + selected = false , + overlay = args.overlay or data.overlay or nil , + state = theme.init_state() , + }, + force_private = { + visible = true, + selected = true, + }, + get_map = { + y = function() return (args.y and args.y >= 0) and args.y or data.height - (data.margins.top or data.border_width) - data.item_height end, --Hack around missing :fit call for last item + }, + autogen_getmap = true, + autogen_setmap = true, + autogen_signals = true, + }) + item._private_data = private_data + item._internal = {get_map=get_map,set_map=set_map} + + for i=1,10 do + item["button"..i] = args["button"..i] + end + + if data.max_items ~= nil and data.rowcount >= data.max_items then-- and (data._start_at or 0) + item._hidden = true + end + + -- Use _internal to avoid the radical.object trigger + data._internal.visible_item_count = (data._internal.visible_item_count or 0) + 1 + item._internal.f_key = data._internal.visible_item_count + + -- Need to be done before painting + data._internal.items[#data._internal.items+1] = {} + data._internal.items[#data._internal.items][1] = item + + -- Setters + set_map.selected = function(value) + private_data.selected = value + if value == false then + data.item_style(data,item,{}) + return + end + local current_item = data._current_item + if current_item and current_item ~= item then + current_item.state[module.item_flags.SELECTED] = nil + if current_item._tmp_menu then + current_item._tmp_menu.visible = false + current_item._tmp_menu = nil + data._tmp_menu = nil + end + data.item_style(data,current_item,{}) + current_item.selected = false + end + if data.sub_menu_on == module.event.SELECTED and current_item ~= item then + module.execute_sub_menu(data,item) + end + item.state[module.item_flags.SELECTED] = true + data.item_style(data,item,{}) + data._current_item = item + end + return item +end + +return setmetatable(module, { __call = function(_, ...) return new_item(...) end, __index=load_async}) +-- kate: space-indent on; indent-width 2; replace-tabs on; \ No newline at end of file diff --git a/item_layout/centerred.lua b/item/layout/centerred.lua similarity index 95% rename from item_layout/centerred.lua rename to item/layout/centerred.lua index fbf3be8..990f89b 100644 --- a/item_layout/centerred.lua +++ b/item/layout/centerred.lua @@ -5,7 +5,7 @@ local cairo = require( "lgi" ).cairo local wibox = require( "wibox" ) local checkbox = require( "radical.widgets.checkbox" ) local fkey = require( "radical.widgets.fkey" ) -local horizontal = require( "radical.item_layout.horizontal" ) +local horizontal = require( "radical.item.layout.horizontal" ) local module = {} diff --git a/item_layout/horizontal.lua b/item/layout/horizontal.lua similarity index 100% rename from item_layout/horizontal.lua rename to item/layout/horizontal.lua diff --git a/item_layout/icon.lua b/item/layout/icon.lua similarity index 98% rename from item_layout/icon.lua rename to item/layout/icon.lua index 590e904..07c26fa 100644 --- a/item_layout/icon.lua +++ b/item/layout/icon.lua @@ -5,7 +5,7 @@ local cairo = require( "lgi" ).cairo local wibox = require( "wibox" ) local checkbox = require( "radical.widgets.checkbox" ) local fkey = require( "radical.widgets.fkey" ) -local horizontal = require( "radical.item_layout.horizontal" ) +local horizontal = require( "radical.item.layout.horizontal" ) local module = {} diff --git a/item/layout/init.lua b/item/layout/init.lua new file mode 100644 index 0000000..ae52f07 --- /dev/null +++ b/item/layout/init.lua @@ -0,0 +1,5 @@ +return { + icon = require( "radical.item.layout.icon" ), + horizontal = require( "radical.item.layout.horizontal" ), + centerred = require( "radical.item.layout.centerred" ), +} \ No newline at end of file diff --git a/item_style/arrow_alt.lua b/item/style/arrow_alt.lua similarity index 100% rename from item_style/arrow_alt.lua rename to item/style/arrow_alt.lua diff --git a/item_style/arrow_prefix.lua b/item/style/arrow_prefix.lua similarity index 98% rename from item_style/arrow_prefix.lua rename to item/style/arrow_prefix.lua index f3af0dd..08269c9 100644 --- a/item_style/arrow_prefix.lua +++ b/item/style/arrow_prefix.lua @@ -4,7 +4,7 @@ local beautiful = require("beautiful" ) local color = require("gears.color" ) local cairo = require("lgi" ).cairo local wibox = require("wibox" ) -local arrow_alt = require("radical.item_style.arrow_alt") +local arrow_alt = require("radical.item.style.arrow_alt") local module = { margins = { diff --git a/item_style/arrow_single.lua b/item/style/arrow_single.lua similarity index 96% rename from item_style/arrow_single.lua rename to item/style/arrow_single.lua index 6bb5181..aa14268 100644 --- a/item_style/arrow_single.lua +++ b/item/style/arrow_single.lua @@ -4,7 +4,7 @@ local beautiful = require("beautiful" ) local color = require("gears.color" ) local cairo = require("lgi" ).cairo local wibox = require("wibox" ) -local arrow_alt = require("radical.item_style.arrow_alt") +local arrow_alt = require("radical.item.style.arrow_alt") local module = { margins = { diff --git a/item_style/basic.lua b/item/style/basic.lua similarity index 100% rename from item_style/basic.lua rename to item/style/basic.lua diff --git a/item_style/classic.lua b/item/style/classic.lua similarity index 100% rename from item_style/classic.lua rename to item/style/classic.lua diff --git a/item/style/init.lua b/item/style/init.lua new file mode 100644 index 0000000..91c7182 --- /dev/null +++ b/item/style/init.lua @@ -0,0 +1,8 @@ +return { + 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" ), + arrow_prefix = require("radical.item.style.arrow_prefix" ), + arrow_single = require("radical.item.style.arrow_single" ), +} \ No newline at end of file diff --git a/item_style/rounded.lua b/item/style/rounded.lua similarity index 100% rename from item_style/rounded.lua rename to item/style/rounded.lua diff --git a/item_layout/init.lua b/item_layout/init.lua deleted file mode 100644 index 3c2e0b9..0000000 --- a/item_layout/init.lua +++ /dev/null @@ -1,5 +0,0 @@ -return { - icon = require( "radical.item_layout.icon" ), - horizontal = require( "radical.item_layout.horizontal" ), - centerred = require( "radical.item_layout.centerred" ), -} \ No newline at end of file diff --git a/item_style/init.lua b/item_style/init.lua deleted file mode 100644 index 2b1af1a..0000000 --- a/item_style/init.lua +++ /dev/null @@ -1,8 +0,0 @@ -return { - 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" ), - arrow_prefix = require("radical.item_style.arrow_prefix" ), - arrow_single = require("radical.item_style.arrow_single" ), -} \ No newline at end of file diff --git a/layout/horizontal.lua b/layout/horizontal.lua index 6d82d90..5959045 100644 --- a/layout/horizontal.lua +++ b/layout/horizontal.lua @@ -5,7 +5,7 @@ local util = require( "awful.util" ) local button = require( "awful.button" ) local checkbox = require( "radical.widgets.checkbox" ) local wibox = require( "wibox" ) -local item_layout = require("radical.item_layout.icon") +local item_layout = require("radical.item.layout.icon") local base = nil local module = {} diff --git a/layout/vertical.lua b/layout/vertical.lua index 50a0539..bb090a2 100644 --- a/layout/vertical.lua +++ b/layout/vertical.lua @@ -5,7 +5,7 @@ local filter = require( "radical.widgets.filter" ) local wibox = require( "wibox" ) local cairo = require( "lgi" ).cairo local base = nil -local horizontal_item_layout= require( "radical.item_layout.horizontal" ) +local horizontal_item_layout= require( "radical.item.layout.horizontal" ) local module = {} diff --git a/theme/init.lua b/theme/init.lua new file mode 100644 index 0000000..d7c68f2 --- /dev/null +++ b/theme/init.lua @@ -0,0 +1,48 @@ +local math = math +local beautiful = require( "beautiful" ) + +local module = { + colors_by_id = {} +} + +-- Do some magic to cache the highest state +local function return_data(tab, key) + return tab._real_table[key] +end +local function change_data(tab, key,value) + if not value and key == rawget(tab,"_current_key") then + -- Loop the array to find a new current_key + local win = math.huge + for k,v in pairs(tab._real_table) do + if k < win and k ~= key then + win = k + end + end + rawset(tab,"_current_key",win ~= math.huge and win or nil) + elseif value and (rawget(tab,"_current_key") or math.huge) > key then + rawset(tab,"_current_key",key) + end + tab._real_table[key] = value +end +function module.init_state() + local mt = {__newindex = change_data,__index=return_data} + return setmetatable({_real_table={}},mt) +end + +-- Util to help match colors to states +local theme_colors = {} +function module.register_color(state_id,name,beautiful_name,allow_fallback) + theme_colors[name] = {id=state_id,beautiful_name=beautiful_name,fallback=allow_fallback} + module.colors_by_id[state_id] = name +end +function module.setup_colors(data,args) + local priv = data._internal.private_data + for k,v in pairs(theme_colors) do + priv["fg_"..k] = args["fg_"..k] or beautiful["menu_fg_"..v.beautiful_name] or beautiful["fg_"..v.beautiful_name] or (v.fallback and "#ff0000") + priv["bg_"..k] = args["bg_"..k] or beautiful["menu_bg_"..v.beautiful_name] or beautiful["bg_"..v.beautiful_name] or (v.fallback and "#00ff00") + end +end + + +return setmetatable(module, { __call = function(_, ...) return new(...) end }) +-- kate: space-indent on; indent-width 2; replace-tabs on; \ No newline at end of file