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