From ce1a2d182eac1d8163206f52a814c4054f98c5a2 Mon Sep 17 00:00:00 2001 From: Darrin Chandler Date: Mon, 25 May 2009 22:04:56 +0000 Subject: [PATCH] Break out static quirks list into dynamic list, initialized to match the previous static list. Add quirks parsing to config file. Update manual with quirks. Man help from Jason McIntyre (jmc). Thanks! ok marco. --- scrotwm.1 | 110 ++++++++++++++++++++++++++++-- scrotwm.c | 212 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ scrotwm.conf | 16 +++++ 3 files changed, 314 insertions(+), 24 deletions(-) diff --git a/scrotwm.1 b/scrotwm.1 index 67124d1..409c86f 100644 --- a/scrotwm.1 +++ b/scrotwm.1 @@ -101,8 +101,9 @@ such as battery life. .It Cm bar_delay Update frequency, in seconds, of external script that populates the status bar. .It Cm clock_enabled -Enable or disable displaying the clock in the status bar. Disable by -setting to 0 so a custom clock could be used in the bar_action script. +Enable or disable displaying the clock in the status bar. +Disable by setting to 0 +so a custom clock could be used in the bar_action script. .It Cm spawn_term External application that gets spawned when .Cm M-S- Ns Aq Cm Return @@ -114,7 +115,8 @@ For example, 0.6 is 60% of the physical screen size. .It Cm region Allocates a custom region, removing any autodetected regions which occupy the same space on the screen. -Defined in the format screen[]:WIDTHxHEIGHT+X+Y, e.g. screen[1]:800x1200+0+0. +Defined in the format screen[]:WIDTHxHEIGHT+X+Y, +e.g.\& screen[1]:800x1200+0+0. .It Cm screenshot_enabled Enable or disable screenshot capability. .It Cm screenshot_app @@ -128,7 +130,7 @@ If this value is greater than 0, .Nm will attempt to adjust the font sizes in the terminal to keep the terminal width above this number as the window is resized. -Only +Only .Xr xterm 1 is currently supported. The @@ -146,6 +148,14 @@ Bind key combo to action See the .Sx BINDINGS section below. +.It Cm quirk Ns Bq Ar c:n +Add "quirk" for windows with class +.Ar c +and name +.Ar n . +See the +.Sx QUIRKS +section below. .El .Pp Colors need to be specified per the @@ -338,13 +348,103 @@ is one of the actions listed above (or empty) and .Aq keys is in the form of zero or more modifier keys (MOD, Mod1, Shift, etc.) and one or more normal keys -(b, space, etc.), separated by "+". For example: +(b, space, etc.), separated by "+". +For example: .Bd -literal -offset indent bind[reset] = Mod4+q # bind Windows-key + q to reset bind[] = Mod1+q # unbind Alt + q .Ed .Pp Multiple key combinations may be bound to the same action. +.Sh QUIRKS +.Nm +provides "quirks" which handle windows that must be treated specially +in a tiling window manager, such as some dialogs and fullscreen apps. +.Pp +The default quirks are described below: +.Pp +.Bl -tag -width "OpenOffice.org N.M:VCLSalFrameXXX" -offset indent -compact +.It Firefox-bin:firefox-bin +TRANSSZ +.It Firefox:Dialog +FLOAT +.It Gimp:gimp +FLOAT | ANYWHERE +.It MPlayer:xv +FLOAT | FULLSCREEN +.It OpenOffice.org 2.4:VCLSalFrame +FLOAT +.It OpenOffice.org 3.1:VCLSalFrame +FLOAT +.It pcb:pcb +FLOAT +.It xine:Xine Window +FLOAT | ANYWHERE +.It xine:xine Panel +FLOAT | ANYWHERE +.It xine:xine Video Fullscreen Window +FULLSCREEN | FLOAT +.It Xitk:Xitk Combo +FLOAT | ANYWHERE +.It Xitk:Xine Window +FLOAT | ANYWHERE +.It XTerm:xterm +XTERM_FONTADJ +.El +.Pp +The quirks themselves are described below: +.Pp +.Bl -tag -width "XTERM_FONTADJXXX" -offset indent -compact +.It FLOAT +This window should not be tiled, but allowed to float freely. +.It TRANSSZ +Adjusts size on transient windows that are too small using dialog_ratio +(see +.Sx CONFIGURATION FILES ) . +.It ANYWHERE +Allow window to position itself, uncentered. +.It XTERM_FONTADJ +Adjust xterm fonts when resizing. +.It FULLSCREEN +Remove border to allow window to use full screen size. +.El +.Pp +Custom quirks in the configuration file are specified as follows: +.Pp +.Dl quirk[:] = [ | ... ] +.Pp +.Aq class +and +.Aq name +specify the window to which the quirk(s) apply, and +.Aq quirk +is one of the quirks from the list above. +For example: +.Bd -literal -offset indent +quirk[MPlayer:xv] = FLOAT | FULLSCREEN # let mplayer play +quirk[pcb:pcb] = NONE # remove existing quirk +.Ed +.Pp +Note that spaces in +.Aq class +or +.Aq name +must be replaced by an underscore in the configuration. +The config entry for "xine:Xine Panel" would be: +.Bd -literal -offset indent +quirk[xine:Xine_Panel] = FLOAT +.Ed +.Pp +You can obtain +.Aq class +and +.Aq name +by running xprop(1) and then clicking on the desired window. +In the following example the main window of Firefox was clicked: +.Bd -literal -offset indent +$ xprop | grep WM_CLASS +WM_CLASS(STRING) = "Navigator", "Firefox" +.Ed .Sh FILES .Bl -tag -width "/etc/scrotwm.confXXX" -compact .It Pa ~/.scrotwm.conf diff --git a/scrotwm.c b/scrotwm.c index abb60de..cae3cac 100644 --- a/scrotwm.c +++ b/scrotwm.c @@ -107,6 +107,7 @@ static const char *cvstag = "$scrotwm$"; #define SWM_D_PROP 0x0080 #define SWM_D_CLASS 0x0100 #define SWM_D_KEY 0x0200 +#define SWM_D_QUIRK 0x0400 u_int32_t swm_debug = 0 | SWM_D_MISC @@ -119,6 +120,7 @@ u_int32_t swm_debug = 0 | SWM_D_PROP | SWM_D_CLASS | SWM_D_KEY + | SWM_D_QUIRK ; #else #define DPRINTF(x...) @@ -133,6 +135,7 @@ u_int32_t swm_debug = 0 #define SWM_PROPLEN (16) #define SWM_FUNCNAME_LEN (32) #define SWM_KEYS_LEN (255) +#define SWM_QUIRK_LEN (32) #define X(r) (r)->g.x #define Y(r) (r)->g.y #define WIDTH(r) (r)->g.w @@ -317,6 +320,10 @@ void update_modkey(unsigned int); int bindmatch(const char *var, const char *name, unsigned int currmod, char *keystr, enum keyfuncid *kfid, unsigned int *mod, KeySym *ks); void setkeybinding(unsigned int mod, KeySym ks, enum keyfuncid kfid); +/* quirks */ +int quirkmatch(const char *var, const char *name, char *qstr, + char *qclass, char *qname, unsigned long *qquirk); +void setquirk(const char *class, const char *name, const int quirk); struct layout { void (*l_stack)(struct workspace *, struct swm_geometry *); @@ -408,30 +415,17 @@ union arg { /* quirks */ struct quirk { - char *class; - char *name; + char class[SWM_QUIRK_LEN]; + char name[SWM_QUIRK_LEN]; unsigned long quirk; #define SWM_Q_FLOAT (1<<0) /* float this window */ #define SWM_Q_TRANSSZ (1<<1) /* transiend window size too small */ #define SWM_Q_ANYWHERE (1<<2) /* don't position this window */ #define SWM_Q_XTERM_FONTADJ (1<<3) /* adjust xterm fonts when resizing */ #define SWM_Q_FULLSCREEN (1<<4) /* remove border */ -} quirks[] = { - { "MPlayer", "xv", SWM_Q_FLOAT | SWM_Q_FULLSCREEN }, - { "OpenOffice.org 2.4", "VCLSalFrame", SWM_Q_FLOAT }, - { "OpenOffice.org 3.0", "VCLSalFrame", SWM_Q_FLOAT }, - { "Firefox-bin", "firefox-bin", SWM_Q_TRANSSZ }, - { "Firefox", "Dialog", SWM_Q_FLOAT }, - { "Gimp", "gimp", SWM_Q_FLOAT | SWM_Q_ANYWHERE }, - { "XTerm", "xterm", SWM_Q_XTERM_FONTADJ }, - { "xine", "Xine Window", SWM_Q_FLOAT | SWM_Q_ANYWHERE }, - { "Xitk", "Xitk Combo", SWM_Q_FLOAT | SWM_Q_ANYWHERE }, - { "xine", "xine Panel", SWM_Q_FLOAT | SWM_Q_ANYWHERE }, - { "Xitk", "Xine Window", SWM_Q_FLOAT | SWM_Q_ANYWHERE }, - { "xine", "xine Video Fullscreen Window", SWM_Q_FULLSCREEN | SWM_Q_FLOAT }, - { "pcb", "pcb", SWM_Q_FLOAT }, - { NULL, NULL, 0}, }; +int quirks_size = 0, quirks_length = 0; +struct quirk *quirks = NULL; /* events */ void expose(XEvent *); @@ -574,6 +568,9 @@ conf_load(char *filename) unsigned int modkey = MODKEY, modmask; KeySym ks; enum keyfuncid kfid; + char class[SWM_QUIRK_LEN]; + char name[SWM_QUIRK_LEN]; + unsigned long quirk; DNPRINTF(SWM_D_MISC, "conf_load: filename %s\n", filename); @@ -665,6 +662,13 @@ conf_load(char *filename) goto bad; break; + case 'q': + if (!quirkmatch(var, "quirk", val, class, name, &quirk)) + setquirk(class, name, quirk); + else + goto bad; + break; + case 'r': if (!strncmp(var, "region", strlen("region"))) custom_region(val); @@ -2546,6 +2550,176 @@ set_win_state(struct ws_win *win, long state) (unsigned char *)data, 2); } +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); +} + struct ws_win * manage_window(Window id) { @@ -2631,8 +2805,7 @@ manage_window(Window id) if (XGetClassHint(display, win->id, &win->ch)) { DNPRINTF(SWM_D_CLASS, "class: %s name: %s\n", win->ch.res_class, win->ch.res_name); - for (i = 0; quirks[i].class != NULL && quirks[i].name != NULL && - quirks[i].quirk != 0; i++){ + for (i = 0; i < quirks_length; i++){ if (!strcmp(win->ch.res_class, quirks[i].class) && !strcmp(win->ch.res_name, quirks[i].name)) { DNPRINTF(SWM_D_CLASS, "found: %s name: %s\n", @@ -3317,6 +3490,7 @@ main(int argc, char *argv[]) setup_screens(); setup_keys(); + setup_quirks(); snprintf(conf, sizeof conf, "%s/.%s", pwd->pw_dir, SWM_CONF_FILE); if (stat(conf, &sb) != -1) { diff --git a/scrotwm.conf b/scrotwm.conf index 50e4f82..5f08360 100644 --- a/scrotwm.conf +++ b/scrotwm.conf @@ -87,3 +87,19 @@ dialog_ratio = 0.6 #bind[version] = MOD+Shift+v #bind[spawn_lock] = MOD+Shift+Delete #bind[spawn_initscr] = MOD+Shift+i + +# quirks +# remove with: quirk[class:name] = NONE +#quirk[MPlayer:xv] = FLOAT | FULLSCREEN +#quirk[OpenOffice.org_2.4:VCLSalFrame] = FLOAT +#quirk[OpenOffice.org_3.0:VCLSalFrame] = FLOAT +#quirk[Firefox-bin:firefox-bin] = TRANSSZ +#quirk[Firefox:Dialog] = FLOAT +#quirk[Gimp:gimp] = FLOAT | ANYWHERE +#quirk[XTerm:xterm] = XTERM_FONTADJ +#quirk[xine:Xine_Window] = FLOAT | ANYWHERE +#quirk[Xitk:Xitk_Combo] = FLOAT | ANYWHERE +#quirk[xine:xine_Panel] = FLOAT | ANYWHERE +#quirk[Xitk:Xine_Window] = FLOAT | ANYWHERE +#quirk[xine:xine_Video_Fullscreen_Window] = FULLSCREEN | FLOAT +#quirk[pcb:pcb] = FLOAT -- 1.7.10.4