wmutils / opt

optional addons to wmutils
Other
114 stars 24 forks source link

xmmv doesn't work properly when called from polybar #43

Closed emanuele6 closed 5 years ago

emanuele6 commented 5 years ago

When xmmv is called from polybar, it does not work properly: the window follows the cursor, but the window is not placed on keydown: the keydown just "goes to the window" (you will have to run killall xmmv to "place the window")

How to reproduce

  1. create a script which calls xmmv (/path/to/script):
    
    #!/bin/bash

xmmv

2. create a button in polybar:

[module/my_button] type = custom/text content = I_AM_A_BUTTON click-left = /path/to/script

if you don't know how to use polybar or you just don't use it, use this minimal config file (/path/to/cfg):

[bar/minimal] modules-center = my_button

[module/my_button] type = custom/text content = I_AM_A_BUTTON click-left = /path/to/script

launch polybar by running this command `polybar -c /path/to/cfg minimal`

NOTE:
I found this bug while making a bspwm script, in which I passed an argument to `xmmv`, so the lack of arguments is not the issue.  
I also tried `xmmv "$(pfw)"`, `xmmv &`, `xmmv & disown`, they don't fix anything.
The output of `pfw` is correct even when launched with polybar: I checked it with this script  
/path/to/script:
```bash
#!/bin/bash

wid="$(pfw)"
notify-send "$wid"
xmmv "$wid"

EDIT: In order to reproduce the bug you also need to make /path/to/script executable: chmod +x /path/to/script
I also tried:

#!/bin/bash

wid="$(pfw)"
wtf "$wid"
xmmv "$wid"

but it didn't fix the issue. And I also tried:

#!/bin/bash

wid="$(pfw)"
sleep 2
xmmv "$wid"

I clicked on the window during the 2 seconds of sleep and it did fix the issue.

z3bra commented 5 years ago

The issue there is most likely that the "button down" event is registered by polybar and not xmmv. I only read the code quickly, but it seems that xmmv has to register for the button down event to start moving the window "dynamically".

Try to force a "button up" event in your script before calling xmmv, eg. with xdo. That could work.

emanuele6 commented 5 years ago

The issue there is most likely that the "button down" event is registered by polybar and not xmmv.

As I said the "button down" event seems to be registered by the window that is being moved ("goes to the window"): if I am moving a terminal, I can highlight lines with double click; if I am moving a browser window, I can click on links.

Try to force a "button up" event in your script before calling xmmv, eg. with xdo. That could work.

I am not sure on how to do that with xdo, I used xdotool instead, but it didn't work.

#!/bin/bash

wid="$(pfw)"
xdotool mouseup 1
xmmv "$wid"

EDIT: I figured out how to use xdo button_release, it doesn't work:

#!/bin/bash

wid="$(pfw)"
xdo button_release -k 1
xmmv "$wid"
z3bra commented 5 years ago

The issue is that xmmv doesn't work if you call it while a mouse button is held down. If you try it in a terminal console, you'll reproduce the bug you encounter with your bar.

A hack is to modify the bar to call the program on BUTTON_RELEASE rather than BUTTON_PRESS. This is only a hack though.

I don't know why we get such a behavior. This is probably related to the fact we grab the event from the root window. But I honestly have no clue where to look at now.

z3bra commented 5 years ago

So I looked into this, and this is not an issue with xmmv by itself. In order to do its job, xmmv must grab the pointer on the root windows to detect any move it does. Under X11, you simply cannot grab the pointer while a button is down.

In your case, the only possibke fix are as follow:

I'm closing this issue asit is not a bug in xmmv.