+const char *quirkname[] = {
+ "NONE", /* config string for "no value" */
+ "FLOAT",
+ "TRANSSZ",
+ "ANYWHERE",
+ "XTERM_FONTADJ",
+ "FULLSCREEN",
+};
+
+#define SWM_Q_WS "\n| \t"
+int
+parsequirks(char *qstr, unsigned long *quirk)
+{
+ char *cp, *name;
+ int i;
+ if (quirk == NULL)
+ return (0);
+ cp = qstr;
+ *quirk = 0;
+ while ((name = strsep(&cp, SWM_Q_WS)) != NULL) {
+ if (cp)
+ cp += (long)strspn(cp, SWM_Q_WS);
+ for (i = 0; i < LENGTH(quirkname); i++) {
+ if (!strncasecmp(name, quirkname[i], SWM_QUIRK_LEN)) {
+ DNPRINTF(SWM_D_QUIRK, "parsequirks: %s\n", name);
+ if (i == 0) {
+ *quirk = 0;
+ return (1);
+ }
+ *quirk |= 1 << (i-1);
+ break;
+ }
+ }
+ if (i >= LENGTH(quirkname)) {
+ DNPRINTF(SWM_D_QUIRK,
+ "parsequirks: invalid quirk [%s]\n", name);
+ return (0);
+ }
+ }
+ return (1);
+}
+int
+quirkmatch(const char *var, const char *name, char *qstr, char *qclass,
+ char *qname, unsigned long *qquirk)
+{
+ char *p;
+ int i;
+ char classname[SWM_QUIRK_LEN*2+1];
+ DNPRINTF(SWM_D_QUIRK, "quirkmatch: in [%s]\n", var);
+ i = strncmp(var, name, 255);
+ if (qclass == NULL || qname == NULL || qquirk == NULL)
+ return (i);
+ *qquirk = 0;
+ *qclass = '\0';
+ *qname = '\0';
+ bzero(classname, LENGTH(classname));
+ if (i <= 0)
+ return (i);
+ p = (char *)var + strlen(name);
+ if (*p++ != '[')
+ return (i);
+ i = 0;
+ while (isgraph(*p) && *p != ']' && i < LENGTH(classname))
+ classname[i++] = *p++;
+ if (i >= LENGTH(classname) || *p != ']')
+ return (1);
+ if ((p = strchr(classname, ':')) == NULL || p-classname >= SWM_QUIRK_LEN)
+ return (1);
+ strlcpy(qclass, classname, p-classname+1);
+ strlcpy(qname, ++p, SWM_QUIRK_LEN);
+ for (p = qclass; *p && p-qclass < SWM_QUIRK_LEN; p++)
+ if (*p == '_')
+ *p = ' ';
+ for (p = qname; *p && p-qname < SWM_QUIRK_LEN; p++)
+ if (*p == '_')
+ *p = ' ';
+ i = (!parsequirks(qstr, qquirk));
+ DNPRINTF(SWM_D_QUIRK, "quirkmatch: [%s][%s] %d\n", qclass, qname, i);
+ return (i);
+}
+void
+setquirk(const char *class, const char *name, const int quirk)
+{
+ int i, j;
+ /* find existing */
+ for (i = 0; i < quirks_length; i++) {
+ if (!strcmp(quirks[i].class, class) &&
+ !strcmp(quirks[i].name, name)) {
+ if (!quirk) {
+ /* found: delete */
+ DNPRINTF(SWM_D_QUIRK,
+ "setquirk: delete #%d %s:%s\n",
+ i, quirks[i].class, quirks[i].name);
+ j = quirks_length - 1;
+ if (i < j)
+ quirks[i] = quirks[j];
+ quirks_length--;
+ return;
+ } else {
+ /* found: replace */
+ DNPRINTF(SWM_D_QUIRK,
+ "setquirk: replace #%d %s:%s\n",
+ i, quirks[i].class, quirks[i].name);
+ strlcpy(quirks[i].class, class,
+ sizeof quirks->class);
+ strlcpy(quirks[i].name, name,
+ sizeof quirks->name);
+ quirks[i].quirk = quirk;
+ return;
+ }
+ }
+ }
+ if (!quirk) {
+ fprintf(stderr,
+ "error: setquirk: cannot find class/name combination");
+ return;
+ }
+ /* not found: add */
+ if (quirks_size == 0 || quirks == NULL) {
+ quirks_size = 4;
+ DNPRINTF(SWM_D_QUIRK, "setquirk: init list %d\n", quirks_size);
+ quirks = malloc((size_t)quirks_size * sizeof(struct quirk));
+ if (!quirks) {
+ fprintf(stderr, "setquirk: malloc failed\n");
+ perror(" failed");
+ quit(NULL, NULL);
+ }
+ } else if (quirks_length == quirks_size) {
+ quirks_size *= 2;
+ DNPRINTF(SWM_D_QUIRK, "setquirk: grow list %d\n", quirks_size);
+ quirks = realloc(quirks, (size_t)quirks_size * sizeof(struct quirk));
+ if (!quirks) {
+ fprintf(stderr, "setquirk: realloc failed\n");
+ perror(" failed");
+ quit(NULL, NULL);
+ }
+ }
+ if (quirks_length < quirks_size) {
+ DNPRINTF(SWM_D_QUIRK, "setquirk: add %d\n", quirks_length);
+ j = quirks_length++;
+ strlcpy(quirks[j].class, class, sizeof quirks->class);
+ strlcpy(quirks[j].name, name, sizeof quirks->name);
+ quirks[j].quirk = quirk;
+ } else {
+ fprintf(stderr, "quirks array problem?\n");
+ if (!quirks) {
+ fprintf(stderr, "quirks array problem!\n");
+ quit(NULL, NULL);
+ }
+ }
+}
+
+void
+setup_quirks(void)
+{
+ setquirk("MPlayer", "xv", SWM_Q_FLOAT | SWM_Q_FULLSCREEN);
+ setquirk("OpenOffice.org 2.4", "VCLSalFrame", SWM_Q_FLOAT);
+ setquirk("OpenOffice.org 3.0", "VCLSalFrame", SWM_Q_FLOAT);
+ setquirk("Firefox-bin", "firefox-bin", SWM_Q_TRANSSZ);
+ setquirk("Firefox", "Dialog", SWM_Q_FLOAT);
+ setquirk("Gimp", "gimp", SWM_Q_FLOAT | SWM_Q_ANYWHERE);
+ setquirk("XTerm", "xterm", SWM_Q_XTERM_FONTADJ);
+ setquirk("xine", "Xine Window", SWM_Q_FLOAT | SWM_Q_ANYWHERE);
+ setquirk("Xitk", "Xitk Combo", SWM_Q_FLOAT | SWM_Q_ANYWHERE);
+ setquirk("xine", "xine Panel", SWM_Q_FLOAT | SWM_Q_ANYWHERE);
+ setquirk("Xitk", "Xine Window", SWM_Q_FLOAT | SWM_Q_ANYWHERE);
+ setquirk("xine", "xine Video Fullscreen Window", SWM_Q_FULLSCREEN | SWM_Q_FLOAT);
+ setquirk("pcb", "pcb", SWM_Q_FLOAT);
+}
+