Correctly handle floating clients

This commit is contained in:
Emmanuel Lepage Vallee 2014-10-04 23:19:04 -04:00
parent d49b431469
commit 28f26002f9
2 changed files with 46 additions and 34 deletions

View File

@ -39,13 +39,20 @@ local function gen_cls(c,results)
end
function module.get_geometry(tag)
local cls,results = {},setmetatable({},{__mode="k"})
local cls,results,flt = {},setmetatable({},{__mode="k"}),{}
local s = awful.tag.getscreen(tag)
local l = awful.tag.getproperty(tag,"layout")
local focus,focus_wrap = capi.client.focus,nil
for k,v in ipairs (tag:clients()) do
cls[#cls+1] = gen_cls(v,results)
if v == focus then
focus_wrap = cls[#cls]
for k,c in ipairs (tag:clients()) do
-- Handle floating client separately
local floating = awful.client.floating.get(c)
if (not floating) and (not l == awful.layout.suit.floating) then
cls[#cls+1] = gen_cls(c,results)
if c == focus then
focus_wrap = cls[#cls]
end
else
flt[#flt+1] = c:geometry()
end
end
@ -64,29 +71,34 @@ function module.get_geometry(tag)
workarea = capi.screen[s or 1].workarea
}
local l = awful.tag.getproperty(tag,"layout")
l.arrange(param)
return results
return results,flt
end
function module.draw(tag,cr,width,height)
local worked = false
local l = module.get_geometry(tag)
local l,l2 = module.get_geometry(tag)
local s = awful.tag.getscreen(tag)
local scr_geo = capi.screen[s or 1].workarea
local ratio = height/scr_geo.height
local w_stretch = width/(scr_geo.width*ratio)
local r,g,b = util.get_rgb()
cr:set_line_width(3)
for c,geom in pairs(l) do
util.draw_round_rect(cr,geom.x*ratio*w_stretch+margin,geom.y*ratio+margin,geom.width*ratio*w_stretch-margin*2,geom.height*ratio-margin*2,radius)
cr:close_path()
cr:set_source_rgba(r,g,b,0.7)
cr:stroke_preserve()
cr:set_source_rgba(r,g,b,0.2)
cr:fill()
worked = true
for c,ll in ipairs({l,l2}) do
for c,geom in pairs(ll) do
util.draw_round_rect(cr,geom.x*ratio*w_stretch+margin,geom.y*ratio+margin,geom.width*ratio*w_stretch-margin*2,geom.height*ratio-margin*2,radius)
cr:close_path()
cr:set_source_rgba(r,g,b,0.7)
cr:stroke_preserve()
cr:set_source_rgba(r,g,b,0.2)
cr:fill()
-- Draw an icon in the region
--TODO
worked = true
end
end
--TODO floating clients
return worked

36
max.lua
View File

@ -73,10 +73,11 @@ local function draw_shape(s,collection,current_idx,icon_f,y,text_height)
cr:set_source_rgba(0,0,0,0)
cr:paint()
-- Get the colors
local white,bg = color("#FFFFFF"),color(beautiful.menu_bg_normal or beautiful.bg_normal)
-- local img2 = get_round_rect(width,height,white)
-- local img4 = get_round_rect(width-6,height-6,bg)
local nornal,focus = color(beautiful.fg_normal),color(beautiful.bg_urgent)
-- Init the text properties
if not pango_l then
local pango_crx = pangocairo.font_map_get_default():create_context()
pango_l = pango.Layout.new(pango_crx)
@ -85,7 +86,6 @@ local function draw_shape(s,collection,current_idx,icon_f,y,text_height)
pango_l:set_wrap("CHAR")
end
local nornal,focus = color(beautiful.fg_normal),color(beautiful.bg_urgent)
for k,v in ipairs(collection) do
-- Shape bounding
cr:set_source(white)
@ -223,23 +223,23 @@ local function tag_icon(t,width,height)
-- Create a monochrome representation of the icon
local icon_orig = surface(awful.tag.geticon(t))
if icon_orig then
local icon = cairo.ImageSurface(cairo.Format.ARGB32, icon_orig:get_width(), icon_orig:get_height())
local cr2 = cairo.Context(icon)
cr2:set_source_surface(icon_orig)
cr2:paint()
local icon = cairo.ImageSurface(cairo.Format.ARGB32, icon_orig:get_width(), icon_orig:get_height())
local cr2 = cairo.Context(icon)
cr2:set_source_surface(icon_orig)
cr2:paint()
cr2:set_source(color(beautiful.fg_normal))
cr2:set_operator(cairo.Operator.IN)
cr2:paint()
cr2:set_source(color(beautiful.fg_normal))
cr2:set_operator(cairo.Operator.IN)
cr2:paint()
local w,h = icon:get_width(),icon:get_height()
local aspect,aspect_h = width / w,(height) / h
if aspect > aspect_h then aspect = aspect_h end
cr:translate((width-w*aspect)/2,(height-h*aspect)/2)
cr:scale(aspect, aspect)
cr:set_source_surface(icon)
cr:paint_with_alpha(has_layout and 0.75 or 1)
end
local w,h = icon:get_width(),icon:get_height()
local aspect,aspect_h = width / w,(height) / h
if aspect > aspect_h then aspect = aspect_h end
cr:translate((width-w*aspect)/2,(height-h*aspect)/2)
cr:scale(aspect, aspect)
cr:set_source_surface(icon)
cr:paint_with_alpha(has_layout and 0.35 or 1)
end
return img
end