removed wmiipsel, wmiisetsid, wmiiwarp (replaced with separate packages spsel, ssid, swarp)

This commit is contained in:
Anselm R. Garbe 2006-10-10 08:16:53 +02:00
parent af6974bdc8
commit 083302da16
12 changed files with 16 additions and 678 deletions

View File

@ -7,9 +7,8 @@ CFLAGS += -I../liblitz -I../libixp -I../libcext
LDFLAGS += -L../libixp -lixp -L../libcext -lcext
X11LDFLAGS += -L../liblitz -llitz -L../libcext -lcext
X11SRC = wmiipsel.c wmiiwarp.c
SRC = wmiir.c wmiisetsid.c
ALLSRC = ${SRC} ${X11SRC}
SRC = wmiir.c
ALLSRC = ${SRC}
all: ${ALLSRC:.c=}
@echo built wmii commands
@ -22,10 +21,6 @@ ${SRC:.c=}: ${SRC:.c=.o}
@echo LD $@
@${CC} -o $@ $@.o ${LDFLAGS}
${X11SRC:.c=}: ${X11SRC:.c=.o}
@echo LD $@
@${CC} -o $@ $@.o ${X11LDFLAGS}
# Solaris
# @${CC} -o $* $*.o ${LDFLAGS} -lsocket

View File

