cvsimport

This commit is contained in:
Christian Neukirchen 2012-11-26 16:17:45 +01:00
commit 319d4e179e
16 changed files with 226 additions and 106 deletions

View File

@ -27,9 +27,9 @@
#include <getopt.h> #include <getopt.h>
#include <locale.h> #include <locale.h>
#include <signal.h> #include <signal.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "calmwm.h" #include "calmwm.h"

View File

@ -85,6 +85,10 @@ size_t strlcat(char *, const char *, size_t);
#define CWM_RCYCLE 0x0002 #define CWM_RCYCLE 0x0002
#define CWM_INGROUP 0x0004 #define CWM_INGROUP 0x0004
/* menu */
#define CWM_MENU_DUMMY 0x0001
#define CWM_MENU_FILE 0x0002
#define KBTOGROUP(X) ((X) - 1) #define KBTOGROUP(X) ((X) - 1)
union arg { union arg {
@ -272,7 +276,7 @@ TAILQ_HEAD(cmd_q, cmd);
struct menu { struct menu {
TAILQ_ENTRY(menu) entry; TAILQ_ENTRY(menu) entry;
TAILQ_ENTRY(menu) resultentry; TAILQ_ENTRY(menu) resultentry;
#define MENU_MAXENTRY 50 #define MENU_MAXENTRY 200
char text[MENU_MAXENTRY + 1]; char text[MENU_MAXENTRY + 1];
char print[MENU_MAXENTRY + 1]; char print[MENU_MAXENTRY + 1];
void *ctx; void *ctx;
@ -367,6 +371,10 @@ void search_match_client(struct menu_q *, struct menu_q *,
char *); char *);
void search_match_exec(struct menu_q *, struct menu_q *, void search_match_exec(struct menu_q *, struct menu_q *,
char *); char *);
void search_match_exec_path(struct menu_q *, struct menu_q *,
char *);
void search_match_path_any(struct menu_q *, struct menu_q *,
char *);
void search_match_text(struct menu_q *, struct menu_q *, void search_match_text(struct menu_q *, struct menu_q *,
char *); char *);
void search_print_client(struct menu *, int); void search_print_client(struct menu *, int);
@ -485,7 +493,7 @@ void xu_ewmh_net_wm_number_of_desktops(struct screen_ctx *);
void xu_ewmh_net_showing_desktop(struct screen_ctx *); void xu_ewmh_net_showing_desktop(struct screen_ctx *);
void xu_ewmh_net_virtual_roots(struct screen_ctx *); void xu_ewmh_net_virtual_roots(struct screen_ctx *);
void xu_ewmh_net_current_desktop(struct screen_ctx *, long); void xu_ewmh_net_current_desktop(struct screen_ctx *, long);
void xu_ewmh_net_desktop_names(struct screen_ctx *, unsigned char *, int); void xu_ewmh_net_desktop_names(struct screen_ctx *, char *, int);
void xu_ewmh_net_wm_desktop(struct client_ctx *); void xu_ewmh_net_wm_desktop(struct client_ctx *);
@ -494,7 +502,6 @@ void u_exec(char *);
void u_spawn(char *); void u_spawn(char *);
void *xcalloc(size_t, size_t); void *xcalloc(size_t, size_t);
void xfree(void *);
void *xmalloc(size_t); void *xmalloc(size_t);
char *xstrdup(const char *); char *xstrdup(const char *);

View File

@ -24,9 +24,9 @@
#include <assert.h> #include <assert.h>
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "calmwm.h" #include "calmwm.h"
@ -166,12 +166,12 @@ client_delete(struct client_ctx *cc)
while ((wn = TAILQ_FIRST(&cc->nameq)) != NULL) { while ((wn = TAILQ_FIRST(&cc->nameq)) != NULL) {
TAILQ_REMOVE(&cc->nameq, wn, entry); TAILQ_REMOVE(&cc->nameq, wn, entry);
if (wn->name != emptystring) if (wn->name != emptystring)
xfree(wn->name); free(wn->name);
xfree(wn); free(wn);
} }
client_freehints(cc); client_freehints(cc);
xfree(cc); free(cc);
} }
void void
@ -582,8 +582,8 @@ match:
assert(wn != NULL); assert(wn != NULL);
TAILQ_REMOVE(&cc->nameq, wn, entry); TAILQ_REMOVE(&cc->nameq, wn, entry);
if (wn->name != emptystring) if (wn->name != emptystring)
xfree(wn->name); free(wn->name);
xfree(wn); free(wn);
cc->nameqlen--; cc->nameqlen--;
} }
} }

