diff --git a/bar.lua b/bar.lua index c9e580e..59f1eb4 100644 --- a/bar.lua +++ b/bar.lua @@ -125,7 +125,6 @@ local function new(args) 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 args.sub_menu_on = args.sub_menu_on or base.event.BUTTON1 local ret = base(args) diff --git a/base.lua b/base.lua index 828503b..15b81ad 100644 --- a/base.lua +++ b/base.lua @@ -455,6 +455,7 @@ local function new(args) end function data:swap(item1,item2) + if not item1 or not item2 then return end if not item1 or not item2 and item1 ~= item2 then return end local idx1,idx2 for k,v in ipairs(internal.items) do --rows @@ -477,6 +478,7 @@ local function new(args) end function data:move(item,idx) + if not item or not idx then return end local idx1 = nil for k,v in ipairs(internal.items) do --rows if item == v[1] then @@ -499,6 +501,7 @@ local function new(args) end function data:remove(item) + if not item then return end local idx1 = nil for k,v in ipairs(internal.items) do --rows if item == v[1] then @@ -513,6 +516,7 @@ local function new(args) end function data:append(item) + if not item then return end internal.items[#internal.items + 1] = item data:emit_signal("item::appended",item) end diff --git a/impl/alttab.lua b/impl/alttab.lua index f8bc040..5ed78a2 100644 --- a/impl/alttab.lua +++ b/impl/alttab.lua @@ -113,6 +113,7 @@ local function new(args) tag.viewonly(v:tags()[1]) end capi.client.focus = v + v:raise() currentMenu.visible = false end, }).client = v diff --git a/impl/tasklist/init.lua b/impl/tasklist/init.lua new file mode 100644 index 0000000..a1df5d2 --- /dev/null +++ b/impl/tasklist/init.lua @@ -0,0 +1,156 @@ +--------------------------------------------------------------------------- +-- @author Emmanuel Lepage Vallee +-- @copyright 2014 Emmanuel Lepage Vallee +-- @release devel +-- @note Based on the original tasklist.lua +-- @license GPLv2+ because of copy paste from the old tasklist.lua +--------------------------------------------------------------------------- + +local capi = {client = client} +local radical = require( "radical" ) +local tag = require( "awful.tag" ) +local beautiful = require( "beautiful" ) +local client = require( "awful.client" ) + +local sticky,urgent,instances,module = {},{},{},{} + +local function sticky_callback(c) + local val = c.sticky + sticky[c] = val and true or nil + for k,v in ipairs(instances) do + if val then + v.menu:append(v.cache[c]) + else + v.menu:remove(v.cache[c]) + end + end +end + +local function urgent_callback(c) + local val = c.urgent + urgent[c] = val and true or nil +end + +local function unmanage_callback(c) + sticky[c] = nil + urgent[c] = nil + for k,v in ipairs(instances) do + v.menu:remove(v.cache[c]) + v.cache[c] = nil + end +end + +local function new(screen) + local cache,menu = setmetatable({}, { __mode = 'k' }),radical.flexbar{select_on=radical.base.event.NEVER,fg=beautiful.fg_normal,bg_focus=beautiful.taglist_bg_image_selected2} + + function create_client_item(c) + -- If it already exist, don't waste time creating a copy + if cache[c] then + return menu:append(cache[c]) + end + + -- Too bad, let's create a new one + cache[c] = menu:add_item{text=c.name,icon=c.icon,button1=function() + capi.client.focus = c + c:raise() + end} + return cache[c] + end + + function add_client(c) + if not (c.skip_taskbar or c.hidden or c.type == "splash" or c.type == "dock" or c.type == "desktop") and c.screen == screen then + local ret = create_client_item(c) + reload_underlay(c) + if c.focus == c then + ret.selected = true + end + end + end + + -- Clear the menu and repopulate it + function load_clients(t) + if not t then return end + if t.selected and tag.getscreen(t) == screen then + menu:clear() + for k, c in ipairs(t:clients()) do + if not c.sticky then + add_client(c) + end + end + for c,_ in pairs(sticky) do + add_client(c) + end + end + end + + -- Unselect the old focussed client + function unfocus(c) + local item = cache[c] + if item and item.selected then + item.selected = false + end + end + + -- Select the newly focussed client + function focus(c) + local item = cache[c] + if item then + item.selected = true + end + end + + -- Reload and labels + function reload_underlay(c) + local udl,item = {},cache[c] + if item then + if c.ontop then + udl[#udl+1] = "ontop" + end + if client.floating.get(c) then + udl[#udl+1] = "float" + end + if c.sticky then + udl[#udl+1] = "sticky" + end + item.underlay = udl + item.widget:emit_signal("widget::updated") + end + end + + -- Add and remove clients from the tasklist + function tagged(c,t) + if t.selected and tag.getscreen(t) == screen and not c.sticky then + add_client(c) + end + end + function untagged(c,t) + if t.selected and tag.getscreen(t) == screen then + menu:remove(cache[c]) + end + end + + -- Connect to a bunch of signals + tag.attached_connect_signal(screen, "property::selected" , load_clients) + tag.attached_connect_signal(screen, "property::activated", load_clients) + capi.client.connect_signal("focus" , focus ) + capi.client.connect_signal("unfocus" , unfocus ) + capi.client.connect_signal("tagged" , tagged ) + capi.client.connect_signal("untagged" , untagged ) + capi.client.connect_signal("property::sticky" , reload_underlay ) + capi.client.connect_signal("property::ontop" , reload_underlay ) + capi.client.connect_signal("property::floating", reload_underlay ) + + instances[#instances+1] = {menu = menu, cache = cache } + + load_clients(tag.selected(screen)) + + return menu +end + +-- Global callbacks +capi.client.connect_signal("property::sticky", sticky_callback ) +capi.client.connect_signal("property::urgent", urgent_callback ) +capi.client.connect_signal("unmanage" , unmanage_callback) + +return setmetatable(module, { __call = function(_, ...) return new(...) end }) +-- kate: space-indent on; indent-width 2; replace-tabs on;