dvtm

dynamic virtual terminal manager - with my changes
git clone https://pi.duncano.de/git/dvtm.git
Log | Files | Refs | README | LICENSE

commit 487a92c5e75a2842fcc5ef28ec3099ac57996538
parent daf2b7867d986d778c2442b526f46e4d59e2c682
Author: Marc Andre Tanner <mat@brain-dump.org>
Date:   Sat, 14 Jun 2008 19:15:32 +0200

Split mouse support into separate file

Diffstat:
config.h | 4++--
config.mk | 2+-
dvtm.c | 94++++++++++++-------------------------------------------------------------------
mouse.c | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 85 insertions(+), 83 deletions(-)

diff --git a/config.h b/config.h @@ -116,14 +116,14 @@ Key keys[] = { * REPORT_MOUSE_POSITION report mouse movement */ -#if defined(HANDLE_MOUSE) +#ifdef CONFIG_MOUSE Button buttons[] = { { BUTTON1_CLICKED, { mouse_focus, { NULL } } }, { BUTTON1_DOUBLE_CLICKED, { mouse_fullscreen, { "[ ]" } } }, { BUTTON2_CLICKED, { mouse_zoom, { NULL } } }, { BUTTON3_CLICKED, { mouse_minimize, { NULL } } }, }; -#endif /* HANDLE_MOUSE */ +#endif /* CONFIG_MOUSE */ #ifdef CONFIG_CMDFIFO Cmd commands[] = { diff --git a/config.mk b/config.mk @@ -14,7 +14,7 @@ CFLAGS += -std=c99 -Os ${INCS} -DVERSION=\"${VERSION}\" -DNDEBUG LDFLAGS += -L/usr/lib -L/usr/local/lib ${LIBS} # Mouse handling -CFLAGS += -DHANDLE_MOUSE +CFLAGS += -DCONFIG_MOUSE CFLAGS += -DCONFIG_CMDFIFO DEBUG_CFLAGS = ${CFLAGS} -UNDEBUG -O0 -g -ggdb -Wall diff --git a/dvtm.c b/dvtm.c @@ -72,12 +72,12 @@ typedef struct { Action action; } Key; -#if defined(HANDLE_MOUSE) +#ifdef CONFIG_MOUSE typedef struct { mmask_t mask; Action action; } Button; -#endif /* HANDLE_MOUSE */ +#endif #ifdef CONFIG_CMDFIFO typedef struct { @@ -118,18 +118,21 @@ void redraw(const char *args[]); void zoom(const char *args[]); void lock(const char *key[]); -#if defined(HANDLE_MOUSE) +#ifdef CONFIG_MOUSE void mouse_focus(const char *args[]); void mouse_fullscreen(const char *args[]); void mouse_minimize(const char *args[]); void mouse_zoom(const char *args[]); -#endif /* HANDLE_MOUSE */ +#endif void clear_workspace(); void draw_all(bool border); void draw_border(Client *c); void drawbar(); void resize(Client *c, int x, int y, int w, int h); +void eprint(const char *errstr, ...); +bool isarrange(void (*func)()); +void focus(Client *c); unsigned int bh = 1, by, waw, wah, wax, way; Client *clients = NULL; @@ -149,6 +152,10 @@ bool need_screen_resize = true; int width, height; bool running = true; +#ifdef CONFIG_MOUSE +# include "mouse.c" +#endif + #ifdef CONFIG_CMDFIFO # include "cmdfifo.c" #endif @@ -728,79 +735,6 @@ keybinding(unsigned int mod, unsigned int code) { return NULL; } -#if defined(HANDLE_MOUSE) - -void -mouse_focus(const char *args[]) { - focus(msel); - if (msel->minimized) - toggleminimize(NULL); -} - -void -mouse_fullscreen(const char *args[]) { - mouse_focus(NULL); - if (isarrange(fullscreen)) - setlayout(NULL); - else - setlayout(args); -} - -void -mouse_minimize(const char *args[]) { - focus(msel); - toggleminimize(NULL); -} - -void -mouse_zoom(const char *args[]) { - focus(msel); - zoom(NULL); -} - -Client* -get_client_by_coord(int x, int y) { - Client *c; - if (y < way || y >= wah) - return NULL; - if (isarrange(fullscreen)) - return sel; - for (c = clients; c; c = 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; - } - } - return NULL; -} - -void -handle_mouse() { - MEVENT event; - unsigned int i; - if (getmouse(&event) != OK) - return; - msel = get_client_by_coord(event.x, event.y); - if (!msel) - return; - for (i = 0; i < countof(buttons); i++) - if (event.bstate & buttons[i].mask) - buttons[i].action.cmd(buttons[i].action.args); - msel = NULL; -} - -void -mouse_setup() { - int i; - mmask_t mask; - for (i = 0, mask = 0; i < countof(buttons); i++) - mask |= buttons[i].mask; - if (mask) - mousemask(mask, NULL); -} - -#endif /* HANDLE_MOUSE */ - Client* get_client_by_pid(pid_t pid) { Client *c; @@ -893,7 +827,7 @@ setup() { start_color(); noecho(); keypad(stdscr, TRUE); -#if defined(HANDLE_MOUSE) +#ifdef CONFIG_MOUSE mouse_setup(); #endif raw(); @@ -1056,11 +990,11 @@ main(int argc, char *argv[]) { int code = getch(); Key *key; if (code >= 0) { -#if defined(HANDLE_MOUSE) +#ifdef CONFIG_MOUSE if (code == KEY_MOUSE) { handle_mouse(); } else -#endif /* HANDLE_MOUSE */ +#endif /* CONFIG_MOUSE */ if (is_modifier(code)) { int mod = code; code = getch(); diff --git a/mouse.c b/mouse.c @@ -0,0 +1,68 @@ +void +mouse_focus(const char *args[]) { + focus(msel); + if (msel->minimized) + toggleminimize(NULL); +} + +void +mouse_fullscreen(const char *args[]) { + mouse_focus(NULL); + if (isarrange(fullscreen)) + setlayout(NULL); + else + setlayout(args); +} + +void +mouse_minimize(const char *args[]) { + focus(msel); + toggleminimize(NULL); +} + +void +mouse_zoom(const char *args[]) { + focus(msel); + zoom(NULL); +} + +Client* +get_client_by_coord(int x, int y) { + Client *c; + if (y < way || y >= wah) + return NULL; + if (isarrange(fullscreen)) + return sel; + for (c = clients; c; c = 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; + } + } + return NULL; +} + +void +handle_mouse() { + MEVENT event; + unsigned int i; + if (getmouse(&event) != OK) + return; + msel = get_client_by_coord(event.x, event.y); + if (!msel) + return; + for (i = 0; i < countof(buttons); i++) + if (event.bstate & buttons[i].mask) + buttons[i].action.cmd(buttons[i].action.args); + msel = NULL; +} + +void +mouse_setup() { + int i; + mmask_t mask; + for (i = 0, mask = 0; i < countof(buttons); i++) + mask |= buttons[i].mask; + if (mask) + mousemask(mask, NULL); +}