MadcowOG / dwl-bar

dwl-like bar for dwl
GNU General Public License v3.0
29 stars 10 forks source link

Trayicons can't be clicked #5

Open starrymohannad opened 1 year ago

MadcowOG commented 1 year ago

The systray patch doesn't implement dbusmenu which some applications require to show menus. I currently don't have plans to implement it. If someone would like to work on it, this pull request on swaybar appears to be relevant and a good starting point. I'm going to leave this issue open.

0mark commented 1 year ago

As a short term solution i use a modified version of dbusmenu.py and call it in systray instead of _sd_bus_call_methodasync (if item has a menu_path and not is_menu).

Patch for dbusmenu.py:

65c65
< def show_menu(session_bus, bus, path):
---
> def show_menu(session_bus, bus, path, num):
69c69
<       _, item = iface.GetLayout(0, -1, [])
---
>       _, item = iface.GetLayout(int(num), -1, [])
97,98c97,98
<       if len(sys.argv) == 3:
<               show_menu(session_bus, sys.argv[1], sys.argv[2])
---
>       if len(sys.argv) == 4:
>               show_menu(session_bus, sys.argv[1], sys.argv[2], sys.argv[3])

Call in systray in user.c (instead of sd_bus_call_method_async(item->tray->bus, NULL, item->service, item->path, item->interface, method, NULL, NULL, "ii", click->x, click->y); ):

if(item->menu_path!=NULL && item->is_menu!=0) {
    cmd[1] = item->service;
    cmd[2] = item->menu_path;

    if (STRING_EQUAL(method, "Activate")) {
        cmd[3] = "0";
    } else if (STRING_EQUAL(method, "SecondaryActivate")) {
        cmd[3] = "1";
    } else if (STRING_EQUAL(method, "ContextMenu")) {
        cmd[3] = "2";
    } else {
        printf("Unknown method \"%s\", using \"Activate\"\n", method);
        cmd[3] = "0";
    }
    arg2.v = cmd;
    spawn(monitor, -1, NULL, &arg2);
} else {
    sd_bus_call_method_async(item->tray->bus, NULL, item->service, item->path, item->interface, method, NULL, NULL, "ii", click->x, click->y);
}

This seems to work so far, although it does look kinda ugly