diff options
Diffstat (limited to 'overlays')
-rw-r--r-- | overlays/batman-adv.nix | 15 | ||||
-rw-r--r-- | overlays/keepassxc/database-open-dialog.patch | 126 | ||||
-rw-r--r-- | overlays/keepassxc/default.nix | 8 | ||||
-rw-r--r-- | overlays/mako.nix | 5 | ||||
-rw-r--r-- | overlays/swayosd/default.nix | 30 | ||||
-rw-r--r-- | overlays/swayosd/exponential.patch | 57 | ||||
-rwxr-xr-x | overlays/worktime/worktime/__main__.py | 119 |
7 files changed, 324 insertions, 36 deletions
diff --git a/overlays/batman-adv.nix b/overlays/batman-adv.nix deleted file mode 100644 index cce7dc4f..00000000 --- a/overlays/batman-adv.nix +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | { final, prev, sources, ... }: { | ||
2 | linuxPackages_latest = prev.linuxPackages_latest.extend (self: super: { | ||
3 | batman_adv = super.batman_adv.overrideAttrs (oldAttrs: { | ||
4 | version = "${sources.batman-adv.version}-${self.kernel.version}"; | ||
5 | inherit (sources.batman-adv) src; | ||
6 | }); | ||
7 | }); | ||
8 | |||
9 | linuxPackages_6_2 = prev.linuxPackages_6_2.extend (self: super: { | ||
10 | batman_adv = super.batman_adv.overrideAttrs (oldAttrs: { | ||
11 | version = "${sources.batman-adv.version}-${self.kernel.version}"; | ||
12 | inherit (sources.batman-adv) src; | ||
13 | }); | ||
14 | }); | ||
15 | } | ||
diff --git a/overlays/keepassxc/database-open-dialog.patch b/overlays/keepassxc/database-open-dialog.patch new file mode 100644 index 00000000..4916dc1b --- /dev/null +++ b/overlays/keepassxc/database-open-dialog.patch | |||
@@ -0,0 +1,126 @@ | |||
1 | diff -u3 -r source.orig/src/browser/BrowserService.cpp source/src/browser/BrowserService.cpp | ||
2 | --- source.orig/src/browser/BrowserService.cpp 2025-01-27 20:55:04.128198171 +0100 | ||
3 | +++ source/src/browser/BrowserService.cpp 2025-01-27 21:16:07.068959077 +0100 | ||
4 | @@ -249,7 +249,7 @@ | ||
5 | return result; | ||
6 | } | ||
7 | |||
8 | - auto dialogResult = MessageBox::warning(m_currentDatabaseWidget, | ||
9 | + auto dialogResult = MessageBox::warning(nullptr, | ||
10 | tr("KeePassXC - Create a new group"), | ||
11 | tr("A request for creating a new group \"%1\" has been received.\n" | ||
12 | "Do you want to create this group?\n") | ||
13 | @@ -422,7 +422,7 @@ | ||
14 | |||
15 | m_dialogActive = true; | ||
16 | updateWindowState(); | ||
17 | - BrowserAccessControlDialog accessControlDialog(m_currentDatabaseWidget); | ||
18 | + BrowserAccessControlDialog accessControlDialog{}; | ||
19 | |||
20 | connect(m_currentDatabaseWidget, SIGNAL(databaseLockRequested()), &accessControlDialog, SLOT(reject())); | ||
21 | |||
22 | @@ -512,7 +512,7 @@ | ||
23 | QString id; | ||
24 | |||
25 | do { | ||
26 | - QInputDialog keyDialog(m_currentDatabaseWidget); | ||
27 | + QInputDialog keyDialog{}; | ||
28 | connect(m_currentDatabaseWidget, SIGNAL(databaseLockRequested()), &keyDialog, SLOT(reject())); | ||
29 | keyDialog.setWindowTitle(tr("KeePassXC - New key association request")); | ||
30 | keyDialog.setLabelText(tr("You have received an association request for the following database:\n%1\n\n" | ||
31 | @@ -535,7 +535,7 @@ | ||
32 | |||
33 | contains = db->metadata()->customData()->contains(CustomData::BrowserKeyPrefix + id); | ||
34 | if (contains) { | ||
35 | - dialogResult = MessageBox::warning(m_currentDatabaseWidget, | ||
36 | + dialogResult = MessageBox::warning(nullptr, | ||
37 | tr("KeePassXC - Overwrite existing key?"), | ||
38 | tr("A shared encryption key with the name \"%1\" " | ||
39 | "already exists.\nDo you want to overwrite it?") | ||
40 | @@ -595,7 +595,7 @@ | ||
41 | const auto existingEntries = getPasskeyEntriesWithUserHandle(rpId, userId, keyList); | ||
42 | |||
43 | raiseWindow(); | ||
44 | - BrowserPasskeysConfirmationDialog confirmDialog(m_currentDatabaseWidget); | ||
45 | + BrowserPasskeysConfirmationDialog confirmDialog{}; | ||
46 | confirmDialog.registerCredential(username, rpId, existingEntries, timeout); | ||
47 | |||
48 | auto dialogResult = confirmDialog.exec(); | ||
49 | @@ -612,7 +612,7 @@ | ||
50 | // If no entry is selected, show the import dialog for manual entry selection | ||
51 | auto selectedEntry = confirmDialog.getSelectedEntry(); | ||
52 | if (!selectedEntry) { | ||
53 | - PasskeyImporter passkeyImporter(m_currentDatabaseWidget); | ||
54 | + PasskeyImporter passkeyImporter{}; | ||
55 | const auto result = passkeyImporter.showImportDialog(db, | ||
56 | nullptr, | ||
57 | origin, | ||
58 | @@ -683,7 +683,7 @@ | ||
59 | const auto timeout = publicKeyOptions["timeout"].toInt(); | ||
60 | |||
61 | raiseWindow(); | ||
62 | - BrowserPasskeysConfirmationDialog confirmDialog(m_currentDatabaseWidget); | ||
63 | + BrowserPasskeysConfirmationDialog confirmDialog{}; | ||
64 | confirmDialog.authenticateCredential(entries, rpId, timeout); | ||
65 | auto dialogResult = confirmDialog.exec(); | ||
66 | if (dialogResult == QDialog::Accepted) { | ||
67 | @@ -760,7 +760,7 @@ | ||
68 | |||
69 | // Ask confirmation if entry already contains a Passkey | ||
70 | if (entry->hasPasskey()) { | ||
71 | - if (MessageBox::question(m_currentDatabaseWidget, | ||
72 | + if (MessageBox::question(nullptr, | ||
73 | tr("KeePassXC - Update passkey"), | ||
74 | tr("Entry already has a passkey.\nDo you want to overwrite the passkey in %1 - %2?") | ||
75 | .arg(entry->title(), passkeyUtils()->getUsernameFromEntry(entry)), | ||
76 | @@ -873,7 +873,7 @@ | ||
77 | MessageBox::Button dialogResult = MessageBox::No; | ||
78 | if (!browserSettings()->alwaysAllowUpdate()) { | ||
79 | raiseWindow(); | ||
80 | - dialogResult = MessageBox::question(m_currentDatabaseWidget, | ||
81 | + dialogResult = MessageBox::question(nullptr, | ||
82 | tr("KeePassXC - Update Entry"), | ||
83 | tr("Do you want to update the information in %1 - %2?") | ||
84 | .arg(QUrl(entryParameters.siteUrl).host(), username), | ||
85 | @@ -909,7 +909,7 @@ | ||
86 | return false; | ||
87 | } | ||
88 | |||
89 | - auto dialogResult = MessageBox::warning(m_currentDatabaseWidget, | ||
90 | + auto dialogResult = MessageBox::warning(nullptr, | ||
91 | tr("KeePassXC - Delete entry"), | ||
92 | tr("A request for deleting entry \"%1\" has been received.\n" | ||
93 | "Do you want to delete the entry?\n") | ||
94 | @@ -1536,7 +1536,7 @@ | ||
95 | } | ||
96 | } | ||
97 | |||
98 | - BrowserEntrySaveDialog browserEntrySaveDialog(m_currentDatabaseWidget); | ||
99 | + BrowserEntrySaveDialog browserEntrySaveDialog{}; | ||
100 | int openDatabaseCount = browserEntrySaveDialog.setItems(databaseWidgets, m_currentDatabaseWidget); | ||
101 | if (openDatabaseCount > 1) { | ||
102 | int res = browserEntrySaveDialog.exec(); | ||
103 | diff -u3 -r source.orig/src/fdosecrets/objects/Prompt.cpp source/src/fdosecrets/objects/Prompt.cpp | ||
104 | --- source.orig/src/fdosecrets/objects/Prompt.cpp 2025-01-27 20:55:04.135942791 +0100 | ||
105 | +++ source/src/fdosecrets/objects/Prompt.cpp 2025-01-27 21:01:37.166710935 +0100 | ||
106 | @@ -313,7 +313,7 @@ | ||
107 | if (!entries.isEmpty()) { | ||
108 | QString app = tr("%1 (PID: %2)").arg(client->name()).arg(client->pid()); | ||
109 | auto ac = new AccessControlDialog( | ||
110 | - findWindow(m_windowId), entries, app, client->processInfo(), AuthOption::Remember); | ||
111 | + nullptr, entries, app, client->processInfo(), AuthOption::Remember); | ||
112 | connect(ac, &AccessControlDialog::finished, this, &UnlockPrompt::itemUnlockFinished); | ||
113 | connect(ac, &AccessControlDialog::finished, ac, &AccessControlDialog::deleteLater); | ||
114 | ac->open(); | ||
115 | diff -u3 -r source.orig/src/gui/DatabaseTabWidget.cpp source/src/gui/DatabaseTabWidget.cpp | ||
116 | --- source.orig/src/gui/DatabaseTabWidget.cpp 2025-01-27 20:55:04.134589500 +0100 | ||
117 | +++ source/src/gui/DatabaseTabWidget.cpp 2025-01-27 21:07:09.785284837 +0100 | ||
118 | @@ -41,7 +41,7 @@ | ||
119 | : QTabWidget(parent) | ||
120 | , m_dbWidgetStateSync(new DatabaseWidgetStateSync(this)) | ||
121 | , m_dbWidgetPendingLock(nullptr) | ||
122 | - , m_databaseOpenDialog(new DatabaseOpenDialog(this)) | ||
123 | + , m_databaseOpenDialog(new DatabaseOpenDialog()) | ||
124 | , m_databaseOpenInProgress(false) | ||
125 | { | ||
126 | auto* tabBar = new QTabBar(this); | ||
diff --git a/overlays/keepassxc/default.nix b/overlays/keepassxc/default.nix new file mode 100644 index 00000000..25429a66 --- /dev/null +++ b/overlays/keepassxc/default.nix | |||
@@ -0,0 +1,8 @@ | |||
1 | { final, prev, ... }: | ||
2 | { | ||
3 | keepassxc = prev.keepassxc.overrideAttrs (oldAttrs: { | ||
4 | patches = (oldAttrs.patches or []) ++ [ | ||
5 | ./database-open-dialog.patch | ||
6 | ]; | ||
7 | }); | ||
8 | } | ||
diff --git a/overlays/mako.nix b/overlays/mako.nix new file mode 100644 index 00000000..1c1464fb --- /dev/null +++ b/overlays/mako.nix | |||
@@ -0,0 +1,5 @@ | |||
1 | { final, prev, sources, ... }: { | ||
2 | mako = prev.mako.overrideAttrs (oldAttrs: { | ||
3 | inherit (sources.mako) version src; | ||
4 | }); | ||
5 | } | ||
diff --git a/overlays/swayosd/default.nix b/overlays/swayosd/default.nix new file mode 100644 index 00000000..28c8f1b9 --- /dev/null +++ b/overlays/swayosd/default.nix | |||
@@ -0,0 +1,30 @@ | |||
1 | { final, prev, sources, ... }: { | ||
2 | swayosd = prev.swayosd.overrideAttrs (oldAttrs: rec { | ||
3 | inherit (sources.swayosd) version src; | ||
4 | cargoDeps = prev.rustPlatform.fetchCargoTarball { | ||
5 | inherit (oldAttrs) pname; | ||
6 | inherit version src; | ||
7 | hash = "sha256-Anrk8p76HKZcNavYdi9l1oYahduLrb7Lf7knQK7Hy5E="; | ||
8 | }; | ||
9 | nativeBuildInputs = with final; [ | ||
10 | wrapGAppsHook4 | ||
11 | pkg-config | ||
12 | meson | ||
13 | rustc | ||
14 | cargo | ||
15 | ninja | ||
16 | rustPlatform.cargoSetupHook | ||
17 | ]; | ||
18 | buildInputs = with final; [ | ||
19 | gtk4-layer-shell | ||
20 | libevdev | ||
21 | libinput | ||
22 | libpulseaudio | ||
23 | udev | ||
24 | sassc | ||
25 | ]; | ||
26 | patches = (oldAttrs.patches or []) ++ [ | ||
27 | ./exponential.patch | ||
28 | ]; | ||
29 | }); | ||
30 | } | ||
diff --git a/overlays/swayosd/exponential.patch b/overlays/swayosd/exponential.patch new file mode 100644 index 00000000..eb90d739 --- /dev/null +++ b/overlays/swayosd/exponential.patch | |||
@@ -0,0 +1,57 @@ | |||
1 | diff --git a/src/brightness_backend/brightnessctl.rs b/src/brightness_backend/brightnessctl.rs | ||
2 | index ccb0e11..740fdb6 100644 | ||
3 | --- a/src/brightness_backend/brightnessctl.rs | ||
4 | +++ b/src/brightness_backend/brightnessctl.rs | ||
5 | @@ -107,10 +107,21 @@ impl VirtualDevice { | ||
6 | } | ||
7 | } | ||
8 | |||
9 | - fn set_percent(&mut self, mut val: u32) -> anyhow::Result<()> { | ||
10 | - val = val.clamp(0, 100); | ||
11 | - self.current = self.max.map(|max| val * max / 100); | ||
12 | - let _: String = self.run(("set", &*format!("{val}%")))?; | ||
13 | + fn val_to_percent(&mut self, val: u32) -> u32 { | ||
14 | + return ((val as f64 / self.get_max() as f64).powf(0.25) * 100_f64).round() as u32; | ||
15 | + } | ||
16 | + fn percent_to_val(&mut self, perc: u32) -> u32 { | ||
17 | + return ((perc as f64 / 100_f64).powf(4_f64) * self.get_max() as f64).round() as u32; | ||
18 | + } | ||
19 | + | ||
20 | + fn set_percent(&mut self, val: u32) -> anyhow::Result<()> { | ||
21 | + let new = self.percent_to_val(val); | ||
22 | + self.set_val(new) | ||
23 | + } | ||
24 | + fn set_val(&mut self, val: u32) -> anyhow::Result<()> { | ||
25 | + let curr = val.clamp(0, self.get_max()); | ||
26 | + self.current = Some(curr); | ||
27 | + let _: String = self.run(("set", &*format!("{curr}")))?; | ||
28 | Ok(()) | ||
29 | } | ||
30 | } | ||
31 | @@ -134,20 +145,18 @@ impl BrightnessBackend for BrightnessCtl { | ||
32 | |||
33 | fn lower(&mut self, by: u32) -> anyhow::Result<()> { | ||
34 | let curr = self.get_current(); | ||
35 | - let max = self.get_max(); | ||
36 | - | ||
37 | - let curr = curr * 100 / max; | ||
38 | + let mut new = self.device.val_to_percent(curr).saturating_sub(by); | ||
39 | + new = self.device.percent_to_val(new).min(curr.saturating_sub(1)); | ||
40 | |||
41 | - self.device.set_percent(curr.saturating_sub(by)) | ||
42 | + self.device.set_val(new) | ||
43 | } | ||
44 | |||
45 | fn raise(&mut self, by: u32) -> anyhow::Result<()> { | ||
46 | let curr = self.get_current(); | ||
47 | - let max = self.get_max(); | ||
48 | - | ||
49 | - let curr = curr * 100 / max; | ||
50 | + let mut new = self.device.val_to_percent(curr) + by; | ||
51 | + new = self.device.percent_to_val(new).max(curr + 1); | ||
52 | |||
53 | - self.device.set_percent(curr + by) | ||
54 | + self.device.set_val(new) | ||
55 | } | ||
56 | |||
57 | fn set(&mut self, val: u32) -> anyhow::Result<()> { | ||
diff --git a/overlays/worktime/worktime/__main__.py b/overlays/worktime/worktime/__main__.py index 362c8da4..ba6c5ff6 100755 --- a/overlays/worktime/worktime/__main__.py +++ b/overlays/worktime/worktime/__main__.py | |||
@@ -23,7 +23,7 @@ import argparse | |||
23 | from copy import deepcopy | 23 | from copy import deepcopy |
24 | 24 | ||
25 | import sys | 25 | import sys |
26 | from sys import stderr | 26 | from sys import stderr, stdout |
27 | 27 | ||
28 | from tabulate import tabulate | 28 | from tabulate import tabulate |
29 | 29 | ||
@@ -38,6 +38,7 @@ from collections import defaultdict | |||
38 | 38 | ||
39 | import jsonpickle | 39 | import jsonpickle |
40 | from hashlib import blake2s | 40 | from hashlib import blake2s |
41 | import json | ||
41 | 42 | ||
42 | class TogglAPISection(Enum): | 43 | class TogglAPISection(Enum): |
43 | TOGGL = '/api/v9' | 44 | TOGGL = '/api/v9' |
@@ -223,6 +224,7 @@ class Worktime(object): | |||
223 | leave_budget = dict() | 224 | leave_budget = dict() |
224 | time_per_day = None | 225 | time_per_day = None |
225 | workdays = None | 226 | workdays = None |
227 | pull_forward = dict() | ||
226 | 228 | ||
227 | @staticmethod | 229 | @staticmethod |
228 | @cache | 230 | @cache |
@@ -390,8 +392,6 @@ class Worktime(object): | |||
390 | if e.errno != 2: | 392 | if e.errno != 2: |
391 | raise e | 393 | raise e |
392 | 394 | ||
393 | pull_forward = dict() | ||
394 | |||
395 | start_day = self.start_date.date() | 395 | start_day = self.start_date.date() |
396 | end_day = self.end_date.date() | 396 | end_day = self.end_date.date() |
397 | 397 | ||
@@ -418,15 +418,15 @@ class Worktime(object): | |||
418 | if not d == datetime.strptime(c, date_format).replace(tzinfo=tzlocal()).date(): break | 418 | if not d == datetime.strptime(c, date_format).replace(tzinfo=tzlocal()).date(): break |
419 | else: | 419 | else: |
420 | if d >= self.end_date.date(): | 420 | if d >= self.end_date.date(): |
421 | pull_forward[d] = min(timedelta(hours = float(hours)), self.time_per_day(d) - (holidays[d] if d in holidays else timedelta())) | 421 | self.pull_forward[d] = min(timedelta(hours = float(hours)), self.time_per_day(d) - (holidays[d] if d in holidays else timedelta())) |
422 | except IOError as e: | 422 | except IOError as e: |
423 | if e.errno != 2: | 423 | if e.errno != 2: |
424 | raise e | 424 | raise e |
425 | 425 | ||
426 | self.days_to_work = dict() | 426 | self.days_to_work = dict() |
427 | 427 | ||
428 | if pull_forward: | 428 | if self.pull_forward: |
429 | end_day = max(end_day, max(list(pull_forward))) | 429 | end_day = max(end_day, max(list(self.pull_forward))) |
430 | 430 | ||
431 | for day in [start_day + timedelta(days = x) for x in range(0, (end_day - start_day).days + 1)]: | 431 | for day in [start_day + timedelta(days = x) for x in range(0, (end_day - start_day).days + 1)]: |
432 | if day.isoweekday() in self.workdays: | 432 | if day.isoweekday() in self.workdays: |
@@ -470,17 +470,17 @@ class Worktime(object): | |||
470 | self.extra_days_to_work[self.now.date()] = timedelta() | 470 | self.extra_days_to_work[self.now.date()] = timedelta() |
471 | 471 | ||
472 | self.time_to_work = sum([self.days_to_work[day] for day in self.days_to_work.keys() if day <= self.end_date.date()], timedelta()) | 472 | self.time_to_work = sum([self.days_to_work[day] for day in self.days_to_work.keys() if day <= self.end_date.date()], timedelta()) |
473 | for day in [d for d in list(pull_forward) if d > self.end_date.date()]: | 473 | for day in [d for d in list(self.pull_forward) if d > self.end_date.date()]: |
474 | days_forward = set([d for d in self.days_to_work.keys() if d >= self.end_date.date() and d < day and (not d in pull_forward or d == self.end_date.date())]) | 474 | days_forward = set([d for d in self.days_to_work.keys() if d >= self.end_date.date() and d < day and (not d in self.pull_forward or d == self.end_date.date())]) |
475 | extra_days_forward = set([d for d in self.extra_days_to_work.keys() if d >= self.end_date.date() and d < day and (not d in pull_forward or d == self.end_date.date())]) | 475 | extra_days_forward = set([d for d in self.extra_days_to_work.keys() if d >= self.end_date.date() and d < day and (not d in self.pull_forward or d == self.end_date.date())]) |
476 | days_forward = days_forward.union(extra_days_forward) | 476 | days_forward = days_forward.union(extra_days_forward) |
477 | 477 | ||
478 | extra_day_time_left = timedelta() | 478 | extra_day_time_left = timedelta() |
479 | for extra_day in extra_days_forward: | 479 | for extra_day in extra_days_forward: |
480 | day_time = max(timedelta(), self.time_per_day(extra_day) - self.extra_days_to_work[extra_day]) | 480 | day_time = max(timedelta(), self.time_per_day(extra_day) - self.extra_days_to_work[extra_day]) |
481 | extra_day_time_left += day_time | 481 | extra_day_time_left += day_time |
482 | extra_day_time = min(extra_day_time_left, pull_forward[day]) | 482 | extra_day_time = min(extra_day_time_left, self.pull_forward[day]) |
483 | time_forward = pull_forward[day] - extra_day_time | 483 | time_forward = self.pull_forward[day] - extra_day_time |
484 | if extra_day_time_left > timedelta(): | 484 | if extra_day_time_left > timedelta(): |
485 | for extra_day in extra_days_forward: | 485 | for extra_day in extra_days_forward: |
486 | day_time = max(timedelta(), self.time_per_day(extra_day) - self.extra_days_to_work[extra_day]) | 486 | day_time = max(timedelta(), self.time_per_day(extra_day) - self.extra_days_to_work[extra_day]) |
@@ -518,7 +518,14 @@ def format_days(worktime, days, date_format=None): | |||
518 | return ', '.join(map(lambda group: ','.join(map(format_group, group)), groups)) | 518 | return ', '.join(map(lambda group: ','.join(map(format_group, group)), groups)) |
519 | 519 | ||
520 | 520 | ||
521 | def worktime(**args): | 521 | def tooltip_timedelta(td): |
522 | if td < timedelta(seconds = 0): | ||
523 | return "-" + tooltip_timedelta(-td) | ||
524 | mm, ss = divmod(td.total_seconds(), 60) | ||
525 | hh, mm = divmod(mm, 60) | ||
526 | return "%d:%02d:%02d" % (hh, mm, ss) | ||
527 | |||
528 | def worktime(pull_forward_cutoff, waybar, **args): | ||
522 | worktime = Worktime(**args) | 529 | worktime = Worktime(**args) |
523 | 530 | ||
524 | def format_worktime(worktime): | 531 | def format_worktime(worktime): |
@@ -562,7 +569,12 @@ def worktime(**args): | |||
562 | else: | 569 | else: |
563 | return f"({difference_string})" | 570 | return f"({difference_string})" |
564 | 571 | ||
565 | if worktime.time_pulled_forward >= timedelta(minutes = 15): | 572 | out_class = "running" if worktime.running_entry else "stopped" |
573 | difference = worktime.time_to_work - worktime.time_worked | ||
574 | if worktime.running_entry and -min(timedelta(milliseconds=0), difference) > sum(worktime.pull_forward.values(), start=timedelta(milliseconds=0)) or not worktime.running_entry and max(timedelta(milliseconds=0), difference) > worktime.time_per_day(worktime.now.date()) and worktime.now_is_workday: | ||
575 | out_class = "over" | ||
576 | tooltip = tooltip_timedelta(difference) | ||
577 | if worktime.time_pulled_forward >= min(pull_forward_cutoff, timedelta(seconds = 1)): | ||
566 | worktime_no_pulled_forward = deepcopy(worktime) | 578 | worktime_no_pulled_forward = deepcopy(worktime) |
567 | worktime_no_pulled_forward.time_to_work -= worktime_no_pulled_forward.time_pulled_forward | 579 | worktime_no_pulled_forward.time_to_work -= worktime_no_pulled_forward.time_pulled_forward |
568 | worktime_no_pulled_forward.time_pulled_forward = timedelta() | 580 | worktime_no_pulled_forward.time_pulled_forward = timedelta() |
@@ -570,11 +582,24 @@ def worktime(**args): | |||
570 | difference_string = format_worktime(worktime) | 582 | difference_string = format_worktime(worktime) |
571 | difference_string_no_pulled_forward = format_worktime(worktime_no_pulled_forward) | 583 | difference_string_no_pulled_forward = format_worktime(worktime_no_pulled_forward) |
572 | 584 | ||
573 | print(f"{difference_string_no_pulled_forward}…{difference_string}") | 585 | tooltip = tooltip_timedelta(worktime_no_pulled_forward.time_to_work - worktime_no_pulled_forward.time_worked) + "…" + tooltip |
586 | if worktime.time_pulled_forward >= pull_forward_cutoff: | ||
587 | out_text = f"{difference_string_no_pulled_forward}…{difference_string}" | ||
588 | else: | ||
589 | out_text = format_worktime(worktime) | ||
590 | else: | ||
591 | out_text = format_worktime(worktime) | ||
592 | |||
593 | if waybar: | ||
594 | json.dump({"text": out_text, "class": out_class, "tooltip": tooltip}, stdout) | ||
574 | else: | 595 | else: |
575 | print(format_worktime(worktime)) | 596 | print(out_text) |
597 | |||
598 | def pull_forward(**args): | ||
599 | worktime = Worktime(**args) | ||
600 | print(tooltip_timedelta(sum(worktime.pull_forward.values(), start=timedelta(milliseconds=0)))) | ||
576 | 601 | ||
577 | def time_worked(now, **args): | 602 | def time_worked(now, waybar, **args): |
578 | then = now.replace(hour = 0, minute = 0, second = 0, microsecond = 0) | 603 | then = now.replace(hour = 0, minute = 0, second = 0, microsecond = 0) |
579 | if now.time() == time(): | 604 | if now.time() == time(): |
580 | now = now + timedelta(days = 1) | 605 | now = now + timedelta(days = 1) |
@@ -584,6 +609,9 @@ def time_worked(now, **args): | |||
584 | 609 | ||
585 | worked = now.time_worked - then.time_worked | 610 | worked = now.time_worked - then.time_worked |
586 | 611 | ||
612 | out_text = None | ||
613 | out_class = "stopped" | ||
614 | tooltip = tooltip_timedelta(worked) | ||
587 | if args['do_round']: | 615 | if args['do_round']: |
588 | total_minutes_difference = 5 * ceil(worked / timedelta(minutes = 5)) | 616 | total_minutes_difference = 5 * ceil(worked / timedelta(minutes = 5)) |
589 | (hours_difference, minutes_difference) = divmod(abs(total_minutes_difference), 60) | 617 | (hours_difference, minutes_difference) = divmod(abs(total_minutes_difference), 60) |
@@ -602,15 +630,25 @@ def time_worked(now, **args): | |||
602 | difference = target_time - worked | 630 | difference = target_time - worked |
603 | clockout_difference = 5 * ceil(difference / timedelta(minutes = 5)) | 631 | clockout_difference = 5 * ceil(difference / timedelta(minutes = 5)) |
604 | clockout_time = now.now + difference | 632 | clockout_time = now.now + difference |
633 | exact_clockout_time = clockout_time | ||
605 | clockout_time += (5 - clockout_time.minute % 5) * timedelta(minutes = 1) | 634 | clockout_time += (5 - clockout_time.minute % 5) * timedelta(minutes = 1) |
606 | clockout_time = clockout_time.replace(second = 0, microsecond = 0) | 635 | clockout_time = clockout_time.replace(second = 0, microsecond = 0) |
607 | 636 | ||
608 | if now.running_entry and clockout_time and clockout_difference >= 0: | 637 | if now.running_entry and clockout_time and clockout_difference >= 0: |
609 | print(f"{difference_string}/{clockout_time:%H:%M}") | 638 | out_class = "running" |
639 | out_text = f"{difference_string}/{clockout_time:%H:%M}" | ||
640 | tooltip = f"{tooltip_timedelta(worked)}/{exact_clockout_time:%H:%M}" | ||
610 | else: | 641 | else: |
611 | print(difference_string) | 642 | if now.running_entry: |
643 | out_class = "over" | ||
644 | out_text = difference_string | ||
645 | else: | ||
646 | out_text = str(worked) | ||
647 | |||
648 | if waybar: | ||
649 | json.dump({"text": out_text, "class": out_class, "tooltip": tooltip}, stdout) | ||
612 | else: | 650 | else: |
613 | print(worked) | 651 | print(out_text) |
614 | 652 | ||
615 | def diff(now, **args): | 653 | def diff(now, **args): |
616 | now = now.replace(hour = 0, minute = 0, second = 0, microsecond = 0) | 654 | now = now.replace(hour = 0, minute = 0, second = 0, microsecond = 0) |
@@ -798,6 +836,38 @@ def classification(classification_name, table, table_format, **args): | |||
798 | def main(): | 836 | def main(): |
799 | def isotime(s): | 837 | def isotime(s): |
800 | return datetime.fromisoformat(s).replace(tzinfo=tzlocal()) | 838 | return datetime.fromisoformat(s).replace(tzinfo=tzlocal()) |
839 | def duration_minutes(s): | ||
840 | return timedelta(minutes = float(s)) | ||
841 | |||
842 | def set_default_subparser(self, name, args=None, positional_args=0): | ||
843 | """default subparser selection. Call after setup, just before parse_args() | ||
844 | name: is the name of the subparser to call by default | ||
845 | args: if set is the argument list handed to parse_args() | ||
846 | |||
847 | , tested with 2.7, 3.2, 3.3, 3.4 | ||
848 | it works with 2.6 assuming argparse is installed | ||
849 | """ | ||
850 | subparser_found = False | ||
851 | for arg in sys.argv[1:]: | ||
852 | if arg in ['-h', '--help']: # global help if no subparser | ||
853 | break | ||
854 | else: | ||
855 | for x in self._subparsers._actions: | ||
856 | if not isinstance(x, argparse._SubParsersAction): | ||
857 | continue | ||
858 | for sp_name in x._name_parser_map.keys(): | ||
859 | if sp_name in sys.argv[1:]: | ||
860 | subparser_found = True | ||
861 | if not subparser_found: | ||
862 | # insert default in last position before global positional | ||
863 | # arguments, this implies no global options are specified after | ||
864 | # first positional argument | ||
865 | if args is None: | ||
866 | sys.argv.insert(len(sys.argv) - positional_args, name) | ||
867 | else: | ||
868 | args.insert(len(args) - positional_args, name) | ||
869 | |||
870 | argparse.ArgumentParser.set_default_subparser = set_default_subparser | ||
801 | 871 | ||
802 | config = Worktime.config() | 872 | config = Worktime.config() |
803 | 873 | ||
@@ -807,9 +877,13 @@ def main(): | |||
807 | parser.add_argument('--no-running', dest = 'include_running', action = 'store_false') | 877 | parser.add_argument('--no-running', dest = 'include_running', action = 'store_false') |
808 | parser.add_argument('--no-force-day-to-work', dest = 'force_day_to_work', action = 'store_false') | 878 | parser.add_argument('--no-force-day-to-work', dest = 'force_day_to_work', action = 'store_false') |
809 | subparsers = parser.add_subparsers(help = 'Subcommands') | 879 | subparsers = parser.add_subparsers(help = 'Subcommands') |
810 | parser.set_defaults(cmd = worktime) | 880 | worktime_parser = subparsers.add_parser('time_worked', aliases = ['time', 'worked']) |
811 | time_worked_parser = subparsers.add_parser('time_worked', aliases = ['time', 'worked', 'today']) | 881 | worktime_parser.add_argument('--pull-forward-cutoff', dest = 'pull_forward_cutoff', metavar = 'MINUTES', type = duration_minutes, default = timedelta(minutes = 15)) |
882 | worktime_parser.add_argument('--waybar', action='store_true') | ||
883 | worktime_parser.set_defaults(cmd = worktime) | ||
884 | time_worked_parser = subparsers.add_parser('today') | ||
812 | time_worked_parser.add_argument('--no-round', dest = 'do_round', action = 'store_false') | 885 | time_worked_parser.add_argument('--no-round', dest = 'do_round', action = 'store_false') |
886 | time_worked_parser.add_argument('--waybar', action='store_true') | ||
813 | time_worked_parser.set_defaults(cmd = time_worked) | 887 | time_worked_parser.set_defaults(cmd = time_worked) |
814 | diff_parser = subparsers.add_parser('diff') | 888 | diff_parser = subparsers.add_parser('diff') |
815 | diff_parser.set_defaults(cmd = diff) | 889 | diff_parser.set_defaults(cmd = diff) |
@@ -827,6 +901,9 @@ def main(): | |||
827 | classification_parser.add_argument('--table', action = 'store_true') | 901 | classification_parser.add_argument('--table', action = 'store_true') |
828 | classification_parser.add_argument('--table-format', dest='table_format', type=str, default='fancy_grid') | 902 | classification_parser.add_argument('--table-format', dest='table_format', type=str, default='fancy_grid') |
829 | classification_parser.set_defaults(cmd = partial(classification, classification_name=classification_name)) | 903 | classification_parser.set_defaults(cmd = partial(classification, classification_name=classification_name)) |
904 | pull_forward_parser = subparsers.add_parser('pull-forward') | ||
905 | pull_forward_parser.set_defaults(cmd = pull_forward) | ||
906 | parser.set_default_subparser('time_worked') | ||
830 | args = parser.parse_args() | 907 | args = parser.parse_args() |
831 | 908 | ||
832 | args.cmd(**vars(args)) | 909 | args.cmd(**vars(args)) |