2014-02-08 06:52:42 +01:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Emmanuel Lepage Vallee <elv1313@gmail.com>
|
|
|
|
-- @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}
|
2014-02-15 05:35:53 +01:00
|
|
|
local rawset = rawset
|
2014-02-08 06:52:42 +01:00
|
|
|
local radical = require( "radical" )
|
|
|
|
local tag = require( "awful.tag" )
|
|
|
|
local beautiful = require( "beautiful" )
|
2014-02-19 04:19:38 +01:00
|
|
|
local client = require( "awful.client" )
|
2014-02-15 05:35:53 +01:00
|
|
|
local wibox = require( "wibox" )
|
2014-02-18 06:19:44 +01:00
|
|
|
local client_menu = require("radical.impl.tasklist.client_menu")
|
2014-02-08 06:52:42 +01:00
|
|
|
|
|
|
|
local sticky,urgent,instances,module = {},{},{},{}
|
|
|
|
|
2014-02-17 07:11:35 +01:00
|
|
|
-- Default button implementation
|
|
|
|
module.buttons = {
|
|
|
|
[1] = function (c)
|
2014-02-19 04:19:38 +01:00
|
|
|
if c == capi.client.focus then
|
2014-02-17 07:11:35 +01:00
|
|
|
c.minimized = true
|
|
|
|
else
|
|
|
|
-- Without this, the following
|
|
|
|
-- :isvisible() makes no sense
|
|
|
|
c.minimized = false
|
|
|
|
if not c:isvisible() then
|
|
|
|
tag.viewonly(c:tags()[1])
|
|
|
|
end
|
|
|
|
-- This will also un-minimize
|
|
|
|
-- the client, if needed
|
2014-02-19 04:19:38 +01:00
|
|
|
capi.client.focus = c
|
2014-02-17 07:11:35 +01:00
|
|
|
c:raise()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
[3] = function(c)
|
2014-02-18 06:19:44 +01:00
|
|
|
client_menu.client = c
|
|
|
|
local menu = client_menu()
|
|
|
|
menu.visible = not menu.visible
|
2014-02-17 07:11:35 +01:00
|
|
|
end,
|
|
|
|
[4] = function ()
|
|
|
|
client.focus.byidx(1)
|
|
|
|
if client.focus then client.focus:raise() end
|
|
|
|
end,
|
|
|
|
[5] = function ()
|
|
|
|
client.focus.byidx(-1)
|
2014-02-19 04:19:38 +01:00
|
|
|
if capi.client.focus then client.focus:raise() end
|
2014-02-17 07:11:35 +01:00
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2014-02-08 06:52:42 +01:00
|
|
|
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
|
2014-02-23 05:59:03 +01:00
|
|
|
local item = instances[c.screen].cache[c]
|
|
|
|
if item then
|
|
|
|
item.state[radical.base.item_flags.URGENT] = val or nil
|
|
|
|
end
|
2014-02-08 06:52:42 +01:00
|
|
|
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
|
|
|
|
|
2014-02-08 07:31:45 +01:00
|
|
|
-- Reload <float> <ontop> and <sticky> labels
|
|
|
|
local function reload_underlay(c)
|
|
|
|
local cache = instances[c.screen].cache
|
|
|
|
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"
|
2014-02-08 06:52:42 +01:00
|
|
|
end
|
2014-02-08 07:31:45 +01:00
|
|
|
item.underlay = udl
|
|
|
|
item.widget:emit_signal("widget::updated")
|
|
|
|
end
|
|
|
|
end
|
2014-02-08 06:52:42 +01:00
|
|
|
|
2014-02-09 09:04:02 +01:00
|
|
|
-- Reload title and icon
|
|
|
|
local function reload_content(c,b,a)
|
|
|
|
local cache = instances[c.screen].cache
|
|
|
|
local item = cache[c]
|
|
|
|
if item then
|
2014-03-02 22:29:07 +01:00
|
|
|
item.text = c.name or "N/A"
|
2014-02-09 09:04:02 +01:00
|
|
|
item.icon = c.icon
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-08 07:31:45 +01:00
|
|
|
local function create_client_item(c,screen)
|
|
|
|
local cache = instances[screen].cache
|
|
|
|
local menu = instances[screen].menu
|
|
|
|
-- If it already exist, don't waste time creating a copy
|
|
|
|
if cache[c] then
|
|
|
|
return menu:append(cache[c])
|
2014-02-08 06:52:42 +01:00
|
|
|
end
|
|
|
|
|
2014-02-08 07:31:45 +01:00
|
|
|
-- Too bad, let's create a new one
|
2014-02-17 07:11:35 +01:00
|
|
|
local item = menu:add_item{text=c.name,icon=c.icon}
|
|
|
|
item.client = c
|
|
|
|
cache[c] = item
|
|
|
|
return item
|
2014-02-08 07:31:45 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local function add_client(c,screen)
|
|
|
|
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,screen)
|
|
|
|
reload_underlay(c)
|
|
|
|
if c.focus == c then
|
|
|
|
ret.selected = true
|
2014-02-08 06:52:42 +01:00
|
|
|
end
|
|
|
|
end
|
2014-02-08 07:31:45 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Unselect the old focussed client
|
|
|
|
local function unfocus(c)
|
|
|
|
local cache = instances[c.screen].cache
|
|
|
|
local item = cache[c]
|
|
|
|
if item and item.selected then
|
|
|
|
item.selected = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Select the newly focussed client
|
|
|
|
local function focus(c)
|
|
|
|
local cache = instances[c.screen].cache
|
|
|
|
local item = cache[c]
|
|
|
|
if item then
|
|
|
|
item.selected = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function new(screen)
|
2014-02-09 06:54:59 +01:00
|
|
|
local cache,menu = setmetatable({}, { __mode = 'k' }),radical.flexbar {
|
|
|
|
select_on=radical.base.event.NEVER,
|
|
|
|
fg = beautiful.fg_normal,
|
2014-03-02 22:29:07 +01:00
|
|
|
bg_focus = beautiful.taglist_bg_image_selected2,
|
|
|
|
bg_urgent = beautiful.taglist_bg_image_urgent2,
|
2014-02-12 03:38:05 +01:00
|
|
|
bg_hover = beautiful.menu_bg_focus,
|
2014-02-13 05:09:55 +01:00
|
|
|
disable_markup = true,
|
2014-03-12 05:31:50 +01:00
|
|
|
underlay_style = radical.widgets.underlay.draw_arrow,
|
2014-02-13 05:09:55 +01:00
|
|
|
overlay = function(data,item,cd,w,h)
|
2014-02-16 03:57:07 +01:00
|
|
|
-- print("foo!")
|
2014-02-20 04:09:19 +01:00
|
|
|
end,
|
|
|
|
icon_transformation = beautiful.tasklist_icon_transformation
|
2014-02-09 06:54:59 +01:00
|
|
|
}
|
2014-02-08 06:52:42 +01:00
|
|
|
|
|
|
|
-- Clear the menu and repopulate it
|
2014-02-08 07:31:45 +01:00
|
|
|
local function load_clients(t)
|
2014-02-08 06:52:42 +01:00
|
|
|
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
|
2014-02-08 07:31:45 +01:00
|
|
|
add_client(c,screen)
|
2014-02-08 06:52:42 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
for c,_ in pairs(sticky) do
|
2014-02-08 07:31:45 +01:00
|
|
|
add_client(c,screen)
|
2014-02-08 06:52:42 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Add and remove clients from the tasklist
|
2014-02-08 07:31:45 +01:00
|
|
|
local function tagged(c,t)
|
|
|
|
if t.selected and not c.sticky and tag.getscreen(t) == screen then
|
|
|
|
add_client(c,screen)
|
2014-02-08 06:52:42 +01:00
|
|
|
end
|
|
|
|
end
|
2014-02-08 07:31:45 +01:00
|
|
|
local function untagged(c,t)
|
|
|
|
local item = cache[c]
|
2014-02-08 06:52:42 +01:00
|
|
|
if t.selected and tag.getscreen(t) == screen then
|
2014-02-08 07:31:45 +01:00
|
|
|
menu:remove(item)
|
2014-02-08 06:52:42 +01:00
|
|
|
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)
|
2014-02-08 07:31:45 +01:00
|
|
|
capi.client.connect_signal("tagged" , tagged )
|
|
|
|
capi.client.connect_signal("untagged" , untagged )
|
2014-02-08 06:52:42 +01:00
|
|
|
|
2014-02-08 07:31:45 +01:00
|
|
|
instances[screen] = {menu = menu, cache = cache }
|
2014-02-08 06:52:42 +01:00
|
|
|
|
|
|
|
load_clients(tag.selected(screen))
|
|
|
|
|
2014-02-15 05:35:53 +01:00
|
|
|
-- Try to make awesome think radical.bar is a real widget
|
|
|
|
-- Use "menu._internal.layout" directly in :add to avoid
|
|
|
|
-- the proxy overhead, for now it doesn't event work on 3.5.2
|
|
|
|
-- rawset(menu,"fit",function(self,...)
|
|
|
|
-- return menu._internal.layout.fit(menu._internal.layout,...)
|
|
|
|
-- end)
|
|
|
|
-- rawset(menu,"draw",function(self,...)
|
|
|
|
-- return menu._internal.layout.draw(menu._internal.layout,...)
|
|
|
|
-- end)
|
|
|
|
-- rawset(menu,"add_signal",function(self,...)
|
|
|
|
-- return menu._internal.layout.add_signal(menu._internal.layout,...)
|
|
|
|
-- end)
|
|
|
|
-- rawset(menu,"disconnect_signal",function(a,...)
|
|
|
|
-- return menu._internal.layout.disconnect_signal(menu._internal.layout,...)
|
|
|
|
-- end)
|
|
|
|
-- rawset(menu,"connect_signal",function(a,...)
|
|
|
|
-- return menu._internal.layout.disconnect_signal(menu._internal.layout,...)
|
|
|
|
-- end)
|
|
|
|
-- rawset(menu,"emit_signal",function(a,...)
|
|
|
|
-- return menu._internal.layout.emit_signal(menu._internal.layout,...)
|
|
|
|
-- end)
|
2014-02-17 07:11:35 +01:00
|
|
|
|
|
|
|
menu:connect_signal("button::press",function(menu,item,button_id,mod)
|
|
|
|
if module.buttons and module.buttons[button_id] then
|
|
|
|
module.buttons[button_id](item.client,menu,item,button_id,mod)
|
|
|
|
end
|
|
|
|
end)
|
2014-02-15 05:35:53 +01:00
|
|
|
|
|
|
|
return menu,menu._internal.layout
|
2014-02-08 06:52:42 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Global callbacks
|
2014-02-08 07:31:45 +01:00
|
|
|
capi.client.connect_signal("property::sticky" , sticky_callback )
|
|
|
|
capi.client.connect_signal("property::urgent" , urgent_callback )
|
|
|
|
capi.client.connect_signal("unmanage" , unmanage_callback )
|
|
|
|
capi.client.connect_signal("focus" , focus )
|
|
|
|
capi.client.connect_signal("unfocus" , unfocus )
|
|
|
|
capi.client.connect_signal("property::sticky" , reload_underlay )
|
|
|
|
capi.client.connect_signal("property::ontop" , reload_underlay )
|
|
|
|
capi.client.connect_signal("property::floating", reload_underlay )
|
2014-02-09 09:04:02 +01:00
|
|
|
capi.client.connect_signal("property::name" , reload_content )
|
|
|
|
capi.client.connect_signal("property::icon" , reload_content )
|
2014-02-08 06:52:42 +01:00
|
|
|
|
|
|
|
return setmetatable(module, { __call = function(_, ...) return new(...) end })
|
|
|
|
-- kate: space-indent on; indent-width 2; replace-tabs on;
|