forked from drath/libratbag
tools: ratbagctl: add support for separate X/Y resolutions
Big commit because of the test suite changes. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
committed by
Peter Hutterer
parent
ced958f135
commit
6faa59c70d
@@ -246,9 +246,9 @@ static const struct ratbag_test_device ratbagd_test_device_descr = {
|
||||
.key = 7 },
|
||||
},
|
||||
.resolutions = {
|
||||
{ .xres = 1100, .yres = 1200, .hz = 2000 },
|
||||
{ .xres = 1200, .yres = 1300, .hz = 2000, .dflt = true },
|
||||
{ .xres = 1300, .yres = 1400, .hz = 2000, .active = true },
|
||||
{ .xres = 1100, .yres = 1200, .hz = 2000, .caps = RATBAG_RESOLUTION_CAP_SEPARATE_XY_RESOLUTION },
|
||||
{ .xres = 1200, .yres = 1300, .hz = 2000, .dflt = true, .caps = RATBAG_RESOLUTION_CAP_SEPARATE_XY_RESOLUTION },
|
||||
{ .xres = 1300, .yres = 1400, .hz = 2000, .active = true, .caps = RATBAG_RESOLUTION_CAP_SEPARATE_XY_RESOLUTION },
|
||||
},
|
||||
.active = false,
|
||||
.dflt = true,
|
||||
@@ -265,9 +265,9 @@ static const struct ratbag_test_device ratbagd_test_device_descr = {
|
||||
.button = 3 },
|
||||
},
|
||||
.resolutions = {
|
||||
{ .xres = 2100, .yres = 2200, .hz = 3000, .active = true },
|
||||
{ .xres = 2200, .yres = 2300, .hz = 3000, .dflt = true },
|
||||
{ .xres = 2300, .yres = 2400, .hz = 3000 },
|
||||
{ .xres = 2100, .yres = 2200, .hz = 3000, .active = true, .caps = RATBAG_RESOLUTION_CAP_SEPARATE_XY_RESOLUTION },
|
||||
{ .xres = 2200, .yres = 2300, .hz = 3000, .dflt = true, .caps = RATBAG_RESOLUTION_CAP_SEPARATE_XY_RESOLUTION },
|
||||
{ .xres = 2300, .yres = 2400, .hz = 3000, .caps = RATBAG_RESOLUTION_CAP_SEPARATE_XY_RESOLUTION },
|
||||
},
|
||||
.leds = {
|
||||
{
|
||||
|
||||
@@ -52,7 +52,7 @@ test_read_profile(struct ratbag_profile *profile, unsigned int index)
|
||||
res->is_default = r->dflt;
|
||||
if (r->dflt)
|
||||
default_set = true;
|
||||
res->capabilities = r->caps;
|
||||
ratbag_resolution_set_cap(res, r->caps);
|
||||
res->hz = r->hz;
|
||||
assert(res);
|
||||
}
|
||||
|
||||
@@ -307,10 +307,7 @@ def func_dpi_get(r, args):
|
||||
|
||||
def func_dpi_set(r, args):
|
||||
r, p, d = find_resolution(r, args)
|
||||
if RatbagdResolution.CAP_SEPARATE_XY_RESOLUTION in r.capabilities:
|
||||
print(args)
|
||||
else:
|
||||
r.resolution = (args.dpi_n, args.dpi_n)
|
||||
r.resolution = (args.dpi_n[0], args.dpi_n[1])
|
||||
d.commit()
|
||||
|
||||
|
||||
@@ -455,6 +452,24 @@ def u8(string):
|
||||
raise argparse.ArgumentTypeError(msg)
|
||||
return int_value
|
||||
|
||||
def dpi(string):
|
||||
try:
|
||||
int_value = int(string)
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
return (int_value, int_value)
|
||||
if string.endswith("dpi"):
|
||||
string = string[:-3]
|
||||
x, y = string.split("x")
|
||||
try:
|
||||
int_x = int(x)
|
||||
int_y = int(y)
|
||||
except ValueError:
|
||||
raise argparse.ArgumentTypeError("%r is not a valid dpi" % string)
|
||||
else:
|
||||
return (int_x, int_y)
|
||||
|
||||
# note: 'eventX' is assumed at the end of each command
|
||||
parser_def = [
|
||||
{
|
||||
@@ -631,7 +646,7 @@ parser_def = [
|
||||
name: 'dpi_n',
|
||||
metavar: 'N',
|
||||
help_str: 'The resolution to set as current',
|
||||
arg_type: int,
|
||||
arg_type: dpi,
|
||||
},
|
||||
],
|
||||
func: func_dpi_set,
|
||||
|
||||
@@ -226,14 +226,14 @@ class TestRatbgagCtlResolution(TestRatbagCtl):
|
||||
|
||||
def test_resolution_n_get(self):
|
||||
r = self.launch_good_test("Resolution 1 get test_device")
|
||||
self.assertEqual(r, "1: 1200dpi @ 2000Hz (default)")
|
||||
self.assertEqual(r, "1: 1200x1300dpi @ 2000Hz (default)")
|
||||
self.launch_fail_test("Resolution 10 get test_device")
|
||||
self.launch_fail_test("Resolution 1 get test_device X")
|
||||
self.launch_fail_test("Resolution 1 get X")
|
||||
|
||||
def test_profile_resolution(self):
|
||||
r = self.launch_good_test("Profile 2 Resolution 2 get test_device")
|
||||
self.assertEqual(r, "2: 2300dpi @ 3000Hz")
|
||||
self.assertEqual(r, "2: 2300x2400dpi @ 3000Hz")
|
||||
|
||||
|
||||
class TestRatbgagCtlDPI(TestRatbagCtl):
|
||||
@@ -246,12 +246,16 @@ class TestRatbgagCtlDPI(TestRatbagCtl):
|
||||
command = "DPI get"
|
||||
r = self.launch_good_test(command + " test_device")
|
||||
self.assertEqual(int(r), 200)
|
||||
self.setProfile(1)
|
||||
r = self.launch_good_test(command + " test_device")
|
||||
self.assertEqual(r, "1300x1400dpi")
|
||||
self.launch_fail_test(command)
|
||||
self.launch_fail_test(command + " 1 test_device")
|
||||
self.launch_fail_test(command + " test_device X")
|
||||
|
||||
def test_dpi_set(self):
|
||||
command = "DPI set"
|
||||
self.setProfile(0)
|
||||
r = self.launch_good_test("DPI get test_device")
|
||||
res = int(r) + 50
|
||||
r = self.launch_good_test(command + " {} test_device".format(res))
|
||||
@@ -262,11 +266,31 @@ class TestRatbgagCtlDPI(TestRatbagCtl):
|
||||
self.launch_fail_test(command + " X test_device")
|
||||
self.launch_fail_test(command + " 100 test_device X")
|
||||
|
||||
def test_dpi_set_xy(self):
|
||||
command = "DPI set"
|
||||
self.setProfile(2)
|
||||
r = self.launch_good_test("DPI get test_device")
|
||||
self.assertEqual(r, "2100x2200dpi")
|
||||
self.launch_good_test(command + " 1350x1450 test_device")
|
||||
r = self.launch_good_test("DPI get test_device")
|
||||
self.assertEqual(r, "1350x1450dpi")
|
||||
self.launch_good_test(command + " 2350x2450dpi test_device")
|
||||
r = self.launch_good_test("DPI get test_device")
|
||||
self.assertEqual(r, "2350x2450dpi")
|
||||
self.launch_good_test(command + " 2350 test_device")
|
||||
r = self.launch_good_test("DPI get test_device")
|
||||
self.assertEqual(r, "2350x2350dpi")
|
||||
self.launch_fail_test(command + " 2350dpi test_device")
|
||||
self.launch_fail_test(command)
|
||||
self.launch_fail_test(command + " X test_device")
|
||||
self.launch_fail_test(command + " 100 test_device X")
|
||||
|
||||
def test_prefix_dpi(self):
|
||||
self.setProfile(0)
|
||||
r = self.launch_good_test("Profile 1 DPI get test_device")
|
||||
self.assertEqual(int(r), 1300)
|
||||
self.assertEqual(r, "1300x1400dpi")
|
||||
r = self.launch_good_test("Profile 1 Resolution 1 DPI get test_device")
|
||||
self.assertEqual(int(r), 1200)
|
||||
self.assertEqual(r, "1200x1300dpi")
|
||||
r = self.launch_good_test("Resolution 2 DPI get test_device")
|
||||
self.assertEqual(int(r), 300)
|
||||
self.launch_fail_test("Profile 1 Profile 1 DPI get test_device")
|
||||
|
||||
Reference in New Issue
Block a user