summary refs log tree commit diff
path: root/xutil.c
diff options
context:
space:
mode:
authorokan <okan>2016-10-24 20:44:08 +0000
committerokan <okan>2016-10-24 20:44:08 +0000
commitdcb741d2b1378432e226bbeea274c2e5e2508c2d (patch)
treeb9a0fcb7200417e49167e78a687632b23cdbf812 /xutil.c
parentfa06851b0ee5b49138f782e500e12646455dd171 (diff)
parentdb93599a0fb302271e10a9dcbcbe6cafdc8aa2cb (diff)
downloadcwm-dcb741d2b1378432e226bbeea274c2e5e2508c2d.tar.gz
cwm-dcb741d2b1378432e226bbeea274c2e5e2508c2d.tar.xz
cwm-dcb741d2b1378432e226bbeea274c2e5e2508c2d.zip
cvsimport
* refs/heads/master: (34 commits)
  Make it clear these are flags.
  Remove duplicate check that strsubmatch() already does; while here, fix a comment.
  Sprinkle __func__ in appropriate error messages.
  Get rid of 'matchname'; it's too surprising to have the menu change during client search as different potential str matches are cycled through. If there's interest, the only string that doesn't exist in the listing is the window's class - that can be added of course, but it makes the line too long imho.
  clean up search_match_client(); no behaviour change
  Refactor callbacks to take a void * so as to not try and generalize into client_ctx in keypress and buttonpress event handlers; pass appropriate *ctx's based on context.
  remove another unused proto
  Rename 2 kbfunc to match closer to what they do
  Add an argument to the callbacks to pass the xevent context, button or key press. This allows to remove a few hacks to duplicate functions only for behaviour changes; now differing behaviours are pushed down to the callback. Also will allow for previously unavailable actions to be bind-able down the road.
  Check the ptr bounds in the new client during cycling, since not all actions do ptrsave, such as restoring client geometry; adapted from a diff by Vadim Vygonets.
  More accurate to say 'toggle', rather than 'select', for group[n]/nogroup.
  Add CM-a for 'nogroup' (CM-0 stays for now); update manpage to reflect.
  Stash wmname into conf.
  When removing xrandr regions, ensure clients are within the bounds of the screen; adapted from an ancient diff from Sviatoslav Chagaev. Things in this area will likely change, but put this in so it works now and serves as a reminder.
  Calculate client nameqlen in client_setname(), the only place it's needed/used.
  Turn CALMWM_NGROUPS define into variable, ngroups.
  Start simplifying menu code; and in turn, remove a cursor no longer needed.
  Defaults are split between defines and conf_init(); normalize these, as well as give 'sticky' groups its own variable.
  For both kb and mouse move, it is possible to grab a client and move it completely off the screen/region; instead, if the pointer is outside of the client bounds, warp the pointer to the closest edge before moving.
  client_ptrwarp should not deal with unhiding or raising clients (non ptr requests); most callers do this already - deal with the few that do not. client_ptrwarp becomes a simple wrapper (setpos) but it will be expanded.
  ...
Diffstat (limited to 'xutil.c')
-rw-r--r--xutil.c109
1 files changed, 15 insertions, 94 deletions
diff --git a/xutil.c b/xutil.c
index 3393179..2a851df 100644
--- a/xutil.c
+++ b/xutil.c
@@ -31,68 +31,6 @@
 
 #include "calmwm.h"
 