@ -336,10 +336,10 @@ frame_of_point(XPoint *pt)
if(!v)
return nil;
for(a=v->area->next; a && !blitz_ispointinrect(pt->x, pt->y, &a->rect);
for(a=v->area->next; a && !ispointinrect(pt->x, pt->y, &a->rect);
a=a->next);
if(a)
for(f=a->frame; f && !blitz_ispointinrect(pt->x, pt->y, &f->rect);
for(f=a->frame; f && !ispointinrect(pt->x, pt->y, &f->rect);
f=f->anext);
return f;
}
@ -358,7 +358,7 @@ drop_move(Frame *f, XRectangle *new, XPoint *pt)
if(!pt)
return;
for(tgt=v->area->next; tgt && !blitz_ispointinrect(pt->x, pt->y, &tgt->rect);
for(tgt=v->area->next; tgt && !ispointinrect(pt->x, pt->y, &tgt->rect);
tgt=tgt->next);
if(tgt) {
if(pt->x < 16) {

View File

@ -67,11 +67,11 @@ buttonrelease(XEvent *e)
XButtonPressedEvent *ev = &e->xbutton;
if(ev->window == screen->barwin) {
for(b=screen->lbar; b; b=b->next)
if(blitz_ispointinrect(ev->x, ev->y, &b->brush.rect))
if(ispointinrect(ev->x, ev->y, &b->brush.rect))
return write_event("LeftBarClick %d %s\n",
ev->button, b->name);
for(b=screen->rbar; b; b=b->next)
if(blitz_ispointinrect(ev->x, ev->y, &b->brush.rect))
if(ispointinrect(ev->x, ev->y, &b->brush.rect))
return write_event("RightBarClick %d %s\n",
ev->button, b->name);
}

View File

@ -7,6 +7,13 @@
#include "wm.h"
Bool
ispointinrect(int x, int y, XRectangle * r)
{
return (x >= r->x) && (x <= r->x + r->width)
&& (y >= r->y) && (y <= r->y + r->height);
}
BlitzAlign
quadofcoord(XRectangle *rect, int x, int y)
{

View File

@ -265,6 +265,7 @@ extern void fs_write(P9Req *r);
extern void write_event(char *format, ...);
/* geom.c */
extern Bool ispointinrect(int x, int y, XRectangle * r);
extern BlitzAlign quadofcoord(XRectangle *rect, int x, int y);
extern int strtorect(XRectangle *r, const char *val);

View File

@ -1,47 +0,0 @@
/*
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <blitz.h>
static char version[] = "wmiipsel - " VERSION ", (C)opyright MMIV-MMVI Anselm R. Garbe\n";
static void
usage()
{
fprintf(stderr, "%s\n", "usage: wmiipsel [-v]\n");
exit(1);
}
int
main(int argc, char **argv)
{
unsigned char *data;
unsigned long i, offset, len, remain;
/* command line args */
if(argc > 1) {
if(!strncmp(argv[1], "-v", 3)) {
fprintf(stdout, "%s", version);
exit(0);
} else
usage();
}
len = offset = remain = 0;
do {
data = blitz_getselection(offset, &len, &remain);
for(i = 0; i < len; i++)
putchar(data[i]);
offset += len;
free(data);
}
while(remain);
if(offset)
putchar('\n');
return 0;
}

View File

@ -1,49 +0,0 @@
/*
* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
static char version[] = "wmiisetsid - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
static void
usage()
{
fprintf(stderr, "%s", "usage: wmiisetsid [-v] cmd [arg ...]\n");
exit(1);
}
int
main(int argc, char *argv[])
{
/* command line args */
if(argc < 2)
usage();
else if(!strncmp(argv[1], "-v", 3)) {
fprintf(stdout, "%s", version);
exit(0);
}
if(getpgrp() == getpid()) {
switch(fork()){
case -1:
perror("wmiisetsid: fork");
exit(1);
case 0:
break;
default:
exit(0);
}
}
if(setsid() < 0) {
perror("wmiisetsid: setsid");
exit(1);
}
execvp(argv[1], argv + 1);
perror("wmiisetsid: execvp");
exit(1);
return 0;
}

View File

@ -1,49 +0,0 @@
/*
* (C)opyright MMIV-MMV Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <X11/Xlib.h>
#include <cext.h>
static char version[] = "wmiiwarp - " VERSION ", (C)opyright MMIV-MMV Anselm R. Garbe\n";
static void
usage()
{
fprintf(stderr, "%s", "usage: wmiiwarp <x> <y> [-v]\n");
exit(1);
}
int
main(int argc, char **argv)
{
Display *dpy;
int x, y;
/* command line args */
if((argc == 2) && !strncmp(argv[1], "-v", 2)) {
fprintf(stdout, "%s", version);
exit(0);
}
else if(argc != 3)
usage();
if(!(dpy = XOpenDisplay(0))) {
fprintf(stderr, "%s", "wmiiwarp: cannot open display\n");
exit(1);
}
if(sscanf(argv[1], "%d", &x) != 1)
usage();
if(sscanf(argv[2], "%d", &y) != 1)
usage();
XWarpPointer(dpy, None, RootWindow(dpy, DefaultScreen(dpy)), 0, 0, 0, 0, x, y);
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
XCloseDisplay(dpy);
return 0;
}

View File

@ -6,7 +6,7 @@ include ../config.mk
CFLAGS += -I../libixp -I../libcext
LDFLAGS += -L../libixp -lixp -L../libcext -lcext
SRC = blitz.c brush.c color.c draw.c font.c
SRC = brush.c color.c draw.c font.c
OBJ = ${SRC:.c=.o}
all: liblitz.a

View File

@ -1,89 +0,0 @@
/*
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include <string.h>
#include <cext.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include "blitz.h"
Bool
blitz_ispointinrect(int x, int y, XRectangle * r)
{
return (x >= r->x) && (x <= r->x + r->width)
&& (y >= r->y) && (y <= r->y + r->height);
}
void
blitz_selrequest(Blitz *blitz, XSelectionRequestEvent *rq, char *text)
{
/*
* PRECONDITION:
* 1. XSetSelectionOwner(blitz->dpy, XA_PRIMARY, w, CurrentTime);
* 2. Received SelectionRequest rq
*/
XEvent ev;
Atom target;
XTextProperty ct;
XICCEncodingStyle style;
char *cl[1];
ev.xselection.type = SelectionNotify;
ev.xselection.property = None;
ev.xselection.display = rq->display;
ev.xselection.requestor = rq->requestor;
ev.xselection.selection = rq->selection;
ev.xselection.target = rq->target;
ev.xselection.time = rq->time;
if (rq->target == XA_STRING) {
style = XStringStyle;
target = XA_STRING;
}
cl[0] = text;
XmbTextListToTextProperty(blitz->dpy, cl, 1, style, &ct);
XChangeProperty(blitz->dpy, rq->requestor, rq->property,
target, 8, PropModeReplace, ct.value, ct.nitems);
ev.xselection.property = rq->property;
XSendEvent(blitz->dpy, rq->requestor, False, 0, &ev);
}
unsigned char *
blitz_getselection(unsigned long offset, unsigned long *len, unsigned long *remain)
{
Display *dpy;
Atom xa_clip_string;
Window w;
XEvent ev;
Atom typeret;
int format;
unsigned char *data;
unsigned char *result = nil;
dpy = XOpenDisplay(nil);
if(!dpy)
return nil;
xa_clip_string = XInternAtom(dpy, "BLITZ_SEL_STRING", False);
w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 200, 200,
1, CopyFromParent, CopyFromParent);
XConvertSelection(dpy, XA_PRIMARY, XA_STRING, xa_clip_string,
w, CurrentTime);
XFlush(dpy);
XNextEvent(dpy, &ev);
if(ev.type == SelectionNotify && ev.xselection.property != None) {
XGetWindowProperty(dpy, w, ev.xselection.property, offset, 4096L, False,
AnyPropertyType, &typeret, &format, len, remain, &data);
if(*len) {
result = cext_emallocz(sizeof(unsigned char) * *len);
memcpy(result, data, *len);
}
XDeleteProperty(dpy, w, ev.xselection.property);
}
XDestroyWindow(dpy, w);
XCloseDisplay(dpy);
return result;
}

