From c2ed9071718e7ef105f17c8030b56643bd4115e0 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Thu, 16 Oct 2014 01:20:41 -0400 Subject: [PATCH] Add tag moving It is no longer required to require() collision at the bottom of rc.lua It is now possible to set the default behavior when swapping clients across screens --- README.md | 9 ++++++++- focus.lua | 27 ++++++++++++++++++--------- init.lua | 43 +++++++++++++++++++++++++------------------ max.lua | 32 +++++++++++++++++++------------- util.lua | 2 +- 5 files changed, 71 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 61a1f77..b4864ad 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ First, clone the repository Now, open ~/.config/awesome/rc.lua (or copy /etc/xdg/awesome/rc.lua to ~/.config/awesome/rc.lua fist if you never modified your Awesome config before) - and add this line at the **end** of rc.lua: + and add this line somewhere in your `rc.lua`: ```lua require("collision")() @@ -87,3 +87,10 @@ This can be used: Of course, if the `Vim` keys are used, any other shortcut binded to them have to be removed from rc.lua. + +# Settings + +```lua +-- Swap clients across screen instead of adding them to the other tag +collision.settings.swap_across_screen = true +``` diff --git a/focus.lua b/focus.lua index 95e4598..5d30ed4 100644 --- a/focus.lua +++ b/focus.lua @@ -3,13 +3,15 @@ local capi = { client = client , mouse = mouse , local setmetatable = setmetatable local ipairs = ipairs -local util = require( "awful.util" ) -local client = require( "awful.client" ) -local alayout = require( "awful.layout" ) -local wibox = require( "wibox" ) -local cairo = require( "lgi" ).cairo -local beautiful = require( "beautiful" ) -local color = require( "gears.color" ) +local util = require( "awful.util" ) +local client = require( "awful.client" ) +local tag = require( "awful.tag" ) +local alayout = require( "awful.layout" ) +local wibox = require( "wibox" ) +local cairo = require( "lgi" ).cairo +local beautiful = require( "beautiful" ) +local color = require( "gears.color" ) +local col_utils = require( "collision.util" ) local module = {} local wiboxes,delta = nil,100 @@ -142,8 +144,15 @@ local function bydirection(dir, c, swap,max) capi.client.focus = cltbl[((not cltbl[target] and #cltbl == 1) and 1 or target)] capi.client.focus:raise() else - --BUG swap doesn't work if the screen is not the same - c:swap(cltbl[((not cltbl[target] and #cltbl == 1) and 1 or target)]) + local other = cltbl[((not cltbl[target] and #cltbl == 1) and 1 or target)] + if other.screen == c.screen or col_utils.settings.swap_across_screen then + --BUG swap doesn't work if the screen is not the same + c:swap(other) + else + local t = tag.selected(other.screen) --TODO get index + c.screen = other.screen + c:tags({t}) + end end display_wiboxes(cltbl,geomtbl,float,swap,c) end diff --git a/init.lua b/init.lua index bdb23e0..b5fca0d 100644 --- a/init.lua +++ b/init.lua @@ -1,12 +1,15 @@ local capi = {root=root,client=client,mouse=mouse, screen = screen, keygrabber = keygrabber} -local util = require( "awful.util" ) -local awful = require( "awful" ) +local util = require( "awful.util" ) +local awful = require( "awful" ) +local glib = require( "lgi" ).GLib +local col_utils = require( "collision.util" ) local module = { _focus = require( "collision.focus" ), _resize = require( "collision.resize"), _max = require( "collision.max" ), _screen = require( "collision.screen"), + settings= col_utils.settings , } local current_mode = "focus" @@ -109,11 +112,11 @@ function module.resize(direction,c,max) module._resize.display(c) end -function module.tag(direction,c,max) +function module.tag(direction,swap,max) current_mode = "tag" - local c = c or capi.client.focus - module._max.display_tags((c) and c.screen or capi.mouse.screen,direction) - start_loop(false,max) + local c = capi.client.focus + module._max.display_tags((c) and c.screen or capi.mouse.screen,direction,c,true,max) + start_loop(swap,max) end function module.screen(direction) @@ -127,20 +130,24 @@ local function new(k) keys = k or keys local aw = {} - for k,v in pairs(keys) do - for _,key_nane in ipairs(v) do - aw[#aw+1] = awful.key({ "Mod4", }, key_nane, function () module.focus (k ) end) - aw[#aw+1] = awful.key({ "Mod4", "Mod1" }, key_nane, function () module.resize(k ) end) - aw[#aw+1] = awful.key({ "Mod4", "Shift" }, key_nane, function () module.move (k ) end) - aw[#aw+1] = awful.key({ "Mod4", "Shift", "Control" }, key_nane, function () module.move (k,nil,true) end) - aw[#aw+1] = awful.key({ "Mod4", "Control" }, key_nane, function () module.focus (k,nil,true) end) - aw[#aw+1] = awful.key({ "Mod4", "Mod1" , "Control" }, key_nane, function () module.screen(k ) end) - if k == "left" or k =="right" then -- Conflict with my text editor, so I say no - aw[#aw+1] = awful.key({ "Mod1", "Control" }, key_nane, function () module.tag (k,nil,true) end) + -- This have to be executer after rc.lua + glib.idle_add(glib.PRIORITY_DEFAULT_IDLE, function() + for k,v in pairs(keys) do + for _,key_nane in ipairs(v) do + aw[#aw+1] = awful.key({ "Mod4", }, key_nane, function () module.focus (k ) end) + aw[#aw+1] = awful.key({ "Mod4", "Mod1" }, key_nane, function () module.resize(k ) end) + aw[#aw+1] = awful.key({ "Mod4", "Shift" }, key_nane, function () module.move (k ) end) + aw[#aw+1] = awful.key({ "Mod4", "Shift", "Control" }, key_nane, function () module.move (k,nil ,true) end) + aw[#aw+1] = awful.key({ "Mod4", "Control" }, key_nane, function () module.focus (k,nil ,true) end) + aw[#aw+1] = awful.key({ "Mod4", "Mod1" , "Control" }, key_nane, function () module.screen(k ) end) + if k == "left" or k =="right" then -- Conflict with my text editor, so I say no + aw[#aw+1] = awful.key({ "Mod1", "Control" }, key_nane, function () module.tag (k,nil ,true) end) + aw[#aw+1] = awful.key({ "Mod1", "Shift", "Control" }, key_nane, function () module.tag (k,true,true) end) + end end end - end - capi.root.keys(awful.util.table.join(capi.root.keys(),unpack(aw))) + capi.root.keys(awful.util.table.join(capi.root.keys(),unpack(aw))) + end) end return setmetatable(module, { __call = function(_, ...) return new(...) end }) diff --git a/max.lua b/max.lua index e132140..2c48e8d 100644 --- a/max.lua +++ b/max.lua @@ -1,4 +1,4 @@ -local capi = {screen=screen,client=client} +local capi = {screen=screen,client=client,mouse=mouse} local wibox = require("wibox") local awful = require("awful") local cairo = require( "lgi" ).cairo @@ -243,26 +243,32 @@ local function tag_icon(t,width,height) return img end -local tmp_screen = nil -function module.display_tags(s,direction) - if not w then - init() - end - tmp_screen = s - if direction then +local function change_tag(s,direction,is_swap) + local s = capi.client.focus and capi.client.focus.screen or capi.mouse.screen + if not is_swap then awful.tag[direction == "left" and "viewprev" or "viewnext"](s) + else + -- Move the tag + local t = awful.tag.selected(s) + local cur_idx,count = awful.tag.getidx(t),#awful.tag.gettags(s) + cur_idx = cur_idx + (direction == "left" and -1 or 1) + cur_idx = cur_idx == 0 and count or cur_idx > count and 1 or cur_idx + awful.tag.move(cur_idx,t) end local tags = awful.tag.gettags(s) local fk = awful.util.table.hasitem(tags,awful.tag.selected(s)) draw_shape(s,tags,fk,tag_icon,capi.screen[s].workarea.y + 15,20) end +function module.display_tags(s,direction,c,is_swap,is_max) + if not w then + init() + end + change_tag(s,direction,is_swap) +end + function module.change_tag(mod,key,event,direction,is_swap,is_max) - local s = tmp_screen or capi.client.focus.screen - awful.tag[direction == "left" and "viewprev" or "viewnext"](s) - local tags = awful.tag.gettags(s) - local fk = awful.util.table.hasitem(tags,awful.tag.selected(s)) - draw_shape(s,tags,fk,tag_icon,capi.screen[s].workarea.y + 15,20) + change_tag(s,direction,is_swap) return true end diff --git a/util.lua b/util.lua index de708f3..05ef123 100644 --- a/util.lua +++ b/util.lua @@ -2,7 +2,7 @@ local math = math local color = require( "gears.color" ) local beautiful = require( "beautiful" ) -local module = {} +local module = {settings={}} local rr,rg,rb