diff --git a/lib/naughty/core.lua b/lib/naughty/core.lua index 98bbb08fb..f21a20a5c 100644 --- a/lib/naughty/core.lua +++ b/lib/naughty/core.lua @@ -151,6 +151,7 @@ screen.connect_for_each_screen(function(s) bottom_left = {}, bottom_middle = {}, bottom_right = {}, + middle = {}, } end) @@ -537,7 +538,7 @@ end -- @tparam[opt=focused] integer|screen args.screen Target screen for the notification. -- @string[opt="top_right"] args.position Corner of the workarea displaying the popups. -- Values: `"top_right"`, `"top_left"`, `"bottom_left"`, --- `"bottom_right"`, `"top_middle"`, `"bottom_middle"`. +-- `"bottom_right"`, `"top_middle"`, `"bottom_middle"`, `"middle"`. -- @bool[opt=true] args.ontop Boolean forcing popups to display on top. -- @int[opt=`beautiful.notification_height` or auto] args.height Popup height. -- @int[opt=`beautiful.notification_width` or auto] args.width Popup width. diff --git a/lib/naughty/layout/legacy.lua b/lib/naughty/layout/legacy.lua index c7a76b48a..530351c35 100644 --- a/lib/naughty/layout/legacy.lua +++ b/lib/naughty/layout/legacy.lua @@ -54,14 +54,37 @@ screen.connect_for_each_screen(function(s) bottom_left = {}, bottom_middle = {}, bottom_right = {}, + middle = {}, } end) +--- Sum heights of notifications at position +-- +-- @param s Screen to use +-- @param position top_right | top_left | bottom_right | bottom_left +-- | top_middle | bottom_middle | middle +-- @param[opt] idx Index of last notification +-- @return Height of notification stack with spacing +local function get_total_heights(s, position, idx) + local sum = 0 + local notifications = current_notifications[s][position] + idx = idx or #notifications + for i = 1, idx, 1 do + local n = notifications[i] + + -- `n` will not nil when there is too many notifications to fit in `s` + if n then + sum = sum + n.height + naughty.config.spacing + end + end + return sum +end + --- Evaluate desired position of the notification by index - internal -- -- @param s Screen to use -- @param position top_right | top_left | bottom_right | bottom_left --- | top_middle | bottom_middle +-- | top_middle | bottom_middle | middle -- @param idx Index of the notification -- @param[opt] width Popup width. -- @param height Popup height @@ -83,21 +106,16 @@ local function get_offset(s, position, idx, width, height) end -- calculate existing popups' height - local existing = 0 - for i = 1, idx-1, 1 do - local n = current_notifications[s][position][i] - - -- `n` will not nil when there is too many notifications to fit in `s` - if n then - existing = existing + n.height + naughty.config.spacing - end - end + local existing = get_total_heights(s, position, idx-1) -- calculate y if position:match("top") then v.y = ws.y + naughty.config.padding + existing - else + elseif position:match("bottom") then v.y = ws.y + ws.height - (naughty.config.padding + height + existing) + else + local total = get_total_heights(s, position) + v.y = ws.y + (ws.height - total) / 2 + naughty.config.padding + existing end -- Find old notification to replace in case there is not enough room. diff --git a/lib/naughty/notification.lua b/lib/naughty/notification.lua index f01124bd8..792a4ae93 100644 --- a/lib/naughty/notification.lua +++ b/lib/naughty/notification.lua @@ -105,6 +105,7 @@ local notification = {} -- * *bottom_right* -- * *top_middle* -- * *bottom_middle* +-- * *middle* -- --@DOC_awful_notification_corner_EXAMPLE@ -- @@ -414,7 +415,7 @@ end -- @tparam[opt=focused] integer|screen args.screen Target screen for the notification. -- @string[opt="top_right"] args.position Corner of the workarea displaying the popups. -- Values: `"top_right"`, `"top_left"`, `"bottom_left"`, --- `"bottom_right"`, `"top_middle"`, `"bottom_middle"`. +-- `"bottom_right"`, `"top_middle"`, `"bottom_middle"`, `"middle"`. -- @bool[opt=true] args.ontop Boolean forcing popups to display on top. -- @int[opt=`beautiful.notification_height` or auto] args.height Popup height. -- @int[opt=`beautiful.notification_width` or auto] args.width Popup width. diff --git a/tests/examples/awful/notification/corner.lua b/tests/examples/awful/notification/corner.lua index 9cbc91287..539d0b773 100644 --- a/tests/examples/awful/notification/corner.lua +++ b/tests/examples/awful/notification/corner.lua @@ -8,6 +8,7 @@ for _, pos in ipairs { "bottom_left", "bottom_middle", "bottom_right", + "middle", } do naughty.notify { title = pos, diff --git a/tests/test-naughty-legacy.lua b/tests/test-naughty-legacy.lua index 160e5fc51..129681916 100644 --- a/tests/test-naughty-legacy.lua +++ b/tests/test-naughty-legacy.lua @@ -342,6 +342,7 @@ end local positions = { "top_left" , "top_middle" , "top_right" , "bottom_left" , "bottom_middle" , "bottom_right" , + "middle" , } -- Test each corners.