From 457938fbd750388907876ce30a98b216ae758922 Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 10 May 2013 15:44:43 +0000 Subject: fix KeySym type --- xutil.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'xutil.c') diff --git a/xutil.c b/xutil.c index 765b664..496fe0b 100644 --- a/xutil.c +++ b/xutil.c @@ -88,7 +88,7 @@ xu_ptr_setpos(Window win, int x, int y) } void -xu_key_grab(Window win, int mask, int keysym) +xu_key_grab(Window win, int mask, KeySym keysym) { KeyCode code; int i; @@ -104,7 +104,7 @@ xu_key_grab(Window win, int mask, int keysym) } void -xu_key_ungrab(Window win, int mask, int keysym) +xu_key_ungrab(Window win, int mask, KeySym keysym) { KeyCode code; int i; -- cgit 1.4.1 From e05c0a2c600d22841d6950abf6fc013efe6a7cad Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 10 May 2013 16:05:34 +0000 Subject: int type fixes --- conf.c | 6 +++--- xevents.c | 2 +- xutil.c | 14 ++++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) (limited to 'xutil.c') diff --git a/conf.c b/conf.c index 06d4e1c..ee18fcd 100644 --- a/conf.c +++ b/conf.c @@ -195,7 +195,7 @@ m_binds[] = { void conf_init(struct conf *c) { - int i; + u_int i; bzero(c, sizeof(*c)); @@ -459,7 +459,7 @@ conf_bindname(struct conf *c, char *name, char *binding) { struct keybinding *current_binding; char *substring, *tmp; - int i; + u_int i; current_binding = xcalloc(1, sizeof(*current_binding)); @@ -564,7 +564,7 @@ conf_mousebind(struct conf *c, char *name, char *binding) struct mousebinding *current_binding; char *substring, *tmp; const char *errstr; - int i; + u_int i; current_binding = xcalloc(1, sizeof(*current_binding)); diff --git a/xevents.c b/xevents.c index 65dba3b..b182299 100644 --- a/xevents.c +++ b/xevents.c @@ -323,7 +323,7 @@ xev_handle_keyrelease(XEvent *ee) struct screen_ctx *sc; struct client_ctx *cc; KeySym keysym; - int i; + u_int i; sc = screen_fromroot(e->root); cc = client_current(); diff --git a/xutil.c b/xutil.c index 496fe0b..6aee4d9 100644 --- a/xutil.c +++ b/xutil.c @@ -56,7 +56,8 @@ xu_ptr_ungrab(void) void xu_btn_grab(Window win, int mask, u_int btn) { - int i; + u_int i; + for (i = 0; i < nitems(ign_mods); i++) XGrabButton(X_Dpy, btn, (mask | ign_mods[i]), win, False, BUTTONMASK, GrabModeAsync, @@ -66,7 +67,8 @@ xu_btn_grab(Window win, int mask, u_int btn) void xu_btn_ungrab(Window win, int mask, u_int btn) { - int i; + u_int i; + for (i = 0; i < nitems(ign_mods); i++) XUngrabButton(X_Dpy, btn, (mask | ign_mods[i]), win); } @@ -91,7 +93,7 @@ void xu_key_grab(Window win, int mask, KeySym keysym) { KeyCode code; - int i; + u_int i; code = XKeysymToKeycode(X_Dpy, keysym); if ((XkbKeycodeToKeysym(X_Dpy, code, 0, 0) != keysym) && @@ -107,7 +109,7 @@ void xu_key_ungrab(Window win, int mask, KeySym keysym) { KeyCode code; - int i; + u_int i; code = XKeysymToKeycode(X_Dpy, keysym); if ((XkbKeycodeToKeysym(X_Dpy, code, 0, 0) != keysym) && @@ -258,7 +260,7 @@ struct atom_ctx ewmh[EWMH_NITEMS] = { void xu_getatoms(void) { - int i; + u_int i; for (i = 0; i < nitems(cwmh); i++) cwmh[i].atom = XInternAtom(X_Dpy, cwmh[i].name, False); @@ -271,7 +273,7 @@ void xu_ewmh_net_supported(struct screen_ctx *sc) { Atom atom[EWMH_NITEMS]; - int i; + u_int i; for (i = 0; i < nitems(ewmh); i++) atom[i] = ewmh[i].atom; -- cgit 1.4.1 From 9b9e95d74236b135d799c19c94d9b8070ffc6a58 Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 10 May 2013 16:32:47 +0000 Subject: more type fixes for mask/button --- calmwm.h | 14 +++++++------- conf.c | 2 +- xevents.c | 2 +- xutil.c | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) (limited to 'xutil.c') diff --git a/calmwm.h b/calmwm.h index 3cb8442..5fd166d 100644 --- a/calmwm.h +++ b/calmwm.h @@ -235,7 +235,7 @@ struct keybinding { TAILQ_ENTRY(keybinding) entry; void (*callback)(struct client_ctx *, union arg *); union arg argument; - int modmask; + u_int modmask; KeySym keysym; int keycode; #define KBFLAG_NEEDCLIENT 0x0001 @@ -247,8 +247,8 @@ TAILQ_HEAD(keybinding_q, keybinding); struct mousebinding { TAILQ_ENTRY(mousebinding) entry; void (*callback)(struct client_ctx *, void *); - int modmask; - int button; + u_int modmask; + u_int button; #define MOUSEBIND_CTX_ROOT 0x0001 #define MOUSEBIND_CTX_WIN 0x0002 int context; @@ -465,11 +465,11 @@ unsigned long xu_getcolor(struct screen_ctx *, char *); int xu_getprop(Window, Atom, Atom, long, u_char **); int xu_get_wm_state(Window, int *); int xu_getstrprop(Window, Atom, char **); -void xu_key_grab(Window, int, KeySym); -void xu_key_ungrab(Window, int, KeySym); +void xu_key_grab(Window, u_int, KeySym); +void xu_key_ungrab(Window, u_int, KeySym); void xu_ptr_getpos(Window, int *, int *); -int xu_ptr_grab(Window, int, Cursor); -int xu_ptr_regrab(int, Cursor); +int xu_ptr_grab(Window, u_int, Cursor); +int xu_ptr_regrab(u_int, Cursor); void xu_ptr_setpos(Window, int, int); void xu_ptr_ungrab(void); void xu_sendmsg(Window, Atom, long); diff --git a/conf.c b/conf.c index ee18fcd..e580b9e 100644 --- a/conf.c +++ b/conf.c @@ -627,7 +627,7 @@ void conf_grab_mouse(struct client_ctx *cc) { struct mousebinding *mb; - int button; + u_int button; TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) { if (mb->context != MOUSEBIND_CTX_WIN) diff --git a/xevents.c b/xevents.c index b182299..073a919 100644 --- a/xevents.c +++ b/xevents.c @@ -277,7 +277,7 @@ xev_handle_keypress(XEvent *ee) struct client_ctx *cc = NULL, fakecc; struct keybinding *kb; KeySym keysym, skeysym; - int modshift; + u_int modshift; keysym = XkbKeycodeToKeysym(X_Dpy, e->keycode, 0, 0); skeysym = XkbKeycodeToKeysym(X_Dpy, e->keycode, 0, 1); diff --git a/xutil.c b/xutil.c index 6aee4d9..a2a6bec 100644 --- a/xutil.c +++ b/xutil.c @@ -33,7 +33,7 @@ static unsigned int ign_mods[] = { 0, LockMask, Mod2Mask, Mod2Mask | LockMask }; int -xu_ptr_grab(Window win, int mask, Cursor curs) +xu_ptr_grab(Window win, u_int mask, Cursor curs) { return (XGrabPointer(X_Dpy, win, False, mask, GrabModeAsync, GrabModeAsync, @@ -41,7 +41,7 @@ xu_ptr_grab(Window win, int mask, Cursor curs) } int -xu_ptr_regrab(int mask, Cursor curs) +xu_ptr_regrab(u_int mask, Cursor curs) { return (XChangeActivePointerGrab(X_Dpy, mask, curs, CurrentTime) == GrabSuccess ? 0 : -1); @@ -90,7 +90,7 @@ xu_ptr_setpos(Window win, int x, int y) } void -xu_key_grab(Window win, int mask, KeySym keysym) +xu_key_grab(Window win, u_int mask, KeySym keysym) { KeyCode code; u_int i; @@ -106,7 +106,7 @@ xu_key_grab(Window win, int mask, KeySym keysym) } void -xu_key_ungrab(Window win, int mask, KeySym keysym) +xu_key_ungrab(Window win, u_int mask, KeySym keysym) { KeyCode code; u_int i; -- cgit 1.4.1 From 556a50d8f7f6804630bfffc6b1f1817fd67a273b Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 19 May 2013 17:03:55 +0000 Subject: treat WM_CHANGE_STATE like other atoms --- calmwm.h | 1 + xevents.c | 7 ++----- xutil.c | 1 + 3 files changed, 4 insertions(+), 5 deletions(-) (limited to 'xutil.c') diff --git a/calmwm.h b/calmwm.h index 033ed5a..032e8b8 100644 --- a/calmwm.h +++ b/calmwm.h @@ -527,6 +527,7 @@ enum { WM_PROTOCOLS, _MOTIF_WM_HINTS, UTF8_STRING, + WM_CHANGE_STATE, CWMH_NITEMS }; enum { diff --git a/xevents.c b/xevents.c index 9849fb5..174985d 100644 --- a/xevents.c +++ b/xevents.c @@ -340,16 +340,13 @@ static void xev_handle_clientmessage(XEvent *ee) { XClientMessageEvent *e = &ee->xclient; - Atom xa_wm_change_state; struct client_ctx *cc; - xa_wm_change_state = XInternAtom(X_Dpy, "WM_CHANGE_STATE", False); - if ((cc = client_find(e->window)) == NULL) return; - if (e->message_type == xa_wm_change_state && e->format == 32 && - e->data.l[0] == IconicState) + if (e->message_type == cwmh[WM_CHANGE_STATE].atom && + e->format == 32 && e->data.l[0] == IconicState) client_hide(cc); } diff --git a/xutil.c b/xutil.c index a2a6bec..764116a 100644 --- a/xutil.c +++ b/xutil.c @@ -239,6 +239,7 @@ struct atom_ctx cwmh[CWMH_NITEMS] = { {"WM_PROTOCOLS", None}, {"_MOTIF_WM_HINTS", None}, {"UTF8_STRING", None}, + {"WM_CHANGE_STATE", None}, }; struct atom_ctx ewmh[EWMH_NITEMS] = { {"_NET_SUPPORTED", None}, -- cgit 1.4.1 From c84145661e14cc62032f30c6a8c744ba84b95601 Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 19 May 2013 17:05:52 +0000 Subject: add support for _NET_CLOSE_WINDOW --- calmwm.h | 1 + xevents.c | 3 +++ xutil.c | 1 + 3 files changed, 5 insertions(+) (limited to 'xutil.c') diff --git a/calmwm.h b/calmwm.h index 032e8b8..cf980e1 100644 --- a/calmwm.h +++ b/calmwm.h @@ -545,6 +545,7 @@ enum { _NET_WORKAREA, _NET_WM_NAME, _NET_WM_DESKTOP, + _NET_CLOSE_WINDOW, EWMH_NITEMS }; struct atom_ctx { diff --git a/xevents.c b/xevents.c index 174985d..91da64a 100644 --- a/xevents.c +++ b/xevents.c @@ -348,6 +348,9 @@ xev_handle_clientmessage(XEvent *ee) if (e->message_type == cwmh[WM_CHANGE_STATE].atom && e->format == 32 && e->data.l[0] == IconicState) client_hide(cc); + + if (e->message_type == ewmh[_NET_CLOSE_WINDOW].atom) + client_send_delete(cc); } static void diff --git a/xutil.c b/xutil.c index 764116a..d9f2106 100644 --- a/xutil.c +++ b/xutil.c @@ -256,6 +256,7 @@ struct atom_ctx ewmh[EWMH_NITEMS] = { {"_NET_WORKAREA", None}, {"_NET_WM_NAME", None}, {"_NET_WM_DESKTOP", None}, + {"_NET_CLOSE_WINDOW", None}, }; void -- cgit 1.4.1 From dac00a232f975967dec9ae8e838b069ec01e6c62 Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 19 May 2013 23:09:59 +0000 Subject: - switch border colors to Xft - merge border/menu color structures/functions since they now both use Xft - switch xu_xorcolor to operating on XftColor instead of just XRenderColor (basically adding pixel) - if color name allocation fails, revert back to default (this, along with font validation should occur during config parse, but we don't have screens setup yet - likely to change at some point) --- calmwm.h | 29 ++++++++++------------------- client.c | 8 ++++---- conf.c | 47 +++++++++++++++++++++++++++++++---------------- font.c | 22 +--------------------- parse.y | 21 +++++++++------------ xutil.c | 24 ++++++------------------ 6 files changed, 61 insertions(+), 90 deletions(-) (limited to 'xutil.c') diff --git a/calmwm.h b/calmwm.h index cf980e1..ebc5bd0 100644 --- a/calmwm.h +++ b/calmwm.h @@ -85,20 +85,16 @@ union arg { int i; }; -enum menucolor { - CWM_COLOR_MENU_FG, - CWM_COLOR_MENU_BG, - CWM_COLOR_MENU_FONT, - CWM_COLOR_MENU_FONT_SEL, - CWM_COLOR_MENU_MAX -}; - -enum bordercolor { +enum color { CWM_COLOR_BORDER_ACTIVE, CWM_COLOR_BORDER_INACTIVE, CWM_COLOR_BORDER_GROUP, CWM_COLOR_BORDER_UNGROUP, - CWM_COLOR_BORDER_MAX + CWM_COLOR_MENU_FG, + CWM_COLOR_MENU_BG, + CWM_COLOR_MENU_FONT, + CWM_COLOR_MENU_FONT_SEL, + CWM_COLOR_MAX }; struct geom { @@ -213,13 +209,12 @@ struct screen_ctx { Colormap colormap; Window rootwin; Window menuwin; - unsigned long color[CWM_COLOR_BORDER_MAX]; int cycling; struct geom view; /* viewable area */ struct geom work; /* workable area, gap-applied */ struct gap gap; struct cycle_entry_q mruq; - XftColor xftcolor[CWM_COLOR_MENU_MAX]; + XftColor xftcolor[CWM_COLOR_MAX]; XftDraw *xftdraw; XftFont *xftfont; int xinerama_no; @@ -293,8 +288,7 @@ struct conf { #define CONF_SNAPDIST 0 int snapdist; struct gap gap; - char *color[CWM_COLOR_BORDER_MAX]; - char *menucolor[CWM_COLOR_MENU_MAX]; + char *color[CWM_COLOR_MAX]; char termpath[MAXPATHLEN]; char lockpath[MAXPATHLEN]; char known_hosts[MAXPATHLEN]; @@ -452,8 +446,7 @@ void conf_ungrab(struct conf *, struct keybinding *); void font_draw(struct screen_ctx *, const char *, Drawable, int, int, int); -void font_init(struct screen_ctx *, const char *, - const char **); +void font_init(struct screen_ctx *, const char *); int font_width(XftFont *, const char *, int); void xev_loop(void); @@ -462,7 +455,6 @@ void xu_btn_grab(Window, int, u_int); void xu_btn_ungrab(Window, int, u_int); void xu_configure(struct client_ctx *); void xu_getatoms(void); -unsigned long xu_getcolor(struct screen_ctx *, char *); int xu_getprop(Window, Atom, Atom, long, u_char **); int xu_get_wm_state(Window, int *); int xu_getstrprop(Window, Atom, char **); @@ -475,8 +467,7 @@ void xu_ptr_setpos(Window, int, int); void xu_ptr_ungrab(void); void xu_sendmsg(Window, Atom, long); void xu_set_wm_state(Window win, int); -void xu_xorcolor(XRenderColor, XRenderColor, - XRenderColor *); +void xu_xorcolor(XftColor, XftColor, XftColor *); void xu_ewmh_net_supported(struct screen_ctx *); void xu_ewmh_net_supported_wm_check(struct screen_ctx *); diff --git a/client.c b/client.c index 6001372..9ebd8bc 100644 --- a/client.c +++ b/client.c @@ -480,17 +480,17 @@ client_draw_border(struct client_ctx *cc) if (cc->active) switch (cc->flags & CLIENT_HIGHLIGHT) { case CLIENT_GROUP: - pixel = sc->color[CWM_COLOR_BORDER_GROUP]; + pixel = sc->xftcolor[CWM_COLOR_BORDER_GROUP].pixel; break; case CLIENT_UNGROUP: - pixel = sc->color[CWM_COLOR_BORDER_UNGROUP]; + pixel = sc->xftcolor[CWM_COLOR_BORDER_UNGROUP].pixel; break; default: - pixel = sc->color[CWM_COLOR_BORDER_ACTIVE]; + pixel = sc->xftcolor[CWM_COLOR_BORDER_ACTIVE].pixel; break; } else - pixel = sc->color[CWM_COLOR_BORDER_INACTIVE]; + pixel = sc->xftcolor[CWM_COLOR_BORDER_INACTIVE].pixel; XSetWindowBorderWidth(X_Dpy, cc->win, cc->bwidth); XSetWindowBorder(X_Dpy, cc->win, pixel); diff --git a/conf.c b/conf.c index 698ab4c..657c686 100644 --- a/conf.c +++ b/conf.c @@ -84,31 +84,49 @@ conf_ignore(struct conf *c, char *val) TAILQ_INSERT_TAIL(&c->ignoreq, wm, entry); } -static char *menu_color_binds[CWM_COLOR_MENU_MAX] = { - "black", /* CWM_COLOR_MENU_FG */ - "white", /* CWM_COLOR_MENU_BG */ - "black", /* CWM_COLOR_MENU_FONT */ - "", /* CWM_COLOR_MENU_FONT_SEL */ -}; - -static char *color_binds[CWM_COLOR_BORDER_MAX] = { +static char *color_binds[CWM_COLOR_MAX] = { "#CCCCCC", /* CWM_COLOR_BORDER_ACTIVE */ "#666666", /* CWM_COLOR_BORDER_INACTIVE */ "blue", /* CWM_COLOR_BORDER_GROUP */ "red", /* CWM_COLOR_BORDER_UNGROUP */ + "black", /* CWM_COLOR_MENU_FG */ + "white", /* CWM_COLOR_MENU_BG */ + "black", /* CWM_COLOR_MENU_FONT */ + "", /* CWM_COLOR_MENU_FONT_SEL */ }; void conf_screen(struct screen_ctx *sc) { - int i; + int i; + XftColor xc; sc->gap = Conf.gap; - font_init(sc, Conf.font, (const char **)Conf.menucolor); + font_init(sc, Conf.font); + + for (i = 0; i < CWM_COLOR_MAX; i++) { + if (*Conf.color[i] == '\0') + break; + if (XftColorAllocName(X_Dpy, sc->visual, sc->colormap, + Conf.color[i], &xc)) { + sc->xftcolor[i] = xc; + XftColorFree(X_Dpy, sc->visual, sc->colormap, &xc); + } else { + warnx("XftColorAllocName: '%s'", Conf.color[i]); + XftColorAllocName(X_Dpy, sc->visual, sc->colormap, + color_binds[i], &sc->xftcolor[i]); + } + } + if (i == CWM_COLOR_MAX) + return; - for (i = 0; i < CWM_COLOR_BORDER_MAX; i++) - sc->color[i] = xu_getcolor(sc, Conf.color[i]); + xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_BG], + sc->xftcolor[CWM_COLOR_MENU_FG], &xc); + xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_FONT], xc, &xc); + if (!XftColorAllocValue(X_Dpy, sc->visual, sc->colormap, + &xc.color, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL])) + warnx("XftColorAllocValue: '%s'", Conf.color[i]); } static struct { @@ -210,9 +228,6 @@ conf_init(struct conf *c) for (i = 0; i < nitems(color_binds); i++) c->color[i] = xstrdup(color_binds[i]); - for (i = 0; i < nitems(menu_color_binds); i++) - c->menucolor[i] = xstrdup(menu_color_binds[i]); - /* Default term/lock */ (void)strlcpy(c->termpath, "xterm", sizeof(c->termpath)); (void)strlcpy(c->lockpath, "xlock", sizeof(c->lockpath)); @@ -260,7 +275,7 @@ conf_clear(struct conf *c) free(mb); } - for (i = 0; i < CWM_COLOR_BORDER_MAX; i++) + for (i = 0; i < CWM_COLOR_MAX; i++) free(c->color[i]); free(c->font); diff --git a/font.c b/font.c index e2b68c0..f4251d9 100644 --- a/font.c +++ b/font.c @@ -31,11 +31,8 @@ #include "calmwm.h" void -font_init(struct screen_ctx *sc, const char *name, const char **color) +font_init(struct screen_ctx *sc, const char *name) { - int i; - XRenderColor c; - sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin, sc->visual, sc->colormap); if (sc->xftdraw == NULL) @@ -44,23 +41,6 @@ font_init(struct screen_ctx *sc, const char *name, const char **color) sc->xftfont = XftFontOpenName(X_Dpy, sc->which, name); if (sc->xftfont == NULL) errx(1, "XftFontOpenName"); - - for (i = 0; i < CWM_COLOR_MENU_MAX; i++) { - if (*color[i] == '\0') - break; - if (!XftColorAllocName(X_Dpy, sc->visual, sc->colormap, - color[i], &sc->xftcolor[i])) - errx(1, "XftColorAllocName"); - } - if (i == CWM_COLOR_MENU_MAX) - return; - - xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_BG].color, - sc->xftcolor[CWM_COLOR_MENU_FG].color, &c); - xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_FONT].color, c, &c); - if (!XftColorAllocValue(X_Dpy, sc->visual, sc->colormap, - &c, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL])) - errx(1, "XftColorAllocValue"); } int diff --git a/parse.y b/parse.y index 9de56da..e0c13bb 100644 --- a/parse.y +++ b/parse.y @@ -198,20 +198,20 @@ colors : ACTIVEBORDER STRING { conf->color[CWM_COLOR_BORDER_UNGROUP] = $2; } | MENUBG STRING { - free(conf->menucolor[CWM_COLOR_MENU_BG]); - conf->menucolor[CWM_COLOR_MENU_BG] = $2; + free(conf->color[CWM_COLOR_MENU_BG]); + conf->color[CWM_COLOR_MENU_BG] = $2; } | MENUFG STRING { - free(conf->menucolor[CWM_COLOR_MENU_FG]); - conf->menucolor[CWM_COLOR_MENU_FG] = $2; + free(conf->color[CWM_COLOR_MENU_FG]); + conf->color[CWM_COLOR_MENU_FG] = $2; } | FONTCOLOR STRING { - free(conf->menucolor[CWM_COLOR_MENU_FONT]); - conf->menucolor[CWM_COLOR_MENU_FONT] = $2; + free(conf->color[CWM_COLOR_MENU_FONT]); + conf->color[CWM_COLOR_MENU_FONT] = $2; } | FONTSELCOLOR STRING { - free(conf->menucolor[CWM_COLOR_MENU_FONT_SEL]); - conf->menucolor[CWM_COLOR_MENU_FONT_SEL] = $2; + free(conf->color[CWM_COLOR_MENU_FONT_SEL]); + conf->color[CWM_COLOR_MENU_FONT_SEL] = $2; } ; %% @@ -589,12 +589,9 @@ parse_config(const char *filename, struct conf *xconf) (void)strlcpy(xconf->lockpath, conf->lockpath, sizeof(xconf->lockpath)); - for (i = 0; i < CWM_COLOR_BORDER_MAX; i++) + for (i = 0; i < CWM_COLOR_MAX; i++) xconf->color[i] = conf->color[i]; - for (i = 0; i < CWM_COLOR_MENU_MAX; i++) - xconf->menucolor[i] = conf->menucolor[i]; - xconf->font = conf->font; } diff --git a/xutil.c b/xutil.c index d9f2106..bcc7366 100644 --- a/xutil.c +++ b/xutil.c @@ -420,24 +420,12 @@ xu_ewmh_net_wm_desktop(struct client_ctx *cc) XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&no, 1); } -unsigned long -xu_getcolor(struct screen_ctx *sc, char *name) -{ - XColor color, tmp; - - if (!XAllocNamedColor(X_Dpy, sc->colormap, name, &color, &tmp)) { - warnx("XAllocNamedColor error: '%s'", name); - return (0); - } - - return (color.pixel); -} - void -xu_xorcolor(XRenderColor a, XRenderColor b, XRenderColor *r) +xu_xorcolor(XftColor a, XftColor b, XftColor *r) { - r->red = a.red ^ b.red; - r->green = a.green ^ b.green; - r->blue = a.blue ^ b.blue; - r->alpha = 0xffff; + r->pixel = a.pixel ^ b.pixel; + r->color.red = a.color.red ^ b.color.red; + r->color.green = a.color.green ^ b.color.green; + r->color.blue = a.color.blue ^ b.color.blue; + r->color.alpha = 0xffff; } -- cgit 1.4.1 From 5b4c55616a58c058cb1f3f80c4e04a24b8e824a3 Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 19 May 2013 23:38:20 +0000 Subject: move the 2 small font helper functions to xutil.c --- Makefile | 2 +- calmwm.h | 7 +++---- font.c | 51 --------------------------------------------------- menu.c | 10 +++++----- mousefunc.c | 5 +++-- xutil.c | 20 ++++++++++++++++++++ 6 files changed, 32 insertions(+), 63 deletions(-) delete mode 100644 font.c (limited to 'xutil.c') diff --git a/Makefile b/Makefile index 1bd9271..25584c7 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ PROG= cwm SRCS= calmwm.c screen.c xmalloc.c client.c menu.c \ search.c util.c xutil.c conf.c xevents.c group.c \ - kbfunc.c mousefunc.c font.c parse.y + kbfunc.c mousefunc.c parse.y CPPFLAGS+= -I${X11BASE}/include -I${X11BASE}/include/freetype2 -I${.CURDIR} diff --git a/calmwm.h b/calmwm.h index a18f92f..b45e9df 100644 --- a/calmwm.h +++ b/calmwm.h @@ -444,10 +444,6 @@ void conf_mousebind(struct conf *, char *, char *); void conf_screen(struct screen_ctx *); void conf_ungrab(struct conf *, struct keybinding *); -void font_draw(struct screen_ctx *, const char *, - Drawable, int, int, int); -int font_width(XftFont *, const char *, int); - void xev_loop(void); void xu_btn_grab(Window, int, u_int); @@ -466,6 +462,9 @@ void xu_ptr_setpos(Window, int, int); void xu_ptr_ungrab(void); void xu_sendmsg(Window, Atom, long); void xu_set_wm_state(Window win, int); +void xu_xft_draw(struct screen_ctx *, const char *, + Drawable, int, int, int); +int xu_xft_width(XftFont *, const char *, int); void xu_xorcolor(XftColor, XftColor, XftColor *); void xu_ewmh_net_supported(struct screen_ctx *); diff --git a/font.c b/font.c deleted file mode 100644 index fc4f3c1..0000000 --- a/font.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * calmwm - the calm window manager - * - * Copyright (c) 2005 Marius Eriksen - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * $OpenBSD$ - */ - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "calmwm.h" - -int -font_width(XftFont *xftfont, const char *text, int len) -{ - XGlyphInfo extents; - - XftTextExtentsUtf8(X_Dpy, xftfont, (const FcChar8*)text, - len, &extents); - - return (extents.xOff); -} - -void -font_draw(struct screen_ctx *sc, const char *text, - Drawable d, int color, int x, int y) -{ - XftDrawChange(sc->xftdraw, d); - XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[color], sc->xftfont, x, y, - (const FcChar8*)text, strlen(text)); -} diff --git a/menu.c b/menu.c index c2bd37c..80e1ce7 100644 --- a/menu.c +++ b/menu.c @@ -367,7 +367,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, if (mc->hasprompt) { (void)snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%s%s", mc->promptstr, PROMPT_SCHAR, mc->searchstr, PROMPT_ECHAR); - mc->width = font_width(sc->xftfont, mc->dispstr, + mc->width = xu_xft_width(sc->xftfont, mc->dispstr, strlen(mc->dispstr)); mc->height = sc->xftfont->height + 1; mc->num = 1; @@ -384,7 +384,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, text = mi->text; } - mc->width = MAX(mc->width, font_width(sc->xftfont, text, + mc->width = MAX(mc->width, xu_xft_width(sc->xftfont, text, MIN(strlen(text), MENU_MAXENTRY))); mc->height += sc->xftfont->height + 1; mc->num++; @@ -419,7 +419,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, mc->width, mc->height); if (mc->hasprompt) { - font_draw(sc, mc->dispstr, sc->menuwin, CWM_COLOR_MENU_FONT, + xu_xft_draw(sc, mc->dispstr, sc->menuwin, CWM_COLOR_MENU_FONT, 0, sc->xftfont->ascent); n = 1; } else @@ -434,7 +434,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, if (mc->y + y > xine.h) break; - font_draw(sc, text, sc->menuwin, CWM_COLOR_MENU_FONT, 0, y); + xu_xft_draw(sc, text, sc->menuwin, CWM_COLOR_MENU_FONT, 0, y); n++; } if (mc->hasprompt && n > 1 && (mc->searchstr[0] != '\0')) { @@ -466,7 +466,7 @@ menu_draw_entry(struct screen_ctx *sc, struct menu_ctx *mc, (sc->xftfont->height + 1) * entry, mc->width, (sc->xftfont->height + 1) + sc->xftfont->descent); color = active ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT; - font_draw(sc, text, sc->menuwin, color, + xu_xft_draw(sc, text, sc->menuwin, color, 0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1); } diff --git a/mousefunc.c b/mousefunc.c index 205f073..64670b5 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -58,11 +58,12 @@ mousefunc_sweep_draw(struct client_ctx *cc) XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0); XMoveResizeWindow(X_Dpy, sc->menuwin, 0, 0, - font_width(sc->xftfont, asize, strlen(asize)), sc->xftfont->height); + xu_xft_width(sc->xftfont, asize, strlen(asize)), + sc->xftfont->height); XMapWindow(X_Dpy, sc->menuwin); XClearWindow(X_Dpy, sc->menuwin); - font_draw(sc, asize, sc->menuwin, CWM_COLOR_MENU_FONT, + xu_xft_draw(sc, asize, sc->menuwin, CWM_COLOR_MENU_FONT, 0, sc->xftfont->ascent + 1); } diff --git a/xutil.c b/xutil.c index bcc7366..3e2b36c 100644 --- a/xutil.c +++ b/xutil.c @@ -429,3 +429,23 @@ xu_xorcolor(XftColor a, XftColor b, XftColor *r) r->color.blue = a.color.blue ^ b.color.blue; r->color.alpha = 0xffff; } + +int +xu_xft_width(XftFont *xftfont, const char *text, int len) +{ + XGlyphInfo extents; + + XftTextExtentsUtf8(X_Dpy, xftfont, (const FcChar8*)text, + len, &extents); + + return (extents.xOff); +} + +void +xu_xft_draw(struct screen_ctx *sc, const char *text, + Drawable d, int color, int x, int y) +{ + XftDrawChange(sc->xftdraw, d); + XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[color], sc->xftfont, + x, y, (const FcChar8*)text, strlen(text)); +} -- cgit 1.4.1 From 270df196ac17363536c44fe342b4e71e1c8450e3 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 20 May 2013 20:21:04 +0000 Subject: - configure menuwin with the screen, then create the xft drawable using the menu window since that's the only place on which we draw - elminate the need to change the drawable on every font draw --- calmwm.h | 3 +-- conf.c | 15 ++++++++++----- menu.c | 15 +++------------ mousefunc.c | 2 +- screen.c | 1 - xutil.c | 4 +--- 6 files changed, 16 insertions(+), 24 deletions(-) (limited to 'xutil.c') diff --git a/calmwm.h b/calmwm.h index b45e9df..5671ece 100644 --- a/calmwm.h +++ b/calmwm.h @@ -426,7 +426,6 @@ struct menu *menu_filter(struct screen_ctx *, struct menu_q *, char *, char *, int, void (*)(struct menu_q *, struct menu_q *, char *), void (*)(struct menu *, int)); -void menu_init(struct screen_ctx *); void menuq_clear(struct menu_q *); int parse_config(const char *, struct conf *); @@ -463,7 +462,7 @@ void xu_ptr_ungrab(void); void xu_sendmsg(Window, Atom, long); void xu_set_wm_state(Window win, int); void xu_xft_draw(struct screen_ctx *, const char *, - Drawable, int, int, int); + int, int, int); int xu_xft_width(XftFont *, const char *, int); void xu_xorcolor(XftColor, XftColor, XftColor *); diff --git a/conf.c b/conf.c index b4d5d9d..984e4cc 100644 --- a/conf.c +++ b/conf.c @@ -103,11 +103,6 @@ conf_screen(struct screen_ctx *sc) sc->gap = Conf.gap; - sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin, - sc->visual, sc->colormap); - if (sc->xftdraw == NULL) - errx(1, "XftDrawCreate"); - sc->xftfont = XftFontOpenName(X_Dpy, sc->which, Conf.font); if (sc->xftfont == NULL) errx(1, "XftFontOpenName"); @@ -134,6 +129,16 @@ conf_screen(struct screen_ctx *sc) if (!XftColorAllocValue(X_Dpy, sc->visual, sc->colormap, &xc.color, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL])) warnx("XftColorAllocValue: '%s'", Conf.color[i]); + + sc->menuwin = XCreateSimpleWindow(X_Dpy, sc->rootwin, 0, 0, 1, 1, + Conf.bwidth, + sc->xftcolor[CWM_COLOR_MENU_FG].pixel, + sc->xftcolor[CWM_COLOR_MENU_BG].pixel); + + sc->xftdraw = XftDrawCreate(X_Dpy, sc->menuwin, + sc->visual, sc->colormap); + if (sc->xftdraw == NULL) + errx(1, "XftDrawCreate"); } static struct { diff --git a/menu.c b/menu.c index e743ad2..5313efb 100644 --- a/menu.c +++ b/menu.c @@ -76,15 +76,6 @@ static int menu_calc_entry(struct menu_ctx *, int, int); static struct menu *menu_complete_path(struct menu_ctx *); static int menu_keycode(XKeyEvent *, enum ctltype *, char *); -void -menu_init(struct screen_ctx *sc) -{ - sc->menuwin = XCreateSimpleWindow(X_Dpy, sc->rootwin, 0, 0, 1, 1, - Conf.bwidth, - sc->xftcolor[CWM_COLOR_MENU_FG].pixel, - sc->xftcolor[CWM_COLOR_MENU_BG].pixel); -} - struct menu * menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt, char *initial, int flags, @@ -417,7 +408,7 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) mc->width, mc->height); if (mc->hasprompt) { - xu_xft_draw(sc, mc->dispstr, sc->menuwin, CWM_COLOR_MENU_FONT, + xu_xft_draw(sc, mc->dispstr, CWM_COLOR_MENU_FONT, 0, sc->xftfont->ascent); n = 1; } else @@ -432,7 +423,7 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) if (mc->y + y > xine.h) break; - xu_xft_draw(sc, text, sc->menuwin, CWM_COLOR_MENU_FONT, 0, y); + xu_xft_draw(sc, text, CWM_COLOR_MENU_FONT, 0, y); n++; } if (mc->hasprompt && n > 1 && (mc->searchstr[0] != '\0')) { @@ -465,7 +456,7 @@ menu_draw_entry(struct menu_ctx *mc, struct menu_q *resultq, (sc->xftfont->height + 1) * entry, mc->width, (sc->xftfont->height + 1) + sc->xftfont->descent); color = active ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT; - xu_xft_draw(sc, text, sc->menuwin, color, + xu_xft_draw(sc, text, color, 0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1); } diff --git a/mousefunc.c b/mousefunc.c index 64670b5..a41a3ad 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -63,7 +63,7 @@ mousefunc_sweep_draw(struct client_ctx *cc) XMapWindow(X_Dpy, sc->menuwin); XClearWindow(X_Dpy, sc->menuwin); - xu_xft_draw(sc, asize, sc->menuwin, CWM_COLOR_MENU_FONT, + xu_xft_draw(sc, asize, CWM_COLOR_MENU_FONT, 0, sc->xftfont->ascent + 1); } diff --git a/screen.c b/screen.c index 8435859..f8abae2 100644 --- a/screen.c +++ b/screen.c @@ -56,7 +56,6 @@ screen_init(int which) TAILQ_INIT(&sc->mruq); group_init(sc); - menu_init(sc); rootattr.cursor = Cursor_normal; rootattr.event_mask = SubstructureRedirectMask|SubstructureNotifyMask| diff --git a/xutil.c b/xutil.c index 3e2b36c..d5055f2 100644 --- a/xutil.c +++ b/xutil.c @@ -442,10 +442,8 @@ xu_xft_width(XftFont *xftfont, const char *text, int len) } void -xu_xft_draw(struct screen_ctx *sc, const char *text, - Drawable d, int color, int x, int y) +xu_xft_draw(struct screen_ctx *sc, const char *text, int color, int x, int y) { - XftDrawChange(sc->xftdraw, d); XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[color], sc->xftfont, x, y, (const FcChar8*)text, strlen(text)); } -- cgit 1.4.1 From 284af4ca0c40d7a90ea0f574924abb707db7db05 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 20 May 2013 21:13:58 +0000 Subject: add support for _NET_WM_STATE_MAXIMIZED_{HORZ,VERT}; from Alexander Polakov. while I'm unsure of the final look of _NET_WM_STATE, there's no reason to delay this support. --- calmwm.h | 7 +++++++ client.c | 5 +++++ xutil.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) (limited to 'xutil.c') diff --git a/calmwm.h b/calmwm.h index 5671ece..e525cbf 100644 --- a/calmwm.h +++ b/calmwm.h @@ -481,6 +481,9 @@ void xu_ewmh_net_desktop_names(struct screen_ctx *, char *, int); void xu_ewmh_net_wm_desktop(struct client_ctx *); +Atom *xu_ewmh_get_net_wm_state(struct client_ctx *, int *); +void xu_ewmh_set_net_wm_state(struct client_ctx *); +void xu_ewmh_restore_net_wm_state(struct client_ctx *); void u_exec(char *); void u_spawn(char *); @@ -534,6 +537,10 @@ enum { _NET_WM_NAME, _NET_WM_DESKTOP, _NET_CLOSE_WINDOW, + _NET_WM_STATE, +#define _NET_WM_STATES_NITEMS 2 + _NET_WM_STATE_MAXIMIZED_VERT, + _NET_WM_STATE_MAXIMIZED_HORZ, EWMH_NITEMS }; struct atom_ctx { diff --git a/client.c b/client.c index 9ebd8bc..605c2a4 100644 --- a/client.c +++ b/client.c @@ -133,6 +133,7 @@ client_init(Window win, struct screen_ctx *sc, int mapped) xu_ewmh_net_client_list(sc); client_wm_protocols(cc); + xu_ewmh_restore_net_wm_state(cc); if (mapped) group_autogroup(cc); @@ -301,6 +302,7 @@ client_maximize(struct client_ctx *cc) resize: client_resize(cc, 0); + xu_ewmh_set_net_wm_state(cc); } void @@ -341,6 +343,7 @@ client_vmaximize(struct client_ctx *cc) resize: client_resize(cc, 0); + xu_ewmh_set_net_wm_state(cc); } void @@ -381,6 +384,7 @@ client_hmaximize(struct client_ctx *cc) resize: client_resize(cc, 0); + xu_ewmh_set_net_wm_state(cc); } void @@ -389,6 +393,7 @@ client_resize(struct client_ctx *cc, int reset) if (reset) { cc->flags &= ~CLIENT_MAXIMIZED; cc->bwidth = Conf.bwidth; + xu_ewmh_set_net_wm_state(cc); } client_draw_border(cc); diff --git a/xutil.c b/xutil.c index d5055f2..95bb0d4 100644 --- a/xutil.c +++ b/xutil.c @@ -257,6 +257,9 @@ struct atom_ctx ewmh[EWMH_NITEMS] = { {"_NET_WM_NAME", None}, {"_NET_WM_DESKTOP", None}, {"_NET_CLOSE_WINDOW", None}, + {"_NET_WM_STATE", None}, + {"_NET_WM_STATE_MAXIMIZED_VERT",None}, + {"_NET_WM_STATE_MAXIMIZED_HORZ",None}, }; void @@ -420,6 +423,64 @@ xu_ewmh_net_wm_desktop(struct client_ctx *cc) XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&no, 1); } +Atom * +xu_ewmh_get_net_wm_state(struct client_ctx *cc, int *n) +{ + Atom *state, *p = NULL; + + if ((*n = xu_getprop(cc->win, ewmh[_NET_WM_STATE].atom, XA_ATOM, 64L, + (u_char **)&p)) <= 0) + return (NULL); + + state = xmalloc(*n * sizeof(Atom)); + memcpy(state, p, *n * sizeof(Atom)); + XFree((char *)p); + + return (state); +} + +void +xu_ewmh_restore_net_wm_state(struct client_ctx *cc) +{ + Atom *atoms; + int i, n; + + atoms = xu_ewmh_get_net_wm_state(cc, &n); + for (i = 0; i < n; i++) { + if (atoms[i] == ewmh[_NET_WM_STATE_MAXIMIZED_HORZ].atom) + client_hmaximize(cc); + if (atoms[i] == ewmh[_NET_WM_STATE_MAXIMIZED_VERT].atom) + client_vmaximize(cc); + } + free(atoms); +} + +void +xu_ewmh_set_net_wm_state(struct client_ctx *cc) +{ + Atom *atoms, *oatoms; + int n, i, j; + + oatoms = xu_ewmh_get_net_wm_state(cc, &n); + atoms = xmalloc((n + _NET_WM_STATES_NITEMS) * sizeof(Atom)); + for (i = j = 0; i < n; i++) { + if (oatoms[i] != ewmh[_NET_WM_STATE_MAXIMIZED_HORZ].atom && + oatoms[i] != ewmh[_NET_WM_STATE_MAXIMIZED_VERT].atom) + atoms[j++] = oatoms[i]; + } + free(oatoms); + if (cc->flags & CLIENT_HMAXIMIZED) + atoms[j++] = ewmh[_NET_WM_STATE_MAXIMIZED_HORZ].atom; + if (cc->flags & CLIENT_VMAXIMIZED) + atoms[j++] = ewmh[_NET_WM_STATE_MAXIMIZED_VERT].atom; + if (j > 0) + XChangeProperty(X_Dpy, cc->win, ewmh[_NET_WM_STATE].atom, + XA_ATOM, 32, PropModeReplace, (unsigned char *)atoms, j); + else + XDeleteProperty(X_Dpy, cc->win, ewmh[_NET_WM_STATE].atom); + free(atoms); +} + void xu_xorcolor(XftColor a, XftColor b, XftColor *r) { -- cgit 1.4.1 From 421bf22ac7a165f0f4d5608ffa22c887ff857d53 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 21 May 2013 00:29:20 +0000 Subject: handle _NET_WM_STATE ClientMessage; from Alexander Polakov. --- calmwm.h | 7 +++++++ xevents.c | 4 ++++ xutil.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) (limited to 'xutil.c') diff --git a/calmwm.h b/calmwm.h index e525cbf..b925c2c 100644 --- a/calmwm.h +++ b/calmwm.h @@ -482,6 +482,8 @@ void xu_ewmh_net_desktop_names(struct screen_ctx *, char *, void xu_ewmh_net_wm_desktop(struct client_ctx *); Atom *xu_ewmh_get_net_wm_state(struct client_ctx *, int *); +void xu_ewmh_handle_net_wm_state_msg(struct client_ctx *, + int, Atom , Atom); void xu_ewmh_set_net_wm_state(struct client_ctx *); void xu_ewmh_restore_net_wm_state(struct client_ctx *); @@ -543,6 +545,11 @@ enum { _NET_WM_STATE_MAXIMIZED_HORZ, EWMH_NITEMS }; +enum { + _NET_WM_STATE_REMOVE, + _NET_WM_STATE_ADD, + _NET_WM_STATE_TOGGLE +}; struct atom_ctx { char *name; Atom atom; diff --git a/xevents.c b/xevents.c index b13548b..1c6ffaf 100644 --- a/xevents.c +++ b/xevents.c @@ -359,6 +359,10 @@ xev_handle_clientmessage(XEvent *ee) client_ptrsave(old_cc); client_ptrwarp(cc); } + if (e->message_type == ewmh[_NET_WM_STATE].atom && + e->format == 32) + xu_ewmh_handle_net_wm_state_msg(cc, + e->data.l[0], e->data.l[1], e->data.l[2]); } static void diff --git a/xutil.c b/xutil.c index 95bb0d4..2c678dd 100644 --- a/xutil.c +++ b/xutil.c @@ -439,6 +439,43 @@ xu_ewmh_get_net_wm_state(struct client_ctx *cc, int *n) return (state); } +void +xu_ewmh_handle_net_wm_state_msg(struct client_ctx *cc, int action, + Atom first, Atom second) +{ + int i; + static struct handlers { + int atom; + int property; + void (*toggle)(struct client_ctx *); + } handlers[] = { + { _NET_WM_STATE_MAXIMIZED_VERT, + CLIENT_VMAXIMIZED, + client_vmaximize }, + { _NET_WM_STATE_MAXIMIZED_HORZ, + CLIENT_HMAXIMIZED, + client_hmaximize }, + }; + + for (i = 0; i < nitems(handlers); i++) { + if (first != ewmh[handlers[i].atom].atom && + second != ewmh[handlers[i].atom].atom) + continue; + switch (action) { + case _NET_WM_STATE_ADD: + if ((cc->flags & handlers[i].property) == 0) + handlers[i].toggle(cc); + break; + case _NET_WM_STATE_REMOVE: + if (cc->flags & handlers[i].property) + handlers[i].toggle(cc); + break; + case _NET_WM_STATE_TOGGLE: + handlers[i].toggle(cc); + } + } +} + void xu_ewmh_restore_net_wm_state(struct client_ctx *cc) { -- cgit 1.4.1 From be1a7a3f5c7c0777ba86d40c49425e97fbae62a1 Mon Sep 17 00:00:00 2001 From: okan Date: Thu, 23 May 2013 16:52:39 +0000 Subject: alter conf_grab(_kbd) to first ungrab AnyKey/AnyModifier, then proceed to grab keys in keybindingq. we don't need to ungrab/grab on every addition to the queue, just once with a complete keybindingq; simplify grabbing keys per screen (during init) and during a MappingNotify. while here, change conf_grab_{kbd,mouse} to require only a Window. --- calmwm.h | 6 ++---- client.c | 2 +- conf.c | 54 +++++++++++++++--------------------------------------- xevents.c | 12 +++++------- xutil.c | 15 --------------- 5 files changed, 23 insertions(+), 66 deletions(-) (limited to 'xutil.c') diff --git a/calmwm.h b/calmwm.h index 16901b3..25eae87 100644 --- a/calmwm.h +++ b/calmwm.h @@ -435,13 +435,12 @@ void conf_bindname(struct conf *, char *, char *); void conf_clear(struct conf *); void conf_client(struct client_ctx *); void conf_cmd_add(struct conf *, char *, char *); -void conf_grab(struct conf *, struct keybinding *); -void conf_grab_mouse(struct client_ctx *); +void conf_grab_kbd(Window); +void conf_grab_mouse(Window); void conf_init(struct conf *); void conf_ignore(struct conf *, char *); int conf_mousebind(struct conf *, char *, char *); void conf_screen(struct screen_ctx *); -void conf_ungrab(struct conf *, struct keybinding *); void xev_loop(void); @@ -453,7 +452,6 @@ int xu_getprop(Window, Atom, Atom, long, u_char **); int xu_get_wm_state(Window, int *); int xu_getstrprop(Window, Atom, char **); void xu_key_grab(Window, u_int, KeySym); -void xu_key_ungrab(Window, u_int, KeySym); void xu_ptr_getpos(Window, int *, int *); int xu_ptr_grab(Window, u_int, Cursor); int xu_ptr_regrab(u_int, Cursor); diff --git a/client.c b/client.c index 605c2a4..650dbaa 100644 --- a/client.c +++ b/client.c @@ -213,7 +213,7 @@ client_setactive(struct client_ctx *cc, int fg) XInstallColormap(X_Dpy, cc->colormap); XSetInputFocus(X_Dpy, cc->win, RevertToPointerRoot, CurrentTime); - conf_grab_mouse(cc); + conf_grab_mouse(cc->win); /* * If we're in the middle of alt-tabbing, don't change * the order please. diff --git a/conf.c b/conf.c index 5d005c1..763e364 100644 --- a/conf.c +++ b/conf.c @@ -98,7 +98,6 @@ static char *color_binds[CWM_COLOR_MAX] = { void conf_screen(struct screen_ctx *sc) { - struct keybinding *kb; int i; XftColor xc; @@ -141,8 +140,7 @@ conf_screen(struct screen_ctx *sc) if (sc->xftdraw == NULL) errx(1, "XftDrawCreate"); - TAILQ_FOREACH(kb, &Conf.keybindingq, entry) - xu_key_grab(sc->rootwin, kb->modmask, kb->keysym); + conf_grab_kbd(sc->rootwin); } static struct { @@ -436,37 +434,6 @@ static struct { {.i = CWM_TILE_VERT } }, }; -/* - * The following two functions are used when grabbing and ungrabbing keys for - * bindings - */ - -/* - * Grab key combination on all screens and add to the global queue - */ -void -conf_grab(struct conf *c, struct keybinding *kb) -{ - extern struct screen_ctx_q Screenq; - struct screen_ctx *sc; - - TAILQ_FOREACH(sc, &Screenq, entry) - xu_key_grab(sc->rootwin, kb->modmask, kb->keysym); -} - -/* - * Ungrab key combination from all screens and remove from global queue - */ -void -conf_ungrab(struct conf *c, struct keybinding *kb) -{ - extern struct screen_ctx_q Screenq; - struct screen_ctx *sc; - - TAILQ_FOREACH(sc, &Screenq, entry) - xu_key_ungrab(sc->rootwin, kb->modmask, kb->keysym); -} - static struct { char chr; int mask; @@ -656,17 +623,26 @@ conf_mouseunbind(struct conf *c, struct mousebinding *unbind) } } -/* - * Grab the mouse buttons that we need for bindings for this client - */ void -conf_grab_mouse(struct client_ctx *cc) +conf_grab_mouse(Window win) { struct mousebinding *mb; TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) { if (mb->context != MOUSEBIND_CTX_WIN) continue; - xu_btn_grab(cc->win, mb->modmask, mb->button); + xu_btn_grab(win, mb->modmask, mb->button); } } + +void +conf_grab_kbd(Window win) +{ + struct keybinding *kb; + + XUngrabKey(X_Dpy, AnyKey, AnyModifier, win); + + TAILQ_FOREACH(kb, &Conf.keybindingq, entry) + xu_key_grab(win, kb->modmask, kb->keysym); +} + diff --git a/xevents.c b/xevents.c index 1c6ffaf..0a8dc9a 100644 --- a/xevents.c +++ b/xevents.c @@ -389,15 +389,13 @@ static void xev_handle_mappingnotify(XEvent *ee) { XMappingEvent *e = &ee->xmapping; - struct keybinding *kb; - - TAILQ_FOREACH(kb, &Conf.keybindingq, entry) - conf_ungrab(&Conf, kb); + struct screen_ctx *sc; XRefreshKeyboardMapping(e); - - TAILQ_FOREACH(kb, &Conf.keybindingq, entry) - conf_grab(&Conf, kb); + if (e->request == MappingKeyboard) { + TAILQ_FOREACH(sc, &Screenq, entry) + conf_grab_kbd(sc->rootwin); + } } static void diff --git a/xutil.c b/xutil.c index 2c678dd..37d7e24 100644 --- a/xutil.c +++ b/xutil.c @@ -105,21 +105,6 @@ xu_key_grab(Window win, u_int mask, KeySym keysym) True, GrabModeAsync, GrabModeAsync); } -void -xu_key_ungrab(Window win, u_int mask, KeySym keysym) -{ - KeyCode code; - u_int i; - - code = XKeysymToKeycode(X_Dpy, keysym); - if ((XkbKeycodeToKeysym(X_Dpy, code, 0, 0) != keysym) && - (XkbKeycodeToKeysym(X_Dpy, code, 0, 1) == keysym)) - mask |= ShiftMask; - - for (i = 0; i < nitems(ign_mods); i++) - XUngrabKey(X_Dpy, code, (mask | ign_mods[i]), win); -} - void xu_configure(struct client_ctx *cc) { -- cgit 1.4.1 From 692d341dfc6b059db570356e9dfadba92dc93f19 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 27 May 2013 23:20:45 +0000 Subject: fix type in a ClientMessage (xu_sendmsg). --- calmwm.h | 2 +- xutil.c | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'xutil.c') diff --git a/calmwm.h b/calmwm.h index 25eae87..62f574a 100644 --- a/calmwm.h +++ b/calmwm.h @@ -457,7 +457,7 @@ int xu_ptr_grab(Window, u_int, Cursor); int xu_ptr_regrab(u_int, Cursor); void xu_ptr_setpos(Window, int, int); void xu_ptr_ungrab(void); -void xu_sendmsg(Window, Atom, long); +void xu_sendmsg(Window, Atom, Atom); void xu_set_wm_state(Window win, int); void xu_xft_draw(struct screen_ctx *, const char *, int, int, int); diff --git a/xutil.c b/xutil.c index 37d7e24..56325b6 100644 --- a/xutil.c +++ b/xutil.c @@ -125,19 +125,19 @@ xu_configure(struct client_ctx *cc) } void -xu_sendmsg(Window win, Atom atm, long val) +xu_sendmsg(Window win, Atom type, Atom atm) { - XEvent e; + XClientMessageEvent e; - (void)memset(&e, 0, sizeof(e)); - e.xclient.type = ClientMessage; - e.xclient.window = win; - e.xclient.message_type = atm; - e.xclient.format = 32; - e.xclient.data.l[0] = val; - e.xclient.data.l[1] = CurrentTime; + bzero(&e, sizeof(e)); + e.type = ClientMessage; + e.window = win; + e.message_type = type; + e.format = 32; + e.data.l[0] = atm; + e.data.l[1] = CurrentTime; - XSendEvent(X_Dpy, win, False, 0, &e); + XSendEvent(X_Dpy, win, False, 0L, (XEvent *)&e); } int -- cgit 1.4.1