From 6faa59c70d82e6aaf27ff6863c3f92339144db3d Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Thu, 20 Jul 2017 16:45:25 +0200 Subject: [PATCH] tools: ratbagctl: add support for separate X/Y resolutions Big commit because of the test suite changes. Signed-off-by: Benjamin Tissoires --- ratbagd/ratbagd.c | 12 ++++++------ src/driver-test.c | 2 +- tools/ratbagctl.in | 25 ++++++++++++++++++++----- tools/ratbagctl.test.in | 32 ++++++++++++++++++++++++++++---- 4 files changed, 55 insertions(+), 16 deletions(-) diff --git a/ratbagd/ratbagd.c b/ratbagd/ratbagd.c index a4058513..25b2ce40 100644 --- a/ratbagd/ratbagd.c +++ b/ratbagd/ratbagd.c @@ -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 = { { diff --git a/src/driver-test.c b/src/driver-test.c index 90e2faee..fe7ccbd6 100644 --- a/src/driver-test.c +++ b/src/driver-test.c @@ -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); } diff --git a/tools/ratbagctl.in b/tools/ratbagctl.in index d0277e94..a784de6d 100755 --- a/tools/ratbagctl.in +++ b/tools/ratbagctl.in @@ -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, diff --git a/tools/ratbagctl.test.in b/tools/ratbagctl.test.in index 112069fc..c9fef326 100755 --- a/tools/ratbagctl.test.in +++ b/tools/ratbagctl.test.in @@ -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")