85
conf.c
View File

@ -24,9 +24,9 @@
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "calmwm.h" #include "calmwm.h"
@ -202,36 +202,35 @@ conf_clear(struct conf *c)
while ((cmd = TAILQ_FIRST(&c->cmdq)) != NULL) { while ((cmd = TAILQ_FIRST(&c->cmdq)) != NULL) {
TAILQ_REMOVE(&c->cmdq, cmd, entry); TAILQ_REMOVE(&c->cmdq, cmd, entry);
xfree(cmd); free(cmd);
} }
while ((kb = TAILQ_FIRST(&c->keybindingq)) != NULL) { while ((kb = TAILQ_FIRST(&c->keybindingq)) != NULL) {
TAILQ_REMOVE(&c->keybindingq, kb, entry); TAILQ_REMOVE(&c->keybindingq, kb, entry);
xfree(kb); free(kb);
} }
while ((ag = TAILQ_FIRST(&c->autogroupq)) != NULL) { while ((ag = TAILQ_FIRST(&c->autogroupq)) != NULL) {
TAILQ_REMOVE(&c->autogroupq, ag, entry); TAILQ_REMOVE(&c->autogroupq, ag, entry);
xfree(ag->class); free(ag->class);
if (ag->name) free(ag->name);
xfree(ag->name); free(ag);
xfree(ag);
} }
while ((wm = TAILQ_FIRST(&c->ignoreq)) != NULL) { while ((wm = TAILQ_FIRST(&c->ignoreq)) != NULL) {
TAILQ_REMOVE(&c->ignoreq, wm, entry); TAILQ_REMOVE(&c->ignoreq, wm, entry);
xfree(wm); free(wm);
} }
while ((mb = TAILQ_FIRST(&c->mousebindingq)) != NULL) { while ((mb = TAILQ_FIRST(&c->mousebindingq)) != NULL) {
TAILQ_REMOVE(&c->mousebindingq, mb, entry); TAILQ_REMOVE(&c->mousebindingq, mb, entry);
xfree(mb); free(mb);
} }
for (i = 0; i < CWM_COLOR_MAX; i++) for (i = 0; i < CWM_COLOR_MAX; i++)
xfree(c->color[i].name); free(c->color[i].name);
xfree(c->font); free(c->font);
} }
void void
@ -447,24 +446,22 @@ conf_bindname(struct conf *c, char *name, char *binding)
{ {
struct keybinding *current_binding; struct keybinding *current_binding;
char *substring, *tmp; char *substring, *tmp;
int iter; int i;
current_binding = xcalloc(1, sizeof(*current_binding)); current_binding = xcalloc(1, sizeof(*current_binding));
if ((substring = strchr(name, '-')) != NULL) { if ((substring = strchr(name, '-')) != NULL) {
for (iter = 0; iter < nitems(bind_mods); iter++) { for (i = 0; i < nitems(bind_mods); i++) {
if ((tmp = strchr(name, bind_mods[iter].chr)) != if ((tmp = strchr(name, bind_mods[i].chr)) !=
NULL && tmp < substring) { NULL && tmp < substring) {
current_binding->modmask |= current_binding->modmask |= bind_mods[i].mask;
bind_mods[iter].mask;
} }
} }
/* skip past the modifiers */ /* skip past the modifiers */
substring++; substring++;
} else { } else
substring = name; substring = name;
}
if (substring[0] == '[' && if (substring[0] == '[' &&
substring[strlen(substring)-1] == ']') { substring[strlen(substring)-1] == ']') {
@ -477,23 +474,25 @@ conf_bindname(struct conf *c, char *name, char *binding)
if (current_binding->keysym == NoSymbol && if (current_binding->keysym == NoSymbol &&
current_binding->keycode == 0) { current_binding->keycode == 0) {
xfree(current_binding); free(current_binding);
return; return;
} }
/* We now have the correct binding, remove duplicates. */ /* We now have the correct binding, remove duplicates. */
conf_unbind(c, current_binding); conf_unbind(c, current_binding);
if (strcmp("unmap", binding) == 0) if (strcmp("unmap", binding) == 0) {
free(current_binding);
return; return;
}
for (iter = 0; iter < nitems(name_to_kbfunc); iter++) { for (i = 0; i < nitems(name_to_kbfunc); i++) {
if (strcmp(name_to_kbfunc[iter].tag, binding) != 0) if (strcmp(name_to_kbfunc[i].tag, binding) != 0)
continue; continue;
current_binding->callback = name_to_kbfunc[iter].handler; current_binding->callback = name_to_kbfunc[i].handler;
current_binding->flags = name_to_kbfunc[iter].flags; current_binding->flags = name_to_kbfunc[i].flags;
current_binding->argument = name_to_kbfunc[iter].argument; current_binding->argument = name_to_kbfunc[i].argument;
conf_grab(c, current_binding); conf_grab(c, current_binding);
TAILQ_INSERT_TAIL(&c->keybindingq, current_binding, entry); TAILQ_INSERT_TAIL(&c->keybindingq, current_binding, entry);
return; return;
@ -511,10 +510,7 @@ conf_unbind(struct conf *c, struct keybinding *unbind)
{ {
struct keybinding *key = NULL, *keynxt; struct keybinding *key = NULL, *keynxt;
for (key = TAILQ_FIRST(&c->keybindingq); TAILQ_FOREACH_SAFE(key, &c->keybindingq, entry, keynxt) {
key != TAILQ_END(&c->keybindingq); key = keynxt) {
keynxt = TAILQ_NEXT(key, entry);
if (key->modmask != unbind->modmask) if (key->modmask != unbind->modmask)
continue; continue;
@ -523,7 +519,7 @@ conf_unbind(struct conf *c, struct keybinding *unbind)
key->keysym == unbind->keysym) { key->keysym == unbind->keysym) {
conf_ungrab(c, key); conf_ungrab(c, key);
TAILQ_REMOVE(&c->keybindingq, key, entry); TAILQ_REMOVE(&c->keybindingq, key, entry);
xfree(key); free(key);
} }
} }
} }
@ -551,16 +547,15 @@ conf_mousebind(struct conf *c, char *name, char *binding)
struct mousebinding *current_binding; struct mousebinding *current_binding;
char *substring, *tmp; char *substring, *tmp;
const char *errstr; const char *errstr;
int iter; int i;
current_binding = xcalloc(1, sizeof(*current_binding)); current_binding = xcalloc(1, sizeof(*current_binding));
if ((substring = strchr(name, '-')) != NULL) { if ((substring = strchr(name, '-')) != NULL) {
for (iter = 0; iter < nitems(bind_mods); iter++) { for (i = 0; i < nitems(bind_mods); i++) {
if ((tmp = strchr(name, bind_mods[iter].chr)) != if ((tmp = strchr(name, bind_mods[i].chr)) !=
NULL && tmp < substring) { NULL && tmp < substring) {
current_binding->modmask |= current_binding->modmask |= bind_mods[i].mask;
bind_mods[iter].mask;
} }
} }
@ -573,17 +568,20 @@ conf_mousebind(struct conf *c, char *name, char *binding)
if (errstr) if (errstr)
warnx("number of buttons is %s: %s", errstr, substring); warnx("number of buttons is %s: %s", errstr, substring);
/* We now have the correct binding, remove duplicates. */
conf_mouseunbind(c, current_binding); conf_mouseunbind(c, current_binding);
if (strcmp("unmap", binding) == 0) if (strcmp("unmap", binding) == 0) {
free(current_binding);
return; return;
}
for (iter = 0; iter < nitems(name_to_mousefunc); iter++) { for (i = 0; i < nitems(name_to_mousefunc); i++) {
if (strcmp(name_to_mousefunc[iter].tag, binding) != 0) if (strcmp(name_to_mousefunc[i].tag, binding) != 0)
continue; continue;
current_binding->context = name_to_mousefunc[iter].context; current_binding->context = name_to_mousefunc[i].context;
current_binding->callback = name_to_mousefunc[iter].handler; current_binding->callback = name_to_mousefunc[i].handler;
TAILQ_INSERT_TAIL(&c->mousebindingq, current_binding, entry); TAILQ_INSERT_TAIL(&c->mousebindingq, current_binding, entry);
return; return;
} }
@ -594,16 +592,13 @@ conf_mouseunbind(struct conf *c, struct mousebinding *unbind)
{ {
struct mousebinding *mb = NULL, *mbnxt; struct mousebinding *mb = NULL, *mbnxt;
for (mb = TAILQ_FIRST(&c->mousebindingq); TAILQ_FOREACH_SAFE(mb, &c->mousebindingq, entry, mbnxt) {
mb != TAILQ_END(&c->mousebindingq); mb = mbnxt) {
mbnxt = TAILQ_NEXT(mb, entry);
if (mb->modmask != unbind->modmask) if (mb->modmask != unbind->modmask)
continue; continue;
if (mb->button == unbind->button) { if (mb->button == unbind->button) {
TAILQ_REMOVE(&c->mousebindingq, mb, entry); TAILQ_REMOVE(&c->mousebindingq, mb, entry);
xfree(mb); free(mb);
} }
} }
} }

View File

@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\" .\"
.Dd $Mdocdate: October 31 2012 $ .Dd $Mdocdate: November 7 2012 $
.Dt CWMRC 5 .Dt CWMRC 5
.Os .Os
.Sh NAME .Sh NAME
@ -58,8 +58,8 @@ is 0, matching windows will not be added to any group; this may be
used to override used to override
.Dq sticky group mode . .Dq sticky group mode .
.Pp .Pp
The name and class values, respectively, for existing windows The name and class values, respectively, for existing windows
may be obtained using are both set in the WM_CLASS property and may be obtained using
.Xr xprop 1 . .Xr xprop 1 .
.Pp .Pp
.It Ic bind Ar keys command .It Ic bind Ar keys command

2
font.c
View File

@ -23,9 +23,9 @@
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "calmwm.h" #include "calmwm.h"

12
group.c
View File

@ -25,9 +25,9 @@
#include <assert.h> #include <assert.h>
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "calmwm.h" #include "calmwm.h"
@ -129,7 +129,7 @@ group_show(struct screen_ctx *sc, struct group_ctx *gc)
} }
XRestackWindows(X_Dpy, winlist, gc->nhidden); XRestackWindows(X_Dpy, winlist, gc->nhidden);
xfree(winlist); free(winlist);
gc->hidden = 0; gc->hidden = 0;
group_setactive(sc, gc->shortcut - 1); group_setactive(sc, gc->shortcut - 1);
@ -387,7 +387,7 @@ group_menu(XButtonEvent *e)
cleanup: cleanup:
while ((mi = TAILQ_FIRST(&menuq)) != NULL) { while ((mi = TAILQ_FIRST(&menuq)) != NULL) {
TAILQ_REMOVE(&menuq, mi, entry); TAILQ_REMOVE(&menuq, mi, entry);
xfree(mi); free(mi);
} }
} }
@ -472,7 +472,7 @@ group_update_names(struct screen_ctx *sc)
strings = xmalloc((nstrings < CALMWM_NGROUPS ? CALMWM_NGROUPS : strings = xmalloc((nstrings < CALMWM_NGROUPS ? CALMWM_NGROUPS :
nstrings) * sizeof(*strings)); nstrings) * sizeof(*strings));
p = prop_ret; p = (char *)prop_ret;
while (n < nstrings) { while (n < nstrings) {
strings[n++] = xstrdup(p); strings[n++] = xstrdup(p);
p += strlen(p) + 1; p += strlen(p) + 1;
@ -491,7 +491,7 @@ group_update_names(struct screen_ctx *sc)
if (prop_ret != NULL) if (prop_ret != NULL)
XFree(prop_ret); XFree(prop_ret);
if (sc->group_nonames != 0) if (sc->group_nonames != 0)
xfree(sc->group_names); free(sc->group_names);
sc->group_names = strings; sc->group_names = strings;
sc->group_nonames = n; sc->group_nonames = n;
@ -502,7 +502,7 @@ group_update_names(struct screen_ctx *sc)
static void static void
group_set_names(struct screen_ctx *sc) group_set_names(struct screen_ctx *sc)
{ {
unsigned char *p, *q; char *p, *q;
size_t len = 0, tlen, slen; size_t len = 0, tlen, slen;
int i; int i;

View File

@ -26,9 +26,9 @@
#include <errno.h> #include <errno.h>
#include <paths.h> #include <paths.h>
#include <signal.h> #include <signal.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "calmwm.h" #include "calmwm.h"
@ -170,7 +170,7 @@ kbfunc_client_search(struct client_ctx *cc, union arg *arg)
while ((mi = TAILQ_FIRST(&menuq)) != NULL) { while ((mi = TAILQ_FIRST(&menuq)) != NULL) {
TAILQ_REMOVE(&menuq, mi, entry); TAILQ_REMOVE(&menuq, mi, entry);
xfree(mi); free(mi);
} }
} }
@ -197,7 +197,7 @@ kbfunc_menu_search(struct client_ctx *cc, union arg *arg)
while ((mi = TAILQ_FIRST(&menuq)) != NULL) { while ((mi = TAILQ_FIRST(&menuq)) != NULL) {
TAILQ_REMOVE(&menuq, mi, entry); TAILQ_REMOVE(&menuq, mi, entry);
xfree(mi); free(mi);
} }
} }
@ -297,10 +297,11 @@ kbfunc_exec(struct client_ctx *cc, union arg *arg)
} }
(void)closedir(dirp); (void)closedir(dirp);
} }
xfree(path); free(path);
if ((mi = menu_filter(sc, &menuq, label, NULL, 1, if ((mi = menu_filter(sc, &menuq, label, NULL,
search_match_exec, NULL)) != NULL) { CWM_MENU_DUMMY | CWM_MENU_FILE,
search_match_exec_path, NULL)) != NULL) {
if (mi->text[0] == '\0') if (mi->text[0] == '\0')
goto out; goto out;
switch (cmd) { switch (cmd) {
@ -318,10 +319,10 @@ kbfunc_exec(struct client_ctx *cc, union arg *arg)
} }
out: out:
if (mi != NULL && mi->dummy) if (mi != NULL && mi->dummy)
xfree(mi); free(mi);
while ((mi = TAILQ_FIRST(&menuq)) != NULL) { while ((mi = TAILQ_FIRST(&menuq)) != NULL) {
TAILQ_REMOVE(&menuq, mi, entry); TAILQ_REMOVE(&menuq, mi, entry);
xfree(mi); free(mi);
} }
} }
@ -374,10 +375,10 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg)
(void)strlcpy(mi->text, hostbuf, sizeof(mi->text)); (void)strlcpy(mi->text, hostbuf, sizeof(mi->text));
TAILQ_INSERT_TAIL(&menuq, mi, entry); TAILQ_INSERT_TAIL(&menuq, mi, entry);
} }
xfree(lbuf); free(lbuf);
(void)fclose(fp); (void)fclose(fp);
if ((mi = menu_filter(sc, &menuq, "ssh", NULL, 1, if ((mi = menu_filter(sc, &menuq, "ssh", NULL, CWM_MENU_DUMMY,
search_match_exec, NULL)) != NULL) { search_match_exec, NULL)) != NULL) {
if (mi->text[0] == '\0') if (mi->text[0] == '\0')
goto out; goto out;
@ -388,10 +389,10 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg)
} }
out: out:
if (mi != NULL && mi->dummy) if (mi != NULL && mi->dummy)
xfree(mi); free(mi);
while ((mi = TAILQ_FIRST(&menuq)) != NULL) { while ((mi = TAILQ_FIRST(&menuq)) != NULL) {
TAILQ_REMOVE(&menuq, mi, entry); TAILQ_REMOVE(&menuq, mi, entry);
xfree(mi); free(mi);
} }
} }
@ -404,15 +405,14 @@ kbfunc_client_label(struct client_ctx *cc, union arg *arg)
TAILQ_INIT(&menuq); TAILQ_INIT(&menuq);
/* dummy is set, so this will always return */ /* dummy is set, so this will always return */
mi = menu_filter(cc->sc, &menuq, "label", cc->label, 1, mi = menu_filter(cc->sc, &menuq, "label", cc->label, CWM_MENU_DUMMY,
search_match_text, NULL); search_match_text, NULL);
if (!mi->abort) { if (!mi->abort) {
if (cc->label != NULL) free(cc->label);
xfree(cc->label);
cc->label = xstrdup(mi->text); cc->label = xstrdup(mi->text);
} }
xfree(mi); free(mi);
} }
void void

