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 var cf = File.new_for_path("/proc/%u/cmdline".printf(pid));
76 var dis = new DataInputStream (cf.read ());
77 cmd = dis.read_line (null);
83 print(this.win +"\n" + cmd + "\n");
84 if (this.win.length < 1 || (win != this.win)) {
86 //print((xDate.newDate()).format("Y-m-d H:i:s") + " " + win + ' - '+ cmd );
91 print(e.message + "\n");
99 public void write (string cmd , string str) throws Error
102 var now = new DateTime.now(new TimeZone.local());
104 var dir = this.outdir + now.format("/%Y/%m");
108 if (this.lastdir.length < 1 || this.lastdir != dir) {
109 if (!FileUtils.test(dir, FileTest.IS_DIR)) {
110 if (!FileUtils.test(Path.get_dirname(dir), FileTest.IS_DIR)) {
111 File.new_for_path(Path.get_dirname(dir)).make_directory(null);
113 File.new_for_path(dir).make_directory(null);
119 var fname = now.format("/%d") + ".log";
120 var path = dir + "/" + fname;
121 var time = now.format("%H:%M:%S ");
122 print("time: " + time + "\n");
123 var f = File.new_for_path(path);
124 FileOutputStream ios = f.append_to (FileCreateFlags.NONE);
125 var data_out = new DataOutputStream (ios);
127 data_out.put_string("\n" +time + str + " " + cmd, null);
128 print(time + str + " " + cmd + "\n");
129 data_out.close(null);
133 // copy to gitlive/gitlog (each user should check out their own gitlog!?
134 if (this.lastcopy != null && this.lastcopy.format("%H") == now.format("%H")) {
139 var cpdir = GitMonitor.gitlive +
140 "/gitlog" + now.format("/%Y/%m");
142 if (!FileUtils.test(cpdir, FileTest.IS_DIR)) {
143 if (!FileUtils.test(Path.get_dirname(cpdir), FileTest.IS_DIR)) {
144 File.new_for_path(Path.get_dirname(cpdir)).make_directory(null);
146 File.new_for_path(cpdir).make_directory(null);
149 var src = File.new_for_path(path);
150 var dest = File.new_for_path(cpdir + fname);
152 src.copy(dest, FileCopyFlags.OVERWRITE);