Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit e019134a31ad5f7acfa7774bb0167e770c0c1a14 @baskerville committed Jan 3, 2013
Showing with 3,077 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +26 −0 LICENSE
  3. +53 −0 Makefile
  4. +46 −0 README.md
  5. +22 −0 examples/sxhkdrc
  6. +42 −0 helpers.c
  7. +21 −0 helpers.h
  8. +2,557 −0 keys.c
  9. +22 −0 keys.h
  10. +240 −0 sxhkd.c
  11. +45 −0 sxhkd.h
@@ -0,0 +1,3 @@
+*.o
+sxhkd
+tags
@@ -0,0 +1,26 @@
+Copyright (c) 2013, Bastien Dejean
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+The views and conclusions contained in the software and documentation are those
+of the authors and should not be interpreted as representing official policies,
+either expressed or implied, of the FreeBSD Project.
@@ -0,0 +1,53 @@
+VERSION = 0.1
+
+CC = gcc
+LIBS = -lm -lxcb -lxcb-keysyms
+CFLAGS = -std=c99 -pedantic -Wall -Wextra -DVERSION=\"$(VERSION)\"
+LDFLAGS = $(LIBS)
+
+PREFIX ?= /usr/local
+BINPREFIX = $(PREFIX)/bin
+MANPREFIX = $(PREFIX)/share/man
+
+SRC = sxhkd.c keys.c helpers.c
+OBJ = $(SRC:.c=.o)
+
+all: CFLAGS += -Os
+all: LDFLAGS += -s
+all: options sxhkd
+
+debug: CFLAGS += -O0 -g -DDEBUG
+debug: options sxhkd
+
+options:
+ @echo "sxhkd build options:"
+ @echo "CC = $(CC)"
+ @echo "CFLAGS = $(CFLAGS)"
+ @echo "LDFLAGS = $(LDFLAGS)"
+ @echo "PREFIX = $(PREFIX)"
+
+.c.o:
+ @echo "CC $<"
+ @$(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $<
+
+sxhkd: $(OBJ)
+ @echo CC -o $@
+ @$(CC) -o $@ $(OBJ) $(LDFLAGS)
+
+clean:
+ @echo "cleaning"
+ @rm -f $(OBJ) sxhkd
+
+install:
+ @echo "installing executable files to $(DESTDIR)$(BINPREFIX)"
+ @install -D -m 755 sxhkd $(DESTDIR)$(BINPREFIX)/xshkd
+ @echo "installing manual page to $(DESTDIR)$(MANPREFIX)/man1"
+ @install -D -m 644 sxhkd.1 $(DESTDIR)$(MANPREFIX)/man1/xshkd.1
+
+uninstall:
+ @echo "removing executable files from $(DESTDIR)$(BINPREFIX)"
+ @rm -f $(DESTDIR)$(BINPREFIX)/sxhkd
+ @echo "removing manual page from $(DESTDIR)$(MANPREFIX)/man1"
+ @rm -f $(DESTDIR)$(MANPREFIX)/man1/sxhkd.1
+
+.PHONY: all debug options clean install uninstall
@@ -0,0 +1,46 @@
+## Description
+
+sxhkd is a simple X hotkey daemon.
+
+## Usage
+
+### Synopsis
+
+ sxhkd [OPTIONS]
+
+### Options
+
+* `-h`: Print the synopsis to standard output and exit.
+* `-v`: Print the version information to standard output and exit.
+* `-c CONFIG_FILE`: Use the given configuration file instead of the default (`$XDG_CONFIG_HOME/sxhkd/sxhkdrc`).
+
+## Configuration
+
+Each line of the configuration file is interpreted as so:
+- If it starts with `#`, it is ignored.
+- If it starts with a white space character, it is read as a command.
+- Otherwise, it is parsed as a hotkey: each key name is separated by spaces and/or `+` characters.
+
+General syntax:
+ [MODIFIER + ]*[@]KEYSYM
+ COMMAND
+
+Where `MODIFIER` is `super|hyper|meta|alt|control|ctrl|shift|mode_switch|lock|mod1|mod2|mod3|mod4|mod5`.
+
+If `@` is added at the beginning of the keysym, the command will be run on key release events, otherwise on key press events.
+
+The keysym names are those your will get from `xev` (minus the prefix if any).
+
+What is actually executed is `/bin/sh -c COMMAND`, which means you can use environment variables in `COMMAND`.
+
+If *sxhkd* receives a `SIGUSR1` signal, it will reload its configuration file.
+
+## Installation
+
+ make
+ make install
+
+## Dependencies
+
+- libxcb
+- xcb-util-keysyms
@@ -0,0 +1,22 @@
+MonBrightnessDown
+ backlight -1
+
+MonBrightnessUp
+ backlight +1
+
+AudioPrev
+ mpc -q prev
+
+AudioNext
+ mpc -q next
+
+super + LaunchA
+ scrot
+
+super + shift + @LaunchA
+ scrot -s
+
+super + shift + equal
+ mosaic "$HOME/image"
+
+# vim: set ft=conf:
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/wait.h>
+#include "helpers.h"
+#include "sxhkd.h"
+
+void warn(char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+}
+
+__attribute__((noreturn))
+void err(char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ exit(EXIT_FAILURE);
+}
+
+void spawn(char *cmd[])
+{
+ if (fork() == 0) {
+ if (dpy != NULL)
+ close(xcb_get_file_descriptor(dpy));
+ if (fork() == 0) {
+ setsid();
+ execvp(cmd[0], cmd);
+ err("Spawning failed.\n");
+ }
+ exit(EXIT_SUCCESS);
+ }
+ wait(NULL);
+}
@@ -0,0 +1,21 @@
+#ifndef _HELPERS_H
+#define _HELPERS_H
+
+#define LENGTH(x) (sizeof(x) / sizeof(*x))
+#define SHELL "/bin/sh"
+#define MAXLEN 256
+
+#ifdef DEBUG
+# define PUTS(x) puts(x)
+# define PRINTF(x,...) printf(x, __VA_ARGS__)
+#else
+# define PUTS(x) ((void)0)
+# define PRINTF(x,...) ((void)0)
+#endif
+
+void warn(char *, ...);
+__attribute__((noreturn))
+void err(char *, ...);
+void spawn(char *[]);
+
+#endif
Oops, something went wrong.

0 comments on commit e019134

Please sign in to comment.