changes to custom layout, modify host, fsignals
This commit is contained in:
parent
277d8005c2
commit
730abe4ccc
|
@ -50,6 +50,9 @@
|
|||
#define RUN "dmenu_run -l 0 -p 'Run:'" /* Run launcher */
|
||||
#define RUN_ALT "speedwm-applist" /* Alternative run launcher */
|
||||
#define RUN_DESKTOP "j4-dmenu-desktop --term=st --dmenu='dmenu -l 20 -p Open'"
|
||||
|
||||
/* Custom layout */
|
||||
#define CUSTOM_HISTFILE ".config/speedwm-de/history" /* History file for the custom layout */
|
||||
#define RUN_CUSTOM_LAYOUT "dmenu -i -l 10 -p '>' <" /* Run launcher to use for the custom layout */
|
||||
|
||||
/* Screenshot actions */
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* Once you're done with your edits, run 'make clean install'. */
|
||||
static Signal signals[] = {
|
||||
/* signum function argument */
|
||||
{ 15, set_custom, {.v = &layouts[13]} },
|
||||
{ 15, set_s_layout, {.v = &layouts[13]} },
|
||||
{ 16, cyclelayout, {.i = +1 } },
|
||||
{ 17, cyclelayout, {.i = -1 } },
|
||||
{ 18, setmfact, {.f = +0.05} },
|
||||
|
@ -58,9 +58,6 @@ static Signal signals[] = {
|
|||
#if USEXRESOURCES
|
||||
{ 65, reloadcolors, {0} },
|
||||
#endif
|
||||
#if LAYOUT_CUSTOM
|
||||
{ 66, set_custom, {.v = &layouts[13]} },
|
||||
#endif
|
||||
#if LAYOUT_TILE
|
||||
{ 1, setlayout, {.v = &layouts[0]} }, /* Tiling layout */
|
||||
#endif
|
||||
|
|
2
host.mk
2
host.mk
|
@ -15,7 +15,7 @@ HTMLDIR = "/home/anon/Projects/page"
|
|||
FREETYPELIBS = -lfontconfig -lXft
|
||||
FREETYPEINC = /usr/include/freetype2
|
||||
CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Wno-unused-variable -Wno-unused-result -Wno-unused-function -Ofast -march=native ${INCS} ${CPPFLAGS}
|
||||
LDFLAGS = ${LIBS}
|
||||
LDFLAGS = ${LIBS} -g
|
||||
|
||||
# OpenBSD support
|
||||
# If you use OpenBSD, uncomment these lines. (remove the # at the start of the line below)
|
||||
|
|
117
layouts.c
117
layouts.c
|
@ -766,12 +766,16 @@ deck(Monitor *m)
|
|||
enum node_type_t
|
||||
{
|
||||
ND_NULL,
|
||||
|
||||
/* Containers */
|
||||
ND_MONOCLE,
|
||||
ND_HORIZONTAL_LR,
|
||||
ND_HORIZONTAL_RL,
|
||||
ND_VERTICAL_UD,
|
||||
ND_VERTICAL_DU,
|
||||
ND_VOID,
|
||||
|
||||
/* Elements */
|
||||
ND_CLIENT,
|
||||
ND_CLIENT_NUM,
|
||||
ND_CLIENT_NTH,
|
||||
|
@ -803,7 +807,7 @@ struct client_ref_t
|
|||
struct client_ref_t *next;
|
||||
};
|
||||
|
||||
static node_t *custom_scheme;
|
||||
static node_t *s_layout_scheme;
|
||||
|
||||
node_t* alloc_node(enum node_type_t type)
|
||||
{
|
||||
|
@ -942,7 +946,7 @@ s_recur_analyze(struct client_ref_t **clients, node_t *node)
|
|||
struct client_ref_t *c = *clients;
|
||||
unsigned i = 0;
|
||||
|
||||
// A single client, just assign a client.
|
||||
/* a single client, just assign a client. */
|
||||
if (node->type == ND_CLIENT) {
|
||||
struct s_recur_analyze_ret ret;
|
||||
ret.tail = ret.head = clone_node(node);
|
||||
|
@ -951,7 +955,7 @@ s_recur_analyze(struct client_ref_t **clients, node_t *node)
|
|||
return ret;
|
||||
}
|
||||
|
||||
// An empty slot.
|
||||
/* An empty slot. */
|
||||
if (node->type == ND_CLIENT_EMPTY) {
|
||||
struct s_recur_analyze_ret ret;
|
||||
ret.tail = ret.head = clone_node(node);
|
||||
|
@ -960,7 +964,7 @@ s_recur_analyze(struct client_ref_t **clients, node_t *node)
|
|||
return ret;
|
||||
}
|
||||
|
||||
// Pick n'th client from the list top.
|
||||
/* pick 'n' client from the list top. */
|
||||
if (node->type == ND_CLIENT_NTH) {
|
||||
struct client_ref_t *prev = NULL;
|
||||
struct s_recur_analyze_ret ret;
|
||||
|
@ -988,17 +992,12 @@ s_recur_analyze(struct client_ref_t **clients, node_t *node)
|
|||
}
|
||||
|
||||
if (node->type == ND_CLIENT_CLASS) {
|
||||
//struct client_ref_t *prev = NULL;
|
||||
struct s_recur_analyze_ret ret;
|
||||
|
||||
for ( c = *clients; c != NULL; c = c->next) {
|
||||
// TODO get class and compare to the pattern.
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Fixed number of clients.
|
||||
/* Fixed number of clients. */
|
||||
if (node->type == ND_CLIENT_NUM) {
|
||||
struct s_recur_analyze_ret ret;
|
||||
node_t head, *p = &head;
|
||||
|
@ -1018,7 +1017,7 @@ s_recur_analyze(struct client_ref_t **clients, node_t *node)
|
|||
return ret;
|
||||
}
|
||||
|
||||
// All leftover client.
|
||||
/* All leftover client. */
|
||||
if (node->type == ND_REST) {
|
||||
struct s_recur_analyze_ret ret;
|
||||
node_t head, *p = &head;
|
||||
|
@ -1042,7 +1041,7 @@ s_recur_analyze(struct client_ref_t **clients, node_t *node)
|
|||
return ret;
|
||||
}
|
||||
|
||||
// In case the element is a container
|
||||
/* In case the element is a container */
|
||||
if (is_nested(node)) {
|
||||
struct s_recur_analyze_ret ret;
|
||||
ret.head = clone_node(node);
|
||||
|
@ -1057,7 +1056,7 @@ s_recur_analyze(struct client_ref_t **clients, node_t *node)
|
|||
|
||||
node_t *n = NULL;
|
||||
|
||||
// For reversed containers the order must be reversed
|
||||
/* For reversed containers the order must be reversed */
|
||||
if (node->type == ND_HORIZONTAL_RL || node->type == ND_VERTICAL_DU) {
|
||||
n = reverse_node(node->branch);
|
||||
} else {
|
||||
|
@ -1068,7 +1067,7 @@ s_recur_analyze(struct client_ref_t **clients, node_t *node)
|
|||
{
|
||||
x = s_recur_analyze(clients, n);
|
||||
|
||||
// Attach the received tree to the tail of the previous element
|
||||
/* Attach the received tree to the tail of the previous element */
|
||||
if (x.head != NULL) {
|
||||
tail->next = x.head;
|
||||
tail = x.tail;
|
||||
|
@ -1183,17 +1182,17 @@ void s_recur_resize(node_t *node, struct frame_t frame)
|
|||
}
|
||||
}
|
||||
|
||||
// Main layout function.
|
||||
/* Main layout function. */
|
||||
void custom(Monitor *m)
|
||||
{
|
||||
// Need to clone the client stack, as we might need to pull items from it.
|
||||
/* Need to clone the client stack, as we might need to pull items from it. */
|
||||
struct client_ref_t *clients = copy_clients(m->clients),
|
||||
*clients_root = clients;
|
||||
|
||||
if (custom_scheme == NULL)
|
||||
if (s_layout_scheme == NULL)
|
||||
return;
|
||||
|
||||
struct s_recur_analyze_ret ret = s_recur_analyze(&clients, custom_scheme);
|
||||
struct s_recur_analyze_ret ret = s_recur_analyze(&clients, s_layout_scheme);
|
||||
|
||||
struct frame_t frame;
|
||||
frame.x = m->wx;
|
||||
|
@ -1203,12 +1202,12 @@ void custom(Monitor *m)
|
|||
|
||||
s_recur_resize(ret.head, frame);
|
||||
|
||||
// Free the resources we allocated.
|
||||
/* Free the resources we allocated. */
|
||||
free_clients(clients_root);
|
||||
free_node(ret.head);
|
||||
}
|
||||
|
||||
// Tokenize string
|
||||
/* tokenize string */
|
||||
typedef struct string_token_t string_token_t;
|
||||
struct string_token_t {
|
||||
char token[32];
|
||||
|
@ -1253,7 +1252,7 @@ struct string_token_t* tokenize_string(char *str)
|
|||
|
||||
for (unsigned i = 0;; i ++) {
|
||||
switch (str[i]) {
|
||||
// End of line
|
||||
/* end of line */
|
||||
case '\0':
|
||||
if (word_start != UINT_MAX) {
|
||||
node->next = (struct string_token_t*) malloc(sizeof(struct string_token_t));
|
||||
|
@ -1266,16 +1265,15 @@ struct string_token_t* tokenize_string(char *str)
|
|||
}
|
||||
return head.next;
|
||||
|
||||
// Comment
|
||||
/* comment */
|
||||
case ';':
|
||||
return head.next;
|
||||
|
||||
// Beginning of a string
|
||||
/* beginning of a string */
|
||||
case '"':
|
||||
node->next = parse_string(str, &i);
|
||||
if (node->next) node = node->next;
|
||||
|
||||
// Space or paren
|
||||
case ' ':
|
||||
case '\t':
|
||||
case '(':
|
||||
|
@ -1307,7 +1305,7 @@ struct string_token_t* tokenize_string(char *str)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
// Parse s-expression to node_t structure
|
||||
/* Parse s-expression to node_t structure */
|
||||
node_t* parse_sexp(string_token_t **token)
|
||||
{
|
||||
node_t *head = NULL;
|
||||
|
@ -1336,8 +1334,8 @@ node_t* parse_sexp(string_token_t **token)
|
|||
continue;
|
||||
}
|
||||
|
||||
// ==== Client slots
|
||||
// Single client
|
||||
/* client slots
|
||||
* single client */
|
||||
if (strcmp(t->token, "c") == 0 || strcmp(t->token, "client") == 0) {
|
||||
if (head == NULL) {
|
||||
head = alloc_node(ND_CLIENT);
|
||||
|
@ -1349,7 +1347,7 @@ node_t* parse_sexp(string_token_t **token)
|
|||
continue;
|
||||
}
|
||||
|
||||
// Empty viewport
|
||||
/* Empty viewport */
|
||||
if (strcmp(t->token, "e") == 0 || strcmp(t->token, "empty") == 0) {
|
||||
if (head == NULL) {
|
||||
head = alloc_node(ND_CLIENT_EMPTY);
|
||||
|
@ -1361,7 +1359,7 @@ node_t* parse_sexp(string_token_t **token)
|
|||
continue;
|
||||
}
|
||||
|
||||
// The rest of the clients
|
||||
/* the rest of the clients */
|
||||
if (strcmp(t->token, "...") == 0 || strcmp(t->token, "rest") == 0) {
|
||||
if (head == NULL) {
|
||||
head = alloc_node(ND_REST);
|
||||
|
@ -1373,7 +1371,7 @@ node_t* parse_sexp(string_token_t **token)
|
|||
continue;
|
||||
}
|
||||
|
||||
// Choose the client by class
|
||||
/* choose the client by class */
|
||||
if (strcmp(t->token, "class") == 0) {
|
||||
if (head == NULL) {
|
||||
head = alloc_node(ND_CLIENT_CLASS);
|
||||
|
@ -1393,7 +1391,7 @@ node_t* parse_sexp(string_token_t **token)
|
|||
continue;
|
||||
}
|
||||
|
||||
// N'th client
|
||||
/* 'n' client */
|
||||
unsigned long n = 0;
|
||||
char *endp = NULL;
|
||||
n = strtoul(t->token, &endp, 10);
|
||||
|
@ -1410,7 +1408,7 @@ node_t* parse_sexp(string_token_t **token)
|
|||
continue;
|
||||
}
|
||||
|
||||
// Max n clients
|
||||
/* max number of clients */
|
||||
if (strcmp(t->token, "max") == 0) {
|
||||
if (head == NULL) {
|
||||
head = alloc_node(ND_CLIENT_NUM);
|
||||
|
@ -1424,8 +1422,8 @@ node_t* parse_sexp(string_token_t **token)
|
|||
continue;
|
||||
}
|
||||
|
||||
// ==== Parameters
|
||||
// weight
|
||||
/* parameters
|
||||
* weight */
|
||||
if ((strcmp(t->token, "w:") == 0 || strcmp(t->token, ":w") == 0
|
||||
|| strcmp(t->token, "weight:") == 0
|
||||
|| strcmp(t->token, ":weight") == 0) && head != NULL) {
|
||||
|
@ -1438,10 +1436,10 @@ node_t* parse_sexp(string_token_t **token)
|
|||
continue;
|
||||
}
|
||||
|
||||
// margin
|
||||
/* margin */
|
||||
if (((strcmp(t->token, "m:") == 0) || strcmp(t->token, ":m") == 0
|
||||
|| strcmp(t->token, "margin:") == 0
|
||||
|| strcmp(t->token, ":margin")) && head != NULL) {
|
||||
|| strcmp(t->token, ":margin") == 0) && head != NULL) {
|
||||
t = t->next;
|
||||
|
||||
if (t != NULL) {
|
||||
|
@ -1451,10 +1449,10 @@ node_t* parse_sexp(string_token_t **token)
|
|||
continue;
|
||||
}
|
||||
|
||||
// floating geometry
|
||||
/* floating geometry */
|
||||
if ((strcmp(t->token, "f:") == 0 || strcmp(t->token, ":f") == 0
|
||||
|| strcmp(t->token, "float:") == 0
|
||||
|| strcmp(t->token, ":float")) && head != NULL) {
|
||||
|| strcmp(t->token, ":float") == 0) && head != NULL) {
|
||||
head->f = 1;
|
||||
t = t->next;
|
||||
|
||||
|
@ -1477,7 +1475,7 @@ node_t* parse_sexp(string_token_t **token)
|
|||
continue;
|
||||
}
|
||||
|
||||
// ==== Containers
|
||||
/* containers */
|
||||
if ((strcmp(t->token, "h") == 0 || strcmp(t->token, "horizontal") == 0) && head == NULL)
|
||||
head = alloc_node(ND_HORIZONTAL_LR);
|
||||
|
||||
|
@ -1503,53 +1501,52 @@ node_t* parse_sexp(string_token_t **token)
|
|||
return head;
|
||||
}
|
||||
|
||||
#define CUSTOM_HISTORY ".config/speedwm-de/custom_history"
|
||||
void
|
||||
set_custom(const Arg *arg)
|
||||
void set_s_layout(const Arg *arg)
|
||||
{
|
||||
FILE *pp, *hf;
|
||||
|
||||
char pathbuf[1024];
|
||||
char *home = getenv("HOME");
|
||||
if (home != NULL) {
|
||||
snprintf(pathbuf, 1023, "%s/" CUSTOM_HISTORY, home);
|
||||
snprintf(pathbuf, 1023, "%s/" CUSTOM_HISTFILE, home);
|
||||
pathbuf[1023] = '\0';
|
||||
|
||||
// make sure the history file exists
|
||||
hf = fopen(CUSTOM_HISTORY, "a"); fclose(hf);
|
||||
system("sort " CUSTOM_HISTORY " | uniq > " CUSTOM_HISTORY "~");
|
||||
system("mv " CUSTOM_HISTORY "~ " CUSTOM_HISTORY);
|
||||
/* make sure the history file exists */
|
||||
hf = fopen(CUSTOM_HISTFILE, "a"); fclose(hf);
|
||||
system("sort " CUSTOM_HISTFILE " | uniq > " CUSTOM_HISTFILE "~");
|
||||
system("mv " CUSTOM_HISTFILE "~ " CUSTOM_HISTFILE);
|
||||
|
||||
pp = popen(RUN_CUSTOM_LAYOUT CUSTOM_HISTORY, "r");
|
||||
pp = popen(RUN_CUSTOM_LAYOUT CUSTOM_HISTFILE, "r");
|
||||
} else {
|
||||
pp = popen(RUN_CUSTOM_LAYOUT, "r");
|
||||
}
|
||||
|
||||
if (!pp) return;
|
||||
char buf[1024 + 1];
|
||||
|
||||
if (!pp)
|
||||
return;
|
||||
|
||||
char buf[1024];
|
||||
buf[1024] = '\0';
|
||||
fgets(buf, 1024, pp);
|
||||
fclose(pp);
|
||||
if (buf[0] == '\0') return;
|
||||
if (buf[0] == '\0')
|
||||
return;
|
||||
|
||||
// Write to history file
|
||||
hf = fopen(CUSTOM_HISTORY, "a");
|
||||
hf = fopen(CUSTOM_HISTFILE, "a");
|
||||
fprintf(hf, "%s", buf);
|
||||
fclose(hf);
|
||||
|
||||
if (custom_scheme != NULL) {
|
||||
free_node(custom_scheme);
|
||||
custom_scheme = NULL;
|
||||
if (s_layout_scheme != NULL) {
|
||||
free_node(s_layout_scheme);
|
||||
s_layout_scheme = NULL;
|
||||
}
|
||||
|
||||
struct string_token_t *token_root = tokenize_string(buf),
|
||||
*token = token_root;
|
||||
|
||||
custom_scheme = parse_sexp(&token);
|
||||
s_layout_scheme = parse_sexp(&token);
|
||||
|
||||
setlayout(arg);
|
||||
|
||||
// Free the token list
|
||||
/* Free the token list */
|
||||
while (token_root != NULL) {
|
||||
token = token_root->next;
|
||||
free(token_root);
|
||||
|
|
Loading…
Reference in a new issue