BunsenLabs / bunsen-utilities

https://pkg.bunsenlabs.org/debian/pool/main/b/bunsen-utilities/
GNU General Public License v3.0
31 stars 21 forks source link

bl-kb does not handle Keybinds wih multiple actions #63

Closed thierrybo closed 5 years ago

thierrybo commented 6 years ago

Hi,

If you create an action in rc.xml like this:


    <keybind key="W-Left">
      <action name="UnmaximizeFull"/>
      <action name="MaximizeVert"/>
      <action name="MoveResizeTo">
        <width>50%</width>
        <x>0</x>
        <y>0</y>
      </action>
    </keybind>

bl-kb will not handle it correctly and it will not appear in Keybindings list. It seems that it is any Keybinding with more that one action that cause this issue.

Regards,

TB

johnraff commented 6 years ago

@thierrybo thank you for reporting this.

I have just confirmed on my own system, although in my case the keybinding is displayed, but with only the first defined action. Example:

    <keybind key="W-Left">
      <action name="ToggleMaximize"><direction>vertical</direction></action>
      <action name="Raise"/>
      <action name="MoveResizeTo">
        <width>50%</width>
        <x>0</x>
        <y>0</y>
      </action>
    </keybind>

Anyway, we must see if there's an easy fix for this.

ghost commented 6 years ago

The bug is very simple. https://github.com/BunsenLabs/bunsen-utilities/blob/helium/bin/bl-kb#L82 drops all but the first <action> node among the children but it needs to handle the case of multiple <action>s inside a <keybind>.

johnraff commented 6 years ago

Assigned the author @capn-damo to this issue.

ghost commented 5 years ago

@johnraff @capn-damo

I've rewritten bl-kb to take multiple actions in account (porting it to Python 3 at the same time). Could you perhaps test bl-kb from the branch wip-bl-kb-rewrite of this repository? I'm a bit unsure if bl-kb-pipemenu handles the spaces in the rightmost column when aggregating actions as described below.

ghost commented 5 years ago

To add: I've so far also excluded this change by damo from a while back: https://github.com/BunsenLabs/bunsen-utilities/commit/83b4d195e9784d94cad5c577c233aba6e7d2fce6#diff-2c4ff6649c36fff457c276471576ed78 since because auf action aggregation as implemented now, the output speaks the 'truth' about all configured keybindings, and because linked change would only prevent UnmaximizeFull to appear, not MaximizeVert and so on. If you Openbox users like to get all tiling actions and suchlike excluded, then it can be done easily. Just let me know your preference.

johnraff commented 5 years ago

"Display keybinds in new window" correctly outputs the contents of my rc.xml to yad, similarly to your example. ie bl-kb --gui seems to be OK.

However, there are issues with the --keybinds option of bl-kb-pipemenu, ie bl-kb with no option.

1) Biggest, it overwrites rc.xml with the same keybinds content.

2) The output menu, when displayed, still fails to show multiple actions, or anything at all for W-A-left. The keybinds.txt file which is generated does not contain the correct data.

OK, now found line 165 should reference kbinds.txt, not rc.xml:

    ap.add_argument("--openbox-kbinds",
            default="{}/.config/openbox/kbinds.txt".format(os.getenv("HOME", "/root")),
            help="Output file to save the keybind list to")

But even fixing that, multiple actions or the W-A-left binding are still not shown. kbinds.txt is now OK so emit_textfile() and emit_gui() are working. There might be a problem with keybind2lines()?

ghost commented 5 years ago

Biggest, it overwrites rc.xml with the same keybinds content.

