summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-07-27 15:06:38 +0200
committerLeah Neukirchen <leah@vuxu.org>2017-07-27 15:07:12 +0200
commit5a46349ec798912f2b5329cc1dbc04ec8595038a (patch)
tree7ca4224cace2f55cbb1df94f65bf0e1ac2a9c40d
parent8908e5ec42aad92ff0c06598274b754c9b954b03 (diff)
parent8dee1182a2a65a0286c68310f6f5181560f6275a (diff)
downloadcwm-5a46349ec798912f2b5329cc1dbc04ec8595038a.tar.gz
cwm-5a46349ec798912f2b5329cc1dbc04ec8595038a.tar.xz
cwm-5a46349ec798912f2b5329cc1dbc04ec8595038a.zip
cvsimport
* refs/heads/master:
  Use the key names from keysymdef.h in the default key bindings list for clarification.
  remove extra parentheses
  Pull over the remaining re-implemented window move/resize functions and create a wrapper so that the key and mouse based move/resize callbacks can be unified. This has already been done with other window operations and menus.
  rename one function, matching others, to help upcoming change
-rw-r--r--Makefile4
-rw-r--r--calmwm.h5
-rw-r--r--conf.c6
-rw-r--r--cwm.112
-rw-r--r--kbfunc.c143
-rw-r--r--mousefunc.c147
6 files changed, 152 insertions, 165 deletions
diff --git a/Makefile b/Makefile
index 441b91d..6909c9b 100644
--- a/Makefile
+++ b/Makefile
@@ -7,11 +7,11 @@ PREFIX?=	/usr/local
 
 SRCS=		calmwm.c screen.c xmalloc.c client.c menu.c \
 		search.c util.c xutil.c conf.c xevents.c group.c \
-		kbfunc.c mousefunc.c parse.y
+		kbfunc.c parse.y
 
 OBJS=		calmwm.o screen.o xmalloc.o client.o menu.o \
 		search.o util.o xutil.o conf.o xevents.o group.o \
-		kbfunc.o mousefunc.o strlcpy.o strlcat.o y.tab.o \
+		kbfunc.o strlcpy.o strlcat.o y.tab.o \
 		strtonum.o reallocarray.o
 
 CPPFLAGS+=	`pkg-config --cflags fontconfig x11 xft xrandr`
diff --git a/calmwm.h b/calmwm.h
index b28b454..9ac69a4 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -509,14 +509,11 @@ void			 kbfunc_menu_cmd(void *, struct cargs *);
 void			 kbfunc_menu_group(void *, struct cargs *);
 void			 kbfunc_menu_exec(void *, struct cargs *);
 void			 kbfunc_menu_ssh(void *, struct cargs *);
-void			 kbfunc_menu_client_label(void *, struct cargs *);
+void			 kbfunc_client_menu_label(void *, struct cargs *);
 void			 kbfunc_exec_cmd(void *, struct cargs *);
 void			 kbfunc_exec_lock(void *, struct cargs *);
 void			 kbfunc_exec_term(void *, struct cargs *);
 
