Skip to content

Commit ce770e3

Browse files
committed
Add new cornerbar applet
1 parent 7135162 commit ce770e3

File tree

4 files changed

+314
-0
lines changed

4 files changed

+314
-0
lines changed

data/theme/cinnamon.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,25 @@ StScrollBar StButton#vhandle:hover {
17911791
border-bottom-width: 2px;
17921792
}
17931793

1794+
.applet-cornerbar-box {
1795+
padding: 4px 4px;
1796+
background: rgba(255,255,255,0);
1797+
}
1798+
1799+
.applet-cornerbar {
1800+
width: 8px;
1801+
background: rgba(255,255,255,0.3);
1802+
}
1803+
1804+
.applet-cornerbar.vertical {
1805+
height: 8px;
1806+
}
1807+
1808+
.applet-cornerbar-box:hover > .applet-cornerbar {
1809+
background: rgba(255,255,255,0.4);
1810+
}
1811+
1812+
17941813
.applet-box {
17951814
padding-left: 3px;
17961815
padding-right: 3px;
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
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+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"uuid": "[email protected]",
3+
"name": "Corner bar",
4+
"description": "A bar designed to be placed in the corner, used to show the desktop, desklets, the workspace selector or the window selector.",
5+
"icon": "cs-applets",
6+
"max-instances": -1
7+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"head" : {
3+
"type" : "header",
4+
"description" : "Settings"
5+
},
6+
"click-action": {
7+
"type": "combobox",
8+
"description": "Click action",
9+
"default": "show_desktop",
10+
"options" : {
11+
"Show the desktop": "show_desktop",
12+
"Show the desklets": "show_desklets",
13+
"Show the workspace selector (Expo)": "show_expo",
14+
"Show the window selector (Scale)": "show_scale"
15+
}
16+
},
17+
"middle-click-action": {
18+
"type": "combobox",
19+
"description": "Middle click action",
20+
"default": "show_desklets",
21+
"options" : {
22+
"Show the desktop": "show_desktop",
23+
"Show the desklets": "show_desklets",
24+
"Show the workspace selector (Expo)": "show_expo",
25+
"Show the window selector (Scale)": "show_scale"
26+
}
27+
},
28+
"peek-at-desktop" : {
29+
"type" : "switch",
30+
"default" : false,
31+
"description": "Peek at the desktop on hover",
32+
"tooltip": "Peek at the desktop when hovering the applet"
33+
},
34+
"peek-blur" : {
35+
"type" : "switch",
36+
"default" : false,
37+
"dependency" : "peek-at-desktop",
38+
"description" : "Blur effect",
39+
"tooltip" : "Blur windows when peeking at the desktop"
40+
},
41+
"peek-delay" : {
42+
"type": "spinbutton",
43+
"default" : 400,
44+
"min" : 0,
45+
"max" : 1000,
46+
"step" : 50,
47+
"units" : "milliseconds",
48+
"dependency" : "peek-at-desktop",
49+
"description": "Hover delay",
50+
"tooltip": "Delay before Peek shows desktop"
51+
},
52+
"peek-opacity": {
53+
"type": "scale",
54+
"default" : 5,
55+
"units": "%",
56+
"digits": 0,
57+
"min" : 0,
58+
"max" : 100,
59+
"step" : 5,
60+
"dependency" : "peek-at-desktop",
61+
"description" : "Window opacity",
62+
"tooltip" : "Change the opacity of windows when peeking at the desktop"
63+
}
64+
}

0 commit comments

Comments
 (0)