Before I screw things up
This commit is contained in:
parent
45058b4272
commit
8ec06d3618
4 changed files with 71 additions and 4 deletions
|
@ -398,6 +398,7 @@ exec --no-startup-id keynav # Keyboard cursor controller
|
|||
# exec --no-startup-id ~/.config/i3/ashuffle # MPD Auto-refill
|
||||
exec --no-startup-id autorandr --change # Screen configuration and everything that depends on it
|
||||
exec --no-startup-id ~/.config/i3/batteryNotify -d # Battery state notification
|
||||
exec --no-startup-id ~/.config/i3/screentime # Activity tracker
|
||||
|
||||
set $ignore #ff00000
|
||||
|
||||
|
|
66
config/i3/screentime
Executable file
66
config/i3/screentime
Executable file
|
@ -0,0 +1,66 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Logs what window is in focus
|
||||
"""
|
||||
|
||||
import csv
|
||||
import datetime
|
||||
import os
|
||||
import typing
|
||||
|
||||
import i3ipc
|
||||
|
||||
|
||||
class ScreenTime:
|
||||
FIELDS = ["date", "type", "class", "role", "instance", "title"]
|
||||
|
||||
def write(self, line: typing.Dict) -> None:
|
||||
now = datetime.datetime.now()
|
||||
line["date"] = now.timestamp()
|
||||
|
||||
print("WROTE", line)
|
||||
with open(self.csv_path, 'a') as typedfd:
|
||||
writer = csv.DictWriter(typedfd, fieldnames=self.FIELDS)
|
||||
writer.writerow(line)
|
||||
|
||||
def on_window_event(self, _: i3ipc.connection.Connection,
|
||||
e: i3ipc.events.WindowEvent) -> None:
|
||||
focused = self.i3.get_tree().find_focused()
|
||||
self.write({
|
||||
"type": "window_" + e.change,
|
||||
"class": focused.window_class,
|
||||
"role": focused.window_role,
|
||||
"title": focused.window_title,
|
||||
"instance": focused.window_instance,
|
||||
})
|
||||
|
||||
def on_mode_event(self, _: i3ipc.connection.Connection,
|
||||
e: i3ipc.events.ModeEvent) -> None:
|
||||
self.write({
|
||||
"type": "mode",
|
||||
"title": e.change
|
||||
})
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.i3 = i3ipc.Connection()
|
||||
self.i3.on(i3ipc.Event.WINDOW, self.on_window_event)
|
||||
self.i3.on(i3ipc.Event.MODE, self.on_mode_event)
|
||||
|
||||
self.csv_path = os.path.join(
|
||||
os.path.expanduser(
|
||||
os.getenv('XDG_CACHE_PATH', '~/.cache/')),
|
||||
'screentime.csv')
|
||||
if not os.path.isfile(self.csv_path):
|
||||
with open(self.csv_path, 'w') as typedfd:
|
||||
writer = csv.DictWriter(typedfd, fieldnames=self.FIELDS)
|
||||
writer.writeheader()
|
||||
self.write({"type": "start"})
|
||||
|
||||
def main(self) -> None:
|
||||
self.i3.main()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
ST = ScreenTime()
|
||||
ST.main()
|
Loading…
Add table
Add a link
Reference in a new issue