about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--bar.c12
-rw-r--r--client.c9
-rw-r--r--cmd.c10
-rw-r--r--config.h12
-rw-r--r--key.c16
-rw-r--r--util.c25
-rw-r--r--util.h12
-rw-r--r--wm.c33
-rw-r--r--wm.h9
9 files changed, 87 insertions, 51 deletions
diff --git a/bar.c b/bar.c
index 8d4fb36..17db8cd 100644
--- a/bar.c
+++ b/bar.c
@@ -5,12 +5,22 @@
 
 #include "wm.h"
 
+static const char *status[] = {
+	"sh", "-c", "echo -n `date` `uptime | sed 's/.*://; s/,//g'`"
+		" `acpi | awk '{print $4}' | sed 's/,//'`", 0 \
+};
+
 void
 draw_bar()
 {
+	static char buf[1024];
+
+	buf[0] = 0;
+	pipe_spawn(buf, sizeof(buf), dpy, (char **)status);
+
 	brush.rect = barrect;
 	brush.rect.x = brush.rect.y = 0;
-	draw(dpy, &brush, False, 0);
+	draw(dpy, &brush, False, buf);
 
 	XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, barrect.width,
 			barrect.height, 0, 0);
diff --git a/client.c b/client.c
index caa523c..f87fb80 100644
--- a/client.c
+++ b/client.c
@@ -122,6 +122,8 @@ unmanage(Client *c)
 	XSetErrorHandler(error_handler);
 	XUngrabServer(dpy);
 	flush_events(EnterWindowMask);
+	if(stack)
+		focus(stack);
 }
 
 
@@ -135,3 +137,10 @@ getclient(Window w)
 	return NULL;
 }
 
+void
+draw_client(Client *c)
+{
+	
+
+
+}
diff --git a/cmd.c b/cmd.c
index 9ac4e72..4f1c84b 100644
--- a/cmd.c
+++ b/cmd.c
@@ -5,22 +5,22 @@
 
 #include "wm.h"
 #include <stdio.h>
+#include <string.h>
 
 void
-run(char *arg)
+run(void *aux)
 {
-	spawn(dpy, arg);
+	spawn(dpy, aux);
 }
 
 void
-quit(char *arg)
+quit(void *aux)
 {
-	fputs("quit\n", stderr);
 	running = False;
 }
 
 void
-kill(char *arg)
+kill(void *aux)
 {
 	Client *c = stack;
 
diff --git a/config.h b/config.h
index adca4e5..ce9e7ab 100644
--- a/config.h
+++ b/config.h
@@ -3,16 +3,8 @@
  * See LICENSE file for license details.
  */
 
-#define FONT		"-*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*"
+#define FONT		"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
 #define BGCOLOR		"#000000"
 #define FGCOLOR		"#ffaa00"
 #define BORDERCOLOR	"#000000"
-#define STATUSCMD	"echo -n `date` `uptime | sed 's/.*://; s/,//g'`" \
-					" `acpi | awk '{print $4}' | sed 's/,//'`"
-#define PLCMD		"`ls -lL /bin /sbin /usr/bin /usr/local/bin 2>/dev/null | awk 'NF>2 && $1 ~ /^[^d].*x/ {print $NF}' | sort | uniq | gridmenu`"
-
-#define KEYS		\
-	{ Mod1Mask, XK_Return, run, "xterm -u8 -bg black -fg white -fn '-*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*'" }, \
-	{ Mod1Mask, XK_p, run, PLCMD }, \
-	{ Mod1Mask | ShiftMask, XK_q, quit, NULL},
-
+#define STATUSDELAY 1 /* milliseconds */
diff --git a/key.c b/key.c
index b5d46c6..7caae15 100644
--- a/key.c
+++ b/key.c
@@ -7,8 +7,20 @@
 
 #include <X11/keysym.h>
 
+static const char *term[] = { 
+	"xterm", "-u8", "-bg", "black", "-fg", "white", "-fn",
+	"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", 0 
+};
+
+static const char *proglist[] = {
+		"sh", "-c", "exec `ls -lL /bin /sbin /usr/bin /usr/local/bin 2>/dev/null | awk 'NF>2 && $1 ~ /^[^d].*x/ {print $NF}' | sort | uniq | gridmenu`", 0
+};
+
 static Key key[] = {
-	KEYS
+	{ Mod1Mask, XK_Return, run, term },
+	{ Mod1Mask, XK_p, run, proglist }, 
+	{ Mod1Mask | ShiftMask, XK_c, kill, NULL}, 
+	{ Mod1Mask | ShiftMask, XK_q, quit, NULL},
 };
 
 void
@@ -37,7 +49,7 @@ keypress(XEvent *e)
 	for(i = 0; i < len; i++)
 		if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
 			if(key[i].func)
-				key[i].func(key[i].arg);
+				key[i].func(key[i].aux);
 			return;
 		}
 }
