use showOsd method exclusively
This commit is contained in:
parent
9c351b5724
commit
b364895c7d
106
extension.js
106
extension.js
|
|
@ -39,6 +39,7 @@ const Draw = Me.imports.draw;
|
||||||
const _ = imports.gettext.domain(Me.metadata['gettext-domain']).gettext;
|
const _ = imports.gettext.domain(Me.metadata['gettext-domain']).gettext;
|
||||||
|
|
||||||
const GS_VERSION = Config.PACKAGE_VERSION;
|
const GS_VERSION = Config.PACKAGE_VERSION;
|
||||||
|
const HIDE_TIMEOUT_LONG = 2500; // ms, default is 1500 ms
|
||||||
|
|
||||||
// DRAWING_ACTION_MODE is a custom Shell.ActionMode
|
// DRAWING_ACTION_MODE is a custom Shell.ActionMode
|
||||||
var DRAWING_ACTION_MODE = Math.pow(2,14);
|
var DRAWING_ACTION_MODE = Math.pow(2,14);
|
||||||
|
|
@ -314,6 +315,10 @@ var AreaManager = new Lang.Class({
|
||||||
if (this.hiddenList)
|
if (this.hiddenList)
|
||||||
this.togglePanelAndDockOpacity();
|
this.togglePanelAndDockOpacity();
|
||||||
|
|
||||||
|
setCursor('DEFAULT');
|
||||||
|
if (!this.osdDisabled)
|
||||||
|
this.showOsd(null, this.leaveGicon, _("Leaving drawing mode"));
|
||||||
|
|
||||||
Main.popModal(this.activeArea);
|
Main.popModal(this.activeArea);
|
||||||
this.removeInternalKeybindings();
|
this.removeInternalKeybindings();
|
||||||
this.activeArea.reactive = false;
|
this.activeArea.reactive = false;
|
||||||
|
|
@ -324,11 +329,7 @@ var AreaManager = new Lang.Class({
|
||||||
Main.layoutManager._backgroundGroup.insert_child_above(activeContainer, Main.layoutManager._bgManagers[activeIndex].backgroundActor);
|
Main.layoutManager._backgroundGroup.insert_child_above(activeContainer, Main.layoutManager._bgManagers[activeIndex].backgroundActor);
|
||||||
if (!this.settings.get_boolean("drawing-on-desktop"))
|
if (!this.settings.get_boolean("drawing-on-desktop"))
|
||||||
activeContainer.hide();
|
activeContainer.hide();
|
||||||
|
} else {
|
||||||
setCursor('DEFAULT');
|
|
||||||
if (!this.osdDisabled)
|
|
||||||
Main.osdWindowManager.show(activeIndex, this.leaveGicon, _("Leaving drawing mode"), null);
|
|
||||||
} else {
|
|
||||||
// avoid to deal with Meta changes (global.display/global.screen)
|
// avoid to deal with Meta changes (global.display/global.screen)
|
||||||
let currentIndex = Main.layoutManager.monitors.indexOf(Main.layoutManager.currentMonitor);
|
let currentIndex = Main.layoutManager.monitors.indexOf(Main.layoutManager.currentMonitor);
|
||||||
let activeContainer = this.areas[currentIndex].get_parent();
|
let activeContainer = this.areas[currentIndex].get_parent();
|
||||||
|
|
@ -346,15 +347,8 @@ var AreaManager = new Lang.Class({
|
||||||
|
|
||||||
setCursor('POINTING_HAND');
|
setCursor('POINTING_HAND');
|
||||||
this.osdDisabled = this.settings.get_boolean('osd-disabled');
|
this.osdDisabled = this.settings.get_boolean('osd-disabled');
|
||||||
if (!this.osdDisabled) {
|
let label = _("<small>Press <i>%s</i> for help</small>").format(this.activeArea.helper.helpKeyLabel) + "\n\n" + _("Entering drawing mode");
|
||||||
// increase OSD display time
|
this.showOsd(null, this.enterGicon, label, null, null, true);
|
||||||
let hideTimeoutSave = OsdWindow.HIDE_TIMEOUT;
|
|
||||||
try { OsdWindow.HIDE_TIMEOUT = 2000; } catch(e) { /* HIDE_TIMEOUT is not exported with 'var' */ }
|
|
||||||
let label = _("<small>Press <i>%s</i> for help</small>").format(this.activeArea.helper.helpKeyLabel) + "\n\n" + _("Entering drawing mode");
|
|
||||||
Main.osdWindowManager.show(currentIndex, this.enterGicon, label, null);
|
|
||||||
Main.osdWindowManager._osdWindows[this.areas.indexOf(this.activeArea)]._label.get_clutter_text().set_use_markup(true);
|
|
||||||
try { OsdWindow.HIDE_TIMEOUT = hideTimeoutSave; } catch(e) {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.indicator)
|
if (this.indicator)
|
||||||
|
|
@ -362,45 +356,61 @@ var AreaManager = new Lang.Class({
|
||||||
},
|
},
|
||||||
|
|
||||||
// use level -1 to set no level (null)
|
// use level -1 to set no level (null)
|
||||||
showOsd: function(emitter, iconName, label, color, level) {
|
showOsd: function(emitter, icon, label, color, level, long) {
|
||||||
if (this.osdDisabled)
|
|
||||||
return;
|
|
||||||
let activeIndex = this.areas.indexOf(this.activeArea);
|
let activeIndex = this.areas.indexOf(this.activeArea);
|
||||||
if (activeIndex != -1) {
|
if (activeIndex == -1 || this.osdDisabled)
|
||||||
let maxLevel;
|
return;
|
||||||
if (level == -1)
|
|
||||||
level = null;
|
|
||||||
else if (level > 100)
|
|
||||||
maxLevel = 2;
|
|
||||||
|
|
||||||
// GS 3.32- : bar from 0 to 100
|
let hideTimeoutSave;
|
||||||
// GS 3.34+ : bar from 0 to 1
|
if (long)
|
||||||
if (level && GS_VERSION > '3.33.0')
|
try {
|
||||||
level = level / 100;
|
hideTimeoutSave = OsdWindow.HIDE_TIMEOUT;
|
||||||
|
OsdWindow.HIDE_TIMEOUT = HIDE_TIMEOUT_LONG;
|
||||||
let icon = iconName && new Gio.ThemedIcon({ name: iconName });
|
} catch(e) {
|
||||||
Main.osdWindowManager.show(activeIndex, icon || this.enterGicon, label, level, maxLevel);
|
// HIDE_TIMEOUT is not exportable.
|
||||||
Main.osdWindowManager._osdWindows[activeIndex]._label.get_clutter_text().set_use_markup(true);
|
hideTimeoutSave = null;
|
||||||
|
|
||||||
if (color) {
|
|
||||||
Main.osdWindowManager._osdWindows[activeIndex]._icon.set_style(`color:${color};`);
|
|
||||||
Main.osdWindowManager._osdWindows[activeIndex]._label.set_style(`color:${color};`);
|
|
||||||
let osdColorChangedHandler = Main.osdWindowManager._osdWindows[activeIndex]._label.connect('notify::text', () => {
|
|
||||||
Main.osdWindowManager._osdWindows[activeIndex]._icon.set_style(`color:;`);
|
|
||||||
Main.osdWindowManager._osdWindows[activeIndex]._label.set_style(`color:;`);
|
|
||||||
Main.osdWindowManager._osdWindows[activeIndex]._label.disconnect(osdColorChangedHandler);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (level === 0) {
|
let maxLevel;
|
||||||
Main.osdWindowManager._osdWindows[activeIndex]._label.add_style_class_name(WARNING_COLOR_STYLE_CLASS_NAME);
|
if (level == -1)
|
||||||
// the same label is shared by all GS OSD so the style must be removed after being used
|
level = null;
|
||||||
let osdLabelChangedHandler = Main.osdWindowManager._osdWindows[activeIndex]._label.connect('notify::text', () => {
|
else if (level > 100)
|
||||||
Main.osdWindowManager._osdWindows[activeIndex]._label.remove_style_class_name(WARNING_COLOR_STYLE_CLASS_NAME);
|
maxLevel = 2;
|
||||||
Main.osdWindowManager._osdWindows[activeIndex]._label.disconnect(osdLabelChangedHandler);
|
|
||||||
});
|
// GS 3.32- : bar from 0 to 100
|
||||||
}
|
// GS 3.34+ : bar from 0 to 1
|
||||||
|
if (level && GS_VERSION > '3.33.0')
|
||||||
|
level = level / 100;
|
||||||
|
|
||||||
|
if (icon && typeof icon == 'string')
|
||||||
|
icon = new Gio.ThemedIcon({ name: icon });
|
||||||
|
else if (!icon)
|
||||||
|
icon = this.enterGicon;
|
||||||
|
|
||||||
|
Main.osdWindowManager.show(activeIndex, icon, label, level, maxLevel);
|
||||||
|
Main.osdWindowManager._osdWindows[activeIndex]._label.get_clutter_text().set_use_markup(true);
|
||||||
|
|
||||||
|
if (color) {
|
||||||
|
Main.osdWindowManager._osdWindows[activeIndex]._icon.set_style(`color:${color};`);
|
||||||
|
Main.osdWindowManager._osdWindows[activeIndex]._label.set_style(`color:${color};`);
|
||||||
|
let osdColorChangedHandler = Main.osdWindowManager._osdWindows[activeIndex]._label.connect('notify::text', () => {
|
||||||
|
Main.osdWindowManager._osdWindows[activeIndex]._icon.set_style(`color:;`);
|
||||||
|
Main.osdWindowManager._osdWindows[activeIndex]._label.set_style(`color:;`);
|
||||||
|
Main.osdWindowManager._osdWindows[activeIndex]._label.disconnect(osdColorChangedHandler);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (level === 0) {
|
||||||
|
Main.osdWindowManager._osdWindows[activeIndex]._label.add_style_class_name(WARNING_COLOR_STYLE_CLASS_NAME);
|
||||||
|
// the same label is shared by all GS OSD so the style must be removed after being used
|
||||||
|
let osdLabelChangedHandler = Main.osdWindowManager._osdWindows[activeIndex]._label.connect('notify::text', () => {
|
||||||
|
Main.osdWindowManager._osdWindows[activeIndex]._label.remove_style_class_name(WARNING_COLOR_STYLE_CLASS_NAME);
|
||||||
|
Main.osdWindowManager._osdWindows[activeIndex]._label.disconnect(osdLabelChangedHandler);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hideTimeoutSave)
|
||||||
|
OsdWindow.HIDE_TIMEOUT = hideTimeoutSave;
|
||||||
},
|
},
|
||||||
|
|
||||||
removeAreas: function() {
|
removeAreas: function() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue