From 0f6125a3f62bdd738576746541cac3418d8c4fa6 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 21 Aug 2009 16:05:02 +0200 Subject: [PATCH] awful.screen.focus: make focus() absolute and add focus_relative() Signed-off-by: Julien Danjou --- awesomerc.lua.in | 8 ++++---- lib/awful/screen.lua.in | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/awesomerc.lua.in b/awesomerc.lua.in index b1239316..b508758f 100644 --- a/awesomerc.lua.in +++ b/awesomerc.lua.in @@ -198,10 +198,10 @@ globalkeys = awful.util.table.join( awful.key({ modkey, }, "w", function () mymainmenu:show(true) end), -- Layout manipulation - awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end), - awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end), - awful.key({ modkey, "Control" }, "j", function () awful.screen.focus( 1) end), - awful.key({ modkey, "Control" }, "k", function () awful.screen.focus(-1) end), + awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end), + awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end), + awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end), + awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end), awful.key({ modkey, }, "u", awful.client.urgent.jumpto), awful.key({ modkey, }, "Tab", function () diff --git a/lib/awful/screen.lua.in b/lib/awful/screen.lua.in index 44a6b031..0a03f74f 100644 --- a/lib/awful/screen.lua.in +++ b/lib/awful/screen.lua.in @@ -21,13 +21,20 @@ local data = {} data.padding = {} --- Give the focus to a screen, and move pointer. --- @param i Relative screen number. -function focus(i) - local s = util.cycle(capi.screen.count(), capi.mouse.screen + i) - local c = client.focus.history.get(s, 0) +-- @param screen Screen number. +function focus(screen) + local c = client.focus.history.get(screen, 0) if c then capi.client.focus = c end -- Move the mouse on the screen - capi.mouse.screen = s + capi.mouse.screen = screen +end + +--- Give the focus to a screen, and move pointer, but relative to the current +-- focused screen. +-- @param i Value to add to the current focused screen index. 1 will focus next +-- screen, -1 would focus the previous one. +function focus_relative(i) + return focus(util.cycle(capi.screen.count(), capi.mouse.screen + i)) end --- Get or set the screen padding.