2007-04-27 11:58:48 -06:00
|
|
|
/*
|
|
|
|
* calmwm - the calm window manager
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>
|
|
|
|
*
|
2008-01-11 09:06:44 -07:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
2012-05-15 19:17:14 -06:00
|
|
|
* $OpenBSD: calmwm.c,v 1.61 2012/05/16 01:17:14 okan Exp $
|
2007-04-27 11:58:48 -06:00
|
|
|
*/
|
|
|
|
|
2009-12-14 21:10:42 -07:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
2009-12-14 20:34:34 -07:00
|
|
|
#include <getopt.h>
|
|
|
|
#include <signal.h>
|
2009-12-14 21:10:42 -07:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
2009-12-14 20:34:34 -07:00
|
|
|
|
2007-04-27 11:58:48 -06:00
|
|
|
#include "calmwm.h"
|
|
|
|
|
2007-05-28 12:34:27 -06:00
|
|
|
Display *X_Dpy;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2007-05-28 12:34:27 -06:00
|
|
|
Cursor Cursor_default;
|
2011-06-24 00:52:23 -06:00
|
|
|
Cursor Cursor_move;
|
|
|
|
Cursor Cursor_normal;
|
2007-05-28 12:34:27 -06:00
|
|
|
Cursor Cursor_question;
|
2011-06-24 00:52:23 -06:00
|
|
|
Cursor Cursor_resize;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2009-08-24 15:22:48 -06:00
|
|
|
struct screen_ctx_q Screenq = TAILQ_HEAD_INITIALIZER(Screenq);
|
|
|
|
struct client_ctx_q Clientq = TAILQ_HEAD_INITIALIZER(Clientq);
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2008-09-29 17:16:46 -06:00
|
|
|
int HasXinerama, HasRandr, Randr_ev;
|
2007-05-28 12:34:27 -06:00
|
|
|
struct conf Conf;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2009-05-17 18:23:35 -06:00
|
|
|
static void sigchld_cb(int);
|
2008-07-22 14:42:24 -06:00
|
|
|
static void dpy_init(const char *);
|
2009-06-26 06:21:58 -06:00
|
|
|
static int x_errorhandler(Display *, XErrorEvent *);
|
2011-06-23 23:58:51 -06:00
|
|
|
static int x_wmerrorhandler(Display *, XErrorEvent *);
|
2009-04-15 08:01:45 -06:00
|
|
|
static void x_setup(void);
|
|
|
|
static void x_setupscreen(struct screen_ctx *, u_int);
|
|
|
|
static void x_teardown(void);
|
2007-04-27 11:58:48 -06:00
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
const char *conf_file = NULL;
|
|
|
|
char *display_name = NULL;
|
|
|
|
int ch;
|
2007-05-10 11:23:49 -06:00
|
|
|
|
2008-03-23 09:09:21 -06:00
|
|
|
while ((ch = getopt(argc, argv, "c:d:")) != -1) {
|
2007-04-27 11:58:48 -06:00
|
|
|
switch (ch) {
|
2008-03-23 09:09:21 -06:00
|
|
|
case 'c':
|
2008-05-19 12:53:09 -06:00
|
|
|
conf_file = optarg;
|
2008-03-23 09:09:21 -06:00
|
|
|
break;
|
2007-05-10 11:23:49 -06:00
|
|
|
case 'd':
|
|
|
|
display_name = optarg;
|
|
|
|
break;
|
2007-04-27 11:58:48 -06:00
|
|
|
default:
|
2008-02-13 14:04:19 -07:00
|
|
|
usage();
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
}
|
2007-05-10 11:23:49 -06:00
|
|
|
argc -= optind;
|
2007-05-21 01:53:11 -06:00
|
|
|
argv += optind;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2009-05-17 18:23:35 -06:00
|
|
|
if (signal(SIGCHLD, sigchld_cb) == SIG_ERR)
|
2008-04-15 14:24:41 -06:00
|
|
|
err(1, "signal");
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2008-07-22 14:42:24 -06:00
|
|
|
dpy_init(display_name);
|
2009-06-23 15:52:38 -06:00
|
|
|
|
2008-04-15 12:22:08 -06:00
|
|
|
bzero(&Conf, sizeof(Conf));
|
2008-05-19 12:53:09 -06:00
|
|
|
conf_setup(&Conf, conf_file);
|
2009-01-22 08:26:33 -07:00
|
|
|
xu_getatoms();
|
2008-07-22 14:42:24 -06:00
|
|
|
x_setup();
|
2007-04-27 11:58:48 -06:00
|
|
|
|
|
|
|
xev_loop();
|
|
|
|
|
2009-04-15 08:01:45 -06:00
|
|
|
x_teardown();
|
|
|
|
|
2007-04-27 11:58:48 -06:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2009-06-26 06:21:58 -06:00
|
|
|
static void
|
2008-07-22 14:42:24 -06:00
|
|
|
dpy_init(const char *dpyname)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
2008-07-22 14:42:24 -06:00
|
|
|
int i;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2011-06-23 23:58:51 -06:00
|
|
|
XSetErrorHandler(x_errorhandler);
|
|
|
|
|
2008-07-22 14:42:24 -06:00
|
|
|
if ((X_Dpy = XOpenDisplay(dpyname)) == NULL)
|
2008-02-13 05:09:47 -07:00
|
|
|
errx(1, "unable to open display \"%s\"",
|
2008-07-22 14:42:24 -06:00
|
|
|
XDisplayName(dpyname));
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2011-06-23 23:58:51 -06:00
|
|
|
XSetErrorHandler(x_wmerrorhandler);
|
|
|
|
XSelectInput(X_Dpy, DefaultRootWindow(X_Dpy), SubstructureRedirectMask);
|
|
|
|
XSync(X_Dpy, False);
|
2007-04-27 11:58:48 -06:00
|
|
|
XSetErrorHandler(x_errorhandler);
|
|
|
|
|
2008-09-29 17:16:46 -06:00
|
|
|
HasRandr = XRRQueryExtension(X_Dpy, &Randr_ev, &i);
|
2008-07-22 14:42:24 -06:00
|
|
|
}
|
|
|
|
|
2009-06-26 06:21:58 -06:00
|
|
|
static void
|
2008-07-22 14:42:24 -06:00
|
|
|
x_setup(void)
|
|
|
|
{
|
|
|
|
struct screen_ctx *sc;
|
2008-07-22 14:51:54 -06:00
|
|
|
struct keybinding *kb;
|
2008-07-22 14:42:24 -06:00
|
|
|
int i;
|
|
|
|
|
2011-06-24 00:52:23 -06:00
|
|
|
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);
|
|
|
|
|
2009-01-26 19:16:20 -07:00
|
|
|
for (i = 0; i < ScreenCount(X_Dpy); i++) {
|
2009-06-19 18:22:39 -06:00
|
|
|
sc = xcalloc(1, sizeof(*sc));
|
2007-04-27 11:58:48 -06:00
|
|
|
x_setupscreen(sc, i);
|
2007-05-28 12:34:27 -06:00
|
|
|
TAILQ_INSERT_TAIL(&Screenq, sc, entry);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
2008-07-22 14:51:54 -06:00
|
|
|
/*
|
|
|
|
* XXX key grabs weren't done before, since Screenq was empty,
|
|
|
|
* do them here for now (this needs changing).
|
|
|
|
*/
|
|
|
|
TAILQ_FOREACH(kb, &Conf.keybindingq, entry)
|
|
|
|
conf_grab(&Conf, kb);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
2009-06-26 06:21:58 -06:00
|
|
|
static void
|
2009-04-15 08:01:45 -06:00
|
|
|
x_teardown(void)
|
|
|
|
{
|
|
|
|
struct screen_ctx *sc;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(sc, &Screenq, entry)
|
|
|
|
XFreeGC(X_Dpy, sc->gc);
|
|
|
|
|
|
|
|
XCloseDisplay(X_Dpy);
|
|
|
|
}
|
|
|
|
|
2009-06-26 06:21:58 -06:00
|
|
|
static void
|
2007-04-27 11:58:48 -06:00
|
|
|
x_setupscreen(struct screen_ctx *sc, u_int which)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
Window *wins, w0, w1;
|
|
|
|
XWindowAttributes winattr;
|
|
|
|
XSetWindowAttributes rootattr;
|
2008-09-29 17:16:46 -06:00
|
|
|
int fake;
|
2009-12-10 16:14:58 -07:00
|
|
|
u_int nwins, i;
|
2012-05-13 09:15:54 -06:00
|
|
|
|
2007-04-27 11:58:48 -06:00
|
|
|
sc->which = which;
|
2009-05-17 17:40:57 -06:00
|
|
|
sc->rootwin = RootWindow(X_Dpy, sc->which);
|
2009-12-10 16:14:58 -07:00
|
|
|
|
2012-05-15 19:17:14 -06:00
|
|
|
xu_ewmh_net_supported(sc);
|
|
|
|
xu_ewmh_net_supported_wm_check(sc);
|
|
|
|
|
2010-01-26 20:04:50 -07:00
|
|
|
conf_gap(&Conf, sc);
|
2009-12-10 16:14:58 -07:00
|
|
|
screen_update_geometry(sc, DisplayWidth(X_Dpy, sc->which),
|
|
|
|
DisplayHeight(X_Dpy, sc->which));
|
2008-05-20 08:50:51 -06:00
|
|
|
|
2009-12-08 09:52:17 -07:00
|
|
|
conf_color(&Conf, sc);
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2009-12-10 10:16:51 -07:00
|
|
|
group_init(sc);
|
2009-12-08 09:52:17 -07:00
|
|
|
conf_font(&Conf, sc);
|
2007-04-27 11:58:48 -06:00
|
|
|
|
|
|
|
TAILQ_INIT(&sc->mruq);
|
|
|
|
|
|
|
|
/* Initialize menu window. */
|
2008-05-21 08:11:19 -06:00
|
|
|
menu_init(sc);
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2011-06-24 00:52:23 -06:00
|
|
|
rootattr.cursor = Cursor_normal;
|
2011-07-23 07:09:11 -06:00
|
|
|
rootattr.event_mask = CHILDMASK|PropertyChangeMask|EnterWindowMask|
|
|
|
|
LeaveWindowMask|ColormapChangeMask|BUTTONMASK;
|
2010-04-12 10:17:46 -06:00
|
|
|
|
|
|
|
XChangeWindowAttributes(X_Dpy, sc->rootwin,
|
2011-06-24 00:52:23 -06:00
|
|
|
CWEventMask|CWCursor, &rootattr);
|
2010-04-12 10:17:46 -06:00
|
|
|
|
2007-04-27 11:58:48 -06:00
|
|
|
/* Deal with existing clients. */
|
2008-04-15 14:24:41 -06:00
|
|
|
XQueryTree(X_Dpy, sc->rootwin, &w0, &w1, &wins, &nwins);
|
2007-04-27 11:58:48 -06:00
|
|
|
|
|
|
|
for (i = 0; i < nwins; i++) {
|
2007-05-28 12:34:27 -06:00
|
|
|
XGetWindowAttributes(X_Dpy, wins[i], &winattr);
|
2007-04-27 11:58:48 -06:00
|
|
|
if (winattr.override_redirect ||
|
2009-01-15 10:23:12 -07:00
|
|
|
winattr.map_state != IsViewable)
|
2007-04-27 11:58:48 -06:00
|
|
|
continue;
|
2011-07-25 09:10:24 -06:00
|
|
|
(void)client_new(wins[i], sc, winattr.map_state != IsUnmapped);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
XFree(wins);
|
|
|
|
|
2009-12-10 10:16:51 -07:00
|
|
|
screen_updatestackingorder(sc);
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2008-09-29 17:16:46 -06:00
|
|
|
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);
|
|
|
|
|
2007-05-28 12:34:27 -06:00
|
|
|
XSync(X_Dpy, False);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
2011-06-23 23:58:51 -06:00
|
|
|
static int
|
|
|
|
x_wmerrorhandler(Display *dpy, XErrorEvent *e)
|
|
|
|
{
|
|
|
|
errx(1, "root window unavailable - perhaps another wm is running?");
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2012-05-13 09:15:54 -06:00
|
|
|
|
2009-06-26 06:21:58 -06:00
|
|
|
static int
|
2007-04-27 11:58:48 -06:00
|
|
|
x_errorhandler(Display *dpy, XErrorEvent *e)
|
|
|
|
{
|
2011-06-23 23:58:51 -06:00
|
|
|
#if DEBUG
|
|
|
|
char msg[80], number[80], req[80];
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2011-06-23 23:58:51 -06:00
|
|
|
XGetErrorText(X_Dpy, e->error_code, msg, sizeof(msg));
|
2011-07-25 09:10:24 -06:00
|
|
|
(void)snprintf(number, sizeof(number), "%d", e->request_code);
|
2011-06-23 23:58:51 -06:00
|
|
|
XGetErrorDatabaseText(X_Dpy, "XRequest", number,
|
|
|
|
"<unknown>", req, sizeof(req));
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2011-06-23 23:58:51 -06:00
|
|
|
warnx("%s(0x%x): %s", req, (u_int)e->resourceid, msg);
|
2007-04-27 11:58:48 -06:00
|
|
|
#endif
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-17 18:23:35 -06:00
|
|
|
sigchld_cb(int which)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
pid_t pid;
|
|
|
|
int save_errno = errno;
|
|
|
|
int status;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2008-04-15 14:24:41 -06:00
|
|
|
/* Collect dead children. */
|
|
|
|
while ((pid = waitpid(-1, &status, WNOHANG)) > 0 ||
|
|
|
|
(pid < 0 && errno == EINTR))
|
2007-04-27 11:58:48 -06:00
|
|
|
;
|
2008-05-06 09:12:04 -06:00
|
|
|
|
|
|
|
errno = save_errno;
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
2008-02-13 14:04:19 -07:00
|
|
|
|
2008-02-13 14:48:03 -07:00
|
|
|
__dead void
|
2008-02-13 14:04:19 -07:00
|
|
|
usage(void)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
extern char *__progname;
|
2008-02-13 14:04:19 -07:00
|
|
|
|
2011-07-25 09:10:24 -06:00
|
|
|
(void)fprintf(stderr, "usage: %s [-c file] [-d display]\n",
|
|
|
|
__progname);
|
2008-02-13 14:04:19 -07:00
|
|
|
exit(1);
|
|
|
|
}
|