phillbush / xmenu

a x11 menu utility
Other
297 stars 26 forks source link

Run xmenu when a button is pressed #35

Open Ved-un opened 2 years ago

Ved-un commented 2 years ago

Hello. Thank you for the project!

Xmenu starts when a button or key is released - why is this so? Is it possible to change this behavior and make xmenu run when pressed?

this is normal behavior for any program...

aspizu commented 1 year ago

this is normal behavior for any program...

No, its not. Buttons usually activate when they are released.

phillbush commented 1 year ago

Menu items are actually activated when the mouse button is released. This is the intended behavior I knowingly implemented.
This allows the user to do a single click to both open the menu and to activate an item: pressing pops the menu up, releasing activates the item.
You can try it on your web browser. I tested in both Chrome and Firefox. That's how context menus work.

phillbush commented 1 year ago

Xmenu starts when a button or key is released - why is this so? Is it possible to change this behavior and make xmenu run when pressed?

Oh, are you talking about the menu popping up, not the item being activated?
If that's the case, that's only possible with the -x option, which makes xmenu watches for button presses and releases on the root window.

As far as I understand, when a button is pressed, the release event is only sent to the X client that got the pressing event.
So the only way for xmenu to get the release event is to have got the pressing event that precedes it, which is possible by watching the mouse button on the root window.

Ved-un commented 1 year ago

This allows the user to do a single click to both open the menu and to activate an item: pressing pops the menu up, releasing activates the item.

-- This is exactly the kind of behavior I need, but I can't get it.

The menu itself appears when I release the mouse button and I have to click again to select the menu item - that is, I have to make two clicks.

What's the reason I can't figure out...

Ved-un commented 1 year ago

I use sxhkd to assign keyboard shortcuts. example from sxhkdrc :

 super + Tab
    xmenu-3

and this is the xmenu-3 file itself :

#!/bin/sh

xmenu -i <<EOF | sh &
File pcmanfm-qt -n
Edit fpad -w
Htop sudo st -g 101x26 -e htop
Term st -g 101x26
EOF

Shouldn't the menu appear when you press super + Tab ? -- but my menu doesn't appear when I press super + Tab, it only appears when I release super + Tab

Ved-un commented 1 year ago

this is normal behavior for any program...

No, its not. Buttons usually activate when they are released.

You probably do not understand what I am talking about.

phillbush commented 1 year ago

-- but my menu doesn't appear when I press super + Tab, it only appears when I release super + Tab

xmenu also performs a keyboard grab in addition to a button grab
that is necessary for xmenu to be controlled by the keyboard (with arrow keys, tab, etc); and since xmenu is a override redirect window (that is, a window that manages itself rather than being managed by a window manager), it can not rely on the window manager for getting keyboard focus.
the grabbing is only performed after the key release is processed by the application that got the original key press (in this case, sxhkd).

you can avoid that by not relying on a caller like sxhkd: you can invoke xmenu from your ~/.xinitrc with the -x mod4-3 option, so either a Super+right mouse button press or a right mouse button press alone on the root window (the desktop) will pop the menu up.
in this case, xmenu will get the button/key press AND release, and can pop up its menu from the pressing.

Ved-un commented 1 year ago

you can avoid that by not relying on a caller like sxhkd: you can invoke xmenu from your ~/.xinitrc with the -x mod4-3 option, so either a Super+right mouse button press or a right mouse button press alone on the root window (the desktop) will pop the menu up.

Please tell me the full command I need to add to ~/.xinitrc to open my xmenu-3 with ONE right mouse button.

phillbush commented 1 year ago

replace your xmenu call in your script with this:

xmenu -i -x mod4-3 <<EOF | sh &

then invoke your script directly in your .xinitrc

Ved-un commented 1 year ago

It's not working ( I changed my script as you said to xmenu -i -x mod4-3 <<EOF | sh & and ran it from the terminal (xmenu-3 &)

Now the menu appears on Super+button3 (and I need only on button 3) and even so, but the items in the menu are selected but now they do not work.

I probably give up and uninstall xmenu, I don't know what to do to solve this simple problem - to open a menu item with a single mouse click, as it is done in openbox...

Ved-un commented 1 year ago

The menu should appear when you click, and then, without releasing the mouse button, you select an item from the menu and then release this button - to run the selected item from the menu...

phillbush commented 1 year ago

Does it work as expected on the desktop (root menu) without using the Super key, only with the button 3?

Btw, is your numlock activated? If it is, I have just found a bug on xmenu that may cause that.

Ved-un commented 1 year ago

I apologize for the delay. I'm using a wireless keyboard and it doesn't have a numlock with a number pad. Now I'll try to connect a regular keyboard and see.

Ved-un commented 1 year ago

No, it still does not work with another keyboard (numlock disabled).

I will try to describe the problem more precisely.

Required behavior: press (menu appears) > select > release

I have a menu file created called xmenu-3:

#!/bin/sh

xmenu -i <<EOF | sh &
File pcmanfm-qt -n
Edit fpad -w
Htop sudo st -g 101x26 -e htop
Term st -g 101x26
EOF

In sxhkdrc I've binded the third mouse button to start xmenu-3 and this menu appears in the root window of the desktop, but it appears when I release the mouse button and not when I press it - so I can't select a menu item without releasing the mouse button...

Next... I changed the xmenu-3 file as you told me:

#!/bin/sh

xmenu -i -x mod4-3 <<EOF | sh &
File pcmanfm-qt -n
Edit fpad -w
Htop sudo st -g 101x26 -e htop
Term st -g 101x26
EOF

