blocks
This commit is contained in:
parent
5c92a15063
commit
b3830b4b12
5 changed files with 353 additions and 85 deletions
56
.gitignore
vendored
Normal file
56
.gitignore
vendored
Normal file
|
@ -0,0 +1,56 @@
|
|||
# Custom blocks file
|
||||
blocks.h
|
||||
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Linker output
|
||||
*.ilk
|
||||
*.map
|
||||
*.exp
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
dwmblocks
|
||||
|
||||
# Debug files
|
||||
*.dSYM/
|
||||
*.su
|
||||
*.idb
|
||||
*.pdb
|
||||
|
||||
# Kernel Module Compile Results
|
||||
*.mod*
|
||||
*.cmd
|
||||
.tmp_versions/
|
||||
modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
36
Makefile
Normal file
36
Makefile
Normal file
|
@ -0,0 +1,36 @@
|
|||
PREFIX := /usr/local
|
||||
CC := cc
|
||||
CFLAGS := -pedantic -Wall -Wno-deprecated-declarations -Os
|
||||
LDFLAGS := -lX11
|
||||
|
||||
# FreeBSD (uncomment)
|
||||
#LDFLAGS += -L/usr/local/lib -I/usr/local/include
|
||||
# # OpenBSD (uncomment)
|
||||
#LDFLAGS += -L/usr/X11R6/lib -I/usr/X11R6/include
|
||||
|
||||
all: options dwmblocks
|
||||
|
||||
options:
|
||||
@echo dwmblocks build options:
|
||||
@echo "CFLAGS = ${CFLAGS}"
|
||||
@echo "LDFLAGS = ${LDFLAGS}"
|
||||
@echo "CC = ${CC}"
|
||||
|
||||
dwmblocks: dwmblocks.c blocks.def.h blocks.h
|
||||
${CC} -o dwmblocks dwmblocks.c ${CFLAGS} ${LDFLAGS}
|
||||
|
||||
blocks.h:
|
||||
cp blocks.def.h $@
|
||||
|
||||
clean:
|
||||
rm -f *.o *.gch dwmblocks
|
||||
|
||||
install: dwmblocks
|
||||
mkdir -p ${DESTDIR}${PREFIX}/bin
|
||||
cp -f dwmblocks ${DESTDIR}${PREFIX}/bin
|
||||
chmod 755 ${DESTDIR}${PREFIX}/bin/dwmblocks
|
||||
|
||||
uninstall:
|
||||
rm -f ${DESTDIR}${PREFIX}/bin/dwmblocks
|
||||
|
||||
.PHONY: all options clean install uninstall
|
119
README.md
119
README.md
|
@ -1,92 +1,41 @@
|
|||
# dwmblocks
|
||||
|
||||
|
||||
|
||||
## Getting started
|
||||
|
||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
||||
|
||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
||||
|
||||
## Add your files
|
||||
|
||||
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
||||
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
||||
|
||||
```
|
||||
cd existing_repo
|
||||
git remote add origin https://gitlab.com/tavo-wasd/blocks.git
|
||||
git branch -M main
|
||||
git push -uf origin main
|
||||
```
|
||||
|
||||
## Integrate with your tools
|
||||
|
||||
- [ ] [Set up project integrations](https://gitlab.com/tavo-wasd/blocks/-/settings/integrations)
|
||||
|
||||
## Collaborate with your team
|
||||
|
||||
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
||||
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
||||
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
||||
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
||||
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
||||
|
||||
## Test and Deploy
|
||||
|
||||
Use the built-in continuous integration in GitLab.
|
||||
|
||||
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
|
||||
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
||||
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
||||
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
||||
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
||||
|
||||
***
|
||||
|
||||
# Editing this README
|
||||
|
||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
||||
|
||||
## Suggestions for a good README
|
||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
||||
|
||||
## Name
|
||||
Choose a self-explaining name for your project.
|
||||
# My personal dwm build
|
||||
|
||||
## Description
|
||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
||||
My personal repository for a custom dwm build currently using the Gruvbox theme.
|
||||
|
||||
## Badges
|
||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
||||
## Patches applied to suckless' software
|
||||
Applied via \*.diff files found in suckless.org, in the appearing order.
|
||||
Unsuccessful patches generated a \*.rej file which was moved to the corresponding "patches/manpatch/" directory for each program, and renamed \*.manpatch. This was then used to manually patch the source code.
|
||||
|
||||
## Visuals
|
||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
||||
### dwm
|
||||
(2147 lines of code unpatched, added +414 lines for 2561 total)
|
||||
- swallow
|
||||
- pertag
|
||||
- fullgaps
|
||||
- movestack
|
||||
- notitle
|
||||
- attachbottom
|
||||
- warp
|
||||
- alwayscenter
|
||||
|
||||
## Installation
|
||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
||||
## Dependencies (Archlinux names)
|
||||
ttf-nerd-fonts-symbols-2048-em-mono.
|
||||
make,
|
||||
libxcb
|
||||
libX11-devel,
|
||||
libXft-devel,
|
||||
libXinerama-devel,
|
||||
alsa-utils,
|
||||
cilpmenu,
|
||||
scrot,
|
||||
dunst,
|
||||
|
||||
## Usage
|
||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
||||
## Default apps
|
||||
librewolf,
|
||||
mpv,
|
||||
vim,
|
||||
nnn,
|
||||
|
||||
## Support
|
||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
||||
|
||||
## Roadmap
|
||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
||||
|
||||
## Contributing
|
||||
State if you are open to contributions and what your requirements are for accepting them.
|
||||
|
||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
||||
|
||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
||||
|
||||
## Authors and acknowledgment
|
||||
Show your appreciation to those who have contributed to the project.
|
||||
|
||||
## License
|
||||
For open source projects, say how it is licensed.
|
||||
|
||||
## Project status
|
||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
||||
## Not necessary but useful in laptops
|
||||
iwd,
|
||||
brightnessctl,
|
||||
|
|
14
blocks.def.h
Normal file
14
blocks.def.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
//Modify this file to change what commands output to your statusbar, and recompile using the make command.
|
||||
static const Block blocks[] = {
|
||||
/*Icon*/ /*Command*/ /*Update Interval*/ /*Update Signal*/
|
||||
{" ♫ ", "volstat", 0, 10},
|
||||
/* {" 直 ", "iwdstat", 2, 0},*/
|
||||
{" ", "layoutstat", 0, 11},
|
||||
/* {" ", "batstat", 2, 0},*/
|
||||
{" ", "date '+%I:%M%p'", 2, 0},
|
||||
{" ", "date '+%a %Y-%m-%d'", 2, 0},
|
||||
};
|
||||
|
||||
//sets delimeter between status commands. NULL character ('\0') means no delimeter.
|
||||
static char delim[] = " ";
|
||||
static unsigned int delimLen = 5;
|
213
dwmblocks.c
Normal file
213
dwmblocks.c
Normal file
|
@ -0,0 +1,213 @@
|
|||
#include<stdlib.h>
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
#include<unistd.h>
|
||||
#include<signal.h>
|
||||
#ifndef NO_X
|
||||
#include<X11/Xlib.h>
|
||||
#endif
|
||||
#ifdef __OpenBSD__
|
||||
#define SIGPLUS SIGUSR1+1
|
||||
#define SIGMINUS SIGUSR1-1
|
||||
#else
|
||||
#define SIGPLUS SIGRTMIN
|
||||
#define SIGMINUS SIGRTMIN
|
||||
#endif
|
||||
#define LENGTH(X) (sizeof(X) / sizeof (X[0]))
|
||||
#define CMDLENGTH 50
|
||||
#define MIN( a, b ) ( ( a < b) ? a : b )
|
||||
#define STATUSLENGTH (LENGTH(blocks) * CMDLENGTH + 1)
|
||||
|
||||
typedef struct {
|
||||
char* icon;
|
||||
char* command;
|
||||
unsigned int interval;
|
||||
unsigned int signal;
|
||||
} Block;
|
||||
#ifndef __OpenBSD__
|
||||
void dummysighandler(int num);
|
||||
#endif
|
||||
void sighandler(int num);
|
||||
void getcmds(int time);
|
||||
void getsigcmds(unsigned int signal);
|
||||
void setupsignals();
|
||||
void sighandler(int signum);
|
||||
int getstatus(char *str, char *last);
|
||||
void statusloop();
|
||||
void termhandler();
|
||||
void pstdout();
|
||||
#ifndef NO_X
|
||||
void setroot();
|
||||
static void (*writestatus) () = setroot;
|
||||
static int setupX();
|
||||
static Display *dpy;
|
||||
static int screen;
|
||||
static Window root;
|
||||
#else
|
||||
static void (*writestatus) () = pstdout;
|
||||
#endif
|
||||
|
||||
|
||||
#include "blocks.h"
|
||||
|
||||
static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0};
|
||||
static char statusstr[2][STATUSLENGTH];
|
||||
static int statusContinue = 1;
|
||||
static int returnStatus = 0;
|
||||
|
||||
//opens process *cmd and stores output in *output
|
||||
void getcmd(const Block *block, char *output)
|
||||
{
|
||||
strcpy(output, block->icon);
|
||||
FILE *cmdf = popen(block->command, "r");
|
||||
if (!cmdf)
|
||||
return;
|
||||
int i = strlen(block->icon);
|
||||
fgets(output+i, CMDLENGTH-i-delimLen, cmdf);
|
||||
i = strlen(output);
|
||||
if (i == 0) {
|
||||
//return if block and command output are both empty
|
||||
pclose(cmdf);
|
||||
return;
|
||||
}
|
||||
//only chop off newline if one is present at the end
|
||||
i = output[i-1] == '\n' ? i-1 : i;
|
||||
if (delim[0] != '\0') {
|
||||
strncpy(output+i, delim, delimLen);
|
||||
}
|
||||
else
|
||||
output[i++] = '\0';
|
||||
pclose(cmdf);
|
||||
}
|
||||
|
||||
void getcmds(int time)
|
||||
{
|
||||
const Block* current;
|
||||
for (unsigned int i = 0; i < LENGTH(blocks); i++) {
|
||||
current = blocks + i;
|
||||
if ((current->interval != 0 && time % current->interval == 0) || time == -1)
|
||||
getcmd(current,statusbar[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void getsigcmds(unsigned int signal)
|
||||
{
|
||||
const Block *current;
|
||||
for (unsigned int i = 0; i < LENGTH(blocks); i++) {
|
||||
current = blocks + i;
|
||||
if (current->signal == signal)
|
||||
getcmd(current,statusbar[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void setupsignals()
|
||||
{
|
||||
#ifndef __OpenBSD__
|
||||
/* initialize all real time signals with dummy handler */
|
||||
for (int i = SIGRTMIN; i <= SIGRTMAX; i++)
|
||||
signal(i, dummysighandler);
|
||||
#endif
|
||||
|
||||
for (unsigned int i = 0; i < LENGTH(blocks); i++) {
|
||||
if (blocks[i].signal > 0)
|
||||
signal(SIGMINUS+blocks[i].signal, sighandler);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int getstatus(char *str, char *last)
|
||||
{
|
||||
strcpy(last, str);
|
||||
str[0] = '\0';
|
||||
for (unsigned int i = 0; i < LENGTH(blocks); i++)
|
||||
strcat(str, statusbar[i]);
|
||||
str[strlen(str)-strlen(delim)] = '\0';
|
||||
return strcmp(str, last);//0 if they are the same
|
||||
}
|
||||
|
||||
#ifndef NO_X
|
||||
void setroot()
|
||||
{
|
||||
if (!getstatus(statusstr[0], statusstr[1]))//Only set root if text has changed.
|
||||
return;
|
||||
XStoreName(dpy, root, statusstr[0]);
|
||||
XFlush(dpy);
|
||||
}
|
||||
|
||||
int setupX()
|
||||
{
|
||||
dpy = XOpenDisplay(NULL);
|
||||
if (!dpy) {
|
||||
fprintf(stderr, "dwmblocks: Failed to open display\n");
|
||||
return 0;
|
||||
}
|
||||
screen = DefaultScreen(dpy);
|
||||
root = RootWindow(dpy, screen);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
void pstdout()
|
||||
{
|
||||
if (!getstatus(statusstr[0], statusstr[1]))//Only write out if text has changed.
|
||||
return;
|
||||
printf("%s\n",statusstr[0]);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
void statusloop()
|
||||
{
|
||||
setupsignals();
|
||||
int i = 0;
|
||||
getcmds(-1);
|
||||
while (1) {
|
||||
getcmds(i++);
|
||||
writestatus();
|
||||
if (!statusContinue)
|
||||
break;
|
||||
sleep(1.0);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef __OpenBSD__
|
||||
/* this signal handler should do nothing */
|
||||
void dummysighandler(int signum)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
void sighandler(int signum)
|
||||
{
|
||||
getsigcmds(signum-SIGPLUS);
|
||||
writestatus();
|
||||
}
|
||||
|
||||
void termhandler()
|
||||
{
|
||||
statusContinue = 0;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
for (int i = 0; i < argc; i++) {//Handle command line arguments
|
||||
if (!strcmp("-d",argv[i]))
|
||||
strncpy(delim, argv[++i], delimLen);
|
||||
else if (!strcmp("-p",argv[i]))
|
||||
writestatus = pstdout;
|
||||
}
|
||||
#ifndef NO_X
|
||||
if (!setupX())
|
||||
return 1;
|
||||
#endif
|
||||
delimLen = MIN(delimLen, strlen(delim));
|
||||
delim[delimLen++] = '\0';
|
||||
signal(SIGTERM, termhandler);
|
||||
signal(SIGINT, termhandler);
|
||||
statusloop();
|
||||
#ifndef NO_X
|
||||
XCloseDisplay(dpy);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue