From 2d777dd67e9be3c5bfd36660ade94710de0f4a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Wed, 19 Nov 2014 02:41:36 +0100 Subject: Rewrite the mouse API I wasn't aware of the fact that 1000, 1002 and 1003 are mutually exclusive and turn each other off. Also now it's not needed to set the protocol, it gets set by default. --- demo.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'demo.c') diff --git a/demo.c b/demo.c index d74892c..bc416c0 100644 --- a/demo.c +++ b/demo.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "termo.h" @@ -14,31 +15,33 @@ main(int argc, char *argv[]) TERMO_CHECK_VERSION; setlocale (LC_CTYPE, ""); - int mouse = 0; - int mouse_proto = 0; + termo_mouse_tracking_t mouse = TERMO_MOUSE_TRACKING_OFF; termo_format_t format = TERMO_FORMAT_VIM; char buffer[50]; termo_t *tk; int opt; - while ((opt = getopt (argc, argv, "m::p:")) != -1) + while ((opt = getopt (argc, argv, "m::")) != -1) { switch (opt) { case 'm': - if (optarg) - mouse = atoi (optarg); - else - mouse = 1000; - break; - - case 'p': - mouse_proto = atoi (optarg); + if (!optarg) + mouse = TERMO_MOUSE_TRACKING_DRAG; + else if (!strcasecmp (optarg, "off")) + mouse = TERMO_MOUSE_TRACKING_OFF; + else if (!strcasecmp (optarg, "click")) + mouse = TERMO_MOUSE_TRACKING_CLICK; + else if (!strcasecmp (optarg, "drag")) + mouse = TERMO_MOUSE_TRACKING_DRAG; + else if (!strcasecmp (optarg, "move")) + mouse = TERMO_MOUSE_TRACKING_MOVE; break; default: - fprintf (stderr, "Usage: %s [-m]\n", argv[0]); + fprintf (stderr, + "Usage: %s [ -m [ off | click | drag | move ]]\n", argv[0]); return 1; } } @@ -59,12 +62,9 @@ main(int argc, char *argv[]) termo_result_t ret; termo_key_t key; - if (mouse) - { - printf ("\033[?%dhMouse mode active\n", mouse); - if (mouse_proto) - printf ("\033[?%dh", mouse_proto); - } + termo_set_mouse_tracking_mode (tk, mouse); + if (mouse != TERMO_MOUSE_TRACKING_OFF) + printf ("Mouse mode active\n"); while ((ret = termo_waitkey (tk, &key)) != TERMO_RES_EOF) { @@ -130,8 +130,5 @@ main(int argc, char *argv[]) } } - if (mouse) - printf ("\033[?%dlMouse mode deactivated\n", mouse); - termo_destroy (tk); } -- cgit v1.2.3