add files

This commit is contained in:
nya 2021-04-13 04:20:34 -05:00
parent cb3f1de4b4
commit 80c972ba89
22 changed files with 13437 additions and 9 deletions

75
.config/dunst/dunstrc Normal file
View File

@ -0,0 +1,75 @@
[global]
follow = mouse
geometry = "300x5-30+20"
indicate_hidden = yes
shrink = no
transparency = 0
notification_height = 0
separator_height = 2
padding = 8
horizontal_padding = 8
frame_width = 3
frame_color = "#aaaaaa"
separator_color = frame
sort = yes
idle_threshold = 120
font = Monospace 8
line_height = 0
markup = full
format = "<b>%a</b>\n<b>%s</b>\n%b"
alignment = left
show_age_threshold = 60
word_wrap = yes
ignore_newline = no
stack_duplicates = true
hide_duplicate_count = false
show_indicators = yes
icon_position = off
max_icon_size = 32
icon_path = /usr/share/icons/gnome/16x16/status/:/usr/share/icons/gnome/16x16/devices/
sticky_history = yes
history_length = 20
dmenu = /usr/bin/dmenu -p dunst:
browser = /usr/bin/firefox-bin -new-tab
always_run_script = true
title = Dunst
class = Dunst
startup_notification = false
verbosity = mesg
corner_radius = 4
mouse_left_click = close_current
mouse_middle_click = none
mouse_right_click = close_all
[shortcuts]
close = ctrl+space
close_all = ctrl+shift+space
history = ctrl+grave
context = ctrl+shift+period
[urgency_low]
background = "#222222"
foreground = "#888888"
timeout = 10
#icon = /path/to/icon
[urgency_normal]
background = "#285577"
foreground = "#ffffff"
timeout = 10
#icon = /path/to/icon
[urgency_critical]
background = "#900000"
foreground = "#ffffff"
frame_color = "#ff0000"
timeout = 0
#icon = /path/to/icon

95
.config/herbstluftwm/autostart Executable file
View File

@ -0,0 +1,95 @@
#!/usr/bin/env bash
hc() {
herbstclient "$@"
}
hc emit_hook reload
hc keyunbind --all
hc mouseunbind --all
hc unrule -F
Mod=Mod4
emacs_proc="ps -aux | grep 'emacs --bg-daemon' | sed '/grep --colour/d"
resizestep=0.05
screenshot="$HOME/bin/screenshot.sh"
tag_names=( {1..9} )
tag_keys=( {1..9} 0 )
term="sakura"
hc keybind $Mod-r reload
hc keybind $Mod-e close
hc keybind $Mod-Return spawn ${term}
hc keybind $Mod-d spawn dmenu_run
hc keybind $Mod-Print spawn ${screenshot}
hc keybind $Mod-Left focus left
hc keybind $Mod-Down focus down
hc keybind $Mod-Up focus up
hc keybind $Mod-Right focus right
hc keybind $Mod-Shift-Left shift left
hc keybind $Mod-Shift-Down shift down
hc keybind $Mod-Shift-Up shift up
hc keybind $Mod-Shift-Right shift right
hc keybind $Mod-u split bottom 0.5
hc keybind $Mod-o split right 0.5
hc keybind $Mod-Control-Left resize left +$resizestep
hc keybind $Mod-Control-Down resize down +$resizestep
hc keybind $Mod-Control-Up resize up +$resizestep
hc keybind $Mod-Control-Right resize right +$resizestep
hc rename default "${tag_names[0]}" || true
for i in ${!tag_names[@]} ; do
hc add "${tag_names[$i]}"
key="${tag_keys[$i]}"
if ! [ -z "$key" ] ; then
hc keybind "$Mod-$key" use_index "$i"
hc keybind "$Mod-Shift-$key" move_index "$i"
fi
done
hc keybind $Mod-period use_index +1 --skip-visible
hc keybind $Mod-comma use_index -1 --skip-visible
hc keybind $Mod-Shift-r remove
hc keybind $Mod-s floating toggle
hc keybind $Mod-f fullscreen toggle
hc keybind $Mod-p pseudotile toggle
hc keybind $Mod-Shift-space attr clients.focus.floating toggle
hc keybind $Mod-space \
or , and . compare tags.focus.curframe_wcount = 2 \
. cycle_layout +1 vertical horizontal max vertical grid \
, cycle_layout +1
hc mousebind $Mod-Button1 move
hc mousebind $Mod-Button3 resize
hc keybind $Mod-Tab cycle_all +1
hc keybind $Mod-Shift-Tab cycle_all -1
hc keybind $Mod-c cycle
hc keybind $Mod-i jumpto urgent
hc pad 0 4 4 36 4
hc set window_gap 1
hc set frame_gap 1
hc set frame_bg_transparent 1
hc attr theme.floating.reset 1
hc attr theme.floating.border_width 3
hc attr theme.floating.outer_width 2
hc attr theme.floating.outer_color '#fefefe'
hc rule class=sakura tag=4
hc rule focus=on
hc rule windowtype~'_NET_WM_WINDOW_TYPE_(DIALOG|UTILITY|SPLASH)' floating=on
hc rule windowtype='_NET_WM_WINDOW_TYPE_DIALOG' focus=on
hc rule windowtype~'_NET_WM_WINDOW_TYPE_(NOTIFICATION|DOCK|DESKTOP)' manage=off
hc set tree_style '╾│ ├└╼─┐'
hc unlock
feh --bg-scale ~/bg/wall_2.jpg &
if [ ! $(pidof dunst) ]; then
dunst & dunstify -t '2500' 'dunst started!'
if [ ! $(emacs_proc) ]; then
emacs --bg-daemon & dunstify -t '3000' 'emacs daemon started!'
fi
fi

