fixing stuff
This commit is contained in:
commit
d95218cf97
|
@ -0,0 +1,17 @@
|
|||
/**Xft**/
|
||||
Xft.dpi: 96
|
||||
Xft.antialias: 1
|
||||
Xft.hinting: 1
|
||||
Xft.autohint: 0
|
||||
Xft.hintstyle: hintslight
|
||||
Xft.rgba: rgb
|
||||
Xft.lcdfilter: lcddefault
|
||||
|
||||
/**Xcursor**/
|
||||
Xcursor.size: 24
|
||||
/**xmenu**/
|
||||
|
||||
/**sxiv**/
|
||||
Sxiv.background: #181819
|
||||
Sxiv.foreground: #e2e2e3
|
||||
Sxiv.font: xft:SF Pro:pixelsize:30
|
|
@ -0,0 +1,40 @@
|
|||
#!/bin/sh
|
||||
|
||||
userresources=$HOME/.Xresources
|
||||
usermodmap=$HOME/.Xmodmap
|
||||
sysresources=/etc/X11/xinit/.Xresources
|
||||
sysmodmap=/etc/X11/xinit/.Xmodmap
|
||||
|
||||
# merge in defaults and keymaps
|
||||
|
||||
if [ -f $sysresources ]; then
|
||||
|
||||
xrdb -merge $sysresources
|
||||
|
||||
fi
|
||||
|
||||
if [ -f $sysmodmap ]; then
|
||||
xmodmap $sysmodmap
|
||||
fi
|
||||
|
||||
if [ -f "$userresources" ]; then
|
||||
|
||||
xrdb -merge "$userresources"
|
||||
|
||||
fi
|
||||
|
||||
if [ -f "$usermodmap" ]; then
|
||||
xmodmap "$usermodmap"
|
||||
fi
|
||||
|
||||
# start some nice programs
|
||||
|
||||
if [ -d /etc/X11/xinit/xinitrc.d ] ; then
|
||||
for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do
|
||||
[ -x "$f" ] && . "$f"
|
||||
done
|
||||
unset f
|
||||
fi
|
||||
|
||||
dwm
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
language: c
|
||||
script: make
|
|
@ -0,0 +1,32 @@
|
|||
MIT/X Consortium License
|
||||
|
||||
© 2016 Google Inc.
|
||||
© 2013 Alan Berndt <alan@eatabrick.org>
|
||||
|
||||
Based on code from dmenu <http://tools.suckless.org/dmenu/>
|
||||
|
||||
© 2010-2011 Connor Lane Smith <cls@lubutu.com>
|
||||
© 2006-2011 Anselm R Garbe <anselm@garbe.us>
|
||||
© 2009 Gottox <gottox@s01.de>
|
||||
© 2009 Markus Schnalke <meillo@marmaro.de>
|
||||
© 2009 Evan Gates <evan.gates@gmail.com>
|
||||
© 2006-2008 Sander van Dijk <a dot h dot vandijk at gmail dot com>
|
||||
© 2006-2007 Michał Janeczek <janeczek at gmail dot com>
|
||||
|
||||
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,55 @@
|
|||
# dcal - dynamic menu
|
||||
# See LICENSE file for copyright and license details.
|
||||
|
||||
include config.mk
|
||||
|
||||
SRC = dcal.c draw.c
|
||||
OBJ = ${SRC:.c=.o}
|
||||
|
||||
all: options dcal
|
||||
|
||||
options:
|
||||
@echo dcal build options:
|
||||
@echo "CFLAGS = ${CFLAGS}"
|
||||
@echo "LDFLAGS = ${LDFLAGS}"
|
||||
@echo "CC = ${CC}"
|
||||
|
||||
.c.o:
|
||||
@echo CC -c $<
|
||||
@${CC} -c $< ${CFLAGS}
|
||||
|
||||
${OBJ}: config.mk draw.h
|
||||
|
||||
dcal: dcal.o draw.o
|
||||
@echo CC -o $@
|
||||
@${CC} -o $@ dcal.o draw.o ${LDFLAGS}
|
||||
|
||||
clean:
|
||||
@echo cleaning
|
||||
@rm -f dcal ${OBJ} dcal-${VERSION}.tar.gz
|
||||
|
||||
dist: clean
|
||||
@echo creating dist tarball
|
||||
@mkdir -p dcal-${VERSION}
|
||||
@cp LICENSE Makefile README.md config.mk dcal.1 draw.h ${SRC} dcal-${VERSION}
|
||||
@tar -cf dcal-${VERSION}.tar dcal-${VERSION}
|
||||
@gzip dcal-${VERSION}.tar
|
||||
@rm -rf dcal-${VERSION}
|
||||
|
||||
install: all
|
||||
@echo installing executables to ${DESTDIR}${PREFIX}/bin
|
||||
@mkdir -p ${DESTDIR}${PREFIX}/bin
|
||||
@cp -f dcal ${DESTDIR}${PREFIX}/bin
|
||||
@chmod 755 ${DESTDIR}${PREFIX}/bin/dcal
|
||||
@echo installing manual pages to ${DESTDIR}${MANPREFIX}/man1
|
||||
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
|
||||
@sed "s/VERSION/${VERSION}/g" < dcal.1 > ${DESTDIR}${MANPREFIX}/man1/dcal.1
|
||||
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/dcal.1
|
||||
|
||||
uninstall:
|
||||
@echo removing executables from ${DESTDIR}${PREFIX}/bin
|
||||
@rm -f ${DESTDIR}${PREFIX}/bin/dcal
|
||||
@echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
|
||||
@rm -f ${DESTDIR}${MANPREFIX}/man1/dcal.1
|
||||
|
||||
.PHONY: all options clean dist install uninstall
|
|
@ -0,0 +1,23 @@
|
|||
# Maintainer: Alan Berndt <alan@eatabrick.org>
|
||||
pkgname=dcal
|
||||
pkgver=1.1
|
||||
pkgrel=1
|
||||
pkgdesc="A generic calendar for X"
|
||||
url="http://dcal.eatabrick.org"
|
||||
license='MIT'
|
||||
arch=('i686' 'x86_64')
|
||||
depends=('libx11')
|
||||
provides=('dcal')
|
||||
source=('https://github.com/bentglasstube/dcal/archive/v1.1.tar.gz')
|
||||
sha1sums=('2278bad1b01c9735c3bbfa5f2870ace6f0e9b447')
|
||||
|
||||
build() {
|
||||
cd "$srcdir/$pkgname-$pkgver"
|
||||
make
|
||||
}
|
||||
|
||||
package() {
|
||||
cd "$srcdir/$pkgname-$pkgver"
|
||||
make DESTDIR="$pkgdir/" install
|
||||
install -D -m644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
dcal - dynamic calendar
|
||||
====================
|
||||
dcal is a minimalistic calendar for X.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
In order to build dcal you need the Xlib header files.
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
Edit config.mk to match your local setup (dcal is installed into
|
||||
the /usr namespace by default).
|
||||
|
||||
Afterwards enter the following command to build and install dcal
|
||||
(if necessary as root):
|
||||
|
||||
make clean install
|
||||
|
||||
Running dcal
|
||||
------------
|
||||
See the man page for details.
|
||||
|
||||
Screenshot
|
||||
----------
|
||||
|
||||
![screenshot](https://raw.github.com/bentglasstube/dcal/master/screenshot.png)
|
||||
|
||||
This is what mine looks like, but it's quite configurable
|
|
@ -0,0 +1,25 @@
|
|||
# dcal version
|
||||
VERSION = 1.1
|
||||
|
||||
# paths
|
||||
PREFIX = /usr
|
||||
MANPREFIX = ${PREFIX}/share/man
|
||||
|
||||
X11INC = /usr/X11R6/include
|
||||
X11LIB = /usr/X11R6/lib
|
||||
|
||||
# Xinerama, comment if you don't want it
|
||||
XINERAMALIBS = -lXinerama
|
||||
XINERAMAFLAGS = -DXINERAMA
|
||||
|
||||
# includes and libs
|
||||
INCS = -I${X11INC}
|
||||
LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS}
|
||||
|
||||
# flags
|
||||
CPPFLAGS = -D_BSD_SOURCE -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
|
||||
CFLAGS = -ansi -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
|
||||
LDFLAGS = -s ${LIBS}
|
||||
|
||||
# compiler and linker
|
||||
CC = cc
|
Binary file not shown.
|
@ -0,0 +1,117 @@
|
|||
.TH DCAL 1 dcal\-VERSION
|
||||
.SH NAME
|
||||
dcal \- dynamic calendar
|
||||
.SH SYNOPSIS
|
||||
.B dcal
|
||||
.RB [ \-b]
|
||||
.RB [ \-l]
|
||||
.RB [ \-k]
|
||||
.RB [ \-fn
|
||||
.IR font ]
|
||||
.RB [ \-bg
|
||||
.IR color ]
|
||||
.RB [ \-bd
|
||||
.IR color ]
|
||||
.RB [ \-cf
|
||||
.IR color ]
|
||||
.RB [ \-of
|
||||
.IR color ]
|
||||
.RB [ \-tf
|
||||
.IR color ]
|
||||
.RB [ \-hf
|
||||
.IR color ]
|
||||
.RB [ \-x
|
||||
.IR offset ]
|
||||
.RB [ \-y
|
||||
.IR offset ]
|
||||
.RB [ dates ]
|
||||
.sp
|
||||
.B dcal -h
|
||||
.sp
|
||||
.B dcal -v
|
||||
.SH DESCRIPTION
|
||||
.B dcal
|
||||
is a dynamic calendar for X. It shows the current month and allows you to
|
||||
navigate to other months.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.BI \-b
|
||||
draws the calendar on the bottom of the screen.
|
||||
.TP
|
||||
.BI \-l
|
||||
draws the calendar on the left of the screen.
|
||||
.TP
|
||||
.BI \-k
|
||||
do not grab the keyboard nor use it for input.
|
||||
.TP
|
||||
.BI \-fn " font"
|
||||
defines the font or font set used.
|
||||
.TP
|
||||
.BI \-bg " color"
|
||||
defines the background color.
|
||||
.IR #RGB ,
|
||||
.IR #RRGGBB ,
|
||||
and X color names are supported.
|
||||
.TP
|
||||
.BI \-bd " color"
|
||||
defines the border color.
|
||||
.TP
|
||||
.BI \-cf " color"
|
||||
defines the current month foreground color.
|
||||
.TP
|
||||
.BI \-of " color"
|
||||
defines the other month foreground color.
|
||||
.TP
|
||||
.BI \-tf " color"
|
||||
defines the forgeround color for today.
|
||||
.TP
|
||||
.BI \-hf " color"
|
||||
defines the foreground color for hilights.
|
||||
.TP
|
||||
.BI \-x " offset"
|
||||
defines an offset in the horizontal direction to adjust where the calendar is
|
||||
shown.
|
||||
.TP
|
||||
.BI \-y " offset"
|
||||
defines an offset in the vertical direction to adjust where the calendar is
|
||||
shown.
|
||||
.TP
|
||||
.B \-h
|
||||
prints usage information to stdout, then exits.
|
||||
.TP
|
||||
.B \-v
|
||||
prints version information to stdout, then exits.
|
||||
.SH IMPORTANT DATES
|
||||
Any other arguments are taken to be important dates that will be drawn with the
|
||||
hilight color. The dates should be formatted as YYYYMMDD without any
|
||||
separators. Only 32 dates are supported, any more will be ignored.
|
||||
.SH USAGE
|
||||
dcal can be controlled via the mouse or the keyboard. The following commands
|
||||
are recognized:
|
||||
.TP
|
||||
.B Space
|
||||
Jump back to the current date.
|
||||
.TP
|
||||
.B H, Left
|
||||
Go back one day.
|
||||
.TP
|
||||
.B L, Right
|
||||
Go forward one day.
|
||||
.TP
|
||||
.B K, Up
|
||||
Go back one week.
|
||||
.TP
|
||||
.B J, Down
|
||||
Go forward one week.
|
||||
.TP
|
||||
.B Shift\-K, Mouse wheel up
|
||||
Go back one month.
|
||||
.TP
|
||||
.B Shift\-J, Mouse wheel down
|
||||
Go forward one month.
|
||||
.TP
|
||||
.B Escape, Q, Right click
|
||||
Exit dcal.
|
||||
.SH SEE ALSO
|
||||
.IR dwm (1),
|
||||
.IR dmenu (1)
|
|
@ -0,0 +1,408 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.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 "draw.h"
|
||||
|
||||
#define HILIGHT_MAX 32
|
||||
|
||||
#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 MIN(a,b) ((a) < (b) ? (a) : (b))
|
||||
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
static void adddays(time_t *d, int count);
|
||||
static void addmonths(time_t *d, int count);
|
||||
static void drawcal(void);
|
||||
static void grabkeyboard(void);
|
||||
static void keypress(XKeyEvent *ev);
|
||||
static void run(void);
|
||||
static void setup(void);
|
||||
static void usage(void);
|
||||
static unsigned long* pickcolor(const char *date, const char *current);
|
||||
|
||||
static int ch, cw; /* Calendar height and width */
|
||||
static time_t current; /* Currently displayed time */
|
||||
static const char *font = NULL; /* font */
|
||||
static const char *bgcolor = "#cccccc"; /* colors */
|
||||
static const char *bdcolor = "#000000";
|
||||
static const char *curfgcolor = "#000000";
|
||||
static const char *othfgcolor = "#ffffff";
|
||||
static const char *todfgcolor = "#ff0000";
|
||||
static const char *hltfgcolor = "#0000ff";
|
||||
static unsigned long curcol[ColLast];
|
||||
static unsigned long othcol[ColLast];
|
||||
static unsigned long todcol[ColLast];
|
||||
static unsigned long hltcol[ColLast];
|
||||
static unsigned long invcol[ColLast];
|
||||
static Atom utf8;
|
||||
static Bool topbar = True; /* Draw on top */
|
||||
static Bool leftbar = False; /* Draw on left */
|
||||
static Bool keyboard = True; /* Use keyboard controls */
|
||||
static int offset_x = 0; /* x offset */
|
||||
static int offset_y = 0; /* y offset */
|
||||
static DC *dc; /* Drawing context */
|
||||
static Window win; /* Window */
|
||||
static XIC xic;
|
||||
static char today[9]; /* Current date when run */
|
||||
static char hilight[HILIGHT_MAX][9]; /* Date for hilighting */
|
||||
static int hilight_count = 0; /* Number of dates to hilight */
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i;
|
||||
|
||||
for(i = 1; i < argc; i++) {
|
||||
/* these options take no arguments */
|
||||
if(!strcmp(argv[i], "-v")) { /* prints version information */
|
||||
puts("dcal-"VERSION", © 2012 Alan Berndt, see LICENSE for details");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
else if(!strcmp(argv[i], "-h")) { /* prints usage information */
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
else if(!strcmp(argv[i], "-b")) /* appears at the bottom of the screen */
|
||||
topbar = False;
|
||||
else if(!strcmp(argv[i], "-l")) /* appears at the left of the screen */
|
||||
leftbar = True;
|
||||
else if(!strcmp(argv[i], "-k")) /* suppress keyboard controls */
|
||||
keyboard = False;
|
||||
/* these options take one argument */
|
||||
else if(!strcmp(argv[i], "-fn")) /* font or font set */
|
||||
font = argv[++i];
|
||||
else if(!strcmp(argv[i], "-bg")) /* background color */
|
||||
bgcolor = argv[++i];
|
||||
else if(!strcmp(argv[i], "-bd")) /* border color */
|
||||
bdcolor = argv[++i];
|
||||
else if(!strcmp(argv[i], "-cf")) /* current month foreground color */
|
||||
curfgcolor = argv[++i];
|
||||
else if(!strcmp(argv[i], "-of")) /* other month foreground color */
|
||||
othfgcolor = argv[++i];
|
||||
else if(!strcmp(argv[i], "-tf")) /* today foreground color */
|
||||
todfgcolor = argv[++i];
|
||||
else if(!strcmp(argv[i], "-hf")) /* hilight foreground color */
|
||||
hltfgcolor = argv[++i];
|
||||
else if(!strcmp(argv[i], "-x")) /* x offset */
|
||||
offset_x = atoi(argv[++i]);
|
||||
else if(!strcmp(argv[i], "-y")) /* y offset */
|
||||
offset_y = atoi(argv[++i]);
|
||||
/* the rest are dates to hilight */
|
||||
else if(hilight_count < HILIGHT_MAX)
|
||||
strncpy(hilight[hilight_count++], argv[i], 9);
|
||||
}
|
||||
|
||||
dc = initdc();
|
||||
initfont(dc, font);
|
||||
|
||||
if (keyboard) grabkeyboard();
|
||||
setup();
|
||||
run();
|
||||
|
||||
return EXIT_FAILURE; /* unreachable */
|
||||
}
|
||||
|
||||
void adddays(time_t *d, int count) {
|
||||
struct tm *t;
|
||||
|
||||
t = localtime(d);
|
||||
t->tm_mday += count;
|
||||
*d = mktime(t);
|
||||
}
|
||||
|
||||
void addmonths(time_t *d, int count) {
|
||||
struct tm *t;
|
||||
|
||||
t = localtime(d);
|
||||
t->tm_mon += count;
|
||||
*d = mktime(t);
|
||||
}
|
||||
|
||||
void drawcal(void) {
|
||||
time_t day, end;
|
||||
struct tm *ti;
|
||||
unsigned long *color;
|
||||
char text[20];
|
||||
char curdate[10];
|
||||
|
||||
/* set up drawing context */
|
||||
dc->x = 0;
|
||||
dc->y = 0;
|
||||
dc->h = ch;
|
||||
dc->w = cw;
|
||||
|
||||
/* clear background and draw border */
|
||||
drawrect(dc, 0, 0, cw, ch, True, BG(dc, curcol));
|
||||
|
||||
/* draw header */
|
||||
ti = localtime(¤t);
|
||||
strftime(text, 20, "%B %Y", ti);
|
||||
dc->x = cw / 2 - textw(dc, text) / 2;
|
||||
dc->y = 1;
|
||||
drawtext(dc, text, curcol);
|
||||
|
||||
/* save selected date */
|
||||
strftime(curdate, 10, "%Y%m%d", ti);
|
||||
|
||||
/* find first of month */
|
||||
ti->tm_mday = 1;
|
||||
mktime(ti);
|
||||
|
||||
/* find first day of first week */
|
||||
ti->tm_mday -= ti->tm_wday;
|
||||
|
||||
day = mktime(ti);
|
||||
fprintf(stderr, "Drawing from %s", asctime(ti));
|
||||
|
||||
ti->tm_mday += 42;
|
||||
end = mktime(ti);
|
||||
fprintf(stderr, "Drawing thru %s", asctime(ti));
|
||||
|
||||
/* draw the calendar */
|
||||
dc->y = 9;
|
||||
while (day < end) {
|
||||
ti = localtime(&day);
|
||||
|
||||
/* new line on sunday */
|
||||
if (ti->tm_wday == 0) {
|
||||
dc->x = 1;
|
||||
dc->y += dc->font.height + 2;
|
||||
}
|
||||
|
||||
/* pick color */
|
||||
strftime(text, 20, "%Y%m%d", ti);
|
||||
color = pickcolor(text, curdate);
|
||||
|
||||
/* write the date */
|
||||
strftime(text, 20, "%d", ti);
|
||||
drawtext(dc, text, color);
|
||||
|
||||
/* increment */
|
||||
dc->x += 3 * (dc->font.width + 2);
|
||||
adddays(&day, 1);
|
||||
}
|
||||
|
||||
/* draw border */
|
||||
dc->x = 0;
|
||||
dc->y = 0;
|
||||
drawrect(dc, 0, 0, cw, ch, False, getcolor(dc, bdcolor));
|
||||
|
||||
mapdc(dc, win, cw, ch);
|
||||
}
|
||||
|
||||
void grabkeyboard(void) {
|
||||
int i;
|
||||
|
||||
/* try to grab keyboard, we may have to wait for another process to ungrab */
|
||||
for(i = 0; i < 1000; i++) {
|
||||
if(XGrabKeyboard(dc->dpy, DefaultRootWindow(dc->dpy), True,
|
||||
GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess)
|
||||
return;
|
||||
usleep(1000);
|
||||
}
|
||||
eprintf("cannot grab keyboard\n");
|
||||
}
|
||||
|
||||
void keypress(XKeyEvent *ev) {
|
||||
char buf[32];
|
||||
KeySym ksym = NoSymbol;
|
||||
Status status;
|
||||
|
||||
XmbLookupString(xic, ev, buf, sizeof buf, &ksym, &status);
|
||||
if(status == XBufferOverflow)
|
||||
return;
|
||||
|
||||
switch(ksym) {
|
||||
case XK_Return:
|
||||
case XK_KP_Enter:
|
||||
case XK_Escape:
|
||||
case XK_Q:
|
||||
case XK_q:
|
||||
exit(EXIT_SUCCESS);
|
||||
case XK_space: /* jump to today */
|
||||
time(¤t);
|
||||
break;
|
||||
case XK_Left: /* back one day */
|
||||
case XK_h:
|
||||
adddays(¤t, -1);
|
||||
break;
|
||||
case XK_Right: /* forward one day */
|
||||
case XK_l:
|
||||
adddays(¤t, 1);
|
||||
break;
|
||||
case XK_Up: /* back one week */
|
||||
case XK_k:
|
||||
adddays(¤t, -7);
|
||||
break;
|
||||
case XK_Down: /* forward one week */
|
||||
case XK_j:
|
||||
adddays(¤t, 7);
|
||||
break;
|
||||
case XK_K: /* back one month */
|
||||
addmonths(¤t, -1);
|
||||
break;
|
||||
case XK_J: /* forward one month */
|
||||
addmonths(¤t, 1);
|
||||
break;
|
||||
}
|
||||
drawcal();
|
||||
}
|
||||
|
||||
void buttonpress(XButtonEvent *ev) {
|
||||
switch (ev->button) {
|
||||
case Button1:
|
||||
exit(EXIT_SUCCESS);
|
||||
case Button4:
|
||||
addmonths(¤t, -1);
|
||||
break;
|
||||
case Button5:
|
||||
addmonths(¤t, 1);
|
||||
break;
|
||||
}
|
||||
drawcal();
|
||||
}
|
||||
|
||||
void run(void) {
|
||||
XEvent ev;
|
||||
|
||||
while(!XNextEvent(dc->dpy, &ev)) {
|
||||
if(XFilterEvent(&ev, win))
|
||||
continue;
|
||||
switch(ev.type) {
|
||||
case Expose:
|
||||
if(ev.xexpose.count == 0)
|
||||
mapdc(dc, win, cw, ch);
|
||||
break;
|
||||
case KeyPress:
|
||||
keypress(&ev.xkey);
|
||||
break;
|
||||
case ButtonPress:
|
||||
buttonpress(&ev.xbutton);
|
||||
break;
|
||||
case VisibilityNotify:
|
||||
if(ev.xvisibility.state != VisibilityUnobscured)
|
||||
XRaiseWindow(dc->dpy, win);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup(void) {
|
||||
int x, y, screen = DefaultScreen(dc->dpy);
|
||||
struct tm* ti;
|
||||
Window root = RootWindow(dc->dpy, screen);
|
||||
XSetWindowAttributes swa;
|
||||
XIM xim;
|
||||
#ifdef XINERAMA
|
||||
int n;
|
||||
XineramaScreenInfo *info;
|
||||
#endif
|
||||
|
||||
curcol[ColBG] = getcolor(dc, bgcolor);
|
||||
curcol[ColFG] = getcolor(dc, curfgcolor);
|
||||
othcol[ColBG] = getcolor(dc, bgcolor);
|
||||
othcol[ColFG] = getcolor(dc, othfgcolor);
|
||||
todcol[ColFG] = getcolor(dc, todfgcolor);
|
||||
todcol[ColBG] = getcolor(dc, bgcolor);
|
||||
hltcol[ColFG] = getcolor(dc, hltfgcolor);
|
||||
hltcol[ColBG] = getcolor(dc, bgcolor);
|
||||
invcol[ColBG] = getcolor(dc, curfgcolor);
|
||||
invcol[ColFG] = getcolor(dc, bgcolor);
|
||||
|
||||
utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False);
|
||||
|
||||
/* default to and save current time */
|
||||
time(¤t);
|
||||
ti = localtime(¤t);
|
||||
strftime(today, 9, "%Y%m%d", ti);
|
||||
|
||||
/* calculate calendar geometry */
|
||||
ch = 7 * (dc->font.height + 2) + 10;
|
||||
cw = 21 * (dc->font.width + 2) + 2;
|
||||
|
||||
#ifdef XINERAMA
|
||||
if((info = XineramaQueryScreens(dc->dpy, &n))) {
|
||||
int a, j, di, i = 0, area = 0;
|
||||
unsigned int du;
|
||||
Window w, pw, dw, *dws;
|
||||
XWindowAttributes wa;
|
||||
|
||||
XGetInputFocus(dc->dpy, &w, &di);
|
||||
if(w != root && w != PointerRoot && w != None) {
|
||||
/* find top-level window containing current input focus */
|
||||
do {
|
||||
if(XQueryTree(dc->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(dc->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(!area && XQueryPointer(dc->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 + (leftbar ? 0 : info[i].width - cw);
|
||||
y = info[i].y_org + (topbar ? 0 : info[i].height - ch);
|
||||
XFree(info);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
x = leftbar ? 0 : DisplayWidth( dc->dpy, screen) - cw;
|
||||
y = topbar ? 0 : DisplayHeight(dc->dpy, screen) - ch;
|
||||
}
|
||||
|
||||
/* apply offsets */
|
||||
x += offset_x;
|
||||
y += offset_y;
|
||||
|
||||
/* create calendar window */
|
||||
swa.override_redirect = True;
|
||||
swa.background_pixmap = ParentRelative;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | VisibilityChangeMask;
|
||||
win = XCreateWindow(dc->dpy, root, x, y, cw, ch, 0,
|
||||
DefaultDepth(dc->dpy, screen), CopyFromParent,
|
||||
DefaultVisual(dc->dpy, screen),
|
||||
CWOverrideRedirect | CWBackPixmap | CWEventMask, &swa);
|
||||
|
||||
/* open input methods */
|
||||
xim = XOpenIM(dc->dpy, NULL, NULL, NULL);
|
||||
xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
|
||||
XNClientWindow, win, XNFocusWindow, win, NULL);
|
||||
|
||||
XMapRaised(dc->dpy, win);
|
||||
resizedc(dc, cw, ch);
|
||||
drawcal();
|
||||
}
|
||||
|
||||
void usage(void) {
|
||||
fputs("usage: dcal [-b] [-l] [-fn font] [-bg color] [-cf color] [-of color] [-tf color] [-hf color] [-v]\n", stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
unsigned long* pickcolor(const char *date, const char *current) {
|
||||
int i;
|
||||
|
||||
if (keyboard && !strcmp(date, current)) return invcol;
|
||||
for (i = 0; i < hilight_count; ++i)
|
||||
if (!strcmp(date, hilight[i])) return hltcol;
|
||||
if (!strcmp(date, today)) return todcol;
|
||||
if (!strncmp(date, current, 6)) return curcol;
|
||||
return othcol;
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,177 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#include <locale.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include "draw.h"
|
||||
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#define DEFAULTFN "fixed"
|
||||
|
||||
static Bool loadfont(DC *dc, const char *fontstr);
|
||||
|
||||
void
|
||||
drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsigned long color) {
|
||||
XSetForeground(dc->dpy, dc->gc, color);
|
||||
if(fill)
|
||||
XFillRectangle(dc->dpy, dc->canvas, dc->gc, dc->x + x, dc->y + y, w, h);
|
||||
else
|
||||
XDrawRectangle(dc->dpy, dc->canvas, dc->gc, dc->x + x, dc->y + y, w-1, h-1);
|
||||
}
|
||||
|
||||
void
|
||||
drawtext(DC *dc, const char *text, unsigned long col[ColLast]) {
|
||||
char buf[BUFSIZ];
|
||||
size_t mn, n = strlen(text);
|
||||
|
||||
/* shorten text if necessary */
|
||||
for(mn = MIN(n, sizeof buf); textnw(dc, text, mn) + dc->font.height/2 > dc->w; mn--)
|
||||
if(mn == 0)
|
||||
return;
|
||||
memcpy(buf, text, mn);
|
||||
if(mn < n)
|
||||
for(n = MAX(mn-3, 0); n < mn; buf[n++] = '.');
|
||||
|
||||
drawrect(dc, 0, 0, dc->w, dc->h, True, BG(dc, col));
|
||||
drawtextn(dc, buf, mn, col);
|
||||
}
|
||||
|
||||
void
|
||||
drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]) {
|
||||
int x = dc->x + dc->font.height/2;
|
||||
int y = dc->y + dc->font.ascent+1;
|
||||
|
||||
XSetForeground(dc->dpy, dc->gc, FG(dc, col));
|
||||
if(dc->font.set)
|
||||
XmbDrawString(dc->dpy, dc->canvas, dc->font.set, dc->gc, x, y, text, n);
|
||||
else {
|
||||
XSetFont(dc->dpy, dc->gc, dc->font.xfont->fid);
|
||||
XDrawString(dc->dpy, dc->canvas, dc->gc, x, y, text, n);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
eprintf(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if(fmt[0] != '\0' && fmt[strlen(fmt)-1] == ':') {
|
||||
fputc(' ', stderr);
|
||||
perror(NULL);
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void
|
||||
freedc(DC *dc) {
|
||||
if(dc->font.set)
|
||||
XFreeFontSet(dc->dpy, dc->font.set);
|
||||
if(dc->font.xfont)
|
||||
XFreeFont(dc->dpy, dc->font.xfont);
|
||||
if(dc->canvas)
|
||||
XFreePixmap(dc->dpy, dc->canvas);
|
||||
XFreeGC(dc->dpy, dc->gc);
|
||||
XCloseDisplay(dc->dpy);
|
||||
free(dc);
|
||||
}
|
||||
|
||||
unsigned long
|
||||
getcolor(DC *dc, const char *colstr) {
|
||||
Colormap cmap = DefaultColormap(dc->dpy, DefaultScreen(dc->dpy));
|
||||
XColor color;
|
||||
|
||||
if(!XAllocNamedColor(dc->dpy, cmap, colstr, &color, &color))
|
||||
eprintf("cannot allocate color '%s'\n", colstr);
|
||||
return color.pixel;
|
||||
}
|
||||
|
||||
DC *
|
||||
initdc(void) {
|
||||
DC *dc;
|
||||
|
||||
if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
||||
fputs("no locale support\n", stderr);
|
||||
if(!(dc = calloc(1, sizeof *dc)))
|
||||
eprintf("cannot malloc %u bytes:", sizeof *dc);
|
||||
if(!(dc->dpy = XOpenDisplay(NULL)))
|
||||
eprintf("cannot open display\n");
|
||||
|
||||
dc->gc = XCreateGC(dc->dpy, DefaultRootWindow(dc->dpy), 0, NULL);
|
||||
XSetLineAttributes(dc->dpy, dc->gc, 1, LineSolid, CapButt, JoinMiter);
|
||||
return dc;
|
||||
}
|
||||
|
||||
void
|
||||
initfont(DC *dc, const char *fontstr) {
|
||||
if(!loadfont(dc, fontstr ? fontstr : DEFAULTFN)) {
|
||||
if(fontstr != NULL)
|
||||
fprintf(stderr, "cannot load font '%s'\n", fontstr);
|
||||
if(fontstr == NULL || !loadfont(dc, DEFAULTFN))
|
||||
eprintf("cannot load font '%s'\n", DEFAULTFN);
|
||||
}
|
||||
dc->font.height = dc->font.ascent + dc->font.descent;
|
||||
}
|
||||
|
||||
Bool
|
||||
loadfont(DC *dc, const char *fontstr) {
|
||||
char *def, **missing, **names;
|
||||
int i, n;
|
||||
XFontStruct **xfonts;
|
||||
|
||||
if(!*fontstr)
|
||||
return False;
|
||||
if((dc->font.set = XCreateFontSet(dc->dpy, fontstr, &missing, &n, &def))) {
|
||||
n = XFontsOfFontSet(dc->font.set, &xfonts, &names);
|
||||
for(i = 0; i < n; i++) {
|
||||
dc->font.ascent = MAX(dc->font.ascent, xfonts[i]->ascent);
|
||||
dc->font.descent = MAX(dc->font.descent, xfonts[i]->descent);
|
||||
dc->font.width = MAX(dc->font.width, xfonts[i]->max_bounds.width);
|
||||
}
|
||||
}
|
||||
else if((dc->font.xfont = XLoadQueryFont(dc->dpy, fontstr))) {
|
||||
dc->font.ascent = dc->font.xfont->ascent;
|
||||
dc->font.descent = dc->font.xfont->descent;
|
||||
dc->font.width = dc->font.xfont->max_bounds.width;
|
||||
}
|
||||
if(missing)
|
||||
XFreeStringList(missing);
|
||||
return dc->font.set || dc->font.xfont;
|
||||
}
|
||||
|
||||
void
|
||||
mapdc(DC *dc, Window win, unsigned int w, unsigned int h) {
|
||||
XCopyArea(dc->dpy, dc->canvas, win, dc->gc, 0, 0, w, h, 0, 0);
|
||||
}
|
||||
|
||||
void
|
||||
resizedc(DC *dc, unsigned int w, unsigned int h) {
|
||||
if(dc->canvas)
|
||||
XFreePixmap(dc->dpy, dc->canvas);
|
||||
|
||||
dc->w = w;
|
||||
dc->h = h;
|
||||
dc->canvas = XCreatePixmap(dc->dpy, DefaultRootWindow(dc->dpy), w, h,
|
||||
DefaultDepth(dc->dpy, DefaultScreen(dc->dpy)));
|
||||
}
|
||||
|
||||
int
|
||||
textnw(DC *dc, const char *text, size_t len) {
|
||||
if(dc->font.set) {
|
||||
XRectangle r;
|
||||
|
||||
XmbTextExtents(dc->font.set, text, len, NULL, &r);
|
||||
return r.width;
|
||||
}
|
||||
return XTextWidth(dc->font.xfont, text, len);
|
||||
}
|
||||
|
||||
int
|
||||
textw(DC *dc, const char *text) {
|
||||
return textnw(dc, text, strlen(text)) + dc->font.height;
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
|
||||
#define FG(dc, col) ((col)[(dc)->invert ? ColBG : ColFG])
|
||||
#define BG(dc, col) ((col)[(dc)->invert ? ColFG : ColBG])
|
||||
|
||||
enum { ColBG, ColFG, ColBorder, ColLast };
|
||||
|
||||
typedef struct {
|
||||
int x, y, w, h;
|
||||
Bool invert;
|
||||
Display *dpy;
|
||||
GC gc;
|
||||
Pixmap canvas;
|
||||
struct {
|
||||
int ascent;
|
||||
int descent;
|
||||
int height;
|
||||
int width;
|
||||
XFontSet set;
|
||||
XFontStruct *xfont;
|
||||
} font;
|
||||
} DC; /* draw context */
|
||||
|
||||
void drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsigned long color);
|
||||
void drawtext(DC *dc, const char *text, unsigned long col[ColLast]);
|
||||
void drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]);
|
||||
void eprintf(const char *fmt, ...);
|
||||
void freedc(DC *dc);
|
||||
unsigned long getcolor(DC *dc, const char *colstr);
|
||||
DC *initdc(void);
|
||||
void initfont(DC *dc, const char *fontstr);
|
||||
void mapdc(DC *dc, Window win, unsigned int w, unsigned int h);
|
||||
void resizedc(DC *dc, unsigned int w, unsigned int h);
|
||||
int textnw(DC *dc, const char *text, size_t len);
|
||||
int textw(DC *dc, const char *text);
|
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 955 B |
|
@ -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,24 @@
|
|||
dmenu - dynamic menu
|
||||
====================
|
||||
dmenu is an efficient dynamic menu for X.
|
||||
|
||||
|
||||
Requirements
|
||||
------------
|
||||
In order to build dmenu you need the Xlib header files.
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
Edit config.mk to match your local setup (dmenu is installed into
|
||||
the /usr/local namespace by default).
|
||||
|
||||
Afterwards enter the following command to build and install dmenu
|
||||
(if necessary as root):
|
||||
|
||||
make clean install
|
||||
|
||||
|
||||
Running dmenu
|
||||
-------------
|
||||
See the man page for details.
|
|
@ -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,28 @@
|
|||
/* 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 */
|
||||
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"
|
||||
};
|
||||
static const char *prompt = NULL; /* -p option; prompt to the left of input field */
|
||||
static const char *colors[SchemeLast][2] = {
|
||||
/* fg bg */
|
||||
[SchemeNorm] = { "#bbbbbb", "#222222" },
|
||||
[SchemeSel] = { "#eeeeee", "#005577" },
|
||||
[SchemeSelHighlight] = { "#ffc978", "#005577" },
|
||||
[SchemeNormHighlight] = { "#ffc978", "#222222" },
|
||||
[SchemeOut] = { "#000000", "#00ffff" },
|
||||
[SchemeOutHighlight] = { "#ffc978", "#00ffff" },
|
||||
};
|
||||
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
|
||||
static unsigned int lines = 0;
|
||||
|
||||
/*
|
||||
* Characters not considered part of a word while deleting words
|
||||
* for example: " /?\"&[]"
|
||||
*/
|
||||
static const char worddelimiters[] = " ";
|
|
@ -0,0 +1,25 @@
|
|||
/* 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 */
|
||||
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"
|
||||
};
|
||||
static const char *prompt = NULL; /* -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 option; if nonzero, dmenu uses vertical list with given number of lines */
|
||||
static unsigned int lines = 0;
|
||||
|
||||
/*
|
||||
* Characters not considered part of a word while deleting words
|
||||
* for example: " /?\"&[]"
|
||||
*/
|
||||
static const char worddelimiters[] = " ";
|
|
@ -0,0 +1,28 @@
|
|||
/* 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 */
|
||||
static int centered = 1; /* -c option; centers dmenu on screen */
|
||||
static int min_width = 650; /* minimum width when centered */
|
||||
/* -fn option overrides fonts[0]; default X11 font or font set */
|
||||
static const char *fonts[] = {
|
||||
"SF Pro Sans:size=13"
|
||||
};
|
||||
static const char *prompt = NULL; /* -p option; prompt to the left of input field */
|
||||
static const char *colors[SchemeLast][2] = {
|
||||
/* fg bg */
|
||||
[SchemeNorm] = { "#d3d3d3", "#111111" },
|
||||
[SchemeSel] = { "#111111", "#8f6f8f" },
|
||||
[SchemeSelHighlight] = { "#111111", "#8f6f8f" },
|
||||
[SchemeNormHighlight] = { "#8f6f8f", "#111111" },
|
||||
[SchemeOut] = { "#000000", "#00ffff" },
|
||||
[SchemeOutHighlight] = { "#8f8f8f", "#111111" },
|
||||
};
|
||||
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
|
||||
static unsigned int lines = 20;
|
||||
|
||||
/*
|
||||
* 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)
|
||||
|
||||
# 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
|
Binary file not shown.
|
@ -0,0 +1,197 @@
|
|||
.TH DMENU 1 dmenu\-VERSION
|
||||
.SH NAME
|
||||
dmenu \- dynamic menu
|
||||
.SH SYNOPSIS
|
||||
.B dmenu
|
||||
.RB [ \-bfiv ]
|
||||
.RB [ \-l
|
||||
.IR lines ]
|
||||
.RB [ \-m
|
||||
.IR monitor ]
|
||||
.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 [ \-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 \-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.
|
||||
.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 \-m " monitor"
|
||||
dmenu is displayed on the monitor number supplied. Monitor numbers are starting
|
||||
from 0.
|
||||
.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
|
||||
.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,846 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#include <ctype.h>
|
||||
#include <locale.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, SchemeOut, SchemeNormHighlight, SchemeSelHighlight, SchemeOutHighlight, SchemeLast }; /* color schemes */
|
||||
struct item {
|
||||
char *text;
|
||||
struct item *left, *right;
|
||||
int out;
|
||||
};
|
||||
|
||||
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"
|
||||
|
||||
static char * cistrstr(const char *s, const char *sub);
|
||||
static int (*fstrncmp)(const char *, const char *, size_t) = strncasecmp;
|
||||
static char *(*fstrstr)(const char *, const char *) = cistrstr;
|
||||
|
||||
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 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
char restorechar, tokens[sizeof text], *highlight, *token;
|
||||
int indentx, highlightlen;
|
||||
|
||||
drw_setscheme(drw, scheme[item == sel ? SchemeSelHighlight : item->out ? SchemeOutHighlight : SchemeNormHighlight]);
|
||||
strcpy(tokens, text);
|
||||
for (token = strtok(tokens, " "); token; token = strtok(NULL, " ")) {
|
||||
highlight = fstrstr(item->text, token);
|
||||
while (highlight) {
|
||||
// Move item str end, calc width for highlight indent, & restore
|
||||
highlightlen = highlight - item->text;
|
||||
restorechar = *highlight;
|
||||
item->text[highlightlen] = '\0';
|
||||
indentx = TEXTW(item->text);
|
||||
item->text[highlightlen] = restorechar;
|
||||
|
||||
// Move highlight str end, draw highlight, & restore
|
||||
restorechar = highlight[strlen(token)];
|
||||
highlight[strlen(token)] = '\0';
|
||||
if (indentx - (lrpad / 2) - 1 < maxw)
|
||||
drw_text(
|
||||
drw,
|
||||
x + indentx - (lrpad / 2) - 1,
|
||||
y,
|
||||
MIN(maxw - indentx, TEXTW(highlight) - lrpad),
|
||||
bh, 0, highlight, 0
|
||||
);
|
||||
highlight[strlen(token)] = restorechar;
|
||||
|
||||
if (strlen(highlight) - strlen(token) < strlen(token)) break;
|
||||
highlight = fstrstr(highlight + strlen(token), token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
drawitem(struct item *item, int x, int y, int w)
|
||||
{
|
||||
if (item == sel)
|
||||
drw_setscheme(drw, scheme[SchemeSel]);
|
||||
else if (item->out)
|
||||
drw_setscheme(drw, scheme[SchemeOut]);
|
||||
else
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
|
||||
int 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, 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, 2, bh - 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");
|
||||
}
|
||||
|
||||
static void
|
||||
match(void)
|
||||
{
|
||||
static char **tokv = NULL;
|
||||
static int tokn = 0;
|
||||
|
||||
char buf[sizeof text], *s;
|
||||
int i, tokc = 0;
|
||||
size_t len, textsize;
|
||||
struct item *item, *lprefix, *lsubstr, *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 = lprefix = lsubstr = matchend = 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, then substrings */
|
||||
if (!tokc || !fstrncmp(text, item->text, textsize))
|
||||
appenditem(item, &matches, &matchend);
|
||||
else if (!fstrncmp(tokv[0], item->text, len))
|
||||
appenditem(item, &lprefix, &prefixend);
|
||||
else
|
||||
appenditem(item, &lsubstr, &substrend);
|
||||
}
|
||||
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:
|
||||
case XK_KP_Left:
|
||||
movewordedge(-1);
|
||||
goto draw;
|
||||
case XK_Right:
|
||||
case XK_KP_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:
|
||||
case XK_KP_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:
|
||||
case XK_KP_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:
|
||||
case XK_KP_Home:
|
||||
if (sel == matches) {
|
||||
cursor = 0;
|
||||
break;
|
||||
}
|
||||
sel = curr = matches;
|
||||
calcoffsets();
|
||||
break;
|
||||
case XK_Left:
|
||||
case XK_KP_Left:
|
||||
if (cursor > 0 && (!sel || !sel->left || lines > 0)) {
|
||||
cursor = nextrune(-1);
|
||||
break;
|
||||
}
|
||||
if (lines > 0)
|
||||
return;
|
||||
/* fallthrough */
|
||||
case XK_Up:
|
||||
case XK_KP_Up:
|
||||
if (sel && sel->left && (sel = sel->left)->right == curr) {
|
||||
curr = prev;
|
||||
calcoffsets();
|
||||
}
|
||||
break;
|
||||
case XK_Next:
|
||||
case XK_KP_Next:
|
||||
if (!next)
|
||||
return;
|
||||
sel = curr = next;
|
||||
calcoffsets();
|
||||
break;
|
||||
case XK_Prior:
|
||||
case XK_KP_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:
|
||||
case XK_KP_Right:
|
||||
if (text[cursor] != '\0') {
|
||||
cursor = nextrune(+1);
|
||||
break;
|
||||
}
|
||||
if (lines > 0)
|
||||
return;
|
||||
/* fallthrough */
|
||||
case XK_Down:
|
||||
case XK_KP_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;
|
||||
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;
|
||||
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))) {
|
||||
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;
|
||||
|
||||
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
|
||||
{
|
||||
if (!XGetWindowAttributes(dpy, parentwin, &wa))
|
||||
die("could not get embedding window attributes: 0x%lx",
|
||||
parentwin);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
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] [-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], "-c")) /* centers dmenu on screen */
|
||||
centered = 1;
|
||||
else if (!strcmp(argv[i], "-s")) { /* case-sensitive item matching */
|
||||
fstrncmp = strncmp;
|
||||
fstrstr = strstr;
|
||||
} 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], "-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], "-w")) /* embedding window id */
|
||||
embed = argv[++i];
|
||||
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,808 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#include <ctype.h>
|
||||
#include <locale.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, SchemeOut, SchemeLast }; /* color schemes */
|
||||
|
||||
struct item {
|
||||
char *text;
|
||||
struct item *left, *right;
|
||||
int out;
|
||||
};
|
||||
|
||||
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"
|
||||
|
||||
static char * cistrstr(const char *s, const char *sub);
|
||||
static int (*fstrncmp)(const char *, const char *, size_t) = strncasecmp;
|
||||
static char *(*fstrstr)(const char *, const char *) = cistrstr;
|
||||
|
||||
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 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)
|
||||
{
|
||||
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 int
|
||||
drawitem(struct item *item, int x, int y, int w)
|
||||
{
|
||||
if (item == sel)
|
||||
drw_setscheme(drw, scheme[SchemeSel]);
|
||||
else if (item->out)
|
||||
drw_setscheme(drw, scheme[SchemeOut]);
|
||||
else
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
|
||||
return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
drawmenu(void)
|
||||
{
|
||||
unsigned int curpos;
|
||||
struct item *item;
|
||||
int x = 0, y = 0, 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, 2, bh - 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");
|
||||
}
|
||||
|
||||
static void
|
||||
match(void)
|
||||
{
|
||||
static char **tokv = NULL;
|
||||
static int tokn = 0;
|
||||
|
||||
char buf[sizeof text], *s;
|
||||
int i, tokc = 0;
|
||||
size_t len, textsize;
|
||||
struct item *item, *lprefix, *lsubstr, *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 = lprefix = lsubstr = matchend = 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, then substrings */
|
||||
if (!tokc || !fstrncmp(text, item->text, textsize))
|
||||
appenditem(item, &matches, &matchend);
|
||||
else if (!fstrncmp(tokv[0], item->text, len))
|
||||
appenditem(item, &lprefix, &prefixend);
|
||||
else
|
||||
appenditem(item, &lsubstr, &substrend);
|
||||
}
|
||||
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:
|
||||
case XK_KP_Left:
|
||||
movewordedge(-1);
|
||||
goto draw;
|
||||
case XK_Right:
|
||||
case XK_KP_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:
|
||||
case XK_KP_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:
|
||||
case XK_KP_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:
|
||||
case XK_KP_Home:
|
||||
if (sel == matches) {
|
||||
cursor = 0;
|
||||
break;
|
||||
}
|
||||
sel = curr = matches;
|
||||
calcoffsets();
|
||||
break;
|
||||
case XK_Left:
|
||||
case XK_KP_Left:
|
||||
if (cursor > 0 && (!sel || !sel->left || lines > 0)) {
|
||||
cursor = nextrune(-1);
|
||||
break;
|
||||
}
|
||||
if (lines > 0)
|
||||
return;
|
||||
/* fallthrough */
|
||||
case XK_Up:
|
||||
case XK_KP_Up:
|
||||
if (sel && sel->left && (sel = sel->left)->right == curr) {
|
||||
curr = prev;
|
||||
calcoffsets();
|
||||
}
|
||||
break;
|
||||
case XK_Next:
|
||||
case XK_KP_Next:
|
||||
if (!next)
|
||||
return;
|
||||
sel = curr = next;
|
||||
calcoffsets();
|
||||
break;
|
||||
case XK_Prior:
|
||||
case XK_KP_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:
|
||||
case XK_KP_Right:
|
||||
if (text[cursor] != '\0') {
|
||||
cursor = nextrune(+1);
|
||||
break;
|
||||
}
|
||||
if (lines > 0)
|
||||
return;
|
||||
/* fallthrough */
|
||||
case XK_Down:
|
||||
case XK_KP_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;
|
||||
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;
|
||||
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))) {
|
||||
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;
|
||||
|
||||
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
|
||||
{
|
||||
if (!XGetWindowAttributes(dpy, parentwin, &wa))
|
||||
die("could not get embedding window attributes: 0x%lx",
|
||||
parentwin);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
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] [-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], "-c")) /* centers dmenu on screen */
|
||||
centered = 1;
|
||||
else if (!strcmp(argv[i], "-s")) { /* case-sensitive item matching */
|
||||
fstrncmp = strncmp;
|
||||
fstrstr = strstr;
|
||||
} 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], "-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], "-w")) /* embedding window id */
|
||||
embed = argv[++i];
|
||||
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,11 @@
|
|||
--- dmenu.c
|
||||
+++ dmenu.c
|
||||
@@ -732,6 +755,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;
|
Binary file not shown.
|
@ -0,0 +1,13 @@
|
|||
#!/bin/sh
|
||||
|
||||
cachedir="${XDG_CACHE_HOME:-"$HOME/.cache"}"
|
||||
cache="$cachedir/dmenu_run"
|
||||
|
||||
[ ! -e "$cachedir" ] && mkdir -p "$cachedir"
|
||||
|
||||
IFS=:
|
||||
if stest -dqr -n "$cache" $PATH; then
|
||||
stest -flx $PATH | sort -u | tee "$cache"
|
||||
else
|
||||
cat "$cache"
|
||||
fi
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/sh
|
||||
dmenu_path | dmenu "$@" | ${SHELL:-"/bin/sh"} &
|
|
@ -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);
|
Binary file not shown.
|
@ -0,0 +1,42 @@
|
|||
From 54acbdf72083a5eae5783eed42e162424ab2cec2 Mon Sep 17 00:00:00 2001
|
||||
From: Kim Torgersen <kim@torgersen.se>
|
||||
Date: Sat, 23 May 2020 14:48:28 +0200
|
||||
Subject: [PATCH] case-insensitive item matching default, case-sensitive option
|
||||
(-s)
|
||||
|
||||
---
|
||||
dmenu.c | 11 ++++++-----
|
||||
1 file changed, 6 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/dmenu.c b/dmenu.c
|
||||
index 65f25ce..855df59 100644
|
||||
--- a/dmenu.c
|
||||
+++ b/dmenu.c
|
||||
@@ -55,8 +55,9 @@ static Clr *scheme[SchemeLast];
|
||||
|
||||
#include "config.h"
|
||||
|
||||
-static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
|
||||
-static char *(*fstrstr)(const char *, const char *) = strstr;
|
||||
+static char * cistrstr(const char *s, const char *sub);
|
||||
+static int (*fstrncmp)(const char *, const char *, size_t) = strncasecmp;
|
||||
+static char *(*fstrstr)(const char *, const char *) = cistrstr;
|
||||
|
||||
static void
|
||||
appenditem(struct item *item, struct item **list, struct item **last)
|
||||
@@ -709,9 +710,9 @@ 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], "-i")) { /* case-insensitive item matching */
|
||||
- fstrncmp = strncasecmp;
|
||||
- fstrstr = cistrstr;
|
||||
+ else if (!strcmp(argv[i], "-s")) { /* case-sensitive item matching */
|
||||
+ fstrncmp = strncmp;
|
||||
+ fstrstr = strstr;
|
||||
} else if (i + 1 == argc)
|
||||
usage();
|
||||
/* these options take one argument */
|
||||
--
|
||||
2.26.2
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
From fcdc1593ed418166f20b7e691a49b1e6eefc116e Mon Sep 17 00:00:00 2001
|
||||
From: Nathaniel Evan <nathanielevan@zohomail.com>
|
||||
Date: Fri, 11 Dec 2020 11:08:12 +0700
|
||||
Subject: [PATCH] Highlight matched text in a different color scheme
|
||||
|
||||
---
|
||||
config.def.h | 3 +++
|
||||
dmenu.c | 44 +++++++++++++++++++++++++++++++++++++++++---
|
||||
2 files changed, 44 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/config.def.h b/config.def.h
|
||||
index 1edb647..79be73a 100644
|
||||
--- a/config.def.h
|
||||
+++ b/config.def.h
|
||||
@@ -11,7 +11,10 @@ static const char *colors[SchemeLast][2] = {
|
||||
/* fg bg */
|
||||
[SchemeNorm] = { "#bbbbbb", "#222222" },
|
||||
[SchemeSel] = { "#eeeeee", "#005577" },
|
||||
+ [SchemeSelHighlight] = { "#ffc978", "#005577" },
|
||||
+ [SchemeNormHighlight] = { "#ffc978", "#222222" },
|
||||
[SchemeOut] = { "#000000", "#00ffff" },
|
||||
+ [SchemeOutHighlight] = { "#ffc978", "#00ffff" },
|
||||
};
|
||||
/* -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 65f25ce..cce1ad1 100644
|
||||
--- a/dmenu.c
|
||||
+++ b/dmenu.c
|
||||
@@ -26,8 +26,7 @@
|
||||
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
|
||||
|
||||
/* enums */
|
||||
-enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
|
||||
-
|
||||
+enum { SchemeNorm, SchemeSel, SchemeOut, SchemeNormHighlight, SchemeSelHighlight, SchemeOutHighlight, SchemeLast }; /* color schemes */
|
||||
struct item {
|
||||
char *text;
|
||||
struct item *left, *right;
|
||||
@@ -113,6 +112,43 @@ cistrstr(const char *s, const char *sub)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+static void
|
||||
+drawhighlights(struct item *item, int x, int y, int maxw)
|
||||
+{
|
||||
+ char restorechar, tokens[sizeof text], *highlight, *token;
|
||||
+ int indentx, highlightlen;
|
||||
+
|
||||
+ drw_setscheme(drw, scheme[item == sel ? SchemeSelHighlight : item->out ? SchemeOutHighlight : SchemeNormHighlight]);
|
||||
+ strcpy(tokens, text);
|
||||
+ for (token = strtok(tokens, " "); token; token = strtok(NULL, " ")) {
|
||||
+ highlight = fstrstr(item->text, token);
|
||||
+ while (highlight) {
|
||||
+ // Move item str end, calc width for highlight indent, & restore
|
||||
+ highlightlen = highlight - item->text;
|
||||
+ restorechar = *highlight;
|
||||
+ item->text[highlightlen] = '\0';
|
||||
+ indentx = TEXTW(item->text);
|
||||
+ item->text[highlightlen] = restorechar;
|
||||
+
|
||||
+ // Move highlight str end, draw highlight, & restore
|
||||
+ restorechar = highlight[strlen(token)];
|
||||
+ highlight[strlen(token)] = '\0';
|
||||
+ if (indentx - (lrpad / 2) - 1 < maxw)
|
||||
+ drw_text(
|
||||
+ drw,
|
||||
+ x + indentx - (lrpad / 2) - 1,
|
||||
+ y,
|
||||
+ MIN(maxw - indentx, TEXTW(highlight) - lrpad),
|
||||
+ bh, 0, highlight, 0
|
||||
+ );
|
||||
+ highlight[strlen(token)] = restorechar;
|
||||
+
|
||||
+ if (strlen(highlight) - strlen(token) < strlen(token)) break;
|
||||
+ highlight = fstrstr(highlight + strlen(token), token);
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
static int
|
||||
drawitem(struct item *item, int x, int y, int w)
|
||||
{
|
||||
@@ -123,7 +159,9 @@ drawitem(struct item *item, int x, int y, int w)
|
||||
else
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
|
||||
- return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
|
||||
+ int r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
|
||||
+ drawhighlights(item, x, y, w);
|
||||
+ return r;
|
||||
}
|
||||
|
||||
static void
|
||||
--
|
||||
2.29.2
|
||||
|
Binary file not shown.
|
@ -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 (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;
|
||||
}
|
Binary file not shown.
|
@ -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);
|
Binary file not shown.
|
@ -0,0 +1,37 @@
|
|||
MIT/X Consortium License
|
||||
|
||||
© 2006-2019 Anselm R Garbe <anselm@garbe.ca>
|
||||
© 2006-2009 Jukka Salmi <jukka at salmi dot ch>
|
||||
© 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
|
||||
© 2007-2011 Peter Hartlich <sgkkr at hartlich dot com>
|
||||
© 2007-2009 Szabolcs Nagy <nszabolcs at gmail dot com>
|
||||
© 2007-2009 Christof Musik <christof at sendfax dot de>
|
||||
© 2007-2009 Premysl Hruby <dfenze at gmail dot com>
|
||||
© 2007-2008 Enno Gottox Boland <gottox at s01 dot de>
|
||||
© 2008 Martin Hurton <martin dot hurton at gmail dot com>
|
||||
© 2008 Neale Pickett <neale dot woozle dot org>
|
||||
© 2009 Mate Nagy <mnagy at port70 dot net>
|
||||
© 2010-2016 Hiltjo Posthuma <hiltjo@codemadness.org>
|
||||
© 2010-2012 Connor Lane Smith <cls@lubutu.com>
|
||||
© 2011 Christoph Lohmann <20h@r-36.net>
|
||||
© 2015-2016 Quentin Rameau <quinq@fifth.space>
|
||||
© 2015-2016 Eric Pruitt <eric.pruitt@gmail.com>
|
||||
© 2016-2017 Markus Teich <markus.teich@stusta.mhn.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,51 @@
|
|||
# dwm - dynamic window manager
|
||||
# See LICENSE file for copyright and license details.
|
||||
|
||||
include config.mk
|
||||
|
||||
SRC = drw.c dwm.c util.c
|
||||
OBJ = ${SRC:.c=.o}
|
||||
|
||||
all: options dwm
|
||||
|
||||
options:
|
||||
@echo dwm build options:
|
||||
@echo "CFLAGS = ${CFLAGS}"
|
||||
@echo "LDFLAGS = ${LDFLAGS}"
|
||||
@echo "CC = ${CC}"
|
||||
|
||||
.c.o:
|
||||
${CC} -c ${CFLAGS} $<
|
||||
|
||||
${OBJ}: config.h config.mk
|
||||
|
||||
config.h:
|
||||
cp config.def.h $@
|
||||
|
||||
dwm: ${OBJ}
|
||||
${CC} -o $@ ${OBJ} ${LDFLAGS}
|
||||
|
||||
clean:
|
||||
rm -f dwm ${OBJ} dwm-${VERSION}.tar.gz
|
||||
|
||||
dist: clean
|
||||
mkdir -p dwm-${VERSION}
|
||||
cp -R LICENSE Makefile README config.def.h config.mk\
|
||||
dwm.1 drw.h util.h ${SRC} dwm.png transient.c dwm-${VERSION}
|
||||
tar -cf dwm-${VERSION}.tar dwm-${VERSION}
|
||||
gzip dwm-${VERSION}.tar
|
||||
rm -rf dwm-${VERSION}
|
||||
|
||||
install: all
|
||||
mkdir -p ${DESTDIR}${PREFIX}/bin
|
||||
cp -f dwm ${DESTDIR}${PREFIX}/bin
|
||||
chmod 755 ${DESTDIR}${PREFIX}/bin/dwm
|
||||
mkdir -p ${DESTDIR}${MANPREFIX}/man1
|
||||
sed "s/VERSION/${VERSION}/g" < dwm.1 > ${DESTDIR}${MANPREFIX}/man1/dwm.1
|
||||
chmod 644 ${DESTDIR}${MANPREFIX}/man1/dwm.1
|
||||
|
||||
uninstall:
|
||||
rm -f ${DESTDIR}${PREFIX}/bin/dwm\
|
||||
${DESTDIR}${MANPREFIX}/man1/dwm.1
|
||||
|
||||
.PHONY: all options clean dist install uninstall
|
|
@ -0,0 +1,48 @@
|
|||
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.
|
|
@ -0,0 +1,156 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
|
||||
/* appearance */
|
||||
static const unsigned int borderpx = 1; /* border pixel of windows */
|
||||
static const unsigned int snap = 32; /* snap pixel */
|
||||
static const unsigned int gappih = 20; /* horiz inner gap between windows */
|
||||
static const unsigned int gappiv = 10; /* vert inner gap between windows */
|
||||
static const unsigned int gappoh = 10; /* horiz outer gap between windows and screen edge */
|
||||
static const unsigned int gappov = 30; /* vert outer gap between windows and screen edge */
|
||||
static int smartgaps = 0; /* 1 means no outer gap when there is only one window */
|
||||
static const int showbar = 1; /* 0 means no bar */
|
||||
static const int topbar = 1; /* 0 means bottom bar */
|
||||
static const char *fonts[] = { "monospace:size=10" };
|
||||
static const char dmenufont[] = "monospace:size=10";
|
||||
static const char col_gray1[] = "#222222";
|
||||
static const char col_gray2[] = "#444444";
|
||||
static const char col_gray3[] = "#bbbbbb";
|
||||
static const char col_gray4[] = "#eeeeee";
|
||||
static const char col_cyan[] = "#005577";
|
||||
static const char *colors[][3] = {
|
||||
/* fg bg border */
|
||||
[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
|
||||
[SchemeSel] = { col_gray4, col_cyan, col_cyan },
|
||||
};
|
||||
|
||||
static const char *const autostart[] = {
|
||||
"st", NULL,
|
||||
NULL /* terminate */
|
||||
};
|
||||
|
||||
/* tagging */
|
||||
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
||||
|
||||
static const Rule rules[] = {
|
||||
/* xprop(1):
|
||||
* WM_CLASS(STRING) = instance, class
|
||||
* WM_NAME(STRING) = title
|
||||
*/
|
||||
/* class instance title tags mask isfloating monitor */
|
||||
{ "Gimp", NULL, NULL, 0, 1, -1 },
|
||||
{ "Firefox", NULL, NULL, 1 << 8, 0, -1 },
|
||||
};
|
||||
|
||||
/* layout(s) */
|
||||
static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
|
||||
static const int nmaster = 1; /* number of clients in master area */
|
||||
static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
|
||||
|
||||
#define FORCE_VSPLIT 1 /* nrowgrid layout: force two clients to always split vertically */
|
||||
#include "vanitygaps.c"
|
||||
|
||||
static const Layout layouts[] = {
|
||||
/* symbol arrange function */
|
||||
{ "[]=", tile }, /* first entry is default */
|
||||
{ "[M]", monocle },
|
||||
{ "[@]", spiral },
|
||||
{ "[\\]", dwindle },
|
||||
{ "H[]", deck },
|
||||
{ "TTT", bstack },
|
||||
{ "===", bstackhoriz },
|
||||
{ "HHH", grid },
|
||||
{ "###", nrowgrid },
|
||||
{ "---", horizgrid },
|
||||
{ ":::", gaplessgrid },
|
||||
{ "|M|", centeredmaster },
|
||||
{ ">M>", centeredfloatingmaster },
|
||||
{ "><>", NULL }, /* no layout function means floating behavior */
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
/* key definitions */
|
||||
#define MODKEY Mod1Mask
|
||||
#define TAGKEYS(KEY,TAG) \
|
||||
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \
|
||||
{ MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
|
||||
{ MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \
|
||||
{ MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} },
|
||||
|
||||
/* helper for spawning shell commands in the pre dwm-5.0 fashion */
|
||||
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
|
||||
|
||||
/* commands */
|
||||
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
|
||||
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
|
||||
static const char *termcmd[] = { "st", NULL };
|
||||
|
||||
static Key keys[] = {
|
||||
/* modifier key function argument */
|
||||
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
|
||||
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
|
||||
{ MODKEY, XK_b, togglebar, {0} },
|
||||
{ MODKEY, XK_j, focusstack, {.i = +1 } },
|
||||
{ MODKEY, XK_k, focusstack, {.i = -1 } },
|
||||
{ MODKEY, XK_i, incnmaster, {.i = +1 } },
|
||||
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
|
||||
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
|
||||
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
|
||||
{ MODKEY, XK_Return, zoom, {0} },
|
||||
{ MODKEY|Mod4Mask, XK_u, incrgaps, {.i = +1 } },
|
||||
{ MODKEY|Mod4Mask|ShiftMask, XK_u, incrgaps, {.i = -1 } },
|
||||
{ MODKEY|Mod4Mask, XK_i, incrigaps, {.i = +1 } },
|
||||
{ MODKEY|Mod4Mask|ShiftMask, XK_i, incrigaps, {.i = -1 } },
|
||||
{ MODKEY|Mod4Mask, XK_o, incrogaps, {.i = +1 } },
|
||||
{ MODKEY|Mod4Mask|ShiftMask, XK_o, incrogaps, {.i = -1 } },
|
||||
{ MODKEY|Mod4Mask, XK_6, incrihgaps, {.i = +1 } },
|
||||
{ MODKEY|Mod4Mask|ShiftMask, XK_6, incrihgaps, {.i = -1 } },
|
||||
{ MODKEY|Mod4Mask, XK_7, incrivgaps, {.i = +1 } },
|
||||
{ MODKEY|Mod4Mask|ShiftMask, XK_7, incrivgaps, {.i = -1 } },
|
||||
{ MODKEY|Mod4Mask, XK_8, incrohgaps, {.i = +1 } },
|
||||
{ MODKEY|Mod4Mask|ShiftMask, XK_8, incrohgaps, {.i = -1 } },
|
||||
{ MODKEY|Mod4Mask, XK_9, incrovgaps, {.i = +1 } },
|
||||
{ MODKEY|Mod4Mask|ShiftMask, XK_9, incrovgaps, {.i = -1 } },
|
||||
{ MODKEY|Mod4Mask, XK_0, togglegaps, {0} },
|
||||
{ MODKEY|Mod4Mask|ShiftMask, XK_0, defaultgaps, {0} },
|
||||
{ MODKEY, XK_Tab, view, {0} },
|
||||
{ MODKEY|ShiftMask, XK_c, killclient, {0} },
|
||||
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
|
||||
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
|
||||
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
|
||||
{ MODKEY, XK_space, setlayout, {0} },
|
||||
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
|
||||
{ MODKEY, XK_0, view, {.ui = ~0 } },
|
||||
{ MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
|
||||
{ MODKEY, XK_comma, focusmon, {.i = -1 } },
|
||||
{ MODKEY, XK_period, focusmon, {.i = +1 } },
|
||||
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
|
||||
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
|
||||
TAGKEYS( XK_1, 0)
|
||||
TAGKEYS( XK_2, 1)
|
||||
TAGKEYS( XK_3, 2)
|
||||
TAGKEYS( XK_4, 3)
|
||||
TAGKEYS( XK_5, 4)
|
||||
TAGKEYS( XK_6, 5)
|
||||
TAGKEYS( XK_7, 6)
|
||||
TAGKEYS( XK_8, 7)
|
||||
TAGKEYS( XK_9, 8)
|
||||
{ MODKEY|ShiftMask, XK_q, quit, {0} },
|
||||
};
|
||||
|
||||
/* button definitions */
|
||||
/* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
|
||||
static Button buttons[] = {
|
||||
/* click event mask button function argument */
|
||||
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
|
||||
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
|
||||
{ ClkWinTitle, 0, Button2, zoom, {0} },
|
||||
{ ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
|
||||
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
|
||||
{ ClkClientWin, MODKEY, Button2, togglefloating, {0} },
|
||||
{ ClkClientWin, MODKEY, Button3, resizemouse, {0} },
|
||||
{ ClkTagBar, 0, Button1, view, {0} },
|
||||
{ ClkTagBar, 0, Button3, toggleview, {0} },
|
||||
{ ClkTagBar, MODKEY, Button1, tag, {0} },
|
||||
{ ClkTagBar, MODKEY, Button3, toggletag, {0} },
|
||||
};
|
||||
|
|
@ -0,0 +1,170 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
|
||||
/* appearance */
|
||||
static const unsigned int borderpx = 0; /* border pixel of windows */
|
||||
static const unsigned int snap = 32; /* snap pixel */
|
||||
static const unsigned int gappih = 8; /* horiz inner gap between windows */
|
||||
static const unsigned int gappiv = 8; /* vert inner gap between windows */
|
||||
static const unsigned int gappoh = 8; /* horiz outer gap between windows and screen edge */
|
||||
static const unsigned int gappov = 8; /* vert outer gap between windows and screen edge */
|
||||
static int smartgaps = 1; /* 1 means no outer gap when there is only one window */
|
||||
static const int showbar = 1; /* 0 means no bar */
|
||||
static const int topbar = 1; /* 0 means bottom bar */
|
||||
static const int usealtbar = 1; /* 1 means use non-dwm status bar */
|
||||
static const char *altbarclass = "Polybar"; /* Alternate bar class name */
|
||||
static const char *alttrayname = "tray"; /* Polybar tray instance name */
|
||||
static const char *altbarcmd = "~/.config/polybar/launch.sh"; /* Alternate bar launch command */
|
||||
static const char *fonts[] = { "SF Pro Display:size=13" };
|
||||
static const char dmenufont[] = "SF Pro Display:size=13";
|
||||
static const char col_gray1[] = "#222222";
|
||||
static const char col_gray2[] = "#444444";
|
||||
static const char col_gray3[] = "#bbbbbb";
|
||||
static const char col_gray4[] = "#eeeeee";
|
||||
static const char col_cyan[] = "#005577";
|
||||
static const char *colors[][3] = {
|
||||
/* fg bg border */
|
||||
[SchemeNorm] = { "#e3e1e4", "#1a181a", col_gray2 },
|
||||
[SchemeSel] = { "#1a181a", "#e3e1e4", col_cyan },
|
||||
};
|
||||
|
||||
static const char *const autostart[] = {
|
||||
"picom", "--experimental-backends", "--backend", "glx", NULL,
|
||||
"setroot", "~/Pictures/Anime-Girls-Holding-Programming-Books/Rust/Rin_Shima_The_Rust_Programming_Language_2.png", "~/Pictures/Anime-Girls-Holding-Programming-Books/Rust/Rin_Shima_The_Rust_Programming_Language.png", NULL,
|
||||
"keepassxc", NULL,
|
||||
"redshift", NULL,
|
||||
"xinput", "set-prop", "SteelSeries SteelSeries Rival 300S Gaming Mouse", "Coordinate Transformation Matrix", "0.62", "0.0", "0.0", "0.0", "0.62", "0.0", "0.0", "0.0", "1.0", NULL,
|
||||
"wired", NULL,
|
||||
NULL /* terminate */
|
||||
};
|
||||
|
||||
/* tagging */
|
||||
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
||||
|
||||
static const Rule rules[] = {
|
||||
/* xprop(1):
|
||||
* WM_CLASS(STRING) = instance, class
|
||||
* WM_NAME(STRING) = title
|
||||
*/
|
||||
/* class instance title tags mask isfloating monitor */
|
||||
{ "Gimp", NULL, NULL, 0, 1, -1 },
|
||||
{ "discord", NULL, NULL, 0, 1, -1 },
|
||||
{ "wired", NULL, NULL, 0, 1, -1 },
|
||||
};
|
||||
|
||||
/* layout(s) */
|
||||
static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
|
||||
static const int nmaster = 1; /* number of clients in master area */
|
||||
static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
|
||||
|
||||
#define FORCE_VSPLIT 1 /* nrowgrid layout: force two clients to always split vertically */
|
||||
#include "vanitygaps.c"
|
||||
|
||||
static const Layout layouts[] = {
|
||||
/* symbol arrange function */
|
||||
{ "[]=", tile }, /* first entry is default */
|
||||
{ "[M]", monocle },
|
||||
{ "[@]", spiral },
|
||||
{ "[\\]", dwindle },
|
||||
{ "H[]", deck },
|
||||
{ "TTT", bstack },
|
||||
{ "===", bstackhoriz },
|
||||
{ "HHH", grid },
|
||||
{ "###", nrowgrid },
|
||||
{ "---", horizgrid },
|
||||
{ ":::", gaplessgrid },
|
||||
{ "|M|", centeredmaster },
|
||||
{ ">M>", centeredfloatingmaster },
|
||||
{ "><>", NULL }, /* no layout function means floating behavior */
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
/* key definitions */
|
||||
#define MODKEY Mod4Mask
|
||||
#define TAGKEYS(KEY,TAG) \
|
||||
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \
|
||||
{ MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
|
||||
{ MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \
|
||||
{ MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} },
|
||||
|
||||
/* helper for spawning shell commands in the pre dwm-5.0 fashion */
|
||||
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
|
||||
|
||||
/* commands */
|
||||
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
|
||||
static const char *dmenucmd[] = { "dmenu_run", NULL };
|
||||
static const char *termcmd[] = { "st", NULL };
|
||||
|
||||
static Key keys[] = {
|
||||
/* modifier key function argument */
|
||||
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
|
||||
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
|
||||
/* { MODKEY, XK_b, togglebar, {0} }, */
|
||||
{ MODKEY, XK_j, focusstack, {.i = +1 } },
|
||||
{ MODKEY, XK_k, focusstack, {.i = -1 } },
|
||||
{ MODKEY, XK_i, incnmaster, {.i = +1 } },
|
||||
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
|
||||
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
|
||||
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
|
||||
{ MODKEY, XK_Return, zoom, {0} },
|
||||
/* { MODKEY|Mod4Mask, XK_u, incrgaps, {.i = +1 } },
|
||||
{ MODKEY|Mod4Mask|ShiftMask, XK_u, incrgaps, {.i = -1 } },
|
||||
{ MODKEY|Mod4Mask, XK_i, incrigaps, {.i = +1 } },
|
||||
{ MODKEY|Mod4Mask|ShiftMask, XK_i, incrigaps, {.i = -1 } },
|
||||
{ MODKEY|Mod4Mask, XK_o, incrogaps, {.i = +1 } },
|
||||
{ MODKEY|Mod4Mask|ShiftMask, XK_o, incrogaps, {.i = -1 } },
|
||||
{ MODKEY|Mod4Mask, XK_6, incrihgaps, {.i = +1 } },
|
||||
{ MODKEY|Mod4Mask|ShiftMask, XK_6, incrihgaps, {.i = -1 } },
|
||||
{ MODKEY|Mod4Mask, XK_7, incrivgaps, {.i = +1 } },
|
||||
{ MODKEY|Mod4Mask|ShiftMask, XK_7, incrivgaps, {.i = -1 } },
|
||||
{ MODKEY|Mod4Mask, XK_8, incrohgaps, {.i = +1 } },
|
||||
{ MODKEY|Mod4Mask|ShiftMask, XK_8, incrohgaps, {.i = -1 } },
|
||||
{ MODKEY|Mod4Mask, XK_9, incrovgaps, {.i = +1 } },
|
||||
{ MODKEY|Mod4Mask|ShiftMask, XK_9, incrovgaps, {.i = -1 } },
|
||||
{ MODKEY|Mod4Mask, XK_0, togglegaps, {0} },
|
||||
{ MODKEY|Mod4Mask|ShiftMask, XK_0, defaultgaps, {0} }, */
|
||||
{ MODKEY, XK_Tab, view, {0} },
|
||||
{ MODKEY|ShiftMask, XK_c, killclient, {0} },
|
||||
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
|
||||
{ MODKEY, XK_f, setlayout, {.v = &layouts[13]} },
|
||||
{ MODKEY, XK_m, setlayout, {.v = &layouts[1]} },
|
||||
{ MODKEY, XK_s, setlayout, {.v = &layouts[4]} },
|
||||
{ MODKEY, XK_g, setlayout, {.v = &layouts[7]} },
|
||||
{ MODKEY, XK_b, setlayout, {.v = &layouts[5]} },
|
||||
{ MODKEY, XK_w, setlayout, {.v = &layouts[3]} },
|
||||
{ MODKEY, XK_space, setlayout, {0} },
|
||||
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
|
||||
{ MODKEY, XK_0, view, {.ui = ~0 } },
|
||||
{ MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
|
||||
{ MODKEY, XK_comma, focusmon, {.i = -1 } },
|
||||
{ MODKEY, XK_period, focusmon, {.i = +1 } },
|
||||
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
|
||||
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
|
||||
TAGKEYS( XK_1, 0)
|
||||
TAGKEYS( XK_2, 1)
|
||||
TAGKEYS( XK_3, 2)
|
||||
TAGKEYS( XK_4, 3)
|
||||
TAGKEYS( XK_5, 4)
|
||||
TAGKEYS( XK_6, 5)
|
||||
TAGKEYS( XK_7, 6)
|
||||
TAGKEYS( XK_8, 7)
|
||||
TAGKEYS( XK_9, 8)
|
||||
{ MODKEY|ShiftMask, XK_q, quit, {0} },
|
||||
};
|
||||
|
||||
/* button definitions */
|
||||
/* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
|
||||
static Button buttons[] = {
|
||||
/* click event mask button function argument */
|
||||
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
|
||||
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
|
||||
{ ClkWinTitle, 0, Button2, zoom, {0} },
|
||||
{ ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
|
||||
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
|
||||
{ ClkClientWin, MODKEY, Button2, togglefloating, {0} },
|
||||
{ ClkClientWin, MODKEY, Button3, resizemouse, {0} },
|
||||
{ ClkTagBar, 0, Button1, view, {0} },
|
||||
{ ClkTagBar, 0, Button3, toggleview, {0} },
|
||||
{ ClkTagBar, MODKEY, Button1, tag, {0} },
|
||||
{ ClkTagBar, MODKEY, Button3, toggletag, {0} },
|
||||
};
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
# dwm version
|
||||
VERSION = 6.2
|
||||
|
||||
# Customize below to fit your system
|
||||
|
||||
# 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}
|
||||
|
||||
# flags
|
||||
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
|
||||
#CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
|
||||
CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os ${INCS} ${CPPFLAGS}
|
||||
LDFLAGS = ${LIBS}
|
||||
|
||||
# Solaris
|
||||
#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
|
||||
#LDFLAGS = ${LIBS}
|
||||
|
||||
# compiler and linker
|
||||
CC = cc
|
|
@ -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, ColBorder }; /* 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);
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,445 @@
|
|||
From 9b5719969ce85c3ecc0238d49c0255c5c2cc79f0 Mon Sep 17 00:00:00 2001
|
||||
From: mihirlad55 <mihirlad55@gmail.com>
|
||||
Date: Mon, 10 Aug 2020 01:39:28 +0000
|
||||
Subject: [PATCH] Add support for managing external status bars
|
||||
|
||||
This patch allows dwm to manage other status bars such as
|
||||
polybar/lemonbar without them needing to set override-redirect. For
|
||||
all intents and purposes, DWM treats this bar as if it were its own
|
||||
and as a result helps the status bar and DWM live in harmony.
|
||||
|
||||
This has a few advantages
|
||||
* The bar does not block fullscreen windows
|
||||
* DWM makes room for the status bar, so windows do not overlap the bar
|
||||
* The bar can be hidden/killed and DWM will not keep an unsightly gap
|
||||
where the bar was
|
||||
* DWM receives EnterNotify events when your cursor enters the bar
|
||||
|
||||
To use another status bar, set usealtbar to 1 in your config.h and set
|
||||
altbarclass to the class name (can be found using xprop) to the class
|
||||
name of your status bar. Also make sure that if your status bar will
|
||||
be displayed on top, topbar is set to 1 in your config, and if it will
|
||||
be displayed on bottom, topbar is set to 0. This patch does not
|
||||
support bars that are not docked at the top or at the bottom of your
|
||||
monitor.
|
||||
|
||||
This verison of the patch fixes handling of polybar's tray.
|
||||
|
||||
The patch is developed at https://github.com/mihirlad55/dwm-anybar
|
||||
---
|
||||
config.def.h | 4 ++
|
||||
dwm.c | 192 +++++++++++++++++++++++++++++++++++++++++++++++----
|
||||
2 files changed, 181 insertions(+), 15 deletions(-)
|
||||
|
||||
diff --git a/config.def.h b/config.def.h
|
||||
index 1c0b587..f45211b 100644
|
||||
--- a/config.def.h
|
||||
+++ b/config.def.h
|
||||
@@ -5,6 +5,10 @@ static const unsigned int borderpx = 1; /* border pixel of windows */
|
||||
static const unsigned int snap = 32; /* snap pixel */
|
||||
static const int showbar = 1; /* 0 means no bar */
|
||||
static const int topbar = 1; /* 0 means bottom bar */
|
||||
+static const int usealtbar = 1; /* 1 means use non-dwm status bar */
|
||||
+static const char *altbarclass = "Polybar"; /* Alternate bar class name */
|
||||
+static const char *alttrayname = "tray"; /* Polybar tray instance name */
|
||||
+static const char *altbarcmd = "$HOME/bar.sh"; /* Alternate bar launch command */
|
||||
static const char *fonts[] = { "monospace:size=10" };
|
||||
static const char dmenufont[] = "monospace:size=10";
|
||||
static const char col_gray1[] = "#222222";
|
||||
diff --git a/dwm.c b/dwm.c
|
||||
index 9fd0286..c1d8ce0 100644
|
||||
--- a/dwm.c
|
||||
+++ b/dwm.c
|
||||
@@ -47,8 +47,8 @@
|
||||
/* macros */
|
||||
#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
|
||||
#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
|
||||
-#define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
|
||||
- * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
|
||||
+#define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->mx+(m)->mw) - MAX((x),(m)->mx)) \
|
||||
+ * MAX(0, MIN((y)+(h),(m)->my+(m)->mh) - MAX((y),(m)->my)))
|
||||
#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
|
||||
#define LENGTH(X) (sizeof X / sizeof X[0])
|
||||
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
|
||||
@@ -116,7 +116,8 @@ struct Monitor {
|
||||
float mfact;
|
||||
int nmaster;
|
||||
int num;
|
||||
- int by; /* bar geometry */
|
||||
+ int by, bh; /* bar geometry */
|
||||
+ int tx, tw; /* bar tray geometry */
|
||||
int mx, my, mw, mh; /* screen size */
|
||||
int wx, wy, ww, wh; /* window area */
|
||||
unsigned int seltags;
|
||||
@@ -129,6 +130,7 @@ struct Monitor {
|
||||
Client *stack;
|
||||
Monitor *next;
|
||||
Window barwin;
|
||||
+ Window traywin;
|
||||
const Layout *lt[2];
|
||||
};
|
||||
|
||||
@@ -179,6 +181,8 @@ static void incnmaster(const Arg *arg);
|
||||
static void keypress(XEvent *e);
|
||||
static void killclient(const Arg *arg);
|
||||
static void manage(Window w, XWindowAttributes *wa);
|
||||
+static void managealtbar(Window win, XWindowAttributes *wa);
|
||||
+static void managetray(Window win, XWindowAttributes *wa);
|
||||
static void mappingnotify(XEvent *e);
|
||||
static void maprequest(XEvent *e);
|
||||
static void monocle(Monitor *m);
|
||||
@@ -195,6 +199,7 @@ static void resizemouse(const Arg *arg);
|
||||
static void restack(Monitor *m);
|
||||
static void run(void);
|
||||
static void scan(void);
|
||||
+static void scantray(void);
|
||||
static int sendevent(Client *c, Atom proto);
|
||||
static void sendmon(Client *c, Monitor *m);
|
||||
static void setclientstate(Client *c, long state);
|
||||
@@ -207,6 +212,7 @@ static void seturgent(Client *c, int urg);
|
||||
static void showhide(Client *c);
|
||||
static void sigchld(int unused);
|
||||
static void spawn(const Arg *arg);
|
||||
+static void spawnbar();
|
||||
static void tag(const Arg *arg);
|
||||
static void tagmon(const Arg *arg);
|
||||
static void tile(Monitor *);
|
||||
@@ -216,6 +222,8 @@ static void toggletag(const Arg *arg);
|
||||
static void toggleview(const Arg *arg);
|
||||
static void unfocus(Client *c, int setfocus);
|
||||
static void unmanage(Client *c, int destroyed);
|
||||
+static void unmanagealtbar(Window w);
|
||||
+static void unmanagetray(Window w);
|
||||
static void unmapnotify(XEvent *e);
|
||||
static void updatebarpos(Monitor *m);
|
||||
static void updatebars(void);
|
||||
@@ -230,6 +238,7 @@ static void updatewmhints(Client *c);
|
||||
static void view(const Arg *arg);
|
||||
static Client *wintoclient(Window w);
|
||||
static Monitor *wintomon(Window w);
|
||||
+static int wmclasscontains(Window win, const char *class, const char *name);
|
||||
static int xerror(Display *dpy, XErrorEvent *ee);
|
||||
static int xerrordummy(Display *dpy, XErrorEvent *ee);
|
||||
static int xerrorstart(Display *dpy, XErrorEvent *ee);
|
||||
@@ -505,8 +514,10 @@ cleanupmon(Monitor *mon)
|
||||
for (m = mons; m && m->next != mon; m = m->next);
|
||||
m->next = mon->next;
|
||||
}
|
||||
- XUnmapWindow(dpy, mon->barwin);
|
||||
- XDestroyWindow(dpy, mon->barwin);
|
||||
+ if (!usealtbar) {
|
||||
+ XUnmapWindow(dpy, mon->barwin);
|
||||
+ XDestroyWindow(dpy, mon->barwin);
|
||||
+ }
|
||||
free(mon);
|
||||
}
|
||||
|
||||
@@ -568,7 +579,7 @@ configurenotify(XEvent *e)
|
||||
for (c = m->clients; c; c = c->next)
|
||||
if (c->isfullscreen)
|
||||
resizeclient(c, m->mx, m->my, m->mw, m->mh);
|
||||
- XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
|
||||
+ XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, m->bh);
|
||||
}
|
||||
focus(NULL);
|
||||
arrange(NULL);
|
||||
@@ -639,6 +650,7 @@ createmon(void)
|
||||
m->nmaster = nmaster;
|
||||
m->showbar = showbar;
|
||||
m->topbar = topbar;
|
||||
+ m->bh = bh;
|
||||
m->lt[0] = &layouts[0];
|
||||
m->lt[1] = &layouts[1 % LENGTH(layouts)];
|
||||
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
|
||||
@@ -649,10 +661,15 @@ void
|
||||
destroynotify(XEvent *e)
|
||||
{
|
||||
Client *c;
|
||||
+ Monitor *m;
|
||||
XDestroyWindowEvent *ev = &e->xdestroywindow;
|
||||
|
||||
if ((c = wintoclient(ev->window)))
|
||||
unmanage(c, 1);
|
||||
+ else if ((m = wintomon(ev->window)) && m->barwin == ev->window)
|
||||
+ unmanagealtbar(ev->window);
|
||||
+ else if (m->traywin == ev->window)
|
||||
+ unmanagetray(ev->window);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -696,6 +713,9 @@ dirtomon(int dir)
|
||||
void
|
||||
drawbar(Monitor *m)
|
||||
{
|
||||
+ if (usealtbar)
|
||||
+ return;
|
||||
+
|
||||
int x, w, tw = 0;
|
||||
int boxs = drw->fonts->h / 9;
|
||||
int boxw = drw->fonts->h / 6 + 2;
|
||||
@@ -1077,6 +1097,45 @@ manage(Window w, XWindowAttributes *wa)
|
||||
focus(NULL);
|
||||
}
|
||||
|
||||
+void
|
||||
+managealtbar(Window win, XWindowAttributes *wa)
|
||||
+{
|
||||
+ Monitor *m;
|
||||
+ if (!(m = recttomon(wa->x, wa->y, wa->width, wa->height)))
|
||||
+ return;
|
||||
+
|
||||
+ m->barwin = win;
|
||||
+ m->by = wa->y;
|
||||
+ bh = m->bh = wa->height;
|
||||
+ updatebarpos(m);
|
||||
+ arrange(m);
|
||||
+ XSelectInput(dpy, win, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
|
||||
+ XMoveResizeWindow(dpy, win, wa->x, wa->y, wa->width, wa->height);
|
||||
+ XMapWindow(dpy, win);
|
||||
+ XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
|
||||
+ (unsigned char *) &win, 1);
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+managetray(Window win, XWindowAttributes *wa)
|
||||
+{
|
||||
+ Monitor *m;
|
||||
+ if (!(m = recttomon(wa->x, wa->y, wa->width, wa->height)))
|
||||
+ return;
|
||||
+
|
||||
+ m->traywin = win;
|
||||
+ m->tx = wa->x;
|
||||
+ m->tw = wa->width;
|
||||
+ updatebarpos(m);
|
||||
+ arrange(m);
|
||||
+ XSelectInput(dpy, win, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
|
||||
+ XMoveResizeWindow(dpy, win, wa->x, wa->y, wa->width, wa->height);
|
||||
+ XMapWindow(dpy, win);
|
||||
+ XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
|
||||
+ (unsigned char *) &win, 1);
|
||||
+}
|
||||
+
|
||||
+
|
||||
void
|
||||
mappingnotify(XEvent *e)
|
||||
{
|
||||
@@ -1097,7 +1156,9 @@ maprequest(XEvent *e)
|
||||
return;
|
||||
if (wa.override_redirect)
|
||||
return;
|
||||
- if (!wintoclient(ev->window))
|
||||
+ if (wmclasscontains(ev->window, altbarclass, ""))
|
||||
+ managealtbar(ev->window, &wa);
|
||||
+ else if (!wintoclient(ev->window))
|
||||
manage(ev->window, &wa);
|
||||
}
|
||||
|
||||
@@ -1393,7 +1454,9 @@ scan(void)
|
||||
if (!XGetWindowAttributes(dpy, wins[i], &wa)
|
||||
|| wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
|
||||
continue;
|
||||
- if (wa.map_state == IsViewable || getstate(wins[i]) == IconicState)
|
||||
+ if (wmclasscontains(wins[i], altbarclass, ""))
|
||||
+ managealtbar(wins[i], &wa);
|
||||
+ else if (wa.map_state == IsViewable || getstate(wins[i]) == IconicState)
|
||||
manage(wins[i], &wa);
|
||||
}
|
||||
for (i = 0; i < num; i++) { /* now the transients */
|
||||
@@ -1408,6 +1471,29 @@ scan(void)
|
||||
}
|
||||
}
|
||||
|
||||
+void
|
||||
+scantray(void)
|
||||
+{
|
||||
+ unsigned int num;
|
||||
+ Window d1, d2, *wins = NULL;
|
||||
+ XWindowAttributes wa;
|
||||
+
|
||||
+ if (XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
|
||||
+ for (unsigned int i = 0; i < num; i++) {
|
||||
+ if (wmclasscontains(wins[i], altbarclass, alttrayname)) {
|
||||
+ if (!XGetWindowAttributes(dpy, wins[i], &wa))
|
||||
+ break;
|
||||
+ managetray(wins[i], &wa);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (wins)
|
||||
+ XFree(wins);
|
||||
+}
|
||||
+
|
||||
+
|
||||
+
|
||||
void
|
||||
sendmon(Client *c, Monitor *m)
|
||||
{
|
||||
@@ -1546,7 +1632,7 @@ setup(void)
|
||||
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
|
||||
die("no fonts could be loaded.");
|
||||
lrpad = drw->fonts->h;
|
||||
- bh = drw->fonts->h + 2;
|
||||
+ bh = usealtbar ? 0 : drw->fonts->h + 2;
|
||||
updategeom();
|
||||
/* init atoms */
|
||||
utf8string = XInternAtom(dpy, "UTF8_STRING", False);
|
||||
@@ -1595,6 +1681,7 @@ setup(void)
|
||||
XSelectInput(dpy, root, wa.event_mask);
|
||||
grabkeys();
|
||||
focus(NULL);
|
||||
+ spawnbar();
|
||||
}
|
||||
|
||||
|
||||
@@ -1653,6 +1740,13 @@ spawn(const Arg *arg)
|
||||
}
|
||||
}
|
||||
|
||||
+void
|
||||
+spawnbar()
|
||||
+{
|
||||
+ if (*altbarcmd)
|
||||
+ system(altbarcmd);
|
||||
+}
|
||||
+
|
||||
void
|
||||
tag(const Arg *arg)
|
||||
{
|
||||
@@ -1702,9 +1796,18 @@ tile(Monitor *m)
|
||||
void
|
||||
togglebar(const Arg *arg)
|
||||
{
|
||||
+ /**
|
||||
+ * Polybar tray does not raise maprequest event. It must be manually scanned
|
||||
+ * for. Scanning it too early while the tray is being populated would give
|
||||
+ * wrong dimensions.
|
||||
+ */
|
||||
+ if (!selmon->traywin)
|
||||
+ scantray();
|
||||
+
|
||||
selmon->showbar = !selmon->showbar;
|
||||
updatebarpos(selmon);
|
||||
- XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
|
||||
+ XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, selmon->bh);
|
||||
+ XMoveResizeWindow(dpy, selmon->traywin, selmon->tx, selmon->by, selmon->tw, selmon->bh);
|
||||
arrange(selmon);
|
||||
}
|
||||
|
||||
@@ -1787,10 +1890,41 @@ unmanage(Client *c, int destroyed)
|
||||
arrange(m);
|
||||
}
|
||||
|
||||
+void
|
||||
+unmanagealtbar(Window w)
|
||||
+{
|
||||
+ Monitor *m = wintomon(w);
|
||||
+
|
||||
+ if (!m)
|
||||
+ return;
|
||||
+
|
||||
+ m->barwin = 0;
|
||||
+ m->by = 0;
|
||||
+ m->bh = 0;
|
||||
+ updatebarpos(m);
|
||||
+ arrange(m);
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+unmanagetray(Window w)
|
||||
+{
|
||||
+ Monitor *m = wintomon(w);
|
||||
+
|
||||
+ if (!m)
|
||||
+ return;
|
||||
+
|
||||
+ m->traywin = 0;
|
||||
+ m->tx = 0;
|
||||
+ m->tw = 0;
|
||||
+ updatebarpos(m);
|
||||
+ arrange(m);
|
||||
+}
|
||||
+
|
||||
void
|
||||
unmapnotify(XEvent *e)
|
||||
{
|
||||
Client *c;
|
||||
+ Monitor *m;
|
||||
XUnmapEvent *ev = &e->xunmap;
|
||||
|
||||
if ((c = wintoclient(ev->window))) {
|
||||
@@ -1798,12 +1932,18 @@ unmapnotify(XEvent *e)
|
||||
setclientstate(c, WithdrawnState);
|
||||
else
|
||||
unmanage(c, 0);
|
||||
- }
|
||||
+ } else if ((m = wintomon(ev->window)) && m->barwin == ev->window)
|
||||
+ unmanagealtbar(ev->window);
|
||||
+ else if (m->traywin == ev->window)
|
||||
+ unmanagetray(ev->window);
|
||||
}
|
||||
|
||||
void
|
||||
updatebars(void)
|
||||
{
|
||||
+ if (usealtbar)
|
||||
+ return;
|
||||
+
|
||||
Monitor *m;
|
||||
XSetWindowAttributes wa = {
|
||||
.override_redirect = True,
|
||||
@@ -1829,11 +1969,11 @@ updatebarpos(Monitor *m)
|
||||
m->wy = m->my;
|
||||
m->wh = m->mh;
|
||||
if (m->showbar) {
|
||||
- m->wh -= bh;
|
||||
+ m->wh -= m->bh;
|
||||
m->by = m->topbar ? m->wy : m->wy + m->wh;
|
||||
- m->wy = m->topbar ? m->wy + bh : m->wy;
|
||||
+ m->wy = m->topbar ? m->wy + m->bh : m->wy;
|
||||
} else
|
||||
- m->by = -bh;
|
||||
+ m->by = -m->bh;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -2070,13 +2210,35 @@ wintomon(Window w)
|
||||
if (w == root && getrootptr(&x, &y))
|
||||
return recttomon(x, y, 1, 1);
|
||||
for (m = mons; m; m = m->next)
|
||||
- if (w == m->barwin)
|
||||
+ if (w == m->barwin || w == m->traywin)
|
||||
return m;
|
||||
if ((c = wintoclient(w)))
|
||||
return c->mon;
|
||||
return selmon;
|
||||
}
|
||||
|
||||
+int
|
||||
+wmclasscontains(Window win, const char *class, const char *name)
|
||||
+{
|
||||
+ XClassHint ch = { NULL, NULL };
|
||||
+ int res = 1;
|
||||
+
|
||||
+ if (XGetClassHint(dpy, win, &ch)) {
|
||||
+ if (ch.res_name && strstr(ch.res_name, name) == NULL)
|
||||
+ res = 0;
|
||||
+ if (ch.res_class && strstr(ch.res_class, class) == NULL)
|
||||
+ res = 0;
|
||||
+ } else
|
||||
+ res = 0;
|
||||
+
|
||||
+ if (ch.res_class)
|
||||
+ XFree(ch.res_class);
|
||||
+ if (ch.res_name)
|
||||
+ XFree(ch.res_name);
|
||||
+
|
||||
+ return res;
|
||||
+}
|
||||
+
|
||||
/* There's no way to check accesses to destroyed windows, thus those cases are
|
||||
* ignored (especially on UnmapNotify's). Other types of errors call Xlibs
|
||||
* default error handler, which may call exit. */
|
||||
--
|
||||
2.28.0
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
diff --git a/config.def.h b/config.def.h
|
||||
index 1c0b587..ed056a4 100644
|
||||
--- a/config.def.h
|
||||
+++ b/config.def.h
|
||||
@@ -18,6 +18,11 @@ static const char *colors[][3] = {
|
||||
[SchemeSel] = { col_gray4, col_cyan, col_cyan },
|
||||
};
|
||||
|
||||
+static const char *const autostart[] = {
|
||||
+ "st", NULL,
|
||||
+ NULL /* terminate */
|
||||
+};
|
||||
+
|
||||
/* tagging */
|
||||
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
||||
|
||||
diff --git a/dwm.c b/dwm.c
|
||||
index 9fd0286..1facd56 100644
|
||||
--- a/dwm.c
|
||||
+++ b/dwm.c
|
||||
@@ -234,6 +234,7 @@ static int xerror(Display *dpy, XErrorEvent *ee);
|
||||
static int xerrordummy(Display *dpy, XErrorEvent *ee);
|
||||
static int xerrorstart(Display *dpy, XErrorEvent *ee);
|
||||
static void zoom(const Arg *arg);
|
||||
+static void autostart_exec(void);
|
||||
|
||||
/* variables */
|
||||
static const char broken[] = "broken";
|
||||
@@ -275,6 +276,34 @@ static Window root, wmcheckwin;
|
||||
/* compile-time check if all tags fit into an unsigned int bit array. */
|
||||
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
|
||||
|
||||
+/* dwm will keep pid's of processes from autostart array and kill them at quit */
|
||||
+static pid_t *autostart_pids;
|
||||
+static size_t autostart_len;
|
||||
+
|
||||
+/* execute command from autostart array */
|
||||
+static void
|
||||
+autostart_exec() {
|
||||
+ const char *const *p;
|
||||
+ size_t i = 0;
|
||||
+
|
||||
+ /* count entries */
|
||||
+ for (p = autostart; *p; autostart_len++, p++)
|
||||
+ while (*++p);
|
||||
+
|
||||
+ autostart_pids = malloc(autostart_len * sizeof(pid_t));
|
||||
+ for (p = autostart; *p; i++, p++) {
|
||||
+ if ((autostart_pids[i] = fork()) == 0) {
|
||||
+ setsid();
|
||||
+ execvp(*p, (char *const *)p);
|
||||
+ fprintf(stderr, "dwm: execvp %s\n", *p);
|
||||
+ perror(" failed");
|
||||
+ _exit(EXIT_FAILURE);
|
||||
+ }
|
||||
+ /* skip arguments */
|
||||
+ while (*++p);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
/* function implementations */
|
||||
void
|
||||
applyrules(Client *c)
|
||||
@@ -1249,6 +1278,16 @@ propertynotify(XEvent *e)
|
||||
void
|
||||
quit(const Arg *arg)
|
||||
{
|
||||
+ size_t i;
|
||||
+
|
||||
+ /* kill child processes */
|
||||
+ for (i = 0; i < autostart_len; i++) {
|
||||
+ if (0 < autostart_pids[i]) {
|
||||
+ kill(autostart_pids[i], SIGTERM);
|
||||
+ waitpid(autostart_pids[i], NULL, 0);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
running = 0;
|
||||
}
|
||||
|
||||
@@ -1632,9 +1671,25 @@ showhide(Client *c)
|
||||
void
|
||||
sigchld(int unused)
|
||||
{
|
||||
+ pid_t pid;
|
||||
+
|
||||
if (signal(SIGCHLD, sigchld) == SIG_ERR)
|
||||
die("can't install SIGCHLD handler:");
|
||||
- while (0 < waitpid(-1, NULL, WNOHANG));
|
||||
+ while (0 < (pid = waitpid(-1, NULL, WNOHANG))) {
|
||||
+ pid_t *p, *lim;
|
||||
+
|
||||
+ if (!(p = autostart_pids))
|
||||
+ continue;
|
||||
+ lim = &p[autostart_len];
|
||||
+
|
||||
+ for (; p < lim; p++) {
|
||||
+ if (*p == pid) {
|
||||
+ *p = -1;
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ }
|
||||
}
|
||||
|
||||
void
|
||||
@@ -2139,6 +2194,7 @@ main(int argc, char *argv[])
|
||||
if (!(dpy = XOpenDisplay(NULL)))
|
||||
die("dwm: cannot open display");
|
||||
checkotherwm();
|
||||
+ autostart_exec();
|
||||
setup();
|
||||
#ifdef __OpenBSD__
|
||||
if (pledge("stdio rpath proc exec", NULL) == -1)
|
||||
|
|
@ -0,0 +1,971 @@
|
|||
From 9709d08daa290c8c7319571cd9e6ef4ec40e7683 Mon Sep 17 00:00:00 2001
|
||||
From: bakkeby <bakkeby@gmail.com>
|
||||
Date: Wed, 6 May 2020 17:21:25 +0200
|
||||
Subject: [PATCH] vanitygaps - adds gaps to layouts
|
||||
|
||||
This patch differentiates between inner and outer gaps as well as
|
||||
horizontal and vertical gaps.
|
||||
|
||||
The logic of these layouts also aims to be pixel perfect by ensuring
|
||||
an even split of the available space and re-distributing the remainder
|
||||
among the available clients.
|
||||
---
|
||||
config.def.h | 38 ++-
|
||||
dwm.c | 35 +--
|
||||
vanitygaps.c | 809 +++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
3 files changed, 854 insertions(+), 28 deletions(-)
|
||||
create mode 100644 vanitygaps.c
|
||||
|
||||
diff --git a/config.def.h b/config.def.h
|
||||
index 1c0b587..a886863 100644
|
||||
--- a/config.def.h
|
||||
+++ b/config.def.h
|
||||
@@ -3,6 +3,11 @@
|
||||
/* appearance */
|
||||
static const unsigned int borderpx = 1; /* border pixel of windows */
|
||||
static const unsigned int snap = 32; /* snap pixel */
|
||||
+static const unsigned int gappih = 20; /* horiz inner gap between windows */
|
||||
+static const unsigned int gappiv = 10; /* vert inner gap between windows */
|
||||
+static const unsigned int gappoh = 10; /* horiz outer gap between windows and screen edge */
|
||||
+static const unsigned int gappov = 30; /* vert outer gap between windows and screen edge */
|
||||
+static int smartgaps = 0; /* 1 means no outer gap when there is only one window */
|
||||
static const int showbar = 1; /* 0 means no bar */
|
||||
static const int topbar = 1; /* 0 means bottom bar */
|
||||
static const char *fonts[] = { "monospace:size=10" };
|
||||
@@ -36,11 +41,26 @@ static const float mfact = 0.55; /* factor of master area size [0.05..0.95]
|
||||
static const int nmaster = 1; /* number of clients in master area */
|
||||
static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
|
||||
|
||||
+#define FORCE_VSPLIT 1 /* nrowgrid layout: force two clients to always split vertically */
|
||||
+#include "vanitygaps.c"
|
||||
+
|
||||
static const Layout layouts[] = {
|
||||
/* symbol arrange function */
|
||||
{ "[]=", tile }, /* first entry is default */
|
||||
- { "><>", NULL }, /* no layout function means floating behavior */
|
||||
{ "[M]", monocle },
|
||||
+ { "[@]", spiral },
|
||||
+ { "[\\]", dwindle },
|
||||
+ { "H[]", deck },
|
||||
+ { "TTT", bstack },
|
||||
+ { "===", bstackhoriz },
|
||||
+ { "HHH", grid },
|
||||
+ { "###", nrowgrid },
|
||||
+ { "---", horizgrid },
|
||||
+ { ":::", gaplessgrid },
|
||||
+ { "|M|", centeredmaster },
|
||||
+ { ">M>", centeredfloatingmaster },
|
||||
+ { "><>", NULL }, /* no layout function means floating behavior */
|
||||
+ { NULL, NULL },
|
||||
};
|
||||
|
||||
/* key definitions */
|
||||
@@ -71,6 +91,22 @@ static Key keys[] = {
|
||||
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
|
||||
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
|
||||
{ MODKEY, XK_Return, zoom, {0} },
|
||||
+ { MODKEY|Mod4Mask, XK_u, incrgaps, {.i = +1 } },
|
||||
+ { MODKEY|Mod4Mask|ShiftMask, XK_u, incrgaps, {.i = -1 } },
|
||||
+ { MODKEY|Mod4Mask, XK_i, incrigaps, {.i = +1 } },
|
||||
+ { MODKEY|Mod4Mask|ShiftMask, XK_i, incrigaps, {.i = -1 } },
|
||||
+ { MODKEY|Mod4Mask, XK_o, incrogaps, {.i = +1 } },
|
||||
+ { MODKEY|Mod4Mask|ShiftMask, XK_o, incrogaps, {.i = -1 } },
|
||||
+ { MODKEY|Mod4Mask, XK_6, incrihgaps, {.i = +1 } },
|
||||
+ { MODKEY|Mod4Mask|ShiftMask, XK_6, incrihgaps, {.i = -1 } },
|
||||
+ { MODKEY|Mod4Mask, XK_7, incrivgaps, {.i = +1 } },
|
||||
+ { MODKEY|Mod4Mask|ShiftMask, XK_7, incrivgaps, {.i = -1 } },
|
||||
+ { MODKEY|Mod4Mask, XK_8, incrohgaps, {.i = +1 } },
|
||||
+ { MODKEY|Mod4Mask|ShiftMask, XK_8, incrohgaps, {.i = -1 } },
|
||||
+ { MODKEY|Mod4Mask, XK_9, incrovgaps, {.i = +1 } },
|
||||
+ { MODKEY|Mod4Mask|ShiftMask, XK_9, incrovgaps, {.i = -1 } },
|
||||
+ { MODKEY|Mod4Mask, XK_0, togglegaps, {0} },
|
||||
+ { MODKEY|Mod4Mask|ShiftMask, XK_0, defaultgaps, {0} },
|
||||
{ MODKEY, XK_Tab, view, {0} },
|
||||
{ MODKEY|ShiftMask, XK_c, killclient, {0} },
|
||||
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
|
||||
diff --git a/dwm.c b/dwm.c
|
||||
index 4465af1..c3b2d82 100644
|
||||
--- a/dwm.c
|
||||
+++ b/dwm.c
|
||||
@@ -119,6 +119,10 @@ struct Monitor {
|
||||
int by; /* bar geometry */
|
||||
int mx, my, mw, mh; /* screen size */
|
||||
int wx, wy, ww, wh; /* window area */
|
||||
+ int gappih; /* horizontal gap between windows */
|
||||
+ int gappiv; /* vertical gap between windows */
|
||||
+ int gappoh; /* horizontal outer gaps */
|
||||
+ int gappov; /* vertical outer gaps */
|
||||
unsigned int seltags;
|
||||
unsigned int sellt;
|
||||
unsigned int tagset[2];
|
||||
@@ -208,7 +212,6 @@ static void sigchld(int unused);
|
||||
static void spawn(const Arg *arg);
|
||||
static void tag(const Arg *arg);
|
||||
static void tagmon(const Arg *arg);
|
||||
-static void tile(Monitor *);
|
||||
static void togglebar(const Arg *arg);
|
||||
static void togglefloating(const Arg *arg);
|
||||
static void toggletag(const Arg *arg);
|
||||
@@ -638,6 +641,10 @@ createmon(void)
|
||||
m->nmaster = nmaster;
|
||||
m->showbar = showbar;
|
||||
m->topbar = topbar;
|
||||
+ m->gappih = gappih;
|
||||
+ m->gappiv = gappiv;
|
||||
+ m->gappoh = gappoh;
|
||||
+ m->gappov = gappov;
|
||||
m->lt[0] = &layouts[0];
|
||||
m->lt[1] = &layouts[1 % LENGTH(layouts)];
|
||||
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
|
||||
@@ -1670,32 +1677,6 @@ tagmon(const Arg *arg)
|
||||
sendmon(selmon->sel, dirtomon(arg->i));
|
||||
}
|
||||
|
||||
-void
|
||||
-tile(Monitor *m)
|
||||
-{
|
||||
- unsigned int i, n, h, mw, my, ty;
|
||||
- Client *c;
|
||||
-
|
||||
- for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
|
||||
- if (n == 0)
|
||||
- return;
|
||||
-
|
||||
- if (n > m->nmaster)
|
||||
- mw = m->nmaster ? m->ww * m->mfact : 0;
|
||||
- else
|
||||
- mw = m->ww;
|
||||
- for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
|
||||
- if (i < m->nmaster) {
|
||||
- h = (m->wh - my) / (MIN(n, m->nmaster) - i);
|
||||
- resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0);
|
||||
- my += HEIGHT(c);
|
||||
- } else {
|
||||
- h = (m->wh - ty) / (n - i);
|
||||
- resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0);
|
||||
- ty += HEIGHT(c);
|
||||
- }
|
||||
-}
|
||||
-
|
||||
void
|
||||
togglebar(const Arg *arg)
|
||||
{
|
||||
diff --git a/vanitygaps.c b/vanitygaps.c
|
||||
new file mode 100644
|
||||
index 0000000..3f31593
|
||||
--- /dev/null
|
||||
+++ b/vanitygaps.c
|
||||
@@ -0,0 +1,809 @@
|
||||
+/* Key binding functions */
|
||||
+static void defaultgaps(const Arg *arg);
|
||||
+static void incrgaps(const Arg *arg);
|
||||
+static void incrigaps(const Arg *arg);
|
||||
+static void incrogaps(const Arg *arg);
|
||||
+static void incrohgaps(const Arg *arg);
|
||||
+static void incrovgaps(const Arg *arg);
|
||||
+static void incrihgaps(const Arg *arg);
|
||||
+static void incrivgaps(const Arg *arg);
|
||||
+static void togglegaps(const Arg *arg);
|
||||
+/* Layouts (delete the ones you do not need) */
|
||||
+static void bstack(Monitor *m);
|
||||
+static void bstackhoriz(Monitor *m);
|
||||
+static void centeredmaster(Monitor *m);
|
||||
+static void centeredfloatingmaster(Monitor *m);
|
||||
+static void deck(Monitor *m);
|
||||
+static void dwindle(Monitor *m);
|
||||
+static void fibonacci(Monitor *m, int s);
|
||||
+static void grid(Monitor *m);
|
||||
+static void nrowgrid(Monitor *m);
|
||||
+static void spiral(Monitor *m);
|
||||
+static void tile(Monitor *m);
|
||||
+/* Internals */
|
||||
+static void getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc);
|
||||
+static void getfacts(Monitor *m, int msize, int ssize, float *mf, float *sf, int *mr, int *sr);
|
||||
+static void setgaps(int oh, int ov, int ih, int iv);
|
||||
+
|
||||
+/* Settings */
|
||||
+#if !PERTAG_PATCH
|
||||
+static int enablegaps = 1;
|
||||
+#endif // PERTAG_PATCH
|
||||
+
|
||||
+void
|
||||
+setgaps(int oh, int ov, int ih, int iv)
|
||||
+{
|
||||
+ if (oh < 0) oh = 0;
|
||||
+ if (ov < 0) ov = 0;
|
||||
+ if (ih < 0) ih = 0;
|
||||
+ if (iv < 0) iv = 0;
|
||||
+
|
||||
+ selmon->gappoh = oh;
|
||||
+ selmon->gappov = ov;
|
||||
+ selmon->gappih = ih;
|
||||
+ selmon->gappiv = iv;
|
||||
+ arrange(selmon);
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+togglegaps(const Arg *arg)
|
||||
+{
|
||||
+ #if PERTAG_PATCH
|
||||
+ selmon->pertag->enablegaps[selmon->pertag->curtag] = !selmon->pertag->enablegaps[selmon->pertag->curtag];
|
||||
+ #else
|
||||
+ enablegaps = !enablegaps;
|
||||
+ #endif // PERTAG_PATCH
|
||||
+ arrange(NULL);
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+defaultgaps(const Arg *arg)
|
||||
+{
|
||||
+ setgaps(gappoh, gappov, gappih, gappiv);
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+incrgaps(const Arg *arg)
|
||||
+{
|
||||
+ setgaps(
|
||||
+ selmon->gappoh + arg->i,
|
||||
+ selmon->gappov + arg->i,
|
||||
+ selmon->gappih + arg->i,
|
||||
+ selmon->gappiv + arg->i
|
||||
+ );
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+incrigaps(const Arg *arg)
|
||||
+{
|
||||
+ setgaps(
|
||||
+ selmon->gappoh,
|
||||
+ selmon->gappov,
|
||||
+ selmon->gappih + arg->i,
|
||||
+ selmon->gappiv + arg->i
|
||||
+ );
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+incrogaps(const Arg *arg)
|
||||
+{
|
||||
+ setgaps(
|
||||
+ selmon->gappoh + arg->i,
|
||||
+ selmon->gappov + arg->i,
|
||||
+ selmon->gappih,
|
||||
+ selmon->gappiv
|
||||
+ );
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+incrohgaps(const Arg *arg)
|
||||
+{
|
||||
+ setgaps(
|
||||
+ selmon->gappoh + arg->i,
|
||||
+ selmon->gappov,
|
||||
+ selmon->gappih,
|
||||
+ selmon->gappiv
|
||||
+ );
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+incrovgaps(const Arg *arg)
|
||||
+{
|
||||
+ setgaps(
|
||||
+ selmon->gappoh,
|
||||
+ selmon->gappov + arg->i,
|
||||
+ selmon->gappih,
|
||||
+ selmon->gappiv
|
||||
+ );
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+incrihgaps(const Arg *arg)
|
||||
+{
|
||||
+ setgaps(
|
||||
+ selmon->gappoh,
|
||||
+ selmon->gappov,
|
||||
+ selmon->gappih + arg->i,
|
||||
+ selmon->gappiv
|
||||
+ );
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+incrivgaps(const Arg *arg)
|
||||
+{
|
||||
+ setgaps(
|
||||
+ selmon->gappoh,
|
||||
+ selmon->gappov,
|
||||
+ selmon->gappih,
|
||||
+ selmon->gappiv + arg->i
|
||||
+ );
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc)
|
||||
+{
|
||||
+ unsigned int n, oe, ie;
|
||||
+ #if PERTAG_PATCH
|
||||
+ oe = ie = selmon->pertag->enablegaps[selmon->pertag->curtag];
|
||||
+ #else
|
||||
+ oe = ie = enablegaps;
|
||||
+ #endif // PERTAG_PATCH
|
||||
+ Client *c;
|
||||
+
|
||||
+ for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
|
||||
+ if (smartgaps && n == 1) {
|
||||
+ oe = 0; // outer gaps disabled when only one client
|
||||
+ }
|
||||
+
|
||||
+ *oh = m->gappoh*oe; // outer horizontal gap
|
||||
+ *ov = m->gappov*oe; // outer vertical gap
|
||||
+ *ih = m->gappih*ie; // inner horizontal gap
|
||||
+ *iv = m->gappiv*ie; // inner vertical gap
|
||||
+ *nc = n; // number of clients
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+getfacts(Monitor *m, int msize, int ssize, float *mf, float *sf, int *mr, int *sr)
|
||||
+{
|
||||
+ unsigned int n;
|
||||
+ float mfacts, sfacts;
|
||||
+ int mtotal = 0, stotal = 0;
|
||||
+ Client *c;
|
||||
+
|
||||
+ for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
|
||||
+ mfacts = MIN(n, m->nmaster);
|
||||
+ sfacts = n - m->nmaster;
|
||||
+
|
||||
+ for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++)
|
||||
+ if (n < m->nmaster)
|
||||
+ mtotal += msize / mfacts;
|
||||
+ else
|
||||
+ stotal += ssize / sfacts;
|
||||
+
|
||||
+ *mf = mfacts; // total factor of master area
|
||||
+ *sf = sfacts; // total factor of stack area
|
||||
+ *mr = msize - mtotal; // the remainder (rest) of pixels after an even master split
|
||||
+ *sr = ssize - stotal; // the remainder (rest) of pixels after an even stack split
|
||||
+}
|
||||
+
|
||||
+/***
|
||||
+ * Layouts
|
||||
+ */
|
||||
+
|
||||
+/*
|
||||
+ * Bottomstack layout + gaps
|
||||
+ * https://dwm.suckless.org/patches/bottomstack/
|
||||
+ */
|
||||
+static void
|
||||
+bstack(Monitor *m)
|
||||
+{
|
||||
+ unsigned int i, n;
|
||||
+ int oh, ov, ih, iv;
|
||||
+ int mx = 0, my = 0, mh = 0, mw = 0;
|
||||
+ int sx = 0, sy = 0, sh = 0, sw = 0;
|
||||
+ float mfacts, sfacts;
|
||||
+ int mrest, srest;
|
||||
+ Client *c;
|
||||
+
|
||||
+ getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
+ if (n == 0)
|
||||
+ return;
|
||||
+
|
||||
+ sx = mx = m->wx + ov;
|
||||
+ sy = my = m->wy + oh;
|
||||
+ sh = mh = m->wh - 2*oh;
|
||||
+ mw = m->ww - 2*ov - iv * (MIN(n, m->nmaster) - 1);
|
||||
+ sw = m->ww - 2*ov - iv * (n - m->nmaster - 1);
|
||||
+
|
||||
+ if (m->nmaster && n > m->nmaster) {
|
||||
+ sh = (mh - ih) * (1 - m->mfact);
|
||||
+ mh = mh - ih - sh;
|
||||
+ sx = mx;
|
||||
+ sy = my + mh + ih;
|
||||
+ }
|
||||
+
|
||||
+ getfacts(m, mw, sw, &mfacts, &sfacts, &mrest, &srest);
|
||||
+
|
||||
+ for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
|
||||
+ if (i < m->nmaster) {
|
||||
+ resize(c, mx, my, (mw / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), mh - (2*c->bw), 0);
|
||||
+ mx += WIDTH(c) + iv;
|
||||
+ } else {
|
||||
+ resize(c, sx, sy, (sw / sfacts) + ((i - m->nmaster) < srest ? 1 : 0) - (2*c->bw), sh - (2*c->bw), 0);
|
||||
+ sx += WIDTH(c) + iv;
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static void
|
||||
+bstackhoriz(Monitor *m)
|
||||
+{
|
||||
+ unsigned int i, n;
|
||||
+ int oh, ov, ih, iv;
|
||||
+ int mx = 0, my = 0, mh = 0, mw = 0;
|
||||
+ int sx = 0, sy = 0, sh = 0, sw = 0;
|
||||
+ float mfacts, sfacts;
|
||||
+ int mrest, srest;
|
||||
+ Client *c;
|
||||
+
|
||||
+ getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
+ if (n == 0)
|
||||
+ return;
|
||||
+
|
||||
+ sx = mx = m->wx + ov;
|
||||
+ sy = my = m->wy + oh;
|
||||
+ mh = m->wh - 2*oh;
|
||||
+ sh = m->wh - 2*oh - ih * (n - m->nmaster - 1);
|
||||
+ mw = m->ww - 2*ov - iv * (MIN(n, m->nmaster) - 1);
|
||||
+ sw = m->ww - 2*ov;
|
||||
+
|
||||
+ if (m->nmaster && n > m->nmaster) {
|
||||
+ sh = (mh - ih) * (1 - m->mfact);
|
||||
+ mh = mh - ih - sh;
|
||||
+ sy = my + mh + ih;
|
||||
+ sh = m->wh - mh - 2*oh - ih * (n - m->nmaster);
|
||||
+ }
|
||||
+
|
||||
+ getfacts(m, mw, sh, &mfacts, &sfacts, &mrest, &srest);
|
||||
+
|
||||
+ for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
|
||||
+ if (i < m->nmaster) {
|
||||
+ resize(c, mx, my, (mw / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), mh - (2*c->bw), 0);
|
||||
+ mx += WIDTH(c) + iv;
|
||||
+ } else {
|
||||
+ resize(c, sx, sy, sw - (2*c->bw), (sh / sfacts) + ((i - m->nmaster) < srest ? 1 : 0) - (2*c->bw), 0);
|
||||
+ sy += HEIGHT(c) + ih;
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * Centred master layout + gaps
|
||||
+ * https://dwm.suckless.org/patches/centeredmaster/
|
||||
+ */
|
||||
+void
|
||||
+centeredmaster(Monitor *m)
|
||||
+{
|
||||
+ unsigned int i, n;
|
||||
+ int oh, ov, ih, iv;
|
||||
+ int mx = 0, my = 0, mh = 0, mw = 0;
|
||||
+ int lx = 0, ly = 0, lw = 0, lh = 0;
|
||||
+ int rx = 0, ry = 0, rw = 0, rh = 0;
|
||||
+ float mfacts = 0, lfacts = 0, rfacts = 0;
|
||||
+ int mtotal = 0, ltotal = 0, rtotal = 0;
|
||||
+ int mrest = 0, lrest = 0, rrest = 0;
|
||||
+ Client *c;
|
||||
+
|
||||
+ getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
+ if (n == 0)
|
||||
+ return;
|
||||
+
|
||||
+ /* initialize areas */
|
||||
+ mx = m->wx + ov;
|
||||
+ my = m->wy + oh;
|
||||
+ mh = m->wh - 2*oh - ih * ((!m->nmaster ? n : MIN(n, m->nmaster)) - 1);
|
||||
+ mw = m->ww - 2*ov;
|
||||
+ lh = m->wh - 2*oh - ih * (((n - m->nmaster) / 2) - 1);
|
||||
+ rh = m->wh - 2*oh - ih * (((n - m->nmaster) / 2) - ((n - m->nmaster) % 2 ? 0 : 1));
|
||||
+
|
||||
+ if (m->nmaster && n > m->nmaster) {
|
||||
+ /* go mfact box in the center if more than nmaster clients */
|
||||
+ if (n - m->nmaster > 1) {
|
||||
+ /* ||<-S->|<---M--->|<-S->|| */
|
||||
+ mw = (m->ww - 2*ov - 2*iv) * m->mfact;
|
||||
+ lw = (m->ww - mw - 2*ov - 2*iv) / 2;
|
||||
+ rw = (m->ww - mw - 2*ov - 2*iv) - lw;
|
||||
+ mx += lw + iv;
|
||||
+ } else {
|
||||
+ /* ||<---M--->|<-S->|| */
|
||||
+ mw = (mw - iv) * m->mfact;
|
||||
+ lw = 0;
|
||||
+ rw = m->ww - mw - iv - 2*ov;
|
||||
+ }
|
||||
+ lx = m->wx + ov;
|
||||
+ ly = m->wy + oh;
|
||||
+ rx = mx + mw + iv;
|
||||
+ ry = m->wy + oh;
|
||||
+ }
|
||||
+
|
||||
+ /* calculate facts */
|
||||
+ for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) {
|
||||
+ if (!m->nmaster || n < m->nmaster)
|
||||
+ mfacts += 1;
|
||||
+ else if ((n - m->nmaster) % 2)
|
||||
+ lfacts += 1; // total factor of left hand stack area
|
||||
+ else
|
||||
+ rfacts += 1; // total factor of right hand stack area
|
||||
+ }
|
||||
+
|
||||
+ for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++)
|
||||
+ if (!m->nmaster || n < m->nmaster)
|
||||
+ mtotal += mh / mfacts;
|
||||
+ else if ((n - m->nmaster) % 2)
|
||||
+ ltotal += lh / lfacts;
|
||||
+ else
|
||||
+ rtotal += rh / rfacts;
|
||||
+
|
||||
+ mrest = mh - mtotal;
|
||||
+ lrest = lh - ltotal;
|
||||
+ rrest = rh - rtotal;
|
||||
+
|
||||
+ for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
|
||||
+ if (!m->nmaster || i < m->nmaster) {
|
||||
+ /* nmaster clients are stacked vertically, in the center of the screen */
|
||||
+ resize(c, mx, my, mw - (2*c->bw), (mh / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
|
||||
+ my += HEIGHT(c) + ih;
|
||||
+ } else {
|
||||
+ /* stack clients are stacked vertically */
|
||||
+ if ((i - m->nmaster) % 2 ) {
|
||||
+ resize(c, lx, ly, lw - (2*c->bw), (lh / lfacts) + ((i - 2*m->nmaster) < 2*lrest ? 1 : 0) - (2*c->bw), 0);
|
||||
+ ly += HEIGHT(c) + ih;
|
||||
+ } else {
|
||||
+ resize(c, rx, ry, rw - (2*c->bw), (rh / rfacts) + ((i - 2*m->nmaster) < 2*rrest ? 1 : 0) - (2*c->bw), 0);
|
||||
+ ry += HEIGHT(c) + ih;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+centeredfloatingmaster(Monitor *m)
|
||||
+{
|
||||
+ unsigned int i, n;
|
||||
+ float mfacts, sfacts;
|
||||
+ float mivf = 1.0; // master inner vertical gap factor
|
||||
+ int oh, ov, ih, iv, mrest, srest;
|
||||
+ int mx = 0, my = 0, mh = 0, mw = 0;
|
||||
+ int sx = 0, sy = 0, sh = 0, sw = 0;
|
||||
+ Client *c;
|
||||
+
|
||||
+ getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
+ if (n == 0)
|
||||
+ return;
|
||||
+
|
||||
+ sx = mx = m->wx + ov;
|
||||
+ sy = my = m->wy + oh;
|
||||
+ sh = mh = m->wh - 2*oh;
|
||||
+ mw = m->ww - 2*ov - iv*(n - 1);
|
||||
+ sw = m->ww - 2*ov - iv*(n - m->nmaster - 1);
|
||||
+
|
||||
+ if (m->nmaster && n > m->nmaster) {
|
||||
+ mivf = 0.8;
|
||||
+ /* go mfact box in the center if more than nmaster clients */
|
||||
+ if (m->ww > m->wh) {
|
||||
+ mw = m->ww * m->mfact - iv*mivf*(MIN(n, m->nmaster) - 1);
|
||||
+ mh = m->wh * 0.9;
|
||||
+ } else {
|
||||
+ mw = m->ww * 0.9 - iv*mivf*(MIN(n, m->nmaster) - 1);
|
||||
+ mh = m->wh * m->mfact;
|
||||
+ }
|
||||
+ mx = m->wx + (m->ww - mw) / 2;
|
||||
+ my = m->wy + (m->wh - mh - 2*oh) / 2;
|
||||
+
|
||||
+ sx = m->wx + ov;
|
||||
+ sy = m->wy + oh;
|
||||
+ sh = m->wh - 2*oh;
|
||||
+ }
|
||||
+
|
||||
+ getfacts(m, mw, sw, &mfacts, &sfacts, &mrest, &srest);
|
||||
+
|
||||
+ for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
|
||||
+ if (i < m->nmaster) {
|
||||
+ /* nmaster clients are stacked horizontally, in the center of the screen */
|
||||
+ resize(c, mx, my, (mw / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), mh - (2*c->bw), 0);
|
||||
+ mx += WIDTH(c) + iv*mivf;
|
||||
+ } else {
|
||||
+ /* stack clients are stacked horizontally */
|
||||
+ resize(c, sx, sy, (sw / sfacts) + ((i - m->nmaster) < srest ? 1 : 0) - (2*c->bw), sh - (2*c->bw), 0);
|
||||
+ sx += WIDTH(c) + iv;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * Deck layout + gaps
|
||||
+ * https://dwm.suckless.org/patches/deck/
|
||||
+ */
|
||||
+void
|
||||
+deck(Monitor *m)
|
||||
+{
|
||||
+ unsigned int i, n;
|
||||
+ int oh, ov, ih, iv;
|
||||
+ int mx = 0, my = 0, mh = 0, mw = 0;
|
||||
+ int sx = 0, sy = 0, sh = 0, sw = 0;
|
||||
+ float mfacts, sfacts;
|
||||
+ int mrest, srest;
|
||||
+ Client *c;
|
||||
+
|
||||
+ getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
+ if (n == 0)
|
||||
+ return;
|
||||
+
|
||||
+ sx = mx = m->wx + ov;
|
||||
+ sy = my = m->wy + oh;
|
||||
+ sh = mh = m->wh - 2*oh - ih * (MIN(n, m->nmaster) - 1);
|
||||
+ sw = mw = m->ww - 2*ov;
|
||||
+
|
||||
+ if (m->nmaster && n > m->nmaster) {
|
||||
+ sw = (mw - iv) * (1 - m->mfact);
|
||||
+ mw = mw - iv - sw;
|
||||
+ sx = mx + mw + iv;
|
||||
+ sh = m->wh - 2*oh;
|
||||
+ }
|
||||
+
|
||||
+ getfacts(m, mh, sh, &mfacts, &sfacts, &mrest, &srest);
|
||||
+
|
||||
+ if (n - m->nmaster > 0) /* override layout symbol */
|
||||
+ snprintf(m->ltsymbol, sizeof m->ltsymbol, "D %d", n - m->nmaster);
|
||||
+
|
||||
+ for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
|
||||
+ if (i < m->nmaster) {
|
||||
+ resize(c, mx, my, mw - (2*c->bw), (mh / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
|
||||
+ my += HEIGHT(c) + ih;
|
||||
+ } else {
|
||||
+ resize(c, sx, sy, sw - (2*c->bw), sh - (2*c->bw), 0);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * Fibonacci layout + gaps
|
||||
+ * https://dwm.suckless.org/patches/fibonacci/
|
||||
+ */
|
||||
+void
|
||||
+fibonacci(Monitor *m, int s)
|
||||
+{
|
||||
+ unsigned int i, n;
|
||||
+ int nx, ny, nw, nh;
|
||||
+ int oh, ov, ih, iv;
|
||||
+ int nv, hrest = 0, wrest = 0, r = 1;
|
||||
+ Client *c;
|
||||
+
|
||||
+ getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
+ if (n == 0)
|
||||
+ return;
|
||||
+
|
||||
+ nx = m->wx + ov;
|
||||
+ ny = m->wy + oh;
|
||||
+ nw = m->ww - 2*ov;
|
||||
+ nh = m->wh - 2*oh;
|
||||
+
|
||||
+ for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
|
||||
+ if (r) {
|
||||
+ if ((i % 2 && (nh - ih) / 2 <= (bh + 2*c->bw))
|
||||
+ || (!(i % 2) && (nw - iv) / 2 <= (bh + 2*c->bw))) {
|
||||
+ r = 0;
|
||||
+ }
|
||||
+ if (r && i < n - 1) {
|
||||
+ if (i % 2) {
|
||||
+ nv = (nh - ih) / 2;
|
||||
+ hrest = nh - 2*nv - ih;
|
||||
+ nh = nv;
|
||||
+ } else {
|
||||
+ nv = (nw - iv) / 2;
|
||||
+ wrest = nw - 2*nv - iv;
|
||||
+ nw = nv;
|
||||
+ }
|
||||
+
|
||||
+ if ((i % 4) == 2 && !s)
|
||||
+ nx += nw + iv;
|
||||
+ else if ((i % 4) == 3 && !s)
|
||||
+ ny += nh + ih;
|
||||
+ }
|
||||
+
|
||||
+ if ((i % 4) == 0) {
|
||||
+ if (s) {
|
||||
+ ny += nh + ih;
|
||||
+ nh += hrest;
|
||||
+ }
|
||||
+ else {
|
||||
+ nh -= hrest;
|
||||
+ ny -= nh + ih;
|
||||
+ }
|
||||
+ }
|
||||
+ else if ((i % 4) == 1) {
|
||||
+ nx += nw + iv;
|
||||
+ nw += wrest;
|
||||
+ }
|
||||
+ else if ((i % 4) == 2) {
|
||||
+ ny += nh + ih;
|
||||
+ nh += hrest;
|
||||
+ if (i < n - 1)
|
||||
+ nw += wrest;
|
||||
+ }
|
||||
+ else if ((i % 4) == 3) {
|
||||
+ if (s) {
|
||||
+ nx += nw + iv;
|
||||
+ nw -= wrest;
|
||||
+ } else {
|
||||
+ nw -= wrest;
|
||||
+ nx -= nw + iv;
|
||||
+ nh += hrest;
|
||||
+ }
|
||||
+ }
|
||||
+ if (i == 0) {
|
||||
+ if (n != 1) {
|
||||
+ nw = (m->ww - iv - 2*ov) - (m->ww - iv - 2*ov) * (1 - m->mfact);
|
||||
+ wrest = 0;
|
||||
+ }
|
||||
+ ny = m->wy + oh;
|
||||
+ }
|
||||
+ else if (i == 1)
|
||||
+ nw = m->ww - nw - iv - 2*ov;
|
||||
+ i++;
|
||||
+ }
|
||||
+
|
||||
+ resize(c, nx, ny, nw - (2*c->bw), nh - (2*c->bw), False);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+dwindle(Monitor *m)
|
||||
+{
|
||||
+ fibonacci(m, 1);
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+spiral(Monitor *m)
|
||||
+{
|
||||
+ fibonacci(m, 0);
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * Gappless grid layout + gaps (ironically)
|
||||
+ * https://dwm.suckless.org/patches/gaplessgrid/
|
||||
+ */
|
||||
+void
|
||||
+gaplessgrid(Monitor *m)
|
||||
+{
|
||||
+ unsigned int i, n;
|
||||
+ int x, y, cols, rows, ch, cw, cn, rn, rrest, crest; // counters
|
||||
+ int oh, ov, ih, iv;
|
||||
+ Client *c;
|
||||
+
|
||||
+ getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
+ if (n == 0)
|
||||
+ return;
|
||||
+
|
||||
+ /* grid dimensions */
|
||||
+ for (cols = 0; cols <= n/2; cols++)
|
||||
+ if (cols*cols >= n)
|
||||
+ break;
|
||||
+ if (n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
|
||||
+ cols = 2;
|
||||
+ rows = n/cols;
|
||||
+ cn = rn = 0; // reset column no, row no, client count
|
||||
+
|
||||
+ ch = (m->wh - 2*oh - ih * (rows - 1)) / rows;
|
||||
+ cw = (m->ww - 2*ov - iv * (cols - 1)) / cols;
|
||||
+ rrest = (m->wh - 2*oh - ih * (rows - 1)) - ch * rows;
|
||||
+ crest = (m->ww - 2*ov - iv * (cols - 1)) - cw * cols;
|
||||
+ x = m->wx + ov;
|
||||
+ y = m->wy + oh;
|
||||
+
|
||||
+ for (i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
|
||||
+ if (i/rows + 1 > cols - n%cols) {
|
||||
+ rows = n/cols + 1;
|
||||
+ ch = (m->wh - 2*oh - ih * (rows - 1)) / rows;
|
||||
+ rrest = (m->wh - 2*oh - ih * (rows - 1)) - ch * rows;
|
||||
+ }
|
||||
+ resize(c,
|
||||
+ x,
|
||||
+ y + rn*(ch + ih) + MIN(rn, rrest),
|
||||
+ cw + (cn < crest ? 1 : 0) - 2*c->bw,
|
||||
+ ch + (rn < rrest ? 1 : 0) - 2*c->bw,
|
||||
+ 0);
|
||||
+ rn++;
|
||||
+ if (rn >= rows) {
|
||||
+ rn = 0;
|
||||
+ x += cw + ih + (cn < crest ? 1 : 0);
|
||||
+ cn++;
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * Gridmode layout + gaps
|
||||
+ * https://dwm.suckless.org/patches/gridmode/
|
||||
+ */
|
||||
+void
|
||||
+grid(Monitor *m)
|
||||
+{
|
||||
+ unsigned int i, n;
|
||||
+ int cx, cy, cw, ch, cc, cr, chrest, cwrest, cols, rows;
|
||||
+ int oh, ov, ih, iv;
|
||||
+ Client *c;
|
||||
+
|
||||
+ getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
+
|
||||
+ /* grid dimensions */
|
||||
+ for (rows = 0; rows <= n/2; rows++)
|
||||
+ if (rows*rows >= n)
|
||||
+ break;
|
||||
+ cols = (rows && (rows - 1) * rows >= n) ? rows - 1 : rows;
|
||||
+
|
||||
+ /* window geoms (cell height/width) */
|
||||
+ ch = (m->wh - 2*oh - ih * (rows - 1)) / (rows ? rows : 1);
|
||||
+ cw = (m->ww - 2*ov - iv * (cols - 1)) / (cols ? cols : 1);
|
||||
+ chrest = (m->wh - 2*oh - ih * (rows - 1)) - ch * rows;
|
||||
+ cwrest = (m->ww - 2*ov - iv * (cols - 1)) - cw * cols;
|
||||
+ for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
|
||||
+ cc = i / rows;
|
||||
+ cr = i % rows;
|
||||
+ cx = m->wx + ov + cc * (cw + iv) + MIN(cc, cwrest);
|
||||
+ cy = m->wy + oh + cr * (ch + ih) + MIN(cr, chrest);
|
||||
+ resize(c, cx, cy, cw + (cc < cwrest ? 1 : 0) - 2*c->bw, ch + (cr < chrest ? 1 : 0) - 2*c->bw, False);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * Horizontal grid layout + gaps
|
||||
+ * https://dwm.suckless.org/patches/horizgrid/
|
||||
+ */
|
||||
+void
|
||||
+horizgrid(Monitor *m) {
|
||||
+ Client *c;
|
||||
+ unsigned int n, i;
|
||||
+ int oh, ov, ih, iv;
|
||||
+ int mx = 0, my = 0, mh = 0, mw = 0;
|
||||
+ int sx = 0, sy = 0, sh = 0, sw = 0;
|
||||
+ int ntop, nbottom = 1;
|
||||
+ float mfacts, sfacts;
|
||||
+ int mrest, srest;
|
||||
+
|
||||
+ /* Count windows */
|
||||
+ getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
+ if (n == 0)
|
||||
+ return;
|
||||
+
|
||||
+ if (n <= 2)
|
||||
+ ntop = n;
|
||||
+ else {
|
||||
+ ntop = n / 2;
|
||||
+ nbottom = n - ntop;
|
||||
+ }
|
||||
+ sx = mx = m->wx + ov;
|
||||
+ sy = my = m->wy + oh;
|
||||
+ sh = mh = m->wh - 2*oh;
|
||||
+ sw = mw = m->ww - 2*ov;
|
||||
+
|
||||
+ if (n > ntop) {
|
||||
+ sh = (mh - ih) / 2;
|
||||
+ mh = mh - ih - sh;
|
||||
+ sy = my + mh + ih;
|
||||
+ mw = m->ww - 2*ov - iv * (ntop - 1);
|
||||
+ sw = m->ww - 2*ov - iv * (nbottom - 1);
|
||||
+ }
|
||||
+
|
||||
+ mfacts = ntop;
|
||||
+ sfacts = nbottom;
|
||||
+ mrest = mw - (mw / ntop) * ntop;
|
||||
+ srest = sw - (sw / nbottom) * nbottom;
|
||||
+
|
||||
+ for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
|
||||
+ if (i < ntop) {
|
||||
+ resize(c, mx, my, (mw / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), mh - (2*c->bw), 0);
|
||||
+ mx += WIDTH(c) + iv;
|
||||
+ } else {
|
||||
+ resize(c, sx, sy, (sw / sfacts) + ((i - ntop) < srest ? 1 : 0) - (2*c->bw), sh - (2*c->bw), 0);
|
||||
+ sx += WIDTH(c) + iv;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * nrowgrid layout + gaps
|
||||
+ * https://dwm.suckless.org/patches/nrowgrid/
|
||||
+ */
|
||||
+void
|
||||
+nrowgrid(Monitor *m)
|
||||
+{
|
||||
+ unsigned int n;
|
||||
+ int ri = 0, ci = 0; /* counters */
|
||||
+ int oh, ov, ih, iv; /* vanitygap settings */
|
||||
+ unsigned int cx, cy, cw, ch; /* client geometry */
|
||||
+ unsigned int uw = 0, uh = 0, uc = 0; /* utilization trackers */
|
||||
+ unsigned int cols, rows = m->nmaster + 1;
|
||||
+ Client *c;
|
||||
+
|
||||
+ /* count clients */
|
||||
+ getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
+
|
||||
+ /* nothing to do here */
|
||||
+ if (n == 0)
|
||||
+ return;
|
||||
+
|
||||
+ /* force 2 clients to always split vertically */
|
||||
+ if (FORCE_VSPLIT && n == 2)
|
||||
+ rows = 1;
|
||||
+
|
||||
+ /* never allow empty rows */
|
||||
+ if (n < rows)
|
||||
+ rows = n;
|
||||
+
|
||||
+ /* define first row */
|
||||
+ cols = n / rows;
|
||||
+ uc = cols;
|
||||
+ cy = m->wy + oh;
|
||||
+ ch = (m->wh - 2*oh - ih*(rows - 1)) / rows;
|
||||
+ uh = ch;
|
||||
+
|
||||
+ for (c = nexttiled(m->clients); c; c = nexttiled(c->next), ci++) {
|
||||
+ if (ci == cols) {
|
||||
+ uw = 0;
|
||||
+ ci = 0;
|
||||
+ ri++;
|
||||
+
|
||||
+ /* next row */
|
||||
+ cols = (n - uc) / (rows - ri);
|
||||
+ uc += cols;
|
||||
+ cy = m->wy + oh + uh + ih;
|
||||
+ uh += ch + ih;
|
||||
+ }
|
||||
+
|
||||
+ cx = m->wx + ov + uw;
|
||||
+ cw = (m->ww - 2*ov - uw) / (cols - ci);
|
||||
+ uw += cw + iv;
|
||||
+
|
||||
+ resize(c, cx, cy, cw - (2*c->bw), ch - (2*c->bw), 0);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * Default tile layout + gaps
|
||||
+ */
|
||||
+static void
|
||||
+tile(Monitor *m)
|
||||
+{
|
||||
+ unsigned int i, n;
|
||||
+ int oh, ov, ih, iv;
|
||||
+ int mx = 0, my = 0, mh = 0, mw = 0;
|
||||
+ int sx = 0, sy = 0, sh = 0, sw = 0;
|
||||
+ float mfacts, sfacts;
|
||||
+ int mrest, srest;
|
||||
+ Client *c;
|
||||
+
|
||||
+ getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
+ if (n == 0)
|
||||
+ return;
|
||||
+
|
||||
+ sx = mx = m->wx + ov;
|
||||
+ sy = my = m->wy + oh;
|
||||
+ mh = m->wh - 2*oh - ih * (MIN(n, m->nmaster) - 1);
|
||||
+ sh = m->wh - 2*oh - ih * (n - m->nmaster - 1);
|
||||
+ sw = mw = m->ww - 2*ov;
|
||||
+
|
||||
+ if (m->nmaster && n > m->nmaster) {
|
||||
+ sw = (mw - iv) * (1 - m->mfact);
|
||||
+ mw = mw - iv - sw;
|
||||
+ sx = mx + mw + iv;
|
||||
+ }
|
||||
+
|
||||
+ getfacts(m, mh, sh, &mfacts, &sfacts, &mrest, &srest);
|
||||
+
|
||||
+ for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
|
||||
+ if (i < m->nmaster) {
|
||||
+ resize(c, mx, my, mw - (2*c->bw), (mh / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
|
||||
+ my += HEIGHT(c) + ih;
|
||||
+ } else {
|
||||
+ resize(c, sx, sy, sw - (2*c->bw), (sh / sfacts) + ((i - m->nmaster) < srest ? 1 : 0) - (2*c->bw), 0);
|
||||
+ sy += HEIGHT(c) + ih;
|
||||
+ }
|
||||
+}
|
||||
\ No newline at end of file
|
||||
--
|
||||
2.19.1
|
||||
|
|
@ -0,0 +1,176 @@
|
|||
.TH DWM 1 dwm\-VERSION
|
||||
.SH NAME
|
||||
dwm \- dynamic window manager
|
||||
.SH SYNOPSIS
|
||||
.B dwm
|
||||
.RB [ \-v ]
|
||||
.SH DESCRIPTION
|
||||
dwm is a dynamic window manager for X. It manages windows in tiled, monocle
|
||||
and floating layouts. Either layout can be applied dynamically, optimising the
|
||||
environment for the application in use and the task performed.
|
||||
.P
|
||||
In tiled layouts windows are managed in a master and stacking area. The master
|
||||
area on the left contains one window by default, and the stacking area on the
|
||||
right contains all other windows. The number of master area windows can be
|
||||
adjusted from zero to an arbitrary number. In monocle layout all windows are
|
||||
maximised to the screen size. In floating layout windows can be resized and
|
||||
moved freely. Dialog windows are always managed floating, regardless of the
|
||||
layout applied.
|
||||
.P
|
||||
Windows are grouped by tags. Each window can be tagged with one or multiple
|
||||
tags. Selecting certain tags displays all windows with these tags.
|
||||
.P
|
||||
Each screen contains a small status bar which displays all available tags, the
|
||||
layout, the title of the focused window, and the text read from the root window
|
||||
name property, if the screen is focused. A floating window is indicated with an
|
||||
empty square and a maximised floating window is indicated with a filled square
|
||||
before the windows title. The selected tags are indicated with a different
|
||||
color. The tags of the focused window are indicated with a filled square in the
|
||||
top left corner. The tags which are applied to one or more windows are
|
||||
indicated with an empty square in the top left corner.
|
||||
.P
|
||||
dwm draws a small border around windows to indicate the focus state.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B \-v
|
||||
prints version information to stderr, then exits.
|
||||
.SH USAGE
|
||||
.SS Status bar
|
||||
.TP
|
||||
.B X root window name
|
||||
is read and displayed in the status text area. It can be set with the
|
||||
.BR xsetroot (1)
|
||||
command.
|
||||
.TP
|
||||
.B Button1
|
||||
click on a tag label to display all windows with that tag, click on the layout
|
||||
label toggles between tiled and floating layout.
|
||||
.TP
|
||||
.B Button3
|
||||
click on a tag label adds/removes all windows with that tag to/from the view.
|
||||
.TP
|
||||
.B Mod1\-Button1
|
||||
click on a tag label applies that tag to the focused window.
|
||||
.TP
|
||||
.B Mod1\-Button3
|
||||
click on a tag label adds/removes that tag to/from the focused window.
|
||||
.SS Keyboard commands
|
||||
.TP
|
||||
.B Mod1\-Shift\-Return
|
||||
Start
|
||||
.BR st(1).
|
||||
.TP
|
||||
.B Mod1\-p
|
||||
Spawn
|
||||
.BR dmenu(1)
|
||||
for launching other programs.
|
||||
.TP
|
||||
.B Mod1\-,
|
||||
Focus previous screen, if any.
|
||||
.TP
|
||||
.B Mod1\-.
|
||||
Focus next screen, if any.
|
||||
.TP
|
||||
.B Mod1\-Shift\-,
|
||||
Send focused window to previous screen, if any.
|
||||
.TP
|
||||
.B Mod1\-Shift\-.
|
||||
Send focused window to next screen, if any.
|
||||
.TP
|
||||
.B Mod1\-b
|
||||
Toggles bar on and off.
|
||||
.TP
|
||||
.B Mod1\-t
|
||||
Sets tiled layout.
|
||||
.TP
|
||||
.B Mod1\-f
|
||||
Sets floating layout.
|
||||
.TP
|
||||
.B Mod1\-m
|
||||
Sets monocle layout.
|
||||
.TP
|
||||
.B Mod1\-space
|
||||
Toggles between current and previous layout.
|
||||
.TP
|
||||
.B Mod1\-j
|
||||
Focus next window.
|
||||
.TP
|
||||
.B Mod1\-k
|
||||
Focus previous window.
|
||||
.TP
|
||||
.B Mod1\-i
|
||||
Increase number of windows in master area.
|
||||
.TP
|
||||
.B Mod1\-d
|
||||
Decrease number of windows in master area.
|
||||
.TP
|
||||
.B Mod1\-l
|
||||
Increase master area size.
|
||||
.TP
|
||||
.B Mod1\-h
|
||||
Decrease master area size.
|
||||
.TP
|
||||
.B Mod1\-Return
|
||||
Zooms/cycles focused window to/from master area (tiled layouts only).
|
||||
.TP
|
||||
.B Mod1\-Shift\-c
|
||||
Close focused window.
|
||||
.TP
|
||||
.B Mod1\-Shift\-space
|
||||
Toggle focused window between tiled and floating state.
|
||||
.TP
|
||||
.B Mod1\-Tab
|
||||
Toggles to the previously selected tags.
|
||||
.TP
|
||||
.B Mod1\-Shift\-[1..n]
|
||||
Apply nth tag to focused window.
|
||||
.TP
|
||||
.B Mod1\-Shift\-0
|
||||
Apply all tags to focused window.
|
||||
.TP
|
||||
.B Mod1\-Control\-Shift\-[1..n]
|
||||
Add/remove nth tag to/from focused window.
|
||||
.TP
|
||||
.B Mod1\-[1..n]
|
||||
View all windows with nth tag.
|
||||
.TP
|
||||
.B Mod1\-0
|
||||
View all windows with any tag.
|
||||
.TP
|
||||
.B Mod1\-Control\-[1..n]
|
||||
Add/remove all windows with nth tag to/from the view.
|
||||
.TP
|
||||
.B Mod1\-Shift\-q
|
||||
Quit dwm.
|
||||
.SS Mouse commands
|
||||
.TP
|
||||
.B Mod1\-Button1
|
||||
Move focused window while dragging. Tiled windows will be toggled to the floating state.
|
||||
.TP
|
||||
.B Mod1\-Button2
|
||||
Toggles focused window between floating and tiled state.
|
||||
.TP
|
||||
.B Mod1\-Button3
|
||||
Resize focused window while dragging. Tiled windows will be toggled to the floating state.
|
||||
.SH CUSTOMIZATION
|
||||
dwm is customized by creating a custom config.h and (re)compiling the source
|
||||
code. This keeps it fast, secure and simple.
|
||||
.SH SEE ALSO
|
||||
.BR dmenu (1),
|
||||
.BR st (1)
|
||||
.SH ISSUES
|
||||
Java applications which use the XToolkit/XAWT backend may draw grey windows
|
||||
only. The XToolkit/XAWT backend breaks ICCCM-compliance in recent JDK 1.5 and early
|
||||
JDK 1.6 versions, because it assumes a reparenting window manager. Possible workarounds
|
||||
are using JDK 1.4 (which doesn't contain the XToolkit/XAWT backend) or setting the
|
||||
environment variable
|
||||
.BR AWT_TOOLKIT=MToolkit
|
||||
(to use the older Motif backend instead) or running
|
||||
.B xprop -root -f _NET_WM_NAME 32a -set _NET_WM_NAME LG3D
|
||||
or
|
||||
.B wmname LG3D
|
||||
(to pretend that a non-reparenting window manager is running that the
|
||||
XToolkit/XAWT backend can recognize) or when using OpenJDK setting the environment variable
|
||||
.BR _JAVA_AWT_WM_NONREPARENTING=1 .
|
||||
.SH BUGS
|
||||
Send all bug reports with a patch to hackers@suckless.org.
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,392 @@
|
|||
--- dwm.c
|
||||
+++ dwm.c
|
||||
@@ -47,8 +47,8 @@
|
||||
/* macros */
|
||||
#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
|
||||
#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
|
||||
-#define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
|
||||
- * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
|
||||
+#define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->mx+(m)->mw) - MAX((x),(m)->mx)) \
|
||||
+ * MAX(0, MIN((y)+(h),(m)->my+(m)->mh) - MAX((y),(m)->my)))
|
||||
#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
|
||||
#define LENGTH(X) (sizeof X / sizeof X[0])
|
||||
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
|
||||
@@ -116,7 +116,8 @@ struct Monitor {
|
||||
float mfact;
|
||||
int nmaster;
|
||||
int num;
|
||||
- int by; /* bar geometry */
|
||||
+ int by, bh; /* bar geometry */
|
||||
+ int tx, tw; /* bar tray geometry */
|
||||
int mx, my, mw, mh; /* screen size */
|
||||
int wx, wy, ww, wh; /* window area */
|
||||
unsigned int seltags;
|
||||
@@ -129,6 +130,7 @@ struct Monitor {
|
||||
Client *stack;
|
||||
Monitor *next;
|
||||
Window barwin;
|
||||
+ Window traywin;
|
||||
const Layout *lt[2];
|
||||
};
|
||||
|
||||
@@ -179,6 +181,8 @@ static void incnmaster(const Arg *arg);
|
||||
static void keypress(XEvent *e);
|
||||
static void killclient(const Arg *arg);
|
||||
static void manage(Window w, XWindowAttributes *wa);
|
||||
+static void managealtbar(Window win, XWindowAttributes *wa);
|
||||
+static void managetray(Window win, XWindowAttributes *wa);
|
||||
static void mappingnotify(XEvent *e);
|
||||
static void maprequest(XEvent *e);
|
||||
static void monocle(Monitor *m);
|
||||
@@ -195,6 +199,7 @@ static void resizemouse(const Arg *arg);
|
||||
static void restack(Monitor *m);
|
||||
static void run(void);
|
||||
static void scan(void);
|
||||
+static void scantray(void);
|
||||
static int sendevent(Client *c, Atom proto);
|
||||
static void sendmon(Client *c, Monitor *m);
|
||||
static void setclientstate(Client *c, long state);
|
||||
@@ -207,6 +212,7 @@ static void seturgent(Client *c, int urg);
|
||||
static void showhide(Client *c);
|
||||
static void sigchld(int unused);
|
||||
static void spawn(const Arg *arg);
|
||||
+static void spawnbar();
|
||||
static void tag(const Arg *arg);
|
||||
static void tagmon(const Arg *arg);
|
||||
static void tile(Monitor *);
|
||||
@@ -216,6 +222,8 @@ static void toggletag(const Arg *arg);
|
||||
static void toggleview(const Arg *arg);
|
||||
static void unfocus(Client *c, int setfocus);
|
||||
static void unmanage(Client *c, int destroyed);
|
||||
+static void unmanagealtbar(Window w);
|
||||
+static void unmanagetray(Window w);
|
||||
static void unmapnotify(XEvent *e);
|
||||
static void updatebarpos(Monitor *m);
|
||||
static void updatebars(void);
|
||||
@@ -230,6 +238,7 @@ static void updatewmhints(Client *c);
|
||||
static void view(const Arg *arg);
|
||||
static Client *wintoclient(Window w);
|
||||
static Monitor *wintomon(Window w);
|
||||
+static int wmclasscontains(Window win, const char *class, const char *name);
|
||||
static int xerror(Display *dpy, XErrorEvent *ee);
|
||||
static int xerrordummy(Display *dpy, XErrorEvent *ee);
|
||||
static int xerrorstart(Display *dpy, XErrorEvent *ee);
|
||||
@@ -505,8 +514,10 @@ cleanupmon(Monitor *mon)
|
||||
for (m = mons; m && m->next != mon; m = m->next);
|
||||
m->next = mon->next;
|
||||
}
|
||||
- XUnmapWindow(dpy, mon->barwin);
|
||||
- XDestroyWindow(dpy, mon->barwin);
|
||||
+ if (!usealtbar) {
|
||||
+ XUnmapWindow(dpy, mon->barwin);
|
||||
+ XDestroyWindow(dpy, mon->barwin);
|
||||
+ }
|
||||
free(mon);
|
||||
}
|
||||
|
||||
@@ -568,7 +579,7 @@ configurenotify(XEvent *e)
|
||||
for (c = m->clients; c; c = c->next)
|
||||
if (c->isfullscreen)
|
||||
resizeclient(c, m->mx, m->my, m->mw, m->mh);
|
||||
- XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
|
||||
+ XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, m->bh);
|
||||
}
|
||||
focus(NULL);
|
||||
arrange(NULL);
|
||||
@@ -639,6 +650,7 @@ createmon(void)
|
||||
m->nmaster = nmaster;
|
||||
m->showbar = showbar;
|
||||
m->topbar = topbar;
|
||||
+ m->bh = bh;
|
||||
m->lt[0] = &layouts[0];
|
||||
m->lt[1] = &layouts[1 % LENGTH(layouts)];
|
||||
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
|
||||
@@ -649,10 +661,15 @@ void
|
||||
destroynotify(XEvent *e)
|
||||
{
|
||||
Client *c;
|
||||
+ Monitor *m;
|
||||
XDestroyWindowEvent *ev = &e->xdestroywindow;
|
||||
|
||||
if ((c = wintoclient(ev->window)))
|
||||
unmanage(c, 1);
|
||||
+ else if ((m = wintomon(ev->window)) && m->barwin == ev->window)
|
||||
+ unmanagealtbar(ev->window);
|
||||
+ else if (m->traywin == ev->window)
|
||||
+ unmanagetray(ev->window);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -696,6 +713,9 @@ dirtomon(int dir)
|
||||
void
|
||||
drawbar(Monitor *m)
|
||||
{
|
||||
+ if (usealtbar)
|
||||
+ return;
|
||||
+
|
||||
int x, w, tw = 0;
|
||||
int boxs = drw->fonts->h / 9;
|
||||
int boxw = drw->fonts->h / 6 + 2;
|
||||
@@ -1077,6 +1097,45 @@ manage(Window w, XWindowAttributes *wa)
|
||||
focus(NULL);
|
||||
}
|
||||
|
||||
+void
|
||||
+managealtbar(Window win, XWindowAttributes *wa)
|
||||
+{
|
||||
+ Monitor *m;
|
||||
+ if (!(m = recttomon(wa->x, wa->y, wa->width, wa->height)))
|
||||
+ return;
|
||||
+
|
||||
+ m->barwin = win;
|
||||
+ m->by = wa->y;
|
||||
+ bh = m->bh = wa->height;
|
||||
+ updatebarpos(m);
|
||||
+ arrange(m);
|
||||
+ XSelectInput(dpy, win, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
|
||||
+ XMoveResizeWindow(dpy, win, wa->x, wa->y, wa->width, wa->height);
|
||||
+ XMapWindow(dpy, win);
|
||||
+ XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
|
||||
+ (unsigned char *) &win, 1);
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+managetray(Window win, XWindowAttributes *wa)
|
||||
+{
|
||||
+ Monitor *m;
|
||||
+ if (!(m = recttomon(wa->x, wa->y, wa->width, wa->height)))
|
||||
+ return;
|
||||
+
|
||||
+ m->traywin = win;
|
||||
+ m->tx = wa->x;
|
||||
+ m->tw = wa->width;
|
||||
+ updatebarpos(m);
|
||||
+ arrange(m);
|
||||
+ XSelectInput(dpy, win, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
|
||||
+ XMoveResizeWindow(dpy, win, wa->x, wa->y, wa->width, wa->height);
|
||||
+ XMapWindow(dpy, win);
|
||||
+ XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
|
||||
+ (unsigned char *) &win, 1);
|
||||
+}
|
||||
+
|
||||
+
|
||||
void
|
||||
mappingnotify(XEvent *e)
|
||||
{
|
||||
@@ -1097,7 +1156,9 @@ maprequest(XEvent *e)
|
||||
return;
|
||||
if (wa.override_redirect)
|
||||
return;
|
||||
- if (!wintoclient(ev->window))
|
||||
+ if (wmclasscontains(ev->window, altbarclass, ""))
|
||||
+ managealtbar(ev->window, &wa);
|
||||
+ else if (!wintoclient(ev->window))
|
||||
manage(ev->window, &wa);
|
||||
}
|
||||
|
||||
@@ -1393,7 +1454,9 @@ scan(void)
|
||||
if (!XGetWindowAttributes(dpy, wins[i], &wa)
|
||||
|| wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
|
||||
continue;
|
||||
- if (wa.map_state == IsViewable || getstate(wins[i]) == IconicState)
|
||||
+ if (wmclasscontains(wins[i], altbarclass, ""))
|
||||
+ managealtbar(wins[i], &wa);
|
||||
+ else if (wa.map_state == IsViewable || getstate(wins[i]) == IconicState)
|
||||
manage(wins[i], &wa);
|
||||
}
|
||||
for (i = 0; i < num; i++) { /* now the transients */
|
||||
@@ -1408,6 +1471,29 @@ scan(void)
|
||||
}
|
||||
}
|
||||
|
||||
+void
|
||||
+scantray(void)
|
||||
+{
|
||||
+ unsigned int num;
|
||||
+ Window d1, d2, *wins = NULL;
|
||||
+ XWindowAttributes wa;
|
||||
+
|
||||
+ if (XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
|
||||
+ for (unsigned int i = 0; i < num; i++) {
|
||||
+ if (wmclasscontains(wins[i], altbarclass, alttrayname)) {
|
||||
+ if (!XGetWindowAttributes(dpy, wins[i], &wa))
|
||||
+ break;
|
||||
+ managetray(wins[i], &wa);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (wins)
|
||||
+ XFree(wins);
|
||||
+}
|
||||
+
|
||||
+
|
||||
+
|
||||
void
|
||||
sendmon(Client *c, Monitor *m)
|
||||
{
|
||||
@@ -1546,7 +1632,7 @@ setup(void)
|
||||
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
|
||||
die("no fonts could be loaded.");
|
||||
lrpad = drw->fonts->h;
|
||||
- bh = drw->fonts->h + 2;
|
||||
+ bh = usealtbar ? 0 : drw->fonts->h + 2;
|
||||
updategeom();
|
||||
/* init atoms */
|
||||
utf8string = XInternAtom(dpy, "UTF8_STRING", False);
|
||||
@@ -1595,6 +1681,7 @@ setup(void)
|
||||
XSelectInput(dpy, root, wa.event_mask);
|
||||
grabkeys();
|
||||
focus(NULL);
|
||||
+ spawnbar();
|
||||
}
|
||||
|
||||
|
||||
@@ -1653,6 +1740,13 @@ spawn(const Arg *arg)
|
||||
}
|
||||
}
|
||||
|
||||
+void
|
||||
+spawnbar()
|
||||
+{
|
||||
+ if (*altbarcmd)
|
||||
+ system(altbarcmd);
|
||||
+}
|
||||
+
|
||||
void
|
||||
tag(const Arg *arg)
|
||||
{
|
||||
@@ -1702,9 +1796,18 @@ tile(Monitor *m)
|
||||
void
|
||||
togglebar(const Arg *arg)
|
||||
{
|
||||
+ /**
|
||||
+ * Polybar tray does not raise maprequest event. It must be manually scanned
|
||||
+ * for. Scanning it too early while the tray is being populated would give
|
||||
+ * wrong dimensions.
|
||||
+ */
|
||||
+ if (!selmon->traywin)
|
||||
+ scantray();
|
||||
+
|
||||
selmon->showbar = !selmon->showbar;
|
||||
updatebarpos(selmon);
|
||||
- XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
|
||||
+ XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, selmon->bh);
|
||||
+ XMoveResizeWindow(dpy, selmon->traywin, selmon->tx, selmon->by, selmon->tw, selmon->bh);
|
||||
arrange(selmon);
|
||||
}
|
||||
|
||||
@@ -1787,10 +1890,41 @@ unmanage(Client *c, int destroyed)
|
||||
arrange(m);
|
||||
}
|
||||
|
||||
+void
|
||||
+unmanagealtbar(Window w)
|
||||
+{
|
||||
+ Monitor *m = wintomon(w);
|
||||
+
|
||||
+ if (!m)
|
||||
+ return;
|
||||
+
|
||||
+ m->barwin = 0;
|
||||
+ m->by = 0;
|
||||
+ m->bh = 0;
|
||||
+ updatebarpos(m);
|
||||
+ arrange(m);
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+unmanagetray(Window w)
|
||||
+{
|
||||
+ Monitor *m = wintomon(w);
|
||||
+
|
||||
+ if (!m)
|
||||
+ return;
|
||||
+
|
||||
+ m->traywin = 0;
|
||||
+ m->tx = 0;
|
||||
+ m->tw = 0;
|
||||
+ updatebarpos(m);
|
||||
+ arrange(m);
|
||||
+}
|
||||
+
|
||||
void
|
||||
unmapnotify(XEvent *e)
|
||||
{
|
||||
Client *c;
|
||||
+ Monitor *m;
|
||||
XUnmapEvent *ev = &e->xunmap;
|
||||
|
||||
if ((c = wintoclient(ev->window))) {
|
||||
@@ -1798,12 +1932,18 @@ unmapnotify(XEvent *e)
|
||||
setclientstate(c, WithdrawnState);
|
||||
else
|
||||
unmanage(c, 0);
|
||||
- }
|
||||
+ } else if ((m = wintomon(ev->window)) && m->barwin == ev->window)
|
||||
+ unmanagealtbar(ev->window);
|
||||
+ else if (m->traywin == ev->window)
|
||||
+ unmanagetray(ev->window);
|
||||
}
|
||||
|
||||
void
|
||||
updatebars(void)
|
||||
{
|
||||
+ if (usealtbar)
|
||||
+ return;
|
||||
+
|
||||
Monitor *m;
|
||||
XSetWindowAttributes wa = {
|
||||
.override_redirect = True,
|
||||
@@ -1829,11 +1969,11 @@ updatebarpos(Monitor *m)
|
||||
m->wy = m->my;
|
||||
m->wh = m->mh;
|
||||
if (m->showbar) {
|
||||
- m->wh -= bh;
|
||||
+ m->wh -= m->bh;
|
||||
m->by = m->topbar ? m->wy : m->wy + m->wh;
|
||||
- m->wy = m->topbar ? m->wy + bh : m->wy;
|
||||
+ m->wy = m->topbar ? m->wy + m->bh : m->wy;
|
||||
} else
|
||||
- m->by = -bh;
|
||||
+ m->by = -m->bh;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -2070,13 +2210,35 @@ wintomon(Window w)
|
||||
if (w == root && getrootptr(&x, &y))
|
||||
return recttomon(x, y, 1, 1);
|
||||
for (m = mons; m; m = m->next)
|
||||
- if (w == m->barwin)
|
||||
+ if (w == m->barwin || w == m->traywin)
|
||||
return m;
|
||||
if ((c = wintoclient(w)))
|
||||
return c->mon;
|
||||
return selmon;
|
||||
}
|
||||
|
||||
+int
|
||||
+wmclasscontains(Window win, const char *class, const char *name)
|
||||
+{
|
||||
+ XClassHint ch = { NULL, NULL };
|
||||
+ int res = 1;
|
||||
+
|
||||
+ if (XGetClassHint(dpy, win, &ch)) {
|
||||
+ if (ch.res_name && strstr(ch.res_name, name) == NULL)
|
||||
+ res = 0;
|
||||
+ if (ch.res_class && strstr(ch.res_class, class) == NULL)
|
||||
+ res = 0;
|
||||
+ } else
|
||||
+ res = 0;
|
||||
+
|
||||
+ if (ch.res_class)
|
||||
+ XFree(ch.res_class);
|
||||
+ if (ch.res_name)
|
||||
+ XFree(ch.res_name);
|
||||
+
|
||||
+ return res;
|
||||
+}
|
||||
+
|
||||
/* There's no way to check accesses to destroyed windows, thus those cases are
|
||||
* ignored (especially on UnmapNotify's). Other types of errors call Xlibs
|
||||
* default error handler, which may call exit. */
|
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 373 B |
|
@ -0,0 +1,42 @@
|
|||
/* cc transient.c -o transient -lX11 */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
int main(void) {
|
||||
Display *d;
|
||||
Window r, f, t = None;
|
||||
XSizeHints h;
|
||||
XEvent e;
|
||||
|
||||
d = XOpenDisplay(NULL);
|
||||
if (!d)
|
||||
exit(1);
|
||||
r = DefaultRootWindow(d);
|
||||
|
||||
f = XCreateSimpleWindow(d, r, 100, 100, 400, 400, 0, 0, 0);
|
||||
h.min_width = h.max_width = h.min_height = h.max_height = 400;
|
||||
h.flags = PMinSize | PMaxSize;
|
||||
XSetWMNormalHints(d, f, &h);
|
||||
XStoreName(d, f, "floating");
|
||||
XMapWindow(d, f);
|
||||
|
||||
XSelectInput(d, f, ExposureMask);
|
||||
while (1) {
|
||||
XNextEvent(d, &e);
|
||||
|
||||
if (t == None) {
|
||||
sleep(5);
|
||||
t = XCreateSimpleWindow(d, r, 50, 50, 100, 100, 0, 0, 0);
|
||||
XSetTransientForHint(d, t, f);
|
||||
XStoreName(d, t, "transient");
|
||||
XMapWindow(d, t);
|
||||
XSelectInput(d, t, ExposureMask);
|
||||
}
|
||||
}
|
||||
|
||||
XCloseDisplay(d);
|
||||
exit(0);
|
||||
}
|
|
@ -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);
|
Binary file not shown.
|
@ -0,0 +1,809 @@
|
|||
/* Key binding functions */
|
||||
static void defaultgaps(const Arg *arg);
|
||||
static void incrgaps(const Arg *arg);
|
||||
static void incrigaps(const Arg *arg);
|
||||
static void incrogaps(const Arg *arg);
|
||||
static void incrohgaps(const Arg *arg);
|
||||
static void incrovgaps(const Arg *arg);
|
||||
static void incrihgaps(const Arg *arg);
|
||||
static void incrivgaps(const Arg *arg);
|
||||
static void togglegaps(const Arg *arg);
|
||||
/* Layouts (delete the ones you do not need) */
|
||||
static void bstack(Monitor *m);
|
||||
static void bstackhoriz(Monitor *m);
|
||||
static void centeredmaster(Monitor *m);
|
||||
static void centeredfloatingmaster(Monitor *m);
|
||||
static void deck(Monitor *m);
|
||||
static void dwindle(Monitor *m);
|
||||
static void fibonacci(Monitor *m, int s);
|
||||
static void grid(Monitor *m);
|
||||
static void nrowgrid(Monitor *m);
|
||||
static void spiral(Monitor *m);
|
||||
static void tile(Monitor *m);
|
||||
/* Internals */
|
||||
static void getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc);
|
||||
static void getfacts(Monitor *m, int msize, int ssize, float *mf, float *sf, int *mr, int *sr);
|
||||
static void setgaps(int oh, int ov, int ih, int iv);
|
||||
|
||||
/* Settings */
|
||||
#if !PERTAG_PATCH
|
||||
static int enablegaps = 1;
|
||||
#endif // PERTAG_PATCH
|
||||
|
||||
void
|
||||
setgaps(int oh, int ov, int ih, int iv)
|
||||
{
|
||||
if (oh < 0) oh = 0;
|
||||
if (ov < 0) ov = 0;
|
||||
if (ih < 0) ih = 0;
|
||||
if (iv < 0) iv = 0;
|
||||
|
||||
selmon->gappoh = oh;
|
||||
selmon->gappov = ov;
|
||||
selmon->gappih = ih;
|
||||
selmon->gappiv = iv;
|
||||
arrange(selmon);
|
||||
}
|
||||
|
||||
void
|
||||
togglegaps(const Arg *arg)
|
||||
{
|
||||
#if PERTAG_PATCH
|
||||
selmon->pertag->enablegaps[selmon->pertag->curtag] = !selmon->pertag->enablegaps[selmon->pertag->curtag];
|
||||
#else
|
||||
enablegaps = !enablegaps;
|
||||
#endif // PERTAG_PATCH
|
||||
arrange(NULL);
|
||||
}
|
||||
|
||||
void
|
||||
defaultgaps(const Arg *arg)
|
||||
{
|
||||
setgaps(gappoh, gappov, gappih, gappiv);
|
||||
}
|
||||
|
||||
void
|
||||
incrgaps(const Arg *arg)
|
||||
{
|
||||
setgaps(
|
||||
selmon->gappoh + arg->i,
|
||||
selmon->gappov + arg->i,
|
||||
selmon->gappih + arg->i,
|
||||
selmon->gappiv + arg->i
|
||||
);
|
||||
}
|
||||
|
||||
void
|
||||
incrigaps(const Arg *arg)
|
||||
{
|
||||
setgaps(
|
||||
selmon->gappoh,
|
||||
selmon->gappov,
|
||||
selmon->gappih + arg->i,
|
||||
selmon->gappiv + arg->i
|
||||
);
|
||||
}
|
||||
|
||||
void
|
||||
incrogaps(const Arg *arg)
|
||||
{
|
||||
setgaps(
|
||||
selmon->gappoh + arg->i,
|
||||
selmon->gappov + arg->i,
|
||||
selmon->gappih,
|
||||
selmon->gappiv
|
||||
);
|
||||
}
|
||||
|
||||
void
|
||||
incrohgaps(const Arg *arg)
|
||||
{
|
||||
setgaps(
|
||||
selmon->gappoh + arg->i,
|
||||
selmon->gappov,
|
||||
selmon->gappih,
|
||||
selmon->gappiv
|
||||
);
|
||||
}
|
||||
|
||||
void
|
||||
incrovgaps(const Arg *arg)
|
||||
{
|
||||
setgaps(
|
||||
selmon->gappoh,
|
||||
selmon->gappov + arg->i,
|
||||
selmon->gappih,
|
||||
selmon->gappiv
|
||||
);
|
||||
}
|
||||
|
||||
void
|
||||
incrihgaps(const Arg *arg)
|
||||
{
|
||||
setgaps(
|
||||
selmon->gappoh,
|
||||
selmon->gappov,
|
||||
selmon->gappih + arg->i,
|
||||
selmon->gappiv
|
||||
);
|
||||
}
|
||||
|
||||
void
|
||||
incrivgaps(const Arg *arg)
|
||||
{
|
||||
setgaps(
|
||||
selmon->gappoh,
|
||||
selmon->gappov,
|
||||
selmon->gappih,
|
||||
selmon->gappiv + arg->i
|
||||
);
|
||||
}
|
||||
|
||||
void
|
||||
getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc)
|
||||
{
|
||||
unsigned int n, oe, ie;
|
||||
#if PERTAG_PATCH
|
||||
oe = ie = selmon->pertag->enablegaps[selmon->pertag->curtag];
|
||||
#else
|
||||
oe = ie = enablegaps;
|
||||
#endif // PERTAG_PATCH
|
||||
Client *c;
|
||||
|
||||
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
|
||||
if (smartgaps && n == 1) {
|
||||
oe = 0; // outer gaps disabled when only one client
|
||||
}
|
||||
|
||||
*oh = m->gappoh*oe; // outer horizontal gap
|
||||
*ov = m->gappov*oe; // outer vertical gap
|
||||
*ih = m->gappih*ie; // inner horizontal gap
|
||||
*iv = m->gappiv*ie; // inner vertical gap
|
||||
*nc = n; // number of clients
|
||||
}
|
||||
|
||||
void
|
||||
getfacts(Monitor *m, int msize, int ssize, float *mf, float *sf, int *mr, int *sr)
|
||||
{
|
||||
unsigned int n;
|
||||
float mfacts, sfacts;
|
||||
int mtotal = 0, stotal = 0;
|
||||
Client *c;
|
||||
|
||||
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
|
||||
mfacts = MIN(n, m->nmaster);
|
||||
sfacts = n - m->nmaster;
|
||||
|
||||
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++)
|
||||
if (n < m->nmaster)
|
||||
mtotal += msize / mfacts;
|
||||
else
|
||||
stotal += ssize / sfacts;
|
||||
|
||||
*mf = mfacts; // total factor of master area
|
||||
*sf = sfacts; // total factor of stack area
|
||||
*mr = msize - mtotal; // the remainder (rest) of pixels after an even master split
|
||||
*sr = ssize - stotal; // the remainder (rest) of pixels after an even stack split
|
||||
}
|
||||
|
||||
/***
|
||||
* Layouts
|
||||
*/
|
||||
|
||||
/*
|
||||
* Bottomstack layout + gaps
|
||||
* https://dwm.suckless.org/patches/bottomstack/
|
||||
*/
|
||||
static void
|
||||
bstack(Monitor *m)
|
||||
{
|
||||
unsigned int i, n;
|
||||
int oh, ov, ih, iv;
|
||||
int mx = 0, my = 0, mh = 0, mw = 0;
|
||||
int sx = 0, sy = 0, sh = 0, sw = 0;
|
||||
float mfacts, sfacts;
|
||||
int mrest, srest;
|
||||
Client *c;
|
||||
|
||||
getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
if (n == 0)
|
||||
return;
|
||||
|
||||
sx = mx = m->wx + ov;
|
||||
sy = my = m->wy + oh;
|
||||
sh = mh = m->wh - 2*oh;
|
||||
mw = m->ww - 2*ov - iv * (MIN(n, m->nmaster) - 1);
|
||||
sw = m->ww - 2*ov - iv * (n - m->nmaster - 1);
|
||||
|
||||
if (m->nmaster && n > m->nmaster) {
|
||||
sh = (mh - ih) * (1 - m->mfact);
|
||||
mh = mh - ih - sh;
|
||||
sx = mx;
|
||||
sy = my + mh + ih;
|
||||
}
|
||||
|
||||
getfacts(m, mw, sw, &mfacts, &sfacts, &mrest, &srest);
|
||||
|
||||
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
|
||||
if (i < m->nmaster) {
|
||||
resize(c, mx, my, (mw / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), mh - (2*c->bw), 0);
|
||||
mx += WIDTH(c) + iv;
|
||||
} else {
|
||||
resize(c, sx, sy, (sw / sfacts) + ((i - m->nmaster) < srest ? 1 : 0) - (2*c->bw), sh - (2*c->bw), 0);
|
||||
sx += WIDTH(c) + iv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
bstackhoriz(Monitor *m)
|
||||
{
|
||||
unsigned int i, n;
|
||||
int oh, ov, ih, iv;
|
||||
int mx = 0, my = 0, mh = 0, mw = 0;
|
||||
int sx = 0, sy = 0, sh = 0, sw = 0;
|
||||
float mfacts, sfacts;
|
||||
int mrest, srest;
|
||||
Client *c;
|
||||
|
||||
getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
if (n == 0)
|
||||
return;
|
||||
|
||||
sx = mx = m->wx + ov;
|
||||
sy = my = m->wy + oh;
|
||||
mh = m->wh - 2*oh;
|
||||
sh = m->wh - 2*oh - ih * (n - m->nmaster - 1);
|
||||
mw = m->ww - 2*ov - iv * (MIN(n, m->nmaster) - 1);
|
||||
sw = m->ww - 2*ov;
|
||||
|
||||
if (m->nmaster && n > m->nmaster) {
|
||||
sh = (mh - ih) * (1 - m->mfact);
|
||||
mh = mh - ih - sh;
|
||||
sy = my + mh + ih;
|
||||
sh = m->wh - mh - 2*oh - ih * (n - m->nmaster);
|
||||
}
|
||||
|
||||
getfacts(m, mw, sh, &mfacts, &sfacts, &mrest, &srest);
|
||||
|
||||
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
|
||||
if (i < m->nmaster) {
|
||||
resize(c, mx, my, (mw / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), mh - (2*c->bw), 0);
|
||||
mx += WIDTH(c) + iv;
|
||||
} else {
|
||||
resize(c, sx, sy, sw - (2*c->bw), (sh / sfacts) + ((i - m->nmaster) < srest ? 1 : 0) - (2*c->bw), 0);
|
||||
sy += HEIGHT(c) + ih;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Centred master layout + gaps
|
||||
* https://dwm.suckless.org/patches/centeredmaster/
|
||||
*/
|
||||
void
|
||||
centeredmaster(Monitor *m)
|
||||
{
|
||||
unsigned int i, n;
|
||||
int oh, ov, ih, iv;
|
||||
int mx = 0, my = 0, mh = 0, mw = 0;
|
||||
int lx = 0, ly = 0, lw = 0, lh = 0;
|
||||
int rx = 0, ry = 0, rw = 0, rh = 0;
|
||||
float mfacts = 0, lfacts = 0, rfacts = 0;
|
||||
int mtotal = 0, ltotal = 0, rtotal = 0;
|
||||
int mrest = 0, lrest = 0, rrest = 0;
|
||||
Client *c;
|
||||
|
||||
getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
if (n == 0)
|
||||
return;
|
||||
|
||||
/* initialize areas */
|
||||
mx = m->wx + ov;
|
||||
my = m->wy + oh;
|
||||
mh = m->wh - 2*oh - ih * ((!m->nmaster ? n : MIN(n, m->nmaster)) - 1);
|
||||
mw = m->ww - 2*ov;
|
||||
lh = m->wh - 2*oh - ih * (((n - m->nmaster) / 2) - 1);
|
||||
rh = m->wh - 2*oh - ih * (((n - m->nmaster) / 2) - ((n - m->nmaster) % 2 ? 0 : 1));
|
||||
|
||||
if (m->nmaster && n > m->nmaster) {
|
||||
/* go mfact box in the center if more than nmaster clients */
|
||||
if (n - m->nmaster > 1) {
|
||||
/* ||<-S->|<---M--->|<-S->|| */
|
||||
mw = (m->ww - 2*ov - 2*iv) * m->mfact;
|
||||
lw = (m->ww - mw - 2*ov - 2*iv) / 2;
|
||||
rw = (m->ww - mw - 2*ov - 2*iv) - lw;
|
||||
mx += lw + iv;
|
||||
} else {
|
||||
/* ||<---M--->|<-S->|| */
|
||||
mw = (mw - iv) * m->mfact;
|
||||
lw = 0;
|
||||
rw = m->ww - mw - iv - 2*ov;
|
||||
}
|
||||
lx = m->wx + ov;
|
||||
ly = m->wy + oh;
|
||||
rx = mx + mw + iv;
|
||||
ry = m->wy + oh;
|
||||
}
|
||||
|
||||
/* calculate facts */
|
||||
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) {
|
||||
if (!m->nmaster || n < m->nmaster)
|
||||
mfacts += 1;
|
||||
else if ((n - m->nmaster) % 2)
|
||||
lfacts += 1; // total factor of left hand stack area
|
||||
else
|
||||
rfacts += 1; // total factor of right hand stack area
|
||||
}
|
||||
|
||||
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++)
|
||||
if (!m->nmaster || n < m->nmaster)
|
||||
mtotal += mh / mfacts;
|
||||
else if ((n - m->nmaster) % 2)
|
||||
ltotal += lh / lfacts;
|
||||
else
|
||||
rtotal += rh / rfacts;
|
||||
|
||||
mrest = mh - mtotal;
|
||||
lrest = lh - ltotal;
|
||||
rrest = rh - rtotal;
|
||||
|
||||
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
|
||||
if (!m->nmaster || i < m->nmaster) {
|
||||
/* nmaster clients are stacked vertically, in the center of the screen */
|
||||
resize(c, mx, my, mw - (2*c->bw), (mh / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
|
||||
my += HEIGHT(c) + ih;
|
||||
} else {
|
||||
/* stack clients are stacked vertically */
|
||||
if ((i - m->nmaster) % 2 ) {
|
||||
resize(c, lx, ly, lw - (2*c->bw), (lh / lfacts) + ((i - 2*m->nmaster) < 2*lrest ? 1 : 0) - (2*c->bw), 0);
|
||||
ly += HEIGHT(c) + ih;
|
||||
} else {
|
||||
resize(c, rx, ry, rw - (2*c->bw), (rh / rfacts) + ((i - 2*m->nmaster) < 2*rrest ? 1 : 0) - (2*c->bw), 0);
|
||||
ry += HEIGHT(c) + ih;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
centeredfloatingmaster(Monitor *m)
|
||||
{
|
||||
unsigned int i, n;
|
||||
float mfacts, sfacts;
|
||||
float mivf = 1.0; // master inner vertical gap factor
|
||||
int oh, ov, ih, iv, mrest, srest;
|
||||
int mx = 0, my = 0, mh = 0, mw = 0;
|
||||
int sx = 0, sy = 0, sh = 0, sw = 0;
|
||||
Client *c;
|
||||
|
||||
getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
if (n == 0)
|
||||
return;
|
||||
|
||||
sx = mx = m->wx + ov;
|
||||
sy = my = m->wy + oh;
|
||||
sh = mh = m->wh - 2*oh;
|
||||
mw = m->ww - 2*ov - iv*(n - 1);
|
||||
sw = m->ww - 2*ov - iv*(n - m->nmaster - 1);
|
||||
|
||||
if (m->nmaster && n > m->nmaster) {
|
||||
mivf = 0.8;
|
||||
/* go mfact box in the center if more than nmaster clients */
|
||||
if (m->ww > m->wh) {
|
||||
mw = m->ww * m->mfact - iv*mivf*(MIN(n, m->nmaster) - 1);
|
||||
mh = m->wh * 0.9;
|
||||
} else {
|
||||
mw = m->ww * 0.9 - iv*mivf*(MIN(n, m->nmaster) - 1);
|
||||
mh = m->wh * m->mfact;
|
||||
}
|
||||
mx = m->wx + (m->ww - mw) / 2;
|
||||
my = m->wy + (m->wh - mh - 2*oh) / 2;
|
||||
|
||||
sx = m->wx + ov;
|
||||
sy = m->wy + oh;
|
||||
sh = m->wh - 2*oh;
|
||||
}
|
||||
|
||||
getfacts(m, mw, sw, &mfacts, &sfacts, &mrest, &srest);
|
||||
|
||||
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
|
||||
if (i < m->nmaster) {
|
||||
/* nmaster clients are stacked horizontally, in the center of the screen */
|
||||
resize(c, mx, my, (mw / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), mh - (2*c->bw), 0);
|
||||
mx += WIDTH(c) + iv*mivf;
|
||||
} else {
|
||||
/* stack clients are stacked horizontally */
|
||||
resize(c, sx, sy, (sw / sfacts) + ((i - m->nmaster) < srest ? 1 : 0) - (2*c->bw), sh - (2*c->bw), 0);
|
||||
sx += WIDTH(c) + iv;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Deck layout + gaps
|
||||
* https://dwm.suckless.org/patches/deck/
|
||||
*/
|
||||
void
|
||||
deck(Monitor *m)
|
||||
{
|
||||
unsigned int i, n;
|
||||
int oh, ov, ih, iv;
|
||||
int mx = 0, my = 0, mh = 0, mw = 0;
|
||||
int sx = 0, sy = 0, sh = 0, sw = 0;
|
||||
float mfacts, sfacts;
|
||||
int mrest, srest;
|
||||
Client *c;
|
||||
|
||||
getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
if (n == 0)
|
||||
return;
|
||||
|
||||
sx = mx = m->wx + ov;
|
||||
sy = my = m->wy + oh;
|
||||
sh = mh = m->wh - 2*oh - ih * (MIN(n, m->nmaster) - 1);
|
||||
sw = mw = m->ww - 2*ov;
|
||||
|
||||
if (m->nmaster && n > m->nmaster) {
|
||||
sw = (mw - iv) * (1 - m->mfact);
|
||||
mw = mw - iv - sw;
|
||||
sx = mx + mw + iv;
|
||||
sh = m->wh - 2*oh;
|
||||
}
|
||||
|
||||
getfacts(m, mh, sh, &mfacts, &sfacts, &mrest, &srest);
|
||||
|
||||
if (n - m->nmaster > 0) /* override layout symbol */
|
||||
snprintf(m->ltsymbol, sizeof m->ltsymbol, "D %d", n - m->nmaster);
|
||||
|
||||
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
|
||||
if (i < m->nmaster) {
|
||||
resize(c, mx, my, mw - (2*c->bw), (mh / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
|
||||
my += HEIGHT(c) + ih;
|
||||
} else {
|
||||
resize(c, sx, sy, sw - (2*c->bw), sh - (2*c->bw), 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Fibonacci layout + gaps
|
||||
* https://dwm.suckless.org/patches/fibonacci/
|
||||
*/
|
||||
void
|
||||
fibonacci(Monitor *m, int s)
|
||||
{
|
||||
unsigned int i, n;
|
||||
int nx, ny, nw, nh;
|
||||
int oh, ov, ih, iv;
|
||||
int nv, hrest = 0, wrest = 0, r = 1;
|
||||
Client *c;
|
||||
|
||||
getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
if (n == 0)
|
||||
return;
|
||||
|
||||
nx = m->wx + ov;
|
||||
ny = m->wy + oh;
|
||||
nw = m->ww - 2*ov;
|
||||
nh = m->wh - 2*oh;
|
||||
|
||||
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
|
||||
if (r) {
|
||||
if ((i % 2 && (nh - ih) / 2 <= (bh + 2*c->bw))
|
||||
|| (!(i % 2) && (nw - iv) / 2 <= (bh + 2*c->bw))) {
|
||||
r = 0;
|
||||
}
|
||||
if (r && i < n - 1) {
|
||||
if (i % 2) {
|
||||
nv = (nh - ih) / 2;
|
||||
hrest = nh - 2*nv - ih;
|
||||
nh = nv;
|
||||
} else {
|
||||
nv = (nw - iv) / 2;
|
||||
wrest = nw - 2*nv - iv;
|
||||
nw = nv;
|
||||
}
|
||||
|
||||
if ((i % 4) == 2 && !s)
|
||||
nx += nw + iv;
|
||||
else if ((i % 4) == 3 && !s)
|
||||
ny += nh + ih;
|
||||
}
|
||||
|
||||
if ((i % 4) == 0) {
|
||||
if (s) {
|
||||
ny += nh + ih;
|
||||
nh += hrest;
|
||||
}
|
||||
else {
|
||||
nh -= hrest;
|
||||
ny -= nh + ih;
|
||||
}
|
||||
}
|
||||
else if ((i % 4) == 1) {
|
||||
nx += nw + iv;
|
||||
nw += wrest;
|
||||
}
|
||||
else if ((i % 4) == 2) {
|
||||
ny += nh + ih;
|
||||
nh += hrest;
|
||||
if (i < n - 1)
|
||||
nw += wrest;
|
||||
}
|
||||
else if ((i % 4) == 3) {
|
||||
if (s) {
|
||||
nx += nw + iv;
|
||||
nw -= wrest;
|
||||
} else {
|
||||
nw -= wrest;
|
||||
nx -= nw + iv;
|
||||
nh += hrest;
|
||||
}
|
||||
}
|
||||
if (i == 0) {
|
||||
if (n != 1) {
|
||||
nw = (m->ww - iv - 2*ov) - (m->ww - iv - 2*ov) * (1 - m->mfact);
|
||||
wrest = 0;
|
||||
}
|
||||
ny = m->wy + oh;
|
||||
}
|
||||
else if (i == 1)
|
||||
nw = m->ww - nw - iv - 2*ov;
|
||||
i++;
|
||||
}
|
||||
|
||||
resize(c, nx, ny, nw - (2*c->bw), nh - (2*c->bw), False);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
dwindle(Monitor *m)
|
||||
{
|
||||
fibonacci(m, 1);
|
||||
}
|
||||
|
||||
void
|
||||
spiral(Monitor *m)
|
||||
{
|
||||
fibonacci(m, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Gappless grid layout + gaps (ironically)
|
||||
* https://dwm.suckless.org/patches/gaplessgrid/
|
||||
*/
|
||||
void
|
||||
gaplessgrid(Monitor *m)
|
||||
{
|
||||
unsigned int i, n;
|
||||
int x, y, cols, rows, ch, cw, cn, rn, rrest, crest; // counters
|
||||
int oh, ov, ih, iv;
|
||||
Client *c;
|
||||
|
||||
getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
if (n == 0)
|
||||
return;
|
||||
|
||||
/* grid dimensions */
|
||||
for (cols = 0; cols <= n/2; cols++)
|
||||
if (cols*cols >= n)
|
||||
break;
|
||||
if (n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
|
||||
cols = 2;
|
||||
rows = n/cols;
|
||||
cn = rn = 0; // reset column no, row no, client count
|
||||
|
||||
ch = (m->wh - 2*oh - ih * (rows - 1)) / rows;
|
||||
cw = (m->ww - 2*ov - iv * (cols - 1)) / cols;
|
||||
rrest = (m->wh - 2*oh - ih * (rows - 1)) - ch * rows;
|
||||
crest = (m->ww - 2*ov - iv * (cols - 1)) - cw * cols;
|
||||
x = m->wx + ov;
|
||||
y = m->wy + oh;
|
||||
|
||||
for (i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
|
||||
if (i/rows + 1 > cols - n%cols) {
|
||||
rows = n/cols + 1;
|
||||
ch = (m->wh - 2*oh - ih * (rows - 1)) / rows;
|
||||
rrest = (m->wh - 2*oh - ih * (rows - 1)) - ch * rows;
|
||||
}
|
||||
resize(c,
|
||||
x,
|
||||
y + rn*(ch + ih) + MIN(rn, rrest),
|
||||
cw + (cn < crest ? 1 : 0) - 2*c->bw,
|
||||
ch + (rn < rrest ? 1 : 0) - 2*c->bw,
|
||||
0);
|
||||
rn++;
|
||||
if (rn >= rows) {
|
||||
rn = 0;
|
||||
x += cw + ih + (cn < crest ? 1 : 0);
|
||||
cn++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Gridmode layout + gaps
|
||||
* https://dwm.suckless.org/patches/gridmode/
|
||||
*/
|
||||
void
|
||||
grid(Monitor *m)
|
||||
{
|
||||
unsigned int i, n;
|
||||
int cx, cy, cw, ch, cc, cr, chrest, cwrest, cols, rows;
|
||||
int oh, ov, ih, iv;
|
||||
Client *c;
|
||||
|
||||
getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
|
||||
/* grid dimensions */
|
||||
for (rows = 0; rows <= n/2; rows++)
|
||||
if (rows*rows >= n)
|
||||
break;
|
||||
cols = (rows && (rows - 1) * rows >= n) ? rows - 1 : rows;
|
||||
|
||||
/* window geoms (cell height/width) */
|
||||
ch = (m->wh - 2*oh - ih * (rows - 1)) / (rows ? rows : 1);
|
||||
cw = (m->ww - 2*ov - iv * (cols - 1)) / (cols ? cols : 1);
|
||||
chrest = (m->wh - 2*oh - ih * (rows - 1)) - ch * rows;
|
||||
cwrest = (m->ww - 2*ov - iv * (cols - 1)) - cw * cols;
|
||||
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
|
||||
cc = i / rows;
|
||||
cr = i % rows;
|
||||
cx = m->wx + ov + cc * (cw + iv) + MIN(cc, cwrest);
|
||||
cy = m->wy + oh + cr * (ch + ih) + MIN(cr, chrest);
|
||||
resize(c, cx, cy, cw + (cc < cwrest ? 1 : 0) - 2*c->bw, ch + (cr < chrest ? 1 : 0) - 2*c->bw, False);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Horizontal grid layout + gaps
|
||||
* https://dwm.suckless.org/patches/horizgrid/
|
||||
*/
|
||||
void
|
||||
horizgrid(Monitor *m) {
|
||||
Client *c;
|
||||
unsigned int n, i;
|
||||
int oh, ov, ih, iv;
|
||||
int mx = 0, my = 0, mh = 0, mw = 0;
|
||||
int sx = 0, sy = 0, sh = 0, sw = 0;
|
||||
int ntop, nbottom = 1;
|
||||
float mfacts, sfacts;
|
||||
int mrest, srest;
|
||||
|
||||
/* Count windows */
|
||||
getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
if (n == 0)
|
||||
return;
|
||||
|
||||
if (n <= 2)
|
||||
ntop = n;
|
||||
else {
|
||||
ntop = n / 2;
|
||||
nbottom = n - ntop;
|
||||
}
|
||||
sx = mx = m->wx + ov;
|
||||
sy = my = m->wy + oh;
|
||||
sh = mh = m->wh - 2*oh;
|
||||
sw = mw = m->ww - 2*ov;
|
||||
|
||||
if (n > ntop) {
|
||||
sh = (mh - ih) / 2;
|
||||
mh = mh - ih - sh;
|
||||
sy = my + mh + ih;
|
||||
mw = m->ww - 2*ov - iv * (ntop - 1);
|
||||
sw = m->ww - 2*ov - iv * (nbottom - 1);
|
||||
}
|
||||
|
||||
mfacts = ntop;
|
||||
sfacts = nbottom;
|
||||
mrest = mw - (mw / ntop) * ntop;
|
||||
srest = sw - (sw / nbottom) * nbottom;
|
||||
|
||||
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
|
||||
if (i < ntop) {
|
||||
resize(c, mx, my, (mw / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), mh - (2*c->bw), 0);
|
||||
mx += WIDTH(c) + iv;
|
||||
} else {
|
||||
resize(c, sx, sy, (sw / sfacts) + ((i - ntop) < srest ? 1 : 0) - (2*c->bw), sh - (2*c->bw), 0);
|
||||
sx += WIDTH(c) + iv;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* nrowgrid layout + gaps
|
||||
* https://dwm.suckless.org/patches/nrowgrid/
|
||||
*/
|
||||
void
|
||||
nrowgrid(Monitor *m)
|
||||
{
|
||||
unsigned int n;
|
||||
int ri = 0, ci = 0; /* counters */
|
||||
int oh, ov, ih, iv; /* vanitygap settings */
|
||||
unsigned int cx, cy, cw, ch; /* client geometry */
|
||||
unsigned int uw = 0, uh = 0, uc = 0; /* utilization trackers */
|
||||
unsigned int cols, rows = m->nmaster + 1;
|
||||
Client *c;
|
||||
|
||||
/* count clients */
|
||||
getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
|
||||
/* nothing to do here */
|
||||
if (n == 0)
|
||||
return;
|
||||
|
||||
/* force 2 clients to always split vertically */
|
||||
if (FORCE_VSPLIT && n == 2)
|
||||
rows = 1;
|
||||
|
||||
/* never allow empty rows */
|
||||
if (n < rows)
|
||||
rows = n;
|
||||
|
||||
/* define first row */
|
||||
cols = n / rows;
|
||||
uc = cols;
|
||||
cy = m->wy + oh;
|
||||
ch = (m->wh - 2*oh - ih*(rows - 1)) / rows;
|
||||
uh = ch;
|
||||
|
||||
for (c = nexttiled(m->clients); c; c = nexttiled(c->next), ci++) {
|
||||
if (ci == cols) {
|
||||
uw = 0;
|
||||
ci = 0;
|
||||
ri++;
|
||||
|
||||
/* next row */
|
||||
cols = (n - uc) / (rows - ri);
|
||||
uc += cols;
|
||||
cy = m->wy + oh + uh + ih;
|
||||
uh += ch + ih;
|
||||
}
|
||||
|
||||
cx = m->wx + ov + uw;
|
||||
cw = (m->ww - 2*ov - uw) / (cols - ci);
|
||||
uw += cw + iv;
|
||||
|
||||
resize(c, cx, cy, cw - (2*c->bw), ch - (2*c->bw), 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Default tile layout + gaps
|
||||
*/
|
||||
static void
|
||||
tile(Monitor *m)
|
||||
{
|
||||
unsigned int i, n;
|
||||
int oh, ov, ih, iv;
|
||||
int mx = 0, my = 0, mh = 0, mw = 0;
|
||||
int sx = 0, sy = 0, sh = 0, sw = 0;
|
||||
float mfacts, sfacts;
|
||||
int mrest, srest;
|
||||
Client *c;
|
||||
|
||||
getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
if (n == 0)
|
||||
return;
|
||||
|
||||
sx = mx = m->wx + ov;
|
||||
sy = my = m->wy + oh;
|
||||
mh = m->wh - 2*oh - ih * (MIN(n, m->nmaster) - 1);
|
||||
sh = m->wh - 2*oh - ih * (n - m->nmaster - 1);
|
||||
sw = mw = m->ww - 2*ov;
|
||||
|
||||
if (m->nmaster && n > m->nmaster) {
|
||||
sw = (mw - iv) * (1 - m->mfact);
|
||||
mw = mw - iv - sw;
|
||||
sx = mx + mw + iv;
|
||||
}
|
||||
|
||||
getfacts(m, mh, sh, &mfacts, &sfacts, &mrest, &srest);
|
||||
|
||||
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
|
||||
if (i < m->nmaster) {
|
||||
resize(c, mx, my, mw - (2*c->bw), (mh / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
|
||||
my += HEIGHT(c) + ih;
|
||||
} else {
|
||||
resize(c, sx, sy, sw - (2*c->bw), (sh / sfacts) + ((i - m->nmaster) < srest ? 1 : 0) - (2*c->bw), 0);
|
||||
sy += HEIGHT(c) + ih;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
#!/bin/fish
|
||||
# Start X at login
|
||||
if status is-login
|
||||
if test -z "$DISPLAY" -a "$XDG_VTNR" = 1
|
||||
exec startx -- -keeptty
|
||||
end
|
||||
end
|
||||
set -Ux HOME /home/fuzzy
|
||||
set -Ux XDG_CONFIG_HOME $HOME/.config
|
||||
|
||||
alias rm="rm -dr"
|
||||
alias cp="cp -r"
|
||||
alias exa="exa -aF -s type"
|
||||
alias mkdir="mkdir -p"
|
||||
alias hima="himalaya"
|
||||
fish_add_path -g /bin /usr/bin /usr/local/bin /home/fuzzy/.cargo/bin /home/fuzzy/.local/bin
|
|
@ -0,0 +1,47 @@
|
|||
# This file contains fish universal variable definitions.
|
||||
# VERSION: 3.0
|
||||
SETUVAR --export EDITOR:nvim
|
||||
SETUVAR --export HOME:/home/fuzzy
|
||||
SETUVAR SHELL:/usr/bin/fish
|
||||
SETUVAR --export XDG_CACHE_HOME:/home/fuzzy/\x2ecache
|
||||
SETUVAR --export XDG_CONFIG_HOME:/home/fuzzy/\x2econfig
|
||||
SETUVAR --export XDG_DATA_HOME:/home/fuzzy/\x2elocal/share
|
||||
SETUVAR __fish_initialized:3100
|
||||
SETUVAR _fish_abbr_docker:sudo\x20docker
|
||||
SETUVAR _fish_abbr_tra:transmission\x2dremote\x20\x2da
|
||||
SETUVAR _fish_abbr_vpmi:sudo\x20vpm\x20install\x20\x2dy
|
||||
SETUVAR _fish_abbr_vpmr:sudo\x20vpm\x20remove
|
||||
SETUVAR _fish_abbr_vpms:sudo\x20vpm\x20search
|
||||
SETUVAR _fish_abbr_vpmu:sudo\x20vpm\x20upgrade
|
||||
SETUVAR _fish_abbr_vsv:sudo\x20vsv
|
||||
SETUVAR _fish_abbr_xbpsi:sudo\x20xbps\x2dinstall
|
||||
SETUVAR _fish_abbr_xbpsq:xbps\x2dquery\x20\x2dRs
|
||||
SETUVAR _fish_abbr_xbpsr:sudo\x20xbps\x2dremove
|
||||
SETUVAR fish_color_autosuggestion:969896
|
||||
SETUVAR fish_color_cancel:\x2dr
|
||||
SETUVAR fish_color_command:8f6f8f
|
||||
SETUVAR fish_color_comment:5f5f5f
|
||||
SETUVAR fish_color_cwd:6688aa
|
||||
SETUVAR fish_color_cwd_root:red
|
||||
SETUVAR fish_color_end:d3d3d3
|
||||
SETUVAR fish_color_error:d3d3d3\x1e\x2d\x2dbackground\x3daa4450
|
||||
SETUVAR fish_color_escape:6688aa
|
||||
SETUVAR fish_color_history_current:\x2d\x2dbold
|
||||
SETUVAR fish_color_host:normal
|
||||
SETUVAR fish_color_host_remote:yellow
|
||||
SETUVAR fish_color_match:d3d3d3
|
||||
SETUVAR fish_color_normal:e3e1e4
|
||||
SETUVAR fish_color_operator:8f6f8f
|
||||
SETUVAR fish_color_param:719611
|
||||
SETUVAR fish_color_quote:ff9800
|
||||
SETUVAR fish_color_redirection:8f6f8f
|
||||
SETUVAR fish_color_search_match:\x2d\x2dbackground\x3d5f5f5f
|
||||
SETUVAR fish_color_selection:white\x1e\x2d\x2dbold\x1e\x2d\x2dbackground\x3dbrblack
|
||||
SETUVAR fish_color_status:red
|
||||
SETUVAR fish_color_user:brgreen
|
||||
SETUVAR fish_color_valid_path:\x2d\x2dunderline
|
||||
SETUVAR fish_key_bindings:fish_default_key_bindings
|
||||
SETUVAR fish_pager_color_completion:5f5f5f
|
||||
SETUVAR fish_pager_color_description:5f5f5f
|
||||
SETUVAR fish_pager_color_prefix:d3d3d3
|
||||
SETUVAR fish_pager_color_progress:d3d3d3
|
|
@ -0,0 +1,3 @@
|
|||
function fish_greeting
|
||||
echo 'HOW ARE YOU GENTLEMEN !!'
|
||||
end
|
|
@ -0,0 +1,84 @@
|
|||
function fish_prompt --description 'Write out the prompt'
|
||||
set -l last_pipestatus $pipestatus
|
||||
|
||||
if not set -q __fish_git_prompt_show_informative_status
|
||||
set -g __fish_git_prompt_show_informative_status 1
|
||||
end
|
||||
if not set -q __fish_git_prompt_hide_untrackedfiles
|
||||
set -g __fish_git_prompt_hide_untrackedfiles 1
|
||||
end
|
||||
if not set -q __fish_git_prompt_color_branch
|
||||
set -g __fish_git_prompt_color_branch magenta --bold
|
||||
end
|
||||
if not set -q __fish_git_prompt_showupstream
|
||||
set -g __fish_git_prompt_showupstream "informative"
|
||||
end
|
||||
if not set -q __fish_git_prompt_char_upstream_ahead
|
||||
set -g __fish_git_prompt_char_upstream_ahead "↑"
|
||||
end
|
||||
if not set -q __fish_git_prompt_char_upstream_behind
|
||||
set -g __fish_git_prompt_char_upstream_behind "↓"
|
||||
end
|
||||
if not set -q __fish_git_prompt_char_upstream_prefix
|
||||
set -g __fish_git_prompt_char_upstream_prefix ""
|
||||
end
|
||||
if not set -q __fish_git_prompt_char_stagedstate
|
||||
set -g __fish_git_prompt_char_stagedstate "●"
|
||||
end
|
||||
if not set -q __fish_git_prompt_char_dirtystate
|
||||
set -g __fish_git_prompt_char_dirtystate "✚"
|
||||
end
|
||||
if not set -q __fish_git_prompt_char_untrackedfiles
|
||||
set -g __fish_git_prompt_char_untrackedfiles "…"
|
||||
end
|
||||
if not set -q __fish_git_prompt_char_invalidstate
|
||||
set -g __fish_git_prompt_char_invalidstate "✖"
|
||||
end
|
||||
if not set -q __fish_git_prompt_char_cleanstate
|
||||
set -g __fish_git_prompt_char_cleanstate "✔"
|
||||
end
|
||||
if not set -q __fish_git_prompt_color_dirtystate
|
||||
set -g __fish_git_prompt_color_dirtystate blue
|
||||
end
|
||||
if not set -q __fish_git_prompt_color_stagedstate
|
||||
set -g __fish_git_prompt_color_stagedstate yellow
|
||||
end
|
||||
if not set -q __fish_git_prompt_color_invalidstate
|
||||
set -g __fish_git_prompt_color_invalidstate red
|
||||
end
|
||||
if not set -q __fish_git_prompt_color_untrackedfiles
|
||||
set -g __fish_git_prompt_color_untrackedfiles $fish_color_normal
|
||||
end
|
||||
if not set -q __fish_git_prompt_color_cleanstate
|
||||
set -g __fish_git_prompt_color_cleanstate green --bold
|
||||
end
|
||||
|
||||
set -l color_cwd
|
||||
set -l prefix
|
||||
set -l suffix
|
||||
switch "$USER"
|
||||
case root toor
|
||||
if set -q fish_color_cwd_root
|
||||
set color_cwd $fish_color_cwd_root
|
||||
else
|
||||
set color_cwd $fish_color_cwd
|
||||
end
|
||||
set suffix '#'
|
||||
case '*'
|
||||
set color_cwd $fish_color_cwd
|
||||
set suffix '❱'
|
||||
end
|
||||
|
||||
# PWD
|
||||
set_color $color_cwd
|
||||
echo -n (prompt_pwd)
|
||||
set_color normal
|
||||
|
||||
printf '%s ' (fish_vcs_prompt)
|
||||
|
||||
set -l pipestatus_string (__fish_print_pipestatus "[" "] " "|" (set_color $fish_color_status) (set_color --bold $fish_color_status) $last_pipestatus)
|
||||
echo -n $pipestatus_string
|
||||
set_color normal
|
||||
|
||||
echo -n "$suffix "
|
||||
end
|
|
@ -0,0 +1,85 @@
|
|||
templates:
|
||||
anime:
|
||||
rss: https://subsplease.org/rss/?r=1080
|
||||
exists_series: /mnt/EntertainmentDrive/anime/{{series_name}}
|
||||
series:
|
||||
settings:
|
||||
seriesgroup:
|
||||
tracking: no
|
||||
identified_by: sequence
|
||||
season_packs: yes
|
||||
set:
|
||||
path: /mnt/EntertainmentDrive/anime/{{series_name}}
|
||||
seriesgroup:
|
||||
- Adachi to Shimamura
|
||||
- Beastars
|
||||
- Blue Period
|
||||
- Blue Reflection Ray
|
||||
- Cheat Kusushi no Slow Life
|
||||
- Deji Meets Girl
|
||||
- Ganbare Douki-chan
|
||||
- Gekidol
|
||||
- Getsuyoubi no Tawawa
|
||||
- Godzilla Singular Point
|
||||
- Gunma-chan
|
||||
- Gyakuten Sekai no Denchi Shoujo
|
||||
- Hanyou no Yashahime
|
||||
- Boku no Hero Academia
|
||||
- Hige wo Soru
|
||||
- Horimiya
|
||||
- Idoly Pride
|
||||
- Jahy-sama wa Kujikenai!
|
||||
- Jaku-Chara Tomozaki-kun
|
||||
- Kageki Shoujo!!
|
||||
- Kanojo mo Kanojo
|
||||
- Kimetsu no Yaiba
|
||||
- Koi to Yobu ni wa Kimochi Warui
|
||||
- Komi-san wa, Comyushou desu
|
||||
- Kuma Kuma Kuma Bear
|
||||
- Kyoukai Senki
|
||||
- Kyuuketsuki Sugu Shinu
|
||||
- Love Live! Superstar!!
|
||||
- Mahouka Koukou no Yuutousei
|
||||
- Majo no Tabitabi
|
||||
- Megaton-kyuu Musashi
|
||||
- Mieruko-chan
|
||||
- Puraore! Pride of Orange
|
||||
- Sakugan
|
||||
- Sayonara Watashi no Cramer
|
||||
- Selection Project
|
||||
- Senpai ga Uzai Kouhai no Hanashi
|
||||
- Shaman King
|
||||
- Shin no Nakama
|
||||
- Shiroi Suna no Aquatope
|
||||
- SSSS.Dynazenon
|
||||
- Subarashiki Kono Sekai
|
||||
- Super Cub
|
||||
- Taishou Otome Otogibanashi
|
||||
- Takt Op. Destiny
|
||||
- Uma Musume
|
||||
- Vivy - Fluorite Eye's Song
|
||||
- Yakunara Mug Cup
|
||||
- Yuru Camp
|
||||
transmission: yes
|
||||
|
||||
tasks:
|
||||
|
||||
judas:
|
||||
rss: https://nyaa.si/?page=rss&u=Judas
|
||||
template: anime
|
||||
|
||||
ASW:
|
||||
rss: https://nyaa.si/?page=rss&u=AkihitoSubsWeeklies
|
||||
template: anime
|
||||
|
||||
subsplease:
|
||||
rss: https://subsplease.org/rss/?r=1080
|
||||
template: anime
|
||||
|
||||
tenrai:
|
||||
rss: https://nyaa.si/?page=rss&u=Tenrai_Sensei
|
||||
template: anime
|
||||
|
||||
moyaisubs:
|
||||
rss: https://nyaa.si/?page=rss&u=MoyaiSubs
|
||||
template: anime
|
|
@ -0,0 +1,26 @@
|
|||
# ~/.config/himalaya/config.toml
|
||||
name = "Jeremy Lavitt"
|
||||
downloads-dir = "~/Downloads"
|
||||
signature = ""
|
||||
default-page-size = 50
|
||||
watch-cmds = ["mbsync -a"]
|
||||
|
||||
[outlook]
|
||||
email = "JeremyLavitt@outlook.com"
|
||||
default = true
|
||||
default-page-size = 25
|
||||
signature = """
|
||||
Regards,
|
||||
Jeremy Lavitt
|
||||
"""
|
||||
|
||||
imap-host = "outlook.office365.com"
|
||||
imap-port = 993
|
||||
imap-login = "jeremylavitt@outlook.com"
|
||||
imap-passwd-cmd = "pass show outlookhima"
|
||||
|
||||
smtp-host = "smtp.office365.com"
|
||||
smtp-port = 587
|
||||
smtp-starttls = true
|
||||
smtp-login = "jeremylavitt@outlook.com"
|
||||
smtp-passwd-cmd = "pass show outlookhima"
|
|
@ -0,0 +1,9 @@
|
|||
profile=gpu-hq
|
||||
alang = 'jpn,jp,eng,en'
|
||||
slang = 'eng,en,enUS' # enUS for Crunchyroll.
|
||||
screenshot-format=png
|
||||
screenshot-high-bit-depth=yes
|
||||
screenshot-png-compression=7 # Setting too high may lag the PC on weaker systems. Recommend 3 (weak systems) or 7.
|
||||
screenshot-directory="~/Pictures/mpv-screenshot"
|
||||
volume=100 # Set volume to 100% on startup.
|
||||
sub-auto=fuzzy
|
|
@ -0,0 +1,8 @@
|
|||
source "gpg2 --decrypt ~/outlookpass.gpg |"
|
||||
source "~/.config/neomutt/outlook.muttrc"
|
||||
source "~/.config/neomutt/colors.muttrc"
|
||||
source "~/.config/neomutt/sidebar.muttrc"
|
||||
souce "~/.config/neomutt/neomuttrc2"
|
||||
auto_view text/html
|
||||
alternative_order text/plain text/enriched text/html text
|
||||
|
|
@ -0,0 +1,228 @@
|
|||
filetype off
|
||||
|
||||
set rtp+=~/.vim/bundle/Vundle.vim
|
||||
call vundle#begin()
|
||||
|
||||
Plugin 'VundleVim/Vundle.vim'
|
||||
Plugin 'mg979/vim-visual-multi'
|
||||
Plugin 'terrortylor/nvim-comment'
|
||||
Plugin 'windwp/nvim-autopairs'
|
||||
Plugin 'Pocco81/AutoSave.nvim'
|
||||
Plugin 'karb94/neoscroll.nvim'
|
||||
Plugin 'nvim-treesitter/nvim-treesitter'
|
||||
Plugin 'itchyny/lightline.vim'
|
||||
Plugin 'ryanoasis/vim-devicons'
|
||||
Plugin 'norcalli/nvim-colorizer.lua'
|
||||
Plugin 'lukas-reineke/indent-blankline.nvim'
|
||||
Plugin 'vim-syntastic/syntastic'
|
||||
Plugin 'neovim/nvim-lspconfig'
|
||||
Plugin 'neoclide/coc.nvim', {'branch': 'release'}
|
||||
|
||||
Plugin 'sainnhe/sonokai'
|
||||
Plugin 'chasinglogic/modus-themes-vim'
|
||||
Plugin 'joshdick/onedark.vim'
|
||||
Plugin 'https://gitlab.com/yorickpeterse/happy_hacking.vim'
|
||||
Plugin 'sickill/vim-monokai'
|
||||
Plugin 'sonph/onehalf'
|
||||
Plugin 'jnurmine/Zenburn'
|
||||
Plugin 'drewtempelmeyer/palenight.vim'
|
||||
Plugin 'morhetz/gruvbox'
|
||||
Plugin 'altercation/vim-colors-solarized'
|
||||
Plugin 'wadackel/vim-dogrun'
|
||||
Plugin 'tyrannicaltoucan/vim-quantum'
|
||||
Plugin 'bluz71/vim-moonfly-colors'
|
||||
Plugin 'tyrannicaltoucan/vim-deep-space'
|
||||
Plugin 'xero/sourcerer.vim'
|
||||
Plugin 'arzg/vim-corvine'
|
||||
Plugin 'tssm/fairyfloss.vim'
|
||||
|
||||
call vundle#end()
|
||||
filetype plugin indent on
|
||||
|
||||
set termguicolors
|
||||
lua require('neoscroll').setup()
|
||||
lua require('nvim-autopairs').setup()
|
||||
lua require('nvim_comment').setup()
|
||||
lua require('colorizer').setup()
|
||||
|
||||
""" Main Config
|
||||
colorscheme sourcerer
|
||||
set tabstop=8 softtabstop=8 noexpandtab smarttab autoindent
|
||||
set incsearch ignorecase smartcase hlsearch
|
||||
set ruler laststatus=2 showcmd showmode
|
||||
set wrap breakindent
|
||||
set encoding=utf-8
|
||||
set textwidth=0
|
||||
set hidden
|
||||
set number relativenumber
|
||||
set title
|
||||
set cursorline
|
||||
"hi CursorLine cterm=bold
|
||||
"hi CursorLineNr term=bold cterm=bold
|
||||
"hi LineNr
|
||||
"hi Whitespace ctermbg=red
|
||||
match Whitespace /\s\+$/
|
||||
|
||||
set statusline+=%#warningmsg#
|
||||
set statusline+=%{SyntasticStatuslineFlag()}
|
||||
set statusline+=%*
|
||||
|
||||
let g:syntastic_always_populate_loc_list = 1
|
||||
let g:syntastic_auto_loc_list = 1
|
||||
let g:syntastic_check_on_open = 1
|
||||
let g:syntastic_check_on_wq = 0
|
||||
|
||||
" Give more space for displaying messages.
|
||||
set cmdheight=2
|
||||
|
||||
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
|
||||
" delays and poor user experience.
|
||||
set updatetime=300
|
||||
|
||||
" Don't pass messages to |ins-completion-menu|.
|
||||
set shortmess+=c
|
||||
|
||||
" Always show the signcolumn, otherwise it would shift the text each time
|
||||
" diagnostics appear/become resolved.
|
||||
if has("nvim-0.5.0") || has("patch-8.1.1564")
|
||||
" Recently vim can merge signcolumn and number column into one
|
||||
set signcolumn=number
|
||||
else
|
||||
set signcolumn=yes
|
||||
endif
|
||||
|
||||
" Use tab for trigger completion with characters ahead and navigate.
|
||||
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
|
||||
" other plugin before putting this into your config.
|
||||
inoremap <silent><expr> <TAB>
|
||||
\ pumvisible() ? "\<C-n>" :
|
||||
\ <SID>check_back_space() ? "\<TAB>" :
|
||||
\ coc#refresh()
|
||||
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
|
||||
|
||||
function! s:check_back_space() abort
|
||||
let col = col('.') - 1
|
||||
return !col || getline('.')[col - 1] =~# '\s'
|
||||
endfunction
|
||||
|
||||
" Use <c-space> to trigger completion.
|
||||
if has('nvim')
|
||||
inoremap <silent><expr> <c-space> coc#refresh()
|
||||
else
|
||||
inoremap <silent><expr> <c-@> coc#refresh(
|
||||
endif
|
||||
|
||||
" Make <CR> auto-select the first completion item and notify coc.nvim to
|
||||
" format on enter, <cr> could be remapped by other vim plugin
|
||||
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
|
||||
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
|
||||
|
||||
" Use `[g` and `]g` to navigate diagnostics
|
||||
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
|
||||
nmap <silent> [g <Plug>(coc-diagnostic-prev)
|
||||
nmap <silent> ]g <Plug>(coc-diagnostic-next)
|
||||
|
||||
" GoTo code navigation.
|
||||
nmap <silent> gd <Plug>(coc-definition)
|
||||
nmap <silent> gy <Plug>(coc-type-definition)
|
||||
nmap <silent> gi <Plug>(coc-implementation)
|
||||
nmap <silent> gr <Plug>(coc-references)
|
||||
|
||||
" Use K to show documentation in preview window.
|
||||
nnoremap <silent> K :call <SID>show_documentation()<CR>
|
||||
|
||||
function! s:show_documentation()
|
||||
if (index(['vim','help'], &filetype) >= 0)
|
||||
execute 'h '.expand('<cword>')
|
||||
elseif (coc#rpc#ready())
|
||||
call CocActionAsync('doHover')
|
||||
else
|
||||
execute '!' . &keywordprg . " " . expand('<cword>')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Highlight the symbol and its references when holding the cursor.
|
||||
autocmd CursorHold * silent call CocActionAsync('highlight')
|
||||
|
||||
" Symbol renaming.
|
||||
nmap <leader>rn <Plug>(coc-rename)
|
||||
|
||||
" Formatting selected code.
|
||||
xmap <leader>f <Plug>(coc-format-selected)
|
||||
nmap <leader>f <Plug>(coc-format-selected)
|
||||
|
||||
augroup mygroup
|
||||
autocmd!
|
||||
" Setup formatexpr specified filetype(s).
|
||||
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
|
||||
" Update signature help on jump placeholder.
|
||||
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
|
||||
augroup end
|
||||
|
||||
" Applying codeAction to the selected region.
|
||||
" Example: `<leader>aap` for current paragraph
|
||||
xmap <leader>a <Plug>(coc-codeaction-selected)
|
||||
nmap <leader>a <Plug>(coc-codeaction-selected)
|
||||
|
||||
" Remap keys for applying codeAction to the current buffer.
|
||||
nmap <leader>ac <Plug>(coc-codeaction)
|
||||
" Apply AutoFix to problem on the current line.
|
||||
nmap <leader>qf <Plug>(coc-fix-current)
|
||||
|
||||
" Map function and class text objects
|
||||
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
|
||||
xmap if <Plug>(coc-funcobj-i)
|
||||
omap if <Plug>(coc-funcobj-i)
|
||||
xmap af <Plug>(coc-funcobj-a)
|
||||
omap af <Plug>(coc-funcobj-a)
|
||||
xmap ic <Plug>(coc-classobj-i)
|
||||
omap ic <Plug>(coc-classobj-i)
|
||||
xmap ac <Plug>(coc-classobj-a)
|
||||
omap ac <Plug>(coc-classobj-a)
|
||||
|
||||
" Remap <C-f> and <C-b> for scroll float windows/popups.
|
||||
if has('nvim-0.4.0') || has('patch-8.2.0750')
|
||||
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
|
||||
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
|
||||
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
|
||||
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll0)\<cr>" : "\<Left>"
|
||||
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
|
||||
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
|
||||
endif
|
||||
|
||||
" Use CTRL-S for selections ranges.
|
||||
" Requires 'textDocument/selectionRange' support of language server.
|
||||
nmap <silent> <C-s> <Plug>(coc-range-select)
|
||||
xmap <silent> <C-s> <Plug>(coc-range-select)
|
||||
|
||||
" Add `:Format` command to format current buffer.
|
||||
command! -nargs=0 Format :call CocAction('format')
|
||||
|
||||
" Add `:Fold` command to fold current buffer.
|
||||
command! -nargs=? Fold :call CocAction('fold', <f-args>)
|
||||
|
||||
" Add `:OR` command for organize imports of the current buffer.
|
||||
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
|
||||
|
||||
" Add (Neo)Vim's native statusline support.
|
||||
" NOTE: Please see `:h coc-status` for integrations with external plugins that
|
||||
" provide custom statusline: lightline.vim, vim-airline.
|
||||
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
|
||||
|
||||
" Mappings for CoCList
|
||||
" Show all diagnostics.
|
||||
nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
|
||||
" Manage extensions.
|
||||
nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
|
||||
" Show commands.
|
||||
nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
|
||||
" Find symbol of current document.
|
||||
nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
|
||||
" Search workspace symbols.
|
||||
nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
|
||||
" Do default action for next item.
|
||||
nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
|
||||
" Do default action for previous item.
|
||||
nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>
|
||||
" Resume latest coc list.
|
||||
nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>(
|
|
@ -0,0 +1,29 @@
|
|||
vsync = true;
|
||||
blur: {
|
||||
method = "dual_kawase";
|
||||
strength = 4.0;
|
||||
deviation = 1.0;
|
||||
kernel = "11x11gaussian";
|
||||
}
|
||||
|
||||
blur-background = false;
|
||||
blur-background-frame = true;
|
||||
blur-background-fixed = true;
|
||||
# blur-kern = "3x3box";
|
||||
|
||||
corner-radius = 4.0;
|
||||
rounded-corners-exclude = [
|
||||
"class_g = 'i3-frame'",
|
||||
"class_g = 'Polybar'",
|
||||
"class_g = 'MPV'",
|
||||
"_NET_WM_STATE_FULLSCREEN:c",
|
||||
]
|
||||
blur-background-exclude = [
|
||||
"class_g = 'slop'",
|
||||
"class_g = 'Firefox' && argb",
|
||||
"_GTK_FRAME_EXTENTS@:c",
|
||||
];
|
||||
opacity-rule = [
|
||||
"90:class_g = 'dmenu'",
|
||||
"85:class_g = 'xmenu'",
|
||||
];
|
|
@ -0,0 +1,163 @@
|
|||
;=====================================================================
|
||||
;
|
||||
;
|
||||
; ███████╗██╗ ██╗███████╗███████╗██╗ ██╗██████╗ █████╗ ██████╗
|
||||
; ██╔════╝██║ ██║╚══███╔╝╚══███╔╝╚██╗ ██╔╝██╔══██╗██╔══██╗██╔══██╗
|
||||
; █████╗ ██║ ██║ ███╔╝ ███╔╝ ╚████╔╝ ██████╔╝███████║██████╔╝
|
||||
; ██╔══╝ ██║ ██║ ███╔╝ ███╔╝ ╚██╔╝ ██╔══██╗██╔══██║██╔══██╗
|
||||
; ██║ ╚██████╔╝███████╗███████╗ ██║ ██████╔╝██║ ██║██║ ██║
|
||||
; ╚═╝ ╚═════╝ ╚══════╝╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝
|
||||
;
|
||||
;
|
||||
; To learn more about how to configure Polybar
|
||||
; go to https://github.com/jaagr/polybar
|
||||
;
|
||||
; The README contains alot of information
|
||||
;
|
||||
;===================================================================
|
||||
|
||||
[colors]
|
||||
background = #E61a181a
|
||||
background-alt = #E6212121
|
||||
foreground = #dfdfdf
|
||||
foreground-alt = #a5a5a5
|
||||
|
||||
[bar/fuzzybar]
|
||||
monitor = DP-2
|
||||
|
||||
width = 100%
|
||||
height = 30
|
||||
|
||||
fixed-center = true
|
||||
bottom = false
|
||||
|
||||
background = ${colors.background}
|
||||
foreground = ${colors.foreground}
|
||||
|
||||
border-size = 0
|
||||
border-color = #09000000
|
||||
|
||||
padding-left = 2
|
||||
padding-right = 2
|
||||
|
||||
module-margin-left = 1
|
||||
module-margin-right = 1
|
||||
|
||||
font-0 = SF Pro Display:weight=SemiBold:pixelsize=12.5;3
|
||||
font-1 = DejaVuSansMono Nerd Font:pixelsize=13;3
|
||||
;https://dejavu-fonts.github.io/
|
||||
;https://www.nerdfonts.com/font-downloads
|
||||
font-2 = forkawesome:pixelsize=13;3
|
||||
;https://forkaweso.me/Fork-Awesome/
|
||||
font-3 = Source Han Sans JP VF:pixelsize=13;3
|
||||
|
||||
modules-left = title
|
||||
modules-center = swatch
|
||||
modules-right = network soundSwitch soundIcon pulseaudio newpower
|
||||
|
||||
tray-position = right
|
||||
tray-padding = 2
|
||||
|
||||
[module/datetime]
|
||||
type=internal/date
|
||||
interval = 5
|
||||
|
||||
date = %a %b %d
|
||||
|
||||
time = %l:%M%P
|
||||
|
||||
label = %date% %time%
|
||||
|
||||
;click-left = ~/Documents/scripts/dzencal.sh
|
||||
click-left = dcal
|
||||
|
||||
[module/swatch]
|
||||
type=custom/script
|
||||
exec = bash ~/Documents/scripts/bartime.sh
|
||||
tail = true
|
||||
format = <label>
|
||||
label = %output%
|
||||
|
||||
click-left = dcal -x -1192 -y 40 -bg "#181819" -bd "#e2e2e3" -cf "#e2e2e3" -of "#7f8490" -tf "#e7c664" -hf "#e2e2e3" -k
|
||||
|
||||
[module/soundSwitch]
|
||||
type=custom/text
|
||||
|
||||
content=""
|
||||
click-left = ~/Documents/scripts/soundSwitch.sh
|
||||
|
||||
[module/soundIcon]
|
||||
type=custom/script
|
||||
exec = bash ~/Documents/scripts/soundSwitchIcon.sh
|
||||
|
||||
interval = 0
|
||||
label=%output%
|
||||
|
||||
[module/pulseaudio]
|
||||
type = internal/pulseaudio
|
||||
format-volume = <ramp-volume> <label-volume> <bar-volume>
|
||||
ramp-volume-0 = 奄
|
||||
ramp-volume-1 = 奔
|
||||
ramp-volume-2 = 墳
|
||||
ramp-volume-3 = 墳
|
||||
ramp-volume-4 = 墳
|
||||
label-volume = %percentage%%
|
||||
labelvolume-foreground = ${root.foreground}
|
||||
ramp-volume-padding = 1
|
||||
label-muted = 婢 muted %{F#b70e17}─────────%{F-}
|
||||
label-muted-foreground = #ffffff
|
||||
|
||||
bar-volume-width = 10
|
||||
bar-volume-foreground-0 = #55aa55
|
||||
bar-volume-foreground-1 = #55aa55
|
||||
bar-volume-foreground-2 = #55aa55
|
||||
bar-volume-foreground-3 = #55aa55
|
||||
bar-volume-foreground-4 = #55aa55
|
||||
bar-volume-foreground-5 = #f5a70a
|
||||
bar-volume-foreground-6 = #ff5555
|
||||
bar-volume-gradient = false
|
||||
bar-volume-indicator = |
|
||||
bar-volume-indicator-font = 0
|
||||
bar-volume-fill = ─
|
||||
bar-volume-fill-font = 0
|
||||
bar-volume-empty = ─
|
||||
bar-volume-empty-font = 0
|
||||
bar-volume-empty-foreground = ${colors.foreground-alt}
|
||||
|
||||
interval = 2
|
||||
|
||||
[module/title]
|
||||
type=internal/xwindow
|
||||
|
||||
format = <label>
|
||||
|
||||
label = %title%
|
||||
label-maxlen=50
|
||||
|
||||
label-empty =
|
||||
label-empty-foreground = ${colors.background}
|
||||
|
||||
[module/network]
|
||||
type = internal/network
|
||||
interface = enp0s31f6
|
||||
unknown-as-up = true
|
||||
|
||||
interval = 5.0
|
||||
upspeed-min = 0
|
||||
downspeed-min = 0
|
||||
|
||||
format-connected = <label-connected>
|
||||
label-connected = %downspeed% %upspeed%
|
||||
|
||||
format-disconnected = <label-disconnected>
|
||||
label-disconnected = "no network"
|
||||
|
||||
[module/newpower]
|
||||
type=custom/text
|
||||
|
||||
content =
|
||||
|
||||
click-left =~/Documents/scripts/xpowermenu.sh
|
||||
|
||||
[settings]
|
||||
screenchange-reload = true
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Terminate already running bar instances
|
||||
pkill polybar
|
||||
|
||||
# Wait until the processes have been shut down
|
||||
while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done
|
||||
|
||||
# Launch Polybar, using default config location ~/.config/polybar/config
|
||||
polybar --config=~/.config/polybar/fuzzy.conf fuzzybar &
|
||||
|
||||
echo "Polybar launched..."
|
|
@ -0,0 +1,70 @@
|
|||
; Global settings for redshift
|
||||
[redshift]
|
||||
; Set the day and night screen temperatures
|
||||
temp-day=6500
|
||||
temp-night=3700
|
||||
|
||||
; Disable the smooth fade between temperatures when Redshift starts and stops.
|
||||
; 0 will cause an immediate change between screen temperatures.
|
||||
; 1 will gradually apply the new screen temperature over a couple of seconds.
|
||||
fade=1
|
||||
|
||||
; Solar elevation thresholds.
|
||||
; By default, Redshift will use the current elevation of the sun to determine
|
||||
; whether it is daytime, night or in transition (dawn/dusk). When the sun is
|
||||
; above the degrees specified with elevation-high it is considered daytime and
|
||||
; below elevation-low it is considered night.
|
||||
; elevation-high=8.4
|
||||
; elevation-low=-7.8
|
||||
|
||||
; Custom dawn/dusk intervals.
|
||||
; Instead of using the solar elevation, the time intervals of dawn and dusk
|
||||
; can be specified manually. The times must be specified as HH:MM in 24-hour
|
||||
; format.
|
||||
;dawn-time=6:00-7:45
|
||||
;dusk-time=18:35-20:15
|
||||
|
||||
; Set the screen brightness. Default is 1.0.
|
||||
;brightness=0.9
|
||||
; It is also possible to use different settings for day and night
|
||||
; since version 1.8.
|
||||
;brightness-day=0.7
|
||||
;brightness-night=0.4
|
||||
; Set the screen gamma (for all colors, or each color channel
|
||||
; individually)
|
||||
gamma=0.8
|
||||
;gamma=0.8:0.7:0.8
|
||||
; This can also be set individually for day and night since
|
||||
; version 1.10.
|
||||
;gamma-day=0.8:0.7:0.8
|
||||
;gamma-night=0.6
|
||||
|
||||
; Set the location-provider: 'geoclue2', 'manual'
|
||||
; type 'redshift -l list' to see possible values.
|
||||
; The location provider settings are in a different section.
|
||||
location-provider=manual
|
||||
|
||||
; Set the adjustment-method: 'randr', 'vidmode'
|
||||
; type 'redshift -m list' to see all possible values.
|
||||
; 'randr' is the preferred method, 'vidmode' is an older API.
|
||||
; but works in some cases when 'randr' does not.
|
||||
; The adjustment method settings are in a different section.
|
||||
adjustment-method=randr
|
||||
|
||||
; Configuration of the location-provider:
|
||||
; type 'redshift -l PROVIDER:help' to see the settings.
|
||||
; ex: 'redshift -l manual:help'
|
||||
; Keep in mind that longitudes west of Greenwich (e.g. the Americas)
|
||||
; are negative numbers.
|
||||
[manual]
|
||||
lat=49.9
|
||||
lon=-97.14
|
||||
|
||||
; Configuration of the adjustment-method
|
||||
; type 'redshift -m METHOD:help' to see the settings.
|
||||
; ex: 'redshift -m randr:help'
|
||||
; In this example, randr is configured to adjust only screen 0.
|
||||
; Note that the numbering starts from 0, so this is actually the first screen.
|
||||
; If this option is not specified, Redshift will try to adjust _all_ screens.
|
||||
;[randr]
|
||||
;screen=0
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 84f050913da777c50059cb37654e71e39b282aa4
|
|
@ -0,0 +1,32 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Jeremy's Homepage :)</title>
|
||||
<link rel=stylesheet type=text/css href=style.css>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Jeremy's Homepage :)</h1>
|
||||
<form id="search_form" method="get" action="https://duckduckgo.com/">
|
||||
<input type="search" name="q" placeholder="search" aria-label="search" autofocus />
|
||||
<button type="submit" label="search!" aria-label="search!">Duck It!</button>
|
||||
</form>
|
||||
</header>
|
||||
|
||||
<section id="quicklinks">
|
||||
<ul>
|
||||
<li><a href="https://holodex.net">Holodex</a></li>
|
||||
<li><a href="https://github.com"> Github</a></li>
|
||||
<li><a href="https://wiki.archlinux.org">Arch Wiki</a></li>
|
||||
<li><a href="https://wiki.gentoo.org">Gentoo Wiki</a></li>
|
||||
<li><a href="https://notabug.org">NotABug</a></li>
|
||||
<li><a href="https://jelly.fuzzy.click">Jellyfin</a></li>
|
||||
<li><a href="https://music.fuzzy.click">Navidrome</a></li>
|
||||
<li><a href="https://piped.kavin.rocks/feed">Piped</a></li>
|
||||
<li><a href="https://nyaa.si">Nyaa</a></li>
|
||||
</ul>
|
||||
<img src="800mel.jpg">
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
After Width: | Height: | Size: 844 KiB |
|
@ -0,0 +1,155 @@
|
|||
html{
|
||||
font-family: monospace, sans-serif;
|
||||
}
|
||||
body{
|
||||
background-color:#222222;
|
||||
color: #d3d3d3;
|
||||
}
|
||||
|
||||
h1, pre, form{
|
||||
text-align: center;
|
||||
margin: 50px 0px 80px 0px;
|
||||
border-style: none;
|
||||
|
||||
}
|
||||
form{
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: center;
|
||||
|
||||
}
|
||||
input{
|
||||
-webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
appearance: none;
|
||||
height: 2vw;
|
||||
width: 18vw;
|
||||
margin-right: 0px;
|
||||
border-style: none;
|
||||
padding-left: 10px;
|
||||
border-top-left-radius: 6px;
|
||||
border-bottom-left-radius: 6px;
|
||||
}
|
||||
input:focus{
|
||||
outline: none;
|
||||
}
|
||||
button{
|
||||
height: 2vw;
|
||||
width: 5vw;
|
||||
border-style: none;
|
||||
border-top-right-radius: 6px;
|
||||
border-bottom-right-radius: 6px;
|
||||
background-color: #8f6f8f;
|
||||
}
|
||||
button:active{
|
||||
background-color: #8181a6;
|
||||
}
|
||||
ul{
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: flex-start;
|
||||
list-style-type: none;
|
||||
font-size: 1.1em;
|
||||
padding-left: 0;
|
||||
}
|
||||
li{
|
||||
color: #d3d3d3;
|
||||
margin: 0px 20px 0 20px;
|
||||
text-align: center;
|
||||
}
|
||||
a{
|
||||
color: #d3d3d3;
|
||||
}
|
||||
a:visited{
|
||||
color: #d3d3d3;
|
||||
}
|
||||
a:hover{
|
||||
color: darkgray;
|
||||
|
||||
}
|
||||
a:focus{
|
||||
color: darkgray;
|
||||
}
|
||||
a:active{
|
||||
color: gray;
|
||||
}
|
||||
img{
|
||||
display: block;
|
||||
margin: 120px auto 0 auto;
|
||||
object-fit: cover;
|
||||
object-position: center;
|
||||
height: 800px;
|
||||
width: 800px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
@media only screen and (max-width: 1300px){
|
||||
input, button{
|
||||
height: 2.5vw;
|
||||
}
|
||||
button{
|
||||
width:6vw;
|
||||
}
|
||||
|
||||
}
|
||||
@media only screen and (max-width: 1000px){
|
||||
h1{
|
||||
font-size: 4em;
|
||||
}
|
||||
form{
|
||||
margin-top: 150px;
|
||||
font-family: monospace, sans-serif;
|
||||
}
|
||||
input{
|
||||
width: 70vw;
|
||||
height: 10vw;
|
||||
font-size: 2.5em;
|
||||
border-bottom-right-radius: 0;
|
||||
border-top-right-radius: 0;
|
||||
}
|
||||
button{
|
||||
width: 20vw;
|
||||
height: 10vw;
|
||||
font-size: 2.5em;
|
||||
font-weight: normal;
|
||||
padding: 0;
|
||||
color: #222;
|
||||
background-color: #8f6f8f;
|
||||
}
|
||||
button:active{
|
||||
color: #222;
|
||||
background-color: #8181a6;
|
||||
}
|
||||
ul{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
align-content: center;
|
||||
font-size: 4em;
|
||||
padding-left: 0;
|
||||
}
|
||||
li{
|
||||
margin: 24px;
|
||||
padding: 10px 10px 10px 10px;
|
||||
border-radius: 6px;
|
||||
text-align: center;
|
||||
background-color: darkgray;
|
||||
color: #222;
|
||||
}
|
||||
a{
|
||||
text-decoration: none;
|
||||
color: #222 !important;
|
||||
}
|
||||
a:visited{
|
||||
color: #222;
|
||||
}
|
||||
li:active, a:active{
|
||||
color: #222;
|
||||
background-color: gray;
|
||||
|
||||
}
|
||||
img{
|
||||
margin-bottom: 100px;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,167 @@
|
|||
CHANGELOG
|
||||
|
||||
4.5.5 (2021-04-11)
|
||||
• Added support for mouse scrolling (#26).
|
||||
• Changed Makefile; simplify ${DESTDIR} (#25).
|
||||
• Changed README; removed demo.gif.
|
||||
• Fixed LICENSE.
|
||||
• Fixed segfault if a sub-menu is added to a separator (#29).
|
||||
|
||||
4.5.4 (2021-01-09)
|
||||
• Fixed ESC key.
|
||||
|
||||
4.5.3 (2021-01-09)
|
||||
• Fixed missing lines in xmenu.c.
|
||||
|
||||
4.5.2 (2021-01-09)
|
||||
• Fixed missing line in xmenu.c.
|
||||
|
||||
4.5.1 (2021-01-09)
|
||||
• Fixed SHIFT key; it cleared the selection, now it doesn't.
|
||||
|
||||
4.5.0 (2021-01-08).
|
||||
• Added type-to-select feature (#21).
|
||||
• Added support for setting the text alignment.
|
||||
• Added -r option to disable right mouse button (#17).
|
||||
• Added CHANGELOG.
|
||||
• Changed order of parsing of options.
|
||||
• Fixed config.mk formatting (#18, #23).
|
||||
• Fixed README's list of header dependencies (#24).
|
||||
|
||||
4.4.1 (2020-10-18).
|
||||
• Fixed Makefile by removing -D flag of install(1) and making it portable.
|
||||
• Fixed menu placement when pointer is at the very top of the menu (#16).
|
||||
|
||||
4.4.0 (2020-09-27).
|
||||
• Added support for custom key bindings in config.h.
|
||||
• Added support for 1 to 9 keys for moving (#14).
|
||||
• Added support for Home and End keys for moving.
|
||||
• Fixed code to free stuff earlier, when they're no longer used.
|
||||
|
||||
4.3.2 (2020-09-13).
|
||||
• Changed license.
|
||||
• Fixed initmonitor() routine to free unused data.
|
||||
|
||||
4.3.1 (2020-08-12).
|
||||
• Added warning messages for unsuccessful icon loading.
|
||||
• Changed wording in some error messages.
|
||||
• Changed README to add reference to xdg-xmenu, by OliverLew.
|
||||
|
||||
4.3.0 (2020-08-01).
|
||||
• Added ability to search the system for font containing character.
|
||||
• Changed drawtext() routine (split part of it into getfontucode()).
|
||||
• Fixed getfontucode() by adding sanity check tests.
|
||||
• Removed the -f option.
|
||||
|
||||
4.2.0 (2020-07-31).
|
||||
• Added the -f option.
|
||||
• Changed xmenu.c to use BETWEEN macro.
|
||||
• Fixed fallback position.
|
||||
• Fixed manpage; simplifying description of -i option.
|
||||
• Fixed xmenu.h; removed unused elements in struct Item.
|
||||
• Fixed cleanup function to free fonts.
|
||||
|
||||
4.1.4 (2020-07-30).
|
||||
• Added detection of icons in menus.
|
||||
• Fixed y position of child menus.
|
||||
• Fixed placement in some window managers when using -w.
|
||||
• Fixed README to add reference to added features.
|
||||
|
||||
4.1.3 (2020-07-30).
|
||||
• Fixed xmenu.c and xmenu.h: removed redundant variables.
|
||||
|
||||
4.1.2 (2020-07-29).
|
||||
• Fixed computation of the text y position.
|
||||
|
||||
4.1.1 (2020-07-29).
|
||||
• Changed README to README.md (#9).
|
||||
• Fixed config.mk to load -lXinerama.
|
||||
|
||||
4.1.0 (2020-07-29).
|
||||
• Added Xinerama support (#8).
|
||||
|
||||
4.0.2 (2020-07-29).
|
||||
• Fixed menu drawing; menus are now drawed on demand.
|
||||
|
||||
4.0.1 (2020-07-29).
|
||||
• Fixed calculation of text width.
|
||||
|
||||
4.0.0 (2020-07-29).
|
||||
• Added support for fallback fonts.
|
||||
• Changed license.
|
||||
|
||||
3.4.1 (2020-07-28).
|
||||
• Fixed performance issue with many icons (#7).
|
||||
|
||||
3.4.0 (2020-07-23).
|
||||
• Added the -p option (to set the root menu position).
|
||||
|
||||
3.3.0 (2020-07-15).
|
||||
• Added the -i option (to disable icons).
|
||||
• Changed code for computing widths and x position.
|
||||
|
||||
3.2.1 (2020-06-29).
|
||||
• Fixed manpage; add reference to added features in the manual.
|
||||
|
||||
3.2.0 (2020-06-29).
|
||||
• Added support for EWMH properties.
|
||||
• Added support for gaps between menus (#3).
|
||||
• Changed README to add reference to xclickroot(1).
|
||||
• Changed how configuration is done; added a config structure.
|
||||
• Fixed missing #include.
|
||||
• Fixed missing type cast.
|
||||
|
||||
3.1.1 (2020-06-20).
|
||||
• Changed how height is calculated; now it's set directly.
|
||||
• Fix Makefile; removed slashes after DESTDIR (#2).
|
||||
|
||||
3.1.0 (2020-06-05).
|
||||
• Fixed several typos and mismatches between code, manual and README.
|
||||
|
||||
3.0.0 (2020-05-31).
|
||||
• Added support for icons.
|
||||
• Added some icons samples (in ./icons/).
|
||||
• Added demo gif.
|
||||
• Added the -w option (again).
|
||||
• Changed Makefile; using -D option of install(1).
|
||||
• Changed input parsing to use stdlib functions rather than get byte-by-byte.
|
||||
• Changed xmenu.c; making global variables local.
|
||||
• Changed calcmenu() routine (split into three routines).
|
||||
• Fixed segfault in case of empty input.
|
||||
• Fixed calls to strdup(3); called twice only when label and output differs.
|
||||
• Fixed menu position calculation (it didn't take borders into account).
|
||||
• Fixed manpage; updated to new features.
|
||||
• Fixed xmenu.c; removed unused code.
|
||||
• Fixed cleanup routine; freeing allocated stuff.
|
||||
|
||||
2.0.0 (2020-05-27).
|
||||
• Changed xmenu.c; making global variables local.
|
||||
• Changed README; including more information.
|
||||
• Changed getmenuitem() routine (split into getmenu() and getitem()).
|
||||
• Changed drawing routines in xmenu.c (drawseparator() and drawitem()).
|
||||
• Fixed xmenu.c; removed unused code.
|
||||
• Removed the -w option.
|
||||
|
||||
1.0.0 (2020-05-19).
|
||||
• Added keyboard navigation.
|
||||
• Added manpage.
|
||||
• Added support for X resources.
|
||||
• Added XFT support (antialiased fonts).
|
||||
• Added setting of WM_CLASS property.
|
||||
• Added recalcmenu() to recalculate menu position when -w is used.
|
||||
• Added support for WM_DELETE_WINDOW property (ability to close window).
|
||||
• Changed xmenu.sh script to pipe into sh(1).
|
||||
• Changed color scheme (stolen from firefox's context menu).
|
||||
• Changed algorithm for remapping menus (find lowest common ancestor menu).
|
||||
• Changed computing of menu width to be based on font.
|
||||
• Changed triangle size; now it's smaller.
|
||||
• Changed xmenu.sh; it now supposes that xmenu is installed.
|
||||
• Fixed README; it was a copy of dwm's.
|
||||
• Fixed Makefile; make install didn't install the manpage.
|
||||
• Fixed pointer and keyboard grabbing race condition.
|
||||
• Fixed order of function calls (grab keyboard after reading input).
|
||||
|
||||
0.5.0 (2020-05-16).
|
||||
• Added menu separators (lines without labels in the input).
|
||||
• Added double buffering, rather than drawing directly on windows.
|
||||
• Added -w option.
|
|
@ -0,0 +1,37 @@
|
|||
MIT/X Consortium License
|
||||
|
||||
© 2020 Phillip Bushee <phillbush@cock.li>
|
||||
|
||||
thingmenu:
|
||||
© 2011 Christoph Lohmann <20h@r-36.net>
|
||||
© 2011 Stephen Paul Weber <singpolyma@singpolyma.net>
|
||||
|
||||
dmenu:
|
||||
© 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,32 @@
|
|||
include config.mk
|
||||
|
||||
bindir = ${DESTDIR}${PREFIX}
|
||||
mandir = ${DESTDIR}${MANPREFIX}
|
||||
|
||||
SRCS = ${PROG}.c
|
||||
OBJS = ${SRCS:.c=.o}
|
||||
|
||||
all: ${PROG}
|
||||
|
||||
${PROG}: ${OBJS}
|
||||
${CC} -o $@ ${OBJS} ${LDFLAGS}
|
||||
|
||||
${OBJS}: config.h ${PROG}.h
|
||||
|
||||
.c.o:
|
||||
${CC} ${CFLAGS} -c $<
|
||||
|
||||
clean:
|
||||
-rm ${OBJS} ${PROG}
|
||||
|
||||
install: all
|
||||
mkdir -p ${bindir}/bin
|
||||
install -m 755 ${PROG} ${bindir}/bin/${PROG}
|
||||
mkdir -p ${mandir}/man1
|
||||
install -m 644 ${PROG}.1 ${mandir}/man1/${PROG}.1
|
||||
|
||||
uninstall:
|
||||
rm -f ${bindir}/bin/${PROG}
|
||||
rm -f ${mandir}/man1/${PROG}.1
|
||||
|
||||
.PHONY: all clean install uninstall
|
|
@ -0,0 +1,88 @@
|
|||
# XMenu
|
||||
|
||||
<p align="center">
|
||||
<img src="https://user-images.githubusercontent.com/63266536/114306062-ffb67000-9ab0-11eb-9a10-be30eadc68b4.gif", title="demo"/>
|
||||
</p>
|
||||
|
||||
XMenu is a menu utility for X.
|
||||
XMenu receives a menu specification in stdin, shows a menu for the user
|
||||
to select one of the options, and outputs the option selected to stdout.
|
||||
XMenu can be controlled both via mouse and via keyboard.
|
||||
|
||||
In order to generate a menu of applications based on .desktop entries,
|
||||
as specified by XDG, checkout [xdg-xmenu](https://github.com/OliverLew/xdg-xmenu)
|
||||
by [OliverLew](https://github.com/OliverLew).
|
||||
|
||||
Check out my other project, [xclickroot](https://github.com/phillbush/xclickroot) for an application that can
|
||||
spawn xmenu by right clicking on the root window (i.e. on the desktop).
|
||||
|
||||
|
||||
## Features
|
||||
|
||||
XMenu comes with the following features:
|
||||
|
||||
* XMenu reads something in and prints something out, the UNIX way.
|
||||
* Submenus (some menu entries can spawn another menu).
|
||||
* Separators (menu entries can be separated by a line).
|
||||
* Icons (menu entries can be preceded by an icon image).
|
||||
* X resources support (you don't need to recompile xmenu for configuring it).
|
||||
* Multi-head (xmenu supports multiple monitors by using Xinerama).
|
||||
* Type-to-select (you can select an item by typing part of its name).
|
||||
|
||||
|
||||
## Files
|
||||
|
||||
The files are:
|
||||
|
||||
* `./README`: This file.
|
||||
* `./Makefile`: The makefile.
|
||||
* `./config.h`: The hardcoded default configuration for XMenu.
|
||||
* `./config.mk`: The setup for the makefile.
|
||||
* `./demo.gif`: A gif demonstrating how XMenu works.
|
||||
* `./xmenu.1`: The manual file (man page) for XMenu.
|
||||
* `./xmenu.c`: The source code of XMenu.
|
||||
* `./xmenu.sh`: A sample script illustrating how to use XMenu.
|
||||
* `./icons/`: Icons for the sample script
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
First, edit `./config.mk` to match your local setup.
|
||||
|
||||
In order to build XMenu you need the `Imlib2`, `Xlib`, `Xinerama` and `Xft` header files.
|
||||
The default configuration for XMenu is specified in the file `config.h`,
|
||||
you can edit it, but most configuration can be changed at runtime via
|
||||
X resources. Enter the following command to build XMenu. This command
|
||||
creates the binary file `./xmenu`.
|
||||
|
||||
make
|
||||
|
||||
By default, XMenu is installed into the `/usr/local` prefix. Enter the
|
||||
following command to install XMenu (if necessary as root). This command
|
||||
installs the binary file `./xmenu` into the `${PREFIX}/bin/` directory, and
|
||||
the manual file `./xmenu.1` into `${MANPREFIX}/man1/` directory.
|
||||
|
||||
make install
|
||||
|
||||
|
||||
## Running XMenu
|
||||
|
||||
XMenu receives as input a menu specification where each line is a menu
|
||||
entry. Each line can be indented with tabs to represent nested menus.
|
||||
Each line is made out of a label and a command separated by any number
|
||||
of tabs. Lines without labels are menu separators.
|
||||
|
||||
See the script `./xmenu.sh` for an example of how to use XMenu to draw a
|
||||
simple menu with submenus and separators. The file `./demo.gif` shows how
|
||||
the menu generated by that script looks like.
|
||||
|
||||
Read the [manual](https://github.com/phillbush/xmenu/wiki) for more information on running XMenu.
|
||||
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
* [thingmenu](https://github.com/singpolyma/thingmenu) for being the base
|
||||
for xmenu's code. However, xmenu evolved enough that it no longer resembles
|
||||
thingmenu at all.
|
||||
* [dmenu](https://tools.suckless.org/dmenu/) for inspiring the stdin-to-stdout
|
||||
interface, and being base for drawing routines and input method code.
|
|
@ -0,0 +1,62 @@
|
|||
static struct Config config = {
|
||||
/* font, separate different fonts with comma */
|
||||
.font = "SF Pro Display:size=13,DejaVuSansMono Nerd Font:size=11",
|
||||
|
||||
/* colors */
|
||||
.background_color = "#111111",
|
||||
.foreground_color = "#d3d3d3",
|
||||
.selbackground_color = "#8f6f8f",
|
||||
.selforeground_color = "#111111",
|
||||
.separator_color = "#d3d3d3",
|
||||
.border_color = "#d3d3d3",
|
||||
|
||||
/* sizes in pixels */
|
||||
.width_pixels = 130, /* minimum width of a menu */
|
||||
.height_pixels = 30, /* height of a single menu item */
|
||||
.border_pixels = 0, /* menu border */
|
||||
.separator_pixels = 3, /* space around separator */
|
||||
.gap_pixels = 0, /* gap between menus */
|
||||
|
||||
/* text alignment, set to LeftAlignment, CenterAlignment or RightAlignment */
|
||||
.alignment = LeftAlignment,
|
||||
|
||||
/*
|
||||
* The variables below cannot be set by X resources.
|
||||
* Their values must be less than .height_pixels.
|
||||
*/
|
||||
|
||||
/* geometry of the right-pointing isoceles triangle for submenus */
|
||||
.triangle_width = 3,
|
||||
.triangle_height = 7,
|
||||
|
||||
/* the icon size is equal to .height_pixels - .iconpadding * 2 */
|
||||
.iconpadding = 2,
|
||||
|
||||
/* area around the icon, the triangle and the separator */
|
||||
.horzpadding = 8,
|
||||
};
|
||||
|
||||
/*
|
||||
* KEYBINDINGS
|
||||
*
|
||||
* Look at your /usr/include/X11/keysymdef.h (or the equivalent file
|
||||
* in your system) for a list of key symbol constants, and change the
|
||||
* macros below accordingly. All key symbol constants begin with the
|
||||
* prefix XK_.
|
||||
*
|
||||
* For example, to use vim-like key bindings, set KEYSYMLEFT to XK_h,
|
||||
* KEYSYMDOWN to XK_j, KEYSYMUP to XK_k, etc.
|
||||
*
|
||||
* Note that the regular keys like ArrowUp, ArrowDown, Tab, Home, etc
|
||||
* will ALWAYS work, so you do not need to set them.
|
||||
*
|
||||
* If you do not want to set a key binding, keep it with the value of
|
||||
* XK_VoidSymbol
|
||||
*/
|
||||
#define KSYMFIRST XK_VoidSymbol /* select first item */
|
||||
#define KSYMLAST XK_VoidSymbol /* select last item */
|
||||
#define KSYMUP XK_VoidSymbol /* select previous item */
|
||||
#define KSYMDOWN XK_VoidSymbol /* select next item */
|
||||
#define KSYMLEFT XK_VoidSymbol /* close current menu */
|
||||
#define KSYMRIGHT XK_VoidSymbol /* enter selected item */
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
# program name
|
||||
PROG = xmenu
|
||||
|
||||
# paths
|
||||
PREFIX ?= /usr/local
|
||||
MANPREFIX ?= ${PREFIX}/share/man
|
||||
|
||||
LOCALINC ?= /usr/local/include
|
||||
LOCALLIB ?= /usr/local/lib
|
||||
|
||||
# SHELL variable (mainly for non-GNU make)
|
||||
SHELL ?= /bin/sh
|
||||
|
||||
X11INC ?= /usr/X11R6/include
|
||||
X11LIB ?= /usr/X11R6/lib
|
||||
|
||||
FREETYPEINC ?= /usr/include/freetype2
|
||||
# OpenBSD (uncomment)
|
||||
#FREETYPEINC = ${X11INC}/freetype2
|
||||
|
||||
# includes and libs
|
||||
INCS := -I${LOCALINC} -I${X11INC} -I${FREETYPEINC}
|
||||
LIBS := -L${LOCALLIB} -L${X11LIB} -lfontconfig -lXft -lX11 -lXinerama -lImlib2
|
||||
|
||||
# flags
|
||||
CPPFLAGS :=
|
||||
CFLAGS := -Wall -Wextra ${INCS} ${CPPFLAGS}
|
||||
LDFLAGS := ${LIBS}
|
||||
|
||||
# compiler and linker
|
||||
CC = cc
|
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
Binary file not shown.
After Width: | Height: | Size: 4.8 KiB |
Binary file not shown.
|
@ -0,0 +1,221 @@
|
|||
.TH XMENU 1
|
||||
.SH NAME
|
||||
xmenu \- menu utility for X
|
||||
.SH SYNOPSIS
|
||||
.B xmenu
|
||||
.RB [ \-irw ]
|
||||
.RB [ -p
|
||||
.IR position ]
|
||||
.RI [ title ]
|
||||
.SH DESCRIPTION
|
||||
.B xmenu
|
||||
is a menu for X,
|
||||
it reads a list of newline-separated items from stdin,
|
||||
shows a menu for the user to select one of the items,
|
||||
and outputs the item selected to stdout.
|
||||
.PP
|
||||
The options are as follows:
|
||||
.TP
|
||||
.B -i
|
||||
Disable icons.
|
||||
This makes xmenu loading faster when not using icons.
|
||||
.TP
|
||||
.BI -p " position"
|
||||
Set the position to spawn xmenu.
|
||||
Without this option, xmenu spawns next to the cursor.
|
||||
.I position
|
||||
is a string of the form
|
||||
.BR INTxINT[:MONITOR] ,
|
||||
where the first INT is the x position and the second INT is the y position.
|
||||
The monitor part between brackets is optional.
|
||||
.B MONITOR
|
||||
can be a number from 0 to the number of monitors minus 1;
|
||||
or it can be a string like
|
||||
.B current
|
||||
or
|
||||
.BR cursor .
|
||||
If present, the monitor specifies that the position is relative to the upper left corner
|
||||
of that monitor.
|
||||
If
|
||||
.B monitor
|
||||
is
|
||||
.B current
|
||||
or
|
||||
.BR cursor ,
|
||||
the monitor to be used is that where the cursor is in.
|
||||
For example,
|
||||
.B -p 0x0:cursor
|
||||
specifies that
|
||||
.B xmenu
|
||||
must spawn at the position 0x0 of the monitor where the cursor is in.
|
||||
And
|
||||
.B -p 100x500:0
|
||||
specifies that
|
||||
.B xmenu
|
||||
must spawn at the position 100x500 of the monitor 0.
|
||||
.TP
|
||||
.B -r
|
||||
If this option is set, the right mouse button is disabled;
|
||||
so pressing it will not trigger any menu item.
|
||||
.TP
|
||||
.B -w
|
||||
Asks the window manager to draw a border around the menus.
|
||||
This option may be buggy in some window managers,
|
||||
specially tiled ones that do not respect window hints.
|
||||
.PP
|
||||
Each item read from stdin has the following format:
|
||||
.IP
|
||||
.EX
|
||||
ITEM := [TABS] [[IMAGE TABS] LABEL [TABS OUTPUT]] NEWLINE
|
||||
.EE
|
||||
.PP
|
||||
That means that each item is composed by
|
||||
tabs, followed by an optional image specification, followed by tabs
|
||||
followed by a label, followed by more tabs, followed by an output,
|
||||
and ended by a newline. Brackets group optional elements.
|
||||
.IP
|
||||
The initial tabs indicate the menu hierarchy:
|
||||
items indented with a tab is shown in a submenu of the preceding item not indented.
|
||||
An item without initial tabs is a top-level item.
|
||||
.IP
|
||||
The image is a string of the form "IMG:/path/to/image.png".
|
||||
It specifies a image to be shown as icon at the left of the entry.
|
||||
.IP
|
||||
The label is the string that will be shown as a item in the menu.
|
||||
An item without label is considered a separator and is drawn as a thin line in the menu
|
||||
separating the item above from the item below.
|
||||
.IP
|
||||
The output is the string that will be output after selecting the item.
|
||||
If an item does not have an output, its label is used as its output.
|
||||
.IP
|
||||
The newline terminates the item specification.
|
||||
.PP
|
||||
If the argument
|
||||
.I title
|
||||
is given, the title of the menu window is set to it.
|
||||
.SH USAGE
|
||||
.B xmenu
|
||||
is controlled by the mouse,
|
||||
but can also be controlled by the keyboard.
|
||||
Items can be selected using the arrow keys,
|
||||
Tab (with and without Shift),
|
||||
Home, End,
|
||||
Enter and Esc, and 1-9 keys.
|
||||
Items can also be selected by typing the first several characters in it.
|
||||
.TP
|
||||
.BR Home
|
||||
Select the first item in the menu.
|
||||
.TP
|
||||
.BR End
|
||||
Select the last item in the menu.
|
||||
.TP
|
||||
.BR Down
|
||||
Cycle through the items in the regular direction.
|
||||
.TP
|
||||
.BR Tab
|
||||
Cycle through the items in the regular direction.
|
||||
When the type\-to\-select feature is active, cycle through matching items instead.
|
||||
.TP
|
||||
.BR Up
|
||||
Cycle through the items in the reverse direction.
|
||||
.TP
|
||||
.BR Shift-Tab
|
||||
Cycle through the items in the reverse direction.
|
||||
When the type\-to\-select feature is active, cycle through matching items instead.
|
||||
.TP
|
||||
.BR Right ", " Enter
|
||||
Select the highlighted item.
|
||||
.TP
|
||||
.B Left
|
||||
Go to the menu above.
|
||||
.TP
|
||||
.B Esc
|
||||
Go to the menu above or exit xmenu.
|
||||
.PP
|
||||
.B xmenu
|
||||
features the type\-to\-select selecting style,
|
||||
where typing a string will select the first item matching it.
|
||||
.PP
|
||||
Additional key bindings can be set at compile time by changing the
|
||||
.B config.h
|
||||
file.
|
||||
.SH RESOURCES
|
||||
.B
|
||||
xmenu
|
||||
understands the following X resources.
|
||||
.TP
|
||||
.B xmenu.font
|
||||
The font in which the labels should be drawn.
|
||||
Multiple fonts can be added as fallback fonts;
|
||||
they must be separated by a comma.
|
||||
.TP
|
||||
.B xmenu.background
|
||||
The background color of non-selected items in the menu.
|
||||
.TP
|
||||
.B xmenu.foreground
|
||||
The color of the label text of non-selected items in the menu.
|
||||
.TP
|
||||
.B xmenu.selbackground
|
||||
The background color of selected items in the menu.
|
||||
.TP
|
||||
.B xmenu.selforeground
|
||||
The color of the label text of selected items in the menu.
|
||||
.TP
|
||||
.B xmenu.border
|
||||
The color of the border around the menu.
|
||||
.TP
|
||||
.B xmenu.separator
|
||||
The color of the separator between items in the menu.
|
||||
.TP
|
||||
.B xmenu.gap
|
||||
The gap, in pixels, between the menus.
|
||||
.TP
|
||||
.B xmenu.width
|
||||
The minimum width, in pixels, of the items in the menu.
|
||||
.TP
|
||||
.B xmenu.height
|
||||
The size in pixels of the height of a single menu item.
|
||||
.TP
|
||||
.B xmenu.borderWidth
|
||||
The size in pixels of the border around the menu.
|
||||
.TP
|
||||
.B xmenu.separatorWidth
|
||||
The size in pixels of the item separator.
|
||||
.TP
|
||||
.B xmenu.alignment
|
||||
If set to
|
||||
.BR "\(dqleft\(dq" ,
|
||||
.BR "\(dqcenter\(dq" ,
|
||||
or
|
||||
.BR "\(dqright\(dq" ,
|
||||
text is aligned to the left, center, or right of the menu, respectively.
|
||||
By default, text is aligned to the left.
|
||||
.SH EXAMPLES
|
||||
The following script illustrates the use of
|
||||
.BR xmenu .
|
||||
The output is redirected to
|
||||
.IR sh (1),
|
||||
creating a command to be run by the shell.
|
||||
.IP
|
||||
.EX
|
||||
#!/bin/sh
|
||||
|
||||
xmenu <<EOF | sh &
|
||||
Applications
|
||||
IMG:./web.png Web Browser firefox
|
||||
IMG:./gimp.png Image editor gimp
|
||||
Terminal (xterm) xterm
|
||||
Terminal (urxvt) urxvt
|
||||
Terminal (st) st
|
||||
|
||||
Shutdown poweroff
|
||||
Reboot reboot
|
||||
EOF
|
||||
.EE
|
||||
.PP
|
||||
For example, by selecting \(lqApplications\(rq, a new menu will appear.
|
||||
Selecting \(lqWeb Browser\(rq in the new menu opens firefox.
|
||||
.SH SEE ALSO
|
||||
.IR dmenu (1),
|
||||
.IR 9menu (1),
|
||||
.IR thingmenu (1)
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,110 @@
|
|||
#define PROGNAME "xmenu"
|
||||
|
||||
/* Actions for the main loop */
|
||||
#define ACTION_NOP 0
|
||||
#define ACTION_CLEAR 1<<0 /* clear text */
|
||||
#define ACTION_SELECT 1<<1 /* select item */
|
||||
#define ACTION_MAP 1<<2 /* remap menu windows */
|
||||
#define ACTION_DRAW 1<<3 /* redraw menu windows */
|
||||
#define ACTION_WARP 1<<4 /* warp the pointer */
|
||||
|
||||
/* enum for keyboard menu navigation */
|
||||
enum { ITEMPREV, ITEMNEXT, ITEMFIRST, ITEMLAST };
|
||||
|
||||
/* enum for text alignment */
|
||||
enum {LeftAlignment, CenterAlignment, RightAlignment};
|
||||
|
||||
/* macros */
|
||||
#define LEN(x) (sizeof (x) / sizeof (x[0]))
|
||||
#define MAX(x,y) ((x)>(y)?(x):(y))
|
||||
#define MIN(x,y) ((x)<(y)?(x):(y))
|
||||
#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
|
||||
#define GETNUM(n, s) { \
|
||||
unsigned long __TMP__; \
|
||||
if ((__TMP__ = strtoul((s), NULL, 10)) < INT_MAX) \
|
||||
(n) = __TMP__; \
|
||||
}
|
||||
|
||||
/* color enum */
|
||||
enum {ColorFG, ColorBG, ColorLast};
|
||||
|
||||
/* EWMH atoms */
|
||||
enum {NetWMName, NetWMWindowType, NetWMWindowTypePopupMenu, NetLast};
|
||||
|
||||
/* configuration structure */
|
||||
struct Config {
|
||||
/* the values below are set by config.h */
|
||||
const char *font;
|
||||
const char *background_color;
|
||||
const char *foreground_color;
|
||||
const char *selbackground_color;
|
||||
const char *selforeground_color;
|
||||
const char *separator_color;
|
||||
const char *border_color;
|
||||
int width_pixels;
|
||||
int height_pixels;
|
||||
int border_pixels;
|
||||
int separator_pixels;
|
||||
int gap_pixels;
|
||||
int triangle_width;
|
||||
int triangle_height;
|
||||
int iconpadding;
|
||||
int horzpadding;
|
||||
int alignment;
|
||||
|
||||
/* the values below are set by options */
|
||||
int monitor;
|
||||
int posx, posy; /* rootmenu position */
|
||||
|
||||
/* the value below is computed by xmenu */
|
||||
int iconsize;
|
||||
};
|
||||
|
||||
/* draw context structure */
|
||||
struct DC {
|
||||
XftColor normal[ColorLast];
|
||||
XftColor selected[ColorLast];
|
||||
XftColor border;
|
||||
XftColor separator;
|
||||
|
||||
GC gc;
|
||||
|
||||
FcPattern *pattern;
|
||||
XftFont **fonts;
|
||||
size_t nfonts;
|
||||
};
|
||||
|
||||
/* menu item structure */
|
||||
struct Item {
|
||||
char *label; /* string to be drawed on menu */
|
||||
char *output; /* string to be outputed when item is clicked */
|
||||
char *file; /* filename of the icon */
|
||||
int y; /* item y position relative to menu */
|
||||
int h; /* item height */
|
||||
int textw; /* text width */
|
||||
struct Item *prev; /* previous item */
|
||||
struct Item *next; /* next item */
|
||||
struct Menu *submenu; /* submenu spawned by clicking on item */
|
||||
Drawable sel, unsel; /* pixmap for selected and unselected item */
|
||||
Imlib_Image icon;
|
||||
};
|
||||
|
||||
/* monitor geometry structure */
|
||||
struct Monitor {
|
||||
int x, y, w, h; /* monitor geometry */
|
||||
};
|
||||
|
||||
/* menu structure */
|
||||
struct Menu {
|
||||
struct Menu *parent; /* parent menu */
|
||||
struct Item *caller; /* item that spawned the menu */
|
||||
struct Item *list; /* list of items contained by the menu */
|
||||
struct Item *selected; /* item currently selected in the menu */
|
||||
int x, y, w, h; /* menu geometry */
|
||||
int hasicon; /* whether the menu has item with icons */
|
||||
int drawn; /* whether the menu was already drawn */
|
||||
int maxtextw; /* maximum text width */
|
||||
unsigned level; /* menu level relative to root */
|
||||
Window win; /* menu window to map on the screen */
|
||||
XIC xic; /* input context */
|
||||
};
|
Binary file not shown.
|
@ -0,0 +1,13 @@
|
|||
#!/bin/sh
|
||||
|
||||
xmenu <<EOF | sh &
|
||||
Applications
|
||||
IMG:./icons/web.png Web Browser firefox
|
||||
IMG:./icons/gimp.png Image editor gimp
|
||||
Terminal (xterm) xterm
|
||||
Terminal (urxvt) urxvt
|
||||
Terminal (st) st
|
||||
|
||||
Shutdown poweroff
|
||||
Reboot reboot
|
||||
EOF
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue