summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile13
-rw-r--r--man/xlnch.1104
-rw-r--r--man/xlnch.1.scd84
-rw-r--r--xlnch.c13
-rwxr-xr-xxlnchrc2
5 files changed, 209 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 172219f..b146099 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,6 @@
TARGET=xlnch
+PREFIX?=/usr/local
+MANUALS=$(PREFIX)/share/man
SRC=*.c
CC=gcc
CFLAGS=-D_GNU_SOURCE -std=c99 -pedantic
@@ -15,6 +17,9 @@ debug: $(SRC)
noasan: $(SRC)
$(CC) $(DBG_FLAGS) $(CFLAGS) -o $(TARGET) $^ $(LIBS)
+docs:
+ scdoc < man/xlnch.1.scd > man/xlnch.1
+
.PHONY: clean
clean:
@@ -22,7 +27,11 @@ clean:
rm -f $(TARGET)
install: $(TARGET)
- @cp -v $(TARGET) /usr/local/bin/$(TARGET)
+ mkdir -p $(PREFIX)/bin $(MANUALS)/man1
+ @cp -v $(TARGET) $(PREFIX)/bin/$(TARGET)
+ @install -v -m644 man/xlnch.1 $(MANUALS)/man1/xlnch.1
+
uninstall:
- @rm -v /usr/local/bin/$(TARGET)
+ @rm -v $(PREFIX)/bin/$(TARGET)
+ @rm -v $(MANUALS)/man1/xlnch.1
diff --git a/man/xlnch.1 b/man/xlnch.1
new file mode 100644
index 0000000..4ca4b92
--- /dev/null
+++ b/man/xlnch.1
@@ -0,0 +1,104 @@
+.\" Generated by scdoc 1.11.1
+.\" Complete documentation for this program is not available as a GNU info page
+.ie \n(.g .ds Aq \(aq
+.el .ds Aq '
+.nh
+.ad l
+.\" Begin generated content:
+.TH "xlnch" "1" "2021-05-04"
+.P
+.P
+.SH NAME
+.P
+xlnch - fast launcher for X
+.P
+.SH SYNOPSIS
+.P
+\fBxlnch\fR [\fIfile\fR]
+.P
+.SH OPTIONS
+.P
+\fBxlnch\fR has the following options:
+.P
+\fIfile\fR
+.RS 4
+xlnch configuration.\&
+.P
+.RE
+\fB-h\fR
+.RS 4
+Print help.\&
+.P
+.RE
+.SH DESCRIPTION
+.P
+\fBxlnch\fR parses a list of commands along with keys for executing them.\& It then
+draws the avaliable commands with their keybinding and grabs the focus so the
+next keypress will run the selected command.\& The configuration can either be
+read from a file or from the standard input.\&
+.P
+.SH CONFIGURATION
+.P
+Each line is a command.\& It must have a key, and can optionally have a
+description.\& By default xlnch exits when you press a key bound to a command.\&
+You can prefix the key with an ampersand (&) which will keep \fBxlnch\fR open and
+in focus.\& Those commands will be shown in red.\& If you ommit the command
+description, \fBxlnch\fR will show the command instead.\&
+.P
+The configuration format is this:
+.P
+.RS 4
+[&]<key>:[<description>]:<command>
+.P
+.RE
+\fBkey\fR
+.RS 4
+A single ascii character.\&
+.P
+.RE
+\fBdescription\fR
+.RS 4
+Any ascii string.\&
+.P
+.RE
+\fBcommand\fR
+.RS 4
+A valid command (see below).\&
+.P
+.RE
+.SH EXAMPLE CONFIGURATION
+.P
+f::firefox
+.br
+e:The best editor:emacs
+.br
+&t:terminals:xterm
+.P
+In this example pressing \fIf\fR will launch firefox and then exit, same for \fIe\fR
+and emacs.\& But if you press \fIt\fR an xterm will spawn but the launcher will stay
+open, so pressing \fIt\fR twice will launch two xterms consecutively.\& This makes
+more sense if used to control your window manager though it's cli interface or
+similar applications.\&
+.P
+.SH VALID COMMANDS
+.P
+Internally \fBxlnch\fR uses \fBwordexp\fR(3) to parse the command.\& So the same
+limitations apply.\& Some advanced stuff might be possible with clever quoting
+and calling \fIbash -c\fR as the command but it is recommended to make a script for
+such things and just call it from \fBxlnch\fR.\&
+.P
+.SH TIPS
+.P
+Since \fBxlnch\fR can read from stdin you can have "excecutable" files with
+different configurations.\& Just add \fI#!\&/bin/xlnch\fR on the first line, make the
+file executable and run it.\&
+.P
+You can call different xlnch configurations from within xlnch to create
+submenues.\& Don't use the & for such calls because the two xlnch windows will
+both want to constantly grab the focus.\& Either don't provide a way to go back
+to the previous menu, or simply assign \fIb\fR to the parent menu so you have a way
+back.\&
+.P
+.SH AUTHOR
+.P
+Anastasis Grammenos \ No newline at end of file
diff --git a/man/xlnch.1.scd b/man/xlnch.1.scd
new file mode 100644
index 0000000..824e2fc
--- /dev/null
+++ b/man/xlnch.1.scd
@@ -0,0 +1,84 @@
+xlnch(1)
+
+; Tabs are required for indentation (<C-q tab> in emacs)
+
+# NAME
+
+xlnch - fast launcher for X
+
+# SYNOPSIS
+
+*xlnch* [_file_]
+
+# OPTIONS
+
+*xlnch* has the following options:
+
+_file_
+ xlnch configuration.
+
+*-h*
+ Print help.
+
+# DESCRIPTION
+
+*xlnch* parses a list of commands along with keys for executing them. It then
+draws the avaliable commands with their keybinding and grabs the focus so the
+next keypress will run the selected command. The configuration can either be
+read from a file or from the standard input.
+
+# CONFIGURATION
+
+Each line is a command. It must have a key, and can optionally have a
+description. By default xlnch exits when you press a key bound to a command.
+You can prefix the key with an ampersand (&) which will keep *xlnch* open and
+in focus. Those commands will be shown in red. If you ommit the command
+description, *xlnch* will show the command instead.
+
+The configuration format is this:
+
+ \[&]<key>:[<description>]:<command>
+
+*key*
+ A single ascii character.
+
+*description*
+ Any ascii string.
+
+*command*
+ A valid command (see below).
+
+# EXAMPLE CONFIGURATION
+
+f::firefox++
+e:The best editor:emacs++
+&t:terminals:xterm
+
+In this example pressing _f_ will launch firefox and then exit, same for _e_
+and emacs. But if you press _t_ an xterm will spawn but the launcher will stay
+open, so pressing _t_ twice will launch two xterms consecutively. This makes
+more sense if used to control your window manager though it's cli interface or
+similar applications.
+
+# VALID COMMANDS
+
+Internally *xlnch* uses *wordexp*(3) to parse the command. So the same
+limitations apply. Some advanced stuff might be possible with clever quoting
+and calling _bash -c_ as the command but it is recommended to make a script for
+such things and just call it from *xlnch*.
+
+# TIPS
+
+Since *xlnch* can read from stdin you can have "excecutable" files with
+different configurations. Just add _#!/bin/xlnch_ on the first line (or the
+appropriate path), make the file executable and run it.
+
+You can call different xlnch configurations from within xlnch to create
+submenues. Don't use the & for such calls because the two xlnch windows will
+both want to constantly grab the focus. Either don't provide a way to go back
+to the previous menu, or simply assign _b_ to the parent menu so you have a way
+back.
+
+# AUTHOR
+
+Anastasis Grammenos \ No newline at end of file
diff --git a/xlnch.c b/xlnch.c
index a5ffd62..f39f606 100644
--- a/xlnch.c
+++ b/xlnch.c
@@ -302,11 +302,16 @@ int run()
return 0;
}
- XLookupString(&event.xkey, text, 255, &keysym, 0);
- flag = 0;
-
for (unsigned int i = 0; i < idx; i++) {
- if (lnch[i].key == text[0]) {
+ char tmp[128] = "";
+ // get configured key
+ tmp[0] = lnch[i].key;
+ tmp[1] = '\0';
+ // convert to keysym, and then to keycode Keycodes are consistent
+ // across layouts but may vary between different keyboard models.
+ // For example, the keycode for the "A" key might differ between
+ // a US QWERTY keyboard and a French AZERTY keyboard.
+ if (XKeysymToKeycode(display, XStringToKeysym(tmp)) == event.xkey.keycode) {
rc = run_cmd(lnch[i].cmd);
flag = 1;
if (lnch[i].exits) {
diff --git a/xlnchrc b/xlnchrc
index 5daf498..49165d1 100755
--- a/xlnchrc
+++ b/xlnchrc
@@ -6,7 +6,7 @@ t:tmux:urxvt-server-client -e tmux
m:mu4e:emacsclient -c --eval "(mu4e~headers-jump-to-maildir '/INBOX)"
i:inkscape:inkscape
k:keepassx:keepassx
-p:emelfm2:emelfm2
+p:emelfm2:emacs -Q --eval "(progn (setq dired-mouse-drag-files t) (dired ~/Downloads))"
P:pavucontrol:pavucontrol
o:popcorntime:popcorntime
d:discord:discord