Add icon_transformation option (take this from Blind playbook)

It can use Blind common.drawing tools to implement some magic.

I may merge this into Radical and kill Blind as everything else
is pretty much deprecated at this point. Blind was never more
than a hack.
This commit is contained in:
Emmanuel Lepage Vallee 2014-02-19 22:09:19 -05:00
parent 1dea6095b0
commit 7046b40f83
7 changed files with 97 additions and 63 deletions

View File

@ -143,7 +143,7 @@ Multiple items can have multiple sets of options.
### Menu options ### Menu options
| Name | Description | Type | | Name | Description | Type |
| --------------- | -------------------------------------------------- | ----------------------------- | | ------------------- | -------------------------------------------------- | ----------------------------- |
| bg | Background color | String/gradient/pattern | | bg | Background color | String/gradient/pattern |
| fg | Foreground (text) color | String/gradient/pattern | | fg | Foreground (text) color | String/gradient/pattern |
| bg_focus | Background of focussed items | String/gradient/pattern | | bg_focus | Background of focussed items | String/gradient/pattern |
@ -186,6 +186,7 @@ Multiple items can have multiple sets of options.
| select_on | The event used to trigger item selection | see "event" enum | | select_on | The event used to trigger item selection | see "event" enum |
| overlay | A layer on top of the item | function(data,item,cr,w,h) | | overlay | A layer on top of the item | function(data,item,cr,w,h) |
| opacity | Make this menu translucent (require a compositor) | number (0 to 1) | | opacity | Make this menu translucent (require a compositor) | number (0 to 1) |
| icon_transformation | Hijack the icon drawing function | function(icon,data,item) |
###Item options ###Item options
@ -241,6 +242,14 @@ here is the list:
Menu also emit many signals, the syntax is usually `PROPERTY_NAME::changed`. Menu also emit many signals, the syntax is usually `PROPERTY_NAME::changed`.
Some others are `item::moved`, `item::swapped`, `item::removed`, `item::appended` Some others are `item::moved`, `item::swapped`, `item::removed`, `item::appended`
Here is an example of how to catch an "opacity" change:
```lua
mymenu:connect_signal("opacity::changed",function(value)
-- Do something
end)
```
Most item_layout also repackage the default widget signals. It usually does the Most item_layout also repackage the default widget signals. It usually does the
same as using the `buttonX` menu attributes, but is preferrable in some scenarios same as using the `buttonX` menu attributes, but is preferrable in some scenarios
like when a modifier is applied. like when a modifier is applied.
@ -277,7 +286,7 @@ An example of how to use them:
Radical also use the some of the same theme options as awful.menu, plus some: Radical also use the some of the same theme options as awful.menu, plus some:
| Name | Description | Type | | Name | Description | Type |
| ---------------------------- | ------------------------------------- | ---------------------- | | ---------------------------- | ------------------------------------- | ------------------------- |
| menu_height | Menu height | String/Gradient/Pattern | | menu_height | Menu height | String/Gradient/Pattern |
| menu_width | Menu default/minimum width | Number | | menu_width | Menu default/minimum width | Number |
| menu_border_width | Border width | Number | | menu_border_width | Border width | Number |
@ -291,5 +300,11 @@ Radical also use the some of the same theme options as awful.menu, plus some:
| menu_submenu_icon | Sub menu pixmap (aka >) | Path/Pattern | | menu_submenu_icon | Sub menu pixmap (aka >) | Path/Pattern |
| menu_separator_color | Menu separator color | String/Gradient/Pattern | | menu_separator_color | Menu separator color | String/Gradient/Pattern |
| menu_opacity | Use your favorite compositor | Number (0=0%, 1=100%) | | menu_opacity | Use your favorite compositor | Number (0=0%, 1=100%) |
| draw_underlay | Function returning the underlay pixmap | Function | | menu_draw_underlay | Function returning the underlay pixmap | function(array,width) |
| menu_icon_transformation | The function used to draw the icon | function(image,data,item) |
Styling can also be done using the icon_transformation option. This feature
allow masks such as desaturation, tinting, invert or some matrix to be applied
on the pixmap before it is being drawn. This function take the path/surface as
only parameter and return the transformed surface.

View File