-static unsigned int ign_mods[] = { 0, LockMask, Mod2Mask, Mod2Mask | LockMask };
-
-void
-xu_btn_grab(Window win, int mask, unsigned int btn)
-{
-	unsigned int	i;
-
-	for (i = 0; i < nitems(ign_mods); i++)
-		XGrabButton(X_Dpy, btn, (mask | ign_mods[i]), win,
-		    False, BUTTONMASK, GrabModeAsync,
-		    GrabModeSync, None, None);
-}
-
-void
-xu_btn_ungrab(Window win)
-{
-	XUngrabButton(X_Dpy, AnyButton, AnyModifier, win);
-}
-
-void
-xu_key_grab(Window win, unsigned int mask, KeySym keysym)
-{
-	KeyCode		 code;
-	unsigned int	 i;
-
-	code = XKeysymToKeycode(X_Dpy, keysym);
-	if ((XkbKeycodeToKeysym(X_Dpy, code, 0, 0) != keysym) &&
-	    (XkbKeycodeToKeysym(X_Dpy, code, 0, 1) == keysym))
-		mask |= ShiftMask;
-
-	for (i = 0; i < nitems(ign_mods); i++)
-		XGrabKey(X_Dpy, code, (mask | ign_mods[i]), win,
-		    True, GrabModeAsync, GrabModeAsync);
-}
-
-void
-xu_key_ungrab(Window win)
-{
-	XUngrabKey(X_Dpy, AnyKey, AnyModifier, win);
-}
-
-int
-xu_ptr_grab(Window win, unsigned int mask, Cursor curs)
-{
-	return(XGrabPointer(X_Dpy, win, False, mask,
-	    GrabModeAsync, GrabModeAsync,
-	    None, curs, CurrentTime) == GrabSuccess ? 0 : -1);
-}
-
-int
-xu_ptr_regrab(unsigned int mask, Cursor curs)
-{
-	return(XChangeActivePointerGrab(X_Dpy, mask,
-	    curs, CurrentTime) == GrabSuccess ? 0 : -1);
-}
-
-void
-xu_ptr_ungrab(void)
-{
-	XUngrabPointer(X_Dpy, CurrentTime);
-}
-
 void
 xu_ptr_getpos(Window win, int *x, int *y)
 {
@@ -177,8 +115,8 @@ xu_ewmh_net_supported_wm_check(struct screen_ctx *sc)
 	XChangeProperty(X_Dpy, w, ewmh[_NET_SUPPORTING_WM_CHECK],
 	    XA_WINDOW, 32, PropModeReplace, (unsigned char *)&w, 1);
 	XChangeProperty(X_Dpy, w, ewmh[_NET_WM_NAME],
-	    cwmh[UTF8_STRING], 8, PropModeReplace, (unsigned char *)WMNAME,
-	    strlen(WMNAME));
+	    cwmh[UTF8_STRING], 8, PropModeReplace,
+	    (unsigned char *)Conf.wmname, strlen(Conf.wmname));
 }
 
 void
@@ -193,19 +131,20 @@ xu_ewmh_net_desktop_geometry(struct screen_ctx *sc)
 void
 xu_ewmh_net_workarea(struct screen_ctx *sc)
 {
-	long	 workareas[CALMWM_NGROUPS][4];
-	int	 i;
-
-	for (i = 0; i < CALMWM_NGROUPS; i++) {
-		workareas[i][0] = sc->work.x;
-		workareas[i][1] = sc->work.y;
-		workareas[i][2] = sc->work.w;
-		workareas[i][3] = sc->work.h;
-	}
+	unsigned long	*workarea;
+	int		 i, ngroups = Conf.ngroups;
 
+	workarea = xreallocarray(NULL, ngroups * 4, sizeof(unsigned long));
+	for (i = 0; i < ngroups; i++) {
+		workarea[4 * i + 0] = sc->work.x;
+		workarea[4 * i + 1] = sc->work.y;
+		workarea[4 * i + 2] = sc->work.w;
+		workarea[4 * i + 3] = sc->work.h;
+	}
 	XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_WORKAREA],
-	    XA_CARDINAL, 32, PropModeReplace, (unsigned char *)workareas,
-	    CALMWM_NGROUPS * 4);
+	    XA_CARDINAL, 32, PropModeReplace, (unsigned char *)workarea,
+	    ngroups * 4);
+	free(workarea);
 }
 
 void
@@ -285,7 +224,7 @@ xu_ewmh_net_wm_desktop_viewport(struct screen_ctx *sc)
 void
 xu_ewmh_net_wm_number_of_desktops(struct screen_ctx *sc)
 {
-	long	 ndesks = CALMWM_NGROUPS;
+	long	 ndesks = Conf.ngroups;
 
 	XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_NUMBER_OF_DESKTOPS],
 	    XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&ndesks, 1);
@@ -531,21 +470,3 @@ xu_xorcolor(XftColor a, XftColor b, XftColor *r)
 	r->color.blue = a.color.blue ^ b.color.blue;
 	r->color.alpha = 0xffff;
 }
-
-int
-xu_xft_width(XftFont *xftfont, const char *text, int len)
-{
-	XGlyphInfo	 extents;
-
-	XftTextExtentsUtf8(X_Dpy, xftfont, (const FcChar8*)text,
-	    len, &extents);
-
-	return(extents.xOff);
-}
-
-void
-xu_xft_draw(struct screen_ctx *sc, const char *text, int color, int x, int y)
-{
-	XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[color], sc->xftfont,
-	    x, y, (const FcChar8*)text, strlen(text));
-}