Skip to content
This repository has been archived by the owner on Jul 15, 2020. It is now read-only.

Commit

Permalink
[menu] Add vertical mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris Maglione committed Oct 7, 2010
1 parent 8ca9f3c commit ed809b8
Show file tree
Hide file tree
Showing 27 changed files with 402 additions and 467 deletions.
8 changes: 4 additions & 4 deletions alternative_wmiircs/python/pygmi/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def message(message):
call(*args, input=message)

def program_list(path):
names = []
names = set()
for d in path:
try:
for f in os.listdir(d):
p = '%s/%s' % (d, f)
if f not in names and os.access(p, os.X_OK) and (
os.path.isfile(p) or os.path.islink(p)):
names.append(f)
if (f not in names and os.access(p, os.X_OK) and
os.path.isfile(p)):
names.add(f)
except Exception:
pass
return sorted(names)
Expand Down
5 changes: 3 additions & 2 deletions cmd/menu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ include $(ROOT)/mk/wmii.mk
main.c: $(ROOT)/mk/wmii.mk

bindings.c: keys.txt Makefile
( echo "char binding_spec[] = "; \
( echo "char binding_spec[] ="; \
sed 's/.*/ "&\\n"/' keys.txt; \
echo " ;" ) >bindings.c
echo " ;" ) >$@

TARG = wimenu
HFILES= dat.h fns.h
TAGFILES= dat.h

PACKAGES += $(X11PACKAGES)

Expand Down
8 changes: 2 additions & 6 deletions cmd/menu/caret.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ caret_find(int dir, int type) {
p = next;
return p;
case CHAR:
if(p < end)
return p+1;
return p;
return next_rune(p, &r);
}
}
else if(dir == BACKWARD) {
Expand All @@ -88,9 +86,7 @@ caret_find(int dir, int type) {
p = next;
return p;
case CHAR:
if(p > end)
return prev_rune(end, p, &r);
return end;
return prev_rune(end, p, &r);
}
}
input.pos_end = nil;
Expand Down
54 changes: 27 additions & 27 deletions cmd/menu/dat.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include <stuff/x.h>
#include <stuff/util.h>

#define BLOCK(x) do { x; }while(0)

#ifndef EXTERN
# define EXTERN extern
#endif
Expand Down Expand Up @@ -69,38 +67,40 @@ EXTERN struct {
int filter_start;
} input;

extern char binding_spec[];

EXTERN int numlock;

EXTERN long xtime;
EXTERN Image* ibuf;
EXTERN Font* font;
EXTERN CTuple cnorm, csel;
EXTERN bool ontop;
EXTERN struct {
Window* win;
Image* buf;
char* prompt;
int height;
int rows;
bool ontop;
Rectangle itemr;
Point arrow;
} menu;

EXTERN Cursor cursor[1];
EXTERN Visual* render_visual;
extern char binding_spec[];

EXTERN IxpServer srv;

EXTERN Window* barwin;

EXTERN Item* items;
EXTERN Item* matchfirst;
EXTERN Item* matchstart;
EXTERN Item* matchend;
EXTERN Item* matchidx;
EXTERN struct {
Item* all;
Item* first;
Item* start;
Item* end;
Item* sel;
int maxwidth;
} match;

Font* font;
CTuple cnorm;
CTuple csel;

EXTERN Item hist;
EXTERN Item* histidx;
EXTERN Item* histsel;

EXTERN int maxwidth;
EXTERN int itempad;
EXTERN int result;

EXTERN char* (*find)(const char*, const char*);
EXTERN int (*compare)(const char*, const char*, size_t);

EXTERN char* prompt;
EXTERN int promptw;
EXTERN char* (*find)(const char*, const char*);
EXTERN int (*compare)(const char*, const char*, size_t);

