From cac94f20192cc41a13edad68536b32b600b4f992 Mon Sep 17 00:00:00 2001 From: Jens Lody Date: Sun, 26 Nov 2017 22:39:09 +0100 Subject: [PATCH] Restore search-results popup on gtk3 < 3.22, broken in commit 21f8299. --- src/prefs.js | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/prefs.js b/src/prefs.js index 096f487..3f20f39 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -185,8 +185,7 @@ const WeatherPrefsWidget = new GObject.Class({ } this.searchMenu.append(item); - this.searchMenu.show_all(); - this.searchMenu.popup_at_widget(this.searchName, Gdk.Gravity.SOUTH_WEST, Gdk.Gravity.NORTH_WEST, null); + this.showSearchMenu(); if (this.geolocation_provider == GeolocationProvider.OPENSTREETMAPS) { let params = { @@ -225,8 +224,7 @@ const WeatherPrefsWidget = new GObject.Class({ } } } - this.searchMenu.show_all(); - this.searchMenu.popup_at_widget(this.searchName, Gdk.Gravity.SOUTH_WEST, Gdk.Gravity.NORTH_WEST, null); + this.showSearchMenu(); return 0; })); } else if (this.geolocation_provider == GeolocationProvider.MAPQUEST) { @@ -240,8 +238,7 @@ const WeatherPrefsWidget = new GObject.Class({ label: "Please visit https://developer.mapquest.com/ ." }); this.searchMenu.append(item); - this.searchMenu.show_all(); - this.searchMenu.popup_at_widget(this.searchName, Gdk.Gravity.SOUTH_WEST, Gdk.Gravity.NORTH_WEST, null); + this.showSearchMenu(); return 0; } let params = { @@ -289,8 +286,7 @@ const WeatherPrefsWidget = new GObject.Class({ } } } - this.searchMenu.show_all(); - this.searchMenu.popup_at_widget(this.searchName, Gdk.Gravity.SOUTH_WEST, Gdk.Gravity.NORTH_WEST, null); + this.showSearchMenu(); return 0; })); } else if (this.geolocation_provider == GeolocationProvider.GEOCODE) { @@ -338,8 +334,7 @@ const WeatherPrefsWidget = new GObject.Class({ } } - this.searchMenu.show_all(); - this.searchMenu.popup_at_widget(this.searchName, Gdk.Gravity.SOUTH_WEST, Gdk.Gravity.NORTH_WEST, null); + this.showSearchMenu(); return 0; })); } @@ -424,6 +419,23 @@ const WeatherPrefsWidget = new GObject.Class({ this.searchName.set_text(arguments[0].get_label()); }, + showSearchMenu: function() { + this.searchMenu.show_all(); + if (versionAtLeast('3.22', Config.PACKAGE_VERSION)) { + this.searchMenu.popup_at_widget(this.searchName, Gdk.Gravity.SOUTH_WEST, Gdk.Gravity.NORTH_WEST, null); + } + else + { + this.searchMenu.popup(null, null, Lang.bind(this, this.placeSearchMenu), 0, this.searchName); + } + }, + + placeSearchMenu: function() { + let[gx, gy, gw, gh] = this.searchName.get_window().get_geometry(); + let[px, py] = this.searchName.get_window().get_position(); + return [gx + px, gy + py + this.searchName.get_allocated_height()]; + }, + clearSearchMenu: function() { let children = this.searchMenu.get_children(); for (let i in children) {