about summary refs log tree commit diff
diff options
context:
space:
mode:
authorokan <okan>2013-06-17 17:11:10 +0000
committerokan <okan>2013-06-17 17:11:10 +0000
commit234b8214df298740b37ad566771a9df2f1b3aec6 (patch)
treee7379452f7f424b6a8d44be6b6bfd4c9ee728b90
parent23d84adb5ed6cc3890fb1d74d4d5a43004b0ea0d (diff)
downloadcwm-234b8214df298740b37ad566771a9df2f1b3aec6.tar.gz
cwm-234b8214df298740b37ad566771a9df2f1b3aec6.tar.xz
cwm-234b8214df298740b37ad566771a9df2f1b3aec6.zip
move Cursors into conf.
-rw-r--r--calmwm.c12
-rw-r--r--calmwm.h17
-rw-r--r--conf.c18
-rw-r--r--menu.c7
-rw-r--r--mousefunc.c4
-rw-r--r--screen.c2
6 files changed, 36 insertions, 24 deletions
diff --git a/calmwm.c b/calmwm.c
index ee1224d..6a189d2 100644
--- a/calmwm.c
+++ b/calmwm.c
@@ -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);
 
@@ -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);
diff --git a/calmwm.h b/calmwm.h
index ba0e15d..caf1808 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -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,
@@ -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 */
@@ -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 *);
@@ -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;
diff --git a/conf.c b/conf.c
index 6b0abe6..6725f4b 100644
--- a/conf.c
+++ b/conf.c
@@ -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)
 {
@@ -647,4 +664,3 @@ conf_grab_kbd(Window win)
 	TAILQ_FOREACH(kb, &Conf.keybindingq, entry)
 		xu_key_grab(win, kb->modmask, kb->keysym);
 }
-
diff --git a/menu.c b/menu.c
index 6816006..ddb1c65 100644
--- a/menu.c
+++ b/menu.c
@@ -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);
 	}
@@ -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);
diff --git a/mousefunc.c b/mousefunc.c
index a41a3ad..90c7078 100644
--- a/mousefunc.c
+++ b/mousefunc.c
@@ -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);
@@ -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);
diff --git a/screen.c b/screen.c
index f8abae2..f6f4bcd 100644
--- a/screen.c
+++ b/screen.c
@@ -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;