diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2014-11-19 02:41:36 +0100 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2014-11-19 03:19:13 +0100 |
commit | 2d777dd67e9be3c5bfd36660ade94710de0f4a0d (patch) | |
tree | 046b13365164eb2ac437804a6eca90131183380b /demo.c | |
parent | 5a80bceec9c3fcc304d8dde1c10f16a9adde8598 (diff) | |
download | termo-2d777dd67e9be3c5bfd36660ade94710de0f4a0d.tar.gz termo-2d777dd67e9be3c5bfd36660ade94710de0f4a0d.tar.xz termo-2d777dd67e9be3c5bfd36660ade94710de0f4a0d.zip |
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.
Diffstat (limited to 'demo.c')
-rw-r--r-- | demo.c | 39 |
1 files changed, 18 insertions, 21 deletions
@@ -5,6 +5,7 @@ #include <unistd.h> #include <errno.h> #include <locale.h> +#include <strings.h> #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); } |