windowMenu: Check if monitorIndex is valid before using it

Calling meta_window_get_monitor on an unmanaged window may return
-1, so we need to check the return value.

https://bugzilla.gnome.org/show_bug.cgi?id=788882


(cherry picked from commit c9bf72c5c4)
This commit is contained in:
Sam Spilsbury 2017-10-11 10:42:04 +00:00 committed by Marco Trevisan
parent 0b82388c49
commit a662e7bb87

View File

@ -128,11 +128,10 @@ var WindowMenu = new Lang.Class({
let screen = global.screen; let screen = global.screen;
let nMonitors = screen.get_n_monitors(); let nMonitors = screen.get_n_monitors();
if (nMonitors > 1) { let monitorIndex = window.get_monitor();
if (nMonitors > 1 && monitorIndex >= 0) {
this.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); this.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
let monitorIndex = window.get_monitor();
let dir = Meta.ScreenDirection.UP; let dir = Meta.ScreenDirection.UP;
let upMonitorIndex = let upMonitorIndex =
screen.get_monitor_neighbor_index(monitorIndex, dir); screen.get_monitor_neighbor_index(monitorIndex, dir);