2007-04-27 21:58:48 +04:00
|
|
|
/*
|
|
|
|
* calmwm - the calm window manager
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Andy Adamson <dros@monkey.org>
|
|
|
|
* Copyright (c) 2004,2005 Marius Aamodt Eriksen <marius@monkey.org>
|
2008-01-11 19:06:44 +03:00
|
|
|
*
|
|
|
|
* 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.
|
2007-04-27 21:58:48 +04:00
|
|
|
*
|
2011-05-11 17:53:51 +04:00
|
|
|
* $OpenBSD$
|
2007-04-27 21:58:48 +04:00
|
|
|
*/
|
|
|
|
|
2009-12-15 07:10:42 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
|
2009-12-15 06:34:34 +03:00
|
|
|
#include <assert.h>
|
2009-12-15 07:10:42 +03:00
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
2012-11-09 07:52:02 +04:00
|
|
|
#include <stdio.h>
|
2009-12-15 07:10:42 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2009-12-15 06:34:34 +03:00
|
|
|
|
2007-04-27 21:58:48 +04:00
|
|
|
#include "calmwm.h"
|
|
|
|
|
2009-05-18 04:23:35 +04:00
|
|
|
static void group_add(struct group_ctx *, struct client_ctx *);
|
|
|
|
static void group_remove(struct client_ctx *);
|
2009-12-10 20:16:51 +03:00
|
|
|
static void group_hide(struct screen_ctx *, struct group_ctx *);
|
|
|
|
static void group_show(struct screen_ctx *, struct group_ctx *);
|
2009-05-18 04:23:35 +04:00
|
|
|
static void group_fix_hidden_state(struct group_ctx *);
|
2009-12-11 20:55:42 +03:00
|
|
|
static void group_setactive(struct screen_ctx *, long);
|
2009-12-11 20:51:42 +03:00
|
|
|
static void group_set_names(struct screen_ctx *);
|
2009-01-15 03:32:35 +03:00
|
|
|
|
2009-01-12 00:46:48 +03:00
|
|
|
const char *shortcut_to_name[] = {
|
2009-01-15 03:32:35 +03:00
|
|
|
"nogroup", "one", "two", "three", "four", "five", "six",
|
|
|
|
"seven", "eight", "nine"
|
2009-01-12 00:46:48 +03:00
|
|
|
};
|
|
|
|
|
2007-04-27 21:58:48 +04:00
|
|
|
static void
|
2009-05-18 04:23:35 +04:00
|
|
|
group_add(struct group_ctx *gc, struct client_ctx *cc)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
|
|
|
if (cc == NULL || gc == NULL)
|
2009-05-18 04:23:35 +04:00
|
|
|
errx(1, "group_add: a ctx is NULL");
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (cc->group == gc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (cc->group != NULL)
|
|
|
|
TAILQ_REMOVE(&cc->group->clients, cc, group_entry);
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&gc->clients, cc, group_entry);
|
|
|
|
cc->group = gc;
|
2012-07-03 17:49:03 +04:00
|
|
|
|
|
|
|
xu_ewmh_net_wm_desktop(cc);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-18 04:23:35 +04:00
|
|
|
group_remove(struct client_ctx *cc)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
|
|
|
if (cc == NULL || cc->group == NULL)
|
2009-05-18 04:23:35 +04:00
|
|
|
errx(1, "group_remove: a ctx is NULL");
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
TAILQ_REMOVE(&cc->group->clients, cc, group_entry);
|
|
|
|
cc->group = NULL;
|
2012-07-03 17:49:03 +04:00
|
|
|
|
|
|
|
xu_ewmh_net_wm_desktop(cc);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-12-10 20:16:51 +03:00
|
|
|
group_hide(struct screen_ctx *sc, struct group_ctx *gc)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct client_ctx *cc;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2009-12-10 20:16:51 +03:00
|
|
|
screen_updatestackingorder(sc);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
gc->nhidden = 0;
|
|
|
|
gc->highstack = 0;
|
|
|
|
TAILQ_FOREACH(cc, &gc->clients, group_entry) {
|
|
|
|
client_hide(cc);
|
|
|
|
gc->nhidden++;
|
|
|
|
if (cc->stackingorder > gc->highstack)
|
|
|
|
gc->highstack = cc->stackingorder;
|
|
|
|
}
|
|
|
|
gc->hidden = 1; /* XXX: equivalent to gc->nhidden > 0 */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-12-10 20:16:51 +03:00
|
|
|
group_show(struct screen_ctx *sc, struct group_ctx *gc)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct client_ctx *cc;
|
|
|
|
Window *winlist;
|
|
|
|
u_int i;
|
|
|
|
int lastempty = -1;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2011-02-13 20:25:20 +03:00
|
|
|
gc->highstack = 0;
|
|
|
|
TAILQ_FOREACH(cc, &gc->clients, group_entry) {
|
|
|
|
if (cc->stackingorder > gc->highstack)
|
|
|
|
gc->highstack = cc->stackingorder;
|
|
|
|
}
|
2008-04-16 17:38:09 +04:00
|
|
|
winlist = (Window *) xcalloc(sizeof(*winlist), (gc->highstack + 1));
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Invert the stacking order as XRestackWindows() expects them
|
|
|
|
* top-to-bottom.
|
|
|
|
*/
|
|
|
|
TAILQ_FOREACH(cc, &gc->clients, group_entry) {
|
2009-01-16 18:24:14 +03:00
|
|
|
winlist[gc->highstack - cc->stackingorder] = cc->win;
|
2007-04-27 21:58:48 +04:00
|
|
|
client_unhide(cc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Un-sparseify */
|
|
|
|
for (i = 0; i <= gc->highstack; i++) {
|
|
|
|
if (!winlist[i] && lastempty == -1)
|
|
|
|
lastempty = i;
|
|
|
|
else if (winlist[i] && lastempty != -1) {
|
|
|
|
winlist[lastempty] = winlist[i];
|
|
|
|
if (++lastempty == i)
|
|
|
|
lastempty = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-28 22:34:27 +04:00
|
|
|
XRestackWindows(X_Dpy, winlist, gc->nhidden);
|
2012-11-08 00:34:39 +04:00
|
|
|
free(winlist);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
gc->hidden = 0;
|
2013-01-01 18:19:56 +04:00
|
|
|
group_setactive(sc, gc->shortcut);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-10 20:16:51 +03:00
|
|
|
group_init(struct screen_ctx *sc)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2009-12-11 20:55:42 +03:00
|
|
|
int i;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2009-12-10 20:16:51 +03:00
|
|
|
TAILQ_INIT(&sc->groupq);
|
|
|
|
sc->group_hideall = 0;
|
2013-04-05 21:07:25 +04:00
|
|
|
/*
|
2012-05-16 05:10:11 +04:00
|
|
|
* See if any group names have already been set and update the
|
|
|
|
* property with ours if they'll have changed.
|
2009-12-11 20:51:42 +03:00
|
|
|
*/
|
|
|
|
group_update_names(sc);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
for (i = 0; i < CALMWM_NGROUPS; i++) {
|
2009-12-10 20:16:51 +03:00
|
|
|
TAILQ_INIT(&sc->groups[i].clients);
|
|
|
|
sc->groups[i].hidden = 0;
|
2013-01-01 18:19:56 +04:00
|
|
|
sc->groups[i].shortcut = i;
|
2009-12-10 20:16:51 +03:00
|
|
|
TAILQ_INSERT_TAIL(&sc->groupq, &sc->groups[i], entry);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
2012-07-03 17:49:03 +04:00
|
|
|
xu_ewmh_net_wm_desktop_viewport(sc);
|
|
|
|
xu_ewmh_net_wm_number_of_desktops(sc);
|
|
|
|
xu_ewmh_net_showing_desktop(sc);
|
|
|
|
xu_ewmh_net_virtual_roots(sc);
|
|
|
|
|
2013-01-10 19:28:11 +04:00
|
|
|
group_setactive(sc, 1);
|
2009-12-11 02:14:58 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 20:51:42 +03:00
|
|
|
void
|
2010-09-26 00:01:27 +04:00
|
|
|
group_make_autogroup(struct conf *conf, char *val, int no)
|
2009-12-11 20:51:42 +03:00
|
|
|
{
|
|
|
|
struct autogroupwin *aw;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
aw = xcalloc(1, sizeof(*aw));
|
|
|
|
|
2010-09-26 00:01:27 +04:00
|
|
|
if ((p = strchr(val, ',')) == NULL) {
|
2009-12-11 20:51:42 +03:00
|
|
|
aw->name = NULL;
|
2010-09-26 00:01:27 +04:00
|
|
|
aw->class = xstrdup(val);
|
2009-12-11 20:51:42 +03:00
|
|
|
} else {
|
|
|
|
*(p++) = '\0';
|
2010-09-26 00:01:27 +04:00
|
|
|
aw->name = xstrdup(val);
|
2010-07-30 16:28:19 +04:00
|
|
|
aw->class = xstrdup(p);
|
2009-12-11 20:51:42 +03:00
|
|
|
}
|
|
|
|
aw->num = no;
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&conf->autogroupq, aw, entry);
|
|
|
|
}
|
|
|
|
|
2009-12-11 02:14:58 +03:00
|
|
|
static void
|
2009-12-11 20:55:42 +03:00
|
|
|
group_setactive(struct screen_ctx *sc, long idx)
|
2009-12-11 02:14:58 +03:00
|
|
|
{
|
|
|
|
sc->group_active = &sc->groups[idx];
|
2012-07-03 17:49:03 +04:00
|
|
|
|
|
|
|
xu_ewmh_net_current_desktop(sc, idx);
|
2009-05-17 21:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
group_movetogroup(struct client_ctx *cc, int idx)
|
|
|
|
{
|
2009-12-10 20:16:51 +03:00
|
|
|
struct screen_ctx *sc = cc->sc;
|
2011-09-19 11:23:03 +04:00
|
|
|
struct group_ctx *gc;
|
2009-12-10 20:16:51 +03:00
|
|
|
|
2009-05-17 21:04:59 +04:00
|
|
|
if (idx < 0 || idx >= CALMWM_NGROUPS)
|
|
|
|
err(1, "group_movetogroup: index out of range (%d)", idx);
|
|
|
|
|
2011-09-19 11:23:03 +04:00
|
|
|
gc = &sc->groups[idx];
|
2011-12-30 00:48:38 +04:00
|
|
|
if (cc->group == gc)
|
|
|
|
return;
|
2011-09-19 11:23:03 +04:00
|
|
|
if (gc->hidden) {
|
2009-05-19 16:49:37 +04:00
|
|
|
client_hide(cc);
|
2011-09-19 11:23:03 +04:00
|
|
|
gc->nhidden++;
|
|
|
|
}
|
2011-12-30 00:48:38 +04:00
|
|
|
group_add(gc, cc);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
2008-03-22 18:09:45 +03:00
|
|
|
/*
|
|
|
|
* Colouring for groups upon add/remove.
|
2007-04-27 21:58:48 +04:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
group_sticky_toggle_enter(struct client_ctx *cc)
|
|
|
|
{
|
2009-12-10 20:16:51 +03:00
|
|
|
struct screen_ctx *sc = cc->sc;
|
2012-12-17 21:48:57 +04:00
|
|
|
struct group_ctx *gc = sc->group_active;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (gc == cc->group) {
|
2009-05-18 04:23:35 +04:00
|
|
|
group_remove(cc);
|
2012-12-17 21:48:57 +04:00
|
|
|
cc->flags |= CLIENT_UNGROUP;
|
2007-04-27 21:58:48 +04:00
|
|
|
} else {
|
2009-05-18 04:23:35 +04:00
|
|
|
group_add(gc, cc);
|
2012-12-17 21:48:57 +04:00
|
|
|
cc->flags |= CLIENT_GROUP;
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
client_draw_border(cc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
group_sticky_toggle_exit(struct client_ctx *cc)
|
|
|
|
{
|
2012-12-17 21:48:57 +04:00
|
|
|
cc->flags &= ~CLIENT_HIGHLIGHT;
|
2007-04-27 21:58:48 +04:00
|
|
|
client_draw_border(cc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-01-15 03:32:35 +03:00
|
|
|
* if group_hidetoggle would produce no effect, toggle the group's hidden state
|
2007-04-27 21:58:48 +04:00
|
|
|
*/
|
2009-01-15 03:32:35 +03:00
|
|
|
static void
|
2009-05-18 04:23:35 +04:00
|
|
|
group_fix_hidden_state(struct group_ctx *gc)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct client_ctx *cc;
|
|
|
|
int same = 0;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
TAILQ_FOREACH(cc, &gc->clients, group_entry) {
|
|
|
|
if (gc->hidden == ((cc->flags & CLIENT_HIDDEN) ? 1 : 0))
|
|
|
|
same++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (same == 0)
|
|
|
|
gc->hidden = !gc->hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-10 20:16:51 +03:00
|
|
|
group_hidetoggle(struct screen_ctx *sc, int idx)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct group_ctx *gc;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (idx < 0 || idx >= CALMWM_NGROUPS)
|
|
|
|
err(1, "group_hidetoggle: index out of range (%d)", idx);
|
|
|
|
|
2009-12-10 20:16:51 +03:00
|
|
|
gc = &sc->groups[idx];
|
2009-05-18 04:23:35 +04:00
|
|
|
group_fix_hidden_state(gc);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (gc->hidden)
|
2009-12-10 20:16:51 +03:00
|
|
|
group_show(sc, gc);
|
2013-01-13 17:55:12 +04:00
|
|
|
else {
|
2009-12-10 20:16:51 +03:00
|
|
|
group_hide(sc, gc);
|
2013-01-13 17:55:12 +04:00
|
|
|
/* make clients stick to empty group */
|
|
|
|
if (TAILQ_EMPTY(&gc->clients))
|
|
|
|
group_setactive(sc, idx);
|
|
|
|
}
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
2009-05-14 20:24:04 +04:00
|
|
|
void
|
2009-12-10 20:16:51 +03:00
|
|
|
group_only(struct screen_ctx *sc, int idx)
|
2009-05-14 20:24:04 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (idx < 0 || idx >= CALMWM_NGROUPS)
|
|
|
|
err(1, "group_only: index out of range (%d)", idx);
|
|
|
|
|
|
|
|
for (i = 0; i < CALMWM_NGROUPS; i++) {
|
2009-05-18 03:37:52 +04:00
|
|
|
if (i == idx)
|
2009-12-10 20:16:51 +03:00
|
|
|
group_show(sc, &sc->groups[i]);
|
2009-05-18 03:37:52 +04:00
|
|
|
else
|
2009-12-10 20:16:51 +03:00
|
|
|
group_hide(sc, &sc->groups[i]);
|
2009-05-14 20:24:04 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-27 21:58:48 +04:00
|
|
|
/*
|
2008-05-19 21:11:19 +04:00
|
|
|
* Cycle through active groups. If none exist, then just stay put.
|
2007-04-27 21:58:48 +04:00
|
|
|
*/
|
|
|
|
void
|
2011-09-13 12:37:49 +04:00
|
|
|
group_cycle(struct screen_ctx *sc, int flags)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct group_ctx *gc, *showgroup = NULL;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2009-12-10 20:16:51 +03:00
|
|
|
assert(sc->group_active != NULL);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2009-12-10 20:16:51 +03:00
|
|
|
gc = sc->group_active;
|
2007-04-27 21:58:48 +04:00
|
|
|
for (;;) {
|
2011-09-13 12:37:49 +04:00
|
|
|
gc = (flags & CWM_RCYCLE) ? TAILQ_PREV(gc, group_ctx_q,
|
|
|
|
entry) : TAILQ_NEXT(gc, entry);
|
2007-04-27 21:58:48 +04:00
|
|
|
if (gc == NULL)
|
2011-09-13 12:37:49 +04:00
|
|
|
gc = (flags & CWM_RCYCLE) ? TAILQ_LAST(&sc->groupq,
|
|
|
|
group_ctx_q) : TAILQ_FIRST(&sc->groupq);
|
2009-12-10 20:16:51 +03:00
|
|
|
if (gc == sc->group_active)
|
2007-04-27 21:58:48 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (!TAILQ_EMPTY(&gc->clients) && showgroup == NULL)
|
|
|
|
showgroup = gc;
|
|
|
|
else if (!gc->hidden)
|
2009-12-10 20:16:51 +03:00
|
|
|
group_hide(sc, gc);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (showgroup == NULL)
|
|
|
|
return;
|
|
|
|
|
2009-12-10 20:16:51 +03:00
|
|
|
group_hide(sc, sc->group_active);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (showgroup->hidden)
|
2009-12-10 20:16:51 +03:00
|
|
|
group_show(sc, showgroup);
|
2007-04-27 21:58:48 +04:00
|
|
|
else
|
2013-01-01 18:19:56 +04:00
|
|
|
group_setactive(sc, showgroup->shortcut);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* called when a client is deleted */
|
|
|
|
void
|
|
|
|
group_client_delete(struct client_ctx *cc)
|
|
|
|
{
|
|
|
|
if (cc->group == NULL)
|
2008-04-16 00:24:41 +04:00
|
|
|
return;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
TAILQ_REMOVE(&cc->group->clients, cc, group_entry);
|
|
|
|
cc->group = NULL; /* he he */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
group_menu(XButtonEvent *e)
|
|
|
|
{
|
2009-12-10 20:16:51 +03:00
|
|
|
struct screen_ctx *sc;
|
2008-07-11 18:21:28 +04:00
|
|
|
struct group_ctx *gc;
|
2008-04-16 00:24:41 +04:00
|
|
|
struct menu *mi;
|
2008-07-11 18:21:28 +04:00
|
|
|
struct menu_q menuq;
|
2008-04-16 00:24:41 +04:00
|
|
|
int i;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2009-12-10 20:16:51 +03:00
|
|
|
sc = screen_fromroot(e->root);
|
2007-04-27 21:58:48 +04:00
|
|
|
TAILQ_INIT(&menuq);
|
|
|
|
|
|
|
|
for (i = 0; i < CALMWM_NGROUPS; i++) {
|
2009-12-10 20:16:51 +03:00
|
|
|
gc = &sc->groups[i];
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (TAILQ_EMPTY(&gc->clients))
|
|
|
|
continue;
|
|
|
|
|
2009-06-20 04:22:39 +04:00
|
|
|
mi = xcalloc(1, sizeof(*mi));
|
2007-04-27 21:58:48 +04:00
|
|
|
if (gc->hidden)
|
2011-07-25 19:10:24 +04:00
|
|
|
(void)snprintf(mi->text, sizeof(mi->text), "%d: [%s]",
|
2009-12-11 20:51:42 +03:00
|
|
|
gc->shortcut, sc->group_names[i]);
|
2007-04-27 21:58:48 +04:00
|
|
|
else
|
2011-07-25 19:10:24 +04:00
|
|
|
(void)snprintf(mi->text, sizeof(mi->text), "%d: %s",
|
2009-12-11 20:51:42 +03:00
|
|
|
gc->shortcut, sc->group_names[i]);
|
2007-04-27 21:58:48 +04:00
|
|
|
mi->ctx = gc;
|
|
|
|
TAILQ_INSERT_TAIL(&menuq, mi, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TAILQ_EMPTY(&menuq))
|
|
|
|
return;
|
|
|
|
|
2009-12-10 20:16:51 +03:00
|
|
|
mi = menu_filter(sc, &menuq, NULL, NULL, 0, NULL, NULL);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (mi == NULL || mi->ctx == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
gc = (struct group_ctx *)mi->ctx;
|
|
|
|
|
2009-12-10 20:16:51 +03:00
|
|
|
(gc->hidden) ? group_show(sc, gc) : group_hide(sc, gc);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-05-16 02:18:00 +04:00
|
|
|
cleanup:
|
2012-12-17 18:32:39 +04:00
|
|
|
menuq_clear(&menuq);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-10 20:16:51 +03:00
|
|
|
group_alltoggle(struct screen_ctx *sc)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
int i;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-04-16 00:24:41 +04:00
|
|
|
for (i = 0; i < CALMWM_NGROUPS; i++) {
|
2009-12-10 20:16:51 +03:00
|
|
|
if (sc->group_hideall)
|
|
|
|
group_show(sc, &sc->groups[i]);
|
2007-04-27 21:58:48 +04:00
|
|
|
else
|
2009-12-10 20:16:51 +03:00
|
|
|
group_hide(sc, &sc->groups[i]);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
2009-12-10 20:16:51 +03:00
|
|
|
sc->group_hideall = (!sc->group_hideall);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
group_autogroup(struct client_ctx *cc)
|
|
|
|
{
|
2009-12-10 20:16:51 +03:00
|
|
|
struct screen_ctx *sc = cc->sc;
|
2008-07-11 18:21:28 +04:00
|
|
|
struct autogroupwin *aw;
|
|
|
|
struct group_ctx *gc;
|
2012-11-29 08:25:49 +04:00
|
|
|
int no = -1, both_match = 0;
|
2009-12-11 20:55:42 +03:00
|
|
|
long *grpno;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (cc->app_class == NULL || cc->app_name == NULL)
|
|
|
|
return;
|
2010-09-26 00:01:27 +04:00
|
|
|
|
2012-07-03 17:49:03 +04:00
|
|
|
if (xu_getprop(cc->win, ewmh[_NET_WM_DESKTOP].atom,
|
|
|
|
XA_CARDINAL, 1, (unsigned char **)&grpno) > 0) {
|
2009-12-11 20:55:42 +03:00
|
|
|
if (*grpno == 0xffffffff)
|
|
|
|
no = 0;
|
|
|
|
else if (*grpno > CALMWM_NGROUPS || *grpno < 0)
|
|
|
|
no = CALMWM_NGROUPS - 1;
|
|
|
|
else
|
2013-01-01 18:19:56 +04:00
|
|
|
no = *grpno;
|
2009-12-11 20:55:42 +03:00
|
|
|
XFree(grpno);
|
2009-01-27 03:42:53 +03:00
|
|
|
} else {
|
|
|
|
TAILQ_FOREACH(aw, &Conf.autogroupq, entry) {
|
2012-11-29 08:25:49 +04:00
|
|
|
if (strcmp(aw->class, cc->app_class) == 0) {
|
|
|
|
if ((aw->name != NULL) &&
|
|
|
|
(strcmp(aw->name, cc->app_name) == 0)) {
|
|
|
|
no = aw->num;
|
|
|
|
both_match = 1;
|
|
|
|
} else if (aw->name == NULL && !both_match)
|
|
|
|
no = aw->num;
|
2009-01-27 03:42:53 +03:00
|
|
|
}
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-11 20:51:42 +03:00
|
|
|
/* no group please */
|
|
|
|
if (no == 0)
|
2008-05-19 21:13:55 +04:00
|
|
|
return;
|
|
|
|
|
2009-12-10 20:16:51 +03:00
|
|
|
TAILQ_FOREACH(gc, &sc->groupq, entry) {
|
2009-12-11 20:51:42 +03:00
|
|
|
if (gc->shortcut == no) {
|
2009-05-18 04:23:35 +04:00
|
|
|
group_add(gc, cc);
|
2008-03-23 00:34:07 +03:00
|
|
|
return;
|
|
|
|
}
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:34:07 +03:00
|
|
|
if (Conf.flags & CONF_STICKY_GROUPS)
|
2009-12-10 20:16:51 +03:00
|
|
|
group_add(sc->group_active, cc);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
2009-12-11 20:51:42 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
group_update_names(struct screen_ctx *sc)
|
|
|
|
{
|
|
|
|
char **strings, *p;
|
|
|
|
unsigned char *prop_ret;
|
2012-09-10 00:52:57 +04:00
|
|
|
int i = 0, j = 0, nstrings = 0, n = 0, setnames = 0;
|
|
|
|
|
|
|
|
if ((j = xu_getprop(sc->rootwin, ewmh[_NET_DESKTOP_NAMES].atom,
|
|
|
|
cwmh[UTF8_STRING].atom, 0xffffff, (u_char **)&prop_ret)) > 0) {
|
|
|
|
prop_ret[j - 1] = '\0'; /* paranoia */
|
|
|
|
while (i < j) {
|
2009-12-11 20:51:42 +03:00
|
|
|
if (prop_ret[i++] == '\0')
|
|
|
|
nstrings++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
strings = xmalloc((nstrings < CALMWM_NGROUPS ? CALMWM_NGROUPS :
|
|
|
|
nstrings) * sizeof(*strings));
|
|
|
|
|
2012-11-09 00:18:19 +04:00
|
|
|
p = (char *)prop_ret;
|
2009-12-11 20:51:42 +03:00
|
|
|
while (n < nstrings) {
|
|
|
|
strings[n++] = xstrdup(p);
|
|
|
|
p += strlen(p) + 1;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* make sure we always set our defaults if nothing is there to
|
|
|
|
* replace them.
|
|
|
|
*/
|
|
|
|
if (n < CALMWM_NGROUPS) {
|
|
|
|
setnames = 1;
|
2013-01-01 18:19:56 +04:00
|
|
|
i = 0;
|
2009-12-11 20:51:42 +03:00
|
|
|
while (n < CALMWM_NGROUPS)
|
|
|
|
strings[n++] = xstrdup(shortcut_to_name[i++]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prop_ret != NULL)
|
|
|
|
XFree(prop_ret);
|
|
|
|
if (sc->group_nonames != 0)
|
2012-11-08 00:34:39 +04:00
|
|
|
free(sc->group_names);
|
2009-12-11 20:51:42 +03:00
|
|
|
|
|
|
|
sc->group_names = strings;
|
|
|
|
sc->group_nonames = n;
|
|
|
|
if (setnames)
|
|
|
|
group_set_names(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
group_set_names(struct screen_ctx *sc)
|
|
|
|
{
|
2012-11-09 00:18:19 +04:00
|
|
|
char *p, *q;
|
2009-12-11 20:51:42 +03:00
|
|
|
size_t len = 0, tlen, slen;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sc->group_nonames; i++)
|
|
|
|
len += strlen(sc->group_names[i]) + 1;
|
2009-12-15 06:38:11 +03:00
|
|
|
q = p = xcalloc(len, sizeof(*p));
|
2009-12-11 20:51:42 +03:00
|
|
|
|
|
|
|
tlen = len;
|
|
|
|
for (i = 0; i < sc->group_nonames; i++) {
|
|
|
|
slen = strlen(sc->group_names[i]) + 1;
|
2011-07-25 19:10:24 +04:00
|
|
|
(void)strlcpy(q, sc->group_names[i], tlen);
|
2009-12-11 20:51:42 +03:00
|
|
|
tlen -= slen;
|
|
|
|
q += slen;
|
|
|
|
}
|
2012-05-17 01:57:21 +04:00
|
|
|
|
2012-07-03 17:49:03 +04:00
|
|
|
xu_ewmh_net_desktop_names(sc, p, len);
|
2009-12-11 20:51:42 +03:00
|
|
|
}
|