5
.config/picom/picom.conf Normal file
View File

@ -0,0 +1,5 @@
backend = "xrender";
vsync = true;
unredir-if-possible = true;
glx-no-stencil = true;
use-damage = false;

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<channel name="xfce4-session" version="1.0">
<property name="general" type="empty">
<property name="FailsafeSessionName" type="empty"/>
<property name="LockCommand" type="empty"/>
<property name="SessionName" type="string" value="Default"/>
<property name="SaveOnExit" type="bool" value="false"/>
<property name="PromptOnLogout" type="bool" value="false"/>
</property>
<property name="sessions" type="empty">
<property name="Failsafe" type="empty">
<property name="IsFailsafe" type="empty"/>
<property name="Count" type="int" value="3"/>
<property name="Client0_Command" type="array">
<value type="string" value="xfsettingsd"/>
</property>
<property name="Client0_Priority" type="empty"/>
<property name="Client0_PerScreen" type="empty"/>
<property name="Client1_Command" type="array">
<value type="string" value="herbstluftwm"/>
</property>
<property name="Client1_Priority" type="empty"/>
<property name="Client1_PerScreen" type="empty"/>
<property name="Client2_Command" type="array">
<value type="string" value="xfce4-panel"/>
</property>
<property name="Client2_Priority" type="empty"/>
<property name="Client2_PerScreen" type="bool" value="true"/>
<property name="Client3_Command" type="array">
<value type="string" value="xfdesktop --disable-wm-check"/>
</property>
<property name="Client3_Priority" type="empty"/>
<property name="Client3_PerScreen" type="empty"/>
<property name="Client4_Command" type="array">
<value type="string" value=""/>
</property>
<property name="Client4_Priority" type="empty"/>
<property name="Client4_PerScreen" type="empty"/>
</property>
</property>
</channel>

4
bin/screenshot.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
# screenshot.sh: use maim+slop to take a screenshot
TIMESTAMP=$(date +"%m-%d-%Y-%T");
notify-send -t 0 "image captured" "$(maim -m 10 -g $(slop) ~/Pictures/$TIMESTAMP.jpg)"

View File

@ -0,0 +1,2 @@
#!/bin/sh
echo '0f' > /sys/kernel/debug/dri/1/pstate

6
etc/local.d/zram.start Normal file
View File

@ -0,0 +1,6 @@
#!/bin/sh
size="8G"
modprobe zram
echo $size > /sys/block/zram0/disksize
mkswap /dev/zram0
swapon -v /dev/zram0 & echo "zram enabled"