-void			 mousefunc_client_move(void *, struct cargs *);
-void			 mousefunc_client_resize(void *, struct cargs *);
-
 void			 menu_windraw(struct screen_ctx *, Window,
 			     const char *, ...);
 struct menu  		*menu_filter(struct screen_ctx *, struct menu_q *,
diff --git a/conf.c b/conf.c
index a321a99..d750c42 100644
--- a/conf.c
+++ b/conf.c
@@ -60,7 +60,7 @@ static const struct {
 	enum context	 context;
 	int		 flag;
 } name_to_func[] = {
-	{ "window-menu-label", kbfunc_menu_client_label, CWM_CONTEXT_CC, 0 },
+	{ "window-menu-label", kbfunc_client_menu_label, CWM_CONTEXT_CC, 0 },
 	{ "window-lower", kbfunc_client_lower, CWM_CONTEXT_CC, 0 },
 	{ "window-raise", kbfunc_client_raise, CWM_CONTEXT_CC, 0 },
 	{ "window-hide", kbfunc_client_hide, CWM_CONTEXT_CC, 0 },
@@ -92,7 +92,7 @@ static const struct {
 	{ "window-movetogroup-8", kbfunc_client_movetogroup, CWM_CONTEXT_CC, 8 },
 	{ "window-movetogroup-9", kbfunc_client_movetogroup, CWM_CONTEXT_CC, 9 },
 
-	{ "window-move", mousefunc_client_move, CWM_CONTEXT_CC, 0 },
+	{ "window-move", kbfunc_client_move, CWM_CONTEXT_CC, 0 },
 	{ "window-move-up", kbfunc_client_move, CWM_CONTEXT_CC,
 	    (CWM_UP) },
 	{ "window-move-down", kbfunc_client_move, CWM_CONTEXT_CC,
@@ -109,7 +109,7 @@ static const struct {
 	    (CWM_RIGHT | CWM_BIGAMOUNT) },
 	{ "window-move-left-big", kbfunc_client_move, CWM_CONTEXT_CC,
 	    (CWM_LEFT | CWM_BIGAMOUNT) },
-	{ "window-resize", mousefunc_client_resize, CWM_CONTEXT_CC, 0 },
+	{ "window-resize", kbfunc_client_resize, CWM_CONTEXT_CC, 0 },
 	{ "window-resize-up", kbfunc_client_resize, CWM_CONTEXT_CC,
 	    (CWM_UP) },
 	{ "window-resize-down", kbfunc_client_resize, CWM_CONTEXT_CC,
diff --git a/cwm.1 b/cwm.1
index 2898a52..d81b223 100644
--- a/cwm.1
+++ b/cwm.1
@@ -83,9 +83,9 @@ Hide current window.
 Lower current window.
 .It Ic M-Up
 Raise current window.
-.It Ic M-/
+.It Ic M-slash
 Search for windows.
-.It Ic C-/
+.It Ic C-slash
 Search for applications.
 .It Ic CM-n
 Label current window.
@@ -113,9 +113,9 @@ Toggle stickiness of current window.
 Toggle full-screen mode of current window.
 .It Ic CM-m
 Toggle maximization of current window.
-.It Ic CM-=
+.It Ic CM-equal
 Toggle vertical maximization of current window.
-.It Ic CMS-=
+.It Ic CMS-equal
 Toggle horizontal maximization of current window.
 .It Ic M-[hjkl]
 Move window by a small amount.
@@ -127,11 +127,11 @@ Resize window by a small amount.
 .It Ic CMS-[hjkl]
 Resize window by a large amount; see
 .Xr cwmrc 5 .
-.It Ic M-?
+.It Ic M-question
 Spawn
 .Dq exec program
 dialog.
-.It Ic M-.
+.It Ic M-period
 Spawn
 .Dq ssh to
 dialog.
diff --git a/kbfunc.c b/kbfunc.c
index 9af37df..70da34c 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -42,6 +42,10 @@
 extern sig_atomic_t	 cwm_status;
 
 static void kbfunc_amount(int, int, int *, int *);
+static void kbfunc_client_move_kb(void *, struct cargs *);
+static void kbfunc_client_move_mb(void *, struct cargs *);
+static void kbfunc_client_resize_kb(void *, struct cargs *);
+static void kbfunc_client_resize_mb(void *, struct cargs *);
 
 void
 kbfunc_cwm_status(void *ctx, struct cargs *cargs)
@@ -89,6 +93,24 @@ kbfunc_ptrmove(void *ctx, struct cargs *cargs)
 void
 kbfunc_client_move(void *ctx, struct cargs *cargs)
 {
+	if (cargs->xev == CWM_XEV_BTN)
+		kbfunc_client_move_mb(ctx, cargs);
+	else
+		kbfunc_client_move_kb(ctx, cargs);
+}
+
+void
+kbfunc_client_resize(void *ctx, struct cargs *cargs)
+{
+	if (cargs->xev == CWM_XEV_BTN)
+		kbfunc_client_resize_mb(ctx, cargs);
+	else
+		kbfunc_client_resize_kb(ctx, cargs);
+}
+
+static void
+kbfunc_client_move_kb(void *ctx, struct cargs *cargs)
+{
 	struct client_ctx	*cc = ctx;
 	struct screen_ctx	*sc = cc->sc;
 	struct geom		 area;
@@ -124,8 +146,69 @@ kbfunc_client_move(void *ctx, struct cargs *cargs)
 	client_ptr_inbound(cc, 1);
 }
 
-void
-kbfunc_client_resize(void *ctx, struct cargs *cargs)
+static void
+kbfunc_client_move_mb(void *ctx, struct cargs *cargs)
+{
+	struct client_ctx	*cc = ctx;
+	XEvent			 ev;
+	Time			 ltime = 0;
+	struct screen_ctx	*sc = cc->sc;
+	struct geom		 area;
+	int			 move = 1;
+
+	client_raise(cc);
+
+	if (cc->flags & CLIENT_FREEZE)
+		return;
+
+	client_ptr_inbound(cc, 1);
+
+	if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK,
+	    GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_MOVE],
+	    CurrentTime) != GrabSuccess)
+		return;
+
+	menu_windraw(sc, cc->win, "%4d, %-4d", cc->geom.x, cc->geom.y);
+
+	while (move) {
+		XWindowEvent(X_Dpy, cc->win, MOUSEMASK, &ev);
+		switch (ev.type) {
+		case MotionNotify:
+			/* not more than 60 times / second */
+			if ((ev.xmotion.time - ltime) <= (1000 / 60))
+				continue;
+			ltime = ev.xmotion.time;
+
+			cc->geom.x = ev.xmotion.x_root - cc->ptr.x - cc->bwidth;
+			cc->geom.y = ev.xmotion.y_root - cc->ptr.y - cc->bwidth;
+
+			area = screen_area(sc,
+			    cc->geom.x + cc->geom.w / 2,
+			    cc->geom.y + cc->geom.h / 2, CWM_GAP);
+			cc->geom.x += client_snapcalc(cc->geom.x,
+			    cc->geom.x + cc->geom.w + (cc->bwidth * 2),
+			    area.x, area.x + area.w, sc->snapdist);
+			cc->geom.y += client_snapcalc(cc->geom.y,
+			    cc->geom.y + cc->geom.h + (cc->bwidth * 2),
+			    area.y, area.y + area.h, sc->snapdist);
+			client_move(cc);
+			menu_windraw(sc, cc->win,
+			    "%4d, %-4d", cc->geom.x, cc->geom.y);
+			break;
+		case ButtonRelease:
+			move = 0;
+			break;
+		}
+	}
+	if (ltime)
+		client_move(cc);
+	XUnmapWindow(X_Dpy, sc->menu.win);
+	XReparentWindow(X_Dpy, sc->menu.win, sc->rootwin, 0, 0);
+	XUngrabPointer(X_Dpy, CurrentTime);
+}
+
+static void
+kbfunc_client_resize_kb(void *ctx, struct cargs *cargs)
 {
 	struct client_ctx	*cc = ctx;
 	int			 mx = 0, my = 0;
@@ -152,6 +235,60 @@ kbfunc_client_resize(void *ctx, struct cargs *cargs)
 	client_ptr_inbound(cc, 1);
 }
 
+static void
+kbfunc_client_resize_mb(void *ctx, struct cargs *cargs)
+{
+	struct client_ctx	*cc = ctx;
+	XEvent			 ev;
+	Time			 ltime = 0;
+	struct screen_ctx	*sc = cc->sc;
+	int			 resize = 1;
+
+	if (cc->flags & CLIENT_FREEZE)
+		return;
+
+	client_raise(cc);
+	client_ptrsave(cc);
+
+	xu_ptr_setpos(cc->win, cc->geom.w, cc->geom.h);
+
+	if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK,
+	    GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_RESIZE],
+	    CurrentTime) != GrabSuccess)
+		return;
+
+	menu_windraw(sc, cc->win, "%4d x %-4d", cc->dim.w, cc->dim.h);
+	while (resize) {
+		XWindowEvent(X_Dpy, cc->win, MOUSEMASK, &ev);
+		switch (ev.type) {
+		case MotionNotify:
+			/* not more than 60 times / second */
+			if ((ev.xmotion.time - ltime) <= (1000 / 60))
+				continue;
+			ltime = ev.xmotion.time;
+
+			cc->geom.w = ev.xmotion.x;
+			cc->geom.h = ev.xmotion.y;
+			client_applysizehints(cc);
+			client_resize(cc, 1);
+			menu_windraw(sc, cc->win,
+			    "%4d x %-4d", cc->dim.w, cc->dim.h);
+			break;
+		case ButtonRelease:
+			resize = 0;
+			break;
+		}
+	}
+	if (ltime)
+		client_resize(cc, 1);
+	XUnmapWindow(X_Dpy, sc->menu.win);
+	XReparentWindow(X_Dpy, sc->menu.win, sc->rootwin, 0, 0);
+	XUngrabPointer(X_Dpy, CurrentTime);
+
+	/* Make sure the pointer stays within the window. */
+	client_ptr_inbound(cc, 0);
+}
+
 void
 kbfunc_client_delete(void *ctx, struct cargs *cargs)
 {
@@ -525,7 +662,7 @@ out:
 }
 
 void
