no reason to pass around *sc when it's already in menu_ctx.

This commit is contained in:
okan 2013-05-20 20:04:36 +00:00
parent 5b4c55616a
commit e14123210a

64
menu.c
View File

@ -65,18 +65,16 @@ struct menu_ctx {
static struct menu *menu_handle_key(XEvent *, struct menu_ctx *, static struct menu *menu_handle_key(XEvent *, struct menu_ctx *,
struct menu_q *, struct menu_q *); struct menu_q *, struct menu_q *);
static void menu_handle_move(XEvent *, struct menu_ctx *, static void menu_handle_move(XEvent *, struct menu_ctx *,
struct screen_ctx *, struct menu_q *); struct menu_q *);
static struct menu *menu_handle_release(XEvent *, struct menu_ctx *, static struct menu *menu_handle_release(XEvent *, struct menu_ctx *,
struct screen_ctx *, struct menu_q *); struct menu_q *);
static void menu_draw(struct screen_ctx *, struct menu_ctx *, static void menu_draw(struct menu_ctx *, struct menu_q *,
struct menu_q *, struct menu_q *); struct menu_q *);
static void menu_draw_entry(struct screen_ctx *, struct menu_ctx *, static void menu_draw_entry(struct menu_ctx *, struct menu_q *,
struct menu_q *, int, int);
static int menu_calc_entry(struct screen_ctx *, struct menu_ctx *,
int, int); int, int);
static int menu_calc_entry(struct menu_ctx *, int, int);
static struct menu *menu_complete_path(struct menu_ctx *); static struct menu *menu_complete_path(struct menu_ctx *);
static int menu_keycode(XKeyEvent *, enum ctltype *, static int menu_keycode(XKeyEvent *, enum ctltype *, char *);
char *);
void void
menu_init(struct screen_ctx *sc) menu_init(struct screen_ctx *sc)
@ -157,13 +155,13 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt,
goto out; goto out;
/* FALLTHROUGH */ /* FALLTHROUGH */
case Expose: case Expose:
menu_draw(sc, &mc, menuq, &resultq); menu_draw(&mc, menuq, &resultq);
break; break;
case MotionNotify: case MotionNotify:
menu_handle_move(&e, &mc, sc, &resultq); menu_handle_move(&e, &mc, &resultq);
break; break;
case ButtonRelease: case ButtonRelease:
if ((mi = menu_handle_release(&e, &mc, sc, &resultq)) if ((mi = menu_handle_release(&e, &mc, &resultq))
!= NULL) != NULL)
goto out; goto out;
break; break;
@ -342,9 +340,9 @@ menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq,
} }
static void static void
menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq)
struct menu_q *resultq)
{ {
struct screen_ctx *sc = mc->sc;
struct menu *mi; struct menu *mi;
struct geom xine; struct geom xine;
int n, xsave, ysave; int n, xsave, ysave;
@ -439,17 +437,18 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
} }
if (mc->hasprompt && n > 1 && (mc->searchstr[0] != '\0')) { if (mc->hasprompt && n > 1 && (mc->searchstr[0] != '\0')) {
mc->entry = 1; mc->entry = 1;
menu_draw_entry(sc, mc, resultq, mc->entry, 1); menu_draw_entry(mc, resultq, mc->entry, 1);
} }
} }
static void static void
menu_draw_entry(struct screen_ctx *sc, struct menu_ctx *mc, menu_draw_entry(struct menu_ctx *mc, struct menu_q *resultq,
struct menu_q *resultq, int entry, int active) int entry, int active)
{ {
struct menu *mi; struct screen_ctx *sc = mc->sc;
char *text; struct menu *mi;
int color, i = 0; char *text;
int color, i = 0;
if (mc->hasprompt) if (mc->hasprompt)
i = 1; i = 1;
@ -471,35 +470,33 @@ menu_draw_entry(struct screen_ctx *sc, struct menu_ctx *mc,
} }
static void static void
menu_handle_move(XEvent *e, struct menu_ctx *mc, struct screen_ctx *sc, menu_handle_move(XEvent *e, struct menu_ctx *mc, struct menu_q *resultq)
struct menu_q *resultq)
{ {
mc->prev = mc->entry; mc->prev = mc->entry;
mc->entry = menu_calc_entry(sc, mc, e->xbutton.x, e->xbutton.y); mc->entry = menu_calc_entry(mc, e->xbutton.x, e->xbutton.y);
if (mc->prev == mc->entry) if (mc->prev == mc->entry)
return; return;
if (mc->prev != -1) if (mc->prev != -1)
menu_draw_entry(sc, mc, resultq, mc->prev, 0); menu_draw_entry(mc, resultq, mc->prev, 0);
if (mc->entry != -1) { if (mc->entry != -1) {
(void)xu_ptr_regrab(MENUGRABMASK, Cursor_normal); (void)xu_ptr_regrab(MENUGRABMASK, Cursor_normal);
menu_draw_entry(sc, mc, resultq, mc->entry, 1); menu_draw_entry(mc, resultq, mc->entry, 1);
} else } else
(void)xu_ptr_regrab(MENUGRABMASK, Cursor_default); (void)xu_ptr_regrab(MENUGRABMASK, Cursor_default);
if (mc->hasprompt) if (mc->hasprompt)
menu_draw_entry(sc, mc, resultq, 1, 1); menu_draw_entry(mc, resultq, 1, 1);
} }
static struct menu * static struct menu *
menu_handle_release(XEvent *e, struct menu_ctx *mc, struct screen_ctx *sc, menu_handle_release(XEvent *e, struct menu_ctx *mc, struct menu_q *resultq)
struct menu_q *resultq)
{ {
struct menu *mi; struct menu *mi;
int entry, i = 0; int entry, i = 0;
entry = menu_calc_entry(sc, mc, e->xbutton.x, e->xbutton.y); entry = menu_calc_entry(mc, e->xbutton.x, e->xbutton.y);
if (mc->hasprompt) if (mc->hasprompt)
i = 1; i = 1;
@ -516,9 +513,10 @@ menu_handle_release(XEvent *e, struct menu_ctx *mc, struct screen_ctx *sc,
} }
static int static int
menu_calc_entry(struct screen_ctx *sc, struct menu_ctx *mc, int x, int y) menu_calc_entry(struct menu_ctx *mc, int x, int y)
{ {
int entry; struct screen_ctx *sc = mc->sc;
int entry;
entry = y / (sc->xftfont->height + 1); entry = y / (sc->xftfont->height + 1);