From ecd3a57fb811a4ae071c9ccdbe35d9cfd996991a Mon Sep 17 00:00:00 2001 From: crater2150 Date: Thu, 19 Feb 2015 11:11:15 +0100 Subject: [PATCH] modalbind: allow setting of position --- modalbind.lua | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/modalbind.lua b/modalbind.lua index 704d0b3..1cc9865 100644 --- a/modalbind.lua +++ b/modalbind.lua @@ -97,15 +97,41 @@ function set_show_options(bool) end modalbind.set_show_options = set_show_options -local function set_default(s) +local function set_default(s, position) minwidth, minheight = modewidget[s]:fit(screen[s].geometry.width, screen[s].geometry.height) modewibox[s].width = minwidth + 1; modewibox[s].height = math.max(settings.height, minheight) - modewibox[s].x = settings.x_offset < 0 and - screen[s].geometry.x - width + settings.x_offset or - settings.x_offset - modewibox[s].y = screen[s].geometry.height - modewibox[s].height + if position then + modewibox[s].x = getXOffset(s, position) + modewibox[s].y = getYOffset(s, position) + else + modewibox[s].x = settings.x_offset < 0 and + screen[s].geometry.x - modewibox[s].width + settings.x_offset or + settings.x_offset + modewibox[s].y = screen[s].geometry.height - modewibox[s].height + end +end + +local function getXOffset(s,position) + if type(position) == "table" then + return position.x + elseif position == "topleft" or position == "bottomleft" then + return 0 + elseif position == "topright" or position == "bottomright" then + return screen[s].geometry.x - modewibox[s].width + end +end + + +local function getYOffset(s,position) + if type(position) == "table" then + return position.y + elseif position == "topleft" or position == "topright" then + return 0 + elseif position == "bottomleft" or position == "bottomright" then + return screen[s].geometry.y - modewibox[s].height + end end local function ensure_init()