Dug this up for context: On Thu, Mar 1, 2012 at 9:38 PM, Uli Schlachter <[email protected]> wrote: > On 01.03.2012 10:52, Anurag Priyam wrote: >> On Wed, Feb 29, 2012 at 3:59 PM, Uli Schlachter <[email protected]> wrote: >>> Anyone out there who opens up a popup menu, then clicks somewhere else and >>> expects the menu to stay open? If yes, speak up now or stay quiet forever! >> >> Yeah, this is another thing that annoys me. Though I am not sure how >> I can fix it. I need to determine that mouse was clicked outside >> menu. So maybe I can attach a handler to 'press' signal on mouse, but >> if it was not clicked on any visible menu (not sure how to determine >> that), then close it? > > Would need a mouse grabber. When someone dares to click elsewhere, the grabber > is stopped and the menu closed. (And the click which caused that is discarded, > but that's also what gtk/qt are doing) > > But yeah, you are right. That'd stop the normal event processing and would > force > the code to do magic with mouse.object_under_pointer() (which should use the > mouse position at the time the event was sent, not the current position, but > that API can be fixed relatively easily).
I stumbled across an issue (bug?) with mousegrabber in an attempt to
fix this. This is how the patch (attached) looks like at the moment:
diff --git a/lib/awful/menu.lua.in b/lib/awful/menu.lua.in
index 8dd1763..7cf9238 100644
--- a/lib/awful/menu.lua.in
+++ b/lib/awful/menu.lua.in
@@ -28,6 +28,7 @@ local capi = {
mouse = mouse,
client = client,
keygrabber = keygrabber,
+ mousegrabber = mousegrabber,
awesome = awesome,
oocairo = oocairo }
@@ -323,6 +324,14 @@ function show(menu, args)
if not cur_menu then
capi.keygrabber.run(grabber)
+ capi.mousegrabber.run(function (mouse)
+ for _, v in ipairs(mouse.buttons) do
+ if v then
+ menu:hide()
+ end
+ end
+ return true
+ end, 'fleur')
end
cur_menu = menu
menu.wibox.visible = true
@@ -346,6 +355,7 @@ function hide(menu)
end
if not cur_menu then
capi.keygrabber.stop()
+ capi.mousegrabber.stop()
end
menu.wibox.visible = false
end
Open a menu. Move the cursor around; nothing happens. Click elsewhere;
the menu is now hidden (actually, clicking on the menu will hie menu
as well but let's forget it for the time being). Re-launch the menu.
Move the cursor around; it hides the menu ?! This behavior persists
till I restart awesome.
So I put in `gears.debug.dump(mouse.buttons, 'buttons')` in the
callback to mousegrabber the first thing and guess what I get each
time after first mouse click:
buttons : table: 0xb93c30
1 : true (boolean)
2 : false (boolean)
3 : false (boolean)
...
Once a button is clicked when mousegrabber was running, its state
remains the same. Is that expected?
Also, how can I pass a normal cursor to mousegrabger? I don't wan't
the cursor to change -- looks silly.
--
Anurag Priyam
0001-awful.menu-close-menu-if-clicked-outside-it.patch
Description: Binary data
