Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Right click menu #463

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 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) {
let [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 Expand Up @@ -241,6 +289,16 @@ var MyDash = new Lang.Class({

this._container.add_actor(this._showAppsIcon);

// When opening the right click menu, deactivate reactiveness of icons.
this._containerObject.menu.connect('open-state-changed', Lang.bind(this, function() {
let reactiveness = !this._containerObject.menu.isOpen;
let appIcons = this.getAppIcons();
appIcons.forEach(function(icon) {
icon.actor.reactive = reactiveness;
});
showAppsIconWrapper.actor.reactive = reactiveness;
}));

let rtl = Clutter.get_default_text_direction() == Clutter.TextDirection.RTL;
this.actor = new St.Bin({
child: this._container,
Expand Down
7 changes: 7 additions & 0 deletions docking.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ const DockedDash = new Lang.Class({
});
this._box.connect('notify::hover', Lang.bind(this, this._hoverChanged));

// This is for the menu to access the settings with right-click
this.dash._containerObject.menu.connect('menu-closed', Lang.bind(this, this._hoverChanged))

// Create and apply height constraint to the dash. It's controlled by this.actor height
this.constrainSize = new Clutter.BindConstraint({
source: this.actor,
Expand Down Expand Up @@ -684,6 +687,10 @@ const DockedDash = new Lang.Class({
},

_hoverChanged: function() {
if (this.dash._containerObject.menu.isOpen) {
return;
}

if (!this._ignoreHover) {
// Skip if dock is not in autohide mode for instance because it is shown
// by intellihide.
Expand Down