Initial commit: Geminux 0.1.0 (helio) for Planet Computers Gemini PDA (MT6797X)
This commit is contained in:
commit
034c1f61b1
816 files changed
+223435
No files matched your search
@@ -0,0 +1,42 @@
|
||||
# Geminux dmenu Makefile
|
||||
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 util.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) config.h
|
||||
|
||||
install: all
|
||||
mkdir -p $(DESTDIR)$(PREFIX)/bin
|
||||
cp -f dmenu dmenu_path dmenu_run stest $(DESTDIR)$(PREFIX)/bin/
|
||||
chmod 755 $(DESTDIR)$(PREFIX)/bin/dmenu $(DESTDIR)$(PREFIX)/bin/dmenu_path \
|
||||
$(DESTDIR)$(PREFIX)/bin/dmenu_run $(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 $(DESTDIR)$(MANPREFIX)/man1/stest.1
|
||||
|
||||
.PHONY: all options clean install
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copy me if you can.
|
||||
* by 20h
|
||||
*/
|
||||
|
||||
#ifndef ARG_H__
|
||||
#define ARG_H__
|
||||
|
||||
extern char *argv0;
|
||||
|
||||
/* use main(int argc, char *argv[]) */
|
||||
#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\
|
||||
argv[0] && argv[0][0] == '-'\
|
||||
&& argv[0][1];\
|
||||
argc--, argv++) {\
|
||||
char argc_;\
|
||||
char **argv_;\
|
||||
int brk_;\
|
||||
if (argv[0][1] == '-' && argv[0][2] == '\0') {\
|
||||
argv++;\
|
||||
argc--;\
|
||||
break;\
|
||||
}\
|
||||
for (brk_ = 0, argv[0]++, argv_ = argv;\
|
||||
argv[0][0] && !brk_;\
|
||||
argv[0]++) {\
|
||||
if (argv_ != argv)\
|
||||
break;\
|
||||
argc_ = argv[0][0];\
|
||||
switch (argc_)
|
||||
|
||||
#define ARGEND }\
|
||||
}
|
||||
|
||||
#define ARGC() argc_
|
||||
|
||||
#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\
|
||||
((x), abort(), (char *)0) :\
|
||||
(brk_ = 1, (argv[0][1] != '\0')?\
|
||||
(&argv[0][1]) :\
|
||||
(argc--, argv++, argv[0])))
|
||||
|
||||
#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\
|
||||
(char *)0 :\
|
||||
(brk_ = 1, (argv[0][1] != '\0')?\
|
||||
(&argv[0][1]) :\
|
||||
(argc--, argv++, argv[0])))
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
/* Geminux dmenu configuration (2160x1080 HiDPI, Fira Code + Nerd Fonts) */
|
||||
|
||||
static int topbar = 1;
|
||||
static int fuzzy = 1;
|
||||
static const char *fonts[] = {
|
||||
"Fira Code, DejaVuSansM Nerd Font 20px"
|
||||
};
|
||||
static const char *prompt = NULL;
|
||||
static const char *colors[SchemeLast][2] = {
|
||||
/* fg bg */
|
||||
[SchemeNorm] = { "#e6e1cf", "#0b0e14" },
|
||||
[SchemeSel] = { "#ffffff", "#2b5278" },
|
||||
[SchemeOut] = { "#ffffff", "#243040" },
|
||||
};
|
||||
static unsigned int lines = 0;
|
||||
static unsigned int lineheight = 48;
|
||||
static unsigned int min_lineheight = 48;
|
||||
static const char worddelimiters[] = " ";
|
||||
@@ -0,0 +1,19 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
/* Geminux dmenu configuration (2160x1080 HiDPI, Fira Code + Nerd Fonts) */
|
||||
|
||||
static int topbar = 1;
|
||||
static int fuzzy = 1;
|
||||
static const char *fonts[] = {
|
||||
"Fira Code, DejaVuSansM Nerd Font 20px"
|
||||
};
|
||||
static const char *prompt = NULL;
|
||||
static const char *colors[SchemeLast][2] = {
|
||||
/* fg bg */
|
||||
[SchemeNorm] = { "#e6e1cf", "#0b0e14" },
|
||||
[SchemeSel] = { "#ffffff", "#2b5278" },
|
||||
[SchemeOut] = { "#ffffff", "#243040" },
|
||||
};
|
||||
static unsigned int lines = 0;
|
||||
static unsigned int lineheight = 48;
|
||||
static unsigned int min_lineheight = 48;
|
||||
static const char worddelimiters[] = " ";
|
||||
@@ -0,0 +1,16 @@
|
||||
# Geminux dmenu build configuration (Pango + HarfBuzz + .Xresources + Xinerama)
|
||||
VERSION = 5.3-geminux
|
||||
|
||||
PREFIX = /usr
|
||||
MANPREFIX = $(PREFIX)/share/man
|
||||
|
||||
PKG_CONFIG ?= pkg-config
|
||||
|
||||
INCS = $(shell $(PKG_CONFIG) --cflags fontconfig freetype2 xft pango pangoxft harfbuzz x11 xinerama)
|
||||
LIBS = -lm $(shell $(PKG_CONFIG) --libs fontconfig freetype2 xft pango pangoxft harfbuzz x11 xinerama)
|
||||
|
||||
CPPFLAGS = -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" -DXINERAMA
|
||||
CFLAGS = -std=gnu99 -pedantic -Wall -O2 $(INCS) $(CPPFLAGS)
|
||||
LDFLAGS = $(LIBS)
|
||||
|
||||
CC ?= cc
|
||||
@@ -0,0 +1,252 @@
|
||||
.TH DMENU 1 dmenu\-VERSION
|
||||
.SH NAME
|
||||
dmenu \- dynamic menu
|
||||
.SH SYNOPSIS
|
||||
.B dmenu
|
||||
.RB [ \-bfitv ]
|
||||
.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 [ \-H
|
||||
.IR height ]
|
||||
.RB [ \-w
|
||||
.IR windowid ]
|
||||
.RB [ \-idx
|
||||
.IR index ]
|
||||
.RB [ \-wm ]
|
||||
.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 \-nc
|
||||
dmenu appears not centered on the screen.
|
||||
.TP
|
||||
.B \-f
|
||||
dmenu grabs the keyboard before reading stdin if not reading from a tty. This
|
||||
is faster, but will lock up X until stdin reaches end\-of\-file.
|
||||
.TP
|
||||
.B \-i
|
||||
dmenu matches menu items case insensitively.
|
||||
.TP
|
||||
.BI \-l " lines"
|
||||
dmenu lists items vertically, with the given number of lines.
|
||||
.TP
|
||||
.BI \-H " height"
|
||||
dmenu uses a menu line of at least 'height' pixels tall, but no less than 8
|
||||
.TP
|
||||
.BI \-m " monitor"
|
||||
dmenu is displayed on the monitor number supplied. Monitor numbers are starting
|
||||
from 0.
|
||||
.TP
|
||||
.BI \-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 \-t
|
||||
Return key prints input text instead of selection.
|
||||
.TP
|
||||
.B \-v
|
||||
prints version information to stdout, then exits.
|
||||
.TP
|
||||
.BI \-w " windowid"
|
||||
embed into windowid.
|
||||
.TP
|
||||
.BI \-idx " index"
|
||||
specify the initial selection index number.
|
||||
.TP
|
||||
.BI \-wm
|
||||
Display as a managed WM window (e.g. don't set overide_redirect flag)
|
||||
.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. If \-t option is given it confirms input instead of selection.
|
||||
.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.
|
||||
If \-t option is given it confirms selection instead of input.
|
||||
.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\-nc
|
||||
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 X Resources
|
||||
.TP
|
||||
.BI dmenu.font
|
||||
defines the font or font set used.
|
||||
.TP
|
||||
.BI dmenu.background
|
||||
defines the normal background color.
|
||||
.IR #RGB ,
|
||||
.IR #RRGGBB ,
|
||||
and X color names are supported.
|
||||
.TP
|
||||
.BI dmenu.foreground
|
||||
defines the normal foreground color.
|
||||
.TP
|
||||
.BI dmenu.selbackground
|
||||
defines the selected background color.
|
||||
.TP
|
||||
.BI dmenu.selforeground
|
||||
defines the selected foreground color.
|
||||
.TP
|
||||
.BI dmenu.selhighlightbackground
|
||||
defines the highlighted selected background color.
|
||||
.TP
|
||||
.BI dmenu.selhighlightforeground
|
||||
defines the highlighted selected foreground color.
|
||||
.TP
|
||||
.BI dmenu.highlightbackground
|
||||
defines the highlighted background color.
|
||||
.TP
|
||||
.BI dmenu.highlightforeground
|
||||
defines the highlighted foreground color.
|
||||
.TP
|
||||
.BI dmenu.outbackground
|
||||
defines the out background color.
|
||||
.TP
|
||||
.BI dmenu.outforeground
|
||||
defines the out foreground color.
|
||||
.SH SEE ALSO
|
||||
.IR dwm (1),
|
||||
.IR stest (1)
|
||||
@@ -0,0 +1,931 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
/* Geminux dmenu - Pango/HarfBuzz + .Xresources + HiDPI touch & keyboard */
|
||||
#include <ctype.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/Xresource.h>
|
||||
#ifdef XINERAMA
|
||||
#include <X11/extensions/Xinerama.h>
|
||||
#endif
|
||||
#include <X11/Xft/Xft.h>
|
||||
|
||||
#include "drw.h"
|
||||
#include "util.h"
|
||||
|
||||
#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)
|
||||
|
||||
enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast };
|
||||
|
||||
struct item {
|
||||
char *text;
|
||||
struct item *left, *right;
|
||||
int out;
|
||||
double distance;
|
||||
};
|
||||
|
||||
static char text[BUFSIZ] = "";
|
||||
static char *embed = NULL;
|
||||
static int bh, mw, mh;
|
||||
static int inputw = 0, promptw;
|
||||
static int lrpad;
|
||||
static size_t cursor = 0;
|
||||
static struct item *items = NULL;
|
||||
static struct item *matches = NULL, *matchend = NULL;
|
||||
static struct item *prev = NULL, *curr = NULL, *next = NULL, *sel = NULL;
|
||||
static int mon = -1, screen;
|
||||
|
||||
static Atom clip, utf8;
|
||||
static Display *dpy;
|
||||
static Window root, parentwin, win;
|
||||
static XIC xic;
|
||||
|
||||
static Drw *drw;
|
||||
static Clr *scheme[SchemeLast];
|
||||
static char xres_font[256] = "";
|
||||
static char *dyn_colors[SchemeLast][2] = { {NULL, NULL}, {NULL, NULL}, {NULL, NULL} };
|
||||
|
||||
#include "config.h"
|
||||
|
||||
static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
|
||||
static char *(*fstrstr)(const char *, const char *) = strstr;
|
||||
|
||||
static int cistrncmp(const char *s1, const char *s2, size_t n) {
|
||||
for (; n > 0 && *s1 && *s2; s1++, s2++, n--) {
|
||||
int d = tolower((unsigned char)*s1) - tolower((unsigned char)*s2);
|
||||
if (d != 0) return d;
|
||||
}
|
||||
if (n == 0) return 0;
|
||||
return tolower((unsigned char)*s1) - tolower((unsigned char)*s2);
|
||||
}
|
||||
|
||||
static char *cistrstr(const char *s, const char *sub) {
|
||||
size_t len;
|
||||
if (!sub[0]) return (char *)s;
|
||||
for (len = strlen(sub); *s; s++) {
|
||||
if (!cistrncmp(s, sub, len)) return (char *)s;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *xrm_get(XrmDatabase xdb, const char *k1, const char *k2, const char *k3) {
|
||||
char *type = NULL;
|
||||
XrmValue xval;
|
||||
if (k1 && XrmGetResource(xdb, k1, "*", &type, &xval) && xval.addr && xval.addr[0])
|
||||
return xval.addr;
|
||||
if (k2 && XrmGetResource(xdb, k2, "*", &type, &xval) && xval.addr && xval.addr[0])
|
||||
return xval.addr;
|
||||
if (k3 && XrmGetResource(xdb, k3, "*", &type, &xval) && xval.addr && xval.addr[0])
|
||||
return xval.addr;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void load_xresources(void) {
|
||||
XrmInitialize();
|
||||
const char *home = getenv("HOME");
|
||||
char path[512];
|
||||
snprintf(path, sizeof(path), "%s/.Xresources", (home && home[0]) ? home : "/home/user");
|
||||
XrmDatabase xdb = XrmGetFileDatabase(path);
|
||||
if (!xdb) {
|
||||
char *xrm = XResourceManagerString(dpy);
|
||||
if (xrm) xdb = XrmGetStringDatabase(xrm);
|
||||
}
|
||||
if (!xdb) return;
|
||||
|
||||
const char *dm_font = xrm_get(xdb, "dmenu.font", NULL, NULL);
|
||||
const char *th_face = xrm_get(xdb, "theme.fontFace", NULL, NULL);
|
||||
const char *th_icon = xrm_get(xdb, "theme.iconFontFace", NULL, NULL);
|
||||
const char *th_size = xrm_get(xdb, "theme.baseFontSize", NULL, NULL);
|
||||
if (th_face) {
|
||||
int px = th_size ? atoi(th_size) : 22;
|
||||
if (px < 12 || px > 48) px = 22;
|
||||
snprintf(xres_font, sizeof(xres_font), "%s, %s %dpx",
|
||||
th_face, th_icon ? th_icon : "DejaVuSansM Nerd Font", px);
|
||||
fonts[0] = xres_font;
|
||||
} else if (dm_font) {
|
||||
snprintf(xres_font, sizeof(xres_font), "%s", dm_font);
|
||||
fonts[0] = xres_font;
|
||||
}
|
||||
|
||||
struct { int scm; int col; const char *k1; const char *k2; } map[] = {
|
||||
{ SchemeNorm, ColFg, "dmenu.foreground", "theme.fgBright" },
|
||||
{ SchemeNorm, ColBg, "dmenu.background", "theme.bgHeader" },
|
||||
{ SchemeSel, ColFg, "dmenu.selforeground", "theme.selFg" },
|
||||
{ SchemeSel, ColBg, "dmenu.selbackground", "theme.selBg" },
|
||||
{ SchemeOut, ColFg, "dmenu.outforeground", "theme.fgMain" },
|
||||
{ SchemeOut, ColBg, "dmenu.outbackground", "theme.bgSearch" },
|
||||
};
|
||||
for (size_t i = 0; i < LENGTH(map); i++) {
|
||||
const char *v = xrm_get(xdb, map[i].k1, map[i].k2, NULL);
|
||||
if (v) {
|
||||
free(dyn_colors[map[i].scm][map[i].col]);
|
||||
dyn_colors[map[i].scm][map[i].col] = strdup(v);
|
||||
colors[map[i].scm][map[i].col] = dyn_colors[map[i].scm][map[i].col];
|
||||
}
|
||||
}
|
||||
XrmDestroyDatabase(xdb);
|
||||
}
|
||||
|
||||
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 = (int)(lines * bh);
|
||||
else
|
||||
n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
|
||||
for (i = 0, next = curr; next; next = next->right) {
|
||||
int step = (lines > 0) ? bh : (int)TEXTW(next->text);
|
||||
if ((i += MIN(step, n)) > n)
|
||||
break;
|
||||
}
|
||||
for (i = 0, prev = curr; prev && prev->left; prev = prev->left) {
|
||||
int step = (lines > 0) ? bh : (int)TEXTW(prev->left->text);
|
||||
if ((i += MIN(step, n)) > n)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int max_textw(void) {
|
||||
int len = 0;
|
||||
for (struct item *item = items; item && item->text; item++)
|
||||
len = MAX((int)TEXTW(item->text), len);
|
||||
return len;
|
||||
}
|
||||
|
||||
static void cleanup(void) {
|
||||
size_t i;
|
||||
XUngrabKey(dpy, AnyKey, AnyModifier, root);
|
||||
for (i = 0; i < SchemeLast; i++) {
|
||||
free(scheme[i]);
|
||||
free(dyn_colors[i][0]);
|
||||
free(dyn_colors[i][1]);
|
||||
}
|
||||
for (i = 0; items && items[i].text; i++)
|
||||
free(items[i].text);
|
||||
free(items);
|
||||
drw_free(drw);
|
||||
XSync(dpy, False);
|
||||
XCloseDisplay(dpy);
|
||||
}
|
||||
|
||||
static int drawitem(struct item *item, int x, int y, int w) {
|
||||
if (item == sel)
|
||||
drw_setscheme(drw, scheme[SchemeSel]);
|
||||
else if (item->out)
|
||||
drw_setscheme(drw, scheme[SchemeOut]);
|
||||
else
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
return drw_text(drw, x, y, (unsigned int)w, (unsigned int)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, (unsigned int)mw, (unsigned int)mh, 1, 1);
|
||||
|
||||
if (prompt && *prompt) {
|
||||
drw_setscheme(drw, scheme[SchemeSel]);
|
||||
x = drw_text(drw, x, 0, (unsigned int)promptw, (unsigned int)bh, lrpad / 2, prompt, 0);
|
||||
}
|
||||
w = (lines > 0 || !matches) ? mw - x : inputw;
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
drw_text(drw, x, 0, (unsigned int)w, (unsigned int)bh, lrpad / 2, text, 0);
|
||||
|
||||
curpos = TEXTW(text) - TEXTW(&text[cursor]);
|
||||
if ((int)(curpos += lrpad / 2 - 1) < w) {
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
drw_rect(drw, x + (int)curpos, 4, 2, (unsigned int)bh - 8, 1, 0);
|
||||
}
|
||||
|
||||
if (lines > 0) {
|
||||
for (item = curr; item != next; item = item->right)
|
||||
drawitem(item, x, y += bh, mw - x);
|
||||
} else if (matches) {
|
||||
x += inputw;
|
||||
w = (int)TEXTW("<");
|
||||
if (curr->left) {
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
drw_text(drw, x, 0, (unsigned int)w, (unsigned int)bh, lrpad / 2, "<", 0);
|
||||
}
|
||||
x += w;
|
||||
for (item = curr; item != next; item = item->right)
|
||||
x = drawitem(item, x, 0, TEXTW(item->text));
|
||||
if (next) {
|
||||
w = (int)TEXTW(">");
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
drw_text(drw, mw - w, 0, (unsigned int)w, (unsigned int)bh, lrpad / 2, ">", 0);
|
||||
}
|
||||
}
|
||||
drw_map(drw, win, 0, 0, (unsigned int)mw, (unsigned int)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);
|
||||
}
|
||||
}
|
||||
|
||||
static void grabkeyboard(void) {
|
||||
struct timespec ts = { .tv_sec = 0, .tv_nsec = 1000000 };
|
||||
int i;
|
||||
if (embed) return;
|
||||
for (i = 0; i < 1000; i++) {
|
||||
if (XGrabKeyboard(dpy, DefaultRootWindow(dpy), True, GrabModeAsync,
|
||||
GrabModeAsync, CurrentTime) == GrabSuccess)
|
||||
return;
|
||||
nanosleep(&ts, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static int compare_distance(const void *a, const void *b) {
|
||||
const struct item *da = *(const struct item *const *)a;
|
||||
const struct item *db = *(const struct item *const *)b;
|
||||
if (!db) return 1;
|
||||
if (!da) return -1;
|
||||
return da->distance == db->distance ? 0 : da->distance < db->distance ? -1 : 1;
|
||||
}
|
||||
|
||||
static void fuzzymatch(void) {
|
||||
struct item *it;
|
||||
struct item **fuzzymatches = NULL;
|
||||
char c;
|
||||
int number_of_matches = 0, i, pidx, sidx, eidx;
|
||||
int text_len = (int)strlen(text), itext_len;
|
||||
|
||||
matches = matchend = NULL;
|
||||
for (it = items; it && it->text; it++) {
|
||||
if (text_len) {
|
||||
itext_len = (int)strlen(it->text);
|
||||
pidx = 0;
|
||||
sidx = eidx = -1;
|
||||
for (i = 0; i < itext_len && (c = it->text[i]); i++) {
|
||||
if (!fstrncmp(&text[pidx], &c, 1)) {
|
||||
if (sidx == -1) sidx = i;
|
||||
pidx++;
|
||||
if (pidx == text_len) {
|
||||
eidx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (eidx != -1) {
|
||||
it->distance = log(sidx + 2) + (double)(eidx - sidx - text_len);
|
||||
appenditem(it, &matches, &matchend);
|
||||
number_of_matches++;
|
||||
}
|
||||
} else {
|
||||
appenditem(it, &matches, &matchend);
|
||||
}
|
||||
}
|
||||
if (number_of_matches) {
|
||||
fuzzymatches = realloc(fuzzymatches, (size_t)number_of_matches * sizeof(struct item *));
|
||||
if (!fuzzymatches) die("cannot realloc:");
|
||||
for (i = 0, it = matches; it && i < number_of_matches; i++, it = it->right)
|
||||
fuzzymatches[i] = it;
|
||||
qsort(fuzzymatches, (size_t)number_of_matches, sizeof(struct item *), compare_distance);
|
||||
matches = matchend = NULL;
|
||||
for (i = 0; i < number_of_matches; i++)
|
||||
appenditem(fuzzymatches[i], &matches, &matchend);
|
||||
free(fuzzymatches);
|
||||
}
|
||||
curr = sel = matches;
|
||||
calcoffsets();
|
||||
}
|
||||
|
||||
static void match(void) {
|
||||
if (fuzzy) {
|
||||
fuzzymatch();
|
||||
return;
|
||||
}
|
||||
static char **tokv = NULL;
|
||||
static int tokn = 0;
|
||||
char buf[sizeof text], *s;
|
||||
int i, tokc = 0;
|
||||
size_t len, textsize;
|
||||
struct item *item, *lprefix, *lsubstr, *prefixend, *substrend;
|
||||
|
||||
strcpy(buf, text);
|
||||
for (s = strtok(buf, " "); s; tokv[tokc - 1] = s, s = strtok(NULL, " ")) {
|
||||
if (++tokc > tokn && !(tokv = realloc(tokv, (size_t)(++tokn) * sizeof(*tokv))))
|
||||
die("cannot realloc %zu 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) continue;
|
||||
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) + (size_t)n > sizeof text - 1) return;
|
||||
memmove(&text[cursor + (size_t)n], &text[cursor], sizeof text - cursor - (size_t)MAX(n, 0));
|
||||
if (n > 0) memcpy(&text[cursor], str, (size_t)n);
|
||||
cursor += (size_t)n;
|
||||
match();
|
||||
}
|
||||
|
||||
static size_t nextrune(int inc) {
|
||||
ssize_t n;
|
||||
for (n = (ssize_t)cursor + inc; n + inc >= 0 && (text[n] & 0xc0) == 0x80; n += inc)
|
||||
;
|
||||
return (size_t)n;
|
||||
}
|
||||
|
||||
static void movewordedge(int dir) {
|
||||
if (dir < 0) {
|
||||
while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)]))
|
||||
cursor = nextrune(-1);
|
||||
while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)]))
|
||||
cursor = nextrune(-1);
|
||||
} else {
|
||||
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[64];
|
||||
int len;
|
||||
KeySym ksym = NoSymbol;
|
||||
Status status;
|
||||
|
||||
len = Xutf8LookupString(xic, ev, buf, sizeof buf - 1, &ksym, &status);
|
||||
switch (status) {
|
||||
default:
|
||||
return;
|
||||
case XLookupChars:
|
||||
goto insert_chars;
|
||||
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:
|
||||
case XK_J:
|
||||
case XK_m:
|
||||
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:
|
||||
text[cursor] = '\0';
|
||||
match();
|
||||
break;
|
||||
case XK_u:
|
||||
insert(NULL, -(ssize_t)cursor);
|
||||
break;
|
||||
case XK_w:
|
||||
while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)]))
|
||||
insert(NULL, (ssize_t)(nextrune(-1) - cursor));
|
||||
while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)]))
|
||||
insert(NULL, (ssize_t)(nextrune(-1) - cursor));
|
||||
break;
|
||||
case XK_v:
|
||||
case XK_V:
|
||||
case XK_y:
|
||||
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;
|
||||
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_chars:
|
||||
buf[len] = '\0';
|
||||
if (len > 0 && !iscntrl((unsigned char)*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, (ssize_t)(nextrune(-1) - cursor));
|
||||
break;
|
||||
case XK_End:
|
||||
case XK_KP_End:
|
||||
if (text[cursor] != '\0') {
|
||||
cursor = strlen(text);
|
||||
break;
|
||||
}
|
||||
if (next) {
|
||||
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 buttonpress(XEvent *e) {
|
||||
struct item *item;
|
||||
XButtonPressedEvent *ev = &e->xbutton;
|
||||
int x = 0, y = 0, w;
|
||||
|
||||
if (ev->window != win) return;
|
||||
if (ev->button == Button4) {
|
||||
if (sel && sel->left) {
|
||||
sel = sel->left;
|
||||
if (sel->right == curr) {
|
||||
curr = prev;
|
||||
calcoffsets();
|
||||
}
|
||||
drawmenu();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (ev->button == Button5) {
|
||||
if (sel && sel->right) {
|
||||
sel = sel->right;
|
||||
if (sel == next) {
|
||||
curr = next;
|
||||
calcoffsets();
|
||||
}
|
||||
drawmenu();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (ev->button != Button1) {
|
||||
if (ev->button == Button3) {
|
||||
cleanup();
|
||||
exit(1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (prompt && *prompt)
|
||||
x += promptw;
|
||||
|
||||
if (lines > 0) {
|
||||
if (ev->y < bh) {
|
||||
drawmenu();
|
||||
return;
|
||||
}
|
||||
w = mw - x;
|
||||
for (item = curr; item != next; item = item->right) {
|
||||
y += bh;
|
||||
if (ev->y >= y && ev->y < y + bh) {
|
||||
puts(item->text);
|
||||
cleanup();
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!matches) return;
|
||||
if (ev->x < x + inputw) return;
|
||||
w = (int)TEXTW("<");
|
||||
if (curr->left && ev->x >= x + inputw && ev->x < x + inputw + w) {
|
||||
if (prev) {
|
||||
sel = curr = prev;
|
||||
calcoffsets();
|
||||
drawmenu();
|
||||
}
|
||||
return;
|
||||
}
|
||||
x += inputw + w;
|
||||
for (item = curr; item != next; item = item->right) {
|
||||
int iw = (int)TEXTW(item->text);
|
||||
if (ev->x >= x && ev->x < x + iw) {
|
||||
puts(item->text);
|
||||
cleanup();
|
||||
exit(0);
|
||||
}
|
||||
x += iw;
|
||||
}
|
||||
if (next && ev->x >= mw - (int)TEXTW(">")) {
|
||||
sel = curr = next;
|
||||
calcoffsets();
|
||||
drawmenu();
|
||||
}
|
||||
}
|
||||
|
||||
static void pastesel(void) {
|
||||
char *p, *q;
|
||||
int di;
|
||||
unsigned long dl;
|
||||
Atom da;
|
||||
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')) ? (ssize_t)(q - p) : (ssize_t)strlen(p));
|
||||
XFree(p);
|
||||
}
|
||||
drawmenu();
|
||||
}
|
||||
|
||||
static void readstdin(void) {
|
||||
char buf[sizeof text], *p;
|
||||
size_t i, itemsiz = 0;
|
||||
ssize_t len;
|
||||
char *line = NULL;
|
||||
size_t linesiz = 0;
|
||||
|
||||
for (i = 0; (len = getline(&line, &linesiz, stdin)) > 0; i++) {
|
||||
if (i + 1 >= itemsiz) {
|
||||
itemsiz += 256;
|
||||
if (!(items = realloc(items, itemsiz * sizeof(*items))))
|
||||
die("cannot realloc %zu bytes:", itemsiz * sizeof(*items));
|
||||
}
|
||||
if (line[len - 1] == '\n')
|
||||
line[len - 1] = '\0';
|
||||
else {
|
||||
strncpy(buf, line, sizeof buf - 1);
|
||||
buf[sizeof buf - 1] = '\0';
|
||||
p = buf;
|
||||
line = strdup(p);
|
||||
}
|
||||
if (!(items[i].text = strdup(line)))
|
||||
die("cannot strdup %zu bytes:", strlen(line) + 1);
|
||||
items[i].out = 0;
|
||||
}
|
||||
free(line);
|
||||
if (items) items[i].text = NULL;
|
||||
lines = MIN(lines, (unsigned int)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, (unsigned int)mw, (unsigned int)mh);
|
||||
break;
|
||||
case FocusIn:
|
||||
if (ev.xfocus.window != win) grabfocus();
|
||||
break;
|
||||
case KeyPress:
|
||||
keypress(&ev.xkey);
|
||||
break;
|
||||
case ButtonPress:
|
||||
buttonpress(&ev);
|
||||
break;
|
||||
case SelectionNotify:
|
||||
if (ev.xselection.property == utf8) pastesel();
|
||||
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
|
||||
|
||||
scheme[SchemeNorm] = drw_scm_create(drw, colors[SchemeNorm], 2);
|
||||
scheme[SchemeSel] = drw_scm_create(drw, colors[SchemeSel], 2);
|
||||
scheme[SchemeOut] = drw_scm_create(drw, colors[SchemeOut], 2);
|
||||
|
||||
clip = XInternAtom(dpy, "CLIPBOARD", False);
|
||||
utf8 = XInternAtom(dpy, "UTF8_STRING", False);
|
||||
|
||||
bh = MAX((int)drw->fonts->h + 18, (int)lineheight);
|
||||
if (bh < (int)min_lineheight) bh = (int)min_lineheight;
|
||||
lines = MAX(lines, 0);
|
||||
mh = (int)(lines + 1) * bh;
|
||||
promptw = (prompt && *prompt) ? (int)TEXTW(prompt) : 0;
|
||||
|
||||
#ifdef XINERAMA
|
||||
i = 0;
|
||||
if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) {
|
||||
XGetInputFocus(dpy, &w, &di);
|
||||
if (mon >= 0 && mon < n) {
|
||||
i = mon;
|
||||
} else if (w != root && w != PointerRoot && w != None) {
|
||||
do {
|
||||
if (XQueryTree(dpy, w, &dw, &pw, &dws, &du) && dws) XFree(dws);
|
||||
if (XGetWindowAttributes(dpy, w, &wa)) break;
|
||||
w = pw;
|
||||
} while (w != root && pw != None);
|
||||
if (XGetWindowAttributes(dpy, w, &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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
inputw = mw / 3;
|
||||
match();
|
||||
|
||||
swa.override_redirect = True;
|
||||
swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | VisibilityChangeMask;
|
||||
win = XCreateWindow(dpy, parentwin, x, y, (unsigned int)mw, (unsigned int)mh, 0,
|
||||
CopyFromParent, CopyFromParent, CopyFromParent,
|
||||
CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
|
||||
XSetClassHint(dpy, win, &ch);
|
||||
|
||||
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; (unsigned int)i < du && dws[i] != win; ++i)
|
||||
XSelectInput(dpy, dws[i], FocusChangeMask);
|
||||
XFree(dws);
|
||||
}
|
||||
grabfocus();
|
||||
}
|
||||
drw_resize(drw, (unsigned int)mw, (unsigned int)mh);
|
||||
drawmenu();
|
||||
}
|
||||
|
||||
static void usage(void) {
|
||||
die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
|
||||
" [-nb color] [-nf color] [-sb color] [-sf color]\n"
|
||||
" [-h height] [-w windowid]");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
XWindowAttributes wa;
|
||||
int i, fast = 0;
|
||||
|
||||
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);
|
||||
|
||||
load_xresources();
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (!strcmp(argv[i], "-v")) {
|
||||
puts("dmenu-" VERSION);
|
||||
return 0;
|
||||
} else if (!strcmp(argv[i], "-b")) {
|
||||
topbar = 0;
|
||||
} else if (!strcmp(argv[i], "-f")) {
|
||||
fast = 1;
|
||||
} else if (!strcmp(argv[i], "-F")) {
|
||||
fuzzy = 0;
|
||||
} else if (!strcmp(argv[i], "-i")) {
|
||||
fstrncmp = cistrncmp;
|
||||
fstrstr = cistrstr;
|
||||
} else if (i + 1 == argc) {
|
||||
usage();
|
||||
} else if (!strcmp(argv[i], "-l")) {
|
||||
lines = (unsigned int)atoi(argv[++i]);
|
||||
} else if (!strcmp(argv[i], "-m")) {
|
||||
mon = atoi(argv[++i]);
|
||||
} else if (!strcmp(argv[i], "-p")) {
|
||||
prompt = argv[++i];
|
||||
} else if (!strcmp(argv[i], "-fn")) {
|
||||
fonts[0] = argv[++i];
|
||||
} else if (!strcmp(argv[i], "-nb")) {
|
||||
colors[SchemeNorm][ColBg] = argv[++i];
|
||||
} else if (!strcmp(argv[i], "-nf")) {
|
||||
colors[SchemeNorm][ColFg] = argv[++i];
|
||||
} else if (!strcmp(argv[i], "-sb")) {
|
||||
colors[SchemeSel][ColBg] = argv[++i];
|
||||
} else if (!strcmp(argv[i], "-sf")) {
|
||||
colors[SchemeSel][ColFg] = argv[++i];
|
||||
} else if (!strcmp(argv[i], "-h")) {
|
||||
lineheight = (unsigned int)atoi(argv[++i]);
|
||||
} else if (!strcmp(argv[i], "-w")) {
|
||||
embed = argv[++i];
|
||||
} else {
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (!embed || !(parentwin = (Window)strtol(embed, NULL, 0)))
|
||||
parentwin = root;
|
||||
if (!XGetWindowAttributes(dpy, parentwin, &wa))
|
||||
die("could not get embedding window attributes: 0x%lx", parentwin);
|
||||
drw = drw_create(dpy, screen, root, (unsigned int)wa.width, (unsigned int)wa.height);
|
||||
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
|
||||
die("no fonts could be loaded.");
|
||||
lrpad = (int)drw->fonts->h;
|
||||
|
||||
if (fast && !isatty(0)) {
|
||||
grabkeyboard();
|
||||
readstdin();
|
||||
} else {
|
||||
readstdin();
|
||||
grabkeyboard();
|
||||
}
|
||||
setup();
|
||||
run();
|
||||
return 1;
|
||||
}
|
||||
Executable
+13
@@ -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
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
dmenu_path | dmenu "$@" | ${SHELL:-"/bin/sh"} &
|
||||
+231
@@ -0,0 +1,231 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
/* Pango + HarfBuzz + Xft drawing backend for Geminux dmenu */
|
||||
#include <hb.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xft/Xft.h>
|
||||
#include <pango/pango.h>
|
||||
#include <pango/pangoxft.h>
|
||||
|
||||
#include "drw.h"
|
||||
#include "util.h"
|
||||
|
||||
Drw *drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) {
|
||||
Drw *drw = ecalloc(1, sizeof(Drw));
|
||||
drw->dpy = dpy;
|
||||
drw->screen = screen;
|
||||
drw->root = root;
|
||||
drw->w = w;
|
||||
drw->h = h;
|
||||
drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen));
|
||||
drw->gc = XCreateGC(dpy, root, 0, NULL);
|
||||
XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
|
||||
return drw;
|
||||
}
|
||||
|
||||
void drw_resize(Drw *drw, unsigned int w, unsigned int h) {
|
||||
if (!drw) return;
|
||||
drw->w = w;
|
||||
drw->h = h;
|
||||
if (drw->drawable)
|
||||
XFreePixmap(drw->dpy, drw->drawable);
|
||||
drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen));
|
||||
}
|
||||
|
||||
void drw_free(Drw *drw) {
|
||||
if (!drw) return;
|
||||
if (drw->drawable)
|
||||
XFreePixmap(drw->dpy, drw->drawable);
|
||||
if (drw->gc)
|
||||
XFreeGC(drw->dpy, drw->gc);
|
||||
drw_fontset_free(drw->fonts);
|
||||
free(drw);
|
||||
}
|
||||
|
||||
Fnt *drw_fontset_create(Drw *drw, const char *fonts[], size_t fontcount) {
|
||||
Fnt *fnt = ecalloc(1, sizeof(Fnt));
|
||||
PangoFontMetrics *metrics;
|
||||
(void)hb_version_string();
|
||||
const char *spec = (fonts && fontcount > 0 && fonts[0] && fonts[0][0])
|
||||
? fonts[0]
|
||||
: "Fira Code, DejaVuSansM Nerd Font 20px";
|
||||
|
||||
fnt->dpy = drw->dpy;
|
||||
fnt->fontmap = pango_xft_get_font_map(drw->dpy, drw->screen);
|
||||
fnt->context = pango_font_map_create_context(fnt->fontmap);
|
||||
fnt->desc = pango_font_description_from_string(spec);
|
||||
pango_context_set_font_description(fnt->context, fnt->desc);
|
||||
|
||||
metrics = pango_context_get_metrics(fnt->context, fnt->desc, pango_language_get_default());
|
||||
fnt->h = (unsigned int)((pango_font_metrics_get_ascent(metrics) +
|
||||
pango_font_metrics_get_descent(metrics)) / PANGO_SCALE);
|
||||
if (fnt->h < 14) fnt->h = 20;
|
||||
pango_font_metrics_unref(metrics);
|
||||
|
||||
fnt->layout = pango_layout_new(fnt->context);
|
||||
pango_layout_set_font_description(fnt->layout, fnt->desc);
|
||||
drw->fonts = fnt;
|
||||
return fnt;
|
||||
}
|
||||
|
||||
void drw_fontset_free(Fnt *set) {
|
||||
if (!set) return;
|
||||
if (set->layout) g_object_unref(set->layout);
|
||||
if (set->context) g_object_unref(set->context);
|
||||
if (set->desc) pango_font_description_free(set->desc);
|
||||
free(set);
|
||||
}
|
||||
|
||||
void drw_clr_create(Drw *drw, Clr *dest, const char *clrname) {
|
||||
if (!drw || !dest || !clrname) return;
|
||||
if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
|
||||
DefaultColormap(drw->dpy, drw->screen), clrname, dest)) {
|
||||
XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
|
||||
DefaultColormap(drw->dpy, drw->screen), "#ffffff", dest);
|
||||
}
|
||||
}
|
||||
|
||||
Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) {
|
||||
Clr *ret;
|
||||
if (!drw || !clrnames || clrcount == 0) return NULL;
|
||||
ret = ecalloc(clrcount, sizeof(XftColor));
|
||||
for (size_t i = 0; i < clrcount; i++)
|
||||
drw_clr_create(drw, &ret[i], clrnames[i]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void drw_setfontset(Drw *drw, Fnt *set) {
|
||||
if (drw) drw->fonts = set;
|
||||
}
|
||||
|
||||
void drw_setscheme(Drw *drw, Clr *scm) {
|
||||
if (drw) drw->scheme = scm;
|
||||
}
|
||||
|
||||
void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert) {
|
||||
if (!drw || !drw->scheme) return;
|
||||
XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme[ColBg].pixel : drw->scheme[ColFg].pixel);
|
||||
if (filled)
|
||||
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
|
||||
else
|
||||
XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w - 1, h - 1);
|
||||
}
|
||||
|
||||
int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
|
||||
unsigned int lpad, const char *text, int invert) {
|
||||
char buf[1024];
|
||||
int ty, render = x || y || w || h;
|
||||
unsigned int ew, eh;
|
||||
XftDraw *d = NULL;
|
||||
|
||||
if (!drw || (render && !drw->scheme) || !text || !drw->fonts)
|
||||
return 0;
|
||||
|
||||
if (!render) {
|
||||
w = ~0;
|
||||
} else {
|
||||
XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel);
|
||||
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
|
||||
d = XftDrawCreate(drw->dpy, drw->drawable,
|
||||
DefaultVisual(drw->dpy, drw->screen),
|
||||
DefaultColormap(drw->dpy, drw->screen));
|
||||
x += (int)lpad;
|
||||
if (w > lpad) w -= lpad;
|
||||
}
|
||||
|
||||
size_t len = strlen(text);
|
||||
if (len >= sizeof(buf)) len = sizeof(buf) - 1;
|
||||
memcpy(buf, text, len);
|
||||
buf[len] = '\0';
|
||||
|
||||
if (len > 0 && w > 0) {
|
||||
drw_font_getexts(drw->fonts, buf, (unsigned int)len, &ew, &eh);
|
||||
while (len > 3 && ew > w) {
|
||||
len--;
|
||||
while (len > 0 && (buf[len] & 0xc0) == 0x80) len--;
|
||||
if (len >= 3) memcpy(buf + len - 3, "...", 3);
|
||||
buf[len] = '\0';
|
||||
drw_font_getexts(drw->fonts, buf, (unsigned int)len, &ew, &eh);
|
||||
}
|
||||
if (render && d) {
|
||||
pango_layout_set_text(drw->fonts->layout, buf, -1);
|
||||
ty = y + (int)(h - eh) / 2;
|
||||
if (ty < y) ty = y;
|
||||
pango_xft_render_layout(d, &drw->scheme[invert ? ColBg : ColFg],
|
||||
drw->fonts->layout, x * PANGO_SCALE, ty * PANGO_SCALE);
|
||||
}
|
||||
x += (int)ew;
|
||||
}
|
||||
|
||||
if (d) XftDrawDestroy(d);
|
||||
return x + (render ? (int)w : 0);
|
||||
}
|
||||
|
||||
int drw_text_align(Drw *drw, int x, int y, unsigned int w, unsigned int h,
|
||||
const char *text, int textlen, int align) {
|
||||
char buf[1024];
|
||||
if (!drw || !drw->scheme || !drw->fonts || !text) return x;
|
||||
int len = textlen < (int)sizeof(buf) - 1 ? textlen : (int)sizeof(buf) - 1;
|
||||
if (len < 0) len = 0;
|
||||
memcpy(buf, text, (size_t)len);
|
||||
buf[len] = '\0';
|
||||
|
||||
unsigned int ew = 0, eh = 0;
|
||||
drw_font_getexts(drw->fonts, buf, (unsigned int)len, &ew, &eh);
|
||||
int dx = (align == AlignR && ew < w) ? x + (int)(w - ew) : x;
|
||||
int ty = y + (int)(h - eh) / 2;
|
||||
if (ty < y) ty = y;
|
||||
|
||||
XftDraw *d = XftDrawCreate(drw->dpy, drw->drawable,
|
||||
DefaultVisual(drw->dpy, drw->screen),
|
||||
DefaultColormap(drw->dpy, drw->screen));
|
||||
pango_layout_set_text(drw->fonts->layout, buf, len);
|
||||
pango_xft_render_layout(d, &drw->scheme[ColFg],
|
||||
drw->fonts->layout, dx * PANGO_SCALE, ty * PANGO_SCALE);
|
||||
XftDrawDestroy(d);
|
||||
return dx + (int)ew;
|
||||
}
|
||||
|
||||
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) {
|
||||
unsigned int w = 0, h = 0;
|
||||
if (!drw || !drw->fonts || !text || !text[0]) return 0;
|
||||
drw_font_getexts(drw->fonts, text, (unsigned int)strlen(text), &w, &h);
|
||||
return w;
|
||||
}
|
||||
|
||||
void drw_font_getexts(Fnt *font, const char *text, unsigned int len,
|
||||
unsigned int *w, unsigned int *h) {
|
||||
PangoRectangle r;
|
||||
if (!font || !text) {
|
||||
if (w) *w = 0;
|
||||
if (h) *h = 0;
|
||||
return;
|
||||
}
|
||||
pango_layout_set_text(font->layout, text, (int)len);
|
||||
pango_layout_get_extents(font->layout, NULL, &r);
|
||||
if (w) *w = (unsigned int)((r.width + PANGO_SCALE - 1) / PANGO_SCALE);
|
||||
if (h) *h = (unsigned int)((r.height + PANGO_SCALE - 1) / PANGO_SCALE);
|
||||
if (h && *h == 0) *h = font->h;
|
||||
}
|
||||
|
||||
Cur *drw_cur_create(Drw *drw, int shape) {
|
||||
Cur *cur;
|
||||
if (!drw) return NULL;
|
||||
cur = ecalloc(1, sizeof(Cur));
|
||||
cur->cursor = XCreateFontCursor(drw->dpy, shape);
|
||||
return cur;
|
||||
}
|
||||
|
||||
void drw_cur_free(Drw *drw, Cur *cursor) {
|
||||
if (!cursor) return;
|
||||
if (drw) XFreeCursor(drw->dpy, cursor->cursor);
|
||||
free(cursor);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#ifndef DMENU_DRW_H
|
||||
#define DMENU_DRW_H
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xft/Xft.h>
|
||||
#include <pango/pango.h>
|
||||
#include <pango/pangoxft.h>
|
||||
|
||||
typedef struct {
|
||||
Cursor cursor;
|
||||
} Cur;
|
||||
|
||||
typedef struct Fnt {
|
||||
Display *dpy;
|
||||
unsigned int h;
|
||||
PangoLayout *layout;
|
||||
PangoFontMap *fontmap;
|
||||
PangoContext *context;
|
||||
PangoFontDescription *desc;
|
||||
} Fnt;
|
||||
|
||||
enum { ColFg, ColBg }; /* Clr scheme index */
|
||||
enum { AlignL, AlignR };
|
||||
typedef XftColor Clr;
|
||||
|
||||
typedef struct {
|
||||
unsigned int w, h;
|
||||
Display *dpy;
|
||||
int screen;
|
||||
Window root;
|
||||
Drawable drawable;
|
||||
GC gc;
|
||||
Clr *scheme;
|
||||
Fnt *fonts;
|
||||
} Drw;
|
||||
|
||||
Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h);
|
||||
void drw_resize(Drw *drw, unsigned int w, unsigned int h);
|
||||
void drw_free(Drw *drw);
|
||||
|
||||
Fnt *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);
|
||||
|
||||
void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
|
||||
Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
|
||||
|
||||
Cur *drw_cur_create(Drw *drw, int shape);
|
||||
void drw_cur_free(Drw *drw, Cur *cursor);
|
||||
|
||||
void drw_setfontset(Drw *drw, Fnt *set);
|
||||
void drw_setscheme(Drw *drw, Clr *scm);
|
||||
|
||||
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);
|
||||
|
||||
void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,90 @@
|
||||
.TH STEST 1 dmenu\-VERSION
|
||||
.SH NAME
|
||||
stest \- filter a list of files by properties
|
||||
.SH SYNOPSIS
|
||||
.B stest
|
||||
.RB [ -abcdefghlpqrsuwx ]
|
||||
.RB [ -n
|
||||
.IR file ]
|
||||
.RB [ -o
|
||||
.IR file ]
|
||||
.RI [ file ...]
|
||||
.SH DESCRIPTION
|
||||
.B stest
|
||||
takes a list of files and filters by the files' properties, analogous to
|
||||
.IR test (1).
|
||||
Files which pass all tests are printed to stdout. If no files are given, stest
|
||||
reads files from stdin.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B \-a
|
||||
Test hidden files.
|
||||
.TP
|
||||
.B \-b
|
||||
Test that files are block specials.
|
||||
.TP
|
||||
.B \-c
|
||||
Test that files are character specials.
|
||||
.TP
|
||||
.B \-d
|
||||
Test that files are directories.
|
||||
.TP
|
||||
.B \-e
|
||||
Test that files exist.
|
||||
.TP
|
||||
.B \-f
|
||||
Test that files are regular files.
|
||||
.TP
|
||||
.B \-g
|
||||
Test that files have their set-group-ID flag set.
|
||||
.TP
|
||||
.B \-h
|
||||
Test that files are symbolic links.
|
||||
.TP
|
||||
.B \-l
|
||||
Test the contents of a directory given as an argument.
|
||||
.TP
|
||||
.BI \-n " file"
|
||||
Test that files are newer than
|
||||
.IR file .
|
||||
.TP
|
||||
.BI \-o " file"
|
||||
Test that files are older than
|
||||
.IR file .
|
||||
.TP
|
||||
.B \-p
|
||||
Test that files are named pipes.
|
||||
.TP
|
||||
.B \-q
|
||||
No files are printed, only the exit status is returned.
|
||||
.TP
|
||||
.B \-r
|
||||
Test that files are readable.
|
||||
.TP
|
||||
.B \-s
|
||||
Test that files are not empty.
|
||||
.TP
|
||||
.B \-u
|
||||
Test that files have their set-user-ID flag set.
|
||||
.TP
|
||||
.B \-v
|
||||
Invert the sense of tests, only failing files pass.
|
||||
.TP
|
||||
.B \-w
|
||||
Test that files are writable.
|
||||
.TP
|
||||
.B \-x
|
||||
Test that files are executable.
|
||||
.SH EXIT STATUS
|
||||
.TP
|
||||
.B 0
|
||||
At least one file passed all tests.
|
||||
.TP
|
||||
.B 1
|
||||
No files passed all tests.
|
||||
.TP
|
||||
.B 2
|
||||
An error occurred.
|
||||
.SH SEE ALSO
|
||||
.IR dmenu (1),
|
||||
.IR test (1)
|
||||
@@ -0,0 +1,109 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "arg.h"
|
||||
char *argv0;
|
||||
|
||||
#define FLAG(x) (flag[(x)-'a'])
|
||||
|
||||
static void test(const char *, const char *);
|
||||
static void usage(void);
|
||||
|
||||
static int match = 0;
|
||||
static int flag[26];
|
||||
static struct stat old, new;
|
||||
|
||||
static void
|
||||
test(const char *path, const char *name)
|
||||
{
|
||||
struct stat st, ln;
|
||||
|
||||
if ((!stat(path, &st) && (FLAG('a') || name[0] != '.') /* hidden files */
|
||||
&& (!FLAG('b') || S_ISBLK(st.st_mode)) /* block special */
|
||||
&& (!FLAG('c') || S_ISCHR(st.st_mode)) /* character special */
|
||||
&& (!FLAG('d') || S_ISDIR(st.st_mode)) /* directory */
|
||||
&& (!FLAG('e') || access(path, F_OK) == 0) /* exists */
|
||||
&& (!FLAG('f') || S_ISREG(st.st_mode)) /* regular file */
|
||||
&& (!FLAG('g') || st.st_mode & S_ISGID) /* set-group-id flag */
|
||||
&& (!FLAG('h') || (!lstat(path, &ln) && S_ISLNK(ln.st_mode))) /* symbolic link */
|
||||
&& (!FLAG('n') || st.st_mtime > new.st_mtime) /* newer than file */
|
||||
&& (!FLAG('o') || st.st_mtime < old.st_mtime) /* older than file */
|
||||
&& (!FLAG('p') || S_ISFIFO(st.st_mode)) /* named pipe */
|
||||
&& (!FLAG('r') || access(path, R_OK) == 0) /* readable */
|
||||
&& (!FLAG('s') || st.st_size > 0) /* not empty */
|
||||
&& (!FLAG('u') || st.st_mode & S_ISUID) /* set-user-id flag */
|
||||
&& (!FLAG('w') || access(path, W_OK) == 0) /* writable */
|
||||
&& (!FLAG('x') || access(path, X_OK) == 0)) != FLAG('v')) { /* executable */
|
||||
if (FLAG('q'))
|
||||
exit(0);
|
||||
match = 1;
|
||||
puts(name);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr, "usage: %s [-abcdefghlpqrsuvwx] "
|
||||
"[-n file] [-o file] [file...]\n", argv0);
|
||||
exit(2); /* like test(1) return > 1 on error */
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct dirent *d;
|
||||
char path[PATH_MAX], *line = NULL, *file;
|
||||
size_t linesiz = 0;
|
||||
ssize_t n;
|
||||
DIR *dir;
|
||||
int r;
|
||||
|
||||
ARGBEGIN {
|
||||
case 'n': /* newer than file */
|
||||
case 'o': /* older than file */
|
||||
file = EARGF(usage());
|
||||
if (!(FLAG(ARGC()) = !stat(file, (ARGC() == 'n' ? &new : &old))))
|
||||
perror(file);
|
||||
break;
|
||||
default:
|
||||
/* miscellaneous operators */
|
||||
if (strchr("abcdefghlpqrsuvwx", ARGC()))
|
||||
FLAG(ARGC()) = 1;
|
||||
else
|
||||
usage(); /* unknown flag */
|
||||
} ARGEND;
|
||||
|
||||
if (!argc) {
|
||||
/* read list from stdin */
|
||||
while ((n = getline(&line, &linesiz, stdin)) > 0) {
|
||||
if (n && line[n - 1] == '\n')
|
||||
line[n - 1] = '\0';
|
||||
test(line, line);
|
||||
}
|
||||
free(line);
|
||||
} else {
|
||||
for (; argc; argc--, argv++) {
|
||||
if (FLAG('l') && (dir = opendir(*argv))) {
|
||||
/* test directory contents */
|
||||
while ((d = readdir(dir))) {
|
||||
r = snprintf(path, sizeof path, "%s/%s",
|
||||
*argv, d->d_name);
|
||||
if (r >= 0 && (size_t)r < sizeof path)
|
||||
test(path, d->d_name);
|
||||
}
|
||||
closedir(dir);
|
||||
} else {
|
||||
test(*argv, *argv);
|
||||
}
|
||||
}
|
||||
}
|
||||
return match ? 0 : 1;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
void *
|
||||
ecalloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
if (!(p = calloc(nmemb, size)))
|
||||
die("calloc:");
|
||||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
die(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
|
||||
fputc(' ', stderr);
|
||||
perror(NULL);
|
||||
} else {
|
||||
fputc('\n', stderr);
|
||||
}
|
||||
|
||||
exit(1);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
|
||||
#define MAX(A, B) ((A) > (B) ? (A) : (B))
|
||||
#define MIN(A, B) ((A) < (B) ? (A) : (B))
|
||||
#define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B))
|
||||
|
||||
void die(const char *fmt, ...);
|
||||
void *ecalloc(size_t nmemb, size_t size);
|
||||
@@ -0,0 +1,289 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdbool.h>
|
||||
#include <cairo.h>
|
||||
#include <jpeglib.h>
|
||||
|
||||
#include "icon.h"
|
||||
#include "icon-lookup.h"
|
||||
#include "log.h"
|
||||
#include "notification.h"
|
||||
#include "settings.h"
|
||||
#include "utils.h"
|
||||
|
||||
static void pixbuf_data_to_cairo_data(
|
||||
const unsigned char *pixels_p,
|
||||
unsigned char *pixels_c,
|
||||
size_t rowstride_p,
|
||||
size_t rowstride_c,
|
||||
int width,
|
||||
int height,
|
||||
int n_channels)
|
||||
{
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
static const size_t CAIRO_B = 0;
|
||||
static const size_t CAIRO_G = 1;
|
||||
static const size_t CAIRO_R = 2;
|
||||
static const size_t CAIRO_A = 3;
|
||||
#else
|
||||
static const size_t CAIRO_A = 0;
|
||||
static const size_t CAIRO_R = 1;
|
||||
static const size_t CAIRO_G = 2;
|
||||
static const size_t CAIRO_B = 3;
|
||||
#endif
|
||||
assert(pixels_p && pixels_c && width > 0 && height > 0);
|
||||
if (n_channels == 3) {
|
||||
for (int h = 0; h < height; h++) {
|
||||
unsigned char *iter_c = pixels_c + h * rowstride_c;
|
||||
const unsigned char *iter_p = pixels_p + h * rowstride_p;
|
||||
for (int w = 0; w < width; w++) {
|
||||
iter_c[CAIRO_R] = iter_p[0];
|
||||
iter_c[CAIRO_G] = iter_p[1];
|
||||
iter_c[CAIRO_B] = iter_p[2];
|
||||
iter_c[CAIRO_A] = 0xff;
|
||||
iter_c += 4;
|
||||
iter_p += 3;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int h = 0; h < height; h++) {
|
||||
unsigned char *iter_c = pixels_c + h * rowstride_c;
|
||||
const unsigned char *iter_p = pixels_p + h * rowstride_p;
|
||||
for (int w = 0; w < width; w++) {
|
||||
double alpha_factor = iter_p[3] / (double)0xff;
|
||||
iter_c[CAIRO_R] = (unsigned char)(iter_p[0] * alpha_factor + .5);
|
||||
iter_c[CAIRO_G] = (unsigned char)(iter_p[1] * alpha_factor + .5);
|
||||
iter_c[CAIRO_B] = (unsigned char)(iter_p[2] * alpha_factor + .5);
|
||||
iter_c[CAIRO_A] = iter_p[3];
|
||||
iter_c += 4;
|
||||
iter_p += n_channels;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int get_icon_width(cairo_surface_t *icon, double scale) {
|
||||
return (int)round(cairo_image_surface_get_width(icon) / scale);
|
||||
}
|
||||
|
||||
int get_icon_height(cairo_surface_t *icon, double scale) {
|
||||
return (int)round(cairo_image_surface_get_height(icon) / scale);
|
||||
}
|
||||
|
||||
static bool icon_size_clamp(int *w, int *h, int min_size, int max_size) {
|
||||
int _w = *w;
|
||||
int _h = *h;
|
||||
if (_w <= 0 || _h <= 0) return false;
|
||||
int larger = MAX(_w, _h);
|
||||
int smaller = MIN(_w, _h);
|
||||
bool landscape = (_w >= _h);
|
||||
bool changed = false;
|
||||
|
||||
if (min_size > 0 && larger < min_size) {
|
||||
smaller = (int)round((double)smaller * min_size / larger);
|
||||
larger = min_size;
|
||||
changed = true;
|
||||
} else if (max_size > 0 && larger > max_size) {
|
||||
smaller = (int)round((double)smaller * max_size / larger);
|
||||
larger = max_size;
|
||||
changed = true;
|
||||
}
|
||||
if (changed) {
|
||||
*w = MAX(1, landscape ? larger : smaller);
|
||||
*h = MAX(1, landscape ? smaller : larger);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
static cairo_surface_t *scale_cairo_surface(cairo_surface_t *src, double dpi_scale,
|
||||
int min_size, int max_size) {
|
||||
if (!src || cairo_surface_status(src) != CAIRO_STATUS_SUCCESS) {
|
||||
if (src) cairo_surface_destroy(src);
|
||||
return NULL;
|
||||
}
|
||||
int sw = cairo_image_surface_get_width(src);
|
||||
int sh = cairo_image_surface_get_height(src);
|
||||
if (sw <= 0 || sh <= 0) {
|
||||
cairo_surface_destroy(src);
|
||||
return NULL;
|
||||
}
|
||||
int dw = sw, dh = sh;
|
||||
icon_size_clamp(&dw, &dh, min_size, max_size);
|
||||
dw = MAX(1, (int)round(dw * dpi_scale));
|
||||
dh = MAX(1, (int)round(dh * dpi_scale));
|
||||
if (dw == sw && dh == sh)
|
||||
return src;
|
||||
|
||||
cairo_format_t fmt = cairo_image_surface_get_format(src);
|
||||
if (fmt != CAIRO_FORMAT_ARGB32 && fmt != CAIRO_FORMAT_RGB24)
|
||||
fmt = CAIRO_FORMAT_ARGB32;
|
||||
cairo_surface_t *dst = cairo_image_surface_create(fmt, dw, dh);
|
||||
cairo_t *cr = cairo_create(dst);
|
||||
cairo_scale(cr, (double)dw / sw, (double)dh / sh);
|
||||
cairo_set_source_surface(cr, src, 0, 0);
|
||||
cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_BILINEAR);
|
||||
cairo_paint(cr);
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_destroy(src);
|
||||
return dst;
|
||||
}
|
||||
|
||||
struct gem_jpeg_err {
|
||||
struct jpeg_error_mgr pub;
|
||||
jmp_buf jmp;
|
||||
};
|
||||
|
||||
static void gem_jpeg_exit(j_common_ptr cinfo) {
|
||||
struct gem_jpeg_err *err = (struct gem_jpeg_err *)cinfo->err;
|
||||
longjmp(err->jmp, 1);
|
||||
}
|
||||
|
||||
static cairo_surface_t *load_jpeg_surface(const char *filename) {
|
||||
FILE *fp = fopen(filename, "rb");
|
||||
if (!fp) return NULL;
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
struct gem_jpeg_err jerr;
|
||||
cairo_surface_t *surf = NULL;
|
||||
JSAMPROW row[1];
|
||||
|
||||
cinfo.err = jpeg_std_error(&jerr.pub);
|
||||
jerr.pub.error_exit = gem_jpeg_exit;
|
||||
if (setjmp(jerr.jmp)) {
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
fclose(fp);
|
||||
if (surf) cairo_surface_destroy(surf);
|
||||
return NULL;
|
||||
}
|
||||
jpeg_create_decompress(&cinfo);
|
||||
jpeg_stdio_src(&cinfo, fp);
|
||||
if (jpeg_read_header(&cinfo, TRUE) != JPEG_HEADER_OK) {
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
cinfo.out_color_space = JCS_RGB;
|
||||
jpeg_start_decompress(&cinfo);
|
||||
int w = (int)cinfo.output_width;
|
||||
int h = (int)cinfo.output_height;
|
||||
surf = cairo_image_surface_create(CAIRO_FORMAT_RGB24, w, h);
|
||||
unsigned char *dst_data = cairo_image_surface_get_data(surf);
|
||||
int dst_stride = cairo_image_surface_get_stride(surf);
|
||||
unsigned char *scan = malloc((size_t)w * 3);
|
||||
if (!scan) {
|
||||
cairo_surface_destroy(surf);
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
cairo_surface_flush(surf);
|
||||
while ((int)cinfo.output_scanline < h) {
|
||||
int y = (int)cinfo.output_scanline;
|
||||
row[0] = scan;
|
||||
jpeg_read_scanlines(&cinfo, row, 1);
|
||||
pixbuf_data_to_cairo_data(scan, dst_data + y * dst_stride,
|
||||
(size_t)w * 3, (size_t)dst_stride, w, 1, 3);
|
||||
}
|
||||
cairo_surface_mark_dirty(surf);
|
||||
free(scan);
|
||||
jpeg_finish_decompress(&cinfo);
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
fclose(fp);
|
||||
return surf;
|
||||
}
|
||||
|
||||
cairo_surface_t *get_surface_from_file(const char *filename, int min_size,
|
||||
int max_size, double scale) {
|
||||
if (!filename || !filename[0]) return NULL;
|
||||
FILE *fp = fopen(filename, "rb");
|
||||
if (!fp) return NULL;
|
||||
unsigned char hdr[8] = {0};
|
||||
size_t n = fread(hdr, 1, sizeof(hdr), fp);
|
||||
fclose(fp);
|
||||
|
||||
cairo_surface_t *raw = NULL;
|
||||
if (n >= 4 && hdr[0] == 0x89 && hdr[1] == 0x50 && hdr[2] == 0x4e && hdr[3] == 0x47) {
|
||||
raw = cairo_image_surface_create_from_png(filename);
|
||||
if (cairo_surface_status(raw) != CAIRO_STATUS_SUCCESS) {
|
||||
cairo_surface_destroy(raw);
|
||||
raw = NULL;
|
||||
}
|
||||
} else if (n >= 2 && hdr[0] == 0xff && hdr[1] == 0xd8) {
|
||||
raw = load_jpeg_surface(filename);
|
||||
}
|
||||
return scale_cairo_surface(raw, scale, min_size, max_size);
|
||||
}
|
||||
|
||||
char *get_path_from_icon_name(const char *iconname, int size) {
|
||||
if (STR_EMPTY(iconname)) return NULL;
|
||||
|
||||
char *uri_path = NULL;
|
||||
if (g_str_has_prefix(iconname, "file://")) {
|
||||
uri_path = g_filename_from_uri(iconname, NULL, NULL);
|
||||
if (!uri_path)
|
||||
LOG_W("Failed to retrieve icon: '%s'", iconname);
|
||||
return uri_path;
|
||||
}
|
||||
if (g_str_has_prefix(iconname, "/") || g_str_has_prefix(iconname, "~") ||
|
||||
strchr(iconname, '.')) {
|
||||
char *maybe_icon_path = string_to_path(g_strdup(iconname));
|
||||
if (is_readable_file(maybe_icon_path)) {
|
||||
LOG_D("Using icon from path '%s'.", maybe_icon_path);
|
||||
return maybe_icon_path;
|
||||
}
|
||||
g_free(maybe_icon_path);
|
||||
}
|
||||
return find_icon_path(iconname, size);
|
||||
}
|
||||
|
||||
cairo_surface_t *icon_get_for_data(GVariant *data, char **id, double dpi_scale,
|
||||
int min_size, int max_size) {
|
||||
ASSERT_OR_RET(data, NULL);
|
||||
ASSERT_OR_RET(id, NULL);
|
||||
|
||||
if (!STR_EQ("(iiibiiay)", g_variant_get_type_string(data))) {
|
||||
LOG_W("Invalid data for raw icon given.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GVariant *data_variant = NULL;
|
||||
int width, height, rowstride, has_alpha, bits_per_sample, n_channels;
|
||||
g_variant_get(data, "(iiibii@ay)", &width, &height, &rowstride,
|
||||
&has_alpha, &bits_per_sample, &n_channels, &data_variant);
|
||||
|
||||
if (width <= 0 || height <= 0 || (n_channels != 3 && n_channels != 4)) {
|
||||
g_variant_unref(data_variant);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gsize pixelstride = (gsize)(n_channels * bits_per_sample + 7) / 8;
|
||||
gsize len_expected = (gsize)(height - 1) * (gsize)rowstride + (gsize)width * pixelstride;
|
||||
gsize len_actual = g_variant_get_size(data_variant);
|
||||
if (len_actual != len_expected) {
|
||||
g_variant_unref(data_variant);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const unsigned char *data_pb = g_variant_get_data(data_variant);
|
||||
size_t rowstride_short = pixelstride * (size_t)width;
|
||||
size_t data_chk_len = rowstride_short * (size_t)height;
|
||||
unsigned char *data_chk = g_malloc(data_chk_len);
|
||||
for (int i = 0; i < height; i++) {
|
||||
memcpy(data_chk + (i * rowstride_short), data_pb + (i * rowstride), rowstride_short);
|
||||
}
|
||||
*id = g_compute_checksum_for_data(G_CHECKSUM_MD5, data_chk, data_chk_len);
|
||||
g_free(data_chk);
|
||||
|
||||
cairo_format_t fmt = has_alpha ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24;
|
||||
cairo_surface_t *surf = cairo_image_surface_create(fmt, width, height);
|
||||
cairo_surface_flush(surf);
|
||||
pixbuf_data_to_cairo_data(data_pb, cairo_image_surface_get_data(surf),
|
||||
(size_t)rowstride, (size_t)cairo_image_surface_get_stride(surf),
|
||||
width, height, n_channels);
|
||||
cairo_surface_mark_dirty(surf);
|
||||
g_variant_unref(data_variant);
|
||||
return scale_cairo_surface(surf, dpi_scale, min_size, max_size);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef DUNST_ICON_H
|
||||
#define DUNST_ICON_H
|
||||
|
||||
#include <cairo.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "notification.h"
|
||||
|
||||
cairo_surface_t *get_surface_from_file(const char *filename, int min_size, int max_size, double scale);
|
||||
int get_icon_width(cairo_surface_t *icon, double scale);
|
||||
int get_icon_height(cairo_surface_t *icon, double scale);
|
||||
char *get_path_from_icon_name(const char *iconname, int size);
|
||||
cairo_surface_t *icon_get_for_data(GVariant *data, char **id, double dpi_scale, int min_size, int max_size);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* Geminux pure-C11 org.freedesktop.Notifications client (notify-send / dunstify).
|
||||
* Zero libnotify / gdk-pixbuf / Rust dependencies.
|
||||
*/
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static int parse_urgency(const char *s) {
|
||||
if (!s) return 1;
|
||||
if (strcmp(s, "low") == 0 || strcmp(s, "0") == 0) return 0;
|
||||
if (strcmp(s, "critical") == 0 || strcmp(s, "2") == 0) return 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void add_hint(GVariantBuilder *hints, const char *spec) {
|
||||
char *copy = g_strdup(spec);
|
||||
char *c1 = strchr(copy, ':');
|
||||
char *c2 = c1 ? strchr(c1 + 1, ':') : NULL;
|
||||
if (!c1 || !c2) {
|
||||
g_free(copy);
|
||||
return;
|
||||
}
|
||||
*c1 = '\0';
|
||||
*c2 = '\0';
|
||||
const char *type = copy;
|
||||
const char *name = c1 + 1;
|
||||
const char *val = c2 + 1;
|
||||
|
||||
if (strcmp(type, "int") == 0 || strcmp(type, "int32") == 0) {
|
||||
g_variant_builder_add(hints, "{sv}", name, g_variant_new_int32((gint32)strtol(val, NULL, 0)));
|
||||
} else if (strcmp(type, "uint") == 0 || strcmp(type, "uint32") == 0) {
|
||||
g_variant_builder_add(hints, "{sv}", name, g_variant_new_uint32((guint32)strtoul(val, NULL, 0)));
|
||||
} else if (strcmp(type, "byte") == 0) {
|
||||
g_variant_builder_add(hints, "{sv}", name, g_variant_new_byte((guchar)strtoul(val, NULL, 0)));
|
||||
} else if (strcmp(type, "boolean") == 0 || strcmp(type, "bool") == 0) {
|
||||
gboolean b = (strcmp(val, "true") == 0 || strcmp(val, "1") == 0);
|
||||
g_variant_builder_add(hints, "{sv}", name, g_variant_new_boolean(b));
|
||||
} else if (strcmp(type, "string") == 0) {
|
||||
g_variant_builder_add(hints, "{sv}", name, g_variant_new_string(val));
|
||||
}
|
||||
g_free(copy);
|
||||
}
|
||||
|
||||
static void usage(const char *prog) {
|
||||
fprintf(stderr,
|
||||
"Usage: %s [-u low|normal|critical] [-t ms] [-a app] [-i icon] "
|
||||
"[-c cat] [-r id] [-h type:name:val] [-A key,label] [-p] [-C id] "
|
||||
"SUMMARY [BODY]\n",
|
||||
prog);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
const char *app_name = "geminux";
|
||||
const char *icon = "";
|
||||
const char *category = NULL;
|
||||
const char *summary = NULL;
|
||||
const char *body = "";
|
||||
int urgency = 1;
|
||||
gint32 expire_ms = -1;
|
||||
guint32 replace_id = 0;
|
||||
guint32 close_id = 0;
|
||||
int print_id = 0;
|
||||
|
||||
GPtrArray *hints_raw = g_ptr_array_new_with_free_func(g_free);
|
||||
GPtrArray *actions_raw = g_ptr_array_new_with_free_func(g_free);
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
const char *arg = argv[i];
|
||||
if (strcmp(arg, "--") == 0) {
|
||||
if (i + 1 < argc) summary = argv[++i];
|
||||
if (i + 1 < argc) body = argv[++i];
|
||||
break;
|
||||
} else if (strcmp(arg, "--help") == 0 || strcmp(arg, "-?") == 0) {
|
||||
usage(argv[0]);
|
||||
return 0;
|
||||
} else if ((strcmp(arg, "-u") == 0 || strcmp(arg, "--urgency") == 0) && i + 1 < argc) {
|
||||
urgency = parse_urgency(argv[++i]);
|
||||
} else if (strncmp(arg, "--urgency=", 10) == 0) {
|
||||
urgency = parse_urgency(arg + 10);
|
||||
} else if ((strcmp(arg, "-t") == 0 || strcmp(arg, "--expire-time") == 0) && i + 1 < argc) {
|
||||
expire_ms = (gint32)strtol(argv[++i], NULL, 10);
|
||||
} else if (strncmp(arg, "--expire-time=", 14) == 0) {
|
||||
expire_ms = (gint32)strtol(arg + 14, NULL, 10);
|
||||
} else if ((strcmp(arg, "-a") == 0 || strcmp(arg, "--app-name") == 0) && i + 1 < argc) {
|
||||
app_name = argv[++i];
|
||||
} else if (strncmp(arg, "--app-name=", 11) == 0) {
|
||||
app_name = arg + 11;
|
||||
} else if ((strcmp(arg, "-i") == 0 || strcmp(arg, "--icon") == 0) && i + 1 < argc) {
|
||||
icon = argv[++i];
|
||||
} else if (strncmp(arg, "--icon=", 7) == 0) {
|
||||
icon = arg + 7;
|
||||
} else if ((strcmp(arg, "-c") == 0 || strcmp(arg, "--category") == 0) && i + 1 < argc) {
|
||||
category = argv[++i];
|
||||
} else if ((strcmp(arg, "-r") == 0 || strcmp(arg, "--replace-id") == 0) && i + 1 < argc) {
|
||||
replace_id = (guint32)strtoul(argv[++i], NULL, 10);
|
||||
} else if (strcmp(arg, "-p") == 0 || strcmp(arg, "--printid") == 0) {
|
||||
print_id = 1;
|
||||
} else if ((strcmp(arg, "-C") == 0 || strcmp(arg, "--close") == 0) && i + 1 < argc) {
|
||||
close_id = (guint32)strtoul(argv[++i], NULL, 10);
|
||||
} else if ((strcmp(arg, "-h") == 0 || strcmp(arg, "--hint") == 0) && i + 1 < argc) {
|
||||
g_ptr_array_add(hints_raw, g_strdup(argv[++i]));
|
||||
} else if ((strcmp(arg, "-A") == 0 || strcmp(arg, "--action") == 0) && i + 1 < argc) {
|
||||
g_ptr_array_add(actions_raw, g_strdup(argv[++i]));
|
||||
} else if (arg[0] == '-' && arg[1] != '\0') {
|
||||
continue;
|
||||
} else if (!summary) {
|
||||
summary = arg;
|
||||
} else if (!body[0]) {
|
||||
body = arg;
|
||||
}
|
||||
}
|
||||
|
||||
GError *err = NULL;
|
||||
GDBusConnection *conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &err);
|
||||
if (!conn) {
|
||||
fprintf(stderr, "notify-send: failed to connect to session dbus: %s\n",
|
||||
err ? err->message : "unknown error");
|
||||
g_clear_error(&err);
|
||||
g_ptr_array_free(hints_raw, TRUE);
|
||||
g_ptr_array_free(actions_raw, TRUE);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (close_id > 0) {
|
||||
GVariant *res = g_dbus_connection_call_sync(
|
||||
conn, "org.freedesktop.Notifications", "/org/freedesktop/Notifications",
|
||||
"org.freedesktop.Notifications", "CloseNotification",
|
||||
g_variant_new("(u)", close_id), NULL, G_DBUS_CALL_FLAGS_NONE, 2000, NULL, &err);
|
||||
if (res) g_variant_unref(res);
|
||||
g_clear_error(&err);
|
||||
g_object_unref(conn);
|
||||
g_ptr_array_free(hints_raw, TRUE);
|
||||
g_ptr_array_free(actions_raw, TRUE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!summary) {
|
||||
usage(argv[0]);
|
||||
g_object_unref(conn);
|
||||
g_ptr_array_free(hints_raw, TRUE);
|
||||
g_ptr_array_free(actions_raw, TRUE);
|
||||
return 2;
|
||||
}
|
||||
|
||||
GVariantBuilder actions_b;
|
||||
g_variant_builder_init(&actions_b, G_VARIANT_TYPE("as"));
|
||||
for (guint j = 0; j < actions_raw->len; j++) {
|
||||
char *item = g_strdup(g_ptr_array_index(actions_raw, j));
|
||||
char *comma = strchr(item, ',');
|
||||
if (comma) {
|
||||
*comma = '\0';
|
||||
g_variant_builder_add(&actions_b, "s", item);
|
||||
g_variant_builder_add(&actions_b, "s", comma + 1);
|
||||
}
|
||||
g_free(item);
|
||||
}
|
||||
|
||||
GVariantBuilder hints_b;
|
||||
g_variant_builder_init(&hints_b, G_VARIANT_TYPE("a{sv}"));
|
||||
g_variant_builder_add(&hints_b, "{sv}", "urgency", g_variant_new_byte((guchar)urgency));
|
||||
if (category && category[0]) {
|
||||
g_variant_builder_add(&hints_b, "{sv}", "category", g_variant_new_string(category));
|
||||
}
|
||||
for (guint j = 0; j < hints_raw->len; j++) {
|
||||
add_hint(&hints_b, g_ptr_array_index(hints_raw, j));
|
||||
}
|
||||
|
||||
GVariant *params = g_variant_new(
|
||||
"(susss@as@a{sv}i)", app_name, replace_id, icon, summary, body,
|
||||
g_variant_builder_end(&actions_b), g_variant_builder_end(&hints_b), expire_ms);
|
||||
|
||||
GVariant *reply = g_dbus_connection_call_sync(
|
||||
conn, "org.freedesktop.Notifications", "/org/freedesktop/Notifications",
|
||||
"org.freedesktop.Notifications", "Notify", params, G_VARIANT_TYPE("(u)"),
|
||||
G_DBUS_CALL_FLAGS_NONE, 3000, NULL, &err);
|
||||
|
||||
int rc = 0;
|
||||
if (!reply) {
|
||||
fprintf(stderr, "notify-send: dbus Notify failed: %s\n",
|
||||
err ? err->message : "unknown error");
|
||||
g_clear_error(&err);
|
||||
rc = 1;
|
||||
} else {
|
||||
guint32 nid = 0;
|
||||
g_variant_get(reply, "(u)", &nid);
|
||||
if (print_id) {
|
||||
printf("%u\n", nid);
|
||||
}
|
||||
g_variant_unref(reply);
|
||||
}
|
||||
|
||||
g_object_unref(conn);
|
||||
g_ptr_array_free(hints_raw, TRUE);
|
||||
g_ptr_array_free(actions_raw, TRUE);
|
||||
return rc;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
# Geminux dwm Makefile
|
||||
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 drw.h util.h
|
||||
|
||||
config.h:
|
||||
cp config.def.h $@
|
||||
|
||||
dwm: $(OBJ)
|
||||
$(CC) -o $@ $(OBJ) $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
rm -f dwm $(OBJ) config.h
|
||||
|
||||
install: all
|
||||
mkdir -p $(DESTDIR)$(PREFIX)/bin
|
||||
cp -f dwm $(DESTDIR)$(PREFIX)/bin/dwm
|
||||
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
|
||||
|
||||
.PHONY: all options clean install
|
||||
@@ -0,0 +1,165 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
/* Geminux DWM configuration (Gemini PDA 2160x1080 HiDPI, Mod4 = Fn+Alt, systray, Pango) */
|
||||
#include <X11/XF86keysym.h>
|
||||
|
||||
/* appearance */
|
||||
static unsigned int borderpx = 3;
|
||||
static unsigned int snap = 24;
|
||||
static const int showbar = 1;
|
||||
static const int topbar = 1;
|
||||
static const unsigned int systraypinning = 0;
|
||||
static const unsigned int systrayonleft = 0;
|
||||
static const unsigned int systrayspacing = 6;
|
||||
static const int systraypinningfailfirst = 1;
|
||||
static const int showsystray = 1;
|
||||
static const char *font = "Fira Code, DejaVuSansM Nerd Font 20px";
|
||||
static char normbgcolor[64] = "#0b0e14";
|
||||
static char normbordercolor[64] = "#283444";
|
||||
static char normfgcolor[64] = "#e6e1cf";
|
||||
static char selbgcolor[64] = "#2b5278";
|
||||
static char selbordercolor[64] = "#59c2ff";
|
||||
static char selfgcolor[64] = "#ffffff";
|
||||
static char *colors[][3] = {
|
||||
/* fg bg border */
|
||||
[SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor },
|
||||
[SchemeSel] = { selfgcolor, selbgcolor, selbordercolor },
|
||||
};
|
||||
|
||||
/* tagging */
|
||||
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
||||
|
||||
static const Rule rules[] = {
|
||||
/* class instance title tags mask isfloating monitor */
|
||||
{ "geminux-callscreen", NULL, NULL, ~0U, 0, -1 },
|
||||
{ "geminux-lock", NULL, NULL, ~0U, 1, -1 },
|
||||
{ "geminux-control", NULL, NULL, 0, 1, -1 },
|
||||
{ "geminux-themes", NULL, NULL, 0, 1, -1 },
|
||||
};
|
||||
|
||||
/* layout(s) */
|
||||
static const float mfact = 0.55;
|
||||
static const int nmaster = 1;
|
||||
static const int resizehints = 0;
|
||||
static const int lockfullscreen = 1;
|
||||
|
||||
static const Layout layouts[] = {
|
||||
/* symbol arrange function */
|
||||
{ "[]=", tile },
|
||||
{ "[M]", monocle },
|
||||
{ "><>", NULL },
|
||||
{ "###", grid },
|
||||
};
|
||||
|
||||
/* key definitions: Mod4 = Fn+Alt (Super_L) on Gemini PDA keyboard */
|
||||
#define MODKEY Mod4Mask
|
||||
#define TAGKEYS(KEY,TAG) \
|
||||
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \
|
||||
{ MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
|
||||
{ MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \
|
||||
{ MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} },
|
||||
|
||||
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
|
||||
|
||||
/* commands */
|
||||
static const char *termcmd[] = { "st", NULL };
|
||||
static const char *launchercmd[] = { "geminux-launcher", NULL };
|
||||
static const char *controlcmd[] = { "geminux-control", NULL };
|
||||
static const char *dialercmd[] = { "geminux-dialer", NULL };
|
||||
static const char *smscmd[] = { "geminux-sms", NULL };
|
||||
static const char *netcmd[] = { "geminux-net", NULL };
|
||||
static const char *cameracmd[] = { "geminux-camera", NULL };
|
||||
static const char *themescmd[] = { "geminux-themes", NULL };
|
||||
static const char *lockcmd[] = { "geminux-lock", NULL };
|
||||
static const char *shotcmd[] = {
|
||||
"/bin/sh", "-c",
|
||||
"mkdir -p ~/Pictures && scrot ~/Pictures/screenshot-$(date +%Y%m%d-%H%M%S).png",
|
||||
NULL
|
||||
};
|
||||
static const char *briupcmd[] = { "brightnessctl", "set", "+10%", NULL };
|
||||
static const char *bridowncmd[] = { "brightnessctl", "set", "10%-", NULL };
|
||||
static const char *volupcmd[] = {
|
||||
"/bin/sh", "-c", "wpctl set-volume -l 1.0 @DEFAULT_AUDIO_SINK@ 5%+ && pkill -USR1 geminux-statusd || true", NULL
|
||||
};
|
||||
static const char *voldowncmd[] = {
|
||||
"/bin/sh", "-c", "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- && pkill -USR1 geminux-statusd || true", NULL
|
||||
};
|
||||
static const char *volmutecmd[] = {
|
||||
"/bin/sh", "-c", "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle && pkill -USR1 geminux-statusd || true", NULL
|
||||
};
|
||||
|
||||
static const Key keys[] = {
|
||||
/* modifier key function argument */
|
||||
{ MODKEY, XK_Return, spawn, {.v = termcmd} },
|
||||
{ MODKEY, XK_p, spawn, {.v = launchercmd} },
|
||||
{ 0, XK_Menu, spawn, {.v = launchercmd} },
|
||||
{ 0, XF86XK_MenuKB, spawn, {.v = launchercmd} },
|
||||
{ 0, XF86XK_Launch1, spawn, {.v = launchercmd} },
|
||||
{ MODKEY, XK_c, spawn, {.v = controlcmd} },
|
||||
{ MODKEY, XK_d, spawn, {.v = dialercmd} },
|
||||
{ MODKEY, XK_s, spawn, {.v = smscmd} },
|
||||
{ MODKEY, XK_n, spawn, {.v = netcmd} },
|
||||
{ MODKEY, XK_v, spawn, {.v = cameracmd} },
|
||||
{ MODKEY, XK_t, spawn, {.v = themescmd} },
|
||||
{ MODKEY|ShiftMask, XK_l, spawn, {.v = lockcmd} },
|
||||
{ 0, XF86XK_ScreenSaver, spawn, {.v = lockcmd} },
|
||||
{ 0, XK_Print, spawn, {.v = shotcmd} },
|
||||
{ 0, XF86XK_MonBrightnessUp, spawn, {.v = briupcmd} },
|
||||
{ 0, XF86XK_MonBrightnessDown, spawn, {.v = bridowncmd} },
|
||||
{ 0, XF86XK_AudioRaiseVolume, spawn, {.v = volupcmd} },
|
||||
{ 0, XF86XK_AudioLowerVolume, spawn, {.v = voldowncmd} },
|
||||
{ 0, XF86XK_AudioMute, spawn, {.v = volmutecmd} },
|
||||
{ MODKEY, XK_b, togglebar, {0} },
|
||||
{ MODKEY, XK_j, focusstack, {.i = +1} },
|
||||
{ MODKEY, XK_k, focusstack, {.i = -1} },
|
||||
{ MODKEY, XK_Down, focusstack, {.i = +1} },
|
||||
{ MODKEY, XK_Up, focusstack, {.i = -1} },
|
||||
{ MODKEY, XK_i, incnmaster, {.i = +1} },
|
||||
{ MODKEY, XK_o, incnmaster, {.i = -1} },
|
||||
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
|
||||
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
|
||||
{ MODKEY, XK_space, zoom, {0} },
|
||||
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
|
||||
{ MODKEY, XK_Tab, view, {0} },
|
||||
{ MODKEY|ShiftMask, XK_q, killclient, {0} },
|
||||
{ MODKEY|ShiftMask, XK_c, killclient, {0} },
|
||||
{ MODKEY, XK_F1, setlayout, {.v = &layouts[0]} },
|
||||
{ MODKEY, XK_F2, setlayout, {.v = &layouts[1]} },
|
||||
{ MODKEY, XK_F3, setlayout, {.v = &layouts[2]} },
|
||||
{ MODKEY, XK_F4, setlayout, {.v = &layouts[3]} },
|
||||
{ MODKEY, XK_m, setlayout, {.v = &layouts[1]} },
|
||||
{ MODKEY, XK_g, setlayout, {.v = &layouts[3]} },
|
||||
{ MODKEY, XK_0, view, {.ui = ~0U} },
|
||||
{ MODKEY|ShiftMask, XK_0, tag, {.ui = ~0U} },
|
||||
{ MODKEY, XK_comma, focusmon, {.i = -1} },
|
||||
{ MODKEY, XK_period, focusmon, {.i = +1} },
|
||||
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1} },
|
||||
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1} },
|
||||
{ MODKEY|ShiftMask, XK_r, reloadxres, {0} },
|
||||
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|ControlMask|ShiftMask, XK_q, quit, {0} },
|
||||
};
|
||||
|
||||
/* button definitions */
|
||||
static const Button buttons[] = {
|
||||
/* click event mask button function argument */
|
||||
{ ClkLauncher, 0, Button1, spawn, {.v = launchercmd} },
|
||||
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
|
||||
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[1]} },
|
||||
{ ClkWinTitle, 0, Button2, zoom, {0} },
|
||||
{ ClkCloseBtn, 0, Button1, killclient, {0} },
|
||||
{ ClkStatusText, 0, Button1, spawn, {.v = controlcmd} },
|
||||
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
|
||||
{ ClkClientWin, MODKEY, Button3, resizemouse, {0} },
|
||||
{ ClkTagBar, 0, Button1, view, {0} },
|
||||
{ ClkTagBar, 0, Button3, toggleview, {0} },
|
||||
{ ClkTagBar, MODKEY, Button1, tag, {0} },
|
||||
{ ClkTagBar, MODKEY, Button3, toggletag, {0} },
|
||||
};
|
||||
@@ -0,0 +1,165 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
/* Geminux DWM configuration (Gemini PDA 2160x1080 HiDPI, Mod4 = Fn+Alt, systray, Pango) */
|
||||
#include <X11/XF86keysym.h>
|
||||
|
||||
/* appearance */
|
||||
static unsigned int borderpx = 3;
|
||||
static unsigned int snap = 24;
|
||||
static const int showbar = 1;
|
||||
static const int topbar = 1;
|
||||
static const unsigned int systraypinning = 0;
|
||||
static const unsigned int systrayonleft = 0;
|
||||
static const unsigned int systrayspacing = 6;
|
||||
static const int systraypinningfailfirst = 1;
|
||||
static const int showsystray = 1;
|
||||
static const char *font = "Fira Code, DejaVuSansM Nerd Font 20px";
|
||||
static char normbgcolor[64] = "#0b0e14";
|
||||
static char normbordercolor[64] = "#283444";
|
||||
static char normfgcolor[64] = "#e6e1cf";
|
||||
static char selbgcolor[64] = "#2b5278";
|
||||
static char selbordercolor[64] = "#59c2ff";
|
||||
static char selfgcolor[64] = "#ffffff";
|
||||
static char *colors[][3] = {
|
||||
/* fg bg border */
|
||||
[SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor },
|
||||
[SchemeSel] = { selfgcolor, selbgcolor, selbordercolor },
|
||||
};
|
||||
|
||||
/* tagging */
|
||||
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
||||
|
||||
static const Rule rules[] = {
|
||||
/* class instance title tags mask isfloating monitor */
|
||||
{ "geminux-callscreen", NULL, NULL, ~0U, 0, -1 },
|
||||
{ "geminux-lock", NULL, NULL, ~0U, 1, -1 },
|
||||
{ "geminux-control", NULL, NULL, 0, 1, -1 },
|
||||
{ "geminux-themes", NULL, NULL, 0, 1, -1 },
|
||||
};
|
||||
|
||||
/* layout(s) */
|
||||
static const float mfact = 0.55;
|
||||
static const int nmaster = 1;
|
||||
static const int resizehints = 0;
|
||||
static const int lockfullscreen = 1;
|
||||
|
||||
static const Layout layouts[] = {
|
||||
/* symbol arrange function */
|
||||
{ "[]=", tile },
|
||||
{ "[M]", monocle },
|
||||
{ "><>", NULL },
|
||||
{ "###", grid },
|
||||
};
|
||||
|
||||
/* key definitions: Mod4 = Fn+Alt (Super_L) on Gemini PDA keyboard */
|
||||
#define MODKEY Mod4Mask
|
||||
#define TAGKEYS(KEY,TAG) \
|
||||
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \
|
||||
{ MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
|
||||
{ MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \
|
||||
{ MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} },
|
||||
|
||||
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
|
||||
|
||||
/* commands */
|
||||
static const char *termcmd[] = { "st", NULL };
|
||||
static const char *launchercmd[] = { "geminux-launcher", NULL };
|
||||
static const char *controlcmd[] = { "geminux-control", NULL };
|
||||
static const char *dialercmd[] = { "geminux-dialer", NULL };
|
||||
static const char *smscmd[] = { "geminux-sms", NULL };
|
||||
static const char *netcmd[] = { "geminux-net", NULL };
|
||||
static const char *cameracmd[] = { "geminux-camera", NULL };
|
||||
static const char *themescmd[] = { "geminux-themes", NULL };
|
||||
static const char *lockcmd[] = { "geminux-lock", NULL };
|
||||
static const char *shotcmd[] = {
|
||||
"/bin/sh", "-c",
|
||||
"mkdir -p ~/Pictures && scrot ~/Pictures/screenshot-$(date +%Y%m%d-%H%M%S).png",
|
||||
NULL
|
||||
};
|
||||
static const char *briupcmd[] = { "brightnessctl", "set", "+10%", NULL };
|
||||
static const char *bridowncmd[] = { "brightnessctl", "set", "10%-", NULL };
|
||||
static const char *volupcmd[] = {
|
||||
"/bin/sh", "-c", "wpctl set-volume -l 1.0 @DEFAULT_AUDIO_SINK@ 5%+ && pkill -USR1 geminux-statusd || true", NULL
|
||||
};
|
||||
static const char *voldowncmd[] = {
|
||||
"/bin/sh", "-c", "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- && pkill -USR1 geminux-statusd || true", NULL
|
||||
};
|
||||
static const char *volmutecmd[] = {
|
||||
"/bin/sh", "-c", "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle && pkill -USR1 geminux-statusd || true", NULL
|
||||
};
|
||||
|
||||
static const Key keys[] = {
|
||||
/* modifier key function argument */
|
||||
{ MODKEY, XK_Return, spawn, {.v = termcmd} },
|
||||
{ MODKEY, XK_p, spawn, {.v = launchercmd} },
|
||||
{ 0, XK_Menu, spawn, {.v = launchercmd} },
|
||||
{ 0, XF86XK_MenuKB, spawn, {.v = launchercmd} },
|
||||
{ 0, XF86XK_Launch1, spawn, {.v = launchercmd} },
|
||||
{ MODKEY, XK_c, spawn, {.v = controlcmd} },
|
||||
{ MODKEY, XK_d, spawn, {.v = dialercmd} },
|
||||
{ MODKEY, XK_s, spawn, {.v = smscmd} },
|
||||
{ MODKEY, XK_n, spawn, {.v = netcmd} },
|
||||
{ MODKEY, XK_v, spawn, {.v = cameracmd} },
|
||||
{ MODKEY, XK_t, spawn, {.v = themescmd} },
|
||||
{ MODKEY|ShiftMask, XK_l, spawn, {.v = lockcmd} },
|
||||
{ 0, XF86XK_ScreenSaver, spawn, {.v = lockcmd} },
|
||||
{ 0, XK_Print, spawn, {.v = shotcmd} },
|
||||
{ 0, XF86XK_MonBrightnessUp, spawn, {.v = briupcmd} },
|
||||
{ 0, XF86XK_MonBrightnessDown, spawn, {.v = bridowncmd} },
|
||||
{ 0, XF86XK_AudioRaiseVolume, spawn, {.v = volupcmd} },
|
||||
{ 0, XF86XK_AudioLowerVolume, spawn, {.v = voldowncmd} },
|
||||
{ 0, XF86XK_AudioMute, spawn, {.v = volmutecmd} },
|
||||
{ MODKEY, XK_b, togglebar, {0} },
|
||||
{ MODKEY, XK_j, focusstack, {.i = +1} },
|
||||
{ MODKEY, XK_k, focusstack, {.i = -1} },
|
||||
{ MODKEY, XK_Down, focusstack, {.i = +1} },
|
||||
{ MODKEY, XK_Up, focusstack, {.i = -1} },
|
||||
{ MODKEY, XK_i, incnmaster, {.i = +1} },
|
||||
{ MODKEY, XK_o, incnmaster, {.i = -1} },
|
||||
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
|
||||
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
|
||||
{ MODKEY, XK_space, zoom, {0} },
|
||||
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
|
||||
{ MODKEY, XK_Tab, view, {0} },
|
||||
{ MODKEY|ShiftMask, XK_q, killclient, {0} },
|
||||
{ MODKEY|ShiftMask, XK_c, killclient, {0} },
|
||||
{ MODKEY, XK_F1, setlayout, {.v = &layouts[0]} },
|
||||
{ MODKEY, XK_F2, setlayout, {.v = &layouts[1]} },
|
||||
{ MODKEY, XK_F3, setlayout, {.v = &layouts[2]} },
|
||||
{ MODKEY, XK_F4, setlayout, {.v = &layouts[3]} },
|
||||
{ MODKEY, XK_m, setlayout, {.v = &layouts[1]} },
|
||||
{ MODKEY, XK_g, setlayout, {.v = &layouts[3]} },
|
||||
{ MODKEY, XK_0, view, {.ui = ~0U} },
|
||||
{ MODKEY|ShiftMask, XK_0, tag, {.ui = ~0U} },
|
||||
{ MODKEY, XK_comma, focusmon, {.i = -1} },
|
||||
{ MODKEY, XK_period, focusmon, {.i = +1} },
|
||||
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1} },
|
||||
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1} },
|
||||
{ MODKEY|ShiftMask, XK_r, reloadxres, {0} },
|
||||
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|ControlMask|ShiftMask, XK_q, quit, {0} },
|
||||
};
|
||||
|
||||
/* button definitions */
|
||||
static const Button buttons[] = {
|
||||
/* click event mask button function argument */
|
||||
{ ClkLauncher, 0, Button1, spawn, {.v = launchercmd} },
|
||||
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
|
||||
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[1]} },
|
||||
{ ClkWinTitle, 0, Button2, zoom, {0} },
|
||||
{ ClkCloseBtn, 0, Button1, killclient, {0} },
|
||||
{ ClkStatusText, 0, Button1, spawn, {.v = controlcmd} },
|
||||
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
|
||||
{ ClkClientWin, MODKEY, Button3, resizemouse, {0} },
|
||||
{ ClkTagBar, 0, Button1, view, {0} },
|
||||
{ ClkTagBar, 0, Button3, toggleview, {0} },
|
||||
{ ClkTagBar, MODKEY, Button1, tag, {0} },
|
||||
{ ClkTagBar, MODKEY, Button3, toggletag, {0} },
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
# Geminux dwm build configuration (Pango + HarfBuzz + systray + .Xresources + Xinerama)
|
||||
VERSION = 6.5-geminux
|
||||
|
||||
PREFIX = /usr
|
||||
MANPREFIX = $(PREFIX)/share/man
|
||||
|
||||
PKG_CONFIG ?= pkg-config
|
||||
|
||||
INCS = $(shell $(PKG_CONFIG) --cflags fontconfig freetype2 xft pango pangoxft harfbuzz x11 xinerama)
|
||||
LIBS = $(shell $(PKG_CONFIG) --libs fontconfig freetype2 xft pango pangoxft harfbuzz x11 xinerama)
|
||||
|
||||
CPPFLAGS = -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" -DXINERAMA
|
||||
CFLAGS = -std=gnu99 -pedantic -Wall -Wno-deprecated-declarations -O2 $(INCS) $(CPPFLAGS)
|
||||
LDFLAGS = $(LIBS)
|
||||
|
||||
CC ?= cc
|
||||
+212
@@ -0,0 +1,212 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
/* Pango + HarfBuzz + Xft drawing backend for Geminux DWM */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xft/Xft.h>
|
||||
#include <pango/pango.h>
|
||||
#include <pango/pangoxft.h>
|
||||
|
||||
#include "drw.h"
|
||||
#include "util.h"
|
||||
|
||||
Drw *drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) {
|
||||
Drw *drw = ecalloc(1, sizeof(Drw));
|
||||
drw->dpy = dpy;
|
||||
drw->screen = screen;
|
||||
drw->root = root;
|
||||
drw->w = w;
|
||||
drw->h = h;
|
||||
drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen));
|
||||
drw->gc = XCreateGC(dpy, root, 0, NULL);
|
||||
XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
|
||||
return drw;
|
||||
}
|
||||
|
||||
void drw_resize(Drw *drw, unsigned int w, unsigned int h) {
|
||||
if (!drw) return;
|
||||
drw->w = w;
|
||||
drw->h = h;
|
||||
if (drw->drawable)
|
||||
XFreePixmap(drw->dpy, drw->drawable);
|
||||
drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen));
|
||||
}
|
||||
|
||||
void drw_free(Drw *drw) {
|
||||
if (!drw) return;
|
||||
if (drw->drawable)
|
||||
XFreePixmap(drw->dpy, drw->drawable);
|
||||
if (drw->gc)
|
||||
XFreeGC(drw->dpy, drw->gc);
|
||||
drw_font_free(drw->font);
|
||||
free(drw);
|
||||
}
|
||||
|
||||
Fnt *drw_font_create(Drw *drw, const char font[]) {
|
||||
Fnt *fnt = ecalloc(1, sizeof(Fnt));
|
||||
PangoFontMetrics *metrics;
|
||||
|
||||
fnt->dpy = drw->dpy;
|
||||
fnt->fontmap = pango_xft_get_font_map(drw->dpy, drw->screen);
|
||||
fnt->context = pango_font_map_create_context(fnt->fontmap);
|
||||
fnt->desc = pango_font_description_from_string(font && font[0] ? font : "Fira Code 18px");
|
||||
pango_context_set_font_description(fnt->context, fnt->desc);
|
||||
|
||||
metrics = pango_context_get_metrics(fnt->context, fnt->desc, pango_language_get_default());
|
||||
fnt->h = (unsigned int)((pango_font_metrics_get_ascent(metrics) +
|
||||
pango_font_metrics_get_descent(metrics)) / PANGO_SCALE);
|
||||
if (fnt->h < 12) fnt->h = 18;
|
||||
pango_font_metrics_unref(metrics);
|
||||
|
||||
fnt->layout = pango_layout_new(fnt->context);
|
||||
pango_layout_set_font_description(fnt->layout, fnt->desc);
|
||||
return fnt;
|
||||
}
|
||||
|
||||
void drw_font_free(Fnt *font) {
|
||||
if (!font) return;
|
||||
if (font->layout) g_object_unref(font->layout);
|
||||
if (font->context) g_object_unref(font->context);
|
||||
if (font->desc) pango_font_description_free(font->desc);
|
||||
free(font);
|
||||
}
|
||||
|
||||
void drw_clr_create(Drw *drw, Clr *dest, const char *clrname) {
|
||||
if (!drw || !dest || !clrname) return;
|
||||
if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
|
||||
DefaultColormap(drw->dpy, drw->screen), clrname, dest)) {
|
||||
fprintf(stderr, "dwm: warning: cannot allocate color '%s', using #ffffff\n", clrname);
|
||||
XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
|
||||
DefaultColormap(drw->dpy, drw->screen), "#ffffff", dest);
|
||||
}
|
||||
}
|
||||
|
||||
Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) {
|
||||
Clr *ret;
|
||||
if (!drw || !clrnames || clrcount == 0) return NULL;
|
||||
ret = ecalloc(clrcount, sizeof(XftColor));
|
||||
for (size_t i = 0; i < clrcount; i++)
|
||||
drw_clr_create(drw, &ret[i], clrnames[i]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void drw_setfont(Drw *drw, Fnt *font) {
|
||||
if (drw) drw->font = font;
|
||||
}
|
||||
|
||||
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, Bool markup) {
|
||||
char buf[1024];
|
||||
int ty, render = x || y || w || h;
|
||||
unsigned int ew, eh;
|
||||
XftDraw *d = NULL;
|
||||
|
||||
if (!drw || (render && !drw->scheme) || !text || !drw->font)
|
||||
return 0;
|
||||
|
||||
if (!render) {
|
||||
w = ~0;
|
||||
} else {
|
||||
XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel);
|
||||
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
|
||||
d = XftDrawCreate(drw->dpy, drw->drawable,
|
||||
DefaultVisual(drw->dpy, drw->screen),
|
||||
DefaultColormap(drw->dpy, drw->screen));
|
||||
x += (int)lpad;
|
||||
if (w > lpad) w -= lpad;
|
||||
}
|
||||
|
||||
size_t len = strlen(text);
|
||||
if (len >= sizeof(buf)) len = sizeof(buf) - 1;
|
||||
memcpy(buf, text, len);
|
||||
buf[len] = '\0';
|
||||
|
||||
if (len > 0 && w > 0) {
|
||||
drw_font_getexts(drw->font, buf, (unsigned int)len, &ew, &eh, markup);
|
||||
while (len > 3 && ew > w) {
|
||||
len--;
|
||||
while (len > 0 && (buf[len] & 0xc0) == 0x80) len--;
|
||||
if (len >= 3) memcpy(buf + len - 3, "...", 3);
|
||||
buf[len] = '\0';
|
||||
drw_font_getexts(drw->font, buf, (unsigned int)len, &ew, &eh, markup);
|
||||
}
|
||||
|
||||
if (render && d) {
|
||||
if (markup)
|
||||
pango_layout_set_markup(drw->font->layout, buf, -1);
|
||||
else
|
||||
pango_layout_set_text(drw->font->layout, buf, -1);
|
||||
ty = y + (int)(h - eh) / 2;
|
||||
if (ty < y) ty = y;
|
||||
pango_xft_render_layout(d, &drw->scheme[invert ? ColBg : ColFg],
|
||||
drw->font->layout, x * PANGO_SCALE, ty * PANGO_SCALE);
|
||||
if (markup)
|
||||
pango_layout_set_attributes(drw->font->layout, NULL);
|
||||
}
|
||||
x += (int)ew;
|
||||
}
|
||||
|
||||
if (d) XftDrawDestroy(d);
|
||||
return x + (render ? (int)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_font_getwidth(Drw *drw, const char *text, Bool markup) {
|
||||
unsigned int w = 0, h = 0;
|
||||
if (!drw || !drw->font || !text || !text[0]) return 0;
|
||||
drw_font_getexts(drw->font, text, (unsigned int)strlen(text), &w, &h, markup);
|
||||
return w;
|
||||
}
|
||||
|
||||
void drw_font_getexts(Fnt *font, const char *text, unsigned int len,
|
||||
unsigned int *w, unsigned int *h, Bool markup) {
|
||||
PangoRectangle r;
|
||||
if (!font || !text) {
|
||||
if (w) *w = 0;
|
||||
if (h) *h = 0;
|
||||
return;
|
||||
}
|
||||
if (markup)
|
||||
pango_layout_set_markup(font->layout, text, (int)len);
|
||||
else
|
||||
pango_layout_set_text(font->layout, text, (int)len);
|
||||
pango_layout_get_extents(font->layout, NULL, &r);
|
||||
if (markup)
|
||||
pango_layout_set_attributes(font->layout, NULL);
|
||||
if (w) *w = (unsigned int)((r.width + PANGO_SCALE - 1) / PANGO_SCALE);
|
||||
if (h) *h = (unsigned int)((r.height + PANGO_SCALE - 1) / PANGO_SCALE);
|
||||
if (h && *h == 0) *h = font->h;
|
||||
}
|
||||
|
||||
Cur *drw_cur_create(Drw *drw, int shape) {
|
||||
Cur *cur;
|
||||
if (!drw) return NULL;
|
||||
cur = ecalloc(1, sizeof(Cur));
|
||||
cur->cursor = XCreateFontCursor(drw->dpy, shape);
|
||||
return cur;
|
||||
}
|
||||
|
||||
void drw_cur_free(Drw *drw, Cur *cursor) {
|
||||
if (!cursor) return;
|
||||
if (drw) XFreeCursor(drw->dpy, cursor->cursor);
|
||||
free(cursor);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#ifndef DWM_DRW_H
|
||||
#define DWM_DRW_H
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xft/Xft.h>
|
||||
#include <pango/pango.h>
|
||||
#include <pango/pangoxft.h>
|
||||
|
||||
typedef struct {
|
||||
Cursor cursor;
|
||||
} Cur;
|
||||
|
||||
typedef struct Fnt {
|
||||
Display *dpy;
|
||||
unsigned int h;
|
||||
PangoLayout *layout;
|
||||
PangoFontMap *fontmap;
|
||||
PangoContext *context;
|
||||
PangoFontDescription *desc;
|
||||
} Fnt;
|
||||
|
||||
enum { ColFg, ColBg, ColBorder }; /* Clr scheme index */
|
||||
typedef XftColor Clr;
|
||||
|
||||
typedef struct {
|
||||
unsigned int w, h;
|
||||
Display *dpy;
|
||||
int screen;
|
||||
Window root;
|
||||
Drawable drawable;
|
||||
GC gc;
|
||||
Clr *scheme;
|
||||
Fnt *font;
|
||||
} Drw;
|
||||
|
||||
Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h);
|
||||
void drw_resize(Drw *drw, unsigned int w, unsigned int h);
|
||||
void drw_free(Drw *drw);
|
||||
|
||||
Fnt *drw_font_create(Drw *drw, const char font[]);
|
||||
void drw_font_free(Fnt *font);
|
||||
unsigned int drw_font_getwidth(Drw *drw, const char *text, Bool markup);
|
||||
void drw_font_getexts(Fnt *font, const char *text, unsigned int len,
|
||||
unsigned int *w, unsigned int *h, Bool markup);
|
||||
|
||||
void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
|
||||
Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
|
||||
|
||||
Cur *drw_cur_create(Drw *drw, int shape);
|
||||
void drw_cur_free(Drw *drw, Cur *cursor);
|
||||
|
||||
void drw_setscheme(Drw *drw, Clr *scm);
|
||||
void drw_setfont(Drw *drw, Fnt *font);
|
||||
|
||||
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, Bool markup);
|
||||
|
||||
void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h);
|
||||
|
||||
#endif
|
||||
+226
@@ -0,0 +1,226 @@
|
||||
.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
|
||||
The attach below patch makes newly spawned windows attach after the currently
|
||||
selected window
|
||||
.P
|
||||
dwm draws a small border around windows to indicate the focus state.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B \-v
|
||||
prints version information to standard output, 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 Mod4\-Button1
|
||||
click on a tag label applies that tag to the focused window.
|
||||
.TP
|
||||
.B Mod4\-Button3
|
||||
click on a tag label adds/removes that tag to/from the focused window.
|
||||
.SS Keyboard commands
|
||||
.TP
|
||||
.B Mod4\-Shift\-Return
|
||||
Start
|
||||
.BR st(1).
|
||||
.TP
|
||||
.B Mod4\-p
|
||||
Spawn
|
||||
.BR dmenu(1)
|
||||
for launching other programs.
|
||||
.TP
|
||||
.B Mod4\-,
|
||||
Focus previous screen, if any.
|
||||
.TP
|
||||
.B Mod4\-.
|
||||
Focus next screen, if any.
|
||||
.TP
|
||||
.B Mod4\-Shift\-,
|
||||
Send focused window to previous screen, if any.
|
||||
.TP
|
||||
.B Mod4\-Shift\-.
|
||||
Send focused window to next screen, if any.
|
||||
.TP
|
||||
.B Mod4\-b
|
||||
Toggles bar on and off.
|
||||
.TP
|
||||
.B Mod4\-t
|
||||
Sets tiled layout.
|
||||
.TP
|
||||
.B Mod4\-f
|
||||
Sets floating layout.
|
||||
.TP
|
||||
.B Mod4\-m
|
||||
Sets monocle layout.
|
||||
.TP
|
||||
.B Mod4\-space
|
||||
Toggles between current and previous layout.
|
||||
.TP
|
||||
.B Mod4\-Control\-,
|
||||
Cycles backwards in layout list.
|
||||
.TP
|
||||
.B Mod4\-Control\-.
|
||||
Cycles forwards in layout list.
|
||||
.TP
|
||||
.B Mod4\-j
|
||||
Focus next window.
|
||||
.TP
|
||||
.B Mod4\-k
|
||||
Focus previous window.
|
||||
.TP
|
||||
.B Mod4\-i
|
||||
Increase number of windows in master area.
|
||||
.TP
|
||||
.B Mod4\-d
|
||||
Decrease number of windows in master area.
|
||||
.TP
|
||||
.B Mod4\-l
|
||||
Increase master area size.
|
||||
.TP
|
||||
.B Mod4\-h
|
||||
Decrease master area size.
|
||||
.TP
|
||||
.B Mod4\-Return
|
||||
Zooms/cycles focused window to/from master area (tiled layouts only).
|
||||
.TP
|
||||
.B Mod4\-Shift\-c
|
||||
Close focused window.
|
||||
.TP
|
||||
.B Mod4\-Shift\-space
|
||||
Toggle focused window between tiled and floating state.
|
||||
.TP
|
||||
.B Mod4\-Tab
|
||||
Toggles to the previously selected tags.
|
||||
.TP
|
||||
.B Mod4\-Shift\-[1..n]
|
||||
Apply nth tag to focused window.
|
||||
.TP
|
||||
.B Mod4\-Shift\-0
|
||||
Apply all tags to focused window.
|
||||
.TP
|
||||
.B Mod4\-Control\-Shift\-[1..n]
|
||||
Add/remove nth tag to/from focused window.
|
||||
.TP
|
||||
.B Mod4\-[1..n]
|
||||
View all windows with nth tag.
|
||||
.TP
|
||||
.B Mod4\-0
|
||||
View all windows with any tag.
|
||||
.TP
|
||||
.B Mod4\-Control\-[1..n]
|
||||
Add/remove all windows with nth tag to/from the view.
|
||||
.TP
|
||||
.B Mod4\-Shift\-q
|
||||
Quit dwm.
|
||||
.SS Mouse commands
|
||||
.TP
|
||||
.B Mod4\-Button1
|
||||
Move focused window while dragging. Tiled windows will be toggled to the floating state.
|
||||
.TP
|
||||
.B Mod4\-Button2
|
||||
Toggles focused window between floating and tiled state.
|
||||
.TP
|
||||
.B Mod4\-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, or by setting X resources.
|
||||
.P
|
||||
The following X resource settings can be set:
|
||||
.TP
|
||||
.BI dwm.font
|
||||
defines the font or font set used.
|
||||
.TP
|
||||
.BI dwm.background
|
||||
defines the normal background color.
|
||||
.IR #RGB ,
|
||||
.IR #RRGGBB ,
|
||||
and X color names are supported.
|
||||
.TP
|
||||
.BI dwm.border
|
||||
defines the normal border color
|
||||
.TP
|
||||
.BI dwm.selbackground
|
||||
defines the selected background color
|
||||
.TP
|
||||
.BI dwm.selforeground
|
||||
defines the selected foreground color
|
||||
.TP
|
||||
.BI dwm.selborder
|
||||
defines the selected border color
|
||||
.TP
|
||||
.BI dwm.tabactivebackground
|
||||
defines the background color for active tabs
|
||||
.TP
|
||||
.BI dwm.tabactiveforeground
|
||||
defines the foreground color for active tabs
|
||||
.TP
|
||||
.BI dwm.tabactiveborder
|
||||
defines the border color for active tabs
|
||||
.TP
|
||||
.BI dwm.tabinactivebackground
|
||||
defines the background color for inactive tabs
|
||||
.TP
|
||||
.BI dwm.tabinactiveforeground
|
||||
defines the foreground color for inactive tabs
|
||||
.TP
|
||||
.BI dwm.tabinactiveborder
|
||||
defines the border color for inactive tabs
|
||||
.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.
|
||||
+2331
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,42 @@
|
||||
/* cc transient.c -o transient -lX11 */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
int main(void) {
|
||||
Display *d;
|
||||
Window r, f, t = None;
|
||||
XSizeHints h;
|
||||
XEvent e;
|
||||
|
||||
d = XOpenDisplay(NULL);
|
||||
if (!d)
|
||||
exit(1);
|
||||
r = DefaultRootWindow(d);
|
||||
|
||||
f = XCreateSimpleWindow(d, r, 100, 100, 400, 400, 0, 0, 0);
|
||||
h.min_width = h.max_width = h.min_height = h.max_height = 400;
|
||||
h.flags = PMinSize | PMaxSize;
|
||||
XSetWMNormalHints(d, f, &h);
|
||||
XStoreName(d, f, "floating");
|
||||
XMapWindow(d, f);
|
||||
|
||||
XSelectInput(d, f, ExposureMask);
|
||||
while (1) {
|
||||
XNextEvent(d, &e);
|
||||
|
||||
if (t == None) {
|
||||
sleep(5);
|
||||
t = XCreateSimpleWindow(d, r, 50, 50, 100, 100, 0, 0, 0);
|
||||
XSetTransientForHint(d, t, f);
|
||||
XStoreName(d, t, "transient");
|
||||
XMapWindow(d, t);
|
||||
XSelectInput(d, t, ExposureMask);
|
||||
}
|
||||
}
|
||||
|
||||
XCloseDisplay(d);
|
||||
exit(0);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
void *
|
||||
ecalloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
if (!(p = calloc(nmemb, size)))
|
||||
die("calloc:");
|
||||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
die(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
|
||||
fputc(' ', stderr);
|
||||
perror(NULL);
|
||||
} else {
|
||||
fputc('\n', stderr);
|
||||
}
|
||||
|
||||
exit(1);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(A, B) ((A) > (B) ? (A) : (B))
|
||||
#endif
|
||||
#ifndef MIN
|
||||
#define MIN(A, B) ((A) < (B) ? (A) : (B))
|
||||
#endif
|
||||
#define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B))
|
||||
|
||||
void die(const char *fmt, ...);
|
||||
void *ecalloc(size_t nmemb, size_t size);
|
||||
@@ -0,0 +1,37 @@
|
||||
CC ?= gcc
|
||||
PKG_CONFIG ?= pkg-config
|
||||
PREFIX ?= /usr
|
||||
DESTDIR ?=
|
||||
|
||||
PKGS = x11 xext xft cairo pangocairo pango harfbuzz
|
||||
CFLAGS += -std=c11 -Wall -Wextra -O2 -I../libgemui $(shell $(PKG_CONFIG) --cflags $(PKGS))
|
||||
LIBS = -L../libgemui -lgemui $(shell $(PKG_CONFIG) --libs $(PKGS))
|
||||
|
||||
APPS = \
|
||||
geminux-dialer \
|
||||
geminux-callscreen \
|
||||
geminux-sms \
|
||||
geminux-contacts \
|
||||
geminux-net \
|
||||
geminux-camera \
|
||||
geminux-control \
|
||||
geminux-themes \
|
||||
geminux-lock
|
||||
|
||||
all: $(APPS)
|
||||
|
||||
geminux-camera: geminux-camera.c ../libgemui/gemui.h
|
||||
$(CC) $(CFLAGS) -o $@ $< $(LIBS) -ljpeg
|
||||
|
||||
geminux-%: geminux-%.c ../libgemui/gemui.h
|
||||
$(CC) $(CFLAGS) -o $@ $< $(LIBS)
|
||||
|
||||
install: all
|
||||
mkdir -p $(DESTDIR)$(PREFIX)/bin
|
||||
cp -f $(APPS) $(DESTDIR)$(PREFIX)/bin/
|
||||
for app in $(APPS); do chmod 0755 $(DESTDIR)$(PREFIX)/bin/$$app; done
|
||||
|
||||
clean:
|
||||
rm -f $(APPS)
|
||||
|
||||
.PHONY: all install clean
|
||||
@@ -0,0 +1,207 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "gemui.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#define HIT_ANSWER 1
|
||||
#define HIT_HANGUP 2
|
||||
#define HIT_MUTE 3
|
||||
#define HIT_SPEAKER 4
|
||||
#define HIT_HOLD 5
|
||||
#define HIT_KEY 6
|
||||
|
||||
typedef struct {
|
||||
gemui_app_t *app;
|
||||
char peer[96];
|
||||
char state_label[64];
|
||||
bool incoming;
|
||||
bool connected;
|
||||
bool muted;
|
||||
bool speaker;
|
||||
bool held;
|
||||
bool show_keypad;
|
||||
int elapsed_sec;
|
||||
} call_state_t;
|
||||
|
||||
static void send_modem(call_state_t *st, const char *cmd, const char *toast) {
|
||||
char resp[128] = {0};
|
||||
gemui_unix_cmd("/run/geminux/modem.sock", cmd, resp, sizeof(resp));
|
||||
if (toast) gemui_show_toast(st->app, toast, 1800);
|
||||
gemui_request_redraw(st->app);
|
||||
}
|
||||
|
||||
static void on_timer(gemui_app_t *app, void *ud) {
|
||||
(void)app;
|
||||
call_state_t *st = ud;
|
||||
if (st->connected && !st->held) {
|
||||
st->elapsed_sec++;
|
||||
gemui_request_redraw(st->app);
|
||||
}
|
||||
}
|
||||
|
||||
static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
|
||||
call_state_t *st = ud;
|
||||
const gemui_theme_t *t = gemui_theme(app);
|
||||
|
||||
char dur[32];
|
||||
snprintf(dur, sizeof(dur), "%02d:%02d", st->elapsed_sec / 60, st->elapsed_sec % 60);
|
||||
gemui_draw_header(app, cr, "\xef\x82\x95", "Geminux Voice Call",
|
||||
st->connected ? dur : (st->incoming ? "INCOMING" : "DIALING"));
|
||||
|
||||
int pad = 28;
|
||||
int card_w = w - pad * 2;
|
||||
gemui_rect_t hero = {pad, 92, card_w, 220};
|
||||
gemui_fill_round(cr, hero, 16, t->bg_overlay);
|
||||
gemui_stroke_round(cr, hero, 16, 2.0, st->connected ? t->success : t->accent);
|
||||
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){hero.x + 24, hero.y + 34, hero.w - 48, 60},
|
||||
st->peer[0] ? st->peer : "Unknown Number",
|
||||
16, true, GEMUI_ALIGN_CENTER, t->fg_bright);
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){hero.x + 24, hero.y + 106, hero.w - 48, 44},
|
||||
st->held ? "Call On Hold" : (st->connected ? "HD Voice Active (MT6797 UCM2)" : st->state_label),
|
||||
2, false, GEMUI_ALIGN_CENTER, st->connected ? t->success : t->accent_alt);
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){hero.x + 24, hero.y + 154, hero.w - 48, 40},
|
||||
dur, 8, true, GEMUI_ALIGN_CENTER, t->fg_main);
|
||||
|
||||
/* Main call control grid */
|
||||
int cy = 340;
|
||||
int gap = 16;
|
||||
int cw = (card_w - gap * 2) / 3;
|
||||
int ch = 96;
|
||||
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad, cy, cw, ch},
|
||||
st->muted ? "Mic: Muted" : "Mute Mic", HIT_MUTE, 0,
|
||||
false, st->muted, false);
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad + cw + gap, cy, cw, ch},
|
||||
st->speaker ? "Speaker: ON" : "Speakerphone", HIT_SPEAKER, 0,
|
||||
false, st->speaker, false);
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad + 2 * (cw + gap), cy, cw, ch},
|
||||
st->held ? "Resume Call" : "Hold Call", HIT_HOLD, 0,
|
||||
false, st->held, false);
|
||||
|
||||
/* Keypad strip for IVR DTMF */
|
||||
int ky = cy + ch + 24;
|
||||
int kw = (card_w - 11 * 8) / 12;
|
||||
static const char *dtmf[12] = {"1","2","3","4","5","6","7","8","9","*","0","#"};
|
||||
for (int i = 0; i < 12; i++) {
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad + i * (kw + 8), ky, kw, 76},
|
||||
dtmf[i], HIT_KEY, i, false, false, false);
|
||||
}
|
||||
|
||||
/* Bottom Answer / Hangup buttons */
|
||||
int by = h - 116;
|
||||
if (st->incoming && !st->connected) {
|
||||
int hw = (card_w - gap) / 2;
|
||||
gemui_rect_t ans = {pad, by, hw, 88};
|
||||
gemui_fill_round(cr, ans, 14, t->success);
|
||||
gemui_draw_text(cr, t, ans, "Answer Call", 4, true, GEMUI_ALIGN_CENTER, t->sel_fg);
|
||||
gemui_hit_add(app, ans, HIT_ANSWER, 0);
|
||||
|
||||
gemui_rect_t rej = {pad + hw + gap, by, hw, 88};
|
||||
gemui_fill_round(cr, rej, 14, t->danger);
|
||||
gemui_draw_text(cr, t, rej, "Decline", 4, true, GEMUI_ALIGN_CENTER, t->sel_fg);
|
||||
gemui_hit_add(app, rej, HIT_HANGUP, 0);
|
||||
} else {
|
||||
gemui_rect_t end = {pad, by, card_w, 88};
|
||||
gemui_fill_round(cr, end, 14, t->danger);
|
||||
gemui_stroke_round(cr, end, 14, 2.0, t->danger_bg);
|
||||
gemui_draw_text(cr, t, end, "Hang Up Call", 6, true, GEMUI_ALIGN_CENTER, t->sel_fg);
|
||||
gemui_hit_add(app, end, HIT_HANGUP, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void toggle_speaker(call_state_t *st) {
|
||||
st->speaker = !st->speaker;
|
||||
send_modem(st, st->speaker ? "speaker on" : "speaker off",
|
||||
st->speaker ? "Audio routed to AW8738 speaker" : "Audio routed to earpiece");
|
||||
}
|
||||
|
||||
static void toggle_mute(call_state_t *st) {
|
||||
st->muted = !st->muted;
|
||||
send_modem(st, st->muted ? "mute on" : "mute off",
|
||||
st->muted ? "Microphone muted" : "Microphone unmuted");
|
||||
}
|
||||
|
||||
static void hangup_and_quit(call_state_t *st) {
|
||||
send_modem(st, "hangup", NULL);
|
||||
const char *mm[] = {"mmcli", "-m", "0", "--voice-hangup-all", NULL};
|
||||
gemui_run_cmd_capture(mm, NULL, 0);
|
||||
gemui_quit(st->app, 0);
|
||||
}
|
||||
|
||||
static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *utf8, void *ud) {
|
||||
(void)app;
|
||||
(void)state;
|
||||
call_state_t *st = ud;
|
||||
if (ks == XK_Escape || ks == XK_h) {
|
||||
hangup_and_quit(st);
|
||||
} else if (ks == XK_m) {
|
||||
toggle_mute(st);
|
||||
} else if (ks == XK_s) {
|
||||
toggle_speaker(st);
|
||||
} else if (ks == XK_Return && st->incoming && !st->connected) {
|
||||
st->connected = true;
|
||||
send_modem(st, "answer", "Call connected");
|
||||
} else if (utf8 && strchr("0123456789*#", utf8[0])) {
|
||||
char cmd[32];
|
||||
snprintf(cmd, sizeof(cmd), "dtmf %c", utf8[0]);
|
||||
send_modem(st, cmd, "Sent DTMF tone");
|
||||
}
|
||||
}
|
||||
|
||||
static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, void *ud) {
|
||||
(void)btn;
|
||||
call_state_t *st = ud;
|
||||
if (type != GEMUI_PTR_DOWN) return;
|
||||
const gemui_hit_t *hit = gemui_hit_test(app, x, y);
|
||||
if (!hit) return;
|
||||
|
||||
if (hit->id == HIT_ANSWER) {
|
||||
st->connected = true;
|
||||
st->incoming = false;
|
||||
send_modem(st, "answer", "Call connected");
|
||||
} else if (hit->id == HIT_HANGUP) {
|
||||
hangup_and_quit(st);
|
||||
} else if (hit->id == HIT_MUTE) {
|
||||
toggle_mute(st);
|
||||
} else if (hit->id == HIT_SPEAKER) {
|
||||
toggle_speaker(st);
|
||||
} else if (hit->id == HIT_HOLD) {
|
||||
st->held = !st->held;
|
||||
gemui_show_toast(app, st->held ? "Call placed on hold" : "Call resumed", 1500);
|
||||
gemui_request_redraw(app);
|
||||
} else if (hit->id == HIT_KEY) {
|
||||
static const char map[12] = {'1','2','3','4','5','6','7','8','9','*','0','#'};
|
||||
if (hit->val >= 0 && hit->val < 12) {
|
||||
char cmd[32];
|
||||
snprintf(cmd, sizeof(cmd), "dtmf %c", map[hit->val]);
|
||||
send_modem(st, cmd, "Sent DTMF tone");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
call_state_t st;
|
||||
memset(&st, 0, sizeof(st));
|
||||
snprintf(st.peer, sizeof(st.peer), "%s", (argc > 1 && argv[1][0]) ? argv[1] : "Unknown");
|
||||
if (argc > 2 && strcmp(argv[2], "--incoming") == 0) {
|
||||
st.incoming = true;
|
||||
snprintf(st.state_label, sizeof(st.state_label), "Incoming Voice Call");
|
||||
} else {
|
||||
st.connected = true;
|
||||
snprintf(st.state_label, sizeof(st.state_label), "Connecting Voice Call...");
|
||||
}
|
||||
|
||||
st.app = gemui_create("geminux-callscreen", "Geminux Voice Call", 1600, 860, false);
|
||||
if (!st.app) return 1;
|
||||
|
||||
gemui_handlers_t h = { .on_draw = on_draw, .on_key = on_key, .on_ptr = on_ptr };
|
||||
gemui_set_handlers(st.app, &h, &st);
|
||||
gemui_set_timer_ms(st.app, 1000, on_timer, &st);
|
||||
int rc = gemui_run(st.app);
|
||||
gemui_destroy(st.app);
|
||||
return rc;
|
||||
}
|
||||
@@ -0,0 +1,527 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "gemui.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/videodev2.h>
|
||||
#include <stdio.h>
|
||||
#include <jpeglib.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define HIT_SHUTTER 1
|
||||
#define HIT_RECORD 2
|
||||
#define HIT_SWITCH 3
|
||||
|
||||
typedef struct {
|
||||
void *start;
|
||||
size_t length;
|
||||
} v4l2_buf_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t offset;
|
||||
uint32_t size;
|
||||
} avi_idx_t;
|
||||
|
||||
typedef struct {
|
||||
gemui_app_t *app;
|
||||
int vfd;
|
||||
char dev_path[64];
|
||||
char dev_list[8][64];
|
||||
int num_devs;
|
||||
int cur_dev;
|
||||
uint32_t pixfmt;
|
||||
int cam_w;
|
||||
int cam_h;
|
||||
v4l2_buf_t bufs[4];
|
||||
int num_bufs;
|
||||
uint8_t *rgb24;
|
||||
uint32_t *argb32;
|
||||
cairo_surface_t *frame_surf;
|
||||
bool recording;
|
||||
FILE *avi_fp;
|
||||
uint32_t avi_frames;
|
||||
long avi_movi_pos;
|
||||
avi_idx_t *avi_idx;
|
||||
int avi_idx_cap;
|
||||
char last_file[128];
|
||||
} cam_state_t;
|
||||
|
||||
static uint8_t clamp_u8(int v) {
|
||||
return (uint8_t)(v < 0 ? 0 : (v > 255 ? 255 : v));
|
||||
}
|
||||
|
||||
static void yuyv_to_buffers(const uint8_t *src, int w, int h, uint8_t *rgb, uint32_t *argb) {
|
||||
int pairs = (w * h) / 2;
|
||||
for (int i = 0; i < pairs; i++) {
|
||||
int y0 = src[4 * i + 0] - 16;
|
||||
int u = src[4 * i + 1] - 128;
|
||||
int y1 = src[4 * i + 2] - 16;
|
||||
int v = src[4 * i + 3] - 128;
|
||||
|
||||
int c0 = 298 * y0;
|
||||
int c1 = 298 * y1;
|
||||
int r0 = clamp_u8((c0 + 409 * v + 128) >> 8);
|
||||
int g0 = clamp_u8((c0 - 100 * u - 208 * v + 128) >> 8);
|
||||
int b0 = clamp_u8((c0 + 516 * u + 128) >> 8);
|
||||
int r1 = clamp_u8((c1 + 409 * v + 128) >> 8);
|
||||
int g1 = clamp_u8((c1 - 100 * u - 208 * v + 128) >> 8);
|
||||
int b1 = clamp_u8((c1 + 516 * u + 128) >> 8);
|
||||
|
||||
rgb[6 * i + 0] = (uint8_t)r0;
|
||||
rgb[6 * i + 1] = (uint8_t)g0;
|
||||
rgb[6 * i + 2] = (uint8_t)b0;
|
||||
rgb[6 * i + 3] = (uint8_t)r1;
|
||||
rgb[6 * i + 4] = (uint8_t)g1;
|
||||
rgb[6 * i + 5] = (uint8_t)b1;
|
||||
|
||||
argb[2 * i + 0] = 0xff000000U | ((uint32_t)r0 << 16) | ((uint32_t)g0 << 8) | (uint32_t)b0;
|
||||
argb[2 * i + 1] = 0xff000000U | ((uint32_t)r1 << 16) | ((uint32_t)g1 << 8) | (uint32_t)b1;
|
||||
}
|
||||
}
|
||||
|
||||
static bool encode_rgb24_jpeg_mem(const uint8_t *rgb, int w, int h, int quality,
|
||||
unsigned char **out_buf, unsigned long *out_sz) {
|
||||
struct jpeg_compress_struct cinfo;
|
||||
struct jpeg_error_mgr jerr;
|
||||
cinfo.err = jpeg_std_error(&jerr);
|
||||
jpeg_create_compress(&cinfo);
|
||||
*out_buf = NULL;
|
||||
*out_sz = 0;
|
||||
jpeg_mem_dest(&cinfo, out_buf, out_sz);
|
||||
cinfo.image_width = (JDIMENSION)w;
|
||||
cinfo.image_height = (JDIMENSION)h;
|
||||
cinfo.input_components = 3;
|
||||
cinfo.in_color_space = JCS_RGB;
|
||||
jpeg_set_defaults(&cinfo);
|
||||
jpeg_set_quality(&cinfo, quality, TRUE);
|
||||
jpeg_start_compress(&cinfo, TRUE);
|
||||
while (cinfo.next_scanline < cinfo.image_height) {
|
||||
JSAMPROW row[1] = {(JSAMPROW)(rgb + (size_t)cinfo.next_scanline * (size_t)w * 3U)};
|
||||
jpeg_write_scanlines(&cinfo, row, 1);
|
||||
}
|
||||
jpeg_finish_compress(&cinfo);
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
return *out_buf != NULL && *out_sz > 0;
|
||||
}
|
||||
|
||||
static void put_le32(FILE *f, uint32_t v) {
|
||||
uint8_t b[4] = {(uint8_t)v, (uint8_t)(v >> 8), (uint8_t)(v >> 16), (uint8_t)(v >> 24)};
|
||||
fwrite(b, 1, 4, f);
|
||||
}
|
||||
|
||||
static void put_le16(FILE *f, uint16_t v) {
|
||||
uint8_t b[2] = {(uint8_t)v, (uint8_t)(v >> 8)};
|
||||
fwrite(b, 1, 2, f);
|
||||
}
|
||||
|
||||
static void avi_stop(cam_state_t *st) {
|
||||
if (!st->recording || !st->avi_fp) return;
|
||||
FILE *f = st->avi_fp;
|
||||
long end_movi = ftell(f);
|
||||
uint32_t movi_sz = (uint32_t)(end_movi - st->avi_movi_pos - 4);
|
||||
|
||||
fwrite("idx1", 1, 4, f);
|
||||
put_le32(f, st->avi_frames * 16U);
|
||||
for (uint32_t i = 0; i < st->avi_frames; i++) {
|
||||
fwrite("00dc", 1, 4, f);
|
||||
put_le32(f, 0x10U);
|
||||
put_le32(f, st->avi_idx[i].offset);
|
||||
put_le32(f, st->avi_idx[i].size);
|
||||
}
|
||||
long file_end = ftell(f);
|
||||
|
||||
fseek(f, 4, SEEK_SET);
|
||||
put_le32(f, (uint32_t)(file_end - 8));
|
||||
fseek(f, 48, SEEK_SET);
|
||||
put_le32(f, st->avi_frames);
|
||||
fseek(f, 140, SEEK_SET);
|
||||
put_le32(f, st->avi_frames);
|
||||
fseek(f, st->avi_movi_pos, SEEK_SET);
|
||||
put_le32(f, movi_sz);
|
||||
|
||||
fclose(f);
|
||||
st->avi_fp = NULL;
|
||||
st->recording = false;
|
||||
free(st->avi_idx);
|
||||
st->avi_idx = NULL;
|
||||
st->avi_idx_cap = 0;
|
||||
gemui_show_toast(st->app, "Saved MJPEG AVI video", 2000);
|
||||
}
|
||||
|
||||
static void avi_start(cam_state_t *st) {
|
||||
if (!st->rgb24 || st->cam_w <= 0 || st->cam_h <= 0) {
|
||||
gemui_show_toast(st->app, "No active camera stream", 1800);
|
||||
return;
|
||||
}
|
||||
const char *home = getenv("HOME");
|
||||
char dir[512], path[576], ts[32];
|
||||
snprintf(dir, sizeof(dir), "%s/Videos", (home && home[0]) ? home : "/home/user");
|
||||
const char *mk[] = {"mkdir", "-p", dir, NULL};
|
||||
gemui_run_cmd_capture(mk, NULL, 0);
|
||||
time_t now = time(NULL);
|
||||
struct tm tm;
|
||||
localtime_r(&now, &tm);
|
||||
strftime(ts, sizeof(ts), "%Y%m%d_%H%M%S", &tm);
|
||||
snprintf(path, sizeof(path), "%s/VID_%s.avi", dir, ts);
|
||||
|
||||
FILE *f = fopen(path, "wb+");
|
||||
if (!f) return;
|
||||
|
||||
fwrite("RIFF", 1, 4, f); put_le32(f, 0); fwrite("AVI ", 1, 4, f);
|
||||
fwrite("LIST", 1, 4, f); put_le32(f, 192); fwrite("hdrl", 1, 4, f);
|
||||
fwrite("avih", 1, 4, f); put_le32(f, 56);
|
||||
put_le32(f, 66667); put_le32(f, 0); put_le32(f, 0); put_le32(f, 0x10U);
|
||||
put_le32(f, 0); put_le32(f, 0); put_le32(f, 1); put_le32(f, 0);
|
||||
put_le32(f, (uint32_t)st->cam_w); put_le32(f, (uint32_t)st->cam_h);
|
||||
for (int i = 0; i < 4; i++) put_le32(f, 0);
|
||||
|
||||
fwrite("LIST", 1, 4, f); put_le32(f, 116); fwrite("strl", 1, 4, f);
|
||||
fwrite("strh", 1, 4, f); put_le32(f, 56);
|
||||
fwrite("vids", 1, 4, f); fwrite("MJPG", 1, 4, f);
|
||||
put_le32(f, 0); put_le32(f, 0); put_le32(f, 0);
|
||||
put_le32(f, 1); put_le32(f, 15); put_le32(f, 0);
|
||||
put_le32(f, 0); put_le32(f, 0); put_le32(f, 0);
|
||||
put_le16(f, 0); put_le16(f, 0);
|
||||
put_le16(f, (uint16_t)st->cam_w); put_le16(f, (uint16_t)st->cam_h);
|
||||
|
||||
fwrite("strf", 1, 4, f); put_le32(f, 40);
|
||||
put_le32(f, 40); put_le32(f, (uint32_t)st->cam_w); put_le32(f, (uint32_t)st->cam_h);
|
||||
put_le16(f, 1); put_le16(f, 24); fwrite("MJPG", 1, 4, f);
|
||||
put_le32(f, (uint32_t)(st->cam_w * st->cam_h * 3));
|
||||
for (int i = 0; i < 4; i++) put_le32(f, 0);
|
||||
|
||||
fwrite("LIST", 1, 4, f);
|
||||
st->avi_movi_pos = ftell(f);
|
||||
put_le32(f, 0);
|
||||
fwrite("movi", 1, 4, f);
|
||||
|
||||
st->avi_fp = f;
|
||||
st->avi_frames = 0;
|
||||
st->recording = true;
|
||||
snprintf(st->last_file, sizeof(st->last_file), "VID_%s.avi", ts);
|
||||
gemui_show_toast(st->app, "Recording MJPEG AVI video...", 1500);
|
||||
}
|
||||
|
||||
static void avi_write_frame(cam_state_t *st, const uint8_t *jpg, size_t jpg_sz) {
|
||||
if (!st->recording || !st->avi_fp || !jpg || !jpg_sz) return;
|
||||
if ((int)st->avi_frames >= st->avi_idx_cap) {
|
||||
int ncap = st->avi_idx_cap ? st->avi_idx_cap * 2 : 512;
|
||||
avi_idx_t *nptr = realloc(st->avi_idx, (size_t)ncap * sizeof(avi_idx_t));
|
||||
if (!nptr) return;
|
||||
st->avi_idx = nptr;
|
||||
st->avi_idx_cap = ncap;
|
||||
}
|
||||
long chunk_off = ftell(st->avi_fp) - (st->avi_movi_pos + 4);
|
||||
fwrite("00dc", 1, 4, st->avi_fp);
|
||||
put_le32(st->avi_fp, (uint32_t)jpg_sz);
|
||||
fwrite(jpg, 1, jpg_sz, st->avi_fp);
|
||||
if (jpg_sz & 1U) fputc(0, st->avi_fp);
|
||||
|
||||
st->avi_idx[st->avi_frames].offset = (uint32_t)chunk_off;
|
||||
st->avi_idx[st->avi_frames].size = (uint32_t)jpg_sz;
|
||||
st->avi_frames++;
|
||||
}
|
||||
|
||||
static void close_camera(cam_state_t *st) {
|
||||
if (st->recording) avi_stop(st);
|
||||
if (st->vfd >= 0) {
|
||||
enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
ioctl(st->vfd, VIDIOC_STREAMOFF, &type);
|
||||
gemui_del_fd(st->app, st->vfd);
|
||||
for (int i = 0; i < st->num_bufs; i++) {
|
||||
if (st->bufs[i].start && st->bufs[i].start != MAP_FAILED) {
|
||||
munmap(st->bufs[i].start, st->bufs[i].length);
|
||||
}
|
||||
}
|
||||
close(st->vfd);
|
||||
st->vfd = -1;
|
||||
}
|
||||
st->num_bufs = 0;
|
||||
if (st->frame_surf) {
|
||||
cairo_surface_destroy(st->frame_surf);
|
||||
st->frame_surf = NULL;
|
||||
}
|
||||
free(st->rgb24); st->rgb24 = NULL;
|
||||
free(st->argb32); st->argb32 = NULL;
|
||||
}
|
||||
|
||||
static void on_v4l2_ready(gemui_app_t *app, int fd, void *ud) {
|
||||
cam_state_t *st = ud;
|
||||
struct v4l2_buffer buf;
|
||||
memset(&buf, 0, sizeof(buf));
|
||||
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
buf.memory = V4L2_MEMORY_MMAP;
|
||||
if (ioctl(fd, VIDIOC_DQBUF, &buf) < 0) return;
|
||||
|
||||
const uint8_t *raw = st->bufs[buf.index].start;
|
||||
if (st->pixfmt == V4L2_PIX_FMT_YUYV && raw && buf.bytesused >= (uint32_t)(st->cam_w * st->cam_h * 2)) {
|
||||
yuyv_to_buffers(raw, st->cam_w, st->cam_h, st->rgb24, st->argb32);
|
||||
if (st->recording) {
|
||||
unsigned char *jb = NULL;
|
||||
unsigned long jsz = 0;
|
||||
if (encode_rgb24_jpeg_mem(st->rgb24, st->cam_w, st->cam_h, 80, &jb, &jsz)) {
|
||||
avi_write_frame(st, jb, jsz);
|
||||
free(jb);
|
||||
}
|
||||
}
|
||||
} else if (st->pixfmt == V4L2_PIX_FMT_MJPEG && raw && buf.bytesused > 4) {
|
||||
if (st->recording) avi_write_frame(st, raw, buf.bytesused);
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
struct jpeg_error_mgr jerr;
|
||||
cinfo.err = jpeg_std_error(&jerr);
|
||||
jpeg_create_decompress(&cinfo);
|
||||
jpeg_mem_src(&cinfo, raw, buf.bytesused);
|
||||
if (jpeg_read_header(&cinfo, TRUE) == JPEG_HEADER_OK) {
|
||||
cinfo.out_color_space = JCS_RGB;
|
||||
jpeg_start_decompress(&cinfo);
|
||||
int row_stride = (int)cinfo.output_width * 3;
|
||||
while ((int)cinfo.output_scanline < (int)cinfo.output_height &&
|
||||
(int)cinfo.output_scanline < st->cam_h) {
|
||||
int y = (int)cinfo.output_scanline;
|
||||
uint8_t *dst = st->rgb24 + (size_t)y * (size_t)st->cam_w * 3U;
|
||||
JSAMPROW row[1] = {dst};
|
||||
jpeg_read_scanlines(&cinfo, row, 1);
|
||||
int cw = (int)cinfo.output_width < st->cam_w ? (int)cinfo.output_width : st->cam_w;
|
||||
for (int x = 0; x < cw; x++) {
|
||||
uint8_t r = dst[3 * x], g = dst[3 * x + 1], b = dst[3 * x + 2];
|
||||
st->argb32[y * st->cam_w + x] = 0xff000000U | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
|
||||
}
|
||||
(void)row_stride;
|
||||
}
|
||||
jpeg_finish_decompress(&cinfo);
|
||||
}
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
}
|
||||
|
||||
if (st->frame_surf) cairo_surface_mark_dirty(st->frame_surf);
|
||||
ioctl(fd, VIDIOC_QBUF, &buf);
|
||||
gemui_request_redraw(app);
|
||||
}
|
||||
|
||||
static void open_camera_idx(cam_state_t *st, int idx) {
|
||||
close_camera(st);
|
||||
if (idx < 0 || idx >= st->num_devs) return;
|
||||
|
||||
int fd = open(st->dev_list[idx], O_RDWR | O_NONBLOCK | O_CLOEXEC);
|
||||
if (fd < 0) return;
|
||||
|
||||
struct v4l2_format fmt;
|
||||
memset(&fmt, 0, sizeof(fmt));
|
||||
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
fmt.fmt.pix.width = 1280;
|
||||
fmt.fmt.pix.height = 720;
|
||||
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
|
||||
fmt.fmt.pix.field = V4L2_FIELD_NONE;
|
||||
if (ioctl(fd, VIDIOC_S_FMT, &fmt) < 0) {
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
st->cam_w = (int)fmt.fmt.pix.width;
|
||||
st->cam_h = (int)fmt.fmt.pix.height;
|
||||
st->pixfmt = fmt.fmt.pix.pixelformat;
|
||||
st->rgb24 = calloc((size_t)st->cam_w * (size_t)st->cam_h, 3);
|
||||
st->argb32 = calloc((size_t)st->cam_w * (size_t)st->cam_h, sizeof(uint32_t));
|
||||
st->frame_surf = cairo_image_surface_create_for_data(
|
||||
(unsigned char *)st->argb32, CAIRO_FORMAT_RGB24, st->cam_w, st->cam_h, st->cam_w * 4);
|
||||
|
||||
struct v4l2_requestbuffers req;
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.count = 4;
|
||||
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
req.memory = V4L2_MEMORY_MMAP;
|
||||
if (ioctl(fd, VIDIOC_REQBUFS, &req) < 0 || req.count == 0) {
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < (int)req.count && i < 4; i++) {
|
||||
struct v4l2_buffer b;
|
||||
memset(&b, 0, sizeof(b));
|
||||
b.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
b.memory = V4L2_MEMORY_MMAP;
|
||||
b.index = (uint32_t)i;
|
||||
if (ioctl(fd, VIDIOC_QUERYBUF, &b) < 0) break;
|
||||
st->bufs[i].length = b.length;
|
||||
st->bufs[i].start = mmap(NULL, b.length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, b.m.offset);
|
||||
if (st->bufs[i].start == MAP_FAILED) break;
|
||||
st->num_bufs = i + 1;
|
||||
ioctl(fd, VIDIOC_QBUF, &b);
|
||||
}
|
||||
|
||||
enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
if (ioctl(fd, VIDIOC_STREAMON, &type) < 0) {
|
||||
st->vfd = fd;
|
||||
close_camera(st);
|
||||
return;
|
||||
}
|
||||
|
||||
st->vfd = fd;
|
||||
st->cur_dev = idx;
|
||||
snprintf(st->dev_path, sizeof(st->dev_path), "%s", st->dev_list[idx]);
|
||||
gemui_add_fd(st->app, fd, on_v4l2_ready, st);
|
||||
}
|
||||
|
||||
static void capture_still(cam_state_t *st) {
|
||||
if (!st->rgb24 || st->cam_w <= 0 || st->cam_h <= 0) {
|
||||
gemui_show_toast(st->app, "No active V4L2 frame to capture", 1800);
|
||||
return;
|
||||
}
|
||||
const char *home = getenv("HOME");
|
||||
char dir[512], path[576], ts[32];
|
||||
snprintf(dir, sizeof(dir), "%s/Pictures", (home && home[0]) ? home : "/home/user");
|
||||
const char *mk[] = {"mkdir", "-p", dir, NULL};
|
||||
gemui_run_cmd_capture(mk, NULL, 0);
|
||||
|
||||
time_t now = time(NULL);
|
||||
struct tm tm;
|
||||
localtime_r(&now, &tm);
|
||||
strftime(ts, sizeof(ts), "%Y%m%d_%H%M%S", &tm);
|
||||
snprintf(path, sizeof(path), "%s/IMG_%s.jpg", dir, ts);
|
||||
|
||||
unsigned char *jb = NULL;
|
||||
unsigned long jsz = 0;
|
||||
if (encode_rgb24_jpeg_mem(st->rgb24, st->cam_w, st->cam_h, 92, &jb, &jsz)) {
|
||||
FILE *f = fopen(path, "wb");
|
||||
if (f) {
|
||||
fwrite(jb, 1, jsz, f);
|
||||
fclose(f);
|
||||
snprintf(st->last_file, sizeof(st->last_file), "IMG_%s.jpg", ts);
|
||||
gemui_show_toast(st->app, "Captured still JPEG to ~/Pictures", 2000);
|
||||
}
|
||||
free(jb);
|
||||
}
|
||||
gemui_request_redraw(st->app);
|
||||
}
|
||||
|
||||
static void discover_cameras(cam_state_t *st) {
|
||||
st->num_devs = 0;
|
||||
for (int i = 0; i < 16 && st->num_devs < 8; i++) {
|
||||
char p[64];
|
||||
snprintf(p, sizeof(p), "/dev/video%d", i);
|
||||
int fd = open(p, O_RDWR | O_NONBLOCK | O_CLOEXEC);
|
||||
if (fd < 0) continue;
|
||||
struct v4l2_capability cap;
|
||||
if (ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0 &&
|
||||
((cap.device_caps & V4L2_CAP_VIDEO_CAPTURE) ||
|
||||
(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))) {
|
||||
snprintf(st->dev_list[st->num_devs++], 64, "%s", p);
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
|
||||
cam_state_t *st = ud;
|
||||
const gemui_theme_t *t = gemui_theme(app);
|
||||
|
||||
char badge[96];
|
||||
snprintf(badge, sizeof(badge), "%s%s",
|
||||
st->vfd >= 0 ? st->dev_path : "No V4L2 Camera",
|
||||
st->recording ? " [REC]" : "");
|
||||
gemui_draw_header(app, cr, "\xef\x80\xb0", "Geminux Camera", badge);
|
||||
|
||||
int pad = 20;
|
||||
gemui_rect_t vf = {pad, 80, w - 260 - pad * 3, h - 100};
|
||||
gemui_fill_round(cr, vf, 14, t->bg_overlay);
|
||||
gemui_stroke_round(cr, vf, 14, 2.0, st->recording ? t->danger : t->border);
|
||||
|
||||
if (st->vfd >= 0 && st->frame_surf && st->cam_w > 0 && st->cam_h > 0) {
|
||||
double sx = (double)(vf.w - 8) / st->cam_w;
|
||||
double sy = (double)(vf.h - 8) / st->cam_h;
|
||||
double sc = sx < sy ? sx : sy;
|
||||
int dw = (int)(st->cam_w * sc);
|
||||
int dh = (int)(st->cam_h * sc);
|
||||
int dx = vf.x + (vf.w - dw) / 2;
|
||||
int dy = vf.y + (vf.h - dh) / 2;
|
||||
cairo_save(cr);
|
||||
cairo_translate(cr, dx, dy);
|
||||
cairo_scale(cr, sc, sc);
|
||||
cairo_set_source_surface(cr, st->frame_surf, 0, 0);
|
||||
cairo_paint(cr);
|
||||
cairo_restore(cr);
|
||||
} else {
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){vf.x + 24, vf.y + vf.h / 2 - 40, vf.w - 48, 40},
|
||||
"Camera Stream Unavailable", 4, true, GEMUI_ALIGN_CENTER, t->fg_bright);
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){vf.x + 24, vf.y + vf.h / 2 + 8, vf.w - 48, 36},
|
||||
"Waiting for hi556 / mt6797-seninf V4L2 /dev/video* device",
|
||||
-2, false, GEMUI_ALIGN_CENTER, t->fg_muted);
|
||||
}
|
||||
|
||||
int rx = vf.x + vf.w + pad;
|
||||
int rw = 260;
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){rx, 96, rw, 92},
|
||||
"Photo (JPEG)", HIT_SHUTTER, 0, true, false, false);
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){rx, 208, rw, 92},
|
||||
st->recording ? "Stop AVI" : "Record AVI", HIT_RECORD, 0, false, st->recording, false);
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){rx, 320, rw, 76},
|
||||
"Switch Sensor", HIT_SWITCH, 0, false, false, false);
|
||||
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){rx, 430, rw, 36},
|
||||
st->last_file[0] ? "Last Saved:" : "", -3, true, GEMUI_ALIGN_LEFT, t->fg_muted);
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){rx, 466, rw, 36},
|
||||
st->last_file[0] ? st->last_file : "Space: Shutter",
|
||||
-3, false, GEMUI_ALIGN_LEFT, t->accent);
|
||||
}
|
||||
|
||||
static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *utf8, void *ud) {
|
||||
(void)state;
|
||||
(void)utf8;
|
||||
cam_state_t *st = ud;
|
||||
if (ks == XK_Escape) {
|
||||
gemui_quit(app, 0);
|
||||
} else if (ks == XK_space || ks == XK_Return) {
|
||||
capture_still(st);
|
||||
} else if (ks == XK_r) {
|
||||
if (st->recording) avi_stop(st); else avi_start(st);
|
||||
gemui_request_redraw(app);
|
||||
}
|
||||
}
|
||||
|
||||
static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, void *ud) {
|
||||
(void)btn;
|
||||
cam_state_t *st = ud;
|
||||
if (type != GEMUI_PTR_DOWN) return;
|
||||
const gemui_hit_t *hit = gemui_hit_test(app, x, y);
|
||||
if (!hit) return;
|
||||
|
||||
if (hit->id == HIT_SHUTTER) {
|
||||
capture_still(st);
|
||||
} else if (hit->id == HIT_RECORD) {
|
||||
if (st->recording) avi_stop(st); else avi_start(st);
|
||||
gemui_request_redraw(app);
|
||||
} else if (hit->id == HIT_SWITCH) {
|
||||
discover_cameras(st);
|
||||
if (st->num_devs > 0) {
|
||||
open_camera_idx(st, (st->cur_dev + 1) % st->num_devs);
|
||||
} else {
|
||||
gemui_show_toast(app, "No /dev/video* sensor found", 1800);
|
||||
}
|
||||
gemui_request_redraw(app);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
cam_state_t st;
|
||||
memset(&st, 0, sizeof(st));
|
||||
st.vfd = -1;
|
||||
discover_cameras(&st);
|
||||
|
||||
st.app = gemui_create("geminux-camera", "Geminux Camera", 1640, 900, false);
|
||||
if (!st.app) return 1;
|
||||
if (st.num_devs > 0) open_camera_idx(&st, 0);
|
||||
|
||||
gemui_handlers_t h = { .on_draw = on_draw, .on_key = on_key, .on_ptr = on_ptr };
|
||||
gemui_set_handlers(st.app, &h, &st);
|
||||
int rc = gemui_run(st.app);
|
||||
close_camera(&st);
|
||||
gemui_destroy(st.app);
|
||||
return rc;
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "gemui.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define HIT_SEARCH 1
|
||||
#define HIT_ROW 2
|
||||
#define HIT_NAME 3
|
||||
#define HIT_PHONE 4
|
||||
#define HIT_SAVE 5
|
||||
#define HIT_DEL 6
|
||||
#define HIT_CALL 7
|
||||
#define HIT_SMS 8
|
||||
#define HIT_NEW 9
|
||||
|
||||
typedef struct {
|
||||
char name[64];
|
||||
char number[48];
|
||||
char note[64];
|
||||
} contact_t;
|
||||
|
||||
typedef struct {
|
||||
gemui_app_t *app;
|
||||
char path[512];
|
||||
contact_t items[128];
|
||||
int num_items;
|
||||
int filtered[128];
|
||||
int num_filtered;
|
||||
int sel_idx;
|
||||
int focus; /* 0 = search, 1 = edit name, 2 = edit phone */
|
||||
char search[64];
|
||||
char edit_name[64];
|
||||
char edit_phone[48];
|
||||
} contacts_state_t;
|
||||
|
||||
static bool contains_ci(const char *hay, const char *needle) {
|
||||
if (!needle[0]) return true;
|
||||
size_t nl = strlen(needle);
|
||||
for (; *hay; hay++) {
|
||||
size_t i = 0;
|
||||
while (i < nl && hay[i] &&
|
||||
tolower((unsigned char)hay[i]) == tolower((unsigned char)needle[i])) {
|
||||
i++;
|
||||
}
|
||||
if (i == nl) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void apply_filter(contacts_state_t *st) {
|
||||
st->num_filtered = 0;
|
||||
for (int i = 0; i < st->num_items; i++) {
|
||||
if (contains_ci(st->items[i].name, st->search) ||
|
||||
contains_ci(st->items[i].number, st->search)) {
|
||||
st->filtered[st->num_filtered++] = i;
|
||||
}
|
||||
}
|
||||
if (st->sel_idx >= st->num_items) st->sel_idx = st->num_items - 1;
|
||||
}
|
||||
|
||||
static void load_contacts(contacts_state_t *st) {
|
||||
st->num_items = 0;
|
||||
FILE *f = fopen(st->path, "r");
|
||||
if (!f) {
|
||||
apply_filter(st);
|
||||
return;
|
||||
}
|
||||
char line[256];
|
||||
while (fgets(line, sizeof(line), f) && st->num_items < 128) {
|
||||
size_t len = strlen(line);
|
||||
while (len > 0 && (line[len - 1] == '\n' || line[len - 1] == '\r')) line[--len] = '\0';
|
||||
if (!line[0] || line[0] == '#') continue;
|
||||
char *t1 = strchr(line, '\t');
|
||||
if (!t1) continue;
|
||||
*t1 = '\0';
|
||||
char *t2 = strchr(t1 + 1, '\t');
|
||||
if (t2) *t2 = '\0';
|
||||
contact_t *c = &st->items[st->num_items++];
|
||||
snprintf(c->name, sizeof(c->name), "%s", line);
|
||||
snprintf(c->number, sizeof(c->number), "%s", t1 + 1);
|
||||
snprintf(c->note, sizeof(c->note), "%s", t2 ? (t2 + 1) : "");
|
||||
}
|
||||
fclose(f);
|
||||
apply_filter(st);
|
||||
}
|
||||
|
||||
static void save_contacts(const contacts_state_t *st) {
|
||||
char dir[512];
|
||||
snprintf(dir, sizeof(dir), "%s", st->path);
|
||||
char *sl = strrchr(dir, '/');
|
||||
if (sl) {
|
||||
*sl = '\0';
|
||||
const char *mk[] = {"mkdir", "-p", dir, NULL};
|
||||
gemui_run_cmd_capture(mk, NULL, 0);
|
||||
}
|
||||
FILE *f = fopen(st->path, "w");
|
||||
if (!f) return;
|
||||
for (int i = 0; i < st->num_items; i++) {
|
||||
fprintf(f, "%s\t%s\t%s\n", st->items[i].name, st->items[i].number, st->items[i].note);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static void select_contact(contacts_state_t *st, int idx) {
|
||||
st->sel_idx = idx;
|
||||
if (idx >= 0 && idx < st->num_items) {
|
||||
snprintf(st->edit_name, sizeof(st->edit_name), "%s", st->items[idx].name);
|
||||
snprintf(st->edit_phone, sizeof(st->edit_phone), "%s", st->items[idx].number);
|
||||
} else {
|
||||
st->edit_name[0] = '\0';
|
||||
st->edit_phone[0] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
|
||||
contacts_state_t *st = ud;
|
||||
const gemui_theme_t *t = gemui_theme(app);
|
||||
|
||||
char badge[48];
|
||||
snprintf(badge, sizeof(badge), "%d contacts", st->num_items);
|
||||
gemui_draw_header(app, cr, "\xef\x8a\xb9", "Geminux Contacts", badge);
|
||||
|
||||
int pad = 20;
|
||||
int top = 80;
|
||||
int left_w = (w - pad * 3) / 2;
|
||||
int right_x = pad * 2 + left_w;
|
||||
int right_w = w - right_x - pad;
|
||||
|
||||
gemui_draw_input(app, cr, (gemui_rect_t){pad, top, left_w - 148, 60},
|
||||
"Search name or number...", st->search, false,
|
||||
st->focus == 0, HIT_SEARCH, 0);
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad + left_w - 136, top, 136, 60},
|
||||
"+ New", HIT_NEW, 0, true, false, false);
|
||||
|
||||
gemui_rect_t list = {pad, top + 74, left_w, h - (top + 74) - pad};
|
||||
gemui_fill_round(cr, list, 12, t->bg_bar);
|
||||
gemui_stroke_round(cr, list, 12, 1.5, t->border);
|
||||
|
||||
if (st->num_filtered == 0) {
|
||||
gemui_draw_text(cr, t, list, "No matching contacts", 0, false,
|
||||
GEMUI_ALIGN_CENTER, t->fg_muted);
|
||||
} else {
|
||||
int rh = 72;
|
||||
for (int i = 0; i < st->num_filtered; i++) {
|
||||
int idx = st->filtered[i];
|
||||
gemui_rect_t rr = {list.x + 10, list.y + 8 + i * rh, list.w - 20, rh - 6};
|
||||
if (rr.y + rr.h > list.y + list.h) break;
|
||||
bool sel = (idx == st->sel_idx);
|
||||
gemui_fill_round(cr, rr, 10, sel ? t->sel_bg : (i % 2 ? t->bg_alt_odd : t->bg_alt_even));
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){rr.x + 14, rr.y + 4, rr.w - 28, 32},
|
||||
st->items[idx].name, -1, true, GEMUI_ALIGN_LEFT,
|
||||
sel ? t->sel_fg : t->fg_bright);
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){rr.x + 14, rr.y + 34, rr.w - 28, 28},
|
||||
st->items[idx].number, -2, false, GEMUI_ALIGN_LEFT,
|
||||
sel ? t->sel_fg : t->accent_alt);
|
||||
gemui_hit_add(app, rr, HIT_ROW, idx);
|
||||
}
|
||||
}
|
||||
|
||||
/* Right pane: details & editor */
|
||||
gemui_rect_t card = {right_x, top, right_w, h - top - pad};
|
||||
gemui_fill_round(cr, card, 14, t->bg_overlay);
|
||||
gemui_stroke_round(cr, card, 14, 1.5, t->border);
|
||||
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){card.x + 24, card.y + 20, card.w - 48, 36},
|
||||
st->sel_idx >= 0 ? "Edit Contact" : "New Contact",
|
||||
4, true, GEMUI_ALIGN_LEFT, t->fg_bright);
|
||||
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){card.x + 24, card.y + 74, card.w - 48, 30},
|
||||
"Full Name", -2, false, GEMUI_ALIGN_LEFT, t->fg_muted);
|
||||
gemui_draw_input(app, cr, (gemui_rect_t){card.x + 24, card.y + 108, card.w - 48, 66},
|
||||
"Enter contact name", st->edit_name, false,
|
||||
st->focus == 1, HIT_NAME, 0);
|
||||
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){card.x + 24, card.y + 194, card.w - 48, 30},
|
||||
"Phone Number", -2, false, GEMUI_ALIGN_LEFT, t->fg_muted);
|
||||
gemui_draw_input(app, cr, (gemui_rect_t){card.x + 24, card.y + 228, card.w - 48, 66},
|
||||
"+1...", st->edit_phone, false,
|
||||
st->focus == 2, HIT_PHONE, 0);
|
||||
|
||||
int bw = (card.w - 60) / 2;
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){card.x + 24, card.y + 324, bw, 72},
|
||||
"Save Contact", HIT_SAVE, 0, true, false, false);
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){card.x + 36 + bw, card.y + 324, bw, 72},
|
||||
"Delete", HIT_DEL, 0, false, false, false);
|
||||
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){card.x + 24, card.y + 420, bw, 76},
|
||||
"Call Contact", HIT_CALL, 0, false, st->edit_phone[0] != '\0', false);
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){card.x + 36 + bw, card.y + 420, bw, 76},
|
||||
"Send SMS", HIT_SMS, 0, false, false, false);
|
||||
}
|
||||
|
||||
static void save_current(contacts_state_t *st) {
|
||||
if (!st->edit_name[0] || !st->edit_phone[0]) {
|
||||
gemui_show_toast(st->app, "Both name and number are required", 1800);
|
||||
return;
|
||||
}
|
||||
if (st->sel_idx >= 0 && st->sel_idx < st->num_items) {
|
||||
snprintf(st->items[st->sel_idx].name, sizeof(st->items[0].name), "%s", st->edit_name);
|
||||
snprintf(st->items[st->sel_idx].number, sizeof(st->items[0].number), "%s", st->edit_phone);
|
||||
} else if (st->num_items < 128) {
|
||||
int idx = st->num_items++;
|
||||
snprintf(st->items[idx].name, sizeof(st->items[0].name), "%s", st->edit_name);
|
||||
snprintf(st->items[idx].number, sizeof(st->items[0].number), "%s", st->edit_phone);
|
||||
snprintf(st->items[idx].note, sizeof(st->items[0].note), "Mobile");
|
||||
st->sel_idx = idx;
|
||||
}
|
||||
save_contacts(st);
|
||||
apply_filter(st);
|
||||
gemui_show_toast(st->app, "Saved contact", 1600);
|
||||
gemui_request_redraw(st->app);
|
||||
}
|
||||
|
||||
static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *utf8, void *ud) {
|
||||
(void)state;
|
||||
contacts_state_t *st = ud;
|
||||
char *buf = (st->focus == 0) ? st->search : (st->focus == 1 ? st->edit_name : st->edit_phone);
|
||||
size_t sz = (st->focus == 2) ? sizeof(st->edit_phone) : sizeof(st->edit_name);
|
||||
|
||||
if (ks == XK_Escape) {
|
||||
gemui_quit(app, 0);
|
||||
} else if (ks == XK_Tab) {
|
||||
st->focus = (st->focus + 1) % 3;
|
||||
gemui_request_redraw(app);
|
||||
} else if (ks == XK_Return || ks == XK_KP_Enter) {
|
||||
if (st->focus == 1) {
|
||||
st->focus = 2;
|
||||
gemui_request_redraw(app);
|
||||
} else if (st->focus == 2) {
|
||||
save_current(st);
|
||||
}
|
||||
} else if (ks == XK_BackSpace) {
|
||||
gemui_utf8_pop_char(buf);
|
||||
if (st->focus == 0) apply_filter(st);
|
||||
gemui_request_redraw(app);
|
||||
} else if (utf8 && utf8[0]) {
|
||||
size_t cur = strlen(buf), add = strlen(utf8);
|
||||
if (cur + add < sz) {
|
||||
memcpy(buf + cur, utf8, add + 1);
|
||||
if (st->focus == 0) apply_filter(st);
|
||||
gemui_request_redraw(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, void *ud) {
|
||||
(void)btn;
|
||||
contacts_state_t *st = ud;
|
||||
if (type != GEMUI_PTR_DOWN) return;
|
||||
const gemui_hit_t *hit = gemui_hit_test(app, x, y);
|
||||
if (!hit) return;
|
||||
|
||||
if (hit->id == HIT_SEARCH) st->focus = 0;
|
||||
else if (hit->id == HIT_NAME) st->focus = 1;
|
||||
else if (hit->id == HIT_PHONE) st->focus = 2;
|
||||
else if (hit->id == HIT_NEW) {
|
||||
select_contact(st, -1);
|
||||
st->focus = 1;
|
||||
} else if (hit->id == HIT_ROW) {
|
||||
select_contact(st, hit->val);
|
||||
} else if (hit->id == HIT_SAVE) {
|
||||
save_current(st);
|
||||
} else if (hit->id == HIT_DEL && st->sel_idx >= 0 && st->sel_idx < st->num_items) {
|
||||
for (int i = st->sel_idx; i + 1 < st->num_items; i++) st->items[i] = st->items[i + 1];
|
||||
st->num_items--;
|
||||
save_contacts(st);
|
||||
apply_filter(st);
|
||||
select_contact(st, st->num_items > 0 ? 0 : -1);
|
||||
gemui_show_toast(app, "Contact deleted", 1600);
|
||||
} else if (hit->id == HIT_CALL && st->edit_phone[0]) {
|
||||
const char *argv[] = {"geminux-dialer", st->edit_phone, NULL};
|
||||
gemui_spawn_detached(argv);
|
||||
} else if (hit->id == HIT_SMS && st->edit_phone[0]) {
|
||||
const char *argv[] = {"geminux-sms", st->edit_phone, NULL};
|
||||
gemui_spawn_detached(argv);
|
||||
}
|
||||
gemui_request_redraw(app);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
contacts_state_t st;
|
||||
memset(&st, 0, sizeof(st));
|
||||
st.sel_idx = -1;
|
||||
const char *home = getenv("HOME");
|
||||
snprintf(st.path, sizeof(st.path), "%s/.local/share/geminux/contacts.tsv",
|
||||
(home && home[0]) ? home : "/home/user");
|
||||
load_contacts(&st);
|
||||
if (st.num_items > 0) select_contact(&st, 0);
|
||||
|
||||
st.app = gemui_create("geminux-contacts", "Geminux Contacts", 1640, 900, false);
|
||||
if (!st.app) return 1;
|
||||
|
||||
gemui_handlers_t h = { .on_draw = on_draw, .on_key = on_key, .on_ptr = on_ptr };
|
||||
gemui_set_handlers(st.app, &h, &st);
|
||||
int rc = gemui_run(st.app);
|
||||
gemui_destroy(st.app);
|
||||
return rc;
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "gemui.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define HIT_BRI 1
|
||||
#define HIT_VOL 2
|
||||
#define HIT_PROF 3
|
||||
#define HIT_LED 4
|
||||
#define HIT_LOCK 5
|
||||
#define HIT_SUSPEND 6
|
||||
#define HIT_REBOOT 7
|
||||
#define HIT_POWER 8
|
||||
|
||||
typedef struct {
|
||||
gemui_app_t *app;
|
||||
char bl_dir[256];
|
||||
int bl_cur;
|
||||
int bl_max;
|
||||
int vol_pct;
|
||||
int profile; /* 0=eco, 1=balanced, 2=performance */
|
||||
gemui_rect_t bri_rect;
|
||||
gemui_rect_t vol_rect;
|
||||
int active_drag;
|
||||
} ctrl_state_t;
|
||||
|
||||
static void detect_backlight(ctrl_state_t *st) {
|
||||
st->bl_dir[0] = '\0';
|
||||
st->bl_cur = 128;
|
||||
st->bl_max = 255;
|
||||
DIR *d = opendir("/sys/class/backlight");
|
||||
if (!d) return;
|
||||
struct dirent *de;
|
||||
while ((de = readdir(d)) != NULL) {
|
||||
if (de->d_name[0] == '.') continue;
|
||||
snprintf(st->bl_dir, sizeof(st->bl_dir), "/sys/class/backlight/%s", de->d_name);
|
||||
char b[64];
|
||||
char p[320];
|
||||
snprintf(p, sizeof(p), "%s/max_brightness", st->bl_dir);
|
||||
if (gemui_read_file_line(p, b, sizeof(b)) == 0 && atoi(b) > 0) st->bl_max = atoi(b);
|
||||
snprintf(p, sizeof(p), "%s/brightness", st->bl_dir);
|
||||
if (gemui_read_file_line(p, b, sizeof(b)) == 0) st->bl_cur = atoi(b);
|
||||
break;
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
static void refresh_hw(ctrl_state_t *st) {
|
||||
detect_backlight(st);
|
||||
char out[128] = {0};
|
||||
const char *vcmd[] = {"wpctl", "get-volume", "@DEFAULT_AUDIO_SINK@", NULL};
|
||||
if (gemui_run_cmd_capture(vcmd, out, sizeof(out)) == 0) {
|
||||
char *p = strstr(out, "Volume:");
|
||||
if (p) st->vol_pct = (int)(atof(p + 7) * 100.0 + 0.5);
|
||||
}
|
||||
char prof[64] = {0};
|
||||
if (gemui_read_file_line("/run/geminux/power-profile", prof, sizeof(prof)) == 0) {
|
||||
if (strcmp(prof, "eco") == 0) st->profile = 0;
|
||||
else if (strcmp(prof, "performance") == 0) st->profile = 2;
|
||||
else st->profile = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void set_brightness_norm(ctrl_state_t *st, double norm) {
|
||||
if (norm < 0.05) norm = 0.05;
|
||||
if (norm > 1.0) norm = 1.0;
|
||||
st->bl_cur = (int)(norm * st->bl_max);
|
||||
int pct = (int)(norm * 100.0 + 0.5);
|
||||
char arg[32];
|
||||
snprintf(arg, sizeof(arg), "%d%%", pct);
|
||||
const char *cmd[] = {"brightnessctl", "set", arg, NULL};
|
||||
gemui_run_cmd_capture(cmd, NULL, 0);
|
||||
gemui_request_redraw(st->app);
|
||||
}
|
||||
|
||||
static void set_volume_norm(ctrl_state_t *st, double norm) {
|
||||
if (norm < 0.0) norm = 0.0;
|
||||
if (norm > 1.0) norm = 1.0;
|
||||
st->vol_pct = (int)(norm * 100.0 + 0.5);
|
||||
char arg[32];
|
||||
snprintf(arg, sizeof(arg), "%d%%", st->vol_pct);
|
||||
const char *cmd[] = {"wpctl", "set-volume", "@DEFAULT_AUDIO_SINK@", arg, NULL};
|
||||
gemui_run_cmd_capture(cmd, NULL, 0);
|
||||
const char *pk[] = {"pkill", "-USR1", "geminux-statusd", NULL};
|
||||
gemui_run_cmd_capture(pk, NULL, 0);
|
||||
gemui_request_redraw(st->app);
|
||||
}
|
||||
|
||||
static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
|
||||
ctrl_state_t *st = ud;
|
||||
const gemui_theme_t *t = gemui_theme(app);
|
||||
|
||||
gemui_draw_header(app, cr, "\xef\x80\x93", "Geminux Control Center", "Power, Audio, Display & LEDs");
|
||||
|
||||
int pad = 24;
|
||||
int cw = (w - pad * 2);
|
||||
|
||||
st->bri_rect = (gemui_rect_t){pad, 88, cw, 92};
|
||||
char btxt[32];
|
||||
double bnorm = st->bl_max > 0 ? (double)st->bl_cur / st->bl_max : 0.5;
|
||||
snprintf(btxt, sizeof(btxt), "%d%%", (int)(bnorm * 100.0 + 0.5));
|
||||
gemui_draw_slider(app, cr, st->bri_rect, "Display Backlight", bnorm, btxt, HIT_BRI, 0, false);
|
||||
|
||||
st->vol_rect = (gemui_rect_t){pad, 196, cw, 92};
|
||||
char vtxt[32];
|
||||
snprintf(vtxt, sizeof(vtxt), "%d%%", st->vol_pct);
|
||||
gemui_draw_slider(app, cr, st->vol_rect, "Master Audio Volume", st->vol_pct / 100.0, vtxt, HIT_VOL, 0, false);
|
||||
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){pad, 308, cw, 34},
|
||||
"MT6797X Power Profile (A72 Big Cluster + Schedutil)",
|
||||
-1, true, GEMUI_ALIGN_LEFT, t->fg_bright);
|
||||
int pw = (cw - 24) / 3;
|
||||
static const char *profs[3] = {"Eco (A53 Only)", "Balanced", "Performance (10-Core)"};
|
||||
for (int i = 0; i < 3; i++) {
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad + i * (pw + 12), 348, pw, 72},
|
||||
profs[i], HIT_PROF, i, false, st->profile == i, false);
|
||||
}
|
||||
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){pad, 444, cw, 34},
|
||||
"AW9120 LED Strip Indicator", -1, true, GEMUI_ALIGN_LEFT, t->fg_bright);
|
||||
int lw = (cw - 36) / 4;
|
||||
static const char *leds[4] = {"Off", "Cyan Pulse", "Green OK", "Amber Warn"};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad + i * (lw + 12), 484, lw, 68},
|
||||
leds[i], HIT_LED, i, false, false, false);
|
||||
}
|
||||
|
||||
int ay = h - 104;
|
||||
int aw = (cw - 36) / 4;
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad, ay, aw, 78},
|
||||
"Lock Screen", HIT_LOCK, 0, false, false, false);
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad + aw + 12, ay, aw, 78},
|
||||
"Suspend Now", HIT_SUSPEND, 0, true, false, false);
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad + 2 * (aw + 12), ay, aw, 78},
|
||||
"Reboot", HIT_REBOOT, 0, false, false, false);
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad + 3 * (aw + 12), ay, aw, 78},
|
||||
"Power Off", HIT_POWER, 0, false, false, false);
|
||||
}
|
||||
|
||||
static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *utf8, void *ud) {
|
||||
(void)state;
|
||||
(void)utf8;
|
||||
ctrl_state_t *st = ud;
|
||||
if (ks == XK_Escape || ks == XK_q) gemui_quit(app, 0);
|
||||
else if (ks == XK_Left) set_brightness_norm(st, ((double)st->bl_cur / st->bl_max) - 0.1);
|
||||
else if (ks == XK_Right) set_brightness_norm(st, ((double)st->bl_cur / st->bl_max) + 0.1);
|
||||
}
|
||||
|
||||
static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, void *ud) {
|
||||
(void)btn;
|
||||
ctrl_state_t *st = ud;
|
||||
if (type == GEMUI_PTR_UP) {
|
||||
st->active_drag = 0;
|
||||
return;
|
||||
}
|
||||
if (type == GEMUI_PTR_MOVE) {
|
||||
if (st->active_drag == HIT_BRI) {
|
||||
set_brightness_norm(st, (double)(x - st->bri_rect.x - 16) / (st->bri_rect.w - 32));
|
||||
} else if (st->active_drag == HIT_VOL) {
|
||||
set_volume_norm(st, (double)(x - st->vol_rect.x - 16) / (st->vol_rect.w - 32));
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (type != GEMUI_PTR_DOWN) return;
|
||||
|
||||
const gemui_hit_t *hit = gemui_hit_test(app, x, y);
|
||||
if (!hit) return;
|
||||
|
||||
if (hit->id == HIT_BRI) {
|
||||
st->active_drag = HIT_BRI;
|
||||
set_brightness_norm(st, (double)(x - st->bri_rect.x - 16) / (st->bri_rect.w - 32));
|
||||
} else if (hit->id == HIT_VOL) {
|
||||
st->active_drag = HIT_VOL;
|
||||
set_volume_norm(st, (double)(x - st->vol_rect.x - 16) / (st->vol_rect.w - 32));
|
||||
} else if (hit->id == HIT_PROF) {
|
||||
static const char *pnames[3] = {"eco", "balanced", "performance"};
|
||||
st->profile = hit->val;
|
||||
const char *cmd[] = {"doas", "/usr/bin/geminux-power-ctl", "profile", pnames[hit->val], NULL};
|
||||
gemui_run_cmd_capture(cmd, NULL, 0);
|
||||
gemui_show_toast(app, "Updated power profile", 1600);
|
||||
gemui_request_redraw(app);
|
||||
} else if (hit->id == HIT_LED) {
|
||||
static const char *lcmds[4] = {"off", "rgb 0 40 60", "rgb 0 64 16", "rgb 64 40 0"};
|
||||
gemui_unix_cmd("/run/geminux/leds.sock", lcmds[hit->val], NULL, 0);
|
||||
gemui_show_toast(app, "Updated AW9120 LED state", 1400);
|
||||
} else if (hit->id == HIT_LOCK) {
|
||||
const char *cmd[] = {"geminux-lock", NULL};
|
||||
gemui_spawn_detached(cmd);
|
||||
gemui_quit(app, 0);
|
||||
} else if (hit->id == HIT_SUSPEND) {
|
||||
const char *cmd[] = {"doas", "/usr/bin/geminux-power-ctl", "suspend", NULL};
|
||||
gemui_spawn_detached(cmd);
|
||||
gemui_quit(app, 0);
|
||||
} else if (hit->id == HIT_REBOOT) {
|
||||
const char *cmd[] = {"doas", "/sbin/reboot", NULL};
|
||||
gemui_run_cmd_capture(cmd, NULL, 0);
|
||||
} else if (hit->id == HIT_POWER) {
|
||||
const char *cmd[] = {"doas", "/sbin/poweroff", NULL};
|
||||
gemui_run_cmd_capture(cmd, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
ctrl_state_t st;
|
||||
memset(&st, 0, sizeof(st));
|
||||
st.vol_pct = 50;
|
||||
st.profile = 1;
|
||||
refresh_hw(&st);
|
||||
|
||||
st.app = gemui_create("geminux-control", "Geminux Control Center", 1480, 720, false);
|
||||
if (!st.app) return 1;
|
||||
|
||||
gemui_handlers_t h = { .on_draw = on_draw, .on_key = on_key, .on_ptr = on_ptr };
|
||||
gemui_set_handlers(st.app, &h, &st);
|
||||
int rc = gemui_run(st.app);
|
||||
gemui_destroy(st.app);
|
||||
return rc;
|
||||
}
|
||||
@@ -0,0 +1,310 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "gemui.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#define HIT_DIGIT 1
|
||||
#define HIT_BACK 2
|
||||
#define HIT_CLEAR 3
|
||||
#define HIT_DIAL 4
|
||||
#define HIT_RECENT 5
|
||||
#define HIT_CONTACT 6
|
||||
#define HIT_SMS 7
|
||||
|
||||
typedef struct {
|
||||
char name[64];
|
||||
char number[48];
|
||||
char detail[64];
|
||||
} entry_t;
|
||||
|
||||
typedef struct {
|
||||
gemui_app_t *app;
|
||||
char number[64];
|
||||
char modem_status[128];
|
||||
entry_t recents[32];
|
||||
int num_recents;
|
||||
entry_t contacts[32];
|
||||
int num_contacts;
|
||||
int list_tab; /* 0 = recents, 1 = contacts */
|
||||
int selected;
|
||||
} dialer_state_t;
|
||||
|
||||
static void get_data_path(const char *rel, char *out, size_t sz) {
|
||||
const char *home = getenv("HOME");
|
||||
snprintf(out, sz, "%s/.local/share/geminux/%s",
|
||||
(home && home[0]) ? home : "/home/user", rel);
|
||||
}
|
||||
|
||||
static void load_tsv_entries(const char *rel, entry_t *arr, int max_n, int *out_n) {
|
||||
*out_n = 0;
|
||||
char path[512];
|
||||
get_data_path(rel, path, sizeof(path));
|
||||
FILE *f = fopen(path, "r");
|
||||
if (!f) return;
|
||||
char line[256];
|
||||
while (fgets(line, sizeof(line), f) && *out_n < max_n) {
|
||||
size_t len = strlen(line);
|
||||
while (len > 0 && (line[len - 1] == '\n' || line[len - 1] == '\r')) line[--len] = '\0';
|
||||
if (!line[0] || line[0] == '#') continue;
|
||||
char *tab1 = strchr(line, '\t');
|
||||
if (!tab1) continue;
|
||||
*tab1 = '\0';
|
||||
char *col2 = tab1 + 1;
|
||||
char *tab2 = strchr(col2, '\t');
|
||||
if (tab2) *tab2 = '\0';
|
||||
entry_t *e = &arr[(*out_n)++];
|
||||
snprintf(e->name, sizeof(e->name), "%s", line);
|
||||
snprintf(e->number, sizeof(e->number), "%s", col2);
|
||||
snprintf(e->detail, sizeof(e->detail), "%s", tab2 ? (tab2 + 1) : "");
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static void append_recent(const char *number) {
|
||||
char dir[512], path[512];
|
||||
get_data_path("", dir, sizeof(dir));
|
||||
const char *mk[] = {"mkdir", "-p", dir, NULL};
|
||||
gemui_run_cmd_capture(mk, NULL, 0);
|
||||
get_data_path("calllog.tsv", path, sizeof(path));
|
||||
FILE *f = fopen(path, "a");
|
||||
if (!f) return;
|
||||
time_t now = time(NULL);
|
||||
struct tm tm;
|
||||
localtime_r(&now, &tm);
|
||||
char ts[32];
|
||||
strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M", &tm);
|
||||
fprintf(f, "%s\t%s\tOutgoing\n", ts, number);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static void refresh_state(dialer_state_t *st) {
|
||||
if (gemui_read_file_line("/run/geminux/modem-state",
|
||||
st->modem_status, sizeof(st->modem_status)) != 0) {
|
||||
snprintf(st->modem_status, sizeof(st->modem_status), "MODEM READY");
|
||||
}
|
||||
load_tsv_entries("calllog.tsv", st->recents, 32, &st->num_recents);
|
||||
load_tsv_entries("contacts.tsv", st->contacts, 32, &st->num_contacts);
|
||||
}
|
||||
|
||||
static void trigger_dial(dialer_state_t *st) {
|
||||
if (!st->number[0]) {
|
||||
gemui_show_toast(st->app, "Enter a phone number first", 1800);
|
||||
return;
|
||||
}
|
||||
append_recent(st->number);
|
||||
load_tsv_entries("calllog.tsv", st->recents, 32, &st->num_recents);
|
||||
|
||||
char cmd[128], resp[128];
|
||||
snprintf(cmd, sizeof(cmd), "dial %s", st->number);
|
||||
if (gemui_unix_cmd("/run/geminux/modem.sock", cmd, resp, sizeof(resp)) != 0) {
|
||||
/* Fallback to ModemManager CLI if modem daemon is not active */
|
||||
char arg[128];
|
||||
snprintf(arg, sizeof(arg), "number=%s", st->number);
|
||||
const char *mm[] = {"mmcli", "-m", "0", "--voice-create-call", arg, NULL};
|
||||
gemui_run_cmd_capture(mm, resp, sizeof(resp));
|
||||
}
|
||||
const char *cs[] = {"geminux-callscreen", st->number, NULL};
|
||||
gemui_spawn_detached(cs);
|
||||
gemui_show_toast(st->app, "Dialing via MT6797 CCCI modem...", 2200);
|
||||
gemui_request_redraw(st->app);
|
||||
}
|
||||
|
||||
static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
|
||||
dialer_state_t *st = ud;
|
||||
const gemui_theme_t *t = gemui_theme(app);
|
||||
|
||||
gemui_draw_header(app, cr, "\xef\x82\x95", "Geminux Dialer", st->modem_status);
|
||||
|
||||
int pad = 20;
|
||||
int top = 80;
|
||||
int left_w = (w - pad * 3) / 2;
|
||||
int right_x = pad * 2 + left_w;
|
||||
int right_w = w - right_x - pad;
|
||||
|
||||
/* Number input box */
|
||||
gemui_rect_t disp = {pad, top, left_w, 80};
|
||||
gemui_fill_round(cr, disp, 12, t->bg_input_focus);
|
||||
gemui_stroke_round(cr, disp, 12, 2.0, t->accent);
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){disp.x + 18, disp.y, disp.w - 130, disp.h},
|
||||
st->number[0] ? st->number : "Type or tap number...",
|
||||
10, true, GEMUI_ALIGN_LEFT,
|
||||
st->number[0] ? t->fg_bright : t->fg_muted);
|
||||
|
||||
gemui_rect_t clr = {disp.x + disp.w - 108, disp.y + 10, 96, 60};
|
||||
gemui_draw_button(app, cr, clr, "CLR", HIT_CLEAR, 0, false, false, false);
|
||||
|
||||
/* DTMF 4x3 keypad + Back/Dial action bar */
|
||||
static const char *keys[12] = {
|
||||
"1", "2 ABC", "3 DEF",
|
||||
"4 GHI", "5 JKL", "6 MNO",
|
||||
"7 PQRS", "8 TUV", "9 WXYZ",
|
||||
"*", "0 +", "#"
|
||||
};
|
||||
int kp_top = top + 96;
|
||||
int btn_h = (h - kp_top - 104 - 3 * 12) / 4;
|
||||
if (btn_h < 64) btn_h = 64;
|
||||
int btn_w = (left_w - 2 * 12) / 3;
|
||||
|
||||
for (int i = 0; i < 12; i++) {
|
||||
int col = i % 3;
|
||||
int row = i / 3;
|
||||
gemui_rect_t br = {
|
||||
pad + col * (btn_w + 12),
|
||||
kp_top + row * (btn_h + 12),
|
||||
btn_w,
|
||||
btn_h
|
||||
};
|
||||
gemui_draw_button(app, cr, br, keys[i], HIT_DIGIT, i, false, false, false);
|
||||
}
|
||||
|
||||
int act_y = h - 88;
|
||||
int third = (left_w - 24) / 3;
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad, act_y, third, 68},
|
||||
"Backspace", HIT_BACK, 0, false, false, false);
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad + third + 12, act_y, third, 68},
|
||||
"Send SMS", HIT_SMS, 0, false, false, false);
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad + 2 * (third + 12), act_y,
|
||||
left_w - 2 * (third + 12), 68},
|
||||
"Call Now", HIT_DIAL, 0, true, false, false);
|
||||
|
||||
/* Right panel: Recents / Contacts tabs */
|
||||
int tab_w = (right_w - 12) / 2;
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){right_x, top, tab_w, 60},
|
||||
"Recent Calls", HIT_RECENT, -1, false, st->list_tab == 0, false);
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){right_x + tab_w + 12, top, tab_w, 60},
|
||||
"Contacts", HIT_CONTACT, -1, false, st->list_tab == 1, false);
|
||||
|
||||
gemui_rect_t list_box = {right_x, top + 74, right_w, h - (top + 74) - 20};
|
||||
gemui_fill_round(cr, list_box, 12, t->bg_bar);
|
||||
gemui_stroke_round(cr, list_box, 12, 1.5, t->border);
|
||||
|
||||
entry_t *arr = (st->list_tab == 0) ? st->recents : st->contacts;
|
||||
int count = (st->list_tab == 0) ? st->num_recents : st->num_contacts;
|
||||
if (count == 0) {
|
||||
gemui_draw_text(cr, t, list_box,
|
||||
st->list_tab == 0 ? "No recent calls recorded" : "No contacts in contacts.tsv",
|
||||
0, false, GEMUI_ALIGN_CENTER, t->fg_muted);
|
||||
return;
|
||||
}
|
||||
|
||||
int row_h = 72;
|
||||
int max_rows = (list_box.h - 16) / row_h;
|
||||
for (int i = 0; i < count && i < max_rows; i++) {
|
||||
int idx = (st->list_tab == 0) ? (count - 1 - i) : i;
|
||||
gemui_rect_t rr = {list_box.x + 10, list_box.y + 8 + i * row_h, list_box.w - 20, row_h - 6};
|
||||
bool sel = (idx == st->selected);
|
||||
gemui_fill_round(cr, rr, 10, sel ? t->sel_bg : (i % 2 ? t->bg_alt_odd : t->bg_alt_even));
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){rr.x + 14, rr.y + 4, rr.w - 220, 32},
|
||||
arr[idx].name, -1, true, GEMUI_ALIGN_LEFT,
|
||||
sel ? t->sel_fg : t->fg_bright);
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){rr.x + 14, rr.y + 34, rr.w - 220, 28},
|
||||
arr[idx].number, -2, false, GEMUI_ALIGN_LEFT,
|
||||
sel ? t->sel_fg : t->accent_alt);
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){rr.x + rr.w - 200, rr.y, 186, rr.h},
|
||||
arr[idx].detail, -3, false, GEMUI_ALIGN_RIGHT,
|
||||
sel ? t->sel_fg : t->fg_muted);
|
||||
gemui_hit_add(app, rr, (st->list_tab == 0) ? HIT_RECENT : HIT_CONTACT, idx);
|
||||
}
|
||||
}
|
||||
|
||||
static void append_digit(dialer_state_t *st, char ch) {
|
||||
size_t len = strlen(st->number);
|
||||
if (len + 1 < sizeof(st->number)) {
|
||||
st->number[len] = ch;
|
||||
st->number[len + 1] = '\0';
|
||||
gemui_request_redraw(st->app);
|
||||
}
|
||||
}
|
||||
|
||||
static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *utf8, void *ud) {
|
||||
(void)state;
|
||||
dialer_state_t *st = ud;
|
||||
if (ks == XK_Escape || ks == XK_q) {
|
||||
gemui_quit(app, 0);
|
||||
return;
|
||||
}
|
||||
if (ks == XK_Return || ks == XK_KP_Enter) {
|
||||
trigger_dial(st);
|
||||
return;
|
||||
}
|
||||
if (ks == XK_BackSpace) {
|
||||
gemui_utf8_pop_char(st->number);
|
||||
gemui_request_redraw(app);
|
||||
return;
|
||||
}
|
||||
if (ks == XK_Tab) {
|
||||
st->list_tab = 1 - st->list_tab;
|
||||
st->selected = -1;
|
||||
gemui_request_redraw(app);
|
||||
return;
|
||||
}
|
||||
if (utf8 && utf8[0]) {
|
||||
char c = utf8[0];
|
||||
if (isdigit((unsigned char)c) || c == '+' || c == '*' || c == '#') {
|
||||
append_digit(st, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, void *ud) {
|
||||
(void)btn;
|
||||
dialer_state_t *st = ud;
|
||||
if (type != GEMUI_PTR_DOWN) return;
|
||||
const gemui_hit_t *hit = gemui_hit_test(app, x, y);
|
||||
if (!hit) return;
|
||||
|
||||
if (hit->id == HIT_DIGIT) {
|
||||
static const char map[12] = {'1','2','3','4','5','6','7','8','9','*','0','#'};
|
||||
if (hit->val >= 0 && hit->val < 12) append_digit(st, map[hit->val]);
|
||||
} else if (hit->id == HIT_BACK) {
|
||||
gemui_utf8_pop_char(st->number);
|
||||
gemui_request_redraw(app);
|
||||
} else if (hit->id == HIT_CLEAR) {
|
||||
st->number[0] = '\0';
|
||||
gemui_request_redraw(app);
|
||||
} else if (hit->id == HIT_DIAL) {
|
||||
trigger_dial(st);
|
||||
} else if (hit->id == HIT_SMS) {
|
||||
const char *argv[] = {"geminux-sms", st->number[0] ? st->number : NULL, NULL};
|
||||
gemui_spawn_detached(argv);
|
||||
} else if (hit->id == HIT_RECENT) {
|
||||
if (hit->val < 0) {
|
||||
st->list_tab = 0;
|
||||
} else if (hit->val < st->num_recents) {
|
||||
st->selected = hit->val;
|
||||
snprintf(st->number, sizeof(st->number), "%s", st->recents[hit->val].number);
|
||||
}
|
||||
gemui_request_redraw(app);
|
||||
} else if (hit->id == HIT_CONTACT) {
|
||||
if (hit->val < 0) {
|
||||
st->list_tab = 1;
|
||||
} else if (hit->val < st->num_contacts) {
|
||||
st->selected = hit->val;
|
||||
snprintf(st->number, sizeof(st->number), "%s", st->contacts[hit->val].number);
|
||||
}
|
||||
gemui_request_redraw(app);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
dialer_state_t st;
|
||||
memset(&st, 0, sizeof(st));
|
||||
st.selected = -1;
|
||||
if (argc > 1 && argv[1][0]) {
|
||||
snprintf(st.number, sizeof(st.number), "%s", argv[1]);
|
||||
}
|
||||
refresh_state(&st);
|
||||
|
||||
st.app = gemui_create("geminux-dialer", "Geminux Dialer", 1600, 900, false);
|
||||
if (!st.app) return 1;
|
||||
|
||||
gemui_handlers_t h = { .on_draw = on_draw, .on_key = on_key, .on_ptr = on_ptr };
|
||||
gemui_set_handlers(st.app, &h, &st);
|
||||
int rc = gemui_run(st.app);
|
||||
gemui_destroy(st.app);
|
||||
return rc;
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "gemui.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define HIT_UNLOCK 1
|
||||
#define HIT_CLEAR 2
|
||||
|
||||
typedef struct {
|
||||
gemui_app_t *app;
|
||||
char user[64];
|
||||
char password[128];
|
||||
char bat_text[96];
|
||||
char err_msg[96];
|
||||
bool grabbed;
|
||||
bool checking;
|
||||
} lock_state_t;
|
||||
|
||||
static void refresh_battery(lock_state_t *st) {
|
||||
snprintf(st->bat_text, sizeof(st->bat_text), "Battery: N/A");
|
||||
DIR *d = opendir("/sys/class/power_supply");
|
||||
if (!d) return;
|
||||
struct dirent *de;
|
||||
while ((de = readdir(d)) != NULL) {
|
||||
if (de->d_name[0] == '.') continue;
|
||||
char p[320], typ[32] = {0}, cap[32] = {0}, bstat[32] = {0};
|
||||
snprintf(p, sizeof(p), "/sys/class/power_supply/%s/type", de->d_name);
|
||||
if (gemui_read_file_line(p, typ, sizeof(typ)) != 0 || strcmp(typ, "Battery") != 0) continue;
|
||||
snprintf(p, sizeof(p), "/sys/class/power_supply/%s/capacity", de->d_name);
|
||||
gemui_read_file_line(p, cap, sizeof(cap));
|
||||
snprintf(p, sizeof(p), "/sys/class/power_supply/%s/status", de->d_name);
|
||||
gemui_read_file_line(p, bstat, sizeof(bstat));
|
||||
snprintf(st->bat_text, sizeof(st->bat_text), "Battery %s%% (%s)",
|
||||
cap[0] ? cap : "?", bstat[0] ? bstat : "Idle");
|
||||
break;
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
static bool verify_password(const char *user, const char *pass) {
|
||||
int pfd[2];
|
||||
if (pipe(pfd) < 0) return false;
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) {
|
||||
close(pfd[0]);
|
||||
close(pfd[1]);
|
||||
return false;
|
||||
}
|
||||
if (pid == 0) {
|
||||
close(pfd[1]);
|
||||
dup2(pfd[0], STDIN_FILENO);
|
||||
close(pfd[0]);
|
||||
if (geteuid() == 0) {
|
||||
const char *argv[] = {"/usr/sbin/geminux-checkpw", NULL};
|
||||
execv(argv[0], (char *const *)argv);
|
||||
} else {
|
||||
const char *argv[] = {"doas", "-n", "/usr/sbin/geminux-checkpw", NULL};
|
||||
execvp(argv[0], (char *const *)argv);
|
||||
}
|
||||
_exit(127);
|
||||
}
|
||||
close(pfd[0]);
|
||||
dprintf(pfd[1], "%s\n%s\n", user, pass);
|
||||
close(pfd[1]);
|
||||
|
||||
int status = 0;
|
||||
if (waitpid(pid, &status, 0) < 0) return false;
|
||||
return WIFEXITED(status) && WEXITSTATUS(status) == 0;
|
||||
}
|
||||
|
||||
static void attempt_unlock(lock_state_t *st) {
|
||||
if (!st->password[0]) {
|
||||
snprintf(st->err_msg, sizeof(st->err_msg), "Enter password to unlock");
|
||||
gemui_request_redraw(st->app);
|
||||
return;
|
||||
}
|
||||
st->checking = true;
|
||||
if (verify_password(st->user, st->password)) {
|
||||
memset(st->password, 0, sizeof(st->password));
|
||||
gemui_ungrab_input(st->app);
|
||||
gemui_quit(st->app, 0);
|
||||
return;
|
||||
}
|
||||
memset(st->password, 0, sizeof(st->password));
|
||||
st->checking = false;
|
||||
snprintf(st->err_msg, sizeof(st->err_msg), "Incorrect password for %s", st->user);
|
||||
gemui_request_redraw(st->app);
|
||||
}
|
||||
|
||||
static void on_timer(gemui_app_t *app, void *ud) {
|
||||
lock_state_t *st = ud;
|
||||
if (!st->grabbed) {
|
||||
st->grabbed = gemui_grab_input(app);
|
||||
}
|
||||
refresh_battery(st);
|
||||
gemui_request_redraw(app);
|
||||
}
|
||||
|
||||
static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
|
||||
lock_state_t *st = ud;
|
||||
const gemui_theme_t *t = gemui_theme(app);
|
||||
|
||||
gemui_fill_rect(cr, (gemui_rect_t){0, 0, w, h}, t->bg_main);
|
||||
|
||||
time_t now = time(NULL);
|
||||
struct tm tm;
|
||||
localtime_r(&now, &tm);
|
||||
char clock_str[32], date_str[64];
|
||||
strftime(clock_str, sizeof(clock_str), "%H:%M", &tm);
|
||||
strftime(date_str, sizeof(date_str), "%A, %d %B %Y", &tm);
|
||||
|
||||
int cw = 760;
|
||||
if (cw > w - 80) cw = w - 80;
|
||||
gemui_rect_t card = {(w - cw) / 2, (h - 520) / 2, cw, 520};
|
||||
gemui_fill_round(cr, card, 18, t->bg_overlay);
|
||||
gemui_stroke_round(cr, card, 18, 2.0, t->border);
|
||||
|
||||
gemui_draw_icon(cr, t, (gemui_rect_t){card.x, card.y + 28, card.w, 52},
|
||||
"\xef\x80\xa3", 14, GEMUI_ALIGN_CENTER, t->accent);
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){card.x + 24, card.y + 84, card.w - 48, 84},
|
||||
clock_str, 26, true, GEMUI_ALIGN_CENTER, t->fg_bright);
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){card.x + 24, card.y + 172, card.w - 48, 40},
|
||||
date_str, 2, false, GEMUI_ALIGN_CENTER, t->fg_muted);
|
||||
|
||||
char status[128];
|
||||
snprintf(status, sizeof(status), "%s | User: %s", st->bat_text, st->user);
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){card.x + 24, card.y + 220, card.w - 48, 36},
|
||||
status, -1, false, GEMUI_ALIGN_CENTER, t->accent_alt);
|
||||
|
||||
gemui_draw_input(app, cr, (gemui_rect_t){card.x + 48, card.y + 280, card.w - 96, 72},
|
||||
"Type password and press Enter...", st->password, true, true, -1, 0);
|
||||
|
||||
if (st->err_msg[0]) {
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){card.x + 48, card.y + 362, card.w - 96, 36},
|
||||
st->err_msg, -1, true, GEMUI_ALIGN_CENTER, t->danger);
|
||||
}
|
||||
|
||||
int bw = (card.w - 112) / 2;
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){card.x + 48, card.y + 414, bw, 72},
|
||||
"Clear", HIT_CLEAR, 0, false, false, false);
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){card.x + 64 + bw, card.y + 414, bw, 72},
|
||||
"Unlock", HIT_UNLOCK, 0, true, false, false);
|
||||
}
|
||||
|
||||
static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *utf8, void *ud) {
|
||||
(void)state;
|
||||
lock_state_t *st = ud;
|
||||
if (ks == XK_Return || ks == XK_KP_Enter) {
|
||||
attempt_unlock(st);
|
||||
} else if (ks == XK_BackSpace) {
|
||||
gemui_utf8_pop_char(st->password);
|
||||
gemui_request_redraw(app);
|
||||
} else if (ks == XK_Escape) {
|
||||
memset(st->password, 0, sizeof(st->password));
|
||||
st->err_msg[0] = '\0';
|
||||
gemui_request_redraw(app);
|
||||
} else if (utf8 && utf8[0]) {
|
||||
size_t cur = strlen(st->password), add = strlen(utf8);
|
||||
if (cur + add < sizeof(st->password)) {
|
||||
memcpy(st->password + cur, utf8, add + 1);
|
||||
st->err_msg[0] = '\0';
|
||||
gemui_request_redraw(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, void *ud) {
|
||||
(void)btn;
|
||||
lock_state_t *st = ud;
|
||||
if (type != GEMUI_PTR_DOWN) return;
|
||||
const gemui_hit_t *hit = gemui_hit_test(app, x, y);
|
||||
if (!hit) return;
|
||||
if (hit->id == HIT_CLEAR) {
|
||||
memset(st->password, 0, sizeof(st->password));
|
||||
st->err_msg[0] = '\0';
|
||||
gemui_request_redraw(app);
|
||||
} else if (hit->id == HIT_UNLOCK) {
|
||||
attempt_unlock(st);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
lock_state_t st;
|
||||
memset(&st, 0, sizeof(st));
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
snprintf(st.user, sizeof(st.user), "%s", (pw && pw->pw_name) ? pw->pw_name : "user");
|
||||
refresh_battery(&st);
|
||||
|
||||
st.app = gemui_create("geminux-lock", "Geminux Lock Screen", 0, 0, true);
|
||||
if (!st.app) return 1;
|
||||
st.grabbed = gemui_grab_input(st.app);
|
||||
|
||||
gemui_handlers_t h = { .on_draw = on_draw, .on_key = on_key, .on_ptr = on_ptr };
|
||||
gemui_set_handlers(st.app, &h, &st);
|
||||
gemui_set_timer_ms(st.app, 1000, on_timer, &st);
|
||||
int rc = gemui_run(st.app);
|
||||
gemui_ungrab_input(st.app);
|
||||
gemui_destroy(st.app);
|
||||
return rc;
|
||||
}
|
||||
@@ -0,0 +1,304 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "gemui.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define HIT_TAB 1
|
||||
#define HIT_TOGGLE 2
|
||||
#define HIT_ACTION 3
|
||||
#define HIT_ROW 4
|
||||
#define HIT_PSK 5
|
||||
#define HIT_CONNECT 6
|
||||
|
||||
typedef struct {
|
||||
char col1[96];
|
||||
char col2[96];
|
||||
char col3[48];
|
||||
} net_row_t;
|
||||
|
||||
typedef struct {
|
||||
gemui_app_t *app;
|
||||
int tab; /* 0=Wi-Fi, 1=Cellular/4G, 2=Bluetooth, 3=USB/HDMI */
|
||||
bool wifi_on;
|
||||
bool cellular_on;
|
||||
bool bt_on;
|
||||
bool hdmi_on;
|
||||
net_row_t rows[32];
|
||||
int num_rows;
|
||||
int sel_row;
|
||||
char status_text[256];
|
||||
char psk[128];
|
||||
bool focus_psk;
|
||||
} net_state_t;
|
||||
|
||||
static void refresh_tab(net_state_t *st) {
|
||||
st->num_rows = 0;
|
||||
st->sel_row = -1;
|
||||
char out[4096] = {0};
|
||||
|
||||
const char *wargv[] = {"nmcli", "-t", "-f", "WIFI", "general", NULL};
|
||||
if (gemui_run_cmd_capture(wargv, out, sizeof(out)) == 0) {
|
||||
st->wifi_on = strstr(out, "enabled") != NULL;
|
||||
}
|
||||
|
||||
if (st->tab == 0) {
|
||||
const char *scan[] = {"nmcli", "-t", "-f", "IN-USE,SSID,SIGNAL,SECURITY", "dev", "wifi", "list", NULL};
|
||||
if (gemui_run_cmd_capture(scan, out, sizeof(out)) == 0) {
|
||||
char *save = NULL;
|
||||
for (char *ln = strtok_r(out, "\n", &save); ln && st->num_rows < 32; ln = strtok_r(NULL, "\n", &save)) {
|
||||
char *c1 = strchr(ln, ':');
|
||||
char *c2 = c1 ? strchr(c1 + 1, ':') : NULL;
|
||||
char *c3 = c2 ? strchr(c2 + 1, ':') : NULL;
|
||||
if (!c1 || !c2 || !c3) continue;
|
||||
*c1 = *c2 = *c3 = '\0';
|
||||
net_row_t *r = &st->rows[st->num_rows++];
|
||||
snprintf(r->col1, sizeof(r->col1), "%s%s", (ln[0] == '*') ? "* " : "", c1 + 1);
|
||||
snprintf(r->col2, sizeof(r->col2), "Signal %s%%", c2 + 1);
|
||||
snprintf(r->col3, sizeof(r->col3), "%s", (c3 + 1)[0] ? (c3 + 1) : "Open");
|
||||
}
|
||||
}
|
||||
snprintf(st->status_text, sizeof(st->status_text), "Wi-Fi %s (powersave=3)",
|
||||
st->wifi_on ? "Enabled" : "Disabled");
|
||||
} else if (st->tab == 1) {
|
||||
gemui_unix_cmd("/run/geminux/ccci.sock", "status", out, sizeof(out));
|
||||
st->cellular_on = strstr(out, "READY") != NULL;
|
||||
snprintf(st->status_text, sizeof(st->status_text), "CCCI Modem: %s",
|
||||
out[0] ? out : "Degraded / No MD1 firmware loaded");
|
||||
const char *mm[] = {"mmcli", "-m", "0", NULL};
|
||||
if (gemui_run_cmd_capture(mm, out, sizeof(out)) == 0) {
|
||||
char *save = NULL;
|
||||
for (char *ln = strtok_r(out, "\n", &save); ln && st->num_rows < 20; ln = strtok_r(NULL, "\n", &save)) {
|
||||
while (*ln == ' ' || *ln == '|') ln++;
|
||||
if (!ln[0]) continue;
|
||||
snprintf(st->rows[st->num_rows].col1, sizeof(st->rows[0].col1), "%s", ln);
|
||||
st->rows[st->num_rows].col2[0] = '\0';
|
||||
st->rows[st->num_rows].col3[0] = '\0';
|
||||
st->num_rows++;
|
||||
}
|
||||
}
|
||||
} else if (st->tab == 2) {
|
||||
const char *bt[] = {"bluetoothctl", "devices", NULL};
|
||||
if (gemui_run_cmd_capture(bt, out, sizeof(out)) == 0) {
|
||||
char *save = NULL;
|
||||
for (char *ln = strtok_r(out, "\n", &save); ln && st->num_rows < 32; ln = strtok_r(NULL, "\n", &save)) {
|
||||
snprintf(st->rows[st->num_rows].col1, sizeof(st->rows[0].col1), "%s", ln);
|
||||
st->rows[st->num_rows].col2[0] = '\0';
|
||||
st->rows[st->num_rows].col3[0] = '\0';
|
||||
st->num_rows++;
|
||||
}
|
||||
}
|
||||
const char *rf[] = {"rfkill", "list", "bluetooth", NULL};
|
||||
gemui_run_cmd_capture(rf, out, sizeof(out));
|
||||
st->bt_on = strstr(out, "Soft blocked: no") != NULL;
|
||||
snprintf(st->status_text, sizeof(st->status_text),
|
||||
"Bluetooth %s (AutoEnable=false at boot)", st->bt_on ? "Powered ON" : "Powered OFF");
|
||||
} else {
|
||||
const char *xr[] = {"xrandr", "--query", NULL};
|
||||
if (gemui_run_cmd_capture(xr, out, sizeof(out)) == 0) {
|
||||
char *save = NULL;
|
||||
for (char *ln = strtok_r(out, "\n", &save); ln && st->num_rows < 24; ln = strtok_r(NULL, "\n", &save)) {
|
||||
if (strstr(ln, "connected")) {
|
||||
if (strstr(ln, "HDMI") && !strstr(ln, "disconnected")) st->hdmi_on = true;
|
||||
snprintf(st->rows[st->num_rows].col1, sizeof(st->rows[0].col1), "%s", ln);
|
||||
st->num_rows++;
|
||||
}
|
||||
}
|
||||
}
|
||||
snprintf(st->status_text, sizeof(st->status_text),
|
||||
"USB NCM Gadget: 172.16.42.1/24 | External HDMI (SiI9024)");
|
||||
}
|
||||
}
|
||||
|
||||
static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
|
||||
net_state_t *st = ud;
|
||||
const gemui_theme_t *t = gemui_theme(app);
|
||||
|
||||
gemui_draw_header(app, cr, "\xef\x87\xab", "Geminux Network & Radios", st->status_text);
|
||||
|
||||
int pad = 20;
|
||||
int top = 80;
|
||||
int tab_w = (w - pad * 2 - 3 * 12) / 4;
|
||||
static const char *tabs[4] = {"Wi-Fi", "4G / CCCI", "Bluetooth", "USB & HDMI"};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad + i * (tab_w + 12), top, tab_w, 60},
|
||||
tabs[i], HIT_TAB, i, false, st->tab == i, false);
|
||||
}
|
||||
|
||||
int cy = top + 76;
|
||||
int ctrl_w = (w - pad * 2 - 12) / 2;
|
||||
if (st->tab == 0) {
|
||||
gemui_draw_toggle(app, cr, (gemui_rect_t){pad, cy, ctrl_w, 66},
|
||||
"Wi-Fi Radio", st->wifi_on, HIT_TOGGLE, 0, false);
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad + ctrl_w + 12, cy, ctrl_w, 66},
|
||||
"Rescan Networks", HIT_ACTION, 0, true, false, false);
|
||||
} else if (st->tab == 1) {
|
||||
gemui_draw_toggle(app, cr, (gemui_rect_t){pad, cy, ctrl_w, 66},
|
||||
"MT6797 Modem Active", st->cellular_on, HIT_TOGGLE, 1, false);
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad + ctrl_w + 12, cy, ctrl_w, 66},
|
||||
"Reset CCCI Modem", HIT_ACTION, 1, false, false, false);
|
||||
} else if (st->tab == 2) {
|
||||
gemui_draw_toggle(app, cr, (gemui_rect_t){pad, cy, ctrl_w, 66},
|
||||
"Bluetooth Radio", st->bt_on, HIT_TOGGLE, 2, false);
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad + ctrl_w + 12, cy, ctrl_w, 66},
|
||||
"Scan 10s", HIT_ACTION, 2, true, false, false);
|
||||
} else {
|
||||
gemui_draw_toggle(app, cr, (gemui_rect_t){pad, cy, ctrl_w, 66},
|
||||
"SiI9024 HDMI Extend", st->hdmi_on, HIT_TOGGLE, 3, false);
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){pad + ctrl_w + 12, cy, ctrl_w, 66},
|
||||
"Mirror Primary Display", HIT_ACTION, 3, true, false, false);
|
||||
}
|
||||
|
||||
int foot_h = (st->tab == 0) ? 84 : 0;
|
||||
gemui_rect_t box = {pad, cy + 80, w - pad * 2, h - (cy + 80) - pad - foot_h};
|
||||
gemui_fill_round(cr, box, 12, t->bg_bar);
|
||||
gemui_stroke_round(cr, box, 12, 1.5, t->border);
|
||||
|
||||
if (st->num_rows == 0) {
|
||||
gemui_draw_text(cr, t, box, "No interfaces or scan results available", 0, false,
|
||||
GEMUI_ALIGN_CENTER, t->fg_muted);
|
||||
} else {
|
||||
int rh = 64;
|
||||
for (int i = 0; i < st->num_rows; i++) {
|
||||
gemui_rect_t rr = {box.x + 10, box.y + 8 + i * rh, box.w - 20, rh - 6};
|
||||
if (rr.y + rr.h > box.y + box.h) break;
|
||||
bool sel = (i == st->sel_row);
|
||||
gemui_fill_round(cr, rr, 10, sel ? t->sel_bg : (i % 2 ? t->bg_alt_odd : t->bg_alt_even));
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){rr.x + 16, rr.y, rr.w - 320, rr.h},
|
||||
st->rows[i].col1, -1, true, GEMUI_ALIGN_LEFT,
|
||||
sel ? t->sel_fg : t->fg_bright);
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){rr.x + rr.w - 300, rr.y, 160, rr.h},
|
||||
st->rows[i].col2, -2, false, GEMUI_ALIGN_RIGHT,
|
||||
sel ? t->sel_fg : t->accent_alt);
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){rr.x + rr.w - 130, rr.y, 116, rr.h},
|
||||
st->rows[i].col3, -2, false, GEMUI_ALIGN_RIGHT,
|
||||
sel ? t->sel_fg : t->fg_muted);
|
||||
gemui_hit_add(app, rr, HIT_ROW, i);
|
||||
}
|
||||
}
|
||||
|
||||
if (st->tab == 0) {
|
||||
int cw = 220;
|
||||
gemui_draw_input(app, cr, (gemui_rect_t){pad, h - 84, w - pad * 2 - cw - 12, 64},
|
||||
"Wi-Fi passphrase (if connecting to secured SSID)...",
|
||||
st->psk, true, st->focus_psk, HIT_PSK, 0);
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){w - pad - cw, h - 84, cw, 64},
|
||||
"Connect Wi-Fi", HIT_CONNECT, 0, true, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
static void connect_selected_wifi(net_state_t *st) {
|
||||
if (st->sel_row < 0 || st->sel_row >= st->num_rows) {
|
||||
gemui_show_toast(st->app, "Select an SSID row first", 1600);
|
||||
return;
|
||||
}
|
||||
const char *ssid = st->rows[st->sel_row].col1;
|
||||
if (ssid[0] == '*' && ssid[1] == ' ') ssid += 2;
|
||||
char out[256] = {0};
|
||||
int rc;
|
||||
if (st->psk[0]) {
|
||||
const char *argv[] = {"nmcli", "dev", "wifi", "connect", ssid, "password", st->psk, NULL};
|
||||
rc = gemui_run_cmd_capture(argv, out, sizeof(out));
|
||||
} else {
|
||||
const char *argv[] = {"nmcli", "dev", "wifi", "connect", ssid, NULL};
|
||||
rc = gemui_run_cmd_capture(argv, out, sizeof(out));
|
||||
}
|
||||
gemui_show_toast(st->app, rc == 0 ? "Connected to Wi-Fi" : "Wi-Fi connect failed", 2200);
|
||||
refresh_tab(st);
|
||||
gemui_request_redraw(st->app);
|
||||
}
|
||||
|
||||
static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *utf8, void *ud) {
|
||||
(void)state;
|
||||
net_state_t *st = ud;
|
||||
if (ks == XK_Escape) {
|
||||
gemui_quit(app, 0);
|
||||
} else if (ks == XK_Tab) {
|
||||
st->tab = (st->tab + 1) % 4;
|
||||
refresh_tab(st);
|
||||
gemui_request_redraw(app);
|
||||
} else if (ks == XK_Return && st->tab == 0) {
|
||||
connect_selected_wifi(st);
|
||||
} else if (ks == XK_BackSpace && st->focus_psk) {
|
||||
gemui_utf8_pop_char(st->psk);
|
||||
gemui_request_redraw(app);
|
||||
} else if (st->focus_psk && utf8 && utf8[0]) {
|
||||
size_t cur = strlen(st->psk), add = strlen(utf8);
|
||||
if (cur + add < sizeof(st->psk)) {
|
||||
memcpy(st->psk + cur, utf8, add + 1);
|
||||
gemui_request_redraw(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, void *ud) {
|
||||
(void)btn;
|
||||
net_state_t *st = ud;
|
||||
if (type != GEMUI_PTR_DOWN) return;
|
||||
const gemui_hit_t *hit = gemui_hit_test(app, x, y);
|
||||
if (!hit) return;
|
||||
|
||||
if (hit->id == HIT_TAB) {
|
||||
st->tab = hit->val;
|
||||
st->focus_psk = false;
|
||||
refresh_tab(st);
|
||||
} else if (hit->id == HIT_ROW) {
|
||||
st->sel_row = hit->val;
|
||||
} else if (hit->id == HIT_PSK) {
|
||||
st->focus_psk = true;
|
||||
} else if (hit->id == HIT_CONNECT) {
|
||||
connect_selected_wifi(st);
|
||||
return;
|
||||
} else if (hit->id == HIT_TOGGLE) {
|
||||
if (hit->val == 0) {
|
||||
const char *argv[] = {"nmcli", "radio", "wifi", st->wifi_on ? "off" : "on", NULL};
|
||||
gemui_run_cmd_capture(argv, NULL, 0);
|
||||
} else if (hit->val == 1) {
|
||||
gemui_unix_cmd("/run/geminux/ccci.sock",
|
||||
st->cellular_on ? "flight on" : "flight off", NULL, 0);
|
||||
} else if (hit->val == 2) {
|
||||
const char *argv[] = {"rfkill", st->bt_on ? "block" : "unblock", "bluetooth", NULL};
|
||||
gemui_run_cmd_capture(argv, NULL, 0);
|
||||
} else if (hit->val == 3) {
|
||||
const char *argv[] = {"xrandr", "--output", "HDMI-1", st->hdmi_on ? "--off" : "--auto", NULL};
|
||||
gemui_run_cmd_capture(argv, NULL, 0);
|
||||
st->hdmi_on = !st->hdmi_on;
|
||||
}
|
||||
refresh_tab(st);
|
||||
} else if (hit->id == HIT_ACTION) {
|
||||
if (hit->val == 0) {
|
||||
const char *argv[] = {"nmcli", "dev", "wifi", "rescan", NULL};
|
||||
gemui_run_cmd_capture(argv, NULL, 0);
|
||||
gemui_show_toast(app, "Rescanning Wi-Fi...", 1400);
|
||||
} else if (hit->val == 1) {
|
||||
gemui_unix_cmd("/run/geminux/ccci.sock", "reset", NULL, 0);
|
||||
gemui_show_toast(app, "Sent CCCI reset request", 1600);
|
||||
} else if (hit->val == 2) {
|
||||
const char *argv[] = {"bluetoothctl", "--timeout", "10", "scan", "on", NULL};
|
||||
gemui_spawn_detached(argv);
|
||||
gemui_show_toast(app, "Bluetooth discovery active (10s)", 1800);
|
||||
} else if (hit->val == 3) {
|
||||
const char *argv[] = {"xrandr", "--output", "HDMI-1", "--same-as", "DSI-1", NULL};
|
||||
gemui_run_cmd_capture(argv, NULL, 0);
|
||||
}
|
||||
refresh_tab(st);
|
||||
}
|
||||
gemui_request_redraw(app);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
net_state_t st;
|
||||
memset(&st, 0, sizeof(st));
|
||||
st.sel_row = -1;
|
||||
refresh_tab(&st);
|
||||
|
||||
st.app = gemui_create("geminux-net", "Geminux Network & Radios", 1680, 920, false);
|
||||
if (!st.app) return 1;
|
||||
|
||||
gemui_handlers_t h = { .on_draw = on_draw, .on_key = on_key, .on_ptr = on_ptr };
|
||||
gemui_set_handlers(st.app, &h, &st);
|
||||
int rc = gemui_run(st.app);
|
||||
gemui_destroy(st.app);
|
||||
return rc;
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "gemui.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/inotify.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define HIT_THREAD 1
|
||||
#define HIT_NEW 2
|
||||
#define HIT_INPUT 3
|
||||
#define HIT_SEND 4
|
||||
|
||||
typedef struct {
|
||||
bool outgoing;
|
||||
char ts[32];
|
||||
char text[256];
|
||||
} msg_t;
|
||||
|
||||
typedef struct {
|
||||
char peer[64];
|
||||
msg_t msgs[64];
|
||||
int num_msgs;
|
||||
} thread_t;
|
||||
|
||||
typedef struct {
|
||||
gemui_app_t *app;
|
||||
char sms_dir[512];
|
||||
thread_t threads[32];
|
||||
int num_threads;
|
||||
int sel_thread;
|
||||
int inotify_fd;
|
||||
int focus_mode; /* 0 = compose, 1 = new peer number */
|
||||
char compose[256];
|
||||
char new_peer[64];
|
||||
} sms_state_t;
|
||||
|
||||
static void load_threads(sms_state_t *st) {
|
||||
char prev_peer[64] = {0};
|
||||
if (st->sel_thread >= 0 && st->sel_thread < st->num_threads) {
|
||||
snprintf(prev_peer, sizeof(prev_peer), "%s", st->threads[st->sel_thread].peer);
|
||||
}
|
||||
st->num_threads = 0;
|
||||
|
||||
DIR *d = opendir(st->sms_dir);
|
||||
if (!d) return;
|
||||
struct dirent *de;
|
||||
while ((de = readdir(d)) != NULL && st->num_threads < 32) {
|
||||
size_t len = strlen(de->d_name);
|
||||
if (len < 5 || strcmp(de->d_name + len - 4, ".tsv") != 0) continue;
|
||||
thread_t *th = &st->threads[st->num_threads++];
|
||||
memset(th, 0, sizeof(*th));
|
||||
snprintf(th->peer, sizeof(th->peer), "%.*s", (int)(len - 4), de->d_name);
|
||||
|
||||
char fp[576];
|
||||
snprintf(fp, sizeof(fp), "%s/%s", st->sms_dir, de->d_name);
|
||||
FILE *f = fopen(fp, "r");
|
||||
if (!f) continue;
|
||||
char line[384];
|
||||
while (fgets(line, sizeof(line), f) && th->num_msgs < 64) {
|
||||
size_t n = strlen(line);
|
||||
while (n > 0 && (line[n - 1] == '\n' || line[n - 1] == '\r')) line[--n] = '\0';
|
||||
char *t1 = strchr(line, '\t');
|
||||
char *t2 = t1 ? strchr(t1 + 1, '\t') : NULL;
|
||||
if (!t1 || !t2) continue;
|
||||
*t1 = '\0';
|
||||
*t2 = '\0';
|
||||
msg_t *m = &th->msgs[th->num_msgs++];
|
||||
m->outgoing = (strcmp(line, "OUT") == 0);
|
||||
snprintf(m->ts, sizeof(m->ts), "%s", t1 + 1);
|
||||
snprintf(m->text, sizeof(m->text), "%s", t2 + 1);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
closedir(d);
|
||||
|
||||
st->sel_thread = st->num_threads > 0 ? 0 : -1;
|
||||
if (prev_peer[0]) {
|
||||
for (int i = 0; i < st->num_threads; i++) {
|
||||
if (strcmp(st->threads[i].peer, prev_peer) == 0) {
|
||||
st->sel_thread = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void on_inotify(gemui_app_t *app, int fd, void *ud) {
|
||||
sms_state_t *st = ud;
|
||||
char buf[512];
|
||||
while (read(fd, buf, sizeof(buf)) > 0) {}
|
||||
load_threads(st);
|
||||
gemui_request_redraw(app);
|
||||
}
|
||||
|
||||
static void send_sms(sms_state_t *st) {
|
||||
const char *peer = NULL;
|
||||
if (st->new_peer[0]) {
|
||||
peer = st->new_peer;
|
||||
} else if (st->sel_thread >= 0 && st->sel_thread < st->num_threads) {
|
||||
peer = st->threads[st->sel_thread].peer;
|
||||
}
|
||||
if (!peer || !peer[0] || !st->compose[0]) {
|
||||
gemui_show_toast(st->app, "Select/enter recipient and message text", 1800);
|
||||
return;
|
||||
}
|
||||
|
||||
char cmd[384], resp[128];
|
||||
snprintf(cmd, sizeof(cmd), "sms-send %s %s", peer, st->compose);
|
||||
if (gemui_unix_cmd("/run/geminux/modem.sock", cmd, resp, sizeof(resp)) != 0) {
|
||||
/* Persist locally if modem daemon isn't running yet */
|
||||
char fp[576];
|
||||
snprintf(fp, sizeof(fp), "%s/%s.tsv", st->sms_dir, peer);
|
||||
FILE *f = fopen(fp, "a");
|
||||
if (f) {
|
||||
time_t now = time(NULL);
|
||||
struct tm tm;
|
||||
localtime_r(&now, &tm);
|
||||
char ts[32];
|
||||
strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M", &tm);
|
||||
fprintf(f, "OUT\t%s\t%s\n", ts, st->compose);
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(st->new_peer, sizeof(st->new_peer), "%s", peer);
|
||||
st->compose[0] = '\0';
|
||||
st->focus_mode = 0;
|
||||
load_threads(st);
|
||||
for (int i = 0; i < st->num_threads; i++) {
|
||||
if (strcmp(st->threads[i].peer, peer) == 0) st->sel_thread = i;
|
||||
}
|
||||
st->new_peer[0] = '\0';
|
||||
gemui_show_toast(st->app, "SMS queued for transmission", 1800);
|
||||
gemui_request_redraw(st->app);
|
||||
}
|
||||
|
||||
static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
|
||||
sms_state_t *st = ud;
|
||||
const gemui_theme_t *t = gemui_theme(app);
|
||||
|
||||
gemui_draw_header(app, cr, "\xef\x83\xa0", "Geminux SMS Messages",
|
||||
"Tab: Switch Field | Enter: Send");
|
||||
|
||||
int pad = 20;
|
||||
int top = 80;
|
||||
int left_w = 520;
|
||||
if (left_w > w / 3) left_w = w / 3;
|
||||
int right_x = pad * 2 + left_w;
|
||||
int right_w = w - right_x - pad;
|
||||
|
||||
/* Left pane: recipient input + thread list */
|
||||
gemui_draw_input(app, cr, (gemui_rect_t){pad, top, left_w, 60},
|
||||
"New recipient number...", st->new_peer, false,
|
||||
st->focus_mode == 1, HIT_NEW, 0);
|
||||
|
||||
gemui_rect_t pane = {pad, top + 74, left_w, h - (top + 74) - pad};
|
||||
gemui_fill_round(cr, pane, 12, t->bg_bar);
|
||||
gemui_stroke_round(cr, pane, 12, 1.5, t->border);
|
||||
|
||||
if (st->num_threads == 0) {
|
||||
gemui_draw_text(cr, t, pane, "No SMS threads yet", 0, false,
|
||||
GEMUI_ALIGN_CENTER, t->fg_muted);
|
||||
} else {
|
||||
int rh = 76;
|
||||
for (int i = 0; i < st->num_threads; i++) {
|
||||
gemui_rect_t rr = {pane.x + 10, pane.y + 10 + i * rh, pane.w - 20, rh - 8};
|
||||
if (rr.y + rr.h > pane.y + pane.h) break;
|
||||
bool sel = (i == st->sel_thread);
|
||||
gemui_fill_round(cr, rr, 10, sel ? t->sel_bg : (i % 2 ? t->bg_alt_odd : t->bg_alt_even));
|
||||
thread_t *th = &st->threads[i];
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){rr.x + 14, rr.y + 4, rr.w - 28, 32},
|
||||
th->peer, -1, true, GEMUI_ALIGN_LEFT,
|
||||
sel ? t->sel_fg : t->fg_bright);
|
||||
const char *preview = (th->num_msgs > 0) ? th->msgs[th->num_msgs - 1].text : "";
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){rr.x + 14, rr.y + 34, rr.w - 28, 28},
|
||||
preview, -2, false, GEMUI_ALIGN_LEFT,
|
||||
sel ? t->sel_fg : t->fg_muted);
|
||||
gemui_hit_add(app, rr, HIT_THREAD, i);
|
||||
}
|
||||
}
|
||||
|
||||
/* Right pane: chat history bubbles + compose bar */
|
||||
gemui_rect_t chat = {right_x, top, right_w, h - top - 104};
|
||||
gemui_fill_round(cr, chat, 12, t->bg_overlay);
|
||||
gemui_stroke_round(cr, chat, 12, 1.5, t->border);
|
||||
|
||||
if (st->sel_thread >= 0 && st->sel_thread < st->num_threads) {
|
||||
thread_t *th = &st->threads[st->sel_thread];
|
||||
int bh = 84;
|
||||
int cap = (chat.h - 24) / bh;
|
||||
int start = (th->num_msgs > cap) ? (th->num_msgs - cap) : 0;
|
||||
int y = chat.y + 12;
|
||||
for (int i = start; i < th->num_msgs; i++) {
|
||||
msg_t *m = &th->msgs[i];
|
||||
int bw = (chat.w * 70) / 100;
|
||||
int bx = m->outgoing ? (chat.x + chat.w - bw - 16) : (chat.x + 16);
|
||||
gemui_rect_t br = {bx, y, bw, bh - 10};
|
||||
gemui_fill_round(cr, br, 12, m->outgoing ? t->bg_bubble_out : t->bg_bubble_in);
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){br.x + 14, br.y + 6, br.w - 28, 34},
|
||||
m->text, -1, false, GEMUI_ALIGN_LEFT, t->fg_bright);
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){br.x + 14, br.y + 42, br.w - 28, 22},
|
||||
m->ts, -4, false, m->outgoing ? GEMUI_ALIGN_RIGHT : GEMUI_ALIGN_LEFT, t->fg_muted);
|
||||
y += bh;
|
||||
}
|
||||
} else {
|
||||
gemui_draw_text(cr, t, chat, "Select a thread or enter a new number", 0,
|
||||
false, GEMUI_ALIGN_CENTER, t->fg_muted);
|
||||
}
|
||||
|
||||
int send_w = 180;
|
||||
gemui_draw_input(app, cr, (gemui_rect_t){right_x, h - 88, right_w - send_w - 12, 68},
|
||||
"Type SMS message...", st->compose, false,
|
||||
st->focus_mode == 0, HIT_INPUT, 0);
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){right_x + right_w - send_w, h - 88, send_w, 68},
|
||||
"Send", HIT_SEND, 0, true, false, false);
|
||||
}
|
||||
|
||||
static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *utf8, void *ud) {
|
||||
(void)state;
|
||||
sms_state_t *st = ud;
|
||||
char *target = (st->focus_mode == 1) ? st->new_peer : st->compose;
|
||||
size_t max_sz = (st->focus_mode == 1) ? sizeof(st->new_peer) : sizeof(st->compose);
|
||||
|
||||
if (ks == XK_Escape) {
|
||||
gemui_quit(app, 0);
|
||||
} else if (ks == XK_Tab) {
|
||||
st->focus_mode = 1 - st->focus_mode;
|
||||
gemui_request_redraw(app);
|
||||
} else if (ks == XK_Up && st->sel_thread > 0) {
|
||||
st->sel_thread--;
|
||||
gemui_request_redraw(app);
|
||||
} else if (ks == XK_Down && st->sel_thread + 1 < st->num_threads) {
|
||||
st->sel_thread++;
|
||||
gemui_request_redraw(app);
|
||||
} else if (ks == XK_Return || ks == XK_KP_Enter) {
|
||||
if (st->focus_mode == 1) {
|
||||
st->focus_mode = 0;
|
||||
gemui_request_redraw(app);
|
||||
} else {
|
||||
send_sms(st);
|
||||
}
|
||||
} else if (ks == XK_BackSpace) {
|
||||
gemui_utf8_pop_char(target);
|
||||
gemui_request_redraw(app);
|
||||
} else if (utf8 && utf8[0]) {
|
||||
size_t cur = strlen(target);
|
||||
size_t add = strlen(utf8);
|
||||
if (cur + add < max_sz) {
|
||||
memcpy(target + cur, utf8, add + 1);
|
||||
gemui_request_redraw(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, void *ud) {
|
||||
(void)btn;
|
||||
sms_state_t *st = ud;
|
||||
if (type != GEMUI_PTR_DOWN) return;
|
||||
const gemui_hit_t *hit = gemui_hit_test(app, x, y);
|
||||
if (!hit) return;
|
||||
|
||||
if (hit->id == HIT_THREAD) {
|
||||
st->sel_thread = hit->val;
|
||||
st->new_peer[0] = '\0';
|
||||
st->focus_mode = 0;
|
||||
gemui_request_redraw(app);
|
||||
} else if (hit->id == HIT_NEW) {
|
||||
st->focus_mode = 1;
|
||||
gemui_request_redraw(app);
|
||||
} else if (hit->id == HIT_INPUT) {
|
||||
st->focus_mode = 0;
|
||||
gemui_request_redraw(app);
|
||||
} else if (hit->id == HIT_SEND) {
|
||||
send_sms(st);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
sms_state_t st;
|
||||
memset(&st, 0, sizeof(st));
|
||||
st.sel_thread = -1;
|
||||
const char *home = getenv("HOME");
|
||||
snprintf(st.sms_dir, sizeof(st.sms_dir), "%s/.local/share/geminux/sms",
|
||||
(home && home[0]) ? home : "/home/user");
|
||||
const char *mk[] = {"mkdir", "-p", st.sms_dir, NULL};
|
||||
gemui_run_cmd_capture(mk, NULL, 0);
|
||||
|
||||
if (argc > 1 && argv[1][0]) {
|
||||
snprintf(st.new_peer, sizeof(st.new_peer), "%s", argv[1]);
|
||||
}
|
||||
load_threads(&st);
|
||||
|
||||
st.app = gemui_create("geminux-sms", "Geminux SMS Messages", 1640, 900, false);
|
||||
if (!st.app) return 1;
|
||||
|
||||
st.inotify_fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
|
||||
if (st.inotify_fd >= 0) {
|
||||
inotify_add_watch(st.inotify_fd, st.sms_dir, IN_MODIFY | IN_CREATE | IN_MOVED_TO);
|
||||
gemui_add_fd(st.app, st.inotify_fd, on_inotify, &st);
|
||||
}
|
||||
|
||||
gemui_handlers_t h = { .on_draw = on_draw, .on_key = on_key, .on_ptr = on_ptr };
|
||||
gemui_set_handlers(st.app, &h, &st);
|
||||
int rc = gemui_run(st.app);
|
||||
if (st.inotify_fd >= 0) close(st.inotify_fd);
|
||||
gemui_destroy(st.app);
|
||||
return rc;
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "gemui.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define HIT_ITEM 1
|
||||
#define HIT_APPLY 2
|
||||
|
||||
typedef struct {
|
||||
char name[64];
|
||||
char path[512];
|
||||
gemui_theme_t parsed;
|
||||
} xth_entry_t;
|
||||
|
||||
typedef struct {
|
||||
gemui_app_t *app;
|
||||
xth_entry_t items[48];
|
||||
int num_items;
|
||||
int sel;
|
||||
} themes_state_t;
|
||||
|
||||
static int cmp_xth(const void *a, const void *b) {
|
||||
const xth_entry_t *xa = a;
|
||||
const xth_entry_t *xb = b;
|
||||
return strcmp(xa->name, xb->name);
|
||||
}
|
||||
|
||||
static void scan_dir(themes_state_t *st, const char *dir) {
|
||||
DIR *d = opendir(dir);
|
||||
if (!d) return;
|
||||
struct dirent *de;
|
||||
while ((de = readdir(d)) != NULL && st->num_items < 48) {
|
||||
size_t len = strlen(de->d_name);
|
||||
if (len < 5 || strcmp(de->d_name + len - 4, ".xth") != 0) continue;
|
||||
char short_name[64];
|
||||
snprintf(short_name, sizeof(short_name), "%.*s", (int)(len - 4), de->d_name);
|
||||
bool dup = false;
|
||||
for (int i = 0; i < st->num_items; i++) {
|
||||
if (strcmp(st->items[i].name, short_name) == 0) {
|
||||
dup = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (dup) continue;
|
||||
xth_entry_t *e = &st->items[st->num_items++];
|
||||
snprintf(e->name, sizeof(e->name), "%s", short_name);
|
||||
snprintf(e->path, sizeof(e->path), "%s/%s", dir, de->d_name);
|
||||
gemui_theme_load_file(e->path, &e->parsed);
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
static void load_themes(themes_state_t *st) {
|
||||
st->num_items = 0;
|
||||
const char *home = getenv("HOME");
|
||||
if (home && home[0]) {
|
||||
char p[512];
|
||||
snprintf(p, sizeof(p), "%s/.xthemes", home);
|
||||
scan_dir(st, p);
|
||||
}
|
||||
scan_dir(st, "/etc/skel/.xthemes");
|
||||
if (st->num_items > 1) qsort(st->items, (size_t)st->num_items, sizeof(st->items[0]), cmp_xth);
|
||||
|
||||
const gemui_theme_t *cur = gemui_theme(st->app);
|
||||
st->sel = 0;
|
||||
for (int i = 0; i < st->num_items; i++) {
|
||||
if (cur && strcmp(st->items[i].name, cur->name) == 0) {
|
||||
st->sel = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void apply_selected(themes_state_t *st) {
|
||||
if (st->sel < 0 || st->sel >= st->num_items) return;
|
||||
const char *argv[] = {"/usr/bin/geminux-apply-theme", st->items[st->sel].name, NULL};
|
||||
int rc = gemui_run_cmd_capture(argv, NULL, 0);
|
||||
gemui_theme_reload(st->app);
|
||||
gemui_show_toast(st->app, rc == 0 ? "Applied .Xresources + dunst theme" : "Theme apply failed", 2000);
|
||||
gemui_request_redraw(st->app);
|
||||
}
|
||||
|
||||
static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
|
||||
themes_state_t *st = ud;
|
||||
const gemui_theme_t *t = gemui_theme(app);
|
||||
|
||||
gemui_draw_header(app, cr, "\xee\x88\xab", "Geminux Unified Themes", t->name);
|
||||
|
||||
int pad = 20;
|
||||
int top = 80;
|
||||
int left_w = (w - pad * 3) / 2;
|
||||
int right_x = pad * 2 + left_w;
|
||||
int right_w = w - right_x - pad;
|
||||
|
||||
gemui_rect_t list = {pad, top, left_w, h - top - pad};
|
||||
gemui_fill_round(cr, list, 12, t->bg_bar);
|
||||
gemui_stroke_round(cr, list, 12, 1.5, t->border);
|
||||
|
||||
int rh = 64;
|
||||
int cap = (list.h - 16) / rh;
|
||||
int start = (st->sel >= cap) ? (st->sel - cap + 1) : 0;
|
||||
for (int i = start; i < st->num_items && (i - start) < cap; i++) {
|
||||
gemui_rect_t rr = {list.x + 10, list.y + 8 + (i - start) * rh, list.w - 20, rh - 6};
|
||||
bool sel = (i == st->sel);
|
||||
gemui_fill_round(cr, rr, 10, sel ? t->sel_bg : (i % 2 ? t->bg_alt_odd : t->bg_alt_even));
|
||||
|
||||
const gemui_theme_t *pt = &st->items[i].parsed;
|
||||
gemui_color_t sw[4] = {pt->bg_main, pt->accent, pt->success, pt->danger};
|
||||
for (int k = 0; k < 4; k++) {
|
||||
gemui_fill_round(cr, (gemui_rect_t){rr.x + 12 + k * 28, rr.y + 18, 22, 22}, 5, sw[k]);
|
||||
}
|
||||
gemui_draw_text(cr, t, (gemui_rect_t){rr.x + 132, rr.y, rr.w - 144, rr.h},
|
||||
st->items[i].name, -1, sel, GEMUI_ALIGN_LEFT,
|
||||
sel ? t->sel_fg : t->fg_bright);
|
||||
gemui_hit_add(app, rr, HIT_ITEM, i);
|
||||
}
|
||||
|
||||
/* Live Preview Card */
|
||||
gemui_rect_t prev = {right_x, top, right_w, h - top - 104};
|
||||
const gemui_theme_t *pt = (st->sel >= 0 && st->sel < st->num_items) ? &st->items[st->sel].parsed : t;
|
||||
gemui_fill_round(cr, prev, 14, pt->bg_main);
|
||||
gemui_stroke_round(cr, prev, 14, 2.0, pt->border);
|
||||
|
||||
gemui_fill_round(cr, (gemui_rect_t){prev.x + 16, prev.y + 16, prev.w - 32, 56}, 10, pt->bg_header);
|
||||
gemui_draw_text(cr, pt, (gemui_rect_t){prev.x + 32, prev.y + 16, prev.w - 64, 56},
|
||||
pt->name, 2, true, GEMUI_ALIGN_LEFT, pt->fg_bright);
|
||||
|
||||
gemui_fill_round(cr, (gemui_rect_t){prev.x + 24, prev.y + 92, prev.w - 48, 72}, 10, pt->bg_bubble_in);
|
||||
gemui_draw_text(cr, pt, (gemui_rect_t){prev.x + 40, prev.y + 92, prev.w - 80, 72},
|
||||
"Fira Code Ligatures: -> => !== <= >=", -1, false, GEMUI_ALIGN_LEFT, pt->fg_main);
|
||||
|
||||
gemui_fill_round(cr, (gemui_rect_t){prev.x + 24, prev.y + 180, prev.w - 48, 72}, 10, pt->sel_bg);
|
||||
gemui_draw_text(cr, pt, (gemui_rect_t){prev.x + 40, prev.y + 180, prev.w - 80, 72},
|
||||
"Selected Item & Accent Highlight", -1, true, GEMUI_ALIGN_LEFT, pt->sel_fg);
|
||||
|
||||
int sw_w = (prev.w - 48 - 4 * 10) / 5;
|
||||
gemui_color_t badges[5] = {pt->accent, pt->success, pt->info, pt->warning, pt->danger};
|
||||
static const char *labels[5] = {"Accent", "Success", "Info", "Warn", "Danger"};
|
||||
for (int i = 0; i < 5; i++) {
|
||||
gemui_rect_t br = {prev.x + 24 + i * (sw_w + 10), prev.y + 276, sw_w, 60};
|
||||
gemui_fill_round(cr, br, 8, badges[i]);
|
||||
gemui_draw_text(cr, pt, br, labels[i], -3, true, GEMUI_ALIGN_CENTER, pt->bg_main);
|
||||
}
|
||||
|
||||
gemui_draw_button(app, cr, (gemui_rect_t){right_x, h - 88, right_w, 68},
|
||||
"Apply Across DWM, st, dmenu, dunst & Apps", HIT_APPLY, 0, true, false, false);
|
||||
}
|
||||
|
||||
static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *utf8, void *ud) {
|
||||
(void)state;
|
||||
(void)utf8;
|
||||
themes_state_t *st = ud;
|
||||
if (ks == XK_Escape || ks == XK_q) gemui_quit(app, 0);
|
||||
else if (ks == XK_Up && st->sel > 0) { st->sel--; gemui_request_redraw(app); }
|
||||
else if (ks == XK_Down && st->sel + 1 < st->num_items) { st->sel++; gemui_request_redraw(app); }
|
||||
else if (ks == XK_Return || ks == XK_KP_Enter) apply_selected(st);
|
||||
}
|
||||
|
||||
static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, void *ud) {
|
||||
(void)btn;
|
||||
themes_state_t *st = ud;
|
||||
if (type != GEMUI_PTR_DOWN) return;
|
||||
const gemui_hit_t *hit = gemui_hit_test(app, x, y);
|
||||
if (!hit) return;
|
||||
if (hit->id == HIT_ITEM) {
|
||||
st->sel = hit->val;
|
||||
gemui_request_redraw(app);
|
||||
} else if (hit->id == HIT_APPLY) {
|
||||
apply_selected(st);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
themes_state_t st;
|
||||
memset(&st, 0, sizeof(st));
|
||||
st.app = gemui_create("geminux-themes", "Geminux Unified Themes", 1560, 860, false);
|
||||
if (!st.app) return 1;
|
||||
load_themes(&st);
|
||||
|
||||
gemui_handlers_t h = { .on_draw = on_draw, .on_key = on_key, .on_ptr = on_ptr };
|
||||
gemui_set_handlers(st.app, &h, &st);
|
||||
int rc = gemui_run(st.app);
|
||||
gemui_destroy(st.app);
|
||||
return rc;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
CC ?= gcc
|
||||
PKG_CONFIG ?= pkg-config
|
||||
PREFIX ?= /usr
|
||||
DESTDIR ?=
|
||||
KERNEL_INC ?= ../../prebuilt/kernel/include
|
||||
|
||||
CFLAGS += -std=c11 -Wall -Wextra -O2 -I. -I$(KERNEL_INC)
|
||||
X11_CFLAGS = $(shell $(PKG_CONFIG) --cflags x11)
|
||||
X11_LIBS = $(shell $(PKG_CONFIG) --libs x11)
|
||||
GIO_CFLAGS = $(shell $(PKG_CONFIG) --cflags gio-2.0 glib-2.0 gobject-2.0)
|
||||
GIO_LIBS = $(shell $(PKG_CONFIG) --libs gio-2.0 glib-2.0 gobject-2.0)
|
||||
|
||||
BINS = \
|
||||
geminux-powerd \
|
||||
geminux-power-ctl \
|
||||
geminux-statusd \
|
||||
geminux-ccci-daemon \
|
||||
geminux-modem-ctl \
|
||||
geminux-bt-obex \
|
||||
geminux-leds \
|
||||
geminux-power-audit \
|
||||
geminux-checkpw
|
||||
|
||||
all: $(BINS)
|
||||
|
||||
geminux-powerd: geminux-powerd.c geminux-power-policy.c geminux-power-policy.h
|
||||
$(CC) $(CFLAGS) -o $@ geminux-powerd.c geminux-power-policy.c
|
||||
|
||||
geminux-power-ctl: geminux-power-ctl.c
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
geminux-statusd: geminux-statusd.c
|
||||
$(CC) $(CFLAGS) $(X11_CFLAGS) -o $@ $< $(X11_LIBS)
|
||||
|
||||
geminux-ccci-daemon: geminux-ccci-daemon.c geminux-ccci-proto.c geminux-ccci-proto.h
|
||||
$(CC) $(CFLAGS) -o $@ geminux-ccci-daemon.c geminux-ccci-proto.c
|
||||
|
||||
geminux-modem-ctl: geminux-modem-ctl.c
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
geminux-bt-obex: geminux-bt-obex.c
|
||||
$(CC) $(CFLAGS) $(GIO_CFLAGS) -o $@ $< $(GIO_LIBS)
|
||||
|
||||
geminux-leds: geminux-leds.c
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
geminux-power-audit: geminux-power-audit.c
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
geminux-checkpw: geminux-checkpw.c
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
install: all
|
||||
mkdir -p $(DESTDIR)$(PREFIX)/bin $(DESTDIR)$(PREFIX)/sbin
|
||||
cp -f geminux-power-ctl geminux-statusd geminux-modem-ctl \
|
||||
geminux-bt-obex geminux-power-audit $(DESTDIR)$(PREFIX)/bin/
|
||||
cp -f geminux-powerd geminux-ccci-daemon geminux-leds \
|
||||
geminux-checkpw $(DESTDIR)$(PREFIX)/sbin/
|
||||
chmod 0755 $(DESTDIR)$(PREFIX)/bin/geminux-* $(DESTDIR)$(PREFIX)/sbin/geminux-*
|
||||
|
||||
clean:
|
||||
rm -f $(BINS)
|
||||
|
||||
.PHONY: all install clean
|
||||
@@ -0,0 +1,78 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <gio/gio.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static GMainLoop *g_loop = NULL;
|
||||
|
||||
static void notify_event(const char *title, const char *body) {
|
||||
const char *argv[] = {"notify-send", title, body, NULL};
|
||||
g_spawn_async(NULL, (gchar **)argv, NULL, G_SPAWN_SEARCH_PATH,
|
||||
NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
static void on_bluez_props(GDBusConnection *conn, const gchar *sender,
|
||||
const gchar *obj_path, const gchar *iface_name,
|
||||
const gchar *signal_name, GVariant *params,
|
||||
gpointer ud) {
|
||||
(void)conn; (void)sender; (void)iface_name; (void)signal_name; (void)ud;
|
||||
const gchar *prop_iface = NULL;
|
||||
GVariant *changed = NULL;
|
||||
GVariant *invalidated = NULL;
|
||||
g_variant_get(params, "(&s@a{sv}@as)", &prop_iface, &changed, &invalidated);
|
||||
|
||||
if (prop_iface && strcmp(prop_iface, "org.bluez.Device1") == 0 && changed) {
|
||||
gboolean connected = FALSE;
|
||||
if (g_variant_lookup(changed, "Connected", "b", &connected)) {
|
||||
notify_event("Bluetooth", connected ? "Device connected" : "Device disconnected");
|
||||
}
|
||||
} else if (prop_iface && strcmp(prop_iface, "org.bluez.obex.Transfer1") == 0 && changed) {
|
||||
const gchar *status = NULL;
|
||||
if (g_variant_lookup(changed, "Status", "&s", &status) &&
|
||||
status && strcmp(status, "complete") == 0) {
|
||||
const gchar *name = NULL;
|
||||
g_variant_lookup(changed, "Name", "&s", &name);
|
||||
char msg[256];
|
||||
snprintf(msg, sizeof(msg), "Received Bluetooth file: %s",
|
||||
(name && name[0]) ? name : obj_path);
|
||||
notify_event("Bluetooth OBEX", msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) g_variant_unref(changed);
|
||||
if (invalidated) g_variant_unref(invalidated);
|
||||
}
|
||||
|
||||
static void handle_sig(int sig) {
|
||||
(void)sig;
|
||||
if (g_loop) g_main_loop_quit(g_loop);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
signal(SIGTERM, handle_sig);
|
||||
signal(SIGINT, handle_sig);
|
||||
signal(SIGCHLD, SIG_IGN);
|
||||
|
||||
g_loop = g_main_loop_new(NULL, FALSE);
|
||||
GDBusConnection *sys = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
|
||||
if (sys) {
|
||||
g_dbus_connection_signal_subscribe(
|
||||
sys, "org.bluez", "org.freedesktop.DBus.Properties",
|
||||
"PropertiesChanged", NULL, "org.bluez.Device1",
|
||||
G_DBUS_SIGNAL_FLAGS_NONE, on_bluez_props, NULL, NULL);
|
||||
}
|
||||
GDBusConnection *ses = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
|
||||
if (ses) {
|
||||
g_dbus_connection_signal_subscribe(
|
||||
ses, "org.bluez.obex", "org.freedesktop.DBus.Properties",
|
||||
"PropertiesChanged", NULL, "org.bluez.obex.Transfer1",
|
||||
G_DBUS_SIGNAL_FLAGS_NONE, on_bluez_props, NULL, NULL);
|
||||
}
|
||||
|
||||
g_main_loop_run(g_loop);
|
||||
if (sys) g_object_unref(sys);
|
||||
if (ses) g_object_unref(ses);
|
||||
g_main_loop_unref(g_loop);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
#define _GNU_SOURCE
|
||||
#include "geminux-ccci-proto.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <grp.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/signalfd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define SOCK_PATH "/run/geminux/ccci.sock"
|
||||
#define NVRAM_DIR "/var/lib/geminux/md_nvram"
|
||||
#define FW_MD1_IMG "/lib/firmware/mediatek/mt6797/md1rom.img"
|
||||
|
||||
typedef struct {
|
||||
int epfd;
|
||||
int sig_fd;
|
||||
int srv_fd;
|
||||
int uev_fd;
|
||||
int ctl_fd;
|
||||
int fs_fd;
|
||||
int rpc_fd;
|
||||
bool fw_present;
|
||||
bool stage_attempted;
|
||||
geminux_ccci_sm_t sm;
|
||||
} ccci_ctx_t;
|
||||
|
||||
static void add_ep(int epfd, int fd) {
|
||||
if (fd < 0) return;
|
||||
struct epoll_event ev = { .events = EPOLLIN, .data.fd = fd };
|
||||
epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev);
|
||||
}
|
||||
|
||||
static int advance_ccci_stage(int target_stage) {
|
||||
int sfd = open("/sys/class/mt6797_ccci/md1/stage", O_WRONLY | O_CLOEXEC);
|
||||
if (sfd < 0) return -1;
|
||||
|
||||
char stage_buf[16];
|
||||
int len = snprintf(stage_buf, sizeof(stage_buf), "%d\n", target_stage);
|
||||
ssize_t w = (len > 0) ? write(sfd, stage_buf, (size_t)len) : -1;
|
||||
close(sfd);
|
||||
return (w > 0) ? 0 : -1;
|
||||
}
|
||||
|
||||
static void maybe_advance_ccci_stage(ccci_ctx_t *ctx) {
|
||||
if (ctx->stage_attempted || ctx->sm.flight_mode) return;
|
||||
if (access("/etc/geminux/ccci-autostart", F_OK) != 0) return;
|
||||
|
||||
int mfd = open("/sys/class/mt6797_ccci/md1/mblock_info", O_RDONLY | O_CLOEXEC);
|
||||
if (mfd < 0) return;
|
||||
|
||||
char info[256] = {0};
|
||||
ssize_t n = read(mfd, info, sizeof(info) - 1);
|
||||
close(mfd);
|
||||
if (n <= 0) return;
|
||||
|
||||
ctx->stage_attempted = true;
|
||||
if (!strstr(info, "handoff=1")) return;
|
||||
|
||||
(void)advance_ccci_stage(3);
|
||||
}
|
||||
|
||||
static void open_ccci_devs(ccci_ctx_t *ctx) {
|
||||
if (ctx->ctl_fd < 0) {
|
||||
ctx->ctl_fd = open("/dev/ccci_monitor", O_RDWR | O_NONBLOCK | O_CLOEXEC);
|
||||
if (ctx->ctl_fd < 0)
|
||||
ctx->ctl_fd = open("/dev/ccci_md_ctl", O_RDWR | O_NONBLOCK | O_CLOEXEC);
|
||||
if (ctx->ctl_fd >= 0) {
|
||||
add_ep(ctx->epfd, ctx->ctl_fd);
|
||||
maybe_advance_ccci_stage(ctx);
|
||||
__u32 st = 0;
|
||||
if (ioctl(ctx->ctl_fd, CCCI_IOC_GET_MD_STATE, &st) == 0 && st <= MT6797_MD_STATE_RESET) {
|
||||
ctx->sm.state = (enum mt6797_ccci_md_state)st;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ctx->fs_fd < 0) {
|
||||
ctx->fs_fd = open("/dev/ccci_fs", O_RDWR | O_NONBLOCK | O_CLOEXEC);
|
||||
if (ctx->fs_fd >= 0) add_ep(ctx->epfd, ctx->fs_fd);
|
||||
}
|
||||
if (ctx->rpc_fd < 0) {
|
||||
ctx->rpc_fd = open("/dev/ccci_rpc", O_RDWR | O_NONBLOCK | O_CLOEXEC);
|
||||
if (ctx->rpc_fd >= 0) add_ep(ctx->epfd, ctx->rpc_fd);
|
||||
}
|
||||
ctx->fw_present = (access(FW_MD1_IMG, R_OK) == 0);
|
||||
}
|
||||
|
||||
static void handle_ctl_read(ccci_ctx_t *ctx) {
|
||||
uint8_t buf[256];
|
||||
ssize_t n;
|
||||
while ((n = read(ctx->ctl_fd, buf, sizeof(buf))) >= (ssize_t)sizeof(struct mt6797_ccci_header)) {
|
||||
struct mt6797_ccci_header rx, tx;
|
||||
bool need_reply = false;
|
||||
geminux_ccci_unpack_hdr(buf, &rx);
|
||||
if (geminux_ccci_handle_ctrl(&ctx->sm, &rx, &tx, &need_reply) && need_reply) {
|
||||
ssize_t unused = write(ctx->ctl_fd, &tx, sizeof(tx));
|
||||
(void)unused;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_fs_or_rpc(ccci_ctx_t *ctx, int fd) {
|
||||
uint8_t buf[4096];
|
||||
ssize_t n;
|
||||
while ((n = read(fd, buf, sizeof(buf))) >= (ssize_t)sizeof(struct mt6797_ccci_header)) {
|
||||
ctx->sm.rx_packets++;
|
||||
struct mt6797_ccci_header rx, tx;
|
||||
geminux_ccci_unpack_hdr(buf, &rx);
|
||||
/* Echo minimal ACK framing on FS/RPC TX channel for clean modem handshake */
|
||||
geminux_ccci_pack_hdr(&tx, rx.data0, 0,
|
||||
(fd == ctx->fs_fd) ? MT6797_CCCI_CH_FS_TX : MT6797_CCCI_CH_RPC_TX,
|
||||
rx.reserved);
|
||||
ctx->sm.tx_packets++;
|
||||
ssize_t unused = write(fd, &tx, sizeof(tx));
|
||||
(void)unused;
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_client(ccci_ctx_t *ctx, int cfd) {
|
||||
char buf[128] = {0};
|
||||
ssize_t n = read(cfd, buf, sizeof(buf) - 1);
|
||||
if (n <= 0) return;
|
||||
while (n > 0 && (buf[n - 1] == '\n' || buf[n - 1] == '\r')) buf[--n] = '\0';
|
||||
|
||||
if (strcmp(buf, "status") == 0) {
|
||||
struct mt6797_ccci_status st;
|
||||
memset(&st, 0, sizeof(st));
|
||||
if (ctx->ctl_fd >= 0) ioctl(ctx->ctl_fd, CCCI_IOC_GET_STATUS, &st);
|
||||
dprintf(cfd, "state=%s dev=%d fw=%d flight=%d tx=%u rx=%u\n",
|
||||
geminux_ccci_state_name(ctx->sm.state),
|
||||
ctx->ctl_fd >= 0 ? 1 : 0,
|
||||
ctx->fw_present ? 1 : 0,
|
||||
ctx->sm.flight_mode ? 1 : 0,
|
||||
ctx->sm.tx_packets, ctx->sm.rx_packets);
|
||||
} else if (strcmp(buf, "reset") == 0) {
|
||||
if (ctx->ctl_fd >= 0) {
|
||||
ioctl(ctx->ctl_fd, CCCI_IOC_MD_RESET);
|
||||
ctx->sm.state = MT6797_MD_STATE_RESET;
|
||||
dprintf(cfd, "OK reset\n");
|
||||
} else {
|
||||
dprintf(cfd, "DEGRADED no /dev/ccci_md_ctl\n");
|
||||
}
|
||||
} else if (strcmp(buf, "boot") == 0) {
|
||||
ctx->sm.flight_mode = false;
|
||||
if (advance_ccci_stage(3) == 0) {
|
||||
ctx->stage_attempted = true;
|
||||
dprintf(cfd, "OK stage=3\n");
|
||||
} else {
|
||||
dprintf(cfd, "DEGRADED stage=3 unavailable\n");
|
||||
}
|
||||
} else if (strcmp(buf, "flight on") == 0) {
|
||||
ctx->sm.flight_mode = true;
|
||||
if (ctx->ctl_fd >= 0) ioctl(ctx->ctl_fd, CCCI_IOC_ENTER_DEEP_FLIGHT);
|
||||
dprintf(cfd, "OK flight=on\n");
|
||||
} else if (strcmp(buf, "flight off") == 0) {
|
||||
ctx->sm.flight_mode = false;
|
||||
(void)advance_ccci_stage(3);
|
||||
if (ctx->ctl_fd >= 0) ioctl(ctx->ctl_fd, CCCI_IOC_LEAVE_DEEP_FLIGHT);
|
||||
dprintf(cfd, "OK flight=off\n");
|
||||
} else {
|
||||
dprintf(cfd, "ERR unknown command\n");
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
ccci_ctx_t ctx;
|
||||
memset(&ctx, 0, sizeof(ctx));
|
||||
ctx.ctl_fd = ctx.fs_fd = ctx.rpc_fd = -1;
|
||||
geminux_ccci_sm_init(&ctx.sm);
|
||||
|
||||
mkdir("/run/geminux", 0755);
|
||||
mkdir("/var/lib/geminux", 0755);
|
||||
mkdir(NVRAM_DIR, 0755);
|
||||
|
||||
sigset_t mask;
|
||||
sigemptyset(&mask);
|
||||
sigaddset(&mask, SIGTERM);
|
||||
sigaddset(&mask, SIGINT);
|
||||
sigprocmask(SIG_BLOCK, &mask, NULL);
|
||||
ctx.sig_fd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC);
|
||||
|
||||
unlink(SOCK_PATH);
|
||||
ctx.srv_fd = socket(AF_UNIX, SOCK_STREAM | O_NONBLOCK | O_CLOEXEC, 0);
|
||||
if (ctx.srv_fd >= 0) {
|
||||
struct sockaddr_un addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sun_family = AF_UNIX;
|
||||
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", SOCK_PATH);
|
||||
if (bind(ctx.srv_fd, (struct sockaddr *)&addr, sizeof(addr)) == 0) {
|
||||
listen(ctx.srv_fd, 8);
|
||||
struct group *gr = getgrnam("wheel");
|
||||
if (gr) chown(SOCK_PATH, 0, gr->gr_gid);
|
||||
chmod(SOCK_PATH, 0660);
|
||||
}
|
||||
}
|
||||
|
||||
ctx.uev_fd = socket(PF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, NETLINK_KOBJECT_UEVENT);
|
||||
if (ctx.uev_fd >= 0) {
|
||||
struct sockaddr_nl nl = { .nl_family = AF_NETLINK, .nl_pid = (uint32_t)getpid(), .nl_groups = 1 };
|
||||
bind(ctx.uev_fd, (struct sockaddr *)&nl, sizeof(nl));
|
||||
}
|
||||
|
||||
ctx.epfd = epoll_create1(EPOLL_CLOEXEC);
|
||||
add_ep(ctx.epfd, ctx.sig_fd);
|
||||
add_ep(ctx.epfd, ctx.srv_fd);
|
||||
add_ep(ctx.epfd, ctx.uev_fd);
|
||||
open_ccci_devs(&ctx);
|
||||
|
||||
struct epoll_event events[12];
|
||||
bool running = true;
|
||||
while (running) {
|
||||
int n = epoll_wait(ctx.epfd, events, 12, -1);
|
||||
if (n < 0) {
|
||||
if (errno == EINTR) continue;
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < n; i++) {
|
||||
int fd = events[i].data.fd;
|
||||
if (fd == ctx.sig_fd) {
|
||||
struct signalfd_siginfo si;
|
||||
while (read(ctx.sig_fd, &si, sizeof(si)) > 0) {}
|
||||
running = false;
|
||||
} else if (fd == ctx.srv_fd) {
|
||||
int cfd;
|
||||
while ((cfd = accept4(ctx.srv_fd, NULL, NULL, SOCK_CLOEXEC)) >= 0) {
|
||||
handle_client(&ctx, cfd);
|
||||
close(cfd);
|
||||
}
|
||||
} else if (fd == ctx.uev_fd) {
|
||||
char ubuf[1024];
|
||||
while (recv(ctx.uev_fd, ubuf, sizeof(ubuf), 0) > 0) {}
|
||||
open_ccci_devs(&ctx);
|
||||
} else if (fd == ctx.ctl_fd) {
|
||||
handle_ctl_read(&ctx);
|
||||
} else if (fd == ctx.fs_fd || fd == ctx.rpc_fd) {
|
||||
handle_fs_or_rpc(&ctx, fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unlink(SOCK_PATH);
|
||||
close(ctx.epfd);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
#include "geminux-ccci-proto.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static uint32_t get_le32(const uint8_t *p) {
|
||||
return (uint32_t)p[0] | ((uint32_t)p[1] << 8) |
|
||||
((uint32_t)p[2] << 16) | ((uint32_t)p[3] << 24);
|
||||
}
|
||||
|
||||
void geminux_ccci_sm_init(geminux_ccci_sm_t *sm) {
|
||||
memset(sm, 0, sizeof(*sm));
|
||||
sm->state = MT6797_MD_STATE_GATED;
|
||||
}
|
||||
|
||||
void geminux_ccci_pack_hdr(struct mt6797_ccci_header *hdr, uint32_t data0,
|
||||
uint32_t data1, uint32_t ch, uint32_t reserved) {
|
||||
hdr->data0 = data0;
|
||||
hdr->data1 = data1;
|
||||
hdr->channel = ch;
|
||||
hdr->reserved = reserved;
|
||||
}
|
||||
|
||||
void geminux_ccci_unpack_hdr(const uint8_t raw[16], struct mt6797_ccci_header *hdr) {
|
||||
hdr->data0 = get_le32(raw + 0);
|
||||
hdr->data1 = get_le32(raw + 4);
|
||||
hdr->channel = get_le32(raw + 8);
|
||||
hdr->reserved = get_le32(raw + 12);
|
||||
}
|
||||
|
||||
const char *geminux_ccci_state_name(enum mt6797_ccci_md_state st) {
|
||||
switch (st) {
|
||||
case MT6797_MD_STATE_INVALID: return "INVALID";
|
||||
case MT6797_MD_STATE_GATED: return "GATED";
|
||||
case MT6797_MD_STATE_BOOTING: return "BOOTING";
|
||||
case MT6797_MD_STATE_HS1: return "HS1";
|
||||
case MT6797_MD_STATE_READY: return "READY";
|
||||
case MT6797_MD_STATE_EXCEPTION: return "EXCEPTION";
|
||||
case MT6797_MD_STATE_RESET: return "RESET";
|
||||
default: return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
bool geminux_ccci_handle_ctrl(geminux_ccci_sm_t *sm,
|
||||
const struct mt6797_ccci_header *rx,
|
||||
struct mt6797_ccci_header *tx_reply,
|
||||
bool *need_reply) {
|
||||
if (!sm || !rx || !tx_reply || !need_reply) return false;
|
||||
*need_reply = false;
|
||||
sm->rx_packets++;
|
||||
|
||||
if (rx->channel != MT6797_CCCI_CH_CONTROL_RX &&
|
||||
rx->channel != MT6797_CCCI_CH_STATUS_RX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (rx->data1) {
|
||||
case MT6797_CCCI_MSG_HS1:
|
||||
sm->state = MT6797_MD_STATE_HS1;
|
||||
geminux_ccci_pack_hdr(tx_reply, 0, MT6797_CCCI_MSG_HS1,
|
||||
MT6797_CCCI_CH_CONTROL_TX, rx->reserved);
|
||||
*need_reply = true;
|
||||
sm->tx_packets++;
|
||||
return true;
|
||||
case MT6797_CCCI_MSG_MD_INIT_START_BOOT:
|
||||
sm->state = MT6797_MD_STATE_BOOTING;
|
||||
return true;
|
||||
case MT6797_CCCI_MSG_NORMAL_BOOT_READY:
|
||||
case MT6797_CCCI_MSG_META_BOOT_READY:
|
||||
sm->state = MT6797_MD_STATE_READY;
|
||||
return true;
|
||||
case MT6797_CCCI_MSG_MD_EX:
|
||||
sm->state = MT6797_MD_STATE_EXCEPTION;
|
||||
return true;
|
||||
case MT6797_CCCI_MSG_MD_EX_REC_OK:
|
||||
sm->state = MT6797_MD_STATE_RESET;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef GEMINUX_CCCI_PROTO_H
|
||||
#define GEMINUX_CCCI_PROTO_H
|
||||
|
||||
#include <linux/mt6797_ccci.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
enum mt6797_ccci_md_state state;
|
||||
bool flight_mode;
|
||||
uint32_t tx_packets;
|
||||
uint32_t rx_packets;
|
||||
} geminux_ccci_sm_t;
|
||||
|
||||
void geminux_ccci_sm_init(geminux_ccci_sm_t *sm);
|
||||
void geminux_ccci_pack_hdr(struct mt6797_ccci_header *hdr, uint32_t data0,
|
||||
uint32_t data1, uint32_t ch, uint32_t reserved);
|
||||
void geminux_ccci_unpack_hdr(const uint8_t raw[16], struct mt6797_ccci_header *hdr);
|
||||
const char *geminux_ccci_state_name(enum mt6797_ccci_md_state st);
|
||||
bool geminux_ccci_handle_ctrl(geminux_ccci_sm_t *sm,
|
||||
const struct mt6797_ccci_header *rx,
|
||||
struct mt6797_ccci_header *tx_reply,
|
||||
bool *need_reply);
|
||||
|
||||
#endif /* GEMINUX_CCCI_PROTO_H */
|
||||
@@ -0,0 +1,47 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#define _XOPEN_SOURCE 700
|
||||
#include <crypt.h>
|
||||
#include <shadow.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static int ct_strcmp(const char *a, const char *b) {
|
||||
size_t la = strlen(a), lb = strlen(b);
|
||||
unsigned int diff = (unsigned int)(la ^ lb);
|
||||
size_t m = la < lb ? la : lb;
|
||||
for (size_t i = 0; i < m; i++) {
|
||||
diff |= (unsigned int)((unsigned char)a[i] ^ (unsigned char)b[i]);
|
||||
}
|
||||
return diff != 0;
|
||||
}
|
||||
|
||||
static void trim_nl(char *s) {
|
||||
size_t n = strlen(s);
|
||||
while (n > 0 && (s[n - 1] == '\n' || s[n - 1] == '\r')) s[--n] = '\0';
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
char user[64] = {0};
|
||||
char pass[128] = {0};
|
||||
if (!fgets(user, sizeof(user), stdin) || !fgets(pass, sizeof(pass), stdin)) {
|
||||
return 1;
|
||||
}
|
||||
trim_nl(user);
|
||||
trim_nl(pass);
|
||||
if (!user[0]) return 1;
|
||||
|
||||
struct spwd *sp = getspnam(user);
|
||||
if (!sp || !sp->sp_pwdp || !sp->sp_pwdp[0] || sp->sp_pwdp[0] == '!' || sp->sp_pwdp[0] == '*') {
|
||||
volatile char *vp = pass;
|
||||
for (size_t i = 0; i < sizeof(pass); i++) vp[i] = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *hashed = crypt(pass, sp->sp_pwdp);
|
||||
volatile char *vp = pass;
|
||||
for (size_t i = 0; i < sizeof(pass); i++) vp[i] = 0;
|
||||
if (!hashed) return 1;
|
||||
|
||||
return ct_strcmp(hashed, sp->sp_pwdp) == 0 ? 0 : 1;
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <grp.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/signalfd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define LEDS_SOCK "/run/geminux/leds.sock"
|
||||
|
||||
static void write_led(const char *channel, int val) {
|
||||
DIR *d = opendir("/sys/class/leds");
|
||||
if (!d) return;
|
||||
struct dirent *de;
|
||||
while ((de = readdir(d)) != NULL) {
|
||||
if (de->d_name[0] == '.') continue;
|
||||
if (strstr(de->d_name, channel)) {
|
||||
char p[320];
|
||||
snprintf(p, sizeof(p), "/sys/class/leds/%s/brightness", de->d_name);
|
||||
int fd = open(p, O_WRONLY | O_CLOEXEC);
|
||||
if (fd >= 0) {
|
||||
dprintf(fd, "%d\n", val);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
static void apply_rgb(int r, int g, int b) {
|
||||
write_led("red", r);
|
||||
write_led("green", g);
|
||||
write_led("blue", b);
|
||||
}
|
||||
|
||||
static void sync_charging_led(void) {
|
||||
DIR *d = opendir("/sys/class/power_supply");
|
||||
if (!d) return;
|
||||
struct dirent *de;
|
||||
while ((de = readdir(d)) != NULL) {
|
||||
if (de->d_name[0] == '.') continue;
|
||||
char p[320], typ[32] = {0}, st[32] = {0};
|
||||
snprintf(p, sizeof(p), "/sys/class/power_supply/%s/type", de->d_name);
|
||||
FILE *ft = fopen(p, "r");
|
||||
if (!ft) continue;
|
||||
if (fgets(typ, sizeof(typ), ft)) {
|
||||
size_t ln = strlen(typ);
|
||||
while (ln > 0 && typ[ln - 1] == '\n') typ[--ln] = '\0';
|
||||
}
|
||||
fclose(ft);
|
||||
if (strcmp(typ, "Battery") != 0) continue;
|
||||
|
||||
snprintf(p, sizeof(p), "/sys/class/power_supply/%s/status", de->d_name);
|
||||
FILE *fs = fopen(p, "r");
|
||||
if (fs) {
|
||||
if (fgets(st, sizeof(st), fs)) {
|
||||
size_t ln = strlen(st);
|
||||
while (ln > 0 && st[ln - 1] == '\n') st[--ln] = '\0';
|
||||
}
|
||||
fclose(fs);
|
||||
}
|
||||
if (strcmp(st, "Charging") == 0) apply_rgb(32, 16, 0);
|
||||
else if (strcmp(st, "Full") == 0) apply_rgb(0, 32, 0);
|
||||
else apply_rgb(0, 0, 0);
|
||||
break;
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
mkdir("/run/geminux", 0755);
|
||||
|
||||
sigset_t mask;
|
||||
sigemptyset(&mask);
|
||||
sigaddset(&mask, SIGTERM);
|
||||
sigaddset(&mask, SIGINT);
|
||||
sigprocmask(SIG_BLOCK, &mask, NULL);
|
||||
int sig_fd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC);
|
||||
|
||||
unlink(LEDS_SOCK);
|
||||
int srv_fd = socket(AF_UNIX, SOCK_STREAM | O_NONBLOCK | O_CLOEXEC, 0);
|
||||
if (srv_fd >= 0) {
|
||||
struct sockaddr_un addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sun_family = AF_UNIX;
|
||||
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", LEDS_SOCK);
|
||||
if (bind(srv_fd, (struct sockaddr *)&addr, sizeof(addr)) == 0) {
|
||||
listen(srv_fd, 8);
|
||||
struct group *gr = getgrnam("wheel");
|
||||
if (gr) chown(LEDS_SOCK, 0, gr->gr_gid);
|
||||
chmod(LEDS_SOCK, 0660);
|
||||
}
|
||||
}
|
||||
|
||||
int uev_fd = socket(PF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, NETLINK_KOBJECT_UEVENT);
|
||||
if (uev_fd >= 0) {
|
||||
struct sockaddr_nl nl = { .nl_family = AF_NETLINK, .nl_pid = (uint32_t)getpid(), .nl_groups = 1 };
|
||||
bind(uev_fd, (struct sockaddr *)&nl, sizeof(nl));
|
||||
}
|
||||
|
||||
int tmr_fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
|
||||
|
||||
int epfd = epoll_create1(EPOLL_CLOEXEC);
|
||||
int fds[4] = {sig_fd, srv_fd, uev_fd, tmr_fd};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (fds[i] >= 0) {
|
||||
struct epoll_event ev = { .events = EPOLLIN, .data.fd = fds[i] };
|
||||
epoll_ctl(epfd, EPOLL_CTL_ADD, fds[i], &ev);
|
||||
}
|
||||
}
|
||||
|
||||
sync_charging_led();
|
||||
|
||||
struct epoll_event events[8];
|
||||
bool running = true;
|
||||
while (running) {
|
||||
int n = epoll_wait(epfd, events, 8, -1);
|
||||
if (n < 0) {
|
||||
if (errno == EINTR) continue;
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < n; i++) {
|
||||
int fd = events[i].data.fd;
|
||||
if (fd == sig_fd) {
|
||||
running = false;
|
||||
} else if (fd == srv_fd) {
|
||||
int cfd;
|
||||
while ((cfd = accept4(srv_fd, NULL, NULL, SOCK_CLOEXEC)) >= 0) {
|
||||
char cmd[128] = {0};
|
||||
ssize_t r = read(cfd, cmd, sizeof(cmd) - 1);
|
||||
if (r > 0) {
|
||||
while (r > 0 && (cmd[r - 1] == '\n' || cmd[r - 1] == '\r')) cmd[--r] = '\0';
|
||||
int rr = 0, gg = 0, bb = 0, ms = 0;
|
||||
if (strcmp(cmd, "off") == 0) {
|
||||
apply_rgb(0, 0, 0);
|
||||
} else if (sscanf(cmd, "rgb %d %d %d", &rr, &gg, &bb) == 3) {
|
||||
apply_rgb(rr, gg, bb);
|
||||
} else if (sscanf(cmd, "pulse %d %d %d %d", &rr, &gg, &bb, &ms) == 4) {
|
||||
apply_rgb(rr, gg, bb);
|
||||
struct itimerspec its;
|
||||
memset(&its, 0, sizeof(its));
|
||||
its.it_value.tv_sec = ms / 1000;
|
||||
its.it_value.tv_nsec = (ms % 1000) * 1000000L;
|
||||
timerfd_settime(tmr_fd, 0, &its, NULL);
|
||||
}
|
||||
}
|
||||
dprintf(cfd, "OK\n");
|
||||
close(cfd);
|
||||
}
|
||||
} else if (fd == tmr_fd) {
|
||||
uint64_t exp = 0;
|
||||
while (read(tmr_fd, &exp, sizeof(exp)) > 0) {}
|
||||
sync_charging_led();
|
||||
} else if (fd == uev_fd) {
|
||||
char ubuf[1024];
|
||||
while (recv(uev_fd, ubuf, sizeof(ubuf), 0) > 0) {}
|
||||
sync_charging_led();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unlink(LEDS_SOCK);
|
||||
close(epfd);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/signalfd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/wait.h>
|
||||
#include <termios.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define MODEM_SOCK "/run/geminux/modem.sock"
|
||||
#define STATE_FILE "/run/geminux/modem-state"
|
||||
#define AT_DEV "/dev/ttyC0"
|
||||
|
||||
typedef struct {
|
||||
int epfd;
|
||||
int sig_fd;
|
||||
int srv_fd;
|
||||
int at_fd;
|
||||
bool in_call;
|
||||
bool muted;
|
||||
bool speaker;
|
||||
char active_peer[64];
|
||||
} modem_ctx_t;
|
||||
|
||||
static void spawn_bg(const char *const argv[]) {
|
||||
pid_t pid = fork();
|
||||
if (pid == 0) {
|
||||
setsid();
|
||||
pid_t p2 = fork();
|
||||
if (p2 == 0) {
|
||||
int devnull = open("/dev/null", O_RDWR);
|
||||
if (devnull >= 0) {
|
||||
dup2(devnull, STDIN_FILENO);
|
||||
dup2(devnull, STDOUT_FILENO);
|
||||
dup2(devnull, STDERR_FILENO);
|
||||
if (devnull > 2) close(devnull);
|
||||
}
|
||||
execvp(argv[0], (char *const *)argv);
|
||||
_exit(127);
|
||||
}
|
||||
_exit(0);
|
||||
}
|
||||
if (pid > 0) waitpid(pid, NULL, 0);
|
||||
}
|
||||
|
||||
static void write_state(const modem_ctx_t *ctx) {
|
||||
FILE *f = fopen(STATE_FILE, "w");
|
||||
if (!f) return;
|
||||
if (ctx->in_call) {
|
||||
fprintf(f, "CALL:%s\n", ctx->active_peer[0] ? ctx->active_peer : "ACTIVE");
|
||||
} else if (ctx->at_fd >= 0) {
|
||||
fprintf(f, "4G:READY\n");
|
||||
} else {
|
||||
fprintf(f, "4G:STANDBY\n");
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static void send_at(modem_ctx_t *ctx, const char *cmd) {
|
||||
if (ctx->at_fd < 0) return;
|
||||
dprintf(ctx->at_fd, "%s\r\n", cmd);
|
||||
}
|
||||
|
||||
static void set_audio_verb(const char *verb) {
|
||||
const char *cmd[] = {"alsaucm", "-c", "mt6797-gemini", "set", "_verb", verb, NULL};
|
||||
spawn_bg(cmd);
|
||||
}
|
||||
|
||||
static void save_sms_row(const char *dir_tag, const char *peer, const char *text) {
|
||||
const char *home = getenv("HOME");
|
||||
char dir[512], fp[600], ts[32];
|
||||
snprintf(dir, sizeof(dir), "%s/.local/share/geminux/sms",
|
||||
(home && home[0]) ? home : "/home/user");
|
||||
mkdir(dir, 0755);
|
||||
snprintf(fp, sizeof(fp), "%s/%s.tsv", dir, peer);
|
||||
FILE *f = fopen(fp, "a");
|
||||
if (!f) return;
|
||||
time_t now = time(NULL);
|
||||
struct tm tm;
|
||||
localtime_r(&now, &tm);
|
||||
strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M", &tm);
|
||||
fprintf(f, "%s\t%s\t%s\n", dir_tag, ts, text);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static void open_at_port(modem_ctx_t *ctx) {
|
||||
if (ctx->at_fd >= 0) return;
|
||||
int fd = open(AT_DEV, O_RDWR | O_NOCTTY | O_NONBLOCK | O_CLOEXEC);
|
||||
if (fd < 0) return;
|
||||
struct termios tio;
|
||||
if (tcgetattr(fd, &tio) == 0) {
|
||||
cfmakeraw(&tio);
|
||||
cfsetispeed(&tio, B115200);
|
||||
cfsetospeed(&tio, B115200);
|
||||
tcsetattr(fd, TCSANOW, &tio);
|
||||
}
|
||||
struct epoll_event ev = { .events = EPOLLIN, .data.fd = fd };
|
||||
if (epoll_ctl(ctx->epfd, EPOLL_CTL_ADD, fd, &ev) == 0) {
|
||||
ctx->at_fd = fd;
|
||||
send_at(ctx, "ATE0");
|
||||
send_at(ctx, "AT+CMGF=1");
|
||||
} else {
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_cmd(modem_ctx_t *ctx, int cfd) {
|
||||
char buf[512] = {0};
|
||||
ssize_t n = read(cfd, buf, sizeof(buf) - 1);
|
||||
if (n <= 0) return;
|
||||
while (n > 0 && (buf[n - 1] == '\n' || buf[n - 1] == '\r')) buf[--n] = '\0';
|
||||
|
||||
if (strncmp(buf, "dial ", 5) == 0) {
|
||||
snprintf(ctx->active_peer, sizeof(ctx->active_peer), "%s", buf + 5);
|
||||
ctx->in_call = true;
|
||||
const char *inh[] = {"geminux-power-ctl", "inhibit", "add", "call", NULL};
|
||||
spawn_bg(inh);
|
||||
set_audio_verb("VoiceCall");
|
||||
char at[96];
|
||||
snprintf(at, sizeof(at), "ATD%s;", ctx->active_peer);
|
||||
send_at(ctx, at);
|
||||
write_state(ctx);
|
||||
dprintf(cfd, "OK dialing %s\n", ctx->active_peer);
|
||||
} else if (strcmp(buf, "answer") == 0) {
|
||||
ctx->in_call = true;
|
||||
const char *inh[] = {"geminux-power-ctl", "inhibit", "add", "call", NULL};
|
||||
spawn_bg(inh);
|
||||
set_audio_verb("VoiceCall");
|
||||
send_at(ctx, "ATA");
|
||||
write_state(ctx);
|
||||
dprintf(cfd, "OK answered\n");
|
||||
} else if (strcmp(buf, "hangup") == 0) {
|
||||
ctx->in_call = false;
|
||||
ctx->active_peer[0] = '\0';
|
||||
send_at(ctx, "ATH");
|
||||
set_audio_verb("HiFi");
|
||||
const char *inh[] = {"geminux-power-ctl", "inhibit", "del", "call", NULL};
|
||||
spawn_bg(inh);
|
||||
write_state(ctx);
|
||||
dprintf(cfd, "OK hangup\n");
|
||||
} else if (strcmp(buf, "mute on") == 0 || strcmp(buf, "mute off") == 0) {
|
||||
ctx->muted = (strcmp(buf, "mute on") == 0);
|
||||
const char *m[] = {"wpctl", "set-mute", "@DEFAULT_AUDIO_SOURCE@", ctx->muted ? "1" : "0", NULL};
|
||||
spawn_bg(m);
|
||||
dprintf(cfd, "OK mute=%d\n", ctx->muted ? 1 : 0);
|
||||
} else if (strcmp(buf, "speaker on") == 0 || strcmp(buf, "speaker off") == 0) {
|
||||
ctx->speaker = (strcmp(buf, "speaker on") == 0);
|
||||
dprintf(cfd, "OK speaker=%d\n", ctx->speaker ? 1 : 0);
|
||||
} else if (strncmp(buf, "dtmf ", 5) == 0 && buf[5]) {
|
||||
char at[32];
|
||||
snprintf(at, sizeof(at), "AT+VTS=\"%c\"", buf[5]);
|
||||
send_at(ctx, at);
|
||||
dprintf(cfd, "OK dtmf\n");
|
||||
} else if (strncmp(buf, "sms-send ", 9) == 0) {
|
||||
char *sp = strchr(buf + 9, ' ');
|
||||
if (!sp) {
|
||||
dprintf(cfd, "ERR usage sms-send <num> <text>\n");
|
||||
return;
|
||||
}
|
||||
*sp = '\0';
|
||||
const char *peer = buf + 9;
|
||||
const char *text = sp + 1;
|
||||
save_sms_row("OUT", peer, text);
|
||||
const char *mm[] = {"mmcli", "-m", "0", "--messaging-create-sms", text, NULL};
|
||||
spawn_bg(mm);
|
||||
dprintf(cfd, "OK sms queued\n");
|
||||
} else if (strcmp(buf, "status") == 0) {
|
||||
dprintf(cfd, "in_call=%d at_dev=%d peer=%s\n",
|
||||
ctx->in_call ? 1 : 0, ctx->at_fd >= 0 ? 1 : 0,
|
||||
ctx->active_peer[0] ? ctx->active_peer : "none");
|
||||
} else {
|
||||
dprintf(cfd, "ERR unknown\n");
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
modem_ctx_t ctx;
|
||||
memset(&ctx, 0, sizeof(ctx));
|
||||
ctx.at_fd = -1;
|
||||
mkdir("/run/geminux", 0755);
|
||||
|
||||
sigset_t mask;
|
||||
sigemptyset(&mask);
|
||||
sigaddset(&mask, SIGTERM);
|
||||
sigaddset(&mask, SIGINT);
|
||||
sigprocmask(SIG_BLOCK, &mask, NULL);
|
||||
ctx.sig_fd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC);
|
||||
|
||||
unlink(MODEM_SOCK);
|
||||
ctx.srv_fd = socket(AF_UNIX, SOCK_STREAM | O_NONBLOCK | O_CLOEXEC, 0);
|
||||
if (ctx.srv_fd >= 0) {
|
||||
struct sockaddr_un addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sun_family = AF_UNIX;
|
||||
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", MODEM_SOCK);
|
||||
if (bind(ctx.srv_fd, (struct sockaddr *)&addr, sizeof(addr)) == 0) {
|
||||
listen(ctx.srv_fd, 8);
|
||||
chmod(MODEM_SOCK, 0660);
|
||||
}
|
||||
}
|
||||
|
||||
ctx.epfd = epoll_create1(EPOLL_CLOEXEC);
|
||||
int fixed[2] = {ctx.sig_fd, ctx.srv_fd};
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (fixed[i] >= 0) {
|
||||
struct epoll_event ev = { .events = EPOLLIN, .data.fd = fixed[i] };
|
||||
epoll_ctl(ctx.epfd, EPOLL_CTL_ADD, fixed[i], &ev);
|
||||
}
|
||||
}
|
||||
open_at_port(&ctx);
|
||||
write_state(&ctx);
|
||||
|
||||
struct epoll_event events[8];
|
||||
bool running = true;
|
||||
while (running) {
|
||||
int n = epoll_wait(ctx.epfd, events, 8, -1);
|
||||
if (n < 0) {
|
||||
if (errno == EINTR) continue;
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < n; i++) {
|
||||
int fd = events[i].data.fd;
|
||||
if (fd == ctx.sig_fd) {
|
||||
running = false;
|
||||
} else if (fd == ctx.srv_fd) {
|
||||
int cfd;
|
||||
while ((cfd = accept4(ctx.srv_fd, NULL, NULL, SOCK_CLOEXEC)) >= 0) {
|
||||
handle_cmd(&ctx, cfd);
|
||||
close(cfd);
|
||||
}
|
||||
} else if (fd == ctx.at_fd) {
|
||||
char atbuf[512] = {0};
|
||||
ssize_t r = read(ctx.at_fd, atbuf, sizeof(atbuf) - 1);
|
||||
if (r > 0) {
|
||||
if (strstr(atbuf, "RING")) {
|
||||
const char *ntf[] = {"notify-send", "Incoming Call", "Voice call on MT6797 LTE", NULL};
|
||||
spawn_bg(ntf);
|
||||
const char *cs[] = {"geminux-callscreen", "Incoming", "--incoming", NULL};
|
||||
spawn_bg(cs);
|
||||
} else if (strstr(atbuf, "+CMT:")) {
|
||||
const char *ntf[] = {"notify-send", "New SMS", "Message received", NULL};
|
||||
spawn_bg(ntf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unlink(MODEM_SOCK);
|
||||
close(ctx.epfd);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <dirent.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static int read_str(const char *path, char *buf, size_t sz) {
|
||||
FILE *f = fopen(path, "r");
|
||||
if (!f) return -1;
|
||||
if (!fgets(buf, (int)sz, f)) {
|
||||
fclose(f);
|
||||
return -1;
|
||||
}
|
||||
fclose(f);
|
||||
size_t n = strlen(buf);
|
||||
while (n > 0 && (buf[n - 1] == '\n' || buf[n - 1] == '\r')) buf[--n] = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
bool json = (argc > 1 && strcmp(argv[1], "--json") == 0);
|
||||
|
||||
char mem_sleep[128] = "unknown", zram_algo[128] = "unknown";
|
||||
char profile[64] = "balanced";
|
||||
read_str("/sys/power/mem_sleep", mem_sleep, sizeof(mem_sleep));
|
||||
read_str("/sys/block/zram0/comp_algorithm", zram_algo, sizeof(zram_algo));
|
||||
read_str("/run/geminux/power-profile", profile, sizeof(profile));
|
||||
|
||||
char bat_cap[32] = "?", bat_status[32] = "Unknown", bat_uv[32] = "?", bat_ua[32] = "?";
|
||||
DIR *d = opendir("/sys/class/power_supply");
|
||||
if (d) {
|
||||
struct dirent *de;
|
||||
while ((de = readdir(d)) != NULL) {
|
||||
if (de->d_name[0] == '.') continue;
|
||||
char p[320], typ[32] = {0};
|
||||
snprintf(p, sizeof(p), "/sys/class/power_supply/%s/type", de->d_name);
|
||||
if (read_str(p, typ, sizeof(typ)) == 0 && strcmp(typ, "Battery") == 0) {
|
||||
snprintf(p, sizeof(p), "/sys/class/power_supply/%s/capacity", de->d_name);
|
||||
read_str(p, bat_cap, sizeof(bat_cap));
|
||||
snprintf(p, sizeof(p), "/sys/class/power_supply/%s/status", de->d_name);
|
||||
read_str(p, bat_status, sizeof(bat_status));
|
||||
snprintf(p, sizeof(p), "/sys/class/power_supply/%s/voltage_now", de->d_name);
|
||||
read_str(p, bat_uv, sizeof(bat_uv));
|
||||
snprintf(p, sizeof(p), "/sys/class/power_supply/%s/current_now", de->d_name);
|
||||
read_str(p, bat_ua, sizeof(bat_ua));
|
||||
break;
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
int online_cpus = 0, a72_online = 0;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
char p[128], v[16] = "1";
|
||||
snprintf(p, sizeof(p), "/sys/devices/system/cpu/cpu%d/online", i);
|
||||
read_str(p, v, sizeof(v));
|
||||
if (atoi(v) != 0) {
|
||||
online_cpus++;
|
||||
if (i >= 8) a72_online++;
|
||||
}
|
||||
}
|
||||
|
||||
char gov0[64] = "unknown";
|
||||
read_str("/sys/devices/system/cpu/cpufreq/policy0/scaling_governor", gov0, sizeof(gov0));
|
||||
|
||||
if (json) {
|
||||
printf("{\"profile\":\"%s\",\"battery_pct\":\"%s\",\"battery_status\":\"%s\","
|
||||
"\"voltage_uv\":\"%s\",\"current_ua\":\"%s\",\"online_cpus\":%d,"
|
||||
"\"a72_online\":%d,\"governor\":\"%s\",\"zram_algo\":\"%s\",\"mem_sleep\":\"%s\"}\n",
|
||||
profile, bat_cap, bat_status, bat_uv, bat_ua, online_cpus, a72_online,
|
||||
gov0, zram_algo, mem_sleep);
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("Geminux Power & Efficiency Audit\n");
|
||||
printf("----------------------------------------\n");
|
||||
printf("Power Profile : %s\n", profile);
|
||||
printf("Battery Status : %s%% (%s, V=%s uV, I=%s uA)\n", bat_cap, bat_status, bat_uv, bat_ua);
|
||||
printf("CPUs Online : %d total (%d A72 big cores online)\n", online_cpus, a72_online);
|
||||
printf("CPUfreq Governor : %s\n", gov0);
|
||||
printf("ZRAM Compression : %s\n", zram_algo);
|
||||
printf("Suspend Modes : %s\n", mem_sleep);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define SOCK_PATH "/run/geminux/powerd.sock"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage: %s <status|suspend|profile eco|balanced|performance|inhibit add|del TAG|lid-suspend on|off>\n",
|
||||
argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
char cmd[256] = {0};
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (i > 1 && strlen(cmd) + 1 < sizeof(cmd)) strcat(cmd, " ");
|
||||
strncat(cmd, argv[i], sizeof(cmd) - strlen(cmd) - 2);
|
||||
}
|
||||
|
||||
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (fd >= 0) {
|
||||
struct sockaddr_un addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sun_family = AF_UNIX;
|
||||
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", SOCK_PATH);
|
||||
if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0) {
|
||||
dprintf(fd, "%s\n", cmd);
|
||||
shutdown(fd, SHUT_WR);
|
||||
char resp[512];
|
||||
ssize_t n;
|
||||
while ((n = read(fd, resp, sizeof(resp))) > 0) {
|
||||
fwrite(resp, 1, (size_t)n, stdout);
|
||||
}
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "suspend") == 0) {
|
||||
int pfd = open("/sys/power/state", O_WRONLY);
|
||||
if (pfd >= 0) {
|
||||
ssize_t w = write(pfd, "mem", 3);
|
||||
close(pfd);
|
||||
return (w == 3) ? 0 : 1;
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "geminux-power-ctl: cannot connect to %s\n", SOCK_PATH);
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "geminux-power-policy.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void geminux_policy_init(geminux_power_policy_t *p) {
|
||||
memset(p, 0, sizeof(*p));
|
||||
p->profile = POWER_PROFILE_BALANCED;
|
||||
p->lid_suspend_enabled = true;
|
||||
}
|
||||
|
||||
bool geminux_policy_set_profile_name(geminux_power_policy_t *p, const char *name) {
|
||||
if (!p || !name) return false;
|
||||
if (strcmp(name, "eco") == 0) {
|
||||
p->profile = POWER_PROFILE_ECO;
|
||||
return true;
|
||||
}
|
||||
if (strcmp(name, "balanced") == 0) {
|
||||
p->profile = POWER_PROFILE_BALANCED;
|
||||
return true;
|
||||
}
|
||||
if (strcmp(name, "performance") == 0) {
|
||||
p->profile = POWER_PROFILE_PERFORMANCE;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *geminux_policy_profile_name(geminux_profile_t prof) {
|
||||
switch (prof) {
|
||||
case POWER_PROFILE_ECO: return "eco";
|
||||
case POWER_PROFILE_PERFORMANCE: return "performance";
|
||||
case POWER_PROFILE_BALANCED:
|
||||
default: return "balanced";
|
||||
}
|
||||
}
|
||||
|
||||
geminux_profile_params_t geminux_policy_params(geminux_profile_t prof, bool on_ac) {
|
||||
geminux_profile_params_t out;
|
||||
out.governor = "schedutil";
|
||||
if (prof == POWER_PROFILE_ECO) {
|
||||
out.a72_online = false;
|
||||
out.a53_max_khz = 1391000UL;
|
||||
out.a72_max_khz = 0UL;
|
||||
out.dim_timeout_s = on_ac ? 180 : 60;
|
||||
out.suspend_timeout_s = on_ac ? 0 : 180;
|
||||
} else if (prof == POWER_PROFILE_PERFORMANCE) {
|
||||
out.a72_online = true;
|
||||
out.a53_max_khz = 1846000UL;
|
||||
out.a72_max_khz = 2600000UL;
|
||||
out.dim_timeout_s = on_ac ? 600 : 180;
|
||||
out.suspend_timeout_s = 0;
|
||||
} else {
|
||||
out.a72_online = true;
|
||||
out.a53_max_khz = 1547000UL;
|
||||
out.a72_max_khz = 2002000UL;
|
||||
out.dim_timeout_s = on_ac ? 300 : 120;
|
||||
out.suspend_timeout_s = on_ac ? 0 : 300;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
bool geminux_policy_add_inhibit(geminux_power_policy_t *p, const char *tag) {
|
||||
if (!p || !tag || !tag[0]) return false;
|
||||
for (int i = 0; i < p->inhibit_count; i++) {
|
||||
if (strcmp(p->inhibitors[i], tag) == 0) return true;
|
||||
}
|
||||
if (p->inhibit_count >= GEMINUX_MAX_INHIBITORS) return false;
|
||||
snprintf(p->inhibitors[p->inhibit_count], sizeof(p->inhibitors[0]), "%s", tag);
|
||||
p->inhibit_count++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool geminux_policy_del_inhibit(geminux_power_policy_t *p, const char *tag) {
|
||||
if (!p || !tag || !tag[0]) return false;
|
||||
for (int i = 0; i < p->inhibit_count; i++) {
|
||||
if (strcmp(p->inhibitors[i], tag) == 0) {
|
||||
for (int j = i; j + 1 < p->inhibit_count; j++) {
|
||||
memcpy(p->inhibitors[j], p->inhibitors[j + 1], sizeof(p->inhibitors[0]));
|
||||
}
|
||||
p->inhibit_count--;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool geminux_should_suspend_on_lid(const geminux_power_policy_t *p) {
|
||||
if (!p || !p->lid_closed || !p->lid_suspend_enabled) return false;
|
||||
if (p->hdmi_connected) return false;
|
||||
if (p->inhibit_count > 0) return false;
|
||||
if (p->on_ac_power && p->inhibit_ac_lid) return false;
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef GEMINUX_POWER_POLICY_H
|
||||
#define GEMINUX_POWER_POLICY_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#define GEMINUX_MAX_INHIBITORS 16
|
||||
|
||||
typedef enum {
|
||||
POWER_PROFILE_ECO = 0,
|
||||
POWER_PROFILE_BALANCED = 1,
|
||||
POWER_PROFILE_PERFORMANCE = 2,
|
||||
} geminux_profile_t;
|
||||
|
||||
typedef struct {
|
||||
geminux_profile_t profile;
|
||||
bool lid_closed;
|
||||
bool lid_suspend_enabled;
|
||||
bool on_ac_power;
|
||||
bool inhibit_ac_lid;
|
||||
bool hdmi_connected;
|
||||
char inhibitors[GEMINUX_MAX_INHIBITORS][32];
|
||||
int inhibit_count;
|
||||
} geminux_power_policy_t;
|
||||
|
||||
typedef struct {
|
||||
const char *governor;
|
||||
bool a72_online;
|
||||
unsigned long a53_max_khz;
|
||||
unsigned long a72_max_khz;
|
||||
int dim_timeout_s;
|
||||
int suspend_timeout_s;
|
||||
} geminux_profile_params_t;
|
||||
|
||||
void geminux_policy_init(geminux_power_policy_t *p);
|
||||
bool geminux_policy_set_profile_name(geminux_power_policy_t *p, const char *name);
|
||||
const char *geminux_policy_profile_name(geminux_profile_t prof);
|
||||
geminux_profile_params_t geminux_policy_params(geminux_profile_t prof, bool on_ac);
|
||||
bool geminux_policy_add_inhibit(geminux_power_policy_t *p, const char *tag);
|
||||
bool geminux_policy_del_inhibit(geminux_power_policy_t *p, const char *tag);
|
||||
bool geminux_should_suspend_on_lid(const geminux_power_policy_t *p);
|
||||
|
||||
#endif /* GEMINUX_POWER_POLICY_H */
|
||||
@@ -0,0 +1,367 @@
|
||||
#define _GNU_SOURCE
|
||||
#include "geminux-power-policy.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <grp.h>
|
||||
#include <linux/input.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/signalfd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define SOCK_PATH "/run/geminux/powerd.sock"
|
||||
#define PROFILE_FILE "/run/geminux/power-profile"
|
||||
#define MAX_EVDEVS 16
|
||||
|
||||
typedef struct {
|
||||
int epfd;
|
||||
int sig_fd;
|
||||
int uev_fd;
|
||||
int srv_fd;
|
||||
int tmr_fd;
|
||||
int ev_fds[MAX_EVDEVS];
|
||||
int num_ev;
|
||||
int saved_brightness;
|
||||
geminux_power_policy_t policy;
|
||||
} powerd_ctx_t;
|
||||
|
||||
static int write_sysfs_str(const char *path, const char *val) {
|
||||
int fd = open(path, O_WRONLY | O_CLOEXEC);
|
||||
if (fd < 0) return -1;
|
||||
ssize_t w = write(fd, val, strlen(val));
|
||||
close(fd);
|
||||
return (w >= 0) ? 0 : -1;
|
||||
}
|
||||
|
||||
static int read_sysfs_line(const char *path, char *buf, size_t sz) {
|
||||
FILE *f = fopen(path, "r");
|
||||
if (!f) return -1;
|
||||
if (!fgets(buf, (int)sz, f)) {
|
||||
fclose(f);
|
||||
return -1;
|
||||
}
|
||||
fclose(f);
|
||||
size_t n = strlen(buf);
|
||||
while (n > 0 && (buf[n - 1] == '\n' || buf[n - 1] == '\r')) buf[--n] = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void refresh_ac_and_hdmi(powerd_ctx_t *ctx) {
|
||||
ctx->policy.on_ac_power = false;
|
||||
DIR *d = opendir("/sys/class/power_supply");
|
||||
if (d) {
|
||||
struct dirent *de;
|
||||
while ((de = readdir(d)) != NULL) {
|
||||
if (de->d_name[0] == '.') continue;
|
||||
char p[320], typ[32] = {0}, onl[16] = {0};
|
||||
snprintf(p, sizeof(p), "/sys/class/power_supply/%s/type", de->d_name);
|
||||
if (read_sysfs_line(p, typ, sizeof(typ)) == 0 && strcmp(typ, "Battery") != 0) {
|
||||
snprintf(p, sizeof(p), "/sys/class/power_supply/%s/online", de->d_name);
|
||||
if (read_sysfs_line(p, onl, sizeof(onl)) == 0 && atoi(onl) == 1) {
|
||||
ctx->policy.on_ac_power = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
ctx->policy.hdmi_connected = false;
|
||||
d = opendir("/sys/class/drm");
|
||||
if (d) {
|
||||
struct dirent *de;
|
||||
while ((de = readdir(d)) != NULL) {
|
||||
if (!strstr(de->d_name, "HDMI")) continue;
|
||||
char p[320], st[32] = {0};
|
||||
snprintf(p, sizeof(p), "/sys/class/drm/%s/status", de->d_name);
|
||||
if (read_sysfs_line(p, st, sizeof(st)) == 0 && strcmp(st, "connected") == 0) {
|
||||
ctx->policy.hdmi_connected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
}
|
||||
|
||||
static void apply_cpu_policy(powerd_ctx_t *ctx) {
|
||||
geminux_profile_params_t par = geminux_policy_params(ctx->policy.profile, ctx->policy.on_ac_power);
|
||||
|
||||
for (int cpu = 8; cpu <= 9; cpu++) {
|
||||
char p[128];
|
||||
snprintf(p, sizeof(p), "/sys/devices/system/cpu/cpu%d/online", cpu);
|
||||
write_sysfs_str(p, par.a72_online ? "1" : "0");
|
||||
}
|
||||
|
||||
DIR *d = opendir("/sys/devices/system/cpu/cpufreq");
|
||||
if (d) {
|
||||
struct dirent *de;
|
||||
while ((de = readdir(d)) != NULL) {
|
||||
if (strncmp(de->d_name, "policy", 6) != 0) continue;
|
||||
char p[256], freq_buf[32];
|
||||
snprintf(p, sizeof(p), "/sys/devices/system/cpu/cpufreq/%s/scaling_governor", de->d_name);
|
||||
write_sysfs_str(p, par.governor);
|
||||
|
||||
int first_cpu = atoi(de->d_name + 6);
|
||||
unsigned long cap = (first_cpu >= 8) ? par.a72_max_khz : par.a53_max_khz;
|
||||
if (cap > 0) {
|
||||
snprintf(p, sizeof(p), "/sys/devices/system/cpu/cpufreq/%s/scaling_max_freq", de->d_name);
|
||||
snprintf(freq_buf, sizeof(freq_buf), "%lu", cap);
|
||||
write_sysfs_str(p, freq_buf);
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
mkdir("/run/geminux", 0755);
|
||||
write_sysfs_str(PROFILE_FILE, geminux_policy_profile_name(ctx->policy.profile));
|
||||
|
||||
struct itimerspec its;
|
||||
memset(&its, 0, sizeof(its));
|
||||
if (par.suspend_timeout_s > 0 && !ctx->policy.hdmi_connected && ctx->policy.inhibit_count == 0) {
|
||||
its.it_value.tv_sec = par.suspend_timeout_s;
|
||||
}
|
||||
timerfd_settime(ctx->tmr_fd, 0, &its, NULL);
|
||||
}
|
||||
|
||||
static void toggle_backlight(powerd_ctx_t *ctx, bool on) {
|
||||
DIR *d = opendir("/sys/class/backlight");
|
||||
if (!d) return;
|
||||
struct dirent *de;
|
||||
while ((de = readdir(d)) != NULL) {
|
||||
if (de->d_name[0] == '.') continue;
|
||||
char p[320], cur[32] = {0};
|
||||
snprintf(p, sizeof(p), "/sys/class/backlight/%s/brightness", de->d_name);
|
||||
if (!on) {
|
||||
if (read_sysfs_line(p, cur, sizeof(cur)) == 0 && atoi(cur) > 0) {
|
||||
ctx->saved_brightness = atoi(cur);
|
||||
}
|
||||
write_sysfs_str(p, "0");
|
||||
} else {
|
||||
char restore[32];
|
||||
int val = ctx->saved_brightness > 0 ? ctx->saved_brightness : 128;
|
||||
snprintf(restore, sizeof(restore), "%d", val);
|
||||
write_sysfs_str(p, restore);
|
||||
}
|
||||
break;
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
static void trigger_suspend(powerd_ctx_t *ctx) {
|
||||
toggle_backlight(ctx, false);
|
||||
write_sysfs_str("/sys/power/mem_sleep", "deep");
|
||||
if (write_sysfs_str("/sys/power/state", "mem") == 0) {
|
||||
/* Woken back up from S3 suspend */
|
||||
toggle_backlight(ctx, true);
|
||||
refresh_ac_and_hdmi(ctx);
|
||||
apply_cpu_policy(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
static void scan_input_devices(powerd_ctx_t *ctx) {
|
||||
for (int i = 0; i < ctx->num_ev; i++) {
|
||||
epoll_ctl(ctx->epfd, EPOLL_CTL_DEL, ctx->ev_fds[i], NULL);
|
||||
close(ctx->ev_fds[i]);
|
||||
}
|
||||
ctx->num_ev = 0;
|
||||
|
||||
for (int i = 0; i < 32 && ctx->num_ev < MAX_EVDEVS; i++) {
|
||||
char p[64];
|
||||
snprintf(p, sizeof(p), "/dev/input/event%d", i);
|
||||
int fd = open(p, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
|
||||
if (fd < 0) continue;
|
||||
unsigned long evbits = 0;
|
||||
if (ioctl(fd, EVIOCGBIT(0, sizeof(evbits)), &evbits) >= 0 &&
|
||||
((evbits & (1UL << EV_SW)) || (evbits & (1UL << EV_KEY)))) {
|
||||
struct epoll_event ev = { .events = EPOLLIN, .data.fd = fd };
|
||||
if (epoll_ctl(ctx->epfd, EPOLL_CTL_ADD, fd, &ev) == 0) {
|
||||
ctx->ev_fds[ctx->num_ev++] = fd;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_client_cmd(powerd_ctx_t *ctx, int cfd) {
|
||||
char buf[256] = {0};
|
||||
ssize_t n = read(cfd, buf, sizeof(buf) - 1);
|
||||
if (n <= 0) return;
|
||||
while (n > 0 && (buf[n - 1] == '\n' || buf[n - 1] == '\r')) buf[--n] = '\0';
|
||||
|
||||
if (strncmp(buf, "profile ", 8) == 0) {
|
||||
if (geminux_policy_set_profile_name(&ctx->policy, buf + 8)) {
|
||||
apply_cpu_policy(ctx);
|
||||
dprintf(cfd, "OK profile=%s\n", geminux_policy_profile_name(ctx->policy.profile));
|
||||
} else {
|
||||
dprintf(cfd, "ERR unknown profile\n");
|
||||
}
|
||||
} else if (strcmp(buf, "suspend") == 0) {
|
||||
dprintf(cfd, "OK suspending\n");
|
||||
trigger_suspend(ctx);
|
||||
} else if (strncmp(buf, "inhibit add ", 12) == 0) {
|
||||
geminux_policy_add_inhibit(&ctx->policy, buf + 12);
|
||||
apply_cpu_policy(ctx);
|
||||
dprintf(cfd, "OK inhibits=%d\n", ctx->policy.inhibit_count);
|
||||
} else if (strncmp(buf, "inhibit del ", 12) == 0) {
|
||||
geminux_policy_del_inhibit(&ctx->policy, buf + 12);
|
||||
apply_cpu_policy(ctx);
|
||||
dprintf(cfd, "OK inhibits=%d\n", ctx->policy.inhibit_count);
|
||||
} else if (strcmp(buf, "lid-suspend on") == 0) {
|
||||
ctx->policy.lid_suspend_enabled = true;
|
||||
dprintf(cfd, "OK lid_suspend=on\n");
|
||||
} else if (strcmp(buf, "lid-suspend off") == 0) {
|
||||
ctx->policy.lid_suspend_enabled = false;
|
||||
dprintf(cfd, "OK lid_suspend=off\n");
|
||||
} else if (strcmp(buf, "status") == 0) {
|
||||
dprintf(cfd, "profile=%s ac=%d hdmi=%d lid_closed=%d lid_suspend=%d inhibits=%d\n",
|
||||
geminux_policy_profile_name(ctx->policy.profile),
|
||||
ctx->policy.on_ac_power ? 1 : 0,
|
||||
ctx->policy.hdmi_connected ? 1 : 0,
|
||||
ctx->policy.lid_closed ? 1 : 0,
|
||||
ctx->policy.lid_suspend_enabled ? 1 : 0,
|
||||
ctx->policy.inhibit_count);
|
||||
} else {
|
||||
dprintf(cfd, "ERR unknown command\n");
|
||||
}
|
||||
}
|
||||
|
||||
static int setup_unix_server(void) {
|
||||
mkdir("/run/geminux", 0755);
|
||||
unlink(SOCK_PATH);
|
||||
int fd = socket(AF_UNIX, SOCK_STREAM | O_NONBLOCK | O_CLOEXEC, 0);
|
||||
if (fd < 0) return -1;
|
||||
struct sockaddr_un addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sun_family = AF_UNIX;
|
||||
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", SOCK_PATH);
|
||||
if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0 || listen(fd, 8) < 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
struct group *gr = getgrnam("wheel");
|
||||
if (gr) chown(SOCK_PATH, 0, gr->gr_gid);
|
||||
chmod(SOCK_PATH, 0660);
|
||||
return fd;
|
||||
}
|
||||
|
||||
static int setup_uevent_socket(void) {
|
||||
int fd = socket(PF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, NETLINK_KOBJECT_UEVENT);
|
||||
if (fd < 0) return -1;
|
||||
struct sockaddr_nl nls;
|
||||
memset(&nls, 0, sizeof(nls));
|
||||
nls.nl_family = AF_NETLINK;
|
||||
nls.nl_pid = (uint32_t)getpid();
|
||||
nls.nl_groups = 1;
|
||||
if (bind(fd, (struct sockaddr *)&nls, sizeof(nls)) < 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
powerd_ctx_t ctx;
|
||||
memset(&ctx, 0, sizeof(ctx));
|
||||
ctx.saved_brightness = 128;
|
||||
geminux_policy_init(&ctx.policy);
|
||||
|
||||
sigset_t mask;
|
||||
sigemptyset(&mask);
|
||||
sigaddset(&mask, SIGTERM);
|
||||
sigaddset(&mask, SIGINT);
|
||||
sigaddset(&mask, SIGHUP);
|
||||
sigprocmask(SIG_BLOCK, &mask, NULL);
|
||||
ctx.sig_fd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC);
|
||||
|
||||
ctx.epfd = epoll_create1(EPOLL_CLOEXEC);
|
||||
ctx.tmr_fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
|
||||
ctx.srv_fd = setup_unix_server();
|
||||
ctx.uev_fd = setup_uevent_socket();
|
||||
|
||||
int fixed[4] = {ctx.sig_fd, ctx.tmr_fd, ctx.srv_fd, ctx.uev_fd};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (fixed[i] >= 0) {
|
||||
struct epoll_event ev = { .events = EPOLLIN, .data.fd = fixed[i] };
|
||||
epoll_ctl(ctx.epfd, EPOLL_CTL_ADD, fixed[i], &ev);
|
||||
}
|
||||
}
|
||||
|
||||
refresh_ac_and_hdmi(&ctx);
|
||||
scan_input_devices(&ctx);
|
||||
apply_cpu_policy(&ctx);
|
||||
|
||||
struct epoll_event events[16];
|
||||
bool running = true;
|
||||
while (running) {
|
||||
int n = epoll_wait(ctx.epfd, events, 16, -1);
|
||||
if (n < 0) {
|
||||
if (errno == EINTR) continue;
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < n; i++) {
|
||||
int fd = events[i].data.fd;
|
||||
if (fd == ctx.sig_fd) {
|
||||
struct signalfd_siginfo si;
|
||||
while (read(ctx.sig_fd, &si, sizeof(si)) > 0) {
|
||||
if (si.ssi_signo == SIGHUP) {
|
||||
refresh_ac_and_hdmi(&ctx);
|
||||
apply_cpu_policy(&ctx);
|
||||
} else {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
} else if (fd == ctx.srv_fd) {
|
||||
int cfd;
|
||||
while ((cfd = accept4(ctx.srv_fd, NULL, NULL, SOCK_CLOEXEC)) >= 0) {
|
||||
handle_client_cmd(&ctx, cfd);
|
||||
close(cfd);
|
||||
}
|
||||
} else if (fd == ctx.tmr_fd) {
|
||||
uint64_t exp = 0;
|
||||
while (read(ctx.tmr_fd, &exp, sizeof(exp)) > 0) {}
|
||||
refresh_ac_and_hdmi(&ctx);
|
||||
if (!ctx.policy.on_ac_power && !ctx.policy.hdmi_connected && ctx.policy.inhibit_count == 0) {
|
||||
trigger_suspend(&ctx);
|
||||
}
|
||||
} else if (fd == ctx.uev_fd) {
|
||||
char ubuf[2048];
|
||||
while (recv(ctx.uev_fd, ubuf, sizeof(ubuf), 0) > 0) {}
|
||||
refresh_ac_and_hdmi(&ctx);
|
||||
apply_cpu_policy(&ctx);
|
||||
} else {
|
||||
struct input_event iev;
|
||||
while (read(fd, &iev, sizeof(iev)) == (ssize_t)sizeof(iev)) {
|
||||
if (iev.type == EV_SW && iev.code == SW_LID) {
|
||||
ctx.policy.lid_closed = (iev.value != 0);
|
||||
if (ctx.policy.lid_closed) {
|
||||
if (geminux_should_suspend_on_lid(&ctx.policy)) {
|
||||
trigger_suspend(&ctx);
|
||||
}
|
||||
} else {
|
||||
toggle_backlight(&ctx, true);
|
||||
apply_cpu_policy(&ctx);
|
||||
}
|
||||
} else if (iev.type == EV_KEY && iev.code == KEY_POWER && iev.value == 1) {
|
||||
trigger_suspend(&ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unlink(SOCK_PATH);
|
||||
close(ctx.epfd);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/inotify.h>
|
||||
#include <sys/signalfd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
static int read_line(const char *path, char *buf, size_t sz) {
|
||||
FILE *f = fopen(path, "r");
|
||||
if (!f) return -1;
|
||||
if (!fgets(buf, (int)sz, f)) {
|
||||
fclose(f);
|
||||
return -1;
|
||||
}
|
||||
fclose(f);
|
||||
size_t n = strlen(buf);
|
||||
while (n > 0 && (buf[n - 1] == '\n' || buf[n - 1] == '\r')) buf[--n] = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool iface_up(const char *ifname) {
|
||||
char p[128], st[32] = {0};
|
||||
snprintf(p, sizeof(p), "/sys/class/net/%s/operstate", ifname);
|
||||
if (read_line(p, st, sizeof(st)) != 0) return false;
|
||||
return strcmp(st, "up") == 0 || strcmp(st, "unknown") == 0;
|
||||
}
|
||||
|
||||
static void read_battery(char *out, size_t sz) {
|
||||
snprintf(out, sz, "BAT:--");
|
||||
DIR *d = opendir("/sys/class/power_supply");
|
||||
if (!d) return;
|
||||
struct dirent *de;
|
||||
while ((de = readdir(d)) != NULL) {
|
||||
if (de->d_name[0] == '.') continue;
|
||||
char p[320], typ[32] = {0}, cap[16] = {0}, st[24] = {0};
|
||||
snprintf(p, sizeof(p), "/sys/class/power_supply/%s/type", de->d_name);
|
||||
if (read_line(p, typ, sizeof(typ)) != 0 || strcmp(typ, "Battery") != 0) continue;
|
||||
snprintf(p, sizeof(p), "/sys/class/power_supply/%s/capacity", de->d_name);
|
||||
read_line(p, cap, sizeof(cap));
|
||||
snprintf(p, sizeof(p), "/sys/class/power_supply/%s/status", de->d_name);
|
||||
read_line(p, st, sizeof(st));
|
||||
const char *tag = (strcmp(st, "Charging") == 0) ? "+" :
|
||||
(strcmp(st, "Full") == 0) ? "=" : "";
|
||||
snprintf(out, sz, "%s%% %s%s", cap[0] ? cap : "?", tag,
|
||||
strcmp(st, "Charging") == 0 ? "CHG" : "BAT");
|
||||
break;
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
static void update_status(Display *dpy) {
|
||||
char bat[48], mdm[64] = {0}, prof[32] = {0}, net[64] = {0};
|
||||
read_battery(bat, sizeof(bat));
|
||||
if (read_line("/run/geminux/modem-state", mdm, sizeof(mdm)) != 0) {
|
||||
snprintf(mdm, sizeof(mdm), "4G:OFF");
|
||||
}
|
||||
if (read_line("/run/geminux/power-profile", prof, sizeof(prof)) != 0) {
|
||||
snprintf(prof, sizeof(prof), "balanced");
|
||||
}
|
||||
|
||||
if (iface_up("wlan0")) snprintf(net, sizeof(net), "WiFi:UP");
|
||||
else if (iface_up("usb0")) snprintf(net, sizeof(net), "USB:UP");
|
||||
else if (iface_up("ccmni0") || iface_up("ccmni1")) snprintf(net, sizeof(net), "LTE:UP");
|
||||
else snprintf(net, sizeof(net), "Net:OFF");
|
||||
|
||||
time_t now = time(NULL);
|
||||
struct tm tm;
|
||||
localtime_r(&now, &tm);
|
||||
char clk[32];
|
||||
strftime(clk, sizeof(clk), "%a %d %H:%M", &tm);
|
||||
|
||||
char bar[256];
|
||||
snprintf(bar, sizeof(bar), " %s | %s | %s | %s | %s ", net, mdm, prof, bat, clk);
|
||||
XStoreName(dpy, DefaultRootWindow(dpy), bar);
|
||||
XFlush(dpy);
|
||||
}
|
||||
|
||||
static void arm_minute_timer(int tfd) {
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_REALTIME, &now);
|
||||
long rem = 60 - (now.tv_sec % 60);
|
||||
if (rem <= 0) rem = 60;
|
||||
struct itimerspec its;
|
||||
memset(&its, 0, sizeof(its));
|
||||
its.it_value.tv_sec = rem;
|
||||
its.it_interval.tv_sec = 60;
|
||||
timerfd_settime(tfd, 0, &its, NULL);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
Display *dpy = XOpenDisplay(NULL);
|
||||
if (!dpy) {
|
||||
fprintf(stderr, "geminux-statusd: cannot open X11 display\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
sigset_t mask;
|
||||
sigemptyset(&mask);
|
||||
sigaddset(&mask, SIGUSR1);
|
||||
sigaddset(&mask, SIGTERM);
|
||||
sigaddset(&mask, SIGINT);
|
||||
sigprocmask(SIG_BLOCK, &mask, NULL);
|
||||
int sig_fd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC);
|
||||
|
||||
int rt_fd = socket(AF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, NETLINK_ROUTE);
|
||||
if (rt_fd >= 0) {
|
||||
struct sockaddr_nl nl = { .nl_family = AF_NETLINK, .nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR };
|
||||
bind(rt_fd, (struct sockaddr *)&nl, sizeof(nl));
|
||||
}
|
||||
|
||||
int uev_fd = socket(AF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, NETLINK_KOBJECT_UEVENT);
|
||||
if (uev_fd >= 0) {
|
||||
struct sockaddr_nl nl = { .nl_family = AF_NETLINK, .nl_groups = 1 };
|
||||
bind(uev_fd, (struct sockaddr *)&nl, sizeof(nl));
|
||||
}
|
||||
|
||||
int ino_fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
|
||||
if (ino_fd >= 0) {
|
||||
inotify_add_watch(ino_fd, "/run/geminux", IN_CLOSE_WRITE | IN_MOVED_TO | IN_CREATE);
|
||||
}
|
||||
|
||||
int tmr_fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
|
||||
if (tmr_fd >= 0) arm_minute_timer(tmr_fd);
|
||||
|
||||
int epfd = epoll_create1(EPOLL_CLOEXEC);
|
||||
int fds[5] = {sig_fd, rt_fd, uev_fd, ino_fd, tmr_fd};
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (fds[i] >= 0) {
|
||||
struct epoll_event ev = { .events = EPOLLIN, .data.fd = fds[i] };
|
||||
epoll_ctl(epfd, EPOLL_CTL_ADD, fds[i], &ev);
|
||||
}
|
||||
}
|
||||
|
||||
update_status(dpy);
|
||||
|
||||
struct epoll_event events[12];
|
||||
bool running = true;
|
||||
while (running) {
|
||||
int n = epoll_wait(epfd, events, 12, -1);
|
||||
if (n < 0) {
|
||||
if (errno == EINTR) continue;
|
||||
break;
|
||||
}
|
||||
bool dirty = false;
|
||||
for (int i = 0; i < n; i++) {
|
||||
int fd = events[i].data.fd;
|
||||
if (fd == sig_fd) {
|
||||
struct signalfd_siginfo si;
|
||||
while (read(sig_fd, &si, sizeof(si)) > 0) {
|
||||
if (si.ssi_signo == SIGUSR1) dirty = true;
|
||||
else running = false;
|
||||
}
|
||||
} else {
|
||||
char drain[1024];
|
||||
while (read(fd, drain, sizeof(drain)) > 0) {}
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
if (running && dirty) update_status(dpy);
|
||||
}
|
||||
|
||||
close(epfd);
|
||||
XCloseDisplay(dpy);
|
||||
return 0;
|
||||
}
|
||||
Executable
+131
@@ -0,0 +1,131 @@
|
||||
#!/bin/sh
|
||||
# Geminux initramfs init (normal boot + off-mode charger guard + safe rootfs e2fsck/resize)
|
||||
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
|
||||
|
||||
mkdir -p /proc /sys /dev /dev/pts /run /mnt/root
|
||||
mount -t proc proc /proc
|
||||
mount -t sysfs sysfs /sys
|
||||
mount -t devtmpfs devtmpfs /dev
|
||||
mkdir -p /dev/pts
|
||||
mount -t devpts devpts /dev/pts 2>/dev/null || true
|
||||
|
||||
set_console_quiet() {
|
||||
echo 3 > /proc/sys/kernel/printk 2>/dev/null || true
|
||||
}
|
||||
|
||||
set_console_quiet
|
||||
|
||||
is_charger_mode() {
|
||||
if grep -q "androidboot\.mode=charger" /proc/cmdline 2>/dev/null; then
|
||||
return 0
|
||||
fi
|
||||
if [ -f /sys/firmware/devicetree/base/chosen/atag,boot ]; then
|
||||
mode_hex="$(hexdump -v -e '1/1 "%02x"' /sys/firmware/devicetree/base/chosen/atag,boot 2>/dev/null || true)"
|
||||
case "$mode_hex" in
|
||||
00000008|08000000|"38")
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
run_offmode_charger() {
|
||||
printf '\n[geminux] Off-mode charger guard active.\n' > /dev/tty1 2>/dev/null || true
|
||||
while true; do
|
||||
cap="$(cat /sys/class/power_supply/battery/capacity 2>/dev/null || echo "?")"
|
||||
temp="$(cat /sys/class/power_supply/battery/temp 2>/dev/null || echo "?")"
|
||||
status="$(cat /sys/class/power_supply/battery/status 2>/dev/null || echo "Unknown")"
|
||||
online="$(cat /sys/class/power_supply/*/online 2>/dev/null | grep -q '^1$' && echo 1 || echo 0)"
|
||||
printf '\r[geminux-charger] Battery: %s%% Status: %s Temp: %s dC ' \
|
||||
"$cap" "$status" "$temp" > /dev/tty1 2>/dev/null || true
|
||||
if [ "$online" = "0" ]; then
|
||||
printf '\n[geminux-charger] Charger disconnected, powering off.\n' > /dev/tty1 2>/dev/null || true
|
||||
sync
|
||||
poweroff -f
|
||||
fi
|
||||
sleep 5
|
||||
done
|
||||
}
|
||||
|
||||
find_root_dev() {
|
||||
for p in /sys/class/block/*/uevent; do
|
||||
[ -f "$p" ] || continue
|
||||
if grep -q '^PARTNAME=linux$' "$p" 2>/dev/null; then
|
||||
devname="$(basename "$(dirname "$p")")"
|
||||
if [ -b "/dev/$devname" ]; then
|
||||
echo "/dev/$devname"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
done
|
||||
if [ -b /dev/disk/by-partlabel/linux ]; then
|
||||
echo /dev/disk/by-partlabel/linux
|
||||
return 0
|
||||
fi
|
||||
for p in /proc/cmdline; do
|
||||
:
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
emergency_shell() {
|
||||
echo "[geminux-init] ERROR: $1"
|
||||
echo "[geminux-init] Dropping to initramfs emergency shell."
|
||||
exec /bin/sh
|
||||
}
|
||||
|
||||
if is_charger_mode; then
|
||||
run_offmode_charger
|
||||
fi
|
||||
|
||||
ROOT_DEV=""
|
||||
i=0
|
||||
while [ "$i" -lt 60 ]; do
|
||||
ROOT_DEV="$(find_root_dev || true)"
|
||||
[ -n "$ROOT_DEV" ] && break
|
||||
usleep 250000 2>/dev/null || sleep 1
|
||||
i=$((i + 1))
|
||||
done
|
||||
|
||||
[ -n "$ROOT_DEV" ] || emergency_shell "PARTLABEL=linux root block device not found"
|
||||
|
||||
if command -v e2fsck >/dev/null 2>&1; then
|
||||
e2fsck -p "$ROOT_DEV" >/dev/null 2>&1 || {
|
||||
rc=$?
|
||||
[ "$rc" -le 1 ] || echo "[geminux-init] Warning: e2fsck returned $rc on $ROOT_DEV"
|
||||
}
|
||||
fi
|
||||
|
||||
mount -t ext4 -o ro "$ROOT_DEV" /mnt/root || emergency_shell "Failed to mount $ROOT_DEV"
|
||||
|
||||
NEEDS_RESIZE=0
|
||||
if [ ! -f /mnt/root/var/lib/geminux/.rootfs-resized ]; then
|
||||
NEEDS_RESIZE=1
|
||||
fi
|
||||
umount /mnt/root
|
||||
|
||||
if [ "$NEEDS_RESIZE" = "1" ] && command -v resize2fs >/dev/null 2>&1; then
|
||||
echo "[geminux-init] Expanding $ROOT_DEV to fill full partition..."
|
||||
resize2fs -f "$ROOT_DEV" >/dev/null 2>&1 || true
|
||||
if command -v e2fsck >/dev/null 2>&1; then
|
||||
e2fsck -p "$ROOT_DEV" >/dev/null 2>&1 || true
|
||||
fi
|
||||
fi
|
||||
|
||||
mount -t ext4 -o rw,noatime,commit=60 "$ROOT_DEV" /mnt/root || \
|
||||
emergency_shell "Failed to mount $ROOT_DEV read-write"
|
||||
|
||||
if [ "$NEEDS_RESIZE" = "1" ]; then
|
||||
mkdir -p /mnt/root/var/lib/geminux
|
||||
touch /mnt/root/var/lib/geminux/.rootfs-resized
|
||||
fi
|
||||
|
||||
[ -x /mnt/root/sbin/init ] || emergency_shell "/sbin/init missing on $ROOT_DEV"
|
||||
|
||||
umount /dev/pts 2>/dev/null || true
|
||||
mount --move /dev /mnt/root/dev
|
||||
mount --move /sys /mnt/root/sys
|
||||
mount --move /proc /mnt/root/proc
|
||||
|
||||
exec switch_root /mnt/root /sbin/init
|
||||
Executable
+92
@@ -0,0 +1,92 @@
|
||||
#!/bin/sh
|
||||
# Geminux recovery initramfs init (USB NCM/RNDIS gadget 172.16.42.1 + interactive repair)
|
||||
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
|
||||
|
||||
mkdir -p /proc /sys /dev /dev/pts /run /tmp /mnt/linux /sys/kernel/config
|
||||
mount -t proc proc /proc
|
||||
mount -t sysfs sysfs /sys
|
||||
mount -t devtmpfs devtmpfs /dev
|
||||
mkdir -p /dev/pts
|
||||
mount -t devpts devpts /dev/pts 2>/dev/null || true
|
||||
mount -t configfs configfs /sys/kernel/config 2>/dev/null || true
|
||||
|
||||
setup_usb_gadget() {
|
||||
G=/sys/kernel/config/usb_gadget/geminux
|
||||
[ -d /sys/kernel/config/usb_gadget ] || return 0
|
||||
udc="$(ls /sys/class/udc 2>/dev/null | head -n 1)"
|
||||
[ -n "$udc" ] || return 0
|
||||
mkdir -p "$G"
|
||||
echo 0x1d6b > "$G/idVendor"
|
||||
echo 0x0104 > "$G/idProduct"
|
||||
mkdir -p "$G/strings/0x409" "$G/configs/c.1/strings/0x409"
|
||||
echo "geminux-recovery" > "$G/strings/0x409/serialnumber"
|
||||
echo "Geminux" > "$G/strings/0x409/manufacturer"
|
||||
echo "Gemini PDA Recovery" > "$G/strings/0x409/product"
|
||||
if mkdir -p "$G/functions/ncm.usb0" 2>/dev/null; then
|
||||
ln -sfn "$G/functions/ncm.usb0" "$G/configs/c.1/ncm.usb0"
|
||||
echo "$udc" > "$G/UDC" 2>/dev/null || true
|
||||
elif mkdir -p "$G/functions/rndis.usb0" 2>/dev/null; then
|
||||
ln -sfn "$G/functions/rndis.usb0" "$G/configs/c.1/rndis.usb0"
|
||||
echo "$udc" > "$G/UDC" 2>/dev/null || true
|
||||
fi
|
||||
ip link set usb0 up 2>/dev/null || true
|
||||
ip addr add 172.16.42.1/24 dev usb0 2>/dev/null || true
|
||||
}
|
||||
|
||||
find_root_dev() {
|
||||
for p in /sys/class/block/*/uevent; do
|
||||
[ -f "$p" ] || continue
|
||||
if grep -q '^PARTNAME=linux$' "$p" 2>/dev/null; then
|
||||
devname="$(basename "$(dirname "$p")")"
|
||||
[ -b "/dev/$devname" ] && echo "/dev/$devname" && return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
setup_usb_gadget
|
||||
|
||||
cat <<'EOF' > /dev/tty1 2>/dev/null || true
|
||||
=======================================================
|
||||
Geminux Recovery Environment (Gemini PDA MT6797X)
|
||||
=======================================================
|
||||
USB Gadget IP : 172.16.42.1/24
|
||||
Commands:
|
||||
check-fs : Run e2fsck -fy on PARTLABEL=linux
|
||||
mount-root : Mount PARTLABEL=linux at /mnt/linux
|
||||
reboot : Reboot normally
|
||||
=======================================================
|
||||
EOF
|
||||
|
||||
cat <<'EOF' > /bin/check-fs
|
||||
#!/bin/sh
|
||||
for p in /sys/class/block/*/uevent; do
|
||||
if grep -q '^PARTNAME=linux$' "$p" 2>/dev/null; then
|
||||
d="/dev/$(basename "$(dirname "$p")")"
|
||||
exec e2fsck -fy "$d"
|
||||
fi
|
||||
done
|
||||
echo "PARTLABEL=linux not found"
|
||||
exit 1
|
||||
EOF
|
||||
|
||||
cat <<'EOF' > /bin/mount-root
|
||||
#!/bin/sh
|
||||
mkdir -p /mnt/linux
|
||||
for p in /sys/class/block/*/uevent; do
|
||||
if grep -q '^PARTNAME=linux$' "$p" 2>/dev/null; then
|
||||
d="/dev/$(basename "$(dirname "$p")")"
|
||||
exec mount -t ext4 "$d" /mnt/linux
|
||||
fi
|
||||
done
|
||||
echo "PARTLABEL=linux not found"
|
||||
exit 1
|
||||
EOF
|
||||
|
||||
chmod +x /bin/check-fs /bin/mount-root
|
||||
|
||||
if command -v loadkmap >/dev/null 2>&1 && [ -f /etc/gemini-us.kmap ]; then
|
||||
loadkmap < /etc/gemini-us.kmap 2>/dev/null || true
|
||||
fi
|
||||
|
||||
exec /bin/sh -i </dev/tty1 >/dev/tty1 2>&1
|
||||
@@ -0,0 +1,24 @@
|
||||
CC ?= gcc
|
||||
PKG_CONFIG ?= pkg-config
|
||||
PREFIX ?= /usr
|
||||
DESTDIR ?=
|
||||
|
||||
PKGS = x11 xext xft cairo pangocairo pango harfbuzz fontconfig freetype2
|
||||
CFLAGS += -std=c11 -Wall -Wextra -O2 -fPIC $(shell $(PKG_CONFIG) --cflags $(PKGS))
|
||||
LDFLAGS += -shared -Wl,-soname,libgemui.so $(shell $(PKG_CONFIG) --libs $(PKGS))
|
||||
|
||||
all: libgemui.so
|
||||
|
||||
libgemui.so: gemui.c gemui.h
|
||||
$(CC) $(CFLAGS) -o $@ gemui.c $(LDFLAGS)
|
||||
|
||||
install: all
|
||||
mkdir -p $(DESTDIR)$(PREFIX)/lib $(DESTDIR)$(PREFIX)/include
|
||||
cp -f libgemui.so $(DESTDIR)$(PREFIX)/lib/libgemui.so
|
||||
chmod 0755 $(DESTDIR)$(PREFIX)/lib/libgemui.so
|
||||
cp -f gemui.h $(DESTDIR)$(PREFIX)/include/gemui.h
|
||||
|
||||
clean:
|
||||
rm -f libgemui.so
|
||||
|
||||
.PHONY: all install clean
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Geminux UI Toolkit (libgemui)
|
||||
* Pure C11 X11 + Cairo + Pango/HarfBuzz landscape HiDPI UI library with live .Xresources theming.
|
||||
*/
|
||||
#ifndef GEMUI_H
|
||||
#define GEMUI_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <cairo/cairo.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define GEMUI_ALIGN_LEFT 0
|
||||
#define GEMUI_ALIGN_CENTER 1
|
||||
#define GEMUI_ALIGN_RIGHT 2
|
||||
|
||||
#define GEMUI_PTR_DOWN 0
|
||||
#define GEMUI_PTR_MOVE 1
|
||||
#define GEMUI_PTR_UP 2
|
||||
#define GEMUI_PTR_SCROLL_UP 3
|
||||
#define GEMUI_PTR_SCROLL_DOWN 4
|
||||
|
||||
#define GEMUI_MAX_HITS 192
|
||||
#define GEMUI_MAX_FDS 16
|
||||
|
||||
typedef struct {
|
||||
double r;
|
||||
double g;
|
||||
double b;
|
||||
double a;
|
||||
uint32_t argb;
|
||||
} gemui_color_t;
|
||||
|
||||
typedef struct {
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
} gemui_rect_t;
|
||||
|
||||
typedef struct {
|
||||
gemui_rect_t r;
|
||||
int id;
|
||||
int val;
|
||||
} gemui_hit_t;
|
||||
|
||||
typedef struct {
|
||||
char name[64];
|
||||
char font_face[96];
|
||||
char icon_font_face[96];
|
||||
int base_font_size;
|
||||
int dpi;
|
||||
gemui_color_t bg_main;
|
||||
gemui_color_t bg_bar;
|
||||
gemui_color_t bg_header;
|
||||
gemui_color_t bg_footer;
|
||||
gemui_color_t bg_overlay;
|
||||
gemui_color_t bg_alt_even;
|
||||
gemui_color_t bg_alt_odd;
|
||||
gemui_color_t bg_input;
|
||||
gemui_color_t bg_input_focus;
|
||||
gemui_color_t bg_button;
|
||||
gemui_color_t bg_search;
|
||||
gemui_color_t bg_bubble_in;
|
||||
gemui_color_t bg_bubble_out;
|
||||
gemui_color_t bg_toast;
|
||||
gemui_color_t fg_main;
|
||||
gemui_color_t fg_bright;
|
||||
gemui_color_t fg_muted;
|
||||
gemui_color_t sel_bg;
|
||||
gemui_color_t sel_fg;
|
||||
gemui_color_t accent;
|
||||
gemui_color_t accent_alt;
|
||||
gemui_color_t highlight;
|
||||
gemui_color_t border;
|
||||
gemui_color_t divider;
|
||||
gemui_color_t success;
|
||||
gemui_color_t info;
|
||||
gemui_color_t warning;
|
||||
gemui_color_t danger;
|
||||
gemui_color_t danger_bg;
|
||||
} gemui_theme_t;
|
||||
|
||||
typedef struct gemui_app gemui_app_t;
|
||||
|
||||
typedef void (*gemui_fd_cb)(gemui_app_t *app, int fd, void *ud);
|
||||
typedef void (*gemui_timer_cb)(gemui_app_t *app, void *ud);
|
||||
|
||||
typedef struct {
|
||||
void (*on_draw)(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud);
|
||||
void (*on_key)(gemui_app_t *app, KeySym ks, unsigned int state, const char *utf8, void *ud);
|
||||
void (*on_ptr)(gemui_app_t *app, int type, int x, int y, unsigned int btn, void *ud);
|
||||
void (*on_theme)(gemui_app_t *app, void *ud);
|
||||
void (*on_resize)(gemui_app_t *app, int w, int h, void *ud);
|
||||
} gemui_handlers_t;
|
||||
|
||||
bool gemui_color_parse(const char *hex, gemui_color_t *out);
|
||||
void gemui_theme_defaults(gemui_theme_t *t);
|
||||
bool gemui_theme_load_file(const char *path, gemui_theme_t *out);
|
||||
void gemui_theme_reload(gemui_app_t *app);
|
||||
|
||||
gemui_app_t *gemui_create(const char *res_name, const char *title,
|
||||
int w, int h, bool fullscreen_override);
|
||||
void gemui_destroy(gemui_app_t *app);
|
||||
void gemui_set_handlers(gemui_app_t *app, const gemui_handlers_t *h, void *userdata);
|
||||
void gemui_set_title(gemui_app_t *app, const char *title);
|
||||
Display *gemui_display(const gemui_app_t *app);
|
||||
Window gemui_window(const gemui_app_t *app);
|
||||
const gemui_theme_t *gemui_theme(const gemui_app_t *app);
|
||||
int gemui_width(const gemui_app_t *app);
|
||||
int gemui_height(const gemui_app_t *app);
|
||||
int gemui_scale_px(const gemui_app_t *app, int logical_px);
|
||||
|
||||
int gemui_add_fd(gemui_app_t *app, int fd, gemui_fd_cb cb, void *userdata);
|
||||
void gemui_del_fd(gemui_app_t *app, int fd);
|
||||
void gemui_set_timer_ms(gemui_app_t *app, int interval_ms, gemui_timer_cb cb, void *userdata);
|
||||
void gemui_request_redraw(gemui_app_t *app);
|
||||
void gemui_show_toast(gemui_app_t *app, const char *msg, int duration_ms);
|
||||
int gemui_run(gemui_app_t *app);
|
||||
void gemui_quit(gemui_app_t *app, int code);
|
||||
bool gemui_grab_input(gemui_app_t *app);
|
||||
void gemui_ungrab_input(gemui_app_t *app);
|
||||
|
||||
void gemui_hits_clear(gemui_app_t *app);
|
||||
void gemui_hit_add(gemui_app_t *app, gemui_rect_t r, int id, int val);
|
||||
const gemui_hit_t *gemui_hit_test(const gemui_app_t *app, int x, int y);
|
||||
|
||||
void gemui_set_source(cairo_t *cr, gemui_color_t c);
|
||||
void gemui_rounded_rect(cairo_t *cr, gemui_rect_t r, double radius);
|
||||
void gemui_fill_rect(cairo_t *cr, gemui_rect_t r, gemui_color_t c);
|
||||
void gemui_fill_round(cairo_t *cr, gemui_rect_t r, double radius, gemui_color_t c);
|
||||
void gemui_stroke_round(cairo_t *cr, gemui_rect_t r, double radius, double lw, gemui_color_t c);
|
||||
int gemui_draw_text(cairo_t *cr, const gemui_theme_t *t, gemui_rect_t r,
|
||||
const char *text, int pt_delta, bool bold, int align, gemui_color_t c);
|
||||
int gemui_draw_icon(cairo_t *cr, const gemui_theme_t *t, gemui_rect_t r,
|
||||
const char *icon_utf8, int pt_delta, int align, gemui_color_t c);
|
||||
void gemui_draw_header(gemui_app_t *app, cairo_t *cr, const char *icon,
|
||||
const char *title, const char *right_badge);
|
||||
void gemui_draw_button(gemui_app_t *app, cairo_t *cr, gemui_rect_t r,
|
||||
const char *label, int hit_id, int hit_val,
|
||||
bool primary, bool active, bool focused);
|
||||
void gemui_draw_toggle(gemui_app_t *app, cairo_t *cr, gemui_rect_t r,
|
||||
const char *label, bool on, int hit_id, int hit_val, bool focused);
|
||||
void gemui_draw_slider(gemui_app_t *app, cairo_t *cr, gemui_rect_t r,
|
||||
const char *label, double norm_val, const char *val_text,
|
||||
int hit_id, int hit_val, bool focused);
|
||||
void gemui_draw_input(gemui_app_t *app, cairo_t *cr, gemui_rect_t r,
|
||||
const char *placeholder, const char *text, bool mask_bullets,
|
||||
bool focused, int hit_id, int hit_val);
|
||||
void gemui_draw_toast(gemui_app_t *app, cairo_t *cr);
|
||||
|
||||
int gemui_unix_cmd(const char *sock_path, const char *cmd, char *resp, size_t resp_sz);
|
||||
int gemui_read_file_line(const char *path, char *buf, size_t sz);
|
||||
int gemui_run_cmd_capture(const char *const argv[], char *out, size_t out_sz);
|
||||
int gemui_spawn_detached(const char *const argv[]);
|
||||
void gemui_utf8_pop_char(char *buf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GEMUI_H */
|
||||
@@ -0,0 +1,56 @@
|
||||
# st - simple terminal
|
||||
# See LICENSE file for copyright and license details.
|
||||
.POSIX:
|
||||
|
||||
include config.mk
|
||||
|
||||
SRC = st.c x.c hb.c
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
all: options st
|
||||
|
||||
options:
|
||||
@echo st build options:
|
||||
@echo "CFLAGS = $(STCFLAGS)"
|
||||
@echo "LDFLAGS = $(STLDFLAGS)"
|
||||
@echo "CC = $(CC)"
|
||||
|
||||
config.h:
|
||||
cp config.def.h config.h
|
||||
|
||||
.c.o:
|
||||
$(CC) $(STCFLAGS) -c $<
|
||||
|
||||
st.o: config.h st.h win.h
|
||||
x.o: arg.h config.h st.h win.h hb.h
|
||||
hb.o: st.h hb.h
|
||||
|
||||
$(OBJ): config.h config.mk
|
||||
|
||||
st: $(OBJ)
|
||||
$(CC) -o $@ $(OBJ) $(STLDFLAGS)
|
||||
|
||||
clean:
|
||||
rm -f st $(OBJ) st-$(VERSION).tar.gz
|
||||
|
||||
dist: clean
|
||||
mkdir -p st-$(VERSION)
|
||||
cp -R FAQ LEGACY TODO LICENSE Makefile README config.mk\
|
||||
config.def.h st.info st.1 arg.h st.h win.h $(SRC)\
|
||||
st-$(VERSION)
|
||||
tar -cf - st-$(VERSION) | gzip > st-$(VERSION).tar.gz
|
||||
rm -rf st-$(VERSION)
|
||||
|
||||
install: st
|
||||
mkdir -p $(DESTDIR)$(PREFIX)/bin
|
||||
cp -f st $(DESTDIR)$(PREFIX)/bin
|
||||
chmod 755 $(DESTDIR)$(PREFIX)/bin/st
|
||||
mkdir -p $(DESTDIR)$(MANPREFIX)/man1
|
||||
sed "s/VERSION/$(VERSION)/g" < st.1 > $(DESTDIR)$(MANPREFIX)/man1/st.1
|
||||
chmod 644 $(DESTDIR)$(MANPREFIX)/man1/st.1
|
||||
|
||||
uninstall:
|
||||
rm -f $(DESTDIR)$(PREFIX)/bin/st
|
||||
rm -f $(DESTDIR)$(MANPREFIX)/man1/st.1
|
||||
|
||||
.PHONY: all options clean dist install uninstall
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copy me if you can.
|
||||
* by 20h
|
||||
*/
|
||||
|
||||
#ifndef ARG_H__
|
||||
#define ARG_H__
|
||||
|
||||
extern char *argv0;
|
||||
|
||||
/* use main(int argc, char *argv[]) */
|
||||
#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\
|
||||
argv[0] && argv[0][0] == '-'\
|
||||
&& argv[0][1];\
|
||||
argc--, argv++) {\
|
||||
char argc_;\
|
||||
char **argv_;\
|
||||
int brk_;\
|
||||
if (argv[0][1] == '-' && argv[0][2] == '\0') {\
|
||||
argv++;\
|
||||
argc--;\
|
||||
break;\
|
||||
}\
|
||||
int i_;\
|
||||
for (i_ = 1, brk_ = 0, argv_ = argv;\
|
||||
argv[0][i_] && !brk_;\
|
||||
i_++) {\
|
||||
if (argv_ != argv)\
|
||||
break;\
|
||||
argc_ = argv[0][i_];\
|
||||
switch (argc_)
|
||||
|
||||
#define ARGEND }\
|
||||
}
|
||||
|
||||
#define ARGC() argc_
|
||||
|
||||
#define EARGF(x) ((argv[0][i_+1] == '\0' && argv[1] == NULL)?\
|
||||
((x), abort(), (char *)0) :\
|
||||
(brk_ = 1, (argv[0][i_+1] != '\0')?\
|
||||
(&argv[0][i_+1]) :\
|
||||
(argc--, argv++, argv[0])))
|
||||
|
||||
#define ARGF() ((argv[0][i_+1] == '\0' && argv[1] == NULL)?\
|
||||
(char *)0 :\
|
||||
(brk_ = 1, (argv[0][i_+1] != '\0')?\
|
||||
(&argv[0][i_+1]) :\
|
||||
(argc--, argv++, argv[0])))
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,522 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
|
||||
/*
|
||||
* appearance
|
||||
*
|
||||
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
|
||||
*/
|
||||
static char *font = "Fira Code:pixelsize=24:style=Regular:antialias=true:autohint=true";
|
||||
static int borderpx = 2;
|
||||
|
||||
/*
|
||||
* What program is execed by st depends of these precedence rules:
|
||||
* 1: program passed with -e
|
||||
* 2: scroll and/or utmp
|
||||
* 3: SHELL environment variable
|
||||
* 4: value of shell in /etc/passwd
|
||||
* 5: value of shell in config.h
|
||||
*/
|
||||
static char *shell = "/bin/sh";
|
||||
char *utmp = NULL;
|
||||
/* scroll program: to enable use a string like "scroll" */
|
||||
char *scroll = NULL;
|
||||
char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400";
|
||||
|
||||
/* identification sequence returned in DA and DECID */
|
||||
char *vtiden = "\033[?6c";
|
||||
|
||||
/* Kerning / character bounding-box multipliers */
|
||||
static float cwscale = 1.0;
|
||||
static float chscale = 1.0;
|
||||
|
||||
/*
|
||||
* word delimiter string
|
||||
*
|
||||
* More advanced example: L" `'\"()[]{}"
|
||||
*/
|
||||
wchar_t *worddelimiters = L" ";
|
||||
|
||||
/* selection timeouts (in milliseconds) */
|
||||
static unsigned int doubleclicktimeout = 1000;
|
||||
static unsigned int tripleclicktimeout = 2000;
|
||||
|
||||
/* alt screens */
|
||||
int allowaltscreen = 1;
|
||||
|
||||
/* allow certain non-interactive (insecure) window operations such as:
|
||||
setting the clipboard text */
|
||||
int allowwindowops = 0;
|
||||
|
||||
/*
|
||||
* draw latency range in ms - from new content/keypress/etc until drawing.
|
||||
* within this range, st draws when content stops arriving (idle). mostly it's
|
||||
* near minlatency, but it waits longer for slow updates to avoid partial draw.
|
||||
* low minlatency will tear/flicker more, as it can "detect" idle too early.
|
||||
*/
|
||||
static double minlatency = 8;
|
||||
static double maxlatency = 33;
|
||||
|
||||
/*
|
||||
* blinking timeout (set to 0 to disable blinking) for the terminal blinking
|
||||
* attribute.
|
||||
*/
|
||||
static unsigned int blinktimeout = 800;
|
||||
|
||||
/*
|
||||
* thickness of underline and bar cursors
|
||||
*/
|
||||
static unsigned int cursorthickness = 2;
|
||||
|
||||
/*
|
||||
* bell volume. It must be a value between -100 and 100. Use 0 for disabling
|
||||
* it
|
||||
*/
|
||||
static int bellvolume = 0;
|
||||
|
||||
/* default TERM value */
|
||||
char *termname = "st-256color";
|
||||
|
||||
/*
|
||||
* spaces per tab
|
||||
*
|
||||
* When you are changing this value, don't forget to adapt the »it« value in
|
||||
* the st.info and appropriately install the st.info in the environment where
|
||||
* you use this st version.
|
||||
*
|
||||
* it#$tabspaces,
|
||||
*
|
||||
* Secondly make sure your kernel is not expanding tabs. When running `stty
|
||||
* -a` »tab0« should appear. You can tell the terminal to not expand tabs by
|
||||
* running following command:
|
||||
*
|
||||
* stty tabs
|
||||
*/
|
||||
unsigned int tabspaces = 8;
|
||||
|
||||
/* Terminal colors (16 first used in escape sequence) */
|
||||
static const char *colorname[] = {
|
||||
/* 8 normal colors */
|
||||
"black",
|
||||
"red3",
|
||||
"green3",
|
||||
"yellow3",
|
||||
"blue2",
|
||||
"magenta3",
|
||||
"cyan3",
|
||||
"gray90",
|
||||
|
||||
/* 8 bright colors */
|
||||
"gray50",
|
||||
"red",
|
||||
"green",
|
||||
"yellow",
|
||||
"#5c5cff",
|
||||
"magenta",
|
||||
"cyan",
|
||||
"white",
|
||||
|
||||
[255] = 0,
|
||||
|
||||
/* more colors can be added after 255 to use with DefaultXX */
|
||||
"#161616",
|
||||
"#dddddd",
|
||||
"#f4d03f",
|
||||
"#555555",
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Default colors (colorname index)
|
||||
* foreground, background, cursor, reverse cursor
|
||||
*/
|
||||
unsigned int defaultfg = 257;
|
||||
unsigned int defaultbg = 256;
|
||||
static unsigned int defaultcs = 258;
|
||||
static unsigned int defaultrcs = 259;
|
||||
|
||||
/*
|
||||
* Default shape of cursor
|
||||
* 2: Block ("█")
|
||||
* 4: Underline ("_")
|
||||
* 6: Bar ("|")
|
||||
* 7: Snowman ("☃")
|
||||
*/
|
||||
static unsigned int cursorshape = 2;
|
||||
|
||||
/*
|
||||
* Default columns and rows numbers
|
||||
*/
|
||||
|
||||
static unsigned int cols = 80;
|
||||
static unsigned int rows = 24;
|
||||
|
||||
/*
|
||||
* Default colour and shape of the mouse cursor
|
||||
*/
|
||||
static unsigned int mouseshape = XC_xterm;
|
||||
static unsigned int mousefg = 7;
|
||||
static unsigned int mousebg = 0;
|
||||
|
||||
/*
|
||||
* Color used to display font attributes when fontconfig selected a font which
|
||||
* doesn't match the ones requested.
|
||||
*/
|
||||
static unsigned int defaultattr = 11;
|
||||
|
||||
/*
|
||||
* Force mouse select/shortcuts while mask is active (when MODE_MOUSE is set).
|
||||
* Note that if you want to use ShiftMask with selmasks, set this to an other
|
||||
* modifier, set to 0 to not use it.
|
||||
*/
|
||||
static uint forcemousemod = ShiftMask;
|
||||
|
||||
/*
|
||||
* Xresources preferences to load at startup
|
||||
*/
|
||||
ResourcePref resources[] = {
|
||||
{ "font", STRING, &font },
|
||||
{ "color0", STRING, &colorname[0] },
|
||||
{ "color1", STRING, &colorname[1] },
|
||||
{ "color2", STRING, &colorname[2] },
|
||||
{ "color3", STRING, &colorname[3] },
|
||||
{ "color4", STRING, &colorname[4] },
|
||||
{ "color5", STRING, &colorname[5] },
|
||||
{ "color6", STRING, &colorname[6] },
|
||||
{ "color7", STRING, &colorname[7] },
|
||||
{ "color8", STRING, &colorname[8] },
|
||||
{ "color9", STRING, &colorname[9] },
|
||||
{ "color10", STRING, &colorname[10] },
|
||||
{ "color11", STRING, &colorname[11] },
|
||||
{ "color12", STRING, &colorname[12] },
|
||||
{ "color13", STRING, &colorname[13] },
|
||||
{ "color14", STRING, &colorname[14] },
|
||||
{ "color15", STRING, &colorname[15] },
|
||||
{ "background", STRING, &colorname[256] },
|
||||
{ "foreground", STRING, &colorname[257] },
|
||||
{ "cursorColor", STRING, &colorname[258] },
|
||||
{ "termname", STRING, &termname },
|
||||
{ "shell", STRING, &shell },
|
||||
{ "blinktimeout", INTEGER, &blinktimeout },
|
||||
{ "bellvolume", INTEGER, &bellvolume },
|
||||
{ "tabspaces", INTEGER, &tabspaces },
|
||||
{ "borderpx", INTEGER, &borderpx },
|
||||
{ "cwscale", FLOAT, &cwscale },
|
||||
{ "chscale", FLOAT, &chscale },
|
||||
};
|
||||
|
||||
/*
|
||||
* Internal mouse shortcuts.
|
||||
* Beware that overloading Button1 will disable the selection.
|
||||
*/
|
||||
static MouseShortcut mshortcuts[] = {
|
||||
/* mask button function argument release */
|
||||
{ XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 },
|
||||
{ ShiftMask, Button4, ttysend, {.s = "\033[5;2~"} },
|
||||
{ XK_ANY_MOD, Button4, ttysend, {.s = "\031"} },
|
||||
{ ShiftMask, Button5, ttysend, {.s = "\033[6;2~"} },
|
||||
{ XK_ANY_MOD, Button5, ttysend, {.s = "\005"} },
|
||||
};
|
||||
|
||||
/* Internal keyboard shortcuts. */
|
||||
#define MODKEY Mod1Mask
|
||||
#define TERMMOD (ControlMask|ShiftMask)
|
||||
|
||||
static Shortcut shortcuts[] = {
|
||||
/* mask keysym function argument */
|
||||
{ XK_ANY_MOD, XK_Break, sendbreak, {.i = 0} },
|
||||
{ ControlMask, XK_Print, toggleprinter, {.i = 0} },
|
||||
{ ShiftMask, XK_Print, printscreen, {.i = 0} },
|
||||
{ XK_ANY_MOD, XK_Print, printsel, {.i = 0} },
|
||||
{ TERMMOD, XK_Prior, zoom, {.f = +1} },
|
||||
{ TERMMOD, XK_Next, zoom, {.f = -1} },
|
||||
{ TERMMOD, XK_Home, zoomreset, {.f = 0} },
|
||||
{ TERMMOD, XK_0, zoomreset, {.f = 0} },
|
||||
{ TERMMOD, XK_parenright, zoomreset, {.f = 0} },
|
||||
{ TERMMOD, XK_equal, zoom, {.f = +1} },
|
||||
{ TERMMOD, XK_minus, zoom, {.f = -1} },
|
||||
{ TERMMOD, XK_C, clipcopy, {.i = 0} },
|
||||
{ TERMMOD, XK_V, clippaste, {.i = 0} },
|
||||
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
|
||||
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
|
||||
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
|
||||
|
||||
{ TERMMOD, XK_S, toggleselectionmode, {.i = 0} },
|
||||
|
||||
{ ShiftMask, XK_Prior, kscrollup, {.i = -1} },
|
||||
{ ShiftMask, XK_Next, kscrolldown, {.i = -1} },
|
||||
{ TERMMOD, XK_B, kscrollup, {.i = -1} },
|
||||
{ TERMMOD, XK_F, kscrolldown, {.i = -1} },
|
||||
{ TERMMOD, XK_X, invert, { } },
|
||||
{ TERMMOD, XK_plus, zoom, {.f = +1} },
|
||||
{ TERMMOD, XK_underscore, zoom, {.f = -1} },
|
||||
};
|
||||
|
||||
/*
|
||||
* Special keys (change & recompile st.info accordingly)
|
||||
*
|
||||
* Mask value:
|
||||
* * Use XK_ANY_MOD to match the key no matter modifiers state
|
||||
* * Use XK_NO_MOD to match the key alone (no modifiers)
|
||||
* appkey value:
|
||||
* * 0: no value
|
||||
* * > 0: keypad application mode enabled
|
||||
* * = 2: term.numlock = 1
|
||||
* * < 0: keypad application mode disabled
|
||||
* appcursor value:
|
||||
* * 0: no value
|
||||
* * > 0: cursor application mode enabled
|
||||
* * < 0: cursor application mode disabled
|
||||
*
|
||||
* Be careful with the order of the definitions because st searches in
|
||||
* this table sequentially, so any XK_ANY_MOD must be in the last
|
||||
* position for a key.
|
||||
*/
|
||||
|
||||
/*
|
||||
* If you want keys other than the X11 function keys (0xFD00 - 0xFFFF)
|
||||
* to be mapped below, add them to this array.
|
||||
*/
|
||||
static KeySym mappedkeys[] = { -1 };
|
||||
|
||||
/*
|
||||
* State bits to ignore when matching key or button events. By default,
|
||||
* numlock (Mod2Mask) and keyboard layout (XK_SWITCH_MOD) are ignored.
|
||||
*/
|
||||
static uint ignoremod = Mod2Mask|XK_SWITCH_MOD;
|
||||
|
||||
/*
|
||||
* This is the huge key array which defines all compatibility to the Linux
|
||||
* world. Please decide about changes wisely.
|
||||
*/
|
||||
static Key key[] = {
|
||||
/* keysym mask string appkey appcursor */
|
||||
{ XK_KP_Home, ShiftMask, "\033[2J", 0, -1},
|
||||
{ XK_KP_Home, ShiftMask, "\033[1;2H", 0, +1},
|
||||
{ XK_KP_Home, XK_ANY_MOD, "\033[H", 0, -1},
|
||||
{ XK_KP_Home, XK_ANY_MOD, "\033[1~", 0, +1},
|
||||
{ XK_KP_Up, XK_ANY_MOD, "\033Ox", +1, 0},
|
||||
{ XK_KP_Up, XK_ANY_MOD, "\033[A", 0, -1},
|
||||
{ XK_KP_Up, XK_ANY_MOD, "\033OA", 0, +1},
|
||||
{ XK_KP_Down, XK_ANY_MOD, "\033Or", +1, 0},
|
||||
{ XK_KP_Down, XK_ANY_MOD, "\033[B", 0, -1},
|
||||
{ XK_KP_Down, XK_ANY_MOD, "\033OB", 0, +1},
|
||||
{ XK_KP_Left, XK_ANY_MOD, "\033Ot", +1, 0},
|
||||
{ XK_KP_Left, XK_ANY_MOD, "\033[D", 0, -1},
|
||||
{ XK_KP_Left, XK_ANY_MOD, "\033OD", 0, +1},
|
||||
{ XK_KP_Right, XK_ANY_MOD, "\033Ov", +1, 0},
|
||||
{ XK_KP_Right, XK_ANY_MOD, "\033[C", 0, -1},
|
||||
{ XK_KP_Right, XK_ANY_MOD, "\033OC", 0, +1},
|
||||
{ XK_KP_Prior, ShiftMask, "\033[5;2~", 0, 0},
|
||||
{ XK_KP_Prior, XK_ANY_MOD, "\033[5~", 0, 0},
|
||||
{ XK_KP_Begin, XK_ANY_MOD, "\033[E", 0, 0},
|
||||
{ XK_KP_End, ControlMask, "\033[J", -1, 0},
|
||||
{ XK_KP_End, ControlMask, "\033[1;5F", +1, 0},
|
||||
{ XK_KP_End, ShiftMask, "\033[K", -1, 0},
|
||||
{ XK_KP_End, ShiftMask, "\033[1;2F", +1, 0},
|
||||
{ XK_KP_End, XK_ANY_MOD, "\033[4~", 0, 0},
|
||||
{ XK_KP_Next, ShiftMask, "\033[6;2~", 0, 0},
|
||||
{ XK_KP_Next, XK_ANY_MOD, "\033[6~", 0, 0},
|
||||
{ XK_KP_Insert, ShiftMask, "\033[2;2~", +1, 0},
|
||||
{ XK_KP_Insert, ShiftMask, "\033[4l", -1, 0},
|
||||
{ XK_KP_Insert, ControlMask, "\033[L", -1, 0},
|
||||
{ XK_KP_Insert, ControlMask, "\033[2;5~", +1, 0},
|
||||
{ XK_KP_Insert, XK_ANY_MOD, "\033[4h", -1, 0},
|
||||
{ XK_KP_Insert, XK_ANY_MOD, "\033[2~", +1, 0},
|
||||
{ XK_KP_Delete, ControlMask, "\033[M", -1, 0},
|
||||
{ XK_KP_Delete, ControlMask, "\033[3;5~", +1, 0},
|
||||
{ XK_KP_Delete, ShiftMask, "\033[2K", -1, 0},
|
||||
{ XK_KP_Delete, ShiftMask, "\033[3;2~", +1, 0},
|
||||
{ XK_KP_Delete, XK_ANY_MOD, "\033[P", -1, 0},
|
||||
{ XK_KP_Delete, XK_ANY_MOD, "\033[3~", +1, 0},
|
||||
{ XK_KP_Multiply, XK_ANY_MOD, "\033Oj", +2, 0},
|
||||
{ XK_KP_Add, XK_ANY_MOD, "\033Ok", +2, 0},
|
||||
{ XK_KP_Enter, XK_ANY_MOD, "\033OM", +2, 0},
|
||||
{ XK_KP_Enter, XK_ANY_MOD, "\r", -1, 0},
|
||||
{ XK_KP_Subtract, XK_ANY_MOD, "\033Om", +2, 0},
|
||||
{ XK_KP_Decimal, XK_ANY_MOD, "\033On", +2, 0},
|
||||
{ XK_KP_Divide, XK_ANY_MOD, "\033Oo", +2, 0},
|
||||
{ XK_KP_0, XK_ANY_MOD, "\033Op", +2, 0},
|
||||
{ XK_KP_1, XK_ANY_MOD, "\033Oq", +2, 0},
|
||||
{ XK_KP_2, XK_ANY_MOD, "\033Or", +2, 0},
|
||||
{ XK_KP_3, XK_ANY_MOD, "\033Os", +2, 0},
|
||||
{ XK_KP_4, XK_ANY_MOD, "\033Ot", +2, 0},
|
||||
{ XK_KP_5, XK_ANY_MOD, "\033Ou", +2, 0},
|
||||
{ XK_KP_6, XK_ANY_MOD, "\033Ov", +2, 0},
|
||||
{ XK_KP_7, XK_ANY_MOD, "\033Ow", +2, 0},
|
||||
{ XK_KP_8, XK_ANY_MOD, "\033Ox", +2, 0},
|
||||
{ XK_KP_9, XK_ANY_MOD, "\033Oy", +2, 0},
|
||||
{ XK_Up, ShiftMask, "\033[1;2A", 0, 0},
|
||||
{ XK_Up, Mod1Mask, "\033[1;3A", 0, 0},
|
||||
{ XK_Up, ShiftMask|Mod1Mask,"\033[1;4A", 0, 0},
|
||||
{ XK_Up, ControlMask, "\033[1;5A", 0, 0},
|
||||
{ XK_Up, ShiftMask|ControlMask,"\033[1;6A", 0, 0},
|
||||
{ XK_Up, ControlMask|Mod1Mask,"\033[1;7A", 0, 0},
|
||||
{ XK_Up,ShiftMask|ControlMask|Mod1Mask,"\033[1;8A", 0, 0},
|
||||
{ XK_Up, XK_ANY_MOD, "\033[A", 0, -1},
|
||||
{ XK_Up, XK_ANY_MOD, "\033OA", 0, +1},
|
||||
{ XK_Down, ShiftMask, "\033[1;2B", 0, 0},
|
||||
{ XK_Down, Mod1Mask, "\033[1;3B", 0, 0},
|
||||
{ XK_Down, ShiftMask|Mod1Mask,"\033[1;4B", 0, 0},
|
||||
{ XK_Down, ControlMask, "\033[1;5B", 0, 0},
|
||||
{ XK_Down, ShiftMask|ControlMask,"\033[1;6B", 0, 0},
|
||||
{ XK_Down, ControlMask|Mod1Mask,"\033[1;7B", 0, 0},
|
||||
{ XK_Down,ShiftMask|ControlMask|Mod1Mask,"\033[1;8B",0, 0},
|
||||
{ XK_Down, XK_ANY_MOD, "\033[B", 0, -1},
|
||||
{ XK_Down, XK_ANY_MOD, "\033OB", 0, +1},
|
||||
{ XK_Left, ShiftMask, "\033[1;2D", 0, 0},
|
||||
{ XK_Left, Mod1Mask, "\033[1;3D", 0, 0},
|
||||
{ XK_Left, ShiftMask|Mod1Mask,"\033[1;4D", 0, 0},
|
||||
{ XK_Left, ControlMask, "\033[1;5D", 0, 0},
|
||||
{ XK_Left, ShiftMask|ControlMask,"\033[1;6D", 0, 0},
|
||||
{ XK_Left, ControlMask|Mod1Mask,"\033[1;7D", 0, 0},
|
||||
{ XK_Left,ShiftMask|ControlMask|Mod1Mask,"\033[1;8D",0, 0},
|
||||
{ XK_Left, XK_ANY_MOD, "\033[D", 0, -1},
|
||||
{ XK_Left, XK_ANY_MOD, "\033OD", 0, +1},
|
||||
{ XK_Right, ShiftMask, "\033[1;2C", 0, 0},
|
||||
{ XK_Right, Mod1Mask, "\033[1;3C", 0, 0},
|
||||
{ XK_Right, ShiftMask|Mod1Mask,"\033[1;4C", 0, 0},
|
||||
{ XK_Right, ControlMask, "\033[1;5C", 0, 0},
|
||||
{ XK_Right, ShiftMask|ControlMask,"\033[1;6C", 0, 0},
|
||||
{ XK_Right, ControlMask|Mod1Mask,"\033[1;7C", 0, 0},
|
||||
{ XK_Right,ShiftMask|ControlMask|Mod1Mask,"\033[1;8C",0, 0},
|
||||
{ XK_Right, XK_ANY_MOD, "\033[C", 0, -1},
|
||||
{ XK_Right, XK_ANY_MOD, "\033OC", 0, +1},
|
||||
{ XK_ISO_Left_Tab, ShiftMask, "\033[Z", 0, 0},
|
||||
{ XK_Return, Mod1Mask, "\033\r", 0, 0},
|
||||
{ XK_Return, XK_ANY_MOD, "\r", 0, 0},
|
||||
{ XK_Insert, ShiftMask, "\033[4l", -1, 0},
|
||||
{ XK_Insert, ShiftMask, "\033[2;2~", +1, 0},
|
||||
{ XK_Insert, ControlMask, "\033[L", -1, 0},
|
||||
{ XK_Insert, ControlMask, "\033[2;5~", +1, 0},
|
||||
{ XK_Insert, XK_ANY_MOD, "\033[4h", -1, 0},
|
||||
{ XK_Insert, XK_ANY_MOD, "\033[2~", +1, 0},
|
||||
{ XK_Delete, ControlMask, "\033[M", -1, 0},
|
||||
{ XK_Delete, ControlMask, "\033[3;5~", +1, 0},
|
||||
{ XK_Delete, ShiftMask, "\033[2K", -1, 0},
|
||||
{ XK_Delete, ShiftMask, "\033[3;2~", +1, 0},
|
||||
{ XK_Delete, XK_ANY_MOD, "\033[P", -1, 0},
|
||||
{ XK_Delete, XK_ANY_MOD, "\033[3~", +1, 0},
|
||||
{ XK_BackSpace, XK_NO_MOD, "\177", 0, 0},
|
||||
{ XK_BackSpace, Mod1Mask, "\033\177", 0, 0},
|
||||
{ XK_Home, ShiftMask, "\033[2J", 0, -1},
|
||||
{ XK_Home, ShiftMask, "\033[1;2H", 0, +1},
|
||||
{ XK_Home, XK_ANY_MOD, "\033[H", 0, -1},
|
||||
{ XK_Home, XK_ANY_MOD, "\033[1~", 0, +1},
|
||||
{ XK_End, ControlMask, "\033[J", -1, 0},
|
||||
{ XK_End, ControlMask, "\033[1;5F", +1, 0},
|
||||
{ XK_End, ShiftMask, "\033[K", -1, 0},
|
||||
{ XK_End, ShiftMask, "\033[1;2F", +1, 0},
|
||||
{ XK_End, XK_ANY_MOD, "\033[4~", 0, 0},
|
||||
{ XK_Prior, ControlMask, "\033[5;5~", 0, 0},
|
||||
{ XK_Prior, ShiftMask, "\033[5;2~", 0, 0},
|
||||
{ XK_Prior, XK_ANY_MOD, "\033[5~", 0, 0},
|
||||
{ XK_Next, ControlMask, "\033[6;5~", 0, 0},
|
||||
{ XK_Next, ShiftMask, "\033[6;2~", 0, 0},
|
||||
{ XK_Next, XK_ANY_MOD, "\033[6~", 0, 0},
|
||||
{ XK_F1, XK_NO_MOD, "\033OP" , 0, 0},
|
||||
{ XK_F1, /* F13 */ ShiftMask, "\033[1;2P", 0, 0},
|
||||
{ XK_F1, /* F25 */ ControlMask, "\033[1;5P", 0, 0},
|
||||
{ XK_F1, /* F37 */ Mod4Mask, "\033[1;6P", 0, 0},
|
||||
{ XK_F1, /* F49 */ Mod1Mask, "\033[1;3P", 0, 0},
|
||||
{ XK_F1, /* F61 */ Mod3Mask, "\033[1;4P", 0, 0},
|
||||
{ XK_F2, XK_NO_MOD, "\033OQ" , 0, 0},
|
||||
{ XK_F2, /* F14 */ ShiftMask, "\033[1;2Q", 0, 0},
|
||||
{ XK_F2, /* F26 */ ControlMask, "\033[1;5Q", 0, 0},
|
||||
{ XK_F2, /* F38 */ Mod4Mask, "\033[1;6Q", 0, 0},
|
||||
{ XK_F2, /* F50 */ Mod1Mask, "\033[1;3Q", 0, 0},
|
||||
{ XK_F2, /* F62 */ Mod3Mask, "\033[1;4Q", 0, 0},
|
||||
{ XK_F3, XK_NO_MOD, "\033OR" , 0, 0},
|
||||
{ XK_F3, /* F15 */ ShiftMask, "\033[1;2R", 0, 0},
|
||||
{ XK_F3, /* F27 */ ControlMask, "\033[1;5R", 0, 0},
|
||||
{ XK_F3, /* F39 */ Mod4Mask, "\033[1;6R", 0, 0},
|
||||
{ XK_F3, /* F51 */ Mod1Mask, "\033[1;3R", 0, 0},
|
||||
{ XK_F3, /* F63 */ Mod3Mask, "\033[1;4R", 0, 0},
|
||||
{ XK_F4, XK_NO_MOD, "\033OS" , 0, 0},
|
||||
{ XK_F4, /* F16 */ ShiftMask, "\033[1;2S", 0, 0},
|
||||
{ XK_F4, /* F28 */ ControlMask, "\033[1;5S", 0, 0},
|
||||
{ XK_F4, /* F40 */ Mod4Mask, "\033[1;6S", 0, 0},
|
||||
{ XK_F4, /* F52 */ Mod1Mask, "\033[1;3S", 0, 0},
|
||||
{ XK_F5, XK_NO_MOD, "\033[15~", 0, 0},
|
||||
{ XK_F5, /* F17 */ ShiftMask, "\033[15;2~", 0, 0},
|
||||
{ XK_F5, /* F29 */ ControlMask, "\033[15;5~", 0, 0},
|
||||
{ XK_F5, /* F41 */ Mod4Mask, "\033[15;6~", 0, 0},
|
||||
{ XK_F5, /* F53 */ Mod1Mask, "\033[15;3~", 0, 0},
|
||||
{ XK_F6, XK_NO_MOD, "\033[17~", 0, 0},
|
||||
{ XK_F6, /* F18 */ ShiftMask, "\033[17;2~", 0, 0},
|
||||
{ XK_F6, /* F30 */ ControlMask, "\033[17;5~", 0, 0},
|
||||
{ XK_F6, /* F42 */ Mod4Mask, "\033[17;6~", 0, 0},
|
||||
{ XK_F6, /* F54 */ Mod1Mask, "\033[17;3~", 0, 0},
|
||||
{ XK_F7, XK_NO_MOD, "\033[18~", 0, 0},
|
||||
{ XK_F7, /* F19 */ ShiftMask, "\033[18;2~", 0, 0},
|
||||
{ XK_F7, /* F31 */ ControlMask, "\033[18;5~", 0, 0},
|
||||
{ XK_F7, /* F43 */ Mod4Mask, "\033[18;6~", 0, 0},
|
||||
{ XK_F7, /* F55 */ Mod1Mask, "\033[18;3~", 0, 0},
|
||||
{ XK_F8, XK_NO_MOD, "\033[19~", 0, 0},
|
||||
{ XK_F8, /* F20 */ ShiftMask, "\033[19;2~", 0, 0},
|
||||
{ XK_F8, /* F32 */ ControlMask, "\033[19;5~", 0, 0},
|
||||
{ XK_F8, /* F44 */ Mod4Mask, "\033[19;6~", 0, 0},
|
||||
{ XK_F8, /* F56 */ Mod1Mask, "\033[19;3~", 0, 0},
|
||||
{ XK_F9, XK_NO_MOD, "\033[20~", 0, 0},
|
||||
{ XK_F9, /* F21 */ ShiftMask, "\033[20;2~", 0, 0},
|
||||
{ XK_F9, /* F33 */ ControlMask, "\033[20;5~", 0, 0},
|
||||
{ XK_F9, /* F45 */ Mod4Mask, "\033[20;6~", 0, 0},
|
||||
{ XK_F9, /* F57 */ Mod1Mask, "\033[20;3~", 0, 0},
|
||||
{ XK_F10, XK_NO_MOD, "\033[21~", 0, 0},
|
||||
{ XK_F10, /* F22 */ ShiftMask, "\033[21;2~", 0, 0},
|
||||
{ XK_F10, /* F34 */ ControlMask, "\033[21;5~", 0, 0},
|
||||
{ XK_F10, /* F46 */ Mod4Mask, "\033[21;6~", 0, 0},
|
||||
{ XK_F10, /* F58 */ Mod1Mask, "\033[21;3~", 0, 0},
|
||||
{ XK_F11, XK_NO_MOD, "\033[23~", 0, 0},
|
||||
{ XK_F11, /* F23 */ ShiftMask, "\033[23;2~", 0, 0},
|
||||
{ XK_F11, /* F35 */ ControlMask, "\033[23;5~", 0, 0},
|
||||
{ XK_F11, /* F47 */ Mod4Mask, "\033[23;6~", 0, 0},
|
||||
{ XK_F11, /* F59 */ Mod1Mask, "\033[23;3~", 0, 0},
|
||||
{ XK_F12, XK_NO_MOD, "\033[24~", 0, 0},
|
||||
{ XK_F12, /* F24 */ ShiftMask, "\033[24;2~", 0, 0},
|
||||
{ XK_F12, /* F36 */ ControlMask, "\033[24;5~", 0, 0},
|
||||
{ XK_F12, /* F48 */ Mod4Mask, "\033[24;6~", 0, 0},
|
||||
{ XK_F12, /* F60 */ Mod1Mask, "\033[24;3~", 0, 0},
|
||||
{ XK_F13, XK_NO_MOD, "\033[1;2P", 0, 0},
|
||||
{ XK_F14, XK_NO_MOD, "\033[1;2Q", 0, 0},
|
||||
{ XK_F15, XK_NO_MOD, "\033[1;2R", 0, 0},
|
||||
{ XK_F16, XK_NO_MOD, "\033[1;2S", 0, 0},
|
||||
{ XK_F17, XK_NO_MOD, "\033[15;2~", 0, 0},
|
||||
{ XK_F18, XK_NO_MOD, "\033[17;2~", 0, 0},
|
||||
{ XK_F19, XK_NO_MOD, "\033[18;2~", 0, 0},
|
||||
{ XK_F20, XK_NO_MOD, "\033[19;2~", 0, 0},
|
||||
{ XK_F21, XK_NO_MOD, "\033[20;2~", 0, 0},
|
||||
{ XK_F22, XK_NO_MOD, "\033[21;2~", 0, 0},
|
||||
{ XK_F23, XK_NO_MOD, "\033[23;2~", 0, 0},
|
||||
{ XK_F24, XK_NO_MOD, "\033[24;2~", 0, 0},
|
||||
{ XK_F25, XK_NO_MOD, "\033[1;5P", 0, 0},
|
||||
{ XK_F26, XK_NO_MOD, "\033[1;5Q", 0, 0},
|
||||
{ XK_F27, XK_NO_MOD, "\033[1;5R", 0, 0},
|
||||
{ XK_F28, XK_NO_MOD, "\033[1;5S", 0, 0},
|
||||
{ XK_F29, XK_NO_MOD, "\033[15;5~", 0, 0},
|
||||
{ XK_F30, XK_NO_MOD, "\033[17;5~", 0, 0},
|
||||
{ XK_F31, XK_NO_MOD, "\033[18;5~", 0, 0},
|
||||
{ XK_F32, XK_NO_MOD, "\033[19;5~", 0, 0},
|
||||
{ XK_F33, XK_NO_MOD, "\033[20;5~", 0, 0},
|
||||
{ XK_F34, XK_NO_MOD, "\033[21;5~", 0, 0},
|
||||
{ XK_F35, XK_NO_MOD, "\033[23;5~", 0, 0},
|
||||
};
|
||||
|
||||
/*
|
||||
* Selection types' masks.
|
||||
* Use the same masks as usual.
|
||||
* Button1Mask is always unset, to make masks match between ButtonPress.
|
||||
* ButtonRelease and MotionNotify.
|
||||
* If no match is found, regular selection is used.
|
||||
*/
|
||||
static uint selmasks[] = {
|
||||
[SEL_RECTANGULAR] = Mod1Mask,
|
||||
};
|
||||
|
||||
/*
|
||||
* Printable characters in ASCII, used to estimate the advance width
|
||||
* of single wide characters.
|
||||
*/
|
||||
static char ascii_printable[] =
|
||||
" !\"#$%&'()*+,-./0123456789:;<=>?"
|
||||
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
|
||||
"`abcdefghijklmnopqrstuvwxyz{|}~";
|
||||
+522
@@ -0,0 +1,522 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
|
||||
/*
|
||||
* appearance
|
||||
*
|
||||
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
|
||||
*/
|
||||
static char *font = "Fira Code:pixelsize=24:style=Regular:antialias=true:autohint=true";
|
||||
static int borderpx = 2;
|
||||
|
||||
/*
|
||||
* What program is execed by st depends of these precedence rules:
|
||||
* 1: program passed with -e
|
||||
* 2: scroll and/or utmp
|
||||
* 3: SHELL environment variable
|
||||
* 4: value of shell in /etc/passwd
|
||||
* 5: value of shell in config.h
|
||||
*/
|
||||
static char *shell = "/bin/sh";
|
||||
char *utmp = NULL;
|
||||
/* scroll program: to enable use a string like "scroll" */
|
||||
char *scroll = NULL;
|
||||
char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400";
|
||||
|
||||
/* identification sequence returned in DA and DECID */
|
||||
char *vtiden = "\033[?6c";
|
||||
|
||||
/* Kerning / character bounding-box multipliers */
|
||||
static float cwscale = 1.0;
|
||||
static float chscale = 1.0;
|
||||
|
||||
/*
|
||||
* word delimiter string
|
||||
*
|
||||
* More advanced example: L" `'\"()[]{}"
|
||||
*/
|
||||
wchar_t *worddelimiters = L" ";
|
||||
|
||||
/* selection timeouts (in milliseconds) */
|
||||
static unsigned int doubleclicktimeout = 1000;
|
||||
static unsigned int tripleclicktimeout = 2000;
|
||||
|
||||
/* alt screens */
|
||||
int allowaltscreen = 1;
|
||||
|
||||
/* allow certain non-interactive (insecure) window operations such as:
|
||||
setting the clipboard text */
|
||||
int allowwindowops = 0;
|
||||
|
||||
/*
|
||||
* draw latency range in ms - from new content/keypress/etc until drawing.
|
||||
* within this range, st draws when content stops arriving (idle). mostly it's
|
||||
* near minlatency, but it waits longer for slow updates to avoid partial draw.
|
||||
* low minlatency will tear/flicker more, as it can "detect" idle too early.
|
||||
*/
|
||||
static double minlatency = 8;
|
||||
static double maxlatency = 33;
|
||||
|
||||
/*
|
||||
* blinking timeout (set to 0 to disable blinking) for the terminal blinking
|
||||
* attribute.
|
||||
*/
|
||||
static unsigned int blinktimeout = 800;
|
||||
|
||||
/*
|
||||
* thickness of underline and bar cursors
|
||||
*/
|
||||
static unsigned int cursorthickness = 2;
|
||||
|
||||
/*
|
||||
* bell volume. It must be a value between -100 and 100. Use 0 for disabling
|
||||
* it
|
||||
*/
|
||||
static int bellvolume = 0;
|
||||
|
||||
/* default TERM value */
|
||||
char *termname = "st-256color";
|
||||
|
||||
/*
|
||||
* spaces per tab
|
||||
*
|
||||
* When you are changing this value, don't forget to adapt the »it« value in
|
||||
* the st.info and appropriately install the st.info in the environment where
|
||||
* you use this st version.
|
||||
*
|
||||
* it#$tabspaces,
|
||||
*
|
||||
* Secondly make sure your kernel is not expanding tabs. When running `stty
|
||||
* -a` »tab0« should appear. You can tell the terminal to not expand tabs by
|
||||
* running following command:
|
||||
*
|
||||
* stty tabs
|
||||
*/
|
||||
unsigned int tabspaces = 8;
|
||||
|
||||
/* Terminal colors (16 first used in escape sequence) */
|
||||
static const char *colorname[] = {
|
||||
/* 8 normal colors */
|
||||
"black",
|
||||
"red3",
|
||||
"green3",
|
||||
"yellow3",
|
||||
"blue2",
|
||||
"magenta3",
|
||||
"cyan3",
|
||||
"gray90",
|
||||
|
||||
/* 8 bright colors */
|
||||
"gray50",
|
||||
"red",
|
||||
"green",
|
||||
"yellow",
|
||||
"#5c5cff",
|
||||
"magenta",
|
||||
"cyan",
|
||||
"white",
|
||||
|
||||
[255] = 0,
|
||||
|
||||
/* more colors can be added after 255 to use with DefaultXX */
|
||||
"#161616",
|
||||
"#dddddd",
|
||||
"#f4d03f",
|
||||
"#555555",
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Default colors (colorname index)
|
||||
* foreground, background, cursor, reverse cursor
|
||||
*/
|
||||
unsigned int defaultfg = 257;
|
||||
unsigned int defaultbg = 256;
|
||||
static unsigned int defaultcs = 258;
|
||||
static unsigned int defaultrcs = 259;
|
||||
|
||||
/*
|
||||
* Default shape of cursor
|
||||
* 2: Block ("█")
|
||||
* 4: Underline ("_")
|
||||
* 6: Bar ("|")
|
||||
* 7: Snowman ("☃")
|
||||
*/
|
||||
static unsigned int cursorshape = 2;
|
||||
|
||||
/*
|
||||
* Default columns and rows numbers
|
||||
*/
|
||||
|
||||
static unsigned int cols = 80;
|
||||
static unsigned int rows = 24;
|
||||
|
||||
/*
|
||||
* Default colour and shape of the mouse cursor
|
||||
*/
|
||||
static unsigned int mouseshape = XC_xterm;
|
||||
static unsigned int mousefg = 7;
|
||||
static unsigned int mousebg = 0;
|
||||
|
||||
/*
|
||||
* Color used to display font attributes when fontconfig selected a font which
|
||||
* doesn't match the ones requested.
|
||||
*/
|
||||
static unsigned int defaultattr = 11;
|
||||
|
||||
/*
|
||||
* Force mouse select/shortcuts while mask is active (when MODE_MOUSE is set).
|
||||
* Note that if you want to use ShiftMask with selmasks, set this to an other
|
||||
* modifier, set to 0 to not use it.
|
||||
*/
|
||||
static uint forcemousemod = ShiftMask;
|
||||
|
||||
/*
|
||||
* Xresources preferences to load at startup
|
||||
*/
|
||||
ResourcePref resources[] = {
|
||||
{ "font", STRING, &font },
|
||||
{ "color0", STRING, &colorname[0] },
|
||||
{ "color1", STRING, &colorname[1] },
|
||||
{ "color2", STRING, &colorname[2] },
|
||||
{ "color3", STRING, &colorname[3] },
|
||||
{ "color4", STRING, &colorname[4] },
|
||||
{ "color5", STRING, &colorname[5] },
|
||||
{ "color6", STRING, &colorname[6] },
|
||||
{ "color7", STRING, &colorname[7] },
|
||||
{ "color8", STRING, &colorname[8] },
|
||||
{ "color9", STRING, &colorname[9] },
|
||||
{ "color10", STRING, &colorname[10] },
|
||||
{ "color11", STRING, &colorname[11] },
|
||||
{ "color12", STRING, &colorname[12] },
|
||||
{ "color13", STRING, &colorname[13] },
|
||||
{ "color14", STRING, &colorname[14] },
|
||||
{ "color15", STRING, &colorname[15] },
|
||||
{ "background", STRING, &colorname[256] },
|
||||
{ "foreground", STRING, &colorname[257] },
|
||||
{ "cursorColor", STRING, &colorname[258] },
|
||||
{ "termname", STRING, &termname },
|
||||
{ "shell", STRING, &shell },
|
||||
{ "blinktimeout", INTEGER, &blinktimeout },
|
||||
{ "bellvolume", INTEGER, &bellvolume },
|
||||
{ "tabspaces", INTEGER, &tabspaces },
|
||||
{ "borderpx", INTEGER, &borderpx },
|
||||
{ "cwscale", FLOAT, &cwscale },
|
||||
{ "chscale", FLOAT, &chscale },
|
||||
};
|
||||
|
||||
/*
|
||||
* Internal mouse shortcuts.
|
||||
* Beware that overloading Button1 will disable the selection.
|
||||
*/
|
||||
static MouseShortcut mshortcuts[] = {
|
||||
/* mask button function argument release */
|
||||
{ XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 },
|
||||
{ ShiftMask, Button4, ttysend, {.s = "\033[5;2~"} },
|
||||
{ XK_ANY_MOD, Button4, ttysend, {.s = "\031"} },
|
||||
{ ShiftMask, Button5, ttysend, {.s = "\033[6;2~"} },
|
||||
{ XK_ANY_MOD, Button5, ttysend, {.s = "\005"} },
|
||||
};
|
||||
|
||||
/* Internal keyboard shortcuts. */
|
||||
#define MODKEY Mod1Mask
|
||||
#define TERMMOD (ControlMask|ShiftMask)
|
||||
|
||||
static Shortcut shortcuts[] = {
|
||||
/* mask keysym function argument */
|
||||
{ XK_ANY_MOD, XK_Break, sendbreak, {.i = 0} },
|
||||
{ ControlMask, XK_Print, toggleprinter, {.i = 0} },
|
||||
{ ShiftMask, XK_Print, printscreen, {.i = 0} },
|
||||
{ XK_ANY_MOD, XK_Print, printsel, {.i = 0} },
|
||||
{ TERMMOD, XK_Prior, zoom, {.f = +1} },
|
||||
{ TERMMOD, XK_Next, zoom, {.f = -1} },
|
||||
{ TERMMOD, XK_Home, zoomreset, {.f = 0} },
|
||||
{ TERMMOD, XK_0, zoomreset, {.f = 0} },
|
||||
{ TERMMOD, XK_parenright, zoomreset, {.f = 0} },
|
||||
{ TERMMOD, XK_equal, zoom, {.f = +1} },
|
||||
{ TERMMOD, XK_minus, zoom, {.f = -1} },
|
||||
{ TERMMOD, XK_C, clipcopy, {.i = 0} },
|
||||
{ TERMMOD, XK_V, clippaste, {.i = 0} },
|
||||
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
|
||||
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
|
||||
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
|
||||
|
||||
{ TERMMOD, XK_S, toggleselectionmode, {.i = 0} },
|
||||
|
||||
{ ShiftMask, XK_Prior, kscrollup, {.i = -1} },
|
||||
{ ShiftMask, XK_Next, kscrolldown, {.i = -1} },
|
||||
{ TERMMOD, XK_B, kscrollup, {.i = -1} },
|
||||
{ TERMMOD, XK_F, kscrolldown, {.i = -1} },
|
||||
{ TERMMOD, XK_X, invert, { } },
|
||||
{ TERMMOD, XK_plus, zoom, {.f = +1} },
|
||||
{ TERMMOD, XK_underscore, zoom, {.f = -1} },
|
||||
};
|
||||
|
||||
/*
|
||||
* Special keys (change & recompile st.info accordingly)
|
||||
*
|
||||
* Mask value:
|
||||
* * Use XK_ANY_MOD to match the key no matter modifiers state
|
||||
* * Use XK_NO_MOD to match the key alone (no modifiers)
|
||||
* appkey value:
|
||||
* * 0: no value
|
||||
* * > 0: keypad application mode enabled
|
||||
* * = 2: term.numlock = 1
|
||||
* * < 0: keypad application mode disabled
|
||||
* appcursor value:
|
||||
* * 0: no value
|
||||
* * > 0: cursor application mode enabled
|
||||
* * < 0: cursor application mode disabled
|
||||
*
|
||||
* Be careful with the order of the definitions because st searches in
|
||||
* this table sequentially, so any XK_ANY_MOD must be in the last
|
||||
* position for a key.
|
||||
*/
|
||||
|
||||
/*
|
||||
* If you want keys other than the X11 function keys (0xFD00 - 0xFFFF)
|
||||
* to be mapped below, add them to this array.
|
||||
*/
|
||||
static KeySym mappedkeys[] = { -1 };
|
||||
|
||||
/*
|
||||
* State bits to ignore when matching key or button events. By default,
|
||||
* numlock (Mod2Mask) and keyboard layout (XK_SWITCH_MOD) are ignored.
|
||||
*/
|
||||
static uint ignoremod = Mod2Mask|XK_SWITCH_MOD;
|
||||
|
||||
/*
|
||||
* This is the huge key array which defines all compatibility to the Linux
|
||||
* world. Please decide about changes wisely.
|
||||
*/
|
||||
static Key key[] = {
|
||||
/* keysym mask string appkey appcursor */
|
||||
{ XK_KP_Home, ShiftMask, "\033[2J", 0, -1},
|
||||
{ XK_KP_Home, ShiftMask, "\033[1;2H", 0, +1},
|
||||
{ XK_KP_Home, XK_ANY_MOD, "\033[H", 0, -1},
|
||||
{ XK_KP_Home, XK_ANY_MOD, "\033[1~", 0, +1},
|
||||
{ XK_KP_Up, XK_ANY_MOD, "\033Ox", +1, 0},
|
||||
{ XK_KP_Up, XK_ANY_MOD, "\033[A", 0, -1},
|
||||
{ XK_KP_Up, XK_ANY_MOD, "\033OA", 0, +1},
|
||||
{ XK_KP_Down, XK_ANY_MOD, "\033Or", +1, 0},
|
||||
{ XK_KP_Down, XK_ANY_MOD, "\033[B", 0, -1},
|
||||
{ XK_KP_Down, XK_ANY_MOD, "\033OB", 0, +1},
|
||||
{ XK_KP_Left, XK_ANY_MOD, "\033Ot", +1, 0},
|
||||
{ XK_KP_Left, XK_ANY_MOD, "\033[D", 0, -1},
|
||||
{ XK_KP_Left, XK_ANY_MOD, "\033OD", 0, +1},
|
||||
{ XK_KP_Right, XK_ANY_MOD, "\033Ov", +1, 0},
|
||||
{ XK_KP_Right, XK_ANY_MOD, "\033[C", 0, -1},
|
||||
{ XK_KP_Right, XK_ANY_MOD, "\033OC", 0, +1},
|
||||
{ XK_KP_Prior, ShiftMask, "\033[5;2~", 0, 0},
|
||||
{ XK_KP_Prior, XK_ANY_MOD, "\033[5~", 0, 0},
|
||||
{ XK_KP_Begin, XK_ANY_MOD, "\033[E", 0, 0},
|
||||
{ XK_KP_End, ControlMask, "\033[J", -1, 0},
|
||||
{ XK_KP_End, ControlMask, "\033[1;5F", +1, 0},
|
||||
{ XK_KP_End, ShiftMask, "\033[K", -1, 0},
|
||||
{ XK_KP_End, ShiftMask, "\033[1;2F", +1, 0},
|
||||
{ XK_KP_End, XK_ANY_MOD, "\033[4~", 0, 0},
|
||||
{ XK_KP_Next, ShiftMask, "\033[6;2~", 0, 0},
|
||||
{ XK_KP_Next, XK_ANY_MOD, "\033[6~", 0, 0},
|
||||
{ XK_KP_Insert, ShiftMask, "\033[2;2~", +1, 0},
|
||||
{ XK_KP_Insert, ShiftMask, "\033[4l", -1, 0},
|
||||
{ XK_KP_Insert, ControlMask, "\033[L", -1, 0},
|
||||
{ XK_KP_Insert, ControlMask, "\033[2;5~", +1, 0},
|
||||
{ XK_KP_Insert, XK_ANY_MOD, "\033[4h", -1, 0},
|
||||
{ XK_KP_Insert, XK_ANY_MOD, "\033[2~", +1, 0},
|
||||
{ XK_KP_Delete, ControlMask, "\033[M", -1, 0},
|
||||
{ XK_KP_Delete, ControlMask, "\033[3;5~", +1, 0},
|
||||
{ XK_KP_Delete, ShiftMask, "\033[2K", -1, 0},
|
||||
{ XK_KP_Delete, ShiftMask, "\033[3;2~", +1, 0},
|
||||
{ XK_KP_Delete, XK_ANY_MOD, "\033[P", -1, 0},
|
||||
{ XK_KP_Delete, XK_ANY_MOD, "\033[3~", +1, 0},
|
||||
{ XK_KP_Multiply, XK_ANY_MOD, "\033Oj", +2, 0},
|
||||
{ XK_KP_Add, XK_ANY_MOD, "\033Ok", +2, 0},
|
||||
{ XK_KP_Enter, XK_ANY_MOD, "\033OM", +2, 0},
|
||||
{ XK_KP_Enter, XK_ANY_MOD, "\r", -1, 0},
|
||||
{ XK_KP_Subtract, XK_ANY_MOD, "\033Om", +2, 0},
|
||||
{ XK_KP_Decimal, XK_ANY_MOD, "\033On", +2, 0},
|
||||
{ XK_KP_Divide, XK_ANY_MOD, "\033Oo", +2, 0},
|
||||
{ XK_KP_0, XK_ANY_MOD, "\033Op", +2, 0},
|
||||
{ XK_KP_1, XK_ANY_MOD, "\033Oq", +2, 0},
|
||||
{ XK_KP_2, XK_ANY_MOD, "\033Or", +2, 0},
|
||||
{ XK_KP_3, XK_ANY_MOD, "\033Os", +2, 0},
|
||||
{ XK_KP_4, XK_ANY_MOD, "\033Ot", +2, 0},
|
||||
{ XK_KP_5, XK_ANY_MOD, "\033Ou", +2, 0},
|
||||
{ XK_KP_6, XK_ANY_MOD, "\033Ov", +2, 0},
|
||||
{ XK_KP_7, XK_ANY_MOD, "\033Ow", +2, 0},
|
||||
{ XK_KP_8, XK_ANY_MOD, "\033Ox", +2, 0},
|
||||
{ XK_KP_9, XK_ANY_MOD, "\033Oy", +2, 0},
|
||||
{ XK_Up, ShiftMask, "\033[1;2A", 0, 0},
|
||||
{ XK_Up, Mod1Mask, "\033[1;3A", 0, 0},
|
||||
{ XK_Up, ShiftMask|Mod1Mask,"\033[1;4A", 0, 0},
|
||||
{ XK_Up, ControlMask, "\033[1;5A", 0, 0},
|
||||
{ XK_Up, ShiftMask|ControlMask,"\033[1;6A", 0, 0},
|
||||
{ XK_Up, ControlMask|Mod1Mask,"\033[1;7A", 0, 0},
|
||||
{ XK_Up,ShiftMask|ControlMask|Mod1Mask,"\033[1;8A", 0, 0},
|
||||
{ XK_Up, XK_ANY_MOD, "\033[A", 0, -1},
|
||||
{ XK_Up, XK_ANY_MOD, "\033OA", 0, +1},
|
||||
{ XK_Down, ShiftMask, "\033[1;2B", 0, 0},
|
||||
{ XK_Down, Mod1Mask, "\033[1;3B", 0, 0},
|
||||
{ XK_Down, ShiftMask|Mod1Mask,"\033[1;4B", 0, 0},
|
||||
{ XK_Down, ControlMask, "\033[1;5B", 0, 0},
|
||||
{ XK_Down, ShiftMask|ControlMask,"\033[1;6B", 0, 0},
|
||||
{ XK_Down, ControlMask|Mod1Mask,"\033[1;7B", 0, 0},
|
||||
{ XK_Down,ShiftMask|ControlMask|Mod1Mask,"\033[1;8B",0, 0},
|
||||
{ XK_Down, XK_ANY_MOD, "\033[B", 0, -1},
|
||||
{ XK_Down, XK_ANY_MOD, "\033OB", 0, +1},
|
||||
{ XK_Left, ShiftMask, "\033[1;2D", 0, 0},
|
||||
{ XK_Left, Mod1Mask, "\033[1;3D", 0, 0},
|
||||
{ XK_Left, ShiftMask|Mod1Mask,"\033[1;4D", 0, 0},
|
||||
{ XK_Left, ControlMask, "\033[1;5D", 0, 0},
|
||||
{ XK_Left, ShiftMask|ControlMask,"\033[1;6D", 0, 0},
|
||||
{ XK_Left, ControlMask|Mod1Mask,"\033[1;7D", 0, 0},
|
||||
{ XK_Left,ShiftMask|ControlMask|Mod1Mask,"\033[1;8D",0, 0},
|
||||
{ XK_Left, XK_ANY_MOD, "\033[D", 0, -1},
|
||||
{ XK_Left, XK_ANY_MOD, "\033OD", 0, +1},
|
||||
{ XK_Right, ShiftMask, "\033[1;2C", 0, 0},
|
||||
{ XK_Right, Mod1Mask, "\033[1;3C", 0, 0},
|
||||
{ XK_Right, ShiftMask|Mod1Mask,"\033[1;4C", 0, 0},
|
||||
{ XK_Right, ControlMask, "\033[1;5C", 0, 0},
|
||||
{ XK_Right, ShiftMask|ControlMask,"\033[1;6C", 0, 0},
|
||||
{ XK_Right, ControlMask|Mod1Mask,"\033[1;7C", 0, 0},
|
||||
{ XK_Right,ShiftMask|ControlMask|Mod1Mask,"\033[1;8C",0, 0},
|
||||
{ XK_Right, XK_ANY_MOD, "\033[C", 0, -1},
|
||||
{ XK_Right, XK_ANY_MOD, "\033OC", 0, +1},
|
||||
{ XK_ISO_Left_Tab, ShiftMask, "\033[Z", 0, 0},
|
||||
{ XK_Return, Mod1Mask, "\033\r", 0, 0},
|
||||
{ XK_Return, XK_ANY_MOD, "\r", 0, 0},
|
||||
{ XK_Insert, ShiftMask, "\033[4l", -1, 0},
|
||||
{ XK_Insert, ShiftMask, "\033[2;2~", +1, 0},
|
||||
{ XK_Insert, ControlMask, "\033[L", -1, 0},
|
||||
{ XK_Insert, ControlMask, "\033[2;5~", +1, 0},
|
||||
{ XK_Insert, XK_ANY_MOD, "\033[4h", -1, 0},
|
||||
{ XK_Insert, XK_ANY_MOD, "\033[2~", +1, 0},
|
||||
{ XK_Delete, ControlMask, "\033[M", -1, 0},
|
||||
{ XK_Delete, ControlMask, "\033[3;5~", +1, 0},
|
||||
{ XK_Delete, ShiftMask, "\033[2K", -1, 0},
|
||||
{ XK_Delete, ShiftMask, "\033[3;2~", +1, 0},
|
||||
{ XK_Delete, XK_ANY_MOD, "\033[P", -1, 0},
|
||||
{ XK_Delete, XK_ANY_MOD, "\033[3~", +1, 0},
|
||||
{ XK_BackSpace, XK_NO_MOD, "\177", 0, 0},
|
||||
{ XK_BackSpace, Mod1Mask, "\033\177", 0, 0},
|
||||
{ XK_Home, ShiftMask, "\033[2J", 0, -1},
|
||||
{ XK_Home, ShiftMask, "\033[1;2H", 0, +1},
|
||||
{ XK_Home, XK_ANY_MOD, "\033[H", 0, -1},
|
||||
{ XK_Home, XK_ANY_MOD, "\033[1~", 0, +1},
|
||||
{ XK_End, ControlMask, "\033[J", -1, 0},
|
||||
{ XK_End, ControlMask, "\033[1;5F", +1, 0},
|
||||
{ XK_End, ShiftMask, "\033[K", -1, 0},
|
||||
{ XK_End, ShiftMask, "\033[1;2F", +1, 0},
|
||||
{ XK_End, XK_ANY_MOD, "\033[4~", 0, 0},
|
||||
{ XK_Prior, ControlMask, "\033[5;5~", 0, 0},
|
||||
{ XK_Prior, ShiftMask, "\033[5;2~", 0, 0},
|
||||
{ XK_Prior, XK_ANY_MOD, "\033[5~", 0, 0},
|
||||
{ XK_Next, ControlMask, "\033[6;5~", 0, 0},
|
||||
{ XK_Next, ShiftMask, "\033[6;2~", 0, 0},
|
||||
{ XK_Next, XK_ANY_MOD, "\033[6~", 0, 0},
|
||||
{ XK_F1, XK_NO_MOD, "\033OP" , 0, 0},
|
||||
{ XK_F1, /* F13 */ ShiftMask, "\033[1;2P", 0, 0},
|
||||
{ XK_F1, /* F25 */ ControlMask, "\033[1;5P", 0, 0},
|
||||
{ XK_F1, /* F37 */ Mod4Mask, "\033[1;6P", 0, 0},
|
||||
{ XK_F1, /* F49 */ Mod1Mask, "\033[1;3P", 0, 0},
|
||||
{ XK_F1, /* F61 */ Mod3Mask, "\033[1;4P", 0, 0},
|
||||
{ XK_F2, XK_NO_MOD, "\033OQ" , 0, 0},
|
||||
{ XK_F2, /* F14 */ ShiftMask, "\033[1;2Q", 0, 0},
|
||||
{ XK_F2, /* F26 */ ControlMask, "\033[1;5Q", 0, 0},
|
||||
{ XK_F2, /* F38 */ Mod4Mask, "\033[1;6Q", 0, 0},
|
||||
{ XK_F2, /* F50 */ Mod1Mask, "\033[1;3Q", 0, 0},
|
||||
{ XK_F2, /* F62 */ Mod3Mask, "\033[1;4Q", 0, 0},
|
||||
{ XK_F3, XK_NO_MOD, "\033OR" , 0, 0},
|
||||
{ XK_F3, /* F15 */ ShiftMask, "\033[1;2R", 0, 0},
|
||||
{ XK_F3, /* F27 */ ControlMask, "\033[1;5R", 0, 0},
|
||||
{ XK_F3, /* F39 */ Mod4Mask, "\033[1;6R", 0, 0},
|
||||
{ XK_F3, /* F51 */ Mod1Mask, "\033[1;3R", 0, 0},
|
||||
{ XK_F3, /* F63 */ Mod3Mask, "\033[1;4R", 0, 0},
|
||||
{ XK_F4, XK_NO_MOD, "\033OS" , 0, 0},
|
||||
{ XK_F4, /* F16 */ ShiftMask, "\033[1;2S", 0, 0},
|
||||
{ XK_F4, /* F28 */ ControlMask, "\033[1;5S", 0, 0},
|
||||
{ XK_F4, /* F40 */ Mod4Mask, "\033[1;6S", 0, 0},
|
||||
{ XK_F4, /* F52 */ Mod1Mask, "\033[1;3S", 0, 0},
|
||||
{ XK_F5, XK_NO_MOD, "\033[15~", 0, 0},
|
||||
{ XK_F5, /* F17 */ ShiftMask, "\033[15;2~", 0, 0},
|
||||
{ XK_F5, /* F29 */ ControlMask, "\033[15;5~", 0, 0},
|
||||
{ XK_F5, /* F41 */ Mod4Mask, "\033[15;6~", 0, 0},
|
||||
{ XK_F5, /* F53 */ Mod1Mask, "\033[15;3~", 0, 0},
|
||||
{ XK_F6, XK_NO_MOD, "\033[17~", 0, 0},
|
||||
{ XK_F6, /* F18 */ ShiftMask, "\033[17;2~", 0, 0},
|
||||
{ XK_F6, /* F30 */ ControlMask, "\033[17;5~", 0, 0},
|
||||
{ XK_F6, /* F42 */ Mod4Mask, "\033[17;6~", 0, 0},
|
||||
{ XK_F6, /* F54 */ Mod1Mask, "\033[17;3~", 0, 0},
|
||||
{ XK_F7, XK_NO_MOD, "\033[18~", 0, 0},
|
||||
{ XK_F7, /* F19 */ ShiftMask, "\033[18;2~", 0, 0},
|
||||
{ XK_F7, /* F31 */ ControlMask, "\033[18;5~", 0, 0},
|
||||
{ XK_F7, /* F43 */ Mod4Mask, "\033[18;6~", 0, 0},
|
||||
{ XK_F7, /* F55 */ Mod1Mask, "\033[18;3~", 0, 0},
|
||||
{ XK_F8, XK_NO_MOD, "\033[19~", 0, 0},
|
||||
{ XK_F8, /* F20 */ ShiftMask, "\033[19;2~", 0, 0},
|
||||
{ XK_F8, /* F32 */ ControlMask, "\033[19;5~", 0, 0},
|
||||
{ XK_F8, /* F44 */ Mod4Mask, "\033[19;6~", 0, 0},
|
||||
{ XK_F8, /* F56 */ Mod1Mask, "\033[19;3~", 0, 0},
|
||||
{ XK_F9, XK_NO_MOD, "\033[20~", 0, 0},
|
||||
{ XK_F9, /* F21 */ ShiftMask, "\033[20;2~", 0, 0},
|
||||
{ XK_F9, /* F33 */ ControlMask, "\033[20;5~", 0, 0},
|
||||
{ XK_F9, /* F45 */ Mod4Mask, "\033[20;6~", 0, 0},
|
||||
{ XK_F9, /* F57 */ Mod1Mask, "\033[20;3~", 0, 0},
|
||||
{ XK_F10, XK_NO_MOD, "\033[21~", 0, 0},
|
||||
{ XK_F10, /* F22 */ ShiftMask, "\033[21;2~", 0, 0},
|
||||
{ XK_F10, /* F34 */ ControlMask, "\033[21;5~", 0, 0},
|
||||
{ XK_F10, /* F46 */ Mod4Mask, "\033[21;6~", 0, 0},
|
||||
{ XK_F10, /* F58 */ Mod1Mask, "\033[21;3~", 0, 0},
|
||||
{ XK_F11, XK_NO_MOD, "\033[23~", 0, 0},
|
||||
{ XK_F11, /* F23 */ ShiftMask, "\033[23;2~", 0, 0},
|
||||
{ XK_F11, /* F35 */ ControlMask, "\033[23;5~", 0, 0},
|
||||
{ XK_F11, /* F47 */ Mod4Mask, "\033[23;6~", 0, 0},
|
||||
{ XK_F11, /* F59 */ Mod1Mask, "\033[23;3~", 0, 0},
|
||||
{ XK_F12, XK_NO_MOD, "\033[24~", 0, 0},
|
||||
{ XK_F12, /* F24 */ ShiftMask, "\033[24;2~", 0, 0},
|
||||
{ XK_F12, /* F36 */ ControlMask, "\033[24;5~", 0, 0},
|
||||
{ XK_F12, /* F48 */ Mod4Mask, "\033[24;6~", 0, 0},
|
||||
{ XK_F12, /* F60 */ Mod1Mask, "\033[24;3~", 0, 0},
|
||||
{ XK_F13, XK_NO_MOD, "\033[1;2P", 0, 0},
|
||||
{ XK_F14, XK_NO_MOD, "\033[1;2Q", 0, 0},
|
||||
{ XK_F15, XK_NO_MOD, "\033[1;2R", 0, 0},
|
||||
{ XK_F16, XK_NO_MOD, "\033[1;2S", 0, 0},
|
||||
{ XK_F17, XK_NO_MOD, "\033[15;2~", 0, 0},
|
||||
{ XK_F18, XK_NO_MOD, "\033[17;2~", 0, 0},
|
||||
{ XK_F19, XK_NO_MOD, "\033[18;2~", 0, 0},
|
||||
{ XK_F20, XK_NO_MOD, "\033[19;2~", 0, 0},
|
||||
{ XK_F21, XK_NO_MOD, "\033[20;2~", 0, 0},
|
||||
{ XK_F22, XK_NO_MOD, "\033[21;2~", 0, 0},
|
||||
{ XK_F23, XK_NO_MOD, "\033[23;2~", 0, 0},
|
||||
{ XK_F24, XK_NO_MOD, "\033[24;2~", 0, 0},
|
||||
{ XK_F25, XK_NO_MOD, "\033[1;5P", 0, 0},
|
||||
{ XK_F26, XK_NO_MOD, "\033[1;5Q", 0, 0},
|
||||
{ XK_F27, XK_NO_MOD, "\033[1;5R", 0, 0},
|
||||
{ XK_F28, XK_NO_MOD, "\033[1;5S", 0, 0},
|
||||
{ XK_F29, XK_NO_MOD, "\033[15;5~", 0, 0},
|
||||
{ XK_F30, XK_NO_MOD, "\033[17;5~", 0, 0},
|
||||
{ XK_F31, XK_NO_MOD, "\033[18;5~", 0, 0},
|
||||
{ XK_F32, XK_NO_MOD, "\033[19;5~", 0, 0},
|
||||
{ XK_F33, XK_NO_MOD, "\033[20;5~", 0, 0},
|
||||
{ XK_F34, XK_NO_MOD, "\033[21;5~", 0, 0},
|
||||
{ XK_F35, XK_NO_MOD, "\033[23;5~", 0, 0},
|
||||
};
|
||||
|
||||
/*
|
||||
* Selection types' masks.
|
||||
* Use the same masks as usual.
|
||||
* Button1Mask is always unset, to make masks match between ButtonPress.
|
||||
* ButtonRelease and MotionNotify.
|
||||
* If no match is found, regular selection is used.
|
||||
*/
|
||||
static uint selmasks[] = {
|
||||
[SEL_RECTANGULAR] = Mod1Mask,
|
||||
};
|
||||
|
||||
/*
|
||||
* Printable characters in ASCII, used to estimate the advance width
|
||||
* of single wide characters.
|
||||
*/
|
||||
static char ascii_printable[] =
|
||||
" !\"#$%&'()*+,-./0123456789:;<=>?"
|
||||
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
|
||||
"`abcdefghijklmnopqrstuvwxyz{|}~";
|
||||
@@ -0,0 +1,16 @@
|
||||
# Geminux st build configuration (HarfBuzz ligatures + Xft + Fontconfig + UTF-8)
|
||||
VERSION = 0.9.2-geminux
|
||||
|
||||
PREFIX = /usr
|
||||
MANPREFIX = $(PREFIX)/share/man
|
||||
|
||||
PKG_CONFIG ?= pkg-config
|
||||
|
||||
INCS = $(shell $(PKG_CONFIG) --cflags fontconfig freetype2 harfbuzz xft x11)
|
||||
LIBS = -lm -lrt -lutil $(shell $(PKG_CONFIG) --libs fontconfig freetype2 harfbuzz xft x11)
|
||||
|
||||
STCPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600
|
||||
STCFLAGS = $(INCS) $(STCPPFLAGS) $(CPPFLAGS) $(CFLAGS) -O2 -std=gnu99 -Wall
|
||||
STLDFLAGS = $(LIBS) $(LDFLAGS)
|
||||
|
||||
CC ?= cc
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <X11/Xft/Xft.h>
|
||||
#include <hb.h>
|
||||
#include <hb-ft.h>
|
||||
|
||||
#include "st.h"
|
||||
#include "hb.h"
|
||||
|
||||
#define FEATURE(c1,c2,c3,c4) { .tag = HB_TAG(c1,c2,c3,c4), .value = 1, .start = HB_FEATURE_GLOBAL_START, .end = HB_FEATURE_GLOBAL_END }
|
||||
|
||||
typedef struct {
|
||||
XftFont *match;
|
||||
hb_font_t *font;
|
||||
} HbFontMatch;
|
||||
|
||||
static int hbfontslen = 0;
|
||||
static HbFontMatch *hbfontcache = NULL;
|
||||
static hb_buffer_t *hbbuffer = NULL;
|
||||
|
||||
static hb_feature_t features[] = {
|
||||
FEATURE('l','i','g','a'),
|
||||
FEATURE('c','a','l','t'),
|
||||
FEATURE('c','l','i','g'),
|
||||
FEATURE('d','l','i','g'),
|
||||
};
|
||||
|
||||
void
|
||||
hbunloadfonts(void)
|
||||
{
|
||||
for (int i = 0; i < hbfontslen; i++) {
|
||||
hb_font_destroy(hbfontcache[i].font);
|
||||
XftUnlockFace(hbfontcache[i].match);
|
||||
}
|
||||
if (hbfontcache != NULL) {
|
||||
free(hbfontcache);
|
||||
hbfontcache = NULL;
|
||||
}
|
||||
hbfontslen = 0;
|
||||
}
|
||||
|
||||
static hb_font_t *
|
||||
hbfindfont(XftFont *match)
|
||||
{
|
||||
for (int i = 0; i < hbfontslen; i++) {
|
||||
if (hbfontcache[i].match == match)
|
||||
return hbfontcache[i].font;
|
||||
}
|
||||
|
||||
hbfontcache = xrealloc(hbfontcache, sizeof(HbFontMatch) * (hbfontslen + 1));
|
||||
FT_Face face = XftLockFace(match);
|
||||
hb_font_t *font = hb_ft_font_create(face, NULL);
|
||||
if (font == NULL)
|
||||
die("Failed to load HarfBuzz font.");
|
||||
|
||||
hbfontcache[hbfontslen].match = match;
|
||||
hbfontcache[hbfontslen].font = font;
|
||||
hbfontslen += 1;
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
static void
|
||||
hbtransformsegment(XftFont *xfont, const Glyph *string, hb_codepoint_t *codepoints, int start, int length)
|
||||
{
|
||||
hb_font_t *font = hbfindfont(xfont);
|
||||
if (font == NULL)
|
||||
return;
|
||||
|
||||
if (hbbuffer == NULL)
|
||||
hbbuffer = hb_buffer_create();
|
||||
hb_buffer_reset(hbbuffer);
|
||||
hb_buffer_set_direction(hbbuffer, HB_DIRECTION_LTR);
|
||||
hb_buffer_set_script(hbbuffer, HB_SCRIPT_LATIN);
|
||||
|
||||
for (int i = start; i < (start + length); i++) {
|
||||
Rune rune = string[i].u;
|
||||
if (string[i].mode & ATTR_WDUMMY)
|
||||
rune = 0x0020;
|
||||
hb_buffer_add_codepoints(hbbuffer, &rune, 1, 0, 1);
|
||||
}
|
||||
|
||||
hb_shape(font, hbbuffer, features, sizeof(features) / sizeof(hb_feature_t));
|
||||
|
||||
unsigned int glyph_count = 0;
|
||||
hb_glyph_info_t *info = hb_buffer_get_glyph_infos(hbbuffer, &glyph_count);
|
||||
|
||||
if ((int)glyph_count == length) {
|
||||
for (int i = 0; i < length; i++)
|
||||
codepoints[start + i] = info[i].codepoint;
|
||||
} else if (glyph_count > 0 && (int)glyph_count < length) {
|
||||
for (int i = 0; i < length; i++)
|
||||
codepoints[start + i] = 0;
|
||||
for (unsigned int g = 0; g < glyph_count; g++) {
|
||||
uint32_t c = info[g].cluster;
|
||||
if ((int)c < length)
|
||||
codepoints[start + c] = info[g].codepoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
hbtransform(XftGlyphFontSpec *specs, const Glyph *glyphs, size_t len, int x, int y)
|
||||
{
|
||||
int start = 0, length = 1, gstart = 0;
|
||||
hb_codepoint_t *codepoints = calloc(len, sizeof(hb_codepoint_t));
|
||||
if (!codepoints)
|
||||
return;
|
||||
|
||||
for (int idx = 1, specidx = 1; idx < (int)len; idx++) {
|
||||
if (glyphs[idx].mode & ATTR_WDUMMY) {
|
||||
length += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (specs[specidx].font != specs[start].font || ATTRCMP(glyphs[gstart], glyphs[idx])) {
|
||||
hbtransformsegment(specs[start].font, glyphs, codepoints, gstart, length);
|
||||
length = 1;
|
||||
start = specidx;
|
||||
gstart = idx;
|
||||
} else {
|
||||
length += 1;
|
||||
}
|
||||
|
||||
specidx++;
|
||||
}
|
||||
|
||||
hbtransformsegment(specs[start].font, glyphs, codepoints, gstart, length);
|
||||
|
||||
for (int i = 0, specidx = 0; i < (int)len; i++) {
|
||||
if (glyphs[i].mode & ATTR_WDUMMY)
|
||||
continue;
|
||||
if (codepoints[i] != 0 && codepoints[i] != specs[specidx].glyph)
|
||||
specs[specidx].glyph = codepoints[i];
|
||||
specidx++;
|
||||
}
|
||||
|
||||
free(codepoints);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#include <X11/Xft/Xft.h>
|
||||
#include <hb.h>
|
||||
#include <hb-ft.h>
|
||||
|
||||
void hbunloadfonts(void);
|
||||
void hbtransform(XftGlyphFontSpec *, const Glyph *, size_t, int, int);
|
||||
+177
@@ -0,0 +1,177 @@
|
||||
.TH ST 1 st\-VERSION
|
||||
.SH NAME
|
||||
st \- simple terminal
|
||||
.SH SYNOPSIS
|
||||
.B st
|
||||
.RB [ \-aiv ]
|
||||
.RB [ \-c
|
||||
.IR class ]
|
||||
.RB [ \-f
|
||||
.IR font ]
|
||||
.RB [ \-g
|
||||
.IR geometry ]
|
||||
.RB [ \-n
|
||||
.IR name ]
|
||||
.RB [ \-o
|
||||
.IR iofile ]
|
||||
.RB [ \-T
|
||||
.IR title ]
|
||||
.RB [ \-t
|
||||
.IR title ]
|
||||
.RB [ \-l
|
||||
.IR line ]
|
||||
.RB [ \-w
|
||||
.IR windowid ]
|
||||
.RB [[ \-e ]
|
||||
.IR command
|
||||
.RI [ arguments ...]]
|
||||
.PP
|
||||
.B st
|
||||
.RB [ \-aiv ]
|
||||
.RB [ \-c
|
||||
.IR class ]
|
||||
.RB [ \-f
|
||||
.IR font ]
|
||||
.RB [ \-g
|
||||
.IR geometry ]
|
||||
.RB [ \-n
|
||||
.IR name ]
|
||||
.RB [ \-o
|
||||
.IR iofile ]
|
||||
.RB [ \-T
|
||||
.IR title ]
|
||||
.RB [ \-t
|
||||
.IR title ]
|
||||
.RB [ \-w
|
||||
.IR windowid ]
|
||||
.RB \-l
|
||||
.IR line
|
||||
.RI [ stty_args ...]
|
||||
.SH DESCRIPTION
|
||||
.B st
|
||||
is a simple terminal emulator.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B \-a
|
||||
disable alternate screens in terminal
|
||||
.TP
|
||||
.BI \-c " class"
|
||||
defines the window class (default $TERM).
|
||||
.TP
|
||||
.BI \-f " font"
|
||||
defines the
|
||||
.I font
|
||||
to use when st is run.
|
||||
.TP
|
||||
.BI \-g " geometry"
|
||||
defines the X11 geometry string.
|
||||
The form is [=][<cols>{xX}<rows>][{+-}<xoffset>{+-}<yoffset>]. See
|
||||
.BR XParseGeometry (3)
|
||||
for further details.
|
||||
.TP
|
||||
.B \-i
|
||||
will fixate the position given with the -g option.
|
||||
.TP
|
||||
.BI \-n " name"
|
||||
defines the window instance name (default $TERM).
|
||||
.TP
|
||||
.BI \-o " iofile"
|
||||
writes all the I/O to
|
||||
.I iofile.
|
||||
This feature is useful when recording st sessions. A value of "-" means
|
||||
standard output.
|
||||
.TP
|
||||
.BI \-T " title"
|
||||
defines the window title (default 'st').
|
||||
.TP
|
||||
.BI \-t " title"
|
||||
defines the window title (default 'st').
|
||||
.TP
|
||||
.BI \-w " windowid"
|
||||
embeds st within the window identified by
|
||||
.I windowid
|
||||
.TP
|
||||
.BI \-l " line"
|
||||
use a tty
|
||||
.I line
|
||||
instead of a pseudo terminal.
|
||||
.I line
|
||||
should be a (pseudo-)serial device (e.g. /dev/ttyS0 on Linux for serial port
|
||||
0).
|
||||
When this flag is given
|
||||
remaining arguments are used as flags for
|
||||
.BR stty(1).
|
||||
By default st initializes the serial line to 8 bits, no parity, 1 stop bit
|
||||
and a 38400 baud rate. The speed is set by appending it as last argument
|
||||
(e.g. 'st -l /dev/ttyS0 115200'). Arguments before the last one are
|
||||
.BR stty(1)
|
||||
flags. If you want to set odd parity on 115200 baud use for example 'st -l
|
||||
/dev/ttyS0 parenb parodd 115200'. Set the number of bits by using for
|
||||
example 'st -l /dev/ttyS0 cs7 115200'. See
|
||||
.BR stty(1)
|
||||
for more arguments and cases.
|
||||
.TP
|
||||
.B \-v
|
||||
prints version information to stderr, then exits.
|
||||
.TP
|
||||
.BI \-e " command " [ " arguments " "... ]"
|
||||
st executes
|
||||
.I command
|
||||
instead of the shell. If this is used it
|
||||
.B must be the last option
|
||||
on the command line, as in xterm / rxvt.
|
||||
This option is only intended for compatibility,
|
||||
and all the remaining arguments are used as a command
|
||||
even without it.
|
||||
.SH SHORTCUTS
|
||||
.TP
|
||||
.B Break
|
||||
Send a break in the serial line.
|
||||
Break key is obtained in PC keyboards
|
||||
pressing at the same time control and pause.
|
||||
.TP
|
||||
.B Ctrl-Print Screen
|
||||
Toggle if st should print to the
|
||||
.I iofile.
|
||||
.TP
|
||||
.B Shift-Print Screen
|
||||
Print the full screen to the
|
||||
.I iofile.
|
||||
.TP
|
||||
.B Print Screen
|
||||
Print the selection to the
|
||||
.I iofile.
|
||||
.TP
|
||||
.B Ctrl-Shift-Page Up
|
||||
Increase font size.
|
||||
.TP
|
||||
.B Ctrl-Shift-Page Down
|
||||
Decrease font size.
|
||||
.TP
|
||||
.B Ctrl-Shift-Home
|
||||
Reset to default font size.
|
||||
.TP
|
||||
.B Ctrl-Shift-y
|
||||
Paste from primary selection (middle mouse button).
|
||||
.TP
|
||||
.B Ctrl-Shift-c
|
||||
Copy the selected text to the clipboard selection.
|
||||
.TP
|
||||
.B Ctrl-Shift-v
|
||||
Paste from the clipboard selection.
|
||||
.SH CUSTOMIZATION
|
||||
.B st
|
||||
can be customized by creating a custom config.h and (re)compiling the source
|
||||
code. This keeps it fast, secure and simple.
|
||||
.SH AUTHORS
|
||||
See the LICENSE file for the authors.
|
||||
.SH LICENSE
|
||||
See the LICENSE file for the terms of redistribution.
|
||||
.SH SEE ALSO
|
||||
.BR tabbed (1),
|
||||
.BR utmp (1),
|
||||
.BR stty (1),
|
||||
.BR scroll (1)
|
||||
.SH BUGS
|
||||
See the TODO file in the distribution.
|
||||
|
||||
+2736
File diff suppressed because it is too large.
Load diff
+128
@@ -0,0 +1,128 @@
|
||||
/* See LICENSE for license details. */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* macros */
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#define MAX(a, b) ((a) < (b) ? (b) : (a))
|
||||
#define LEN(a) (sizeof(a) / sizeof(a)[0])
|
||||
#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
|
||||
#define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d))
|
||||
#define DEFAULT(a, b) (a) = (a) ? (a) : (b)
|
||||
#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
|
||||
#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || \
|
||||
(a).bg != (b).bg)
|
||||
#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \
|
||||
(t1.tv_nsec-t2.tv_nsec)/1E6)
|
||||
#define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
|
||||
|
||||
#define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
|
||||
#define IS_TRUECOL(x) (1 << 24 & (x))
|
||||
|
||||
enum glyph_attribute {
|
||||
ATTR_NULL = 0,
|
||||
ATTR_BOLD = 1 << 0,
|
||||
ATTR_FAINT = 1 << 1,
|
||||
ATTR_ITALIC = 1 << 2,
|
||||
ATTR_UNDERLINE = 1 << 3,
|
||||
ATTR_BLINK = 1 << 4,
|
||||
ATTR_REVERSE = 1 << 5,
|
||||
ATTR_INVISIBLE = 1 << 6,
|
||||
ATTR_STRUCK = 1 << 7,
|
||||
ATTR_WRAP = 1 << 8,
|
||||
ATTR_WIDE = 1 << 9,
|
||||
ATTR_WDUMMY = 1 << 10,
|
||||
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
|
||||
};
|
||||
|
||||
enum selection_mode {
|
||||
SEL_IDLE = 0,
|
||||
SEL_EMPTY = 1,
|
||||
SEL_READY = 2
|
||||
};
|
||||
|
||||
enum selection_type {
|
||||
SEL_REGULAR = 1,
|
||||
SEL_RECTANGULAR = 2
|
||||
};
|
||||
|
||||
enum selection_snap {
|
||||
SNAP_WORD = 1,
|
||||
SNAP_LINE = 2
|
||||
};
|
||||
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned long ulong;
|
||||
typedef unsigned short ushort;
|
||||
|
||||
typedef uint_least32_t Rune;
|
||||
|
||||
#define Glyph Glyph_
|
||||
typedef struct {
|
||||
Rune u; /* character code */
|
||||
ushort mode; /* attribute flags */
|
||||
uint32_t fg; /* foreground */
|
||||
uint32_t bg; /* background */
|
||||
} Glyph;
|
||||
|
||||
typedef Glyph *Line;
|
||||
|
||||
typedef union {
|
||||
int i;
|
||||
uint ui;
|
||||
float f;
|
||||
const void *v;
|
||||
const char *s;
|
||||
} Arg;
|
||||
|
||||
void die(const char *, ...);
|
||||
void redraw(void);
|
||||
void draw(void);
|
||||
|
||||
void kscrolldown(const Arg *);
|
||||
void kscrollup(const Arg *);
|
||||
void printscreen(const Arg *);
|
||||
void printsel(const Arg *);
|
||||
void sendbreak(const Arg *);
|
||||
void toggleprinter(const Arg *);
|
||||
void externalpipe(const Arg *);
|
||||
|
||||
int tattrset(int);
|
||||
void tnew(int, int);
|
||||
void tresize(int, int);
|
||||
void tsetdirtattr(int);
|
||||
void ttyhangup(void);
|
||||
int ttynew(char *, char *, char *, char **);
|
||||
size_t ttyread(void);
|
||||
void ttyresize(int, int);
|
||||
void ttywrite(const char *, size_t, int);
|
||||
|
||||
void resettitle(void);
|
||||
|
||||
void selclear(void);
|
||||
void selinit(void);
|
||||
void selstart(int, int, int);
|
||||
void selextend(int, int, int, int);
|
||||
int selected(int, int);
|
||||
char *getsel(void);
|
||||
|
||||
size_t utf8encode(Rune, char *);
|
||||
|
||||
void *xmalloc(size_t);
|
||||
void *xrealloc(void *, size_t);
|
||||
char *xstrdup(char *);
|
||||
|
||||
/* config.h globals */
|
||||
extern char *utmp;
|
||||
extern char *scroll;
|
||||
extern char *stty_args;
|
||||
extern char *vtiden;
|
||||
extern wchar_t *worddelimiters;
|
||||
extern int allowaltscreen;
|
||||
extern int allowwindowops;
|
||||
extern char *termname;
|
||||
extern unsigned int tabspaces;
|
||||
extern unsigned int defaultfg;
|
||||
extern unsigned int defaultbg;
|
||||
+239
@@ -0,0 +1,239 @@
|
||||
st-mono| simpleterm monocolor,
|
||||
acsc=+C\,D-A.B0E``aaffgghFiGjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
|
||||
am,
|
||||
bce,
|
||||
bel=^G,
|
||||
blink=\E[5m,
|
||||
bold=\E[1m,
|
||||
cbt=\E[Z,
|
||||
cvvis=\E[?25h,
|
||||
civis=\E[?25l,
|
||||
clear=\E[H\E[2J,
|
||||
cnorm=\E[?12l\E[?25h,
|
||||
colors#2,
|
||||
cols#80,
|
||||
cr=^M,
|
||||
csr=\E[%i%p1%d;%p2%dr,
|
||||
cub=\E[%p1%dD,
|
||||
cub1=^H,
|
||||
cud1=^J,
|
||||
cud=\E[%p1%dB,
|
||||
cuf1=\E[C,
|
||||
cuf=\E[%p1%dC,
|
||||
cup=\E[%i%p1%d;%p2%dH,
|
||||
cuu1=\E[A,
|
||||
cuu=\E[%p1%dA,
|
||||
dch=\E[%p1%dP,
|
||||
dch1=\E[P,
|
||||
dim=\E[2m,
|
||||
dl=\E[%p1%dM,
|
||||
dl1=\E[M,
|
||||
ech=\E[%p1%dX,
|
||||
ed=\E[J,
|
||||
el=\E[K,
|
||||
el1=\E[1K,
|
||||
enacs=\E)0,
|
||||
flash=\E[?5h$<80/>\E[?5l,
|
||||
fsl=^G,
|
||||
home=\E[H,
|
||||
hpa=\E[%i%p1%dG,
|
||||
hs,
|
||||
ht=^I,
|
||||
hts=\EH,
|
||||
ich=\E[%p1%d@,
|
||||
il1=\E[L,
|
||||
il=\E[%p1%dL,
|
||||
ind=^J,
|
||||
indn=\E[%p1%dS,
|
||||
invis=\E[8m,
|
||||
is2=\E[4l\E>\E[?1034l,
|
||||
it#8,
|
||||
kel=\E[1;2F,
|
||||
ked=\E[1;5F,
|
||||
ka1=\E[1~,
|
||||
ka3=\E[5~,
|
||||
kc1=\E[4~,
|
||||
kc3=\E[6~,
|
||||
kbs=\177,
|
||||
kcbt=\E[Z,
|
||||
kb2=\EOu,
|
||||
kcub1=\EOD,
|
||||
kcud1=\EOB,
|
||||
kcuf1=\EOC,
|
||||
kcuu1=\EOA,
|
||||
kDC=\E[3;2~,
|
||||
kent=\EOM,
|
||||
kEND=\E[1;2F,
|
||||
kIC=\E[2;2~,
|
||||
kNXT=\E[6;2~,
|
||||
kPRV=\E[5;2~,
|
||||
kHOM=\E[1;2H,
|
||||
kLFT=\E[1;2D,
|
||||
kRIT=\E[1;2C,
|
||||
kind=\E[1;2B,
|
||||
kri=\E[1;2A,
|
||||
kclr=\E[3;5~,
|
||||
kdl1=\E[3;2~,
|
||||
kdch1=\E[3~,
|
||||
kich1=\E[2~,
|
||||
kend=\E[4~,
|
||||
kf1=\EOP,
|
||||
kf2=\EOQ,
|
||||
kf3=\EOR,
|
||||
kf4=\EOS,
|
||||
kf5=\E[15~,
|
||||
kf6=\E[17~,
|
||||
kf7=\E[18~,
|
||||
kf8=\E[19~,
|
||||
kf9=\E[20~,
|
||||
kf10=\E[21~,
|
||||
kf11=\E[23~,
|
||||
kf12=\E[24~,
|
||||
kf13=\E[1;2P,
|
||||
kf14=\E[1;2Q,
|
||||
kf15=\E[1;2R,
|
||||
kf16=\E[1;2S,
|
||||
kf17=\E[15;2~,
|
||||
kf18=\E[17;2~,
|
||||
kf19=\E[18;2~,
|
||||
kf20=\E[19;2~,
|
||||
kf21=\E[20;2~,
|
||||
kf22=\E[21;2~,
|
||||
kf23=\E[23;2~,
|
||||
kf24=\E[24;2~,
|
||||
kf25=\E[1;5P,
|
||||
kf26=\E[1;5Q,
|
||||
kf27=\E[1;5R,
|
||||
kf28=\E[1;5S,
|
||||
kf29=\E[15;5~,
|
||||
kf30=\E[17;5~,
|
||||
kf31=\E[18;5~,
|
||||
kf32=\E[19;5~,
|
||||
kf33=\E[20;5~,
|
||||
kf34=\E[21;5~,
|
||||
kf35=\E[23;5~,
|
||||
kf36=\E[24;5~,
|
||||
kf37=\E[1;6P,
|
||||
kf38=\E[1;6Q,
|
||||
kf39=\E[1;6R,
|
||||
kf40=\E[1;6S,
|
||||
kf41=\E[15;6~,
|
||||
kf42=\E[17;6~,
|
||||
kf43=\E[18;6~,
|
||||
kf44=\E[19;6~,
|
||||
kf45=\E[20;6~,
|
||||
kf46=\E[21;6~,
|
||||
kf47=\E[23;6~,
|
||||
kf48=\E[24;6~,
|
||||
kf49=\E[1;3P,
|
||||
kf50=\E[1;3Q,
|
||||
kf51=\E[1;3R,
|
||||
kf52=\E[1;3S,
|
||||
kf53=\E[15;3~,
|
||||
kf54=\E[17;3~,
|
||||
kf55=\E[18;3~,
|
||||
kf56=\E[19;3~,
|
||||
kf57=\E[20;3~,
|
||||
kf58=\E[21;3~,
|
||||
kf59=\E[23;3~,
|
||||
kf60=\E[24;3~,
|
||||
kf61=\E[1;4P,
|
||||
kf62=\E[1;4Q,
|
||||
kf63=\E[1;4R,
|
||||
khome=\E[1~,
|
||||
kil1=\E[2;5~,
|
||||
krmir=\E[2;2~,
|
||||
knp=\E[6~,
|
||||
kmous=\E[M,
|
||||
kpp=\E[5~,
|
||||
lines#24,
|
||||
mir,
|
||||
msgr,
|
||||
npc,
|
||||
op=\E[39;49m,
|
||||
pairs#64,
|
||||
mc0=\E[i,
|
||||
mc4=\E[4i,
|
||||
mc5=\E[5i,
|
||||
rc=\E8,
|
||||
rev=\E[7m,
|
||||
ri=\EM,
|
||||
rin=\E[%p1%dT,
|
||||
ritm=\E[23m,
|
||||
rmacs=\E(B,
|
||||
rmcup=\E[?1049l,
|
||||
rmir=\E[4l,
|
||||
rmkx=\E[?1l\E>,
|
||||
rmso=\E[27m,
|
||||
rmul=\E[24m,
|
||||
rs1=\Ec,
|
||||
rs2=\E[4l\E>\E[?1034l,
|
||||
sc=\E7,
|
||||
sitm=\E[3m,
|
||||
sgr0=\E[0m,
|
||||
smacs=\E(0,
|
||||
smcup=\E[?1049h,
|
||||
smir=\E[4h,
|
||||
smkx=\E[?1h\E=,
|
||||
smso=\E[7m,
|
||||
smul=\E[4m,
|
||||
tbc=\E[3g,
|
||||
tsl=\E]0;,
|
||||
xenl,
|
||||
vpa=\E[%i%p1%dd,
|
||||
# XTerm extensions
|
||||
rmxx=\E[29m,
|
||||
smxx=\E[9m,
|
||||
# disabled rep for now: causes some issues with older ncurses versions.
|
||||
# rep=%p1%c\E[%p2%{1}%-%db,
|
||||
# tmux extensions, see TERMINFO EXTENSIONS in tmux(1)
|
||||
Tc,
|
||||
Ms=\E]52;%p1%s;%p2%s\007,
|
||||
Se=\E[2 q,
|
||||
Ss=\E[%p1%d q,
|
||||
|
||||
st| simpleterm,
|
||||
use=st-mono,
|
||||
colors#8,
|
||||
setab=\E[4%p1%dm,
|
||||
setaf=\E[3%p1%dm,
|
||||
setb=\E[4%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,
|
||||
setf=\E[3%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,
|
||||
sgr=%?%p9%t\E(0%e\E(B%;\E[0%?%p6%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m,
|
||||
|
||||
st-256color| simpleterm with 256 colors,
|
||||
use=st,
|
||||
ccc,
|
||||
colors#256,
|
||||
oc=\E]104\007,
|
||||
pairs#32767,
|
||||
# Nicked from xterm-256color
|
||||
initc=\E]4;%p1%d;rgb\:%p2%{255}%*%{1000}%/%2.2X/%p3%{255}%*%{1000}%/%2.2X/%p4%{255}%*%{1000}%/%2.2X\E\\,
|
||||
setab=\E[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m,
|
||||
setaf=\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m,
|
||||
|
||||
st-meta| simpleterm with meta key,
|
||||
use=st,
|
||||
km,
|
||||
rmm=\E[?1034l,
|
||||
smm=\E[?1034h,
|
||||
rs2=\E[4l\E>\E[?1034h,
|
||||
is2=\E[4l\E>\E[?1034h,
|
||||
|
||||
st-meta-256color| simpleterm with meta key and 256 colors,
|
||||
use=st-256color,
|
||||
km,
|
||||
rmm=\E[?1034l,
|
||||
smm=\E[?1034h,
|
||||
rs2=\E[4l\E>\E[?1034h,
|
||||
is2=\E[4l\E>\E[?1034h,
|
||||
|
||||
st-bs| simpleterm with backspace as backspace,
|
||||
use=st,
|
||||
kbs=\010,
|
||||
kdch1=\177,
|
||||
|
||||
st-bs-256color| simpleterm with backspace as backspace and 256colors,
|
||||
use=st-256color,
|
||||
kbs=\010,
|
||||
kdch1=\177,
|
||||
@@ -0,0 +1,39 @@
|
||||
/* See LICENSE for license details. */
|
||||
|
||||
enum win_mode {
|
||||
MODE_VISIBLE = 1 << 0,
|
||||
MODE_FOCUSED = 1 << 1,
|
||||
MODE_APPKEYPAD = 1 << 2,
|
||||
MODE_MOUSEBTN = 1 << 3,
|
||||
MODE_MOUSEMOTION = 1 << 4,
|
||||
MODE_REVERSE = 1 << 5,
|
||||
MODE_KBDLOCK = 1 << 6,
|
||||
MODE_HIDE = 1 << 7,
|
||||
MODE_APPCURSOR = 1 << 8,
|
||||
MODE_MOUSESGR = 1 << 9,
|
||||
MODE_8BIT = 1 << 10,
|
||||
MODE_BLINK = 1 << 11,
|
||||
MODE_FBLINK = 1 << 12,
|
||||
MODE_FOCUS = 1 << 13,
|
||||
MODE_MOUSEX10 = 1 << 14,
|
||||
MODE_MOUSEMANY = 1 << 15,
|
||||
MODE_BRCKTPASTE = 1 << 16,
|
||||
MODE_NUMLOCK = 1 << 17,
|
||||
MODE_MOUSE = MODE_MOUSEBTN|MODE_MOUSEMOTION|MODE_MOUSEX10\
|
||||
|MODE_MOUSEMANY,
|
||||
};
|
||||
|
||||
void xbell(void);
|
||||
void xclipcopy(void);
|
||||
void xdrawcursor(int, int, Glyph, int, int, Glyph);
|
||||
void xdrawline(Line, int, int, int);
|
||||
void xfinishdraw(void);
|
||||
void xloadcols(void);
|
||||
int xsetcolorname(int, const char *);
|
||||
void xsettitle(char *);
|
||||
int xsetcursor(int);
|
||||
void xsetmode(int, unsigned int);
|
||||
void xsetpointermotion(int);
|
||||
void xsetsel(char *);
|
||||
int xstartdraw(void);
|
||||
void xximspot(int, int);
|
||||
+2300
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user