Add awful.screen.focused [FS#1029]

This allows to configure / override what gets considered to be the
"focused screen".

Ref: https://awesome.naquadah.org/bugs/index.php?do=details&task_id=1029

Closes https://github.com/awesomeWM/awesome/pull/94.
This commit is contained in:
Daniel Hahler 2015-01-31 16:40:46 +01:00
parent 2c3c6b5ca8
commit cbe684efd1
6 changed files with 41 additions and 36 deletions

View File

@ -273,12 +273,12 @@ globalkeys = awful.util.table.join(
end), end),
-- Prompt -- Prompt
awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end), awful.key({ modkey }, "r", function () mypromptbox[awful.screen.focused()]:run() end),
awful.key({ modkey }, "x", awful.key({ modkey }, "x",
function () function ()
awful.prompt.run({ prompt = "Run Lua code: " }, awful.prompt.run({ prompt = "Run Lua code: " },
mypromptbox[mouse.screen].widget, mypromptbox[awful.screen.focused()].widget,
awful.util.eval, nil, awful.util.eval, nil,
awful.util.getdir("cache") .. "/history_eval") awful.util.getdir("cache") .. "/history_eval")
end), end),
@ -318,7 +318,7 @@ for i = 1, 9 do
-- View tag only. -- View tag only.
awful.key({ modkey }, "#" .. i + 9, awful.key({ modkey }, "#" .. i + 9,
function () function ()
local screen = mouse.screen local screen = awful.screen.focused()
local tag = awful.tag.gettags(screen)[i] local tag = awful.tag.gettags(screen)[i]
if tag then if tag then
awful.tag.viewonly(tag) awful.tag.viewonly(tag)
@ -327,7 +327,7 @@ for i = 1, 9 do
-- Toggle tag. -- Toggle tag.
awful.key({ modkey, "Control" }, "#" .. i + 9, awful.key({ modkey, "Control" }, "#" .. i + 9,
function () function ()
local screen = mouse.screen local screen = awful.screen.focused()
local tag = awful.tag.gettags(screen)[i] local tag = awful.tag.gettags(screen)[i]
if tag then if tag then
awful.tag.viewtoggle(tag) awful.tag.viewtoggle(tag)

View File

@ -54,10 +54,11 @@ client.shape = require("awful.client.shape")
-- @client c the client to jump to -- @client c the client to jump to
-- @tparam bool merge If true then merge tags when clients are not visible. -- @tparam bool merge If true then merge tags when clients are not visible.
function client.jumpto(c, merge) function client.jumpto(c, merge)
local s = capi.client.focus and capi.client.focus.screen or capi.mouse.screen screen = screen or require("awful.screen")
local s = screen.focused()
-- focus the screen -- focus the screen
if s ~= c.screen then if s ~= c.screen then
capi.mouse.screen = c.screen screen.focus(c.screen)
end end
-- Try to make client visible, this also covers e.g. sticky -- Try to make client visible, this also covers e.g. sticky
@ -204,12 +205,7 @@ end
--- Focus the previous client in history. --- Focus the previous client in history.
function client.focus.history.previous() function client.focus.history.previous()
local sel = capi.client.focus local sel = capi.client.focus
local s local s = sel and sel.screen or awful.screen.focused()
if sel then
s = sel.screen
else
s = capi.mouse.screen
end
local c = client.focus.history.get(s, 1) local c = client.focus.history.get(s, 1)
if c then if c then
c:emit_signal("request::activate", "client.focus.history.previous", c:emit_signal("request::activate", "client.focus.history.previous",
@ -317,7 +313,7 @@ end
function client.focus.global_bydirection(dir, c) function client.focus.global_bydirection(dir, c)
screen = screen or require("awful.screen") screen = screen or require("awful.screen")
local sel = c or capi.client.focus local sel = c or capi.client.focus
local scr = capi.mouse.screen local scr = awful.screen.focused()
if sel then if sel then
scr = sel.screen scr = sel.screen
end end
@ -328,8 +324,8 @@ function client.focus.global_bydirection(dir, c)
-- if focus not changed, we must change screen -- if focus not changed, we must change screen
if sel == capi.client.focus then if sel == capi.client.focus then
screen.focus_bydirection(dir, scr) screen.focus_bydirection(dir, scr)
if scr ~= capi.mouse.screen then if scr ~= awful.screen.focused() then
local cltbl = client.visible(capi.mouse.screen) local cltbl = client.visible(awful.screen.focused())
local geomtbl = {} local geomtbl = {}
for i,cl in ipairs(cltbl) do for i,cl in ipairs(cltbl) do
geomtbl[i] = cl:geometry() geomtbl[i] = cl:geometry()
@ -383,7 +379,7 @@ end
function client.swap.global_bydirection(dir, c) function client.swap.global_bydirection(dir, c)
screen = screen or require("awful.screen") screen = screen or require("awful.screen")
local sel = c or capi.client.focus local sel = c or capi.client.focus
local scr = capi.mouse.screen local scr = awful.screen.focused()
if sel then if sel then
scr = sel.screen scr = sel.screen
end end
@ -399,7 +395,7 @@ function client.swap.global_bydirection(dir, c)
-- swapping to an empty screen -- swapping to an empty screen
elseif sel.screen ~= c.screen and sel == c then elseif sel.screen ~= c.screen and sel == c then
client.movetoscreen(sel, capi.mouse.screen) client.movetoscreen(sel, awful.screen.focused())
-- swapping to a nonempty screen -- swapping to a nonempty screen
elseif sel.screen ~= c.screen and sel ~= c then elseif sel.screen ~= c.screen and sel ~= c then
@ -429,7 +425,7 @@ end
-- @param clockwise True to cycle clients clockwise. -- @param clockwise True to cycle clients clockwise.
-- @param[opt] screen The screen where to cycle clients. -- @param[opt] screen The screen where to cycle clients.
function client.cycle(clockwise, screen) function client.cycle(clockwise, screen)
local screen = screen or capi.mouse.screen local screen = screen or awful.screen.focused()
local cls = client.visible(screen) local cls = client.visible(screen)
-- We can't rotate without at least 2 clients, buddy. -- We can't rotate without at least 2 clients, buddy.
if #cls >= 2 then if #cls >= 2 then
@ -451,7 +447,7 @@ end
-- @param[opt] screen The screen number, otherwise screen mouse is used. -- @param[opt] screen The screen number, otherwise screen mouse is used.
-- @return The master window. -- @return The master window.
function client.getmaster(screen) function client.getmaster(screen)
local s = screen or capi.mouse.screen local s = screen or awful.screen.focused()
return client.visible(s)[1] return client.visible(s)[1]
end end
@ -714,7 +710,7 @@ end
-- @param s The screen to use. -- @param s The screen to use.
-- @return The restored client if some client was restored, otherwise nil. -- @return The restored client if some client was restored, otherwise nil.
function client.restore(s) function client.restore(s)
local s = s or (capi.client.focus and capi.client.focus.screen) or capi.mouse.screen local s = s or (capi.client.focus and capi.client.focus.screen) or awful.screen.focused()
local cls = capi.client.get(s) local cls = capi.client.get(s)
local tags = tag.selectedlist(s) local tags = tag.selectedlist(s)
local mcls = {} local mcls = {}

View File

@ -32,6 +32,7 @@ local capi = {
screen = screen, screen = screen,
mouse = mouse, mouse = mouse,
client = client } client = client }
local screen = require("awful.screen")
local menu = { mt = {} } local menu = { mt = {} }
@ -315,7 +316,7 @@ end
function menu:show(args) function menu:show(args)
args = args or {} args = args or {}
local coords = args.coords or nil local coords = args.coords or nil
local screen_index = capi.mouse.screen local screen_index = screen.focused()
if not set_size(self) then return end if not set_size(self) then return end
set_coords(self, screen_index, coords) set_coords(self, screen_index, coords)

View File

@ -46,10 +46,10 @@ end
--- Give the focus to a screen, and move pointer. --- Give the focus to a screen, and move pointer.
-- Keeps relative position of the pointer on the screen. -- Keeps relative position of the pointer on the screen.
-- @param _screen Screen number. -- @param _screen Screen number (defaults / falls back to mouse.screen).
function screen.focus(_screen) function screen.focus(_screen)
client = client or require("awful.client") client = client or require("awful.client")
if _screen > capi.screen.count() then _screen = capi.mouse.screen end if _screen > capi.screen.count() then _screen = screen.focused() end
-- screen and pos for current screen -- screen and pos for current screen
local s = capi.mouse.screen local s = capi.mouse.screen
@ -75,7 +75,7 @@ end
-- @param dir The direction, can be either "up", "down", "left" or "right". -- @param dir The direction, can be either "up", "down", "left" or "right".
-- @param _screen Screen number. -- @param _screen Screen number.
function screen.focus_bydirection(dir, _screen) function screen.focus_bydirection(dir, _screen)
local sel = _screen or capi.mouse.screen local sel = _screen or screen.focused()
if sel then if sel then
local geomtbl = {} local geomtbl = {}
for s = 1, capi.screen.count() do for s = 1, capi.screen.count() do
@ -93,7 +93,7 @@ end
-- @param i Value to add to the current focused screen index. 1 will focus next -- @param i Value to add to the current focused screen index. 1 will focus next
-- screen, -1 would focus the previous one. -- screen, -1 would focus the previous one.
function screen.focus_relative(i) function screen.focus_relative(i)
return screen.focus(util.cycle(capi.screen.count(), capi.mouse.screen + i)) return screen.focus(util.cycle(capi.screen.count(), screen.focused() + i))
end end
--- Get or set the screen padding. --- Get or set the screen padding.
@ -108,6 +108,13 @@ function screen.padding(_screen, padding)
return data.padding[_screen] return data.padding[_screen]
end end
--- Get the focused screen.
-- This can be replaced in a user's config.
-- @treturn integer
function screen.focused()
return capi.mouse.screen
end
capi.screen.add_signal("padding") capi.screen.add_signal("padding")
return screen return screen

View File

@ -9,6 +9,7 @@
-- Grab environment we need -- Grab environment we need
local util = require("awful.util") local util = require("awful.util")
local ascreen = require("awful.screen")
local timer = require("gears.timer") local timer = require("gears.timer")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local tostring = tostring local tostring = tostring
@ -91,7 +92,7 @@ function tag.add(name, props)
-- connected to property::activated to be called without a valid tag. -- connected to property::activated to be called without a valid tag.
-- set properies cannot be used as this has to be set before the first signal -- set properies cannot be used as this has to be set before the first signal
-- is sent -- is sent
properties.screen = properties.screen or capi.mouse.screen properties.screen = properties.screen or ascreen.focused()
-- Index is also required -- Index is also required
properties.index = (#tag.gettags(properties.screen))+1 properties.index = (#tag.gettags(properties.screen))+1
@ -132,10 +133,10 @@ function tag.new(names, screen, layout)
end end
--- Find a suitable fallback tag. --- Find a suitable fallback tag.
-- @param screen The screen number to look for a tag on. [mouse.screen] -- @param screen The screen number to look for a tag on. [awful.screen.focused()]
-- @param invalids A table of tags we consider unacceptable. [selectedlist(scr)] -- @param invalids A table of tags we consider unacceptable. [selectedlist(scr)]
function tag.find_fallback(screen, invalids) function tag.find_fallback(screen, invalids)
local scr = screen or capi.mouse.screen local scr = screen or ascreen.focused()
local t = invalids or tag.selectedlist(scr) local t = invalids or tag.selectedlist(scr)
for _, v in pairs(tag.gettags(scr)) do for _, v in pairs(tag.gettags(scr)) do
@ -255,7 +256,7 @@ end
-- toggling between last two selected sets of tags. Number (eg 1) will go back -- toggling between last two selected sets of tags. Number (eg 1) will go back
-- to the given index in history. -- to the given index in history.
function tag.history.restore(screen, idx) function tag.history.restore(screen, idx)
local s = screen or capi.mouse.screen local s = screen or ascreen.focused()
local i = idx or "previous" local i = idx or "previous"
local sel = tag.selectedlist(s) local sel = tag.selectedlist(s)
-- do nothing if history empty -- do nothing if history empty
@ -303,7 +304,7 @@ end
-- @param t tag object -- @param t tag object
-- @param s Screen number -- @param s Screen number
function tag.setscreen(t, s) function tag.setscreen(t, s)
local s = s or capi.mouse.screen local s = s or ascreen.focused()
local sel = tag.selected local sel = tag.selected
local old_screen = tag.getproperty(t, "screen") local old_screen = tag.getproperty(t, "screen")
if s == old_screen then return end if s == old_screen then return end
@ -344,7 +345,7 @@ end
-- @param s Screen number. -- @param s Screen number.
-- @return A table with all selected tags. -- @return A table with all selected tags.
function tag.selectedlist(s) function tag.selectedlist(s)
local screen = s or capi.mouse.screen local screen = s or ascreen.focused()
local tags = tag.gettags(screen) local tags = tag.gettags(screen)
local vtags = {} local vtags = {}
for i, t in pairs(tags) do for i, t in pairs(tags) do
@ -476,7 +477,7 @@ end
--- View no tag. --- View no tag.
-- @tparam[opt] int screen The screen number. -- @tparam[opt] int screen The screen number.
function tag.viewnone(screen) function tag.viewnone(screen)
local tags = tag.gettags(screen or capi.mouse.screen) local tags = tag.gettags(screen or ascreen.focused())
for i, t in pairs(tags) do for i, t in pairs(tags) do
t.selected = false t.selected = false
end end
@ -486,7 +487,7 @@ end
-- @param i The relative index to see. -- @param i The relative index to see.
-- @param[opt] screen The screen number. -- @param[opt] screen The screen number.
function tag.viewidx(i, screen) function tag.viewidx(i, screen)
local screen = screen or capi.mouse.screen local screen = screen or ascreen.focused()
local tags = tag.gettags(screen) local tags = tag.gettags(screen)
local showntags = {} local showntags = {}
for k, t in ipairs(tags) do for k, t in ipairs(tags) do
@ -551,7 +552,7 @@ end
-- @param tags A table with tags to view only. -- @param tags A table with tags to view only.
-- @param[opt] screen The screen number of the tags. -- @param[opt] screen The screen number of the tags.
function tag.viewmore(tags, screen) function tag.viewmore(tags, screen)
local screen = screen or capi.mouse.screen local screen = screen or ascreen.focused()
local screen_tags = tag.gettags(screen) local screen_tags = tag.gettags(screen)
for _, _tag in ipairs(screen_tags) do for _, _tag in ipairs(screen_tags) do
if not util.table.hasitem(tags, _tag) then if not util.table.hasitem(tags, _tag) then
@ -655,7 +656,7 @@ capi.client.connect_signal("manage", function(c)
c:tags(c.transient_for:tags()) c:tags(c.transient_for:tags())
end end
else else
c.screen = capi.mouse.screen c.screen = ascreen.focused()
end end
end end
c:connect_signal("property::screen", tag.withcurrent) c:connect_signal("property::screen", tag.withcurrent)

View File

@ -298,7 +298,7 @@ function menubar.show(scr)
end end
-- Set position and size -- Set position and size
scr = scr or capi.mouse.screen or 1 scr = scr or awful.screen.focused() or 1
local scrgeom = capi.screen[scr].workarea local scrgeom = capi.screen[scr].workarea
local geometry = menubar.geometry local geometry = menubar.geometry
instance.geometry = {x = geometry.x or scrgeom.x, instance.geometry = {x = geometry.x or scrgeom.x,