From d9f4ed9fb60b64b3095081dd853122e96fe4ecf7 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Fri, 26 Feb 2016 18:25:55 +0100 Subject: [PATCH] menubar: Support screen objects This commit makes meanubar accept a screen object everywhere where a screen index is accepted. Signed-off-by: Uli Schlachter --- lib/menubar/init.lua | 12 +++++++++--- lib/menubar/utils.lua | 7 ++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/menubar/init.lua b/lib/menubar/init.lua index 53e94eb17..cd1199a1b 100644 --- a/lib/menubar/init.lua +++ b/lib/menubar/init.lua @@ -31,6 +31,10 @@ local common = require("awful.widget.common") local theme = require("beautiful") local wibox = require("wibox") +local function get_screen(s) + return s and capi.screen[s] +end + -- menubar local menubar = { mt = {}, menu_entries = {} } menubar.menu_gen = require("menubar.menu_gen") @@ -122,9 +126,10 @@ end --- Cut item list to return only current page. -- @tparam table all_items All items list. -- @tparam str query Search query. --- @tparam number scr Screen number +-- @tparam number|screen scr Screen -- @return table List of items for current page. local function get_current_page(all_items, query, scr) + scr = get_screen(scr) if not instance.prompt.width then instance.prompt.width = compute_text_width(instance.prompt.prompt, scr) end @@ -161,7 +166,7 @@ end --- Update the menubar according to the command entered by user. -- @tparam str query Search query. --- @tparam number scr Screen number +-- @tparam number|screen scr Screen local function menulist_update(query, scr) query = query or "" shownitems = {} @@ -288,7 +293,7 @@ local function prompt_keypressed_callback(mod, key, comm) end --- Show the menubar on the given screen. --- @param scr Screen number. +-- @param scr Screen. function menubar.show(scr) if not instance.wibox then initialize() @@ -300,6 +305,7 @@ function menubar.show(scr) -- Set position and size scr = scr or awful.screen.focused() or 1 + scr = get_screen(scr) local scrgeom = capi.screen[scr].workarea local geometry = menubar.geometry instance.geometry = {x = geometry.x or scrgeom.x, diff --git a/lib/menubar/utils.lua b/lib/menubar/utils.lua index 80edc7534..65d174fb6 100644 --- a/lib/menubar/utils.lua +++ b/lib/menubar/utils.lua @@ -12,6 +12,7 @@ local io = io local table = table local ipairs = ipairs local string = string +local screen = screen local awful_util = require("awful.util") local theme = require("beautiful") local glib = require("lgi").GLib @@ -257,17 +258,17 @@ end --- Compute textbox width. -- @tparam wibox.widget.textbox textbox Textbox instance. --- @tparam number s Screen number +-- @tparam number|screen s Screen -- @treturn int Text width. 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) return w end --- Compute text width. -- @tparam str text Text. --- @tparam number s Screen number +-- @tparam number|screen s Screen -- @treturn int Text width. function utils.compute_text_width(text, s) return utils.compute_textbox_width(wibox.widget.textbox(awful_util.escape(text)), s)