Browse Source

Add Imlib2 support: option dependence (use --without-imlib2 at configure). New status sequence: \i[left/right;w;h;/path/img] OR \i[x;y;w;h;/path/img]

Martin Duquesnoy 12 years ago
parent
commit
9d462ac71e
6 changed files with 141 additions and 46 deletions
  1. 42 38
      configure
  2. 2 2
      src/client.c
  3. 36 2
      src/draw.h
  4. 3 1
      src/fifo.c
  5. 45 3
      src/status.c
  6. 13 0
      src/wmfs.c

+ 42 - 38
configure

@@ -11,61 +11,65 @@ MANPREFIX="$PREFIX/man"
 XDG_CONFIG_DIR="$PREFIX/etc/xdg"
 
 while true; do
-	case "$1" in
-		--without-xinerama)
-			USE_XINERAMA="";  shift;;
-		--prefix)
-			[ -z "$2" ] && echo "Missing argument" && exit 1
-			PREFIX=$2; shift 2;;
-		--xdg-config-dir)
-			[ -z "$2" ] && echo "Missing argument" && exit 1
-			XDG_CONFIG_DIR=$2; shift 2;;
-		--help|-h)
-			echo "Usage: ./configure [options]
+    case "$1" in
+        --without-xinerama)
+	    USE_XINERAMA="";  shift;;
+        --without-imlib2)
+            USE_IMLIB2="";  shift;;
+	--prefix)
+	    [ -z "$2" ] && echo "Missing argument" && exit 1
+	    PREFIX=$2; shift 2;;
+	--xdg-config-dir)
+	    [ -z "$2" ] && echo "Missing argument" && exit 1
+	    XDG_CONFIG_DIR=$2; shift 2;;
+	--help|-h)
+	    echo "Usage: ./configure [options]
 	--without-xinerama		: compile without xinerama support
+        --without-imlib2                : compile without imlib2 support
 	--prefix DIRECTORY		: install binary with specified prefix (default $PREFIX)
 	--xdg-config-dir DIRECTORY	: install configuration to specified directory (default $XDG_CONFIG_DIR)"
-			exit 0;;
-		*) break;;
-	esac
+	    exit 0;;
+	*) break;;
+    esac
 done
 
-LIBS="$LIBS $USE_XINERAMA"
+LIBS="$LIBS $USE_XINERAMA $USE_IMLIB2"
 
 which pkg-config > /dev/null 2>&1
 
 if [ $? -eq 0 ];
 then
-	CFLAGS=`pkg-config --cflags-only-I $LIBS`
-	LDFLAGS=`pkg-config --libs $LIBS`
+    CFLAGS=`pkg-config --cflags-only-I $LIBS`
+    LDFLAGS=`pkg-config --libs $LIBS`
 else
 	# Try to use some known paths
-	case $OS in
-		FreeBSD)
-			CFLAGS="-I/usr/local/include"
-			LDFLAGS="-L/usr/local/lib";;
-		OpenBSD)
-			CFLAGS="-I/usr/X11R6/include -I/usr/local/include"
-			LDFLAGS="-L/usr/X11R6/lib -L/usr/local/lib";;
-		NetBSD)
-			CFLAGS="-I/usr/X11R7/include -I/usr/local/include"
-			LDFLAGS="-L/usr/X11R7/lib -L/usr/local/lib";;
-		Linux)
-			CFLAGS=""
-			LDFLAGS=""
-			;;
-		*)
-			echo "No default CFLAGS and LDFLAGS found for your OS, feel free to contribute or install pkg-config :)"
-			exit 1;;
-	esac
+    case $OS in
+	FreeBSD)
+	    CFLAGS="-I/usr/local/include"
+	    LDFLAGS="-L/usr/local/lib";;
+	OpenBSD)
+	    CFLAGS="-I/usr/X11R6/include -I/usr/local/include"
+	    LDFLAGS="-L/usr/X11R6/lib -L/usr/local/lib";;
+	NetBSD)
+	    CFLAGS="-I/usr/X11R7/include -I/usr/local/include"
+	    LDFLAGS="-L/usr/X11R7/lib -L/usr/local/lib";;
+	Linux)
+	    CFLAGS=""
+	    LDFLAGS=""
+	    ;;
+	*)
+	    echo "No default CFLAGS and LDFLAGS found for your OS, feel free to contribute or install pkg-config :)"
+	    exit 1;;
+    esac
 
