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

View File

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

View File

@ -32,6 +32,7 @@ local capi = {
screen = screen,
mouse = mouse,
client = client }
local screen = require("awful.screen")
local menu = { mt = {} }
@ -315,7 +316,7 @@ end
function menu:show(args)
args = args or {}
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
set_coords(self, screen_index, coords)

View File

@ -46,10 +46,10 @@ end
--- Give the focus to a screen, and move pointer.
-- 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)
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
local s = capi.mouse.screen
@ -75,7 +75,7 @@ end
-- @param dir The direction, can be either "up", "down", "left" or "right".
-- @param _screen Screen number.
function screen.focus_bydirection(dir, _screen)
local sel = _screen or capi.mouse.screen
local sel = _screen or screen.focused()
if sel then
local geomtbl = {}
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
-- screen, -1 would focus the previous one.
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
--- Get or set the screen padding.
@ -108,6 +108,13 @@ function screen.padding(_screen, padding)
return data.padding[_screen]
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")
return screen

View File

@ -9,6 +9,7 @@
-- Grab environment we need
local util = require("awful.util")
local ascreen = require("awful.screen")
local timer = require("gears.timer")
local beautiful = require("beautiful")
local tostring = tostring
@ -91,7 +92,7 @@ function tag.add(name, props)
-- 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
-- is sent
properties.screen = properties.screen or capi.mouse.screen
properties.screen = properties.screen or ascreen.focused()
-- Index is also required
properties.index = (#tag.gettags(properties.screen))+1
@ -132,10 +133,10 @@ function tag.new(names, screen, layout)
end
--- 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)]
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)
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
-- to the given index in history.
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 sel = tag.selectedlist(s)
-- do nothing if history empty
@ -303,7 +304,7 @@ end
-- @param t tag object
-- @param s Screen number
function tag.setscreen(t, s)
local s = s or capi.mouse.screen
local s = s or ascreen.focused()
local sel = tag.selected
local old_screen = tag.getproperty(t, "screen")
if s == old_screen then return end
@ -344,7 +345,7 @@ end
-- @param s Screen number.
-- @return A table with all selected tags.
function tag.selectedlist(s)
local screen = s or capi.mouse.screen
local screen = s or ascreen.focused()
local tags = tag.gettags(screen)
local vtags = {}
for i, t in pairs(tags) do
@ -476,7 +477,7 @@ end
--- View no tag.
-- @tparam[opt] int screen The screen number.
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
t.selected = false
end
@ -486,7 +487,7 @@ end
-- @param i The relative index to see.
-- @param[opt] screen The screen number.
function tag.viewidx(i, screen)
local screen = screen or capi.mouse.screen
local screen = screen or ascreen.focused()
local tags = tag.gettags(screen)
local showntags = {}
for k, t in ipairs(tags) do
@ -551,7 +552,7 @@ end
-- @param tags A table with tags to view only.
-- @param[opt] screen The screen number of the tags.
function tag.viewmore(tags, screen)
local screen = screen or capi.mouse.screen
local screen = screen or ascreen.focused()
local screen_tags = tag.gettags(screen)
for _, _tag in ipairs(screen_tags) do
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())
end
else
c.screen = capi.mouse.screen
c.screen = ascreen.focused()
end
end
c:connect_signal("property::screen", tag.withcurrent)

View File

@ -298,7 +298,7 @@ function menubar.show(scr)
end
-- 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 geometry = menubar.geometry
instance.geometry = {x = geometry.x or scrgeom.x,