forked from bobcao3/SESDE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
APanel.vala
161 lines (126 loc) · 3.86 KB
/
APanel.vala
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
using Wnck;
using Gtk;
using Na;
namespace Panel {
public class ActionMenu : Gtk.Window {
private Box box = new Box (Orientation.VERTICAL, 3);
private Button btn_shutdown = new Button ();
private Button btn_reboot = new Button ();
private ToggleButton btn_preferences = new ToggleButton ();
private Label label = new Label ("Actions .. ");
private GLib.SubprocessLauncher processL = new GLib.SubprocessLauncher (GLib.SubprocessFlags.NONE);
public void appear () {
this.show_all ();
}
public void vanish () {
this.hide ();
}
private void shutdown () {
try {
processL.spawnv ({"shutdown","-P","now",null});
} catch (Error e) {
stderr.printf ("Failed to shutdown: %s\n", e.message);
}
}
private void reboot () {
try {
processL.spawnv ({"shutdown","-r","now",null});
} catch (Error e) {
stderr.printf ("Failed to reboot: %s\n", e.message);
}
}
private void preferences () {
if (SESDE.prwin.visible) {
SESDE.prwin.vanish ();
} else {
SESDE.prwin.appear ();
}
}
public ActionMenu () {
btn_shutdown.set_label ("Shutdown");
btn_shutdown.clicked.connect (shutdown);
btn_reboot.set_label ("Reboot");
btn_reboot.clicked.connect (reboot);
btn_preferences.set_label ("Preferences");
btn_preferences.toggled.connect (preferences);
box.pack_start (label, true, true, 0);
box.pack_start (btn_shutdown, true, true, 0);
box.pack_start (btn_reboot, true, true, 0);
box.pack_start (btn_preferences, true, true, 0);
this.add (box);
this.window_position = Gtk.WindowPosition.CENTER_ALWAYS;
this.border_width = 3;
this.set_decorated (false);
this.set_skip_pager_hint (true);
this.set_skip_taskbar_hint (true);
this.set_keep_above (true);
this.stick ();
}
}
public class MainWindow : Gtk.Window {
private Box box = new Box (Orientation.HORIZONTAL, 0);
public ToggleButton button_launcher = new ToggleButton.with_mnemonic ("_Launch");
public ToggleButton button_action = new ToggleButton.with_mnemonic ("Action");
private Label time_dis = new Label ("0:0");
private ATaskl.TabletWindow tablet_win;
private ATaskl.ATaskContext actx;
private ActionMenu action = new ActionMenu ();
private ALaunch.MainWindow l_win;
private ATray.Tray syt = new ATray.Tray();
private void Launcher () {
if (l_win.visible) {
l_win.vanish ();
} else {
l_win.appear ();
}
}
private void Action () {
if (action.visible) {
action.vanish ();
} else {
action.appear ();
}
}
private void timer () {
GLib.DateTime now = new GLib.DateTime.now_local ();
string t = now.format(" %H:%M ");
time_dis.label = t;
}
private void tablet_multitask () {
if (tablet_win.visible) {
((ATaskl.TabletWindow) tablet_win).vanish ();
} else {
((ATaskl.TabletWindow) tablet_win).appear ();
}
}
public MainWindow (int runmode /* Can be null */) {
this.title = "APanel";
this.set_type_hint (Gdk.WindowTypeHint.DOCK);
Gdk.Screen screen = Gdk.Screen.get_default ();
this.set_default_size (screen.get_width (), 32);
button_launcher.toggled.connect (Launcher);
button_action.clicked.connect (Action);
if (runmode == 1) {
this.tablet_win = new ATaskl.TabletWindow ();
ToggleButton button_tablet_task = new ToggleButton.with_mnemonic ("_Multitask");
button_tablet_task.toggled.connect (tablet_multitask);
box.pack_start (button_tablet_task, false, true, 0);
}
box.pack_start (button_launcher, false, true, 0);
box.pack_start (button_action, false, true, 0);
if (runmode == 0) {
actx = new ATaskl.ATaskContext ();
box.pack_start (actx.tskl, false, true, 0);
}
box.pack_end (time_dis, false, true, 0);
box.pack_end (syt, false, false, 0);
this.set_decorated (false);
this.set_skip_pager_hint (true);
this.set_skip_taskbar_hint (true);
l_win = new ALaunch.MainWindow ();
GLib.Timeout.add (1000, (GLib.SourceFunc) timer);
timer ();
this.add(box);
}
}
}