Wnhanced menu, new font, new patches, new color scheme
This commit is contained in:
commit
3106a6ac75
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "j4-dmenu-desktop"]
|
||||||
|
path = j4-dmenu-desktop
|
||||||
|
url = http://github.com/enkore/j4-dmenu-desktop.git
|
23
LICENSE
Normal file
23
LICENSE
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
MIT/X Consortium License
|
||||||
|
|
||||||
|
© 2009-2011 Enno Boland <g s01 de>
|
||||||
|
© 2011,2015 Connor Lane Smith <cls@lubutu.com>
|
||||||
|
© 2012-2015 Christoph Lohmann <20h@r-36.net>
|
||||||
|
|
||||||
|
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.
|
60
README.md
Normal file
60
README.md
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
# Suckless Utilities version 6.3
|
||||||
|
## About
|
||||||
|
These are my builds of suckless software such as dwm and st.
|
||||||
|
It's simple to compile these things.
|
||||||
|
|
||||||
|
1. Install necessary tools and libraries
|
||||||
|
```
|
||||||
|
Linux/Unix users:
|
||||||
|
- xorg (including drivers of course)
|
||||||
|
- base-devel (or build-essential/s)
|
||||||
|
- libX11(-devel or -dev)
|
||||||
|
- libXft(-devel or -dev)
|
||||||
|
- libXinerama(-devel or -dev)
|
||||||
|
- freetype(-devel or -dev)
|
||||||
|
- fontconfig(-devel or -dev)
|
||||||
|
- font-awesome (for slstatus)(must be 6.x)
|
||||||
|
- terminus-font
|
||||||
|
- imlibs2(-devel or -dev)
|
||||||
|
- picom (for transparency)
|
||||||
|
- feh (optional)
|
||||||
|
|
||||||
|
Termux users:
|
||||||
|
- xorg
|
||||||
|
- termux-X11 repo (via main Termux app)
|
||||||
|
- proot/chroot
|
||||||
|
- PulseAudio (if you like audio support)
|
||||||
|
- TigerVNC
|
||||||
|
- VNC client
|
||||||
|
or
|
||||||
|
- XSDL client
|
||||||
|
or
|
||||||
|
- Termux:X11 (both apk and deb)
|
||||||
|
````
|
||||||
|
2. Clone this repository
|
||||||
|
3. Change directory to what suckless software do you want to use
|
||||||
|
4. Remove the `config.h` file, to make sure all patches are applied correctly
|
||||||
|
5. Copy `make clean install` and paste it on your terminal
|
||||||
|
6. Insert dwm, slstatus and/or st inside your `.xinitrc` using your favorite text editor (usually located in `/home/<username>/.xinitrc`)
|
||||||
|
7. Start it and done!
|
||||||
|
|
||||||
|
## Current bugs
|
||||||
|
- ~~Taskbar not working properly~~ (fixed in commit [e9015f2](https://github.com/Lucas-mother3/suckless-utils/commit/e9015f2d2a09ef66f1c9e188b277c89d23635195) & [7085f9](https://github.com/Lucas-mother3/suckless-utils/commit/7085f97d80fc203d6f54d0209af07007c0347880)). Thanks, [Speedie](https://speedie.gq)!
|
||||||
|
|
||||||
|
## Patching even further
|
||||||
|
|
||||||
|
Patching everything is as easy as downloading the diff file, use the `patch` command and apply changes.
|
||||||
|
|
||||||
|
But, since this is a heavily patched version of everything, I wouldn't recommend patching even further unless if you know what you're doing.
|
||||||
|
|
||||||
|
## How the versioning system works
|
||||||
|
|
||||||
|
Suckless Uilities (the whole package and not the individual components) are versioned under the current version of the repo's dwm.
|
||||||
|
Even if dwm 6.4 releases, if the repo still uses dwm 6.3 for compatibility reasons, the whole package will be still be Suckless Utilities 6.3.
|
||||||
|
|
||||||
|
## Licensing
|
||||||
|
All programs are licensed under the MIT License, which sucks, and worse than GNU GPL, but hey, it's better than proprietary code!
|
||||||
|
|
||||||
|
## Special thanks
|
||||||
|
* [Speedie](https://speedie.gq) for helping me out with this and providing me with patches
|
||||||
|
* [The suckless team](https://suckless.org) for maintaining suckless software suck less
|
30
dmenu/LICENSE
Normal file
30
dmenu/LICENSE
Normal file
|
@ -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-2022 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.
|
64
dmenu/Makefile
Normal file
64
dmenu/Makefile
Normal file
|
@ -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
|
24
dmenu/README
Normal file
24
dmenu/README
Normal file
|
@ -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.
|
49
dmenu/arg.h
Normal file
49
dmenu/arg.h
Normal file
|
@ -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
|
34
dmenu/config.def.h
Normal file
34
dmenu/config.def.h
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
/* Default settings; can be overriden by command line. */
|
||||||
|
|
||||||
|
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
|
||||||
|
/* -fn option overrides fonts[0]; default X11 font or font set */
|
||||||
|
static const char *fonts[] = {
|
||||||
|
"Hack Nerd Font:size=14:"
|
||||||
|
};
|
||||||
|
static const char *prompt = NULL; /* -p option; prompt to the left of input field */
|
||||||
|
|
||||||
|
static const unsigned int baralpha = 0xd0;
|
||||||
|
static const unsigned int borderalpha = OPAQUE;
|
||||||
|
static const unsigned int alphas[][3] = {
|
||||||
|
/* fg bg border */
|
||||||
|
[SchemeNorm] = { OPAQUE, baralpha, borderalpha },
|
||||||
|
[SchemeSel] = { OPAQUE, baralpha, borderalpha },
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *colors[SchemeLast][2] = {
|
||||||
|
/* fg bg */
|
||||||
|
[SchemeNorm] = { "#bbbbbb", "#222222" },
|
||||||
|
[SchemeSel] = { "#eeeeee", "#005577" },
|
||||||
|
[SchemeOut] = { "#000000", "#00ffff" },
|
||||||
|
[SchemeMid] = { "#eeeeee", "#770000" },
|
||||||
|
};
|
||||||
|
/* -l and -g options; controls number of lines and columns in grid if > 0 */
|
||||||
|
static unsigned int lines = 0;
|
||||||
|
static unsigned int columns = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Characters not considered part of a word while deleting words
|
||||||
|
* for example: " /?\"&[]"
|
||||||
|
*/
|
||||||
|
static const char worddelimiters[] = " ";
|
34
dmenu/config.h
Normal file
34
dmenu/config.h
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
/* Default settings; can be overriden by command line. */
|
||||||
|
|
||||||
|
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
|
||||||
|
/* -fn option overrides fonts[0]; default X11 font or font set */
|
||||||
|
static const char *fonts[] = {
|
||||||
|
"Hack Nerd Font:size=14:"
|
||||||
|
};
|
||||||
|
static const char *prompt = NULL; /* -p option; prompt to the left of input field */
|
||||||
|
|
||||||
|
static const unsigned int baralpha = 0xd0;
|
||||||
|
static const unsigned int borderalpha = OPAQUE;
|
||||||
|
static const unsigned int alphas[][3] = {
|
||||||
|
/* fg bg border */
|
||||||
|
[SchemeNorm] = { OPAQUE, baralpha, borderalpha },
|
||||||
|
[SchemeSel] = { OPAQUE, baralpha, borderalpha },
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *colors[SchemeLast][2] = {
|
||||||
|
/* fg bg */
|
||||||
|
[SchemeNorm] = { "#bbbbbb", "#222222" },
|
||||||
|
[SchemeSel] = { "#eeeeee", "#005577" },
|
||||||
|
[SchemeOut] = { "#000000", "#00ffff" },
|
||||||
|
[SchemeMid] = { "#eeeeee", "#770000" },
|
||||||
|
};
|
||||||
|
/* -l and -g options; controls number of lines and columns in grid if > 0 */
|
||||||
|
static unsigned int lines = 0;
|
||||||
|
static unsigned int columns = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Characters not considered part of a word while deleting words
|
||||||
|
* for example: " /?\"&[]"
|
||||||
|
*/
|
||||||
|
static const char worddelimiters[] = " ";
|
35
dmenu/config.mk
Normal file
35
dmenu/config.mk
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
# dmenu version
|
||||||
|
VERSION = 5.1
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# alpha
|
||||||
|
XRENDERLIBS = -lXrender
|
||||||
|
|
||||||
|
# OpenBSD (uncomment)
|
||||||
|
#FREETYPEINC = $(X11INC)/freetype2
|
||||||
|
|
||||||
|
# includes and libs
|
||||||
|
INCS = -I$(X11INC) -I$(FREETYPEINC)
|
||||||
|
LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS) ${XRENDERLIBS}
|
||||||
|
|
||||||
|
# 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
|
BIN
dmenu/dmenu
Executable file
BIN
dmenu/dmenu
Executable file
Binary file not shown.
199
dmenu/dmenu.1
Normal file
199
dmenu/dmenu.1
Normal file
|
@ -0,0 +1,199 @@
|
||||||
|
.TH DMENU 1 dmenu\-VERSION
|
||||||
|
.SH NAME
|
||||||
|
dmenu \- dynamic menu
|
||||||
|
.SH SYNOPSIS
|
||||||
|
.B dmenu
|
||||||
|
.RB [ \-bfiv ]
|
||||||
|
.RB [ \-g
|
||||||
|
.IR columns ]
|
||||||
|
.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 \-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 \-g " columns"
|
||||||
|
dmenu lists items in a grid with the given number of columns.
|
||||||
|
.TP
|
||||||
|
.BI \-l " lines"
|
||||||
|
dmenu lists items in a grid with the given number of lines.
|
||||||
|
.TP
|
||||||
|
.BI \-m " monitor"
|
||||||
|
dmenu is displayed on the monitor number supplied. Monitor numbers are starting
|
||||||
|
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)
|
847
dmenu/dmenu.c
Normal file
847
dmenu/dmenu.c
Normal file
|
@ -0,0 +1,847 @@
|
||||||
|
/* 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)
|
||||||
|
#define OPAQUE 0xffU
|
||||||
|
|
||||||
|
/* enums */
|
||||||
|
enum { SchemeNorm, SchemeSel, SchemeOut, SchemeMid, 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 int useargb = 0;
|
||||||
|
static Visual *visual;
|
||||||
|
static int depth;
|
||||||
|
static Colormap cmap;
|
||||||
|
|
||||||
|
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 * columns * bh;
|
||||||
|
else
|
||||||
|
n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
|
||||||
|
/* calculate which items will begin the next page and previous page */
|
||||||
|
for (i = 0, next = curr; next; next = next->right)
|
||||||
|
if ((i += (lines > 0) ? bh : MIN(TEXTW(next->text), n)) > n)
|
||||||
|
break;
|
||||||
|
for (i = 0, prev = curr; prev && prev->left; prev = prev->left)
|
||||||
|
if ((i += (lines > 0) ? bh : MIN(TEXTW(prev->left->text), n)) > n)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cleanup(void)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
XUngrabKey(dpy, AnyKey, AnyModifier, root);
|
||||||
|
for (i = 0; i < SchemeLast; i++)
|
||||||
|
free(scheme[i]);
|
||||||
|
drw_free(drw);
|
||||||
|
XSync(dpy, False);
|
||||||
|
XCloseDisplay(dpy);
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
cistrstr(const char *h, const char *n)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (!n[0])
|
||||||
|
return (char *)h;
|
||||||
|
|
||||||
|
for (; *h; ++h) {
|
||||||
|
for (i = 0; n[i] && tolower((unsigned char)n[i]) ==
|
||||||
|
tolower((unsigned char)h[i]); ++i)
|
||||||
|
;
|
||||||
|
if (n[i] == '\0')
|
||||||
|
return (char *)h;
|
||||||
|
}
|
||||||
|
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->left == sel || item->right == sel)
|
||||||
|
drw_setscheme(drw, scheme[SchemeMid]);
|
||||||
|
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 grid */
|
||||||
|
int i = 0;
|
||||||
|
for (item = curr; item != next; item = item->right, i++)
|
||||||
|
drawitem(
|
||||||
|
item,
|
||||||
|
x + ((i / lines) * ((mw - x) / columns)),
|
||||||
|
y + (((i % lines) + 1) * bh),
|
||||||
|
(mw - x) / columns
|
||||||
|
);
|
||||||
|
} else if (matches) {
|
||||||
|
/* draw horizontal list */
|
||||||
|
x += inputw;
|
||||||
|
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
|
||||||
|
xinitvisual()
|
||||||
|
{
|
||||||
|
XVisualInfo *infos;
|
||||||
|
XRenderPictFormat *fmt;
|
||||||
|
int nitems;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
XVisualInfo tpl = {
|
||||||
|
.screen = screen,
|
||||||
|
.depth = 32,
|
||||||
|
.class = TrueColor
|
||||||
|
};
|
||||||
|
long masks = VisualScreenMask | VisualDepthMask | VisualClassMask;
|
||||||
|
|
||||||
|
infos = XGetVisualInfo(dpy, masks, &tpl, &nitems);
|
||||||
|
visual = NULL;
|
||||||
|
for(i = 0; i < nitems; i ++) {
|
||||||
|
fmt = XRenderFindVisualFormat(dpy, infos[i].visual);
|
||||||
|
if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
|
||||||
|
visual = infos[i].visual;
|
||||||
|
depth = infos[i].depth;
|
||||||
|
cmap = XCreateColormap(dpy, root, visual, AllocNone);
|
||||||
|
useargb = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
XFree(infos);
|
||||||
|
|
||||||
|
if (! visual) {
|
||||||
|
visual = DefaultVisual(dpy, screen);
|
||||||
|
depth = DefaultDepth(dpy, screen);
|
||||||
|
cmap = DefaultColormap(dpy, screen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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], alphas[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;
|
||||||
|
#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]) != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
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);
|
||||||
|
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();
|
||||||
|
|
||||||
|
/* create menu window */
|
||||||
|
swa.override_redirect = True;
|
||||||
|
swa.background_pixel = 0;
|
||||||
|
swa.colormap = cmap;
|
||||||
|
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
|
||||||
|
win = XCreateWindow(dpy, parentwin, x, y, mw, mh, 0,
|
||||||
|
depth, InputOutput, visual,
|
||||||
|
CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWColormap|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], "-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], "-g")) { /* number of columns in grid */
|
||||||
|
columns = atoi(argv[++i]);
|
||||||
|
if (lines == 0) lines = 1;
|
||||||
|
} else if (!strcmp(argv[i], "-l")) { /* number of lines in grid */
|
||||||
|
lines = atoi(argv[++i]);
|
||||||
|
if (columns == 0) columns = 1;
|
||||||
|
} else if (!strcmp(argv[i], "-m"))
|
||||||
|
mon = atoi(argv[++i]);
|
||||||
|
else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
|
||||||
|
prompt = argv[++i];
|
||||||
|
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);
|
||||||
|
xinitvisual();
|
||||||
|
drw = drw_create(dpy, screen, root, wa.width, wa.height, visual, depth, cmap);
|
||||||
|
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 */
|
||||||
|
}
|
BIN
dmenu/dmenu.o
Normal file
BIN
dmenu/dmenu.o
Normal file
Binary file not shown.
13
dmenu/dmenu_path
Executable file
13
dmenu/dmenu_path
Executable file
|
@ -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
|
2
dmenu/dmenu_run
Executable file
2
dmenu/dmenu_run
Executable file
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
dmenu_path | dmenu "$@" | ${SHELL:-"/bin/sh"} &
|
438
dmenu/drw.c
Normal file
438
dmenu/drw.c
Normal file
|
@ -0,0 +1,438 @@
|
||||||
|
/* 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, Visual *visual, unsigned int depth, Colormap cmap)
|
||||||
|
{
|
||||||
|
Drw *drw = ecalloc(1, sizeof(Drw));
|
||||||
|
|
||||||
|
drw->dpy = dpy;
|
||||||
|
drw->screen = screen;
|
||||||
|
drw->root = root;
|
||||||
|
drw->w = w;
|
||||||
|
drw->h = h;
|
||||||
|
drw->visual = visual;
|
||||||
|
drw->depth = depth;
|
||||||
|
drw->cmap = cmap;
|
||||||
|
drw->drawable = XCreatePixmap(dpy, root, w, h, depth);
|
||||||
|
drw->gc = XCreateGC(dpy, drw->drawable, 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, drw->depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
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, unsigned int alpha)
|
||||||
|
{
|
||||||
|
if (!drw || !dest || !clrname)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!XftColorAllocName(drw->dpy, drw->visual, drw->cmap,
|
||||||
|
clrname, dest))
|
||||||
|
die("error, cannot allocate color '%s'", clrname);
|
||||||
|
|
||||||
|
dest->pixel = (dest->pixel & 0x00ffffffU) | (alpha << 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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[], const unsigned int alphas[], 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], alphas[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, drw->visual, drw->cmap);
|
||||||
|
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);
|
||||||
|
}
|
438
dmenu/drw.c.orig
Normal file
438
dmenu/drw.c.orig
Normal file
|
@ -0,0 +1,438 @@
|
||||||
|
/* 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, Visual *visual, unsigned int depth, Colormap cmap)
|
||||||
|
{
|
||||||
|
Drw *drw = ecalloc(1, sizeof(Drw));
|
||||||
|
|
||||||
|
drw->dpy = dpy;
|
||||||
|
drw->screen = screen;
|
||||||
|
drw->root = root;
|
||||||
|
drw->w = w;
|
||||||
|
drw->h = h;
|
||||||
|
drw->visual = visual;
|
||||||
|
drw->depth = depth;
|
||||||
|
drw->cmap = cmap;
|
||||||
|
drw->drawable = XCreatePixmap(dpy, root, w, h, depth);
|
||||||
|
drw->gc = XCreateGC(dpy, drw->drawable, 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, drw->depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
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, unsigned int alpha)
|
||||||
|
{
|
||||||
|
if (!drw || !dest || !clrname)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!XftColorAllocName(drw->dpy, drw->visual, drw->cmap,
|
||||||
|
clrname, dest))
|
||||||
|
die("error, cannot allocate color '%s'", clrname);
|
||||||
|
|
||||||
|
dest->pixel = (dest->pixel & 0x00ffffffU) | (alpha << 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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[], const unsigned int alphas[], 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], alphas[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, drw->visual, drw->cmap);
|
||||||
|
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);
|
||||||
|
}
|
60
dmenu/drw.h
Normal file
60
dmenu/drw.h
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/* 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;
|
||||||
|
Visual *visual;
|
||||||
|
unsigned int depth;
|
||||||
|
Colormap cmap;
|
||||||
|
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, Visual *visual, unsigned int depth, Colormap cmap);
|
||||||
|
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, unsigned int alpha);
|
||||||
|
Clr *drw_scm_create(Drw *drw, const char *clrnames[], const unsigned int alphas[], 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);
|
60
dmenu/drw.h.orig
Normal file
60
dmenu/drw.h.orig
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/* 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;
|
||||||
|
Visual *visual;
|
||||||
|
unsigned int depth;
|
||||||
|
Colormap cmap;
|
||||||
|
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, Visual *visual, unsigned int depth, Colormap cmap);
|
||||||
|
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, unsigned int alpha);
|
||||||
|
Clr *drw_scm_create(Drw *drw, const char *clrnames[], const unsigned int alphas[], 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);
|
BIN
dmenu/drw.o
Normal file
BIN
dmenu/drw.o
Normal file
Binary file not shown.
281
dmenu/patches/dmenu-alpha.diff
Normal file
281
dmenu/patches/dmenu-alpha.diff
Normal file
|
@ -0,0 +1,281 @@
|
||||||
|
From 5e232dc79ba3c0b791f3d9ddfab2fcecca19f18d Mon Sep 17 00:00:00 2001
|
||||||
|
From: bakkeby <bakkeby@gmail.com>
|
||||||
|
Date: Thu, 28 May 2020 16:58:12 +0200
|
||||||
|
Subject: [PATCH] Adding alpha patch
|
||||||
|
|
||||||
|
---
|
||||||
|
config.def.h | 9 +++++++++
|
||||||
|
config.mk | 6 +++++-
|
||||||
|
dmenu.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++------
|
||||||
|
drw.c | 26 +++++++++++++-----------
|
||||||
|
drw.h | 9 ++++++---
|
||||||
|
5 files changed, 84 insertions(+), 22 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index 1edb647..5c512d3 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -7,6 +7,15 @@ static const char *fonts[] = {
|
||||||
|
"monospace:size=10"
|
||||||
|
};
|
||||||
|
static const char *prompt = NULL; /* -p option; prompt to the left of input field */
|
||||||
|
+
|
||||||
|
+static const unsigned int baralpha = 0xd0;
|
||||||
|
+static const unsigned int borderalpha = OPAQUE;
|
||||||
|
+static const unsigned int alphas[][3] = {
|
||||||
|
+ /* fg bg border */
|
||||||
|
+ [SchemeNorm] = { OPAQUE, baralpha, borderalpha },
|
||||||
|
+ [SchemeSel] = { OPAQUE, baralpha, borderalpha },
|
||||||
|
+};
|
||||||
|
+
|
||||||
|
static const char *colors[SchemeLast][2] = {
|
||||||
|
/* fg bg */
|
||||||
|
[SchemeNorm] = { "#bbbbbb", "#222222" },
|
||||||
|
diff --git a/config.mk b/config.mk
|
||||||
|
index 05d5a3e..ee4991a 100644
|
||||||
|
--- a/config.mk
|
||||||
|
+++ b/config.mk
|
||||||
|
@@ -15,12 +15,16 @@ XINERAMAFLAGS = -DXINERAMA
|
||||||
|
# freetype
|
||||||
|
FREETYPELIBS = -lfontconfig -lXft
|
||||||
|
FREETYPEINC = /usr/include/freetype2
|
||||||
|
+
|
||||||
|
+# alpha
|
||||||
|
+XRENDERLIBS = -lXrender
|
||||||
|
+
|
||||||
|
# OpenBSD (uncomment)
|
||||||
|
#FREETYPEINC = $(X11INC)/freetype2
|
||||||
|
|
||||||
|
# includes and libs
|
||||||
|
INCS = -I$(X11INC) -I$(FREETYPEINC)
|
||||||
|
-LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS)
|
||||||
|
+LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS) ${XRENDERLIBS}
|
||||||
|
|
||||||
|
# flags
|
||||||
|
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS)
|
||||||
|
diff --git a/dmenu.c b/dmenu.c
|
||||||
|
index 65f25ce..31efafc 100644
|
||||||
|
--- a/dmenu.c
|
||||||
|
+++ b/dmenu.c
|
||||||
|
@@ -24,6 +24,7 @@
|
||||||
|
* MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org)))
|
||||||
|
#define LENGTH(X) (sizeof X / sizeof X[0])
|
||||||
|
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
|
||||||
|
+#define OPAQUE 0xffU
|
||||||
|
|
||||||
|
/* enums */
|
||||||
|
enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
|
||||||
|
@@ -50,6 +51,11 @@ static Display *dpy;
|
||||||
|
static Window root, parentwin, win;
|
||||||
|
static XIC xic;
|
||||||
|
|
||||||
|
+static int useargb = 0;
|
||||||
|
+static Visual *visual;
|
||||||
|
+static int depth;
|
||||||
|
+static Colormap cmap;
|
||||||
|
+
|
||||||
|
static Drw *drw;
|
||||||
|
static Clr *scheme[SchemeLast];
|
||||||
|
|
||||||
|
@@ -518,6 +524,43 @@ paste(void)
|
||||||
|
drawmenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
+static void
|
||||||
|
+xinitvisual()
|
||||||
|
+{
|
||||||
|
+ XVisualInfo *infos;
|
||||||
|
+ XRenderPictFormat *fmt;
|
||||||
|
+ int nitems;
|
||||||
|
+ int i;
|
||||||
|
+
|
||||||
|
+ XVisualInfo tpl = {
|
||||||
|
+ .screen = screen,
|
||||||
|
+ .depth = 32,
|
||||||
|
+ .class = TrueColor
|
||||||
|
+ };
|
||||||
|
+ long masks = VisualScreenMask | VisualDepthMask | VisualClassMask;
|
||||||
|
+
|
||||||
|
+ infos = XGetVisualInfo(dpy, masks, &tpl, &nitems);
|
||||||
|
+ visual = NULL;
|
||||||
|
+ for(i = 0; i < nitems; i ++) {
|
||||||
|
+ fmt = XRenderFindVisualFormat(dpy, infos[i].visual);
|
||||||
|
+ if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
|
||||||
|
+ visual = infos[i].visual;
|
||||||
|
+ depth = infos[i].depth;
|
||||||
|
+ cmap = XCreateColormap(dpy, root, visual, AllocNone);
|
||||||
|
+ useargb = 1;
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ XFree(infos);
|
||||||
|
+
|
||||||
|
+ if (! visual) {
|
||||||
|
+ visual = DefaultVisual(dpy, screen);
|
||||||
|
+ depth = DefaultDepth(dpy, screen);
|
||||||
|
+ cmap = DefaultColormap(dpy, screen);
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
static void
|
||||||
|
readstdin(void)
|
||||||
|
{
|
||||||
|
@@ -602,7 +645,7 @@ setup(void)
|
||||||
|
#endif
|
||||||
|
/* init appearance */
|
||||||
|
for (j = 0; j < SchemeLast; j++)
|
||||||
|
- scheme[j] = drw_scm_create(drw, colors[j], 2);
|
||||||
|
+ scheme[j] = drw_scm_create(drw, colors[j], alphas[j], 2);
|
||||||
|
|
||||||
|
clip = XInternAtom(dpy, "CLIPBOARD", False);
|
||||||
|
utf8 = XInternAtom(dpy, "UTF8_STRING", False);
|
||||||
|
@@ -657,14 +700,14 @@ setup(void)
|
||||||
|
|
||||||
|
/* create menu window */
|
||||||
|
swa.override_redirect = True;
|
||||||
|
- swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
|
||||||
|
+ swa.background_pixel = 0;
|
||||||
|
+ swa.colormap = cmap;
|
||||||
|
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
|
||||||
|
win = XCreateWindow(dpy, parentwin, x, y, mw, mh, 0,
|
||||||
|
- CopyFromParent, CopyFromParent, CopyFomParent,
|
||||||
|
- CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
|
||||||
|
+ depth, InputOutput, visual,
|
||||||
|
+ CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &swa);
|
||||||
|
XSetClassHint(dpy, win, &ch);
|
||||||
|
|
||||||
|
-
|
||||||
|
/* input methods */
|
||||||
|
if ((xim = XOpenIM(dpy, NULL, NULL, NULL)) == NULL)
|
||||||
|
die("XOpenIM failed: could not open input device");
|
||||||
|
@@ -747,7 +790,8 @@ main(int argc, char *argv[])
|
||||||
|
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);
|
||||||
|
+ xinitvisual();
|
||||||
|
+ drw = drw_create(dpy, screen, root, wa.width, wa.height, visual, depth, cmap);
|
||||||
|
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
|
||||||
|
die("no fonts could be loaded.");
|
||||||
|
lrpad = drw->fonts->h;
|
||||||
|
diff --git a/drw.c b/drw.c
|
||||||
|
index 4cdbcbe..fe3aadd 100644
|
||||||
|
--- a/drw.c
|
||||||
|
+++ b/drw.c
|
||||||
|
@@ -61,7 +61,7 @@ utf8decode(const char *c, long *u, size_t clen)
|
||||||
|
}
|
||||||
|
|
||||||
|
Drw *
|
||||||
|
-drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h)
|
||||||
|
+drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap)
|
||||||
|
{
|
||||||
|
Drw *drw = ecalloc(1, sizeof(Drw));
|
||||||
|
|
||||||
|
@@ -70,8 +70,11 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h
|
||||||
|
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);
|
||||||
|
+ drw->visual = visual;
|
||||||
|
+ drw->depth = depth;
|
||||||
|
+ drw->cmap = cmap;
|
||||||
|
+ drw->drawable = XCreatePixmap(dpy, root, w, h, depth);
|
||||||
|
+ drw->gc = XCreateGC(dpy, drw->drawable, 0, NULL);
|
||||||
|
XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
|
||||||
|
|
||||||
|
return drw;
|
||||||
|
@@ -87,7 +90,7 @@ drw_resize(Drw *drw, unsigned int w, unsigned int h)
|
||||||
|
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));
|
||||||
|
+ drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, drw->depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
@@ -194,21 +197,22 @@ drw_fontset_free(Fnt *font)
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
-drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
|
||||||
|
+drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha)
|
||||||
|
{
|
||||||
|
if (!drw || !dest || !clrname)
|
||||||
|
return;
|
||||||
|
|
||||||
|
- if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
|
||||||
|
- DefaultColormap(drw->dpy, drw->screen),
|
||||||
|
+ if (!XftColorAllocName(drw->dpy, drw->visual, drw->cmap,
|
||||||
|
clrname, dest))
|
||||||
|
die("error, cannot allocate color '%s'", clrname);
|
||||||
|
+
|
||||||
|
+ dest->pixel = (dest->pixel & 0x00ffffffU) | (alpha << 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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)
|
||||||
|
+drw_scm_create(Drw *drw, const char *clrnames[], const unsigned int alphas[], size_t clrcount)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
Clr *ret;
|
||||||
|
@@ -218,7 +222,7 @@ drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
for (i = 0; i < clrcount; i++)
|
||||||
|
- drw_clr_create(drw, &ret[i], clrnames[i]);
|
||||||
|
+ drw_clr_create(drw, &ret[i], clrnames[i], alphas[i]);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -274,9 +278,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
|
||||||
|
} 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));
|
||||||
|
+ d = XftDrawCreate(drw->dpy, drw->drawable, drw->visual, drw->cmap);
|
||||||
|
x += lpad;
|
||||||
|
w -= lpad;
|
||||||
|
}
|
||||||
|
diff --git a/drw.h b/drw.h
|
||||||
|
index 4c67419..4f66f0d 100644
|
||||||
|
--- a/drw.h
|
||||||
|
+++ b/drw.h
|
||||||
|
@@ -20,6 +20,9 @@ typedef struct {
|
||||||
|
Display *dpy;
|
||||||
|
int screen;
|
||||||
|
Window root;
|
||||||
|
+ Visual *visual;
|
||||||
|
+ unsigned int depth;
|
||||||
|
+ Colormap cmap;
|
||||||
|
Drawable drawable;
|
||||||
|
GC gc;
|
||||||
|
Clr *scheme;
|
||||||
|
@@ -27,7 +30,7 @@ typedef struct {
|
||||||
|
} Drw;
|
||||||
|
|
||||||
|
/* Drawable abstraction */
|
||||||
|
-Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h);
|
||||||
|
+Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap);
|
||||||
|
void drw_resize(Drw *drw, unsigned int w, unsigned int h);
|
||||||
|
void drw_free(Drw *drw);
|
||||||
|
|
||||||
|
@@ -38,8 +41,8 @@ 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);
|
||||||
|
+void drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha);
|
||||||
|
+Clr *drw_scm_create(Drw *drw, const char *clrnames[], const unsigned int alphas[], size_t clrcount);
|
||||||
|
|
||||||
|
/* Cursor abstraction */
|
||||||
|
Cur *drw_cur_create(Drw *drw, int shape);
|
||||||
|
--
|
||||||
|
2.34.1
|
||||||
|
r
|
42
dmenu/patches/dmenu-caseinsensitive-20200523-db6093f.diff
Normal file
42
dmenu/patches/dmenu-caseinsensitive-20200523-db6093f.diff
Normal file
|
@ -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
|
||||||
|
|
107
dmenu/patches/dmenu-grid-4.9.diff
Normal file
107
dmenu/patches/dmenu-grid-4.9.diff
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
From 39ab9676914bd0d8105d0f96bbd7611a53077438 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Miles Alan <m@milesalan.com>
|
||||||
|
Date: Sat, 4 Jul 2020 11:19:04 -0500
|
||||||
|
Subject: [PATCH] Add -g option to display entries in the given number of grid
|
||||||
|
columns
|
||||||
|
|
||||||
|
This option can be used in conjunction with -l to format dmenu's options in
|
||||||
|
arbitrary size grids. For example, to create a 4 column by 6 line grid, you
|
||||||
|
could use: dmenu -g 4 -l 6
|
||||||
|
---
|
||||||
|
config.def.h | 3 ++-
|
||||||
|
dmenu.1 | 7 ++++++-
|
||||||
|
dmenu.c | 22 ++++++++++++++++------
|
||||||
|
3 files changed, 24 insertions(+), 8 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index 1edb647..96cf3c9 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -13,8 +13,9 @@ static const char *colors[SchemeLast][2] = {
|
||||||
|
[SchemeSel] = { "#eeeeee", "#005577" },
|
||||||
|
[SchemeOut] = { "#000000", "#00ffff" },
|
||||||
|
};
|
||||||
|
-/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
|
||||||
|
+/* -l and -g options; controls number of lines and columns in grid if > 0 */
|
||||||
|
static unsigned int lines = 0;
|
||||||
|
+static unsigned int columns = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Characters not considered part of a word while deleting words
|
||||||
|
diff --git a/dmenu.1 b/dmenu.1
|
||||||
|
index 323f93c..d0a734a 100644
|
||||||
|
--- a/dmenu.1
|
||||||
|
+++ b/dmenu.1
|
||||||
|
@@ -4,6 +4,8 @@ dmenu \- dynamic menu
|
||||||
|
.SH SYNOPSIS
|
||||||
|
.B dmenu
|
||||||
|
.RB [ \-bfiv ]
|
||||||
|
+.RB [ \-g
|
||||||
|
+.IR columns ]
|
||||||
|
.RB [ \-l
|
||||||
|
.IR lines ]
|
||||||
|
.RB [ \-m
|
||||||
|
@@ -47,8 +49,11 @@ is faster, but will lock up X until stdin reaches end\-of\-file.
|
||||||
|
.B \-i
|
||||||
|
dmenu matches menu items case insensitively.
|
||||||
|
.TP
|
||||||
|
+.BI \-g " columns"
|
||||||
|
+dmenu lists items in a grid with the given number of columns.
|
||||||
|
+.TP
|
||||||
|
.BI \-l " lines"
|
||||||
|
-dmenu lists items vertically, with the given number of lines.
|
||||||
|
+dmenu lists items in a grid with the given number of lines.
|
||||||
|
.TP
|
||||||
|
.BI \-m " monitor"
|
||||||
|
dmenu is displayed on the monitor number supplied. Monitor numbers are starting
|
||||||
|
diff --git a/dmenu.c b/dmenu.c
|
||||||
|
index 6b8f51b..d79b6bb 100644
|
||||||
|
--- a/dmenu.c
|
||||||
|
+++ b/dmenu.c
|
||||||
|
@@ -77,7 +77,7 @@ calcoffsets(void)
|
||||||
|
int i, n;
|
||||||
|
|
||||||
|
if (lines > 0)
|
||||||
|
- n = lines * bh;
|
||||||
|
+ n = lines * columns * bh;
|
||||||
|
else
|
||||||
|
n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
|
||||||
|
/* calculate which items will begin the next page and previous page */
|
||||||
|
@@ -152,9 +152,15 @@ drawmenu(void)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lines > 0) {
|
||||||
|
- /* draw vertical list */
|
||||||
|
- for (item = curr; item != next; item = item->right)
|
||||||
|
- drawitem(item, x, y += bh, mw - x);
|
||||||
|
+ /* draw grid */
|
||||||
|
+ int i = 0;
|
||||||
|
+ for (item = curr; item != next; item = item->right, i++)
|
||||||
|
+ drawitem(
|
||||||
|
+ item,
|
||||||
|
+ x + ((i / lines) * ((mw - x) / columns)),
|
||||||
|
+ y + (((i % lines) + 1) * bh),
|
||||||
|
+ (mw - x) / columns
|
||||||
|
+ );
|
||||||
|
} else if (matches) {
|
||||||
|
/* draw horizontal list */
|
||||||
|
x += inputw;
|
||||||
|
@@ -708,9 +714,13 @@ main(int argc, char *argv[])
|
||||||
|
} else if (i + 1 == argc)
|
||||||
|
usage();
|
||||||
|
/* these options take one argument */
|
||||||
|
- else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
|
||||||
|
+ else if (!strcmp(argv[i], "-g")) { /* number of columns in grid */
|
||||||
|
+ columns = atoi(argv[++i]);
|
||||||
|
+ if (lines == 0) lines = 1;
|
||||||
|
+ } else if (!strcmp(argv[i], "-l")) { /* number of lines in grid */
|
||||||
|
lines = atoi(argv[++i]);
|
||||||
|
- else if (!strcmp(argv[i], "-m"))
|
||||||
|
+ if (columns == 0) columns = 1;
|
||||||
|
+ } else if (!strcmp(argv[i], "-m"))
|
||||||
|
mon = atoi(argv[++i]);
|
||||||
|
else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
|
||||||
|
prompt = argv[++i];
|
||||||
|
--
|
||||||
|
2.23.1
|
||||||
|
|
47
dmenu/patches/dmenu-morecolor-20190922-4bf895b.diff
Normal file
47
dmenu/patches/dmenu-morecolor-20190922-4bf895b.diff
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
From 4bf895be219ae00394a5cde901dc43ec6dcb3759 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Tanner Babcock <babkock@gmail.com>
|
||||||
|
Date: Sun, 22 Sep 2019 03:07:26 -0500
|
||||||
|
Subject: [PATCH] Additional color scheme, for adjacent entries
|
||||||
|
|
||||||
|
---
|
||||||
|
config.def.h | 1 +
|
||||||
|
dmenu.c | 4 +++-
|
||||||
|
2 files changed, 4 insertions(+), 1 deletion(-)
|
||||||
|
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index 1edb647..767c88f 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -12,6 +12,7 @@ static const char *colors[SchemeLast][2] = {
|
||||||
|
[SchemeNorm] = { "#bbbbbb", "#222222" },
|
||||||
|
[SchemeSel] = { "#eeeeee", "#005577" },
|
||||||
|
[SchemeOut] = { "#000000", "#00ffff" },
|
||||||
|
+ [SchemeMid] = { "#eeeeee", "#770000" },
|
||||||
|
};
|
||||||
|
/* -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..0a5c08d 100644
|
||||||
|
--- a/dmenu.c
|
||||||
|
+++ b/dmenu.c
|
||||||
|
@@ -26,7 +26,7 @@
|
||||||
|
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
|
||||||
|
|
||||||
|
/* enums */
|
||||||
|
-enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
|
||||||
|
+enum { SchemeNorm, SchemeSel, SchemeOut, SchemeMid, SchemeLast }; /* color schemes */
|
||||||
|
|
||||||
|
struct item {
|
||||||
|
char *text;
|
||||||
|
@@ -118,6 +118,8 @@ drawitem(struct item *item, int x, int y, int w)
|
||||||
|
{
|
||||||
|
if (item == sel)
|
||||||
|
drw_setscheme(drw, scheme[SchemeSel]);
|
||||||
|
+ else if (item->left == sel || item->right == sel)
|
||||||
|
+ drw_setscheme(drw, scheme[SchemeMid]);
|
||||||
|
else if (item->out)
|
||||||
|
drw_setscheme(drw, scheme[SchemeOut]);
|
||||||
|
else
|
||||||
|
--
|
||||||
|
2.23.0
|
||||||
|
|
144
dmenu/patches/dmenu-mousesupport.diff
Normal file
144
dmenu/patches/dmenu-mousesupport.diff
Normal file
|
@ -0,0 +1,144 @@
|
||||||
|
diff --git a/dmenu.c b/dmenu.c
|
||||||
|
index d95e6c6..75a79d0 100644
|
||||||
|
--- a/dmenu.c
|
||||||
|
+++ b/dmenu.c
|
||||||
|
@@ -518,6 +518,119 @@ draw:
|
||||||
|
drawmenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
+static void
|
||||||
|
+buttonpress(XEvent *e)
|
||||||
|
+{
|
||||||
|
+ struct item *item;
|
||||||
|
+ XButtonPressedEvent *ev = &e->xbutton;
|
||||||
|
+ int x = 0, y = 0, h = bh, w;
|
||||||
|
+
|
||||||
|
+ if (ev->window != win)
|
||||||
|
+ return;
|
||||||
|
+
|
||||||
|
+ /* right-click: exit */
|
||||||
|
+ if (ev->button == Button3)
|
||||||
|
+ exit(1);
|
||||||
|
+
|
||||||
|
+ if (prompt && *prompt)
|
||||||
|
+ x += promptw;
|
||||||
|
+
|
||||||
|
+ /* input field */
|
||||||
|
+ w = (lines > 0 || !matches) ? mw - x : inputw;
|
||||||
|
+
|
||||||
|
+ /* left-click on input: clear input,
|
||||||
|
+ * NOTE: if there is no left-arrow the space for < is reserved so
|
||||||
|
+ * add that to the input width */
|
||||||
|
+ if (ev->button == Button1 &&
|
||||||
|
+ ((lines <= 0 && ev->x >= 0 && ev->x <= x + w +
|
||||||
|
+ ((!prev || !curr->left) ? TEXTW("<") : 0)) ||
|
||||||
|
+ (lines > 0 && ev->y >= y && ev->y <= y + h))) {
|
||||||
|
+ insert(NULL, -cursor);
|
||||||
|
+ drawmenu();
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ /* middle-mouse click: paste selection */
|
||||||
|
+ if (ev->button == Button2) {
|
||||||
|
+ XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
|
||||||
|
+ utf8, utf8, win, CurrentTime);
|
||||||
|
+ drawmenu();
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ /* scroll up */
|
||||||
|
+ if (ev->button == Button4 && prev) {
|
||||||
|
+ sel = curr = prev;
|
||||||
|
+ calcoffsets();
|
||||||
|
+ drawmenu();
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ /* scroll down */
|
||||||
|
+ if (ev->button == Button5 && next) {
|
||||||
|
+ sel = curr = next;
|
||||||
|
+ calcoffsets();
|
||||||
|
+ drawmenu();
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ if (ev->button != Button1)
|
||||||
|
+ return;
|
||||||
|
+ if (ev->state & ~ControlMask)
|
||||||
|
+ return;
|
||||||
|
+ if (lines > 0) {
|
||||||
|
+ /* vertical list: (ctrl)left-click on item */
|
||||||
|
+ w = mw - x;
|
||||||
|
+ for (item = curr; item != next; item = item->right) {
|
||||||
|
+ y += h;
|
||||||
|
+ if (ev->y >= y && ev->y <= (y + h)) {
|
||||||
|
+ puts(item->text);
|
||||||
|
+ if (!(ev->state & ControlMask))
|
||||||
|
+ exit(0);
|
||||||
|
+ sel = item;
|
||||||
|
+ if (sel) {
|
||||||
|
+ sel->out = 1;
|
||||||
|
+ drawmenu();
|
||||||
|
+ }
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ } else if (matches) {
|
||||||
|
+ /* left-click on left arrow */
|
||||||
|
+ x += inputw;
|
||||||
|
+ w = TEXTW("<");
|
||||||
|
+ if (prev && curr->left) {
|
||||||
|
+ if (ev->x >= x && ev->x <= x + w) {
|
||||||
|
+ sel = curr = prev;
|
||||||
|
+ calcoffsets();
|
||||||
|
+ drawmenu();
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ /* horizontal list: (ctrl)left-click on item */
|
||||||
|
+ for (item = curr; item != next; item = item->right) {
|
||||||
|
+ x += w;
|
||||||
|
+ w = MIN(TEXTW(item->text), mw - x - TEXTW(">"));
|
||||||
|
+ if (ev->x >= x && ev->x <= x + w) {
|
||||||
|
+ puts(item->text);
|
||||||
|
+ if (!(ev->state & ControlMask))
|
||||||
|
+ exit(0);
|
||||||
|
+ sel = item;
|
||||||
|
+ if (sel) {
|
||||||
|
+ sel->out = 1;
|
||||||
|
+ drawmenu();
|
||||||
|
+ }
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ /* left-click on right arrow */
|
||||||
|
+ w = TEXTW(">");
|
||||||
|
+ x = mw - w;
|
||||||
|
+ if (next && ev->x >= x && ev->x <= x + w) {
|
||||||
|
+ sel = curr = next;
|
||||||
|
+ calcoffsets();
|
||||||
|
+ drawmenu();
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
static void
|
||||||
|
paste(void)
|
||||||
|
{
|
||||||
|
@@ -579,6 +692,9 @@ run(void)
|
||||||
|
break;
|
||||||
|
cleanup();
|
||||||
|
exit(1);
|
||||||
|
+ case ButtonPress:
|
||||||
|
+ buttonpress(&ev);
|
||||||
|
+ break;
|
||||||
|
case Expose:
|
||||||
|
if (ev.xexpose.count == 0)
|
||||||
|
drw_map(drw, win, 0, 0, mw, mh);
|
||||||
|
@@ -676,7 +792,8 @@ setup(void)
|
||||||
|
/* create menu window */
|
||||||
|
swa.override_redirect = True;
|
||||||
|
swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
|
||||||
|
- swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
|
||||||
|
+ swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask |
|
||||||
|
+ ButtonPressMask;
|
||||||
|
win = XCreateWindow(dpy, parentwin, x, y, mw, mh, 0,
|
||||||
|
CopyFromParent, CopyFromParent, CopyFromParent,
|
||||||
|
CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
|
245
dmenu/patches/dmenu-scroll.diff
Normal file
245
dmenu/patches/dmenu-scroll.diff
Normal file
|
@ -0,0 +1,245 @@
|
||||||
|
diff --git a/dmenu.c b/dmenu.c
|
||||||
|
index 5c835dd..71efe52 100644
|
||||||
|
--- a/dmenu.c
|
||||||
|
+++ b/dmenu.c
|
||||||
|
@@ -131,9 +131,10 @@ drawitem(struct item *item, int x, int y, int w)
|
||||||
|
static void
|
||||||
|
drawmenu(void)
|
||||||
|
{
|
||||||
|
- unsigned int curpos;
|
||||||
|
+ static int curpos, oldcurlen;
|
||||||
|
struct item *item;
|
||||||
|
int x = 0, y = 0, w;
|
||||||
|
+ int curlen, rcurlen;
|
||||||
|
|
||||||
|
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||||
|
drw_rect(drw, 0, 0, mw, mh, 1, 1);
|
||||||
|
@@ -144,14 +145,21 @@ drawmenu(void)
|
||||||
|
}
|
||||||
|
/* draw input field */
|
||||||
|
w = (lines > 0 || !matches) ? mw - x : inputw;
|
||||||
|
- drw_setscheme(drw, scheme[SchemeNorm]);
|
||||||
|
- drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
|
||||||
|
+ w -= lrpad / 2;
|
||||||
|
+ x += lrpad / 2;
|
||||||
|
|
||||||
|
- curpos = TEXTW(text) - TEXTW(&text[cursor]);
|
||||||
|
- if ((curpos += lrpad / 2 - 1) < w) {
|
||||||
|
- drw_setscheme(drw, scheme[SchemeNorm]);
|
||||||
|
- drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
|
||||||
|
- }
|
||||||
|
+ rcurlen = drw_fontset_getwidth(drw, text + cursor);
|
||||||
|
+ curlen = drw_fontset_getwidth(drw, text) - rcurlen;
|
||||||
|
+ curpos += curlen - oldcurlen;
|
||||||
|
+ curpos = MIN(w, MAX(0, curpos));
|
||||||
|
+ curpos = MAX(curpos, w - rcurlen);
|
||||||
|
+ curpos = MIN(curpos, curlen);
|
||||||
|
+ oldcurlen = curlen;
|
||||||
|
+
|
||||||
|
+ drw_setscheme(drw, scheme[SchemeNorm]);
|
||||||
|
+ drw_text_align(drw, x, 0, curpos, bh, text, cursor, AlignR);
|
||||||
|
+ drw_text_align(drw, x + curpos, 0, w - curpos, bh, text + cursor, strlen(text) - cursor, AlignL);
|
||||||
|
+ drw_rect(drw, x + curpos - 1, 2, 2, bh - 4, 1, 0);
|
||||||
|
|
||||||
|
if (lines > 0) {
|
||||||
|
/* draw vertical list */
|
||||||
|
diff --git a/drw.c b/drw.c
|
||||||
|
index c638323..bfffbc1 100644
|
||||||
|
--- a/drw.c
|
||||||
|
+++ b/drw.c
|
||||||
|
@@ -364,6 +364,175 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
|
||||||
|
return x + (render ? w : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
+int
|
||||||
|
+utf8nextchar(const char *str, int len, int i, int inc)
|
||||||
|
+{
|
||||||
|
+ int n;
|
||||||
|
+
|
||||||
|
+ for (n = i + inc; n + inc >= 0 && n + inc <= len
|
||||||
|
+ && (str[n] & 0xc0) == 0x80; n += inc)
|
||||||
|
+ ;
|
||||||
|
+ return n;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+int
|
||||||
|
+drw_text_align(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int textlen, int align)
|
||||||
|
+{
|
||||||
|
+ int ty;
|
||||||
|
+ unsigned int ew;
|
||||||
|
+ XftDraw *d = NULL;
|
||||||
|
+ Fnt *usedfont, *curfont, *nextfont;
|
||||||
|
+ size_t len;
|
||||||
|
+ int utf8strlen, utf8charlen, render = x || y || w || h;
|
||||||
|
+ long utf8codepoint = 0;
|
||||||
|
+ const char *utf8str;
|
||||||
|
+ FcCharSet *fccharset;
|
||||||
|
+ FcPattern *fcpattern;
|
||||||
|
+ FcPattern *match;
|
||||||
|
+ XftResult result;
|
||||||
|
+ int charexists = 0;
|
||||||
|
+ int i, n;
|
||||||
|
+
|
||||||
|
+ if (!drw || (render && !drw->scheme) || !text || !drw->fonts || textlen <= 0
|
||||||
|
+ || (align != AlignL && align != AlignR))
|
||||||
|
+ return 0;
|
||||||
|
+
|
||||||
|
+ if (!render) {
|
||||||
|
+ w = ~w;
|
||||||
|
+ } else {
|
||||||
|
+ XSetForeground(drw->dpy, drw->gc, drw->scheme[ColBg].pixel);
|
||||||
|
+ XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
|
||||||
|
+ d = XftDrawCreate(drw->dpy, drw->drawable,
|
||||||
|
+ DefaultVisual(drw->dpy, drw->screen),
|
||||||
|
+ DefaultColormap(drw->dpy, drw->screen));
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ usedfont = drw->fonts;
|
||||||
|
+ i = align == AlignL ? 0 : textlen;
|
||||||
|
+ x = align == AlignL ? x : x + w;
|
||||||
|
+ while (1) {
|
||||||
|
+ utf8strlen = 0;
|
||||||
|
+ nextfont = NULL;
|
||||||
|
+ /* if (align == AlignL) */
|
||||||
|
+ utf8str = text + i;
|
||||||
|
+
|
||||||
|
+ while ((align == AlignL && i < textlen) || (align == AlignR && i > 0)) {
|
||||||
|
+ if (align == AlignL) {
|
||||||
|
+ utf8charlen = utf8decode(text + i, &utf8codepoint, MIN(textlen - i, UTF_SIZ));
|
||||||
|
+ if (!utf8charlen) {
|
||||||
|
+ textlen = i;
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+ } else {
|
||||||
|
+ n = utf8nextchar(text, textlen, i, -1);
|
||||||
|
+ utf8charlen = utf8decode(text + n, &utf8codepoint, MIN(textlen - n, UTF_SIZ));
|
||||||
|
+ if (!utf8charlen) {
|
||||||
|
+ textlen -= i;
|
||||||
|
+ text += i;
|
||||||
|
+ i = 0;
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ for (curfont = drw->fonts; curfont; curfont = curfont->next) {
|
||||||
|
+ charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint);
|
||||||
|
+ if (charexists) {
|
||||||
|
+ if (curfont == usedfont) {
|
||||||
|
+ utf8strlen += utf8charlen;
|
||||||
|
+ i += align == AlignL ? utf8charlen : -utf8charlen;
|
||||||
|
+ } else {
|
||||||
|
+ nextfont = curfont;
|
||||||
|
+ }
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (!charexists || nextfont)
|
||||||
|
+ break;
|
||||||
|
+ else
|
||||||
|
+ charexists = 0;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (align == AlignR)
|
||||||
|
+ utf8str = text + i;
|
||||||
|
+
|
||||||
|
+ if (utf8strlen) {
|
||||||
|
+ drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL);
|
||||||
|
+ /* shorten text if necessary */
|
||||||
|
+ if (align == AlignL) {
|
||||||
|
+ for (len = utf8strlen; len && ew > w; ) {
|
||||||
|
+ len = utf8nextchar(utf8str, len, len, -1);
|
||||||
|
+ drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
|
||||||
|
+ }
|
||||||
|
+ } else {
|
||||||
|
+ for (len = utf8strlen; len && ew > w; ) {
|
||||||
|
+ n = utf8nextchar(utf8str, len, 0, +1);
|
||||||
|
+ utf8str += n;
|
||||||
|
+ len -= n;
|
||||||
|
+ drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (len) {
|
||||||
|
+ if (render) {
|
||||||
|
+ ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent;
|
||||||
|
+ XftDrawStringUtf8(d, &drw->scheme[ColFg],
|
||||||
|
+ usedfont->xfont, align == AlignL ? x : x - ew, ty, (XftChar8 *)utf8str, len);
|
||||||
|
+ }
|
||||||
|
+ x += align == AlignL ? ew : -ew;
|
||||||
|
+ w -= ew;
|
||||||
|
+ }
|
||||||
|
+ if (len < utf8strlen)
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if ((align == AlignR && i <= 0) || (align == AlignL && i >= textlen)) {
|
||||||
|
+ break;
|
||||||
|
+ } else if (nextfont) {
|
||||||
|
+ charexists = 0;
|
||||||
|
+ usedfont = nextfont;
|
||||||
|
+ } else {
|
||||||
|
+ /* Regardless of whether or not a fallback font is found, the
|
||||||
|
+ * character must be drawn. */
|
||||||
|
+ charexists = 1;
|
||||||
|
+
|
||||||
|
+ fccharset = FcCharSetCreate();
|
||||||
|
+ FcCharSetAddChar(fccharset, utf8codepoint);
|
||||||
|
+
|
||||||
|
+ if (!drw->fonts->pattern) {
|
||||||
|
+ /* Refer to the comment in xfont_create for more information. */
|
||||||
|
+ die("the first font in the cache must be loaded from a font string.");
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ fcpattern = FcPatternDuplicate(drw->fonts->pattern);
|
||||||
|
+ FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset);
|
||||||
|
+ FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue);
|
||||||
|
+
|
||||||
|
+ FcConfigSubstitute(NULL, fcpattern, FcMatchPattern);
|
||||||
|
+ FcDefaultSubstitute(fcpattern);
|
||||||
|
+ match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result);
|
||||||
|
+
|
||||||
|
+ FcCharSetDestroy(fccharset);
|
||||||
|
+ FcPatternDestroy(fcpattern);
|
||||||
|
+
|
||||||
|
+ if (match) {
|
||||||
|
+ usedfont = xfont_create(drw, NULL, match);
|
||||||
|
+ if (usedfont && XftCharExists(drw->dpy, usedfont->xfont, utf8codepoint)) {
|
||||||
|
+ for (curfont = drw->fonts; curfont->next; curfont = curfont->next)
|
||||||
|
+ ; /* NOP */
|
||||||
|
+ curfont->next = usedfont;
|
||||||
|
+ } else {
|
||||||
|
+ xfont_free(usedfont);
|
||||||
|
+ usedfont = drw->fonts;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ if (d)
|
||||||
|
+ XftDrawDestroy(d);
|
||||||
|
+
|
||||||
|
+ return x;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
void
|
||||||
|
drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h)
|
||||||
|
{
|
||||||
|
diff --git a/drw.h b/drw.h
|
||||||
|
index 4c67419..b66a83e 100644
|
||||||
|
--- a/drw.h
|
||||||
|
+++ b/drw.h
|
||||||
|
@@ -13,6 +13,7 @@ typedef struct Fnt {
|
||||||
|
} Fnt;
|
||||||
|
|
||||||
|
enum { ColFg, ColBg }; /* Clr scheme index */
|
||||||
|
+enum { AlignL, AlignR };
|
||||||
|
typedef XftColor Clr;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
@@ -52,6 +53,7 @@ void drw_setscheme(Drw *drw, Clr *scm);
|
||||||
|
/* Drawing functions */
|
||||||
|
void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert);
|
||||||
|
int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert);
|
||||||
|
+int drw_text_align(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int textlen, int align);
|
||||||
|
|
||||||
|
/* Map functions */
|
||||||
|
void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h);
|
2174
dmenu/scripts/dboard
Executable file
2174
dmenu/scripts/dboard
Executable file
File diff suppressed because it is too large
Load diff
83
dmenu/scripts/dcalc
Executable file
83
dmenu/scripts/dcalc
Executable file
|
@ -0,0 +1,83 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Super basic dmenu calculator.
|
||||||
|
# Written by speedie
|
||||||
|
# Licensed under GNU GPLv3.
|
||||||
|
|
||||||
|
LIST_01()
|
||||||
|
{
|
||||||
|
printf "
|
||||||
|
0
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
6
|
||||||
|
7
|
||||||
|
8
|
||||||
|
9
|
||||||
|
0
|
||||||
|
Last
|
||||||
|
Previous Result
|
||||||
|
Quit"
|
||||||
|
}
|
||||||
|
|
||||||
|
VALUE_01=$(printf "$(LIST_01)" | dmenu -l 20 -p "dcalc") && printf "$VALUE_01" > /tmp/dcalc_val1
|
||||||
|
case "$VALUE_01" in
|
||||||
|
"Last") VALUE_01=$(cat /tmp/dcalc_val1) ;;
|
||||||
|
"Quit") exit 0 ;;
|
||||||
|
"Previous Result") VALUE_01=$(cat /tmp/dcalc-result) ;;
|
||||||
|
"") exit 0 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
LIST_02()
|
||||||
|
{
|
||||||
|
printf "
|
||||||
|
+
|
||||||
|
-
|
||||||
|
×
|
||||||
|
÷
|
||||||
|
Quit
|
||||||
|
Last"
|
||||||
|
}
|
||||||
|
|
||||||
|
VALUE_02=$(printf "$(LIST_02)" | dmenu -l 20 -p "dcalc") && printf "$VALUE_02" > /tmp/dcalc_val2
|
||||||
|
case "$VALUE_02" in
|
||||||
|
"Last") VALUE_02=$(cat /tmp/dcalc_val2) ;;
|
||||||
|
"×") VALUE_02="*" ;;
|
||||||
|
"÷") VALUE_02="/" ;;
|
||||||
|
"Quit") exit 0 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
LIST_03()
|
||||||
|
{
|
||||||
|
printf "
|
||||||
|
0
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
6
|
||||||
|
7
|
||||||
|
8
|
||||||
|
9
|
||||||
|
0
|
||||||
|
Quit
|
||||||
|
Previous Result
|
||||||
|
Last"
|
||||||
|
}
|
||||||
|
|
||||||
|
VALUE_03=$(printf "$(LIST_03)" | dmenu -l 20 -p "dcalc") && printf "$VALUE_03" > /tmp/dcalc_val3
|
||||||
|
case "$VALUE_03" in
|
||||||
|
"Last") VALUE_03=$(cat /tmp/dcalc_val3) ;;
|
||||||
|
"Previous Result") VALUE_03=$(cat /tmp/dcalc-result) ;;
|
||||||
|
"Quit") exit 0 ;;
|
||||||
|
"") exit 0 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
RESULT=$(expr ${VALUE_01} "${VALUE_02}" ${VALUE_03})
|
||||||
|
|
||||||
|
printf "Result = $RESULT" | dmenu -l 1 | sed "s|Result = ||" | xclip -selection clipboard && notify-send "$RESULT copied to clipboard!"
|
||||||
|
printf "$RESULT" > /tmp/dcalc-result
|
||||||
|
|
46
dmenu/scripts/dfmpeg
Executable file
46
dmenu/scripts/dfmpeg
Executable file
|
@ -0,0 +1,46 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# dfmpeg
|
||||||
|
# dmenu gui for recording your screen with ffmpeg
|
||||||
|
# Licensed under MIT, written by speedie
|
||||||
|
# https://github.com/speediegamer/dfmpeg
|
||||||
|
|
||||||
|
defaultConfig() {
|
||||||
|
DFMPEG_DOTDIR="$HOME/.config/dfmpeg" # The directory where dotfiles are
|
||||||
|
DFMPEG_RESOLUTION="1920x1080" # The resolution to record in
|
||||||
|
DFMPEG_AUDIO_DEVICE="alsa" # How to capture audio (alsa/pulseaudio)
|
||||||
|
DFMPEG_FRAME_RATE="60" # Frame rate to capture in.
|
||||||
|
DFMPEG_RECORD_DEVICE="x11grab" # Probably do not change.
|
||||||
|
DFMPEG_OUTPUT_PATH="$HOME/Videos" # Path where videos will be saved.
|
||||||
|
DFMPEG_OUTPUT_FORMAT="mp4" # What format to use
|
||||||
|
DFMPEG_OUTPUT_FILENAME="$DFMPEG_OUTPUT_PATH/Dfmpeg-Output-$(date +"%d-%d-%y-%T").$DFMPEG_OUTPUT_FORMAT" # File name of the output. Probably don't need to change.
|
||||||
|
DFMPEG_WH=":0.0" # Width and height, no need to change, defaults should work.
|
||||||
|
DFMPEG_DMENU="dmenu" # Path to dmenu
|
||||||
|
DFMPEG_TERM="$TERMINAL" # Terminal to use when editing the configuration file.
|
||||||
|
DFMPEG_EDITOR="vim" # Editor to edit the config file with
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultConfig
|
||||||
|
. "$DFMPEG_DOTDIR"/dfmpegrc
|
||||||
|
startrec="ffmpeg -f $DFMPEG_RECORD_DEVICE -s $DFMPEG_RESOLUTION -i $DFMPEG_WH -f $DFMPEG_AUDIO_DEVICE -r $DFMPEG_FRAME_RATE -i default $DFMPEG_OUTPUT_FILENAME"
|
||||||
|
startrec_no_audio="ffmpeg -f $DFMPEG_RECORD_DEVICE -s $DFMPEG_RESOLUTION -r $DFMPEG_FRAME_RATE -i $DFMPEG_WH $DFMPEG_OUTPUT_FILENAME"
|
||||||
|
stoprec="pkill ffmpeg"
|
||||||
|
dfmpeg_ver="2022-04-03-r1"
|
||||||
|
about_screen="dfmpeg $dfmpeg_ver."
|
||||||
|
about_screen_2="Licensed under MIT, written by speedie + contributors."
|
||||||
|
about_screen_3="https://github.com/speediegamer/dfmpeg"
|
||||||
|
|
||||||
|
case "$(printf 'Start\nStop\nStart-No-Audio\nConfigure\nExit\nAbout' | dmenu -p 'Record your screen:')" in
|
||||||
|
"Exit") DFMPEG_STATUS=idle && exit 0 ;;
|
||||||
|
"Start") DFMPEG_STATUS=recording && touch /tmp/dfmpeg-recording && $startrec && exit 0 ;;
|
||||||
|
"Stop") $stoprec && rm /tmp/dfmpeg-recording && DFMPEG_STATUS=idle ;;
|
||||||
|
"Configure") $DFMPEG_TERM $DFMPEG_EDITOR $DFMPEG_DOTDIR/dfmpegrc ;;
|
||||||
|
"Start-No-Audio") DFMPEG_STATUS=recording && touch /tmp/dfmpeg-recording && $startrec_no_audio && exit 0 ;;
|
||||||
|
"About")
|
||||||
|
echo $about_screen > $DFMPEG_DOTDIR/dfmpeg_about
|
||||||
|
echo $about_screen_2 >> $DFMPEG_DOTDIR/dfmpeg_about
|
||||||
|
echo $about_screen_3 >> $DFMPEG_DOTDIR/dfmpeg_about
|
||||||
|
$DFMPEG_TERM $DFMPEG_EDITOR $DFMPEG_DOTDIR/dfmpeg_about
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0 # This fixes a small bug.
|
13
dmenu/scripts/shutdown.sh
Normal file
13
dmenu/scripts/shutdown.sh
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# This simple script uses dmenu to ask the user what they wanna do.
|
||||||
|
|
||||||
|
USER_OPT1=$(printf "Shutdown\nReboot\nExit\nLock\nKill X" | dmenu -b -l 5 -p "What do you wanna do?" -nb "#DC143C")
|
||||||
|
|
||||||
|
case "$USER_OPT1" in
|
||||||
|
"Shutdown") sudo shutdown now || doas shutdown now ;;
|
||||||
|
"Reboot") reboot ;;
|
||||||
|
"Exit") exit 0 ;;
|
||||||
|
"Lock") slock ;;
|
||||||
|
"Kill X") pkill Xorg || pkill X ;;
|
||||||
|
"") exit 0 ;;
|
||||||
|
esac
|
BIN
dmenu/stest
Executable file
BIN
dmenu/stest
Executable file
Binary file not shown.
90
dmenu/stest.1
Normal file
90
dmenu/stest.1
Normal file
|
@ -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)
|
109
dmenu/stest.c
Normal file
109
dmenu/stest.c
Normal file
|
@ -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;
|
||||||
|
}
|
BIN
dmenu/stest.o
Normal file
BIN
dmenu/stest.o
Normal file
Binary file not shown.
35
dmenu/util.c
Normal file
35
dmenu/util.c
Normal file
|
@ -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);
|
||||||
|
}
|
8
dmenu/util.h
Normal file
8
dmenu/util.h
Normal file
|
@ -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);
|
BIN
dmenu/util.o
Normal file
BIN
dmenu/util.o
Normal file
Binary file not shown.
37
dwm/LICENSE
Normal file
37
dwm/LICENSE
Normal file
|
@ -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.
|
51
dwm/Makefile
Normal file
51
dwm/Makefile
Normal file
|
@ -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
|
48
dwm/README
Normal file
48
dwm/README
Normal file
|
@ -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.
|
178
dwm/config.def.h
Normal file
178
dwm/config.def.h
Normal file
|
@ -0,0 +1,178 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
|
||||||
|
/* alt-tab configuration */
|
||||||
|
static const unsigned int tabModKey = 0x40; /* if this key is hold the alt-tab functionality stays acitve. This key must be the same as key that is used to active functin altTabStart `*/
|
||||||
|
static const unsigned int tabCycleKey = 0x17; /* if this key is hit the alt-tab program moves one position forward in clients stack. This key must be the same as key that is used to active functin altTabStart */
|
||||||
|
static const unsigned int tabPosY = 1; /* tab position on Y axis, 0 = bottom, 1 = center, 2 = top */
|
||||||
|
static const unsigned int tabPosX = 1; /* tab position on X axis, 0 = left, 1 = center, 2 = right */
|
||||||
|
static const unsigned int maxWTab = 600; /* tab menu width */
|
||||||
|
static const unsigned int maxHTab = 200; /* tab menu height */
|
||||||
|
|
||||||
|
/* appearance */
|
||||||
|
static const unsigned int borderpx = 1; /* border pixel of windows */
|
||||||
|
static const unsigned int gappx = 5; /* gaps between 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 user_bh = 2; /* 2 is the default spacing around the bar's font */
|
||||||
|
static const char buttonbar[] = " Start";
|
||||||
|
#define ICONSIZE bh /* icon size */
|
||||||
|
#define ICONSPACING 5 /* space between icon and title */
|
||||||
|
static const int focusonwheel = 0;
|
||||||
|
static const char *fonts[] = { "Hack Nerd Font:size=14" };
|
||||||
|
static const char dmenufont[] = "Hack Nerd Font:size=14";
|
||||||
|
static const char col_color1[] = "#173f4f";
|
||||||
|
static const char col_color2[] = "#173f4f";
|
||||||
|
static const char col_color3[] = "#ffffff";
|
||||||
|
static const char col_color4[] = "#eeeeee";
|
||||||
|
static const char col_color5[] = "#124f5f";
|
||||||
|
static const unsigned int baralpha = 0xd0;
|
||||||
|
static const unsigned int borderalpha = OPAQUE;
|
||||||
|
static const char *colors[][3] = {
|
||||||
|
/* fg bg border */
|
||||||
|
[SchemeNorm] = { col_color3, col_color1, col_color2 },
|
||||||
|
[SchemeSel] = { col_color4, col_color5, col_color5 },
|
||||||
|
[SchemeHid] = { col_color5, col_color1, col_color5 },
|
||||||
|
};
|
||||||
|
static const unsigned int alphas[][3] = {
|
||||||
|
/* fg bg border */
|
||||||
|
[SchemeNorm] = { OPAQUE, baralpha, borderalpha },
|
||||||
|
[SchemeSel] = { OPAQUE, baralpha, borderalpha },
|
||||||
|
};
|
||||||
|
|
||||||
|
/* tagging */
|
||||||
|
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
||||||
|
static const char *alttags[] = { "<01>", "<02>", "<03>", "<04>", "<05>" };
|
||||||
|
|
||||||
|
static const unsigned int ulinepad = 5; /* horizontal padding between the underline and tag */
|
||||||
|
static const unsigned int ulinestroke = 1; /* thickness / height of the underline */
|
||||||
|
static const unsigned int ulinevoffset = 0; /* how far above the bottom of the bar the line should appear */
|
||||||
|
static const int ulineall = 0; /* 1 to show underline on all tags, 0 for just the active ones */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static const char ptagf[] = "[%s %s]"; /* format of a tag label */
|
||||||
|
static const char etagf[] = "[%s]"; /* format of an empty tag */
|
||||||
|
static const int lcaselbl = 0; /* 1 means make tag label lowercase */
|
||||||
|
static const Rule rules[] = {
|
||||||
|
/* xprop(1):
|
||||||
|
* WM_CLASS(STRING) = instance, class
|
||||||
|
* WM_NAME(STRING) = title
|
||||||
|
*/
|
||||||
|
/* class instance title tags mask isfloating CenterThisWindow? monitor */
|
||||||
|
{ "st", NULL, NULL, 0, 0, 0, -1 },
|
||||||
|
{ "Gimp", NULL, NULL, 0, 0, 0, -1 },
|
||||||
|
{ "Firefox", NULL, NULL, 1 << 8, 0, 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 */
|
||||||
|
static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
|
||||||
|
static const int decorhints = 1; /* 1 means respect decoration hints */
|
||||||
|
|
||||||
|
#include "layouts.c"
|
||||||
|
static const Layout layouts[] = {
|
||||||
|
/* symbol arrange function */
|
||||||
|
{ "[]=", tile }, /* first entry is default */
|
||||||
|
{ "><>", NULL }, /* no layout function means floating behavior */
|
||||||
|
{ "[M]", monocle },
|
||||||
|
{ "HHH", grid },
|
||||||
|
};
|
||||||
|
|
||||||
|
/* 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() */
|
||||||
|
/* replace the values with ones on col_color as an workaround */
|
||||||
|
static const char *dmenucmd[] = { "j4-dmenu-desktop", "--dmenu", "dmenu -fn 'Hack Nerd Font' -nb '#173f4f' -nf '#ffffff' -sb '#124f5f' -sf '#eeeeee' -g 6 -l 6 ", "--term", "st", NULL };
|
||||||
|
static const char *dmenualt[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_color1, "-nf", col_color3, "-sb", col_color5, "-sf", col_color4, "-g", "6", "-l", "6", NULL};
|
||||||
|
static const char *termcmd[] = { "st", NULL };
|
||||||
|
static const char *tabtermcmd[] = { "tabbed", "-r 2", "st", "-w", "''", NULL };
|
||||||
|
static const char *firefoxcmd[] = { "firefox", NULL };
|
||||||
|
static const char *thunarcmd[] = { "Dolphin", NULL };
|
||||||
|
|
||||||
|
#include "shiftview.c"
|
||||||
|
static Key keys[] = {
|
||||||
|
/* modifier key function argument */
|
||||||
|
{ Mod4Mask, XK_s, spawn, {.v = dmenucmd } },
|
||||||
|
{ Mod4Mask|ShiftMask, XK_s, spawn, {.v = dmenualt } },
|
||||||
|
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
|
||||||
|
{ MODKEY|ShiftMask, XK_t, spawn, {.v = tabtermcmd } },
|
||||||
|
{ MODKEY|ShiftMask, XK_i, spawn, {.v = firefoxcmd } },
|
||||||
|
{ Mod4Mask, XK_e, spawn, {.v = thunarcmd } },
|
||||||
|
{ Mod4Mask, XK_Print, spawn, SHCMD("maim ~/Pictures/Screenshot_$(date +%s).png") },
|
||||||
|
{ MODKEY|ShiftMask, XK_b, togglebar, {0} },
|
||||||
|
{ MODKEY, XK_j, focusstackvis, {.i = +1 } },
|
||||||
|
{ MODKEY, XK_k, focusstackvis, {.i = -1 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_j, focusstackhid, {.i = +1 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_k, focusstackhid, {.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, XK_q, view, {0} },
|
||||||
|
{ MODKEY|ShiftMask, XK_x, 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_g, setlayout, {.v = &layouts[3]} },
|
||||||
|
{ MODKEY, XK_space, setlayout, {0} },
|
||||||
|
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
|
||||||
|
{ MODKEY|ShiftMask, XK_f, togglefullscr, {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, XK_s, show, {0} },
|
||||||
|
{ MODKEY, XK_h, hide, {0} },
|
||||||
|
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
|
||||||
|
{ MODKEY, XK_minus, setgaps, {.i = -1 } },
|
||||||
|
{ MODKEY, XK_equal, setgaps, {.i = +1 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_equal, setgaps, {.i = 0 } },
|
||||||
|
{ Mod1Mask, XK_Tab, altTabStart, {0} },
|
||||||
|
{ MODKEY, XK_n, shiftview, { .i = +1 } },
|
||||||
|
{ MODKEY, XK_b, shiftview, { .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 */
|
||||||
|
{ ClkButton, 0, Button1, spawn, {.v = dmenucmd } },
|
||||||
|
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
|
||||||
|
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
|
||||||
|
{ ClkWinTitle, 0, Button1, togglewin, {0} },
|
||||||
|
{ 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} },
|
||||||
|
};
|
||||||
|
|
164
dwm/config.def.h.bak
Normal file
164
dwm/config.def.h.bak
Normal file
|
@ -0,0 +1,164 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
|
||||||
|
/* appearance */
|
||||||
|
static const unsigned int borderpx = 1; /* border pixel of windows */
|
||||||
|
static const unsigned int gappx = 5; /* gaps between 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 user_bh = 3; /* 2 is the default spacing around the bar's font */
|
||||||
|
static const char buttonbar[] = " Start";
|
||||||
|
#define ICONSIZE bh /* icon size */
|
||||||
|
#define ICONSPACING 5 /* space between icon and title */
|
||||||
|
static const char *fonts[] = { "Hack Nerd Font:size=12" };
|
||||||
|
static const char dmenufont[] = "Hack Nerd Font:size=12";
|
||||||
|
static const char col_color1[] = "#204E98";
|
||||||
|
static const char col_color2[] = "#204E98";
|
||||||
|
static const char col_color3[] = "#ffffff";
|
||||||
|
static const char col_color4[] = "#eeeeee";
|
||||||
|
static const char col_color5[] = "#3465a2";
|
||||||
|
static const unsigned int baralpha = 0xd0;
|
||||||
|
static const unsigned int borderalpha = OPAQUE;
|
||||||
|
static const char *colors[][3] = {
|
||||||
|
/* fg bg border */
|
||||||
|
[SchemeNorm] = { col_color3, col_color1, col_color2 },
|
||||||
|
[SchemeSel] = { col_color4, col_color5, col_color5 },
|
||||||
|
[SchemeHid] = { col_color5, col_color1, col_color5 },
|
||||||
|
};
|
||||||
|
static const unsigned int alphas[][3] = {
|
||||||
|
/* fg bg border */
|
||||||
|
[SchemeNorm] = { OPAQUE, baralpha, borderalpha },
|
||||||
|
[SchemeSel] = { OPAQUE, baralpha, borderalpha },
|
||||||
|
};
|
||||||
|
|
||||||
|
/* tagging */
|
||||||
|
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
||||||
|
static const char *alttags[] = { "<01>", "<02>", "<03>", "<04>", "<05>" };
|
||||||
|
|
||||||
|
static const unsigned int ulinepad = 5; /* horizontal padding between the underline and tag */
|
||||||
|
static const unsigned int ulinestroke = 1; /* thickness / height of the underline */
|
||||||
|
static const unsigned int ulinevoffset = 0; /* how far above the bottom of the bar the line should appear */
|
||||||
|
static const int ulineall = 0; /* 1 to show underline on all tags, 0 for just the active ones */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static const char ptagf[] = "[%s %s]"; /* format of a tag label */
|
||||||
|
static const char etagf[] = "[%s]"; /* format of an empty tag */
|
||||||
|
static const int lcaselbl = 0; /* 1 means make tag label lowercase */
|
||||||
|
static const Rule rules[] = {
|
||||||
|
/* xprop(1):
|
||||||
|
* WM_CLASS(STRING) = instance, class
|
||||||
|
* WM_NAME(STRING) = title
|
||||||
|
*/
|
||||||
|
/* class instance title tags mask isfloating CenterThisWindow? monitor */
|
||||||
|
{ "st", NULL, NULL, 0, 0, 0, -1 },
|
||||||
|
{ "Gimp", NULL, NULL, 0, 0, 0, -1 },
|
||||||
|
{ "Firefox", NULL, NULL, 1 << 8, 0, 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 */
|
||||||
|
static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
|
||||||
|
|
||||||
|
#include "layouts.c"
|
||||||
|
static const Layout layouts[] = {
|
||||||
|
/* symbol arrange function */
|
||||||
|
{ "[]=", tile }, /* first entry is default */
|
||||||
|
{ "><>", NULL }, /* no layout function means floating behavior */
|
||||||
|
{ "[M]", monocle },
|
||||||
|
{ "HHH", grid },
|
||||||
|
};
|
||||||
|
|
||||||
|
/* 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_color1, "-nf", col_color3, "-sb", col_color5, "-sf", col_color4, "-g", "6", "-l", "6", NULL };
|
||||||
|
static const char *termcmd[] = { "st", NULL };
|
||||||
|
static const char *tabtermcmd[] = { "tabbed", "-r 2", "st", "-w", "''", NULL };
|
||||||
|
static const char *firefoxcmd[] = { "firefox", NULL };
|
||||||
|
static const char *thunarcmd[] = { "Thunar", NULL };
|
||||||
|
|
||||||
|
#include "shiftview.c"
|
||||||
|
static Key keys[] = {
|
||||||
|
/* modifier key function argument */
|
||||||
|
{ Mod4Mask, XK_s, spawn, {.v = dmenucmd } },
|
||||||
|
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
|
||||||
|
{ MODKEY|ShiftMask, XK_t, spawn, {.v = tabtermcmd } },
|
||||||
|
{ MODKEY|ShiftMask, XK_i, spawn, {.v = firefoxcmd } },
|
||||||
|
{ Mod4Mask, XK_e, spawn, {.v = thunarcmd } },
|
||||||
|
{ Mod4Mask, XK_Print, spawn, SHCMD("maim ~/Pictures/Screenshot_$(date +%s).png") },
|
||||||
|
{ MODKEY|ShiftMask, XK_b, togglebar, {0} },
|
||||||
|
{ MODKEY, XK_j, focusstackvis, {.i = +1 } },
|
||||||
|
{ MODKEY, XK_k, focusstackvis, {.i = -1 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_j, focusstackhid, {.i = +1 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_k, focusstackhid, {.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, XK_Tab, view, {0} },
|
||||||
|
{ MODKEY|ShiftMask, XK_x, 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_g, setlayout, {.v = &layouts[3]} },
|
||||||
|
{ MODKEY, XK_space, setlayout, {0} },
|
||||||
|
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
|
||||||
|
{ MODKEY|ShiftMask, XK_f, togglefullscr, {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, XK_s, show, {0} },
|
||||||
|
{ MODKEY, XK_h, hide, {0} },
|
||||||
|
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
|
||||||
|
{ MODKEY, XK_minus, setgaps, {.i = -1 } },
|
||||||
|
{ MODKEY, XK_equal, setgaps, {.i = +1 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_equal, setgaps, {.i = 0 } },
|
||||||
|
{ MODKEY, XK_n, shiftview, { .i = +1 } },
|
||||||
|
{ MODKEY, XK_b, shiftview, { .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 */
|
||||||
|
{ ClkButton, 0, Button1, spawn, {.v = dmenucmd } },
|
||||||
|
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
|
||||||
|
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
|
||||||
|
{ ClkWinTitle, 0, Button1, togglewin, {0} },
|
||||||
|
{ 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} },
|
||||||
|
};
|
||||||
|
|
178
dwm/config.h
Normal file
178
dwm/config.h
Normal file
|
@ -0,0 +1,178 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
|
||||||
|
/* alt-tab configuration */
|
||||||
|
static const unsigned int tabModKey = 0x40; /* if this key is hold the alt-tab functionality stays acitve. This key must be the same as key that is used to active functin altTabStart `*/
|
||||||
|
static const unsigned int tabCycleKey = 0x17; /* if this key is hit the alt-tab program moves one position forward in clients stack. This key must be the same as key that is used to active functin altTabStart */
|
||||||
|
static const unsigned int tabPosY = 1; /* tab position on Y axis, 0 = bottom, 1 = center, 2 = top */
|
||||||
|
static const unsigned int tabPosX = 1; /* tab position on X axis, 0 = left, 1 = center, 2 = right */
|
||||||
|
static const unsigned int maxWTab = 600; /* tab menu width */
|
||||||
|
static const unsigned int maxHTab = 200; /* tab menu height */
|
||||||
|
|
||||||
|
/* appearance */
|
||||||
|
static const unsigned int borderpx = 1; /* border pixel of windows */
|
||||||
|
static const unsigned int gappx = 5; /* gaps between 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 user_bh = 2; /* 2 is the default spacing around the bar's font */
|
||||||
|
static const char buttonbar[] = " Start";
|
||||||
|
#define ICONSIZE bh /* icon size */
|
||||||
|
#define ICONSPACING 5 /* space between icon and title */
|
||||||
|
static const int focusonwheel = 0;
|
||||||
|
static const char *fonts[] = { "Hack Nerd Font:size=14" };
|
||||||
|
static const char dmenufont[] = "Hack Nerd Font:size=14";
|
||||||
|
static const char col_color1[] = "#173f4f";
|
||||||
|
static const char col_color2[] = "#173f4f";
|
||||||
|
static const char col_color3[] = "#ffffff";
|
||||||
|
static const char col_color4[] = "#eeeeee";
|
||||||
|
static const char col_color5[] = "#124f5f";
|
||||||
|
static const unsigned int baralpha = 0xd0;
|
||||||
|
static const unsigned int borderalpha = OPAQUE;
|
||||||
|
static const char *colors[][3] = {
|
||||||
|
/* fg bg border */
|
||||||
|
[SchemeNorm] = { col_color3, col_color1, col_color2 },
|
||||||
|
[SchemeSel] = { col_color4, col_color5, col_color5 },
|
||||||
|
[SchemeHid] = { col_color5, col_color1, col_color5 },
|
||||||
|
};
|
||||||
|
static const unsigned int alphas[][3] = {
|
||||||
|
/* fg bg border */
|
||||||
|
[SchemeNorm] = { OPAQUE, baralpha, borderalpha },
|
||||||
|
[SchemeSel] = { OPAQUE, baralpha, borderalpha },
|
||||||
|
};
|
||||||
|
|
||||||
|
/* tagging */
|
||||||
|
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
||||||
|
static const char *alttags[] = { "<01>", "<02>", "<03>", "<04>", "<05>" };
|
||||||
|
|
||||||
|
static const unsigned int ulinepad = 5; /* horizontal padding between the underline and tag */
|
||||||
|
static const unsigned int ulinestroke = 1; /* thickness / height of the underline */
|
||||||
|
static const unsigned int ulinevoffset = 0; /* how far above the bottom of the bar the line should appear */
|
||||||
|
static const int ulineall = 0; /* 1 to show underline on all tags, 0 for just the active ones */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static const char ptagf[] = "[%s %s]"; /* format of a tag label */
|
||||||
|
static const char etagf[] = "[%s]"; /* format of an empty tag */
|
||||||
|
static const int lcaselbl = 0; /* 1 means make tag label lowercase */
|
||||||
|
static const Rule rules[] = {
|
||||||
|
/* xprop(1):
|
||||||
|
* WM_CLASS(STRING) = instance, class
|
||||||
|
* WM_NAME(STRING) = title
|
||||||
|
*/
|
||||||
|
/* class instance title tags mask isfloating CenterThisWindow? monitor */
|
||||||
|
{ "st", NULL, NULL, 0, 0, 0, -1 },
|
||||||
|
{ "Gimp", NULL, NULL, 0, 0, 0, -1 },
|
||||||
|
{ "Firefox", NULL, NULL, 1 << 8, 0, 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 */
|
||||||
|
static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
|
||||||
|
static const int decorhints = 1; /* 1 means respect decoration hints */
|
||||||
|
|
||||||
|
#include "layouts.c"
|
||||||
|
static const Layout layouts[] = {
|
||||||
|
/* symbol arrange function */
|
||||||
|
{ "[]=", tile }, /* first entry is default */
|
||||||
|
{ "><>", NULL }, /* no layout function means floating behavior */
|
||||||
|
{ "[M]", monocle },
|
||||||
|
{ "HHH", grid },
|
||||||
|
};
|
||||||
|
|
||||||
|
/* 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() */
|
||||||
|
/* replace the values with ones on col_color as an workaround */
|
||||||
|
static const char *dmenucmd[] = { "j4-dmenu-desktop", "--dmenu", "dmenu -fn 'Hack Nerd Font' -nb '#173f4f' -nf '#ffffff' -sb '#124f5f' -sf '#eeeeee' -g 6 -l 6 ", "--term", "st", NULL };
|
||||||
|
static const char *dmenualt[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_color1, "-nf", col_color3, "-sb", col_color5, "-sf", col_color4, "-g", "6", "-l", "6", NULL};
|
||||||
|
static const char *termcmd[] = { "st", NULL };
|
||||||
|
static const char *tabtermcmd[] = { "tabbed", "-r 2", "st", "-w", "''", NULL };
|
||||||
|
static const char *firefoxcmd[] = { "firefox", NULL };
|
||||||
|
static const char *thunarcmd[] = { "Dolphin", NULL };
|
||||||
|
|
||||||
|
#include "shiftview.c"
|
||||||
|
static Key keys[] = {
|
||||||
|
/* modifier key function argument */
|
||||||
|
{ Mod4Mask, XK_s, spawn, {.v = dmenucmd } },
|
||||||
|
{ Mod4Mask|ShiftMask, XK_s, spawn, {.v = dmenualt } },
|
||||||
|
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
|
||||||
|
{ MODKEY|ShiftMask, XK_t, spawn, {.v = tabtermcmd } },
|
||||||
|
{ MODKEY|ShiftMask, XK_i, spawn, {.v = firefoxcmd } },
|
||||||
|
{ Mod4Mask, XK_e, spawn, {.v = thunarcmd } },
|
||||||
|
{ Mod4Mask, XK_Print, spawn, SHCMD("maim ~/Pictures/Screenshot_$(date +%s).png") },
|
||||||
|
{ MODKEY|ShiftMask, XK_b, togglebar, {0} },
|
||||||
|
{ MODKEY, XK_j, focusstackvis, {.i = +1 } },
|
||||||
|
{ MODKEY, XK_k, focusstackvis, {.i = -1 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_j, focusstackhid, {.i = +1 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_k, focusstackhid, {.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, XK_q, view, {0} },
|
||||||
|
{ MODKEY|ShiftMask, XK_x, 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_g, setlayout, {.v = &layouts[3]} },
|
||||||
|
{ MODKEY, XK_space, setlayout, {0} },
|
||||||
|
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
|
||||||
|
{ MODKEY|ShiftMask, XK_f, togglefullscr, {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, XK_s, show, {0} },
|
||||||
|
{ MODKEY, XK_h, hide, {0} },
|
||||||
|
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
|
||||||
|
{ MODKEY, XK_minus, setgaps, {.i = -1 } },
|
||||||
|
{ MODKEY, XK_equal, setgaps, {.i = +1 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_equal, setgaps, {.i = 0 } },
|
||||||
|
{ Mod1Mask, XK_Tab, altTabStart, {0} },
|
||||||
|
{ MODKEY, XK_n, shiftview, { .i = +1 } },
|
||||||
|
{ MODKEY, XK_b, shiftview, { .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 */
|
||||||
|
{ ClkButton, 0, Button1, spawn, {.v = dmenucmd } },
|
||||||
|
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
|
||||||
|
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
|
||||||
|
{ ClkWinTitle, 0, Button1, togglewin, {0} },
|
||||||
|
{ 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} },
|
||||||
|
};
|
||||||
|
|
38
dwm/config.mk
Normal file
38
dwm/config.mk
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
# dwm version
|
||||||
|
VERSION = 6.3
|
||||||
|
|
||||||
|
# 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} -lXrender -lImlib2
|
||||||
|
|
||||||
|
# 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 -O3 -march=native ${INCS} ${CPPFLAGS}
|
||||||
|
LDFLAGS = ${LIBS}
|
||||||
|
|
||||||
|
# Solaris
|
||||||
|
#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
|
||||||
|
#LDFLAGS = ${LIBS}
|
||||||
|
|
||||||
|
# compiler and linker
|
||||||
|
CC = gcc
|
513
dwm/drw.c
Normal file
513
dwm/drw.c
Normal file
|
@ -0,0 +1,513 @@
|
||||||
|
/* 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 <Imlib2.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, Visual *visual, unsigned int depth, Colormap cmap)
|
||||||
|
{
|
||||||
|
Drw *drw = ecalloc(1, sizeof(Drw));
|
||||||
|
|
||||||
|
drw->dpy = dpy;
|
||||||
|
drw->screen = screen;
|
||||||
|
drw->root = root;
|
||||||
|
drw->w = w;
|
||||||
|
drw->h = h;
|
||||||
|
drw->visual = visual;
|
||||||
|
drw->depth = depth;
|
||||||
|
drw->cmap = cmap;
|
||||||
|
drw->drawable = XCreatePixmap(dpy, root, w, h, depth);
|
||||||
|
drw->picture = XRenderCreatePicture(dpy, drw->drawable, XRenderFindVisualFormat(dpy, visual), 0, NULL);
|
||||||
|
drw->gc = XCreateGC(dpy, drw->drawable, 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->picture)
|
||||||
|
XRenderFreePicture(drw->dpy, drw->picture);
|
||||||
|
if (drw->drawable)
|
||||||
|
XFreePixmap(drw->dpy, drw->drawable);
|
||||||
|
drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, drw->depth);
|
||||||
|
drw->picture = XRenderCreatePicture(drw->dpy, drw->drawable, XRenderFindVisualFormat(drw->dpy, drw->visual), 0, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
drw_free(Drw *drw)
|
||||||
|
{
|
||||||
|
XRenderFreePicture(drw->dpy, drw->picture);
|
||||||
|
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, unsigned int alpha)
|
||||||
|
{
|
||||||
|
if (!drw || !dest || !clrname)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!XftColorAllocName(drw->dpy, drw->visual, drw->cmap,
|
||||||
|
clrname, dest))
|
||||||
|
die("error, cannot allocate color '%s'", clrname);
|
||||||
|
|
||||||
|
dest->pixel = (dest->pixel & 0x00ffffffU) | (alpha << 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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[], const unsigned int alphas[], 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], alphas[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;
|
||||||
|
}
|
||||||
|
|
||||||
|
Picture
|
||||||
|
drw_picture_create_resized(Drw *drw, char *src, unsigned int srcw, unsigned int srch, unsigned int dstw, unsigned int dsth) {
|
||||||
|
Pixmap pm;
|
||||||
|
Picture pic;
|
||||||
|
GC gc;
|
||||||
|
|
||||||
|
if (srcw <= (dstw << 1u) && srch <= (dsth << 1u)) {
|
||||||
|
XImage img = {
|
||||||
|
srcw, srch, 0, ZPixmap, src,
|
||||||
|
ImageByteOrder(drw->dpy), BitmapUnit(drw->dpy), BitmapBitOrder(drw->dpy), 32,
|
||||||
|
32, 0, 32,
|
||||||
|
0, 0, 0
|
||||||
|
};
|
||||||
|
XInitImage(&img);
|
||||||
|
|
||||||
|
pm = XCreatePixmap(drw->dpy, drw->root, srcw, srch, 32);
|
||||||
|
gc = XCreateGC(drw->dpy, pm, 0, NULL);
|
||||||
|
XPutImage(drw->dpy, pm, gc, &img, 0, 0, 0, 0, srcw, srch);
|
||||||
|
XFreeGC(drw->dpy, gc);
|
||||||
|
|
||||||
|
pic = XRenderCreatePicture(drw->dpy, pm, XRenderFindStandardFormat(drw->dpy, PictStandardARGB32), 0, NULL);
|
||||||
|
XFreePixmap(drw->dpy, pm);
|
||||||
|
|
||||||
|
XRenderSetPictureFilter(drw->dpy, pic, FilterBilinear, NULL, 0);
|
||||||
|
XTransform xf;
|
||||||
|
xf.matrix[0][0] = (srcw << 16u) / dstw; xf.matrix[0][1] = 0; xf.matrix[0][2] = 0;
|
||||||
|
xf.matrix[1][0] = 0; xf.matrix[1][1] = (srch << 16u) / dsth; xf.matrix[1][2] = 0;
|
||||||
|
xf.matrix[2][0] = 0; xf.matrix[2][1] = 0; xf.matrix[2][2] = 65536;
|
||||||
|
XRenderSetPictureTransform(drw->dpy, pic, &xf);
|
||||||
|
} else {
|
||||||
|
Imlib_Image origin = imlib_create_image_using_data(srcw, srch, (DATA32 *)src);
|
||||||
|
if (!origin) return None;
|
||||||
|
imlib_context_set_image(origin);
|
||||||
|
imlib_image_set_has_alpha(1);
|
||||||
|
Imlib_Image scaled = imlib_create_cropped_scaled_image(0, 0, srcw, srch, dstw, dsth);
|
||||||
|
imlib_free_image_and_decache();
|
||||||
|
if (!scaled) return None;
|
||||||
|
imlib_context_set_image(scaled);
|
||||||
|
imlib_image_set_has_alpha(1);
|
||||||
|
|
||||||
|
XImage img = {
|
||||||
|
dstw, dsth, 0, ZPixmap, (char *)imlib_image_get_data_for_reading_only(),
|
||||||
|
ImageByteOrder(drw->dpy), BitmapUnit(drw->dpy), BitmapBitOrder(drw->dpy), 32,
|
||||||
|
32, 0, 32,
|
||||||
|
0, 0, 0
|
||||||
|
};
|
||||||
|
XInitImage(&img);
|
||||||
|
|
||||||
|
pm = XCreatePixmap(drw->dpy, drw->root, dstw, dsth, 32);
|
||||||
|
gc = XCreateGC(drw->dpy, pm, 0, NULL);
|
||||||
|
XPutImage(drw->dpy, pm, gc, &img, 0, 0, 0, 0, dstw, dsth);
|
||||||
|
imlib_free_image_and_decache();
|
||||||
|
XFreeGC(drw->dpy, gc);
|
||||||
|
|
||||||
|
pic = XRenderCreatePicture(drw->dpy, pm, XRenderFindStandardFormat(drw->dpy, PictStandardARGB32), 0, NULL);
|
||||||
|
XFreePixmap(drw->dpy, pm);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pic;
|
||||||
|
}
|
||||||
|
|
||||||
|
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, drw->visual, drw->cmap);
|
||||||
|
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_pic(Drw *drw, int x, int y, unsigned int w, unsigned int h, Picture pic)
|
||||||
|
{
|
||||||
|
if (!drw)
|
||||||
|
return;
|
||||||
|
XRenderComposite(drw->dpy, PictOpOver, pic, None, drw->picture, 0, 0, 0, 0, x, y, w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
64
dwm/drw.h
Normal file
64
dwm/drw.h
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
/* 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;
|
||||||
|
Visual *visual;
|
||||||
|
unsigned int depth;
|
||||||
|
Colormap cmap;
|
||||||
|
Drawable drawable;
|
||||||
|
Picture picture;
|
||||||
|
GC gc;
|
||||||
|
Clr *scheme;
|
||||||
|
Fnt *fonts;
|
||||||
|
} Drw;
|
||||||
|
|
||||||
|
/* Drawable abstraction */
|
||||||
|
Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap);
|
||||||
|
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, unsigned int alpha);
|
||||||
|
Clr *drw_scm_create(Drw *drw, const char *clrnames[], const unsigned int alphas[], 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);
|
||||||
|
|
||||||
|
Picture drw_picture_create_resized(Drw *drw, char *src, unsigned int src_w, unsigned int src_h, unsigned int dst_w, unsigned int dst_h);
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
void drw_pic(Drw *drw, int x, int y, unsigned int w, unsigned int h, Picture pic);
|
||||||
|
|
||||||
|
/* Map functions */
|
||||||
|
void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h);
|
179
dwm/dwm.1
Normal file
179
dwm/dwm.1
Normal file
|
@ -0,0 +1,179 @@
|
||||||
|
.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\-f
|
||||||
|
Toggle fullscreen for 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.
|
BIN
dwm/dwm.png
Normal file
BIN
dwm/dwm.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 373 B |
30
dwm/get-xkey.c
Normal file
30
dwm/get-xkey.c
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
Display *dpy;
|
||||||
|
Window win;
|
||||||
|
XEvent e;
|
||||||
|
int s;
|
||||||
|
|
||||||
|
dpy = XOpenDisplay(NULL);
|
||||||
|
if (dpy == NULL) {
|
||||||
|
fprintf(stderr, "Cannot open display\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
s = DefaultScreen(dpy);
|
||||||
|
win = XCreateSimpleWindow(dpy, RootWindow(dpy, s), 10, 10, 100, 100, 0, 0, 0);
|
||||||
|
XSelectInput(dpy, win, ExposureMask | KeyPressMask);
|
||||||
|
XMapWindow(dpy, win);
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
XNextEvent(dpy, &e);
|
||||||
|
if (e.type == KeyPress)
|
||||||
|
printf("0x%x\n",e.xkey.keycode);
|
||||||
|
}
|
||||||
|
|
||||||
|
XCloseDisplay(dpy);
|
||||||
|
return 0;
|
||||||
|
}
|
8
dwm/layoutmenu.sh
Executable file
8
dwm/layoutmenu.sh
Executable file
|
@ -0,0 +1,8 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
cat <<EOF | xmenu
|
||||||
|
[]= Tiled Layout 0
|
||||||
|
><> Floating Layout 1
|
||||||
|
[M] Monocle Layout 2
|
||||||
|
HHH Grid Layout 3
|
||||||
|
EOF
|
27
dwm/layouts.c
Normal file
27
dwm/layouts.c
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
void
|
||||||
|
grid(Monitor *m) {
|
||||||
|
unsigned int i, n, cx, cy, cw, ch, aw, ah, cols, rows;
|
||||||
|
Client *c;
|
||||||
|
|
||||||
|
for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next))
|
||||||
|
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 / (rows ? rows : 1);
|
||||||
|
cw = m->ww / (cols ? cols : 1);
|
||||||
|
for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
|
||||||
|
cx = m->wx + (i / rows) * cw;
|
||||||
|
cy = m->wy + (i % rows) * ch;
|
||||||
|
/* adjust height/width of last row/column's windows */
|
||||||
|
ah = ((i + 1) % rows == 0) ? m->wh - ch * rows : 0;
|
||||||
|
aw = (i >= rows * (cols - 1)) ? m->ww - cw * cols : 0;
|
||||||
|
resize(c, cx, cy, cw - 2 * c->bw + aw, ch - 2 * c->bw + ah, False);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
68
dwm/patches/dwm-actualfullscreen.diff
Normal file
68
dwm/patches/dwm-actualfullscreen.diff
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
From eea13010ffc3983392857ee1e3804e3aa1064d7a Mon Sep 17 00:00:00 2001
|
||||||
|
From: Soenke Lambert <s.lambert@mittwald.de>
|
||||||
|
Date: Wed, 13 Oct 2021 18:21:09 +0200
|
||||||
|
Subject: [PATCH] Fullscreen current window with [Alt]+[Shift]+[f]
|
||||||
|
|
||||||
|
This actually fullscreens a window, instead of just hiding the statusbar
|
||||||
|
and applying the monocle layout.
|
||||||
|
---
|
||||||
|
config.def.h | 1 +
|
||||||
|
dwm.1 | 3 +++
|
||||||
|
dwm.c | 8 ++++++++
|
||||||
|
3 files changed, 12 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index 1c0b587..8cd3204 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -78,6 +78,7 @@ static Key keys[] = {
|
||||||
|
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
|
||||||
|
{ MODKEY, XK_space, setlayout, {0} },
|
||||||
|
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
|
||||||
|
+ { MODKEY|ShiftMask, XK_f, togglefullscr, {0} },
|
||||||
|
{ MODKEY, XK_0, view, {.ui = ~0 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
|
||||||
|
{ MODKEY, XK_comma, focusmon, {.i = -1 } },
|
||||||
|
diff --git a/dwm.1 b/dwm.1
|
||||||
|
index 13b3729..a368d05 100644
|
||||||
|
--- a/dwm.1
|
||||||
|
+++ b/dwm.1
|
||||||
|
@@ -116,6 +116,9 @@ Zooms/cycles focused window to/from master area (tiled layouts only).
|
||||||
|
.B Mod1\-Shift\-c
|
||||||
|
Close focused window.
|
||||||
|
.TP
|
||||||
|
+.B Mod1\-Shift\-f
|
||||||
|
+Toggle fullscreen for focused window.
|
||||||
|
+.TP
|
||||||
|
.B Mod1\-Shift\-space
|
||||||
|
Toggle focused window between tiled and floating state.
|
||||||
|
.TP
|
||||||
|
diff --git a/dwm.c b/dwm.c
|
||||||
|
index 4465af1..c1b899a 100644
|
||||||
|
--- a/dwm.c
|
||||||
|
+++ b/dwm.c
|
||||||
|
@@ -211,6 +211,7 @@ static void tagmon(const Arg *arg);
|
||||||
|
static void tile(Monitor *);
|
||||||
|
static void togglebar(const Arg *arg);
|
||||||
|
static void togglefloating(const Arg *arg);
|
||||||
|
+static void togglefullscr(const Arg *arg);
|
||||||
|
static void toggletag(const Arg *arg);
|
||||||
|
static void toggleview(const Arg *arg);
|
||||||
|
static void unfocus(Client *c, int setfocus);
|
||||||
|
@@ -1719,6 +1720,13 @@ togglefloating(const Arg *arg)
|
||||||
|
arrange(selmon);
|
||||||
|
}
|
||||||
|
|
||||||
|
+void
|
||||||
|
+togglefullscr(const Arg *arg)
|
||||||
|
+{
|
||||||
|
+ if(selmon->sel)
|
||||||
|
+ setfullscreen(selmon->sel, !selmon->sel->isfullscreen);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
void
|
||||||
|
toggletag(const Arg *arg)
|
||||||
|
{
|
||||||
|
--
|
||||||
|
2.30.2
|
||||||
|
|
297
dwm/patches/dwm-alpha.diff
Normal file
297
dwm/patches/dwm-alpha.diff
Normal file
|
@ -0,0 +1,297 @@
|
||||||
|
From 29ce86e6162c47ee5cd830df5781a572e3fed43e Mon Sep 17 00:00:00 2001
|
||||||
|
From: Bakkeby <bakkeby@gmail.com>
|
||||||
|
Date: Mon, 10 Jan 2022 10:55:28 +0100
|
||||||
|
Subject: [PATCH] Alpha, adds transparency for the status bar.
|
||||||
|
|
||||||
|
Allow dwm to have translucent bars, while keeping all the text on it opaque, just like the alpha-patch for st.
|
||||||
|
|
||||||
|
Refer to https://dwm.suckless.org/patches/alpha/
|
||||||
|
|
||||||
|
Authors:
|
||||||
|
|
||||||
|
Eon S. Jeon - esjeon@hyunmu.am
|
||||||
|
Laslo Hunhold - dev@frign.de (6.1 port)
|
||||||
|
Thomas Oltmann - thomas.oltmann.hhg@gmail.com (20180613-b69c870 port)
|
||||||
|
---
|
||||||
|
config.def.h | 7 ++++++
|
||||||
|
config.mk | 2 +-
|
||||||
|
drw.c | 26 ++++++++++++-----------
|
||||||
|
drw.h | 9 +++++---
|
||||||
|
dwm.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++------
|
||||||
|
5 files changed, 82 insertions(+), 22 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index a2ac963..ca7a9ba 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -12,11 +12,18 @@ 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 unsigned int baralpha = 0xd0;
|
||||||
|
+static const unsigned int borderalpha = OPAQUE;
|
||||||
|
static const char *colors[][3] = {
|
||||||
|
/* fg bg border */
|
||||||
|
[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
|
||||||
|
[SchemeSel] = { col_gray4, col_cyan, col_cyan },
|
||||||
|
};
|
||||||
|
+static const unsigned int alphas[][3] = {
|
||||||
|
+ /* fg bg border */
|
||||||
|
+ [SchemeNorm] = { OPAQUE, baralpha, borderalpha },
|
||||||
|
+ [SchemeSel] = { OPAQUE, baralpha, borderalpha },
|
||||||
|
+};
|
||||||
|
|
||||||
|
/* tagging */
|
||||||
|
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
||||||
|
diff --git a/config.mk b/config.mk
|
||||||
|
index b6eb7e0..848aef9 100644
|
||||||
|
--- a/config.mk
|
||||||
|
+++ b/config.mk
|
||||||
|
@@ -22,7 +22,7 @@ FREETYPEINC = /usr/include/freetype2
|
||||||
|
|
||||||
|
# includes and libs
|
||||||
|
INCS = -I${X11INC} -I${FREETYPEINC}
|
||||||
|
-LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS}
|
||||||
|
+LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lXrender
|
||||||
|
|
||||||
|
# flags
|
||||||
|
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
|
||||||
|
diff --git a/drw.c b/drw.c
|
||||||
|
index 4cdbcbe..fe3aadd 100644
|
||||||
|
--- a/drw.c
|
||||||
|
+++ b/drw.c
|
||||||
|
@@ -61,7 +61,7 @@ utf8decode(const char *c, long *u, size_t clen)
|
||||||
|
}
|
||||||
|
|
||||||
|
Drw *
|
||||||
|
-drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h)
|
||||||
|
+drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap)
|
||||||
|
{
|
||||||
|
Drw *drw = ecalloc(1, sizeof(Drw));
|
||||||
|
|
||||||
|
@@ -70,8 +70,11 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h
|
||||||
|
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);
|
||||||
|
+ drw->visual = visual;
|
||||||
|
+ drw->depth = depth;
|
||||||
|
+ drw->cmap = cmap;
|
||||||
|
+ drw->drawable = XCreatePixmap(dpy, root, w, h, depth);
|
||||||
|
+ drw->gc = XCreateGC(dpy, drw->drawable, 0, NULL);
|
||||||
|
XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
|
||||||
|
|
||||||
|
return drw;
|
||||||
|
@@ -87,7 +90,7 @@ drw_resize(Drw *drw, unsigned int w, unsigned int h)
|
||||||
|
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));
|
||||||
|
+ drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, drw->depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
@@ -194,21 +197,22 @@ drw_fontset_free(Fnt *font)
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
-drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
|
||||||
|
+drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha)
|
||||||
|
{
|
||||||
|
if (!drw || !dest || !clrname)
|
||||||
|
return;
|
||||||
|
|
||||||
|
- if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
|
||||||
|
- DefaultColormap(drw->dpy, drw->screen),
|
||||||
|
+ if (!XftColorAllocName(drw->dpy, drw->visual, drw->cmap,
|
||||||
|
clrname, dest))
|
||||||
|
die("error, cannot allocate color '%s'", clrname);
|
||||||
|
+
|
||||||
|
+ dest->pixel = (dest->pixel & 0x00ffffffU) | (alpha << 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wrapper to create color schemes. The caller ha 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)
|
||||||
|
+drw_scm_create(Drw *drw, const char *clrnames[], const unsigned int alphas[], size_t clrcount)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
Clr *ret;
|
||||||
|
@@ -218,7 +222,7 @@ drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
for (i = 0; i < clrcount; i++)
|
||||||
|
- drw_clr_create(drw, &ret[i], clrnames[i]);
|
||||||
|
+ drw_clr_create(drw, &ret[i], clrnames[i], alphas[i]);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -274,9 +278,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
|
||||||
|
} 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));
|
||||||
|
+ d = XftDrawCreate(drw->dpy, drw->drawable, drw->visual, drw->cmap);
|
||||||
|
x += lpad;
|
||||||
|
w -= lpad;
|
||||||
|
}
|
||||||
|
diff --git a/drw.h b/drw.h
|
||||||
|
index 4bcd5ad..a56f523 100644
|
||||||
|
--- a/drw.h
|
||||||
|
+++ b/drw.h
|
||||||
|
@@ -20,6 +20,9 @@ typedef struct {
|
||||||
|
Display *dpy;
|
||||||
|
int screen;
|
||||||
|
Window root;
|
||||||
|
+ Visual *visual;
|
||||||
|
+ unsigned int depth;
|
||||||
|
+ Colormap cmap;
|
||||||
|
Drawable drawable;
|
||||||
|
GC gc;
|
||||||
|
Clr *scheme;
|
||||||
|
@@ -27,7 +30,7 @@ typedef struct {
|
||||||
|
} Drw;
|
||||||
|
|
||||||
|
/* Drawable abstraction */
|
||||||
|
-Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h);
|
||||||
|
+Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap);
|
||||||
|
void drw_resize(Drw *drw, unsigned int w, unsigned int h);
|
||||||
|
void drw_free(Drw *drw);
|
||||||
|
|
||||||
|
@@ -38,8 +41,8 @@ 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);
|
||||||
|
+void drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha);
|
||||||
|
+Clr *drw_scm_create(Drw *drw, const char *clrnames[], const unsigned int alphas[], size_t clrcount);
|
||||||
|
|
||||||
|
/* Cursor abstraction */
|
||||||
|
Cur *drw_cur_create(Drw *drw, int shape);
|
||||||
|
diff --git a/dwm.c b/dwm.c
|
||||||
|
index a96f33c..34b9a32 100644
|
||||||
|
--- a/dwm.c
|
||||||
|
+++ b/dwm.c
|
||||||
|
@@ -57,6 +57,8 @@
|
||||||
|
#define TAGMASK ((1 << LENGTH(tags)) - 1)
|
||||||
|
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
|
||||||
|
|
||||||
|
+#define OPAQUE 0xffU
|
||||||
|
+
|
||||||
|
/* enums */
|
||||||
|
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
|
||||||
|
enum { SchemeNorm, SchemeSel }; /* color schemes */
|
||||||
|
@@ -233,6 +235,7 @@ static Monitor *wintomon(Window w);
|
||||||
|
static int xerror(Display *dpy, XErrorEvent *ee);
|
||||||
|
static int xerrordummy(Display *dpy, XErrorEvent *ee);
|
||||||
|
static int xerrorstart(Display *dpy, XErrorEvent *ee);
|
||||||
|
+static void xinitvisual();
|
||||||
|
static void zoom(const Arg *arg);
|
||||||
|
|
||||||
|
/* variables */
|
||||||
|
@@ -269,6 +272,11 @@ static Drw *drw;
|
||||||
|
static Monitor *mons, *selmon;
|
||||||
|
static Window root, wmcheckwin;
|
||||||
|
|
||||||
|
+static int useargb = 0;
|
||||||
|
+static Visual *visual;
|
||||||
|
+static int depth;
|
||||||
|
+static Colormap cmap;
|
||||||
|
+
|
||||||
|
/* configuration, allows nested code to access above variables */
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
@@ -1545,7 +1553,8 @@ setup(void)
|
||||||
|
sw = DisplayWidth(dpy, screen);
|
||||||
|
sh = DisplayHeight(dpy, screen);
|
||||||
|
root = RootWindow(dpy, screen);
|
||||||
|
- drw = drw_create(dpy, screen, root, sw, sh);
|
||||||
|
+ xinitvisual();
|
||||||
|
+ drw = drw_create(dpy, screen, root, sw, sh, visual, depth, cmap);
|
||||||
|
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
|
||||||
|
die("no fonts could be loaded.");
|
||||||
|
lrpad = drw->fonts->h;
|
||||||
|
@@ -1573,7 +1582,7 @@ setup(void)
|
||||||
|
/* init appearance */
|
||||||
|
scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
|
||||||
|
for (i = 0; i < LENGTH(colors); i++)
|
||||||
|
- scheme[i] = drw_scm_create(drw, colors[i], 3);
|
||||||
|
+ scheme[i] = drw_scm_create(drw, colors[i], alphas[i], 3);
|
||||||
|
/* init bars */
|
||||||
|
updatebars();
|
||||||
|
updatestatus();
|
||||||
|
@@ -1810,16 +1819,18 @@ updatebars(void)
|
||||||
|
Monitor *m;
|
||||||
|
XSetWindowAttributes wa = {
|
||||||
|
.override_redirect = True,
|
||||||
|
- .background_pixmap = ParentRelative,
|
||||||
|
+ .background_pixel = 0,
|
||||||
|
+ .border_pixel = 0,
|
||||||
|
+ .colormap = cmap,
|
||||||
|
.event_mask = ButtonPressMask|ExposureMask
|
||||||
|
};
|
||||||
|
XClassHint ch = {"dwm", "dwm"};
|
||||||
|
for (m = mons; m; m = m->next) {
|
||||||
|
if (m->barwin)
|
||||||
|
continue;
|
||||||
|
- m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen),
|
||||||
|
- CopyFromParent, DefaultVisual(dpy, screen),
|
||||||
|
- CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
|
||||||
|
+ m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, depth,
|
||||||
|
+ InputOutput, visual,
|
||||||
|
+ CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &wa);
|
||||||
|
XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
|
||||||
|
XMapRaised(dpy, m->barwin);
|
||||||
|
XSetClassHint(dpy, m->barwin, &ch);
|
||||||
|
@@ -2116,6 +2127,43 @@ xerrorstart(Display *dpy, XErrorEvent *ee)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
+void
|
||||||
|
+xinitvisual()
|
||||||
|
+{
|
||||||
|
+ XVisualInfo *infos;
|
||||||
|
+ XRenderPictFormat *fmt;
|
||||||
|
+ int nitems;
|
||||||
|
+ int i;
|
||||||
|
+
|
||||||
|
+ XVisualInfo tpl = {
|
||||||
|
+ .screen = screen,
|
||||||
|
+ .depth = 32,
|
||||||
|
+ .class = TrueColor
|
||||||
|
+ };
|
||||||
|
+ long masks = VisualScreenMask | VisualDepthMask | VisualClassMask;
|
||||||
|
+
|
||||||
|
+ infos = XGetVisualInfo(dpy, masks, &tpl, &nitems);
|
||||||
|
+ visual = NULL;
|
||||||
|
+ for(i = 0; i < nitems; i ++) {
|
||||||
|
+ fmt = XRenderFindVisualFormat(dpy, infos[i].visual);
|
||||||
|
+ if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
|
||||||
|
+ visual = infos[i].visual;
|
||||||
|
+ depth = infos[i].depth;
|
||||||
|
+ cmap = XCreateColormap(dpy, root, visual, AllocNone);
|
||||||
|
+ useargb = 1;
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ XFree(infos);
|
||||||
|
+
|
||||||
|
+ if (! visual) {
|
||||||
|
+ visual = DefaultVisual(dpy, screen);
|
||||||
|
+ depth = DefaultDepth(dpy, screen);
|
||||||
|
+ cmap = DefaultColormap(dpy, screen);
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
void
|
||||||
|
zoom(const Arg *arg)
|
||||||
|
{
|
||||||
|
--
|
||||||
|
2.19.1
|
||||||
|
s
|
321
dwm/patches/dwm-alttab-20220709-d3f93c7.diff
Normal file
321
dwm/patches/dwm-alttab-20220709-d3f93c7.diff
Normal file
|
@ -0,0 +1,321 @@
|
||||||
|
From ec9fcfe019623ec6aff6476b6838eb4863098cf0 Mon Sep 17 00:00:00 2001
|
||||||
|
From: ViliamKovac1223 <viliamkovac1223@gmail.com>
|
||||||
|
Date: Sat, 9 Jul 2022 02:58:18 +0200
|
||||||
|
Subject: [PATCH] add alt-tab functionality
|
||||||
|
|
||||||
|
---
|
||||||
|
config.def.h | 11 ++-
|
||||||
|
dwm.c | 218 +++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
2 files changed, 228 insertions(+), 1 deletion(-)
|
||||||
|
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index a2ac963..3760870 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -1,5 +1,13 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
|
||||||
|
+/* alt-tab configuration */
|
||||||
|
+static const unsigned int tabModKey = 0x40; /* if this key is hold the alt-tab functionality stays acitve. This key must be the same as key that is used to active functin altTabStart `*/
|
||||||
|
+static const unsigned int tabCycleKey = 0x17; /* if this key is hit the alt-tab program moves one position forward in clients stack. This key must be the same as key that is used to active functin altTabStart */
|
||||||
|
+static const unsigned int tabPosY = 1; /* tab position on Y axis, 0 = bottom, 1 = center, 2 = top */
|
||||||
|
+static const unsigned int tabPosX = 1; /* tab position on X axis, 0 = left, 1 = center, 2 = right */
|
||||||
|
+static const unsigned int maxWTab = 600; /* tab menu width */
|
||||||
|
+static const unsigned int maxHTab = 200; /* tab menu height */
|
||||||
|
+
|
||||||
|
/* appearance */
|
||||||
|
static const unsigned int borderpx = 1; /* border pixel of windows */
|
||||||
|
static const unsigned int snap = 32; /* snap pixel */
|
||||||
|
@@ -72,7 +80,7 @@ static Key keys[] = {
|
||||||
|
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
|
||||||
|
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
|
||||||
|
{ MODKEY, XK_Return, zoom, {0} },
|
||||||
|
- { MODKEY, XK_Tab, view, {0} },
|
||||||
|
+ { MODKEY, XK_q, view, {0} },
|
||||||
|
{ MODKEY|ShiftMask, XK_c, killclient, {0} },
|
||||||
|
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
|
||||||
|
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
|
||||||
|
@@ -85,6 +93,7 @@ static Key keys[] = {
|
||||||
|
{ MODKEY, XK_period, focusmon, {.i = +1 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
|
||||||
|
+ { Mod1Mask, XK_Tab, altTabStart, {0} },
|
||||||
|
TAGKEYS( XK_1, 0)
|
||||||
|
TAGKEYS( XK_2, 1)
|
||||||
|
TAGKEYS( XK_3, 2)
|
||||||
|
diff --git a/dwm.c b/dwm.c
|
||||||
|
index 5646a5c..90edf9b 100644
|
||||||
|
--- a/dwm.c
|
||||||
|
+++ b/dwm.c
|
||||||
|
@@ -40,6 +40,7 @@
|
||||||
|
#include <X11/extensions/Xinerama.h>
|
||||||
|
#endif /* XINERAMA */
|
||||||
|
#include <X11/Xft/Xft.h>
|
||||||
|
+#include <time.h>
|
||||||
|
|
||||||
|
#include "drw.h"
|
||||||
|
#include "util.h"
|
||||||
|
@@ -119,6 +120,11 @@ struct Monitor {
|
||||||
|
int by; /* bar geometry */
|
||||||
|
int mx, my, mw, mh; /* screen size */
|
||||||
|
int wx, wy, ww, wh; /* window area */
|
||||||
|
+ int altTabN; /* move that many clients forward */
|
||||||
|
+ int nTabs; /* number of active clients in tag */
|
||||||
|
+ int isAlt; /* 1,0 */
|
||||||
|
+ int maxWTab;
|
||||||
|
+ int maxHTab;
|
||||||
|
unsigned int seltags;
|
||||||
|
unsigned int sellt;
|
||||||
|
unsigned int tagset[2];
|
||||||
|
@@ -127,8 +133,10 @@ struct Monitor {
|
||||||
|
Client *clients;
|
||||||
|
Client *sel;
|
||||||
|
Client *stack;
|
||||||
|
+ Client ** altsnext; /* array of all clients in the tag */
|
||||||
|
Monitor *next;
|
||||||
|
Window barwin;
|
||||||
|
+ Window tabwin;
|
||||||
|
const Layout *lt[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
@@ -234,6 +242,9 @@ 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);
|
||||||
|
+void drawTab(int nwins, int first, Monitor *m);
|
||||||
|
+void altTabStart(const Arg *arg);
|
||||||
|
+static void altTabEnd();
|
||||||
|
|
||||||
|
/* variables */
|
||||||
|
static const char broken[] = "broken";
|
||||||
|
@@ -477,6 +488,7 @@ cleanup(void)
|
||||||
|
Monitor *m;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
+ altTabEnd();
|
||||||
|
view(&a);
|
||||||
|
selmon->lt[selmon->sellt] = &foo;
|
||||||
|
for (m = mons; m; m = m->next)
|
||||||
|
@@ -644,6 +656,7 @@ createmon(void)
|
||||||
|
m->topbar = topbar;
|
||||||
|
m->lt[0] = &layouts[0];
|
||||||
|
m->lt[1] = &layouts[1 % LENGTH(layouts)];
|
||||||
|
+ m->nTabs = 0;
|
||||||
|
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
@@ -1659,6 +1672,211 @@ spawn(const Arg *arg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
+void
|
||||||
|
+altTab()
|
||||||
|
+{
|
||||||
|
+ /* move to next window */
|
||||||
|
+ if (selmon->sel != NULL && selmon->sel->snext != NULL) {
|
||||||
|
+ selmon->altTabN++;
|
||||||
|
+ if (selmon->altTabN >= selmon->nTabs)
|
||||||
|
+ selmon->altTabN = 0; /* reset altTabN */
|
||||||
|
+
|
||||||
|
+ focus(selmon->altsnext[selmon->altTabN]);
|
||||||
|
+ restack(selmon);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /* redraw tab */
|
||||||
|
+ XRaiseWindow(dpy, selmon->tabwin);
|
||||||
|
+ drawTab(selmon->nTabs, 0, selmon);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+void
|
||||||
|
+altTabEnd()
|
||||||
|
+{
|
||||||
|
+ if (selmon->isAlt == 0)
|
||||||
|
+ return;
|
||||||
|
+
|
||||||
|
+ /*
|
||||||
|
+ * move all clients between 1st and choosen position,
|
||||||
|
+ * one down in stack and put choosen client to the first position
|
||||||
|
+ * so they remain in right order for the next time that alt-tab is used
|
||||||
|
+ */
|
||||||
|
+ if (selmon->nTabs > 1) {
|
||||||
|
+ if (selmon->altTabN != 0) { /* if user picked original client do nothing */
|
||||||
|
+ Client *buff = selmon->altsnext[selmon->altTabN];
|
||||||
|
+ if (selmon->altTabN > 1)
|
||||||
|
+ for (int i = selmon->altTabN;i > 0;i--)
|
||||||
|
+ selmon->altsnext[i] = selmon->altsnext[i - 1];
|
||||||
|
+ else /* swap them if there are just 2 clients */
|
||||||
|
+ selmon->altsnext[selmon->altTabN] = selmon->altsnext[0];
|
||||||
|
+ selmon->altsnext[0] = buff;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /* restack clients */
|
||||||
|
+ for (int i = selmon->nTabs - 1;i >= 0;i--) {
|
||||||
|
+ focus(selmon->altsnext[i]);
|
||||||
|
+ restack(selmon);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ free(selmon->altsnext); /* free list of clients */
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /* turn off/destroy the window */
|
||||||
|
+ selmon->isAlt = 0;
|
||||||
|
+ selmon->nTabs = 0;
|
||||||
|
+ XUnmapWindow(dpy, selmon->tabwin);
|
||||||
|
+ XDestroyWindow(dpy, selmon->tabwin);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+void
|
||||||
|
+drawTab(int nwins, int first, Monitor *m)
|
||||||
|
+{
|
||||||
|
+ /* little documentation of 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); */
|
||||||
|
+ /* void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h); */
|
||||||
|
+
|
||||||
|
+ Client *c;
|
||||||
|
+ int h;
|
||||||
|
+
|
||||||
|
+ if (first) {
|
||||||
|
+ Monitor *m = selmon;
|
||||||
|
+ XSetWindowAttributes wa = {
|
||||||
|
+ .override_redirect = True,
|
||||||
|
+ .background_pixmap = ParentRelative,
|
||||||
|
+ .event_mask = ButtonPressMask|ExposureMask
|
||||||
|
+ };
|
||||||
|
+
|
||||||
|
+ selmon->maxWTab = maxWTab;
|
||||||
|
+ selmon->maxHTab = maxHTab;
|
||||||
|
+
|
||||||
|
+ /* decide position of tabwin */
|
||||||
|
+ int posX = 0;
|
||||||
|
+ int posY = 0;
|
||||||
|
+ if (tabPosX == 0)
|
||||||
|
+ posX = 0;
|
||||||
|
+ if (tabPosX == 1)
|
||||||
|
+ posX = (selmon->mw / 2) - (maxWTab / 2);
|
||||||
|
+ if (tabPosX == 2)
|
||||||
|
+ posX = selmon->mw - maxWTab;
|
||||||
|
+
|
||||||
|
+ if (tabPosY == 0)
|
||||||
|
+ posY = selmon->mh - maxHTab;
|
||||||
|
+ if (tabPosY == 1)
|
||||||
|
+ posY = (selmon->mh / 2) - (maxHTab / 2);
|
||||||
|
+ if (tabPosY == 2)
|
||||||
|
+ posY = 0;
|
||||||
|
+
|
||||||
|
+ h = selmon->maxHTab;
|
||||||
|
+ /* XCreateWindow(display, parent, x, y, width, height, border_width, depth, class, visual, valuemask, attributes); just reference */
|
||||||
|
+ m->tabwin = XCreateWindow(dpy, root, posX, posY, selmon->maxWTab, selmon->maxHTab, 2, DefaultDepth(dpy, screen),
|
||||||
|
+ CopyFromParent, DefaultVisual(dpy, screen),
|
||||||
|
+ CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); /* create tabwin */
|
||||||
|
+
|
||||||
|
+ XDefineCursor(dpy, m->tabwin, cursor[CurNormal]->cursor);
|
||||||
|
+ XMapRaised(dpy, m->tabwin);
|
||||||
|
+
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ h = selmon->maxHTab / m->nTabs;
|
||||||
|
+
|
||||||
|
+ int y = 0;
|
||||||
|
+ int n = 0;
|
||||||
|
+ for (int i = 0;i < m->nTabs;i++) { /* draw all clients into tabwin */
|
||||||
|
+ c = m->altsnext[i];
|
||||||
|
+ if(!ISVISIBLE(c)) continue;
|
||||||
|
+ /* if (HIDDEN(c)) continue; uncomment if you're using awesomebar patch */
|
||||||
|
+
|
||||||
|
+ n++;
|
||||||
|
+ drw_setscheme(drw, scheme[(c == m->sel) ? SchemeSel : SchemeNorm]);
|
||||||
|
+ drw_text(drw, 0, y, selmon->maxWTab, h, 0, c->name, 0);
|
||||||
|
+ y += h;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ drw_setscheme(drw, scheme[SchemeNorm]);
|
||||||
|
+ drw_map(drw, m->tabwin, 0, 0, selmon->maxWTab, selmon->maxHTab);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+void
|
||||||
|
+altTabStart(const Arg *arg)
|
||||||
|
+{
|
||||||
|
+ selmon->altsnext = NULL;
|
||||||
|
+ if (selmon->tabwin)
|
||||||
|
+ altTabEnd();
|
||||||
|
+
|
||||||
|
+ if (selmon->isAlt == 1) {
|
||||||
|
+ altTabEnd();
|
||||||
|
+ } else {
|
||||||
|
+ selmon->isAlt = 1;
|
||||||
|
+ selmon->altTabN = 0;
|
||||||
|
+
|
||||||
|
+ Client *c;
|
||||||
|
+ Monitor *m = selmon;
|
||||||
|
+
|
||||||
|
+ m->nTabs = 0;
|
||||||
|
+ for(c = m->clients; c; c = c->next) { /* count clients */
|
||||||
|
+ if(!ISVISIBLE(c)) continue;
|
||||||
|
+ /* if (HIDDEN(c)) continue; uncomment if you're using awesomebar patch */
|
||||||
|
+
|
||||||
|
+ ++m->nTabs;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (m->nTabs > 0) {
|
||||||
|
+ m->altsnext = (Client **) malloc(m->nTabs * sizeof(Client *));
|
||||||
|
+
|
||||||
|
+ int listIndex = 0;
|
||||||
|
+ for(c = m->stack; c; c = c->snext) { /* add clients to the list */
|
||||||
|
+ if(!ISVISIBLE(c)) continue;
|
||||||
|
+ /* if (HIDDEN(c)) continue; uncomment if you're using awesomebar patch */
|
||||||
|
+
|
||||||
|
+ m->altsnext[listIndex++] = c;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ drawTab(m->nTabs, 1, m);
|
||||||
|
+
|
||||||
|
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 1000000 };
|
||||||
|
+
|
||||||
|
+ /* grab keyboard (take all input from keyboard) */
|
||||||
|
+ int grabbed = 1;
|
||||||
|
+ for (int i = 0;i < 1000;i++) {
|
||||||
|
+ if (XGrabKeyboard(dpy, DefaultRootWindow(dpy), True, GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess)
|
||||||
|
+ break;
|
||||||
|
+ nanosleep(&ts, NULL);
|
||||||
|
+ if (i == 1000 - 1)
|
||||||
|
+ grabbed = 0;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ XEvent event;
|
||||||
|
+ altTab();
|
||||||
|
+ if (grabbed == 0) {
|
||||||
|
+ altTabEnd();
|
||||||
|
+ } else {
|
||||||
|
+ while (grabbed) {
|
||||||
|
+ XNextEvent(dpy, &event);
|
||||||
|
+ if (event.type == KeyPress || event.type == KeyRelease) {
|
||||||
|
+ if (event.type == KeyRelease && event.xkey.keycode == tabModKey) { /* if super key is released break cycle */
|
||||||
|
+ break;
|
||||||
|
+ } else if (event.type == KeyPress) {
|
||||||
|
+ if (event.xkey.keycode == tabCycleKey) {/* if XK_s is pressed move to the next window */
|
||||||
|
+ altTab();
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ c = selmon->sel;
|
||||||
|
+ altTabEnd(); /* end the alt-tab functionality */
|
||||||
|
+ /* XUngrabKeyboard(display, time); just a reference */
|
||||||
|
+ XUngrabKeyboard(dpy, CurrentTime); /* stop taking all input from keyboard */
|
||||||
|
+ focus(c);
|
||||||
|
+ restack(selmon);
|
||||||
|
+ }
|
||||||
|
+ } else {
|
||||||
|
+ altTabEnd(); /* end the alt-tab functionality */
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
void
|
||||||
|
tag(const Arg *arg)
|
||||||
|
{
|
||||||
|
--
|
||||||
|
2.35.1
|
||||||
|
|
67
dwm/patches/dwm-alttags.diff
Normal file
67
dwm/patches/dwm-alttags.diff
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index 1c0b587..d4b11fc 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -20,6 +20,7 @@ static const char *colors[][3] = {
|
||||||
|
|
||||||
|
/* tagging */
|
||||||
|
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
||||||
|
+static const char *alttags[] = { "<01>", "<02>", "<03>", "<04>", "<05>" };
|
||||||
|
|
||||||
|
static const Rule rules[] = {
|
||||||
|
/* xprop(1):
|
||||||
|
diff --git a/dwm.c b/dwm.c
|
||||||
|
index 4465af1..a394159 100644
|
||||||
|
--- a/dwm.c
|
||||||
|
+++ b/dwm.c
|
||||||
|
@@ -416,7 +416,7 @@ attachstack(Client *c)
|
||||||
|
void
|
||||||
|
buttonpress(XEvent *e)
|
||||||
|
{
|
||||||
|
- unsigned int i, x, click;
|
||||||
|
+ unsigned int i, x, click, occ;
|
||||||
|
Arg arg = {0};
|
||||||
|
Client *c;
|
||||||
|
Monitor *m;
|
||||||
|
@@ -430,9 +430,13 @@ buttonpress(XEvent *e)
|
||||||
|
focus(NULL);
|
||||||
|
}
|
||||||
|
if (ev->window == selmon->barwin) {
|
||||||
|
- i = x = 0;
|
||||||
|
+ i = x = occ = 0;
|
||||||
|
+ /* Bitmask of occupied tags */
|
||||||
|
+ for (c = m->clients; c; c = c->next)
|
||||||
|
+ occ |= c->tags;
|
||||||
|
+
|
||||||
|
do
|
||||||
|
- x += TEXTW(tags[i]);
|
||||||
|
+ x += TEXTW(occ & 1 << i ? alttags[i] : tags[i]);
|
||||||
|
while (ev->x >= x && ++i < LENGTH(tags));
|
||||||
|
if (i < LENGTH(tags)) {
|
||||||
|
click = ClkTagBar;
|
||||||
|
@@ -699,6 +703,7 @@ drawbar(Monitor *m)
|
||||||
|
int boxs = drw->fonts->h / 9;
|
||||||
|
int boxw = drw->fonts->h / 6 + 2;
|
||||||
|
unsigned int i, occ = 0, urg = 0;
|
||||||
|
+ const char *tagtext;
|
||||||
|
Client *c;
|
||||||
|
|
||||||
|
/* draw status first so it can be overdrawn by tags later */
|
||||||
|
@@ -715,13 +720,10 @@ drawbar(Monitor *m)
|
||||||
|
}
|
||||||
|
x = 0;
|
||||||
|
for (i = 0; i < LENGTH(tags); i++) {
|
||||||
|
- w = TEXTW(tags[i]);
|
||||||
|
- drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
|
||||||
|
- drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
|
||||||
|
- if (occ & 1 << i)
|
||||||
|
- drw_rect(drw, x + boxs, boxs, boxw, boxw,
|
||||||
|
- m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
|
||||||
|
- urg & 1 << i);
|
||||||
|
+ tagtext = occ & 1 << i ? alttags[i] : tags[i];
|
||||||
|
+ w = TEXTW(tagtext);
|
||||||
|
+ drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
|
||||||
|
+ drw_text(drw, x, 0, w, bh, lrpad / 2, tagtext, urg & 1 << i);
|
||||||
|
x += w;
|
||||||
|
}
|
||||||
|
w = blw = TEXTW(m->ltsymbol);
|
431
dwm/patches/dwm-awesomebar-20200907-6.2.diff
Normal file
431
dwm/patches/dwm-awesomebar-20200907-6.2.diff
Normal file
|
@ -0,0 +1,431 @@
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index 1c0b587..bb8f3f7 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -16,6 +16,7 @@ static const char *colors[][3] = {
|
||||||
|
/* fg bg border */
|
||||||
|
[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
|
||||||
|
[SchemeSel] = { col_gray4, col_cyan, col_cyan },
|
||||||
|
+ [SchemeHid] = { col_cyan, col_gray1, col_cyan },
|
||||||
|
};
|
||||||
|
|
||||||
|
/* tagging */
|
||||||
|
@@ -64,8 +65,10 @@ static Key keys[] = {
|
||||||
|
{ 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_j, focusstackvis, {.i = +1 } },
|
||||||
|
+ { MODKEY, XK_k, focusstackvis, {.i = -1 } },
|
||||||
|
+ { MODKEY|ShiftMask, XK_j, focusstackhid, {.i = +1 } },
|
||||||
|
+ { MODKEY|ShiftMask, XK_k, focusstackhid, {.i = -1 } },
|
||||||
|
{ MODKEY, XK_i, incnmaster, {.i = +1 } },
|
||||||
|
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
|
||||||
|
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
|
||||||
|
@@ -84,6 +87,8 @@ static Key keys[] = {
|
||||||
|
{ MODKEY, XK_period, focusmon, {.i = +1 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
|
||||||
|
+ { MODKEY, XK_s, show, {0} },
|
||||||
|
+ { MODKEY, XK_h, hide, {0} },
|
||||||
|
TAGKEYS( XK_1, 0)
|
||||||
|
TAGKEYS( XK_2, 1)
|
||||||
|
TAGKEYS( XK_3, 2)
|
||||||
|
@@ -102,6 +107,7 @@ static Button buttons[] = {
|
||||||
|
/* click event mask button function argument */
|
||||||
|
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
|
||||||
|
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
|
||||||
|
+ { ClkWinTitle, 0, Button1, togglewin, {0} },
|
||||||
|
{ ClkWinTitle, 0, Button2, zoom, {0} },
|
||||||
|
{ ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
|
||||||
|
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
|
||||||
|
diff --git a/dwm.c b/dwm.c
|
||||||
|
index 4465af1..e780189 100644
|
||||||
|
--- a/dwm.c
|
||||||
|
+++ b/dwm.c
|
||||||
|
@@ -50,6 +50,7 @@
|
||||||
|
#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 ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
|
||||||
|
+#define HIDDEN(C) ((getstate(C->win) == IconicState))
|
||||||
|
#define LENGTH(X) (sizeof X / sizeof X[0])
|
||||||
|
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
|
||||||
|
#define WIDTH(X) ((X)->w + 2 * (X)->bw)
|
||||||
|
@@ -59,7 +60,7 @@
|
||||||
|
|
||||||
|
/* enums */
|
||||||
|
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
|
||||||
|
-enum { SchemeNorm, SchemeSel }; /* color schemes */
|
||||||
|
+enum { SchemeNorm, SchemeSel, SchemeHid }; /* color schemes */
|
||||||
|
enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
|
||||||
|
NetWMFullscreen, NetActiveWindow, NetWMWindowType,
|
||||||
|
NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
|
||||||
|
@@ -117,6 +118,8 @@ struct Monitor {
|
||||||
|
int nmaster;
|
||||||
|
int num;
|
||||||
|
int by; /* bar geometry */
|
||||||
|
+ int btw; /* width of tasks portion of bar */
|
||||||
|
+ int bt; /* number of tasks */
|
||||||
|
int mx, my, mw, mh; /* screen size */
|
||||||
|
int wx, wy, ww, wh; /* window area */
|
||||||
|
unsigned int seltags;
|
||||||
|
@@ -124,6 +127,7 @@ struct Monitor {
|
||||||
|
unsigned int tagset[2];
|
||||||
|
int showbar;
|
||||||
|
int topbar;
|
||||||
|
+ int hidsel;
|
||||||
|
Client *clients;
|
||||||
|
Client *sel;
|
||||||
|
Client *stack;
|
||||||
|
@@ -168,12 +172,16 @@ static void expose(XEvent *e);
|
||||||
|
static void focus(Client *c);
|
||||||
|
static void focusin(XEvent *e);
|
||||||
|
static void focusmon(const Arg *arg);
|
||||||
|
-static void focusstack(const Arg *arg);
|
||||||
|
+static void focusstackvis(const Arg *arg);
|
||||||
|
+static void focusstackhid(const Arg *arg);
|
||||||
|
+static void focusstack(int inc, int vis);
|
||||||
|
static int getrootptr(int *x, int *y);
|
||||||
|
static long getstate(Window w);
|
||||||
|
static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
|
||||||
|
static void grabbuttons(Client *c, int focused);
|
||||||
|
static void grabkeys(void);
|
||||||
|
+static void hide(const Arg *arg);
|
||||||
|
+static void hidewin(Client *c);
|
||||||
|
static void incnmaster(const Arg *arg);
|
||||||
|
static void keypress(XEvent *e);
|
||||||
|
static void killclient(const Arg *arg);
|
||||||
|
@@ -203,6 +211,8 @@ static void setlayout(const Arg *arg);
|
||||||
|
static void setmfact(const Arg *arg);
|
||||||
|
static void setup(void);
|
||||||
|
static void seturgent(Client *c, int urg);
|
||||||
|
+static void show(const Arg *arg);
|
||||||
|
+static void showwin(Client *c);
|
||||||
|
static void showhide(Client *c);
|
||||||
|
static void sigchld(int unused);
|
||||||
|
static void spawn(const Arg *arg);
|
||||||
|
@@ -213,6 +223,7 @@ static void togglebar(const Arg *arg);
|
||||||
|
static void togglefloating(const Arg *arg);
|
||||||
|
static void toggletag(const Arg *arg);
|
||||||
|
static void toggleview(const Arg *arg);
|
||||||
|
+static void togglewin(const Arg *arg);
|
||||||
|
static void unfocus(Client *c, int setfocus);
|
||||||
|
static void unmanage(Client *c, int destroyed);
|
||||||
|
static void unmapnotify(XEvent *e);
|
||||||
|
@@ -439,10 +450,25 @@ buttonpress(XEvent *e)
|
||||||
|
arg.ui = 1 << i;
|
||||||
|
} else if (ev->x < x + blw)
|
||||||
|
click = ClkLtSymbol;
|
||||||
|
- else if (ev->x > selmon->ww - TEXTW(stext))
|
||||||
|
+ /* 2px right padding */
|
||||||
|
+ else if (ev->x > selmon->ww - TEXTW(stext) + lrpad - 2)
|
||||||
|
click = ClkStatusText;
|
||||||
|
- else
|
||||||
|
- click = ClkWinTitle;
|
||||||
|
+ else {
|
||||||
|
+ x += blw;
|
||||||
|
+ c = m->clients;
|
||||||
|
+
|
||||||
|
+ if (c) {
|
||||||
|
+ do {
|
||||||
|
+ if (!ISVISIBLE(c))
|
||||||
|
+ continue;
|
||||||
|
+ else
|
||||||
|
+ x += (1.0 / (double)m->bt) * m->btw;
|
||||||
|
+ } while (ev->x > x && (c = c->next));
|
||||||
|
+
|
||||||
|
+ click = ClkWinTitle;
|
||||||
|
+ arg.v = c;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
} else if ((c = wintoclient(ev->window))) {
|
||||||
|
focus(c);
|
||||||
|
restack(selmon);
|
||||||
|
@@ -452,7 +478,7 @@ buttonpress(XEvent *e)
|
||||||
|
for (i = 0; i < LENGTH(buttons); i++)
|
||||||
|
if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
|
||||||
|
&& CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
|
||||||
|
- buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
|
||||||
|
+ buttons[i].func((click == ClkTagBar || click == ClkWinTitle) && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
@@ -695,7 +721,7 @@ dirtomon(int dir)
|
||||||
|
void
|
||||||
|
drawbar(Monitor *m)
|
||||||
|
{
|
||||||
|
- int x, w, sw = 0;
|
||||||
|
+ int x, w, sw = 0, n = 0, scm;
|
||||||
|
int boxs = drw->fonts->h / 9;
|
||||||
|
int boxw = drw->fonts->h / 6 + 2;
|
||||||
|
unsigned int i, occ = 0, urg = 0;
|
||||||
|
@@ -709,6 +735,8 @@ drawbar(Monitor *m)
|
||||||
|
}
|
||||||
|
|
||||||
|
for (c = m->clients; c; c = c->next) {
|
||||||
|
+ if (ISVISIBLE(c))
|
||||||
|
+ n++;
|
||||||
|
occ |= c->tags;
|
||||||
|
if (c->isurgent)
|
||||||
|
urg |= c->tags;
|
||||||
|
@@ -729,16 +757,37 @@ drawbar(Monitor *m)
|
||||||
|
x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
|
||||||
|
|
||||||
|
if ((w = m->ww - sw - x) > bh) {
|
||||||
|
- if (m->sel) {
|
||||||
|
- drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
|
||||||
|
- drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
|
||||||
|
- if (m->sel->isfloating)
|
||||||
|
- drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
|
||||||
|
+ if (n > 0) {
|
||||||
|
+ int remainder = w % n;
|
||||||
|
+ int tabw = (1.0 / (double)n) * w + 1;
|
||||||
|
+ for (c = m->clients; c; c = c->next) {
|
||||||
|
+ if (!ISVISIBLE(c))
|
||||||
|
+ continue;
|
||||||
|
+ if (m->sel == c)
|
||||||
|
+ scm = SchemeSel;
|
||||||
|
+ else if (HIDDEN(c))
|
||||||
|
+ scm = SchemeHid;
|
||||||
|
+ else
|
||||||
|
+ scm = SchemeNorm;
|
||||||
|
+ drw_setscheme(drw, scheme[scm]);
|
||||||
|
+
|
||||||
|
+ if (remainder >= 0) {
|
||||||
|
+ if (remainder == 0) {
|
||||||
|
+ tabw--;
|
||||||
|
+ }
|
||||||
|
+ remainder--;
|
||||||
|
+ }
|
||||||
|
+ drw_text(drw, x, 0, tabw, bh, lrpad / 2, c->name, 0);
|
||||||
|
+ x += tabw;
|
||||||
|
+ }
|
||||||
|
} else {
|
||||||
|
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||||
|
drw_rect(drw, x, 0, w, bh, 1, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+ m->bt = n;
|
||||||
|
+ m->btw = w;
|
||||||
|
drw_map(drw, m->barwin, 0, 0, m->ww, bh);
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -784,9 +833,17 @@ void
|
||||||
|
focus(Client *c)
|
||||||
|
{
|
||||||
|
if (!c || !ISVISIBLE(c))
|
||||||
|
- for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
|
||||||
|
- if (selmon->sel && selmon->sel != c)
|
||||||
|
+ for (c = selmon->stack; c && (!ISVISIBLE(c) || HIDDEN(c)); c = c->snext);
|
||||||
|
+ if (selmon->sel && selmon->sel != c) {
|
||||||
|
unfocus(selmon->sel, 0);
|
||||||
|
+
|
||||||
|
+ if (selmon->hidsel) {
|
||||||
|
+ hidewin(selmon->sel);
|
||||||
|
+ if (c)
|
||||||
|
+ arrange(c->mon);
|
||||||
|
+ selmon->hidsel = 0;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
if (c) {
|
||||||
|
if (c->mon != selmon)
|
||||||
|
selmon = c->mon;
|
||||||
|
@@ -830,28 +887,57 @@ focusmon(const Arg *arg)
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
-focusstack(const Arg *arg)
|
||||||
|
+focusstackvis(const Arg *arg)
|
||||||
|
+{
|
||||||
|
+ focusstack(arg->i, 0);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+void
|
||||||
|
+focusstackhid(const Arg *arg)
|
||||||
|
+{
|
||||||
|
+ focusstack(arg->i, 1);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+void
|
||||||
|
+focusstack(int inc, int hid)
|
||||||
|
{
|
||||||
|
Client *c = NULL, *i;
|
||||||
|
|
||||||
|
- if (!selmon->sel)
|
||||||
|
+ if (!selmon->sel && !hid)
|
||||||
|
return;
|
||||||
|
- if (arg->i > 0) {
|
||||||
|
- for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next);
|
||||||
|
+ if (!selmon->clients)
|
||||||
|
+ return;
|
||||||
|
+
|
||||||
|
+ if (inc > 0) {
|
||||||
|
+ if (selmon->sel)
|
||||||
|
+ for (c = selmon->sel->next;
|
||||||
|
+ c && (!ISVISIBLE(c) || (!hid && HIDDEN(c)));
|
||||||
|
+ c = c->next);
|
||||||
|
if (!c)
|
||||||
|
- for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next);
|
||||||
|
+ for (c = selmon->clients;
|
||||||
|
+ c && (!ISVISIBLE(c) || (!hid && HIDDEN(c)));
|
||||||
|
+ c = c->next);
|
||||||
|
} else {
|
||||||
|
- for (i = selmon->clients; i != selmon->sel; i = i->next)
|
||||||
|
- if (ISVISIBLE(i))
|
||||||
|
- c = i;
|
||||||
|
+ if (selmon->sel) {
|
||||||
|
+ for (i = selmon->clients; i != selmon->sel; i = i->next)
|
||||||
|
+ if (ISVISIBLE(i) && !(!hid && HIDDEN(i)))
|
||||||
|
+ c = i;
|
||||||
|
+ } else
|
||||||
|
+ c = selmon->clients;
|
||||||
|
if (!c)
|
||||||
|
for (; i; i = i->next)
|
||||||
|
- if (ISVISIBLE(i))
|
||||||
|
+ if (ISVISIBLE(i) && !(!hid && HIDDEN(i)))
|
||||||
|
c = i;
|
||||||
|
}
|
||||||
|
+
|
||||||
|
if (c) {
|
||||||
|
focus(c);
|
||||||
|
restack(selmon);
|
||||||
|
+
|
||||||
|
+ if (HIDDEN(c)) {
|
||||||
|
+ showwin(c);
|
||||||
|
+ c->mon->hidsel = 1;
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -963,6 +1049,36 @@ grabkeys(void)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
+void
|
||||||
|
+hide(const Arg *arg)
|
||||||
|
+{
|
||||||
|
+ hidewin(selmon->sel);
|
||||||
|
+ focus(NULL);
|
||||||
|
+ arrange(selmon);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+void
|
||||||
|
+hidewin(Client *c) {
|
||||||
|
+ if (!c || HIDDEN(c))
|
||||||
|
+ return;
|
||||||
|
+
|
||||||
|
+ Window w = c->win;
|
||||||
|
+ static XWindowAttributes ra, ca;
|
||||||
|
+
|
||||||
|
+ // more or less taken directly from blackbox's hide() function
|
||||||
|
+ XGrabServer(dpy);
|
||||||
|
+ XGetWindowAttributes(dpy, root, &ra);
|
||||||
|
+ XGetWindowAttributes(dpy, w, &ca);
|
||||||
|
+ // prevent UnmapNotify events
|
||||||
|
+ XSelectInput(dpy, root, ra.your_event_mask & ~SubstructureNotifyMask);
|
||||||
|
+ XSelectInput(dpy, w, ca.your_event_mask & ~StructureNotifyMask);
|
||||||
|
+ XUnmapWindow(dpy, w);
|
||||||
|
+ setclientstate(c, IconicState);
|
||||||
|
+ XSelectInput(dpy, root, ra.your_event_mask);
|
||||||
|
+ XSelectInput(dpy, w, ca.your_event_mask);
|
||||||
|
+ XUngrabServer(dpy);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
void
|
||||||
|
incnmaster(const Arg *arg)
|
||||||
|
{
|
||||||
|
@@ -1067,12 +1183,14 @@ manage(Window w, XWindowAttributes *wa)
|
||||||
|
XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
|
||||||
|
(unsigned char *) &(c->win), 1);
|
||||||
|
XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */
|
||||||
|
- setclientstate(c, NormalState);
|
||||||
|
+ if (!HIDDEN(c))
|
||||||
|
+ setclientstate(c, NormalState);
|
||||||
|
if (c->mon == selmon)
|
||||||
|
unfocus(selmon->sel, 0);
|
||||||
|
c->mon->sel = c;
|
||||||
|
arrange(c->mon);
|
||||||
|
- XMapWindow(dpy, c->win);
|
||||||
|
+ if (!HIDDEN(c))
|
||||||
|
+ XMapWindow(dpy, c->win);
|
||||||
|
focus(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -1195,7 +1313,7 @@ movemouse(const Arg *arg)
|
||||||
|
Client *
|
||||||
|
nexttiled(Client *c)
|
||||||
|
{
|
||||||
|
- for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);
|
||||||
|
+ for (; c && (c->isfloating || !ISVISIBLE(c) || HIDDEN(c)); c = c->next);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -1248,6 +1366,16 @@ propertynotify(XEvent *e)
|
||||||
|
void
|
||||||
|
quit(const Arg *arg)
|
||||||
|
{
|
||||||
|
+ // fix: reloading dwm keeps all the hidden clients hidden
|
||||||
|
+ Monitor *m;
|
||||||
|
+ Client *c;
|
||||||
|
+ for (m = mons; m; m = m->next) {
|
||||||
|
+ if (m) {
|
||||||
|
+ for (c = m->stack; c; c = c->next)
|
||||||
|
+ if (c && HIDDEN(c)) showwin(c);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
running = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -1610,6 +1738,25 @@ seturgent(Client *c, int urg)
|
||||||
|
XFree(wmh);
|
||||||
|
}
|
||||||
|
|
||||||
|
+void
|
||||||
|
+show(const Arg *arg)
|
||||||
|
+{
|
||||||
|
+ if (selmon->hidsel)
|
||||||
|
+ selmon->hidsel = 0;
|
||||||
|
+ showwin(selmon->sel);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+void
|
||||||
|
+showwin(Client *c)
|
||||||
|
+{
|
||||||
|
+ if (!c || !HIDDEN(c))
|
||||||
|
+ return;
|
||||||
|
+
|
||||||
|
+ XMapWindow(dpy, c->win);
|
||||||
|
+ setclientstate(c, NormalState);
|
||||||
|
+ arrange(c->mon);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
void
|
||||||
|
showhide(Client *c)
|
||||||
|
{
|
||||||
|
@@ -1746,6 +1893,23 @@ toggleview(const Arg *arg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
+void
|
||||||
|
+togglewin(const Arg *arg)
|
||||||
|
+{
|
||||||
|
+ Client *c = (Client*)arg->v;
|
||||||
|
+
|
||||||
|
+ if (c == selmon->sel) {
|
||||||
|
+ hidewin(c);
|
||||||
|
+ focus(NULL);
|
||||||
|
+ arrange(c->mon);
|
||||||
|
+ } else {
|
||||||
|
+ if (HIDDEN(c))
|
||||||
|
+ showwin(c);
|
||||||
|
+ focus(c);
|
||||||
|
+ restack(selmon);
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
void
|
||||||
|
unfocus(Client *c, int setfocus)
|
||||||
|
{
|
25
dwm/patches/dwm-bar-height-spacing-6.3.diff
Normal file
25
dwm/patches/dwm-bar-height-spacing-6.3.diff
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index 1c0b587..9814500 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -5,6 +5,7 @@ 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 user_bh = 2; /* 2 is the default spacing around the bar's font */
|
||||||
|
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 4465af1..2c27cb3 100644
|
||||||
|
--- a/dwm.c
|
||||||
|
+++ b/dwm.c
|
||||||
|
@@ -1545,7 +1545,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 = drw->fonts->h + user_bh;
|
||||||
|
updategeom();
|
||||||
|
/* init atoms */
|
||||||
|
utf8string = XInternAtom(dpy, "UTF8_STRING", False);
|
30
dwm/patches/dwm-centeredtitle.diff
Normal file
30
dwm/patches/dwm-centeredtitle.diff
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
From f035e1e5abb19df5dced9c592ca986deac460435 Mon Sep 17 00:00:00 2001
|
||||||
|
From: bastila <20937049+silentfault@users.noreply.github.com>
|
||||||
|
Date: Thu, 23 Jul 2020 02:45:12 +0300
|
||||||
|
Subject: [PATCH] Fix overflow when window name is bigger than window width
|
||||||
|
|
||||||
|
---
|
||||||
|
dwm.c | 6 +++++-
|
||||||
|
1 file changed, 5 insertions(+), 1 deletion(-)
|
||||||
|
|
||||||
|
diff --git a/dwm.c b/dwm.c
|
||||||
|
index 9fd0286..42cb8dd 100644
|
||||||
|
--- a/dwm.c
|
||||||
|
+++ b/dwm.c
|
||||||
|
@@ -731,8 +731,12 @@ drawbar(Monitor *m)
|
||||||
|
|
||||||
|
if ((w = m->ww - tw - x) > bh) {
|
||||||
|
if (m->sel) {
|
||||||
|
+ /* fix overflow when window name is bigger than window width */
|
||||||
|
+ int mid = (m->ww - (int)TEXTW(m->sel->name)) / 2 - x;
|
||||||
|
+ /* make sure name will not overlap on tags even when it is very long */
|
||||||
|
+ mid = mid >= lrpad / 2 ? mid : lrpad / 2;
|
||||||
|
drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
|
||||||
|
- drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
|
||||||
|
+ drw_text(drw, x, 0, w, bh, mid, m->sel->name, 0);
|
||||||
|
if (m->sel->isfloating)
|
||||||
|
drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
|
||||||
|
} else {
|
||||||
|
--
|
||||||
|
2.27.0
|
||||||
|
|
67
dwm/patches/dwm-centerfirstwindow-6.2.diff
Normal file
67
dwm/patches/dwm-centerfirstwindow-6.2.diff
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
diff -up dwm-6.2-orig/config.def.h dwm-6.2-modd/config.def.h
|
||||||
|
--- dwm-6.2-orig/config.def.h 2019-02-02 16:55:28.000000000 +0400
|
||||||
|
+++ dwm-6.2-modd/config.def.h 2021-04-25 16:05:22.569759243 +0400
|
||||||
|
@@ -26,9 +26,10 @@ static const Rule rules[] = {
|
||||||
|
* 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 },
|
||||||
|
+ /* class instance title tags mask isfloating CenterThisWindow? monitor */
|
||||||
|
+ { "st", NULL, NULL, 0, 0, 1, -1 },
|
||||||
|
+ { "Gimp", NULL, NULL, 0, 1, 0, -1 },
|
||||||
|
+ { "Firefox", NULL, NULL, 1 << 8, 0, 0, -1 },
|
||||||
|
};
|
||||||
|
|
||||||
|
/* layout(s) */
|
||||||
|
diff -up dwm-6.2-orig/dwm.c dwm-6.2-modd/dwm.c
|
||||||
|
--- dwm-6.2-orig/dwm.c 2019-02-02 16:55:28.000000000 +0400
|
||||||
|
+++ dwm-6.2-modd/dwm.c 2021-04-25 16:06:15.368310756 +0400
|
||||||
|
@@ -92,7 +92,7 @@ struct Client {
|
||||||
|
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
|
||||||
|
int bw, oldbw;
|
||||||
|
unsigned int tags;
|
||||||
|
- int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
|
||||||
|
+ int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, CenterThisWindow;
|
||||||
|
Client *next;
|
||||||
|
Client *snext;
|
||||||
|
Monitor *mon;
|
||||||
|
@@ -138,6 +138,7 @@ typedef struct {
|
||||||
|
const char *title;
|
||||||
|
unsigned int tags;
|
||||||
|
int isfloating;
|
||||||
|
+ int CenterThisWindow;
|
||||||
|
int monitor;
|
||||||
|
} Rule;
|
||||||
|
|
||||||
|
@@ -286,6 +287,7 @@ applyrules(Client *c)
|
||||||
|
|
||||||
|
/* rule matching */
|
||||||
|
c->isfloating = 0;
|
||||||
|
+ c->CenterThisWindow = 0;
|
||||||
|
c->tags = 0;
|
||||||
|
XGetClassHint(dpy, c->win, &ch);
|
||||||
|
class = ch.res_class ? ch.res_class : broken;
|
||||||
|
@@ -298,6 +300,7 @@ applyrules(Client *c)
|
||||||
|
&& (!r->instance || strstr(instance, r->instance)))
|
||||||
|
{
|
||||||
|
c->isfloating = r->isfloating;
|
||||||
|
+ c->CenterThisWindow = r->CenterThisWindow;
|
||||||
|
c->tags |= r->tags;
|
||||||
|
for (m = mons; m && m->num != r->monitor; m = m->next);
|
||||||
|
if (m)
|
||||||
|
@@ -1694,6 +1697,13 @@ tile(Monitor *m)
|
||||||
|
resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0);
|
||||||
|
ty += HEIGHT(c);
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+ if (n == 1 && selmon->sel->CenterThisWindow)
|
||||||
|
+ resizeclient(selmon->sel,
|
||||||
|
+ (selmon->mw - selmon->mw * 0.5) / 2,
|
||||||
|
+ (selmon->mh - selmon->mh * 0.5) / 2,
|
||||||
|
+ selmon->mw * 0.5,
|
||||||
|
+ selmon->mh * 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
131
dwm/patches/dwm-decorhints-6.2.diff
Normal file
131
dwm/patches/dwm-decorhints-6.2.diff
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
From 3875094925f817e047049635514034a75275d269 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Jakub Leszczak <szatan@gecc.xyz>
|
||||||
|
Date: Sat, 18 Apr 2020 19:17:46 +0200
|
||||||
|
Subject: [PATCH] Respect decoration hints
|
||||||
|
|
||||||
|
Make dwm respect _MOTIF_WM_HINTS property. Applications use this
|
||||||
|
property to notify window managers to not draw window decorations.
|
||||||
|
|
||||||
|
Not respecting this property leads to issues with applications that draw
|
||||||
|
their own borders, like chromium (with "Use system title bar and
|
||||||
|
borders" turned off) and vlc in fullscreen mode.
|
||||||
|
---
|
||||||
|
config.def.h | 1 +
|
||||||
|
dwm.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
|
||||||
|
2 files changed, 47 insertions(+), 1 deletion(-)
|
||||||
|
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index 1c0b587..2a32635 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -35,6 +35,7 @@ static const Rule rules[] = {
|
||||||
|
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 */
|
||||||
|
+static const int decorhints = 1; /* 1 means respect decoration hints */
|
||||||
|
|
||||||
|
static const Layout layouts[] = {
|
||||||
|
/* symbol arrange function */
|
||||||
|
diff --git a/dwm.c b/dwm.c
|
||||||
|
index 4465af1..95873c7 100644
|
||||||
|
--- a/dwm.c
|
||||||
|
+++ b/dwm.c
|
||||||
|
@@ -57,6 +57,13 @@
|
||||||
|
#define TAGMASK ((1 << LENGTH(tags)) - 1)
|
||||||
|
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
|
||||||
|
|
||||||
|
+#define MWM_HINTS_FLAGS_FIELD 0
|
||||||
|
+#define MWM_HINTS_DECORATIONS_FIELD 2
|
||||||
|
+#define MWM_HINTS_DECORATIONS (1 << 1)
|
||||||
|
+#define MWM_DECOR_ALL (1 << 0)
|
||||||
|
+#define MWM_DECOR_BORDER (1 << 1)
|
||||||
|
+#define MWM_DECOR_TITLE (1 << 3)
|
||||||
|
+
|
||||||
|
/* enums */
|
||||||
|
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
|
||||||
|
enum { SchemeNorm, SchemeSel }; /* color schemes */
|
||||||
|
@@ -220,6 +227,7 @@ static void updatebarpos(Monitor *m);
|
||||||
|
static void updatebars(void);
|
||||||
|
static void updateclientlist(void);
|
||||||
|
static int updategeom(void);
|
||||||
|
+static void updatemotifhints(Client *c);
|
||||||
|
static void updatenumlockmask(void);
|
||||||
|
static void updatesizehints(Client *c);
|
||||||
|
static void updatestatus(void);
|
||||||
|
@@ -259,7 +267,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
|
||||||
|
[PropertyNotify] = propertynotify,
|
||||||
|
[UnmapNotify] = unmapnotify
|
||||||
|
};
|
||||||
|
-static Atom wmatom[WMLast], netatom[NetLast];
|
||||||
|
+static Atom wmatom[WMLast], netatom[NetLast], motifatom;
|
||||||
|
static int running = 1;
|
||||||
|
static Cur *cursor[CurLast];
|
||||||
|
static Clr **scheme;
|
||||||
|
@@ -1056,6 +1064,7 @@ manage(Window w, XWindowAttributes *wa)
|
||||||
|
updatewindowtype(c);
|
||||||
|
updatesizehints(c);
|
||||||
|
updatewmhints(c);
|
||||||
|
+ updatemotifhints(c);
|
||||||
|
XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
|
||||||
|
grabbuttons(c, 0);
|
||||||
|
if (!c->isfloating)
|
||||||
|
@@ -1242,6 +1251,8 @@ propertynotify(XEvent *e)
|
||||||
|
}
|
||||||
|
if (ev->atom == netatom[NetWMWindowType])
|
||||||
|
updatewindowtype(c);
|
||||||
|
+ if (ev->atom == motifatom)
|
||||||
|
+ updatemotifhints(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -1562,6 +1573,7 @@ setup(void)
|
||||||
|
netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
|
||||||
|
netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
|
||||||
|
netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
|
||||||
|
+ motifatom = XInternAtom(dpy, "_MOTIF_WM_HINTS", False);
|
||||||
|
/* init cursors */
|
||||||
|
cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);
|
||||||
|
cursor[CurResize] = drw_cur_create(drw, XC_sizing);
|
||||||
|
@@ -1925,6 +1937,39 @@ updategeom(void)
|
||||||
|
return dirty;
|
||||||
|
}
|
||||||
|
|
||||||
|
+void
|
||||||
|
+updatemotifhints(Client *c)
|
||||||
|
+{
|
||||||
|
+ Atom real;
|
||||||
|
+ int format;
|
||||||
|
+ unsigned char *p = NULL;
|
||||||
|
+ unsigned long n, extra;
|
||||||
|
+ unsigned long *motif;
|
||||||
|
+ int width, height;
|
||||||
|
+
|
||||||
|
+ if (!decorhints)
|
||||||
|
+ return;
|
||||||
|
+
|
||||||
|
+ if (XGetWindowProperty(dpy, c->win, motifatom, 0L, 5L, False, motifatom,
|
||||||
|
+ &real, &format, &n, &extra, &p) == Success && p != NULL) {
|
||||||
|
+ motif = (unsigned long*)p;
|
||||||
|
+ if (motif[MWM_HINTS_FLAGS_FIELD] & MWM_HINTS_DECORATIONS) {
|
||||||
|
+ width = WIDTH(c);
|
||||||
|
+ height = HEIGHT(c);
|
||||||
|
+
|
||||||
|
+ if (motif[MWM_HINTS_DECORATIONS_FIELD] & MWM_DECOR_ALL ||
|
||||||
|
+ motif[MWM_HINTS_DECORATIONS_FIELD] & MWM_DECOR_BORDER ||
|
||||||
|
+ motif[MWM_HINTS_DECORATIONS_FIELD] & MWM_DECOR_TITLE)
|
||||||
|
+ c->bw = c->oldbw = borderpx;
|
||||||
|
+ else
|
||||||
|
+ c->bw = c->oldbw = 0;
|
||||||
|
+
|
||||||
|
+ resize(c, c->x, c->y, width - (2*c->bw), height - (2*c->bw), 0);
|
||||||
|
+ }
|
||||||
|
+ XFree(p);
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
void
|
||||||
|
updatenumlockmask(void)
|
||||||
|
{
|
||||||
|
--
|
||||||
|
2.26.2
|
||||||
|
|
130
dwm/patches/dwm-focusonclick-20200110-61bb8b2.diff
Normal file
130
dwm/patches/dwm-focusonclick-20200110-61bb8b2.diff
Normal file
|
@ -0,0 +1,130 @@
|
||||||
|
From 7ac0b812540e21b470f2f6947c6cc1e30bf24b42 Mon Sep 17 00:00:00 2001
|
||||||
|
From: iofq <cjriddz@protonmail.com>
|
||||||
|
Date: Sun, 10 Jan 2021 22:43:16 -0600
|
||||||
|
Subject: [PATCH] tweak fixes floating window mouse controls
|
||||||
|
|
||||||
|
---
|
||||||
|
config.def.h | 1 +
|
||||||
|
dwm.c | 47 ++++-------------------------------------------
|
||||||
|
2 files changed, 5 insertions(+), 43 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index 1c0b587..4f2c946 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -5,6 +5,7 @@ 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 focusonwheel = 0;
|
||||||
|
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 664c527..de3e883 100644
|
||||||
|
--- a/dwm.c
|
||||||
|
+++ b/dwm.c
|
||||||
|
@@ -163,7 +163,6 @@ static void detachstack(Client *c);
|
||||||
|
static Monitor *dirtomon(int dir);
|
||||||
|
static void drawbar(Monitor *m);
|
||||||
|
static void drawbars(void);
|
||||||
|
-static void enternotify(XEvent *e);
|
||||||
|
static void expose(XEvent *e);
|
||||||
|
static void focus(Client *c);
|
||||||
|
static void focusin(XEvent *e);
|
||||||
|
@@ -182,7 +181,6 @@ static void manage(Window w, XWindowAttributes *wa);
|
||||||
|
static void mappingnotify(XEvent *e);
|
||||||
|
static void maprequest(XEvent *e);
|
||||||
|
static void monocle(Monitor *m);
|
||||||
|
-static void motionnotify(XEvent *e);
|
||||||
|
static void movemouse(const Arg *arg);
|
||||||
|
static Client *nexttiled(Client *c);
|
||||||
|
static void pop(Client *);
|
||||||
|
@@ -250,13 +248,11 @@ static void (*handler[LASTEvent]) (XEvent *) = {
|
||||||
|
[ConfigureRequest] = configurerequest,
|
||||||
|
[ConfigureNotify] = configurenotify,
|
||||||
|
[DestroyNotify] = destroynotify,
|
||||||
|
- [EnterNotify] = enternotify,
|
||||||
|
[Expose] = expose,
|
||||||
|
[FocusIn] = focusin,
|
||||||
|
[KeyPress] = keypress,
|
||||||
|
[MappingNotify] = mappingnotify,
|
||||||
|
[MapRequest] = maprequest,
|
||||||
|
- [MotionNotify] = motionnotify,
|
||||||
|
[PropertyNotify] = propertynotify,
|
||||||
|
[UnmapNotify] = unmapnotify
|
||||||
|
};
|
||||||
|
@@ -425,7 +421,8 @@ buttonpress(XEvent *e)
|
||||||
|
|
||||||
|
click = ClkRootWin;
|
||||||
|
/* focus monitor if necessary */
|
||||||
|
- if ((m = wintomon(ev->window)) && m != selmon) {
|
||||||
|
+ if ((m = wintomon(ev->window)) && m != selmon
|
||||||
|
+ && (focusonwheel || (ev->button != Button4 && ev->button != Button5))) {
|
||||||
|
unfocus(selmon->sel, 1);
|
||||||
|
selmon = m;
|
||||||
|
focus(NULL);
|
||||||
|
@@ -445,8 +442,8 @@ buttonpress(XEvent *e)
|
||||||
|
else
|
||||||
|
click = ClkWinTitle;
|
||||||
|
} else if ((c = wintoclient(ev->window))) {
|
||||||
|
- focus(c);
|
||||||
|
- restack(selmon);
|
||||||
|
+ if (focusonwheel || (ev->button != Button4 && ev->button != Button5))
|
||||||
|
+ focus(c);
|
||||||
|
XAllowEvents(dpy, ReplayPointer, CurrentTime);
|
||||||
|
click = ClkClientWin;
|
||||||
|
}
|
||||||
|
@@ -752,25 +749,6 @@ drawbars(void)
|
||||||
|
drawbar(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
-void
|
||||||
|
-enternotify(XEvent *e)
|
||||||
|
-{
|
||||||
|
- Client *c;
|
||||||
|
- Monitor *m;
|
||||||
|
- XCrossingEvent *ev = &e->xcrossing;
|
||||||
|
-
|
||||||
|
- if ((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root)
|
||||||
|
- return;
|
||||||
|
- c = wintoclient(ev->window);
|
||||||
|
- m = c ? c->mon : wintomon(ev->window);
|
||||||
|
- if (m != selmon) {
|
||||||
|
- unfocus(selmon->sel, 1);
|
||||||
|
- selmon = m;
|
||||||
|
- } else if (!c || c == selmon->sel)
|
||||||
|
- return;
|
||||||
|
- focus(c);
|
||||||
|
-}
|
||||||
|
-
|
||||||
|
void
|
||||||
|
expose(XEvent *e)
|
||||||
|
{
|
||||||
|
@@ -1116,23 +1094,6 @@ monocle(Monitor *m)
|
||||||
|
resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
-void
|
||||||
|
-motionnotify(XEvent *e)
|
||||||
|
-{
|
||||||
|
- static Monitor *mon = NULL;
|
||||||
|
- Monitor *m;
|
||||||
|
- XMotionEvent *ev = &e->xmotion;
|
||||||
|
-
|
||||||
|
- if (ev->window != root)
|
||||||
|
- return;
|
||||||
|
- if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) {
|
||||||
|
- unfocus(selmon->sel, 1);
|
||||||
|
- selmon = m;
|
||||||
|
- focus(NULL);
|
||||||
|
- }
|
||||||
|
- mon = m;
|
||||||
|
-}
|
||||||
|
-
|
||||||
|
void
|
||||||
|
movemouse(const Arg *arg)
|
||||||
|
{
|
||||||
|
--
|
||||||
|
2.30.0
|
||||||
|
|
95
dwm/patches/dwm-fullgaps-6.2.diff
Normal file
95
dwm/patches/dwm-fullgaps-6.2.diff
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index 1c0b587..38d2f6c 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -2,6 +2,7 @@
|
||||||
|
|
||||||
|
/* appearance */
|
||||||
|
static const unsigned int borderpx = 1; /* border pixel of windows */
|
||||||
|
+static const unsigned int gappx = 5; /* gaps between 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 */
|
||||||
|
@@ -84,6 +85,9 @@ static Key keys[] = {
|
||||||
|
{ MODKEY, XK_period, focusmon, {.i = +1 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
|
||||||
|
+ { MODKEY, XK_minus, setgaps, {.i = -1 } },
|
||||||
|
+ { MODKEY, XK_equal, setgaps, {.i = +1 } },
|
||||||
|
+ { MODKEY|ShiftMask, XK_equal, setgaps, {.i = 0 } },
|
||||||
|
TAGKEYS( XK_1, 0)
|
||||||
|
TAGKEYS( XK_2, 1)
|
||||||
|
TAGKEYS( XK_3, 2)
|
||||||
|
diff --git a/dwm.c b/dwm.c
|
||||||
|
index 4465af1..4363627 100644
|
||||||
|
--- a/dwm.c
|
||||||
|
+++ b/dwm.c
|
||||||
|
@@ -119,6 +119,7 @@ struct Monitor {
|
||||||
|
int by; /* bar geometry */
|
||||||
|
int mx, my, mw, mh; /* screen size */
|
||||||
|
int wx, wy, ww, wh; /* window area */
|
||||||
|
+ int gappx; /* gaps between windows */
|
||||||
|
unsigned int seltags;
|
||||||
|
unsigned int sellt;
|
||||||
|
unsigned int tagset[2];
|
||||||
|
@@ -199,6 +200,7 @@ static void sendmon(Client *c, Monitor *m);
|
||||||
|
static void setclientstate(Client *c, long state);
|
||||||
|
static void setfocus(Client *c);
|
||||||
|
static void setfullscreen(Client *c, int fullscreen);
|
||||||
|
+static void setgaps(const Arg *arg);
|
||||||
|
static void setlayout(const Arg *arg);
|
||||||
|
static void setmfact(const Arg *arg);
|
||||||
|
static void setup(void);
|
||||||
|
@@ -638,6 +640,7 @@ createmon(void)
|
||||||
|
m->nmaster = nmaster;
|
||||||
|
m->showbar = showbar;
|
||||||
|
m->topbar = topbar;
|
||||||
|
+ m->gappx = gappx;
|
||||||
|
m->lt[0] = &layouts[0];
|
||||||
|
m->lt[1] = &layouts[1 % LENGTH(layouts)];
|
||||||
|
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
|
||||||
|
@@ -1497,6 +1500,16 @@ setfullscreen(Client *c, int fullscreen)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
+void
|
||||||
|
+setgaps(const Arg *arg)
|
||||||
|
+{
|
||||||
|
+ if ((arg->i == 0) || (selmon->gappx + arg->i < 0))
|
||||||
|
+ selmon->gappx = 0;
|
||||||
|
+ else
|
||||||
|
+ selmon->gappx += arg->i;
|
||||||
|
+ arrange(selmon);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
void
|
||||||
|
setlayout(const Arg *arg)
|
||||||
|
{
|
||||||
|
@@ -1683,16 +1696,16 @@ tile(Monitor *m)
|
||||||
|
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++)
|
||||||
|
+ mw = m->ww - m->gappx;
|
||||||
|
+ for (i = 0, my = ty = m->gappx, 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);
|
||||||
|
+ h = (m->wh - my) / (MIN(n, m->nmaster) - i) - m->gappx;
|
||||||
|
+ resize(c, m->wx + m->gappx, m->wy + my, mw - (2*c->bw) - m->gappx, h - (2*c->bw), 0);
|
||||||
|
+ my += HEIGHT(c) + m->gappx;
|
||||||
|
} 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);
|
||||||
|
+ h = (m->wh - ty) / (n - i) - m->gappx;
|
||||||
|
+ resize(c, m->wx + mw + m->gappx, m->wy + ty, m->ww - mw - (2*c->bw) - 2*m->gappx, h - (2*c->bw), 0);
|
||||||
|
+ ty += HEIGHT(c) + m->gappx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
--
|
||||||
|
2.20.1
|
||||||
|
|
73
dwm/patches/dwm-gridmode.diff
Normal file
73
dwm/patches/dwm-gridmode.diff
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
From b04bb473cf9818277d33a591f7fe2dfae96afaaf Mon Sep 17 00:00:00 2001
|
||||||
|
From: Joshua Haase <hahj87@gmail.com>
|
||||||
|
Date: Mon, 15 Aug 2016 17:06:18 -0500
|
||||||
|
Subject: [PATCH] Apply modified gridmode patch.
|
||||||
|
|
||||||
|
---
|
||||||
|
config.def.h | 3 +++
|
||||||
|
layouts.c | 27 +++++++++++++++++++++++++++
|
||||||
|
2 files changed, 30 insertions(+)
|
||||||
|
create mode 100644 layouts.c
|
||||||
|
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index a9ac303..30b7c4a 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -36,11 +36,13 @@ 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 */
|
||||||
|
|
||||||
|
+#include "layouts.c"
|
||||||
|
static const Layout layouts[] = {
|
||||||
|
/* symbol arrange function */
|
||||||
|
{ "[]=", tile }, /* first entry is default */
|
||||||
|
{ "><>", NULL }, /* no layout function means floating behavior */
|
||||||
|
{ "[M]", monocle },
|
||||||
|
+ { "HHH", grid },
|
||||||
|
};
|
||||||
|
|
||||||
|
/* key definitions */
|
||||||
|
@@ -76,6 +78,7 @@ static Key keys[] = {
|
||||||
|
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
|
||||||
|
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
|
||||||
|
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
|
||||||
|
+ { MODKEY, XK_g, setlayout, {.v = &layouts[3]} },
|
||||||
|
{ MODKEY, XK_space, setlayout, {0} },
|
||||||
|
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
|
||||||
|
{ MODKEY, XK_0, view, {.ui = ~0 } },
|
||||||
|
diff --git a/layouts.c b/layouts.c
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..d26acf3
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/layouts.c
|
||||||
|
@@ -0,0 +1,27 @@
|
||||||
|
+void
|
||||||
|
+grid(Monitor *m) {
|
||||||
|
+ unsigned int i, n, cx, cy, cw, ch, aw, ah, cols, rows;
|
||||||
|
+ Client *c;
|
||||||
|
+
|
||||||
|
+ for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next))
|
||||||
|
+ 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 / (rows ? rows : 1);
|
||||||
|
+ cw = m->ww / (cols ? cols : 1);
|
||||||
|
+ for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
|
||||||
|
+ cx = m->wx + (i / rows) * cw;
|
||||||
|
+ cy = m->wy + (i % rows) * ch;
|
||||||
|
+ /* adjust height/width of last row/column's windows */
|
||||||
|
+ ah = ((i + 1) % rows == 0) ? m->wh - ch * rows : 0;
|
||||||
|
+ aw = (i >= rows * (cols - 1)) ? m->ww - cw * cols : 0;
|
||||||
|
+ resize(c, cx, cy, cw - 2 * c->bw + aw, ch - 2 * c->bw + ah, False);
|
||||||
|
+ i++;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
--
|
||||||
|
2.14.1
|
||||||
|
|
89
dwm/patches/dwm-layoutmenu-6.2.diff
Normal file
89
dwm/patches/dwm-layoutmenu-6.2.diff
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
From e45e286b3d639b90ef202996d87054cced1fd80e Mon Sep 17 00:00:00 2001
|
||||||
|
From: tdu <tdukv@protonmail.com>
|
||||||
|
Date: Mon, 31 Aug 2020 00:07:32 +0300
|
||||||
|
Subject: [PATCH] Right clicking the layout symbol opens an xmenu prompt to
|
||||||
|
select layout.
|
||||||
|
|
||||||
|
Xmenu need to be installed for this to work.
|
||||||
|
Edit layoutmenu.sh with the correct layout table, and place in PATH.
|
||||||
|
---
|
||||||
|
config.def.h | 3 ++-
|
||||||
|
dwm.c | 19 +++++++++++++++++++
|
||||||
|
layoutmenu.sh | 7 +++++++
|
||||||
|
3 files changed, 28 insertions(+), 1 deletion(-)
|
||||||
|
create mode 100755 layoutmenu.sh
|
||||||
|
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index 1c0b587..c9e0833 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -58,6 +58,7 @@ static const Layout layouts[] = {
|
||||||
|
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 const char *layoutmenu_cmd = "layoutmenu.sh";
|
||||||
|
|
||||||
|
static Key keys[] = {
|
||||||
|
/* modifier key function argument */
|
||||||
|
@@ -101,7 +102,7 @@ static Key keys[] = {
|
||||||
|
static Button buttons[] = {
|
||||||
|
/* click event mask button function argument */
|
||||||
|
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
|
||||||
|
- { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
|
||||||
|
+ { ClkLtSymbol, 0, Button3, layoutmenu, {0} },
|
||||||
|
{ ClkWinTitle, 0, Button2, zoom, {0} },
|
||||||
|
{ ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
|
||||||
|
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
|
||||||
|
diff --git a/dwm.c b/dwm.c
|
||||||
|
index 4465af1..2508a0a 100644
|
||||||
|
--- a/dwm.c
|
||||||
|
+++ b/dwm.c
|
||||||
|
@@ -177,6 +177,7 @@ static void grabkeys(void);
|
||||||
|
static void incnmaster(const Arg *arg);
|
||||||
|
static void keypress(XEvent *e);
|
||||||
|
static void killclient(const Arg *arg);
|
||||||
|
+static void layoutmenu(const Arg *arg);
|
||||||
|
static void manage(Window w, XWindowAttributes *wa);
|
||||||
|
static void mappingnotify(XEvent *e);
|
||||||
|
static void maprequest(XEvent *e);
|
||||||
|
@@ -1014,6 +1015,24 @@ killclient(const Arg *arg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
+void
|
||||||
|
+layoutmenu(const Arg *arg) {
|
||||||
|
+ FILE *p;
|
||||||
|
+ char c[3], *s;
|
||||||
|
+ int i;
|
||||||
|
+
|
||||||
|
+ if (!(p = popen(layoutmenu_cmd, "r")))
|
||||||
|
+ return;
|
||||||
|
+ s = fgets(c, sizeof(c), p);
|
||||||
|
+ pclose(p);
|
||||||
|
+
|
||||||
|
+ if (!s || *s == '\0' || c[0] == '\0')
|
||||||
|
+ return;
|
||||||
|
+
|
||||||
|
+ i = atoi(c);
|
||||||
|
+ setlayout(&((Arg) { .v = &layouts[i] }));
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
void
|
||||||
|
manage(Window w, XWindowAttributes *wa)
|
||||||
|
{
|
||||||
|
diff --git a/layoutmenu.sh b/layoutmenu.sh
|
||||||
|
new file mode 100755
|
||||||
|
index 0000000..1bf95f2
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/layoutmenu.sh
|
||||||
|
@@ -0,0 +1,7 @@
|
||||||
|
+#!/bin/sh
|
||||||
|
+
|
||||||
|
+cat <<EOF | xmenu
|
||||||
|
+[]= Tiled Layout 0
|
||||||
|
+><> Floating Layout 1
|
||||||
|
+[M] Monocle Layout 2
|
||||||
|
+EOF
|
||||||
|
--
|
||||||
|
2.28.0
|
||||||
|
|
92
dwm/patches/dwm-statusbutton-20180524-c8e9479.diff
Normal file
92
dwm/patches/dwm-statusbutton-20180524-c8e9479.diff
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
From 63515eaf23d3f32f12d159c5e84af09f3a2d3323 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Christopher Drelich <cd@cdrakka.com>
|
||||||
|
Date: Thu, 24 May 2018 20:26:42 -0400
|
||||||
|
Subject: [PATCH] Added left-hand side statusbar button.
|
||||||
|
|
||||||
|
---
|
||||||
|
config.def.h | 2 ++
|
||||||
|
dwm.c | 34 +++++++++++++++++++++-------------
|
||||||
|
2 files changed, 23 insertions(+), 13 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index a9ac303..63ff917 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -5,6 +5,7 @@ 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 char buttonbar[] = "<O>";
|
||||||
|
static const char *fonts[] = { "monospace:size=10" };
|
||||||
|
static const char dmenufont[] = "monospace:size=10";
|
||||||
|
static const char col_gray1[] = "#222222";
|
||||||
|
@@ -100,6 +101,7 @@ static Key keys[] = {
|
||||||
|
/* click can be ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
|
||||||
|
static Button buttons[] = {
|
||||||
|
/* click event mask button function argument */
|
||||||
|
+ { ClkButton, 0, Button1, spawn, {.v = dmenucmd } },
|
||||||
|
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
|
||||||
|
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
|
||||||
|
{ ClkWinTitle, 0, Button2, zoom, {0} },
|
||||||
|
diff --git a/dwm.c b/dwm.c
|
||||||
|
index bb95e26..689cb01 100644
|
||||||
|
--- a/dwm.c
|
||||||
|
+++ b/dwm.c
|
||||||
|
@@ -64,7 +64,7 @@ enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
|
||||||
|
NetWMFullscreen, NetActiveWindow, NetWMWindowType,
|
||||||
|
NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
|
||||||
|
enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
|
||||||
|
-enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
|
||||||
|
+enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkButton, ClkWinTitle,
|
||||||
|
ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
@@ -431,18 +431,23 @@ buttonpress(XEvent *e)
|
||||||
|
}
|
||||||
|
if (ev->window == selmon->barwin) {
|
||||||
|
i = x = 0;
|
||||||
|
- do
|
||||||
|
- x += TEXTW(tags[i]);
|
||||||
|
- while (ev->x >= x && ++i < LENGTH(tags));
|
||||||
|
- if (i < LENGTH(tags)) {
|
||||||
|
- click = ClkTagBar;
|
||||||
|
- arg.ui = 1 << i;
|
||||||
|
- } else if (ev->x < x + blw)
|
||||||
|
- click = ClkLtSymbol;
|
||||||
|
- else if (ev->x > selmon->ww - TEXTW(stext))
|
||||||
|
- click = ClkStatusText;
|
||||||
|
- else
|
||||||
|
- click = ClkWinTitle;
|
||||||
|
+ x += TEXTW(buttonbar);
|
||||||
|
+ if(ev->x < x) {
|
||||||
|
+ click = ClkButton;
|
||||||
|
+ } else {
|
||||||
|
+ do
|
||||||
|
+ x += TEXTW(tags[i]);
|
||||||
|
+ while (ev->x >= x && ++i < LENGTH(tags));
|
||||||
|
+ if (i < LENGTH(tags)) {
|
||||||
|
+ click = ClkTagBar;
|
||||||
|
+ arg.ui = 1 << i;
|
||||||
|
+ } else if (ev->x < x + blw)
|
||||||
|
+ click = ClkLtSymbol;
|
||||||
|
+ else if (ev->x > selmon->ww - TEXTW(stext))
|
||||||
|
+ click = ClkStatusText;
|
||||||
|
+ else
|
||||||
|
+ click = ClkWinTitle;
|
||||||
|
+ }
|
||||||
|
} else if ((c = wintoclient(ev->window))) {
|
||||||
|
focus(c);
|
||||||
|
restack(selmon);
|
||||||
|
@@ -714,6 +719,9 @@ drawbar(Monitor *m)
|
||||||
|
urg |= c->tags;
|
||||||
|
}
|
||||||
|
x = 0;
|
||||||
|
+ w = blw = TEXTW(buttonbar);
|
||||||
|
+ drw_setscheme(drw, scheme[SchemeNorm]);
|
||||||
|
+ x = drw_text(drw, x, 0, w, bh, lrpad / 2, buttonbar, 0);
|
||||||
|
for (i = 0; i < LENGTH(tags); i++) {
|
||||||
|
w = TEXTW(tags[i]);
|
||||||
|
drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
|
||||||
|
--
|
||||||
|
2.7.4
|
||||||
|
|
64
dwm/patches/dwm-steam.diff
Normal file
64
dwm/patches/dwm-steam.diff
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
From 2550931c66e10e667ce56a6761cbadd12b331c52 Mon Sep 17 00:00:00 2001
|
||||||
|
From: bakkeby <bakkeby@gmail.com>
|
||||||
|
Date: Mon, 10 Aug 2020 16:45:00 +0200
|
||||||
|
Subject: [PATCH] Steam patch
|
||||||
|
|
||||||
|
Steam, and steam windows (games), trigger a ConfigureNotify request every time the window
|
||||||
|
gets focus. More so, the configure event passed along from Steam tends to have the wrong
|
||||||
|
x and y coordinates which can make the window, if floating, jump around the screen.
|
||||||
|
|
||||||
|
This patch works around this age-old issue by ignoring the x and y co-ordinates for
|
||||||
|
ConfigureNotify requests relating to Steam windows.
|
||||||
|
---
|
||||||
|
dwm.c | 20 +++++++++++++-------
|
||||||
|
1 file changed, 13 insertions(+), 7 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/dwm.c b/dwm.c
|
||||||
|
index 4465af1..598d36d 100644
|
||||||
|
--- a/dwm.c
|
||||||
|
+++ b/dwm.c
|
||||||
|
@@ -93,6 +93,7 @@ struct Client {
|
||||||
|
int bw, oldbw;
|
||||||
|
unsigned int tags;
|
||||||
|
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
|
||||||
|
+ int issteam;
|
||||||
|
Client *next;
|
||||||
|
Client *snext;
|
||||||
|
Monitor *mon;
|
||||||
|
@@ -291,6 +292,9 @@ applyrules(Client *c)
|
||||||
|
class = ch.res_class ? ch.res_class : broken;
|
||||||
|
instance = ch.res_name ? ch.res_name : broken;
|
||||||
|
|
||||||
|
+ if (strstr(class, "Steam") || strstr(class, "steam_app_"))
|
||||||
|
+ c->issteam = 1;
|
||||||
|
+
|
||||||
|
for (i = 0; i < LENGTH(rules); i++) {
|
||||||
|
r = &rules[i];
|
||||||
|
if ((!r->title || strstr(c->name, r->title))
|
||||||
|
@@ -588,13 +592,15 @@ configurerequest(XEvent *e)
|
||||||
|
c->bw = ev->border_width;
|
||||||
|
else if (c->isfloating || !selmon->lt[selmon->sellt]->arrange) {
|
||||||
|
m = c->mon;
|
||||||
|
- if (ev->value_mask & CWX) {
|
||||||
|
- c->oldx = c->x;
|
||||||
|
- c->x = m->mx + ev->x;
|
||||||
|
- }
|
||||||
|
- if (ev->value_mask & CWY) {
|
||||||
|
- c->oldy = c->y;
|
||||||
|
- c->y = m->my + ev->y;
|
||||||
|
+ if (!c->issteam) {
|
||||||
|
+ if (ev->value_mask & CWX) {
|
||||||
|
+ c->oldx = c->x;
|
||||||
|
+ c->x = m->mx + ev->x;
|
||||||
|
+ }
|
||||||
|
+ if (ev->value_mask & CWY) {
|
||||||
|
+ c->oldy = c->y;
|
||||||
|
+ c->y = m->my + ev->y;
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
if (ev->value_mask & CWWidth) {
|
||||||
|
c->oldw = c->w;
|
||||||
|
--
|
||||||
|
2.19.1
|
||||||
|
|
||||||
|
|
114
dwm/patches/dwm-taglabels+hide_vacant_tags-6.2.diff
Normal file
114
dwm/patches/dwm-taglabels+hide_vacant_tags-6.2.diff
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
diff -pu dwm.git/config.def.h dwm.programtags+hidewithvacanttags/config.def.h
|
||||||
|
--- dwm.git/config.def.h 2021-02-27 20:04:32.030570909 -0600
|
||||||
|
+++ dwm.programtags+hidewithvacanttags/config.def.h 2021-03-15 16:32:37.586956549 -0500
|
||||||
|
@@ -21,6 +21,10 @@ static const char *colors[][3] = {
|
||||||
|
/* tagging */
|
||||||
|
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
||||||
|
|
||||||
|
+static const char ptagf[] = "[%s %s]"; /* format of a tag label */
|
||||||
|
+static const char etagf[] = "[%s]"; /* format of an empty tag */
|
||||||
|
+static const int lcaselbl = 0; /* 1 means make tag label lowercase */
|
||||||
|
+
|
||||||
|
static const Rule rules[] = {
|
||||||
|
/* xprop(1):
|
||||||
|
* WM_CLASS(STRING) = instance, class
|
||||||
|
diff -pu dwm.git/dwm.c dwm.programtags+hidewithvacanttags/dwm.c
|
||||||
|
--- dwm.git/dwm.c 2021-02-27 20:04:32.030570909 -0600
|
||||||
|
+++ dwm.programtags+hidewithvacanttags/dwm.c 2021-03-15 16:32:23.693639390 -0500
|
||||||
|
@@ -20,6 +20,7 @@
|
||||||
|
*
|
||||||
|
* To understand everything else, start reading main().
|
||||||
|
*/
|
||||||
|
+#include <ctype.h> /* for tolower function, very tiny standard library */
|
||||||
|
#include <errno.h>
|
||||||
|
#include <locale.h>
|
||||||
|
#include <signal.h>
|
||||||
|
@@ -272,6 +273,8 @@ static Window root, wmcheckwin;
|
||||||
|
/* configuration, allows nested code to access above variables */
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
+unsigned int tagw[LENGTH(tags)];
|
||||||
|
+
|
||||||
|
/* compile-time check if all tags fit into an unsigned int bit array. */
|
||||||
|
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
|
||||||
|
|
||||||
|
@@ -417,7 +420,7 @@ attachstack(Client *c)
|
||||||
|
void
|
||||||
|
buttonpress(XEvent *e)
|
||||||
|
{
|
||||||
|
- unsigned int i, x, click;
|
||||||
|
+ unsigned int i, x, click, occ = 0;
|
||||||
|
Arg arg = {0};
|
||||||
|
Client *c;
|
||||||
|
Monitor *m;
|
||||||
|
@@ -432,9 +435,14 @@ buttonpress(XEvent *e)
|
||||||
|
}
|
||||||
|
if (ev->window == selmon->barwin) {
|
||||||
|
i = x = 0;
|
||||||
|
- do
|
||||||
|
- x += TEXTW(tags[i]);
|
||||||
|
- while (ev->x >= x && ++i < LENGTH(tags));
|
||||||
|
+ for (c = m->clients; c; c = c->next)
|
||||||
|
+ occ |= c->tags == 255 ? 0 : c->tags;
|
||||||
|
+ do {
|
||||||
|
+ /* do not reserve space for vacant tags */
|
||||||
|
+ if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
|
||||||
|
+ continue;
|
||||||
|
+ x += tagw[i];
|
||||||
|
+ } while (ev->x >= x && ++i < LENGTH(tags));
|
||||||
|
if (i < LENGTH(tags)) {
|
||||||
|
click = ClkTagBar;
|
||||||
|
arg.ui = 1 << i;
|
||||||
|
@@ -701,6 +709,8 @@ drawbar(Monitor *m)
|
||||||
|
int boxw = drw->fonts->h / 6 + 2;
|
||||||
|
unsigned int i, occ = 0, urg = 0;
|
||||||
|
Client *c;
|
||||||
|
+ char tagdisp[64];
|
||||||
|
+ char *masterclientontag[LENGTH(tags)];
|
||||||
|
|
||||||
|
/* draw status first so it can be overdrawn by tags later */
|
||||||
|
if (m == selmon) { /* status is only drawn on selected monitor */
|
||||||
|
@@ -709,20 +719,36 @@ drawbar(Monitor *m)
|
||||||
|
drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
+ for (i = 0; i < LENGTH(tags); i++)
|
||||||
|
+ masterclientontag[i] = NULL;
|
||||||
|
+
|
||||||
|
for (c = m->clients; c; c = c->next) {
|
||||||
|
- occ |= c->tags;
|
||||||
|
+ occ |= c->tags == 255 ? 0 : c->tags;
|
||||||
|
if (c->isurgent)
|
||||||
|
urg |= c->tags;
|
||||||
|
+ for (i = 0; i < LENGTH(tags); i++)
|
||||||
|
+ if (!masterclientontag[i] && c->tags & (1<<i)) {
|
||||||
|
+ XClassHint ch = { NULL, NULL };
|
||||||
|
+ XGetClassHint(dpy, c->win, &ch);
|
||||||
|
+ masterclientontag[i] = ch.res_class;
|
||||||
|
+ if (lcaselbl)
|
||||||
|
+ masterclientontag[i][0] = tolower(masterclientontag[i][0]);
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
x = 0;
|
||||||
|
for (i = 0; i < LENGTH(tags); i++) {
|
||||||
|
- w = TEXTW(tags[i]);
|
||||||
|
+ /* do not draw vacant tags */
|
||||||
|
+ if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
|
||||||
|
+ continue;
|
||||||
|
+
|
||||||
|
+ if (masterclientontag[i])
|
||||||
|
+ snprintf(tagdisp, 64, ptagf, tags[i], masterclientontag[i]);
|
||||||
|
+ else
|
||||||
|
+ snprintf(tagdisp, 64, etagf, tags[i]);
|
||||||
|
+ masterclientontag[i] = tagdisp;
|
||||||
|
+ tagw[i] = w = TEXTW(masterclientontag[i]);
|
||||||
|
drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
|
||||||
|
- drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
|
||||||
|
- if (occ & 1 << i)
|
||||||
|
- drw_rect(drw, x + boxs, boxs, boxw, boxw,
|
||||||
|
- m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
|
||||||
|
- urg & 1 << i);
|
||||||
|
+ drw_text(drw, x, 0, w, bh, lrpad / 2, masterclientontag[i], urg & 1 << i);
|
||||||
|
x += w;
|
||||||
|
}
|
||||||
|
w = blw = TEXTW(m->ltsymbol);
|
27
dwm/patches/dwm-underlinetags-6.2.diff
Normal file
27
dwm/patches/dwm-underlinetags-6.2.diff
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
diff -pu dwm.git/config.def.h dwm.underlinetags/config.def.h
|
||||||
|
--- dwm.git/config.def.h 2021-02-27 20:04:32.030570909 -0600
|
||||||
|
+++ dwm.underlinetags/config.def.h 2021-03-16 16:42:26.278703624 -0500
|
||||||
|
@@ -21,6 +21,11 @@ static const char *colors[][3] = {
|
||||||
|
/* tagging */
|
||||||
|
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
||||||
|
|
||||||
|
+static const unsigned int ulinepad = 5; /* horizontal padding between the underline and tag */
|
||||||
|
+static const unsigned int ulinestroke = 2; /* thickness / height of the underline */
|
||||||
|
+static const unsigned int ulinevoffset = 0; /* how far above the bottom of the bar the line should appear */
|
||||||
|
+static const int ulineall = 0; /* 1 to show underline on all tags, 0 for just the active ones */
|
||||||
|
+
|
||||||
|
static const Rule rules[] = {
|
||||||
|
/* xprop(1):
|
||||||
|
* WM_CLASS(STRING) = instance, class
|
||||||
|
diff -pu dwm.git/dwm.c dwm.underlinetags/dwm.c
|
||||||
|
--- dwm.git/dwm.c 2021-02-27 20:04:32.030570909 -0600
|
||||||
|
+++ dwm.underlinetags/dwm.c 2021-03-16 16:41:21.468077151 -0500
|
||||||
|
@@ -719,6 +719,8 @@ drawbar(Monitor *m)
|
||||||
|
w = TEXTW(tags[i]);
|
||||||
|
drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
|
||||||
|
drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
|
||||||
|
+ if (ulineall || m->tagset[m->seltags] & 1 << i) /* if there are conflicts, just move these lines directly underneath both 'drw_setscheme' and 'drw_text' :) */
|
||||||
|
+ drw_rect(drw, x + ulinepad, bh - ulinestroke - ulinevoffset, w - (ulinepad * 2), ulinestroke, 1, 0);
|
||||||
|
if (occ & 1 << i)
|
||||||
|
drw_rect(drw, x + boxs, boxs, boxw, boxw,
|
||||||
|
m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
|
371
dwm/patches/dwm-winicon-6.3-v2.1.diff
Normal file
371
dwm/patches/dwm-winicon-6.3-v2.1.diff
Normal file
|
@ -0,0 +1,371 @@
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index a2ac963..322d181 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -5,6 +5,8 @@ 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 */
|
||||||
|
+#define ICONSIZE 16 /* icon size */
|
||||||
|
+#define ICONSPACING 5 /* space between icon and title */
|
||||||
|
static const char *fonts[] = { "monospace:size=10" };
|
||||||
|
static const char dmenufont[] = "monospace:size=10";
|
||||||
|
static const char col_gray1[] = "#222222";
|
||||||
|
diff --git a/config.mk b/config.mk
|
||||||
|
index b6eb7e0..f3c01b0 100644
|
||||||
|
--- a/config.mk
|
||||||
|
+++ b/config.mk
|
||||||
|
@@ -22,7 +22,7 @@ FREETYPEINC = /usr/include/freetype2
|
||||||
|
|
||||||
|
# includes and libs
|
||||||
|
INCS = -I${X11INC} -I${FREETYPEINC}
|
||||||
|
-LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS}
|
||||||
|
+LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lXrender -lImlib2
|
||||||
|
|
||||||
|
# flags
|
||||||
|
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
|
||||||
|
diff --git a/drw.c b/drw.c
|
||||||
|
index 4cdbcbe..9b474c5 100644
|
||||||
|
--- a/drw.c
|
||||||
|
+++ b/drw.c
|
||||||
|
@@ -4,6 +4,7 @@
|
||||||
|
#include <string.h>
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
#include <X11/Xft/Xft.h>
|
||||||
|
+#include <Imlib2.h>
|
||||||
|
|
||||||
|
#include "drw.h"
|
||||||
|
#include "util.h"
|
||||||
|
@@ -71,6 +72,7 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h
|
||||||
|
drw->w = w;
|
||||||
|
drw->h = h;
|
||||||
|
drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen));
|
||||||
|
+ drw->picture = XRenderCreatePicture(dpy, drw->drawable, XRenderFindVisualFormat(dpy, DefaultVisual(dpy, screen)), 0, NULL);
|
||||||
|
drw->gc = XCreateGC(dpy, root, 0, NULL);
|
||||||
|
XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
|
||||||
|
|
||||||
|
@@ -85,14 +87,18 @@ drw_resize(Drw *drw, unsigned int w, unsigned int h)
|
||||||
|
|
||||||
|
drw->w = w;
|
||||||
|
drw->h = h;
|
||||||
|
+ if (drw->picture)
|
||||||
|
+ XRenderFreePicture(drw->dpy, drw->picture);
|
||||||
|
if (drw->drawable)
|
||||||
|
XFreePixmap(drw->dpy, drw->drawable);
|
||||||
|
drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen));
|
||||||
|
+ drw->picture = XRenderCreatePicture(drw->dpy, drw->drawable, XRenderFindVisualFormat(drw->dpy, DefaultVisual(drw->dpy, drw->screen)), 0, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
drw_free(Drw *drw)
|
||||||
|
{
|
||||||
|
+ XRenderFreePicture(drw->dpy, drw->picture);
|
||||||
|
XFreePixmap(drw->dpy, drw->drawable);
|
||||||
|
XFreeGC(drw->dpy, drw->gc);
|
||||||
|
drw_fontset_free(drw->fonts);
|
||||||
|
@@ -236,6 +242,67 @@ drw_setscheme(Drw *drw, Clr *scm)
|
||||||
|
drw->scheme = scm;
|
||||||
|
}
|
||||||
|
|
||||||
|
+Picture
|
||||||
|
+drw_picture_create_resized(Drw *drw, char *src, unsigned int srcw, unsigned int srch, unsigned int dstw, unsigned int dsth) {
|
||||||
|
+ Pixmap pm;
|
||||||
|
+ Picture pic;
|
||||||
|
+ GC gc;
|
||||||
|
+
|
||||||
|
+ if (srcw <= (dstw << 1u) && srch <= (dsth << 1u)) {
|
||||||
|
+ XImage img = {
|
||||||
|
+ srcw, srch, 0, ZPixmap, src,
|
||||||
|
+ ImageByteOrder(drw->dpy), BitmapUnit(drw->dpy), BitmapBitOrder(drw->dpy), 32,
|
||||||
|
+ 32, 0, 32,
|
||||||
|
+ 0, 0, 0
|
||||||
|
+ };
|
||||||
|
+ XInitImage(&img);
|
||||||
|
+
|
||||||
|
+ pm = XCreatePixmap(drw->dpy, drw->root, srcw, srch, 32);
|
||||||
|
+ gc = XCreateGC(drw->dpy, pm, 0, NULL);
|
||||||
|
+ XPutImage(drw->dpy, pm, gc, &img, 0, 0, 0, 0, srcw, srch);
|
||||||
|
+ XFreeGC(drw->dpy, gc);
|
||||||
|
+
|
||||||
|
+ pic = XRenderCreatePicture(drw->dpy, pm, XRenderFindStandardFormat(drw->dpy, PictStandardARGB32), 0, NULL);
|
||||||
|
+ XFreePixmap(drw->dpy, pm);
|
||||||
|
+
|
||||||
|
+ XRenderSetPictureFilter(drw->dpy, pic, FilterBilinear, NULL, 0);
|
||||||
|
+ XTransform xf;
|
||||||
|
+ xf.matrix[0][0] = (srcw << 16u) / dstw; xf.matrix[0][1] = 0; xf.matrix[0][2] = 0;
|
||||||
|
+ xf.matrix[1][0] = 0; xf.matrix[1][1] = (srch << 16u) / dsth; xf.matrix[1][2] = 0;
|
||||||
|
+ xf.matrix[2][0] = 0; xf.matrix[2][1] = 0; xf.matrix[2][2] = 65536;
|
||||||
|
+ XRenderSetPictureTransform(drw->dpy, pic, &xf);
|
||||||
|
+ } else {
|
||||||
|
+ Imlib_Image origin = imlib_create_image_using_data(srcw, srch, (DATA32 *)src);
|
||||||
|
+ if (!origin) return None;
|
||||||
|
+ imlib_context_set_image(origin);
|
||||||
|
+ imlib_image_set_has_alpha(1);
|
||||||
|
+ Imlib_Image scaled = imlib_create_cropped_scaled_image(0, 0, srcw, srch, dstw, dsth);
|
||||||
|
+ imlib_free_image_and_decache();
|
||||||
|
+ if (!scaled) return None;
|
||||||
|
+ imlib_context_set_image(scaled);
|
||||||
|
+ imlib_image_set_has_alpha(1);
|
||||||
|
+
|
||||||
|
+ XImage img = {
|
||||||
|
+ dstw, dsth, 0, ZPixmap, (char *)imlib_image_get_data_for_reading_only(),
|
||||||
|
+ ImageByteOrder(drw->dpy), BitmapUnit(drw->dpy), BitmapBitOrder(drw->dpy), 32,
|
||||||
|
+ 32, 0, 32,
|
||||||
|
+ 0, 0, 0
|
||||||
|
+ };
|
||||||
|
+ XInitImage(&img);
|
||||||
|
+
|
||||||
|
+ pm = XCreatePixmap(drw->dpy, drw->root, dstw, dsth, 32);
|
||||||
|
+ gc = XCreateGC(drw->dpy, pm, 0, NULL);
|
||||||
|
+ XPutImage(drw->dpy, pm, gc, &img, 0, 0, 0, 0, dstw, dsth);
|
||||||
|
+ imlib_free_image_and_decache();
|
||||||
|
+ XFreeGC(drw->dpy, gc);
|
||||||
|
+
|
||||||
|
+ pic = XRenderCreatePicture(drw->dpy, pm, XRenderFindStandardFormat(drw->dpy, PictStandardARGB32), 0, NULL);
|
||||||
|
+ XFreePixmap(drw->dpy, pm);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return pic;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
void
|
||||||
|
drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert)
|
||||||
|
{
|
||||||
|
@@ -379,6 +446,14 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
|
||||||
|
return x + (render ? w : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
+void
|
||||||
|
+drw_pic(Drw *drw, int x, int y, unsigned int w, unsigned int h, Picture pic)
|
||||||
|
+{
|
||||||
|
+ if (!drw)
|
||||||
|
+ return;
|
||||||
|
+ XRenderComposite(drw->dpy, PictOpOver, pic, None, drw->picture, 0, 0, 0, 0, x, y, w, h);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
void
|
||||||
|
drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h)
|
||||||
|
{
|
||||||
|
diff --git a/drw.h b/drw.h
|
||||||
|
index 4bcd5ad..71aefa2 100644
|
||||||
|
--- a/drw.h
|
||||||
|
+++ b/drw.h
|
||||||
|
@@ -21,6 +21,7 @@ typedef struct {
|
||||||
|
int screen;
|
||||||
|
Window root;
|
||||||
|
Drawable drawable;
|
||||||
|
+ Picture picture;
|
||||||
|
GC gc;
|
||||||
|
Clr *scheme;
|
||||||
|
Fnt *fonts;
|
||||||
|
@@ -49,9 +50,12 @@ void drw_cur_free(Drw *drw, Cur *cursor);
|
||||||
|
void drw_setfontset(Drw *drw, Fnt *set);
|
||||||
|
void drw_setscheme(Drw *drw, Clr *scm);
|
||||||
|
|
||||||
|
+Picture drw_picture_create_resized(Drw *drw, char *src, unsigned int src_w, unsigned int src_h, unsigned int dst_w, unsigned int dst_h);
|
||||||
|
+
|
||||||
|
/* 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);
|
||||||
|
+void drw_pic(Drw *drw, int x, int y, unsigned int w, unsigned int h, Picture pic);
|
||||||
|
|
||||||
|
/* Map functions */
|
||||||
|
void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h);
|
||||||
|
diff --git a/dwm.c b/dwm.c
|
||||||
|
index a96f33c..033ccec 100644
|
||||||
|
--- a/dwm.c
|
||||||
|
+++ b/dwm.c
|
||||||
|
@@ -28,6 +28,8 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
+#include <limits.h>
|
||||||
|
+#include <stdint.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <X11/cursorfont.h>
|
||||||
|
@@ -60,7 +62,7 @@
|
||||||
|
/* enums */
|
||||||
|
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
|
||||||
|
enum { SchemeNorm, SchemeSel }; /* color schemes */
|
||||||
|
-enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
|
||||||
|
+enum { NetSupported, NetWMName, NetWMIcon, NetWMState, NetWMCheck,
|
||||||
|
NetWMFullscreen, NetActiveWindow, NetWMWindowType,
|
||||||
|
NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
|
||||||
|
enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
|
||||||
|
@@ -93,6 +95,7 @@ struct Client {
|
||||||
|
int bw, oldbw;
|
||||||
|
unsigned int tags;
|
||||||
|
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
|
||||||
|
+ unsigned int icw, ich; Picture icon;
|
||||||
|
Client *next;
|
||||||
|
Client *snext;
|
||||||
|
Monitor *mon;
|
||||||
|
@@ -170,6 +173,7 @@ static void focusin(XEvent *e);
|
||||||
|
static void focusmon(const Arg *arg);
|
||||||
|
static void focusstack(const Arg *arg);
|
||||||
|
static Atom getatomprop(Client *c, Atom prop);
|
||||||
|
+static Picture geticonprop(Window w, unsigned int *icw, unsigned int *ich);
|
||||||
|
static int getrootptr(int *x, int *y);
|
||||||
|
static long getstate(Window w);
|
||||||
|
static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
|
||||||
|
@@ -214,6 +218,7 @@ static void togglebar(const Arg *arg);
|
||||||
|
static void togglefloating(const Arg *arg);
|
||||||
|
static void toggletag(const Arg *arg);
|
||||||
|
static void toggleview(const Arg *arg);
|
||||||
|
+static void freeicon(Client *c);
|
||||||
|
static void unfocus(Client *c, int setfocus);
|
||||||
|
static void unmanage(Client *c, int destroyed);
|
||||||
|
static void unmapnotify(XEvent *e);
|
||||||
|
@@ -225,6 +230,7 @@ static void updatenumlockmask(void);
|
||||||
|
static void updatesizehints(Client *c);
|
||||||
|
static void updatestatus(void);
|
||||||
|
static void updatetitle(Client *c);
|
||||||
|
+static void updateicon(Client *c);
|
||||||
|
static void updatewindowtype(Client *c);
|
||||||
|
static void updatewmhints(Client *c);
|
||||||
|
static void view(const Arg *arg);
|
||||||
|
@@ -735,7 +741,8 @@ drawbar(Monitor *m)
|
||||||
|
if ((w = m->ww - tw - x) > bh) {
|
||||||
|
if (m->sel) {
|
||||||
|
drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
|
||||||
|
- drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
|
||||||
|
+ drw_text(drw, x, 0, w, bh, lrpad / 2 + (m->sel->icon ? m->sel->icw + ICONSPACING : 0), m->sel->name, 0);
|
||||||
|
+ if (m->sel->icon) drw_pic(drw, x + lrpad / 2, (bh - m->sel->ich) / 2, m->sel->icw, m->sel->ich, m->sel->icon);
|
||||||
|
if (m->sel->isfloating)
|
||||||
|
drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
|
||||||
|
} else {
|
||||||
|
@@ -875,6 +882,67 @@ getatomprop(Client *c, Atom prop)
|
||||||
|
return atom;
|
||||||
|
}
|
||||||
|
|
||||||
|
+static uint32_t prealpha(uint32_t p) {
|
||||||
|
+ uint8_t a = p >> 24u;
|
||||||
|
+ uint32_t rb = (a * (p & 0xFF00FFu)) >> 8u;
|
||||||
|
+ uint32_t g = (a * (p & 0x00FF00u)) >> 8u;
|
||||||
|
+ return (rb & 0xFF00FFu) | (g & 0x00FF00u) | (a << 24u);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+Picture
|
||||||
|
+geticonprop(Window win, unsigned int *picw, unsigned int *pich)
|
||||||
|
+{
|
||||||
|
+ int format;
|
||||||
|
+ unsigned long n, extra, *p = NULL;
|
||||||
|
+ Atom real;
|
||||||
|
+
|
||||||
|
+ if (XGetWindowProperty(dpy, win, netatom[NetWMIcon], 0L, LONG_MAX, False, AnyPropertyType,
|
||||||
|
+ &real, &format, &n, &extra, (unsigned char **)&p) != Success)
|
||||||
|
+ return None;
|
||||||
|
+ if (n == 0 || format != 32) { XFree(p); return None; }
|
||||||
|
+
|
||||||
|
+ unsigned long *bstp = NULL;
|
||||||
|
+ uint32_t w, h, sz;
|
||||||
|
+ {
|
||||||
|
+ unsigned long *i; const unsigned long *end = p + n;
|
||||||
|
+ uint32_t bstd = UINT32_MAX, d, m;
|
||||||
|
+ for (i = p; i < end - 1; i += sz) {
|
||||||
|
+ if ((w = *i++) >= 16384 || (h = *i++) >= 16384) { XFree(p); return None; }
|
||||||
|
+ if ((sz = w * h) > end - i) break;
|
||||||
|
+ if ((m = w > h ? w : h) >= ICONSIZE && (d = m - ICONSIZE) < bstd) { bstd = d; bstp = i; }
|
||||||
|
+ }
|
||||||
|
+ if (!bstp) {
|
||||||
|
+ for (i = p; i < end - 1; i += sz) {
|
||||||
|
+ if ((w = *i++) >= 16384 || (h = *i++) >= 16384) { XFree(p); return None; }
|
||||||
|
+ if ((sz = w * h) > end - i) break;
|
||||||
|
+ if ((d = ICONSIZE - (w > h ? w : h)) < bstd) { bstd = d; bstp = i; }
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ if (!bstp) { XFree(p); return None; }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if ((w = *(bstp - 2)) == 0 || (h = *(bstp - 1)) == 0) { XFree(p); return None; }
|
||||||
|
+
|
||||||
|
+ uint32_t icw, ich;
|
||||||
|
+ if (w <= h) {
|
||||||
|
+ ich = ICONSIZE; icw = w * ICONSIZE / h;
|
||||||
|
+ if (icw == 0) icw = 1;
|
||||||
|
+ }
|
||||||
|
+ else {
|
||||||
|
+ icw = ICONSIZE; ich = h * ICONSIZE / w;
|
||||||
|
+ if (ich == 0) ich = 1;
|
||||||
|
+ }
|
||||||
|
+ *picw = icw; *pich = ich;
|
||||||
|
+
|
||||||
|
+ uint32_t i, *bstp32 = (uint32_t *)bstp;
|
||||||
|
+ for (sz = w * h, i = 0; i < sz; ++i) bstp32[i] = prealpha(bstp[i]);
|
||||||
|
+
|
||||||
|
+ Picture ret = drw_picture_create_resized(drw, (char *)bstp, w, h, icw, ich);
|
||||||
|
+ XFree(p);
|
||||||
|
+
|
||||||
|
+ return ret;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
int
|
||||||
|
getrootptr(int *x, int *y)
|
||||||
|
{
|
||||||
|
@@ -1034,6 +1102,7 @@ manage(Window w, XWindowAttributes *wa)
|
||||||
|
c->h = c->oldh = wa->height;
|
||||||
|
c->oldbw = wa->border_width;
|
||||||
|
|
||||||
|
+ updateicon(c);
|
||||||
|
updatetitle(c);
|
||||||
|
if (XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) {
|
||||||
|
c->mon = t->mon;
|
||||||
|
@@ -1244,6 +1313,11 @@ propertynotify(XEvent *e)
|
||||||
|
if (c == c->mon->sel)
|
||||||
|
drawbar(c->mon);
|
||||||
|
}
|
||||||
|
+ else if (ev->atom == netatom[NetWMIcon]) {
|
||||||
|
+ updateicon(c);
|
||||||
|
+ if (c == c->mon->sel)
|
||||||
|
+ drawbar(c->mon);
|
||||||
|
+ }
|
||||||
|
if (ev->atom == netatom[NetWMWindowType])
|
||||||
|
updatewindowtype(c);
|
||||||
|
}
|
||||||
|
@@ -1560,6 +1634,7 @@ setup(void)
|
||||||
|
netatom[NetActiveWindow] = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
|
||||||
|
netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
|
||||||
|
netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
|
||||||
|
+ netatom[NetWMIcon] = XInternAtom(dpy, "_NET_WM_ICON", False);
|
||||||
|
netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
|
||||||
|
netatom[NetWMCheck] = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False);
|
||||||
|
netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
|
||||||
|
@@ -1752,6 +1827,15 @@ toggleview(const Arg *arg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
+void
|
||||||
|
+freeicon(Client *c)
|
||||||
|
+{
|
||||||
|
+ if (c->icon) {
|
||||||
|
+ XRenderFreePicture(dpy, c->icon);
|
||||||
|
+ c->icon = None;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
void
|
||||||
|
unfocus(Client *c, int setfocus)
|
||||||
|
{
|
||||||
|
@@ -1773,6 +1857,7 @@ unmanage(Client *c, int destroyed)
|
||||||
|
|
||||||
|
detach(c);
|
||||||
|
detachstack(c);
|
||||||
|
+ freeicon(c);
|
||||||
|
if (!destroyed) {
|
||||||
|
wc.border_width = c->oldbw;
|
||||||
|
XGrabServer(dpy); /* avoid race conditions */
|
||||||
|
@@ -2007,6 +2092,13 @@ updatetitle(Client *c)
|
||||||
|
strcpy(c->name, broken);
|
||||||
|
}
|
||||||
|
|
||||||
|
+void
|
||||||
|
+updateicon(Client *c)
|
||||||
|
+{
|
||||||
|
+ freeicon(c);
|
||||||
|
+ c->icon = geticonprop(c->win, &c->icw, &c->ich);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
void
|
||||||
|
updatewindowtype(Client *c)
|
||||||
|
{
|
95
dwm/patches/fullgaps.diff
Normal file
95
dwm/patches/fullgaps.diff
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index 1c0b587..38d2f6c 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -2,6 +2,7 @@
|
||||||
|
|
||||||
|
/* appearance */
|
||||||
|
static const unsigned int borderpx = 1; /* border pixel of windows */
|
||||||
|
+static const unsigned int gappx = 5; /* gaps between 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 */
|
||||||
|
@@ -84,6 +85,9 @@ static Key keys[] = {
|
||||||
|
{ MODKEY, XK_period, focusmon, {.i = +1 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
|
||||||
|
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
|
||||||
|
+ { MODKEY, XK_minus, setgaps, {.i = -1 } },
|
||||||
|
+ { MODKEY, XK_equal, setgaps, {.i = +1 } },
|
||||||
|
+ { MODKEY|ShiftMask, XK_equal, setgaps, {.i = 0 } },
|
||||||
|
TAGKEYS( XK_1, 0)
|
||||||
|
TAGKEYS( XK_2, 1)
|
||||||
|
TAGKEYS( XK_3, 2)
|
||||||
|
diff --git a/dwm.c b/dwm.c
|
||||||
|
index 4465af1..4363627 100644
|
||||||
|
--- a/dwm.c
|
||||||
|
+++ b/dwm.c
|
||||||
|
@@ -119,6 +119,7 @@ struct Monitor {
|
||||||
|
int by; /* bar geometry */
|
||||||
|
int mx, my, mw, mh; /* screen size */
|
||||||
|
int wx, wy, ww, wh; /* window area */
|
||||||
|
+ int gappx; /* gaps between windows */
|
||||||
|
unsigned int seltags;
|
||||||
|
unsigned int sellt;
|
||||||
|
unsigned int tagset[2];
|
||||||
|
@@ -199,6 +200,7 @@ static void sendmon(Client *c, Monitor *m);
|
||||||
|
static void setclientstate(Client *c, long state);
|
||||||
|
static void setfocus(Client *c);
|
||||||
|
static void setfullscreen(Client *c, int fullscreen);
|
||||||
|
+static void setgaps(const Arg *arg);
|
||||||
|
static void setlayout(const Arg *arg);
|
||||||
|
static void setmfact(const Arg *arg);
|
||||||
|
static void setup(void);
|
||||||
|
@@ -638,6 +640,7 @@ createmon(void)
|
||||||
|
m->nmaster = nmaster;
|
||||||
|
m->showbar = showbar;
|
||||||
|
m->topbar = topbar;
|
||||||
|
+ m->gappx = gappx;
|
||||||
|
m->lt[0] = &layouts[0];
|
||||||
|
m->lt[1] = &layouts[1 % LENGTH(layouts)];
|
||||||
|
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
|
||||||
|
@@ -1497,6 +1500,16 @@ setfullscreen(Client *c, int fullscreen)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
+void
|
||||||
|
+setgaps(const Arg *arg)
|
||||||
|
+{
|
||||||
|
+ if ((arg->i == 0) || (selmon->gappx + arg->i < 0))
|
||||||
|
+ selmon->gappx = 0;
|
||||||
|
+ else
|
||||||
|
+ selmon->gappx += arg->i;
|
||||||
|
+ arrange(selmon);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
void
|
||||||
|
setlayout(const Arg *arg)
|
||||||
|
{
|
||||||
|
@@ -1683,16 +1696,16 @@ tile(Monitor *m)
|
||||||
|
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++)
|
||||||
|
+ mw = m->ww - m->gappx;
|
||||||
|
+ for (i = 0, my = ty = m->gappx, 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);
|
||||||
|
+ h = (m->wh - my) / (MIN(n, m->nmaster) - i) - m->gappx;
|
||||||
|
+ resize(c, m->wx + m->gappx, m->wy + my, mw - (2*c->bw) - m->gappx, h - (2*c->bw), 0);
|
||||||
|
+ my += HEIGHT(c) + m->gappx;
|
||||||
|
} 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);
|
||||||
|
+ h = (m->wh - ty) / (n - i) - m->gappx;
|
||||||
|
+ resize(c, m->wx + mw + m->gappx, m->wy + ty, m->ww - mw - (2*c->bw) - 2*m->gappx, h - (2*c->bw), 0);
|
||||||
|
+ ty += HEIGHT(c) + m->gappx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
--
|
||||||
|
2.20.1
|
||||||
|
|
19
dwm/shiftview.c
Normal file
19
dwm/shiftview.c
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/** Function to shift the current view to the left/right
|
||||||
|
*
|
||||||
|
* @param: "arg->i" stores the number of tags to shift right (positive value)
|
||||||
|
* or left (negative value)
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
shiftview(const Arg *arg) {
|
||||||
|
Arg shifted;
|
||||||
|
|
||||||
|
if(arg->i > 0) // left circular shift
|
||||||
|
shifted.ui = (selmon->tagset[selmon->seltags] << arg->i)
|
||||||
|
| (selmon->tagset[selmon->seltags] >> (LENGTH(tags) - arg->i));
|
||||||
|
|
||||||
|
else // right circular shift
|
||||||
|
shifted.ui = selmon->tagset[selmon->seltags] >> (- arg->i)
|
||||||
|
| selmon->tagset[selmon->seltags] << (LENGTH(tags) + arg->i);
|
||||||
|
|
||||||
|
view(&shifted);
|
||||||
|
}
|
42
dwm/transient.c
Normal file
42
dwm/transient.c
Normal file
|
@ -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);
|
||||||
|
}
|
35
dwm/util.c
Normal file
35
dwm/util.c
Normal file
|
@ -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);
|
||||||
|
}
|
8
dwm/util.h
Normal file
8
dwm/util.h
Normal file
|
@ -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);
|
BIN
dwm/util.o
Normal file
BIN
dwm/util.o
Normal file
Binary file not shown.
1
j4-dmenu-desktop
Submodule
1
j4-dmenu-desktop
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 65b13587793d7660797e67b18e2f0daad6ec4708
|
40
slstatus/LICENSE
Normal file
40
slstatus/LICENSE
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
ISC License
|
||||||
|
|
||||||
|
Copyright 2016-2020 Aaron Marcher <me@drkhsh.at>
|
||||||
|
|
||||||
|
Copyright 2016 Roy Freytag <rfreytag@hs-mittweida.de>
|
||||||
|
Copyright 2016 Vincent Loupmon <vincentloupmon@gmail.com>
|
||||||
|
Copyright 2016 Daniel Walter <d.walter@0x90.at>
|
||||||
|
Copyright 2016-2018 Ali H. Fardan <raiz@firemail.cc>
|
||||||
|
Copyright 2016 Jody Leonard <me@jodyleonard.com>
|
||||||
|
Copyright 2016-2018 Quentin Rameau <quinq@fifth.space>
|
||||||
|
Copyright 2016 Mike Coddington <mike@coddington.us>
|
||||||
|
Copyright 2016-2018 parazyd <parazyd@dyne.org>
|
||||||
|
Copyright 2017 Tobias Stoeckmann <tobias@stoeckmann.org>
|
||||||
|
Copyright 2017-2018 Laslo Hunhold <dev@frign.de>
|
||||||
|
Copyright 2018 Darron Anderson <darronanderson@protonmail.com>
|
||||||
|
Copyright 2018 Josuah Demangeon <mail@josuah.net>
|
||||||
|
Copyright 2018 Tobias Tschinkowitz <tobias@he4d.net>
|
||||||
|
Copyright 2018 David Demelier <markand@malikania.fr>
|
||||||
|
Copyright 2018-2019 Michael Buch <michaelbuch12@gmail.com>
|
||||||
|
Copyright 2018 Ian Remmler <ian@remmler.org>
|
||||||
|
Copyright 2016-2019 Joerg Jung <jung@openbsd.org>
|
||||||
|
Copyright 2019 Ryan Kes <alrayyes@gmail.com>
|
||||||
|
Copyright 2019 Cem Keylan <cem@ckyln.com>
|
||||||
|
Copyright 2019 dsp <dsp@2f30.org>
|
||||||
|
Copyright 2019-2020 Ingo Feinerer <feinerer@logic.at>
|
||||||
|
Copyright 2020 Alexandre Ratchov <alex@caoua.org>
|
||||||
|
Copyright 2020 Mart Lubbers <mart@martlubbers.net>
|
||||||
|
Copyright 2020 Daniel Moch <daniel@danielmoch.com>
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
68
slstatus/Makefile
Normal file
68
slstatus/Makefile
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
# See LICENSE file for copyright and license details
|
||||||
|
# slstatus - suckless status monitor
|
||||||
|
.POSIX:
|
||||||
|
|
||||||
|
include config.mk
|
||||||
|
|
||||||
|
REQ = util
|
||||||
|
COM =\
|
||||||
|
components/battery\
|
||||||
|
components/cpu\
|
||||||
|
components/datetime\
|
||||||
|
components/disk\
|
||||||
|
components/entropy\
|
||||||
|
components/hostname\
|
||||||
|
components/ip\
|
||||||
|
components/kernel_release\
|
||||||
|
components/keyboard_indicators\
|
||||||
|
components/keymap\
|
||||||
|
components/load_avg\
|
||||||
|
components/netspeeds\
|
||||||
|
components/num_files\
|
||||||
|
components/ram\
|
||||||
|
components/run_command\
|
||||||
|
components/separator\
|
||||||
|
components/swap\
|
||||||
|
components/temperature\
|
||||||
|
components/uptime\
|
||||||
|
components/user\
|
||||||
|
components/volume\
|
||||||
|
components/wifi
|
||||||
|
|
||||||
|
all: slstatus
|
||||||
|
|
||||||
|
$(COM:=.o): config.mk $(REQ:=.h)
|
||||||
|
slstatus.o: slstatus.c slstatus.h arg.h config.h config.mk $(REQ:=.h)
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(CC) -o $@ -c $(CPPFLAGS) $(CFLAGS) $<
|
||||||
|
|
||||||
|
config.h:
|
||||||
|
cp config.def.h $@
|
||||||
|
|
||||||
|
slstatus: slstatus.o $(COM:=.o) $(REQ:=.o)
|
||||||
|
$(CC) -o $@ $(LDFLAGS) $(COM:=.o) $(REQ:=.o) slstatus.o $(LDLIBS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f slstatus slstatus.o $(COM:=.o) $(REQ:=.o)
|
||||||
|
|
||||||
|
dist:
|
||||||
|
rm -rf "slstatus-$(VERSION)"
|
||||||
|
mkdir -p "slstatus-$(VERSION)/components"
|
||||||
|
cp -R LICENSE Makefile README config.mk config.def.h \
|
||||||
|
arg.h slstatus.c $(COM:=.c) $(REQ:=.c) $(REQ:=.h) \
|
||||||
|
slstatus.1 "slstatus-$(VERSION)"
|
||||||
|
tar -cf - "slstatus-$(VERSION)" | gzip -c > "slstatus-$(VERSION).tar.gz"
|
||||||
|
rm -rf "slstatus-$(VERSION)"
|
||||||
|
|
||||||
|
install: all
|
||||||
|
mkdir -p "$(DESTDIR)$(PREFIX)/bin"
|
||||||
|
cp -f slstatus "$(DESTDIR)$(PREFIX)/bin"
|
||||||
|
chmod 755 "$(DESTDIR)$(PREFIX)/bin/slstatus"
|
||||||
|
mkdir -p "$(DESTDIR)$(MANPREFIX)/man1"
|
||||||
|
cp -f slstatus.1 "$(DESTDIR)$(MANPREFIX)/man1"
|
||||||
|
chmod 644 "$(DESTDIR)$(MANPREFIX)/man1/slstatus.1"
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
rm -f "$(DESTDIR)$(PREFIX)/bin/slstatus"
|
||||||
|
rm -f "$(DESTDIR)$(MANPREFIX)/man1/slstatus.1"
|
65
slstatus/README
Normal file
65
slstatus/README
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
slstatus - suckless status
|
||||||
|
==========================
|
||||||
|
slstatus is a suckless status monitor for window managers that use WM_NAME
|
||||||
|
(e.g. dwm) or stdin to fill the status bar.
|
||||||
|
|
||||||
|
|
||||||
|
Features
|
||||||
|
--------
|
||||||
|
- Battery percentage/state/time left
|
||||||
|
- CPU usage
|
||||||
|
- CPU frequency
|
||||||
|
- Custom shell commands
|
||||||
|
- Date and time
|
||||||
|
- Disk status (free storage, percentage, total storage and used storage)
|
||||||
|
- Available entropy
|
||||||
|
- Username/GID/UID
|
||||||
|
- Hostname
|
||||||
|
- IP address (IPv4 and IPv6)
|
||||||
|
- Kernel version
|
||||||
|
- Keyboard indicators
|
||||||
|
- Keymap
|
||||||
|
- Load average
|
||||||
|
- Network speeds (RX and TX)
|
||||||
|
- Number of files in a directory (hint: Maildir)
|
||||||
|
- Memory status (free memory, percentage, total memory and used memory)
|
||||||
|
- Swap status (free swap, percentage, total swap and used swap)
|
||||||
|
- Temperature
|
||||||
|
- Uptime
|
||||||
|
- Volume percentage
|
||||||
|
- WiFi signal percentage and ESSID
|
||||||
|
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
Currently slstatus works on FreeBSD, Linux and OpenBSD.
|
||||||
|
In order to build slstatus you need the Xlib header files.
|
||||||
|
|
||||||
|
|
||||||
|
Installation
|
||||||
|
------------
|
||||||
|
Edit config.mk to match your local setup (slstatus is installed into the
|
||||||
|
/usr/local namespace by default).
|
||||||
|
|
||||||
|
Afterwards enter the following command to build and install slstatus (if
|
||||||
|
necessary as root):
|
||||||
|
|
||||||
|
make clean install
|
||||||
|
|
||||||
|
|
||||||
|
Running slstatus
|
||||||
|
----------------
|
||||||
|
See the man page for details.
|
||||||
|
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
-------------
|
||||||
|
slstatus can be customized by creating a custom config.h and (re)compiling the
|
||||||
|
source code. This keeps it fast, secure and simple.
|
||||||
|
|
||||||
|
|
||||||
|
Upcoming
|
||||||
|
--------
|
||||||
|
|
||||||
|
A release (v1.0) will come soon... ;)
|
||||||
|
After a long phase of inactivity, development has been continued!
|
33
slstatus/arg.h
Normal file
33
slstatus/arg.h
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
#ifndef ARG_H
|
||||||
|
#define ARG_H
|
||||||
|
|
||||||
|
extern char *argv0;
|
||||||
|
|
||||||
|
/* int main(int argc, char *argv[]) */
|
||||||
|
#define ARGBEGIN for (argv0 = *argv, *argv ? (argc--, argv++) : ((void *)0); \
|
||||||
|
*argv && (*argv)[0] == '-' && (*argv)[1]; argc--, argv++) { \
|
||||||
|
int i_, argused_; \
|
||||||
|
if ((*argv)[1] == '-' && !(*argv)[2]) { \
|
||||||
|
argc--, argv++; \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
for (i_ = 1, argused_ = 0; (*argv)[i_]; i_++) { \
|
||||||
|
switch((*argv)[i_])
|
||||||
|
#define ARGEND if (argused_) { \
|
||||||
|
if ((*argv)[i_ + 1]) { \
|
||||||
|
break; \
|
||||||
|
} else { \
|
||||||
|
argc--, argv++; \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
#define ARGC() ((*argv)[i_])
|
||||||
|
#define ARGF_(x) (((*argv)[i_ + 1]) ? (argused_ = 1, &((*argv)[i_ + 1])) : \
|
||||||
|
(*(argv + 1)) ? (argused_ = 1, *(argv + 1)) : (x))
|
||||||
|
#define EARGF(x) ARGF_(((x), exit(1), (char *)0))
|
||||||
|
#define ARGF() ARGF_((char *)0)
|
||||||
|
|
||||||
|
#endif
|
252
slstatus/components/battery.c
Normal file
252
slstatus/components/battery.c
Normal file
|
@ -0,0 +1,252 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "../util.h"
|
||||||
|
|
||||||
|
#if defined(__linux__)
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
pick(const char *bat, const char *f1, const char *f2, char *path,
|
||||||
|
size_t length)
|
||||||
|
{
|
||||||
|
if (esnprintf(path, length, f1, bat) > 0 &&
|
||||||
|
access(path, R_OK) == 0) {
|
||||||
|
return f1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (esnprintf(path, length, f2, bat) > 0 &&
|
||||||
|
access(path, R_OK) == 0) {
|
||||||
|
return f2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
battery_perc(const char *bat)
|
||||||
|
{
|
||||||
|
int perc;
|
||||||
|
char path[PATH_MAX];
|
||||||
|
|
||||||
|
if (esnprintf(path, sizeof(path),
|
||||||
|
"/sys/class/power_supply/%s/capacity", bat) < 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (pscanf(path, "%d", &perc) != 1) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bprintf("%d", perc);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
battery_state(const char *bat)
|
||||||
|
{
|
||||||
|
static struct {
|
||||||
|
char *state;
|
||||||
|
char *symbol;
|
||||||
|
} map[] = {
|
||||||
|
{ "Charging", "+" },
|
||||||
|
{ "Discharging", "-" },
|
||||||
|
{ "Full", "o" },
|
||||||
|
};
|
||||||
|
size_t i;
|
||||||
|
char path[PATH_MAX], state[12];
|
||||||
|
|
||||||
|
if (esnprintf(path, sizeof(path),
|
||||||
|
"/sys/class/power_supply/%s/status", bat) < 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (pscanf(path, "%12s", state) != 1) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < LEN(map); i++) {
|
||||||
|
if (!strcmp(map[i].state, state)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (i == LEN(map)) ? "?" : map[i].symbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
battery_remaining(const char *bat)
|
||||||
|
{
|
||||||
|
uintmax_t charge_now, current_now, m, h;
|
||||||
|
double timeleft;
|
||||||
|
char path[PATH_MAX], state[12];
|
||||||
|
|
||||||
|
if (esnprintf(path, sizeof(path),
|
||||||
|
"/sys/class/power_supply/%s/status", bat) < 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (pscanf(path, "%12s", state) != 1) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pick(bat, "/sys/class/power_supply/%s/charge_now",
|
||||||
|
"/sys/class/power_supply/%s/energy_now", path,
|
||||||
|
sizeof(path)) ||
|
||||||
|
pscanf(path, "%ju", &charge_now) < 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp(state, "Discharging")) {
|
||||||
|
if (!pick(bat, "/sys/class/power_supply/%s/current_now",
|
||||||
|
"/sys/class/power_supply/%s/power_now", path,
|
||||||
|
sizeof(path)) ||
|
||||||
|
pscanf(path, "%ju", ¤t_now) < 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current_now == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
timeleft = (double)charge_now / (double)current_now;
|
||||||
|
h = timeleft;
|
||||||
|
m = (timeleft - (double)h) * 60;
|
||||||
|
|
||||||
|
return bprintf("%juh %jum", h, m);
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
#elif defined(__OpenBSD__)
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <machine/apmvar.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
static int
|
||||||
|
load_apm_power_info(struct apm_power_info *apm_info)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
fd = open("/dev/apm", O_RDONLY);
|
||||||
|
if (fd < 0) {
|
||||||
|
warn("open '/dev/apm':");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(apm_info, 0, sizeof(struct apm_power_info));
|
||||||
|
if (ioctl(fd, APM_IOC_GETPOWER, apm_info) < 0) {
|
||||||
|
warn("ioctl 'APM_IOC_GETPOWER':");
|
||||||
|
close(fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return close(fd), 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
battery_perc(const char *unused)
|
||||||
|
{
|
||||||
|
struct apm_power_info apm_info;
|
||||||
|
|
||||||
|
if (load_apm_power_info(&apm_info)) {
|
||||||
|
return bprintf("%d", apm_info.battery_life);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
battery_state(const char *unused)
|
||||||
|
{
|
||||||
|
struct {
|
||||||
|
unsigned int state;
|
||||||
|
char *symbol;
|
||||||
|
} map[] = {
|
||||||
|
{ APM_AC_ON, "+" },
|
||||||
|
{ APM_AC_OFF, "-" },
|
||||||
|
};
|
||||||
|
struct apm_power_info apm_info;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (load_apm_power_info(&apm_info)) {
|
||||||
|
for (i = 0; i < LEN(map); i++) {
|
||||||
|
if (map[i].state == apm_info.ac_state) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (i == LEN(map)) ? "?" : map[i].symbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
battery_remaining(const char *unused)
|
||||||
|
{
|
||||||
|
struct apm_power_info apm_info;
|
||||||
|
|
||||||
|
if (load_apm_power_info(&apm_info)) {
|
||||||
|
if (apm_info.ac_state != APM_AC_ON) {
|
||||||
|
return bprintf("%uh %02um",
|
||||||
|
apm_info.minutes_left / 60,
|
||||||
|
apm_info.minutes_left % 60);
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#elif defined(__FreeBSD__)
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
|
||||||
|
const char *
|
||||||
|
battery_perc(const char *unused)
|
||||||
|
{
|
||||||
|
int cap;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
len = sizeof(cap);
|
||||||
|
if (sysctlbyname("hw.acpi.battery.life", &cap, &len, NULL, 0) == -1
|
||||||
|
|| !len)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return bprintf("%d", cap);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
battery_state(const char *unused)
|
||||||
|
{
|
||||||
|
int state;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
len = sizeof(state);
|
||||||
|
if (sysctlbyname("hw.acpi.battery.state", &state, &len, NULL, 0) == -1
|
||||||
|
|| !len)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
switch(state) {
|
||||||
|
case 0:
|
||||||
|
case 2:
|
||||||
|
return "+";
|
||||||
|
case 1:
|
||||||
|
return "-";
|
||||||
|
default:
|
||||||
|
return "?";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
battery_remaining(const char *unused)
|
||||||
|
{
|
||||||
|
int rem;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
len = sizeof(rem);
|
||||||
|
if (sysctlbyname("hw.acpi.battery.time", &rem, &len, NULL, 0) == -1
|
||||||
|
|| !len
|
||||||
|
|| rem == -1)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return bprintf("%uh %02um", rem / 60, rem % 60);
|
||||||
|
}
|
||||||
|
#endif
|
BIN
slstatus/components/battery.o
Normal file
BIN
slstatus/components/battery.o
Normal file
Binary file not shown.
164
slstatus/components/cpu.c
Normal file
164
slstatus/components/cpu.c
Normal file
|
@ -0,0 +1,164 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "../util.h"
|
||||||
|
|
||||||
|
#if defined(__linux__)
|
||||||
|
const char *
|
||||||
|
cpu_freq(void)
|
||||||
|
{
|
||||||
|
uintmax_t freq;
|
||||||
|
|
||||||
|
/* in kHz */
|
||||||
|
if (pscanf("/sys/devices/system/cpu/cpu0/cpufreq/"
|
||||||
|
"scaling_cur_freq", "%ju", &freq) != 1) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt_human(freq * 1000, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
cpu_perc(void)
|
||||||
|
{
|
||||||
|
static long double a[7];
|
||||||
|
long double b[7], sum;
|
||||||
|
|
||||||
|
memcpy(b, a, sizeof(b));
|
||||||
|
/* cpu user nice system idle iowait irq softirq */
|
||||||
|
if (pscanf("/proc/stat", "%*s %Lf %Lf %Lf %Lf %Lf %Lf %Lf",
|
||||||
|
&a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6])
|
||||||
|
!= 7) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (b[0] == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
sum = (b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6]) -
|
||||||
|
(a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6]);
|
||||||
|
|
||||||
|
if (sum == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bprintf("%d", (int)(100 *
|
||||||
|
((b[0] + b[1] + b[2] + b[5] + b[6]) -
|
||||||
|
(a[0] + a[1] + a[2] + a[5] + a[6])) / sum));
|
||||||
|
}
|
||||||
|
#elif defined(__OpenBSD__)
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/sched.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
|
||||||
|
const char *
|
||||||
|
cpu_freq(void)
|
||||||
|
{
|
||||||
|
int freq, mib[2];
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
mib[0] = CTL_HW;
|
||||||
|
mib[1] = HW_CPUSPEED;
|
||||||
|
|
||||||
|
size = sizeof(freq);
|
||||||
|
|
||||||
|
/* in MHz */
|
||||||
|
if (sysctl(mib, 2, &freq, &size, NULL, 0) < 0) {
|
||||||
|
warn("sysctl 'HW_CPUSPEED':");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt_human(freq * 1E6, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
cpu_perc(void)
|
||||||
|
{
|
||||||
|
int mib[2];
|
||||||
|
static uintmax_t a[CPUSTATES];
|
||||||
|
uintmax_t b[CPUSTATES], sum;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
mib[0] = CTL_KERN;
|
||||||
|
mib[1] = KERN_CPTIME;
|
||||||
|
|
||||||
|
size = sizeof(a);
|
||||||
|
|
||||||
|
memcpy(b, a, sizeof(b));
|
||||||
|
if (sysctl(mib, 2, &a, &size, NULL, 0) < 0) {
|
||||||
|
warn("sysctl 'KERN_CPTIME':");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (b[0] == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
sum = (a[CP_USER] + a[CP_NICE] + a[CP_SYS] + a[CP_INTR] + a[CP_IDLE]) -
|
||||||
|
(b[CP_USER] + b[CP_NICE] + b[CP_SYS] + b[CP_INTR] + b[CP_IDLE]);
|
||||||
|
|
||||||
|
if (sum == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bprintf("%d", 100 *
|
||||||
|
((a[CP_USER] + a[CP_NICE] + a[CP_SYS] +
|
||||||
|
a[CP_INTR]) -
|
||||||
|
(b[CP_USER] + b[CP_NICE] + b[CP_SYS] +
|
||||||
|
b[CP_INTR])) / sum);
|
||||||
|
}
|
||||||
|
#elif defined(__FreeBSD__)
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#include <devstat.h>
|
||||||
|
|
||||||
|
const char *
|
||||||
|
cpu_freq(void)
|
||||||
|
{
|
||||||
|
int freq;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
size = sizeof(freq);
|
||||||
|
/* in MHz */
|
||||||
|
if (sysctlbyname("hw.clockrate", &freq, &size, NULL, 0) == -1
|
||||||
|
|| !size) {
|
||||||
|
warn("sysctlbyname 'hw.clockrate':");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt_human(freq * 1E6, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
cpu_perc(void)
|
||||||
|
{
|
||||||
|
size_t size;
|
||||||
|
static long a[CPUSTATES];
|
||||||
|
long b[CPUSTATES], sum;
|
||||||
|
|
||||||
|
size = sizeof(a);
|
||||||
|
memcpy(b, a, sizeof(b));
|
||||||
|
if (sysctlbyname("kern.cp_time", &a, &size, NULL, 0) == -1
|
||||||
|
|| !size) {
|
||||||
|
warn("sysctlbyname 'kern.cp_time':");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (b[0] == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
sum = (a[CP_USER] + a[CP_NICE] + a[CP_SYS] + a[CP_INTR] + a[CP_IDLE]) -
|
||||||
|
(b[CP_USER] + b[CP_NICE] + b[CP_SYS] + b[CP_INTR] + b[CP_IDLE]);
|
||||||
|
|
||||||
|
if (sum == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bprintf("%d", 100 *
|
||||||
|
((a[CP_USER] + a[CP_NICE] + a[CP_SYS] +
|
||||||
|
a[CP_INTR]) -
|
||||||
|
(b[CP_USER] + b[CP_NICE] + b[CP_SYS] +
|
||||||
|
b[CP_INTR])) / sum);
|
||||||
|
}
|
||||||
|
#endif
|
BIN
slstatus/components/cpu.o
Normal file
BIN
slstatus/components/cpu.o
Normal file
Binary file not shown.
19
slstatus/components/datetime.c
Normal file
19
slstatus/components/datetime.c
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "../util.h"
|
||||||
|
|
||||||
|
const char *
|
||||||
|
datetime(const char *fmt)
|
||||||
|
{
|
||||||
|
time_t t;
|
||||||
|
|
||||||
|
t = time(NULL);
|
||||||
|
if (!strftime(buf, sizeof(buf), fmt, localtime(&t))) {
|
||||||
|
warn("strftime: Result string exceeds buffer size");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
BIN
slstatus/components/datetime.o
Normal file
BIN
slstatus/components/datetime.o
Normal file
Binary file not shown.
58
slstatus/components/disk.c
Normal file
58
slstatus/components/disk.c
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/statvfs.h>
|
||||||
|
|
||||||
|
#include "../util.h"
|
||||||
|
|
||||||
|
const char *
|
||||||
|
disk_free(const char *path)
|
||||||
|
{
|
||||||
|
struct statvfs fs;
|
||||||
|
|
||||||
|
if (statvfs(path, &fs) < 0) {
|
||||||
|
warn("statvfs '%s':", path);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt_human(fs.f_frsize * fs.f_bavail, 1024);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
disk_perc(const char *path)
|
||||||
|
{
|
||||||
|
struct statvfs fs;
|
||||||
|
|
||||||
|
if (statvfs(path, &fs) < 0) {
|
||||||
|
warn("statvfs '%s':", path);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bprintf("%d", (int)(100 *
|
||||||
|
(1.0f - ((float)fs.f_bavail / (float)fs.f_blocks))));
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
disk_total(const char *path)
|
||||||
|
{
|
||||||
|
struct statvfs fs;
|
||||||
|
|
||||||
|
if (statvfs(path, &fs) < 0) {
|
||||||
|
warn("statvfs '%s':", path);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt_human(fs.f_frsize * fs.f_blocks, 1024);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
disk_used(const char *path)
|
||||||
|
{
|
||||||
|
struct statvfs fs;
|
||||||
|
|
||||||
|
if (statvfs(path, &fs) < 0) {
|
||||||
|
warn("statvfs '%s':", path);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt_human(fs.f_frsize * (fs.f_blocks - fs.f_bfree), 1024);
|
||||||
|
}
|
BIN
slstatus/components/disk.o
Normal file
BIN
slstatus/components/disk.o
Normal file
Binary file not shown.
27
slstatus/components/entropy.c
Normal file
27
slstatus/components/entropy.c
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
#if defined(__linux__)
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "../util.h"
|
||||||
|
|
||||||
|
const char *
|
||||||
|
entropy(void)
|
||||||
|
{
|
||||||
|
uintmax_t num;
|
||||||
|
|
||||||
|
if (pscanf("/proc/sys/kernel/random/entropy_avail", "%ju", &num)
|
||||||
|
!= 1) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bprintf("%ju", num);
|
||||||
|
}
|
||||||
|
#elif defined(__OpenBSD__) | defined(__FreeBSD__)
|
||||||
|
const char *
|
||||||
|
entropy(void)
|
||||||
|
{
|
||||||
|
/* Unicode Character 'INFINITY' (U+221E) */
|
||||||
|
return "\xe2\x88\x9e";
|
||||||
|
}
|
||||||
|
#endif
|
BIN
slstatus/components/entropy.o
Normal file
BIN
slstatus/components/entropy.o
Normal file
Binary file not shown.
16
slstatus/components/hostname.c
Normal file
16
slstatus/components/hostname.c
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "../util.h"
|
||||||
|
|
||||||
|
const char *
|
||||||
|
hostname(void)
|
||||||
|
{
|
||||||
|
if (gethostname(buf, sizeof(buf)) < 0) {
|
||||||
|
warn("gethostbyname:");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
BIN
slstatus/components/hostname.o
Normal file
BIN
slstatus/components/hostname.o
Normal file
Binary file not shown.
60
slstatus/components/ip.c
Normal file
60
slstatus/components/ip.c
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
#include <ifaddrs.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#if defined(__OpenBSD__)
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#elif defined(__FreeBSD__)
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "../util.h"
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
ip(const char *interface, unsigned short sa_family)
|
||||||
|
{
|
||||||
|
struct ifaddrs *ifaddr, *ifa;
|
||||||
|
int s;
|
||||||
|
char host[NI_MAXHOST];
|
||||||
|
|
||||||
|
if (getifaddrs(&ifaddr) < 0) {
|
||||||
|
warn("getifaddrs:");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
|
||||||
|
if (!ifa->ifa_addr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
|
||||||
|
host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
|
||||||
|
if (!strcmp(ifa->ifa_name, interface) &&
|
||||||
|
(ifa->ifa_addr->sa_family == sa_family)) {
|
||||||
|
freeifaddrs(ifaddr);
|
||||||
|
if (s != 0) {
|
||||||
|
warn("getnameinfo: %s", gai_strerror(s));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return bprintf("%s", host);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
freeifaddrs(ifaddr);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
ipv4(const char *interface)
|
||||||
|
{
|
||||||
|
return ip(interface, AF_INET);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
ipv6(const char *interface)
|
||||||
|
{
|
||||||
|
return ip(interface, AF_INET6);
|
||||||
|
}
|
BIN
slstatus/components/ip.o
Normal file
BIN
slstatus/components/ip.o
Normal file
Binary file not shown.
18
slstatus/components/kernel_release.c
Normal file
18
slstatus/components/kernel_release.c
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "../util.h"
|
||||||
|
|
||||||
|
const char *
|
||||||
|
kernel_release(void)
|
||||||
|
{
|
||||||
|
struct utsname udata;
|
||||||
|
|
||||||
|
if (uname(&udata) < 0) {
|
||||||
|
warn("uname:");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bprintf("%s", udata.release);
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue