2014-03-30 04:56:09 +02:00
|
|
|
-- This file provide extensions
|
|
|
|
|
|
|
|
local capi = { screen = screen, client=client}
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local ipairs,pairs = ipairs,pairs
|
|
|
|
local type = type
|
|
|
|
local radical = require( "radical" )
|
|
|
|
local beautiful = require( "beautiful" )
|
|
|
|
local awful = require( "awful" )
|
|
|
|
local util = require( "awful.util" )
|
|
|
|
local wibox = require( "wibox" )
|
|
|
|
local tasklist = nil
|
|
|
|
|
|
|
|
local module = {}
|
|
|
|
|
|
|
|
local current_client = nil
|
|
|
|
|
|
|
|
local classes = {}
|
|
|
|
local global = {}
|
|
|
|
|
|
|
|
local extension_list = {}
|
|
|
|
|
2014-04-09 05:38:31 +02:00
|
|
|
local function read_add(item,w,position)
|
|
|
|
if position == "suffix" then
|
|
|
|
item:add_suffix(w)
|
|
|
|
elseif position == "prefix" then
|
|
|
|
item:add_prefix(w)
|
|
|
|
elseif position == "overlay" then
|
|
|
|
item:add_overlay(w)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-30 04:56:09 +02:00
|
|
|
local per_m,per_glob,per_class,per_this = nil
|
2014-04-09 05:38:31 +02:00
|
|
|
local function persistence_menu(ext,position)
|
|
|
|
local position=position
|
2014-03-30 04:56:09 +02:00
|
|
|
if not tasklist then
|
|
|
|
tasklist = require("radical.impl.tasklist")
|
|
|
|
end
|
|
|
|
if not per_m then
|
|
|
|
per_m = radical.context{}
|
|
|
|
per_glob = per_m:add_item{text= "All clients" ,checkable = true , button1 = function()
|
|
|
|
local i1 = tasklist.item(current_client)
|
|
|
|
if i1 and (not i1._internal.has_widget or not i1._internal.has_widget[ext]) then
|
2014-04-09 05:38:31 +02:00
|
|
|
read_add(i1,ext(current_client),position)
|
2014-03-30 04:56:09 +02:00
|
|
|
i1._internal.has_widget = i1._internal.has_widget or {}
|
|
|
|
i1._internal.has_widget[ext] = true
|
|
|
|
end
|
|
|
|
for k,v in ipairs(capi.client.get()) do
|
|
|
|
local i2 = tasklist.item(v)
|
|
|
|
if i2 and (not i2._internal.has_widget or not i2._internal.has_widget[ext]) then
|
2014-04-09 05:38:31 +02:00
|
|
|
read_add(i2,ext(v),position)
|
2014-03-30 04:56:09 +02:00
|
|
|
i2._internal.has_widget = i2._internal.has_widget or {}
|
|
|
|
i2._internal.has_widget[ext] = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
per_glob.checked = true
|
|
|
|
end}
|
|
|
|
per_class = per_m:add_item{text= "This class only" ,checkable = true, button1 = function()
|
|
|
|
local i1 = tasklist.item(current_client)
|
|
|
|
if i1 and (not i1._internal.has_widget or not i1._internal.has_widget[ext]) then
|
2014-04-09 05:38:31 +02:00
|
|
|
read_add(i1,ext(current_client),position)
|
2014-03-30 04:56:09 +02:00
|
|
|
i1._internal.has_widget = i1._internal.has_widget or {}
|
|
|
|
i1._internal.has_widget[ext] = true
|
|
|
|
end
|
|
|
|
for k,v in ipairs(capi.client.get()) do
|
|
|
|
if v.class == current_client.class then
|
|
|
|
local i2 = tasklist.item(v)
|
|
|
|
if i2 and (not i2._internal.has_widget or not i2._internal.has_widget[ext]) then
|
2014-04-09 05:38:31 +02:00
|
|
|
read_add(i2,ext(v),position)
|
2014-03-30 04:56:09 +02:00
|
|
|
i2._internal.has_widget = i2._internal.has_widget or {}
|
|
|
|
i2._internal.has_widget[ext] = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
per_class.checked = true
|
|
|
|
end}
|
|
|
|
per_this = per_m:add_item{text= "This client only" ,checkable = true, button1 = function()
|
|
|
|
local i1 = tasklist.item(current_client)
|
|
|
|
if i1 and (not i1._internal.has_widget or not i1._internal.has_widget[ext]) then
|
2014-04-09 05:38:31 +02:00
|
|
|
read_add(i1,ext(current_client),position)
|
2014-03-30 04:56:09 +02:00
|
|
|
i1._internal.has_widget = i1._internal.has_widget or {}
|
|
|
|
i1._internal.has_widget[ext] = true
|
|
|
|
end
|
|
|
|
per_this.checked = true
|
|
|
|
end}
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Check the checkboxes
|
|
|
|
local i1 = tasklist.item(current_client)
|
|
|
|
if global[ext] then
|
|
|
|
per_glob.checked = true
|
|
|
|
per_class.checked = false
|
|
|
|
per_this.checked = false
|
|
|
|
elseif classes[ext] and classes[ext][current_client.class] then
|
|
|
|
per_class.checked = true
|
|
|
|
per_this.checked = false
|
|
|
|
per_glob.checked = false
|
|
|
|
elseif i1 and i1._internal.has_widget and i1._internal.has_widget[ext] then
|
|
|
|
per_this.checked = true
|
|
|
|
per_class.checked = false
|
|
|
|
per_glob.checked = false
|
|
|
|
else
|
|
|
|
per_this.checked = false
|
|
|
|
per_class.checked = false
|
|
|
|
per_glob.checked = false
|
|
|
|
end
|
|
|
|
|
|
|
|
return per_m
|
|
|
|
end
|
|
|
|
|
2014-06-01 05:45:46 +02:00
|
|
|
local ext_list_m,cur_pos = nil
|
2014-04-09 05:38:31 +02:00
|
|
|
local function extension_list_menu(position)
|
2014-06-01 05:45:46 +02:00
|
|
|
cur_pos = position
|
2014-03-30 04:56:09 +02:00
|
|
|
if not ext_list_m then
|
|
|
|
ext_list_m = radical.context{}
|
|
|
|
for k,v in pairs(extension_list) do
|
2014-06-01 05:45:46 +02:00
|
|
|
ext_list_m:add_item{text=k,sub_menu=function() return persistence_menu(v,cur_pos) end}
|
2014-03-30 04:56:09 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return ext_list_m
|
|
|
|
end
|
|
|
|
|
|
|
|
local ext_m = nil
|
|
|
|
function module.extensions_menu(c)
|
|
|
|
current_client = c
|
|
|
|
if not ext_m then
|
|
|
|
ext_m = radical.context{}
|
2014-04-09 05:38:31 +02:00
|
|
|
ext_m:add_item{text="Overlay widget", sub_menu=function() return extension_list_menu( "overlay" ) end }
|
|
|
|
ext_m:add_item{text="Prefix widget" , sub_menu=function() return extension_list_menu( "prefix" ) end }
|
|
|
|
ext_m:add_item{text="Suffix widget" , sub_menu=function() return extension_list_menu( "suffix" ) end }
|
2014-03-30 04:56:09 +02:00
|
|
|
end
|
|
|
|
return ext_m
|
|
|
|
end
|
|
|
|
|
|
|
|
function module.add(name,f)
|
|
|
|
extension_list[name] = f
|
|
|
|
if ext_list_m then
|
|
|
|
ext_list_m:add_item{text=name,sub_menu=function() return persistence_menu(f) end}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(module, { __call = function(_, ...) return new(...) end })
|
|
|
|
-- kate: space-indent on; indent-width 2; replace-tabs on;
|