-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSessionBox.vala
More file actions
111 lines (90 loc) · 3.68 KB
/
SessionBox.vala
File metadata and controls
111 lines (90 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2024 elementary, Inc. (https://elementary.io)
*/
public class QuickSettings.SessionBox : Gtk.Box {
public Wingpanel.IndicatorManager.ServerType server_type { get; construct; }
private Gtk.Popover? popover;
public SessionBox (Wingpanel.IndicatorManager.ServerType server_type) {
Object (server_type: server_type);
}
construct {
var settings_button = new Gtk.Button.from_icon_name ("preferences-system-symbolic") {
tooltip_text = _("System Settings…")
};
settings_button.get_style_context ().add_class ("circular");
var suspend_button = new Gtk.Button.from_icon_name ("system-suspend-symbolic") {
tooltip_text = _("Suspend")
};
suspend_button.get_style_context ().add_class ("circular");
var lock_button = new Gtk.Button.from_icon_name ("system-lock-screen-symbolic") {
tooltip_text = _("Lock")
};
lock_button.get_style_context ().add_class ("circular");
var shutdown_button = new Gtk.Button.from_icon_name ("system-shutdown-symbolic") {
tooltip_text = _("Shut Down…")
};
shutdown_button.get_style_context ().add_class ("circular");
spacing = 6;
add (settings_button);
add (suspend_button);
add (lock_button);
add (shutdown_button);
realize.connect (() => {
popover = (Gtk.Popover) get_ancestor (typeof (Gtk.Popover));
});
if (server_type == SESSION) {
setup_lock_interface.begin ((obj, res) => {
var lock_interface = setup_lock_interface.end (res);
lock_button.clicked.connect (() => {
popover.popdown ();
try {
lock_interface.lock ();
} catch (GLib.Error e) {
critical ("Unable to lock: %s", e.message);
}
});
});
} else {
remove (settings_button);
remove (lock_button);
}
shutdown_button.clicked.connect (() => {
popover.popdown ();
EndSessionDialogServer.get_default ().show_dialog (EndSessionDialogType.RESTART);
});
suspend_button.clicked.connect (() => {
popover.popdown ();
try {
Login1Manager.get_default ().proxy.suspend (true);
} catch (GLib.Error e) {
critical ("Unable to suspend: %s", e.message);
}
});
var keybinding_settings = new Settings ("org.gnome.settings-daemon.plugins.media-keys");
lock_button.tooltip_markup = Granite.markup_accel_tooltip (
keybinding_settings.get_strv ("screensaver"), _("Lock")
);
keybinding_settings.changed["screensaver"].connect (() => {
lock_button.tooltip_markup = Granite.markup_accel_tooltip (
keybinding_settings.get_strv ("screensaver"), _("Lock")
);
});
settings_button.clicked.connect (() => {
popover.popdown ();
try {
AppInfo.launch_default_for_uri ("settings://", null);
} catch (Error e) {
critical ("Failed to open system settings: %s", e.message);
}
});
}
private async LockInterface? setup_lock_interface () {
try {
return yield Bus.get_proxy (BusType.SESSION, "org.gnome.ScreenSaver", "/org/gnome/ScreenSaver");
} catch (IOError e) {
critical ("Unable to connect to lock interface: %s", e.message);
return null;
}
}
}