12 changes: 6 additions & 6 deletions cmd/menu/history.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ history_search(int dir, char *string, int n) {
Item *i;

if(dir == FORWARD) {
if(histidx == &hist)
if(histsel == &hist)
return hist.string;
for(i=histidx->next; i != hist.next; i=i->next)
for(i=histsel->next; i != hist.next; i=i->next)
if(!i->string || !compare(i->string, string, n)) {
histidx = i;
histsel = i;
return i->string;
}
return string;
}
assert(dir == BACKWARD);

if(histidx == &hist) {
if(histsel == &hist) {
free(hist.string);
hist.string = estrdup(input.string);
}

for(i=histidx->prev; i != &hist; i=i->prev)
for(i=histsel->prev; i != &hist; i=i->prev)
if(!compare(i->string, string, n)) {
histidx = i;
histsel = i;
return i->string;
}
return string;
Expand Down
3 changes: 2 additions & 1 deletion cmd/menu/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ struct Key {
char** action;
};

static Key* bindings;
static Key* bindings;
static int numlock;

/*
* To do: Find my red black tree implementation.
Expand Down
62 changes: 30 additions & 32 deletions cmd/menu/main.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* Copyright ©2006-2010 Kris Maglione <maglione.k at Gmail>
* See LICENSE file for license details.
*/
#define IXP_NO_P9_
#define IXP_P9_STRUCTS
#define EXTERN
#include "dat.h"
#include <X11/Xproto.h>
Expand All @@ -23,7 +21,9 @@ static int screen_hint;

static void
usage(void) {
fatal("usage: wimenu -i [-h <history>] [-a <address>] [-p <prompt>] [-s <screen>]\n");
fprint(2, "usage: %s -i [-a <address>] [-h <history>] [-p <prompt>] [-r <rows>] [-s <screen>]\n", argv0);
fprint(2, " See manual page for full usage details.\n");
exit(1);
}

static int
Expand All @@ -50,13 +50,13 @@ populate_list(Biobuf *buf, bool hist) {
bool stop;

stop = !hist && !isatty(buf->fid);
ret.next_link = nil;
i = &ret;
while((p = Brdstr(buf, '\n', true))) {
if(stop && p[0] == '\0')
break;
link(i, emallocz(sizeof *i));
i->next_link = i->next;
i = i->next;
i->next_link = emallocz(sizeof *i);
i = i->next_link;
i->string = p;
i->retstring = p;
if(cmdsep && (p = strstr(p, cmdsep))) {
Expand All @@ -65,15 +65,12 @@ populate_list(Biobuf *buf, bool hist) {
}
if(!hist) {
i->len = strlen(i->string);
i->width = textwidth_l(font, i->string, i->len);
if(i->width > maxwidth)
maxwidth = i->width;
i->width = textwidth_l(font, i->string, i->len) + itempad;
match.maxwidth = max(i->width, match.maxwidth);
}
}

link(i, &ret);
splice(&ret);
return ret.next != &ret ? ret.next : nil;
return ret.next_link;
}

static void
Expand All @@ -86,7 +83,7 @@ check_competions(IxpConn *c) {
return;
}
input.filter_start = strtol(s, nil, 10);
items = populate_list(cmplbuf, false);
match.all = populate_list(cmplbuf, false);
update_filter(false);
menu_draw();
}
Expand Down Expand Up @@ -143,8 +140,8 @@ update_filter(bool print) {
if(input.pos < input.end)
filter = freelater(estrndup(filter, input.pos - filter));

matchidx = nil;
matchfirst = matchstart = filter_list(items, filter);
match.sel = nil;
match.first = match.start = filter_list(match.all, filter);
if(print)
update_input();
}
Expand All @@ -158,8 +155,7 @@ init_screens(void) {
int i, n;

rects = xinerama_screens(&n);
if (screen_hint >= 0 && screen_hint < n)
/* We were given a valid screen index, use that. */
if(screen_hint >= 0 && screen_hint < n)
i = screen_hint;
else {
/* Pick the screen with the pointer, for now. Later,
Expand All @@ -178,11 +174,11 @@ init_screens(void) {

int
main(int argc, char *argv[]) {
Item *item;
static char *address;
static char *histfile;
static char *keyfile;
static bool nokeys;
Item *item;
int i;
long ndump;

Expand Down Expand Up @@ -220,7 +216,10 @@ main(int argc, char *argv[]) {
ndump = strtol(EARGF(usage()), nil, 10);
break;
case 'p':
prompt = EARGF(usage());
menu.prompt = EARGF(usage());
break;
case 'r':
menu.rows = strtol(EARGF(usage()), nil, 10);
break;
case 's':
screen_hint = strtol(EARGF(usage()), nil, 10);
Expand Down Expand Up @@ -249,11 +248,13 @@ main(int argc, char *argv[]) {
srv.preselect = event_preselect;
ixp_listen(&srv, ConnectionNumber(display), nil, event_fdready, event_fdclosed);

ontop = !strcmp(readctl("bar on "), "top");
menu.ontop = !strcmp(readctl("/ctl", "bar "), "on top");
client_readconfig(&cnorm, &csel, &font);

itempad = (font->height & ~1) + font->pad.min.x + font->pad.max.x;

cmplbuf = Bfdopen(0, OREAD);
items = populate_list(cmplbuf, false);
match.all = populate_list(cmplbuf, false);
if(!isatty(cmplbuf->fid))
ixp_listen(&srv, cmplbuf->fid, inbuf, check_competions, nil);

Expand All @@ -268,21 +269,18 @@ main(int argc, char *argv[]) {
parse_keys(buffer);
}

histidx = &hist;
histsel = &hist;
link(&hist, &hist);
if(histfile) {
inbuf = Bopen(histfile, OREAD);
if(inbuf) {
item = populate_list(inbuf, true);
if(item) {
link(item->prev, &hist);
link(&hist, item);
}
Bterm(inbuf);
if(histfile && (inbuf = Bopen(histfile, OREAD))) {
item = filter_list(populate_list(inbuf, true), "");
if(item->string) {
link(item->prev, &hist);
link(&hist, item);
}
Bterm(inbuf);
}

if(barwin == nil)
if(menu.win == nil)
menu_init();

init_screens();
Expand Down
Loading

0 comments on commit ed809b8

Please sign in to comment.