diff options
Diffstat (limited to 'overlays')
-rw-r--r-- | overlays/swayosd/default.nix (renamed from overlays/swayosd.nix) | 3 | ||||
-rw-r--r-- | overlays/swayosd/exponential.patch | 57 | ||||
-rwxr-xr-x | overlays/worktime/worktime/__main__.py | 30 |
3 files changed, 79 insertions, 11 deletions
diff --git a/overlays/swayosd.nix b/overlays/swayosd/default.nix index 61c865e7..28c8f1b9 100644 --- a/overlays/swayosd.nix +++ b/overlays/swayosd/default.nix | |||
@@ -23,5 +23,8 @@ | |||
23 | udev | 23 | udev |
24 | sassc | 24 | sassc |
25 | ]; | 25 | ]; |
26 | patches = (oldAttrs.patches or []) ++ [ | ||
27 | ./exponential.patch | ||
28 | ]; | ||
26 | }); | 29 | }); |
27 | } | 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 9335afdc..ba6c5ff6 100755 --- a/overlays/worktime/worktime/__main__.py +++ b/overlays/worktime/worktime/__main__.py | |||
@@ -224,6 +224,7 @@ class Worktime(object): | |||
224 | leave_budget = dict() | 224 | leave_budget = dict() |
225 | time_per_day = None | 225 | time_per_day = None |
226 | workdays = None | 226 | workdays = None |
227 | pull_forward = dict() | ||
227 | 228 | ||
228 | @staticmethod | 229 | @staticmethod |
229 | @cache | 230 | @cache |
@@ -391,8 +392,6 @@ class Worktime(object): | |||
391 | if e.errno != 2: | 392 | if e.errno != 2: |
392 | raise e | 393 | raise e |
393 | 394 | ||
394 | pull_forward = dict() | ||
395 | |||
396 | start_day = self.start_date.date() | 395 | start_day = self.start_date.date() |
397 | end_day = self.end_date.date() | 396 | end_day = self.end_date.date() |
398 | 397 | ||
@@ -419,15 +418,15 @@ class Worktime(object): | |||
419 | 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 |
420 | else: | 419 | else: |
421 | if d >= self.end_date.date(): | 420 | if d >= self.end_date.date(): |
422 | 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())) |
423 | except IOError as e: | 422 | except IOError as e: |
424 | if e.errno != 2: | 423 | if e.errno != 2: |
425 | raise e | 424 | raise e |
426 | 425 | ||
427 | self.days_to_work = dict() | 426 | self.days_to_work = dict() |
428 | 427 | ||
429 | if pull_forward: | 428 | if self.pull_forward: |
430 | end_day = max(end_day, max(list(pull_forward))) | 429 | end_day = max(end_day, max(list(self.pull_forward))) |
431 | 430 | ||
432 | 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)]: |
433 | if day.isoweekday() in self.workdays: | 432 | if day.isoweekday() in self.workdays: |
@@ -471,17 +470,17 @@ class Worktime(object): | |||
471 | self.extra_days_to_work[self.now.date()] = timedelta() | 470 | self.extra_days_to_work[self.now.date()] = timedelta() |
472 | 471 | ||
473 | 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()) |
474 | 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()]: |
475 | 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())]) |
476 | 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())]) |
477 | days_forward = days_forward.union(extra_days_forward) | 476 | days_forward = days_forward.union(extra_days_forward) |
478 | 477 | ||
479 | extra_day_time_left = timedelta() | 478 | extra_day_time_left = timedelta() |
480 | for extra_day in extra_days_forward: | 479 | for extra_day in extra_days_forward: |
481 | 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]) |
482 | extra_day_time_left += day_time | 481 | extra_day_time_left += day_time |
483 | extra_day_time = min(extra_day_time_left, pull_forward[day]) | 482 | extra_day_time = min(extra_day_time_left, self.pull_forward[day]) |
484 | time_forward = pull_forward[day] - extra_day_time | 483 | time_forward = self.pull_forward[day] - extra_day_time |
485 | if extra_day_time_left > timedelta(): | 484 | if extra_day_time_left > timedelta(): |
486 | for extra_day in extra_days_forward: | 485 | for extra_day in extra_days_forward: |
487 | 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]) |
@@ -571,7 +570,10 @@ def worktime(pull_forward_cutoff, waybar, **args): | |||
571 | return f"({difference_string})" | 570 | return f"({difference_string})" |
572 | 571 | ||
573 | out_class = "running" if worktime.running_entry else "stopped" | 572 | out_class = "running" if worktime.running_entry else "stopped" |
574 | tooltip = tooltip_timedelta(worktime.time_to_work - worktime.time_worked) | 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) | ||
575 | if worktime.time_pulled_forward >= min(pull_forward_cutoff, timedelta(seconds = 1)): | 577 | if worktime.time_pulled_forward >= min(pull_forward_cutoff, timedelta(seconds = 1)): |
576 | worktime_no_pulled_forward = deepcopy(worktime) | 578 | worktime_no_pulled_forward = deepcopy(worktime) |
577 | 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 |
@@ -593,6 +595,10 @@ def worktime(pull_forward_cutoff, waybar, **args): | |||
593 | else: | 595 | else: |
594 | print(out_text) | 596 | print(out_text) |
595 | 597 | ||
598 | def pull_forward(**args): | ||
599 | worktime = Worktime(**args) | ||
600 | print(tooltip_timedelta(sum(worktime.pull_forward.values(), start=timedelta(milliseconds=0)))) | ||
601 | |||
596 | def time_worked(now, waybar, **args): | 602 | def time_worked(now, waybar, **args): |
597 | then = now.replace(hour = 0, minute = 0, second = 0, microsecond = 0) | 603 | then = now.replace(hour = 0, minute = 0, second = 0, microsecond = 0) |
598 | if now.time() == time(): | 604 | if now.time() == time(): |
@@ -895,6 +901,8 @@ def main(): | |||
895 | classification_parser.add_argument('--table', action = 'store_true') | 901 | classification_parser.add_argument('--table', action = 'store_true') |
896 | 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') |
897 | 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) | ||
898 | parser.set_default_subparser('time_worked') | 906 | parser.set_default_subparser('time_worked') |
899 | args = parser.parse_args() | 907 | args = parser.parse_args() |
900 | 908 | ||