Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename awful.popup hide_on_right_click property to hide_on_click #3665

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/common/object.ldoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@
-- @method weak_connect_signal
-- @noreturn
-- @baseclass gears.object

--- Check if the callback is connected to the signal.
--
-- This function check both kind of signal connection (strong and weak).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-- This function check both kind of signal connection (strong and weak).
-- This function checks both kinds of signal connection (strong and weak).

--
-- @tparam string name The name of the signal.
-- @tparam function func The callback to check if connected.
-- @treturn boolean Whether the signal is connected.
-- @method is_signal_connected
-- @baseclass gears.object
40 changes: 30 additions & 10 deletions lib/awful/popup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
-- @supermodule wibox
---------------------------------------------------------------------------
local wibox = require( "wibox" )
local gdebug = require( "gears.debug" )
local gtable = require( "gears.table" )
local placement = require( "awful.placement" )
local xresources= require("beautiful.xresources")
Expand Down Expand Up @@ -297,17 +298,28 @@ function popup:unbind_to_widget(widget)
widget:disconnect_signal("button::press", self._private.show_fct)
end

--- Hide the popup when right clicked.
--- Hide the popup when clicked inside.
--
-- @property hide_on_right_click
-- @tparam[opt=false] boolean hide_on_right_click
-- @property hide_on_click
-- @tparam[opt=false] boolean hide_on_click
-- @propemits true false

function popup:set_hide_on_right_click(value)
function popup:set_hide_on_click(value)
self[value and "connect_signal" or "disconnect_signal"](
self, "button::press", self._private.hide_fct
self,
"button::press",
self._private.hide_fct
)
self:emit_signal("property::hide_on_click", value)
end
function popup:set_hide_on_right_click(value)
gdebug.deprecate(
"Use popup:set_hide_on_click() instead of set_hide_on_right_click",
{ deprecated_in = 4 }
)
self:emit_signal("property::hide_on_right_click", value)
self:set_hide_on_click(value)
end
function popup:get_hide_on_click()
return self:is_signal_connected("button::press", self._private.hide_fct)
end

--- The popup minimum width.
Expand Down Expand Up @@ -453,8 +465,8 @@ end
-- @tparam string|table args.preferred_positions
-- @tparam string|table args.preferred_anchors
-- @tparam table|number args.offset The X and Y offset compared to the parent object
-- @tparam boolean args.hide_on_right_click Whether or not to hide the popup on
-- right clicks.
-- @tparam boolean args.hide_on_click Whether or not to hide the popup on
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about turning it from boolean into int, so user could choose the mouse button?

-- clicks.
-- @constructorfct awful.popup
local function create_popup(_, args)
assert(args)
Expand Down Expand Up @@ -509,12 +521,20 @@ local function create_popup(_, args)
-- when set_position is called before the limits
for _,v in ipairs{"minimum_width", "minimum_height", "maximum_height",
"maximum_width", "offset", "placement","preferred_positions",
"preferred_anchors", "hide_on_right_click"} do
"preferred_anchors", "hide_on_right_click", "hide_on_click"} do
if args[v] ~= nil then
w["set_"..v](w, args[v])
end
end

-- TODO : remove when we are ready to break backward compatibility
if args.hide_on_right_click ~= nil then
gdebug.deprecate(
"Use the hide_on_click parameter instead of hide_on_right_click",
{ deprecated_in = 4 }
)
end

-- Default to visible
if args.visible ~= false then
w.visible = true
Expand Down
17 changes: 17 additions & 0 deletions lib/gears/object.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ function object:connect_signal(name, func)
sig.strong[func] = true
end

--- Check if the callback is connected to the signal.
--
-- This function check both kind of signal connection (strong and weak).
--
-- @tparam string name The name of the signal.
-- @tparam function func The callback to check if connected.
-- @treturn boolean Whether the signal is connected.
-- @method is_signal_connected
function object:is_signal_connected(name, func)
assert(
type(func) == "function",
"callback must be a function, got: " .. type(func)
)
local sig = find_signal(self, name)
return not not (sig and (sig.strong[func] or sig.weak[func]))
Comment on lines +76 to +77
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find_signal creates the entry when it doesn't exist, so you don't need to check if sig exists.

end

-- Register a global signal receiver.
function object:_connect_everything(callback)
table.insert(self._global_receivers, callback)
Expand Down
14 changes: 14 additions & 0 deletions spec/gears/object_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,20 @@ describe("gears.object", function()
object{enable_auto_signals=true, enable_properties=false}
end)
end)

it("is_signal_connected", function()
local cb = function()end
assert.is_false(obj:is_signal_connected("signal", cb))
obj:connect_signal("signal", cb)
assert.is_true(obj:is_signal_connected("signal", cb))
end)

it("is_weak_signal_connected", function()
local cb = function()end
assert.is_false(obj:is_signal_connected("signal", cb))
obj:weak_connect_signal("signal", cb)
assert.is_true(obj:is_signal_connected("signal", cb))
end)
end)

-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
38 changes: 38 additions & 0 deletions tests/test-awful-popup-hide-on-click.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
local runner = require "_runner"
local base = require "wibox.widget.base"
local popup = require "awful.popup"

local widget = base.make_widget()
local p = popup { widget = widget }

local function click(x, y)
return function()
mouse.coords { x = x, y = y }
assert(mouse.coords().x == x and mouse.coords().y == y)
root.fake_input("button_press", 1)
awesome.sync()
root.fake_input("button_release", 1)
awesome.sync()
return true
end
end

runner.run_steps {
function()
assert(p.visible)
assert(not p.hide_on_click)
return true
end,
click(p.x, p.y),
function()
assert(p.visible)
p.hide_on_click = true
return true
end,
click(p.x, p.y),
function()
assert(not p.visible)
assert(p.hide_on_click)
return true
end,
}