Skip to content

Commit 65605f7

Browse files
committed
save rules in current format
1 parent 5b0bba4 commit 65605f7

File tree

6 files changed

+195
-5
lines changed

6 files changed

+195
-5
lines changed

.indent.pro

+1
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,4 @@
271271
-Tbfunc_t
272272
-Tabq_item_t
273273
-TXClassHint
274+
-TRule

doc/adwm-rules.5.in

+3-3
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ title bar;
202202
resize grips;
203203
.It Cm border
204204
decorative border; and
205-
.It Cm button.<button>
205+
.It Cm but.<button>
206206
buttons to display where
207207
.Cm <button>
208208
may be one of the following:
@@ -358,7 +358,7 @@ floating, even on tiled layouts. When false, the client will be started
358358
tiled.
359359
.Pp
360360
This is the equivalent of the current
361-
.Cm is.floater
361+
.Cm skip.arrange
362362
setting (see
363363
.Sx SETTINGS ,
364364
above).
@@ -379,7 +379,7 @@ resize grips by default, using the current syntax:
379379
.Pp
380380
Example:
381381
.Dl Li "Adwm*" Ns Cm rule0.prop Ns Li : Ar ^Mplayer:
382-
.Dl Li "Adwm*" Ns Cm rule0.is.floater Ns Li : Ar 1
382+
.Dl Li "Adwm*" Ns Cm rule0.skip.arrange Ns Li : Ar 1
383383
.Dl Li "Adwm*" Ns Cm rule0.has.title Ns Li : Ar 1
384384
.Dl Li "Adwm*" Ns Cm rule0.has.grips Ns Li : Ar 1
385385
.Pp

src/adwm.h

+26
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,8 @@ typedef union {
932932
unsigned skip;
933933
} SkipUnion;
934934