78
menu.c
View File

@ -22,11 +22,12 @@
#include <sys/param.h> #include <sys/param.h>
#include <sys/queue.h> #include <sys/queue.h>
#include <ctype.h>
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "calmwm.h" #include "calmwm.h"
@ -37,10 +38,11 @@
enum ctltype { enum ctltype {
CTL_NONE = -1, CTL_NONE = -1,
CTL_ERASEONE = 0, CTL_WIPE, CTL_UP, CTL_DOWN, CTL_RETURN, CTL_ERASEONE = 0, CTL_WIPE, CTL_UP, CTL_DOWN, CTL_RETURN,
CTL_ABORT, CTL_ALL CTL_TAB, CTL_ABORT, CTL_ALL
}; };
struct menu_ctx { struct menu_ctx {
struct screen_ctx *sc;
char searchstr[MENU_MAXENTRY + 1]; char searchstr[MENU_MAXENTRY + 1];
char dispstr[MENU_MAXENTRY*2 + 1]; char dispstr[MENU_MAXENTRY*2 + 1];
char promptstr[MENU_MAXENTRY + 1]; char promptstr[MENU_MAXENTRY + 1];
@ -54,6 +56,7 @@ struct menu_ctx {
int height; int height;
int width; int width;
int num; int num;
int flags;
int x; int x;
int y; int y;
void (*match)(struct menu_q *, struct menu_q *, char *); void (*match)(struct menu_q *, struct menu_q *, char *);
@ -93,7 +96,7 @@ menu_init(struct screen_ctx *sc)
struct menu * struct menu *
menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt, menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt,
char *initial, int dummy, char *initial, int flags,
void (*match)(struct menu_q *, struct menu_q *, char *), void (*match)(struct menu_q *, struct menu_q *, char *),
void (*print)(struct menu *, int)) void (*print)(struct menu *, int))
{ {
@ -114,6 +117,8 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt,
xsave = mc.x; xsave = mc.x;
ysave = mc.y; ysave = mc.y;
mc.sc = sc;
mc.flags = flags;
if (prompt == NULL) { if (prompt == NULL) {
evmask = MENUMASK; evmask = MENUMASK;
mc.promptstr[0] = '\0'; mc.promptstr[0] = '\0';
@ -181,8 +186,9 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt,
} }
} }
out: out:
if (dummy == 0 && mi->dummy) { /* no mouse based match */ if ((mc.flags & CWM_MENU_DUMMY) == 0 && mi->dummy) {
xfree(mi); /* no mouse based match */
free(mi);
mi = NULL; mi = NULL;
} }
@ -199,6 +205,38 @@ out:
return (mi); return (mi);
} }
static struct menu *
menu_complete_path(struct menu_ctx *mc)
{
struct menu *mi, *mr;
struct menu_q menuq;
char *path = NULL;
path = xcalloc(1, sizeof(mr->text));
mr = xcalloc(1, sizeof(*mr));
TAILQ_INIT(&menuq);
if ((mi = menu_filter(mc->sc, &menuq, mc->searchstr, NULL,
CWM_MENU_DUMMY, search_match_path_any, NULL)) != NULL) {
mr->abort = mi->abort;
mr->dummy = mi->dummy;
strlcpy(path, mi->text, sizeof(mi->text));
}
while ((mi = TAILQ_FIRST(&menuq)) != NULL) {
TAILQ_REMOVE(&menuq, mi, entry);
free(mi);
}
if (path[0] != '\0')
snprintf(mr->text, sizeof(mr->text), "%s \"%s\"",
mc->searchstr, path);
else if (!mr->abort)
strlcpy(mr->text, mc->searchstr, sizeof(mr->text));
free(path);
return (mr);
}
static struct menu * static struct menu *
menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq, menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq,
struct menu_q *resultq) struct menu_q *resultq)
@ -257,6 +295,33 @@ menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq,
mc->searchstr[0] = '\0'; mc->searchstr[0] = '\0';
mc->changed = 1; mc->changed = 1;
break; break;
case CTL_TAB:
if ((mi = TAILQ_FIRST(resultq)) != NULL) {
/*
* - We are in exec_path menu mode
* - It is equal to the input
* We got a command, launch the file menu
*/
if ((mc->flags & CWM_MENU_FILE) &&
(strncmp(mc->searchstr, mi->text,
strlen(mi->text))) == 0)
return (menu_complete_path(mc));
/*
* Put common prefix of the results into searchstr
*/
(void)strlcpy(mc->searchstr,
mi->text, sizeof(mc->searchstr));
while ((mi = TAILQ_NEXT(mi, resultentry)) != NULL) {
i = 0;
while (tolower(mc->searchstr[i]) ==
tolower(mi->text[i]))
i++;
mc->searchstr[i] = '\0';
}
mc->changed = 1;
}
break;
case CTL_ALL: case CTL_ALL:
mc->list = !mc->list; mc->list = !mc->list;
break; break;
@ -484,6 +549,9 @@ menu_keycode(XKeyEvent *ev, enum ctltype *ctl, char *chr)
case XK_Return: case XK_Return:
*ctl = CTL_RETURN; *ctl = CTL_RETURN;
break; break;
case XK_Tab:
*ctl = CTL_TAB;
break;
case XK_Up: case XK_Up:
*ctl = CTL_UP; *ctl = CTL_UP;
break; break;

