Add screen switching support

This commit is contained in:
Emmanuel Lepage Vallee 2014-10-15 23:50:58 -04:00
parent 28f26002f9
commit c47e2d5bca
3 changed files with 158 additions and 28 deletions

View File

@ -49,15 +49,16 @@ Using Collision is easy. You just have to hit the arrow keys (`➡` `⬆` `⬇`
with some modifiers keys. The `Shift` key is usually used for grabbing something with some modifiers keys. The `Shift` key is usually used for grabbing something
while the `Control` key is used to max out the effect. while the `Control` key is used to max out the effect.
| Modifier 1 | Modifier 2 | Modifier 3 | Effect | | Modifier 1 | Modifier 2 | Modifier 3 | Effect |
| :--------: | :----------: | :--------: | ----------------------------------------------------- | | :--------: | :----------: | :----------: | ----------------------------------------------------- |
| `Mod4` | | | Move the focus om the tiled layer | | `Mod4` | | | Move the focus om the tiled layer |
| `Mod4` | | `Control` | Move the focus on the floating layer | | `Mod4` | | `Control` | Move the focus on the floating layer |
| `Mod4` | `Shift` | | Move a client in the tiled or floating layer | | `Mod4` | `Shift` | | Move a client in the tiled or floating layer |
| `Mod4` | `Shift` | `Control` | Move a floating client to the far side of that screen | | `Mod4` | `Shift` | `Control` | Move a floating client to the far side of that screen |
| `Mod4` | `Mod1 (Alt)` | | Resize a client relative to the bottom right corner | | `Mod4` | `Mod1 (Alt)` | | Resize a client relative to the bottom right corner |
| `Mod4` | `Mod1 (Alt)` | `Shift` | Resize a client relative to the top left corner | | `Mod4` | `Mod1 (Alt)` | `Shift` | Resize a client relative to the top left corner |
| `Control` | `Mod1 (Alt)` | | Move to the next/previous tag | | `Control` | `Mod1 (Alt)` | | Move to the next/previous tag |
| `Control` | `Mod4` | `Mod1 (Alt)` | Move to the next/previous screen |
# Using different keys # Using different keys

View File

@ -45,14 +45,16 @@ function module.get_geometry(tag)
local focus,focus_wrap = capi.client.focus,nil local focus,focus_wrap = capi.client.focus,nil
for k,c in ipairs (tag:clients()) do for k,c in ipairs (tag:clients()) do
-- Handle floating client separately -- Handle floating client separately
local floating = awful.client.floating.get(c) if not c.minimized then
if (not floating) and (not l == awful.layout.suit.floating) then local floating = awful.client.floating.get(c)
cls[#cls+1] = gen_cls(c,results) if (not floating) and (not l == awful.layout.suit.floating) then
if c == focus then cls[#cls+1] = gen_cls(c,results)
focus_wrap = cls[#cls] if c == focus then
focus_wrap = cls[#cls]
end
else
flt[#flt+1] = c:geometry()
end end
else
flt[#flt+1] = c:geometry()
end end
end end

View File

@ -1,24 +1,151 @@
local capi = {screen=screen,client=client} local capi = {screen=screen,client=client,mouse=mouse}
local wibox = require("wibox") local math,table = math,table
local awful = require("awful") local wibox = require( "wibox" )
local cairo = require( "lgi" ).cairo local awful = require( "awful" )
local color = require( "gears.color" ) local cairo = require( "lgi" ).cairo
local beautiful = require( "beautiful" ) local color = require( "gears.color" )
local beautiful = require( "beautiful" )
local surface = require( "gears.surface" ) local surface = require( "gears.surface" )
local pango = require("lgi").Pango local pango = require( "lgi" ).Pango
local pangocairo = require("lgi").PangoCairo local pangocairo = require( "lgi" ).PangoCairo
local module = {} local module = {}
local wiboxes = {}
local size = 100
local shape = nil
local pss = 1
-- 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 geom.x == 0 then
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
end
return ret
end
local screens = get_first_screen()
local function create_text(text)
local img = cairo.ImageSurface(cairo.Format.ARGB32, size, size)
local cr = cairo.Context(img)
cr:set_source(color(text == pss and beautiful.bg_urgent or beautiful.bg_alternate or beautiful.bg_normal))
cr:paint()
cr:set_source(color(beautiful.fg_normal))
cr:set_line_width(6)
cr:arc(size/2,size/2,size/2,0,2*math.pi)
cr:stroke()
local pango_crx = pangocairo.font_map_get_default():create_context()
local pango_l = pango.Layout.new(pango_crx)
local desc = pango.FontDescription()
desc:set_family("Verdana")
desc:set_weight(pango.Weight.BOLD)
desc:set_size(60 * pango.SCALE)
pango_l:set_font_description(desc)
pango_l.text = text
local geo = pango_l:get_pixel_extents()
cr:move_to(((size-geo.width)/2)*.75,0)--(size-geo.height)/2)
cr:show_layout(pango_l)
return surface(img)
end
local function create_shape_bounding(wa)
local w = wibox{}
w.width = size
w.height = size
w.x=wa.x+wa.width/2-size/2
w.y=wa.y+wa.height/2-size/2
w.ontop = true
if not shape then
shape = cairo.ImageSurface(cairo.Format.ARGB32, size, size)
local cr = cairo.Context(shape)
cr:set_source_rgba(0,0,0,0)
cr:paint()
cr:set_source_rgba(1,1,1,1)
cr:arc(size/2,size/2,size/2,0,2*math.pi)
cr:fill()
end
w.shape_bounding = shape._native
return w
end
local function init_wiboxes()
if #wiboxes > 0 then return end
for s=1, capi.screen.count() do
local w = create_shape_bounding(capi.screen[s].geometry)
wiboxes[s] = w
w:set_widget(wibox.widget.imagebox(create_text(s)))
end
module.reload()
return true
end
local function next_screen(ss,dir)
local scr_index = ss
for k,s in ipairs(screens) do
if ss == s then
scr_index = k
break
end
end
if dir == "Left" then
scr_index = scr_index == 1 and #screens or scr_index - 1
elseif rit == "Right" then
scr_index = scr_index == #screens and 1 or scr_index+1
end
local geom = capi.screen[scr_index].geometry
capi.mouse.coords({x=geom.x+geom.width/2,y=geom.y+geom.height/2})
return scr_index
end
function module.display() function module.display()
print("DISPLAT") if #wiboxes == 0 then
init_wiboxes()
end
end end
function module.hide() function module.hide()
print("HIDE") if #wiboxes == 0 then return end
for s=1, capi.screen.count() do
wiboxes[s].visible = false
end
end end
function module.reload() function module.reload(_,dir)
print("RELOAD") local ss,opss = capi.client.focus and capi.client.focus.screen or capi.mouse.screen,pss
if dir then
ss = next_screen(ss,dir)
end
if pss ~= ss then
pss = nil
wiboxes[opss]:set_widget(wibox.widget.imagebox(create_text(opss)))
pss = ss
wiboxes[ss]:set_widget(wibox.widget.imagebox(create_text(ss)))
end
for s=1, capi.screen.count() do
wiboxes[s].visible = true
end
return true
end end
return module return module