3
etc/local.d/zram.stop Normal file
View File

@ -0,0 +1,3 @@
swapoff -v /dev/zram0 & echo "zram disabled"
echo 1 > /sys/block/zram0/reset
modprobe -r zram

View File

@ -1,27 +1,31 @@
COMMON_FLAGS="-O2 -pipe -march=native -mtune=ivybridge"
MAKEOPTS="-j6 -l8"
#MAKEOPTS="-j6"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"
#CHOST="x86_64-gentoo-linux-musl"
## uncomment for use with musl. be sure to select the musl profile
## and enable the gentoo musl overlay.
# CHOST="x86_64-gentoo-linux-musl"
PORTDIR="/var/db/repos/gentoo"
DISTDIR="/var/cache/distfiles"
PKGDIR="/var/cache/binpkgs"
LC_MESSAGES=C
EMERGE_DEFAULT_OPTS="-a -v -t"
FEATURES="candy collision-protect parallel-fetch"
## portage settings
EMERGE_DEFAULT_OPTS="--ask --verbose --tree --deep"
PORTAGE_SYNC_STALE="3"
FEATURES="candy collision-protect network-sandbox parallel-fetch sandbox"
# organize useflags
## organize useflags
AUDIO_FLAGS="aac alsa -cdda flac mp3 mp4 ogg pulseaudio vorbis x264"
MEDIA_FLAGS="gif imlib jpeg png svg tiff truetype unicode"
VIDEO_FLAGS="acpi cairo -cdr dri gles2 opengl -ogre sdl vulkan -wayland X"
SYSTEM_FLAGS="bluetooth -branding -cups dbus elogind -geolocation -gnome gtk gtk3 gpm icu
libnotify -netifrc networkmanager policykit -systemd threads udev xml"
SYSTEM_FLAGS="bluetooth -branding -cups dbus elogind -geolocation -gnome gtk
gtk3 gpm icu -netifrc networkmanager policykit -systemd threads udev upower udisks xml"
GPU="intel nouveau i915 i965"
USE="${AUDIO_FLAGS} ${MEDIA_FLAGS} ${VIDEO_FLAGS} ${SYSTEM_FLAGS}"
VIDEO_CARDS="intel i915 i965 nouveau"
VIDEO_CARDS="${GPU}"
INPUT_DEVICES="libinput synaptics"
PYTHON_TARGETS="python3_8"

View File

@ -0,0 +1,12 @@
sys-kernel/vanilla-kernel ~amd64
virtual/dist-kernel ~amd64
www-client/qutebrowser ~amd64
games-action/multimc5 **
games-engines/openmw **
dev-games/recastnavigation ~amd64
dev-games/openscenegraph-openmw ~amd64
dev-lang/rust ~amd64
virtual/rust ~amd64
>=x11-misc/dmenu-5.0 ~amd64
x11-wm/herbstluftwm ~amd64
x11-libs/libdrm ~amd64

View File

@ -0,0 +1,4 @@
# linux-firmware licenses
sys-kernel/linux-firmware linux-fw-redistributable no-source-code
# berry font
media-fonts/berry unknown

63
etc/portage/package.use Normal file
View File