View File

@ -24,9 +24,9 @@
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "calmwm.h" #include "calmwm.h"
@ -253,7 +253,7 @@ mousefunc_menu_unhide(struct client_ctx *cc, void *arg)
} else { } else {
while ((mi = TAILQ_FIRST(&menuq)) != NULL) { while ((mi = TAILQ_FIRST(&menuq)) != NULL) {
TAILQ_REMOVE(&menuq, mi, entry); TAILQ_REMOVE(&menuq, mi, entry);
xfree(mi); free(mi);
} }
} }
} }
@ -282,6 +282,6 @@ mousefunc_menu_cmd(struct client_ctx *cc, void *arg)
else else
while ((mi = TAILQ_FIRST(&menuq)) != NULL) { while ((mi = TAILQ_FIRST(&menuq)) != NULL) {
TAILQ_REMOVE(&menuq, mi, entry); TAILQ_REMOVE(&menuq, mi, entry);
xfree(mi); free(mi);
} }
} }

View File

@ -23,9 +23,9 @@
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "calmwm.h" #include "calmwm.h"

View File

@ -25,13 +25,16 @@
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
#include <fnmatch.h> #include <fnmatch.h>
#include <glob.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "calmwm.h" #include "calmwm.h"
#define PATH_EXEC 0x1
static int strsubmatch(char *, char *, int); static int strsubmatch(char *, char *, int);
/* /*
@ -161,6 +164,43 @@ search_print_client(struct menu *mi, int list)
} }
} }
static void
search_match_path(struct menu_q *menuq, struct menu_q *resultq, char *search, int flag)
{
struct menu *mi;
char pattern[MAXPATHLEN];
glob_t g;
int i;
TAILQ_INIT(resultq);
(void)strlcpy(pattern, search, sizeof(pattern));
(void)strlcat(pattern, "*", sizeof(pattern));
if (glob(pattern, GLOB_MARK, NULL, &g) != 0)
return;
for (i = 0; i < g.gl_pathc; i++) {
if ((flag & PATH_EXEC) && access(g.gl_pathv[i], X_OK))
continue;
mi = xcalloc(1, sizeof(*mi));
(void)strlcpy(mi->text, g.gl_pathv[i], sizeof(mi->text));
TAILQ_INSERT_TAIL(resultq, mi, resultentry);
}
globfree(&g);
}
void
search_match_path_exec(struct menu_q *menuq, struct menu_q *resultq, char *search)
{
return (search_match_path(menuq, resultq, search, PATH_EXEC));
}
void
search_match_path_any(struct menu_q *menuq, struct menu_q *resultq, char *search)
{
return (search_match_path(menuq, resultq, search, 0));
}
void void
search_match_text(struct menu_q *menuq, struct menu_q *resultq, char *search) search_match_text(struct menu_q *menuq, struct menu_q *resultq, char *search)
{ {
@ -196,6 +236,14 @@ search_match_exec(struct menu_q *menuq, struct menu_q *resultq, char *search)
} }
} }
void
search_match_exec_path(struct menu_q *menuq, struct menu_q *resultq, char *search)
{
search_match_exec(menuq, resultq, search);
if (TAILQ_EMPTY(resultq))
search_match_path_exec(menuq, resultq, search);
}
static int static int
strsubmatch(char *sub, char *str, int zeroidx) strsubmatch(char *sub, char *str, int zeroidx)
{ {

2
util.c
View File

@ -23,9 +23,9 @@
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "calmwm.h" #include "calmwm.h"

View File

@ -30,9 +30,9 @@
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "calmwm.h" #include "calmwm.h"

View File

@ -23,9 +23,10 @@
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "calmwm.h" #include "calmwm.h"
@ -35,6 +36,8 @@ xmalloc(size_t siz)
{ {
void *p; void *p;
if (siz == 0)
errx(1, "xmalloc: zero size");
if ((p = malloc(siz)) == NULL) if ((p = malloc(siz)) == NULL)
err(1, "malloc"); err(1, "malloc");
@ -46,18 +49,16 @@ xcalloc(size_t no, size_t siz)
{ {
void *p; void *p;
if (siz == 0 || no == 0)
errx(1, "xcalloc: zero size");
if (SIZE_MAX / no < siz)
errx(1, "xcalloc: no * siz > SIZE_MAX");
if ((p = calloc(no, siz)) == NULL) if ((p = calloc(no, siz)) == NULL)
err(1, "calloc"); err(1, "calloc");
return (p); return (p);
} }
void
xfree(void *p)
{
free(p);
}
char * char *
xstrdup(const char *str) xstrdup(const char *str)
{ {

13
xutil.c
View File

@ -23,9 +23,9 @@
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "calmwm.h" #include "calmwm.h"
@ -188,7 +188,7 @@ xu_getstrprop(Window win, Atom atm, char **text) {
XTextProperty prop2; XTextProperty prop2;
if (Xutf8TextListToTextProperty(X_Dpy, list, nitems, if (Xutf8TextListToTextProperty(X_Dpy, list, nitems,
XUTF8StringStyle, &prop2) == Success) { XUTF8StringStyle, &prop2) == Success) {
*text = xstrdup(prop2.value); *text = xstrdup((const char *)prop2.value);
XFree(prop2.value); XFree(prop2.value);
} }
} else { } else {
@ -292,7 +292,8 @@ xu_ewmh_net_supported_wm_check(struct screen_ctx *sc)
XChangeProperty(X_Dpy, w, ewmh[_NET_SUPPORTING_WM_CHECK].atom, XChangeProperty(X_Dpy, w, ewmh[_NET_SUPPORTING_WM_CHECK].atom,
XA_WINDOW, 32, PropModeReplace, (unsigned char *)&w, 1); XA_WINDOW, 32, PropModeReplace, (unsigned char *)&w, 1);
XChangeProperty(X_Dpy, w, ewmh[_NET_WM_NAME].atom, XChangeProperty(X_Dpy, w, ewmh[_NET_WM_NAME].atom,
XA_WM_NAME, 8, PropModeReplace, WMNAME, strlen(WMNAME)); XA_WM_NAME, 8, PropModeReplace, (unsigned char *)WMNAME,
strlen(WMNAME));
} }
void void
@ -339,7 +340,7 @@ xu_ewmh_net_client_list(struct screen_ctx *sc)
winlist[j++] = cc->win; winlist[j++] = cc->win;
XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_CLIENT_LIST].atom, XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_CLIENT_LIST].atom,
XA_WINDOW, 32, PropModeReplace, (unsigned char *)winlist, i); XA_WINDOW, 32, PropModeReplace, (unsigned char *)winlist, i);
xfree(winlist); free(winlist);
} }
void void
@ -396,10 +397,10 @@ xu_ewmh_net_current_desktop(struct screen_ctx *sc, long idx)
} }
void void
xu_ewmh_net_desktop_names(struct screen_ctx *sc, unsigned char *data, int n) xu_ewmh_net_desktop_names(struct screen_ctx *sc, char *data, int n)
{ {
XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_DESKTOP_NAMES].atom, XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_DESKTOP_NAMES].atom,
cwmh[UTF8_STRING].atom, 8, PropModeReplace, data, n); cwmh[UTF8_STRING].atom, 8, PropModeReplace, (unsigned char *)data, n);
} }
/* Application Window Properties */ /* Application Window Properties */