From 8671a9e5027646b38adba9e81ebff315f4143533 Mon Sep 17 00:00:00 2001 From: abakkk Date: Fri, 11 Oct 2019 09:22:37 +0200 Subject: [PATCH] GS 3.34 compatibility * PanelMenu.Button actor * PopupMenu.PopupBaseMenuItem, PopupMenu.PopupSwitchMenuItem and PopupMenu.PopupSeparatorMenuItem actor * Slider.Slider actor and 'value-changed' signal * PopupMenu.PopupMenuManager init params * 'org.gnome.settings-daemon.plugins.media-keys' setting values : string -> array of strings --- draw.js | 44 +++++++++++++++++++++++++++++++------------- extension.js | 10 +++++++--- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/draw.js b/draw.js index 4a2dae4..9c634d4 100644 --- a/draw.js +++ b/draw.js @@ -33,6 +33,7 @@ const Signals = imports.signals; const St = imports.gi.St; const BoxPointer = imports.ui.boxpointer; +const Config = imports.misc.config; const Main = imports.ui.main; const PopupMenu = imports.ui.popupMenu; const Slider = imports.ui.slider; @@ -46,6 +47,8 @@ const ExtensionJs = Extension.imports.extension; const Prefs = Extension.imports.prefs; const _ = imports.gettext.domain(Extension.metadata["gettext-domain"]).gettext; +const GS_VERSION = Config.PACKAGE_VERSION; + const FILL_ICON_PATH = Extension.dir.get_child('icons').get_child('fill-symbolic.svg').get_path(); const STROKE_ICON_PATH = Extension.dir.get_child('icons').get_child('stroke-symbolic.svg').get_path(); const LINEJOIN_ICON_PATH = Extension.dir.get_child('icons').get_child('linejoin-symbolic.svg').get_path(); @@ -919,6 +922,8 @@ var DrawingHelper = new Lang.Class({ this.vbox.add(hbox); continue; } + if (!settings.get_strv(settingKey)[0]) + continue; let [keyval, mods] = Gtk.accelerator_parse(settings.get_strv(settingKey)[0]); hbox.add(new St.Label({ text: _(Prefs.GLOBAL_KEYBINDINGS[settingKey]) })); hbox.add(new St.Label({ text: Gtk.accelerator_get_label(keyval, mods) }), { expand: true }); @@ -946,6 +951,8 @@ var DrawingHelper = new Lang.Class({ continue; } let hbox = new St.BoxLayout({ vertical: false }); + if (!settings.get_strv(settingKey)[0]) + continue; let [keyval, mods] = Gtk.accelerator_parse(settings.get_strv(settingKey)[0]); hbox.add(new St.Label({ text: _(Prefs.INTERNAL_KEYBINDINGS[settingKey]) })); hbox.add(new St.Label({ text: Gtk.accelerator_get_label(keyval, mods) }), { expand: true }); @@ -958,8 +965,9 @@ var DrawingHelper = new Lang.Class({ for (let settingKey in MEDIA_KEYS_KEYS) { if (!mediaKeysSettings.settings_schema.has_key(settingKey)) - return; - let [keyval, mods] = Gtk.accelerator_parse(mediaKeysSettings.get_string(settingKey)); + continue; + let shortcut = GS_VERSION < '3.33.0' ? mediaKeysSettings.get_string(settingKey) : mediaKeysSettings.get_strv(settingKey)[0]; + let [keyval, mods] = Gtk.accelerator_parse(shortcut); let hbox = new St.BoxLayout({ vertical: false }); hbox.add(new St.Label({ text: _(MEDIA_KEYS_KEYS[settingKey]) })); hbox.add(new St.Label({ text: Gtk.accelerator_get_label(keyval, mods) }), { expand: true }); @@ -1005,7 +1013,7 @@ var DrawingMenu = new Lang.Class({ this.area = area; let side = Clutter.get_default_text_direction() == Clutter.TextDirection.RTL ? St.Side.RIGHT : St.Side.LEFT; this.menu = new PopupMenu.PopupMenu(Main.layoutManager.dummyCursor, 0.25, side); - this.menuManager = new PopupMenu.PopupMenuManager({ actor: this.area }); + this.menuManager = new PopupMenu.PopupMenuManager(GS_VERSION < '3.33.0' ? { actor: this.area } : this.area); this.menuManager.addMenu(this.menu); Main.layoutManager.uiGroup.add_actor(this.menu.actor); @@ -1022,7 +1030,6 @@ var DrawingMenu = new Lang.Class({ this.linecapIcon = new Gio.FileIcon({ file: Gio.File.new_for_path(LINECAP_ICON_PATH) }); this.fullLineIcon = new Gio.FileIcon({ file: Gio.File.new_for_path(FULL_LINE_ICON_PATH) }); this.dashedLineIcon = new Gio.FileIcon({ file: Gio.File.new_for_path(DASHED_LINE_ICON_PATH) }); - }, disable: function() { @@ -1125,9 +1132,10 @@ var DrawingMenu = new Lang.Class({ _addSwitchItem: function(menu, label, iconFalse, iconTrue, target, targetProperty) { let item = new PopupMenu.PopupSwitchMenuItem(label, target[targetProperty]); + let itemActor = GS_VERSION < '3.33.0' ? item.actor : item; item.icon = new St.Icon({ style_class: 'popup-menu-icon' }); - item.actor.insert_child_at_index(item.icon, 1); + itemActor.insert_child_at_index(item.icon, 1); item.icon.set_gicon(target[targetProperty] ? iconTrue : iconFalse); item.connect('toggled', (item, state) => { @@ -1146,17 +1154,26 @@ var DrawingMenu = new Lang.Class({ _addSliderItem: function(menu, target, targetProperty) { let item = new PopupMenu.PopupBaseMenuItem({ activate: false }); + let itemActor = GS_VERSION < '3.33.0' ? item.actor : item; let label = new St.Label({ text: target[targetProperty] + " " + _("px"), style_class: 'draw-on-your-screen-menu-slider-label' }); let slider = new Slider.Slider(target[targetProperty] / 50); + let sliderActor = GS_VERSION < '3.33.0' ? slider.actor : slider; - slider.connect('value-changed', (slider, value, property) => { - target[targetProperty] = Math.max(Math.round(value * 50), 1); - label.set_text(target[targetProperty] + " px"); - }); + if (GS_VERSION < '3.33.0') { + slider.connect('value-changed', (slider, value, property) => { + target[targetProperty] = Math.max(Math.round(value * 50), 1); + label.set_text(target[targetProperty] + " px"); + }); + } else { + slider.connect('notify::value', () => { + target[targetProperty] = Math.max(Math.round(slider.value * 50), 1); + label.set_text(target[targetProperty] + " px"); + }); + } - item.actor.add(slider.actor, { expand: true }); - item.actor.add(label); - item.actor.connect('key-press-event', slider.onKeyPressEvent.bind(slider)); + itemActor.add(sliderActor, { expand: true }); + itemActor.add(label); + itemActor.connect('key-press-event', slider.onKeyPressEvent.bind(slider)); menu.addMenuItem(item); }, @@ -1222,7 +1239,8 @@ var DrawingMenu = new Lang.Class({ _addSeparator: function(menu) { let separator = new PopupMenu.PopupSeparatorMenuItem(' '); - separator.actor.add_style_class_name('draw-on-your-screen-menu-separator'); + let separatorActor = GS_VERSION < '3.33.0' ? separator.actor : separator; + separatorActor.add_style_class_name('draw-on-your-screen-menu-separator'); menu.addMenuItem(separator); } }); diff --git a/extension.js b/extension.js index e928394..2767def 100644 --- a/extension.js +++ b/extension.js @@ -26,6 +26,7 @@ const Meta = imports.gi.Meta; const Shell = imports.gi.Shell; const St = imports.gi.St; +const Config = imports.misc.config; const Main = imports.ui.main; const OsdWindow = imports.ui.osdWindow; const PanelMenu = imports.ui.panelMenu; @@ -35,6 +36,8 @@ const Convenience = Extension.imports.convenience; const Draw = Extension.imports.draw; const _ = imports.gettext.domain(Extension.metadata["gettext-domain"]).gettext; +const GS_VERSION = Config.PACKAGE_VERSION; + // DRAWING_ACTION_MODE is a custom Shell.ActionMode var DRAWING_ACTION_MODE = Math.pow(2,14); @@ -378,16 +381,17 @@ var DrawingIndicator = new Lang.Class({ _init: function() { let [menuAlignment, dontCreateMenu] = [0, true]; this.button = new PanelMenu.Button(menuAlignment, "Drawing Indicator", dontCreateMenu); + this.buttonActor = GS_VERSION < '3.33.0' ? this.button.actor: this.button; Main.panel.addToStatusArea('draw-on-your-screen-indicator', this.button); this.icon = new St.Icon({ icon_name: 'applications-graphics-symbolic', style_class: 'system-status-icon screencast-indicator' }); - this.button.actor.add_child(this.icon); - this.button.actor.visible = false; + this.buttonActor.add_child(this.icon); + this.buttonActor.visible = false; }, sync: function(visible) { - this.button.actor.visible = visible; + this.buttonActor.visible = visible; }, disable: function() {