diff --git a/dash.js b/dash.js index 84f3b8d7c8..109603b4fd 100644 --- a/dash.js +++ b/dash.js @@ -55,9 +55,10 @@ function extendDashItemContainer(dashItemContainer, settings) { const MyDashActor = new Lang.Class({ Name: 'DashToDock.MyDashActor', - _init: function(settings) { + _init: function(settings, monitorIndex) { // a prefix is required to avoid conflicting with the parent class variable this._dtdSettings = settings; + this._monitorIndex = monitorIndex; this._rtl = (Clutter.get_default_text_direction() == Clutter.TextDirection.RTL); this._position = Utils.getPosition(settings); @@ -78,6 +79,25 @@ const MyDashActor = new Lang.Class({ this.actor.connect('allocate', Lang.bind(this, this._allocate)); this.actor._delegate = this; + + // Popup menu + let alignment = 0.5; + this.menu = new PopupMenu.PopupMenu(this.actor, alignment, this._position); + this.menu.actor.hide(); + let settingsMenuItem = new PopupMenu.PopupMenuItem('Dash to Dock ' + _('Settings')); + settingsMenuItem.connect('activate', Lang.bind(this, function() { + Util.spawn(['gnome-shell-extension-prefs', Me.metadata.uuid]); + })); + this.menu.addMenuItem(settingsMenuItem); + + Main.uiGroup.add_actor(this.menu.actor); + this.menu.close(); + + this._menuManager = new PopupMenu.PopupMenuManager(this); + this._menuManager.addMenu(this.menu); + + this.actor.reactive = true; + this.actor.connect('button-press-event', Lang.bind(this, this._rightClickMenu)); }, _allocate: function(actor, box, flags) { @@ -154,6 +174,34 @@ const MyDashActor = new Lang.Class({ alloc.min_size = minHeight; alloc.natural_size = natHeight; + }, + + _rightClickMenu: function(actor, event) { + if (this.menu.isOpen) { + this.menu.toggle(); + return; + } + + let button = event.get_button(); + if (button == 3) { + [x, y] = event.get_coords(); + let coords, offset, size; + + if (this._isHorizontal) { + coords = x; + offset = (Main.layoutManager.getWorkAreaForMonitor(this._monitorIndex).width - this.actor.width)/2; + size = this.actor.width; + } + else { + coords = y; + offset = (Main.layoutManager.getWorkAreaForMonitor(this._monitorIndex).height - this.actor.height)/2 + + Main.layoutManager.getWorkAreaForMonitor(this._monitorIndex).y; // This is the offset due to the top bar + size = this.actor.height; + } + + this.menu.setSourceAlignment((coords - offset) / size); + this.menu.toggle(); + } } }); @@ -203,7 +251,7 @@ var MyDash = new Lang.Class({ this._ensureAppIconVisibilityTimeoutId = 0; this._labelShowing = false; - this._containerObject = new MyDashActor(settings); + this._containerObject = new MyDashActor(settings, this._monitorIndex); this._container = this._containerObject.actor; this._scrollView = new St.ScrollView({ name: 'dashtodockDashScrollview',