-	LDFLAGS="$LDFLAGS -lX11"
-
-	[ -n "$USE_XINERAMA" ] && LDFLAGS="$LDFLAGS -lXinerama"
+    LDFLAGS="$LDFLAGS -lX11"
 
+    [ -n "$USE_XINERAMA" ] && LDFLAGS="$LDFLAGS -lXinerama"
+    [ -n "$USE_IMLIB2" ] && LDFLAGS="$LDFLAGS -lImlib2"
 fi
 
 [ -n "$USE_XINERAMA" ] && CFLAGS="$CFLAGS -DHAVE_XINERAMA"
+[ -n "$USE_IMLIB2" ] && CFLAGS="$CFLAGS -DHAVE_IMLIB2"
 
 cat > Makefile << EOF
 PREFIX=$PREFIX

+ 2 - 2
src/client.c

@@ -407,7 +407,7 @@ client_frame_update(struct client *c, struct colpair *cp)
                     barwin_resize(c->titlebar, f, c->tbarw);
 
                     barwin_refresh_color(c->titlebar);
-                    draw_rect(c->titlebar->dr, g, c->scol.bg);
+                    draw_rect(c->titlebar->dr, &g, c->scol.bg);
                     draw_text(c->titlebar->dr, c->theme, xt, y, cp->fg, c->title);
                     barwin_refresh(c->titlebar);
 
@@ -423,7 +423,7 @@ client_frame_update(struct client *c, struct colpair *cp)
                     barwin_resize(cc->titlebar, f, c->tbarw - 2);
 
                     barwin_refresh_color(cc->titlebar);
-                    draw_rect(cc->titlebar->dr, g, c->scol.bg);
+                    draw_rect(cc->titlebar->dr, &g, c->scol.bg);
                     draw_text(cc->titlebar->dr, c->theme, xt, y - 1, c->ncol.fg, cc->title);
                     barwin_refresh(cc->titlebar);
 

+ 36 - 2
src/draw.h

@@ -10,6 +10,10 @@
 #include <string.h>
 #include <X11/Xlib.h>
 
+#ifdef HAVE_IMLIB2
+#include <Imlib2.h>
+#endif /* HAVE_IMLIB2 */
+
 #include "wmfs.h"
 #include "config.h"
 #include "screen.h"
@@ -25,12 +29,42 @@ draw_text(Drawable d, struct theme *t, int x, int y, Color fg, const char *str)
 }
 
 static inline void
-draw_rect(Drawable d, struct geo g, Color bg)
+draw_rect(Drawable d, struct geo *g, Color bg)
 {
      XSetForeground(W->dpy, W->gc, bg);
-     XFillRectangle(W->dpy, d, W->gc, g.x, g.y, g.w, g.h);
+     XFillRectangle(W->dpy, d, W->gc, g->x, g->y, g->w, g->h);
+}
+
+#ifdef HAVE_IMLIB2
+
+static inline void
+draw_image(Drawable d, struct geo *g, char *path)
+{
+     Imlib_Image image = imlib_load_image(path);
+
+     imlib_context_set_drawable(d);
+     imlib_context_set_image(image);
+
+     imlib_render_image_on_drawable_at_size(g->x, g->y, g->w, g->h);
+
+     imlib_free_image();
 }
 
+static inline void
+draw_image_get_size(char *path, int *w, int *h)
+{
+     Imlib_Image image = imlib_load_image(path);
+
+     imlib_context_set_image(image);
+
+     *w = imlib_image_get_width();
+     *h = imlib_image_get_height();
+
+     imlib_free_image();
+}
+
+#endif /* HAVE_IMLIB2 */
+
 /*
  * For client use
  */

+ 3 - 1
src/fifo.c

@@ -11,6 +11,8 @@
 #include "config.h"
 #include "fifo.h"
 
