Merge branch 'linux' of git://github.com/chneukirchen/cwm into linux

This commit is contained in:
Michael Weber 2013-12-09 11:10:31 +01:00
commit 8ae4b75da9
9 changed files with 94 additions and 154 deletions

View File

@ -239,6 +239,7 @@ struct screen_ctx {
Window rootwin; Window rootwin;
Window menuwin; Window menuwin;
int cycling; int cycling;
int snapdist;
struct geom view; /* viewable area */ struct geom view; /* viewable area */
struct geom work; /* workable area, gap-applied */ struct geom work; /* workable area, gap-applied */
struct gap gap; struct gap gap;
@ -392,8 +393,7 @@ void client_applysizehints(struct client_ctx *);
void client_config(struct client_ctx *); void client_config(struct client_ctx *);
struct client_ctx *client_current(void); struct client_ctx *client_current(void);
void client_cycle(struct screen_ctx *, int); void client_cycle(struct screen_ctx *, int);
void client_cycle_leave(struct screen_ctx *, void client_cycle_leave(struct screen_ctx *);
struct client_ctx *);
void client_delete(struct client_ctx *); void client_delete(struct client_ctx *);
void client_draw_border(struct client_ctx *); void client_draw_border(struct client_ctx *);
struct client_ctx *client_find(Window); struct client_ctx *client_find(Window);
@ -402,7 +402,6 @@ void client_getsizehints(struct client_ctx *);
void client_hide(struct client_ctx *); void client_hide(struct client_ctx *);
void client_hmaximize(struct client_ctx *); void client_hmaximize(struct client_ctx *);
void client_htile(struct client_ctx *); void client_htile(struct client_ctx *);
void client_leave(struct client_ctx *);
void client_lower(struct client_ctx *); void client_lower(struct client_ctx *);
void client_map(struct client_ctx *); void client_map(struct client_ctx *);
void client_maximize(struct client_ctx *); void client_maximize(struct client_ctx *);
@ -414,7 +413,7 @@ void client_ptrwarp(struct client_ctx *);
void client_raise(struct client_ctx *); void client_raise(struct client_ctx *);
void client_resize(struct client_ctx *, int); void client_resize(struct client_ctx *, int);
void client_send_delete(struct client_ctx *); void client_send_delete(struct client_ctx *);
void client_setactive(struct client_ctx *, int); void client_setactive(struct client_ctx *);
void client_setname(struct client_ctx *); void client_setname(struct client_ctx *);
int client_snapcalc(int, int, int, int, int); int client_snapcalc(int, int, int, int, int);
void client_transient(struct client_ctx *); void client_transient(struct client_ctx *);

150
client.c
View File

@ -180,53 +180,35 @@ client_delete(struct client_ctx *cc)
} }
void void
client_leave(struct client_ctx *cc) client_setactive(struct client_ctx *cc)
{ {
if (cc == NULL) struct screen_ctx *sc = cc->sc;
cc = client_current(); struct client_ctx *oldcc;
if (cc == NULL)
return;
}
void XInstallColormap(X_Dpy, cc->colormap);
client_setactive(struct client_ctx *cc, int fg)
{
struct screen_ctx *sc;
if (cc == NULL) if ((cc->flags & CLIENT_INPUT) ||
cc = client_current(); ((cc->flags & CLIENT_WM_TAKE_FOCUS) == 0)) {
if (cc == NULL) XSetInputFocus(X_Dpy, cc->win,
return; RevertToPointerRoot, CurrentTime);
}
if (cc->flags & CLIENT_WM_TAKE_FOCUS)
client_msg(cc, cwmh[WM_TAKE_FOCUS]);
sc = cc->sc; if ((oldcc = client_current())) {
oldcc->active = 0;
if (fg) { client_draw_border(oldcc);
XInstallColormap(X_Dpy, cc->colormap);
if ((cc->flags & CLIENT_INPUT) ||
((cc->flags & CLIENT_WM_TAKE_FOCUS) == 0)) {
XSetInputFocus(X_Dpy, cc->win,
RevertToPointerRoot, CurrentTime);
}
if (cc->flags & CLIENT_WM_TAKE_FOCUS)
client_msg(cc, cwmh[WM_TAKE_FOCUS]);
conf_grab_mouse(cc->win);
/*
* If we're in the middle of alt-tabbing, don't change
* the order please.
*/
if (!sc->cycling)
client_mtf(cc);
} else
client_leave(cc);
if (fg && cc != client_current()) {
client_setactive(NULL, 0);
_curcc = cc;
xu_ewmh_net_active_window(sc, cc->win);
} }
cc->active = fg; /* If we're in the middle of cycing, don't change the order. */
if (!sc->cycling)
client_mtf(cc);
_curcc = cc;
cc->active = 1;
client_draw_border(cc); client_draw_border(cc);
conf_grab_mouse(cc->win);
xu_ewmh_net_active_window(sc, cc->win);
} }
/* /*
@ -640,12 +622,14 @@ client_cycle(struct screen_ctx *sc, int flags)
} }
void void
client_cycle_leave(struct screen_ctx *sc, struct client_ctx *cc) client_cycle_leave(struct screen_ctx *sc)
{ {
struct client_ctx *cc;
sc->cycling = 0; sc->cycling = 0;
client_mtf(NULL); if ((cc = client_current())) {
if (cc) { client_mtf(cc);
group_sticky_toggle_exit(cc); group_sticky_toggle_exit(cc);
XUngrabKeyboard(X_Dpy, CurrentTime); XUngrabKeyboard(X_Dpy, CurrentTime);
} }
@ -724,14 +708,8 @@ client_placecalc(struct client_ctx *cc)
static void static void
client_mtf(struct client_ctx *cc) client_mtf(struct client_ctx *cc)
{ {
struct screen_ctx *sc; struct screen_ctx *sc = cc->sc;
if (cc == NULL)
cc = client_current();
if (cc == NULL)
return;
sc = cc->sc;
TAILQ_REMOVE(&sc->mruq, cc, mru_entry); TAILQ_REMOVE(&sc->mruq, cc, mru_entry);
TAILQ_INSERT_HEAD(&sc->mruq, cc, mru_entry); TAILQ_INSERT_HEAD(&sc->mruq, cc, mru_entry);
} }
@ -740,52 +718,46 @@ void
client_getsizehints(struct client_ctx *cc) client_getsizehints(struct client_ctx *cc)
{ {
long tmp; long tmp;
XSizeHints *size; XSizeHints size;
if ((size = XAllocSizeHints()) == NULL) if (!XGetWMNormalHints(X_Dpy, cc->win, &size, &tmp))
warnx("XAllocSizeHints failure"); size.flags = 0;
if (!XGetWMNormalHints(X_Dpy, cc->win, size, &tmp)) cc->hint.flags = size.flags;
size->flags = 0;
cc->hint.flags = size->flags; if (size.flags & PBaseSize) {
cc->hint.basew = size.base_width;
if (size->flags & PBaseSize) { cc->hint.baseh = size.base_height;
cc->hint.basew = size->base_width; } else if (size.flags & PMinSize) {
cc->hint.baseh = size->base_height; cc->hint.basew = size.min_width;
} else if (size->flags & PMinSize) { cc->hint.baseh = size.min_height;
cc->hint.basew = size->min_width;
cc->hint.baseh = size->min_height;
} }
if (size->flags & PMinSize) { if (size.flags & PMinSize) {
cc->hint.minw = size->min_width; cc->hint.minw = size.min_width;
cc->hint.minh = size->min_height; cc->hint.minh = size.min_height;
} else if (size->flags & PBaseSize) { } else if (size.flags & PBaseSize) {
cc->hint.minw = size->base_width; cc->hint.minw = size.base_width;
cc->hint.minh = size->base_height; cc->hint.minh = size.base_height;
} }
if (size->flags & PMaxSize) { if (size.flags & PMaxSize) {
cc->hint.maxw = size->max_width; cc->hint.maxw = size.max_width;
cc->hint.maxh = size->max_height; cc->hint.maxh = size.max_height;
} }
if (size->flags & PResizeInc) { if (size.flags & PResizeInc) {
cc->hint.incw = size->width_inc; cc->hint.incw = size.width_inc;
cc->hint.inch = size->height_inc; cc->hint.inch = size.height_inc;
} }
cc->hint.incw = MAX(1, cc->hint.incw); cc->hint.incw = MAX(1, cc->hint.incw);
cc->hint.inch = MAX(1, cc->hint.inch); cc->hint.inch = MAX(1, cc->hint.inch);
if (size->flags & PAspect) { if (size.flags & PAspect) {
if (size->min_aspect.x > 0) if (size.min_aspect.x > 0)
cc->hint.mina = (float)size->min_aspect.y / cc->hint.mina = (float)size.min_aspect.y /
size->min_aspect.x; size.min_aspect.x;
if (size->max_aspect.y > 0) if (size.max_aspect.y > 0)
cc->hint.maxa = (float)size->max_aspect.x / cc->hint.maxa = (float)size.max_aspect.x /
size->max_aspect.y; size.max_aspect.y;
} }
if (size)
XFree(size);
} }
void void
@ -803,12 +775,10 @@ client_applysizehints(struct client_ctx *cc)
} }
/* adjust for aspect limits */ /* adjust for aspect limits */
if (cc->hint.mina > 0 && cc->hint.maxa > 0) { if (cc->hint.mina && cc->hint.maxa) {
if (cc->hint.maxa < if (cc->hint.maxa < (float)cc->geom.w / cc->geom.h)
(float)cc->geom.w / cc->geom.h)
cc->geom.w = cc->geom.h * cc->hint.maxa; cc->geom.w = cc->geom.h * cc->hint.maxa;
else if (cc->hint.mina < else if (cc->hint.mina < (float)cc->geom.h / cc->geom.w)
(float)cc->geom.h / cc->geom.w)
cc->geom.h = cc->geom.w * cc->hint.mina; cc->geom.h = cc->geom.w * cc->hint.mina;
} }

