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( this.windowChanged );
33 public bool getStatus()
36 var output = xorg_idletime();
38 // more that 10 seconds?? - report idle..
39 if (output * 1 > 10000) {
40 if (this.win.length > 0) {
41 //print( (xDate.newDate()).format("Y-m-d H:i:s") + " IDLE");
43 this.write("", "IDLE");
45 GLib.debug("%s",e.message);
54 public void windowChanged(Wnck.Window? pr_win)
56 this.screen.force_update();
57 // print("window changeD");
58 var aw = this.screen.get_active_window();
63 var win = aw.get_name();
64 var app = aw.get_application();
65 var pid = app.get_pid();
66 //print("PID " + pid);
67 //var cmd = File.realpath('/proc/'+ pid + '/exe');
70 // print("/proc/%u/cmdline".printf(pid) + "\n");
73 var cf = File.new_for_path("/proc/%u/cmdline".printf(pid));
74 var dis = new DataInputStream (cf.read ());
75 cmd = dis.read_line (null);
81 //print(this.win +"\n" + cmd + "\n");
82 if (this.win.length < 1 || (win != this.win)) {
84 //print((xDate.newDate()).format("Y-m-d H:i:s") + " " + win + ' - '+ cmd );
89 GLib.debug("%s",e.message);
97 public void write (string cmd , string str) throws Error
100 var now = new DateTime.now(new TimeZone.local());
102 var dir = this.outdir + now.format("/%Y/%m");
106 if (this.lastdir.length < 1 || this.lastdir != dir) {
107 if (!FileUtils.test(dir, FileTest.IS_DIR)) {
108 if (!FileUtils.test(Path.get_dirname(dir), FileTest.IS_DIR)) {
109 File.new_for_path(Path.get_dirname(dir)).make_directory(null);
111 File.new_for_path(dir).make_directory(null);
117 var fname = now.format("/%d") + ".log";
118 var path = dir + "/" + fname;
119 var time = now.format("%H:%M:%S ");
120 //print("time: " + time + "\n");
121 var f = File.new_for_path(path);
122 var ios = f.append_to (FileCreateFlags.NONE);
123 var data_out = new DataOutputStream (ios);
125 data_out.put_string("\n" +time + str + " " + cmd, null);
126 GLib.debug("%s%s %s",time , str , cmd);
127 data_out.close(null);
131 // copy to gitlive/gitlog (each user should check out their own gitlog!?
132 if (this.lastcopy != null && this.lastcopy.format("%H") == now.format("%H")) {
137 var cpdir = GitMonitor.gitlive +
138 "/gitlog" + now.format("/%Y/%m");
140 if (!FileUtils.test(cpdir, FileTest.IS_DIR)) {
141 if (!FileUtils.test(Path.get_dirname(cpdir), FileTest.IS_DIR)) {
142 File.new_for_path(Path.get_dirname(cpdir)).make_directory(null);
144 File.new_for_path(cpdir).make_directory(null);
147 var src = File.new_for_path(path);
148 var dest = File.new_for_path(cpdir + fname);
150 src.copy(dest, FileCopyFlags.OVERWRITE);