@ -0,0 +1,63 @@
# rust useflags
dev-lang/rust nightly parallel-compiler system-llvm
# qemu useflags
app-emulation/qemu aio alsa bzip2 caps curl fdt filecaps gnutls gtk io-uring jemalloc jpeg lzo numaopengl pin-upstream-blobs plugins pulseaudio sdl seccomp spice udev usb usbredir vhost-net vhost-user-fs virgl vnc vde vte xattr -debug -doc -glusterfs -iscsi -infiniband -nfs -rbd -sasl -sdl-image -smartcard -static -static-user -snappy -test -virtfs -xen -xfs
# libvirt useflags
app-emulation/libvirt caps fuse libssh libvirtd numa qemu udev virt-network -apparmor -dtrace -firewalld -glusterfs -iscsi -iscsi-direct -lvm -lxc -parted -pcap -rbd -sasl -virtualbox -wireshark-plugins -xen -zfs
net-dns/dnsmasq script
net-misc/spice-gtk usbredir
# flatpak useflags
dev-util/ostree curl
# rust useflags
dev-lang/rust nightly parallel-compiler system-llvm
# source-han-sans useflags
media-fonts/source-han-sans l10n_ja l10n_ko l10n_zh-CN"
# emacs useflags
app-editors/emacs gui sound xft xwidgets harfbuzz imagemagick
app-emacs/emacs-common gui
# save kernel config
sys-kernel/vanilla-kernel savedconfig
# save dmenu config
x11-misc/dmenu savedconfig
# build xfdesktop without thunar
xfce-base/xfdesktop -thunar
# build xfce4-session without xscreensaver
xfce-base/xfce4-session -xscreensaver
# build pinentry with gnome-keyring support
app-crypt/pinentry gnome-keyring
# build PCRE libs for UTF-16
dev-libs/libpcre2 pcre16
# build libraries in double precision, sacrificing speed for precise calculations
sci-physics/bullet double-precision
# build ffmpeg support in osg
dev-games/openscenegraph-openmw ffmpeg
# build python support for boost
dev-libs/boost python
# dunstify notify-send
x11-misc/dunst dunstify
# support conversion from XML to plain text
app-text/xmlto text
# required by udev helpers, set here to avoid pulling in extra deps
dev-libs/libgudev introspection
sys-fs/eudev introspection
# required by qtwayland
dev-qt/qtgui egl

View File

@ -0,0 +1,107 @@
From 39ab9676914bd0d8105d0f96bbd7611a53077438 Mon Sep 17 00:00:00 2001
From: Miles Alan <m@milesalan.com>
Date: Sat, 4 Jul 2020 11:19:04 -0500
Subject: [PATCH] Add -g option to display entries in the given number of grid
columns
This option can be used in conjunction with -l to format dmenu's options in
arbitrary size grids. For example, to create a 4 column by 6 line grid, you
could use: dmenu -g 4 -l 6
---
config.def.h | 3 ++-
dmenu.1 | 7 ++++++-
dmenu.c | 22 ++++++++++++++++------
3 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/config.def.h b/config.def.h
index 1edb647..96cf3c9 100644
--- a/config.def.h
+++ b/config.def.h
@@ -13,8 +13,9 @@ static const char *colors[SchemeLast][2] = {
[SchemeSel] = { "#eeeeee", "#005577" },
[SchemeOut] = { "#000000", "#00ffff" },
};
-/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
+/* -l and -g options; controls number of lines and columns in grid if > 0 */
static unsigned int lines = 0;
+static unsigned int columns = 0;
/*
* Characters not considered part of a word while deleting words
diff --git a/dmenu.1 b/dmenu.1
index 323f93c..d0a734a 100644
--- a/dmenu.1
+++ b/dmenu.1
@@ -4,6 +4,8 @@ dmenu \- dynamic menu
.SH SYNOPSIS
.B dmenu
.RB [ \-bfiv ]
+.RB [ \-g
+.IR columns ]
.RB [ \-l
.IR lines ]
.RB [ \-m
@@ -47,8 +49,11 @@ is faster, but will lock up X until stdin reaches end\-of\-file.
.B \-i
dmenu matches menu items case insensitively.
.TP
+.BI \-g " columns"
+dmenu lists items in a grid with the given number of columns.
+.TP
.BI \-l " lines"
-dmenu lists items vertically, with the given number of lines.
+dmenu lists items in a grid with the given number of lines.
.TP
.BI \-m " monitor"
dmenu is displayed on the monitor number supplied. Monitor numbers are starting
diff --git a/dmenu.c b/dmenu.c
index 6b8f51b..d79b6bb 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -77,7 +77,7 @@ calcoffsets(void)
int i, n;
if (lines > 0)
- n = lines * bh;
+ n = lines * columns * bh;
else
n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
/* calculate which items will begin the next page and previous page */
@@ -152,9 +152,15 @@ drawmenu(void)
}
if (lines > 0) {
- /* draw vertical list */
- for (item = curr; item != next; item = item->right)
- drawitem(item, x, y += bh, mw - x);
+ /* draw grid */
+ int i = 0;
+ for (item = curr; item != next; item = item->right, i++)
+ drawitem(
+ item,
+ x + ((i / lines) * ((mw - x) / columns)),
+ y + (((i % lines) + 1) * bh),
+ (mw - x) / columns
+ );
} else if (matches) {
/* draw horizontal list */
x += inputw;
@@ -708,9 +714,13 @@ main(int argc, char *argv[])
} else if (i + 1 == argc)
usage();
/* these options take one argument */
- else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
+ else if (!strcmp(argv[i], "-g")) { /* number of columns in grid */
+ columns = atoi(argv[++i]);
+ if (lines == 0) lines = 1;
+ } else if (!strcmp(argv[i], "-l")) { /* number of lines in grid */
lines = atoi(argv[++i]);
- else if (!strcmp(argv[i], "-m"))
+ if (columns == 0) columns = 1;
+ } 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];
--
2.23.1

View File

@ -0,0 +1,72 @@
diff --git a/dmenu.c b/dmenu.c
index 7361377..76acee6 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -7,6 +7,7 @@
#include <strings.h>
#include <time.h>
#include <unistd.h>
+#include <stdbool.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
@@ -317,6 +318,9 @@ keypress(XKeyEvent *ev)
int len;
KeySym ksym;
Status status;
+ int i;
+ struct item *tmpsel;
+ bool offscreen = false;
len = XmbLookupString(xic, ev, buf, sizeof buf, &ksym, &status);
switch (status) {
@@ -443,6 +447,24 @@ insert:
calcoffsets();
break;
case XK_Left:
+ if (columns > 1) {
+ if (!sel)
+ return;
+ tmpsel = sel;
+ for (i = 0; i < lines; i++) {
+ if (!tmpsel->left || tmpsel->left->right != tmpsel)
+ return;
+ if (tmpsel == curr)
+ offscreen = true;
+ tmpsel = tmpsel->left;
+ }
+ sel = tmpsel;
+ if (offscreen) {
+ curr = prev;
+ calcoffsets();
+ }
+ break;
+ }
if (cursor > 0 && (!sel || !sel->left || lines > 0)) {
cursor = nextrune(-1);
break;
@@ -479,6 +501,24 @@ insert:
sel->out = 1;
break;
case XK_Right:
+ if (columns > 1) {
+ if (!sel)
+ return;
+ tmpsel = sel;
+ for (i = 0; i < lines; i++) {
+ if (!tmpsel->right || tmpsel->right->left != tmpsel)
+ return;
+ tmpsel = tmpsel->right;
+ if (tmpsel == next)
+ offscreen = true;
+ }
+ sel = tmpsel;
+ if (offscreen) {
+ curr = next;
+ calcoffsets();
+ }
+ break;
+ }
if (text[cursor] != '\0') {
cursor = nextrune(+1);
break;

View File

@ -0,0 +1,25 @@
diff -up dmenu-4.9-b/config.def.h dmenu-4.9-a/config.def.h
--- dmenu-4.9-b/config.def.h 2019-02-02 13:55:02.000000000 +0100
+++ dmenu-4.9-a/config.def.h 2019-05-19 02:10:12.740040403 +0200
@@ -21,3 +21,6 @@ static unsigned int lines = 0;
* for example: " /?\"&[]"
*/
static const char worddelimiters[] = " ";
+
+/* Size of the window border */
+static const unsigned int border_width = 5;
diff -up dmenu-4.9-b/dmenu.c dmenu-4.9-a/dmenu.c
--- dmenu-4.9-b/dmenu.c 2019-02-02 13:55:02.000000000 +0100
+++ dmenu-4.9-a/dmenu.c 2019-05-19 02:11:20.966710117 +0200
@@ -654,9 +654,10 @@ setup(void)
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,
+ win = XCreateWindow(dpy, parentwin, x, y, mw, mh, border_width,
CopyFromParent, CopyFromParent, CopyFromParent,
CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
+ XSetWindowBorder(dpy, win, scheme[SchemeSel][ColBg].pixel);
XSetClassHint(dpy, win, &ch);
/* open input methods */

View File

@ -0,0 +1,120 @@
From 8cd37e1ab9e7cb025224aeb3543f1a5be8bceb93 Mon Sep 17 00:00:00 2001
From: Nihal Jere <nihal@nihaljere.xyz>
Date: Sat, 11 Jan 2020 21:16:08 -0600
Subject: [PATCH] center patch now has adjustable minimum width
---
config.def.h | 2 ++
dmenu.1 | 3 +++
dmenu.c | 39 ++++++++++++++++++++++++++++++++-------
3 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/config.def.h b/config.def.h
index 1edb647..88ef264 100644
--- a/config.def.h
+++ b/config.def.h
@@ -2,6 +2,8 @@
/* Default settings; can be overriden by command line. */
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
+static int centered = 0; /* -c option; centers dmenu on screen */
+static int min_width = 500; /* minimum width when centered */
/* -fn option overrides fonts[0]; default X11 font or font set */
static const char *fonts[] = {
"monospace:size=10"
diff --git a/dmenu.1 b/dmenu.1
index 323f93c..c036baa 100644
--- a/dmenu.1
+++ b/dmenu.1
@@ -40,6 +40,9 @@ which lists programs in the user's $PATH and runs the result in their $SHELL.
.B \-b
dmenu appears at the bottom of the screen.
.TP
+.B \-c
+dmenu appears centered on 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.
diff --git a/dmenu.c b/dmenu.c
index 65f25ce..041c7f8 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -89,6 +89,15 @@ calcoffsets(void)
break;
}
+static int
+max_textw(void)
+{
+ int len = 0;
+ for (struct item *item = items; item && item->text; item++)
+ len = MAX(TEXTW(item->text), len);
+ return len;
+}
+
static void
cleanup(void)
{
@@ -611,6 +620,7 @@ setup(void)
bh = drw->fonts->h + 2;
lines = MAX(lines, 0);
mh = (lines + 1) * bh;
+ promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
#ifdef XINERAMA
i = 0;
if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) {
@@ -637,9 +647,16 @@ 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;
+ if (centered) {
+ mw = MIN(MAX(max_textw() + promptw, min_width), info[i].width);
+ x = info[i].x_org + ((info[i].width - mw) / 2);
+ y = info[i].y_org + ((info[i].height - mh) / 2);
+ } else {
+ x = info[i].x_org;
+ y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
+ mw = info[i].width;
+ }
+
XFree(info);
} else
#endif
@@ -647,11 +664,17 @@ 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;
+
+ if (centered) {
+ mw = MIN(MAX(max_textw() + promptw, min_width), wa.width);
+ x = (wa.width - mw) / 2;
+ y = (wa.height - mh) / 2;
+ } else {
+ x = 0;
+ y = topbar ? 0 : wa.height - mh;
+ mw = wa.width;
+ }
}
- promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
inputw = MIN(inputw, mw/3);
match();
@@ -709,6 +732,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], "-c")) /* centers dmenu on screen */
+ centered = 1;
else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
fstrncmp = strncasecmp;
fstrstr = cistrstr;
--
2.24.1

