Merge branch 'linux' of git://github.com/chneukirchen/cwm into linux

This commit is contained in:
Michael Weber 2013-06-28 22:36:04 +02:00
commit c7a8e8a286
10 changed files with 108 additions and 95 deletions

View File

@ -38,12 +38,6 @@
char **cwm_argv; char **cwm_argv;
Display *X_Dpy; Display *X_Dpy;
Cursor Cursor_default;
Cursor Cursor_move;
Cursor Cursor_normal;
Cursor Cursor_question;
Cursor Cursor_resize;
struct screen_ctx_q Screenq = TAILQ_HEAD_INITIALIZER(Screenq); struct screen_ctx_q Screenq = TAILQ_HEAD_INITIALIZER(Screenq);
struct client_ctx_q Clientq = TAILQ_HEAD_INITIALIZER(Clientq); struct client_ctx_q Clientq = TAILQ_HEAD_INITIALIZER(Clientq);
@ -52,11 +46,10 @@ struct conf Conf;
char *homedir; char *homedir;
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_errorhandler(Display *, XErrorEvent *);
static int x_wmerrorhandler(Display *, XErrorEvent *); static void x_init(const char *);
static void x_setup(void);
static void x_teardown(void); static void x_teardown(void);
static int x_wmerrorhandler(Display *, XErrorEvent *);
int int
main(int argc, char **argv) main(int argc, char **argv)
@ -109,15 +102,13 @@ main(int argc, char **argv)
conf_path = NULL; conf_path = NULL;
} }
dpy_init(display_name);
conf_init(&Conf); conf_init(&Conf);
if (conf_path && (parse_config(conf_path, &Conf) == -1)) if (conf_path && (parse_config(conf_path, &Conf) == -1))
warnx("config file %s has errors, not loading", conf_path); warnx("config file %s has errors, not loading", conf_path);
free(conf_path); free(conf_path);
xu_getatoms(); x_init(display_name);
x_setup();
xev_loop(); xev_loop();
x_teardown(); x_teardown();
@ -125,7 +116,7 @@ main(int argc, char **argv)
} }
static void static void
dpy_init(const char *dpyname) x_init(const char *dpyname)
{ {
int i; int i;
@ -139,18 +130,10 @@ dpy_init(const char *dpyname)
XSetErrorHandler(x_errorhandler); XSetErrorHandler(x_errorhandler);
HasRandr = XRRQueryExtension(X_Dpy, &Randr_ev, &i); HasRandr = XRRQueryExtension(X_Dpy, &Randr_ev, &i);
}
static void xu_getatoms();
x_setup(void)
{
int i;
Cursor_default = XCreateFontCursor(X_Dpy, XC_X_cursor); conf_cursor(&Conf);
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++) for (i = 0; i < ScreenCount(X_Dpy); i++)
screen_init(i); screen_init(i);

View File

@ -100,6 +100,15 @@ union arg {
int i; int i;
}; };
enum cursor_font {
CF_DEFAULT,
CF_MOVE,
CF_NORMAL,
CF_QUESTION,
CF_RESIZE,
CF_NITEMS
};
enum color { enum color {
CWM_COLOR_BORDER_ACTIVE, CWM_COLOR_BORDER_ACTIVE,
CWM_COLOR_BORDER_INACTIVE, CWM_COLOR_BORDER_INACTIVE,
@ -318,6 +327,7 @@ struct conf {
char known_hosts[MAXPATHLEN]; char known_hosts[MAXPATHLEN];
#define CONF_FONT "sans-serif:pixelsize=14:bold" #define CONF_FONT "sans-serif:pixelsize=14:bold"
char *font; char *font;
Cursor cursor[CF_NITEMS];
}; };
/* MWM hints */ /* MWM hints */
@ -335,6 +345,7 @@ struct mwm_hints {
__dead void usage(void); __dead void usage(void);
void client_applysizehints(struct client_ctx *); void client_applysizehints(struct client_ctx *);
void client_config(struct client_ctx *);
struct client_ctx *client_current(void); struct client_ctx *client_current(void);
void client_cycle(struct screen_ctx *, int); void client_cycle(struct screen_ctx *, int);
void client_cycle_leave(struct screen_ctx *, void client_cycle_leave(struct screen_ctx *,
@ -351,6 +362,7 @@ void client_leave(struct client_ctx *);
void client_lower(struct client_ctx *); void client_lower(struct client_ctx *);
void client_map(struct client_ctx *); void client_map(struct client_ctx *);
void client_maximize(struct client_ctx *); void client_maximize(struct client_ctx *);
void client_msg(struct client_ctx *, Atom);
void client_move(struct client_ctx *); void client_move(struct client_ctx *);
struct client_ctx *client_init(Window, struct screen_ctx *, int); struct client_ctx *client_init(Window, struct screen_ctx *, int);
void client_ptrsave(struct client_ctx *); void client_ptrsave(struct client_ctx *);
@ -460,6 +472,7 @@ void conf_bindname(struct conf *, char *, char *);
void conf_clear(struct conf *); void conf_clear(struct conf *);
void conf_client(struct client_ctx *); void conf_client(struct client_ctx *);
void conf_cmd_add(struct conf *, char *, char *); void conf_cmd_add(struct conf *, char *, char *);
void conf_cursor(struct conf *);
void conf_grab_kbd(Window); void conf_grab_kbd(Window);
void conf_grab_mouse(Window); void conf_grab_mouse(Window);
void conf_init(struct conf *); void conf_init(struct conf *);
@ -471,7 +484,6 @@ void xev_loop(void);
void xu_btn_grab(Window, int, u_int); void xu_btn_grab(Window, int, u_int);
void xu_btn_ungrab(Window, int, u_int); void xu_btn_ungrab(Window, int, u_int);
void xu_configure(struct client_ctx *);
void xu_getatoms(void); void xu_getatoms(void);
int xu_getprop(Window, Atom, Atom, long, u_char **); int xu_getprop(Window, Atom, Atom, long, u_char **);
int xu_get_wm_state(Window, int *); int xu_get_wm_state(Window, int *);
@ -482,7 +494,6 @@ int xu_ptr_grab(Window, u_int, Cursor);
int xu_ptr_regrab(u_int, Cursor); int xu_ptr_regrab(u_int, Cursor);
void xu_ptr_setpos(Window, int, int); void xu_ptr_setpos(Window, int, int);
void xu_ptr_ungrab(void); void xu_ptr_ungrab(void);
void xu_sendmsg(Window, Atom, Atom);
void xu_set_wm_state(Window win, int); void xu_set_wm_state(Window win, int);
void xu_xft_draw(struct screen_ctx *, const char *, void xu_xft_draw(struct screen_ctx *, const char *,
int, int, int); int, int, int);
@ -523,12 +534,6 @@ int xasprintf(char **, const char *, ...)
/* Externs */ /* Externs */
extern Display *X_Dpy; extern Display *X_Dpy;
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_q Screenq;
extern struct client_ctx_q Clientq; extern struct client_ctx_q Clientq;
extern struct conf Conf; extern struct conf Conf;

View File

@ -123,7 +123,7 @@ client_init(Window win, struct screen_ctx *sc, int mapped)
client_transient(cc); client_transient(cc);
/* Notify client of its configuration. */ /* Notify client of its configuration. */
xu_configure(cc); client_config(cc);
(state == IconicState) ? client_hide(cc) : client_unhide(cc); (state == IconicState) ? client_hide(cc) : client_unhide(cc);
@ -400,14 +400,14 @@ client_resize(struct client_ctx *cc, int reset)
XMoveResizeWindow(X_Dpy, cc->win, cc->geom.x, XMoveResizeWindow(X_Dpy, cc->win, cc->geom.x,
cc->geom.y, cc->geom.w, cc->geom.h); cc->geom.y, cc->geom.w, cc->geom.h);
xu_configure(cc); client_config(cc);
} }
void void
client_move(struct client_ctx *cc) client_move(struct client_ctx *cc)
{ {
XMoveWindow(X_Dpy, cc->win, cc->geom.x, cc->geom.y); XMoveWindow(X_Dpy, cc->win, cc->geom.x, cc->geom.y);
xu_configure(cc); client_config(cc);
} }
void void
@ -422,6 +422,26 @@ client_raise(struct client_ctx *cc)
XRaiseWindow(X_Dpy, cc->win); XRaiseWindow(X_Dpy, cc->win);
} }
void
client_config(struct client_ctx *cc)
{
XConfigureEvent cn;
bzero(&cn, sizeof(cn));
cn.type = ConfigureNotify;
cn.event = cc->win;
cn.window = cc->win;
cn.x = cc->geom.x;
cn.y = cc->geom.y;
cn.width = cc->geom.w;
cn.height = cc->geom.h;
cn.border_width = cc->bwidth;
cn.above = None;
cn.override_redirect = 0;
XSendEvent(X_Dpy, cc->win, False, StructureNotifyMask, (XEvent *)&cn);
}
void void
client_ptrwarp(struct client_ctx *cc) client_ptrwarp(struct client_ctx *cc)
{ {
@ -518,12 +538,27 @@ client_wm_protocols(struct client_ctx *cc)
} }
} }
void
client_msg(struct client_ctx *cc, Atom proto)
{
XClientMessageEvent cm;
bzero(&cm, sizeof(cm));
cm.type = ClientMessage;
cm.window = cc->win;
cm.message_type = cwmh[WM_PROTOCOLS].atom;
cm.format = 32;
cm.data.l[0] = proto;
cm.data.l[1] = CurrentTime;
XSendEvent(X_Dpy, cc->win, False, NoEventMask, (XEvent *)&cm);
}
void void
client_send_delete(struct client_ctx *cc) client_send_delete(struct client_ctx *cc)
{ {
if (cc->xproto & _WM_DELETE_WINDOW) if (cc->xproto & _WM_DELETE_WINDOW)
xu_sendmsg(cc->win, client_msg(cc, cwmh[WM_DELETE_WINDOW].atom);
cwmh[WM_PROTOCOLS].atom, cwmh[WM_DELETE_WINDOW].atom);
else else
XKillClient(X_Dpy, cc->win); XKillClient(X_Dpy, cc->win);
} }

