mirror of
https://github.com/dguglielmi/sunny-overlay.git
synced 2025-12-06 16:02:39 +01:00
68 lines
2.5 KiB
Diff
68 lines
2.5 KiB
Diff
From 1f1b43b40ae4ed5699f8fbf420eb2d4d32fa2fbc Mon Sep 17 00:00:00 2001
|
|
From: Peter Hutterer <peter.hutterer@who-t.net>
|
|
Date: Mon, 16 Oct 2017 09:58:07 +1000
|
|
Subject: [PATCH 25/30] ResolutionsRow: snap to nearest allowed resolution
|
|
value
|
|
|
|
libratbag now exports a list of permitted resolutions rather than a min/max
|
|
value (and a guesswork step increment on piper's side). Use that and snap the
|
|
resolution slider to the nearest value in that list.
|
|
|
|
See https://github.com/libratbag/libratbag/pull/393
|
|
|
|
Related to #186
|
|
---
|
|
piper/resolutionrow.py | 29 +++++++++++++++++++++++++----
|
|
1 file changed, 25 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/piper/resolutionrow.py b/piper/resolutionrow.py
|
|
index 108af45..884fad7 100644
|
|
--- a/piper/resolutionrow.py
|
|
+++ b/piper/resolutionrow.py
|
|
@@ -62,6 +62,7 @@ class ResolutionRow(Gtk.ListBoxRow):
|
|
xres, __ = resolution.resolution
|
|
minres = resolution.resolutions[0]
|
|
maxres = resolution.resolutions[-1]
|
|
+ self.resolutions = resolution.resolutions
|
|
self.dpi_label.set_text("{} DPI".format(xres))
|
|
self.active_label.set_visible(resolution.is_active)
|
|
|
|
@@ -75,10 +76,30 @@ class ResolutionRow(Gtk.ListBoxRow):
|
|
|
|
@GtkTemplate.Callback
|
|
def _on_change_value(self, scale, scroll, value):
|
|
- # Round the value resulting from a scroll event to the nearest multiple
|
|
- # of 50. This is to work around the Gtk.Scale not snapping to its
|
|
- # Gtk.Adjustment's step_increment.
|
|
- scale.set_value(int(value - (value % 50)))
|
|
+
|
|
+ # Cursor-controlled slider may get out of the GtkAdjustment's range
|
|
+ value = min(max(self.resolutions[0], value), self.resolutions[-1])
|
|
+
|
|
+ # Find the nearest permitted value to our Gtk.Scale value
|
|
+ lo = max([r for r in self.resolutions if r <= value])
|
|
+ hi = min([r for r in self.resolutions if r >= value])
|
|
+
|
|
+ if value - lo < hi - value:
|
|
+ value = lo
|
|
+ else:
|
|
+ value = hi
|
|
+
|
|
+ scale.set_value(value)
|
|
+
|
|
+ # libratbag provides a fake-exponential range with the deltas
|
|
+ # increasing as the resolution goes up. Make sure we set our
|
|
+ # steps to the next available value.
|
|
+ idx = self.resolutions.index(value)
|
|
+ if idx < len(self.resolutions) - 1:
|
|
+ delta = self.resolutions[idx + 1] - self.resolutions[idx]
|
|
+ self.scale.props.adjustment.set_step_increment(delta)
|
|
+ self.scale.props.adjustment.set_page_increment(delta)
|
|
+
|
|
return True
|
|
|
|
@GtkTemplate.Callback
|
|
--
|
|
2.16.1
|
|
|