View File

@ -0,0 +1,245 @@
diff --git a/dmenu.c b/dmenu.c
index 5c835dd..71efe52 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -131,9 +131,10 @@ drawitem(struct item *item, int x, int y, int w)
static void
drawmenu(void)
{
- unsigned int curpos;
+ static int curpos, oldcurlen;
struct item *item;
int x = 0, y = 0, w;
+ int curlen, rcurlen;
drw_setscheme(drw, scheme[SchemeNorm]);
drw_rect(drw, 0, 0, mw, mh, 1, 1);
@@ -144,14 +145,21 @@ drawmenu(void)
}
/* 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);
+ w -= lrpad / 2;
+ x += lrpad / 2;
- 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);
- }
+ rcurlen = drw_fontset_getwidth(drw, text + cursor);
+ curlen = drw_fontset_getwidth(drw, text) - rcurlen;
+ curpos += curlen - oldcurlen;
+ curpos = MIN(w, MAX(0, curpos));
+ curpos = MAX(curpos, w - rcurlen);
+ curpos = MIN(curpos, curlen);
+ oldcurlen = curlen;
+
+ drw_setscheme(drw, scheme[SchemeNorm]);
+ drw_text_align(drw, x, 0, curpos, bh, text, cursor, AlignR);
+ drw_text_align(drw, x + curpos, 0, w - curpos, bh, text + cursor, strlen(text) - cursor, AlignL);
+ drw_rect(drw, x + curpos - 1, 2, 2, bh - 4, 1, 0);
if (lines > 0) {
/* draw vertical list */
diff --git a/drw.c b/drw.c
index c638323..bfffbc1 100644
--- a/drw.c
+++ b/drw.c
@@ -364,6 +364,175 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
return x + (render ? w : 0);
}
+int
+utf8nextchar(const char *str, int len, int i, int inc)
+{
+ int n;
+
+ for (n = i + inc; n + inc >= 0 && n + inc <= len
+ && (str[n] & 0xc0) == 0x80; n += inc)
+ ;
+ return n;
+}
+
+int
+drw_text_align(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int textlen, int align)
+{
+ int ty;
+ unsigned int ew;
+ XftDraw *d = NULL;
+ Fnt *usedfont, *curfont, *nextfont;
+ size_t 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;
+ int i, n;
+
+ if (!drw || (render && !drw->scheme) || !text || !drw->fonts || textlen <= 0
+ || (align != AlignL && align != AlignR))
+ return 0;
+
+ if (!render) {
+ w = ~w;
+ } else {
+ XSetForeground(drw->dpy, drw->gc, drw->scheme[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));
+ }
+
+ usedfont = drw->fonts;
+ i = align == AlignL ? 0 : textlen;
+ x = align == AlignL ? x : x + w;
+ while (1) {
+ utf8strlen = 0;
+ nextfont = NULL;
+ /* if (align == AlignL) */
+ utf8str = text + i;
+
+ while ((align == AlignL && i < textlen) || (align == AlignR && i > 0)) {
+ if (align == AlignL) {
+ utf8charlen = utf8decode(text + i, &utf8codepoint, MIN(textlen - i, UTF_SIZ));
+ if (!utf8charlen) {
+ textlen = i;
+ break;
+ }
+ } else {
+ n = utf8nextchar(text, textlen, i, -1);
+ utf8charlen = utf8decode(text + n, &utf8codepoint, MIN(textlen - n, UTF_SIZ));
+ if (!utf8charlen) {
+ textlen -= i;
+ text += i;
+ i = 0;
+ break;
+ }
+ }
+ for (curfont = drw->fonts; curfont; curfont = curfont->next) {
+ charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint);
+ if (charexists) {
+ if (curfont == usedfont) {
+ utf8strlen += utf8charlen;
+ i += align == AlignL ? utf8charlen : -utf8charlen;
+ } else {
+ nextfont = curfont;
+ }
+ break;
+ }
+ }
+
+ if (!charexists || nextfont)
+ break;
+ else
+ charexists = 0;
+ }
+
+ if (align == AlignR)
+ utf8str = text + i;
+
+ if (utf8strlen) {
+ drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL);
+ /* shorten text if necessary */
+ if (align == AlignL) {
+ for (len = utf8strlen; len && ew > w; ) {
+ len = utf8nextchar(utf8str, len, len, -1);
+ drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
+ }
+ } else {
+ for (len = utf8strlen; len && ew > w; ) {
+ n = utf8nextchar(utf8str, len, 0, +1);
+ utf8str += n;
+ len -= n;
+ drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
+ }
+ }
+
+ if (len) {
+ if (render) {
+ ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent;
+ XftDrawStringUtf8(d, &drw->scheme[ColFg],
+ usedfont->xfont, align == AlignL ? x : x - ew, ty, (XftChar8 *)utf8str, len);
+ }
+ x += align == AlignL ? ew : -ew;
+ w -= ew;
+ }
+ if (len < utf8strlen)
+ break;
+ }
+
+ if ((align == AlignR && i <= 0) || (align == AlignL && i >= textlen)) {
+ 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);
+
+ 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;
+}
+
void
drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h)
{
diff --git a/drw.h b/drw.h
index 4c67419..b66a83e 100644
--- a/drw.h
+++ b/drw.h
@@ -13,6 +13,7 @@ typedef struct Fnt {
} Fnt;
enum { ColFg, ColBg }; /* Clr scheme index */
+enum { AlignL, AlignR };
typedef XftColor Clr;
typedef struct {
@@ -52,6 +53,7 @@ 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);
+int drw_text_align(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int textlen, int align);
/* Map functions */
void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h);

View File

@ -0,0 +1,81 @@
From 61abc60dbfaa8ec63fcd176307308aee88a19e32 Mon Sep 17 00:00:00 2001
From: Miles Alan <m@milesalan.com>
Date: Sat, 10 Aug 2019 17:20:08 -0500
Subject: [PATCH] Display number of matched and total items in top right corner
---
dmenu.c | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/dmenu.c b/dmenu.c
index 6b8f51b..98c5810 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -24,6 +24,8 @@
* 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)
+#define NUMBERSMAXDIGITS 100
+#define NUMBERSBUFSIZE (NUMBERSMAXDIGITS * 2) + 1
/* enums */
enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
@@ -34,6 +36,7 @@ struct item {
int out;
};
+static char numbers[NUMBERSBUFSIZE] = "";
static char text[BUFSIZ] = "";
static char *embed;
static int bh, mw, mh;
@@ -126,6 +129,21 @@ drawitem(struct item *item, int x, int y, int w)
return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
}
+static void
+recalculatenumbers()
+{
+ unsigned int numer = 0, denom = 0;
+ struct item *item;
+ if (matchend) {
+ numer++;
+ for (item = matchend; item && item->left; item = item->left)
+ numer++;
+ }
+ for (item = items; item && item->text; item++)
+ denom++;
+ snprintf(numbers, NUMBERSBUFSIZE, "%d/%d", numer, denom);
+}
+
static void
drawmenu(void)
{
@@ -151,6 +169,7 @@ drawmenu(void)
drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
}
+ recalculatenumbers();
if (lines > 0) {
/* draw vertical list */
for (item = curr; item != next; item = item->right)
@@ -165,13 +184,15 @@ drawmenu(void)
}
x += w;
for (item = curr; item != next; item = item->right)
- x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">")));
+ x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">") - TEXTW(numbers)));
if (next) {
w = TEXTW(">");
drw_setscheme(drw, scheme[SchemeNorm]);
- drw_text(drw, mw - w, 0, w, bh, lrpad / 2, ">", 0);
+ drw_text(drw, mw - w - TEXTW(numbers), 0, w, bh, lrpad / 2, ">", 0);
}
}
+ drw_setscheme(drw, scheme[SchemeNorm]);
+ drw_text(drw, mw - TEXTW(numbers), 0, TEXTW(numbers), bh, lrpad / 2, numbers, 0);
drw_map(drw, win, 0, 0, mw, mh);
}
--
2.19.2

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,29 @@
/* See LICENSE file for copyright and license details. */
/* Default settings; can be overriden by command line. */
static int topbar = 0; /* -b option; if 0, dmenu appears at bottom */
static int centered = 1; /* -c option; centers dmenu on screen */
static int min_width = 300; /* minimum width when centered */
static const char *fonts[] = { "lucy tewi-font:size=8" }; /* -fn option overrides fonts[0]; default X11 font or font set */
static const char *prompt = "dmenu:" ; /* -p option; prompt to the left of input field */
static const char *colors[SchemeLast][2] = {
/* fg bg */
[SchemeNorm] = { "#bbbbbb", "#222222" },
[SchemeSel] = { "#eeeeee", "#005577" },
[SchemeOut] = { "#000000", "#00ffff" },
};
/* -l and -g options; controls number of lines and columns in grid if > 0 */
static unsigned int lines = 6;
static unsigned int maxhist = 64;
static int histnodup = 1; /* if 0, record repeated histories */
static unsigned int columns = 2;
/*
* Characters not considered part of a word while deleting words
* for example: " /?\"&[]"
*/
static const char worddelimiters[] = " ";
static const unsigned int border_width = 3;