Skip to content

Commit

Permalink
move Cursors into conf.
Browse files Browse the repository at this point in the history
  • Loading branch information
okan committed Jun 17, 2013
1 parent 23d84ad commit 234b821
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 24 deletions.
12 changes: 1 addition & 11 deletions calmwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@
char **cwm_argv;
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 client_ctx_q Clientq = TAILQ_HEAD_INITIALIZER(Clientq);

Expand Down Expand Up @@ -139,11 +133,7 @@ x_init(const char *dpyname)

xu_getatoms();

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);
conf_cursor(&Conf);

for (i = 0; i < ScreenCount(X_Dpy); i++)
screen_init(i);
Expand Down
17 changes: 11 additions & 6 deletions calmwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ union arg {
int i;
};

enum cursor_font {
CF_DEFAULT,
CF_MOVE,
CF_NORMAL,
CF_QUESTION,
CF_RESIZE,
CF_NITEMS
};

enum color {
CWM_COLOR_BORDER_ACTIVE,
CWM_COLOR_BORDER_INACTIVE,
Expand Down Expand Up @@ -294,6 +303,7 @@ struct conf {
char known_hosts[MAXPATHLEN];
#define CONF_FONT "sans-serif:pixelsize=14:bold"
char *font;
Cursor cursor[CF_NITEMS];
};

/* MWM hints */
Expand Down Expand Up @@ -437,6 +447,7 @@ void conf_bindname(struct conf *, char *, char *);
void conf_clear(struct conf *);
void conf_client(struct client_ctx *);
void conf_cmd_add(struct conf *, char *, char *);
void conf_cursor(struct conf *);
void conf_grab_kbd(Window);
void conf_grab_mouse(Window);
void conf_init(struct conf *);
Expand Down Expand Up @@ -498,12 +509,6 @@ int xasprintf(char **, const char *, ...)
/* Externs */
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 client_ctx_q Clientq;
extern struct conf Conf;
Expand Down
18 changes: 17 additions & 1 deletion conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,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
conf_grab_mouse(Window win)
{
Expand All @@ -647,4 +664,3 @@ conf_grab_kbd(Window win)
TAILQ_FOREACH(kb, &Conf.keybindingq, entry)
xu_key_grab(win, kb->modmask, kb->keysym);
}

7 changes: 4 additions & 3 deletions menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt,
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,
Conf.cursor[CF_QUESTION]) < 0) {
XUnmapWindow(X_Dpy, sc->menuwin);
return (NULL);
}
Expand Down Expand Up @@ -472,10 +473,10 @@ menu_handle_move(XEvent *e, struct menu_ctx *mc, struct menu_q *resultq)
if (mc->prev != -1)
menu_draw_entry(mc, resultq, mc->prev, 0);
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);
} else
(void)xu_ptr_regrab(MENUGRABMASK, Cursor_default);
(void)xu_ptr_regrab(MENUGRABMASK, Conf.cursor[CF_DEFAULT]);

if (mc->hasprompt)
menu_draw_entry(mc, resultq, 1, 1);
Expand Down
4 changes: 2 additions & 2 deletions mousefunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ mousefunc_window_resize(struct client_ctx *cc, void *arg)
client_raise(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;

xu_ptr_setpos(cc->win, cc->geom.w, cc->geom.h);
Expand Down Expand Up @@ -137,7 +137,7 @@ mousefunc_window_move(struct client_ctx *cc, void *arg)
if (cc->flags & CLIENT_FREEZE)
return;

if (xu_ptr_grab(cc->win, MOUSEMASK, Cursor_move) < 0)
if (xu_ptr_grab(cc->win, MOUSEMASK, Conf.cursor[CF_MOVE]) < 0)
return;

xu_ptr_getpos(cc->win, &px, &py);
Expand Down
2 changes: 1 addition & 1 deletion screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ screen_init(int which)

group_init(sc);

rootattr.cursor = Cursor_normal;
rootattr.cursor = Conf.cursor[CF_NORMAL];
rootattr.event_mask = SubstructureRedirectMask|SubstructureNotifyMask|
PropertyChangeMask|EnterWindowMask|LeaveWindowMask|
ColormapChangeMask|BUTTONMASK;
Expand Down

0 comments on commit 234b821

Please sign in to comment.