Manage Left/Right click into panel menu


I present a simple and dirty solution for manage the left click and the right click event into a panel menu button of the gnome shell DE; all consosiste simply fill the menu with all the items of both the left than to the right menu, and intercept the type of event to hide the group of menu items on the left or instead to hiding the group of menu items on the right. this is the sample code:

...
const DoubleIndicatorSample_Indicator = new Lang.Class({
    Name: 'DoubleIndicatorSample.indicator',
    Extends: PanelMenu.SystemStatusButton,

    _init: function() {
        this.parent(null, "doubleindicatorsample-indicator")
        
        //............

        this.iteml1 = new PopupMenu.PopupMenuItem(_("Left Menu Item 1"));
        this.menu.addMenuItem(this.iteml1);
        this.iteml2 = new PopupMenu.PopupMenuItem(_("Left Menu Item 2"));
        this.menu.addMenuItem(this.iteml2);

        //add separetor menu
        this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
        //add option menu entry
        this.imOptions = new PopupMenu.PopupMenuItem(_("Options"));
        this.menu.addMenuItem(this.imOptions);
        this.imOptions.connect('activate', Lang.bind(this, this._doExtensionPreferences));


        this.itemr1 = new PopupMenu.PopupMenuItem(_("Right Menu Item 1"));
        this.menu.addMenuItem(this.itemr1);
        this.itemr2 = new PopupMenu.PopupMenuItem(_("Right Menu Item 2"));
        this.menu.addMenuItem(this.itemr2);
        this.itemr3 = new PopupMenu.PopupMenuItem(_("Right Menu Item 3"));
        this.menu.addMenuItem(this.itemr3);
        this.itemr4 = new PopupMenu.PopupMenuItem(_("Right Menu Item 4"));
        this.menu.addMenuItem(this.itemr4);
    },

    _onButtonPress: function(actor, event) {
        let button = event.get_button();
        if (button === 1) {
            Lib.TalkativeLog('Test18 > event indicator left click');
            
            if(this.menu.isOpen){
                this.menu.close();
            }else{
                this._disableMenuRight();
                this._enableMenuLeft();
            
                this.menu.open();
            }

        } else if (button === 3) {
            Lib.TalkativeLog('Test18 > event indicator right click');
            
            if(this.menu.isOpen){
                this.menu.close();
            }else{
                this._disableMenuLeft();
                this._enableMenuRight();
                
                this.menu.open();
            }
        }
    },
    
    _enableMenuLeft: function(){
        this.iteml1.actor.show();
        this.iteml2.actor.show();
        this.imOptions.actor.show();

    },
    
    _disableMenuLeft: function(){
        this.iteml1.actor.hide();
        this.iteml2.actor.hide();
        this.imOptions.actor.hide();
        
    },
    
    _enableMenuRight: function(){
        this.itemr1.actor.show();
        this.itemr2.actor.show();
        this.itemr3.actor.show();
        this.itemr4.actor.show();


    },
    
    _disableMenuRight: function(){
        this.itemr1.actor.hide();
        this.itemr2.actor.hide();
        this.itemr3.actor.hide();
        this.itemr4.actor.hide();
    },

    _doExtensionPreferences: function() {
        Lib.TalkativeLog('Test18 > open preferences');
        Main.Util.trySpawnCommandLine('gnome-shell-extension-prefs DoubleIndicatorSample@iacopodeenosee.gmail.com');
    },

    destroy: function() {
        this.parent();
    }
});
...

that’s all.8y3

Lascia un commento

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...