From 1bd4a54d540e79908cc9ae2c170b19a31d296516 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Fri, 9 Aug 2013 01:42:28 -0400 Subject: [PATCH] Prevent menus from being off screen --- context.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/context.lua b/context.lua index 8ec51e8..5c14759 100644 --- a/context.lua +++ b/context.lua @@ -39,12 +39,13 @@ end local function set_position(self) local ret,parent = {x=self.wibox.x,y=self.wibox.y},self.parent_geometry local prefx,prefy = self._internal.private_data.x,self._internal.private_data.y + local src_geo = capi.screen[capi.mouse.screen].geometry if parent and parent.is_menu then if parent.direction == "right" then ret={x=parent.x-self.width,y=parent.y+(self.parent_item.y)} else ret={x=parent.x+parent.width,y=parent.y+(self.parent_item.y)- (parent.show_filter and parent.item_height or 0)} - if ret.y+self.height > capi.screen[capi.mouse.screen].geometry.height then + if ret.y+self.height > src_geo.height then ret.y = ret.y - self.height + self.item_height end end @@ -71,13 +72,18 @@ local function set_position(self) if self.direction == "top" or self.direction == "bottom" then ret.x = ret.x - (self.arrow_x or 20) - 13 ret.y = geometry.y+geometry.height - if ret.y+self.height > capi.screen[capi.mouse.screen].geometry.height then + if ret.y+self.height > src_geo.height then self.direction = "bottom" ret.y = geometry.y-self.height end end end end + if ret.x+self.width > src_geo.x + src_geo.width then + ret.x = ret.x - (ret.x+self.width - (src_geo.x + src_geo.width)) + elseif ret.x < 0 then + ret.x = 0 + end self.wibox.x = ret.x self.wibox.y = ret.y - 2*(self.wibox.border_width or 0) end