From bdd76df8f2fb662909dab97fed8c0e90b96bbdbe Mon Sep 17 00:00:00 2001 From: Mark Paronyan Date: Fri, 2 Oct 2026 10:03:53 +0000 Subject: [PATCH] fix: remove mouse capture so the terminal keeps the mouse --- README.md | 10 ------ config.def.h | 45 ------------------------ dvtm.1 | 34 ------------------ dvtm.c | 98 ++-------------------------------------------------- vt.c | 43 ----------------------- vt.h | 5 --- 6 files changed, 2 insertions(+), 233 deletions(-) diff --git a/README.md b/README.md index 0656923..fe95bcd 100644 --- a/README.md +++ b/README.md @@ -174,16 +174,6 @@ Detach using `CTRL-\` and later reattach with $ abduco -a dvtm-session -### Copy / Paste does not work under X - -If you have mouse support enabled, which is the case with the -default settings, you need to hold down shift while selecting -and inserting text. In case you don't like this behaviour either -run dvtm with the `-M` command line argument, disable it at run -time with `MOD+M` or modify `config.def.h` to disable it completely -at compile time. You will however no longer be able to perform -other mouse actions like selecting windows etc. - ### How to change the key bindings? The configuration of dvtm is done by creating a custom `config.h` diff --git a/config.def.h b/config.def.h index 513c734..143c902 100644 --- a/config.def.h +++ b/config.def.h @@ -99,7 +99,6 @@ static KeyBinding bindings[] = { { { MOD, '.', }, { toggleminimize, { NULL } } }, { { MOD, 's', }, { togglebar, { NULL } } }, { { MOD, 'S', }, { togglebarpos, { NULL } } }, - { { MOD, 'M', }, { togglemouse, { NULL } } }, { { MOD, '\n', }, { zoom , { NULL } } }, { { MOD, '\r', }, { zoom , { NULL } } }, { { MOD, '1', }, { focusn, { "1" } } }, @@ -146,50 +145,6 @@ static const ColorRule colorrules[] = { { "", A_NORMAL, &colors[DEFAULT] }, /* default */ }; -/* possible values for the mouse buttons are listed below: - * - * BUTTON1_PRESSED mouse button 1 down - * BUTTON1_RELEASED mouse button 1 up - * BUTTON1_CLICKED mouse button 1 clicked - * BUTTON1_DOUBLE_CLICKED mouse button 1 double clicked - * BUTTON1_TRIPLE_CLICKED mouse button 1 triple clicked - * BUTTON2_PRESSED mouse button 2 down - * BUTTON2_RELEASED mouse button 2 up - * BUTTON2_CLICKED mouse button 2 clicked - * BUTTON2_DOUBLE_CLICKED mouse button 2 double clicked - * BUTTON2_TRIPLE_CLICKED mouse button 2 triple clicked - * BUTTON3_PRESSED mouse button 3 down - * BUTTON3_RELEASED mouse button 3 up - * BUTTON3_CLICKED mouse button 3 clicked - * BUTTON3_DOUBLE_CLICKED mouse button 3 double clicked - * BUTTON3_TRIPLE_CLICKED mouse button 3 triple clicked - * BUTTON4_PRESSED mouse button 4 down - * BUTTON4_RELEASED mouse button 4 up - * BUTTON4_CLICKED mouse button 4 clicked - * BUTTON4_DOUBLE_CLICKED mouse button 4 double clicked - * BUTTON4_TRIPLE_CLICKED mouse button 4 triple clicked - * BUTTON_SHIFT shift was down during button state change - * BUTTON_CTRL control was down during button state change - * BUTTON_ALT alt was down during button state change - * ALL_MOUSE_EVENTS report all button state changes - * REPORT_MOUSE_POSITION report mouse movement - */ - -#ifdef NCURSES_MOUSE_VERSION -# define CONFIG_MOUSE /* compile in mouse support if we build against ncurses */ -#endif - -#define ENABLE_MOUSE true /* whether to enable mouse events by default */ - -#ifdef CONFIG_MOUSE -static Button buttons[] = { - { BUTTON1_CLICKED, { mouse_focus, { NULL } } }, - { BUTTON1_DOUBLE_CLICKED, { mouse_fullscreen, { "[ ]" } } }, - { BUTTON2_CLICKED, { mouse_zoom, { NULL } } }, - { BUTTON3_CLICKED, { mouse_minimize, { NULL } } }, -}; -#endif /* CONFIG_MOUSE */ - static Cmd commands[] = { /* create [cmd]: create a new window, run `cmd` in the shell if specified */ { "create", { create, { NULL } } }, diff --git a/dvtm.1 b/dvtm.1 index 019dcee..c773517 100644 --- a/dvtm.1 +++ b/dvtm.1 @@ -32,10 +32,6 @@ console based applications. .It Fl v Print version information to standard output and exit. . -.It Fl M -Toggle default mouse grabbing upon startup. Use this to allow normal mouse operation -under X. -. .It Fl m Ar modifier Set command modifier at runtime. . @@ -177,9 +173,6 @@ Redraw whole screen. Toggle keyboard multiplexing mode, if activated keypresses are sent to all visible windows. . -.It Ic Mod-M -Toggle dvtm mouse grabbing. -. .It Ic Mod-e Enter copy mode (see section below for further information). . @@ -219,33 +212,6 @@ Quit dvtm. .El . . -.Ss Mouse commands -. -By default dvtm captures mouse events to provide the actions listed below. -Unfortunately this interferes with the standard X copy and paste mechanism. -To work around this you need to hold down -.Ic Shift -while selecting or pasting text. -Alternatively you can disable mouse support at compile time, start dvtm with the -.Fl M -flag or toggle mouse support during runtime with -.Ic Mod-M . -. -.Bl -tag -width 8 -.It Ic Button1 click -Focus window. -. -.It Ic Button1 double click -Focus window and toggle maximization. -. -.It Ic Button2 click -Zoom/cycle current window to/from master area. -. -.It Ic Button3 click -Toggle minimization of current window. -.El -. -. .Ss Copy mode . Copy mode gives easy access to past output by piping it to diff --git a/dvtm.c b/dvtm.c index 85a2705..e4e5171 100644 --- a/dvtm.c +++ b/dvtm.c @@ -131,11 +131,6 @@ typedef struct { Action action; } KeyBinding; -typedef struct { - mmask_t mask; - Action action; -} Button; - typedef struct { const char *name; Action action; @@ -212,7 +207,6 @@ static void tagid(const char *args[]); static void togglebar(const char *args[]); static void togglebarpos(const char *args[]); static void toggleminimize(const char *args[]); -static void togglemouse(const char *args[]); static void togglerunall(const char *args[]); static void toggletag(const char *args[]); static void toggleview(const char *args[]); @@ -220,12 +214,6 @@ static void viewprevtag(const char *args[]); static void view(const char *args[]); static void zoom(const char *args[]); -/* commands for use by mouse bindings */ -static void mouse_focus(const char *args[]); -static void mouse_fullscreen(const char *args[]); -static void mouse_minimize(const char *args[]); -static void mouse_zoom(const char *args[]); - /* functions and variables available to layouts via config.h */ static Client* nextvisible(Client *c); static void focus(Client *c); @@ -244,10 +232,8 @@ Screen screen = { .mfact = MFACT, .nmaster = NMASTER, .history = SCROLL_HISTORY static Client *stack = NULL; static Client *sel = NULL; static Client *lastsel = NULL; -static Client *msel = NULL; static unsigned int seltags; static unsigned int tagset[2] = { 1, 1 }; -static bool mouse_events_enabled = ENABLE_MOUSE; static Layout *layout = layouts; static StatusBar bar = { .fd = -1, .lastpos = BAR_POS, .pos = BAR_POS, .autohide = BAR_AUTOHIDE, .h = 1 }; static CmdFifo cmdfifo = { .fd = -1 }; @@ -707,7 +693,6 @@ get_client_by_coord(unsigned int x, unsigned int y) { return sel; for (Client *c = nextvisible(clients); c; c = nextvisible(c->next)) { if (x >= c->x && x < c->x + c->w && y >= c->y && y < c->y + c->h) { - debug("mouse event, x: %d y: %d client: %d\n", x, y, c->order); return c; } } @@ -950,20 +935,6 @@ keypress(int code) { } } -static void -mouse_setup(void) { -#ifdef CONFIG_MOUSE - mmask_t mask = 0; - - if (mouse_events_enabled) { - mask = BUTTON1_CLICKED | BUTTON2_CLICKED; - for (unsigned int i = 0; i < LENGTH(buttons); i++) - mask |= buttons[i].mask; - } - mousemask(mask, NULL); -#endif /* CONFIG_MOUSE */ -} - static bool checkshell(const char *shell) { if (shell == NULL || *shell == '\0' || *shell != '/') @@ -1073,7 +1044,6 @@ setup(void) { noecho(); nonl(); keypad(stdscr, TRUE); - mouse_setup(); raw(); vt_init(); if (LENGTH(keytable)) @@ -1615,12 +1585,6 @@ toggleminimize(const char *args[]) { arrange(); } -static void -togglemouse(const char *args[]) { - mouse_events_enabled = !mouse_events_enabled; - mouse_setup(); -} - static void togglerunall(const char *args[]) { runinall = !runinall; @@ -1647,32 +1611,6 @@ zoom(const char *args[]) { arrange(); } -/* commands for use by mouse bindings */ -static void -mouse_focus(const char *args[]) { - focus(msel); - if (msel->minimized) - toggleminimize(NULL); -} - -static void -mouse_fullscreen(const char *args[]) { - mouse_focus(NULL); - setlayout(isarrange(fullscreen) ? NULL : args); -} - -static void -mouse_minimize(const char *args[]) { - focus(msel); - toggleminimize(NULL); -} - -static void -mouse_zoom(const char *args[]) { - focus(msel); - zoom(NULL); -} - static Cmd * get_cmd_by_name(const char *name) { for (unsigned int i = 0; i < LENGTH(commands); i++) { @@ -1813,31 +1751,6 @@ handle_cmdfifo(void) { len -= end; } -static void -handle_mouse(void) { -#ifdef CONFIG_MOUSE - MEVENT event; - unsigned int i; - if (getmouse(&event) != OK) - return; - msel = get_client_by_coord(event.x, event.y); - - if (!msel) - return; - - debug("mouse x:%d y:%d cx:%d cy:%d mask:%d\n", event.x, event.y, event.x - msel->x, event.y - msel->y, event.bstate); - - vt_mouse(msel->term, event.x - msel->x, event.y - msel->y, event.bstate); - - for (i = 0; i < LENGTH(buttons); i++) { - if (event.bstate & buttons[i].mask) - buttons[i].action.cmd(buttons[i].action.args); - } - - msel = NULL; -#endif /* CONFIG_MOUSE */ -} - static void handle_statusbar(void) { char *p; @@ -1942,7 +1855,6 @@ help(void) { " -v print version and exit\n" " -h print this help and exit\n" " -m mod command prefix key, e.g. ^b (default ^g)\n" - " -M toggle mouse support\n" " -d delay ESC delay in ms, 50-1000 (default 100)\n" " -h lines scrollback history size in lines\n" " -t title terminal title\n" @@ -1987,15 +1899,12 @@ parse_args(int argc, char *argv[]) { if (!strcmp(argv[arg], "--help") || (argv[arg][1] == 'h' && (arg + 1) >= argc)) help(); - if (argv[arg][1] != 'v' && argv[arg][1] != 'M' && (arg + 1) >= argc) + if (argv[arg][1] != 'v' && (arg + 1) >= argc) usage(); switch (argv[arg][1]) { case 'v': puts("dvtm-"VERSION" © 2007-2016 Marc André Tanner"); exit(EXIT_SUCCESS); - case 'M': - mouse_events_enabled = !mouse_events_enabled; - break; case 'm': { char *mod = argv[++arg]; if (mod[0] == '^' && mod[1]) @@ -2111,10 +2020,7 @@ main(int argc, char *argv[]) { if (code >= 0) { keys[key_index++] = code; KeyBinding *binding = NULL; - if (code == KEY_MOUSE) { - key_index = 0; - handle_mouse(); - } else if ((binding = keybinding(keys, key_index))) { + if ((binding = keybinding(keys, key_index))) { unsigned int key_length = MAX_KEYS; while (key_length > 1 && !binding->keys[key_length-1]) key_length--; diff --git a/vt.c b/vt.c index 9bd3a4d..556e407 100644 --- a/vt.c +++ b/vt.c @@ -184,7 +184,6 @@ struct Vt { unsigned curskeymode:1; unsigned bell:1; unsigned relposmode:1; - unsigned mousetrack:1; unsigned graphmode:1; unsigned savgraphmode:1; bool charsets[2]; @@ -1002,9 +1001,6 @@ static void interpret_csi_priv_mode(Vt *t, int param[], int pcount, bool set) else cursor_restore(t); break; - case 1000: /* enable/disable normal mouse tracking */ - t->mousetrack = set; - break; } } } @@ -1768,45 +1764,6 @@ void vt_keypress(Vt *t, int keycode) } } -void vt_mouse(Vt *t, int x, int y, mmask_t mask) -{ -#ifdef NCURSES_MOUSE_VERSION - char seq[6] = { '\e', '[', 'M' }, state = 0, button = 0; - - if (!t->mousetrack) - return; - - if (mask & (BUTTON1_PRESSED | BUTTON1_CLICKED)) - button = 0; - else if (mask & (BUTTON2_PRESSED | BUTTON2_CLICKED)) - button = 1; - else if (mask & (BUTTON3_PRESSED | BUTTON3_CLICKED)) - button = 2; - else if (mask & (BUTTON1_RELEASED | BUTTON2_RELEASED | BUTTON3_RELEASED)) - button = 3; - - if (mask & BUTTON_SHIFT) - state |= 4; - if (mask & BUTTON_ALT) - state |= 8; - if (mask & BUTTON_CTRL) - state |= 16; - - seq[3] = 32 + button + state; - seq[4] = 32 + x; - seq[5] = 32 + y; - - vt_write(t, seq, sizeof seq); - - if (mask & (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED)) { - /* send a button release event */ - button = 3; - seq[3] = 32 + button + state; - vt_write(t, seq, sizeof seq); - } -#endif /* NCURSES_MOUSE_VERSION */ -} - #ifndef HAVE_ALLOC_PAIR /* minimal replacements for the ncurses >= 6.1 color pair functions */ static struct { short fg, bg; } pairs[256]; diff --git a/vt.h b/vt.h index 5918d39..a4c7d5e 100644 --- a/vt.h +++ b/vt.h @@ -22,10 +22,6 @@ #include #include -#ifndef NCURSES_MOUSE_VERSION -#define mmask_t unsigned long -#endif - typedef struct Vt Vt; typedef void (*vt_title_handler_t)(Vt*, const char *title); typedef void (*vt_urgent_handler_t)(Vt*); @@ -51,7 +47,6 @@ bool vt_cursor_visible(Vt*); int vt_process(Vt *); void vt_keypress(Vt *, int keycode); ssize_t vt_write(Vt*, const char *buf, size_t len); -void vt_mouse(Vt*, int x, int y, mmask_t mask); void vt_dirty(Vt*); void vt_draw(Vt*, WINDOW *win, int startrow, int startcol); int vt_color_get(Vt*, int fg, int bg);