935+
extern char *skip_fields[32]; /* see parse.h */
936+
935937
typedef union {
936938
struct {
937939
unsigned border:1;
@@ -953,6 +955,8 @@ typedef union {
953955
unsigned has;
954956
} HasUnion;
955957

958+
extern char *has_fields[32]; /* see parse.h */
959+
956960
typedef union {
957961
struct {
958962
unsigned transient:1;
@@ -989,6 +993,8 @@ typedef union {
989993
unsigned is;
990994
} IsUnion;
991995

996+
extern char *is_fields[32]; /* see parse.h */
997+
992998
typedef union {
993999
struct {
9941000
unsigned move:1;
@@ -1019,6 +1025,8 @@ typedef union {
10191025
unsigned can;
10201026
} CanUnion;
10211027

1028+
extern char *can_fields[32]; /* see parse.h */
1029+
10221030
typedef union {
10231031
struct {
10241032
unsigned struts:1;
@@ -1031,6 +1039,8 @@ typedef union {
10311039
unsigned with;
10321040
} WithUnion;
10331041

1042+
extern char *with_fields[32]; /* see parse.h */
1043+
10341044
struct Appl {
10351045
Appl *next; /* next in list */
10361046
char *appid; /* application id (unique) */
@@ -1475,6 +1485,22 @@ struct AScreen {
14751485
typedef struct {
14761486
char *prop;
14771487
char *tags;
1488+
struct {
1489+
IsUnion is;
1490+
IsUnion set;
1491+
} is;
1492+
struct {
1493+
SkipUnion skip;
1494+
SkipUnion set;
1495+
} skip;
1496+
struct {
1497+
HasUnion has;
1498+
HasUnion set;
1499+
} has;
1500+
struct {
1501+
CanUnion can;
1502+
CanUnion set;
1503+
} can;
14781504
Bool isfloating;
14791505
Bool hastitle;
14801506
regex_t *propregex;

src/parse.c

+113-2
Original file line numberDiff line numberDiff line change
@@ -802,12 +802,123 @@ initkeys(Bool reload)
802802
}
803803
}
804804

805+
char *skip_fields[32] = {
806+
"taskbar",
807+
"pager",
808+
"winlist",
809+
"cycle",
810+
"focus",
811+
"arrange",
812+
"sloppy",
813+
NULL,
814+
};
815+
816+
char *has_fields[32] = {
817+
"border",
818+
"grips",
819+
"title",
820+
"but.menu",
821+
"but.min",
822+
"but.max",
823+
"but.close",
824+
"but.size",
825+
"but.shade",
826+
"but.stick",
827+
"but.fill",
828+
"but.floats",
829+
"but.half",
830+
NULL,
831+
};
832+
833+
char *is_fields[32] = {
834+
NULL /* "transient" */,
835+
NULL /* "grptrans" */,
836+
NULL /* "banned" */,
837+
"max",
838+
"floater",
839+
"maxv",
840+
"maxh",
841+
"lhalf",
842+
"rhalf",
843+
"shaded",
844+
"icon",
845+
"fill",
846+
NULL /* "modal" */,
847+
"above",
848+
"below",
849+
NULL /* "attn" */,
850+
"sticky",
851+
"undec",
852+
NULL /* "closing" */,
853+
NULL /* "killing" */,
854+
NULL /* "pinging" */,
855+
"hidden",
856+
"bastard",
857+
"full",
858+
NULL /* "focused" */,
859+
NULL /* "selected" */,
860+
"dockapp",
861+
NULL /* "moveresize" */,
862+
NULL /* "managed" */,
863+
NULL /* "saving" */,
864+
NULL,
865+
};
866+
867+
char *can_fields[32] = {
868+
"move",
869+
"size",
870+
"sizev",
871+
"sizeh",
872+
"min",
873+
"max",
874+
"maxv",
875+
"maxh",
876+
"close",
877+
"shade",
878+
"stick",
879+
"full",
880+
"above",
881+
"below",
882+
"fill",
883+
"fillh",
884+
"fillv",
885+
"floats",
886+
"hide",
887+
"tag",
888+
"arrange",
889+
"undec",
890+
"select",
891+
"focus",
892+
NULL,
893+
};
894+
895+
char *with_fields[32] = {
896+
NULL /* "struts" */,
897+
NULL /* "time" */,
898+
NULL /* "boundary" */,
899+
NULL /* "clipping" */,
900+
NULL /* "wshape" */,
901+
NULL /* "bshape" */,
902+
NULL,
903+
};
904+
805905
static void
806-
parserule(const char *s, Rule * r)
906+
parserule(const char *s, Rule *r)
807907
{
908+
Bool isfloating = False;
909+
Bool hastitle = False;
910+
808911
r->prop = emallocz(128);
809912
r->tags = emallocz(64);
810-
sscanf(s, "%s %s %d %d", r->prop, r->tags, &r->isfloating, &r->hastitle);
913+
sscanf(s, "%s %s %d %d", r->prop, r->tags, &isfloating, &hastitle);
914+
915+
/* set current equivalents to old format */
916+
r->skip.skip.arrange = isfloating;
917+
r->skip.set.arrange = 1;
918+
r->has.has.title = hastitle;
919+
r->has.has.grips = hastitle;
920+
r->has.set.title = 1;
921+
r->has.set.grips = 1;
811922
}
812923

813924
static void

src/parse.h

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
#ifndef __LOCAL_PARSE_H__
44
#define __LOCAL_PARSE_H__
55

6+
extern char *skip_fields[32];
7+
extern char *has_fields[32];
8+
extern char *is_fields[32];
9+
extern char *can_fields[32];
10+
extern char *with_fields[32];
11+
612
void initrules(Bool reload);
713
void initkeys(Bool reload);
814
void freekeys(void);

src/save.c

+46
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,54 @@ save(Bool permanent)
449449
Rule *r;
450450

451451
if ((r = rules[i])) {
452+
int f;
453+
unsigned mask;
454+
#if 0
455+
/* old deprecated format */
452456
snprintf(line, sizeof(line), "Adwm.rule%u:\t\t%s %s %d %d\n", i, r->prop, r->tags, r->isfloating, r->hastitle);
453457
XrmPutLineResource(&srdb, line);
458+
#else
459+
if (r->prop) {
460+
snprintf(line, sizeof(line), "Adwm.rule%u.prop:\t\t%s\n", i, r->prop);
461+
XrmPutLineResource(&srdb, line);
462+
}
463+
if (r->tags) {
464+
snprintf(line, sizeof(line), "Adwm.rule%u.tags:\t\t%s\n", i, r->tags);
465+
XrmPutLineResource(&srdb, line);
466+
}
467+
if (r->is.set.is) {
468+
for (f = 0, mask = 1; f < 32; f++, mask <<= 1) {
469+
if ((r->is.set.is & mask) && is_fields[f]) {
470+
snprintf(line, sizeof(line), "Adwm.rule%u.is.%s:\t\t%d\n", i, is_fields[f], (r->is.is.is & mask) ? 1 : 0);
471+
XrmPutLineResource(&srdb, line);
472+
}
473+
}
474+
}
475+
if (r->skip.set.skip) {
476+
for (f = 0, mask = 1; f < 32; f++, mask <<= 1) {
477+
if ((r->skip.set.skip & mask) && skip_fields[f]) {
478+
snprintf(line, sizeof(line), "Adwm.rule%u.skip.%s:\t\t%d\n", i, skip_fields[f], (r->skip.skip.skip & mask) ? 1 : 0);
479+
XrmPutLineResource(&srdb, line);
480+
}
481+
}
482+
}
483+
if (r->has.set.has) {
484+
for (f = 0, mask = 1; f < 32; f++, mask <<= 1) {
485+
if ((r->has.set.has & mask) && has_fields[f]) {
486+
snprintf(line, sizeof(line), "Adwm.rule%u.has.%s:\t\t%d\n", i, has_fields[f], (r->has.has.has & mask) ? 1 : 0);
487+
XrmPutLineResource(&srdb, line);
488+
}
489+
}
490+
}
491+
if (r->can.set.can) {
492+
for (f = 0, mask = 1; f < 32; f++, mask <<= 1) {
493+
if ((r->can.set.can & mask) && can_fields[f]) {
494+
snprintf(line, sizeof(line), "Adwm.rule%u.can.%s:\t\t%d\n", i, can_fields[f], (r->can.can.can & mask) ? 1 : 0);
495+
XrmPutLineResource(&srdb, line);
496+
}
497+
}
498+
}
499+
#endif
454500
}
455501
}
456502

0 commit comments

Comments
 (0)