2005-11-18 18:54:58 +03:00
|
|
|
/*
|
2006-01-20 17:20:24 +03:00
|
|
|
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
2006-02-11 01:57:21 +03:00
|
|
|
* (C)opyright MMVI Sander van Dijk <a dot h dot vandijk at gmail dot com>
|
2005-11-18 18:54:58 +03:00
|
|
|
* See LICENSE file for license details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <time.h>
|
2006-02-11 01:57:21 +03:00
|
|
|
#include <unistd.h>
|
2006-01-21 14:57:20 +03:00
|
|
|
#include <X11/Xlib.h>
|
2005-11-18 18:54:58 +03:00
|
|
|
#include <X11/cursorfont.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
|
2006-04-03 17:52:05 +04:00
|
|
|
#include <blitz.h>
|
|
|
|
#include <cext.h>
|
2006-02-11 01:57:21 +03:00
|
|
|
|
2006-04-06 12:39:49 +04:00
|
|
|
VECTOR(ItemVector, char *);
|
2006-05-25 00:10:54 +04:00
|
|
|
static char *title = nil;
|
2006-02-12 05:16:42 +03:00
|
|
|
static Bool done = False;
|
|
|
|
static int ret = 0;
|
|
|
|
static char text[4096];
|
2006-04-23 22:00:47 +04:00
|
|
|
static BlitzColor selcolor;
|
|
|
|
static BlitzColor normcolor;
|
2005-11-18 18:54:58 +03:00
|
|
|
static Display *dpy;
|
2005-12-05 01:45:59 +03:00
|
|
|
static Window win;
|
2006-05-25 00:10:54 +04:00
|
|
|
static XRectangle irect;
|
2006-02-02 18:44:45 +03:00
|
|
|
static int screen;
|
2006-04-03 17:38:32 +04:00
|
|
|
static ItemVector allitem = {0};
|
|
|
|
static ItemVector item = {0};
|
2006-02-12 05:16:42 +03:00
|
|
|
static int sel = -1;
|
2006-03-01 13:55:46 +03:00
|
|
|
static unsigned int nextoff = 0;
|
|
|
|
static unsigned int prevoff = 0;
|
|
|
|
static unsigned int curroff = 0;
|
2005-11-18 18:54:58 +03:00
|
|
|
static unsigned int cmdw = 0;
|
2006-06-05 05:21:15 +04:00
|
|
|
static unsigned int twidth = 0;
|
2006-06-05 05:50:48 +04:00
|
|
|
static unsigned int cwidth = 0;
|
2006-06-20 17:47:08 +04:00
|
|
|
static BlitzWidget *draw = nil;
|
2006-04-06 10:09:22 +04:00
|
|
|
static const int seek = 30; /* 30px */
|
2005-12-05 01:45:59 +03:00
|
|
|
|
|
|
|
static void draw_menu(void);
|
|
|
|
static void handle_kpress(XKeyEvent * e);
|
|
|
|
|
2006-02-04 17:31:52 +03:00
|
|
|
static char version[] = "wmiimenu - " VERSION ", (C)opyright MMIV-MMVI Anselm R. Garbe\n";
|
2005-11-18 18:54:58 +03:00
|
|
|
|
2006-04-03 17:38:32 +04:00
|
|
|
static Vector *
|
|
|
|
item2vector(ItemVector *iv)
|
|
|
|
{
|
|
|
|
return (Vector *) iv;
|
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
static void
|
|
|
|
usage()
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-05-25 00:10:54 +04:00
|
|
|
fprintf(stderr, "%s", "usage: wmiimenu [-v] [-t <title>]\n");
|
2006-03-23 00:54:23 +03:00
|
|
|
exit(1);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
static void
|
|
|
|
update_offsets()
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-03-01 13:55:46 +03:00
|
|
|
unsigned int i;
|
2006-05-13 23:21:32 +04:00
|
|
|
unsigned int tw, w = cmdw + 2 * seek;
|
2005-12-21 18:18:11 +03:00
|
|
|
|
2006-04-03 17:38:32 +04:00
|
|
|
if(!item.size)
|
2006-03-23 00:54:23 +03:00
|
|
|
return;
|
2005-12-21 18:18:11 +03:00
|
|
|
|
2006-04-03 17:38:32 +04:00
|
|
|
for(i = curroff; i < item.size; i++) {
|
2006-06-20 17:47:08 +04:00
|
|
|
tw = blitz_textwidth(draw->font, item.data[i]);
|
2006-05-25 00:10:54 +04:00
|
|
|
if(tw > irect.width / 3)
|
|
|
|
tw = irect.width / 3;
|
|
|
|
w += tw + irect.height;
|
|
|
|
if(w > irect.width)
|
2006-03-23 00:54:23 +03:00
|
|
|
break;
|
|
|
|
}
|
2006-02-12 05:16:42 +03:00
|
|
|
nextoff = i;
|
2005-12-21 18:18:11 +03:00
|
|
|
|
2006-03-23 00:54:23 +03:00
|
|
|
w = cmdw + 2 * seek;
|
|
|
|
for(i = curroff; i > 0; i--) {
|
2006-06-20 17:47:08 +04:00
|
|
|
tw = blitz_textwidth(draw->font, item.data[i]);
|
2006-05-25 00:10:54 +04:00
|
|
|
if(tw > irect.width / 3)
|
|
|
|
tw = irect.width / 3;
|
|
|
|
w += tw + irect.height;
|
|
|
|
if(w > irect.width)
|
2006-03-23 00:54:23 +03:00
|
|
|
break;
|
|
|
|
}
|
2006-02-12 05:16:42 +03:00
|
|
|
prevoff = i;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2006-03-23 18:12:06 +03:00
|
|
|
static unsigned int
|
2005-12-21 18:18:11 +03:00
|
|
|
update_items(char *pattern)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-03-23 00:54:23 +03:00
|
|
|
unsigned int plen = strlen(pattern);
|
|
|
|
int i;
|
2005-12-21 18:18:11 +03:00
|
|
|
|
2006-06-07 07:01:00 +04:00
|
|
|
if(*pattern)
|
|
|
|
cmdw = cwidth;
|
|
|
|
else
|
|
|
|
cmdw = twidth;
|
|
|
|
|
2006-02-12 05:16:42 +03:00
|
|
|
curroff = prevoff = nextoff = 0;
|
|
|
|
sel = -1;
|
|
|
|
|
2006-04-03 17:38:32 +04:00
|
|
|
while(item.size)
|
|
|
|
cext_vdetach(item2vector(&item), item.data[0]);
|
|
|
|
|
|
|
|
for(i = 0; i < allitem.size; i++)
|
|
|
|
if(!plen || !strncmp(pattern, allitem.data[i], plen))
|
|
|
|
cext_vattach(item2vector(&item), allitem.data[i]);
|
|
|
|
for(i = 0; i < allitem.size; i++)
|
|
|
|
if(plen && strncmp(pattern, allitem.data[i], plen)
|
|
|
|
&& strstr(allitem.data[i], pattern))
|
|
|
|
cext_vattach(item2vector(&item), allitem.data[i]);
|
|
|
|
if(item.size)
|
2006-02-12 14:00:44 +03:00
|
|
|
sel = 0;
|
2006-03-23 18:12:06 +03:00
|
|
|
|
2006-03-23 00:54:23 +03:00
|
|
|
update_offsets();
|
2006-04-03 17:38:32 +04:00
|
|
|
return item.size;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* creates draw structs for menu mode drawing */
|
2005-12-21 18:18:11 +03:00
|
|
|
static void
|
|
|
|
draw_menu()
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-03-23 00:54:23 +03:00
|
|
|
unsigned int i, offx = 0;
|
2006-02-12 05:16:42 +03:00
|
|
|
|
2006-06-20 17:47:08 +04:00
|
|
|
draw->align = WEST;
|
2006-05-25 00:10:54 +04:00
|
|
|
|
2006-06-20 17:47:08 +04:00
|
|
|
draw->rect = irect;
|
|
|
|
draw->rect.x = 0;
|
|
|
|
draw->rect.y = 0;
|
|
|
|
draw->color = normcolor;
|
|
|
|
draw->text = nil;
|
|
|
|
draw->draw(draw);
|
2006-03-23 00:54:23 +03:00
|
|
|
|
|
|
|
/* print command */
|
2006-06-05 05:21:15 +04:00
|
|
|
if(!title || text[0]) {
|
2006-06-20 17:47:08 +04:00
|
|
|
draw->text = text;
|
|
|
|
draw->color = normcolor;
|
2006-06-05 05:50:48 +04:00
|
|
|
cmdw = cwidth;
|
2006-06-05 05:21:15 +04:00
|
|
|
if(cmdw && item.size)
|
2006-06-20 17:47:08 +04:00
|
|
|
draw->rect.width = cmdw;
|
|
|
|
draw->draw(draw);
|
2006-06-05 05:21:15 +04:00
|
|
|
}
|
|
|
|
else {
|
2006-06-05 05:50:48 +04:00
|
|
|
cmdw = twidth;
|
2006-06-20 17:47:08 +04:00
|
|
|
draw->text = title;
|
|
|
|
draw->color = selcolor;
|
|
|
|
draw->rect.width = cmdw;
|
|
|
|
draw->draw(draw);
|
2006-06-05 05:21:15 +04:00
|
|
|
}
|
2006-06-20 17:47:08 +04:00
|
|
|
offx += draw->rect.width;
|
2006-03-23 00:54:23 +03:00
|
|
|
|
2006-06-20 17:47:08 +04:00
|
|
|
draw->align = CENTER;
|
2006-04-03 17:38:32 +04:00
|
|
|
if(item.size) {
|
2006-06-20 17:47:08 +04:00
|
|
|
draw->color = normcolor;
|
|
|
|
draw->text = prevoff < curroff ? "<" : nil;
|
|
|
|
draw->rect.x = offx;
|
|
|
|
draw->rect.width = seek;
|
|
|
|
offx += draw->rect.width;
|
|
|
|
draw->draw(draw);
|
2006-03-23 00:54:23 +03:00
|
|
|
|
|
|
|
/* determine maximum items */
|
|
|
|
for(i = curroff; i < nextoff; i++) {
|
2006-06-20 17:47:08 +04:00
|
|
|
draw->text = item.data[i];
|
|
|
|
draw->rect.x = offx;
|
|
|
|
draw->rect.width = blitz_textwidth(draw->font, draw->text);
|
|
|
|
if(draw->rect.width > irect.width / 3)
|
|
|
|
draw->rect.width = irect.width / 3;
|
|
|
|
draw->rect.width += irect.height;
|
2006-03-23 00:54:23 +03:00
|
|
|
if(sel == i) {
|
2006-06-20 17:47:08 +04:00
|
|
|
draw->color = selcolor;
|
|
|
|
draw->draw(draw);
|
2006-03-23 00:54:23 +03:00
|
|
|
} else {
|
2006-06-20 17:47:08 +04:00
|
|
|
draw->color = normcolor;
|
|
|
|
draw->draw(draw);
|
2006-03-23 00:54:23 +03:00
|
|
|
}
|
2006-06-20 17:47:08 +04:00
|
|
|
offx += draw->rect.width;
|
2006-03-23 00:54:23 +03:00
|
|
|
}
|
|
|
|
|
2006-06-20 17:47:08 +04:00
|
|
|
draw->color = normcolor;
|
|
|
|
draw->text = item.size > nextoff ? ">" : nil;
|
|
|
|
draw->rect.x = irect.width - seek;
|
|
|
|
draw->rect.width = seek;
|
|
|
|
draw->draw(draw);
|
2006-03-23 00:54:23 +03:00
|
|
|
}
|
2006-06-20 17:47:08 +04:00
|
|
|
XCopyArea(dpy, draw->drawable, win, draw->gc, 0, 0, irect.width,
|
2006-06-05 05:21:15 +04:00
|
|
|
irect.height, 0, 0);
|
2006-03-23 00:54:23 +03:00
|
|
|
XSync(dpy, False);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
static void
|
|
|
|
handle_kpress(XKeyEvent * e)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-03-23 00:54:23 +03:00
|
|
|
KeySym ksym;
|
|
|
|
char buf[32];
|
|
|
|
int num;
|
|
|
|
unsigned int len = strlen(text);
|
|
|
|
|
|
|
|
buf[0] = 0;
|
|
|
|
num = XLookupString(e, buf, sizeof(buf), &ksym, 0);
|
|
|
|
|
|
|
|
if(IsFunctionKey(ksym) || IsKeypadKey(ksym)
|
|
|
|
|| IsMiscFunctionKey(ksym) || IsPFKey(ksym)
|
|
|
|
|| IsPrivateKeypadKey(ksym))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* first check if a control mask is omitted */
|
|
|
|
if(e->state & ControlMask) {
|
|
|
|
switch (ksym) {
|
|
|
|
case XK_H:
|
|
|
|
case XK_h:
|
|
|
|
ksym = XK_BackSpace;
|
|
|
|
break;
|
|
|
|
case XK_I:
|
|
|
|
case XK_i:
|
|
|
|
ksym = XK_Tab;
|
|
|
|
break;
|
|
|
|
case XK_J:
|
|
|
|
case XK_j:
|
|
|
|
ksym = XK_Return;
|
|
|
|
break;
|
|
|
|
case XK_N:
|
|
|
|
case XK_n:
|
|
|
|
ksym = XK_Right;
|
|
|
|
break;
|
|
|
|
case XK_P:
|
|
|
|
case XK_p:
|
|
|
|
ksym = XK_Left;
|
|
|
|
break;
|
|
|
|
case XK_U:
|
|
|
|
case XK_u:
|
|
|
|
text[0] = 0;
|
|
|
|
update_items(text);
|
|
|
|
draw_menu();
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
case XK_bracketleft:
|
|
|
|
ksym = XK_Escape;
|
|
|
|
break;
|
|
|
|
default: /* ignore other control sequences */
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (ksym) {
|
|
|
|
case XK_Left:
|
|
|
|
if(sel <= 0)
|
|
|
|
return;
|
2006-02-12 05:16:42 +03:00
|
|
|
sel--;
|
2006-03-23 00:54:23 +03:00
|
|
|
break;
|
|
|
|
case XK_Tab:
|
2006-04-03 17:38:32 +04:00
|
|
|
if(!item.size)
|
2006-03-23 00:54:23 +03:00
|
|
|
return;
|
2006-04-03 17:38:32 +04:00
|
|
|
cext_strlcpy(text, item.data[sel], sizeof(text));
|
2006-03-23 00:54:23 +03:00
|
|
|
update_items(text);
|
|
|
|
break;
|
|
|
|
case XK_Right:
|
2006-04-03 17:38:32 +04:00
|
|
|
if(sel < 0 || (sel + 1 == item.size))
|
2006-03-23 00:54:23 +03:00
|
|
|
return;
|
2006-02-12 05:16:42 +03:00
|
|
|
sel++;
|
2006-03-23 00:54:23 +03:00
|
|
|
break;
|
|
|
|
case XK_Return:
|
2006-04-20 03:19:23 +04:00
|
|
|
if(e->state & ShiftMask) {
|
|
|
|
if(text)
|
|
|
|
fprintf(stdout, "%s", text);
|
|
|
|
}
|
2006-04-19 18:53:40 +04:00
|
|
|
else if(sel >= 0)
|
|
|
|
fprintf(stdout, "%s", item.data[sel]);
|
2006-04-20 03:02:31 +04:00
|
|
|
else if(text)
|
|
|
|
fprintf(stdout, "%s", text);
|
2006-02-12 05:16:42 +03:00
|
|
|
fflush(stdout);
|
|
|
|
done = True;
|
|
|
|
break;
|
2006-03-23 00:54:23 +03:00
|
|
|
case XK_Escape:
|
2006-02-12 05:16:42 +03:00
|
|
|
ret = 1;
|
|
|
|
done = True;
|
2006-03-23 00:54:23 +03:00
|
|
|
break;
|
|
|
|
case XK_BackSpace:
|
|
|
|
if(len) {
|
|
|
|
unsigned int i = len;
|
|
|
|
if(i) {
|
|
|
|
int prev_nitem;
|
|
|
|
do
|
|
|
|
text[--i] = 0;
|
2006-04-03 17:38:32 +04:00
|
|
|
while((prev_nitem = item.size) && i &&
|
2006-03-23 00:54:23 +03:00
|
|
|
prev_nitem == update_items(text));
|
|
|
|
}
|
|
|
|
update_items(text);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if((num == 1) && !iscntrl((int) buf[0])) {
|
|
|
|
buf[num] = 0;
|
|
|
|
if(len > 0)
|
|
|
|
cext_strlcat(text, buf, sizeof(text));
|
|
|
|
else
|
|
|
|
cext_strlcpy(text, buf, sizeof(text));
|
|
|
|
update_items(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(sel >= 0) {
|
|
|
|
if(sel == curroff - 1) {
|
2006-02-12 14:00:44 +03:00
|
|
|
curroff = prevoff;
|
2006-03-23 00:54:23 +03:00
|
|
|
update_offsets();
|
2006-04-03 17:38:32 +04:00
|
|
|
} else if((sel == nextoff) && (item.size > nextoff)) {
|
2006-02-12 14:00:44 +03:00
|
|
|
curroff = nextoff;
|
2006-03-23 00:54:23 +03:00
|
|
|
update_offsets();
|
2006-02-12 14:00:44 +03:00
|
|
|
}
|
2006-03-23 00:54:23 +03:00
|
|
|
}
|
|
|
|
draw_menu();
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2006-05-11 01:26:53 +04:00
|
|
|
static char *
|
2006-02-12 05:16:42 +03:00
|
|
|
read_allitems()
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-05-11 01:26:53 +04:00
|
|
|
static char *maxname = nil;
|
|
|
|
char *p, buf[1024];
|
2006-03-01 13:55:46 +03:00
|
|
|
unsigned int len = 0, max = 0;
|
2006-02-12 05:16:42 +03:00
|
|
|
|
|
|
|
while(fgets(buf, sizeof(buf), stdin)) {
|
2006-02-12 14:00:44 +03:00
|
|
|
len = strlen(buf);
|
2006-02-19 00:07:04 +03:00
|
|
|
if (buf[len - 1] == '\n') /* there might be no \n after the last item */
|
|
|
|
buf[len - 1] = 0; /* removing \n */
|
2006-02-12 05:16:42 +03:00
|
|
|
p = strdup(buf);
|
2006-03-23 00:54:23 +03:00
|
|
|
if(max < len) {
|
2006-02-12 05:16:42 +03:00
|
|
|
maxname = p;
|
2006-03-23 00:54:23 +03:00
|
|
|
max = len;
|
|
|
|
}
|
2006-04-03 17:38:32 +04:00
|
|
|
cext_vattach(item2vector(&allitem), p);
|
2006-02-12 05:16:42 +03:00
|
|
|
}
|
|
|
|
|
2006-05-11 01:26:53 +04:00
|
|
|
return maxname;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
2006-03-23 00:54:23 +03:00
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-03-23 00:54:23 +03:00
|
|
|
int i;
|
|
|
|
XSetWindowAttributes wa;
|
2006-06-19 12:28:37 +04:00
|
|
|
char *maxname, *p;
|
2006-06-20 17:47:08 +04:00
|
|
|
BlitzFont font;
|
|
|
|
GC gc;
|
|
|
|
Drawable pmap;
|
2006-03-23 00:54:23 +03:00
|
|
|
XEvent ev;
|
|
|
|
|
|
|
|
/* command line args */
|
2006-05-25 00:10:54 +04:00
|
|
|
for(i = 1; i < argc; i++) {
|
|
|
|
if (argv[i][0] == '-')
|
|
|
|
switch (argv[i][1]) {
|
|
|
|
case 'v':
|
|
|
|
fprintf(stdout, "%s", version);
|
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if(++i < argc)
|
|
|
|
title = argv[i];
|
|
|
|
else
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
2006-03-23 00:54:23 +03:00
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
dpy = XOpenDisplay(0);
|
|
|
|
if(!dpy) {
|
|
|
|
fprintf(stderr, "%s", "wmiimenu: cannot open display\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
screen = DefaultScreen(dpy);
|
|
|
|
|
2006-05-11 01:26:53 +04:00
|
|
|
maxname = read_allitems();
|
|
|
|
|
|
|
|
/* grab as early as possible, but after reading all items!!! */
|
2006-05-03 15:07:14 +04:00
|
|
|
while(XGrabKeyboard
|
|
|
|
(dpy, RootWindow(dpy, screen), True, GrabModeAsync,
|
|
|
|
GrabModeAsync, CurrentTime) != GrabSuccess)
|
|
|
|
usleep(1000);
|
|
|
|
|
2006-03-23 00:54:23 +03:00
|
|
|
/* set font and colors */
|
2006-06-13 13:21:06 +04:00
|
|
|
blitz_x11_init(dpy);
|
2006-06-20 17:47:08 +04:00
|
|
|
|
|
|
|
font.fontstr = getenv("WMII_FONT");
|
|
|
|
if (!font.fontstr)
|
|
|
|
font.fontstr = strdup(BLITZ_FONT);
|
|
|
|
blitz_loadfont(&font);
|
2006-06-19 12:28:37 +04:00
|
|
|
|
|
|
|
if((p = getenv("WMII_NORMCOLORS")))
|
|
|
|
cext_strlcpy(normcolor.colstr, p, sizeof(normcolor.colstr));
|
|
|
|
if(strlen(normcolor.colstr) != 23)
|
|
|
|
cext_strlcpy(normcolor.colstr, BLITZ_NORMCOLORS, sizeof(normcolor.colstr));
|
|
|
|
blitz_loadcolor(&normcolor);
|
|
|
|
|
|
|
|
if((p = getenv("WMII_SELCOLORS")))
|
|
|
|
cext_strlcpy(selcolor.colstr, p, sizeof(selcolor.colstr));
|
|
|
|
if(strlen(selcolor.colstr) != 23)
|
|
|
|
cext_strlcpy(selcolor.colstr, BLITZ_SELCOLORS, sizeof(selcolor.colstr));
|
|
|
|
blitz_loadcolor(&selcolor);
|
2005-12-21 18:18:11 +03:00
|
|
|
|
2006-03-23 00:54:23 +03:00
|
|
|
wa.override_redirect = 1;
|
|
|
|
wa.background_pixmap = ParentRelative;
|
|
|
|
wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask
|
|
|
|
| SubstructureRedirectMask | SubstructureNotifyMask;
|
2005-12-21 18:18:11 +03:00
|
|
|
|
2006-05-25 00:10:54 +04:00
|
|
|
irect.width = DisplayWidth(dpy, screen);
|
2006-06-20 17:47:08 +04:00
|
|
|
irect.height = font.ascent + font.descent + 4;
|
2006-05-25 00:10:54 +04:00
|
|
|
irect.y = DisplayHeight(dpy, screen) - irect.height;
|
|
|
|
irect.x = 0;
|
|
|
|
|
2006-06-05 05:21:15 +04:00
|
|
|
win = XCreateWindow(dpy, RootWindow(dpy, screen), irect.x, irect.y,
|
|
|
|
irect.width, irect.height, 0, DefaultDepth(dpy, screen),
|
2006-03-23 00:54:23 +03:00
|
|
|
CopyFromParent, DefaultVisual(dpy, screen),
|
|
|
|
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
|
|
|
XDefineCursor(dpy, win, XCreateFontCursor(dpy, XC_xterm));
|
|
|
|
XSync(dpy, False);
|
|
|
|
|
|
|
|
/* pixmap */
|
2006-06-20 17:47:08 +04:00
|
|
|
gc = XCreateGC(dpy, win, 0, 0);
|
|
|
|
pmap = XCreatePixmap(dpy, win, irect.width, irect.height,
|
2006-03-23 00:54:23 +03:00
|
|
|
DefaultDepth(dpy, screen));
|
|
|
|
|
|
|
|
XSync(dpy, False);
|
2006-05-11 01:26:53 +04:00
|
|
|
|
2006-06-20 17:47:08 +04:00
|
|
|
draw = blitz_create_input(pmap, gc, &font);
|
2006-05-11 01:26:53 +04:00
|
|
|
if(maxname)
|
2006-06-20 17:47:08 +04:00
|
|
|
cwidth = blitz_textwidth(draw->font, maxname) + irect.height;
|
2006-06-05 05:50:48 +04:00
|
|
|
if(cwidth > irect.width / 3)
|
|
|
|
cwidth = irect.width / 3;
|
|
|
|
|
|
|
|
if(title) {
|
2006-06-20 17:47:08 +04:00
|
|
|
twidth = blitz_textwidth(draw->font, title) + irect.height;
|
2006-06-05 05:50:48 +04:00
|
|
|
if(twidth > irect.width / 3)
|
|
|
|
twidth = irect.width / 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdw = title ? twidth : cwidth;
|
2006-03-23 00:54:23 +03:00
|
|
|
|
|
|
|
text[0] = 0;
|
|
|
|
update_items(text);
|
|
|
|
XMapRaised(dpy, win);
|
|
|
|
draw_menu();
|
|
|
|
XSync(dpy, False);
|
|
|
|
|
|
|
|
/* main event loop */
|
|
|
|
while(!XNextEvent(dpy, &ev)) {
|
|
|
|
switch (ev.type) {
|
|
|
|
case KeyPress:
|
|
|
|
handle_kpress(&ev.xkey);
|
|
|
|
break;
|
|
|
|
case Expose:
|
|
|
|
if(ev.xexpose.count == 0) {
|
|
|
|
draw_menu();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-03-05 15:29:21 +03:00
|
|
|
if(done)
|
|
|
|
break;
|
2006-03-23 00:54:23 +03:00
|
|
|
}
|
2006-02-11 01:57:21 +03:00
|
|
|
|
2006-05-11 01:26:53 +04:00
|
|
|
XUngrabKeyboard(dpy, CurrentTime);
|
2006-06-20 17:47:08 +04:00
|
|
|
XFreePixmap(dpy, pmap);
|
|
|
|
XFreeGC(dpy, gc);
|
2006-02-12 05:16:42 +03:00
|
|
|
XDestroyWindow(dpy, win);
|
2006-03-23 00:54:23 +03:00
|
|
|
XCloseDisplay(dpy);
|
2005-12-21 18:18:11 +03:00
|
|
|
|
2006-03-23 00:54:23 +03:00
|
|
|
return ret;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|