commit e5e64f3eb45887ca4b45a0e59b427297337ece61 parent 9faaa0679e406c67f7c935fb63b902290b95d83b Author: Kris Maglione <kris@suckless.org> Date: Tue, 1 Jun 2010 20:09:25 -0400 [witray] Add partial DND proxy. Diffstat:
41 files changed, 258 insertions(+), 142 deletions(-)
diff --git a/cmd/menu/fns.h b/cmd/menu/fns.h @@ -1,10 +1,4 @@ -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); char* caret_find(int, int); @@ -32,19 +26,3 @@ void parse_keys(char*); 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 --git a/cmd/menu/main.c b/cmd/menu/main.c @@ -167,7 +167,7 @@ init_screens(void) { */ 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 --git a/cmd/tray/main.c b/cmd/tray/main.c @@ -78,7 +78,7 @@ message(Selection *s, XClientMessageEvent *ev) { 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 --git a/cmd/tray/selection.c b/cmd/tray/selection.c @@ -123,7 +123,7 @@ selectionrequest_event(Window *w, void *aux, XSelectionRequestEvent *ev) { 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 --git a/cmd/tray/tray.c b/cmd/tray/tray.c @@ -3,6 +3,7 @@ */ #include "dat.h" #include <string.h> +#include <strings.h> #include "fns.h" static Handlers handlers; @@ -69,28 +70,20 @@ tray_init(void) { | 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 @@ expose_event(Window *w, void *aux, XExposeEvent *ev) { 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; + + 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); + } - Dprint("tray_message: %s\n", XGetAtomName(display, ev->message_type)); - return false; + 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 --git a/cmd/tray/xembed.c b/cmd/tray/xembed.c @@ -106,8 +106,8 @@ static bool 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 --git a/cmd/wmii/bar.c b/cmd/wmii/bar.c @@ -244,7 +244,7 @@ findbar(WMScreen *s, Point p) { 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 --git a/cmd/wmii/layout.c b/cmd/wmii/layout.c @@ -132,7 +132,7 @@ find_area(Point pt) { 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 --git a/cmd/wmii/mouse.c b/cmd/wmii/mouse.c @@ -603,14 +603,14 @@ mouse_checkresize(Frame *f, Point p, bool exec) { 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 @@ mouse_checkresize(Frame *f, Point p, bool exec) { 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 --git a/cmd/wmii/xdnd.c b/cmd/wmii/xdnd.c @@ -65,7 +65,7 @@ clientmessage_event(Window *w, void *aux, XClientMessageEvent *e) { 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 --git a/cmd/wmii9menu.c b/cmd/wmii9menu.c @@ -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 warpmouse(int, int); 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 @@ init_screens(void) { 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 --git a/include/stuff/geom.h b/include/stuff/geom.h @@ -48,7 +48,7 @@ Point subpt(Point, Point); 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 --git a/include/stuff/x11.h b/include/stuff/x11.h @@ -168,8 +168,8 @@ struct Xft { 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 @@ Screen scr; 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 @@ XRectangle XRect(Rectangle r); /* 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 freeimage(Image *); 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 reparentwindow(Window*, Window*, Point); 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 @@ void setwinattr(Window*, WinAttr*, int valmask); 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 @@ void warppointer(Point); Window* window(XWindow); char* windowname(Window*); long winprotocols(Window*); -Atom xatom(char*); +Atom xatom(const char*); diff --git a/lib/libstuff/Makefile b/lib/libstuff/Makefile @@ -144,7 +144,6 @@ OBJ=\ 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 --git a/lib/libstuff/geom/rect_haspoint_p.c b/lib/libstuff/geom/rect_haspoint_p.c @@ -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 --git a/lib/libstuff/map.c b/lib/libstuff/map.c @@ -65,7 +65,7 @@ hash_getp(Map *map, const char *str, int create) { 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 @@ hash_getp(Map *map, const char *str, int create) { 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 @@ hash_rm(Map *map, const char *str) { ret = te->val; *e = te->next; assert(map->nmemb-- > 0); + free((void*)(uintptr_t)te->key); free(te); } return ret; diff --git a/lib/libstuff/printevent.c b/lib/libstuff/printevent.c @@ -480,13 +480,8 @@ TKeycode(Fmt *b, va_list *ap) { /* 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 --git a/lib/libstuff/x11/colors/loadcolor.c b/lib/libstuff/x11/colors/loadcolor.c @@ -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 --git a/lib/libstuff/x11/drawing/drawstring.c b/lib/libstuff/x11/drawing/drawstring.c @@ -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 --git a/lib/libstuff/x11/initdisplay.c b/lib/libstuff/x11/initdisplay.c @@ -7,20 +7,15 @@ int (*xlib_errorhandler) (Display*, XErrorEvent*); 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 @@ initdisplay(void) { 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 --git a/lib/libstuff/x11/keys/keycode.c b/lib/libstuff/x11/keys/keycode.c @@ -4,6 +4,6 @@ #include "../x11.h" KeyCode -keycode(char *name) { +keycode(const char *name) { return XKeysymToKeycode(display, XStringToKeysym(name)); } diff --git a/lib/libstuff/x11/properties/changeprop_char.c b/lib/libstuff/x11/properties/changeprop_char.c @@ -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 --git a/lib/libstuff/x11/properties/changeprop_long.c b/lib/libstuff/x11/properties/changeprop_long.c @@ -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 --git a/lib/libstuff/x11/properties/changeprop_short.c b/lib/libstuff/x11/properties/changeprop_short.c @@ -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 --git a/lib/libstuff/x11/properties/changeprop_string.c b/lib/libstuff/x11/properties/changeprop_string.c @@ -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 --git a/lib/libstuff/x11/properties/changeprop_textlist.c b/lib/libstuff/x11/properties/changeprop_textlist.c @@ -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 --git a/lib/libstuff/x11/properties/changeprop_ulong.c b/lib/libstuff/x11/properties/changeprop_ulong.c @@ -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 --git a/lib/libstuff/x11/properties/changeproperty.c b/lib/libstuff/x11/properties/changeproperty.c @@ -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 --git a/lib/libstuff/x11/properties/delproperty.c b/lib/libstuff/x11/properties/delproperty.c @@ -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 --git a/lib/libstuff/x11/properties/getprop.c b/lib/libstuff/x11/properties/getprop.c @@ -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 --git a/lib/libstuff/x11/properties/getprop_long.c b/lib/libstuff/x11/properties/getprop_long.c @@ -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 @@ getprop_long(Window *w, char *prop, char *type, *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 --git a/lib/libstuff/x11/properties/getprop_string.c b/lib/libstuff/x11/properties/getprop_string.c @@ -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 --git a/lib/libstuff/x11/properties/getprop_ulong.c b/lib/libstuff/x11/properties/getprop_ulong.c @@ -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 --git a/lib/libstuff/x11/sendmessage.c b/lib/libstuff/x11/sendmessage.c @@ -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 --git a/lib/libstuff/x11/text/loadfont.c b/lib/libstuff/x11/text/loadfont.c @@ -5,7 +5,7 @@ #include "../x11.h" Font* -loadfont(char *name) { +loadfont(const char *name) { XFontStruct **xfonts; char **missing, **font_names; Biobuf *b; diff --git a/lib/libstuff/x11/text/textextents_l.c b/lib/libstuff/x11/text/textextents_l.c @@ -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 --git a/lib/libstuff/x11/text/textwidth.c b/lib/libstuff/x11/text/textwidth.c @@ -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 --git a/lib/libstuff/x11/text/textwidth_l.c b/lib/libstuff/x11/text/textwidth_l.c @@ -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 --git a/lib/libstuff/x11/windows/destroywindow.c b/lib/libstuff/x11/windows/destroywindow.c @@ -10,6 +10,7 @@ cleanupwindow(Window *w) { 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 --git a/lib/libstuff/x11/x11.h b/lib/libstuff/x11/x11.h @@ -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 --git a/lib/libstuff/x11/xatom.c b/lib/libstuff/x11/xatom.c @@ -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; +} +