1

I wrote a PanelMenu.Button-derived class for shell 3.36 by following the tutorial at:

https://wiki.gnome.org/Projects/GnomeShell/Extensions/Writing

Everything works (after a few 3.36-related tweaks I had to do) but now I would like to have a single left click show/hide the application and single right click open the menu. For that I wanted to catch a 'clicked' signal but PanelMenu.Button only emits menu-set. I'd need something like this:

indicator.connect("clicked", () => GLib.spawn_command_line_async("my_app"));

Is there a widget that supports the 'clicked' signal?

Andrej Prsa
  • 551
  • 3
  • 14

2 Answers2

1

I think looking for a another widget might be more work than it's worth. If you look here at the implementation, they're really just overriding the event vfunc to open the menu.

vfunc_event(event) {
    if (this.menu &&
        (event.type() == Clutter.EventType.TOUCH_BEGIN ||
         event.type() == Clutter.EventType.BUTTON_PRESS))
        this.menu.toggle();

    return Clutter.EVENT_PROPAGATE;
}

If you've subclassed yourself and don't need the menu, you can simply do a similar thing just by redefining the virtual function like so (just put this in your subclass like a regular function):

vfunc_event() {
    if ((event.type() == Clutter.EventType.TOUCH_BEGIN ||
         event.type() == Clutter.EventType.BUTTON_PRESS))
        GLib.spawn_command_line_async("my_app");

    return Clutter.EVENT_PROPAGATE;
}

However, you may want to change the events to BUTTON_RELEASE and TOUCH_END so it happens when the user releases the button, giving them a chance to change their mind by dragging the mouse away.

andy.holmes
  • 3,383
  • 17
  • 28
  • Perfect, thank you! A small follow-up question: is there a preferred way to show/hide a window of a running application? Spawning it works but it feels like an overkill if the application is already running. In other words, how do I connect the extension to a running instance of a specific application? – Andrej Prsa Apr 12 '20 at 13:07
  • You probably want to look at https://gjs-docs.gnome.org/shell01~0.1_api-appsystem/ or open a new question if you need more detailed help. – andy.holmes Apr 13 '20 at 19:43
1

Did you try:
indicator.connect("button-press-event", () => GLib.spawn_command_line_async("my_app"));

The signal you are looking for should be: button-press-event. A single left mouse button click will trigger the button-press-event.
This signal works for me. My GNOME shell version is: 3.36.9

Regarding your second question:
is there a preferred way to show/hide a window of a running application?
This link may be able to help you or will hopefully at least give you some pointers in the right direction:
https://github.com/amivaleo/Show-Desktop-Button/blob/master/extension.js
Good Luck!
Mody
  • 86
  • 3