That was a mistake in the option parser; fixed. openbox-kbinds pointed to the wrong path (the RC file (I'm not using the defaults)).

When you run bl-kb alone (either --gui or without) it should show the correct setup. I think the output format is fine this way; bl-kb-pipemenu is probably choking on https://github.com/BunsenLabs/bunsen-pipemenus/blob/helium/bin/bl-kb-pipemenu#L84 and https://github.com/BunsenLabs/bunsen-pipemenus/blob/helium/bin/bl-kb-pipemenu#L93 where it accepts only exeactly three fields while bl-kb outputs nice-to-read keybind listings for your 'problematic' key like so

o W-A-Left              UnmaximizeFull, MaximizeVert, MoveResizeTo

which would be hard to read if we removed the space between the , and the text. Maybe quoting does work (seems to work with the x actions (executable actions)). I need to get OB running to test for myself it looks like.

johnraff commented 5 years ago

Biggest, it overwrites rc.xml with the same keybinds content.

That was a mistake in the option parser; fixed. openbox-kbinds pointed to the wrong path (the RC file (I'm not using the defaults)).

Where have you fixed this? Line 165 is still wrong, I think: https://github.com/BunsenLabs/bunsen-utilities/blob/wip-bl-kb-rewrite/bin/bl-kb#L165 Anyway, if that line is fixed, then bl-kb does its job OK - the problem is with bl-kb-pipemenu.

The generated xml in fact looks fine in a terminal, so it must be an Openbox escaping issue.

        <item label="W-A-Left             UnmaximizeFull, MaximizeVert, MoveResizeTo">
            <action name="Execute">
                <command>
                    echo &gt;/dev/null 2&gt;&amp;1
                </command>
            </action>
        </item>

Anyway, the outputted menu is not as neat as the code clearly means it to be. Openbox is changing the spacing, and dropping everything after the first comma. This can be confirmed by hardcoding a string on line 86 of bl-kb-pipemenu.

ghost commented 5 years ago

Forgot to push.

For the rest (the alignment) I need to install BL myself. I don't see why a comma would need escaping; it's not a magic XML character. Perhaps it is the label length? I'll see.

johnraff commented 5 years ago

Apologies - the menu is now OK - thanks! Halfway through my testing I forgot to check between jgmenu and openbox's native rendering.

The comma issue is with jgmenu's xml parsing, and I'll pass it over to @johanmalm

The alignment issue is simply the proportional font. If Openbox is set to use a monospace font for menu items then everything lines up nicely. I doubt if there's anything more we can do about that. EDIT: Adding the encoded tab character &#x9; does improve alignment with proportional fonts, but cannot be passed through our xml escape function because the ampersand will become literal. Probably too much trouble. Meanwhile xml:space="preserve" seems not to be supported.

I've just confirmed the latest bl-kb copied from wip-bl-kb-rewrite results in a working keybinds menu. Would you like to merge it into helium and close this issue?

ghost commented 5 years ago

@johnraff Thank you for double-checking. I squashed the branch and opened a pull requeset (#64).

I'm always open to improving the menu, but if you don't know a trick how to improve the pipemenu layout short of using a proportional font (ideally, we'd have something like 'expanding tabs/spacers' to put between key and action description, like LaTeX's \hfill) it solves the current issue and therefore is merge-ready.

johanmalm commented 5 years ago

Nice rewrite @2ion

Openbox doesn't appear to use pango-markup. Otherwise we might have been able to do a "pango table" or similar to tabulate.

Anyway, I've fixed the shortcoming in jgmenu 2f6e6eba

johanmalm commented 5 years ago

^ Ignore last, I misread. "Pango tables" is something different.

I've played around a bit with pango_layout_set_tabs() and jgmenu. I think we could easily tidy it up to look like this...

2018-11-21-220652_1024x600_scrot

ghost commented 5 years ago

@johanmalm ^ Looking good (no idea how it looked before, I've done this blind).

Let me know if I have to change something, and if yes what I have to change in the output of bl-kb to make things work smoothly at your end.

johanmalm commented 5 years ago

@2ion bl-kb shouldn’t need to change. I think I’ll just replace a group of spaces with a tab in the ob module.

Sent from my iPhone

On 21 Nov 2018, at 23:28, Jens John notifications@github.com wrote:

@johanmalm ^ Looking good (no idea how it looked before, I've done this blind).

Let me know if I have to change something, and if yes what I have to change in the output of bl-kb to make things work smoothly at your end.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

ghost commented 5 years ago

@thierrybo Thank you for your report; the issue is now fixed and will ship with the next package release (coming very soon).

@johnraff Unless you have any changes on your own to ship right now, I suggest you cut a new release of 'your' package.

johanmalm commented 5 years ago

@johnraff @2ion @hhhorb

For completeness, I've now pushed the commits to make this happen. openbox - wobbly jgmenu - straight

ob

jgmenu

johnraff commented 5 years ago

@2ion I don't think there are any important changes waiting in bunsen-utilities but I'll do a quick check for any tweaks, update the changelog, push and tag today.

@johanmalm That looks very nice.

Thanks to everyone!

johnraff commented 5 years ago

Sorry, package upgrade has been a bit delayed by other things. Coming soon.