18
conf.c
View File

@ -103,6 +103,7 @@ conf_screen(struct screen_ctx *sc)
XftColor xc; XftColor xc;
sc->gap = Conf.gap; sc->gap = Conf.gap;
sc->snapdist = Conf.snapdist;
sc->xftfont = XftFontOpenXlfd(X_Dpy, sc->which, Conf.font); sc->xftfont = XftFontOpenXlfd(X_Dpy, sc->which, Conf.font);
if (sc->xftfont == NULL) { if (sc->xftfont == NULL) {
@ -505,17 +506,8 @@ conf_bind_kbd(struct conf *c, char *name, char *binding)
substring = conf_bind_getmask(name, &mask); substring = conf_bind_getmask(name, &mask);
current_binding->modmask |= mask; current_binding->modmask |= mask;
if (substring[0] == '[' && current_binding->keysym = XStringToKeysym(substring);
substring[strlen(substring)-1] == ']') { if (current_binding->keysym == NoSymbol) {
sscanf(substring, "[%d]", &current_binding->keycode);
current_binding->keysym = NoSymbol;
} else {
current_binding->keycode = 0;
current_binding->keysym = XStringToKeysym(substring);
}
if (current_binding->keysym == NoSymbol &&
current_binding->keycode == 0) {
free(current_binding); free(current_binding);
return; return;
} }
@ -556,9 +548,7 @@ conf_unbind_kbd(struct conf *c, struct keybinding *unbind)
if (key->modmask != unbind->modmask) if (key->modmask != unbind->modmask)
continue; continue;
if ((key->keycode != 0 && key->keysym == NoSymbol && if (key->keysym == unbind->keysym) {
key->keycode == unbind->keycode) ||
key->keysym == unbind->keysym) {
TAILQ_REMOVE(&c->keybindingq, key, entry); TAILQ_REMOVE(&c->keybindingq, key, entry);
if (key->argtype & ARG_CHAR) if (key->argtype & ARG_CHAR)
free(key->argument.c); free(key->argument.c);

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: June 17 2013 $ .Dd $Mdocdate: July 8 2013 $
.Dt CWMRC 5 .Dt CWMRC 5
.Os .Os
.Sh NAME .Sh NAME
@ -84,10 +84,8 @@ The Mod4 key (normally the windows key).
.Pp .Pp
The The
.Sq - .Sq -
should be followed by either a keysym name, taken from should be followed by a keysym name, taken from
.Pa /usr/X11R6/include/X11/keysymdef.h , .Pa /usr/X11R6/include/X11/keysymdef.h .
or a numerical keycode value enclosed in
.Dq [] .
The The
.Ar command .Ar command
may either be one from the may either be one from the

View File

@ -102,10 +102,10 @@ kbfunc_client_moveresize(struct client_ctx *cc, union arg *arg)
cc->geom.x += client_snapcalc(cc->geom.x, cc->geom.x += client_snapcalc(cc->geom.x,
cc->geom.x + cc->geom.w + (cc->bwidth * 2), cc->geom.x + cc->geom.w + (cc->bwidth * 2),
sc->work.x, sc->work.w, Conf.snapdist); sc->work.x, sc->work.w, sc->snapdist);
cc->geom.y += client_snapcalc(cc->geom.y, cc->geom.y += client_snapcalc(cc->geom.y,
cc->geom.y + cc->geom.h + (cc->bwidth * 2), cc->geom.y + cc->geom.h + (cc->bwidth * 2),
sc->work.y, sc->work.h, Conf.snapdist); sc->work.y, sc->work.h, sc->snapdist);
client_move(cc); client_move(cc);
xu_ptr_getpos(cc->win, &x, &y); xu_ptr_getpos(cc->win, &x, &y);

9
menu.c
View File

@ -427,10 +427,8 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq)
xu_xft_draw(sc, text, CWM_COLOR_MENU_FONT, 0, y); xu_xft_draw(sc, text, CWM_COLOR_MENU_FONT, 0, y);
n++; n++;
} }
if (mc->hasprompt && n > 1 && (mc->searchstr[0] != '\0')) { if (mc->hasprompt && n > 1)
mc->entry = 1; menu_draw_entry(mc, resultq, 1, 1);
menu_draw_entry(mc, resultq, mc->entry, 1);
}
} }
static void static void
@ -477,9 +475,6 @@ menu_handle_move(XEvent *e, struct menu_ctx *mc, struct menu_q *resultq)
menu_draw_entry(mc, resultq, mc->entry, 1); menu_draw_entry(mc, resultq, mc->entry, 1);
} else } else
(void)xu_ptr_regrab(MENUGRABMASK, Conf.cursor[CF_DEFAULT]); (void)xu_ptr_regrab(MENUGRABMASK, Conf.cursor[CF_DEFAULT]);
if (mc->hasprompt)
menu_draw_entry(mc, resultq, 1, 1);
} }
static struct menu * static struct menu *