And added xmenu-3 autorun to the .xinitrc: xmenu-3 &

flameshot_360

After that, my menu appears in the root window of the desktop only when I press mod4 and the third mouse button, but it appears as it should - exactly when you press it, not as it was. (Then the menu items can be selected, but they still do not work)

Besides I do not need this mod4, and need only a click on the third mouse button.

========

Information about my system: Arch Linux bspwm & sxhkd

sorry about the translator, my english is not very good

phillbush commented 1 year ago

That seems a weird behavior.

Have you removed the xmenu entry from sxhkd?
With the -x option, xmenu can open menus by itself.

Ved-un commented 1 year ago

Have you removed the xmenu entry from sxhkd?

Yes, of course, I checked everything.

And even tried a session with sxhkd disabled - same thing, The menu still appears only when I press mod4 together with the right mouse button and the menu items are selected, but they don't work...

Why do you have mod4 in this line? xmenu -i -x mod4-3 <<EOF | sh & the number 3, as I understand it, is the number of the mouse button.

I don't even know where to dig anymore... I'm still struggling with this menu :)) , i would like to get it to work ! :))

Ved-un commented 1 year ago

Experimented a little with the script xmenu -i -x mod4-3 <<EOF | sh &

With different mods and different mouse buttons the behavior is the same as I described above, BUT what is interesting it does not distinguish whether it is the root of the desktop or it is a normal program window i.e. the menu appears both there and there. This is not suitable to work without using the mod key.

=========

And what kind of program do you have? - xclickroot maybe this program is better used to call the xmenu on the desktop?

Ved-un commented 1 year ago

In bspwm xclickroot doesn't work either, nor does xmenu -x.

Tried it in my openbox: xclickroot works, but again the menu appears when releasing the mouse button. xmenu -x works as it should, but the menu items don't work (selectable but not triggered)

Damn it! ))))))

Ved-un commented 1 year ago

I also have WMs here cwm dk spectrwm

Maybe I'll try them later, if I don't get bored with the whole thing )))

phillbush commented 1 year ago

That behavior is expected for xclickroot, as it grabs the button press and xmenu could not watch the press-then-release events.

But for the -x option, i do not know how i can help, because i could not reproduce the error here.

I'm rewriting xmenu from scratch, changing most of the code base and most of the logic in it.
As my efforts are into this new version; and the bug may be in the old code, I hope the issue gets solved in this new version.

Meanwhile, the only I can do is to recommend you a different application like https://github.com/jgmenu/jgmenu

Ved-un commented 1 year ago

Hello, it's me again.

An interesting observation.

I recently started using XNOTIFY (.actionbutton = Button1 in my XNOTIFY config) and what I noticed: clicking 3 button on the message box for some reason appears XMENU, but the most interesting thing is that it works as it should - clicked > selected > released

Let me remind you that on the root window XMENU appears only when I release 3 button

Maybe this will give you some ideas?

Ved-un commented 1 year ago

Thanks for the advice, but I used JGMENU before - it consumes memory in the background and also does not work selecting a menu item on releasing the button, that's why I switched to XMENU - it is simple and does not consume in the background.

Well, I'm already used to XMENU and used to double-click ) so I will only use it or I will give up any menus...

Ved-un commented 1 year ago

Now I tried HERBE and the behavior is the same as with XNOTIFY - right-clicking on the message box XMENU works as it should.

It turns out that the real root window is not recognized, but the XNOTIFY and HERBE windows are recognized as the root window...

Interesting all this

phillbush commented 1 year ago

Hi, I made a change in xclickroot and now it ungrabs the pointer after pressing a button.
This can, theoretically, make xmenu aware of the pointer right after the button is pressed.

Can you check if your problem is solved with this new xclickroot?

With xclickroot you do not need xmenu's -x option.

Ved-un commented 1 year ago

Thank you. I will try it a little later.

Ved-un commented 1 year ago

Unfortunately in BSPWM the xclickroot -3 xterm & does not work (I tried different buttons -1 -2 -3) pressing the button in the root (and any) window xterm does not start and kills the xclickroot -3 xterm process.

flameshot_010

I decided to try it in OPENBOX - in it xclickroot works as it should in the root window, But as soon as I click in any window other than the root window, the same thing happens - xclickroot -3 xterm kills the process

phillbush commented 1 year ago

But as soon as I click in any window other than the root window, the same thing happens - xclickroot -3 xterm kills the process

Oh, sorry about that. It was supposed to continue the loop when clicking on a non-root window, rather than breaking the loop. The last commit on xclickroot fixes that line.

Ved-un commented 1 year ago

Yay In OPENBOX everything worked as it should, thank you, although it has its own built-in menu.

But I use BSPWM on a daily basis and it still doesn't work.

What is even the difference between them? I have two other WMs - can I try them or is it something to do with SXHKD

Ved-un commented 1 year ago

A little later I will try xclickroot in other WMs - SpectrWM and DK. There must be a reason why it doesn't work

P.S. I think there is a problem with tiled WMs - in them xclickroot probably does not recognize the root window, apparently they have some difference in the root window compared to floating WMs

Ved-un commented 1 year ago

Now I have tried other WMs

In DK wm and Openbox xclickroot works as it should, but in SpectrWM as well as in BSPWM - it doesn't work.

Okay, I won't torture you, I'll leave it as it is. Thank you for your time and effort.

phillbush commented 1 year ago

That's weir indeed.
I'm going to try other wms and see what can I do on xmenu or xclickroot side.