mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
cvsimport
* refs/heads/master: Do not print any parse errors when ~/.cwmrc is missing. Regression introduced in revision 1.109 of calmwm.c. Store the screen's visual type and colormap. Consolidate region 'view' and 'area'. limit scope of screen_apply_gap() Clean up conf_file/homedir and conf_init() bits.
This commit is contained in:
41
calmwm.c
41
calmwm.c
@@ -28,7 +28,6 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <pwd.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -54,23 +53,24 @@ static int x_wmerrorhandler(Display *, XErrorEvent *);
|
|||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
const char *conf_file = NULL;
|
char *display_name = NULL;
|
||||||
char *conf_path, *display_name = NULL;
|
|
||||||
char *fallback;
|
char *fallback;
|
||||||
int ch, xfd;
|
int ch, xfd;
|
||||||
struct pollfd pfd[1];
|
struct pollfd pfd[1];
|
||||||
struct passwd *pw;
|
|
||||||
|
|
||||||
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
||||||
warnx("no locale support");
|
warnx("no locale support");
|
||||||
mbtowc(NULL, NULL, MB_CUR_MAX);
|
mbtowc(NULL, NULL, MB_CUR_MAX);
|
||||||
|
|
||||||
|
conf_init(&Conf);
|
||||||
|
|
||||||
fallback = u_argv(argv);
|
fallback = u_argv(argv);
|
||||||
Conf.wm_argv = u_argv(argv);
|
Conf.wm_argv = u_argv(argv);
|
||||||
while ((ch = getopt(argc, argv, "c:d:v")) != -1) {
|
while ((ch = getopt(argc, argv, "c:d:v")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'c':
|
case 'c':
|
||||||
conf_file = optarg;
|
free(Conf.conf_file);
|
||||||
|
Conf.conf_file = xstrdup(optarg);
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
display_name = optarg;
|
display_name = optarg;
|
||||||
@@ -90,32 +90,8 @@ main(int argc, char **argv)
|
|||||||
if (signal(SIGHUP, sighdlr) == SIG_ERR)
|
if (signal(SIGHUP, sighdlr) == SIG_ERR)
|
||||||
err(1, "signal");
|
err(1, "signal");
|
||||||
|
|
||||||
Conf.homedir = getenv("HOME");
|
if (parse_config(Conf.conf_file, &Conf) == -1)
|
||||||
if ((Conf.homedir == NULL) || (Conf.homedir[0] == '\0')) {
|
warnx("error parsing config file");
|
||||||
pw = getpwuid(getuid());
|
|
||||||
if (pw != NULL && pw->pw_dir != NULL && *pw->pw_dir != '\0')
|
|
||||||
Conf.homedir = pw->pw_dir;
|
|
||||||
else
|
|
||||||
Conf.homedir = "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (conf_file == NULL)
|
|
||||||
xasprintf(&conf_path, "%s/%s", Conf.homedir, CONFFILE);
|
|
||||||
else
|
|
||||||
conf_path = xstrdup(conf_file);
|
|
||||||
|
|
||||||
if (access(conf_path, R_OK) != 0) {
|
|
||||||
if (conf_file != NULL)
|
|
||||||
warn("%s", conf_file);
|
|
||||||
free(conf_path);
|
|
||||||
conf_path = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
conf_init(&Conf);
|
|
||||||
|
|
||||||
if (conf_path && (parse_config(conf_path, &Conf) == -1))
|
|
||||||
warnx("config file %s has errors", conf_path);
|
|
||||||
free(conf_path);
|
|
||||||
|
|
||||||
xfd = x_init(display_name);
|
xfd = x_init(display_name);
|
||||||
cwm_status = CWM_RUNNING;
|
cwm_status = CWM_RUNNING;
|
||||||
@@ -138,7 +114,7 @@ main(int argc, char **argv)
|
|||||||
x_teardown();
|
x_teardown();
|
||||||
if (cwm_status == CWM_EXEC_WM) {
|
if (cwm_status == CWM_EXEC_WM) {
|
||||||
u_exec(Conf.wm_argv);
|
u_exec(Conf.wm_argv);
|
||||||
warnx("'%s' failed to start, restarting fallback", Conf.wm_argv);
|
warnx("'%s' failed to start, starting fallback", Conf.wm_argv);
|
||||||
u_exec(fallback);
|
u_exec(fallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +176,6 @@ static int
|
|||||||
x_wmerrorhandler(Display *dpy, XErrorEvent *e)
|
x_wmerrorhandler(Display *dpy, XErrorEvent *e)
|
||||||
{
|
{
|
||||||
errx(1, "root window unavailable - perhaps another wm is running?");
|
errx(1, "root window unavailable - perhaps another wm is running?");
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
10
calmwm.h
10
calmwm.h
@@ -66,8 +66,6 @@ size_t strlcpy(char *, const char *, size_t);
|
|||||||
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
|
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CONFFILE ".cwmrc"
|
|
||||||
|
|
||||||
#define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
|
#define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
|
||||||
#define MOUSEMASK (BUTTONMASK | PointerMotionMask)
|
#define MOUSEMASK (BUTTONMASK | PointerMotionMask)
|
||||||
#define MENUMASK (MOUSEMASK | ButtonMotionMask | KeyPressMask | \
|
#define MENUMASK (MOUSEMASK | ButtonMotionMask | KeyPressMask | \
|
||||||
@@ -227,7 +225,6 @@ TAILQ_HEAD(autogroup_q, autogroup);
|
|||||||
struct region_ctx {
|
struct region_ctx {
|
||||||
TAILQ_ENTRY(region_ctx) entry;
|
TAILQ_ENTRY(region_ctx) entry;
|
||||||
int num;
|
int num;
|
||||||
struct geom area;
|
|
||||||
struct geom view; /* viewable area */
|
struct geom view; /* viewable area */
|
||||||
struct geom work; /* workable area, gap-applied */
|
struct geom work; /* workable area, gap-applied */
|
||||||
};
|
};
|
||||||
@@ -247,6 +244,8 @@ struct screen_ctx {
|
|||||||
struct region_q regionq;
|
struct region_q regionq;
|
||||||
struct group_q groupq;
|
struct group_q groupq;
|
||||||
struct group_ctx *group_active;
|
struct group_ctx *group_active;
|
||||||
|
Colormap colormap;
|
||||||
|
Visual *visual;
|
||||||
struct {
|
struct {
|
||||||
Window win;
|
Window win;
|
||||||
XftDraw *xftdraw;
|
XftDraw *xftdraw;
|
||||||
@@ -329,10 +328,10 @@ struct conf {
|
|||||||
Cursor cursor[CF_NITEMS];
|
Cursor cursor[CF_NITEMS];
|
||||||
int xrandr;
|
int xrandr;
|
||||||
int xrandr_event_base;
|
int xrandr_event_base;
|
||||||
char *homedir;
|
char *conf_file;
|
||||||
char *known_hosts;
|
char *known_hosts;
|
||||||
char *wm_argv;
|
char *wm_argv;
|
||||||
u_int32_t debug;
|
int debug;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* MWM hints */
|
/* MWM hints */
|
||||||
@@ -499,7 +498,6 @@ void search_print_text(struct menu *, int);
|
|||||||
void search_print_wm(struct menu *, int);
|
void search_print_wm(struct menu *, int);
|
||||||
|
|
||||||
struct region_ctx *region_find(struct screen_ctx *, int, int);
|
struct region_ctx *region_find(struct screen_ctx *, int, int);
|
||||||
struct geom screen_apply_gap(struct screen_ctx *, struct geom);
|
|
||||||
struct screen_ctx *screen_find(Window);
|
struct screen_ctx *screen_find(Window);
|
||||||
struct geom screen_area(struct screen_ctx *, int, int,
|
struct geom screen_area(struct screen_ctx *, int, int,
|
||||||
enum apply_gap);
|
enum apply_gap);
|
||||||
|
|||||||
38
conf.c
38
conf.c
@@ -25,6 +25,7 @@
|
|||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <pwd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -248,6 +249,8 @@ mouse_binds[] = {
|
|||||||
void
|
void
|
||||||
conf_init(struct conf *c)
|
conf_init(struct conf *c)
|
||||||
{
|
{
|
||||||
|
const char *home;
|
||||||
|
struct passwd *pw;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
c->stickygroups = 0;
|
c->stickygroups = 0;
|
||||||
@@ -258,11 +261,11 @@ conf_init(struct conf *c)
|
|||||||
c->nameqlen = 5;
|
c->nameqlen = 5;
|
||||||
|
|
||||||
TAILQ_INIT(&c->ignoreq);
|
TAILQ_INIT(&c->ignoreq);
|
||||||
|
TAILQ_INIT(&c->autogroupq);
|
||||||
|
TAILQ_INIT(&c->keybindq);
|
||||||
|
TAILQ_INIT(&c->mousebindq);
|
||||||
TAILQ_INIT(&c->cmdq);
|
TAILQ_INIT(&c->cmdq);
|
||||||
TAILQ_INIT(&c->wmq);
|
TAILQ_INIT(&c->wmq);
|
||||||
TAILQ_INIT(&c->keybindq);
|
|
||||||
TAILQ_INIT(&c->autogroupq);
|
|
||||||
TAILQ_INIT(&c->mousebindq);
|
|
||||||
|
|
||||||
for (i = 0; i < nitems(key_binds); i++)
|
for (i = 0; i < nitems(key_binds); i++)
|
||||||
conf_bind_key(c, key_binds[i].key, key_binds[i].func);
|
conf_bind_key(c, key_binds[i].key, key_binds[i].func);
|
||||||
@@ -275,13 +278,21 @@ conf_init(struct conf *c)
|
|||||||
|
|
||||||
conf_cmd_add(c, "lock", "xlock");
|
conf_cmd_add(c, "lock", "xlock");
|
||||||
conf_cmd_add(c, "term", "xterm");
|
conf_cmd_add(c, "term", "xterm");
|
||||||
|
|
||||||
conf_wm_add(c, "cwm", "cwm");
|
conf_wm_add(c, "cwm", "cwm");
|
||||||
|
|
||||||
xasprintf(&c->known_hosts, "%s/%s", c->homedir, ".ssh/known_hosts");
|
|
||||||
|
|
||||||
c->font = xstrdup("sans-serif:pixelsize=14:bold");
|
c->font = xstrdup("sans-serif:pixelsize=14:bold");
|
||||||
c->wmname = xstrdup("CWM");
|
c->wmname = xstrdup("CWM");
|
||||||
|
|
||||||
|
home = getenv("HOME");
|
||||||
|
if ((home == NULL) || (*home == '\0')) {
|
||||||
|
pw = getpwuid(getuid());
|
||||||
|
if (pw != NULL && pw->pw_dir != NULL && *pw->pw_dir != '\0')
|
||||||
|
home = pw->pw_dir;
|
||||||
|
else
|
||||||
|
home = "/";
|
||||||
|
}
|
||||||
|
xasprintf(&c->conf_file, "%s/%s", home, ".cwmrc");
|
||||||
|
xasprintf(&c->known_hosts, "%s/%s", home, ".ssh/known_hosts");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -327,6 +338,7 @@ conf_clear(struct conf *c)
|
|||||||
for (i = 0; i < CWM_COLOR_NITEMS; i++)
|
for (i = 0; i < CWM_COLOR_NITEMS; i++)
|
||||||
free(c->color[i]);
|
free(c->color[i]);
|
||||||
|
|
||||||
|
free(c->conf_file);
|
||||||
free(c->known_hosts);
|
free(c->known_hosts);
|
||||||
free(c->font);
|
free(c->font);
|
||||||
free(c->wmname);
|
free(c->wmname);
|
||||||
@@ -439,8 +451,6 @@ conf_screen(struct screen_ctx *sc)
|
|||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
XftColor xc;
|
XftColor xc;
|
||||||
Colormap colormap = DefaultColormap(X_Dpy, sc->which);
|
|
||||||
Visual *visual = DefaultVisual(X_Dpy, sc->which);
|
|
||||||
|
|
||||||
sc->gap = Conf.gap;
|
sc->gap = Conf.gap;
|
||||||
sc->snapdist = Conf.snapdist;
|
sc->snapdist = Conf.snapdist;
|
||||||
@@ -457,18 +467,18 @@ conf_screen(struct screen_ctx *sc)
|
|||||||
xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_BG],
|
xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_BG],
|
||||||
sc->xftcolor[CWM_COLOR_MENU_FG], &xc);
|
sc->xftcolor[CWM_COLOR_MENU_FG], &xc);
|
||||||
xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_FONT], xc, &xc);
|
xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_FONT], xc, &xc);
|
||||||
if (!XftColorAllocValue(X_Dpy, visual, colormap,
|
if (!XftColorAllocValue(X_Dpy, sc->visual, sc->colormap,
|
||||||
&xc.color, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL]))
|
&xc.color, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL]))
|
||||||
warnx("XftColorAllocValue: %s", Conf.color[i]);
|
warnx("XftColorAllocValue: %s", Conf.color[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (XftColorAllocName(X_Dpy, visual, colormap,
|
if (XftColorAllocName(X_Dpy, sc->visual, sc->colormap,
|
||||||
Conf.color[i], &xc)) {
|
Conf.color[i], &xc)) {
|
||||||
sc->xftcolor[i] = xc;
|
sc->xftcolor[i] = xc;
|
||||||
XftColorFree(X_Dpy, visual, colormap, &xc);
|
XftColorFree(X_Dpy, sc->visual, sc->colormap, &xc);
|
||||||
} else {
|
} else {
|
||||||
warnx("XftColorAllocName: %s", Conf.color[i]);
|
warnx("XftColorAllocName: %s", Conf.color[i]);
|
||||||
XftColorAllocName(X_Dpy, visual, colormap,
|
XftColorAllocName(X_Dpy, sc->visual, sc->colormap,
|
||||||
color_binds[i], &sc->xftcolor[i]);
|
color_binds[i], &sc->xftcolor[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -478,7 +488,8 @@ conf_screen(struct screen_ctx *sc)
|
|||||||
sc->xftcolor[CWM_COLOR_MENU_FG].pixel,
|
sc->xftcolor[CWM_COLOR_MENU_FG].pixel,
|
||||||
sc->xftcolor[CWM_COLOR_MENU_BG].pixel);
|
sc->xftcolor[CWM_COLOR_MENU_BG].pixel);
|
||||||
|
|
||||||
sc->menu.xftdraw = XftDrawCreate(X_Dpy, sc->menu.win, visual, colormap);
|
sc->menu.xftdraw = XftDrawCreate(X_Dpy, sc->menu.win,
|
||||||
|
sc->visual, sc->colormap);
|
||||||
if (sc->menu.xftdraw == NULL)
|
if (sc->menu.xftdraw == NULL)
|
||||||
errx(1, "%s: XftDrawCreate", __func__);
|
errx(1, "%s: XftDrawCreate", __func__);
|
||||||
|
|
||||||
@@ -703,7 +714,6 @@ static char *ewmhints[] = {
|
|||||||
"_NET_WM_STATE_SKIP_TASKBAR",
|
"_NET_WM_STATE_SKIP_TASKBAR",
|
||||||
"_CWM_WM_STATE_FREEZE",
|
"_CWM_WM_STATE_FREEZE",
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
conf_atoms(void)
|
conf_atoms(void)
|
||||||
{
|
{
|
||||||
|
|||||||
20
parse.y
20
parse.y
@@ -45,7 +45,7 @@ static struct file {
|
|||||||
int lineno;
|
int lineno;
|
||||||
int errors;
|
int errors;
|
||||||
} *file, *topfile;
|
} *file, *topfile;
|
||||||
struct file *pushfile(const char *);
|
struct file *pushfile(const char *, FILE *);
|
||||||
int popfile(void);
|
int popfile(void);
|
||||||
int yyparse(void);
|
int yyparse(void);
|
||||||
int yylex(void);
|
int yylex(void);
|
||||||
@@ -559,19 +559,13 @@ nodigits:
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct file *
|
struct file *
|
||||||
pushfile(const char *name)
|
pushfile(const char *name, FILE *stream)
|
||||||
{
|
{
|
||||||
struct file *nfile;
|
struct file *nfile;
|
||||||
|
|
||||||
nfile = xcalloc(1, sizeof(struct file));
|
nfile = xcalloc(1, sizeof(struct file));
|
||||||
nfile->name = xstrdup(name);
|
nfile->name = xstrdup(name);
|
||||||
|
nfile->stream = stream;
|
||||||
if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
|
|
||||||
warn("%s", nfile->name);
|
|
||||||
free(nfile->name);
|
|
||||||
free(nfile);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
nfile->lineno = 1;
|
nfile->lineno = 1;
|
||||||
TAILQ_INSERT_TAIL(&files, nfile, entry);
|
TAILQ_INSERT_TAIL(&files, nfile, entry);
|
||||||
return (nfile);
|
return (nfile);
|
||||||
@@ -596,13 +590,19 @@ popfile(void)
|
|||||||
int
|
int
|
||||||
parse_config(const char *filename, struct conf *xconf)
|
parse_config(const char *filename, struct conf *xconf)
|
||||||
{
|
{
|
||||||
|
FILE *stream;
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
|
|
||||||
conf = xconf;
|
conf = xconf;
|
||||||
|
|
||||||
if ((file = pushfile(filename)) == NULL) {
|
stream = fopen(filename, "r");
|
||||||
|
if (stream == NULL) {
|
||||||
|
if (errno == ENOENT)
|
||||||
|
return (0);
|
||||||
|
warn("%s", filename);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
file = pushfile(filename, stream);
|
||||||
topfile = file;
|
topfile = file;
|
||||||
|
|
||||||
yyparse();
|
yyparse();
|
||||||
|
|||||||
18
screen.c
18
screen.c
@@ -31,6 +31,8 @@
|
|||||||
|
|
||||||
#include "calmwm.h"
|
#include "calmwm.h"
|
||||||
|
|
||||||
|
static struct geom screen_apply_gap(struct screen_ctx *, struct geom);
|
||||||
|
|
||||||
void
|
void
|
||||||
screen_init(int which)
|
screen_init(int which)
|
||||||
{
|
{
|
||||||
@@ -48,6 +50,8 @@ screen_init(int which)
|
|||||||
|
|
||||||
sc->which = which;
|
sc->which = which;
|
||||||
sc->rootwin = RootWindow(X_Dpy, sc->which);
|
sc->rootwin = RootWindow(X_Dpy, sc->which);
|
||||||
|
sc->colormap = DefaultColormap(X_Dpy, sc->which);
|
||||||
|
sc->visual = DefaultVisual(X_Dpy, sc->which);
|
||||||
sc->cycling = 0;
|
sc->cycling = 0;
|
||||||
sc->hideall = 0;
|
sc->hideall = 0;
|
||||||
|
|
||||||
@@ -144,12 +148,12 @@ struct geom
|
|||||||
screen_area(struct screen_ctx *sc, int x, int y, enum apply_gap apply_gap)
|
screen_area(struct screen_ctx *sc, int x, int y, enum apply_gap apply_gap)
|
||||||
{
|
{
|
||||||
struct region_ctx *rc;
|
struct region_ctx *rc;
|
||||||
struct geom area = sc->work;
|
struct geom area = sc->view;
|
||||||
|
|
||||||
TAILQ_FOREACH(rc, &sc->regionq, entry) {
|
TAILQ_FOREACH(rc, &sc->regionq, entry) {
|
||||||
if ((x >= rc->area.x) && (x < (rc->area.x + rc->area.w)) &&
|
if ((x >= rc->view.x) && (x < (rc->view.x + rc->view.w)) &&
|
||||||
(y >= rc->area.y) && (y < (rc->area.y + rc->area.h))) {
|
(y >= rc->view.y) && (y < (rc->view.y + rc->view.h))) {
|
||||||
area = rc->area;
|
area = rc->view;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -191,10 +195,6 @@ screen_update_geometry(struct screen_ctx *sc)
|
|||||||
|
|
||||||
rc = xmalloc(sizeof(*rc));
|
rc = xmalloc(sizeof(*rc));
|
||||||
rc->num = i;
|
rc->num = i;
|
||||||
rc->area.x = ci->x;
|
|
||||||
rc->area.y = ci->y;
|
|
||||||
rc->area.w = ci->width;
|
|
||||||
rc->area.h = ci->height;
|
|
||||||
rc->view.x = ci->x;
|
rc->view.x = ci->x;
|
||||||
rc->view.y = ci->y;
|
rc->view.y = ci->y;
|
||||||
rc->view.w = ci->width;
|
rc->view.w = ci->width;
|
||||||
@@ -220,7 +220,7 @@ screen_update_geometry(struct screen_ctx *sc)
|
|||||||
xu_ewmh_net_workarea(sc);
|
xu_ewmh_net_workarea(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct geom
|
static struct geom
|
||||||
screen_apply_gap(struct screen_ctx *sc, struct geom geom)
|
screen_apply_gap(struct screen_ctx *sc, struct geom geom)
|
||||||
{
|
{
|
||||||
geom.x += sc->gap.left;
|
geom.x += sc->gap.left;
|
||||||
|
|||||||
Reference in New Issue
Block a user