+#define READ_SIZE (32768)
+
 static void
 fifo_open(void)
 {
@@ -63,7 +65,7 @@ fifo_parse(char *cmd)
 void
 fifo_read(void)
 {
-     char buf[256] = { 0 };
+     char buf[READ_SIZE] = { 0 };
      int ret;
 
      if((ret = read(W->fifo.fd, buf, sizeof(buf) - 1)) > 0)

+ 45 - 3
src/status.c

@@ -8,6 +8,7 @@
 #include "config.h"
 #include "infobar.h"
 #include "util.h"
+#include "draw.h"
 
 #include <string.h>
 
@@ -82,7 +83,7 @@ status_parse(struct element *e)
 
           p = ++dstr;
 
-          if(!(strchr("sR", *p)) || !(end = strchr(p, ']')))
+          if(!(strchr("sRi", *p)) || !(end = strchr(p, ']')))
                continue;
 
           /* Then parse & list it */
@@ -114,6 +115,22 @@ status_parse(struct element *e)
                sq->color = color_atoh(arg[3 + shift]);
 
                break;
+
+          /*
+           * Image sequence: \i[left/right;w;h;/path/img] OR \i[x;y;w;h;/path/img]
+           */
+#ifdef HAVE_IMLIB2
+          case 'i':
+               i = parse_args(p + 2, ';', ']', 5, arg);
+               STATUS_CHECK_ARGS(i, 3, 4, dstr, end);
+               sq = status_new_seq(type, i, 3, arg, &shift);
+
+               sq->geo.w = ATOI(arg[1 + shift]);
+               sq->geo.h = ATOI(arg[2 + shift]);
+               sq->str   = xstrdup(arg[3 + shift]);
+
+               break;
+#endif /* HAVE_IMLIB2 */
           }
 
           SLIST_INSERT_TAIL(&e->infobar->statushead, sq, next, prev);
@@ -148,7 +165,7 @@ status_apply_list(struct element *e)
      struct status_seq *sq;
      struct barwin *b = SLIST_FIRST(&e->bars);
      struct mousebind *m;
-     int left = 0, right = 0;
+     int left = 0, right = 0, w, h;
 
      SLIST_FOREACH(sq, &e->infobar->statushead, next)
      {
@@ -182,13 +199,38 @@ status_apply_list(struct element *e)
 
                STATUS_ALIGN(sq->align);
 
-               draw_rect(b->dr, sq->geo, sq->color);
+               draw_rect(b->dr, &sq->geo, sq->color);
+
+               if(!SLIST_EMPTY(&sq->mousebinds))
+                    SLIST_FOREACH(m, &sq->mousebinds, snext)
+                         m->area = sq->geo;
+
+               break;
+
+          /* Image */
+#ifdef HAVE_IMLIB2
+          case 'i':
+               draw_image_get_size(sq->str, &w, &h);
+
+               if(sq->geo.w <= 0)
+                    sq->geo.w = w;
+               if(sq->geo.h <= 0)
+                    sq->geo.h = h;
+
+               if(sq->align != NoAlign)
+                    sq->geo.y = (e->geo.h >> 1) - (sq->geo.h >> 1);
+
+               STATUS_ALIGN(sq->align);
+
+               draw_image(b->dr, &sq->geo, sq->str);
 
                if(!SLIST_EMPTY(&sq->mousebinds))
                     SLIST_FOREACH(m, &sq->mousebinds, snext)
                          m->area = sq->geo;
 
                break;
+#endif /* HAVE_IMLIB2 */
+
           }
      }
 }

+ 13 - 0
src/wmfs.c

@@ -7,6 +7,10 @@
 #include <X11/keysym.h>
 #include <X11/cursorfont.h>
 
+#ifdef HAVE_IMLIB2
+#include <Imlib2.h>
+#endif /* HAVE_IMLIB2 */
+
 #include "wmfs.h"
 #include "event.h"
 #include "ewmh.h"
@@ -154,6 +158,15 @@ wmfs_xinit(void)
       */
      SLIST_INIT(&W->h.barwin);
 
+     /*
+      * Optional dep init
+      */
+#ifdef HAVE_IMLIB2
+     imlib_context_set_display(W->dpy);
+     imlib_context_set_visual(DefaultVisual(W->dpy, W->xscreen));
+     imlib_context_set_colormap(DefaultColormap(W->dpy, W->xscreen));
+#endif /* HAVE_IMLIB2 */
+
      W->flags |= WMFS_RUNNING;
 }