[w3m-dev 03455] mouse menu

* configure (config.h): MOUSE_FILE
* display.c (displayBuffer): nTab -> nTab2, N_TAB -> nTabLine()
	(redrawNLine): nTab -> nTab2, N_TAB -> nTabLine()
			mouse_menu support
* fm.h (nTab2): added
	(N_TAB): deleted
	(NO_TABBUFFER): added
	(struct _MouseMenu): added
	(mouse_menu_map): added
	(mouse_menu): added
* func.c (initMouseMenu): added
* main.c (main): initMouseMenu()
	(posTab): mouse_menu support
	(mouse_menu_action): added
	(process_mouse): mouse_menu support
	(reinit): initMouseMenu()
	(nTabLine): added
	(moveTab): check NO_TABBUFFER
* proto.h (nTabLine): added
	(initMouseMenu): added
* rc.c (sync_with_option): initMouseMenu()
From: Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
This commit is contained in:
Fumitoshi UKAI
2002-11-21 16:31:35 +00:00
parent be89d9319a
commit 1248fa2911
8 changed files with 216 additions and 26 deletions
+26 -1
View File
@@ -1,3 +1,28 @@
2002-11-22 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
* [w3m-dev 03455] mouse menu
* configure (config.h): MOUSE_FILE
* display.c (displayBuffer): nTab -> nTab2, N_TAB -> nTabLine()
(redrawNLine): nTab -> nTab2, N_TAB -> nTabLine()
mouse_menu support
* fm.h (nTab2): added
(N_TAB): deleted
(NO_TABBUFFER): added
(struct _MouseMenu): added
(mouse_menu_map): added
(mouse_menu): added
* func.c (initMouseMenu): added
* main.c (main): initMouseMenu()
(posTab): mouse_menu support
(mouse_menu_action): added
(process_mouse): mouse_menu support
(reinit): initMouseMenu()
(nTabLine): added
(moveTab): check NO_TABBUFFER
* proto.h (nTabLine): added
(initMouseMenu): added
* rc.c (sync_with_option): initMouseMenu()
2002-11-22 Fumitoshi UKAI <ukai@debian.or.jp> 2002-11-22 Fumitoshi UKAI <ukai@debian.or.jp>
* NEWS: func: NEXT, PREV * NEWS: func: NEXT, PREV
@@ -4948,4 +4973,4 @@ a * [w3m-dev 03276] compile error on EWS4800
* release-0-2-1 * release-0-2-1
* import w3m-0.2.1 * import w3m-0.2.1
$Id: ChangeLog,v 1.540 2002/11/21 16:17:15 ukai Exp $ $Id: ChangeLog,v 1.541 2002/11/21 16:31:35 ukai Exp $
Vendored
+2 -1
View File
@@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
# $Id: configure,v 1.87 2002/11/15 15:36:48 ukai Exp $ # $Id: configure,v 1.88 2002/11/21 16:31:35 ukai Exp $
# Configuration. # Configuration.
# #
@@ -2420,6 +2420,7 @@ $def_use_xface
#define CONFIG_FILE "config" #define CONFIG_FILE "config"
#define KEYMAP_FILE "keymap" #define KEYMAP_FILE "keymap"
#define MENU_FILE "menu" #define MENU_FILE "menu"
#define MOUSE_FILE "mouse"
#define COOKIE_FILE "cookie" #define COOKIE_FILE "cookie"
#define HISTORY_FILE "history" #define HISTORY_FILE "history"
+13 -7
View File
@@ -1,4 +1,4 @@
/* $Id: display.c,v 1.34 2002/11/19 17:40:31 ukai Exp $ */ /* $Id: display.c,v 1.35 2002/11/21 16:31:35 ukai Exp $ */
#include <signal.h> #include <signal.h>
#include "fm.h" #include "fm.h"
@@ -254,8 +254,8 @@ displayBuffer(Buffer *buf, int mode)
else else
buf->rootX = 0; buf->rootX = 0;
buf->COLS = COLS - buf->rootX; buf->COLS = COLS - buf->rootX;
if (nTab > 1) { if (nTab2 > 1) {
ny = (nTab - 1) / N_TAB + 2; ny = (nTab2 - 1) / nTabLine() + 2;
if (ny > LASTLINE) if (ny > LASTLINE)
ny = LASTLINE; ny = LASTLINE;
} }
@@ -445,12 +445,18 @@ redrawNLine(Buffer *buf, int n)
#endif /* USE_BG_COLOR */ #endif /* USE_BG_COLOR */
} }
#endif /* USE_COLOR */ #endif /* USE_COLOR */
if (nTab > 1) { if (nTab2 > 1) {
TabBuffer *t; TabBuffer *t;
int nx = N_TAB, col = COLS - 2, x, l; int nx = nTabLine(), col = COLS - 2, x, l;
i = 0;
move(0, 0); move(0, 0);
for (t = FirstTab, i = 0; t; t = t->nextTab, i++) { if (mouse_menu) {
addstr(mouse_menu);
clrtoeolx();
i++;
}
for (t = FirstTab; t; t = t->nextTab, i++) {
x = col * (i % nx) / nx; x = col * (i % nx) / nx;
move(i / nx, x); move(i / nx, x);
if (t == CurrentTab) if (t == CurrentTab)
@@ -474,7 +480,7 @@ redrawNLine(Buffer *buf, int n)
} }
move(0, col); move(0, col);
addstr(" x"); addstr(" x");
move((nTab - 1) / nx + 1, 0); move((nTab2 - 1) / nx + 1, 0);
for (i = 0; i < COLS; i++) for (i = 0; i < COLS; i++)
addch('~'); addch('~');
} }
+8 -3
View File
@@ -1,4 +1,4 @@
/* $Id: fm.h,v 1.84 2002/11/19 17:40:32 ukai Exp $ */ /* $Id: fm.h,v 1.85 2002/11/21 16:31:36 ukai Exp $ */
/* /*
* w3m: WWW wo Miru utility * w3m: WWW wo Miru utility
* *
@@ -805,9 +805,9 @@ global int open_tab_blank init(FALSE);
global int open_tab_dl_list init(FALSE); global int open_tab_dl_list init(FALSE);
global int close_tab_back init(FALSE); global int close_tab_back init(FALSE);
global int nTab; global int nTab;
#define nTab2 (mouse_menu ? (nTab + 1) : nTab)
global int TabCols init(10); global int TabCols init(10);
#define N_TAB ((COLS - 2 > TabCols * nTab) ? nTab \ #define NO_TABBUFFER ((TabBuffer *)1)
: (nTab - 1) / ((nTab * TabCols - 1) / (COLS - 2) + 1) + 1)
#define Currentbuf (CurrentTab->currentBuffer) #define Currentbuf (CurrentTab->currentBuffer)
#define Firstbuf (CurrentTab->firstBuffer) #define Firstbuf (CurrentTab->firstBuffer)
global DownloadList *FirstDL init(NULL); global DownloadList *FirstDL init(NULL);
@@ -991,7 +991,12 @@ global int reverse_mouse init(FALSE);
global int relative_wheel_scroll init(FALSE); global int relative_wheel_scroll init(FALSE);
global int fixed_wheel_scroll_count init(5); global int fixed_wheel_scroll_count init(5);
global int relative_wheel_scroll_ratio init(30); global int relative_wheel_scroll_ratio init(30);
struct _MouseMenu {
void (*func) ();
char *data;
} mouse_menu_map[3][10];
#endif /* USE_MOUSE */ #endif /* USE_MOUSE */
global char *mouse_menu init(NULL);
#ifdef USE_COOKIE #ifdef USE_COOKIE
global int default_use_cookie init(TRUE); global int default_use_cookie init(TRUE);
+66 -1
View File
@@ -1,4 +1,4 @@
/* $Id: func.c,v 1.10 2002/06/01 16:50:16 ukai Exp $ */ /* $Id: func.c,v 1.11 2002/11/21 16:31:36 ukai Exp $ */
/* /*
* w3m func.c * w3m func.c
*/ */
@@ -320,3 +320,68 @@ getQWord(char **str)
*str = p; *str = p;
return tmp->ptr; return tmp->ptr;
} }
#ifdef USE_MOUSE
void
initMouseMenu(void)
{
FILE *mf;
Str line;
char *p, *s;
int f, b, x, x2;
mouse_menu = NULL;
for (b = 1; b <= 3; b++) {
for (x = 0; x < 10; x++) {
mouse_menu_map[b - 1][x].func = NULL;
mouse_menu_map[b - 1][x].data = NULL;
}
}
if ((mf = fopen(rcFile(MOUSE_FILE), "rt")) == NULL)
return;
while (!feof(mf)) {
line = Strfgets(mf);
Strchop(line);
Strremovefirstspaces(line);
if (line->length == 0)
continue;
p = line->ptr;
s = getWord(&p);
if (*s == '#') /* comment */
continue;
if (!strcmp(s, "menu")) {
s = getQWord(&p);
if (*s)
mouse_menu = Strnew_charp(s)->ptr;
continue;
}
if (strcmp(s, "button"))
continue; /* error */
s = getWord(&p);
b = atoi(s);
if (!(b >= 1 && b <= 3))
continue; /* error */
s = getWord(&p);
x = atoi(s);
if (!(IS_DIGIT(*s) && x >= 0 && x <= 9))
continue; /* error */
s = getWord(&p);
x2 = atoi(s);
if (!(IS_DIGIT(*s) && x2 >= 0 && x2 <= 9))
continue; /* error */
s = getWord(&p);
f = getFuncList(s);
if (f < 0)
continue; /* error */
s = getQWord(&p);
if (!*s)
s = NULL;
for (; x <= x2; x++) {
mouse_menu_map[b - 1][x].func = w3mFuncList[f].func;
mouse_menu_map[b - 1][x].data = s;
}
}
fclose(mf);
}
#endif
+92 -11
View File
@@ -1,4 +1,4 @@
/* $Id: main.c,v 1.146 2002/11/21 16:15:58 ukai Exp $ */ /* $Id: main.c,v 1.147 2002/11/21 16:31:36 ukai Exp $ */
#define MAINPROGRAM #define MAINPROGRAM
#include "fm.h" #include "fm.h"
#include <signal.h> #include <signal.h>
@@ -746,6 +746,9 @@ main(int argc, char **argv, char **envp)
setupscreen(); setupscreen();
#endif /* not SIGWINCH */ #endif /* not SIGWINCH */
initKeymap(TRUE); initKeymap(TRUE);
#ifdef USE_MOUSE
initMouseMenu();
#endif /* MOUSE */
#ifdef USE_MENU #ifdef USE_MENU
initMenu(); initMenu();
#endif /* MENU */ #endif /* MENU */
@@ -4787,11 +4790,43 @@ posTab(int x, int y)
if (col <= 0) if (col <= 0)
return NULL; return NULL;
n = x * N_TAB / col + y * N_TAB; n = nTabLine();
for (t = FirstTab, i = 0; t && i < n; t = t->nextTab, i++) ; n = x * n / col + y * n;
i = 0;
if (mouse_menu) {
if (n == 0)
return NO_TABBUFFER;
i++;
}
for (t = FirstTab; t && i < n; t = t->nextTab, i++) ;
return t; return t;
} }
static void
mouse_menu_action(int btn, int x)
{
switch (btn) {
case MOUSE_BTN1_DOWN:
btn = 0;
break;
case MOUSE_BTN2_DOWN:
btn = 1;
break;
case MOUSE_BTN3_DOWN:
btn = 2;
break;
default:
return;
}
if (x >= 0 && x <= 9 && mouse_menu_map[btn][x].func) {
CurrentKey = -1;
CurrentKeyData = NULL;
CurrentCmdData = mouse_menu_map[btn][x].data;
(*mouse_menu_map[btn][x].func) ();
CurrentCmdData = NULL;
}
}
static void static void
process_mouse(int btn, int x, int y) process_mouse(int btn, int x, int y)
{ {
@@ -4800,20 +4835,26 @@ process_mouse(int btn, int x, int y)
TabBuffer *t; TabBuffer *t;
int ny = 0; int ny = 0;
if (nTab > 1) if (nTab2 > 1)
ny = (nTab - 1) / N_TAB + 1; ny = (nTab2 - 1) / nTabLine() + 1;
if (btn == MOUSE_BTN_UP) { if (btn == MOUSE_BTN_UP) {
switch (press_btn) { switch (press_btn) {
case MOUSE_BTN1_DOWN: case MOUSE_BTN1_DOWN:
if (nTab > 1 && y < ny) { if (nTab2 > 1 && y < ny) {
if (press_y == y && press_x == x) { if (press_y == y && press_x == x) {
if (y == 0 && x >= COLS - 2) { if (y == 0 && x >= COLS - 2) {
deleteTab(CurrentTab); deleteTab(CurrentTab);
displayBuffer(Currentbuf, B_NORMAL); displayBuffer(Currentbuf, B_FORCE_REDRAW);
return;
} }
t = posTab(x, y); t = posTab(x, y);
if (t) if (t == NULL)
CurrentTab = t; return;
if (t == NO_TABBUFFER) {
mouse_menu_action(press_btn, x);
return;
}
CurrentTab = t;
displayBuffer(Currentbuf, B_FORCE_REDRAW); displayBuffer(Currentbuf, B_FORCE_REDRAW);
return; return;
} }
@@ -4829,6 +4870,8 @@ process_mouse(int btn, int x, int y)
t = posTab(x, y); t = posTab(x, y);
if (t == NULL) if (t == NULL)
return; return;
if (t == NO_TABBUFFER)
t = NULL; /* open new tab */
cursorXY(Currentbuf, press_x - Currentbuf->rootX, cursorXY(Currentbuf, press_x - Currentbuf->rootX,
press_y - Currentbuf->rootY); press_y - Currentbuf->rootY);
if (Currentbuf->cursorY == press_y - Currentbuf->rootY && if (Currentbuf->cursorY == press_y - Currentbuf->rootY &&
@@ -4915,9 +4958,13 @@ process_mouse(int btn, int x, int y)
} }
break; break;
case MOUSE_BTN2_DOWN: case MOUSE_BTN2_DOWN:
if (nTab > 1 && y < ny) { if (nTab2 > 1 && y < ny) {
if (press_y == y && press_x == x) { if (press_y == y && press_x == x) {
t = posTab(x, y); t = posTab(x, y);
if (t == NO_TABBUFFER) {
mouse_menu_action(press_btn, x);
return;
}
if (t) { if (t) {
deleteTab(t); deleteTab(t);
displayBuffer(Currentbuf, B_FORCE_REDRAW); displayBuffer(Currentbuf, B_FORCE_REDRAW);
@@ -4928,6 +4975,15 @@ process_mouse(int btn, int x, int y)
backBf(); backBf();
break; break;
case MOUSE_BTN3_DOWN: case MOUSE_BTN3_DOWN:
if (nTab2 > 1 && y < ny) {
if (press_y == y && press_x == x) {
t = posTab(x, y);
if (t == NO_TABBUFFER) {
mouse_menu_action(press_btn, x);
return;
}
}
}
#ifdef USE_MENU #ifdef USE_MENU
if (x >= Currentbuf->rootX && y > ny) if (x >= Currentbuf->rootX && y > ny)
cursorXY(Currentbuf, x - Currentbuf->rootX, cursorXY(Currentbuf, x - Currentbuf->rootX,
@@ -5438,6 +5494,9 @@ reinit()
initCookie(); initCookie();
#endif #endif
initKeymap(TRUE); initKeymap(TRUE);
#ifdef USE_MOUSE
initMouseMenu();
#endif
#ifdef USE_MENU #ifdef USE_MENU
initMenu(); initMenu();
#endif #endif
@@ -5467,6 +5526,13 @@ reinit()
return; return;
} }
#ifdef USE_MOUSE
if (!strcasecmp(resource, "MOUSE_MENU")) {
initMouseMenu();
return;
}
#endif
#ifdef USE_MENU #ifdef USE_MENU
if (!strcasecmp(resource, "MENU")) { if (!strcasecmp(resource, "MENU")) {
initMenu(); initMenu();
@@ -5559,6 +5625,19 @@ newT(void)
displayBuffer(Currentbuf, B_REDRAW_IMAGE); displayBuffer(Currentbuf, B_REDRAW_IMAGE);
} }
int
nTabLine(void)
{
int n = nTab2;
if (COLS - 2 > TabCols * n)
return n;
n = (n - 1) / ((n * TabCols - 1) / (COLS - 2) + 1) + 1;
if (n > (COLS - 2) / TabCols)
n = (COLS - 2) / TabCols;
return n ? n : 1;
}
TabBuffer * TabBuffer *
numTab(int n) numTab(int n)
{ {
@@ -5763,7 +5842,9 @@ tabrURL(void)
void void
moveTab(TabBuffer * t, TabBuffer * t2, int right) moveTab(TabBuffer * t, TabBuffer * t2, int right)
{ {
if (!t || !t2 || t == t2) if (t2 == NO_TABBUFFER)
t2 = FirstTab;
if (!t || !t2 || t == t2 || t == NO_TABBUFFER)
return; return;
if (t->prevTab) { if (t->prevTab) {
if (t->nextTab) if (t->nextTab)
+5 -1
View File
@@ -1,4 +1,4 @@
/* $Id: proto.h,v 1.57 2002/11/21 16:15:58 ukai Exp $ */ /* $Id: proto.h,v 1.58 2002/11/21 16:31:36 ukai Exp $ */
/* /*
* This file was automatically generated by version 1.7 of cextract. * This file was automatically generated by version 1.7 of cextract.
* Manual editing not recommended. * Manual editing not recommended.
@@ -225,6 +225,7 @@ extern char *inputAnswer(char *prompt);
extern int matchattr(char *p, char *attr, int len, Str *value); extern int matchattr(char *p, char *attr, int len, Str *value);
extern void readHeader(URLFile *uf, Buffer *newBuf, int thru, ParsedURL *pu); extern void readHeader(URLFile *uf, Buffer *newBuf, int thru, ParsedURL *pu);
extern char *checkHeader(Buffer *buf, char *field); extern char *checkHeader(Buffer *buf, char *field);
extern int nTabLine(void);
extern TabBuffer *newTab(void); extern TabBuffer *newTab(void);
extern TabBuffer *deleteTab(TabBuffer *tab); extern TabBuffer *deleteTab(TabBuffer *tab);
extern void addDownloadList(pid_t pid, char *url, char *save, char *lock, extern void addDownloadList(pid_t pid, char *url, char *save, char *lock,
@@ -626,6 +627,9 @@ extern int getKey(char *s);
extern char *getKeyData(int key); extern char *getKeyData(int key);
extern char *getWord(char **str); extern char *getWord(char **str);
extern char *getQWord(char **str); extern char *getQWord(char **str);
#ifdef USE_MOUSE
extern void initMouseMenu(void);
#endif
#ifdef USE_MENU #ifdef USE_MENU
extern void new_menu(Menu *menu, MenuItem *item); extern void new_menu(Menu *menu, MenuItem *item);
+4 -1
View File
@@ -1,4 +1,4 @@
/* $Id: rc.c,v 1.65 2002/11/19 17:40:34 ukai Exp $ */ /* $Id: rc.c,v 1.66 2002/11/21 16:31:36 ukai Exp $ */
/* /*
* Initialization file etc. * Initialization file etc.
*/ */
@@ -1322,6 +1322,9 @@ sync_with_option(void)
AcceptMedia = acceptableMimeTypes(); AcceptMedia = acceptableMimeTypes();
if (fmInitialized) { if (fmInitialized) {
initKeymap(FALSE); initKeymap(FALSE);
#ifdef USE_MOUSE
initMouseMenu();
#endif /* MOUSE */
#ifdef USE_MENU #ifdef USE_MENU
initMenu(); initMenu();
#endif /* MENU */ #endif /* MENU */