Skip to content

Commit

Permalink
Right-click menu: settings by right clicking on the dock.
Browse files Browse the repository at this point in the history
  • Loading branch information
franglais125 committed Oct 2, 2017
1 parent 8cbfa98 commit 3cd1671
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions dash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
}
}
});

Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 3cd1671

Please sign in to comment.