changeset: 2684:660b8c88382c
tag: tip
user: Kris Maglione <kris_AT_suckless.org>
date: Tue Jun 01 20:09:25 2010 -0400
files: cmd/menu/fns.h cmd/menu/main.c cmd/tray/main.c cmd/tray/selection.c cmd/tray/tray.c cmd/tray/xembed.c cmd/wmii/bar.c cmd/wmii/layout.c cmd/wmii/mouse.c cmd/wmii/xdnd.c cmd/wmii9menu.c include/stuff/geom.h include/stuff/x11.h lib/libstuff/Makefile lib/libstuff/geom/rect_haspoint_p.c lib/libstuff/map.c lib/libstuff/printevent.c lib/libstuff/x11/colors/loadcolor.c lib/libstuff/x11/drawing/drawstring.c lib/libstuff/x11/initdisplay.c lib/libstuff/x11/keys/keycode.c lib/libstuff/x11/properties/changeprop_char.c lib/libstuff/x11/properties/changeprop_long.c lib/libstuff/x11/properties/changeprop_short.c lib/libstuff/x11/properties/changeprop_string.c lib/libstuff/x11/properties/changeprop_textlist.c lib/libstuff/x11/properties/changeprop_ulong.c lib/libstuff/x11/properties/changeproperty.c lib/libstuff/x11/properties/delproperty.c lib/libstuff/x11/properties/getprop.c lib/libstuff/x11/properties/getprop_long.c lib/libstuff/x11/properties/getprop_string.c lib/libstuff/x11/properties/getprop_ulong.c lib/
libstuff/x11/sendmessage.c lib/libstuff/x11/text/loadfont.c lib/libstuff/x11/text/textextents_l.c lib/libstuff/x11/text/textwidth.c lib/libstuff/x11/text/textwidth_l.c lib/libstuff/x11/windows/destroywindow.c lib/libstuff/x11/x11.h lib/libstuff/x11/xatom.c
description:
[witray] Add partial DND proxy.
diff -r d99dfc382e65 -r 660b8c88382c cmd/menu/fns.h
--- a/cmd/menu/fns.h Mon May 31 13:26:51 2010 +0200
+++ b/cmd/menu/fns.h Tue Jun 01 20:09:25 2010 -0400
@@ -1,9 +1,3 @@
-
-void check_x_event(IxpConn*);
-void dispatch_event(XEvent*);
-uint flushenterevents(void);
-uint flushevents(long, bool);
-void xtime_kludge(void);
/* caret.c */
void caret_delete(int, int);
@@ -32,19 +26,3 @@
char** find_key(char*, long);
int getsym(char*);
-/* geom.c */
-Align get_sticky(Rectangle src, Rectangle dst);
-Cursor quad_cursor(Align);
-Align quadrant(Rectangle, Point);
-bool rect_contains_p(Rectangle, Rectangle);
-bool rect_haspoint_p(Point, Rectangle);
-bool rect_intersect_p(Rectangle, Rectangle);
-Rectangle rect_intersection(Rectangle, Rectangle);
-
-/* xext.c */
-void randr_event(XEvent*);
-bool render_argb_p(Visual*);
-void xext_event(XEvent*);
-void xext_init(void);
-Rectangle* xinerama_screens(int*);
-
diff -r d99dfc382e65 -r 660b8c88382c cmd/menu/main.c
--- a/cmd/menu/main.c Mon May 31 13:26:51 2010 +0200
+++ b/cmd/menu/main.c Tue Jun 01 20:09:25 2010 -0400
@@ -167,7 +167,7 @@
*/
p = querypointer(&scr.root);
for(i=0; i < n; i++)
- if(rect_haspoint_p(p, rects[i]))
+ if(rect_haspoint_p(rects[i], p))
break;
if(i == n)
i = 0;
diff -r d99dfc382e65 -r 660b8c88382c cmd/tray/main.c
--- a/cmd/tray/main.c Mon May 31 13:26:51 2010 +0200
+++ b/cmd/tray/main.c Tue Jun 01 20:09:25 2010 -0400
@@ -78,7 +78,7 @@
USED(s);
- Dprint("message(%s) 0x%lx\n", XGetAtomName(display, ev->message_type), ev->window);
+ Dprint("message(%A) 0x%lx\n", ev->message_type, ev->window);
Dprint("\t0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx\n",
ev->data.l[0], ev->data.l[1], ev->data.l[2], ev->data.l[3], ev->data.l[4]);
diff -r d99dfc382e65 -r 660b8c88382c cmd/tray/selection.c
--- a/cmd/tray/selection.c Mon May 31 13:26:51 2010 +0200
+++ b/cmd/tray/selection.c Tue Jun 01 20:09:25 2010 -0400
@@ -123,7 +123,7 @@
if(ev->target == xatom("TIMESTAMP")) {
/* Per ICCCM §2.6.2. */
changeprop_ulong(window(ev->requestor),
- XGetAtomName(display, ev->property), "TIMESTAMP",
+ atomname(ev->property), "TIMESTAMP",
&s->time_start, 1);
selection_notify(s, ev, true);
return false;
diff -r d99dfc382e65 -r 660b8c88382c cmd/tray/tray.c
--- a/cmd/tray/tray.c Mon May 31 13:26:51 2010 +0200
+++ b/cmd/tray/tray.c Tue Jun 01 20:09:25 2010 -0400
@@ -3,6 +3,7 @@
*/
#include "dat.h"
#include <string.h>
+#include <strings.h>
#include "fns.h"
static Handlers handlers;
@@ -69,28 +70,20 @@
| SubstructureNotifyMask
/* Disallow clients reconfiguring themselves. */
| SubstructureRedirectMask;
- if(true)
- tray.win = createwindow(&scr.root, Rect(0, 0, 1, 1), scr.depth, InputOutput,
- &wa, CWBackPixmap
- | CWBitGravity
- | CWEventMask);
- else {
- wa.colormap = XCreateColormap(display, scr.root.xid, scr.visual32, AllocNone);
- tray.win = createwindow_visual(&scr.root, Rect(0, 0, 1, 1), 32, scr.visual32, InputOutput,
- &wa, CWBackPixmap
- | CWBorderPixel
- | CWColormap
- | CWBitGravity
- | CWEventMask);
- XFreeColormap(display, wa.colormap);
- }
+ tray.win = createwindow(&scr.root, Rect(0, 0, 1, 1), scr.depth, InputOutput,
+ &wa, CWBackPixmap
+ | CWBitGravity
+ | CWEventMask);
sethandler(tray.win, &handlers);
pushhandler(&scr.root, &root_handlers, nil);
selectinput(&scr.root, scr.root.eventmask | PropertyChangeMask);
+
changeprop_string(tray.win, "_WMII_TAGS", tray.tags);
+ changeprop_ulong(tray.win, "XdndAware", "ATOM", (ulong[1]){ 5 }, 1);
+
changeprop_ulong(tray.selection->owner, Net("SYSTEM_TRAY_VISUAL"), "VISUALID",
&scr.visual->visualid, 1);
changeprop_long(tray.win, Net("WM_WINDOW_TYPE"), "ATOM",
@@ -250,11 +243,152 @@
return false;
}
+typedef struct Dnd Dnd;
+
+struct Dnd {
+ ulong source;
+ ulong dest;
+ long data[4];
+ Point p;
+ bool have_actions;
+};
+
+static Dnd dnd;
+
+#define Point(l) Pt((ulong)(l) >> 16, (ulong)(l) & 0xffff)
+#define Long(p) ((long)(((ulong)(p).x << 16) | (ulong)(p).y))
+#define sendmessage(...) BLOCK( \
+ Dprint("(%W) %s 0x%ulx, 0x%ulx, 0x%ulx, 0x%ulx, 0x%ulx\n", __VA_ARGS__); \
+ sendmessage(__VA_ARGS__); \
+ )
+
+static void
+dnd_updatestatus(ulong dest) {
+ if(dest == dnd.dest)
+ return;
+
+ if(dnd.dest && dnd.dest != ~0UL)
+ sendmessage(window(dnd.dest), "XdndLeave", tray.win->xid, 0, 0, 0, 0);
+ dnd.dest = dest;
+ if(dest)
+ sendmessage(window(dest), "XdndEnter", tray.win->xid,
+ dnd.data[0], dnd.data[1], dnd.data[2], dnd.data[3]);
+ else
+ sendmessage(window(dnd.source), "XdndStatus", tray.win->xid, (1<<1),
+ Long(tray.win->r.min), (Dx(tray.win->r)<<16) | Dy(tray.win->r), 0UL);
+}
+
+static void
+copyprop_long(Window *src, Window *dst, char *atom, char *type, long max) {
+ long *data;
+ long n;
+
+ /* Round trip. Really need to switch to XCB. */
+ if((n = getprop_long(src, atom, type, 0, &data, max)))
+ changeprop_long(dst, atom, type, data, n);
+ free(data);
+}
+
+static void
+copyprop_char(Window *src, Window *dst, char *atom, char *type, long max) {
+ uchar *data;
+ ulong actual, n;
+ int format;
+
+ n = getprop(src, atom, type, &actual, &format, 0, &data, max);
+ if(n > 0 && format == 8 && xatom(type) == actual)
+ changeprop_char(dst, atom, type, (char*)data, n);
+ free(data);
+}
+
static bool
-message_event(Window *w, void *aux, XClientMessageEvent *ev) {
+message_event(Window *w, void *aux, XClientMessageEvent *e) {
+ Client *c;
+ long *l;
+ Rectangle r;
+ Point p;
+ ulong msg;
- Dprint("tray_message: %s\n", XGetAtomName(display, ev->message_type));
- return false;
+ msg = e->message_type;
+ l = e->data.l;
+ Dprint("ClientMessage: %A\n", msg);
+ if(e->format == 32)
+ Dprint("\t0x%ulx, 0x%ulx, 0x%ulx, 0x%ulx, 0x%ulx\n",
+ l[0], l[1], l[2], l[3], l[4]);
+
+ if(msg == xatom("XdndEnter")) {
+ if(e->format != 32)
+ return false;
+ dnd = (Dnd){0};
+ dnd.source = l[0];
+ bcopy(&l[1], dnd.data, sizeof dnd.data);
+
+ copyprop_long(window(dnd.source), tray.win, "XdndSelection", "ATOM", 128);
+ if(l[1] & 0x01)
+ copyprop_long(window(dnd.source), tray.win, "XdndTypeList", "ATOM", 128);
+ return false;
+ }else
+ if(msg == xatom("XdndLeave")) {
+ if(e->format != 32)
+ return false;
+ dnd.source = 0UL;
+ if(dnd.dest)
+ sendmessage(window(dnd.dest), "XdndLeave", tray.win->xid, l[1], 0, 0, 0);
+ return false;
+ }else
+ if(msg == xatom("XdndPosition")) {
+ if(e->format != 32)
+ return false;
+
+ if(!dnd.have_actions && l[4] == xatom("XdndActionAsk")) {
+ dnd.have_actions = true;
+ copyprop_long(window(dnd.source), tray.win, "XdndActionList", "ATOM", 16);
+ copyprop_char(window(dnd.source), tray.win, "XdndActionDescription", "ATOM", 16 * 32);
+ }
+
+ dnd.p = subpt(Point(l[2]), tray.win->r.min);
+ for(c=tray.clients; c; c=c->next)
+ if(rect_haspoint_p(c->w.r, dnd.p)) {
+ dnd_updatestatus(c->w.xid);
+ sendmessage(&c->w, "XdndPosition", tray.win->xid, l[1], l[2], l[3], l[4]);
+ return false;
+ }
+ dnd_updatestatus(0UL);
+ return false;
+ }else
+ if(msg == xatom("XdndStatus")) {
+ if(e->format != 32)
+ return false;
+ if(l[0] != dnd.dest)
+ return false;
+
+ for(c=tray.clients; c; c=c->next)
+ if(c->w.xid == dnd.dest) {
+ p = Point(l[2]);
+ r = Rpt(p, addpt(p, Point(l[3])));
+ r = rect_intersection(r, rectaddpt(c->w.r, tray.win->r.min));
+
+ sendmessage(window(dnd.source), "XdndStatus", tray.win->xid, l[1],
+ Long(r.min), (Dx(r)<<16) | Dy(r), l[4]);
+ break;
+ }
+
+ return false;
+ }else
+ if(msg == xatom("XdndDrop") || msg == xatom("XdndFinished")) {
+ if(e->format != 32)
+ return false;
+
+ for(c=tray.clients; c; c=c->next)
+ if(c->w.xid == dnd.dest) {
+ sendmessage(&c->w, atomname(msg),
+ tray.win->xid, l[1], l[2], 0L, 0L);
+ break;
+ }
+ return false;
+ }
+
+ return true;
}
static Handlers handlers = {
diff -r d99dfc382e65 -r 660b8c88382c cmd/tray/xembed.c
--- a/cmd/tray/xembed.c Mon May 31 13:26:51 2010 +0200
+++ b/cmd/tray/xembed.c Tue Jun 01 20:09:25 2010 -0400
@@ -106,8 +106,8 @@
property_event(Window *w, void *aux, XPropertyEvent *ev) {
XEmbed *xembed;
- Dprint("property_event(%W, %p, %s)\n",
- w, aux, XGetAtomName(display, ev->atom));
+ Dprint("property_event(%W, %p, %A)\n",
+ w, aux, ev->atom);
xembed = aux;
if(ev->atom == xatom("_XEMBED_INFO"))
xembed_updateinfo(xembed);
diff -r d99dfc382e65 -r 660b8c88382c cmd/wmii/bar.c
--- a/cmd/wmii/bar.c Mon May 31 13:26:51 2010 +0200
+++ b/cmd/wmii/bar.c Tue Jun 01 20:09:25 2010 -0400
@@ -244,7 +244,7 @@
Bar *b;
foreach_bar(s, b)
- if(rect_haspoint_p(p, b->r))
+ if(rect_haspoint_p(b->r, p))
return b;
return nil;
}
diff -r d99dfc382e65 -r 660b8c88382c cmd/wmii/layout.c
--- a/cmd/wmii/layout.c Mon May 31 13:26:51 2010 +0200
+++ b/cmd/wmii/layout.c Tue Jun 01 20:09:25 2010 -0400
@@ -132,7 +132,7 @@
v = selview;
for(s=0; s < nscreens; s++) {
- if(!rect_haspoint_p(pt, screens[s]->r))
+ if(!rect_haspoint_p(screens[s]->r, pt))
continue;
for(a=v->areas[s]; a; a=a->next)
if(pt.x < a->r.max.x)
diff -r d99dfc382e65 -r 660b8c88382c cmd/wmii/mouse.c
--- a/cmd/wmii/mouse.c Mon May 31 13:26:51 2010 +0200
+++ b/cmd/wmii/mouse.c Tue Jun 01 20:09:25 2010 -0400
@@ -603,14 +603,14 @@
int q;
cur = cursor[CurNormal];
- if(rect_haspoint_p(p, f->crect)) {
+ if(rect_haspoint_p(f->crect, p)) {
client_setcursor(f->client, cur);
return;
}
r = rectsubpt(f->r, f->r.min);
q = quadrant(r, p);
- if(rect_haspoint_p(p, f->grabbox)) {
+ if(rect_haspoint_p(f->grabbox, p)) {
cur = cursor[CurTCross];
if(exec)
mouse_movegrabbox(f->client, false);
@@ -624,7 +624,7 @@
if(exec)
mouse_resize(f->client, q, false);
}
- else if(exec && rect_haspoint_p(p, f->titlebar))
+ else if(exec && rect_haspoint_p(f->titlebar, p))
mouse_movegrabbox(f->client, true);
}else {
if(f->aprev && p.y <= 2
diff -r d99dfc382e65 -r 660b8c88382c cmd/wmii/xdnd.c
--- a/cmd/wmii/xdnd.c Mon May 31 13:26:51 2010 +0200
+++ b/cmd/wmii/xdnd.c Tue Jun 01 20:09:25 2010 -0400
@@ -65,7 +65,7 @@
p = subpt(p, w->r.min);
Dprint(DDnd, "\tw: %W\n", w);
Dprint(DDnd, "\tp: %P\n", p);
- if(eqrect(dnd->r, ZR) || !rect_haspoint_p(p, dnd->r))
+ if(eqrect(dnd->r, ZR) || !rect_haspoint_p(dnd->r, p))
if(w->handler->dndmotion)
dnd->r = w->handler->dndmotion(w, w->aux, p);
r = dnd->r;
diff -r d99dfc382e65 -r 660b8c88382c cmd/wmii9menu.c
--- a/cmd/wmii9menu.c Mon May 31 13:26:51 2010 +0200
+++ b/cmd/wmii9menu.c Tue Jun 01 20:09:25 2010 -0400
@@ -46,7 +46,7 @@
#include <stuff/clientutil.h>
#include <stuff/util.h>
-#include <stuff/x11.h>
+#include <stuff/x.h>
char version[] = "wmii9menu-"VERSION" "COPYRIGHT", ©1994 David Hogan, Arnold Robbins";
@@ -81,12 +81,6 @@
void memory(void);
int args(void);
-/* xext.c */
-void xext_init(void);
-Rectangle* xinerama_screens(int*);
-/* geom.c */
-bool rect_haspoint_p(Point, Rectangle);
-
Cursor cursor[1];
Visual* render_visual;
@@ -100,7 +94,7 @@
rects = xinerama_screens(&n);
p = querypointer(&scr.root);
for(i=0; i < n; i++) {
- if(rect_haspoint_p(p, rects[i]))
+ if(rect_haspoint_p(rects[i], p))
break;
}
if(i == n)
diff -r d99dfc382e65 -r 660b8c88382c include/stuff/geom.h
--- a/include/stuff/geom.h Mon May 31 13:26:51 2010 +0200
+++ b/include/stuff/geom.h Tue Jun 01 20:09:25 2010 -0400
@@ -48,7 +48,7 @@
Align get_sticky(Rectangle src, Rectangle dst);
Align quadrant(Rectangle, Point);
bool rect_contains_p(Rectangle, Rectangle);
-bool rect_haspoint_p(Point, Rectangle);
+bool rect_haspoint_p(Rectangle, Point);
bool rect_intersect_p(Rectangle, Rectangle);
Rectangle rect_intersection(Rectangle, Rectangle);
diff -r d99dfc382e65 -r 660b8c88382c include/stuff/x11.h
--- a/include/stuff/x11.h Mon May 31 13:26:51 2010 +0200
+++ b/include/stuff/x11.h Tue Jun 01 20:09:25 2010 -0400
@@ -168,8 +168,8 @@
XftFont* (*fontopen)(Display*, int, const char*);
XftFont* (*fontopenname)(Display*, int, const char*);
XftFont* (*fontclose)(Display*, XftFont*);
- void (*textextents)(Display*, XftFont*, char*, int len, XGlyphInfo*);
- void (*drawstring)(Display*, XftColor*, XftFont*, int x, int y, char*, int len);
+ void (*textextents)(Display*, XftFont*, const char*, int len, XGlyphInfo*);
+ void (*drawstring)(Display*, XftColor*, XftFont*, int x, int y, const char*, int len);
};
struct XftColor {
@@ -212,6 +212,7 @@
extern struct Map windowmap;
extern struct Map atommap;
+extern struct Map atomnamemap;
extern const Point ZP;
extern const Rectangle ZR;
extern const WinHints ZWinHints;
@@ -228,24 +229,25 @@
/* x11.c */
XRectangle XRect(Rectangle);
Image* allocimage(int w, int h, int depth);
+char* atomname(ulong);
void border(Image *dst, Rectangle, int w, Color);
-void changeprop_char(Window*, char*, char*, char[], int);
-void changeprop_long(Window*, char*, char*, long[], int);
-void changeprop_short(Window*, char*, char*, short[], int);
-void changeprop_string(Window*, char*, char*);
-void changeprop_textlist(Window*, char*, char*, char*[]);
-void changeprop_ulong(Window*, char*, char*, ulong[], int);
-void changeproperty(Window*, char*, char*, int width, uchar*, int);
-void clientmessage(Window*, char*, long, int, ClientMessageData);
+void changeprop_char(Window*, const char*, const char*, const char*, int);
+void changeprop_long(Window*, const char*, const char*, long[], int);
+void changeprop_short(Window*, const char*, const char*, short[], int);
+void changeprop_string(Window*, const char*, const char*);
+void changeprop_textlist(Window*, const char*, const char*, char*[]);
+void changeprop_ulong(Window*, const char*, const char*, ulong[], int);
+void changeproperty(Window*, const char*, const char*, int width, const uchar*, int);
+void clientmessage(Window*, const char*, long, int, ClientMessageData);
void copyimage(Image*, Rectangle, Image*, Point);
Window* createwindow(Window*, Rectangle, int depth, uint class, WinAttr*, int valuemask);
void cleanupwindow(Window*);
Window* createwindow_visual(Window*, Rectangle, int depth, Visual*, uint class, WinAttr*, int);
-void delproperty(Window*, char*);
+void delproperty(Window*, const char*);
void destroywindow(Window*);
void drawline(Image*, Point, Point, int cap, int w, Color);
void drawpoly(Image*, Point*, int, int cap, int w, Color);
-uint drawstring(Image*, Font*, Rectangle, Align, char*, Color);
+uint drawstring(Image*, Font*, Rectangle, Align, const char*, Color);
void fill(Image*, Rectangle, Color);
void fillpoly(Image*, Point*, int, Color);
Window* findwin(XWindow);
@@ -254,20 +256,21 @@
void freestringlist(char**);
XWindow getfocus(void);
void gethints(Window*);
-ulong getprop_long(Window*, char*, char*, ulong, long**, ulong);
-char* getprop_string(Window*, char*);
-int getprop_textlist(Window *w, char *name, char **ret[]);
-ulong getprop_ulong(Window*, char*, char*, ulong, ulong**, ulong);
+ulong getprop(Window*, const char*, const char*, Atom*, int*, ulong, uchar**, ulong);
+ulong getprop_long(Window*, const char*, const char*, ulong, long**, ulong);
+char* getprop_string(Window*, const char*);
+int getprop_textlist(Window *w, const char *name, char **ret[]);
+ulong getprop_ulong(Window*, const char*, const char*, ulong, ulong**, ulong);
ulong getproperty(Window*, char *prop, char *type, Atom *actual, ulong offset, uchar **ret, ulong length);
Rectangle getwinrect(Window*);
int grabkeyboard(Window*);
int grabpointer(Window*, Window *confine, Cursor, int mask);
bool havexft(void);
void initdisplay(void);
-KeyCode keycode(char*);
+KeyCode keycode(const char*);
uint labelh(Font*);
-bool loadcolor(CTuple*, char*);
-Font* loadfont(char*);
+bool loadcolor(CTuple*, const char*);
+Font* loadfont(const char*);
void lowerwin(Window*);
int mapwin(Window*);
void movewin(Window*, Point);
@@ -282,7 +285,7 @@
void reshapewin(Window*, Rectangle);
void selectinput(Window*, long);
void sendevent(Window*, bool propagate, long mask, void*);
-void sendmessage(Window*, char*, long, long, long, long, long);
+void sendmessage(Window*, const char*, long, long, long, long, long);
void setborder(Window*, int, Color);
void setfocus(Window*, int mode);
Handlers* sethandler(Window*, Handlers*);
@@ -292,9 +295,9 @@
Rectangle sizehint(WinHints*, Rectangle);
char** strlistdup(char**);
void sync(void);
-Rectangle textextents_l(Font*, char*, uint, int*);
-uint textwidth(Font*, char*);
-uint textwidth_l(Font*, char*, uint len);
+Rectangle textextents_l(Font*, const char*, uint, int*);
+uint textwidth(Font*, const char*);
+uint textwidth_l(Font*, const char*, uint len);
Point translate(Window*, Window*, Point);
int traperrors(bool);
void ungrabkeyboard(void);
@@ -304,5 +307,5 @@
Window* window(XWindow);
char* windowname(Window*);
long winprotocols(Window*);
-Atom xatom(char*);
+Atom xatom(const char*);
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/Makefile
--- a/lib/libstuff/Makefile Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/Makefile Tue Jun 01 20:09:25 2010 -0400
@@ -144,7 +144,6 @@
x11/properties/getprop_long \
x11/properties/getprop_string \
x11/properties/getprop_textlist \
- x11/properties/getprop_ulong \
x11/properties/getproperty \
x11/properties/strlistdup \
x11/properties/windowname \
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/geom/rect_haspoint_p.c
--- a/lib/libstuff/geom/rect_haspoint_p.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/geom/rect_haspoint_p.c Tue Jun 01 20:09:25 2010 -0400
@@ -4,7 +4,7 @@
#include <stuff/geom.h>
bool
-rect_haspoint_p(Point pt, Rectangle r) {
+rect_haspoint_p(Rectangle r, Point pt) {
return (pt.x >= r.min.x) && (pt.x < r.max.x)
&& (pt.y >= r.min.y) && (pt.y < r.max.y);
}
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/map.c
--- a/lib/libstuff/map.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/map.c Tue Jun 01 20:09:25 2010 -0400
@@ -65,7 +65,7 @@
h = hash(str);
e = map_getp(map, h, create);
if(*e && (*e)->key == nil)
- (*e)->key = str;
+ (*e)->key = estrdup(str);
else {
SET(cmp);
for(; *e; e = &(*e)->next)
@@ -73,7 +73,7 @@
break;
if(*e == nil || (*e)->hash > h || cmp > 0)
if(create)
- insert(map, e, h, str);
+ insert(map, e, h, estrdup(str));
}
return e;
}
@@ -123,6 +123,7 @@
ret = te->val;
*e = te->next;
assert(map->nmemb-- > 0);
+ free((void*)(uintptr_t)te->key);
free(te);
}
return ret;
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/printevent.c
--- a/lib/libstuff/printevent.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/printevent.c Tue Jun 01 20:09:25 2010 -0400
@@ -480,13 +480,8 @@
/* Returns the string equivalent of an atom or "None" */
static void
TAtom(Fmt *b, va_list *ap) {
- char *atom_name;
- Atom atom;
- atom = va_arg(*ap, Atom);
- atom_name = XGetAtomName(display, atom);
- fmtprint(b, "%s", atom_name);
- XFree(atom_name);
+ fmtstrcpy(b, atomname(va_arg(*ap, Atom)));
}
#define _(m) #m, ev->m
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/colors/loadcolor.c
--- a/lib/libstuff/x11/colors/loadcolor.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/colors/loadcolor.c Tue Jun 01 20:09:25 2010 -0400
@@ -5,7 +5,7 @@
#include "../x11.h"
bool
-loadcolor(CTuple *c, char *str) {
+loadcolor(CTuple *c, const char *str) {
char buf[24];
utflcpy(buf, str, sizeof buf);
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/drawing/drawstring.c
--- a/lib/libstuff/x11/drawing/drawstring.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/drawing/drawstring.c Tue Jun 01 20:09:25 2010 -0400
@@ -7,7 +7,7 @@
uint
drawstring(Image *dst, Font *font,
Rectangle r, Align align,
- char *text, Color col) {
+ const char *text, Color col) {
Rectangle tr;
char *buf;
uint x, y, width, height, len;
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/initdisplay.c
--- a/lib/libstuff/x11/initdisplay.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/initdisplay.c Tue Jun 01 20:09:25 2010 -0400
@@ -7,20 +7,15 @@
Map windowmap;
Map atommap;
-MapEnt* wbucket[137];
-MapEnt* abucket[137];
+Map atomnamemap;
+static MapEnt* wbucket[137];
+static MapEnt* abucket[137];
+static MapEnt* anamebucket[137];
static int
Afmt(Fmt *f) {
- Atom a;
- char *s;
- int i;
- a = va_arg(f->args, Atom);
- s = XGetAtomName(display, a);
- i = fmtprint(f, "%s", s);
- free(s);
- return i;
+ return fmtstrcpy(f, atomname(va_arg(f->args, Atom)));
}
static int
@@ -76,6 +71,8 @@
windowmap.nhash = nelem(wbucket);
atommap.bucket = abucket;
atommap.nhash = nelem(abucket);
+ atomnamemap.bucket = anamebucket;
+ atomnamemap.nhash = nelem(anamebucket);
fmtinstall('A', Afmt);
fmtinstall('R', Rfmt);
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/keys/keycode.c
--- a/lib/libstuff/x11/keys/keycode.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/keys/keycode.c Tue Jun 01 20:09:25 2010 -0400
@@ -4,6 +4,6 @@
#include "../x11.h"
KeyCode
-keycode(char *name) {
+keycode(const char *name) {
return XKeysymToKeycode(display, XStringToKeysym(name));
}
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/properties/changeprop_char.c
--- a/lib/libstuff/x11/properties/changeprop_char.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/properties/changeprop_char.c Tue Jun 01 20:09:25 2010 -0400
@@ -4,6 +4,6 @@
#include "../x11.h"
void
-changeprop_char(Window *w, char *prop, char *type, char data[], int len) {
+changeprop_char(Window *w, const char *prop, const char *type, char data[], int len) {
changeproperty(w, prop, type, 8, (uchar*)data, len);
}
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/properties/changeprop_long.c
--- a/lib/libstuff/x11/properties/changeprop_long.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/properties/changeprop_long.c Tue Jun 01 20:09:25 2010 -0400
@@ -4,6 +4,6 @@
#include "../x11.h"
void
-changeprop_long(Window *w, char *prop, char *type, long data[], int len) {
+changeprop_long(Window *w, const char *prop, const char *type, long data[], int len) {
changeproperty(w, prop, type, 32, (uchar*)data, len);
}
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/properties/changeprop_short.c
--- a/lib/libstuff/x11/properties/changeprop_short.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/properties/changeprop_short.c Tue Jun 01 20:09:25 2010 -0400
@@ -4,6 +4,6 @@
#include "../x11.h"
void
-changeprop_short(Window *w, char *prop, char *type, short data[], int len) {
+changeprop_short(Window *w, const char *prop, const char *type, short data[], int len) {
changeproperty(w, prop, type, 16, (uchar*)data, len);
}
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/properties/changeprop_string.c
--- a/lib/libstuff/x11/properties/changeprop_string.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/properties/changeprop_string.c Tue Jun 01 20:09:25 2010 -0400
@@ -5,6 +5,6 @@
#include "../x11.h"
void
-changeprop_string(Window *w, char *prop, char *string) {
+changeprop_string(Window *w, const char *prop, const char *string) {
changeprop_char(w, prop, "UTF8_STRING", string, strlen(string));
}
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/properties/changeprop_textlist.c
--- a/lib/libstuff/x11/properties/changeprop_textlist.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/properties/changeprop_textlist.c Tue Jun 01 20:09:25 2010 -0400
@@ -5,7 +5,7 @@
#include "../x11.h"
void
-changeprop_textlist(Window *w, char *prop, char *type, char *data[]) {
+changeprop_textlist(Window *w, const char *prop, const char *type, char *data[]) {
char **p, *s, *t;
int len, n;
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/properties/changeprop_ulong.c
--- a/lib/libstuff/x11/properties/changeprop_ulong.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/properties/changeprop_ulong.c Tue Jun 01 20:09:25 2010 -0400
@@ -4,6 +4,6 @@
#include "../x11.h"
void
-changeprop_ulong(Window *w, char *prop, char *type, ulong data[], int len) {
+changeprop_ulong(Window *w, const char *prop, const char *type, ulong data[], int len) {
changeproperty(w, prop, type, 32, (uchar*)data, len);
}
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/properties/changeproperty.c
--- a/lib/libstuff/x11/properties/changeproperty.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/properties/changeproperty.c Tue Jun 01 20:09:25 2010 -0400
@@ -4,8 +4,8 @@
#include "../x11.h"
void
-changeproperty(Window *w, char *prop, char *type,
- int width, uchar data[], int n) {
+changeproperty(Window *w, const char *prop, const char *type,
+ int width, const uchar data[], int n) {
XChangeProperty(display, w->xid, xatom(prop), xatom(type), width,
PropModeReplace, data, n);
}
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/properties/delproperty.c
--- a/lib/libstuff/x11/properties/delproperty.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/properties/delproperty.c Tue Jun 01 20:09:25 2010 -0400
@@ -4,6 +4,6 @@
#include "../x11.h"
void
-delproperty(Window *w, char *prop) {
+delproperty(Window *w, const char *prop) {
XDeleteProperty(display, w->xid, xatom(prop));
}
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/properties/getprop.c
--- a/lib/libstuff/x11/properties/getprop.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/properties/getprop.c Tue Jun 01 20:09:25 2010 -0400
@@ -4,7 +4,7 @@
#include "../x11.h"
ulong
-getprop(Window *w, char *prop, char *type, Atom *actual, int *format,
+getprop(Window *w, const char *prop, const char *type, Atom *actual, int *format,
ulong offset, uchar **ret, ulong length) {
Atom typea;
ulong n, extra;
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/properties/getprop_long.c
--- a/lib/libstuff/x11/properties/getprop_long.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/properties/getprop_long.c Tue Jun 01 20:09:25 2010 -0400
@@ -4,7 +4,7 @@
#include "../x11.h"
ulong
-getprop_long(Window *w, char *prop, char *type,
+getprop_long(Window *w, const char *prop, const char *type,
ulong offset, long **ret, ulong length) {
Atom actual;
ulong n;
@@ -17,3 +17,10 @@
*ret = 0;
return 0;
}
+
+ulong
+getprop_ulong(Window *w, const char *prop, const char *type,
+ ulong offset, ulong **ret, ulong length) {
+ return getprop_long(w, prop, type, offset, (long**)ret, length);
+}
+
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/properties/getprop_string.c
--- a/lib/libstuff/x11/properties/getprop_string.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/properties/getprop_string.c Tue Jun 01 20:09:25 2010 -0400
@@ -4,7 +4,7 @@
#include "../x11.h"
char*
-getprop_string(Window *w, char *name) {
+getprop_string(Window *w, const char *name) {
char **list, *str;
int n;
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/properties/getprop_ulong.c
--- a/lib/libstuff/x11/properties/getprop_ulong.c Mon May 31 13:26:51 2010 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-/* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail>
- * See LICENSE file for license details.
- */
-#include "../x11.h"
-
-ulong
-getprop_ulong(Window *w, char *prop, char *type,
- ulong offset, ulong **ret, ulong length) {
- return getprop_long(w, prop, type, offset, (long**)ret, length);
-}
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/sendmessage.c
--- a/lib/libstuff/x11/sendmessage.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/sendmessage.c Tue Jun 01 20:09:25 2010 -0400
@@ -5,13 +5,13 @@
#include <string.h>
void
-sendmessage(Window *w, char *name, long l0, long l1, long l2, long l3, long l4) {
+sendmessage(Window *w, const char *name, long l0, long l1, long l2, long l3, long l4) {
clientmessage(w, name, NoEventMask, 32, (ClientMessageData){ .l = { l0, l1, l2, l3, l4 } });
}
void
-clientmessage(Window *w, char *name, long mask, int format, ClientMessageData data) {
+clientmessage(Window *w, const char *name, long mask, int format, ClientMessageData data) {
XClientMessageEvent e;
e.type = ClientMessage;
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/text/loadfont.c
--- a/lib/libstuff/x11/text/loadfont.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/text/loadfont.c Tue Jun 01 20:09:25 2010 -0400
@@ -5,7 +5,7 @@
#include "../x11.h"
Font*
-loadfont(char *name) {
+loadfont(const char *name) {
XFontStruct **xfonts;
char **missing, **font_names;
Biobuf *b;
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/text/textextents_l.c
--- a/lib/libstuff/x11/text/textextents_l.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/text/textextents_l.c Tue Jun 01 20:09:25 2010 -0400
@@ -4,7 +4,7 @@
#include "../x11.h"
Rectangle
-textextents_l(Font *font, char *text, uint len, int *offset) {
+textextents_l(Font *font, const char *text, uint len, int *offset) {
Rectangle rect;
XRectangle r;
XGlyphInfo i;
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/text/textwidth.c
--- a/lib/libstuff/x11/text/textwidth.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/text/textwidth.c Tue Jun 01 20:09:25 2010 -0400
@@ -5,6 +5,6 @@
#include "../x11.h"
uint
-textwidth(Font *font, char *text) {
+textwidth(Font *font, const char *text) {
return textwidth_l(font, text, strlen(text));
}
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/text/textwidth_l.c
--- a/lib/libstuff/x11/text/textwidth_l.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/text/textwidth_l.c Tue Jun 01 20:09:25 2010 -0400
@@ -4,7 +4,7 @@
#include "../x11.h"
uint
-textwidth_l(Font *font, char *text, uint len) {
+textwidth_l(Font *font, const char *text, uint len) {
Rectangle r;
r = textextents_l(font, text, len, nil);
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/windows/destroywindow.c
--- a/lib/libstuff/x11/windows/destroywindow.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/windows/destroywindow.c Tue Jun 01 20:09:25 2010 -0400
@@ -10,6 +10,7 @@
while(w->handler_link)
pophandler(w, w->handler_link->handler);
free(w->hints);
+ free(w->dnd);
if(w->xft)
xft->drawdestroy(w->xft);
if(w->gc)
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/x11.h
--- a/lib/libstuff/x11/x11.h Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/x11.h Tue Jun 01 20:09:25 2010 -0400
@@ -14,15 +14,11 @@
#include <stuff/util.h>
#undef pointerwin
-extern MapEnt* wbucket[137];
-extern MapEnt* abucket[137];
-
extern int (*xlib_errorhandler) (Display*, XErrorEvent*);
void configwin(Window*, Rectangle, int);
XPoint* convpts(Point*, int);
int errorhandler(Display*, XErrorEvent*);
-ulong getprop(Window*, char*, char*, Atom*, int*, ulong, uchar**, ulong);
void setgccol(Image*, Color);
XftColor* xftcolor(Color);
XftDraw* xftdrawable(Image*);
diff -r d99dfc382e65 -r 660b8c88382c lib/libstuff/x11/xatom.c
--- a/lib/libstuff/x11/xatom.c Mon May 31 13:26:51 2010 +0200
+++ b/lib/libstuff/x11/xatom.c Tue Jun 01 20:09:25 2010 -0400
@@ -4,11 +4,32 @@
#include "x11.h"
Atom
-xatom(char *name) {
- void **e;
+xatom(const char *name) {
+ void **e, **f;
e = hash_get(&atommap, name, true);
- if(*e == nil)
+ if(*e == nil) {
*e = (void*)XInternAtom(display, name, false);
+ f = map_get(&atomnamemap, (ulong)*e, true);
+ if(*f == nil)
+ *f = (void*)(uintptr_t)name;
+ }
return (Atom)*e;
}
+
+char*
+atomname(ulong atom) {
+ void **e;
+
+ e = map_get(&atomnamemap, atom, true);
+ if(*e == nil) {
+ *e = XGetAtomName(display, atom);
+ if(&e == nil) {
+ map_rm(&atomnamemap, atom);
+ return nil;
+ }
+ *hash_get(&atommap, *e, true) = (void*)atom;
+ }
+ return *e;
+}
+
Received on Wed Jun 02 2010 - 00:09:39 UTC
This archive was generated by hypermail 2.2.0 : Wed Jun 02 2010 - 00:12:07 UTC