|
| 1 | +const Applet = imports.ui.applet; |
| 2 | +const St = imports.gi.St; |
| 3 | +const Lang = imports.lang; |
| 4 | +const Clutter = imports.gi.Clutter; |
| 5 | +const Main = imports.ui.main; |
| 6 | +const Settings = imports.ui.settings; |
| 7 | +const PopupMenu = imports.ui.popupMenu; |
| 8 | +const SignalManager = imports.misc.signalManager; |
| 9 | +const Mainloop = imports.mainloop; |
| 10 | +const Tweener = imports.ui.tweener; |
| 11 | + |
| 12 | +class CinnamonBarApplet extends Applet.Applet { |
| 13 | + constructor(orientation, panel_height, instance_id) { |
| 14 | + super(orientation, panel_height, instance_id); |
| 15 | + this.settings = new Settings.AppletSettings(this, "[email protected]", instance_id); |
| 16 | + |
| 17 | + this.settings.bind("peek-at-desktop", "peek_at_desktop"); |
| 18 | + this.settings.bind("peek-delay", "peek_delay"); |
| 19 | + this.settings.bind("peek-opacity", "peek_opacity"); |
| 20 | + this.settings.bind("peek-blur", "peek_blur"); |
| 21 | + this.settings.bind("click-action", "click_action"); |
| 22 | + this.settings.bind("middle-click-action", "middle_click_action"); |
| 23 | + |
| 24 | + this.signals = new SignalManager.SignalManager(null); |
| 25 | + this.actor.connect('enter-event', Lang.bind(this, this._on_enter)); |
| 26 | + this.actor.connect('leave-event', Lang.bind(this, this._on_leave)); |
| 27 | + this.signals.connect(global.stage, 'notify::key-focus', this._on_leave, this); |
| 28 | + |
| 29 | + this._did_peek = false; |
| 30 | + this._peek_timeout_id = 0; |
| 31 | + |
| 32 | + this.actor.style_class = 'applet-cornerbar-box'; |
| 33 | + this.setAllowedLayout(Applet.AllowedLayout.BOTH); |
| 34 | + |
| 35 | + this.settings.connect("settings-changed", () => { |
| 36 | + this.set_tooltip(); |
| 37 | + }); |
| 38 | + this.set_tooltip(); |
| 39 | + |
| 40 | + this.on_orientation_changed(orientation); |
| 41 | + |
| 42 | + // Context menu |
| 43 | + let desktop_option = new PopupMenu.PopupMenuItem(_('Show the desktop')); |
| 44 | + desktop_option.connect('activate', () => this.show_desktop()); |
| 45 | + this._applet_context_menu.addMenuItem(desktop_option); |
| 46 | + let desklet_option = new PopupMenu.PopupMenuItem(_('Show the desklets')); |
| 47 | + desklet_option.connect('activate', () => this.show_desklets()); |
| 48 | + this._applet_context_menu.addMenuItem(desklet_option); |
| 49 | + let expo_option = new PopupMenu.PopupMenuItem(_('Show the workspace selector (Expo)')); |
| 50 | + expo_option.connect('activate', () => this.expo()); |
| 51 | + this._applet_context_menu.addMenuItem(expo_option); |
| 52 | + let scale_option = new PopupMenu.PopupMenuItem(_('Show the window selector (Scale)')); |
| 53 | + scale_option.connect('activate', () => this.scale()); |
| 54 | + this._applet_context_menu.addMenuItem(scale_option); |
| 55 | + } |
| 56 | + |
| 57 | + set_tooltip() { |
| 58 | + if (this.click_action == "show_desktop") |
| 59 | + this.set_applet_tooltip(_("Show the desktop")); |
| 60 | + else if (this.click_action == "show_desklets") |
| 61 | + this.set_applet_tooltip(_('Show the desklets')); |
| 62 | + else if (this.click_action == "show_expo") |
| 63 | + this.set_applet_tooltip(_('Show the workspace selector (Expo)')); |
| 64 | + else if (this.click_action == "show_scale") |
| 65 | + this.set_applet_tooltip(_('Show the window selector (Scale)')); |
| 66 | + } |
| 67 | + |
| 68 | + handleDragOver(source, actor, x, y, time){ |
| 69 | + this.show_desktop(); |
| 70 | + } |
| 71 | + |
| 72 | + on_panel_height_changed() { |
| 73 | + this.on_orientation_changed(this.orientation); |
| 74 | + } |
| 75 | + |
| 76 | + on_orientation_changed(neworientation) { |
| 77 | + this.orientation = neworientation; |
| 78 | + |
| 79 | + if (this.orientation == St.Side.TOP || this.orientation == St.Side.BOTTOM) { |
| 80 | + if (this._line) { |
| 81 | + this._line.destroy(); |
| 82 | + } |
| 83 | + |
| 84 | + this.actor.remove_style_class_name('vertical'); |
| 85 | + |
| 86 | + this._line = new St.BoxLayout({ style_class: 'applet-cornerbar', reactive: true, track_hover: true}); |
| 87 | + this.actor.add(this._line, { y_align: Clutter.ActorAlign.CENTER, x_align: Clutter.ActorAlign.CENTER, y_fill: true, y_expand: true}); |
| 88 | + } else { |
| 89 | + if (this._line) { |
| 90 | + this._line.destroy(); |
| 91 | + } |
| 92 | + |
| 93 | + this.actor.add_style_class_name('vertical'); |
| 94 | + |
| 95 | + this._line = new St.BoxLayout({ style_class: 'applet-cornerbar', reactive: true, track_hover: true }); |
| 96 | + this._line.add_style_class_name('vertical'); |
| 97 | + this._line.set_important(true); |
| 98 | + this.actor.add(this._line, { y_align: Clutter.ActorAlign.CENTER, x_align: Clutter.ActorAlign.CENTER}); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + _on_enter(event) { |
| 103 | + if (this.peek_at_desktop) { |
| 104 | + |
| 105 | + if (this._peek_timeout_id > 0) { |
| 106 | + Mainloop.source_remove(this._peek_timeout_id); |
| 107 | + this._peek_timeout_id = 0; |
| 108 | + } |
| 109 | + |
| 110 | + this._peek_timeout_id = Mainloop.timeout_add(this.peek_delay, Lang.bind(this, function() { |
| 111 | + if (this.actor.hover && |
| 112 | + !this._applet_context_menu.isOpen && |
| 113 | + !global.settings.get_boolean("panel-edit-mode")) { |
| 114 | + |
| 115 | + let windows = global.get_window_actors(); |
| 116 | + |
| 117 | + for (let i = 0; i < windows.length; i++) { |
| 118 | + let window = windows[i].meta_window; |
| 119 | + let compositor = windows[i]; |
| 120 | + |
| 121 | + if (window.get_title() !== "Desktop") { |
| 122 | + if (this.peek_blur) { |
| 123 | + if (!compositor.eff) |
| 124 | + compositor.eff = new Clutter.BlurEffect(); |
| 125 | + compositor.add_effect_with_name('peek-blur', compositor.eff); |
| 126 | + } |
| 127 | + |
| 128 | + Tweener.addTween(compositor, |
| 129 | + { |
| 130 | + opacity: this.peek_opacity / 100 * 255, |
| 131 | + time: 0.275, |
| 132 | + transition: "easeInSine" |
| 133 | + } |
| 134 | + ); |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + this._did_peek = true; |
| 139 | + } |
| 140 | + this._peek_timeout_id = 0; |
| 141 | + return false; |
| 142 | + })); |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + _on_leave(event) { |
| 147 | + if (this._did_peek) { |
| 148 | + this.show_all_windows(0.2); |
| 149 | + this._did_peek = false; |
| 150 | + } |
| 151 | + if (this._peek_timeout_id > 0) { |
| 152 | + Mainloop.source_remove(this._peek_timeout_id); |
| 153 | + this._peek_timeout_id = 0; |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + show_all_windows(time) { |
| 158 | + let windows = global.get_window_actors(); |
| 159 | + for(let i = 0; i < windows.length; i++){ |
| 160 | + let window = windows[i].meta_window; |
| 161 | + let compositor = windows[i]; |
| 162 | + |
| 163 | + Tweener.addTween(compositor, |
| 164 | + { |
| 165 | + opacity: 255, |
| 166 | + time: time, |
| 167 | + transition: "easeOutSine" |
| 168 | + } |
| 169 | + ); |
| 170 | + |
| 171 | + if (this.peek_blur && compositor.eff) { |
| 172 | + compositor.remove_effect(compositor.eff); |
| 173 | + } |
| 174 | + } |
| 175 | + } |
| 176 | + |
| 177 | + on_applet_clicked(event) { |
| 178 | + this.perform_action(this.click_action); |
| 179 | + } |
| 180 | + |
| 181 | + on_applet_middle_clicked(event) { |
| 182 | + this.perform_action(this.middle_click_action); |
| 183 | + } |
| 184 | + |
| 185 | + perform_action(action) { |
| 186 | + if (action == "show_desktop") |
| 187 | + this.show_desktop(); |
| 188 | + else if (action == "show_desklets") |
| 189 | + this.show_desklets(); |
| 190 | + else if (action == "show_expo") |
| 191 | + this.expo(); |
| 192 | + else if (action == "show_scale") |
| 193 | + this.scale(); |
| 194 | + } |
| 195 | + |
| 196 | + show_desktop() { |
| 197 | + global.workspace_manager.toggle_desktop(global.get_current_time()); |
| 198 | + this.show_all_windows(0); |
| 199 | + if (this._peek_timeout_id > 0) { |
| 200 | + Mainloop.source_remove(this._peek_timeout_id); |
| 201 | + this._peek_timeout_id = 0; |
| 202 | + } |
| 203 | + this._did_peek = false; |
| 204 | + } |
| 205 | + |
| 206 | + show_desklets() { |
| 207 | + Main.deskletContainer.toggle(); |
| 208 | + } |
| 209 | + |
| 210 | + expo() { |
| 211 | + if (!Main.expo.animationInProgress) |
| 212 | + Main.expo.toggle(); |
| 213 | + } |
| 214 | + |
| 215 | + scale() { |
| 216 | + if (!Main.overview.animationInProgress) |
| 217 | + Main.overview.toggle(); |
| 218 | + } |
| 219 | + |
| 220 | +} |
| 221 | + |
| 222 | +function main(metadata, orientation, panel_height, instance_id) { |
| 223 | + return new CinnamonBarApplet(orientation, panel_height, instance_id); |
| 224 | +} |
0 commit comments