4 extern int xorg_idletime();
7 public class WindowLog : Object {
18 this.outdir = Environment.get_home_dir() + "/.gitlog";
19 this.screen = Wnck.Screen.get_default();
23 Timeout.add_full(Priority.LOW, 5000, () => {
24 return this.getStatus();
26 //Roo.log("Windowlog start");
27 this.screen.active_window_changed.connect((pr_win) => {
35 public bool getStatus()
38 var output = xorg_idletime();
40 // more that 10 seconds?? - report idle..
41 if (output * 1 > 10000) {
42 if (this.win.length > 0) {
43 //print( (xDate.newDate()).format("Y-m-d H:i:s") + " IDLE");
45 this.write("", "IDLE");
47 print(e.message + "\n");
56 public void windowChanged()
58 this.screen.force_update();
59 // print("window changeD");
60 var aw = this.screen.get_active_window();
65 var win = aw.get_name();
66 var app = aw.get_application();
67 var pid = app.get_pid();
68 //print("PID " + pid);
69 //var cmd = File.realpath('/proc/'+ pid + '/exe');
72 print("/proc/%u/cmdline".printf(pid) + "\n");
75 FileUtils.get_contents("/proc/%u/cmdline".printf(pid), out cmd, out len);
80 print(this.win +"\n" + cmd + "\n");
81 if (this.win.length < 1 || (win != this.win)) {
83 //print((xDate.newDate()).format("Y-m-d H:i:s") + " " + win + ' - '+ cmd );
88 print(e.message + "\n");
96 public void write (string cmd , string str) throws Error
99 var now = new DateTime.now(new TimeZone.local());
101 var dir = this.outdir + now.format("/%Y/%m");
103 if (this.lastdir.length < 1 || this.lastdir != dir) {
104 if (!FileUtils.test(dir, FileTest.IS_DIR)) {
105 if (!FileUtils.test(Path.get_dirname(dir), FileTest.IS_DIR)) {
106 File.new_for_path(Path.get_dirname(dir)).make_directory(null);
108 File.new_for_path(dir).make_directory(null);
114 var fname = now.format("/%d") + ".log";
115 var path = dir + "/" + fname;
116 var time = now.format("%H:%i:%s ");
117 var f = File.new_for_path(path);
118 FileOutputStream ios = f.append_to (FileCreateFlags.NONE);
119 var data_out = new DataOutputStream (ios);
121 data_out.put_string("\n" +time + str + " " + cmd, null);
122 print(time + str + " " + cmd + "\n");
123 data_out.close(null);
127 // copy to gitlive/gitlog (each user should check out their own gitlog!?
128 if (this.lastcopy != null && this.lastcopy.format("%H") == now.format("%H")) {
133 var cpdir = GitMonitor.gitlive +
134 "/gitlog" + now.format("/%Y/%m");
136 if (!FileUtils.test(cpdir, FileTest.IS_DIR)) {
137 if (!FileUtils.test(Path.get_dirname(cpdir), FileTest.IS_DIR)) {
138 File.new_for_path(Path.get_dirname(cpdir)).make_directory(null);
140 File.new_for_path(cpdir).make_directory(null);
143 var src = File.new_for_path(path);
144 var dest = File.new_for_path(cpdir + fname);
146 src.copy(dest, FileCopyFlags.OVERWRITE);