46
conf.c
View File

@ -84,7 +84,7 @@ conf_ignore(struct conf *c, char *val)
TAILQ_INSERT_TAIL(&c->ignoreq, wm, entry); TAILQ_INSERT_TAIL(&c->ignoreq, wm, entry);
} }
static char *color_binds[CWM_COLOR_MAX] = { static char *color_binds[] = {
"#CCCCCC", /* CWM_COLOR_BORDER_ACTIVE */ "#CCCCCC", /* CWM_COLOR_BORDER_ACTIVE */
"#666666", /* CWM_COLOR_BORDER_INACTIVE */ "#666666", /* CWM_COLOR_BORDER_INACTIVE */
"blue", /* CWM_COLOR_BORDER_GROUP */ "blue", /* CWM_COLOR_BORDER_GROUP */
@ -107,9 +107,16 @@ conf_screen(struct screen_ctx *sc)
if (sc->xftfont == NULL) if (sc->xftfont == NULL)
errx(1, "XftFontOpenName"); errx(1, "XftFontOpenName");
for (i = 0; i < CWM_COLOR_MAX; i++) { for (i = 0; i < nitems(color_binds); i++) {
if (*Conf.color[i] == '\0') if (i == CWM_COLOR_MENU_FONT_SEL && *Conf.color[i] == '\0') {
xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_BG],
sc->xftcolor[CWM_COLOR_MENU_FG], &xc);
xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_FONT], xc, &xc);
if (!XftColorAllocValue(X_Dpy, sc->visual, sc->colormap,
&xc.color, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL]))
warnx("XftColorAllocValue: '%s'", Conf.color[i]);
break; break;
}
if (XftColorAllocName(X_Dpy, sc->visual, sc->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;
@ -120,15 +127,6 @@ conf_screen(struct screen_ctx *sc)
color_binds[i], &sc->xftcolor[i]); color_binds[i], &sc->xftcolor[i]);
} }
} }
if (i == CWM_COLOR_MAX)
return;
xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_BG],
sc->xftcolor[CWM_COLOR_MENU_FG], &xc);
xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_FONT], xc, &xc);
if (!XftColorAllocValue(X_Dpy, sc->visual, sc->colormap,
&xc.color, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL]))
warnx("XftColorAllocValue: '%s'", Conf.color[i]);
sc->menuwin = XCreateSimpleWindow(X_Dpy, sc->rootwin, 0, 0, 1, 1, sc->menuwin = XCreateSimpleWindow(X_Dpy, sc->rootwin, 0, 0, 1, 1,
Conf.bwidth, Conf.bwidth,
@ -571,7 +569,9 @@ static struct {
{ "menu_cmd", mousefunc_menu_cmd, MOUSEBIND_CTX_ROOT }, { "menu_cmd", mousefunc_menu_cmd, MOUSEBIND_CTX_ROOT },
}; };
static unsigned int mouse_btns[] = { Button1, Button2, Button3 }; static unsigned int mouse_btns[] = {
Button1, Button2, Button3, Button4, Button5
};
int int
conf_mousebind(struct conf *c, char *name, char *binding) conf_mousebind(struct conf *c, char *name, char *binding)
@ -597,7 +597,7 @@ conf_mousebind(struct conf *c, char *name, char *binding)
} else } else
substring = name; substring = name;
button = strtonum(substring, 1, 3, &errstr); button = strtonum(substring, 1, 5, &errstr);
if (errstr) if (errstr)
warnx("button number is %s: %s", errstr, substring); warnx("button number is %s: %s", errstr, substring);
@ -649,6 +649,23 @@ conf_mouseunbind(struct conf *c, struct mousebinding *unbind)
} }
} }
static int cursor_binds[CF_NITEMS] = {
XC_X_cursor, /* CF_DEFAULT */
XC_fleur, /* CF_MOVE */
XC_left_ptr, /* CF_NORMAL */
XC_question_arrow, /* CF_QUESTION */
XC_bottom_right_corner, /* CF_RESIZE */
};
void
conf_cursor(struct conf *c)
{
u_int i;
for (i = 0; i < nitems(cursor_binds); i++)
c->cursor[i] = XCreateFontCursor(X_Dpy, cursor_binds[i]);
}
void void
conf_grab_mouse(Window win) conf_grab_mouse(Window win)
{ {
@ -671,4 +688,3 @@ conf_grab_kbd(Window win)
TAILQ_FOREACH(kb, &Conf.keybindingq, entry) TAILQ_FOREACH(kb, &Conf.keybindingq, entry)
xu_key_grab(win, kb->modmask, kb->keysym); xu_key_grab(win, kb->modmask, kb->keysym);
} }