-kbfunc_menu_client_label(void *ctx, struct cargs *cargs)
+kbfunc_client_menu_label(void *ctx, struct cargs *cargs)
 {
 	struct client_ctx	*cc = ctx;
 	struct menu		*mi;
diff --git a/mousefunc.c b/mousefunc.c
deleted file mode 100644
index e6d3862..0000000
--- a/mousefunc.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * calmwm - the calm window manager
- *
- * Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>
- * Copyright (c) 2008 rivo nurges <rix@estpak.ee>
- *
- * 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.
- *
- * $OpenBSD$
- */
-
-#include <sys/types.h>
-#include "queue.h"
-
-#include <err.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "calmwm.h"
-
-void
-mousefunc_client_resize(void *ctx, struct cargs *cargs)
-{
-	struct client_ctx	*cc = ctx;
-	XEvent			 ev;
-	Time			 ltime = 0;
-	struct screen_ctx	*sc = cc->sc;
-
-	if (cc->flags & CLIENT_FREEZE)
-		return;
-
-	client_raise(cc);
-	client_ptrsave(cc);
-
-	xu_ptr_setpos(cc->win, cc->geom.w, cc->geom.h);
-
-	if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK,
-	    GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_RESIZE],
-	    CurrentTime) != GrabSuccess)
-		return;
-
-	menu_windraw(sc, cc->win, "%4d x %-4d", cc->dim.w, cc->dim.h);
-
-	for (;;) {
-		XWindowEvent(X_Dpy, cc->win, MOUSEMASK, &ev);
-
-		switch (ev.type) {
-		case MotionNotify:
-			/* not more than 60 times / second */
-			if ((ev.xmotion.time - ltime) <= (1000 / 60))
-				continue;
-			ltime = ev.xmotion.time;
-
-			cc->geom.w = ev.xmotion.x;
-			cc->geom.h = ev.xmotion.y;
-			client_applysizehints(cc);
-			client_resize(cc, 1);
-			menu_windraw(sc, cc->win,
-			    "%4d x %-4d", cc->dim.w, cc->dim.h);
-			break;
-		case ButtonRelease:
-			client_resize(cc, 1);
-			XUnmapWindow(X_Dpy, sc->menu.win);
-			XReparentWindow(X_Dpy, sc->menu.win, sc->rootwin, 0, 0);
-			XUngrabPointer(X_Dpy, CurrentTime);
-
-			/* Make sure the pointer stays within the window. */
-			client_ptr_inbound(cc, 0);
-			return;
-		}
-	}
-	/* NOTREACHED */
-}
-
-void
-mousefunc_client_move(void *ctx, struct cargs *cargs)
-{
-	struct client_ctx	*cc = ctx;
-	XEvent			 ev;
-	Time			 ltime = 0;
-	struct screen_ctx	*sc = cc->sc;
-	struct geom		 area;
-
-	client_raise(cc);
-
-	if (cc->flags & CLIENT_FREEZE)
-		return;
-
-	client_ptr_inbound(cc, 1);
-
-	if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK,
-	    GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_MOVE],
-	    CurrentTime) != GrabSuccess)
-		return;
-
-	menu_windraw(sc, cc->win, "%4d, %-4d", cc->geom.x, cc->geom.y);
-
-	for (;;) {
-		XWindowEvent(X_Dpy, cc->win, MOUSEMASK, &ev);
-
-		switch (ev.type) {
-		case MotionNotify:
-			/* not more than 60 times / second */
-			if ((ev.xmotion.time - ltime) <= (1000 / 60))
-				continue;
-			ltime = ev.xmotion.time;
-
-			cc->geom.x = ev.xmotion.x_root - cc->ptr.x - cc->bwidth;
-			cc->geom.y = ev.xmotion.y_root - cc->ptr.y - cc->bwidth;
-
-			area = screen_area(sc,
-			    cc->geom.x + cc->geom.w / 2,
-			    cc->geom.y + cc->geom.h / 2, CWM_GAP);
-			cc->geom.x += client_snapcalc(cc->geom.x,
-			    cc->geom.x + cc->geom.w + (cc->bwidth * 2),
-			    area.x, area.x + area.w, sc->snapdist);
-			cc->geom.y += client_snapcalc(cc->geom.y,
-			    cc->geom.y + cc->geom.h + (cc->bwidth * 2),
-			    area.y, area.y + area.h, sc->snapdist);
-			client_move(cc);
-			menu_windraw(sc, cc->win,
-			    "%4d, %-4d", cc->geom.x, cc->geom.y);
-			break;
-		case ButtonRelease:
-			client_move(cc);
-			XUnmapWindow(X_Dpy, sc->menu.win);
-			XReparentWindow(X_Dpy, sc->menu.win, sc->rootwin, 0, 0);
-			XUngrabPointer(X_Dpy, CurrentTime);
-			return;
-		}
-	}
-	/* NOTREACHED */
-}