menubar: Support screen objects

This commit makes meanubar accept a screen object everywhere where a screen
index is accepted.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2016-02-26 18:25:55 +01:00
parent 20e13602de
commit d9f4ed9fb6
2 changed files with 13 additions and 6 deletions

View File

@ -31,6 +31,10 @@ local common = require("awful.widget.common")
local theme = require("beautiful") local theme = require("beautiful")
local wibox = require("wibox") local wibox = require("wibox")
local function get_screen(s)
return s and capi.screen[s]
end
-- menubar -- menubar
local menubar = { mt = {}, menu_entries = {} } local menubar = { mt = {}, menu_entries = {} }
menubar.menu_gen = require("menubar.menu_gen") menubar.menu_gen = require("menubar.menu_gen")
@ -122,9 +126,10 @@ end
--- Cut item list to return only current page. --- Cut item list to return only current page.
-- @tparam table all_items All items list. -- @tparam table all_items All items list.
-- @tparam str query Search query. -- @tparam str query Search query.
-- @tparam number scr Screen number -- @tparam number|screen scr Screen
-- @return table List of items for current page. -- @return table List of items for current page.
local function get_current_page(all_items, query, scr) local function get_current_page(all_items, query, scr)
scr = get_screen(scr)
if not instance.prompt.width then if not instance.prompt.width then
instance.prompt.width = compute_text_width(instance.prompt.prompt, scr) instance.prompt.width = compute_text_width(instance.prompt.prompt, scr)
end end
@ -161,7 +166,7 @@ end
--- Update the menubar according to the command entered by user. --- Update the menubar according to the command entered by user.
-- @tparam str query Search query. -- @tparam str query Search query.
-- @tparam number scr Screen number -- @tparam number|screen scr Screen
local function menulist_update(query, scr) local function menulist_update(query, scr)
query = query or "" query = query or ""
shownitems = {} shownitems = {}
@ -288,7 +293,7 @@ local function prompt_keypressed_callback(mod, key, comm)
end end
--- Show the menubar on the given screen. --- Show the menubar on the given screen.
-- @param scr Screen number. -- @param scr Screen.
function menubar.show(scr) function menubar.show(scr)
if not instance.wibox then if not instance.wibox then
initialize() initialize()
@ -300,6 +305,7 @@ function menubar.show(scr)
-- Set position and size -- Set position and size
scr = scr or awful.screen.focused() or 1 scr = scr or awful.screen.focused() or 1
scr = get_screen(scr)
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,

View File

@ -12,6 +12,7 @@ local io = io
local table = table local table = table
local ipairs = ipairs local ipairs = ipairs
local string = string local string = string
local screen = screen
local awful_util = require("awful.util") local awful_util = require("awful.util")
local theme = require("beautiful") local theme = require("beautiful")
local glib = require("lgi").GLib local glib = require("lgi").GLib
@ -257,17 +258,17 @@ end
--- Compute textbox width. --- Compute textbox width.
-- @tparam wibox.widget.textbox textbox Textbox instance. -- @tparam wibox.widget.textbox textbox Textbox instance.
-- @tparam number s Screen number -- @tparam number|screen s Screen
-- @treturn int Text width. -- @treturn int Text width.
function utils.compute_textbox_width(textbox, s) function utils.compute_textbox_width(textbox, s)
s = s or mouse.screen s = screen[s or mouse.screen]
local w, _ = textbox:get_preferred_size(s) local w, _ = textbox:get_preferred_size(s)
return w return w
end end
--- Compute text width. --- Compute text width.
-- @tparam str text Text. -- @tparam str text Text.
-- @tparam number s Screen number -- @tparam number|screen s Screen
-- @treturn int Text width. -- @treturn int Text width.
function utils.compute_text_width(text, s) function utils.compute_text_width(text, s)
return utils.compute_textbox_width(wibox.widget.textbox(awful_util.escape(text)), s) return utils.compute_textbox_width(wibox.widget.textbox(awful_util.escape(text)), s)