From 9142b6a7ab0fcf3a3122086db75d53b64218e8ce Mon Sep 17 00:00:00 2001 From: garbeam Date: Mon, 12 Dec 2005 18:49:56 +0200 Subject: [PATCH] changed libwmii signatures, removed win_prop, using XGetWMName instead (more modern) --- cmd/wm/client.c | 21 +++++++++++---------- cmd/wm/frame.c | 2 +- cmd/wm/wm.c | 10 ++++------ cmd/wmiibar.c | 2 +- cmd/wmiikeys.c | 8 ++++---- cmd/wmiimenu.c | 2 +- libwmii/Makefile | 2 +- libwmii/spawn.c | 2 +- libwmii/util.c | 13 ------------- libwmii/wm.c | 23 ++++------------------- libwmii/wmii.h | 16 ++++------------ 11 files changed, 32 insertions(+), 69 deletions(-) delete mode 100644 libwmii/util.c diff --git a/cmd/wm/client.c b/cmd/wm/client.c index a8ab0dad..83c10534 100644 --- a/cmd/wm/client.c +++ b/cmd/wm/client.c @@ -14,15 +14,16 @@ Client *alloc_client(Window w) { static int id = 0; char buf[MAX_BUF]; - char buf2[MAX_BUF]; + XTextProperty name; Client *c = (Client *) cext_emallocz(sizeof(Client)); c->win = w; snprintf(buf, MAX_BUF, "/detached/client/%d", id); c->file[C_PREFIX] = ixp_create(ixps, buf); - win_prop(dpy, c->win, XA_WM_NAME, buf2, MAX_BUF); + XGetWMName(dpy, c->win, &name); snprintf(buf, MAX_BUF, "/detached/client/%d/name", id); - c->file[C_NAME] = wmii_create_ixpfile(ixps, buf, buf2); + c->file[C_NAME] = wmii_create_ixpfile(ixps, buf, (char *)name.value); + free(name.value); id++; cext_attach_item(&clients, c); return c; @@ -117,7 +118,7 @@ void configure_client(Client * c) void close_client(Client * c) { if (c->proto & PROTO_DEL) - send_message(dpy, c->win, wm_protocols, wm_delete); + wmii_send_message(dpy, c->win, wm_protocols, wm_delete); else XKillClient(dpy, c->win); } @@ -142,10 +143,9 @@ void init_client(Client * c, XWindowAttributes * wa) void handle_client_property(Client * c, XPropertyEvent * e) { - char buf[1024]; + XTextProperty name; long msize; - buf[0] = 0; if (e->state == PropertyDelete) return; /* ignore */ @@ -156,13 +156,14 @@ void handle_client_property(Client * c, XPropertyEvent * e) } switch (e->atom) { case XA_WM_NAME: - win_prop(dpy, c->win, XA_WM_NAME, buf, sizeof(buf)); - if (strlen(buf)) { + XGetWMName(dpy, c->win, &name); + if (strlen((char *)name.value)) { if (c->file[C_NAME]->content) free(c->file[C_NAME]->content); - c->file[C_NAME]->content = cext_estrdup(buf); - c->file[C_NAME]->size = strlen(buf); + c->file[C_NAME]->content = cext_estrdup((char *)name.value); + c->file[C_NAME]->size = strlen((char *)name.value); } + free(name.value); if (c->frame) draw_client(c, nil); invoke_wm_event(def[WM_EVENT_CLIENT_UPDATE]); diff --git a/cmd/wm/frame.c b/cmd/wm/frame.c index 97f2cde9..24f04bb1 100644 --- a/cmd/wm/frame.c +++ b/cmd/wm/frame.c @@ -295,7 +295,7 @@ void handle_frame_buttonpress(XButtonEvent *e, Frame *f) bindex = F_EVENT_B2PRESS - 2 + e->button; /* frame mouse handling */ if (f->file[bindex]->content) - spawn(dpy, f->file[bindex]->content); + wmii_spawn(dpy, f->file[bindex]->content); draw_frame(f, nil); } diff --git a/cmd/wm/wm.c b/cmd/wm/wm.c index 3669e105..0bb3af1d 100644 --- a/cmd/wm/wm.c +++ b/cmd/wm/wm.c @@ -90,7 +90,7 @@ void invoke_wm_event(File * f) { if (!f->content) return; - spawn(dpy, f->content); + wmii_spawn(dpy, f->content); } static void @@ -481,8 +481,7 @@ int win_proto(Window w) int protos = 0; int i; - res = property(dpy, w, wm_protocols, XA_ATOM, - 20L, ((unsigned char **) &protocols)); + res = wmii_property(dpy, w, wm_protocols, XA_ATOM, 20L, ((unsigned char **) &protocols)); if (res <= 0) { return protos; } @@ -502,8 +501,7 @@ int win_state(Window w) int res; long *prop = 0; - if (property(dpy, w, wm_state, wm_state, - 2L, ((unsigned char **) &prop)) > 0) { + if (wmii_property(dpy, w, wm_state, wm_state, 2L, ((unsigned char **) &prop)) > 0) { res = (int) *prop; free((long *) prop); } else { @@ -754,7 +752,7 @@ int main(int argc, char *argv[]) init_cursors(); init_default(); font = blitz_getfont(dpy, def[WM_FONT]->content); - init_lock_modifiers(dpy, &valid_mask, &num_lock_mask); + wmii_init_lock_modifiers(dpy, &valid_mask, &num_lock_mask); init_screen(); init_layouts(); scan_wins(); diff --git a/cmd/wmiibar.c b/cmd/wmiibar.c index abd5cdc7..4b27f780 100644 --- a/cmd/wmiibar.c +++ b/cmd/wmiibar.c @@ -328,7 +328,7 @@ static void iter_buttonpress(void *item, void *bpress) snprintf(buf, MAX_BUF, "%s/b%upress", path, e->button); if ((p = ixp_walk(ixps, buf))) if (p->content) - spawn(dpy, p->content); + wmii_spawn(dpy, p->content); return; } } diff --git a/cmd/wmiikeys.c b/cmd/wmiikeys.c index 4dc90f08..0f08fa87 100644 --- a/cmd/wmiikeys.c +++ b/cmd/wmiikeys.c @@ -205,7 +205,7 @@ static void handle_shortcut_chain(Window w, Shortcut * processed, char *prefix, emulate_key_press(mod, key); } else if ((s->mod == mod) && (s->key == key)) { if (s->cmdfile && s->cmdfile->content) - spawn(dpy, s->cmdfile->content); + wmii_spawn(dpy, s->cmdfile->content); else if (s->next) { snprintf(buf, sizeof(buf), "%s/%s", prefix, s->name); handle_shortcut_chain(w, s, buf, 0); @@ -236,7 +236,7 @@ static void handle_shortcut_gkb(Window w, unsigned long mod, KeyCode key) s = cext_find_item(&shortcuts, &comp, comp_shortcut); if (s && s->cmdfile && s->cmdfile->content) { - spawn(dpy, s->cmdfile->content); + wmii_spawn(dpy, s->cmdfile->content); return; } XBell(dpy, 0); @@ -253,7 +253,7 @@ static void handle_shortcut(Window w, unsigned long mod, KeyCode key) s = cext_find_item(&shortcuts, &comp, comp_shortcut); if (s && s->cmdfile && s->cmdfile->content) { - spawn(dpy, s->cmdfile->content); + wmii_spawn(dpy, s->cmdfile->content); return; } if (s && s->next) @@ -456,7 +456,7 @@ int main(int argc, char *argv[]) krect.x = krect.y = 0; krect.width = krect.height = 1; - init_lock_modifiers(dpy, &valid_mask, &num_lock_mask); + wmii_init_lock_modifiers(dpy, &valid_mask, &num_lock_mask); win = XCreateWindow(dpy, RootWindow(dpy, screen_num), krect.x, krect.y, krect.width, krect.height, 0, DefaultDepth(dpy, screen_num), diff --git a/cmd/wmiimenu.c b/cmd/wmiimenu.c index 93e75aac..348f927e 100644 --- a/cmd/wmiimenu.c +++ b/cmd/wmiimenu.c @@ -111,7 +111,7 @@ static void exec_item(char *cmd) snprintf(rc, len, "%s %s", (char *) files[M_PRE_COMMAND]->content, cmd); } /* fallback */ - spawn(dpy, rc); + wmii_spawn(dpy, rc); /* cleanup */ if (files[M_PRE_COMMAND]->content) free(rc); diff --git a/libwmii/Makefile b/libwmii/Makefile index 50919996..16dafe24 100644 --- a/libwmii/Makefile +++ b/libwmii/Makefile @@ -6,7 +6,7 @@ include ../config.mk CFLAGS += -I../liblitz -I../libixp -I../libcext LDFLAGS += -L../liblitz -llitz -L../libixp -lixp -L../libcext -lcext -SRC = ixputil.c spawn.c util.c wm.c +SRC = ixputil.c spawn.c wm.c OBJ = ${SRC:.c=.o} diff --git a/libwmii/spawn.c b/libwmii/spawn.c index c6a08c1a..0306de5e 100644 --- a/libwmii/spawn.c +++ b/libwmii/spawn.c @@ -11,7 +11,7 @@ #include "wmii.h" -void spawn(void *dpy, char *cmd) +void wmii_spawn(void *dpy, char *cmd) { /* the questionable double-fork is done to catch all zombies */ if (fork() == 0) { diff --git a/libwmii/util.c b/libwmii/util.c deleted file mode 100644 index bf445fc8..00000000 --- a/libwmii/util.c +++ /dev/null @@ -1,13 +0,0 @@ -/* - * (C)opyright MMIV-MMV Anselm R. Garbe - * See LICENSE file for license details. - */ - -#include "wmii.h" - -void swap(void **p1, void **p2) -{ - void *tmp = *p1; - *p1 = *p2; - *p2 = tmp; -} diff --git a/libwmii/wm.c b/libwmii/wm.c index 69978965..fb4dc0c9 100644 --- a/libwmii/wm.c +++ b/libwmii/wm.c @@ -13,15 +13,14 @@ #include "blitz.h" -int property(Display * dpy, Window w, Atom a, Atom t, long l, unsigned char **prop) +int wmii_property(Display * dpy, Window w, Atom a, Atom t, long l, unsigned char **prop) { Atom real; int format; unsigned long res, extra; int status; - status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format, - &res, &extra, prop); + status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format, &res, &extra, prop); if (status != Success || *prop == 0) { return 0; @@ -32,19 +31,7 @@ int property(Display * dpy, Window w, Atom a, Atom t, long l, unsigned char **pr return res; } -void win_prop(Display * dpy, Window w, Atom a, char *res, int len) -{ - unsigned char *prop; - - if (property(dpy, w, a, XA_STRING, 100L, &prop)) { - cext_strlcpy(res, (char *) prop, len); - XFree(prop); - } - res[len - 1] = 0; - XSync(dpy, False); -} - -void send_message(Display * dpy, Window w, Atom a, long value) +void wmii_send_message(Display * dpy, Window w, Atom a, long value) { XEvent e; e.type = ClientMessage; @@ -59,9 +46,7 @@ void send_message(Display * dpy, Window w, Atom a, long value) } #define NUM_MASKS 8 -void -init_lock_modifiers(Display * dpy, unsigned int *valid_mask, - unsigned int *num_lock_mask) +void wmii_init_lock_modifiers(Display * dpy, unsigned int *valid_mask, unsigned int *num_lock_mask) { XModifierKeymap *modmap; KeyCode num_lock; diff --git a/libwmii/wmii.h b/libwmii/wmii.h index 3db85548..ed160ba3 100644 --- a/libwmii/wmii.h +++ b/libwmii/wmii.h @@ -23,17 +23,9 @@ void wmii_move_ixpfile(File * f, File * to_parent); IXPServer *wmii_setup_server(char *sockfile); /* spawn.c */ -void spawn(void *dpy, char *cmd); - -/* util.c */ -void swap(void **p1, void **p2); +void wmii_spawn(void *dpy, char *cmd); /* wm.c */ -int -property(Display * dpy, Window w, Atom a, Atom t, long l, - unsigned char **prop); -void win_prop(Display * dpy, Window w, Atom a, char *res, int len); -void send_message(Display * dpy, Window w, Atom a, long value); -void -init_lock_modifiers(Display * dpy, unsigned int *valid_mask, - unsigned int *num_lock_mask); +int wmii_property(Display *dpy, Window w, Atom a, Atom t, long l, unsigned char **prop); +void wmii_send_message(Display *dpy, Window w, Atom a, long value); +void wmii_init_lock_modifiers(Display *dpy, unsigned int *valid_mask, unsigned int *num_lock_mask);