1
const Main = imports.ui.main;
2
const Mainloop = imports.mainloop;
3
const St = imports.gi.St;
4
const Tweener = imports.ui.tweener;
5
const Gio = imports.gi.Gio
6
const ExtensionUtils = imports.misc.extensionUtils;
7
const Pango = imports.gi.Pango;
9
// get current extension
10
const extension = imports.misc.extensionUtils.getCurrentExtension();
12
// used to restore monkey patched function on disable
13
let _old_addItem = null;
14
// used to disconnect events on disable
16
// id of timer waiting for start
17
let _labelTimeoutId = 0;
18
// id of last (cancellable) timer
19
let _resetHoverTimeoutId = 0;
20
// actor for displaying the tooltip (or null)
23
let _labelShowing = false;
25
// stores settings from the schema
28
const GioSSS = Gio.SettingsSchemaSource;
30
let schemaSource = GioSSS.new_from_directory(extension.path + "/schemas",
31
GioSSS.get_default(), false);
33
let schemaObj = schemaSource.lookup(extension.metadata["settings-schema"], true);
35
throw new Error("Schema " + extension.metadata["settings-schema"] + " could not be found for extension " +
36
extension.uuid + ". Please check your installation.");
39
_settings = new Gio.Settings({ settings_schema: schemaObj });
42
function _get_tooltip_label_show_time() { return (_settings.get_int("label-show-time")/100); }
43
function _get_tooltip_label_hide_time() { return (_settings.get_int("label-hide-time")/100); }
44
function _get_tooltip_hover_timeout() { return (_settings.get_int("hoover-timeout")); }
45
function _get_always_show_tooltip() { return (_settings.get_boolean("allways-show-tooltips")); }
46
function _get_show_app_description() { return (_settings.get_boolean("show-app-description")); }
47
function _get_tooltip_text_font_size() { return (_settings.get_int("font-size")); }
48
function _get_tooltip_text_max_width() { return (_settings.get_int("max-width")); }
52
_tooltips = new Array();
53
// Enabling tooltips after _appIcons has been populated
54
let appIcons = Main.overview.viewSelector.appDisplay._views[1].view._items;
55
//global.log("appIcons after enable",appIcons, Object.keys(appIcons).length);
56
for (let i in appIcons) {
57
_connect(appIcons[i].actor);
59
// monkeypatching for the load time and for the search overview tooltips
60
_old_addItem = imports.ui.iconGrid.IconGrid.prototype.addItem;
61
imports.ui.iconGrid.IconGrid.prototype.addItem = function(item, index){
63
// original part of the function I'm overwriting
64
_old_addItem.apply(this, arguments);
69
//restore the function
70
imports.ui.iconGrid.IconGrid.prototype.addItem = _old_addItem;
71
for (let i = 0; i < _tooltips.length; i++) {
72
//disconnect hover signals
73
_tooltips[i].actor.disconnect(_tooltips[i].connection);
78
function _onHover(actor){
79
if (actor.get_hover()) {
80
if (_labelTimeoutId == 0) {
81
let timeout = _labelShowing ? 0 : _get_tooltip_hover_timeout();
82
_labelTimeoutId = Mainloop.timeout_add(timeout,
89
if (_resetHoverTimeoutId > 0) {
90
Mainloop.source_remove(_resetHoverTimeoutId);
91
_resetHoverTimeoutId = 0;
95
if (_labelTimeoutId > 0){
96
Mainloop.source_remove(_labelTimeoutId);
101
_resetHoverTimeoutId = Mainloop.timeout_add(_get_tooltip_hover_timeout(),
103
_labelShowing = false;
111
function _showTooltip(actor) {
113
let should_display = false;
114
if (actor._delegate.app){
115
//applications overview
116
icontext = actor._delegate.app.get_name();
117
if (_get_show_app_description()) {
118
let appDescription = actor._delegate.app.get_description();
119
// allow only valid description-text (not null)
121
icontext = icontext.concat(" :\n", appDescription);
124
if (!_get_always_show_tooltip()){
125
// will be displayed if elipsized/text cut-off (is_ellipsized)
126
should_display = actor._delegate.icon.label.get_clutter_text().get_layout().is_ellipsized();
129
should_display = true;
131
}/*else if (actor._delegate._content._delegate){
132
//app and settings searchs results
133
icontext = actor._delegate.metaInfo['name'];
134
should_display = actor._delegate._content._delegate.icon.label.get_clutter_text().get_layout().is_ellipsized();
135
}else if (actor._delegate._content.label_actor){
136
//locations and other (generic) search results (wanda wouldn't work)
137
icontext = actor._delegate.metaInfo['name'];
138
should_display = actor._delegate._content.label_actor.get_clutter_text().get_layout().is_ellipsized();
140
else if (actor._delegate.hasOwnProperty('_folder')){
141
// folder in the application overview
142
icontext = 'Group: '.concat(actor._delegate['name']);
143
if (!_get_always_show_tooltip()){
144
// will be displayed if elipsized/text cut-off (is_ellipsized)
145
should_display = actor._delegate.icon.label.get_clutter_text().get_layout().is_ellipsized();
148
should_display = true;
151
//app and settings searchs results
152
icontext = actor._delegate.metaInfo['name'];
153
if (!_get_always_show_tooltip()){
154
// will be displayed if elipsized/text cut-off (is_ellipsized)
155
should_display = actor._delegate.icon.label.get_clutter_text().get_layout().is_ellipsized();
158
should_display = true;
162
if (!should_display){
167
_label = new St.Label({text: icontext});
168
Main.uiGroup.add_actor(_label);
170
_label.text = icontext;
174
_label.style = 'font-size: ' + _get_tooltip_text_font_size() + 'px; max-width:' + _get_tooltip_text_max_width() + 'px; font-weight: bold; color: ' + '#ffffff' +'; text-align: center; background-color: ' + 'rgba(10,10,10,0.6)' + '; border-radius: 5px; padding: 5px;';
175
_label.clutter_text.line_wrap = true;
176
_label.clutter_text.line_wrap_mode = Pango.WrapMode.WORD;
177
_label.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
179
[stageX, stageY] = actor.get_transformed_position();
180
[iconWidth, iconHeight] = actor.get_transformed_size();
182
let y = stageY + iconHeight + 5;
183
let x = stageX - Math.round((_label.get_width() - iconWidth)/2);
185
_label.set_position(x, y);
186
Tweener.addTween(_label,{
188
time: _get_tooltip_label_show_time(),
189
transition: 'easeOutQuad',
193
function _hideTooltip() {
195
Tweener.addTween(_label, {
197
time: _get_tooltip_label_hide_time(),
198
transition: 'easeOutQuad',
199
onComplete: function() {
200
Main.uiGroup.remove_actor(_label);
207
function _connect(actr){
208
let con = actr.connect('notify::hover', _onHover);
209
_tooltips.push({actor: actr, connection: con});