-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPopoverWidget.vala
More file actions
216 lines (173 loc) · 7.03 KB
/
PopoverWidget.vala
File metadata and controls
216 lines (173 loc) · 7.03 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2023 elementary, Inc. (https://elementary.io)
*/
public class QuickSettings.PopoverWidget : Gtk.Box {
public Wingpanel.IndicatorManager.ServerType server_type { get; construct; }
private const string FDO_ACCOUNTS_NAME = "org.freedesktop.Accounts";
private const string FDO_ACCOUNTS_PATH = "/org/freedesktop/Accounts";
private Gtk.Popover? popover;
private Gtk.Stack stack;
private Gtk.Box main_box;
private UserList accounts_view;
private Gtk.Button current_user_button;
public PopoverWidget (Wingpanel.IndicatorManager.ServerType server_type) {
Object (server_type: server_type);
}
class construct {
set_css_name ("quicksettings");
}
construct {
var tattle_box = new TattleBox () {
halign = CENTER
};
var screen_reader = new SettingsToggle (
_("Screen Reader")
) {
icon_name = "orca-symbolic",
settings_uri = "settings://sound"
};
var onscreen_keyboard = new SettingsToggle (
_("Onscreen Keyboard")
) {
icon_name = "input-keyboard-symbolic",
settings_uri = "settings://input/keyboard/behavior"
};
var prevent_sleep_toggle = new PreventSleepToggle ();
var toggle_box = new Gtk.FlowBox () {
column_spacing = 6,
homogeneous = true,
max_children_per_line = 3,
row_spacing = 12,
selection_mode = NONE
};
toggle_box.get_style_context ().add_class ("togglebox");
toggle_box.add (prevent_sleep_toggle);
var text_scale = new TextScale ();
var scale_box = new Gtk.Box (VERTICAL, 0);
var current_user = new AvatarButton ();
current_user_button = new Gtk.Button () {
child = current_user
};
current_user_button.get_style_context ().add_class ("circular");
current_user_button.get_style_context ().add_class ("flat");
current_user_button.get_style_context ().add_class ("no-padding");
var session_box = new SessionBox (server_type) {
halign = END,
hexpand = true,
margin_start = 6
};
var bottom_box = new Gtk.Box (HORIZONTAL, 0);
bottom_box.add (current_user_button);
bottom_box.add (session_box);
bottom_box.get_style_context ().add_class ("togglebox");
main_box = new Gtk.Box (VERTICAL, 0);
main_box.add (tattle_box);
main_box.add (toggle_box);
main_box.add (scale_box);
main_box.add (new Gtk.Separator (HORIZONTAL));
main_box.add (bottom_box);
accounts_view = new UserList ();
stack = new Gtk.Stack () {
vhomogeneous = false,
hhomogeneous = true,
transition_type = SLIDE_LEFT_RIGHT
};
stack.add (main_box);
stack.add (accounts_view);
add (stack);
if (server_type == GREETER) {
bottom_box.remove (current_user_button);
}
if (server_type != GREETER) {
var darkmode_button = new DarkModeToggle ();
toggle_box.add (darkmode_button);
show_all ();
}
setup_sensor_proxy.begin ((obj, res) => {
var sensor_proxy = setup_sensor_proxy.end (res);
if (sensor_proxy.has_accelerometer) {
var rotation_toggle = new RotationToggle ();
toggle_box.add (rotation_toggle);
show_all ();
};
});
realize.connect (() => {
popover = (Gtk.Popover) get_ancestor (typeof (Gtk.Popover));
});
var applications_settings = new Settings ("org.gnome.desktop.a11y.applications");
applications_settings.bind ("screen-reader-enabled", screen_reader, "active", DEFAULT);
var glib_settings = new Settings ("io.elementary.desktop.quick-settings");
if (server_type == GREETER || glib_settings.get_boolean ("show-a11y")) {
toggle_box.add (screen_reader);
toggle_box.add (onscreen_keyboard);
scale_box.add (text_scale);
}
glib_settings.changed["show-a11y"].connect (() => {
if (glib_settings.get_boolean ("show-a11y") && screen_reader.parent == null) {
toggle_box.add (screen_reader);
toggle_box.add (onscreen_keyboard);
scale_box.add (text_scale);
} else {
toggle_box.remove (screen_reader);
toggle_box.remove (onscreen_keyboard);
scale_box.remove (text_scale);
}
});
current_user_button.clicked.connect (() => {
stack.visible_child = accounts_view;
});
if (!(Gdk.Display.get_default () is Gdk.Wayland.Display)) {
applications_settings.bind ("screen-keyboard-enabled", onscreen_keyboard, "active", DEFAULT);
} else {
onscreen_keyboard.notify["active"].connect (() => {
if (!onscreen_keyboard.active) {
return;
}
onscreen_keyboard.active = false;
var message_dialog = new Granite.MessageDialog (
_("On Screen keyboard is unavailable in the Secure session"),
_("Log out and select “Classic session” to use the On Screen Keyboard."),
new ThemedIcon ("onboard")
) {
badge_icon = new ThemedIcon ("system-log-out"),
transient_for = (Gtk.Window) get_toplevel ()
};
message_dialog.response.connect (message_dialog.destroy);
message_dialog.present ();
});
}
}
private async SensorProxy? setup_sensor_proxy () {
try {
return yield Bus.get_proxy (BusType.SYSTEM, "net.hadess.SensorProxy", "/net/hadess/SensorProxy");
} catch (Error e) {
info ("Unable to connect to SensorProxy bus, probably means no accelerometer supported: %s", e.message);
return null;
}
}
public void reset_stack () {
stack.visible_child = main_box;
}
public async void update_user_tooltip () {
if (server_type != SESSION || is_running_in_demo_mode ()) {
current_user_button.tooltip_text = _("Not logged in");
return;
}
current_user_button.tooltip_markup = yield UserManager.get_loggedin_tooltip_markup ();
}
private bool is_running_in_demo_mode () {
var proc_cmdline = File.new_for_path ("/proc/cmdline");
try {
var @is = proc_cmdline.read ();
var dis = new DataInputStream (@is);
var line = dis.read_line ();
if ("boot=casper" in line || "boot=live" in line || "rd.live.image" in line) {
return true;
}
} catch (Error e) {
critical ("Couldn't detect if running in Demo Mode: %s", e.message);
}
return false;
}
}