View File

@ -50,21 +50,19 @@ static void
mousefunc_sweep_draw(struct client_ctx *cc) mousefunc_sweep_draw(struct client_ctx *cc)
{ {
struct screen_ctx *sc = cc->sc; struct screen_ctx *sc = cc->sc;
char asize[14]; /* fits " nnnn x nnnn \0" */ char s[14]; /* fits " nnnn x nnnn \0" */
(void)snprintf(asize, sizeof(asize), " %4d x %-4d ", (void)snprintf(s, sizeof(s), " %4d x %-4d ",
(cc->geom.w - cc->hint.basew) / cc->hint.incw, (cc->geom.w - cc->hint.basew) / cc->hint.incw,
(cc->geom.h - cc->hint.baseh) / cc->hint.inch); (cc->geom.h - cc->hint.baseh) / cc->hint.inch);
XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0); XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0);
XMoveResizeWindow(X_Dpy, sc->menuwin, 0, 0, XMoveResizeWindow(X_Dpy, sc->menuwin, 0, 0,
xu_xft_width(sc->xftfont, asize, strlen(asize)), xu_xft_width(sc->xftfont, s, strlen(s)), sc->xftfont->height);
sc->xftfont->height);
XMapWindow(X_Dpy, sc->menuwin); XMapWindow(X_Dpy, sc->menuwin);
XClearWindow(X_Dpy, sc->menuwin); XClearWindow(X_Dpy, sc->menuwin);
xu_xft_draw(sc, asize, CWM_COLOR_MENU_FONT, xu_xft_draw(sc, s, CWM_COLOR_MENU_FONT, 0, sc->xftfont->ascent + 1);
0, sc->xftfont->ascent + 1);
} }
void void
@ -149,10 +147,10 @@ mousefunc_client_move(struct client_ctx *cc, void *arg)
cc->geom.x += client_snapcalc(cc->geom.x, cc->geom.x += client_snapcalc(cc->geom.x,
cc->geom.x + cc->geom.w + (cc->bwidth * 2), cc->geom.x + cc->geom.w + (cc->bwidth * 2),
sc->work.x, sc->work.w, Conf.snapdist); sc->work.x, sc->work.w, sc->snapdist);
cc->geom.y += client_snapcalc(cc->geom.y, cc->geom.y += client_snapcalc(cc->geom.y,
cc->geom.y + cc->geom.h + (cc->bwidth * 2), cc->geom.y + cc->geom.h + (cc->bwidth * 2),
sc->work.y, sc->work.h, Conf.snapdist); sc->work.y, sc->work.h, sc->snapdist);
/* don't move more than 60 times / second */ /* don't move more than 60 times / second */
if ((ev.xmotion.time - ltime) > (1000 / 60)) { if ((ev.xmotion.time - ltime) > (1000 / 60)) {
@ -233,7 +231,8 @@ mousefunc_menu_unhide(struct client_ctx *cc, void *arg)
continue; continue;
mi = xcalloc(1, sizeof(*mi)); mi = xcalloc(1, sizeof(*mi));
(void)strlcpy(mi->text, wname, sizeof(mi->text)); (void)snprintf(mi->text, sizeof(mi->text), "(%d) %s",
cc->group ? cc->group->shortcut : 0, wname);
mi->ctx = cc; mi->ctx = cc;
TAILQ_INSERT_TAIL(&menuq, mi, entry); TAILQ_INSERT_TAIL(&menuq, mi, entry);
} }