View File

@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\" .\"
.Dd $Mdocdate: December 17 2012 $ .Dd $Mdocdate: January 8 2013 $
.Dt CWMRC 5 .Dt CWMRC 5
.Os .Os
.Sh NAME .Sh NAME
@ -206,6 +206,10 @@ Left mouse button.
Middle mouse button. Middle mouse button.
.It 3 .It 3
Right mouse button. Right mouse button.
.It 4
Scroll up mouse button.
.It 5
Scroll down mouse button.
.El .El
.Pp .Pp
The The

7
menu.c
View File

@ -122,7 +122,8 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt,
XSelectInput(X_Dpy, sc->menuwin, evmask); XSelectInput(X_Dpy, sc->menuwin, evmask);
XMapRaised(X_Dpy, sc->menuwin); XMapRaised(X_Dpy, sc->menuwin);
if (xu_ptr_grab(sc->menuwin, MENUGRABMASK, Cursor_question) < 0) { if (xu_ptr_grab(sc->menuwin, MENUGRABMASK,
Conf.cursor[CF_QUESTION]) < 0) {
XUnmapWindow(X_Dpy, sc->menuwin); XUnmapWindow(X_Dpy, sc->menuwin);
return (NULL); return (NULL);
} }
@ -472,10 +473,10 @@ menu_handle_move(XEvent *e, struct menu_ctx *mc, struct menu_q *resultq)
if (mc->prev != -1) if (mc->prev != -1)
menu_draw_entry(mc, resultq, mc->prev, 0); menu_draw_entry(mc, resultq, mc->prev, 0);
if (mc->entry != -1) { if (mc->entry != -1) {
(void)xu_ptr_regrab(MENUGRABMASK, Cursor_normal); (void)xu_ptr_regrab(MENUGRABMASK, Conf.cursor[CF_NORMAL]);
menu_draw_entry(mc, resultq, mc->entry, 1); menu_draw_entry(mc, resultq, mc->entry, 1);
} else } else
(void)xu_ptr_regrab(MENUGRABMASK, Cursor_default); (void)xu_ptr_regrab(MENUGRABMASK, Conf.cursor[CF_DEFAULT]);
if (mc->hasprompt) if (mc->hasprompt)
menu_draw_entry(mc, resultq, 1, 1); menu_draw_entry(mc, resultq, 1, 1);