@ -342,6 +342,7 @@ local function new(args)
select_on = args.select_on or module.event.HOVER, select_on = args.select_on or module.event.HOVER,
overlay = args.overlay or nil, overlay = args.overlay or nil,
opacity = args.opacity or beautiful.menu_opacity or 1, opacity = args.opacity or beautiful.menu_opacity or 1,
icon_transformation = args.icon_transformation or nil,
}, },
get_map = { get_map = {
is_menu = function() return true end, is_menu = function() return true end,

View File

@ -74,7 +74,8 @@ end
local function new(args) local function new(args)
local t,auto_release = tag.selected(capi.client.focus and capi.client.focus.screen or capi.mouse.screen),args.auto_release local t,auto_release = tag.selected(capi.client.focus and capi.client.focus.screen or capi.mouse.screen),args.auto_release
local currentMenu = menu({filter = true, show_filter=true, autodiscard = true, local currentMenu = menu({filter = true, show_filter=true, autodiscard = true,
disable_markup=true,fkeys_prefix=not auto_release,width=(((capi.screen[capi.client.focus and capi.client.focus.screen or capi.mouse.screen]).geometry.width)/2)}) disable_markup=true,fkeys_prefix=not auto_release,width=(((capi.screen[capi.client.focus and capi.client.focus.screen or capi.mouse.screen]).geometry.width)/2),
icon_transformation = beautiful.alttab_icon_transformation})
currentMenu:add_key_hook({}, "Tab", "press", select_next) currentMenu:add_key_hook({}, "Tab", "press", select_next)
@ -102,7 +103,7 @@ local function new(args)
l.fit = function (s,w,h) return 5*h,h end l.fit = function (s,w,h) return 5*h,h end
currentMenu:add_item({ currentMenu:add_item({
text = v.name, text = v.name,
icon = module.icon_transform and module.icon_transform(v.icon or module.default_icon) or v.icon or module.default_icon, icon = v.icon or module.default_icon,
suffix_widget = not auto_release and l or nil, suffix_widget = not auto_release and l or nil,
selected = capi.client.focus and capi.client.focus == v, selected = capi.client.focus and capi.client.focus == v,
underlay = underlays, underlay = underlays,

3
impl/tasklist/README.md Normal file
View File

@ -0,0 +1,3 @@
### Beautiful options
tasklist_icon_transformation | function(image) |

View File

@ -157,7 +157,8 @@ local function new(screen)
disable_markup = true, disable_markup = true,
overlay = function(data,item,cd,w,h) overlay = function(data,item,cd,w,h)
-- print("foo!") -- print("foo!")
end end,
icon_transformation = beautiful.tasklist_icon_transformation
} }
-- Clear the menu and repopulate it -- Clear the menu and repopulate it

View File

@ -33,6 +33,14 @@ function module.paint_underlay(data,item,cr,width,height)
cr:restore() cr:restore()
end end
-- Apply icon transformation
function module.set_icon(self,image)
if self._data.icon_transformation then
image = self._data.icon_transformation(image,self._data,self._item)
end
wibox.widget.imagebox.set_image(self,image)
end
-- Setup the item icon -- Setup the item icon
function module:setup_icon(item,data) function module:setup_icon(item,data)
local icon = wibox.widget.imagebox() local icon = wibox.widget.imagebox()
@ -40,6 +48,9 @@ function module:setup_icon(item,data)
local w,h = wibox.widget.imagebox.fit(...) local w,h = wibox.widget.imagebox.fit(...)
return w+3,h return w+3,h
end end
icon._data = data
icon._item = item
icon.set_image = module.set_icon
if item.icon then if item.icon then
icon:set_image(item.icon) icon:set_image(item.icon)
end end

View File

@ -55,6 +55,8 @@ local function create_item(item,data,args)
local icon_flex = wibox.layout.align.horizontal() local icon_flex = wibox.layout.align.horizontal()
local icon = wibox.widget.imagebox() local icon = wibox.widget.imagebox()
icon.fit = function(...) return icon_fit(data,...) end icon.fit = function(...) return icon_fit(data,...) end
icon._data = data
icon.set_image = horizontal.set_icon
if args.icon then if args.icon then
icon:set_image(args.icon) icon:set_image(args.icon)
end end