@ -1,100 +0,0 @@ | |||
[![Tests](https://img.shields.io/travis/cdown/clipmenu/develop.svg)](https://travis-ci.org/cdown/clipmenu) | |||
clipmenu is a simple clipboard manager using [dmenu][] (or [rofi][] with | |||
`CM_LAUNCHER=rofi`) and [xsel][]. | |||
# Demo | |||
![Demo](https://cloud.githubusercontent.com/assets/660663/24079784/6f76da94-0c88-11e7-8251-40b1f02ebf3c.gif) | |||
# Usage | |||
## clipmenud | |||
Start `clipmenud`, then run `clipmenu` to select something to put on the | |||
clipboard. For systemd users, a user service called `clipmenud` is packaged as | |||
part of the project. | |||
For those using a systemd unit and not using a desktop environment which does | |||
it automatically, you must import `$DISPLAY` so that `clipmenud` knows which X | |||
server to use. For example, in your `~/.xinitrc` do this prior to launching | |||
clipmenud: | |||
systemctl --user import-environment DISPLAY | |||
## clipmenu | |||
You may wish to bind a shortcut in your window manager to launch `clipmenu`. | |||
All args passed to clipmenu are transparently dispatched to dmenu. That is, if | |||
you usually call dmenu with args to set colours and other properties, you can | |||
invoke clipmenu in exactly the same way to get the same effect, like so: | |||
clipmenu -i -fn Terminus:size=8 -nb '#002b36' -nf '#839496' -sb '#073642' -sf '#93a1a1' | |||
For a full list of environment variables that clipmenud can take, please see | |||
`clipmenud --help`. | |||
# Features | |||
The behavior of `clipmenud` can be customized through environment variables. | |||
Despite being only <300 lines, clipmenu has many useful features, including: | |||
* Customising the maximum number of clips stored (default 1000) | |||
* Disabling clip collection temporarily with `clipctl disable`, reenabling with | |||
`clipctl enable` | |||
* Not storing clipboard changes from certain applications, like password | |||
managers | |||
* Taking direct ownership of the clipboard | |||
* ...and much more. | |||
Check `clipmenud --help` to view all possible environment variables and what | |||
they do. If you manage `clipmenud` with `systemd`, you can override the | |||
defaults by using `systemctl --user edit clipmenud` to generate an override | |||
file. | |||
# Supported launchers | |||
Any dmenu-compliant application will work, but here are `CM_LAUNCHER` | |||
configurations that are known to work: | |||
- `dmenu` (the default) | |||
- `fzf` | |||
- `rofi` | |||
- `rofi-script`, for [rofi's script | |||
mode](https://github.com/davatorium/rofi-scripts/tree/master/mode-scripts) | |||
# Installation | |||
Several distributions, including Arch and Nix, provide clipmenu as an official | |||
package called `clipmenu`. | |||
## Manual installation | |||
If your distribution doesn't provide a package, you can manually install using | |||
`make install` (or better yet, create a package for your distribution!). You | |||
will need `xsel` and `clipnotify` installed, and also `dmenu` unless you plan | |||
to use a different launcher. | |||
# How does it work? | |||
clipmenud is less than 300 lines, and clipmenu is less than 100, so hopefully | |||
it should be fairly self-explanatory. However, at the most basic level: | |||
## clipmenud | |||
1. `clipmenud` uses [clipnotify](https://github.com/cdown/clipnotify) to wait | |||
for new clipboard events. | |||
2. If `clipmenud` detects changes to the clipboard contents, it writes them out | |||
to the cache directory and an index using a hash as the filename. | |||
## clipmenu | |||
1. `clipmenu` reads the index to find all available clips. | |||
2. `dmenu` is executed to allow the user to select a clip. | |||
3. After selection, the clip is put onto the PRIMARY and CLIPBOARD X | |||
selections. | |||
[dmenu]: http://tools.suckless.org/dmenu/ | |||
[rofi]: https://github.com/DaveDavenport/Rofi | |||
[xsel]: http://www.vergenet.net/~conrad/software/xsel/ |
@ -0,0 +1,30 @@ | |||
MIT/X Consortium License | |||
© 2006-2019 Anselm R Garbe <anselm@garbe.ca> | |||
© 2006-2008 Sander van Dijk <a.h.vandijk@gmail.com> | |||
© 2006-2007 Michał Janeczek <janeczek@gmail.com> | |||
© 2007 Kris Maglione <jg@suckless.org> | |||
© 2009 Gottox <gottox@s01.de> | |||
© 2009 Markus Schnalke <meillo@marmaro.de> | |||
© 2009 Evan Gates <evan.gates@gmail.com> | |||
© 2010-2012 Connor Lane Smith <cls@lubutu.com> | |||
© 2014-2020 Hiltjo Posthuma <hiltjo@codemadness.org> | |||
© 2015-2019 Quentin Rameau <quinq@fifth.space> | |||
Permission is hereby granted, free of charge, to any person obtaining a | |||
copy of this software and associated documentation files (the "Software"), | |||
to deal in the Software without restriction, including without limitation | |||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||
and/or sell copies of the Software, and to permit persons to whom the | |||
Software is furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
DEALINGS IN THE SOFTWARE. |
@ -0,0 +1,64 @@ | |||
# dmenu - dynamic menu | |||
# See LICENSE file for copyright and license details. | |||
include config.mk | |||
SRC = drw.c dmenu.c stest.c util.c | |||
OBJ = $(SRC:.c=.o) | |||
all: options dmenu stest | |||
options: | |||
@echo dmenu build options: | |||
@echo "CFLAGS = $(CFLAGS)" | |||
@echo "LDFLAGS = $(LDFLAGS)" | |||
@echo "CC = $(CC)" | |||
.c.o: | |||
$(CC) -c $(CFLAGS) $< | |||
config.h: | |||
cp config.def.h $@ | |||
$(OBJ): arg.h config.h config.mk drw.h | |||
dmenu: dmenu.o drw.o util.o | |||
$(CC) -o $@ dmenu.o drw.o util.o $(LDFLAGS) | |||
stest: stest.o | |||
$(CC) -o $@ stest.o $(LDFLAGS) | |||
clean: | |||
rm -f dmenu stest $(OBJ) dmenu-$(VERSION).tar.gz | |||
dist: clean | |||
mkdir -p dmenu-$(VERSION) | |||
cp LICENSE Makefile README arg.h config.def.h config.mk dmenu.1\ | |||
drw.h util.h dmenu_path dmenu_run stest.1 $(SRC)\ | |||
dmenu-$(VERSION) | |||
tar -cf dmenu-$(VERSION).tar dmenu-$(VERSION) | |||
gzip dmenu-$(VERSION).tar | |||
rm -rf dmenu-$(VERSION) | |||
install: all | |||
mkdir -p $(DESTDIR)$(PREFIX)/bin | |||
cp -f dmenu dmenu_path dmenu_run stest $(DESTDIR)$(PREFIX)/bin | |||
chmod 755 $(DESTDIR)$(PREFIX)/bin/dmenu | |||
chmod 755 $(DESTDIR)$(PREFIX)/bin/dmenu_path | |||
chmod 755 $(DESTDIR)$(PREFIX)/bin/dmenu_run | |||
chmod 755 $(DESTDIR)$(PREFIX)/bin/stest | |||
mkdir -p $(DESTDIR)$(MANPREFIX)/man1 | |||
sed "s/VERSION/$(VERSION)/g" < dmenu.1 > $(DESTDIR)$(MANPREFIX)/man1/dmenu.1 | |||
sed "s/VERSION/$(VERSION)/g" < stest.1 > $(DESTDIR)$(MANPREFIX)/man1/stest.1 | |||
chmod 644 $(DESTDIR)$(MANPREFIX)/man1/dmenu.1 | |||
chmod 644 $(DESTDIR)$(MANPREFIX)/man1/stest.1 | |||
uninstall: | |||
rm -f $(DESTDIR)$(PREFIX)/bin/dmenu\ | |||
$(DESTDIR)$(PREFIX)/bin/dmenu_path\ | |||
$(DESTDIR)$(PREFIX)/bin/dmenu_run\ | |||
$(DESTDIR)$(PREFIX)/bin/stest\ | |||
$(DESTDIR)$(MANPREFIX)/man1/dmenu.1\ | |||
$(DESTDIR)$(MANPREFIX)/man1/stest.1 | |||
.PHONY: all options clean dist install uninstall |
@ -0,0 +1,49 @@ | |||
/* | |||
* Copy me if you can. | |||
* by 20h | |||
*/ | |||
#ifndef ARG_H__ | |||
#define ARG_H__ | |||
extern char *argv0; | |||
/* use main(int argc, char *argv[]) */ | |||
#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\ | |||
argv[0] && argv[0][0] == '-'\ | |||
&& argv[0][1];\ | |||
argc--, argv++) {\ | |||
char argc_;\ | |||
char **argv_;\ | |||
int brk_;\ | |||
if (argv[0][1] == '-' && argv[0][2] == '\0') {\ | |||
argv++;\ | |||
argc--;\ | |||
break;\ | |||
}\ | |||
for (brk_ = 0, argv[0]++, argv_ = argv;\ | |||
argv[0][0] && !brk_;\ | |||
argv[0]++) {\ | |||
if (argv_ != argv)\ | |||
break;\ | |||
argc_ = argv[0][0];\ | |||
switch (argc_) | |||
#define ARGEND }\ | |||
} | |||
#define ARGC() argc_ | |||
#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\ | |||
((x), abort(), (char *)0) :\ | |||
(brk_ = 1, (argv[0][1] != '\0')?\ | |||
(&argv[0][1]) :\ | |||
(argc--, argv++, argv[0]))) | |||
#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\ | |||
(char *)0 :\ | |||
(brk_ = 1, (argv[0][1] != '\0')?\ | |||
(&argv[0][1]) :\ | |||
(argc--, argv++, argv[0]))) | |||
#endif |
@ -0,0 +1,11 @@ | |||
/* This file is used for color settings */ | |||
static const char *colors[SchemeLast][2] = { | |||
/* fg bg */ | |||
[SchemeNorm] = { "#e5e9f0", "#0f111a" }, | |||
[SchemeSel] = { "#0f111a", "#bf616a" }, | |||
[SchemeOut] = { "#000000", "#00ffff" }, | |||
[SchemeNormHighlight] = { "#88c0d0", "#0f111a" }, | |||
[SchemeSelHighlight] = { "#88c0d0", "#bf616a" }, | |||
// [SchemeHp] = { "#e5e9f0", "#4c566a" }, | |||
}; |
@ -0,0 +1,26 @@ | |||
/* See LICENSE file for copyright and license details. */ | |||
/* Default settings; can be overriden by command line. */ | |||
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */ | |||
/* -fn option overrides fonts[0]; default X11 font or font set */ | |||
static const char *fonts[] = { | |||
"CaskaydiaCove Nerd Font Mono:size=10" | |||
}; | |||
static const char *prompt = NULL; /* -p option; prompt to the left of input field */ | |||
static const unsigned int min_lineheight = 27; | |||
static unsigned int lineheight = 27; | |||
static unsigned int fuzzy = 0; | |||
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */ | |||
static unsigned int lines = 0; | |||
static int dmx = 10; /* put dmenu at this x offset */ | |||
static int dmy = 10; /* put dmenu at this y offset (measured from the bottom if topbar is 0) */ | |||
static unsigned int dmw = 1900; /* make dmenu this wide */ | |||
static char **hpitems = {"firefox-developer-edition", "st"}; | |||
/* | |||
* Characters not considered part of a word while deleting words | |||
* for example: " /?\"&[]" | |||
*/ | |||
static const char worddelimiters[] = " "; |
@ -0,0 +1,31 @@ | |||
# dmenu version | |||
VERSION = 5.0 | |||
# paths | |||
PREFIX = /usr/local | |||
MANPREFIX = $(PREFIX)/share/man | |||
X11INC = /usr/X11R6/include | |||
X11LIB = /usr/X11R6/lib | |||
# Xinerama, comment if you don't want it | |||
XINERAMALIBS = -lXinerama | |||
XINERAMAFLAGS = -DXINERAMA | |||
# freetype | |||
FREETYPELIBS = -lfontconfig -lXft | |||
FREETYPEINC = /usr/include/freetype2 | |||
# OpenBSD (uncomment) | |||
#FREETYPEINC = $(X11INC)/freetype2 | |||
# includes and libs | |||
INCS = -I$(X11INC) -I$(FREETYPEINC) | |||
LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS) -lm | |||
# flags | |||
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS) | |||
CFLAGS = -std=c99 -pedantic -Wall -Os $(INCS) $(CPPFLAGS) | |||
LDFLAGS = $(LIBS) | |||
# compiler and linker | |||
CC = cc |
@ -0,0 +1,152 @@ | |||
Author: Chris Noxz <chris@noxz.tech> | |||
note: This patch is meant to be used together with fuzzymatch | |||
diff -upN dmenu-4.9/config.def.h dmenu-4.9-fuzzyhighlight/config.def.h | |||
--- dmenu-4.9/config.def.h 2019-02-02 13:55:02.000000000 +0100 | |||
+++ dmenu-4.9-fuzzyhighlight/config.def.h 2020-04-04 10:26:36.990890854 +0200 | |||
@@ -11,6 +11,8 @@ static const char *colors[SchemeLast][2] | |||
/* fg bg */ | |||
[SchemeNorm] = { "#bbbbbb", "#222222" }, | |||
[SchemeSel] = { "#eeeeee", "#005577" }, | |||
+ [SchemeSelHighlight] = { "#ffc978", "#005577" }, | |||
+ [SchemeNormHighlight] = { "#ffc978", "#222222" }, | |||
[SchemeOut] = { "#000000", "#00ffff" }, | |||
}; | |||
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */ | |||
diff -upN dmenu-4.9/dmenu.1 dmenu-4.9-fuzzyhighlight/dmenu.1 | |||
--- dmenu-4.9/dmenu.1 2019-02-02 13:55:02.000000000 +0100 | |||
+++ dmenu-4.9-fuzzyhighlight/dmenu.1 2020-04-04 10:30:16.430054933 +0200 | |||
@@ -20,6 +20,14 @@ dmenu \- dynamic menu | |||
.IR color ] | |||
.RB [ \-sf | |||
.IR color ] | |||
+.RB [ \-nhb | |||
+.IR color ] | |||
+.RB [ \-nhf | |||
+.IR color ] | |||
+.RB [ \-shb | |||
+.IR color ] | |||
+.RB [ \-shf | |||
+.IR color ] | |||
.RB [ \-w | |||
.IR windowid ] | |||
.P | |||
@@ -75,6 +83,18 @@ defines the selected background color. | |||
.BI \-sf " color" | |||
defines the selected foreground color. | |||
.TP | |||
+.BI \-nhb " color" | |||
+defines the normal highlight background color. | |||
+.TP | |||
+.BI \-nhf " color" | |||
+defines the normal highlight foreground color. | |||
+.TP | |||
+.BI \-shb " color" | |||
+defines the selected highlight background color. | |||
+.TP | |||
+.BI \-shf " color" | |||
+defines the selected highlight foreground color. | |||
+.TP | |||
.B \-v | |||
prints version information to stdout, then exits. | |||
.TP | |||
diff -upN dmenu-4.9/dmenu.c dmenu-4.9-fuzzyhighlight/dmenu.c | |||
--- dmenu-4.9/dmenu.c 2019-02-02 13:55:02.000000000 +0100 | |||
+++ dmenu-4.9-fuzzyhighlight/dmenu.c 2020-04-04 10:27:43.888026309 +0200 | |||
@@ -26,7 +26,9 @@ | |||
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) | |||
/* enums */ | |||
-enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */ | |||
+enum { SchemeNorm, SchemeSel, SchemeNormHighlight, SchemeSelHighlight, | |||
+ SchemeOut, SchemeLast }; /* color schemes */ | |||
+ | |||
struct item { | |||
char *text; | |||
@@ -113,9 +115,49 @@ cistrstr(const char *s, const char *sub) | |||
return NULL; | |||
} | |||
+static void | |||
+drawhighlights(struct item *item, int x, int y, int maxw) | |||
+{ | |||
+ int i, indent; | |||
+ char *highlight; | |||
+ char c; | |||
+ | |||
+ if (!(strlen(item->text) && strlen(text))) | |||
+ return; | |||
+ | |||
+ drw_setscheme(drw, scheme[item == sel | |||
+ ? SchemeSelHighlight | |||
+ : SchemeNormHighlight]); | |||
+ for (i = 0, highlight = item->text; *highlight && text[i];) { | |||
+ if (*highlight == text[i]) { | |||
+ /* get indentation */ | |||
+ c = *highlight; | |||
+ *highlight = '\0'; | |||
+ indent = TEXTW(item->text); | |||
+ *highlight = c; | |||
+ | |||
+ /* highlight character */ | |||
+ c = highlight[1]; | |||
+ highlight[1] = '\0'; | |||
+ drw_text( | |||
+ drw, | |||
+ x + indent - (lrpad / 2), | |||
+ y, | |||
+ MIN(maxw - indent, TEXTW(highlight) - lrpad), | |||
+ bh, 0, highlight, 0 | |||
+ ); | |||
+ highlight[1] = c; | |||
+ i++; | |||
+ } | |||
+ highlight++; | |||
+ } | |||
+} | |||
+ | |||
+ | |||
static int | |||
drawitem(struct item *item, int x, int y, int w) | |||
{ | |||
+ int r; | |||
if (item == sel) | |||
drw_setscheme(drw, scheme[SchemeSel]); | |||
else if (item->out) | |||
@@ -123,7 +165,9 @@ drawitem(struct item *item, int x, int y | |||
else | |||
drw_setscheme(drw, scheme[SchemeNorm]); | |||
- return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0); | |||
+ r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0); | |||
+ drawhighlights(item, x, y, w); | |||
+ return r; | |||
} | |||
static void | |||
@@ -683,7 +727,8 @@ static void | |||
usage(void) | |||
{ | |||
fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" | |||
- " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr); | |||
+ " [-nb color] [-nf color] [-sb color] [-sf color]\n" | |||
+ " [-nhb color] [-nhf color] [-shb color] [-shf color] [-w windowid]\n", stderr); | |||
exit(1); | |||
} | |||
@@ -724,6 +769,14 @@ main(int argc, char *argv[]) | |||
colors[SchemeSel][ColBg] = argv[++i]; | |||
else if (!strcmp(argv[i], "-sf")) /* selected foreground color */ | |||
colors[SchemeSel][ColFg] = argv[++i]; | |||
+ else if (!strcmp(argv[i], "-nhb")) /* normal hi background color */ | |||
+ colors[SchemeNormHighlight][ColBg] = argv[++i]; | |||
+ else if (!strcmp(argv[i], "-nhf")) /* normal hi foreground color */ | |||
+ colors[SchemeNormHighlight][ColFg] = argv[++i]; | |||
+ else if (!strcmp(argv[i], "-shb")) /* selected hi background color */ | |||
+ colors[SchemeSelHighlight][ColBg] = argv[++i]; | |||
+ else if (!strcmp(argv[i], "-shf")) /* selected hi foreground color */ | |||
+ colors[SchemeSelHighlight][ColFg] = argv[++i]; | |||
else if (!strcmp(argv[i], "-w")) /* embedding window id */ | |||
embed = argv[++i]; | |||
else |
@ -0,0 +1,163 @@ | |||
From 94353eb52055927d9079f3d9e33da1c954abf386 Mon Sep 17 00:00:00 2001 | |||
From: aleks <aleks.stier@icloud.com> | |||
Date: Wed, 26 Jun 2019 13:25:10 +0200 | |||
Subject: [PATCH] Add support for fuzzy-matching | |||
--- | |||
config.def.h | 1 + | |||
config.mk | 2 +- | |||
dmenu.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++ | |||
3 files changed, 91 insertions(+), 1 deletion(-) | |||
diff --git a/config.def.h b/config.def.h | |||
index 1edb647..51612b9 100644 | |||
--- a/config.def.h | |||
+++ b/config.def.h | |||
@@ -2,6 +2,7 @@ | |||
/* Default settings; can be overriden by command line. */ | |||
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */ | |||
+static int fuzzy = 1; /* -F option; if 0, dmenu doesn't use fuzzy matching */ | |||
/* -fn option overrides fonts[0]; default X11 font or font set */ | |||
static const char *fonts[] = { | |||
"monospace:size=10" | |||
diff --git a/config.mk b/config.mk | |||
index 0929b4a..d14309a 100644 | |||
--- a/config.mk | |||
+++ b/config.mk | |||
@@ -20,7 +20,7 @@ FREETYPEINC = /usr/include/freetype2 | |||
# includes and libs | |||
INCS = -I$(X11INC) -I$(FREETYPEINC) | |||
-LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS) | |||
+LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS) -lm | |||
# flags | |||
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS) | |||
diff --git a/dmenu.c b/dmenu.c | |||
index 6b8f51b..96ddc98 100644 | |||
--- a/dmenu.c | |||
+++ b/dmenu.c | |||
@@ -1,6 +1,7 @@ | |||
/* See LICENSE file for copyright and license details. */ | |||
#include <ctype.h> | |||
#include <locale.h> | |||
+#include <math.h> | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include <string.h> | |||
@@ -32,6 +33,7 @@ struct item { | |||
char *text; | |||
struct item *left, *right; | |||
int out; | |||
+ double distance; | |||
}; | |||
static char text[BUFSIZ] = ""; | |||
@@ -210,9 +212,94 @@ grabkeyboard(void) | |||
die("cannot grab keyboard"); | |||
} | |||
+int | |||
+compare_distance(const void *a, const void *b) | |||
+{ | |||
+ struct item *da = *(struct item **) a; | |||
+ struct item *db = *(struct item **) b; | |||
+ | |||
+ if (!db) | |||
+ return 1; | |||
+ if (!da) | |||
+ return -1; | |||
+ | |||
+ return da->distance == db->distance ? 0 : da->distance < db->distance ? -1 : 1; | |||
+} | |||
+ | |||
+void | |||
+fuzzymatch(void) | |||
+{ | |||
+ /* bang - we have so much memory */ | |||
+ struct item *it; | |||
+ struct item **fuzzymatches = NULL; | |||
+ char c; | |||
+ int number_of_matches = 0, i, pidx, sidx, eidx; | |||
+ int text_len = strlen(text), itext_len; | |||
+ | |||
+ matches = matchend = NULL; | |||
+ | |||
+ /* walk through all items */ | |||
+ for (it = items; it && it->text; it++) { | |||
+ if (text_len) { | |||
+ itext_len = strlen(it->text); | |||
+ pidx = 0; /* pointer */ | |||
+ sidx = eidx = -1; /* start of match, end of match */ | |||
+ /* walk through item text */ | |||
+ for (i = 0; i < itext_len && (c = it->text[i]); i++) { | |||
+ /* fuzzy match pattern */ | |||
+ if (!fstrncmp(&text[pidx], &c, 1)) { | |||
+ if(sidx == -1) | |||
+ sidx = i; | |||
+ pidx++; | |||
+ if (pidx == text_len) { | |||
+ eidx = i; | |||
+ break; | |||
+ } | |||
+ } | |||
+ } | |||
+ /* build list of matches */ | |||
+ if (eidx != -1) { | |||
+ /* compute distance */ | |||
+ /* add penalty if match starts late (log(sidx+2)) | |||
+ * add penalty for long a match without many matching characters */ | |||
+ it->distance = log(sidx + 2) + (double)(eidx - sidx - text_len); | |||
+ /* fprintf(stderr, "distance %s %f\n", it->text, it->distance); */ | |||
+ appenditem(it, &matches, &matchend); | |||
+ number_of_matches++; | |||
+ } | |||
+ } else { | |||
+ appenditem(it, &matches, &matchend); | |||
+ } | |||
+ } | |||
+ | |||
+ if (number_of_matches) { | |||
+ /* initialize array with matches */ | |||
+ if (!(fuzzymatches = realloc(fuzzymatches, number_of_matches * sizeof(struct item*)))) | |||
+ die("cannot realloc %u bytes:", number_of_matches * sizeof(struct item*)); | |||
+ for (i = 0, it = matches; it && i < number_of_matches; i++, it = it->right) { | |||
+ fuzzymatches[i] = it; | |||
+ } | |||
+ /* sort matches according to distance */ | |||
+ qsort(fuzzymatches, number_of_matches, sizeof(struct item*), compare_distance); | |||
+ /* rebuild list of matches */ | |||
+ matches = matchend = NULL; | |||
+ for (i = 0, it = fuzzymatches[i]; i < number_of_matches && it && \ | |||
+ it->text; i++, it = fuzzymatches[i]) { | |||
+ appenditem(it, &matches, &matchend); | |||
+ } | |||
+ free(fuzzymatches); | |||
+ } | |||
+ curr = sel = matches; | |||
+ calcoffsets(); | |||
+} | |||
+ | |||
static void | |||
match(void) | |||
{ | |||
+ if (fuzzy) { | |||
+ fuzzymatch(); | |||
+ return; | |||
+ } | |||
static char **tokv = NULL; | |||
static int tokn = 0; | |||
@@ -702,6 +789,8 @@ main(int argc, char *argv[]) | |||
topbar = 0; | |||
else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */ | |||
fast = 1; | |||
+ else if (!strcmp(argv[i], "-F")) /* grabs keyboard before reading stdin */ | |||
+ fuzzy = 0; | |||
else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ | |||
fstrncmp = strncasecmp; | |||
fstrstr = cistrstr; | |||
-- | |||
2.22.0 | |||
@ -0,0 +1,163 @@ | |||
From 94353eb52055927d9079f3d9e33da1c954abf386 Mon Sep 17 00:00:00 2001 | |||
From: aleks <aleks.stier@icloud.com> | |||
Date: Wed, 26 Jun 2019 13:25:10 +0200 | |||
Subject: [PATCH] Add support for fuzzy-matching | |||
--- | |||
config.def.h | 1 + | |||
config.mk | 2 +- | |||
dmenu.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++ | |||
3 files changed, 91 insertions(+), 1 deletion(-) | |||
diff --git a/config.def.h b/config.def.h | |||
index 1edb647..51612b9 100644 | |||
--- a/config.def.h | |||
+++ b/config.def.h | |||
@@ -2,6 +2,7 @@ | |||
/* Default settings; can be overriden by command line. */ | |||
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */ | |||
+static int fuzzy = 1; /* -F option; if 0, dmenu doesn't use fuzzy matching */ | |||
/* -fn option overrides fonts[0]; default X11 font or font set */ | |||
static const char *fonts[] = { | |||
"monospace:size=10" | |||
diff --git a/config.mk b/config.mk | |||
index 0929b4a..d14309a 100644 | |||
--- a/config.mk | |||
+++ b/config.mk | |||
@@ -20,7 +20,7 @@ FREETYPEINC = /usr/include/freetype2 | |||
# includes and libs | |||
INCS = -I$(X11INC) -I$(FREETYPEINC) | |||
-LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS) | |||
+LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS) -lm | |||
# flags | |||
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS) | |||
diff --git a/dmenu.c b/dmenu.c | |||
index 6b8f51b..96ddc98 100644 | |||
--- a/dmenu.c | |||
+++ b/dmenu.c | |||
@@ -1,6 +1,7 @@ | |||
/* See LICENSE file for copyright and license details. */ | |||
#include <ctype.h> | |||
#include <locale.h> | |||
+#include <math.h> | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include <string.h> | |||
@@ -32,6 +33,7 @@ struct item { | |||
char *text; | |||
struct item *left, *right; | |||
int out; | |||
+ double distance; | |||
}; | |||
static char text[BUFSIZ] = ""; | |||
@@ -210,9 +212,94 @@ grabkeyboard(void) | |||
die("cannot grab keyboard"); | |||
} | |||
+int | |||
+compare_distance(const void *a, const void *b) | |||
+{ | |||
+ struct item *da = *(struct item **) a; | |||
+ struct item *db = *(struct item **) b; | |||
+ | |||
+ if (!db) | |||
+ return 1; | |||
+ if (!da) | |||
+ return -1; | |||
+ | |||
+ return da->distance == db->distance ? 0 : da->distance < db->distance ? -1 : 1; | |||
+} | |||
+ | |||
+void | |||
+fuzzymatch(void) | |||
+{ | |||
+ /* bang - we have so much memory */ | |||
+ struct item *it; | |||
+ struct item **fuzzymatches = NULL; | |||
+ char c; | |||
+ int number_of_matches = 0, i, pidx, sidx, eidx; | |||
+ int text_len = strlen(text), itext_len; | |||
+ | |||
+ matches = matchend = NULL; | |||
+ | |||
+ /* walk through all items */ | |||
+ for (it = items; it && it->text; it++) { | |||
+ if (text_len) { | |||
+ itext_len = strlen(it->text); | |||
+ pidx = 0; /* pointer */ | |||
+ sidx = eidx = -1; /* start of match, end of match */ | |||
+ /* walk through item text */ | |||
+ for (i = 0; i < itext_len && (c = it->text[i]); i++) { | |||
+ /* fuzzy match pattern */ | |||
+ if (!fstrncmp(&text[pidx], &c, 1)) { | |||
+ if(sidx == -1) | |||
+ sidx = i; | |||
+ pidx++; | |||
+ if (pidx == text_len) { | |||
+ eidx = i; | |||
+ break; | |||
+ } | |||
+ } | |||
+ } | |||
+ /* build list of matches */ | |||
+ if (eidx != -1) { | |||
+ /* compute distance */ | |||
+ /* add penalty if match starts late (log(sidx+2)) | |||
+ * add penalty for long a match without many matching characters */ | |||
+ it->distance = log(sidx + 2) + (double)(eidx - sidx - text_len); | |||
+ /* fprintf(stderr, "distance %s %f\n", it->text, it->distance); */ | |||
+ appenditem(it, &matches, &matchend); | |||
+ number_of_matches++; | |||
+ } | |||
+ } else { | |||
+ appenditem(it, &matches, &matchend); | |||
+ } | |||
+ } | |||
+ | |||
+ if (number_of_matches) { | |||
+ /* initialize array with matches */ | |||
+ if (!(fuzzymatches = realloc(fuzzymatches, number_of_matches * sizeof(struct item*)))) | |||
+ die("cannot realloc %u bytes:", number_of_matches * sizeof(struct item*)); | |||
+ for (i = 0, it = matches; it && i < number_of_matches; i++, it = it->right) { | |||
+ fuzzymatches[i] = it; | |||
+ } | |||
+ /* sort matches according to distance */ | |||
+ qsort(fuzzymatches, number_of_matches, sizeof(struct item*), compare_distance); | |||
+ /* rebuild list of matches */ | |||
+ matches = matchend = NULL; | |||
+ for (i = 0, it = fuzzymatches[i]; i < number_of_matches && it && \ | |||
+ it->text; i++, it = fuzzymatches[i]) { | |||
+ appenditem(it, &matches, &matchend); | |||
+ } | |||
+ free(fuzzymatches); | |||
+ } | |||
+ curr = sel = matches; | |||
+ calcoffsets(); | |||
+} | |||
+ | |||
static void | |||
match(void) | |||
{ | |||
+ if (fuzzy) { | |||
+ fuzzymatch(); | |||
+ return; | |||
+ } | |||
static char **tokv = NULL; | |||
static int tokn = 0; | |||
@@ -702,6 +789,8 @@ main(int argc, char *argv[]) | |||
topbar = 0; | |||
else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */ | |||
fast = 1; | |||
+ else if (!strcmp(argv[i], "-F")) /* grabs keyboard before reading stdin */ | |||
+ fuzzy = 0; | |||
else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ | |||
fstrncmp = strncasecmp; | |||
fstrstr = cistrstr; | |||
-- | |||
2.22.0 | |||
@ -0,0 +1,178 @@ | |||
From e9e1691a9b4ffa2db45cd5108b76b9a68610ba37 Mon Sep 17 00:00:00 2001 | |||
From: takase1121 <takase1121@outlook.com> | |||
Date: Sun, 17 May 2020 07:05:32 +0800 | |||
Subject: [PATCH] Adds high-priority items. | |||
This allows users to specify a list of high priority commands that should be | |||
displayed before other matches with the following arrangement: | |||
match -> prefix && high priority -> prefix -> substring | |||
As you can see, high priority for substring matches is not implemented or will not | |||
be implemented depending on needs. | |||
--- | |||
config.def.h | 1 + | |||
dmenu.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++----- | |||
2 files changed, 59 insertions(+), 6 deletions(-) | |||
diff --git a/config.def.h b/config.def.h | |||
index 1edb647..65e03fb 100644 | |||
--- a/config.def.h | |||
+++ b/config.def.h | |||
@@ -12,6 +12,7 @@ static const char *colors[SchemeLast][2] = { | |||
[SchemeNorm] = { "#bbbbbb", "#222222" }, | |||
[SchemeSel] = { "#eeeeee", "#005577" }, | |||
[SchemeOut] = { "#000000", "#00ffff" }, | |||
+ [SchemeHp] = { "#bbbbbb", "#333333" } | |||
}; | |||
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */ | |||
static unsigned int lines = 0; | |||
diff --git a/dmenu.c b/dmenu.c | |||
index 6b8f51b..7bf4099 100644 | |||
--- a/dmenu.c | |||
+++ b/dmenu.c | |||
@@ -26,14 +26,16 @@ | |||
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) | |||
/* enums */ | |||
-enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */ | |||
+enum { SchemeNorm, SchemeSel, SchemeHp, SchemeOut, SchemeLast }; /* color schemes */ | |||
struct item { | |||
char *text; | |||
struct item *left, *right; | |||
- int out; | |||
+ int out, hp; | |||
}; | |||
+static char **hpitems = NULL; | |||
+static int hplength = 0; | |||
static char text[BUFSIZ] = ""; | |||
static char *embed; | |||
static int bh, mw, mh; | |||
@@ -58,6 +60,36 @@ static Clr *scheme[SchemeLast]; | |||
static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; | |||
static char *(*fstrstr)(const char *, const char *) = strstr; | |||
+static char** | |||
+tokenize(char *source, const char *delim, int *llen) { | |||
+ int listlength = 0; | |||
+ char **list = malloc(1 * sizeof(char*)); | |||
+ char *token = strtok(source, delim); | |||
+ | |||
+ while (token) { | |||
+ if (!(list = realloc(list, sizeof(char*) * (listlength + 1)))) | |||
+ die("Unable to realloc %d bytes\n", sizeof(char*) * (listlength + 1)); | |||
+ if (!(list[listlength] = strdup(token))) | |||
+ die("Unable to strdup %d bytes\n", strlen(token) + 1); | |||
+ token = strtok(NULL, delim); | |||
+ listlength++; | |||
+ } | |||
+ | |||
+ *llen = listlength; | |||
+ return list; | |||
+} | |||
+ | |||
+static int | |||
+arrayhas(char **list, int length, char *item) { | |||
+ for (int i = 0; i < length; i++) { | |||
+ int len1 = strlen(list[i]); | |||
+ int len2 = strlen(item); | |||
+ if (fstrncmp(list[i], item, len1 > len2 ? len2 : len1) == 0) | |||
+ return 1; | |||
+ } | |||
+ return 0; | |||
+} | |||
+ | |||
static void | |||
appenditem(struct item *item, struct item **list, struct item **last) | |||
{ | |||
@@ -118,6 +150,8 @@ drawitem(struct item *item, int x, int y, int w) | |||
{ | |||
if (item == sel) | |||
drw_setscheme(drw, scheme[SchemeSel]); | |||
+ else if (item->hp) | |||
+ drw_setscheme(drw, scheme[SchemeHp]); | |||
else if (item->out) | |||
drw_setscheme(drw, scheme[SchemeOut]); | |||
else | |||
@@ -219,7 +253,7 @@ match(void) | |||
char buf[sizeof text], *s; | |||
int i, tokc = 0; | |||
size_t len, textsize; | |||
- struct item *item, *lprefix, *lsubstr, *prefixend, *substrend; | |||
+ struct item *item, *lhpprefix, *lprefix, *lsubstr, *hpprefixend, *prefixend, *substrend; | |||
strcpy(buf, text); | |||
/* separate input text into tokens to be matched individually */ | |||
@@ -228,7 +262,7 @@ match(void) | |||
die("cannot realloc %u bytes:", tokn * sizeof *tokv); | |||
len = tokc ? strlen(tokv[0]) : 0; | |||
- matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL; | |||
+ matches = lhpprefix = lprefix = lsubstr = matchend = hpprefixend = prefixend = substrend = NULL; | |||
textsize = strlen(text) + 1; | |||
for (item = items; item && item->text; item++) { | |||
for (i = 0; i < tokc; i++) | |||
@@ -236,14 +270,24 @@ match(void) | |||
break; | |||
if (i != tokc) /* not all tokens match */ | |||
continue; | |||
- /* exact matches go first, then prefixes, then substrings */ | |||
+ /* exact matches go first, then prefixes with high priority, then prefixes, then substrings */ | |||
if (!tokc || !fstrncmp(text, item->text, textsize)) | |||
appenditem(item, &matches, &matchend); | |||
+ else if (item->hp && !fstrncmp(tokv[0], item->text, len)) | |||
+ appenditem(item, &lhpprefix, &hpprefixend); | |||
else if (!fstrncmp(tokv[0], item->text, len)) | |||
appenditem(item, &lprefix, &prefixend); | |||
else | |||
appenditem(item, &lsubstr, &substrend); | |||
} | |||
+ if (lhpprefix) { | |||
+ if (matches) { | |||
+ matchend->right = lhpprefix; | |||
+ lhpprefix->left = matchend; | |||
+ } else | |||
+ matches = lhpprefix; | |||
+ matchend = hpprefixend; | |||
+ } | |||
if (lprefix) { | |||
if (matches) { | |||
matchend->right = lprefix; | |||
@@ -535,6 +579,7 @@ readstdin(void) | |||
if (!(items[i].text = strdup(buf))) | |||
die("cannot strdup %u bytes:", strlen(buf) + 1); | |||
items[i].out = 0; | |||
+ items[i].hp = arrayhas(hpitems, hplength, items[i].text); | |||
drw_font_getexts(drw->fonts, buf, strlen(buf), &tmpmax, NULL); | |||
if (tmpmax > inputw) { | |||
inputw = tmpmax; | |||
@@ -683,7 +728,8 @@ static void | |||
usage(void) | |||
{ | |||
fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" | |||
- " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr); | |||
+ " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n" | |||
+ " [-hb color] [-hf color] [-hp items]\n", stderr); | |||
exit(1); | |||
} | |||
@@ -724,8 +770,14 @@ main(int argc, char *argv[]) | |||
colors[SchemeSel][ColBg] = argv[++i]; | |||
else if (!strcmp(argv[i], "-sf")) /* selected foreground color */ | |||
colors[SchemeSel][ColFg] = argv[++i]; | |||
+ else if (!strcmp(argv[i], "-hb")) /* high priority background color */ | |||
+ colors[SchemeHp][ColBg] = argv[++i]; | |||
+ else if (!strcmp(argv[i], "-hf")) /* low priority background color */ | |||
+ colors[SchemeHp][ColFg] = argv[++i]; | |||
else if (!strcmp(argv[i], "-w")) /* embedding window id */ | |||
embed = argv[++i]; | |||
+ else if (!strcmp(argv[i], "-hp")) | |||
+ hpitems = tokenize(argv[++i], ",", &hplength); | |||
else | |||
usage(); | |||
-- | |||
2.26.2 | |||
@ -0,0 +1,106 @@ | |||
From ba103e38ea4ab07f9a3ee90627714b9bea17c329 Mon Sep 17 00:00:00 2001 | |||
From: pskry <peter@skrypalle.dk> | |||
Date: Sun, 8 Nov 2020 22:04:22 +0100 | |||
Subject: [PATCH] Add an option which defines the lineheight | |||
Despite both the panel and dmenu using the same font (a Terminus 12), | |||
dmenu is shorter and the panel is visible from under the dmenu bar. | |||
The appearance can be even more distracting when using similar colors | |||
for background and selections. With the option added by this patch, | |||
dmenu can be launched with a '-h 24', thus completely covering the panel. | |||
--- | |||
config.def.h | 3 +++ | |||
dmenu.1 | 5 +++++ | |||
dmenu.c | 11 ++++++++--- | |||
3 files changed, 16 insertions(+), 3 deletions(-) | |||
diff --git a/config.def.h b/config.def.h | |||
index 1edb647..4394dec 100644 | |||
--- a/config.def.h | |||
+++ b/config.def.h | |||
@@ -15,6 +15,9 @@ static const char *colors[SchemeLast][2] = { | |||
}; | |||
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */ | |||
static unsigned int lines = 0; | |||
+/* -h option; minimum height of a menu line */ | |||
+static unsigned int lineheight = 0; | |||
+static unsigned int min_lineheight = 8; | |||
/* | |||
* Characters not considered part of a word while deleting words | |||
diff --git a/dmenu.1 b/dmenu.1 | |||
index 323f93c..f2a82b4 100644 | |||
--- a/dmenu.1 | |||
+++ b/dmenu.1 | |||
@@ -6,6 +6,8 @@ dmenu \- dynamic menu | |||
.RB [ \-bfiv ] | |||
.RB [ \-l | |||
.IR lines ] | |||
+.RB [ \-h | |||
+.IR height ] | |||
.RB [ \-m | |||
.IR monitor ] | |||
.RB [ \-p | |||
@@ -50,6 +52,9 @@ dmenu matches menu items case insensitively. | |||
.BI \-l " lines" | |||
dmenu lists items vertically, with the given number of lines. | |||
.TP | |||
+.BI \-h " height" | |||
+dmenu uses a menu line of at least 'height' pixels tall, but no less than 8. | |||
+.TP | |||
.BI \-m " monitor" | |||
dmenu is displayed on the monitor number supplied. Monitor numbers are starting | |||
from 0. | |||
diff --git a/dmenu.c b/dmenu.c | |||
index 65f25ce..f2a4047 100644 | |||
--- a/dmenu.c | |||
+++ b/dmenu.c | |||
@@ -131,7 +131,7 @@ drawmenu(void) | |||
{ | |||
unsigned int curpos; | |||
struct item *item; | |||
- int x = 0, y = 0, w; | |||
+ int x = 0, y = 0, fh = drw->fonts->h, w; | |||
drw_setscheme(drw, scheme[SchemeNorm]); | |||
drw_rect(drw, 0, 0, mw, mh, 1, 1); | |||
@@ -148,7 +148,7 @@ drawmenu(void) | |||
curpos = TEXTW(text) - TEXTW(&text[cursor]); | |||
if ((curpos += lrpad / 2 - 1) < w) { | |||
drw_setscheme(drw, scheme[SchemeNorm]); | |||
- drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0); | |||
+ drw_rect(drw, x + curpos, 2 + (bh - fh) / 2, 2, fh - 4, 1, 0); | |||
} | |||
if (lines > 0) { | |||
@@ -609,6 +609,7 @@ setup(void) | |||
/* calculate menu geometry */ | |||
bh = drw->fonts->h + 2; | |||
+ bh = MAX(bh,lineheight); /* make a menu line AT LEAST 'lineheight' tall */ | |||
lines = MAX(lines, 0); | |||
mh = (lines + 1) * bh; | |||
#ifdef XINERAMA | |||
@@ -689,7 +690,7 @@ setup(void) | |||
static void | |||
usage(void) | |||
{ | |||
- fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" | |||
+ fputs("usage: dmenu [-bfiv] [-l lines] [-h height] [-p prompt] [-fn font] [-m monitor]\n" | |||
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr); | |||
exit(1); | |||
} | |||
@@ -717,6 +718,10 @@ main(int argc, char *argv[]) | |||
/* these options take one argument */ | |||
else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */ | |||
lines = atoi(argv[++i]); | |||
+ else if (!strcmp(argv[i], "-h")) { /* minimum height of one menu line */ | |||
+ lineheight = atoi(argv[++i]); | |||
+ lineheight = MAX(lineheight, min_lineheight); | |||
+ } | |||
else if (!strcmp(argv[i], "-m")) | |||
mon = atoi(argv[++i]); | |||
else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */ | |||
-- | |||
2.29.2 | |||
@ -0,0 +1,116 @@ | |||
From 7dc7cb96cdda9ad66e33109223c4cc297a7721d1 Mon Sep 17 00:00:00 2001 | |||
From: Alex Cole <ajzcole@airmail.cc> | |||
Date: Tue, 6 Oct 2020 10:42:07 +1300 | |||
Subject: [PATCH] Updated xyw for 5.0 properly | |||
--- | |||
dmenu.1 | 24 ++++++++++++++++++++++++ | |||
dmenu.c | 22 ++++++++++++++++------ | |||
2 files changed, 40 insertions(+), 6 deletions(-) | |||
diff --git a/dmenu.1 b/dmenu.1 | |||
index 323f93c..a4ecbbb 100644 | |||
--- a/dmenu.1 | |||
+++ b/dmenu.1 | |||
@@ -8,6 +8,12 @@ dmenu \- dynamic menu | |||
.IR lines ] | |||
.RB [ \-m | |||
.IR monitor ] | |||
+.RB [ \-x | |||
+.IR xoffset ] | |||
+.RB [ \-y | |||
+.IR yoffset ] | |||
+.RB [ \-z | |||
+.IR width ] | |||
.RB [ \-p | |||
.IR prompt ] | |||
.RB [ \-fn | |||
@@ -54,6 +60,24 @@ dmenu lists items vertically, with the given number of lines. | |||
dmenu is displayed on the monitor number supplied. Monitor numbers are starting | |||
from 0. | |||
.TP | |||
+.BI \-x " xoffset" | |||
+dmenu is placed at this offset measured from the left side of the monitor. | |||
+Can be negative. | |||
+If option | |||
+.B \-m | |||
+is present, the measurement will use the given monitor. | |||
+.TP | |||
+.BI \-y " yoffset" | |||
+dmenu is placed at this offset measured from the top of the monitor. If the | |||
+.B \-b | |||
+option is used, the offset is measured from the bottom. Can be negative. | |||
+If option | |||
+.B \-m | |||
+is present, the measurement will use the given monitor. | |||
+.TP | |||
+.BI \-z " width" | |||
+sets the width of the dmenu window. | |||
+.TP | |||
.BI \-p " prompt" | |||
defines the prompt to be displayed to the left of the input field. | |||
.TP | |||
diff --git a/dmenu.c b/dmenu.c | |||
index 65f25ce..7be19ae 100644 | |||
--- a/dmenu.c | |||
+++ b/dmenu.c | |||
@@ -37,6 +37,9 @@ struct item { | |||
static char text[BUFSIZ] = ""; | |||
static char *embed; | |||
static int bh, mw, mh; | |||
+static int dmx = 0; /* put dmenu at this x offset */ | |||
+static int dmy = 0; /* put dmenu at this y offset (measured from the bottom if topbar is 0) */ | |||
+static unsigned int dmw = 0; /* make dmenu this wide */ | |||
static int inputw = 0, promptw; | |||
static int lrpad; /* sum of left and right padding */ | |||
static size_t cursor; | |||
@@ -637,9 +640,9 @@ setup(void) | |||
if (INTERSECT(x, y, 1, 1, info[i])) | |||
break; | |||
- x = info[i].x_org; | |||
- y = info[i].y_org + (topbar ? 0 : info[i].height - mh); | |||
- mw = info[i].width; | |||
+ x = info[i].x_org + dmx; | |||
+ y = info[i].y_org + (topbar ? dmy : info[i].height - mh - dmy); | |||
+ mw = (dmw>0 ? dmw : info[i].width); | |||
XFree(info); | |||
} else | |||
#endif | |||
@@ -647,9 +650,9 @@ setup(void) | |||
if (!XGetWindowAttributes(dpy, parentwin, &wa)) | |||
die("could not get embedding window attributes: 0x%lx", | |||
parentwin); | |||
- x = 0; | |||
- y = topbar ? 0 : wa.height - mh; | |||
- mw = wa.width; | |||
+ x = dmx; | |||
+ y = topbar ? dmy : wa.height - mh - dmy; | |||
+ mw = (dmw>0 ? dmw : wa.width); | |||
} | |||
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; | |||
inputw = MIN(inputw, mw/3); | |||
@@ -690,6 +693,7 @@ static void | |||
usage(void) | |||
{ | |||
fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" | |||
+ " [-x xoffset] [-y yoffset] [-z width]\n" | |||
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr); | |||
exit(1); | |||
} | |||
@@ -717,6 +721,12 @@ main(int argc, char *argv[]) | |||
/* these options take one argument */ | |||
else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */ | |||
lines = atoi(argv[++i]); | |||
+ else if (!strcmp(argv[i], "-x")) /* window x offset */ | |||
+ dmx = atoi(argv[++i]); | |||
+ else if (!strcmp(argv[i], "-y")) /* window y offset (from bottom up if -b) */ | |||
+ dmy = atoi(argv[++i]); | |||
+ else if (!strcmp(argv[i], "-z")) /* make dmenu this wide */ | |||
+ dmw = atoi(argv[++i]); | |||
else if (!strcmp(argv[i], "-m")) | |||
mon = atoi(argv[++i]); | |||
else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */ | |||
-- | |||
2.28.0 | |||
@ -0,0 +1,243 @@ | |||
.TH DMENU 1 dmenu\-VERSION | |||
.SH NAME | |||
dmenu \- dynamic menu | |||
.SH SYNOPSIS | |||
.B dmenu | |||
.RB [ \-bfiv ] | |||
.RB [ \-l | |||
.IR lines ] | |||
.RB [ \-h | |||
.IR height ] | |||
.RB [ \-m | |||
.IR monitor ] | |||
.RB [ \-x | |||
.IR xoffset ] | |||
.RB [ \-y | |||
.IR yoffset ] | |||
.RB [ \-z | |||
.IR width ] | |||
.RB [ \-p | |||
.IR prompt ] | |||
.RB [ \-fn | |||
.IR font ] | |||
.RB [ \-nb | |||
.IR color ] | |||
.RB [ \-nf | |||
.IR color ] | |||
.RB [ \-sb | |||
.IR color ] | |||
.RB [ \-sf | |||
.IR color ] | |||
.RB [ \-nhb | |||
.IR color ] | |||
.RB [ \-nhf | |||
.IR color ] | |||
.RB [ \-shb | |||
.IR color ] | |||
.RB [ \-shf | |||
.IR color ] | |||
.RB [ \-w | |||
.IR windowid ] | |||
.P | |||
.BR dmenu_run " ..." | |||
.SH DESCRIPTION | |||
.B dmenu | |||
is a dynamic menu for X, which reads a list of newline\-separated items from | |||
stdin. When the user selects an item and presses Return, their choice is printed | |||
to stdout and dmenu terminates. Entering text will narrow the items to those | |||
matching the tokens in the input. | |||
.P | |||
.B dmenu_run | |||
is a script used by | |||
.IR dwm (1) | |||
which lists programs in the user's $PATH and runs the result in their $SHELL. | |||
.SH OPTIONS | |||
.TP | |||
.B \-b | |||
dmenu appears at the bottom of the screen. | |||
.TP | |||
.B \-f | |||
dmenu grabs the keyboard before reading stdin if not reading from a tty. This | |||
is faster, but will lock up X until stdin reaches end\-of\-file. | |||
.TP | |||
.B \-i | |||
dmenu matches menu items case insensitively. | |||
.TP | |||
.BI \-l " lines" | |||
dmenu lists items vertically, with the given number of lines. | |||
.TP | |||
.BI \-h " height" | |||
dmenu uses a menu line of at least 'height' pixels tall, but no less than 8. | |||
.TP | |||
.BI \-m " monitor" | |||
dmenu is displayed on the monitor number supplied. Monitor numbers are starting | |||
from 0. | |||
.TP | |||
.BI \-x " xoffset" | |||
dmenu is placed at this offset measured from the left side of the monitor. | |||
Can be negative. | |||
If option | |||
.B \-m | |||
is present, the measurement will use the given monitor. | |||
.TP | |||
.BI \-y " yoffset" | |||
dmenu is placed at this offset measured from the top of the monitor. If the | |||
.B \-b | |||
option is used, the offset is measured from the bottom. Can be negative. | |||
If option | |||
.B \-m | |||
is present, the measurement will use the given monitor. | |||
.TP | |||
.BI \-z " width" | |||
sets the width of the dmenu window. | |||
.TP | |||
.BI \-p " prompt" | |||
defines the prompt to be displayed to the left of the input field. | |||
.TP | |||
.BI \-fn " font" | |||
defines the font or font set used. | |||
.TP | |||
.BI \-nb " color" | |||
defines the normal background color. | |||
.IR #RGB , | |||
.IR #RRGGBB , | |||
and X color names are supported. | |||
.TP | |||
.BI \-nf " color" | |||
defines the normal foreground color. | |||
.TP | |||
.BI \-sb " color" | |||
defines the selected background color. | |||
.TP | |||
.BI \-sf " color" | |||
defines the selected foreground color. | |||
.TP | |||
.BI \-nhb " color" | |||
defines the normal highlight background color. | |||
.TP | |||
.BI \-nhf " color" | |||
defines the normal highlight foreground color. | |||
.TP | |||
.BI \-shb " color" | |||
defines the selected highlight background color. | |||
.TP | |||
.BI \-shf " color" | |||
defines the selected highlight foreground color. | |||
.TP | |||
.B \-v | |||
prints version information to stdout, then exits. | |||
.TP | |||
.BI \-w " windowid" | |||
embed into windowid. | |||
.SH USAGE | |||
dmenu is completely controlled by the keyboard. Items are selected using the | |||
arrow keys, page up, page down, home, and end. | |||
.TP | |||
.B Tab | |||
Copy the selected item to the input field. | |||
.TP | |||
.B Return | |||
Confirm selection. Prints the selected item to stdout and exits, returning | |||
success. | |||
.TP | |||
.B Ctrl-Return | |||
Confirm selection. Prints the selected item to stdout and continues. | |||
.TP | |||
.B Shift\-Return | |||
Confirm input. Prints the input text to stdout and exits, returning success. | |||
.TP | |||
.B Escape | |||
Exit without selecting an item, returning failure. | |||
.TP | |||
.B Ctrl-Left | |||
Move cursor to the start of the current word | |||
.TP | |||
.B Ctrl-Right | |||
Move cursor to the end of the current word | |||
.TP | |||
.B C\-a | |||
Home | |||
.TP | |||
.B C\-b | |||
Left | |||
.TP | |||
.B C\-c | |||
Escape | |||
.TP | |||
.B C\-d | |||
Delete | |||
.TP | |||
.B C\-e | |||
End | |||
.TP | |||
.B C\-f | |||
Right | |||
.TP | |||
.B C\-g | |||
Escape | |||
.TP | |||
.B C\-h | |||
Backspace | |||
.TP | |||
.B C\-i | |||
Tab | |||
.TP | |||
.B C\-j | |||
Return | |||
.TP | |||
.B C\-J | |||
Shift-Return | |||
.TP | |||
.B C\-k | |||
Delete line right | |||
.TP | |||
.B C\-m | |||
Return | |||
.TP | |||
.B C\-M | |||
Shift-Return | |||
.TP | |||
.B C\-n | |||
Down | |||
.TP | |||
.B C\-p | |||
Up | |||
.TP | |||
.B C\-u | |||
Delete line left | |||
.TP | |||
.B C\-w | |||
Delete word left | |||
.TP | |||
.B C\-y | |||
Paste from primary X selection | |||
.TP | |||
.B C\-Y | |||
Paste from X clipboard | |||
.TP | |||
.B M\-b | |||
Move cursor to the start of the current word | |||
.TP | |||
.B M\-f | |||
Move cursor to the end of the current word | |||
.TP | |||
.B M\-g | |||
Home | |||
.TP | |||
.B M\-G | |||
End | |||
.TP | |||
.B M\-h | |||
Up | |||
.TP | |||
.B M\-j | |||
Page down | |||
.TP | |||
.B M\-k | |||
Page up | |||
.TP | |||
.B M\-l | |||
Down | |||
.SH SEE ALSO | |||
.IR dwm (1), | |||
.IR stest (1) |
@ -0,0 +1,973 @@ | |||
/* See LICENSE file for copyright and license details. */ | |||
#include <ctype.h> | |||
#include <locale.h> | |||
#include <math.h> | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include <string.h> | |||
#include <strings.h> | |||
#include <time.h> | |||
#include <unistd.h> | |||
#include <X11/Xlib.h> | |||
#include <X11/Xatom.h> | |||
#include <X11/Xutil.h> | |||
#ifdef XINERAMA | |||
#include <X11/extensions/Xinerama.h> | |||
#endif | |||
#include <X11/Xft/Xft.h> | |||
#include "drw.h" | |||
#include "util.h" | |||
/* macros */ | |||
#define INTERSECT(x,y,w,h,r) (MAX(0, MIN((x)+(w),(r).x_org+(r).width) - MAX((x),(r).x_org)) \ | |||
* MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org))) | |||
#define LENGTH(X) (sizeof X / sizeof X[0]) | |||
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) | |||
/* enums */ | |||
enum { SchemeNorm, SchemeSel,SchemeNormHighlight, SchemeSelHighlight, SchemeOut, SchemeLast, SchemeHp}; /* color schemes */ | |||
struct item { | |||
char *text; | |||
struct item *left, *right; | |||
int out, hp; | |||
double distance; | |||
}; | |||
static int hplength = 0; | |||
static char text[BUFSIZ] = ""; | |||
static char *embed; | |||
static int bh, mw, mh; | |||
static int inputw = 0, promptw; | |||
static int lrpad; /* sum of left and right padding */ | |||
static size_t cursor; | |||
static struct item *items = NULL; | |||
static struct item *matches, *matchend; | |||
static struct item *prev, *curr, *next, *sel; | |||
static int mon = -1, screen; | |||
static Atom clip, utf8; | |||
static Display *dpy; | |||
static Window root, parentwin, win; | |||
static XIC xic; | |||
static Drw *drw; | |||
static Clr *scheme[SchemeLast]; | |||
#include "config.h" | |||
#include "colors.h" | |||
static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; | |||
static char *(*fstrstr)(const char *, const char *) = strstr; | |||
static char** | |||
tokenize(char *source, const char *delim, int *llen) { | |||
int listlength = 0; | |||
char **list = malloc(1 * sizeof(char*)); | |||
char *token = strtok(source, delim); | |||
while (token) { | |||
if (!(list = realloc(list, sizeof(char*) * (listlength + 1)))) | |||
die("Unable to realloc %d bytes\n", sizeof(char*) * (listlength + 1)); | |||
if (!(list[listlength] = strdup(token))) | |||
die("Unable to strdup %d bytes\n", strlen(token) + 1); | |||
token = strtok(NULL, delim); | |||
listlength++; | |||
} | |||
*llen = listlength; | |||
return list; | |||
} | |||
static int | |||
arrayhas(char **list, int length, char *item) { | |||
for (int i = 0; i < length; i++) { | |||
int len1 = strlen(list[i]); | |||
int len2 = strlen(item); | |||
if (fstrncmp(list[i], item, len1 > len2 ? len2 : len1) == 0) | |||
return 1; | |||
} | |||
return 0; | |||
} | |||
static void | |||
appenditem(struct item *item, struct item **list, struct item **last) | |||
{ | |||
if (*last) | |||
(*last)->right = item; | |||
else | |||
*list = item; | |||
item->left = *last; | |||
item->right = NULL; | |||
*last = item; | |||
} | |||
static void | |||
calcoffsets(void) | |||
{ | |||
int i, n; | |||
if (lines > 0) | |||
n = lines * bh; | |||
else | |||
n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">")); | |||
/* calculate which items will begin the next page and previous page */ | |||
for (i = 0, next = curr; next; next = next->right) | |||
if ((i += (lines > 0) ? bh : MIN(TEXTW(next->text), n)) > n) | |||
break; | |||
for (i = 0, prev = curr; prev && prev->left; prev = prev->left) | |||
if ((i += (lines > 0) ? bh : MIN(TEXTW(prev->left->text), n)) > n) | |||
break; | |||
} | |||
static void | |||
cleanup(void) | |||
{ | |||
size_t i; | |||
XUngrabKey(dpy, AnyKey, AnyModifier, root); | |||
for (i = 0; i < SchemeLast; i++) | |||
free(scheme[i]); | |||
drw_free(drw); | |||
XSync(dpy, False); | |||
XCloseDisplay(dpy); | |||
} | |||
static char * | |||
cistrstr(const char *s, const char *sub) | |||
{ | |||
size_t len; | |||
for (len = strlen(sub); *s; s++) | |||
if (!strncasecmp(s, sub, len)) | |||
return (char *)s; | |||
return NULL; | |||
} | |||
static void | |||
drawhighlights(struct item *item, int x, int y, int maxw) | |||
{ | |||
int i, indent; | |||
char *highlight; | |||
char c; | |||
if (!(strlen(item->text) && strlen(text))) | |||
return; | |||
drw_setscheme(drw, scheme[item == sel | |||
? SchemeSelHighlight | |||
: SchemeNormHighlight]); | |||
for (i = 0, highlight = item->text; *highlight && text[i];) { | |||
if (*highlight == text[i]) { | |||
/* get indentation */ | |||
c = *highlight; | |||
*highlight = '\0'; | |||
indent = TEXTW(item->text); | |||
*highlight = c; | |||
/* highlight character */ | |||
c = highlight[1]; | |||
highlight[1] = '\0'; | |||
drw_text( | |||
drw, | |||
x + indent - (lrpad / 2), | |||
y, | |||
MIN(maxw - indent, TEXTW(highlight) - lrpad), | |||
bh, 0, highlight, 0 | |||
); | |||
highlight[1] = c; | |||
i++; | |||
} | |||
highlight++; | |||
} | |||
} | |||
static int | |||
drawitem(struct item *item, int x, int y, int w) | |||
{ | |||
int r; | |||
if (item == sel) | |||
drw_setscheme(drw, scheme[SchemeSel]); | |||
else if (item->hp) | |||
drw_setscheme(drw, scheme[SchemeHp]); | |||
else if (item->out) | |||
drw_setscheme(drw, scheme[SchemeOut]); | |||
else | |||
drw_setscheme(drw, scheme[SchemeNorm]); | |||
r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0); | |||
drawhighlights(item, x, y, w); | |||
return r; | |||
} | |||
static void | |||
drawmenu(void) | |||
{ | |||
unsigned int curpos; | |||
struct item *item; | |||
int x = 0, y = 0, fh = drw->fonts->h, w; | |||
drw_setscheme(drw, scheme[SchemeNorm]); | |||
drw_rect(drw, 0, 0, mw, mh, 1, 1); | |||
if (prompt && *prompt) { | |||
drw_setscheme(drw, scheme[SchemeSel]); | |||
x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0); | |||
} | |||
/* draw input field */ | |||
w = (lines > 0 || !matches) ? mw - x : inputw; | |||
drw_setscheme(drw, scheme[SchemeNorm]); | |||
drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0); | |||
curpos = TEXTW(text) - TEXTW(&text[cursor]); | |||
if ((curpos += lrpad / 2 - 1) < w) { | |||
drw_setscheme(drw, scheme[SchemeNorm]); | |||
drw_rect(drw, x + curpos, 2 + (bh - fh) / 2, 2, fh - 4, 1, 0); | |||
} | |||
if (lines > 0) { | |||
/* draw vertical list */ | |||
for (item = curr; item != next; item = item->right) | |||
drawitem(item, x, y += bh, mw - x); | |||
} else if (matches) { | |||
/* draw horizontal list */ | |||
x += inputw; | |||
w = TEXTW("<"); | |||
if (curr->left) { | |||
drw_setscheme(drw, scheme[SchemeNorm]); | |||
drw_text(drw, x, 0, w, bh, lrpad / 2, "<", 0); | |||
} | |||
x += w; | |||
for (item = curr; item != next; item = item->right) | |||
x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">"))); | |||
if (next) { | |||
w = TEXTW(">"); | |||
drw_setscheme(drw, scheme[SchemeNorm]); | |||
drw_text(drw, mw - w, 0, w, bh, lrpad / 2, ">", 0); | |||
} | |||
} | |||
drw_map(drw, win, 0, 0, mw, mh); | |||
} | |||
static void | |||
grabfocus(void) | |||
{ | |||
struct timespec ts = { .tv_sec = 0, .tv_nsec = 10000000 }; | |||
Window focuswin; | |||
int i, revertwin; | |||
for (i = 0; i < 100; ++i) { | |||
XGetInputFocus(dpy, &focuswin, &revertwin); | |||
if (focuswin == win) | |||
return; | |||
XSetInputFocus(dpy, win, RevertToParent, CurrentTime); | |||
nanosleep(&ts, NULL); | |||
} | |||
die("cannot grab focus"); | |||
} | |||
static void | |||
grabkeyboard(void) | |||
{ | |||
struct timespec ts = { .tv_sec = 0, .tv_nsec = 1000000 }; | |||
int i; | |||
if (embed) | |||
return; | |||
/* try to grab keyboard, we may have to wait for another process to ungrab */ | |||
for (i = 0; i < 1000; i++) { | |||
if (XGrabKeyboard(dpy, DefaultRootWindow(dpy), True, GrabModeAsync, | |||
GrabModeAsync, CurrentTime) == GrabSuccess) | |||
return; | |||
nanosleep(&ts, NULL); | |||
} | |||
die("cannot grab keyboard"); | |||
} | |||
int | |||
compare_distance(const void *a, const void *b) | |||
{ | |||
struct item *da = *(struct item **) a; | |||
struct item *db = *(struct item **) b; | |||
if (!db) | |||
return 1; | |||
if (!da) | |||
return -1; | |||
return da->distance == db->distance ? 0 : da->distance < db->distance ? -1 : 1; | |||
} | |||
void | |||
fuzzymatch(void) | |||
{ | |||
/* bang - we have so much memory */ | |||
struct item *it; | |||
struct item **fuzzymatches = NULL; | |||
char c; | |||
int number_of_matches = 0, i, pidx, sidx, eidx; | |||
int text_len = strlen(text), itext_len; | |||
matches = matchend = NULL; | |||
/* walk through all items */ | |||
for (it = items; it && it->text; it++) { | |||
if (text_len) { | |||
itext_len = strlen(it->text); | |||
pidx = 0; /* pointer */ | |||
sidx = eidx = -1; /* start of match, end of match */ | |||
/* walk through item text */ | |||
for (i = 0; i < itext_len && (c = it->text[i]); i++) { | |||
/* fuzzy match pattern */ | |||
if (!fstrncmp(&text[pidx], &c, 1)) { | |||
if(sidx == -1) | |||
sidx = i; | |||
pidx++; | |||
if (pidx == text_len) { | |||
eidx = i; | |||
break; | |||
} | |||
} | |||
} | |||
/* build list of matches */ | |||
if (eidx != -1) { | |||
/* compute distance */ | |||
/* add penalty if match starts late (log(sidx+2)) | |||
* add penalty for long a match without many matching characters */ | |||
it->distance = log(sidx + 2) + (double)(eidx - sidx - text_len); | |||
/* fprintf(stderr, "distance %s %f\n", it->text, it->distance); */ | |||
appenditem(it, &matches, &matchend); | |||
number_of_matches++; | |||
} | |||
} else { | |||
appenditem(it, &matches, &matchend); | |||
} | |||
} | |||
if (number_of_matches) { | |||
/* initialize array with matches */ | |||
if (!(fuzzymatches = realloc(fuzzymatches, number_of_matches * sizeof(struct item*)))) | |||
die("cannot realloc %u bytes:", number_of_matches * sizeof(struct item*)); | |||
for (i = 0, it = matches; it && i < number_of_matches; i++, it = it->right) { | |||
fuzzymatches[i] = it; | |||
} | |||
/* sort matches according to distance */ | |||
qsort(fuzzymatches, number_of_matches, sizeof(struct item*), compare_distance); | |||
/* rebuild list of matches */ | |||
matches = matchend = NULL; | |||
for (i = 0, it = fuzzymatches[i]; i < number_of_matches && it && \ | |||
it->text; i++, it = fuzzymatches[i]) { | |||
appenditem(it, &matches, &matchend); | |||
} | |||
free(fuzzymatches); | |||
} | |||
curr = sel = matches; | |||
calcoffsets(); | |||
} | |||
static void | |||
match(void) | |||
{ | |||
if (fuzzy) { | |||
fuzzymatch(); | |||
return; | |||
} | |||
static char **tokv = NULL; | |||
static int tokn = 0; | |||
char buf[sizeof text], *s; | |||
int i, tokc = 0; | |||
size_t len, textsize; | |||
struct item *item, *lhpprefix, *lprefix, *lsubstr, *hpprefixend, *prefixend, *substrend; | |||
strcpy(buf, text); | |||
/* separate input text into tokens to be matched individually */ | |||
for (s = strtok(buf, " "); s; tokv[tokc - 1] = s, s = strtok(NULL, " ")) | |||
if (++tokc > tokn && !(tokv = realloc(tokv, ++tokn * sizeof *tokv))) | |||
die("cannot realloc %u bytes:", tokn * sizeof *tokv); | |||
len = tokc ? strlen(tokv[0]) : 0; | |||
matches = lhpprefix = lprefix = lsubstr = matchend = hpprefixend = prefixend = substrend = NULL; | |||
textsize = strlen(text) + 1; | |||
for (item = items; item && item->text; item++) { | |||
for (i = 0; i < tokc; i++) | |||
if (!fstrstr(item->text, tokv[i])) | |||
break; | |||
if (i != tokc) /* not all tokens match */ | |||
continue; | |||
/* exact matches go first, then prefixes with high priority, then prefixes, then substrings */ | |||
if (!tokc || !fstrncmp(text, item->text, textsize)) | |||
appenditem(item, &matches, &matchend); | |||
else if (item->hp && !fstrncmp(tokv[0], item->text, len)) | |||
appenditem(item, &lhpprefix, &hpprefixend); | |||
else if (!fstrncmp(tokv[0], item->text, len)) | |||
appenditem(item, &lprefix, &prefixend); | |||
else | |||
appenditem(item, &lsubstr, &substrend); | |||
} | |||
if (lhpprefix) { | |||
if (matches) { | |||
matchend->right = lhpprefix; | |||
lhpprefix->left = matchend; | |||
} else | |||
matches = lhpprefix; | |||
matchend = hpprefixend; | |||
} | |||
if (lprefix) { | |||
if (matches) { | |||
matchend->right = lprefix; | |||
lprefix->left = matchend; | |||
} else | |||
matches = lprefix; | |||
matchend = prefixend; | |||
} | |||
if (lsubstr) { | |||
if (matches) { | |||
matchend->right = lsubstr; | |||
lsubstr->left = matchend; | |||
} else | |||
matches = lsubstr; | |||
matchend = substrend; | |||
} | |||
curr = sel = matches; | |||
calcoffsets(); | |||
} | |||
static void | |||
insert(const char *str, ssize_t n) | |||
{ | |||
if (strlen(text) + n > sizeof text - 1) | |||
return; | |||
/* move existing text out of the way, insert new text, and update cursor */ | |||
memmove(&text[cursor + n], &text[cursor], sizeof text - cursor - MAX(n, 0)); | |||
if (n > 0) | |||
memcpy(&text[cursor], str, n); | |||
cursor += n; | |||
match(); | |||
} | |||
static size_t | |||
nextrune(int inc) | |||
{ | |||
ssize_t n; | |||
/* return location of next utf8 rune in the given direction (+1 or -1) */ | |||
for (n = cursor + inc; n + inc >= 0 && (text[n] & 0xc0) == 0x80; n += inc) | |||
; | |||
return n; | |||
} | |||
static void | |||
movewordedge(int dir) | |||
{ | |||
if (dir < 0) { /* move cursor to the start of the word*/ | |||
while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)])) | |||
cursor = nextrune(-1); | |||
while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)])) | |||
cursor = nextrune(-1); | |||
} else { /* move cursor to the end of the word */ | |||
while (text[cursor] && strchr(worddelimiters, text[cursor])) | |||
cursor = nextrune(+1); | |||
while (text[cursor] && !strchr(worddelimiters, text[cursor])) | |||
cursor = nextrune(+1); | |||
} | |||
} | |||
static void | |||
keypress(XKeyEvent *ev) | |||
{ | |||
char buf[32]; | |||
int len; | |||
KeySym ksym; | |||
Status status; | |||
len = XmbLookupString(xic, ev, buf, sizeof buf, &ksym, &status); | |||
switch (status) { | |||
default: /* XLookupNone, XBufferOverflow */ | |||
return; | |||
case XLookupChars: | |||
goto insert; | |||
case XLookupKeySym: | |||
case XLookupBoth: | |||
break; | |||
} | |||
if (ev->state & ControlMask) { | |||
switch(ksym) { | |||
case XK_a: ksym = XK_Home; break; | |||
case XK_b: ksym = XK_Left; break; | |||
case XK_c: ksym = XK_Escape; break; | |||
case XK_d: ksym = XK_Delete; break; | |||
case XK_e: ksym = XK_End; break; | |||
case XK_f: ksym = XK_Right; break; | |||
case XK_g: ksym = XK_Escape; break; | |||
case XK_h: ksym = XK_BackSpace; break; | |||
case XK_i: ksym = XK_Tab; break; | |||
case XK_j: /* fallthrough */ | |||
case XK_J: /* fallthrough */ | |||
case XK_m: /* fallthrough */ | |||
case XK_M: ksym = XK_Return; ev->state &= ~ControlMask; break; | |||
case XK_n: ksym = XK_Down; break; | |||
case XK_p: ksym = XK_Up; break; | |||
case XK_k: /* delete right */ | |||
text[cursor] = '\0'; | |||
match(); | |||
break; | |||
case XK_u: /* delete left */ | |||
insert(NULL, 0 - cursor); | |||
break; | |||
case XK_w: /* delete word */ | |||
while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)])) | |||
insert(NULL, nextrune(-1) - cursor); | |||
while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)])) | |||
insert(NULL, nextrune(-1) - cursor); | |||
break; | |||
case XK_y: /* paste selection */ | |||
case XK_Y: | |||
XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY, | |||
utf8, utf8, win, CurrentTime); | |||
return; | |||
case XK_Left: | |||
movewordedge(-1); | |||
goto draw; | |||
case XK_Right: | |||
movewordedge(+1); | |||
goto draw; | |||
case XK_Return: | |||
case XK_KP_Enter: | |||
break; | |||
case XK_bracketleft: | |||
cleanup(); | |||
exit(1); | |||
default: | |||
return; | |||
} | |||
} else if (ev->state & Mod1Mask) { | |||
switch(ksym) { | |||
case XK_b: | |||
movewordedge(-1); | |||
goto draw; | |||
case XK_f: | |||
movewordedge(+1); | |||
goto draw; | |||
case XK_g: ksym = XK_Home; break; | |||
case XK_G: ksym = XK_End; break; | |||
case XK_h: ksym = XK_Up; break; | |||
case XK_j: ksym = XK_Next; break; | |||
case XK_k: ksym = XK_Prior; break; | |||
case XK_l: ksym = XK_Down; break; | |||
default: | |||
return; | |||
} | |||
} | |||
switch(ksym) { | |||
default: | |||
insert: | |||
if (!iscntrl(*buf)) | |||
insert(buf, len); | |||
break; | |||
case XK_Delete: | |||
if (text[cursor] == '\0') | |||
return; | |||
cursor = nextrune(+1); | |||
/* fallthrough */ | |||
case XK_BackSpace: | |||
if (cursor == 0) | |||
return; | |||
insert(NULL, nextrune(-1) - cursor); | |||
break; | |||
case XK_End: | |||
if (text[cursor] != '\0') { | |||
cursor = strlen(text); | |||
break; | |||
} | |||
if (next) { | |||
/* jump to end of list and position items in reverse */ | |||
curr = matchend; | |||
calcoffsets(); | |||
curr = prev; | |||
calcoffsets(); | |||
while (next && (curr = curr->right)) | |||
calcoffsets(); | |||
} | |||
sel = matchend; | |||
break; | |||
case XK_Escape: | |||
cleanup(); | |||
exit(1); | |||
case XK_Home: | |||
if (sel == matches) { | |||
cursor = 0; | |||
break; | |||
} | |||
sel = curr = matches; | |||
calcoffsets(); | |||
break; | |||
case XK_Left: | |||
if (cursor > 0 && (!sel || !sel->left || lines > 0)) { | |||
cursor = nextrune(-1); | |||
break; | |||
} | |||
if (lines > 0) | |||
return; | |||
/* fallthrough */ | |||
case XK_Up: | |||
if (sel && sel->left && (sel = sel->left)->right == curr) { | |||
curr = prev; | |||
calcoffsets(); | |||
} | |||
break; | |||
case XK_Next: | |||
if (!next) | |||
return; | |||
sel = curr = next; | |||
calcoffsets(); | |||
break; | |||
case XK_Prior: | |||
if (!prev) | |||
return; | |||
sel = curr = prev; | |||
calcoffsets(); | |||
break; | |||
case XK_Return: | |||
case XK_KP_Enter: | |||
puts((sel && !(ev->state & ShiftMask)) ? sel->text : text); | |||
if (!(ev->state & ControlMask)) { | |||
cleanup(); | |||
exit(0); | |||
} | |||
if (sel) | |||
sel->out = 1; | |||
break; | |||
case XK_Right: | |||
if (text[cursor] != '\0') { | |||
cursor = nextrune(+1); | |||
break; | |||
} | |||
if (lines > 0) | |||
return; | |||
/* fallthrough */ | |||
case XK_Down: | |||
if (sel && sel->right && (sel = sel->right) == next) { | |||
curr = next; | |||
calcoffsets(); | |||
} | |||
break; | |||
case XK_Tab: | |||
if (!sel) | |||
return; | |||
strncpy(text, sel->text, sizeof text - 1); | |||
text[sizeof text - 1] = '\0'; | |||
cursor = strlen(text); | |||
match(); | |||
break; | |||
} | |||
draw: | |||
drawmenu(); | |||
} | |||
static void | |||
paste(void) | |||
{ | |||
char *p, *q; | |||
int di; | |||
unsigned long dl; | |||
Atom da; | |||
/* we have been given the current selection, now insert it into input */ | |||
if (XGetWindowProperty(dpy, win, utf8, 0, (sizeof text / 4) + 1, False, | |||
utf8, &da, &di, &dl, &dl, (unsigned char **)&p) | |||
== Success && p) { | |||
insert(p, (q = strchr(p, '\n')) ? q - p : (ssize_t)strlen(p)); | |||
XFree(p); | |||
} | |||
drawmenu(); | |||
} | |||
static void | |||
readstdin(void) | |||
{ | |||
char buf[sizeof text], *p; | |||
size_t i, imax = 0, size = 0; | |||
unsigned int tmpmax = 0; | |||
/* read each line from stdin and add it to the item list */ | |||
for (i = 0; fgets(buf, sizeof buf, stdin); i++) { | |||
if (i + 1 >= size / sizeof *items) | |||
if (!(items = realloc(items, (size += BUFSIZ)))) | |||
die("cannot realloc %u bytes:", size); | |||
if ((p = strchr(buf, '\n'))) | |||
*p = '\0'; | |||
if (!(items[i].text = strdup(buf))) | |||
die("cannot strdup %u bytes:", strlen(buf) + 1); | |||
items[i].out = 0; | |||
items[i].hp = arrayhas(hpitems, hplength, items[i].text); | |||
drw_font_getexts(drw->fonts, buf, strlen(buf), &tmpmax, NULL); | |||
if (tmpmax > inputw) { | |||
inputw = tmpmax; | |||
imax = i; | |||
} | |||
} | |||
if (items) | |||
items[i].text = NULL; | |||
inputw = items ? TEXTW(items[imax].text) : 0; | |||
lines = MIN(lines, i); | |||
} | |||
static void | |||
run(void) | |||
{ | |||
XEvent ev; | |||
while (!XNextEvent(dpy, &ev)) { | |||
if (XFilterEvent(&ev, win)) | |||
continue; | |||
switch(ev.type) { | |||
case DestroyNotify: | |||
if (ev.xdestroywindow.window != win) | |||
break; | |||
cleanup(); | |||
exit(1); | |||
case Expose: | |||
if (ev.xexpose.count == 0) | |||
drw_map(drw, win, 0, 0, mw, mh); | |||
break; | |||
case FocusIn: | |||
/* regrab focus from parent window */ | |||
if (ev.xfocus.window != win) | |||
grabfocus(); | |||
break; | |||
case KeyPress: | |||
keypress(&ev.xkey); | |||
break; | |||
case SelectionNotify: | |||
if (ev.xselection.property == utf8) | |||
paste(); | |||
break; | |||
case VisibilityNotify: | |||
if (ev.xvisibility.state != VisibilityUnobscured) | |||
XRaiseWindow(dpy, win); | |||
break; | |||
} | |||
} | |||
} | |||
static void | |||
setup(void) | |||
{ | |||
int x, y, i, j; | |||
unsigned int du; | |||
XSetWindowAttributes swa; | |||
XIM xim; | |||
Window w, dw, *dws; | |||
XWindowAttributes wa; | |||
XClassHint ch = {"dmenu", "dmenu"}; | |||
#ifdef XINERAMA | |||
XineramaScreenInfo *info; | |||
Window pw; | |||
int a, di, n, area = 0; | |||
#endif | |||
/* init appearance */ | |||
for (j = 0; j < SchemeLast; j++) | |||
scheme[j] = drw_scm_create(drw, colors[j], 2); | |||
clip = XInternAtom(dpy, "CLIPBOARD", False); | |||
utf8 = XInternAtom(dpy, "UTF8_STRING", False); | |||
/* calculate menu geometry */ | |||
bh = drw->fonts->h + 2; | |||
bh = MAX(bh,lineheight); /* make a menu line AT LEAST 'lineheight' tall */ | |||
lines = MAX(lines, 0); | |||
mh = (lines + 1) * bh; | |||
#ifdef XINERAMA | |||
i = 0; | |||
if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) { | |||
XGetInputFocus(dpy, &w, &di); | |||
if (mon >= 0 && mon < n) | |||
i = mon; | |||
else if (w != root && w != PointerRoot && w != None) { | |||
/* find top-level window containing current input focus */ | |||
do { | |||
if (XQueryTree(dpy, (pw = w), &dw, &w, &dws, &du) && dws) | |||
XFree(dws); | |||
} while (w != root && w != pw); | |||
/* find xinerama screen with which the window intersects most */ | |||
if (XGetWindowAttributes(dpy, pw, &wa)) | |||
for (j = 0; j < n; j++) | |||
if ((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) { | |||
area = a; | |||
i = j; | |||
} | |||
} | |||
/* no focused window is on screen, so use pointer location instead */ | |||
if (mon < 0 && !area && XQueryPointer(dpy, root, &dw, &dw, &x, &y, &di, &di, &du)) | |||
for (i = 0; i < n; i++) | |||
if (INTERSECT(x, y, 1, 1, info[i])) | |||
break; | |||
x = info[i].x_org + dmx; | |||
y = info[i].y_org + (topbar ? dmy : info[i].height - mh - dmy); | |||
mw = (dmw>0 ? dmw : info[i].width); | |||
XFree(info); | |||
} else | |||
#endif | |||
{ | |||
if (!XGetWindowAttributes(dpy, parentwin, &wa)) | |||
die("could not get embedding window attributes: 0x%lx", | |||
parentwin); | |||
x = dmx; | |||
y = topbar ? dmy : wa.height - mh - dmy; | |||
mw = (dmw>0 ? dmw : wa.width); | |||
} | |||
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; | |||
inputw = MIN(inputw, mw/3); | |||
match(); | |||
/* create menu window */ | |||
swa.override_redirect = True; | |||
swa.background_pixel = scheme[SchemeNorm][ColBg].pixel; | |||
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask; | |||
win = XCreateWindow(dpy, parentwin, x, y, mw, mh, 0, | |||
CopyFromParent, CopyFromParent, CopyFromParent, | |||
CWOverrideRedirect | CWBackPixel | CWEventMask, &swa); | |||
XSetClassHint(dpy, win, &ch); | |||
/* input methods */ | |||
if ((xim = XOpenIM(dpy, NULL, NULL, NULL)) == NULL) | |||
die("XOpenIM failed: could not open input device"); | |||
xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, | |||
XNClientWindow, win, XNFocusWindow, win, NULL); | |||
XMapRaised(dpy, win); | |||
if (embed) { | |||
XSelectInput(dpy, parentwin, FocusChangeMask | SubstructureNotifyMask); | |||
if (XQueryTree(dpy, parentwin, &dw, &w, &dws, &du) && dws) { | |||
for (i = 0; i < du && dws[i] != win; ++i) | |||
XSelectInput(dpy, dws[i], FocusChangeMask); | |||
XFree(dws); | |||
} | |||
grabfocus(); | |||
} | |||
drw_resize(drw, mw, mh); | |||
drawmenu(); | |||
} | |||
static void | |||
usage(void) | |||
{ | |||
fputs("usage: dmenu [-bfiv] [-l lines] [-h height] [-p prompt] [-fn font] [-m monitor]\n" | |||
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr); | |||
exit(1); | |||
} | |||
int | |||
main(int argc, char *argv[]) | |||
{ | |||
XWindowAttributes wa; | |||
int i, fast = 0; | |||
for (i = 1; i < argc; i++) | |||
/* these options take no arguments */ | |||
if (!strcmp(argv[i], "-v")) { /* prints version information */ | |||
puts("dmenu-"VERSION); | |||
exit(0); | |||
} else if (!strcmp(argv[i], "-b")) /* appears at the bottom of the screen */ | |||
topbar = 0; | |||
else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */ | |||
fast = 1; | |||
else if (!strcmp(argv[i], "-F")) /* grabs keyboard before reading stdin */ | |||
fuzzy = 1; | |||
else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ | |||
fstrncmp = strncasecmp; | |||
fstrstr = cistrstr; | |||
} else if (i + 1 == argc) | |||
usage(); | |||
/* these options take one argument */ | |||
else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */ | |||
lines = atoi(argv[++i]); | |||
else if (!strcmp(argv[i], "-h")) { /* minimum height of one menu line */ | |||
lineheight = atoi(argv[++i]); | |||
lineheight = MAX(lineheight, min_lineheight); | |||
} | |||
else if (!strcmp(argv[i], "-x")) /* window x offset */ | |||
dmx = atoi(argv[++i]); | |||
else if (!strcmp(argv[i], "-y")) /* window y offset (from bottom up if -b) */ | |||
dmy = atoi(argv[++i]); | |||
else if (!strcmp(argv[i], "-z")) /* make dmenu this wide */ | |||
dmw = atoi(argv[++i]); | |||
else if (!strcmp(argv[i], "-m")) | |||
mon = atoi(argv[++i]); | |||
else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */ | |||
prompt = argv[++i]; | |||
else if (!strcmp(argv[i], "-fn")) /* font or font set */ | |||
fonts[0] = argv[++i]; | |||
else if (!strcmp(argv[i], "-nb")) /* normal background color */ | |||
colors[SchemeNorm][ColBg] = argv[++i]; | |||
else if (!strcmp(argv[i], "-nf")) /* normal foreground color */ | |||
colors[SchemeNorm][ColFg] = argv[++i]; | |||
else if (!strcmp(argv[i], "-sb")) /* selected background color */ | |||
colors[SchemeSel][ColBg] = argv[++i]; | |||
else if (!strcmp(argv[i], "-sf")) /* selected foreground color */ | |||
colors[SchemeSel][ColFg] = argv[++i]; | |||
else if (!strcmp(argv[i], "-hb")) /* high priority background color */ | |||
colors[SchemeHp][ColBg] = argv[++i]; | |||
else if (!strcmp(argv[i], "-hf")) /* low priority background color */ | |||
colors[SchemeHp][ColFg] = argv[++i]; | |||
else if (!strcmp(argv[i], "-w")) /* embedding window id */ | |||
embed = argv[++i]; | |||
else if (!strcmp(argv[i], "-nhb")) /* normal hi background color */ | |||
colors[SchemeNormHighlight][ColBg] = argv[++i]; | |||
else if (!strcmp(argv[i], "-nhf")) /* normal hi foreground color */ | |||
colors[SchemeNormHighlight][ColFg] = argv[++i]; | |||
else if (!strcmp(argv[i], "-shb")) /* selected hi background color */ | |||
colors[SchemeSelHighlight][ColBg] = argv[++i]; | |||
else if (!strcmp(argv[i], "-shf")) /* selected hi foreground color */ | |||
colors[SchemeSelHighlight][ColFg] = argv[++i]; | |||
else if (!strcmp(argv[i], "-hp")) | |||
hpitems = tokenize(argv[++i], ",", &hplength); | |||
else | |||
usage(); | |||
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) | |||
fputs("warning: no locale support\n", stderr); | |||
if (!(dpy = XOpenDisplay(NULL))) | |||
die("cannot open display"); | |||
screen = DefaultScreen(dpy); | |||
root = RootWindow(dpy, screen); | |||
if (!embed || !(parentwin = strtol(embed, NULL, 0))) | |||
parentwin = root; | |||
if (!XGetWindowAttributes(dpy, parentwin, &wa)) | |||
die("could not get embedding window attributes: 0x%lx", | |||
parentwin); | |||
drw = drw_create(dpy, screen, root, wa.width, wa.height); | |||
if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) | |||
die("no fonts could be loaded."); | |||
lrpad = drw->fonts->h; | |||
#ifdef __OpenBSD__ | |||
if (pledge("stdio rpath", NULL) == -1) | |||
die("pledge"); | |||
#endif | |||
if (fast && !isatty(0)) { | |||
grabkeyboard(); | |||
readstdin(); | |||
} else { | |||
readstdin(); | |||
grabkeyboard(); | |||
} | |||
setup(); | |||
run(); | |||
return 1; /* unreachable */ | |||
} |
@ -0,0 +1,436 @@ | |||
/* See LICENSE file for copyright and license details. */ | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include <string.h> | |||
#include <X11/Xlib.h> | |||
#include <X11/Xft/Xft.h> | |||
#include "drw.h" | |||
#include "util.h" | |||
#define UTF_INVALID 0xFFFD | |||
#define UTF_SIZ 4 | |||
static const unsigned char utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; | |||
static const unsigned char utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; | |||
static const long utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; | |||
static const long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; | |||
static long | |||
utf8decodebyte(const char c, size_t *i) | |||
{ | |||
for (*i = 0; *i < (UTF_SIZ + 1); ++(*i)) | |||
if (((unsigned char)c & utfmask[*i]) == utfbyte[*i]) | |||
return (unsigned char)c & ~utfmask[*i]; | |||
return 0; | |||
} | |||
static size_t | |||
utf8validate(long *u, size_t i) | |||
{ | |||
if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF)) | |||
*u = UTF_INVALID; | |||
for (i = 1; *u > utfmax[i]; ++i) | |||
; | |||
return i; | |||
} | |||
static size_t | |||
utf8decode(const char *c, long *u, size_t clen) | |||
{ | |||
size_t i, j, len, type; | |||
long udecoded; | |||
*u = UTF_INVALID; | |||
if (!clen) | |||
return 0; | |||
udecoded = utf8decodebyte(c[0], &len); | |||
if (!BETWEEN(len, 1, UTF_SIZ)) | |||
return 1; | |||
for (i = 1, j = 1; i < clen && j < len; ++i, ++j) { | |||
udecoded = (udecoded << 6) | utf8decodebyte(c[i], &type); | |||
if (type) | |||
return j; | |||
} | |||
if (j < len) | |||
return 0; | |||
*u = udecoded; | |||
utf8validate(u, len); | |||
return len; | |||
} | |||
Drw * | |||
drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) | |||
{ | |||
Drw *drw = ecalloc(1, sizeof(Drw)); | |||
drw->dpy = dpy; | |||
drw->screen = screen; | |||
drw->root = root; | |||
drw->w = w; | |||
drw->h = h; | |||
drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen)); | |||
drw->gc = XCreateGC(dpy, root, 0, NULL); | |||
XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter); | |||
return drw; | |||
} | |||
void | |||
drw_resize(Drw *drw, unsigned int w, unsigned int h) | |||
{ | |||
if (!drw) | |||
return; | |||
drw->w = w; | |||
drw->h = h; | |||
if (drw->drawable) | |||
XFreePixmap(drw->dpy, drw->drawable); | |||
drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen)); | |||
} | |||
void | |||
drw_free(Drw *drw) | |||
{ | |||
XFreePixmap(drw->dpy, drw->drawable); | |||
XFreeGC(drw->dpy, drw->gc); | |||
drw_fontset_free(drw->fonts); | |||
free(drw); | |||
} | |||
/* This function is an implementation detail. Library users should use | |||
* drw_fontset_create instead. | |||
*/ | |||
static Fnt * | |||
xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern) | |||
{ | |||
Fnt *font; | |||
XftFont *xfont = NULL; | |||
FcPattern *pattern = NULL; | |||
if (fontname) { | |||
/* Using the pattern found at font->xfont->pattern does not yield the | |||
* same substitution results as using the pattern returned by | |||
* FcNameParse; using the latter results in the desired fallback | |||
* behaviour whereas the former just results in missing-character | |||
* rectangles being drawn, at least with some fonts. */ | |||
if (!(xfont = XftFontOpenName(drw->dpy, drw->screen, fontname))) { | |||
fprintf(stderr, "error, cannot load font from name: '%s'\n", fontname); | |||
return NULL; | |||
} | |||
if (!(pattern = FcNameParse((FcChar8 *) fontname))) { | |||
fprintf(stderr, "error, cannot parse font name to pattern: '%s'\n", fontname); | |||
XftFontClose(drw->dpy, xfont); | |||
return NULL; | |||
} | |||
} else if (fontpattern) { | |||
if (!(xfont = XftFontOpenPattern(drw->dpy, fontpattern))) { | |||
fprintf(stderr, "error, cannot load font from pattern.\n"); | |||
return NULL; | |||
} | |||
} else { | |||
die("no font specified."); | |||
} | |||
/* Do not allow using color fonts. This is a workaround for a BadLength | |||
* error from Xft with color glyphs. Modelled on the Xterm workaround. See | |||
* https://bugzilla.redhat.com/show_bug.cgi?id=1498269 | |||
* https://lists.suckless.org/dev/1701/30932.html | |||
* https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=916349 | |||
* and lots more all over the internet. | |||
*/ | |||
FcBool iscol; | |||
if(FcPatternGetBool(xfont->pattern, FC_COLOR, 0, &iscol) == FcResultMatch && iscol) { | |||
XftFontClose(drw->dpy, xfont); | |||
return NULL; | |||
} | |||
font = ecalloc(1, sizeof(Fnt)); | |||
font->xfont = xfont; | |||
font->pattern = pattern; | |||
font->h = xfont->ascent + xfont->descent; | |||
font->dpy = drw->dpy; | |||
return font; | |||
} | |||
static void | |||
xfont_free(Fnt *font) | |||
{ | |||
if (!font) | |||
return; | |||
if (font->pattern) | |||
FcPatternDestroy(font->pattern); | |||
XftFontClose(font->dpy, font->xfont); | |||
free(font); | |||
} | |||
Fnt* | |||
drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount) | |||
{ | |||
Fnt *cur, *ret = NULL; | |||
size_t i; | |||
if (!drw || !fonts) | |||
return NULL; | |||
for (i = 1; i <= fontcount; i++) { | |||
if ((cur = xfont_create(drw, fonts[fontcount - i], NULL))) { | |||
cur->next = ret; | |||
ret = cur; | |||
} | |||
} | |||
return (drw->fonts = ret); | |||
} | |||
void | |||
drw_fontset_free(Fnt *font) | |||
{ | |||
if (font) { | |||
drw_fontset_free(font->next); | |||
xfont_free(font); | |||
} | |||
} | |||
void | |||
drw_clr_create(Drw *drw, Clr *dest, const char *clrname) | |||
{ | |||
if (!drw || !dest || !clrname) | |||
return; | |||
if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen), | |||
DefaultColormap(drw->dpy, drw->screen), | |||
clrname, dest)) | |||
die("error, cannot allocate color '%s'", clrname); | |||
} | |||
/* Wrapper to create color schemes. The caller has to call free(3) on the | |||
* returned color scheme when done using it. */ | |||
Clr * | |||
drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) | |||
{ | |||
size_t i; | |||
Clr *ret; | |||
/* need at least two colors for a scheme */ | |||
if (!drw || !clrnames || clrcount < 2 || !(ret = ecalloc(clrcount, sizeof(XftColor)))) | |||
return NULL; | |||
for (i = 0; i < clrcount; i++) | |||
drw_clr_create(drw, &ret[i], clrnames[i]); | |||
return ret; | |||
} | |||
void | |||
drw_setfontset(Drw *drw, Fnt *set) | |||
{ | |||
if (drw) | |||
drw->fonts = set; | |||
} | |||
void | |||
drw_setscheme(Drw *drw, Clr *scm) | |||
{ | |||
if (drw) | |||
drw->scheme = scm; | |||
} | |||
void | |||
drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert) | |||
{ | |||
if (!drw || !drw->scheme) | |||
return; | |||
XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme[ColBg].pixel : drw->scheme[ColFg].pixel); | |||
if (filled) | |||
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); | |||
else | |||
XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w - 1, h - 1); | |||
} | |||
int | |||
drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert) | |||
{ | |||
char buf[1024]; | |||
int ty; | |||
unsigned int ew; | |||
XftDraw *d = NULL; | |||
Fnt *usedfont, *curfont, *nextfont; | |||
size_t i, len; | |||
int utf8strlen, utf8charlen, render = x || y || w || h; | |||
long utf8codepoint = 0; | |||
const char *utf8str; | |||
FcCharSet *fccharset; | |||
FcPattern *fcpattern; | |||
FcPattern *match; | |||
XftResult result; | |||
int charexists = 0; | |||
if (!drw || (render && !drw->scheme) || !text || !drw->fonts) | |||
return 0; | |||
if (!render) { | |||
w = ~w; | |||
} else { | |||
XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel); | |||
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); | |||
d = XftDrawCreate(drw->dpy, drw->drawable, | |||
DefaultVisual(drw->dpy, drw->screen), | |||
DefaultColormap(drw->dpy, drw->screen)); | |||
x += lpad; | |||
w -= lpad; | |||
} | |||
usedfont = drw->fonts; | |||
while (1) { | |||
utf8strlen = 0; | |||
utf8str = text; | |||
nextfont = NULL; | |||
while (*text) { | |||
utf8charlen = utf8decode(text, &utf8codepoint, UTF_SIZ); | |||
for (curfont = drw->fonts; curfont; curfont = curfont->next) { | |||
charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint); | |||
if (charexists) { | |||
if (curfont == usedfont) { | |||
utf8strlen += utf8charlen; | |||
text += utf8charlen; | |||
} else { | |||
nextfont = curfont; | |||
} | |||
break; | |||
} | |||
} | |||
if (!charexists || nextfont) | |||
break; | |||
else | |||
charexists = 0; | |||
} | |||
if (utf8strlen) { | |||
drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL); | |||
/* shorten text if necessary */ | |||
for (len = MIN(utf8strlen, sizeof(buf) - 1); len && ew > w; len--) | |||
drw_font_getexts(usedfont, utf8str, len, &ew, NULL); | |||
if (len) { | |||
memcpy(buf, utf8str, len); | |||
buf[len] = '\0'; | |||
if (len < utf8strlen) | |||
for (i = len; i && i > len - 3; buf[--i] = '.') | |||
; /* NOP */ | |||
if (render) { | |||
ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent; | |||
XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg], | |||
usedfont->xfont, x, ty, (XftChar8 *)buf, len); | |||
} | |||
x += ew; | |||
w -= ew; | |||
} | |||
} | |||
if (!*text) { | |||
break; | |||
} else if (nextfont) { | |||
charexists = 0; | |||
usedfont = nextfont; | |||
} else { | |||
/* Regardless of whether or not a fallback font is found, the | |||
* character must be drawn. */ | |||
charexists = 1; | |||
fccharset = FcCharSetCreate(); | |||
FcCharSetAddChar(fccharset, utf8codepoint); | |||
if (!drw->fonts->pattern) { | |||
/* Refer to the comment in xfont_create for more information. */ | |||
die("the first font in the cache must be loaded from a font string."); | |||
} | |||
fcpattern = FcPatternDuplicate(drw->fonts->pattern); | |||
FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset); | |||
FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue); | |||
FcPatternAddBool(fcpattern, FC_COLOR, FcFalse); | |||
FcConfigSubstitute(NULL, fcpattern, FcMatchPattern); | |||
FcDefaultSubstitute(fcpattern); | |||
match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result); | |||
FcCharSetDestroy(fccharset); | |||
FcPatternDestroy(fcpattern); | |||
if (match) { | |||
usedfont = xfont_create(drw, NULL, match); | |||
if (usedfont && XftCharExists(drw->dpy, usedfont->xfont, utf8codepoint)) { | |||
for (curfont = drw->fonts; curfont->next; curfont = curfont->next) | |||
; /* NOP */ | |||
curfont->next = usedfont; | |||
} else { | |||
xfont_free(usedfont); | |||
usedfont = drw->fonts; | |||
} | |||
} | |||
} | |||
} | |||
if (d) | |||
XftDrawDestroy(d); | |||
return x + (render ? w : 0); | |||
} | |||
void | |||
drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) | |||
{ | |||
if (!drw) | |||
return; | |||
XCopyArea(drw->dpy, drw->drawable, win, drw->gc, x, y, w, h, x, y); | |||
XSync(drw->dpy, False); | |||
} | |||
unsigned int | |||
drw_fontset_getwidth(Drw *drw, const char *text) | |||
{ | |||
if (!drw || !drw->fonts || !text) | |||
return 0; | |||
return drw_text(drw, 0, 0, 0, 0, 0, text, 0); | |||
} | |||
void | |||
drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h) | |||
{ | |||
XGlyphInfo ext; | |||
if (!font || !text) | |||
return; | |||
XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext); | |||
if (w) | |||
*w = ext.xOff; | |||
if (h) | |||
*h = font->h; | |||
} | |||
Cur * | |||
drw_cur_create(Drw *drw, int shape) | |||
{ | |||
Cur *cur; | |||
if (!drw || !(cur = ecalloc(1, sizeof(Cur)))) | |||
return NULL; | |||
cur->cursor = XCreateFontCursor(drw->dpy, shape); | |||
return cur; | |||
} | |||
void | |||
drw_cur_free(Drw *drw, Cur *cursor) | |||
{ | |||
if (!cursor) | |||
return; | |||
XFreeCursor(drw->dpy, cursor->cursor); | |||
free(cursor); | |||
} |
@ -0,0 +1,57 @@ | |||
/* See LICENSE file for copyright and license details. */ | |||
typedef struct { | |||
Cursor cursor; | |||
} Cur; | |||
typedef struct Fnt { | |||
Display *dpy; | |||
unsigned int h; | |||
XftFont *xfont; | |||
FcPattern *pattern; | |||
struct Fnt *next; | |||
} Fnt; | |||
enum { ColFg, ColBg }; /* Clr scheme index */ | |||
typedef XftColor Clr; | |||
typedef struct { | |||
unsigned int w, h; | |||
Display *dpy; | |||
int screen; | |||
Window root; | |||
Drawable drawable; | |||
GC gc; | |||
Clr *scheme; | |||
Fnt *fonts; | |||
} Drw; | |||
/* Drawable abstraction */ | |||
Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h); | |||
void drw_resize(Drw *drw, unsigned int w, unsigned int h); | |||
void drw_free(Drw *drw); | |||
/* Fnt abstraction */ | |||
Fnt *drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount); | |||
void drw_fontset_free(Fnt* set); | |||
unsigned int drw_fontset_getwidth(Drw *drw, const char *text); | |||
void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h); | |||
/* Colorscheme abstraction */ | |||
void drw_clr_create(Drw *drw, Clr *dest, const char *clrname); | |||
Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount); | |||
/* Cursor abstraction */ | |||
Cur *drw_cur_create(Drw *drw, int shape); | |||
void drw_cur_free(Drw *drw, Cur *cursor); | |||
/* Drawing context manipulation */ | |||
void drw_setfontset(Drw *drw, Fnt *set); | |||
void drw_setscheme(Drw *drw, Clr *scm); | |||
/* Drawing functions */ | |||
void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert); | |||
int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert); | |||
/* Map functions */ | |||
void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h); |
@ -0,0 +1,90 @@ | |||
.TH STEST 1 dmenu\-VERSION | |||
.SH NAME | |||
stest \- filter a list of files by properties | |||
.SH SYNOPSIS | |||
.B stest | |||
.RB [ -abcdefghlpqrsuwx ] | |||
.RB [ -n | |||
.IR file ] | |||
.RB [ -o | |||
.IR file ] | |||
.RI [ file ...] | |||
.SH DESCRIPTION | |||
.B stest | |||
takes a list of files and filters by the files' properties, analogous to | |||
.IR test (1). | |||
Files which pass all tests are printed to stdout. If no files are given, stest | |||
reads files from stdin. | |||
.SH OPTIONS | |||
.TP | |||
.B \-a | |||
Test hidden files. | |||
.TP | |||
.B \-b | |||
Test that files are block specials. | |||
.TP | |||
.B \-c | |||
Test that files are character specials. | |||
.TP | |||
.B \-d | |||
Test that files are directories. | |||
.TP | |||
.B \-e | |||
Test that files exist. | |||
.TP | |||
.B \-f | |||
Test that files are regular files. | |||
.TP | |||
.B \-g | |||
Test that files have their set-group-ID flag set. | |||
.TP | |||
.B \-h | |||
Test that files are symbolic links. | |||
.TP | |||
.B \-l | |||
Test the contents of a directory given as an argument. | |||
.TP | |||
.BI \-n " file" | |||
Test that files are newer than | |||
.IR file . | |||
.TP | |||
.BI \-o " file" | |||
Test that files are older than | |||
.IR file . | |||
.TP | |||
.B \-p | |||
Test that files are named pipes. | |||
.TP | |||
.B \-q | |||
No files are printed, only the exit status is returned. | |||
.TP | |||
.B \-r | |||
Test that files are readable. | |||
.TP | |||
.B \-s | |||
Test that files are not empty. | |||
.TP | |||
.B \-u | |||
Test that files have their set-user-ID flag set. | |||
.TP | |||
.B \-v | |||
Invert the sense of tests, only failing files pass. | |||
.TP | |||
.B \-w | |||
Test that files are writable. | |||
.TP | |||
.B \-x | |||
Test that files are executable. | |||
.SH EXIT STATUS | |||
.TP | |||
.B 0 | |||
At least one file passed all tests. | |||
.TP | |||
.B 1 | |||
No files passed all tests. | |||
.TP | |||
.B 2 | |||
An error occurred. | |||
.SH SEE ALSO | |||
.IR dmenu (1), | |||
.IR test (1) |
@ -0,0 +1,109 @@ | |||
/* See LICENSE file for copyright and license details. */ | |||
#include <sys/stat.h> | |||
#include <dirent.h> | |||
#include <limits.h> | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include <string.h> | |||
#include <unistd.h> | |||
#include "arg.h" | |||
char *argv0; | |||
#define FLAG(x) (flag[(x)-'a']) | |||
static void test(const char *, const char *); | |||
static void usage(void); | |||
static int match = 0; | |||
static int flag[26]; | |||
static struct stat old, new; | |||
static void | |||
test(const char *path, const char *name) | |||
{ | |||
struct stat st, ln; | |||
if ((!stat(path, &st) && (FLAG('a') || name[0] != '.') /* hidden files */ | |||
&& (!FLAG('b') || S_ISBLK(st.st_mode)) /* block special */ | |||
&& (!FLAG('c') || S_ISCHR(st.st_mode)) /* character special */ | |||
&& (!FLAG('d') || S_ISDIR(st.st_mode)) /* directory */ | |||
&& (!FLAG('e') || access(path, F_OK) == 0) /* exists */ | |||
&& (!FLAG('f') || S_ISREG(st.st_mode)) /* regular file */ | |||
&& (!FLAG('g') || st.st_mode & S_ISGID) /* set-group-id flag */ | |||
&& (!FLAG('h') || (!lstat(path, &ln) && S_ISLNK(ln.st_mode))) /* symbolic link */ | |||
&& (!FLAG('n') || st.st_mtime > new.st_mtime) /* newer than file */ | |||
&& (!FLAG('o') || st.st_mtime < old.st_mtime) /* older than file */ | |||
&& (!FLAG('p') || S_ISFIFO(st.st_mode)) /* named pipe */ | |||
&& (!FLAG('r') || access(path, R_OK) == 0) /* readable */ | |||
&& (!FLAG('s') || st.st_size > 0) /* not empty */ | |||
&& (!FLAG('u') || st.st_mode & S_ISUID) /* set-user-id flag */ | |||
&& (!FLAG('w') || access(path, W_OK) == 0) /* writable */ | |||
&& (!FLAG('x') || access(path, X_OK) == 0)) != FLAG('v')) { /* executable */ | |||
if (FLAG('q')) | |||
exit(0); | |||
match = 1; | |||
puts(name); | |||
} | |||
} | |||
static void | |||
usage(void) | |||
{ | |||
fprintf(stderr, "usage: %s [-abcdefghlpqrsuvwx] " | |||
"[-n file] [-o file] [file...]\n", argv0); | |||
exit(2); /* like test(1) return > 1 on error */ | |||
} | |||
int | |||
main(int argc, char *argv[]) | |||
{ | |||
struct dirent *d; | |||
char path[PATH_MAX], *line = NULL, *file; | |||
size_t linesiz = 0; | |||
ssize_t n; | |||
DIR *dir; | |||
int r; | |||
ARGBEGIN { | |||
case 'n': /* newer than file */ | |||
case 'o': /* older than file */ | |||
file = EARGF(usage()); | |||
if (!(FLAG(ARGC()) = !stat(file, (ARGC() == 'n' ? &new : &old)))) | |||
perror(file); | |||
break; | |||
default: | |||
/* miscellaneous operators */ | |||
if (strchr("abcdefghlpqrsuvwx", ARGC())) | |||
FLAG(ARGC()) = 1; | |||
else | |||
usage(); /* unknown flag */ | |||
} ARGEND; | |||
if (!argc) { | |||
/* read list from stdin */ | |||
while ((n = getline(&line, &linesiz, stdin)) > 0) { | |||
if (n && line[n - 1] == '\n') | |||
line[n - 1] = '\0'; | |||
test(line, line); | |||
} | |||
free(line); | |||
} else { | |||
for (; argc; argc--, argv++) { | |||
if (FLAG('l') && (dir = opendir(*argv))) { | |||
/* test directory contents */ | |||
while ((d = readdir(dir))) { | |||
r = snprintf(path, sizeof path, "%s/%s", | |||
*argv, d->d_name); | |||
if (r >= 0 && (size_t)r < sizeof path) | |||
test(path, d->d_name); | |||
} | |||
closedir(dir); | |||
} else { | |||
test(*argv, *argv); | |||
} | |||
} | |||
} | |||
return match ? 0 : 1; | |||
} |
@ -0,0 +1,35 @@ | |||
/* See LICENSE file for copyright and license details. */ | |||
#include <stdarg.h> | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include <string.h> | |||
#include "util.h" | |||
void * | |||
ecalloc(size_t nmemb, size_t size) | |||
{ | |||
void *p; | |||
if (!(p = calloc(nmemb, size))) | |||
die("calloc:"); | |||
return p; | |||
} | |||
void | |||
die(const char *fmt, ...) { | |||
va_list ap; | |||
va_start(ap, fmt); | |||
vfprintf(stderr, fmt, ap); | |||
va_end(ap); | |||
if (fmt[0] && fmt[strlen(fmt)-1] == ':') { | |||
fputc(' ', stderr); | |||
perror(NULL); | |||
} else { | |||
fputc('\n', stderr); | |||
} | |||
exit(1); | |||
} |
@ -0,0 +1,8 @@ | |||
/* See LICENSE file for copyright and license details. */ | |||
#define MAX(A, B) ((A) > (B) ? (A) : (B)) | |||
#define MIN(A, B) ((A) < (B) ? (A) : (B)) | |||
#define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B)) | |||
void die(const char *fmt, ...); | |||
void *ecalloc(size_t nmemb, size_t size); |
@ -1,48 +0,0 @@ | |||
dwm - dynamic window manager | |||
============================ | |||
dwm is an extremely fast, small, and dynamic window manager for X. | |||
Requirements | |||
------------ | |||
In order to build dwm you need the Xlib header files. | |||
Installation | |||
------------ | |||
Edit config.mk to match your local setup (dwm is installed into | |||
the /usr/local namespace by default). | |||
Afterwards enter the following command to build and install dwm (if | |||
necessary as root): | |||
make clean install | |||
Running dwm | |||
----------- | |||
Add the following line to your .xinitrc to start dwm using startx: | |||
exec dwm | |||
In order to connect dwm to a specific display, make sure that | |||
the DISPLAY environment variable is set correctly, e.g.: | |||
DISPLAY=foo.bar:1 exec dwm | |||
(This will start dwm on display :1 of the host foo.bar.) | |||
In order to display status info in the bar, you can do something | |||
like this in your .xinitrc: | |||
while xsetroot -name "`date` `uptime | sed 's/.*,//'`" | |||
do | |||
sleep 1 | |||
done & | |||
exec dwm | |||
Configuration | |||
------------- | |||
The configuration of dwm is done by creating a custom config.h | |||
and (re)compiling the source code. |
@ -1,690 +0,0 @@ | |||
This dwm 6.2 (bb2e72, 2020-07-08) side project has a different take on dwm patching. It uses preprocessor directives to decide whether or not to include a patch during build time. Essentially this means that this build, for better or worse, contains both the patched _and_ the original code. The aim being that you can select which patches to include and the build will contain that code and nothing more. Due to the complexity of some of the patches dwm-flexipatch has diverged from mainstream dwm by making some core patches non-optional for maintenance reasons. For the classic dwm-flexipatch build refer to branch [dwm-flexipatch-1.0](https://github.com/bakkeby/dwm-flexipatch/tree/dwm-flexipatch-1.0). | |||
For example to include the `alpha` patch then you would only need to flip this setting from 0 to 1 in [patches.h](https://github.com/bakkeby/dwm-flexipatch/blob/master/patches.def.h): | |||
```c | |||
#define BAR_ALPHA_PATCH 1 | |||
``` | |||
So if you have ever been curious about trying out dwm, but have been discouraged by manual patching, then this may be a good starting point to see what a "fully fledged" dwm can look like. Want to try out the `pertag` patch? Just flip a config and recompile. Once you have found out what works for you and what doesn't then you should be in a better position to choose patches should you want to start patching from scratch. | |||
Alternatively if you have found the patches you want, but don't want the rest of the flexipatch entanglement on your plate then you may want to have a look at [flexipatch-finalizer](https://github.com/bakkeby/flexipatch-finalizer); a custom pre-processor tool that removes all the unused flexipatch code leaving you with a build that contains the patches you selected. | |||
Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on the dwm window manager, how to install it and how it works. | |||
--- | |||
### Changelog: | |||
2021-02-11 - Added the riodraw and focusdir patches | |||
2021-01-22 - Added the placemouse patch | |||
2021-01-02 - Added the Layoutmenu patch | |||
2020-10-26 - Added the \_NET\_CLIENT\_LIST\_STACKING patch | |||
2020-09-29 - Added the on\_empty\_keys patch (ported from InstantOS) | |||
2020-09-28 - Added the \_IS\_FLOATING patch (embedded in the EWMHTAGS patch) | |||
2020-09-18 - Added the nomodbuttons patch allowing for toggleable mouse button bindings that have no modifiers | |||
2020-09-10 - Added the anybar patch (with experimental support for dwm bar(s) + anybar) | |||
2020-09-09 - Added the bar border patch | |||
2020-09-08 - Added ipc v1.5.5 patch | |||
2020-09-07 - Scratchpads improvement (multi-monitor support) | |||
2020-09-05 - Assortment of fullscreen improvements | |||
2020-08-27 - Added aspectresize patch | |||
2020-08-25 - Unified tag icon handling while adding support for different icons per monitor. Added alttagsdecoration patch. | |||
2020-08-22 - Added logic to auto-hide bars if nothing is drawn on them (e.g. for standalone bars that only show certain clients). Added clientindicators patch and unified indicator code. Simplified Pango integration by settling on common function signatures. | |||
2020-08-21 - Simplification of color configuration; settling on a set of color schemes that is shared between multiple patches (urgentborder, floatborder and titlecolor patches made non-optional) | |||
2020-08-20 - Added experimental flexwintitle patch based on bartabgroups | |||
2020-08-13 - Added bartabgroups patch | |||
2020-08-11 - Added decoration hints and focusmaster patches | |||
2020-08-10 - Added cool autostart, insets and steam patches | |||
2020-08-02 - Added reorganizetags patch | |||
2020-07-19 - Added barmodules patch - making extrabar, leftlayout, staticstatus and statusallmons patches redundant, added powerline patch | |||
2020-07-18 - **Note**: Up until now building dwm-flexipath without any patches selected would have given you something more or less identical with mainstream dwm. In order to reduce complexity when it comes to maintainance future versions of dwm-flexipatch may diverge from this by making some patches non-optional. For the classic dwm-flexipatch and its many patch integration hints refer to branch [dwm-flexipatch-1.0](https://github.com/bakkeby/dwm-flexipatch/tree/dwm-flexipatch-1.0) which will be subject to bug fixes and mainstream dwm updates as far as feasible. | |||
2020-07-05 - Extrabar compatibility improvements (staticstatus, status2d, dwmblocks) and fix for systray randomly causing dwm to crash when first systray application starts | |||
2020-06-24 - Added resizepoint, statusbutton and sendmon_keepfocus patches | |||
2020-06-21 - Added floatpos and bar_height patches | |||
2020-06-19 - Added tagothermonitor patch | |||
2020-06-15 - Added sizehints patch | |||
2020-06-14 - Added RULE macro to replace rules setup making the default config less of an abomination and making it simpler to include new rules based patches | |||
2020-06-11 - Added the pango patch | |||
2020-06-10 - Added the staticstatus patch | |||
2020-05-31 - Added the keymodes patch | |||
2020-05-29 - Added the color emoji patch | |||
2020-05-26 - Added the status2d patch (with alpha, systray, statuspadding and dwmblocks compatibility, no statuscolors or extrabar compatibility) | |||
2020-05-21 - Added the moveplace and moveresize patches | |||
2020-05-03 - Added the shiftviewclients patch and the no transparent borders patch which removes opacity from window borders when the alpha patch is not used | |||
2020-05-02 - Added dwmblocks patch | |||
2020-04-27 - Upgraded the tagmonfixfs patch to better support moving fullscreen windows to adjacent monitors | |||
2020-04-26 - Expanded monitor rules patch to include nmaster, showbar and topbar options | |||
2020-04-23 - Improved swallow and switchtag compatibility | |||
2020-04-16 - Upgraded the scratchpad patch to the multiple scratchpads patch \[[ref](https://lists.suckless.org/hackers/2004/17205.html)\]. Updated the statuscolors patch with the width computation fix \[[ref](https://lists.suckless.org/hackers/2004/17207.html)\]. | |||
2020-04-13 - Added statuscmd patch | |||
2020-03-31 - Added the rounded corners patch | |||
2020-03-27 - Revamped the dragmfact patch to support both horizontal and vertical layout splits as well as centered master variants | |||
2020-03-25 - Added dragcfact patch | |||
2020-03-23 - Added stacker patch | |||
2020-03-21 - Reworked a series of layouts to re-allocate remaining pixels following an even (or cfacts) split with the aim of presenting a pixel perfect layout. This affects the following layouts: tile, bstack, bstackhoriz, centered master, centered floating master, columns, deck, and corresponding flextile-deluxe layouts | |||
2020-02-11 - Added swaptags and vtcolor patches | |||
2020-02-09 - Added alternative scratchpad patch | |||
2020-02-02 - Added fsignal and transferall patches | |||
2020-01-29 - Added swapfocus and shiftview patches | |||
2020-01-26 - Added transfer patch | |||
2020-01-24 - Added barpadding patch (incl. statusallmons, statuspadding, statuscolors, systray, alpha, holdbar and extrabar patch compatibility). Moved patches.h to patches.def.h to mimic the config pattern of having default and personal settings. | |||
2020-01-17 - Added inplacerotate patch | |||
2019-12-15 - Updated dragmfact patch to include fix patch to make it work with multiple monitors | |||
2019-11-26 - Added dmenumatchtop patch, added improvements to the switchtag patch based on ideas from the switchtotag patch | |||
2019-11-21 - Added fakefullscreenclient patch | |||
2019-10-24 - Added dragmfact, extrabar, exresize and nodmenu patches | |||
2019-10-22 - Added ispermanent and swallow patches | |||
2019-10-16 - Introduced [flexipatch-finalizer](https://github.com/bakkeby/flexipatch-finalizer) | |||
2019-10-11 - Added the patch to ignore Xft errors when drawing text in the status bar | |||
2019-10-10 - Added mpdcontrol, scratchpad and spawn_cwd cpatches | |||
2019-10-08 - Added columns layout and fakefullscreen patch | |||
2019-10-07 - Added sortscreens and dwmc patches, fixed minor cross-compatibility issues for combo, holdbar, leftlayout, hidevacanttags, taggrid and activetagindicatorbar | |||
2019-10-06 - Added statuscolors and statusallmons patches, fixed minor cross-compatibility issues for killunsel, fullscreen, noborder, tagintostack patches | |||
2019-10-05 - Added killunsel, taggrid, hidevacanttags and cmdcustomize patches | |||
2019-10-04 - Added maximize, movestack, monoclesymbol, noborder, tagall and tagintostack patches | |||
2019-10-03 - Added onlyquitonempty and switchcol patches | |||
2019-10-02 - Added restartsig, emptyview, focusurgent and focusadjacenttag patches | |||
2019-10-01 - Added leftlayout, fullscreen, holdbar and unfloatvisible patches | |||
2019-09-30 - Replaced flextile with flextile-deluxe, refactored monitor rules to support predetermined layouts per tag | |||
2019-09-15 - Added focusonclick, xrdb, viewontag, urgentborder and winview patches | |||
2019-09-14 - Added setborderpx, selfrestart and push (no master variant), sticky and warp patches | |||
2019-09-13 - Added titlecolor and push patches | |||
2019-09-12 - Added activetagindicatorbar, alwaysfullscreen and autoresize patches | |||
2019-09-11 - Added monitor rules, combo and ewmhtags patches | |||
2019-09-10 - Minor tweaks to awesomebar patch (incl. alpha and systray compatibility). Added floatbordercolor patch. | |||
2019-09-09 - Added deck, fibonacci (dwindle and spiral), gridmode, gapplessgrid, horizgrid, nrowgrid, centeredmaster and flextile layouts. Added alternativetags and awesomebar patches. | |||
2019-09-08 - Added cfacts and vanitygaps patches, added bstack and bstackhoriz layouts | |||
2019-09-07 - Added cyclelayouts, resizecorners, rotatestack, savefloats, statuspadding, switchtag, center and windowrolerule patches | |||
2019-09-06 - Added attachabove, attachaside, attachbelow, attachbottom, autostart, fancybar, focusonnetactive and losefullscreen patches | |||
2019-09-05 - Alpha, systray, togglefullscreen, tagallmon, tagmonfixfs, tagswapmon, pertag and zoomswap patches added | |||
### Patches included: | |||
- [activetagindicatorbar](https://dwm.suckless.org/patches/activetagindicatorbar/) | |||
- this patch changes the rectangle indicating if a tag is used by a client into a bar above the tag name | |||
- [alpha](https://dwm.suckless.org/patches/alpha/) | |||
- adds transparency for the status bar | |||
- [alternativetags](https://dwm.suckless.org/patches/alternativetags/) | |||
- adds alternative tags which can be toggled on the fly for the sole purpose of providing visual aid | |||
- [alttagsdecoration](https://dwm.suckless.org/patches/alttagsdecoration/) | |||
- provides the ability to use alternative text for tags which contain at least one window | |||
- [alwaysfullscreen](https://dwm.suckless.org/patches/alwaysfullscreen/) | |||
- prevents the focus to drift from the active fullscreen client when using focusstack\(\) | |||
- [anybar](https://dwm.suckless.org/patches/anybar/) | |||
- enables dwm to manage external status bars such as lemonbar and polybar | |||
- dwm treats the external bar as it would its own, so all regular dwm commands such as togglebar affect the external bar in the same way | |||
- [aspectresize](https://dwm.suckless.org/patches/aspectresize/) | |||
- allows windows to be resized with its aspect ratio remaining constant | |||
- [attachabove](https://dwm.suckless.org/patches/attachabove/) | |||
- new windows are placed above selected client | |||
- [attachaside](https://dwm.suckless.org/patches/attachaside/) | |||
- new windows are placed on top of the stack | |||
- [attachbelow](https://dwm.suckless.org/patches/attachbelow/) | |||
- new windows are placed below selected client | |||
- [attachbottom](https://dwm.suckless.org/patches/attachbottom/) | |||
- new windows are placed at the bottom of the stack | |||
- [autoresize](https://dwm.suckless.org/patches/autoresize/) | |||
- by default, windows that are not visible when requesting a resize/move will not get resized/moved, with this patch, however, they will | |||
- [autostart](https://dwm.suckless.org/patches/autostart/) | |||
- makes dwm run `~/.dwm/autostart_blocking.sh` and `~/.dwm/autostart.sh &` on startup | |||
- [awesomebar](https://dwm.suckless.org/patches/awesomebar/) | |||
- enhanced taskbar that allows focus / hiding / unhiding of windows by clicking on the status bar | |||
- [bar_border](https://codemadness.org/paste/dwm-border-bar.patch) | |||
- adds a border around the bar similarly to how client windows have borders | |||
- [bar_height](https://dwm.suckless.org/patches/bar_height/) | |||
- allows the bar height to be explicitly set rather than being derived from font | |||
- [barmodules](https://github.com/bakkeby/patches/wiki/barmodules/) | |||
- splits the dwm bar into modules allowing for re-arrangement of the bar and easier integration for new features | |||
- [barpadding](https://dwm.suckless.org/patches/barpadding/) | |||
- adds vertical and horizontal space between the statusbar and the edge of the screen | |||
- [bartabgroups](https://dwm.suckless.org/patches/bartabgroups/) | |||
- turns the titlebar area into a mfact-respecting tab-bar showing each client's title | |||
- [center](https://dwm.suckless.org/patches/center/) | |||
- adds an iscentered rule to automatically center clients on the current monitor | |||
- [cfacts](https://dwm.suckless.org/patches/cfacts/) | |||
- the cfacts patch provides the ability to assign different weights to clients in their respective stack in tiled layout | |||
- [clientindicators](https://dwm.suckless.org/patches/clientindicators/) | |||
- draws a dot indicator overlayed on each tag icon for each client | |||
- the selected client is drawn as a larger horizontal line | |||
- [cmdcustomize](https://dwm.suckless.org/patches/cmdcustomize/) | |||
- allows color attributes to be set through the command line | |||
- [colorbar](https://dwm.suckless.org/patches/colorbar/) | |||
- lets you change the foreground and background color of every statusbar element | |||
- color_emoji | |||
- enables color emoji in dmenu by removing a workaround for a BadLength error in the Xft library when color glyphs are used | |||
- enabling this will crash dwm on encountering such glyphs unless you also have an updated Xft library that can handle them | |||
- [combo](https://dwm.suckless.org/patches/combo/) | |||
- allows you to select multiple tags by pressing all the right keys as a combo, e.g. hold MOD and press and hold 1 and 3 together to view those two tags | |||
- [cool_autostart](https://dwm.suckless.org/patches/cool_autostart/) | |||
- allows dwm to execute commands from an array in the config.h file | |||
- when dwm exits all processes from the autostart array will be killed automatically | |||
- [cyclelayouts](https://dwm.suckless.org/patches/cyclelayouts/) | |||
- lets you cycle through all your layouts | |||
- [decoration_hints](https://dwm.suckless.org/patches/decoration_hints/) | |||
- make dwm respect \_MOTIF\_WM\_HINTS property, and not draw borders around windows requesting for it | |||
- some applications use this property to notify window managers to not draw window decorations | |||
- not respecting this property leads to issues with applications that draw their own borders, like chromium (with "Use system title bar and borders" turned off) or vlc in fullscreen mode | |||
- [dmenumatchtop](https://dwm.suckless.org/patches/dmenumatchtop) | |||
- updates the position of dmenu to match that of the bar | |||
- i.e. if topbar is 0 then dmenu will appear at the bottom and if 1 then dmenu will appear at the top | |||
- [dragcfact](https://github.com/bakkeby/patches/wiki/dragcfact/) | |||
- lets you resize clients' size (i.e. modify cfact) by holding modkey + shift + right-click and dragging the mouse | |||
- [dragmfact](https://github.com/bakkeby/patches/wiki/dragmfact/) | |||
- lets you resize the split in layouts (i.e. modify mfact) by holding the modkey + shift + left-click and dragging the mouse | |||
- this is a bespoke patch that supports vertical and horizontal layout splits as well as centered master variants | |||
- [dwmblocks](https://gist.github.com/danbyl/54f7c1d57fc6507242a95b71c3d8fdea) | |||
- signal integration to use dwm with a patched [dwmblocks](https://github.com/torrinfail/dwmblocks) | |||
- combined with the statuscmd patch this gives a clickable statusbar | |||
- [dwmc](http://dwm.suckless.org/patches/dwmc/) | |||
- a simple dwmc client using a fork of fsignal to communicate with dwm | |||
- [emptyview](https://dwm.suckless.org/patches/emptyview/) | |||
- allows no tag at all to be selected | |||
- dwm will start with no tag selected and when a client with no tag rule is started and no tag is selected then it will be opened on the first tag | |||
- [ewmhtags](https://dwm.suckless.org/patches/ewmhtags/) | |||
- adds EWMH support for \_NET_NUMBER_OF_DESKTOPS, \_NET_CURRENT_DESKTOP, \_NET_DESKTOP_NAMES and \_NET_DESKTOP_VIEWPORT, which allows for compatibility with other bars and programs that request workspace information, e.g. polybar's xworkspaces module | |||
- [exresize](https://dwm.suckless.org/patches/exresize/) | |||
- this patch allows the user to change size and placement of floating windows using only the keyboard | |||
- it also allows for temporary vertical and horizontal extension of windows similar to other WMs fill command | |||
- [~extrabar~](https://dwm.suckless.org/patches/extrabar/) | |||
- ~enables an extra status bar in dwm in a similar manner to the dualstatus patch~ | |||
- ~if the primary status is at the top via topbar then the extra status bar will be placed at the bottom and vice versa~ | |||
- extrastatus | |||
- formerly extrabar - now only splits the status into to statuses by using a status separator | |||
- [fakefullscreen](https://dwm.suckless.org/patches/fakefullscreen/) | |||
- only allow clients to "fullscreen" into the space currently given to them | |||
- as an example, this will allow you to view a fullscreen video in your browser on one half of the screen, while having the other half available for other tasks | |||
- [fakefullscreenclient](https://github.com/bakkeby/patches/wiki/fakefullscreenclient/) | |||
- similarly to the fakefullscreen patch this patch only allows clients to "fullscreen" into the space currently given to them | |||
- as an example, this will allow you to view a fullscreen video in your browser on one half of the screen, while having the other half available for other tasks | |||
- the "twist" with this patch is that fake fullscreen can be toggled on a per client basis rather than applying to all clients globally | |||
- [fancybar](https://dwm.suckless.org/patches/fancybar/) | |||
- shows the titles of all visible windows in the status bar | |||
- flexwintitle | |||
- based on the bartabgroups patch, this is a layout aware barmodules module for handling window titles intended to be used with flextile-deluxe | |||
- [~floatbordercolor~](https://dwm.suckless.org/patches/float_border_color/) | |||
- ~this patch allows a different border color to be chosen for floating windows~ | |||
- [floatpos](https://github.com/bakkeby/patches/wiki/floatpos/) | |||
- adds a float rule allowing the size and position of floating windows to be specified | |||
- control the size and position of floating windows similar to exresize, moveresize, moveplace patches | |||
- specify size and position using absolute, relative or fixed co-ordinates or | |||
- position floating windows in a grid-like manner | |||
- [focusadjacenttag](https://dwm.suckless.org/patches/focusadjacenttag/) | |||
- provides the ability to focus the tag on the immediate left or right of the currently focused tag | |||
- it also allows to send the focused window either on the left or the right tag | |||
- [focusdir](https://github.com/bakkeby/patches/wiki/focusdir) | |||
- allows focusing on clients based on direction (up, down, left, right) instead of client order | |||
- [focusmaster](https://dwm.suckless.org/patches/focusmaster/) | |||
- a simple patch that just puts focus back to the master client | |||
- [focusonclick](https://dwm.suckless.org/patches/focusonclick/) | |||
- this patch makes you switch focus only by mouse click and not sloppy (focus follows mouse pointer) | |||
- [focusonnetactive](https://dwm.suckless.org/patches/focusonnetactive/) | |||
- by default, dwm responds to \_NET_ACTIVE_WINDOW client messages by setting the urgency bit on the named window | |||
- this patch activates the window instead | |||
- [focusurgent](https://dwm.suckless.org/patches/focusurgent/) | |||
- adds a keyboard shortcut to select the next window having the urgent flag regardless of the tag it is on | |||
- [fsignal](https://dwm.suckless.org/patches/fsignal/) | |||
- send "fake signals" to dwm for handling, using xsetroot | |||
- this will not conflict with the status bar, which also is managed using xsetroot | |||
- [fullscreen](https://dwm.suckless.org/patches/fullscreen/) | |||
- applies the monocle layout with the focused client on top and hides the bar | |||
- when pressed again it shows the bar and restores the layout that was active before going fullscreen | |||
- [hidevacanttags](https://dwm.suckless.org/patches/hide_vacant_tags/) | |||
- prevents dwm from drawing tags with no clients (i.e. vacant) on the bar | |||
- [holdbar](http://dwm.suckless.org/patches/holdbar/) | |||
- with this patch dwm's built-in status bar is only shown when HOLDKEY is pressed | |||
- additionally the bar will now overlay the display | |||
- [ignore-xft-errors-when-drawing-text](https://groups.google.com/forum/m/#!topic/wmii/7bncCahYIww) | |||
- sometimes dwm crashes when it cannot render some glyphs in window titles (usually emoji) | |||
- this patch is essentially a hack to ignore any errors when drawing text on the status bar and may be removed if a more appropriate solution comes up | |||
- [inplacerotate](https://dwm.suckless.org/patches/inplacerotate/) | |||
- allows rotation of all clients in the master or stack area without affecting the other area | |||
- [insets](https://dwm.suckless.org/patches/insets/) | |||
- lets custom insets from each edge of the screen to be defined | |||
- an example use case would be to make space for an external bar | |||
- [ipc](https://github.com/mihirlad55/dwm-ipc) | |||
- implements inter-process communication through a UNIX socket for dwm | |||
- allows for the window manager to be queried for information, e.g. listen for events such as tag or layout changes, as well as send commands to control the window manager via other programs | |||
- [\_IS\_FLOATING](https://github.com/bakkeby/dwm-flexipatch/issues/50) | |||
- adds the \_IS\_FLOATING xproperty for floating windows | |||
- this can allow for a compositor to handle floating windows differently to tiled windows, e.g. only show shadows on floating windows | |||
- this patch is enabled via the ewmhtags patch | |||
- [ispermanent](https://dwm.suckless.org/patches/ispermanent/) | |||
- adds rule option for clients to avoid accidental termination by killclient for sticky windows | |||
- [keymodes](https://dwm.suckless.org/patches/keymodes/) | |||
- this patch adds key modes (like in vim or emacs) where chains of keyboard shortcuts can be performed | |||
- [~leftlayout~](http://dwm.suckless.org/patches/leftlayout/) | |||
- ~moves the layout symbol in the status bar to the left hand side~ | |||
- [losefullscreen](https://github.com/bakkeby/patches/wiki/losefullscreen/) | |||
- by default in dwm it is possible to make an application fullscreen, then use the focusstack keybindings to focus on other windows beneath the current window | |||
- it is also possible to spawn new windows (e.g. a terminal) that end up getting focus while the previous window remains in fullscreen | |||
- this patch ensures that in such scenarios the previous window loses fullscreen | |||
- [maximize](https://dwm.suckless.org/patches/maximize/) | |||
- adds helper functions for maximizing, horizontally and vertically, floating windows using keybindings | |||
- [mpdcontrol](https://dwm.suckless.org/patches/mpdcontrol/) | |||
- adds keyboard bindings to control MDP (Music Player Daemon) | |||
- [monitorrules](https://github.com/bakkeby/patches/wiki/monitorrules/) | |||
- adds rules per monitor, e.g. have default layouts per monitor | |||
- the use case for this is if the second monitor is vertical (i.e. rotated) then you may want to use a different default layout for this monitor than what is used for the main monitor (for example normal vertical split for main monitor and horizontal split for the second) | |||
- [monoclesymbol](https://dwm.suckless.org/patches/monoclesymbol/) | |||
- always display the the monocle-symbol as defined in config.h if the monocle-layout is activated | |||
- do not display the number of open clients in the current tag | |||
- [moveresize](https://dwm.suckless.org/patches/moveresize/) | |||
- allows you to move and resize dwm's clients using keyboard bindings | |||
- [movestack](https://dwm.suckless.org/patches/movestack/) | |||
- allows you to move clients around in the stack and swap them with the master | |||
- [netclientliststacking](https://github.com/bakkeby/patches/wiki/netclientliststacking) | |||
- adds support for the \_NET\_CLIENT\_LIST\_STACKING atom, needed by certain applications like the Zoom video conferencing application | |||
- [noborder](https://dwm.suckless.org/patches/noborder/) | |||
- removes the border when there is only one window visible | |||
- [nodmenu](https://dwm.suckless.org/patches/nodmenu/) | |||
- enable modifying dmenu in config.def.h which resulted previously in a compilation error because two lines of code hardcode dmenu into dwm | |||
- allows complete removal of dmenu, should you want to do that | |||
- nomodbuttons | |||
- allows for toggleable client button bindings that have no modifiers | |||
- this can, for example, allow you to move or resize using the mouse alone without holding down a modifier key, which can be practical if you have extra buttons on your mouse | |||
- [no_transparent_borders](https://github.com/szatanjl/dwm/commit/1529909466206016f2101457bbf37c67195714c8) | |||
- when terminals have transparency then their borders also become transparent | |||
- this patch ensures that borders have no transparency | |||
- note that this patch is only relevant if you are not using the alpha patch | |||
- [on\_empty\_keys](https://github.com/bakkeby/dwm-flexipatch/issues/51) | |||
- port of InstantVM's on_empty_keys functionality allowing keybindings that apply only when a tag/view is empty | |||
- an example use case is being able to launch applications with first hand keys like "f" to launch firefox | |||
- [onlyquitonempty](https://dwm.suckless.org/patches/onlyquitonempty/) | |||
- makes it so dwm will only exit via quit() if no windows are open (in order to prevent accidental loss of work) | |||
- [pango](https://dwm.suckless.org/patches/pango/) | |||
- adds simple markup for status messages using pango markup | |||
- [pertag](https://dwm.suckless.org/patches/pertag/) | |||
- adds nmaster, mfact, layouts and more per tag rather than per monitor | |||
- [placemouse](https://github.com/bakkeby/patches/wiki/placemouse) | |||
- lets the user change the position of a client in the stack using the mouse. | |||
- [powerline](https://gitlab.com/udiboy1209-suckless/dwm/-/commit/071f5063e8ac4280666828179f92788d893eea40#4b1a539194be7467cefbda22f675a3b7c19ceca7) | |||
- adds drawing of powerline arrows (and diagonal lines) for both the status bar and the tags | |||
- [push](https://dwm.suckless.org/patches/push/) | |||
- this patch provides a way to move clients up and down inside the client list | |||
- [reorganizetags](https://dwm.suckless.org/patches/reorganizetags/) | |||
- shifts all clients per tag to leftmost unoccupied tags | |||
- e.g. if clients A, B, C are tagged on tags 1, 5, 9 respectively, when reorganized they will now be on tag 1, 2, and 3 | |||
- [resizecorners](https://dwm.suckless.org/patches/resizecorners/) | |||
- by default, windows only resize from the bottom right corner | |||
- with this patch the mouse is warped to the nearest corner and you resize from there | |||
- [resizepoint](https://github.com/bakkeby/patches/wiki/resizepoint/) | |||
- practically the same as resizecorners, but the cursor does not warp to any of the window corners | |||
- [restartsig](https://dwm.suckless.org/patches/restartsig/) | |||
- adds a keyboard shortcut to restart dwm or alternatively by using kill -HUP dwmpid | |||
- additionally dwm can quit cleanly by using kill -TERM dwmpid | |||
- [riodraw](https://github.com/bakkeby/patches/wiki/riodraw/) | |||
- adds rio-like drawing to spawn new windows or to resize the selected client (backported from instantWM) | |||
- depends on an external tool slop being installed | |||
- [rotatestack](https://dwm.suckless.org/patches/rotatestack/) | |||
- let's you rotate through the stack using keyboard shortcuts | |||
- [roundedcorners](https://github.com/mitchweaver/suckless/blob/master/dwm/patches/mitch-06-rounded_corners-f04cac6d6e39cd9e3fc4fae526e3d1e8df5e34b2.patch) | |||
- adds rounded corners to client windows | |||
- [savefloats](https://dwm.suckless.org/patches/save_floats/) | |||
- saves size and position of every floating window before it is forced into tiled mode | |||
- if the window is made floating again then the old dimensions will be restored | |||
- [scratchpad](https://dwm.suckless.org/patches/scratchpad/) | |||
- the scratchpad patch allows you to spawn or restore a floating terminal window | |||
- [scratchpad_alt_1](https://github.com/GasparVardanyan/dwm-scratchpad) | |||
- this alternative patch enables a scratchpad feature in dwm similar to the scratchpad feature in i3wm | |||
- [selfrestart](https://dwm.suckless.org/patches/selfrestart/) | |||
- restart dwm without the unnecessary dependency of an external script | |||
- [sendmon_keepfocus](https://github.com/bakkeby/patches/wiki/sendmon_keepfocus/) | |||
- minor patch that allow clients to keep focus when being sent to another monitor | |||
- [setborderpx](https://dwm.suckless.org/patches/setborderpx/) | |||
- this patch allows border pixels to be changed during runtime | |||
- [shiftview](https://github.com/chau-bao-long/dotfiles/blob/master/suckless/dwm/shiftview.diff) | |||
- adds keybindings for left and right circular shift through tags | |||
- also see focusadjacenttag | |||
- [shiftviewclients](https://github.com/bakkeby/patches/wiki/shiftviewclients/) | |||
- variant of the shiftview patch which skips tags that have no clients | |||
- [sizehints](https://dwm.suckless.org/patches/sizehints/) | |||
- makes dwm obey even "soft" sizehints for new clients | |||
- [sortscreens](https://www.mail-archive.com/hackers@suckless.org/msg09400.html) | |||
- this patch aims to address some inconsistencies when it comes to focusmon, tagmon and similar functionality by explicitly sorting screens left to right (or top to bottom in a vertical layout) | |||
- [spawn_cwd](https://dwm.suckless.org/patches/spawn_cwd/) | |||
- spawns programs from currently focused client's working directory | |||
- [stacker](https://dwm.suckless.org/patches/stacker/) | |||
- provides comprehensive utilities for managing the client stack | |||
- [~staticstatus~](https://dwm.suckless.org/patches/staticstatus/) | |||
- ~allows the status text to be fixed to the bar on a specific monitor rather than being drawn on the focused monitor~ | |||
- [status2d](https://dwm.suckless.org/patches/status2d/) | |||
- allows colors and rectangle drawing in the dwm status bar | |||
- [~statusallmons~](https://dwm.suckless.org/patches/statuspadding/) | |||
- ~this patch draws and updates the statusbar on all monitors~ | |||
- [statusbutton](https://dwm.suckless.org/patches/statusbutton/) | |||
- adds a clickable button to the left hand side of the statusbar | |||
- [statuscmd](https://dwm.suckless.org/patches/statuscmd/) | |||
- adds the ability to execute shell commands based on the mouse button and position when clicking the status bar | |||
- [statuscolors](https://dwm.suckless.org/patches/statuscolors/) | |||
- enables colored text in the status bar allowing multiple color combinations for use in the status script | |||
- [statuspadding](https://dwm.suckless.org/patches/statuspadding/) | |||
- adds configuration options for horizontal and vertical padding in the status bar | |||
- [steam](https://github.com/bakkeby/patches/wiki/steam) | |||
- a minor patch that works around the issue of floating Steam windows jumping around the screen when they receive focus | |||
- [sticky](https://dwm.suckless.org/patches/sticky/) | |||
- adds toggleable keyboard shortcut to make a client 'sticky', i.e. visible on all tags | |||
- [swallow](https://dwm.suckless.org/patches/swallow/) | |||
- this patch adds "window swallowing" to dwm as known from Plan 9's windowing system rio | |||
- clients marked with isterminal in config.h swallow a window opened by any child process, e.g. running xclock in a terminal | |||
- closing the xclock window restores the terminal window in the current position | |||
- [swapfocus](https://dwm.suckless.org/patches/swapfocus/) | |||
- this patch depends on the pertag patch and makes it possible to switch focus with a single shortcut (mod-s) instead of having to think if you should use mod-j or mod-k for reaching the previously used window | |||
- [swaptags](https://dwm.suckless.org/patches/swaptags/) | |||
- allows swapping the contents of the currently selected tag with another tag by using keyboard shortcuts | |||
- [switchcol](https://dwm.suckless.org/patches/switchcol/) | |||
- allows you to switch focus between the master and stack columns using a single keybinding | |||
- [switchtag](https://github.com/bakkeby/patches/wiki/switchtag/) | |||
- when an application opens on a specific tab this patch adds the option to also switch to that tag when the application starts | |||
- optionally, the previous view can also be restored when the client is closed | |||
- [systray](https://dwm.suckless.org/patches/systray/) | |||
- adds system tray in the status bar | |||
- [tagall](https://dwm.suckless.org/patches/tagall/) | |||
- adds keyboard shortcuts to move all (or only floating) windows from one tag to another | |||
- [tagallmon](https://github.com/bakkeby/patches/wiki/tagallmon/) | |||
- move all visible windows to an adjacent monitor | |||
- [tagintostack](https://dwm.suckless.org/patches/tagintostack/) | |||
- makes new clients attach into the stack area when you toggle a new tag into view | |||
- this means your master area will remain unchanged when toggling views | |||
- [taggrid](https://dwm.suckless.org/patches/taggrid/) | |||
- adds an option to place tags in rows like in many other window managers | |||
- [tagmonfixfs](https://github.com/bakkeby/patches/wiki/tagmonfixfs/) | |||
- allows moving a fullscreen window to another monitor while remaining in fullscreen | |||
- [tagothermonitor](https://dwm.suckless.org/patches/tagothermonitor/) | |||
- adds functions and keybindings to tag a window to a desired tag on an adjacent monitor | |||
- [tagswapmon](https://github.com/bakkeby/patches/wiki/tagswapmon/) | |||
- swap all visible windows on one monitor with those of an adjacent monitor | |||
- [~titlecolor~](https://dwm.suckless.org/patches/titlecolor/) | |||
- ~adds a new color scheme used by the (selected) window title in the bar~ | |||
- [togglefullscreen](https://github.com/bakkeby/patches/wiki/togglefullscreen/) | |||
- allows you to toggle fullscreen on and off using a single shortcut key | |||
- [transfer](https://dwm.suckless.org/patches/transfer/) | |||
- lets you transfer the currently focused client between the master and stack area while increasing or decreasing the master area (nmaster) accordingly | |||
- [transferall](https://dwm.suckless.org/patches/transfer/) | |||
- lets you transfer all clients between the master and stack area while increasing or decreasing the master area (nmaster) accordingly | |||
- [unfloatvisible](https://dwm.suckless.org/patches/unfloatvisible/) | |||
- resets isfloating on any visible windows that have it set and optionally also applies a layout | |||
- [killunsel](https://dwm.suckless.org/patches/killunsel/) | |||
- kills all visible clients that are not selected (only the selected client will remain) | |||
- [~urgentborder~](https://dwm.suckless.org/patches/urgentborder/) | |||
- ~this patch makes "urgent" windows have different colors~ | |||
- [vanitygaps](https://github.com/bakkeby/patches/blob/master/dwm/dwm-vanitygaps-6.2.diff) | |||
- adds configurable gaps between windows differentiating between outer, inner, horizontal and vertical gaps | |||
- [viewontag](https://dwm.suckless.org/patches/viewontag/) | |||
- follow a window to the tag it is being moved to | |||
- [vtcolor](https://dwm.suckless.org/patches/vtcolors/) | |||
- this patch adds the ability for dwm to read colors from the linux virtual console essentially allowing you to use the same color scheme as your regular tty | |||
- [warp](https://dwm.suckless.org/patches/warp/) | |||
- warps the mouse cursor to the center of the currently focused window or screen when the mouse cursor is (a) on a different screen or (b) on top of a different window | |||
- [windowrolerule](https://github.com/bakkeby/patches/wiki/windowrolerule/) | |||
- sometimes a single application opens different windows depending on the task at hand and this is often reflected in the WM_WINDOW_ROLE(STRING) x property | |||
- this patch adds the role field to the rule configuration so that one can differentiate between, say, Firefox "browser" vs "Preferences" vs "Manager" or Google-chrome "browser" vs "pop-up". | |||
- [winview](http://dwm.suckless.org/patches/winview/) | |||
- allows switching the view to that of a given client from the all-window view (Mod-0) using a keyboard shortcut | |||
- [xrdb](http://dwm.suckless.org/patches/xrdb/) | |||
- allows dwm to read colors from xrdb (.Xresources) during runtime | |||
- [zoomfloating](https://www.reddit.com/r/suckless/comments/ie5fe3/zoomfloating_my_own_simple_original_patch/) | |||
- a simple patch that allows floating windows to be zoomed into the master stack position | |||
- [zoomswap](https://dwm.suckless.org/patches/zoomswap/) | |||
- allows a master and a stack window to swap places rather than every window on the screen changing position | |||
### Layouts included: | |||
- [bstack](https://dwm.suckless.org/patches/bottomstack/) | |||
- bottomstack layout | |||
- [bstackhoriz](https://dwm.suckless.org/patches/bottomstack/) | |||
- bottomstack horizontal layout | |||
- [centeredmaster](https://dwm.suckless.org/patches/centeredmaster/) | |||
- centeredmaster layout | |||
- [centeredfloatingmaster](https://dwm.suckless.org/patches/centeredmaster/) | |||
- centeredfloatingmaster layout | |||
- [columns](https://dwm.suckless.org/patches/columns/) | |||
- same as the default tile layout except clients in the master area are arranged in columns (i.e. left to right) | |||
- [deck](https://dwm.suckless.org/patches/deck/) | |||
- deck layout - clients in the stack area are arranged on top of each other (like monocle) | |||
- [fibonacci](https://dwm.suckless.org/patches/fibonacci/) | |||
- fibonacci (dwindle and spiral) layouts | |||
- [flextile-deluxe](https://github.com/bakkeby/patches/wiki/flextile-deluxe/) | |||
- a re-envisioned, flexible and over-the-top version of the original [flextile](https://dwm.suckless.org/patches/flextile/) patch supporting | |||
- multiple split layouts (horizontal, vertical, centered, floating, fixed) | |||
- tile arrangement on a per split basis (stack horizontally, stack vertically, grids, fibonacci) | |||
- pertag, cfacts, rmaster, vanitygaps compatibility | |||
- tile, deck, monocle, centeredmaster, bstack, bstackhoriz, gapplessgrid and more | |||
- this gives you a lot of versatility in terms of layout | |||
- [gapplessgrid](https://dwm.suckless.org/patches/gaplessgrid/) | |||
- gappless grid layout | |||
- [gridmode](https://dwm.suckless.org/patches/gridmode/) | |||
- gridmode (grid) layout | |||
- [horizgrid](https://dwm.suckless.org/patches/horizgrid/) | |||
- horizontal grid layout | |||
- [nrowgrid](https://dwm.suckless.org/patches/nrowgrid/) | |||
- nrowgrid layout, number of rows in grid controlled by nmaster |
@ -1,44 +0,0 @@ | |||
# dwmblocks | |||
Modular status bar for dwm written in c. | |||
# Modifying blocks | |||
The statusbar is made from text output from commandline programs. Blocks are | |||
added and removed by editing the config.h file. | |||
# Luke's build | |||
I have dwmblocks read my preexisting scripts | |||
[here in my dotfiles repo](https://github.com/LukeSmithxyz/voidrice/tree/master/.local/bin/statusbar). | |||
So if you want my build out of the box, download those and put them in your | |||
`$PATH`. I do this to avoid redundancy in LARBS, both i3 and dwm use the same | |||
statusbar scripts. | |||
# Signaling changes | |||
Most statusbars constantly rerun every script every several seconds to update. | |||
This is an option here, but a superior choice is giving your module a signal | |||
that you can signal to it to update on a relevant event, rather than having it | |||
rerun idly. | |||
For example, the audio module has the update signal 10 by default. Thus, | |||
running `pkill -RTMIN+10 dwmblocks` will update it. | |||
You can also run `kill -44 $(pidof dwmblocks)` which will have the same effect, | |||
but is faster. Just add 34 to your typical signal number. | |||
My volume module *never* updates on its own, instead I have this command run | |||
along side my volume shortcuts in dwm to only update it when relevant. | |||
Note that all modules must have different signal numbers. | |||
# Clickable modules | |||
Like i3blocks, this build allows you to build in additional actions into your | |||
scripts in response to click events. See the above linked scripts for examples | |||
of this using the `$BLOCK_BUTTON` variable. | |||
For this feature to work, you need the appropriate patch in dwm as well. See | |||
[here](https://dwm.suckless.org/patches/statuscmd/). | |||
Credit for those patches goes to Daniel Bylinka (daniel.bylinka@gmail.com). |
@ -1,34 +0,0 @@ | |||
This program provides a scroll back buffer for a terminal like st(1). It | |||
should run on any Unix-like system. | |||
At the moment it is in an experimental state. Its not recommended for | |||
productive use. | |||
The initial version of this program is from Roberto E. Vargas Caballero: | |||
https://lists.suckless.org/dev/1703/31256.html | |||
What is the state of scroll? | |||
The project is faced with some hard facts, that our original plan is not doable | |||
as we thought in the first place: | |||
1. [crtl]+[e] is used in emacs mode (default) on the shell to jump to the end | |||
of the line. But, its also used so signal a scroll down mouse event from | |||
terminal emulators to the shell an other programs. | |||
- A workaround is to use vi mode in the shell. | |||
- Or to give up mouse support (default behavior) | |||
2. scroll could not handle backward cursor jumps and editing of old lines | |||
properly. We just handle current line editing and switching between | |||
alternative screens (curses mode). For a proper end user experience we | |||
would need to write a completely new terminal emulator like screen or tmux. | |||
What is the performance impact of scroll? | |||
indirect OpenBSD | |||
------------------------------- | |||
0x 7.53 s | |||
1x 10.10 s | |||
2x 12.00 s | |||
3x 13.73 s |
@ -0,0 +1,250 @@ | |||
## Why does st not handle utmp entries? | |||
Use the excellent tool of [utmp](https://git.suckless.org/utmp/) for this task. | |||
## Some _random program_ complains that st is unknown/not recognised/unsupported/whatever! | |||
It means that st doesn’t have any terminfo entry on your system. Chances are | |||
you did not `make install`. If you just want to test it without installing it, | |||
you can manually run `tic -sx st.info`. | |||
## Nothing works, and nothing is said about an unknown terminal! | |||
* Some programs just assume they’re running in xterm i.e. they don’t rely on | |||
terminfo. What you see is the current state of the “xterm compliance”. | |||
* Some programs don’t complain about the lacking st description and default to | |||
another terminal. In that case see the question about terminfo. | |||
## How do I scroll back up? | |||
* Using a terminal multiplexer. | |||
* `st -e tmux` using C-b [ | |||
* `st -e screen` using C-a ESC | |||
* Using the excellent tool of [scroll](https://git.suckless.org/scroll/). | |||
* Using the scrollback [patch](https://st.suckless.org/patches/scrollback/). | |||
## I would like to have utmp and/or scroll functionality by default | |||
You can add the absolute patch of both programs in your config.h | |||
file. You only have to modify the value of utmp and scroll variables. | |||
## Why doesn't the Del key work in some programs? | |||
Taken from the terminfo manpage: | |||
If the terminal has a keypad that transmits codes when the keys | |||
are pressed, this information can be given. Note that it is not | |||
possible to handle terminals where the keypad only works in | |||
local (this applies, for example, to the unshifted HP 2621 keys). | |||
If the keypad can be set to transmit or not transmit, give these | |||
codes as smkx and rmkx. Otherwise the keypad is assumed to | |||
always transmit. | |||
In the st case smkx=E[?1hE= and rmkx=E[?1lE>, so it is mandatory that | |||
applications which want to test against keypad keys send these | |||
sequences. | |||
But buggy applications (like bash and irssi, for example) don't do this. A fast | |||
solution for them is to use the following command: | |||
$ printf '\033[?1h\033=' >/dev/tty | |||
or | |||
$ tput smkx | |||
In the case of bash, readline is used. Readline has a different note in its | |||
manpage about this issue: | |||
enable-keypad (Off) | |||
When set to On, readline will try to enable the | |||
application keypad when it is called. Some systems | |||
need this to enable arrow keys. | |||
Adding this option to your .inputrc will fix the keypad problem for all | |||
applications using readline. | |||
If you are using zsh, then read the zsh FAQ | |||
<http://zsh.sourceforge.net/FAQ/zshfaq03.html#l25>: | |||
It should be noted that the O / [ confusion can occur with other keys | |||
such as Home and End. Some systems let you query the key sequences | |||
sent by these keys from the system's terminal database, terminfo. | |||
Unfortunately, the key sequences given there typically apply to the | |||
mode that is not the one zsh uses by default (it's the "application" | |||
mode rather than the "raw" mode). Explaining the use of terminfo is | |||
outside of the scope of this FAQ, but if you wish to use the key | |||
sequences given there you can tell the line editor to turn on | |||
"application" mode when it starts and turn it off when it stops: | |||
function zle-line-init () { echoti smkx } | |||
function zle-line-finish () { echoti rmkx } | |||
zle -N zle-line-init | |||
zle -N zle-line-finish | |||
Putting these lines into your .zshrc will fix the problems. | |||
## How can I use meta in 8bit mode? | |||
St supports meta in 8bit mode, but the default terminfo entry doesn't | |||
use this capability. If you want it, you have to use the 'st-meta' value | |||
in TERM. | |||
## I cannot compile st in OpenBSD | |||
OpenBSD lacks librt, despite it being mandatory in POSIX | |||
<http://pubs.opengroup.org/onlinepubs/9699919799/utilities/c99.html#tag_20_11_13>. | |||
If you want to compile st for OpenBSD you have to remove -lrt from config.mk, and | |||
st will compile without any loss of functionality, because all the functions are | |||
included in libc on this platform. | |||
## The Backspace Case | |||
St is emulating the Linux way of handling backspace being delete and delete being | |||
backspace. | |||
This is an issue that was discussed in suckless mailing list | |||
<https://lists.suckless.org/dev/1404/20697.html>. Here is why some old grumpy | |||
terminal users wants its backspace to be how he feels it: | |||
Well, I am going to comment why I want to change the behaviour | |||
of this key. When ASCII was defined in 1968, communication | |||
with computers was done using punched cards, or hardcopy | |||
terminals (basically a typewriter machine connected with the | |||
computer using a serial port). ASCII defines DELETE as 7F, | |||
because, in punched-card terms, it means all the holes of the | |||
card punched; it is thus a kind of 'physical delete'. In the | |||
same way, the BACKSPACE key was a non-destructive backspace, | |||
as on a typewriter. So, if you wanted to delete a character, | |||
you had to BACKSPACE and then DELETE. Another use of BACKSPACE | |||
was to type accented characters, for example 'a BACKSPACE `'. | |||
The VT100 had no BACKSPACE key; it was generated using the | |||
CONTROL key as another control character (CONTROL key sets to | |||
0 b7 b6 b5, so it converts H (code 0x48) into BACKSPACE (code | |||
0x08)), but it had a DELETE key in a similar position where | |||
the BACKSPACE key is located today on common PC keyboards. | |||
All the terminal emulators emulated the difference between | |||
these keys correctly: the backspace key generated a BACKSPACE | |||
(^H) and delete key generated a DELETE (^?). | |||
But a problem arose when Linus Torvalds wrote Linux. Unlike | |||
earlier terminals, the Linux virtual terminal (the terminal | |||
emulator integrated in the kernel) returned a DELETE when | |||
backspace was pressed, due to the VT100 having a DELETE key in | |||
the same position. This created a lot of problems (see [1] | |||
and [2]). Since Linux has become the king, a lot of terminal | |||
emulators today generate a DELETE when the backspace key is | |||
pressed in order to avoid problems with Linux. The result is | |||
that the only way of generating a BACKSPACE on these systems | |||
is by using CONTROL + H. (I also think that emacs had an | |||
important point here because the CONTROL + H prefix is used | |||
in emacs in some commands (help commands).) | |||
From point of view of the kernel, you can change the key | |||
for deleting a previous character with stty erase. When you | |||
connect a real terminal into a machine you describe the type | |||
of terminal, so getty configures the correct value of stty | |||
erase for this terminal. In the case of terminal emulators, | |||
however, you don't have any getty that can set the correct | |||
value of stty erase, so you always get the default value. | |||
For this reason, it is necessary to add 'stty erase ^H' to your | |||
profile if you have changed the value of the backspace key. | |||
Of course, another solution is for st itself to modify the | |||
value of stty erase. I usually have the inverse problem: | |||
when I connect to non-Unix machines, I have to press CONTROL + | |||
h to get a BACKSPACE. The inverse problem occurs when a user | |||
connects to my Unix machines from a different system with a | |||
correct backspace key. | |||
[1] http://www.ibb.net/~anne/keyboard.html | |||
[2] http://www.tldp.org/HOWTO/Keyboard-and-Console-HOWTO-5.html | |||
## But I really want the old grumpy behaviour of my terminal | |||
Apply [1]. | |||
[1] https://st.suckless.org/patches/delkey | |||
## Why do images not work in st using the w3m image hack? | |||
w3mimg uses a hack that draws an image on top of the terminal emulator Drawable | |||
window. The hack relies on the terminal to use a single buffer to draw its | |||
contents directly. | |||
st uses double-buffered drawing so the image is quickly replaced and may show a | |||
short flicker effect. | |||
Below is a patch example to change st double-buffering to a single Drawable | |||
buffer. | |||
diff --git a/x.c b/x.c | |||
--- a/x.c | |||
+++ b/x.c | |||
@@ -732,10 +732,6 @@ xresize(int col, int row) | |||
win.tw = col * win.cw; | |||
win.th = row * win.ch; | |||
- XFreePixmap(xw.dpy, xw.buf); | |||
- xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, | |||
- DefaultDepth(xw.dpy, xw.scr)); | |||
- XftDrawChange(xw.draw, xw.buf); | |||
xclear(0, 0, win.w, win.h); | |||
/* resize to new width */ | |||
@@ -1148,8 +1144,7 @@ xinit(int cols, int rows) | |||
gcvalues.graphics_exposures = False; | |||
dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures, | |||
&gcvalues); | |||
- xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, | |||
- DefaultDepth(xw.dpy, xw.scr)); | |||
+ xw.buf = xw.win; | |||
XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel); | |||
XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h); | |||
@@ -1632,8 +1627,6 @@ xdrawline(Line line, int x1, int y1, int x2) | |||
void | |||
xfinishdraw(void) | |||
{ | |||
- XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, win.w, | |||
- win.h, 0, 0); | |||
XSetForeground(xw.dpy, dc.gc, | |||
dc.col[IS_SET(MODE_REVERSE)? | |||
defaultfg : defaultbg].pixel); | |||
## BadLength X error in Xft when trying to render emoji | |||
Xft makes st crash when rendering color emojis with the following error: | |||
"X Error of failed request: BadLength (poly request too large or internal Xlib length error)" | |||
Major opcode of failed request: 139 (RENDER) | |||
Minor opcode of failed request: 20 (RenderAddGlyphs) | |||
Serial number of failed request: 1595 | |||
Current serial number in output stream: 1818" | |||
This is a known bug in Xft (not st) which happens on some platforms and | |||
combination of particular fonts and fontconfig settings. | |||
See also: | |||
https://gitlab.freedesktop.org/xorg/lib/libxft/issues/6 | |||
https://bugs.freedesktop.org/show_bug.cgi?id=107534 | |||
https://bugzilla.redhat.com/show_bug.cgi?id=1498269 | |||
The solution is to remove color emoji fonts or disable this in the fontconfig | |||
XML configuration. As an ugly workaround (which may work only on newer | |||
fontconfig versions (FC_COLOR)), the following code can be used to mask color | |||
fonts: | |||
FcPatternAddBool(fcpattern, FC_COLOR, FcFalse); | |||
Please don't bother reporting this bug to st, but notify the upstream Xft | |||
developers about fixing this bug. |
@ -0,0 +1,17 @@ | |||
A STATEMENT ON LEGACY SUPPORT | |||
In the terminal world there is much cruft that comes from old and unsup‐ | |||
ported terminals that inherit incompatible modes and escape sequences | |||
which noone is able to know, except when he/she comes from that time and | |||
developed a graphical vt100 emulator at that time. | |||
One goal of st is to only support what is really needed. When you en‐ | |||
counter a sequence which you really need, implement it. But while you | |||
are at it, do not add the other cruft you might encounter while sneek‐ | |||
ing at other terminal emulators. History has bloated them and there is | |||
no real evidence that most of the sequences are used today. | |||
Christoph Lohmann <20h@r-36.net> | |||
2012-09-13T07:00:36.081271045+02:00 | |||
@ -0,0 +1,34 @@ | |||
MIT/X Consortium License | |||
© 2014-2020 Hiltjo Posthuma <hiltjo at codemadness dot org> | |||
© 2018 Devin J. Pohly <djpohly at gmail dot com> | |||
© 2014-2017 Quentin Rameau <quinq at fifth dot space> | |||
© 2009-2012 Aurélien APTEL <aurelien dot aptel at gmail dot com> | |||
© 2008-2017 Anselm R Garbe <garbeam at gmail dot com> | |||
© 2012-2017 Roberto E. Vargas Caballero <k0ga at shike2 dot com> | |||
© 2012-2016 Christoph Lohmann <20h at r-36 dot net> | |||
© 2013 Eon S. Jeon <esjeon at hyunmu dot am> | |||
© 2013 Alexander Sedov <alex0player at gmail dot com> | |||
© 2013 Mark Edgar <medgar123 at gmail dot com> | |||
© 2013-2014 Eric Pruitt <eric.pruitt at gmail dot com> | |||
© 2013 Michael Forney <mforney at mforney dot org> | |||
© 2013-2014 Markus Teich <markus dot teich at stusta dot mhn dot de> | |||
© 2014-2015 Laslo Hunhold <dev at frign dot de> | |||
Permission is hereby granted, free of charge, to any person obtaining a | |||
copy of this software and associated documentation files (the "Software"), | |||
to deal in the Software without restriction, including without limitation | |||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||
and/or sell copies of the Software, and to permit persons to whom the | |||
Software is furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
DEALINGS IN THE SOFTWARE. |
@ -0,0 +1,60 @@ | |||
# st - simple terminal | |||
# See LICENSE file for copyright and license details. | |||
.POSIX: | |||
include config.mk | |||
SRC = st.c x.c | |||
OBJ = $(SRC:.c=.o) | |||
all: options st | |||
options: | |||
@echo st build options: | |||
@echo "CFLAGS = $(STCFLAGS)" | |||
@echo "LDFLAGS = $(STLDFLAGS)" | |||
@echo "CC = $(CC)" | |||
config.h: | |||
cp config.def.h config.h | |||
.c.o: | |||
$(CC) $(STCFLAGS) -c $< | |||
st.o: config.h st.h win.h | |||
x.o: arg.h config.h st.h win.h | |||
$(OBJ): config.h config.mk | |||
st: $(OBJ) | |||
$(CC) -o $@ $(OBJ) $(STLDFLAGS) | |||
clean: | |||
rm -f st $(OBJ) st-$(VERSION).tar.gz | |||
dist: clean | |||
mkdir -p st-$(VERSION) | |||
cp -R FAQ LEGACY TODO LICENSE Makefile README config.mk\ | |||
config.def.h st.info st.1 arg.h st.h win.h $(SRC)\ | |||
st-$(VERSION) | |||
tar -cf - st-$(VERSION) | gzip > st-$(VERSION).tar.gz | |||
rm -rf st-$(VERSION) | |||
install: st | |||
mkdir -p $(DESTDIR)$(PREFIX)/bin | |||
cp -f st $(DESTDIR)$(PREFIX)/bin | |||
chmod 755 $(DESTDIR)$(PREFIX)/bin/st | |||
mkdir -p $(DESTDIR)$(MANPREFIX)/man1 | |||
sed "s/VERSION/$(VERSION)/g" < st.1 > $(DESTDIR)$(MANPREFIX)/man1/st.1 | |||
chmod 644 $(DESTDIR)$(MANPREFIX)/man1/st.1 | |||
tic -sx st.info | |||
@echo Please see the README file regarding the terminfo entry of st. | |||
mkdir -p $(DESTDIR)$(PREFIX)/share/applications | |||
cp -f st.desktop $(DESTDIR)$(PREFIX)/share/applications | |||
uninstall: | |||
rm -f $(DESTDIR)$(PREFIX)/bin/st | |||
rm -f $(DESTDIR)$(MANPREFIX)/man1/st.1 | |||
rm -f $(DESTDIR)$(PREFIX)/share/applications/st.desktop | |||
.PHONY: all options clean dist install uninstall |
@ -0,0 +1,28 @@ | |||
vt emulation | |||
------------ | |||
* double-height support | |||
code & interface | |||
---------------- | |||
* add a simple way to do multiplexing | |||
drawing | |||
------- | |||
* add diacritics support to xdraws() | |||
* switch to a suckless font drawing library | |||
* make the font cache simpler | |||
* add better support for brightening of the upper colors | |||
bugs | |||
---- | |||
* fix shift up/down (shift selection in emacs) | |||
* remove DEC test sequence when appropriate | |||
misc | |||
---- | |||
$ grep -nE 'XXX|TODO' st.c | |||
@ -0,0 +1,50 @@ | |||
/* | |||
* Copy me if you can. | |||
* by 20h | |||
*/ | |||
#ifndef ARG_H__ | |||
#define ARG_H__ | |||
extern char *argv0; | |||
/* use main(int argc, char *argv[]) */ | |||
#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\ | |||
argv[0] && argv[0][0] == '-'\ | |||
&& argv[0][1];\ | |||
argc--, argv++) {\ | |||
char argc_;\ | |||
char **argv_;\ | |||
int brk_;\ | |||
if (argv[0][1] == '-' && argv[0][2] == '\0') {\ | |||
argv++;\ | |||
argc--;\ | |||
break;\ | |||
}\ | |||
int i_;\ | |||
for (i_ = 1, brk_ = 0, argv_ = argv;\ | |||
argv[0][i_] && !brk_;\ | |||
i_++) {\ | |||
if (argv_ != argv)\ | |||
break;\ | |||
argc_ = argv[0][i_];\ | |||
switch (argc_) | |||
#define ARGEND }\ | |||
} | |||
#define ARGC() argc_ | |||
#define EARGF(x) ((argv[0][i_+1] == '\0' && argv[1] == NULL)?\ | |||
((x), abort(), (char *)0) :\ | |||
(brk_ = 1, (argv[0][i_+1] != '\0')?\ | |||
(&argv[0][i_+1]) :\ | |||
(argc--, argv++, argv[0]))) | |||
#define ARGF() ((argv[0][i_+1] == '\0' && argv[1] == NULL)?\ | |||
(char *)0 :\ | |||
(brk_ = 1, (argv[0][i_+1] != '\0')?\ | |||
(&argv[0][i_+1]) :\ | |||
(argc--, argv++, argv[0]))) | |||
#endif |
@ -0,0 +1,484 @@ | |||
/* See LICENSE file for copyright and license details. */ | |||
/* | |||
* appearance | |||
* | |||
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html | |||
*/ | |||
static char *font = "CaskaydiaCove Nerd Font Mono:pixelsize=16:antialias=true:autohint=true"; | |||
static char *font2[] = { | |||
"Symbola:pixelsize=12:antialias=true:autohint=true", | |||
}; | |||
static int borderpx = 2; | |||
/* | |||
* What program is execed by st depends of these precedence rules: | |||
* 1: program passed with -e | |||
* 2: scroll and/or utmp | |||
* 3: SHELL environment variable | |||
* 4: value of shell in /etc/passwd | |||
* 5: value of shell in config.h | |||
*/ | |||
static char *shell = "/bin/zsh"; | |||
char *utmp = NULL; | |||
/* scroll program: to enable use a string like "scroll" */ | |||
char *scroll = "scroll"; | |||
char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400"; | |||
/* identification sequence returned in DA and DECID */ | |||
char *vtiden = "\033[?6c"; | |||
/* Kerning / character bounding-box multipliers */ | |||
static float cwscale = 1.0; | |||
static float chscale = 1.0; | |||
/* | |||
* word delimiter string | |||
* | |||
* More advanced example: L" `'\"()[]{}" | |||
*/ | |||
wchar_t *worddelimiters = L" "; | |||
/* selection timeouts (in milliseconds) */ | |||
static unsigned int doubleclicktimeout = 300; | |||
static unsigned int tripleclicktimeout = 600; | |||
/* alt screens */ | |||
int allowaltscreen = 1; | |||
/* allow certain non-interactive (insecure) window operations such as: | |||
setting the clipboard text */ | |||
int allowwindowops = 0; | |||
/* | |||
* draw latency range in ms - from new content/keypress/etc until drawing. | |||
* within this range, st draws when content stops arriving (idle). mostly it's | |||
* near minlatency, but it waits longer for slow updates to avoid partial draw. | |||
* low minlatency will tear/flicker more, as it can "detect" idle too early. | |||
*/ | |||
static double minlatency = 8; | |||
static double maxlatency = 33; | |||
/* | |||
* blinking timeout (set to 0 to disable blinking) for the terminal blinking | |||
* attribute. | |||
*/ | |||
static unsigned int blinktimeout = 800; | |||
/* | |||
* thickness of underline and bar cursors | |||
*/ | |||
static unsigned int cursorthickness = 2; | |||
/* | |||
* bell volume. It must be a value between -100 and 100. Use 0 for disabling | |||
* it | |||
*/ | |||
static int bellvolume = 0; | |||
/* default TERM value */ | |||
char *termname = "st-256color"; | |||
/* | |||
* spaces per tab | |||
* | |||
* When you are changing this value, don't forget to adapt the »it« value in | |||
* the st.info and appropriately install the st.info in the environment where | |||
* you use this st version. | |||
* | |||
* it#$tabspaces, | |||
* | |||
* Secondly make sure your kernel is not expanding tabs. When running `stty | |||
* -a` »tab0« should appear. You can tell the terminal to not expand tabs by | |||
* running following command: | |||
* | |||
* stty tabs | |||
*/ | |||
unsigned int tabspaces = 8; | |||
static const char *colorname[] = { | |||
/* 8 normal colors */ | |||
[0] = "#000000", /* black */ | |||
[1] = "#cc0000", /* red */ | |||
[2] = "#4e9a06", /* green */ | |||
[3] = "#c4a000", /* yellow */ | |||
[4] = "#3465a4", /* blue */ | |||
[5] = "#75507b", /* magenta */ | |||
[6] = "#06989a", /* cyan */ | |||
[7] = "#d3d7cf", /* white */ | |||
/* 8 bright colors */ | |||
[8] = "#555753", /* black */ | |||
[9] = "#ef2929", /* red */ | |||
[10] = "#8ae234", /* green */ | |||
[11] = "#fce94f", /* yellow */ | |||
[12] = "#729fcf", /* blue */ | |||
[13] = "#ad7fa8", /* magenta */ | |||
[14] = "#34e2e2", /* cyan */ | |||
[15] = "#eeeeec", /* white */ | |||
/* special colors */ | |||
[256] = "#000000", /* background */ | |||
[257] = "#ffffff", /* foreground */ | |||
}; | |||
/* | |||
* Default colors (colorname index) | |||
* foreground, background, cursor, reverse cursor | |||
*/ | |||
unsigned int defaultfg = 257; | |||
unsigned int defaultbg = 256; | |||
static unsigned int defaultcs = 257; | |||
static unsigned int defaultrcs = 256; | |||
static unsigned int defaultitalic = 7; | |||
static unsigned int defaultunderline = 7; | |||
/* | |||
* Default shape of cursor | |||
* 2: Block ("█") | |||
* 4: Underline ("_") | |||
* 6: Bar ("|") | |||
* 7: Snowman ("☃") | |||
*/ | |||
static unsigned int cursorshape = 2; | |||
/* | |||
* Default columns and rows numbers | |||
*/ | |||
static unsigned int cols = 80; | |||
static unsigned int rows = 24; | |||
/* | |||
* Default colour and shape of the mouse cursor | |||
*/ | |||
static unsigned int mouseshape = XC_xterm; | |||
static unsigned int mousefg = 7; | |||
static unsigned int mousebg = 0; | |||
/* | |||
* Color used to display font attributes when fontconfig selected a font which | |||
* doesn't match the ones requested. | |||
*/ | |||
static unsigned int defaultattr = 11; | |||
/* | |||
* Force mouse select/shortcuts while mask is active (when MODE_MOUSE is set). | |||
* Note that if you want to use ShiftMask with selmasks, set this to an other | |||
* modifier, set to 0 to not use it. | |||
*/ | |||
static uint forcemousemod = ShiftMask; | |||
/* | |||
* Internal mouse shortcuts. | |||
* Beware that overloading Button1 will disable the selection. | |||
*/ | |||
static MouseShortcut mshortcuts[] = { | |||
/* mask button function argument release */ | |||
{ XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 }, | |||
{ ShiftMask, Button4, ttysend, {.s = "\033[5;2~"} }, | |||
{ XK_ANY_MOD, Button4, ttysend, {.s = "\031"} }, | |||
{ ShiftMask, Button5, ttysend, {.s = "\033[6;2~"} }, | |||
{ XK_ANY_MOD, Button5, ttysend, {.s = "\005"} }, | |||
{ XK_NO_MOD, Button4, ttysend, {.s = "\033[1;3A"}, 0, -1 }, | |||
{ XK_NO_MOD, Button5, ttysend, {.s = "\033[1;3B"}, 0, -1 }, | |||
}; | |||
/* Internal keyboard shortcuts. */ | |||
#define MODKEY Mod1Mask | |||
#define TERMMOD (ControlMask|ShiftMask) | |||
static unsigned int cursorstyle = 1; | |||
static Rune stcursor = 0x2603; /* snowman (U+2603) */ | |||
char *iso14755_cmd = "dmenu -w \"$WINDOWID\" -p codepoint: </dev/null"; | |||
static Shortcut shortcuts[] = { | |||
/* mask keysym function argument */ | |||
{ XK_ANY_MOD, XK_Break, sendbreak, {.i = 0} }, | |||
{ ControlMask, XK_Print, toggleprinter, {.i = 0} }, | |||
{ ShiftMask, XK_Print, printscreen, {.i = 0} }, | |||
{ XK_ANY_MOD, XK_Print, printsel, {.i = 0} }, | |||
{ TERMMOD, XK_Prior, zoom, {.f = +1} }, | |||
{ TERMMOD, XK_Next, zoom, {.f = -1} }, | |||
{ TERMMOD, XK_Home, zoomreset, {.f = 0} }, | |||
{ TERMMOD, XK_C, clipcopy, {.i = 0} }, | |||
{ TERMMOD, XK_V, clippaste, {.i = 0} }, | |||
{ TERMMOD, XK_Y, selpaste, {.i = 0} }, | |||
{ ShiftMask, XK_Insert, selpaste, {.i = 0} }, | |||
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, | |||
{ TERMMOD, XK_I, iso14755, {.i = 0} }, | |||
}; | |||
/* | |||
* Special keys (change & recompile st.info accordingly) | |||
* | |||
* Mask value: | |||
* * Use XK_ANY_MOD to match the key no matter modifiers state | |||
* * Use XK_NO_MOD to match the key alone (no modifiers) | |||
* appkey value: | |||
* * 0: no value | |||
* * > 0: keypad application mode enabled | |||
* * = 2: term.numlock = 1 | |||
* * < 0: keypad application mode disabled | |||
* appcursor value: | |||
* * 0: no value | |||
* * > 0: cursor application mode enabled | |||
* * < 0: cursor application mode disabled | |||
* | |||
* Be careful with the order of the definitions because st searches in | |||
* this table sequentially, so any XK_ANY_MOD must be in the last | |||
* position for a key. | |||
*/ | |||
/* | |||
* If you want keys other than the X11 function keys (0xFD00 - 0xFFFF) | |||
* to be mapped below, add them to this array. | |||
*/ | |||
static KeySym mappedkeys[] = { -1 }; | |||
/* | |||
* State bits to ignore when matching key or button events. By default, | |||
* numlock (Mod2Mask) and keyboard layout (XK_SWITCH_MOD) are ignored. | |||
*/ | |||
static uint ignoremod = Mod2Mask|XK_SWITCH_MOD; | |||
/* | |||
* This is the huge key array which defines all compatibility to the Linux | |||
* world. Please decide about changes wisely. | |||
*/ | |||
static Key key[] = { | |||
/* keysym mask string appkey appcursor */ | |||
{ XK_KP_Home, ShiftMask, "\033[2J", 0, -1}, | |||
{ XK_KP_Home, ShiftMask, "\033[1;2H", 0, +1}, | |||
{ XK_KP_Home, XK_ANY_MOD, "\033[H", 0, -1}, | |||
{ XK_KP_Home, XK_ANY_MOD, "\033[1~", 0, +1}, | |||
{ XK_KP_Up, XK_ANY_MOD, "\033Ox", +1, 0}, | |||
{ XK_KP_Up, XK_ANY_MOD, "\033[A", 0, -1}, | |||
{ XK_KP_Up, XK_ANY_MOD, "\033OA", 0, +1}, | |||
{ XK_KP_Down, XK_ANY_MOD, "\033Or", +1, 0}, | |||
{ XK_KP_Down, XK_ANY_MOD, "\033[B", 0, -1}, | |||
{ XK_KP_Down, XK_ANY_MOD, "\033OB", 0, +1}, | |||
{ XK_KP_Left, XK_ANY_MOD, "\033Ot", +1, 0}, | |||
{ XK_KP_Left, XK_ANY_MOD, "\033[D", 0, -1}, | |||
{ XK_KP_Left, XK_ANY_MOD, "\033OD", 0, +1}, | |||
{ XK_KP_Right, XK_ANY_MOD, "\033Ov", +1, 0}, | |||
{ XK_KP_Right, XK_ANY_MOD, "\033[C", 0, -1}, | |||
{ XK_KP_Right, XK_ANY_MOD, "\033OC", 0, +1}, | |||
{ XK_KP_Prior, ShiftMask, "\033[5;2~", 0, 0}, | |||
{ XK_KP_Prior, XK_ANY_MOD, "\033[5~", 0, 0}, | |||
{ XK_KP_Begin, XK_ANY_MOD, "\033[E", 0, 0}, | |||
{ XK_KP_End, ControlMask, "\033[J", -1, 0}, | |||
{ XK_KP_End, ControlMask, "\033[1;5F", +1, 0}, | |||
{ XK_KP_End, ShiftMask, "\033[K", -1, 0}, | |||
{ XK_KP_End, ShiftMask, "\033[1;2F", +1, 0}, | |||
{ XK_KP_End, XK_ANY_MOD, "\033[4~", 0, 0}, | |||
{ XK_KP_Next, ShiftMask, "\033[6;2~", 0, 0}, | |||
{ XK_KP_Next, XK_ANY_MOD, "\033[6~", 0, 0}, | |||
{ XK_KP_Insert, ShiftMask, "\033[2;2~", +1, 0}, | |||
{ XK_KP_Insert, ShiftMask, "\033[4l", -1, 0}, | |||
{ XK_KP_Insert, ControlMask, "\033[L", -1, 0}, | |||
{ XK_KP_Insert, ControlMask, "\033[2;5~", +1, 0}, | |||
{ XK_KP_Insert, XK_ANY_MOD, "\033[4h", -1, 0}, | |||
{ XK_KP_Insert, XK_ANY_MOD, "\033[2~", +1, 0}, | |||
{ XK_KP_Delete, ControlMask, "\033[M", -1, 0}, | |||
{ XK_KP_Delete, ControlMask, "\033[3;5~", +1, 0}, | |||
{ XK_KP_Delete, ShiftMask, "\033[2K", -1, 0}, | |||
{ XK_KP_Delete, ShiftMask, "\033[3;2~", +1, 0}, | |||
{ XK_KP_Delete, XK_ANY_MOD, "\033[P", -1, 0}, | |||
{ XK_KP_Delete, XK_ANY_MOD, "\033[3~", +1, 0}, | |||
{ XK_KP_Multiply, XK_ANY_MOD, "\033Oj", +2, 0}, | |||
{ XK_KP_Add, XK_ANY_MOD, "\033Ok", +2, 0}, | |||
{ XK_KP_Enter, XK_ANY_MOD, "\033OM", +2, 0}, | |||
{ XK_KP_Enter, XK_ANY_MOD, "\r", -1, 0}, | |||
{ XK_KP_Subtract, XK_ANY_MOD, "\033Om", +2, 0}, | |||
{ XK_KP_Decimal, XK_ANY_MOD, "\033On", +2, 0}, | |||
{ XK_KP_Divide, XK_ANY_MOD, "\033Oo", +2, 0}, | |||
{ XK_KP_0, XK_ANY_MOD, "\033Op", +2, 0}, | |||
{ XK_KP_1, XK_ANY_MOD, "\033Oq", +2, 0}, | |||
{ XK_KP_2, XK_ANY_MOD, "\033Or", +2, 0}, | |||
{ XK_KP_3, XK_ANY_MOD, "\033Os", +2, 0}, | |||
{ XK_KP_4, XK_ANY_MOD, "\033Ot", +2, 0}, | |||
{ XK_KP_5, XK_ANY_MOD, "\033Ou", +2, 0}, | |||
{ XK_KP_6, XK_ANY_MOD, "\033Ov", +2, 0}, | |||
{ XK_KP_7, XK_ANY_MOD, "\033Ow", +2, 0}, | |||
{ XK_KP_8, XK_ANY_MOD, "\033Ox", +2, 0}, | |||
{ XK_KP_9, XK_ANY_MOD, "\033Oy", +2, 0}, | |||
{ XK_Up, ShiftMask, "\033[1;2A", 0, 0}, | |||
{ XK_Up, Mod1Mask, "\033[1;3A", 0, 0}, | |||
{ XK_Up, ShiftMask|Mod1Mask,"\033[1;4A", 0, 0}, | |||
{ XK_Up, ControlMask, "\033[1;5A", 0, 0}, | |||
{ XK_Up, ShiftMask|ControlMask,"\033[1;6A", 0, 0}, | |||
{ XK_Up, ControlMask|Mod1Mask,"\033[1;7A", 0, 0}, | |||
{ XK_Up,ShiftMask|ControlMask|Mod1Mask,"\033[1;8A", 0, 0}, | |||
{ XK_Up, XK_ANY_MOD, "\033[A", 0, -1}, | |||
{ XK_Up, XK_ANY_MOD, "\033OA", 0, +1}, | |||
{ XK_Down, ShiftMask, "\033[1;2B", 0, 0}, | |||
{ XK_Down, Mod1Mask, "\033[1;3B", 0, 0}, | |||
{ XK_Down, ShiftMask|Mod1Mask,"\033[1;4B", 0, 0}, | |||
{ XK_Down, ControlMask, "\033[1;5B", 0, 0}, | |||
{ XK_Down, ShiftMask|ControlMask,"\033[1;6B", 0, 0}, | |||
{ XK_Down, ControlMask|Mod1Mask,"\033[1;7B", 0, 0}, | |||
{ XK_Down,ShiftMask|ControlMask|Mod1Mask,"\033[1;8B",0, 0}, | |||
{ XK_Down, XK_ANY_MOD, "\033[B", 0, -1}, | |||
{ XK_Down, XK_ANY_MOD, "\033OB", 0, +1}, | |||
{ XK_Left, ShiftMask, "\033[1;2D", 0, 0}, | |||
{ XK_Left, Mod1Mask, "\033[1;3D", 0, 0}, | |||
{ XK_Left, ShiftMask|Mod1Mask,"\033[1;4D", 0, 0}, | |||
{ XK_Left, ControlMask, "\033[1;5D", 0, 0}, | |||
{ XK_Left, ShiftMask|ControlMask,"\033[1;6D", 0, 0}, | |||
{ XK_Left, ControlMask|Mod1Mask,"\033[1;7D", 0, 0}, | |||
{ XK_Left,ShiftMask|ControlMask|Mod1Mask,"\033[1;8D",0, 0}, | |||
{ XK_Left, XK_ANY_MOD, "\033[D", 0, -1}, | |||
{ XK_Left, XK_ANY_MOD, "\033OD", 0, +1}, | |||
{ XK_Right, ShiftMask, "\033[1;2C", 0, 0}, | |||
{ XK_Right, Mod1Mask, "\033[1;3C", 0, 0}, | |||
{ XK_Right, ShiftMask|Mod1Mask,"\033[1;4C", 0, 0}, | |||
{ XK_Right, ControlMask, "\033[1;5C", 0, 0}, | |||
{ XK_Right, ShiftMask|ControlMask,"\033[1;6C", 0, 0}, | |||
{ XK_Right, ControlMask|Mod1Mask,"\033[1;7C", 0, 0}, | |||
{ XK_Right,ShiftMask|ControlMask|Mod1Mask,"\033[1;8C",0, 0}, | |||
{ XK_Right, XK_ANY_MOD, "\033[C", 0, -1}, | |||
{ XK_Right, XK_ANY_MOD, "\033OC", 0, +1}, | |||
{ XK_ISO_Left_Tab, ShiftMask, "\033[Z", 0, 0}, | |||
{ XK_Return, Mod1Mask, "\033\r", 0, 0}, | |||
{ XK_Return, XK_ANY_MOD, "\r", 0, 0}, | |||
{ XK_Insert, ShiftMask, "\033[4l", -1, 0}, | |||
{ XK_Insert, ShiftMask, "\033[2;2~", +1, 0}, | |||
{ XK_Insert, ControlMask, "\033[L", -1, 0}, | |||
{ XK_Insert, ControlMask, "\033[2;5~", +1, 0}, | |||
{ XK_Insert, XK_ANY_MOD, "\033[4h", -1, 0}, | |||
{ XK_Insert, XK_ANY_MOD, "\033[2~", +1, 0}, | |||
{ XK_Delete, ControlMask, "\033[M", -1, 0}, | |||
{ XK_Delete, ControlMask, "\033[3;5~", +1, 0}, | |||
{ XK_Delete, ShiftMask, "\033[2K", -1, 0}, | |||
{ XK_Delete, ShiftMask, "\033[3;2~", +1, 0}, | |||
{ XK_Delete, XK_ANY_MOD, "\033[P", -1, 0}, | |||
{ XK_Delete, XK_ANY_MOD, "\033[3~", +1, 0}, | |||
{ XK_BackSpace, XK_NO_MOD, "\177", 0, 0}, | |||
{ XK_BackSpace, Mod1Mask, "\033\177", 0, 0}, | |||
{ XK_Home, ShiftMask, "\033[2J", 0, -1}, | |||
{ XK_Home, ShiftMask, "\033[1;2H", 0, +1}, | |||
{ XK_Home, XK_ANY_MOD, "\033[H", 0, -1}, | |||
{ XK_Home, XK_ANY_MOD, "\033[1~", 0, +1}, | |||
{ XK_End, ControlMask, "\033[J", -1, 0}, | |||
{ XK_End, ControlMask, "\033[1;5F", +1, 0}, | |||
{ XK_End, ShiftMask, "\033[K", -1, 0}, | |||
{ XK_End, ShiftMask, "\033[1;2F", +1, 0}, | |||
{ XK_End, XK_ANY_MOD, "\033[4~", 0, 0}, | |||
{ XK_Prior, ControlMask, "\033[5;5~", 0, 0}, | |||
{ XK_Prior, ShiftMask, "\033[5;2~", 0, 0}, | |||
{ XK_Prior, XK_ANY_MOD, "\033[5~", 0, 0}, | |||
{ XK_Next, ControlMask, "\033[6;5~", 0, 0}, | |||
{ XK_Next, ShiftMask, "\033[6;2~", 0, 0}, | |||
{ XK_Next, XK_ANY_MOD, "\033[6~", 0, 0}, | |||
{ XK_F1, XK_NO_MOD, "\033OP" , 0, 0}, | |||
{ XK_F1, /* F13 */ ShiftMask, "\033[1;2P", 0, 0}, | |||
{ XK_F1, /* F25 */ ControlMask, "\033[1;5P", 0, 0}, | |||
{ XK_F1, /* F37 */ Mod4Mask, "\033[1;6P", 0, 0}, | |||
{ XK_F1, /* F49 */ Mod1Mask, "\033[1;3P", 0, 0}, | |||
{ XK_F1, /* F61 */ Mod3Mask, "\033[1;4P", 0, 0}, | |||
{ XK_F2, XK_NO_MOD, "\033OQ" , 0, 0}, | |||
{ XK_F2, /* F14 */ ShiftMask, "\033[1;2Q", 0, 0}, | |||
{ XK_F2, /* F26 */ ControlMask, "\033[1;5Q", 0, 0}, | |||
{ XK_F2, /* F38 */ Mod4Mask, "\033[1;6Q", 0, 0}, | |||
{ XK_F2, /* F50 */ Mod1Mask, "\033[1;3Q", 0, 0}, | |||
{ XK_F2, /* F62 */ Mod3Mask, "\033[1;4Q", 0, 0}, | |||
{ XK_F3, XK_NO_MOD, "\033OR" , 0, 0}, | |||
{ XK_F3, /* F15 */ ShiftMask, "\033[1;2R", 0, 0}, | |||
{ XK_F3, /* F27 */ ControlMask, "\033[1;5R", 0, 0}, | |||
{ XK_F3, /* F39 */ Mod4Mask, "\033[1;6R", 0, 0}, | |||
{ XK_F3, /* F51 */ Mod1Mask, "\033[1;3R", 0, 0}, | |||
{ XK_F3, /* F63 */ Mod3Mask, "\033[1;4R", 0, 0}, | |||
{ XK_F4, XK_NO_MOD, "\033OS" , 0, 0}, | |||
{ XK_F4, /* F16 */ ShiftMask, "\033[1;2S", 0, 0}, | |||
{ XK_F4, /* F28 */ ControlMask, "\033[1;5S", 0, 0}, | |||
{ XK_F4, /* F40 */ Mod4Mask, "\033[1;6S", 0, 0}, | |||
{ XK_F4, /* F52 */ Mod1Mask, "\033[1;3S", 0, 0}, | |||
{ XK_F5, XK_NO_MOD, "\033[15~", 0, 0}, | |||
{ XK_F5, /* F17 */ ShiftMask, "\033[15;2~", 0, 0}, | |||
{ XK_F5, /* F29 */ ControlMask, "\033[15;5~", 0, 0}, | |||
{ XK_F5, /* F41 */ Mod4Mask, "\033[15;6~", 0, 0}, | |||
{ XK_F5, /* F53 */ Mod1Mask, "\033[15;3~", 0, 0}, | |||
{ XK_F6, XK_NO_MOD, "\033[17~", 0, 0}, | |||
{ XK_F6, /* F18 */ ShiftMask, "\033[17;2~", 0, 0}, | |||
{ XK_F6, /* F30 */ ControlMask, "\033[17;5~", 0, 0}, | |||
{ XK_F6, /* F42 */ Mod4Mask, "\033[17;6~", 0, 0}, | |||
{ XK_F6, /* F54 */ Mod1Mask, "\033[17;3~", 0, 0}, | |||
{ XK_F7, XK_NO_MOD, "\033[18~", 0, 0}, | |||
{ XK_F7, /* F19 */ ShiftMask, "\033[18;2~", 0, 0}, | |||
{ XK_F7, /* F31 */ ControlMask, "\033[18;5~", 0, 0}, | |||
{ XK_F7, /* F43 */ Mod4Mask, "\033[18;6~", 0, 0}, | |||
{ XK_F7, /* F55 */ Mod1Mask, "\033[18;3~", 0, 0}, | |||
{ XK_F8, XK_NO_MOD, "\033[19~", 0, 0}, | |||
{ XK_F8, /* F20 */ ShiftMask, "\033[19;2~", 0, 0}, | |||
{ XK_F8, /* F32 */ ControlMask, "\033[19;5~", 0, 0}, | |||
{ XK_F8, /* F44 */ Mod4Mask, "\033[19;6~", 0, 0}, | |||
{ XK_F8, /* F56 */ Mod1Mask, "\033[19;3~", 0, 0}, | |||
{ XK_F9, XK_NO_MOD, "\033[20~", 0, 0}, | |||
{ XK_F9, /* F21 */ ShiftMask, "\033[20;2~", 0, 0}, | |||
{ XK_F9, /* F33 */ ControlMask, "\033[20;5~", 0, 0}, | |||
{ XK_F9, /* F45 */ Mod4Mask, "\033[20;6~", 0, 0}, | |||
{ XK_F9, /* F57 */ Mod1Mask, "\033[20;3~", 0, 0}, | |||
{ XK_F10, XK_NO_MOD, "\033[21~", 0, 0}, | |||
{ XK_F10, /* F22 */ ShiftMask, "\033[21;2~", 0, 0}, | |||
{ XK_F10, /* F34 */ ControlMask, "\033[21;5~", 0, 0}, | |||
{ XK_F10, /* F46 */ Mod4Mask, "\033[21;6~", 0, 0}, | |||
{ XK_F10, /* F58 */ Mod1Mask, "\033[21;3~", 0, 0}, | |||
{ XK_F11, XK_NO_MOD, "\033[23~", 0, 0}, | |||
{ XK_F11, /* F23 */ ShiftMask, "\033[23;2~", 0, 0}, | |||
{ XK_F11, /* F35 */ ControlMask, "\033[23;5~", 0, 0}, | |||
{ XK_F11, /* F47 */ Mod4Mask, "\033[23;6~", 0, 0}, | |||
{ XK_F11, /* F59 */ Mod1Mask, "\033[23;3~", 0, 0}, | |||
{ XK_F12, XK_NO_MOD, "\033[24~", 0, 0}, | |||
{ XK_F12, /* F24 */ ShiftMask, "\033[24;2~", 0, 0}, | |||
{ XK_F12, /* F36 */ ControlMask, "\033[24;5~", 0, 0}, | |||
{ XK_F12, /* F48 */ Mod4Mask, "\033[24;6~", 0, 0}, | |||
{ XK_F12, /* F60 */ Mod1Mask, "\033[24;3~", 0, 0}, | |||
{ XK_F13, XK_NO_MOD, "\033[1;2P", 0, 0}, | |||
{ XK_F14, XK_NO_MOD, "\033[1;2Q", 0, 0}, | |||
{ XK_F15, XK_NO_MOD, "\033[1;2R", 0, 0}, | |||
{ XK_F16, XK_NO_MOD, "\033[1;2S", 0, 0}, | |||
{ XK_F17, XK_NO_MOD, "\033[15;2~", 0, 0}, | |||
{ XK_F18, XK_NO_MOD, "\033[17;2~", 0, 0}, | |||
{ XK_F19, XK_NO_MOD, "\033[18;2~", 0, 0}, | |||
{ XK_F20, XK_NO_MOD, "\033[19;2~", 0, 0}, | |||
{ XK_F21, XK_NO_MOD, "\033[20;2~", 0, 0}, | |||
{ XK_F22, XK_NO_MOD, "\033[21;2~", 0, 0}, | |||
{ XK_F23, XK_NO_MOD, "\033[23;2~", 0, 0}, | |||
{ XK_F24, XK_NO_MOD, "\033[24;2~", 0, 0}, | |||
{ XK_F25, XK_NO_MOD, "\033[1;5P", 0, 0}, | |||
{ XK_F26, XK_NO_MOD, "\033[1;5Q", 0, 0}, | |||
{ XK_F27, XK_NO_MOD, "\033[1;5R", 0, 0}, | |||
{ XK_F28, XK_NO_MOD, "\033[1;5S", 0, 0}, | |||
{ XK_F29, XK_NO_MOD, "\033[15;5~", 0, 0}, | |||
{ XK_F30, XK_NO_MOD, "\033[17;5~", 0, 0}, | |||
{ XK_F31, XK_NO_MOD, "\033[18;5~", 0, 0}, | |||
{ XK_F32, XK_NO_MOD, "\033[19;5~", 0, 0}, | |||
{ XK_F33, XK_NO_MOD, "\033[20;5~", 0, 0}, | |||
{ XK_F34, XK_NO_MOD, "\033[21;5~", 0, 0}, | |||
{ XK_F35, XK_NO_MOD, "\033[23;5~", 0, 0}, | |||
}; | |||
/* | |||
* Selection types' masks. | |||
* Use the same masks as usual. | |||
* Button1Mask is always unset, to make masks match between ButtonPress. | |||
* ButtonRelease and MotionNotify. | |||
* If no match is found, regular selection is used. | |||
*/ | |||
static uint selmasks[] = { | |||
[SEL_RECTANGULAR] = Mod1Mask, | |||
}; | |||
/* | |||
* Printable characters in ASCII, used to estimate the advance width | |||
* of single wide characters. | |||
*/ | |||
static char ascii_printable[] = | |||
" !\"#$%&'()*+,-./0123456789:;<=>?" | |||
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" | |||
"`abcdefghijklmnopqrstuvwxyz{|}~"; |
@ -0,0 +1,35 @@ | |||
# st version | |||
VERSION = 0.8.4 | |||
# Customize below to fit your system | |||
# paths | |||
PREFIX = /usr/local | |||
MANPREFIX = $(PREFIX)/share/man | |||
X11INC = /usr/X11R6/include | |||
X11LIB = /usr/X11R6/lib | |||
PKG_CONFIG = pkg-config | |||
# includes and libs | |||
INCS = -I$(X11INC) \ | |||
`$(PKG_CONFIG) --cflags fontconfig` \ | |||
`$(PKG_CONFIG) --cflags freetype2` | |||
LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \ | |||
`$(PKG_CONFIG) --libs fontconfig` \ | |||
`$(PKG_CONFIG) --libs freetype2` | |||
# flags | |||
STCPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600 | |||
STCFLAGS = $(INCS) $(STCPPFLAGS) $(CPPFLAGS) $(CFLAGS) | |||
STLDFLAGS = $(LIBS) $(LDFLAGS) | |||
# OpenBSD: | |||
#CPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600 -D_BSD_SOURCE | |||
#LIBS = -L$(X11LIB) -lm -lX11 -lutil -lXft \ | |||
# `$(PKG_CONFIG) --libs fontconfig` \ | |||
# `$(PKG_CONFIG) --libs freetype2` | |||
# compiler and linker | |||
# CC = c99 |
@ -0,0 +1,150 @@ | |||
From bff176133618854676bbdc74c0099f184d3da365 Mon Sep 17 00:00:00 2001 | |||
From: Steve Ward <planet36@gmail.com> | |||
Date: Sun, 31 May 2020 22:48:25 -0400 | |||
Subject: [PATCH] Allow blinking cursor | |||
--- | |||
config.def.h | 19 +++++++++++++------ | |||
x.c | 42 ++++++++++++++++++++++++++++++++---------- | |||
2 files changed, 45 insertions(+), 16 deletions(-) | |||
diff --git a/config.def.h b/config.def.h | |||
index 6f05dce..3dbe915 100644 | |||
--- a/config.def.h | |||
+++ b/config.def.h | |||
@@ -133,13 +133,20 @@ static unsigned int defaultcs = 256; | |||
static unsigned int defaultrcs = 257; | |||
/* | |||
- * Default shape of cursor | |||
- * 2: Block ("█") | |||
- * 4: Underline ("_") | |||
- * 6: Bar ("|") | |||
- * 7: Snowman ("☃") | |||
+ * https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h4-Functions-using-CSI-_-ordered-by-the-final-character-lparen-s-rparen:CSI-Ps-SP-q.1D81 | |||
+ * Default style of cursor | |||
+ * 0: Blinking block | |||
+ * 1: Blinking block (default) | |||
+ * 2: Steady block ("█") | |||
+ * 3: Blinking underline | |||
+ * 4: Steady underline ("_") | |||
+ * 5: Blinking bar | |||
+ * 6: Steady bar ("|") | |||
+ * 7: Blinking st cursor | |||
+ * 8: Steady st cursor | |||
*/ | |||
-static unsigned int cursorshape = 2; | |||
+static unsigned int cursorstyle = 1; | |||
+static Rune stcursor = 0x2603; /* snowman (U+2603) */ | |||
/* | |||
* Default columns and rows numbers | |||
diff --git a/x.c b/x.c | |||
index 210f184..bd80a5e 100644 | |||
--- a/x.c | |||
+++ b/x.c | |||
@@ -253,6 +253,7 @@ static char *opt_name = NULL; | |||
static char *opt_title = NULL; | |||
static int oldbutton = 3; /* button event on startup: 3 = release */ | |||
+static int cursorblinks = 0; | |||
void | |||
clipcopy(const Arg *dummy) | |||
@@ -1526,16 +1527,19 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) | |||
/* draw the new one */ | |||
if (IS_SET(MODE_FOCUSED)) { | |||
switch (win.cursor) { | |||
- case 7: /* st extension */ | |||
- g.u = 0x2603; /* snowman (U+2603) */ | |||
+ case 0: /* Blinking block */ | |||
+ case 1: /* Blinking block (default) */ | |||
+ if (IS_SET(MODE_BLINK)) | |||
+ break; | |||
/* FALLTHROUGH */ | |||
- case 0: /* Blinking Block */ | |||
- case 1: /* Blinking Block (Default) */ | |||
- case 2: /* Steady Block */ | |||
+ case 2: /* Steady block */ | |||
xdrawglyph(g, cx, cy); | |||
break; | |||
- case 3: /* Blinking Underline */ | |||
- case 4: /* Steady Underline */ | |||
+ case 3: /* Blinking underline */ | |||
+ if (IS_SET(MODE_BLINK)) | |||
+ break; | |||
+ /* FALLTHROUGH */ | |||
+ case 4: /* Steady underline */ | |||
XftDrawRect(xw.draw, &drawcol, | |||
borderpx + cx * win.cw, | |||
borderpx + (cy + 1) * win.ch - \ | |||
@@ -1543,12 +1547,23 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) | |||
win.cw, cursorthickness); | |||
break; | |||
case 5: /* Blinking bar */ | |||
+ if (IS_SET(MODE_BLINK)) | |||
+ break; | |||
+ /* FALLTHROUGH */ | |||
case 6: /* Steady bar */ | |||
XftDrawRect(xw.draw, &drawcol, | |||
borderpx + cx * win.cw, | |||
borderpx + cy * win.ch, | |||
cursorthickness, win.ch); | |||
break; | |||
+ case 7: /* Blinking st cursor */ | |||
+ if (IS_SET(MODE_BLINK)) | |||
+ break; | |||
+ /* FALLTHROUGH */ | |||
+ case 8: /* Steady st cursor */ | |||
+ g.u = stcursor; | |||
+ xdrawglyph(g, cx, cy); | |||
+ break; | |||
} | |||
} else { | |||
XftDrawRect(xw.draw, &drawcol, | |||
@@ -1690,9 +1705,12 @@ xsetmode(int set, unsigned int flags) | |||
int | |||
xsetcursor(int cursor) | |||
{ | |||
- if (!BETWEEN(cursor, 0, 7)) /* 7: st extension */ | |||
+ if (!BETWEEN(cursor, 0, 8)) /* 7-8: st extensions */ | |||
return 1; | |||
win.cursor = cursor; | |||
+ cursorblinks = win.cursor == 0 || win.cursor == 1 || | |||
+ win.cursor == 3 || win.cursor == 5 || | |||
+ win.cursor == 7; | |||
return 0; | |||
} | |||
@@ -1936,6 +1954,10 @@ run(void) | |||
if (FD_ISSET(ttyfd, &rfd) || xev) { | |||
if (!drawing) { | |||
trigger = now; | |||
+ if (IS_SET(MODE_BLINK)) { | |||
+ win.mode ^= MODE_BLINK; | |||
+ } | |||
+ lastblink = now; | |||
drawing = 1; | |||
} | |||
timeout = (maxlatency - TIMEDIFF(now, trigger)) \ | |||
@@ -1946,7 +1968,7 @@ run(void) | |||
/* idle detected or maxlatency exhausted -> draw */ | |||
timeout = -1; | |||
- if (blinktimeout && tattrset(ATTR_BLINK)) { | |||
+ if (blinktimeout && (cursorblinks || tattrset(ATTR_BLINK))) { | |||
timeout = blinktimeout - TIMEDIFF(now, lastblink); | |||
if (timeout <= 0) { | |||
if (-timeout > blinktimeout) /* start visible */ | |||
@@ -1982,7 +2004,7 @@ main(int argc, char *argv[]) | |||
{ | |||
xw.l = xw.t = 0; | |||
xw.isfixed = False; | |||
- xsetcursor(cursorshape); | |||
+ xsetcursor(cursorstyle); | |||
ARGBEGIN { | |||
case 'a': | |||
-- | |||
2.20.1 | |||
@ -0,0 +1,44 @@ | |||
From 0ba2850930d2ef22a1774f3dc78884c978f2d8be Mon Sep 17 00:00:00 2001 | |||
From: aleks <aleks.stier@icloud.com> | |||
Date: Wed, 27 May 2020 01:20:00 +0200 | |||
Subject: [PATCH] Create a desktop-entry for st | |||
--- | |||
Makefile | 3 +++ | |||
st.desktop | 7 +++++++ | |||
2 files changed, 10 insertions(+) | |||
create mode 100644 st.desktop | |||
diff --git a/Makefile b/Makefile | |||
index ed19e70..29e25b9 100644 | |||
--- a/Makefile | |||
+++ b/Makefile | |||
@@ -50,9 +50,12 @@ install: st | |||
chmod 644 $(DESTDIR)$(MANPREFIX)/man1/st.1 | |||
tic -sx st.info | |||
@echo Please see the README file regarding the terminfo entry of st. | |||
+ mkdir -p $(DESTDIR)$(PREFIX)/share/applications | |||
+ cp -f st.desktop $(DESTDIR)$(PREFIX)/share/applications | |||
uninstall: | |||
rm -f $(DESTDIR)$(PREFIX)/bin/st | |||
rm -f $(DESTDIR)$(MANPREFIX)/man1/st.1 | |||
+ rm -f $(DESTDIR)$(PREFIX)/share/applications/st.desktop | |||
.PHONY: all options clean dist install uninstall | |||
diff --git a/st.desktop b/st.desktop | |||
new file mode 100644 | |||
index 0000000..a1b5116 | |||
--- /dev/null | |||
+++ b/st.desktop | |||
@@ -0,0 +1,7 @@ | |||
+[Desktop Entry] | |||
+Type=Application | |||
+Name=st | |||
+Comment=simple-terminal emulator for X | |||
+Icon=utilities-terminal | |||
+Exec=st | |||
+Categories=System;TerminalEmulator | |||
-- | |||
2.26.2 | |||
@ -0,0 +1,167 @@ | |||
From ba724004c6a368e452114f7dc147a9978fe0f3b4 Mon Sep 17 00:00:00 2001 | |||
From: Kirill Bugaev <kirill.bugaev87@gmail.com> | |||
Date: Tue, 16 Apr 2019 04:31:30 +0800 | |||
Subject: [PATCH] This patch allows to add spare font besides default. Some | |||
glyphs can be not present in default font. For this glyphs st uses | |||
font-config and try to find them in font cache first. This patch append fonts | |||
defined in font2 variable to the beginning of font cache. So they will be | |||
used first for glyphs that absent in default font. | |||
--- | |||
config.def.h | 6 +++ | |||
x.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++ | |||
2 files changed, 107 insertions(+) | |||
diff --git a/config.def.h b/config.def.h | |||
index 482901e..676719e 100644 | |||
--- a/config.def.h | |||
+++ b/config.def.h | |||
@@ -6,6 +6,12 @@ | |||
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html | |||
*/ | |||
static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true"; | |||
+/* Spare fonts */ | |||
+static char *font2[] = { | |||
+/* "Inconsolata for Powerline:pixelsize=12:antialias=true:autohint=true", */ | |||
+/* "Hack Nerd Font Mono:pixelsize=11:antialias=true:autohint=true", */ | |||
+}; | |||
+ | |||
static int borderpx = 2; | |||
/* | |||
diff --git a/x.c b/x.c | |||
index 5828a3b..d37e59d 100644 | |||
--- a/x.c | |||
+++ b/x.c | |||
@@ -149,6 +149,8 @@ static void xhints(void); | |||
static int xloadcolor(int, const char *, Color *); | |||
static int xloadfont(Font *, FcPattern *); | |||
static void xloadfonts(char *, double); | |||
+static int xloadsparefont(FcPattern *, int); | |||
+static void xloadsparefonts(void); | |||
static void xunloadfont(Font *); | |||
static void xunloadfonts(void); | |||
static void xsetenv(void); | |||
@@ -296,6 +298,7 @@ zoomabs(const Arg *arg) | |||
{ | |||
xunloadfonts(); | |||
xloadfonts(usedfont, arg->f); | |||
+ xloadsparefonts(); | |||
cresize(0, 0); | |||
redraw(); | |||
xhints(); | |||
@@ -977,6 +980,101 @@ xloadfonts(char *fontstr, double fontsize) | |||
FcPatternDestroy(pattern); | |||
} | |||
+int | |||
+xloadsparefont(FcPattern *pattern, int flags) | |||
+{ | |||
+ FcPattern *match; | |||
+ FcResult result; | |||
+ | |||
+ match = FcFontMatch(NULL, pattern, &result); | |||
+ if (!match) { | |||
+ return 1; | |||
+ } | |||
+ | |||
+ if (!(frc[frclen].font = XftFontOpenPattern(xw.dpy, match))) { | |||
+ FcPatternDestroy(match); | |||
+ return 1; | |||
+ } | |||
+ | |||
+ frc[frclen].flags = flags; | |||
+ /* Believe U+0000 glyph will present in each default font */ | |||
+ frc[frclen].unicodep = 0; | |||
+ frclen++; | |||
+ | |||
+ return 0; | |||
+} | |||
+ | |||
+void | |||
+xloadsparefonts(void) | |||
+{ | |||
+ FcPattern *pattern; | |||
+ double sizeshift, fontval; | |||
+ int fc; | |||
+ char **fp; | |||
+ | |||
+ if (frclen != 0) | |||
+ die("can't embed spare fonts. cache isn't empty"); | |||
+ | |||
+ /* Calculate count of spare fonts */ | |||
+ fc = sizeof(font2) / sizeof(*font2); | |||
+ if (fc == 0) | |||
+ return; | |||
+ | |||
+ /* Allocate memory for cache entries. */ | |||
+ if (frccap < 4 * fc) { | |||
+ frccap += 4 * fc - frccap; | |||
+ frc = xrealloc(frc, frccap * sizeof(Fontcache)); | |||
+ } | |||
+ | |||
+ for (fp = font2; fp - font2 < fc; ++fp) { | |||
+ | |||
+ if (**fp == '-') | |||
+ pattern = XftXlfdParse(*fp, False, False); | |||
+ else | |||
+ pattern = FcNameParse((FcChar8 *)*fp); | |||
+ | |||
+ if (!pattern) | |||
+ die("can't open spare font %s\n", *fp); | |||
+ | |||
+ if (defaultfontsize > 0) { | |||
+ sizeshift = usedfontsize - defaultfontsize; | |||
+ if (sizeshift != 0 && | |||
+ FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &fontval) == | |||
+ FcResultMatch) { | |||
+ fontval += sizeshift; | |||
+ FcPatternDel(pattern, FC_PIXEL_SIZE); | |||
+ FcPatternDel(pattern, FC_SIZE); | |||
+ FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fontval); | |||
+ } | |||
+ } | |||
+ | |||
+ FcPatternAddBool(pattern, FC_SCALABLE, 1); | |||
+ | |||
+ FcConfigSubstitute(NULL, pattern, FcMatchPattern); | |||
+ XftDefaultSubstitute(xw.dpy, xw.scr, pattern); | |||
+ | |||
+ if (xloadsparefont(pattern, FRC_NORMAL)) | |||
+ die("can't open spare font %s\n", *fp); | |||
+ | |||
+ FcPatternDel(pattern, FC_SLANT); | |||
+ FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC); | |||
+ if (xloadsparefont(pattern, FRC_ITALIC)) | |||
+ die("can't open spare font %s\n", *fp); | |||
+ | |||
+ FcPatternDel(pattern, FC_WEIGHT); | |||
+ FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD); | |||
+ if (xloadsparefont(pattern, FRC_ITALICBOLD)) | |||
+ die("can't open spare font %s\n", *fp); | |||
+ | |||
+ FcPatternDel(pattern, FC_SLANT); | |||
+ FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN); | |||
+ if (xloadsparefont(pattern, FRC_BOLD)) | |||
+ die("can't open spare font %s\n", *fp); | |||
+ | |||
+ FcPatternDestroy(pattern); | |||
+ } | |||
+} | |||
+ | |||
void | |||
xunloadfont(Font *f) | |||
{ | |||
@@ -1057,6 +1155,9 @@ xinit(int cols, int rows) | |||
usedfont = (opt_font == NULL)? font : opt_font; | |||
xloadfonts(usedfont, 0); | |||
+ /* spare fonts */ | |||
+ xloadsparefonts(); | |||
+ | |||
/* colors */ | |||
xw.cmap = XDefaultColormap(xw.dpy, xw.scr); | |||
xloadcols(); | |||
-- | |||
2.21.0 | |||
@ -0,0 +1,89 @@ | |||
diff --git a/config.def.h b/config.def.h | |||
index 0895a1f..578a90e 100644 | |||
--- a/config.def.h | |||
+++ b/config.def.h | |||
@@ -159,6 +159,11 @@ static unsigned int defaultattr = 11; | |||
*/ | |||
static uint forcemousemod = ShiftMask; | |||
+/* | |||
+ * Command used to query unicode glyphs. | |||
+ */ | |||
+char *iso14755_cmd = "dmenu -w \"$WINDOWID\" -p codepoint: </dev/null"; | |||
+ | |||
/* | |||
* Internal mouse shortcuts. | |||
* Beware that overloading Button1 will disable the selection. | |||
@@ -188,6 +193,7 @@ static Shortcut shortcuts[] = { | |||
{ TERMMOD, XK_Y, selpaste, {.i = 0} }, | |||
{ ShiftMask, XK_Insert, selpaste, {.i = 0} }, | |||
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, | |||
+ { TERMMOD, XK_I, iso14755, {.i = 0} }, | |||
}; | |||
/* | |||
diff --git a/st.1 b/st.1 | |||
index 39120b4..4a98626 100644 | |||
--- a/st.1 | |||
+++ b/st.1 | |||
@@ -159,6 +159,10 @@ Copy the selected text to the clipboard selection. | |||
.TP | |||
.B Ctrl-Shift-v | |||
Paste from the clipboard selection. | |||
+.TP | |||
+.B Ctrl-Shift-i | |||
+Launch dmenu to enter a unicode codepoint and send the corresponding glyph | |||
+to st. | |||
.SH CUSTOMIZATION | |||
.B st | |||
can be customized by creating a custom config.h and (re)compiling the source | |||
diff --git a/st.c b/st.c | |||
index 0ce6ac2..532dc8c 100644 | |||
--- a/st.c | |||
+++ b/st.c | |||
@@ -1985,6 +1985,28 @@ tprinter(char *s, size_t len) | |||
} | |||
} | |||
+void | |||
+iso14755(const Arg *arg) | |||
+{ | |||
+ FILE *p; | |||
+ char *us, *e, codepoint[9], uc[UTF_SIZ]; | |||
+ unsigned long utf32; | |||
+ | |||
+ if (!(p = popen(iso14755_cmd, "r"))) | |||
+ return; | |||
+ | |||
+ us = fgets(codepoint, sizeof(codepoint), p); | |||
+ pclose(p); | |||
+ | |||
+ if (!us || *us == '\0' || *us == '-' || strlen(us) > 7) | |||
+ return; | |||
+ if ((utf32 = strtoul(us, &e, 16)) == ULONG_MAX || | |||
+ (*e != '\n' && *e != '\0')) | |||
+ return; | |||
+ | |||
+ ttywrite(uc, utf8encode(utf32, uc), 1); | |||
+} | |||
+ | |||
void | |||
toggleprinter(const Arg *arg) | |||
{ | |||
diff --git a/st.h b/st.h | |||
index d978458..7b00dd6 100644 | |||
--- a/st.h | |||
+++ b/st.h | |||
@@ -81,6 +81,7 @@ void die(const char *, ...); | |||
void redraw(void); | |||
void draw(void); | |||
+void iso14755(const Arg *); | |||
void printscreen(const Arg *); | |||
void printsel(const Arg *); | |||
void sendbreak(const Arg *); | |||
@@ -122,3 +123,4 @@ extern char *termname; | |||
extern unsigned int tabspaces; | |||
extern unsigned int defaultfg; | |||
extern unsigned int defaultbg; | |||
+extern char *iso14755_cmd; |
@ -0,0 +1,90 @@ | |||
From 9726b1e58352126252412e101432e64d46fc51ca Mon Sep 17 00:00:00 2001 | |||
From: Dennis Lee <dennis@dennislee.xyz> | |||
Date: Sun, 28 Jun 2020 23:01:03 -0700 | |||
Subject: [PATCH] universcroll: mouse wheel only scroll in all modes | |||
Scroll normally via scroll(1), without Shift, when outside of | |||
`MODE_ALTSCREEN`. Inside an alt screen, continue to scroll normally | |||
without Shift; in this mode, your scrolling is automatically translated | |||
into ^Y and ^E. It just werks! | |||
Based on the existing mouse-altscreen patch | |||
https://st.suckless.org/patches/scrollback/ | |||
adapted for st(1) 0.8.4 and scroll(1). | |||
--- | |||
config.def.h | 10 +++++----- | |||
st.c | 5 +++++ | |||
st.h | 1 + | |||
x.c | 2 ++ | |||
4 files changed, 13 insertions(+), 5 deletions(-) | |||
diff --git a/config.def.h b/config.def.h | |||
index 6f05dce..62e87da 100644 | |||
--- a/config.def.h | |||
+++ b/config.def.h | |||
@@ -173,11 +173,11 @@ static uint forcemousemod = ShiftMask; | |||
* Beware that overloading Button1 will disable the selection. | |||
*/ | |||
static MouseShortcut mshortcuts[] = { | |||
- /* mask button function argument release */ | |||
- { XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 }, | |||
- { ShiftMask, Button4, ttysend, {.s = "\033[5;2~"} }, | |||
+ /* mask button function argument release alt */ | |||
+ { XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 }, | |||
+ { XK_ANY_MOD, Button4, ttysend, {.s = "\033[5;2~"}, 0, -1 }, | |||
{ XK_ANY_MOD, Button4, ttysend, {.s = "\031"} }, | |||
- { ShiftMask, Button5, ttysend, {.s = "\033[6;2~"} }, | |||
+ { XK_ANY_MOD, Button5, ttysend, {.s = "\033[6;2~"}, 0, -1 }, | |||
{ XK_ANY_MOD, Button5, ttysend, {.s = "\005"} }, | |||
}; | |||
diff --git a/st.c b/st.c | |||
index 76b7e0d..1f65453 100644 | |||
--- a/st.c | |||
+++ b/st.c | |||
@@ -1047,6 +1047,11 @@ tnew(int col, int row) | |||
treset(); | |||
} | |||
+int tisaltscr(void) | |||
+{ | |||
+ return IS_SET(MODE_ALTSCREEN); | |||
+} | |||
+ | |||
void | |||
tswapscreen(void) | |||
{ | |||
diff --git a/st.h b/st.h | |||
index 3d351b6..39cc054 100644 | |||
--- a/st.h | |||
+++ b/st.h | |||
@@ -87,6 +87,7 @@ void sendbreak(const Arg *); | |||
void toggleprinter(const Arg *); | |||
int tattrset(int); | |||
+int tisaltscr(void); | |||
void tnew(int, int); | |||
void tresize(int, int); | |||
void tsetdirtattr(int); | |||
diff --git a/x.c b/x.c | |||
index 210f184..210dde9 100644 | |||
--- a/x.c | |||
+++ b/x.c | |||
@@ -34,6 +34,7 @@ typedef struct { | |||
void (*func)(const Arg *); | |||
const Arg arg; | |||
uint release; | |||
+ int altscrn; /* 0: don't care, -1: not alt screen, 1: alt screen */ | |||
} MouseShortcut; | |||
typedef struct { | |||
@@ -446,6 +447,7 @@ mouseaction(XEvent *e, uint release) | |||
for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) { | |||
if (ms->release == release && | |||
ms->button == e->xbutton.button && | |||
+ (!ms->altscrn || (ms->altscrn == (tisaltscr() ? 1 : -1))) && | |||
(match(ms->mod, state) || /* exact or forced */ | |||
match(ms->mod, state & ~forcemousemod))) { | |||
ms->func(&(ms->arg)); | |||
-- | |||
2.27.0 |
@ -0,0 +1,181 @@ | |||
.TH ST 1 st\-VERSION | |||
.SH NAME | |||
st \- simple terminal | |||
.SH SYNOPSIS | |||
.B st | |||
.RB [ \-aiv ] | |||
.RB [ \-c | |||
.IR class ] | |||
.RB [ \-f | |||
.IR font ] | |||
.RB [ \-g | |||
.IR geometry ] | |||
.RB [ \-n | |||
.IR name ] | |||
.RB [ \-o | |||
.IR iofile ] | |||
.RB [ \-T | |||
.IR title ] | |||
.RB [ \-t | |||
.IR title ] | |||
.RB [ \-l | |||
.IR line ] | |||
.RB [ \-w | |||
.IR windowid ] | |||
.RB [[ \-e ] | |||
.IR command | |||
.RI [ arguments ...]] | |||
.PP | |||
.B st | |||
.RB [ \-aiv ] | |||
.RB [ \-c | |||
.IR class ] | |||
.RB [ \-f | |||
.IR font ] | |||
.RB [ \-g | |||
.IR geometry ] | |||
.RB [ \-n | |||
.IR name ] | |||
.RB [ \-o | |||
.IR iofile ] | |||
.RB [ \-T | |||
.IR title ] | |||
.RB [ \-t | |||
.IR title ] | |||
.RB [ \-w | |||
.IR windowid ] | |||
.RB \-l | |||
.IR line | |||
.RI [ stty_args ...] | |||
.SH DESCRIPTION | |||
.B st | |||
is a simple terminal emulator. | |||
.SH OPTIONS | |||
.TP | |||
.B \-a | |||
disable alternate screens in terminal | |||
.TP | |||
.BI \-c " class" | |||
defines the window class (default $TERM). | |||
.TP | |||
.BI \-f " font" | |||
defines the | |||
.I font | |||
to use when st is run. | |||
.TP | |||
.BI \-g " geometry" | |||
defines the X11 geometry string. | |||
The form is [=][<cols>{xX}<rows>][{+-}<xoffset>{+-}<yoffset>]. See | |||
.BR XParseGeometry (3) | |||
for further details. | |||
.TP | |||
.B \-i | |||
will fixate the position given with the -g option. | |||
.TP | |||
.BI \-n " name" | |||
defines the window instance name (default $TERM). | |||
.TP | |||
.BI \-o " iofile" | |||
writes all the I/O to | |||
.I iofile. | |||
This feature is useful when recording st sessions. A value of "-" means | |||
standard output. | |||
.TP | |||
.BI \-T " title" | |||
defines the window title (default 'st'). | |||
.TP | |||
.BI \-t " title" | |||
defines the window title (default 'st'). | |||
.TP | |||
.BI \-w " windowid" | |||
embeds st within the window identified by | |||
.I windowid | |||
.TP | |||
.BI \-l " line" | |||
use a tty | |||
.I line | |||
instead of a pseudo terminal. | |||
.I line | |||
should be a (pseudo-)serial device (e.g. /dev/ttyS0 on Linux for serial port | |||
0). | |||
When this flag is given | |||
remaining arguments are used as flags for | |||
.BR stty(1). | |||
By default st initializes the serial line to 8 bits, no parity, 1 stop bit | |||
and a 38400 baud rate. The speed is set by appending it as last argument | |||
(e.g. 'st -l /dev/ttyS0 115200'). Arguments before the last one are | |||
.BR stty(1) | |||
flags. If you want to set odd parity on 115200 baud use for example 'st -l | |||
/dev/ttyS0 parenb parodd 115200'. Set the number of bits by using for | |||
example 'st -l /dev/ttyS0 cs7 115200'. See | |||
.BR stty(1) | |||
for more arguments and cases. | |||
.TP | |||
.B \-v | |||
prints version information to stderr, then exits. | |||
.TP | |||
.BI \-e " command " [ " arguments " "... ]" | |||
st executes | |||
.I command | |||
instead of the shell. If this is used it | |||
.B must be the last option | |||
on the command line, as in xterm / rxvt. | |||
This option is only intended for compatibility, | |||
and all the remaining arguments are used as a command | |||
even without it. | |||
.SH SHORTCUTS | |||
.TP | |||
.B Break | |||
Send a break in the serial line. | |||
Break key is obtained in PC keyboards | |||
pressing at the same time control and pause. | |||
.TP | |||
.B Ctrl-Print Screen | |||
Toggle if st should print to the | |||
.I iofile. | |||
.TP | |||
.B Shift-Print Screen | |||
Print the full screen to the | |||
.I iofile. | |||
.TP | |||
.B Print Screen | |||
Print the selection to the | |||
.I iofile. | |||
.TP | |||
.B Ctrl-Shift-Page Up | |||
Increase font size. | |||
.TP | |||
.B Ctrl-Shift-Page Down | |||
Decrease font size. | |||
.TP | |||
.B Ctrl-Shift-Home | |||
Reset to default font size. | |||
.TP | |||
.B Ctrl-Shift-y | |||
Paste from primary selection (middle mouse button). | |||
.TP | |||
.B Ctrl-Shift-c | |||
Copy the selected text to the clipboard selection. | |||
.TP | |||
.B Ctrl-Shift-v | |||
Paste from the clipboard selection. | |||
.TP | |||
.B Ctrl-Shift-i | |||
Launch dmenu to enter a unicode codepoint and send the corresponding glyph | |||
to st. | |||
.SH CUSTOMIZATION | |||
.B st | |||
can be customized by creating a custom config.h and (re)compiling the source | |||
code. This keeps it fast, secure and simple. | |||
.SH AUTHORS | |||
See the LICENSE file for the authors. | |||
.SH LICENSE | |||
See the LICENSE file for the terms of redistribution. | |||
.SH SEE ALSO | |||
.BR tabbed (1), | |||
.BR utmp (1), | |||
.BR stty (1), | |||
.BR scroll (1) | |||
.SH BUGS | |||
See the TODO file in the distribution. | |||
@ -0,0 +1,7 @@ | |||
[Desktop Entry] | |||
Type=Application | |||
Name=Simple Terminal | |||
Comment=simple-terminal emulator for X | |||
Icon=utilities-terminal | |||
Exec=st | |||
Categories=System;TerminalEmulator |
@ -0,0 +1,128 @@ | |||
/* See LICENSE for license details. */ | |||
#include <stdint.h> | |||
#include <sys/types.h> | |||
/* macros */ | |||
#define MIN(a, b) ((a) < (b) ? (a) : (b)) | |||
#define MAX(a, b) ((a) < (b) ? (b) : (a)) | |||
#define LEN(a) (sizeof(a) / sizeof(a)[0]) | |||
#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) | |||
#define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d)) | |||
#define DEFAULT(a, b) (a) = (a) ? (a) : (b) | |||
#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) | |||
#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || \ | |||
(a).bg != (b).bg) | |||
#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \ | |||
(t1.tv_nsec-t2.tv_nsec)/1E6) | |||
#define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit))) | |||
#define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b)) | |||
#define IS_TRUECOL(x) (1 << 24 & (x)) | |||
enum glyph_attribute { | |||
ATTR_NULL = 0, | |||
ATTR_BOLD = 1 << 0, | |||
ATTR_FAINT = 1 << 1, | |||
ATTR_ITALIC = 1 << 2, | |||
ATTR_UNDERLINE = 1 << 3, | |||
ATTR_BLINK = 1 << 4, | |||
ATTR_REVERSE = 1 << 5, | |||
ATTR_INVISIBLE = 1 << 6, | |||
ATTR_STRUCK = 1 << 7, | |||
ATTR_WRAP = 1 << 8, | |||
ATTR_WIDE = 1 << 9, | |||
ATTR_WDUMMY = 1 << 10, | |||
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT, | |||
}; | |||
enum selection_mode { | |||
SEL_IDLE = 0, | |||
SEL_EMPTY = 1, | |||
SEL_READY = 2 | |||
}; | |||
enum selection_type { | |||
SEL_REGULAR = 1, | |||
SEL_RECTANGULAR = 2 | |||
}; | |||
enum selection_snap { | |||
SNAP_WORD = 1, | |||
SNAP_LINE = 2 | |||
}; | |||
typedef unsigned char uchar; | |||
typedef unsigned int uint; | |||
typedef unsigned long ulong; | |||
typedef unsigned short ushort; | |||
typedef uint_least32_t Rune; | |||
#define Glyph Glyph_ | |||
typedef struct { | |||
Rune u; /* character code */ | |||
ushort mode; /* attribute flags */ | |||
uint32_t fg; /* foreground */ | |||
uint32_t bg; /* background */ | |||
} Glyph; | |||
typedef Glyph *Line; | |||
typedef union { | |||
int i; | |||
uint ui; | |||
float f; | |||
const void *v; | |||
const char *s; | |||
} Arg; | |||
void die(const char *, ...); | |||
void redraw(void); | |||
void draw(void); | |||
void iso14755(const Arg *); | |||
void printscreen(const Arg *); | |||
void printsel(const Arg *); | |||
void sendbreak(const Arg *); | |||
void toggleprinter(const Arg *); | |||
int tattrset(int); | |||
int tisaltscr(void); | |||
void tnew(int, int); | |||
void tresize(int, int); | |||
void tsetdirtattr(int); | |||
void ttyhangup(void); | |||
int ttynew(char *, char *, char *, char **); | |||
size_t ttyread(void); | |||
void ttyresize(int, int); | |||
void ttywrite(const char *, size_t, int); | |||
void resettitle(void); | |||
void selclear(void); | |||
void selinit(void); | |||
void selstart(int, int, int); | |||
void selextend(int, int, int, int); | |||
int selected(int, int); | |||
char *getsel(void); | |||
size_t utf8encode(Rune, char *); | |||
void *xmalloc(size_t); | |||
void *xrealloc(void *, size_t); | |||
char *xstrdup(char *); | |||
/* config.h globals */ | |||
extern char *utmp; | |||
extern char *scroll; | |||
extern char *stty_args; | |||
extern char *vtiden; | |||
extern wchar_t *worddelimiters; | |||
extern int allowaltscreen; | |||
extern int allowwindowops; | |||
extern char *termname; | |||
extern unsigned int tabspaces; | |||
extern unsigned int defaultfg; | |||
extern unsigned int defaultbg; | |||
extern char *iso14755_cmd; |
@ -0,0 +1,239 @@ | |||
st-mono| simpleterm monocolor, | |||
acsc=+C\,D-A.B0E``aaffgghFiGjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, | |||
am, | |||
bce, | |||
bel=^G, | |||
blink=\E[5m, | |||
bold=\E[1m, | |||
cbt=\E[Z, | |||
cvvis=\E[?25h, | |||
civis=\E[?25l, | |||
clear=\E[H\E[2J, | |||
cnorm=\E[?12l\E[?25h, | |||
colors#2, | |||
cols#80, | |||
cr=^M, | |||
csr=\E[%i%p1%d;%p2%dr, | |||
cub=\E[%p1%dD, | |||
cub1=^H, | |||
cud1=^J, | |||
cud=\E[%p1%dB, | |||
cuf1=\E[C, | |||
cuf=\E[%p1%dC, | |||
cup=\E[%i%p1%d;%p2%dH, | |||
cuu1=\E[A, | |||
cuu=\E[%p1%dA, | |||
dch=\E[%p1%dP, | |||
dch1=\E[P, | |||
dim=\E[2m, | |||
dl=\E[%p1%dM, | |||
dl1=\E[M, | |||
ech=\E[%p1%dX, | |||
ed=\E[J, | |||
el=\E[K, | |||
el1=\E[1K, | |||
enacs=\E)0, | |||
flash=\E[?5h$<80/>\E[?5l, | |||
fsl=^G, | |||
home=\E[H, | |||
hpa=\E[%i%p1%dG, | |||
hs, | |||
ht=^I, | |||
hts=\EH, | |||
ich=\E[%p1%d@, | |||
il1=\E[L, | |||
il=\E[%p1%dL, | |||
ind=^J, | |||
indn=\E[%p1%dS, | |||
invis=\E[8m, | |||
is2=\E[4l\E>\E[?1034l, | |||
it#8, | |||
kel=\E[1;2F, | |||
ked=\E[1;5F, | |||
ka1=\E[1~, | |||
ka3=\E[5~, | |||
kc1=\E[4~, | |||
kc3=\E[6~, | |||
kbs=\177, | |||
kcbt=\E[Z, | |||
kb2=\EOu, | |||
kcub1=\EOD, | |||
kcud1=\EOB, | |||
kcuf1=\EOC, | |||
kcuu1=\EOA, | |||
kDC=\E[3;2~, | |||
kent=\EOM, | |||
kEND=\E[1;2F, | |||
kIC=\E[2;2~, | |||
kNXT=\E[6;2~, | |||
kPRV=\E[5;2~, | |||
kHOM=\E[1;2H, | |||
kLFT=\E[1;2D, | |||
kRIT=\E[1;2C, | |||
kind=\E[1;2B, | |||
kri=\E[1;2A, | |||
kclr=\E[3;5~, | |||
kdl1=\E[3;2~, | |||
kdch1=\E[3~, | |||
kich1=\E[2~, | |||
kend=\E[4~, | |||
kf1=\EOP, | |||
kf2=\EOQ, | |||
kf3=\EOR, | |||
kf4=\EOS, | |||
kf5=\E[15~, | |||
kf6=\E[17~, | |||
kf7=\E[18~, | |||
kf8=\E[19~, | |||
kf9=\E[20~, | |||
kf10=\E[21~, | |||
kf11=\E[23~, | |||
kf12=\E[24~, | |||
kf13=\E[1;2P, | |||
kf14=\E[1;2Q, | |||
kf15=\E[1;2R, | |||
kf16=\E[1;2S, | |||
kf17=\E[15;2~, | |||
kf18=\E[17;2~, | |||
kf19=\E[18;2~, | |||
kf20=\E[19;2~, | |||
kf21=\E[20;2~, | |||
kf22=\E[21;2~, | |||
kf23=\E[23;2~, | |||
kf24=\E[24;2~, | |||
kf25=\E[1;5P, | |||
kf26=\E[1;5Q, | |||
kf27=\E[1;5R, | |||
kf28=\E[1;5S, | |||
kf29=\E[15;5~, | |||
kf30=\E[17;5~, | |||
kf31=\E[18;5~, | |||
kf32=\E[19;5~, | |||
kf33=\E[20;5~, | |||
kf34=\E[21;5~, | |||
kf35=\E[23;5~, | |||
kf36=\E[24;5~, | |||
kf37=\E[1;6P, | |||
kf38=\E[1;6Q, | |||
kf39=\E[1;6R, | |||
kf40=\E[1;6S, | |||
kf41=\E[15;6~, | |||
kf42=\E[17;6~, | |||
kf43=\E[18;6~, | |||
kf44=\E[19;6~, | |||
kf45=\E[20;6~, | |||
kf46=\E[21;6~, | |||
kf47=\E[23;6~, | |||
kf48=\E[24;6~, | |||
kf49=\E[1;3P, | |||
kf50=\E[1;3Q, | |||
kf51=\E[1;3R, | |||
kf52=\E[1;3S, | |||
kf53=\E[15;3~, | |||
kf54=\E[17;3~, | |||
kf55=\E[18;3~, | |||
kf56=\E[19;3~, | |||
kf57=\E[20;3~, | |||
kf58=\E[21;3~, | |||
kf59=\E[23;3~, | |||
kf60=\E[24;3~, | |||
kf61=\E[1;4P, | |||
kf62=\E[1;4Q, | |||
kf63=\E[1;4R, | |||
khome=\E[1~, | |||
kil1=\E[2;5~, | |||
krmir=\E[2;2~, | |||
knp=\E[6~, | |||
kmous=\E[M, | |||
kpp=\E[5~, | |||
lines#24, | |||
mir, | |||
msgr, | |||
npc, | |||
op=\E[39;49m, | |||
pairs#64, | |||
mc0=\E[i, | |||
mc4=\E[4i, | |||
mc5=\E[5i, | |||
rc=\E8, | |||
rev=\E[7m, | |||
ri=\EM, | |||
rin=\E[%p1%dT, | |||
ritm=\E[23m, | |||
rmacs=\E(B, | |||
rmcup=\E[?1049l, | |||
rmir=\E[4l, | |||
rmkx=\E[?1l\E>, | |||
rmso=\E[27m, | |||
rmul=\E[24m, | |||
rs1=\Ec, | |||
rs2=\E[4l\E>\E[?1034l, | |||
sc=\E7, | |||
sitm=\E[3m, | |||
sgr0=\E[0m, | |||
smacs=\E(0, | |||
smcup=\E[?1049h, | |||
smir=\E[4h, | |||
smkx=\E[?1h\E=, | |||
smso=\E[7m, | |||
smul=\E[4m, | |||
tbc=\E[3g, | |||
tsl=\E]0;, | |||
xenl, | |||
vpa=\E[%i%p1%dd, | |||
# XTerm extensions | |||
rmxx=\E[29m, | |||
smxx=\E[9m, | |||
# disabled rep for now: causes some issues with older ncurses versions. | |||
# rep=%p1%c\E[%p2%{1}%-%db, | |||
# tmux extensions, see TERMINFO EXTENSIONS in tmux(1) | |||
Tc, | |||
Ms=\E]52;%p1%s;%p2%s\007, | |||
Se=\E[2 q, | |||
Ss=\E[%p1%d q, | |||
st| simpleterm, | |||
use=st-mono, | |||
colors#8, | |||
setab=\E[4%p1%dm, | |||
setaf=\E[3%p1%dm, | |||
setb=\E[4%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m, | |||
setf=\E[3%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m, | |||
sgr=%?%p9%t\E(0%e\E(B%;\E[0%?%p6%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m, | |||
st-256color| simpleterm with 256 colors, | |||
use=st, | |||
ccc, | |||
colors#256, | |||
oc=\E]104\007, | |||
pairs#32767, | |||
# Nicked from xterm-256color | |||
initc=\E]4;%p1%d;rgb\:%p2%{255}%*%{1000}%/%2.2X/%p3%{255}%*%{1000}%/%2.2X/%p4%{255}%*%{1000}%/%2.2X\E\\, | |||
setab=\E[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m, | |||
setaf=\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m, | |||
st-meta| simpleterm with meta key, | |||
use=st, | |||
km, | |||
rmm=\E[?1034l, | |||
smm=\E[?1034h, | |||
rs2=\E[4l\E>\E[?1034h, | |||
is2=\E[4l\E>\E[?1034h, | |||
st-meta-256color| simpleterm with meta key and 256 colors, | |||
use=st-256color, | |||
km, | |||
rmm=\E[?1034l, | |||
smm=\E[?1034h, | |||
rs2=\E[4l\E>\E[?1034h, | |||
is2=\E[4l\E>\E[?1034h, | |||
st-bs| simpleterm with backspace as backspace, | |||
use=st, | |||
kbs=\010, | |||
kdch1=\177, | |||
st-bs-256color| simpleterm with backspace as backspace and 256colors, | |||
use=st-256color, | |||
kbs=\010, | |||
kdch1=\177, |
@ -0,0 +1,40 @@ | |||
/* See LICENSE for license details. */ | |||
enum win_mode { | |||
MODE_VISIBLE = 1 << 0, | |||
MODE_FOCUSED = 1 << 1, | |||
MODE_APPKEYPAD = 1 << 2, | |||
MODE_MOUSEBTN = 1 << 3, | |||
MODE_MOUSEMOTION = 1 << 4, | |||
MODE_REVERSE = 1 << 5, | |||
MODE_KBDLOCK = 1 << 6, | |||
MODE_HIDE = 1 << 7, | |||
MODE_APPCURSOR = 1 << 8, | |||
MODE_MOUSESGR = 1 << 9, | |||
MODE_8BIT = 1 << 10, | |||
MODE_BLINK = 1 << 11, | |||
MODE_FBLINK = 1 << 12, | |||
MODE_FOCUS = 1 << 13, | |||
MODE_MOUSEX10 = 1 << 14, | |||
MODE_MOUSEMANY = 1 << 15, | |||
MODE_BRCKTPASTE = 1 << 16, | |||
MODE_NUMLOCK = 1 << 17, | |||
MODE_MOUSE = MODE_MOUSEBTN|MODE_MOUSEMOTION|MODE_MOUSEX10\ | |||
|MODE_MOUSEMANY, | |||
}; | |||
void xbell(void); | |||
void xclipcopy(void); | |||
void xdrawcursor(int, int, Glyph, int, int, Glyph); | |||
void xdrawline(Line, int, int, int); | |||
void xfinishdraw(void); | |||
void xloadcols(void); | |||
int xsetcolorname(int, const char *); | |||
void xseticontitle(char *); | |||
void xsettitle(char *); | |||
int xsetcursor(int); | |||
void xsetmode(int, unsigned int); | |||
void xsetpointermotion(int); | |||
void xsetsel(char *); | |||
int xstartdraw(void); | |||
void xximspot(int, int); |
@ -0,0 +1,10 @@ | |||
# Frequently Asked Questions | |||
## Surf is starting up slowly. What might be causing this? | |||
The first suspect for such behaviour is the plugin handling. Run surf on | |||
the commandline and see if there are errors because of “nspluginwrapper” | |||
or failed RPCs to them. If that is true, go to ~/.mozilla/plugins and | |||
try removing stale links to plugins not on your system anymore. This | |||
will stop surf from trying to load them. | |||
@ -0,0 +1,48 @@ | |||
MIT/X Consortium License | |||
© 2009-2010 Enno Boland <tox@s01.de> | |||
© 2009 Thomas Menari <spaceinvader@chaotika.org> | |||
© 2009 Simon Rozet <simon@rozet.name> | |||
© 2009 Andrew Antle <andrew.antle@gmail.com> | |||
© 2010-2011 pancake <nopcode.org> | |||
© 2011-2013 Anselm R Garbe <anselm@garbe.us> | |||
© 2011-2012 Troels Henriksen <athas@sigkill.dk> | |||
© 2011 Connor Lane Smith <cls@lubutu.com> | |||
© 2012-2017 Christoph Lohmann <20h@r-36.net> | |||
© 2013 Shayan Pooya <shayan@liveve.org> | |||
© 2013 Jens Nyberg <jens.nyberg@gmail.com> | |||
© 2013 Carlos J. Torres <vlaadbrain@gmail.com> | |||
© 2013 Alexander Sedov <alex0player@gmail.com> | |||
© 2013 Nick White <git@njw.me.uk> | |||
© 2013 David Dufberg <david@dufberg.se> | |||
© 2014-2017 Quentin Rameau <quinq@fifth.space> | |||
© 2014-2016 Markus Teich <markus.teich@stusta.mhn.de> | |||
© 2015 Jakukyo Friel <weakish@gmail.com> | |||
© 2015 Ben Woolley <tautolog@gmail.com> | |||
© 2015 Greg Reagle <greg.reagle@umbc.edu> | |||
© 2015 GhostAV <ghostav@riseup.net> | |||
© 2015 Ivan Tham <pickfire@riseup.net> | |||
© 2015 Alexander Huemer <alexander.huemer@xx.vu> | |||
© 2015 Michael Stevens <mstevens@etla.org> | |||
© 2015 Felix Janda <felix.janda@posteo.de> | |||
© 2016 Charles Lehner <cel@celehner.com> | |||
© 2016 Dmitry Bogatov <KAction@gnu.org> | |||
Permission is hereby granted, free of charge, to any person obtaining a | |||
copy of this software and associated documentation files (the "Software"), | |||
to deal in the Software without restriction, including without limitation | |||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||
and/or sell copies of the Software, and to permit persons to whom the | |||
Software is furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
DEALINGS IN THE SOFTWARE. | |||
@ -0,0 +1,76 @@ | |||
# surf - simple browser | |||
# See LICENSE file for copyright and license details. | |||
.POSIX: | |||
include config.mk | |||
SRC = surf.c | |||
WSRC = webext-surf.c | |||
OBJ = $(SRC:.c=.o) | |||
WOBJ = $(WSRC:.c=.o) | |||
WLIB = $(WSRC:.c=.so) | |||
all: options surf $(WLIB) | |||
options: | |||
@echo surf build options: | |||
@echo "CC = $(CC)" | |||
@echo "CFLAGS = $(SURFCFLAGS) $(CFLAGS)" | |||
@echo "WEBEXTCFLAGS = $(WEBEXTCFLAGS) $(CFLAGS)" | |||
@echo "LDFLAGS = $(LDFLAGS)" | |||
surf: $(OBJ) | |||
$(CC) $(SURFLDFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) | |||
$(OBJ) $(WOBJ): config.h common.h config.mk | |||
config.h: | |||
cp config.def.h $@ | |||
$(OBJ): $(SRC) | |||
$(CC) $(SURFCFLAGS) $(CFLAGS) -c $(SRC) | |||
$(WLIB): $(WOBJ) | |||
$(CC) -shared -Wl,-soname,$@ $(LDFLAGS) -o $@ $? $(WEBEXTLIBS) | |||
$(WOBJ): $(WSRC) | |||
$(CC) $(WEBEXTCFLAGS) $(CFLAGS) -c $(WSRC) | |||
clean: | |||
rm -f surf $(OBJ) | |||
rm -f $(WLIB) $(WOBJ) | |||
distclean: clean | |||
rm -f config.h surf-$(VERSION).tar.gz | |||
dist: distclean | |||
mkdir -p surf-$(VERSION) | |||
cp -R LICENSE Makefile config.mk config.def.h README \ | |||
surf-open.sh arg.h TODO.md surf.png \ | |||
surf.1 $(SRC) $(CSRC) $(WSRC) surf-$(VERSION) | |||
tar -cf surf-$(VERSION).tar surf-$(VERSION) | |||
gzip surf-$(VERSION).tar | |||
rm -rf surf-$(VERSION) | |||
install: all | |||
mkdir -p $(DESTDIR)$(PREFIX)/bin | |||
cp -f surf $(DESTDIR)$(PREFIX)/bin | |||
chmod 755 $(DESTDIR)$(PREFIX)/bin/surf | |||
mkdir -p $(DESTDIR)$(LIBDIR) | |||
cp -f $(WLIB) $(DESTDIR)$(LIBDIR) | |||
for wlib in $(WLIB); do \ | |||
chmod 644 $(DESTDIR)$(LIBDIR)/$$wlib; \ | |||
done | |||
mkdir -p $(DESTDIR)$(MANPREFIX)/man1 | |||
sed "s/VERSION/$(VERSION)/g" < surf.1 > $(DESTDIR)$(MANPREFIX)/man1/surf.1 | |||
chmod 644 $(DESTDIR)$(MANPREFIX)/man1/surf.1 | |||
uninstall: | |||
rm -f $(DESTDIR)$(PREFIX)/bin/surf | |||
rm -f $(DESTDIR)$(MANPREFIX)/man1/surf.1 | |||
for wlib in $(WLIB); do \ | |||
rm -f $(DESTDIR)$(LIBDIR)/$$wlib; \ | |||
done | |||
- rmdir $(DESTDIR)$(LIBDIR) | |||
.PHONY: all options distclean clean dist install uninstall |
@ -0,0 +1,10 @@ | |||
# TODO | |||
* suckless adblocking | |||
* replace twitch() with proper gtk calls to make scrollbars reappear | |||
* replace webkit with something sane | |||
* add video player options | |||
* play in plugin | |||
* play in video player | |||
* call command with URI (quvi + cclive) | |||
@ -0,0 +1,48 @@ | |||
/* | |||
* Copy me if you can. | |||
* by 20h | |||
*/ | |||
#ifndef ARG_H__ | |||
#define ARG_H__ | |||
extern char *argv0; | |||
/* use main(int argc, char *argv[]) */ | |||
#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\ | |||
argv[0] && argv[0][0] == '-'\ | |||
&& argv[0][1];\ | |||
argc--, argv++) {\ | |||
char argc_;\ | |||
char **argv_;\ | |||
int brk_;\ | |||
if (argv[0][1] == '-' && argv[0][2] == '\0') {\ | |||
argv++;\ | |||
argc--;\ | |||
break;\ | |||
}\ | |||
for (brk_ = 0, argv[0]++, argv_ = argv;\ | |||
argv[0][0] && !brk_;\ | |||
argv[0]++) {\ | |||
if (argv_ != argv)\ | |||
break;\ | |||
argc_ = argv[0][0];\ | |||
switch (argc_) | |||
#define ARGEND }\ | |||
} | |||
#define ARGC() argc_ | |||
#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\ | |||
((x), abort(), (char *)0) :\ | |||
(brk_ = 1, (argv[0][1] != '\0')?\ | |||
(&argv[0][1]) :\ | |||
(argc--, argv++, argv[0]))) | |||
#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\ | |||
(char *)0 :\ | |||
(brk_ = 1, (argv[0][1] != '\0')?\ | |||
(&argv[0][1]) :\ | |||
(argc--, argv++, argv[0]))) | |||
#endif |
@ -0,0 +1 @@ | |||
#define MSGBUFSZ 8 |
@ -0,0 +1,252 @@ | |||
/* modifier 0 means no modifier */ | |||
static int surfuseragent = 0; /* Append Surf version to default WebKit user agent */ | |||
static char *fulluseragent = "Mozilla/5.0 (X11; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0"; /* Or override the whole user agent string */ | |||
static char *scriptfiles[] = { | |||
"~/.surf/scripts/default.js", | |||
}; | |||
static char *styledir = "~/.surf/styles/"; | |||
static char *certdir = "~/.surf/certificates/"; | |||
static char *cachedir = "~/.surf/cache/"; | |||
static char *historyfile = "~/.surf/history.txt"; | |||
static char *cookiefile = "~/.surf/cookies.txt"; | |||
static char *searchengine = "https://google.com/search?q="; | |||
static char **plugindirs = (char*[]){ | |||
"~/.surf/plugins/", | |||
LIBPREFIX "/mozilla/plugins/", | |||
NULL | |||
}; | |||
/* Webkit default features */ | |||
/* Highest priority value will be used. | |||
* Default parameters are priority 0 | |||
* Per-uri parameters are priority 1 | |||
* Command parameters are priority 2 | |||
*/ | |||
static Parameter defconfig[ParameterLast] = { | |||
/* parameter Arg value priority */ | |||
[AcceleratedCanvas] = { { .i = 1 }, }, | |||
[AccessMicrophone] = { { .i = 0 }, }, | |||
[AccessWebcam] = { { .i = 0 }, }, | |||
[Certificate] = { { .i = 0 }, }, | |||
[CaretBrowsing] = { { .i = 0 }, }, | |||
[CookiePolicies] = { { .v = "A" }, }, | |||
[DefaultCharset] = { { .v = "UTF-8" }, }, | |||
[DiskCache] = { { .i = 1 }, }, | |||
[DNSPrefetch] = { { .i = 0 }, }, | |||
[Ephemeral] = { { .i = 0 }, }, | |||
[FileURLsCrossAccess] = { { .i = 0 }, }, | |||
[FontSize] = { { .i = 12 }, }, | |||
[FrameFlattening] = { { .i = 0 }, }, | |||
[Geolocation] = { { .i = 0 }, }, | |||
[HideBackground] = { { .i = 0 }, }, | |||
[Inspector] = { { .i = 0 }, }, | |||
[Java] = { { .i = 1 }, }, | |||
[JavaScript] = { { .i = 1 }, }, | |||
[KioskMode] = { { .i = 0 }, }, | |||
[LoadImages] = { { .i = 1 }, }, | |||
[MediaManualPlay] = { { .i = 1 }, }, | |||
[Plugins] = { { .i = 1 }, }, | |||
[PreferredLanguages] = { { .v = (char *[]){ NULL } }, }, | |||
[RunInFullscreen] = { { .i = 0 }, }, | |||
[ScrollBars] = { { .i = 1 }, }, | |||
[ShowIndicators] = { { .i = 1 }, }, | |||
[SiteQuirks] = { { .i = 1 }, }, | |||
[SmoothScrolling] = { { .i = 0 }, }, | |||
[SpellChecking] = { { .i = 0 }, }, | |||
[SpellLanguages] = { { .v = ((char *[]){ "en_US", NULL }) }, }, | |||
[StrictTLS] = { { .i = 1 }, }, | |||
[Style] = { { .i = 1 }, }, | |||
[WebGL] = { { .i = 0 }, }, | |||
[ZoomLevel] = { { .f = 1.0 }, }, | |||
[ClipboardNotPrimary] = { { .i = 1 }, }, | |||
}; | |||
#define SETURI(p) { .v = (char *[]){ "/bin/sh", "-c", \ | |||
"prop=\"`surf_history_dmenu.sh`\" &&" \ | |||
"xprop -id $1 -f $0 8s -set $0 \"$prop\"", \ | |||
p, winid, NULL } } | |||
static UriParameters uriparams[] = { | |||
{ "(://|\\.)suckless\\.org(/|$)", { | |||
[JavaScript] = { { .i = 0 }, 1 }, | |||
[Plugins] = { { .i = 0 }, 1 }, | |||
}, }, | |||
}; | |||
/* default window size: width, height */ | |||
static int winsize[] = { 800, 600 }; | |||
static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | | |||
WEBKIT_FIND_OPTIONS_WRAP_AROUND; | |||
#define PROMPT_GO "Go:" | |||
#define PROMPT_FIND "Find:" | |||
/* SETPROP(readprop, setprop, prompt)*/ | |||
#define SETPROP(r, s, p) { \ | |||
.v = (const char *[]){ "/bin/sh", "-c", \ | |||
"prop=\"$(printf '%b' \"$(xprop -id $1 $2 " \ | |||
"| sed \"s/^$2(STRING) = //;s/^\\\"\\(.*\\)\\\"$/\\1/\" && cat ~/.surf/bookmarks)\" " \ | |||
"| dmenu -l 10 -p \"$4\" -w $1)\" && " \ | |||
"xprop -id $1 -f $3 8s -set $3 \"$prop\"", \ | |||
"surf-setprop", winid, r, s, p, NULL \ | |||
} \ | |||
} | |||
/* DOWNLOAD(URI, referer) */ | |||
#define DOWNLOAD(d, r) { \ | |||
.v = (char *[]){ "/bin/sh", "-c", \ | |||
"cd ~/Downloads;"\ | |||
"st -e /bin/sh -c \"aria2c -U '$1'" \ | |||
" --referer '$2' --load-cookies $3 --save-cookies $3 '$0';" \ | |||
" sleep 3;\"", \ | |||
d, useragent, r, cookiefile, NULL \ | |||
} \ | |||
} | |||
/* PLUMB(URI) */ | |||
/* This called when some URI which does not begin with "about:", | |||
* "http://" or "https://" should be opened. | |||
*/ | |||
#define PLUMB(u) {\ | |||
.v = (const char *[]){ "/bin/sh", "-c", \ | |||
"xdg-open \"$0\"", u, NULL \ | |||
} \ | |||
} | |||
/* VIDEOPLAY(URI) */ | |||
#define VIDEOPLAY(u) {\ | |||
.v = (const char *[]){ "/bin/sh", "-c", \ | |||
"mpv --really-quiet \"$0\"", u, NULL \ | |||
} \ | |||
} | |||
/* BM_ADD(readprop) */ | |||
#define BM_ADD(r) {\ | |||
.v = (const char *[]){ "/bin/sh", "-c", \ | |||
"(echo $(xprop -id $0 $1) | cut -d '\"' -f2 " \ | |||
"| sed 's/.*https*:\\/\\/\\(www\\.\\)\\?//' && cat ~/.surf/bookmarks) " \ | |||
"| awk '!seen[$0]++' > ~/.surf/bookmarks.tmp && " \ | |||
"mv ~/.surf/bookmarks.tmp ~/.surf/bookmarks", \ | |||
winid, r, NULL \ | |||
} \ | |||
} | |||
/* styles */ | |||
/* | |||
* The iteration will stop at the first match, beginning at the beginning of | |||
* the list. | |||
*/ | |||
static SiteSpecific styles[] = { | |||
/* regexp file in $styledir */ | |||
{ "google.com", "google.css" }, | |||
{ ".*", "default.css" }, | |||
}; | |||
/* certificates */ | |||
/* | |||
* Provide custom certificate for urls | |||
*/ | |||
static SiteSpecific certs[] = { | |||
/* regexp file in $certdir */ | |||
{ "://suckless\\.org/", "suckless.org.crt" }, | |||
}; | |||
#define MODKEY GDK_CONTROL_MASK | |||
static char *linkselect_curwin [] = { "/bin/sh", "-c", | |||
"surf_linkselect.sh $0 'Link' | xargs -r xprop -id $0 -f _SURF_GO 8s -set _SURF_GO", | |||
winid, NULL | |||
}; | |||
static char *linkselect_newwin [] = { "/bin/sh", "-c", | |||
"surf_linkselect.sh $0 'Link (new window)' | xargs -r /home/yigit/.scripts/tabbed_surf", | |||
winid, NULL | |||
}; | |||
static char *editscreen[] = { "/bin/sh", "-c", "edit_screen.sh", NULL }; | |||
#define WATCH {.v = (char *[]){ "/bin/sh", "-c", \ | |||
"/home/yigit/.scripts/watch_mpv.sh $(xprop -id $0 _SURF_URI | cut -d \\\" -f 2)", \ | |||
winid, NULL } } | |||
#define WALLABAG {.v = (char *[]){ "/bin/sh", "-c", \ | |||
"wallabag add $(xprop -id $0 _SURF_URI | cut -d '\"' -f 2) ; echo test > /tmp/aaa", \ | |||
winid, NULL }} | |||
/* hotkeys */ | |||
/* | |||
* If you use anything else but MODKEY and GDK_SHIFT_MASK, don't forget to | |||
* edit the CLEANMASK() macro. | |||
*/ | |||
static Key keys[] = { | |||
/* modifier keyval function arg */ | |||
{ 0, GDK_KEY_i, insert, { .i = 1 } }, | |||
{ 0, GDK_KEY_Escape, insert, { .i = 0 } }, | |||
{ 0, GDK_KEY_o, spawn, SETPROP("_SURF_URI", "_SURF_GO", PROMPT_GO) }, | |||
{ MODKEY, GDK_KEY_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, | |||
{ MODKEY, GDK_KEY_b, spawn, BM_ADD("_SURF_URI") }, | |||
{ 0, GDK_KEY_Escape, stop, { 0 } }, | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_r, reload, { .i = 1 } }, | |||
{ MODKEY, GDK_KEY_r, reload, { .i = 0 } }, | |||
{ 0, GDK_KEY_l, navigate, { .i = +1 } }, | |||
{ 0, GDK_KEY_h, navigate, { .i = -1 } }, | |||
/* vertical and horizontal scrolling, in viewport percentage */ | |||
{ 0, GDK_KEY_j, scrollv, { .i = +10 } }, | |||
{ 0, GDK_KEY_k, scrollv, { .i = -10 } }, | |||
{ 0, GDK_KEY_space, scrollv, { .i = +50 } }, | |||
{ 0, GDK_KEY_b, scrollv, { .i = -50 } }, | |||
{ 0, GDK_KEY_u, scrollh, { .i = -10 } }, | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_j, zoom, { .i = -1 } }, | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_k, zoom, { .i = +1 } }, | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_q, zoom, { .i = 0 } }, | |||
{ MODKEY, GDK_KEY_minus, zoom, { .i = -1 } }, | |||
{ MODKEY, GDK_KEY_plus, zoom, { .i = +1 } }, | |||
{ 0, GDK_KEY_p, clipboard, { .i = 1 } }, | |||
{ 0, GDK_KEY_y, clipboard, { .i = 0 } }, | |||
{ 0, GDK_KEY_n, find, { .i = +1 } }, | |||
{ GDK_SHIFT_MASK, GDK_KEY_n, find, { .i = -1 } }, | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_p, print, { 0 } }, | |||
{ MODKEY, GDK_KEY_t, showcert, { 0 } }, | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_a, togglecookiepolicy, { 0 } }, | |||
{ 0, GDK_KEY_F11, togglefullscreen, { 0 } }, | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_o, toggleinspector, { 0 } }, | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_c, toggle, { .i = CaretBrowsing } }, | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_g, toggle, { .i = Geolocation } }, | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_s, toggle, { .i = JavaScript } }, | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_i, toggle, { .i = LoadImages } }, | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_v, toggle, { .i = Plugins } }, | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_b, toggle, { .i = ScrollBars } }, | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_t, toggle, { .i = StrictTLS } }, | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_m, toggle, { .i = Style } }, | |||
{ MODKEY, GDK_KEY_d, externalpipe, { .v = linkselect_curwin } }, | |||
{ GDK_SHIFT_MASK|MODKEY, GDK_KEY_d, externalpipe, { .v = linkselect_newwin } }, | |||
{ MODKEY, GDK_KEY_o, externalpipe, { .v = editscreen } }, | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_w, spawn, WATCH }, | |||
{ MODKEY, GDK_KEY_m, spawn, WALLABAG }, | |||
{ MODKEY , GDK_KEY_Return, spawn, SETURI("_SURF_GO") }, | |||
}; | |||
/* button definitions */ | |||
/* target can be OnDoc, OnLink, OnImg, OnMedia, OnEdit, OnBar, OnSel, OnAny */ | |||
static Button buttons[] = { | |||
/* target event mask button function argument stop event */ | |||
{ OnLink, 0, 2, clicknewwindow, { .i = 0 }, 1 }, | |||
{ OnLink, MODKEY, 2, clicknewwindow, { .i = 0 }, 1 }, | |||
{ OnLink, MODKEY, 1, clicknewwindow, { .i = 0 }, 1 }, | |||
{ OnAny, 0, 8, clicknavigate, { .i = -1 }, 1 }, | |||
{ OnAny, 0, 9, clicknavigate, { .i = +1 }, 1 }, | |||
{ OnMedia, MODKEY, 1, clickexternplayer, { 0 }, 1 }, | |||
}; | |||
#define HOMEPAGE "http://localhost/Bento" |
@ -0,0 +1,32 @@ | |||
# surf version | |||
VERSION = 2.0 | |||
# Customize below to fit your system | |||
# paths | |||
PREFIX = /usr/local | |||
MANPREFIX = $(PREFIX)/share/man | |||
LIBPREFIX = $(PREFIX)/lib | |||
LIBDIR = $(LIBPREFIX)/surf | |||
X11INC = `pkg-config --cflags x11` | |||
X11LIB = `pkg-config --libs x11` | |||
GTKINC = `pkg-config --cflags gtk+-3.0 gcr-3 webkit2gtk-4.0` | |||
GTKLIB = `pkg-config --libs gtk+-3.0 gcr-3 webkit2gtk-4.0` | |||
WEBEXTINC = `pkg-config --cflags webkit2gtk-4.0 webkit2gtk-web-extension-4.0 gio-2.0` | |||
WEBEXTLIBS = `pkg-config --libs webkit2gtk-4.0 webkit2gtk-web-extension-4.0 gio-2.0` | |||
# includes and libs | |||
INCS = $(X11INC) $(GTKINC) | |||
LIBS = $(X11LIB) $(GTKLIB) -lgthread-2.0 | |||
# flags | |||
CPPFLAGS = -DVERSION=\"$(VERSION)\" -DGCR_API_SUBJECT_TO_CHANGE \ | |||
-DLIBPREFIX=\"$(LIBPREFIX)\" -DWEBEXTDIR=\"$(LIBDIR)\" \ | |||
-D_DEFAULT_SOURCE | |||
SURFCFLAGS = -fPIC $(INCS) $(CPPFLAGS) | |||
WEBEXTCFLAGS = -fPIC $(WEBEXTINC) | |||
# compiler | |||
#CC = c99 |
@ -0,0 +1,138 @@ | |||
diff --git a/config.def.h b/config.def.h | |||
index a221c86..9840736 100644 | |||
--- a/config.def.h | |||
+++ b/config.def.h | |||
@@ -32,6 +32,16 @@ static Bool hidebackground = FALSE; | |||
} \ | |||
} | |||
+#define SELNAV { \ | |||
+ .v = (char *[]){ "/bin/sh", "-c", \ | |||
+ "prop=\"`xprop -id $0 _SURF_HIST" \ | |||
+ " | sed -e 's/^.[^\"]*\"//' -e 's/\"$//' -e 's/\\\\\\n/\\n/g'" \ | |||
+ " | dmenu -i -l 10`\"" \ | |||
+ " && xprop -id $0 -f _SURF_NAV 8s -set _SURF_NAV \"$prop\"", \ | |||
+ winid, NULL \ | |||
+ } \ | |||
+} | |||
+ | |||
/* DOWNLOAD(URI, referer) */ | |||
#define DOWNLOAD(d, r) { \ | |||
.v = (char *[]){ "/bin/sh", "-c", \ | |||
@@ -67,6 +77,7 @@ static Key keys[] = { | |||
{ MODKEY, GDK_l, navigate, { .i = +1 } }, | |||
{ MODKEY, GDK_h, navigate, { .i = -1 } }, | |||
+ { MODKEY|GDK_SHIFT_MASK,GDK_h, selhist, SELNAV }, | |||
{ MODKEY, GDK_j, scroll_v, { .i = +1 } }, | |||
{ MODKEY, GDK_k, scroll_v, { .i = -1 } }, | |||
diff --git a/surf.c b/surf.c | |||
index cebd469..8b6d751 100644 | |||
--- a/surf.c | |||
+++ b/surf.c | |||
@@ -32,7 +32,7 @@ char *argv0; | |||
#define COOKIEJAR_TYPE (cookiejar_get_type ()) | |||
#define COOKIEJAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COOKIEJAR_TYPE, CookieJar)) | |||
-enum { AtomFind, AtomGo, AtomUri, AtomLast }; | |||
+enum { AtomFind, AtomGo, AtomUri, AtomHist, AtomNav, AtomLast }; | |||
typedef union Arg Arg; | |||
union Arg { | |||
@@ -137,6 +137,8 @@ static void loadstatuschange(WebKitWebView *view, GParamSpec *pspec, | |||
Client *c); | |||
static void loaduri(Client *c, const Arg *arg); | |||
static void navigate(Client *c, const Arg *arg); | |||
+static void selhist(Client *c, const Arg *arg); | |||
+static void navhist(Client *c, const Arg *arg); | |||
static Client *newclient(void); | |||
static void newwindow(Client *c, const Arg *arg, gboolean noembed); | |||
static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d); | |||
@@ -649,6 +651,59 @@ navigate(Client *c, const Arg *arg) { | |||
webkit_web_view_go_back_or_forward(c->view, steps); | |||
} | |||
+static void | |||
+selhist(Client *c, const Arg *arg) { | |||
+ WebKitWebBackForwardList *lst; | |||
+ WebKitWebHistoryItem *cur; | |||
+ gint i; | |||
+ gchar *out; | |||
+ gchar *tmp; | |||
+ gchar *line; | |||
+ | |||
+ out = g_strdup(""); | |||
+ | |||
+ if(!(lst = webkit_web_view_get_back_forward_list(c->view))) | |||
+ return; | |||
+ | |||
+ for(i = webkit_web_back_forward_list_get_back_length(lst); i > 0; i--) { | |||
+ if(!(cur = webkit_web_back_forward_list_get_nth_item(lst, -i))) | |||
+ break; | |||
+ line = g_strdup_printf("%d: %s\n", -i, | |||
+ webkit_web_history_item_get_original_uri(cur)); | |||
+ tmp = g_strconcat(out, line, NULL); | |||
+ g_free(out); | |||
+ out = tmp; | |||
+ } | |||
+ | |||
+ if((cur = webkit_web_back_forward_list_get_nth_item(lst, 0))) { | |||
+ line = g_strdup_printf("%d: %s", 0, | |||
+ webkit_web_history_item_get_original_uri(cur)); | |||
+ tmp = g_strconcat(out, line, NULL); | |||
+ g_free(out); | |||
+ out = tmp; | |||
+ } | |||
+ | |||
+ for(i = 1; i <= webkit_web_back_forward_list_get_forward_length(lst); i++) { | |||
+ if(!(cur = webkit_web_back_forward_list_get_nth_item(lst, i))) | |||
+ break; | |||
+ line = g_strdup_printf("\n%d: %s", i, | |||
+ webkit_web_history_item_get_original_uri(cur)); | |||
+ tmp = g_strconcat(out, line, NULL); | |||
+ g_free(out); | |||
+ out = tmp; | |||
+ } | |||
+ | |||
+ setatom(c, AtomHist, out); | |||
+ g_free(out); | |||
+ spawn(c, arg); | |||
+} | |||
+ | |||
+static void | |||
+navhist(Client *c, const Arg *arg) { | |||
+ Arg a = { .i = atoi(arg->v) }; | |||
+ navigate(c, &a); | |||
+} | |||
+ | |||
static Client * | |||
newclient(void) { | |||
Client *c; | |||
@@ -805,6 +860,7 @@ newclient(void) { | |||
setatom(c, AtomFind, ""); | |||
setatom(c, AtomUri, "about:blank"); | |||
+ setatom(c, AtomHist, ""); | |||
if(hidebackground) | |||
webkit_web_view_set_transparent(c->view, TRUE); | |||
@@ -923,6 +979,9 @@ processx(GdkXEvent *e, GdkEvent *event, gpointer d) { | |||
arg.v = getatom(c, AtomGo); | |||
loaduri(c, &arg); | |||
return GDK_FILTER_REMOVE; | |||
+ } else if(ev->atom == atoms[AtomNav]) { | |||
+ arg.v = getatom(c, AtomNav); | |||
+ navhist(c, &arg); | |||
} | |||
} | |||
} | |||
@@ -1004,6 +1063,8 @@ setup(void) { | |||
atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False); | |||
atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False); | |||
atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False); | |||
+ atoms[AtomHist] = XInternAtom(dpy, "_SURF_HIST", False); | |||
+ atoms[AtomNav] = XInternAtom(dpy, "_SURF_NAV", False); | |||
/* dirs and files */ | |||
cookiefile = buildpath(cookiefile); |
@ -0,0 +1,59 @@ | |||
diff --git a/config.def.h b/config.def.h | |||
index 93a3d49..05d81de 100644 | |||
--- a/config.def.h | |||
+++ b/config.def.h | |||
@@ -65,6 +65,18 @@ static Bool allowgeolocation = TRUE; | |||
} \ | |||
} | |||
+#define ONLOAD(u) { \ | |||
+ .v = (char *[]){"/bin/sh", "-c", \ | |||
+ "~/.surf/omnibar addhist \"$0\"", u, NULL \ | |||
+ } \ | |||
+} | |||
+ | |||
+#define GOTO { \ | |||
+ .v = (char *[]){"/bin/sh", "-c", \ | |||
+ "~/.surf/omnibar goto \"$0\" \"$1\"", winid, "_SURF_GO", NULL \ | |||
+ } \ | |||
+} | |||
+ | |||
/* styles */ | |||
/* | |||
* The iteration will stop at the first match, beginning at the beginning of | |||
@@ -112,7 +124,7 @@ static Key keys[] = { | |||
{ MODKEY, GDK_o, source, { 0 } }, | |||
{ MODKEY|GDK_SHIFT_MASK,GDK_o, inspector, { 0 } }, | |||
- { MODKEY, GDK_g, spawn, SETPROP("_SURF_URI", "_SURF_GO") }, | |||
+ { MODKEY, GDK_g, spawn, GOTO }, | |||
{ MODKEY, GDK_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND") }, | |||
{ MODKEY, GDK_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND") }, | |||
diff --git a/surf.c b/surf.c | |||
index f2170a4..c8fdab3 100644 | |||
--- a/surf.c | |||
+++ b/surf.c | |||
@@ -789,11 +789,11 @@ loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c) | |||
WebKitWebDataSource *src; | |||
WebKitNetworkRequest *request; | |||
SoupMessage *msg; | |||
- char *uri; | |||
+ char *uri = geturi(c); | |||
+ Arg arg; | |||
switch (webkit_web_view_get_load_status (c->view)) { | |||
case WEBKIT_LOAD_COMMITTED: | |||
- uri = geturi(c); | |||
if (strstr(uri, "https://") == uri) { | |||
frame = webkit_web_view_get_main_frame(c->view); | |||
src = webkit_web_frame_get_data_source(frame); | |||
@@ -809,6 +809,8 @@ loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c) | |||
setstyle(c, getstyle(uri)); | |||
break; | |||
case WEBKIT_LOAD_FINISHED: | |||
+ arg = (Arg)ONLOAD(uri); | |||
+ spawn(NULL, &arg); | |||
c->progress = 100; | |||
updatetitle(c); | |||
if (diskcache) { |
@ -0,0 +1,93 @@ | |||
diff --git a/surf.c b/surf.c | |||
index 93a1629..ba53b94 100644 | |||
--- a/surf.c | |||
+++ b/surf.c | |||
@@ -217,6 +217,7 @@ static void togglefullscreen(Client *c, const Arg *a); | |||
static void togglecookiepolicy(Client *c, const Arg *a); | |||
static void toggleinspector(Client *c, const Arg *a); | |||
static void find(Client *c, const Arg *a); | |||
+static void externalpipe(Client *c, const Arg *a); | |||
/* Buttons */ | |||
static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h); | |||
@@ -241,6 +242,80 @@ char *argv0; | |||
/* configuration, allows nested code to access above variables */ | |||
#include "config.h" | |||
+static void | |||
+externalpipe_execute(char* buffer, Arg *arg) { | |||
+ int to[2]; | |||
+ void (*oldsigpipe)(int); | |||
+ | |||
+ if (pipe(to) == -1) | |||
+ return; | |||
+ | |||
+ switch (fork()) { | |||
+ case -1: | |||
+ close(to[0]); | |||
+ close(to[1]); | |||
+ return; | |||
+ case 0: | |||
+ dup2(to[0], STDIN_FILENO); close(to[0]); close(to[1]); | |||
+ execvp(((char **)arg->v)[0], (char **)arg->v); | |||
+ fprintf(stderr, "st: execvp %s\n", ((char **)arg->v)[0]); | |||
+ perror("failed"); | |||
+ exit(0); | |||
+ } | |||
+ | |||
+ close(to[0]); | |||
+ oldsigpipe = signal(SIGPIPE, SIG_IGN); | |||
+ write(to[1], buffer, strlen(buffer)); | |||
+ close(to[1]); | |||
+ signal(SIGPIPE, oldsigpipe); | |||
+} | |||
+ | |||
+static void | |||
+externalpipe_resource_done(WebKitWebResource *r, GAsyncResult *s, Arg *arg) | |||
+{ | |||
+ GError *gerr = NULL; | |||
+ guchar *buffer = webkit_web_resource_get_data_finish(r, s, NULL, &gerr); | |||
+ if (gerr == NULL) { | |||
+ externalpipe_execute((char *) buffer, arg); | |||
+ } else { | |||
+ g_error_free(gerr); | |||
+ } | |||
+ g_free(buffer); | |||
+} | |||
+ | |||
+static void | |||
+externalpipe_js_done(WebKitWebView *wv, GAsyncResult *s, Arg *arg) | |||
+{ | |||
+ WebKitJavascriptResult *j = webkit_web_view_run_javascript_finish( | |||
+ wv, s, NULL); | |||
+ if (!j) { | |||
+ return; | |||
+ } | |||
+ JSCValue *v = webkit_javascript_result_get_js_value(j); | |||
+ if (jsc_value_is_string(v)) { | |||
+ char *buffer = jsc_value_to_string(v); | |||
+ externalpipe_execute(buffer, arg); | |||
+ g_free(buffer); | |||
+ } | |||
+ webkit_javascript_result_unref(j); | |||
+} | |||
+ | |||
+void | |||
+externalpipe(Client *c, const Arg *arg) | |||
+{ | |||
+ if (curconfig[JavaScript].val.i) { | |||
+ webkit_web_view_run_javascript( | |||
+ c->view, "window.document.documentElement.outerHTML", | |||
+ NULL, externalpipe_js_done, arg); | |||
+ } else { | |||
+ WebKitWebResource *resource = webkit_web_view_get_main_resource(c->view); | |||
+ if (resource != NULL) { | |||
+ webkit_web_resource_get_data( | |||
+ resource, NULL, externalpipe_resource_done, arg); | |||
+ } | |||
+ } | |||
+} | |||
+ | |||
void | |||
usage(void) | |||
{ |
@ -0,0 +1,24 @@ | |||
diff --git a/config.def.h b/config.def.h | |||
--- a/config.def.h | |||
+++ b/config.def.h | |||
@@ -164,3 +164,5 @@ static Button buttons[] = { | |||
{ OnAny, 0, 9, clicknavigate, { .i = +1 }, 1 }, | |||
{ OnMedia, MODKEY, 1, clickexternplayer, { 0 }, 1 }, | |||
}; | |||
+ | |||
+#define HOMEPAGE "https://duckduckgo.com/" | |||
diff --git a/surf.c b/surf.c | |||
--- a/surf.c | |||
+++ b/surf.c | |||
@@ -1751,7 +1751,11 @@ main(int argc, char *argv[]) | |||
if (argc > 0) | |||
arg.v = argv[0]; | |||
else | |||
+#ifdef HOMEPAGE | |||
+ arg.v = HOMEPAGE; | |||
+#else | |||
arg.v = "about:blank"; | |||
+#endif | |||
setup(); | |||
c = newclient(NULL); |
@ -0,0 +1,42 @@ | |||
diff --git a/config.def.h b/config.def.h | |||
index 2e735bf..43ad9ab 100644 | |||
--- a/config.def.h | |||
+++ b/config.def.h | |||
@@ -69,8 +69,9 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | | |||
#define SETPROP(r, s, p) { \ | |||
.v = (const char *[]){ "/bin/sh", "-c", \ | |||
"prop=\"$(printf '%b' \"$(xprop -id $1 $2 " \ | |||
- "| sed \"s/^$2(STRING) = //;s/^\\\"\\(.*\\)\\\"$/\\1/\")\" " \ | |||
- "| dmenu -p \"$4\" -w $1)\" && xprop -id $1 -f $3 8s -set $3 \"$prop\"", \ | |||
+ "| sed \"s/^$2(STRING) = //;s/^\\\"\\(.*\\)\\\"$/\\1/\" && cat ~/.surf/bookmarks)\" " \ | |||
+ "| dmenu -l 10 -p \"$4\" -w $1)\" && " \ | |||
+ "xprop -id $1 -f $3 8s -set $3 \"$prop\"", \ | |||
"surf-setprop", winid, r, s, p, NULL \ | |||
} \ | |||
} | |||
@@ -101,6 +102,17 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | | |||
} \ | |||
} | |||
+/* BM_ADD(readprop) */ | |||
+#define BM_ADD(r) {\ | |||
+ .v = (const char *[]){ "/bin/sh", "-c", \ | |||
+ "(echo $(xprop -id $0 $1) | cut -d '\"' -f2 " \ | |||
+ "| sed 's/.*https*:\\/\\/\\(www\\.\\)\\?//' && cat ~/.surf/bookmarks) " \ | |||
+ "| awk '!seen[$0]++' > ~/.surf/bookmarks.tmp && " \ | |||
+ "mv ~/.surf/bookmarks.tmp ~/.surf/bookmarks", \ | |||
+ winid, r, NULL \ | |||
+ } \ | |||
+} | |||
+ | |||
/* styles */ | |||
/* | |||
* The iteration will stop at the first match, beginning at the beginning of | |||
@@ -132,6 +144,7 @@ static Key keys[] = { | |||
{ MODKEY, GDK_KEY_g, spawn, SETPROP("_SURF_URI", "_SURF_GO", PROMPT_GO) }, | |||
{ MODKEY, GDK_KEY_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, | |||
{ MODKEY, GDK_KEY_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, | |||
+ { MODKEY, GDK_KEY_m, spawn, BM_ADD("_SURF_URI") }, | |||
{ 0, GDK_KEY_Escape, stop, { 0 } }, | |||
{ MODKEY, GDK_KEY_c, stop, { 0 } }, |
@ -0,0 +1,67 @@ | |||
From a6a8878bb6a203b589d559025b94a78214f22878 Mon Sep 17 00:00:00 2001 | |||
From: Olivier Moreau <m242@protonmail.com> | |||
Date: Sun, 12 Jan 2020 11:23:11 +0000 | |||
Subject: [PATCH] Added choice between PRIMARY and CLIPBOARD Gtk selections, as | |||
a config option | |||
--- | |||
config.def.h | 1 + | |||
surf.c | 11 +++++++++-- | |||
2 files changed, 10 insertions(+), 2 deletions(-) | |||
diff --git a/config.def.h b/config.def.h | |||
index 34265f6..03bbe2b 100644 | |||
--- a/config.def.h | |||
+++ b/config.def.h | |||
@@ -48,6 +48,7 @@ static Parameter defconfig[ParameterLast] = { | |||
[Style] = { { .i = 1 }, }, | |||
[WebGL] = { { .i = 0 }, }, | |||
[ZoomLevel] = { { .f = 1.0 }, }, | |||
+ [ClipboardNotPrimary] = { { .i = 1 }, }, | |||
}; | |||
static UriParameters uriparams[] = { | |||
diff --git a/surf.c b/surf.c | |||
index 2b54e3c..b8a9b2f 100644 | |||
--- a/surf.c | |||
+++ b/surf.c | |||
@@ -82,6 +82,7 @@ typedef enum { | |||
Style, | |||
WebGL, | |||
ZoomLevel, | |||
+ ClipboardNotPrimary, | |||
ParameterLast | |||
} ParamName; | |||
@@ -291,6 +292,7 @@ static ParamName loadcommitted[] = { | |||
SpellLanguages, | |||
Style, | |||
ZoomLevel, | |||
+ ClipboardNotPrimary, | |||
ParameterLast | |||
}; | |||
@@ -1816,13 +1818,18 @@ showcert(Client *c, const Arg *a) | |||
void | |||
clipboard(Client *c, const Arg *a) | |||
{ | |||
+ /* User defined choice of selection, see config.h */ | |||
+ GdkAtom selection = GDK_SELECTION_PRIMARY; | |||
+ if (curconfig[ClipboardNotPrimary].val.i > 0) | |||
+ selection = GDK_SELECTION_CLIPBOARD; | |||
+ | |||
if (a->i) { /* load clipboard uri */ | |||
gtk_clipboard_request_text(gtk_clipboard_get( | |||
- GDK_SELECTION_PRIMARY), | |||
+ selection), | |||
pasteuri, c); | |||
} else { /* copy uri */ | |||
gtk_clipboard_set_text(gtk_clipboard_get( | |||
- GDK_SELECTION_PRIMARY), c->targeturi | |||
+ selection), c->targeturi | |||
? c->targeturi : geturi(c), -1); | |||
} | |||
} | |||
-- | |||
2.24.1 | |||
@ -0,0 +1,107 @@ | |||
diff -up surf-2.0/config.def.h surf-2.0-history/config.def.h | |||
--- surf-2.0/config.def.h 2017-11-26 14:29:37.963786915 +0100 | |||
+++ surf-2.0-history/config.def.h 2017-11-26 19:48:31.300096237 +0100 | |||
@@ -6,6 +6,7 @@ static char *styledir = "~/.surf/s | |||
static char *certdir = "~/.surf/certificates/"; | |||
static char *cachedir = "~/.surf/cache/"; | |||
static char *cookiefile = "~/.surf/cookies.txt"; | |||
+static char *historyfile = "~/.surf/history.txt"; | |||
/* Webkit default features */ | |||
/* Highest priority value will be used. | |||
@@ -101,6 +102,11 @@ static WebKitFindOptions findopts = WEBK | |||
} \ | |||
} | |||
+#define SETURI(p) { .v = (char *[]){ "/bin/sh", "-c", \ | |||
+"prop=\"`surf_history_dmenu.sh`\" &&" \ | |||
+"xprop -id $1 -f $0 8s -set $0 \"$prop\"", \ | |||
+p, winid, NULL } } | |||
+ | |||
/* styles */ | |||
/* | |||
* The iteration will stop at the first match, beginning at the beginning of | |||
@@ -181,6 +187,7 @@ static Key keys[] = { | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_b, toggle, { .i = ScrollBars } }, | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_t, toggle, { .i = StrictTLS } }, | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_m, toggle, { .i = Style } }, | |||
+ { MODKEY , GDK_KEY_Return, spawn, SETURI("_SURF_GO") }, | |||
}; | |||
/* button definitions */ | |||
Only in surf-2.0-history/: config.h | |||
Only in surf-2.0: .git | |||
Only in surf-2.0-history/: surf | |||
diff -up surf-2.0/surf.c surf-2.0-history/surf.c | |||
--- surf-2.0/surf.c 2017-11-26 14:29:37.963786915 +0100 | |||
+++ surf-2.0-history/surf.c 2017-11-26 14:20:36.757100476 +0100 | |||
@@ -171,6 +171,7 @@ static void newwindow(Client *c, const A | |||
static void spawn(Client *c, const Arg *a); | |||
static void destroyclient(Client *c); | |||
static void cleanup(void); | |||
+static void updatehistory(const char *u, const char *t); | |||
/* GTK/WebKit */ | |||
static WebKitWebView *newview(Client *c, WebKitWebView *rv); | |||
@@ -336,10 +337,11 @@ setup(void) | |||
curconfig = defconfig; | |||
/* dirs and files */ | |||
- cookiefile = buildfile(cookiefile); | |||
- scriptfile = buildfile(scriptfile); | |||
- cachedir = buildpath(cachedir); | |||
- certdir = buildpath(certdir); | |||
+ cookiefile = buildfile(cookiefile); | |||
+ historyfile = buildfile(historyfile); | |||
+ scriptfile = buildfile(scriptfile); | |||
+ cachedir = buildpath(cachedir); | |||
+ certdir = buildpath(certdir); | |||
gdkkb = gdk_seat_get_keyboard(gdk_display_get_default_seat(gdpy)); | |||
@@ -1042,12 +1044,28 @@ cleanup(void) | |||
while (clients) | |||
destroyclient(clients); | |||
g_free(cookiefile); | |||
+ g_free(historyfile); | |||
g_free(scriptfile); | |||
g_free(stylefile); | |||
g_free(cachedir); | |||
XCloseDisplay(dpy); | |||
} | |||
+void | |||
+updatehistory(const char *u, const char *t) | |||
+{ | |||
+ FILE *f; | |||
+ f = fopen(historyfile, "a+"); | |||
+ | |||
+ char b[20]; | |||
+ time_t now = time (0); | |||
+ strftime (b, 20, "%Y-%m-%d %H:%M:%S", localtime (&now)); | |||
+ fputs(b, f); | |||
+ | |||
+ fprintf(f, " %s %s\n", u, t); | |||
+ fclose(f); | |||
+} | |||
+ | |||
WebKitWebView * | |||
newview(Client *c, WebKitWebView *rv) | |||
{ | |||
@@ -1417,6 +1435,7 @@ loadfailedtls(WebKitWebView *v, gchar *u | |||
return TRUE; | |||
} | |||
+ | |||
void | |||
loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c) | |||
{ | |||
@@ -1445,6 +1464,7 @@ loadchanged(WebKitWebView *v, WebKitLoad | |||
break; | |||
case WEBKIT_LOAD_FINISHED: | |||
seturiparameters(c, uri, loadfinished); | |||
+ updatehistory(uri, c->title); | |||
/* Disabled until we write some WebKitWebExtension for | |||
* manipulating the DOM directly. | |||
evalscript(c, "document.documentElement.style.overflow = '%s'", | |||
Only in surf-2.0-history/: surf.o |
@ -0,0 +1,134 @@ | |||
From 74a98d9600c50d50b9323cf8e459c88eb15da557 Mon Sep 17 00:00:00 2001 | |||
From: efe <efe@efe.kim> | |||
Date: Sat, 9 Feb 2019 13:16:51 -0500 | |||
Subject: [PATCH] Modal behaviour, 'i' to insert 'Esc' to get to the normal | |||
mode | |||
--- | |||
config.def.h | 53 +++++++++++++++++++++++++++------------------------- | |||
surf.c | 14 +++++++++++++- | |||
2 files changed, 41 insertions(+), 26 deletions(-) | |||
diff --git a/config.def.h b/config.def.h | |||
index 34265f6..8b7d5a2 100644 | |||
--- a/config.def.h | |||
+++ b/config.def.h | |||
@@ -130,41 +130,44 @@ static SiteSpecific certs[] = { | |||
*/ | |||
static Key keys[] = { | |||
/* modifier keyval function arg */ | |||
- { MODKEY, GDK_KEY_g, spawn, SETPROP("_SURF_URI", "_SURF_GO", PROMPT_GO) }, | |||
- { MODKEY, GDK_KEY_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, | |||
- { MODKEY, GDK_KEY_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, | |||
+ { 0, GDK_KEY_g, spawn, SETPROP("_SURF_URI", "_SURF_GO", PROMPT_GO) }, | |||
+ { 0, GDK_KEY_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, | |||
+ { 0, GDK_KEY_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, | |||
- { 0, GDK_KEY_Escape, stop, { 0 } }, | |||
- { MODKEY, GDK_KEY_c, stop, { 0 } }, | |||
+ { 0, GDK_KEY_i, insert, { .i = 1 } }, | |||
+ { 0, GDK_KEY_Escape, insert, { .i = 0 } }, | |||
- { MODKEY|GDK_SHIFT_MASK, GDK_KEY_r, reload, { .i = 1 } }, | |||
- { MODKEY, GDK_KEY_r, reload, { .i = 0 } }, | |||
+ { 0, GDK_KEY_c, stop, { 0 } }, | |||
- { MODKEY, GDK_KEY_l, navigate, { .i = +1 } }, | |||
- { MODKEY, GDK_KEY_h, navigate, { .i = -1 } }, | |||
+ { MODKEY, GDK_KEY_r, reload, { .i = 1 } }, | |||
+ { 0, GDK_KEY_r, reload, { .i = 0 } }, | |||
+ | |||
+ { 0, GDK_KEY_l, navigate, { .i = +1 } }, | |||
+ { 0, GDK_KEY_h, navigate, { .i = -1 } }, | |||
/* vertical and horizontal scrolling, in viewport percentage */ | |||
- { MODKEY, GDK_KEY_j, scrollv, { .i = +10 } }, | |||
- { MODKEY, GDK_KEY_k, scrollv, { .i = -10 } }, | |||
- { MODKEY, GDK_KEY_space, scrollv, { .i = +50 } }, | |||
- { MODKEY, GDK_KEY_b, scrollv, { .i = -50 } }, | |||
- { MODKEY, GDK_KEY_i, scrollh, { .i = +10 } }, | |||
- { MODKEY, GDK_KEY_u, scrollh, { .i = -10 } }, | |||
+ { 0, GDK_KEY_j, scrollv, { .i = +10 } }, | |||
+ { 0, GDK_KEY_k, scrollv, { .i = -10 } }, | |||
+ { 0, GDK_KEY_space, scrollv, { .i = +50 } }, | |||
+ { 0, GDK_KEY_b, scrollv, { .i = -50 } }, | |||
+ { 0, GDK_KEY_i, scrollh, { .i = +10 } }, | |||
+ { 0, GDK_KEY_u, scrollh, { .i = -10 } }, | |||
- { MODKEY|GDK_SHIFT_MASK, GDK_KEY_j, zoom, { .i = -1 } }, | |||
- { MODKEY|GDK_SHIFT_MASK, GDK_KEY_k, zoom, { .i = +1 } }, | |||
- { MODKEY|GDK_SHIFT_MASK, GDK_KEY_q, zoom, { .i = 0 } }, | |||
- { MODKEY, GDK_KEY_minus, zoom, { .i = -1 } }, | |||
- { MODKEY, GDK_KEY_plus, zoom, { .i = +1 } }, | |||
+ { 0|GDK_SHIFT_MASK, GDK_KEY_j, zoom, { .i = -1 } }, | |||
+ { 0|GDK_SHIFT_MASK, GDK_KEY_k, zoom, { .i = +1 } }, | |||
+ { 0|GDK_SHIFT_MASK, GDK_KEY_q, zoom, { .i = 0 } }, | |||
+ { 0, GDK_KEY_minus, zoom, { .i = -1 } }, | |||
+ { 0|GDK_SHIFT_MASK, GDK_KEY_plus, zoom, { .i = +1 } }, | |||
+ { 0, GDK_KEY_equal, zoom, { .i = 0 } }, | |||
- { MODKEY, GDK_KEY_p, clipboard, { .i = 1 } }, | |||
- { MODKEY, GDK_KEY_y, clipboard, { .i = 0 } }, | |||
+ { 0, GDK_KEY_p, clipboard, { .i = 1 } }, | |||
+ { 0, GDK_KEY_y, clipboard, { .i = 0 } }, | |||
- { MODKEY, GDK_KEY_n, find, { .i = +1 } }, | |||
- { MODKEY|GDK_SHIFT_MASK, GDK_KEY_n, find, { .i = -1 } }, | |||
+ { 0, GDK_KEY_n, find, { .i = +1 } }, | |||
+ { 0|GDK_SHIFT_MASK, GDK_KEY_n, find, { .i = -1 } }, | |||
- { MODKEY|GDK_SHIFT_MASK, GDK_KEY_p, print, { 0 } }, | |||
+ { MODKEY, GDK_KEY_p, print, { 0 } }, | |||
{ MODKEY, GDK_KEY_t, showcert, { 0 } }, | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_a, togglecookiepolicy, { 0 } }, | |||
diff --git a/surf.c b/surf.c | |||
index 2b54e3c..f4cbe68 100644 | |||
--- a/surf.c | |||
+++ b/surf.c | |||
@@ -175,6 +175,7 @@ static void spawn(Client *c, const Arg *a); | |||
static void msgext(Client *c, char type, const Arg *a); | |||
static void destroyclient(Client *c); | |||
static void cleanup(void); | |||
+static int insertmode = 0; | |||
/* GTK/WebKit */ | |||
static WebKitWebView *newview(Client *c, WebKitWebView *rv); | |||
@@ -231,6 +232,7 @@ static void togglefullscreen(Client *c, const Arg *a); | |||
static void togglecookiepolicy(Client *c, const Arg *a); | |||
static void toggleinspector(Client *c, const Arg *a); | |||
static void find(Client *c, const Arg *a); | |||
+static void insert(Client *c, const Arg *a); | |||
/* Buttons */ | |||
static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h); | |||
@@ -1333,7 +1335,11 @@ winevent(GtkWidget *w, GdkEvent *e, Client *c) | |||
updatetitle(c); | |||
break; | |||
case GDK_KEY_PRESS: | |||
- if (!curconfig[KioskMode].val.i) { | |||
+ if (!curconfig[KioskMode].val.i && | |||
+ !insertmode || | |||
+ CLEANMASK(e->key.state) == (MODKEY|GDK_SHIFT_MASK) || | |||
+ CLEANMASK(e->key.state) == (MODKEY) || | |||
+ gdk_keyval_to_lower(e->key.keyval) == (GDK_KEY_Escape)) { | |||
for (i = 0; i < LENGTH(keys); ++i) { | |||
if (gdk_keyval_to_lower(e->key.keyval) == | |||
keys[i].keyval && | |||
@@ -1947,6 +1953,12 @@ find(Client *c, const Arg *a) | |||
} | |||
} | |||
+void | |||
+insert(Client *c, const Arg *a) | |||
+{ | |||
+ insertmode = (a->i); | |||
+} | |||
+ | |||
void | |||
clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h) | |||
{ | |||
-- | |||
2.20.1 | |||
@ -0,0 +1,101 @@ | |||
From 8d8ca34a8e61733711e23ce43b88435bfdfd4962 Mon Sep 17 00:00:00 2001 | |||
From: knary <theknary@gmail.com> | |||
Date: Mon, 25 Mar 2019 15:03:15 -0400 | |||
Subject: [PATCH] This patch replaces scriptfile with an array of | |||
scriptfiles[]. This allows for the inclusion of multiple javascript files | |||
instead of filling up one file with multiple script plugins. | |||
--- | |||
config.def.h | 4 +++- | |||
surf.c | 23 +++++++++++++++-------- | |||
2 files changed, 18 insertions(+), 9 deletions(-) | |||
diff --git a/config.def.h b/config.def.h | |||
index 34265f6..7d7d68e 100644 | |||
--- a/config.def.h | |||
+++ b/config.def.h | |||
@@ -1,11 +1,13 @@ | |||
/* modifier 0 means no modifier */ | |||
static int surfuseragent = 1; /* Append Surf version to default WebKit user agent */ | |||
static char *fulluseragent = ""; /* Or override the whole user agent string */ | |||
-static char *scriptfile = "~/.surf/script.js"; | |||
static char *styledir = "~/.surf/styles/"; | |||
static char *certdir = "~/.surf/certificates/"; | |||
static char *cachedir = "~/.surf/cache/"; | |||
static char *cookiefile = "~/.surf/cookies.txt"; | |||
+static char *scriptfiles[] = { | |||
+ "~/.surf/script.js", | |||
+}; | |||
/* Webkit default features */ | |||
/* Highest priority value will be used. | |||
diff --git a/surf.c b/surf.c | |||
index 2b54e3c..34a75de 100644 | |||
--- a/surf.c | |||
+++ b/surf.c | |||
@@ -337,9 +337,11 @@ setup(void) | |||
/* dirs and files */ | |||
cookiefile = buildfile(cookiefile); | |||
- scriptfile = buildfile(scriptfile); | |||
cachedir = buildpath(cachedir); | |||
certdir = buildpath(certdir); | |||
+ for (i = 0; i < LENGTH(scriptfiles); i++) { | |||
+ scriptfiles[i] = buildfile(scriptfiles[i]); | |||
+ } | |||
gdkkb = gdk_seat_get_keyboard(gdk_display_get_default_seat(gdpy)); | |||
@@ -945,9 +947,11 @@ runscript(Client *c) | |||
gchar *script; | |||
gsize l; | |||
- if (g_file_get_contents(scriptfile, &script, &l, NULL) && l) | |||
- evalscript(c, "%s", script); | |||
- g_free(script); | |||
+ for (int i = 0; i < LENGTH(scriptfiles); i++) { | |||
+ if (g_file_get_contents(scriptfiles[i], &script, &l, NULL) && l) | |||
+ evalscript(c, "%s", script); | |||
+ g_free(script); | |||
+ } | |||
} | |||
void | |||
@@ -1010,9 +1014,9 @@ newwindow(Client *c, const Arg *a, int noembed) | |||
cmd[i++] = curconfig[Style].val.i ? "-M" : "-m" ; | |||
cmd[i++] = curconfig[Inspector].val.i ? "-N" : "-n" ; | |||
cmd[i++] = curconfig[Plugins].val.i ? "-P" : "-p" ; | |||
- if (scriptfile && g_strcmp0(scriptfile, "")) { | |||
+ if (scriptfiles[0] && g_strcmp0(scriptfiles[0], "")) { | |||
cmd[i++] = "-r"; | |||
- cmd[i++] = scriptfile; | |||
+ cmd[i++] = scriptfiles[0]; | |||
} | |||
cmd[i++] = curconfig[JavaScript].val.i ? "-S" : "-s"; | |||
cmd[i++] = curconfig[StrictTLS].val.i ? "-T" : "-t"; | |||
@@ -1076,9 +1080,12 @@ cleanup(void) | |||
close(pipein[0]); | |||
close(pipeout[1]); | |||
g_free(cookiefile); | |||
- g_free(scriptfile); | |||
g_free(stylefile); | |||
g_free(cachedir); | |||
+ for (int i = 0; i < LENGTH(scriptfiles); i++) { | |||
+ g_free(scriptfiles[i]); | |||
+ } | |||
+ | |||
XCloseDisplay(dpy); | |||
} | |||
@@ -2067,7 +2074,7 @@ main(int argc, char *argv[]) | |||
defconfig[Plugins].prio = 2; | |||
break; | |||
case 'r': | |||
- scriptfile = EARGF(usage()); | |||
+ scriptfiles[0] = EARGF(usage()); | |||
break; | |||
case 's': | |||
defconfig[JavaScript].val.i = 0; | |||
-- | |||
2.21.0 | |||
@ -0,0 +1,32 @@ | |||
#!/bin/sh | |||
# | |||
# See the LICENSE file for copyright and license details. | |||
# | |||
xidfile="$HOME/tmp/tabbed-surf.xid" | |||
uri="" | |||
if [ "$#" -gt 0 ]; | |||
then | |||
uri="$1" | |||
fi | |||
runtabbed() { | |||
tabbed -dn tabbed-surf -r 2 surf -e '' "$uri" >"$xidfile" \ | |||
2>/dev/null & | |||
} | |||
if [ ! -r "$xidfile" ]; | |||
then | |||
runtabbed | |||
else | |||
xid=$(cat "$xidfile") | |||
xprop -id "$xid" >/dev/null 2>&1 | |||
if [ $? -gt 0 ]; | |||
then | |||
runtabbed | |||
else | |||
surf -e "$xid" "$uri" >/dev/null 2>&1 & | |||
fi | |||
fi | |||
@ -0,0 +1,26 @@ | |||
diff --git a/config.def.h b/config.def.h | |||
index 6d3135e..75dc6a6 100644 | |||
--- a/config.def.h | |||
+++ b/config.def.h | |||
@@ -153,6 +153,8 @@ static Key keys[] = { | |||
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_m, toggle, { .i = Style } }, | |||
}; | |||
+static char *searchengine = "https://duckduckgo.com/?q="; | |||
+ | |||
/* button definitions */ | |||
/* target can be OnDoc, OnLink, OnImg, OnMedia, OnEdit, OnBar, OnSel, OnAny */ | |||
static Button buttons[] = { | |||
diff --git a/surf.c b/surf.c | |||
index 93a1629..c20537e 100644 | |||
--- a/surf.c | |||
+++ b/surf.c | |||
@@ -476,6 +476,8 @@ loaduri(Client *c, const Arg *a) | |||
} else if (!stat(uri, &st) && (path = realpath(uri, NULL))) { | |||
url = g_strdup_printf("file://%s", path); | |||
free(path); | |||
+ } else if (*uri == ' ') { | |||
+ url = g_strdup_printf("%s%s", searchengine, uri + 1); | |||
} else { | |||
url = g_strdup_printf("http://%s", uri); | |||
} |
@ -0,0 +1,138 @@ | |||
diff --git a/config.def.h b/config.def.h | |||
index 5245129..604028f 100644 | |||
--- a/config.def.h | |||
+++ b/config.def.h | |||
@@ -45,6 +45,16 @@ static Bool allowgeolocation = TRUE; | |||
} \ | |||
} | |||
+#define SELNAV { \ | |||
+ .v = (char *[]){ "/bin/sh", "-c", \ | |||
+ "prop=\"`xprop -id $0 _SURF_HIST" \ | |||
+ " | sed -e 's/^.[^\"]*\"//' -e 's/\"$//' -e 's/\\\\\\n/\\n/g'" \ | |||
+ " | dmenu -i -l 10`\"" \ | |||
+ " && xprop -id $0 -f _SURF_NAV 8s -set _SURF_NAV \"$prop\"", \ | |||
+ winid, NULL \ | |||
+ } \ | |||
+} | |||
+ | |||
/* DOWNLOAD(URI, referer) */ | |||
#define DOWNLOAD(d, r) { \ | |||
.v = (char *[]){ "/bin/sh", "-c", \ | |||
@@ -99,6 +109,7 @@ static Key keys[] = { | |||
{ MODKEY, GDK_l, navigate, { .i = +1 } }, | |||
{ MODKEY, GDK_h, navigate, { .i = -1 } }, | |||
+ { MODKEY|GDK_SHIFT_MASK,GDK_h, selhist, SELNAV }, | |||
{ MODKEY, GDK_j, scroll_v, { .i = +1 } }, | |||
{ MODKEY, GDK_k, scroll_v, { .i = -1 } }, | |||
diff --git a/surf.c b/surf.c | |||
index 0fae80b..1c09336 100644 | |||
--- a/surf.c | |||
+++ b/surf.c | |||
@@ -36,7 +36,7 @@ char *argv0; | |||
#define COOKIEJAR_TYPE (cookiejar_get_type ()) | |||
#define COOKIEJAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COOKIEJAR_TYPE, CookieJar)) | |||
-enum { AtomFind, AtomGo, AtomUri, AtomLast }; | |||
+enum { AtomFind, AtomGo, AtomUri, AtomHist, AtomNav, AtomLast }; | |||
enum { | |||
ClkDoc = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT, | |||
ClkLink = WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK, | |||
@@ -177,6 +177,8 @@ static void loadstatuschange(WebKitWebView *view, GParamSpec *pspec, | |||
Client *c); | |||
static void loaduri(Client *c, const Arg *arg); | |||
static void navigate(Client *c, const Arg *arg); | |||
+static void selhist(Client *c, const Arg *arg); | |||
+static void navhist(Client *c, const Arg *arg); | |||
static Client *newclient(void); | |||
static void newwindow(Client *c, const Arg *arg, gboolean noembed); | |||
static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d); | |||
@@ -813,6 +815,59 @@ navigate(Client *c, const Arg *arg) { | |||
webkit_web_view_go_back_or_forward(c->view, steps); | |||
} | |||
+static void | |||
+selhist(Client *c, const Arg *arg) { | |||
+ WebKitWebBackForwardList *lst; | |||
+ WebKitWebHistoryItem *cur; | |||
+ gint i; | |||
+ gchar *out; | |||
+ gchar *tmp; | |||
+ gchar *line; | |||
+ | |||
+ out = g_strdup(""); | |||
+ | |||
+ if(!(lst = webkit_web_view_get_back_forward_list(c->view))) | |||
+ return; | |||
+ | |||
+ for(i = webkit_web_back_forward_list_get_back_length(lst); i > 0; i--) { | |||
+ if(!(cur = webkit_web_back_forward_list_get_nth_item(lst, -i))) | |||
+ break; | |||
+ line = g_strdup_printf("%d: %s\n", -i, | |||
+ webkit_web_history_item_get_original_uri(cur)); | |||
+ tmp = g_strconcat(out, line, NULL); | |||
+ g_free(out); | |||
+ out = tmp; | |||
+ } | |||
+ | |||
+ if((cur = webkit_web_back_forward_list_get_nth_item(lst, 0))) { | |||
+ line = g_strdup_printf("%d: %s", 0, | |||
+ webkit_web_history_item_get_original_uri(cur)); | |||
+ tmp = g_strconcat(out, line, NULL); | |||
+ g_free(out); | |||
+ out = tmp; | |||
+ } | |||
+ | |||
+ for(i = 1; i <= webkit_web_back_forward_list_get_forward_length(lst); i++) { | |||
+ if(!(cur = webkit_web_back_forward_list_get_nth_item(lst, i))) | |||
+ break; | |||
+ line = g_strdup_printf("\n%d: %s", i, | |||
+ webkit_web_history_item_get_original_uri(cur)); | |||
+ tmp = g_strconcat(out, line, NULL); | |||
+ g_free(out); | |||
+ out = tmp; | |||
+ } | |||
+ | |||
+ setatom(c, AtomHist, out); | |||
+ g_free(out); | |||
+ spawn(c, arg); | |||
+} | |||
+ | |||
+static void | |||
+navhist(Client *c, const Arg *arg) { | |||
+ Arg a = { .i = atoi(arg->v) }; | |||
+ navigate(c, &a); | |||
+} | |||
+ | |||
static Client * | |||
newclient(void) { | |||
Client *c; | |||
@@ -1014,6 +1069,7 @@ newclient(void) { | |||
setatom(c, AtomFind, ""); | |||
setatom(c, AtomUri, "about:blank"); | |||
+ setatom(c, AtomHist, ""); | |||
if(hidebackground) | |||
webkit_web_view_set_transparent(c->view, TRUE); | |||
@@ -1153,6 +1209,9 @@ processx(GdkXEvent *e, GdkEvent *event, gpointer d) { | |||
loaduri(c, &arg); | |||
return GDK_FILTER_REMOVE; | |||
+ } else if(ev->atom == atoms[AtomNav]) { | |||
+ arg.v = getatom(c, AtomNav); | |||
+ navhist(c, &arg); | |||
} | |||
} | |||
} | |||
@@ -1247,6 +1306,8 @@ setup(void) { | |||
atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False); | |||
atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False); | |||
atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False); | |||
+ atoms[AtomHist] = XInternAtom(dpy, "_SURF_HIST", False); | |||
+ atoms[AtomNav] = XInternAtom(dpy, "_SURF_NAV", False); | |||
/* dirs and files */ | |||
cookiefile = buildfile(cookiefile); |
@ -0,0 +1,330 @@ | |||
.TH SURF 1 surf\-VERSION | |||
.SH NAME | |||
surf \- simple webkit-based browser | |||
.SH SYNOPSIS | |||
.B surf | |||
.RB [-bBdDfFgGiIkKmMnNpPsStTvwxX] | |||
.RB [-a\ cookiepolicies] | |||
.RB [-c\ cookiefile] | |||
.RB [-C\ stylefile] | |||
.RB [-e\ xid] | |||
.RB [-r\ scriptfile] | |||
.RB [-u\ useragent] | |||
.RB [-z\ zoomlevel] | |||
.RB [URI] | |||
.SH DESCRIPTION | |||
surf is a simple Web browser based on WebKit/GTK+. It is able | |||
to display websites and follow links. It supports the XEmbed protocol | |||
which makes it possible to embed it in another application. Furthermore, | |||
one can point surf to another URI by setting its XProperties. | |||
.SH OPTIONS | |||
.TP | |||
.B \-a cookiepolicies | |||
Define the order of | |||
.I cookie policies\fR. | |||
The default is "@Aa" but could be | |||
redefined in the | |||
.IR config.h , | |||
with "A" meaning to | |||
accept all cookies, "a" to deny all cookies and "@", which tells surf to | |||
accept no third party cookies. | |||
.TP | |||
.B \-b | |||
Disable Scrollbars. | |||
.TP | |||
.B \-B | |||
Enable Scrollbars. | |||
.TP | |||
.B \-c cookiefile | |||
Specify the | |||
.I cookiefile | |||
to use. | |||
.TP | |||
.B \-C stylefile | |||
Specify the user | |||
.IR stylefile . | |||
This does disable the site-specific styles. | |||
.TP | |||
.B \-d | |||
Disable the disk cache. | |||
.TP | |||
.B \-D | |||
Enable the disk cache. | |||
.TP | |||
.B \-e xid | |||
Reparents to window specified by | |||
.IR xid . | |||
.TP | |||
.B \-f | |||
Start surf in windowed mode (not fullscreen). | |||
.TP | |||
.B \-F | |||
Start surf in fullscreen mode. | |||
.TP | |||
.B \-g | |||
Disable giving the geolocation to websites. | |||
.TP | |||
.B \-G | |||
Enable giving the geolocation to websites. | |||
.TP | |||
.B \-i | |||
Disable Images. | |||
.TP | |||
.B \-I | |||
Enable Images. | |||
.TP | |||
.B \-k | |||
Disable kiosk mode (disable key strokes and right click). | |||
.TP | |||
.B \-K | |||
Enable kiosk mode (disable key strokes and right click). | |||
.TP | |||
.B \-m | |||
Disable application of user style sheets. | |||
.TP | |||
.B \-M | |||
Enable application of user style sheets. | |||
.TP | |||
.B \-n | |||
Disable the Web Inspector (Developer Tools). | |||
.TP | |||
.B \-N | |||
Enable the Web Inspector (Developer Tools). | |||
.TP | |||
.B \-p | |||
Disable Plugins. | |||
.TP | |||
.B \-P | |||
Enable Plugins. | |||
.TP | |||
.B \-r scriptfile | |||
Specify the user | |||
.IR scriptfile . | |||
.TP | |||
.B \-s | |||
Disable Javascript. | |||
.TP | |||
.B \-S | |||
Enable Javascript. | |||
.TP | |||
.B \-t | |||
Disable strict TLS check. | |||
.TP | |||
.B \-T | |||
Enable strict TLS check. | |||
.TP | |||
.B \-u useragent | |||
Specify the | |||
.I useragent | |||
which surf should use. | |||
.TP | |||
.B \-v | |||
Prints version information to standard output, then exits. | |||
.TP | |||
.B \-w | |||
Prints xid to standard output. This can be used to script the browser in for | |||
example | |||
.BR xdotool(1) . | |||
.TP | |||
.B -x | |||
Disable custom certificates. | |||
.TP | |||
.B -X | |||
Enable custom certificates. | |||
.TP | |||
.B \-z zoomlevel | |||
Specify the | |||
.I zoomlevel | |||
which surf should use. | |||
.SH USAGE | |||
.B Escape | |||
Stops loading current page or stops download. | |||
.TP | |||
.B Ctrl\-h | |||
Walks back the history. | |||
.TP | |||
.B Ctrl\-l | |||
Walks forward the history. | |||
.TP | |||
.B Ctrl\-k | |||
Scrolls page upwards. | |||
.TP | |||
.B Ctrl\-j | |||
Scrolls page downwards. | |||
.TP | |||
.B Ctrl\-b | |||
Scroll up one whole page view. | |||
.TP | |||
.B Ctrl\-Space | |||
Scroll down one whole page view. | |||
.TP | |||
.B Ctrl\-i | |||
Scroll horizontally to the right. | |||
.TP | |||
.B Ctrl\-u | |||
Scroll horizontally to the left. | |||
.TP | |||
.B Ctrl\-Shift\-k or Ctrl\-+ | |||
Zooms page in. | |||
.TP | |||
.B Ctrl\-Shift\-j or Ctrl\-- | |||
Zooms page out. | |||
.TP | |||
.B Ctrl\-Shift\-q | |||
Resets Zoom. | |||
.TP | |||
.B Ctrl\-f and Ctrl\-/ | |||
Opens the search-bar. | |||
.TP | |||
.B Ctrl\-n | |||
Go to next search result. | |||
.TP | |||
.B Ctrl\-Shift\-n | |||
Go to previous search result. | |||
.TP | |||
.B Ctrl\-g | |||
Opens the URL-bar (requires dmenu installed). | |||
.TP | |||
.B Ctrl\-p | |||
Loads URI from primary selection. | |||
.TP | |||
.B Ctrl\-Shift\-p | |||
Calls Printpage Dialog. | |||
.TP | |||
.B Ctrl\-r | |||
Reloads the website. | |||
.TP | |||
.B Ctrl\-Shift\-r | |||
Reloads the website without using the cache. | |||
.TP | |||
.B Ctrl\-y | |||
Copies current URI to primary selection. | |||
.TP | |||
.B Ctrl\-t | |||
Display the current TLS certificate in a popup window. | |||
.TP | |||
.B Ctrl\-Shift\-a | |||
Toggle through the the | |||
.I cookie policies\fR. | |||
This will not reload the page. | |||
.TP | |||
.B Ctrl\-Shift\-b | |||
Toggle scrollbars. This will reload the page. | |||
.TP | |||
.B Ctrl\-Shift\-c | |||
Toggle caret browsing. This will reload the page. | |||
.TP | |||
.B Ctrl\-Shift\-i | |||
Toggle auto-loading of images. This will reload the page. | |||
.TP | |||
.B Ctrl\-Shift\-m | |||
Toggle if the | |||
.I stylefile | |||
file should be loaded. This will reload the page. | |||
.TP | |||
.B Ctrl\-Shift\-o | |||
Open the Web Inspector (Developer Tools) window for the current page. | |||
.TP | |||
.B Ctrl\-Shift\-s | |||
Toggle script execution. This will reload the page. | |||
.TP | |||
.B Ctrl\-Shift\-t | |||
Toggle strict TLS check. This will reload the page. | |||
.TP | |||
.B Ctrl\-Shift\-v | |||
Toggle the enabling of plugins on that surf instance. This will reload the | |||
page. | |||
.TP | |||
.B F11 | |||
Toggle fullscreen mode. | |||
.SH INDICATORS OF OPERATION | |||
Surf is showing indicators of operation in front of the site title. | |||
For all indicators, unless otherwise specified, a lower case letter means disabled and an upper case letter means enabled. | |||
.TP | |||
.B A | |||
all cookies accepted | |||
.TP | |||
.B a | |||
no cookies accepted | |||
.TP | |||
.B @ | |||
all except third-party cookies accepted | |||
.TP | |||
.B c C | |||
caret browsing | |||
.TP | |||
.B g G | |||
geolocation | |||
.TP | |||
.B d D | |||
disk cache | |||
.TP | |||
.B i I | |||
images | |||
.TP | |||
.B s S | |||
scripts | |||
.TP | |||
.B v V | |||
plugins | |||
.TP | |||
.B m M | |||
styles | |||
.TP | |||
.B f F | |||
frame flattening | |||
.TP | |||
.B x X | |||
custom certificates | |||
.TP | |||
.B t T | |||
strict TLS | |||
.SH INDICATORS OF WEB PAGE | |||
The second part of the indicators specifies modes of the web page itself. | |||
.SS First character: encryption | |||
.TP | |||
.B - | |||
unencrypted | |||
.TP | |||
.B T | |||
encrypted (TLS) | |||
.TP | |||
.B U | |||
attempted encryption but failed | |||
.SS Second character: proxying | |||
.TP | |||
.B - | |||
no proxy | |||
.TP | |||
.B P | |||
using proxy | |||
.SH ENVIRONMENT | |||
.B SURF_USERAGENT | |||
If this variable is set upon startup, surf will use it as the | |||
.I useragent | |||
string. | |||
.TP | |||
.B http_proxy | |||
If this variable is set and not empty upon startup, surf will use it as the http proxy. | |||
.SH SIGNALS | |||
Surf will reload the current page on | |||
.BR SIGHUP . | |||
.SH PLUGINS | |||
For using plugins in surf, first determine your running architecture. Then get | |||
the appropriate plugin for that architecture and copy it to | |||
.BR /usr/lib/browser-plugins | |||
or | |||
.BR /usr/lib64/browser-plugins. | |||
Surf should load them automatically. | |||
.BR | |||
If you want to use a 32bit plugin on a 64bit system, | |||
.BR nspluginwrapper(1) | |||
will help you. | |||
.SH SEE ALSO | |||
.BR dmenu(1), | |||
.BR xprop(1), | |||
.BR tabbed(1), | |||
.BR nspluginwrapper(1), | |||
.BR xdotool(1) | |||
.SH BUGS | |||
Please report them! |
@ -0,0 +1,106 @@ | |||
#include <sys/socket.h> | |||
#include <sys/stat.h> | |||
#include <fcntl.h> | |||
#include <inttypes.h> | |||
#include <limits.h> | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include <gio/gio.h> | |||
#include <webkit2/webkit-web-extension.h> | |||
#include <webkitdom/webkitdom.h> | |||
#include <webkitdom/WebKitDOMDOMWindowUnstable.h> | |||
#include "common.h" | |||
#define LENGTH(x) (sizeof(x) / sizeof(x[0])) | |||
static WebKitWebExtension *webext; | |||
static int sock; | |||
static void | |||
msgsurf(guint64 pageid, const char *s) | |||
{ | |||
static char msg[MSGBUFSZ]; | |||
size_t sln = strlen(s); | |||
int ret; | |||
if ((ret = snprintf(msg, sizeof(msg), "%c%s", pageid, s)) | |||
>= sizeof(msg)) { | |||
fprintf(stderr, "webext: msg: message too long: %d\n", ret); | |||
return; | |||
} | |||
if (send(sock, msg, ret, 0) < 0) | |||
fprintf(stderr, "webext: error sending: %s\n", msg+1); | |||
} | |||
static gboolean | |||
readsock(GIOChannel *s, GIOCondition c, gpointer unused) | |||
{ | |||
static char js[48], msg[MSGBUFSZ]; | |||
WebKitWebPage *page; | |||
JSCContext *jsc; | |||
GError *gerr = NULL; | |||
gsize msgsz; | |||
if (g_io_channel_read_chars(s, msg, sizeof(msg), &msgsz, &gerr) != | |||
G_IO_STATUS_NORMAL) { | |||
if (gerr) { | |||
fprintf(stderr, "webext: error reading socket: %s\n", | |||
gerr->message); | |||
g_error_free(gerr); | |||
} | |||
return TRUE; | |||
} | |||
if (msgsz < 2) { | |||
fprintf(stderr, "webext: readsock: message too short: %d\n", | |||
msgsz); | |||
return TRUE; | |||
} | |||
if (!(page = webkit_web_extension_get_page(webext, msg[0]))) | |||
return TRUE; | |||
jsc = webkit_frame_get_js_context(webkit_web_page_get_main_frame(page)); | |||
switch (msg[1]) { | |||
case 'h': | |||
if (msgsz != 3) | |||
return TRUE; | |||
snprintf(js, sizeof(js), | |||
"window.scrollBy(window.innerWidth/100*%d,0);", | |||
msg[2]); | |||
jsc_context_evaluate(jsc, js, -1); | |||
break; | |||
case 'v': | |||
if (msgsz != 3) | |||
return TRUE; | |||
snprintf(js, sizeof(js), | |||
"window.scrollBy(0,window.innerHeight/100*%d);", | |||
msg[2]); | |||
jsc_context_evaluate(jsc, js, -1); | |||
break; | |||
} | |||
return TRUE; | |||
} | |||
G_MODULE_EXPORT void | |||
webkit_web_extension_initialize_with_user_data(WebKitWebExtension *e, | |||
const GVariant *gv) | |||
{ | |||
GIOChannel *gchansock; | |||
webext = e; | |||
g_variant_get(gv, "i", &sock); | |||
gchansock = g_io_channel_unix_new(sock); | |||
g_io_channel_set_encoding(gchansock, NULL, NULL); | |||
g_io_channel_set_flags(gchansock, g_io_channel_get_flags(gchansock) | |||
| G_IO_FLAG_NONBLOCK, NULL); | |||
g_io_channel_set_close_on_unref(gchansock, TRUE); | |||
g_io_add_watch(gchansock, G_IO_IN, readsock, NULL); | |||
} |
@ -1,22 +0,0 @@ | |||
tabbed - generic tabbed interface | |||
================================= | |||
tabbed is a simple tabbed X window container. | |||
Requirements | |||
------------ | |||
In order to build tabbed you need the Xlib header files. | |||
Installation | |||
------------ | |||
Edit config.mk to match your local setup (tabbed is installed into | |||
the /usr/local namespace by default). | |||
Afterwards enter the following command to build and install tabbed | |||
(if necessary as root): | |||
make clean install | |||
Running tabbed | |||
-------------- | |||
See the man page for details. | |||