View File

@ -65,11 +65,6 @@ struct BlitzBrush {
XRectangle rect; /* relative rect */
};
/* blitz.c */
extern unsigned char *blitz_getselection(unsigned long offset,
unsigned long *len, unsigned long *remain);
extern void blitz_selrequest(Blitz *blitz, XSelectionRequestEvent *rq, char *text);
/* brush.c */
extern void blitz_draw_label(BlitzBrush *b, char *text);
extern void blitz_draw_tile(BlitzBrush *b);

View File

@ -1,426 +0,0 @@
/*
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cext.h>
#include <X11/keysym.h>
#include <X11/Xutil.h>
#include "blitz.h"
static void
xchangegc(BlitzInput *i, BlitzColor c)
{
XGCValues gcv;
gcv.foreground = c.fg;
gcv.background = c.bg;
if(i->font->set)
XChangeGC(i->blitz->dpy, i->gc, GCForeground | GCBackground, &gcv);
else {
gcv.font = i->font->xfont->fid;
XChangeGC(i->blitz->dpy, i->gc, GCForeground | GCBackground | GCFont, &gcv);
}
}
static void
xdrawtextpart(BlitzInput *i, char *start, char *end,
unsigned int *xoff, unsigned int yoff)
{
unsigned int len;
if(!start || !(len = end - start))
return;
if(i->font->set)
XmbDrawImageString(i->blitz->dpy, i->drawable, i->font->set, i->gc,
*xoff, yoff, start, len);
else
XDrawImageString(i->blitz->dpy, i->drawable, i->gc, *xoff, yoff,
start, len);
*xoff += blitz_textwidth_l(i->font, start, len);
}
static void
setcursor(BlitzInput *i, Cursor cur)
{
XDefineCursor(i->blitz->dpy, i->win, cur);
i->cursor = cur;
}
void
blitz_setinput(BlitzInput *i, char *text)
{
if(!text) {
if(i->size) {
i->len = 0;
i->text[i->len] = 0;
i->curstart = i->curend = i->text;
}
return;
}
i->len = strlen(text);
if(i->len + 1 > i->size) {
i->size = 2 * i->len + 1;
i->text = cext_erealloc(i->text, i->size);
}
memcpy(i->text, text, i->len);
i->text[i->len] = 0;
i->curstart = i->curend = i->text + i->len;
}
static char *
curend(BlitzInput *i)
{
if(i->curstart < i->curend)
return i->curend;
else
return i->curstart;
}
static char *
curstart(BlitzInput *i)
{
if(i->curstart < i->curend)
return i->curstart;
else
return i->curend;
}
void
blitz_draw_input(BlitzInput *i)
{
char *start, *end;
unsigned int xoff, yoff, xcursor, h;
if (!i)
return;
blitz_drawbg(i->blitz->dpy, i->drawable, i->gc, i->rect, i->color, True);
h = (i->font->ascent + i->font->descent);
yoff = i->rect.y + (i->rect.height - h) / 2 + i->font->ascent;
xcursor = xoff = i->rect.x + i->font->height / 2;
start = curstart(i);
end = curend(i);
/* draw normal text */
xchangegc(i, i->color);
xdrawtextpart(i, i->text, start, &xoff, yoff);
xcursor = xoff;
/* draw sel text */
xchangegc(i, i->bcolor[i->button]);
xdrawtextpart(i, start, end, &xoff, yoff);
/* draw remaining normal text */
xchangegc(i, i->color);
xdrawtextpart(i, end, i->text + i->len, &xoff, yoff);
/* draw cursor */
if(!start && !end)
xcursor = xoff;
if(start == end)
blitz_drawcursor(i->blitz->dpy, i->drawable, i->gc,
xcursor, yoff - h + 2, h - 1, i->color);
}
Bool
blitz_ispointinrect(int x, int y, XRectangle * r)
{
return (x >= r->x) && (x <= r->x + r->width)
&& (y >= r->y) && (y <= r->y + r->height);
}
static char *
xcharof(BlitzInput *i, int x, char *start, unsigned int len)
{
unsigned int tw;
while((len /= 2)) {
tw = blitz_textwidth_l(i->font, start, len);
if(x >= tw) {
x -= tw;
start += len;
len = strlen(start);
}
}
return start; /* found */
}
static char *
charof(BlitzInput *i, int x, int y)
{
if(!i->text || !blitz_ispointinrect(x, y, &i->rect))
return nil;
/* normalize and check x */
if((x -= (i->rect.x + i->font->height / 2)) < 0)
return i->text;
else if(x > blitz_textwidth_l(i->font, i->text, i->len))
return i->text + i->len;
return xcharof(i, x, i->text, i->len);
}
void
xdraw(BlitzInput *i)
{
if(i->aux && i->draw)
i->draw(i->aux);
}
void
blitz_bpress_input(BlitzInput *i, int button, int x, int y)
{
char *ostart, *oend;
if(blitz_ispointinrect(x, y, &i->rect)) {
i->drag = True;
setcursor(i, i->input);
}
else {
setcursor(i, i->def);
return;
}
XSetInputFocus(i->blitz->dpy, i->win,
RevertToPointerRoot, CurrentTime);
ostart = i->curstart;
oend = i->curend;
i->curstart = i->curend = charof(i, x, y);
if((i->button = button - Button1) > 2)
i->button = 0;
if((i->curstart != ostart) || (i->curend != oend))
xdraw(i);
if(XGrabPointer(i->blitz->dpy, i->win, False,
ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
GrabModeAsync, GrabModeAsync, None,
i->cursor, CurrentTime) != GrabSuccess)
return;
}
static void
mark(BlitzInput *i, int x, int y)
{
char *start, *end;
start = curstart(i);
end = curend(i);
if(!start)
return;
if(start != end) {
i->curstart = i->curend = charof(i, x, y);
return;
}
if(start == i->text + i->len) {
/* mark everything */
i->curstart = i->text;
i->curend = i->text + i->len;
return;
}
if(*start == ' ' && start > i->text && *(start - 1) != ' ')
start = --end;
while(start > i->text && *(start - 1) != ' ')
start--;
while(*end && *end != ' ')
end++;
i->curstart = start;
i->curend = end;
}
void
blitz_brelease_input(BlitzInput *i, int button, int x, int y, unsigned long time)
{
char *oend;
if(!blitz_ispointinrect(x, y, &i->rect))
goto Drop;
XSetInputFocus(i->blitz->dpy, i->win,
RevertToPointerRoot, CurrentTime);
oend = i->curend;
if((i->button = button - Button1) > 2)
i->button = 0;
if(!i->button && (time - i->tdbclk < 1000)
&& (x == i->xdbclk && y == i->ydbclk))
{
mark(i, x, y);
i->tdbclk = 0;
i->xdbclk = i->ydbclk = 0;
goto Drop;
}
i->curend = charof(i, x, y);
i->tdbclk = time;
i->xdbclk = x;
i->ydbclk = y;
Drop:
XUngrabPointer(i->blitz->dpy, CurrentTime);
i->drag = False;
if(i->button)
i->curstart = i->curend;
setcursor(i, i->def);
xdraw(i);
}
void
blitz_bmotion_input(BlitzInput *i, int x, int y)
{
char *oend;
if(blitz_ispointinrect(x, y, &i->rect)) {
setcursor(i, i->input);
XSetInputFocus(i->blitz->dpy, i->win,
RevertToPointerRoot, CurrentTime);
}
else {
setcursor(i, i->def);
return;
}
if(!i->drag)
return;
oend = i->curend;
i->curend = charof(i, x, y);
if(i->curend != oend)
xdraw(i);
}
static void
delete(BlitzInput *i, char *start, char *end)
{
if(!start)
return;
else if((start == end) && (start != i->text)) {
i->curstart = i->curend = --start;
memmove(start, start + 1, strlen(start + 1));
i->len--;
}
else {
i->curstart = i->curend = start;
memmove(start, end, strlen(end));
i->len -= (end - start);
}
i->text[i->len] = 0;
}
static void
insert(BlitzInput *i, char *start, char *end, char *text)
{
unsigned int len;
int s, e;
if(!(len = strlen(text)))
return;
if(!start) {
blitz_setinput(i, text);
return;
}
i->len = i->len - (end - start) + len;
if(i->len + 1 > i->size) {
s = start - i->text;
e = end - i->text;
i->size = 2 * i->len + 1;
i->text = cext_erealloc(i->text, i->size);
start = i->text + s;
end = i->text + e;
}
memmove(start + len, end, strlen(end));
memcpy(start, text, len);
i->curstart = i->curend = start + len;
i->text[i->len] = 0;
}
void
blitz_kpress_input(BlitzInput *i, unsigned long mod, KeySym k, char *text)
{
char *start, *end;
start = curstart(i);
end = curend(i);
if(mod & ControlMask) {
switch (k) {
default: /* ignore other control sequences */
return;
case XK_A:
case XK_a:
k = XK_Begin;
break;
case XK_E:
case XK_e:
k = XK_End;
break;
case XK_H:
case XK_h:
k = XK_BackSpace;
break;
case XK_U:
case XK_u:
k = XK_BackSpace;
start = i->text;
break;
case XK_W:
case XK_w:
k = XK_BackSpace;
while(start > i->text && (*(--start) == ' '));
while(start > i->text && (*(start - 1) != ' '))
--start;
break;
}
}
if(IsCursorKey(k)) {
switch(k) {
case XK_Begin:
i->curstart = i->curend = i->text;
goto Draw;
case XK_End:
i->curstart = i->curend = i->text + i->len;
goto Draw;
case XK_Left:
if(start != end)
i->curstart = i->curend = start;
else if(start > i->text)
i->curstart = i->curend = --start;
else
i->curstart = i->curend = i->text;
goto Draw;
case XK_Right:
if(start != end)
i->curstart = i->curend = end;
else if(start < i->text + i->len)
i->curstart = i->curend = ++start;
else
i->curstart = i->curend = i->text + i->len;
goto Draw;
}
}
else {
switch(k) {
default:
insert(i, start, end, text);
break;
case XK_BackSpace:
delete(i, start, end);
}
}
Draw:
xdraw(i);
}