2014-03-13 18:51:10 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*
|
|
|
|
|
|
|
|
const Gtk = imports.gi.Gtk;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Meta = imports.gi.Meta;
|
|
|
|
const St = imports.gi.St;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
|
|
|
|
const BoxPointer = imports.ui.boxpointer;
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
2014-05-23 21:32:44 -04:00
|
|
|
const RemoteMenu = imports.ui.remoteMenu;
|
2014-03-13 18:51:10 -04:00
|
|
|
|
|
|
|
const WindowMenu = new Lang.Class({
|
|
|
|
Name: 'WindowMenu',
|
|
|
|
Extends: PopupMenu.PopupMenu,
|
|
|
|
|
2014-05-30 23:19:20 -04:00
|
|
|
_init: function(window, sourceActor) {
|
|
|
|
this.parent(sourceActor, 0, St.Side.TOP);
|
2014-03-13 18:51:10 -04:00
|
|
|
|
|
|
|
this.actor.add_style_class_name('window-menu');
|
|
|
|
|
|
|
|
Main.layoutManager.uiGroup.add_actor(this.actor);
|
|
|
|
this.actor.hide();
|
|
|
|
|
|
|
|
this._buildMenu(window);
|
|
|
|
},
|
|
|
|
|
|
|
|
_buildMenu: function(window) {
|
|
|
|
let type = window.get_window_type();
|
|
|
|
|
|
|
|
let item;
|
|
|
|
|
|
|
|
item = this.addAction(_("Minimize"), Lang.bind(this, function(event) {
|
|
|
|
window.minimize();
|
|
|
|
}));
|
|
|
|
if (!window.can_minimize())
|
|
|
|
item.setSensitive(false);
|
|
|
|
|
|
|
|
if (window.get_maximized()) {
|
|
|
|
item = this.addAction(_("Unmaximize"), Lang.bind(this, function() {
|
|
|
|
window.unmaximize(Meta.MaximizeFlags.BOTH);
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
item = this.addAction(_("Maximize"), Lang.bind(this, function() {
|
|
|
|
window.maximize(Meta.MaximizeFlags.BOTH);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
if (!window.can_maximize())
|
|
|
|
item.setSensitive(false);
|
|
|
|
|
|
|
|
item = this.addAction(_("Move"), Lang.bind(this, function(event) {
|
|
|
|
window.begin_grab_op(Meta.GrabOp.KEYBOARD_MOVING, true, event.get_time());
|
|
|
|
}));
|
|
|
|
if (!window.allows_move())
|
|
|
|
item.setSensitive(false);
|
|
|
|
|
|
|
|
item = this.addAction(_("Resize"), Lang.bind(this, function(event) {
|
|
|
|
window.begin_grab_op(Meta.GrabOp.KEYBOARD_RESIZING_UNKNOWN, true, event.get_time());
|
|
|
|
}));
|
|
|
|
if (!window.allows_resize())
|
|
|
|
item.setSensitive(false);
|
|
|
|
|
|
|
|
if (!window.titlebar_is_onscreen() && type != Meta.WindowType.DOCK && type != Meta.WindowType.DESKTOP) {
|
|
|
|
this.addAction(_("Move Titlebar Onscreen"), Lang.bind(this, function(event) {
|
|
|
|
window.shove_titlebar_onscreen();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2014-05-17 19:08:49 -04:00
|
|
|
item = this.addAction(_("Always on Top"), Lang.bind(this, function() {
|
2014-03-13 18:51:10 -04:00
|
|
|
if (window.is_above())
|
|
|
|
window.unmake_above();
|
|
|
|
else
|
|
|
|
window.make_above();
|
|
|
|
}));
|
|
|
|
if (window.is_above())
|
2015-07-30 09:54:16 -04:00
|
|
|
item.setOrnament(PopupMenu.Ornament.CHECK);
|
2014-09-25 15:26:07 -04:00
|
|
|
if (window.get_maximized() == Meta.MaximizeFlags.BOTH ||
|
2014-03-13 18:51:10 -04:00
|
|
|
type == Meta.WindowType.DOCK ||
|
|
|
|
type == Meta.WindowType.DESKTOP ||
|
|
|
|
type == Meta.WindowType.SPLASHSCREEN)
|
|
|
|
item.setSensitive(false);
|
|
|
|
|
2014-05-23 12:38:23 -04:00
|
|
|
if (Main.sessionMode.hasWorkspaces &&
|
|
|
|
(!Meta.prefs_get_workspaces_only_on_primary() ||
|
|
|
|
window.is_on_primary_monitor())) {
|
2014-03-13 18:51:10 -04:00
|
|
|
let isSticky = window.is_on_all_workspaces();
|
|
|
|
|
|
|
|
item = this.addAction(_("Always on Visible Workspace"), Lang.bind(this, function() {
|
|
|
|
if (isSticky)
|
|
|
|
window.unstick();
|
|
|
|
else
|
|
|
|
window.stick();
|
|
|
|
}));
|
|
|
|
if (isSticky)
|
2015-07-30 09:54:16 -04:00
|
|
|
item.setOrnament(PopupMenu.Ornament.CHECK);
|
2014-03-13 18:51:10 -04:00
|
|
|
if (window.is_always_on_all_workspaces())
|
|
|
|
item.setSensitive(false);
|
|
|
|
|
|
|
|
if (!isSticky) {
|
|
|
|
let workspace = window.get_workspace();
|
2015-06-22 17:10:50 -04:00
|
|
|
if (workspace != workspace.get_neighbor(Meta.MotionDirection.LEFT)) {
|
|
|
|
this.addAction(_("Move to Workspace Left"), Lang.bind(this, function(event) {
|
|
|
|
window.change_workspace(workspace.get_neighbor(Meta.MotionDirection.LEFT));
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
if (workspace != workspace.get_neighbor(Meta.MotionDirection.RIGHT)) {
|
|
|
|
this.addAction(_("Move to Workspace Right"), Lang.bind(this, function(event) {
|
|
|
|
window.change_workspace(workspace.get_neighbor(Meta.MotionDirection.RIGHT));
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
if (workspace != workspace.get_neighbor(Meta.MotionDirection.UP)) {
|
2014-03-13 18:51:10 -04:00
|
|
|
this.addAction(_("Move to Workspace Up"), Lang.bind(this, function(event) {
|
|
|
|
window.change_workspace(workspace.get_neighbor(Meta.MotionDirection.UP));
|
|
|
|
}));
|
|
|
|
}
|
2015-06-22 17:10:50 -04:00
|
|
|
if (workspace != workspace.get_neighbor(Meta.MotionDirection.DOWN)) {
|
2014-03-13 18:51:10 -04:00
|
|
|
this.addAction(_("Move to Workspace Down"), Lang.bind(this, function(event) {
|
|
|
|
window.change_workspace(workspace.get_neighbor(Meta.MotionDirection.DOWN));
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-23 23:19:46 -04:00
|
|
|
let screen = global.screen;
|
|
|
|
let nMonitors = screen.get_n_monitors();
|
|
|
|
if (nMonitors > 1) {
|
|
|
|
this.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
|
|
|
|
|
|
|
let monitorIndex = window.get_monitor();
|
|
|
|
|
|
|
|
let upMonitorIndex = screen.get_monitor_neighbor_index(monitorIndex, Meta.ScreenDirection.UP);
|
|
|
|
if (upMonitorIndex != -1) {
|
|
|
|
this.addAction(_("Move to Monitor Up"), Lang.bind(this, function(event) {
|
|
|
|
window.move_to_monitor(upMonitorIndex);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
let downMonitorIndex = screen.get_monitor_neighbor_index(monitorIndex, Meta.ScreenDirection.DOWN);
|
|
|
|
if (downMonitorIndex != -1) {
|
|
|
|
this.addAction(_("Move to Monitor Down"), Lang.bind(this, function(event) {
|
|
|
|
window.move_to_monitor(downMonitorIndex);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
let leftMonitorIndex = screen.get_monitor_neighbor_index(monitorIndex, Meta.ScreenDirection.LEFT);
|
|
|
|
if (leftMonitorIndex != -1) {
|
|
|
|
this.addAction(_("Move to Monitor Left"), Lang.bind(this, function(event) {
|
|
|
|
window.move_to_monitor(leftMonitorIndex);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
let rightMonitorIndex = screen.get_monitor_neighbor_index(monitorIndex, Meta.ScreenDirection.RIGHT);
|
|
|
|
if (rightMonitorIndex != -1) {
|
|
|
|
this.addAction(_("Move to Monitor Right"), Lang.bind(this, function(event) {
|
|
|
|
window.move_to_monitor(rightMonitorIndex);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-13 18:51:10 -04:00
|
|
|
this.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
|
|
|
|
|
|
|
item = this.addAction(_("Close"), Lang.bind(this, function(event) {
|
2014-05-21 13:53:50 -04:00
|
|
|
window.delete(event.get_time());
|
2014-03-13 18:51:10 -04:00
|
|
|
}));
|
|
|
|
if (!window.can_close())
|
|
|
|
item.setSensitive(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-05-23 21:32:44 -04:00
|
|
|
const AppMenu = new Lang.Class({
|
|
|
|
Name: 'AppMenu',
|
|
|
|
Extends: RemoteMenu.RemoteMenu,
|
|
|
|
|
2014-05-30 23:19:20 -04:00
|
|
|
_init: function(window, sourceActor) {
|
2014-05-23 21:32:44 -04:00
|
|
|
let app = Shell.WindowTracker.get_default().get_window_app(window);
|
|
|
|
|
2014-05-30 23:19:20 -04:00
|
|
|
this.parent(sourceActor, app.menu, app.action_group);
|
2014-05-23 21:32:44 -04:00
|
|
|
|
|
|
|
this.actor.add_style_class_name('fallback-app-menu');
|
2014-05-25 10:46:09 -04:00
|
|
|
let variant = window.get_gtk_theme_variant();
|
|
|
|
if (variant)
|
|
|
|
this.actor.add_style_class_name(variant);
|
2014-05-23 21:32:44 -04:00
|
|
|
|
|
|
|
Main.layoutManager.uiGroup.add_actor(this.actor);
|
|
|
|
this.actor.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-03-13 18:51:10 -04:00
|
|
|
const WindowMenuManager = new Lang.Class({
|
|
|
|
Name: 'WindowMenuManager',
|
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
this._manager = new PopupMenu.PopupMenuManager({ actor: Main.layoutManager.dummyCursor });
|
2014-05-30 23:19:20 -04:00
|
|
|
|
|
|
|
this._sourceActor = new St.Widget({ reactive: true, visible: false });
|
|
|
|
this._sourceActor.connect('button-press-event', Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
this._manager.activeMenu.toggle();
|
|
|
|
}));
|
|
|
|
Main.uiGroup.add_actor(this._sourceActor);
|
2014-03-13 18:51:10 -04:00
|
|
|
},
|
|
|
|
|
2014-06-02 15:47:24 -04:00
|
|
|
showWindowMenuForWindow: function(window, type, rect) {
|
2014-05-30 23:19:20 -04:00
|
|
|
let menuType = (type == Meta.WindowMenuType.WM) ? WindowMenu : AppMenu;
|
|
|
|
let menu = new menuType(window, this._sourceActor);
|
2014-05-23 21:32:44 -04:00
|
|
|
|
2014-03-13 18:51:10 -04:00
|
|
|
this._manager.addMenu(menu);
|
|
|
|
|
2014-05-27 11:32:34 -04:00
|
|
|
menu.connect('activate', function() {
|
|
|
|
window.check_alive(global.get_current_time());
|
|
|
|
});
|
2015-05-21 12:14:51 -04:00
|
|
|
let destroyId = window.connect('unmanaged',
|
|
|
|
function() {
|
|
|
|
menu.close();
|
|
|
|
});
|
2014-05-27 11:32:34 -04:00
|
|
|
|
2015-10-19 13:06:28 -04:00
|
|
|
this._sourceActor.set_size(Math.max(1, rect.width), Math.max(1, rect.height));
|
2014-05-30 23:19:20 -04:00
|
|
|
this._sourceActor.set_position(rect.x, rect.y);
|
|
|
|
this._sourceActor.show();
|
|
|
|
|
2014-03-13 18:51:10 -04:00
|
|
|
menu.open(BoxPointer.PopupAnimation.NONE);
|
|
|
|
menu.actor.navigate_focus(null, Gtk.DirectionType.TAB_FORWARD, false);
|
|
|
|
menu.connect('open-state-changed', Lang.bind(this, function(menu_, isOpen) {
|
2014-05-30 23:19:20 -04:00
|
|
|
if (isOpen)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._sourceActor.hide();
|
|
|
|
menu.destroy();
|
2015-05-21 12:14:51 -04:00
|
|
|
window.disconnect(destroyId);
|
2014-03-13 18:51:10 -04:00
|
|
|
}));
|
2014-05-23 21:32:44 -04:00
|
|
|
}
|
2014-03-13 18:51:10 -04:00
|
|
|
});
|