From a79cc9161f1b7b78c085f0e9002e144a64323f01 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 15 Feb 2015 04:50:21 +0000 Subject: [PATCH] Add select_screen method --- README.md | 7 ++++++- init.lua | 7 +++++++ resize.lua | 10 ++++++++-- screen.lua | 38 +++++++++++++++++++++++--------------- 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 1232b83..f605dc4 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ while the `Control` key is used to max out the effect. | Modifier 1 | Modifier 2 | Modifier 3 | Effect | | :--------: | :----------: | :----------: | ----------------------------------------------------- | -| `Mod4` | | | Move the focus on the tiled layer | +| `Mod4` | | | Move the focus om the tiled layer | | `Mod4` | | `Control` | Move the focus on the 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 | @@ -95,3 +95,8 @@ be removed from rc.lua. -- Swap clients across screen instead of adding them to the other tag collision.settings.swap_across_screen = true ``` + +# Other + +The `collision.select_screen(idx)` function allow to select a screen and can be +assigned to shortcuts. \ No newline at end of file diff --git a/init.lua b/init.lua index 5aa8666..cf8e728 100644 --- a/init.lua +++ b/init.lua @@ -10,6 +10,7 @@ local module = { _max = require( "collision.max" ), _screen = require( "collision.screen"), settings= col_utils.settings , + util = col_utils , } local current_mode = "focus" @@ -125,6 +126,12 @@ function module.screen(direction, move) start_loop(false,max) end +function module.select_screen(idx) + if idx and idx > 0 and idx < capi.screen.count() then + module._screen.select_screen(idx) + end +end + local function new(k) -- Replace the keys array. The new one has to have a valid mapping keys = k or keys diff --git a/resize.lua b/resize.lua index f988d40..7e49d60 100644 --- a/resize.lua +++ b/resize.lua @@ -153,8 +153,14 @@ function module.resize(mod,key,event,direction,is_swap,is_max) return true end +local corners = { + tl = function(geom,mouse,curX,curY) return {x=geom.x+(mouse.x-curX),y=geom.y+(mouse.y-curY),width=geom.width-(mouse.x-curX),height=geom.height-(mouse.y-curY)} end, + bl = function(geom,mouse,curX,curY) return {x=geom.x+(mouse.x-curX),y=geom.y ,width=geom.width-(mouse.x-curX),height=geom.height-(curY-mouse.y)} end, + br = function(geom,mouse,curX,curY) return {x=geom.x ,y=geom.y ,width=geom.width-(curX-mouse.x),height=geom.height-(curY-mouse.y)} end, +} + -- Resize from the top left corner -function module.mouse_resize(c,btn) +function module.mouse_resize(c,corner) module.display(c) local geom,curX,curY = c:geometry(),capi.mouse.coords().x,capi.mouse.coords().y capi.mousegrabber.run(function(mouse) @@ -162,7 +168,7 @@ function module.mouse_resize(c,btn) module.hide() return false elseif mouse.x ~= curX and mouse.y ~= curY then - c:geometry({x=geom.x+(mouse.x-curX),y=geom.y+(mouse.y-curY),width=geom.width-(mouse.x-curX),height=geom.height-(mouse.y-curY)}) + c:geometry(corners[corner or "tl"](geom,mouse,curX,curY)) end return true end,"fleur") diff --git a/screen.lua b/screen.lua index 0c23dc8..6eef71b 100644 --- a/screen.lua +++ b/screen.lua @@ -98,21 +98,7 @@ local function init_wiboxes(direction) return true end -local function next_screen(ss,dir,move) - 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 dir == "right" then - scr_index = scr_index == #screens and 1 or scr_index+1 - end - +local function select_screen(scr_index,move) local geom = capi.screen[scr_index].geometry capi.mouse.coords({x=geom.x+geom.width/2,y=geom.y+geom.height/2+55}) @@ -130,6 +116,24 @@ local function next_screen(ss,dir,move) return scr_index end +local function next_screen(ss,dir,move) + 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 dir == "right" then + scr_index = scr_index == #screens and 1 or scr_index+1 + end + + return select_screen(scr_index,move) +end + function module.display(_,dir,move) if #wiboxes == 0 then init_wiboxes(dir) @@ -168,5 +172,9 @@ print("LA",mod and #mod) return true end +function module.select_screen(idx) + select_screen(idx,false) +end + return module -- kate: space-indent on; indent-width 2; replace-tabs on; \ No newline at end of file