View File

@ -81,7 +81,7 @@ mousefunc_window_resize(struct client_ctx *cc, void *arg)
client_raise(cc); client_raise(cc);
client_ptrsave(cc); client_ptrsave(cc);
if (xu_ptr_grab(cc->win, MOUSEMASK, Cursor_resize) < 0) if (xu_ptr_grab(cc->win, MOUSEMASK, Conf.cursor[CF_RESIZE]) < 0)
return; return;
xu_ptr_setpos(cc->win, cc->geom.w, cc->geom.h); xu_ptr_setpos(cc->win, cc->geom.w, cc->geom.h);
@ -137,7 +137,7 @@ mousefunc_window_move(struct client_ctx *cc, void *arg)
if (cc->flags & CLIENT_FREEZE) if (cc->flags & CLIENT_FREEZE)
return; return;
if (xu_ptr_grab(cc->win, MOUSEMASK, Cursor_move) < 0) if (xu_ptr_grab(cc->win, MOUSEMASK, Conf.cursor[CF_MOVE]) < 0)
return; return;
xu_ptr_getpos(cc->win, &px, &py); xu_ptr_getpos(cc->win, &px, &py);

View File

@ -57,7 +57,7 @@ screen_init(int which)
group_init(sc); group_init(sc);
rootattr.cursor = Cursor_normal; rootattr.cursor = Conf.cursor[CF_NORMAL];
rootattr.event_mask = SubstructureRedirectMask|SubstructureNotifyMask| rootattr.event_mask = SubstructureRedirectMask|SubstructureNotifyMask|
PropertyChangeMask|EnterWindowMask|LeaveWindowMask| PropertyChangeMask|EnterWindowMask|LeaveWindowMask|
ColormapChangeMask|BUTTONMASK; ColormapChangeMask|BUTTONMASK;

