awful.menu: Use oocairo instead of image
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
4279c879b3
commit
e53054553d
|
@ -12,7 +12,6 @@ local string = string
|
||||||
local type = type
|
local type = type
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
local wibox = wibox
|
local wibox = wibox
|
||||||
local image = image
|
|
||||||
local widget = widget
|
local widget = widget
|
||||||
local button = require("awful.button")
|
local button = require("awful.button")
|
||||||
local capi =
|
local capi =
|
||||||
|
@ -20,7 +19,8 @@ local capi =
|
||||||
screen = screen,
|
screen = screen,
|
||||||
mouse = mouse,
|
mouse = mouse,
|
||||||
client = client,
|
client = client,
|
||||||
keygrabber = keygrabber
|
keygrabber = keygrabber,
|
||||||
|
oocairo = oocairo
|
||||||
}
|
}
|
||||||
local util = require("awful.util")
|
local util = require("awful.util")
|
||||||
local tags = require("awful.tag")
|
local tags = require("awful.tag")
|
||||||
|
@ -218,15 +218,23 @@ local function add_item(data, num, item_info)
|
||||||
-- Set icon if needed
|
-- Set icon if needed
|
||||||
local iconbox
|
local iconbox
|
||||||
if item_info[3] then
|
if item_info[3] then
|
||||||
local icon = type(item_info[3]) == "string" and image(item_info[3]) or item_info[3]
|
local icon = type(item_info[3]) == "string" and capi.oocairo.image_surface_create_from_png(item_info[3]) or item_info[3]
|
||||||
if icon.width > data.h or icon.height > data.h then
|
local width = icon:get_width()
|
||||||
local width, height
|
local height = icon:get_height()
|
||||||
if ((data.h/icon.height) * icon.width) > data.h then
|
if width > data.h or height > data.h then
|
||||||
width, height = data.h, (data.h / icon.width) * icon.height
|
local w, h
|
||||||
|
if ((data.h/height) * width) > data.h then
|
||||||
|
w, h = data.h, (data.h / width) * height
|
||||||
else
|
else
|
||||||
width, height = (data.h / icon.height) * icon.width, data.h
|
w, h = (data.h / height) * width, data.h
|
||||||
end
|
end
|
||||||
icon = icon:crop_and_scale(0, 0, icon.width, icon.height, width, height)
|
-- We need to scale the image to size w x h
|
||||||
|
local img = capi.oocairo.image_surface_create("argb32", w, h)
|
||||||
|
local cr = capi.oocairo.context_create(img)
|
||||||
|
cr:scale(w / width, h / height)
|
||||||
|
cr:set_source(icon, 0, 0)
|
||||||
|
cr:paint()
|
||||||
|
icon = img
|
||||||
end
|
end
|
||||||
iconbox = widget { type = "imagebox" }
|
iconbox = widget { type = "imagebox" }
|
||||||
iconbox.image = icon
|
iconbox.image = icon
|
||||||
|
@ -244,7 +252,7 @@ local function add_item(data, num, item_info)
|
||||||
local submenu
|
local submenu
|
||||||
if type(item_info[2]) == "table" then
|
if type(item_info[2]) == "table" then
|
||||||
submenu = widget({ type = "imagebox" })
|
submenu = widget({ type = "imagebox" })
|
||||||
submenu.image = data.theme.submenu_icon and image(data.theme.submenu_icon)
|
submenu.image = data.theme.submenu_icon and capi.oocairo.image_surface_create_from_png(data.theme.submenu_icon)
|
||||||
submenu:buttons(bindings)
|
submenu:buttons(bindings)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue