Fix the screen order logic

This commit is contained in:
Emmanuel Lepage Vallee 2015-02-15 06:57:40 +00:00
parent a79cc9161f
commit 49b567cbd6
1 changed files with 30 additions and 29 deletions

View File

@ -17,38 +17,40 @@ local shape = nil
local pss = 1 local pss = 1
-- Screen order is not always geometrical, sort them -- Screen order is not always geometrical, sort them
-- local function get_first_screen()
-- local ret = {}
-- for i=1,capi.screen.count() do
-- local geom = capi.screen[i].geometry
-- if #ret == 0 then
-- ret[1] = i
-- elseif geom.x < capi.screen[ret[1]].geometry.x then
-- table.insert(ret,1,i)
-- else
-- for j=1,#ret do
-- if geom.x > capi.screen[ret[j]].geometry.x then
-- table.insert(ret,j,i)
-- break
-- end
-- end
-- end
-- end
-- return ret
-- end
local function get_first_screen() local function get_first_screen()
local ret = {} local ret = {}
for i=1,capi.screen.count() do for i=1,capi.screen.count() do
ret[i] = i local geom = capi.screen[i].geometry
if #ret == 0 then
ret[1] = i
elseif geom.x < capi.screen[ret[1]].geometry.x then
table.insert(ret,1,i)
else
for j=#ret,1,-1 do
if geom.x > capi.screen[ret[j]].geometry.x then
table.insert(ret,j+1,i)
break
end
end
end
end end
return ret return ret
end end
local screens = get_first_screen()
local screens,screens_inv = get_first_screen(),{}
for k,v in ipairs(screens) do
screens_inv[v] = k
end
local function current_screen()
-- return capi.client.focus and capi.client.focus.screen or capi.mouse.screen
return capi.mouse.screen
end
local function create_text(text) local function create_text(text)
local img = cairo.ImageSurface(cairo.Format.ARGB32, size, size) local img = cairo.ImageSurface(cairo.Format.ARGB32, size, size)
local cr = cairo.Context(img) local cr = cairo.Context(img)
cr:set_source(color(text == pss and beautiful.bg_urgent or beautiful.bg_alternate or beautiful.bg_normal)) cr:set_source(color(text == screens[pss] and beautiful.bg_urgent or beautiful.bg_alternate or beautiful.bg_normal))
cr:paint() cr:paint()
cr:set_source(color(beautiful.fg_normal)) cr:set_source(color(beautiful.fg_normal))
cr:set_line_width(6) cr:set_line_width(6)
@ -93,7 +95,7 @@ local function init_wiboxes(direction)
for s=1, capi.screen.count() do for s=1, capi.screen.count() do
local w = create_shape_bounding(capi.screen[s].geometry) local w = create_shape_bounding(capi.screen[s].geometry)
wiboxes[s] = w wiboxes[s] = w
w:set_widget(wibox.widget.imagebox(create_text(s))) w:set_widget(wibox.widget.imagebox(create_text(screens[s])))
end end
return true return true
end end
@ -131,7 +133,7 @@ local function next_screen(ss,dir,move)
scr_index = scr_index == #screens and 1 or scr_index+1 scr_index = scr_index == #screens and 1 or scr_index+1
end end
return select_screen(scr_index,move) return select_screen(screens_inv[scr_index],move)
end end
function module.display(_,dir,move) function module.display(_,dir,move)
@ -139,7 +141,7 @@ function module.display(_,dir,move)
init_wiboxes(dir) init_wiboxes(dir)
end end
module.reload(nil,direction) module.reload(nil,direction)
local ss,opss = capi.client.focus and capi.client.focus.screen or capi.mouse.screen,pss local ss,opss = current_screen(),pss
next_screen(ss,dir,move) next_screen(ss,dir,move)
module.reload(nil,direction) module.reload(nil,direction)
end end
@ -153,17 +155,16 @@ function module.hide()
end end
function module.reload(mod,dir,__,___,move) function module.reload(mod,dir,__,___,move)
print("LA",mod and #mod) local ss,opss = current_screen(),pss
local ss,opss = capi.client.focus and capi.client.focus.screen or capi.mouse.screen,pss
if dir then if dir then
ss = next_screen(ss,dir:lower(),move or (mod and #mod == 4)) ss = next_screen(ss,dir:lower(),move or (mod and #mod == 4))
end end
if pss ~= ss then if pss ~= ss then
pss = nil pss = nil
wiboxes[opss]:set_widget(wibox.widget.imagebox(create_text(opss))) wiboxes[opss]:set_widget(wibox.widget.imagebox(create_text(screens[opss])))
pss = ss pss = ss
wiboxes[ss]:set_widget(wibox.widget.imagebox(create_text(ss))) wiboxes[ss]:set_widget(wibox.widget.imagebox(create_text(screens[ss])))
end end
for s=1, capi.screen.count() do for s=1, capi.screen.count() do