View File

@ -150,7 +150,11 @@ xev_handle_configurerequest(XEvent *ee)
if (e->value_mask & CWY) if (e->value_mask & CWY)
cc->geom.y = e->y; cc->geom.y = e->y;
if (e->value_mask & CWBorderWidth) if (e->value_mask & CWBorderWidth)
wc.border_width = e->border_width; cc->bwidth = e->border_width;
if (e->value_mask & CWSibling)
wc.sibling = e->above;
if (e->value_mask & CWStackMode)
wc.stack_mode = e->detail;
if (cc->geom.x == 0 && cc->geom.w >= sc->view.w) if (cc->geom.x == 0 && cc->geom.w >= sc->view.w)
cc->geom.x -= cc->bwidth; cc->geom.x -= cc->bwidth;
@ -165,7 +169,7 @@ xev_handle_configurerequest(XEvent *ee)
wc.border_width = cc->bwidth; wc.border_width = cc->bwidth;
XConfigureWindow(X_Dpy, cc->win, e->value_mask, &wc); XConfigureWindow(X_Dpy, cc->win, e->value_mask, &wc);
xu_configure(cc); client_config(cc);
} else { } else {
/* let it do what it wants, it'll be ours when we map it. */ /* let it do what it wants, it'll be ours when we map it. */
wc.x = e->x; wc.x = e->x;

35
xutil.c
View File

@ -105,41 +105,6 @@ xu_key_grab(Window win, u_int mask, KeySym keysym)
True, GrabModeAsync, GrabModeAsync); True, GrabModeAsync, GrabModeAsync);
} }
void
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.w;
ce.height = cc->geom.h;
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 type, Atom atm)
{
XClientMessageEvent e;
bzero(&e, sizeof(e));
e.type = ClientMessage;
e.window = win;
e.message_type = type;
e.format = 32;
e.data.l[0] = atm;
e.data.l[1] = CurrentTime;
XSendEvent(X_Dpy, win, False, 0L, (XEvent *)&e);
}
int int
xu_getprop(Window win, Atom atm, Atom type, long len, u_char **p) xu_getprop(Window win, Atom atm, Atom type, long len, u_char **p)
{ {