mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
Compare commits
228 Commits
OPENBSD_4_
...
v5.1
Author | SHA1 | Date | |
---|---|---|---|
601779351c | |||
5f79bace21 | |||
de5efc6a54 | |||
1603d18560 | |||
fd9b83a232 | |||
96ebac8b04 | |||
22c2bc618b | |||
cbe46b651f | |||
fded46ba9f | |||
901a75d3c6 | |||
f60f630b81 | |||
58077c157b | |||
ce34d0066e | |||
7c7a5bdcdc | |||
ba3dfcf7bd | |||
54c1b90725 | |||
22f366830e | |||
3c67ec8ccc | |||
796b32123d | |||
b96caa16e6 | |||
b1d81b7eb6 | |||
82d31aec1d | |||
a262f8e80c | |||
840323558d | |||
d85b3adc0c | |||
44d8b1d3ac | |||
b852a73a60 | |||
325129c6ba | |||
142a36a0c0 | |||
b51f8e6a99 | |||
a4683b55f8 | |||
0dcf7efb8e | |||
be3b8a0748 | |||
2dc8df110c | |||
513c35dca9 | |||
912dd46a7e | |||
30dbdf4178 | |||
f51f3cb9c2 | |||
69ac0624cc | |||
c585dfbf32 | |||
3db2d84fa8 | |||
bcf90f5f34 | |||
0573d184f7 | |||
d8747ae702 | |||
8f1c583361 | |||
34ba6cdbcc | |||
b230e611be | |||
c566b31bd0 | |||
d39f5b9183 | |||
c8ea76a965 | |||
c2a8363dd9 | |||
f6fcd0eb5d | |||
69cc58555d | |||
89d8a14b6d | |||
9a6a2d3cf3 | |||
f067809af4 | |||
64d8bb630a | |||
fa64bc2f32 | |||
c8cd94882d | |||
a90a0b5705 | |||
43450c8fd7 | |||
760c6b5522 | |||
604a5d07a4 | |||
8ed968601e | |||
c62c0ee9db | |||
2bac9a6be9 | |||
349b3295b8 | |||
5972c7a507 | |||
e28a7f832e | |||
9c587d9725 | |||
765479fc86 | |||
a50bfb613d | |||
2c706e60c7 | |||
8f88cd474a | |||
9b4985439e | |||
3ff303658c | |||
a12fb346a2 | |||
00b502b1da | |||
e03323d22e | |||
9eaece0541 | |||
64e62989d0 | |||
0884d38e3b | |||
5bc15cdb58 | |||
cd23316a72 | |||
111a88129d | |||
10622cf40d | |||
a64855f9cc | |||
e6d9effa8d | |||
b11c12e99b | |||
1f310d57e2 | |||
ff3df256a1 | |||
dee6ac5b7d | |||
2d66003e4b | |||
917bce4b8d | |||
c9a14a8f40 | |||
2440efad06 | |||
aaca5b7e45 | |||
2a5e1791d4 | |||
e0c9657773 | |||
85a53083cb | |||
72e6d2d0a9 | |||
f769df540d | |||
a292c96977 | |||
b12e6fc5cd | |||
46c9b5cbae | |||
d90ab51111 | |||
50aff37f50 | |||
507480a695 | |||
c4a97053cd | |||
e88bda0df5 | |||
ccb207a8a8 | |||
09a2d7fb98 | |||
b27c3c22b5 | |||
2ad2b5f31d | |||
597cb25820 | |||
b6b7d273d4 | |||
49661d405b | |||
3b87bdb047 | |||
28e94b2fbc | |||
a0ec2515e9 | |||
b35cbf81d8 | |||
9b04930f24 | |||
a7c3a7cac3 | |||
134e777cf0 | |||
ee7df6a95f | |||
aa88d5848e | |||
728d2a40dd | |||
3c60d854db | |||
3e309894c1 | |||
46630531f8 | |||
ab4d36531c | |||
892e1e1c0d | |||
4e2014863b | |||
42bf29fb20 | |||
afaf69cefc | |||
85d8697676 | |||
4af6a60d84 | |||
38ad2e1d9c | |||
7295c51155 | |||
b9f8367089 | |||
0a44f2e5c4 | |||
1968561fcc | |||
95f65b8be6 | |||
8fd4ff1c7c | |||
fcb2684db1 | |||
e2b1cb98c1 | |||
028a1778db | |||
09d88f4a18 | |||
e7f0d63413 | |||
82911249e2 | |||
e095e955a8 | |||
590eb4f37b | |||
f44862be9c | |||
b13d592c57 | |||
bcc0f73bb6 | |||
58d12134b1 | |||
18c7d89c98 | |||
ee59e4a5a1 | |||
055b244bb4 | |||
71ad069846 | |||
11b4b7fec6 | |||
61f841ea58 | |||
d7589ca80b | |||
3eec3b3802 | |||
d1b84c5415 | |||
6e9fa7548b | |||
8bbc376fd9 | |||
2c29a1de65 | |||
d2cfeb40b4 | |||
382662d003 | |||
9be7726606 | |||
4d5dc5d9ea | |||
5d51c8e0e5 | |||
4c10afe2cc | |||
eb7803269e | |||
6df7cba24e | |||
29cdc29c6e | |||
3de90d44fc | |||
fbb1edf2b3 | |||
64f0038db7 | |||
4f34392258 | |||
655c33c489 | |||
cc68490fe1 | |||
ea96e92ac8 | |||
8a490fc270 | |||
8346de997f | |||
17ae65adc5 | |||
507b65a27f | |||
4fe12f528c | |||
6ad198022b | |||
c750462d13 | |||
9203c7e8ca | |||
b23cef2e4a | |||
01af04a342 | |||
7660bf0db0 | |||
779177a53d | |||
87964e5c7e | |||
e239976078 | |||
712f3f62c7 | |||
e2f3810fe8 | |||
1b269199c1 | |||
0548673f2f | |||
bd4c4d7734 | |||
fa87ef4a9e | |||
399253a4ff | |||
ec8e6052ba | |||
5c757cc7f4 | |||
49e218cf53 | |||
7e110f379b | |||
c07123ec78 | |||
d1050afb60 | |||
dcfae161a2 | |||
0aca400461 | |||
590169ce24 | |||
99afa5091f | |||
b47283ab41 | |||
b523788c0e | |||
ee0ec9a453 | |||
d2a54bc115 | |||
841c646a2b | |||
25af744559 | |||
be5dfb4ea4 | |||
a0739c6cd4 | |||
e2610449d1 | |||
2bd5e53c2e | |||
60a88f54cc | |||
61601991b5 | |||
a0082c58a4 |
51
Makefile
51
Makefile
@ -1,24 +1,47 @@
|
||||
# $OpenBSD$
|
||||
|
||||
.include <bsd.xconf.mk>
|
||||
# cwm makefile for BSD make and GNU make
|
||||
# uses pkg-config, DESTDIR and PREFIX
|
||||
|
||||
PROG= cwm
|
||||
|
||||
SRCS= calmwm.c screen.c xmalloc.c client.c grab.c menu.c \
|
||||
search.c util.c xutil.c conf.c input.c xevents.c group.c \
|
||||
PREFIX= /usr/local
|
||||
|
||||
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
|
||||
|
||||
CPPFLAGS+= -I${X11BASE}/include -I${X11BASE}/include/freetype2 -I${.CURDIR}
|
||||
OBJS= calmwm.o screen.o xmalloc.o client.o menu.o \
|
||||
search.o util.o xutil.o conf.o xevents.o group.o \
|
||||
kbfunc.o mousefunc.o font.o strlcpy.o strlcat.o y.tab.o \
|
||||
strtonum.o fgetln.o
|
||||
|
||||
LDADD+= -L${X11BASE}/lib -lXft -lXrender -lX11 -lXau -lXdmcp -lXext \
|
||||
-lfontconfig -lexpat -lfreetype -lz
|
||||
CPPFLAGS+= `pkg-config --cflags fontconfig x11 xft xinerama xrandr`
|
||||
|
||||
MANDIR= ${X11BASE}/man/cat
|
||||
MAN= cwm.1 cwmrc.5
|
||||
CFLAGS= -Wall -O2 -g
|
||||
|
||||
CLEANFILES= cwm.cat1 cwmrc.cat5
|
||||
LDFLAGS+= `pkg-config --libs fontconfig x11 xft xinerama xrandr`
|
||||
|
||||
obj: _xenocara_obj
|
||||
MANPREFIX= ${PREFIX}/share/man
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
.include <bsd.xorg.mk>
|
||||
all: ${PROG}
|
||||
|
||||
clean:
|
||||
rm -rf ${OBJS} ${PROG} y.tab.c
|
||||
|
||||
y.tab.c: parse.y
|
||||
yacc parse.y
|
||||
|
||||
${PROG}: ${OBJS} y.tab.o
|
||||
${CC} ${OBJS} ${LDFLAGS} -o ${PROG}
|
||||
|
||||
.c.o:
|
||||
${CC} -c ${CFLAGS} ${CPPFLAGS} $<
|
||||
|
||||
install: ${PROG}
|
||||
install -d ${DESTDIR}${PREFIX}/bin ${DESTDIR}${MANPREFIX}/man1 ${DESTDIR}${MANPREFIX}/man5
|
||||
install -m 755 cwm ${DESTDIR}${PREFIX}/bin
|
||||
install -m 644 cwm.1 ${DESTDIR}${MANPREFIX}/man1
|
||||
install -m 644 cwmrc.5 ${DESTDIR}${MANPREFIX}/man5
|
||||
|
||||
release:
|
||||
VERSION=$$(git describe --tags | sed 's/^v//;s/-[^.]*$$//') && \
|
||||
git archive --prefix=cwm-$$VERSION/ -o cwm-$$VERSION.tar.gz HEAD
|
||||
|
66
README
66
README
@ -1,58 +1,24 @@
|
||||
--------------------------------------------------------------------------------
|
||||
cwm release three
|
||||
--------------------------------------------------------------------------------
|
||||
by Marius Aamodt Eriksen <marius@monkey.org>
|
||||
contributions by Andy Adamson <dros@monkey.org>,
|
||||
Niels Provos <provos@monkey.org>,
|
||||
Martin Murray <mmurray@monkey.org>,
|
||||
Dimitris Economou <dimeco@stanford.edu> &
|
||||
Antti Nyk<79>nen <aon@iki.fi>.
|
||||
This is a port of OpenBSD's excellent cwm[0] to Linux and other
|
||||
Unices.
|
||||
|
||||
http://monkey.org/~marius/cwm
|
||||
cwm is a window manager for X11 which contains many features that
|
||||
concentrate on the efficiency and transparency of window
|
||||
management. cwm also aims to maintain the simplest and most
|
||||
pleasant aesthetic.
|
||||
|
||||
DESCRIPTION
|
||||
This port requires pkg-config, Xft, Xinerama and Xrandr. The included
|
||||
Makefile should work with both GNU make and BSD make.
|
||||
|
||||
cwm is a window manager initially inspired by evilwm[1]. It
|
||||
developed out of modifications to evilwm, but eventually the code
|
||||
base of evilwm did not accomodate well for the new features added.
|
||||
So calmwm was written from scratch.
|
||||
This version actively tracks changes in the OpenBSD CVS repository.
|
||||
Releases are roughly coordinated.
|
||||
|
||||
Its main goal is to be as efficient as possible, while providing
|
||||
a very clean, simple & attractive aesthetic.
|
||||
The revision controlled version is at https://github.com/chneukirchen/cwm
|
||||
Releases can be found at http://chneukirchen.org/releases
|
||||
|
||||
cwm has several novel features, including the ability to search
|
||||
for windows.
|
||||
ChangeLog:
|
||||
|
||||
HIGHLIGHTS IN RELEASE TWO
|
||||
2012-05-02: First public release 5.1 of portable cwm.
|
||||
|
||||
* Improved alt-tabbing, including the ability to reverse cycle.
|
||||
* Display of a context menu when alt-tabbing, showing the previous,
|
||||
current and next window in the cycle order.
|
||||
* Much improved ranking in search.
|
||||
* In search-menus, the ability to list every item.
|
||||
--Christian Neukirchen <chneukirchen@gmail.com>
|
||||
|
||||
HIGHLIGHTS IN RELEASE THREE
|
||||
|
||||
* More search ranking improvements
|
||||
* Many contributions by Antti Nyk<79>nen: keyboard binding "i18n",
|
||||
show window labels in minimized window menu, automatic window
|
||||
grouping, MWM hints support & some bug fixes.
|
||||
* Xft support & the addition of the -f flag (see manpage).
|
||||
|
||||
INSTALL
|
||||
|
||||
./configure
|
||||
make
|
||||
su
|
||||
make install
|
||||
|
||||
DOCUMENTATION
|
||||
|
||||
See the manpage cwm(1).
|
||||
|
||||
LICENSE
|
||||
|
||||
cwm is distributed under a BSD like license. Please see the LICENSE
|
||||
file or the top of any source file for more information.
|
||||
|
||||
[1] http://evilwm.sourceforge.net/
|
||||
[0]: http://www.openbsd.org/cgi-bin/cvsweb/xenocara/app/cwm/
|
||||
|
28
TODO
28
TODO
@ -1,28 +0,0 @@
|
||||
- window initial position
|
||||
|
||||
- don't map windows if it's within [some time increment] of active typing,
|
||||
this is part of the "calm" goal. also, it helps if you're mindlessly
|
||||
typing in a password and the keyboard input ends up in some other window,
|
||||
bad...
|
||||
|
||||
- integrate everything into /ONE/ event loop.
|
||||
register handlers, with the ability to select, for example,
|
||||
a window, or an event, etc. (no, maybe not...)
|
||||
|
||||
- ignoreq, always lower them. perhaps implement by lowering the entire
|
||||
queue on each XLower...
|
||||
|
||||
- search window should try to stay inside of the screen boundaries.
|
||||
|
||||
- geographical keyboard navigation (window switching)
|
||||
|
||||
- search should ignore the current window. (not add to match list).
|
||||
|
||||
- make kbd shortcuts/events more general. the ability to associate an
|
||||
event with a mode (i.e. prioritize). gets rid of hacky-ness in
|
||||
groups, etc.
|
||||
|
||||
- figure out what's up when alt-tab goes back to the current window
|
||||
once before moving on.
|
||||
|
||||
- cache all the atoms somewhere.
|
274
calmwm.c
274
calmwm.c
@ -15,37 +15,45 @@
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* $Id$
|
||||
* $OpenBSD$
|
||||
*/
|
||||
|
||||
#include "headers.h"
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "calmwm.h"
|
||||
|
||||
Display *X_Dpy;
|
||||
|
||||
Cursor Cursor_move;
|
||||
Cursor Cursor_resize;
|
||||
Cursor Cursor_select;
|
||||
Cursor Cursor_default;
|
||||
Cursor Cursor_move;
|
||||
Cursor Cursor_normal;
|
||||
Cursor Cursor_question;
|
||||
Cursor Cursor_resize;
|
||||
|
||||
struct screen_ctx_q Screenq;
|
||||
struct screen_ctx *Curscreen;
|
||||
u_int Nscreens;
|
||||
struct screen_ctx_q Screenq = TAILQ_HEAD_INITIALIZER(Screenq);
|
||||
struct client_ctx_q Clientq = TAILQ_HEAD_INITIALIZER(Clientq);
|
||||
|
||||
struct client_ctx_q Clientq;
|
||||
|
||||
int Doshape, Shape_ev;
|
||||
int Starting;
|
||||
int HasXinerama, HasRandr, Randr_ev;
|
||||
struct conf Conf;
|
||||
|
||||
/* From TWM */
|
||||
#define gray_width 2
|
||||
#define gray_height 2
|
||||
static char gray_bits[] = {0x02, 0x01};
|
||||
|
||||
static void _sigchld_cb(int);
|
||||
static void sigchld_cb(int);
|
||||
static void dpy_init(const char *);
|
||||
static int x_errorhandler(Display *, XErrorEvent *);
|
||||
static int x_wmerrorhandler(Display *, XErrorEvent *);
|
||||
static void x_setup(void);
|
||||
static void x_setupscreen(struct screen_ctx *, u_int);
|
||||
static void x_teardown(void);
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
@ -69,71 +77,57 @@ main(int argc, char **argv)
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
/* Ignore a few signals. */
|
||||
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
|
||||
if (signal(SIGCHLD, sigchld_cb) == SIG_ERR)
|
||||
err(1, "signal");
|
||||
|
||||
if (signal(SIGCHLD, _sigchld_cb) == SIG_ERR)
|
||||
err(1, "signal");
|
||||
|
||||
group_init();
|
||||
|
||||
Starting = 1;
|
||||
dpy_init(display_name);
|
||||
|
||||
bzero(&Conf, sizeof(Conf));
|
||||
conf_setup(&Conf, conf_file);
|
||||
client_setup();
|
||||
xu_getatoms();
|
||||
x_setup();
|
||||
Starting = 0;
|
||||
|
||||
xev_init();
|
||||
XEV_QUICK(NULL, NULL, MapRequest, xev_handle_maprequest, NULL);
|
||||
XEV_QUICK(NULL, NULL, UnmapNotify, xev_handle_unmapnotify, NULL);
|
||||
XEV_QUICK(NULL, NULL, ConfigureRequest,
|
||||
xev_handle_configurerequest, NULL);
|
||||
XEV_QUICK(NULL, NULL, PropertyNotify, xev_handle_propertynotify, NULL);
|
||||
XEV_QUICK(NULL, NULL, EnterNotify, xev_handle_enternotify, NULL);
|
||||
XEV_QUICK(NULL, NULL, LeaveNotify, xev_handle_leavenotify, NULL);
|
||||
XEV_QUICK(NULL, NULL, ButtonPress, xev_handle_buttonpress, NULL);
|
||||
XEV_QUICK(NULL, NULL, ButtonRelease, xev_handle_buttonrelease, NULL);
|
||||
XEV_QUICK(NULL, NULL, KeyPress, xev_handle_keypress, NULL);
|
||||
XEV_QUICK(NULL, NULL, KeyRelease, xev_handle_keyrelease, NULL);
|
||||
XEV_QUICK(NULL, NULL, Expose, xev_handle_expose, NULL);
|
||||
XEV_QUICK(NULL, NULL, DestroyNotify, xev_handle_destroynotify, NULL);
|
||||
XEV_QUICK(NULL, NULL, ClientMessage, xev_handle_clientmessage, NULL);
|
||||
XEV_QUICK(NULL, NULL, MappingNotify, xev_handle_mapping, NULL);
|
||||
|
||||
xev_loop();
|
||||
|
||||
x_teardown();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
dpy_init(const char *dpyname)
|
||||
{
|
||||
int i;
|
||||
|
||||
XSetErrorHandler(x_errorhandler);
|
||||
|
||||
if ((X_Dpy = XOpenDisplay(dpyname)) == NULL)
|
||||
errx(1, "unable to open display \"%s\"",
|
||||
XDisplayName(dpyname));
|
||||
|
||||
XSetErrorHandler(x_wmerrorhandler);
|
||||
XSelectInput(X_Dpy, DefaultRootWindow(X_Dpy), SubstructureRedirectMask);
|
||||
XSync(X_Dpy, False);
|
||||
XSetErrorHandler(x_errorhandler);
|
||||
|
||||
Doshape = XShapeQueryExtension(X_Dpy, &Shape_ev, &i);
|
||||
|
||||
TAILQ_INIT(&Screenq);
|
||||
HasRandr = XRRQueryExtension(X_Dpy, &Randr_ev, &i);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
x_setup(void)
|
||||
{
|
||||
struct screen_ctx *sc;
|
||||
struct keybinding *kb;
|
||||
int i;
|
||||
|
||||
Nscreens = ScreenCount(X_Dpy);
|
||||
for (i = 0; i < (int)Nscreens; i++) {
|
||||
XMALLOC(sc, struct screen_ctx);
|
||||
Cursor_default = XCreateFontCursor(X_Dpy, XC_X_cursor);
|
||||
Cursor_move = XCreateFontCursor(X_Dpy, XC_fleur);
|
||||
Cursor_normal = XCreateFontCursor(X_Dpy, XC_left_ptr);
|
||||
Cursor_question = XCreateFontCursor(X_Dpy, XC_question_arrow);
|
||||
Cursor_resize = XCreateFontCursor(X_Dpy, XC_bottom_right_corner);
|
||||
|
||||
for (i = 0; i < ScreenCount(X_Dpy); i++) {
|
||||
sc = xcalloc(1, sizeof(*sc));
|
||||
x_setupscreen(sc, i);
|
||||
TAILQ_INSERT_TAIL(&Screenq, sc, entry);
|
||||
}
|
||||
@ -144,166 +138,107 @@ x_setup(void)
|
||||
*/
|
||||
TAILQ_FOREACH(kb, &Conf.keybindingq, entry)
|
||||
conf_grab(&Conf, kb);
|
||||
|
||||
|
||||
Cursor_move = XCreateFontCursor(X_Dpy, XC_fleur);
|
||||
Cursor_resize = XCreateFontCursor(X_Dpy, XC_bottom_right_corner);
|
||||
Cursor_select = XCreateFontCursor(X_Dpy, XC_hand1);
|
||||
Cursor_default = XCreateFontCursor(X_Dpy, XC_X_cursor);
|
||||
Cursor_question = XCreateFontCursor(X_Dpy, XC_question_arrow);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
x_teardown(void)
|
||||
{
|
||||
struct screen_ctx *sc;
|
||||
|
||||
TAILQ_FOREACH(sc, &Screenq, entry)
|
||||
XFreeGC(X_Dpy, sc->gc);
|
||||
|
||||
XCloseDisplay(X_Dpy);
|
||||
}
|
||||
|
||||
static void
|
||||
x_setupscreen(struct screen_ctx *sc, u_int which)
|
||||
{
|
||||
XColor tmp;
|
||||
XGCValues gv;
|
||||
Window *wins, w0, w1;
|
||||
XWindowAttributes winattr;
|
||||
XSetWindowAttributes rootattr;
|
||||
int fake;
|
||||
u_int nwins, i;
|
||||
|
||||
Curscreen = sc;
|
||||
|
||||
sc->display = x_screenname(which);
|
||||
sc->which = which;
|
||||
sc->rootwin = RootWindow(X_Dpy, which);
|
||||
sc->rootwin = RootWindow(X_Dpy, sc->which);
|
||||
|
||||
sc->xmax = DisplayWidth(X_Dpy, sc->which);
|
||||
sc->ymax = DisplayHeight(X_Dpy, sc->which);
|
||||
conf_gap(&Conf, sc);
|
||||
screen_update_geometry(sc, DisplayWidth(X_Dpy, sc->which),
|
||||
DisplayHeight(X_Dpy, sc->which));
|
||||
|
||||
XAllocNamedColor(X_Dpy, DefaultColormap(X_Dpy, which),
|
||||
"black", &sc->fgcolor, &tmp);
|
||||
XAllocNamedColor(X_Dpy, DefaultColormap(X_Dpy, which),
|
||||
"#00cc00", &sc->bgcolor, &tmp);
|
||||
XAllocNamedColor(X_Dpy,DefaultColormap(X_Dpy, which),
|
||||
"blue", &sc->fccolor, &tmp);
|
||||
XAllocNamedColor(X_Dpy, DefaultColormap(X_Dpy, which),
|
||||
"red", &sc->redcolor, &tmp);
|
||||
XAllocNamedColor(X_Dpy, DefaultColormap(X_Dpy, which),
|
||||
"#00ccc8", &sc->cyancolor, &tmp);
|
||||
XAllocNamedColor(X_Dpy, DefaultColormap(X_Dpy, which),
|
||||
"white", &sc->whitecolor, &tmp);
|
||||
XAllocNamedColor(X_Dpy, DefaultColormap(X_Dpy, which),
|
||||
"black", &sc->blackcolor, &tmp);
|
||||
conf_color(&Conf, sc);
|
||||
|
||||
sc->blackpixl = BlackPixel(X_Dpy, sc->which);
|
||||
sc->whitepixl = WhitePixel(X_Dpy, sc->which);
|
||||
sc->bluepixl = sc->fccolor.pixel;
|
||||
sc->redpixl = sc->redcolor.pixel;
|
||||
sc->cyanpixl = sc->cyancolor.pixel;
|
||||
|
||||
sc->gray = XCreatePixmapFromBitmapData(X_Dpy, sc->rootwin,
|
||||
gray_bits, gray_width, gray_height,
|
||||
sc->blackpixl, sc->whitepixl, DefaultDepth(X_Dpy, sc->which));
|
||||
|
||||
sc->blue = XCreatePixmapFromBitmapData(X_Dpy, sc->rootwin,
|
||||
gray_bits, gray_width, gray_height,
|
||||
sc->bluepixl, sc->whitepixl, DefaultDepth(X_Dpy, sc->which));
|
||||
|
||||
sc->red = XCreatePixmapFromBitmapData(X_Dpy, sc->rootwin,
|
||||
gray_bits, gray_width, gray_height,
|
||||
sc->redpixl, sc->whitepixl, DefaultDepth(X_Dpy, sc->which));
|
||||
|
||||
gv.foreground = sc->blackpixl^sc->whitepixl;
|
||||
gv.background = sc->whitepixl;
|
||||
gv.function = GXxor;
|
||||
gv.line_width = 1;
|
||||
gv.subwindow_mode = IncludeInferiors;
|
||||
|
||||
sc->gc = XCreateGC(X_Dpy, sc->rootwin,
|
||||
GCForeground|GCBackground|GCFunction|
|
||||
GCLineWidth|GCSubwindowMode, &gv);
|
||||
|
||||
font_init(sc);
|
||||
conf_font(&Conf);
|
||||
group_init(sc);
|
||||
conf_font(&Conf, sc);
|
||||
|
||||
TAILQ_INIT(&sc->mruq);
|
||||
|
||||
/* Initialize menu window. */
|
||||
menu_init(sc);
|
||||
|
||||
xu_setwmname(sc);
|
||||
|
||||
rootattr.cursor = Cursor_normal;
|
||||
rootattr.event_mask = CHILDMASK|PropertyChangeMask|EnterWindowMask|
|
||||
LeaveWindowMask|ColormapChangeMask|BUTTONMASK;
|
||||
|
||||
XChangeWindowAttributes(X_Dpy, sc->rootwin,
|
||||
CWEventMask|CWCursor, &rootattr);
|
||||
|
||||
/* Deal with existing clients. */
|
||||
XQueryTree(X_Dpy, sc->rootwin, &w0, &w1, &wins, &nwins);
|
||||
|
||||
for (i = 0; i < nwins; i++) {
|
||||
XGetWindowAttributes(X_Dpy, wins[i], &winattr);
|
||||
if (winattr.override_redirect ||
|
||||
winattr.map_state != IsViewable) {
|
||||
char *name;
|
||||
XFetchName(X_Dpy, wins[i], &name);
|
||||
winattr.map_state != IsViewable)
|
||||
continue;
|
||||
}
|
||||
client_new(wins[i], sc, winattr.map_state != IsUnmapped);
|
||||
(void)client_new(wins[i], sc, winattr.map_state != IsUnmapped);
|
||||
}
|
||||
XFree(wins);
|
||||
|
||||
screen_updatestackingorder();
|
||||
screen_updatestackingorder(sc);
|
||||
|
||||
rootattr.event_mask = ChildMask|PropertyChangeMask|EnterWindowMask|
|
||||
LeaveWindowMask|ColormapChangeMask|ButtonMask;
|
||||
|
||||
XChangeWindowAttributes(X_Dpy, sc->rootwin,
|
||||
CWEventMask, &rootattr);
|
||||
if (XineramaQueryExtension(X_Dpy, &fake, &fake) == 1 &&
|
||||
((HasXinerama = XineramaIsActive(X_Dpy)) == 1))
|
||||
HasXinerama = 1;
|
||||
if (HasRandr)
|
||||
XRRSelectInput(X_Dpy, sc->rootwin, RRScreenChangeNotifyMask);
|
||||
/*
|
||||
* initial setup of xinerama screens, if we're using RandR then we'll
|
||||
* redo this whenever the screen changes since a CTRC may have been
|
||||
* added or removed
|
||||
*/
|
||||
screen_init_xinerama(sc);
|
||||
|
||||
XSync(X_Dpy, False);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
char *
|
||||
x_screenname(int which)
|
||||
static int
|
||||
x_wmerrorhandler(Display *dpy, XErrorEvent *e)
|
||||
{
|
||||
char *cp, *dstr, *sn;
|
||||
size_t snlen;
|
||||
errx(1, "root window unavailable - perhaps another wm is running?");
|
||||
|
||||
if (which > 9)
|
||||
errx(1, "Can't handle more than 9 screens. If you need it, "
|
||||
"tell <marius@monkey.org>. It's a trivial fix.");
|
||||
|
||||
dstr = xstrdup(DisplayString(X_Dpy));
|
||||
|
||||
if ((cp = strrchr(dstr, ':')) == NULL)
|
||||
return (NULL);
|
||||
|
||||
if ((cp = strchr(cp, '.')) != NULL)
|
||||
*cp = '\0';
|
||||
|
||||
snlen = strlen(dstr) + 3; /* string, dot, number, null */
|
||||
sn = (char *)xmalloc(snlen);
|
||||
snprintf(sn, snlen, "%s.%d", dstr, which);
|
||||
free(dstr);
|
||||
|
||||
return (sn);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
x_errorhandler(Display *dpy, XErrorEvent *e)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
{
|
||||
char msg[80], number[80], req[80];
|
||||
#if DEBUG
|
||||
char msg[80], number[80], req[80];
|
||||
|
||||
XGetErrorText(X_Dpy, e->error_code, msg, sizeof(msg));
|
||||
snprintf(number, sizeof(number), "%d", e->request_code);
|
||||
XGetErrorDatabaseText(X_Dpy, "XRequest", number,
|
||||
"<unknown>", req, sizeof(req));
|
||||
XGetErrorText(X_Dpy, e->error_code, msg, sizeof(msg));
|
||||
(void)snprintf(number, sizeof(number), "%d", e->request_code);
|
||||
XGetErrorDatabaseText(X_Dpy, "XRequest", number,
|
||||
"<unknown>", req, sizeof(req));
|
||||
|
||||
warnx("%s(0x%x): %s", req, (u_int)e->resourceid, msg);
|
||||
}
|
||||
warnx("%s(0x%x): %s", req, (u_int)e->resourceid, msg);
|
||||
#endif
|
||||
|
||||
if (Starting &&
|
||||
e->error_code == BadAccess &&
|
||||
e->request_code == X_GrabKey)
|
||||
errx(1, "root window unavailable - perhaps another "
|
||||
"wm is running?");
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
_sigchld_cb(int which)
|
||||
sigchld_cb(int which)
|
||||
{
|
||||
pid_t pid;
|
||||
int save_errno = errno;
|
||||
@ -322,6 +257,7 @@ usage(void)
|
||||
{
|
||||
extern char *__progname;
|
||||
|
||||
fprintf(stderr, "usage: %s [-c file] [-d display]\n", __progname);
|
||||
(void)fprintf(stderr, "usage: %s [-c file] [-d display]\n",
|
||||
__progname);
|
||||
exit(1);
|
||||
}
|
||||
|
736
calmwm.h
736
calmwm.h
@ -15,135 +15,179 @@
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* $Id$
|
||||
* $OpenBSD$
|
||||
*/
|
||||
|
||||
#ifndef _CALMWM_H_
|
||||
#define _CALMWM_H_
|
||||
|
||||
#define CALMWM_MAXNAMELEN 256
|
||||
/* ugly stuff */
|
||||
#ifndef TAILQ_END
|
||||
#define TAILQ_END(head) NULL
|
||||
#endif
|
||||
#ifndef __dead
|
||||
#define __dead
|
||||
#endif
|
||||
char *fgetln(FILE *, size_t *);
|
||||
long long strtonum(const char *, long long, long long, const char **);
|
||||
size_t strlcpy(char *, const char *, size_t);
|
||||
size_t strlcat(char *, const char *, size_t);
|
||||
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xft/Xft.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xproto.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/cursorfont.h>
|
||||
#include <X11/extensions/Xinerama.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <X11/keysym.h>
|
||||
|
||||
#undef MIN
|
||||
#undef MAX
|
||||
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
||||
#define MAX(x, y) ((x) > (y) ? (x) : (y))
|
||||
|
||||
#ifndef nitems
|
||||
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
|
||||
#endif
|
||||
|
||||
#define CONFFILE ".cwmrc"
|
||||
#define WMNAME "CWM"
|
||||
|
||||
#define ChildMask (SubstructureRedirectMask|SubstructureNotifyMask)
|
||||
#define ButtonMask (ButtonPressMask|ButtonReleaseMask)
|
||||
#define MouseMask (ButtonMask|PointerMotionMask)
|
||||
#define CHILDMASK (SubstructureRedirectMask|SubstructureNotifyMask)
|
||||
#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
|
||||
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
|
||||
#define KEYMASK (KeyPressMask|ExposureMask)
|
||||
#define MENUMASK (BUTTONMASK|ButtonMotionMask|ExposureMask| \
|
||||
PointerMotionMask)
|
||||
#define MENUGRABMASK (BUTTONMASK|ButtonMotionMask|StructureNotifyMask|\
|
||||
PointerMotionMask)
|
||||
#define SEARCHMASK (KeyPressMask|ExposureMask)
|
||||
|
||||
struct client_ctx;
|
||||
/* kb movement */
|
||||
#define CWM_MOVE 0x0001
|
||||
#define CWM_RESIZE 0x0002
|
||||
#define CWM_PTRMOVE 0x0004
|
||||
#define CWM_BIGMOVE 0x0008
|
||||
#define CWM_UP 0x0010
|
||||
#define CWM_DOWN 0x0020
|
||||
#define CWM_LEFT 0x0040
|
||||
#define CWM_RIGHT 0x0080
|
||||
|
||||
TAILQ_HEAD(cycle_entry_q, client_ctx);
|
||||
/* exec */
|
||||
#define CWM_EXEC_PROGRAM 0x0001
|
||||
#define CWM_EXEC_WM 0x0002
|
||||
|
||||
struct screen_ctx {
|
||||
TAILQ_ENTRY(screen_ctx) entry;
|
||||
/* cycle */
|
||||
#define CWM_CYCLE 0x0001
|
||||
#define CWM_RCYCLE 0x0002
|
||||
#define CWM_INGROUP 0x0004
|
||||
|
||||
u_int which;
|
||||
Window rootwin;
|
||||
Window menuwin;
|
||||
Colormap colormap;
|
||||
XColor bgcolor, fgcolor, fccolor, redcolor, cyancolor,
|
||||
whitecolor, blackcolor;
|
||||
char *display;
|
||||
unsigned long blackpixl, whitepixl, redpixl, bluepixl, cyanpixl;
|
||||
GC gc;
|
||||
#define KBTOGROUP(X) ((X) - 1)
|
||||
|
||||
Pixmap gray, blue, red;
|
||||
|
||||
int altpersist;
|
||||
|
||||
int xmax;
|
||||
int ymax;
|
||||
|
||||
struct cycle_entry_q mruq;
|
||||
|
||||
XftDraw *xftdraw;
|
||||
XftColor xftcolor;
|
||||
union arg {
|
||||
char *c;
|
||||
int i;
|
||||
};
|
||||
|
||||
TAILQ_HEAD(screen_ctx_q, screen_ctx);
|
||||
enum cwmcolor {
|
||||
CWM_COLOR_BORDER_ACTIVE,
|
||||
CWM_COLOR_BORDER_INACTIVE,
|
||||
CWM_COLOR_BORDER_GROUP,
|
||||
CWM_COLOR_BORDER_UNGROUP,
|
||||
CWM_COLOR_FG_MENU,
|
||||
CWM_COLOR_BG_MENU,
|
||||
CWM_COLOR_FONT,
|
||||
CWM_COLOR_MAX
|
||||
};
|
||||
|
||||
#define CLIENT_PROTO_DELETE 0x01
|
||||
#define CLIENT_PROTO_TAKEFOCUS 0x02
|
||||
|
||||
#define CLIENT_MAXNAMEQLEN 5
|
||||
|
||||
#define CLIENT_HIDDEN 0x01
|
||||
#define CLIENT_IGNORE 0x02
|
||||
#define CLIENT_DOMAXIMIZE 0x04
|
||||
#define CLIENT_MAXIMIZED 0x08
|
||||
#define CLIENT_DOVMAXIMIZE 0x10
|
||||
#define CLIENT_VMAXIMIZED 0x20
|
||||
|
||||
#define CLIENT_HIGHLIGHT_BLUE 1
|
||||
#define CLIENT_HIGHLIGHT_RED 2
|
||||
struct color {
|
||||
char *name;
|
||||
unsigned long pixel;
|
||||
};
|
||||
|
||||
struct gap {
|
||||
int top;
|
||||
int bottom;
|
||||
int left;
|
||||
int right;
|
||||
};
|
||||
|
||||
struct winname {
|
||||
TAILQ_ENTRY(winname) entry;
|
||||
char *name;
|
||||
};
|
||||
|
||||
TAILQ_HEAD(winname_q, winname);
|
||||
|
||||
struct client_ctx {
|
||||
TAILQ_ENTRY(client_ctx) entry;
|
||||
TAILQ_ENTRY(client_ctx) searchentry;
|
||||
TAILQ_ENTRY(client_ctx) group_entry;
|
||||
TAILQ_ENTRY(client_ctx) mru_entry;
|
||||
|
||||
struct screen_ctx *sc;
|
||||
Window win;
|
||||
XSizeHints *size;
|
||||
|
||||
Colormap cmap;
|
||||
|
||||
Window pwin;
|
||||
|
||||
u_int bwidth;
|
||||
u_int bwidth; /* border width */
|
||||
struct {
|
||||
int x, y, width, height;
|
||||
int min_dx, min_dy;
|
||||
int x; /* x position */
|
||||
int y; /* y position */
|
||||
int width; /* width */
|
||||
int height;/* height */
|
||||
} geom, savegeom;
|
||||
|
||||
struct {
|
||||
int x,y;
|
||||
int basew; /* desired width */
|
||||
int baseh; /* desired height */
|
||||
int minw; /* minimum width */
|
||||
int minh; /* minimum height */
|
||||
int maxw; /* maximum width */
|
||||
int maxh; /* maximum height */
|
||||
int incw; /* width increment progression */
|
||||
int inch; /* height increment progression */
|
||||
float mina; /* minimum aspect ratio */
|
||||
float maxa; /* maximum aspect ratio */
|
||||
} hint;
|
||||
struct {
|
||||
int x; /* x position */
|
||||
int y; /* y position */
|
||||
} ptr;
|
||||
|
||||
int beepbeep;
|
||||
|
||||
#define CLIENT_PROTO_DELETE 0x0001
|
||||
#define CLIENT_PROTO_TAKEFOCUS 0x0002
|
||||
int xproto;
|
||||
#define CLIENT_HIDDEN 0x0001
|
||||
#define CLIENT_IGNORE 0x0002
|
||||
#define CLIENT_VMAXIMIZED 0x0004
|
||||
#define CLIENT_HMAXIMIZED 0x0008
|
||||
#define CLIENT_FREEZE 0x0010
|
||||
|
||||
#define CLIENT_MAXFLAGS (CLIENT_VMAXIMIZED | CLIENT_HMAXIMIZED)
|
||||
#define CLIENT_MAXIMIZED (CLIENT_VMAXIMIZED | CLIENT_HMAXIMIZED)
|
||||
int flags;
|
||||
int state;
|
||||
char *name;
|
||||
struct winname_q nameq;
|
||||
size_t nameqlen;
|
||||
|
||||
char *label;
|
||||
int active;
|
||||
int stackingorder;
|
||||
#define CLIENT_HIGHLIGHT_GROUP 0x0001
|
||||
#define CLIENT_HIGHLIGHT_UNGROUP 0x0002
|
||||
int highlight;
|
||||
|
||||
struct winname_q nameq;
|
||||
#define CLIENT_MAXNAMEQLEN 5
|
||||
int nameqlen;
|
||||
char *name;
|
||||
char *label;
|
||||
char *matchname;
|
||||
struct group_ctx *group;
|
||||
|
||||
int stackingorder;
|
||||
|
||||
char *app_class;
|
||||
char *app_name;
|
||||
char *app_cliarg;
|
||||
};
|
||||
|
||||
TAILQ_HEAD(client_ctx_q, client_ctx);
|
||||
TAILQ_HEAD(cycle_entry_q, client_ctx);
|
||||
|
||||
static char *shortcut_to_name[] = {
|
||||
"nogroup", "one", "two", "three",
|
||||
"four", "five", "six", "seven",
|
||||
"eight", "nine"
|
||||
struct winmatch {
|
||||
TAILQ_ENTRY(winmatch) entry;
|
||||
#define WIN_MAXTITLELEN 256
|
||||
char title[WIN_MAXTITLELEN];
|
||||
};
|
||||
TAILQ_HEAD(winmatch_q, winmatch);
|
||||
|
||||
struct group_ctx {
|
||||
TAILQ_ENTRY(group_ctx) entry;
|
||||
@ -153,100 +197,87 @@ struct group_ctx {
|
||||
int nhidden;
|
||||
int highstack;
|
||||
};
|
||||
|
||||
TAILQ_HEAD(group_ctx_q, group_ctx);
|
||||
|
||||
/* Autogroups */
|
||||
struct autogroupwin {
|
||||
TAILQ_ENTRY(autogroupwin) entry;
|
||||
|
||||
char *class;
|
||||
char *name;
|
||||
char *group;
|
||||
TAILQ_ENTRY(autogroupwin) entry;
|
||||
char *class;
|
||||
char *name;
|
||||
int num;
|
||||
};
|
||||
|
||||
TAILQ_HEAD(autogroupwin_q, autogroupwin);
|
||||
|
||||
/* NULL/0 values indicate match any. */
|
||||
struct xevent {
|
||||
TAILQ_ENTRY(xevent) entry;
|
||||
Window *xev_win;
|
||||
Window *xev_root;
|
||||
int xev_type;
|
||||
void (*xev_cb)(struct xevent *, XEvent *);
|
||||
void *xev_arg;
|
||||
struct screen_ctx {
|
||||
TAILQ_ENTRY(screen_ctx) entry;
|
||||
u_int which;
|
||||
Window rootwin;
|
||||
Window menuwin;
|
||||
struct color color[CWM_COLOR_MAX];
|
||||
GC gc;
|
||||
int altpersist;
|
||||
int xmax;
|
||||
int ymax;
|
||||
struct gap gap;
|
||||
struct cycle_entry_q mruq;
|
||||
XftColor xftcolor;
|
||||
XftDraw *xftdraw;
|
||||
XftFont *font;
|
||||
int xinerama_no;
|
||||
XineramaScreenInfo *xinerama;
|
||||
#define CALMWM_NGROUPS 9
|
||||
struct group_ctx groups[CALMWM_NGROUPS];
|
||||
struct group_ctx_q groupq;
|
||||
int group_hideall;
|
||||
int group_nonames;
|
||||
struct group_ctx *group_active;
|
||||
char **group_names;
|
||||
};
|
||||
|
||||
TAILQ_HEAD(xevent_q, xevent);
|
||||
|
||||
#define CWM_MOVE 0x01
|
||||
#define CWM_RESIZE 0x02
|
||||
#define CWM_PTRMOVE 0x04
|
||||
#define CWM_BIGMOVE 0x08
|
||||
#define CWM_UP 0x10
|
||||
#define CWM_DOWN 0x20
|
||||
#define CWM_LEFT 0x40
|
||||
#define CWM_RIGHT 0x80
|
||||
|
||||
/*
|
||||
* Match a window.
|
||||
*/
|
||||
#define CONF_MAX_WINTITLE 256
|
||||
struct winmatch {
|
||||
TAILQ_ENTRY(winmatch) entry;
|
||||
char title[CONF_MAX_WINTITLE];
|
||||
};
|
||||
|
||||
TAILQ_HEAD(winmatch_q, winmatch);
|
||||
|
||||
/* for cwm_exec */
|
||||
#define CWM_EXEC_PROGRAM 0x1
|
||||
#define CWM_EXEC_WM 0x2
|
||||
/* for alt-tab */
|
||||
#define CWM_CYCLE 0x0
|
||||
#define CWM_RCYCLE 0x1
|
||||
/* for group cycle */
|
||||
#define CWM_CYCLEGROUP 0x0
|
||||
#define CWM_RCYCLEGROUP 0x1
|
||||
|
||||
#define KBFLAG_NEEDCLIENT 0x01
|
||||
|
||||
#define KBTOGROUP(X) ((X) - 1)
|
||||
TAILQ_HEAD(screen_ctx_q, screen_ctx);
|
||||
|
||||
struct keybinding {
|
||||
TAILQ_ENTRY(keybinding) entry;
|
||||
void (*callback)(struct client_ctx *, union arg *);
|
||||
union arg argument;
|
||||
int modmask;
|
||||
int keysym;
|
||||
int keycode;
|
||||
#define KBFLAG_NEEDCLIENT 0x0001
|
||||
int flags;
|
||||
void (*callback)(struct client_ctx *, void *);
|
||||
void *argument;
|
||||
TAILQ_ENTRY(keybinding) entry;
|
||||
};
|
||||
TAILQ_HEAD(keybinding_q, keybinding);
|
||||
|
||||
struct mousebinding {
|
||||
TAILQ_ENTRY(mousebinding) entry;
|
||||
void (*callback)(struct client_ctx *, void *);
|
||||
int modmask;
|
||||
int button;
|
||||
#define MOUSEBIND_CTX_ROOT 0x0001
|
||||
#define MOUSEBIND_CTX_WIN 0x0002
|
||||
int context;
|
||||
};
|
||||
TAILQ_HEAD(mousebinding_q, mousebinding);
|
||||
|
||||
struct cmd {
|
||||
TAILQ_ENTRY(cmd) entry;
|
||||
int flags;
|
||||
char image[MAXPATHLEN];
|
||||
char label[256];
|
||||
/* (argv) */
|
||||
#define CMD_MAXLABELLEN 256
|
||||
char label[CMD_MAXLABELLEN];
|
||||
};
|
||||
|
||||
struct mousebinding {
|
||||
int modmask;
|
||||
int button;
|
||||
int context;
|
||||
void (*callback)(struct client_ctx *, void *);
|
||||
TAILQ_ENTRY(mousebinding) entry;
|
||||
};
|
||||
|
||||
#define MOUSEBIND_CTX_ROOT 1
|
||||
#define MOUSEBIND_CTX_WIN 2
|
||||
|
||||
TAILQ_HEAD(keybinding_q, keybinding);
|
||||
TAILQ_HEAD(cmd_q, cmd);
|
||||
TAILQ_HEAD(mousebinding_q, mousebinding);
|
||||
|
||||
/* Global configuration */
|
||||
struct menu {
|
||||
TAILQ_ENTRY(menu) entry;
|
||||
TAILQ_ENTRY(menu) resultentry;
|
||||
#define MENU_MAXENTRY 50
|
||||
char text[MENU_MAXENTRY + 1];
|
||||
char print[MENU_MAXENTRY + 1];
|
||||
void *ctx;
|
||||
short dummy;
|
||||
short abort;
|
||||
};
|
||||
TAILQ_HEAD(menu_q, menu);
|
||||
|
||||
struct conf {
|
||||
struct keybinding_q keybindingq;
|
||||
struct autogroupwin_q autogroupq;
|
||||
@ -254,264 +285,247 @@ struct conf {
|
||||
char conf_path[MAXPATHLEN];
|
||||
struct cmd_q cmdq;
|
||||
struct mousebinding_q mousebindingq;
|
||||
|
||||
#define CONF_STICKY_GROUPS 0x0001
|
||||
#define CONF_STICKY_GROUPS 0x0001
|
||||
int flags;
|
||||
|
||||
#define CONF_BWIDTH 1
|
||||
int bwidth;
|
||||
#define CONF_MAMOUNT 1
|
||||
int mamount;
|
||||
#define CONF_SNAPDIST 0
|
||||
int snapdist;
|
||||
struct gap gap;
|
||||
struct color color[CWM_COLOR_MAX];
|
||||
char termpath[MAXPATHLEN];
|
||||
char lockpath[MAXPATHLEN];
|
||||
|
||||
#define DEFAULTFONTNAME "sans-serif:pixelsize=14:bold"
|
||||
char *DefaultFontName;
|
||||
XftFont *DefaultFont;
|
||||
u_int FontHeight;
|
||||
int gap_top, gap_bottom, gap_left, gap_right;
|
||||
};
|
||||
|
||||
/* Menu stuff */
|
||||
|
||||
#define MENU_MAXENTRY 50
|
||||
|
||||
struct menu {
|
||||
TAILQ_ENTRY(menu) entry;
|
||||
TAILQ_ENTRY(menu) resultentry;
|
||||
|
||||
char text[MENU_MAXENTRY + 1];
|
||||
char print[MENU_MAXENTRY + 1];
|
||||
void *ctx;
|
||||
short dummy;
|
||||
};
|
||||
|
||||
TAILQ_HEAD(menu_q, menu);
|
||||
|
||||
enum ctltype {
|
||||
CTL_NONE = -1,
|
||||
CTL_ERASEONE = 0, CTL_WIPE, CTL_UP, CTL_DOWN, CTL_RETURN,
|
||||
CTL_ABORT, CTL_ALL
|
||||
#define CONF_FONT "sans-serif:pixelsize=14:bold"
|
||||
char *font;
|
||||
};
|
||||
|
||||
/* MWM hints */
|
||||
|
||||
struct mwm_hints {
|
||||
u_long flags;
|
||||
u_long functions;
|
||||
u_long decorations;
|
||||
};
|
||||
|
||||
#define MWM_NUMHINTS 3
|
||||
|
||||
#define MWM_NUMHINTS 3
|
||||
#define PROP_MWM_HINTS_ELEMENTS 3
|
||||
#define MWM_HINTS_DECORATIONS (1 << 1)
|
||||
#define MWM_DECOR_ALL (1 << 0)
|
||||
#define MWM_DECOR_BORDER (1 << 1)
|
||||
#define MWM_HINTS_DECORATIONS (1<<1)
|
||||
#define MWM_DECOR_ALL (1<<0)
|
||||
#define MWM_DECOR_BORDER (1<<1)
|
||||
|
||||
int input_keycodetrans(KeyCode, u_int, enum ctltype *,
|
||||
char *);
|
||||
|
||||
int x_errorhandler(Display *, XErrorEvent *);
|
||||
void x_setup(void);
|
||||
char *x_screenname(int);
|
||||
void x_setupscreen(struct screen_ctx *, u_int);
|
||||
__dead void usage(void);
|
||||
|
||||
struct client_ctx *client_find(Window);
|
||||
void client_setup(void);
|
||||
struct client_ctx *client_new(Window, struct screen_ctx *, int);
|
||||
int client_delete(struct client_ctx *, int, int);
|
||||
void client_setactive(struct client_ctx *, int);
|
||||
void client_gravitate(struct client_ctx *, int);
|
||||
void client_resize(struct client_ctx *);
|
||||
void client_lower(struct client_ctx *);
|
||||
void client_raise(struct client_ctx *);
|
||||
void client_move(struct client_ctx *);
|
||||
void client_leave(struct client_ctx *);
|
||||
void client_send_delete(struct client_ctx *);
|
||||
void client_applysizehints(struct client_ctx *);
|
||||
struct client_ctx *client_current(void);
|
||||
void client_hide(struct client_ctx *);
|
||||
void client_unhide(struct client_ctx *);
|
||||
void client_nocurrent(void);
|
||||
void client_setname(struct client_ctx *);
|
||||
void client_warp(struct client_ctx *);
|
||||
void client_ptrwarp(struct client_ctx *);
|
||||
void client_ptrsave(struct client_ctx *);
|
||||
void client_cycle(struct screen_ctx *, int);
|
||||
void client_delete(struct client_ctx *);
|
||||
void client_draw_border(struct client_ctx *);
|
||||
void client_update(struct client_ctx *);
|
||||
void client_placecalc(struct client_ctx *);
|
||||
void client_maximize(struct client_ctx *);
|
||||
void client_vertmaximize(struct client_ctx *);
|
||||
u_long client_bg_pixel(struct client_ctx *);
|
||||
Pixmap client_bg_pixmap(struct client_ctx *);
|
||||
struct client_ctx *client_find(Window);
|
||||
void client_freeze(struct client_ctx *);
|
||||
void client_getsizehints(struct client_ctx *);
|
||||
void client_hide(struct client_ctx *);
|
||||
void client_horizmaximize(struct client_ctx *);
|
||||
void client_leave(struct client_ctx *);
|
||||
void client_lower(struct client_ctx *);
|
||||
void client_map(struct client_ctx *);
|
||||
void client_maximize(struct client_ctx *);
|
||||
void client_move(struct client_ctx *);
|
||||
void client_mtf(struct client_ctx *);
|
||||
struct client_ctx *client_cycle(int);
|
||||
struct client_ctx *client_mrunext(struct client_ctx *);
|
||||
struct client_ctx *client_mruprev(struct client_ctx *);
|
||||
void client_gethints(struct client_ctx *);
|
||||
void client_freehints(struct client_ctx *);
|
||||
void client_do_shape(struct client_ctx *);
|
||||
struct client_ctx *client_new(Window, struct screen_ctx *, int);
|
||||
void client_ptrsave(struct client_ctx *);
|
||||
void client_ptrwarp(struct client_ctx *);
|
||||
void client_raise(struct client_ctx *);
|
||||
void client_resize(struct client_ctx *);
|
||||
void client_send_delete(struct client_ctx *);
|
||||
void client_setactive(struct client_ctx *, int);
|
||||
void client_setname(struct client_ctx *);
|
||||
int client_snapcalc(int, int, int, int, int);
|
||||
void client_transient(struct client_ctx *);
|
||||
void client_unhide(struct client_ctx *);
|
||||
void client_vertmaximize(struct client_ctx *);
|
||||
void client_warp(struct client_ctx *);
|
||||
|
||||
struct menu *menu_filter(struct menu_q *, char *, char *, int,
|
||||
void group_alltoggle(struct screen_ctx *);
|
||||
void group_autogroup(struct client_ctx *);
|
||||
void group_client_delete(struct client_ctx *);
|
||||
void group_cycle(struct screen_ctx *, int);
|
||||
void group_hidetoggle(struct screen_ctx *, int);
|
||||
void group_init(struct screen_ctx *);
|
||||
void group_make_autogroup(struct conf *, char *, int);
|
||||
void group_menu(XButtonEvent *);
|
||||
void group_movetogroup(struct client_ctx *, int);
|
||||
void group_only(struct screen_ctx *, int);
|
||||
void group_sticky(struct client_ctx *);
|
||||
void group_sticky_toggle_enter(struct client_ctx *);
|
||||
void group_sticky_toggle_exit(struct client_ctx *);
|
||||
void group_update_names(struct screen_ctx *);
|
||||
|
||||
void search_match_client(struct menu_q *, struct menu_q *,
|
||||
char *);
|
||||
void search_match_exec(struct menu_q *, struct menu_q *,
|
||||
char *);
|
||||
void search_match_text(struct menu_q *, struct menu_q *,
|
||||
char *);
|
||||
void search_print_client(struct menu *, int);
|
||||
|
||||
XineramaScreenInfo *screen_find_xinerama(struct screen_ctx *, int, int);
|
||||
struct screen_ctx *screen_fromroot(Window);
|
||||
void screen_init_xinerama(struct screen_ctx *);
|
||||
void screen_update_geometry(struct screen_ctx *, int, int);
|
||||
void screen_updatestackingorder(struct screen_ctx *);
|
||||
|
||||
void kbfunc_client_cycle(struct client_ctx *, union arg *);
|
||||
void kbfunc_client_cyclegroup(struct client_ctx *,
|
||||
union arg *);
|
||||
void kbfunc_client_delete(struct client_ctx *, union arg *);
|
||||
void kbfunc_client_freeze(struct client_ctx *, union arg *);
|
||||
void kbfunc_client_group(struct client_ctx *, union arg *);
|
||||
void kbfunc_client_grouponly(struct client_ctx *,
|
||||
union arg *);
|
||||
void kbfunc_client_grouptoggle(struct client_ctx *,
|
||||
union arg *);
|
||||
void kbfunc_client_hide(struct client_ctx *, union arg *);
|
||||
void kbfunc_client_hmaximize(struct client_ctx *,
|
||||
union arg *);
|
||||
void kbfunc_client_label(struct client_ctx *, union arg *);
|
||||
void kbfunc_client_lower(struct client_ctx *, union arg *);
|
||||
void kbfunc_client_maximize(struct client_ctx *,
|
||||
union arg *);
|
||||
void kbfunc_client_movetogroup(struct client_ctx *,
|
||||
union arg *);
|
||||
void kbfunc_client_nogroup(struct client_ctx *,
|
||||
union arg *);
|
||||
void kbfunc_client_raise(struct client_ctx *, union arg *);
|
||||
void kbfunc_client_rcycle(struct client_ctx *, union arg *);
|
||||
void kbfunc_client_search(struct client_ctx *, union arg *);
|
||||
void kbfunc_client_vmaximize(struct client_ctx *,
|
||||
union arg *);
|
||||
void kbfunc_cmdexec(struct client_ctx *, union arg *);
|
||||
void kbfunc_exec(struct client_ctx *, union arg *);
|
||||
void kbfunc_lock(struct client_ctx *, union arg *);
|
||||
void kbfunc_menu_search(struct client_ctx *, union arg *);
|
||||
void kbfunc_moveresize(struct client_ctx *, union arg *);
|
||||
void kbfunc_quit_wm(struct client_ctx *, union arg *);
|
||||
void kbfunc_reload(struct client_ctx *, union arg *);
|
||||
void kbfunc_ssh(struct client_ctx *, union arg *);
|
||||
void kbfunc_term(struct client_ctx *, union arg *);
|
||||
|
||||
void mousefunc_menu_cmd(struct client_ctx *, void *);
|
||||
void mousefunc_menu_group(struct client_ctx *, void *);
|
||||
void mousefunc_menu_unhide(struct client_ctx *, void *);
|
||||
void mousefunc_window_grouptoggle(struct client_ctx *,
|
||||
void *);
|
||||
void mousefunc_window_hide(struct client_ctx *, void *);
|
||||
void mousefunc_window_lower(struct client_ctx *, void *);
|
||||
void mousefunc_window_move(struct client_ctx *, void *);
|
||||
void mousefunc_window_raise(struct client_ctx *, void *);
|
||||
void mousefunc_window_resize(struct client_ctx *, void *);
|
||||
|
||||
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 xev_handle_maprequest(struct xevent *, XEvent *);
|
||||
void xev_handle_unmapnotify(struct xevent *, XEvent *);
|
||||
void xev_handle_destroynotify(struct xevent *, XEvent *);
|
||||
void xev_handle_configurerequest(struct xevent *, XEvent *);
|
||||
void xev_handle_propertynotify(struct xevent *, XEvent *);
|
||||
void xev_handle_enternotify(struct xevent *, XEvent *);
|
||||
void xev_handle_leavenotify(struct xevent *, XEvent *);
|
||||
void xev_handle_buttonpress(struct xevent *, XEvent *);
|
||||
void xev_handle_buttonrelease(struct xevent *, XEvent *);
|
||||
void xev_handle_keypress(struct xevent *, XEvent *);
|
||||
void xev_handle_keyrelease(struct xevent *, XEvent *);
|
||||
void xev_handle_expose(struct xevent *, XEvent *);
|
||||
void xev_handle_clientmessage(struct xevent *, XEvent *);
|
||||
void xev_handle_shape(struct xevent *, XEvent *);
|
||||
void xev_handle_mapping(struct xevent *, XEvent *);
|
||||
int parse_config(const char *, struct conf *);
|
||||
|
||||
#define XEV_QUICK(a, b, c, d, e) do { \
|
||||
xev_register(xev_new(a, b, c, d, e)); \
|
||||
} while (0)
|
||||
|
||||
/* XXX should be xu_ */
|
||||
void xev_reconfig(struct client_ctx *);
|
||||
|
||||
void xev_init(void);
|
||||
struct xevent *xev_new(Window *, Window *, int,
|
||||
void (*)(struct xevent *, XEvent *), void *);
|
||||
void xev_register(struct xevent *);
|
||||
void xev_loop(void);
|
||||
|
||||
int xu_ptr_grab(Window, int, Cursor);
|
||||
void xu_btn_grab(Window, int, u_int);
|
||||
int xu_ptr_regrab(int, Cursor);
|
||||
void xu_btn_ungrab(Window, int, u_int);
|
||||
void xu_ptr_ungrab(void);
|
||||
void xu_ptr_setpos(Window, int, int);
|
||||
void xu_ptr_getpos(Window, int *, int *);
|
||||
void xu_key_grab(Window, int, int);
|
||||
void xu_key_ungrab(Window, int, int);
|
||||
void xu_sendmsg(struct client_ctx *, Atom, long);
|
||||
int xu_getprop(struct client_ctx *, Atom, Atom, long,
|
||||
u_char **);
|
||||
char *xu_getstrprop(struct client_ctx *, Atom atm);
|
||||
void xu_setstate(struct client_ctx *, int);
|
||||
int xu_getstate(struct client_ctx *, int *);
|
||||
|
||||
int u_spawn(char *);
|
||||
void u_exec(char *);
|
||||
|
||||
void grab_sweep(struct client_ctx *);
|
||||
void grab_drag(struct client_ctx *);
|
||||
|
||||
void xfree(void *);
|
||||
void *xmalloc(size_t);
|
||||
void *xcalloc(size_t, size_t);
|
||||
char *xstrdup(const char *);
|
||||
|
||||
#define XMALLOC(p, t) ((p) = (t *)xmalloc(sizeof * (p)))
|
||||
#define XCALLOC(p, t) ((p) = (t *)xcalloc(1, sizeof * (p)))
|
||||
|
||||
struct screen_ctx *screen_fromroot(Window);
|
||||
struct screen_ctx *screen_current(void);
|
||||
void screen_updatestackingorder(void);
|
||||
|
||||
void conf_setup(struct conf *, const char *);
|
||||
void conf_client(struct client_ctx *);
|
||||
void conf_grab(struct conf *, struct keybinding *);
|
||||
void conf_ungrab(struct conf *, struct keybinding *);
|
||||
void conf_bindname(struct conf *, char *, char *);
|
||||
void conf_unbind(struct conf *, struct keybinding *);
|
||||
void conf_mousebind(struct conf *, char *, char *);
|
||||
void conf_mouseunbind(struct conf *, struct mousebinding *);
|
||||
void conf_clear(struct conf *);
|
||||
void conf_client(struct client_ctx *);
|
||||
void conf_cmd_add(struct conf *, char *, char *, int);
|
||||
void conf_color(struct conf *, struct screen_ctx *);
|
||||
void conf_font(struct conf *, struct screen_ctx *);
|
||||
void conf_gap(struct conf *, struct screen_ctx *);
|
||||
void conf_grab(struct conf *, struct keybinding *);
|
||||
void conf_grab_mouse(struct client_ctx *);
|
||||
void conf_init(struct conf *);
|
||||
void conf_mousebind(struct conf *, char *, char *);
|
||||
void conf_reload(struct conf *);
|
||||
void conf_font(struct conf *);
|
||||
void conf_setup(struct conf *, const char *);
|
||||
void conf_ungrab(struct conf *, struct keybinding *);
|
||||
|
||||
void kbfunc_client_lower(struct client_ctx *, void *);
|
||||
void kbfunc_client_raise(struct client_ctx *, void *);
|
||||
void kbfunc_client_search(struct client_ctx *, void *);
|
||||
void kbfunc_client_hide(struct client_ctx *, void *);
|
||||
void kbfunc_client_cycle(struct client_ctx *, void *);
|
||||
void kbfunc_client_rcycle(struct client_ctx *, void *);
|
||||
void kbfunc_cmdexec(struct client_ctx *, void *);
|
||||
void kbfunc_client_label(struct client_ctx *, void *);
|
||||
void kbfunc_client_delete(struct client_ctx *, void *);
|
||||
void kbfunc_client_group(struct client_ctx *, void *);
|
||||
void kbfunc_client_cyclegroup(struct client_ctx *, void *);
|
||||
void kbfunc_client_nogroup(struct client_ctx *, void *);
|
||||
void kbfunc_client_grouptoggle(struct client_ctx *, void *);
|
||||
void kbfunc_client_maximize(struct client_ctx *, void *);
|
||||
void kbfunc_client_vmaximize(struct client_ctx *, void *);
|
||||
void kbfunc_reload(struct client_ctx *, void *);
|
||||
void kbfunc_quit_wm(struct client_ctx *, void *);
|
||||
void kbfunc_moveresize(struct client_ctx *, void *);
|
||||
void kbfunc_menu_search(struct client_ctx *, void *);
|
||||
void kbfunc_exec(struct client_ctx *, void *);
|
||||
void kbfunc_ssh(struct client_ctx *, void *);
|
||||
void kbfunc_term(struct client_ctx *, void *);
|
||||
void kbfunc_lock(struct client_ctx *, void *);
|
||||
|
||||
void mousefunc_window_resize(struct client_ctx *, void *);
|
||||
void mousefunc_window_move(struct client_ctx *, void *);
|
||||
void mousefunc_window_grouptoggle(struct client_ctx *,
|
||||
void *);
|
||||
void mousefunc_window_lower(struct client_ctx *, void *);
|
||||
void mousefunc_window_hide(struct client_ctx *, void *);
|
||||
void mousefunc_menu_group(struct client_ctx *, void *);
|
||||
void mousefunc_menu_unhide(struct client_ctx *, void *);
|
||||
void mousefunc_menu_cmd(struct client_ctx *, void *);
|
||||
|
||||
void search_match_client(struct menu_q *, struct menu_q *,
|
||||
char *);
|
||||
void search_print_client(struct menu *, int);
|
||||
void search_match_text(struct menu_q *, struct menu_q *,
|
||||
char *);
|
||||
void search_match_exec(struct menu_q *, struct menu_q *,
|
||||
char *);
|
||||
|
||||
void group_init(void);
|
||||
void group_hidetoggle(int);
|
||||
void group_cycle(int);
|
||||
void group_sticky(struct client_ctx *);
|
||||
void group_client_delete(struct client_ctx *);
|
||||
void group_menu(XButtonEvent *);
|
||||
void group_alltoggle(void);
|
||||
void group_sticky_toggle_enter(struct client_ctx *);
|
||||
void group_sticky_toggle_exit(struct client_ctx *);
|
||||
void group_autogroup(struct client_ctx *);
|
||||
|
||||
void font_init(struct screen_ctx *);
|
||||
int font_width(const char *, int);
|
||||
int font_ascent(struct screen_ctx *);
|
||||
int font_descent(struct screen_ctx *);
|
||||
void font_draw(struct screen_ctx *, const char *, int,
|
||||
Drawable, int, int);
|
||||
u_int font_height(struct screen_ctx *);
|
||||
void font_init(struct screen_ctx *, const char *);
|
||||
int font_width(struct screen_ctx *, const char *, int);
|
||||
XftFont *font_make(struct screen_ctx *, const char *);
|
||||
|
||||
#define font_ascent() Conf.DefaultFont->ascent
|
||||
#define font_descent() Conf.DefaultFont->descent
|
||||
#define font_height() Conf.FontHeight
|
||||
void xev_loop(void);
|
||||
|
||||
#define CCTOSC(cc) (cc->sc)
|
||||
void xu_btn_grab(Window, int, u_int);
|
||||
void xu_btn_ungrab(Window, int, u_int);
|
||||
void xu_configure(struct client_ctx *);
|
||||
void xu_freecolor(struct screen_ctx *, unsigned long);
|
||||
void xu_getatoms(void);
|
||||
unsigned long xu_getcolor(struct screen_ctx *, char *);
|
||||
int xu_getprop(Window, Atom, Atom, long, u_char **);
|
||||
int xu_getstate(struct client_ctx *, int *);
|
||||
int xu_getstrprop(Window, Atom, char **);
|
||||
void xu_key_grab(Window, int, int);
|
||||
void xu_key_ungrab(Window, int, int);
|
||||
void xu_ptr_getpos(Window, int *, int *);
|
||||
int xu_ptr_grab(Window, int, Cursor);
|
||||
int xu_ptr_regrab(int, Cursor);
|
||||
void xu_ptr_setpos(Window, int, int);
|
||||
void xu_ptr_ungrab(void);
|
||||
void xu_sendmsg(Window, Atom, long);
|
||||
void xu_setstate(struct client_ctx *, int);
|
||||
void xu_setwmname(struct screen_ctx *);
|
||||
|
||||
void u_exec(char *);
|
||||
void u_spawn(char *);
|
||||
|
||||
void *xcalloc(size_t, size_t);
|
||||
void xfree(void *);
|
||||
void *xmalloc(size_t);
|
||||
char *xstrdup(const char *);
|
||||
|
||||
/* Externs */
|
||||
|
||||
extern Display *X_Dpy;
|
||||
|
||||
extern Cursor Cursor_move;
|
||||
extern Cursor Cursor_resize;
|
||||
extern Cursor Cursor_select;
|
||||
extern Cursor Cursor_default;
|
||||
extern Cursor Cursor_move;
|
||||
extern Cursor Cursor_normal;
|
||||
extern Cursor Cursor_question;
|
||||
extern Cursor Cursor_resize;
|
||||
|
||||
extern struct screen_ctx_q Screenq;
|
||||
extern struct screen_ctx *curscreen;
|
||||
extern u_int Nscreens;
|
||||
|
||||
extern struct client_ctx_q Clientq;
|
||||
|
||||
extern int Doshape, Shape_ev;
|
||||
extern struct conf Conf;
|
||||
|
||||
extern int HasXinerama, HasRandr, Randr_ev;
|
||||
|
||||
#define WM_STATE cwm_atoms[0]
|
||||
#define WM_DELETE_WINDOW cwm_atoms[1]
|
||||
#define WM_TAKE_FOCUS cwm_atoms[2]
|
||||
#define WM_PROTOCOLS cwm_atoms[3]
|
||||
#define _MOTIF_WM_HINTS cwm_atoms[4]
|
||||
#define UTF8_STRING cwm_atoms[5]
|
||||
/*
|
||||
* please make all hints below this point netwm hints, starting with
|
||||
* _NET_SUPPORTED. If you change other hints make sure you update
|
||||
* CWM_NETWM_START
|
||||
*/
|
||||
#define _NET_SUPPORTED cwm_atoms[6]
|
||||
#define _NET_SUPPORTING_WM_CHECK cwm_atoms[7]
|
||||
#define _NET_WM_NAME cwm_atoms[8]
|
||||
#define _NET_ACTIVE_WINDOW cwm_atoms[9]
|
||||
#define _NET_CLIENT_LIST cwm_atoms[10]
|
||||
#define _NET_NUMBER_OF_DESKTOPS cwm_atoms[11]
|
||||
#define _NET_CURRENT_DESKTOP cwm_atoms[12]
|
||||
#define _NET_DESKTOP_VIEWPORT cwm_atoms[13]
|
||||
#define _NET_DESKTOP_GEOMETRY cwm_atoms[14]
|
||||
#define _NET_VIRTUAL_ROOTS cwm_atoms[15]
|
||||
#define _NET_SHOWING_DESKTOP cwm_atoms[16]
|
||||
#define _NET_DESKTOP_NAMES cwm_atoms[17]
|
||||
#define _NET_WM_DESKTOP cwm_atoms[18]
|
||||
#define _NET_WORKAREA cwm_atoms[19]
|
||||
#define CWM_NO_ATOMS 20
|
||||
#define CWM_NETWM_START 6
|
||||
|
||||
extern Atom cwm_atoms[CWM_NO_ATOMS];
|
||||
|
||||
#endif /* _CALMWM_H_ */
|
||||
|
583
conf.c
583
conf.c
@ -15,20 +15,24 @@
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* $Id$
|
||||
* $OpenBSD$
|
||||
*/
|
||||
|
||||
#include "headers.h"
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "calmwm.h"
|
||||
|
||||
#ifndef timespeccmp
|
||||
#define timespeccmp(tsp, usp, cmp) \
|
||||
(((tsp)->tv_sec == (usp)->tv_sec) ? \
|
||||
((tsp)->tv_nsec cmp (usp)->tv_nsec) : \
|
||||
((tsp)->tv_sec cmp (usp)->tv_sec))
|
||||
#endif
|
||||
|
||||
extern struct screen_ctx *Curscreen;
|
||||
static void conf_mouseunbind(struct conf *, struct mousebinding *);
|
||||
static void conf_unbind(struct conf *, struct keybinding *);
|
||||
|
||||
/* Add an command menu entry to the end of the menu */
|
||||
void
|
||||
@ -37,45 +41,155 @@ conf_cmd_add(struct conf *c, char *image, char *label, int flags)
|
||||
/* "term" and "lock" have special meanings. */
|
||||
|
||||
if (strcmp(label, "term") == 0)
|
||||
strlcpy(c->termpath, image, sizeof(c->termpath));
|
||||
(void)strlcpy(c->termpath, image, sizeof(c->termpath));
|
||||
else if (strcmp(label, "lock") == 0)
|
||||
strlcpy(c->lockpath, image, sizeof(c->lockpath));
|
||||
(void)strlcpy(c->lockpath, image, sizeof(c->lockpath));
|
||||
else {
|
||||
struct cmd *cmd;
|
||||
XMALLOC(cmd, struct cmd);
|
||||
struct cmd *cmd = xmalloc(sizeof(*cmd));
|
||||
cmd->flags = flags;
|
||||
strlcpy(cmd->image, image, sizeof(cmd->image));
|
||||
strlcpy(cmd->label, label, sizeof(cmd->label));
|
||||
(void)strlcpy(cmd->image, image, sizeof(cmd->image));
|
||||
(void)strlcpy(cmd->label, label, sizeof(cmd->label));
|
||||
TAILQ_INSERT_TAIL(&c->cmdq, cmd, entry);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
conf_font(struct conf *c)
|
||||
conf_gap(struct conf *c, struct screen_ctx *sc)
|
||||
{
|
||||
struct screen_ctx *sc;
|
||||
sc->gap = c->gap;
|
||||
}
|
||||
|
||||
sc = screen_current();
|
||||
void
|
||||
conf_font(struct conf *c, struct screen_ctx *sc)
|
||||
{
|
||||
font_init(sc, c->color[CWM_COLOR_FONT].name);
|
||||
sc->font = font_make(sc, c->font);
|
||||
}
|
||||
|
||||
c->DefaultFont = font_make(sc, Conf.DefaultFontName);
|
||||
c->FontHeight = font_ascent() + font_descent() + 1;
|
||||
static struct color color_binds[] = {
|
||||
{ "#CCCCCC", 0 }, /* CWM_COLOR_BORDER_ACTIVE */
|
||||
{ "#666666", 0 }, /* CWM_COLOR_BORDER_INACTIVE */
|
||||
{ "blue", 0 }, /* CWM_COLOR_BORDER_GROUP */
|
||||
{ "red", 0 }, /* CWM_COLOR_BORDER_UNGROUP */
|
||||
{ "black", 0 }, /* CWM_COLOR_FG_MENU */
|
||||
{ "white", 0 }, /* CWM_COLOR_BG_MENU */
|
||||
{ "black", 0 }, /* CWM_COLOR_FONT */
|
||||
};
|
||||
|
||||
void
|
||||
conf_color(struct conf *c, struct screen_ctx *sc)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < CWM_COLOR_MAX; i++) {
|
||||
xu_freecolor(sc, sc->color[i].pixel);
|
||||
sc->color[i].pixel = xu_getcolor(sc, c->color[i].name);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
conf_reload(struct conf *c)
|
||||
{
|
||||
struct screen_ctx *sc;
|
||||
struct client_ctx *cc;
|
||||
|
||||
if (parse_config(c->conf_path, c) == -1) {
|
||||
warnx("config file %s has errors, not reloading", c->conf_path);
|
||||
return;
|
||||
}
|
||||
|
||||
conf_font(c);
|
||||
TAILQ_FOREACH(sc, &Screenq, entry) {
|
||||
conf_gap(c, sc);
|
||||
conf_color(c, sc);
|
||||
conf_font(c, sc);
|
||||
menu_init(sc);
|
||||
}
|
||||
TAILQ_FOREACH(cc, &Clientq, entry)
|
||||
client_draw_border(cc);
|
||||
}
|
||||
|
||||
static struct {
|
||||
char *key;
|
||||
char *func;
|
||||
} kb_binds[] = {
|
||||
{ "CM-Return", "terminal" },
|
||||
{ "CM-Delete", "lock" },
|
||||
{ "M-question", "exec" },
|
||||
{ "CM-w", "exec_wm" },
|
||||
{ "M-period", "ssh" },
|
||||
{ "M-Return", "hide" },
|
||||
{ "M-Down", "lower" },
|
||||
{ "M-Up", "raise" },
|
||||
{ "M-slash", "search" },
|
||||
{ "C-slash", "menusearch" },
|
||||
{ "M-Tab", "cycle" },
|
||||
{ "MS-Tab", "rcycle" },
|
||||
{ "CM-n", "label" },
|
||||
{ "CM-x", "delete" },
|
||||
{ "CM-0", "nogroup" },
|
||||
{ "CM-1", "group1" },
|
||||
{ "CM-2", "group2" },
|
||||
{ "CM-3", "group3" },
|
||||
{ "CM-4", "group4" },
|
||||
{ "CM-5", "group5" },
|
||||
{ "CM-6", "group6" },
|
||||
{ "CM-7", "group7" },
|
||||
{ "CM-8", "group8" },
|
||||
{ "CM-9", "group9" },
|
||||
{ "M-Right", "cyclegroup" },
|
||||
{ "M-Left", "rcyclegroup" },
|
||||
{ "CM-g", "grouptoggle" },
|
||||
{ "CM-f", "maximize" },
|
||||
{ "CM-equal", "vmaximize" },
|
||||
{ "CMS-equal", "hmaximize" },
|
||||
{ "CMS-f", "freeze" },
|
||||
{ "CMS-r", "reload" },
|
||||
{ "CMS-q", "quit" },
|
||||
{ "M-h", "moveleft" },
|
||||
{ "M-j", "movedown" },
|
||||
{ "M-k", "moveup" },
|
||||
{ "M-l", "moveright" },
|
||||
{ "M-H", "bigmoveleft" },
|
||||
{ "M-J", "bigmovedown" },
|
||||
{ "M-K", "bigmoveup" },
|
||||
{ "M-L", "bigmoveright" },
|
||||
{ "CM-h", "resizeleft" },
|
||||
{ "CM-j", "resizedown" },
|
||||
{ "CM-k", "resizeup" },
|
||||
{ "CM-l", "resizeright" },
|
||||
{ "CM-H", "bigresizeleft" },
|
||||
{ "CM-J", "bigresizedown" },
|
||||
{ "CM-K", "bigresizeup" },
|
||||
{ "CM-L", "bigresizeright" },
|
||||
{ "C-Left", "ptrmoveleft" },
|
||||
{ "C-Down", "ptrmovedown" },
|
||||
{ "C-Up", "ptrmoveup" },
|
||||
{ "C-Right", "ptrmoveright" },
|
||||
{ "CS-Left", "bigptrmoveleft" },
|
||||
{ "CS-Down", "bigptrmovedown" },
|
||||
{ "CS-Up", "bigptrmoveup" },
|
||||
{ "CS-Right", "bigptrmoveright" },
|
||||
},
|
||||
m_binds[] = {
|
||||
{ "1", "menu_unhide" },
|
||||
{ "2", "menu_group" },
|
||||
{ "3", "menu_cmd" },
|
||||
{ "M-1", "window_move" },
|
||||
{ "CM-1", "window_grouptoggle" },
|
||||
{ "M-2", "window_resize" },
|
||||
{ "M-3", "window_lower" },
|
||||
{ "CMS-3", "window_hide" },
|
||||
};
|
||||
|
||||
void
|
||||
conf_init(struct conf *c)
|
||||
{
|
||||
int i;
|
||||
|
||||
c->flags = 0;
|
||||
c->bwidth = CONF_BWIDTH;
|
||||
c->mamount = CONF_MAMOUNT;
|
||||
c->snapdist = CONF_SNAPDIST;
|
||||
|
||||
TAILQ_INIT(&c->ignoreq);
|
||||
TAILQ_INIT(&c->cmdq);
|
||||
@ -83,103 +197,96 @@ conf_init(struct conf *c)
|
||||
TAILQ_INIT(&c->autogroupq);
|
||||
TAILQ_INIT(&c->mousebindingq);
|
||||
|
||||
conf_bindname(c, "CM-Return", "terminal");
|
||||
conf_bindname(c, "CM-Delete", "lock");
|
||||
conf_bindname(c, "M-question", "exec");
|
||||
conf_bindname(c, "CM-w", "exec_wm");
|
||||
conf_bindname(c, "M-period", "ssh");
|
||||
conf_bindname(c, "M-Return", "hide");
|
||||
conf_bindname(c, "M-Down", "lower");
|
||||
conf_bindname(c, "M-Up", "raise");
|
||||
conf_bindname(c, "M-slash", "search");
|
||||
conf_bindname(c, "C-slash", "menusearch");
|
||||
conf_bindname(c, "M-Tab", "cycle");
|
||||
conf_bindname(c, "MS-Tab", "rcycle");
|
||||
conf_bindname(c, "CM-n", "label");
|
||||
conf_bindname(c, "CM-x", "delete");
|
||||
conf_bindname(c, "CM-0", "nogroup");
|
||||
conf_bindname(c, "CM-1", "group1");
|
||||
conf_bindname(c, "CM-2", "group2");
|
||||
conf_bindname(c, "CM-3", "group3");
|
||||
conf_bindname(c, "CM-4", "group4");
|
||||
conf_bindname(c, "CM-5", "group5");
|
||||
conf_bindname(c, "CM-6", "group6");
|
||||
conf_bindname(c, "CM-7", "group7");
|
||||
conf_bindname(c, "CM-8", "group8");
|
||||
conf_bindname(c, "CM-9", "group9");
|
||||
conf_bindname(c, "M-Right", "cyclegroup");
|
||||
conf_bindname(c, "M-Left", "rcyclegroup");
|
||||
conf_bindname(c, "CM-g", "grouptoggle");
|
||||
conf_bindname(c, "CM-f", "maximize");
|
||||
conf_bindname(c, "CM-equal", "vmaximize");
|
||||
conf_bindname(c, "CMS-r", "reload");
|
||||
conf_bindname(c, "CMS-q", "quit");
|
||||
for (i = 0; i < nitems(kb_binds); i++)
|
||||
conf_bindname(c, kb_binds[i].key, kb_binds[i].func);
|
||||
|
||||
conf_bindname(c, "M-h", "moveleft");
|
||||
conf_bindname(c, "M-j", "movedown");
|
||||
conf_bindname(c, "M-k", "moveup");
|
||||
conf_bindname(c, "M-l", "moveright");
|
||||
conf_bindname(c, "M-H", "bigmoveleft");
|
||||
conf_bindname(c, "M-J", "bigmovedown");
|
||||
conf_bindname(c, "M-K", "bigmoveup");
|
||||
conf_bindname(c, "M-L", "bigmoveright");
|
||||
for (i = 0; i < nitems(m_binds); i++)
|
||||
conf_mousebind(c, m_binds[i].key, m_binds[i].func);
|
||||
|
||||
conf_bindname(c, "CM-h", "resizeleft");
|
||||
conf_bindname(c, "CM-j", "resizedown");
|
||||
conf_bindname(c, "CM-k", "resizeup");
|
||||
conf_bindname(c, "CM-l", "resizeright");
|
||||
conf_bindname(c, "CM-H", "bigresizeleft");
|
||||
conf_bindname(c, "CM-J", "bigresizedown");
|
||||
conf_bindname(c, "CM-K", "bigresizeup");
|
||||
conf_bindname(c, "CM-L", "bigresizeright");
|
||||
|
||||
conf_bindname(c, "C-Left", "ptrmoveleft");
|
||||
conf_bindname(c, "C-Down", "ptrmovedown");
|
||||
conf_bindname(c, "C-Up", "ptrmoveup");
|
||||
conf_bindname(c, "C-Right", "ptrmoveright");
|
||||
conf_bindname(c, "CS-Left", "bigptrmoveleft");
|
||||
conf_bindname(c, "CS-Down", "bigptrmovedown");
|
||||
conf_bindname(c, "CS-Up", "bigptrmoveup");
|
||||
conf_bindname(c, "CS-Right", "bigptrmoveright");
|
||||
|
||||
conf_mousebind(c, "1", "menu_unhide");
|
||||
conf_mousebind(c, "2", "menu_group");
|
||||
conf_mousebind(c, "3", "menu_cmd");
|
||||
conf_mousebind(c, "M-1", "window_move");
|
||||
conf_mousebind(c, "CM-1", "window_grouptoggle");
|
||||
conf_mousebind(c, "M-2", "window_resize");
|
||||
conf_mousebind(c, "M-3", "window_lower");
|
||||
conf_mousebind(c, "CMS-3", "window_hide");
|
||||
for (i = 0; i < nitems(color_binds); i++)
|
||||
c->color[i].name = xstrdup(color_binds[i].name);
|
||||
|
||||
/* Default term/lock */
|
||||
strlcpy(c->termpath, "xterm", sizeof(c->termpath));
|
||||
strlcpy(c->lockpath, "xlock", sizeof(c->lockpath));
|
||||
(void)strlcpy(c->termpath, "xterm", sizeof(c->termpath));
|
||||
(void)strlcpy(c->lockpath, "xlock", sizeof(c->lockpath));
|
||||
|
||||
c->DefaultFontName = xstrdup(DEFAULTFONTNAME);
|
||||
c->font = xstrdup(CONF_FONT);
|
||||
}
|
||||
|
||||
void
|
||||
conf_clear(struct conf *c)
|
||||
{
|
||||
struct autogroupwin *ag;
|
||||
struct keybinding *kb;
|
||||
struct winmatch *wm;
|
||||
struct cmd *cmd;
|
||||
struct mousebinding *mb;
|
||||
int i;
|
||||
|
||||
while ((cmd = TAILQ_FIRST(&c->cmdq)) != NULL) {
|
||||
TAILQ_REMOVE(&c->cmdq, cmd, entry);
|
||||
xfree(cmd);
|
||||
}
|
||||
|
||||
while ((kb = TAILQ_FIRST(&c->keybindingq)) != NULL) {
|
||||
TAILQ_REMOVE(&c->keybindingq, kb, entry);
|
||||
xfree(kb);
|
||||
}
|
||||
|
||||
while ((ag = TAILQ_FIRST(&c->autogroupq)) != NULL) {
|
||||
TAILQ_REMOVE(&c->autogroupq, ag, entry);
|
||||
xfree(ag->class);
|
||||
if (ag->name)
|
||||
xfree(ag->name);
|
||||
xfree(ag);
|
||||
}
|
||||
|
||||
while ((wm = TAILQ_FIRST(&c->ignoreq)) != NULL) {
|
||||
TAILQ_REMOVE(&c->ignoreq, wm, entry);
|
||||
xfree(wm);
|
||||
}
|
||||
|
||||
while ((mb = TAILQ_FIRST(&c->mousebindingq)) != NULL) {
|
||||
TAILQ_REMOVE(&c->mousebindingq, mb, entry);
|
||||
xfree(mb);
|
||||
}
|
||||
|
||||
for (i = 0; i < CWM_COLOR_MAX; i++)
|
||||
xfree(c->color[i].name);
|
||||
|
||||
xfree(c->font);
|
||||
}
|
||||
|
||||
void
|
||||
conf_setup(struct conf *c, const char *conf_file)
|
||||
{
|
||||
char *home;
|
||||
struct stat sb;
|
||||
|
||||
if (conf_file == NULL) {
|
||||
char *home = getenv("HOME");
|
||||
|
||||
if (home == NULL)
|
||||
errx(1, "No HOME directory.");
|
||||
|
||||
snprintf(c->conf_path, sizeof(c->conf_path), "%s/%s", home,
|
||||
CONFFILE);
|
||||
} else
|
||||
if (stat(conf_file, &sb) == -1 || !(sb.st_mode & S_IFREG))
|
||||
errx(1, "%s: %s", conf_file, strerror(errno));
|
||||
else
|
||||
strlcpy(c->conf_path, conf_file, sizeof(c->conf_path));
|
||||
int parse = 0;
|
||||
|
||||
conf_init(c);
|
||||
|
||||
(void)parse_config(c->conf_path, c);
|
||||
if (conf_file == NULL) {
|
||||
if ((home = getenv("HOME")) == NULL)
|
||||
errx(1, "No HOME directory.");
|
||||
|
||||
(void)snprintf(c->conf_path, sizeof(c->conf_path), "%s/%s",
|
||||
home, CONFFILE);
|
||||
|
||||
if (stat(c->conf_path, &sb) == 0 && (sb.st_mode & S_IFREG))
|
||||
parse = 1;
|
||||
} else {
|
||||
if (stat(conf_file, &sb) == -1 || !(sb.st_mode & S_IFREG))
|
||||
errx(1, "%s: %s", conf_file, strerror(errno));
|
||||
else {
|
||||
(void)strlcpy(c->conf_path, conf_file,
|
||||
sizeof(c->conf_path));
|
||||
parse = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (parse && (parse_config(c->conf_path, c) == -1))
|
||||
warnx("config file %s has errors, not loading", c->conf_path);
|
||||
}
|
||||
|
||||
void
|
||||
@ -189,105 +296,130 @@ conf_client(struct client_ctx *cc)
|
||||
char *wname = cc->name;
|
||||
int ignore = 0;
|
||||
|
||||
/* Can wname be NULL? */
|
||||
if (wname != NULL) {
|
||||
TAILQ_FOREACH(wm, &Conf.ignoreq, entry) {
|
||||
if (strncasecmp(wm->title, wname, strlen(wm->title))
|
||||
== 0) {
|
||||
ignore = 1;
|
||||
break;
|
||||
}
|
||||
TAILQ_FOREACH(wm, &Conf.ignoreq, entry) {
|
||||
if (strncasecmp(wm->title, wname, strlen(wm->title)) == 0) {
|
||||
ignore = 1;
|
||||
break;
|
||||
}
|
||||
} else
|
||||
ignore = 1;
|
||||
}
|
||||
|
||||
cc->bwidth = ignore ? 0 : 3;
|
||||
cc->bwidth = ignore ? 0 : Conf.bwidth;
|
||||
cc->flags |= ignore ? CLIENT_IGNORE : 0;
|
||||
}
|
||||
|
||||
struct {
|
||||
char *tag;
|
||||
void (*handler)(struct client_ctx *, void *);
|
||||
int flags;
|
||||
void *argument;
|
||||
static struct {
|
||||
char *tag;
|
||||
void (*handler)(struct client_ctx *, union arg *);
|
||||
int flags;
|
||||
union arg argument;
|
||||
} name_to_kbfunc[] = {
|
||||
{ "lower", kbfunc_client_lower, KBFLAG_NEEDCLIENT, 0 },
|
||||
{ "raise", kbfunc_client_raise, KBFLAG_NEEDCLIENT, 0 },
|
||||
{ "search", kbfunc_client_search, 0, 0 },
|
||||
{ "menusearch", kbfunc_menu_search, 0, 0 },
|
||||
{ "hide", kbfunc_client_hide, KBFLAG_NEEDCLIENT, 0 },
|
||||
{ "cycle", kbfunc_client_cycle, 0, (void *)CWM_CYCLE },
|
||||
{ "rcycle", kbfunc_client_cycle, 0, (void *)CWM_RCYCLE },
|
||||
{ "label", kbfunc_client_label, KBFLAG_NEEDCLIENT, 0 },
|
||||
{ "delete", kbfunc_client_delete, KBFLAG_NEEDCLIENT, 0 },
|
||||
{ "group1", kbfunc_client_group, 0, (void *)1 },
|
||||
{ "group2", kbfunc_client_group, 0, (void *)2 },
|
||||
{ "group3", kbfunc_client_group, 0, (void *)3 },
|
||||
{ "group4", kbfunc_client_group, 0, (void *)4 },
|
||||
{ "group5", kbfunc_client_group, 0, (void *)5 },
|
||||
{ "group6", kbfunc_client_group, 0, (void *)6 },
|
||||
{ "group7", kbfunc_client_group, 0, (void *)7 },
|
||||
{ "group8", kbfunc_client_group, 0, (void *)8 },
|
||||
{ "group9", kbfunc_client_group, 0, (void *)9 },
|
||||
{ "nogroup", kbfunc_client_nogroup, 0, 0 },
|
||||
{ "cyclegroup", kbfunc_client_cyclegroup, 0, (void *)CWM_CYCLEGROUP },
|
||||
{ "rcyclegroup", kbfunc_client_cyclegroup, 0, (void *)CWM_RCYCLEGROUP },
|
||||
{ "grouptoggle", kbfunc_client_grouptoggle, KBFLAG_NEEDCLIENT, 0},
|
||||
{ "maximize", kbfunc_client_maximize, KBFLAG_NEEDCLIENT, 0 },
|
||||
{ "vmaximize", kbfunc_client_vmaximize, KBFLAG_NEEDCLIENT, 0 },
|
||||
{ "reload", kbfunc_reload, 0, 0 },
|
||||
{ "quit", kbfunc_quit_wm, 0, 0 },
|
||||
{ "exec", kbfunc_exec, 0, (void *)CWM_EXEC_PROGRAM },
|
||||
{ "exec_wm", kbfunc_exec, 0, (void *)CWM_EXEC_WM },
|
||||
{ "ssh", kbfunc_ssh, 0, 0 },
|
||||
{ "terminal", kbfunc_term, 0, 0 },
|
||||
{ "lock", kbfunc_lock, 0, 0 },
|
||||
{ "lower", kbfunc_client_lower, KBFLAG_NEEDCLIENT, {0} },
|
||||
{ "raise", kbfunc_client_raise, KBFLAG_NEEDCLIENT, {0} },
|
||||
{ "search", kbfunc_client_search, 0, {0} },
|
||||
{ "menusearch", kbfunc_menu_search, 0, {0} },
|
||||
{ "hide", kbfunc_client_hide, KBFLAG_NEEDCLIENT, {0} },
|
||||
{ "cycle", kbfunc_client_cycle, 0, {.i = CWM_CYCLE} },
|
||||
{ "rcycle", kbfunc_client_cycle, 0, {.i = CWM_RCYCLE} },
|
||||
{ "label", kbfunc_client_label, KBFLAG_NEEDCLIENT, {0} },
|
||||
{ "delete", kbfunc_client_delete, KBFLAG_NEEDCLIENT, {0} },
|
||||
{ "group1", kbfunc_client_group, 0, {.i = 1} },
|
||||
{ "group2", kbfunc_client_group, 0, {.i = 2} },
|
||||
{ "group3", kbfunc_client_group, 0, {.i = 3} },
|
||||
{ "group4", kbfunc_client_group, 0, {.i = 4} },
|
||||
{ "group5", kbfunc_client_group, 0, {.i = 5} },
|
||||
{ "group6", kbfunc_client_group, 0, {.i = 6} },
|
||||
{ "group7", kbfunc_client_group, 0, {.i = 7} },
|
||||
{ "group8", kbfunc_client_group, 0, {.i = 8} },
|
||||
{ "group9", kbfunc_client_group, 0, {.i = 9} },
|
||||
{ "grouponly1", kbfunc_client_grouponly, 0, {.i = 1} },
|
||||
{ "grouponly2", kbfunc_client_grouponly, 0, {.i = 2} },
|
||||
{ "grouponly3", kbfunc_client_grouponly, 0, {.i = 3} },
|
||||
{ "grouponly4", kbfunc_client_grouponly, 0, {.i = 4} },
|
||||
{ "grouponly5", kbfunc_client_grouponly, 0, {.i = 5} },
|
||||
{ "grouponly6", kbfunc_client_grouponly, 0, {.i = 6} },
|
||||
{ "grouponly7", kbfunc_client_grouponly, 0, {.i = 7} },
|
||||
{ "grouponly8", kbfunc_client_grouponly, 0, {.i = 8} },
|
||||
{ "grouponly9", kbfunc_client_grouponly, 0, {.i = 9} },
|
||||
{ "movetogroup1", kbfunc_client_movetogroup, KBFLAG_NEEDCLIENT,
|
||||
{.i = 1} },
|
||||
{ "movetogroup2", kbfunc_client_movetogroup, KBFLAG_NEEDCLIENT,
|
||||
{.i = 2} },
|
||||
{ "movetogroup3", kbfunc_client_movetogroup, KBFLAG_NEEDCLIENT,
|
||||
{.i = 3} },
|
||||
{ "movetogroup4", kbfunc_client_movetogroup, KBFLAG_NEEDCLIENT,
|
||||
{.i = 4} },
|
||||
{ "movetogroup5", kbfunc_client_movetogroup, KBFLAG_NEEDCLIENT,
|
||||
{.i = 5} },
|
||||
{ "movetogroup6", kbfunc_client_movetogroup, KBFLAG_NEEDCLIENT,
|
||||
{.i = 6} },
|
||||
{ "movetogroup7", kbfunc_client_movetogroup, KBFLAG_NEEDCLIENT,
|
||||
{.i = 7} },
|
||||
{ "movetogroup8", kbfunc_client_movetogroup, KBFLAG_NEEDCLIENT,
|
||||
{.i = 8} },
|
||||
{ "movetogroup9", kbfunc_client_movetogroup, KBFLAG_NEEDCLIENT,
|
||||
{.i = 9} },
|
||||
{ "nogroup", kbfunc_client_nogroup, 0, {0} },
|
||||
{ "cyclegroup", kbfunc_client_cyclegroup, 0, {.i = CWM_CYCLE} },
|
||||
{ "rcyclegroup", kbfunc_client_cyclegroup, 0, {.i = CWM_RCYCLE} },
|
||||
{ "cycleingroup", kbfunc_client_cycle, KBFLAG_NEEDCLIENT, {.i = CWM_CYCLE|CWM_INGROUP} },
|
||||
{ "rcycleingroup", kbfunc_client_cycle, KBFLAG_NEEDCLIENT, {.i = CWM_RCYCLE|CWM_INGROUP} },
|
||||
{ "grouptoggle", kbfunc_client_grouptoggle, KBFLAG_NEEDCLIENT, {0}},
|
||||
{ "maximize", kbfunc_client_maximize, KBFLAG_NEEDCLIENT, {0} },
|
||||
{ "vmaximize", kbfunc_client_vmaximize, KBFLAG_NEEDCLIENT, {0} },
|
||||
{ "hmaximize", kbfunc_client_hmaximize, KBFLAG_NEEDCLIENT, {0} },
|
||||
{ "freeze", kbfunc_client_freeze, KBFLAG_NEEDCLIENT, {0} },
|
||||
{ "reload", kbfunc_reload, 0, {0} },
|
||||
{ "quit", kbfunc_quit_wm, 0, {0} },
|
||||
{ "exec", kbfunc_exec, 0, {.i = CWM_EXEC_PROGRAM} },
|
||||
{ "exec_wm", kbfunc_exec, 0, {.i = CWM_EXEC_WM} },
|
||||
{ "ssh", kbfunc_ssh, 0, {0} },
|
||||
{ "terminal", kbfunc_term, 0, {0} },
|
||||
{ "lock", kbfunc_lock, 0, {0} },
|
||||
{ "moveup", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
(void *)(CWM_UP|CWM_MOVE) },
|
||||
{.i = (CWM_UP|CWM_MOVE)} },
|
||||
{ "movedown", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
(void *)(CWM_DOWN|CWM_MOVE) },
|
||||
{.i = (CWM_DOWN|CWM_MOVE)} },
|
||||
{ "moveright", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
(void *)(CWM_RIGHT|CWM_MOVE) },
|
||||
{.i = (CWM_RIGHT|CWM_MOVE)} },
|
||||
{ "moveleft", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
(void *)(CWM_LEFT|CWM_MOVE) },
|
||||
{.i = (CWM_LEFT|CWM_MOVE)} },
|
||||
{ "bigmoveup", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
(void *)(CWM_UP|CWM_MOVE|CWM_BIGMOVE) },
|
||||
{.i = (CWM_UP|CWM_MOVE|CWM_BIGMOVE)} },
|
||||
{ "bigmovedown", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
(void *)(CWM_DOWN|CWM_MOVE|CWM_BIGMOVE) },
|
||||
{.i = (CWM_DOWN|CWM_MOVE|CWM_BIGMOVE)} },
|
||||
{ "bigmoveright", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
(void *)(CWM_RIGHT|CWM_MOVE|CWM_BIGMOVE) },
|
||||
{.i = (CWM_RIGHT|CWM_MOVE|CWM_BIGMOVE)} },
|
||||
{ "bigmoveleft", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
(void *)(CWM_LEFT|CWM_MOVE|CWM_BIGMOVE) },
|
||||
{.i = (CWM_LEFT|CWM_MOVE|CWM_BIGMOVE)} },
|
||||
{ "resizeup", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
(void *)(CWM_UP|CWM_RESIZE) },
|
||||
{.i = (CWM_UP|CWM_RESIZE)} },
|
||||
{ "resizedown", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
(void *)(CWM_DOWN|CWM_RESIZE) },
|
||||
{.i = (CWM_DOWN|CWM_RESIZE)} },
|
||||
{ "resizeright", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
(void *)(CWM_RIGHT|CWM_RESIZE) },
|
||||
{.i = (CWM_RIGHT|CWM_RESIZE)} },
|
||||
{ "resizeleft", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
(void *)(CWM_LEFT|CWM_RESIZE) },
|
||||
{.i = (CWM_LEFT|CWM_RESIZE)} },
|
||||
{ "bigresizeup", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
(void *)(CWM_UP|CWM_RESIZE|CWM_BIGMOVE) },
|
||||
{.i = (CWM_UP|CWM_RESIZE|CWM_BIGMOVE)} },
|
||||
{ "bigresizedown", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
(void *)(CWM_DOWN|CWM_RESIZE|CWM_BIGMOVE) },
|
||||
{.i = (CWM_DOWN|CWM_RESIZE|CWM_BIGMOVE)} },
|
||||
{ "bigresizeright", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
(void *)(CWM_RIGHT|CWM_RESIZE|CWM_BIGMOVE) },
|
||||
{.i = (CWM_RIGHT|CWM_RESIZE|CWM_BIGMOVE)} },
|
||||
{ "bigresizeleft", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
||||
(void *)(CWM_LEFT|CWM_RESIZE|CWM_BIGMOVE) },
|
||||
{ "ptrmoveup", kbfunc_moveresize, 0, (void *)(CWM_UP|CWM_PTRMOVE) },
|
||||
{ "ptrmovedown", kbfunc_moveresize, 0, (void *)(CWM_DOWN|CWM_PTRMOVE) },
|
||||
{ "ptrmoveleft", kbfunc_moveresize, 0, (void *)(CWM_LEFT|CWM_PTRMOVE) },
|
||||
{.i = (CWM_LEFT|CWM_RESIZE|CWM_BIGMOVE)} },
|
||||
{ "ptrmoveup", kbfunc_moveresize, 0, {.i = (CWM_UP|CWM_PTRMOVE)} },
|
||||
{ "ptrmovedown", kbfunc_moveresize, 0, {.i = (CWM_DOWN|CWM_PTRMOVE)} },
|
||||
{ "ptrmoveleft", kbfunc_moveresize, 0, {.i = (CWM_LEFT|CWM_PTRMOVE)} },
|
||||
{ "ptrmoveright", kbfunc_moveresize, 0,
|
||||
(void *)(CWM_RIGHT|CWM_PTRMOVE) },
|
||||
{.i = (CWM_RIGHT|CWM_PTRMOVE)} },
|
||||
{ "bigptrmoveup", kbfunc_moveresize, 0,
|
||||
(void *)(CWM_UP|CWM_PTRMOVE|CWM_BIGMOVE) },
|
||||
{.i = (CWM_UP|CWM_PTRMOVE|CWM_BIGMOVE)} },
|
||||
{ "bigptrmovedown", kbfunc_moveresize, 0,
|
||||
(void *)(CWM_DOWN|CWM_PTRMOVE|CWM_BIGMOVE) },
|
||||
{.i = (CWM_DOWN|CWM_PTRMOVE|CWM_BIGMOVE)} },
|
||||
{ "bigptrmoveleft", kbfunc_moveresize, 0,
|
||||
(void *)(CWM_LEFT|CWM_PTRMOVE|CWM_BIGMOVE) },
|
||||
{.i = (CWM_LEFT|CWM_PTRMOVE|CWM_BIGMOVE)} },
|
||||
{ "bigptrmoveright", kbfunc_moveresize, 0,
|
||||
(void *)(CWM_RIGHT|CWM_PTRMOVE|CWM_BIGMOVE) },
|
||||
{ NULL, NULL, 0, 0},
|
||||
{.i = (CWM_RIGHT|CWM_PTRMOVE|CWM_BIGMOVE)} },
|
||||
};
|
||||
|
||||
/*
|
||||
@ -306,7 +438,6 @@ conf_grab(struct conf *c, struct keybinding *kb)
|
||||
|
||||
TAILQ_FOREACH(sc, &Screenq, entry)
|
||||
xu_key_grab(sc->rootwin, kb->modmask, kb->keysym);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@ -322,36 +453,39 @@ conf_ungrab(struct conf *c, struct keybinding *kb)
|
||||
xu_key_ungrab(sc->rootwin, kb->modmask, kb->keysym);
|
||||
}
|
||||
|
||||
static struct {
|
||||
char chr;
|
||||
int mask;
|
||||
} bind_mods[] = {
|
||||
{ 'C', ControlMask },
|
||||
{ 'M', Mod1Mask },
|
||||
{ '4', Mod4Mask },
|
||||
{ 'S', ShiftMask },
|
||||
};
|
||||
|
||||
void
|
||||
conf_bindname(struct conf *c, char *name, char *binding)
|
||||
{
|
||||
struct keybinding *current_binding;
|
||||
char *substring;
|
||||
char *substring, *tmp;
|
||||
int iter;
|
||||
|
||||
XCALLOC(current_binding, struct keybinding);
|
||||
current_binding = xcalloc(1, sizeof(*current_binding));
|
||||
|
||||
if (strchr(name, 'C') != NULL &&
|
||||
strchr(name, 'C') < strchr(name, '-'))
|
||||
current_binding->modmask |= ControlMask;
|
||||
if ((substring = strchr(name, '-')) != NULL) {
|
||||
for (iter = 0; iter < nitems(bind_mods); iter++) {
|
||||
if ((tmp = strchr(name, bind_mods[iter].chr)) !=
|
||||
NULL && tmp < substring) {
|
||||
current_binding->modmask |=
|
||||
bind_mods[iter].mask;
|
||||
}
|
||||
}
|
||||
|
||||
if (strchr(name, 'M') != NULL &&
|
||||
strchr(name, 'M') < strchr(name, '-'))
|
||||
current_binding->modmask |= Mod1Mask;
|
||||
|
||||
if (strchr(name, '4') != NULL &&
|
||||
strchr(name, '4') < strchr(name, '-'))
|
||||
current_binding->modmask |= Mod4Mask;
|
||||
|
||||
if (strchr(name, 'S') != NULL &&
|
||||
strchr(name, 'S') < strchr(name, '-'))
|
||||
current_binding->modmask |= ShiftMask;
|
||||
|
||||
substring = strchr(name, '-') + 1;
|
||||
|
||||
/* If there is no '-' in name, continue as is */
|
||||
if (strchr(name, '-') == NULL)
|
||||
/* skip past the modifiers */
|
||||
substring++;
|
||||
} else {
|
||||
substring = name;
|
||||
}
|
||||
|
||||
if (substring[0] == '[' &&
|
||||
substring[strlen(substring)-1] == ']') {
|
||||
@ -374,7 +508,7 @@ conf_bindname(struct conf *c, char *name, char *binding)
|
||||
if (strcmp("unmap", binding) == 0)
|
||||
return;
|
||||
|
||||
for (iter = 0; name_to_kbfunc[iter].tag != NULL; iter++) {
|
||||
for (iter = 0; iter < nitems(name_to_kbfunc); iter++) {
|
||||
if (strcmp(name_to_kbfunc[iter].tag, binding) != 0)
|
||||
continue;
|
||||
|
||||
@ -387,14 +521,13 @@ conf_bindname(struct conf *c, char *name, char *binding)
|
||||
}
|
||||
|
||||
current_binding->callback = kbfunc_cmdexec;
|
||||
current_binding->argument = xstrdup(binding);
|
||||
current_binding->argument.c = xstrdup(binding);
|
||||
current_binding->flags = 0;
|
||||
conf_grab(c, current_binding);
|
||||
TAILQ_INSERT_TAIL(&c->keybindingq, current_binding, entry);
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
conf_unbind(struct conf *c, struct keybinding *unbind)
|
||||
{
|
||||
struct keybinding *key = NULL, *keynxt;
|
||||
@ -416,7 +549,7 @@ conf_unbind(struct conf *c, struct keybinding *unbind)
|
||||
}
|
||||
}
|
||||
|
||||
struct {
|
||||
static struct {
|
||||
char *tag;
|
||||
void (*handler)(struct client_ctx *, void *);
|
||||
int context;
|
||||
@ -426,42 +559,35 @@ struct {
|
||||
{ "window_grouptoggle", mousefunc_window_grouptoggle,
|
||||
MOUSEBIND_CTX_WIN },
|
||||
{ "window_lower", mousefunc_window_lower, MOUSEBIND_CTX_WIN },
|
||||
{ "window_raise", mousefunc_window_raise, MOUSEBIND_CTX_WIN },
|
||||
{ "window_hide", mousefunc_window_hide, MOUSEBIND_CTX_WIN },
|
||||
{ "menu_group", mousefunc_menu_group, MOUSEBIND_CTX_ROOT },
|
||||
{ "menu_unhide", mousefunc_menu_unhide, MOUSEBIND_CTX_ROOT },
|
||||
{ "menu_cmd", mousefunc_menu_cmd, MOUSEBIND_CTX_ROOT },
|
||||
{ NULL, NULL, 0 },
|
||||
};
|
||||
|
||||
void
|
||||
conf_mousebind(struct conf *c, char *name, char *binding)
|
||||
{
|
||||
struct mousebinding *current_binding;
|
||||
char *substring;
|
||||
char *substring, *tmp;
|
||||
const char *errstr;
|
||||
int iter;
|
||||
|
||||
XCALLOC(current_binding, struct mousebinding);
|
||||
current_binding = xcalloc(1, sizeof(*current_binding));
|
||||
|
||||
if (strchr(name, 'C') != NULL &&
|
||||
strchr(name, 'C') < strchr(name, '-'))
|
||||
current_binding->modmask |= ControlMask;
|
||||
if ((substring = strchr(name, '-')) != NULL) {
|
||||
for (iter = 0; iter < nitems(bind_mods); iter++) {
|
||||
if ((tmp = strchr(name, bind_mods[iter].chr)) !=
|
||||
NULL && tmp < substring) {
|
||||
current_binding->modmask |=
|
||||
bind_mods[iter].mask;
|
||||
}
|
||||
}
|
||||
|
||||
if (strchr(name, 'M') != NULL &&
|
||||
strchr(name, 'M') < strchr(name, '-'))
|
||||
current_binding->modmask |= Mod1Mask;
|
||||
|
||||
if (strchr(name, 'S') != NULL &&
|
||||
strchr(name, 'S') < strchr(name, '-'))
|
||||
current_binding->modmask |= ShiftMask;
|
||||
|
||||
if (strchr(name, '4') != NULL &&
|
||||
strchr(name, '4') < strchr(name, '-'))
|
||||
current_binding->modmask |= Mod4Mask;
|
||||
|
||||
substring = strchr(name, '-') + 1;
|
||||
|
||||
if (strchr(name, '-') == NULL)
|
||||
/* skip past the modifiers */
|
||||
substring++;
|
||||
} else
|
||||
substring = name;
|
||||
|
||||
current_binding->button = strtonum(substring, 1, 3, &errstr);
|
||||
@ -473,7 +599,7 @@ conf_mousebind(struct conf *c, char *name, char *binding)
|
||||
if (strcmp("unmap", binding) == 0)
|
||||
return;
|
||||
|
||||
for (iter = 0; name_to_mousefunc[iter].tag != NULL; iter++) {
|
||||
for (iter = 0; iter < nitems(name_to_mousefunc); iter++) {
|
||||
if (strcmp(name_to_mousefunc[iter].tag, binding) != 0)
|
||||
continue;
|
||||
|
||||
@ -484,7 +610,7 @@ conf_mousebind(struct conf *c, char *name, char *binding)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
conf_mouseunbind(struct conf *c, struct mousebinding *unbind)
|
||||
{
|
||||
struct mousebinding *mb = NULL, *mbnxt;
|
||||
@ -528,7 +654,8 @@ conf_grab_mouse(struct client_ctx *cc)
|
||||
break;
|
||||
default:
|
||||
warnx("strange button in mousebinding\n");
|
||||
continue;
|
||||
}
|
||||
xu_btn_grab(cc->pwin, mb->modmask, button);
|
||||
xu_btn_grab(cc->win, mb->modmask, button);
|
||||
}
|
||||
}
|
||||
|
116
cwm.1
116
cwm.1
@ -14,8 +14,7 @@
|
||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
.\"
|
||||
.\" The following requests are required for all man pages.
|
||||
.Dd $Mdocdate: July 11 2008 $
|
||||
.Dd $Mdocdate: September 25 2010 $
|
||||
.Dt CWM 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -37,29 +36,29 @@ The following notation is used throughout this page:
|
||||
.Pp
|
||||
.Bl -tag -width Ds -offset indent -compact
|
||||
.It Ic C
|
||||
Control
|
||||
Control.
|
||||
.It Ic M
|
||||
Meta
|
||||
Meta.
|
||||
.It Ic S
|
||||
Shift
|
||||
Shift.
|
||||
.It Ic M1
|
||||
Left mouse button
|
||||
Left mouse button.
|
||||
.It Ic M2
|
||||
Middle mouse button
|
||||
Middle mouse button.
|
||||
.It Ic M3
|
||||
Right mouse button
|
||||
Right mouse button.
|
||||
.El
|
||||
.Pp
|
||||
.Nm
|
||||
is very simple in its use.
|
||||
Most of the actions are initiated via keybindings.
|
||||
The current keybindings are described below;
|
||||
Most of the actions are initiated via key bindings.
|
||||
The current key bindings are described below;
|
||||
their functionality is described in more detail later.
|
||||
.Pp
|
||||
.Bl -tag -width "C-M-EscapeXXX" -offset indent -compact
|
||||
.It Ic C-M-Return
|
||||
.Bl -tag -width "CM-EscapeXXXXX" -offset indent -compact
|
||||
.It Ic CM-Return
|
||||
Spawn a new terminal.
|
||||
.It Ic C-M-Delete
|
||||
.It Ic CM-Delete
|
||||
Lock the screen.
|
||||
.It Ic M-Return
|
||||
Hide current window.
|
||||
@ -71,50 +70,54 @@ Raise current window.
|
||||
Search for windows.
|
||||
.It Ic C-/
|
||||
Search for applications.
|
||||
.It Ic C-M-n
|
||||
.It Ic CM-n
|
||||
Label current window.
|
||||
.It Ic M-Tab
|
||||
Cycle through currently visible windows.
|
||||
.It Ic M-S-Tab
|
||||
.It Ic MS-Tab
|
||||
Reverse cycle through currently visible windows.
|
||||
.It Ic C-M-x
|
||||
.It Ic CM-x
|
||||
Delete current window.
|
||||
.It Ic C-M-[n]
|
||||
.It Ic CM-[n]
|
||||
Select group n, where n is 1-9.
|
||||
.It Ic C-M-0
|
||||
.It Ic CM-0
|
||||
Select all groups.
|
||||
.It Ic C-M-g
|
||||
.It Ic CM-g
|
||||
Toggle group membership of current window.
|
||||
.It Ic M-Right
|
||||
Cycle through active groups.
|
||||
.It Ic M-Left
|
||||
Reverse cycle through active groups.
|
||||
.It Ic C-M-f
|
||||
.It Ic CMS-f
|
||||
Toggle freezing geometry of current window.
|
||||
.It Ic CM-f
|
||||
Toggle full-screen size of current window.
|
||||
.It Ic C-M-=
|
||||
.It Ic CM-=
|
||||
Toggle vertical maximization of current window.
|
||||
.It Ic CMS-=
|
||||
Toggle horizontal maximization of current window.
|
||||
.It Ic M-?
|
||||
Spawn
|
||||
.Dq Exec program
|
||||
.Dq exec program
|
||||
dialog.
|
||||
.It Ic M-.
|
||||
Spawn
|
||||
.Dq Ssh to
|
||||
.Dq ssh to
|
||||
dialog.
|
||||
This parses
|
||||
.Pa $HOME/.ssh/known_hosts
|
||||
to provide host auto-completion.
|
||||
.Xr ssh 1
|
||||
will be executed via the configured terminal emulator.
|
||||
.It Ic C-M-w
|
||||
.It Ic CM-w
|
||||
Spawn
|
||||
.Dq Exec WindowManager
|
||||
.Dq exec WindowManager
|
||||
dialog; allows you to switch from
|
||||
.Nm
|
||||
to another window manager without restarting the X server.
|
||||
.It Ic C-M-S-r
|
||||
.It Ic CMS-r
|
||||
Reload configuration.
|
||||
.It Ic C-M-S-q
|
||||
.It Ic CMS-q
|
||||
Quit
|
||||
.Nm .
|
||||
.El
|
||||
@ -122,15 +125,15 @@ Quit
|
||||
The mouse bindings are also important, they are:
|
||||
.Pp
|
||||
.Bl -tag -width Ds -offset indent -compact
|
||||
.It M-M1
|
||||
.It Ic M-M1
|
||||
Move current window.
|
||||
.It C-M-M1
|
||||
.It Ic CM-M1
|
||||
Toggle group membership of current window.
|
||||
.It M-M2
|
||||
.It Ic M-M2
|
||||
Resize current window
|
||||
.It M-M3
|
||||
.It Ic M-M3
|
||||
Lower current window.
|
||||
.It CMS-M3
|
||||
.It Ic CMS-M3
|
||||
Hide current window.
|
||||
.El
|
||||
.Pp
|
||||
@ -146,22 +149,34 @@ Specify the display to use.
|
||||
.El
|
||||
.Sh POINTER MOVEMENT
|
||||
The pointer can be moved with the use of the keyboard through bindings.
|
||||
C-[UP|DOWN|LEFT|RIGHT] moves the pointer a small amount, while
|
||||
C-shift-[UP|DOWN|LEFT|RIGHT] moves the pointer a larger amount.
|
||||
.Ic C-[Up|Down|Left|Right]
|
||||
moves the pointer a small amount, while
|
||||
.Ic CS-[Up|Down|Left|Right]
|
||||
moves the pointer a larger amount.
|
||||
For example, to move the pointer to the left by a small amount,
|
||||
press C-LEFT.
|
||||
To move the pointer down by a larger amount, press C-shift-DOWN.
|
||||
press
|
||||
.Ic C-Left .
|
||||
To move the pointer down by a larger amount, press
|
||||
.Ic CS-Down .
|
||||
.Sh WINDOW MOVEMENT AND RESIZING
|
||||
.Nm
|
||||
windows can be moved with the use of the keyboard through Vi-like bindings.
|
||||
M-[hjkl] moves the current window a small amount, while M-shift-[hjkl] moves
|
||||
the current window a larger amount.
|
||||
For example, to move the current window to the left a small amount, press M-h.
|
||||
To move the current window down by a larger amount, press M-shift-j.
|
||||
windows can be moved with the use of the keyboard through
|
||||
.Cm vi Ns -like
|
||||
bindings.
|
||||
.Ic M-[hjkl]
|
||||
moves the current window a small amount, while
|
||||
.Ic MS-[hjkl]
|
||||
moves the current window a larger amount.
|
||||
For example, to move the current window to the left a small amount, press
|
||||
.Ic M-h .
|
||||
To move the current window down by a larger amount, press
|
||||
.Ic MS-j .
|
||||
.Pp
|
||||
Similarly, windows may be resized with the same keybindings with the addition
|
||||
Similarly, windows may be resized with the same key bindings with the addition
|
||||
of the Control key.
|
||||
C-M-[hjkl] resizes the window a small amount and C-M-shift-[hjkl]
|
||||
.Ic CM-[hjkl]
|
||||
resizes the window a small amount and
|
||||
.Ic CMS-[hjkl]
|
||||
resizes by a larger increment.
|
||||
.Sh SEARCH
|
||||
.Nm
|
||||
@ -175,14 +190,14 @@ keeps a history of the 5 previous titles of a window.
|
||||
When searching, the leftmost character of the result list may show a
|
||||
flag:
|
||||
.Pp
|
||||
.Bl -tag -width 10n -offset -indent -compact
|
||||
.Bl -tag -width 10n -offset indent -compact
|
||||
.It !
|
||||
The window is the currently focused window.
|
||||
.It &
|
||||
The window is hidden.
|
||||
.El
|
||||
.Pp
|
||||
The following keybindings may be used to navigate the result list:
|
||||
The following key bindings may be used to navigate the result list:
|
||||
.Pp
|
||||
.Bl -tag -width "[Down] or C-s or M-j" -offset indent -compact
|
||||
.It Ic [Down], C-s No or Ic M-j
|
||||
@ -217,14 +232,14 @@ and a red border will be shown on those just removed.
|
||||
.Sh MENUS
|
||||
Menus are recalled by clicking the mouse on the root window:
|
||||
.Pp
|
||||
.Bl -tag -width 10n -offset -indent -compact
|
||||
.It M1
|
||||
.Bl -tag -width 10n -offset indent -compact
|
||||
.It Ic M1
|
||||
Show list of currently hidden windows.
|
||||
Clicking on an item will unhide that window.
|
||||
.It M2
|
||||
.It Ic M2
|
||||
Show list of currently defined groups.
|
||||
Clicking on an item will hide/unhide that group.
|
||||
.It M3
|
||||
.It Ic M3
|
||||
Show list of applications as defined in
|
||||
.Pa ~/.cwmrc .
|
||||
Clicking on an item will spawn that application.
|
||||
@ -240,6 +255,7 @@ option is given.
|
||||
.Sh FILES
|
||||
.Bl -tag -width Ds
|
||||
.It Pa ~/.cwmrc
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr cwmrc 5
|
||||
.Sh AUTHORS
|
||||
@ -252,7 +268,7 @@ with contributions from
|
||||
.An Andy Adamson Aq dros@monkey.org ,
|
||||
.An Niels Provos Aq provos@monkey.org ,
|
||||
and
|
||||
.An Antti Nyk<EFBFBD>nen Aq aon@iki.fi .
|
||||
.An Antti Nyk\(:anen Aq aon@iki.fi .
|
||||
Ideas, discussion with many others.
|
||||
.Sh HISTORY
|
||||
.Nm
|
||||
|
203
cwmrc.5
203
cwmrc.5
@ -14,8 +14,7 @@
|
||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
.\"
|
||||
.\" The following requests are required for all man pages.
|
||||
.Dd $Mdocdate: July 11 2008 $
|
||||
.Dd $Mdocdate: September 8 2011 $
|
||||
.Dt CWMRC 5
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -25,24 +24,36 @@
|
||||
This manual page describes the
|
||||
.Xr cwm 1
|
||||
configuration file.
|
||||
The following options are accepted in the configuration file:
|
||||
.Pp
|
||||
The current line can be extended over multiple lines using a backslash
|
||||
.Pq Sq \e .
|
||||
Comments can be put anywhere in the file using a hash mark
|
||||
.Pq Sq # ,
|
||||
and extend to the end of the current line.
|
||||
Care should be taken when commenting out multi-line text:
|
||||
the comment is effective until the end of the entire block.
|
||||
.Pp
|
||||
Arguments containing whitespace should be surrounded by double quotes
|
||||
.Pq \&" .
|
||||
.Pp
|
||||
The following options are accepted:
|
||||
.Pp
|
||||
.Bl -tag -width Ds -compact
|
||||
.It Ic autogroup Ar group Dq windowclass
|
||||
.It Ic autogroup Ar group Dq windowclass,windowname
|
||||
Control automatic window grouping, based on the class and/or name
|
||||
.It Ic autogroup Ar group windowname
|
||||
.It Ic autogroup Ar group windowname,windowclass
|
||||
Control automatic window grouping, based on the name and/or class
|
||||
properties, where
|
||||
.Ar group
|
||||
is a number between 0 and 9.
|
||||
If the group number is 0, then the window will not be grouped; this to
|
||||
allow for
|
||||
allow for
|
||||
.Dq sticky
|
||||
windows in sticky group mode.
|
||||
.Pp
|
||||
The class and name of a window may be obtained using
|
||||
The name and class of a window may be obtained using
|
||||
.Xr xprop 1 .
|
||||
.Pp
|
||||
.It Ic bind Ar keys Ar command
|
||||
.It Ic bind Ar keys command
|
||||
Cause the creation of a keybinding, or replacement of a default
|
||||
keybinding.
|
||||
The modifier keys come first, followed by a
|
||||
@ -81,7 +92,32 @@ can be used to remove the named keybinding.
|
||||
This can be used to remove a binding which conflicts with an
|
||||
application.
|
||||
.Pp
|
||||
.It Ic command Ar name Ar path
|
||||
.It Ic borderwidth Ar pixels
|
||||
Set the window border width to
|
||||
.Ar pixels .
|
||||
.Pp
|
||||
.It Ic color activeborder Ar color
|
||||
Set the color of the active border.
|
||||
.Pp
|
||||
.It Ic color font Ar color
|
||||
Set menu font color.
|
||||
.Pp
|
||||
.It Ic color groupborder Ar color
|
||||
Set the color of the border while grouping a window.
|
||||
.Pp
|
||||
.It Ic color inactiveborder Ar color
|
||||
Set the color of the inactive border.
|
||||
.Pp
|
||||
.It Ic color menubg Ar color
|
||||
Set menu background color.
|
||||
.Pp
|
||||
.It Ic color menufg Ar color
|
||||
Set menu foreground color.
|
||||
.Pp
|
||||
.It Ic color ungroupborder Ar color
|
||||
Set the color of the border while ungrouping a window.
|
||||
.Pp
|
||||
.It Ic command Ar name path
|
||||
Every
|
||||
.Ar name
|
||||
entry is shown in the application menu.
|
||||
@ -123,19 +159,20 @@ can be used for applications such as
|
||||
where the user may wish to remain visible.
|
||||
.Pp
|
||||
.It Ic ignore Ar windowname
|
||||
Ignore drawing borders around a window with the name
|
||||
.Ar windowname .
|
||||
Ignore, and do not warp to, windows with the name
|
||||
.Ar windowname
|
||||
when drawing borders and cycling through windows.
|
||||
.Pp
|
||||
.It Ic mousebind Ar buttons Ar command
|
||||
.It Ic mousebind Ar buttons command
|
||||
Cause the creation of a mouse binding, or replacement of a default
|
||||
mouse binding.
|
||||
The modifier keys come first, followed by a
|
||||
.Sq - .
|
||||
.Pb
|
||||
.Pp
|
||||
The following modifiers are recognised:
|
||||
.Pp
|
||||
.Bl -tag -width Ds -offset indent -compact
|
||||
.It C
|
||||
.It C
|
||||
The Control key.
|
||||
.It M
|
||||
The Meta key.
|
||||
@ -148,15 +185,14 @@ The Mod4 key (normally the windows key).
|
||||
The
|
||||
.Sq -
|
||||
should be followed by number:
|
||||
.Pb
|
||||
.Bl -tag -width Ds -offset indent -compact
|
||||
.Pp
|
||||
.Bl -tag -width Ds -offset indent -compact
|
||||
.It 1
|
||||
Left mouse button.
|
||||
.It 2
|
||||
Right mouse button.
|
||||
.It 3
|
||||
Middle mouse button.
|
||||
.It 3
|
||||
Right mouse button.
|
||||
.El
|
||||
.Pp
|
||||
The
|
||||
@ -165,6 +201,15 @@ may be taken from the
|
||||
.Sx MOUSEBIND COMMAND LIST
|
||||
(see below).
|
||||
.Pp
|
||||
.It Ic moveamount Ar pixels
|
||||
Set a default size for the keyboard movement bindings,
|
||||
in pixels.
|
||||
The default is 1.
|
||||
.Pp
|
||||
.It Ic snapdist Ar pixels
|
||||
Minimum distance to snap-to adjacent edge, in pixels.
|
||||
The default is 0.
|
||||
.Pp
|
||||
.It Ic sticky Ic yes Ns \&| Ns Ic no
|
||||
Toggle sticky group mode.
|
||||
The default behavior for new windows is to not assign any group.
|
||||
@ -199,6 +244,12 @@ ignore xclock
|
||||
bind CM-r label
|
||||
bind CS-Return "xterm -e top"
|
||||
bind 4-o unmap
|
||||
bind M-1 grouponly1
|
||||
bind M-2 grouponly2
|
||||
bind M-3 grouponly3
|
||||
bind MS-1 movetogroup1
|
||||
bind MS-2 movetogroup2
|
||||
bind MS-3 movetogroup3
|
||||
|
||||
# Mousebindings
|
||||
mousebind M-2 window_lower
|
||||
@ -233,10 +284,16 @@ Launch
|
||||
menu.
|
||||
.It group[n]
|
||||
Select group n, where n is 1-9.
|
||||
.It grouponly[n]
|
||||
Like
|
||||
.Ar group[n]
|
||||
but also hides the other groups.
|
||||
.It nogroup
|
||||
Select all groups.
|
||||
.It grouptoggle
|
||||
Toggle group membership of current window.
|
||||
.It movetogroup[n]
|
||||
Hide current window from display and move to group n, where n is 1-9.
|
||||
.It cyclegroup
|
||||
Forward cycle through groups.
|
||||
.It rcyclegroup
|
||||
@ -245,6 +302,10 @@ Reverse cycle through groups.
|
||||
Forward cycle through windows.
|
||||
.It rcycle
|
||||
Reverse cycle through windows.
|
||||
.It cycleingroup
|
||||
Forward cycle through windows in current group.
|
||||
.It rcycleingroup
|
||||
Reverse cycle through windows in current group.
|
||||
.It delete
|
||||
Delete current window.
|
||||
.It hide
|
||||
@ -255,58 +316,110 @@ Lower current window.
|
||||
Raise current window.
|
||||
.It label
|
||||
Label current window.
|
||||
.It freeze
|
||||
Freeze current window geometry.
|
||||
.It maximize
|
||||
Maximize current window full-screen.
|
||||
.It vmaximize
|
||||
Maximize current window vertically.
|
||||
.It hmaximize
|
||||
Maximize current window horizontally.
|
||||
.It moveup
|
||||
Move window 1 pixel up.
|
||||
Move window
|
||||
.Ar moveamount
|
||||
pixels up.
|
||||
.It movedown
|
||||
Move window 1 pixel down.
|
||||
Move window
|
||||
.Ar moveamount
|
||||
pixels down.
|
||||
.It moveright
|
||||
Move window 1 pixel right.
|
||||
Move window
|
||||
.Ar moveamount
|
||||
pixels right.
|
||||
.It moveleft
|
||||
Move window 1 pixel left.
|
||||
Move window
|
||||
.Ar moveamount
|
||||
pixels left.
|
||||
.It bigmoveup
|
||||
Move window 10 pixels up.
|
||||
Move window 10 times
|
||||
.Ar moveamount
|
||||
pixels up.
|
||||
.It bigmovedown
|
||||
Move window 10 pixels down.
|
||||
Move window 10 times
|
||||
.Ar moveamount
|
||||
pixels down.
|
||||
.It bigmoveright
|
||||
Move window 10 pixels right.
|
||||
Move window 10 times
|
||||
.Ar moveamount
|
||||
pixels right.
|
||||
.It bigmoveleft
|
||||
Move window 10 pixels left.
|
||||
Move window 10 times
|
||||
.Ar moveamount
|
||||
pixels left.
|
||||
.It resizeup
|
||||
Resize window 1 pixel up.
|
||||
Resize window
|
||||
.Ar moveamount
|
||||
pixels up.
|
||||
.It resizedown
|
||||
Resize window 1 pixel down.
|
||||
Resize window
|
||||
.Ar moveamount
|
||||
pixels down.
|
||||
.It resizeright
|
||||
Resize window 1 pixel right.
|
||||
Resize window
|
||||
.Ar moveamount
|
||||
pixels right.
|
||||
.It resizeleft
|
||||
Resize window 1 pixel left.
|
||||
Resize window
|
||||
.Ar moveamount
|
||||
pixels left.
|
||||
.It bigresizeup
|
||||
Resize window 10 pixels up.
|
||||
Resize window 10 times
|
||||
.Ar moveamount
|
||||
pixels up.
|
||||
.It bigresizedown
|
||||
Resize window 10 pixels down.
|
||||
Resize window 10 times
|
||||
.Ar moveamount
|
||||
pixels down.
|
||||
.It bigresizeright
|
||||
Resize window 10 pixels right.
|
||||
Resize window 10 times
|
||||
.Ar moveamount
|
||||
pixels right.
|
||||
.It bigresizeleft
|
||||
Resize window 10 pixels left.
|
||||
Resize window 10 times
|
||||
.Ar moveamount
|
||||
pixels left.
|
||||
.It ptrmoveup
|
||||
Move pointer 1 pixel up.
|
||||
Move pointer
|
||||
.Ar moveamount
|
||||
pixels up.
|
||||
.It ptrmovedown
|
||||
Move pointer 1 pixel down.
|
||||
Move pointer
|
||||
.Ar moveamount
|
||||
pixels down.
|
||||
.It ptrmoveright
|
||||
Move pointer 1 pixel right.
|
||||
Move pointer
|
||||
.Ar moveamount
|
||||
pixels right.
|
||||
.It ptrmoveleft
|
||||
Move pointer 1 pixel left.
|
||||
Move pointer
|
||||
.Ar moveamount
|
||||
pixels left.
|
||||
.It bigptrmoveup
|
||||
Move pointer 10 pixels up.
|
||||
Move pointer 10 times
|
||||
.Ar moveamount
|
||||
pixels up.
|
||||
.It bigptrmovedown
|
||||
Move pointer 10 pixels down.
|
||||
Move pointer 10 times
|
||||
.Ar moveamount
|
||||
pixels down.
|
||||
.It bigptrmoveright
|
||||
Move pointer 10 pixels right.
|
||||
Move pointer 10 times
|
||||
.Ar moveamount
|
||||
pixels right.
|
||||
.It bigptrmoveleft
|
||||
Move pointer 10 pixels left.
|
||||
Move pointer 10 times
|
||||
.Ar moveamount
|
||||
pixels left.
|
||||
.El
|
||||
.Sh MOUSEBIND COMMAND LIST
|
||||
.Bl -tag -width 18n -compact
|
||||
@ -316,6 +429,8 @@ Move current window.
|
||||
Resize current window.
|
||||
.It window_lower
|
||||
Lower current window.
|
||||
.It window_raise
|
||||
Raise current window.
|
||||
.It window_hide
|
||||
Hide current window.
|
||||
.It window_grouptoggle
|
||||
@ -323,7 +438,7 @@ Toggle group membership of current window.
|
||||
.It menu_group
|
||||
Launch group list.
|
||||
.It menu_unhide
|
||||
Launch group list.
|
||||
Launch hidden window list.
|
||||
.It menu_cmd
|
||||
Launch command list.
|
||||
.El
|
||||
|
106
fgetln.c
Normal file
106
fgetln.c
Normal file
@ -0,0 +1,106 @@
|
||||
/* $NetBSD: fgetln.c,v 1.9 2008/04/29 06:53:03 martin Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#if !HAVE_FGETLN
|
||||
#include <stdlib.h>
|
||||
#ifndef HAVE_NBTOOL_CONFIG_H
|
||||
/* These headers are required, but included from nbtool_config.h */
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
char *
|
||||
fgetln(FILE *fp, size_t *len)
|
||||
{
|
||||
static char *buf = NULL;
|
||||
static size_t bufsiz = 0;
|
||||
char *ptr;
|
||||
|
||||
|
||||
if (buf == NULL) {
|
||||
bufsiz = BUFSIZ;
|
||||
if ((buf = malloc(bufsiz)) == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fgets(buf, bufsiz, fp) == NULL)
|
||||
return NULL;
|
||||
|
||||
*len = 0;
|
||||
while ((ptr = strchr(&buf[*len], '\n')) == NULL) {
|
||||
size_t nbufsiz = bufsiz + BUFSIZ;
|
||||
char *nbuf = realloc(buf, nbufsiz);
|
||||
|
||||
if (nbuf == NULL) {
|
||||
int oerrno = errno;
|
||||
free(buf);
|
||||
errno = oerrno;
|
||||
buf = NULL;
|
||||
return NULL;
|
||||
} else
|
||||
buf = nbuf;
|
||||
|
||||
if (fgets(&buf[bufsiz], BUFSIZ, fp) == NULL) {
|
||||
buf[bufsiz] = '\0';
|
||||
*len = strlen(buf);
|
||||
return buf;
|
||||
}
|
||||
|
||||
*len = bufsiz;
|
||||
bufsiz = nbufsiz;
|
||||
}
|
||||
|
||||
*len = (ptr - buf) + 1;
|
||||
return buf;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef TEST
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char *p;
|
||||
size_t len;
|
||||
|
||||
while ((p = fgetln(stdin, &len)) != NULL) {
|
||||
(void)printf("%zu %s", len, p);
|
||||
free(p);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
63
font.c
63
font.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* font.c - cwm font abstraction
|
||||
* calmwm - the calm window manager
|
||||
*
|
||||
* Copyright (c) 2005 Marius Eriksen <marius@monkey.org>
|
||||
*
|
||||
@ -14,38 +14,64 @@
|
||||
* 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 "headers.h"
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "calmwm.h"
|
||||
|
||||
void
|
||||
font_init(struct screen_ctx *sc)
|
||||
int
|
||||
font_ascent(struct screen_ctx *sc)
|
||||
{
|
||||
XColor xcolor, tmp;
|
||||
return (sc->font->ascent);
|
||||
}
|
||||
|
||||
int
|
||||
font_descent(struct screen_ctx *sc)
|
||||
{
|
||||
return (sc->font->descent);
|
||||
}
|
||||
|
||||
u_int
|
||||
font_height(struct screen_ctx *sc)
|
||||
{
|
||||
return (sc->font->height + 1);
|
||||
}
|
||||
|
||||
void
|
||||
font_init(struct screen_ctx *sc, const char *color)
|
||||
{
|
||||
if (sc->xftdraw)
|
||||
XftDrawDestroy(sc->xftdraw);
|
||||
sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin,
|
||||
DefaultVisual(X_Dpy, sc->which), DefaultColormap(X_Dpy, sc->which));
|
||||
if (sc->xftdraw == NULL)
|
||||
errx(1, "XftDrawCreate");
|
||||
|
||||
if (!XAllocNamedColor(X_Dpy, DefaultColormap(X_Dpy, sc->which),
|
||||
"black", &xcolor, &tmp))
|
||||
errx(1, "XAllocNamedColor");
|
||||
|
||||
sc->xftcolor.color.red = xcolor.red;
|
||||
sc->xftcolor.color.green = xcolor.green;
|
||||
sc->xftcolor.color.blue = xcolor.blue;
|
||||
sc->xftcolor.color.alpha = 0x00ff00;
|
||||
sc->xftcolor.pixel = xcolor.pixel;
|
||||
if (sc->xftcolor.pixel)
|
||||
XftColorFree(X_Dpy, DefaultVisual(X_Dpy, sc->which),
|
||||
DefaultColormap(X_Dpy, sc->which), &sc->xftcolor);
|
||||
if (!XftColorAllocName(X_Dpy, DefaultVisual(X_Dpy, sc->which),
|
||||
DefaultColormap(X_Dpy, sc->which), color, &sc->xftcolor))
|
||||
errx(1, "XftColorAllocName");
|
||||
}
|
||||
|
||||
int
|
||||
font_width(const char *text, int len)
|
||||
font_width(struct screen_ctx *sc, const char *text, int len)
|
||||
{
|
||||
XGlyphInfo extents;
|
||||
|
||||
XftTextExtents8(X_Dpy, Conf.DefaultFont, (const XftChar8*)text,
|
||||
XftTextExtentsUtf8(X_Dpy, sc->font, (const FcChar8*)text,
|
||||
len, &extents);
|
||||
|
||||
return (extents.xOff);
|
||||
@ -56,8 +82,7 @@ font_draw(struct screen_ctx *sc, const char *text, int len,
|
||||
Drawable d, int x, int y)
|
||||
{
|
||||
XftDrawChange(sc->xftdraw, d);
|
||||
/* Really needs to be UTF8'd. */
|
||||
XftDrawString8(sc->xftdraw, &sc->xftcolor, Conf.DefaultFont, x, y,
|
||||
XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor, sc->font, x, y,
|
||||
(const FcChar8*)text, len);
|
||||
}
|
||||
|
||||
@ -68,7 +93,7 @@ font_make(struct screen_ctx *sc, const char *name)
|
||||
FcPattern *pat, *patx;
|
||||
XftResult res;
|
||||
|
||||
if ((pat = FcNameParse(name)) == NULL)
|
||||
if ((pat = FcNameParse((const FcChar8*)name)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
if ((patx = XftFontMatch(X_Dpy, sc->which, pat, &res)) != NULL)
|
||||
|
184
grab.c
184
grab.c
@ -1,184 +0,0 @@
|
||||
/*
|
||||
* calmwm - the calm window manager
|
||||
*
|
||||
* Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include "headers.h"
|
||||
#include "calmwm.h"
|
||||
|
||||
static int _sweepcalc(struct client_ctx *, int, int, int, int);
|
||||
|
||||
#define ADJUST_HEIGHT(cc, dy) ((cc->geom.height - cc->geom.min_dy)/ dy)
|
||||
#define ADJUST_WIDTH(cc, dx) ((cc->geom.width - cc->geom.min_dx)/ dx)
|
||||
|
||||
void
|
||||
grab_sweep_draw(struct client_ctx *cc, int dx, int dy)
|
||||
{
|
||||
struct screen_ctx *sc = CCTOSC(cc);
|
||||
char asize[10]; /* fits "nnnnxnnnn\0" */
|
||||
int wide, height, wide_size, wide_name;
|
||||
int x = cc->geom.x, y = cc->geom.y;
|
||||
|
||||
snprintf(asize, sizeof(asize), "%dx%d",
|
||||
ADJUST_WIDTH(cc, dx), ADJUST_HEIGHT(cc, dy));
|
||||
wide_size = font_width(asize, strlen(asize)) + 4;
|
||||
wide_name = font_width(cc->name, strlen(cc->name)) + 4;
|
||||
wide = MAX(wide_size, wide_name);
|
||||
height = font_ascent() + font_descent() + 1;
|
||||
|
||||
XMoveResizeWindow(X_Dpy, sc->menuwin, x, y, wide, height * 2);
|
||||
XMapWindow(X_Dpy, sc->menuwin);
|
||||
XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0);
|
||||
XClearWindow(X_Dpy, sc->menuwin);
|
||||
font_draw(sc, cc->name, strlen(cc->name), sc->menuwin,
|
||||
2, font_ascent() + 1);
|
||||
font_draw(sc, asize, strlen(asize), sc->menuwin,
|
||||
wide / 2 - wide_size / 2, height + font_ascent() + 1);
|
||||
}
|
||||
|
||||
void
|
||||
grab_sweep(struct client_ctx *cc)
|
||||
{
|
||||
XEvent ev;
|
||||
struct screen_ctx *sc = CCTOSC(cc);
|
||||
int x = cc->geom.x, y = cc->geom.y, dx, dy;
|
||||
|
||||
dx = MAX(1, cc->size->width_inc);
|
||||
dy = MAX(1, cc->size->height_inc);
|
||||
|
||||
client_raise(cc);
|
||||
client_ptrsave(cc);
|
||||
|
||||
if (xu_ptr_grab(sc->rootwin, MouseMask, Cursor_resize) < 0)
|
||||
return;
|
||||
|
||||
xu_ptr_setpos(cc->win, cc->geom.width, cc->geom.height);
|
||||
grab_sweep_draw(cc, dx, dy);
|
||||
|
||||
for (;;) {
|
||||
/* Look for changes in ptr position. */
|
||||
XMaskEvent(X_Dpy, MouseMask|ExposureMask, &ev);
|
||||
|
||||
switch (ev.type) {
|
||||
case Expose:
|
||||
client_draw_border(cc);
|
||||
break;
|
||||
case MotionNotify:
|
||||
if (_sweepcalc(cc, x, y, ev.xmotion.x, ev.xmotion.y))
|
||||
/* Recompute window output */
|
||||
grab_sweep_draw(cc, dx, dy);
|
||||
|
||||
XMoveResizeWindow(X_Dpy, cc->pwin,
|
||||
cc->geom.x - cc->bwidth,
|
||||
cc->geom.y - cc->bwidth,
|
||||
cc->geom.width + cc->bwidth*2,
|
||||
cc->geom.height + cc->bwidth*2);
|
||||
XMoveResizeWindow(X_Dpy, cc->win,
|
||||
cc->bwidth, cc->bwidth,
|
||||
cc->geom.width, cc->geom.height);
|
||||
|
||||
client_do_shape(cc);
|
||||
break;
|
||||
case ButtonRelease:
|
||||
XUnmapWindow(X_Dpy, sc->menuwin);
|
||||
XReparentWindow(X_Dpy, sc->menuwin, sc->rootwin, 0, 0);
|
||||
xu_ptr_ungrab();
|
||||
|
||||
/* Make sure the pointer stays within the window. */
|
||||
if (cc->ptr.x > cc->geom.width)
|
||||
cc->ptr.x = cc->geom.width - cc->bwidth;
|
||||
if (cc->ptr.y > cc->geom.height)
|
||||
cc->ptr.y = cc->geom.height - cc->bwidth;
|
||||
client_ptrwarp(cc);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
void
|
||||
grab_drag(struct client_ctx *cc)
|
||||
{
|
||||
XEvent ev;
|
||||
struct screen_ctx *sc = CCTOSC(cc);
|
||||
int x = cc->geom.x, y = cc->geom.y, xm, ym;
|
||||
|
||||
client_raise(cc);
|
||||
|
||||
if (xu_ptr_grab(sc->rootwin, MouseMask, Cursor_move) < 0)
|
||||
return;
|
||||
|
||||
xu_ptr_getpos(sc->rootwin, &xm, &ym);
|
||||
|
||||
for (;;) {
|
||||
XMaskEvent(X_Dpy, MouseMask|ExposureMask, &ev);
|
||||
|
||||
switch (ev.type) {
|
||||
case Expose:
|
||||
client_draw_border(cc);
|
||||
break;
|
||||
case MotionNotify:
|
||||
cc->geom.x = x + (ev.xmotion.x - xm);
|
||||
cc->geom.y = y + (ev.xmotion.y - ym);
|
||||
|
||||
XMoveWindow(X_Dpy, cc->pwin,
|
||||
cc->geom.x - cc->bwidth, cc->geom.y - cc->bwidth);
|
||||
|
||||
break;
|
||||
case ButtonRelease:
|
||||
xu_ptr_ungrab();
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
static int
|
||||
_sweepcalc(struct client_ctx *cc, int x, int y, int motionx, int motiony)
|
||||
{
|
||||
int width, height;
|
||||
|
||||
width = cc->geom.width;
|
||||
height = cc->geom.height;
|
||||
|
||||
cc->geom.width = abs(x - motionx);
|
||||
cc->geom.height = abs(y - motiony);
|
||||
|
||||
if (cc->size->flags & PResizeInc) {
|
||||
cc->geom.width -=
|
||||
(cc->geom.width - cc->geom.min_dx) % cc->size->width_inc;
|
||||
cc->geom.height -=
|
||||
(cc->geom.height - cc->geom.min_dy) % cc->size->height_inc;
|
||||
}
|
||||
|
||||
if (cc->size->flags & PMinSize) {
|
||||
cc->geom.width = MAX(cc->geom.width, cc->size->min_width);
|
||||
cc->geom.height = MAX(cc->geom.height, cc->size->min_height);
|
||||
}
|
||||
|
||||
if (cc->size->flags & PMaxSize) {
|
||||
cc->geom.width = MIN(cc->geom.width, cc->size->max_width);
|
||||
cc->geom.height = MIN(cc->geom.height, cc->size->max_height);
|
||||
}
|
||||
|
||||
cc->geom.x = x <= motionx ? x : x - cc->geom.width;
|
||||
cc->geom.y = y <= motiony ? y : y - cc->geom.height;
|
||||
|
||||
return (width != cc->geom.width || height != cc->geom.height);
|
||||
}
|
371
group.c
371
group.c
@ -16,24 +16,43 @@
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* $Id$
|
||||
* $OpenBSD$
|
||||
*/
|
||||
|
||||
#include "headers.h"
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "calmwm.h"
|
||||
|
||||
#define CALMWM_NGROUPS 9
|
||||
static void group_add(struct group_ctx *, struct client_ctx *);
|
||||
static void group_remove(struct client_ctx *);
|
||||
static void group_hide(struct screen_ctx *, struct group_ctx *);
|
||||
static void group_show(struct screen_ctx *, struct group_ctx *);
|
||||
static void group_fix_hidden_state(struct group_ctx *);
|
||||
static void group_setactive(struct screen_ctx *, long);
|
||||
static void group_set_names(struct screen_ctx *);
|
||||
|
||||
struct group_ctx *Group_active = NULL;
|
||||
struct group_ctx Groups[CALMWM_NGROUPS];
|
||||
int Grouphideall = 0;
|
||||
struct group_ctx_q Groupq;
|
||||
const char *shortcut_to_name[] = {
|
||||
"nogroup", "one", "two", "three", "four", "five", "six",
|
||||
"seven", "eight", "nine"
|
||||
};
|
||||
|
||||
static void
|
||||
_group_add(struct group_ctx *gc, struct client_ctx *cc)
|
||||
group_add(struct group_ctx *gc, struct client_ctx *cc)
|
||||
{
|
||||
long no;
|
||||
if (cc == NULL || gc == NULL)
|
||||
errx(1, "_group_add: a ctx is NULL");
|
||||
errx(1, "group_add: a ctx is NULL");
|
||||
|
||||
no = gc->shortcut - 1;
|
||||
|
||||
if (cc->group == gc)
|
||||
return;
|
||||
@ -41,26 +60,34 @@ _group_add(struct group_ctx *gc, struct client_ctx *cc)
|
||||
if (cc->group != NULL)
|
||||
TAILQ_REMOVE(&cc->group->clients, cc, group_entry);
|
||||
|
||||
XChangeProperty(X_Dpy, cc->win, _NET_WM_DESKTOP, XA_CARDINAL,
|
||||
32, PropModeReplace, (unsigned char *)&no, 1);
|
||||
|
||||
TAILQ_INSERT_TAIL(&gc->clients, cc, group_entry);
|
||||
cc->group = gc;
|
||||
}
|
||||
|
||||
static void
|
||||
_group_remove(struct client_ctx *cc)
|
||||
group_remove(struct client_ctx *cc)
|
||||
{
|
||||
long no = 0xffffffff;
|
||||
|
||||
if (cc == NULL || cc->group == NULL)
|
||||
errx(1, "_group_remove: a ctx is NULL");
|
||||
errx(1, "group_remove: a ctx is NULL");
|
||||
|
||||
XChangeProperty(X_Dpy, cc->win, _NET_WM_DESKTOP, XA_CARDINAL,
|
||||
32, PropModeReplace, (unsigned char *)&no, 1);
|
||||
|
||||
TAILQ_REMOVE(&cc->group->clients, cc, group_entry);
|
||||
cc->group = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
_group_hide(struct group_ctx *gc)
|
||||
group_hide(struct screen_ctx *sc, struct group_ctx *gc)
|
||||
{
|
||||
struct client_ctx *cc;
|
||||
|
||||
screen_updatestackingorder();
|
||||
screen_updatestackingorder(sc);
|
||||
|
||||
gc->nhidden = 0;
|
||||
gc->highstack = 0;
|
||||
@ -74,13 +101,18 @@ _group_hide(struct group_ctx *gc)
|
||||
}
|
||||
|
||||
static void
|
||||
_group_show(struct group_ctx *gc)
|
||||
group_show(struct screen_ctx *sc, struct group_ctx *gc)
|
||||
{
|
||||
struct client_ctx *cc;
|
||||
Window *winlist;
|
||||
u_int i;
|
||||
int lastempty = -1;
|
||||
|
||||
gc->highstack = 0;
|
||||
TAILQ_FOREACH(cc, &gc->clients, group_entry) {
|
||||
if (cc->stackingorder > gc->highstack)
|
||||
gc->highstack = cc->stackingorder;
|
||||
}
|
||||
winlist = (Window *) xcalloc(sizeof(*winlist), (gc->highstack + 1));
|
||||
|
||||
/*
|
||||
@ -88,7 +120,7 @@ _group_show(struct group_ctx *gc)
|
||||
* top-to-bottom.
|
||||
*/
|
||||
TAILQ_FOREACH(cc, &gc->clients, group_entry) {
|
||||
winlist[gc->highstack - cc->stackingorder] = cc->pwin;
|
||||
winlist[gc->highstack - cc->stackingorder] = cc->win;
|
||||
client_unhide(cc);
|
||||
}
|
||||
|
||||
@ -107,24 +139,96 @@ _group_show(struct group_ctx *gc)
|
||||
xfree(winlist);
|
||||
|
||||
gc->hidden = 0;
|
||||
Group_active = gc;
|
||||
group_setactive(sc, gc->shortcut - 1);
|
||||
}
|
||||
|
||||
void
|
||||
group_init(void)
|
||||
group_init(struct screen_ctx *sc)
|
||||
{
|
||||
int i;
|
||||
long viewports[2] = {0, 0};
|
||||
long ndesks = CALMWM_NGROUPS, zero = 0;
|
||||
|
||||
TAILQ_INIT(&Groupq);
|
||||
TAILQ_INIT(&sc->groupq);
|
||||
sc->group_hideall = 0;
|
||||
/* see if any group names have already been set and update the property
|
||||
* with ours if they'll have changed.
|
||||
*/
|
||||
group_update_names(sc);
|
||||
|
||||
for (i = 0; i < CALMWM_NGROUPS; i++) {
|
||||
TAILQ_INIT(&Groups[i].clients);
|
||||
Groups[i].hidden = 0;
|
||||
Groups[i].shortcut = i + 1;
|
||||
TAILQ_INSERT_TAIL(&Groupq, &Groups[i], entry);
|
||||
TAILQ_INIT(&sc->groups[i].clients);
|
||||
sc->groups[i].hidden = 0;
|
||||
sc->groups[i].shortcut = i + 1;
|
||||
TAILQ_INSERT_TAIL(&sc->groupq, &sc->groups[i], entry);
|
||||
}
|
||||
|
||||
Group_active = &Groups[0];
|
||||
/* we don't support large desktops, so this is always (0, 0) */
|
||||
XChangeProperty(X_Dpy, sc->rootwin, _NET_DESKTOP_VIEWPORT,
|
||||
XA_CARDINAL, 32, PropModeReplace, (unsigned char *)viewports, 2);
|
||||
XChangeProperty(X_Dpy, sc->rootwin, _NET_NUMBER_OF_DESKTOPS,
|
||||
XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&ndesks, 1);
|
||||
/*
|
||||
* we don't use virtual roots, so make sure it's not there from a
|
||||
* previous wm.
|
||||
*/
|
||||
XDeleteProperty(X_Dpy, sc->rootwin, _NET_VIRTUAL_ROOTS);
|
||||
/*
|
||||
* We don't really have a ``showing desktop'' mode, so this is zero
|
||||
* always. XXX Note that when we hide all groups, or when all groups
|
||||
* are hidden we could technically set this later on.
|
||||
*/
|
||||
XChangeProperty(X_Dpy, sc->rootwin, _NET_SHOWING_DESKTOP,
|
||||
XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&zero, 1);
|
||||
group_setactive(sc, 0);
|
||||
}
|
||||
|
||||
void
|
||||
group_make_autogroup(struct conf *conf, char *val, int no)
|
||||
{
|
||||
struct autogroupwin *aw;
|
||||
char *p;
|
||||
|
||||
aw = xcalloc(1, sizeof(*aw));
|
||||
|
||||
if ((p = strchr(val, ',')) == NULL) {
|
||||
aw->name = NULL;
|
||||
aw->class = xstrdup(val);
|
||||
} else {
|
||||
*(p++) = '\0';
|
||||
aw->name = xstrdup(val);
|
||||
aw->class = xstrdup(p);
|
||||
}
|
||||
aw->num = no;
|
||||
|
||||
TAILQ_INSERT_TAIL(&conf->autogroupq, aw, entry);
|
||||
}
|
||||
|
||||
static void
|
||||
group_setactive(struct screen_ctx *sc, long idx)
|
||||
{
|
||||
sc->group_active = &sc->groups[idx];
|
||||
XChangeProperty(X_Dpy, sc->rootwin, _NET_CURRENT_DESKTOP,
|
||||
XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&idx, 1);
|
||||
}
|
||||
|
||||
void
|
||||
group_movetogroup(struct client_ctx *cc, int idx)
|
||||
{
|
||||
struct screen_ctx *sc = cc->sc;
|
||||
struct group_ctx *gc;
|
||||
|
||||
if (idx < 0 || idx >= CALMWM_NGROUPS)
|
||||
err(1, "group_movetogroup: index out of range (%d)", idx);
|
||||
|
||||
gc = &sc->groups[idx];
|
||||
if (cc->group == gc)
|
||||
return;
|
||||
if (gc->hidden) {
|
||||
client_hide(cc);
|
||||
gc->nhidden++;
|
||||
}
|
||||
group_add(gc, cc);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -133,16 +237,17 @@ group_init(void)
|
||||
void
|
||||
group_sticky_toggle_enter(struct client_ctx *cc)
|
||||
{
|
||||
struct screen_ctx *sc = cc->sc;
|
||||
struct group_ctx *gc;
|
||||
|
||||
gc = Group_active;
|
||||
gc = sc->group_active;
|
||||
|
||||
if (gc == cc->group) {
|
||||
_group_remove(cc);
|
||||
cc->highlight = CLIENT_HIGHLIGHT_RED;
|
||||
group_remove(cc);
|
||||
cc->highlight = CLIENT_HIGHLIGHT_UNGROUP;
|
||||
} else {
|
||||
_group_add(gc, cc);
|
||||
cc->highlight = CLIENT_HIGHLIGHT_BLUE;
|
||||
group_add(gc, cc);
|
||||
cc->highlight = CLIENT_HIGHLIGHT_GROUP;
|
||||
}
|
||||
|
||||
client_draw_border(cc);
|
||||
@ -156,13 +261,10 @@ group_sticky_toggle_exit(struct client_ctx *cc)
|
||||
}
|
||||
|
||||
/*
|
||||
* selection list display
|
||||
* if group_hidetoggle would produce no effect, toggle the group's hidden state
|
||||
*/
|
||||
|
||||
/* if group_hidetoggle would produce no effect, toggle the group's hidden state
|
||||
*/
|
||||
void
|
||||
_group_fix_hidden_state(struct group_ctx *gc)
|
||||
static void
|
||||
group_fix_hidden_state(struct group_ctx *gc)
|
||||
{
|
||||
struct client_ctx *cc;
|
||||
int same = 0;
|
||||
@ -177,23 +279,39 @@ _group_fix_hidden_state(struct group_ctx *gc)
|
||||
}
|
||||
|
||||
void
|
||||
group_hidetoggle(int idx)
|
||||
group_hidetoggle(struct screen_ctx *sc, int idx)
|
||||
{
|
||||
struct group_ctx *gc;
|
||||
|
||||
if (idx < 0 || idx >= CALMWM_NGROUPS)
|
||||
err(1, "group_hidetoggle: index out of range (%d)", idx);
|
||||
|
||||
gc = &Groups[idx];
|
||||
|
||||
_group_fix_hidden_state(gc);
|
||||
gc = &sc->groups[idx];
|
||||
group_fix_hidden_state(gc);
|
||||
|
||||
if (gc->hidden)
|
||||
_group_show(gc);
|
||||
group_show(sc, gc);
|
||||
else {
|
||||
_group_hide(gc);
|
||||
group_hide(sc, gc);
|
||||
/* XXX wtf? */
|
||||
if (TAILQ_EMPTY(&gc->clients))
|
||||
Group_active = gc;
|
||||
group_setactive(sc, idx);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
group_only(struct screen_ctx *sc, int idx)
|
||||
{
|
||||
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++) {
|
||||
if (i == idx)
|
||||
group_show(sc, &sc->groups[i]);
|
||||
else
|
||||
group_hide(sc, &sc->groups[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,37 +319,37 @@ group_hidetoggle(int idx)
|
||||
* Cycle through active groups. If none exist, then just stay put.
|
||||
*/
|
||||
void
|
||||
group_cycle(int reverse)
|
||||
group_cycle(struct screen_ctx *sc, int flags)
|
||||
{
|
||||
struct group_ctx *gc, *showgroup = NULL;
|
||||
|
||||
assert(Group_active != NULL);
|
||||
assert(sc->group_active != NULL);
|
||||
|
||||
gc = Group_active;
|
||||
gc = sc->group_active;
|
||||
for (;;) {
|
||||
gc = reverse ? TAILQ_PREV(gc, group_ctx_q, entry) :
|
||||
TAILQ_NEXT(gc, entry);
|
||||
gc = (flags & CWM_RCYCLE) ? TAILQ_PREV(gc, group_ctx_q,
|
||||
entry) : TAILQ_NEXT(gc, entry);
|
||||
if (gc == NULL)
|
||||
gc = reverse ? TAILQ_LAST(&Groupq, group_ctx_q) :
|
||||
TAILQ_FIRST(&Groupq);
|
||||
if (gc == Group_active)
|
||||
gc = (flags & CWM_RCYCLE) ? TAILQ_LAST(&sc->groupq,
|
||||
group_ctx_q) : TAILQ_FIRST(&sc->groupq);
|
||||
if (gc == sc->group_active)
|
||||
break;
|
||||
|
||||
if (!TAILQ_EMPTY(&gc->clients) && showgroup == NULL)
|
||||
showgroup = gc;
|
||||
else if (!gc->hidden)
|
||||
_group_hide(gc);
|
||||
group_hide(sc, gc);
|
||||
}
|
||||
|
||||
if (showgroup == NULL)
|
||||
return;
|
||||
|
||||
_group_hide(Group_active);
|
||||
group_hide(sc, sc->group_active);
|
||||
|
||||
if (showgroup->hidden)
|
||||
_group_show(showgroup);
|
||||
group_show(sc, showgroup);
|
||||
else
|
||||
Group_active = showgroup;
|
||||
group_setactive(sc, showgroup->shortcut - 1);
|
||||
}
|
||||
|
||||
/* called when a client is deleted */
|
||||
@ -248,26 +366,28 @@ group_client_delete(struct client_ctx *cc)
|
||||
void
|
||||
group_menu(XButtonEvent *e)
|
||||
{
|
||||
struct screen_ctx *sc;
|
||||
struct group_ctx *gc;
|
||||
struct menu *mi;
|
||||
struct menu_q menuq;
|
||||
int i;
|
||||
|
||||
sc = screen_fromroot(e->root);
|
||||
TAILQ_INIT(&menuq);
|
||||
|
||||
for (i = 0; i < CALMWM_NGROUPS; i++) {
|
||||
gc = &Groups[i];
|
||||
gc = &sc->groups[i];
|
||||
|
||||
if (TAILQ_EMPTY(&gc->clients))
|
||||
continue;
|
||||
|
||||
XCALLOC(mi, struct menu);
|
||||
mi = xcalloc(1, sizeof(*mi));
|
||||
if (gc->hidden)
|
||||
snprintf(mi->text, sizeof(mi->text), "%d: [%s]",
|
||||
gc->shortcut, shortcut_to_name[gc->shortcut]);
|
||||
(void)snprintf(mi->text, sizeof(mi->text), "%d: [%s]",
|
||||
gc->shortcut, sc->group_names[i]);
|
||||
else
|
||||
snprintf(mi->text, sizeof(mi->text), "%d: %s",
|
||||
gc->shortcut, shortcut_to_name[gc->shortcut]);
|
||||
(void)snprintf(mi->text, sizeof(mi->text), "%d: %s",
|
||||
gc->shortcut, sc->group_names[i]);
|
||||
mi->ctx = gc;
|
||||
TAILQ_INSERT_TAIL(&menuq, mi, entry);
|
||||
}
|
||||
@ -275,17 +395,14 @@ group_menu(XButtonEvent *e)
|
||||
if (TAILQ_EMPTY(&menuq))
|
||||
return;
|
||||
|
||||
mi = menu_filter(&menuq, NULL, NULL, 0, NULL, NULL);
|
||||
mi = menu_filter(sc, &menuq, NULL, NULL, 0, NULL, NULL);
|
||||
|
||||
if (mi == NULL || mi->ctx == NULL)
|
||||
goto cleanup;
|
||||
|
||||
gc = (struct group_ctx *)mi->ctx;
|
||||
|
||||
if (gc->hidden)
|
||||
_group_show(gc);
|
||||
else
|
||||
_group_hide(gc);
|
||||
(gc->hidden) ? group_show(sc, gc) : group_hide(sc, gc);
|
||||
|
||||
cleanup:
|
||||
while ((mi = TAILQ_FIRST(&menuq)) != NULL) {
|
||||
@ -295,52 +412,138 @@ cleanup:
|
||||
}
|
||||
|
||||
void
|
||||
group_alltoggle(void)
|
||||
group_alltoggle(struct screen_ctx *sc)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < CALMWM_NGROUPS; i++) {
|
||||
if (Grouphideall)
|
||||
_group_show(&Groups[i]);
|
||||
if (sc->group_hideall)
|
||||
group_show(sc, &sc->groups[i]);
|
||||
else
|
||||
_group_hide(&Groups[i]);
|
||||
group_hide(sc, &sc->groups[i]);
|
||||
}
|
||||
|
||||
if (Grouphideall)
|
||||
Grouphideall = 0;
|
||||
else
|
||||
Grouphideall = 1;
|
||||
sc->group_hideall = (!sc->group_hideall);
|
||||
}
|
||||
|
||||
void
|
||||
group_autogroup(struct client_ctx *cc)
|
||||
{
|
||||
struct screen_ctx *sc = cc->sc;
|
||||
struct autogroupwin *aw;
|
||||
struct group_ctx *gc;
|
||||
char group[CALMWM_MAXNAMELEN];
|
||||
int no = -1;
|
||||
long *grpno;
|
||||
|
||||
if (cc->app_class == NULL || cc->app_name == NULL)
|
||||
return;
|
||||
|
||||
TAILQ_FOREACH(aw, &Conf.autogroupq, entry) {
|
||||
if (strcmp(aw->class, cc->app_class) == 0 &&
|
||||
(aw->name == NULL || strcmp(aw->name, cc->app_name) == 0)) {
|
||||
strlcpy(group, aw->group, sizeof(group));
|
||||
break;
|
||||
if (xu_getprop(cc->win, _NET_WM_DESKTOP, XA_CARDINAL,
|
||||
1, (unsigned char **)&grpno) > 0) {
|
||||
if (*grpno == 0xffffffff)
|
||||
no = 0;
|
||||
else if (*grpno > CALMWM_NGROUPS || *grpno < 0)
|
||||
no = CALMWM_NGROUPS - 1;
|
||||
else
|
||||
no = *grpno + 1;
|
||||
XFree(grpno);
|
||||
} else {
|
||||
TAILQ_FOREACH(aw, &Conf.autogroupq, entry) {
|
||||
if (strcmp(aw->class, cc->app_class) == 0 &&
|
||||
(aw->name == NULL ||
|
||||
strcmp(aw->name, cc->app_name) == 0)) {
|
||||
no = aw->num;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (strncmp("nogroup", group, 7) == 0)
|
||||
/* no group please */
|
||||
if (no == 0)
|
||||
return;
|
||||
|
||||
TAILQ_FOREACH(gc, &Groupq, entry) {
|
||||
if (strcmp(shortcut_to_name[gc->shortcut], group) == 0) {
|
||||
_group_add(gc, cc);
|
||||
TAILQ_FOREACH(gc, &sc->groupq, entry) {
|
||||
if (gc->shortcut == no) {
|
||||
group_add(gc, cc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (Conf.flags & CONF_STICKY_GROUPS)
|
||||
_group_add(Group_active, cc);
|
||||
|
||||
group_add(sc->group_active, cc);
|
||||
}
|
||||
|
||||
void
|
||||
group_update_names(struct screen_ctx *sc)
|
||||
{
|
||||
char **strings, *p;
|
||||
unsigned char *prop_ret;
|
||||
Atom type_ret;
|
||||
int format_ret, i = 0, nstrings = 0, n, setnames = 0;
|
||||
unsigned long bytes_after, num_ret;
|
||||
|
||||
if (XGetWindowProperty(X_Dpy, sc->rootwin, _NET_DESKTOP_NAMES, 0,
|
||||
0xffffff, False, UTF8_STRING, &type_ret, &format_ret,
|
||||
&num_ret, &bytes_after, &prop_ret) == Success &&
|
||||
prop_ret != NULL && format_ret == 8) {
|
||||
/* failure, just set defaults */
|
||||
prop_ret[num_ret - 1] = '\0'; /* paranoia */
|
||||
while (i < num_ret) {
|
||||
if (prop_ret[i++] == '\0')
|
||||
nstrings++;
|
||||
}
|
||||
}
|
||||
|
||||
strings = xmalloc((nstrings < CALMWM_NGROUPS ? CALMWM_NGROUPS :
|
||||
nstrings) * sizeof(*strings));
|
||||
|
||||
i = n = 0;
|
||||
p = prop_ret;
|
||||
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;
|
||||
i = 1;
|
||||
while (n < CALMWM_NGROUPS)
|
||||
strings[n++] = xstrdup(shortcut_to_name[i++]);
|
||||
}
|
||||
|
||||
if (prop_ret != NULL)
|
||||
XFree(prop_ret);
|
||||
if (sc->group_nonames != 0)
|
||||
xfree(sc->group_names);
|
||||
|
||||
sc->group_names = strings;
|
||||
sc->group_nonames = n;
|
||||
if (setnames)
|
||||
group_set_names(sc);
|
||||
}
|
||||
|
||||
static void
|
||||
group_set_names(struct screen_ctx *sc)
|
||||
{
|
||||
unsigned char *p, *q;
|
||||
size_t len = 0, tlen, slen;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sc->group_nonames; i++)
|
||||
len += strlen(sc->group_names[i]) + 1;
|
||||
q = p = xcalloc(len, sizeof(*p));
|
||||
|
||||
tlen = len;
|
||||
for (i = 0; i < sc->group_nonames; i++) {
|
||||
slen = strlen(sc->group_names[i]) + 1;
|
||||
(void)strlcpy(q, sc->group_names[i], tlen);
|
||||
tlen -= slen;
|
||||
q += slen;
|
||||
}
|
||||
|
||||
XChangeProperty(X_Dpy, sc->rootwin, _NET_DESKTOP_NAMES,
|
||||
UTF8_STRING, 8, PropModeReplace, p, len);
|
||||
}
|
||||
|
55
headers.h
55
headers.h
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* calmwm - the calm window manager
|
||||
*
|
||||
* Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef _CALMWM_HEADERS_H_
|
||||
#define _CALMWM_HEADERS_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <sys/queue.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <dirent.h>
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <X11/cursorfont.h>
|
||||
#include <X11/extensions/shape.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xproto.h>
|
||||
#include <X11/Intrinsic.h>
|
||||
#include <X11/Xos.h>
|
||||
#include <X11/Xft/Xft.h>
|
||||
|
||||
#include <err.h>
|
||||
|
||||
#endif /* _CALMWM_HEADERS_H_ */
|
111
input.c
111
input.c
@ -1,111 +0,0 @@
|
||||
/*
|
||||
* calmwm - the calm window manager
|
||||
*
|
||||
* Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include "headers.h"
|
||||
#include "calmwm.h"
|
||||
|
||||
int
|
||||
input_keycodetrans(KeyCode kc, u_int state, enum ctltype *ctl, char *chr)
|
||||
{
|
||||
int ks;
|
||||
|
||||
*ctl = CTL_NONE;
|
||||
*chr = '\0';
|
||||
|
||||
if (state & ShiftMask)
|
||||
ks = XKeycodeToKeysym(X_Dpy, kc, 1);
|
||||
else
|
||||
ks = XKeycodeToKeysym(X_Dpy, kc, 0);
|
||||
|
||||
/* Look for control characters. */
|
||||
switch (ks) {
|
||||
case XK_BackSpace:
|
||||
*ctl = CTL_ERASEONE;
|
||||
break;
|
||||
case XK_Return:
|
||||
*ctl = CTL_RETURN;
|
||||
break;
|
||||
case XK_Up:
|
||||
*ctl = CTL_UP;
|
||||
break;
|
||||
case XK_Down:
|
||||
*ctl = CTL_DOWN;
|
||||
break;
|
||||
case XK_Escape:
|
||||
*ctl = CTL_ABORT;
|
||||
break;
|
||||
}
|
||||
|
||||
if (*ctl == CTL_NONE && (state & ControlMask)) {
|
||||
switch (ks) {
|
||||
case XK_s:
|
||||
case XK_S:
|
||||
/* Emacs "next" */
|
||||
*ctl = CTL_DOWN;
|
||||
break;
|
||||
case XK_r:
|
||||
case XK_R:
|
||||
/* Emacs "previous" */
|
||||
*ctl = CTL_UP;
|
||||
break;
|
||||
case XK_u:
|
||||
case XK_U:
|
||||
*ctl = CTL_WIPE;
|
||||
break;
|
||||
case XK_h:
|
||||
case XK_H:
|
||||
*ctl = CTL_ERASEONE;
|
||||
break;
|
||||
case XK_a:
|
||||
case XK_A:
|
||||
*ctl = CTL_ALL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (*ctl == CTL_NONE && (state & Mod1Mask)) {
|
||||
switch (ks) {
|
||||
case XK_j:
|
||||
case XK_J:
|
||||
/* Vi "down" */
|
||||
*ctl = CTL_DOWN;
|
||||
break;
|
||||
case XK_k:
|
||||
case XK_K:
|
||||
/* Vi "up" */
|
||||
*ctl = CTL_UP;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (*ctl != CTL_NONE)
|
||||
return (0);
|
||||
|
||||
/*
|
||||
* For regular characters, only (part of, actually) Latin 1
|
||||
* for now.
|
||||
*/
|
||||
if (ks < 0x20 || ks > 0x07e)
|
||||
return (-1);
|
||||
|
||||
*chr = (char)ks;
|
||||
|
||||
return (0);
|
||||
}
|
289
kbfunc.c
289
kbfunc.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* calmwm - the calm window manager
|
||||
* calmwm - the calm window manager
|
||||
*
|
||||
* Copyright (c) 2004 Martin Murray <mmurray@monkey.org>
|
||||
* Copyright (c) 2004 Martin Murray <mmurray@monkey.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@ -15,53 +15,65 @@
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* $Id$
|
||||
* $OpenBSD$
|
||||
*/
|
||||
|
||||
#include <paths.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <paths.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "headers.h"
|
||||
#include "calmwm.h"
|
||||
|
||||
#define KNOWN_HOSTS ".ssh/known_hosts"
|
||||
#define HASH_MARKER "|1|"
|
||||
#define MOVE_AMOUNT 1
|
||||
|
||||
extern int _xev_quit;
|
||||
extern sig_atomic_t xev_quit;
|
||||
|
||||
void
|
||||
kbfunc_client_lower(struct client_ctx *cc, void *arg)
|
||||
kbfunc_client_lower(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
client_lower(cc);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_client_raise(struct client_ctx *cc, void *arg)
|
||||
kbfunc_client_raise(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
client_raise(cc);
|
||||
}
|
||||
|
||||
#define typemask (CWM_MOVE | CWM_RESIZE | CWM_PTRMOVE)
|
||||
#define movemask (CWM_UP | CWM_DOWN | CWM_LEFT | CWM_RIGHT)
|
||||
#define TYPEMASK (CWM_MOVE | CWM_RESIZE | CWM_PTRMOVE)
|
||||
#define MOVEMASK (CWM_UP | CWM_DOWN | CWM_LEFT | CWM_RIGHT)
|
||||
void
|
||||
kbfunc_moveresize(struct client_ctx *cc, void *arg)
|
||||
kbfunc_moveresize(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
struct screen_ctx *sc;
|
||||
int x, y, flags, amt;
|
||||
u_int mx, my;
|
||||
|
||||
sc = screen_current();
|
||||
if (cc->flags & CLIENT_FREEZE)
|
||||
return;
|
||||
|
||||
sc = cc->sc;
|
||||
mx = my = 0;
|
||||
|
||||
flags = (int)arg;
|
||||
amt = MOVE_AMOUNT;
|
||||
flags = arg->i;
|
||||
amt = Conf.mamount;
|
||||
|
||||
if (flags & CWM_BIGMOVE) {
|
||||
flags -= CWM_BIGMOVE;
|
||||
amt = amt * 10;
|
||||
}
|
||||
|
||||
switch (flags & movemask) {
|
||||
switch (flags & MOVEMASK) {
|
||||
case CWM_UP:
|
||||
my -= amt;
|
||||
break;
|
||||
@ -75,22 +87,29 @@ kbfunc_moveresize(struct client_ctx *cc, void *arg)
|
||||
mx -= amt;
|
||||
break;
|
||||
}
|
||||
switch (flags & typemask) {
|
||||
switch (flags & TYPEMASK) {
|
||||
case CWM_MOVE:
|
||||
cc->geom.y += my;
|
||||
if (cc->geom.y + cc->geom.height < 0)
|
||||
cc->geom.y = -cc->geom.height;
|
||||
if (cc->geom.y > cc->sc->ymax)
|
||||
cc->geom.y = cc->sc->ymax;
|
||||
if (cc->geom.y > cc->sc->ymax - 1)
|
||||
cc->geom.y = cc->sc->ymax - 1;
|
||||
|
||||
cc->geom.x += mx;
|
||||
if (cc->geom.x + cc->geom.width < 0)
|
||||
cc->geom.x = -cc->geom.width;
|
||||
if (cc->geom.x > cc->sc->xmax)
|
||||
cc->geom.x = cc->sc->xmax;
|
||||
if (cc->geom.x > cc->sc->xmax - 1)
|
||||
cc->geom.x = cc->sc->xmax - 1;
|
||||
|
||||
cc->geom.x += client_snapcalc(cc->geom.x,
|
||||
cc->geom.width, cc->sc->xmax,
|
||||
cc->bwidth, Conf.snapdist);
|
||||
cc->geom.y += client_snapcalc(cc->geom.y,
|
||||
cc->geom.height, cc->sc->ymax,
|
||||
cc->bwidth, Conf.snapdist);
|
||||
|
||||
client_move(cc);
|
||||
xu_ptr_getpos(cc->pwin, &x, &y);
|
||||
xu_ptr_getpos(cc->win, &x, &y);
|
||||
cc->ptr.y = y + my;
|
||||
cc->ptr.x = x + mx;
|
||||
client_ptrwarp(cc);
|
||||
@ -103,7 +122,7 @@ kbfunc_moveresize(struct client_ctx *cc, void *arg)
|
||||
client_resize(cc);
|
||||
|
||||
/* Make sure the pointer stays within the window. */
|
||||
xu_ptr_getpos(cc->pwin, &cc->ptr.x, &cc->ptr.y);
|
||||
xu_ptr_getpos(cc->win, &cc->ptr.x, &cc->ptr.y);
|
||||
if (cc->ptr.x > cc->geom.width)
|
||||
cc->ptr.x = cc->geom.width - cc->bwidth;
|
||||
if (cc->ptr.y > cc->geom.height)
|
||||
@ -111,13 +130,8 @@ kbfunc_moveresize(struct client_ctx *cc, void *arg)
|
||||
client_ptrwarp(cc);
|
||||
break;
|
||||
case CWM_PTRMOVE:
|
||||
if (cc) {
|
||||
xu_ptr_getpos(cc->pwin, &x, &y);
|
||||
xu_ptr_setpos(cc->pwin, x + mx, y + my);
|
||||
} else {
|
||||
xu_ptr_getpos(sc->rootwin, &x, &y);
|
||||
xu_ptr_setpos(sc->rootwin, x + mx, y + my);
|
||||
}
|
||||
xu_ptr_getpos(sc->rootwin, &x, &y);
|
||||
xu_ptr_setpos(sc->rootwin, x + mx, y + my);
|
||||
break;
|
||||
default:
|
||||
warnx("invalid flags passed to kbfunc_client_moveresize");
|
||||
@ -125,24 +139,26 @@ kbfunc_moveresize(struct client_ctx *cc, void *arg)
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_client_search(struct client_ctx *scratch, void *arg)
|
||||
kbfunc_client_search(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
struct client_ctx *cc, *old_cc;
|
||||
struct screen_ctx *sc;
|
||||
struct client_ctx *old_cc;
|
||||
struct menu *mi;
|
||||
struct menu_q menuq;
|
||||
|
||||
sc = cc->sc;
|
||||
old_cc = client_current();
|
||||
|
||||
TAILQ_INIT(&menuq);
|
||||
|
||||
TAILQ_FOREACH(cc, &Clientq, entry) {
|
||||
XCALLOC(mi, struct menu);
|
||||
strlcpy(mi->text, cc->name, sizeof(mi->text));
|
||||
mi = xcalloc(1, sizeof(*mi));
|
||||
(void)strlcpy(mi->text, cc->name, sizeof(mi->text));
|
||||
mi->ctx = cc;
|
||||
TAILQ_INSERT_TAIL(&menuq, mi, entry);
|
||||
}
|
||||
|
||||
if ((mi = menu_filter(&menuq, "window", NULL, 0,
|
||||
if ((mi = menu_filter(sc, &menuq, "window", NULL, 0,
|
||||
search_match_client, search_print_client)) != NULL) {
|
||||
cc = (struct client_ctx *)mi->ctx;
|
||||
if (cc->flags & CLIENT_HIDDEN)
|
||||
@ -160,22 +176,24 @@ kbfunc_client_search(struct client_ctx *scratch, void *arg)
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_menu_search(struct client_ctx *scratch, void *arg)
|
||||
kbfunc_menu_search(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
struct menu *mi;
|
||||
struct menu_q menuq;
|
||||
struct screen_ctx *sc;
|
||||
struct cmd *cmd;
|
||||
struct menu *mi;
|
||||
struct menu_q menuq;
|
||||
|
||||
sc = cc->sc;
|
||||
TAILQ_INIT(&menuq);
|
||||
|
||||
TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
|
||||
XCALLOC(mi, struct menu);
|
||||
strlcpy(mi->text, cmd->label, sizeof(mi->text));
|
||||
mi = xcalloc(1, sizeof(*mi));
|
||||
(void)strlcpy(mi->text, cmd->label, sizeof(mi->text));
|
||||
mi->ctx = cmd;
|
||||
TAILQ_INSERT_TAIL(&menuq, mi, entry);
|
||||
}
|
||||
|
||||
if ((mi = menu_filter(&menuq, "application", NULL, 0,
|
||||
if ((mi = menu_filter(sc, &menuq, "application", NULL, 0,
|
||||
search_match_text, NULL)) != NULL)
|
||||
u_spawn(((struct cmd *)mi->ctx)->image);
|
||||
|
||||
@ -186,59 +204,57 @@ kbfunc_menu_search(struct client_ctx *scratch, void *arg)
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_client_cycle(struct client_ctx *scratch, void *arg)
|
||||
kbfunc_client_cycle(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
struct screen_ctx *sc;
|
||||
|
||||
sc = screen_current();
|
||||
sc = cc->sc;
|
||||
|
||||
/* XXX for X apps that ignore events */
|
||||
XGrabKeyboard(X_Dpy, sc->rootwin, True,
|
||||
GrabModeAsync, GrabModeAsync, CurrentTime);
|
||||
|
||||
client_cycle((int)arg);
|
||||
client_cycle(sc, arg->i);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_client_hide(struct client_ctx *cc, void *arg)
|
||||
kbfunc_client_hide(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
client_hide(cc);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_cmdexec(struct client_ctx *cc, void *arg)
|
||||
kbfunc_cmdexec(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
u_spawn((char *)arg);
|
||||
u_spawn(arg->c);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_term(struct client_ctx *cc, void *arg)
|
||||
kbfunc_term(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
u_spawn(Conf.termpath);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_lock(struct client_ctx *cc, void *arg)
|
||||
kbfunc_lock(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
u_spawn(Conf.lockpath);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_exec(struct client_ctx *scratch, void *arg)
|
||||
kbfunc_exec(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
#define NPATHS 256
|
||||
char **ap, *paths[NPATHS], *path, *pathcpy, *label;
|
||||
char tpath[MAXPATHLEN];
|
||||
int l, i, j, ngroups;
|
||||
gid_t mygroups[NGROUPS_MAX];
|
||||
uid_t ruid, euid, suid;
|
||||
DIR *dirp;
|
||||
struct dirent *dp;
|
||||
struct menu *mi;
|
||||
struct menu_q menuq;
|
||||
struct stat sb;
|
||||
struct screen_ctx *sc;
|
||||
char **ap, *paths[NPATHS], *path, *pathcpy, *label;
|
||||
char tpath[MAXPATHLEN];
|
||||
DIR *dirp;
|
||||
struct dirent *dp;
|
||||
struct menu *mi;
|
||||
struct menu_q menuq;
|
||||
int l, i, cmd = arg->i;
|
||||
|
||||
int cmd = (int)arg;
|
||||
sc = cc->sc;
|
||||
switch (cmd) {
|
||||
case CWM_EXEC_PROGRAM:
|
||||
label = "exec";
|
||||
@ -251,11 +267,6 @@ kbfunc_exec(struct client_ctx *scratch, void *arg)
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
if (getgroups(0, mygroups) == -1)
|
||||
err(1, "getgroups failure");
|
||||
if ((ngroups = getresuid(&ruid, &euid, &suid)) == -1)
|
||||
err(1, "getresuid failure");
|
||||
|
||||
TAILQ_INIT(&menuq);
|
||||
|
||||
if ((path = getenv("PATH")) == NULL)
|
||||
@ -276,45 +287,27 @@ kbfunc_exec(struct client_ctx *scratch, void *arg)
|
||||
/* skip everything but regular files and symlinks */
|
||||
if (dp->d_type != DT_REG && dp->d_type != DT_LNK)
|
||||
continue;
|
||||
memset(tpath, '\0', sizeof(tpath));
|
||||
(void)memset(tpath, '\0', sizeof(tpath));
|
||||
l = snprintf(tpath, sizeof(tpath), "%s/%s", paths[i],
|
||||
dp->d_name);
|
||||
/* check for truncation etc */
|
||||
if (l == -1 || l >= (int)sizeof(tpath))
|
||||
continue;
|
||||
/* just ignore on stat failure */
|
||||
if (stat(tpath, &sb) == -1)
|
||||
continue;
|
||||
/* may we execute this file? */
|
||||
if (euid == sb.st_uid) {
|
||||
if (sb.st_mode & S_IXUSR)
|
||||
goto executable;
|
||||
else
|
||||
continue;
|
||||
if (access(tpath, X_OK) == 0) {
|
||||
mi = xcalloc(1, sizeof(*mi));
|
||||
(void)strlcpy(mi->text,
|
||||
dp->d_name, sizeof(mi->text));
|
||||
TAILQ_INSERT_TAIL(&menuq, mi, entry);
|
||||
}
|
||||
for (j = 0; j < ngroups; j++) {
|
||||
if (mygroups[j] == sb.st_gid) {
|
||||
if (sb.st_mode & S_IXGRP)
|
||||
goto executable;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (sb.st_mode & S_IXOTH)
|
||||
goto executable;
|
||||
continue;
|
||||
executable:
|
||||
/* the thing in tpath, we may execute */
|
||||
XCALLOC(mi, struct menu);
|
||||
strlcpy(mi->text, dp->d_name, sizeof(mi->text));
|
||||
TAILQ_INSERT_TAIL(&menuq, mi, entry);
|
||||
}
|
||||
(void)closedir(dirp);
|
||||
}
|
||||
xfree(path);
|
||||
|
||||
if ((mi = menu_filter(&menuq, label, NULL, 1,
|
||||
if ((mi = menu_filter(sc, &menuq, label, NULL, 1,
|
||||
search_match_exec, NULL)) != NULL) {
|
||||
if (mi->text[0] == '\0')
|
||||
goto out;
|
||||
switch (cmd) {
|
||||
case CWM_EXEC_PROGRAM:
|
||||
u_spawn(mi->text);
|
||||
@ -328,7 +321,7 @@ kbfunc_exec(struct client_ctx *scratch, void *arg)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
if (mi != NULL && mi->dummy)
|
||||
xfree(mi);
|
||||
while ((mi = TAILQ_FIRST(&menuq)) != NULL) {
|
||||
@ -338,16 +331,19 @@ kbfunc_exec(struct client_ctx *scratch, void *arg)
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_ssh(struct client_ctx *scratch, void *arg)
|
||||
kbfunc_ssh(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
struct menu *mi;
|
||||
struct menu_q menuq;
|
||||
FILE *fp;
|
||||
char *buf, *lbuf, *p, *home;
|
||||
char hostbuf[MAXHOSTNAMELEN], filename[MAXPATHLEN];
|
||||
char cmd[256];
|
||||
int l;
|
||||
size_t len;
|
||||
struct screen_ctx *sc;
|
||||
struct menu *mi;
|
||||
struct menu_q menuq;
|
||||
FILE *fp;
|
||||
char *buf, *lbuf, *p, *home;
|
||||
char hostbuf[MAXHOSTNAMELEN], filename[MAXPATHLEN];
|
||||
char cmd[256];
|
||||
int l;
|
||||
size_t len;
|
||||
|
||||
sc = cc->sc;
|
||||
|
||||
if ((home = getenv("HOME")) == NULL)
|
||||
return;
|
||||
@ -367,7 +363,7 @@ kbfunc_ssh(struct client_ctx *scratch, void *arg)
|
||||
else {
|
||||
/* EOF without EOL, copy and add the NUL */
|
||||
lbuf = xmalloc(len + 1);
|
||||
memcpy(lbuf, buf, len);
|
||||
(void)memcpy(lbuf, buf, len);
|
||||
lbuf[len] = '\0';
|
||||
buf = lbuf;
|
||||
}
|
||||
@ -380,22 +376,24 @@ kbfunc_ssh(struct client_ctx *scratch, void *arg)
|
||||
/* ignore badness */
|
||||
if (p - buf + 1 > sizeof(hostbuf))
|
||||
continue;
|
||||
(void) strlcpy(hostbuf, buf, p - buf + 1);
|
||||
XCALLOC(mi, struct menu);
|
||||
(void) strlcpy(mi->text, hostbuf, sizeof(mi->text));
|
||||
(void)strlcpy(hostbuf, buf, p - buf + 1);
|
||||
mi = xcalloc(1, sizeof(*mi));
|
||||
(void)strlcpy(mi->text, hostbuf, sizeof(mi->text));
|
||||
TAILQ_INSERT_TAIL(&menuq, mi, entry);
|
||||
}
|
||||
xfree(lbuf);
|
||||
fclose(fp);
|
||||
(void)fclose(fp);
|
||||
|
||||
if ((mi = menu_filter(&menuq, "ssh", NULL, 1,
|
||||
if ((mi = menu_filter(sc, &menuq, "ssh", NULL, 1,
|
||||
search_match_exec, NULL)) != NULL) {
|
||||
if (mi->text[0] == '\0')
|
||||
goto out;
|
||||
l = snprintf(cmd, sizeof(cmd), "%s -e ssh %s", Conf.termpath,
|
||||
mi->text);
|
||||
if (l != -1 && l < sizeof(cmd))
|
||||
u_spawn(cmd);
|
||||
}
|
||||
|
||||
out:
|
||||
if (mi != NULL && mi->dummy)
|
||||
xfree(mi);
|
||||
while ((mi = TAILQ_FIRST(&menuq)) != NULL) {
|
||||
@ -405,82 +403,103 @@ kbfunc_ssh(struct client_ctx *scratch, void *arg)
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_client_label(struct client_ctx *cc, void *arg)
|
||||
kbfunc_client_label(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
struct menu *mi;
|
||||
struct menu_q menuq;
|
||||
char *current;
|
||||
|
||||
TAILQ_INIT(&menuq);
|
||||
|
||||
if (cc->label != NULL)
|
||||
current = cc->label;
|
||||
else
|
||||
current = NULL;
|
||||
|
||||
if ((mi = menu_filter(&menuq, "label", current, 1,
|
||||
search_match_text, NULL)) != NULL) {
|
||||
/* dummy is set, so this will always return */
|
||||
mi = menu_filter(cc->sc, &menuq, "label", cc->label, 1,
|
||||
search_match_text, NULL);
|
||||
|
||||
if (!mi->abort) {
|
||||
if (cc->label != NULL)
|
||||
xfree(cc->label);
|
||||
cc->label = xstrdup(mi->text);
|
||||
xfree(mi);
|
||||
}
|
||||
xfree(mi);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_client_delete(struct client_ctx *cc, void *arg)
|
||||
kbfunc_client_delete(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
client_send_delete(cc);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_client_group(struct client_ctx *cc, void *arg)
|
||||
kbfunc_client_group(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
group_hidetoggle(KBTOGROUP((int)arg));
|
||||
group_hidetoggle(cc->sc, KBTOGROUP(arg->i));
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_client_cyclegroup(struct client_ctx *cc, void *arg)
|
||||
kbfunc_client_grouponly(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
group_cycle((int)arg);
|
||||
group_only(cc->sc, KBTOGROUP(arg->i));
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_client_nogroup(struct client_ctx *cc, void *arg)
|
||||
kbfunc_client_cyclegroup(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
group_alltoggle();
|
||||
group_cycle(cc->sc, arg->i);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_client_grouptoggle(struct client_ctx *cc, void *arg)
|
||||
kbfunc_client_nogroup(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
group_alltoggle(cc->sc);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_client_grouptoggle(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
/* XXX for stupid X apps like xpdf and gvim */
|
||||
XGrabKeyboard(X_Dpy, cc->pwin, True,
|
||||
XGrabKeyboard(X_Dpy, cc->win, True,
|
||||
GrabModeAsync, GrabModeAsync, CurrentTime);
|
||||
|
||||
group_sticky_toggle_enter(cc);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_client_maximize(struct client_ctx *cc, void *arg)
|
||||
kbfunc_client_movetogroup(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
group_movetogroup(cc, KBTOGROUP(arg->i));
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_client_maximize(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
client_maximize(cc);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_client_vmaximize(struct client_ctx *cc, void *arg)
|
||||
kbfunc_client_vmaximize(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
client_vertmaximize(cc);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_quit_wm(struct client_ctx *cc, void *arg)
|
||||
kbfunc_client_hmaximize(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
_xev_quit = 1;
|
||||
client_horizmaximize(cc);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_reload(struct client_ctx *cc, void *arg)
|
||||
kbfunc_client_freeze(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
client_freeze(cc);
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_quit_wm(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
xev_quit = 1;
|
||||
}
|
||||
|
||||
void
|
||||
kbfunc_reload(struct client_ctx *cc, union arg *arg)
|
||||
{
|
||||
conf_reload(&Conf);
|
||||
}
|
||||
|
282
menu.c
282
menu.c
@ -1,4 +1,6 @@
|
||||
/*
|
||||
* calmwm - the calm window manager
|
||||
*
|
||||
* Copyright (c) 2008 Owain G. Ainsworth <oga@openbsd.org>
|
||||
* Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>
|
||||
*
|
||||
@ -13,18 +15,30 @@
|
||||
* 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 "headers.h"
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "calmwm.h"
|
||||
|
||||
#define KeyMask (KeyPressMask|ExposureMask)
|
||||
#define MenuMask (ButtonMask|ButtonMotionMask|ExposureMask| \
|
||||
PointerMotionMask)
|
||||
#define MenuGrabMask (ButtonMask|ButtonMotionMask|StructureNotifyMask|\
|
||||
PointerMotionMask)
|
||||
#define PROMPT_SCHAR '<27>'
|
||||
#define PROMPT_ECHAR '<27>'
|
||||
#define PROMPT_SCHAR "\xc2\xbb"
|
||||
#define PROMPT_ECHAR "\xc2\xab"
|
||||
|
||||
enum ctltype {
|
||||
CTL_NONE = -1,
|
||||
CTL_ERASEONE = 0, CTL_WIPE, CTL_UP, CTL_DOWN, CTL_RETURN,
|
||||
CTL_ABORT, CTL_ALL
|
||||
};
|
||||
|
||||
struct menu_ctx {
|
||||
char searchstr[MENU_MAXENTRY + 1];
|
||||
@ -48,34 +62,51 @@ static struct menu *menu_handle_key(XEvent *, struct menu_ctx *,
|
||||
struct menu_q *, struct menu_q *);
|
||||
static void menu_handle_move(XEvent *, struct menu_ctx *,
|
||||
struct screen_ctx *);
|
||||
struct menu *menu_handle_release(XEvent *, struct menu_ctx *,
|
||||
static struct menu *menu_handle_release(XEvent *, struct menu_ctx *,
|
||||
struct screen_ctx *, struct menu_q *);
|
||||
static void menu_draw(struct screen_ctx *, struct menu_ctx *,
|
||||
struct menu_q *, struct menu_q *);
|
||||
static int menu_calc_entry(struct screen_ctx *, struct menu_ctx *,
|
||||
int, int);
|
||||
static int menu_keycode(KeyCode, u_int, enum ctltype *,
|
||||
char *);
|
||||
|
||||
void
|
||||
menu_init(struct screen_ctx *sc)
|
||||
{
|
||||
sc->menuwin = XCreateSimpleWindow(X_Dpy, sc->rootwin, 0, 0,
|
||||
1, 1, 1, sc->blackpixl, sc->whitepixl);
|
||||
XGCValues gv;
|
||||
|
||||
if (sc->menuwin)
|
||||
XDestroyWindow(X_Dpy, sc->menuwin);
|
||||
sc->menuwin = XCreateSimpleWindow(X_Dpy, sc->rootwin, 0, 0, 1, 1,
|
||||
Conf.bwidth,
|
||||
sc->color[CWM_COLOR_FG_MENU].pixel,
|
||||
sc->color[CWM_COLOR_BG_MENU].pixel);
|
||||
|
||||
gv.foreground =
|
||||
sc->color[CWM_COLOR_FG_MENU].pixel^sc->color[CWM_COLOR_BG_MENU].pixel;
|
||||
gv.background = sc->color[CWM_COLOR_BG_MENU].pixel;
|
||||
gv.function = GXxor;
|
||||
|
||||
if (sc->gc)
|
||||
XFreeGC(X_Dpy, sc->gc);
|
||||
sc->gc = XCreateGC(X_Dpy, sc->menuwin,
|
||||
GCForeground|GCBackground|GCFunction, &gv);
|
||||
}
|
||||
|
||||
struct menu *
|
||||
menu_filter(struct menu_q *menuq, char *prompt, char *initial, int dummy,
|
||||
menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt,
|
||||
char *initial, int dummy,
|
||||
void (*match)(struct menu_q *, struct menu_q *, char *),
|
||||
void (*print)(struct menu *, int))
|
||||
{
|
||||
struct screen_ctx *sc;
|
||||
struct menu_ctx mc;
|
||||
struct menu_q resultq;
|
||||
struct menu *mi = NULL;
|
||||
XEvent e;
|
||||
Window focuswin;
|
||||
int Mask, focusrevert;
|
||||
|
||||
sc = screen_current();
|
||||
int evmask, focusrevert;
|
||||
int xsave, ysave, xcur, ycur;
|
||||
|
||||
TAILQ_INIT(&resultq);
|
||||
|
||||
@ -83,22 +114,25 @@ menu_filter(struct menu_q *menuq, char *prompt, char *initial, int dummy,
|
||||
|
||||
xu_ptr_getpos(sc->rootwin, &mc.x, &mc.y);
|
||||
|
||||
xsave = mc.x;
|
||||
ysave = mc.y;
|
||||
|
||||
if (prompt == NULL) {
|
||||
Mask = MenuMask;
|
||||
evmask = MENUMASK;
|
||||
mc.promptstr[0] = '\0';
|
||||
mc.list = 1;
|
||||
} else {
|
||||
Mask = MenuMask | KeyMask; /* only accept keys if prompt */
|
||||
snprintf(mc.promptstr, sizeof(mc.promptstr), "%s%c", prompt,
|
||||
PROMPT_SCHAR);
|
||||
snprintf(mc.dispstr, sizeof(mc.dispstr), "%s%s%c", mc.promptstr,
|
||||
mc.searchstr, PROMPT_ECHAR);
|
||||
mc.width = font_width(mc.dispstr, strlen(mc.dispstr));
|
||||
evmask = MENUMASK | KEYMASK; /* only accept keys if prompt */
|
||||
(void)snprintf(mc.promptstr, sizeof(mc.promptstr), "%s%s",
|
||||
prompt, PROMPT_SCHAR);
|
||||
(void)snprintf(mc.dispstr, sizeof(mc.dispstr), "%s%s%s",
|
||||
mc.promptstr, mc.searchstr, PROMPT_ECHAR);
|
||||
mc.width = font_width(sc, mc.dispstr, strlen(mc.dispstr));
|
||||
mc.hasprompt = 1;
|
||||
}
|
||||
|
||||
if (initial != NULL)
|
||||
strlcpy(mc.searchstr, initial, sizeof(mc.searchstr));
|
||||
(void)strlcpy(mc.searchstr, initial, sizeof(mc.searchstr));
|
||||
else
|
||||
mc.searchstr[0] = '\0';
|
||||
|
||||
@ -107,11 +141,11 @@ menu_filter(struct menu_q *menuq, char *prompt, char *initial, int dummy,
|
||||
mc.entry = mc.prev = -1;
|
||||
|
||||
XMoveResizeWindow(X_Dpy, sc->menuwin, mc.x, mc.y, mc.width,
|
||||
font_height());
|
||||
XSelectInput(X_Dpy, sc->menuwin, Mask);
|
||||
font_height(sc));
|
||||
XSelectInput(X_Dpy, sc->menuwin, evmask);
|
||||
XMapRaised(X_Dpy, sc->menuwin);
|
||||
|
||||
if (xu_ptr_grab(sc->menuwin, MenuGrabMask, Cursor_question) < 0) {
|
||||
if (xu_ptr_grab(sc->menuwin, MENUGRABMASK, Cursor_question) < 0) {
|
||||
XUnmapWindow(X_Dpy, sc->menuwin);
|
||||
return (NULL);
|
||||
}
|
||||
@ -126,11 +160,9 @@ menu_filter(struct menu_q *menuq, char *prompt, char *initial, int dummy,
|
||||
for (;;) {
|
||||
mc.changed = 0;
|
||||
|
||||
XWindowEvent(X_Dpy, sc->menuwin, Mask, &e);
|
||||
XWindowEvent(X_Dpy, sc->menuwin, evmask, &e);
|
||||
|
||||
switch (e.type) {
|
||||
default:
|
||||
break;
|
||||
case KeyPress:
|
||||
if ((mi = menu_handle_key(&e, &mc, menuq, &resultq))
|
||||
!= NULL)
|
||||
@ -147,16 +179,23 @@ menu_filter(struct menu_q *menuq, char *prompt, char *initial, int dummy,
|
||||
!= NULL)
|
||||
goto out;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
out:
|
||||
if ((dummy == 0 && mi->dummy) || (mi->text[0] == '\0')) { /* no match */
|
||||
xfree (mi);
|
||||
if (dummy == 0 && mi->dummy) { /* no mouse based match */
|
||||
xfree(mi);
|
||||
mi = NULL;
|
||||
xu_ptr_ungrab();
|
||||
XSetInputFocus(X_Dpy, focuswin, focusrevert, CurrentTime);
|
||||
}
|
||||
|
||||
XSetInputFocus(X_Dpy, focuswin, focusrevert, CurrentTime);
|
||||
/* restore if user didn't move */
|
||||
xu_ptr_getpos(sc->rootwin, &xcur, &ycur);
|
||||
if (xcur == mc.x && ycur == mc.y)
|
||||
xu_ptr_setpos(sc->rootwin, xsave, ysave);
|
||||
xu_ptr_ungrab();
|
||||
|
||||
XUnmapWindow(X_Dpy, sc->menuwin);
|
||||
XUngrabKeyboard(X_Dpy, CurrentTime);
|
||||
|
||||
@ -172,8 +211,7 @@ menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq,
|
||||
char chr;
|
||||
size_t len;
|
||||
|
||||
if (input_keycodetrans(e->xkey.keycode, e->xkey.state,
|
||||
&ctl, &chr) < 0)
|
||||
if (menu_keycode(e->xkey.keycode, e->xkey.state, &ctl, &chr) < 0)
|
||||
return (NULL);
|
||||
|
||||
switch (ctl) {
|
||||
@ -210,6 +248,7 @@ menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq,
|
||||
mc->searchstr, sizeof(mi->text));
|
||||
mi->dummy = 1;
|
||||
}
|
||||
mi->abort = 0;
|
||||
return (mi);
|
||||
case CTL_WIPE:
|
||||
mc->searchstr[0] = '\0';
|
||||
@ -222,6 +261,7 @@ menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq,
|
||||
mi = xmalloc(sizeof *mi);
|
||||
mi->text[0] = '\0';
|
||||
mi->dummy = 1;
|
||||
mi->abort = 1;
|
||||
return (mi);
|
||||
default:
|
||||
break;
|
||||
@ -233,18 +273,18 @@ menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq,
|
||||
str[0] = chr;
|
||||
str[1] = '\0';
|
||||
mc->changed = 1;
|
||||
strlcat(mc->searchstr, str, sizeof(mc->searchstr));
|
||||
(void)strlcat(mc->searchstr, str, sizeof(mc->searchstr));
|
||||
}
|
||||
|
||||
mc->noresult = 0;
|
||||
if (mc->changed && strlen(mc->searchstr) > 0) {
|
||||
if (mc->changed && mc->searchstr[0] != '\0') {
|
||||
(*mc->match)(menuq, resultq, mc->searchstr);
|
||||
/* If menuq is empty, never show we've failed */
|
||||
mc->noresult = TAILQ_EMPTY(resultq) && !TAILQ_EMPTY(menuq);
|
||||
} else if (mc->changed)
|
||||
TAILQ_INIT(resultq);
|
||||
|
||||
if (!mc->list && mc->listing && !mc->changed) {
|
||||
if (!mc->list && mc->listing && !mc->changed) {
|
||||
TAILQ_INIT(resultq);
|
||||
mc->listing = 0;
|
||||
}
|
||||
@ -256,8 +296,10 @@ static void
|
||||
menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
|
||||
struct menu_q *resultq)
|
||||
{
|
||||
struct menu *mi;
|
||||
int n, dy, xsave, ysave;
|
||||
struct menu *mi;
|
||||
XineramaScreenInfo *xine;
|
||||
int xmin, xmax, ymin, ymax;
|
||||
int n, dy, xsave, ysave;
|
||||
|
||||
if (mc->list) {
|
||||
if (TAILQ_EMPTY(resultq) && mc->list) {
|
||||
@ -275,10 +317,10 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
|
||||
mc->width = 0;
|
||||
dy = 0;
|
||||
if (mc->hasprompt) {
|
||||
snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%c",
|
||||
(void)snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%s",
|
||||
mc->promptstr, mc->searchstr, PROMPT_ECHAR);
|
||||
mc->width = font_width(mc->dispstr, strlen(mc->dispstr));
|
||||
dy = font_height();
|
||||
mc->width = font_width(sc, mc->dispstr, strlen(mc->dispstr));
|
||||
dy = font_height(sc);
|
||||
mc->num = 1;
|
||||
}
|
||||
|
||||
@ -293,24 +335,39 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
|
||||
text = mi->text;
|
||||
}
|
||||
|
||||
mc->width = MAX(mc->width, font_width(text,
|
||||
mc->width = MAX(mc->width, font_width(sc, text,
|
||||
MIN(strlen(text), MENU_MAXENTRY)));
|
||||
dy += font_height();
|
||||
dy += font_height(sc);
|
||||
mc->num++;
|
||||
}
|
||||
|
||||
xine = screen_find_xinerama(sc, mc->x, mc->y);
|
||||
if (xine) {
|
||||
xmin = xine->x_org;
|
||||
xmax = xine->x_org + xine->width;
|
||||
ymin = xine->y_org;
|
||||
ymax = xine->y_org + xine->height;
|
||||
} else {
|
||||
xmin = ymin = 0;
|
||||
xmax = sc->xmax;
|
||||
ymax = sc->ymax;
|
||||
}
|
||||
|
||||
xsave = mc->x;
|
||||
ysave = mc->y;
|
||||
if (mc->x < 0)
|
||||
mc->x = 0;
|
||||
else if (mc->x + mc->width >= sc->xmax)
|
||||
mc->x = sc->xmax - mc->width;
|
||||
|
||||
if (mc->y + dy >= sc->ymax)
|
||||
mc->y = sc->ymax - dy;
|
||||
if (mc->x < xmin)
|
||||
mc->x = xmin;
|
||||
else if (mc->x + mc->width >= xmax)
|
||||
mc->x = xmax - mc->width;
|
||||
|
||||
if (mc->y + dy >= ymax)
|
||||
mc->y = ymax - dy;
|
||||
/* never hide the top of the menu */
|
||||
if (mc->y < 0)
|
||||
mc->y = 0;
|
||||
if (mc->y < ymin) {
|
||||
mc->y = ymin;
|
||||
dy = ymax - ymin;
|
||||
}
|
||||
|
||||
if (mc->x != xsave || mc->y != ysave)
|
||||
xu_ptr_setpos(sc->rootwin, mc->x, mc->y);
|
||||
@ -320,7 +377,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
|
||||
|
||||
if (mc->hasprompt) {
|
||||
font_draw(sc, mc->dispstr, strlen(mc->dispstr), sc->menuwin,
|
||||
0, font_ascent() + 1);
|
||||
0, font_ascent(sc) + 1);
|
||||
n = 1;
|
||||
} else
|
||||
n = 0;
|
||||
@ -330,20 +387,20 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
|
||||
mi->print : mi->text;
|
||||
|
||||
font_draw(sc, text, MIN(strlen(text), MENU_MAXENTRY),
|
||||
sc->menuwin, 0, n*font_height() + font_ascent() + 1);
|
||||
sc->menuwin, 0, n * font_height(sc) + font_ascent(sc) + 1);
|
||||
n++;
|
||||
}
|
||||
|
||||
if (mc->hasprompt && n > 1)
|
||||
if (mc->hasprompt && n > 1 && (mc->searchstr[0] != '\0'))
|
||||
XFillRectangle(X_Dpy, sc->menuwin, sc->gc,
|
||||
0, font_height(), mc->width, font_height());
|
||||
0, font_height(sc), mc->width, font_height(sc));
|
||||
|
||||
if (mc->noresult)
|
||||
XFillRectangle(X_Dpy, sc->menuwin, sc->gc,
|
||||
0, 0, mc->width, font_height());
|
||||
0, 0, mc->width, font_height(sc));
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
menu_handle_move(XEvent *e, struct menu_ctx *mc, struct screen_ctx *sc)
|
||||
{
|
||||
mc->prev = mc->entry;
|
||||
@ -351,16 +408,16 @@ menu_handle_move(XEvent *e, struct menu_ctx *mc, struct screen_ctx *sc)
|
||||
|
||||
if (mc->prev != -1)
|
||||
XFillRectangle(X_Dpy, sc->menuwin, sc->gc, 0,
|
||||
font_height() * mc->prev, mc->width, font_height());
|
||||
font_height(sc) * mc->prev, mc->width, font_height(sc));
|
||||
if (mc->entry != -1) {
|
||||
xu_ptr_regrab(MenuGrabMask, Cursor_select);
|
||||
(void)xu_ptr_regrab(MENUGRABMASK, Cursor_normal);
|
||||
XFillRectangle(X_Dpy, sc->menuwin, sc->gc, 0,
|
||||
font_height() * mc->entry, mc->width, font_height());
|
||||
font_height(sc) * mc->entry, mc->width, font_height(sc));
|
||||
} else
|
||||
xu_ptr_regrab(MenuGrabMask, Cursor_default);
|
||||
(void)xu_ptr_regrab(MENUGRABMASK, Cursor_default);
|
||||
}
|
||||
|
||||
struct menu *
|
||||
static struct menu *
|
||||
menu_handle_release(XEvent *e, struct menu_ctx *mc, struct screen_ctx *sc,
|
||||
struct menu_q *resultq)
|
||||
{
|
||||
@ -368,7 +425,6 @@ menu_handle_release(XEvent *e, struct menu_ctx *mc, struct screen_ctx *sc,
|
||||
int entry, i = 0;
|
||||
|
||||
entry = menu_calc_entry(sc, mc, e->xbutton.x, e->xbutton.y);
|
||||
xu_ptr_ungrab();
|
||||
|
||||
if (mc->hasprompt)
|
||||
i = 1;
|
||||
@ -377,7 +433,7 @@ menu_handle_release(XEvent *e, struct menu_ctx *mc, struct screen_ctx *sc,
|
||||
if (entry == i++)
|
||||
break;
|
||||
if (mi == NULL) {
|
||||
XMALLOC(mi, struct menu);
|
||||
mi = xmalloc(sizeof(*mi));
|
||||
mi->text[0] = '\0';
|
||||
mi->dummy = 1;
|
||||
}
|
||||
@ -389,11 +445,11 @@ menu_calc_entry(struct screen_ctx *sc, struct menu_ctx *mc, int x, int y)
|
||||
{
|
||||
int entry;
|
||||
|
||||
entry = y / font_height();
|
||||
entry = y / font_height(sc);
|
||||
|
||||
/* in bounds? */
|
||||
if (x < 0 || x > mc->width || y < 0 || y > font_height() * mc->num ||
|
||||
entry < 0 || entry >= mc->num)
|
||||
if (x <= 0 || x > mc->width || y <= 0 ||
|
||||
y > font_height(sc) * mc->num || entry < 0 || entry >= mc->num)
|
||||
entry = -1;
|
||||
|
||||
if (mc->hasprompt && entry == 0)
|
||||
@ -401,3 +457,89 @@ menu_calc_entry(struct screen_ctx *sc, struct menu_ctx *mc, int x, int y)
|
||||
|
||||
return (entry);
|
||||
}
|
||||
|
||||
static int
|
||||
menu_keycode(KeyCode kc, u_int state, enum ctltype *ctl, char *chr)
|
||||
{
|
||||
int ks;
|
||||
|
||||
*ctl = CTL_NONE;
|
||||
*chr = '\0';
|
||||
|
||||
ks = XKeycodeToKeysym(X_Dpy, kc, (state & ShiftMask) ? 1 : 0);
|
||||
|
||||
/* Look for control characters. */
|
||||
switch (ks) {
|
||||
case XK_BackSpace:
|
||||
*ctl = CTL_ERASEONE;
|
||||
break;
|
||||
case XK_Return:
|
||||
*ctl = CTL_RETURN;
|
||||
break;
|
||||
case XK_Up:
|
||||
*ctl = CTL_UP;
|
||||
break;
|
||||
case XK_Down:
|
||||
*ctl = CTL_DOWN;
|
||||
break;
|
||||
case XK_Escape:
|
||||
*ctl = CTL_ABORT;
|
||||
break;
|
||||
}
|
||||
|
||||
if (*ctl == CTL_NONE && (state & ControlMask)) {
|
||||
switch (ks) {
|
||||
case XK_s:
|
||||
case XK_S:
|
||||
/* Emacs "next" */
|
||||
*ctl = CTL_DOWN;
|
||||
break;
|
||||
case XK_r:
|
||||
case XK_R:
|
||||
/* Emacs "previous" */
|
||||
*ctl = CTL_UP;
|
||||
break;
|
||||
case XK_u:
|
||||
case XK_U:
|
||||
*ctl = CTL_WIPE;
|
||||
break;
|
||||
case XK_h:
|
||||
case XK_H:
|
||||
*ctl = CTL_ERASEONE;
|
||||
break;
|
||||
case XK_a:
|
||||
case XK_A:
|
||||
*ctl = CTL_ALL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (*ctl == CTL_NONE && (state & Mod1Mask)) {
|
||||
switch (ks) {
|
||||
case XK_j:
|
||||
case XK_J:
|
||||
/* Vi "down" */
|
||||
*ctl = CTL_DOWN;
|
||||
break;
|
||||
case XK_k:
|
||||
case XK_K:
|
||||
/* Vi "up" */
|
||||
*ctl = CTL_UP;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (*ctl != CTL_NONE)
|
||||
return (0);
|
||||
|
||||
/*
|
||||
* For regular characters, only (part of, actually) Latin 1
|
||||
* for now.
|
||||
*/
|
||||
if (ks < 0x20 || ks > 0x07e)
|
||||
return (-1);
|
||||
|
||||
*chr = (char)ks;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
199
mousefunc.c
199
mousefunc.c
@ -1,7 +1,8 @@
|
||||
/*
|
||||
* calmwm - the calm window manager
|
||||
* calmwm - the calm window manager
|
||||
*
|
||||
* Copyright (c) 2008 rivo nurges <rix@estpak.ee>
|
||||
* Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>
|
||||
* Copyright (c) 2008 rivo nurges <rix@estpak.ee>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@ -15,24 +16,171 @@
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* $Id$
|
||||
* $OpenBSD$
|
||||
*/
|
||||
|
||||
#include "headers.h"
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "calmwm.h"
|
||||
|
||||
static int mousefunc_sweep_calc(struct client_ctx *, int, int, int, int);
|
||||
static void mousefunc_sweep_draw(struct client_ctx *);
|
||||
|
||||
static int
|
||||
mousefunc_sweep_calc(struct client_ctx *cc, int x, int y, int mx, int my)
|
||||
{
|
||||
int width = cc->geom.width, height = cc->geom.height;
|
||||
|
||||
cc->geom.width = abs(x - mx) - cc->bwidth;
|
||||
cc->geom.height = abs(y - my) - cc->bwidth;
|
||||
|
||||
client_applysizehints(cc);
|
||||
|
||||
cc->geom.x = x <= mx ? x : x - cc->geom.width;
|
||||
cc->geom.y = y <= my ? y : y - cc->geom.height;
|
||||
|
||||
return (width != cc->geom.width || height != cc->geom.height);
|
||||
}
|
||||
|
||||
static void
|
||||
mousefunc_sweep_draw(struct client_ctx *cc)
|
||||
{
|
||||
struct screen_ctx *sc = cc->sc;
|
||||
char asize[10]; /* fits "nnnnxnnnn\0" */
|
||||
int width, width_size, width_name;
|
||||
|
||||
(void)snprintf(asize, sizeof(asize), "%dx%d",
|
||||
(cc->geom.width - cc->hint.basew) / cc->hint.incw,
|
||||
(cc->geom.height - cc->hint.baseh) / cc->hint.inch);
|
||||
width_size = font_width(sc, asize, strlen(asize)) + 4;
|
||||
width_name = font_width(sc, cc->name, strlen(cc->name)) + 4;
|
||||
width = MAX(width_size, width_name);
|
||||
|
||||
XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0);
|
||||
XMoveResizeWindow(X_Dpy, sc->menuwin, 0, 0, width, font_height(sc) * 2);
|
||||
XMapWindow(X_Dpy, sc->menuwin);
|
||||
XClearWindow(X_Dpy, sc->menuwin);
|
||||
font_draw(sc, cc->name, strlen(cc->name), sc->menuwin,
|
||||
2, font_ascent(sc) + 1);
|
||||
font_draw(sc, asize, strlen(asize), sc->menuwin,
|
||||
width / 2 - width_size / 2, font_height(sc) + font_ascent(sc) + 1);
|
||||
}
|
||||
|
||||
void
|
||||
mousefunc_window_resize(struct client_ctx *cc, void *arg)
|
||||
{
|
||||
grab_sweep(cc);
|
||||
client_resize(cc);
|
||||
XEvent ev;
|
||||
Time ltime = 0;
|
||||
struct screen_ctx *sc = cc->sc;
|
||||
int x = cc->geom.x, y = cc->geom.y;
|
||||
|
||||
if (cc->flags & CLIENT_FREEZE)
|
||||
return;
|
||||
|
||||
client_raise(cc);
|
||||
client_ptrsave(cc);
|
||||
|
||||
if (xu_ptr_grab(cc->win, MOUSEMASK, Cursor_resize) < 0)
|
||||
return;
|
||||
|
||||
xu_ptr_setpos(cc->win, cc->geom.width, cc->geom.height);
|
||||
mousefunc_sweep_draw(cc);
|
||||
|
||||
for (;;) {
|
||||
XMaskEvent(X_Dpy, MOUSEMASK|ExposureMask, &ev);
|
||||
|
||||
switch (ev.type) {
|
||||
case Expose:
|
||||
client_draw_border(cc);
|
||||
break;
|
||||
case MotionNotify:
|
||||
if (mousefunc_sweep_calc(cc, x, y,
|
||||
ev.xmotion.x_root, ev.xmotion.y_root))
|
||||
/* Recompute window output */
|
||||
mousefunc_sweep_draw(cc);
|
||||
|
||||
/* don't resize more than 60 times / second */
|
||||
if ((ev.xmotion.time - ltime) > (1000 / 60)) {
|
||||
ltime = ev.xmotion.time;
|
||||
client_resize(cc);
|
||||
}
|
||||
break;
|
||||
case ButtonRelease:
|
||||
if (ltime)
|
||||
client_resize(cc);
|
||||
XUnmapWindow(X_Dpy, sc->menuwin);
|
||||
XReparentWindow(X_Dpy, sc->menuwin, sc->rootwin, 0, 0);
|
||||
xu_ptr_ungrab();
|
||||
|
||||
/* Make sure the pointer stays within the window. */
|
||||
if (cc->ptr.x > cc->geom.width)
|
||||
cc->ptr.x = cc->geom.width - cc->bwidth;
|
||||
if (cc->ptr.y > cc->geom.height)
|
||||
cc->ptr.y = cc->geom.height - cc->bwidth;
|
||||
client_ptrwarp(cc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
void
|
||||
mousefunc_window_move(struct client_ctx *cc, void *arg)
|
||||
{
|
||||
grab_drag(cc);
|
||||
client_move(cc);
|
||||
XEvent ev;
|
||||
Time ltime = 0;
|
||||
int px, py;
|
||||
|
||||
client_raise(cc);
|
||||
|
||||
if (cc->flags & CLIENT_FREEZE)
|
||||
return;
|
||||
|
||||
if (xu_ptr_grab(cc->win, MOUSEMASK, Cursor_move) < 0)
|
||||
return;
|
||||
|
||||
xu_ptr_getpos(cc->win, &px, &py);
|
||||
|
||||
for (;;) {
|
||||
XMaskEvent(X_Dpy, MOUSEMASK|ExposureMask, &ev);
|
||||
|
||||
switch (ev.type) {
|
||||
case Expose:
|
||||
client_draw_border(cc);
|
||||
break;
|
||||
case MotionNotify:
|
||||
cc->geom.x = ev.xmotion.x_root - px - cc->bwidth;
|
||||
cc->geom.y = ev.xmotion.y_root - py - cc->bwidth;
|
||||
|
||||
cc->geom.x += client_snapcalc(cc->geom.x,
|
||||
cc->geom.width, cc->sc->xmax,
|
||||
cc->bwidth, Conf.snapdist);
|
||||
cc->geom.y += client_snapcalc(cc->geom.y,
|
||||
cc->geom.height, cc->sc->ymax,
|
||||
cc->bwidth, Conf.snapdist);
|
||||
|
||||
/* don't move more than 60 times / second */
|
||||
if ((ev.xmotion.time - ltime) > (1000 / 60)) {
|
||||
ltime = ev.xmotion.time;
|
||||
client_move(cc);
|
||||
}
|
||||
break;
|
||||
case ButtonRelease:
|
||||
if (ltime)
|
||||
client_move(cc);
|
||||
xu_ptr_ungrab();
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
void
|
||||
@ -48,6 +196,12 @@ mousefunc_window_lower(struct client_ctx *cc, void *arg)
|
||||
client_lower(cc);
|
||||
}
|
||||
|
||||
void
|
||||
mousefunc_window_raise(struct client_ctx *cc, void *arg)
|
||||
{
|
||||
client_raise(cc);
|
||||
}
|
||||
|
||||
void
|
||||
mousefunc_window_hide(struct client_ctx *cc, void *arg)
|
||||
{
|
||||
@ -63,26 +217,24 @@ mousefunc_menu_group(struct client_ctx *cc, void *arg)
|
||||
void
|
||||
mousefunc_menu_unhide(struct client_ctx *cc, void *arg)
|
||||
{
|
||||
struct screen_ctx *sc;
|
||||
struct client_ctx *old_cc;
|
||||
struct menu *mi;
|
||||
struct menu_q menuq;
|
||||
char *wname;
|
||||
|
||||
sc = cc->sc;
|
||||
old_cc = client_current();
|
||||
|
||||
TAILQ_INIT(&menuq);
|
||||
TAILQ_FOREACH(cc, &Clientq, entry)
|
||||
if (cc->flags & CLIENT_HIDDEN) {
|
||||
if (cc->label != NULL)
|
||||
wname = cc->label;
|
||||
else
|
||||
wname = cc->name;
|
||||
|
||||
wname = (cc->label) ? cc->label : cc->name;
|
||||
if (wname == NULL)
|
||||
continue;
|
||||
|
||||
XCALLOC(mi, struct menu);
|
||||
strlcpy(mi->text, wname, sizeof(mi->text));
|
||||
mi = xcalloc(1, sizeof(*mi));
|
||||
(void)strlcpy(mi->text, wname, sizeof(mi->text));
|
||||
mi->ctx = cc;
|
||||
TAILQ_INSERT_TAIL(&menuq, mi, entry);
|
||||
}
|
||||
@ -90,7 +242,7 @@ mousefunc_menu_unhide(struct client_ctx *cc, void *arg)
|
||||
if (TAILQ_EMPTY(&menuq))
|
||||
return;
|
||||
|
||||
mi = menu_filter(&menuq, NULL, NULL, 0, NULL, NULL);
|
||||
mi = menu_filter(sc, &menuq, NULL, NULL, 0, NULL, NULL);
|
||||
if (mi != NULL) {
|
||||
cc = (struct client_ctx *)mi->ctx;
|
||||
client_unhide(cc);
|
||||
@ -109,21 +261,24 @@ mousefunc_menu_unhide(struct client_ctx *cc, void *arg)
|
||||
void
|
||||
mousefunc_menu_cmd(struct client_ctx *cc, void *arg)
|
||||
{
|
||||
struct menu *mi;
|
||||
struct menu_q menuq;
|
||||
struct cmd *cmd;
|
||||
struct screen_ctx *sc;
|
||||
struct menu *mi;
|
||||
struct menu_q menuq;
|
||||
struct cmd *cmd;
|
||||
|
||||
sc = cc->sc;
|
||||
|
||||
TAILQ_INIT(&menuq);
|
||||
TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
|
||||
XCALLOC(mi, struct menu);
|
||||
strlcpy(mi->text, cmd->label, sizeof(mi->text));
|
||||
mi = xcalloc(1, sizeof(*mi));
|
||||
(void)strlcpy(mi->text, cmd->label, sizeof(mi->text));
|
||||
mi->ctx = cmd;
|
||||
TAILQ_INSERT_TAIL(&menuq, mi, entry);
|
||||
}
|
||||
if (TAILQ_EMPTY(&menuq))
|
||||
return;
|
||||
|
||||
mi = menu_filter(&menuq, NULL, NULL, 0, NULL, NULL);
|
||||
mi = menu_filter(sc, &menuq, NULL, NULL, 0, NULL, NULL);
|
||||
if (mi != NULL)
|
||||
u_spawn(((struct cmd *)mi->ctx)->image);
|
||||
else
|
||||
|
180
parse.y
180
parse.y
@ -21,7 +21,11 @@
|
||||
|
||||
%{
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
@ -29,7 +33,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "headers.h"
|
||||
#include "calmwm.h"
|
||||
|
||||
TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files);
|
||||
@ -54,8 +57,6 @@ int findeol(void);
|
||||
|
||||
static struct conf *conf;
|
||||
|
||||
extern char *shortcut_to_name[];
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
int64_t number;
|
||||
@ -68,7 +69,11 @@ typedef struct {
|
||||
|
||||
%token FONTNAME STICKY GAP MOUSEBIND
|
||||
%token AUTOGROUP BIND COMMAND IGNORE
|
||||
%token YES NO
|
||||
%token YES NO BORDERWIDTH MOVEAMOUNT
|
||||
%token COLOR SNAPDIST
|
||||
%token ACTIVEBORDER INACTIVEBORDER
|
||||
%token GROUPBORDER UNGROUPBORDER
|
||||
%token MENUBG MENUFG FONTCOLOR
|
||||
%token ERROR
|
||||
%token <v.string> STRING
|
||||
%token <v.number> NUMBER
|
||||
@ -79,6 +84,7 @@ typedef struct {
|
||||
grammar : /* empty */
|
||||
| grammar '\n'
|
||||
| grammar main '\n'
|
||||
| grammar color '\n'
|
||||
| grammar error '\n' { file->errors++; }
|
||||
;
|
||||
|
||||
@ -100,8 +106,8 @@ yesno : YES { $$ = 1; }
|
||||
;
|
||||
|
||||
main : FONTNAME STRING {
|
||||
free(conf->DefaultFontName);
|
||||
conf->DefaultFontName = $2;
|
||||
free(conf->font);
|
||||
conf->font = $2;
|
||||
}
|
||||
| STICKY yesno {
|
||||
if ($2 == 0)
|
||||
@ -109,42 +115,35 @@ main : FONTNAME STRING {
|
||||
else
|
||||
conf->flags |= CONF_STICKY_GROUPS;
|
||||
}
|
||||
| BORDERWIDTH NUMBER {
|
||||
conf->bwidth = $2;
|
||||
}
|
||||
| MOVEAMOUNT NUMBER {
|
||||
conf->mamount = $2;
|
||||
}
|
||||
| SNAPDIST NUMBER {
|
||||
conf->snapdist = $2;
|
||||
}
|
||||
| COMMAND STRING string {
|
||||
conf_cmd_add(conf, $3, $2, 0);
|
||||
free($2);
|
||||
free($3);
|
||||
}
|
||||
| AUTOGROUP NUMBER STRING {
|
||||
struct autogroupwin *aw;
|
||||
char *p;
|
||||
|
||||
if ($2 < 0 || $2 > 9) {
|
||||
free($3);
|
||||
yyerror("autogroup number out of range: %d", $2);
|
||||
YYERROR;
|
||||
}
|
||||
|
||||
XCALLOC(aw, struct autogroupwin);
|
||||
|
||||
if ((p = strchr($3, ',')) == NULL) {
|
||||
aw->name = NULL;
|
||||
aw->class = xstrdup($3);
|
||||
} else {
|
||||
*(p++) = '\0';
|
||||
aw->name = xstrdup($3);
|
||||
aw->class = xstrdup(p);
|
||||
}
|
||||
aw->group = xstrdup(shortcut_to_name[$2]);
|
||||
|
||||
TAILQ_INSERT_TAIL(&conf->autogroupq, aw, entry);
|
||||
|
||||
group_make_autogroup(conf, $3, $2);
|
||||
free($3);
|
||||
}
|
||||
| IGNORE STRING {
|
||||
struct winmatch *wm;
|
||||
|
||||
XCALLOC(wm, struct winmatch);
|
||||
strlcpy(wm->title, $2, sizeof(wm->title));
|
||||
wm = xcalloc(1, sizeof(*wm));
|
||||
(void)strlcpy(wm->title, $2, sizeof(wm->title));
|
||||
TAILQ_INSERT_TAIL(&conf->ignoreq, wm, entry);
|
||||
|
||||
free($2);
|
||||
@ -155,10 +154,10 @@ main : FONTNAME STRING {
|
||||
free($3);
|
||||
}
|
||||
| GAP NUMBER NUMBER NUMBER NUMBER {
|
||||
conf->gap_top = $2;
|
||||
conf->gap_bottom = $3;
|
||||
conf->gap_left = $4;
|
||||
conf->gap_right = $5;
|
||||
conf->gap.top = $2;
|
||||
conf->gap.bottom = $3;
|
||||
conf->gap.left = $4;
|
||||
conf->gap.right = $5;
|
||||
}
|
||||
| MOUSEBIND STRING string {
|
||||
conf_mousebind(conf, $2, $3);
|
||||
@ -166,6 +165,39 @@ main : FONTNAME STRING {
|
||||
free($3);
|
||||
}
|
||||
;
|
||||
|
||||
color : COLOR colors
|
||||
;
|
||||
|
||||
colors : ACTIVEBORDER STRING {
|
||||
free(conf->color[CWM_COLOR_BORDER_ACTIVE].name);
|
||||
conf->color[CWM_COLOR_BORDER_ACTIVE].name = $2;
|
||||
}
|
||||
| INACTIVEBORDER STRING {
|
||||
free(conf->color[CWM_COLOR_BORDER_INACTIVE].name);
|
||||
conf->color[CWM_COLOR_BORDER_INACTIVE].name = $2;
|
||||
}
|
||||
| GROUPBORDER STRING {
|
||||
free(conf->color[CWM_COLOR_BORDER_GROUP].name);
|
||||
conf->color[CWM_COLOR_BORDER_GROUP].name = $2;
|
||||
}
|
||||
| UNGROUPBORDER STRING {
|
||||
free(conf->color[CWM_COLOR_BORDER_UNGROUP].name);
|
||||
conf->color[CWM_COLOR_BORDER_UNGROUP].name = $2;
|
||||
}
|
||||
| MENUBG STRING {
|
||||
free(conf->color[CWM_COLOR_BG_MENU].name);
|
||||
conf->color[CWM_COLOR_BG_MENU].name = $2;
|
||||
}
|
||||
| MENUFG STRING {
|
||||
free(conf->color[CWM_COLOR_FG_MENU].name);
|
||||
conf->color[CWM_COLOR_FG_MENU].name = $2;
|
||||
}
|
||||
| FONTCOLOR STRING {
|
||||
free(conf->color[CWM_COLOR_FONT].name);
|
||||
conf->color[CWM_COLOR_FONT].name = $2;
|
||||
}
|
||||
;
|
||||
%%
|
||||
|
||||
struct keywords {
|
||||
@ -198,15 +230,26 @@ lookup(char *s)
|
||||
{
|
||||
/* this has to be sorted always */
|
||||
static const struct keywords keywords[] = {
|
||||
{ "activeborder", ACTIVEBORDER},
|
||||
{ "autogroup", AUTOGROUP},
|
||||
{ "bind", BIND},
|
||||
{ "borderwidth", BORDERWIDTH},
|
||||
{ "color", COLOR},
|
||||
{ "command", COMMAND},
|
||||
{ "font", FONTCOLOR},
|
||||
{ "fontname", FONTNAME},
|
||||
{ "gap", GAP},
|
||||
{ "groupborder", GROUPBORDER},
|
||||
{ "ignore", IGNORE},
|
||||
{ "inactiveborder", INACTIVEBORDER},
|
||||
{ "menubg", MENUBG},
|
||||
{ "menufg", MENUFG},
|
||||
{ "mousebind", MOUSEBIND},
|
||||
{ "moveamount", MOVEAMOUNT},
|
||||
{ "no", NO},
|
||||
{ "snapdist", SNAPDIST},
|
||||
{ "sticky", STICKY},
|
||||
{ "ungroupborder", UNGROUPBORDER},
|
||||
{ "yes", YES}
|
||||
};
|
||||
const struct keywords *p;
|
||||
@ -343,9 +386,10 @@ yylex(void)
|
||||
return (0);
|
||||
if (next == quotec || c == ' ' || c == '\t')
|
||||
c = next;
|
||||
else if (next == '\n')
|
||||
else if (next == '\n') {
|
||||
file->lineno++;
|
||||
continue;
|
||||
else
|
||||
} else
|
||||
lungetc(next);
|
||||
} else if (c == quotec) {
|
||||
*p = '\0';
|
||||
@ -434,8 +478,6 @@ pushfile(const char *name)
|
||||
nfile->name = xstrdup(name);
|
||||
|
||||
if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
|
||||
if (errno != ENOENT)
|
||||
warn("%s", nfile->name);
|
||||
free(nfile->name);
|
||||
free(nfile);
|
||||
return (NULL);
|
||||
@ -462,63 +504,19 @@ popfile(void)
|
||||
return (EOF);
|
||||
}
|
||||
|
||||
void
|
||||
conf_clear(struct conf *c)
|
||||
{
|
||||
struct autogroupwin *ag;
|
||||
struct keybinding *kb;
|
||||
struct winmatch *wm;
|
||||
struct cmd *cmd;
|
||||
struct mousebinding *mb;
|
||||
|
||||
while (cmd = TAILQ_FIRST(&c->cmdq)) {
|
||||
TAILQ_REMOVE(&c->cmdq, cmd, entry);
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
while (kb = TAILQ_FIRST(&c->keybindingq)) {
|
||||
TAILQ_REMOVE(&c->keybindingq, kb, entry);
|
||||
free(kb);
|
||||
}
|
||||
|
||||
while (ag = TAILQ_FIRST(&c->autogroupq)) {
|
||||
TAILQ_REMOVE(&c->autogroupq, ag, entry);
|
||||
free(ag->class);
|
||||
if (ag->name)
|
||||
free(ag->name);
|
||||
free(ag->group);
|
||||
free(ag);
|
||||
}
|
||||
|
||||
while (wm = TAILQ_FIRST(&c->ignoreq)) {
|
||||
TAILQ_REMOVE(&c->ignoreq, wm, entry);
|
||||
free(wm);
|
||||
}
|
||||
|
||||
while (mb = TAILQ_FIRST(&c->mousebindingq)) {
|
||||
TAILQ_REMOVE(&c->mousebindingq, mb, entry);
|
||||
free(mb);
|
||||
}
|
||||
|
||||
if (c->DefaultFontName != NULL &&
|
||||
c->DefaultFontName != DEFAULTFONTNAME)
|
||||
free(c->DefaultFontName);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
parse_config(const char *filename, struct conf *xconf)
|
||||
{
|
||||
int errors = 0;
|
||||
|
||||
XCALLOC(conf, struct conf);
|
||||
conf = xcalloc(1, sizeof(*conf));
|
||||
|
||||
if ((file = pushfile(filename)) == NULL) {
|
||||
free(conf);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
strlcpy(conf->conf_path, filename, sizeof(conf->conf_path));
|
||||
(void)strlcpy(conf->conf_path, filename, sizeof(conf->conf_path));
|
||||
|
||||
conf_init(conf);
|
||||
|
||||
@ -536,44 +534,50 @@ parse_config(const char *filename, struct conf *xconf)
|
||||
struct winmatch *wm;
|
||||
struct cmd *cmd;
|
||||
struct mousebinding *mb;
|
||||
int i;
|
||||
|
||||
conf_clear(xconf);
|
||||
|
||||
xconf->flags = conf->flags;
|
||||
xconf->bwidth = conf->bwidth;
|
||||
xconf->mamount = conf->mamount;
|
||||
xconf->snapdist = conf->snapdist;
|
||||
xconf->gap = conf->gap;
|
||||
|
||||
while (cmd = TAILQ_FIRST(&conf->cmdq)) {
|
||||
while ((cmd = TAILQ_FIRST(&conf->cmdq)) != NULL) {
|
||||
TAILQ_REMOVE(&conf->cmdq, cmd, entry);
|
||||
TAILQ_INSERT_TAIL(&xconf->cmdq, cmd, entry);
|
||||
}
|
||||
|
||||
while (kb = TAILQ_FIRST(&conf->keybindingq)) {
|
||||
while ((kb = TAILQ_FIRST(&conf->keybindingq)) != NULL) {
|
||||
TAILQ_REMOVE(&conf->keybindingq, kb, entry);
|
||||
TAILQ_INSERT_TAIL(&xconf->keybindingq, kb, entry);
|
||||
}
|
||||
|
||||
while (ag = TAILQ_FIRST(&conf->autogroupq)) {
|
||||
while ((ag = TAILQ_FIRST(&conf->autogroupq)) != NULL) {
|
||||
TAILQ_REMOVE(&conf->autogroupq, ag, entry);
|
||||
TAILQ_INSERT_TAIL(&xconf->autogroupq, ag, entry);
|
||||
}
|
||||
|
||||
while (wm = TAILQ_FIRST(&conf->ignoreq)) {
|
||||
while ((wm = TAILQ_FIRST(&conf->ignoreq)) != NULL) {
|
||||
TAILQ_REMOVE(&conf->ignoreq, wm, entry);
|
||||
TAILQ_INSERT_TAIL(&xconf->ignoreq, wm, entry);
|
||||
}
|
||||
|
||||
while (mb = TAILQ_FIRST(&conf->mousebindingq)) {
|
||||
while ((mb = TAILQ_FIRST(&conf->mousebindingq)) != NULL) {
|
||||
TAILQ_REMOVE(&conf->mousebindingq, mb, entry);
|
||||
TAILQ_INSERT_TAIL(&xconf->mousebindingq, mb, entry);
|
||||
}
|
||||
|
||||
strlcpy(xconf->termpath, conf->termpath,
|
||||
(void)strlcpy(xconf->termpath, conf->termpath,
|
||||
sizeof(xconf->termpath));
|
||||
strlcpy(xconf->lockpath, conf->lockpath,
|
||||
(void)strlcpy(xconf->lockpath, conf->lockpath,
|
||||
sizeof(xconf->lockpath));
|
||||
|
||||
xconf->DefaultFontName = conf->DefaultFontName;
|
||||
for (i = 0; i < CWM_COLOR_MAX; i++)
|
||||
xconf->color[i].name = conf->color[i].name;
|
||||
|
||||
bcopy(&(conf->gap_top), &(xconf->gap_top), sizeof(int) * 4);
|
||||
xconf->font = conf->font;
|
||||
}
|
||||
|
||||
free(conf);
|
||||
|
94
screen.c
94
screen.c
@ -15,14 +15,20 @@
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* $Id$
|
||||
* $OpenBSD$
|
||||
*/
|
||||
|
||||
#include "headers.h"
|
||||
#include "calmwm.h"
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
extern struct screen_ctx_q Screenq;
|
||||
extern struct screen_ctx *Curscreen;
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "calmwm.h"
|
||||
|
||||
struct screen_ctx *
|
||||
screen_fromroot(Window rootwin)
|
||||
@ -37,22 +43,13 @@ screen_fromroot(Window rootwin)
|
||||
return (TAILQ_FIRST(&Screenq));
|
||||
}
|
||||
|
||||
struct screen_ctx *
|
||||
screen_current(void)
|
||||
{
|
||||
return (Curscreen);
|
||||
}
|
||||
|
||||
void
|
||||
screen_updatestackingorder(void)
|
||||
screen_updatestackingorder(struct screen_ctx *sc)
|
||||
{
|
||||
Window *wins, w0, w1;
|
||||
struct screen_ctx *sc;
|
||||
struct client_ctx *cc;
|
||||
u_int nwins, i, s;
|
||||
|
||||
sc = screen_current();
|
||||
|
||||
if (!XQueryTree(X_Dpy, sc->rootwin, &w0, &w1, &wins, &nwins))
|
||||
return;
|
||||
|
||||
@ -67,3 +64,70 @@ screen_updatestackingorder(void)
|
||||
|
||||
XFree(wins);
|
||||
}
|
||||
|
||||
void
|
||||
screen_init_xinerama(struct screen_ctx *sc)
|
||||
{
|
||||
XineramaScreenInfo *info;
|
||||
int no;
|
||||
|
||||
if (HasXinerama == 0 || XineramaIsActive(X_Dpy) == 0) {
|
||||
HasXinerama = 0;
|
||||
sc->xinerama_no = 0;
|
||||
}
|
||||
|
||||
info = XineramaQueryScreens(X_Dpy, &no);
|
||||
if (info == NULL) {
|
||||
/* Is xinerama actually off, instead of a malloc failure? */
|
||||
if (sc->xinerama == NULL)
|
||||
HasXinerama = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (sc->xinerama != NULL)
|
||||
XFree(sc->xinerama);
|
||||
sc->xinerama = info;
|
||||
sc->xinerama_no = no;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find which xinerama screen the coordinates (x,y) is on.
|
||||
*/
|
||||
XineramaScreenInfo *
|
||||
screen_find_xinerama(struct screen_ctx *sc, int x, int y)
|
||||
{
|
||||
XineramaScreenInfo *info;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sc->xinerama_no; i++) {
|
||||
info = &sc->xinerama[i];
|
||||
if (x >= info->x_org && x < info->x_org + info->width &&
|
||||
y >= info->y_org && y < info->y_org + info->height)
|
||||
return (info);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
void
|
||||
screen_update_geometry(struct screen_ctx *sc, int width, int height)
|
||||
{
|
||||
long geom[2], workareas[CALMWM_NGROUPS][4];
|
||||
int i;
|
||||
|
||||
sc->xmax = geom[0] = width;
|
||||
sc->ymax = geom[1] = height;
|
||||
XChangeProperty(X_Dpy, sc->rootwin, _NET_DESKTOP_GEOMETRY,
|
||||
XA_CARDINAL, 32, PropModeReplace, (unsigned char *)geom , 2);
|
||||
|
||||
/* x, y, width, height. */
|
||||
for (i = 0; i < CALMWM_NGROUPS; i++) {
|
||||
workareas[i][0] = sc->gap.left;
|
||||
workareas[i][1] = sc->gap.top;
|
||||
workareas[i][2] = width - (sc->gap.left + sc->gap.right);
|
||||
workareas[i][3] = height - (sc->gap.top + sc->gap.bottom);
|
||||
}
|
||||
|
||||
XChangeProperty(X_Dpy, sc->rootwin, _NET_WORKAREA,
|
||||
XA_CARDINAL, 32, PropModeReplace,
|
||||
(unsigned char *)workareas, CALMWM_NGROUPS * 4);
|
||||
}
|
||||
|
76
search.c
76
search.c
@ -2,6 +2,7 @@
|
||||
* calmwm - the calm window manager
|
||||
*
|
||||
* Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>
|
||||
*
|
||||
* 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.
|
||||
@ -14,15 +15,24 @@
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* $Id$
|
||||
* $OpenBSD$
|
||||
*/
|
||||
|
||||
#include "headers.h"
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fnmatch.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "calmwm.h"
|
||||
|
||||
#define SearchMask (KeyPressMask|ExposureMask)
|
||||
|
||||
static int _strsubmatch(char *, char *, int);
|
||||
static int strsubmatch(char *, char *, int);
|
||||
|
||||
/*
|
||||
* Match: label, title, class.
|
||||
@ -33,13 +43,10 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search)
|
||||
{
|
||||
struct winname *wn;
|
||||
struct menu *mi, *tierp[4], *before = NULL;
|
||||
int ntiers;
|
||||
|
||||
ntiers = sizeof(tierp) / sizeof(tierp[0]);
|
||||
|
||||
TAILQ_INIT(resultq);
|
||||
|
||||
memset(tierp, 0, sizeof(tierp));
|
||||
(void)memset(tierp, 0, sizeof(tierp));
|
||||
|
||||
/*
|
||||
* In order of rank:
|
||||
@ -54,7 +61,7 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search)
|
||||
struct client_ctx *cc = mi->ctx;
|
||||
|
||||
/* First, try to match on labels. */
|
||||
if (cc->label != NULL && _strsubmatch(search, cc->label, 0)) {
|
||||
if (cc->label != NULL && strsubmatch(search, cc->label, 0)) {
|
||||
cc->matchname = cc->label;
|
||||
tier = 0;
|
||||
}
|
||||
@ -62,19 +69,15 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search)
|
||||
/* Then, on window names. */
|
||||
if (tier < 0) {
|
||||
TAILQ_FOREACH_REVERSE(wn, &cc->nameq, winname_q, entry)
|
||||
if (_strsubmatch(search, wn->name, 0)) {
|
||||
if (strsubmatch(search, wn->name, 0)) {
|
||||
cc->matchname = wn->name;
|
||||
tier = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* See if there is a match on the window class
|
||||
* name.
|
||||
*/
|
||||
|
||||
if (tier < 0 && _strsubmatch(search, cc->app_class, 0)) {
|
||||
/* Then if there is a match on the window class name. */
|
||||
if (tier < 0 && strsubmatch(search, cc->app_class, 0)) {
|
||||
cc->matchname = cc->app_class;
|
||||
tier = 3;
|
||||
}
|
||||
@ -87,16 +90,14 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search)
|
||||
* window. Furthermore, this is denoted by a "!" when
|
||||
* printing the window name in the search menu.
|
||||
*/
|
||||
if (cc == client_current() && tier < ntiers - 1)
|
||||
if (cc == client_current() && tier < nitems(tierp) - 1)
|
||||
tier++;
|
||||
|
||||
/*
|
||||
* Clients that are hidden get ranked one up.
|
||||
*/
|
||||
/* Clients that are hidden get ranked one up. */
|
||||
if (cc->flags & CLIENT_HIDDEN && tier > 0)
|
||||
tier--;
|
||||
|
||||
assert(tier < ntiers);
|
||||
assert(tier < nitems(tierp));
|
||||
|
||||
/*
|
||||
* If you have a tierp, insert after it, and make it
|
||||
@ -105,7 +106,6 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search)
|
||||
* Always make your current tierp the newly inserted
|
||||
* entry.
|
||||
*/
|
||||
|
||||
for (t = tier; t >= 0 && ((before = tierp[t]) == NULL); t--)
|
||||
;
|
||||
|
||||
@ -132,9 +132,10 @@ search_print_client(struct menu *mi, int list)
|
||||
flag = '&';
|
||||
|
||||
if (list)
|
||||
cc->matchname = TAILQ_FIRST(&cc->nameq)->name;
|
||||
cc->matchname = cc->name;
|
||||
|
||||
snprintf(mi->print, sizeof(mi->print), "%c%s", flag, cc->matchname);
|
||||
(void)snprintf(mi->print, sizeof(mi->print), "%c%s", flag,
|
||||
cc->matchname);
|
||||
|
||||
if (!list && cc->matchname != cc->name &&
|
||||
strlen(mi->print) < sizeof(mi->print) - 1) {
|
||||
@ -154,8 +155,8 @@ search_print_client(struct menu *mi, int list)
|
||||
diff = strlen(cc->name);
|
||||
}
|
||||
|
||||
strlcpy(buf, mi->print, sizeof(buf));
|
||||
snprintf(mi->print, sizeof(mi->print),
|
||||
(void)strlcpy(buf, mi->print, sizeof(buf));
|
||||
(void)snprintf(mi->print, sizeof(mi->print),
|
||||
"%s:%.*s%s", buf, diff, cc->name, marker);
|
||||
}
|
||||
}
|
||||
@ -168,24 +169,35 @@ search_match_text(struct menu_q *menuq, struct menu_q *resultq, char *search)
|
||||
TAILQ_INIT(resultq);
|
||||
|
||||
TAILQ_FOREACH(mi, menuq, entry)
|
||||
if (_strsubmatch(search, mi->text, 0))
|
||||
if (strsubmatch(search, mi->text, 0))
|
||||
TAILQ_INSERT_TAIL(resultq, mi, resultentry);
|
||||
}
|
||||
|
||||
void
|
||||
search_match_exec(struct menu_q *menuq, struct menu_q *resultq, char *search)
|
||||
{
|
||||
struct menu *mi;
|
||||
struct menu *mi, *mj;
|
||||
|
||||
TAILQ_INIT(resultq);
|
||||
|
||||
TAILQ_FOREACH(mi, menuq, entry)
|
||||
if (_strsubmatch(search, mi->text, 1))
|
||||
TAILQ_FOREACH(mi, menuq, entry) {
|
||||
if (strsubmatch(search, mi->text, 1) == 0 &&
|
||||
fnmatch(search, mi->text, 0) == FNM_NOMATCH)
|
||||
continue;
|
||||
for (mj = TAILQ_FIRST(resultq); mj != NULL;
|
||||
mj = TAILQ_NEXT(mj, resultentry)) {
|
||||
if (strcasecmp(mi->text, mj->text) < 0) {
|
||||
TAILQ_INSERT_BEFORE(mj, mi, resultentry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (mj == NULL)
|
||||
TAILQ_INSERT_TAIL(resultq, mi, resultentry);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
_strsubmatch(char *sub, char *str, int zeroidx)
|
||||
strsubmatch(char *sub, char *str, int zeroidx)
|
||||
{
|
||||
size_t len, sublen;
|
||||
u_int n, flen;
|
||||
|
61
strlcat.c
Normal file
61
strlcat.c
Normal file
@ -0,0 +1,61 @@
|
||||
/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* 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 ORIGINAL: lib/libc/string/strlcat.c */
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Appends src to string dst of size siz (unlike strncat, siz is the
|
||||
* full size of dst, not space left). At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
|
||||
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
|
||||
* If retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcat(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
size_t n = siz;
|
||||
size_t dlen;
|
||||
|
||||
/* Find the end of dst and adjust bytes left but don't go past end */
|
||||
while (n-- != 0 && *d != '\0')
|
||||
d++;
|
||||
dlen = d - dst;
|
||||
n = siz - dlen;
|
||||
|
||||
if (n == 0)
|
||||
return(dlen + strlen(s));
|
||||
while (*s != '\0') {
|
||||
if (n != 1) {
|
||||
*d++ = *s;
|
||||
n--;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
*d = '\0';
|
||||
|
||||
return(dlen + (s - src)); /* count does not include NUL */
|
||||
}
|
||||
|
||||
#endif /* !HAVE_STRLCAT */
|
57
strlcpy.c
Normal file
57
strlcpy.c
Normal file
@ -0,0 +1,57 @@
|
||||
/* $OpenBSD: strlcpy.c,v 1.10 2005/08/08 08:05:37 espie Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* 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 ORIGINAL: lib/libc/string/strlcpy.c */
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Copy src to string dst of size siz. At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz == 0).
|
||||
* Returns strlen(src); if retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcpy(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
size_t n = siz;
|
||||
|
||||
/* Copy as many bytes as will fit */
|
||||
if (n != 0 && --n != 0) {
|
||||
do {
|
||||
if ((*d++ = *s++) == 0)
|
||||
break;
|
||||
} while (--n != 0);
|
||||
}
|
||||
|
||||
/* Not enough room in dst, add NUL and traverse rest of src */
|
||||
if (n == 0) {
|
||||
if (siz != 0)
|
||||
*d = '\0'; /* NUL-terminate dst */
|
||||
while (*s++)
|
||||
;
|
||||
}
|
||||
|
||||
return(s - src - 1); /* count does not include NUL */
|
||||
}
|
||||
|
||||
#endif /* !HAVE_STRLCPY */
|
70
strtonum.c
Normal file
70
strtonum.c
Normal file
@ -0,0 +1,70 @@
|
||||
/* $OpenBSD: strtonum.c,v 1.6 2004/08/03 19:38:01 millert Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004 Ted Unangst and Todd Miller
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 ORIGINAL: lib/libc/stdlib/strtonum.c */
|
||||
|
||||
#ifndef HAVE_STRTONUM
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define INVALID 1
|
||||
#define TOOSMALL 2
|
||||
#define TOOLARGE 3
|
||||
|
||||
long long
|
||||
strtonum(const char *numstr, long long minval, long long maxval,
|
||||
const char **errstrp)
|
||||
{
|
||||
long long ll = 0;
|
||||
char *ep;
|
||||
int error = 0;
|
||||
struct errval {
|
||||
const char *errstr;
|
||||
int err;
|
||||
} ev[4] = {
|
||||
{ NULL, 0 },
|
||||
{ "invalid", EINVAL },
|
||||
{ "too small", ERANGE },
|
||||
{ "too large", ERANGE },
|
||||
};
|
||||
|
||||
ev[0].err = errno;
|
||||
errno = 0;
|
||||
if (minval > maxval)
|
||||
error = INVALID;
|
||||
else {
|
||||
ll = strtoll(numstr, &ep, 10);
|
||||
if (numstr == ep || *ep != '\0')
|
||||
error = INVALID;
|
||||
else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval)
|
||||
error = TOOSMALL;
|
||||
else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval)
|
||||
error = TOOLARGE;
|
||||
}
|
||||
if (errstrp != NULL)
|
||||
*errstrp = ev[error].errstr;
|
||||
errno = ev[error].err;
|
||||
if (error)
|
||||
ll = 0;
|
||||
|
||||
return (ll);
|
||||
}
|
||||
|
||||
#endif /* HAVE_STRTONUM */
|
22
util.c
22
util.c
@ -15,15 +15,24 @@
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* $Id$
|
||||
* $OpenBSD$
|
||||
*/
|
||||
|
||||
#include "headers.h"
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "calmwm.h"
|
||||
|
||||
#define MAXARGLEN 20
|
||||
|
||||
int
|
||||
void
|
||||
u_spawn(char *argstr)
|
||||
{
|
||||
switch (fork()) {
|
||||
@ -33,12 +42,9 @@ u_spawn(char *argstr)
|
||||
break;
|
||||
case -1:
|
||||
warn("fork");
|
||||
return (-1);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
@ -70,6 +76,6 @@ u_exec(char *argstr)
|
||||
}
|
||||
|
||||
*ap = NULL;
|
||||
setsid();
|
||||
execvp(args[0], args);
|
||||
(void)setsid();
|
||||
(void)execvp(args[0], args);
|
||||
}
|
||||
|
477
xevents.c
477
xevents.c
@ -15,7 +15,7 @@
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* $Id$
|
||||
* $OpenBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -24,25 +24,59 @@
|
||||
* management of the xevent's.
|
||||
*/
|
||||
|
||||
#include "headers.h"
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "calmwm.h"
|
||||
|
||||
/*
|
||||
* NOTE: in reality, many of these should move to client.c now that
|
||||
* we've got this nice event layer.
|
||||
*/
|
||||
static void xev_handle_maprequest(XEvent *);
|
||||
static void xev_handle_unmapnotify(XEvent *);
|
||||
static void xev_handle_destroynotify(XEvent *);
|
||||
static void xev_handle_configurerequest(XEvent *);
|
||||
static void xev_handle_propertynotify(XEvent *);
|
||||
static void xev_handle_enternotify(XEvent *);
|
||||
static void xev_handle_leavenotify(XEvent *);
|
||||
static void xev_handle_buttonpress(XEvent *);
|
||||
static void xev_handle_buttonrelease(XEvent *);
|
||||
static void xev_handle_keypress(XEvent *);
|
||||
static void xev_handle_keyrelease(XEvent *);
|
||||
static void xev_handle_expose(XEvent *);
|
||||
static void xev_handle_clientmessage(XEvent *);
|
||||
static void xev_handle_randr(XEvent *);
|
||||
static void xev_handle_mappingnotify(XEvent *);
|
||||
|
||||
void
|
||||
xev_handle_maprequest(struct xevent *xev, XEvent *ee)
|
||||
|
||||
void (*xev_handlers[LASTEvent])(XEvent *) = {
|
||||
[MapRequest] = xev_handle_maprequest,
|
||||
[UnmapNotify] = xev_handle_unmapnotify,
|
||||
[ConfigureRequest] = xev_handle_configurerequest,
|
||||
[PropertyNotify] = xev_handle_propertynotify,
|
||||
[EnterNotify] = xev_handle_enternotify,
|
||||
[LeaveNotify] = xev_handle_leavenotify,
|
||||
[ButtonPress] = xev_handle_buttonpress,
|
||||
[ButtonRelease] = xev_handle_buttonrelease,
|
||||
[KeyPress] = xev_handle_keypress,
|
||||
[KeyRelease] = xev_handle_keyrelease,
|
||||
[Expose] = xev_handle_expose,
|
||||
[DestroyNotify] = xev_handle_destroynotify,
|
||||
[ClientMessage] = xev_handle_clientmessage,
|
||||
[MappingNotify] = xev_handle_mappingnotify,
|
||||
};
|
||||
|
||||
static void
|
||||
xev_handle_maprequest(XEvent *ee)
|
||||
{
|
||||
XMapRequestEvent *e = &ee->xmaprequest;
|
||||
XWindowAttributes xattr;
|
||||
struct client_ctx *cc = NULL, *old_cc;
|
||||
struct screen_ctx *sc;
|
||||
|
||||
#ifdef notyet
|
||||
int state;
|
||||
#endif
|
||||
XWindowAttributes xattr;
|
||||
|
||||
if ((old_cc = client_current()) != NULL)
|
||||
client_ptrsave(old_cc);
|
||||
@ -50,46 +84,51 @@ xev_handle_maprequest(struct xevent *xev, XEvent *ee)
|
||||
if ((cc = client_find(e->window)) == NULL) {
|
||||
XGetWindowAttributes(X_Dpy, e->window, &xattr);
|
||||
cc = client_new(e->window, screen_fromroot(xattr.root), 1);
|
||||
sc = CCTOSC(cc);
|
||||
} else
|
||||
cc->beepbeep = 1;
|
||||
}
|
||||
|
||||
#ifdef notyet /* XXX - possibly, we shouldn't map if
|
||||
* the window is withdrawn. */
|
||||
if (xu_getstate(cc, &state) == 0 && state == WithdrawnState)
|
||||
warnx("WITHDRAWNSTATE for %s", cc->name);
|
||||
#endif
|
||||
|
||||
client_ptrwarp(cc);
|
||||
xev_register(xev);
|
||||
if ((cc->flags & CLIENT_IGNORE) == 0)
|
||||
client_ptrwarp(cc);
|
||||
}
|
||||
|
||||
void
|
||||
xev_handle_unmapnotify(struct xevent *xev, XEvent *ee)
|
||||
static void
|
||||
xev_handle_unmapnotify(XEvent *ee)
|
||||
{
|
||||
XUnmapEvent *e = &ee->xunmap;
|
||||
XEvent ev;
|
||||
struct client_ctx *cc;
|
||||
|
||||
if ((cc = client_find(e->window)) != NULL)
|
||||
client_delete(cc, e->send_event, 0);
|
||||
|
||||
xev_register(xev);
|
||||
/* XXX, we need a recursive locking wrapper around grab server */
|
||||
XGrabServer(X_Dpy);
|
||||
if ((cc = client_find(e->window)) != NULL) {
|
||||
/*
|
||||
* If it's going to die anyway, nuke it.
|
||||
*
|
||||
* Else, if it's a synthetic event delete state, since they
|
||||
* want it to be withdrawn. ICCM recommends you withdraw on
|
||||
* this even if we haven't alredy been told to iconify, to
|
||||
* deal with legacy clients.
|
||||
*/
|
||||
if (XCheckTypedWindowEvent(X_Dpy, cc->win,
|
||||
DestroyNotify, &ev) || e->send_event != 0) {
|
||||
client_delete(cc);
|
||||
} else
|
||||
client_hide(cc);
|
||||
}
|
||||
XUngrabServer(X_Dpy);
|
||||
}
|
||||
|
||||
void
|
||||
xev_handle_destroynotify(struct xevent *xev, XEvent *ee)
|
||||
static void
|
||||
xev_handle_destroynotify(XEvent *ee)
|
||||
{
|
||||
XDestroyWindowEvent *e = &ee->xdestroywindow;
|
||||
struct client_ctx *cc;
|
||||
|
||||
if ((cc = client_find(e->window)) != NULL)
|
||||
client_delete(cc, 1, 1);
|
||||
|
||||
xev_register(xev);
|
||||
client_delete(cc);
|
||||
}
|
||||
|
||||
void
|
||||
xev_handle_configurerequest(struct xevent *xev, XEvent *ee)
|
||||
static void
|
||||
xev_handle_configurerequest(XEvent *ee)
|
||||
{
|
||||
XConfigureRequestEvent *e = &ee->xconfigurerequest;
|
||||
struct client_ctx *cc;
|
||||
@ -97,9 +136,8 @@ xev_handle_configurerequest(struct xevent *xev, XEvent *ee)
|
||||
XWindowChanges wc;
|
||||
|
||||
if ((cc = client_find(e->window)) != NULL) {
|
||||
sc = CCTOSC(cc);
|
||||
sc = cc->sc;
|
||||
|
||||
client_gravitate(cc, 0);
|
||||
if (e->value_mask & CWWidth)
|
||||
cc->geom.width = e->width;
|
||||
if (e->value_mask & CWHeight)
|
||||
@ -108,124 +146,96 @@ xev_handle_configurerequest(struct xevent *xev, XEvent *ee)
|
||||
cc->geom.x = e->x;
|
||||
if (e->value_mask & CWY)
|
||||
cc->geom.y = e->y;
|
||||
if (e->value_mask & CWBorderWidth)
|
||||
wc.border_width = e->border_width;
|
||||
|
||||
if (cc->geom.x == 0 &&
|
||||
cc->geom.width >= DisplayWidth(X_Dpy, sc->which))
|
||||
if (cc->geom.x == 0 && cc->geom.width >= sc->xmax)
|
||||
cc->geom.x -= cc->bwidth;
|
||||
|
||||
if (cc->geom.y == 0 &&
|
||||
cc->geom.height >= DisplayHeight(X_Dpy, sc->which))
|
||||
if (cc->geom.y == 0 && cc->geom.height >= sc->ymax)
|
||||
cc->geom.y -= cc->bwidth;
|
||||
|
||||
client_gravitate(cc, 1);
|
||||
wc.x = cc->geom.x;
|
||||
wc.y = cc->geom.y;
|
||||
wc.width = cc->geom.width;
|
||||
wc.height = cc->geom.height;
|
||||
wc.border_width = cc->bwidth;
|
||||
|
||||
wc.x = cc->geom.x - cc->bwidth;
|
||||
wc.y = cc->geom.y - cc->bwidth;
|
||||
wc.width = cc->geom.width + cc->bwidth*2;
|
||||
wc.height = cc->geom.height + cc->bwidth*2;
|
||||
wc.border_width = 0;
|
||||
XConfigureWindow(X_Dpy, cc->win, e->value_mask, &wc);
|
||||
xu_configure(cc);
|
||||
} else {
|
||||
/* let it do what it wants, it'll be ours when we map it. */
|
||||
wc.x = e->x;
|
||||
wc.y = e->y;
|
||||
wc.width = e->width;
|
||||
wc.height = e->height;
|
||||
wc.border_width = e->border_width;
|
||||
wc.stack_mode = Above;
|
||||
e->value_mask &= ~CWStackMode;
|
||||
|
||||
/* We need to move the parent window, too. */
|
||||
XConfigureWindow(X_Dpy, cc->pwin, e->value_mask, &wc);
|
||||
xev_reconfig(cc);
|
||||
XConfigureWindow(X_Dpy, e->window, e->value_mask, &wc);
|
||||
}
|
||||
|
||||
wc.x = cc != NULL ? cc->bwidth : e->x;
|
||||
wc.y = cc != NULL ? cc->bwidth : e->y;
|
||||
wc.width = e->width;
|
||||
wc.height = e->height;
|
||||
wc.stack_mode = Above;
|
||||
wc.border_width = 0;
|
||||
e->value_mask &= ~CWStackMode;
|
||||
e->value_mask |= CWBorderWidth;
|
||||
|
||||
XConfigureWindow(X_Dpy, e->window, e->value_mask, &wc);
|
||||
|
||||
xev_register(xev);
|
||||
}
|
||||
|
||||
void
|
||||
xev_handle_propertynotify(struct xevent *xev, XEvent *ee)
|
||||
static void
|
||||
xev_handle_propertynotify(XEvent *ee)
|
||||
{
|
||||
XPropertyEvent *e = &ee->xproperty;
|
||||
struct screen_ctx *sc;
|
||||
struct client_ctx *cc;
|
||||
long tmp;
|
||||
|
||||
if ((cc = client_find(e->window)) != NULL) {
|
||||
switch (e->atom) {
|
||||
case XA_WM_NORMAL_HINTS:
|
||||
XGetWMNormalHints(X_Dpy, cc->win, cc->size, &tmp);
|
||||
client_getsizehints(cc);
|
||||
break;
|
||||
case XA_WM_NAME:
|
||||
client_setname(cc);
|
||||
break;
|
||||
case XA_WM_TRANSIENT_FOR:
|
||||
client_transient(cc);
|
||||
break;
|
||||
default:
|
||||
/* do nothing */
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
TAILQ_FOREACH(sc, &Screenq, entry)
|
||||
if (sc->rootwin == e->window)
|
||||
goto test;
|
||||
return;
|
||||
|
||||
test:
|
||||
if (e->atom == _NET_DESKTOP_NAMES)
|
||||
group_update_names(sc);
|
||||
}
|
||||
|
||||
xev_register(xev);
|
||||
}
|
||||
|
||||
void
|
||||
xev_reconfig(struct client_ctx *cc)
|
||||
{
|
||||
XConfigureEvent ce;
|
||||
|
||||
ce.type = ConfigureNotify;
|
||||
ce.event = cc->win;
|
||||
ce.window = cc->win;
|
||||
ce.x = cc->geom.x;
|
||||
ce.y = cc->geom.y;
|
||||
ce.width = cc->geom.width;
|
||||
ce.height = cc->geom.height;
|
||||
ce.border_width = 0;
|
||||
ce.above = None;
|
||||
ce.override_redirect = 0;
|
||||
|
||||
XSendEvent(X_Dpy, cc->win, False, StructureNotifyMask, (XEvent *)&ce);
|
||||
}
|
||||
|
||||
void
|
||||
xev_handle_enternotify(struct xevent *xev, XEvent *ee)
|
||||
static void
|
||||
xev_handle_enternotify(XEvent *ee)
|
||||
{
|
||||
XCrossingEvent *e = &ee->xcrossing;
|
||||
struct client_ctx *cc;
|
||||
|
||||
if ((cc = client_find(e->window)) == NULL) {
|
||||
/*
|
||||
* XXX - later. messes up unclutter. but may be
|
||||
* needed when we introduce menu windows and such into
|
||||
* the main event loop.
|
||||
*/
|
||||
#ifdef notyet
|
||||
if (e->window != e->root)
|
||||
client_nocurrent();
|
||||
#endif
|
||||
} else
|
||||
if ((cc = client_find(e->window)) != NULL)
|
||||
client_setactive(cc, 1);
|
||||
|
||||
xev_register(xev);
|
||||
}
|
||||
|
||||
void
|
||||
xev_handle_leavenotify(struct xevent *xev, XEvent *ee)
|
||||
static void
|
||||
xev_handle_leavenotify(XEvent *ee)
|
||||
{
|
||||
client_leave(NULL);
|
||||
|
||||
xev_register(xev);
|
||||
}
|
||||
|
||||
/* We can split this into two event handlers. */
|
||||
void
|
||||
xev_handle_buttonpress(struct xevent *xev, XEvent *ee)
|
||||
static void
|
||||
xev_handle_buttonpress(XEvent *ee)
|
||||
{
|
||||
XButtonEvent *e = &ee->xbutton;
|
||||
struct client_ctx *cc;
|
||||
struct client_ctx *cc, fakecc;
|
||||
struct screen_ctx *sc;
|
||||
struct mousebinding *mb;
|
||||
char *wname;
|
||||
|
||||
sc = screen_fromroot(e->root);
|
||||
cc = client_find(e->window);
|
||||
@ -239,38 +249,32 @@ xev_handle_buttonpress(struct xevent *xev, XEvent *ee)
|
||||
}
|
||||
|
||||
if (mb == NULL)
|
||||
goto out;
|
||||
|
||||
return;
|
||||
if (mb->context == MOUSEBIND_CTX_ROOT) {
|
||||
if (e->window != sc->rootwin)
|
||||
goto out;
|
||||
} else if (mb->context == MOUSEBIND_CTX_WIN) {
|
||||
cc = client_find(e->window);
|
||||
if (cc == NULL)
|
||||
goto out;
|
||||
}
|
||||
return;
|
||||
cc = &fakecc;
|
||||
cc->sc = screen_fromroot(e->window);
|
||||
} else if (cc == NULL) /* (mb->context == MOUSEBIND_CTX_WIN */
|
||||
return;
|
||||
|
||||
(*mb->callback)(cc, e);
|
||||
out:
|
||||
xev_register(xev);
|
||||
}
|
||||
|
||||
void
|
||||
xev_handle_buttonrelease(struct xevent *xev, XEvent *ee)
|
||||
static void
|
||||
xev_handle_buttonrelease(XEvent *ee)
|
||||
{
|
||||
struct client_ctx *cc;
|
||||
|
||||
if ((cc = client_current()) != NULL)
|
||||
group_sticky_toggle_exit(cc);
|
||||
|
||||
xev_register(xev);
|
||||
}
|
||||
|
||||
void
|
||||
xev_handle_keypress(struct xevent *xev, XEvent *ee)
|
||||
static void
|
||||
xev_handle_keypress(XEvent *ee)
|
||||
{
|
||||
XKeyEvent *e = &ee->xkey;
|
||||
struct client_ctx *cc = NULL;
|
||||
struct client_ctx *cc = NULL, fakecc;
|
||||
struct keybinding *kb;
|
||||
KeySym keysym, skeysym;
|
||||
int modshift;
|
||||
@ -297,25 +301,24 @@ xev_handle_keypress(struct xevent *xev, XEvent *ee)
|
||||
}
|
||||
|
||||
if (kb == NULL)
|
||||
goto out;
|
||||
return;
|
||||
if (kb->flags & KBFLAG_NEEDCLIENT) {
|
||||
if (((cc = client_find(e->window)) == NULL) &&
|
||||
(cc = client_current()) == NULL)
|
||||
return;
|
||||
} else {
|
||||
cc = &fakecc;
|
||||
cc->sc = screen_fromroot(e->window);
|
||||
}
|
||||
|
||||
if ((kb->flags & (KBFLAG_NEEDCLIENT)) &&
|
||||
(cc = client_find(e->window)) == NULL &&
|
||||
(cc = client_current()) == NULL)
|
||||
if (kb->flags & KBFLAG_NEEDCLIENT)
|
||||
goto out;
|
||||
|
||||
(*kb->callback)(cc, kb->argument);
|
||||
|
||||
out:
|
||||
xev_register(xev);
|
||||
(*kb->callback)(cc, &kb->argument);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is only used for the alt suppression detection.
|
||||
*/
|
||||
void
|
||||
xev_handle_keyrelease(struct xevent *xev, XEvent *ee)
|
||||
static void
|
||||
xev_handle_keyrelease(XEvent *ee)
|
||||
{
|
||||
XKeyEvent *e = &ee->xkey;
|
||||
struct screen_ctx *sc;
|
||||
@ -327,7 +330,7 @@ xev_handle_keyrelease(struct xevent *xev, XEvent *ee)
|
||||
|
||||
keysym = XKeycodeToKeysym(X_Dpy, e->keycode, 0);
|
||||
if (keysym != XK_Alt_L && keysym != XK_Alt_R)
|
||||
goto out;
|
||||
return;
|
||||
|
||||
sc->altpersist = 0;
|
||||
|
||||
@ -341,13 +344,10 @@ xev_handle_keyrelease(struct xevent *xev, XEvent *ee)
|
||||
group_sticky_toggle_exit(cc);
|
||||
XUngrabKeyboard(X_Dpy, CurrentTime);
|
||||
}
|
||||
|
||||
out:
|
||||
xev_register(xev);
|
||||
}
|
||||
|
||||
void
|
||||
xev_handle_clientmessage(struct xevent *xev, XEvent *ee)
|
||||
static void
|
||||
xev_handle_clientmessage(XEvent *ee)
|
||||
{
|
||||
XClientMessageEvent *e = &ee->xclient;
|
||||
Atom xa_wm_change_state;
|
||||
@ -356,31 +356,36 @@ xev_handle_clientmessage(struct xevent *xev, XEvent *ee)
|
||||
xa_wm_change_state = XInternAtom(X_Dpy, "WM_CHANGE_STATE", False);
|
||||
|
||||
if ((cc = client_find(e->window)) == NULL)
|
||||
goto out;
|
||||
return;
|
||||
|
||||
if (e->message_type == xa_wm_change_state && e->format == 32 &&
|
||||
e->data.l[0] == IconicState)
|
||||
client_hide(cc);
|
||||
out:
|
||||
xev_register(xev);
|
||||
}
|
||||
|
||||
void
|
||||
xev_handle_shape(struct xevent *xev, XEvent *ee)
|
||||
static void
|
||||
xev_handle_randr(XEvent *ee)
|
||||
{
|
||||
XShapeEvent *sev = (XShapeEvent *) ee;
|
||||
struct client_ctx *cc;
|
||||
XRRScreenChangeNotifyEvent *rev = (XRRScreenChangeNotifyEvent *)ee;
|
||||
struct screen_ctx *sc;
|
||||
int i;
|
||||
|
||||
if ((cc = client_find(sev->window)) != NULL)
|
||||
client_do_shape(cc);
|
||||
i = XRRRootToScreen(X_Dpy, rev->root);
|
||||
TAILQ_FOREACH(sc, &Screenq, entry) {
|
||||
if (sc->which == (u_int)i) {
|
||||
XRRUpdateConfiguration(ee);
|
||||
screen_update_geometry(sc, rev->width, rev->height);
|
||||
screen_init_xinerama(sc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Called when the keymap has changed.
|
||||
* Ungrab all keys, reload keymap and then regrab
|
||||
*/
|
||||
void
|
||||
xev_handle_mapping(struct xevent *xev, XEvent *ee)
|
||||
static void
|
||||
xev_handle_mappingnotify(XEvent *ee)
|
||||
{
|
||||
XMappingEvent *e = &ee->xmapping;
|
||||
struct keybinding *kb;
|
||||
@ -392,162 +397,30 @@ xev_handle_mapping(struct xevent *xev, XEvent *ee)
|
||||
|
||||
TAILQ_FOREACH(kb, &Conf.keybindingq, entry)
|
||||
conf_grab(&Conf, kb);
|
||||
|
||||
xev_register(xev);
|
||||
}
|
||||
|
||||
/*
|
||||
* X Event handling
|
||||
*/
|
||||
|
||||
static struct xevent_q _xevq, _xevq_putaway;
|
||||
static short _xev_q_lock = 0;
|
||||
volatile sig_atomic_t _xev_quit = 0;
|
||||
|
||||
void
|
||||
xev_init(void)
|
||||
{
|
||||
TAILQ_INIT(&_xevq);
|
||||
TAILQ_INIT(&_xevq_putaway);
|
||||
}
|
||||
|
||||
struct xevent *
|
||||
xev_new(Window *win, Window *root,
|
||||
int type, void (*cb)(struct xevent *, XEvent *), void *arg)
|
||||
{
|
||||
struct xevent *xev;
|
||||
|
||||
XMALLOC(xev, struct xevent);
|
||||
xev->xev_win = win;
|
||||
xev->xev_root = root;
|
||||
xev->xev_type = type;
|
||||
xev->xev_cb = cb;
|
||||
xev->xev_arg = arg;
|
||||
|
||||
return (xev);
|
||||
}
|
||||
|
||||
void
|
||||
xev_register(struct xevent *xev)
|
||||
{
|
||||
struct xevent_q *xq;
|
||||
|
||||
xq = _xev_q_lock ? &_xevq_putaway : &_xevq;
|
||||
TAILQ_INSERT_TAIL(xq, xev, entry);
|
||||
}
|
||||
|
||||
void
|
||||
_xev_reincorporate(void)
|
||||
{
|
||||
struct xevent *xev;
|
||||
|
||||
while ((xev = TAILQ_FIRST(&_xevq_putaway)) != NULL) {
|
||||
TAILQ_REMOVE(&_xevq_putaway, xev, entry);
|
||||
TAILQ_INSERT_TAIL(&_xevq, xev, entry);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
xev_handle_expose(struct xevent *xev, XEvent *ee)
|
||||
static void
|
||||
xev_handle_expose(XEvent *ee)
|
||||
{
|
||||
XExposeEvent *e = &ee->xexpose;
|
||||
struct client_ctx *cc;
|
||||
|
||||
if ((cc = client_find(e->window)) != NULL && e->count == 0) {
|
||||
if ((cc = client_find(e->window)) != NULL && e->count == 0)
|
||||
client_draw_border(cc);
|
||||
client_do_shape(cc);
|
||||
}
|
||||
|
||||
xev_register(xev);
|
||||
}
|
||||
|
||||
#define ASSIGN(xtype) do { \
|
||||
root = e. xtype .root; \
|
||||
win = e. xtype .window; \
|
||||
} while (0)
|
||||
|
||||
#define ASSIGN1(xtype) do { \
|
||||
win = e. xtype .window; \
|
||||
} while (0)
|
||||
volatile sig_atomic_t xev_quit = 0;
|
||||
|
||||
void
|
||||
xev_loop(void)
|
||||
{
|
||||
Window win, root;
|
||||
XEvent e;
|
||||
struct xevent *xev = NULL, *nextxev;
|
||||
int type;
|
||||
|
||||
while (_xev_quit == 0) {
|
||||
#ifdef DIAGNOSTIC
|
||||
if (TAILQ_EMPTY(&_xevq))
|
||||
errx(1, "X event queue empty");
|
||||
#endif
|
||||
|
||||
while (xev_quit == 0) {
|
||||
XNextEvent(X_Dpy, &e);
|
||||
type = e.type;
|
||||
|
||||
win = root = 0;
|
||||
|
||||
switch (type) {
|
||||
case MapRequest:
|
||||
ASSIGN1(xmaprequest);
|
||||
break;
|
||||
case UnmapNotify:
|
||||
ASSIGN1(xunmap);
|
||||
break;
|
||||
case ConfigureRequest:
|
||||
ASSIGN1(xconfigurerequest);
|
||||
break;
|
||||
case PropertyNotify:
|
||||
ASSIGN1(xproperty);
|
||||
break;
|
||||
case EnterNotify:
|
||||
case LeaveNotify:
|
||||
ASSIGN(xcrossing);
|
||||
break;
|
||||
case ButtonPress:
|
||||
ASSIGN(xbutton);
|
||||
break;
|
||||
case ButtonRelease:
|
||||
ASSIGN(xbutton);
|
||||
break;
|
||||
case KeyPress:
|
||||
case KeyRelease:
|
||||
ASSIGN(xkey);
|
||||
break;
|
||||
case DestroyNotify:
|
||||
ASSIGN1(xdestroywindow);
|
||||
break;
|
||||
case ClientMessage:
|
||||
ASSIGN1(xclient);
|
||||
break;
|
||||
default:
|
||||
if (e.type == Shape_ev)
|
||||
xev_handle_shape(xev, &e);
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Now, search for matches, and call each of them.
|
||||
*/
|
||||
_xev_q_lock = 1;
|
||||
for (xev = TAILQ_FIRST(&_xevq); xev != NULL; xev = nextxev) {
|
||||
nextxev = TAILQ_NEXT(xev, entry);
|
||||
|
||||
if ((type != xev->xev_type && xev->xev_type != 0) ||
|
||||
(xev->xev_win != NULL && win != *xev->xev_win) ||
|
||||
(xev->xev_root != NULL && root != *xev->xev_root))
|
||||
continue;
|
||||
|
||||
TAILQ_REMOVE(&_xevq, xev, entry);
|
||||
|
||||
(*xev->xev_cb)(xev, &e);
|
||||
}
|
||||
_xev_q_lock = 0;
|
||||
_xev_reincorporate();
|
||||
if (e.type - Randr_ev == RRScreenChangeNotify)
|
||||
xev_handle_randr(&e);
|
||||
else if (e.type < LASTEvent && xev_handlers[e.type] != NULL)
|
||||
(*xev_handlers[e.type])(&e);
|
||||
}
|
||||
}
|
||||
|
||||
#undef ASSIGN
|
||||
#undef ASSIGN1
|
||||
|
13
xmalloc.c
13
xmalloc.c
@ -15,10 +15,19 @@
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* $Id$
|
||||
* $OpenBSD$
|
||||
*/
|
||||
|
||||
#include "headers.h"
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "calmwm.h"
|
||||
|
||||
void *
|
||||
|
178
xutil.c
178
xutil.c
@ -15,13 +15,22 @@
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* $Id$
|
||||
* $OpenBSD$
|
||||
*/
|
||||
|
||||
#include "headers.h"
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "calmwm.h"
|
||||
|
||||
unsigned int ign_mods[] = { 0, LockMask, Mod2Mask, Mod2Mask | LockMask };
|
||||
static unsigned int ign_mods[] = { 0, LockMask, Mod2Mask, Mod2Mask | LockMask };
|
||||
|
||||
int
|
||||
xu_ptr_grab(Window win, int mask, Cursor curs)
|
||||
@ -48,9 +57,9 @@ void
|
||||
xu_btn_grab(Window win, int mask, u_int btn)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < sizeof(ign_mods)/sizeof(*ign_mods); i++)
|
||||
for (i = 0; i < nitems(ign_mods); i++)
|
||||
XGrabButton(X_Dpy, btn, (mask | ign_mods[i]), win,
|
||||
False, ButtonMask, GrabModeAsync,
|
||||
False, BUTTONMASK, GrabModeAsync,
|
||||
GrabModeSync, None, None);
|
||||
}
|
||||
|
||||
@ -58,7 +67,7 @@ void
|
||||
xu_btn_ungrab(Window win, int mask, u_int btn)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < sizeof(ign_mods)/sizeof(*ign_mods); i++)
|
||||
for (i = 0; i < nitems(ign_mods); i++)
|
||||
XUngrabButton(X_Dpy, btn, (mask | ign_mods[i]), win);
|
||||
}
|
||||
|
||||
@ -89,7 +98,7 @@ xu_key_grab(Window win, int mask, int keysym)
|
||||
(XKeycodeToKeysym(X_Dpy, code, 1) == keysym))
|
||||
mask |= ShiftMask;
|
||||
|
||||
for (i = 0; i < sizeof(ign_mods)/sizeof(*ign_mods); i++)
|
||||
for (i = 0; i < nitems(ign_mods); i++)
|
||||
XGrabKey(X_Dpy, code, (mask | ign_mods[i]), win,
|
||||
True, GrabModeAsync, GrabModeAsync);
|
||||
}
|
||||
@ -105,34 +114,53 @@ xu_key_ungrab(Window win, int mask, int keysym)
|
||||
(XKeycodeToKeysym(X_Dpy, code, 1) == keysym))
|
||||
mask |= ShiftMask;
|
||||
|
||||
for (i = 0; i < sizeof(ign_mods)/sizeof(*ign_mods); i++)
|
||||
for (i = 0; i < nitems(ign_mods); i++)
|
||||
XUngrabKey(X_Dpy, code, (mask | ign_mods[i]), win);
|
||||
}
|
||||
|
||||
void
|
||||
xu_sendmsg(struct client_ctx *cc, Atom atm, long val)
|
||||
xu_configure(struct client_ctx *cc)
|
||||
{
|
||||
XConfigureEvent ce;
|
||||
|
||||
ce.type = ConfigureNotify;
|
||||
ce.event = cc->win;
|
||||
ce.window = cc->win;
|
||||
ce.x = cc->geom.x;
|
||||
ce.y = cc->geom.y;
|
||||
ce.width = cc->geom.width;
|
||||
ce.height = cc->geom.height;
|
||||
ce.border_width = cc->bwidth;
|
||||
ce.above = None;
|
||||
ce.override_redirect = 0;
|
||||
|
||||
XSendEvent(X_Dpy, cc->win, False, StructureNotifyMask, (XEvent *)&ce);
|
||||
}
|
||||
|
||||
void
|
||||
xu_sendmsg(Window win, Atom atm, long val)
|
||||
{
|
||||
XEvent e;
|
||||
|
||||
memset(&e, 0, sizeof(e));
|
||||
(void)memset(&e, 0, sizeof(e));
|
||||
e.xclient.type = ClientMessage;
|
||||
e.xclient.window = cc->win;
|
||||
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;
|
||||
|
||||
XSendEvent(X_Dpy, cc->win, False, 0, &e);
|
||||
XSendEvent(X_Dpy, win, False, 0, &e);
|
||||
}
|
||||
|
||||
int
|
||||
xu_getprop(struct client_ctx *cc, Atom atm, Atom type, long len, u_char **p)
|
||||
xu_getprop(Window win, Atom atm, Atom type, long len, u_char **p)
|
||||
{
|
||||
Atom realtype;
|
||||
u_long n, extra;
|
||||
int format;
|
||||
|
||||
if (XGetWindowProperty(X_Dpy, cc->win, atm, 0L, len, False, type,
|
||||
if (XGetWindowProperty(X_Dpy, win, atm, 0L, len, False, type,
|
||||
&realtype, &format, &n, &extra, p) != Success || *p == NULL)
|
||||
return (-1);
|
||||
|
||||
@ -142,15 +170,44 @@ xu_getprop(struct client_ctx *cc, Atom atm, Atom type, long len, u_char **p)
|
||||
return (n);
|
||||
}
|
||||
|
||||
int
|
||||
xu_getstrprop(Window win, Atom atm, char **text) {
|
||||
XTextProperty prop;
|
||||
char **list;
|
||||
int nitems = 0;
|
||||
|
||||
*text = NULL;
|
||||
|
||||
XGetTextProperty(X_Dpy, win, &prop, atm);
|
||||
if (!prop.nitems)
|
||||
return (0);
|
||||
|
||||
if (Xutf8TextPropertyToTextList(X_Dpy, &prop, &list,
|
||||
&nitems) == Success && nitems > 0 && *list) {
|
||||
if (nitems > 1) {
|
||||
XTextProperty prop2;
|
||||
if (Xutf8TextListToTextProperty(X_Dpy, list, nitems,
|
||||
XUTF8StringStyle, &prop2) == Success) {
|
||||
*text = xstrdup(prop2.value);
|
||||
XFree(prop2.value);
|
||||
}
|
||||
} else {
|
||||
*text = xstrdup(*list);
|
||||
}
|
||||
XFreeStringList(list);
|
||||
}
|
||||
|
||||
XFree(prop.value);
|
||||
|
||||
return (nitems);
|
||||
}
|
||||
|
||||
int
|
||||
xu_getstate(struct client_ctx *cc, int *state)
|
||||
{
|
||||
Atom wm_state;
|
||||
long *p = NULL;
|
||||
|
||||
wm_state = XInternAtom(X_Dpy, "WM_STATE", False);
|
||||
|
||||
if (xu_getprop(cc, wm_state, wm_state, 2L, (u_char **)&p) <= 0)
|
||||
if (xu_getprop(cc->win, WM_STATE, WM_STATE, 2L, (u_char **)&p) <= 0)
|
||||
return (-1);
|
||||
|
||||
*state = (int)*p;
|
||||
@ -162,16 +219,87 @@ xu_getstate(struct client_ctx *cc, int *state)
|
||||
void
|
||||
xu_setstate(struct client_ctx *cc, int state)
|
||||
{
|
||||
Atom wm_state;
|
||||
long dat[2];
|
||||
|
||||
/* XXX cache */
|
||||
wm_state = XInternAtom(X_Dpy, "WM_STATE", False);
|
||||
|
||||
dat[0] = (long)state;
|
||||
dat[1] = (long)None;
|
||||
dat[0] = state;
|
||||
dat[1] = None;
|
||||
|
||||
cc->state = state;
|
||||
XChangeProperty(X_Dpy, cc->win, wm_state, wm_state, 32,
|
||||
XChangeProperty(X_Dpy, cc->win, WM_STATE, WM_STATE, 32,
|
||||
PropModeReplace, (unsigned char *)dat, 2);
|
||||
}
|
||||
|
||||
Atom cwm_atoms[CWM_NO_ATOMS];
|
||||
char *atoms[CWM_NO_ATOMS] = {
|
||||
"WM_STATE",
|
||||
"WM_DELETE_WINDOW",
|
||||
"WM_TAKE_FOCUS",
|
||||
"WM_PROTOCOLS",
|
||||
"_MOTIF_WM_HINTS",
|
||||
"UTF8_STRING",
|
||||
"_NET_SUPPORTED",
|
||||
"_NET_SUPPORTING_WM_CHECK",
|
||||
"_NET_WM_NAME",
|
||||
"_NET_ACTIVE_WINDOW",
|
||||
"_NET_CLIENT_LIST",
|
||||
"_NET_NUMBER_OF_DESKTOPS",
|
||||
"_NET_CURRENT_DESKTOP",
|
||||
"_NET_DESKTOP_VIEWPORT",
|
||||
"_NET_DESKTOP_GEOMETRY",
|
||||
"_NET_VIRTUAL_ROOTS",
|
||||
"_NET_SHOWING_DESKTOP",
|
||||
"_NET_DESKTOP_NAMES",
|
||||
"_NET_WM_DESKTOP",
|
||||
"_NET_WORKAREA",
|
||||
};
|
||||
|
||||
void
|
||||
xu_getatoms(void)
|
||||
{
|
||||
XInternAtoms(X_Dpy, atoms, CWM_NO_ATOMS, False, cwm_atoms);
|
||||
}
|
||||
|
||||
void
|
||||
xu_setwmname(struct screen_ctx *sc)
|
||||
{
|
||||
/*
|
||||
* set up the _NET_SUPPORTED hint with all netwm atoms that we
|
||||
* know about.
|
||||
*/
|
||||
XChangeProperty(X_Dpy, sc->rootwin, _NET_SUPPORTED, XA_ATOM, 32,
|
||||
PropModeReplace, (unsigned char *)&_NET_SUPPORTED,
|
||||
CWM_NO_ATOMS - CWM_NETWM_START);
|
||||
/*
|
||||
* netwm spec says that to prove that the hint is not stale you must
|
||||
* provide _NET_SUPPORTING_WM_CHECK containing a window (we use the
|
||||
* menu window). The property must be set on the root window and the
|
||||
* window itself, the window also must have _NET_WM_NAME set with the
|
||||
* window manager name.
|
||||
*/
|
||||
XChangeProperty(X_Dpy, sc->rootwin, _NET_SUPPORTING_WM_CHECK,
|
||||
XA_WINDOW, 32, PropModeReplace, (unsigned char *)&sc->menuwin, 1);
|
||||
XChangeProperty(X_Dpy, sc->menuwin, _NET_SUPPORTING_WM_CHECK,
|
||||
XA_WINDOW, 32, PropModeReplace, (unsigned char *)&sc->menuwin, 1);
|
||||
XChangeProperty(X_Dpy, sc->menuwin, _NET_WM_NAME, UTF8_STRING,
|
||||
8, PropModeReplace, WMNAME, strlen(WMNAME));
|
||||
}
|
||||
|
||||
unsigned long
|
||||
xu_getcolor(struct screen_ctx *sc, char *name)
|
||||
{
|
||||
XColor color, tmp;
|
||||
|
||||
if (!XAllocNamedColor(X_Dpy, DefaultColormap(X_Dpy, sc->which),
|
||||
name, &color, &tmp)) {
|
||||
warnx("XAllocNamedColor error: '%s'", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return color.pixel;
|
||||
}
|
||||
|
||||
void
|
||||
xu_freecolor(struct screen_ctx *sc, unsigned long pixel)
|
||||
{
|
||||
XFreeColors(X_Dpy, DefaultColormap(X_Dpy, sc->which), &pixel, 1, 0L);
|
||||
}
|
||||
|
Reference in New Issue
Block a user