diff --git a/util.c b/util.c
index 052d535..2cc2d4d 100644
--- a/util.c
+++ b/util.c
@@ -14,8 +14,6 @@
 
 #include "util.h"
 
-static char *shell = NULL;
-
 void
 error(char *errstr, ...) {
 	va_list ap;
@@ -85,21 +83,17 @@ swap(void **p1, void **p2)
 }
 
 void
-spawn(Display *dpy, const char *cmd)
+spawn(Display *dpy, char *argv[])
 {
-	if(!shell && !(shell = getenv("SHELL")))
-		shell = "/bin/sh";
-
-	if(!cmd)
+	if(!argv || !argv[0])
 		return;
 	if(fork() == 0) {
 		if(fork() == 0) {
 			if(dpy)
 				close(ConnectionNumber(dpy));
 			setsid();
-			fprintf(stderr, "gridwm: execlp %s %s -c %s", shell, shell, cmd);
-			execlp(shell, shell, "-c", cmd, NULL);
-			fprintf(stderr, "gridwm: execlp %s", cmd);
+			execvp(argv[0], argv);
+			fprintf(stderr, "gridwm: execvp %s", argv[0]);
 			perror(" failed");
 		}
 		exit (0);
@@ -108,15 +102,12 @@ spawn(Display *dpy, const char *cmd)
 }
 
 void
-pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd)
+pipe_spawn(char *buf, unsigned int len, Display *dpy, char *argv[])
 {
 	unsigned int l, n;
 	int pfd[2];
 
-	if(!shell && !(shell = getenv("SHELL")))
-		shell = "/bin/sh";
-
-	if(!cmd)
+	if(!argv || !argv[0])
 		return;
 
 	if(pipe(pfd) == -1) {
@@ -131,8 +122,8 @@ pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd)
 		dup2(pfd[1], STDOUT_FILENO);
 		close(pfd[0]);
 		close(pfd[1]);
-		execlp(shell, shell, "-c", cmd, NULL);
-		fprintf(stderr, "gridwm: execlp %s", cmd);
+		execvp(argv[0], argv);
+		fprintf(stderr, "gridwm: execvp %s", argv[0]);
 		perror(" failed");
 	}
 	else {
diff --git a/util.h b/util.h
index 51b0871..00f0714 100644
--- a/util.h
+++ b/util.h
@@ -9,12 +9,16 @@ extern void *emallocz(unsigned int size);
 extern void *emalloc(unsigned int size);
 extern void *erealloc(void *ptr, unsigned int size);
 extern char *estrdup(const char *str);
-#define eassert(a) do { \
+#define eassert(a) \
+	do { \
 		if(!(a)) \
 			failed_assert(#a, __FILE__, __LINE__); \
 	} while (0)
 extern void failed_assert(char *a, char *file, int line);
-void pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd);
-extern void spawn(Display *dpy, const char *cmd);
+extern void pipe_spawn(char *buf, unsigned int len, Display *dpy, char *argv[]);
+extern void spawn(Display *dpy, char *argv[]);
 extern void swap(void **p1, void **p2);
-unsigned char *getselection(unsigned long offset, unsigned long *len, unsigned long *remain);
+extern unsigned char *getselection(unsigned long offset, unsigned long *len,
+		unsigned long *remain);
+extern unsigned int tokenize(char **result, unsigned int reslen,
+		char *str, char delim);
diff --git a/wm.c b/wm.c
index b156cba..f247372 100644
--- a/wm.c
+++ b/wm.c
@@ -3,10 +3,15 @@
  * See LICENSE file for license details.
  */
 
+#include <errno.h>
+
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <sys/types.h>
+#include <sys/time.h>
+
 #include <X11/cursorfont.h>
 #include <X11/Xatom.h>
 #include <X11/Xproto.h>
@@ -160,12 +165,9 @@ startup_error_handler(Display *dpy, XErrorEvent *error)
 static void
 cleanup()
 {
-	/*
-	Client *c;
-	for(c=client; c; c=c->next)
-		reparent_client(c, root, c->sel->rect.x, c->sel->rect.y);
+	while(clients)
+		unmanage(clients);
 	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
-	*/
 }
 
 int
@@ -176,6 +178,11 @@ main(int argc, char *argv[])
 	unsigned int mask;
 	Window w;
 	XEvent ev;
+	fd_set fds;
+	struct timeval t, timeout = {
+		.tv_usec = 0,
+		.tv_sec = STATUSDELAY,
+	};
 
 	/* command line args */
 	for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
@@ -264,9 +271,19 @@ main(int argc, char *argv[])
 	scan_wins();
 
 	while(running) {
-		XNextEvent(dpy, &ev);
-		if(handler[ev.type])
-			(handler[ev.type]) (&ev); /* call handler */
+		if(XPending(dpy) > 0) {
+			XNextEvent(dpy, &ev);
+			if(handler[ev.type])
+				(handler[ev.type]) (&ev); /* call handler */
+			continue;
+		}
+		FD_ZERO(&fds);
+		FD_SET(ConnectionNumber(dpy), &fds);
+		t = timeout;
+		if(select(ConnectionNumber(dpy) + 1, &fds, NULL, NULL, &t) > 0)
+			continue;
+		else if(errno != EINTR)
+			draw_bar();
 	}
 
 	cleanup();
diff --git a/wm.h b/wm.h
index b9ba8f7..24662fa 100644
--- a/wm.h
+++ b/wm.h
@@ -42,8 +42,8 @@ struct Client {
 struct Key {
 	unsigned long mod;
 	KeySym keysym;
-	void (*func)(char *arg);
-	char *arg;
+	void (*func)(void *aux);
+	void *aux;
 };
 
 extern Display *dpy;
@@ -64,8 +64,9 @@ extern Client *clients, *stack;
 extern void draw_bar();
 
 /* cmd.c */
-extern void run(char *arg);
-extern void quit(char *arg);
+extern void run(void *aux);
+extern void quit(void *aux);
+extern void kill(void *aux);
 
 /* client.c */
 extern void manage(Window w, XWindowAttributes *wa);
Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#!/usr/bin/python -O
# coding=utf-8
#
# Ranger: Explore your forest of files from inside your terminal
# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# ----------------------------------------------------------------------------
#
# An embedded shell script. It allows you to change the directory
# after you exit ranger by starting it with: source ranger ranger
"""":
if [ $1 ]; then
	if [ -z "$XDG_CONFIG_HOME" ]; then
		"$@" --fail-unless-cd && cd "$(grep \^\' ~/.config/ranger/bookmarks | cut -b3-)"
	else
		"$@" --fail-unless-cd && cd "$(grep \^\' "$XDG_CONFIG_HOME"/ranger/bookmarks | cut -b3-)"
	fi
else
	echo "usage: source path/to/ranger.py path/to/ranger.py"
fi
return 1
"""

import sys

# Redefine the docstring, since the previous one was hijacked to
# embed a shellscript.
__doc__ = """Ranger - file browser for the unix terminal"""

# Importing the main method may fail if the ranger directory
# is neither in the same directory as this file, nor in one of
# pythons global import paths.
try:
	from ranger.__main__ import main
except ImportError:
	if '-d' not in sys.argv and '--debug' not in sys.argv:
		print("Can't import the main module.")
		print("To run an uninstalled copy of ranger,")
		print("launch ranger.py in the top directory.")
	else:
		raise
else:
	sys.exit(main())