-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapplication.vala
91 lines (85 loc) · 2.41 KB
/
application.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
/**
* Gtk Application framework implementation
*/
public class TabbedMux.Application : Gtk.Application {
internal Gee.Set<TMuxStream> streams = new Gee.HashSet<TMuxStream> ();
internal SavedSessions saved_sessions;
protected override void activate () {
unowned List<Gtk.Window>? windows = get_windows ();
if (windows == null) {
new Window (this).show_all ();
} else {
windows.data.present ();
}
}
internal Application () {
Object (application_id: "name.masella.tabbedmux");
saved_sessions = new SavedSessions (application_id);
}
/**
* Add a new TMuxStream to the applications menus.
*
* This registers all the appropriate callbacks so the application can handle events from the stream.
*/
public void add_stream (TMuxStream stream) {
if (stream in streams) {
return;
}
unowned Application unowned_this = this;
stream.connection_closed.connect (unowned_this.on_stream_closed);
stream.window_created.connect (unowned_this.on_window_created);
streams.add (stream);
stream.start ();
foreach (var window in get_windows ()) {
if (window is Window) {
((Window) window).add_new_stream (stream);
}
}
message ("Added TMux stream for %s:%s.", stream.name, stream.session_name);
}
/**
* Deal with a stream dying for any reason.
*/
private void on_stream_closed (TMuxStream stream, string reason) {
streams.remove (stream);
try {
var notification = new Notify.Notification (@"Disconnected from $(stream.name) session '$(stream.session_name)'.", reason, null);
notification.show ();
} catch (Error e) {
critical ("Notification error: %s", e.message);
}
}
/**
* When a window is created remotely, figure out what GTK+ windw to stick it in.
*/
private void on_window_created (TMuxWindow tmux_window) {
var window = (active_window as Window);
if (window == null) {
foreach (var possible_window in get_windows ()) {
window = (possible_window as Window);
if (window != null) {
break;
}
}
}
if (window == null) {
critical ("Can't find a Gtk+ window to hold the TMux window.");
return;
}
((!)window).add_window (tmux_window);
}
/**
* On startup, create a TMux on the current system.
*/
protected override void startup () {
base.startup ();
try {
var stream = TMuxLocalStream.open ("0");
if (stream != null) {
add_stream ((!)stream);
}
} catch (Error e) {
critical ("Startup error: %s", e.message);
}
}
}