View File

@ -142,8 +142,8 @@ search_print_client(struct menu *mi, int list)
if (list) if (list)
cc->matchname = cc->name; cc->matchname = cc->name;
(void)snprintf(mi->print, sizeof(mi->print), "%c%s", flag, (void)snprintf(mi->print, sizeof(mi->print), "(%d) %c%s",
cc->matchname); cc->group ? cc->group->shortcut : 0, flag, cc->matchname);
if (!list && cc->matchname != cc->name && if (!list && cc->matchname != cc->name &&
strlen(mi->print) < sizeof(mi->print) - 1) { strlen(mi->print) < sizeof(mi->print) - 1) {

View File

@ -43,7 +43,6 @@ static void xev_handle_destroynotify(XEvent *);
static void xev_handle_configurerequest(XEvent *); static void xev_handle_configurerequest(XEvent *);
static void xev_handle_propertynotify(XEvent *); static void xev_handle_propertynotify(XEvent *);
static void xev_handle_enternotify(XEvent *); static void xev_handle_enternotify(XEvent *);
static void xev_handle_leavenotify(XEvent *);
static void xev_handle_buttonpress(XEvent *); static void xev_handle_buttonpress(XEvent *);
static void xev_handle_buttonrelease(XEvent *); static void xev_handle_buttonrelease(XEvent *);
static void xev_handle_keypress(XEvent *); static void xev_handle_keypress(XEvent *);
@ -60,7 +59,6 @@ void (*xev_handlers[LASTEvent])(XEvent *) = {
[ConfigureRequest] = xev_handle_configurerequest, [ConfigureRequest] = xev_handle_configurerequest,
[PropertyNotify] = xev_handle_propertynotify, [PropertyNotify] = xev_handle_propertynotify,
[EnterNotify] = xev_handle_enternotify, [EnterNotify] = xev_handle_enternotify,
[LeaveNotify] = xev_handle_leavenotify,
[ButtonPress] = xev_handle_buttonpress, [ButtonPress] = xev_handle_buttonpress,
[ButtonRelease] = xev_handle_buttonrelease, [ButtonRelease] = xev_handle_buttonrelease,
[KeyPress] = xev_handle_keypress, [KeyPress] = xev_handle_keypress,
@ -81,7 +79,7 @@ xev_handle_maprequest(XEvent *ee)
struct client_ctx *cc = NULL, *old_cc; struct client_ctx *cc = NULL, *old_cc;
XWindowAttributes xattr; XWindowAttributes xattr;
if ((old_cc = client_current()) != NULL) if ((old_cc = client_current()))
client_ptrsave(old_cc); client_ptrsave(old_cc);
if ((cc = client_find(e->window)) == NULL) { if ((cc = client_find(e->window)) == NULL) {
@ -103,8 +101,10 @@ xev_handle_unmapnotify(XEvent *ee)
if (e->send_event) { if (e->send_event) {
cc->state = WithdrawnState; cc->state = WithdrawnState;
xu_set_wm_state(cc->win, cc->state); xu_set_wm_state(cc->win, cc->state);
} else } else {
client_hide(cc); if (!(cc->flags & CLIENT_HIDDEN))
client_delete(cc);
}
} }
} }
@ -211,13 +211,7 @@ xev_handle_enternotify(XEvent *ee)
struct client_ctx *cc; struct client_ctx *cc;
if ((cc = client_find(e->window)) != NULL) if ((cc = client_find(e->window)) != NULL)
client_setactive(cc, 1); client_setactive(cc);
}
static void
xev_handle_leavenotify(XEvent *ee)
{
client_leave(NULL);
} }
/* We can split this into two event handlers. */ /* We can split this into two event handlers. */
@ -256,7 +250,7 @@ xev_handle_buttonrelease(XEvent *ee)
{ {
struct client_ctx *cc; struct client_ctx *cc;
if ((cc = client_current()) != NULL) if ((cc = client_current()))
group_sticky_toggle_exit(cc); group_sticky_toggle_exit(cc);
} }
@ -283,9 +277,7 @@ xev_handle_keypress(XEvent *ee)
if ((kb->modmask | modshift) != e->state) if ((kb->modmask | modshift) != e->state)
continue; continue;
if ((kb->keycode != 0 && kb->keysym == NoSymbol && if (kb->keysym == (modshift == 0 ? keysym : skeysym))
kb->keycode == e->keycode) || kb->keysym ==
(modshift == 0 ? keysym : skeysym))
break; break;
} }
@ -311,17 +303,15 @@ xev_handle_keyrelease(XEvent *ee)
{ {
XKeyEvent *e = &ee->xkey; XKeyEvent *e = &ee->xkey;
struct screen_ctx *sc; struct screen_ctx *sc;
struct client_ctx *cc;
KeySym keysym; KeySym keysym;
u_int i; u_int i;
sc = screen_fromroot(e->root); sc = screen_fromroot(e->root);
cc = client_current();
keysym = XkbKeycodeToKeysym(X_Dpy, e->keycode, 0, 0); keysym = XkbKeycodeToKeysym(X_Dpy, e->keycode, 0, 0);
for (i = 0; i < nitems(modkeys); i++) { for (i = 0; i < nitems(modkeys); i++) {
if (keysym == modkeys[i]) { if (keysym == modkeys[i]) {
client_cycle_leave(sc, cc); client_cycle_leave(sc);
break; break;
} }
} }
@ -344,8 +334,7 @@ xev_handle_clientmessage(XEvent *ee)
client_send_delete(cc); client_send_delete(cc);
if (e->message_type == ewmh[_NET_ACTIVE_WINDOW] && e->format == 32) { if (e->message_type == ewmh[_NET_ACTIVE_WINDOW] && e->format == 32) {
old_cc = client_current(); if ((old_cc = client_current()))
if (old_cc)
client_ptrsave(old_cc); client_ptrsave(old_cc);
client_ptrwarp(cc); client_ptrwarp(cc);
} }